Subject: intersil7170(4) cleanup
To: None <port-sun3@NetBSD.org, port-sparc@NetBSD.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-sun3
Date: 10/01/2006 17:58:11
Hi,

I'd like to commit the following changes against the intersil7170(4)
TOD clock driver used on old sun3/sun4 machines:

- make intersil7170_softc more generic and allocate it during autoconf(9)
  (rather than MALLOC(9) in attachment)
- put todr_chip_handle_t, year0 value, and the century adjustment flag
  into the intersil7170_softc
- change the attachment function to just take the softc like mk48txx(4)
- split sys/dev/ic/intersil7170.h into intersil7170reg.h and intersil7170var.h
- cleanup some macro

I'll also change sun3 port to use these MI todr drivers.

Any comments (or reports on such ancient machines) are appricated.
(only tested on TME which emulates sun3/120)
---
Izumi Tsutsui


Index: share/man/man4/intersil7170.4
===================================================================
RCS file: /cvsroot/src/share/man/man4/intersil7170.4,v
retrieving revision 1.9
diff -u -r1.9 intersil7170.4
--- share/man/man4/intersil7170.4	27 Jun 2003 18:32:02 -0000	1.9
+++ share/man/man4/intersil7170.4	1 Oct 2006 06:11:44 -0000
@@ -34,22 +34,23 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd July 20, 2000
+.Dd October 1, 2006
 .Dt INTERSIL7170 4
 .Os
 .Sh NAME
 .Nm intersil7170
 .Nd
-.Tn Intersil time-of-day clock driver
+.Tn Intersil ICM7170 time-of-day clock driver
 .Sh SYNOPSIS
-.In dev/ic/intersil7170.h
+.In dev/ic/intersil7170reg.h
+.In dev/ic/intersil7170var.h
 .Cd "define intersil7170"
 .Cd "file   dev/ic/intersil7170.c    intersil7170"
 .Sh DESCRIPTION
 The
 .Nm
 driver provides access to the
-.Tn Intersil 7170
+.Tn Intersil ICM7170
 time-of-day clock chip.
 Access methods to retrieve and set date and time
 are provided through the
@@ -57,18 +58,39 @@
 interface defined in
 .Xr todr 9 .
 .Pp
-To tie an instance of this device to the system, use
+To tie an instance of this device to the system, use the
+.Fn intersil7170_attach
+function and the
+.Fa intersil7170_softc
+structure defined as follows:
 .Pp
-.Ft "todr_chip_handle_t"
-.Fn intersil7170_attach "bus_space_tag_t bus_tag" \
-"bus_space_handle_t bus_handle" "int year0"
+.nr nS 1
+.Ft "void"
+.Fn intersil7170_attach "struct intersil7170_softc *"
+.Pp
+.Bd -literal
+struct intersil7170_softc {
+	struct device	sc_dev;
+	bus_space_tag_t	sc_bst;
+	bus_space_handle_t sc_bsh;
+	struct todr_chip_handle sc_handle;
+	u_int		sc_year0;
+	u_int		sc_flag;
+};
+.Ed
 .Pp
 .Bl -tag -width Dv -offset indent
 .It Fa bus_tag
 .It Fa bus_handle
 Specify bus space access to the chip's non-volatile memory
 .Pq including the clock registers .
-.It Fa year0
+.It Fa sc_handle
+TODR handle passed to the
+.Fn todr_attach
+function to register
+.Xr todr 9
+interface.
+.It Fa sc_year0
 The actual year represented by the clock's
 .Sq year
 counter.
@@ -76,14 +98,17 @@
 the clock device is mounted.
 For instance, on Sun Microsystems machines
 the convention is to have clock's two-digit year represent the year 1968.
+.It Fa sc_flag
+This flag is used to specify machine-dependent features.
 .El
 .Pp
 Note that if the resulting date retrieved with the todr_gettime() method
 is earlier that January 1, 1970, the driver will assume that the chip's
 year counter actually represents a year in the 21st century.
-This behaviour can be overridden by setting the global variable
-.Va intersil7170_auto_century_adjust
-to zero.
+This behaviour can be overridden by setting the
+.Va INTERSIL7170_NO_CENT_ADJUST
+flag in
+.Fa sc_flag .
 .Sh SEE ALSO
 .Xr intro 4 ,
 .Xr todr 9
Index: sys/arch/sparc/sparc/oclock.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/sparc/oclock.c,v
retrieving revision 1.13
diff -u -r1.13 oclock.c
--- sys/arch/sparc/sparc/oclock.c	3 Sep 2006 22:27:45 -0000	1.13
+++ sys/arch/sparc/sparc/oclock.c	1 Oct 2006 06:11:44 -0000
@@ -58,7 +58,8 @@
 #include <machine/autoconf.h>
 
 #include <dev/clock_subr.h>
-#include <dev/ic/intersil7170.h>
+#include <dev/ic/intersil7170reg.h>
+#include <dev/ic/intersil7170var.h>
 
 /* Imported from clock.c: */
 extern int oldclk;
@@ -69,24 +70,20 @@
 static int oclockmatch(struct device *, struct cfdata *, void *);
 static void oclockattach(struct device *, struct device *, void *);
 
-CFATTACH_DECL(oclock, sizeof(struct device),
+CFATTACH_DECL(oclock, sizeof(struct intersil7170_softc),
     oclockmatch, oclockattach, NULL, NULL);
 
 #if defined(SUN4)
 static bus_space_tag_t i7_bt;
 static bus_space_handle_t i7_bh;
 
-#define intersil_command(run, interrupt) \
-    (run | interrupt | INTERSIL_CMD_FREQ_32K | INTERSIL_CMD_24HR_MODE | \
-     INTERSIL_CMD_NORMAL_MODE)
-
-#define intersil_disable() \
-	bus_space_write_1(i7_bt, i7_bh, INTERSIL_ICMD, \
-		  intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE));
-
-#define intersil_enable() \
-	bus_space_write_1(i7_bt, i7_bh, INTERSIL_ICMD, \
-		  intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE));
+#define intersil_disable()						\
+	bus_space_write_1(i7_bt, i7_bh, INTERSIL_ICMD,			\
+	    INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE));
+
+#define intersil_enable()						\
+	bus_space_write_1(i7_bt, i7_bh, INTERSIL_ICMD,			\
+	    INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE));
 
 #define intersil_clear() bus_space_read_1(i7_bt, i7_bh, INTERSIL_IINTR)
 
@@ -129,22 +126,21 @@
 #if defined(SUN4)
 	union obio_attach_args *uoba = aux;
 	struct obio4_attach_args *oba = &uoba->uoba_oba4;
-	bus_space_tag_t bt = oba->oba_bustag;
-	bus_space_handle_t bh;
-	todr_chip_handle_t tch;
+	struct intersil7170_softc *sc = (void *)self;
 
 	oldclk = 1;  /* we've got an oldie! */
 
-	if (bus_space_map(bt,
+	sc->sc_bst = oba->oba_bustag;
+	if (bus_space_map(sc->sc_bst,
 			  oba->oba_paddr,
 			  sizeof(struct intersil7170),
 			  BUS_SPACE_MAP_LINEAR,	/* flags */
-			  &bh) != 0) {
+			  &sc->sc_bsh) != 0) {
 		printf("%s: can't map register\n", self->dv_xname);
 		return;
 	}
-	i7_bt = bt;
-	i7_bh = bh;
+	i7_bt = sc->sc_bst;
+	i7_bh = sc->sc_bsh;
 
 	/*
 	 * calibrate delay()
@@ -154,8 +150,8 @@
 		int ival;
 
 		/* Set to 1/100 second interval */
-		bus_space_write_1(bt, bh, INTERSIL_IINTR,
-				  INTERSIL_INTER_CSECONDS);
+		bus_space_write_1(sc->sc_bst, sc->sc_bsh, INTERSIL_IINTR,
+		    INTERSIL_INTER_CSECONDS);
 
 		/* enable clock */
 		intersil_enable();
@@ -192,10 +188,11 @@
 	intr_establish(10, 0, &level10, NULL);
 
 	/* Our TOD clock year 0 represents 1968 */
-	if ((tch = intersil7170_attach(bt, bh, 1968)) == NULL)
-		panic("Can't attach tod clock");
+	sc->sc_year0 = 1968;
+	intersil7170_attach(sc);
+
 	printf("\n");
-	todr_attach(tch);
+	todr_attach(&sc->sc_handle);
 #endif /* SUN4 */
 }
 
Index: sys/arch/sun3/conf/files.sun3
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/conf/files.sun3,v
retrieving revision 1.75
diff -u -r1.75 files.sun3
--- sys/arch/sun3/conf/files.sun3	1 Oct 2006 03:53:27 -0000	1.75
+++ sys/arch/sun3/conf/files.sun3	1 Oct 2006 06:11:44 -0000
@@ -116,9 +116,9 @@
 file dev/ic/z8530sc.c			zsc
 
 # Intersil or Mostek clock
-device clock
+device clock: mk48txx
 attach clock at obio
-device oclock
+device oclock: intersil7170
 attach oclock at obio
 file arch/sun3/sun3/clock.c		_sun3_
 file arch/sun3/sun3x/clock.c		_sun3x_
Index: sys/arch/sun3/sun3/clock.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/sun3/clock.c,v
retrieving revision 1.56
diff -u -r1.56 clock.c
--- sys/arch/sun3/sun3/clock.c	5 Sep 2006 06:45:05 -0000	1.56
+++ sys/arch/sun3/sun3/clock.c	1 Oct 2006 06:11:44 -0000
@@ -96,6 +96,7 @@
 #include <m68k/asm_single.h>
 
 #include <machine/autoconf.h>
+#include <machine/bus.h>
 #include <machine/cpu.h>
 #include <machine/leds.h>
 
@@ -104,7 +105,8 @@
 #include <sun3/sun3/machdep.h>
 
 #include <dev/clock_subr.h>
-#include <dev/ic/intersil7170.h>
+#include <dev/ic/intersil7170reg.h>
+#include <dev/ic/intersil7170var.h>
 
 extern int intrcnt[];
 
@@ -113,63 +115,54 @@
 
 void _isr_clock(void);	/* in locore.s */
 void clock_intr(struct clockframe);
-static int clk_get_secs(todr_chip_handle_t, volatile struct timeval *);
-static int clk_set_secs(todr_chip_handle_t, volatile struct timeval *);
-static struct todr_chip_handle clk_hdl = {
-	.todr_gettime = clk_get_secs,
-	.todr_settime = clk_set_secs,
-};
 
 static volatile void *intersil_va;
 
-#define intersil_clock ((volatile struct intersil7170 *) intersil_va)
-
-#define intersil_command(run, interrupt) \
-	(run | interrupt | INTERSIL_CMD_FREQ_32K | INTERSIL_CMD_24HR_MODE | \
-	 INTERSIL_CMD_NORMAL_MODE)
+#define intersil_clock ((volatile struct intersil7170 *)intersil_va)
 
 #define intersil_clear() (void)intersil_clock->clk_intr_reg
 
-static int  clock_match(struct device *, struct cfdata *, void *);
-static void clock_attach(struct device *, struct device *, void *);
+static int  oclock_match(struct device *, struct cfdata *, void *);
+static void oclock_attach(struct device *, struct device *, void *);
 
-CFATTACH_DECL(clock, sizeof(struct device),
-    clock_match, clock_attach, NULL, NULL);
+CFATTACH_DECL(oclock, sizeof(struct intersil7170_softc),
+    oclock_match, oclock_attach, NULL, NULL);
 
 static int 
-clock_match(struct device *parent, struct cfdata *cf, void *args)
+oclock_match(struct device *parent, struct cfdata *cf, void *aux)
 {
-	struct confargs *ca = args;
+	struct confargs *ca = aux;
 
 	/* This driver only supports one unit. */
 	if (intersil_va)
-		return (0);
+		return 0;
 
 	/* Make sure there is something there... */
 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 1) == -1)
-		return (0);
+		return 0;
 
 	/* Default interrupt priority. */
 	if (ca->ca_intpri == -1)
 		ca->ca_intpri = CLOCK_PRI;
 
-	return (1);
+	return 1;
 }
 
 static void 
-clock_attach(struct device *parent, struct device *self, void *args)
+oclock_attach(struct device *parent, struct device *self, void *aux)
 {
-	struct confargs *ca = args;
-	caddr_t va;
-
-	printf("\n");
+	struct confargs *ca = aux;
+	struct intersil7170_softc *sc = (void *)self;
 
 	/* Get a mapping for it. */
-	va = bus_mapin(ca->ca_bustype,
-	    ca->ca_paddr, sizeof(struct intersil7170));
-	if (!va)
-		panic("clock_attach");
-	intersil_va = va;
+	sc->sc_bst = ca->ca_bustag;
+	if (bus_space_map(sc->sc_bst, ca->ca_paddr, sizeof(struct intersil7170),
+	    0, &sc->sc_bsh) != 0) {
+		printf(": can't map registers\n");
+		return;
+	}
+
+	intersil_va = (void *)sc->sc_bsh;	/* XXX */
 
 	/*
 	 * Set the clock to the correct interrupt rate, but
@@ -178,12 +171,20 @@
 	 * at this point, so the clock interrupts should not
 	 * affect us, but we need to set the rate...
 	 */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE);
-	intersil_clear();
+	bus_space_write_1(sc->sc_bst, sc->sc_bsh, INTERSIL_ICMD,
+	    INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE));
+	(void)bus_space_read_1(sc->sc_bst, sc->sc_bsh, INTERSIL_IINTR);
 
 	/* Set the clock to 100 Hz, but do not enable it yet. */
-	intersil_clock->clk_intr_reg = INTERSIL_INTER_CSECONDS;
+	bus_space_write_1(sc->sc_bst, sc->sc_bsh,
+	    INTERSIL_IINTR, INTERSIL_INTER_CSECONDS);
+
+	sc->sc_year0 = 1968;
+	intersil7170_attach(sc);
+
+	printf("\n");
+
+	todr_attach(&sc->sc_handle);
 
 	/*
 	 * Can not hook up the ISR until cpu_initclocks()
@@ -191,7 +192,6 @@
 	 * For now, the handler is _isr_autovec(), which
 	 * will complain if it gets clock interrupts.
 	 */
-	todr_attach(&clk_hdl);
 }
 
 /*
@@ -245,7 +245,7 @@
 		 * interrupt register to clear any pending signals there.
 		 */
 		intersil_clock->clk_cmd_reg =
-		    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE);
+		    INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE);
 		intersil_clear();
 	}
 
@@ -255,7 +255,7 @@
 	/* Turn the clock back on (maybe) */
 	if (intersil_va && enable_clk)
 		intersil_clock->clk_cmd_reg =
-		    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
+		    INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
 
 	/* Finally, turn the "master" enable back on. */
 	single_inst_bset_b(*interrupt_reg, IREG_ALL_ENAB);
@@ -329,113 +329,3 @@
 	/* Call common clock interrupt handler. */
 	hardclock(&cf);
 }
-
-/*
- * Machine-dependent clock routines.
- *
- * Inittodr initializes the time of day hardware which provides
- * date functions.
- *
- * Resettodr restores the time of day hardware after a time change.
- */
-
-/*
- * Now routines to get and set clock as POSIX time.
- * Our clock keeps "years since 1/1/1968".
- */
-#define	CLOCK_BASE_YEAR 1968
-static void intersil_get_dt(struct clock_ymdhms *);
-static void intersil_set_dt(struct clock_ymdhms *);
-
-static int
-clk_get_secs(todr_chip_handle_t tch, volatile struct timeval *tvp)
-{
-	struct clock_ymdhms dt;
-
-	intersil_get_dt(&dt);
-
-	if ((dt.dt_hour > 24) ||
-	    (dt.dt_day  > 31) ||
-	    (dt.dt_mon  > 12))
-		return -1;
-
-	dt.dt_year += CLOCK_BASE_YEAR;
-	tvp->tv_sec = clock_ymdhms_to_secs(&dt);
-	return 0;
-}
-
-static int
-clk_set_secs(todr_chip_handle_t tch, volatile struct timeval *tvp)
-{
-	struct clock_ymdhms dt;
-
-	clock_secs_to_ymdhms(tvp->tv_sec, &dt);
-	dt.dt_year -= CLOCK_BASE_YEAR;
-
-	intersil_set_dt(&dt);
-	return 0;
-}
-
-
-/*
- * Routines to copy state into and out of the clock.
- * The intersil registers have to be read or written
- * in sequential order (or so it appears). -gwr
- */
-static void
-intersil_get_dt(struct clock_ymdhms *dt)
-{
-	volatile struct intersil_dt *isdt;
-	int s;
-
-	isdt = &intersil_clock->counters;
-	s = splhigh();
-
-	/* Enable read (stop time) */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
-
-	/* Copy the info.  Careful about the order! */
-	dt->dt_sec  = isdt->dt_csec;  /* throw-away */
-	dt->dt_hour = isdt->dt_hour;
-	dt->dt_min  = isdt->dt_min;
-	dt->dt_sec  = isdt->dt_sec;
-	dt->dt_mon  = isdt->dt_month;
-	dt->dt_day  = isdt->dt_day;
-	dt->dt_year = isdt->dt_year;
-	dt->dt_wday = isdt->dt_dow;
-
-	/* Done reading (time wears on) */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
-	splx(s);
-}
-
-static void
-intersil_set_dt(struct clock_ymdhms *dt)
-{
-	volatile struct intersil_dt *isdt;
-	int s;
-
-	isdt = &intersil_clock->counters;
-	s = splhigh();
-
-	/* Enable write (stop time) */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
-
-	/* Copy the info.  Careful about the order! */
-	isdt->dt_csec = 0;
-	isdt->dt_hour = dt->dt_hour;
-	isdt->dt_min  = dt->dt_min;
-	isdt->dt_sec  = dt->dt_sec;
-	isdt->dt_month= dt->dt_mon;
-	isdt->dt_day  = dt->dt_day;
-	isdt->dt_year = dt->dt_year;
-	isdt->dt_dow  = dt->dt_wday;
-
-	/* Done writing (time wears on) */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
-	splx(s);
-}
Index: sys/arch/sun3/sun3x/clock.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/sun3x/clock.c,v
retrieving revision 1.31
diff -u -r1.31 clock.c
--- sys/arch/sun3/sun3x/clock.c	5 Sep 2006 06:45:05 -0000	1.31
+++ sys/arch/sun3/sun3x/clock.c	1 Oct 2006 06:11:45 -0000
@@ -108,18 +108,20 @@
 #include <m68k/asm_single.h>
 
 #include <machine/autoconf.h>
+#include <machine/bus.h>
 #include <machine/cpu.h>
 #include <machine/idprom.h>
 #include <machine/leds.h>
 
 #include <dev/clock_subr.h>
-#include <dev/ic/intersil7170.h>
+#include <dev/ic/intersil7170reg.h>
+#include <dev/ic/intersil7170var.h>
+#include <dev/ic/mk48txxreg.h>
+#include <dev/ic/mk48txxvar.h>
 
 #include <sun3/sun3/machdep.h>
 #include <sun3/sun3/interreg.h>
 
-#include <sun3/sun3x/mk48t02.h>
-
 extern int intrcnt[];
 
 #define SUN3_470	Yes
@@ -127,6 +129,8 @@
 #define	CLOCK_PRI	5
 #define IREG_CLK_BITS	(IREG_CLOCK_ENAB_7 | IREG_CLOCK_ENAB_5)
 
+#define MKCLOCK_REG_OFFSET	(MK48T02_CLKOFF + MK48TXX_ICSR)
+
 /*
  * Only one of these two variables should be non-zero after
  * autoconfiguration determines which clock we have.
@@ -141,84 +145,75 @@
 static int  clock_match(struct device *, struct cfdata *, void *);
 static void clock_attach(struct device *, struct device *, void *);
 
-CFATTACH_DECL(clock, sizeof(struct device),
+CFATTACH_DECL(clock, sizeof(struct mk48txx_softc),
     clock_match, clock_attach, NULL, NULL);
 
 #ifdef	SUN3_470
 
-#define intersil_clock ((volatile struct intersil7170 *) intersil_va)
-
-#define intersil_command(run, interrupt) \
-	(run | interrupt | INTERSIL_CMD_FREQ_32K | INTERSIL_CMD_24HR_MODE | \
-	 INTERSIL_CMD_NORMAL_MODE)
+#define intersil_clock ((volatile struct intersil7170 *)intersil_va)
 
 #define intersil_clear() (void)intersil_clock->clk_intr_reg
 
 static int  oclock_match(struct device *, struct cfdata *, void *);
 static void oclock_attach(struct device *, struct device *, void *);
 
-CFATTACH_DECL(oclock, sizeof(struct device),
+CFATTACH_DECL(oclock, sizeof(struct intersil7170_softc),
     oclock_match, oclock_attach, NULL, NULL);
 
-static int clk_get_secs(todr_chip_handle_t, volatile struct timeval *);
-static int clk_set_secs(todr_chip_handle_t, volatile struct timeval *);
-static struct todr_chip_handle clk_hdl = {
-	.todr_gettime = clk_get_secs,
-	.todr_settime = clk_set_secs,
-};
 
 /*
  * Is there an intersil clock?
  */
 static int 
-oclock_match(struct device *parent, struct cfdata *cf, void *args)
+oclock_match(struct device *parent, struct cfdata *cf, void *aux)
 {
-	struct confargs *ca = args;
+	struct confargs *ca = aux;
 
 	/* This driver only supports one unit. */
 	if (intersil_va)
-		return (0);
+		return 0;
 
 	/*
 	 * The 3/80 can not probe the Intersil absent,
 	 * but it never has one, so "just say no."
 	 */
 	if (cpu_machine_id == ID_SUN3X_80)
-		return (0);
+		return 0;
 
 	/* OK, really probe for the Intersil. */
 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 1) == -1)
-		return (0);
+		return 0;
 
 	/* Default interrupt priority. */
 	if (ca->ca_intpri == -1)
 		ca->ca_intpri = CLOCK_PRI;
 
-	return (1);
+	return 1;
 }
 
 /*
  * Attach the intersil clock.
  */
 static void 
-oclock_attach(struct device *parent, struct device *self, void *args)
+oclock_attach(struct device *parent, struct device *self, void *aux)
 {
-	struct confargs *ca = args;
-	caddr_t va;
-
-	printf("\n");
+	struct confargs *ca = aux;
+	struct intersil7170_softc *sc = (void *)self;
 
 	/* Get a mapping for it. */
-	va = bus_mapin(ca->ca_bustype,
-	    ca->ca_paddr, sizeof(struct intersil7170));
-	if (!va)
-		panic("oclock_attach");
-	intersil_va = va;
+	sc->sc_bst = ca->ca_bustag;
+	if (bus_space_map(sc->sc_bst, ca->ca_paddr, sizeof(struct intersil7170),
+	    0, &sc->sc_bsh) != 0) {
+		printf(": can't map registers\n");
+		return;
+	}
+
+	intersil_va = (void *)sc->sc_bsh;	/* XXX */
 
 #ifdef	DIAGNOSTIC
 	/* Verify correct probe order... */
 	if (mostek_clk_va) {
-		mostek_clk_va = 0;
+		mostek_clk_va = NULL;
 		printf("%s: warning - mostek found also!\n", self->dv_xname);
 	}
 #endif
@@ -230,12 +225,20 @@
 	 * at this point, so the clock interrupts should not
 	 * affect us, but we need to set the rate...
 	 */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE);
-	intersil_clear();
+	bus_space_write_1(sc->sc_bst, sc->sc_bsh, INTERSIL_ICMD,
+	    INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE));
+	(void)bus_space_read_1(sc->sc_bst, sc->sc_bsh, INTERSIL_IINTR);
 
 	/* Set the clock to 100 Hz, but do not enable it yet. */
-	intersil_clock->clk_intr_reg = INTERSIL_INTER_CSECONDS;
+	bus_space_write_1(sc->sc_bst, sc->sc_bsh,
+	    INTERSIL_IINTR, INTERSIL_INTER_CSECONDS);
+
+	sc->sc_year0 = 1968;
+	intersil7170_attach(sc);
+
+	printf("\n");
+
+	todr_attach(&sc->sc_handle);
 
 	/*
 	 * Can not hook up the ISR until cpu_initclocks()
@@ -243,8 +246,6 @@
 	 * For now, the handler is _isr_autovec(), which
 	 * will complain if it gets clock interrupts.
 	 */
-
-	todr_attach(&clk_hdl);
 }
 #endif	/* SUN3_470 */
 
@@ -260,46 +261,46 @@
 
 	/* This driver only supports one unit. */
 	if (mostek_clk_va)
-		return (0);
+		return 0;
 
 	/* If intersil was found, use that. */
 	if (intersil_va)
-		return (0);
+		return 0;
 	/* Else assume a Mostek is there... */
 
 	/* Default interrupt priority. */
 	if (ca->ca_intpri == -1)
 		ca->ca_intpri = CLOCK_PRI;
 
-	return (1);
+	return 1;
 }
 
 /*
  * Attach the mostek clock.
  */
 static void 
-clock_attach(struct device *parent, struct device *self, void *args)
+clock_attach(struct device *parent, struct device *self, void *aux)
 {
-	struct confargs *ca = args;
-	caddr_t va;
+	struct mk48txx_softc *sc = (void *)self;
+	struct confargs *ca = aux;
 
-	printf("\n");
+	sc->sc_bst = ca->ca_bustag;
+	if (bus_space_map(sc->sc_bst, ca->ca_paddr - MKCLOCK_REG_OFFSET,
+	    MK48T02_CLKSZ, 0, &sc->sc_bsh) != 0) {
+		printf("can't map device space\n");
+		return;
+	}
 
-	/* Get a mapping for it. */
-	va = bus_mapin(ca->ca_bustype,
-	    ca->ca_paddr, sizeof(struct mostek_clkreg));
-	if (!va)
-		panic("clock_attach");
-	mostek_clk_va = va;
+	mostek_clk_va = (void *)(sc->sc_bsh + MKCLOCK_REG_OFFSET); /* XXX */
 
-	/*
-	 * Can not hook up the ISR until cpu_initclocks()
-	 * because hardclock is not ready until then.
-	 * For now, the handler is _isr_autovec(), which
-	 * will complain if it gets clock interrupts.
-	 */
+	sc->sc_model = "mk48t02";
+	sc->sc_year0 = 1968;
+
+	mk48txx_attach(sc);
 
-	todr_attach(&clk_hdl);
+	printf("\n");
+
+	todr_attach(&sc->sc_handle);
 }
 
 /*
@@ -354,7 +355,7 @@
 		 * interrupt register to clear any pending signals there.
 		 */
 		intersil_clock->clk_cmd_reg =
-		    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE);
+		    INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IDISABLE);
 		intersil_clear();
 	}
 #endif	/* SUN3_470 */
@@ -366,7 +367,7 @@
 	/* Turn the clock back on (maybe) */
 	if (intersil_va && enable_clk)
 		intersil_clock->clk_cmd_reg =
-		    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
+		    INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
 #endif	/* SUN3_470 */
 
 	/* Finally, turn the "master" enable back on. */
@@ -449,207 +450,3 @@
 	/* Call common clock interrupt handler. */
 	hardclock(&cf);
 }
-
-/*
- * Machine-dependent clock routines.
- *
- * Inittodr initializes the time of day hardware which provides
- * date functions.
- *
- * Resettodr restores the time of day hardware after a time change.
- */
-
-
-/*
- * Now routines to get and set clock as POSIX time.
- * Our clock keeps "years since 1/1/1968".
- */
-#define	CLOCK_BASE_YEAR 1968
-#ifdef	SUN3_470
-static void intersil_get_dt(struct clock_ymdhms *);
-static void intersil_set_dt(struct clock_ymdhms *);
-#endif /* SUN3_470 */
-static void mostek_get_dt(struct clock_ymdhms *);
-static void mostek_set_dt(struct clock_ymdhms *);
-
-static int 
-clk_get_secs(todr_chip_handle_t tch, volatile struct timeval *tvp)
-{
-	struct clock_ymdhms dt;
-
-	memset(&dt, 0, sizeof(dt));
-
-#ifdef	SUN3_470
-	if (intersil_va)
-		intersil_get_dt(&dt);
-#endif	/* SUN3_470 */
-	if (mostek_clk_va) {
-		/* Read the Mostek. */
-		mostek_get_dt(&dt);
-		/* Convert BCD values to binary. */
-		dt.dt_sec  = FROMBCD(dt.dt_sec);
-		dt.dt_min  = FROMBCD(dt.dt_min);
-		dt.dt_hour = FROMBCD(dt.dt_hour);
-		dt.dt_day  = FROMBCD(dt.dt_day);
-		dt.dt_mon  = FROMBCD(dt.dt_mon);
-		dt.dt_year = FROMBCD(dt.dt_year);
-	}
-
-	if ((dt.dt_hour > 24) ||
-	    (dt.dt_day  > 31) ||
-	    (dt.dt_mon  > 12))
-		return (-1);
-
-	dt.dt_year += CLOCK_BASE_YEAR;
-	tvp->tv_sec = clock_ymdhms_to_secs(&dt);
-	return 0;
-}
-
-static int 
-clk_set_secs(todr_chip_handle_t tch, volatile struct timeval *tvp)
-{
-	struct clock_ymdhms dt;
-
-	clock_secs_to_ymdhms(tvp->tv_sec, &dt);
-	dt.dt_year -= CLOCK_BASE_YEAR;
-
-#ifdef	SUN3_470
-	if (intersil_va)
-		intersil_set_dt(&dt);
-#endif	/* SUN3_470 */
-
-	if (mostek_clk_va) {
-		/* Convert binary values to BCD. */
-		dt.dt_sec  = TOBCD(dt.dt_sec);
-		dt.dt_min  = TOBCD(dt.dt_min);
-		dt.dt_hour = TOBCD(dt.dt_hour);
-		dt.dt_day  = TOBCD(dt.dt_day);
-		dt.dt_mon  = TOBCD(dt.dt_mon);
-		dt.dt_year = TOBCD(dt.dt_year);
-		/* Write the Mostek. */
-		mostek_set_dt(&dt);
-	}
-	return 0;
-}
-
-#ifdef	SUN3_470
-
-/*
- * Routines to copy state into and out of the clock.
- * The intersil registers have to be read or written
- * in sequential order (or so it appears). -gwr
- */
-static void
-intersil_get_dt(struct clock_ymdhms *dt)
-{
-	volatile struct intersil_dt *isdt;
-	int s;
-
-	isdt = &intersil_clock->counters;
-	s = splhigh();
-
-	/* Enable read (stop time) */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
-
-	/* Copy the info.  Careful about the order! */
-	dt->dt_sec  = isdt->dt_csec;  /* throw-away */
-	dt->dt_hour = isdt->dt_hour;
-	dt->dt_min  = isdt->dt_min;
-	dt->dt_sec  = isdt->dt_sec;
-	dt->dt_mon  = isdt->dt_month;
-	dt->dt_day  = isdt->dt_day;
-	dt->dt_year = isdt->dt_year;
-	dt->dt_wday = isdt->dt_dow;
-
-	/* Done reading (time wears on) */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
-	splx(s);
-}
-
-static void
-intersil_set_dt(struct clock_ymdhms *dt)
-{
-	volatile struct intersil_dt *isdt;
-	int s;
-
-	isdt = &intersil_clock->counters;
-	s = splhigh();
-
-	/* Enable write (stop time) */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
-
-	/* Copy the info.  Careful about the order! */
-	isdt->dt_csec = 0;
-	isdt->dt_hour = dt->dt_hour;
-	isdt->dt_min  = dt->dt_min;
-	isdt->dt_sec  = dt->dt_sec;
-	isdt->dt_month= dt->dt_mon;
-	isdt->dt_day  = dt->dt_day;
-	isdt->dt_year = dt->dt_year;
-	isdt->dt_dow  = dt->dt_wday;
-
-	/* Done writing (time wears on) */
-	intersil_clock->clk_cmd_reg =
-	    intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
-	splx(s);
-}
-
-#endif /* SUN3_470 */
-
-
-/*
- * Routines to copy state into and out of the clock.
- * The clock CSR has to be set for read or write.
- */
-static void
-mostek_get_dt(struct clock_ymdhms *dt)
-{
-	volatile struct mostek_clkreg *cl = mostek_clk_va;
-	int s;
-
-	s = splhigh();
-
-	/* enable read (stop time) */
-	cl->cl_csr |= CLK_READ;
-
-	/* Copy the info */
-	dt->dt_sec  = cl->cl_sec;
-	dt->dt_min  = cl->cl_min;
-	dt->dt_hour = cl->cl_hour;
-	dt->dt_wday = cl->cl_wday;
-	dt->dt_day  = cl->cl_mday;
-	dt->dt_mon  = cl->cl_month;
-	dt->dt_year = cl->cl_year;
-
-	/* Done reading (time wears on) */
-	cl->cl_csr &= ~CLK_READ;
-	splx(s);
-}
-
-static void
-mostek_set_dt(struct clock_ymdhms *dt)
-{
-	volatile struct mostek_clkreg *cl = mostek_clk_va;
-	int s;
-
-	s = splhigh();
-	/* enable write */
-	cl->cl_csr |= CLK_WRITE;
-
-	/* Copy the info */
-	cl->cl_sec = dt->dt_sec;
-	cl->cl_min = dt->dt_min;
-	cl->cl_hour = dt->dt_hour;
-	cl->cl_wday = dt->dt_wday;
-	cl->cl_mday = dt->dt_day;
-	cl->cl_month = dt->dt_mon;
-	cl->cl_year = dt->dt_year;
-
-	/* load them up */
-	cl->cl_csr &= ~CLK_WRITE;
-	splx(s);
-}
-
Index: sys/dev/ic/intersil7170.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/intersil7170.c,v
retrieving revision 1.7
diff -u -r1.7 intersil7170.c
--- sys/dev/ic/intersil7170.c	7 Sep 2006 05:09:29 -0000	1.7
+++ sys/dev/ic/intersil7170.c	1 Oct 2006 06:11:45 -0000
@@ -45,51 +45,32 @@
 #include <sys/param.h>
 #include <sys/malloc.h>
 #include <sys/systm.h>
+#include <sys/device.h>
 #include <sys/errno.h>
 
 #include <machine/bus.h>
 #include <dev/clock_subr.h>
-#include <dev/ic/intersil7170.h>
-
-#define intersil_command(run, interrupt) \
-	(run | interrupt | INTERSIL_CMD_FREQ_32K | INTERSIL_CMD_24HR_MODE | \
-	 INTERSIL_CMD_NORMAL_MODE)
-
-struct intersil7170_softc {
-	bus_space_tag_t		sil_bt;
-	bus_space_handle_t	sil_bh;
-	int			sil_year0;
-};
+#include <dev/ic/intersil7170reg.h>
+#include <dev/ic/intersil7170var.h>
 
 int intersil7170_gettime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
 int intersil7170_settime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
 
-int intersil7170_auto_century_adjust = 1;
-
-todr_chip_handle_t
-intersil7170_attach(bus_space_tag_t bt, bus_space_handle_t bh, int year0)
+void
+intersil7170_attach(struct intersil7170_softc *sc)
 {
 	todr_chip_handle_t handle;
-	struct intersil7170_softc *sil;
-	int sz;
 
 	printf(": intersil7170");
 
-	sz = ALIGN(sizeof(struct todr_chip_handle)) + sizeof(struct intersil7170);
-	handle = malloc(sz, M_DEVBUF, M_NOWAIT);
-	sil = (struct intersil7170_softc *)((u_long)handle +
-					ALIGN(sizeof(struct todr_chip_handle)));
-	handle->cookie = sil;
+	handle = &sc->sc_handle;
+
+	handle->cookie = sc;
 	handle->todr_gettime = NULL;
 	handle->todr_settime = NULL;
-	handle->todr_setwen = NULL;
 	handle->todr_gettime_ymdhms = intersil7170_gettime_ymdhms;
 	handle->todr_settime_ymdhms = intersil7170_settime_ymdhms;
-	sil->sil_bt = bt;
-	sil->sil_bh = bh;
-	sil->sil_year0 = year0;
-
-	return (handle);
+	handle->todr_setwen = NULL;
 }
 
 /*
@@ -98,10 +79,10 @@
 int
 intersil7170_gettime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
 {
-	struct intersil7170_softc *sil = handle->cookie;
-	bus_space_tag_t bt = sil->sil_bt;
-	bus_space_handle_t bh = sil->sil_bh;
-	u_int8_t cmd;
+	struct intersil7170_softc *sc = handle->cookie;
+	bus_space_tag_t bt = sc->sc_bst;
+	bus_space_handle_t bh = sc->sc_bsh;
+	uint8_t cmd;
 	int year;
 	int s;
 
@@ -109,11 +90,11 @@
 	s = splhigh();
 
 	/* Enable read (stop time) */
-	cmd = intersil_command(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
+	cmd = INTERSIL_COMMAND(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
 	bus_space_write_1(bt, bh, INTERSIL_ICMD, cmd);
 
 	/* The order of reading out the clock elements is important */
-	bus_space_read_1(bt, bh, INTERSIL_ICSEC);	/* not used */
+	(void)bus_space_read_1(bt, bh, INTERSIL_ICSEC);	/* not used */
 	dt->dt_hour = bus_space_read_1(bt, bh, INTERSIL_IHOUR);
 	dt->dt_min = bus_space_read_1(bt, bh, INTERSIL_IMIN);
 	dt->dt_sec = bus_space_read_1(bt, bh, INTERSIL_ISEC);
@@ -123,17 +104,18 @@
 	dt->dt_wday = bus_space_read_1(bt, bh, INTERSIL_IDOW);
 
 	/* Done writing (time wears on) */
-	cmd = intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
+	cmd = INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
 	bus_space_write_1(bt, bh, INTERSIL_ICMD, cmd);
 	splx(s);
 
-	year += sil->sil_year0;
-	if (year < 1970 && intersil7170_auto_century_adjust != 0)
+	year += sc->sc_year0;
+	if (year < POSIX_BASE_YEAR &&
+	    (sc->sc_flag & INTERSIL7170_NO_CENT_ADJUST) == 0)
 		year += 100;
 
 	dt->dt_year = year;
 
-	return (0);
+	return 0;
 }
 
 /*
@@ -142,22 +124,22 @@
 int
 intersil7170_settime_ymdhms(todr_chip_handle_t handle, struct clock_ymdhms *dt)
 {
-	struct intersil7170_softc *sil = handle->cookie;
-	bus_space_tag_t bt = sil->sil_bt;
-	bus_space_handle_t bh = sil->sil_bh;
-	u_int8_t cmd;
+	struct intersil7170_softc *sc = handle->cookie;
+	bus_space_tag_t bt = sc->sc_bst;
+	bus_space_handle_t bh = sc->sc_bsh;
+	uint8_t cmd;
 	int year;
 	int s;
 
-	year = dt->dt_year - sil->sil_year0;
-	if (year > 99 && intersil7170_auto_century_adjust != 0)
+	year = dt->dt_year - sc->sc_year0;
+	if (year > 99 && (sc->sc_flag & INTERSIL7170_NO_CENT_ADJUST) == 0)
 		year -= 100;
 
 	/* No interrupts while we're fiddling with the chip */
 	s = splhigh();
 
 	/* Enable write (stop time) */
-	cmd = intersil_command(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
+	cmd = INTERSIL_COMMAND(INTERSIL_CMD_STOP, INTERSIL_CMD_IENABLE);
 	bus_space_write_1(bt, bh, INTERSIL_ICMD, cmd);
 
 	/* The order of reading writing the clock elements is important */
@@ -171,9 +153,9 @@
 	bus_space_write_1(bt, bh, INTERSIL_IDOW, dt->dt_wday);
 
 	/* Done writing (time wears on) */
-	cmd = intersil_command(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
+	cmd = INTERSIL_COMMAND(INTERSIL_CMD_RUN, INTERSIL_CMD_IENABLE);
 	bus_space_write_1(bt, bh, INTERSIL_ICMD, cmd);
 	splx(s);
 
-	return (0);
+	return 0;
 }
--- /dev/null	2006-10-01 15:10:44.000000000 +0900
+++ sys/dev/ic/intersil7170reg.h	2006-10-01 13:33:04.000000000 +0900
@@ -0,0 +1,124 @@
+/*	$NetBSD$	*/
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Adam Glass.
+ *
+ * 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.
+ */
+
+#ifndef	_INTERSIL7170REG_H_
+#define	_INTERSIL7170REG_H_
+
+/*
+ * Driver support for the intersil7170 used in sun[34]s to provide
+ * real time clock and time-of-day support.
+ *
+ * Derived from: datasheet "ICM7170 a uP-Compatible Real-Time Clock"
+ *                          document #301680-005, Dec 85
+ *
+ * Note that this device provides both time-of-day and interval timer
+ * functionality. Both functions use the same control registers. On top
+ * of that, the command control register is write-only. Currently, this
+ * driver assumes that the interval timer is to be enabled, and hence
+ * always sets/restores the INTERSIL_CMD_IENABLE control bit when
+ * manipulating the TOD.
+ */
+
+struct intersil_dt {		/* from p. 7 of 10 */
+	uint8_t dt_csec;   
+	uint8_t dt_hour;   
+	uint8_t dt_min;
+	uint8_t dt_sec;
+	uint8_t dt_month;
+	uint8_t dt_day;
+	uint8_t dt_year;   
+	uint8_t dt_dow;
+};  
+
+struct intersil7170 {
+	struct intersil_dt counters; 
+	struct intersil_dt clk_ram; /* should be ok as both are word aligned */
+	uint8_t clk_intr_reg;
+	uint8_t clk_cmd_reg;
+};
+
+/* Indices to time-of-day clock registers */
+#define INTERSIL_ICSEC	0
+#define INTERSIL_IHOUR	1
+#define INTERSIL_IMIN	2
+#define INTERSIL_ISEC	3
+#define INTERSIL_IMON	4
+#define INTERSIL_IDAY	5
+#define INTERSIL_IYEAR	6
+#define INTERSIL_IDOW	7
+
+#define INTERSIL_IINTR	16
+#define INTERSIL_ICMD	17
+
+/*  bit assignments for command register, p. 6 of 10, write-only */
+#define INTERSIL_CMD_FREQ_32K    0x0
+#define INTERSIL_CMD_FREQ_1M     0x1
+#define INTERSIL_CMD_FREQ_2M     0x2
+#define INTERSIL_CMD_FREQ_4M     0x3
+
+#define INTERSIL_CMD_12HR_MODE   0x0
+#define INTERSIL_CMD_24HR_MODE   0x4
+
+#define INTERSIL_CMD_STOP        0x0
+#define INTERSIL_CMD_RUN         0x8
+
+#define INTERSIL_CMD_IDISABLE   0x0
+#define INTERSIL_CMD_IENABLE   0x10
+
+#define INTERSIL_CMD_TEST_MODE      0x20
+#define INTERSIL_CMD_NORMAL_MODE    0x0
+
+#define INTERSIL_COMMAND(run, interrupt)				\
+        ((run) | (interrupt) | INTERSIL_CMD_FREQ_32K |			\
+	INTERSIL_CMD_24HR_MODE | INTERSIL_CMD_NORMAL_MODE)
+   
+/* bit assignments for interrupt register r/w, p 7 of 10 */
+
+#define INTERSIL_INTER_ALARM       0x1 /* r/w */
+#define INTERSIL_INTER_CSECONDS    0x2 /* r/w */
+#define INTERSIL_INTER_DSECONDS    0x4 /* r/w */
+#define INTERSIL_INTER_SECONDS     0x8 /* r/w */
+#define INTERSIL_INTER_MINUTES    0x10 /* r/w */
+#define INTERSIL_INTER_HOURS      0x20 /* r/w */
+#define INTERSIL_INTER_DAYS       0x40 /* r/w */
+#define INTERSIL_INTER_PENDING    0x80 /* read-only */
+
+#define INTERSIL_INTER_BITS	\
+	"\20\10PENDING\7DAYS\6HRS\5MIN\4SCDS\3DSEC\2CSEC\1ALARM"
+
+#endif	/* _INTERSIL7170REG_H_ */
--- /dev/null	2006-10-01 15:10:44.000000000 +0900
+++ sys/dev/ic/intersil7170var.h	2006-10-01 13:51:49.000000000 +0900
@@ -0,0 +1,63 @@
+/*	$NetBSD$	*/
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Adam Glass.
+ *
+ * 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.
+ */
+
+#ifndef	_INTERSIL7170VAR_H_
+#define	_INTERSIL7170VAR_H_
+
+/*
+ * Driver support for the intersil7170 used in sun[34]s to provide
+ * real time clock and time-of-day support.
+ */
+
+struct intersil7170_softc {
+	struct device	sc_dev;
+
+	bus_space_tag_t	sc_bst;			/* bus_space(9) tag */
+	bus_space_handle_t sc_bsh;		/* bus_space(9) handle */
+	struct todr_chip_handle sc_handle;	/* todr(9) handle */
+	u_int		sc_year0;		/* what year is represented on
+						   the system by the chip's
+						   year counter at 0 */
+	u_int		sc_flag;
+#define INTERSIL7170_NO_CENT_ADJUST	0x0001
+};
+
+/* common attach function */
+void intersil7170_attach(struct intersil7170_softc *);
+
+#endif	/* _INTERSIL7170VAR_H_ */