Subject: Re: RTC todr for mips/alchemy
To: Shigeyuki Fukushima <shige@netbsd.org>
From: Garrett D'Amore <garrett_damore@tadpole.com>
List: port-evbmips
Date: 03/08/2006 13:57:13
Shigeyuki Fukushima wrote:
> 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?
>
No, my vote is to change aurtc.c AND the mcclockc. in malta at the
*same* time. Put the common inittodr/resettodr logic in clock.c.
I thinks this should be unconditional, and remove the #ifdef USE_CLOCKSUBR.
I also *really* want the inittodr/resettodr functions *not* to panic if
there is no TODR registered. The forthcoming AR5312 port has no
external time-of-day clock. I'd rather not have to provide a stupid
stub RTC just to keep the stuff in clock.c happy.
-- Garrett
>
> FYI: attached clock.c sample fix for clock.c.
>
>
> ------------------------------------------------------------------------
>
> 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
> }
>
>
>
--
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