rtc: sh: set range
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Wed, 20 Mar 2019 11:30:10 +0000 (12:30 +0100)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Thu, 4 Apr 2019 08:07:09 +0000 (10:07 +0200)
The SH RTC is a BCD RTC with some version having 4 digits for the year.

The range for the RTCs with only 2 digits for the year was unfortunately
shifted to handle 1999 to 2098.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-sh.c
include/linux/rtc.h

index d9e67ca..4cca54a 100644 (file)
@@ -600,6 +600,14 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
        rtc->rtc_dev->ops = &sh_rtc_ops;
        rtc->rtc_dev->max_user_freq = 256;
 
+       if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
+               rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
+               rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
+       } else {
+               rtc->rtc_dev->range_min = mktime64(1999, 1, 1, 0, 0, 0);
+               rtc->rtc_dev->range_max = mktime64(2098, 12, 31, 23, 59, 59);
+       }
+
        ret = rtc_register_device(rtc->rtc_dev);
        if (ret)
                goto err_unmap;
index f89bfbb..588120b 100644 (file)
@@ -165,6 +165,7 @@ struct rtc_device {
 #define RTC_TIMESTAMP_BEGIN_1900       -2208989361LL /* 1900-01-01 00:00:00 */
 #define RTC_TIMESTAMP_BEGIN_2000       946684800LL /* 2000-01-01 00:00:00 */
 #define RTC_TIMESTAMP_END_2099         4102444799LL /* 2099-12-31 23:59:59 */
+#define RTC_TIMESTAMP_END_9999         253402300799LL /* 9999-12-31 23:59:59 */
 
 extern struct rtc_device *devm_rtc_device_register(struct device *dev,
                                        const char *name,