Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Make this support the DS1553 as well. Add suppor...



details:   https://anonhg.NetBSD.org/src/rev/bc5671de7b55
branches:  trunk
changeset: 760369:bc5671de7b55
user:      matt <matt%NetBSD.org@localhost>
date:      Tue Jan 04 01:28:15 2011 +0000

description:
Make this support the DS1553 as well.  Add support for the centry reg which
newer RTCs seem to have.

diffstat:

 sys/dev/ic/mk48txx.c    |  45 ++++++++++++++++++++++++++++++++++-----------
 sys/dev/ic/mk48txxreg.h |   8 ++++++--
 sys/dev/ic/mk48txxvar.h |   3 ++-
 3 files changed, 42 insertions(+), 14 deletions(-)

diffs (148 lines):

diff -r 4c4d544a9d7c -r bc5671de7b55 sys/dev/ic/mk48txx.c
--- a/sys/dev/ic/mk48txx.c      Tue Jan 04 01:26:22 2011 +0000
+++ b/sys/dev/ic/mk48txx.c      Tue Jan 04 01:28:15 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mk48txx.c,v 1.25 2008/04/28 20:23:50 martin Exp $ */
+/*     $NetBSD: mk48txx.c,v 1.26 2011/01/04 01:28:15 matt Exp $ */
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mk48txx.c,v 1.25 2008/04/28 20:23:50 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mk48txx.c,v 1.26 2011/01/04 01:28:15 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -50,7 +50,7 @@
 uint8_t mk48txx_def_nvrd(struct mk48txx_softc *, int);
 void mk48txx_def_nvwr(struct mk48txx_softc *, int, uint8_t);
 
-struct {
+const struct {
        const char *name;
        bus_size_t nvramsz;
        bus_size_t clkoff;
@@ -61,6 +61,7 @@
        { "mk48t08", MK48T08_CLKSZ, MK48T08_CLKOFF, 0 },
        { "mk48t18", MK48T18_CLKSZ, MK48T18_CLKOFF, 0 },
        { "mk48t59", MK48T59_CLKSZ, MK48T59_CLKOFF, MK48TXX_EXT_REGISTERS },
+       { "ds1553", DS1553_CLKSZ, DS1553_CLKOFF, MK48TXX_EXT_REGISTERS },
 };
 
 void
@@ -127,10 +128,14 @@
        dt->dt_mon = FROMBCD((*sc->sc_nvrd)(sc, clkoff + MK48TXX_IMON));
        year = FROMBCD((*sc->sc_nvrd)(sc, clkoff + MK48TXX_IYEAR));
 
-       year += sc->sc_year0;
-       if (year < POSIX_BASE_YEAR &&
-           (sc->sc_flag & MK48TXX_NO_CENT_ADJUST) == 0)
-               year += 100;
+       if (sc->sc_flag & MK48TXX_HAVE_CENT_REG) {
+               year += 100*FROMBCD(csr & MK48TXX_CSR_CENT_MASK);
+       } else {
+               year += sc->sc_year0;
+               if (year < POSIX_BASE_YEAR &&
+                   (sc->sc_flag & MK48TXX_NO_CENT_ADJUST) == 0)
+                       year += 100;
+       }
 
        dt->dt_year = year;
 
@@ -154,14 +159,21 @@
        bus_size_t clkoff;
        uint8_t csr;
        int year;
+       int cent;
 
        sc = handle->cookie;
        clkoff = sc->sc_clkoffset;
 
-       year = dt->dt_year - sc->sc_year0;
-       if (year > 99 &&
-           (sc->sc_flag & MK48TXX_NO_CENT_ADJUST) == 0)
-               year -= 100;
+       if ((sc->sc_flag & MK48TXX_HAVE_CENT_REG) == 0) {
+               cent = 0;
+               year = dt->dt_year - sc->sc_year0;
+               if (year > 99 &&
+                   (sc->sc_flag & MK48TXX_NO_CENT_ADJUST) == 0)
+                       year -= 100;
+       } else {
+               cent = dt->dt_year / 100;
+               year = dt->dt_year % 100;
+       }
 
        todr_wenable(handle, 1);
        /* enable write */
@@ -177,6 +189,17 @@
        (*sc->sc_nvwr)(sc, clkoff + MK48TXX_IMON, TOBCD(dt->dt_mon));
        (*sc->sc_nvwr)(sc, clkoff + MK48TXX_IYEAR, TOBCD(year));
 
+       /*
+        * If we have a century register and the century has changed
+        * update it.
+        */
+       if ((sc->sc_flag & MK48TXX_HAVE_CENT_REG)
+           && (csr & MK48TXX_CSR_CENT_MASK) != TOBCD(cent)) {
+               csr &= ~MK48TXX_CSR_CENT_MASK;
+               csr |= MK48TXX_CSR_CENT_MASK & TOBCD(cent);
+               (*sc->sc_nvwr)(sc, clkoff + MK48TXX_ICSR, csr);
+       }
+
        /* load them up */
        csr = (*sc->sc_nvrd)(sc, clkoff + MK48TXX_ICSR);
        csr &= ~MK48TXX_CSR_WRITE;
diff -r 4c4d544a9d7c -r bc5671de7b55 sys/dev/ic/mk48txxreg.h
--- a/sys/dev/ic/mk48txxreg.h   Tue Jan 04 01:26:22 2011 +0000
+++ b/sys/dev/ic/mk48txxreg.h   Tue Jan 04 01:28:15 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mk48txxreg.h,v 1.10 2008/04/28 20:23:50 martin Exp $ */
+/*     $NetBSD: mk48txxreg.h,v 1.11 2011/01/04 01:28:15 matt Exp $ */
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -57,7 +57,7 @@
 #define MK48TXX_IADAY  5       /* alarm day (1..31; BCD) */
 #define MK48TXX_IINTR  6       /* interrupts */
 #define MK48TXX_IWDOG  7       /* watchdog */
-#define MK48TXX_ICSR   8       /* control register */
+#define MK48TXX_ICSR   8       /* control register / century (DS1553) */
 #define MK48TXX_ISEC   9       /* seconds (0..59; BCD) */
 #define MK48TXX_IMIN   10      /* minutes (0..59; BCD) */
 #define MK48TXX_IHOUR  11      /* hour (0..23; BCD) */
@@ -88,6 +88,7 @@
 /* Bits in the control register */
 #define MK48TXX_CSR_WRITE      0x80    /* want to write */
 #define MK48TXX_CSR_READ       0x40    /* want to read (freeze clock) */
+#define MK48TXX_CSR_CENT_MASK  0x3f    /* century mask */
 
 /* Bit in the weekday register */
 #define MK48TXX_WDAY_FT                0x40    /* freq test: toggle sec[0] at 512Hz */
@@ -109,3 +110,6 @@
 
 #define MK48T59_CLKSZ          8192
 #define MK48T59_CLKOFF         0x1ff0
+
+#define        DS1553_CLKSZ            8192
+#define        DS1553_CLKOFF           0x1ff0
diff -r 4c4d544a9d7c -r bc5671de7b55 sys/dev/ic/mk48txxvar.h
--- a/sys/dev/ic/mk48txxvar.h   Tue Jan 04 01:26:22 2011 +0000
+++ b/sys/dev/ic/mk48txxvar.h   Tue Jan 04 01:28:15 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mk48txxvar.h,v 1.6 2008/04/28 20:23:50 martin Exp $ */
+/*     $NetBSD: mk48txxvar.h,v 1.7 2011/01/04 01:28:15 matt Exp $ */
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -48,6 +48,7 @@
                                           counter at 0 */
        u_int           sc_flag;
 #define MK48TXX_NO_CENT_ADJUST 0x0001
+#define MK48TXX_HAVE_CENT_REG  0x0002
 
        mk48txx_nvrd_t  sc_nvrd;        /* NVRAM/RTC read function */
        mk48txx_nvwr_t  sc_nvwr;        /* NVRAM/RTC write function */



Home | Main Index | Thread Index | Old Index