hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rtc/rtc-pl031.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * drivers/rtc/rtc-pl031.c
34 *
....@@ -9,11 +10,6 @@
910 *
1011 * Author: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
1112 * Copyright 2010 (c) ST-Ericsson AB
12
- *
13
- * This program is free software; you can redistribute it and/or
14
- * modify it under the terms of the GNU General Public License
15
- * as published by the Free Software Foundation; either version
16
- * 2 of the License, or (at your option) any later version.
1713 */
1814 #include <linux/module.h>
1915 #include <linux/rtc.h>
....@@ -84,6 +80,8 @@
8480 bool clockwatch;
8581 bool st_weekday;
8682 unsigned long irqflags;
83
+ time64_t range_min;
84
+ timeu64_t range_max;
8785 };
8886
8987 struct pl031_local {
....@@ -127,11 +125,9 @@
127125 return -EINVAL;
128126 } else if (wday == -1) {
129127 /* wday is not provided, calculate it here */
130
- unsigned long time;
131128 struct rtc_time calc_tm;
132129
133
- rtc_tm_to_time(tm, &time);
134
- rtc_time_to_tm(time, &calc_tm);
130
+ rtc_time64_to_tm(rtc_tm_to_time64(tm), &calc_tm);
135131 wday = calc_tm.tm_wday;
136132 }
137133
....@@ -214,17 +210,13 @@
214210 unsigned long bcd_year;
215211 int ret;
216212
217
- /* At the moment, we can only deal with non-wildcarded alarm times. */
218
- ret = rtc_valid_tm(&alarm->time);
213
+ ret = pl031_stv2_tm_to_time(dev, &alarm->time,
214
+ &time, &bcd_year);
219215 if (ret == 0) {
220
- ret = pl031_stv2_tm_to_time(dev, &alarm->time,
221
- &time, &bcd_year);
222
- if (ret == 0) {
223
- writel(bcd_year, ldata->base + RTC_YMR);
224
- writel(time, ldata->base + RTC_MR);
216
+ writel(bcd_year, ldata->base + RTC_YMR);
217
+ writel(time, ldata->base + RTC_MR);
225218
226
- pl031_alarm_irq_enable(dev, alarm->enabled);
227
- }
219
+ pl031_alarm_irq_enable(dev, alarm->enabled);
228220 }
229221
230222 return ret;
....@@ -252,30 +244,25 @@
252244 {
253245 struct pl031_local *ldata = dev_get_drvdata(dev);
254246
255
- rtc_time_to_tm(readl(ldata->base + RTC_DR), tm);
247
+ rtc_time64_to_tm(readl(ldata->base + RTC_DR), tm);
256248
257249 return 0;
258250 }
259251
260252 static int pl031_set_time(struct device *dev, struct rtc_time *tm)
261253 {
262
- unsigned long time;
263254 struct pl031_local *ldata = dev_get_drvdata(dev);
264
- int ret;
265255
266
- ret = rtc_tm_to_time(tm, &time);
256
+ writel(rtc_tm_to_time64(tm), ldata->base + RTC_LR);
267257
268
- if (ret == 0)
269
- writel(time, ldata->base + RTC_LR);
270
-
271
- return ret;
258
+ return 0;
272259 }
273260
274261 static int pl031_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
275262 {
276263 struct pl031_local *ldata = dev_get_drvdata(dev);
277264
278
- rtc_time_to_tm(readl(ldata->base + RTC_MR), &alarm->time);
265
+ rtc_time64_to_tm(readl(ldata->base + RTC_MR), &alarm->time);
279266
280267 alarm->pending = readl(ldata->base + RTC_RIS) & RTC_BIT_AI;
281268 alarm->enabled = readl(ldata->base + RTC_IMSC) & RTC_BIT_AI;
....@@ -286,23 +273,14 @@
286273 static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
287274 {
288275 struct pl031_local *ldata = dev_get_drvdata(dev);
289
- unsigned long time;
290
- int ret;
291276
292
- /* At the moment, we can only deal with non-wildcarded alarm times. */
293
- ret = rtc_valid_tm(&alarm->time);
294
- if (ret == 0) {
295
- ret = rtc_tm_to_time(&alarm->time, &time);
296
- if (ret == 0) {
297
- writel(time, ldata->base + RTC_MR);
298
- pl031_alarm_irq_enable(dev, alarm->enabled);
299
- }
300
- }
277
+ writel(rtc_tm_to_time64(&alarm->time), ldata->base + RTC_MR);
278
+ pl031_alarm_irq_enable(dev, alarm->enabled);
301279
302
- return ret;
280
+ return 0;
303281 }
304282
305
-static int pl031_remove(struct amba_device *adev)
283
+static void pl031_remove(struct amba_device *adev)
306284 {
307285 struct pl031_local *ldata = dev_get_drvdata(&adev->dev);
308286
....@@ -310,10 +288,7 @@
310288 device_init_wakeup(&adev->dev, false);
311289 if (adev->irq[0])
312290 free_irq(adev->irq[0], ldata);
313
- rtc_device_unregister(ldata->rtc);
314291 amba_release_regions(adev);
315
-
316
- return 0;
317292 }
318293
319294 static int pl031_probe(struct amba_device *adev, const struct amba_id *id)
....@@ -383,24 +358,29 @@
383358 }
384359
385360 device_init_wakeup(&adev->dev, true);
386
- ldata->rtc = rtc_device_register("pl031", &adev->dev, ops,
387
- THIS_MODULE);
361
+ ldata->rtc = devm_rtc_allocate_device(&adev->dev);
388362 if (IS_ERR(ldata->rtc)) {
389363 ret = PTR_ERR(ldata->rtc);
390364 goto out;
391365 }
392366
367
+ ldata->rtc->ops = ops;
368
+ ldata->rtc->range_min = vendor->range_min;
369
+ ldata->rtc->range_max = vendor->range_max;
370
+
371
+ ret = rtc_register_device(ldata->rtc);
372
+ if (ret)
373
+ goto out;
374
+
393375 if (adev->irq[0]) {
394376 ret = request_irq(adev->irq[0], pl031_interrupt,
395377 vendor->irqflags, "rtc-pl031", ldata);
396378 if (ret)
397
- goto out_no_irq;
379
+ goto out;
398380 dev_pm_set_wake_irq(&adev->dev, adev->irq[0]);
399381 }
400382 return 0;
401383
402
-out_no_irq:
403
- rtc_device_unregister(ldata->rtc);
404384 out:
405385 amba_release_regions(adev);
406386 err_req:
....@@ -417,6 +397,7 @@
417397 .set_alarm = pl031_set_alarm,
418398 .alarm_irq_enable = pl031_alarm_irq_enable,
419399 },
400
+ .range_max = U32_MAX,
420401 };
421402
422403 /* The First ST derivative */
....@@ -430,6 +411,7 @@
430411 },
431412 .clockwatch = true,
432413 .st_weekday = true,
414
+ .range_max = U32_MAX,
433415 };
434416
435417 /* And the second ST derivative */
....@@ -450,6 +432,8 @@
450432 * remove IRQF_COND_SUSPEND
451433 */
452434 .irqflags = IRQF_SHARED | IRQF_COND_SUSPEND,
435
+ .range_min = RTC_TIMESTAMP_BEGIN_0000,
436
+ .range_max = RTC_TIMESTAMP_END_9999,
453437 };
454438
455439 static const struct amba_id pl031_ids[] = {