Subject: port-dreamcast/22319: Cannot set time in rtc
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <ryo@nerv.org>
List: netbsd-bugs
Date: 07/31/2003 10:18:17
>Number:         22319
>Category:       port-dreamcast
>Synopsis:       Cannot set time in rtc
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-dreamcast-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 31 10:19:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     SHIMIZU Ryo
>Release:        1.6U
>Organization:
>Environment:
NetBSD guruguru 1.6U NetBSD 1.6U (GURUGURU) #210: Thu Jul 31 18:33:14 JST 2003  ryo@moveq.nerv.org:/usr/src/sys/arch/dreamcast/compile/GURUGURU dreamcast

>Description:
Cannot set time in dreamcast rtc. (Not supported)
>How-To-Repeat:
#date
Thu Jul 31 11:11:55 JST 2003
#date 1200
Thu Jul 31 12:00:00 JST 2003
#reboot

...and login again,

#date
The Jul 31 11:13:02 JST 2003
>Fix:
Index: clock_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/dreamcast/dreamcast/clock_machdep.c,v
retrieving revision 1.2
diff -a -b -c -1 -r1.2 clock_machdep.c
*** clock_machdep.c     2003/07/15 01:31:41     1.2
--- clock_machdep.c     2003/07/31 09:58:33
***************
*** 57,58 ****
--- 57,59 ----
  STATIC u_int32_t dreamcast_read_rtc(void);
+ STATIC void dreamcast_write_rtc(u_int32_t);
  
***************
*** 88,90 ****
  
!       /* Not suppoted */
  }
--- 89,91 ----
  
!       dreamcast_write_rtc(clock_ymdhms_to_secs(dt));
  }
***************
*** 113 ****
--- 114,145 ----
  }
+ 
+ void
+ dreamcast_write_rtc(u_int32_t secs)
+ {
+       __volatile__ u_int32_t *rtc = (__volatile__ u_int32_t *)DREAMCAST_RTC;
+       u_int32_t new;
+       int i, retry;
+ 
+       /* offset 20 years */
+       secs += 631152000;
+ 
+       for (retry = 0; retry < 5; retry++) {
+ 
+               /* Don't change an order */
+               rtc[2] = 1;
+               rtc[1] = (secs & 0xffff);
+               rtc[0] = (secs >> 16);
+ 
+               /* verify */
+               for (i = 0; i < 3; i++) {
+                       new = ((rtc[0] & 0xffff) << 16) | (rtc[1] & 0xffff);
+                       if (new == secs)
+                               goto success;
+               }
+       }
+       /* set failure. but nothing to do */
+ 
+ success:
+       return;
+ }
+ 

>Release-Note:
>Audit-Trail:
>Unformatted: