Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/allwinner Allwinner A20 RTC has a different ide...



details:   https://anonhg.NetBSD.org/src/rev/a7e7ac058755
branches:  trunk
changeset: 333536:a7e7ac058755
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Fri Nov 07 18:10:16 2014 +0000

description:
Allwinner A20 RTC has a different idea about years than the rest of them.

diffstat:

 sys/arch/arm/allwinner/awin_reg.h |   8 ++++----
 sys/arch/arm/allwinner/awin_rtc.c |  38 +++++++++++++++++++++-----------------
 2 files changed, 25 insertions(+), 21 deletions(-)

diffs (112 lines):

diff -r f587a8e48b1f -r a7e7ac058755 sys/arch/arm/allwinner/awin_reg.h
--- a/sys/arch/arm/allwinner/awin_reg.h Fri Nov 07 17:50:14 2014 +0000
+++ b/sys/arch/arm/allwinner/awin_reg.h Fri Nov 07 18:10:16 2014 +0000
@@ -1517,8 +1517,10 @@
         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 @@
 #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
diff -r f587a8e48b1f -r a7e7ac058755 sys/arch/arm/allwinner/awin_rtc.c
--- a/sys/arch/arm/allwinner/awin_rtc.c Fri Nov 07 17:50:14 2014 +0000
+++ b/sys/arch/arm/allwinner/awin_rtc.c Fri Nov 07 18:10:16 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_rtc.c,v 1.6 2014/11/04 19:22:50 jmcneill Exp $ */
+/* $NetBSD: awin_rtc.c,v 1.7 2014/11/07 18:10:16 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_rtc.c,v 1.6 2014/11/04 19:22:50 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_rtc.c,v 1.7 2014/11/07 18:10:16 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -49,6 +49,8 @@
        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,17 @@
                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 = POSIX_BASE_YEAR;
+               sc->sc_year_mask = AWIN_RTC_YY_MM_DD_YEAR;
+       }
+#ifdef AWIN_RTC_BASE_YEAR
+       sc->sc_year_base = AWIN_RTC_BASE_YEAR;
+#endif
+
        aprint_naive("\n");
        aprint_normal(": RTC\n");
 
@@ -117,10 +130,7 @@
        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 +159,18 @@
                    "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