aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-05-09 17:46:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-05-09 17:46:33 -0400
commit8e4ff713ce313dcabbb60e6ede1ffc193e67631f (patch)
tree8efdfe4925570ec8608d40e229ed01a5432d901e
parent45182e4e1f8ac04708ca7508c51d9103f07d81ab (diff)
parentdacb6a4035a010e41abaf81c1cfe2beadfb05ec8 (diff)
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() ...
-rw-r--r--Documentation/devicetree/bindings/rtc/nxp,pcf85063.txt6
-rw-r--r--Documentation/devicetree/bindings/rtc/rtc-aspeed.txt22
-rw-r--r--Documentation/devicetree/bindings/rtc/rtc.txt1
-rw-r--r--drivers/rtc/Kconfig19
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/class.c21
-rw-r--r--drivers/rtc/dev.c20
-rw-r--r--drivers/rtc/hctosys.c10
-rw-r--r--drivers/rtc/interface.c107
-rw-r--r--drivers/rtc/lib.c30
-rw-r--r--drivers/rtc/nvmem.c7
-rw-r--r--drivers/rtc/proc.c21
-rw-r--r--drivers/rtc/rtc-88pm80x.c14
-rw-r--r--drivers/rtc/rtc-88pm860x.c2
-rw-r--r--drivers/rtc/rtc-ab-b5ze-s3.c189
-rw-r--r--drivers/rtc/rtc-ab3100.c24
-rw-r--r--drivers/rtc/rtc-abx80x.c43
-rw-r--r--drivers/rtc/rtc-aspeed.c136
-rw-r--r--drivers/rtc/rtc-at91sam9.c108
-rw-r--r--drivers/rtc/rtc-brcmstb-waketimer.c2
-rw-r--r--drivers/rtc/rtc-coh901331.c37
-rw-r--r--drivers/rtc/rtc-da9063.c27
-rw-r--r--drivers/rtc/rtc-digicolor.c25
-rw-r--r--drivers/rtc/rtc-dm355evm.c24
-rw-r--r--drivers/rtc/rtc-ds1672.c127
-rw-r--r--drivers/rtc/rtc-ds1685.c262
-rw-r--r--drivers/rtc/rtc-ds2404.c73
-rw-r--r--drivers/rtc/rtc-ds3232.c40
-rw-r--r--drivers/rtc/rtc-ep93xx.c70
-rw-r--r--drivers/rtc/rtc-goldfish.c50
-rw-r--r--drivers/rtc/rtc-hid-sensor-time.c3
-rw-r--r--drivers/rtc/rtc-imxdi.c50
-rw-r--r--drivers/rtc/rtc-jz4740.c95
-rw-r--r--drivers/rtc/rtc-lpc32xx.c59
-rw-r--r--drivers/rtc/rtc-mc13xxx.c25
-rw-r--r--drivers/rtc/rtc-mt6397.c9
-rw-r--r--drivers/rtc/rtc-mv.c33
-rw-r--r--drivers/rtc/rtc-mxc.c86
-rw-r--r--drivers/rtc/rtc-mxc_v2.c29
-rw-r--r--drivers/rtc/rtc-omap.c32
-rw-r--r--drivers/rtc/rtc-opal.c2
-rw-r--r--drivers/rtc/rtc-pcap.c28
-rw-r--r--drivers/rtc/rtc-pcf85063.c446
-rw-r--r--drivers/rtc/rtc-pcf85363.c20
-rw-r--r--drivers/rtc/rtc-ps3.c30
-rw-r--r--drivers/rtc/rtc-pxa.c3
-rw-r--r--drivers/rtc/rtc-rk808.c6
-rw-r--r--drivers/rtc/rtc-rx6110.c9
-rw-r--r--drivers/rtc/rtc-rx8025.c2
-rw-r--r--drivers/rtc/rtc-sh.c30
-rw-r--r--drivers/rtc/rtc-sirfsoc.c2
-rw-r--r--drivers/rtc/rtc-snvs.c48
-rw-r--r--drivers/rtc/rtc-stm32.c9
-rw-r--r--drivers/rtc/rtc-stmp3xxx.c34
-rw-r--r--drivers/rtc/rtc-sun4v.c21
-rw-r--r--drivers/rtc/rtc-tegra.c47
-rw-r--r--drivers/rtc/rtc-test.c11
-rw-r--r--drivers/rtc/rtc-tx4939.c17
-rw-r--r--drivers/rtc/rtc-wm831x.c69
-rw-r--r--drivers/rtc/rtc-wm8350.c12
-rw-r--r--drivers/rtc/rtc-x1205.c7
-rw-r--r--drivers/rtc/rtc-xgene.c61
-rw-r--r--drivers/rtc/rtc-zynqmp.c13
-rw-r--r--drivers/rtc/sysfs.c23
-rw-r--r--drivers/rtc/systohc.c13
-rw-r--r--include/linux/rtc.h6
-rw-r--r--include/linux/rtc/ds1685.h2
67 files changed, 1400 insertions, 1510 deletions
diff --git a/Documentation/devicetree/bindings/rtc/nxp,pcf85063.txt b/Documentation/devicetree/bindings/rtc/nxp,pcf85063.txt
index d3e380ad712d..627bb533eff7 100644
--- a/Documentation/devicetree/bindings/rtc/nxp,pcf85063.txt
+++ b/Documentation/devicetree/bindings/rtc/nxp,pcf85063.txt
@@ -1,7 +1,11 @@
1* NXP PCF85063 Real Time Clock 1* NXP PCF85063 Real Time Clock
2 2
3Required properties: 3Required 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"
5- reg: I2C address for chip. 9- reg: I2C address for chip.
6 10
7Optional property: 11Optional property:
diff --git a/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
new file mode 100644
index 000000000000..2e956b3dc276
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt
@@ -0,0 +1,22 @@
1ASPEED BMC RTC
2==============
3
4Required 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
15Example:
16
17 rtc@1e781000 {
18 compatible = "aspeed,ast2400-rtc";
19 reg = <0x1e781000 0x18>;
20 interrupts = <22>;
21 status = "disabled";
22 };
diff --git a/Documentation/devicetree/bindings/rtc/rtc.txt b/Documentation/devicetree/bindings/rtc/rtc.txt
index f4687c68c08c..a97fc6a9a75e 100644
--- a/Documentation/devicetree/bindings/rtc/rtc.txt
+++ b/Documentation/devicetree/bindings/rtc/rtc.txt
@@ -69,3 +69,4 @@ ricoh,rv5c386 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
69ricoh,rv5c387a I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC 69ricoh,rv5c387a I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
70sii,s35390a 2-wire CMOS real-time clock 70sii,s35390a 2-wire CMOS real-time clock
71whwave,sd3078 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC 71whwave,sd3078 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
72xircom,x1205 Xircom X1205 I2C RTC
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index f933c06bff4f..7b8e156dbf38 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -439,6 +439,7 @@ config RTC_DRV_PCF8523
439 439
440config RTC_DRV_PCF85063 440config RTC_DRV_PCF85063
441 tristate "NXP PCF85063" 441 tristate "NXP PCF85063"
442 select REGMAP_I2C
442 help 443 help
443 If you say yes here you get support for the PCF85063 RTC chip 444 If you say yes here you get support for the PCF85063 RTC chip
444 445
@@ -447,7 +448,6 @@ config RTC_DRV_PCF85063
447 448
448config RTC_DRV_PCF85363 449config RTC_DRV_PCF85363
449 tristate "NXP PCF85363" 450 tristate "NXP PCF85363"
450 depends on I2C
451 select REGMAP_I2C 451 select REGMAP_I2C
452 help 452 help
453 If you say yes here you get support for the PCF85363 RTC chip. 453 If you say yes here you get support for the PCF85363 RTC chip.
@@ -602,7 +602,6 @@ config RTC_DRV_FM3130
602 602
603config RTC_DRV_RX8010 603config RTC_DRV_RX8010
604 tristate "Epson RX8010SJ" 604 tristate "Epson RX8010SJ"
605 depends on I2C
606 help 605 help
607 If you say yes here you get support for the Epson RX8010SJ RTC 606 If you say yes here you get support for the Epson RX8010SJ RTC
608 chip. 607 chip.
@@ -1432,7 +1431,7 @@ config RTC_DRV_AT91RM9200
1432config RTC_DRV_AT91SAM9 1431config RTC_DRV_AT91SAM9
1433 tristate "AT91SAM9 RTT as RTC" 1432 tristate "AT91SAM9 RTT as RTC"
1434 depends on ARCH_AT91 || COMPILE_TEST 1433 depends on ARCH_AT91 || COMPILE_TEST
1435 depends on HAS_IOMEM 1434 depends on OF && HAS_IOMEM
1436 select MFD_SYSCON 1435 select MFD_SYSCON
1437 help 1436 help
1438 Some AT91SAM9 SoCs provide an RTT (Real Time Timer) block which 1437 Some AT91SAM9 SoCs provide an RTT (Real Time Timer) block which
@@ -1841,6 +1840,17 @@ config RTC_DRV_RTD119X
1841 If you say yes here, you get support for the RTD1295 SoC 1840 If you say yes here, you get support for the RTD1295 SoC
1842 Real Time Clock. 1841 Real Time Clock.
1843 1842
1843config 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
1844comment "HID Sensor RTC drivers" 1854comment "HID Sensor RTC drivers"
1845 1855
1846config RTC_DRV_HID_SENSOR_TIME 1856config RTC_DRV_HID_SENSOR_TIME
@@ -1857,7 +1867,8 @@ config RTC_DRV_HID_SENSOR_TIME
1857 1867
1858config RTC_DRV_GOLDFISH 1868config RTC_DRV_GOLDFISH
1859 tristate "Goldfish Real Time Clock" 1869 tristate "Goldfish Real Time Clock"
1860 depends on MIPS && (GOLDFISH || COMPILE_TEST) 1870 depends on OF && HAS_IOMEM
1871 depends on GOLDFISH || COMPILE_TEST
1861 help 1872 help
1862 Say yes to enable RTC driver for the Goldfish based virtual platform. 1873 Say yes to enable RTC driver for the Goldfish based virtual platform.
1863 1874
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index fe3962496685..9d997faa2c26 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_AC100) += rtc-ac100.o
34obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o 34obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o
35obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o 35obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o
36obj-$(CONFIG_RTC_DRV_ASM9260) += rtc-asm9260.o 36obj-$(CONFIG_RTC_DRV_ASM9260) += rtc-asm9260.o
37obj-$(CONFIG_RTC_DRV_ASPEED) += rtc-aspeed.o
37obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o 38obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
38obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o 39obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
39obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o 40obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index ac93b76f2b11..0f492b0940b3 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * RTC subsystem, base class 3 * RTC subsystem, base class
3 * 4 *
@@ -5,11 +6,7 @@
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 7 *
7 * class skeleton from drivers/hwmon/hwmon.c 8 * class skeleton from drivers/hwmon/hwmon.c
8 * 9 */
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*/
13 10
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 12
@@ -23,13 +20,13 @@
23 20
24#include "rtc-core.h" 21#include "rtc-core.h"
25 22
26
27static DEFINE_IDA(rtc_ida); 23static DEFINE_IDA(rtc_ida);
28struct class *rtc_class; 24struct class *rtc_class;
29 25
30static void rtc_device_release(struct device *dev) 26static void rtc_device_release(struct device *dev)
31{ 27{
32 struct rtc_device *rtc = to_rtc_device(dev); 28 struct rtc_device *rtc = to_rtc_device(dev);
29
33 ida_simple_remove(&rtc_ida, rtc->id); 30 ida_simple_remove(&rtc_ida, rtc->id);
34 kfree(rtc); 31 kfree(rtc);
35} 32}
@@ -47,7 +44,6 @@ int rtc_hctosys_ret = -ENODEV;
47 44
48static struct timespec64 old_rtc, old_system, old_delta; 45static struct timespec64 old_rtc, old_system, old_delta;
49 46
50
51static int rtc_suspend(struct device *dev) 47static int rtc_suspend(struct device *dev)
52{ 48{
53 struct rtc_device *rtc = to_rtc_device(dev); 49 struct rtc_device *rtc = to_rtc_device(dev);
@@ -71,7 +67,6 @@ static int rtc_suspend(struct device *dev)
71 ktime_get_real_ts64(&old_system); 67 ktime_get_real_ts64(&old_system);
72 old_rtc.tv_sec = rtc_tm_to_time64(&tm); 68 old_rtc.tv_sec = rtc_tm_to_time64(&tm);
73 69
74
75 /* 70 /*
76 * To avoid drift caused by repeated suspend/resumes, 71 * To avoid drift caused by repeated suspend/resumes,
77 * which each can add ~1 second drift error, 72 * which each can add ~1 second drift error,
@@ -83,7 +78,7 @@ static int rtc_suspend(struct device *dev)
83 if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) { 78 if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) {
84 /* 79 /*
85 * if delta_delta is too large, assume time correction 80 * 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.
87 */ 82 */
88 old_delta = delta; 83 old_delta = delta;
89 } else { 84 } else {
@@ -136,7 +131,7 @@ static int rtc_resume(struct device *dev)
136 * to keep things accurate. 131 * to keep things accurate.
137 */ 132 */
138 sleep_time = timespec64_sub(sleep_time, 133 sleep_time = timespec64_sub(sleep_time,
139 timespec64_sub(new_system, old_system)); 134 timespec64_sub(new_system, old_system));
140 135
141 if (sleep_time.tv_sec >= 0) 136 if (sleep_time.tv_sec >= 0)
142 timekeeping_inject_sleeptime64(&sleep_time); 137 timekeeping_inject_sleeptime64(&sleep_time);
@@ -397,9 +392,9 @@ EXPORT_SYMBOL_GPL(__rtc_register_device);
397 * rtc_register_device instead 392 * rtc_register_device instead
398 */ 393 */
399struct rtc_device *devm_rtc_device_register(struct device *dev, 394struct rtc_device *devm_rtc_device_register(struct device *dev,
400 const char *name, 395 const char *name,
401 const struct rtc_class_ops *ops, 396 const struct rtc_class_ops *ops,
402 struct module *owner) 397 struct module *owner)
403{ 398{
404 struct rtc_device *rtc; 399 struct rtc_device *rtc;
405 int err; 400 int err;
diff --git a/drivers/rtc/dev.c b/drivers/rtc/dev.c
index 1d006ef4bb57..84feb2565abd 100644
--- a/drivers/rtc/dev.c
+++ b/drivers/rtc/dev.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * RTC subsystem, dev interface 3 * RTC subsystem, dev interface
3 * 4 *
@@ -5,11 +6,7 @@
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 7 *
7 * based on arch/arm/common/rtctime.c 8 * based on arch/arm/common/rtctime.c
8 * 9 */
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*/
13 10
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 12
@@ -60,7 +57,7 @@ static void rtc_uie_task(struct work_struct *work)
60 } else if (rtc->oldsecs != tm.tm_sec) { 57 } else if (rtc->oldsecs != tm.tm_sec) {
61 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60; 58 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60;
62 rtc->oldsecs = tm.tm_sec; 59 rtc->oldsecs = tm.tm_sec;
63 rtc->uie_timer.expires = jiffies + HZ - (HZ/10); 60 rtc->uie_timer.expires = jiffies + HZ - (HZ / 10);
64 rtc->uie_timer_active = 1; 61 rtc->uie_timer_active = 1;
65 rtc->uie_task_active = 0; 62 rtc->uie_task_active = 0;
66 add_timer(&rtc->uie_timer); 63 add_timer(&rtc->uie_timer);
@@ -71,6 +68,7 @@ static void rtc_uie_task(struct work_struct *work)
71 if (num) 68 if (num)
72 rtc_handle_legacy_irq(rtc, num, RTC_UF); 69 rtc_handle_legacy_irq(rtc, num, RTC_UF);
73} 70}
71
74static void rtc_uie_timer(struct timer_list *t) 72static void rtc_uie_timer(struct timer_list *t)
75{ 73{
76 struct rtc_device *rtc = from_timer(rtc, t, uie_timer); 74 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)
202} 200}
203 201
204static long rtc_dev_ioctl(struct file *file, 202static long rtc_dev_ioctl(struct file *file,
205 unsigned int cmd, unsigned long arg) 203 unsigned int cmd, unsigned long arg)
206{ 204{
207 int err = 0; 205 int err = 0;
208 struct rtc_device *rtc = file->private_data; 206 struct rtc_device *rtc = file->private_data;
209 const struct rtc_class_ops *ops = rtc->ops; 207 const struct rtc_class_ops *ops = rtc->ops;
210 struct rtc_time tm; 208 struct rtc_time tm;
211 struct rtc_wkalrm alarm; 209 struct rtc_wkalrm alarm;
212 void __user *uarg = (void __user *) arg; 210 void __user *uarg = (void __user *)arg;
213 211
214 err = mutex_lock_interruptible(&rtc->ops_lock); 212 err = mutex_lock_interruptible(&rtc->ops_lock);
215 if (err) 213 if (err)
@@ -233,7 +231,7 @@ static long rtc_dev_ioctl(struct file *file,
233 231
234 case RTC_PIE_ON: 232 case RTC_PIE_ON:
235 if (rtc->irq_freq > rtc->max_user_freq && 233 if (rtc->irq_freq > rtc->max_user_freq &&
236 !capable(CAP_SYS_RESOURCE)) 234 !capable(CAP_SYS_RESOURCE))
237 err = -EACCES; 235 err = -EACCES;
238 break; 236 break;
239 } 237 }
@@ -390,8 +388,9 @@ static long rtc_dev_ioctl(struct file *file,
390 err = ops->ioctl(rtc->dev.parent, cmd, arg); 388 err = ops->ioctl(rtc->dev.parent, cmd, arg);
391 if (err == -ENOIOCTLCMD) 389 if (err == -ENOIOCTLCMD)
392 err = -ENOTTY; 390 err = -ENOTTY;
393 } else 391 } else {
394 err = -ENOTTY; 392 err = -ENOTTY;
393 }
395 break; 394 break;
396 } 395 }
397 396
@@ -403,6 +402,7 @@ done:
403static int rtc_dev_fasync(int fd, struct file *file, int on) 402static int rtc_dev_fasync(int fd, struct file *file, int on)
404{ 403{
405 struct rtc_device *rtc = file->private_data; 404 struct rtc_device *rtc = file->private_data;
405
406 return fasync_helper(fd, file, on, &rtc->async_queue); 406 return fasync_helper(fd, file, on, &rtc->async_queue);
407} 407}
408 408
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index ff2092a0d38c..a74d0d890600 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -1,13 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * RTC subsystem, initialize system time on startup 3 * RTC subsystem, initialize system time on startup
3 * 4 *
4 * Copyright (C) 2005 Tower Technologies 5 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 7 */
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*/
11 8
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 10
@@ -33,7 +30,7 @@ static int __init rtc_hctosys(void)
33 }; 30 };
34 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); 31 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
35 32
36 if (rtc == NULL) { 33 if (!rtc) {
37 pr_info("unable to open rtc device (%s)\n", 34 pr_info("unable to open rtc device (%s)\n",
38 CONFIG_RTC_HCTOSYS_DEVICE); 35 CONFIG_RTC_HCTOSYS_DEVICE);
39 goto err_open; 36 goto err_open;
@@ -44,7 +41,6 @@ static int __init rtc_hctosys(void)
44 dev_err(rtc->dev.parent, 41 dev_err(rtc->dev.parent,
45 "hctosys: unable to read the hardware clock\n"); 42 "hctosys: unable to read the hardware clock\n");
46 goto err_read; 43 goto err_read;
47
48 } 44 }
49 45
50 tv64.tv_sec = rtc_tm_to_time64(&tm); 46 tv64.tv_sec = rtc_tm_to_time64(&tm);
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 98d9c87b0d1b..4124f4dd376b 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * RTC subsystem, interface functions 3 * RTC subsystem, interface functions
3 * 4 *
@@ -5,11 +6,7 @@
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 7 *
7 * based on arch/arm/common/rtctime.c 8 * based on arch/arm/common/rtctime.c
8 * 9 */
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*/
13 10
14#include <linux/rtc.h> 11#include <linux/rtc.h>
15#include <linux/sched.h> 12#include <linux/sched.h>
@@ -87,11 +84,12 @@ static int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm)
87static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) 84static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
88{ 85{
89 int err; 86 int err;
90 if (!rtc->ops) 87
88 if (!rtc->ops) {
91 err = -ENODEV; 89 err = -ENODEV;
92 else if (!rtc->ops->read_time) 90 } else if (!rtc->ops->read_time) {
93 err = -EINVAL; 91 err = -EINVAL;
94 else { 92 } else {
95 memset(tm, 0, sizeof(struct rtc_time)); 93 memset(tm, 0, sizeof(struct rtc_time));
96 err = rtc->ops->read_time(rtc->dev.parent, tm); 94 err = rtc->ops->read_time(rtc->dev.parent, tm);
97 if (err < 0) { 95 if (err < 0) {
@@ -147,14 +145,7 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
147 err = -ENODEV; 145 err = -ENODEV;
148 else if (rtc->ops->set_time) 146 else if (rtc->ops->set_time)
149 err = rtc->ops->set_time(rtc->dev.parent, tm); 147 err = rtc->ops->set_time(rtc->dev.parent, tm);
150 else if (rtc->ops->set_mmss64) { 148 else
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
158 err = -EINVAL; 149 err = -EINVAL;
159 150
160 pm_stay_awake(rtc->dev.parent); 151 pm_stay_awake(rtc->dev.parent);
@@ -167,7 +158,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
167} 158}
168EXPORT_SYMBOL_GPL(rtc_set_time); 159EXPORT_SYMBOL_GPL(rtc_set_time);
169 160
170static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm *alarm) 161static int rtc_read_alarm_internal(struct rtc_device *rtc,
162 struct rtc_wkalrm *alarm)
171{ 163{
172 int err; 164 int err;
173 165
@@ -175,11 +167,11 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm *al
175 if (err) 167 if (err)
176 return err; 168 return err;
177 169
178 if (rtc->ops == NULL) 170 if (!rtc->ops) {
179 err = -ENODEV; 171 err = -ENODEV;
180 else if (!rtc->ops->read_alarm) 172 } else if (!rtc->ops->read_alarm) {
181 err = -EINVAL; 173 err = -EINVAL;
182 else { 174 } else {
183 alarm->enabled = 0; 175 alarm->enabled = 0;
184 alarm->pending = 0; 176 alarm->pending = 0;
185 alarm->time.tm_sec = -1; 177 alarm->time.tm_sec = -1;
@@ -207,7 +199,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
207 int first_time = 1; 199 int first_time = 1;
208 time64_t t_now, t_alm; 200 time64_t t_now, t_alm;
209 enum { none, day, month, year } missing = none; 201 enum { none, day, month, year } missing = none;
210 unsigned days; 202 unsigned int days;
211 203
212 /* The lower level RTC driver may return -1 in some fields, 204 /* The lower level RTC driver may return -1 in some fields,
213 * creating invalid alarm->time values, for reasons like: 205 * creating invalid alarm->time values, for reasons like:
@@ -276,10 +268,10 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
276 return err; 268 return err;
277 269
278 /* note that tm_sec is a "don't care" value here: */ 270 /* note that tm_sec is a "don't care" value here: */
279 } while ( before.tm_min != now.tm_min 271 } while (before.tm_min != now.tm_min ||
280 || before.tm_hour != now.tm_hour 272 before.tm_hour != now.tm_hour ||
281 || before.tm_mon != now.tm_mon 273 before.tm_mon != now.tm_mon ||
282 || before.tm_year != now.tm_year); 274 before.tm_year != now.tm_year);
283 275
284 /* Fill in the missing alarm fields using the timestamp; we 276 /* Fill in the missing alarm fields using the timestamp; we
285 * know there's at least one since alarm->time is invalid. 277 * 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)
296 alarm->time.tm_mday = now.tm_mday; 288 alarm->time.tm_mday = now.tm_mday;
297 missing = day; 289 missing = day;
298 } 290 }
299 if ((unsigned)alarm->time.tm_mon >= 12) { 291 if ((unsigned int)alarm->time.tm_mon >= 12) {
300 alarm->time.tm_mon = now.tm_mon; 292 alarm->time.tm_mon = now.tm_mon;
301 if (missing == none) 293 if (missing == none)
302 missing = month; 294 missing = month;
@@ -321,7 +313,6 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
321 goto done; 313 goto done;
322 314
323 switch (missing) { 315 switch (missing) {
324
325 /* 24 hour rollover ... if it's now 10am Monday, an alarm that 316 /* 24 hour rollover ... if it's now 10am Monday, an alarm that
326 * that will trigger at 5am will do so at 5am Tuesday, which 317 * that will trigger at 5am will do so at 5am Tuesday, which
327 * could also be in the next month or year. This is a common 318 * 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)
341 case month: 332 case month:
342 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "month"); 333 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "month");
343 do { 334 do {
344 if (alarm->time.tm_mon < 11) 335 if (alarm->time.tm_mon < 11) {
345 alarm->time.tm_mon++; 336 alarm->time.tm_mon++;
346 else { 337 } else {
347 alarm->time.tm_mon = 0; 338 alarm->time.tm_mon = 0;
348 alarm->time.tm_year++; 339 alarm->time.tm_year++;
349 } 340 }
350 days = rtc_month_days(alarm->time.tm_mon, 341 days = rtc_month_days(alarm->time.tm_mon,
351 alarm->time.tm_year); 342 alarm->time.tm_year);
352 } while (days < alarm->time.tm_mday); 343 } while (days < alarm->time.tm_mday);
353 break; 344 break;
354 345
@@ -357,8 +348,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
357 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year"); 348 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year");
358 do { 349 do {
359 alarm->time.tm_year++; 350 alarm->time.tm_year++;
360 } while (!is_leap_year(alarm->time.tm_year + 1900) 351 } while (!is_leap_year(alarm->time.tm_year + 1900) &&
361 && rtc_valid_tm(&alarm->time) != 0); 352 rtc_valid_tm(&alarm->time) != 0);
362 break; 353 break;
363 354
364 default: 355 default:
@@ -369,7 +360,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
369 360
370done: 361done:
371 if (err) 362 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);
373 365
374 return err; 366 return err;
375} 367}
@@ -381,11 +373,11 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
381 err = mutex_lock_interruptible(&rtc->ops_lock); 373 err = mutex_lock_interruptible(&rtc->ops_lock);
382 if (err) 374 if (err)
383 return err; 375 return err;
384 if (rtc->ops == NULL) 376 if (!rtc->ops) {
385 err = -ENODEV; 377 err = -ENODEV;
386 else if (!rtc->ops->read_alarm) 378 } else if (!rtc->ops->read_alarm) {
387 err = -EINVAL; 379 err = -EINVAL;
388 else { 380 } else {
389 memset(alarm, 0, sizeof(struct rtc_wkalrm)); 381 memset(alarm, 0, sizeof(struct rtc_wkalrm));
390 alarm->enabled = rtc->aie_timer.enabled; 382 alarm->enabled = rtc->aie_timer.enabled;
391 alarm->time = rtc_ktime_to_tm(rtc->aie_timer.node.expires); 383 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)
494 /* Alarm has to be enabled & in the future for us to enqueue it */ 486 /* Alarm has to be enabled & in the future for us to enqueue it */
495 if (alarm->enabled && (rtc_tm_to_ktime(now) < 487 if (alarm->enabled && (rtc_tm_to_ktime(now) <
496 rtc->aie_timer.node.expires)) { 488 rtc->aie_timer.node.expires)) {
497
498 rtc->aie_timer.enabled = 1; 489 rtc->aie_timer.enabled = 1;
499 timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node); 490 timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node);
500 trace_rtc_timer_enqueue(&rtc->aie_timer); 491 trace_rtc_timer_enqueue(&rtc->aie_timer);
@@ -506,7 +497,9 @@ EXPORT_SYMBOL_GPL(rtc_initialize_alarm);
506 497
507int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled) 498int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled)
508{ 499{
509 int err = mutex_lock_interruptible(&rtc->ops_lock); 500 int err;
501
502 err = mutex_lock_interruptible(&rtc->ops_lock);
510 if (err) 503 if (err)
511 return err; 504 return err;
512 505
@@ -535,7 +528,9 @@ EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable);
535 528
536int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) 529int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
537{ 530{
538 int err = mutex_lock_interruptible(&rtc->ops_lock); 531 int err;
532
533 err = mutex_lock_interruptible(&rtc->ops_lock);
539 if (err) 534 if (err)
540 return err; 535 return err;
541 536
@@ -564,27 +559,25 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
564 rtc->uie_rtctimer.node.expires = ktime_add(now, onesec); 559 rtc->uie_rtctimer.node.expires = ktime_add(now, onesec);
565 rtc->uie_rtctimer.period = ktime_set(1, 0); 560 rtc->uie_rtctimer.period = ktime_set(1, 0);
566 err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer); 561 err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer);
567 } else 562 } else {
568 rtc_timer_remove(rtc, &rtc->uie_rtctimer); 563 rtc_timer_remove(rtc, &rtc->uie_rtctimer);
564 }
569 565
570out: 566out:
571 mutex_unlock(&rtc->ops_lock); 567 mutex_unlock(&rtc->ops_lock);
572#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 568#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
573 /* 569 /*
574 * Enable emulation if the driver did not provide 570 * Enable emulation if the driver returned -EINVAL to signal that it has
575 * the update_irq_enable function pointer or if returned 571 * been configured without interrupts or they are not available at the
576 * -EINVAL to signal that it has been configured without 572 * moment.
577 * interrupts or that are not available at the moment.
578 */ 573 */
579 if (err == -EINVAL) 574 if (err == -EINVAL)
580 err = rtc_dev_update_irq_enable_emul(rtc, enabled); 575 err = rtc_dev_update_irq_enable_emul(rtc, enabled);
581#endif 576#endif
582 return err; 577 return err;
583
584} 578}
585EXPORT_SYMBOL_GPL(rtc_update_irq_enable); 579EXPORT_SYMBOL_GPL(rtc_update_irq_enable);
586 580
587
588/** 581/**
589 * rtc_handle_legacy_irq - AIE, UIE and PIE event hook 582 * rtc_handle_legacy_irq - AIE, UIE and PIE event hook
590 * @rtc: pointer to the rtc device 583 * @rtc: pointer to the rtc device
@@ -599,14 +592,13 @@ void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode)
599 592
600 /* mark one irq of the appropriate mode */ 593 /* mark one irq of the appropriate mode */
601 spin_lock_irqsave(&rtc->irq_lock, flags); 594 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);
603 spin_unlock_irqrestore(&rtc->irq_lock, flags); 596 spin_unlock_irqrestore(&rtc->irq_lock, flags);
604 597
605 wake_up_interruptible(&rtc->irq_queue); 598 wake_up_interruptible(&rtc->irq_queue);
606 kill_fasync(&rtc->async_queue, SIGIO, POLL_IN); 599 kill_fasync(&rtc->async_queue, SIGIO, POLL_IN);
607} 600}
608 601
609
610/** 602/**
611 * rtc_aie_update_irq - AIE mode rtctimer hook 603 * rtc_aie_update_irq - AIE mode rtctimer hook
612 * @rtc: pointer to the rtc_device 604 * @rtc: pointer to the rtc_device
@@ -618,7 +610,6 @@ void rtc_aie_update_irq(struct rtc_device *rtc)
618 rtc_handle_legacy_irq(rtc, 1, RTC_AF); 610 rtc_handle_legacy_irq(rtc, 1, RTC_AF);
619} 611}
620 612
621
622/** 613/**
623 * rtc_uie_update_irq - UIE mode rtctimer hook 614 * rtc_uie_update_irq - UIE mode rtctimer hook
624 * @rtc: pointer to the rtc_device 615 * @rtc: pointer to the rtc_device
@@ -630,7 +621,6 @@ void rtc_uie_update_irq(struct rtc_device *rtc)
630 rtc_handle_legacy_irq(rtc, 1, RTC_UF); 621 rtc_handle_legacy_irq(rtc, 1, RTC_UF);
631} 622}
632 623
633
634/** 624/**
635 * rtc_pie_update_irq - PIE mode hrtimer hook 625 * rtc_pie_update_irq - PIE mode hrtimer hook
636 * @timer: pointer to the pie mode hrtimer 626 * @timer: pointer to the pie mode hrtimer
@@ -644,6 +634,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
644 struct rtc_device *rtc; 634 struct rtc_device *rtc;
645 ktime_t period; 635 ktime_t period;
646 int count; 636 int count;
637
647 rtc = container_of(timer, struct rtc_device, pie_timer); 638 rtc = container_of(timer, struct rtc_device, pie_timer);
648 639
649 period = NSEC_PER_SEC / rtc->irq_freq; 640 period = NSEC_PER_SEC / rtc->irq_freq;
@@ -662,7 +653,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
662 * Context: any 653 * Context: any
663 */ 654 */
664void rtc_update_irq(struct rtc_device *rtc, 655void rtc_update_irq(struct rtc_device *rtc,
665 unsigned long num, unsigned long events) 656 unsigned long num, unsigned long events)
666{ 657{
667 if (IS_ERR_OR_NULL(rtc)) 658 if (IS_ERR_OR_NULL(rtc))
668 return; 659 return;
@@ -811,6 +802,7 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
811 if (!next || ktime_before(timer->node.expires, next->expires)) { 802 if (!next || ktime_before(timer->node.expires, next->expires)) {
812 struct rtc_wkalrm alarm; 803 struct rtc_wkalrm alarm;
813 int err; 804 int err;
805
814 alarm.time = rtc_ktime_to_tm(timer->node.expires); 806 alarm.time = rtc_ktime_to_tm(timer->node.expires);
815 alarm.enabled = 1; 807 alarm.enabled = 1;
816 err = __rtc_set_alarm(rtc, &alarm); 808 err = __rtc_set_alarm(rtc, &alarm);
@@ -851,12 +843,14 @@ static void rtc_alarm_disable(struct rtc_device *rtc)
851static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer) 843static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer)
852{ 844{
853 struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue); 845 struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue);
846
854 timerqueue_del(&rtc->timerqueue, &timer->node); 847 timerqueue_del(&rtc->timerqueue, &timer->node);
855 trace_rtc_timer_dequeue(timer); 848 trace_rtc_timer_dequeue(timer);
856 timer->enabled = 0; 849 timer->enabled = 0;
857 if (next == &timer->node) { 850 if (next == &timer->node) {
858 struct rtc_wkalrm alarm; 851 struct rtc_wkalrm alarm;
859 int err; 852 int err;
853
860 next = timerqueue_getnext(&rtc->timerqueue); 854 next = timerqueue_getnext(&rtc->timerqueue);
861 if (!next) { 855 if (!next) {
862 rtc_alarm_disable(rtc); 856 rtc_alarm_disable(rtc);
@@ -929,9 +923,9 @@ again:
929 alarm.enabled = 1; 923 alarm.enabled = 1;
930reprogram: 924reprogram:
931 err = __rtc_set_alarm(rtc, &alarm); 925 err = __rtc_set_alarm(rtc, &alarm);
932 if (err == -ETIME) 926 if (err == -ETIME) {
933 goto again; 927 goto again;
934 else if (err) { 928 } else if (err) {
935 if (retry-- > 0) 929 if (retry-- > 0)
936 goto reprogram; 930 goto reprogram;
937 931
@@ -942,14 +936,14 @@ reprogram:
942 dev_err(&rtc->dev, "__rtc_set_alarm: err=%d\n", err); 936 dev_err(&rtc->dev, "__rtc_set_alarm: err=%d\n", err);
943 goto again; 937 goto again;
944 } 938 }
945 } else 939 } else {
946 rtc_alarm_disable(rtc); 940 rtc_alarm_disable(rtc);
941 }
947 942
948 pm_relax(rtc->dev.parent); 943 pm_relax(rtc->dev.parent);
949 mutex_unlock(&rtc->ops_lock); 944 mutex_unlock(&rtc->ops_lock);
950} 945}
951 946
952
953/* rtc_timer_init - Initializes an rtc_timer 947/* rtc_timer_init - Initializes an rtc_timer
954 * @timer: timer to be intiialized 948 * @timer: timer to be intiialized
955 * @f: function pointer to be called when timer fires 949 * @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),
975 * Kernel interface to set an rtc_timer 969 * Kernel interface to set an rtc_timer
976 */ 970 */
977int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer, 971int 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)
979{ 973{
980 int ret = 0; 974 int ret = 0;
975
981 mutex_lock(&rtc->ops_lock); 976 mutex_lock(&rtc->ops_lock);
982 if (timer->enabled) 977 if (timer->enabled)
983 rtc_timer_remove(rtc, timer); 978 rtc_timer_remove(rtc, timer);
diff --git a/drivers/rtc/lib.c b/drivers/rtc/lib.c
index 9714cb3d1e29..23284580df97 100644
--- a/drivers/rtc/lib.c
+++ b/drivers/rtc/lib.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * rtc and date/time utility functions 3 * rtc and date/time utility functions
3 * 4 *
@@ -5,11 +6,7 @@
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 7 *
7 * based on arch/arm/common/rtctime.c and other bits 8 * based on arch/arm/common/rtctime.c and other bits
8 * 9 */
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*/
13 10
14#include <linux/export.h> 11#include <linux/export.h>
15#include <linux/rtc.h> 12#include <linux/rtc.h>
@@ -25,7 +22,7 @@ static const unsigned short rtc_ydays[2][13] = {
25 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } 22 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
26}; 23};
27 24
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)
29 26
30/* 27/*
31 * The number of days in the month. 28 * The number of days in the month.
@@ -41,11 +38,10 @@ EXPORT_SYMBOL(rtc_month_days);
41 */ 38 */
42int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) 39int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
43{ 40{
44 return rtc_ydays[is_leap_year(year)][month] + day-1; 41 return rtc_ydays[is_leap_year(year)][month] + day - 1;
45} 42}
46EXPORT_SYMBOL(rtc_year_days); 43EXPORT_SYMBOL(rtc_year_days);
47 44
48
49/* 45/*
50 * rtc_time64_to_tm - Converts time64_t to rtc_time. 46 * rtc_time64_to_tm - Converts time64_t to rtc_time.
51 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. 47 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
@@ -97,13 +93,15 @@ EXPORT_SYMBOL(rtc_time64_to_tm);
97 */ 93 */
98int rtc_valid_tm(struct rtc_time *tm) 94int rtc_valid_tm(struct rtc_time *tm)
99{ 95{
100 if (tm->tm_year < 70 96 if (tm->tm_year < 70 ||
101 || ((unsigned)tm->tm_mon) >= 12 97 tm->tm_year > (INT_MAX - 1900) ||
102 || tm->tm_mday < 1 98 ((unsigned int)tm->tm_mon) >= 12 ||
103 || tm->tm_mday > rtc_month_days(tm->tm_mon, ((unsigned)tm->tm_year + 1900)) 99 tm->tm_mday < 1 ||
104 || ((unsigned)tm->tm_hour) >= 24 100 tm->tm_mday > rtc_month_days(tm->tm_mon,
105 || ((unsigned)tm->tm_min) >= 60 101 ((unsigned int)tm->tm_year + 1900)) ||
106 || ((unsigned)tm->tm_sec) >= 60) 102 ((unsigned int)tm->tm_hour) >= 24 ||
103 ((unsigned int)tm->tm_min) >= 60 ||
104 ((unsigned int)tm->tm_sec) >= 60)
107 return -EINVAL; 105 return -EINVAL;
108 106
109 return 0; 107 return 0;
@@ -116,7 +114,7 @@ EXPORT_SYMBOL(rtc_valid_tm);
116 */ 114 */
117time64_t rtc_tm_to_time64(struct rtc_time *tm) 115time64_t rtc_tm_to_time64(struct rtc_time *tm)
118{ 116{
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,
120 tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); 118 tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
121} 119}
122EXPORT_SYMBOL(rtc_tm_to_time64); 120EXPORT_SYMBOL(rtc_tm_to_time64);
diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c
index dce518d5e50e..4312096c7738 100644
--- a/drivers/rtc/nvmem.c
+++ b/drivers/rtc/nvmem.c
@@ -1,11 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * RTC subsystem, nvmem interface 3 * RTC subsystem, nvmem interface
3 * 4 *
4 * Copyright (C) 2017 Alexandre Belloni 5 * 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.
9 */ 6 */
10 7
11#include <linux/err.h> 8#include <linux/err.h>
@@ -46,7 +43,7 @@ static int rtc_nvram_register(struct rtc_device *rtc,
46{ 43{
47 int err; 44 int err;
48 45
49 rtc->nvram = kzalloc(sizeof(struct bin_attribute), GFP_KERNEL); 46 rtc->nvram = kzalloc(sizeof(*rtc->nvram), GFP_KERNEL);
50 if (!rtc->nvram) 47 if (!rtc->nvram)
51 return -ENOMEM; 48 return -ENOMEM;
52 49
diff --git a/drivers/rtc/proc.c b/drivers/rtc/proc.c
index 4d74e4f4ff30..73344598fc1b 100644
--- a/drivers/rtc/proc.c
+++ b/drivers/rtc/proc.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * RTC subsystem, proc interface 3 * RTC subsystem, proc interface
3 * 4 *
@@ -5,11 +6,7 @@
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 7 *
7 * based on arch/arm/common/rtctime.c 8 * based on arch/arm/common/rtctime.c
8 * 9 */
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*/
13 10
14#include <linux/module.h> 11#include <linux/module.h>
15#include <linux/rtc.h> 12#include <linux/rtc.h>
@@ -60,17 +57,17 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
60 seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time); 57 seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
61 seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time); 58 seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
62 seq_printf(seq, "alarm_IRQ\t: %s\n", 59 seq_printf(seq, "alarm_IRQ\t: %s\n",
63 alrm.enabled ? "yes" : "no"); 60 alrm.enabled ? "yes" : "no");
64 seq_printf(seq, "alrm_pending\t: %s\n", 61 seq_printf(seq, "alrm_pending\t: %s\n",
65 alrm.pending ? "yes" : "no"); 62 alrm.pending ? "yes" : "no");
66 seq_printf(seq, "update IRQ enabled\t: %s\n", 63 seq_printf(seq, "update IRQ enabled\t: %s\n",
67 (rtc->uie_rtctimer.enabled) ? "yes" : "no"); 64 (rtc->uie_rtctimer.enabled) ? "yes" : "no");
68 seq_printf(seq, "periodic IRQ enabled\t: %s\n", 65 seq_printf(seq, "periodic IRQ enabled\t: %s\n",
69 (rtc->pie_enabled) ? "yes" : "no"); 66 (rtc->pie_enabled) ? "yes" : "no");
70 seq_printf(seq, "periodic IRQ frequency\t: %d\n", 67 seq_printf(seq, "periodic IRQ frequency\t: %d\n",
71 rtc->irq_freq); 68 rtc->irq_freq);
72 seq_printf(seq, "max user IRQ frequency\t: %d\n", 69 seq_printf(seq, "max user IRQ frequency\t: %d\n",
73 rtc->max_user_freq); 70 rtc->max_user_freq);
74 } 71 }
75 72
76 seq_printf(seq, "24hr\t\t: yes\n"); 73 seq_printf(seq, "24hr\t\t: yes\n");
@@ -85,7 +82,7 @@ void rtc_proc_add_device(struct rtc_device *rtc)
85{ 82{
86 if (is_rtc_hctosys(rtc)) 83 if (is_rtc_hctosys(rtc))
87 proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show, 84 proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
88 rtc); 85 rtc);
89} 86}
90 87
91void rtc_proc_del_device(struct rtc_device *rtc) 88void rtc_proc_del_device(struct rtc_device *rtc)
diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c
index 1fc48ebd3cd0..e4d5a19fd1c9 100644
--- a/drivers/rtc/rtc-88pm80x.c
+++ b/drivers/rtc/rtc-88pm80x.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Real Time Clock driver for Marvell 88PM80x PMIC 3 * Real Time Clock driver for Marvell 88PM80x PMIC
3 * 4 *
4 * Copyright (c) 2012 Marvell International Ltd. 5 * Copyright (c) 2012 Marvell International Ltd.
5 * Wenzeng Chen<wzch@marvell.com> 6 * Wenzeng Chen<wzch@marvell.com>
6 * Qiao Zhou <zhouqiao@marvell.com> 7 * 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
20 */ 8 */
21 9
22#include <linux/kernel.h> 10#include <linux/kernel.h>
diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
index d25282b4a7dd..73697e4b18a9 100644
--- a/drivers/rtc/rtc-88pm860x.c
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -421,7 +421,7 @@ static int pm860x_rtc_remove(struct platform_device *pdev)
421 struct pm860x_rtc_info *info = platform_get_drvdata(pdev); 421 struct pm860x_rtc_info *info = platform_get_drvdata(pdev);
422 422
423#ifdef VRTC_CALIBRATION 423#ifdef VRTC_CALIBRATION
424 flush_scheduled_work(); 424 cancel_delayed_work_sync(&info->calib_work);
425 /* disable measurement */ 425 /* disable measurement */
426 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0); 426 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
427#endif /* VRTC_CALIBRATION */ 427#endif /* VRTC_CALIBRATION */
diff --git a/drivers/rtc/rtc-ab-b5ze-s3.c b/drivers/rtc/rtc-ab-b5ze-s3.c
index 2233601761ac..cdad6f00debf 100644
--- a/drivers/rtc/rtc-ab-b5ze-s3.c
+++ b/drivers/rtc/rtc-ab-b5ze-s3.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * rtc-ab-b5ze-s3 - Driver for Abracon AB-RTCMC-32.768Khz-B5ZE-S3 3 * rtc-ab-b5ze-s3 - Driver for Abracon AB-RTCMC-32.768Khz-B5ZE-S3
3 * I2C RTC / Alarm chip 4 * I2C RTC / Alarm chip
@@ -10,19 +11,9 @@
10 * 11 *
11 * This work is based on ISL12057 driver (drivers/rtc/rtc-isl12057.c). 12 * This work is based on ISL12057 driver (drivers/rtc/rtc-isl12057.c).
12 * 13 *
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.
22 */ 14 */
23 15
24#include <linux/module.h> 16#include <linux/module.h>
25#include <linux/mutex.h>
26#include <linux/rtc.h> 17#include <linux/rtc.h>
27#include <linux/i2c.h> 18#include <linux/i2c.h>
28#include <linux/bcd.h> 19#include <linux/bcd.h>
@@ -128,7 +119,6 @@
128struct abb5zes3_rtc_data { 119struct abb5zes3_rtc_data {
129 struct rtc_device *rtc; 120 struct rtc_device *rtc;
130 struct regmap *regmap; 121 struct regmap *regmap;
131 struct mutex lock;
132 122
133 int irq; 123 int irq;
134 124
@@ -138,8 +128,7 @@ struct abb5zes3_rtc_data {
138 128
139/* 129/*
140 * Try and match register bits w/ fixed null values to see whether we 130 * 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 131 * are dealing with an ABB5ZES3.
142 * during init and hence does need mutex protection.
143 */ 132 */
144static int abb5zes3_i2c_validate_chip(struct regmap *regmap) 133static int abb5zes3_i2c_validate_chip(struct regmap *regmap)
145{ 134{
@@ -230,14 +219,12 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm)
230 if (ret) { 219 if (ret) {
231 dev_err(dev, "%s: reading RTC time failed (%d)\n", 220 dev_err(dev, "%s: reading RTC time failed (%d)\n",
232 __func__, ret); 221 __func__, ret);
233 goto err; 222 return ret;
234 } 223 }
235 224
236 /* If clock integrity is not guaranteed, do not return a time value */ 225 /* If clock integrity is not guaranteed, do not return a time value */
237 if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC) { 226 if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC)
238 ret = -ENODATA; 227 return -ENODATA;
239 goto err;
240 }
241 228
242 tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F); 229 tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F);
243 tm->tm_min = bcd2bin(regs[ABB5ZES3_REG_RTC_MN]); 230 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)
255 tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */ 242 tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */
256 tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100; 243 tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100;
257 244
258err:
259 return ret; 245 return ret;
260} 246}
261 247
@@ -273,12 +259,9 @@ static int abb5zes3_rtc_set_time(struct device *dev, struct rtc_time *tm)
273 regs[ABB5ZES3_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1); 259 regs[ABB5ZES3_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1);
274 regs[ABB5ZES3_REG_RTC_YR] = bin2bcd(tm->tm_year - 100); 260 regs[ABB5ZES3_REG_RTC_YR] = bin2bcd(tm->tm_year - 100);
275 261
276 mutex_lock(&data->lock);
277 ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_RTC_SC, 262 ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_RTC_SC,
278 regs + ABB5ZES3_REG_RTC_SC, 263 regs + ABB5ZES3_REG_RTC_SC,
279 ABB5ZES3_RTC_SEC_LEN); 264 ABB5ZES3_RTC_SEC_LEN);
280 mutex_unlock(&data->lock);
281
282 265
283 return ret; 266 return ret;
284} 267}
@@ -332,38 +315,35 @@ static int _abb5zes3_rtc_read_timer(struct device *dev,
332 if (ret) { 315 if (ret) {
333 dev_err(dev, "%s: reading Timer A section failed (%d)\n", 316 dev_err(dev, "%s: reading Timer A section failed (%d)\n",
334 __func__, ret); 317 __func__, ret);
335 goto err; 318 return ret;
336 } 319 }
337 320
338 /* get current time ... */ 321 /* get current time ... */
339 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); 322 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
340 if (ret) 323 if (ret)
341 goto err; 324 return ret;
342 325
343 /* ... convert to seconds ... */ 326 /* ... convert to seconds ... */
344 ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); 327 rtc_secs = rtc_tm_to_time64(&rtc_tm);
345 if (ret)
346 goto err;
347 328
348 /* ... add remaining timer A time ... */ 329 /* ... add remaining timer A time ... */
349 ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]); 330 ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]);
350 if (ret) 331 if (ret)
351 goto err; 332 return ret;
352 333
353 /* ... and convert back. */ 334 /* ... 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);
355 336
356 ret = regmap_read(data->regmap, ABB5ZES3_REG_CTRL2, &reg); 337 ret = regmap_read(data->regmap, ABB5ZES3_REG_CTRL2, &reg);
357 if (ret) { 338 if (ret) {
358 dev_err(dev, "%s: reading ctrl reg failed (%d)\n", 339 dev_err(dev, "%s: reading ctrl reg failed (%d)\n",
359 __func__, ret); 340 __func__, ret);
360 goto err; 341 return ret;
361 } 342 }
362 343
363 alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE); 344 alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE);
364 345
365err: 346 return 0;
366 return ret;
367} 347}
368 348
369/* Read alarm currently configured via a RTC alarm registers. */ 349/* Read alarm currently configured via a RTC alarm registers. */
@@ -382,7 +362,7 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
382 if (ret) { 362 if (ret) {
383 dev_err(dev, "%s: reading alarm section failed (%d)\n", 363 dev_err(dev, "%s: reading alarm section failed (%d)\n",
384 __func__, ret); 364 __func__, ret);
385 goto err; 365 return ret;
386 } 366 }
387 367
388 alarm_tm->tm_sec = 0; 368 alarm_tm->tm_sec = 0;
@@ -398,18 +378,13 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
398 */ 378 */
399 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); 379 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
400 if (ret) 380 if (ret)
401 goto err; 381 return ret;
402 382
403 alarm_tm->tm_year = rtc_tm.tm_year; 383 alarm_tm->tm_year = rtc_tm.tm_year;
404 alarm_tm->tm_mon = rtc_tm.tm_mon; 384 alarm_tm->tm_mon = rtc_tm.tm_mon;
405 385
406 ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); 386 rtc_secs = rtc_tm_to_time64(&rtc_tm);
407 if (ret) 387 alarm_secs = rtc_tm_to_time64(alarm_tm);
408 goto err;
409
410 ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
411 if (ret)
412 goto err;
413 388
414 if (alarm_secs < rtc_secs) { 389 if (alarm_secs < rtc_secs) {
415 if (alarm_tm->tm_mon == 11) { 390 if (alarm_tm->tm_mon == 11) {
@@ -424,13 +399,12 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
424 if (ret) { 399 if (ret) {
425 dev_err(dev, "%s: reading ctrl reg failed (%d)\n", 400 dev_err(dev, "%s: reading ctrl reg failed (%d)\n",
426 __func__, ret); 401 __func__, ret);
427 goto err; 402 return ret;
428 } 403 }
429 404
430 alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE); 405 alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE);
431 406
432err: 407 return 0;
433 return ret;
434} 408}
435 409
436/* 410/*
@@ -447,12 +421,10 @@ static int abb5zes3_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
447 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); 421 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
448 int ret; 422 int ret;
449 423
450 mutex_lock(&data->lock);
451 if (data->timer_alarm) 424 if (data->timer_alarm)
452 ret = _abb5zes3_rtc_read_timer(dev, alarm); 425 ret = _abb5zes3_rtc_read_timer(dev, alarm);
453 else 426 else
454 ret = _abb5zes3_rtc_read_alarm(dev, alarm); 427 ret = _abb5zes3_rtc_read_alarm(dev, alarm);
455 mutex_unlock(&data->lock);
456 428
457 return ret; 429 return ret;
458} 430}
@@ -466,33 +438,25 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
466{ 438{
467 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); 439 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
468 struct rtc_time *alarm_tm = &alarm->time; 440 struct rtc_time *alarm_tm = &alarm->time;
469 unsigned long rtc_secs, alarm_secs;
470 u8 regs[ABB5ZES3_ALRM_SEC_LEN]; 441 u8 regs[ABB5ZES3_ALRM_SEC_LEN];
471 struct rtc_time rtc_tm; 442 struct rtc_time rtc_tm;
472 int ret, enable = 1; 443 int ret, enable = 1;
473 444
474 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); 445 if (!alarm->enabled) {
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) {
488 enable = 0; 446 enable = 0;
489 } else { 447 } else {
448 unsigned long rtc_secs, alarm_secs;
449
490 /* 450 /*
491 * Chip only support alarms up to one month in the future. Let's 451 * Chip only support alarms up to one month in the future. Let's
492 * return an error if we get something after that limit. 452 * return an error if we get something after that limit.
493 * Comparison is done by incrementing rtc_tm month field by one 453 * Comparison is done by incrementing rtc_tm month field by one
494 * and checking alarm value is still below. 454 * and checking alarm value is still below.
495 */ 455 */
456 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
457 if (ret)
458 return ret;
459
496 if (rtc_tm.tm_mon == 11) { /* handle year wrapping */ 460 if (rtc_tm.tm_mon == 11) { /* handle year wrapping */
497 rtc_tm.tm_mon = 0; 461 rtc_tm.tm_mon = 0;
498 rtc_tm.tm_year += 1; 462 rtc_tm.tm_year += 1;
@@ -500,15 +464,13 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
500 rtc_tm.tm_mon += 1; 464 rtc_tm.tm_mon += 1;
501 } 465 }
502 466
503 ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); 467 rtc_secs = rtc_tm_to_time64(&rtc_tm);
504 if (ret) 468 alarm_secs = rtc_tm_to_time64(alarm_tm);
505 goto err;
506 469
507 if (alarm_secs > rtc_secs) { 470 if (alarm_secs > rtc_secs) {
508 dev_err(dev, "%s: alarm maximum is one month in the " 471 dev_err(dev, "%s: alarm maximum is one month in the future (%d)\n",
509 "future (%d)\n", __func__, ret); 472 __func__, ret);
510 ret = -EINVAL; 473 return -EINVAL;
511 goto err;
512 } 474 }
513 } 475 }
514 476
@@ -526,17 +488,14 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
526 if (ret < 0) { 488 if (ret < 0) {
527 dev_err(dev, "%s: writing ALARM section failed (%d)\n", 489 dev_err(dev, "%s: writing ALARM section failed (%d)\n",
528 __func__, ret); 490 __func__, ret);
529 goto err; 491 return ret;
530 } 492 }
531 493
532 /* Record currently configured alarm is not a timer */ 494 /* Record currently configured alarm is not a timer */
533 data->timer_alarm = 0; 495 data->timer_alarm = 0;
534 496
535 /* Enable or disable alarm interrupt generation */ 497 /* Enable or disable alarm interrupt generation */
536 ret = _abb5zes3_rtc_update_alarm(dev, enable); 498 return _abb5zes3_rtc_update_alarm(dev, enable);
537
538err:
539 return ret;
540} 499}
541 500
542/* 501/*
@@ -557,7 +516,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm,
557 ABB5ZES3_TIMA_SEC_LEN); 516 ABB5ZES3_TIMA_SEC_LEN);
558 if (ret < 0) { 517 if (ret < 0) {
559 dev_err(dev, "%s: writing timer section failed\n", __func__); 518 dev_err(dev, "%s: writing timer section failed\n", __func__);
560 goto err; 519 return ret;
561 } 520 }
562 521
563 /* Configure Timer A as a watchdog timer */ 522 /* Configure Timer A as a watchdog timer */
@@ -570,10 +529,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm,
570 data->timer_alarm = 1; 529 data->timer_alarm = 1;
571 530
572 /* Enable or disable timer interrupt generation */ 531 /* Enable or disable timer interrupt generation */
573 ret = _abb5zes3_rtc_update_timer(dev, alarm->enabled); 532 return _abb5zes3_rtc_update_timer(dev, alarm->enabled);
574
575err:
576 return ret;
577} 533}
578 534
579/* 535/*
@@ -590,31 +546,25 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
590 struct rtc_time rtc_tm; 546 struct rtc_time rtc_tm;
591 int ret; 547 int ret;
592 548
593 mutex_lock(&data->lock);
594 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); 549 ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
595 if (ret) 550 if (ret)
596 goto err; 551 return ret;
597 552
598 ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); 553 rtc_secs = rtc_tm_to_time64(&rtc_tm);
599 if (ret) 554 alarm_secs = rtc_tm_to_time64(alarm_tm);
600 goto err;
601
602 ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
603 if (ret)
604 goto err;
605 555
606 /* Let's first disable both the alarm and the timer interrupts */ 556 /* Let's first disable both the alarm and the timer interrupts */
607 ret = _abb5zes3_rtc_update_alarm(dev, false); 557 ret = _abb5zes3_rtc_update_alarm(dev, false);
608 if (ret < 0) { 558 if (ret < 0) {
609 dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__, 559 dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__,
610 ret); 560 ret);
611 goto err; 561 return ret;
612 } 562 }
613 ret = _abb5zes3_rtc_update_timer(dev, false); 563 ret = _abb5zes3_rtc_update_timer(dev, false);
614 if (ret < 0) { 564 if (ret < 0) {
615 dev_err(dev, "%s: unable to disable timer (%d)\n", __func__, 565 dev_err(dev, "%s: unable to disable timer (%d)\n", __func__,
616 ret); 566 ret);
617 goto err; 567 return ret;
618 } 568 }
619 569
620 data->timer_alarm = 0; 570 data->timer_alarm = 0;
@@ -629,9 +579,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
629 else 579 else
630 ret = _abb5zes3_rtc_set_alarm(dev, alarm); 580 ret = _abb5zes3_rtc_set_alarm(dev, alarm);
631 581
632 err:
633 mutex_unlock(&data->lock);
634
635 if (ret) 582 if (ret)
636 dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__, 583 dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__,
637 ret); 584 ret);
@@ -650,8 +597,7 @@ static inline int _abb5zes3_rtc_battery_low_irq_enable(struct regmap *regmap,
650 597
651/* 598/*
652 * Check current RTC status and enable/disable what needs to be. Return 0 if 599 * 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 600 * everything went ok and a negative value upon error.
654 * is called early during init and hence does need mutex protection.
655 */ 601 */
656static int abb5zes3_rtc_check_setup(struct device *dev) 602static int abb5zes3_rtc_check_setup(struct device *dev)
657{ 603{
@@ -675,8 +621,9 @@ static int abb5zes3_rtc_check_setup(struct device *dev)
675 ABB5ZES3_REG_TIM_CLK_COF1 | ABB5ZES3_REG_TIM_CLK_COF2 | 621 ABB5ZES3_REG_TIM_CLK_COF1 | ABB5ZES3_REG_TIM_CLK_COF2 |
676 ABB5ZES3_REG_TIM_CLK_TBM | ABB5ZES3_REG_TIM_CLK_TAM); 622 ABB5ZES3_REG_TIM_CLK_TBM | ABB5ZES3_REG_TIM_CLK_TAM);
677 ret = regmap_update_bits(regmap, ABB5ZES3_REG_TIM_CLK, mask, 623 ret = regmap_update_bits(regmap, ABB5ZES3_REG_TIM_CLK, mask,
678 ABB5ZES3_REG_TIM_CLK_COF0 | ABB5ZES3_REG_TIM_CLK_COF1 | 624 ABB5ZES3_REG_TIM_CLK_COF0 |
679 ABB5ZES3_REG_TIM_CLK_COF2); 625 ABB5ZES3_REG_TIM_CLK_COF1 |
626 ABB5ZES3_REG_TIM_CLK_COF2);
680 if (ret < 0) { 627 if (ret < 0) {
681 dev_err(dev, "%s: unable to initialize clkout register (%d)\n", 628 dev_err(dev, "%s: unable to initialize clkout register (%d)\n",
682 __func__, ret); 629 __func__, ret);
@@ -729,9 +676,9 @@ static int abb5zes3_rtc_check_setup(struct device *dev)
729 * switchover flag but not battery low flag. The latter is checked 676 * switchover flag but not battery low flag. The latter is checked
730 * later below. 677 * later below.
731 */ 678 */
732 mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 | 679 mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 |
733 ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE | 680 ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE |
734 ABB5ZES3_REG_CTRL3_BSIE| ABB5ZES3_REG_CTRL3_BSF); 681 ABB5ZES3_REG_CTRL3_BSIE | ABB5ZES3_REG_CTRL3_BSF);
735 ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL3, mask, 0); 682 ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL3, mask, 0);
736 if (ret < 0) { 683 if (ret < 0) {
737 dev_err(dev, "%s: unable to initialize CTRL3 register (%d)\n", 684 dev_err(dev, "%s: unable to initialize CTRL3 register (%d)\n",
@@ -748,10 +695,8 @@ static int abb5zes3_rtc_check_setup(struct device *dev)
748 } 695 }
749 696
750 if (reg & ABB5ZES3_REG_RTC_SC_OSC) { 697 if (reg & ABB5ZES3_REG_RTC_SC_OSC) {
751 dev_err(dev, "clock integrity not guaranteed. Osc. has stopped " 698 dev_err(dev, "clock integrity not guaranteed. Osc. has stopped or has been interrupted.\n");
752 "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");
753 dev_err(dev, "change battery (if not already done) and "
754 "then set time to reset osc. failure flag.\n");
755 } 700 }
756 701
757 /* 702 /*
@@ -769,13 +714,12 @@ static int abb5zes3_rtc_check_setup(struct device *dev)
769 714
770 data->battery_low = reg & ABB5ZES3_REG_CTRL3_BLF; 715 data->battery_low = reg & ABB5ZES3_REG_CTRL3_BLF;
771 if (data->battery_low) { 716 if (data->battery_low) {
772 dev_err(dev, "RTC battery is low; please, consider " 717 dev_err(dev, "RTC battery is low; please, consider changing it!\n");
773 "changing it!\n");
774 718
775 ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, false); 719 ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, false);
776 if (ret) 720 if (ret)
777 dev_err(dev, "%s: disabling battery low interrupt " 721 dev_err(dev, "%s: disabling battery low interrupt generation failed (%d)\n",
778 "generation failed (%d)\n", __func__, ret); 722 __func__, ret);
779 } 723 }
780 724
781 return ret; 725 return ret;
@@ -788,12 +732,10 @@ static int abb5zes3_rtc_alarm_irq_enable(struct device *dev,
788 int ret = 0; 732 int ret = 0;
789 733
790 if (rtc_data->irq) { 734 if (rtc_data->irq) {
791 mutex_lock(&rtc_data->lock);
792 if (rtc_data->timer_alarm) 735 if (rtc_data->timer_alarm)
793 ret = _abb5zes3_rtc_update_timer(dev, enable); 736 ret = _abb5zes3_rtc_update_timer(dev, enable);
794 else 737 else
795 ret = _abb5zes3_rtc_update_alarm(dev, enable); 738 ret = _abb5zes3_rtc_update_alarm(dev, enable);
796 mutex_unlock(&rtc_data->lock);
797 } 739 }
798 740
799 return ret; 741 return ret;
@@ -885,49 +827,44 @@ static int abb5zes3_probe(struct i2c_client *client,
885 827
886 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | 828 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
887 I2C_FUNC_SMBUS_BYTE_DATA | 829 I2C_FUNC_SMBUS_BYTE_DATA |
888 I2C_FUNC_SMBUS_I2C_BLOCK)) { 830 I2C_FUNC_SMBUS_I2C_BLOCK))
889 ret = -ENODEV; 831 return -ENODEV;
890 goto err;
891 }
892 832
893 regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config); 833 regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config);
894 if (IS_ERR(regmap)) { 834 if (IS_ERR(regmap)) {
895 ret = PTR_ERR(regmap); 835 ret = PTR_ERR(regmap);
896 dev_err(dev, "%s: regmap allocation failed: %d\n", 836 dev_err(dev, "%s: regmap allocation failed: %d\n",
897 __func__, ret); 837 __func__, ret);
898 goto err; 838 return ret;
899 } 839 }
900 840
901 ret = abb5zes3_i2c_validate_chip(regmap); 841 ret = abb5zes3_i2c_validate_chip(regmap);
902 if (ret) 842 if (ret)
903 goto err; 843 return ret;
904 844
905 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 845 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
906 if (!data) { 846 if (!data)
907 ret = -ENOMEM; 847 return -ENOMEM;
908 goto err;
909 }
910 848
911 mutex_init(&data->lock);
912 data->regmap = regmap; 849 data->regmap = regmap;
913 dev_set_drvdata(dev, data); 850 dev_set_drvdata(dev, data);
914 851
915 ret = abb5zes3_rtc_check_setup(dev); 852 ret = abb5zes3_rtc_check_setup(dev);
916 if (ret) 853 if (ret)
917 goto err; 854 return ret;
918 855
919 data->rtc = devm_rtc_allocate_device(dev); 856 data->rtc = devm_rtc_allocate_device(dev);
920 ret = PTR_ERR_OR_ZERO(data->rtc); 857 ret = PTR_ERR_OR_ZERO(data->rtc);
921 if (ret) { 858 if (ret) {
922 dev_err(dev, "%s: unable to allocate RTC device (%d)\n", 859 dev_err(dev, "%s: unable to allocate RTC device (%d)\n",
923 __func__, ret); 860 __func__, ret);
924 goto err; 861 return ret;
925 } 862 }
926 863
927 if (client->irq > 0) { 864 if (client->irq > 0) {
928 ret = devm_request_threaded_irq(dev, client->irq, NULL, 865 ret = devm_request_threaded_irq(dev, client->irq, NULL,
929 _abb5zes3_rtc_interrupt, 866 _abb5zes3_rtc_interrupt,
930 IRQF_SHARED|IRQF_ONESHOT, 867 IRQF_SHARED | IRQF_ONESHOT,
931 DRV_NAME, client); 868 DRV_NAME, client);
932 if (!ret) { 869 if (!ret) {
933 device_init_wakeup(dev, true); 870 device_init_wakeup(dev, true);
@@ -949,8 +886,8 @@ static int abb5zes3_probe(struct i2c_client *client,
949 if (!data->battery_low && data->irq) { 886 if (!data->battery_low && data->irq) {
950 ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, true); 887 ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, true);
951 if (ret) { 888 if (ret) {
952 dev_err(dev, "%s: enabling battery low interrupt " 889 dev_err(dev, "%s: enabling battery low interrupt generation failed (%d)\n",
953 "generation failed (%d)\n", __func__, ret); 890 __func__, ret);
954 goto err; 891 goto err;
955 } 892 }
956 } 893 }
@@ -958,7 +895,7 @@ static int abb5zes3_probe(struct i2c_client *client,
958 ret = rtc_register_device(data->rtc); 895 ret = rtc_register_device(data->rtc);
959 896
960err: 897err:
961 if (ret && data && data->irq) 898 if (ret && data->irq)
962 device_init_wakeup(dev, false); 899 device_init_wakeup(dev, false);
963 return ret; 900 return ret;
964} 901}
diff --git a/drivers/rtc/rtc-ab3100.c b/drivers/rtc/rtc-ab3100.c
index 821ff52a2222..2ed6def90975 100644
--- a/drivers/rtc/rtc-ab3100.c
+++ b/drivers/rtc/rtc-ab3100.c
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2007-2009 ST-Ericsson AB 3 * Copyright (C) 2007-2009 ST-Ericsson AB
3 * License terms: GNU General Public License (GPL) version 2
4 * RTC clock driver for the AB3100 Analog Baseband Chip 4 * RTC clock driver for the AB3100 Analog Baseband Chip
5 * Author: Linus Walleij <linus.walleij@stericsson.com> 5 * Author: Linus Walleij <linus.walleij@stericsson.com>
6 */ 6 */
@@ -43,12 +43,12 @@
43/* 43/*
44 * RTC clock functions and device struct declaration 44 * RTC clock functions and device struct declaration
45 */ 45 */
46static int ab3100_rtc_set_mmss(struct device *dev, time64_t secs) 46static int ab3100_rtc_set_time(struct device *dev, struct rtc_time *tm)
47{ 47{
48 u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2, 48 u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2,
49 AB3100_TI3, AB3100_TI4, AB3100_TI5}; 49 AB3100_TI3, AB3100_TI4, AB3100_TI5};
50 unsigned char buf[6]; 50 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;
52 int err = 0; 52 int err = 0;
53 int i; 53 int i;
54 54
@@ -192,7 +192,7 @@ static int ab3100_rtc_irq_enable(struct device *dev, unsigned int enabled)
192 192
193static const struct rtc_class_ops ab3100_rtc_ops = { 193static const struct rtc_class_ops ab3100_rtc_ops = {
194 .read_time = ab3100_rtc_read_time, 194 .read_time = ab3100_rtc_read_time,
195 .set_mmss64 = ab3100_rtc_set_mmss, 195 .set_time = ab3100_rtc_set_time,
196 .read_alarm = ab3100_rtc_read_alarm, 196 .read_alarm = ab3100_rtc_read_alarm,
197 .set_alarm = ab3100_rtc_set_alarm, 197 .set_alarm = ab3100_rtc_set_alarm,
198 .alarm_irq_enable = ab3100_rtc_irq_enable, 198 .alarm_irq_enable = ab3100_rtc_irq_enable,
@@ -228,15 +228,17 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
228 /* Ignore any error on this write */ 228 /* Ignore any error on this write */
229 } 229 }
230 230
231 rtc = devm_rtc_device_register(&pdev->dev, "ab3100-rtc", 231 rtc = devm_rtc_allocate_device(&pdev->dev);
232 &ab3100_rtc_ops, THIS_MODULE); 232 if (IS_ERR(rtc))
233 if (IS_ERR(rtc)) { 233 return PTR_ERR(rtc);
234 err = PTR_ERR(rtc); 234
235 return err; 235 rtc->ops = &ab3100_rtc_ops;
236 } 236 /* 48bit counter at (AB3100_RTC_CLOCK_RATE * 2) */
237 rtc->range_max = U32_MAX;
238
237 platform_set_drvdata(pdev, rtc); 239 platform_set_drvdata(pdev, rtc);
238 240
239 return 0; 241 return rtc_register_device(rtc);
240} 242}
241 243
242static struct platform_driver ab3100_rtc_driver = { 244static struct platform_driver ab3100_rtc_driver = {
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index 6ddcad642d1e..73830670a41f 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * A driver for the I2C members of the Abracon AB x8xx RTC family, 3 * A driver for the I2C members of the Abracon AB x8xx RTC family,
3 * and compatible: AB 1805 and AB 0805 4 * and compatible: AB 1805 and AB 0805
@@ -7,10 +8,6 @@
7 * Author: Philippe De Muyter <phdm@macqel.be> 8 * Author: Philippe De Muyter <phdm@macqel.be>
8 * Author: Alexandre Belloni <alexandre.belloni@bootlin.com> 9 * Author: Alexandre Belloni <alexandre.belloni@bootlin.com>
9 * 10 *
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 *
14 */ 11 */
15 12
16#include <linux/bcd.h> 13#include <linux/bcd.h>
@@ -404,7 +401,7 @@ static ssize_t autocalibration_store(struct device *dev,
404 return -EINVAL; 401 return -EINVAL;
405 } 402 }
406 403
407 retval = abx80x_rtc_set_autocalibration(dev, autocalibration); 404 retval = abx80x_rtc_set_autocalibration(dev->parent, autocalibration);
408 405
409 return retval ? retval : count; 406 return retval ? retval : count;
410} 407}
@@ -414,7 +411,7 @@ static ssize_t autocalibration_show(struct device *dev,
414{ 411{
415 int autocalibration = 0; 412 int autocalibration = 0;
416 413
417 autocalibration = abx80x_rtc_get_autocalibration(dev); 414 autocalibration = abx80x_rtc_get_autocalibration(dev->parent);
418 if (autocalibration < 0) { 415 if (autocalibration < 0) {
419 dev_err(dev, "Failed to read RTC autocalibration\n"); 416 dev_err(dev, "Failed to read RTC autocalibration\n");
420 sprintf(buf, "0\n"); 417 sprintf(buf, "0\n");
@@ -430,7 +427,7 @@ static ssize_t oscillator_store(struct device *dev,
430 struct device_attribute *attr, 427 struct device_attribute *attr,
431 const char *buf, size_t count) 428 const char *buf, size_t count)
432{ 429{
433 struct i2c_client *client = to_i2c_client(dev); 430 struct i2c_client *client = to_i2c_client(dev->parent);
434 int retval, flags, rc_mode = 0; 431 int retval, flags, rc_mode = 0;
435 432
436 if (strncmp(buf, "rc", 2) == 0) { 433 if (strncmp(buf, "rc", 2) == 0) {
@@ -472,7 +469,7 @@ static ssize_t oscillator_show(struct device *dev,
472 struct device_attribute *attr, char *buf) 469 struct device_attribute *attr, char *buf)
473{ 470{
474 int rc_mode = 0; 471 int rc_mode = 0;
475 struct i2c_client *client = to_i2c_client(dev); 472 struct i2c_client *client = to_i2c_client(dev->parent);
476 473
477 rc_mode = abx80x_is_rc_mode(client); 474 rc_mode = abx80x_is_rc_mode(client);
478 475
@@ -592,13 +589,6 @@ static int abx80x_dt_trickle_cfg(struct device_node *np)
592 return (trickle_cfg | i); 589 return (trickle_cfg | i);
593} 590}
594 591
595static 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
602#ifdef CONFIG_WATCHDOG 592#ifdef CONFIG_WATCHDOG
603 593
604static inline u8 timeout_bits(unsigned int timeout) 594static inline u8 timeout_bits(unsigned int timeout)
@@ -851,32 +841,14 @@ static int abx80x_probe(struct i2c_client *client,
851 } 841 }
852 } 842 }
853 843
854 /* Export sysfs entries */ 844 err = rtc_add_group(priv->rtc, &rtc_calib_attr_group);
855 err = sysfs_create_group(&(&client->dev)->kobj, &rtc_calib_attr_group);
856 if (err) { 845 if (err) {
857 dev_err(&client->dev, "Failed to create sysfs group: %d\n", 846 dev_err(&client->dev, "Failed to create sysfs group: %d\n",
858 err); 847 err);
859 return err; 848 return err;
860 } 849 }
861 850
862 err = devm_add_action_or_reset(&client->dev, 851 return rtc_register_device(priv->rtc);
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
877static int abx80x_remove(struct i2c_client *client)
878{
879 return 0;
880} 852}
881 853
882static const struct i2c_device_id abx80x_id[] = { 854static const struct i2c_device_id abx80x_id[] = {
@@ -899,7 +871,6 @@ static struct i2c_driver abx80x_driver = {
899 .name = "rtc-abx80x", 871 .name = "rtc-abx80x",
900 }, 872 },
901 .probe = abx80x_probe, 873 .probe = abx80x_probe,
902 .remove = abx80x_remove,
903 .id_table = abx80x_id, 874 .id_table = abx80x_id,
904}; 875};
905 876
diff --git a/drivers/rtc/rtc-aspeed.c b/drivers/rtc/rtc-aspeed.c
new file mode 100644
index 000000000000..af3eb676d7c3
--- /dev/null
+++ b/drivers/rtc/rtc-aspeed.c
@@ -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
10struct 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
22static 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
53static 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
80static const struct rtc_class_ops aspeed_rtc_ops = {
81 .read_time = aspeed_rtc_read_time,
82 .set_time = aspeed_rtc_set_time,
83};
84
85static 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
117static 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};
123MODULE_DEVICE_TABLE(of, aspeed_rtc_match);
124
125static 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
132module_platform_driver_probe(aspeed_rtc_driver, aspeed_rtc_probe);
133
134MODULE_DESCRIPTION("ASPEED RTC driver");
135MODULE_AUTHOR("Joel Stanley <joel@jms.id.au>");
136MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 1d31c0ae6334..4daf3789b978 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -1,14 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * "RTT as Real Time Clock" driver for AT91SAM9 SoC family 3 * "RTT as Real Time Clock" driver for AT91SAM9 SoC family
3 * 4 *
4 * (C) 2007 Michel Benoit 5 * (C) 2007 Michel Benoit
5 * 6 *
6 * Based on rtc-at91rm9200.c by Rick Bronson 7 * 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.
12 */ 8 */
13 9
14#include <linux/clk.h> 10#include <linux/clk.h>
@@ -47,21 +43,21 @@
47 * registers available, likewise usable for more than "RTC" support. 43 * registers available, likewise usable for more than "RTC" support.
48 */ 44 */
49 45
50#define AT91_RTT_MR 0x00 /* Real-time Mode Register */ 46#define AT91_RTT_MR 0x00 /* Real-time Mode Register */
51#define AT91_RTT_RTPRES (0xffff << 0) /* Real-time Timer Prescaler Value */ 47#define AT91_RTT_RTPRES (0xffff << 0) /* Timer Prescaler Value */
52#define AT91_RTT_ALMIEN (1 << 16) /* Alarm Interrupt Enable */ 48#define AT91_RTT_ALMIEN BIT(16) /* Alarm Interrupt Enable */
53#define AT91_RTT_RTTINCIEN (1 << 17) /* Real Time Timer Increment Interrupt Enable */ 49#define AT91_RTT_RTTINCIEN BIT(17) /* Increment Interrupt Enable */
54#define AT91_RTT_RTTRST (1 << 18) /* Real Time Timer Restart */ 50#define AT91_RTT_RTTRST BIT(18) /* Timer Restart */
55 51
56#define AT91_RTT_AR 0x04 /* Real-time Alarm Register */ 52#define AT91_RTT_AR 0x04 /* Real-time Alarm Register */
57#define AT91_RTT_ALMV (0xffffffff) /* Alarm Value */ 53#define AT91_RTT_ALMV (0xffffffff) /* Alarm Value */
58 54
59#define AT91_RTT_VR 0x08 /* Real-time Value Register */ 55#define AT91_RTT_VR 0x08 /* Real-time Value Register */
60#define AT91_RTT_CRTV (0xffffffff) /* Current Real-time Value */ 56#define AT91_RTT_CRTV (0xffffffff) /* Current Real-time Value */
61 57
62#define AT91_RTT_SR 0x0c /* Real-time Status Register */ 58#define AT91_RTT_SR 0x0c /* Real-time Status Register */
63#define AT91_RTT_ALMS (1 << 0) /* Real-time Alarm Status */ 59#define AT91_RTT_ALMS BIT(0) /* Alarm Status */
64#define AT91_RTT_RTTINC (1 << 1) /* Real-time Timer Increment */ 60#define AT91_RTT_RTTINC BIT(1) /* Timer Increment */
65 61
66/* 62/*
67 * We store ALARM_DISABLED in ALMV to record that no alarm is set. 63 * We store ALARM_DISABLED in ALMV to record that no alarm is set.
@@ -69,14 +65,13 @@
69 */ 65 */
70#define ALARM_DISABLED ((u32)~0) 66#define ALARM_DISABLED ((u32)~0)
71 67
72
73struct sam9_rtc { 68struct sam9_rtc {
74 void __iomem *rtt; 69 void __iomem *rtt;
75 struct rtc_device *rtcdev; 70 struct rtc_device *rtcdev;
76 u32 imr; 71 u32 imr;
77 struct regmap *gpbr; 72 struct regmap *gpbr;
78 unsigned int gpbr_offset; 73 unsigned int gpbr_offset;
79 int irq; 74 int irq;
80 struct clk *sclk; 75 struct clk *sclk;
81 bool suspended; 76 bool suspended;
82 unsigned long events; 77 unsigned long events;
@@ -122,7 +117,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
122 if (secs != secs2) 117 if (secs != secs2)
123 secs = rtt_readl(rtc, VR); 118 secs = rtt_readl(rtc, VR);
124 119
125 rtc_time_to_tm(offset + secs, tm); 120 rtc_time64_to_tm(offset + secs, tm);
126 121
127 dev_dbg(dev, "%s: %ptR\n", __func__, tm); 122 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
128 123
@@ -135,15 +130,12 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
135static int at91_rtc_settime(struct device *dev, struct rtc_time *tm) 130static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
136{ 131{
137 struct sam9_rtc *rtc = dev_get_drvdata(dev); 132 struct sam9_rtc *rtc = dev_get_drvdata(dev);
138 int err;
139 u32 offset, alarm, mr; 133 u32 offset, alarm, mr;
140 unsigned long secs; 134 unsigned long secs;
141 135
142 dev_dbg(dev, "%s: %ptR\n", __func__, tm); 136 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
143 137
144 err = rtc_tm_to_time(tm, &secs); 138 secs = rtc_tm_to_time64(tm);
145 if (err != 0)
146 return err;
147 139
148 mr = rtt_readl(rtc, MR); 140 mr = rtt_readl(rtc, MR);
149 141
@@ -193,7 +185,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
193 185
194 memset(alrm, 0, sizeof(*alrm)); 186 memset(alrm, 0, sizeof(*alrm));
195 if (alarm != ALARM_DISABLED && offset != 0) { 187 if (alarm != ALARM_DISABLED && offset != 0) {
196 rtc_time_to_tm(offset + alarm, tm); 188 rtc_time64_to_tm(offset + alarm, tm);
197 189
198 dev_dbg(dev, "%s: %ptR\n", __func__, tm); 190 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
199 191
@@ -211,11 +203,8 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
211 unsigned long secs; 203 unsigned long secs;
212 u32 offset; 204 u32 offset;
213 u32 mr; 205 u32 mr;
214 int err;
215 206
216 err = rtc_tm_to_time(tm, &secs); 207 secs = rtc_tm_to_time64(tm);
217 if (err != 0)
218 return err;
219 208
220 offset = gpbr_readl(rtc); 209 offset = gpbr_readl(rtc);
221 if (offset == 0) { 210 if (offset == 0) {
@@ -263,7 +252,7 @@ static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
263 u32 mr = rtt_readl(rtc, MR); 252 u32 mr = rtt_readl(rtc, MR);
264 253
265 seq_printf(seq, "update_IRQ\t: %s\n", 254 seq_printf(seq, "update_IRQ\t: %s\n",
266 (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no"); 255 (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no");
267 return 0; 256 return 0;
268} 257}
269 258
@@ -299,7 +288,7 @@ static void at91_rtc_flush_events(struct sam9_rtc *rtc)
299 rtc->events = 0; 288 rtc->events = 0;
300 289
301 pr_debug("%s: num=%ld, events=0x%02lx\n", __func__, 290 pr_debug("%s: num=%ld, events=0x%02lx\n", __func__,
302 rtc->events >> 8, rtc->events & 0x000000FF); 291 rtc->events >> 8, rtc->events & 0x000000FF);
303} 292}
304 293
305/* 294/*
@@ -340,13 +329,6 @@ static const struct rtc_class_ops at91_rtc_ops = {
340 .alarm_irq_enable = at91_rtc_alarm_irq_enable, 329 .alarm_irq_enable = at91_rtc_alarm_irq_enable,
341}; 330};
342 331
343static const struct regmap_config gpbr_regmap_config = {
344 .name = "gpbr",
345 .reg_bits = 32,
346 .val_bits = 32,
347 .reg_stride = 4,
348};
349
350/* 332/*
351 * Initialize and install RTC driver 333 * Initialize and install RTC driver
352 */ 334 */
@@ -357,6 +339,7 @@ static int at91_rtc_probe(struct platform_device *pdev)
357 int ret, irq; 339 int ret, irq;
358 u32 mr; 340 u32 mr;
359 unsigned int sclk_rate; 341 unsigned int sclk_rate;
342 struct of_phandle_args args;
360 343
361 irq = platform_get_irq(pdev, 0); 344 irq = platform_get_irq(pdev, 0);
362 if (irq < 0) { 345 if (irq < 0) {
@@ -382,34 +365,14 @@ static int at91_rtc_probe(struct platform_device *pdev)
382 if (IS_ERR(rtc->rtt)) 365 if (IS_ERR(rtc->rtt))
383 return PTR_ERR(rtc->rtt); 366 return PTR_ERR(rtc->rtt);
384 367
385 if (!pdev->dev.of_node) { 368 ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
386 /* 369 "atmel,rtt-rtc-time-reg", 1, 0,
387 * TODO: Remove this code chunk when removing non DT board 370 &args);
388 * support. Remember to remove the gpbr_regmap_config 371 if (ret)
389 * variable too. 372 return ret;
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 }
412 373
374 rtc->gpbr = syscon_node_to_regmap(args.np);
375 rtc->gpbr_offset = args.args[0];
413 if (IS_ERR(rtc->gpbr)) { 376 if (IS_ERR(rtc->gpbr)) {
414 dev_err(&pdev->dev, "failed to retrieve gpbr regmap, aborting.\n"); 377 dev_err(&pdev->dev, "failed to retrieve gpbr regmap, aborting.\n");
415 return -ENOMEM; 378 return -ENOMEM;
@@ -444,13 +407,15 @@ static int at91_rtc_probe(struct platform_device *pdev)
444 mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); 407 mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
445 rtt_writel(rtc, MR, mr); 408 rtt_writel(rtc, MR, mr);
446 409
447 rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name, 410 rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev);
448 &at91_rtc_ops, THIS_MODULE);
449 if (IS_ERR(rtc->rtcdev)) { 411 if (IS_ERR(rtc->rtcdev)) {
450 ret = PTR_ERR(rtc->rtcdev); 412 ret = PTR_ERR(rtc->rtcdev);
451 goto err_clk; 413 goto err_clk;
452 } 414 }
453 415
416 rtc->rtcdev->ops = &at91_rtc_ops;
417 rtc->rtcdev->range_max = U32_MAX;
418
454 /* register irq handler after we know what name we'll use */ 419 /* register irq handler after we know what name we'll use */
455 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt, 420 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt,
456 IRQF_SHARED | IRQF_COND_SUSPEND, 421 IRQF_SHARED | IRQF_COND_SUSPEND,
@@ -468,9 +433,9 @@ static int at91_rtc_probe(struct platform_device *pdev)
468 433
469 if (gpbr_readl(rtc) == 0) 434 if (gpbr_readl(rtc) == 0)
470 dev_warn(&pdev->dev, "%s: SET TIME!\n", 435 dev_warn(&pdev->dev, "%s: SET TIME!\n",
471 dev_name(&rtc->rtcdev->dev)); 436 dev_name(&rtc->rtcdev->dev));
472 437
473 return 0; 438 return rtc_register_device(rtc->rtcdev);
474 439
475err_clk: 440err_clk:
476 clk_disable_unprepare(rtc->sclk); 441 clk_disable_unprepare(rtc->sclk);
@@ -528,8 +493,9 @@ static int at91_rtc_suspend(struct device *dev)
528 /* don't let RTTINC cause wakeups */ 493 /* don't let RTTINC cause wakeups */
529 if (mr & AT91_RTT_RTTINCIEN) 494 if (mr & AT91_RTT_RTTINCIEN)
530 rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN); 495 rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN);
531 } else 496 } else {
532 rtt_writel(rtc, MR, mr & ~rtc->imr); 497 rtt_writel(rtc, MR, mr & ~rtc->imr);
498 }
533 } 499 }
534 500
535 return 0; 501 return 0;
@@ -561,13 +527,11 @@ static int at91_rtc_resume(struct device *dev)
561 527
562static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume); 528static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
563 529
564#ifdef CONFIG_OF
565static const struct of_device_id at91_rtc_dt_ids[] = { 530static const struct of_device_id at91_rtc_dt_ids[] = {
566 { .compatible = "atmel,at91sam9260-rtt" }, 531 { .compatible = "atmel,at91sam9260-rtt" },
567 { /* sentinel */ } 532 { /* sentinel */ }
568}; 533};
569MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids); 534MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids);
570#endif
571 535
572static struct platform_driver at91_rtc_driver = { 536static struct platform_driver at91_rtc_driver = {
573 .probe = at91_rtc_probe, 537 .probe = at91_rtc_probe,
diff --git a/drivers/rtc/rtc-brcmstb-waketimer.c b/drivers/rtc/rtc-brcmstb-waketimer.c
index f4010a75f2be..a193396a8140 100644
--- a/drivers/rtc/rtc-brcmstb-waketimer.c
+++ b/drivers/rtc/rtc-brcmstb-waketimer.c
@@ -132,7 +132,7 @@ static int brcmstb_waketmr_gettime(struct device *dev,
132 132
133 wktmr_read(timer, &now); 133 wktmr_read(timer, &now);
134 134
135 rtc_time_to_tm(now.sec, tm); 135 rtc_time64_to_tm(now.sec, tm);
136 136
137 return 0; 137 return 0;
138} 138}
diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c
index 0b232c84f674..4ac850837153 100644
--- a/drivers/rtc/rtc-coh901331.c
+++ b/drivers/rtc/rtc-coh901331.c
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2007-2009 ST-Ericsson AB 3 * Copyright (C) 2007-2009 ST-Ericsson AB
3 * License terms: GNU General Public License (GPL) version 2
4 * Real Time Clock interface for ST-Ericsson AB COH 901 331 RTC. 4 * Real Time Clock interface for ST-Ericsson AB COH 901 331 RTC.
5 * Author: Linus Walleij <linus.walleij@stericsson.com> 5 * Author: Linus Walleij <linus.walleij@stericsson.com>
6 * Based on rtc-pl031.c by Deepak Saxena <dsaxena@plexity.net> 6 * 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)
80 80
81 clk_enable(rtap->clk); 81 clk_enable(rtap->clk);
82 /* Check if the time is valid */ 82 /* Check if the time is valid */
83 if (readl(rtap->virtbase + COH901331_VALID)) { 83 if (!readl(rtap->virtbase + COH901331_VALID)) {
84 rtc_time_to_tm(readl(rtap->virtbase + COH901331_CUR_TIME), tm);
85 clk_disable(rtap->clk); 84 clk_disable(rtap->clk);
86 return 0; 85 return -EINVAL;
87 } 86 }
87
88 rtc_time64_to_tm(readl(rtap->virtbase + COH901331_CUR_TIME), tm);
88 clk_disable(rtap->clk); 89 clk_disable(rtap->clk);
89 return -EINVAL; 90 return 0;
90} 91}
91 92
92static int coh901331_set_mmss(struct device *dev, unsigned long secs) 93static int coh901331_set_time(struct device *dev, struct rtc_time *tm)
93{ 94{
94 struct coh901331_port *rtap = dev_get_drvdata(dev); 95 struct coh901331_port *rtap = dev_get_drvdata(dev);
95 96
96 clk_enable(rtap->clk); 97 clk_enable(rtap->clk);
97 writel(secs, rtap->virtbase + COH901331_SET_TIME); 98 writel(rtc_tm_to_time64(tm), rtap->virtbase + COH901331_SET_TIME);
98 clk_disable(rtap->clk); 99 clk_disable(rtap->clk);
99 100
100 return 0; 101 return 0;
@@ -105,7 +106,7 @@ static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
105 struct coh901331_port *rtap = dev_get_drvdata(dev); 106 struct coh901331_port *rtap = dev_get_drvdata(dev);
106 107
107 clk_enable(rtap->clk); 108 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);
109 alarm->pending = readl(rtap->virtbase + COH901331_IRQ_EVENT) & 1U; 110 alarm->pending = readl(rtap->virtbase + COH901331_IRQ_EVENT) & 1U;
110 alarm->enabled = readl(rtap->virtbase + COH901331_IRQ_MASK) & 1U; 111 alarm->enabled = readl(rtap->virtbase + COH901331_IRQ_MASK) & 1U;
111 clk_disable(rtap->clk); 112 clk_disable(rtap->clk);
@@ -116,9 +117,8 @@ static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
116static int coh901331_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 117static int coh901331_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
117{ 118{
118 struct coh901331_port *rtap = dev_get_drvdata(dev); 119 struct coh901331_port *rtap = dev_get_drvdata(dev);
119 unsigned long time; 120 unsigned long time = rtc_tm_to_time64(&alarm->time);
120 121
121 rtc_tm_to_time(&alarm->time, &time);
122 clk_enable(rtap->clk); 122 clk_enable(rtap->clk);
123 writel(time, rtap->virtbase + COH901331_ALARM); 123 writel(time, rtap->virtbase + COH901331_ALARM);
124 writel(alarm->enabled, rtap->virtbase + COH901331_IRQ_MASK); 124 writel(alarm->enabled, rtap->virtbase + COH901331_IRQ_MASK);
@@ -143,7 +143,7 @@ static int coh901331_alarm_irq_enable(struct device *dev, unsigned int enabled)
143 143
144static const struct rtc_class_ops coh901331_ops = { 144static const struct rtc_class_ops coh901331_ops = {
145 .read_time = coh901331_read_time, 145 .read_time = coh901331_read_time,
146 .set_mmss = coh901331_set_mmss, 146 .set_time = coh901331_set_time,
147 .read_alarm = coh901331_read_alarm, 147 .read_alarm = coh901331_read_alarm,
148 .set_alarm = coh901331_set_alarm, 148 .set_alarm = coh901331_set_alarm,
149 .alarm_irq_enable = coh901331_alarm_irq_enable, 149 .alarm_irq_enable = coh901331_alarm_irq_enable,
@@ -188,6 +188,13 @@ static int __init coh901331_probe(struct platform_device *pdev)
188 return ret; 188 return ret;
189 } 189 }
190 190
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
191 /* We enable/disable the clock only to assure it works */ 198 /* We enable/disable the clock only to assure it works */
192 ret = clk_prepare_enable(rtap->clk); 199 ret = clk_prepare_enable(rtap->clk);
193 if (ret) { 200 if (ret) {
@@ -197,12 +204,10 @@ static int __init coh901331_probe(struct platform_device *pdev)
197 clk_disable(rtap->clk); 204 clk_disable(rtap->clk);
198 205
199 platform_set_drvdata(pdev, rtap); 206 platform_set_drvdata(pdev, rtap);
200 rtap->rtc = devm_rtc_device_register(&pdev->dev, "coh901331", 207
201 &coh901331_ops, THIS_MODULE); 208 ret = rtc_register_device(rtap->rtc);
202 if (IS_ERR(rtap->rtc)) { 209 if (ret)
203 ret = PTR_ERR(rtap->rtc);
204 goto out_no_rtc; 210 goto out_no_rtc;
205 }
206 211
207 return 0; 212 return 0;
208 213
diff --git a/drivers/rtc/rtc-da9063.c b/drivers/rtc/rtc-da9063.c
index 69b54e5556c0..15908d51b1cb 100644
--- a/drivers/rtc/rtc-da9063.c
+++ b/drivers/rtc/rtc-da9063.c
@@ -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
2 * Copyright (C) 2013-2015 Dialog Semiconductor Ltd. 4 * 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.
13 */ 5 */
14 6
15#include <linux/delay.h> 7#include <linux/delay.h>
@@ -247,8 +239,8 @@ static int da9063_rtc_read_time(struct device *dev, struct rtc_time *tm)
247 239
248 da9063_data_to_tm(data, tm, rtc); 240 da9063_data_to_tm(data, tm, rtc);
249 241
250 rtc_tm_to_time(tm, &tm_secs); 242 tm_secs = rtc_tm_to_time64(tm);
251 rtc_tm_to_time(&rtc->alarm_time, &al_secs); 243 al_secs = rtc_tm_to_time64(&rtc->alarm_time);
252 244
253 /* handle the rtc synchronisation delay */ 245 /* handle the rtc synchronisation delay */
254 if (rtc->rtc_sync == true && al_secs - tm_secs == 1) 246 if (rtc->rtc_sync == true && al_secs - tm_secs == 1)
@@ -472,11 +464,14 @@ static int da9063_rtc_probe(struct platform_device *pdev)
472 464
473 platform_set_drvdata(pdev, rtc); 465 platform_set_drvdata(pdev, rtc);
474 466
475 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, DA9063_DRVNAME_RTC, 467 rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
476 &da9063_rtc_ops, THIS_MODULE);
477 if (IS_ERR(rtc->rtc_dev)) 468 if (IS_ERR(rtc->rtc_dev))
478 return PTR_ERR(rtc->rtc_dev); 469 return PTR_ERR(rtc->rtc_dev);
479 470
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
480 da9063_data_to_tm(data, &rtc->alarm_time, rtc); 475 da9063_data_to_tm(data, &rtc->alarm_time, rtc);
481 rtc->rtc_sync = false; 476 rtc->rtc_sync = false;
482 477
@@ -496,7 +491,7 @@ static int da9063_rtc_probe(struct platform_device *pdev)
496 dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n", 491 dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n",
497 irq_alarm, ret); 492 irq_alarm, ret);
498 493
499 return ret; 494 return rtc_register_device(rtc->rtc_dev);
500} 495}
501 496
502static struct platform_driver da9063_rtc_driver = { 497static struct platform_driver da9063_rtc_driver = {
diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c
index b253bf1b3531..0aecc3f8e721 100644
--- a/drivers/rtc/rtc-digicolor.c
+++ b/drivers/rtc/rtc-digicolor.c
@@ -1,14 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Real Time Clock driver for Conexant Digicolor 3 * Real Time Clock driver for Conexant Digicolor
3 * 4 *
4 * Copyright (C) 2015 Paradox Innovation Ltd. 5 * Copyright (C) 2015 Paradox Innovation Ltd.
5 * 6 *
6 * Author: Baruch Siach <baruch@tkos.co.il> 7 * 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.
12 */ 8 */
13 9
14#include <linux/io.h> 10#include <linux/io.h>
@@ -106,11 +102,11 @@ static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm)
106 return 0; 102 return 0;
107} 103}
108 104
109static int dc_rtc_set_mmss(struct device *dev, unsigned long secs) 105static int dc_rtc_set_time(struct device *dev, struct rtc_time *tm)
110{ 106{
111 struct dc_rtc *rtc = dev_get_drvdata(dev); 107 struct dc_rtc *rtc = dev_get_drvdata(dev);
112 108
113 return dc_rtc_write(rtc, secs); 109 return dc_rtc_write(rtc, rtc_tm_to_time64(tm));
114} 110}
115 111
116static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 112static 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)
161 157
162static const struct rtc_class_ops dc_rtc_ops = { 158static const struct rtc_class_ops dc_rtc_ops = {
163 .read_time = dc_rtc_read_time, 159 .read_time = dc_rtc_read_time,
164 .set_mmss = dc_rtc_set_mmss, 160 .set_time = dc_rtc_set_time,
165 .read_alarm = dc_rtc_read_alarm, 161 .read_alarm = dc_rtc_read_alarm,
166 .set_alarm = dc_rtc_set_alarm, 162 .set_alarm = dc_rtc_set_alarm,
167 .alarm_irq_enable = dc_rtc_alarm_irq_enable, 163 .alarm_irq_enable = dc_rtc_alarm_irq_enable,
@@ -192,6 +188,10 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
192 if (IS_ERR(rtc->regs)) 188 if (IS_ERR(rtc->regs))
193 return PTR_ERR(rtc->regs); 189 return PTR_ERR(rtc->regs);
194 190
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
195 irq = platform_get_irq(pdev, 0); 195 irq = platform_get_irq(pdev, 0);
196 if (irq < 0) 196 if (irq < 0)
197 return irq; 197 return irq;
@@ -200,12 +200,11 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
200 return ret; 200 return ret;
201 201
202 platform_set_drvdata(pdev, rtc); 202 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);
207 203
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);
209} 208}
210 209
211static const struct of_device_id dc_dt_ids[] = { 210static const struct of_device_id dc_dt_ids[] = {
diff --git a/drivers/rtc/rtc-dm355evm.c b/drivers/rtc/rtc-dm355evm.c
index 97d8259b9494..cd947a20843b 100644
--- a/drivers/rtc/rtc-dm355evm.c
+++ b/drivers/rtc/rtc-dm355evm.c
@@ -1,12 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * rtc-dm355evm.c - access battery-backed counter in MSP430 firmware 3 * rtc-dm355evm.c - access battery-backed counter in MSP430 firmware
3 * 4 *
4 * Copyright (c) 2008 by David Brownell 5 * 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.
10 */ 6 */
11#include <linux/kernel.h> 7#include <linux/kernel.h>
12#include <linux/init.h> 8#include <linux/init.h>
@@ -78,7 +74,7 @@ static int dm355evm_rtc_read_time(struct device *dev, struct rtc_time *tm)
78 74
79 dev_dbg(dev, "read timestamp %08x\n", time.value); 75 dev_dbg(dev, "read timestamp %08x\n", time.value);
80 76
81 rtc_time_to_tm(le32_to_cpu(time.value), tm); 77 rtc_time64_to_tm(le32_to_cpu(time.value), tm);
82 return 0; 78 return 0;
83} 79}
84 80
@@ -88,7 +84,7 @@ static int dm355evm_rtc_set_time(struct device *dev, struct rtc_time *tm)
88 unsigned long value; 84 unsigned long value;
89 int status; 85 int status;
90 86
91 rtc_tm_to_time(tm, &value); 87 value = rtc_tm_to_time64(tm);
92 time.value = cpu_to_le32(value); 88 time.value = cpu_to_le32(value);
93 89
94 dev_dbg(dev, "write timestamp %08x\n", time.value); 90 dev_dbg(dev, "write timestamp %08x\n", time.value);
@@ -127,16 +123,16 @@ static int dm355evm_rtc_probe(struct platform_device *pdev)
127{ 123{
128 struct rtc_device *rtc; 124 struct rtc_device *rtc;
129 125
130 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 126 rtc = devm_rtc_allocate_device(&pdev->dev);
131 &dm355evm_rtc_ops, THIS_MODULE); 127 if (IS_ERR(rtc))
132 if (IS_ERR(rtc)) {
133 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
134 PTR_ERR(rtc));
135 return PTR_ERR(rtc); 128 return PTR_ERR(rtc);
136 } 129
137 platform_set_drvdata(pdev, rtc); 130 platform_set_drvdata(pdev, rtc);
138 131
139 return 0; 132 rtc->ops = &dm355evm_rtc_ops;
133 rtc->range_max = U32_MAX;
134
135 return rtc_register_device(rtc);
140} 136}
141 137
142/* 138/*
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index b1ebca099b0d..e9e8d02743ee 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * An rtc/i2c driver for the Dallas DS1672 3 * An rtc/i2c driver for the Dallas DS1672
3 * Copyright 2005-06 Tower Technologies 4 * Copyright 2005-06 Tower Technologies
4 * 5 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * 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 */
11 8
12#include <linux/i2c.h> 9#include <linux/i2c.h>
@@ -21,17 +18,16 @@
21 18
22#define DS1672_REG_CONTROL_EOSC 0x80 19#define DS1672_REG_CONTROL_EOSC 0x80
23 20
24static struct i2c_driver ds1672_driver;
25
26/* 21/*
27 * In the routines that deal directly with the ds1672 hardware, we use 22 * In the routines that deal directly with the ds1672 hardware, we use
28 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch 23 * 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.
30 */ 25 */
31static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm) 26static int ds1672_read_time(struct device *dev, struct rtc_time *tm)
32{ 27{
28 struct i2c_client *client = to_i2c_client(dev);
33 unsigned long time; 29 unsigned long time;
34 unsigned char addr = DS1672_REG_CNT_BASE; 30 unsigned char addr = DS1672_REG_CONTROL;
35 unsigned char buf[4]; 31 unsigned char buf[4];
36 32
37 struct i2c_msg msgs[] = { 33 struct i2c_msg msgs[] = {
@@ -43,11 +39,25 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
43 {/* read date */ 39 {/* read date */
44 .addr = client->addr, 40 .addr = client->addr,
45 .flags = I2C_M_RD, 41 .flags = I2C_M_RD,
46 .len = 4, 42 .len = 1,
47 .buf = buf 43 .buf = buf
48 }, 44 },
49 }; 45 };
50 46
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
51 /* read date registers */ 61 /* read date registers */
52 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { 62 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
53 dev_err(&client->dev, "%s: read error\n", __func__); 63 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)
61 time = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | 71 time = ((unsigned long)buf[3] << 24) | (buf[2] << 16) |
62 (buf[1] << 8) | buf[0]; 72 (buf[1] << 8) | buf[0];
63 73
64 rtc_time_to_tm(time, tm); 74 rtc_time64_to_tm(time, tm);
65 75
66 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 76 dev_dbg(&client->dev, "%s: tm is %ptR\n", __func__, tm);
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);
70 77
71 return 0; 78 return 0;
72} 79}
73 80
74static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs) 81static int ds1672_set_time(struct device *dev, struct rtc_time *tm)
75{ 82{
83 struct i2c_client *client = to_i2c_client(dev);
76 int xfer; 84 int xfer;
77 unsigned char buf[6]; 85 unsigned char buf[6];
86 unsigned long secs = rtc_tm_to_time64(tm);
78 87
79 buf[0] = DS1672_REG_CNT_BASE; 88 buf[0] = DS1672_REG_CNT_BASE;
80 buf[1] = secs & 0x000000FF; 89 buf[1] = secs & 0x000000FF;
@@ -92,71 +101,15 @@ static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
92 return 0; 101 return 0;
93} 102}
94 103
95static 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
100static int ds1672_rtc_set_mmss(struct device *dev, unsigned long secs)
101{
102 return ds1672_set_mmss(to_i2c_client(dev), secs);
103}
104
105static 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 */
133static 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
148static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
149
150static const struct rtc_class_ops ds1672_rtc_ops = { 104static const struct rtc_class_ops ds1672_rtc_ops = {
151 .read_time = ds1672_rtc_read_time, 105 .read_time = ds1672_read_time,
152 .set_mmss = ds1672_rtc_set_mmss, 106 .set_time = ds1672_set_time,
153}; 107};
154 108
155static int ds1672_probe(struct i2c_client *client, 109static int ds1672_probe(struct i2c_client *client,
156 const struct i2c_device_id *id) 110 const struct i2c_device_id *id)
157{ 111{
158 int err = 0; 112 int err = 0;
159 u8 control;
160 struct rtc_device *rtc; 113 struct rtc_device *rtc;
161 114
162 dev_dbg(&client->dev, "%s\n", __func__); 115 dev_dbg(&client->dev, "%s\n", __func__);
@@ -164,29 +117,21 @@ static int ds1672_probe(struct i2c_client *client,
164 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 117 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
165 return -ENODEV; 118 return -ENODEV;
166 119
167 rtc = devm_rtc_device_register(&client->dev, ds1672_driver.driver.name, 120 rtc = devm_rtc_allocate_device(&client->dev);
168 &ds1672_rtc_ops, THIS_MODULE);
169
170 if (IS_ERR(rtc)) 121 if (IS_ERR(rtc))
171 return PTR_ERR(rtc); 122 return PTR_ERR(rtc);
172 123
173 i2c_set_clientdata(client, rtc); 124 rtc->ops = &ds1672_rtc_ops;
125 rtc->range_max = U32_MAX;
174 126
175 /* read control register */ 127 err = rtc_register_device(rtc);
176 err = ds1672_get_control(client, &control); 128 if (err)
177 if (err) { 129 return err;
178 dev_warn(&client->dev, "Unable to read the control register\n");
179 }
180 130
181 if (control & DS1672_REG_CONTROL_EOSC) 131 if (IS_ERR(rtc))
182 dev_warn(&client->dev, "Oscillator not enabled. " 132 return PTR_ERR(rtc);
183 "Set time to enable.\n");
184 133
185 /* Register sysfs hooks */ 134 i2c_set_clientdata(client, rtc);
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);
190 135
191 return 0; 136 return 0;
192} 137}
diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index 2710f2594c42..5f4328524183 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -192,42 +192,6 @@ ds1685_rtc_end_data_access(struct ds1685_priv *rtc)
192} 192}
193 193
194/** 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 */
207static inline void
208ds1685_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 */
223static inline void
224ds1685_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
230/**
231 * ds1685_rtc_get_ssn - retrieve the silicon serial number. 195 * ds1685_rtc_get_ssn - retrieve the silicon serial number.
232 * @rtc: pointer to the ds1685 rtc structure. 196 * @rtc: pointer to the ds1685 rtc structure.
233 * @ssn: u8 array to hold the bits of the silicon serial number. 197 * @ssn: u8 array to hold the bits of the silicon serial number.
@@ -546,10 +510,6 @@ static int
546ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 510ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
547{ 511{
548 struct ds1685_priv *rtc = dev_get_drvdata(dev); 512 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);
553 513
554 /* Flip the requisite interrupt-enable bit. */ 514 /* Flip the requisite interrupt-enable bit. */
555 if (enabled) 515 if (enabled)
@@ -561,7 +521,6 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
561 521
562 /* Read Control C to clear all the flag bits. */ 522 /* Read Control C to clear all the flag bits. */
563 rtc->read(rtc, RTC_CTRL_C); 523 rtc->read(rtc, RTC_CTRL_C);
564 spin_unlock_irqrestore(&rtc->lock, flags);
565 524
566 return 0; 525 return 0;
567} 526}
@@ -569,98 +528,18 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
569 528
570 529
571/* ----------------------------------------------------------------------- */ 530/* ----------------------------------------------------------------------- */
572/* IRQ handler & workqueue. */ 531/* IRQ handler */
573
574/**
575 * ds1685_rtc_irq_handler - IRQ handler.
576 * @irq: IRQ number.
577 * @dev_id: platform device pointer.
578 */
579static irqreturn_t
580ds1685_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}
648 532
649/** 533/**
650 * ds1685_rtc_work_queue - work queue handler. 534 * ds1685_rtc_extended_irq - take care of extended interrupts
651 * @work: work_struct containing data to work on in task context. 535 * @rtc: pointer to the ds1685 rtc structure.
536 * @pdev: platform device pointer.
652 */ 537 */
653static void 538static void
654ds1685_rtc_work_queue(struct work_struct *work) 539ds1685_rtc_extended_irq(struct ds1685_priv *rtc, struct platform_device *pdev)
655{ 540{
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;
660 u8 ctrl4a, ctrl4b; 541 u8 ctrl4a, ctrl4b;
661 542
662 mutex_lock(rtc_mutex);
663
664 ds1685_rtc_switch_to_bank1(rtc); 543 ds1685_rtc_switch_to_bank1(rtc);
665 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A); 544 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A);
666 ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B); 545 ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B);
@@ -739,8 +618,76 @@ ds1685_rtc_work_queue(struct work_struct *work)
739 "RAM-Clear IRQ just occurred!\n"); 618 "RAM-Clear IRQ just occurred!\n");
740 } 619 }
741 ds1685_rtc_switch_to_bank0(rtc); 620 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 */
628static irqreturn_t
629ds1685_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);
742 644
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);
743 mutex_unlock(rtc_mutex); 688 mutex_unlock(rtc_mutex);
689
690 return events ? IRQ_HANDLED : IRQ_NONE;
744} 691}
745/* ----------------------------------------------------------------------- */ 692/* ----------------------------------------------------------------------- */
746 693
@@ -869,11 +816,15 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val,
869 size_t size) 816 size_t size)
870{ 817{
871 struct ds1685_priv *rtc = priv; 818 struct ds1685_priv *rtc = priv;
819 struct mutex *rtc_mutex = &rtc->dev->ops_lock;
872 ssize_t count; 820 ssize_t count;
873 unsigned long flags = 0;
874 u8 *buf = val; 821 u8 *buf = val;
822 int err;
823
824 err = mutex_lock_interruptible(rtc_mutex);
825 if (err)
826 return err;
875 827
876 spin_lock_irqsave(&rtc->lock, flags);
877 ds1685_rtc_switch_to_bank0(rtc); 828 ds1685_rtc_switch_to_bank0(rtc);
878 829
879 /* Read NVRAM in time and bank0 registers. */ 830 /* Read NVRAM in time and bank0 registers. */
@@ -923,7 +874,7 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val,
923 ds1685_rtc_switch_to_bank0(rtc); 874 ds1685_rtc_switch_to_bank0(rtc);
924 } 875 }
925#endif /* !CONFIG_RTC_DRV_DS1689 */ 876#endif /* !CONFIG_RTC_DRV_DS1689 */
926 spin_unlock_irqrestore(&rtc->lock, flags); 877 mutex_unlock(rtc_mutex);
927 878
928 return 0; 879 return 0;
929} 880}
@@ -932,11 +883,15 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val,
932 size_t size) 883 size_t size)
933{ 884{
934 struct ds1685_priv *rtc = priv; 885 struct ds1685_priv *rtc = priv;
886 struct mutex *rtc_mutex = &rtc->dev->ops_lock;
935 ssize_t count; 887 ssize_t count;
936 unsigned long flags = 0;
937 u8 *buf = val; 888 u8 *buf = val;
889 int err;
890
891 err = mutex_lock_interruptible(rtc_mutex);
892 if (err)
893 return err;
938 894
939 spin_lock_irqsave(&rtc->lock, flags);
940 ds1685_rtc_switch_to_bank0(rtc); 895 ds1685_rtc_switch_to_bank0(rtc);
941 896
942 /* Write NVRAM in time and bank0 registers. */ 897 /* Write NVRAM in time and bank0 registers. */
@@ -986,7 +941,7 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val,
986 ds1685_rtc_switch_to_bank0(rtc); 941 ds1685_rtc_switch_to_bank0(rtc);
987 } 942 }
988#endif /* !CONFIG_RTC_DRV_DS1689 */ 943#endif /* !CONFIG_RTC_DRV_DS1689 */
989 spin_unlock_irqrestore(&rtc->lock, flags); 944 mutex_unlock(rtc_mutex);
990 945
991 return 0; 946 return 0;
992} 947}
@@ -1004,7 +959,7 @@ static ssize_t
1004ds1685_rtc_sysfs_battery_show(struct device *dev, 959ds1685_rtc_sysfs_battery_show(struct device *dev,
1005 struct device_attribute *attr, char *buf) 960 struct device_attribute *attr, char *buf)
1006{ 961{
1007 struct ds1685_priv *rtc = dev_get_drvdata(dev); 962 struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
1008 u8 ctrld; 963 u8 ctrld;
1009 964
1010 ctrld = rtc->read(rtc, RTC_CTRL_D); 965 ctrld = rtc->read(rtc, RTC_CTRL_D);
@@ -1024,7 +979,7 @@ static ssize_t
1024ds1685_rtc_sysfs_auxbatt_show(struct device *dev, 979ds1685_rtc_sysfs_auxbatt_show(struct device *dev,
1025 struct device_attribute *attr, char *buf) 980 struct device_attribute *attr, char *buf)
1026{ 981{
1027 struct ds1685_priv *rtc = dev_get_drvdata(dev); 982 struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
1028 u8 ctrl4a; 983 u8 ctrl4a;
1029 984
1030 ds1685_rtc_switch_to_bank1(rtc); 985 ds1685_rtc_switch_to_bank1(rtc);
@@ -1046,7 +1001,7 @@ static ssize_t
1046ds1685_rtc_sysfs_serial_show(struct device *dev, 1001ds1685_rtc_sysfs_serial_show(struct device *dev,
1047 struct device_attribute *attr, char *buf) 1002 struct device_attribute *attr, char *buf)
1048{ 1003{
1049 struct ds1685_priv *rtc = dev_get_drvdata(dev); 1004 struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
1050 u8 ssn[8]; 1005 u8 ssn[8];
1051 1006
1052 ds1685_rtc_switch_to_bank1(rtc); 1007 ds1685_rtc_switch_to_bank1(rtc);
@@ -1177,9 +1132,7 @@ ds1685_rtc_probe(struct platform_device *pdev)
1177 if (pdata->plat_post_ram_clear) 1132 if (pdata->plat_post_ram_clear)
1178 rtc->post_ram_clear = pdata->plat_post_ram_clear; 1133 rtc->post_ram_clear = pdata->plat_post_ram_clear;
1179 1134
1180 /* Init the spinlock, workqueue, & set the driver data. */ 1135 /* set the driver data. */
1181 spin_lock_init(&rtc->lock);
1182 INIT_WORK(&rtc->work, ds1685_rtc_work_queue);
1183 platform_set_drvdata(pdev, rtc); 1136 platform_set_drvdata(pdev, rtc);
1184 1137
1185 /* Turn the oscillator on if is not already on (DV1 = 1). */ 1138 /* Turn the oscillator on if is not already on (DV1 = 1). */
@@ -1335,22 +1288,23 @@ ds1685_rtc_probe(struct platform_device *pdev)
1335 */ 1288 */
1336 if (!pdata->no_irq) { 1289 if (!pdata->no_irq) {
1337 ret = platform_get_irq(pdev, 0); 1290 ret = platform_get_irq(pdev, 0);
1338 if (ret > 0) { 1291 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
1353 return ret; 1292 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 }
1354 } 1308 }
1355 rtc->no_irq = pdata->no_irq; 1309 rtc->no_irq = pdata->no_irq;
1356 1310
@@ -1397,8 +1351,6 @@ ds1685_rtc_remove(struct platform_device *pdev)
1397 (rtc->read(rtc, RTC_EXT_CTRL_4A) & 1351 (rtc->read(rtc, RTC_EXT_CTRL_4A) &
1398 ~(RTC_CTRL_4A_RWK_MASK))); 1352 ~(RTC_CTRL_4A_RWK_MASK)));
1399 1353
1400 cancel_work_sync(&rtc->work);
1401
1402 return 0; 1354 return 0;
1403} 1355}
1404 1356
diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index b886b6a5c178..1e9f429ada64 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -1,11 +1,5 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (C) 2012 Sven Schnelle <svens@stackframe.org> 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 */
9 3
10#include <linux/platform_device.h> 4#include <linux/platform_device.h>
11#include <linux/module.h> 5#include <linux/module.h>
@@ -29,14 +23,6 @@
29#define DS2404_COPY_SCRATCHPAD_CMD 0x55 23#define DS2404_COPY_SCRATCHPAD_CMD 0x55
30#define DS2404_READ_MEMORY_CMD 0xf0 24#define DS2404_READ_MEMORY_CMD 0xf0
31 25
32struct ds2404;
33
34struct 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
40#define DS2404_RST 0 26#define DS2404_RST 0
41#define DS2404_CLK 1 27#define DS2404_CLK 1
42#define DS2404_DQ 2 28#define DS2404_DQ 2
@@ -48,7 +34,6 @@ struct ds2404_gpio {
48 34
49struct ds2404 { 35struct ds2404 {
50 struct ds2404_gpio *gpio; 36 struct ds2404_gpio *gpio;
51 const struct ds2404_chip_ops *ops;
52 struct rtc_device *rtc; 37 struct rtc_device *rtc;
53}; 38};
54 39
@@ -87,7 +72,7 @@ err_request:
87 return err; 72 return err;
88} 73}
89 74
90static void ds2404_gpio_unmap(struct ds2404 *chip) 75static void ds2404_gpio_unmap(void *data)
91{ 76{
92 int i; 77 int i;
93 78
@@ -95,11 +80,6 @@ static void ds2404_gpio_unmap(struct ds2404 *chip)
95 gpio_free(ds2404_gpio[i].gpio); 80 gpio_free(ds2404_gpio[i].gpio);
96} 81}
97 82
98static const struct ds2404_chip_ops ds2404_gpio_ops = {
99 .map_io = ds2404_gpio_map,
100 .unmap_io = ds2404_gpio_unmap,
101};
102
103static void ds2404_reset(struct device *dev) 83static void ds2404_reset(struct device *dev)
104{ 84{
105 gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 0); 85 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)
206 ds2404_read_memory(dev, 0x203, 4, (u8 *)&time); 186 ds2404_read_memory(dev, 0x203, 4, (u8 *)&time);
207 time = le32_to_cpu(time); 187 time = le32_to_cpu(time);
208 188
209 rtc_time_to_tm(time, dt); 189 rtc_time64_to_tm(time, dt);
210 return 0; 190 return 0;
211} 191}
212 192
213static int ds2404_set_mmss(struct device *dev, unsigned long secs) 193static int ds2404_set_time(struct device *dev, struct rtc_time *dt)
214{ 194{
215 u32 time = cpu_to_le32(secs); 195 u32 time = cpu_to_le32(rtc_tm_to_time64(dt));
216 ds2404_write_memory(dev, 0x203, 4, (u8 *)&time); 196 ds2404_write_memory(dev, 0x203, 4, (u8 *)&time);
217 return 0; 197 return 0;
218} 198}
219 199
220static const struct rtc_class_ops ds2404_rtc_ops = { 200static const struct rtc_class_ops ds2404_rtc_ops = {
221 .read_time = ds2404_read_time, 201 .read_time = ds2404_read_time,
222 .set_mmss = ds2404_set_mmss, 202 .set_time = ds2404_set_time,
223}; 203};
224 204
225static int rtc_probe(struct platform_device *pdev) 205static int rtc_probe(struct platform_device *pdev)
@@ -232,11 +212,17 @@ static int rtc_probe(struct platform_device *pdev)
232 if (!chip) 212 if (!chip)
233 return -ENOMEM; 213 return -ENOMEM;
234 214
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);
236 218
237 retval = chip->ops->map_io(chip, pdev, pdata); 219 retval = ds2404_gpio_map(chip, pdev, pdata);
238 if (retval) 220 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;
240 226
241 dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n", 227 dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n",
242 chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio, 228 chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio,
@@ -244,34 +230,19 @@ static int rtc_probe(struct platform_device *pdev)
244 230
245 platform_set_drvdata(pdev, chip); 231 platform_set_drvdata(pdev, chip);
246 232
247 chip->rtc = devm_rtc_device_register(&pdev->dev, "ds2404", 233 chip->rtc->ops = &ds2404_rtc_ops;
248 &ds2404_rtc_ops, THIS_MODULE); 234 chip->rtc->range_max = U32_MAX;
249 if (IS_ERR(chip->rtc)) {
250 retval = PTR_ERR(chip->rtc);
251 goto err_io;
252 }
253 235
254 ds2404_enable_osc(&pdev->dev); 236 retval = rtc_register_device(chip->rtc);
255 return 0; 237 if (retval)
256 238 return retval;
257err_io:
258 chip->ops->unmap_io(chip);
259err_chip:
260 return retval;
261}
262
263static int rtc_remove(struct platform_device *dev)
264{
265 struct ds2404 *chip = platform_get_drvdata(dev);
266
267 chip->ops->unmap_io(chip);
268 239
240 ds2404_enable_osc(&pdev->dev);
269 return 0; 241 return 0;
270} 242}
271 243
272static struct platform_driver rtc_device_driver = { 244static struct platform_driver rtc_device_driver = {
273 .probe = rtc_probe, 245 .probe = rtc_probe,
274 .remove = rtc_remove,
275 .driver = { 246 .driver = {
276 .name = "ds2404", 247 .name = "ds2404",
277 }, 248 },
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index 7184e5145f12..1e9312f96021 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -48,6 +48,10 @@
48# define DS3232_REG_SR_A1F 0x01 48# define DS3232_REG_SR_A1F 0x01
49 49
50#define DS3232_REG_TEMPERATURE 0x11 50#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
51 55
52struct ds3232 { 56struct ds3232 {
53 struct device *dev; 57 struct device *dev;
@@ -461,11 +465,39 @@ static const struct rtc_class_ops ds3232_rtc_ops = {
461 .alarm_irq_enable = ds3232_alarm_irq_enable, 465 .alarm_irq_enable = ds3232_alarm_irq_enable,
462}; 466};
463 467
468static 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
477static 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
464static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, 486static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
465 const char *name) 487 const char *name)
466{ 488{
467 struct ds3232 *ds3232; 489 struct ds3232 *ds3232;
468 int ret; 490 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 };
469 501
470 ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL); 502 ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL);
471 if (!ds3232) 503 if (!ds3232)
@@ -490,6 +522,10 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
490 if (IS_ERR(ds3232->rtc)) 522 if (IS_ERR(ds3232->rtc))
491 return PTR_ERR(ds3232->rtc); 523 return PTR_ERR(ds3232->rtc);
492 524
525 ret = rtc_nvmem_register(ds3232->rtc, &nvmem_cfg);
526 if(ret)
527 return ret;
528
493 if (ds3232->irq > 0) { 529 if (ds3232->irq > 0) {
494 ret = devm_request_threaded_irq(dev, ds3232->irq, NULL, 530 ret = devm_request_threaded_irq(dev, ds3232->irq, NULL,
495 ds3232_irq, 531 ds3232_irq,
@@ -542,7 +578,7 @@ static int ds3232_i2c_probe(struct i2c_client *client,
542 static const struct regmap_config config = { 578 static const struct regmap_config config = {
543 .reg_bits = 8, 579 .reg_bits = 8,
544 .val_bits = 8, 580 .val_bits = 8,
545 .max_register = 0x13, 581 .max_register = DS3232_REG_SRAM_END,
546 }; 582 };
547 583
548 regmap = devm_regmap_init_i2c(client, &config); 584 regmap = devm_regmap_init_i2c(client, &config);
@@ -609,7 +645,7 @@ static int ds3234_probe(struct spi_device *spi)
609 static const struct regmap_config config = { 645 static const struct regmap_config config = {
610 .reg_bits = 8, 646 .reg_bits = 8,
611 .val_bits = 8, 647 .val_bits = 8,
612 .max_register = 0x13, 648 .max_register = DS3232_REG_SRAM_END,
613 .write_flag_mask = 0x80, 649 .write_flag_mask = 0x80,
614 }; 650 };
615 struct regmap *regmap; 651 struct regmap *regmap;
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 1932a4f861d1..1766496385fe 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * A driver for the RTC embedded in the Cirrus Logic EP93XX processors 3 * A driver for the RTC embedded in the Cirrus Logic EP93XX processors
3 * Copyright (c) 2006 Tower Technologies 4 * Copyright (c) 2006 Tower Technologies
4 * 5 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * 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 */
11 8
12#include <linux/module.h> 9#include <linux/module.h>
@@ -18,27 +15,23 @@
18#define EP93XX_RTC_DATA 0x000 15#define EP93XX_RTC_DATA 0x000
19#define EP93XX_RTC_MATCH 0x004 16#define EP93XX_RTC_MATCH 0x004
20#define EP93XX_RTC_STATUS 0x008 17#define EP93XX_RTC_STATUS 0x008
21#define EP93XX_RTC_STATUS_INTR (1<<0) 18#define EP93XX_RTC_STATUS_INTR BIT(0)
22#define EP93XX_RTC_LOAD 0x00C 19#define EP93XX_RTC_LOAD 0x00C
23#define EP93XX_RTC_CONTROL 0x010 20#define EP93XX_RTC_CONTROL 0x010
24#define EP93XX_RTC_CONTROL_MIE (1<<0) 21#define EP93XX_RTC_CONTROL_MIE BIT(0)
25#define EP93XX_RTC_SWCOMP 0x108 22#define EP93XX_RTC_SWCOMP 0x108
26#define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000 23#define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000
27#define EP93XX_RTC_SWCOMP_DEL_SHIFT 16 24#define EP93XX_RTC_SWCOMP_DEL_SHIFT 16
28#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff 25#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
29#define EP93XX_RTC_SWCOMP_INT_SHIFT 0 26#define EP93XX_RTC_SWCOMP_INT_SHIFT 0
30 27
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 */
35struct ep93xx_rtc { 28struct ep93xx_rtc {
36 void __iomem *mmio_base; 29 void __iomem *mmio_base;
37 struct rtc_device *rtc; 30 struct rtc_device *rtc;
38}; 31};
39 32
40static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload, 33static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
41 unsigned short *delete) 34 unsigned short *delete)
42{ 35{
43 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev); 36 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
44 unsigned long comp; 37 unsigned long comp;
@@ -63,13 +56,14 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
63 56
64 time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA); 57 time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
65 58
66 rtc_time_to_tm(time, tm); 59 rtc_time64_to_tm(time, tm);
67 return 0; 60 return 0;
68} 61}
69 62
70static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs) 63static int ep93xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
71{ 64{
72 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev); 65 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
66 unsigned long secs = rtc_tm_to_time64(tm);
73 67
74 writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD); 68 writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
75 return 0; 69 return 0;
@@ -89,31 +83,31 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
89 83
90static const struct rtc_class_ops ep93xx_rtc_ops = { 84static const struct rtc_class_ops ep93xx_rtc_ops = {
91 .read_time = ep93xx_rtc_read_time, 85 .read_time = ep93xx_rtc_read_time,
92 .set_mmss = ep93xx_rtc_set_mmss, 86 .set_time = ep93xx_rtc_set_time,
93 .proc = ep93xx_rtc_proc, 87 .proc = ep93xx_rtc_proc,
94}; 88};
95 89
96static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev, 90static ssize_t comp_preload_show(struct device *dev,
97 struct device_attribute *attr, char *buf) 91 struct device_attribute *attr, char *buf)
98{ 92{
99 unsigned short preload; 93 unsigned short preload;
100 94
101 ep93xx_rtc_get_swcomp(dev, &preload, NULL); 95 ep93xx_rtc_get_swcomp(dev->parent, &preload, NULL);
102 96
103 return sprintf(buf, "%d\n", preload); 97 return sprintf(buf, "%d\n", preload);
104} 98}
105static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL); 99static DEVICE_ATTR_RO(comp_preload);
106 100
107static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev, 101static ssize_t comp_delete_show(struct device *dev,
108 struct device_attribute *attr, char *buf) 102 struct device_attribute *attr, char *buf)
109{ 103{
110 unsigned short delete; 104 unsigned short delete;
111 105
112 ep93xx_rtc_get_swcomp(dev, NULL, &delete); 106 ep93xx_rtc_get_swcomp(dev->parent, NULL, &delete);
113 107
114 return sprintf(buf, "%d\n", delete); 108 return sprintf(buf, "%d\n", delete);
115} 109}
116static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL); 110static DEVICE_ATTR_RO(comp_delete);
117 111
118static struct attribute *ep93xx_rtc_attrs[] = { 112static struct attribute *ep93xx_rtc_attrs[] = {
119 &dev_attr_comp_preload.attr, 113 &dev_attr_comp_preload.attr,
@@ -140,33 +134,20 @@ static int ep93xx_rtc_probe(struct platform_device *pdev)
140 if (IS_ERR(ep93xx_rtc->mmio_base)) 134 if (IS_ERR(ep93xx_rtc->mmio_base))
141 return PTR_ERR(ep93xx_rtc->mmio_base); 135 return PTR_ERR(ep93xx_rtc->mmio_base);
142 136
143 pdev->dev.platform_data = ep93xx_rtc;
144 platform_set_drvdata(pdev, ep93xx_rtc); 137 platform_set_drvdata(pdev, ep93xx_rtc);
145 138
146 ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev, 139 ep93xx_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
147 pdev->name, &ep93xx_rtc_ops, THIS_MODULE); 140 if (IS_ERR(ep93xx_rtc->rtc))
148 if (IS_ERR(ep93xx_rtc->rtc)) { 141 return PTR_ERR(ep93xx_rtc->rtc);
149 err = PTR_ERR(ep93xx_rtc->rtc);
150 goto exit;
151 }
152 142
153 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); 143 ep93xx_rtc->rtc->ops = &ep93xx_rtc_ops;
154 if (err) 144 ep93xx_rtc->rtc->range_max = U32_MAX;
155 goto exit;
156
157 return 0;
158 145
159exit: 146 err = rtc_add_group(ep93xx_rtc->rtc, &ep93xx_rtc_sysfs_files);
160 pdev->dev.platform_data = NULL; 147 if (err)
161 return err; 148 return err;
162}
163
164static 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;
168 149
169 return 0; 150 return rtc_register_device(ep93xx_rtc->rtc);
170} 151}
171 152
172static struct platform_driver ep93xx_rtc_driver = { 153static struct platform_driver ep93xx_rtc_driver = {
@@ -174,7 +155,6 @@ static struct platform_driver ep93xx_rtc_driver = {
174 .name = "ep93xx-rtc", 155 .name = "ep93xx-rtc",
175 }, 156 },
176 .probe = ep93xx_rtc_probe, 157 .probe = ep93xx_rtc_probe,
177 .remove = ep93xx_rtc_remove,
178}; 158};
179 159
180module_platform_driver(ep93xx_rtc_driver); 160module_platform_driver(ep93xx_rtc_driver);
diff --git a/drivers/rtc/rtc-goldfish.c b/drivers/rtc/rtc-goldfish.c
index a1c44d0c8557..1a3420ee6a4d 100644
--- a/drivers/rtc/rtc-goldfish.c
+++ b/drivers/rtc/rtc-goldfish.c
@@ -1,23 +1,15 @@
1// SPDX-License-Identifier: GPL-2.0
1/* drivers/rtc/rtc-goldfish.c 2/* drivers/rtc/rtc-goldfish.c
2 * 3 *
3 * Copyright (C) 2007 Google, Inc. 4 * Copyright (C) 2007 Google, Inc.
4 * Copyright (C) 2017 Imagination Technologies Ltd. 5 * 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 *
15 */ 6 */
16 7
8#include <linux/io.h>
17#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/of.h>
18#include <linux/platform_device.h> 11#include <linux/platform_device.h>
19#include <linux/rtc.h> 12#include <linux/rtc.h>
20#include <linux/io.h>
21 13
22#define TIMER_TIME_LOW 0x00 /* get low bits of current time */ 14#define TIMER_TIME_LOW 0x00 /* get low bits of current time */
23 /* and update TIMER_TIME_HIGH */ 15 /* and update TIMER_TIME_HIGH */
@@ -56,7 +48,7 @@ static int goldfish_rtc_read_alarm(struct device *dev,
56 do_div(rtc_alarm, NSEC_PER_SEC); 48 do_div(rtc_alarm, NSEC_PER_SEC);
57 memset(alrm, 0, sizeof(struct rtc_wkalrm)); 49 memset(alrm, 0, sizeof(struct rtc_wkalrm));
58 50
59 rtc_time_to_tm(rtc_alarm, &alrm->time); 51 rtc_time64_to_tm(rtc_alarm, &alrm->time);
60 52
61 if (readl(base + TIMER_ALARM_STATUS)) 53 if (readl(base + TIMER_ALARM_STATUS))
62 alrm->enabled = 1; 54 alrm->enabled = 1;
@@ -70,21 +62,15 @@ static int goldfish_rtc_set_alarm(struct device *dev,
70 struct rtc_wkalrm *alrm) 62 struct rtc_wkalrm *alrm)
71{ 63{
72 struct goldfish_rtc *rtcdrv; 64 struct goldfish_rtc *rtcdrv;
73 unsigned long rtc_alarm;
74 u64 rtc_alarm64; 65 u64 rtc_alarm64;
75 u64 rtc_status_reg; 66 u64 rtc_status_reg;
76 void __iomem *base; 67 void __iomem *base;
77 int ret = 0;
78 68
79 rtcdrv = dev_get_drvdata(dev); 69 rtcdrv = dev_get_drvdata(dev);
80 base = rtcdrv->base; 70 base = rtcdrv->base;
81 71
82 if (alrm->enabled) { 72 if (alrm->enabled) {
83 ret = rtc_tm_to_time(&alrm->time, &rtc_alarm); 73 rtc_alarm64 = rtc_tm_to_time64(&alrm->time) * NSEC_PER_SEC;
84 if (ret != 0)
85 return ret;
86
87 rtc_alarm64 = rtc_alarm * NSEC_PER_SEC;
88 writel((rtc_alarm64 >> 32), base + TIMER_ALARM_HIGH); 74 writel((rtc_alarm64 >> 32), base + TIMER_ALARM_HIGH);
89 writel(rtc_alarm64, base + TIMER_ALARM_LOW); 75 writel(rtc_alarm64, base + TIMER_ALARM_LOW);
90 } else { 76 } else {
@@ -98,7 +84,7 @@ static int goldfish_rtc_set_alarm(struct device *dev,
98 writel(1, base + TIMER_CLEAR_ALARM); 84 writel(1, base + TIMER_CLEAR_ALARM);
99 } 85 }
100 86
101 return ret; 87 return 0;
102} 88}
103 89
104static int goldfish_rtc_alarm_irq_enable(struct device *dev, 90static 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)
147 133
148 do_div(time, NSEC_PER_SEC); 134 do_div(time, NSEC_PER_SEC);
149 135
150 rtc_time_to_tm(time, tm); 136 rtc_time64_to_tm(time, tm);
151 137
152 return 0; 138 return 0;
153} 139}
@@ -156,21 +142,16 @@ static int goldfish_rtc_set_time(struct device *dev, struct rtc_time *tm)
156{ 142{
157 struct goldfish_rtc *rtcdrv; 143 struct goldfish_rtc *rtcdrv;
158 void __iomem *base; 144 void __iomem *base;
159 unsigned long now;
160 u64 now64; 145 u64 now64;
161 int ret;
162 146
163 rtcdrv = dev_get_drvdata(dev); 147 rtcdrv = dev_get_drvdata(dev);
164 base = rtcdrv->base; 148 base = rtcdrv->base;
165 149
166 ret = rtc_tm_to_time(tm, &now); 150 now64 = rtc_tm_to_time64(tm) * NSEC_PER_SEC;
167 if (ret == 0) { 151 writel((now64 >> 32), base + TIMER_TIME_HIGH);
168 now64 = now * NSEC_PER_SEC; 152 writel(now64, base + TIMER_TIME_LOW);
169 writel((now64 >> 32), base + TIMER_TIME_HIGH);
170 writel(now64, base + TIMER_TIME_LOW);
171 }
172 153
173 return ret; 154 return 0;
174} 155}
175 156
176static const struct rtc_class_ops goldfish_rtc_ops = { 157static const struct rtc_class_ops goldfish_rtc_ops = {
@@ -205,19 +186,20 @@ static int goldfish_rtc_probe(struct platform_device *pdev)
205 if (rtcdrv->irq < 0) 186 if (rtcdrv->irq < 0)
206 return -ENODEV; 187 return -ENODEV;
207 188
208 rtcdrv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 189 rtcdrv->rtc = devm_rtc_allocate_device(&pdev->dev);
209 &goldfish_rtc_ops,
210 THIS_MODULE);
211 if (IS_ERR(rtcdrv->rtc)) 190 if (IS_ERR(rtcdrv->rtc))
212 return PTR_ERR(rtcdrv->rtc); 191 return PTR_ERR(rtcdrv->rtc);
213 192
193 rtcdrv->rtc->ops = &goldfish_rtc_ops;
194 rtcdrv->rtc->range_max = U64_MAX / NSEC_PER_SEC;
195
214 err = devm_request_irq(&pdev->dev, rtcdrv->irq, 196 err = devm_request_irq(&pdev->dev, rtcdrv->irq,
215 goldfish_rtc_interrupt, 197 goldfish_rtc_interrupt,
216 0, pdev->name, rtcdrv); 198 0, pdev->name, rtcdrv);
217 if (err) 199 if (err)
218 return err; 200 return err;
219 201
220 return 0; 202 return rtc_register_device(rtcdrv->rtc);
221} 203}
222 204
223static const struct of_device_id goldfish_rtc_of_match[] = { 205static const struct of_device_id goldfish_rtc_of_match[] = {
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index 3e1abb455472..f27c40e8331f 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -205,8 +205,7 @@ static int hid_time_parse_report(struct platform_device *pdev,
205static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm) 205static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
206{ 206{
207 unsigned long flags; 207 unsigned long flags;
208 struct hid_time_state *time_state = 208 struct hid_time_state *time_state = dev_get_drvdata(dev);
209 platform_get_drvdata(to_platform_device(dev));
210 int ret; 209 int ret;
211 210
212 reinit_completion(&time_state->comp_last_time); 211 reinit_completion(&time_state->comp_last_time);
diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c
index 80931114c899..3f3d652a0b0f 100644
--- a/drivers/rtc/rtc-imxdi.c
+++ b/drivers/rtc/rtc-imxdi.c
@@ -1,20 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved. 3 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright 2010 Orex Computed Radiography 4 * Copyright 2010 Orex Computed Radiography
4 */ 5 */
5 6
6/* 7/*
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
17/*
18 * This driver uses the 47-bit 32 kHz counter in the Freescale DryIce block 8 * This driver uses the 47-bit 32 kHz counter in the Freescale DryIce block
19 * to implement a Linux RTC. Times and alarms are truncated to seconds. 9 * to implement a Linux RTC. Times and alarms are truncated to seconds.
20 * Since the RTC framework performs API locking via rtc->ops_lock the 10 * Since the RTC framework performs API locking via rtc->ops_lock the
@@ -552,7 +542,7 @@ static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm)
552 unsigned long now; 542 unsigned long now;
553 543
554 now = readl(imxdi->ioaddr + DTCMR); 544 now = readl(imxdi->ioaddr + DTCMR);
555 rtc_time_to_tm(now, tm); 545 rtc_time64_to_tm(now, tm);
556 546
557 return 0; 547 return 0;
558} 548}
@@ -561,7 +551,7 @@ static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm)
561 * set the seconds portion of dryice time counter and clear the 551 * set the seconds portion of dryice time counter and clear the
562 * fractional part. 552 * fractional part.
563 */ 553 */
564static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs) 554static int dryice_rtc_set_time(struct device *dev, struct rtc_time *tm)
565{ 555{
566 struct imxdi_dev *imxdi = dev_get_drvdata(dev); 556 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
567 u32 dcr, dsr; 557 u32 dcr, dsr;
@@ -588,7 +578,7 @@ static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs)
588 if (rc != 0) 578 if (rc != 0)
589 return rc; 579 return rc;
590 580
591 rc = di_write_wait(imxdi, secs, DTCMR); 581 rc = di_write_wait(imxdi, rtc_tm_to_time64(tm), DTCMR);
592 if (rc != 0) 582 if (rc != 0)
593 return rc; 583 return rc;
594 584
@@ -618,7 +608,7 @@ static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
618 u32 dcamr; 608 u32 dcamr;
619 609
620 dcamr = readl(imxdi->ioaddr + DCAMR); 610 dcamr = readl(imxdi->ioaddr + DCAMR);
621 rtc_time_to_tm(dcamr, &alarm->time); 611 rtc_time64_to_tm(dcamr, &alarm->time);
622 612
623 /* alarm is enabled if the interrupt is enabled */ 613 /* alarm is enabled if the interrupt is enabled */
624 alarm->enabled = (readl(imxdi->ioaddr + DIER) & DIER_CAIE) != 0; 614 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)
640static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 630static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
641{ 631{
642 struct imxdi_dev *imxdi = dev_get_drvdata(dev); 632 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
643 unsigned long now;
644 unsigned long alarm_time;
645 int rc; 633 int rc;
646 634
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
656 /* write the new alarm time */ 635 /* 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);
658 if (rc) 637 if (rc)
659 return rc; 638 return rc;
660 639
@@ -668,7 +647,7 @@ static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
668 647
669static const struct rtc_class_ops dryice_rtc_ops = { 648static const struct rtc_class_ops dryice_rtc_ops = {
670 .read_time = dryice_rtc_read_time, 649 .read_time = dryice_rtc_read_time,
671 .set_mmss = dryice_rtc_set_mmss, 650 .set_time = dryice_rtc_set_time,
672 .alarm_irq_enable = dryice_rtc_alarm_irq_enable, 651 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
673 .read_alarm = dryice_rtc_read_alarm, 652 .read_alarm = dryice_rtc_read_alarm,
674 .set_alarm = dryice_rtc_set_alarm, 653 .set_alarm = dryice_rtc_set_alarm,
@@ -796,6 +775,10 @@ static int __init dryice_rtc_probe(struct platform_device *pdev)
796 775
797 mutex_init(&imxdi->write_mutex); 776 mutex_init(&imxdi->write_mutex);
798 777
778 imxdi->rtc = devm_rtc_allocate_device(&pdev->dev);
779 if (IS_ERR(imxdi->rtc))
780 return PTR_ERR(imxdi->rtc);
781
799 imxdi->clk = devm_clk_get(&pdev->dev, NULL); 782 imxdi->clk = devm_clk_get(&pdev->dev, NULL);
800 if (IS_ERR(imxdi->clk)) 783 if (IS_ERR(imxdi->clk))
801 return PTR_ERR(imxdi->clk); 784 return PTR_ERR(imxdi->clk);
@@ -829,12 +812,13 @@ static int __init dryice_rtc_probe(struct platform_device *pdev)
829 } 812 }
830 813
831 platform_set_drvdata(pdev, imxdi); 814 platform_set_drvdata(pdev, imxdi);
832 imxdi->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 815
833 &dryice_rtc_ops, THIS_MODULE); 816 imxdi->rtc->ops = &dryice_rtc_ops;
834 if (IS_ERR(imxdi->rtc)) { 817 imxdi->rtc->range_max = U32_MAX;
835 rc = PTR_ERR(imxdi->rtc); 818
819 rc = rtc_register_device(imxdi->rtc);
820 if (rc)
836 goto err; 821 goto err;
837 }
838 822
839 return 0; 823 return 0;
840 824
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index d0a891777f44..9e7b3a04debc 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -1,17 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> 3 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3 * Copyright (C) 2010, Paul Cercueil <paul@crapouillou.net> 4 * Copyright (C) 2010, Paul Cercueil <paul@crapouillou.net>
4 * JZ4740 SoC RTC driver 5 * 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 *
15 */ 6 */
16 7
17#include <linux/clk.h> 8#include <linux/clk.h>
@@ -20,6 +11,7 @@
20#include <linux/module.h> 11#include <linux/module.h>
21#include <linux/of_device.h> 12#include <linux/of_device.h>
22#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/pm_wakeirq.h>
23#include <linux/reboot.h> 15#include <linux/reboot.h>
24#include <linux/rtc.h> 16#include <linux/rtc.h>
25#include <linux/slab.h> 17#include <linux/slab.h>
@@ -156,6 +148,9 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time)
156 uint32_t secs, secs2; 148 uint32_t secs, secs2;
157 int timeout = 5; 149 int timeout = 5;
158 150
151 if (jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD) != 0x12345678)
152 return -EINVAL;
153
159 /* If the seconds register is read while it is updated, it can contain a 154 /* If the seconds register is read while it is updated, it can contain a
160 * bogus value. This can be avoided by making sure that two consecutive 155 * bogus value. This can be avoided by making sure that two consecutive
161 * reads have the same value. 156 * reads have the same value.
@@ -171,16 +166,21 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time)
171 if (timeout == 0) 166 if (timeout == 0)
172 return -EIO; 167 return -EIO;
173 168
174 rtc_time_to_tm(secs, time); 169 rtc_time64_to_tm(secs, time);
175 170
176 return 0; 171 return 0;
177} 172}
178 173
179static int jz4740_rtc_set_mmss(struct device *dev, unsigned long secs) 174static int jz4740_rtc_set_time(struct device *dev, struct rtc_time *time)
180{ 175{
181 struct jz4740_rtc *rtc = dev_get_drvdata(dev); 176 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
177 int ret;
182 178
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);
184} 184}
185 185
186static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 186static 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)
196 alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE); 196 alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE);
197 alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF); 197 alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF);
198 198
199 rtc_time_to_tm(secs, &alrm->time); 199 rtc_time64_to_tm(secs, &alrm->time);
200 200
201 return rtc_valid_tm(&alrm->time); 201 return 0;
202} 202}
203 203
204static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 204static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
205{ 205{
206 int ret; 206 int ret;
207 struct jz4740_rtc *rtc = dev_get_drvdata(dev); 207 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
208 unsigned long secs; 208 uint32_t secs = lower_32_bits(rtc_tm_to_time64(&alrm->time));
209
210 rtc_tm_to_time(&alrm->time, &secs);
211 209
212 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs); 210 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs);
213 if (!ret) 211 if (!ret)
@@ -225,7 +223,7 @@ static int jz4740_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
225 223
226static const struct rtc_class_ops jz4740_rtc_ops = { 224static const struct rtc_class_ops jz4740_rtc_ops = {
227 .read_time = jz4740_rtc_read_time, 225 .read_time = jz4740_rtc_read_time,
228 .set_mmss = jz4740_rtc_set_mmss, 226 .set_time = jz4740_rtc_set_time,
229 .read_alarm = jz4740_rtc_read_alarm, 227 .read_alarm = jz4740_rtc_read_alarm,
230 .set_alarm = jz4740_rtc_set_alarm, 228 .set_alarm = jz4740_rtc_set_alarm,
231 .alarm_irq_enable = jz4740_rtc_alarm_irq_enable, 229 .alarm_irq_enable = jz4740_rtc_alarm_irq_enable,
@@ -309,7 +307,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
309{ 307{
310 int ret; 308 int ret;
311 struct jz4740_rtc *rtc; 309 struct jz4740_rtc *rtc;
312 uint32_t scratchpad;
313 struct resource *mem; 310 struct resource *mem;
314 const struct platform_device_id *id = platform_get_device_id(pdev); 311 const struct platform_device_id *id = platform_get_device_id(pdev);
315 const struct of_device_id *of_id = of_match_device( 312 const struct of_device_id *of_id = of_match_device(
@@ -348,10 +345,24 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
348 345
349 device_init_wakeup(&pdev->dev, 1); 346 device_init_wakeup(&pdev->dev, 1);
350 347
351 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 348 ret = dev_pm_set_wake_irq(&pdev->dev, rtc->irq);
352 &jz4740_rtc_ops, THIS_MODULE); 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);
353 if (IS_ERR(rtc->rtc)) { 355 if (IS_ERR(rtc->rtc)) {
354 ret = PTR_ERR(rtc->rtc); 356 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) {
355 dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret); 366 dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret);
356 return ret; 367 return ret;
357 } 368 }
@@ -363,16 +374,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
363 return ret; 374 return ret;
364 } 375 }
365 376
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
376 if (np && of_device_is_system_power_controller(np)) { 377 if (np && of_device_is_system_power_controller(np)) {
377 if (!pm_power_off) { 378 if (!pm_power_off) {
378 /* Default: 60ms */ 379 /* Default: 60ms */
@@ -397,35 +398,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
397 return 0; 398 return 0;
398} 399}
399 400
400#ifdef CONFIG_PM
401static 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
410static 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
419static 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
429static const struct platform_device_id jz4740_rtc_ids[] = { 401static const struct platform_device_id jz4740_rtc_ids[] = {
430 { "jz4740-rtc", ID_JZ4740 }, 402 { "jz4740-rtc", ID_JZ4740 },
431 { "jz4780-rtc", ID_JZ4780 }, 403 { "jz4780-rtc", ID_JZ4780 },
@@ -437,7 +409,6 @@ static struct platform_driver jz4740_rtc_driver = {
437 .probe = jz4740_rtc_probe, 409 .probe = jz4740_rtc_probe,
438 .driver = { 410 .driver = {
439 .name = "jz4740-rtc", 411 .name = "jz4740-rtc",
440 .pm = JZ4740_RTC_PM_OPS,
441 .of_match_table = of_match_ptr(jz4740_rtc_of_match), 412 .of_match_table = of_match_ptr(jz4740_rtc_of_match),
442 }, 413 },
443 .id_table = jz4740_rtc_ids, 414 .id_table = jz4740_rtc_ids,
diff --git a/drivers/rtc/rtc-lpc32xx.c b/drivers/rtc/rtc-lpc32xx.c
index 910e600275b9..ac393230e592 100644
--- a/drivers/rtc/rtc-lpc32xx.c
+++ b/drivers/rtc/rtc-lpc32xx.c
@@ -1,14 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Copyright (C) 2010 NXP Semiconductors 3 * Copyright (C) 2010 NXP Semiconductors
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * You should have received a copy of the GNU General Public License along
10 * with this program; if not, write to the Free Software Foundation, Inc.,
11 * 675 Mass Ave, Cambridge, MA 02139, USA.
12 */ 4 */
13 5
14#include <linux/kernel.h> 6#include <linux/kernel.h>
@@ -47,8 +39,6 @@
47 39
48#define LPC32XX_RTC_KEY_ONSW_LOADVAL 0xB5C13F27 40#define LPC32XX_RTC_KEY_ONSW_LOADVAL 0xB5C13F27
49 41
50#define RTC_NAME "rtc-lpc32xx"
51
52#define rtc_readl(dev, reg) \ 42#define rtc_readl(dev, reg) \
53 __raw_readl((dev)->rtc_base + (reg)) 43 __raw_readl((dev)->rtc_base + (reg))
54#define rtc_writel(dev, reg, val) \ 44#define rtc_writel(dev, reg, val) \
@@ -68,14 +58,15 @@ static int lpc32xx_rtc_read_time(struct device *dev, struct rtc_time *time)
68 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); 58 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
69 59
70 elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT); 60 elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT);
71 rtc_time_to_tm(elapsed_sec, time); 61 rtc_time64_to_tm(elapsed_sec, time);
72 62
73 return 0; 63 return 0;
74} 64}
75 65
76static int lpc32xx_rtc_set_mmss(struct device *dev, unsigned long secs) 66static int lpc32xx_rtc_set_time(struct device *dev, struct rtc_time *time)
77{ 67{
78 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); 68 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
69 u32 secs = rtc_tm_to_time64(time);
79 u32 tmp; 70 u32 tmp;
80 71
81 spin_lock_irq(&rtc->lock); 72 spin_lock_irq(&rtc->lock);
@@ -97,7 +88,7 @@ static int lpc32xx_rtc_read_alarm(struct device *dev,
97{ 88{
98 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); 89 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
99 90
100 rtc_time_to_tm(rtc_readl(rtc, LPC32XX_RTC_MATCH0), &wkalrm->time); 91 rtc_time64_to_tm(rtc_readl(rtc, LPC32XX_RTC_MATCH0), &wkalrm->time);
101 wkalrm->enabled = rtc->alarm_enabled; 92 wkalrm->enabled = rtc->alarm_enabled;
102 wkalrm->pending = !!(rtc_readl(rtc, LPC32XX_RTC_INTSTAT) & 93 wkalrm->pending = !!(rtc_readl(rtc, LPC32XX_RTC_INTSTAT) &
103 LPC32XX_RTC_INTSTAT_MATCH0); 94 LPC32XX_RTC_INTSTAT_MATCH0);
@@ -111,13 +102,8 @@ static int lpc32xx_rtc_set_alarm(struct device *dev,
111 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); 102 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
112 unsigned long alarmsecs; 103 unsigned long alarmsecs;
113 u32 tmp; 104 u32 tmp;
114 int ret;
115 105
116 ret = rtc_tm_to_time(&wkalrm->time, &alarmsecs); 106 alarmsecs = rtc_tm_to_time64(&wkalrm->time);
117 if (ret < 0) {
118 dev_warn(dev, "Failed to convert time: %d\n", ret);
119 return ret;
120 }
121 107
122 spin_lock_irq(&rtc->lock); 108 spin_lock_irq(&rtc->lock);
123 109
@@ -191,7 +177,7 @@ static irqreturn_t lpc32xx_rtc_alarm_interrupt(int irq, void *dev)
191 177
192static const struct rtc_class_ops lpc32xx_rtc_ops = { 178static const struct rtc_class_ops lpc32xx_rtc_ops = {
193 .read_time = lpc32xx_rtc_read_time, 179 .read_time = lpc32xx_rtc_read_time,
194 .set_mmss = lpc32xx_rtc_set_mmss, 180 .set_time = lpc32xx_rtc_set_time,
195 .read_alarm = lpc32xx_rtc_read_alarm, 181 .read_alarm = lpc32xx_rtc_read_alarm,
196 .set_alarm = lpc32xx_rtc_set_alarm, 182 .set_alarm = lpc32xx_rtc_set_alarm,
197 .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable, 183 .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable,
@@ -201,21 +187,13 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
201{ 187{
202 struct resource *res; 188 struct resource *res;
203 struct lpc32xx_rtc *rtc; 189 struct lpc32xx_rtc *rtc;
204 int rtcirq; 190 int err;
205 u32 tmp; 191 u32 tmp;
206 192
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
213 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); 193 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
214 if (unlikely(!rtc)) 194 if (unlikely(!rtc))
215 return -ENOMEM; 195 return -ENOMEM;
216 196
217 rtc->irq = rtcirq;
218
219 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 197 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
220 rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res); 198 rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
221 if (IS_ERR(rtc->rtc_base)) 199 if (IS_ERR(rtc->rtc_base))
@@ -256,18 +234,25 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
256 234
257 platform_set_drvdata(pdev, rtc); 235 platform_set_drvdata(pdev, rtc);
258 236
259 rtc->rtc = devm_rtc_device_register(&pdev->dev, RTC_NAME, 237 rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
260 &lpc32xx_rtc_ops, THIS_MODULE); 238 if (IS_ERR(rtc->rtc))
261 if (IS_ERR(rtc->rtc)) {
262 dev_err(&pdev->dev, "Can't get RTC\n");
263 return PTR_ERR(rtc->rtc); 239 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;
265 247
266 /* 248 /*
267 * IRQ is enabled after device registration in case alarm IRQ 249 * IRQ is enabled after device registration in case alarm IRQ
268 * is pending upon suspend exit. 250 * is pending upon suspend exit.
269 */ 251 */
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 {
271 if (devm_request_irq(&pdev->dev, rtc->irq, 256 if (devm_request_irq(&pdev->dev, rtc->irq,
272 lpc32xx_rtc_alarm_interrupt, 257 lpc32xx_rtc_alarm_interrupt,
273 0, pdev->name, rtc) < 0) { 258 0, pdev->name, rtc) < 0) {
@@ -374,7 +359,7 @@ static struct platform_driver lpc32xx_rtc_driver = {
374 .probe = lpc32xx_rtc_probe, 359 .probe = lpc32xx_rtc_probe,
375 .remove = lpc32xx_rtc_remove, 360 .remove = lpc32xx_rtc_remove,
376 .driver = { 361 .driver = {
377 .name = RTC_NAME, 362 .name = "rtc-lpc32xx",
378 .pm = LPC32XX_RTC_PM_OPS, 363 .pm = LPC32XX_RTC_PM_OPS,
379 .of_match_table = of_match_ptr(lpc32xx_rtc_match), 364 .of_match_table = of_match_ptr(lpc32xx_rtc_match),
380 }, 365 },
diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c
index 0fa33708fc49..afce2c0b4bd6 100644
--- a/drivers/rtc/rtc-mc13xxx.c
+++ b/drivers/rtc/rtc-mc13xxx.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Real Time Clock driver for Freescale MC13XXX PMIC 3 * Real Time Clock driver for Freescale MC13XXX PMIC
3 * 4 *
4 * (C) 2009 Sascha Hauer, Pengutronix 5 * (C) 2009 Sascha Hauer, Pengutronix
5 * (C) 2009 Uwe Kleine-Koenig, Pengutronix 6 * (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.
10 */ 7 */
11 8
12#include <linux/mfd/mc13xxx.h> 9#include <linux/mfd/mc13xxx.h>
@@ -89,14 +86,14 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
89 return 0; 86 return 0;
90} 87}
91 88
92static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs) 89static int mc13xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
93{ 90{
94 struct mc13xxx_rtc *priv = dev_get_drvdata(dev); 91 struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
95 unsigned int seconds, days; 92 unsigned int seconds, days;
96 unsigned int alarmseconds; 93 unsigned int alarmseconds;
97 int ret; 94 int ret;
98 95
99 days = div_s64_rem(secs, SEC_PER_DAY, &seconds); 96 days = div_s64_rem(rtc_tm_to_time64(tm), SEC_PER_DAY, &seconds);
100 97
101 mc13xxx_lock(priv->mc13xxx); 98 mc13xxx_lock(priv->mc13xxx);
102 99
@@ -158,7 +155,7 @@ out:
158static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 155static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
159{ 156{
160 struct mc13xxx_rtc *priv = dev_get_drvdata(dev); 157 struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
161 unsigned seconds, days; 158 unsigned int seconds, days;
162 time64_t s1970; 159 time64_t s1970;
163 int enabled, pending; 160 int enabled, pending;
164 int ret; 161 int ret;
@@ -253,7 +250,7 @@ static irqreturn_t mc13xxx_rtc_alarm_handler(int irq, void *dev)
253 250
254static const struct rtc_class_ops mc13xxx_rtc_ops = { 251static const struct rtc_class_ops mc13xxx_rtc_ops = {
255 .read_time = mc13xxx_rtc_read_time, 252 .read_time = mc13xxx_rtc_read_time,
256 .set_mmss64 = mc13xxx_rtc_set_mmss, 253 .set_time = mc13xxx_rtc_set_time,
257 .read_alarm = mc13xxx_rtc_read_alarm, 254 .read_alarm = mc13xxx_rtc_read_alarm,
258 .set_alarm = mc13xxx_rtc_set_alarm, 255 .set_alarm = mc13xxx_rtc_set_alarm,
259 .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable, 256 .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable,
@@ -285,8 +282,15 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
285 priv->mc13xxx = mc13xxx; 282 priv->mc13xxx = mc13xxx;
286 priv->valid = 1; 283 priv->valid = 1;
287 284
285 priv->rtc = devm_rtc_allocate_device(&pdev->dev);
286 if (IS_ERR(priv->rtc))
287 return PTR_ERR(priv->rtc);
288 platform_set_drvdata(pdev, priv); 288 platform_set_drvdata(pdev, priv);
289 289
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
290 mc13xxx_lock(mc13xxx); 294 mc13xxx_lock(mc13xxx);
291 295
292 mc13xxx_irq_ack(mc13xxx, MC13XXX_IRQ_RTCRST); 296 mc13xxx_irq_ack(mc13xxx, MC13XXX_IRQ_RTCRST);
@@ -303,8 +307,9 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
303 307
304 mc13xxx_unlock(mc13xxx); 308 mc13xxx_unlock(mc13xxx);
305 309
306 priv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 310 ret = rtc_register_device(priv->rtc);
307 &mc13xxx_rtc_ops, THIS_MODULE); 311 if (ret)
312 goto err_irq_request;
308 313
309 return 0; 314 return 0;
310 315
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index e9a25ec4d434..c06cf5202e02 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -343,7 +343,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
343 if (ret) { 343 if (ret) {
344 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 344 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
345 rtc->irq, ret); 345 rtc->irq, ret);
346 goto out_dispose_irq; 346 return ret;
347 } 347 }
348 348
349 device_init_wakeup(&pdev->dev, 1); 349 device_init_wakeup(&pdev->dev, 1);
@@ -359,9 +359,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
359 return 0; 359 return 0;
360 360
361out_free_irq: 361out_free_irq:
362 free_irq(rtc->irq, rtc->rtc_dev); 362 free_irq(rtc->irq, rtc);
363out_dispose_irq:
364 irq_dispose_mapping(rtc->irq);
365 return ret; 363 return ret;
366} 364}
367 365
@@ -369,8 +367,7 @@ static int mtk_rtc_remove(struct platform_device *pdev)
369{ 367{
370 struct mt6397_rtc *rtc = platform_get_drvdata(pdev); 368 struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
371 369
372 free_irq(rtc->irq, rtc->rtc_dev); 370 free_irq(rtc->irq, rtc);
373 irq_dispose_mapping(rtc->irq);
374 371
375 return 0; 372 return 0;
376} 373}
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c
index e7f14bd12fe3..ab9db57a6834 100644
--- a/drivers/rtc/rtc-mv.c
+++ b/drivers/rtc/rtc-mv.c
@@ -1,9 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Driver for the RTC in Marvell SoCs. 3 * 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.
7 */ 4 */
8 5
9#include <linux/init.h> 6#include <linux/init.h>
@@ -60,7 +57,7 @@ static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm)
60 57
61 rtc_reg = (bin2bcd(tm->tm_mday) << RTC_MDAY_OFFS) | 58 rtc_reg = (bin2bcd(tm->tm_mday) << RTC_MDAY_OFFS) |
62 (bin2bcd(tm->tm_mon + 1) << RTC_MONTH_OFFS) | 59 (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);
64 writel(rtc_reg, ioaddr + RTC_DATE_REG_OFFS); 61 writel(rtc_reg, ioaddr + RTC_DATE_REG_OFFS);
65 62
66 return 0; 63 return 0;
@@ -159,7 +156,7 @@ static int mv_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
159 << RTC_MONTH_OFFS; 156 << RTC_MONTH_OFFS;
160 157
161 if (alm->time.tm_year >= 0) 158 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))
163 << RTC_YEAR_OFFS; 160 << RTC_YEAR_OFFS;
164 161
165 writel(rtc_reg, ioaddr + RTC_ALARM_DATE_REG_OFFS); 162 writel(rtc_reg, ioaddr + RTC_ALARM_DATE_REG_OFFS);
@@ -257,15 +254,7 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
257 254
258 platform_set_drvdata(pdev, pdata); 255 platform_set_drvdata(pdev, pdata);
259 256
260 if (pdata->irq >= 0) { 257 pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
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 }
269 if (IS_ERR(pdata->rtc)) { 258 if (IS_ERR(pdata->rtc)) {
270 ret = PTR_ERR(pdata->rtc); 259 ret = PTR_ERR(pdata->rtc);
271 goto out; 260 goto out;
@@ -281,7 +270,19 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
281 } 270 }
282 } 271 }
283 272
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;
285out: 286out:
286 if (!IS_ERR(pdata->clk)) 287 if (!IS_ERR(pdata->clk))
287 clk_disable_unprepare(pdata->clk); 288 clk_disable_unprepare(pdata->clk);
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 878c6ee82901..e697e96612bb 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -8,6 +8,7 @@
8#include <linux/slab.h> 8#include <linux/slab.h>
9#include <linux/interrupt.h> 9#include <linux/interrupt.h>
10#include <linux/platform_device.h> 10#include <linux/platform_device.h>
11#include <linux/pm_wakeirq.h>
11#include <linux/clk.h> 12#include <linux/clk.h>
12#include <linux/of.h> 13#include <linux/of.h>
13#include <linux/of_device.h> 14#include <linux/of_device.h>
@@ -253,20 +254,9 @@ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm)
253/* 254/*
254 * This function sets the internal RTC time based on tm in Gregorian date. 255 * This function sets the internal RTC time based on tm in Gregorian date.
255 */ 256 */
256static int mxc_rtc_set_mmss(struct device *dev, time64_t time) 257static int mxc_rtc_set_time(struct device *dev, struct rtc_time *tm)
257{ 258{
258 struct rtc_plat_data *pdata = dev_get_drvdata(dev); 259 time64_t time = rtc_tm_to_time64(tm);
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 }
270 260
271 /* Avoid roll-over from reading the different registers */ 261 /* Avoid roll-over from reading the different registers */
272 do { 262 do {
@@ -310,7 +300,7 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
310/* RTC layer */ 300/* RTC layer */
311static const struct rtc_class_ops mxc_rtc_ops = { 301static const struct rtc_class_ops mxc_rtc_ops = {
312 .read_time = mxc_rtc_read_time, 302 .read_time = mxc_rtc_read_time,
313 .set_mmss64 = mxc_rtc_set_mmss, 303 .set_time = mxc_rtc_set_time,
314 .read_alarm = mxc_rtc_read_alarm, 304 .read_alarm = mxc_rtc_read_alarm,
315 .set_alarm = mxc_rtc_set_alarm, 305 .set_alarm = mxc_rtc_set_alarm,
316 .alarm_irq_enable = mxc_rtc_alarm_irq_enable, 306 .alarm_irq_enable = mxc_rtc_alarm_irq_enable,
@@ -318,7 +308,6 @@ static const struct rtc_class_ops mxc_rtc_ops = {
318 308
319static int mxc_rtc_probe(struct platform_device *pdev) 309static int mxc_rtc_probe(struct platform_device *pdev)
320{ 310{
321 struct resource *res;
322 struct rtc_device *rtc; 311 struct rtc_device *rtc;
323 struct rtc_plat_data *pdata = NULL; 312 struct rtc_plat_data *pdata = NULL;
324 u32 reg; 313 u32 reg;
@@ -336,11 +325,34 @@ static int mxc_rtc_probe(struct platform_device *pdev)
336 else 325 else
337 pdata->devtype = pdev->id_entry->driver_data; 326 pdata->devtype = pdev->id_entry->driver_data;
338 327
339 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 328 pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0);
340 pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res);
341 if (IS_ERR(pdata->ioaddr)) 329 if (IS_ERR(pdata->ioaddr))
342 return PTR_ERR(pdata->ioaddr); 330 return PTR_ERR(pdata->ioaddr);
343 331
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
344 pdata->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); 356 pdata->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
345 if (IS_ERR(pdata->clk_ipg)) { 357 if (IS_ERR(pdata->clk_ipg)) {
346 dev_err(&pdev->dev, "unable to get ipg clock!\n"); 358 dev_err(&pdev->dev, "unable to get ipg clock!\n");
@@ -396,17 +408,16 @@ static int mxc_rtc_probe(struct platform_device *pdev)
396 pdata->irq = -1; 408 pdata->irq = -1;
397 } 409 }
398 410
399 if (pdata->irq >= 0) 411 if (pdata->irq >= 0) {
400 device_init_wakeup(&pdev->dev, 1); 412 device_init_wakeup(&pdev->dev, 1);
401 413 ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq);
402 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops, 414 if (ret)
403 THIS_MODULE); 415 dev_err(&pdev->dev, "failed to enable irq wake\n");
404 if (IS_ERR(rtc)) {
405 ret = PTR_ERR(rtc);
406 goto exit_put_clk_ref;
407 } 416 }
408 417
409 pdata->rtc = rtc; 418 ret = rtc_register_device(rtc);
419 if (ret)
420 goto exit_put_clk_ref;
410 421
411 return 0; 422 return 0;
412 423
@@ -428,35 +439,10 @@ static int mxc_rtc_remove(struct platform_device *pdev)
428 return 0; 439 return 0;
429} 440}
430 441
431#ifdef CONFIG_PM_SLEEP
432static 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
442static 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
453static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
454
455static struct platform_driver mxc_rtc_driver = { 442static struct platform_driver mxc_rtc_driver = {
456 .driver = { 443 .driver = {
457 .name = "mxc_rtc", 444 .name = "mxc_rtc",
458 .of_match_table = of_match_ptr(imx_rtc_dt_ids), 445 .of_match_table = of_match_ptr(imx_rtc_dt_ids),
459 .pm = &mxc_rtc_pm_ops,
460 }, 446 },
461 .id_table = imx_rtc_devtype, 447 .id_table = imx_rtc_devtype,
462 .probe = mxc_rtc_probe, 448 .probe = mxc_rtc_probe,
diff --git a/drivers/rtc/rtc-mxc_v2.c b/drivers/rtc/rtc-mxc_v2.c
index 007879a5042d..5b970a816631 100644
--- a/drivers/rtc/rtc-mxc_v2.c
+++ b/drivers/rtc/rtc-mxc_v2.c
@@ -10,6 +10,7 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/mod_devicetable.h> 11#include <linux/mod_devicetable.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/pm_wakeirq.h>
13#include <linux/rtc.h> 14#include <linux/rtc.h>
14 15
15#define SRTC_LPPDR_INIT 0x41736166 /* init for glitch detect */ 16#define SRTC_LPPDR_INIT 0x41736166 /* init for glitch detect */
@@ -305,6 +306,9 @@ static int mxc_rtc_probe(struct platform_device *pdev)
305 return pdata->irq; 306 return pdata->irq;
306 307
307 device_init_wakeup(&pdev->dev, 1); 308 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");
308 312
309 ret = clk_prepare_enable(pdata->clk); 313 ret = clk_prepare_enable(pdata->clk);
310 if (ret) 314 if (ret)
@@ -367,30 +371,6 @@ static int mxc_rtc_remove(struct platform_device *pdev)
367 return 0; 371 return 0;
368} 372}
369 373
370#ifdef CONFIG_PM_SLEEP
371static 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
381static 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
392static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
393
394static const struct of_device_id mxc_ids[] = { 374static const struct of_device_id mxc_ids[] = {
395 { .compatible = "fsl,imx53-rtc", }, 375 { .compatible = "fsl,imx53-rtc", },
396 {} 376 {}
@@ -400,7 +380,6 @@ static struct platform_driver mxc_rtc_driver = {
400 .driver = { 380 .driver = {
401 .name = "mxc_rtc_v2", 381 .name = "mxc_rtc_v2",
402 .of_match_table = mxc_ids, 382 .of_match_table = mxc_ids,
403 .pm = &mxc_rtc_pm_ops,
404 }, 383 },
405 .probe = mxc_rtc_probe, 384 .probe = mxc_rtc_probe,
406 .remove = mxc_rtc_remove, 385 .remove = mxc_rtc_remove,
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index bbff0e2deb84..32994b0dd139 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * TI OMAP Real Time Clock interface for Linux 3 * TI OMAP Real Time Clock interface for Linux
3 * 4 *
@@ -6,11 +7,6 @@
6 * 7 *
7 * Copyright (C) 2006 David Brownell (new RTC framework) 8 * Copyright (C) 2006 David Brownell (new RTC framework)
8 * Copyright (C) 2014 Johan Hovold <johan@kernel.org> 9 * 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.
14 */ 10 */
15 11
16#include <dt-bindings/gpio/gpio.h> 12#include <dt-bindings/gpio/gpio.h>
@@ -271,7 +267,7 @@ static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
271} 267}
272 268
273/* this hardware doesn't support "don't care" alarm fields */ 269/* this hardware doesn't support "don't care" alarm fields */
274static int tm2bcd(struct rtc_time *tm) 270static void tm2bcd(struct rtc_time *tm)
275{ 271{
276 tm->tm_sec = bin2bcd(tm->tm_sec); 272 tm->tm_sec = bin2bcd(tm->tm_sec);
277 tm->tm_min = bin2bcd(tm->tm_min); 273 tm->tm_min = bin2bcd(tm->tm_min);
@@ -279,13 +275,7 @@ static int tm2bcd(struct rtc_time *tm)
279 tm->tm_mday = bin2bcd(tm->tm_mday); 275 tm->tm_mday = bin2bcd(tm->tm_mday);
280 276
281 tm->tm_mon = bin2bcd(tm->tm_mon + 1); 277 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;
286 tm->tm_year = bin2bcd(tm->tm_year - 100); 278 tm->tm_year = bin2bcd(tm->tm_year - 100);
287
288 return 0;
289} 279}
290 280
291static void bcd2tm(struct rtc_time *tm) 281static void bcd2tm(struct rtc_time *tm)
@@ -328,8 +318,7 @@ static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm)
328{ 318{
329 struct omap_rtc *rtc = dev_get_drvdata(dev); 319 struct omap_rtc *rtc = dev_get_drvdata(dev);
330 320
331 if (tm2bcd(tm) < 0) 321 tm2bcd(tm);
332 return -EINVAL;
333 322
334 local_irq_disable(); 323 local_irq_disable();
335 rtc_wait_not_busy(rtc); 324 rtc_wait_not_busy(rtc);
@@ -378,8 +367,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
378 struct omap_rtc *rtc = dev_get_drvdata(dev); 367 struct omap_rtc *rtc = dev_get_drvdata(dev);
379 u8 reg, irqwake_reg = 0; 368 u8 reg, irqwake_reg = 0;
380 369
381 if (tm2bcd(&alm->time) < 0) 370 tm2bcd(&alm->time);
382 return -EINVAL;
383 371
384 local_irq_disable(); 372 local_irq_disable();
385 rtc_wait_not_busy(rtc); 373 rtc_wait_not_busy(rtc);
@@ -441,14 +429,10 @@ again:
441 omap_rtc_read_time_raw(rtc, &tm); 429 omap_rtc_read_time_raw(rtc, &tm);
442 seconds = tm.tm_sec; 430 seconds = tm.tm_sec;
443 bcd2tm(&tm); 431 bcd2tm(&tm);
444 rtc_tm_to_time(&tm, &now); 432 now = rtc_tm_to_time64(&tm);
445 rtc_time_to_tm(now + 1, &tm); 433 rtc_time64_to_tm(now + 1, &tm);
446 434
447 if (tm2bcd(&tm) < 0) { 435 tm2bcd(&tm);
448 dev_err(&rtc->rtc->dev, "power off failed\n");
449 rtc->type->lock(rtc);
450 return;
451 }
452 436
453 rtc_wait_not_busy(rtc); 437 rtc_wait_not_busy(rtc);
454 438
@@ -845,6 +829,8 @@ static int omap_rtc_probe(struct platform_device *pdev)
845 } 829 }
846 830
847 rtc->rtc->ops = &omap_rtc_ops; 831 rtc->rtc->ops = &omap_rtc_ops;
832 rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
833 rtc->rtc->range_max = RTC_TIMESTAMP_END_2099;
848 omap_rtc_nvmem_config.priv = rtc; 834 omap_rtc_nvmem_config.priv = rtc;
849 835
850 /* handle periodic and alarm irqs */ 836 /* handle periodic and alarm irqs */
diff --git a/drivers/rtc/rtc-opal.c b/drivers/rtc/rtc-opal.c
index 60f2250fd96b..3dd9d266ce09 100644
--- a/drivers/rtc/rtc-opal.c
+++ b/drivers/rtc/rtc-opal.c
@@ -224,7 +224,7 @@ exit:
224 return rc; 224 return rc;
225} 225}
226 226
227int opal_tpo_alarm_irq_enable(struct device *dev, unsigned int enabled) 227static int opal_tpo_alarm_irq_enable(struct device *dev, unsigned int enabled)
228{ 228{
229 struct rtc_wkalrm alarm = { .enabled = 0 }; 229 struct rtc_wkalrm alarm = { .enabled = 0 };
230 230
diff --git a/drivers/rtc/rtc-pcap.c b/drivers/rtc/rtc-pcap.c
index f176cb9d0dbc..178bfb1dea21 100644
--- a/drivers/rtc/rtc-pcap.c
+++ b/drivers/rtc/rtc-pcap.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * pcap rtc code for Motorola EZX phones 3 * pcap rtc code for Motorola EZX phones
3 * 4 *
@@ -5,11 +6,6 @@
5 * Copyright (c) 2009 Daniel Ribeiro <drwyrm@gmail.com> 6 * Copyright (c) 2009 Daniel Ribeiro <drwyrm@gmail.com>
6 * 7 *
7 * Based on Motorola's rtc.c Copyright (c) 2003-2005 Motorola 8 * 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 *
13 */ 9 */
14 10
15#include <linux/kernel.h> 11#include <linux/kernel.h>
@@ -55,7 +51,7 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
55 ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAYA, &days); 51 ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAYA, &days);
56 secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY; 52 secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY;
57 53
58 rtc_time_to_tm(secs, tm); 54 rtc_time64_to_tm(secs, tm);
59 55
60 return 0; 56 return 0;
61} 57}
@@ -63,12 +59,9 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
63static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 59static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
64{ 60{
65 struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); 61 struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev);
66 struct rtc_time *tm = &alrm->time; 62 unsigned long secs = rtc_tm_to_time64(&alrm->time);
67 unsigned long secs;
68 u32 tod, days; 63 u32 tod, days;
69 64
70 rtc_tm_to_time(tm, &secs);
71
72 tod = secs % SEC_PER_DAY; 65 tod = secs % SEC_PER_DAY;
73 ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_TODA, tod); 66 ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_TODA, tod);
74 67
@@ -90,14 +83,15 @@ static int pcap_rtc_read_time(struct device *dev, struct rtc_time *tm)
90 ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAY, &days); 83 ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAY, &days);
91 secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY; 84 secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY;
92 85
93 rtc_time_to_tm(secs, tm); 86 rtc_time64_to_tm(secs, tm);
94 87
95 return 0; 88 return 0;
96} 89}
97 90
98static int pcap_rtc_set_mmss(struct device *dev, unsigned long secs) 91static int pcap_rtc_set_time(struct device *dev, struct rtc_time *tm)
99{ 92{
100 struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); 93 struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev);
94 unsigned long secs = rtc_tm_to_time64(tm);
101 u32 tod, days; 95 u32 tod, days;
102 96
103 tod = secs % SEC_PER_DAY; 97 tod = secs % SEC_PER_DAY;
@@ -128,9 +122,9 @@ static int pcap_rtc_alarm_irq_enable(struct device *dev, unsigned int en)
128 122
129static const struct rtc_class_ops pcap_rtc_ops = { 123static const struct rtc_class_ops pcap_rtc_ops = {
130 .read_time = pcap_rtc_read_time, 124 .read_time = pcap_rtc_read_time,
125 .set_time = pcap_rtc_set_time,
131 .read_alarm = pcap_rtc_read_alarm, 126 .read_alarm = pcap_rtc_read_alarm,
132 .set_alarm = pcap_rtc_set_alarm, 127 .set_alarm = pcap_rtc_set_alarm,
133 .set_mmss = pcap_rtc_set_mmss,
134 .alarm_irq_enable = pcap_rtc_alarm_irq_enable, 128 .alarm_irq_enable = pcap_rtc_alarm_irq_enable,
135}; 129};
136 130
@@ -149,11 +143,13 @@ static int __init pcap_rtc_probe(struct platform_device *pdev)
149 143
150 platform_set_drvdata(pdev, pcap_rtc); 144 platform_set_drvdata(pdev, pcap_rtc);
151 145
152 pcap_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pcap", 146 pcap_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
153 &pcap_rtc_ops, THIS_MODULE);
154 if (IS_ERR(pcap_rtc->rtc)) 147 if (IS_ERR(pcap_rtc->rtc))
155 return PTR_ERR(pcap_rtc->rtc); 148 return PTR_ERR(pcap_rtc->rtc);
156 149
150 pcap_rtc->rtc->ops = &pcap_rtc_ops;
151 pcap_rtc->rtc->range_max = (1 << 14) * 86400ULL - 1;
152
157 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ); 153 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ);
158 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA); 154 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA);
159 155
@@ -167,7 +163,7 @@ static int __init pcap_rtc_probe(struct platform_device *pdev)
167 if (err) 163 if (err)
168 return err; 164 return err;
169 165
170 return 0; 166 return rtc_register_device(pcap_rtc->rtc);
171} 167}
172 168
173static int __exit pcap_rtc_remove(struct platform_device *pdev) 169static int __exit pcap_rtc_remove(struct platform_device *pdev)
diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index f6ce63c443a0..1afa6d9fa9fb 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * An I2C driver for the PCF85063 RTC 3 * An I2C driver for the PCF85063 RTC
3 * Copyright 2014 Rose Technology 4 * Copyright 2014 Rose Technology
@@ -5,16 +6,16 @@
5 * Author: Søren Andersen <san@rosetechnology.dk> 6 * Author: Søren Andersen <san@rosetechnology.dk>
6 * Maintainers: http://www.nslu2-linux.org/ 7 * Maintainers: http://www.nslu2-linux.org/
7 * 8 *
8 * based on the other drivers in this same directory. 9 * Copyright (C) 2019 Micro Crystal AG
9 * 10 * Author: Alexandre Belloni <alexandre.belloni@bootlin.com>
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 */ 11 */
14#include <linux/i2c.h> 12#include <linux/i2c.h>
15#include <linux/bcd.h> 13#include <linux/bcd.h>
16#include <linux/rtc.h> 14#include <linux/rtc.h>
17#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/of_device.h>
17#include <linux/pm_wakeirq.h>
18#include <linux/regmap.h>
18 19
19/* 20/*
20 * Information for this driver was pulled from the following datasheets. 21 * Information for this driver was pulled from the following datasheets.
@@ -24,61 +25,47 @@
24 * 25 *
25 * PCF85063A -- Rev. 6 — 18 November 2015 26 * PCF85063A -- Rev. 6 — 18 November 2015
26 * PCF85063TP -- Rev. 4 — 6 May 2015 27 * 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 */
28 32
29#define PCF85063_REG_CTRL1 0x00 /* status */ 33#define PCF85063_REG_CTRL1 0x00 /* status */
30#define PCF85063_REG_CTRL1_CAP_SEL BIT(0) 34#define PCF85063_REG_CTRL1_CAP_SEL BIT(0)
31#define PCF85063_REG_CTRL1_STOP BIT(5) 35#define PCF85063_REG_CTRL1_STOP BIT(5)
32 36
33#define PCF85063_REG_SC 0x04 /* datetime */ 37#define PCF85063_REG_CTRL2 0x01
34#define PCF85063_REG_SC_OS 0x80 38#define PCF85063_CTRL2_AF BIT(6)
35 39#define PCF85063_CTRL2_AIE BIT(7)
36static struct i2c_driver pcf85063_driver;
37
38static int pcf85063_stop_clock(struct i2c_client *client, u8 *ctrl1)
39{
40 int rc;
41 u8 reg;
42 40
43 rc = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1); 41#define PCF85063_REG_OFFSET 0x02
44 if (rc < 0) { 42#define PCF85063_OFFSET_SIGN_BIT 6 /* 2's complement sign bit */
45 dev_err(&client->dev, "Failing to stop the clock\n"); 43#define PCF85063_OFFSET_MODE BIT(7)
46 return -EIO; 44#define PCF85063_OFFSET_STEP0 4340
47 } 45#define PCF85063_OFFSET_STEP1 4069
48 46
49 /* stop the clock */ 47#define PCF85063_REG_RAM 0x03
50 reg = rc | PCF85063_REG_CTRL1_STOP;
51 48
52 rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, reg); 49#define PCF85063_REG_SC 0x04 /* datetime */
53 if (rc < 0) { 50#define PCF85063_REG_SC_OS 0x80
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
63static int pcf85063_start_clock(struct i2c_client *client, u8 ctrl1)
64{
65 int rc;
66 51
67 /* start the clock */ 52#define PCF85063_REG_ALM_S 0x0b
68 ctrl1 &= ~PCF85063_REG_CTRL1_STOP; 53#define PCF85063_AEN BIT(7)
69 54
70 rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ctrl1); 55struct pcf85063_config {
71 if (rc < 0) { 56 struct regmap_config regmap;
72 dev_err(&client->dev, "Failing to start the clock\n"); 57 unsigned has_alarms:1;
73 return -EIO; 58 unsigned force_cap_7000:1;
74 } 59};
75 60
76 return 0; 61struct pcf85063 {
77} 62 struct rtc_device *rtc;
63 struct regmap *regmap;
64};
78 65
79static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) 66static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm)
80{ 67{
81 struct i2c_client *client = to_i2c_client(dev); 68 struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
82 int rc; 69 int rc;
83 u8 regs[7]; 70 u8 regs[7];
84 71
@@ -88,16 +75,14 @@ static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm)
88 * event, the access must be finished within one second. So, read all 75 * event, the access must be finished within one second. So, read all
89 * time/date registers in one turn. 76 * time/date registers in one turn.
90 */ 77 */
91 rc = i2c_smbus_read_i2c_block_data(client, PCF85063_REG_SC, 78 rc = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_SC, regs,
92 sizeof(regs), regs); 79 sizeof(regs));
93 if (rc != sizeof(regs)) { 80 if (rc)
94 dev_err(&client->dev, "date/time register read error\n"); 81 return rc;
95 return -EIO;
96 }
97 82
98 /* if the clock has lost its power it makes no sense to use its time */ 83 /* if the clock has lost its power it makes no sense to use its time */
99 if (regs[0] & PCF85063_REG_SC_OS) { 84 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");
101 return -EINVAL; 86 return -EINVAL;
102 } 87 }
103 88
@@ -115,20 +100,18 @@ static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm)
115 100
116static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm) 101static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm)
117{ 102{
118 struct i2c_client *client = to_i2c_client(dev); 103 struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
119 int rc; 104 int rc;
120 u8 regs[7]; 105 u8 regs[7];
121 u8 ctrl1;
122
123 if ((tm->tm_year < 100) || (tm->tm_year > 199))
124 return -EINVAL;
125 106
126 /* 107 /*
127 * to accurately set the time, reset the divider chain and keep it in 108 * to accurately set the time, reset the divider chain and keep it in
128 * reset state until all time/date registers are written 109 * reset state until all time/date registers are written
129 */ 110 */
130 rc = pcf85063_stop_clock(client, &ctrl1); 111 rc = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
131 if (rc != 0) 112 PCF85063_REG_CTRL1_STOP,
113 PCF85063_REG_CTRL1_STOP);
114 if (rc)
132 return rc; 115 return rc;
133 116
134 /* hours, minutes and seconds */ 117 /* hours, minutes and seconds */
@@ -150,101 +133,351 @@ static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm)
150 regs[6] = bin2bcd(tm->tm_year - 100); 133 regs[6] = bin2bcd(tm->tm_year - 100);
151 134
152 /* write all registers at once */ 135 /* write all registers at once */
153 rc = i2c_smbus_write_i2c_block_data(client, PCF85063_REG_SC, 136 rc = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_SC,
154 sizeof(regs), regs); 137 regs, sizeof(regs));
155 if (rc < 0) { 138 if (rc)
156 dev_err(&client->dev, "date/time register write error\n");
157 return rc; 139 return rc;
158 }
159 140
160 /* 141 /*
161 * Write the control register as a separate action since the size of 142 * Write the control register as a separate action since the size of
162 * the register space is different between the PCF85063TP and 143 * the register space is different between the PCF85063TP and
163 * PCF85063A devices. The rollover point can not be used. 144 * PCF85063A devices. The rollover point can not be used.
164 */ 145 */
165 rc = pcf85063_start_clock(client, ctrl1); 146 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
166 if (rc != 0) 147 PCF85063_REG_CTRL1_STOP, 0);
167 return rc; 148}
149
150static 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);
168 172
169 return 0; 173 return 0;
170} 174}
171 175
176static 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
203static 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
213static 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
234static 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
256static 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
280static 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
172static const struct rtc_class_ops pcf85063_rtc_ops = { 313static const struct rtc_class_ops pcf85063_rtc_ops = {
173 .read_time = pcf85063_rtc_read_time, 314 .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
321static 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,
175}; 330};
176 331
177static int pcf85063_load_capacitance(struct i2c_client *client) 332static int pcf85063_nvmem_read(void *priv, unsigned int offset,
333 void *val, size_t bytes)
178{ 334{
179 u32 load; 335 return regmap_read(priv, PCF85063_REG_RAM, val);
180 int rc; 336}
181 u8 reg;
182 337
183 rc = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1); 338static int pcf85063_nvmem_write(void *priv, unsigned int offset,
184 if (rc < 0) 339 void *val, size_t bytes)
185 return rc; 340{
341 return regmap_write(priv, PCF85063_REG_RAM, *(u8 *)val);
342}
186 343
187 reg = rc; 344static int pcf85063_load_capacitance(struct pcf85063 *pcf85063,
188 load = 7000; 345 const struct device_node *np,
189 of_property_read_u32(client->dev.of_node, "quartz-load-femtofarads", 346 unsigned int force_cap)
190 &load); 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);
191 355
192 switch (load) { 356 switch (load) {
193 default: 357 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",
195 load); 359 load);
196 /* fall through */ 360 /* fall through */
197 case 7000: 361 case 7000:
198 reg &= ~PCF85063_REG_CTRL1_CAP_SEL;
199 break; 362 break;
200 case 12500: 363 case 12500:
201 reg |= PCF85063_REG_CTRL1_CAP_SEL; 364 reg = PCF85063_REG_CTRL1_CAP_SEL;
202 break; 365 break;
203 } 366 }
204 367
205 rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, reg); 368 return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
206 369 PCF85063_REG_CTRL1_CAP_SEL, reg);
207 return rc;
208} 370}
209 371
210static int pcf85063_probe(struct i2c_client *client, 372static const struct pcf85063_config pcf85063a_config = {
211 const struct i2c_device_id *id) 373 .regmap = {
374 .reg_bits = 8,
375 .val_bits = 8,
376 .max_register = 0x11,
377 },
378 .has_alarms = 1,
379};
380
381static const struct pcf85063_config pcf85063tp_config = {
382 .regmap = {
383 .reg_bits = 8,
384 .val_bits = 8,
385 .max_register = 0x0a,
386 },
387};
388
389static 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
399static int pcf85063_probe(struct i2c_client *client)
212{ 400{
213 struct rtc_device *rtc; 401 struct pcf85063 *pcf85063;
402 unsigned int tmp;
214 int err; 403 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 };
215 413
216 dev_dbg(&client->dev, "%s\n", __func__); 414 dev_dbg(&client->dev, "%s\n", __func__);
217 415
218 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 416 pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063),
219 return -ENODEV; 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);
220 427
221 err = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1); 428 i2c_set_clientdata(client, pcf85063);
222 if (err < 0) { 429
430 err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL1, &tmp);
431 if (err) {
223 dev_err(&client->dev, "RTC chip is not present\n"); 432 dev_err(&client->dev, "RTC chip is not present\n");
224 return err; 433 return err;
225 } 434 }
226 435
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);
228 if (err < 0) 442 if (err < 0)
229 dev_warn(&client->dev, "failed to set xtal load capacitance: %d", 443 dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
230 err); 444 err);
231 445
232 rtc = devm_rtc_device_register(&client->dev, 446 pcf85063->rtc->ops = &pcf85063_rtc_ops;
233 pcf85063_driver.driver.name, 447 pcf85063->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
234 &pcf85063_rtc_ops, THIS_MODULE); 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);
235 471
236 return PTR_ERR_OR_ZERO(rtc); 472 return rtc_register_device(pcf85063->rtc);
237} 473}
238 474
239static const struct i2c_device_id pcf85063_id[] = {
240 { "pcf85063", 0 },
241 { }
242};
243MODULE_DEVICE_TABLE(i2c, pcf85063_id);
244
245#ifdef CONFIG_OF 475#ifdef CONFIG_OF
246static const struct of_device_id pcf85063_of_match[] = { 476static 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 },
248 {} 481 {}
249}; 482};
250MODULE_DEVICE_TABLE(of, pcf85063_of_match); 483MODULE_DEVICE_TABLE(of, pcf85063_of_match);
@@ -255,8 +488,7 @@ static struct i2c_driver pcf85063_driver = {
255 .name = "rtc-pcf85063", 488 .name = "rtc-pcf85063",
256 .of_match_table = of_match_ptr(pcf85063_of_match), 489 .of_match_table = of_match_ptr(pcf85063_of_match),
257 }, 490 },
258 .probe = pcf85063_probe, 491 .probe_new = pcf85063_probe,
259 .id_table = pcf85063_id,
260}; 492};
261 493
262module_i2c_driver(pcf85063_driver); 494module_i2c_driver(pcf85063_driver);
diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
index a3988079f60a..a075e77617dc 100644
--- a/drivers/rtc/rtc-pcf85363.c
+++ b/drivers/rtc/rtc-pcf85363.c
@@ -1,15 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * drivers/rtc/rtc-pcf85363.c 3 * drivers/rtc/rtc-pcf85363.c
3 * 4 *
4 * Driver for NXP PCF85363 real-time clock. 5 * Driver for NXP PCF85363 real-time clock.
5 * 6 *
6 * Copyright (C) 2017 Eric Nelson 7 * 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
13 */ 8 */
14#include <linux/module.h> 9#include <linux/module.h>
15#include <linux/i2c.h> 10#include <linux/i2c.h>
@@ -112,10 +107,7 @@
112 107
113#define NVRAM_SIZE 0x40 108#define NVRAM_SIZE 0x40
114 109
115static struct i2c_driver pcf85363_driver;
116
117struct pcf85363 { 110struct pcf85363 {
118 struct device *dev;
119 struct rtc_device *rtc; 111 struct rtc_device *rtc;
120 struct regmap *regmap; 112 struct regmap *regmap;
121}; 113};
@@ -386,9 +378,6 @@ static int pcf85363_probe(struct i2c_client *client,
386 if (data) 378 if (data)
387 config = data; 379 config = data;
388 380
389 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
390 return -ENODEV;
391
392 pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363), 381 pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363),
393 GFP_KERNEL); 382 GFP_KERNEL);
394 if (!pcf85363) 383 if (!pcf85363)
@@ -400,20 +389,21 @@ static int pcf85363_probe(struct i2c_client *client,
400 return PTR_ERR(pcf85363->regmap); 389 return PTR_ERR(pcf85363->regmap);
401 } 390 }
402 391
403 pcf85363->dev = &client->dev;
404 i2c_set_clientdata(client, pcf85363); 392 i2c_set_clientdata(client, pcf85363);
405 393
406 pcf85363->rtc = devm_rtc_allocate_device(pcf85363->dev); 394 pcf85363->rtc = devm_rtc_allocate_device(&client->dev);
407 if (IS_ERR(pcf85363->rtc)) 395 if (IS_ERR(pcf85363->rtc))
408 return PTR_ERR(pcf85363->rtc); 396 return PTR_ERR(pcf85363->rtc);
409 397
410 pcf85363->rtc->ops = &rtc_ops; 398 pcf85363->rtc->ops = &rtc_ops;
399 pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
400 pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
411 401
412 if (client->irq > 0) { 402 if (client->irq > 0) {
413 regmap_write(pcf85363->regmap, CTRL_FLAGS, 0); 403 regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
414 regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, 404 regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
415 PIN_IO_INTA_OUT, PIN_IO_INTAPM); 405 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,
417 NULL, pcf85363_rtc_handle_irq, 407 NULL, pcf85363_rtc_handle_irq,
418 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 408 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
419 "pcf85363", client); 409 "pcf85363", client);
diff --git a/drivers/rtc/rtc-ps3.c b/drivers/rtc/rtc-ps3.c
index 347288bff438..f0336d691e6c 100644
--- a/drivers/rtc/rtc-ps3.c
+++ b/drivers/rtc/rtc-ps3.c
@@ -1,20 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * PS3 RTC Driver 3 * PS3 RTC Driver
3 * 4 *
4 * Copyright 2009 Sony Corporation 5 * 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/>.
18 */ 6 */
19 7
20#include <linux/kernel.h> 8#include <linux/kernel.h>
@@ -40,16 +28,13 @@ static u64 read_rtc(void)
40 28
41static int ps3_get_time(struct device *dev, struct rtc_time *tm) 29static int ps3_get_time(struct device *dev, struct rtc_time *tm)
42{ 30{
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);
44 return 0; 32 return 0;
45} 33}
46 34
47static int ps3_set_time(struct device *dev, struct rtc_time *tm) 35static int ps3_set_time(struct device *dev, struct rtc_time *tm)
48{ 36{
49 unsigned long now; 37 ps3_os_area_set_rtc_diff(rtc_tm_to_time64(tm) - read_rtc());
50
51 rtc_tm_to_time(tm, &now);
52 ps3_os_area_set_rtc_diff(now - read_rtc());
53 return 0; 38 return 0;
54} 39}
55 40
@@ -62,13 +47,16 @@ static int __init ps3_rtc_probe(struct platform_device *dev)
62{ 47{
63 struct rtc_device *rtc; 48 struct rtc_device *rtc;
64 49
65 rtc = devm_rtc_device_register(&dev->dev, "rtc-ps3", &ps3_rtc_ops, 50 rtc = devm_rtc_allocate_device(&dev->dev);
66 THIS_MODULE);
67 if (IS_ERR(rtc)) 51 if (IS_ERR(rtc))
68 return PTR_ERR(rtc); 52 return PTR_ERR(rtc);
69 53
54 rtc->ops = &ps3_rtc_ops;
55 rtc->range_max = U64_MAX;
56
70 platform_set_drvdata(dev, rtc); 57 platform_set_drvdata(dev, rtc);
71 return 0; 58
59 return rtc_register_device(rtc);
72} 60}
73 61
74static struct platform_driver ps3_rtc_driver = { 62static struct platform_driver ps3_rtc_driver = {
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c
index e1887b86fdc7..d4766734e40b 100644
--- a/drivers/rtc/rtc-pxa.c
+++ b/drivers/rtc/rtc-pxa.c
@@ -145,8 +145,7 @@ static void rtsr_set_bits(struct pxa_rtc *pxa_rtc, u32 mask)
145 145
146static irqreturn_t pxa_rtc_irq(int irq, void *dev_id) 146static irqreturn_t pxa_rtc_irq(int irq, void *dev_id)
147{ 147{
148 struct platform_device *pdev = to_platform_device(dev_id); 148 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev_id);
149 struct pxa_rtc *pxa_rtc = platform_get_drvdata(pdev);
150 u32 rtsr; 149 u32 rtsr;
151 unsigned long events = 0; 150 unsigned long events = 0;
152 151
diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c
index 1fb864d4ef83..5c5d9f125669 100644
--- a/drivers/rtc/rtc-rk808.c
+++ b/drivers/rtc/rtc-rk808.c
@@ -336,8 +336,7 @@ static const struct rtc_class_ops rk808_rtc_ops = {
336/* Turn off the alarm if it should not be a wake source. */ 336/* Turn off the alarm if it should not be a wake source. */
337static int rk808_rtc_suspend(struct device *dev) 337static int rk808_rtc_suspend(struct device *dev)
338{ 338{
339 struct platform_device *pdev = to_platform_device(dev); 339 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
340 struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev);
341 340
342 if (device_may_wakeup(dev)) 341 if (device_may_wakeup(dev))
343 enable_irq_wake(rk808_rtc->irq); 342 enable_irq_wake(rk808_rtc->irq);
@@ -350,8 +349,7 @@ static int rk808_rtc_suspend(struct device *dev)
350 */ 349 */
351static int rk808_rtc_resume(struct device *dev) 350static int rk808_rtc_resume(struct device *dev)
352{ 351{
353 struct platform_device *pdev = to_platform_device(dev); 352 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
354 struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev);
355 353
356 if (device_may_wakeup(dev)) 354 if (device_may_wakeup(dev))
357 disable_irq_wake(rk808_rtc->irq); 355 disable_irq_wake(rk808_rtc->irq);
diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c
index 5899ca368d59..71e20a6bd387 100644
--- a/drivers/rtc/rtc-rx6110.c
+++ b/drivers/rtc/rtc-rx6110.c
@@ -21,6 +21,8 @@
21#include <linux/of_gpio.h> 21#include <linux/of_gpio.h>
22#include <linux/regmap.h> 22#include <linux/regmap.h>
23#include <linux/rtc.h> 23#include <linux/rtc.h>
24#include <linux/of.h>
25#include <linux/of_device.h>
24#include <linux/spi/spi.h> 26#include <linux/spi/spi.h>
25 27
26/* RX-6110 Register definitions */ 28/* RX-6110 Register definitions */
@@ -379,9 +381,16 @@ static const struct spi_device_id rx6110_id[] = {
379}; 381};
380MODULE_DEVICE_TABLE(spi, rx6110_id); 382MODULE_DEVICE_TABLE(spi, rx6110_id);
381 383
384static const struct of_device_id rx6110_spi_of_match[] = {
385 { .compatible = "epson,rx6110" },
386 { },
387};
388MODULE_DEVICE_TABLE(of, rx6110_spi_of_match);
389
382static struct spi_driver rx6110_driver = { 390static struct spi_driver rx6110_driver = {
383 .driver = { 391 .driver = {
384 .name = RX6110_DRIVER_NAME, 392 .name = RX6110_DRIVER_NAME,
393 .of_match_table = of_match_ptr(rx6110_spi_of_match),
385 }, 394 },
386 .probe = rx6110_probe, 395 .probe = rx6110_probe,
387 .remove = rx6110_remove, 396 .remove = rx6110_remove,
diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
index 41de38acc570..fddc996cb38d 100644
--- a/drivers/rtc/rtc-rx8025.c
+++ b/drivers/rtc/rtc-rx8025.c
@@ -311,7 +311,7 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
311 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12 311 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12
312 + (ald[1] & 0x20 ? 12 : 0); 312 + (ald[1] & 0x20 ? 12 : 0);
313 313
314 dev_dbg(dev, "%s: date: %ptRr\n", __func__, t); 314 dev_dbg(dev, "%s: date: %ptRr\n", __func__, &t->time);
315 t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE); 315 t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE);
316 t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled; 316 t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled;
317 317
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 1d3de2a3d1a4..579b3ff5c644 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -276,6 +276,9 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
276 struct sh_rtc *rtc = dev_get_drvdata(dev); 276 struct sh_rtc *rtc = dev_get_drvdata(dev);
277 unsigned int sec128, sec2, yr, yr100, cf_bit; 277 unsigned int sec128, sec2, yr, yr100, cf_bit;
278 278
279 if (!(readb(rtc->regbase + RCR2) & RCR2_RTCEN))
280 return -EINVAL;
281
279 do { 282 do {
280 unsigned int tmp; 283 unsigned int tmp;
281 284
@@ -466,7 +469,6 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
466{ 469{
467 struct sh_rtc *rtc; 470 struct sh_rtc *rtc;
468 struct resource *res; 471 struct resource *res;
469 struct rtc_time r;
470 char clk_name[6]; 472 char clk_name[6];
471 int clk_id, ret; 473 int clk_id, ret;
472 474
@@ -528,6 +530,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
528 rtc->clk = NULL; 530 rtc->clk = NULL;
529 } 531 }
530 532
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
531 clk_enable(rtc->clk); 537 clk_enable(rtc->clk);
532 538
533 rtc->capabilities = RTC_DEF_CAPABILITIES; 539 rtc->capabilities = RTC_DEF_CAPABILITIES;
@@ -591,21 +597,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
591 sh_rtc_setaie(&pdev->dev, 0); 597 sh_rtc_setaie(&pdev->dev, 0);
592 sh_rtc_setcie(&pdev->dev, 0); 598 sh_rtc_setcie(&pdev->dev, 0);
593 599
594 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "sh", 600 rtc->rtc_dev->ops = &sh_rtc_ops;
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
601 rtc->rtc_dev->max_user_freq = 256; 601 rtc->rtc_dev->max_user_freq = 256;
602 602
603 /* reset rtc to epoch 0 if time is invalid */ 603 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
604 if (rtc_read_time(rtc->rtc_dev, &r) < 0) { 604 rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
605 rtc_time_to_tm(0, &r); 605 rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
606 rtc_set_time(rtc->rtc_dev, &r); 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);
607 } 609 }
608 610
611 ret = rtc_register_device(rtc->rtc_dev);
612 if (ret)
613 goto err_unmap;
614
609 device_init_wakeup(&pdev->dev, 1); 615 device_init_wakeup(&pdev->dev, 1);
610 return 0; 616 return 0;
611 617
diff --git a/drivers/rtc/rtc-sirfsoc.c b/drivers/rtc/rtc-sirfsoc.c
index 2a9e151cae99..9ba28d1ebd87 100644
--- a/drivers/rtc/rtc-sirfsoc.c
+++ b/drivers/rtc/rtc-sirfsoc.c
@@ -279,7 +279,7 @@ static const struct of_device_id sirfsoc_rtc_of_match[] = {
279 {}, 279 {},
280}; 280};
281 281
282const struct regmap_config sysrtc_regmap_config = { 282static const struct regmap_config sysrtc_regmap_config = {
283 .reg_bits = 32, 283 .reg_bits = 32,
284 .val_bits = 32, 284 .val_bits = 32,
285 .fast_io = true, 285 .fast_io = true,
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index 0b9eff19149b..7ee673a25fd0 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -9,6 +9,7 @@
9#include <linux/of.h> 9#include <linux/of.h>
10#include <linux/of_device.h> 10#include <linux/of_device.h>
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/pm_wakeirq.h>
12#include <linux/rtc.h> 13#include <linux/rtc.h>
13#include <linux/clk.h> 14#include <linux/clk.h>
14#include <linux/mfd/syscon.h> 15#include <linux/mfd/syscon.h>
@@ -271,7 +272,6 @@ static const struct regmap_config snvs_rtc_config = {
271static int snvs_rtc_probe(struct platform_device *pdev) 272static int snvs_rtc_probe(struct platform_device *pdev)
272{ 273{
273 struct snvs_rtc_data *data; 274 struct snvs_rtc_data *data;
274 struct resource *res;
275 int ret; 275 int ret;
276 void __iomem *mmio; 276 void __iomem *mmio;
277 277
@@ -283,9 +283,8 @@ static int snvs_rtc_probe(struct platform_device *pdev)
283 283
284 if (IS_ERR(data->regmap)) { 284 if (IS_ERR(data->regmap)) {
285 dev_warn(&pdev->dev, "snvs rtc: you use old dts file, please update it\n"); 285 dev_warn(&pdev->dev, "snvs rtc: you use old dts file, please update it\n");
286 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
287 286
288 mmio = devm_ioremap_resource(&pdev->dev, res); 287 mmio = devm_platform_ioremap_resource(pdev, 0);
289 if (IS_ERR(mmio)) 288 if (IS_ERR(mmio))
290 return PTR_ERR(mmio); 289 return PTR_ERR(mmio);
291 290
@@ -332,6 +331,9 @@ static int snvs_rtc_probe(struct platform_device *pdev)
332 } 331 }
333 332
334 device_init_wakeup(&pdev->dev, true); 333 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");
335 337
336 ret = devm_request_irq(&pdev->dev, data->irq, snvs_rtc_irq_handler, 338 ret = devm_request_irq(&pdev->dev, data->irq, snvs_rtc_irq_handler,
337 IRQF_SHARED, "rtc alarm", &pdev->dev); 339 IRQF_SHARED, "rtc alarm", &pdev->dev);
@@ -358,18 +360,7 @@ error_rtc_device_register:
358 return ret; 360 return ret;
359} 361}
360 362
361#ifdef CONFIG_PM_SLEEP 363static int __maybe_unused snvs_rtc_suspend_noirq(struct device *dev)
362static 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
372static int snvs_rtc_suspend_noirq(struct device *dev)
373{ 364{
374 struct snvs_rtc_data *data = dev_get_drvdata(dev); 365 struct snvs_rtc_data *data = dev_get_drvdata(dev);
375 366
@@ -379,17 +370,7 @@ static int snvs_rtc_suspend_noirq(struct device *dev)
379 return 0; 370 return 0;
380} 371}
381 372
382static int snvs_rtc_resume(struct device *dev) 373static int __maybe_unused snvs_rtc_resume_noirq(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
392static int snvs_rtc_resume_noirq(struct device *dev)
393{ 374{
394 struct snvs_rtc_data *data = dev_get_drvdata(dev); 375 struct snvs_rtc_data *data = dev_get_drvdata(dev);
395 376
@@ -400,20 +381,9 @@ static int snvs_rtc_resume_noirq(struct device *dev)
400} 381}
401 382
402static const struct dev_pm_ops snvs_rtc_pm_ops = { 383static const struct dev_pm_ops snvs_rtc_pm_ops = {
403 .suspend = snvs_rtc_suspend, 384 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(snvs_rtc_suspend_noirq, snvs_rtc_resume_noirq)
404 .suspend_noirq = snvs_rtc_suspend_noirq,
405 .resume = snvs_rtc_resume,
406 .resume_noirq = snvs_rtc_resume_noirq,
407}; 385};
408 386
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
417static const struct of_device_id snvs_dt_ids[] = { 387static const struct of_device_id snvs_dt_ids[] = {
418 { .compatible = "fsl,sec-v4.0-mon-rtc-lp", }, 388 { .compatible = "fsl,sec-v4.0-mon-rtc-lp", },
419 { /* sentinel */ } 389 { /* sentinel */ }
@@ -423,7 +393,7 @@ MODULE_DEVICE_TABLE(of, snvs_dt_ids);
423static struct platform_driver snvs_rtc_driver = { 393static struct platform_driver snvs_rtc_driver = {
424 .driver = { 394 .driver = {
425 .name = "snvs_rtc", 395 .name = "snvs_rtc",
426 .pm = SNVS_RTC_PM_OPS, 396 .pm = &snvs_rtc_pm_ops,
427 .of_match_table = snvs_dt_ids, 397 .of_match_table = snvs_dt_ids,
428 }, 398 },
429 .probe = snvs_rtc_probe, 399 .probe = snvs_rtc_probe,
diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c
index c5908cfea234..8e6c9b3bcc29 100644
--- a/drivers/rtc/rtc-stm32.c
+++ b/drivers/rtc/rtc-stm32.c
@@ -788,11 +788,14 @@ static int stm32_rtc_probe(struct platform_device *pdev)
788 ret = device_init_wakeup(&pdev->dev, true); 788 ret = device_init_wakeup(&pdev->dev, true);
789 if (rtc->data->has_wakeirq) { 789 if (rtc->data->has_wakeirq) {
790 rtc->wakeirq_alarm = platform_get_irq(pdev, 1); 790 rtc->wakeirq_alarm = platform_get_irq(pdev, 1);
791 if (rtc->wakeirq_alarm <= 0) 791 if (rtc->wakeirq_alarm > 0) {
792 ret = rtc->wakeirq_alarm;
793 else
794 ret = dev_pm_set_dedicated_wake_irq(&pdev->dev, 792 ret = dev_pm_set_dedicated_wake_irq(&pdev->dev,
795 rtc->wakeirq_alarm); 793 rtc->wakeirq_alarm);
794 } else {
795 ret = rtc->wakeirq_alarm;
796 if (rtc->wakeirq_alarm == -EPROBE_DEFER)
797 goto err;
798 }
796 } 799 }
797 if (ret) 800 if (ret)
798 dev_warn(&pdev->dev, "alarm can't wake up the system: %d", ret); 801 dev_warn(&pdev->dev, "alarm can't wake up the system: %d", ret);
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index b76318fd5bb0..ff6488be385f 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Freescale STMP37XX/STMP378X Real Time Clock driver 3 * Freescale STMP37XX/STMP378X Real Time Clock driver
3 * 4 *
@@ -8,15 +9,6 @@
8 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved. 9 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
9 * Copyright 2011 Wolfram Sang, Pengutronix e.K. 10 * Copyright 2011 Wolfram Sang, Pengutronix e.K.
10 */ 11 */
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 */
20#include <linux/kernel.h> 12#include <linux/kernel.h>
21#include <linux/module.h> 13#include <linux/module.h>
22#include <linux/io.h> 14#include <linux/io.h>
@@ -160,15 +152,15 @@ static int stmp3xxx_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
160 if (ret) 152 if (ret)
161 return ret; 153 return ret;
162 154
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);
164 return 0; 156 return 0;
165} 157}
166 158
167static int stmp3xxx_rtc_set_mmss(struct device *dev, unsigned long t) 159static int stmp3xxx_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
168{ 160{
169 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); 161 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
170 162
171 writel(t, rtc_data->io + STMP3XXX_RTC_SECONDS); 163 writel(rtc_tm_to_time64(rtc_tm), rtc_data->io + STMP3XXX_RTC_SECONDS);
172 return stmp3xxx_wait_time(rtc_data); 164 return stmp3xxx_wait_time(rtc_data);
173} 165}
174 166
@@ -214,17 +206,15 @@ static int stmp3xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
214{ 206{
215 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); 207 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
216 208
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);
218 return 0; 210 return 0;
219} 211}
220 212
221static int stmp3xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) 213static int stmp3xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
222{ 214{
223 unsigned long t;
224 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); 215 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
225 216
226 rtc_tm_to_time(&alm->time, &t); 217 writel(rtc_tm_to_time64(&alm->time), rtc_data->io + STMP3XXX_RTC_ALARM);
227 writel(t, rtc_data->io + STMP3XXX_RTC_ALARM);
228 218
229 stmp3xxx_alarm_irq_enable(dev, alm->enabled); 219 stmp3xxx_alarm_irq_enable(dev, alm->enabled);
230 220
@@ -235,7 +225,7 @@ static const struct rtc_class_ops stmp3xxx_rtc_ops = {
235 .alarm_irq_enable = 225 .alarm_irq_enable =
236 stmp3xxx_alarm_irq_enable, 226 stmp3xxx_alarm_irq_enable,
237 .read_time = stmp3xxx_rtc_gettime, 227 .read_time = stmp3xxx_rtc_gettime,
238 .set_mmss = stmp3xxx_rtc_set_mmss, 228 .set_time = stmp3xxx_rtc_settime,
239 .read_alarm = stmp3xxx_rtc_read_alarm, 229 .read_alarm = stmp3xxx_rtc_read_alarm,
240 .set_alarm = stmp3xxx_rtc_set_alarm, 230 .set_alarm = stmp3xxx_rtc_set_alarm,
241}; 231};
@@ -361,8 +351,7 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
361 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 351 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
362 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR); 352 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
363 353
364 rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 354 rtc_data->rtc = devm_rtc_allocate_device(&pdev->dev);
365 &stmp3xxx_rtc_ops, THIS_MODULE);
366 if (IS_ERR(rtc_data->rtc)) 355 if (IS_ERR(rtc_data->rtc))
367 return PTR_ERR(rtc_data->rtc); 356 return PTR_ERR(rtc_data->rtc);
368 357
@@ -374,6 +363,13 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
374 return err; 363 return err;
375 } 364 }
376 365
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
377 stmp3xxx_wdt_register(pdev); 373 stmp3xxx_wdt_register(pdev);
378 return 0; 374 return 0;
379} 375}
diff --git a/drivers/rtc/rtc-sun4v.c b/drivers/rtc/rtc-sun4v.c
index 11bc562eba5d..036463dfa103 100644
--- a/drivers/rtc/rtc-sun4v.c
+++ b/drivers/rtc/rtc-sun4v.c
@@ -1,7 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1/* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems. 2/* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems.
2 * 3 *
3 * Author: David S. Miller 4 * Author: David S. Miller
4 * License: GPL
5 * 5 *
6 * Copyright (C) 2008 David S. Miller <davem@davemloft.net> 6 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
7 */ 7 */
@@ -39,7 +39,7 @@ retry:
39 39
40static int sun4v_read_time(struct device *dev, struct rtc_time *tm) 40static int sun4v_read_time(struct device *dev, struct rtc_time *tm)
41{ 41{
42 rtc_time_to_tm(hypervisor_get_time(), tm); 42 rtc_time64_to_tm(hypervisor_get_time(), tm);
43 return 0; 43 return 0;
44} 44}
45 45
@@ -66,14 +66,7 @@ retry:
66 66
67static int sun4v_set_time(struct device *dev, struct rtc_time *tm) 67static int sun4v_set_time(struct device *dev, struct rtc_time *tm)
68{ 68{
69 unsigned long secs; 69 return hypervisor_set_time(rtc_tm_to_time64(tm));
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);
77} 70}
78 71
79static const struct rtc_class_ops sun4v_rtc_ops = { 72static const struct rtc_class_ops sun4v_rtc_ops = {
@@ -85,13 +78,15 @@ static int __init sun4v_rtc_probe(struct platform_device *pdev)
85{ 78{
86 struct rtc_device *rtc; 79 struct rtc_device *rtc;
87 80
88 rtc = devm_rtc_device_register(&pdev->dev, "sun4v", 81 rtc = devm_rtc_allocate_device(&pdev->dev);
89 &sun4v_rtc_ops, THIS_MODULE);
90 if (IS_ERR(rtc)) 82 if (IS_ERR(rtc))
91 return PTR_ERR(rtc); 83 return PTR_ERR(rtc);
92 84
85 rtc->ops = &sun4v_rtc_ops;
86 rtc->range_max = U64_MAX;
93 platform_set_drvdata(pdev, rtc); 87 platform_set_drvdata(pdev, rtc);
94 return 0; 88
89 return rtc_register_device(rtc);
95} 90}
96 91
97static struct platform_driver sun4v_rtc_driver = { 92static struct platform_driver sun4v_rtc_driver = {
diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c
index c6b0a99aa3a9..f0ce76865434 100644
--- a/drivers/rtc/rtc-tegra.c
+++ b/drivers/rtc/rtc-tegra.c
@@ -1,21 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * An RTC driver for the NVIDIA Tegra 200 series internal RTC. 3 * An RTC driver for the NVIDIA Tegra 200 series internal RTC.
3 * 4 *
4 * Copyright (c) 2010, NVIDIA Corporation. 5 * 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.
19 */ 6 */
20 7
21#include <linux/clk.h> 8#include <linux/clk.h>
@@ -123,7 +110,7 @@ static int tegra_rtc_read_time(struct device *dev, struct rtc_time *tm)
123 110
124 spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags); 111 spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
125 112
126 rtc_time_to_tm(sec, tm); 113 rtc_time64_to_tm(sec, tm);
127 114
128 dev_vdbg(dev, "time read as %lu. %ptR\n", sec, tm); 115 dev_vdbg(dev, "time read as %lu. %ptR\n", sec, tm);
129 116
@@ -137,7 +124,7 @@ static int tegra_rtc_set_time(struct device *dev, struct rtc_time *tm)
137 int ret; 124 int ret;
138 125
139 /* convert tm to seconds. */ 126 /* convert tm to seconds. */
140 rtc_tm_to_time(tm, &sec); 127 sec = rtc_tm_to_time64(tm);
141 128
142 dev_vdbg(dev, "time set to %lu. %ptR\n", sec, tm); 129 dev_vdbg(dev, "time set to %lu. %ptR\n", sec, tm);
143 130
@@ -166,7 +153,7 @@ static int tegra_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
166 } else { 153 } else {
167 /* alarm is enabled. */ 154 /* alarm is enabled. */
168 alarm->enabled = 1; 155 alarm->enabled = 1;
169 rtc_time_to_tm(sec, &alarm->time); 156 rtc_time64_to_tm(sec, &alarm->time);
170 } 157 }
171 158
172 tmp = readl(info->rtc_base + TEGRA_RTC_REG_INTR_STATUS); 159 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)
204 unsigned long sec; 191 unsigned long sec;
205 192
206 if (alarm->enabled) 193 if (alarm->enabled)
207 rtc_tm_to_time(&alarm->time, &sec); 194 sec = rtc_tm_to_time64(&alarm->time);
208 else 195 else
209 sec = 0; 196 sec = 0;
210 197
@@ -306,6 +293,13 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
306 293
307 info->tegra_rtc_irq = ret; 294 info->tegra_rtc_irq = ret;
308 295
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
309 info->clk = devm_clk_get(&pdev->dev, NULL); 303 info->clk = devm_clk_get(&pdev->dev, NULL);
310 if (IS_ERR(info->clk)) 304 if (IS_ERR(info->clk))
311 return PTR_ERR(info->clk); 305 return PTR_ERR(info->clk);
@@ -327,16 +321,6 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
327 321
328 device_init_wakeup(&pdev->dev, 1); 322 device_init_wakeup(&pdev->dev, 1);
329 323
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
340 ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq, 324 ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq,
341 tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH, 325 tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH,
342 dev_name(&pdev->dev), &pdev->dev); 326 dev_name(&pdev->dev), &pdev->dev);
@@ -347,6 +331,13 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
347 goto disable_clk; 331 goto disable_clk;
348 } 332 }
349 333
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
350 dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n"); 341 dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n");
351 342
352 return 0; 343 return 0;
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 6c5f09c815e8..b298e9902f45 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -70,11 +70,11 @@ static int test_rtc_read_time(struct device *dev, struct rtc_time *tm)
70 return 0; 70 return 0;
71} 71}
72 72
73static int test_rtc_set_mmss64(struct device *dev, time64_t secs) 73static int test_rtc_set_time(struct device *dev, struct rtc_time *tm)
74{ 74{
75 struct rtc_test_data *rtd = dev_get_drvdata(dev); 75 struct rtc_test_data *rtd = dev_get_drvdata(dev);
76 76
77 rtd->offset = secs - ktime_get_real_seconds(); 77 rtd->offset = rtc_tm_to_time64(tm) - ktime_get_real_seconds();
78 78
79 return 0; 79 return 0;
80} 80}
@@ -94,15 +94,15 @@ static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
94 94
95static const struct rtc_class_ops test_rtc_ops_noalm = { 95static const struct rtc_class_ops test_rtc_ops_noalm = {
96 .read_time = test_rtc_read_time, 96 .read_time = test_rtc_read_time,
97 .set_mmss64 = test_rtc_set_mmss64, 97 .set_time = test_rtc_set_time,
98 .alarm_irq_enable = test_rtc_alarm_irq_enable, 98 .alarm_irq_enable = test_rtc_alarm_irq_enable,
99}; 99};
100 100
101static const struct rtc_class_ops test_rtc_ops = { 101static const struct rtc_class_ops test_rtc_ops = {
102 .read_time = test_rtc_read_time, 102 .read_time = test_rtc_read_time,
103 .set_time = test_rtc_set_time,
103 .read_alarm = test_rtc_read_alarm, 104 .read_alarm = test_rtc_read_alarm,
104 .set_alarm = test_rtc_set_alarm, 105 .set_alarm = test_rtc_set_alarm,
105 .set_mmss64 = test_rtc_set_mmss64,
106 .alarm_irq_enable = test_rtc_alarm_irq_enable, 106 .alarm_irq_enable = test_rtc_alarm_irq_enable,
107}; 107};
108 108
@@ -152,7 +152,8 @@ static int __init test_init(void)
152{ 152{
153 int i, err; 153 int i, err;
154 154
155 if ((err = platform_driver_register(&test_driver))) 155 err = platform_driver_register(&test_driver);
156 if (err)
156 return err; 157 return err;
157 158
158 err = -ENOMEM; 159 err = -ENOMEM;
diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index 2d24babc4057..5a29915a06ec 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -42,11 +42,6 @@ struct tx4939rtc_plat_data {
42 spinlock_t lock; 42 spinlock_t lock;
43}; 43};
44 44
45static struct tx4939rtc_plat_data *get_tx4939rtc_plat_data(struct device *dev)
46{
47 return platform_get_drvdata(to_platform_device(dev));
48}
49
50static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd) 45static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd)
51{ 46{
52 int i = 0; 47 int i = 0;
@@ -64,7 +59,7 @@ static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd)
64 59
65static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm) 60static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm)
66{ 61{
67 struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); 62 struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
68 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 63 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
69 unsigned long secs = rtc_tm_to_time64(tm); 64 unsigned long secs = rtc_tm_to_time64(tm);
70 int i, ret; 65 int i, ret;
@@ -89,7 +84,7 @@ static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm)
89 84
90static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm) 85static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm)
91{ 86{
92 struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); 87 struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
93 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 88 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
94 int i, ret; 89 int i, ret;
95 unsigned long sec; 90 unsigned long sec;
@@ -115,7 +110,7 @@ static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm)
115 110
116static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 111static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
117{ 112{
118 struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); 113 struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
119 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 114 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
120 int i, ret; 115 int i, ret;
121 unsigned long sec; 116 unsigned long sec;
@@ -140,7 +135,7 @@ static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
140 135
141static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 136static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
142{ 137{
143 struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); 138 struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
144 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 139 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
145 int i, ret; 140 int i, ret;
146 unsigned long sec; 141 unsigned long sec;
@@ -170,7 +165,7 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
170 165
171static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 166static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
172{ 167{
173 struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); 168 struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
174 169
175 spin_lock_irq(&pdata->lock); 170 spin_lock_irq(&pdata->lock);
176 tx4939_rtc_cmd(pdata->rtcreg, 171 tx4939_rtc_cmd(pdata->rtcreg,
@@ -182,7 +177,7 @@ static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
182 177
183static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id) 178static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id)
184{ 179{
185 struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev_id); 180 struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev_id);
186 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 181 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
187 unsigned long events = RTC_IRQF; 182 unsigned long events = RTC_IRQF;
188 183
diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
index 7b824dabf104..d2e8b21c90c4 100644
--- a/drivers/rtc/rtc-wm831x.c
+++ b/drivers/rtc/rtc-wm831x.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Real Time Clock driver for Wolfson Microelectronics WM831x 3 * Real Time Clock driver for Wolfson Microelectronics WM831x
3 * 4 *
@@ -5,11 +6,6 @@
5 * 6 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 * 8 *
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 */ 9 */
14 10
15#include <linux/module.h> 11#include <linux/module.h>
@@ -155,7 +151,7 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm)
155 if (memcmp(time1, time2, sizeof(time1)) == 0) { 151 if (memcmp(time1, time2, sizeof(time1)) == 0) {
156 u32 time = (time1[0] << 16) | time1[1]; 152 u32 time = (time1[0] << 16) | time1[1];
157 153
158 rtc_time_to_tm(time, tm); 154 rtc_time64_to_tm(time, tm);
159 return 0; 155 return 0;
160 } 156 }
161 157
@@ -169,15 +165,17 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm)
169/* 165/*
170 * Set current time and date in RTC 166 * Set current time and date in RTC
171 */ 167 */
172static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time) 168static int wm831x_rtc_settime(struct device *dev, struct rtc_time *tm)
173{ 169{
174 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev); 170 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
175 struct wm831x *wm831x = wm831x_rtc->wm831x; 171 struct wm831x *wm831x = wm831x_rtc->wm831x;
176 struct rtc_time new_tm; 172 struct rtc_time new_tm;
177 unsigned long new_time; 173 unsigned long time, new_time;
178 int ret; 174 int ret;
179 int count = 0; 175 int count = 0;
180 176
177 time = rtc_tm_to_time64(tm);
178
181 ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_1, 179 ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_1,
182 (time >> 16) & 0xffff); 180 (time >> 16) & 0xffff);
183 if (ret < 0) { 181 if (ret < 0) {
@@ -215,11 +213,7 @@ static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time)
215 if (ret < 0) 213 if (ret < 0)
216 return ret; 214 return ret;
217 215
218 ret = rtc_tm_to_time(&new_tm, &new_time); 216 new_time = rtc_tm_to_time64(&new_tm);
219 if (ret < 0) {
220 dev_err(dev, "Failed to convert time: %d\n", ret);
221 return ret;
222 }
223 217
224 /* Allow a second of change in case of tick */ 218 /* Allow a second of change in case of tick */
225 if (new_time - time > 1) { 219 if (new_time - time > 1) {
@@ -249,7 +243,7 @@ static int wm831x_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
249 243
250 time = (data[0] << 16) | data[1]; 244 time = (data[0] << 16) | data[1];
251 245
252 rtc_time_to_tm(time, &alrm->time); 246 rtc_time64_to_tm(time, &alrm->time);
253 247
254 ret = wm831x_reg_read(wm831x_rtc->wm831x, WM831X_RTC_CONTROL); 248 ret = wm831x_reg_read(wm831x_rtc->wm831x, WM831X_RTC_CONTROL);
255 if (ret < 0) { 249 if (ret < 0) {
@@ -288,11 +282,7 @@ static int wm831x_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
288 int ret; 282 int ret;
289 unsigned long time; 283 unsigned long time;
290 284
291 ret = rtc_tm_to_time(&alrm->time, &time); 285 time = rtc_tm_to_time64(&alrm->time);
292 if (ret < 0) {
293 dev_err(dev, "Failed to convert time: %d\n", ret);
294 return ret;
295 }
296 286
297 ret = wm831x_rtc_stop_alarm(wm831x_rtc); 287 ret = wm831x_rtc_stop_alarm(wm831x_rtc);
298 if (ret < 0) { 288 if (ret < 0) {
@@ -346,7 +336,7 @@ static irqreturn_t wm831x_alm_irq(int irq, void *data)
346 336
347static const struct rtc_class_ops wm831x_rtc_ops = { 337static const struct rtc_class_ops wm831x_rtc_ops = {
348 .read_time = wm831x_rtc_readtime, 338 .read_time = wm831x_rtc_readtime,
349 .set_mmss = wm831x_rtc_set_mmss, 339 .set_time = wm831x_rtc_settime,
350 .read_alarm = wm831x_rtc_readalarm, 340 .read_alarm = wm831x_rtc_readalarm,
351 .set_alarm = wm831x_rtc_setalarm, 341 .set_alarm = wm831x_rtc_setalarm,
352 .alarm_irq_enable = wm831x_rtc_alarm_irq_enable, 342 .alarm_irq_enable = wm831x_rtc_alarm_irq_enable,
@@ -356,11 +346,10 @@ static const struct rtc_class_ops wm831x_rtc_ops = {
356/* Turn off the alarm if it should not be a wake source. */ 346/* Turn off the alarm if it should not be a wake source. */
357static int wm831x_rtc_suspend(struct device *dev) 347static int wm831x_rtc_suspend(struct device *dev)
358{ 348{
359 struct platform_device *pdev = to_platform_device(dev); 349 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
360 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
361 int ret, enable; 350 int ret, enable;
362 351
363 if (wm831x_rtc->alarm_enabled && device_may_wakeup(&pdev->dev)) 352 if (wm831x_rtc->alarm_enabled && device_may_wakeup(dev))
364 enable = WM831X_RTC_ALM_ENA; 353 enable = WM831X_RTC_ALM_ENA;
365 else 354 else
366 enable = 0; 355 enable = 0;
@@ -368,7 +357,7 @@ static int wm831x_rtc_suspend(struct device *dev)
368 ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL, 357 ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL,
369 WM831X_RTC_ALM_ENA, enable); 358 WM831X_RTC_ALM_ENA, enable);
370 if (ret != 0) 359 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);
372 361
373 return 0; 362 return 0;
374} 363}
@@ -378,15 +367,13 @@ static int wm831x_rtc_suspend(struct device *dev)
378 */ 367 */
379static int wm831x_rtc_resume(struct device *dev) 368static int wm831x_rtc_resume(struct device *dev)
380{ 369{
381 struct platform_device *pdev = to_platform_device(dev); 370 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
382 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
383 int ret; 371 int ret;
384 372
385 if (wm831x_rtc->alarm_enabled) { 373 if (wm831x_rtc->alarm_enabled) {
386 ret = wm831x_rtc_start_alarm(wm831x_rtc); 374 ret = wm831x_rtc_start_alarm(wm831x_rtc);
387 if (ret != 0) 375 if (ret != 0)
388 dev_err(&pdev->dev, 376 dev_err(dev, "Failed to restart RTC alarm: %d\n", ret);
389 "Failed to restart RTC alarm: %d\n", ret);
390 } 377 }
391 378
392 return 0; 379 return 0;
@@ -395,14 +382,13 @@ static int wm831x_rtc_resume(struct device *dev)
395/* Unconditionally disable the alarm */ 382/* Unconditionally disable the alarm */
396static int wm831x_rtc_freeze(struct device *dev) 383static int wm831x_rtc_freeze(struct device *dev)
397{ 384{
398 struct platform_device *pdev = to_platform_device(dev); 385 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
399 struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
400 int ret; 386 int ret;
401 387
402 ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL, 388 ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL,
403 WM831X_RTC_ALM_ENA, 0); 389 WM831X_RTC_ALM_ENA, 0);
404 if (ret != 0) 390 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);
406 392
407 return 0; 393 return 0;
408} 394}
@@ -429,19 +415,23 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
429 ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL); 415 ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL);
430 if (ret < 0) { 416 if (ret < 0) {
431 dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret); 417 dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret);
432 goto err; 418 return ret;
433 } 419 }
434 if (ret & WM831X_RTC_ALM_ENA) 420 if (ret & WM831X_RTC_ALM_ENA)
435 wm831x_rtc->alarm_enabled = 1; 421 wm831x_rtc->alarm_enabled = 1;
436 422
437 device_init_wakeup(&pdev->dev, 1); 423 device_init_wakeup(&pdev->dev, 1);
438 424
439 wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x", 425 wm831x_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
440 &wm831x_rtc_ops, THIS_MODULE); 426 if (IS_ERR(wm831x_rtc->rtc))
441 if (IS_ERR(wm831x_rtc->rtc)) { 427 return PTR_ERR(wm831x_rtc->rtc);
442 ret = PTR_ERR(wm831x_rtc->rtc); 428
443 goto err; 429 wm831x_rtc->rtc->ops = &wm831x_rtc_ops;
444 } 430 wm831x_rtc->rtc->range_max = U32_MAX;
431
432 ret = rtc_register_device(wm831x_rtc->rtc);
433 if (ret)
434 return ret;
445 435
446 ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL, 436 ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL,
447 wm831x_alm_irq, 437 wm831x_alm_irq,
@@ -455,9 +445,6 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
455 wm831x_rtc_add_randomness(wm831x); 445 wm831x_rtc_add_randomness(wm831x);
456 446
457 return 0; 447 return 0;
458
459err:
460 return ret;
461} 448}
462 449
463static const struct dev_pm_ops wm831x_rtc_pm_ops = { 450static const struct dev_pm_ops wm831x_rtc_pm_ops = {
diff --git a/drivers/rtc/rtc-wm8350.c b/drivers/rtc/rtc-wm8350.c
index 483c7993516b..f54fa12c4b4b 100644
--- a/drivers/rtc/rtc-wm8350.c
+++ b/drivers/rtc/rtc-wm8350.c
@@ -340,8 +340,7 @@ static const struct rtc_class_ops wm8350_rtc_ops = {
340#ifdef CONFIG_PM_SLEEP 340#ifdef CONFIG_PM_SLEEP
341static int wm8350_rtc_suspend(struct device *dev) 341static int wm8350_rtc_suspend(struct device *dev)
342{ 342{
343 struct platform_device *pdev = to_platform_device(dev); 343 struct wm8350 *wm8350 = dev_get_drvdata(dev);
344 struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
345 int ret = 0; 344 int ret = 0;
346 u16 reg; 345 u16 reg;
347 346
@@ -351,8 +350,7 @@ static int wm8350_rtc_suspend(struct device *dev)
351 reg & WM8350_RTC_ALMSTS) { 350 reg & WM8350_RTC_ALMSTS) {
352 ret = wm8350_rtc_stop_alarm(wm8350); 351 ret = wm8350_rtc_stop_alarm(wm8350);
353 if (ret != 0) 352 if (ret != 0)
354 dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n", 353 dev_err(dev, "Failed to stop RTC alarm: %d\n", ret);
355 ret);
356 } 354 }
357 355
358 return ret; 356 return ret;
@@ -360,15 +358,13 @@ static int wm8350_rtc_suspend(struct device *dev)
360 358
361static int wm8350_rtc_resume(struct device *dev) 359static int wm8350_rtc_resume(struct device *dev)
362{ 360{
363 struct platform_device *pdev = to_platform_device(dev); 361 struct wm8350 *wm8350 = dev_get_drvdata(dev);
364 struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
365 int ret; 362 int ret;
366 363
367 if (wm8350->rtc.alarm_enabled) { 364 if (wm8350->rtc.alarm_enabled) {
368 ret = wm8350_rtc_start_alarm(wm8350); 365 ret = wm8350_rtc_start_alarm(wm8350);
369 if (ret != 0) 366 if (ret != 0)
370 dev_err(&pdev->dev, 367 dev_err(dev, "Failed to restart RTC alarm: %d\n", ret);
371 "Failed to restart RTC alarm: %d\n", ret);
372 } 368 }
373 369
374 return 0; 370 return 0;
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index f08f18e4fcdf..ad2ae2f0536e 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -673,9 +673,16 @@ static const struct i2c_device_id x1205_id[] = {
673}; 673};
674MODULE_DEVICE_TABLE(i2c, x1205_id); 674MODULE_DEVICE_TABLE(i2c, x1205_id);
675 675
676static const struct of_device_id x1205_dt_ids[] = {
677 { .compatible = "xircom,x1205", },
678 {},
679};
680MODULE_DEVICE_TABLE(of, x1205_dt_ids);
681
676static struct i2c_driver x1205_driver = { 682static struct i2c_driver x1205_driver = {
677 .driver = { 683 .driver = {
678 .name = "rtc-x1205", 684 .name = "rtc-x1205",
685 .of_match_table = x1205_dt_ids,
679 }, 686 },
680 .probe = x1205_probe, 687 .probe = x1205_probe,
681 .remove = x1205_remove, 688 .remove = x1205_remove,
diff --git a/drivers/rtc/rtc-xgene.c b/drivers/rtc/rtc-xgene.c
index 153820876a82..9888383f0088 100644
--- a/drivers/rtc/rtc-xgene.c
+++ b/drivers/rtc/rtc-xgene.c
@@ -1,34 +1,21 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * APM X-Gene SoC Real Time Clock Driver 3 * APM X-Gene SoC Real Time Clock Driver
3 * 4 *
4 * Copyright (c) 2014, Applied Micro Circuits Corporation 5 * Copyright (c) 2014, Applied Micro Circuits Corporation
5 * Author: Rameshwar Prasad Sahu <rsahu@apm.com> 6 * Author: Rameshwar Prasad Sahu <rsahu@apm.com>
6 * Loc Ho <lho@apm.com> 7 * 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 *
21 */ 8 */
22 9
10#include <linux/clk.h>
11#include <linux/delay.h>
23#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/io.h>
24#include <linux/module.h> 14#include <linux/module.h>
25#include <linux/of.h> 15#include <linux/of.h>
26#include <linux/platform_device.h> 16#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>
31#include <linux/rtc.h> 17#include <linux/rtc.h>
18#include <linux/slab.h>
32 19
33/* RTC CSR Registers */ 20/* RTC CSR Registers */
34#define RTC_CCVR 0x00 21#define RTC_CCVR 0x00
@@ -48,7 +35,6 @@
48struct xgene_rtc_dev { 35struct xgene_rtc_dev {
49 struct rtc_device *rtc; 36 struct rtc_device *rtc;
50 struct device *dev; 37 struct device *dev;
51 unsigned long alarm_time;
52 void __iomem *csr_base; 38 void __iomem *csr_base;
53 struct clk *clk; 39 struct clk *clk;
54 unsigned int irq_wake; 40 unsigned int irq_wake;
@@ -59,11 +45,11 @@ static int xgene_rtc_read_time(struct device *dev, struct rtc_time *tm)
59{ 45{
60 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); 46 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
61 47
62 rtc_time_to_tm(readl(pdata->csr_base + RTC_CCVR), tm); 48 rtc_time64_to_tm(readl(pdata->csr_base + RTC_CCVR), tm);
63 return 0; 49 return 0;
64} 50}
65 51
66static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs) 52static int xgene_rtc_set_time(struct device *dev, struct rtc_time *tm)
67{ 53{
68 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); 54 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
69 55
@@ -71,7 +57,7 @@ static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs)
71 * NOTE: After the following write, the RTC_CCVR is only reflected 57 * NOTE: After the following write, the RTC_CCVR is only reflected
72 * after the update cycle of 1 seconds. 58 * after the update cycle of 1 seconds.
73 */ 59 */
74 writel((u32) secs, pdata->csr_base + RTC_CLR); 60 writel((u32)rtc_tm_to_time64(tm), pdata->csr_base + RTC_CLR);
75 readl(pdata->csr_base + RTC_CLR); /* Force a barrier */ 61 readl(pdata->csr_base + RTC_CLR); /* Force a barrier */
76 62
77 return 0; 63 return 0;
@@ -81,7 +67,8 @@ static int xgene_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
81{ 67{
82 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); 68 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
83 69
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);
85 alrm->enabled = readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE; 72 alrm->enabled = readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE;
86 73
87 return 0; 74 return 0;
@@ -115,11 +102,8 @@ static int xgene_rtc_alarm_irq_enabled(struct device *dev)
115static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 102static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
116{ 103{
117 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); 104 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
118 unsigned long alarm_time;
119 105
120 rtc_tm_to_time(&alrm->time, &alarm_time); 106 writel((u32)rtc_tm_to_time64(&alrm->time), pdata->csr_base + RTC_CMR);
121 pdata->alarm_time = alarm_time;
122 writel((u32) pdata->alarm_time, pdata->csr_base + RTC_CMR);
123 107
124 xgene_rtc_alarm_irq_enable(dev, alrm->enabled); 108 xgene_rtc_alarm_irq_enable(dev, alrm->enabled);
125 109
@@ -128,7 +112,7 @@ static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
128 112
129static const struct rtc_class_ops xgene_rtc_ops = { 113static const struct rtc_class_ops xgene_rtc_ops = {
130 .read_time = xgene_rtc_read_time, 114 .read_time = xgene_rtc_read_time,
131 .set_mmss = xgene_rtc_set_mmss, 115 .set_time = xgene_rtc_set_time,
132 .read_alarm = xgene_rtc_read_alarm, 116 .read_alarm = xgene_rtc_read_alarm,
133 .set_alarm = xgene_rtc_set_alarm, 117 .set_alarm = xgene_rtc_set_alarm,
134 .alarm_irq_enable = xgene_rtc_alarm_irq_enable, 118 .alarm_irq_enable = xgene_rtc_alarm_irq_enable,
@@ -136,7 +120,7 @@ static const struct rtc_class_ops xgene_rtc_ops = {
136 120
137static irqreturn_t xgene_rtc_interrupt(int irq, void *id) 121static irqreturn_t xgene_rtc_interrupt(int irq, void *id)
138{ 122{
139 struct xgene_rtc_dev *pdata = (struct xgene_rtc_dev *) id; 123 struct xgene_rtc_dev *pdata = id;
140 124
141 /* Check if interrupt asserted */ 125 /* Check if interrupt asserted */
142 if (!(readl(pdata->csr_base + RTC_STAT) & RTC_STAT_BIT)) 126 if (!(readl(pdata->csr_base + RTC_STAT) & RTC_STAT_BIT))
@@ -168,6 +152,10 @@ static int xgene_rtc_probe(struct platform_device *pdev)
168 if (IS_ERR(pdata->csr_base)) 152 if (IS_ERR(pdata->csr_base))
169 return PTR_ERR(pdata->csr_base); 153 return PTR_ERR(pdata->csr_base);
170 154
155 pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
156 if (IS_ERR(pdata->rtc))
157 return PTR_ERR(pdata->rtc);
158
171 irq = platform_get_irq(pdev, 0); 159 irq = platform_get_irq(pdev, 0);
172 if (irq < 0) { 160 if (irq < 0) {
173 dev_err(&pdev->dev, "No IRQ resource\n"); 161 dev_err(&pdev->dev, "No IRQ resource\n");
@@ -198,15 +186,16 @@ static int xgene_rtc_probe(struct platform_device *pdev)
198 return ret; 186 return ret;
199 } 187 }
200 188
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
208 /* HW does not support update faster than 1 seconds */ 189 /* HW does not support update faster than 1 seconds */
209 pdata->rtc->uie_unsupported = 1; 190 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 }
210 199
211 return 0; 200 return 0;
212} 201}
diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c
index bb950945ec7f..00639594de0c 100644
--- a/drivers/rtc/rtc-zynqmp.c
+++ b/drivers/rtc/rtc-zynqmp.c
@@ -1,20 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Xilinx Zynq Ultrascale+ MPSoC Real Time Clock Driver 3 * Xilinx Zynq Ultrascale+ MPSoC Real Time Clock Driver
3 * 4 *
4 * Copyright (C) 2015 Xilinx, Inc. 5 * Copyright (C) 2015 Xilinx, Inc.
5 * 6 *
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 *
18 */ 7 */
19 8
20#include <linux/delay.h> 9#include <linux/delay.h>
diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c
index a8f22ee726bb..be3531e7f868 100644
--- a/drivers/rtc/sysfs.c
+++ b/drivers/rtc/sysfs.c
@@ -1,20 +1,16 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * RTC subsystem, sysfs interface 3 * RTC subsystem, sysfs interface
3 * 4 *
4 * Copyright (C) 2005 Tower Technologies 5 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 7 */
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*/
11 8
12#include <linux/module.h> 9#include <linux/module.h>
13#include <linux/rtc.h> 10#include <linux/rtc.h>
14 11
15#include "rtc-core.h" 12#include "rtc-core.h"
16 13
17
18/* device attributes */ 14/* device attributes */
19 15
20/* 16/*
@@ -86,7 +82,7 @@ max_user_freq_show(struct device *dev, struct device_attribute *attr, char *buf)
86 82
87static ssize_t 83static ssize_t
88max_user_freq_store(struct device *dev, struct device_attribute *attr, 84max_user_freq_store(struct device *dev, struct device_attribute *attr,
89 const char *buf, size_t n) 85 const char *buf, size_t n)
90{ 86{
91 struct rtc_device *rtc = to_rtc_device(dev); 87 struct rtc_device *rtc = to_rtc_device(dev);
92 unsigned long val; 88 unsigned long val;
@@ -116,12 +112,11 @@ hctosys_show(struct device *dev, struct device_attribute *attr, char *buf)
116{ 112{
117#ifdef CONFIG_RTC_HCTOSYS_DEVICE 113#ifdef CONFIG_RTC_HCTOSYS_DEVICE
118 if (rtc_hctosys_ret == 0 && 114 if (rtc_hctosys_ret == 0 &&
119 strcmp(dev_name(&to_rtc_device(dev)->dev), 115 strcmp(dev_name(&to_rtc_device(dev)->dev),
120 CONFIG_RTC_HCTOSYS_DEVICE) == 0) 116 CONFIG_RTC_HCTOSYS_DEVICE) == 0)
121 return sprintf(buf, "1\n"); 117 return sprintf(buf, "1\n");
122 else
123#endif 118#endif
124 return sprintf(buf, "0\n"); 119 return sprintf(buf, "0\n");
125} 120}
126static DEVICE_ATTR_RO(hctosys); 121static DEVICE_ATTR_RO(hctosys);
127 122
@@ -175,15 +170,15 @@ wakealarm_store(struct device *dev, struct device_attribute *attr,
175 if (*buf_ptr == '=') { 170 if (*buf_ptr == '=') {
176 buf_ptr++; 171 buf_ptr++;
177 push = 1; 172 push = 1;
178 } else 173 } else {
179 adjust = 1; 174 adjust = 1;
175 }
180 } 176 }
181 retval = kstrtos64(buf_ptr, 0, &alarm); 177 retval = kstrtos64(buf_ptr, 0, &alarm);
182 if (retval) 178 if (retval)
183 return retval; 179 return retval;
184 if (adjust) { 180 if (adjust)
185 alarm += now; 181 alarm += now;
186 }
187 if (alarm > now || push) { 182 if (alarm > now || push) {
188 /* Avoid accidentally clobbering active alarms; we can't 183 /* Avoid accidentally clobbering active alarms; we can't
189 * entirely prevent that here, without even the minimal 184 * entirely prevent that here, without even the minimal
diff --git a/drivers/rtc/systohc.c b/drivers/rtc/systohc.c
index 718293d72426..8b70f0520e13 100644
--- a/drivers/rtc/systohc.c
+++ b/drivers/rtc/systohc.c
@@ -1,9 +1,4 @@
1/* 1// SPDX-License-Identifier: GPL-2.0
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 */
7#include <linux/rtc.h> 2#include <linux/rtc.h>
8#include <linux/time.h> 3#include <linux/time.h>
9 4
@@ -35,8 +30,7 @@ int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec)
35 if (!rtc) 30 if (!rtc)
36 goto out_err; 31 goto out_err;
37 32
38 if (!rtc->ops || (!rtc->ops->set_time && !rtc->ops->set_mmss64 && 33 if (!rtc->ops || !rtc->ops->set_time)
39 !rtc->ops->set_mmss))
40 goto out_close; 34 goto out_close;
41 35
42 /* Compute the value of tv_nsec we require the caller to supply in 36 /* 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)
58 52
59 rtc_time64_to_tm(to_set.tv_sec, &tm); 53 rtc_time64_to_tm(to_set.tv_sec, &tm);
60 54
61 /* rtc_hctosys exclusively uses UTC, so we call set_time here, not
62 * set_mmss.
63 */
64 err = rtc_set_time(rtc, &tm); 55 err = rtc_set_time(rtc, &tm);
65 56
66out_close: 57out_close:
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index f89bfbb54902..df666cf29ef1 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -79,8 +79,6 @@ struct rtc_class_ops {
79 int (*read_alarm)(struct device *, struct rtc_wkalrm *); 79 int (*read_alarm)(struct device *, struct rtc_wkalrm *);
80 int (*set_alarm)(struct device *, struct rtc_wkalrm *); 80 int (*set_alarm)(struct device *, struct rtc_wkalrm *);
81 int (*proc)(struct device *, struct seq_file *); 81 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);
84 int (*alarm_irq_enable)(struct device *, unsigned int enabled); 82 int (*alarm_irq_enable)(struct device *, unsigned int enabled);
85 int (*read_offset)(struct device *, long *offset); 83 int (*read_offset)(struct device *, long *offset);
86 int (*set_offset)(struct device *, long offset); 84 int (*set_offset)(struct device *, long offset);
@@ -162,9 +160,11 @@ struct rtc_device {
162#define to_rtc_device(d) container_of(d, struct rtc_device, dev) 160#define to_rtc_device(d) container_of(d, struct rtc_device, dev)
163 161
164/* useful timestamps */ 162/* 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 */
166#define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */ 164#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 */
167#define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */ 166#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 */
168 168
169extern struct rtc_device *devm_rtc_device_register(struct device *dev, 169extern struct rtc_device *devm_rtc_device_register(struct device *dev,
170 const char *name, 170 const char *name,
diff --git a/include/linux/rtc/ds1685.h b/include/linux/rtc/ds1685.h
index e6337a56d741..a00b332c505f 100644
--- a/include/linux/rtc/ds1685.h
+++ b/include/linux/rtc/ds1685.h
@@ -48,8 +48,6 @@ struct ds1685_priv {
48 u32 regstep; 48 u32 regstep;
49 resource_size_t baseaddr; 49 resource_size_t baseaddr;
50 size_t size; 50 size_t size;
51 spinlock_t lock;
52 struct work_struct work;
53 int irq_num; 51 int irq_num;
54 bool bcd_mode; 52 bool bcd_mode;
55 bool no_irq; 53 bool no_irq;