]> git.karo-electronics.de Git - linux-beck.git/commitdiff
rtc: mv: reset date if after year 2038
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Tue, 18 Feb 2014 13:26:06 +0000 (14:26 +0100)
committerJason Cooper <jason@lakedaemon.net>
Fri, 21 Feb 2014 23:29:05 +0000 (23:29 +0000)
Dates after January, 19th 2038 are badly handled by userspace due to
the time being stored on 32 bits. This causes issues on some Marvell
platform on which the RTC is initialized by default to a date that's
beyond 2038, causing a really weird behavior of the RTC.

In order to avoid that, reset the date to a sane value if the RTC is
beyond 2038.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
drivers/rtc/rtc-mv.c

index d536c5962c99f1e6477f63b377e7445c354c5d14..d15a999363fce2808cfcba6089cf8282dfedc48a 100644 (file)
@@ -222,6 +222,7 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
        struct resource *res;
        struct rtc_plat_data *pdata;
        u32 rtc_time;
+       u32 rtc_date;
        int ret = 0;
 
        pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
@@ -257,6 +258,17 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
                }
        }
 
+       /*
+        * A date after January 19th, 2038 does not fit on 32 bits and
+        * will confuse the kernel and userspace. Reset to a sane date
+        * (January 1st, 2013) if we're after 2038.
+        */
+       rtc_date = readl(pdata->ioaddr + RTC_DATE_REG_OFFS);
+       if (bcd2bin((rtc_date >> RTC_YEAR_OFFS) & 0xff) >= 38) {
+               dev_info(&pdev->dev, "invalid RTC date, resetting to January 1st, 2013\n");
+               writel(0x130101, pdata->ioaddr + RTC_DATE_REG_OFFS);
+       }
+
        pdata->irq = platform_get_irq(pdev, 0);
 
        platform_set_drvdata(pdev, pdata);