Re: RTC todr for mips/alchemy

Shigeyuki Fukushima <[email protected]>
Newsgroups gmane.os.netbsd.ports.evbmips
Organization NetBSD Developper
Message-ID <[email protected]>
Garrett D'Amore wrote:

> But, the first step is to make evbmips/evmips/clock.c support todr_attach.
> That should be the direction you proceed, I think.

Please add the following code to evbmips/evbmips/clock.c:

===========================
todr_chip_handle_t todr_handle;

void
todr_attach(todr_chip_handle_t todr)
{

        if (todr_handle)
                panic("todr_attach: realtime-clock already configured");
        todr_handle = todr;
}
===========================

But it isn't enough to support todr functions.
We must change inittodr()/resettodr() to use todr_{get,set}time
functions properly.
Such changes cause a break of aurtc.

First, we should change aurtc device driver. ok?


FYI: attached clock.c sample fix for clock.c.

-- 
Kind Regards,
--- shige
Shigeyuki Fukushima <shige@{FreeBSD,jp.FreeBSD,NetBSD}.org>
clock.c.diff (text/plain, 2.2 KB)
Index: sys/arch/evbmips/evbmips/clock.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbmips/evbmips/clock.c,v
retrieving revision 1.6
diff -u -r1.6 clock.c
--- sys/arch/evbmips/evbmips/clock.c	11 Dec 2005 12:17:11 -0000	1.6
+++ sys/arch/evbmips/evbmips/clock.c	8 Mar 2006 14:05:20 -0000
@@ -100,6 +100,7 @@
 struct device *clockdev;
 const struct clockfns *clockfns;
 int clockinitted;
+todr_chip_handle_t todr_handle;
 
 void
 clockattach(struct device *dev, const struct clockfns *fns)
@@ -116,6 +117,15 @@
 	clockfns = fns;
 }
 
+void
+todr_attach(todr_chip_handle_t todr)
+{
+
+	if (todr_handle)
+		panic("todr_attach: realtime-clock already configured");
+	todr_handle = todr;
+}
+
 /*
  * Machine-dependent clock routines.
  *
@@ -182,9 +192,13 @@
 void
 inittodr(time_t base)
 {
+#ifdef USE_CLOCKSUBR
+	struct timeval todrtime;
+#else
 	struct clocktime ct;
 	int year;
 	struct clock_ymdhms dt;
+#endif
 	time_t deltat;
 	int badbase;
 
@@ -196,6 +210,24 @@
 	} else
 		badbase = 0;
 
+#ifdef USE_CLOCKSUBR
+	if (todr_handle == NULL) {
+		printf("inittodr: rtc not present");
+		time.tv_sec = base;
+		time.tv_usec = 0;
+		goto bad;
+	}
+
+	if (todr_gettime(todr_handle, &todrtime) != 0) {
+		printf("inittodr: Error reading clock");
+		time.tv_sec = base;
+		time.tv_usec = 0;
+		goto bad;
+	}
+	time = todrtime;
+	badbase = 0;
+	clockinitted = 1;
+#else
 	(*clockfns->cf_get)(clockdev, base, &ct);
 #ifdef DEBUG
 	printf("readclock: %d/%d/%d/%d/%d/%d\n", ct.year, ct.mon, ct.day,
@@ -229,6 +261,8 @@
 	dt.dt_min = ct.min;
 	dt.dt_sec = ct.sec;
 	time.tv_sec = clock_ymdhms_to_secs(&dt);
+#endif
+
 #ifdef DEBUG
 	printf("=>%ld (%ld)\n", time.tv_sec, base);
 #endif
@@ -261,12 +295,20 @@
 void
 resettodr(void)
 {
+#ifdef USE_CLOCKSUBR
+#else
 	struct clock_ymdhms dt;
 	struct clocktime ct;
+#endif
 
 	if (!clockinitted)
 		return;
 
+#ifdef USE_CLOCKSUBR
+	if (todr_handle != NULL &&
+		todr_settime(todr_handle, &time) != 0)
+		printf("resettodr: failed to set time\n");
+#else
 	clock_secs_to_ymdhms(time.tv_sec, &dt);
 
 	/* rt clock wants 2 digits */
@@ -283,6 +325,7 @@
 #endif
 
 	(*clockfns->cf_set)(clockdev, &ct);
+#endif
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.