Subject: todr changes for sbmips
To: None <port-sbmips@netbsd.org>
From: Garrett D'Amore <garrett_damore@tadpole.com>
List: port-sbmips
Date: 09/13/2006 07:59:43
This is a multi-part message in MIME format.
--------------090807060909020000040906
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

These are pretty trivial.  Here are the diffs. 

sbmips timecounters are harder, due to SMP considerations, so I have not
attempted that.

-- 
Garrett D'Amore, Principal Software Engineer
Tadpole Computer / Computing Technologies Division,
General Dynamics C4 Systems
http://www.tadpolecomputer.com/
Phone: 951 325-2134  Fax: 951 325-2191


--------------090807060909020000040906
Content-Type: text/x-patch;
 name="sbmips.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="sbmips.diff"

Index: sys/arch/sbmips/include/systemsw.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sbmips/include/systemsw.h,v
retrieving revision 1.5
diff -d -p -u -r1.5 systemsw.h
--- sys/arch/sbmips/include/systemsw.h	11 Nov 2005 23:45:56 -0000	1.5
+++ sys/arch/sbmips/include/systemsw.h	13 Sep 2006 14:58:07 -0000
@@ -51,10 +51,6 @@ struct systemsw {
 	void	(*s_statclock_init)(void *);
 	void	(*s_statclock_setrate)(void *, int);
 
-	void	*s_todr_arg;
-	void	(*s_inittodr)(void *, time_t);
-	void	(*s_resettodr)(void *);
-
 	void	*(*s_intr_establish)(u_int, u_int,
 		    void (*fun)(void *, uint32_t, uint32_t), void *);
 };
Index: sys/arch/sbmips/include/types.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sbmips/include/types.h,v
retrieving revision 1.2
diff -d -p -u -r1.2 types.h
--- sys/arch/sbmips/include/types.h	11 Nov 2005 23:45:56 -0000	1.2
+++ sys/arch/sbmips/include/types.h	13 Sep 2006 14:58:07 -0000
@@ -4,3 +4,4 @@
 
 #define	__HAVE_DEVICE_REGISTER
 #define	__HAVE_GENERIC_SOFT_INTERRUPTS
+#define	__HAVE_GENERIC_TODR
Index: sys/arch/sbmips/sbmips/rtc.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sbmips/sbmips/rtc.c,v
retrieving revision 1.13
diff -d -p -u -r1.13 rtc.c
--- sys/arch/sbmips/sbmips/rtc.c	4 Sep 2006 23:45:30 -0000	1.13
+++ sys/arch/sbmips/sbmips/rtc.c	13 Sep 2006 14:58:07 -0000
@@ -76,8 +76,6 @@ static void strtc_attach(struct device *
 static int strtc_gettime(todr_chip_handle_t, volatile struct timeval *);
 static int strtc_settime(todr_chip_handle_t, volatile struct timeval *);
 
-static void rtc_inittodr(void *, time_t base);
-static void rtc_resettodr(void *);
 static void rtc_cal_timer(void);
 
 static void time_smbus_init(int);
@@ -141,7 +139,7 @@ xirtc_attach(struct device *parent, stru
 	sc->sc_ct.todr_settime = xirtc_settime;
 	sc->sc_ct.todr_gettime = xirtc_gettime;
 
-	system_set_todrfns(sc, rtc_inittodr, rtc_resettodr);
+	todr_attach(&sc->sc_ct);
 
 	printf("\n");
 	rtc_cal_timer();	/* XXX */
@@ -257,7 +255,7 @@ strtc_attach(struct device *parent, stru
 	sc->sc_ct.todr_settime = strtc_settime;
 	sc->sc_ct.todr_gettime = strtc_gettime;
 
-	system_set_todrfns(sc, rtc_inittodr, rtc_resettodr);
+	todr_attach(&sc->sc_ct);
 
 	printf("\n");
 	rtc_cal_timer();	/* XXX */
@@ -317,57 +315,6 @@ strtc_gettime(todr_chip_handle_t handle,
 	return (0);
 }
 
-static void
-rtc_inittodr(void *cookie, time_t base)
-{
-	struct timeval todrtime;
-	todr_chip_handle_t chip;
-	struct rtc_softc *sc = cookie;
-	int check;
-
-	check = 0;
-	if (sc == NULL) {
-		printf("inittodr: rtc0 not present");
-		time.tv_sec = base;
-		time.tv_usec = 0;
-		check = 1;
-	} else {
-		chip = &sc->sc_ct;
-		if (todr_gettime(chip, &todrtime) != 0) {
-			printf("inittodr: Error reading clock");
-			time.tv_sec = base;
-			time.tv_usec = 0;
-			check = 1;
-		} else {
-			time = todrtime;
-			if (time.tv_sec > base + 3 * SECDAY) {
-				printf("inittodr: Clock has gained %ld days",
-				    (time.tv_sec - base) / SECDAY);
-				check = 1;
-			} else if (time.tv_sec + SECDAY < base) {
-				printf("inittodr: Clock has lost %ld day(s)",
-				    (base - time.tv_sec) / SECDAY);
-				check = 1;
-			}
-		}
-	}
-	if (check)
-		printf(" - CHECK AND RESET THE DATE.\n");
-
-}
-
-static void
-rtc_resettodr(void *cookie)
-{
-	struct rtc_softc *sc = cookie;
-
-	if (time.tv_sec == 0)
-		return;
-
-	if (todr_settime(&sc->sc_ct, &time) != 0)
-		printf("resettodr: cannot set time in time-of-day clock\n");
-}
-
 #define	NITERS			3
 #define	RTC_SECONDS(rtc)	FROMBCD(READRTC((rtc), X1241REG_SC))
 
Index: sys/arch/sbmips/sbmips/systemsw.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sbmips/sbmips/systemsw.c,v
retrieving revision 1.10
diff -d -p -u -r1.10 systemsw.c
--- sys/arch/sbmips/sbmips/systemsw.c	11 Nov 2005 23:45:56 -0000	1.10
+++ sys/arch/sbmips/sbmips/systemsw.c	13 Sep 2006 14:58:07 -0000
@@ -48,9 +48,7 @@ static void	clock_init_triv(void *);
 static uint32_t	clkread_triv(void);
 static void	cpu_intr_triv(uint32_t, uint32_t, uint32_t, uint32_t);
 static void	delay_triv(u_long);
-static void	inittodr_triv(void *, time_t);
 static void	microtime_triv(struct timeval *);
-static void	resettodr_triv(void *);
 
 /* system function switch */
 struct systemsw systemsw = {
@@ -66,9 +64,6 @@ struct systemsw systemsw = {
 	NULL,			/* s_statclock_init: dflt no-op */
 	NULL,			/* s_statclock_setrate: dflt no-op */
 
-	NULL,			/* todr functions arg */
-	inittodr_triv,
-	resettodr_triv,
 	NULL,			/* intr_establish */
 };
 
@@ -83,21 +78,6 @@ system_set_clockfns(void *arg, void (*in
 	return 0;
 }
 
-int
-system_set_todrfns(void *arg, void (*init)(void *, time_t),
-    void (*reset)(void *))
-{
-
-	if (systemsw.s_inittodr != inittodr_triv ||
-	    systemsw.s_resettodr != resettodr_triv)
-		return 1;
-	systemsw.s_todr_arg = arg;
-	systemsw.s_inittodr = init;
-	systemsw.s_resettodr = reset;
-	return 0;
-}
-
-
 /* trivial microtime() implementation */
 static void
 microtime_triv(struct timeval *tvp)
@@ -178,20 +158,6 @@ clock_init_triv(void *arg)
 	panic("clock_init_triv");
 }
 
-static void
-inittodr_triv(void *arg, time_t t)
-{
-
-	time.tv_sec = t;
-}
-
-static void
-resettodr_triv(void *arg)
-{
-
-	/* do nothing */
-}
-
 void
 cpu_initclocks(void)
 {
@@ -218,17 +184,3 @@ setstatclockrate(int hzrate)
 		(*systemsw.s_statclock_setrate)(systemsw.s_statclock_arg,
 		    hzrate);
 }
-
-void
-inittodr(time_t t)
-{
-
-	(*systemsw.s_inittodr)(systemsw.s_todr_arg, t);
-}
-
-void
-resettodr(void)
-{
-
-	(*systemsw.s_resettodr)(systemsw.s_todr_arg);
-}

--------------090807060909020000040906--