]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dm: rtc: Rename to_tm() to rtc_to_tm() and add error code
authorSimon Glass <sjg@chromium.org>
Mon, 20 Apr 2015 18:37:18 +0000 (12:37 -0600)
committerSimon Glass <sjg@chromium.org>
Wed, 6 May 2015 02:58:20 +0000 (20:58 -0600)
Rename this function so that it is clear that it is provided by the RTC.
Also return an error when it cannot function as expected. This is unlikely
to occur since it works for dates since 1752 and many RTCs do not support
such old dates. Still it is better to be accurate.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Heiko Schocher <hs@denx.de>
16 files changed:
common/image.c
drivers/rtc/at91sam9_rtt.c
drivers/rtc/bfin_rtc.c
drivers/rtc/date.c
drivers/rtc/ds1374.c
drivers/rtc/ftrtc010.c
drivers/rtc/imxdi.c
drivers/rtc/mc13xxx-rtc.c
drivers/rtc/mcfrtc.c
drivers/rtc/mpc8xx.c
drivers/rtc/mx27rtc.c
drivers/rtc/mxsrtc.c
drivers/rtc/pl031.c
include/rtc.h
net/sntp.c
post/drivers/rtc.c

index abc0d890f289d622503f7e028ade7a48dc55478c..fdec496c4bf0e936f26e8876f621d9103c19595c 100644 (file)
@@ -533,7 +533,7 @@ void genimg_print_time(time_t timestamp)
 #ifndef USE_HOSTCC
        struct rtc_time tm;
 
-       to_tm(timestamp, &tm);
+       rtc_to_tm(timestamp, &tm);
        printf("%4d-%02d-%02d  %2d:%02d:%02d UTC\n",
                        tm.tm_year, tm.tm_mon, tm.tm_mday,
                        tm.tm_hour, tm.tm_min, tm.tm_sec);
index 714dd2a34f53268687db5b534febe16d3356e6e8..d3cdee04ffc736c42d5580e19e793b3e0c22f775 100644 (file)
@@ -44,7 +44,7 @@ int rtc_get (struct rtc_time *tmp)
        } while (tim!=tim2);
        off = readl(&gpbr->reg[AT91_GPBR_INDEX_TIMEOFF]);
        /* off==0 means time is invalid, but we ignore that */
-       to_tm (tim+off, tmp);
+       rtc_to_tm(tim+off, tmp);
        return 0;
 }
 
index 4cf2d834b219683c1839a4d51a79f5b71641657b..6cb1ebac74c09996fc78f7a1d15349285402f69d 100644 (file)
@@ -114,7 +114,7 @@ int rtc_get(struct rtc_time *tmp)
 
        /* Calculate the total number of seconds since epoch */
        time_in_sec = (tm_sec) + MIN_TO_SECS(tm_min) + HRS_TO_SECS(tm_hr) + DAYS_TO_SECS(tm_day);
-       to_tm(time_in_sec, tmp);
+       rtc_to_tm(time_in_sec, tmp);
 
        return 0;
 }
index 20005657360765e7e3c92a041ce25a0faef403e7..79beb940e5c5a193aff68c9fa0d42863c82a9b2b 100644 (file)
@@ -71,7 +71,7 @@ int rtc_calc_weekday(struct rtc_time *tm)
        return 0;
 }
 
-void to_tm(int tim, struct rtc_time * tm)
+int rtc_to_tm(int tim, struct rtc_time *tm)
 {
        register int    i;
        register long   hms, day;
@@ -103,10 +103,14 @@ void to_tm(int tim, struct rtc_time * tm)
        /* Days are what is left over (+1) from all that. */
        tm->tm_mday = day + 1;
 
+       /* Zero unused fields */
+       tm->tm_yday = 0;
+       tm->tm_isdst = 0;
+
        /*
         * Determine the day of week
         */
-       rtc_calc_weekday(tm);
+       return rtc_calc_weekday(tm);
 }
 
 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
index 427b1eb8d0a5f82541e99578d00e7a48c7a009c6..04793b54be67f67554fb3ae51c8bb34e0e38dd43 100644 (file)
@@ -118,7 +118,7 @@ int rtc_get (struct rtc_time *tm){
 
        DEBUGR ("Get RTC s since 1.1.1970: %ld\n", time1);
 
-       to_tm(time1, tm); /* To Gregorian Date */
+       rtc_to_tm(time1, tm); /* To Gregorian Date */
 
        if (rtc_read(RTC_SR_ADDR) & RTC_SR_BIT_OSF) {
                printf ("### Warning: RTC oscillator has stopped\n");
index 713dad274f1cb5e938e613d72b5118864b2a66f3..3c5d95594390eef7b20526c03d069ec1f45aa375 100644 (file)
@@ -86,7 +86,7 @@ int rtc_get(struct rtc_time *tmp)
        now = ftrtc010_time() + readl(&rtc->record);
 #endif
 
-       to_tm(now, tmp);
+       rtc_to_tm(now, tmp);
 
        return 0;
 }
index 0d7d736eff510970183b7af84f2aacb54098bcb7..e89034dc0a80c5b7b35ccb47f1c24c5236e9fd81 100644 (file)
@@ -192,7 +192,7 @@ int rtc_get(struct rtc_time *tmp)
        }
 
        now = __raw_readl(&data.regs->dtcmr);
-       to_tm(now, tmp);
+       rtc_to_tm(now, tmp);
 
 err:
        return rc;
index 528247ac86e09399dc1ad7f9ddf10cded566edd9..30c4e662dd7652d534048a8ae793ab209cb850dc 100644 (file)
@@ -36,7 +36,7 @@ int rtc_get(struct rtc_time *rtc)
 
        tim = day1 * 86400 + time;
 
-       to_tm(tim, rtc);
+       rtc_to_tm(tim, rtc);
 
        rtc->tm_yday = 0;
        rtc->tm_isdst = 0;
index 8961ca4f8b6708fcf6989bf2561f1f10a11bbf83..e02e29793e03a85b2734a7b359aaa32a6c2a8b3d 100644 (file)
@@ -38,7 +38,7 @@ int rtc_get(struct rtc_time *tmp)
        tim = (tim * 60) + rtc_mins;
        tim = (tim * 60) + rtc->seconds;
 
-       to_tm(tim, tmp);
+       rtc_to_tm(tim, tmp);
 
        tmp->tm_yday = 0;
        tmp->tm_isdst = 0;
index d239daee1b08db54fa5297293d381b9e46643746..796295d5b0e0640e5d9f0549d82907a62fea7591 100644 (file)
@@ -26,7 +26,7 @@ int rtc_get (struct rtc_time *tmp)
 
        tim = immr->im_sit.sit_rtc;
 
-       to_tm (tim, tmp);
+       rtc_to_tm(tim, tmp);
 
        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 ae6595b86037744f2153051410c6d4c215132add..7ba74d3b110436d154499b2bb89ed7b42f025170 100644 (file)
@@ -30,7 +30,7 @@ int rtc_get(struct rtc_time *time)
 
        sec += min * 60 + hour * 3600 + day * 24 * 3600;
 
-       to_tm(sec, time);
+       rtc_to_tm(sec, time);
 
        return 0;
 }
index 32ba8a3062ce07f1d2cb4db9af8dcd0ac2020e65..82c2fbfde04c7cc799254f34edb80d9b3dd2a6f9 100644 (file)
@@ -43,7 +43,7 @@ int rtc_get(struct rtc_time *time)
        uint32_t secs;
 
        secs = readl(&rtc_regs->hw_rtc_seconds);
-       to_tm(secs, time);
+       rtc_to_tm(secs, time);
 
        return 0;
 }
index c4d1259a898d2e885eea0d76a6f16ad1c07e7434..e6c1a6c27100e8c4904d8a6932bdd42c3d6a6a4e 100644 (file)
@@ -97,7 +97,7 @@ int rtc_get(struct rtc_time *tmp)
 
        tim = RTC_READ_REG(RTC_DR);
 
-       to_tm (tim, tmp);
+       rtc_to_tm(tim, tmp);
 
        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 96c696ad65b6a79eceb6bc8ea04639d225e355ad..4b7ce6108cfc3f726b4da10bd61d48634780349a 100644 (file)
@@ -45,7 +45,6 @@ int rtc_get (struct rtc_time *);
 int rtc_set (struct rtc_time *);
 void rtc_reset (void);
 
-void to_tm (int, struct rtc_time *);
 unsigned long mktime (unsigned int, unsigned int, unsigned int,
                      unsigned int, unsigned int, unsigned int);
 
@@ -97,4 +96,18 @@ void rtc_init(void);
  */
 int rtc_calc_weekday(struct rtc_time *time);
 
+/**
+ * rtc_to_tm() - Convert a time_t value into a broken-out time
+ *
+ * The following fields are set up by this function:
+ *     tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday
+ *
+ * Note that tm_yday and tm_isdst are set to 0.
+ *
+ * @time_t:    Number of seconds since 1970-01-01 00:00:00
+ * @time:      Place to put the broken-out time
+ * @return 0 if OK, -EINVAL if the weekday could not be determined
+ */
+int rtc_to_tm(int time_t, struct rtc_time *time);
+
 #endif /* _RTC_H_ */
index 6422eef72ef2b694177115a7634364b1fd05b34b..d7b9e5563a7da1fdbfc1d407995d27a3080ee5bf 100644 (file)
@@ -68,7 +68,7 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
         */
        memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
 
-       to_tm(ntohl(seconds) - 2208988800UL + net_ntp_time_offset, &tm);
+       rtc_to_tm(ntohl(seconds) - 2208988800UL + net_ntp_time_offset, &tm);
 #if defined(CONFIG_CMD_DATE)
        rtc_set(&tm);
 #endif
index cd19f7568df39984e982c190d767276ee0a859af..8d7a7884bc28dec6ec63d527ab1464b20a62c71d 100644 (file)
@@ -63,7 +63,7 @@ static void rtc_post_restore (struct rtc_time *tm, unsigned int sec)
                                           tm->tm_min, tm->tm_sec) + sec;
        struct rtc_time ntm;
 
-       to_tm (t, &ntm);
+       rtc_to_tm(t, &ntm);
 
        rtc_set (&ntm);
 }
@@ -119,7 +119,7 @@ int rtc_post_test (int flags)
                time_t t = mktime (ynl, i + 1, daysnl[i], 23, 59, 59);
                struct rtc_time tm;
 
-               to_tm (t, &tm);
+               rtc_to_tm(t, &tm);
                rtc_set (&tm);
 
                skipped++;
@@ -143,7 +143,7 @@ int rtc_post_test (int flags)
                time_t t = mktime (yl, i + 1, daysl[i], 23, 59, 59);
                struct rtc_time tm;
 
-               to_tm (t, &tm);
+               rtc_to_tm(t, &tm);
                rtc_set (&tm);
 
                skipped++;