public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 08/20] dm: rtc: Rename mktime() and reduce the number of parameters
Date: Tue, 21 Apr 2015 07:17:14 +0200	[thread overview]
Message-ID: <5535DD5A.90900@denx.de> (raw)
In-Reply-To: <1429555051-22335-9-git-send-email-sjg@chromium.org>

Hello Simon,

Am 20.04.2015 20:37, schrieb Simon Glass:
> Most callers unpack the structure and pass each member. It seems better to
> pass the whole structure instead, as with the C library. Also add an rtc_
> prefix.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   drivers/rtc/at91sam9_rtt.c |  3 +--
>   drivers/rtc/bfin_rtc.c     |  3 +--
>   drivers/rtc/date.c         | 23 ++++++++++++-----------
>   drivers/rtc/ds1306.c       |  3 +--
>   drivers/rtc/ds1374.c       |  4 +---
>   drivers/rtc/ftrtc010.c     |  3 +--
>   drivers/rtc/imxdi.c        |  3 +--
>   drivers/rtc/mc13xxx-rtc.c  |  3 +--
>   drivers/rtc/mpc8xx.c       |  3 +--
>   drivers/rtc/mx27rtc.c      |  3 +--
>   drivers/rtc/mxsrtc.c       |  3 +--
>   drivers/rtc/pl031.c        |  3 +--
>   include/rtc.h              | 16 +++++++++++++---
>   post/drivers/rtc.c         | 22 ++++++++++++++++++----
>   14 files changed, 54 insertions(+), 41 deletions(-)

Acked-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
>
> diff --git a/drivers/rtc/at91sam9_rtt.c b/drivers/rtc/at91sam9_rtt.c
> index d3cdee0..a684ad6 100644
> --- a/drivers/rtc/at91sam9_rtt.c
> +++ b/drivers/rtc/at91sam9_rtt.c
> @@ -54,8 +54,7 @@ int rtc_set (struct rtc_time *tmp)
>   	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
>   	ulong tim;
>
> -	tim = mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
> -		      tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
> +	tim = rtc_mktime(tmp);
>
>   	/* clear alarm, set prescaler to 32768, clear counter */
>   	writel(32768+AT91_RTT_RTTRST, &rtt->mr);
> diff --git a/drivers/rtc/bfin_rtc.c b/drivers/rtc/bfin_rtc.c
> index 6cb1eba..a079a1d 100644
> --- a/drivers/rtc/bfin_rtc.c
> +++ b/drivers/rtc/bfin_rtc.c
> @@ -67,8 +67,7 @@ int rtc_set(struct rtc_time *tmp)
>   	wait_for_complete();
>
>   	/* Calculate number of seconds this incoming time represents */
> -	remain = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
> -			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
> +	remain = rtc_mktime(tmp);
>
>   	/* Figure out how many days since epoch */
>   	days = remain / NUM_SECS_IN_DAY;
> diff --git a/drivers/rtc/date.c b/drivers/rtc/date.c
> index 79beb94..8c643a0 100644
> --- a/drivers/rtc/date.c
> +++ b/drivers/rtc/date.c
> @@ -128,22 +128,23 @@ int rtc_to_tm(int tim, struct rtc_time *tm)
>    * machines were long is 32-bit! (However, as time_t is signed, we
>    * will already get problems at other places on 2038-01-19 03:14:08)
>    */
> -unsigned long
> -mktime (unsigned int year, unsigned int mon,
> -	unsigned int day, unsigned int hour,
> -	unsigned int min, unsigned int sec)
> +unsigned long rtc_mktime(const struct rtc_time *tm)
>   {
> -	if (0 >= (int) (mon -= 2)) {	/* 1..12 -> 11,12,1..10 */
> +	int mon = tm->tm_mon;
> +	int year = tm->tm_year;
> +	int days, hours;
> +
> +	mon -= 2;
> +	if (0 >= (int)mon) {	/* 1..12 -> 11,12,1..10 */
>   		mon += 12;		/* Puts Feb last since it has leap day */
>   		year -= 1;
>   	}
>
> -	return (((
> -		(unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
> -			year*365 - 719499
> -	    )*24 + hour /* now have hours */
> -	  )*60 + min /* now have minutes */
> -	)*60 + sec; /* finally seconds */
> +	days = (unsigned long)(year / 4 - year / 100 + year / 400 +
> +			367 * mon / 12 + tm->tm_mday) +
> +			year * 365 - 719499;
> +	hours = days * 24 + tm->tm_hour;
> +	return (hours * 60 + tm->tm_min) * 60 + tm->tm_sec;
>   }
>
>   #endif
> diff --git a/drivers/rtc/ds1306.c b/drivers/rtc/ds1306.c
> index 3fe6721..7dd3e19 100644
> --- a/drivers/rtc/ds1306.c
> +++ b/drivers/rtc/ds1306.c
> @@ -180,8 +180,7 @@ int rtc_set (struct rtc_time *tmp)
>   	{
>   		ulong tim;
>
> -		tim = mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
> -			      tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
> +		tim = rtc_mktime(tmp);
>
>   		immap->im_sitk.sitk_rtck = KAPWR_KEY;
>   		immap->im_sit.sit_rtc = tim;
> diff --git a/drivers/rtc/ds1374.c b/drivers/rtc/ds1374.c
> index 04793b5..7847357 100644
> --- a/drivers/rtc/ds1374.c
> +++ b/drivers/rtc/ds1374.c
> @@ -147,9 +147,7 @@ int rtc_set (struct rtc_time *tmp){
>   	if (tmp->tm_year < 1970 || tmp->tm_year > 2069)
>   		printf("WARNING: year should be between 1970 and 2069!\n");
>
> -	time = mktime(tmp->tm_year, tmp->tm_mon,
> -			tmp->tm_mday, tmp->tm_hour,
> -			tmp->tm_min, tmp->tm_sec);
> +	time = rtc_mktime(tmp);
>
>   	DEBUGR ("Set RTC s since 1.1.1970: %ld (0x%02lx)\n", time, time);
>
> diff --git a/drivers/rtc/ftrtc010.c b/drivers/rtc/ftrtc010.c
> index 3c5d955..7d0cfb3 100644
> --- a/drivers/rtc/ftrtc010.c
> +++ b/drivers/rtc/ftrtc010.c
> @@ -104,8 +104,7 @@ int rtc_set(struct rtc_time *tmp)
>   	      tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
>   	      tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
>
> -	new = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_hour,
> -		     tmp->tm_min, tmp->tm_sec);
> +	new = rtc_mktime(tmp);
>
>   	now = ftrtc010_time();
>
> diff --git a/drivers/rtc/imxdi.c b/drivers/rtc/imxdi.c
> index e89034d..17519ce 100644
> --- a/drivers/rtc/imxdi.c
> +++ b/drivers/rtc/imxdi.c
> @@ -209,8 +209,7 @@ int rtc_set(struct rtc_time *tmp)
>   			goto err;
>   	}
>
> -	now = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
> -		     tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
> +	now = rtc_mktime(tmp);
>   	/* zero the fractional part first */
>   	rc = DI_WRITE_WAIT(0, dtclr);
>   	if (rc == 0)
> diff --git a/drivers/rtc/mc13xxx-rtc.c b/drivers/rtc/mc13xxx-rtc.c
> index 30c4e66..3e46336 100644
> --- a/drivers/rtc/mc13xxx-rtc.c
> +++ b/drivers/rtc/mc13xxx-rtc.c
> @@ -51,8 +51,7 @@ int rtc_set(struct rtc_time *rtc)
>   	if (!p)
>   		return -1;
>
> -	time = mktime(rtc->tm_year, rtc->tm_mon, rtc->tm_mday,
> -		      rtc->tm_hour, rtc->tm_min, rtc->tm_sec);
> +	time = rtc_mktime(rtc);
>   	day = time / 86400;
>   	time %= 86400;
>
> diff --git a/drivers/rtc/mpc8xx.c b/drivers/rtc/mpc8xx.c
> index 796295d..147a225 100644
> --- a/drivers/rtc/mpc8xx.c
> +++ b/drivers/rtc/mpc8xx.c
> @@ -44,8 +44,7 @@ int rtc_set (struct rtc_time *tmp)
>   		tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
>   		tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
>
> -	tim = mktime (tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
> -		      tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
> +	tim = rtc_mktime(tmp);
>
>   	immr->im_sitk.sitk_rtck = KAPWR_KEY;
>   	immr->im_sit.sit_rtc = tim;
> diff --git a/drivers/rtc/mx27rtc.c b/drivers/rtc/mx27rtc.c
> index 7ba74d3..29ccdf1 100644
> --- a/drivers/rtc/mx27rtc.c
> +++ b/drivers/rtc/mx27rtc.c
> @@ -40,8 +40,7 @@ int rtc_set(struct rtc_time *time)
>   	struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
>   	uint32_t day, hour, min, sec;
>
> -	sec = mktime(time->tm_year, time->tm_mon, time->tm_mday,
> -		time->tm_hour, time->tm_min, time->tm_sec);
> +	sec = rtc_mktime(time);
>
>   	day  = sec / (24 * 3600);
>   	sec  = sec % (24 * 3600);
> diff --git a/drivers/rtc/mxsrtc.c b/drivers/rtc/mxsrtc.c
> index 82c2fbf..6e32154 100644
> --- a/drivers/rtc/mxsrtc.c
> +++ b/drivers/rtc/mxsrtc.c
> @@ -52,8 +52,7 @@ int rtc_set(struct rtc_time *time)
>   {
>   	uint32_t secs;
>
> -	secs = mktime(time->tm_year, time->tm_mon, time->tm_mday,
> -		time->tm_hour, time->tm_min, time->tm_sec);
> +	secs = rtc_mktime(time);
>
>   	return mxs_rtc_set_time(secs);
>   }
> diff --git a/drivers/rtc/pl031.c b/drivers/rtc/pl031.c
> index e6c1a6c..fc83049 100644
> --- a/drivers/rtc/pl031.c
> +++ b/drivers/rtc/pl031.c
> @@ -72,8 +72,7 @@ int rtc_set(struct rtc_time *tmp)
>   	}
>
>   	/* Calculate number of seconds this incoming time represents */
> -	tim = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
> -			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
> +	tim = rtc_mktime(tmp);
>
>   	RTC_WRITE_REG(RTC_LR, tim);
>
> diff --git a/include/rtc.h b/include/rtc.h
> index 4b7ce61..b1a4bf0 100644
> --- a/include/rtc.h
> +++ b/include/rtc.h
> @@ -45,9 +45,6 @@ int rtc_get (struct rtc_time *);
>   int rtc_set (struct rtc_time *);
>   void rtc_reset (void);
>
> -unsigned long mktime (unsigned int, unsigned int, unsigned int,
> -		      unsigned int, unsigned int, unsigned int);
> -
>   /**
>    * rtc_read8() - Read an 8-bit register
>    *
> @@ -110,4 +107,17 @@ int rtc_calc_weekday(struct rtc_time *time);
>    */
>   int rtc_to_tm(int time_t, struct rtc_time *time);
>
> +/**
> + * rtc_mktime() - Convert a broken-out time into a time_t value
> + *
> + * The following fields need to be valid for this function to work:
> + *	tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year
> + *
> + * Note that tm_wday and tm_yday are ignored.
> + *
> + * @time:	Broken-out time to convert
> + * @return corresponding time_t value, seconds since 1970-01-01 00:00:00
> + */
> +unsigned long rtc_mktime(const struct rtc_time *time);
> +
>   #endif	/* _RTC_H_ */
> diff --git a/post/drivers/rtc.c b/post/drivers/rtc.c
> index 8d7a788..c2e7391 100644
> --- a/post/drivers/rtc.c
> +++ b/post/drivers/rtc.c
> @@ -59,8 +59,7 @@ static int rtc_post_skip (ulong * diff)
>
>   static void rtc_post_restore (struct rtc_time *tm, unsigned int sec)
>   {
> -	time_t t = mktime (tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour,
> -					   tm->tm_min, tm->tm_sec) + sec;
> +	time_t t = rtc_mktime(tm) + sec;
>   	struct rtc_time ntm;
>
>   	rtc_to_tm(t, &ntm);
> @@ -116,9 +115,16 @@ int rtc_post_test (int flags)
>   	rtc_get (&svtm);
>
>   	for (i = 0; i < 12; i++) {
> -		time_t t = mktime (ynl, i + 1, daysnl[i], 23, 59, 59);
> +		time_t t;
>   		struct rtc_time tm;
>
> +		tm.tm_year = ynl;
> +		tm.tm_mon = i + 1;
> +		tm.tm_mday = daysnl[i];
> +		tm.tm_hour = 23;
> +		tm.tm_min = 59;
> +		tm.tm_sec = 59;
> +		t = rtc_mktime(&tm);
>   		rtc_to_tm(t, &tm);
>   		rtc_set (&tm);
>
> @@ -140,9 +146,17 @@ int rtc_post_test (int flags)
>   	}
>
>   	for (i = 0; i < 12; i++) {
> -		time_t t = mktime (yl, i + 1, daysl[i], 23, 59, 59);
> +		time_t t;
>   		struct rtc_time tm;
>
> +		tm.tm_year = yl;
> +		tm.tm_mon = i + 1;
> +		tm.tm_mday = daysl[i];
> +		tm.tm_hour = 23;
> +		tm.tm_min = 59;
> +		tm.tm_sec = 59;
> +		t = rtc_mktime(&tm);
> +
>   		rtc_to_tm(t, &tm);
>   		rtc_set (&tm);
>
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

  reply	other threads:[~2015-04-21  5:17 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
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 [this message]
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=5535DD5A.90900@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox