diff --git a/sys/arch/x68k/dev/rtclock.c b/sys/arch/x68k/dev/rtclock.c index 2eb6d502a271..9912eb637af0 100644 --- a/sys/arch/x68k/dev/rtclock.c +++ b/sys/arch/x68k/dev/rtclock.c @@ -1,4 +1,4 @@ -/* $NetBSD: rtclock.c,v 1.18 2005/12/11 12:19:37 christos Exp $ */ +/* $NetBSD: rtclock.c,v 1.19 2006/09/14 01:18:11 gdamore Exp $ */ /* * Copyright 1993, 1994 Masaru Oki @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rtclock.c,v 1.18 2005/12/11 12:19:37 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtclock.c,v 1.19 2006/09/14 01:18:11 gdamore Exp $"); #include #include @@ -55,8 +55,8 @@ __KERNEL_RCSID(0, "$NetBSD: rtclock.c,v 1.18 2005/12/11 12:19:37 christos Exp $" #include #include -static time_t rtgettod(void); -static int rtsettod(long); +static int rtgettod(todr_chip_handle_t, struct clock_ymdhms *); +static int rtsettod(todr_chip_handle_t, struct clock_ymdhms *); static int rtc_match(struct device *, struct cfdata *, void *); static void rtc_attach(struct device *, struct device *, void *); @@ -87,9 +87,6 @@ rtc_match(struct device *parent, struct cfdata *cf, void *aux) return (1); } - -static struct rtc_softc *rtc; /* XXX: softc cache */ - static void rtc_attach(struct device *parent, struct device *self, void *aux) { @@ -109,65 +106,42 @@ rtc_attach(struct device *parent, struct device *self, void *aux) sc->sc_bst = ia->ia_bst; bus_space_map(sc->sc_bst, ia->ia_addr, 0x2000, 0, &sc->sc_bht); - rtc = sc; - rtclockinit(); + sc->sc_todr.cookie = sc; + sc->sc_todr.todr_gettime_ymdhms = rtgettod; + sc->sc_todr.todr_settime_ymdhms = rtsettod; + todr_attach(&sc->sc_todr); + printf (": RP5C15\n"); } - - -/* - * x68k/clock.c calls thru the get/set tod vector, if it is set, to read - * the realtime clock. - */ - -int -rtclockinit(void) +static int +rtgettod(todr_chip_handle_t tch, struct clock_ymdhms *dt) { - if (rtgettod()) { - gettod = rtgettod; - settod = rtsettod; - } else { - return 0; - } - return 1; -} - -static time_t -rtgettod(void) -{ - struct clock_ymdhms dt; + struct rtc_softc *rtc = tch->cookie; /* hold clock */ RTC_WRITE(RTC_MODE, RTC_HOLD_CLOCK); /* read it */ - dt.dt_sec = RTC_REG(RTC_SEC10) * 10 + RTC_REG(RTC_SEC); - dt.dt_min = RTC_REG(RTC_MIN10) * 10 + RTC_REG(RTC_MIN); - dt.dt_hour = RTC_REG(RTC_HOUR10) * 10 + RTC_REG(RTC_HOUR); - dt.dt_day = RTC_REG(RTC_DAY10) * 10 + RTC_REG(RTC_DAY); - dt.dt_mon = RTC_REG(RTC_MON10) * 10 + RTC_REG(RTC_MON); - dt.dt_year = RTC_REG(RTC_YEAR10) * 10 + RTC_REG(RTC_YEAR) + dt->dt_sec = RTC_REG(RTC_SEC10) * 10 + RTC_REG(RTC_SEC); + dt->dt_min = RTC_REG(RTC_MIN10) * 10 + RTC_REG(RTC_MIN); + dt->dt_hour = RTC_REG(RTC_HOUR10) * 10 + RTC_REG(RTC_HOUR); + dt->dt_day = RTC_REG(RTC_DAY10) * 10 + RTC_REG(RTC_DAY); + dt->dt_mon = RTC_REG(RTC_MON10) * 10 + RTC_REG(RTC_MON); + dt->dt_year = RTC_REG(RTC_YEAR10) * 10 + RTC_REG(RTC_YEAR) +RTC_BASE_YEAR; /* let it run again.. */ RTC_WRITE(RTC_MODE, RTC_FREE_CLOCK); -#ifdef DIAGNOSTIC - range_test0(dt.dt_hour, 23); - range_test(dt.dt_day, 1, 31); - range_test(dt.dt_mon, 1, 12); - range_test(dt.dt_year, RTC_BASE_YEAR, RTC_BASE_YEAR+100-1); -#endif - - return clock_ymdhms_to_secs (&dt) + rtc_offset * 60; + return 0; } static int -rtsettod(time_t tim) +rtsettod(todr_chip_handle_t tch, struct clock_ymdhms *dt) { - struct clock_ymdhms dt; + struct rtc_softc *rtc = tch->cookie; u_char sec1, sec2; u_char min1, min2; u_char hour1, hour2; @@ -175,22 +149,20 @@ rtsettod(time_t tim) u_char mon1, mon2; u_char year1, year2; - clock_secs_to_ymdhms (tim - rtc_offset * 60, &dt); - /* prepare values to be written to clock */ - sec1 = dt.dt_sec / 10; - sec2 = dt.dt_sec % 10; - min1 = dt.dt_min / 10; - min2 = dt.dt_min % 10; - hour1 = dt.dt_hour / 10; - hour2 = dt.dt_hour % 10; + sec1 = dt->dt_sec / 10; + sec2 = dt->dt_sec % 10; + min1 = dt->dt_min / 10; + min2 = dt->dt_min % 10; + hour1 = dt->dt_hour / 10; + hour2 = dt->dt_hour % 10; - day1 = dt.dt_day / 10; - day2 = dt.dt_day % 10; - mon1 = dt.dt_mon / 10; - mon2 = dt.dt_mon % 10; - year1 = (dt.dt_year - RTC_BASE_YEAR) / 10; - year2 = dt.dt_year % 10; + day1 = dt->dt_day / 10; + day2 = dt->dt_day % 10; + mon1 = dt->dt_mon / 10; + mon2 = dt->dt_mon % 10; + year1 = (dt->dt_year - RTC_BASE_YEAR) / 10; + year2 = dt->dt_year % 10; RTC_WRITE(RTC_MODE, RTC_HOLD_CLOCK); RTC_WRITE(RTC_SEC10, sec1); @@ -207,5 +179,5 @@ rtsettod(time_t tim) RTC_WRITE(RTC_YEAR, year2); RTC_WRITE(RTC_MODE, RTC_FREE_CLOCK); - return 1; + return 0; } diff --git a/sys/arch/x68k/dev/rtclock_var.h b/sys/arch/x68k/dev/rtclock_var.h index 9b7e5daeaa02..033fa4e9c6f9 100644 --- a/sys/arch/x68k/dev/rtclock_var.h +++ b/sys/arch/x68k/dev/rtclock_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: rtclock_var.h,v 1.7 2005/12/11 12:19:37 christos Exp $ */ +/* $NetBSD: rtclock_var.h,v 1.8 2006/09/14 01:18:11 gdamore Exp $ */ /* * Copyright 1993, 1994 Masaru Oki @@ -42,6 +42,7 @@ struct rtc_softc { bus_space_tag_t sc_bst; bus_space_handle_t sc_bht; + struct todr_chip_handle sc_todr; }; /* diff --git a/sys/arch/x68k/include/types.h b/sys/arch/x68k/include/types.h index 0b5226b97868..f7a70bafed66 100644 --- a/sys/arch/x68k/include/types.h +++ b/sys/arch/x68k/include/types.h @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.9 2005/12/11 12:19:44 christos Exp $ */ +/* $NetBSD: types.h,v 1.10 2006/09/14 01:18:11 gdamore Exp $ */ #ifndef _MACHINE_TYPES_H_ #define _MACHINE_TYPES_H_ @@ -6,5 +6,6 @@ #include #define __HAVE_DEVICE_REGISTER +#define __HAVE_GENERIC_TODR #endif diff --git a/sys/arch/x68k/x68k/clock.c b/sys/arch/x68k/x68k/clock.c index 448366735c2b..dfcc223e53f2 100644 --- a/sys/arch/x68k/x68k/clock.c +++ b/sys/arch/x68k/x68k/clock.c @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.22 2005/12/24 22:45:40 perry Exp $ */ +/* $NetBSD: clock.c,v 1.23 2006/09/14 01:18:11 gdamore Exp $ */ /* * Copyright (c) 1982, 1990, 1993 @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.22 2005/12/24 22:45:40 perry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.23 2006/09/14 01:18:11 gdamore Exp $"); #include "clock.h" @@ -535,46 +535,6 @@ microtime(struct timeval *tvp) lasttime = *tvp; } -/* this is a hook set by a clock driver for the configured realtime clock, - returning plain current unix-time */ -time_t (*gettod)(void) = 0; -int (*settod)(long) = 0; - -/* - * Initialize the time of day register, based on the time base which is, e.g. - * from a filesystem. - */ -void -inittodr(time_t base) -{ - u_long timbuf = base; /* assume no battery clock exists */ - - if (!gettod) - printf ("WARNING: no battery clock\n"); - else - timbuf = gettod(); - - if (timbuf < base) { - printf ("WARNING: bad date in battery clock\n"); - timbuf = base; - } - if (base < 5*SECYR) { - printf("WARNING: preposterous time in file system"); - timbuf = 6*SECYR + 186*SECDAY + SECDAY/2; - printf(" -- CHECK AND RESET THE DATE!\n"); - } - - /* Battery clock does not store usec's, so forget about it. */ - time.tv_sec = timbuf; -} - -void -resettodr(void) -{ - if (settod) - if (settod (time.tv_sec) != 1) - printf("Cannot set battery backed clock\n"); -} #else /* NCLOCK */ #error loose. #endif