]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
rtc: mc146818: Set up RTC at start of day
authorSimon Glass <sjg@chromium.org>
Sat, 15 Nov 2014 01:18:26 +0000 (18:18 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 25 Nov 2014 13:33:59 +0000 (06:33 -0700)
Provide a function to set up the RTC ready for use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
drivers/rtc/bfin_rtc.c
drivers/rtc/mc146818.c
include/rtc.h

index 21a2189e2753b8d2fffceecc41a5e3c2b4c780e6..4cf2d834b219683c1839a4d51a79f5b71641657b 100644 (file)
@@ -27,7 +27,7 @@
 #define NUM_SECS_IN_DAY   DAYS_TO_SECS(1)
 
 /* Enable the RTC prescaler enable register */
-static void rtc_init(void)
+void rtc_init(void)
 {
        if (!(bfin_read_RTC_PREN() & 0x1))
                bfin_write_RTC_PREN(0x1);
index f7cf1064f9052de9b2e56fcc7de3d53544826efa..39e6041be365ccdb9089d21ee302c9de76d429cf 100644 (file)
@@ -14,6 +14,7 @@
 #include <common.h>
 #include <command.h>
 #include <rtc.h>
+#include <version.h>
 
 #if defined(__I386__) || defined(CONFIG_MALTA)
 #include <asm/io.h>
@@ -23,6 +24,9 @@
 
 #if defined(CONFIG_CMD_DATE)
 
+/* Set this to 1 to clear the CMOS RAM */
+#define CLEAR_CMOS 0
+
 static uchar rtc_read  (uchar reg);
 static void  rtc_write (uchar reg, uchar val);
 
@@ -41,7 +45,14 @@ static void  rtc_write (uchar reg, uchar val);
 #define RTC_CONFIG_B           0x0B
 #define RTC_CONFIG_C           0x0C
 #define RTC_CONFIG_D           0x0D
+#define RTC_REG_SIZE           0x80
+
+#define RTC_CONFIG_A_REF_CLCK_32KHZ    (1 << 5)
+#define RTC_CONFIG_A_RATE_1024HZ       6
 
+#define RTC_CONFIG_B_24H               (1 << 1)
+
+#define RTC_CONFIG_D_VALID_RAM_AND_TIME        0x80
 
 /* ------------------------------------------------------------------------- */
 
@@ -128,25 +139,49 @@ void rtc_reset (void)
  */
 static uchar rtc_read (uchar reg)
 {
-       return(in8(CONFIG_SYS_RTC_REG_BASE_ADDR+reg));
+       return in8(CONFIG_SYS_RTC_REG_BASE_ADDR + reg);
 }
 
 static void rtc_write (uchar reg, uchar val)
 {
-       out8(CONFIG_SYS_RTC_REG_BASE_ADDR+reg, val);
+       out8(CONFIG_SYS_RTC_REG_BASE_ADDR + reg, val);
 }
 #else
 static uchar rtc_read (uchar reg)
 {
        out8(RTC_PORT_MC146818,reg);
-       return(in8(RTC_PORT_MC146818+1));
+       return in8(RTC_PORT_MC146818 + 1);
 }
 
 static void rtc_write (uchar reg, uchar val)
 {
        out8(RTC_PORT_MC146818,reg);
-       out8(RTC_PORT_MC146818+1,val);
+       out8(RTC_PORT_MC146818+1, val);
 }
 #endif
 
+void rtc_init(void)
+{
+#if CLEAR_CMOS
+       int i;
+
+       rtc_write(RTC_SECONDS_ALARM, 0);
+       rtc_write(RTC_MINUTES_ALARM, 0);
+       rtc_write(RTC_HOURS_ALARM, 0);
+       for (i = RTC_CONFIG_A; i < RTC_REG_SIZE; i++)
+               rtc_write(i, 0);
+       printf("RTC: zeroing CMOS RAM\n");
+#endif
+
+       /* Setup the real time clock */
+       rtc_write(RTC_CONFIG_B, RTC_CONFIG_B_24H);
+       /* Setup the frequency it operates at */
+       rtc_write(RTC_CONFIG_A, RTC_CONFIG_A_REF_CLCK_32KHZ |
+                 RTC_CONFIG_A_RATE_1024HZ);
+       /* Ensure all reserved bits are 0 in register D */
+       rtc_write(RTC_CONFIG_D, RTC_CONFIG_D_VALID_RAM_AND_TIME);
+
+       /* Clear any pending interrupts */
+       rtc_read(RTC_CONFIG_C);
+}
 #endif
index c0349668bccb805f01bc1c8096ed1491b27f9599..d11aa8baf91b7370bf40a18f5785522448933386 100644 (file)
@@ -50,4 +50,9 @@ void to_tm (int, struct rtc_time *);
 unsigned long mktime (unsigned int, unsigned int, unsigned int,
                      unsigned int, unsigned int, unsigned int);
 
+/**
+ * rtc_init() - Set up the real time clock ready for use
+ */
+void rtc_init(void);
+
 #endif /* _RTC_H_ */