.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * 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. |
---|
12 | 4 | */ |
---|
13 | 5 | |
---|
14 | 6 | #include <linux/kernel.h> |
---|
.. | .. |
---|
47 | 39 | |
---|
48 | 40 | #define LPC32XX_RTC_KEY_ONSW_LOADVAL 0xB5C13F27 |
---|
49 | 41 | |
---|
50 | | -#define RTC_NAME "rtc-lpc32xx" |
---|
51 | | - |
---|
52 | 42 | #define rtc_readl(dev, reg) \ |
---|
53 | 43 | __raw_readl((dev)->rtc_base + (reg)) |
---|
54 | 44 | #define rtc_writel(dev, reg, val) \ |
---|
.. | .. |
---|
68 | 58 | struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); |
---|
69 | 59 | |
---|
70 | 60 | elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT); |
---|
71 | | - rtc_time_to_tm(elapsed_sec, time); |
---|
| 61 | + rtc_time64_to_tm(elapsed_sec, time); |
---|
72 | 62 | |
---|
73 | 63 | return 0; |
---|
74 | 64 | } |
---|
75 | 65 | |
---|
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) |
---|
77 | 67 | { |
---|
78 | 68 | struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); |
---|
| 69 | + u32 secs = rtc_tm_to_time64(time); |
---|
79 | 70 | u32 tmp; |
---|
80 | 71 | |
---|
81 | 72 | spin_lock_irq(&rtc->lock); |
---|
.. | .. |
---|
97 | 88 | { |
---|
98 | 89 | struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); |
---|
99 | 90 | |
---|
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); |
---|
101 | 92 | wkalrm->enabled = rtc->alarm_enabled; |
---|
102 | 93 | wkalrm->pending = !!(rtc_readl(rtc, LPC32XX_RTC_INTSTAT) & |
---|
103 | 94 | LPC32XX_RTC_INTSTAT_MATCH0); |
---|
.. | .. |
---|
111 | 102 | struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); |
---|
112 | 103 | unsigned long alarmsecs; |
---|
113 | 104 | u32 tmp; |
---|
114 | | - int ret; |
---|
115 | 105 | |
---|
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); |
---|
121 | 107 | |
---|
122 | 108 | spin_lock_irq(&rtc->lock); |
---|
123 | 109 | |
---|
.. | .. |
---|
191 | 177 | |
---|
192 | 178 | static const struct rtc_class_ops lpc32xx_rtc_ops = { |
---|
193 | 179 | .read_time = lpc32xx_rtc_read_time, |
---|
194 | | - .set_mmss = lpc32xx_rtc_set_mmss, |
---|
| 180 | + .set_time = lpc32xx_rtc_set_time, |
---|
195 | 181 | .read_alarm = lpc32xx_rtc_read_alarm, |
---|
196 | 182 | .set_alarm = lpc32xx_rtc_set_alarm, |
---|
197 | 183 | .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable, |
---|
.. | .. |
---|
199 | 185 | |
---|
200 | 186 | static int lpc32xx_rtc_probe(struct platform_device *pdev) |
---|
201 | 187 | { |
---|
202 | | - struct resource *res; |
---|
203 | 188 | struct lpc32xx_rtc *rtc; |
---|
204 | | - int rtcirq; |
---|
| 189 | + int err; |
---|
205 | 190 | 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 | | - } |
---|
212 | 191 | |
---|
213 | 192 | rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); |
---|
214 | 193 | if (unlikely(!rtc)) |
---|
215 | 194 | return -ENOMEM; |
---|
216 | 195 | |
---|
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); |
---|
221 | 197 | if (IS_ERR(rtc->rtc_base)) |
---|
222 | 198 | return PTR_ERR(rtc->rtc_base); |
---|
223 | 199 | |
---|
.. | .. |
---|
256 | 232 | |
---|
257 | 233 | platform_set_drvdata(pdev, rtc); |
---|
258 | 234 | |
---|
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)) |
---|
263 | 237 | 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; |
---|
265 | 245 | |
---|
266 | 246 | /* |
---|
267 | 247 | * IRQ is enabled after device registration in case alarm IRQ |
---|
268 | 248 | * is pending upon suspend exit. |
---|
269 | 249 | */ |
---|
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 { |
---|
271 | 254 | if (devm_request_irq(&pdev->dev, rtc->irq, |
---|
272 | 255 | lpc32xx_rtc_alarm_interrupt, |
---|
273 | 256 | 0, pdev->name, rtc) < 0) { |
---|
.. | .. |
---|
277 | 260 | device_init_wakeup(&pdev->dev, 1); |
---|
278 | 261 | } |
---|
279 | 262 | } |
---|
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); |
---|
290 | 263 | |
---|
291 | 264 | return 0; |
---|
292 | 265 | } |
---|
.. | .. |
---|
372 | 345 | |
---|
373 | 346 | static struct platform_driver lpc32xx_rtc_driver = { |
---|
374 | 347 | .probe = lpc32xx_rtc_probe, |
---|
375 | | - .remove = lpc32xx_rtc_remove, |
---|
376 | 348 | .driver = { |
---|
377 | | - .name = RTC_NAME, |
---|
| 349 | + .name = "rtc-lpc32xx", |
---|
378 | 350 | .pm = LPC32XX_RTC_PM_OPS, |
---|
379 | 351 | .of_match_table = of_match_ptr(lpc32xx_rtc_match), |
---|
380 | 352 | }, |
---|