--- /dev/null 2003-10-30 02:56:31.000000000 +0900 +++ dev/ic/mk48txxvar.h 2003-10-31 23:45:43.000000000 +0900 @@ -0,0 +1,67 @@ +/* $NetBSD$ */ +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +struct mk48txx_softc; + +typedef u_int8_t (*mk48txx_nvrd_t)(struct mk48txx_softc *, int); +typedef void (*mk48txx_nvwr_t)(struct mk48txx_softc *, int, u_int8_t); + +struct mk48txx_softc { + struct device sc_dev; + + bus_space_tag_t sc_bst; /* bus tag & handle */ + bus_space_handle_t sc_bsh; /* */ + + struct todr_chip_handle sc_handle; /* TODR handle */ + const char *sc_model; /* chip model name */ + bus_size_t sc_nvramsz; /* Size of NVRAM on the chip */ + bus_size_t sc_clkoffset; /* Offset in NVRAM to clock bits */ + u_int sc_year0; /* What year is represented on + the system by the chip's year + counter at 0 */ + u_int sc_flag; +#define MK48TXX_NO_CENT_ADJUST 0x0001 + + mk48txx_nvrd_t sc_nvrd; /* NVRAM/RTC read function */ + mk48txx_nvwr_t sc_nvwr; /* NVRAM/RTC write function */ +}; + +/* Chip attach function */ +void mk48txx_attach(struct mk48txx_softc *); + +/* Retrieve size of the on-chip NVRAM area */ +int mk48txx_get_nvram_size(todr_chip_handle_t, bus_size_t *); Index: dev/ic/mk48txx.c =================================================================== RCS file: /cvsroot/src/sys/dev/ic/mk48txx.c,v retrieving revision 1.11 diff -u -r1.11 mk48txx.c --- dev/ic/mk48txx.c 30 Oct 2003 21:19:02 -0000 1.11 +++ dev/ic/mk48txx.c 31 Oct 2003 14:51:46 -0000 @@ -43,34 +43,21 @@ __KERNEL_RCSID(0, "$NetBSD: mk48txx.c,v 1.11 2003/10/30 21:19:02 matt Exp $"); #include -#include #include +#include #include #include #include #include - - -struct mk48txx { - bus_space_tag_t mk_bt; /* bus tag & handle */ - bus_space_handle_t mk_bh; /* */ - bus_size_t mk_nvramsz; /* Size of NVRAM on the chip */ - bus_size_t mk_clkoffset; /* Offset in NVRAM to clock bits */ - u_int mk_year0; /* What year is represented on the system - by the chip's year counter at 0 */ - mk48txx_nvrd_t mk_nvrd; /* NVRAM/RTC read function */ - mk48txx_nvwr_t mk_nvwr; /* NVRAM/RTC write function */ -}; +#include int mk48txx_gettime(todr_chip_handle_t, struct timeval *); int mk48txx_settime(todr_chip_handle_t, struct timeval *); int mk48txx_getcal(todr_chip_handle_t, int *); int mk48txx_setcal(todr_chip_handle_t, int); -u_int8_t mk48txx_def_nvrd(bus_space_tag_t, bus_space_handle_t, int); -void mk48txx_def_nvwr(bus_space_tag_t, bus_space_handle_t, int, u_int8_t); - -int mk48txx_auto_century_adjust = 1; +u_int8_t mk48txx_def_nvrd(struct mk48txx_softc *, int); +void mk48txx_def_nvwr(struct mk48txx_softc *, int, u_int8_t); struct { const char *name; @@ -85,60 +72,38 @@ { "mk48t59", MK48T59_CLKSZ, MK48T59_CLKOFF, MK48TXX_EXT_REGISTERS }, }; -todr_chip_handle_t -mk48txx_attach(bt, bh, model, year0, nvread, nvwrite) - bus_space_tag_t bt; - bus_space_handle_t bh; - const char *model; - int year0; - mk48txx_nvrd_t nvread; - mk48txx_nvwr_t nvwrite; +void +mk48txx_attach(sc) + struct mk48txx_softc *sc; { todr_chip_handle_t handle; - struct mk48txx *mk; - bus_size_t nvramsz, clkoff; - int sz; int i; - printf(": %s", model); + printf(": %s", sc->sc_model); - i = sizeof(mk48txx_models)/sizeof(mk48txx_models[0]); + i = sizeof(mk48txx_models) / sizeof(mk48txx_models[0]); while (--i >= 0) { - if (strcmp(model, mk48txx_models[i].name) == 0) + if (strcmp(sc->sc_model, mk48txx_models[i].name) == 0) break; } - if (i < 0) { - printf(": unsupported model"); - return (NULL); - } - nvramsz = mk48txx_models[i].nvramsz; - clkoff = mk48txx_models[i].clkoff; + if (i < 0) + panic("mk48txx_attach: unsupported model"); - sz = ALIGN(sizeof(struct todr_chip_handle)) + sizeof(struct mk48txx); - handle = malloc(sz, M_DEVBUF, M_NOWAIT); - mk = (struct mk48txx *)((u_long)handle + - ALIGN(sizeof(struct todr_chip_handle))); - handle->cookie = mk; + sc->sc_nvramsz = mk48txx_models[i].nvramsz; + sc->sc_clkoffset = mk48txx_models[i].clkoff; + + handle = &sc->sc_handle; + handle->cookie = sc; handle->todr_gettime = mk48txx_gettime; handle->todr_settime = mk48txx_settime; handle->todr_getcal = mk48txx_getcal; handle->todr_setcal = mk48txx_setcal; handle->todr_setwen = NULL; - mk->mk_bt = bt; - mk->mk_bh = bh; - mk->mk_nvramsz = nvramsz; - mk->mk_clkoffset = clkoff; - mk->mk_year0 = year0; - - if (nvread == NULL) - nvread = mk48txx_def_nvrd; - if (nvwrite == NULL) - nvwrite = mk48txx_def_nvwr; - - mk->mk_nvrd = nvread; - mk->mk_nvwr = nvwrite; - return (handle); + if (sc->sc_nvrd == NULL) + sc->sc_nvrd = mk48txx_def_nvrd; + if (sc->sc_nvwr == NULL) + sc->sc_nvwr = mk48txx_def_nvwr; } /* @@ -150,49 +115,51 @@ todr_chip_handle_t handle; struct timeval *tv; { - struct mk48txx *mk = handle->cookie; - bus_space_tag_t bt = mk->mk_bt; - bus_space_handle_t bh = mk->mk_bh; - bus_size_t clkoff = mk->mk_clkoffset; + struct mk48txx_softc *sc; + bus_size_t clkoff; struct clock_ymdhms dt; int year; u_int8_t csr; + sc = handle->cookie; + clkoff = sc->sc_clkoffset; + todr_wenable(handle, 1); /* enable read (stop time) */ - csr = (*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ICSR); + csr = (*sc->sc_nvrd)(sc, clkoff + MK48TXX_ICSR); csr |= MK48TXX_CSR_READ; - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ICSR, csr); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_ICSR, csr); - dt.dt_sec = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ISEC)); - dt.dt_min = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IMIN)); - dt.dt_hour = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IHOUR)); - dt.dt_day = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IDAY)); - dt.dt_wday = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IWDAY)); - dt.dt_mon = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IMON)); - year = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IYEAR)); - - year += mk->mk_year0; - if (year < POSIX_BASE_YEAR && mk48txx_auto_century_adjust != 0) + dt.dt_sec = FROMBCD((*sc->sc_nvrd)(sc, clkoff + MK48TXX_ISEC)); + dt.dt_min = FROMBCD((*sc->sc_nvrd)(sc, clkoff + MK48TXX_IMIN)); + dt.dt_hour = FROMBCD((*sc->sc_nvrd)(sc, clkoff + MK48TXX_IHOUR)); + dt.dt_day = FROMBCD((*sc->sc_nvrd)(sc, clkoff + MK48TXX_IDAY)); + dt.dt_wday = FROMBCD((*sc->sc_nvrd)(sc, clkoff + MK48TXX_IWDAY)); + 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; dt.dt_year = year; /* time wears on */ - csr = (*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ICSR); + csr = (*sc->sc_nvrd)(sc, clkoff + MK48TXX_ICSR); csr &= ~MK48TXX_CSR_READ; - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ICSR, csr); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_ICSR, csr); todr_wenable(handle, 0); /* simple sanity checks */ if (dt.dt_mon > 12 || dt.dt_day > 31 || dt.dt_hour >= 24 || dt.dt_min >= 60 || dt.dt_sec >= 60) - return (1); + return EIO; tv->tv_sec = clock_ymdhms_to_secs(&dt); tv->tv_usec = 0; - return (0); + return 0; } /* @@ -204,41 +171,43 @@ todr_chip_handle_t handle; struct timeval *tv; { - struct mk48txx *mk = handle->cookie; - bus_space_tag_t bt = mk->mk_bt; - bus_space_handle_t bh = mk->mk_bh; - bus_size_t clkoff = mk->mk_clkoffset; + struct mk48txx_softc *sc; + bus_size_t clkoff; struct clock_ymdhms dt; u_int8_t csr; int year; + sc = handle->cookie; + clkoff = sc->sc_clkoffset; + /* Note: we ignore `tv_usec' */ clock_secs_to_ymdhms(tv->tv_sec, &dt); - year = dt.dt_year - mk->mk_year0; - if (year > 99 && mk48txx_auto_century_adjust != 0) + year = dt.dt_year - sc->sc_year0; + if (year > 99 && + (sc->sc_flag & MK48TXX_NO_CENT_ADJUST) == 0) year -= 100; todr_wenable(handle, 1); /* enable write */ - csr = (*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ICSR); + csr = (*sc->sc_nvrd)(sc, clkoff + MK48TXX_ICSR); csr |= MK48TXX_CSR_WRITE; - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ICSR, csr); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_ICSR, csr); - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ISEC, TOBCD(dt.dt_sec)); - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IMIN, TOBCD(dt.dt_min)); - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IHOUR, TOBCD(dt.dt_hour)); - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IWDAY, TOBCD(dt.dt_wday)); - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IDAY, TOBCD(dt.dt_day)); - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IMON, TOBCD(dt.dt_mon)); - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IYEAR, TOBCD(year)); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_ISEC, TOBCD(dt.dt_sec)); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_IMIN, TOBCD(dt.dt_min)); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_IHOUR, TOBCD(dt.dt_hour)); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_IWDAY, TOBCD(dt.dt_wday)); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_IDAY, TOBCD(dt.dt_day)); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_IMON, TOBCD(dt.dt_mon)); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_IYEAR, TOBCD(year)); /* load them up */ - csr = (*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ICSR); + csr = (*sc->sc_nvrd)(sc, clkoff + MK48TXX_ICSR); csr &= ~MK48TXX_CSR_WRITE; - (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ICSR, csr); + (*sc->sc_nvwr)(sc, clkoff + MK48TXX_ICSR, csr); todr_wenable(handle, 0); - return (0); + return 0; } int @@ -246,7 +215,8 @@ todr_chip_handle_t handle; int *vp; { - return (EOPNOTSUPP); + + return EOPNOTSUPP; } int @@ -254,7 +224,8 @@ todr_chip_handle_t handle; int v; { - return (EOPNOTSUPP); + + return EOPNOTSUPP; } int @@ -262,21 +233,23 @@ todr_chip_handle_t handle; bus_size_t *vp; { - struct mk48txx *mk = handle->cookie; - *vp = mk->mk_nvramsz; - return (0); + struct mk48txx_softc *sc; + + sc = handle->cookie; + *vp = sc->sc_nvramsz; + return 0; } u_int8_t -mk48txx_def_nvrd(bus_space_tag_t bt, bus_space_handle_t bh, int off) +mk48txx_def_nvrd(struct mk48txx_softc *sc, int off) { - return (bus_space_read_1(bt, bh, off)); + return bus_space_read_1(sc->sc_bst, sc->sc_bsh, off); } void -mk48txx_def_nvwr(bus_space_tag_t bt, bus_space_handle_t bh, int off, u_int8_t v) +mk48txx_def_nvwr(struct mk48txx_softc *sc, int off, u_int8_t v) { - bus_space_write_1(bt, bh, off, v); + bus_space_write_1(sc->sc_bst, sc->sc_bsh, off, v); } Index: dev/ic/mk48txxreg.h =================================================================== RCS file: /cvsroot/src/sys/dev/ic/mk48txxreg.h,v retrieving revision 1.6 diff -u -r1.6 mk48txxreg.h --- dev/ic/mk48txxreg.h 23 Feb 2002 17:18:56 -0000 1.6 +++ dev/ic/mk48txxreg.h 31 Oct 2003 14:51:46 -0000 @@ -83,14 +83,3 @@ #define MK48T59_CLKSZ 8192 #define MK48T59_CLKOFF 0x1ff0 - -typedef u_int8_t (*mk48txx_nvrd_t)(bus_space_tag_t, bus_space_handle_t, int); -typedef void (*mk48txx_nvwr_t)(bus_space_tag_t, bus_space_handle_t, int, - u_int8_t); - -/* Chip attach function */ -todr_chip_handle_t mk48txx_attach(bus_space_tag_t, bus_space_handle_t, - const char *, int, mk48txx_nvrd_t, mk48txx_nvwr_t); - -/* Retrieve size of the on-chip NVRAM area */ -int mk48txx_get_nvram_size(todr_chip_handle_t, bus_size_t *); Index: dev/mvme/clockvar.h =================================================================== RCS file: /cvsroot/src/sys/dev/mvme/clockvar.h,v retrieving revision 1.3 diff -u -r1.3 clockvar.h --- dev/mvme/clockvar.h 26 Sep 2003 22:25:21 -0000 1.3 +++ dev/mvme/clockvar.h 31 Oct 2003 14:51:46 -0000 @@ -40,7 +40,6 @@ #define _MVME_CLOCKVAR_H #include -#include /* * Definitions exported to ASIC-specific clock attachment. Index: arch/mvme68k/dev/timekeeper.c =================================================================== RCS file: /cvsroot/src/sys/arch/mvme68k/dev/timekeeper.c,v retrieving revision 1.7 diff -u -r1.7 timekeeper.c --- arch/mvme68k/dev/timekeeper.c 18 Jul 2003 21:41:22 -0000 1.7 +++ arch/mvme68k/dev/timekeeper.c 31 Oct 2003 14:51:46 -0000 @@ -56,19 +56,15 @@ #include -#include +#include +#include -struct timekeeper_softc { - struct device sc_dev; - bus_space_tag_t sc_bust; - bus_space_handle_t sc_bush; - bus_size_t sc_size; -}; +#include int timekeeper_match(struct device *, struct cfdata *, void *); void timekeeper_attach(struct device *, struct device *, void *); -CFATTACH_DECL(timekeeper, sizeof(struct timekeeper_softc), +CFATTACH_DECL(timekeeper, sizeof(struct mk48txx_softc), timekeeper_match, timekeeper_attach, NULL, NULL); extern struct cfdriver timekeeper_cd; @@ -93,31 +89,28 @@ struct device *self; void *aux; { - struct timekeeper_softc *sc = (struct timekeeper_softc *)self; + struct mk48txx_softc *sc = (void *)self; struct mainbus_attach_args *ma = aux; - todr_chip_handle_t todr; - const char *model; + bus_size_t size; - sc->sc_bust = ma->ma_bust; + sc->sc_bst = ma->ma_bust; if (machineid == MVME_147) { - sc->sc_size = MK48T02_CLKSZ; - model = "mk48t02"; + size = MK48T02_CLKSZ; + sc->sc_model = "mk48t02"; } else { - sc->sc_size = MK48T08_CLKSZ; - model = "mk48t08"; + size = MK48T08_CLKSZ; + sc->sc_model = "mk48t08"; } - bus_space_map(ma->ma_bust, ma->ma_offset, sc->sc_size, 0, &sc->sc_bush); + bus_space_map(sc->sc_bst, ma->ma_offset, size, 0, &sc->sc_bsh); - todr = mk48txx_attach(sc->sc_bust, sc->sc_bush, model, YEAR0, - NULL, NULL); - if (todr == NULL) - panic("\ntimekeeper_attach"); + sc->sc_year0 = YEAR0; + mk48txx_attach(sc); printf(" Time-Keeper RAM\n"); printf("%s: %ld bytes NVRAM plus Realtime Clock\n", - sc->sc_dev.dv_xname, sc->sc_size); + sc->sc_dev.dv_xname, sc->sc_nvramsz); - todr_attach(todr); + todr_attach(&sc->sc_handle); } Index: arch/mvmeppc/isa/mkclock_isa.c =================================================================== RCS file: /cvsroot/src/sys/arch/mvmeppc/isa/mkclock_isa.c,v retrieving revision 1.6 diff -u -r1.6 mkclock_isa.c --- arch/mvmeppc/isa/mkclock_isa.c 18 Jul 2003 21:41:23 -0000 1.6 +++ arch/mvmeppc/isa/mkclock_isa.c 31 Oct 2003 14:51:46 -0000 @@ -53,6 +53,7 @@ #include #include +#include #include @@ -65,34 +66,24 @@ #define MKCLOCK_NPORTS (MKCLOCK_DATA - MKCLOCK_STB0 + 1) -struct mkclock_isa_softc { - struct device sc_dev; /* Base device */ - - bus_space_tag_t sc_iot; /* I/O space access */ - bus_space_handle_t sc_ioh; - - todr_chip_handle_t sc_todr; /* MI todr interface handle */ -}; - - /* Autoconfiguration interface */ int mkclock_isa_match(struct device *, struct cfdata *, void *); void mkclock_isa_attach(struct device *, struct device *, void *); -CFATTACH_DECL(mkclock_isa, sizeof (struct mkclock_isa_softc), +CFATTACH_DECL(mkclock_isa, sizeof (struct mk48txx_softc), mkclock_isa_match, mkclock_isa_attach, NULL, NULL); /* mk48txx interface */ -uint8_t mkclock_isa_nvrd(bus_space_tag_t, bus_space_handle_t, int); -void mkclock_isa_nvwr(bus_space_tag_t, bus_space_handle_t, int, uint8_t); +uint8_t mkclock_isa_nvrd(struct mk48txx_softc *, int); +void mkclock_isa_nvwr(struct mk48txx_softc *, int, uint8_t); int mkclock_isa_match(struct device *parent, struct cfdata *match, void *aux) { struct isa_attach_args *ia = aux; - bus_space_handle_t ioh; + struct mk48txx_softc mk48txx, *sc; uint8_t csr, ocsr; unsigned int t1, t2; int found; @@ -119,34 +110,33 @@ /* * Map I/O space, then try to determine if it's really there. */ - if (bus_space_map(ia->ia_iot, 0x74, MKCLOCK_NPORTS, 0, &ioh)) + sc = &mk48txx; + sc->sc_bst = ia->ia_iot; + if (bus_space_map(sc->sc_bst, 0x74, MKCLOCK_NPORTS, 0, &sc->sc_bsh)) return (0); /* Supposedly no control bits are set after POST; check for this. */ - ocsr = mkclock_isa_nvrd(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR); + ocsr = mkclock_isa_nvrd(sc, MK48T18_CLKOFF + MK48TXX_ICSR); if (ocsr != 0) goto unmap; /* Set clock data to read mode, prohibiting updates from clock. */ csr = ocsr | MK48TXX_CSR_READ; - mkclock_isa_nvwr(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR, csr); + mkclock_isa_nvwr(sc, MK48T18_CLKOFF + MK48TXX_ICSR, csr); /* Compare. */ - if (mkclock_isa_nvrd(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR) - != csr) + if (mkclock_isa_nvrd(sc, MK48T18_CLKOFF + MK48TXX_ICSR) != csr) goto restore; /* Read from the seconds counter. */ - t1 = FROMBCD(mkclock_isa_nvrd(ia->ia_iot, ioh, - MK48T18_CLKOFF + MK48TXX_ISEC)); + t1 = FROMBCD(mkclock_isa_nvrd(sc, MK48T18_CLKOFF + MK48TXX_ISEC)); if (t1 > 59) goto restore; /* Make it tick again, wait, then look again. */ - mkclock_isa_nvwr(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR, ocsr); + mkclock_isa_nvwr(sc, MK48T18_CLKOFF + MK48TXX_ICSR, ocsr); DELAY(1100000); - mkclock_isa_nvwr(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR, csr); - t2 = FROMBCD(mkclock_isa_nvrd(ia->ia_iot, ioh, - MK48T18_CLKOFF + MK48TXX_ISEC)); + mkclock_isa_nvwr(sc, MK48T18_CLKOFF + MK48TXX_ICSR, csr); + t2 = FROMBCD(mkclock_isa_nvrd(sc, MK48T18_CLKOFF + MK48TXX_ISEC)); if (t2 > 59) goto restore; @@ -155,9 +145,9 @@ found = 1; restore: - mkclock_isa_nvwr(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR, ocsr); + mkclock_isa_nvwr(sc, MK48T18_CLKOFF + MK48TXX_ICSR, ocsr); unmap: - bus_space_unmap(ia->ia_iot, ioh, MKCLOCK_NPORTS); + bus_space_unmap(sc->sc_bst, sc->sc_bsh, MKCLOCK_NPORTS); if (found) { ia->ia_nio = 1; @@ -176,34 +166,41 @@ mkclock_isa_attach(struct device *parent, struct device *self, void *aux) { struct isa_attach_args *ia = aux; - struct mkclock_isa_softc *sc = (struct mkclock_isa_softc *)self; + struct mk48txx_softc *sc = (void *)self; /* Map I/O space. */ - sc->sc_iot = ia->ia_iot; - if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, - ia->ia_io[0].ir_size, 0, &sc->sc_ioh)) + sc->sc_bst = ia->ia_iot; + if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr, + ia->ia_io[0].ir_size, 0, &sc->sc_bsh)) panic("mkclock_isa_attach: couldn't map clock I/O space"); /* Attach to MI mk48txx driver. */ - sc->sc_todr = mk48txx_attach(sc->sc_iot, sc->sc_ioh, "mk48t18", 1968, - mkclock_isa_nvrd, mkclock_isa_nvwr); - if (sc->sc_todr == NULL) - panic("\nmkclock_isa_attach: mk48txx attach failed"); + sc->sc_model = "mk48t18"; + sc->sc_year0 = 1968; + sc->sc_nvrd = mkclock_isa_nvrd; + sc->sc_nvwr = mkclock_isa_nvwr; + + mk48txx_attach(sc); printf(" Timekeeper NVRAM/RTC\n"); - todr_attach(sc->sc_todr); + todr_attach(&sc->sc_handle); } /* * Bus access methods for MI mk48txx driver. */ uint8_t -mkclock_isa_nvrd(bus_space_tag_t iot, bus_space_handle_t ioh, int off) +mkclock_isa_nvrd(struct mk48txx_softc *sc, int off) { + bus_space_tag_t iot; + bus_space_handle_t ioh; uint8_t datum; int s; + iot = sc->sc_bst; + ioh = sc->sc_bsh; + s = splclock(); bus_space_write_1(iot, ioh, MKCLOCK_STB0, off & 0xff); bus_space_write_1(iot, ioh, MKCLOCK_STB1, off >> 8); @@ -214,10 +211,14 @@ } void -mkclock_isa_nvwr(bus_space_tag_t iot, bus_space_handle_t ioh, int off, - uint8_t datum) +mkclock_isa_nvwr(struct mk48txx_softc *sc, int off, uint8_t datum) { + bus_space_tag_t iot; + bus_space_handle_t ioh; int s; + + iot = sc->sc_bst; + ioh = sc->sc_bsh; s = splclock(); bus_space_write_1(iot, ioh, MKCLOCK_STB0, off & 0xff); Index: arch/news68k/dev/mkclock_hb.c =================================================================== RCS file: /cvsroot/src/sys/arch/news68k/dev/mkclock_hb.c,v retrieving revision 1.7 diff -u -r1.7 mkclock_hb.c --- arch/news68k/dev/mkclock_hb.c 19 Jul 2003 02:25:21 -0000 1.7 +++ arch/news68k/dev/mkclock_hb.c 31 Oct 2003 14:51:46 -0000 @@ -49,6 +49,7 @@ #include #include +#include #include @@ -57,7 +58,7 @@ int mkclock_hb_match(struct device *, struct cfdata *, void *); void mkclock_hb_attach(struct device *, struct device *, void *); -CFATTACH_DECL(mkclock_hb, sizeof(struct device), +CFATTACH_DECL(mkclock_hb, sizeof(struct mk48txx_softc), mkclock_hb_match, mkclock_hb_attach, NULL, NULL); extern struct cfdriver mkclock_cd; @@ -90,23 +91,19 @@ struct device *parent, *self; void *aux; { + struct mk48txx_softc *sc = (void *)self; struct hb_attach_args *ha = aux; - bus_space_tag_t bst = ha->ha_bust; - bus_space_handle_t bsh; - todr_chip_handle_t handle; - if (bus_space_map(bst, (bus_addr_t)ha->ha_address, ha->ha_size, - 0, &bsh) != 0) + sc->sc_bst = ha->ha_bust; + if (bus_space_map(sc->sc_bst, (bus_addr_t)ha->ha_address, ha->ha_size, + 0, &sc->sc_bsh) != 0) printf("can't map device space\n"); - handle = mk48txx_attach(bst, bsh, "mk48t02", 1900, NULL, NULL); - if (handle == NULL) - panic("can't attach tod clock"); + sc->sc_model = "mk48t02"; + sc->sc_year0 = 1900; + mk48txx_attach(sc); printf("\n"); - handle->bus_cookie = NULL; - handle->todr_setwen = NULL; - - todr_attach(handle); + todr_attach(&sc->sc_handle); } Index: arch/newsmips/apbus/mkclock_ap.c =================================================================== RCS file: /cvsroot/src/sys/arch/newsmips/apbus/mkclock_ap.c,v retrieving revision 1.1 diff -u -r1.1 mkclock_ap.c --- arch/newsmips/apbus/mkclock_ap.c 25 Oct 2003 04:07:28 -0000 1.1 +++ arch/newsmips/apbus/mkclock_ap.c 31 Oct 2003 14:51:46 -0000 @@ -49,6 +49,7 @@ #include #include +#include #include @@ -58,10 +59,10 @@ int mkclock_ap_match(struct device *, struct cfdata *, void *); void mkclock_ap_attach(struct device *, struct device *, void *); -static u_int8_t mkclock_ap_nvrd(bus_space_tag_t bt, bus_space_handle_t, int); -static void mkclock_ap_nvwr(bus_space_tag_t, bus_space_handle_t, int, u_int8_t); +static u_int8_t mkclock_ap_nvrd(struct mk48txx_softc *, int); +static void mkclock_ap_nvwr(struct mk48txx_softc *, int, u_int8_t); -CFATTACH_DECL(mkclock_ap, sizeof(struct device), +CFATTACH_DECL(mkclock_ap, sizeof(struct mk48txx_softc), mkclock_ap_match, mkclock_ap_attach, NULL, NULL); extern struct cfdriver mkclock_cd; @@ -85,48 +86,43 @@ struct device *parent, *self; void *aux; { + struct mk48txx_softc *sc = (void *)self; struct apbus_attach_args *apa = aux; - bus_space_tag_t bst; - bus_space_handle_t bsh; - todr_chip_handle_t handle; printf(" slot%d addr 0x%lx", apa->apa_slotno, apa->apa_hwbase); - if (bus_space_map(bst, apa->apa_hwbase - MKCLOCK_AP_OFFSET, - MK48T02_CLKSZ, 0, &bsh) != 0) + if (bus_space_map(sc->sc_bst, apa->apa_hwbase - MKCLOCK_AP_OFFSET, + MK48T02_CLKSZ, 0, &sc->sc_bsh) != 0) printf("can't map device space\n"); - handle = mk48txx_attach(bst, bsh, "mk48t02", 1900, - mkclock_ap_nvrd, mkclock_ap_nvwr); - if (handle == NULL) - panic("can't attach tod clock"); + sc->sc_model = "mk48t02"; + sc->sc_year0 = 1900; + sc->sc_nvrd = mkclock_ap_nvrd; + sc->sc_nvwr = mkclock_ap_nvwr; - printf("\n"); + mk48txx_attach(sc); - handle->bus_cookie = NULL; - handle->todr_setwen = NULL; + printf("\n"); - todr_attach(handle); + todr_attach(&sc->sc_handle); } static u_int8_t -mkclock_ap_nvrd(bt, bh, off) - bus_space_tag_t bt; - bus_space_handle_t bh; +mkclock_ap_nvrd(sc, off) + struct mk48txx_softc *sc; int off; { u_int8_t rv; - rv = bus_space_read_4(bt, bh, off << MKCLOCK_AP_STRIDE); + rv = bus_space_read_4(sc->sc_bst, sc->sc_bsh, off << MKCLOCK_AP_STRIDE); return rv; } static void -mkclock_ap_nvwr(bt, bh, off, v) - bus_space_tag_t bt; - bus_space_handle_t bh; +mkclock_ap_nvwr(sc, off, v) + struct mk48txx_softc *sc; int off; u_int8_t v; { - bus_space_write_4(bt, bh, off << MKCLOCK_AP_STRIDE, v); + bus_space_write_4(sc->sc_bst, sc->sc_bsh, off << MKCLOCK_AP_STRIDE, v); } Index: arch/newsmips/dev/mkclock_hb.c =================================================================== RCS file: /cvsroot/src/sys/arch/newsmips/dev/mkclock_hb.c,v retrieving revision 1.1 diff -u -r1.1 mkclock_hb.c --- arch/newsmips/dev/mkclock_hb.c 25 Oct 2003 04:10:12 -0000 1.1 +++ arch/newsmips/dev/mkclock_hb.c 31 Oct 2003 14:51:47 -0000 @@ -49,13 +49,14 @@ #include #include +#include #include int mkclock_hb_match(struct device *, struct cfdata *, void *); void mkclock_hb_attach(struct device *, struct device *, void *); -CFATTACH_DECL(mkclock_hb, sizeof(struct device), +CFATTACH_DECL(mkclock_hb, sizeof(struct mk48txx_softc), mkclock_hb_match, mkclock_hb_attach, NULL, NULL); extern struct cfdriver mkclock_cd; @@ -86,23 +87,18 @@ struct device *parent, *self; void *aux; { + struct mk48txx_softc *sc = (void *)self; struct hb_attach_args *ha = aux; - bus_space_tag_t bst; - bus_space_handle_t bsh; - todr_chip_handle_t handle; - if (bus_space_map(bst, (bus_addr_t)ha->ha_addr, MK48T02_CLKSZ, - 0, &bsh) != 0) + if (bus_space_map(sc->sc_bst, (bus_addr_t)ha->ha_addr, MK48T02_CLKSZ, + 0, &sc->sc_bsh) != 0) printf("can't map device space\n"); - handle = mk48txx_attach(bst, bsh, "mk48t02", 1900, NULL, NULL); - if (handle == NULL) - panic("can't attach tod clock"); + sc->sc_model = "mk48t02"; + sc->sc_year0 = 1900; + mk48txx_attach(sc); printf("\n"); - handle->bus_cookie = NULL; - handle->todr_setwen = NULL; - - todr_attach(handle); + todr_attach(&sc->sc_handle); } Index: arch/prep/conf/files.prep =================================================================== RCS file: /cvsroot/src/sys/arch/prep/conf/files.prep,v retrieving revision 1.43 diff -u -r1.43 files.prep --- arch/prep/conf/files.prep 27 Jul 2003 01:19:30 -0000 1.43 +++ arch/prep/conf/files.prep 31 Oct 2003 14:51:47 -0000 @@ -119,9 +119,8 @@ # clock # # mc146818 and compat. -device mcclock +device mcclock: mc146818 attach mcclock at isa with mcclock_isa -file arch/prep/prep/mcclock.c mcclock file arch/prep/isa/mcclock_isa.c mcclock_isa # mk48t18 and compat. Index: arch/prep/isa/mcclock_isa.c =================================================================== RCS file: /cvsroot/src/sys/arch/prep/isa/mcclock_isa.c,v retrieving revision 1.9 diff -u -r1.9 mcclock_isa.c --- arch/prep/isa/mcclock_isa.c 15 Jul 2003 02:54:51 -0000 1.9 +++ arch/prep/isa/mcclock_isa.c 31 Oct 2003 14:51:47 -0000 @@ -41,33 +41,21 @@ #include #include - -#include -#include +#include #include #define MCCLOCK_NPORTS 2 -struct mcclock_isa_softc { - struct mcclock_softc sc_mcclock; - - bus_space_tag_t sc_iot; - bus_space_handle_t sc_ioh; -}; - int mcclock_isa_match __P((struct device *, struct cfdata *, void *)); void mcclock_isa_attach __P((struct device *, struct device *, void *)); -CFATTACH_DECL(mcclock_isa, sizeof (struct mcclock_isa_softc), +CFATTACH_DECL(mcclock_isa, sizeof (struct mc146818_softc), mcclock_isa_match, mcclock_isa_attach, NULL, NULL); -void mcclock_isa_write __P((struct mcclock_softc *, u_int, u_int)); -u_int mcclock_isa_read __P((struct mcclock_softc *, u_int)); +void mcclock_isa_write __P((struct mc146818_softc *, u_int, u_int)); +u_int mcclock_isa_read __P((struct mc146818_softc *, u_int)); -const struct mcclock_busfns mcclock_isa_busfns = { - mcclock_isa_write, mcclock_isa_read, -}; int mcclock_isa_match(parent, match, aux) @@ -76,8 +64,7 @@ void *aux; { struct isa_attach_args *ia = aux; - struct mcclock_isa_softc sc; - bus_space_handle_t ioh; + struct mc146818_softc mc146818, *sc; unsigned int cra, t1, t2; int found; @@ -100,25 +87,24 @@ (ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT)) return (0); - if (bus_space_map(ia->ia_iot, 0x70, MCCLOCK_NPORTS, 0, &ioh)) + sc = &mc146818; + sc->sc_bst = ia->ia_iot; + if (bus_space_map(sc->sc_bst, 0x70, MCCLOCK_NPORTS, 0, &sc->sc_bsh)) return (0); - sc.sc_iot = ia->ia_iot; - sc.sc_ioh = ioh; - /* Supposedly no update in progress after POST; check for this. */ - cra = mcclock_isa_read((struct mcclock_softc *)&sc, MC_REGA); + cra = mcclock_isa_read(sc, MC_REGA); if (cra & MC_REGA_UIP) goto unmap; /* Read from the seconds counter. */ - t1 = FROMBCD(mcclock_isa_read((struct mcclock_softc *)&sc, MC_SEC)); + t1 = FROMBCD(mcclock_isa_read(sc, MC_SEC)); if (t1 > 59) goto unmap; /* Wait, then look again. */ DELAY(1100000); - t2 = FROMBCD(mcclock_isa_read((struct mcclock_softc *)&sc, MC_SEC)); + t2 = FROMBCD(mcclock_isa_read(sc, MC_SEC)); if (t2 > 59) goto unmap; @@ -131,7 +117,7 @@ found = 1; unmap: - bus_space_unmap(ia->ia_iot, ioh, MCCLOCK_NPORTS); + bus_space_unmap(sc->sc_bst, sc->sc_bsh, MCCLOCK_NPORTS); if (found) { ia->ia_nio = 1; @@ -151,39 +137,48 @@ struct device *parent, *self; void *aux; { + struct mc146818_softc *sc = (void *)self; struct isa_attach_args *ia = aux; - struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)self; - sc->sc_iot = ia->ia_iot; - if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, - ia->ia_io[0].ir_size, 0, &sc->sc_ioh)) + sc->sc_bst = ia->ia_iot; + if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr, + ia->ia_io[0].ir_size, 0, &sc->sc_bsh)) panic("mcclock_isa_attach: couldn't map clock I/O space"); - mcclock_attach(&sc->sc_mcclock, &mcclock_isa_busfns); + sc->sc_year0 = 1900; + sc->sc_mcread = mcclock_isa_read; + sc->sc_mcwrite = mcclock_isa_write; + mc146818_attach(sc); + + todr_attach(&sc->sc_handle); } void -mcclock_isa_write(mcsc, reg, datum) - struct mcclock_softc *mcsc; +mcclock_isa_write(sc, reg, datum) + struct mc146818_softc *sc; u_int reg, datum; { - struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + bus_space_tag_t iot; + bus_space_handle_t ioh; + + iot = sc->sc_bst; + ioh = sc->sc_bsh; bus_space_write_1(iot, ioh, 0, reg); bus_space_write_1(iot, ioh, 1, datum); } u_int -mcclock_isa_read(mcsc, reg) - struct mcclock_softc *mcsc; +mcclock_isa_read(sc, reg) + struct mc146818_softc *sc; u_int reg; { - struct mcclock_isa_softc *sc = (struct mcclock_isa_softc *)mcsc; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + bus_space_tag_t iot; + bus_space_handle_t ioh; u_int datum; + + iot = sc->sc_bst; + ioh = sc->sc_bsh; bus_space_write_1(iot, ioh, 0, reg); datum = bus_space_read_1(iot, ioh, 1); Index: arch/prep/isa/mkclock_isa.c =================================================================== RCS file: /cvsroot/src/sys/arch/prep/isa/mkclock_isa.c,v retrieving revision 1.5 diff -u -r1.5 mkclock_isa.c --- arch/prep/isa/mkclock_isa.c 2 Oct 2002 15:52:29 -0000 1.5 +++ arch/prep/isa/mkclock_isa.c 31 Oct 2003 14:51:47 -0000 @@ -49,13 +49,12 @@ #include #include -#include - #include #include #include #include +#include #include @@ -68,44 +67,23 @@ #define MKCLOCK_NPORTS (MKCLOCK_DATA - MKCLOCK_STB0 + 1) -struct mkclock_isa_softc { - struct device sc_dev; /* Base device */ - - bus_space_tag_t sc_iot; /* I/O space access */ - bus_space_handle_t sc_ioh; - - todr_chip_handle_t sc_todr; /* MI todr interface handle */ -}; - - /* Autoconfiguration interface */ int mkclock_isa_match(struct device *, struct cfdata *, void *); void mkclock_isa_attach(struct device *, struct device *, void *); -CFATTACH_DECL(mkclock_isa, sizeof (struct mkclock_isa_softc), +CFATTACH_DECL(mkclock_isa, sizeof (struct mk48txx_softc), mkclock_isa_match, mkclock_isa_attach, NULL, NULL); /* mk48txx interface */ -uint8_t mkclock_isa_nvrd(bus_space_tag_t, bus_space_handle_t, int); -void mkclock_isa_nvwr(bus_space_tag_t, bus_space_handle_t, int, uint8_t); - -/* MI todr/PReP clock handling shim */ -void mkclock_isa_init(struct device *); -void mkclock_isa_get(struct device *, time_t, struct clocktime *); -void mkclock_isa_set(struct device *, struct clocktime *); - -struct clockfns mkclock_isa_clockfns = { - mkclock_isa_init, /* cf_init */ - mkclock_isa_get, /* cf_get */ - mkclock_isa_set /* cf_set */ -}; +uint8_t mkclock_isa_nvrd(struct mk48txx_softc *, int); +void mkclock_isa_nvwr(struct mk48txx_softc *, int, uint8_t); int mkclock_isa_match(struct device *parent, struct cfdata *match, void *aux) { struct isa_attach_args *ia = aux; - bus_space_handle_t ioh; + struct mk48txx_softc mk48txx, *sc; uint8_t csr, ocsr; unsigned int t1, t2; int found; @@ -135,34 +113,33 @@ /* * Map I/O space, then try to determine if it's really there. */ - if (bus_space_map(ia->ia_iot, 0x74, MKCLOCK_NPORTS, 0, &ioh)) + sc = &mk48txx; + sc->sc_bst = ia->ia_iot; + if (bus_space_map(sc->sc_bst, 0x74, MKCLOCK_NPORTS, 0, &sc->sc_bsh)) return (0); /* Supposedly no control bits are set after POST; check for this. */ - ocsr = mkclock_isa_nvrd(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR); + ocsr = mkclock_isa_nvrd(sc, MK48T18_CLKOFF + MK48TXX_ICSR); if (ocsr != 0) goto unmap; /* Set clock data to read mode, prohibiting updates from clock. */ csr = ocsr | MK48TXX_CSR_READ; - mkclock_isa_nvwr(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR, csr); + mkclock_isa_nvwr(sc, MK48T18_CLKOFF + MK48TXX_ICSR, csr); /* Compare. */ - if (mkclock_isa_nvrd(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR) - != csr) + if (mkclock_isa_nvrd(sc, MK48T18_CLKOFF + MK48TXX_ICSR) != csr) goto restore; /* Read from the seconds counter. */ - t1 = FROMBCD(mkclock_isa_nvrd(ia->ia_iot, ioh, - MK48T18_CLKOFF + MK48TXX_ISEC)); + t1 = FROMBCD(mkclock_isa_nvrd(sc, MK48T18_CLKOFF + MK48TXX_ISEC)); if (t1 > 59) goto restore; /* Make it tick again, wait, then look again. */ - mkclock_isa_nvwr(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR, ocsr); + mkclock_isa_nvwr(sc, MK48T18_CLKOFF + MK48TXX_ICSR, ocsr); DELAY(1100000); - mkclock_isa_nvwr(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR, csr); - t2 = FROMBCD(mkclock_isa_nvrd(ia->ia_iot, ioh, - MK48T18_CLKOFF + MK48TXX_ISEC)); + mkclock_isa_nvwr(sc, MK48T18_CLKOFF + MK48TXX_ICSR, csr); + t2 = FROMBCD(mkclock_isa_nvrd(sc, MK48T18_CLKOFF + MK48TXX_ISEC)); if (t2 > 59) goto restore; @@ -175,9 +152,9 @@ found = 1; restore: - mkclock_isa_nvwr(ia->ia_iot, ioh, MK48T18_CLKOFF + MK48TXX_ICSR, ocsr); + mkclock_isa_nvwr(sc, MK48T18_CLKOFF + MK48TXX_ICSR, ocsr); unmap: - bus_space_unmap(ia->ia_iot, ioh, MKCLOCK_NPORTS); + bus_space_unmap(sc->sc_bst, sc->sc_bsh, MKCLOCK_NPORTS); if (found) { ia->ia_nio = 1; @@ -195,84 +172,33 @@ void mkclock_isa_attach(struct device *parent, struct device *self, void *aux) { + struct mk48txx_softc *sc = (void *)self; struct isa_attach_args *ia = aux; - struct mkclock_isa_softc *sc = (struct mkclock_isa_softc *)self; /* Map I/O space. */ - sc->sc_iot = ia->ia_iot; - if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, - ia->ia_io[0].ir_size, 0, &sc->sc_ioh)) + sc->sc_bst = ia->ia_iot; + if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr, + ia->ia_io[0].ir_size, 0, &sc->sc_bsh)) panic("mkclock_isa_attach: couldn't map clock I/O space"); /* Attach to MI mk48txx driver. */ - sc->sc_todr = mk48txx_attach(sc->sc_iot, sc->sc_ioh, "mk48t18", 1900, - mkclock_isa_nvrd, mkclock_isa_nvwr); - if (sc->sc_todr == NULL) - panic("\nmkclock_isa_attach: mk48txx attach failed"); - - clockattach(self, &mkclock_isa_clockfns); -} - -/* - * Shim to interface mk48txx's MI TODR handling with current PReP structure. - */ -void -mkclock_isa_init(struct device *self) -{ + sc->sc_model = "mk48t18"; + sc->sc_year0 = 1900; + sc->sc_nvrd = mkclock_isa_nvrd; + sc->sc_nvwr = mkclock_isa_nvwr; + mk48txx_attach(sc); - /* Nothing to be done. */ -} - -void -mkclock_isa_get(struct device *self, time_t base, struct clocktime *ct) -{ - struct mkclock_isa_softc *sc = (struct mkclock_isa_softc *)self; - struct clock_ymdhms dt; - struct timeval tv; - - todr_gettime(sc->sc_todr, &tv); - - /* Note: we ignore `tv_usec'. */ - clock_secs_to_ymdhms(tv.tv_sec, &dt); - - ct->year = dt.dt_year - 1900; - ct->mon = dt.dt_mon; - ct->day = dt.dt_day; - ct->hour = dt.dt_hour; - ct->min = dt.dt_min; - ct->sec = dt.dt_sec; - ct->dow = dt.dt_wday; -} - -void -mkclock_isa_set(struct device *self, struct clocktime *ct) -{ - struct mkclock_isa_softc *sc = (struct mkclock_isa_softc *)self; - struct clock_ymdhms dt; - struct timeval tv; - - dt.dt_year = ct->year + 1900; - if (dt.dt_year < 1970) - dt.dt_year += 100; - dt.dt_mon = ct->mon; - dt.dt_day = ct->day; - dt.dt_wday = ct->dow; - dt.dt_hour = ct->hour; - dt.dt_min = ct->min; - dt.dt_sec = ct->sec; - - tv.tv_sec = clock_ymdhms_to_secs(&dt); - tv.tv_usec = 0; - - todr_settime(sc->sc_todr, &tv); + todr_attach(&sc->sc_handle); } /* * Bus access methods for MI mk48txx driver. */ uint8_t -mkclock_isa_nvrd(bus_space_tag_t iot, bus_space_handle_t ioh, int off) +mkclock_isa_nvrd(struct mk48txx_softc *sc, int off) { + bus_space_tag_t iot; + bus_space_handle_t ioh; uint8_t datum; int s; @@ -280,6 +206,9 @@ printf("mkclock_isa_nvrd(%d)", off); #endif + iot = sc->sc_bst; + ioh = sc->sc_bsh; + s = splclock(); bus_space_write_1(iot, ioh, MKCLOCK_STB0, off & 0xff); bus_space_write_1(iot, ioh, MKCLOCK_STB1, off >> 8); @@ -294,14 +223,17 @@ } void -mkclock_isa_nvwr(bus_space_tag_t iot, bus_space_handle_t ioh, int off, - uint8_t datum) +mkclock_isa_nvwr(struct mk48txx_softc *sc, int off, uint8_t datum) { + bus_space_tag_t iot; + bus_space_handle_t ioh; int s; #ifdef DEBUG printf("mkclock_isa_nvwr(%d, %02x)\n", off, datum); #endif + iot = sc->sc_bst; + ioh = sc->sc_bsh; s = splclock(); bus_space_write_1(iot, ioh, MKCLOCK_STB0, off & 0xff); Index: arch/prep/prep/clock.c =================================================================== RCS file: /cvsroot/src/sys/arch/prep/prep/clock.c,v retrieving revision 1.6 diff -u -r1.6 clock.c --- arch/prep/prep/clock.c 15 Jul 2003 02:54:52 -0000 1.6 +++ arch/prep/prep/clock.c 31 Oct 2003 14:51:47 -0000 @@ -42,8 +42,6 @@ #include -#include - #define MINYEAR 1990 void decr_intr __P((struct clockframe *)); @@ -58,21 +56,18 @@ struct device *clockdev; const struct clockfns *clockfns; -int clockinitted; + +static todr_chip_handle_t todr_handle; void -clockattach(dev, fns) - struct device *dev; - const struct clockfns *fns; +todr_attach(handle) + todr_chip_handle_t handle; { - printf("\n"); - - if (clockfns != NULL) - panic("clockattach: multiple clocks"); + if (todr_handle) + panic("todr_attach: to many todclock configured"); - clockdev = dev; - clockfns = fns; + todr_handle = handle; } /* @@ -97,72 +92,42 @@ inittodr(base) time_t base; { - struct clocktime ct; - int year; - struct clock_ymdhms dt; - time_t deltat; - int badbase = 0; + int badbase, waszero; + + badbase = 0; + waszero = (base == 0); if (base < (MINYEAR - 1970) * SECYR) { - printf("WARNING: preposterous time in file system"); + if (base != 0) + printf("WARNING: preposterous time in file system\n"); /* read the system clock anyway */ base = (MINYEAR - 1970) * SECYR + 186 * SECDAY + SECDAY / 2; badbase = 1; } - (*clockfns->cf_get)(clockdev, base, &ct); -#ifdef DEBUG - printf("readclock: %d/%d/%d/%d/%d/%d", ct.year, ct.mon, ct.day, - ct.hour, ct.min, ct.sec); -#endif - clockinitted = 1; - - year = 1900 + ct.year; - if (year < 1970) - year += 100; - - /* simple sanity checks (2037 = time_t overflow) */ - if (year < MINYEAR || year > 2037 || - ct.mon < 1 || ct.mon > 12 || ct.day < 1 || - ct.day > 31 || ct.hour > 23 || ct.min > 59 || ct.sec > 59) { + if (todr_gettime(todr_handle, (struct timeval *)&time) != 0 || + time.tv_sec == 0) { + printf("WARNING: bad date in battery clock"); /* * Believe the time in the file system for lack of - * anything better, resetting the TODR. + * anything better, resetting the clock. */ time.tv_sec = base; - if (!badbase) { - printf("WARNING: preposterous clock chip time\n"); + if (!badbase) resettodr(); - } - goto bad; - } - - dt.dt_year = year; - dt.dt_mon = ct.mon; - dt.dt_day = ct.day; - dt.dt_hour = ct.hour; - dt.dt_min = ct.min; - dt.dt_sec = ct.sec; - time.tv_sec = clock_ymdhms_to_secs(&dt); -#ifdef DEBUG - printf("=>%ld (%d)\n", (long int)time.tv_sec, (int)base); -#endif - - if (!badbase) { + } else { /* * See if we gained/lost two or more days; * if so, assume something is amiss. */ - deltat = time.tv_sec - base; + int deltat = time.tv_sec - base; if (deltat < 0) deltat = -deltat; - if (deltat < 2 * SECDAY) + if (waszero || deltat < 2 * SECDAY) return; - printf("WARNING: clock %s %ld days", - time.tv_sec < base ? "lost" : "gained", - (long)deltat / SECDAY); + printf("WARNING: clock %s %d days", + time.tv_sec < base ? "lost" : "gained", deltat / SECDAY); } -bad: printf(" -- CHECK AND RESET THE DATE!\n"); } @@ -176,28 +141,12 @@ void resettodr() { - struct clock_ymdhms dt; - struct clocktime ct; - if (!clockinitted) + if (time.tv_sec == 0) return; - clock_secs_to_ymdhms(time.tv_sec, &dt); - - /* rt clock wants 2 digits */ - ct.year = dt.dt_year % 100; - ct.mon = dt.dt_mon; - ct.day = dt.dt_day; - ct.hour = dt.dt_hour; - ct.min = dt.dt_min; - ct.sec = dt.dt_sec; - ct.dow = dt.dt_wday; -#ifdef DEBUG - printf("setclock: %d/%d/%d/%d/%d/%d\n", ct.year, ct.mon, ct.day, - ct.hour, ct.min, ct.sec); -#endif - - (*clockfns->cf_set)(clockdev, &ct); + if (todr_settime(todr_handle, (struct timeval *)&time) != 0) + printf("resettodr: cannot set time in time-of-day clock\n"); } /* Index: arch/sparc/sparc/mkclock.c =================================================================== RCS file: /cvsroot/src/sys/arch/sparc/sparc/mkclock.c,v retrieving revision 1.7 diff -u -r1.7 mkclock.c --- arch/sparc/sparc/mkclock.c 15 Jul 2003 00:05:07 -0000 1.7 +++ arch/sparc/sparc/mkclock.c 31 Oct 2003 14:51:47 -0000 @@ -60,6 +60,7 @@ #include #include +#include /* Location and size of the MK48xx TOD clock, if present */ static bus_space_handle_t mk_nvram_base; @@ -73,12 +74,12 @@ static void clockattach_mainbus(struct device *, struct device *, void *); static void clockattach_obio(struct device *, struct device *, void *); -static void clockattach(int, bus_space_tag_t, bus_space_handle_t); +static void clockattach(struct mk48txx_softc *, int); -CFATTACH_DECL(clock_mainbus, sizeof(struct device), +CFATTACH_DECL(clock_mainbus, sizeof(struct mk48txx_softc), clockmatch_mainbus, clockattach_mainbus, NULL, NULL); -CFATTACH_DECL(clock_obio, sizeof(struct device), +CFATTACH_DECL(clock_obio, sizeof(struct mk48txx_softc), clockmatch_obio, clockattach_obio, NULL, NULL); /* Imported from clock.c: */ @@ -138,9 +139,10 @@ struct device *parent, *self; void *aux; { + struct mk48txx_softc *sc = (void *)self; struct mainbus_attach_args *ma = aux; - bus_space_tag_t bt = ma->ma_bustag; - bus_space_handle_t bh; + + sc->sc_bst = ma->ma_bustag; /* * We ignore any existing virtual address as we need to map @@ -150,16 +152,16 @@ * of reloading the cpu type, Ethernet address, etc, by hand from * the console FORTH interpreter. I intend not to enjoy it again. */ - if (bus_space_map(bt, + if (bus_space_map(sc->sc_bst, ma->ma_paddr, ma->ma_size, BUS_SPACE_MAP_LINEAR, - &bh) != 0) { + &sc->sc_bsh) != 0) { printf("%s: can't map register\n", self->dv_xname); return; } - clockattach(ma->ma_node, bt, bh); + clockattach(sc, ma->ma_node); } static void @@ -167,9 +169,8 @@ struct device *parent, *self; void *aux; { + struct mk48txx_softc *sc = (void *)self; union obio_attach_args *uoba = aux; - bus_space_tag_t bt; - bus_space_handle_t bh; int node; if (uoba->uoba_isobio4 == 0) { @@ -177,10 +178,10 @@ struct sbus_attach_args *sa = &uoba->uoba_sbus; node = sa->sa_node; - bt = sa->sa_bustag; - if (sbus_bus_map(bt, + sc->sc_bst = sa->sa_bustag; + if (sbus_bus_map(sc->sc_bst, sa->sa_slot, sa->sa_offset, sa->sa_size, - BUS_SPACE_MAP_LINEAR, &bh) != 0) { + BUS_SPACE_MAP_LINEAR, &sc->sc_bsh) != 0) { printf("%s: can't map register\n", self->dv_xname); return; } @@ -193,39 +194,39 @@ * the device address space length to 2048. */ node = 0; - bt = oba->oba_bustag; - if (bus_space_map(bt, + sc->sc_bst = oba->oba_bustag; + if (bus_space_map(sc->sc_bst, oba->oba_paddr, 2048, /* size */ BUS_SPACE_MAP_LINEAR, /* flags */ - &bh) != 0) { + &sc->sc_bsh) != 0) { printf("%s: can't map register\n", self->dv_xname); return; } } - clockattach(node, bt, bh); + clockattach(sc, node); } static void -clockattach(node, bt, bh) +clockattach(sc, node) + struct mk48txx_softc *sc; int node; - bus_space_tag_t bt; - bus_space_handle_t bh; { - char *model; if (CPU_ISSUN4) - model = "mk48t02"; /* Hard-coded sun4 clock */ + sc->sc_model = "mk48t02"; /* Hard-coded sun4 clock */ else if (node != 0) - model = PROM_getpropstring(node, "model"); + sc->sc_model = PROM_getpropstring(node, "model"); else panic("clockattach: node == 0"); /* Our TOD clock year 0 represents 1968 */ - todr_handle = mk48txx_attach(bt, bh, model, 1968, NULL, NULL); - if (todr_handle == NULL) - panic("Cannot attach %s tod clock", model); + sc->sc_year0 = 1968; + mk48txx_attach(sc); + + /* XXX this should be done by todr_attach() */ + todr_handle = &sc->sc_handle; printf("\n"); @@ -233,9 +234,9 @@ * Store NVRAM base address and size in globals for use * by mk_nvram_wenable(). */ - mk_nvram_base = bh; + mk_nvram_base = sc->sc_bsh; if (mk48txx_get_nvram_size(todr_handle, &mk_nvram_size) != 0) - panic("Cannot get nvram size on %s", model); + panic("Cannot get nvram size on %s", sc->sc_model); /* Establish clock write-enable method */ todr_handle->todr_setwen = mk_clk_wenable; Index: arch/sparc64/conf/files.sparc64 =================================================================== RCS file: /cvsroot/src/sys/arch/sparc64/conf/files.sparc64,v retrieving revision 1.83 diff -u -r1.83 files.sparc64 --- arch/sparc64/conf/files.sparc64 26 Oct 2003 08:07:27 -0000 1.83 +++ arch/sparc64/conf/files.sparc64 31 Oct 2003 14:51:47 -0000 @@ -40,7 +40,7 @@ attach ebus at pci file arch/sparc64/dev/ebus.c ebus -device clock: mk48txx +device clock: mk48txx, mc146818 attach clock at mainbus, sbus with clock_sbus attach clock at ebus with clock_ebus Index: arch/sparc64/sparc64/clock.c =================================================================== RCS file: /cvsroot/src/sys/arch/sparc64/sparc64/clock.c,v retrieving revision 1.65 diff -u -r1.65 clock.c --- arch/sparc64/sparc64/clock.c 21 Oct 2003 08:27:20 -0000 1.65 +++ arch/sparc64/sparc64/clock.c 31 Oct 2003 14:51:47 -0000 @@ -88,7 +88,9 @@ #include #include +#include #include +#include #include #include @@ -98,12 +100,6 @@ #include #include -struct rtc_info { - bus_space_tag_t rtc_bt; /* bus tag & handle */ - bus_space_handle_t rtc_bh; /* */ - u_int rtc_year0; /* What year is represented on the system - by the chip's year counter at 0 */ -}; /* * Statistics clock interval and variance, in usec. Variance must be a @@ -135,16 +131,16 @@ static void clockattach_ebus __P((struct device *, struct device *, void *)); static int clockmatch_rtc __P((struct device *, struct cfdata *, void *)); static void clockattach_rtc __P((struct device *, struct device *, void *)); -static void clockattach __P((int, bus_space_tag_t, bus_space_handle_t)); +static void clockattach __P((struct mk48txx_softc *, int)); -CFATTACH_DECL(clock_sbus, sizeof(struct device), +CFATTACH_DECL(clock_sbus, sizeof(struct mk48txx_softc), clockmatch_sbus, clockattach_sbus, NULL, NULL); -CFATTACH_DECL(clock_ebus, sizeof(struct device), +CFATTACH_DECL(clock_ebus, sizeof(struct mk48txx_softc), clockmatch_ebus, clockattach_ebus, NULL, NULL); -CFATTACH_DECL(rtc_ebus, sizeof(struct device), +CFATTACH_DECL(rtc_ebus, sizeof(struct mc146818_softc), clockmatch_rtc, clockattach_rtc, NULL, NULL); extern struct cfdriver clock_cd; @@ -170,14 +166,10 @@ int timerblurb = 10; /* Guess a value; used before clock is attached */ -u_int8_t rtc_read_reg(bus_space_tag_t, bus_space_handle_t, int); -void rtc_write_reg(bus_space_tag_t, bus_space_handle_t, int, u_int8_t); -int rtc_gettime(todr_chip_handle_t, struct timeval *); -int rtc_settime(todr_chip_handle_t, struct timeval *); -int rtc_getcal(todr_chip_handle_t, int *); -int rtc_setcal(todr_chip_handle_t, int); - -int rtc_auto_century_adjust = 1; +u_int rtc_read_reg(struct mc146818_softc *, u_int); +void rtc_write_reg(struct mc146818_softc *, u_int, u_int); +u_int rtc_getcent(struct mc146818_softc *); +void rtc_setcent(struct mc146818_softc *, u_int); /* * The OPENPROM calls the clock the "eeprom", so we have to have our @@ -239,39 +231,33 @@ * a non-trivial operation. */ -/* Somewhere to keep info that clock_wenable() needs */ -static struct clock_info { - bus_space_tag_t ci_bt; - bus_space_handle_t ci_bh; -} ci; - /* ARGSUSED */ static void clockattach_sbus(parent, self, aux) struct device *parent, *self; void *aux; { + struct mk48txx_softc *sc = (void *)self; struct sbus_attach_args *sa = aux; - bus_space_tag_t bt = sa->sa_bustag; int sz; + sc->sc_bst = sa->sa_bustag; + /* use sa->sa_regs[0].size? */ sz = 8192; - if (sbus_bus_map(bt, + if (sbus_bus_map(sc->sc_bst, sa->sa_slot, (sa->sa_offset & ~(PAGE_SIZE - 1)), sz, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_READONLY, - &ci.ci_bh) != 0) { + &sc->sc_bsh) != 0) { printf("%s: can't map register\n", self->dv_xname); return; } - clockattach(sa->sa_node, bt, ci.ci_bh); + clockattach(sc, sa->sa_node); /* Save info for the clock wenable call. */ - ci.ci_bt = bt; - todr_handle->bus_cookie = &ci; todr_handle->todr_setwen = clock_wenable; } @@ -284,7 +270,7 @@ struct todr_chip_handle *handle; int onoff; { - struct clock_info *ci; + struct mk48txx_softc *sc; vm_prot_t prot; vaddr_t va; int s, err = 0; @@ -299,8 +285,8 @@ if (prot == VM_PROT_NONE) { return 0; } - ci = (struct clock_info *)handle->bus_cookie; - va = (vaddr_t)bus_space_vaddr(ci->ci_bt, ci->ci_bh); + sc = handle->cookie; + va = (vaddr_t)bus_space_vaddr(sc->sc_bst, sc->sc_bsh); if (va == 0UL) { printf("clock_wenable: WARNING -- cannot get va\n"); return EIO; @@ -316,55 +302,52 @@ struct device *parent, *self; void *aux; { + struct mk48txx_softc *sc = (void *)self; struct ebus_attach_args *ea = aux; - bus_space_tag_t bt = ea->ea_bustag; int sz; + sc->sc_bst = ea->ea_bustag; + /* hard code to 8K? */ sz = ea->ea_reg[0].size; - if (bus_space_map(bt, + if (bus_space_map(sc->sc_bst, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]), sz, BUS_SPACE_MAP_LINEAR, - &ci.ci_bh) != 0) { + &sc->sc_bsh) != 0) { printf("%s: can't map register\n", self->dv_xname); return; } - clockattach(ea->ea_node, bt, ci.ci_bh); + clockattach(sc, ea->ea_node); /* Save info for the clock wenable call. */ - ci.ci_bt = bt; - todr_handle->bus_cookie = &ci; todr_handle->todr_setwen = clock_wenable; } static void -clockattach(node, bt, bh) +clockattach(sc, node) + struct mk48txx_softc *sc; int node; - bus_space_tag_t bt; - bus_space_handle_t bh; { - char *model; struct idprom *idp; int h; - model = PROM_getpropstring(node, "model"); + sc->sc_model = PROM_getpropstring(node, "model"); #ifdef DIAGNOSTIC - if (model == NULL) + if (sc->sc_model == NULL) panic("clockattach: no model property"); #endif /* Our TOD clock year 0 is 1968 */ - todr_handle = mk48txx_attach(bt, bh, model, 1968, NULL, NULL); - if (todr_handle == NULL) - panic("Can't attach %s tod clock", model); + sc->sc_year0 = 1968; + mk48txx_attach(sc); #define IDPROM_OFFSET (8*1024 - 40) /* XXX - get nvram sz from driver */ - idp = (struct idprom *)((vaddr_t)bus_space_vaddr(bt, bh) + - IDPROM_OFFSET); + idp = (struct idprom *)((vaddr_t)bus_space_vaddr(sc->sc_bst, + sc->sc_bsh) + IDPROM_OFFSET); h = idp->id_machine << 24; h |= idp->id_hostid[0] << 16; @@ -374,6 +357,9 @@ printf(": hostid %x\n", (u_int)hostid); idprom = idp; + + /* XXX should be done by todr_attach() */ + todr_handle = &sc->sc_handle; } /* @@ -392,17 +378,19 @@ */ #define RTC_ADDR 0 #define RTC_DATA 1 -u_int8_t -rtc_read_reg(bus_space_tag_t bt, bus_space_handle_t bh, int reg) +u_int +rtc_read_reg(struct mc146818_softc *sc, u_int reg) { - bus_space_write_1(bt, bh, RTC_ADDR, reg); - return (bus_space_read_1(bt, bh, RTC_DATA)); + + bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_ADDR, reg); + return (bus_space_read_1(sc->sc_bst, sc->sc_bsh, RTC_DATA)); } void -rtc_write_reg(bus_space_tag_t bt, bus_space_handle_t bh, int reg, u_int8_t val) +rtc_write_reg(struct mc146818_softc *sc, u_int reg, u_int val) { - bus_space_write_1(bt, bh, RTC_ADDR, reg); - bus_space_write_1(bt, bh, RTC_DATA, val); + + bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_ADDR, reg); + bus_space_write_1(sc->sc_bst, sc->sc_bsh, RTC_DATA, val); } /* ARGSUSED */ @@ -411,22 +399,21 @@ struct device *parent, *self; void *aux; { + struct mc146818_softc *sc = (void *)self; struct ebus_attach_args *ea = aux; - bus_space_tag_t bt = ea->ea_bustag; - todr_chip_handle_t handle; - struct rtc_info *rtc; char *model; int sz; - static struct clock_info ci; + + sc->sc_bst = ea->ea_bustag; /* hard code to 8K? */ sz = ea->ea_reg[0].size; - if (bus_space_map(bt, + if (bus_space_map(sc->sc_bst, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]), sz, BUS_SPACE_MAP_LINEAR, - &ci.ci_bh) != 0) { + &sc->sc_bsh) != 0) { printf("%s: can't map register\n", self->dv_xname); return; } @@ -436,35 +423,32 @@ if (model == NULL) panic("clockattach_rtc: no model property"); #endif + + /* Our TOD clock year 0 is 0 */ + sc->sc_year0 = 0; + sc->sc_flag = NO_CENTURY_ADJUST; + sc->sc_mcread = rtc_read_reg; + sc->sc_mcwrite = rtc_write_reg; + sc->sc_getcent = rtc_getcent; + sc->sc_setcent = rtc_setcent; + mc146818_attach(sc); + printf(": %s\n", model); /* * Turn interrupts off, just in case. (Although they shouldn't * be wired to an interrupt controller on sparcs). */ - rtc_write_reg(bt, ci.ci_bh, - MC_REGB, MC_REGB_BINARY | MC_REGB_24HR); + rtc_write_reg(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR); - /* Setup our todr_handle */ - sz = ALIGN(sizeof(struct todr_chip_handle)) + sizeof(struct rtc_info); - handle = malloc(sz, M_DEVBUF, M_NOWAIT); - rtc = (struct rtc_info*)((u_long)handle + - ALIGN(sizeof(struct todr_chip_handle))); - handle->cookie = rtc; - handle->todr_gettime = rtc_gettime; - handle->todr_settime = rtc_settime; - handle->todr_getcal = rtc_getcal; - handle->todr_setcal = rtc_setcal; /* * Apparently on some machines the TOD registers are on the same * physical page as the COM registers. So we won't protect them. */ - handle->todr_setwen = NULL; - rtc->rtc_bt = bt; - rtc->rtc_bh = ci.ci_bh; - /* Our TOD clock year 0 is 0 */ - rtc->rtc_year0 = 0; - todr_handle = handle; + /*sc->sc_handle.todr_setwen = NULL;*/ + + /* XXX should be done by todr_attach() */ + todr_handle = &sc->sc_handle; } /* @@ -1004,129 +988,25 @@ /* - * RTC todr routines. + * MD mc146818 RTC todr routines. */ /* Loooks like Sun stores the century info somewhere in CMOS RAM */ #define MC_CENT 0x32 -/* - * Get time-of-day and convert to a `struct timeval' - * Return 0 on success; an error number otherwise. - */ -int -rtc_gettime(handle, tv) - todr_chip_handle_t handle; - struct timeval *tv; -{ - struct rtc_info *rtc = handle->cookie; - bus_space_tag_t bt = rtc->rtc_bt; - bus_space_handle_t bh = rtc->rtc_bh; - struct clock_ymdhms dt; - int year, cent; - u_int8_t csr; - - todr_wenable(handle, 1); - - /* Stop updates. */ - csr = rtc_read_reg(bt, bh, MC_REGB); - csr |= MC_REGB_SET; - rtc_write_reg(bt, bh, MC_REGB, csr); - - /* Read time */ - dt.dt_sec = rtc_read_reg(bt, bh, MC_SEC); - dt.dt_min = rtc_read_reg(bt, bh, MC_MIN); - dt.dt_hour = rtc_read_reg(bt, bh, MC_HOUR); - dt.dt_day = rtc_read_reg(bt, bh, MC_DOM); - dt.dt_wday = rtc_read_reg(bt, bh, MC_DOW); - dt.dt_mon = rtc_read_reg(bt, bh, MC_MONTH); - year = rtc_read_reg(bt, bh, MC_YEAR); - cent = rtc_read_reg(bt, bh, MC_CENT); -#ifdef DIAGNOSTIC - printf("rtc_gettime: read c %x/%d y %x/%d m %x/%d wd %d d %x/%d " - "h %x/%d m %x/%d s %x/%d\n", - cent, cent, year, year, dt.dt_mon, dt.dt_mon, dt.dt_wday, - dt.dt_day, dt.dt_day, dt.dt_hour, dt.dt_hour, - dt.dt_min, dt.dt_min, dt.dt_sec, dt.dt_sec); -#endif - - year += cent * 100; - dt.dt_year = year; - - /* time wears on */ - csr = rtc_read_reg(bt, bh, MC_REGB); - csr &= ~MC_REGB_SET; - rtc_write_reg(bt, bh, MC_REGB, csr); - todr_wenable(handle, 0); - - /* simple sanity checks */ - if (dt.dt_year < 1970 || dt.dt_mon > 12 || dt.dt_day > 31 || - dt.dt_hour >= 24 || dt.dt_min >= 60 || dt.dt_sec >= 60) - return (1); - - tv->tv_sec = clock_ymdhms_to_secs(&dt); - tv->tv_usec = 0; - return (0); -} +u_int +rtc_getcent(sc) + struct mc146818_softc *sc; +{ -/* - * Set the time-of-day clock based on the value of the `struct timeval' arg. - * Return 0 on success; an error number otherwise. - */ -int -rtc_settime(handle, tv) - todr_chip_handle_t handle; - struct timeval *tv; -{ - struct rtc_info *rtc = handle->cookie; - bus_space_tag_t bt = rtc->rtc_bt; - bus_space_handle_t bh = rtc->rtc_bh; - struct clock_ymdhms dt; - u_int8_t csr; - int year, cent; - - /* Note: we ignore `tv_usec' */ - clock_secs_to_ymdhms(tv->tv_sec, &dt); - - year = dt.dt_year % 100; - cent = dt.dt_year / 100; - - todr_wenable(handle, 1); - /* enable write */ - csr = rtc_read_reg(bt, bh, MC_REGB); - csr |= MC_REGB_SET; - rtc_write_reg(bt, bh, MC_REGB, csr); - - rtc_write_reg(bt, bh, MC_SEC, dt.dt_sec); - rtc_write_reg(bt, bh, MC_MIN, dt.dt_min); - rtc_write_reg(bt, bh, MC_HOUR, dt.dt_hour); - rtc_write_reg(bt, bh, MC_DOW, dt.dt_wday); - rtc_write_reg(bt, bh, MC_DOM, dt.dt_day); - rtc_write_reg(bt, bh, MC_MONTH, dt.dt_mon); - rtc_write_reg(bt, bh, MC_YEAR, year); - rtc_write_reg(bt, bh, MC_CENT, cent); - - /* load them up */ - csr = rtc_read_reg(bt, bh, MC_REGB); - csr &= ~MC_REGB_SET; - rtc_write_reg(bt, bh, MC_REGB, csr); - todr_wenable(handle, 0); - return (0); + return rtc_read_reg(sc, MC_CENT); } -int -rtc_getcal(handle, vp) - todr_chip_handle_t handle; - int *vp; +void +rtc_setcent(sc, cent) + struct mc146818_softc *sc; + u_int cent; { - return (EOPNOTSUPP); -} -int -rtc_setcal(handle, v) - todr_chip_handle_t handle; - int v; -{ - return (EOPNOTSUPP); + rtc_write_reg(sc, MC_CENT, cent); } -