From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 07/20] dm: rtc: Rename to_tm() to rtc_to_tm() and add error code
Date: Tue, 21 Apr 2015 07:16:33 +0200 [thread overview]
Message-ID: <5535DD31.8050507@denx.de> (raw)
In-Reply-To: <1429555051-22335-8-git-send-email-sjg@chromium.org>
Hello Simon,
Am 20.04.2015 20:37, schrieb Simon Glass:
> 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>
> ---
>
> common/image.c | 2 +-
> drivers/rtc/at91sam9_rtt.c | 2 +-
> drivers/rtc/bfin_rtc.c | 2 +-
> drivers/rtc/date.c | 8 ++++++--
> drivers/rtc/ds1374.c | 2 +-
> drivers/rtc/ftrtc010.c | 2 +-
> drivers/rtc/imxdi.c | 2 +-
> drivers/rtc/mc13xxx-rtc.c | 2 +-
> drivers/rtc/mcfrtc.c | 2 +-
> drivers/rtc/mpc8xx.c | 2 +-
> drivers/rtc/mx27rtc.c | 2 +-
> drivers/rtc/mxsrtc.c | 2 +-
> drivers/rtc/pl031.c | 2 +-
> include/rtc.h | 15 ++++++++++++++-
> net/sntp.c | 2 +-
> post/drivers/rtc.c | 6 +++---
> 16 files changed, 36 insertions(+), 19 deletions(-)
Thanks!
Acked-by: Heiko Schocher <hs@denx.de>
bye,
Heiko
> diff --git a/common/image.c b/common/image.c
> index abc0d89..fdec496 100644
> --- a/common/image.c
> +++ b/common/image.c
> @@ -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);
> diff --git a/drivers/rtc/at91sam9_rtt.c b/drivers/rtc/at91sam9_rtt.c
> index 714dd2a..d3cdee0 100644
> --- a/drivers/rtc/at91sam9_rtt.c
> +++ b/drivers/rtc/at91sam9_rtt.c
> @@ -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;
> }
>
> diff --git a/drivers/rtc/bfin_rtc.c b/drivers/rtc/bfin_rtc.c
> index 4cf2d83..6cb1eba 100644
> --- a/drivers/rtc/bfin_rtc.c
> +++ b/drivers/rtc/bfin_rtc.c
> @@ -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;
> }
> diff --git a/drivers/rtc/date.c b/drivers/rtc/date.c
> index 2000565..79beb94 100644
> --- a/drivers/rtc/date.c
> +++ b/drivers/rtc/date.c
> @@ -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.
> diff --git a/drivers/rtc/ds1374.c b/drivers/rtc/ds1374.c
> index 427b1eb..04793b5 100644
> --- a/drivers/rtc/ds1374.c
> +++ b/drivers/rtc/ds1374.c
> @@ -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");
> diff --git a/drivers/rtc/ftrtc010.c b/drivers/rtc/ftrtc010.c
> index 713dad2..3c5d955 100644
> --- a/drivers/rtc/ftrtc010.c
> +++ b/drivers/rtc/ftrtc010.c
> @@ -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;
> }
> diff --git a/drivers/rtc/imxdi.c b/drivers/rtc/imxdi.c
> index 0d7d736..e89034d 100644
> --- a/drivers/rtc/imxdi.c
> +++ b/drivers/rtc/imxdi.c
> @@ -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;
> diff --git a/drivers/rtc/mc13xxx-rtc.c b/drivers/rtc/mc13xxx-rtc.c
> index 528247a..30c4e66 100644
> --- a/drivers/rtc/mc13xxx-rtc.c
> +++ b/drivers/rtc/mc13xxx-rtc.c
> @@ -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;
> diff --git a/drivers/rtc/mcfrtc.c b/drivers/rtc/mcfrtc.c
> index 8961ca4..e02e297 100644
> --- a/drivers/rtc/mcfrtc.c
> +++ b/drivers/rtc/mcfrtc.c
> @@ -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;
> diff --git a/drivers/rtc/mpc8xx.c b/drivers/rtc/mpc8xx.c
> index d239dae..796295d 100644
> --- a/drivers/rtc/mpc8xx.c
> +++ b/drivers/rtc/mpc8xx.c
> @@ -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,
> diff --git a/drivers/rtc/mx27rtc.c b/drivers/rtc/mx27rtc.c
> index ae6595b..7ba74d3 100644
> --- a/drivers/rtc/mx27rtc.c
> +++ b/drivers/rtc/mx27rtc.c
> @@ -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;
> }
> diff --git a/drivers/rtc/mxsrtc.c b/drivers/rtc/mxsrtc.c
> index 32ba8a3..82c2fbf 100644
> --- a/drivers/rtc/mxsrtc.c
> +++ b/drivers/rtc/mxsrtc.c
> @@ -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;
> }
> diff --git a/drivers/rtc/pl031.c b/drivers/rtc/pl031.c
> index c4d1259..e6c1a6c 100644
> --- a/drivers/rtc/pl031.c
> +++ b/drivers/rtc/pl031.c
> @@ -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,
> diff --git a/include/rtc.h b/include/rtc.h
> index 96c696a..4b7ce61 100644
> --- a/include/rtc.h
> +++ b/include/rtc.h
> @@ -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_ */
> diff --git a/net/sntp.c b/net/sntp.c
> index 6422eef..d7b9e55 100644
> --- a/net/sntp.c
> +++ b/net/sntp.c
> @@ -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
> diff --git a/post/drivers/rtc.c b/post/drivers/rtc.c
> index cd19f75..8d7a788 100644
> --- a/post/drivers/rtc.c
> +++ b/post/drivers/rtc.c
> @@ -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++;
>
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
next prev parent reply other threads:[~2015-04-21 5:16 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-20 18:37 [U-Boot] [PATCH 00/20] dm: rtc: Add driver model support for real-time clocks Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 01/20] dm: spi: Correct the comment on spi_get_ops() Simon Glass
2015-04-22 11:39 ` Jagan Teki
2015-05-04 14:17 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 02/20] dm: i2c: sandbox: Add debugging to the speed limit Simon Glass
2015-04-21 5:04 ` Heiko Schocher
2015-04-23 15:12 ` Simon Glass
2015-04-24 5:14 ` Heiko Schocher
2015-05-04 14:19 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 03/20] dm: i2c: Add functions to read and write a register Simon Glass
2015-04-21 5:05 ` Heiko Schocher
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 04/20] dm: i2c: Add an explicit test mode to the sandbox I2C driver Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 05/20] fdt: Correct warning in fdt_setup_simplefb_node() Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 06/20] dm: rtc: Rename gregorian day function Simon Glass
2015-04-21 5:13 ` Heiko Schocher
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 07/20] dm: rtc: Rename to_tm() to rtc_to_tm() and add error code Simon Glass
2015-04-21 5:16 ` Heiko Schocher [this message]
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 08/20] dm: rtc: Rename mktime() and reduce the number of parameters Simon Glass
2015-04-21 5:17 ` Heiko Schocher
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 09/20] dm: Remove unnecessary types in bcd.h Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 10/20] dm: rtc: Split structure definition into its own file Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 11/20] dm: sandbox: Add os_localtime() to obtain the system time Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 12/20] dm: rtc: Add a uclass for real-time clocks Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 13/20] dm: rtc: sandbox: Add an emulated I2C RTC device Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 14/20] dm: rtc: sandbox: Add a driver for the sandbox I2C RTC Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 15/20] dm: rtc: Convert 'date' command to support driver model Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 16/20] dm: net: rtc: Support using driver model for rtc in sntp Simon Glass
2015-04-20 18:43 ` Joe Hershberger
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 17/20] dm: sandbox: dts: Add a real-time clock attached to I2C Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 18/20] dm: rtc: sandbox: Enable real-time clock support Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 19/20] dm: test: dts: Sort the aliases in the test device tree file Simon Glass
2015-04-21 15:32 ` Joe Hershberger
2015-05-04 14:20 ` Simon Glass
2015-04-20 18:37 ` [U-Boot] [PATCH 20/20] dm: rtc: Add tests for real-time clocks Simon Glass
2015-05-04 14:20 ` Simon Glass
2015-04-29 2:43 ` [U-Boot] [PATCH 00/20] dm: rtc: Add driver model support " Simon Glass
2015-04-29 7:09 ` Albert ARIBAUD
2015-05-03 17:21 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5535DD31.8050507@denx.de \
--to=hs@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.