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.
This commit is contained in:
tsutsui 2009-12-12 16:12:05 +00:00
parent aae0dc7c17
commit 698e481cab
1 changed files with 28 additions and 38 deletions

View File

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