rtc: move RTC_RX8025 to Kconfig
[oweals/u-boot.git] / drivers / rtc / mc146818.c
index da804d54595f6fab83fd86396eb8ca59eef262f8..b98c39d8219cc4714ad47713c81a7fdd59fc8fb1 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2001
  * Denis Peter MPL AG Switzerland. d.peter@mpl.ch
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
 #include <dm.h>
 #include <rtc.h>
 
-#if defined(__I386__) || defined(CONFIG_MALTA)
+#if defined(CONFIG_X86) || defined(CONFIG_MALTA)
 #include <asm/io.h>
 #define in8(p) inb(p)
 #define out8(p, v) outb(v, p)
 #endif
 
-#if defined(CONFIG_CMD_DATE)
-
 /* Set this to 1 to clear the CMOS RAM */
 #define CLEAR_CMOS             0
 
@@ -84,7 +81,7 @@ static void mc146818_write8(int reg, uchar val)
 
 static int mc146818_get(struct rtc_time *tmp)
 {
-       uchar sec, min, hour, mday, wdaymon, year;
+       uchar sec, min, hour, mday, wday __attribute__((unused)),mon, year;
 
        /* here check if rtc can be accessed */
        while ((mc146818_read8(RTC_CONFIG_A) & 0x80) == 0x80)
@@ -100,7 +97,7 @@ static int mc146818_get(struct rtc_time *tmp)
 #ifdef RTC_DEBUG
        printf("Get RTC year: %02x mon/cent: %02x mday: %02x wday: %02x hr: %02x min: %02x sec: %02x\n",
               year, mon, mday, wday, hour, min, sec);
-       printf("Alarms: month: %02x hour: %02x min: %02x sec: %02x\n",
+       printf("Alarms: mday: %02x hour: %02x min: %02x sec: %02x\n",
               mc146818_read8(RTC_CONFIG_D) & 0x3f,
               mc146818_read8(RTC_HOURS_ALARM),
               mc146818_read8(RTC_MINUTES_ALARM),
@@ -112,7 +109,6 @@ static int mc146818_get(struct rtc_time *tmp)
        tmp->tm_mday = bcd2bin(mday & 0x3f);
        tmp->tm_mon  = bcd2bin(mon & 0x1f);
        tmp->tm_year = bcd2bin(year);
-       tmp->tm_wday = bcd2bin(wday & 0x07);
 
        if (tmp->tm_year < 70)
                tmp->tm_year += 2000;
@@ -121,6 +117,11 @@ static int mc146818_get(struct rtc_time *tmp)
 
        tmp->tm_yday = 0;
        tmp->tm_isdst = 0;
+       /*
+        * The mc146818 only updates wday if it is non-zero, sunday is 1
+        * saturday is 7. So let's use our library routine.
+        */
+       rtc_calc_weekday(tmp);
 #ifdef RTC_DEBUG
        printf("Get DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
               tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
@@ -142,7 +143,8 @@ static int mc146818_set(struct rtc_time *tmp)
 
        mc146818_write8(RTC_YEAR, bin2bcd(tmp->tm_year % 100));
        mc146818_write8(RTC_MONTH, bin2bcd(tmp->tm_mon));
-       mc146818_write8(RTC_DAY_OF_WEEK, bin2bcd(tmp->tm_wday));
+       /* Sunday = 1, Saturday = 7 */
+       mc146818_write8(RTC_DAY_OF_WEEK, bin2bcd(tmp->tm_wday + 1));
        mc146818_write8(RTC_DATE_OF_MONTH, bin2bcd(tmp->tm_mday));
        mc146818_write8(RTC_HOURS, bin2bcd(tmp->tm_hour));
        mc146818_write8(RTC_MINUTES, bin2bcd(tmp->tm_min));
@@ -192,7 +194,6 @@ static void mc146818_init(void)
        /* Clear any pending interrupts */
        mc146818_read8(RTC_CONFIG_C);
 }
-#endif /* CONFIG_CMD_DATE */
 
 #ifdef CONFIG_DM_RTC