From: Soeren Moch <smoch@web.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] rtc: ds1307: add support for MCP7941x RTCs
Date: Thu, 15 Jan 2015 14:25:28 +0100 [thread overview]
Message-ID: <54B7BFC8.3080201@web.de> (raw)
In-Reply-To: <1417084328-3404-1-git-send-email-smoch@web.de>
> MCP7941x RTCs are very similar to ds1307. So add support in the ds1307 driver,
> as it is done in the linux kernel
>
> Signed-off-by: Soeren Moch <smoch@web.de>
> ---
> Cc: Tom Rini <trini@ti.com>
Tom,
since the merge window is open now, can you pick up this patch?
Or do you think this should go through some other tree?
Thanks,
Soeren
> ---
> drivers/rtc/ds1307.c | 30 ++++++++++++++++++++++++------
> 1 file changed, 24 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/rtc/ds1307.c b/drivers/rtc/ds1307.c
> index 03ab1a8..20da43a 100644
> --- a/drivers/rtc/ds1307.c
> +++ b/drivers/rtc/ds1307.c
> @@ -10,6 +10,10 @@
> /*
> * Date & Time support (no alarms) for Dallas Semiconductor (now Maxim)
> * DS1307 and DS1338/9 Real Time Clock (RTC).
> + * i2c address 0x68
> + *
> + * Date & Time support (no alarms) for MCP7941x Real Time Clock (RTC).
> + * i2c address 0x6f
> *
> * based on ds1337.c
> */
> @@ -52,12 +56,24 @@
> #define RTC_CTL_REG_ADDR 0x07
>
> #define RTC_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */
> +#define RTC_SEC_CH 0x80 /* Clock Halt (in Register 0) */
> +
> +#define RTC_DAY_VBATEN 0x00 /* Battery EN (in Register 3) */
>
> #define RTC_CTL_BIT_RS0 0x01 /* Rate select 0 */
> #define RTC_CTL_BIT_RS1 0x02 /* Rate select 1 */
> #define RTC_CTL_BIT_SQWE 0x10 /* Square Wave Enable */
> #define RTC_CTL_BIT_OUT 0x80 /* Output Control */
>
> +#if CONFIG_SYS_I2C_RTC_ADDR == 0x6f
> +#undef RTC_SEC_CH
> +#undef RTC_DAY_VBATEN
> +#undef RTC_CTL_BIT_SQWE
> +#define RTC_SEC_CH 0x00 /* Clock Halt (in Register 0) */
> +#define RTC_DAY_VBATEN 0x08 /* Battery EN (in Register 3) */
> +#define RTC_CTL_BIT_SQWE 0x40 /* Square Wave Enable */
> +#endif
> +
> static uchar rtc_read (uchar reg);
> static void rtc_write (uchar reg, uchar val);
>
> @@ -81,11 +97,11 @@ int rtc_get (struct rtc_time *tmp)
> "hr: %02x min: %02x sec: %02x\n",
> year, mon, mday, wday, hour, min, sec);
>
> - if (sec & RTC_SEC_BIT_CH) {
> + if ((sec & RTC_SEC_BIT_CH) == RTC_SEC_CH) {
> printf ("### Warning: RTC oscillator has stopped\n");
> - /* clear the CH flag */
> + /* start clock */
> rtc_write (RTC_SEC_REG_ADDR,
> - rtc_read (RTC_SEC_REG_ADDR) & ~RTC_SEC_BIT_CH);
> + rtc_read (RTC_SEC_REG_ADDR) ^ RTC_SEC_BIT_CH);
> rel = -1;
> }
>
> @@ -112,6 +128,9 @@ int rtc_get (struct rtc_time *tmp)
> */
> int rtc_set (struct rtc_time *tmp)
> {
> + uchar clk_en = RTC_SEC_BIT_CH & ~RTC_SEC_CH;
> + uchar bat_en = RTC_DAY_VBATEN;
> +
> DEBUGR ("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
> tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
> tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
> @@ -121,11 +140,11 @@ int rtc_set (struct rtc_time *tmp)
>
> rtc_write (RTC_YR_REG_ADDR, bin2bcd (tmp->tm_year % 100));
> rtc_write (RTC_MON_REG_ADDR, bin2bcd (tmp->tm_mon));
> - rtc_write (RTC_DAY_REG_ADDR, bin2bcd (tmp->tm_wday + 1));
> + rtc_write (RTC_DAY_REG_ADDR, bin2bcd (tmp->tm_wday + 1) | bat_en);
> rtc_write (RTC_DATE_REG_ADDR, bin2bcd (tmp->tm_mday));
> rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour));
> rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min));
> - rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec));
> + rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec) | clk_en);
>
> return 0;
> }
> @@ -142,7 +161,6 @@ void rtc_reset (void)
> {
> struct rtc_time tmp;
>
> - rtc_write (RTC_SEC_REG_ADDR, 0x00); /* clearing Clock Halt */
> rtc_write (RTC_CTL_REG_ADDR, RTC_CTL_BIT_SQWE | RTC_CTL_BIT_RS1 | RTC_CTL_BIT_RS0);
>
> tmp.tm_year = 1970;
prev parent reply other threads:[~2015-01-15 13:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-27 10:32 [U-Boot] [PATCH] rtc: ds1307: add support for MCP7941x RTCs Soeren Moch
2015-01-15 13:25 ` Soeren Moch [this message]
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=54B7BFC8.3080201@web.de \
--to=smoch@web.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