hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rtc/rtc-lpc32xx.c
....@@ -1,14 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Copyright (C) 2010 NXP Semiconductors
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * You should have received a copy of the GNU General Public License along
10
- * with this program; if not, write to the Free Software Foundation, Inc.,
11
- * 675 Mass Ave, Cambridge, MA 02139, USA.
124 */
135
146 #include <linux/kernel.h>
....@@ -47,8 +39,6 @@
4739
4840 #define LPC32XX_RTC_KEY_ONSW_LOADVAL 0xB5C13F27
4941
50
-#define RTC_NAME "rtc-lpc32xx"
51
-
5242 #define rtc_readl(dev, reg) \
5343 __raw_readl((dev)->rtc_base + (reg))
5444 #define rtc_writel(dev, reg, val) \
....@@ -68,14 +58,15 @@
6858 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
6959
7060 elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT);
71
- rtc_time_to_tm(elapsed_sec, time);
61
+ rtc_time64_to_tm(elapsed_sec, time);
7262
7363 return 0;
7464 }
7565
76
-static int lpc32xx_rtc_set_mmss(struct device *dev, unsigned long secs)
66
+static int lpc32xx_rtc_set_time(struct device *dev, struct rtc_time *time)
7767 {
7868 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
69
+ u32 secs = rtc_tm_to_time64(time);
7970 u32 tmp;
8071
8172 spin_lock_irq(&rtc->lock);
....@@ -97,7 +88,7 @@
9788 {
9889 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
9990
100
- rtc_time_to_tm(rtc_readl(rtc, LPC32XX_RTC_MATCH0), &wkalrm->time);
91
+ rtc_time64_to_tm(rtc_readl(rtc, LPC32XX_RTC_MATCH0), &wkalrm->time);
10192 wkalrm->enabled = rtc->alarm_enabled;
10293 wkalrm->pending = !!(rtc_readl(rtc, LPC32XX_RTC_INTSTAT) &
10394 LPC32XX_RTC_INTSTAT_MATCH0);
....@@ -111,13 +102,8 @@
111102 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
112103 unsigned long alarmsecs;
113104 u32 tmp;
114
- int ret;
115105
116
- ret = rtc_tm_to_time(&wkalrm->time, &alarmsecs);
117
- if (ret < 0) {
118
- dev_warn(dev, "Failed to convert time: %d\n", ret);
119
- return ret;
120
- }
106
+ alarmsecs = rtc_tm_to_time64(&wkalrm->time);
121107
122108 spin_lock_irq(&rtc->lock);
123109
....@@ -191,7 +177,7 @@
191177
192178 static const struct rtc_class_ops lpc32xx_rtc_ops = {
193179 .read_time = lpc32xx_rtc_read_time,
194
- .set_mmss = lpc32xx_rtc_set_mmss,
180
+ .set_time = lpc32xx_rtc_set_time,
195181 .read_alarm = lpc32xx_rtc_read_alarm,
196182 .set_alarm = lpc32xx_rtc_set_alarm,
197183 .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable,
....@@ -199,25 +185,15 @@
199185
200186 static int lpc32xx_rtc_probe(struct platform_device *pdev)
201187 {
202
- struct resource *res;
203188 struct lpc32xx_rtc *rtc;
204
- int rtcirq;
189
+ int err;
205190 u32 tmp;
206
-
207
- rtcirq = platform_get_irq(pdev, 0);
208
- if (rtcirq < 0) {
209
- dev_warn(&pdev->dev, "Can't get interrupt resource\n");
210
- rtcirq = -1;
211
- }
212191
213192 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
214193 if (unlikely(!rtc))
215194 return -ENOMEM;
216195
217
- rtc->irq = rtcirq;
218
-
219
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
220
- rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
196
+ rtc->rtc_base = devm_platform_ioremap_resource(pdev, 0);
221197 if (IS_ERR(rtc->rtc_base))
222198 return PTR_ERR(rtc->rtc_base);
223199
....@@ -256,18 +232,25 @@
256232
257233 platform_set_drvdata(pdev, rtc);
258234
259
- rtc->rtc = devm_rtc_device_register(&pdev->dev, RTC_NAME,
260
- &lpc32xx_rtc_ops, THIS_MODULE);
261
- if (IS_ERR(rtc->rtc)) {
262
- dev_err(&pdev->dev, "Can't get RTC\n");
235
+ rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
236
+ if (IS_ERR(rtc->rtc))
263237 return PTR_ERR(rtc->rtc);
264
- }
238
+
239
+ rtc->rtc->ops = &lpc32xx_rtc_ops;
240
+ rtc->rtc->range_max = U32_MAX;
241
+
242
+ err = rtc_register_device(rtc->rtc);
243
+ if (err)
244
+ return err;
265245
266246 /*
267247 * IRQ is enabled after device registration in case alarm IRQ
268248 * is pending upon suspend exit.
269249 */
270
- if (rtc->irq >= 0) {
250
+ rtc->irq = platform_get_irq(pdev, 0);
251
+ if (rtc->irq < 0) {
252
+ dev_warn(&pdev->dev, "Can't get interrupt resource\n");
253
+ } else {
271254 if (devm_request_irq(&pdev->dev, rtc->irq,
272255 lpc32xx_rtc_alarm_interrupt,
273256 0, pdev->name, rtc) < 0) {
....@@ -277,16 +260,6 @@
277260 device_init_wakeup(&pdev->dev, 1);
278261 }
279262 }
280
-
281
- return 0;
282
-}
283
-
284
-static int lpc32xx_rtc_remove(struct platform_device *pdev)
285
-{
286
- struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev);
287
-
288
- if (rtc->irq >= 0)
289
- device_init_wakeup(&pdev->dev, 0);
290263
291264 return 0;
292265 }
....@@ -372,9 +345,8 @@
372345
373346 static struct platform_driver lpc32xx_rtc_driver = {
374347 .probe = lpc32xx_rtc_probe,
375
- .remove = lpc32xx_rtc_remove,
376348 .driver = {
377
- .name = RTC_NAME,
349
+ .name = "rtc-lpc32xx",
378350 .pm = LPC32XX_RTC_PM_OPS,
379351 .of_match_table = of_match_ptr(lpc32xx_rtc_match),
380352 },