hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/rtc/rtc-at91sam9.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * "RTT as Real Time Clock" driver for AT91SAM9 SoC family
34 *
45 * (C) 2007 Michel Benoit
56 *
67 * Based on rtc-at91rm9200.c by Rick Bronson
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU General Public License
10
- * as published by the Free Software Foundation; either version
11
- * 2 of the License, or (at your option) any later version.
128 */
139
1410 #include <linux/clk.h>
....@@ -47,21 +43,21 @@
4743 * registers available, likewise usable for more than "RTC" support.
4844 */
4945
50
-#define AT91_RTT_MR 0x00 /* Real-time Mode Register */
51
-#define AT91_RTT_RTPRES (0xffff << 0) /* Real-time Timer Prescaler Value */
52
-#define AT91_RTT_ALMIEN (1 << 16) /* Alarm Interrupt Enable */
53
-#define AT91_RTT_RTTINCIEN (1 << 17) /* Real Time Timer Increment Interrupt Enable */
54
-#define AT91_RTT_RTTRST (1 << 18) /* Real Time Timer Restart */
46
+#define AT91_RTT_MR 0x00 /* Real-time Mode Register */
47
+#define AT91_RTT_RTPRES (0xffff << 0) /* Timer Prescaler Value */
48
+#define AT91_RTT_ALMIEN BIT(16) /* Alarm Interrupt Enable */
49
+#define AT91_RTT_RTTINCIEN BIT(17) /* Increment Interrupt Enable */
50
+#define AT91_RTT_RTTRST BIT(18) /* Timer Restart */
5551
56
-#define AT91_RTT_AR 0x04 /* Real-time Alarm Register */
57
-#define AT91_RTT_ALMV (0xffffffff) /* Alarm Value */
52
+#define AT91_RTT_AR 0x04 /* Real-time Alarm Register */
53
+#define AT91_RTT_ALMV (0xffffffff) /* Alarm Value */
5854
59
-#define AT91_RTT_VR 0x08 /* Real-time Value Register */
60
-#define AT91_RTT_CRTV (0xffffffff) /* Current Real-time Value */
55
+#define AT91_RTT_VR 0x08 /* Real-time Value Register */
56
+#define AT91_RTT_CRTV (0xffffffff) /* Current Real-time Value */
6157
62
-#define AT91_RTT_SR 0x0c /* Real-time Status Register */
63
-#define AT91_RTT_ALMS (1 << 0) /* Real-time Alarm Status */
64
-#define AT91_RTT_RTTINC (1 << 1) /* Real-time Timer Increment */
58
+#define AT91_RTT_SR 0x0c /* Real-time Status Register */
59
+#define AT91_RTT_ALMS BIT(0) /* Alarm Status */
60
+#define AT91_RTT_RTTINC BIT(1) /* Timer Increment */
6561
6662 /*
6763 * We store ALARM_DISABLED in ALMV to record that no alarm is set.
....@@ -69,14 +65,13 @@
6965 */
7066 #define ALARM_DISABLED ((u32)~0)
7167
72
-
7368 struct sam9_rtc {
7469 void __iomem *rtt;
7570 struct rtc_device *rtcdev;
7671 u32 imr;
7772 struct regmap *gpbr;
7873 unsigned int gpbr_offset;
79
- int irq;
74
+ int irq;
8075 struct clk *sclk;
8176 bool suspended;
8277 unsigned long events;
....@@ -122,11 +117,9 @@
122117 if (secs != secs2)
123118 secs = rtt_readl(rtc, VR);
124119
125
- rtc_time_to_tm(offset + secs, tm);
120
+ rtc_time64_to_tm(offset + secs, tm);
126121
127
- dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "readtime",
128
- 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
129
- tm->tm_hour, tm->tm_min, tm->tm_sec);
122
+ dev_dbg(dev, "%s: %ptR\n", __func__, tm);
130123
131124 return 0;
132125 }
....@@ -137,17 +130,12 @@
137130 static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
138131 {
139132 struct sam9_rtc *rtc = dev_get_drvdata(dev);
140
- int err;
141133 u32 offset, alarm, mr;
142134 unsigned long secs;
143135
144
- dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "settime",
145
- 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
146
- tm->tm_hour, tm->tm_min, tm->tm_sec);
136
+ dev_dbg(dev, "%s: %ptR\n", __func__, tm);
147137
148
- err = rtc_tm_to_time(tm, &secs);
149
- if (err != 0)
150
- return err;
138
+ secs = rtc_tm_to_time64(tm);
151139
152140 mr = rtt_readl(rtc, MR);
153141
....@@ -197,11 +185,9 @@
197185
198186 memset(alrm, 0, sizeof(*alrm));
199187 if (alarm != ALARM_DISABLED && offset != 0) {
200
- rtc_time_to_tm(offset + alarm, tm);
188
+ rtc_time64_to_tm(offset + alarm, tm);
201189
202
- dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "readalarm",
203
- 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
204
- tm->tm_hour, tm->tm_min, tm->tm_sec);
190
+ dev_dbg(dev, "%s: %ptR\n", __func__, tm);
205191
206192 if (rtt_readl(rtc, MR) & AT91_RTT_ALMIEN)
207193 alrm->enabled = 1;
....@@ -217,11 +203,8 @@
217203 unsigned long secs;
218204 u32 offset;
219205 u32 mr;
220
- int err;
221206
222
- err = rtc_tm_to_time(tm, &secs);
223
- if (err != 0)
224
- return err;
207
+ secs = rtc_tm_to_time64(tm);
225208
226209 offset = gpbr_readl(rtc);
227210 if (offset == 0) {
....@@ -242,9 +225,7 @@
242225 if (alrm->enabled)
243226 rtt_writel(rtc, MR, mr | AT91_RTT_ALMIEN);
244227
245
- dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "setalarm",
246
- tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour,
247
- tm->tm_min, tm->tm_sec);
228
+ dev_dbg(dev, "%s: %ptR\n", __func__, tm);
248229
249230 return 0;
250231 }
....@@ -271,7 +252,7 @@
271252 u32 mr = rtt_readl(rtc, MR);
272253
273254 seq_printf(seq, "update_IRQ\t: %s\n",
274
- (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no");
255
+ (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no");
275256 return 0;
276257 }
277258
....@@ -307,7 +288,7 @@
307288 rtc->events = 0;
308289
309290 pr_debug("%s: num=%ld, events=0x%02lx\n", __func__,
310
- rtc->events >> 8, rtc->events & 0x000000FF);
291
+ rtc->events >> 8, rtc->events & 0x000000FF);
311292 }
312293
313294 /*
....@@ -348,29 +329,20 @@
348329 .alarm_irq_enable = at91_rtc_alarm_irq_enable,
349330 };
350331
351
-static const struct regmap_config gpbr_regmap_config = {
352
- .name = "gpbr",
353
- .reg_bits = 32,
354
- .val_bits = 32,
355
- .reg_stride = 4,
356
-};
357
-
358332 /*
359333 * Initialize and install RTC driver
360334 */
361335 static int at91_rtc_probe(struct platform_device *pdev)
362336 {
363
- struct resource *r;
364337 struct sam9_rtc *rtc;
365338 int ret, irq;
366339 u32 mr;
367340 unsigned int sclk_rate;
341
+ struct of_phandle_args args;
368342
369343 irq = platform_get_irq(pdev, 0);
370
- if (irq < 0) {
371
- dev_err(&pdev->dev, "failed to get interrupt resource\n");
344
+ if (irq < 0)
372345 return irq;
373
- }
374346
375347 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
376348 if (!rtc)
....@@ -385,39 +357,18 @@
385357
386358 platform_set_drvdata(pdev, rtc);
387359
388
- r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
389
- rtc->rtt = devm_ioremap_resource(&pdev->dev, r);
360
+ rtc->rtt = devm_platform_ioremap_resource(pdev, 0);
390361 if (IS_ERR(rtc->rtt))
391362 return PTR_ERR(rtc->rtt);
392363
393
- if (!pdev->dev.of_node) {
394
- /*
395
- * TODO: Remove this code chunk when removing non DT board
396
- * support. Remember to remove the gpbr_regmap_config
397
- * variable too.
398
- */
399
- void __iomem *gpbr;
364
+ ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
365
+ "atmel,rtt-rtc-time-reg", 1, 0,
366
+ &args);
367
+ if (ret)
368
+ return ret;
400369
401
- r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
402
- gpbr = devm_ioremap_resource(&pdev->dev, r);
403
- if (IS_ERR(gpbr))
404
- return PTR_ERR(gpbr);
405
-
406
- rtc->gpbr = regmap_init_mmio(NULL, gpbr,
407
- &gpbr_regmap_config);
408
- } else {
409
- struct of_phandle_args args;
410
-
411
- ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
412
- "atmel,rtt-rtc-time-reg", 1, 0,
413
- &args);
414
- if (ret)
415
- return ret;
416
-
417
- rtc->gpbr = syscon_node_to_regmap(args.np);
418
- rtc->gpbr_offset = args.args[0];
419
- }
420
-
370
+ rtc->gpbr = syscon_node_to_regmap(args.np);
371
+ rtc->gpbr_offset = args.args[0];
421372 if (IS_ERR(rtc->gpbr)) {
422373 dev_err(&pdev->dev, "failed to retrieve gpbr regmap, aborting.\n");
423374 return -ENOMEM;
....@@ -452,12 +403,14 @@
452403 mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
453404 rtt_writel(rtc, MR, mr);
454405
455
- rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
456
- &at91_rtc_ops, THIS_MODULE);
406
+ rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev);
457407 if (IS_ERR(rtc->rtcdev)) {
458408 ret = PTR_ERR(rtc->rtcdev);
459409 goto err_clk;
460410 }
411
+
412
+ rtc->rtcdev->ops = &at91_rtc_ops;
413
+ rtc->rtcdev->range_max = U32_MAX;
461414
462415 /* register irq handler after we know what name we'll use */
463416 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt,
....@@ -476,9 +429,9 @@
476429
477430 if (gpbr_readl(rtc) == 0)
478431 dev_warn(&pdev->dev, "%s: SET TIME!\n",
479
- dev_name(&rtc->rtcdev->dev));
432
+ dev_name(&rtc->rtcdev->dev));
480433
481
- return 0;
434
+ return rtc_register_device(rtc->rtcdev);
482435
483436 err_clk:
484437 clk_disable_unprepare(rtc->sclk);
....@@ -536,8 +489,9 @@
536489 /* don't let RTTINC cause wakeups */
537490 if (mr & AT91_RTT_RTTINCIEN)
538491 rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN);
539
- } else
492
+ } else {
540493 rtt_writel(rtc, MR, mr & ~rtc->imr);
494
+ }
541495 }
542496
543497 return 0;
....@@ -569,13 +523,11 @@
569523
570524 static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
571525
572
-#ifdef CONFIG_OF
573526 static const struct of_device_id at91_rtc_dt_ids[] = {
574527 { .compatible = "atmel,at91sam9260-rtt" },
575528 { /* sentinel */ }
576529 };
577530 MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids);
578
-#endif
579531
580532 static struct platform_driver at91_rtc_driver = {
581533 .probe = at91_rtc_probe,