ds1302: Move the rtc_read/write helpers to the common code
authorAlan Cox <alan@linux.intel.com>
Sat, 25 Aug 2018 18:19:42 +0000 (19:19 +0100)
committerAlan Cox <alan@linux.intel.com>
Sat, 25 Aug 2018 18:19:42 +0000 (19:19 +0100)
Kernel/dev/ds1302.c
Kernel/dev/ds1302.h
Kernel/platform-sbcv2/main.c

index 35c1813..e0adf3b 100644 (file)
@@ -9,6 +9,7 @@
 #include <kdata.h>
 #include <stdbool.h>
 #include <printf.h>
+#include <rtc.h>
 #include <ds1302.h>
 
 void ds1302_send_byte(uint8_t byte)
@@ -83,3 +84,51 @@ uint8_t platform_rtc_secs(void)
     ds1302_read_clock(&buffer, 1);   /* read out only the seconds value */
     return uint8_from_bcd(buffer & 0x7F); /* mask off top bit (clock-halt) */
 }
+
+static uint8_t rtc_buf[8];
+
+/* Full RTC support (for read - no write yet) */
+int platform_rtc_read(void)
+{
+       uint16_t len = sizeof(struct cmos_rtc);
+       uint16_t y;
+       struct cmos_rtc cmos;
+       uint8_t *p = cmos.data.bytes;
+
+       if (udata.u_count < len)
+               len = udata.u_count;
+
+       ds1302_read_clock(rtc_buf, 7);
+
+       y = rtc_buf[6];
+       if (y > 0x70)
+               y = 0x1900 | y;
+       else
+               y = 0x2000 | y;
+       *p++ = y >> 8;
+       *p++ = y;
+       rtc_buf[4]--;           /* 0 based */
+       if ((rtc_buf[4] & 0x0F) > 9)    /* Overflow case */
+               rtc_buf[4] -= 0x06;
+       *p++ = rtc_buf[4];      /* Month */
+       *p++ = rtc_buf[3];      /* Day of month */
+       if ((rtc_buf[2] & 0x90) == 0x90) {      /* 12hr mode, PM */
+               /* Add 12 BCD */
+               rtc_buf[2] += 0x12;
+               if ((rtc_buf[2] & 0x0F) > 9)    /* Overflow case */
+                       rtc_buf[2] += 0x06;
+       }
+       *p++ = rtc_buf[2];      /* Hour */
+       *p++ = rtc_buf[1];      /* Minute */
+       *p = rtc_buf[0];        /* Second */
+       cmos.type = CMOS_RTC_BCD;
+       if (uput(&cmos, udata.u_base, len) == -1)
+               return -1;
+       return len;
+}
+
+int platform_rtc_write(void)
+{
+       udata.u_error = -EOPNOTSUPP;
+       return -1;
+}
index 7227777..4315d9d 100644 (file)
@@ -5,6 +5,8 @@
 void ds1302_init(void);
 uint8_t platform_rtc_secs(void);
 void ds1302_read_clock(uint8_t *buffer, uint8_t length);
+int platform_rtc_read(void);
+int platform_rtc_write(void);
 
 #ifdef _DS1302_PRIVATE
 /* consult the DS1302 datasheet for data format;
index 2cae50c..f01f9cc 100644 (file)
@@ -52,52 +52,10 @@ void platform_discard(void)
        }
 }
 
-static uint8_t rtc_buf[8];
 
-int platform_rtc_read(void)
-{
-       uint16_t len = sizeof(struct cmos_rtc);
-       uint16_t y;
-       struct cmos_rtc cmos;
-       uint8_t *p = cmos.data.bytes;
-
-       if (udata.u_count < len)
-               len = udata.u_count;
-
-       ds1302_read_clock(rtc_buf, 7);
-
-       y = rtc_buf[6];
-       if (y > 0x70)
-               y = 0x1900 | y;
-       else
-               y = 0x2000 | y;
-       *p++ = y >> 8;
-       *p++ = y;
-       rtc_buf[4]--;           /* 0 based */
-       if ((rtc_buf[4] & 0x0F) > 9)    /* Overflow case */
-               rtc_buf[4] -= 0x06;
-       *p++ = rtc_buf[4];      /* Month */
-       *p++ = rtc_buf[3];      /* Day of month */
-       if ((rtc_buf[2] & 0x90) == 0x90) {      /* 12hr mode, PM */
-               /* Add 12 BCD */
-               rtc_buf[2] += 0x12;
-               if ((rtc_buf[2] & 0x0F) > 9)    /* Overflow case */
-                       rtc_buf[2] += 0x06;
-       }
-       *p++ = rtc_buf[2];      /* Hour */
-       *p++ = rtc_buf[1];      /* Minute */
-       *p = rtc_buf[0];        /* Second */
-       cmos.type = CMOS_RTC_BCD;
-       if (uput(&cmos, udata.u_base, len) == -1)
-               return -1;
-       return len;
-}
-
-int platform_rtc_write(void)
-{
-       udata.u_error = -EOPNOTSUPP;
-       return -1;
-}
+/*
+ *     Logic for tickless system. If you have an RTC you can ignore this.
+ */
 
 static uint8_t newticks = 0xFF;
 static uint8_t oldticks;