Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Switch to using todr_[gs]ettime_ymdhms() format



details:   https://anonhg.NetBSD.org/src/rev/20725dcc8c29
branches:  trunk
changeset: 749910:20725dcc8c29
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sat Dec 12 16:12:05 2009 +0000

description:
Switch to using todr_[gs]ettime_ymdhms() format
which don't require struct timeval details.
Also fix a botch calling MI todr_settime(9) without rtc_offset adjustment.

diffstat:

 sys/dev/ic/mm58167.c |  66 ++++++++++++++++++++++-----------------------------
 1 files changed, 28 insertions(+), 38 deletions(-)

diffs (167 lines):

diff -r e6ddfe948678 -r 20725dcc8c29 sys/dev/ic/mm58167.c
--- a/sys/dev/ic/mm58167.c      Sat Dec 12 15:25:32 2009 +0000
+++ b/sys/dev/ic/mm58167.c      Sat Dec 12 16:12:05 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mm58167.c,v 1.13 2009/12/12 14:44:10 tsutsui Exp $     */
+/*     $NetBSD: mm58167.c,v 1.14 2009/12/12 16:12:05 tsutsui Exp $     */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mm58167.c,v 1.13 2009/12/12 14:44:10 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mm58167.c,v 1.14 2009/12/12 16:12:05 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -46,8 +46,8 @@
 #include <dev/clock_subr.h>
 #include <dev/ic/mm58167var.h>
 
-int mm58167_gettime(todr_chip_handle_t, struct timeval *);
-int mm58167_settime(todr_chip_handle_t, struct timeval *);
+static int mm58167_gettime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
+static int mm58167_settime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
 
 /*
  * To quote SunOS's todreg.h:
@@ -70,8 +70,8 @@
        handle = &sc->_mm58167_todr_handle;
        memset(handle, 0, sizeof(handle));
        handle->cookie = sc;
-       handle->todr_gettime = mm58167_gettime;
-       handle->todr_settime = mm58167_settime;
+       handle->todr_gettime_ymdhms = mm58167_gettime_ymdhms;
+       handle->todr_settime_ymdhms = mm58167_settime_ymdhms;
        return handle;
 }
 
@@ -79,10 +79,9 @@
  * Set up the system's time, given a `reasonable' time value.
  */
 int
-mm58167_gettime(todr_chip_handle_t handle, struct timeval *tv)
+mm58167_gettime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
 {
        struct mm58167_softc *sc = handle->cookie;
-       struct clock_ymdhms dt_hardware;
        struct clock_ymdhms dt_reasonable;
        struct timeval now;
        int s;
@@ -105,7 +104,7 @@
        do {
 #define _MM58167_GET(dt_f, mm_f)                                       \
        byte_value = mm58167_read(sc, mm_f);                            \
-       dt_hardware.dt_f = FROMBCD(byte_value)
+       dt->dt_f = FROMBCD(byte_value)
 
                _MM58167_GET(dt_mon, mm58167_mon);
                _MM58167_GET(dt_day, mm58167_day);
@@ -135,24 +134,20 @@
         * HH:MM:SS, call it the reasonable year plus one, else call
         * it the reasonable year.
         */
-       if (dt_hardware.dt_mon < dt_reasonable.dt_mon ||
-           (dt_hardware.dt_mon == dt_reasonable.dt_mon &&
-            (dt_hardware.dt_day < dt_reasonable.dt_day ||
-             (dt_hardware.dt_day == dt_reasonable.dt_day &&
-              (dt_hardware.dt_hour < dt_reasonable.dt_hour ||
-               (dt_hardware.dt_hour == dt_reasonable.dt_hour &&
-                (dt_hardware.dt_min < dt_reasonable.dt_min ||
-                 (dt_hardware.dt_min == dt_reasonable.dt_min &&
-                  (dt_hardware.dt_sec < dt_reasonable.dt_sec))))))))) {
-               dt_hardware.dt_year = dt_reasonable.dt_year + 1;
+       if (dt->dt_mon < dt_reasonable.dt_mon ||
+           (dt->dt_mon == dt_reasonable.dt_mon &&
+            (dt->dt_day < dt_reasonable.dt_day ||
+             (dt->dt_day == dt_reasonable.dt_day &&
+              (dt->dt_hour < dt_reasonable.dt_hour ||
+               (dt->dt_hour == dt_reasonable.dt_hour &&
+                (dt->dt_min < dt_reasonable.dt_min ||
+                 (dt->dt_min == dt_reasonable.dt_min &&
+                  (dt->dt_sec < dt_reasonable.dt_sec))))))))) {
+               dt->dt_year = dt_reasonable.dt_year + 1;
        } else {
-               dt_hardware.dt_year = dt_reasonable.dt_year;
+               dt->dt_year = dt_reasonable.dt_year;
        }
 
-       /* convert the hardware date into a time: */
-       tv->tv_sec = clock_ymdhms_to_secs(&dt_hardware);
-       tv->tv_usec = 0;
-
        /*
         * Make a reasonable effort to see if a leap day has passed
         * that we need to account for.  This does the right thing
@@ -169,9 +164,9 @@
         * March in the following year.  Check that following year for
         * a leap day.
         */
-       if (dt_hardware.dt_year > dt_reasonable.dt_year &&
-           dt_hardware.dt_mon >= 3) {
-               leap_year = dt_hardware.dt_year;
+       if (dt->dt_year > dt_reasonable.dt_year &&
+           dt->dt_mon >= 3) {
+               leap_year = dt->dt_year;
        }
 
        /*
@@ -180,7 +175,7 @@
         * the previous year.  check that previous year for a leap
         * day.
         */
-       else if (dt_hardware.dt_year > dt_reasonable.dt_year &&
+       else if (dt->dt_year > dt_reasonable.dt_year &&
            dt_reasonable.dt_mon < 3) {
                leap_year = dt_reasonable.dt_year;
        }
@@ -190,9 +185,9 @@
         * same year, but we weren't to March before, and we're in or
         * past March now.  Check this year for a leap day.
         */
-       else if (dt_hardware.dt_year == dt_reasonable.dt_year
+       else if (dt->dt_year == dt_reasonable.dt_year
            && dt_reasonable.dt_mon < 3
-           && dt_hardware.dt_mon >= 3) {
+           && dt->dt_mon >= 3) {
                leap_year = dt_reasonable.dt_year;
        }
 
@@ -227,24 +222,19 @@
         * Use NTP to deal.
         */
        if (had_leap_day) {
-               tv->tv_sec += SECDAY;
-               todr_settime(handle, tv);
+               mm58167_settime_ymdhms(handle, dt);
        }
 
        return 0;
 }
 
 int
-mm58167_settime(todr_chip_handle_t handle, struct timeval *tv)
+mm58167_settime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
 {
        struct mm58167_softc *sc = handle->cookie;
-       struct clock_ymdhms dt_hardware;
        int s;
        uint8_t byte_value;
 
-       /* Convert the seconds into ymdhms. */
-       clock_secs_to_ymdhms(tv->tv_sec, &dt_hardware);
-
        /* No interrupts while we're in the chip. */
        s = splhigh();
 
@@ -256,7 +246,7 @@
 
        /* Load everything. */
 #define _MM58167_PUT(dt_f, mm_f)                                       \
-       byte_value = TOBCD(dt_hardware.dt_f);                           \
+       byte_value = TOBCD(dt->dt_f);                                   \
        mm58167_write(sc, mm_f, byte_value)
 
        _MM58167_PUT(dt_mon, mm58167_mon);



Home | Main Index | Thread Index | Old Index