aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-pic32.c
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2019-03-04 05:19:02 -0500
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2019-03-04 14:21:19 -0500
commitc145e5f4a4b76971d42098775a2443bdd4884de4 (patch)
treee3f4ed2d0b9a40155f1a977813fdada0c2088599 /drivers/rtc/rtc-pic32.c
parent6515e23b9fdeb9a69caee79f6a71dd6d82125f66 (diff)
rtc: pic32: let the core handle range
Let the core handle the RTC range instead of open coding it. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc/rtc-pic32.c')
-rw-r--r--drivers/rtc/rtc-pic32.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/drivers/rtc/rtc-pic32.c b/drivers/rtc/rtc-pic32.c
index 43bd701daef2..7824acc18b6e 100644
--- a/drivers/rtc/rtc-pic32.c
+++ b/drivers/rtc/rtc-pic32.c
@@ -180,22 +180,16 @@ static int pic32_rtc_settime(struct device *dev, struct rtc_time *tm)
180{ 180{
181 struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); 181 struct pic32_rtc_dev *pdata = dev_get_drvdata(dev);
182 void __iomem *base = pdata->reg_base; 182 void __iomem *base = pdata->reg_base;
183 int year = tm->tm_year - 100;
184 183
185 dev_dbg(dev, "set time %ptR\n", tm); 184 dev_dbg(dev, "set time %ptR\n", tm);
186 185
187 if (year < 0 || year >= 100) {
188 dev_err(dev, "rtc only supports 100 years\n");
189 return -EINVAL;
190 }
191
192 clk_enable(pdata->clk); 186 clk_enable(pdata->clk);
193 writeb(bin2bcd(tm->tm_sec), base + PIC32_RTCSEC); 187 writeb(bin2bcd(tm->tm_sec), base + PIC32_RTCSEC);
194 writeb(bin2bcd(tm->tm_min), base + PIC32_RTCMIN); 188 writeb(bin2bcd(tm->tm_min), base + PIC32_RTCMIN);
195 writeb(bin2bcd(tm->tm_hour), base + PIC32_RTCHOUR); 189 writeb(bin2bcd(tm->tm_hour), base + PIC32_RTCHOUR);
196 writeb(bin2bcd(tm->tm_mday), base + PIC32_RTCDAY); 190 writeb(bin2bcd(tm->tm_mday), base + PIC32_RTCDAY);
197 writeb(bin2bcd(tm->tm_mon + 1), base + PIC32_RTCMON); 191 writeb(bin2bcd(tm->tm_mon + 1), base + PIC32_RTCMON);
198 writeb(bin2bcd(year), base + PIC32_RTCYEAR); 192 writeb(bin2bcd(tm->tm_year - 100), base + PIC32_RTCYEAR);
199 clk_disable(pdata->clk); 193 clk_disable(pdata->clk);
200 194
201 return 0; 195 return 0;
@@ -353,6 +347,8 @@ static int pic32_rtc_probe(struct platform_device *pdev)
353 return PTR_ERR(pdata->rtc); 347 return PTR_ERR(pdata->rtc);
354 348
355 pdata->rtc->ops = &pic32_rtcops; 349 pdata->rtc->ops = &pic32_rtcops;
350 pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
351 pdata->rtc->range_max = RTC_TIMESTAMP_END_2099;
356 352
357 ret = rtc_register_device(pdata->rtc); 353 ret = rtc_register_device(pdata->rtc);
358 if (ret) 354 if (ret)