]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtc: rzn1: fix BCD to rtc_time conversion errors
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Wed, 13 Nov 2024 11:30:32 +0000 (12:30 +0100)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 18 Nov 2024 11:04:59 +0000 (12:04 +0100)
tm_mon describes months from 0 to 11, but the register contains BCD from
1 to 12. tm_year contains years since 1900, but the BCD contains 20XX.
Apply the offsets when converting these numbers.

Fixes: deeb4b5393e1 ("rtc: rzn1: Add new RTC driver")
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20241113113032.27409-1-wsa+renesas@sang-engineering.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-rzn1.c

index a8316956f7d72805dc4bfebc5a82cf0e89401f54..d084e8b838fc691a391a76e3f854e0a81770bee2 100644 (file)
@@ -111,8 +111,8 @@ static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
        tm->tm_hour = bcd2bin(tm->tm_hour);
        tm->tm_wday = bcd2bin(tm->tm_wday);
        tm->tm_mday = bcd2bin(tm->tm_mday);
-       tm->tm_mon = bcd2bin(tm->tm_mon);
-       tm->tm_year = bcd2bin(tm->tm_year);
+       tm->tm_mon = bcd2bin(tm->tm_mon) - 1;
+       tm->tm_year = bcd2bin(tm->tm_year) + 100;
 
        return 0;
 }
@@ -128,8 +128,8 @@ static int rzn1_rtc_set_time(struct device *dev, struct rtc_time *tm)
        tm->tm_hour = bin2bcd(tm->tm_hour);
        tm->tm_wday = bin2bcd(rzn1_rtc_tm_to_wday(tm));
        tm->tm_mday = bin2bcd(tm->tm_mday);
-       tm->tm_mon = bin2bcd(tm->tm_mon);
-       tm->tm_year = bin2bcd(tm->tm_year);
+       tm->tm_mon = bin2bcd(tm->tm_mon + 1);
+       tm->tm_year = bin2bcd(tm->tm_year - 100);
 
        val = readl(rtc->base + RZN1_RTC_CTL2);
        if (!(val & RZN1_RTC_CTL2_STOPPED)) {