Skip to content

Commit 8ae79be

Browse files
rtc: sun6i: let the core handle rtc range
Let the rtc core check the date/time against the RTC range. Tested-by: Paul Kocialkowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 99b7ac9 commit 8ae79be

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

drivers/rtc/rtc-sun6i.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
* driver, even though it is somewhat limited.
109109
*/
110110
#define SUN6I_YEAR_MIN 1970
111-
#define SUN6I_YEAR_MAX 2033
112111
#define SUN6I_YEAR_OFF (SUN6I_YEAR_MIN - 1900)
113112

114113
/*
@@ -569,14 +568,6 @@ static int sun6i_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
569568
struct sun6i_rtc_dev *chip = dev_get_drvdata(dev);
570569
u32 date = 0;
571570
u32 time = 0;
572-
int year;
573-
574-
year = rtc_tm->tm_year + 1900;
575-
if (year < SUN6I_YEAR_MIN || year > SUN6I_YEAR_MAX) {
576-
dev_err(dev, "rtc only supports year in range %d - %d\n",
577-
SUN6I_YEAR_MIN, SUN6I_YEAR_MAX);
578-
return -EINVAL;
579-
}
580571

581572
rtc_tm->tm_year -= SUN6I_YEAR_OFF;
582573
rtc_tm->tm_mon += 1;
@@ -585,7 +576,7 @@ static int sun6i_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
585576
SUN6I_DATE_SET_MON_VALUE(rtc_tm->tm_mon) |
586577
SUN6I_DATE_SET_YEAR_VALUE(rtc_tm->tm_year);
587578

588-
if (is_leap_year(year))
579+
if (is_leap_year(rtc_tm->tm_year + SUN6I_YEAR_MIN))
589580
date |= SUN6I_LEAP_SET_VALUE(1);
590581

591582
time = SUN6I_TIME_SET_SEC_VALUE(rtc_tm->tm_sec) |
@@ -726,12 +717,16 @@ static int sun6i_rtc_probe(struct platform_device *pdev)
726717

727718
device_init_wakeup(&pdev->dev, 1);
728719

729-
chip->rtc = devm_rtc_device_register(&pdev->dev, "rtc-sun6i",
730-
&sun6i_rtc_ops, THIS_MODULE);
731-
if (IS_ERR(chip->rtc)) {
732-
dev_err(&pdev->dev, "unable to register device\n");
720+
chip->rtc = devm_rtc_allocate_device(&pdev->dev);
721+
if (IS_ERR(chip->rtc))
733722
return PTR_ERR(chip->rtc);
734-
}
723+
724+
chip->rtc->ops = &sun6i_rtc_ops;
725+
chip->rtc->range_max = 2019686399LL; /* 2033-12-31 23:59:59 */
726+
727+
ret = rtc_register_device(chip->rtc);
728+
if (ret)
729+
return ret;
735730

736731
dev_info(&pdev->dev, "RTC enabled\n");
737732

0 commit comments

Comments
 (0)