]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: rtc: Rename gregorian day function
authorSimon Glass <sjg@chromium.org>
Mon, 20 Apr 2015 18:37:17 +0000 (12:37 -0600)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 8 Sep 2015 20:37:13 +0000 (22:37 +0200)
Change this function name to something more descriptive. Also return a
failure code if it cannot calculate a correct value.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Heiko Schocher <hs@denx.de>
common/cmd_date.c
drivers/rtc/date.c
drivers/rtc/ds1306.c
include/rtc.h

index 4a653e5bcfab8e24c35608aa256c8c8161b2b291..dfb9349517325f0bd2525cd4607ee65955096f77 100644 (file)
@@ -201,7 +201,7 @@ int mk_date (const char *datestr, struct rtc_time *tmp)
                tmp->tm_min  = val;
 
                /* calculate day of week */
-               GregorianDay (tmp);
+               rtc_calc_weekday(tmp);
 
                return (0);
        default:
index 15e6db06b2d4fd03c617de8a82ba3a6346b7052d..20005657360765e7e3c92a041ce25a0faef403e7 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <errno.h>
 #include <rtc.h>
 
 #if defined(CONFIG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
@@ -30,13 +31,15 @@ static int month_days[12] = {
 /*
  * This only works for the Gregorian calendar - i.e. after 1752 (in the UK)
  */
-void GregorianDay(struct rtc_time * tm)
+int rtc_calc_weekday(struct rtc_time *tm)
 {
        int leapsToDate;
        int lastYear;
        int day;
        int MonthOffset[] = { 0,31,59,90,120,151,181,212,243,273,304,334 };
 
+       if (tm->tm_year < 1753)
+               return -EINVAL;
        lastYear=tm->tm_year-1;
 
        /*
@@ -64,6 +67,8 @@ void GregorianDay(struct rtc_time * tm)
        day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + tm->tm_mday;
 
        tm->tm_wday=day%7;
+
+       return 0;
 }
 
 void to_tm(int tim, struct rtc_time * tm)
@@ -101,7 +106,7 @@ void to_tm(int tim, struct rtc_time * tm)
        /*
         * Determine the day of week
         */
-       GregorianDay(tm);
+       rtc_calc_weekday(tm);
 }
 
 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
index 1ec1837cb4e1e79405d6ba7357d8fc0b51f307f0..3fe6721c13617517344fcb56afcdc18c63343935 100644 (file)
@@ -110,7 +110,7 @@ int rtc_get (struct rtc_time *tmp)
        immap->im_cpm.cp_pbdat &= ~PB_SPI_CE;   /* Disable DS1306 Chip */
        udelay (10);
 
-       GregorianDay (tmp);     /* Determine the day of week */
+       rtc_calc_weekday(tmp);  /* Determine the day of week */
 
        debug ("Get DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
               tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
index 54e361ea5e83ee28593dddd8178a361b5e1b53f2..96c696ad65b6a79eceb6bc8ea04639d225e355ad 100644 (file)
@@ -45,7 +45,6 @@ int rtc_get (struct rtc_time *);
 int rtc_set (struct rtc_time *);
 void rtc_reset (void);
 
-void GregorianDay (struct rtc_time *);
 void to_tm (int, struct rtc_time *);
 unsigned long mktime (unsigned int, unsigned int, unsigned int,
                      unsigned int, unsigned int, unsigned int);
@@ -87,4 +86,15 @@ void rtc_write32(int reg, u32 value);
  */
 void rtc_init(void);
 
+/**
+ * rtc_calc_weekday() - Work out the weekday from a time
+ *
+ * This only works for the Gregorian calendar - i.e. after 1752 (in the UK).
+ * It sets time->tm_wdaay to the correct day of the week.
+ *
+ * @time:      Time to inspect. tm_wday is updated
+ * @return 0 if OK, -EINVAL if the weekday could not be determined
+ */
+int rtc_calc_weekday(struct rtc_time *time);
+
 #endif /* _RTC_H_ */