Subject: port-acorn32/15313: CMOS Clock writing broken on RiscPC.
To: None <gnats-bugs@gnats.netbsd.org>
From: Mike Pumford <mpumford@black-star.demon.co.uk>
List: netbsd-bugs
Date: 01/20/2002 13:53:32
>Number:         15313
>Category:       port-acorn32
>Synopsis:       CMOS Clock writing broken on RiscPC.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-acorn32-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 20 05:54:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Mike Pumford
>Release:        NetBSD 1.5Z
>Organization:
None
>Environment:
System: NetBSD black-star.demon.co.uk 1.5Z NetBSD 1.5Z (BSTAR_WS) #0: Wed Dec 12 00:03:05 GMT 2001 mpumford@black-star.demon.co.uk:/usr/src/netbsd/sys/arch/acorn32/compile/BSTAR_WS acorn32
Architecture: arm32
Machine: acorn32
>Description:
The CMOS clock writing code has been disabled (due to brokenness) for 
ages. This patch resolves the CMOS write problem and re-enables the
CMOS clock write. (Useful when running ntpd)
>How-To-Repeat:
	Set the time using date or any other time setting mechanism. 
	kernel dmesg will print 'rtc_write: Currently disabled'.

>Fix:

This patch fixes and re-enables the CMOS clock write. The 
#ifdef RTC_VERBOSE code is debug code used during the development
of the patch and can be removed.

-------------Cut Here------------------
        if (iic_control(RTC_Write, buff, 2))
                return(-1);
 
 /* Now update the checksum. This code only modifies the value. It does */
 /* not recalculate it */
-
+  
        buff[0] = RTC_ADDR_CHECKSUM;
        buff[1] = oldsum - oldvalue + value;
        if (iic_control(RTC_Write, buff, 2))
                return(-1);
-       
+      
        return(0);
 }
 
@@ -177,12 +178,11 @@
        u_char buff[8];
 
        buff[0] = 1;
-
-               
+
        if (iic_control(RTC_Write, buff, 2))
                return(-1);
 
 /* Now update the checksum. This code only modifies the value. It does */
 /* not recalculate it */
-
+  
        buff[0] = RTC_ADDR_CHECKSUM;
        buff[1] = oldsum - oldvalue + value;
        if (iic_control(RTC_Write, buff, 2))
                return(-1);
-       
+      
        return(0);
 }
 
@@ -177,12 +178,11 @@
        u_char buff[8];
 
        buff[0] = 1;
-
-/*     buff[1] = dectohexdec(rtc->rtc_centi);
+       buff[1] = dectohexdec(rtc->rtc_centi);
        buff[2] = dectohexdec(rtc->rtc_sec);
        buff[3] = dectohexdec(rtc->rtc_min);
        buff[4] = dectohexdec(rtc->rtc_hour) & 0x3f;
-       buff[5] = dectohexdec(rtc->rtc_day);
+       buff[5] = dectohexdec(rtc->rtc_day) | ((rtc->rtc_year & 3) << 6);
        buff[6] = dectohexdec(rtc->rtc_mon);
 
        if (iic_control(RTC_Write, buff, 7))
@@ -192,8 +192,7 @@
                return(0);
        if (cmos_write(RTC_ADDR_CENT, rtc->rtc_cen))
                return(0);
-*/
-       printf("rtc_write: Currently disabled\n");
+
        return(1);
 }
 
@@ -215,7 +214,14 @@
 
        if (iic_control(RTC_Read, buff, 8))
                return(0);
-
+#ifdef RTC_VERBOSE
+       /* dump the RTC clock buffer */
+       printf("CMOS Read:");
+       for (byte = 1 ; byte <= 6 ; ++byte) {
+           printf(" %02x",buff[byte]);
+       }
+       printf("\n");
+#endif
        rtc->rtc_micro = 0;
        rtc->rtc_centi = hexdectodec(buff[1] & 0xff);
        rtc->rtc_sec   = hexdectodec(buff[2] & 0x7f);
-------------Cut Here------------------
>Release-Note:
>Audit-Trail:
>Unformatted: