diff options
Diffstat (limited to 'drivers/rtc/rtc-pic32.c')
-rw-r--r-- | drivers/rtc/rtc-pic32.c | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/drivers/rtc/rtc-pic32.c b/drivers/rtc/rtc-pic32.c index d7ef0a6f8931..1c4de6e90da0 100644 --- a/drivers/rtc/rtc-pic32.c +++ b/drivers/rtc/rtc-pic32.c | |||
@@ -1,18 +1,10 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0+ | ||
1 | /* | 2 | /* |
2 | * PIC32 RTC driver | 3 | * PIC32 RTC driver |
3 | * | 4 | * |
4 | * Joshua Henderson <joshua.henderson@microchip.com> | 5 | * Joshua Henderson <joshua.henderson@microchip.com> |
5 | * Copyright (C) 2016 Microchip Technology Inc. All rights reserved. | 6 | * Copyright (C) 2016 Microchip Technology Inc. All rights reserved. |
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
15 | * more details. | ||
16 | */ | 8 | */ |
17 | #include <linux/init.h> | 9 | #include <linux/init.h> |
18 | #include <linux/module.h> | 10 | #include <linux/module.h> |
@@ -180,22 +172,16 @@ static int pic32_rtc_settime(struct device *dev, struct rtc_time *tm) | |||
180 | { | 172 | { |
181 | struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); | 173 | struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); |
182 | void __iomem *base = pdata->reg_base; | 174 | void __iomem *base = pdata->reg_base; |
183 | int year = tm->tm_year - 100; | ||
184 | 175 | ||
185 | dev_dbg(dev, "set time %ptR\n", tm); | 176 | dev_dbg(dev, "set time %ptR\n", tm); |
186 | 177 | ||
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); | 178 | clk_enable(pdata->clk); |
193 | writeb(bin2bcd(tm->tm_sec), base + PIC32_RTCSEC); | 179 | writeb(bin2bcd(tm->tm_sec), base + PIC32_RTCSEC); |
194 | writeb(bin2bcd(tm->tm_min), base + PIC32_RTCMIN); | 180 | writeb(bin2bcd(tm->tm_min), base + PIC32_RTCMIN); |
195 | writeb(bin2bcd(tm->tm_hour), base + PIC32_RTCHOUR); | 181 | writeb(bin2bcd(tm->tm_hour), base + PIC32_RTCHOUR); |
196 | writeb(bin2bcd(tm->tm_mday), base + PIC32_RTCDAY); | 182 | writeb(bin2bcd(tm->tm_mday), base + PIC32_RTCDAY); |
197 | writeb(bin2bcd(tm->tm_mon + 1), base + PIC32_RTCMON); | 183 | writeb(bin2bcd(tm->tm_mon + 1), base + PIC32_RTCMON); |
198 | writeb(bin2bcd(year), base + PIC32_RTCYEAR); | 184 | writeb(bin2bcd(tm->tm_year - 100), base + PIC32_RTCYEAR); |
199 | clk_disable(pdata->clk); | 185 | clk_disable(pdata->clk); |
200 | 186 | ||
201 | return 0; | 187 | return 0; |
@@ -348,13 +334,17 @@ static int pic32_rtc_probe(struct platform_device *pdev) | |||
348 | 334 | ||
349 | device_init_wakeup(&pdev->dev, 1); | 335 | device_init_wakeup(&pdev->dev, 1); |
350 | 336 | ||
351 | pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, | 337 | pdata->rtc = devm_rtc_allocate_device(&pdev->dev); |
352 | &pic32_rtcops, | 338 | if (IS_ERR(pdata->rtc)) |
353 | THIS_MODULE); | 339 | return PTR_ERR(pdata->rtc); |
354 | if (IS_ERR(pdata->rtc)) { | 340 | |
355 | ret = PTR_ERR(pdata->rtc); | 341 | pdata->rtc->ops = &pic32_rtcops; |
342 | pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; | ||
343 | pdata->rtc->range_max = RTC_TIMESTAMP_END_2099; | ||
344 | |||
345 | ret = rtc_register_device(pdata->rtc); | ||
346 | if (ret) | ||
356 | goto err_nortc; | 347 | goto err_nortc; |
357 | } | ||
358 | 348 | ||
359 | pdata->rtc->max_user_freq = 128; | 349 | pdata->rtc->max_user_freq = 128; |
360 | 350 | ||