Allow MD code to provide functions for reading/writing NVRAM/RTC

locations. If passed NULL, the old behaviour using bus_space_{read,write}_1()
is used. Otherwise, all access to the chip goes via the MD functions.

This is necessary for mvmeppc boards where the mk48txx NVRAM/RTC is not
directly addressable.
This commit is contained in:
scw 2002-02-23 17:18:54 +00:00
parent 0f4520b538
commit c4dbe1a160
6 changed files with 71 additions and 35 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: timekeeper.c,v 1.2 2002/02/12 20:38:28 scw Exp $ */ /* $NetBSD: timekeeper.c,v 1.3 2002/02/23 17:18:54 scw Exp $ */
/*- /*-
* Copyright (c) 2001 The NetBSD Foundation, Inc. * Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -108,7 +108,8 @@ timekeeper_attach(parent, self, aux)
bus_space_map(ma->ma_bust, ma->ma_offset, sc->sc_size, 0, &sc->sc_bush); bus_space_map(ma->ma_bust, ma->ma_offset, sc->sc_size, 0, &sc->sc_bush);
todr = mk48txx_attach(sc->sc_bust, sc->sc_bush, model, YEAR0); todr = mk48txx_attach(sc->sc_bust, sc->sc_bush, model, YEAR0,
NULL, NULL);
if (todr == NULL) if (todr == NULL)
panic("\ntimekeeper_attach"); panic("\ntimekeeper_attach");

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkclock_hb.c,v 1.1 2001/07/07 15:27:22 tsutsui Exp $ */ /* $NetBSD: mkclock_hb.c,v 1.2 2002/02/23 17:18:55 scw Exp $ */
/*- /*-
* Copyright (c) 1996 The NetBSD Foundation, Inc. * Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -97,7 +97,8 @@ mkclock_hb_attach(parent, self, aux)
0, &bsh) != 0) 0, &bsh) != 0)
printf("can't map device space\n"); printf("can't map device space\n");
if ((handle = mk48txx_attach(bst, bsh, "mk48t02", 1900)) == NULL) handle = mk48txx_attach(bst, bsh, "mk48t02", 1900, NULL, NULL);
if (handle == NULL)
panic("can't attach tod clock"); panic("can't attach tod clock");
printf("\n"); printf("\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.c,v 1.84 2001/12/11 05:54:56 uwe Exp $ */ /* $NetBSD: clock.c,v 1.85 2002/02/23 17:18:55 scw Exp $ */
/* /*
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
@ -584,7 +584,8 @@ clockattach(node, bt, bh)
panic("clockattach: node == 0"); panic("clockattach: node == 0");
/* Our TOD clock year 0 represents 1968 */ /* Our TOD clock year 0 represents 1968 */
if ((todr_handle = mk48txx_attach(bt, bh, model, 1968)) == NULL) todr_handle = mk48txx_attach(bt, bh, model, 1968, NULL, NULL);
if (todr_handle == NULL)
panic("Cannot attach %s tod clock", model); panic("Cannot attach %s tod clock", model);
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.c,v 1.44 2001/10/22 08:00:12 mrg Exp $ */ /* $NetBSD: clock.c,v 1.45 2002/02/23 17:18:55 scw Exp $ */
/* /*
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
@ -412,7 +412,8 @@ clockattach(node, bt, bh)
#endif #endif
/* Our TOD clock year 0 is 1968 */ /* Our TOD clock year 0 is 1968 */
if ((todr_handle = mk48txx_attach(bt, bh, model, 1968)) == NULL) todr_handle = mk48txx_attach(bt, bh, model, 1968, NULL, NULL);
if (todr_handle == NULL)
panic("Can't attach %s tod clock", model); panic("Can't attach %s tod clock", model);
#define IDPROM_OFFSET (8*1024 - 40) /* XXX - get nvram sz from driver */ #define IDPROM_OFFSET (8*1024 - 40) /* XXX - get nvram sz from driver */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mk48txx.c,v 1.9 2001/12/06 18:54:23 kleink Exp $ */ /* $NetBSD: mk48txx.c,v 1.10 2002/02/23 17:18:56 scw Exp $ */
/*- /*-
* Copyright (c) 2000 The NetBSD Foundation, Inc. * Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
@ -40,7 +40,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mk48txx.c,v 1.9 2001/12/06 18:54:23 kleink Exp $"); __KERNEL_RCSID(0, "$NetBSD: mk48txx.c,v 1.10 2002/02/23 17:18:56 scw Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/malloc.h> #include <sys/malloc.h>
@ -59,12 +59,16 @@ struct mk48txx {
bus_size_t mk_clkoffset; /* Offset in NVRAM to clock bits */ bus_size_t mk_clkoffset; /* Offset in NVRAM to clock bits */
u_int mk_year0; /* What year is represented on the system u_int mk_year0; /* What year is represented on the system
by the chip's year counter at 0 */ 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 */
}; };
int mk48txx_gettime(todr_chip_handle_t, struct timeval *); int mk48txx_gettime(todr_chip_handle_t, struct timeval *);
int mk48txx_settime(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_getcal(todr_chip_handle_t, int *);
int mk48txx_setcal(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; int mk48txx_auto_century_adjust = 1;
@ -82,11 +86,13 @@ struct {
}; };
todr_chip_handle_t todr_chip_handle_t
mk48txx_attach(bt, bh, model, year0) mk48txx_attach(bt, bh, model, year0, nvread, nvwrite)
bus_space_tag_t bt; bus_space_tag_t bt;
bus_space_handle_t bh; bus_space_handle_t bh;
const char *model; const char *model;
int year0; int year0;
mk48txx_nvrd_t nvread;
mk48txx_nvwr_t nvwrite;
{ {
todr_chip_handle_t handle; todr_chip_handle_t handle;
struct mk48txx *mk; struct mk48txx *mk;
@ -125,6 +131,14 @@ mk48txx_attach(bt, bh, model, year0)
mk->mk_clkoffset = clkoff; mk->mk_clkoffset = clkoff;
mk->mk_year0 = year0; 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); return (handle);
} }
@ -148,17 +162,17 @@ mk48txx_gettime(handle, tv)
todr_wenable(handle, 1); todr_wenable(handle, 1);
/* enable read (stop time) */ /* enable read (stop time) */
csr = bus_space_read_1(bt, bh, clkoff + MK48TXX_ICSR); csr = (*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ICSR);
csr |= MK48TXX_CSR_READ; csr |= MK48TXX_CSR_READ;
bus_space_write_1(bt, bh, clkoff + MK48TXX_ICSR, csr); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ICSR, csr);
dt.dt_sec = FROMBCD(bus_space_read_1(bt, bh, clkoff + MK48TXX_ISEC)); dt.dt_sec = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ISEC));
dt.dt_min = FROMBCD(bus_space_read_1(bt, bh, clkoff + MK48TXX_IMIN)); dt.dt_min = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IMIN));
dt.dt_hour = FROMBCD(bus_space_read_1(bt, bh, clkoff + MK48TXX_IHOUR)); dt.dt_hour = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IHOUR));
dt.dt_day = FROMBCD(bus_space_read_1(bt, bh, clkoff + MK48TXX_IDAY)); dt.dt_day = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IDAY));
dt.dt_wday = FROMBCD(bus_space_read_1(bt, bh, clkoff + MK48TXX_IWDAY)); dt.dt_wday = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IWDAY));
dt.dt_mon = FROMBCD(bus_space_read_1(bt, bh, clkoff + MK48TXX_IMON)); dt.dt_mon = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IMON));
year = FROMBCD(bus_space_read_1(bt, bh, clkoff + MK48TXX_IYEAR)); year = FROMBCD((*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_IYEAR));
year += mk->mk_year0; year += mk->mk_year0;
if (year < POSIX_BASE_YEAR && mk48txx_auto_century_adjust != 0) if (year < POSIX_BASE_YEAR && mk48txx_auto_century_adjust != 0)
@ -167,9 +181,9 @@ mk48txx_gettime(handle, tv)
dt.dt_year = year; dt.dt_year = year;
/* time wears on */ /* time wears on */
csr = bus_space_read_1(bt, bh, clkoff + MK48TXX_ICSR); csr = (*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ICSR);
csr &= ~MK48TXX_CSR_READ; csr &= ~MK48TXX_CSR_READ;
bus_space_write_1(bt, bh, clkoff + MK48TXX_ICSR, csr); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ICSR, csr);
todr_wenable(handle, 0); todr_wenable(handle, 0);
/* simple sanity checks */ /* simple sanity checks */
@ -208,22 +222,22 @@ mk48txx_settime(handle, tv)
todr_wenable(handle, 1); todr_wenable(handle, 1);
/* enable write */ /* enable write */
csr = bus_space_read_1(bt, bh, clkoff + MK48TXX_ICSR); csr = (*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ICSR);
csr |= MK48TXX_CSR_WRITE; csr |= MK48TXX_CSR_WRITE;
bus_space_write_1(bt, bh, clkoff + MK48TXX_ICSR, csr); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ICSR, csr);
bus_space_write_1(bt, bh, clkoff + MK48TXX_ISEC, TOBCD(dt.dt_sec)); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ISEC, TOBCD(dt.dt_sec));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IMIN, TOBCD(dt.dt_min)); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IMIN, TOBCD(dt.dt_min));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IHOUR, TOBCD(dt.dt_hour)); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IHOUR, TOBCD(dt.dt_hour));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IWDAY, TOBCD(dt.dt_wday)); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IWDAY, TOBCD(dt.dt_wday));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IDAY, TOBCD(dt.dt_day)); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IDAY, TOBCD(dt.dt_day));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IMON, TOBCD(dt.dt_mon)); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IMON, TOBCD(dt.dt_mon));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IYEAR, TOBCD(year)); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_IYEAR, TOBCD(year));
/* load them up */ /* load them up */
csr = bus_space_read_1(bt, bh, clkoff + MK48TXX_ICSR); csr = (*mk->mk_nvrd)(bt, bh, clkoff + MK48TXX_ICSR);
csr &= ~MK48TXX_CSR_WRITE; csr &= ~MK48TXX_CSR_WRITE;
bus_space_write_1(bt, bh, clkoff + MK48TXX_ICSR, csr); (*mk->mk_nvwr)(bt, bh, clkoff + MK48TXX_ICSR, csr);
todr_wenable(handle, 0); todr_wenable(handle, 0);
return (0); return (0);
} }
@ -253,3 +267,17 @@ mk48txx_get_nvram_size(handle, vp)
*vp = mk->mk_nvramsz; *vp = mk->mk_nvramsz;
return (0); return (0);
} }
u_int8_t
mk48txx_def_nvrd(bus_space_tag_t bt, bus_space_handle_t bh, int off)
{
return (bus_space_read_1(bt, bh, off));
}
void
mk48txx_def_nvwr(bus_space_tag_t bt, bus_space_handle_t bh, int off, u_int8_t v)
{
bus_space_write_1(bt, bh, off, v);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mk48txxreg.h,v 1.5 2001/12/06 18:54:23 kleink Exp $ */ /* $NetBSD: mk48txxreg.h,v 1.6 2002/02/23 17:18:56 scw Exp $ */
/*- /*-
* Copyright (c) 2000 The NetBSD Foundation, Inc. * Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
@ -84,9 +84,13 @@
#define MK48T59_CLKSZ 8192 #define MK48T59_CLKSZ 8192
#define MK48T59_CLKOFF 0x1ff0 #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 */ /* Chip attach function */
todr_chip_handle_t mk48txx_attach(bus_space_tag_t, bus_space_handle_t, todr_chip_handle_t mk48txx_attach(bus_space_tag_t, bus_space_handle_t,
const char *, int); const char *, int, mk48txx_nvrd_t, mk48txx_nvwr_t);
/* Retrieve size of the on-chip NVRAM area */ /* Retrieve size of the on-chip NVRAM area */
int mk48txx_get_nvram_size(todr_chip_handle_t, bus_size_t *); int mk48txx_get_nvram_size(todr_chip_handle_t, bus_size_t *);