Subject: generic todr implementation for hp700
To: None <port-hp700@NetBSD.org>
From: Garrett D'Amore <garrett_damore@tadpole.com>
List: port-hp700
Date: 09/14/2006 10:17:48
This is a multi-part message in MIME format.
--------------020609060800070604030606
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Attached is the code to convert hp700 to generic TODR.  Testing and
commit approval desired. :-)

-- 
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


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

Index: sys/arch/hp700/dev/clock.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hp700/dev/clock.c,v
retrieving revision 1.4
diff -d -p -u -r1.4 clock.c
--- sys/arch/hp700/dev/clock.c	11 Dec 2005 12:17:24 -0000	1.4
+++ sys/arch/hp700/dev/clock.c	14 Sep 2006 17:16:56 -0000
@@ -58,21 +58,27 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.
 #include <ddb/db_extern.h>
 #endif
 
-volatile struct timeval time;
-
-void startrtclock(void);
-
 static struct pdc_tod tod PDC_ALIGNMENT;
 
+static int gettod(todr_chip_handle_t, volatile struct timeval *);
+static int settod(todr_chip_handle_t, volatile struct timeval *);
+
 void
 cpu_initclocks(void)
 {
+	static struct todr_chip_handle todr = {
+		.todr_settime = settod,
+		.todr_gettime = gettod,
+	};
 	extern u_int cpu_hzticks;
 	u_int time_inval;
 
 	/* Start the interval timer. */
 	mfctl(CR_ITMR, time_inval);
 	mtctl(time_inval + cpu_hzticks, CR_ITMR);
+
+	/* attach the TOD clock */
+	todr_attach(&todr);
 }
 
 int
@@ -98,57 +104,33 @@ clock_intr(void *v)
 }
 
 
-/*
- * initialize the system time from the time of day clock
- */
-void
-inittodr(time_t t)
+int
+gettod(todr_chip_handle_t tch, volatile struct timeval *tvp)
 {
-	int 	tbad = 0;
-	int pagezero_cookie;
-
-	if (t < 5*SECYR) {
-		printf ("WARNING: preposterous time in file system");
-		t = 6*SECYR + 186*SECDAY + SECDAY/2;
-		tbad = 1;
-	}
-
+	int	pagezero_cookie;
+	
 	pagezero_cookie = hp700_pagezero_map();
 	pdc_call((iodcio_t)PAGE0->mem_pdc, 1, PDC_TOD, PDC_TOD_READ,
 		&tod, 0, 0, 0, 0, 0);
 	hp700_pagezero_unmap(pagezero_cookie);
 
-	time.tv_sec = tod.sec;
-	time.tv_usec = tod.usec;
-
-	if (!tbad) {
-		u_long	dt;
-
-		dt = (time.tv_sec < t)?  t - time.tv_sec : time.tv_sec - t;
-
-		if (dt < 2 * SECDAY)
-			return;
-		printf("WARNING: clock %s %ld days",
-		    time.tv_sec < t? "lost" : "gained", dt / SECDAY);
-	}
-
-	printf (" -- CHECK AND RESET THE DATE!\n");
+	tvp->tv_sec = tod.sec;
+	tvp->tv_usec = tod.usec;
+	return 0;
 }
 
-/*
- * reset the time of day clock to the value in time
- */
-void
-resettodr(void)
+int
+settod(todr_chip_handle_t tch, volatile struct timeval *tvp)
 {
-	int pagezero_cookie;
+	int	pagezero_cookie;
 
-	tod.sec = time.tv_sec;
-	tod.usec = time.tv_usec;
+	tod.sec = tvp->tv_sec;
+	tod.usec = tvp->tv_usec;
 
 	pagezero_cookie = hp700_pagezero_map();
 	pdc_call((iodcio_t)PAGE0->mem_pdc, 1, PDC_TOD, PDC_TOD_WRITE, &tod);
 	hp700_pagezero_unmap(pagezero_cookie);
+	return 0;
 }
 
 void
Index: sys/arch/hp700/include/types.h
===================================================================
RCS file: /cvsroot/src/sys/arch/hp700/include/types.h,v
retrieving revision 1.5
diff -d -p -u -r1.5 types.h
--- sys/arch/hp700/include/types.h	3 Sep 2006 13:51:23 -0000	1.5
+++ sys/arch/hp700/include/types.h	14 Sep 2006 17:16:56 -0000
@@ -7,5 +7,6 @@
 
 #define	__HAVE_GENERIC_SOFT_INTERRUPTS
 #define	__HAVE_DEVICE_REGISTER
+#define	__HAVE_GENERIC_TODR
 
 #endif	/* _HP700_TYPES_H_ */

--------------020609060800070604030606--