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 A31 RTC support



details:   https://anonhg.NetBSD.org/src/rev/8c4ff1f9c596
branches:  trunk
changeset: 332955:8c4ff1f9c596
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Oct 12 17:20:58 2014 +0000

description:
A31 RTC support

diffstat:

 sys/arch/arm/allwinner/awin_rtc.c |  43 +++++++++++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 13 deletions(-)

diffs (100 lines):

diff -r d28635ba8d22 -r 8c4ff1f9c596 sys/arch/arm/allwinner/awin_rtc.c
--- a/sys/arch/arm/allwinner/awin_rtc.c Sun Oct 12 17:20:46 2014 +0000
+++ b/sys/arch/arm/allwinner/awin_rtc.c Sun Oct 12 17:20:58 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_rtc.c,v 1.1 2014/09/07 17:49:39 jmcneill Exp $ */
+/* $NetBSD: awin_rtc.c,v 1.2 2014/10/12 17:20:58 jmcneill 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.1 2014/09/07 17:49:39 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_rtc.c,v 1.2 2014/10/12 17:20:58 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -46,8 +46,16 @@
        bus_space_tag_t sc_bst;
        bus_space_handle_t sc_bsh;
        struct todr_chip_handle sc_todr;
+       uint32_t sc_loscctrl_reg;
+       uint32_t sc_yymmdd_reg;
+       uint32_t sc_hhmmss_reg;
 };
 
+#define RTC_READ(sc, reg) \
+    bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
+#define RTC_WRITE(sc, reg, val) \
+    bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
+
 static int     awin_rtc_match(device_t, cfdata_t, void *);
 static void    awin_rtc_attach(device_t, device_t, void *);
 
@@ -81,6 +89,16 @@
        bus_space_subregion(sc->sc_bst, aio->aio_core_bsh,
            loc->loc_offset, loc->loc_size, &sc->sc_bsh);
 
+       if (awin_chip_id() == AWIN_CHIP_ID_A31) {
+               sc->sc_loscctrl_reg = AWIN_A31_LOSC_CTRL_REG;
+               sc->sc_yymmdd_reg = AWIN_A31_RTC_YY_MM_DD_REG;
+               sc->sc_hhmmss_reg = AWIN_A31_RTC_HH_MM_SS_REG;
+       } else {
+               sc->sc_loscctrl_reg = AWIN_LOSC_CTRL_REG;
+               sc->sc_yymmdd_reg = AWIN_RTC_YY_MM_DD_REG;
+               sc->sc_hhmmss_reg = AWIN_RTC_HH_MM_SS_REG;
+       }
+
        aprint_naive("\n");
        aprint_normal(": RTC\n");
 
@@ -96,12 +114,12 @@
        struct awin_rtc_softc *sc = tch->cookie;
        uint32_t yymmdd, hhmmss;
 
-       yymmdd = bus_space_read_4(sc->sc_bst, sc->sc_bsh,
-           AWIN_RTC_YY_MM_DD_REG);
-       hhmmss = bus_space_read_4(sc->sc_bst, sc->sc_bsh,
-           AWIN_RTC_HH_MM_SS_REG);
+       yymmdd = RTC_READ(sc, sc->sc_yymmdd_reg);
+       hhmmss = RTC_READ(sc, sc->sc_hhmmss_reg);
 
-       dt->dt_year = __SHIFTOUT(yymmdd, AWIN_RTC_YY_MM_DD_YEAR) +
+       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_mon = __SHIFTOUT(yymmdd, AWIN_RTC_YY_MM_DD_MONTH);
        dt->dt_day = __SHIFTOUT(yymmdd, AWIN_RTC_YY_MM_DD_DAY);
@@ -119,13 +137,14 @@
        struct awin_rtc_softc *sc = tch->cookie;
        uint32_t yymmdd, hhmmss, losc;
 
-       losc = bus_space_read_4(sc->sc_bst, sc->sc_bsh, AWIN_LOSC_CTRL_REG);
+       losc = RTC_READ(sc, sc->sc_loscctrl_reg);
        if (losc & AWIN_LOSC_CTRL_BUSY)
                return EBUSY;
 
        yymmdd = 0;
        yymmdd |= __SHIFTIN(dt->dt_year - POSIX_BASE_YEAR,
-           AWIN_RTC_YY_MM_DD_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_mon, AWIN_RTC_YY_MM_DD_MONTH);
        yymmdd |= __SHIFTIN(dt->dt_day, AWIN_RTC_YY_MM_DD_DAY);
        hhmmss = 0;
@@ -134,10 +153,8 @@
        hhmmss |= __SHIFTIN(dt->dt_min, AWIN_RTC_HH_MM_SS_MINUTE);
        hhmmss |= __SHIFTIN(dt->dt_sec, AWIN_RTC_HH_MM_SS_SECOND);
 
-       bus_space_write_4(sc->sc_bst, sc->sc_bsh, AWIN_RTC_YY_MM_DD_REG,
-           yymmdd);
-       bus_space_write_4(sc->sc_bst, sc->sc_bsh, AWIN_RTC_HH_MM_SS_REG,
-           hhmmss);
+       RTC_WRITE(sc, sc->sc_yymmdd_reg, yymmdd);
+       RTC_WRITE(sc, sc->sc_hhmmss_reg, hhmmss);
 
        return 0;
 }



Home | Main Index | Thread Index | Old Index