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 06/20] dm: rtc: Rename gregorian day function
Date: Tue, 21 Apr 2015 07:13:03 +0200	[thread overview]
Message-ID: <5535DC5F.8060004@denx.de> (raw)
In-Reply-To: <1429555051-22335-7-git-send-email-sjg@chromium.org>

Hello Simon,

Am 20.04.2015 20:37, schrieb Simon Glass:
> 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>
> ---
>
>   common/cmd_date.c    |  2 +-
>   drivers/rtc/date.c   |  9 +++++++--
>   drivers/rtc/ds1306.c |  2 +-
>   include/rtc.h        | 12 +++++++++++-
>   4 files changed, 20 insertions(+), 5 deletions(-)

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

bye,
Heiko
>
> diff --git a/common/cmd_date.c b/common/cmd_date.c
> index e349166..3b7ac3e 100644
> --- a/common/cmd_date.c
> +++ b/common/cmd_date.c
> @@ -196,7 +196,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:
> diff --git a/drivers/rtc/date.c b/drivers/rtc/date.c
> index 15e6db0..2000565 100644
> --- a/drivers/rtc/date.c
> +++ b/drivers/rtc/date.c
> @@ -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.
> diff --git a/drivers/rtc/ds1306.c b/drivers/rtc/ds1306.c
> index 1ec1837..3fe6721 100644
> --- a/drivers/rtc/ds1306.c
> +++ b/drivers/rtc/ds1306.c
> @@ -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,
> diff --git a/include/rtc.h b/include/rtc.h
> index 54e361e..96c696a 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 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_ */
>

-- 
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:13 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 [this message]
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
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=5535DC5F.8060004@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