sam: rtc support now appears to be in working order
authorAlan Cox <alan@linux.intel.com>
Sat, 17 Nov 2018 13:21:19 +0000 (13:21 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 17 Nov 2018 13:21:19 +0000 (13:21 +0000)
Kernel/platform-sam/README
Kernel/platform-sam/config.h
Kernel/platform-sam/discard.c
Kernel/platform-sam/msm6242b.c
Kernel/platform-sam/msm6242b.h

index c1f6a12..c766dd9 100644 (file)
@@ -40,6 +40,7 @@ Stub code is in the low parts of the low banks and the top of the high banks
 so we have two copier routines one for each half.
 
        -       Control key debugging
+       -       Review and test signal handling paths more
        -       AtomIDE driver (prob need minimal copiers in high stubs)
        -       RTC driver
        -       Serial driver
@@ -69,7 +70,6 @@ Boot from the created floppy .mgt file
 Filesystem on Atomlite. If using simcoupe dd it 534 bytes into the image
 Select device 0 for boot to get atomlite (you can do partitions)
 
-
 DONE   -       Crashes on interrupt preempt (Fixed I hope)
 DONE   -       Fix signal handling crashes  ( ditto )
 DONE   -       Run out of pages - suggests child exit/bank32 isn't cleaning
index df1c54e..635314e 100644 (file)
@@ -1,4 +1,5 @@
 #define CONFIG_RTC
+#define CONFIG_RTC_FULL
 /* Enable to make ^Z dump the inode table for debug */
 #undef CONFIG_IDUMP
 /* Enable to make ^A drop back into the monitor */
index 7b26ec1..191d99e 100644 (file)
@@ -7,6 +7,9 @@
 #include <devatom.h>
 #include <msm6242b.h>
 
+/* FIXME */
+extern int strcmp(const char *, const char *);
+
 void map_init(void)
 {
 }
@@ -25,7 +28,10 @@ void pagemap_init(void)
 
 uint8_t platform_param(char *p)
 {
-       used(p);
+       if (strcmp(p, "rtc") == 0) {
+               samrtc = 1;
+               return 1;
+       }
        return 0;
 }
 
index 0b32f2e..9d7e68c 100644 (file)
@@ -4,11 +4,12 @@
 
 #include <kernel.h>
 #include <kdata.h>
+#include <printf.h>
 #include <rtc.h>
 #include <msm6242b.h>
 
 static uint8_t rtc_buf[6];
-static uint8_t samrtc = 0;
+uint8_t samrtc;
 
 uint8_t platform_rtc_secs(void)
 {
@@ -19,7 +20,7 @@ uint8_t platform_rtc_secs(void)
     
     do {
         r = samrtc_in(0);
-        v = samrtc_in(1);
+        v = samrtc_in(0x10);
     } while (r != samrtc_in(0));
     
     return v * 10 + r;
@@ -30,9 +31,9 @@ static void read_clock_once(void)
     uint8_t *p = rtc_buf;
     uint8_t n = 0;
     
-    while(n < 12) {
-        *p++ = samrtc_in(n) | (samrtc_in(n + 1) << 4);
-        n += 2;
+    while(n < 0xC0) {
+        *p++ = samrtc_in(n) | (samrtc_in(n + 0x10) << 4);
+        n += 0x20;
     }
 }
 
@@ -54,6 +55,7 @@ int platform_rtc_read(void)
        uint8_t *p = cmos.data.bytes;
 
        if (!samrtc) {
+           kputs("nortc\n");
            udata.u_error = -EOPNOTSUPP;
            return -1;
         }
@@ -63,16 +65,11 @@ int platform_rtc_read(void)
         read_clock();
 
        y = rtc_buf[5];
-       /* 1980 based year , if its 0x20 or more we are in 2000-2079 and
-          need to adjust the clock up by 2000 and back by 10. If not well
-          then its 1980-1999 so just needs 0x1980 adding to the 0-9 we have */
-       if (y >= 0x20)
-           y += 0x19F0;
-        else
-            y += 0x1980;
-       *p++ = y >> 8;
+       /* Year is the low 2 digits. We work on the basis that it's past
+          2000 now so just assume 20xx */
+       *p++ = 0x20;
        *p++ = y;
-       *p++ = rtc_buf[4];      /* month */
+       *p++ = rtc_buf[4] - 1;  /* month (convert from 1 based) */
        *p++ = rtc_buf[3];      /* day */
        *p++ = rtc_buf[2];      /* Hour */
        *p++ = rtc_buf[1];      /* Minute */
@@ -94,20 +91,23 @@ uint8_t platform_rtc_probe(void)
 {
         uint8_t r;
 
+        if (samrtc)
+            return 1;
+
         for (r = 0; r < 12; r++) {
             if (samrtc_in(r) > 9)
                 return 0;
         }
         
         /* Now play with 24 hour mode */
-        r = samrtc_in(15);
+        r = samrtc_in(0xF0);
         r &= ~4;
-        samrtc_out(15 | (r << 8));
-        if (samrtc_in(15) != r)
+        samrtc_out(0xF0 | (r << 8));
+        if (samrtc_in(0xF0) != r)
             return 0;
         r |= 4;        /* 24 hour */
-        samrtc_out(15 | (r << 8));
-        if (samrtc_in(15) != r)
+        samrtc_out(0xF0 | (r << 8));
+        if (samrtc_in(0xF0) != r)
             return 0;
         /* Looks like we have a valid Sam RTC */
         samrtc = 1;
index 1a892f4..9ee1c90 100644 (file)
@@ -2,3 +2,5 @@ extern uint8_t samrtc_in(uint8_t reg) __z88dk_fastcall;
 extern void samrtc_out(uint16_t rv) __z88dk_fastcall;
 
 extern uint8_t platform_rtc_probe(void);
+
+extern uint8_t samrtc;