Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: pcf2123: let the core handle range offsetting

Set the RTC range properly and use the core windowing and offsetting to
(unfortunately) map back to a 1970-2069 range.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20190819182656.29744-8-alexandre.belloni@bootlin.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

+5 -4
+5 -4
drivers/rtc/rtc-pcf2123.c
··· 194 194 tm->tm_mday = bcd2bin(rxbuf[3] & 0x3F); 195 195 tm->tm_wday = rxbuf[4] & 0x07; 196 196 tm->tm_mon = bcd2bin(rxbuf[5] & 0x1F) - 1; /* rtc mn 1-12 */ 197 - tm->tm_year = bcd2bin(rxbuf[6]); 198 - if (tm->tm_year < 70) 199 - tm->tm_year += 100; /* assume we are in 1970...2069 */ 197 + tm->tm_year = bcd2bin(rxbuf[6]) + 100; 200 198 201 199 dev_dbg(dev, "%s: tm is %ptR\n", __func__, tm); 202 200 ··· 221 223 txbuf[3] = bin2bcd(tm->tm_mday & 0x3F); 222 224 txbuf[4] = tm->tm_wday & 0x07; 223 225 txbuf[5] = bin2bcd((tm->tm_mon + 1) & 0x1F); /* rtc mn 1-12 */ 224 - txbuf[6] = bin2bcd(tm->tm_year < 100 ? tm->tm_year : tm->tm_year - 100); 226 + txbuf[6] = bin2bcd(tm->tm_year - 100); 225 227 226 228 ret = regmap_bulk_write(pcf2123->map, PCF2123_REG_SC, txbuf, 227 229 sizeof(txbuf)); ··· 430 432 */ 431 433 rtc->uie_unsupported = 1; 432 434 rtc->ops = &pcf2123_rtc_ops; 435 + rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 436 + rtc->range_max = RTC_TIMESTAMP_END_2099; 437 + rtc->set_start_time = true; 433 438 434 439 ret = rtc_register_device(rtc); 435 440 if (ret)