public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] rtc: pcf2127: don't add/subtract 1 to tm_mon
@ 2020-05-01 13:24 Rasmus Villemoes
  2020-05-01 21:57 ` Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Rasmus Villemoes @ 2020-05-01 13:24 UTC (permalink / raw)
  To: u-boot

As noted in rtc_def.h, the tm_mon field in struct rtc_time is 1-12,
unlike in struct tm where it is 0-11. Currently, running "date" prints
the wrong

Date: 2020-04-01 (Friday)    Time: 13:05:30

and setting the RTC via the date command is also broken.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 drivers/rtc/pcf2127.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/pcf2127.c b/drivers/rtc/pcf2127.c
index f6953505a5..b34ed63bf0 100644
--- a/drivers/rtc/pcf2127.c
+++ b/drivers/rtc/pcf2127.c
@@ -56,7 +56,7 @@ static int pcf2127_rtc_set(struct udevice *dev, const struct rtc_time *tm)
 	buf[i++] = tm->tm_wday & 0x07;
 
 	/* month, 1 - 12 */
-	buf[i++] = bin2bcd(tm->tm_mon + 1);
+	buf[i++] = bin2bcd(tm->tm_mon);
 
 	/* year */
 	buf[i++] = bin2bcd(tm->tm_year % 100);
@@ -83,7 +83,7 @@ static int pcf2127_rtc_get(struct udevice *dev, struct rtc_time *tm)
 	tm->tm_min  = bcd2bin(buf[PCF2127_REG_MN] & 0x7F);
 	tm->tm_hour = bcd2bin(buf[PCF2127_REG_HR] & 0x3F);
 	tm->tm_mday = bcd2bin(buf[PCF2127_REG_DM] & 0x3F);
-	tm->tm_mon  = bcd2bin(buf[PCF2127_REG_MO] & 0x1F) - 1;
+	tm->tm_mon  = bcd2bin(buf[PCF2127_REG_MO] & 0x1F);
 	tm->tm_year = bcd2bin(buf[PCF2127_REG_YR]) + 1900;
 	if (tm->tm_year < 1970)
 		tm->tm_year += 100;	/* assume we are in 1970...2069 */
-- 
2.23.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] rtc: pcf2127: don't add/subtract 1 to tm_mon
  2020-05-01 13:24 [PATCH] rtc: pcf2127: don't add/subtract 1 to tm_mon Rasmus Villemoes
@ 2020-05-01 21:57 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2020-05-01 21:57 UTC (permalink / raw)
  To: u-boot

On Fri, May 01, 2020 at 03:24:50PM +0200, Rasmus Villemoes wrote:

> As noted in rtc_def.h, the tm_mon field in struct rtc_time is 1-12,
> unlike in struct tm where it is 0-11. Currently, running "date" prints
> the wrong
> 
> Date: 2020-04-01 (Friday)    Time: 13:05:30
> 
> and setting the RTC via the date command is also broken.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200501/e56f01bf/attachment.sig>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-01 21:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-01 13:24 [PATCH] rtc: pcf2127: don't add/subtract 1 to tm_mon Rasmus Villemoes
2020-05-01 21:57 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox