History

Merge tag 'rtc-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux

Pull RTC updates from Alexandre Belloni: "A huge series from me this cycle. I went through many drivers to set the date and time range supported by the RTC which helps solving HW limitation when the time comes (as early as next year for some). This time, I focused on drivers using .set_mms and .set_mmss64, allowing me to remove those callbacks. About a third of the patches got reviews, I actually own the RTCs and I tested another third and the remaining one are unlikely to cause any issues. Other than that, a single new driver and the usual fixes here and there. Summary: Subsystem: - set_mmss and set_mmss64 rtc_ops removal - Fix timestamp value for RTC_TIMESTAMP_BEGIN_1900 - Use SPDX identifier for the core - validate upper bound of tm->tm_year New driver: - Aspeed BMC SoC RTC Drivers: - abx80x: use rtc_add_group - ds3232: nvram support - pcf85063: add alarm, nvram, offset correction and microcrystal rv8263 support - x1205: add of_match_table - Use set_time instead of set_mms/set_mmss64 for: ab3100, coh901331, digicolor, ds1672, ds2404, ep93xx, imxdi, jz4740, lpc32xx, mc13xxx, mxc, pcap, stmp3xxx, test, wm831x, xgene. - Set RTC range for: ab3100, at91sam9, coh901331, da9063, digicolor, dm355evm, ds1672, ds2404, ep39xx, goldfish, imxdi, jz4740, lpc32xx, mc13xxx, mv, mxc, omap, pcap, pcf85063, pcf85363, ps3, sh, stmp3xxx, sun4v, tegra, wm831x, xgene. - Switch to rtc_time64_to_tm/rtc_tm_to_time64 for the driver that properly set the RTC range. - Use dev_get_drvdata instead of multiple indirections" * tag 'rtc-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (177 commits) rtc: snvs: Use __maybe_unused instead of #if CONFIG_PM_SLEEP rtc: imxdi: remove unused variable rtc: drop set_mms and set_mmss64 rtc: pcap: convert to SPDX identifier rtc: pcap: use .set_time rtc: pcap: switch to rtc_time64_to_tm/rtc_tm_to_time64 rtc: pcap: set range rtc: digicolor: convert to SPDX identifier rtc: digicolor: use .set_time rtc: digicolor: set range rtc: digicolor: fix possible race condition rtc: jz4740: convert to SPDX identifier rtc: jz4740: rework invalid time detection rtc: jz4740: use dev_pm_set_wake_irq() to simplify code rtc: jz4740: use .set_time rtc: jz4740: remove useless check rtc: jz4740: switch to rtc_time64_to_tm/rtc_tm_to_time64 rtc: jz4740: set range rtc: 88pm860x: prevent use-after-free on device remove rtc: Use dev_get_drvdata() ...

Linus Torvalds committed 7 years ago

Commit 8e4ff712 parents 45182e4 dacb6a467 files · +1400 −1510Browse files

Unified · Split

67 files
  1. Documentation/devicetree/bindings/rtc/nxp,pcf85063.txt +5 −1
  2. Documentation/devicetree/bindings/rtc/rtc-aspeed.txt +22 −0
  3. Documentation/devicetree/bindings/rtc/rtc.txt +1 −0
  4. drivers/rtc/Kconfig +15 −4
  5. drivers/rtc/Makefile +1 −0
  6. drivers/rtc/class.c +8 −13
  7. drivers/rtc/dev.c +10 −10
  8. drivers/rtc/hctosys.c +3 −7
  9. drivers/rtc/interface.c +51 −56
  10. drivers/rtc/lib.c +14 −16
  11. drivers/rtc/nvmem.c +2 −5
  12. drivers/rtc/proc.c +9 −12
  13. drivers/rtc/rtc-88pm80x.c +1 −13
  14. drivers/rtc/rtc-88pm860x.c +1 −1
  15. drivers/rtc/rtc-ab-b5ze-s3.c +63 −126
  16. drivers/rtc/rtc-ab3100.c +13 −11
  17. drivers/rtc/rtc-abx80x.c +7 −36
  18. drivers/rtc/rtc-aspeed.c +136 −0
  19. drivers/rtc/rtc-at91sam9.c +36 −72
  20. drivers/rtc/rtc-brcmstb-waketimer.c +1 −1
  21. drivers/rtc/rtc-coh901331.c +21 −16
  22. drivers/rtc/rtc-da9063.c +11 −16
  23. drivers/rtc/rtc-digicolor.c +12 −13
  24. drivers/rtc/rtc-dm355evm.c +10 −14
  25. drivers/rtc/rtc-ds1672.c +36 −91
  26. drivers/rtc/rtc-ds1685.c +107 −155
  27. drivers/rtc/rtc-ds2404.c +22 −51
  28. drivers/rtc/rtc-ds3232.c +38 −2
  29. drivers/rtc/rtc-ep93xx.c +25 −45
  30. drivers/rtc/rtc-goldfish.c +16 −34
  31. drivers/rtc/rtc-hid-sensor-time.c +1 −2
  32. drivers/rtc/rtc-imxdi.c +17 −33
  33. drivers/rtc/rtc-jz4740.c +33 −62
  34. drivers/rtc/rtc-lpc32xx.c +22 −37
  35. drivers/rtc/rtc-mc13xxx.c +15 −10
  36. drivers/rtc/rtc-mt6397.c +3 −6
  37. drivers/rtc/rtc-mv.c +17 −16
  38. drivers/rtc/rtc-mxc.c +36 −50
  39. drivers/rtc/rtc-mxc_v2.c +4 −25
  40. drivers/rtc/rtc-omap.c +9 −23
  41. drivers/rtc/rtc-opal.c +1 −1
  42. drivers/rtc/rtc-pcap.c +12 −16
  43. drivers/rtc/rtc-pcf85063.c +339 −107
  44. drivers/rtc/rtc-pcf85363.c +5 −15
  45. drivers/rtc/rtc-ps3.c +9 −21
  46. drivers/rtc/rtc-pxa.c +1 −2
  47. drivers/rtc/rtc-rk808.c +2 −4
  48. drivers/rtc/rtc-rx6110.c +9 −0
  49. drivers/rtc/rtc-rx8025.c +1 −1
  50. drivers/rtc/rtc-sh.c +18 −12
  51. drivers/rtc/rtc-sirfsoc.c +1 −1
  52. drivers/rtc/rtc-snvs.c +9 −39
  53. drivers/rtc/rtc-stm32.c +6 −3
  54. drivers/rtc/rtc-stmp3xxx.c +15 −19
  55. drivers/rtc/rtc-sun4v.c +8 −13
  56. drivers/rtc/rtc-tegra.c +19 −28
  57. drivers/rtc/rtc-test.c +6 −5
  58. drivers/rtc/rtc-tx4939.c +6 −11
  59. drivers/rtc/rtc-wm831x.c +28 −41
  60. drivers/rtc/rtc-wm8350.c +4 −8
  61. drivers/rtc/rtc-x1205.c +7 −0
  62. drivers/rtc/rtc-xgene.c +25 −36
  63. drivers/rtc/rtc-zynqmp.c +1 −12
  64. drivers/rtc/sysfs.c +9 −14
  65. drivers/rtc/systohc.c +2 −11
  66. include/linux/rtc.h +3 −3
  67. include/linux/rtc/ds1685.h +0 −2
Documentation/devicetree/bindings/rtc/nxp,pcf85063.txt+5−1
@@ -1,7 +1,11 @@
11 * NXP PCF85063 Real Time Clock
22
33 Required properties:
4−- compatible: Should contain "nxp,pcf85063".
4+- compatible: Should one of contain:
5+ "nxp,pcf85063",
6+ "nxp,pcf85063a",
7+ "nxp,pcf85063tp",
8+ "microcrystal,rv8263"
59 - reg: I2C address for chip.
610
711 Optional property:
Documentation/devicetree/bindings/rtc/rtc-aspeed.txt+22−0
@@ -0,0 +1,22 @@
1+ASPEED BMC RTC
2+==============
3+
4+Required properties:
5+ - compatible: should be one of the following
6+ * aspeed,ast2400-rtc for the ast2400
7+ * aspeed,ast2500-rtc for the ast2500
8+ * aspeed,ast2600-rtc for the ast2600
9+
10+ - reg: physical base address of the controller and length of memory mapped
11+ region
12+
13+ - interrupts: The interrupt number
14+
15+Example:
16+
17+ rtc@1e781000 {
18+ compatible = "aspeed,ast2400-rtc";
19+ reg = <0x1e781000 0x18>;
20+ interrupts = <22>;
21+ status = "disabled";
22+ };
Documentation/devicetree/bindings/rtc/rtc.txt+1−0
@@ -69,3 +69,4 @@ ricoh,rv5c386 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC · 68 unmodified lines
6969 ricoh,rv5c387a I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
7070 sii,s35390a 2-wire CMOS real-time clock
7171 whwave,sd3078 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
72+xircom,x1205 Xircom X1205 I2C RTC
drivers/rtc/Kconfig+15−4
@@ -439,6 +439,7 @@ config RTC_DRV_PCF8523 · 438 unmodified lines
439439
440440 config RTC_DRV_PCF85063
441441 tristate "NXP PCF85063"
442+ select REGMAP_I2C
442443 help
443444 If you say yes here you get support for the PCF85063 RTC chip
444445
@@ -447,7 +448,6 @@ config RTC_DRV_PCF85063 · 2 unmodified lines
447448
448449 config RTC_DRV_PCF85363
449450 tristate "NXP PCF85363"
450− depends on I2C
451451 select REGMAP_I2C
452452 help
453453 If you say yes here you get support for the PCF85363 RTC chip.
@@ -602,7 +602,6 @@ config RTC_DRV_FM3130 · 148 unmodified lines
602602
603603 config RTC_DRV_RX8010
604604 tristate "Epson RX8010SJ"
605− depends on I2C
606605 help
607606 If you say yes here you get support for the Epson RX8010SJ RTC
608607 chip.
@@ -1432,7 +1431,7 @@ config RTC_DRV_AT91RM9200 · 823 unmodified lines
14321431 config RTC_DRV_AT91SAM9
14331432 tristate "AT91SAM9 RTT as RTC"
14341433 depends on ARCH_AT91 || COMPILE_TEST
1435− depends on HAS_IOMEM
1434+ depends on OF && HAS_IOMEM
14361435 select MFD_SYSCON
14371436 help
14381437 Some AT91SAM9 SoCs provide an RTT (Real Time Timer) block which
@@ -1841,6 +1840,17 @@ config RTC_DRV_RTD119X · 402 unmodified lines
18411840 If you say yes here, you get support for the RTD1295 SoC
18421841 Real Time Clock.
18431842
1843+config RTC_DRV_ASPEED
1844+ tristate "ASPEED RTC"
1845+ depends on OF
1846+ depends on ARCH_ASPEED || COMPILE_TEST
1847+ help
1848+ If you say yes here you get support for the ASPEED BMC SoC real time
1849+ clocks.
1850+
1851+ This driver can also be built as a module, if so, the module
1852+ will be called "rtc-aspeed".
1853+
18441854 comment "HID Sensor RTC drivers"
18451855
18461856 config RTC_DRV_HID_SENSOR_TIME
@@ -1857,7 +1867,8 @@ config RTC_DRV_HID_SENSOR_TIME · 10 unmodified lines
18571867
18581868 config RTC_DRV_GOLDFISH
18591869 tristate "Goldfish Real Time Clock"
1860− depends on MIPS && (GOLDFISH || COMPILE_TEST)
1870+ depends on OF && HAS_IOMEM
1871+ depends on GOLDFISH || COMPILE_TEST
18611872 help
18621873 Say yes to enable RTC driver for the Goldfish based virtual platform.
18631874
drivers/rtc/Makefile+1−0
@@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_AC100) += rtc-ac100.o · 33 unmodified lines
3434 obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o
3535 obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o
3636 obj-$(CONFIG_RTC_DRV_ASM9260) += rtc-asm9260.o
37+obj-$(CONFIG_RTC_DRV_ASPEED) += rtc-aspeed.o
3738 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
3839 obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
3940 obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o
drivers/rtc/class.c+8−13
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * RTC subsystem, base class
34 *
@@ -5,11 +6,7 @@ · 1 unmodified line
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
67 *
78 * class skeleton from drivers/hwmon/hwmon.c
8− *
9− * This program is free software; you can redistribute it and/or modify
10− * it under the terms of the GNU General Public License version 2 as
11− * published by the Free Software Foundation.
12−*/
9+ */
1310
1411 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1512
@@ -23,13 +20,13 @@ · 7 unmodified lines
2320
2421 #include "rtc-core.h"
2522
26−
2723 static DEFINE_IDA(rtc_ida);
2824 struct class *rtc_class;
2925
3026 static void rtc_device_release(struct device *dev)
3127 {
3228 struct rtc_device *rtc = to_rtc_device(dev);
29+
3330 ida_simple_remove(&rtc_ida, rtc->id);
3431 kfree(rtc);
3532 }
@@ -47,7 +44,6 @@ int rtc_hctosys_ret = -ENODEV; · 11 unmodified lines
4744
4845 static struct timespec64 old_rtc, old_system, old_delta;
4946
50−
5147 static int rtc_suspend(struct device *dev)
5248 {
5349 struct rtc_device *rtc = to_rtc_device(dev);
@@ -71,7 +67,6 @@ static int rtc_suspend(struct device *dev) · 17 unmodified lines
7167 ktime_get_real_ts64(&old_system);
7268 old_rtc.tv_sec = rtc_tm_to_time64(&tm);
7369
74−
7570 /*
7671 * To avoid drift caused by repeated suspend/resumes,
7772 * which each can add ~1 second drift error,
@@ -83,7 +78,7 @@ static int rtc_suspend(struct device *dev) · 5 unmodified lines
8378 if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) {
8479 /*
8580 * if delta_delta is too large, assume time correction
86− * has occured and set old_delta to the current delta.
81+ * has occurred and set old_delta to the current delta.
8782 */
8883 old_delta = delta;
8984 } else {
@@ -136,7 +131,7 @@ static int rtc_resume(struct device *dev) · 46 unmodified lines
136131 * to keep things accurate.
137132 */
138133 sleep_time = timespec64_sub(sleep_time,
139− timespec64_sub(new_system, old_system));
134+ timespec64_sub(new_system, old_system));
140135
141136 if (sleep_time.tv_sec >= 0)
142137 timekeeping_inject_sleeptime64(&sleep_time);
@@ -397,9 +392,9 @@ EXPORT_SYMBOL_GPL(__rtc_register_device); · 254 unmodified lines
397392 * rtc_register_device instead
398393 */
399394 struct rtc_device *devm_rtc_device_register(struct device *dev,
400− const char *name,
401− const struct rtc_class_ops *ops,
402− struct module *owner)
395+ const char *name,
396+ const struct rtc_class_ops *ops,
397+ struct module *owner)
403398 {
404399 struct rtc_device *rtc;
405400 int err;
drivers/rtc/dev.c+10−10
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * RTC subsystem, dev interface
34 *
@@ -5,11 +6,7 @@ · 1 unmodified line
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
67 *
78 * based on arch/arm/common/rtctime.c
8− *
9− * This program is free software; you can redistribute it and/or modify
10− * it under the terms of the GNU General Public License version 2 as
11− * published by the Free Software Foundation.
12−*/
9+ */
1310
1411 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1512
@@ -60,7 +57,7 @@ static void rtc_uie_task(struct work_struct *work) · 44 unmodified lines
6057 } else if (rtc->oldsecs != tm.tm_sec) {
6158 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60;
6259 rtc->oldsecs = tm.tm_sec;
63− rtc->uie_timer.expires = jiffies + HZ - (HZ/10);
60+ rtc->uie_timer.expires = jiffies + HZ - (HZ / 10);
6461 rtc->uie_timer_active = 1;
6562 rtc->uie_task_active = 0;
6663 add_timer(&rtc->uie_timer);
@@ -71,6 +68,7 @@ static void rtc_uie_task(struct work_struct *work) · 4 unmodified lines
7168 if (num)
7269 rtc_handle_legacy_irq(rtc, num, RTC_UF);
7370 }
71+
7472 static void rtc_uie_timer(struct timer_list *t)
7573 {
7674 struct rtc_device *rtc = from_timer(rtc, t, uie_timer);
@@ -202,14 +200,14 @@ static __poll_t rtc_dev_poll(struct file *file, poll_table *wait) · 125 unmodified lines
202200 }
203201
204202 static long rtc_dev_ioctl(struct file *file,
205− unsigned int cmd, unsigned long arg)
203+ unsigned int cmd, unsigned long arg)
206204 {
207205 int err = 0;
208206 struct rtc_device *rtc = file->private_data;
209207 const struct rtc_class_ops *ops = rtc->ops;
210208 struct rtc_time tm;
211209 struct rtc_wkalrm alarm;
212− void __user *uarg = (void __user *) arg;
210+ void __user *uarg = (void __user *)arg;
213211
214212 err = mutex_lock_interruptible(&rtc->ops_lock);
215213 if (err)
@@ -233,7 +231,7 @@ static long rtc_dev_ioctl(struct file *file, · 17 unmodified lines
233231
234232 case RTC_PIE_ON:
235233 if (rtc->irq_freq > rtc->max_user_freq &&
236− !capable(CAP_SYS_RESOURCE))
234+ !capable(CAP_SYS_RESOURCE))
237235 err = -EACCES;
238236 break;
239237 }
@@ -390,8 +388,9 @@ static long rtc_dev_ioctl(struct file *file, · 150 unmodified lines
390388 err = ops->ioctl(rtc->dev.parent, cmd, arg);
391389 if (err == -ENOIOCTLCMD)
392390 err = -ENOTTY;
393− } else
391+ } else {
394392 err = -ENOTTY;
393+ }
395394 break;
396395 }
397396
@@ -403,6 +402,7 @@ done: · 5 unmodified lines
403402 static int rtc_dev_fasync(int fd, struct file *file, int on)
404403 {
405404 struct rtc_device *rtc = file->private_data;
405+
406406 return fasync_helper(fd, file, on, &rtc->async_queue);
407407 }
408408
drivers/rtc/hctosys.c+3−7
@@ -1,13 +1,10 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * RTC subsystem, initialize system time on startup
34 *
45 * Copyright (C) 2005 Tower Technologies
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
6− *
7− * This program is free software; you can redistribute it and/or modify
8− * it under the terms of the GNU General Public License version 2 as
9− * published by the Free Software Foundation.
10−*/
7+ */
118
129 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1310
@@ -33,7 +30,7 @@ static int __init rtc_hctosys(void) · 19 unmodified lines
3330 };
3431 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
3532
36− if (rtc == NULL) {
33+ if (!rtc) {
3734 pr_info("unable to open rtc device (%s)\n",
3835 CONFIG_RTC_HCTOSYS_DEVICE);
3936 goto err_open;
@@ -44,7 +41,6 @@ static int __init rtc_hctosys(void) · 4 unmodified lines
4441 dev_err(rtc->dev.parent,
4542 "hctosys: unable to read the hardware clock\n");
4643 goto err_read;
47−
4844 }
4945
5046 tv64.tv_sec = rtc_tm_to_time64(&tm);
drivers/rtc/interface.c+51−56
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * RTC subsystem, interface functions
34 *
@@ -5,11 +6,7 @@ · 1 unmodified line
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
67 *
78 * based on arch/arm/common/rtctime.c
8− *
9− * This program is free software; you can redistribute it and/or modify
10− * it under the terms of the GNU General Public License version 2 as
11− * published by the Free Software Foundation.
12−*/
9+ */
1310
1411 #include <linux/rtc.h>
1512 #include <linux/sched.h>
@@ -87,11 +84,12 @@ static int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm) · 71 unmodified lines
8784 static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
8885 {
8986 int err;
90− if (!rtc->ops)
87+
88+ if (!rtc->ops) {
9189 err = -ENODEV;
92− else if (!rtc->ops->read_time)
90+ } else if (!rtc->ops->read_time) {
9391 err = -EINVAL;
94− else {
92+ } else {
9593 memset(tm, 0, sizeof(struct rtc_time));
9694 err = rtc->ops->read_time(rtc->dev.parent, tm);
9795 if (err < 0) {
@@ -147,14 +145,7 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) · 49 unmodified lines
147145 err = -ENODEV;
148146 else if (rtc->ops->set_time)
149147 err = rtc->ops->set_time(rtc->dev.parent, tm);
150− else if (rtc->ops->set_mmss64) {
151− time64_t secs64 = rtc_tm_to_time64(tm);
152−
153− err = rtc->ops->set_mmss64(rtc->dev.parent, secs64);
154− } else if (rtc->ops->set_mmss) {
155− time64_t secs64 = rtc_tm_to_time64(tm);
156− err = rtc->ops->set_mmss(rtc->dev.parent, secs64);
157− } else
148+ else
158149 err = -EINVAL;
159150
160151 pm_stay_awake(rtc->dev.parent);
@@ -167,7 +158,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) · 6 unmodified lines
167158 }
168159 EXPORT_SYMBOL_GPL(rtc_set_time);
169160
170−static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
161+static int rtc_read_alarm_internal(struct rtc_device *rtc,
162+ struct rtc_wkalrm *alarm)
171163 {
172164 int err;
173165
@@ -175,11 +167,11 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm *al · 1 unmodified line
175167 if (err)
176168 return err;
177169
178− if (rtc->ops == NULL)
170+ if (!rtc->ops) {
179171 err = -ENODEV;
180− else if (!rtc->ops->read_alarm)
172+ } else if (!rtc->ops->read_alarm) {
181173 err = -EINVAL;
182− else {
174+ } else {
183175 alarm->enabled = 0;
184176 alarm->pending = 0;
185177 alarm->time.tm_sec = -1;
@@ -207,7 +199,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 21 unmodified lines
207199 int first_time = 1;
208200 time64_t t_now, t_alm;
209201 enum { none, day, month, year } missing = none;
210− unsigned days;
202+ unsigned int days;
211203
212204 /* The lower level RTC driver may return -1 in some fields,
213205 * creating invalid alarm->time values, for reasons like:
@@ -276,10 +268,10 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 62 unmodified lines
276268 return err;
277269
278270 /* note that tm_sec is a "don't care" value here: */
279− } while ( before.tm_min != now.tm_min
280− || before.tm_hour != now.tm_hour
281− || before.tm_mon != now.tm_mon
282− || before.tm_year != now.tm_year);
271+ } while (before.tm_min != now.tm_min ||
272+ before.tm_hour != now.tm_hour ||
273+ before.tm_mon != now.tm_mon ||
274+ before.tm_year != now.tm_year);
283275
284276 /* Fill in the missing alarm fields using the timestamp; we
285277 * know there's at least one since alarm->time is invalid.
@@ -296,7 +288,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 10 unmodified lines
296288 alarm->time.tm_mday = now.tm_mday;
297289 missing = day;
298290 }
299− if ((unsigned)alarm->time.tm_mon >= 12) {
291+ if ((unsigned int)alarm->time.tm_mon >= 12) {
300292 alarm->time.tm_mon = now.tm_mon;
301293 if (missing == none)
302294 missing = month;
@@ -321,7 +313,6 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 18 unmodified lines
321313 goto done;
322314
323315 switch (missing) {
324−
325316 /* 24 hour rollover ... if it's now 10am Monday, an alarm that
326317 * that will trigger at 5am will do so at 5am Tuesday, which
327318 * could also be in the next month or year. This is a common
@@ -341,14 +332,14 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 13 unmodified lines
341332 case month:
342333 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "month");
343334 do {
344− if (alarm->time.tm_mon < 11)
335+ if (alarm->time.tm_mon < 11) {
345336 alarm->time.tm_mon++;
346− else {
337+ } else {
347338 alarm->time.tm_mon = 0;
348339 alarm->time.tm_year++;
349340 }
350341 days = rtc_month_days(alarm->time.tm_mon,
351− alarm->time.tm_year);
342+ alarm->time.tm_year);
352343 } while (days < alarm->time.tm_mday);
353344 break;
354345
@@ -357,8 +348,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 2 unmodified lines
357348 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year");
358349 do {
359350 alarm->time.tm_year++;
360− } while (!is_leap_year(alarm->time.tm_year + 1900)
361− && rtc_valid_tm(&alarm->time) != 0);
351+ } while (!is_leap_year(alarm->time.tm_year + 1900) &&
352+ rtc_valid_tm(&alarm->time) != 0);
362353 break;
363354
364355 default:
@@ -369,7 +360,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 4 unmodified lines
369360
370361 done:
371362 if (err)
372− dev_warn(&rtc->dev, "invalid alarm value: %ptR\n", &alarm->time);
363+ dev_warn(&rtc->dev, "invalid alarm value: %ptR\n",
364+ &alarm->time);
373365
374366 return err;
375367 }
@@ -381,11 +373,11 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 5 unmodified lines
381373 err = mutex_lock_interruptible(&rtc->ops_lock);
382374 if (err)
383375 return err;
384− if (rtc->ops == NULL)
376+ if (!rtc->ops) {
385377 err = -ENODEV;
386− else if (!rtc->ops->read_alarm)
378+ } else if (!rtc->ops->read_alarm) {
387379 err = -EINVAL;
388− else {
380+ } else {
389381 memset(alarm, 0, sizeof(struct rtc_wkalrm));
390382 alarm->enabled = rtc->aie_timer.enabled;
391383 alarm->time = rtc_ktime_to_tm(rtc->aie_timer.node.expires);
@@ -494,7 +486,6 @@ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) · 102 unmodified lines
494486 /* Alarm has to be enabled & in the future for us to enqueue it */
495487 if (alarm->enabled && (rtc_tm_to_ktime(now) <
496488 rtc->aie_timer.node.expires)) {
497−
498489 rtc->aie_timer.enabled = 1;
499490 timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node);
500491 trace_rtc_timer_enqueue(&rtc->aie_timer);
@@ -506,7 +497,9 @@ EXPORT_SYMBOL_GPL(rtc_initialize_alarm); · 5 unmodified lines
506497
507498 int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled)
508499 {
509− int err = mutex_lock_interruptible(&rtc->ops_lock);
500+ int err;
501+
502+ err = mutex_lock_interruptible(&rtc->ops_lock);
510503 if (err)
511504 return err;
512505
@@ -535,7 +528,9 @@ EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable); · 22 unmodified lines
535528
536529 int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
537530 {
538− int err = mutex_lock_interruptible(&rtc->ops_lock);
531+ int err;
532+
533+ err = mutex_lock_interruptible(&rtc->ops_lock);
539534 if (err)
540535 return err;
541536
@@ -564,27 +559,25 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) · 22 unmodified lines
564559 rtc->uie_rtctimer.node.expires = ktime_add(now, onesec);
565560 rtc->uie_rtctimer.period = ktime_set(1, 0);
566561 err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer);
567− } else
562+ } else {
568563 rtc_timer_remove(rtc, &rtc->uie_rtctimer);
564+ }
569565
570566 out:
571567 mutex_unlock(&rtc->ops_lock);
572568 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
573569 /*
574− * Enable emulation if the driver did not provide
575− * the update_irq_enable function pointer or if returned
576− * -EINVAL to signal that it has been configured without
577− * interrupts or that are not available at the moment.
570+ * Enable emulation if the driver returned -EINVAL to signal that it has
571+ * been configured without interrupts or they are not available at the
572+ * moment.
578573 */
579574 if (err == -EINVAL)
580575 err = rtc_dev_update_irq_enable_emul(rtc, enabled);
581576 #endif
582577 return err;
583−
584578 }
585579 EXPORT_SYMBOL_GPL(rtc_update_irq_enable);
586580
587−
588581 /**
589582 * rtc_handle_legacy_irq - AIE, UIE and PIE event hook
590583 * @rtc: pointer to the rtc device
@@ -599,14 +592,13 @@ void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode) · 8 unmodified lines
599592
600593 /* mark one irq of the appropriate mode */
601594 spin_lock_irqsave(&rtc->irq_lock, flags);
602− rtc->irq_data = (rtc->irq_data + (num << 8)) | (RTC_IRQF|mode);
595+ rtc->irq_data = (rtc->irq_data + (num << 8)) | (RTC_IRQF | mode);
603596 spin_unlock_irqrestore(&rtc->irq_lock, flags);
604597
605598 wake_up_interruptible(&rtc->irq_queue);
606599 kill_fasync(&rtc->async_queue, SIGIO, POLL_IN);
607600 }
608601
609−
610602 /**
611603 * rtc_aie_update_irq - AIE mode rtctimer hook
612604 * @rtc: pointer to the rtc_device
@@ -618,7 +610,6 @@ void rtc_aie_update_irq(struct rtc_device *rtc) · 5 unmodified lines
618610 rtc_handle_legacy_irq(rtc, 1, RTC_AF);
619611 }
620612
621−
622613 /**
623614 * rtc_uie_update_irq - UIE mode rtctimer hook
624615 * @rtc: pointer to the rtc_device
@@ -630,7 +621,6 @@ void rtc_uie_update_irq(struct rtc_device *rtc) · 5 unmodified lines
630621 rtc_handle_legacy_irq(rtc, 1, RTC_UF);
631622 }
632623
633−
634624 /**
635625 * rtc_pie_update_irq - PIE mode hrtimer hook
636626 * @timer: pointer to the pie mode hrtimer
@@ -644,6 +634,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer) · 7 unmodified lines
644634 struct rtc_device *rtc;
645635 ktime_t period;
646636 int count;
637+
647638 rtc = container_of(timer, struct rtc_device, pie_timer);
648639
649640 period = NSEC_PER_SEC / rtc->irq_freq;
@@ -662,7 +653,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer) · 12 unmodified lines
662653 * Context: any
663654 */
664655 void rtc_update_irq(struct rtc_device *rtc,
665− unsigned long num, unsigned long events)
656+ unsigned long num, unsigned long events)
666657 {
667658 if (IS_ERR_OR_NULL(rtc))
668659 return;
@@ -811,6 +802,7 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) · 142 unmodified lines
811802 if (!next || ktime_before(timer->node.expires, next->expires)) {
812803 struct rtc_wkalrm alarm;
813804 int err;
805+
814806 alarm.time = rtc_ktime_to_tm(timer->node.expires);
815807 alarm.enabled = 1;
816808 err = __rtc_set_alarm(rtc, &alarm);
@@ -851,12 +843,14 @@ static void rtc_alarm_disable(struct rtc_device *rtc) · 34 unmodified lines
851843 static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer)
852844 {
853845 struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue);
846+
854847 timerqueue_del(&rtc->timerqueue, &timer->node);
855848 trace_rtc_timer_dequeue(timer);
856849 timer->enabled = 0;
857850 if (next == &timer->node) {
858851 struct rtc_wkalrm alarm;
859852 int err;
853+
860854 next = timerqueue_getnext(&rtc->timerqueue);
861855 if (!next) {
862856 rtc_alarm_disable(rtc);
@@ -929,9 +923,9 @@ again: · 66 unmodified lines
929923 alarm.enabled = 1;
930924 reprogram:
931925 err = __rtc_set_alarm(rtc, &alarm);
932− if (err == -ETIME)
926+ if (err == -ETIME) {
933927 goto again;
934− else if (err) {
928+ } else if (err) {
935929 if (retry-- > 0)
936930 goto reprogram;
937931
@@ -942,14 +936,14 @@ reprogram: · 4 unmodified lines
942936 dev_err(&rtc->dev, "__rtc_set_alarm: err=%d\n", err);
943937 goto again;
944938 }
945− } else
939+ } else {
946940 rtc_alarm_disable(rtc);
941+ }
947942
948943 pm_relax(rtc->dev.parent);
949944 mutex_unlock(&rtc->ops_lock);
950945 }
951946
952−
953947 /* rtc_timer_init - Initializes an rtc_timer
954948 * @timer: timer to be intiialized
955949 * @f: function pointer to be called when timer fires
@@ -975,9 +969,10 @@ void rtc_timer_init(struct rtc_timer *timer, void (*f)(struct rtc_device *r), · 19 unmodified lines
975969 * Kernel interface to set an rtc_timer
976970 */
977971 int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer,
978− ktime_t expires, ktime_t period)
972+ ktime_t expires, ktime_t period)
979973 {
980974 int ret = 0;
975+
981976 mutex_lock(&rtc->ops_lock);
982977 if (timer->enabled)
983978 rtc_timer_remove(rtc, timer);
drivers/rtc/lib.c+14−16
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * rtc and date/time utility functions
34 *
@@ -5,11 +6,7 @@ · 1 unmodified line
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
67 *
78 * based on arch/arm/common/rtctime.c and other bits
8− *
9− * This program is free software; you can redistribute it and/or modify
10− * it under the terms of the GNU General Public License version 2 as
11− * published by the Free Software Foundation.
12−*/
9+ */
1310
1411 #include <linux/export.h>
1512 #include <linux/rtc.h>
@@ -25,7 +22,7 @@ static const unsigned short rtc_ydays[2][13] = { · 9 unmodified lines
2522 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
2623 };
2724
28−#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
25+#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
2926
3027 /*
3128 * The number of days in the month.
@@ -41,11 +38,10 @@ EXPORT_SYMBOL(rtc_month_days); · 9 unmodified lines
4138 */
4239 int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
4340 {
44− return rtc_ydays[is_leap_year(year)][month] + day-1;
41+ return rtc_ydays[is_leap_year(year)][month] + day - 1;
4542 }
4643 EXPORT_SYMBOL(rtc_year_days);
4744
48−
4945 /*
5046 * rtc_time64_to_tm - Converts time64_t to rtc_time.
5147 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
@@ -97,13 +93,15 @@ EXPORT_SYMBOL(rtc_time64_to_tm); · 45 unmodified lines
9793 */
9894 int rtc_valid_tm(struct rtc_time *tm)
9995 {
100− if (tm->tm_year < 70
101− || ((unsigned)tm->tm_mon) >= 12
102− || tm->tm_mday < 1
103− || tm->tm_mday > rtc_month_days(tm->tm_mon, ((unsigned)tm->tm_year + 1900))
104− || ((unsigned)tm->tm_hour) >= 24
105− || ((unsigned)tm->tm_min) >= 60
106− || ((unsigned)tm->tm_sec) >= 60)
96+ if (tm->tm_year < 70 ||
97+ tm->tm_year > (INT_MAX - 1900) ||
98+ ((unsigned int)tm->tm_mon) >= 12 ||
99+ tm->tm_mday < 1 ||
100+ tm->tm_mday > rtc_month_days(tm->tm_mon,
101+ ((unsigned int)tm->tm_year + 1900)) ||
102+ ((unsigned int)tm->tm_hour) >= 24 ||
103+ ((unsigned int)tm->tm_min) >= 60 ||
104+ ((unsigned int)tm->tm_sec) >= 60)
107105 return -EINVAL;
108106
109107 return 0;
@@ -116,7 +114,7 @@ EXPORT_SYMBOL(rtc_valid_tm); · 6 unmodified lines
116114 */
117115 time64_t rtc_tm_to_time64(struct rtc_time *tm)
118116 {
119− return mktime64(((unsigned)tm->tm_year + 1900), tm->tm_mon + 1,
117+ return mktime64(((unsigned int)tm->tm_year + 1900), tm->tm_mon + 1,
120118 tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
121119 }
122120 EXPORT_SYMBOL(rtc_tm_to_time64);
drivers/rtc/nvmem.c+2−5
@@ -1,11 +1,8 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * RTC subsystem, nvmem interface
34 *
45 * Copyright (C) 2017 Alexandre Belloni
5− *
6− * This program is free software; you can redistribute it and/or modify
7− * it under the terms of the GNU General Public License version 2 as
8− * published by the Free Software Foundation.
96 */
107
118 #include <linux/err.h>
@@ -46,7 +43,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, · 34 unmodified lines
4643 {
4744 int err;
4845
49− rtc->nvram = kzalloc(sizeof(struct bin_attribute), GFP_KERNEL);
46+ rtc->nvram = kzalloc(sizeof(*rtc->nvram), GFP_KERNEL);
5047 if (!rtc->nvram)
5148 return -ENOMEM;
5249
drivers/rtc/proc.c+9−12
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * RTC subsystem, proc interface
34 *
@@ -5,11 +6,7 @@ · 1 unmodified line
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
67 *
78 * based on arch/arm/common/rtctime.c
8− *
9− * This program is free software; you can redistribute it and/or modify
10− * it under the terms of the GNU General Public License version 2 as
11− * published by the Free Software Foundation.
12−*/
9+ */
1310
1411 #include <linux/module.h>
1512 #include <linux/rtc.h>
@@ -60,17 +57,17 @@ static int rtc_proc_show(struct seq_file *seq, void *offset) · 44 unmodified lines
6057 seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
6158 seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
6259 seq_printf(seq, "alarm_IRQ\t: %s\n",
63− alrm.enabled ? "yes" : "no");
60+ alrm.enabled ? "yes" : "no");
6461 seq_printf(seq, "alrm_pending\t: %s\n",
65− alrm.pending ? "yes" : "no");
62+ alrm.pending ? "yes" : "no");
6663 seq_printf(seq, "update IRQ enabled\t: %s\n",
67− (rtc->uie_rtctimer.enabled) ? "yes" : "no");
64+ (rtc->uie_rtctimer.enabled) ? "yes" : "no");
6865 seq_printf(seq, "periodic IRQ enabled\t: %s\n",
69− (rtc->pie_enabled) ? "yes" : "no");
66+ (rtc->pie_enabled) ? "yes" : "no");
7067 seq_printf(seq, "periodic IRQ frequency\t: %d\n",
71− rtc->irq_freq);
68+ rtc->irq_freq);
7269 seq_printf(seq, "max user IRQ frequency\t: %d\n",
73− rtc->max_user_freq);
70+ rtc->max_user_freq);
7471 }
7572
7673 seq_printf(seq, "24hr\t\t: yes\n");
@@ -85,7 +82,7 @@ void rtc_proc_add_device(struct rtc_device *rtc) · 8 unmodified lines
8582 {
8683 if (is_rtc_hctosys(rtc))
8784 proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
88− rtc);
85+ rtc);
8986 }
9087
9188 void rtc_proc_del_device(struct rtc_device *rtc)
drivers/rtc/rtc-88pm80x.c+1−13
@@ -1,22 +1,10 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Real Time Clock driver for Marvell 88PM80x PMIC
34 *
45 * Copyright (c) 2012 Marvell International Ltd.
56 * Wenzeng Chen<wzch@marvell.com>
67 * Qiao Zhou <zhouqiao@marvell.com>
7− *
8− * This file is subject to the terms and conditions of the GNU General
9− * Public License. See the file "COPYING" in the main directory of this
10− * archive for more details.
11− *
12− * This program is distributed in the hope that it will be useful,
13− * but WITHOUT ANY WARRANTY; without even the implied warranty of
14− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15− * GNU General Public License for more details.
16− *
17− * You should have received a copy of the GNU General Public License
18− * along with this program; if not, write to the Free Software
19− * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
208 */
219
2210 #include <linux/kernel.h>
drivers/rtc/rtc-88pm860x.c+1−1
@@ -421,7 +421,7 @@ static int pm860x_rtc_remove(struct platform_device *pdev) · 420 unmodified lines
421421 struct pm860x_rtc_info *info = platform_get_drvdata(pdev);
422422
423423 #ifdef VRTC_CALIBRATION
424− flush_scheduled_work();
424+ cancel_delayed_work_sync(&info->calib_work);
425425 /* disable measurement */
426426 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
427427 #endif /* VRTC_CALIBRATION */
drivers/rtc/rtc-ab-b5ze-s3.c+63−126
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * rtc-ab-b5ze-s3 - Driver for Abracon AB-RTCMC-32.768Khz-B5ZE-S3
34 * I2C RTC / Alarm chip
@@ -10,19 +11,9 @@ · 6 unmodified lines
1011 *
1112 * This work is based on ISL12057 driver (drivers/rtc/rtc-isl12057.c).
1213 *
13− * This program is free software; you can redistribute it and/or modify
14− * it under the terms of the GNU General Public License as published by
15− * the Free Software Foundation; either version 2 of the License, or
16− * (at your option) any later version.
17− *
18− * This program is distributed in the hope that it will be useful,
19− * but WITHOUT ANY WARRANTY; without even the implied warranty of
20− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21− * GNU General Public License for more details.
2214 */
2315
2416 #include <linux/module.h>
25−#include <linux/mutex.h>
2617 #include <linux/rtc.h>
2718 #include <linux/i2c.h>
2819 #include <linux/bcd.h>
@@ -128,7 +119,6 @@ · 99 unmodified lines
128119 struct abb5zes3_rtc_data {
129120 struct rtc_device *rtc;
130121 struct regmap *regmap;
131− struct mutex lock;
132122
133123 int irq;
134124
@@ -138,8 +128,7 @@ struct abb5zes3_rtc_data { · 3 unmodified lines
138128
139129 /*
140130 * Try and match register bits w/ fixed null values to see whether we
141− * are dealing with an ABB5ZES3. Note: this function is called early
142− * during init and hence does need mutex protection.
131+ * are dealing with an ABB5ZES3.
143132 */
144133 static int abb5zes3_i2c_validate_chip(struct regmap *regmap)
145134 {
@@ -230,14 +219,12 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm) · 84 unmodified lines
230219 if (ret) {
231220 dev_err(dev, "%s: reading RTC time failed (%d)\n",
232221 __func__, ret);
233− goto err;
222+ return ret;
234223 }
235224
236225 /* If clock integrity is not guaranteed, do not return a time value */
237− if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC) {
238− ret = -ENODATA;
239− goto err;
240− }
226+ if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC)
227+ return -ENODATA;
241228
242229 tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F);
243230 tm->tm_min = bcd2bin(regs[ABB5ZES3_REG_RTC_MN]);
@@ -255,7 +242,6 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm) · 11 unmodified lines
255242 tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */
256243 tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100;
257244
258−err:
259245 return ret;
260246 }
261247
@@ -273,12 +259,9 @@ static int abb5zes3_rtc_set_time(struct device *dev, struct rtc_time *tm) · 11 unmodified lines
273259 regs[ABB5ZES3_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1);
274260 regs[ABB5ZES3_REG_RTC_YR] = bin2bcd(tm->tm_year - 100);
275261
276− mutex_lock(&data->lock);
277262 ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_RTC_SC,
278263 regs + ABB5ZES3_REG_RTC_SC,
279264 ABB5ZES3_RTC_SEC_LEN);
280− mutex_unlock(&data->lock);
281−
282265
283266 return ret;
284267 }
@@ -332,38 +315,35 @@ static int _abb5zes3_rtc_read_timer(struct device *dev, · 47 unmodified lines
332315 if (ret) {
333316 dev_err(dev, "%s: reading Timer A section failed (%d)\n",
334317 __func__, ret);
335− goto err;
318+ return ret;
336319 }
337320
338321 /* get current time ... */
339322 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
340323 if (ret)
341− goto err;
324+ return ret;
342325
343326 /* ... convert to seconds ... */
344− ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
345− if (ret)
346− goto err;
327+ rtc_secs = rtc_tm_to_time64(&rtc_tm);
347328
348329 /* ... add remaining timer A time ... */
349330 ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]);
350331 if (ret)
351− goto err;
332+ return ret;
352333
353334 /* ... and convert back. */
354− rtc_time_to_tm(rtc_secs + timer_secs, alarm_tm);
335+ rtc_time64_to_tm(rtc_secs + timer_secs, alarm_tm);
355336
356337 ret = regmap_read(data->regmap, ABB5ZES3_REG_CTRL2, &reg);
357338 if (ret) {
358339 dev_err(dev, "%s: reading ctrl reg failed (%d)\n",
359340 __func__, ret);
360− goto err;
341+ return ret;
361342 }
362343
363344 alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE);
364345
365−err:
366− return ret;
346+ return 0;
367347 }
368348
369349 /* Read alarm currently configured via a RTC alarm registers. */
@@ -382,7 +362,7 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, · 12 unmodified lines
382362 if (ret) {
383363 dev_err(dev, "%s: reading alarm section failed (%d)\n",
384364 __func__, ret);
385− goto err;
365+ return ret;
386366 }
387367
388368 alarm_tm->tm_sec = 0;
@@ -398,18 +378,13 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, · 9 unmodified lines
398378 */
399379 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
400380 if (ret)
401− goto err;
381+ return ret;
402382
403383 alarm_tm->tm_year = rtc_tm.tm_year;
404384 alarm_tm->tm_mon = rtc_tm.tm_mon;
405385
406− ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
407− if (ret)
408− goto err;
409−
410− ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
411− if (ret)
412− goto err;
386+ rtc_secs = rtc_tm_to_time64(&rtc_tm);
387+ alarm_secs = rtc_tm_to_time64(alarm_tm);
413388
414389 if (alarm_secs < rtc_secs) {
415390 if (alarm_tm->tm_mon == 11) {
@@ -424,13 +399,12 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, · 8 unmodified lines
424399 if (ret) {
425400 dev_err(dev, "%s: reading ctrl reg failed (%d)\n",
426401 __func__, ret);
427− goto err;
402+ return ret;
428403 }
429404
430405 alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE);
431406
432−err:
433− return ret;
407+ return 0;
434408 }
435409
436410 /*
@@ -447,12 +421,10 @@ static int abb5zes3_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 10 unmodified lines
447421 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
448422 int ret;
449423
450− mutex_lock(&data->lock);
451424 if (data->timer_alarm)
452425 ret = _abb5zes3_rtc_read_timer(dev, alarm);
453426 else
454427 ret = _abb5zes3_rtc_read_alarm(dev, alarm);
455− mutex_unlock(&data->lock);
456428
457429 return ret;
458430 }
@@ -466,33 +438,25 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 7 unmodified lines
466438 {
467439 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
468440 struct rtc_time *alarm_tm = &alarm->time;
469− unsigned long rtc_secs, alarm_secs;
470441 u8 regs[ABB5ZES3_ALRM_SEC_LEN];
471442 struct rtc_time rtc_tm;
472443 int ret, enable = 1;
473444
474− ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
475− if (ret)
476− goto err;
477−
478− ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
479− if (ret)
480− goto err;
481−
482− ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
483− if (ret)
484− goto err;
485−
486− /* If alarm time is before current time, disable the alarm */
487− if (!alarm->enabled || alarm_secs <= rtc_secs) {
445+ if (!alarm->enabled) {
488446 enable = 0;
489447 } else {
448+ unsigned long rtc_secs, alarm_secs;
449+
490450 /*
491451 * Chip only support alarms up to one month in the future. Let's
492452 * return an error if we get something after that limit.
493453 * Comparison is done by incrementing rtc_tm month field by one
494454 * and checking alarm value is still below.
495455 */
456+ ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
457+ if (ret)
458+ return ret;
459+
496460 if (rtc_tm.tm_mon == 11) { /* handle year wrapping */
497461 rtc_tm.tm_mon = 0;
498462 rtc_tm.tm_year += 1;
@@ -500,15 +464,13 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 1 unmodified line
500464 rtc_tm.tm_mon += 1;
501465 }
502466
503− ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
504− if (ret)
505− goto err;
467+ rtc_secs = rtc_tm_to_time64(&rtc_tm);
468+ alarm_secs = rtc_tm_to_time64(alarm_tm);
506469
507470 if (alarm_secs > rtc_secs) {
508− dev_err(dev, "%s: alarm maximum is one month in the "
509− "future (%d)\n", __func__, ret);
510− ret = -EINVAL;
511− goto err;
471+ dev_err(dev, "%s: alarm maximum is one month in the future (%d)\n",
472+ __func__, ret);
473+ return -EINVAL;
512474 }
513475 }
514476
@@ -526,17 +488,14 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 11 unmodified lines
526488 if (ret < 0) {
527489 dev_err(dev, "%s: writing ALARM section failed (%d)\n",
528490 __func__, ret);
529− goto err;
491+ return ret;
530492 }
531493
532494 /* Record currently configured alarm is not a timer */
533495 data->timer_alarm = 0;
534496
535497 /* Enable or disable alarm interrupt generation */
536− ret = _abb5zes3_rtc_update_alarm(dev, enable);
537−
538−err:
539− return ret;
498+ return _abb5zes3_rtc_update_alarm(dev, enable);
540499 }
541500
542501 /*
@@ -557,7 +516,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, · 14 unmodified lines
557516 ABB5ZES3_TIMA_SEC_LEN);
558517 if (ret < 0) {
559518 dev_err(dev, "%s: writing timer section failed\n", __func__);
560− goto err;
519+ return ret;
561520 }
562521
563522 /* Configure Timer A as a watchdog timer */
@@ -570,10 +529,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, · 6 unmodified lines
570529 data->timer_alarm = 1;
571530
572531 /* Enable or disable timer interrupt generation */
573− ret = _abb5zes3_rtc_update_timer(dev, alarm->enabled);
574−
575−err:
576− return ret;
532+ return _abb5zes3_rtc_update_timer(dev, alarm->enabled);
577533 }
578534
579535 /*
@@ -590,31 +546,25 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 10 unmodified lines
590546 struct rtc_time rtc_tm;
591547 int ret;
592548
593− mutex_lock(&data->lock);
594549 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
595550 if (ret)
596− goto err;
551+ return ret;
597552
598− ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
599− if (ret)
600− goto err;
601−
602− ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
603− if (ret)
604− goto err;
553+ rtc_secs = rtc_tm_to_time64(&rtc_tm);
554+ alarm_secs = rtc_tm_to_time64(alarm_tm);
605555
606556 /* Let's first disable both the alarm and the timer interrupts */
607557 ret = _abb5zes3_rtc_update_alarm(dev, false);
608558 if (ret < 0) {
609559 dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__,
610560 ret);
611− goto err;
561+ return ret;
612562 }
613563 ret = _abb5zes3_rtc_update_timer(dev, false);
614564 if (ret < 0) {
615565 dev_err(dev, "%s: unable to disable timer (%d)\n", __func__,
616566 ret);
617− goto err;
567+ return ret;
618568 }
619569
620570 data->timer_alarm = 0;
@@ -629,9 +579,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 8 unmodified lines
629579 else
630580 ret = _abb5zes3_rtc_set_alarm(dev, alarm);
631581
632− err:
633− mutex_unlock(&data->lock);
634−
635582 if (ret)
636583 dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__,
637584 ret);
@@ -650,8 +597,7 @@ static inline int _abb5zes3_rtc_battery_low_irq_enable(struct regmap *regmap, · 12 unmodified lines
650597
651598 /*
652599 * Check current RTC status and enable/disable what needs to be. Return 0 if
653− * everything went ok and a negative value upon error. Note: this function
654− * is called early during init and hence does need mutex protection.
600+ * everything went ok and a negative value upon error.
655601 */
656602 static int abb5zes3_rtc_check_setup(struct device *dev)
657603 {
@@ -675,8 +621,9 @@ static int abb5zes3_rtc_check_setup(struct device *dev) · 17 unmodified lines
675621 ABB5ZES3_REG_TIM_CLK_COF1 | ABB5ZES3_REG_TIM_CLK_COF2 |
676622 ABB5ZES3_REG_TIM_CLK_TBM | ABB5ZES3_REG_TIM_CLK_TAM);
677623 ret = regmap_update_bits(regmap, ABB5ZES3_REG_TIM_CLK, mask,
678− ABB5ZES3_REG_TIM_CLK_COF0 | ABB5ZES3_REG_TIM_CLK_COF1 |
679− ABB5ZES3_REG_TIM_CLK_COF2);
624+ ABB5ZES3_REG_TIM_CLK_COF0 |
625+ ABB5ZES3_REG_TIM_CLK_COF1 |
626+ ABB5ZES3_REG_TIM_CLK_COF2);
680627 if (ret < 0) {
681628 dev_err(dev, "%s: unable to initialize clkout register (%d)\n",
682629 __func__, ret);
@@ -729,9 +676,9 @@ static int abb5zes3_rtc_check_setup(struct device *dev) · 46 unmodified lines
729676 * switchover flag but not battery low flag. The latter is checked
730677 * later below.
731678 */
732− mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 |
733− ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE |
734− ABB5ZES3_REG_CTRL3_BSIE| ABB5ZES3_REG_CTRL3_BSF);
679+ mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 |
680+ ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE |
681+ ABB5ZES3_REG_CTRL3_BSIE | ABB5ZES3_REG_CTRL3_BSF);
735682 ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL3, mask, 0);
736683 if (ret < 0) {
737684 dev_err(dev, "%s: unable to initialize CTRL3 register (%d)\n",
@@ -748,10 +695,8 @@ static int abb5zes3_rtc_check_setup(struct device *dev) · 10 unmodified lines
748695 }
749696
750697 if (reg & ABB5ZES3_REG_RTC_SC_OSC) {
751− dev_err(dev, "clock integrity not guaranteed. Osc. has stopped "
752− "or has been interrupted.\n");
753− dev_err(dev, "change battery (if not already done) and "
754− "then set time to reset osc. failure flag.\n");
698+ dev_err(dev, "clock integrity not guaranteed. Osc. has stopped or has been interrupted.\n");
699+ dev_err(dev, "change battery (if not already done) and then set time to reset osc. failure flag.\n");
755700 }
756701
757702 /*
@@ -769,13 +714,12 @@ static int abb5zes3_rtc_check_setup(struct device *dev) · 11 unmodified lines
769714
770715 data->battery_low = reg & ABB5ZES3_REG_CTRL3_BLF;
771716 if (data->battery_low) {
772− dev_err(dev, "RTC battery is low; please, consider "
773− "changing it!\n");
717+ dev_err(dev, "RTC battery is low; please, consider changing it!\n");
774718
775719 ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, false);
776720 if (ret)
777− dev_err(dev, "%s: disabling battery low interrupt "
778− "generation failed (%d)\n", __func__, ret);
721+ dev_err(dev, "%s: disabling battery low interrupt generation failed (%d)\n",
722+ __func__, ret);
779723 }
780724
781725 return ret;
@@ -788,12 +732,10 @@ static int abb5zes3_rtc_alarm_irq_enable(struct device *dev, · 6 unmodified lines
788732 int ret = 0;
789733
790734 if (rtc_data->irq) {
791− mutex_lock(&rtc_data->lock);
792735 if (rtc_data->timer_alarm)
793736 ret = _abb5zes3_rtc_update_timer(dev, enable);
794737 else
795738 ret = _abb5zes3_rtc_update_alarm(dev, enable);
796− mutex_unlock(&rtc_data->lock);
797739 }
798740
799741 return ret;
@@ -885,49 +827,44 @@ static int abb5zes3_probe(struct i2c_client *client, · 85 unmodified lines
885827
886828 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
887829 I2C_FUNC_SMBUS_BYTE_DATA |
888− I2C_FUNC_SMBUS_I2C_BLOCK)) {
889− ret = -ENODEV;
890− goto err;
891− }
830+ I2C_FUNC_SMBUS_I2C_BLOCK))
831+ return -ENODEV;
892832
893833 regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config);
894834 if (IS_ERR(regmap)) {
895835 ret = PTR_ERR(regmap);
896836 dev_err(dev, "%s: regmap allocation failed: %d\n",
897837 __func__, ret);
898− goto err;
838+ return ret;
899839 }
900840
901841 ret = abb5zes3_i2c_validate_chip(regmap);
902842 if (ret)
903− goto err;
843+ return ret;
904844
905845 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
906− if (!data) {
907− ret = -ENOMEM;
908− goto err;
909− }
846+ if (!data)
847+ return -ENOMEM;
910848
911− mutex_init(&data->lock);
912849 data->regmap = regmap;
913850 dev_set_drvdata(dev, data);
914851
915852 ret = abb5zes3_rtc_check_setup(dev);
916853 if (ret)
917− goto err;
854+ return ret;
918855
919856 data->rtc = devm_rtc_allocate_device(dev);
920857 ret = PTR_ERR_OR_ZERO(data->rtc);
921858 if (ret) {
922859 dev_err(dev, "%s: unable to allocate RTC device (%d)\n",
923860 __func__, ret);
924− goto err;
861+ return ret;
925862 }
926863
927864 if (client->irq > 0) {
928865 ret = devm_request_threaded_irq(dev, client->irq, NULL,
929866 _abb5zes3_rtc_interrupt,
930− IRQF_SHARED|IRQF_ONESHOT,
867+ IRQF_SHARED | IRQF_ONESHOT,
931868 DRV_NAME, client);
932869 if (!ret) {
933870 device_init_wakeup(dev, true);
@@ -949,8 +886,8 @@ static int abb5zes3_probe(struct i2c_client *client, · 15 unmodified lines
949886 if (!data->battery_low && data->irq) {
950887 ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, true);
951888 if (ret) {
952− dev_err(dev, "%s: enabling battery low interrupt "
953− "generation failed (%d)\n", __func__, ret);
889+ dev_err(dev, "%s: enabling battery low interrupt generation failed (%d)\n",
890+ __func__, ret);
954891 goto err;
955892 }
956893 }
@@ -958,7 +895,7 @@ static int abb5zes3_probe(struct i2c_client *client, · 1 unmodified line
958895 ret = rtc_register_device(data->rtc);
959896
960897 err:
961− if (ret && data && data->irq)
898+ if (ret && data->irq)
962899 device_init_wakeup(dev, false);
963900 return ret;
964901 }
drivers/rtc/rtc-ab3100.c+13−11
@@ -1,6 +1,6 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Copyright (C) 2007-2009 ST-Ericsson AB
3− * License terms: GNU General Public License (GPL) version 2
44 * RTC clock driver for the AB3100 Analog Baseband Chip
55 * Author: Linus Walleij <linus.walleij@stericsson.com>
66 */
@@ -43,12 +43,12 @@ · 36 unmodified lines
4343 /*
4444 * RTC clock functions and device struct declaration
4545 */
46−static int ab3100_rtc_set_mmss(struct device *dev, time64_t secs)
46+static int ab3100_rtc_set_time(struct device *dev, struct rtc_time *tm)
4747 {
4848 u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2,
4949 AB3100_TI3, AB3100_TI4, AB3100_TI5};
5050 unsigned char buf[6];
51− u64 hw_counter = secs * AB3100_RTC_CLOCK_RATE * 2;
51+ u64 hw_counter = rtc_tm_to_time64(tm) * AB3100_RTC_CLOCK_RATE * 2;
5252 int err = 0;
5353 int i;
5454
@@ -192,7 +192,7 @@ static int ab3100_rtc_irq_enable(struct device *dev, unsigned int enabled) · 137 unmodified lines
192192
193193 static const struct rtc_class_ops ab3100_rtc_ops = {
194194 .read_time = ab3100_rtc_read_time,
195− .set_mmss64 = ab3100_rtc_set_mmss,
195+ .set_time = ab3100_rtc_set_time,
196196 .read_alarm = ab3100_rtc_read_alarm,
197197 .set_alarm = ab3100_rtc_set_alarm,
198198 .alarm_irq_enable = ab3100_rtc_irq_enable,
@@ -228,15 +228,17 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev) · 29 unmodified lines
228228 /* Ignore any error on this write */
229229 }
230230
231− rtc = devm_rtc_device_register(&pdev->dev, "ab3100-rtc",
232− &ab3100_rtc_ops, THIS_MODULE);
233− if (IS_ERR(rtc)) {
234− err = PTR_ERR(rtc);
235− return err;
236− }
231+ rtc = devm_rtc_allocate_device(&pdev->dev);
232+ if (IS_ERR(rtc))
233+ return PTR_ERR(rtc);
234+
235+ rtc->ops = &ab3100_rtc_ops;
236+ /* 48bit counter at (AB3100_RTC_CLOCK_RATE * 2) */
237+ rtc->range_max = U32_MAX;
238+
237239 platform_set_drvdata(pdev, rtc);
238240
239− return 0;
241+ return rtc_register_device(rtc);
240242 }
241243
242244 static struct platform_driver ab3100_rtc_driver = {
drivers/rtc/rtc-abx80x.c+7−36
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * A driver for the I2C members of the Abracon AB x8xx RTC family,
34 * and compatible: AB 1805 and AB 0805
@@ -7,10 +8,6 @@ · 3 unmodified lines
78 * Author: Philippe De Muyter <phdm@macqel.be>
89 * Author: Alexandre Belloni <alexandre.belloni@bootlin.com>
910 *
10− * This program is free software; you can redistribute it and/or modify
11− * it under the terms of the GNU General Public License version 2 as
12− * published by the Free Software Foundation.
13− *
1411 */
1512
1613 #include <linux/bcd.h>
@@ -404,7 +401,7 @@ static ssize_t autocalibration_store(struct device *dev, · 387 unmodified lines
404401 return -EINVAL;
405402 }
406403
407− retval = abx80x_rtc_set_autocalibration(dev, autocalibration);
404+ retval = abx80x_rtc_set_autocalibration(dev->parent, autocalibration);
408405
409406 return retval ? retval : count;
410407 }
@@ -414,7 +411,7 @@ static ssize_t autocalibration_show(struct device *dev, · 3 unmodified lines
414411 {
415412 int autocalibration = 0;
416413
417− autocalibration = abx80x_rtc_get_autocalibration(dev);
414+ autocalibration = abx80x_rtc_get_autocalibration(dev->parent);
418415 if (autocalibration < 0) {
419416 dev_err(dev, "Failed to read RTC autocalibration\n");
420417 sprintf(buf, "0\n");
@@ -430,7 +427,7 @@ static ssize_t oscillator_store(struct device *dev, · 9 unmodified lines
430427 struct device_attribute *attr,
431428 const char *buf, size_t count)
432429 {
433− struct i2c_client *client = to_i2c_client(dev);
430+ struct i2c_client *client = to_i2c_client(dev->parent);
434431 int retval, flags, rc_mode = 0;
435432
436433 if (strncmp(buf, "rc", 2) == 0) {
@@ -472,7 +469,7 @@ static ssize_t oscillator_show(struct device *dev, · 35 unmodified lines
472469 struct device_attribute *attr, char *buf)
473470 {
474471 int rc_mode = 0;
475− struct i2c_client *client = to_i2c_client(dev);
472+ struct i2c_client *client = to_i2c_client(dev->parent);
476473
477474 rc_mode = abx80x_is_rc_mode(client);
478475
@@ -592,13 +589,6 @@ static int abx80x_dt_trickle_cfg(struct device_node *np) · 113 unmodified lines
592589 return (trickle_cfg | i);
593590 }
594591
595−static void rtc_calib_remove_sysfs_group(void *_dev)
596−{
597− struct device *dev = _dev;
598−
599− sysfs_remove_group(&dev->kobj, &rtc_calib_attr_group);
600−}
601−
602592 #ifdef CONFIG_WATCHDOG
603593
604594 static inline u8 timeout_bits(unsigned int timeout)
@@ -851,32 +841,14 @@ static int abx80x_probe(struct i2c_client *client, · 246 unmodified lines
851841 }
852842 }
853843
854− /* Export sysfs entries */
855− err = sysfs_create_group(&(&client->dev)->kobj, &rtc_calib_attr_group);
844+ err = rtc_add_group(priv->rtc, &rtc_calib_attr_group);
856845 if (err) {
857846 dev_err(&client->dev, "Failed to create sysfs group: %d\n",
858847 err);
859848 return err;
860849 }
861850
862− err = devm_add_action_or_reset(&client->dev,
863− rtc_calib_remove_sysfs_group,
864− &client->dev);
865− if (err) {
866− dev_err(&client->dev,
867− "Failed to add sysfs cleanup action: %d\n",
868− err);
869− return err;
870− }
871−
872− err = rtc_register_device(priv->rtc);
873−
874− return err;
875−}
876−
877−static int abx80x_remove(struct i2c_client *client)
878−{
879− return 0;
851+ return rtc_register_device(priv->rtc);
880852 }
881853
882854 static const struct i2c_device_id abx80x_id[] = {
@@ -899,7 +871,6 @@ static struct i2c_driver abx80x_driver = { · 16 unmodified lines
899871 .name = "rtc-abx80x",
900872 },
901873 .probe = abx80x_probe,
902− .remove = abx80x_remove,
903874 .id_table = abx80x_id,
904875 };
905876
drivers/rtc/rtc-aspeed.c+136−0
@@ -0,0 +1,136 @@
1+// SPDX-License-Identifier: GPL-2.0+
2+// Copyright 2015 IBM Corp.
3+
4+#include <linux/module.h>
5+#include <linux/of.h>
6+#include <linux/platform_device.h>
7+#include <linux/rtc.h>
8+#include <linux/io.h>
9+
10+struct aspeed_rtc {
11+ struct rtc_device *rtc_dev;
12+ void __iomem *base;
13+};
14+
15+#define RTC_TIME 0x00
16+#define RTC_YEAR 0x04
17+#define RTC_CTRL 0x10
18+
19+#define RTC_UNLOCK BIT(1)
20+#define RTC_ENABLE BIT(0)
21+
22+static int aspeed_rtc_read_time(struct device *dev, struct rtc_time *tm)
23+{
24+ struct aspeed_rtc *rtc = dev_get_drvdata(dev);
25+ unsigned int cent, year;
26+ u32 reg1, reg2;
27+
28+ if (!(readl(rtc->base + RTC_CTRL) & RTC_ENABLE)) {
29+ dev_dbg(dev, "%s failing as rtc disabled\n", __func__);
30+ return -EINVAL;
31+ }
32+
33+ do {
34+ reg2 = readl(rtc->base + RTC_YEAR);
35+ reg1 = readl(rtc->base + RTC_TIME);
36+ } while (reg2 != readl(rtc->base + RTC_YEAR));
37+
38+ tm->tm_mday = (reg1 >> 24) & 0x1f;
39+ tm->tm_hour = (reg1 >> 16) & 0x1f;
40+ tm->tm_min = (reg1 >> 8) & 0x3f;
41+ tm->tm_sec = (reg1 >> 0) & 0x3f;
42+
43+ cent = (reg2 >> 16) & 0x1f;
44+ year = (reg2 >> 8) & 0x7f;
45+ tm->tm_mon = ((reg2 >> 0) & 0x0f) - 1;
46+ tm->tm_year = year + (cent * 100) - 1900;
47+
48+ dev_dbg(dev, "%s %ptR", __func__, tm);
49+
50+ return 0;
51+}
52+
53+static int aspeed_rtc_set_time(struct device *dev, struct rtc_time *tm)
54+{
55+ struct aspeed_rtc *rtc = dev_get_drvdata(dev);
56+ u32 reg1, reg2, ctrl;
57+ int year, cent;
58+
59+ cent = (tm->tm_year + 1900) / 100;
60+ year = tm->tm_year % 100;
61+
62+ reg1 = (tm->tm_mday << 24) | (tm->tm_hour << 16) | (tm->tm_min << 8) |
63+ tm->tm_sec;
64+
65+ reg2 = ((cent & 0x1f) << 16) | ((year & 0x7f) << 8) |
66+ ((tm->tm_mon + 1) & 0xf);
67+
68+ ctrl = readl(rtc->base + RTC_CTRL);
69+ writel(ctrl | RTC_UNLOCK, rtc->base + RTC_CTRL);
70+
71+ writel(reg1, rtc->base + RTC_TIME);
72+ writel(reg2, rtc->base + RTC_YEAR);
73+
74+ /* Re-lock and ensure enable is set now that a time is programmed */
75+ writel(ctrl | RTC_ENABLE, rtc->base + RTC_CTRL);
76+
77+ return 0;
78+}
79+
80+static const struct rtc_class_ops aspeed_rtc_ops = {
81+ .read_time = aspeed_rtc_read_time,
82+ .set_time = aspeed_rtc_set_time,
83+};
84+
85+static int aspeed_rtc_probe(struct platform_device *pdev)
86+{
87+ struct aspeed_rtc *rtc;
88+ struct resource *res;
89+ int ret;
90+
91+ rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
92+ if (!rtc)
93+ return -ENOMEM;
94+
95+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
96+ rtc->base = devm_ioremap_resource(&pdev->dev, res);
97+ if (IS_ERR(rtc->base))
98+ return PTR_ERR(rtc->base);
99+
100+ rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
101+ if (IS_ERR(rtc->rtc_dev))
102+ return PTR_ERR(rtc->rtc_dev);
103+
104+ platform_set_drvdata(pdev, rtc);
105+
106+ rtc->rtc_dev->ops = &aspeed_rtc_ops;
107+ rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
108+ rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */
109+
110+ ret = rtc_register_device(rtc->rtc_dev);
111+ if (ret)
112+ return ret;
113+
114+ return 0;
115+}
116+
117+static const struct of_device_id aspeed_rtc_match[] = {
118+ { .compatible = "aspeed,ast2400-rtc", },
119+ { .compatible = "aspeed,ast2500-rtc", },
120+ { .compatible = "aspeed,ast2600-rtc", },
121+ {}
122+};
123+MODULE_DEVICE_TABLE(of, aspeed_rtc_match);
124+
125+static struct platform_driver aspeed_rtc_driver = {
126+ .driver = {
127+ .name = "aspeed-rtc",
128+ .of_match_table = of_match_ptr(aspeed_rtc_match),
129+ },
130+};
131+
132+module_platform_driver_probe(aspeed_rtc_driver, aspeed_rtc_probe);
133+
134+MODULE_DESCRIPTION("ASPEED RTC driver");
135+MODULE_AUTHOR("Joel Stanley <joel@jms.id.au>");
136+MODULE_LICENSE("GPL");
drivers/rtc/rtc-at91sam9.c+36−72
@@ -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 @@ · 32 unmodified lines
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 @@ · 1 unmodified line
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,7 +117,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm) · 39 unmodified lines
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
127122 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
128123
@@ -135,15 +130,12 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm) · 6 unmodified lines
135130 static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
136131 {
137132 struct sam9_rtc *rtc = dev_get_drvdata(dev);
138− int err;
139133 u32 offset, alarm, mr;
140134 unsigned long secs;
141135
142136 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
143137
144− err = rtc_tm_to_time(tm, &secs);
145− if (err != 0)
146− return err;
138+ secs = rtc_tm_to_time64(tm);
147139
148140 mr = rtt_readl(rtc, MR);
149141
@@ -193,7 +185,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) · 43 unmodified lines
193185
194186 memset(alrm, 0, sizeof(*alrm));
195187 if (alarm != ALARM_DISABLED && offset != 0) {
196− rtc_time_to_tm(offset + alarm, tm);
188+ rtc_time64_to_tm(offset + alarm, tm);
197189
198190 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
199191
@@ -211,11 +203,8 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) · 11 unmodified lines
211203 unsigned long secs;
212204 u32 offset;
213205 u32 mr;
214− int err;
215206
216− err = rtc_tm_to_time(tm, &secs);
217− if (err != 0)
218− return err;
207+ secs = rtc_tm_to_time64(tm);
219208
220209 offset = gpbr_readl(rtc);
221210 if (offset == 0) {
@@ -263,7 +252,7 @@ static int at91_rtc_proc(struct device *dev, struct seq_file *seq) · 41 unmodified lines
263252 u32 mr = rtt_readl(rtc, MR);
264253
265254 seq_printf(seq, "update_IRQ\t: %s\n",
266− (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no");
255+ (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no");
267256 return 0;
268257 }
269258
@@ -299,7 +288,7 @@ static void at91_rtc_flush_events(struct sam9_rtc *rtc) · 29 unmodified lines
299288 rtc->events = 0;
300289
301290 pr_debug("%s: num=%ld, events=0x%02lx\n", __func__,
302− rtc->events >> 8, rtc->events & 0x000000FF);
291+ rtc->events >> 8, rtc->events & 0x000000FF);
303292 }
304293
305294 /*
@@ -340,13 +329,6 @@ static const struct rtc_class_ops at91_rtc_ops = { · 34 unmodified lines
340329 .alarm_irq_enable = at91_rtc_alarm_irq_enable,
341330 };
342331
343−static const struct regmap_config gpbr_regmap_config = {
344− .name = "gpbr",
345− .reg_bits = 32,
346− .val_bits = 32,
347− .reg_stride = 4,
348−};
349−
350332 /*
351333 * Initialize and install RTC driver
352334 */
@@ -357,6 +339,7 @@ static int at91_rtc_probe(struct platform_device *pdev) · 4 unmodified lines
357339 int ret, irq;
358340 u32 mr;
359341 unsigned int sclk_rate;
342+ struct of_phandle_args args;
360343
361344 irq = platform_get_irq(pdev, 0);
362345 if (irq < 0) {
@@ -382,34 +365,14 @@ static int at91_rtc_probe(struct platform_device *pdev) · 19 unmodified lines
382365 if (IS_ERR(rtc->rtt))
383366 return PTR_ERR(rtc->rtt);
384367
385− if (!pdev->dev.of_node) {
386− /*
387− * TODO: Remove this code chunk when removing non DT board
388− * support. Remember to remove the gpbr_regmap_config
389− * variable too.
390− */
391− void __iomem *gpbr;
392−
393− r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
394− gpbr = devm_ioremap_resource(&pdev->dev, r);
395− if (IS_ERR(gpbr))
396− return PTR_ERR(gpbr);
397−
398− rtc->gpbr = regmap_init_mmio(NULL, gpbr,
399− &gpbr_regmap_config);
400− } else {
401− struct of_phandle_args args;
402−
403− ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
404− "atmel,rtt-rtc-time-reg", 1, 0,
405− &args);
406− if (ret)
407− return ret;
408−
409− rtc->gpbr = syscon_node_to_regmap(args.np);
410− rtc->gpbr_offset = args.args[0];
411− }
368+ ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
369+ "atmel,rtt-rtc-time-reg", 1, 0,
370+ &args);
371+ if (ret)
372+ return ret;
412373
374+ rtc->gpbr = syscon_node_to_regmap(args.np);
375+ rtc->gpbr_offset = args.args[0];
413376 if (IS_ERR(rtc->gpbr)) {
414377 dev_err(&pdev->dev, "failed to retrieve gpbr regmap, aborting.\n");
415378 return -ENOMEM;
@@ -444,13 +407,15 @@ static int at91_rtc_probe(struct platform_device *pdev) · 28 unmodified lines
444407 mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
445408 rtt_writel(rtc, MR, mr);
446409
447− rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
448− &at91_rtc_ops, THIS_MODULE);
410+ rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev);
449411 if (IS_ERR(rtc->rtcdev)) {
450412 ret = PTR_ERR(rtc->rtcdev);
451413 goto err_clk;
452414 }
453415
416+ rtc->rtcdev->ops = &at91_rtc_ops;
417+ rtc->rtcdev->range_max = U32_MAX;
418+
454419 /* register irq handler after we know what name we'll use */
455420 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt,
456421 IRQF_SHARED | IRQF_COND_SUSPEND,
@@ -468,9 +433,9 @@ static int at91_rtc_probe(struct platform_device *pdev) · 11 unmodified lines
468433
469434 if (gpbr_readl(rtc) == 0)
470435 dev_warn(&pdev->dev, "%s: SET TIME!\n",
471− dev_name(&rtc->rtcdev->dev));
436+ dev_name(&rtc->rtcdev->dev));
472437
473− return 0;
438+ return rtc_register_device(rtc->rtcdev);
474439
475440 err_clk:
476441 clk_disable_unprepare(rtc->sclk);
@@ -528,8 +493,9 @@ static int at91_rtc_suspend(struct device *dev) · 51 unmodified lines
528493 /* don't let RTTINC cause wakeups */
529494 if (mr & AT91_RTT_RTTINCIEN)
530495 rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN);
531− } else
496+ } else {
532497 rtt_writel(rtc, MR, mr & ~rtc->imr);
498+ }
533499 }
534500
535501 return 0;
@@ -561,13 +527,11 @@ static int at91_rtc_resume(struct device *dev) · 25 unmodified lines
561527
562528 static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
563529
564−#ifdef CONFIG_OF
565530 static const struct of_device_id at91_rtc_dt_ids[] = {
566531 { .compatible = "atmel,at91sam9260-rtt" },
567532 { /* sentinel */ }
568533 };
569534 MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids);
570−#endif
571535
572536 static struct platform_driver at91_rtc_driver = {
573537 .probe = at91_rtc_probe,
drivers/rtc/rtc-brcmstb-waketimer.c+1−1
@@ -132,7 +132,7 @@ static int brcmstb_waketmr_gettime(struct device *dev, · 131 unmodified lines
132132
133133 wktmr_read(timer, &now);
134134
135− rtc_time_to_tm(now.sec, tm);
135+ rtc_time64_to_tm(now.sec, tm);
136136
137137 return 0;
138138 }
drivers/rtc/rtc-coh901331.c+21−16
@@ -1,6 +1,6 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Copyright (C) 2007-2009 ST-Ericsson AB
3− * License terms: GNU General Public License (GPL) version 2
44 * Real Time Clock interface for ST-Ericsson AB COH 901 331 RTC.
55 * Author: Linus Walleij <linus.walleij@stericsson.com>
66 * Based on rtc-pl031.c by Deepak Saxena <dsaxena@plexity.net>
@@ -80,21 +80,22 @@ static int coh901331_read_time(struct device *dev, struct rtc_time *tm) · 73 unmodified lines
8080
8181 clk_enable(rtap->clk);
8282 /* Check if the time is valid */
83− if (readl(rtap->virtbase + COH901331_VALID)) {
84− rtc_time_to_tm(readl(rtap->virtbase + COH901331_CUR_TIME), tm);
83+ if (!readl(rtap->virtbase + COH901331_VALID)) {
8584 clk_disable(rtap->clk);
86− return 0;
85+ return -EINVAL;
8786 }
87+
88+ rtc_time64_to_tm(readl(rtap->virtbase + COH901331_CUR_TIME), tm);
8889 clk_disable(rtap->clk);
89− return -EINVAL;
90+ return 0;
9091 }
9192
92−static int coh901331_set_mmss(struct device *dev, unsigned long secs)
93+static int coh901331_set_time(struct device *dev, struct rtc_time *tm)
9394 {
9495 struct coh901331_port *rtap = dev_get_drvdata(dev);
9596
9697 clk_enable(rtap->clk);
97− writel(secs, rtap->virtbase + COH901331_SET_TIME);
98+ writel(rtc_tm_to_time64(tm), rtap->virtbase + COH901331_SET_TIME);
9899 clk_disable(rtap->clk);
99100
100101 return 0;
@@ -105,7 +106,7 @@ static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 4 unmodified lines
105106 struct coh901331_port *rtap = dev_get_drvdata(dev);
106107
107108 clk_enable(rtap->clk);
108− rtc_time_to_tm(readl(rtap->virtbase + COH901331_ALARM), &alarm->time);
109+ rtc_time64_to_tm(readl(rtap->virtbase + COH901331_ALARM), &alarm->time);
109110 alarm->pending = readl(rtap->virtbase + COH901331_IRQ_EVENT) & 1U;
110111 alarm->enabled = readl(rtap->virtbase + COH901331_IRQ_MASK) & 1U;
111112 clk_disable(rtap->clk);
@@ -116,9 +117,8 @@ static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 4 unmodified lines
116117 static int coh901331_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
117118 {
118119 struct coh901331_port *rtap = dev_get_drvdata(dev);
119− unsigned long time;
120+ unsigned long time = rtc_tm_to_time64(&alarm->time);
120121
121− rtc_tm_to_time(&alarm->time, &time);
122122 clk_enable(rtap->clk);
123123 writel(time, rtap->virtbase + COH901331_ALARM);
124124 writel(alarm->enabled, rtap->virtbase + COH901331_IRQ_MASK);
@@ -143,7 +143,7 @@ static int coh901331_alarm_irq_enable(struct device *dev, unsigned int enabled) · 18 unmodified lines
143143
144144 static const struct rtc_class_ops coh901331_ops = {
145145 .read_time = coh901331_read_time,
146− .set_mmss = coh901331_set_mmss,
146+ .set_time = coh901331_set_time,
147147 .read_alarm = coh901331_read_alarm,
148148 .set_alarm = coh901331_set_alarm,
149149 .alarm_irq_enable = coh901331_alarm_irq_enable,
@@ -188,6 +188,13 @@ static int __init coh901331_probe(struct platform_device *pdev) · 38 unmodified lines
188188 return ret;
189189 }
190190
191+ rtap->rtc = devm_rtc_allocate_device(&pdev->dev);
192+ if (IS_ERR(rtap->rtc))
193+ return PTR_ERR(rtap->rtc);
194+
195+ rtap->rtc->ops = &coh901331_ops;
196+ rtap->rtc->range_max = U32_MAX;
197+
191198 /* We enable/disable the clock only to assure it works */
192199 ret = clk_prepare_enable(rtap->clk);
193200 if (ret) {
@@ -197,12 +204,10 @@ static int __init coh901331_probe(struct platform_device *pdev) · 3 unmodified lines
197204 clk_disable(rtap->clk);
198205
199206 platform_set_drvdata(pdev, rtap);
200− rtap->rtc = devm_rtc_device_register(&pdev->dev, "coh901331",
201− &coh901331_ops, THIS_MODULE);
202− if (IS_ERR(rtap->rtc)) {
203− ret = PTR_ERR(rtap->rtc);
207+
208+ ret = rtc_register_device(rtap->rtc);
209+ if (ret)
204210 goto out_no_rtc;
205− }
206211
207212 return 0;
208213
drivers/rtc/rtc-da9063.c+11−16
@@ -1,15 +1,7 @@
1−/* rtc-da9063.c - Real time clock device driver for DA9063
1+// SPDX-License-Identifier: GPL-2.0+
2+/*
3+ * Real time clock device driver for DA9063
24 * Copyright (C) 2013-2015 Dialog Semiconductor Ltd.
3− *
4− * This program is free software; you can redistribute it and/or
5− * modify it under the terms of the GNU General Public License
6− * as published by the Free Software Foundation; either version 2
7− * of the License, or (at your option) any later version.
8− *
9− * This program is distributed in the hope that it will be useful,
10− * but WITHOUT ANY WARRANTY; without even the implied warranty of
11− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12− * GNU General Public License for more details.
135 */
146
157 #include <linux/delay.h>
@@ -247,8 +239,8 @@ static int da9063_rtc_read_time(struct device *dev, struct rtc_time *tm) · 231 unmodified lines
247239
248240 da9063_data_to_tm(data, tm, rtc);
249241
250− rtc_tm_to_time(tm, &tm_secs);
251− rtc_tm_to_time(&rtc->alarm_time, &al_secs);
242+ tm_secs = rtc_tm_to_time64(tm);
243+ al_secs = rtc_tm_to_time64(&rtc->alarm_time);
252244
253245 /* handle the rtc synchronisation delay */
254246 if (rtc->rtc_sync == true && al_secs - tm_secs == 1)
@@ -472,11 +464,14 @@ static int da9063_rtc_probe(struct platform_device *pdev) · 217 unmodified lines
472464
473465 platform_set_drvdata(pdev, rtc);
474466
475− rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, DA9063_DRVNAME_RTC,
476− &da9063_rtc_ops, THIS_MODULE);
467+ rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
477468 if (IS_ERR(rtc->rtc_dev))
478469 return PTR_ERR(rtc->rtc_dev);
479470
471+ rtc->rtc_dev->ops = &da9063_rtc_ops;
472+ rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000;
473+ rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_2063;
474+
480475 da9063_data_to_tm(data, &rtc->alarm_time, rtc);
481476 rtc->rtc_sync = false;
482477
@@ -496,7 +491,7 @@ static int da9063_rtc_probe(struct platform_device *pdev) · 13 unmodified lines
496491 dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n",
497492 irq_alarm, ret);
498493
499− return ret;
494+ return rtc_register_device(rtc->rtc_dev);
500495 }
501496
502497 static struct platform_driver da9063_rtc_driver = {
drivers/rtc/rtc-digicolor.c+12−13
@@ -1,14 +1,10 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Real Time Clock driver for Conexant Digicolor
34 *
45 * Copyright (C) 2015 Paradox Innovation Ltd.
56 *
67 * Author: Baruch Siach <baruch@tkos.co.il>
7− *
8− * This program is free software; you can redistribute it and/or modify it
9− * under the terms of the GNU General Public License as published by the
10− * Free Software Foundation; either version 2 of the License, or (at your
11− * option) any later version.
128 */
139
1410 #include <linux/io.h>
@@ -106,11 +102,11 @@ static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm) · 91 unmodified lines
106102 return 0;
107103 }
108104
109−static int dc_rtc_set_mmss(struct device *dev, unsigned long secs)
105+static int dc_rtc_set_time(struct device *dev, struct rtc_time *tm)
110106 {
111107 struct dc_rtc *rtc = dev_get_drvdata(dev);
112108
113− return dc_rtc_write(rtc, secs);
109+ return dc_rtc_write(rtc, rtc_tm_to_time64(tm));
114110 }
115111
116112 static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
@@ -161,7 +157,7 @@ static int dc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 44 unmodified lines
161157
162158 static const struct rtc_class_ops dc_rtc_ops = {
163159 .read_time = dc_rtc_read_time,
164− .set_mmss = dc_rtc_set_mmss,
160+ .set_time = dc_rtc_set_time,
165161 .read_alarm = dc_rtc_read_alarm,
166162 .set_alarm = dc_rtc_set_alarm,
167163 .alarm_irq_enable = dc_rtc_alarm_irq_enable,
@@ -192,6 +188,10 @@ static int __init dc_rtc_probe(struct platform_device *pdev) · 24 unmodified lines
192188 if (IS_ERR(rtc->regs))
193189 return PTR_ERR(rtc->regs);
194190
191+ rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
192+ if (IS_ERR(rtc->rtc_dev))
193+ return PTR_ERR(rtc->rtc_dev);
194+
195195 irq = platform_get_irq(pdev, 0);
196196 if (irq < 0)
197197 return irq;
@@ -200,12 +200,11 @@ static int __init dc_rtc_probe(struct platform_device *pdev) · 2 unmodified lines
200200 return ret;
201201
202202 platform_set_drvdata(pdev, rtc);
203− rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
204− &dc_rtc_ops, THIS_MODULE);
205− if (IS_ERR(rtc->rtc_dev))
206− return PTR_ERR(rtc->rtc_dev);
207203
208− return 0;
204+ rtc->rtc_dev->ops = &dc_rtc_ops;
205+ rtc->rtc_dev->range_max = U32_MAX;
206+
207+ return rtc_register_device(rtc->rtc_dev);
209208 }
210209
211210 static const struct of_device_id dc_dt_ids[] = {
drivers/rtc/rtc-dm355evm.c+10−14
@@ -1,12 +1,8 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * rtc-dm355evm.c - access battery-backed counter in MSP430 firmware
34 *
45 * Copyright (c) 2008 by David Brownell
5− *
6− * This program is free software; you can redistribute it and/or
7− * modify it under the terms of the GNU General Public License
8− * as published by the Free Software Foundation; either version
9− * 2 of the License, or (at your option) any later version.
106 */
117 #include <linux/kernel.h>
128 #include <linux/init.h>
@@ -78,7 +74,7 @@ static int dm355evm_rtc_read_time(struct device *dev, struct rtc_time *tm) · 65 unmodified lines
7874
7975 dev_dbg(dev, "read timestamp %08x\n", time.value);
8076
81− rtc_time_to_tm(le32_to_cpu(time.value), tm);
77+ rtc_time64_to_tm(le32_to_cpu(time.value), tm);
8278 return 0;
8379 }
8480
@@ -88,7 +84,7 @@ static int dm355evm_rtc_set_time(struct device *dev, struct rtc_time *tm) · 3 unmodified lines
8884 unsigned long value;
8985 int status;
9086
91− rtc_tm_to_time(tm, &value);
87+ value = rtc_tm_to_time64(tm);
9288 time.value = cpu_to_le32(value);
9389
9490 dev_dbg(dev, "write timestamp %08x\n", time.value);
@@ -127,16 +123,16 @@ static int dm355evm_rtc_probe(struct platform_device *pdev) · 32 unmodified lines
127123 {
128124 struct rtc_device *rtc;
129125
130− rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
131− &dm355evm_rtc_ops, THIS_MODULE);
132− if (IS_ERR(rtc)) {
133− dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
134− PTR_ERR(rtc));
126+ rtc = devm_rtc_allocate_device(&pdev->dev);
127+ if (IS_ERR(rtc))
135128 return PTR_ERR(rtc);
136− }
129+
137130 platform_set_drvdata(pdev, rtc);
138131
139− return 0;
132+ rtc->ops = &dm355evm_rtc_ops;
133+ rtc->range_max = U32_MAX;
134+
135+ return rtc_register_device(rtc);
140136 }
141137
142138 /*
drivers/rtc/rtc-ds1672.c+36−91
@@ -1,12 +1,9 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * An rtc/i2c driver for the Dallas DS1672
34 * Copyright 2005-06 Tower Technologies
45 *
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
6− *
7− * This program is free software; you can redistribute it and/or modify
8− * it under the terms of the GNU General Public License version 2 as
9− * published by the Free Software Foundation.
107 */
118
129 #include <linux/i2c.h>
@@ -21,17 +18,16 @@ · 8 unmodified lines
2118
2219 #define DS1672_REG_CONTROL_EOSC 0x80
2320
24−static struct i2c_driver ds1672_driver;
25−
2621 /*
2722 * In the routines that deal directly with the ds1672 hardware, we use
2823 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
29− * Epoch is initialized as 2000. Time is set to UTC.
24+ * Time is set to UTC.
3025 */
31−static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
26+static int ds1672_read_time(struct device *dev, struct rtc_time *tm)
3227 {
28+ struct i2c_client *client = to_i2c_client(dev);
3329 unsigned long time;
34− unsigned char addr = DS1672_REG_CNT_BASE;
30+ unsigned char addr = DS1672_REG_CONTROL;
3531 unsigned char buf[4];
3632
3733 struct i2c_msg msgs[] = {
@@ -43,11 +39,25 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm) · 5 unmodified lines
4339 {/* read date */
4440 .addr = client->addr,
4541 .flags = I2C_M_RD,
46− .len = 4,
42+ .len = 1,
4743 .buf = buf
4844 },
4945 };
5046
47+ /* read control register */
48+ if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
49+ dev_warn(&client->dev, "Unable to read the control register\n");
50+ return -EIO;
51+ }
52+
53+ if (buf[0] & DS1672_REG_CONTROL_EOSC) {
54+ dev_warn(&client->dev, "Oscillator not enabled. Set time to enable.\n");
55+ return -EINVAL;
56+ }
57+
58+ addr = DS1672_REG_CNT_BASE;
59+ msgs[1].len = 4;
60+
5161 /* read date registers */
5262 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
5363 dev_err(&client->dev, "%s: read error\n", __func__);
@@ -61,20 +71,19 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm) · 7 unmodified lines
6171 time = ((unsigned long)buf[3] << 24) | (buf[2] << 16) |
6272 (buf[1] << 8) | buf[0];
6373
64− rtc_time_to_tm(time, tm);
74+ rtc_time64_to_tm(time, tm);
6575
66− dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
67− "mday=%d, mon=%d, year=%d, wday=%d\n",
68− __func__, tm->tm_sec, tm->tm_min, tm->tm_hour,
69− tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
76+ dev_dbg(&client->dev, "%s: tm is %ptR\n", __func__, tm);
7077
7178 return 0;
7279 }
7380
74−static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
81+static int ds1672_set_time(struct device *dev, struct rtc_time *tm)
7582 {
83+ struct i2c_client *client = to_i2c_client(dev);
7684 int xfer;
7785 unsigned char buf[6];
86+ unsigned long secs = rtc_tm_to_time64(tm);
7887
7988 buf[0] = DS1672_REG_CNT_BASE;
8089 buf[1] = secs & 0x000000FF;
@@ -92,71 +101,15 @@ static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs) · 11 unmodified lines
92101 return 0;
93102 }
94103
95−static int ds1672_rtc_read_time(struct device *dev, struct rtc_time *tm)
96−{
97− return ds1672_get_datetime(to_i2c_client(dev), tm);
98−}
99−
100−static int ds1672_rtc_set_mmss(struct device *dev, unsigned long secs)
101−{
102− return ds1672_set_mmss(to_i2c_client(dev), secs);
103−}
104−
105−static int ds1672_get_control(struct i2c_client *client, u8 *status)
106−{
107− unsigned char addr = DS1672_REG_CONTROL;
108−
109− struct i2c_msg msgs[] = {
110− {/* setup read ptr */
111− .addr = client->addr,
112− .len = 1,
113− .buf = &addr
114− },
115− {/* read control */
116− .addr = client->addr,
117− .flags = I2C_M_RD,
118− .len = 1,
119− .buf = status
120− },
121− };
122−
123− /* read control register */
124− if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
125− dev_err(&client->dev, "%s: read error\n", __func__);
126− return -EIO;
127− }
128−
129− return 0;
130−}
131−
132−/* following are the sysfs callback functions */
133−static ssize_t show_control(struct device *dev, struct device_attribute *attr,
134− char *buf)
135−{
136− struct i2c_client *client = to_i2c_client(dev);
137− u8 control;
138− int err;
139−
140− err = ds1672_get_control(client, &control);
141− if (err)
142− return err;
143−
144− return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC)
145− ? "disabled" : "enabled");
146−}
147−
148−static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
149−
150104 static const struct rtc_class_ops ds1672_rtc_ops = {
151− .read_time = ds1672_rtc_read_time,
152− .set_mmss = ds1672_rtc_set_mmss,
105+ .read_time = ds1672_read_time,
106+ .set_time = ds1672_set_time,
153107 };
154108
155109 static int ds1672_probe(struct i2c_client *client,
156110 const struct i2c_device_id *id)
157111 {
158112 int err = 0;
159− u8 control;
160113 struct rtc_device *rtc;
161114
162115 dev_dbg(&client->dev, "%s\n", __func__);
@@ -164,29 +117,21 @@ static int ds1672_probe(struct i2c_client *client, · 1 unmodified line
164117 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
165118 return -ENODEV;
166119
167− rtc = devm_rtc_device_register(&client->dev, ds1672_driver.driver.name,
168− &ds1672_rtc_ops, THIS_MODULE);
169−
120+ rtc = devm_rtc_allocate_device(&client->dev);
170121 if (IS_ERR(rtc))
171122 return PTR_ERR(rtc);
172123
173− i2c_set_clientdata(client, rtc);
124+ rtc->ops = &ds1672_rtc_ops;
125+ rtc->range_max = U32_MAX;
174126
175− /* read control register */
176− err = ds1672_get_control(client, &control);
177− if (err) {
178− dev_warn(&client->dev, "Unable to read the control register\n");
179− }
127+ err = rtc_register_device(rtc);
128+ if (err)
129+ return err;
180130
181− if (control & DS1672_REG_CONTROL_EOSC)
182− dev_warn(&client->dev, "Oscillator not enabled. "
183− "Set time to enable.\n");
131+ if (IS_ERR(rtc))
132+ return PTR_ERR(rtc);
184133
185− /* Register sysfs hooks */
186− err = device_create_file(&client->dev, &dev_attr_control);
187− if (err)
188− dev_err(&client->dev, "Unable to create sysfs entry: %s\n",
189− dev_attr_control.attr.name);
134+ i2c_set_clientdata(client, rtc);
190135
191136 return 0;
192137 }
drivers/rtc/rtc-ds1685.c+107−155
@@ -191,42 +191,6 @@ ds1685_rtc_end_data_access(struct ds1685_priv *rtc) · 190 unmodified lines
191191 (rtc->read(rtc, RTC_CTRL_B) & ~(RTC_CTRL_B_SET)));
192192 }
193193
194−/**
195− * ds1685_rtc_begin_ctrl_access - prepare the rtc for ctrl access.
196− * @rtc: pointer to the ds1685 rtc structure.
197− * @flags: irq flags variable for spin_lock_irqsave.
198− *
199− * This takes several steps to prepare the rtc for access to read just the
200− * control registers:
201− * - Sets a spinlock on the rtc IRQ.
202− * - Switches the rtc to bank 1. This allows access to the two extended
203− * control registers.
204− *
205− * Only use this where you are certain another lock will not be held.
206− */
207−static inline void
208−ds1685_rtc_begin_ctrl_access(struct ds1685_priv *rtc, unsigned long *flags)
209−{
210− spin_lock_irqsave(&rtc->lock, *flags);
211− ds1685_rtc_switch_to_bank1(rtc);
212−}
213−
214−/**
215− * ds1685_rtc_end_ctrl_access - end ctrl access on the rtc.
216− * @rtc: pointer to the ds1685 rtc structure.
217− * @flags: irq flags variable for spin_unlock_irqrestore.
218− *
219− * This ends what was started by ds1685_rtc_begin_ctrl_access:
220− * - Switches the rtc back to bank 0.
221− * - Unsets the spinlock on the rtc IRQ.
222− */
223−static inline void
224−ds1685_rtc_end_ctrl_access(struct ds1685_priv *rtc, unsigned long flags)
225−{
226− ds1685_rtc_switch_to_bank0(rtc);
227− spin_unlock_irqrestore(&rtc->lock, flags);
228−}
229−
230194 /**
231195 * ds1685_rtc_get_ssn - retrieve the silicon serial number.
232196 * @rtc: pointer to the ds1685 rtc structure.
@@ -546,10 +510,6 @@ static int · 313 unmodified lines
546510 ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
547511 {
548512 struct ds1685_priv *rtc = dev_get_drvdata(dev);
549− unsigned long flags = 0;
550−
551− /* Enable/disable the Alarm IRQ-Enable flag. */
552− spin_lock_irqsave(&rtc->lock, flags);
553513
554514 /* Flip the requisite interrupt-enable bit. */
555515 if (enabled)
@@ -561,7 +521,6 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 5 unmodified lines
561521
562522 /* Read Control C to clear all the flag bits. */
563523 rtc->read(rtc, RTC_CTRL_C);
564− spin_unlock_irqrestore(&rtc->lock, flags);
565524
566525 return 0;
567526 }
@@ -569,98 +528,18 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 1 unmodified line
569528
570529
571530 /* ----------------------------------------------------------------------- */
572−/* IRQ handler & workqueue. */
573−
574−/**
575− * ds1685_rtc_irq_handler - IRQ handler.
576− * @irq: IRQ number.
577− * @dev_id: platform device pointer.
578− */
579−static irqreturn_t
580−ds1685_rtc_irq_handler(int irq, void *dev_id)
581−{
582− struct platform_device *pdev = dev_id;
583− struct ds1685_priv *rtc = platform_get_drvdata(pdev);
584− u8 ctrlb, ctrlc;
585− unsigned long events = 0;
586− u8 num_irqs = 0;
587−
588− /* Abort early if the device isn't ready yet (i.e., DEBUG_SHIRQ). */
589− if (unlikely(!rtc))
590− return IRQ_HANDLED;
591−
592− /* Ctrlb holds the interrupt-enable bits and ctrlc the flag bits. */
593− spin_lock(&rtc->lock);
594− ctrlb = rtc->read(rtc, RTC_CTRL_B);
595− ctrlc = rtc->read(rtc, RTC_CTRL_C);
596−
597− /* Is the IRQF bit set? */
598− if (likely(ctrlc & RTC_CTRL_C_IRQF)) {
599− /*
600− * We need to determine if it was one of the standard
601− * events: PF, AF, or UF. If so, we handle them and
602− * update the RTC core.
603− */
604− if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) {
605− events = RTC_IRQF;
606−
607− /* Check for a periodic interrupt. */
608− if ((ctrlb & RTC_CTRL_B_PIE) &&
609− (ctrlc & RTC_CTRL_C_PF)) {
610− events |= RTC_PF;
611− num_irqs++;
612− }
613−
614− /* Check for an alarm interrupt. */
615− if ((ctrlb & RTC_CTRL_B_AIE) &&
616− (ctrlc & RTC_CTRL_C_AF)) {
617− events |= RTC_AF;
618− num_irqs++;
619− }
620−
621− /* Check for an update interrupt. */
622− if ((ctrlb & RTC_CTRL_B_UIE) &&
623− (ctrlc & RTC_CTRL_C_UF)) {
624− events |= RTC_UF;
625− num_irqs++;
626− }
627−
628− rtc_update_irq(rtc->dev, num_irqs, events);
629− } else {
630− /*
631− * One of the "extended" interrupts was received that
632− * is not recognized by the RTC core. These need to
633− * be handled in task context as they can call other
634− * functions and the time spent in irq context needs
635− * to be minimized. Schedule them into a workqueue
636− * and inform the RTC core that the IRQs were handled.
637− */
638− spin_unlock(&rtc->lock);
639− schedule_work(&rtc->work);
640− rtc_update_irq(rtc->dev, 0, 0);
641− return IRQ_HANDLED;
642− }
643− }
644− spin_unlock(&rtc->lock);
645−
646− return events ? IRQ_HANDLED : IRQ_NONE;
647−}
531+/* IRQ handler */
648532
649533 /**
650− * ds1685_rtc_work_queue - work queue handler.
651− * @work: work_struct containing data to work on in task context.
534+ * ds1685_rtc_extended_irq - take care of extended interrupts
535+ * @rtc: pointer to the ds1685 rtc structure.
536+ * @pdev: platform device pointer.
652537 */
653538 static void
654−ds1685_rtc_work_queue(struct work_struct *work)
539+ds1685_rtc_extended_irq(struct ds1685_priv *rtc, struct platform_device *pdev)
655540 {
656− struct ds1685_priv *rtc = container_of(work,
657− struct ds1685_priv, work);
658− struct platform_device *pdev = to_platform_device(&rtc->dev->dev);
659− struct mutex *rtc_mutex = &rtc->dev->ops_lock;
660541 u8 ctrl4a, ctrl4b;
661542
662− mutex_lock(rtc_mutex);
663−
664543 ds1685_rtc_switch_to_bank1(rtc);
665544 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A);
666545 ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B);
@@ -739,8 +618,76 @@ ds1685_rtc_work_queue(struct work_struct *work) · 72 unmodified lines
739618 "RAM-Clear IRQ just occurred!\n");
740619 }
741620 ds1685_rtc_switch_to_bank0(rtc);
621+}
622+
623+/**
624+ * ds1685_rtc_irq_handler - IRQ handler.
625+ * @irq: IRQ number.
626+ * @dev_id: platform device pointer.
627+ */
628+static irqreturn_t
629+ds1685_rtc_irq_handler(int irq, void *dev_id)
630+{
631+ struct platform_device *pdev = dev_id;
632+ struct ds1685_priv *rtc = platform_get_drvdata(pdev);
633+ struct mutex *rtc_mutex;
634+ u8 ctrlb, ctrlc;
635+ unsigned long events = 0;
636+ u8 num_irqs = 0;
637+
638+ /* Abort early if the device isn't ready yet (i.e., DEBUG_SHIRQ). */
639+ if (unlikely(!rtc))
640+ return IRQ_HANDLED;
641+
642+ rtc_mutex = &rtc->dev->ops_lock;
643+ mutex_lock(rtc_mutex);
742644
645+ /* Ctrlb holds the interrupt-enable bits and ctrlc the flag bits. */
646+ ctrlb = rtc->read(rtc, RTC_CTRL_B);
647+ ctrlc = rtc->read(rtc, RTC_CTRL_C);
648+
649+ /* Is the IRQF bit set? */
650+ if (likely(ctrlc & RTC_CTRL_C_IRQF)) {
651+ /*
652+ * We need to determine if it was one of the standard
653+ * events: PF, AF, or UF. If so, we handle them and
654+ * update the RTC core.
655+ */
656+ if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) {
657+ events = RTC_IRQF;
658+
659+ /* Check for a periodic interrupt. */
660+ if ((ctrlb & RTC_CTRL_B_PIE) &&
661+ (ctrlc & RTC_CTRL_C_PF)) {
662+ events |= RTC_PF;
663+ num_irqs++;
664+ }
665+
666+ /* Check for an alarm interrupt. */
667+ if ((ctrlb & RTC_CTRL_B_AIE) &&
668+ (ctrlc & RTC_CTRL_C_AF)) {
669+ events |= RTC_AF;
670+ num_irqs++;
671+ }
672+
673+ /* Check for an update interrupt. */
674+ if ((ctrlb & RTC_CTRL_B_UIE) &&
675+ (ctrlc & RTC_CTRL_C_UF)) {
676+ events |= RTC_UF;
677+ num_irqs++;
678+ }
679+ } else {
680+ /*
681+ * One of the "extended" interrupts was received that
682+ * is not recognized by the RTC core.
683+ */
684+ ds1685_rtc_extended_irq(rtc, pdev);
685+ }
686+ }
687+ rtc_update_irq(rtc->dev, num_irqs, events);
743688 mutex_unlock(rtc_mutex);
689+
690+ return events ? IRQ_HANDLED : IRQ_NONE;
744691 }
745692 /* ----------------------------------------------------------------------- */
746693
@@ -869,11 +816,15 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val, · 122 unmodified lines
869816 size_t size)
870817 {
871818 struct ds1685_priv *rtc = priv;
819+ struct mutex *rtc_mutex = &rtc->dev->ops_lock;
872820 ssize_t count;
873− unsigned long flags = 0;
874821 u8 *buf = val;
822+ int err;
823+
824+ err = mutex_lock_interruptible(rtc_mutex);
825+ if (err)
826+ return err;
875827
876− spin_lock_irqsave(&rtc->lock, flags);
877828 ds1685_rtc_switch_to_bank0(rtc);
878829
879830 /* Read NVRAM in time and bank0 registers. */
@@ -923,7 +874,7 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val, · 43 unmodified lines
923874 ds1685_rtc_switch_to_bank0(rtc);
924875 }
925876 #endif /* !CONFIG_RTC_DRV_DS1689 */
926− spin_unlock_irqrestore(&rtc->lock, flags);
877+ mutex_unlock(rtc_mutex);
927878
928879 return 0;
929880 }
@@ -932,11 +883,15 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val, · 2 unmodified lines
932883 size_t size)
933884 {
934885 struct ds1685_priv *rtc = priv;
886+ struct mutex *rtc_mutex = &rtc->dev->ops_lock;
935887 ssize_t count;
936− unsigned long flags = 0;
937888 u8 *buf = val;
889+ int err;
890+
891+ err = mutex_lock_interruptible(rtc_mutex);
892+ if (err)
893+ return err;
938894
939− spin_lock_irqsave(&rtc->lock, flags);
940895 ds1685_rtc_switch_to_bank0(rtc);
941896
942897 /* Write NVRAM in time and bank0 registers. */
@@ -986,7 +941,7 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val, · 43 unmodified lines
986941 ds1685_rtc_switch_to_bank0(rtc);
987942 }
988943 #endif /* !CONFIG_RTC_DRV_DS1689 */
989− spin_unlock_irqrestore(&rtc->lock, flags);
944+ mutex_unlock(rtc_mutex);
990945
991946 return 0;
992947 }
@@ -1004,7 +959,7 @@ static ssize_t · 11 unmodified lines
1004959 ds1685_rtc_sysfs_battery_show(struct device *dev,
1005960 struct device_attribute *attr, char *buf)
1006961 {
1007− struct ds1685_priv *rtc = dev_get_drvdata(dev);
962+ struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
1008963 u8 ctrld;
1009964
1010965 ctrld = rtc->read(rtc, RTC_CTRL_D);
@@ -1024,7 +979,7 @@ static ssize_t · 13 unmodified lines
1024979 ds1685_rtc_sysfs_auxbatt_show(struct device *dev,
1025980 struct device_attribute *attr, char *buf)
1026981 {
1027− struct ds1685_priv *rtc = dev_get_drvdata(dev);
982+ struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
1028983 u8 ctrl4a;
1029984
1030985 ds1685_rtc_switch_to_bank1(rtc);
@@ -1046,7 +1001,7 @@ static ssize_t · 15 unmodified lines
10461001 ds1685_rtc_sysfs_serial_show(struct device *dev,
10471002 struct device_attribute *attr, char *buf)
10481003 {
1049− struct ds1685_priv *rtc = dev_get_drvdata(dev);
1004+ struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
10501005 u8 ssn[8];
10511006
10521007 ds1685_rtc_switch_to_bank1(rtc);
@@ -1177,9 +1132,7 @@ ds1685_rtc_probe(struct platform_device *pdev) · 124 unmodified lines
11771132 if (pdata->plat_post_ram_clear)
11781133 rtc->post_ram_clear = pdata->plat_post_ram_clear;
11791134
1180− /* Init the spinlock, workqueue, & set the driver data. */
1181− spin_lock_init(&rtc->lock);
1182− INIT_WORK(&rtc->work, ds1685_rtc_work_queue);
1135+ /* set the driver data. */
11831136 platform_set_drvdata(pdev, rtc);
11841137
11851138 /* Turn the oscillator on if is not already on (DV1 = 1). */
@@ -1335,22 +1288,23 @@ ds1685_rtc_probe(struct platform_device *pdev) · 149 unmodified lines
13351288 */
13361289 if (!pdata->no_irq) {
13371290 ret = platform_get_irq(pdev, 0);
1338− if (ret > 0) {
1339− rtc->irq_num = ret;
1340−
1341− /* Request an IRQ. */
1342− ret = devm_request_irq(&pdev->dev, rtc->irq_num,
1343− ds1685_rtc_irq_handler,
1344− IRQF_SHARED, pdev->name, pdev);
1345−
1346− /* Check to see if something came back. */
1347− if (unlikely(ret)) {
1348− dev_warn(&pdev->dev,
1349− "RTC interrupt not available\n");
1350− rtc->irq_num = 0;
1351− }
1352− } else
1291+ if (ret <= 0)
13531292 return ret;
1293+
1294+ rtc->irq_num = ret;
1295+
1296+ /* Request an IRQ. */
1297+ ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_num,
1298+ NULL, ds1685_rtc_irq_handler,
1299+ IRQF_SHARED | IRQF_ONESHOT,
1300+ pdev->name, pdev);
1301+
1302+ /* Check to see if something came back. */
1303+ if (unlikely(ret)) {
1304+ dev_warn(&pdev->dev,
1305+ "RTC interrupt not available\n");
1306+ rtc->irq_num = 0;
1307+ }
13541308 }
13551309 rtc->no_irq = pdata->no_irq;
13561310
@@ -1397,8 +1351,6 @@ ds1685_rtc_remove(struct platform_device *pdev) · 40 unmodified lines
13971351 (rtc->read(rtc, RTC_EXT_CTRL_4A) &
13981352 ~(RTC_CTRL_4A_RWK_MASK)));
13991353
1400− cancel_work_sync(&rtc->work);
1401−
14021354 return 0;
14031355 }
14041356
drivers/rtc/rtc-ds2404.c+22−51
@@ -1,11 +1,5 @@
1−/*
2− * Copyright (C) 2012 Sven Schnelle <svens@stackframe.org>
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 version 2 as
6− * published by the Free Software Foundation.
7− *
8− */
1+// SPDX-License-Identifier: GPL-2.0
2+// Copyright (C) 2012 Sven Schnelle <svens@stackframe.org>
93
104 #include <linux/platform_device.h>
115 #include <linux/module.h>
@@ -29,14 +23,6 @@ · 17 unmodified lines
2923 #define DS2404_COPY_SCRATCHPAD_CMD 0x55
3024 #define DS2404_READ_MEMORY_CMD 0xf0
3125
32−struct ds2404;
33−
34−struct ds2404_chip_ops {
35− int (*map_io)(struct ds2404 *chip, struct platform_device *pdev,
36− struct ds2404_platform_data *pdata);
37− void (*unmap_io)(struct ds2404 *chip);
38−};
39−
4026 #define DS2404_RST 0
4127 #define DS2404_CLK 1
4228 #define DS2404_DQ 2
@@ -48,7 +34,6 @@ struct ds2404_gpio { · 5 unmodified lines
4834
4935 struct ds2404 {
5036 struct ds2404_gpio *gpio;
51− const struct ds2404_chip_ops *ops;
5237 struct rtc_device *rtc;
5338 };
5439
@@ -87,7 +72,7 @@ err_request: · 32 unmodified lines
8772 return err;
8873 }
8974
90−static void ds2404_gpio_unmap(struct ds2404 *chip)
75+static void ds2404_gpio_unmap(void *data)
9176 {
9277 int i;
9378
@@ -95,11 +80,6 @@ static void ds2404_gpio_unmap(struct ds2404 *chip) · 1 unmodified line
9580 gpio_free(ds2404_gpio[i].gpio);
9681 }
9782
98−static const struct ds2404_chip_ops ds2404_gpio_ops = {
99− .map_io = ds2404_gpio_map,
100− .unmap_io = ds2404_gpio_unmap,
101−};
102−
10383 static void ds2404_reset(struct device *dev)
10484 {
10585 gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 0);
@@ -206,20 +186,20 @@ static int ds2404_read_time(struct device *dev, struct rtc_time *dt) · 100 unmodified lines
206186 ds2404_read_memory(dev, 0x203, 4, (u8 *)&time);
207187 time = le32_to_cpu(time);
208188
209− rtc_time_to_tm(time, dt);
189+ rtc_time64_to_tm(time, dt);
210190 return 0;
211191 }
212192
213−static int ds2404_set_mmss(struct device *dev, unsigned long secs)
193+static int ds2404_set_time(struct device *dev, struct rtc_time *dt)
214194 {
215− u32 time = cpu_to_le32(secs);
195+ u32 time = cpu_to_le32(rtc_tm_to_time64(dt));
216196 ds2404_write_memory(dev, 0x203, 4, (u8 *)&time);
217197 return 0;
218198 }
219199
220200 static const struct rtc_class_ops ds2404_rtc_ops = {
221201 .read_time = ds2404_read_time,
222− .set_mmss = ds2404_set_mmss,
202+ .set_time = ds2404_set_time,
223203 };
224204
225205 static int rtc_probe(struct platform_device *pdev)
@@ -232,11 +212,17 @@ static int rtc_probe(struct platform_device *pdev) · 6 unmodified lines
232212 if (!chip)
233213 return -ENOMEM;
234214
235− chip->ops = &ds2404_gpio_ops;
215+ chip->rtc = devm_rtc_allocate_device(&pdev->dev);
216+ if (IS_ERR(chip->rtc))
217+ return PTR_ERR(chip->rtc);
236218
237− retval = chip->ops->map_io(chip, pdev, pdata);
219+ retval = ds2404_gpio_map(chip, pdev, pdata);
238220 if (retval)
239− goto err_chip;
221+ return retval;
222+
223+ retval = devm_add_action_or_reset(&pdev->dev, ds2404_gpio_unmap, chip);
224+ if (retval)
225+ return retval;
240226
241227 dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n",
242228 chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio,
@@ -244,34 +230,19 @@ static int rtc_probe(struct platform_device *pdev) · 1 unmodified line
244230
245231 platform_set_drvdata(pdev, chip);
246232
247− chip->rtc = devm_rtc_device_register(&pdev->dev, "ds2404",
248− &ds2404_rtc_ops, THIS_MODULE);
249− if (IS_ERR(chip->rtc)) {
250− retval = PTR_ERR(chip->rtc);
251− goto err_io;
252− }
233+ chip->rtc->ops = &ds2404_rtc_ops;
234+ chip->rtc->range_max = U32_MAX;
253235
254− ds2404_enable_osc(&pdev->dev);
255− return 0;
256−
257−err_io:
258− chip->ops->unmap_io(chip);
259−err_chip:
260− return retval;
261−}
262−
263−static int rtc_remove(struct platform_device *dev)
264−{
265− struct ds2404 *chip = platform_get_drvdata(dev);
266−
267− chip->ops->unmap_io(chip);
236+ retval = rtc_register_device(chip->rtc);
237+ if (retval)
238+ return retval;
268239
240+ ds2404_enable_osc(&pdev->dev);
269241 return 0;
270242 }
271243
272244 static struct platform_driver rtc_device_driver = {
273245 .probe = rtc_probe,
274− .remove = rtc_remove,
275246 .driver = {
276247 .name = "ds2404",
277248 },
drivers/rtc/rtc-ds3232.c+38−2
@@ -48,6 +48,10 @@ · 47 unmodified lines
4848 # define DS3232_REG_SR_A1F 0x01
4949
5050 #define DS3232_REG_TEMPERATURE 0x11
51+#define DS3232_REG_SRAM_START 0x14
52+#define DS3232_REG_SRAM_END 0xFF
53+
54+#define DS3232_REG_SRAM_SIZE 236
5155
5256 struct ds3232 {
5357 struct device *dev;
@@ -461,11 +465,39 @@ static const struct rtc_class_ops ds3232_rtc_ops = { · 407 unmodified lines
461465 .alarm_irq_enable = ds3232_alarm_irq_enable,
462466 };
463467
468+static int ds3232_nvmem_read(void *priv, unsigned int offset, void *val,
469+ size_t bytes)
470+{
471+ struct regmap *ds3232_regmap = (struct regmap *)priv;
472+
473+ return regmap_bulk_read(ds3232_regmap, DS3232_REG_SRAM_START + offset,
474+ val, bytes);
475+}
476+
477+static int ds3232_nvmem_write(void *priv, unsigned int offset, void *val,
478+ size_t bytes)
479+{
480+ struct regmap *ds3232_regmap = (struct regmap *)priv;
481+
482+ return regmap_bulk_write(ds3232_regmap, DS3232_REG_SRAM_START + offset,
483+ val, bytes);
484+}
485+
464486 static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
465487 const char *name)
466488 {
467489 struct ds3232 *ds3232;
468490 int ret;
491+ struct nvmem_config nvmem_cfg = {
492+ .name = "ds3232_sram",
493+ .stride = 1,
494+ .size = DS3232_REG_SRAM_SIZE,
495+ .word_size = 1,
496+ .reg_read = ds3232_nvmem_read,
497+ .reg_write = ds3232_nvmem_write,
498+ .priv = regmap,
499+ .type = NVMEM_TYPE_BATTERY_BACKED
500+ };
469501
470502 ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL);
471503 if (!ds3232)
@@ -490,6 +522,10 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, · 18 unmodified lines
490522 if (IS_ERR(ds3232->rtc))
491523 return PTR_ERR(ds3232->rtc);
492524
525+ ret = rtc_nvmem_register(ds3232->rtc, &nvmem_cfg);
526+ if(ret)
527+ return ret;
528+
493529 if (ds3232->irq > 0) {
494530 ret = devm_request_threaded_irq(dev, ds3232->irq, NULL,
495531 ds3232_irq,
@@ -542,7 +578,7 @@ static int ds3232_i2c_probe(struct i2c_client *client, · 46 unmodified lines
542578 static const struct regmap_config config = {
543579 .reg_bits = 8,
544580 .val_bits = 8,
545− .max_register = 0x13,
581+ .max_register = DS3232_REG_SRAM_END,
546582 };
547583
548584 regmap = devm_regmap_init_i2c(client, &config);
@@ -609,7 +645,7 @@ static int ds3234_probe(struct spi_device *spi) · 60 unmodified lines
609645 static const struct regmap_config config = {
610646 .reg_bits = 8,
611647 .val_bits = 8,
612− .max_register = 0x13,
648+ .max_register = DS3232_REG_SRAM_END,
613649 .write_flag_mask = 0x80,
614650 };
615651 struct regmap *regmap;
drivers/rtc/rtc-ep93xx.c+25−45
@@ -1,12 +1,9 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * A driver for the RTC embedded in the Cirrus Logic EP93XX processors
34 * Copyright (c) 2006 Tower Technologies
45 *
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
6− *
7− * This program is free software; you can redistribute it and/or modify
8− * it under the terms of the GNU General Public License version 2 as
9− * published by the Free Software Foundation.
107 */
118
129 #include <linux/module.h>
@@ -18,27 +15,23 @@ · 5 unmodified lines
1815 #define EP93XX_RTC_DATA 0x000
1916 #define EP93XX_RTC_MATCH 0x004
2017 #define EP93XX_RTC_STATUS 0x008
21−#define EP93XX_RTC_STATUS_INTR (1<<0)
18+#define EP93XX_RTC_STATUS_INTR BIT(0)
2219 #define EP93XX_RTC_LOAD 0x00C
2320 #define EP93XX_RTC_CONTROL 0x010
24−#define EP93XX_RTC_CONTROL_MIE (1<<0)
21+#define EP93XX_RTC_CONTROL_MIE BIT(0)
2522 #define EP93XX_RTC_SWCOMP 0x108
2623 #define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000
2724 #define EP93XX_RTC_SWCOMP_DEL_SHIFT 16
2825 #define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
2926 #define EP93XX_RTC_SWCOMP_INT_SHIFT 0
3027
31−/*
32− * struct device dev.platform_data is used to store our private data
33− * because struct rtc_device does not have a variable to hold it.
34− */
3528 struct ep93xx_rtc {
3629 void __iomem *mmio_base;
3730 struct rtc_device *rtc;
3831 };
3932
4033 static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
41− unsigned short *delete)
34+ unsigned short *delete)
4235 {
4336 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
4437 unsigned long comp;
@@ -63,13 +56,14 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) · 18 unmodified lines
6356
6457 time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
6558
66− rtc_time_to_tm(time, tm);
59+ rtc_time64_to_tm(time, tm);
6760 return 0;
6861 }
6962
70−static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
63+static int ep93xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
7164 {
7265 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
66+ unsigned long secs = rtc_tm_to_time64(tm);
7367
7468 writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
7569 return 0;
@@ -89,31 +83,31 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq) · 13 unmodified lines
8983
9084 static const struct rtc_class_ops ep93xx_rtc_ops = {
9185 .read_time = ep93xx_rtc_read_time,
92− .set_mmss = ep93xx_rtc_set_mmss,
86+ .set_time = ep93xx_rtc_set_time,
9387 .proc = ep93xx_rtc_proc,
9488 };
9589
96−static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev,
97− struct device_attribute *attr, char *buf)
90+static ssize_t comp_preload_show(struct device *dev,
91+ struct device_attribute *attr, char *buf)
9892 {
9993 unsigned short preload;
10094
101− ep93xx_rtc_get_swcomp(dev, &preload, NULL);
95+ ep93xx_rtc_get_swcomp(dev->parent, &preload, NULL);
10296
10397 return sprintf(buf, "%d\n", preload);
10498 }
105−static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL);
99+static DEVICE_ATTR_RO(comp_preload);
106100
107−static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev,
108− struct device_attribute *attr, char *buf)
101+static ssize_t comp_delete_show(struct device *dev,
102+ struct device_attribute *attr, char *buf)
109103 {
110104 unsigned short delete;
111105
112− ep93xx_rtc_get_swcomp(dev, NULL, &delete);
106+ ep93xx_rtc_get_swcomp(dev->parent, NULL, &delete);
113107
114108 return sprintf(buf, "%d\n", delete);
115109 }
116−static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL);
110+static DEVICE_ATTR_RO(comp_delete);
117111
118112 static struct attribute *ep93xx_rtc_attrs[] = {
119113 &dev_attr_comp_preload.attr,
@@ -140,33 +134,20 @@ static int ep93xx_rtc_probe(struct platform_device *pdev) · 20 unmodified lines
140134 if (IS_ERR(ep93xx_rtc->mmio_base))
141135 return PTR_ERR(ep93xx_rtc->mmio_base);
142136
143− pdev->dev.platform_data = ep93xx_rtc;
144137 platform_set_drvdata(pdev, ep93xx_rtc);
145138
146− ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev,
147− pdev->name, &ep93xx_rtc_ops, THIS_MODULE);
148− if (IS_ERR(ep93xx_rtc->rtc)) {
149− err = PTR_ERR(ep93xx_rtc->rtc);
150− goto exit;
151− }
139+ ep93xx_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
140+ if (IS_ERR(ep93xx_rtc->rtc))
141+ return PTR_ERR(ep93xx_rtc->rtc);
152142
153− err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
154− if (err)
155− goto exit;
156−
157− return 0;
143+ ep93xx_rtc->rtc->ops = &ep93xx_rtc_ops;
144+ ep93xx_rtc->rtc->range_max = U32_MAX;
158145
159−exit:
160− pdev->dev.platform_data = NULL;
161− return err;
162−}
163−
164−static int ep93xx_rtc_remove(struct platform_device *pdev)
165−{
166− sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
167− pdev->dev.platform_data = NULL;
146+ err = rtc_add_group(ep93xx_rtc->rtc, &ep93xx_rtc_sysfs_files);
147+ if (err)
148+ return err;
168149
169− return 0;
150+ return rtc_register_device(ep93xx_rtc->rtc);
170151 }
171152
172153 static struct platform_driver ep93xx_rtc_driver = {
@@ -174,7 +155,6 @@ static struct platform_driver ep93xx_rtc_driver = { · 1 unmodified line
174155 .name = "ep93xx-rtc",
175156 },
176157 .probe = ep93xx_rtc_probe,
177− .remove = ep93xx_rtc_remove,
178158 };
179159
180160 module_platform_driver(ep93xx_rtc_driver);
drivers/rtc/rtc-goldfish.c+16−34
@@ -1,23 +1,15 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /* drivers/rtc/rtc-goldfish.c
23 *
34 * Copyright (C) 2007 Google, Inc.
45 * Copyright (C) 2017 Imagination Technologies Ltd.
5− *
6− * This software is licensed under the terms of the GNU General Public
7− * License version 2, as published by the Free Software Foundation, and
8− * may be copied, distributed, and modified under those terms.
9− *
10− * This program is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
156 */
167
8+#include <linux/io.h>
179 #include <linux/module.h>
10+#include <linux/of.h>
1811 #include <linux/platform_device.h>
1912 #include <linux/rtc.h>
20−#include <linux/io.h>
2113
2214 #define TIMER_TIME_LOW 0x00 /* get low bits of current time */
2315 /* and update TIMER_TIME_HIGH */
@@ -56,7 +48,7 @@ static int goldfish_rtc_read_alarm(struct device *dev, · 32 unmodified lines
5648 do_div(rtc_alarm, NSEC_PER_SEC);
5749 memset(alrm, 0, sizeof(struct rtc_wkalrm));
5850
59− rtc_time_to_tm(rtc_alarm, &alrm->time);
51+ rtc_time64_to_tm(rtc_alarm, &alrm->time);
6052
6153 if (readl(base + TIMER_ALARM_STATUS))
6254 alrm->enabled = 1;
@@ -70,21 +62,15 @@ static int goldfish_rtc_set_alarm(struct device *dev, · 7 unmodified lines
7062 struct rtc_wkalrm *alrm)
7163 {
7264 struct goldfish_rtc *rtcdrv;
73− unsigned long rtc_alarm;
7465 u64 rtc_alarm64;
7566 u64 rtc_status_reg;
7667 void __iomem *base;
77− int ret = 0;
7868
7969 rtcdrv = dev_get_drvdata(dev);
8070 base = rtcdrv->base;
8171
8272 if (alrm->enabled) {
83− ret = rtc_tm_to_time(&alrm->time, &rtc_alarm);
84− if (ret != 0)
85− return ret;
86−
87− rtc_alarm64 = rtc_alarm * NSEC_PER_SEC;
73+ rtc_alarm64 = rtc_tm_to_time64(&alrm->time) * NSEC_PER_SEC;
8874 writel((rtc_alarm64 >> 32), base + TIMER_ALARM_HIGH);
8975 writel(rtc_alarm64, base + TIMER_ALARM_LOW);
9076 } else {
@@ -98,7 +84,7 @@ static int goldfish_rtc_set_alarm(struct device *dev, · 7 unmodified lines
9884 writel(1, base + TIMER_CLEAR_ALARM);
9985 }
10086
101− return ret;
87+ return 0;
10288 }
10389
10490 static int goldfish_rtc_alarm_irq_enable(struct device *dev,
@@ -147,7 +133,7 @@ static int goldfish_rtc_read_time(struct device *dev, struct rtc_time *tm) · 42 unmodified lines
147133
148134 do_div(time, NSEC_PER_SEC);
149135
150− rtc_time_to_tm(time, tm);
136+ rtc_time64_to_tm(time, tm);
151137
152138 return 0;
153139 }
@@ -156,21 +142,16 @@ static int goldfish_rtc_set_time(struct device *dev, struct rtc_time *tm) · 2 unmodified lines
156142 {
157143 struct goldfish_rtc *rtcdrv;
158144 void __iomem *base;
159− unsigned long now;
160145 u64 now64;
161− int ret;
162146
163147 rtcdrv = dev_get_drvdata(dev);
164148 base = rtcdrv->base;
165149
166− ret = rtc_tm_to_time(tm, &now);
167− if (ret == 0) {
168− now64 = now * NSEC_PER_SEC;
169− writel((now64 >> 32), base + TIMER_TIME_HIGH);
170− writel(now64, base + TIMER_TIME_LOW);
171− }
150+ now64 = rtc_tm_to_time64(tm) * NSEC_PER_SEC;
151+ writel((now64 >> 32), base + TIMER_TIME_HIGH);
152+ writel(now64, base + TIMER_TIME_LOW);
172153
173− return ret;
154+ return 0;
174155 }
175156
176157 static const struct rtc_class_ops goldfish_rtc_ops = {
@@ -205,19 +186,20 @@ static int goldfish_rtc_probe(struct platform_device *pdev) · 28 unmodified lines
205186 if (rtcdrv->irq < 0)
206187 return -ENODEV;
207188
208− rtcdrv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
209− &goldfish_rtc_ops,
210− THIS_MODULE);
189+ rtcdrv->rtc = devm_rtc_allocate_device(&pdev->dev);
211190 if (IS_ERR(rtcdrv->rtc))
212191 return PTR_ERR(rtcdrv->rtc);
213192
193+ rtcdrv->rtc->ops = &goldfish_rtc_ops;
194+ rtcdrv->rtc->range_max = U64_MAX / NSEC_PER_SEC;
195+
214196 err = devm_request_irq(&pdev->dev, rtcdrv->irq,
215197 goldfish_rtc_interrupt,
216198 0, pdev->name, rtcdrv);
217199 if (err)
218200 return err;
219201
220− return 0;
202+ return rtc_register_device(rtcdrv->rtc);
221203 }
222204
223205 static const struct of_device_id goldfish_rtc_of_match[] = {
drivers/rtc/rtc-hid-sensor-time.c+1−2
@@ -205,8 +205,7 @@ static int hid_time_parse_report(struct platform_device *pdev, · 204 unmodified lines
205205 static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
206206 {
207207 unsigned long flags;
208− struct hid_time_state *time_state =
209− platform_get_drvdata(to_platform_device(dev));
208+ struct hid_time_state *time_state = dev_get_drvdata(dev);
210209 int ret;
211210
212211 reinit_completion(&time_state->comp_last_time);
drivers/rtc/rtc-imxdi.c+17−33
@@ -1,19 +1,9 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
34 * Copyright 2010 Orex Computed Radiography
45 */
56
6−/*
7− * The code contained herein is licensed under the GNU General Public
8− * License. You may obtain a copy of the GNU General Public License
9− * Version 2 or later at the following locations:
10− *
11− * http://www.opensource.org/licenses/gpl-license.html
12− * http://www.gnu.org/copyleft/gpl.html
13− */
14−
15−/* based on rtc-mc13892.c */
16−
177 /*
188 * This driver uses the 47-bit 32 kHz counter in the Freescale DryIce block
199 * to implement a Linux RTC. Times and alarms are truncated to seconds.
@@ -552,7 +542,7 @@ static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm) · 532 unmodified lines
552542 unsigned long now;
553543
554544 now = readl(imxdi->ioaddr + DTCMR);
555− rtc_time_to_tm(now, tm);
545+ rtc_time64_to_tm(now, tm);
556546
557547 return 0;
558548 }
@@ -561,7 +551,7 @@ static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm) · 2 unmodified lines
561551 * set the seconds portion of dryice time counter and clear the
562552 * fractional part.
563553 */
564−static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs)
554+static int dryice_rtc_set_time(struct device *dev, struct rtc_time *tm)
565555 {
566556 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
567557 u32 dcr, dsr;
@@ -588,7 +578,7 @@ static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs) · 20 unmodified lines
588578 if (rc != 0)
589579 return rc;
590580
591− rc = di_write_wait(imxdi, secs, DTCMR);
581+ rc = di_write_wait(imxdi, rtc_tm_to_time64(tm), DTCMR);
592582 if (rc != 0)
593583 return rc;
594584
@@ -618,7 +608,7 @@ static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 23 unmodified lines
618608 u32 dcamr;
619609
620610 dcamr = readl(imxdi->ioaddr + DCAMR);
621− rtc_time_to_tm(dcamr, &alarm->time);
611+ rtc_time64_to_tm(dcamr, &alarm->time);
622612
623613 /* alarm is enabled if the interrupt is enabled */
624614 alarm->enabled = (readl(imxdi->ioaddr + DIER) & DIER_CAIE) != 0;
@@ -640,21 +630,10 @@ static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 15 unmodified lines
640630 static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
641631 {
642632 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
643− unsigned long now;
644− unsigned long alarm_time;
645633 int rc;
646634
647− rc = rtc_tm_to_time(&alarm->time, &alarm_time);
648− if (rc)
649− return rc;
650−
651− /* don't allow setting alarm in the past */
652− now = readl(imxdi->ioaddr + DTCMR);
653− if (alarm_time < now)
654− return -EINVAL;
655−
656635 /* write the new alarm time */
657− rc = di_write_wait(imxdi, (u32)alarm_time, DCAMR);
636+ rc = di_write_wait(imxdi, rtc_tm_to_time64(&alarm->time), DCAMR);
658637 if (rc)
659638 return rc;
660639
@@ -668,7 +647,7 @@ static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 7 unmodified lines
668647
669648 static const struct rtc_class_ops dryice_rtc_ops = {
670649 .read_time = dryice_rtc_read_time,
671− .set_mmss = dryice_rtc_set_mmss,
650+ .set_time = dryice_rtc_set_time,
672651 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
673652 .read_alarm = dryice_rtc_read_alarm,
674653 .set_alarm = dryice_rtc_set_alarm,
@@ -796,6 +775,10 @@ static int __init dryice_rtc_probe(struct platform_device *pdev) · 121 unmodified lines
796775
797776 mutex_init(&imxdi->write_mutex);
798777
778+ imxdi->rtc = devm_rtc_allocate_device(&pdev->dev);
779+ if (IS_ERR(imxdi->rtc))
780+ return PTR_ERR(imxdi->rtc);
781+
799782 imxdi->clk = devm_clk_get(&pdev->dev, NULL);
800783 if (IS_ERR(imxdi->clk))
801784 return PTR_ERR(imxdi->clk);
@@ -829,12 +812,13 @@ static int __init dryice_rtc_probe(struct platform_device *pdev) · 27 unmodified lines
829812 }
830813
831814 platform_set_drvdata(pdev, imxdi);
832− imxdi->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
833− &dryice_rtc_ops, THIS_MODULE);
834− if (IS_ERR(imxdi->rtc)) {
835− rc = PTR_ERR(imxdi->rtc);
815+
816+ imxdi->rtc->ops = &dryice_rtc_ops;
817+ imxdi->rtc->range_max = U32_MAX;
818+
819+ rc = rtc_register_device(imxdi->rtc);
820+ if (rc)
836821 goto err;
837− }
838822
839823 return 0;
840824
drivers/rtc/rtc-jz4740.c+33−62
@@ -1,17 +1,8 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
34 * Copyright (C) 2010, Paul Cercueil <paul@crapouillou.net>
45 * JZ4740 SoC RTC driver
5− *
6− * This program is free software; you can redistribute it and/or modify it
7− * under the terms of the GNU General Public License as published by the
8− * Free Software Foundation; either version 2 of the License, or (at your
9− * option) any later version.
10− *
11− * You should have received a copy of the GNU General Public License along
12− * with this program; if not, write to the Free Software Foundation, Inc.,
13− * 675 Mass Ave, Cambridge, MA 02139, USA.
14− *
156 */
167
178 #include <linux/clk.h>
@@ -20,6 +11,7 @@ · 2 unmodified lines
2011 #include <linux/module.h>
2112 #include <linux/of_device.h>
2213 #include <linux/platform_device.h>
14+#include <linux/pm_wakeirq.h>
2315 #include <linux/reboot.h>
2416 #include <linux/rtc.h>
2517 #include <linux/slab.h>
@@ -156,6 +148,9 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time) · 130 unmodified lines
156148 uint32_t secs, secs2;
157149 int timeout = 5;
158150
151+ if (jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD) != 0x12345678)
152+ return -EINVAL;
153+
159154 /* If the seconds register is read while it is updated, it can contain a
160155 * bogus value. This can be avoided by making sure that two consecutive
161156 * reads have the same value.
@@ -171,16 +166,21 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time) · 9 unmodified lines
171166 if (timeout == 0)
172167 return -EIO;
173168
174− rtc_time_to_tm(secs, time);
169+ rtc_time64_to_tm(secs, time);
175170
176171 return 0;
177172 }
178173
179−static int jz4740_rtc_set_mmss(struct device *dev, unsigned long secs)
174+static int jz4740_rtc_set_time(struct device *dev, struct rtc_time *time)
180175 {
181176 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
177+ int ret;
182178
183− return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, secs);
179+ ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, rtc_tm_to_time64(time));
180+ if (ret)
181+ return ret;
182+
183+ return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678);
184184 }
185185
186186 static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
@@ -196,18 +196,16 @@ static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 9 unmodified lines
196196 alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE);
197197 alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF);
198198
199− rtc_time_to_tm(secs, &alrm->time);
199+ rtc_time64_to_tm(secs, &alrm->time);
200200
201− return rtc_valid_tm(&alrm->time);
201+ return 0;
202202 }
203203
204204 static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
205205 {
206206 int ret;
207207 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
208− unsigned long secs;
209−
210− rtc_tm_to_time(&alrm->time, &secs);
208+ uint32_t secs = lower_32_bits(rtc_tm_to_time64(&alrm->time));
211209
212210 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs);
213211 if (!ret)
@@ -225,7 +223,7 @@ static int jz4740_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) · 11 unmodified lines
225223
226224 static const struct rtc_class_ops jz4740_rtc_ops = {
227225 .read_time = jz4740_rtc_read_time,
228− .set_mmss = jz4740_rtc_set_mmss,
226+ .set_time = jz4740_rtc_set_time,
229227 .read_alarm = jz4740_rtc_read_alarm,
230228 .set_alarm = jz4740_rtc_set_alarm,
231229 .alarm_irq_enable = jz4740_rtc_alarm_irq_enable,
@@ -309,7 +307,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) · 77 unmodified lines
309307 {
310308 int ret;
311309 struct jz4740_rtc *rtc;
312− uint32_t scratchpad;
313310 struct resource *mem;
314311 const struct platform_device_id *id = platform_get_device_id(pdev);
315312 const struct of_device_id *of_id = of_match_device(
@@ -348,10 +345,24 @@ static int jz4740_rtc_probe(struct platform_device *pdev) · 32 unmodified lines
348345
349346 device_init_wakeup(&pdev->dev, 1);
350347
351− rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
352− &jz4740_rtc_ops, THIS_MODULE);
348+ ret = dev_pm_set_wake_irq(&pdev->dev, rtc->irq);
349+ if (ret) {
350+ dev_err(&pdev->dev, "Failed to set wake irq: %d\n", ret);
351+ return ret;
352+ }
353+
354+ rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
353355 if (IS_ERR(rtc->rtc)) {
354356 ret = PTR_ERR(rtc->rtc);
357+ dev_err(&pdev->dev, "Failed to allocate rtc device: %d\n", ret);
358+ return ret;
359+ }
360+
361+ rtc->rtc->ops = &jz4740_rtc_ops;
362+ rtc->rtc->range_max = U32_MAX;
363+
364+ ret = rtc_register_device(rtc->rtc);
365+ if (ret) {
355366 dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret);
356367 return ret;
357368 }
@@ -363,16 +374,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) · 5 unmodified lines
363374 return ret;
364375 }
365376
366− scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD);
367− if (scratchpad != 0x12345678) {
368− ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678);
369− ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0);
370− if (ret) {
371− dev_err(&pdev->dev, "Could not write to RTC registers\n");
372− return ret;
373− }
374− }
375−
376377 if (np && of_device_is_system_power_controller(np)) {
377378 if (!pm_power_off) {
378379 /* Default: 60ms */
@@ -397,35 +398,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) · 18 unmodified lines
397398 return 0;
398399 }
399400
400−#ifdef CONFIG_PM
401−static int jz4740_rtc_suspend(struct device *dev)
402−{
403− struct jz4740_rtc *rtc = dev_get_drvdata(dev);
404−
405− if (device_may_wakeup(dev))
406− enable_irq_wake(rtc->irq);
407− return 0;
408−}
409−
410−static int jz4740_rtc_resume(struct device *dev)
411−{
412− struct jz4740_rtc *rtc = dev_get_drvdata(dev);
413−
414− if (device_may_wakeup(dev))
415− disable_irq_wake(rtc->irq);
416− return 0;
417−}
418−
419−static const struct dev_pm_ops jz4740_pm_ops = {
420− .suspend = jz4740_rtc_suspend,
421− .resume = jz4740_rtc_resume,
422−};
423−#define JZ4740_RTC_PM_OPS (&jz4740_pm_ops)
424−
425−#else
426−#define JZ4740_RTC_PM_OPS NULL
427−#endif /* CONFIG_PM */
428−
429401 static const struct platform_device_id jz4740_rtc_ids[] = {
430402 { "jz4740-rtc", ID_JZ4740 },
431403 { "jz4780-rtc", ID_JZ4780 },
@@ -437,7 +409,6 @@ static struct platform_driver jz4740_rtc_driver = { · 5 unmodified lines
437409 .probe = jz4740_rtc_probe,
438410 .driver = {
439411 .name = "jz4740-rtc",
440− .pm = JZ4740_RTC_PM_OPS,
441412 .of_match_table = of_match_ptr(jz4740_rtc_of_match),
442413 },
443414 .id_table = jz4740_rtc_ids,
drivers/rtc/rtc-lpc32xx.c+22−37
@@ -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 @@ · 32 unmodified lines
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 @@ static int lpc32xx_rtc_read_time(struct device *dev, struct rtc_time *time) · 13 unmodified lines
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 @@ static int lpc32xx_rtc_read_alarm(struct device *dev, · 15 unmodified lines
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 @@ static int lpc32xx_rtc_set_alarm(struct device *dev, · 7 unmodified lines
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 @@ static irqreturn_t lpc32xx_rtc_alarm_interrupt(int irq, void *dev) · 67 unmodified lines
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,
@@ -201,21 +187,13 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev) · 3 unmodified lines
201187 {
202188 struct resource *res;
203189 struct lpc32xx_rtc *rtc;
204− int rtcirq;
190+ int err;
205191 u32 tmp;
206192
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−
213193 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
214194 if (unlikely(!rtc))
215195 return -ENOMEM;
216196
217− rtc->irq = rtcirq;
218−
219197 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
220198 rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
221199 if (IS_ERR(rtc->rtc_base))
@@ -256,18 +234,25 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev) · 34 unmodified lines
256234
257235 platform_set_drvdata(pdev, rtc);
258236
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");
237+ rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
238+ if (IS_ERR(rtc->rtc))
263239 return PTR_ERR(rtc->rtc);
264− }
240+
241+ rtc->rtc->ops = &lpc32xx_rtc_ops;
242+ rtc->rtc->range_max = U32_MAX;
243+
244+ err = rtc_register_device(rtc->rtc);
245+ if (err)
246+ return err;
265247
266248 /*
267249 * IRQ is enabled after device registration in case alarm IRQ
268250 * is pending upon suspend exit.
269251 */
270− if (rtc->irq >= 0) {
252+ rtc->irq = platform_get_irq(pdev, 0);
253+ if (rtc->irq < 0) {
254+ dev_warn(&pdev->dev, "Can't get interrupt resource\n");
255+ } else {
271256 if (devm_request_irq(&pdev->dev, rtc->irq,
272257 lpc32xx_rtc_alarm_interrupt,
273258 0, pdev->name, rtc) < 0) {
@@ -374,7 +359,7 @@ static struct platform_driver lpc32xx_rtc_driver = { · 100 unmodified lines
374359 .probe = lpc32xx_rtc_probe,
375360 .remove = lpc32xx_rtc_remove,
376361 .driver = {
377− .name = RTC_NAME,
362+ .name = "rtc-lpc32xx",
378363 .pm = LPC32XX_RTC_PM_OPS,
379364 .of_match_table = of_match_ptr(lpc32xx_rtc_match),
380365 },
drivers/rtc/rtc-mc13xxx.c+15−10
@@ -1,12 +1,9 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Real Time Clock driver for Freescale MC13XXX PMIC
34 *
45 * (C) 2009 Sascha Hauer, Pengutronix
56 * (C) 2009 Uwe Kleine-Koenig, Pengutronix
6− *
7− * This program is free software; you can redistribute it and/or modify
8− * it under the terms of the GNU General Public License version 2 as
9− * published by the Free Software Foundation.
107 */
118
129 #include <linux/mfd/mc13xxx.h>
@@ -89,14 +86,14 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) · 76 unmodified lines
8986 return 0;
9087 }
9188
92−static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs)
89+static int mc13xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
9390 {
9491 struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
9592 unsigned int seconds, days;
9693 unsigned int alarmseconds;
9794 int ret;
9895
99− days = div_s64_rem(secs, SEC_PER_DAY, &seconds);
96+ days = div_s64_rem(rtc_tm_to_time64(tm), SEC_PER_DAY, &seconds);
10097
10198 mc13xxx_lock(priv->mc13xxx);
10299
@@ -158,7 +155,7 @@ out: · 55 unmodified lines
158155 static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
159156 {
160157 struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
161− unsigned seconds, days;
158+ unsigned int seconds, days;
162159 time64_t s1970;
163160 int enabled, pending;
164161 int ret;
@@ -253,7 +250,7 @@ static irqreturn_t mc13xxx_rtc_alarm_handler(int irq, void *dev) · 88 unmodified lines
253250
254251 static const struct rtc_class_ops mc13xxx_rtc_ops = {
255252 .read_time = mc13xxx_rtc_read_time,
256− .set_mmss64 = mc13xxx_rtc_set_mmss,
253+ .set_time = mc13xxx_rtc_set_time,
257254 .read_alarm = mc13xxx_rtc_read_alarm,
258255 .set_alarm = mc13xxx_rtc_set_alarm,
259256 .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable,
@@ -285,8 +282,15 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev) · 25 unmodified lines
285282 priv->mc13xxx = mc13xxx;
286283 priv->valid = 1;
287284
285+ priv->rtc = devm_rtc_allocate_device(&pdev->dev);
286+ if (IS_ERR(priv->rtc))
287+ return PTR_ERR(priv->rtc);
288288 platform_set_drvdata(pdev, priv);
289289
290+ priv->rtc->ops = &mc13xxx_rtc_ops;
291+ /* 15bit days + hours, minutes, seconds */
292+ priv->rtc->range_max = (timeu64_t)(1 << 15) * SEC_PER_DAY - 1;
293+
290294 mc13xxx_lock(mc13xxx);
291295
292296 mc13xxx_irq_ack(mc13xxx, MC13XXX_IRQ_RTCRST);
@@ -303,8 +307,9 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev) · 10 unmodified lines
303307
304308 mc13xxx_unlock(mc13xxx);
305309
306− priv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
307− &mc13xxx_rtc_ops, THIS_MODULE);
310+ ret = rtc_register_device(priv->rtc);
311+ if (ret)
312+ goto err_irq_request;
308313
309314 return 0;
310315
drivers/rtc/rtc-mt6397.c+3−6
@@ -343,7 +343,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) · 342 unmodified lines
343343 if (ret) {
344344 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
345345 rtc->irq, ret);
346− goto out_dispose_irq;
346+ return ret;
347347 }
348348
349349 device_init_wakeup(&pdev->dev, 1);
@@ -359,9 +359,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) · 9 unmodified lines
359359 return 0;
360360
361361 out_free_irq:
362− free_irq(rtc->irq, rtc->rtc_dev);
363−out_dispose_irq:
364− irq_dispose_mapping(rtc->irq);
362+ free_irq(rtc->irq, rtc);
365363 return ret;
366364 }
367365
@@ -369,8 +367,7 @@ static int mtk_rtc_remove(struct platform_device *pdev) · 1 unmodified line
369367 {
370368 struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
371369
372− free_irq(rtc->irq, rtc->rtc_dev);
373− irq_dispose_mapping(rtc->irq);
370+ free_irq(rtc->irq, rtc);
374371
375372 return 0;
376373 }
drivers/rtc/rtc-mv.c+17−16
@@ -1,9 +1,6 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Driver for the RTC in Marvell SoCs.
3− *
4− * This file is licensed under the terms of the GNU General Public
5− * License version 2. This program is licensed "as is" without any
6− * warranty of any kind, whether express or implied.
74 */
85
96 #include <linux/init.h>
@@ -60,7 +57,7 @@ static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm) · 50 unmodified lines
6057
6158 rtc_reg = (bin2bcd(tm->tm_mday) << RTC_MDAY_OFFS) |
6259 (bin2bcd(tm->tm_mon + 1) << RTC_MONTH_OFFS) |
63− (bin2bcd(tm->tm_year % 100) << RTC_YEAR_OFFS);
60+ (bin2bcd(tm->tm_year - 100) << RTC_YEAR_OFFS);
6461 writel(rtc_reg, ioaddr + RTC_DATE_REG_OFFS);
6562
6663 return 0;
@@ -159,7 +156,7 @@ static int mv_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) · 92 unmodified lines
159156 << RTC_MONTH_OFFS;
160157
161158 if (alm->time.tm_year >= 0)
162− rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_year % 100))
159+ rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_year - 100))
163160 << RTC_YEAR_OFFS;
164161
165162 writel(rtc_reg, ioaddr + RTC_ALARM_DATE_REG_OFFS);
@@ -257,15 +254,7 @@ static int __init mv_rtc_probe(struct platform_device *pdev) · 91 unmodified lines
257254
258255 platform_set_drvdata(pdev, pdata);
259256
260− if (pdata->irq >= 0) {
261− device_init_wakeup(&pdev->dev, 1);
262− pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
263− &mv_rtc_alarm_ops,
264− THIS_MODULE);
265− } else {
266− pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
267− &mv_rtc_ops, THIS_MODULE);
268− }
257+ pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
269258 if (IS_ERR(pdata->rtc)) {
270259 ret = PTR_ERR(pdata->rtc);
271260 goto out;
@@ -281,7 +270,19 @@ static int __init mv_rtc_probe(struct platform_device *pdev) · 9 unmodified lines
281270 }
282271 }
283272
284− return 0;
273+ if (pdata->irq >= 0) {
274+ device_init_wakeup(&pdev->dev, 1);
275+ pdata->rtc->ops = &mv_rtc_alarm_ops;
276+ } else {
277+ pdata->rtc->ops = &mv_rtc_ops;
278+ }
279+
280+ pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
281+ pdata->rtc->range_max = RTC_TIMESTAMP_END_2099;
282+
283+ ret = rtc_register_device(pdata->rtc);
284+ if (!ret)
285+ return 0;
285286 out:
286287 if (!IS_ERR(pdata->clk))
287288 clk_disable_unprepare(pdata->clk);
drivers/rtc/rtc-mxc.c+36−50
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #include <linux/slab.h>
99 #include <linux/interrupt.h>
1010 #include <linux/platform_device.h>
11+#include <linux/pm_wakeirq.h>
1112 #include <linux/clk.h>
1213 #include <linux/of.h>
1314 #include <linux/of_device.h>
@@ -253,20 +254,9 @@ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) · 239 unmodified lines
253254 /*
254255 * This function sets the internal RTC time based on tm in Gregorian date.
255256 */
256−static int mxc_rtc_set_mmss(struct device *dev, time64_t time)
257+static int mxc_rtc_set_time(struct device *dev, struct rtc_time *tm)
257258 {
258− struct rtc_plat_data *pdata = dev_get_drvdata(dev);
259−
260− /*
261− * TTC_DAYR register is 9-bit in MX1 SoC, save time and day of year only
262− */
263− if (is_imx1_rtc(pdata)) {
264− struct rtc_time tm;
265−
266− rtc_time64_to_tm(time, &tm);
267− tm.tm_year = 70;
268− time = rtc_tm_to_time64(&tm);
269− }
259+ time64_t time = rtc_tm_to_time64(tm);
270260
271261 /* Avoid roll-over from reading the different registers */
272262 do {
@@ -310,7 +300,7 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 37 unmodified lines
310300 /* RTC layer */
311301 static const struct rtc_class_ops mxc_rtc_ops = {
312302 .read_time = mxc_rtc_read_time,
313− .set_mmss64 = mxc_rtc_set_mmss,
303+ .set_time = mxc_rtc_set_time,
314304 .read_alarm = mxc_rtc_read_alarm,
315305 .set_alarm = mxc_rtc_set_alarm,
316306 .alarm_irq_enable = mxc_rtc_alarm_irq_enable,
@@ -318,7 +308,6 @@ static const struct rtc_class_ops mxc_rtc_ops = { · 1 unmodified line
318308
319309 static int mxc_rtc_probe(struct platform_device *pdev)
320310 {
321− struct resource *res;
322311 struct rtc_device *rtc;
323312 struct rtc_plat_data *pdata = NULL;
324313 u32 reg;
@@ -336,11 +325,34 @@ static int mxc_rtc_probe(struct platform_device *pdev) · 11 unmodified lines
336325 else
337326 pdata->devtype = pdev->id_entry->driver_data;
338327
339− res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
340− pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res);
328+ pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0);
341329 if (IS_ERR(pdata->ioaddr))
342330 return PTR_ERR(pdata->ioaddr);
343331
332+ rtc = devm_rtc_allocate_device(&pdev->dev);
333+ if (IS_ERR(rtc))
334+ return PTR_ERR(rtc);
335+
336+ pdata->rtc = rtc;
337+ rtc->ops = &mxc_rtc_ops;
338+ if (is_imx1_rtc(pdata)) {
339+ struct rtc_time tm;
340+
341+ /* 9bit days + hours minutes seconds */
342+ rtc->range_max = (1 << 9) * 86400 - 1;
343+
344+ /*
345+ * Set the start date as beginning of the current year. This can
346+ * be overridden using device tree.
347+ */
348+ rtc_time64_to_tm(ktime_get_real_seconds(), &tm);
349+ rtc->start_secs = mktime64(tm.tm_year, 1, 1, 0, 0, 0);
350+ rtc->set_start_time = true;
351+ } else {
352+ /* 16bit days + hours minutes seconds */
353+ rtc->range_max = (1 << 16) * 86400ULL - 1;
354+ }
355+
344356 pdata->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
345357 if (IS_ERR(pdata->clk_ipg)) {
346358 dev_err(&pdev->dev, "unable to get ipg clock!\n");
@@ -396,17 +408,16 @@ static int mxc_rtc_probe(struct platform_device *pdev) · 49 unmodified lines
396408 pdata->irq = -1;
397409 }
398410
399− if (pdata->irq >= 0)
411+ if (pdata->irq >= 0) {
400412 device_init_wakeup(&pdev->dev, 1);
401−
402− rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops,
403− THIS_MODULE);
404− if (IS_ERR(rtc)) {
405− ret = PTR_ERR(rtc);
406− goto exit_put_clk_ref;
413+ ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq);
414+ if (ret)
415+ dev_err(&pdev->dev, "failed to enable irq wake\n");
407416 }
408417
409− pdata->rtc = rtc;
418+ ret = rtc_register_device(rtc);
419+ if (ret)
420+ goto exit_put_clk_ref;
410421
411422 return 0;
412423
@@ -428,35 +439,10 @@ static int mxc_rtc_remove(struct platform_device *pdev) · 15 unmodified lines
428439 return 0;
429440 }
430441
431−#ifdef CONFIG_PM_SLEEP
432−static int mxc_rtc_suspend(struct device *dev)
433−{
434− struct rtc_plat_data *pdata = dev_get_drvdata(dev);
435−
436− if (device_may_wakeup(dev))
437− enable_irq_wake(pdata->irq);
438−
439− return 0;
440−}
441−
442−static int mxc_rtc_resume(struct device *dev)
443−{
444− struct rtc_plat_data *pdata = dev_get_drvdata(dev);
445−
446− if (device_may_wakeup(dev))
447− disable_irq_wake(pdata->irq);
448−
449− return 0;
450−}
451−#endif
452−
453−static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
454−
455442 static struct platform_driver mxc_rtc_driver = {
456443 .driver = {
457444 .name = "mxc_rtc",
458445 .of_match_table = of_match_ptr(imx_rtc_dt_ids),
459− .pm = &mxc_rtc_pm_ops,
460446 },
461447 .id_table = imx_rtc_devtype,
462448 .probe = mxc_rtc_probe,
drivers/rtc/rtc-mxc_v2.c+4−25
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/module.h>
1111 #include <linux/mod_devicetable.h>
1212 #include <linux/platform_device.h>
13+#include <linux/pm_wakeirq.h>
1314 #include <linux/rtc.h>
1415
1516 #define SRTC_LPPDR_INIT 0x41736166 /* init for glitch detect */
@@ -305,6 +306,9 @@ static int mxc_rtc_probe(struct platform_device *pdev) · 289 unmodified lines
305306 return pdata->irq;
306307
307308 device_init_wakeup(&pdev->dev, 1);
309+ ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq);
310+ if (ret)
311+ dev_err(&pdev->dev, "failed to enable irq wake\n");
308312
309313 ret = clk_prepare_enable(pdata->clk);
310314 if (ret)
@@ -367,30 +371,6 @@ static int mxc_rtc_remove(struct platform_device *pdev) · 56 unmodified lines
367371 return 0;
368372 }
369373
370−#ifdef CONFIG_PM_SLEEP
371−static int mxc_rtc_suspend(struct device *dev)
372−{
373− struct mxc_rtc_data *pdata = dev_get_drvdata(dev);
374−
375− if (device_may_wakeup(dev))
376− enable_irq_wake(pdata->irq);
377−
378− return 0;
379−}
380−
381−static int mxc_rtc_resume(struct device *dev)
382−{
383− struct mxc_rtc_data *pdata = dev_get_drvdata(dev);
384−
385− if (device_may_wakeup(dev))
386− disable_irq_wake(pdata->irq);
387−
388− return 0;
389−}
390−#endif
391−
392−static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
393−
394374 static const struct of_device_id mxc_ids[] = {
395375 { .compatible = "fsl,imx53-rtc", },
396376 {}
@@ -400,7 +380,6 @@ static struct platform_driver mxc_rtc_driver = { · 3 unmodified lines
400380 .driver = {
401381 .name = "mxc_rtc_v2",
402382 .of_match_table = mxc_ids,
403− .pm = &mxc_rtc_pm_ops,
404383 },
405384 .probe = mxc_rtc_probe,
406385 .remove = mxc_rtc_remove,
drivers/rtc/rtc-omap.c+9−23
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * TI OMAP Real Time Clock interface for Linux
34 *
@@ -6,11 +7,6 @@ · 2 unmodified lines
67 *
78 * Copyright (C) 2006 David Brownell (new RTC framework)
89 * Copyright (C) 2014 Johan Hovold <johan@kernel.org>
9− *
10− * This program is free software; you can redistribute it and/or
11− * modify it under the terms of the GNU General Public License
12− * as published by the Free Software Foundation; either version
13− * 2 of the License, or (at your option) any later version.
1410 */
1511
1612 #include <dt-bindings/gpio/gpio.h>
@@ -271,7 +267,7 @@ static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 254 unmodified lines
271267 }
272268
273269 /* this hardware doesn't support "don't care" alarm fields */
274−static int tm2bcd(struct rtc_time *tm)
270+static void tm2bcd(struct rtc_time *tm)
275271 {
276272 tm->tm_sec = bin2bcd(tm->tm_sec);
277273 tm->tm_min = bin2bcd(tm->tm_min);
@@ -279,13 +275,7 @@ static int tm2bcd(struct rtc_time *tm) · 1 unmodified line
279275 tm->tm_mday = bin2bcd(tm->tm_mday);
280276
281277 tm->tm_mon = bin2bcd(tm->tm_mon + 1);
282−
283− /* epoch == 1900 */
284− if (tm->tm_year < 100 || tm->tm_year > 199)
285− return -EINVAL;
286278 tm->tm_year = bin2bcd(tm->tm_year - 100);
287−
288− return 0;
289279 }
290280
291281 static void bcd2tm(struct rtc_time *tm)
@@ -328,8 +318,7 @@ static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm) · 36 unmodified lines
328318 {
329319 struct omap_rtc *rtc = dev_get_drvdata(dev);
330320
331− if (tm2bcd(tm) < 0)
332− return -EINVAL;
321+ tm2bcd(tm);
333322
334323 local_irq_disable();
335324 rtc_wait_not_busy(rtc);
@@ -378,8 +367,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) · 42 unmodified lines
378367 struct omap_rtc *rtc = dev_get_drvdata(dev);
379368 u8 reg, irqwake_reg = 0;
380369
381− if (tm2bcd(&alm->time) < 0)
382− return -EINVAL;
370+ tm2bcd(&alm->time);
383371
384372 local_irq_disable();
385373 rtc_wait_not_busy(rtc);
@@ -441,14 +429,10 @@ again: · 55 unmodified lines
441429 omap_rtc_read_time_raw(rtc, &tm);
442430 seconds = tm.tm_sec;
443431 bcd2tm(&tm);
444− rtc_tm_to_time(&tm, &now);
445− rtc_time_to_tm(now + 1, &tm);
432+ now = rtc_tm_to_time64(&tm);
433+ rtc_time64_to_tm(now + 1, &tm);
446434
447− if (tm2bcd(&tm) < 0) {
448− dev_err(&rtc->rtc->dev, "power off failed\n");
449− rtc->type->lock(rtc);
450− return;
451− }
435+ tm2bcd(&tm);
452436
453437 rtc_wait_not_busy(rtc);
454438
@@ -845,6 +829,8 @@ static int omap_rtc_probe(struct platform_device *pdev) · 390 unmodified lines
845829 }
846830
847831 rtc->rtc->ops = &omap_rtc_ops;
832+ rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
833+ rtc->rtc->range_max = RTC_TIMESTAMP_END_2099;
848834 omap_rtc_nvmem_config.priv = rtc;
849835
850836 /* handle periodic and alarm irqs */
drivers/rtc/rtc-opal.c+1−1
@@ -224,7 +224,7 @@ exit: · 223 unmodified lines
224224 return rc;
225225 }
226226
227−int opal_tpo_alarm_irq_enable(struct device *dev, unsigned int enabled)
227+static int opal_tpo_alarm_irq_enable(struct device *dev, unsigned int enabled)
228228 {
229229 struct rtc_wkalrm alarm = { .enabled = 0 };
230230
drivers/rtc/rtc-pcap.c+12−16
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * pcap rtc code for Motorola EZX phones
34 *
@@ -5,11 +6,6 @@ · 1 unmodified line
56 * Copyright (c) 2009 Daniel Ribeiro <drwyrm@gmail.com>
67 *
78 * Based on Motorola's rtc.c Copyright (c) 2003-2005 Motorola
8− *
9− * This program is free software; you can redistribute it and/or modify
10− * it under the terms of the GNU General Public License version 2 as
11− * published by the Free Software Foundation.
12− *
139 */
1410
1511 #include <linux/kernel.h>
@@ -55,7 +51,7 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 39 unmodified lines
5551 ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAYA, &days);
5652 secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY;
5753
58− rtc_time_to_tm(secs, tm);
54+ rtc_time64_to_tm(secs, tm);
5955
6056 return 0;
6157 }
@@ -63,12 +59,9 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 1 unmodified line
6359 static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
6460 {
6561 struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev);
66− struct rtc_time *tm = &alrm->time;
67− unsigned long secs;
62+ unsigned long secs = rtc_tm_to_time64(&alrm->time);
6863 u32 tod, days;
6964
70− rtc_tm_to_time(tm, &secs);
71−
7265 tod = secs % SEC_PER_DAY;
7366 ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_TODA, tod);
7467
@@ -90,14 +83,15 @@ static int pcap_rtc_read_time(struct device *dev, struct rtc_time *tm) · 15 unmodified lines
9083 ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAY, &days);
9184 secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY;
9285
93− rtc_time_to_tm(secs, tm);
86+ rtc_time64_to_tm(secs, tm);
9487
9588 return 0;
9689 }
9790
98−static int pcap_rtc_set_mmss(struct device *dev, unsigned long secs)
91+static int pcap_rtc_set_time(struct device *dev, struct rtc_time *tm)
9992 {
10093 struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev);
94+ unsigned long secs = rtc_tm_to_time64(tm);
10195 u32 tod, days;
10296
10397 tod = secs % SEC_PER_DAY;
@@ -128,9 +122,9 @@ static int pcap_rtc_alarm_irq_enable(struct device *dev, unsigned int en) · 24 unmodified lines
128122
129123 static const struct rtc_class_ops pcap_rtc_ops = {
130124 .read_time = pcap_rtc_read_time,
125+ .set_time = pcap_rtc_set_time,
131126 .read_alarm = pcap_rtc_read_alarm,
132127 .set_alarm = pcap_rtc_set_alarm,
133− .set_mmss = pcap_rtc_set_mmss,
134128 .alarm_irq_enable = pcap_rtc_alarm_irq_enable,
135129 };
136130
@@ -149,11 +143,13 @@ static int __init pcap_rtc_probe(struct platform_device *pdev) · 12 unmodified lines
149143
150144 platform_set_drvdata(pdev, pcap_rtc);
151145
152− pcap_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pcap",
153− &pcap_rtc_ops, THIS_MODULE);
146+ pcap_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
154147 if (IS_ERR(pcap_rtc->rtc))
155148 return PTR_ERR(pcap_rtc->rtc);
156149
150+ pcap_rtc->rtc->ops = &pcap_rtc_ops;
151+ pcap_rtc->rtc->range_max = (1 << 14) * 86400ULL - 1;
152+
157153 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ);
158154 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA);
159155
@@ -167,7 +163,7 @@ static int __init pcap_rtc_probe(struct platform_device *pdev) · 7 unmodified lines
167163 if (err)
168164 return err;
169165
170− return 0;
166+ return rtc_register_device(pcap_rtc->rtc);
171167 }
172168
173169 static int __exit pcap_rtc_remove(struct platform_device *pdev)
drivers/rtc/rtc-pcf85063.c+339−107
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * An I2C driver for the PCF85063 RTC
34 * Copyright 2014 Rose Technology
@@ -5,16 +6,16 @@ · 1 unmodified line
56 * Author: Søren Andersen <san@rosetechnology.dk>
67 * Maintainers: http://www.nslu2-linux.org/
78 *
8− * based on the other drivers in this same directory.
9− *
10− * This program is free software; you can redistribute it and/or modify
11− * it under the terms of the GNU General Public License version 2 as
12− * published by the Free Software Foundation.
9+ * Copyright (C) 2019 Micro Crystal AG
10+ * Author: Alexandre Belloni <alexandre.belloni@bootlin.com>
1311 */
1412 #include <linux/i2c.h>
1513 #include <linux/bcd.h>
1614 #include <linux/rtc.h>
1715 #include <linux/module.h>
16+#include <linux/of_device.h>
17+#include <linux/pm_wakeirq.h>
18+#include <linux/regmap.h>
1819
1920 /*
2021 * Information for this driver was pulled from the following datasheets.
@@ -24,61 +25,47 @@ · 3 unmodified lines
2425 *
2526 * PCF85063A -- Rev. 6 — 18 November 2015
2627 * PCF85063TP -- Rev. 4 — 6 May 2015
27−*/
28+ *
29+ * https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8263-C7_App-Manual.pdf
30+ * RV8263 -- Rev. 1.0 — January 2019
31+ */
2832
2933 #define PCF85063_REG_CTRL1 0x00 /* status */
3034 #define PCF85063_REG_CTRL1_CAP_SEL BIT(0)
3135 #define PCF85063_REG_CTRL1_STOP BIT(5)
3236
33−#define PCF85063_REG_SC 0x04 /* datetime */
34−#define PCF85063_REG_SC_OS 0x80
35−
36−static struct i2c_driver pcf85063_driver;
37−
38−static int pcf85063_stop_clock(struct i2c_client *client, u8 *ctrl1)
39−{
40− int rc;
41− u8 reg;
37+#define PCF85063_REG_CTRL2 0x01
38+#define PCF85063_CTRL2_AF BIT(6)
39+#define PCF85063_CTRL2_AIE BIT(7)
4240
43− rc = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1);
44− if (rc < 0) {
45− dev_err(&client->dev, "Failing to stop the clock\n");
46− return -EIO;
47− }
41+#define PCF85063_REG_OFFSET 0x02
42+#define PCF85063_OFFSET_SIGN_BIT 6 /* 2's complement sign bit */
43+#define PCF85063_OFFSET_MODE BIT(7)
44+#define PCF85063_OFFSET_STEP0 4340
45+#define PCF85063_OFFSET_STEP1 4069
4846
49− /* stop the clock */
50− reg = rc | PCF85063_REG_CTRL1_STOP;
47+#define PCF85063_REG_RAM 0x03
5148
52− rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, reg);
53− if (rc < 0) {
54− dev_err(&client->dev, "Failing to stop the clock\n");
55− return -EIO;
56− }
57−
58− *ctrl1 = reg;
59−
60− return 0;
61−}
62−
63−static int pcf85063_start_clock(struct i2c_client *client, u8 ctrl1)
64−{
65− int rc;
49+#define PCF85063_REG_SC 0x04 /* datetime */
50+#define PCF85063_REG_SC_OS 0x80
6651
67− /* start the clock */
68− ctrl1 &= ~PCF85063_REG_CTRL1_STOP;
52+#define PCF85063_REG_ALM_S 0x0b
53+#define PCF85063_AEN BIT(7)
6954
70− rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ctrl1);
71− if (rc < 0) {
72− dev_err(&client->dev, "Failing to start the clock\n");
73− return -EIO;
74− }
55+struct pcf85063_config {
56+ struct regmap_config regmap;
57+ unsigned has_alarms:1;
58+ unsigned force_cap_7000:1;
59+};
7560
76− return 0;
77−}
61+struct pcf85063 {
62+ struct rtc_device *rtc;
63+ struct regmap *regmap;
64+};
7865
7966 static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm)
8067 {
81− struct i2c_client *client = to_i2c_client(dev);
68+ struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
8269 int rc;
8370 u8 regs[7];
8471
@@ -88,16 +75,14 @@ static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) · 3 unmodified lines
8875 * event, the access must be finished within one second. So, read all
8976 * time/date registers in one turn.
9077 */
91− rc = i2c_smbus_read_i2c_block_data(client, PCF85063_REG_SC,
92− sizeof(regs), regs);
93− if (rc != sizeof(regs)) {
94− dev_err(&client->dev, "date/time register read error\n");
95− return -EIO;
96− }
78+ rc = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_SC, regs,
79+ sizeof(regs));
80+ if (rc)
81+ return rc;
9782
9883 /* if the clock has lost its power it makes no sense to use its time */
9984 if (regs[0] & PCF85063_REG_SC_OS) {
100− dev_warn(&client->dev, "Power loss detected, invalid time\n");
85+ dev_warn(&pcf85063->rtc->dev, "Power loss detected, invalid time\n");
10186 return -EINVAL;
10287 }
10388
@@ -115,20 +100,18 @@ static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) · 11 unmodified lines
115100
116101 static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm)
117102 {
118− struct i2c_client *client = to_i2c_client(dev);
103+ struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
119104 int rc;
120105 u8 regs[7];
121− u8 ctrl1;
122−
123− if ((tm->tm_year < 100) || (tm->tm_year > 199))
124− return -EINVAL;
125106
126107 /*
127108 * to accurately set the time, reset the divider chain and keep it in
128109 * reset state until all time/date registers are written
129110 */
130− rc = pcf85063_stop_clock(client, &ctrl1);
131− if (rc != 0)
111+ rc = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
112+ PCF85063_REG_CTRL1_STOP,
113+ PCF85063_REG_CTRL1_STOP);
114+ if (rc)
132115 return rc;
133116
134117 /* hours, minutes and seconds */
@@ -150,101 +133,351 @@ static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm) · 15 unmodified lines
150133 regs[6] = bin2bcd(tm->tm_year - 100);
151134
152135 /* write all registers at once */
153− rc = i2c_smbus_write_i2c_block_data(client, PCF85063_REG_SC,
154− sizeof(regs), regs);
155− if (rc < 0) {
156− dev_err(&client->dev, "date/time register write error\n");
136+ rc = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_SC,
137+ regs, sizeof(regs));
138+ if (rc)
157139 return rc;
158− }
159140
160141 /*
161142 * Write the control register as a separate action since the size of
162143 * the register space is different between the PCF85063TP and
163144 * PCF85063A devices. The rollover point can not be used.
164145 */
165− rc = pcf85063_start_clock(client, ctrl1);
166− if (rc != 0)
167− return rc;
146+ return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
147+ PCF85063_REG_CTRL1_STOP, 0);
148+}
149+
150+static int pcf85063_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
151+{
152+ struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
153+ u8 buf[4];
154+ unsigned int val;
155+ int ret;
156+
157+ ret = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_ALM_S,
158+ buf, sizeof(buf));
159+ if (ret)
160+ return ret;
161+
162+ alrm->time.tm_sec = bcd2bin(buf[0]);
163+ alrm->time.tm_min = bcd2bin(buf[1]);
164+ alrm->time.tm_hour = bcd2bin(buf[2]);
165+ alrm->time.tm_mday = bcd2bin(buf[3]);
166+
167+ ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val);
168+ if (ret)
169+ return ret;
170+
171+ alrm->enabled = !!(val & PCF85063_CTRL2_AIE);
168172
169173 return 0;
170174 }
171175
176+static int pcf85063_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
177+{
178+ struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
179+ u8 buf[5];
180+ int ret;
181+
182+ buf[0] = bin2bcd(alrm->time.tm_sec);
183+ buf[1] = bin2bcd(alrm->time.tm_min);
184+ buf[2] = bin2bcd(alrm->time.tm_hour);
185+ buf[3] = bin2bcd(alrm->time.tm_mday);
186+ buf[4] = PCF85063_AEN; /* Do not match on week day */
187+
188+ ret = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2,
189+ PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF, 0);
190+ if (ret)
191+ return ret;
192+
193+ ret = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_ALM_S,
194+ buf, sizeof(buf));
195+ if (ret)
196+ return ret;
197+
198+ return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2,
199+ PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF,
200+ alrm->enabled ? PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF : PCF85063_CTRL2_AF);
201+}
202+
203+static int pcf85063_rtc_alarm_irq_enable(struct device *dev,
204+ unsigned int enabled)
205+{
206+ struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
207+
208+ return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2,
209+ PCF85063_CTRL2_AIE,
210+ enabled ? PCF85063_CTRL2_AIE : 0);
211+}
212+
213+static irqreturn_t pcf85063_rtc_handle_irq(int irq, void *dev_id)
214+{
215+ struct pcf85063 *pcf85063 = dev_id;
216+ unsigned int val;
217+ int err;
218+
219+ err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val);
220+ if (err)
221+ return IRQ_NONE;
222+
223+ if (val & PCF85063_CTRL2_AF) {
224+ rtc_update_irq(pcf85063->rtc, 1, RTC_IRQF | RTC_AF);
225+ regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2,
226+ PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF,
227+ 0);
228+ return IRQ_HANDLED;
229+ }
230+
231+ return IRQ_NONE;
232+}
233+
234+static int pcf85063_read_offset(struct device *dev, long *offset)
235+{
236+ struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
237+ long val;
238+ u32 reg;
239+ int ret;
240+
241+ ret = regmap_read(pcf85063->regmap, PCF85063_REG_OFFSET, &reg);
242+ if (ret < 0)
243+ return ret;
244+
245+ val = sign_extend32(reg & ~PCF85063_OFFSET_MODE,
246+ PCF85063_OFFSET_SIGN_BIT);
247+
248+ if (reg & PCF85063_OFFSET_MODE)
249+ *offset = val * PCF85063_OFFSET_STEP1;
250+ else
251+ *offset = val * PCF85063_OFFSET_STEP0;
252+
253+ return 0;
254+}
255+
256+static int pcf85063_set_offset(struct device *dev, long offset)
257+{
258+ struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
259+ s8 mode0, mode1, reg;
260+ unsigned int error0, error1;
261+
262+ if (offset > PCF85063_OFFSET_STEP0 * 63)
263+ return -ERANGE;
264+ if (offset < PCF85063_OFFSET_STEP0 * -64)
265+ return -ERANGE;
266+
267+ mode0 = DIV_ROUND_CLOSEST(offset, PCF85063_OFFSET_STEP0);
268+ mode1 = DIV_ROUND_CLOSEST(offset, PCF85063_OFFSET_STEP1);
269+
270+ error0 = abs(offset - (mode0 * PCF85063_OFFSET_STEP0));
271+ error1 = abs(offset - (mode1 * PCF85063_OFFSET_STEP1));
272+ if (mode1 > 63 || mode1 < -64 || error0 < error1)
273+ reg = mode0 & ~PCF85063_OFFSET_MODE;
274+ else
275+ reg = mode1 | PCF85063_OFFSET_MODE;
276+
277+ return regmap_write(pcf85063->regmap, PCF85063_REG_OFFSET, reg);
278+}
279+
280+static int pcf85063_ioctl(struct device *dev, unsigned int cmd,
281+ unsigned long arg)
282+{
283+ struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
284+ int status, ret = 0;
285+
286+ switch (cmd) {
287+ case RTC_VL_READ:
288+ ret = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &status);
289+ if (ret < 0)
290+ return ret;
291+
292+ if (status & PCF85063_REG_SC_OS)
293+ dev_warn(&pcf85063->rtc->dev, "Voltage low, data loss detected.\n");
294+
295+ status &= PCF85063_REG_SC_OS;
296+
297+ if (copy_to_user((void __user *)arg, &status, sizeof(int)))
298+ return -EFAULT;
299+
300+ return 0;
301+
302+ case RTC_VL_CLR:
303+ ret = regmap_update_bits(pcf85063->regmap, PCF85063_REG_SC,
304+ PCF85063_REG_SC_OS, 0);
305+
306+ return ret;
307+
308+ default:
309+ return -ENOIOCTLCMD;
310+ }
311+}
312+
172313 static const struct rtc_class_ops pcf85063_rtc_ops = {
173314 .read_time = pcf85063_rtc_read_time,
174− .set_time = pcf85063_rtc_set_time
315+ .set_time = pcf85063_rtc_set_time,
316+ .read_offset = pcf85063_read_offset,
317+ .set_offset = pcf85063_set_offset,
318+ .ioctl = pcf85063_ioctl,
319+};
320+
321+static const struct rtc_class_ops pcf85063_rtc_ops_alarm = {
322+ .read_time = pcf85063_rtc_read_time,
323+ .set_time = pcf85063_rtc_set_time,
324+ .read_offset = pcf85063_read_offset,
325+ .set_offset = pcf85063_set_offset,
326+ .read_alarm = pcf85063_rtc_read_alarm,
327+ .set_alarm = pcf85063_rtc_set_alarm,
328+ .alarm_irq_enable = pcf85063_rtc_alarm_irq_enable,
329+ .ioctl = pcf85063_ioctl,
175330 };
176331
177−static int pcf85063_load_capacitance(struct i2c_client *client)
332+static int pcf85063_nvmem_read(void *priv, unsigned int offset,
333+ void *val, size_t bytes)
178334 {
179− u32 load;
180− int rc;
181− u8 reg;
335+ return regmap_read(priv, PCF85063_REG_RAM, val);
336+}
182337
183− rc = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1);
184− if (rc < 0)
185− return rc;
338+static int pcf85063_nvmem_write(void *priv, unsigned int offset,
339+ void *val, size_t bytes)
340+{
341+ return regmap_write(priv, PCF85063_REG_RAM, *(u8 *)val);
342+}
186343
187− reg = rc;
188− load = 7000;
189− of_property_read_u32(client->dev.of_node, "quartz-load-femtofarads",
190− &load);
344+static int pcf85063_load_capacitance(struct pcf85063 *pcf85063,
345+ const struct device_node *np,
346+ unsigned int force_cap)
347+{
348+ u32 load = 7000;
349+ u8 reg = 0;
350+
351+ if (force_cap)
352+ load = force_cap;
353+ else
354+ of_property_read_u32(np, "quartz-load-femtofarads", &load);
191355
192356 switch (load) {
193357 default:
194− dev_warn(&client->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000",
358+ dev_warn(&pcf85063->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000",
195359 load);
196360 /* fall through */
197361 case 7000:
198− reg &= ~PCF85063_REG_CTRL1_CAP_SEL;
199362 break;
200363 case 12500:
201− reg |= PCF85063_REG_CTRL1_CAP_SEL;
364+ reg = PCF85063_REG_CTRL1_CAP_SEL;
202365 break;
203366 }
204367
205− rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, reg);
206−
207− return rc;
368+ return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
369+ PCF85063_REG_CTRL1_CAP_SEL, reg);
208370 }
209371
210−static int pcf85063_probe(struct i2c_client *client,
211− const struct i2c_device_id *id)
372+static const struct pcf85063_config pcf85063a_config = {
373+ .regmap = {
374+ .reg_bits = 8,
375+ .val_bits = 8,
376+ .max_register = 0x11,
377+ },
378+ .has_alarms = 1,
379+};
380+
381+static const struct pcf85063_config pcf85063tp_config = {
382+ .regmap = {
383+ .reg_bits = 8,
384+ .val_bits = 8,
385+ .max_register = 0x0a,
386+ },
387+};
388+
389+static const struct pcf85063_config rv8263_config = {
390+ .regmap = {
391+ .reg_bits = 8,
392+ .val_bits = 8,
393+ .max_register = 0x11,
394+ },
395+ .has_alarms = 1,
396+ .force_cap_7000 = 1,
397+};
398+
399+static int pcf85063_probe(struct i2c_client *client)
212400 {
213− struct rtc_device *rtc;
401+ struct pcf85063 *pcf85063;
402+ unsigned int tmp;
214403 int err;
404+ const struct pcf85063_config *config = &pcf85063tp_config;
405+ const void *data = of_device_get_match_data(&client->dev);
406+ struct nvmem_config nvmem_cfg = {
407+ .name = "pcf85063_nvram",
408+ .reg_read = pcf85063_nvmem_read,
409+ .reg_write = pcf85063_nvmem_write,
410+ .type = NVMEM_TYPE_BATTERY_BACKED,
411+ .size = 1,
412+ };
215413
216414 dev_dbg(&client->dev, "%s\n", __func__);
217415
218− if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
219− return -ENODEV;
416+ pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063),
417+ GFP_KERNEL);
418+ if (!pcf85063)
419+ return -ENOMEM;
420+
421+ if (data)
422+ config = data;
423+
424+ pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap);
425+ if (IS_ERR(pcf85063->regmap))
426+ return PTR_ERR(pcf85063->regmap);
220427
221− err = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1);
222− if (err < 0) {
428+ i2c_set_clientdata(client, pcf85063);
429+
430+ err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL1, &tmp);
431+ if (err) {
223432 dev_err(&client->dev, "RTC chip is not present\n");
224433 return err;
225434 }
226435
227− err = pcf85063_load_capacitance(client);
436+ pcf85063->rtc = devm_rtc_allocate_device(&client->dev);
437+ if (IS_ERR(pcf85063->rtc))
438+ return PTR_ERR(pcf85063->rtc);
439+
440+ err = pcf85063_load_capacitance(pcf85063, client->dev.of_node,
441+ config->force_cap_7000 ? 7000 : 0);
228442 if (err < 0)
229443 dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
230444 err);
231445
232− rtc = devm_rtc_device_register(&client->dev,
233− pcf85063_driver.driver.name,
234− &pcf85063_rtc_ops, THIS_MODULE);
446+ pcf85063->rtc->ops = &pcf85063_rtc_ops;
447+ pcf85063->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
448+ pcf85063->rtc->range_max = RTC_TIMESTAMP_END_2099;
449+ pcf85063->rtc->uie_unsupported = 1;
450+
451+ if (config->has_alarms && client->irq > 0) {
452+ err = devm_request_threaded_irq(&client->dev, client->irq,
453+ NULL, pcf85063_rtc_handle_irq,
454+ IRQF_TRIGGER_LOW | IRQF_ONESHOT,
455+ "pcf85063", pcf85063);
456+ if (err) {
457+ dev_warn(&pcf85063->rtc->dev,
458+ "unable to request IRQ, alarms disabled\n");
459+ } else {
460+ pcf85063->rtc->ops = &pcf85063_rtc_ops_alarm;
461+ device_init_wakeup(&client->dev, true);
462+ err = dev_pm_set_wake_irq(&client->dev, client->irq);
463+ if (err)
464+ dev_err(&pcf85063->rtc->dev,
465+ "failed to enable irq wake\n");
466+ }
467+ }
468+
469+ nvmem_cfg.priv = pcf85063->regmap;
470+ rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg);
235471
236− return PTR_ERR_OR_ZERO(rtc);
472+ return rtc_register_device(pcf85063->rtc);
237473 }
238474
239−static const struct i2c_device_id pcf85063_id[] = {
240− { "pcf85063", 0 },
241− { }
242−};
243−MODULE_DEVICE_TABLE(i2c, pcf85063_id);
244−
245475 #ifdef CONFIG_OF
246476 static const struct of_device_id pcf85063_of_match[] = {
247− { .compatible = "nxp,pcf85063" },
477+ { .compatible = "nxp,pcf85063", .data = &pcf85063tp_config },
478+ { .compatible = "nxp,pcf85063tp", .data = &pcf85063tp_config },
479+ { .compatible = "nxp,pcf85063a", .data = &pcf85063a_config },
480+ { .compatible = "microcrystal,rv8263", .data = &rv8263_config },
248481 {}
249482 };
250483 MODULE_DEVICE_TABLE(of, pcf85063_of_match);
@@ -255,8 +488,7 @@ static struct i2c_driver pcf85063_driver = { · 4 unmodified lines
255488 .name = "rtc-pcf85063",
256489 .of_match_table = of_match_ptr(pcf85063_of_match),
257490 },
258− .probe = pcf85063_probe,
259− .id_table = pcf85063_id,
491+ .probe_new = pcf85063_probe,
260492 };
261493
262494 module_i2c_driver(pcf85063_driver);
drivers/rtc/rtc-pcf85363.c+5−15
@@ -1,15 +1,10 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * drivers/rtc/rtc-pcf85363.c
34 *
45 * Driver for NXP PCF85363 real-time clock.
56 *
67 * Copyright (C) 2017 Eric Nelson
7− *
8− * This program is free software; you can redistribute it and/or modify
9− * it under the terms of the GNU General Public License version 2 as
10− * published by the Free Software Foundation.
11− *
12− * Based loosely on rtc-8583 by Russell King, Wolfram Sang and Juergen Beisert
138 */
149 #include <linux/module.h>
1510 #include <linux/i2c.h>
@@ -112,10 +107,7 @@ · 96 unmodified lines
112107
113108 #define NVRAM_SIZE 0x40
114109
115−static struct i2c_driver pcf85363_driver;
116−
117110 struct pcf85363 {
118− struct device *dev;
119111 struct rtc_device *rtc;
120112 struct regmap *regmap;
121113 };
@@ -386,9 +378,6 @@ static int pcf85363_probe(struct i2c_client *client, · 264 unmodified lines
386378 if (data)
387379 config = data;
388380
389− if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
390− return -ENODEV;
391−
392381 pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363),
393382 GFP_KERNEL);
394383 if (!pcf85363)
@@ -400,20 +389,21 @@ static int pcf85363_probe(struct i2c_client *client, · 5 unmodified lines
400389 return PTR_ERR(pcf85363->regmap);
401390 }
402391
403− pcf85363->dev = &client->dev;
404392 i2c_set_clientdata(client, pcf85363);
405393
406− pcf85363->rtc = devm_rtc_allocate_device(pcf85363->dev);
394+ pcf85363->rtc = devm_rtc_allocate_device(&client->dev);
407395 if (IS_ERR(pcf85363->rtc))
408396 return PTR_ERR(pcf85363->rtc);
409397
410398 pcf85363->rtc->ops = &rtc_ops;
399+ pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
400+ pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
411401
412402 if (client->irq > 0) {
413403 regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
414404 regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
415405 PIN_IO_INTA_OUT, PIN_IO_INTAPM);
416− ret = devm_request_threaded_irq(pcf85363->dev, client->irq,
406+ ret = devm_request_threaded_irq(&client->dev, client->irq,
417407 NULL, pcf85363_rtc_handle_irq,
418408 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
419409 "pcf85363", client);
drivers/rtc/rtc-ps3.c+9−21
@@ -1,20 +1,8 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * PS3 RTC Driver
34 *
45 * Copyright 2009 Sony Corporation
5− *
6− * This program is free software; you can redistribute it and/or modify
7− * it under the terms of the GNU General Public License as published by
8− * the Free Software Foundation; version 2 of the License.
9− *
10− * This program is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with this program.
17− * If not, see <http://www.gnu.org/licenses/>.
186 */
197
208 #include <linux/kernel.h>
@@ -40,16 +28,13 @@ static u64 read_rtc(void) · 19 unmodified lines
4028
4129 static int ps3_get_time(struct device *dev, struct rtc_time *tm)
4230 {
43− rtc_time_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
31+ rtc_time64_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
4432 return 0;
4533 }
4634
4735 static int ps3_set_time(struct device *dev, struct rtc_time *tm)
4836 {
49− unsigned long now;
50−
51− rtc_tm_to_time(tm, &now);
52− ps3_os_area_set_rtc_diff(now - read_rtc());
37+ ps3_os_area_set_rtc_diff(rtc_tm_to_time64(tm) - read_rtc());
5338 return 0;
5439 }
5540
@@ -62,13 +47,16 @@ static int __init ps3_rtc_probe(struct platform_device *dev) · 6 unmodified lines
6247 {
6348 struct rtc_device *rtc;
6449
65− rtc = devm_rtc_device_register(&dev->dev, "rtc-ps3", &ps3_rtc_ops,
66− THIS_MODULE);
50+ rtc = devm_rtc_allocate_device(&dev->dev);
6751 if (IS_ERR(rtc))
6852 return PTR_ERR(rtc);
6953
54+ rtc->ops = &ps3_rtc_ops;
55+ rtc->range_max = U64_MAX;
56+
7057 platform_set_drvdata(dev, rtc);
71− return 0;
58+
59+ return rtc_register_device(rtc);
7260 }
7361
7462 static struct platform_driver ps3_rtc_driver = {
drivers/rtc/rtc-pxa.c+1−2
@@ -145,8 +145,7 @@ static void rtsr_set_bits(struct pxa_rtc *pxa_rtc, u32 mask) · 144 unmodified lines
145145
146146 static irqreturn_t pxa_rtc_irq(int irq, void *dev_id)
147147 {
148− struct platform_device *pdev = to_platform_device(dev_id);
149− struct pxa_rtc *pxa_rtc = platform_get_drvdata(pdev);
148+ struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev_id);
150149 u32 rtsr;
151150 unsigned long events = 0;
152151
drivers/rtc/rtc-rk808.c+2−4
@@ -336,8 +336,7 @@ static const struct rtc_class_ops rk808_rtc_ops = { · 335 unmodified lines
336336 /* Turn off the alarm if it should not be a wake source. */
337337 static int rk808_rtc_suspend(struct device *dev)
338338 {
339− struct platform_device *pdev = to_platform_device(dev);
340− struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev);
339+ struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
341340
342341 if (device_may_wakeup(dev))
343342 enable_irq_wake(rk808_rtc->irq);
@@ -350,8 +349,7 @@ static int rk808_rtc_suspend(struct device *dev) · 6 unmodified lines
350349 */
351350 static int rk808_rtc_resume(struct device *dev)
352351 {
353− struct platform_device *pdev = to_platform_device(dev);
354− struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev);
352+ struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
355353
356354 if (device_may_wakeup(dev))
357355 disable_irq_wake(rk808_rtc->irq);
drivers/rtc/rtc-rx6110.c+9−0
@@ -21,6 +21,8 @@ · 20 unmodified lines
2121 #include <linux/of_gpio.h>
2222 #include <linux/regmap.h>
2323 #include <linux/rtc.h>
24+#include <linux/of.h>
25+#include <linux/of_device.h>
2426 #include <linux/spi/spi.h>
2527
2628 /* RX-6110 Register definitions */
@@ -379,9 +381,16 @@ static const struct spi_device_id rx6110_id[] = { · 352 unmodified lines
379381 };
380382 MODULE_DEVICE_TABLE(spi, rx6110_id);
381383
384+static const struct of_device_id rx6110_spi_of_match[] = {
385+ { .compatible = "epson,rx6110" },
386+ { },
387+};
388+MODULE_DEVICE_TABLE(of, rx6110_spi_of_match);
389+
382390 static struct spi_driver rx6110_driver = {
383391 .driver = {
384392 .name = RX6110_DRIVER_NAME,
393+ .of_match_table = of_match_ptr(rx6110_spi_of_match),
385394 },
386395 .probe = rx6110_probe,
387396 .remove = rx6110_remove,
drivers/rtc/rtc-rx8025.c+1−1
@@ -311,7 +311,7 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t) · 310 unmodified lines
311311 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12
312312 + (ald[1] & 0x20 ? 12 : 0);
313313
314− dev_dbg(dev, "%s: date: %ptRr\n", __func__, t);
314+ dev_dbg(dev, "%s: date: %ptRr\n", __func__, &t->time);
315315 t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE);
316316 t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled;
317317
drivers/rtc/rtc-sh.c+18−12
@@ -276,6 +276,9 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm) · 275 unmodified lines
276276 struct sh_rtc *rtc = dev_get_drvdata(dev);
277277 unsigned int sec128, sec2, yr, yr100, cf_bit;
278278
279+ if (!(readb(rtc->regbase + RCR2) & RCR2_RTCEN))
280+ return -EINVAL;
281+
279282 do {
280283 unsigned int tmp;
281284
@@ -466,7 +469,6 @@ static int __init sh_rtc_probe(struct platform_device *pdev) · 184 unmodified lines
466469 {
467470 struct sh_rtc *rtc;
468471 struct resource *res;
469− struct rtc_time r;
470472 char clk_name[6];
471473 int clk_id, ret;
472474
@@ -528,6 +530,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev) · 55 unmodified lines
528530 rtc->clk = NULL;
529531 }
530532
533+ rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
534+ if (IS_ERR(rtc->rtc_dev))
535+ return PTR_ERR(rtc->rtc_dev);
536+
531537 clk_enable(rtc->clk);
532538
533539 rtc->capabilities = RTC_DEF_CAPABILITIES;
@@ -591,21 +597,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev) · 57 unmodified lines
591597 sh_rtc_setaie(&pdev->dev, 0);
592598 sh_rtc_setcie(&pdev->dev, 0);
593599
594− rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "sh",
595− &sh_rtc_ops, THIS_MODULE);
596− if (IS_ERR(rtc->rtc_dev)) {
597− ret = PTR_ERR(rtc->rtc_dev);
598− goto err_unmap;
599− }
600−
600+ rtc->rtc_dev->ops = &sh_rtc_ops;
601601 rtc->rtc_dev->max_user_freq = 256;
602602
603− /* reset rtc to epoch 0 if time is invalid */
604− if (rtc_read_time(rtc->rtc_dev, &r) < 0) {
605− rtc_time_to_tm(0, &r);
606− rtc_set_time(rtc->rtc_dev, &r);
603+ if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
604+ rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
605+ rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
606+ } else {
607+ rtc->rtc_dev->range_min = mktime64(1999, 1, 1, 0, 0, 0);
608+ rtc->rtc_dev->range_max = mktime64(2098, 12, 31, 23, 59, 59);
607609 }
608610
611+ ret = rtc_register_device(rtc->rtc_dev);
612+ if (ret)
613+ goto err_unmap;
614+
609615 device_init_wakeup(&pdev->dev, 1);
610616 return 0;
611617
drivers/rtc/rtc-sirfsoc.c+1−1
@@ -279,7 +279,7 @@ static const struct of_device_id sirfsoc_rtc_of_match[] = { · 278 unmodified lines
279279 {},
280280 };
281281
282−const struct regmap_config sysrtc_regmap_config = {
282+static const struct regmap_config sysrtc_regmap_config = {
283283 .reg_bits = 32,
284284 .val_bits = 32,
285285 .fast_io = true,
drivers/rtc/rtc-snvs.c+9−39
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 #include <linux/of.h>
1010 #include <linux/of_device.h>
1111 #include <linux/platform_device.h>
12+#include <linux/pm_wakeirq.h>
1213 #include <linux/rtc.h>
1314 #include <linux/clk.h>
1415 #include <linux/mfd/syscon.h>
@@ -271,7 +272,6 @@ static const struct regmap_config snvs_rtc_config = { · 256 unmodified lines
271272 static int snvs_rtc_probe(struct platform_device *pdev)
272273 {
273274 struct snvs_rtc_data *data;
274− struct resource *res;
275275 int ret;
276276 void __iomem *mmio;
277277
@@ -283,9 +283,8 @@ static int snvs_rtc_probe(struct platform_device *pdev) · 5 unmodified lines
283283
284284 if (IS_ERR(data->regmap)) {
285285 dev_warn(&pdev->dev, "snvs rtc: you use old dts file, please update it\n");
286− res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
287286
288− mmio = devm_ioremap_resource(&pdev->dev, res);
287+ mmio = devm_platform_ioremap_resource(pdev, 0);
289288 if (IS_ERR(mmio))
290289 return PTR_ERR(mmio);
291290
@@ -332,6 +331,9 @@ static int snvs_rtc_probe(struct platform_device *pdev) · 40 unmodified lines
332331 }
333332
334333 device_init_wakeup(&pdev->dev, true);
334+ ret = dev_pm_set_wake_irq(&pdev->dev, data->irq);
335+ if (ret)
336+ dev_err(&pdev->dev, "failed to enable irq wake\n");
335337
336338 ret = devm_request_irq(&pdev->dev, data->irq, snvs_rtc_irq_handler,
337339 IRQF_SHARED, "rtc alarm", &pdev->dev);
@@ -358,18 +360,7 @@ error_rtc_device_register: · 20 unmodified lines
358360 return ret;
359361 }
360362
361−#ifdef CONFIG_PM_SLEEP
362−static int snvs_rtc_suspend(struct device *dev)
363−{
364− struct snvs_rtc_data *data = dev_get_drvdata(dev);
365−
366− if (device_may_wakeup(dev))
367− return enable_irq_wake(data->irq);
368−
369− return 0;
370−}
371−
372−static int snvs_rtc_suspend_noirq(struct device *dev)
363+static int __maybe_unused snvs_rtc_suspend_noirq(struct device *dev)
373364 {
374365 struct snvs_rtc_data *data = dev_get_drvdata(dev);
375366
@@ -379,17 +370,7 @@ static int snvs_rtc_suspend_noirq(struct device *dev) · 3 unmodified lines
379370 return 0;
380371 }
381372
382−static int snvs_rtc_resume(struct device *dev)
383−{
384− struct snvs_rtc_data *data = dev_get_drvdata(dev);
385−
386− if (device_may_wakeup(dev))
387− return disable_irq_wake(data->irq);
388−
389− return 0;
390−}
391−
392−static int snvs_rtc_resume_noirq(struct device *dev)
373+static int __maybe_unused snvs_rtc_resume_noirq(struct device *dev)
393374 {
394375 struct snvs_rtc_data *data = dev_get_drvdata(dev);
395376
@@ -400,20 +381,9 @@ static int snvs_rtc_resume_noirq(struct device *dev) · 4 unmodified lines
400381 }
401382
402383 static const struct dev_pm_ops snvs_rtc_pm_ops = {
403− .suspend = snvs_rtc_suspend,
404− .suspend_noirq = snvs_rtc_suspend_noirq,
405− .resume = snvs_rtc_resume,
406− .resume_noirq = snvs_rtc_resume_noirq,
384+ SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(snvs_rtc_suspend_noirq, snvs_rtc_resume_noirq)
407385 };
408386
409−#define SNVS_RTC_PM_OPS (&snvs_rtc_pm_ops)
410−
411−#else
412−
413−#define SNVS_RTC_PM_OPS NULL
414−
415−#endif
416−
417387 static const struct of_device_id snvs_dt_ids[] = {
418388 { .compatible = "fsl,sec-v4.0-mon-rtc-lp", },
419389 { /* sentinel */ }
@@ -423,7 +393,7 @@ MODULE_DEVICE_TABLE(of, snvs_dt_ids); · 3 unmodified lines
423393 static struct platform_driver snvs_rtc_driver = {
424394 .driver = {
425395 .name = "snvs_rtc",
426− .pm = SNVS_RTC_PM_OPS,
396+ .pm = &snvs_rtc_pm_ops,
427397 .of_match_table = snvs_dt_ids,
428398 },
429399 .probe = snvs_rtc_probe,
drivers/rtc/rtc-stm32.c+6−3
@@ -788,11 +788,14 @@ static int stm32_rtc_probe(struct platform_device *pdev) · 787 unmodified lines
788788 ret = device_init_wakeup(&pdev->dev, true);
789789 if (rtc->data->has_wakeirq) {
790790 rtc->wakeirq_alarm = platform_get_irq(pdev, 1);
791− if (rtc->wakeirq_alarm <= 0)
792− ret = rtc->wakeirq_alarm;
793− else
791+ if (rtc->wakeirq_alarm > 0) {
794792 ret = dev_pm_set_dedicated_wake_irq(&pdev->dev,
795793 rtc->wakeirq_alarm);
794+ } else {
795+ ret = rtc->wakeirq_alarm;
796+ if (rtc->wakeirq_alarm == -EPROBE_DEFER)
797+ goto err;
798+ }
796799 }
797800 if (ret)
798801 dev_warn(&pdev->dev, "alarm can't wake up the system: %d", ret);
drivers/rtc/rtc-stmp3xxx.c+15−19
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Freescale STMP37XX/STMP378X Real Time Clock driver
34 *
@@ -8,15 +9,6 @@ · 4 unmodified lines
89 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
910 * Copyright 2011 Wolfram Sang, Pengutronix e.K.
1011 */
11−
12−/*
13− * The code contained herein is licensed under the GNU General Public
14− * License. You may obtain a copy of the GNU General Public License
15− * Version 2 or later at the following locations:
16− *
17− * http://www.opensource.org/licenses/gpl-license.html
18− * http://www.gnu.org/copyleft/gpl.html
19− */
2012 #include <linux/kernel.h>
2113 #include <linux/module.h>
2214 #include <linux/io.h>
@@ -160,15 +152,15 @@ static int stmp3xxx_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) · 137 unmodified lines
160152 if (ret)
161153 return ret;
162154
163− rtc_time_to_tm(readl(rtc_data->io + STMP3XXX_RTC_SECONDS), rtc_tm);
155+ rtc_time64_to_tm(readl(rtc_data->io + STMP3XXX_RTC_SECONDS), rtc_tm);
164156 return 0;
165157 }
166158
167−static int stmp3xxx_rtc_set_mmss(struct device *dev, unsigned long t)
159+static int stmp3xxx_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
168160 {
169161 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
170162
171− writel(t, rtc_data->io + STMP3XXX_RTC_SECONDS);
163+ writel(rtc_tm_to_time64(rtc_tm), rtc_data->io + STMP3XXX_RTC_SECONDS);
172164 return stmp3xxx_wait_time(rtc_data);
173165 }
174166
@@ -214,17 +206,15 @@ static int stmp3xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) · 39 unmodified lines
214206 {
215207 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
216208
217− rtc_time_to_tm(readl(rtc_data->io + STMP3XXX_RTC_ALARM), &alm->time);
209+ rtc_time64_to_tm(readl(rtc_data->io + STMP3XXX_RTC_ALARM), &alm->time);
218210 return 0;
219211 }
220212
221213 static int stmp3xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
222214 {
223− unsigned long t;
224215 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
225216
226− rtc_tm_to_time(&alm->time, &t);
227− writel(t, rtc_data->io + STMP3XXX_RTC_ALARM);
217+ writel(rtc_tm_to_time64(&alm->time), rtc_data->io + STMP3XXX_RTC_ALARM);
228218
229219 stmp3xxx_alarm_irq_enable(dev, alm->enabled);
230220
@@ -235,7 +225,7 @@ static const struct rtc_class_ops stmp3xxx_rtc_ops = { · 4 unmodified lines
235225 .alarm_irq_enable =
236226 stmp3xxx_alarm_irq_enable,
237227 .read_time = stmp3xxx_rtc_gettime,
238− .set_mmss = stmp3xxx_rtc_set_mmss,
228+ .set_time = stmp3xxx_rtc_settime,
239229 .read_alarm = stmp3xxx_rtc_read_alarm,
240230 .set_alarm = stmp3xxx_rtc_set_alarm,
241231 };
@@ -361,8 +351,7 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) · 119 unmodified lines
361351 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
362352 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
363353
364− rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
365− &stmp3xxx_rtc_ops, THIS_MODULE);
354+ rtc_data->rtc = devm_rtc_allocate_device(&pdev->dev);
366355 if (IS_ERR(rtc_data->rtc))
367356 return PTR_ERR(rtc_data->rtc);
368357
@@ -374,6 +363,13 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) · 5 unmodified lines
374363 return err;
375364 }
376365
366+ rtc_data->rtc->ops = &stmp3xxx_rtc_ops;
367+ rtc_data->rtc->range_max = U32_MAX;
368+
369+ err = rtc_register_device(rtc_data->rtc);
370+ if (err)
371+ return err;
372+
377373 stmp3xxx_wdt_register(pdev);
378374 return 0;
379375 }
drivers/rtc/rtc-sun4v.c+8−13
@@ -1,7 +1,7 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems.
23 *
34 * Author: David S. Miller
4− * License: GPL
55 *
66 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
77 */
@@ -39,7 +39,7 @@ retry: · 31 unmodified lines
3939
4040 static int sun4v_read_time(struct device *dev, struct rtc_time *tm)
4141 {
42− rtc_time_to_tm(hypervisor_get_time(), tm);
42+ rtc_time64_to_tm(hypervisor_get_time(), tm);
4343 return 0;
4444 }
4545
@@ -66,14 +66,7 @@ retry: · 20 unmodified lines
6666
6767 static int sun4v_set_time(struct device *dev, struct rtc_time *tm)
6868 {
69− unsigned long secs;
70− int err;
71−
72− err = rtc_tm_to_time(tm, &secs);
73− if (err)
74− return err;
75−
76− return hypervisor_set_time(secs);
69+ return hypervisor_set_time(rtc_tm_to_time64(tm));
7770 }
7871
7972 static const struct rtc_class_ops sun4v_rtc_ops = {
@@ -85,13 +78,15 @@ static int __init sun4v_rtc_probe(struct platform_device *pdev) · 5 unmodified lines
8578 {
8679 struct rtc_device *rtc;
8780
88− rtc = devm_rtc_device_register(&pdev->dev, "sun4v",
89− &sun4v_rtc_ops, THIS_MODULE);
81+ rtc = devm_rtc_allocate_device(&pdev->dev);
9082 if (IS_ERR(rtc))
9183 return PTR_ERR(rtc);
9284
85+ rtc->ops = &sun4v_rtc_ops;
86+ rtc->range_max = U64_MAX;
9387 platform_set_drvdata(pdev, rtc);
94− return 0;
88+
89+ return rtc_register_device(rtc);
9590 }
9691
9792 static struct platform_driver sun4v_rtc_driver = {
drivers/rtc/rtc-tegra.c+19−28
@@ -1,21 +1,8 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * An RTC driver for the NVIDIA Tegra 200 series internal RTC.
34 *
45 * Copyright (c) 2010, NVIDIA Corporation.
5− *
6− * This program is free software; you can redistribute it and/or modify
7− * it under the terms of the GNU General Public License as published by
8− * the Free Software Foundation; either version 2 of the License, or
9− * (at your option) any later version.
10− *
11− * This program is distributed in the hope that it will be useful, but WITHOUT
12− * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13− * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14− * more details.
15− *
16− * You should have received a copy of the GNU General Public License along
17− * with this program; if not, write to the Free Software Foundation, Inc.,
18− * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
196 */
207
218 #include <linux/clk.h>
@@ -123,7 +110,7 @@ static int tegra_rtc_read_time(struct device *dev, struct rtc_time *tm) · 101 unmodified lines
123110
124111 spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
125112
126− rtc_time_to_tm(sec, tm);
113+ rtc_time64_to_tm(sec, tm);
127114
128115 dev_vdbg(dev, "time read as %lu. %ptR\n", sec, tm);
129116
@@ -137,7 +124,7 @@ static int tegra_rtc_set_time(struct device *dev, struct rtc_time *tm) · 7 unmodified lines
137124 int ret;
138125
139126 /* convert tm to seconds. */
140− rtc_tm_to_time(tm, &sec);
127+ sec = rtc_tm_to_time64(tm);
141128
142129 dev_vdbg(dev, "time set to %lu. %ptR\n", sec, tm);
143130
@@ -166,7 +153,7 @@ static int tegra_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 22 unmodified lines
166153 } else {
167154 /* alarm is enabled. */
168155 alarm->enabled = 1;
169− rtc_time_to_tm(sec, &alarm->time);
156+ rtc_time64_to_tm(sec, &alarm->time);
170157 }
171158
172159 tmp = readl(info->rtc_base + TEGRA_RTC_REG_INTR_STATUS);
@@ -204,7 +191,7 @@ static int tegra_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 31 unmodified lines
204191 unsigned long sec;
205192
206193 if (alarm->enabled)
207− rtc_tm_to_time(&alarm->time, &sec);
194+ sec = rtc_tm_to_time64(&alarm->time);
208195 else
209196 sec = 0;
210197
@@ -306,6 +293,13 @@ static int __init tegra_rtc_probe(struct platform_device *pdev) · 95 unmodified lines
306293
307294 info->tegra_rtc_irq = ret;
308295
296+ info->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
297+ if (IS_ERR(info->rtc_dev))
298+ return PTR_ERR(info->rtc_dev);
299+
300+ info->rtc_dev->ops = &tegra_rtc_ops;
301+ info->rtc_dev->range_max = U32_MAX;
302+
309303 info->clk = devm_clk_get(&pdev->dev, NULL);
310304 if (IS_ERR(info->clk))
311305 return PTR_ERR(info->clk);
@@ -327,16 +321,6 @@ static int __init tegra_rtc_probe(struct platform_device *pdev) · 15 unmodified lines
327321
328322 device_init_wakeup(&pdev->dev, 1);
329323
330− info->rtc_dev = devm_rtc_device_register(&pdev->dev,
331− dev_name(&pdev->dev), &tegra_rtc_ops,
332− THIS_MODULE);
333− if (IS_ERR(info->rtc_dev)) {
334− ret = PTR_ERR(info->rtc_dev);
335− dev_err(&pdev->dev, "Unable to register device (err=%d).\n",
336− ret);
337− goto disable_clk;
338− }
339−
340324 ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq,
341325 tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH,
342326 dev_name(&pdev->dev), &pdev->dev);
@@ -347,6 +331,13 @@ static int __init tegra_rtc_probe(struct platform_device *pdev) · 4 unmodified lines
347331 goto disable_clk;
348332 }
349333
334+ ret = rtc_register_device(info->rtc_dev);
335+ if (ret) {
336+ dev_err(&pdev->dev, "Unable to register device (err=%d).\n",
337+ ret);
338+ goto disable_clk;
339+ }
340+
350341 dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n");
351342
352343 return 0;
drivers/rtc/rtc-test.c+6−5
@@ -70,11 +70,11 @@ static int test_rtc_read_time(struct device *dev, struct rtc_time *tm) · 69 unmodified lines
7070 return 0;
7171 }
7272
73−static int test_rtc_set_mmss64(struct device *dev, time64_t secs)
73+static int test_rtc_set_time(struct device *dev, struct rtc_time *tm)
7474 {
7575 struct rtc_test_data *rtd = dev_get_drvdata(dev);
7676
77− rtd->offset = secs - ktime_get_real_seconds();
77+ rtd->offset = rtc_tm_to_time64(tm) - ktime_get_real_seconds();
7878
7979 return 0;
8080 }
@@ -94,15 +94,15 @@ static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) · 13 unmodified lines
9494
9595 static const struct rtc_class_ops test_rtc_ops_noalm = {
9696 .read_time = test_rtc_read_time,
97− .set_mmss64 = test_rtc_set_mmss64,
97+ .set_time = test_rtc_set_time,
9898 .alarm_irq_enable = test_rtc_alarm_irq_enable,
9999 };
100100
101101 static const struct rtc_class_ops test_rtc_ops = {
102102 .read_time = test_rtc_read_time,
103+ .set_time = test_rtc_set_time,
103104 .read_alarm = test_rtc_read_alarm,
104105 .set_alarm = test_rtc_set_alarm,
105− .set_mmss64 = test_rtc_set_mmss64,
106106 .alarm_irq_enable = test_rtc_alarm_irq_enable,
107107 };
108108
@@ -152,7 +152,8 @@ static int __init test_init(void) · 43 unmodified lines
152152 {
153153 int i, err;
154154
155− if ((err = platform_driver_register(&test_driver)))
155+ err = platform_driver_register(&test_driver);
156+ if (err)
156157 return err;
157158
158159 err = -ENOMEM;
drivers/rtc/rtc-tx4939.c+6−11
@@ -42,11 +42,6 @@ struct tx4939rtc_plat_data { · 41 unmodified lines
4242 spinlock_t lock;
4343 };
4444
45−static struct tx4939rtc_plat_data *get_tx4939rtc_plat_data(struct device *dev)
46−{
47− return platform_get_drvdata(to_platform_device(dev));
48−}
49−
5045 static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd)
5146 {
5247 int i = 0;
@@ -64,7 +59,7 @@ static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd) · 11 unmodified lines
6459
6560 static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm)
6661 {
67− struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
62+ struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
6863 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
6964 unsigned long secs = rtc_tm_to_time64(tm);
7065 int i, ret;
@@ -89,7 +84,7 @@ static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm) · 18 unmodified lines
8984
9085 static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm)
9186 {
92− struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
87+ struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
9388 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
9489 int i, ret;
9590 unsigned long sec;
@@ -115,7 +110,7 @@ static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm) · 19 unmodified lines
115110
116111 static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
117112 {
118− struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
113+ struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
119114 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
120115 int i, ret;
121116 unsigned long sec;
@@ -140,7 +135,7 @@ static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 18 unmodified lines
140135
141136 static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
142137 {
143− struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
138+ struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
144139 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
145140 int i, ret;
146141 unsigned long sec;
@@ -170,7 +165,7 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 23 unmodified lines
170165
171166 static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
172167 {
173− struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev);
168+ struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
174169
175170 spin_lock_irq(&pdata->lock);
176171 tx4939_rtc_cmd(pdata->rtcreg,
@@ -182,7 +177,7 @@ static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 5 unmodified lines
182177
183178 static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id)
184179 {
185− struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev_id);
180+ struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev_id);
186181 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
187182 unsigned long events = RTC_IRQF;
188183
drivers/rtc/rtc-wm831x.c+28−41
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Real Time Clock driver for Wolfson Microelectronics WM831x
34 *
@@ -5,11 +6,6 @@ · 1 unmodified line
56 *
67 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
78 *
8− * This program is free software; you can redistribute it and/or modify it
9− * under the terms of the GNU General Public License as published by the
10− * Free Software Foundation; either version 2 of the License, or (at your
11− * option) any later version.
12− *
139 */
1410
1511 #include <linux/module.h>
@@ -155,7 +151,7 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm) · 139 unmodified lines
155151 if (memcmp(time1, time2, sizeof(time1)) == 0) {
156152 u32 time = (time1[0] << 16) | time1[1];
157153
158− rtc_time_to_tm(time, tm);
154+ rtc_time64_to_tm(time, tm);
159155 return 0;
160156 }
161157
@@ -169,15 +165,17 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm) · 7 unmodified lines
169165 /*
170166 * Set current time and date in RTC
171167 */
172−static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time)
168+static int wm831x_rtc_settime(struct device *dev, struct rtc_time *tm)
173169 {
174170 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
175171 struct wm831x *wm831x = wm831x_rtc->wm831x;
176172 struct rtc_time new_tm;
177− unsigned long new_time;
173+ unsigned long time, new_time;
178174 int ret;
179175 int count = 0;
180176
177+ time = rtc_tm_to_time64(tm);
178+
181179 ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_1,
182180 (time >> 16) & 0xffff);
183181 if (ret < 0) {
@@ -215,11 +213,7 @@ static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time) · 31 unmodified lines
215213 if (ret < 0)
216214 return ret;
217215
218− ret = rtc_tm_to_time(&new_tm, &new_time);
219− if (ret < 0) {
220− dev_err(dev, "Failed to convert time: %d\n", ret);
221− return ret;
222− }
216+ new_time = rtc_tm_to_time64(&new_tm);
223217
224218 /* Allow a second of change in case of tick */
225219 if (new_time - time > 1) {
@@ -249,7 +243,7 @@ static int wm831x_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) · 23 unmodified lines
249243
250244 time = (data[0] << 16) | data[1];
251245
252− rtc_time_to_tm(time, &alrm->time);
246+ rtc_time64_to_tm(time, &alrm->time);
253247
254248 ret = wm831x_reg_read(wm831x_rtc->wm831x, WM831X_RTC_CONTROL);
255249 if (ret < 0) {
@@ -288,11 +282,7 @@ static int wm831x_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) · 32 unmodified lines
288282 int ret;
289283 unsigned long time;
290284
291− ret = rtc_tm_to_time(&alrm->time, &time);
292− if (ret < 0) {
293− dev_err(dev, "Failed to convert time: %d\n", ret);
294− return ret;
295− }
285+ time = rtc_tm_to_time64(&alrm->time);
296286
297287 ret = wm831x_rtc_stop_alarm(wm831x_rtc);
298288 if (ret < 0) {
@@ -346,7 +336,7 @@ static irqreturn_t wm831x_alm_irq(int irq, void *data) · 47 unmodified lines
346336
347337 static const struct rtc_class_ops wm831x_rtc_ops = {
348338 .read_time = wm831x_rtc_readtime,
349− .set_mmss = wm831x_rtc_set_mmss,
339+ .set_time = wm831x_rtc_settime,
350340 .read_alarm = wm831x_rtc_readalarm,
351341 .set_alarm = wm831x_rtc_setalarm,
352342 .alarm_irq_enable = wm831x_rtc_alarm_irq_enable,
@@ -356,11 +346,10 @@ static const struct rtc_class_ops wm831x_rtc_ops = { · 3 unmodified lines
356346 /* Turn off the alarm if it should not be a wake source. */
357347 static int wm831x_rtc_suspend(struct device *dev)
358348 {
359− struct platform_device *pdev = to_platform_device(dev);
360− struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
349+ struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
361350 int ret, enable;
362351
363− if (wm831x_rtc->alarm_enabled && device_may_wakeup(&pdev->dev))
352+ if (wm831x_rtc->alarm_enabled && device_may_wakeup(dev))
364353 enable = WM831X_RTC_ALM_ENA;
365354 else
366355 enable = 0;
@@ -368,7 +357,7 @@ static int wm831x_rtc_suspend(struct device *dev) · 1 unmodified line
368357 ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL,
369358 WM831X_RTC_ALM_ENA, enable);
370359 if (ret != 0)
371− dev_err(&pdev->dev, "Failed to update RTC alarm: %d\n", ret);
360+ dev_err(dev, "Failed to update RTC alarm: %d\n", ret);
372361
373362 return 0;
374363 }
@@ -378,15 +367,13 @@ static int wm831x_rtc_suspend(struct device *dev) · 3 unmodified lines
378367 */
379368 static int wm831x_rtc_resume(struct device *dev)
380369 {
381− struct platform_device *pdev = to_platform_device(dev);
382− struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
370+ struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
383371 int ret;
384372
385373 if (wm831x_rtc->alarm_enabled) {
386374 ret = wm831x_rtc_start_alarm(wm831x_rtc);
387375 if (ret != 0)
388− dev_err(&pdev->dev,
389− "Failed to restart RTC alarm: %d\n", ret);
376+ dev_err(dev, "Failed to restart RTC alarm: %d\n", ret);
390377 }
391378
392379 return 0;
@@ -395,14 +382,13 @@ static int wm831x_rtc_resume(struct device *dev) · 2 unmodified lines
395382 /* Unconditionally disable the alarm */
396383 static int wm831x_rtc_freeze(struct device *dev)
397384 {
398− struct platform_device *pdev = to_platform_device(dev);
399− struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
385+ struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
400386 int ret;
401387
402388 ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL,
403389 WM831X_RTC_ALM_ENA, 0);
404390 if (ret != 0)
405− dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n", ret);
391+ dev_err(dev, "Failed to stop RTC alarm: %d\n", ret);
406392
407393 return 0;
408394 }
@@ -429,19 +415,23 @@ static int wm831x_rtc_probe(struct platform_device *pdev) · 20 unmodified lines
429415 ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL);
430416 if (ret < 0) {
431417 dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret);
432− goto err;
418+ return ret;
433419 }
434420 if (ret & WM831X_RTC_ALM_ENA)
435421 wm831x_rtc->alarm_enabled = 1;
436422
437423 device_init_wakeup(&pdev->dev, 1);
438424
439− wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x",
440− &wm831x_rtc_ops, THIS_MODULE);
441− if (IS_ERR(wm831x_rtc->rtc)) {
442− ret = PTR_ERR(wm831x_rtc->rtc);
443− goto err;
444− }
425+ wm831x_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
426+ if (IS_ERR(wm831x_rtc->rtc))
427+ return PTR_ERR(wm831x_rtc->rtc);
428+
429+ wm831x_rtc->rtc->ops = &wm831x_rtc_ops;
430+ wm831x_rtc->rtc->range_max = U32_MAX;
431+
432+ ret = rtc_register_device(wm831x_rtc->rtc);
433+ if (ret)
434+ return ret;
445435
446436 ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL,
447437 wm831x_alm_irq,
@@ -455,9 +445,6 @@ static int wm831x_rtc_probe(struct platform_device *pdev) · 7 unmodified lines
455445 wm831x_rtc_add_randomness(wm831x);
456446
457447 return 0;
458−
459−err:
460− return ret;
461448 }
462449
463450 static const struct dev_pm_ops wm831x_rtc_pm_ops = {
drivers/rtc/rtc-wm8350.c+4−8
@@ -340,8 +340,7 @@ static const struct rtc_class_ops wm8350_rtc_ops = { · 339 unmodified lines
340340 #ifdef CONFIG_PM_SLEEP
341341 static int wm8350_rtc_suspend(struct device *dev)
342342 {
343− struct platform_device *pdev = to_platform_device(dev);
344− struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
343+ struct wm8350 *wm8350 = dev_get_drvdata(dev);
345344 int ret = 0;
346345 u16 reg;
347346
@@ -351,8 +350,7 @@ static int wm8350_rtc_suspend(struct device *dev) · 3 unmodified lines
351350 reg & WM8350_RTC_ALMSTS) {
352351 ret = wm8350_rtc_stop_alarm(wm8350);
353352 if (ret != 0)
354− dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n",
355− ret);
353+ dev_err(dev, "Failed to stop RTC alarm: %d\n", ret);
356354 }
357355
358356 return ret;
@@ -360,15 +358,13 @@ static int wm8350_rtc_suspend(struct device *dev) · 1 unmodified line
360358
361359 static int wm8350_rtc_resume(struct device *dev)
362360 {
363− struct platform_device *pdev = to_platform_device(dev);
364− struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
361+ struct wm8350 *wm8350 = dev_get_drvdata(dev);
365362 int ret;
366363
367364 if (wm8350->rtc.alarm_enabled) {
368365 ret = wm8350_rtc_start_alarm(wm8350);
369366 if (ret != 0)
370− dev_err(&pdev->dev,
371− "Failed to restart RTC alarm: %d\n", ret);
367+ dev_err(dev, "Failed to restart RTC alarm: %d\n", ret);
372368 }
373369
374370 return 0;
drivers/rtc/rtc-x1205.c+7−0
@@ -673,9 +673,16 @@ static const struct i2c_device_id x1205_id[] = { · 672 unmodified lines
673673 };
674674 MODULE_DEVICE_TABLE(i2c, x1205_id);
675675
676+static const struct of_device_id x1205_dt_ids[] = {
677+ { .compatible = "xircom,x1205", },
678+ {},
679+};
680+MODULE_DEVICE_TABLE(of, x1205_dt_ids);
681+
676682 static struct i2c_driver x1205_driver = {
677683 .driver = {
678684 .name = "rtc-x1205",
685+ .of_match_table = x1205_dt_ids,
679686 },
680687 .probe = x1205_probe,
681688 .remove = x1205_remove,
drivers/rtc/rtc-xgene.c+25−36
@@ -1,34 +1,21 @@
1+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * APM X-Gene SoC Real Time Clock Driver
34 *
45 * Copyright (c) 2014, Applied Micro Circuits Corporation
56 * Author: Rameshwar Prasad Sahu <rsahu@apm.com>
67 * Loc Ho <lho@apm.com>
7− *
8− * This program is free software; you can redistribute it and/or modify it
9− * under the terms of the GNU General Public License as published by the
10− * Free Software Foundation; either version 2 of the License, or (at your
11− * option) any later version.
12− *
13− * This program is distributed in the hope that it will be useful,
14− * but WITHOUT ANY WARRANTY; without even the implied warranty of
15− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16− * GNU General Public License for more details.
17− *
18− * You should have received a copy of the GNU General Public License
19− * along with this program. If not, see <http://www.gnu.org/licenses/>.
20− *
218 */
229
10+#include <linux/clk.h>
11+#include <linux/delay.h>
2312 #include <linux/init.h>
13+#include <linux/io.h>
2414 #include <linux/module.h>
2515 #include <linux/of.h>
2616 #include <linux/platform_device.h>
27−#include <linux/io.h>
28−#include <linux/slab.h>
29−#include <linux/clk.h>
30−#include <linux/delay.h>
3117 #include <linux/rtc.h>
18+#include <linux/slab.h>
3219
3320 /* RTC CSR Registers */
3421 #define RTC_CCVR 0x00
@@ -48,7 +35,6 @@ · 13 unmodified lines
4835 struct xgene_rtc_dev {
4936 struct rtc_device *rtc;
5037 struct device *dev;
51− unsigned long alarm_time;
5238 void __iomem *csr_base;
5339 struct clk *clk;
5440 unsigned int irq_wake;
@@ -59,11 +45,11 @@ static int xgene_rtc_read_time(struct device *dev, struct rtc_time *tm) · 4 unmodified lines
5945 {
6046 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
6147
62− rtc_time_to_tm(readl(pdata->csr_base + RTC_CCVR), tm);
48+ rtc_time64_to_tm(readl(pdata->csr_base + RTC_CCVR), tm);
6349 return 0;
6450 }
6551
66−static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs)
52+static int xgene_rtc_set_time(struct device *dev, struct rtc_time *tm)
6753 {
6854 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
6955
@@ -71,7 +57,7 @@ static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs) · 1 unmodified line
7157 * NOTE: After the following write, the RTC_CCVR is only reflected
7258 * after the update cycle of 1 seconds.
7359 */
74− writel((u32) secs, pdata->csr_base + RTC_CLR);
60+ writel((u32)rtc_tm_to_time64(tm), pdata->csr_base + RTC_CLR);
7561 readl(pdata->csr_base + RTC_CLR); /* Force a barrier */
7662
7763 return 0;
@@ -81,7 +67,8 @@ static int xgene_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 3 unmodified lines
8167 {
8268 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
8369
84− rtc_time_to_tm(pdata->alarm_time, &alrm->time);
70+ /* If possible, CMR should be read here */
71+ rtc_time64_to_tm(0, &alrm->time);
8572 alrm->enabled = readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE;
8673
8774 return 0;
@@ -115,11 +102,8 @@ static int xgene_rtc_alarm_irq_enabled(struct device *dev) · 27 unmodified lines
115102 static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
116103 {
117104 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
118− unsigned long alarm_time;
119105
120− rtc_tm_to_time(&alrm->time, &alarm_time);
121− pdata->alarm_time = alarm_time;
122− writel((u32) pdata->alarm_time, pdata->csr_base + RTC_CMR);
106+ writel((u32)rtc_tm_to_time64(&alrm->time), pdata->csr_base + RTC_CMR);
123107
124108 xgene_rtc_alarm_irq_enable(dev, alrm->enabled);
125109
@@ -128,7 +112,7 @@ static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 2 unmodified lines
128112
129113 static const struct rtc_class_ops xgene_rtc_ops = {
130114 .read_time = xgene_rtc_read_time,
131− .set_mmss = xgene_rtc_set_mmss,
115+ .set_time = xgene_rtc_set_time,
132116 .read_alarm = xgene_rtc_read_alarm,
133117 .set_alarm = xgene_rtc_set_alarm,
134118 .alarm_irq_enable = xgene_rtc_alarm_irq_enable,
@@ -136,7 +120,7 @@ static const struct rtc_class_ops xgene_rtc_ops = { · 1 unmodified line
136120
137121 static irqreturn_t xgene_rtc_interrupt(int irq, void *id)
138122 {
139− struct xgene_rtc_dev *pdata = (struct xgene_rtc_dev *) id;
123+ struct xgene_rtc_dev *pdata = id;
140124
141125 /* Check if interrupt asserted */
142126 if (!(readl(pdata->csr_base + RTC_STAT) & RTC_STAT_BIT))
@@ -168,6 +152,10 @@ static int xgene_rtc_probe(struct platform_device *pdev) · 25 unmodified lines
168152 if (IS_ERR(pdata->csr_base))
169153 return PTR_ERR(pdata->csr_base);
170154
155+ pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
156+ if (IS_ERR(pdata->rtc))
157+ return PTR_ERR(pdata->rtc);
158+
171159 irq = platform_get_irq(pdev, 0);
172160 if (irq < 0) {
173161 dev_err(&pdev->dev, "No IRQ resource\n");
@@ -198,15 +186,16 @@ static int xgene_rtc_probe(struct platform_device *pdev) · 24 unmodified lines
198186 return ret;
199187 }
200188
201− pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
202− &xgene_rtc_ops, THIS_MODULE);
203− if (IS_ERR(pdata->rtc)) {
204− clk_disable_unprepare(pdata->clk);
205− return PTR_ERR(pdata->rtc);
206− }
207−
208189 /* HW does not support update faster than 1 seconds */
209190 pdata->rtc->uie_unsupported = 1;
191+ pdata->rtc->ops = &xgene_rtc_ops;
192+ pdata->rtc->range_max = U32_MAX;
193+
194+ ret = rtc_register_device(pdata->rtc);
195+ if (ret) {
196+ clk_disable_unprepare(pdata->clk);
197+ return ret;
198+ }
210199
211200 return 0;
212201 }
drivers/rtc/rtc-zynqmp.c+1−12
@@ -1,20 +1,9 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Xilinx Zynq Ultrascale+ MPSoC Real Time Clock Driver
34 *
45 * Copyright (C) 2015 Xilinx, Inc.
56 *
6− * This program is free software; you can redistribute it and/or modify it
7− * under the terms and conditions of the GNU General Public License,
8− * version 2, as published by the Free Software Foundation.
9− *
10− * This program is distributed in the hope it will be useful, but WITHOUT
11− * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12− * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13− * more details.
14− *
15− * You should have received a copy of the GNU General Public License along with
16− * this program. If not, see <http://www.gnu.org/licenses/>.
17− *
187 */
198
209 #include <linux/delay.h>
drivers/rtc/sysfs.c+9−14
@@ -1,20 +1,16 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * RTC subsystem, sysfs interface
34 *
45 * Copyright (C) 2005 Tower Technologies
56 * Author: Alessandro Zummo <a.zummo@towertech.it>
6− *
7− * This program is free software; you can redistribute it and/or modify
8− * it under the terms of the GNU General Public License version 2 as
9− * published by the Free Software Foundation.
10−*/
7+ */
118
129 #include <linux/module.h>
1310 #include <linux/rtc.h>
1411
1512 #include "rtc-core.h"
1613
17−
1814 /* device attributes */
1915
2016 /*
@@ -86,7 +82,7 @@ max_user_freq_show(struct device *dev, struct device_attribute *attr, char *buf) · 65 unmodified lines
8682
8783 static ssize_t
8884 max_user_freq_store(struct device *dev, struct device_attribute *attr,
89− const char *buf, size_t n)
85+ const char *buf, size_t n)
9086 {
9187 struct rtc_device *rtc = to_rtc_device(dev);
9288 unsigned long val;
@@ -116,12 +112,11 @@ hctosys_show(struct device *dev, struct device_attribute *attr, char *buf) · 23 unmodified lines
116112 {
117113 #ifdef CONFIG_RTC_HCTOSYS_DEVICE
118114 if (rtc_hctosys_ret == 0 &&
119− strcmp(dev_name(&to_rtc_device(dev)->dev),
120− CONFIG_RTC_HCTOSYS_DEVICE) == 0)
115+ strcmp(dev_name(&to_rtc_device(dev)->dev),
116+ CONFIG_RTC_HCTOSYS_DEVICE) == 0)
121117 return sprintf(buf, "1\n");
122− else
123118 #endif
124− return sprintf(buf, "0\n");
119+ return sprintf(buf, "0\n");
125120 }
126121 static DEVICE_ATTR_RO(hctosys);
127122
@@ -175,15 +170,15 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, · 47 unmodified lines
175170 if (*buf_ptr == '=') {
176171 buf_ptr++;
177172 push = 1;
178− } else
173+ } else {
179174 adjust = 1;
175+ }
180176 }
181177 retval = kstrtos64(buf_ptr, 0, &alarm);
182178 if (retval)
183179 return retval;
184− if (adjust) {
180+ if (adjust)
185181 alarm += now;
186− }
187182 if (alarm > now || push) {
188183 /* Avoid accidentally clobbering active alarms; we can't
189184 * entirely prevent that here, without even the minimal
drivers/rtc/systohc.c+2−11
@@ -1,9 +1,4 @@
1−/*
2− * This program is free software; you can redistribute it and/or modify it
3− * under the terms of the GNU General Public License version 2 as published by
4− * the Free Software Foundation.
5− *
6− */
1+// SPDX-License-Identifier: GPL-2.0
72 #include <linux/rtc.h>
83 #include <linux/time.h>
94
@@ -35,8 +30,7 @@ int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec) · 25 unmodified lines
3530 if (!rtc)
3631 goto out_err;
3732
38− if (!rtc->ops || (!rtc->ops->set_time && !rtc->ops->set_mmss64 &&
39− !rtc->ops->set_mmss))
33+ if (!rtc->ops || !rtc->ops->set_time)
4034 goto out_close;
4135
4236 /* Compute the value of tv_nsec we require the caller to supply in
@@ -58,9 +52,6 @@ int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec) · 15 unmodified lines
5852
5953 rtc_time64_to_tm(to_set.tv_sec, &tm);
6054
61− /* rtc_hctosys exclusively uses UTC, so we call set_time here, not
62− * set_mmss.
63− */
6455 err = rtc_set_time(rtc, &tm);
6556
6657 out_close:
include/linux/rtc.h+3−3
@@ -79,8 +79,6 @@ struct rtc_class_ops { · 78 unmodified lines
7979 int (*read_alarm)(struct device *, struct rtc_wkalrm *);
8080 int (*set_alarm)(struct device *, struct rtc_wkalrm *);
8181 int (*proc)(struct device *, struct seq_file *);
82− int (*set_mmss64)(struct device *, time64_t secs);
83− int (*set_mmss)(struct device *, unsigned long secs);
8482 int (*alarm_irq_enable)(struct device *, unsigned int enabled);
8583 int (*read_offset)(struct device *, long *offset);
8684 int (*set_offset)(struct device *, long offset);
@@ -162,9 +160,11 @@ struct rtc_device { · 75 unmodified lines
162160 #define to_rtc_device(d) container_of(d, struct rtc_device, dev)
163161
164162 /* useful timestamps */
165−#define RTC_TIMESTAMP_BEGIN_1900 -2208989361LL /* 1900-01-01 00:00:00 */
163+#define RTC_TIMESTAMP_BEGIN_1900 -2208988800LL /* 1900-01-01 00:00:00 */
166164 #define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */
165+#define RTC_TIMESTAMP_END_2063 2966371199LL /* 2063-12-31 23:59:59 */
167166 #define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */
167+#define RTC_TIMESTAMP_END_9999 253402300799LL /* 9999-12-31 23:59:59 */
168168
169169 extern struct rtc_device *devm_rtc_device_register(struct device *dev,
170170 const char *name,
include/linux/rtc/ds1685.h+0−2
@@ -48,8 +48,6 @@ struct ds1685_priv { · 47 unmodified lines
4848 u32 regstep;
4949 resource_size_t baseaddr;
5050 size_t size;
51− spinlock_t lock;
52− struct work_struct work;
5351 int irq_num;
5452 bool bcd_mode;
5553 bool no_irq;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t