--- zzzz-none-000/linux-3.10.107/drivers/rtc/rtc-mv.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/rtc/rtc-mv.c 2021-02-04 17:41:59.000000000 +0000 @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -24,7 +25,7 @@ #define RTC_MINUTES_OFFS 8 #define RTC_HOURS_OFFS 16 #define RTC_WDAY_OFFS 24 -#define RTC_HOURS_12H_MODE (1 << 22) /* 12 hours mode */ +#define RTC_HOURS_12H_MODE BIT(22) /* 12 hour mode */ #define RTC_DATE_REG_OFFS 4 #define RTC_MDAY_OFFS 0 @@ -33,7 +34,7 @@ #define RTC_ALARM_TIME_REG_OFFS 8 #define RTC_ALARM_DATE_REG_OFFS 0xc -#define RTC_ALARM_VALID (1 << 7) +#define RTC_ALARM_VALID BIT(7) #define RTC_ALARM_INTERRUPT_MASK_REG_OFFS 0x10 #define RTC_ALARM_INTERRUPT_CASUE_REG_OFFS 0x14 @@ -77,7 +78,7 @@ second = rtc_time & 0x7f; minute = (rtc_time >> RTC_MINUTES_OFFS) & 0x7f; - hour = (rtc_time >> RTC_HOURS_OFFS) & 0x3f; /* assume 24 hours mode */ + hour = (rtc_time >> RTC_HOURS_OFFS) & 0x3f; /* assume 24 hour mode */ wday = (rtc_time >> RTC_WDAY_OFFS) & 0x7; day = rtc_date & 0x3f; @@ -108,7 +109,7 @@ second = rtc_time & 0x7f; minute = (rtc_time >> RTC_MINUTES_OFFS) & 0x7f; - hour = (rtc_time >> RTC_HOURS_OFFS) & 0x3f; /* assume 24 hours mode */ + hour = (rtc_time >> RTC_HOURS_OFFS) & 0x3f; /* assume 24 hour mode */ wday = (rtc_time >> RTC_WDAY_OFFS) & 0x7; day = rtc_date & 0x3f; @@ -221,36 +222,28 @@ { struct resource *res; struct rtc_plat_data *pdata; - resource_size_t size; u32 rtc_time; + u32 rtc_date; int ret = 0; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return -ENODEV; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return -ENOMEM; - size = resource_size(res); - if (!devm_request_mem_region(&pdev->dev, res->start, size, - pdev->name)) - return -EBUSY; - - pdata->ioaddr = devm_ioremap(&pdev->dev, res->start, size); - if (!pdata->ioaddr) - return -ENOMEM; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(pdata->ioaddr)) + return PTR_ERR(pdata->ioaddr); pdata->clk = devm_clk_get(&pdev->dev, NULL); /* Not all SoCs require a clock.*/ if (!IS_ERR(pdata->clk)) clk_prepare_enable(pdata->clk); - /* make sure the 24 hours mode is enabled */ + /* make sure the 24 hour mode is enabled */ rtc_time = readl(pdata->ioaddr + RTC_TIME_REG_OFFS); if (rtc_time & RTC_HOURS_12H_MODE) { - dev_err(&pdev->dev, "24 Hours mode not supported.\n"); + dev_err(&pdev->dev, "12 Hour mode is enabled but not supported.\n"); ret = -EINVAL; goto out; } @@ -266,6 +259,17 @@ } } + /* + * 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); @@ -316,17 +320,17 @@ } #ifdef CONFIG_OF -static struct of_device_id rtc_mv_of_match_table[] = { +static const struct of_device_id rtc_mv_of_match_table[] = { { .compatible = "marvell,orion-rtc", }, {} }; +MODULE_DEVICE_TABLE(of, rtc_mv_of_match_table); #endif static struct platform_driver mv_rtc_driver = { .remove = __exit_p(mv_rtc_remove), .driver = { .name = "rtc-mv", - .owner = THIS_MODULE, .of_match_table = of_match_ptr(rtc_mv_of_match_table), }, };