Port-arm archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Allwinner RTC
On Fri, Nov 07, 2014 at 08:48:53AM -0600, Jonathan A. Kollasch wrote:
> On Fri, Nov 07, 2014 at 08:33:49AM -0600, Jonathan A. Kollasch wrote:
> >
> > Currently whenever I boot NetBSD on my Cubietruck after booting the
> > Android system in NAND the clock is exactly 70 years in the future.
> >
> > I've looked at the linux-sunxi/drivers/rtc/rtc-sun4i.c code and it
> > appears than all RTCs supported by rtc-sun4i except the sun7i (A20)
> > implement a 63-year RTC based at 1970. The sun7i uses a 255-year RTC
> > register layout and is based at 1900.
> >
> > Comparing this to src/sys/arch/arm/allwinner/awin_rtc.c v1.6, I seem to
> > find that we only do as Linux on the A30 chips.
> >
> > Does anyone have Linux/Android booting on a A10-based system to confirm
> > that it uses the 63-year 1970-based RTC? I believe you would find that
> > that NetBSD would think it was 70 years earlier than Linux on A10.
>
> Looking at the A10 User Manual, it seems to indicate it has a 63-year RTC.
Proposed change attached.
Jonathan Kollasch
Index: sys/arch/arm/allwinner/awin_reg.h
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/allwinner/awin_reg.h,v
retrieving revision 1.42
diff -d -u -a -p -r1.42 awin_reg.h
--- sys/arch/arm/allwinner/awin_reg.h 5 Nov 2014 15:05:20 -0000 1.42
+++ sys/arch/arm/allwinner/awin_reg.h 7 Nov 2014 15:43:24 -0000
@@ -1517,8 +1517,10 @@ struct awin_mmc_idma_descriptor {
AWIN_LOSC_CTRL_RTC_YYMMDD_ACCE)
#define AWIN_RTC_YY_MM_DD_RTC_SIM_CTRL __BIT(30)
-#define AWIN_RTC_YY_MM_DD_LEAP __BIT(24)
-#define AWIN_RTC_YY_MM_DD_YEAR __BITS(23,16)
+#define AWIN_RTC_YY_MM_DD_LEAP __BIT(22)
+#define AWIN_A20_RTC_YY_MM_DD_LEAP __BIT(24)
+#define AWIN_RTC_YY_MM_DD_YEAR __BITS(21,16)
+#define AWIN_A20_RTC_YY_MM_DD_YEAR __BITS(23,16)
#define AWIN_RTC_YY_MM_DD_MONTH __BITS(11,8)
#define AWIN_RTC_YY_MM_DD_DAY __BITS(4,0)
#define AWIN_RTC_HH_MM_SS_WK_NO __BITS(31,29)
@@ -1907,8 +1909,6 @@ struct awin_mmc_idma_descriptor {
#define AWIN_A31_RTC_YY_MM_DD_REG 0x0010
#define AWIN_A31_RTC_HH_MM_SS_REG 0x0014
-#define AWIN_A31_RTC_YY_MM_DD_YEAR __BITS(21,16)
-
#define AWIN_A31_P2WI_CTRL_REG 0x0000
#define AWIN_A31_P2WI_CCR_REG 0x0004
#define AWIN_A31_P2WI_INTE_REG 0x0008
Index: sys/arch/arm/allwinner/awin_rtc.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/allwinner/awin_rtc.c,v
retrieving revision 1.6
diff -d -u -a -p -r1.6 awin_rtc.c
--- sys/arch/arm/allwinner/awin_rtc.c 4 Nov 2014 19:22:50 -0000 1.6
+++ sys/arch/arm/allwinner/awin_rtc.c 7 Nov 2014 15:43:24 -0000
@@ -49,6 +49,8 @@ struct awin_rtc_softc {
uint32_t sc_loscctrl_reg;
uint32_t sc_yymmdd_reg;
uint32_t sc_hhmmss_reg;
+ uint32_t sc_year_base;
+ uint32_t sc_year_mask;
};
#define RTC_READ(sc, reg) \
@@ -99,6 +101,14 @@ awin_rtc_attach(device_t parent, device_
sc->sc_hhmmss_reg = AWIN_RTC_HH_MM_SS_REG;
}
+ if (awin_chip_id() == AWIN_CHIP_ID_A20) {
+ sc->sc_year_base = 1900;
+ sc->sc_year_mask = AWIN_A20_RTC_YY_MM_DD_YEAR;
+ } else {
+ sc->sc_year_base = 1970;
+ sc->sc_year_mask = AWIN_RTC_YY_MM_DD_YEAR;
+ }
+
aprint_naive("\n");
aprint_normal(": RTC\n");
@@ -117,10 +127,7 @@ awin_rtc_gettime(todr_chip_handle_t tch,
yymmdd = RTC_READ(sc, sc->sc_yymmdd_reg);
hhmmss = RTC_READ(sc, sc->sc_hhmmss_reg);
- dt->dt_year = __SHIFTOUT(yymmdd,
- awin_chip_id() == AWIN_CHIP_ID_A31 ?
- AWIN_A31_RTC_YY_MM_DD_YEAR : AWIN_RTC_YY_MM_DD_YEAR) +
- POSIX_BASE_YEAR;
+ dt->dt_year = __SHIFTOUT(yymmdd, sc->sc_year_mask) + sc->sc_year_base;
dt->dt_mon = __SHIFTOUT(yymmdd, AWIN_RTC_YY_MM_DD_MONTH);
dt->dt_day = __SHIFTOUT(yymmdd, AWIN_RTC_YY_MM_DD_DAY);
dt->dt_wday = __SHIFTOUT(hhmmss, AWIN_RTC_HH_MM_SS_WK_NO);
@@ -149,24 +156,18 @@ awin_rtc_settime(todr_chip_handle_t tch,
"not writing back time\n", dt->dt_year);
return EIO;
}
- maxyear = __SHIFTOUT(0xffffffff,
- awin_chip_id() == AWIN_CHIP_ID_A31 ?
- AWIN_A31_RTC_YY_MM_DD_YEAR : AWIN_RTC_YY_MM_DD_YEAR)
- + POSIX_BASE_YEAR;
+ maxyear = __SHIFTOUT(0xffffffff, sc->sc_year_mask) + sc->sc_year_base;
if (dt->dt_year > maxyear) {
aprint_normal_dev(sc->sc_dev, "year exceeds available field:"
" %llu, not writing back time\n", dt->dt_year);
return EIO;
}
- yymmdd = __SHIFTIN(dt->dt_year - POSIX_BASE_YEAR,
- awin_chip_id() == AWIN_CHIP_ID_A31 ?
- AWIN_A31_RTC_YY_MM_DD_YEAR : AWIN_RTC_YY_MM_DD_YEAR);
+ yymmdd = __SHIFTIN(dt->dt_year - sc->sc_year_base,
+ sc->sc_year_mask);
- KASSERT(__SHIFTOUT(yymmdd,
- awin_chip_id() == AWIN_CHIP_ID_A31 ?
- AWIN_A31_RTC_YY_MM_DD_YEAR : AWIN_RTC_YY_MM_DD_YEAR) +
- POSIX_BASE_YEAR == dt->dt_year);
+ KASSERT(__SHIFTOUT(yymmdd, sc->sc_year_mask) +
+ sc->sc_year_base == dt->dt_year);
yymmdd |= __SHIFTIN(dt->dt_mon, AWIN_RTC_YY_MM_DD_MONTH);
yymmdd |= __SHIFTIN(dt->dt_day, AWIN_RTC_YY_MM_DD_DAY);
Home |
Main Index |
Thread Index |
Old Index