Skip to content

Commit 5572718

Browse files
Wolfram Sangalexandrebelloni
authored andcommitted
rtc: rzn1: fix BCD to rtc_time conversion errors
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: deeb4b5 ("rtc: rzn1: Add new RTC driver") Signed-off-by: Wolfram Sang <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 6cc79a6 commit 5572718

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/rtc/rtc-rzn1.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
111111
tm->tm_hour = bcd2bin(tm->tm_hour);
112112
tm->tm_wday = bcd2bin(tm->tm_wday);
113113
tm->tm_mday = bcd2bin(tm->tm_mday);
114-
tm->tm_mon = bcd2bin(tm->tm_mon);
115-
tm->tm_year = bcd2bin(tm->tm_year);
114+
tm->tm_mon = bcd2bin(tm->tm_mon) - 1;
115+
tm->tm_year = bcd2bin(tm->tm_year) + 100;
116116

117117
return 0;
118118
}
@@ -128,8 +128,8 @@ static int rzn1_rtc_set_time(struct device *dev, struct rtc_time *tm)
128128
tm->tm_hour = bin2bcd(tm->tm_hour);
129129
tm->tm_wday = bin2bcd(rzn1_rtc_tm_to_wday(tm));
130130
tm->tm_mday = bin2bcd(tm->tm_mday);
131-
tm->tm_mon = bin2bcd(tm->tm_mon);
132-
tm->tm_year = bin2bcd(tm->tm_year);
131+
tm->tm_mon = bin2bcd(tm->tm_mon + 1);
132+
tm->tm_year = bin2bcd(tm->tm_year - 100);
133133

134134
val = readl(rtc->base + RZN1_RTC_CTL2);
135135
if (!(val & RZN1_RTC_CTL2_STOPPED)) {

0 commit comments

Comments
 (0)