rtc: pcf2123: let the core handle range offsetting
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 19 Aug 2019 18:26:55 +0000 (20:26 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Tue, 20 Aug 2019 19:42:17 +0000 (21:42 +0200)
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>
drivers/rtc/rtc-pcf2123.c

index fd326fd2932ee33345267b3dc63f6432b523e263..bda4b1687318c0df48d016fdbf6ab93c829c76b0 100644 (file)
@@ -194,9 +194,7 @@ static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm)
        tm->tm_mday = bcd2bin(rxbuf[3] & 0x3F);
        tm->tm_wday = rxbuf[4] & 0x07;
        tm->tm_mon = bcd2bin(rxbuf[5] & 0x1F) - 1; /* rtc mn 1-12 */
-       tm->tm_year = bcd2bin(rxbuf[6]);
-       if (tm->tm_year < 70)
-               tm->tm_year += 100;     /* assume we are in 1970...2069 */
+       tm->tm_year = bcd2bin(rxbuf[6]) + 100;
 
        dev_dbg(dev, "%s: tm is %ptR\n", __func__, tm);
 
@@ -223,7 +221,7 @@ static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
        txbuf[3] = bin2bcd(tm->tm_mday & 0x3F);
        txbuf[4] = tm->tm_wday & 0x07;
        txbuf[5] = bin2bcd((tm->tm_mon + 1) & 0x1F); /* rtc mn 1-12 */
-       txbuf[6] = bin2bcd(tm->tm_year < 100 ? tm->tm_year : tm->tm_year - 100);
+       txbuf[6] = bin2bcd(tm->tm_year - 100);
 
        ret = regmap_bulk_write(pcf2123->map, PCF2123_REG_SC, txbuf,
                                sizeof(txbuf));
@@ -432,6 +430,9 @@ static int pcf2123_probe(struct spi_device *spi)
         */
        rtc->uie_unsupported = 1;
        rtc->ops = &pcf2123_rtc_ops;
+       rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+       rtc->range_max = RTC_TIMESTAMP_END_2099;
+       rtc->set_start_time = true;
 
        ret = rtc_register_device(rtc);
        if (ret)