diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-06-10 19:13:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-06-10 19:13:24 -0400 |
commit | 1aaccb5fa0eac996adde53538ca4b87a0b229ab7 (patch) | |
tree | 3d00406e38ca168ef6c23c3e1c8f4809e8983d20 | |
parent | ab0b2e59323cd3972e5f011fbbf3868a4ec360dd (diff) | |
parent | e4302aec8a0646828a701443e303eb5ef48b37f5 (diff) |
Merge tag 'rtc-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni:
"Setting the supported range from drivers for RTCs failing soon has
started. A few fixes are developed along the way. Some drivers have
been switched to SPDX by their maintainers.
Subsystem:
- rework of the rtc-test driver which allows to test the core more
thoroughly
- rtc_set_alarm() now fails early when alarms are not supported
Drivers:
- mktime() is now replaced by mktime64()
- RTC range added for 88pm80x, ab-b5ze-s3, at91rm9200,
brcmstb-waketimer, ds1685, ftrtc010, ls1x, mxc_v2, rx8581, sprd,
st-lpc, tps6586x, tps65910 and vr41xx
- fixed a possible race condition in probe functions
- pxa: fix the probe function that is broken since v4.3
- stm32: now supports stm32mp1"
* tag 'rtc-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (78 commits)
rtc: pxa: fix probe function
rtc: cros-ec: Switch to SPDX identifier.
rtc: cros-ec: Make license text and module license match.
rtc: ensure rtc_set_alarm fails when alarms are not supported
rtc: test: remove alarm support from the first device
rtc: test: convert to devm_rtc_allocate_device
rtc: ftrtc010: let the core handle range
rtc: ftrtc010: handle dates after 2106
rtc: ftrtc010: switch to devm_rtc_allocate_device
rtc: mrst: switch to devm functions
rtc: sunxi: fix possible race condition
rtc: test: remove irq sysfs file
rtc: test: emulate alarms using timers
rtc: test: store time as an offset to system time
rtc: test: allow registering many devices
rtc: test: remove useless proc info
rtc: ds1685: Add range
rtc: ds1685: fix possible race condition
rtc: sprd: Add new RTC power down check method
rtc: sun6i: Fix bit_idx value for clk_register_gate
...
43 files changed, 904 insertions, 841 deletions
diff --git a/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt b/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt index 5cbc0b145a61..811124a36d16 100644 --- a/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt +++ b/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt | |||
@@ -9,7 +9,7 @@ Optional properties: | |||
9 | 9 | ||
10 | Example: | 10 | Example: |
11 | 11 | ||
12 | rtc: nxp,rtc-pcf2123@3 { | 12 | pcf2123: rtc@3 { |
13 | compatible = "nxp,rtc-pcf2123" | 13 | compatible = "nxp,rtc-pcf2123" |
14 | reg = <3> | 14 | reg = <3> |
15 | spi-cs-high; | 15 | spi-cs-high; |
diff --git a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.txt b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.txt index a66692a08ace..c920e2736991 100644 --- a/Documentation/devicetree/bindings/rtc/st,stm32-rtc.txt +++ b/Documentation/devicetree/bindings/rtc/st,stm32-rtc.txt | |||
@@ -1,23 +1,29 @@ | |||
1 | STM32 Real Time Clock | 1 | STM32 Real Time Clock |
2 | 2 | ||
3 | Required properties: | 3 | Required properties: |
4 | - compatible: can be either "st,stm32-rtc" or "st,stm32h7-rtc", depending on | 4 | - compatible: can be one of the following: |
5 | the device is compatible with stm32(f4/f7) or stm32h7. | 5 | - "st,stm32-rtc" for devices compatible with stm32(f4/f7). |
6 | - "st,stm32h7-rtc" for devices compatible with stm32h7. | ||
7 | - "st,stm32mp1-rtc" for devices compatible with stm32mp1. | ||
6 | - reg: address range of rtc register set. | 8 | - reg: address range of rtc register set. |
7 | - clocks: can use up to two clocks, depending on part used: | 9 | - clocks: can use up to two clocks, depending on part used: |
8 | - "rtc_ck": RTC clock source. | 10 | - "rtc_ck": RTC clock source. |
9 | It is required on stm32(f4/f7) and stm32h7. | ||
10 | - "pclk": RTC APB interface clock. | 11 | - "pclk": RTC APB interface clock. |
11 | It is not present on stm32(f4/f7). | 12 | It is not present on stm32(f4/f7). |
12 | It is required on stm32h7. | 13 | It is required on stm32(h7/mp1). |
13 | - clock-names: must be "rtc_ck" and "pclk". | 14 | - clock-names: must be "rtc_ck" and "pclk". |
14 | It is required only on stm32h7. | 15 | It is required on stm32(h7/mp1). |
15 | - interrupt-parent: phandle for the interrupt controller. | 16 | - interrupt-parent: phandle for the interrupt controller. |
16 | - interrupts: rtc alarm interrupt. | 17 | It is required on stm32(f4/f7/h7). |
17 | - st,syscfg: phandle for pwrcfg, mandatory to disable/enable backup domain | 18 | - interrupts: rtc alarm interrupt. On stm32mp1, a second interrupt is required |
18 | (RTC registers) write protection. | 19 | for rtc alarm wakeup interrupt. |
20 | - st,syscfg: phandle/offset/mask triplet. The phandle to pwrcfg used to | ||
21 | access control register at offset, and change the dbp (Disable Backup | ||
22 | Protection) bit represented by the mask, mandatory to disable/enable backup | ||
23 | domain (RTC registers) write protection. | ||
24 | It is required on stm32(f4/f7/h7). | ||
19 | 25 | ||
20 | Optional properties (to override default rtc_ck parent clock): | 26 | Optional properties (to override default rtc_ck parent clock on stm32(f4/f7/h7): |
21 | - assigned-clocks: reference to the rtc_ck clock entry. | 27 | - assigned-clocks: reference to the rtc_ck clock entry. |
22 | - assigned-clock-parents: phandle of the new parent clock of rtc_ck. | 28 | - assigned-clock-parents: phandle of the new parent clock of rtc_ck. |
23 | 29 | ||
@@ -31,7 +37,7 @@ Example: | |||
31 | assigned-clock-parents = <&rcc 1 CLK_LSE>; | 37 | assigned-clock-parents = <&rcc 1 CLK_LSE>; |
32 | interrupt-parent = <&exti>; | 38 | interrupt-parent = <&exti>; |
33 | interrupts = <17 1>; | 39 | interrupts = <17 1>; |
34 | st,syscfg = <&pwrcfg>; | 40 | st,syscfg = <&pwrcfg 0x00 0x100>; |
35 | }; | 41 | }; |
36 | 42 | ||
37 | rtc: rtc@58004000 { | 43 | rtc: rtc@58004000 { |
@@ -44,5 +50,14 @@ Example: | |||
44 | interrupt-parent = <&exti>; | 50 | interrupt-parent = <&exti>; |
45 | interrupts = <17 1>; | 51 | interrupts = <17 1>; |
46 | interrupt-names = "alarm"; | 52 | interrupt-names = "alarm"; |
47 | st,syscfg = <&pwrcfg>; | 53 | st,syscfg = <&pwrcfg 0x00 0x100>; |
54 | }; | ||
55 | |||
56 | rtc: rtc@5c004000 { | ||
57 | compatible = "st,stm32mp1-rtc"; | ||
58 | reg = <0x5c004000 0x400>; | ||
59 | clocks = <&rcc RTCAPB>, <&rcc RTC>; | ||
60 | clock-names = "pclk", "rtc_ck"; | ||
61 | interrupts-extended = <&intc GIC_SPI 3 IRQ_TYPE_NONE>, | ||
62 | <&exti 19 1>; | ||
48 | }; | 63 | }; |
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 59e6dede3db3..a2ba5db36145 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -1613,7 +1613,7 @@ config RTC_DRV_JZ4740 | |||
1613 | If you say yes here you get support for the Ingenic JZ47xx SoCs RTC | 1613 | If you say yes here you get support for the Ingenic JZ47xx SoCs RTC |
1614 | controllers. | 1614 | controllers. |
1615 | 1615 | ||
1616 | This driver can also be buillt as a module. If so, the module | 1616 | This driver can also be built as a module. If so, the module |
1617 | will be called rtc-jz4740. | 1617 | will be called rtc-jz4740. |
1618 | 1618 | ||
1619 | config RTC_DRV_LPC24XX | 1619 | config RTC_DRV_LPC24XX |
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 7cbdc9228dd5..6d4012dd6922 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c | |||
@@ -441,6 +441,11 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
441 | { | 441 | { |
442 | int err; | 442 | int err; |
443 | 443 | ||
444 | if (!rtc->ops) | ||
445 | return -ENODEV; | ||
446 | else if (!rtc->ops->set_alarm) | ||
447 | return -EINVAL; | ||
448 | |||
444 | err = rtc_valid_tm(&alarm->time); | 449 | err = rtc_valid_tm(&alarm->time); |
445 | if (err != 0) | 450 | if (err != 0) |
446 | return err; | 451 | return err; |
diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c index 17ec4c8d0fad..36ab183c42f1 100644 --- a/drivers/rtc/nvmem.c +++ b/drivers/rtc/nvmem.c | |||
@@ -94,7 +94,7 @@ int rtc_nvmem_register(struct rtc_device *rtc, | |||
94 | nvmem_config->dev = rtc->dev.parent; | 94 | nvmem_config->dev = rtc->dev.parent; |
95 | nvmem_config->owner = rtc->owner; | 95 | nvmem_config->owner = rtc->owner; |
96 | rtc->nvmem = nvmem_register(nvmem_config); | 96 | rtc->nvmem = nvmem_register(nvmem_config); |
97 | if (IS_ERR_OR_NULL(rtc->nvmem)) | 97 | if (IS_ERR(rtc->nvmem)) |
98 | return PTR_ERR(rtc->nvmem); | 98 | return PTR_ERR(rtc->nvmem); |
99 | 99 | ||
100 | /* Register the old ABI */ | 100 | /* Register the old ABI */ |
diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c index 6cbafefa80a2..cab293cb2bf0 100644 --- a/drivers/rtc/rtc-88pm80x.c +++ b/drivers/rtc/rtc-88pm80x.c | |||
@@ -52,10 +52,8 @@ struct pm80x_rtc_info { | |||
52 | struct regmap *map; | 52 | struct regmap *map; |
53 | struct rtc_device *rtc_dev; | 53 | struct rtc_device *rtc_dev; |
54 | struct device *dev; | 54 | struct device *dev; |
55 | struct delayed_work calib_work; | ||
56 | 55 | ||
57 | int irq; | 56 | int irq; |
58 | int vrtc; | ||
59 | }; | 57 | }; |
60 | 58 | ||
61 | static irqreturn_t rtc_update_handler(int irq, void *data) | 59 | static irqreturn_t rtc_update_handler(int irq, void *data) |
@@ -100,13 +98,13 @@ static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, | |||
100 | next->tm_min = alrm->tm_min; | 98 | next->tm_min = alrm->tm_min; |
101 | next->tm_sec = alrm->tm_sec; | 99 | next->tm_sec = alrm->tm_sec; |
102 | 100 | ||
103 | rtc_tm_to_time(now, &now_time); | 101 | now_time = rtc_tm_to_time64(now); |
104 | rtc_tm_to_time(next, &next_time); | 102 | next_time = rtc_tm_to_time64(next); |
105 | 103 | ||
106 | if (next_time < now_time) { | 104 | if (next_time < now_time) { |
107 | /* Advance one day */ | 105 | /* Advance one day */ |
108 | next_time += 60 * 60 * 24; | 106 | next_time += 60 * 60 * 24; |
109 | rtc_time_to_tm(next_time, next); | 107 | rtc_time64_to_tm(next_time, next); |
110 | } | 108 | } |
111 | } | 109 | } |
112 | 110 | ||
@@ -125,7 +123,7 @@ static int pm80x_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
125 | ticks = base + data; | 123 | ticks = base + data; |
126 | dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", | 124 | dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", |
127 | base, data, ticks); | 125 | base, data, ticks); |
128 | rtc_time_to_tm(ticks, tm); | 126 | rtc_time64_to_tm(ticks, tm); |
129 | return 0; | 127 | return 0; |
130 | } | 128 | } |
131 | 129 | ||
@@ -134,13 +132,8 @@ static int pm80x_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
134 | struct pm80x_rtc_info *info = dev_get_drvdata(dev); | 132 | struct pm80x_rtc_info *info = dev_get_drvdata(dev); |
135 | unsigned char buf[4]; | 133 | unsigned char buf[4]; |
136 | unsigned long ticks, base, data; | 134 | unsigned long ticks, base, data; |
137 | if (tm->tm_year > 206) { | 135 | |
138 | dev_dbg(info->dev, | 136 | ticks = rtc_tm_to_time64(tm); |
139 | "Set time %d out of range. Please set time between 1970 to 2106.\n", | ||
140 | 1900 + tm->tm_year); | ||
141 | return -EINVAL; | ||
142 | } | ||
143 | rtc_tm_to_time(tm, &ticks); | ||
144 | 137 | ||
145 | /* load 32-bit read-only counter */ | 138 | /* load 32-bit read-only counter */ |
146 | regmap_raw_read(info->map, PM800_RTC_COUNTER1, buf, 4); | 139 | regmap_raw_read(info->map, PM800_RTC_COUNTER1, buf, 4); |
@@ -174,7 +167,7 @@ static int pm80x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
174 | dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", | 167 | dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", |
175 | base, data, ticks); | 168 | base, data, ticks); |
176 | 169 | ||
177 | rtc_time_to_tm(ticks, &alrm->time); | 170 | rtc_time64_to_tm(ticks, &alrm->time); |
178 | regmap_read(info->map, PM800_RTC_CONTROL, &ret); | 171 | regmap_read(info->map, PM800_RTC_CONTROL, &ret); |
179 | alrm->enabled = (ret & PM800_ALARM1_EN) ? 1 : 0; | 172 | alrm->enabled = (ret & PM800_ALARM1_EN) ? 1 : 0; |
180 | alrm->pending = (ret & (PM800_ALARM | PM800_ALARM_WAKEUP)) ? 1 : 0; | 173 | alrm->pending = (ret & (PM800_ALARM | PM800_ALARM_WAKEUP)) ? 1 : 0; |
@@ -202,11 +195,11 @@ static int pm80x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
202 | dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", | 195 | dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", |
203 | base, data, ticks); | 196 | base, data, ticks); |
204 | 197 | ||
205 | rtc_time_to_tm(ticks, &now_tm); | 198 | rtc_time64_to_tm(ticks, &now_tm); |
206 | dev_dbg(info->dev, "%s, now time : %lu\n", __func__, ticks); | 199 | dev_dbg(info->dev, "%s, now time : %lu\n", __func__, ticks); |
207 | rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time); | 200 | rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time); |
208 | /* get new ticks for alarm in 24 hours */ | 201 | /* get new ticks for alarm in 24 hours */ |
209 | rtc_tm_to_time(&alarm_tm, &ticks); | 202 | ticks = rtc_tm_to_time64(&alarm_tm); |
210 | dev_dbg(info->dev, "%s, alarm time: %lu\n", __func__, ticks); | 203 | dev_dbg(info->dev, "%s, alarm time: %lu\n", __func__, ticks); |
211 | data = ticks - base; | 204 | data = ticks - base; |
212 | 205 | ||
@@ -254,8 +247,6 @@ static int pm80x_rtc_probe(struct platform_device *pdev) | |||
254 | struct pm80x_rtc_pdata *pdata = dev_get_platdata(&pdev->dev); | 247 | struct pm80x_rtc_pdata *pdata = dev_get_platdata(&pdev->dev); |
255 | struct pm80x_rtc_info *info; | 248 | struct pm80x_rtc_info *info; |
256 | struct device_node *node = pdev->dev.of_node; | 249 | struct device_node *node = pdev->dev.of_node; |
257 | struct rtc_time tm; | ||
258 | unsigned long ticks = 0; | ||
259 | int ret; | 250 | int ret; |
260 | 251 | ||
261 | if (!pdata && !node) { | 252 | if (!pdata && !node) { |
@@ -294,6 +285,10 @@ static int pm80x_rtc_probe(struct platform_device *pdev) | |||
294 | info->dev = &pdev->dev; | 285 | info->dev = &pdev->dev; |
295 | dev_set_drvdata(&pdev->dev, info); | 286 | dev_set_drvdata(&pdev->dev, info); |
296 | 287 | ||
288 | info->rtc_dev = devm_rtc_allocate_device(&pdev->dev); | ||
289 | if (IS_ERR(info->rtc_dev)) | ||
290 | return PTR_ERR(info->rtc_dev); | ||
291 | |||
297 | ret = pm80x_request_irq(chip, info->irq, rtc_update_handler, | 292 | ret = pm80x_request_irq(chip, info->irq, rtc_update_handler, |
298 | IRQF_ONESHOT, "rtc", info); | 293 | IRQF_ONESHOT, "rtc", info); |
299 | if (ret < 0) { | 294 | if (ret < 0) { |
@@ -302,30 +297,11 @@ static int pm80x_rtc_probe(struct platform_device *pdev) | |||
302 | goto out; | 297 | goto out; |
303 | } | 298 | } |
304 | 299 | ||
305 | ret = pm80x_rtc_read_time(&pdev->dev, &tm); | 300 | info->rtc_dev->ops = &pm80x_rtc_ops; |
306 | if (ret < 0) { | 301 | info->rtc_dev->range_max = U32_MAX; |
307 | dev_err(&pdev->dev, "Failed to read initial time.\n"); | ||
308 | goto out_rtc; | ||
309 | } | ||
310 | if ((tm.tm_year < 70) || (tm.tm_year > 138)) { | ||
311 | tm.tm_year = 70; | ||
312 | tm.tm_mon = 0; | ||
313 | tm.tm_mday = 1; | ||
314 | tm.tm_hour = 0; | ||
315 | tm.tm_min = 0; | ||
316 | tm.tm_sec = 0; | ||
317 | ret = pm80x_rtc_set_time(&pdev->dev, &tm); | ||
318 | if (ret < 0) { | ||
319 | dev_err(&pdev->dev, "Failed to set initial time.\n"); | ||
320 | goto out_rtc; | ||
321 | } | ||
322 | } | ||
323 | rtc_tm_to_time(&tm, &ticks); | ||
324 | 302 | ||
325 | info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm80x-rtc", | 303 | ret = rtc_register_device(info->rtc_dev); |
326 | &pm80x_rtc_ops, THIS_MODULE); | 304 | if (ret) { |
327 | if (IS_ERR(info->rtc_dev)) { | ||
328 | ret = PTR_ERR(info->rtc_dev); | ||
329 | dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); | 305 | dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); |
330 | goto out_rtc; | 306 | goto out_rtc; |
331 | } | 307 | } |
diff --git a/drivers/rtc/rtc-ab-b5ze-s3.c b/drivers/rtc/rtc-ab-b5ze-s3.c index 8dc451932446..2233601761ac 100644 --- a/drivers/rtc/rtc-ab-b5ze-s3.c +++ b/drivers/rtc/rtc-ab-b5ze-s3.c | |||
@@ -265,15 +265,6 @@ static int abb5zes3_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
265 | u8 regs[ABB5ZES3_REG_RTC_SC + ABB5ZES3_RTC_SEC_LEN]; | 265 | u8 regs[ABB5ZES3_REG_RTC_SC + ABB5ZES3_RTC_SEC_LEN]; |
266 | int ret; | 266 | int ret; |
267 | 267 | ||
268 | /* | ||
269 | * Year register is 8-bit wide and bcd-coded, i.e records values | ||
270 | * between 0 and 99. tm_year is an offset from 1900 and we are | ||
271 | * interested in the 2000-2099 range, so any value less than 100 | ||
272 | * is invalid. | ||
273 | */ | ||
274 | if (tm->tm_year < 100) | ||
275 | return -EINVAL; | ||
276 | |||
277 | regs[ABB5ZES3_REG_RTC_SC] = bin2bcd(tm->tm_sec); /* MSB=0 clears OSC */ | 268 | regs[ABB5ZES3_REG_RTC_SC] = bin2bcd(tm->tm_sec); /* MSB=0 clears OSC */ |
278 | regs[ABB5ZES3_REG_RTC_MN] = bin2bcd(tm->tm_min); | 269 | regs[ABB5ZES3_REG_RTC_MN] = bin2bcd(tm->tm_min); |
279 | regs[ABB5ZES3_REG_RTC_HR] = bin2bcd(tm->tm_hour); /* 24-hour format */ | 270 | regs[ABB5ZES3_REG_RTC_HR] = bin2bcd(tm->tm_hour); /* 24-hour format */ |
@@ -925,6 +916,14 @@ static int abb5zes3_probe(struct i2c_client *client, | |||
925 | if (ret) | 916 | if (ret) |
926 | goto err; | 917 | goto err; |
927 | 918 | ||
919 | data->rtc = devm_rtc_allocate_device(dev); | ||
920 | ret = PTR_ERR_OR_ZERO(data->rtc); | ||
921 | if (ret) { | ||
922 | dev_err(dev, "%s: unable to allocate RTC device (%d)\n", | ||
923 | __func__, ret); | ||
924 | goto err; | ||
925 | } | ||
926 | |||
928 | if (client->irq > 0) { | 927 | if (client->irq > 0) { |
929 | ret = devm_request_threaded_irq(dev, client->irq, NULL, | 928 | ret = devm_request_threaded_irq(dev, client->irq, NULL, |
930 | _abb5zes3_rtc_interrupt, | 929 | _abb5zes3_rtc_interrupt, |
@@ -942,14 +941,9 @@ static int abb5zes3_probe(struct i2c_client *client, | |||
942 | } | 941 | } |
943 | } | 942 | } |
944 | 943 | ||
945 | data->rtc = devm_rtc_device_register(dev, DRV_NAME, &rtc_ops, | 944 | data->rtc->ops = &rtc_ops; |
946 | THIS_MODULE); | 945 | data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; |
947 | ret = PTR_ERR_OR_ZERO(data->rtc); | 946 | data->rtc->range_max = RTC_TIMESTAMP_END_2099; |
948 | if (ret) { | ||
949 | dev_err(dev, "%s: unable to register RTC device (%d)\n", | ||
950 | __func__, ret); | ||
951 | goto err; | ||
952 | } | ||
953 | 947 | ||
954 | /* Enable battery low detection interrupt if battery not already low */ | 948 | /* Enable battery low detection interrupt if battery not already low */ |
955 | if (!data->battery_low && data->irq) { | 949 | if (!data->battery_low && data->irq) { |
@@ -961,6 +955,8 @@ static int abb5zes3_probe(struct i2c_client *client, | |||
961 | } | 955 | } |
962 | } | 956 | } |
963 | 957 | ||
958 | ret = rtc_register_device(data->rtc); | ||
959 | |||
964 | err: | 960 | err: |
965 | if (ret && data && data->irq) | 961 | if (ret && data && data->irq) |
966 | device_init_wakeup(dev, false); | 962 | device_init_wakeup(dev, false); |
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c index de81ecedd571..caa71d04e989 100644 --- a/drivers/rtc/rtc-at91rm9200.c +++ b/drivers/rtc/rtc-at91rm9200.c | |||
@@ -440,6 +440,8 @@ static int __init at91_rtc_probe(struct platform_device *pdev) | |||
440 | device_init_wakeup(&pdev->dev, 1); | 440 | device_init_wakeup(&pdev->dev, 1); |
441 | 441 | ||
442 | rtc->ops = &at91_rtc_ops; | 442 | rtc->ops = &at91_rtc_ops; |
443 | rtc->range_min = RTC_TIMESTAMP_BEGIN_1900; | ||
444 | rtc->range_max = RTC_TIMESTAMP_END_2099; | ||
443 | ret = rtc_register_device(rtc); | 445 | ret = rtc_register_device(rtc); |
444 | if (ret) | 446 | if (ret) |
445 | goto err_clk; | 447 | goto err_clk; |
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c index bd170cb3361c..d768f6747961 100644 --- a/drivers/rtc/rtc-bq4802.c +++ b/drivers/rtc/rtc-bq4802.c | |||
@@ -48,8 +48,7 @@ static void bq4802_write_mem(struct bq4802 *p, int off, u8 val) | |||
48 | 48 | ||
49 | static int bq4802_read_time(struct device *dev, struct rtc_time *tm) | 49 | static int bq4802_read_time(struct device *dev, struct rtc_time *tm) |
50 | { | 50 | { |
51 | struct platform_device *pdev = to_platform_device(dev); | 51 | struct bq4802 *p = dev_get_drvdata(dev); |
52 | struct bq4802 *p = platform_get_drvdata(pdev); | ||
53 | unsigned long flags; | 52 | unsigned long flags; |
54 | unsigned int century; | 53 | unsigned int century; |
55 | u8 val; | 54 | u8 val; |
@@ -91,8 +90,7 @@ static int bq4802_read_time(struct device *dev, struct rtc_time *tm) | |||
91 | 90 | ||
92 | static int bq4802_set_time(struct device *dev, struct rtc_time *tm) | 91 | static int bq4802_set_time(struct device *dev, struct rtc_time *tm) |
93 | { | 92 | { |
94 | struct platform_device *pdev = to_platform_device(dev); | 93 | struct bq4802 *p = dev_get_drvdata(dev); |
95 | struct bq4802 *p = platform_get_drvdata(pdev); | ||
96 | u8 sec, min, hrs, day, mon, yrs, century, val; | 94 | u8 sec, min, hrs, day, mon, yrs, century, val; |
97 | unsigned long flags; | 95 | unsigned long flags; |
98 | unsigned int year; | 96 | unsigned int year; |
diff --git a/drivers/rtc/rtc-brcmstb-waketimer.c b/drivers/rtc/rtc-brcmstb-waketimer.c index bdd6674a1054..f4010a75f2be 100644 --- a/drivers/rtc/rtc-brcmstb-waketimer.c +++ b/drivers/rtc/rtc-brcmstb-waketimer.c | |||
@@ -145,9 +145,6 @@ static int brcmstb_waketmr_settime(struct device *dev, | |||
145 | 145 | ||
146 | sec = rtc_tm_to_time64(tm); | 146 | sec = rtc_tm_to_time64(tm); |
147 | 147 | ||
148 | if (sec > U32_MAX || sec < 0) | ||
149 | return -EINVAL; | ||
150 | |||
151 | writel_relaxed(sec, timer->base + BRCMSTB_WKTMR_COUNTER); | 148 | writel_relaxed(sec, timer->base + BRCMSTB_WKTMR_COUNTER); |
152 | 149 | ||
153 | return 0; | 150 | return 0; |
@@ -184,9 +181,6 @@ static int brcmstb_waketmr_setalarm(struct device *dev, | |||
184 | else | 181 | else |
185 | sec = 0; | 182 | sec = 0; |
186 | 183 | ||
187 | if (sec > U32_MAX || sec < 0) | ||
188 | return -EINVAL; | ||
189 | |||
190 | brcmstb_waketmr_set_alarm(timer, sec); | 184 | brcmstb_waketmr_set_alarm(timer, sec); |
191 | 185 | ||
192 | return 0; | 186 | return 0; |
@@ -229,6 +223,10 @@ static int brcmstb_waketmr_probe(struct platform_device *pdev) | |||
229 | if (IS_ERR(timer->base)) | 223 | if (IS_ERR(timer->base)) |
230 | return PTR_ERR(timer->base); | 224 | return PTR_ERR(timer->base); |
231 | 225 | ||
226 | timer->rtc = devm_rtc_allocate_device(dev); | ||
227 | if (IS_ERR(timer->rtc)) | ||
228 | return PTR_ERR(timer->rtc); | ||
229 | |||
232 | /* | 230 | /* |
233 | * Set wakeup capability before requesting wakeup interrupt, so we can | 231 | * Set wakeup capability before requesting wakeup interrupt, so we can |
234 | * process boot-time "wakeups" (e.g., from S5 soft-off) | 232 | * process boot-time "wakeups" (e.g., from S5 soft-off) |
@@ -261,11 +259,12 @@ static int brcmstb_waketmr_probe(struct platform_device *pdev) | |||
261 | timer->reboot_notifier.notifier_call = brcmstb_waketmr_reboot; | 259 | timer->reboot_notifier.notifier_call = brcmstb_waketmr_reboot; |
262 | register_reboot_notifier(&timer->reboot_notifier); | 260 | register_reboot_notifier(&timer->reboot_notifier); |
263 | 261 | ||
264 | timer->rtc = rtc_device_register("brcmstb-waketmr", dev, | 262 | timer->rtc->ops = &brcmstb_waketmr_ops; |
265 | &brcmstb_waketmr_ops, THIS_MODULE); | 263 | timer->rtc->range_max = U32_MAX; |
266 | if (IS_ERR(timer->rtc)) { | 264 | |
265 | ret = rtc_register_device(timer->rtc); | ||
266 | if (ret) { | ||
267 | dev_err(dev, "unable to register device\n"); | 267 | dev_err(dev, "unable to register device\n"); |
268 | ret = PTR_ERR(timer->rtc); | ||
269 | goto err_notifier; | 268 | goto err_notifier; |
270 | } | 269 | } |
271 | 270 | ||
@@ -288,7 +287,6 @@ static int brcmstb_waketmr_remove(struct platform_device *pdev) | |||
288 | struct brcmstb_waketmr *timer = dev_get_drvdata(&pdev->dev); | 287 | struct brcmstb_waketmr *timer = dev_get_drvdata(&pdev->dev); |
289 | 288 | ||
290 | unregister_reboot_notifier(&timer->reboot_notifier); | 289 | unregister_reboot_notifier(&timer->reboot_notifier); |
291 | rtc_device_unregister(timer->rtc); | ||
292 | 290 | ||
293 | return 0; | 291 | return 0; |
294 | } | 292 | } |
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 1b3738a11702..cd3a2411bc2f 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c | |||
@@ -43,11 +43,24 @@ | |||
43 | #include <linux/of_platform.h> | 43 | #include <linux/of_platform.h> |
44 | #ifdef CONFIG_X86 | 44 | #ifdef CONFIG_X86 |
45 | #include <asm/i8259.h> | 45 | #include <asm/i8259.h> |
46 | #include <asm/processor.h> | ||
47 | #include <linux/dmi.h> | ||
46 | #endif | 48 | #endif |
47 | 49 | ||
48 | /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ | 50 | /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ |
49 | #include <linux/mc146818rtc.h> | 51 | #include <linux/mc146818rtc.h> |
50 | 52 | ||
53 | /* | ||
54 | * Use ACPI SCI to replace HPET interrupt for RTC Alarm event | ||
55 | * | ||
56 | * If cleared, ACPI SCI is only used to wake up the system from suspend | ||
57 | * | ||
58 | * If set, ACPI SCI is used to handle UIE/AIE and system wakeup | ||
59 | */ | ||
60 | |||
61 | static bool use_acpi_alarm; | ||
62 | module_param(use_acpi_alarm, bool, 0444); | ||
63 | |||
51 | struct cmos_rtc { | 64 | struct cmos_rtc { |
52 | struct rtc_device *rtc; | 65 | struct rtc_device *rtc; |
53 | struct device *dev; | 66 | struct device *dev; |
@@ -153,6 +166,12 @@ static inline int hpet_unregister_irq_handler(irq_handler_t handler) | |||
153 | 166 | ||
154 | #endif | 167 | #endif |
155 | 168 | ||
169 | /* Don't use HPET for RTC Alarm event if ACPI Fixed event is used */ | ||
170 | static int use_hpet_alarm(void) | ||
171 | { | ||
172 | return is_hpet_enabled() && !use_acpi_alarm; | ||
173 | } | ||
174 | |||
156 | /*----------------------------------------------------------------*/ | 175 | /*----------------------------------------------------------------*/ |
157 | 176 | ||
158 | #ifdef RTC_PORT | 177 | #ifdef RTC_PORT |
@@ -298,7 +317,7 @@ static void cmos_checkintr(struct cmos_rtc *cmos, unsigned char rtc_control) | |||
298 | */ | 317 | */ |
299 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); | 318 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); |
300 | 319 | ||
301 | if (is_hpet_enabled()) | 320 | if (use_hpet_alarm()) |
302 | return; | 321 | return; |
303 | 322 | ||
304 | rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; | 323 | rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; |
@@ -318,7 +337,13 @@ static void cmos_irq_enable(struct cmos_rtc *cmos, unsigned char mask) | |||
318 | 337 | ||
319 | rtc_control |= mask; | 338 | rtc_control |= mask; |
320 | CMOS_WRITE(rtc_control, RTC_CONTROL); | 339 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
321 | hpet_set_rtc_irq_bit(mask); | 340 | if (use_hpet_alarm()) |
341 | hpet_set_rtc_irq_bit(mask); | ||
342 | |||
343 | if ((mask & RTC_AIE) && use_acpi_alarm) { | ||
344 | if (cmos->wake_on) | ||
345 | cmos->wake_on(cmos->dev); | ||
346 | } | ||
322 | 347 | ||
323 | cmos_checkintr(cmos, rtc_control); | 348 | cmos_checkintr(cmos, rtc_control); |
324 | } | 349 | } |
@@ -330,7 +355,13 @@ static void cmos_irq_disable(struct cmos_rtc *cmos, unsigned char mask) | |||
330 | rtc_control = CMOS_READ(RTC_CONTROL); | 355 | rtc_control = CMOS_READ(RTC_CONTROL); |
331 | rtc_control &= ~mask; | 356 | rtc_control &= ~mask; |
332 | CMOS_WRITE(rtc_control, RTC_CONTROL); | 357 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
333 | hpet_mask_rtc_irq_bit(mask); | 358 | if (use_hpet_alarm()) |
359 | hpet_mask_rtc_irq_bit(mask); | ||
360 | |||
361 | if ((mask & RTC_AIE) && use_acpi_alarm) { | ||
362 | if (cmos->wake_off) | ||
363 | cmos->wake_off(cmos->dev); | ||
364 | } | ||
334 | 365 | ||
335 | cmos_checkintr(cmos, rtc_control); | 366 | cmos_checkintr(cmos, rtc_control); |
336 | } | 367 | } |
@@ -448,10 +479,14 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
448 | CMOS_WRITE(mon, cmos->mon_alrm); | 479 | CMOS_WRITE(mon, cmos->mon_alrm); |
449 | } | 480 | } |
450 | 481 | ||
451 | /* FIXME the HPET alarm glue currently ignores day_alrm | 482 | if (use_hpet_alarm()) { |
452 | * and mon_alrm ... | 483 | /* |
453 | */ | 484 | * FIXME the HPET alarm glue currently ignores day_alrm |
454 | hpet_set_alarm_time(t->time.tm_hour, t->time.tm_min, t->time.tm_sec); | 485 | * and mon_alrm ... |
486 | */ | ||
487 | hpet_set_alarm_time(t->time.tm_hour, t->time.tm_min, | ||
488 | t->time.tm_sec); | ||
489 | } | ||
455 | 490 | ||
456 | if (t->enabled) | 491 | if (t->enabled) |
457 | cmos_irq_enable(cmos, RTC_AIE); | 492 | cmos_irq_enable(cmos, RTC_AIE); |
@@ -508,7 +543,7 @@ static int cmos_procfs(struct device *dev, struct seq_file *seq) | |||
508 | "batt_status\t: %s\n", | 543 | "batt_status\t: %s\n", |
509 | (rtc_control & RTC_PIE) ? "yes" : "no", | 544 | (rtc_control & RTC_PIE) ? "yes" : "no", |
510 | (rtc_control & RTC_UIE) ? "yes" : "no", | 545 | (rtc_control & RTC_UIE) ? "yes" : "no", |
511 | is_hpet_enabled() ? "yes" : "no", | 546 | use_hpet_alarm() ? "yes" : "no", |
512 | // (rtc_control & RTC_SQWE) ? "yes" : "no", | 547 | // (rtc_control & RTC_SQWE) ? "yes" : "no", |
513 | (rtc_control & RTC_DM_BINARY) ? "no" : "yes", | 548 | (rtc_control & RTC_DM_BINARY) ? "no" : "yes", |
514 | (rtc_control & RTC_DST_EN) ? "yes" : "no", | 549 | (rtc_control & RTC_DST_EN) ? "yes" : "no", |
@@ -614,7 +649,7 @@ static irqreturn_t cmos_interrupt(int irq, void *p) | |||
614 | */ | 649 | */ |
615 | irqstat = CMOS_READ(RTC_INTR_FLAGS); | 650 | irqstat = CMOS_READ(RTC_INTR_FLAGS); |
616 | rtc_control = CMOS_READ(RTC_CONTROL); | 651 | rtc_control = CMOS_READ(RTC_CONTROL); |
617 | if (is_hpet_enabled()) | 652 | if (use_hpet_alarm()) |
618 | irqstat = (unsigned long)irq & 0xF0; | 653 | irqstat = (unsigned long)irq & 0xF0; |
619 | 654 | ||
620 | /* If we were suspended, RTC_CONTROL may not be accurate since the | 655 | /* If we were suspended, RTC_CONTROL may not be accurate since the |
@@ -633,7 +668,8 @@ static irqreturn_t cmos_interrupt(int irq, void *p) | |||
633 | cmos_rtc.suspend_ctrl &= ~RTC_AIE; | 668 | cmos_rtc.suspend_ctrl &= ~RTC_AIE; |
634 | rtc_control &= ~RTC_AIE; | 669 | rtc_control &= ~RTC_AIE; |
635 | CMOS_WRITE(rtc_control, RTC_CONTROL); | 670 | CMOS_WRITE(rtc_control, RTC_CONTROL); |
636 | hpet_mask_rtc_irq_bit(RTC_AIE); | 671 | if (use_hpet_alarm()) |
672 | hpet_mask_rtc_irq_bit(RTC_AIE); | ||
637 | CMOS_READ(RTC_INTR_FLAGS); | 673 | CMOS_READ(RTC_INTR_FLAGS); |
638 | } | 674 | } |
639 | spin_unlock(&rtc_lock); | 675 | spin_unlock(&rtc_lock); |
@@ -762,7 +798,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
762 | * need to do something about other clock frequencies. | 798 | * need to do something about other clock frequencies. |
763 | */ | 799 | */ |
764 | cmos_rtc.rtc->irq_freq = 1024; | 800 | cmos_rtc.rtc->irq_freq = 1024; |
765 | hpet_set_periodic_freq(cmos_rtc.rtc->irq_freq); | 801 | if (use_hpet_alarm()) |
802 | hpet_set_periodic_freq(cmos_rtc.rtc->irq_freq); | ||
766 | CMOS_WRITE(RTC_REF_CLCK_32KHZ | 0x06, RTC_FREQ_SELECT); | 803 | CMOS_WRITE(RTC_REF_CLCK_32KHZ | 0x06, RTC_FREQ_SELECT); |
767 | } | 804 | } |
768 | 805 | ||
@@ -780,12 +817,13 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
780 | goto cleanup1; | 817 | goto cleanup1; |
781 | } | 818 | } |
782 | 819 | ||
783 | hpet_rtc_timer_init(); | 820 | if (use_hpet_alarm()) |
821 | hpet_rtc_timer_init(); | ||
784 | 822 | ||
785 | if (is_valid_irq(rtc_irq)) { | 823 | if (is_valid_irq(rtc_irq)) { |
786 | irq_handler_t rtc_cmos_int_handler; | 824 | irq_handler_t rtc_cmos_int_handler; |
787 | 825 | ||
788 | if (is_hpet_enabled()) { | 826 | if (use_hpet_alarm()) { |
789 | rtc_cmos_int_handler = hpet_rtc_interrupt; | 827 | rtc_cmos_int_handler = hpet_rtc_interrupt; |
790 | retval = hpet_register_irq_handler(cmos_interrupt); | 828 | retval = hpet_register_irq_handler(cmos_interrupt); |
791 | if (retval) { | 829 | if (retval) { |
@@ -824,7 +862,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
824 | "alarms up to one day", | 862 | "alarms up to one day", |
825 | cmos_rtc.century ? ", y3k" : "", | 863 | cmos_rtc.century ? ", y3k" : "", |
826 | nvmem_cfg.size, | 864 | nvmem_cfg.size, |
827 | is_hpet_enabled() ? ", hpet irqs" : ""); | 865 | use_hpet_alarm() ? ", hpet irqs" : ""); |
828 | 866 | ||
829 | return 0; | 867 | return 0; |
830 | 868 | ||
@@ -858,7 +896,8 @@ static void cmos_do_remove(struct device *dev) | |||
858 | 896 | ||
859 | if (is_valid_irq(cmos->irq)) { | 897 | if (is_valid_irq(cmos->irq)) { |
860 | free_irq(cmos->irq, cmos->rtc); | 898 | free_irq(cmos->irq, cmos->rtc); |
861 | hpet_unregister_irq_handler(cmos_interrupt); | 899 | if (use_hpet_alarm()) |
900 | hpet_unregister_irq_handler(cmos_interrupt); | ||
862 | } | 901 | } |
863 | 902 | ||
864 | cmos->rtc = NULL; | 903 | cmos->rtc = NULL; |
@@ -935,13 +974,13 @@ static int cmos_suspend(struct device *dev) | |||
935 | mask = RTC_IRQMASK; | 974 | mask = RTC_IRQMASK; |
936 | tmp &= ~mask; | 975 | tmp &= ~mask; |
937 | CMOS_WRITE(tmp, RTC_CONTROL); | 976 | CMOS_WRITE(tmp, RTC_CONTROL); |
938 | hpet_mask_rtc_irq_bit(mask); | 977 | if (use_hpet_alarm()) |
939 | 978 | hpet_mask_rtc_irq_bit(mask); | |
940 | cmos_checkintr(cmos, tmp); | 979 | cmos_checkintr(cmos, tmp); |
941 | } | 980 | } |
942 | spin_unlock_irq(&rtc_lock); | 981 | spin_unlock_irq(&rtc_lock); |
943 | 982 | ||
944 | if (tmp & RTC_AIE) { | 983 | if ((tmp & RTC_AIE) && !use_acpi_alarm) { |
945 | cmos->enabled_wake = 1; | 984 | cmos->enabled_wake = 1; |
946 | if (cmos->wake_on) | 985 | if (cmos->wake_on) |
947 | cmos->wake_on(dev); | 986 | cmos->wake_on(dev); |
@@ -976,8 +1015,26 @@ static void cmos_check_wkalrm(struct device *dev) | |||
976 | { | 1015 | { |
977 | struct cmos_rtc *cmos = dev_get_drvdata(dev); | 1016 | struct cmos_rtc *cmos = dev_get_drvdata(dev); |
978 | struct rtc_wkalrm current_alarm; | 1017 | struct rtc_wkalrm current_alarm; |
1018 | time64_t t_now; | ||
979 | time64_t t_current_expires; | 1019 | time64_t t_current_expires; |
980 | time64_t t_saved_expires; | 1020 | time64_t t_saved_expires; |
1021 | struct rtc_time now; | ||
1022 | |||
1023 | /* Check if we have RTC Alarm armed */ | ||
1024 | if (!(cmos->suspend_ctrl & RTC_AIE)) | ||
1025 | return; | ||
1026 | |||
1027 | cmos_read_time(dev, &now); | ||
1028 | t_now = rtc_tm_to_time64(&now); | ||
1029 | |||
1030 | /* | ||
1031 | * ACPI RTC wake event is cleared after resume from STR, | ||
1032 | * ACK the rtc irq here | ||
1033 | */ | ||
1034 | if (t_now >= cmos->alarm_expires && use_acpi_alarm) { | ||
1035 | cmos_interrupt(0, (void *)cmos->rtc); | ||
1036 | return; | ||
1037 | } | ||
981 | 1038 | ||
982 | cmos_read_alarm(dev, ¤t_alarm); | 1039 | cmos_read_alarm(dev, ¤t_alarm); |
983 | t_current_expires = rtc_tm_to_time64(¤t_alarm.time); | 1040 | t_current_expires = rtc_tm_to_time64(¤t_alarm.time); |
@@ -996,7 +1053,7 @@ static int __maybe_unused cmos_resume(struct device *dev) | |||
996 | struct cmos_rtc *cmos = dev_get_drvdata(dev); | 1053 | struct cmos_rtc *cmos = dev_get_drvdata(dev); |
997 | unsigned char tmp; | 1054 | unsigned char tmp; |
998 | 1055 | ||
999 | if (cmos->enabled_wake) { | 1056 | if (cmos->enabled_wake && !use_acpi_alarm) { |
1000 | if (cmos->wake_off) | 1057 | if (cmos->wake_off) |
1001 | cmos->wake_off(dev); | 1058 | cmos->wake_off(dev); |
1002 | else | 1059 | else |
@@ -1014,16 +1071,17 @@ static int __maybe_unused cmos_resume(struct device *dev) | |||
1014 | if (tmp & RTC_IRQMASK) { | 1071 | if (tmp & RTC_IRQMASK) { |
1015 | unsigned char mask; | 1072 | unsigned char mask; |
1016 | 1073 | ||
1017 | if (device_may_wakeup(dev)) | 1074 | if (device_may_wakeup(dev) && use_hpet_alarm()) |
1018 | hpet_rtc_timer_init(); | 1075 | hpet_rtc_timer_init(); |
1019 | 1076 | ||
1020 | do { | 1077 | do { |
1021 | CMOS_WRITE(tmp, RTC_CONTROL); | 1078 | CMOS_WRITE(tmp, RTC_CONTROL); |
1022 | hpet_set_rtc_irq_bit(tmp & RTC_IRQMASK); | 1079 | if (use_hpet_alarm()) |
1080 | hpet_set_rtc_irq_bit(tmp & RTC_IRQMASK); | ||
1023 | 1081 | ||
1024 | mask = CMOS_READ(RTC_INTR_FLAGS); | 1082 | mask = CMOS_READ(RTC_INTR_FLAGS); |
1025 | mask &= (tmp & RTC_IRQMASK) | RTC_IRQF; | 1083 | mask &= (tmp & RTC_IRQMASK) | RTC_IRQF; |
1026 | if (!is_hpet_enabled() || !is_intr(mask)) | 1084 | if (!use_hpet_alarm() || !is_intr(mask)) |
1027 | break; | 1085 | break; |
1028 | 1086 | ||
1029 | /* force one-shot behavior if HPET blocked | 1087 | /* force one-shot behavior if HPET blocked |
@@ -1068,16 +1126,27 @@ static u32 rtc_handler(void *context) | |||
1068 | unsigned char rtc_intr; | 1126 | unsigned char rtc_intr; |
1069 | unsigned long flags; | 1127 | unsigned long flags; |
1070 | 1128 | ||
1071 | spin_lock_irqsave(&rtc_lock, flags); | 1129 | |
1072 | if (cmos_rtc.suspend_ctrl) | 1130 | /* |
1073 | rtc_control = CMOS_READ(RTC_CONTROL); | 1131 | * Always update rtc irq when ACPI is used as RTC Alarm. |
1074 | if (rtc_control & RTC_AIE) { | 1132 | * Or else, ACPI SCI is enabled during suspend/resume only, |
1075 | cmos_rtc.suspend_ctrl &= ~RTC_AIE; | 1133 | * update rtc irq in that case. |
1076 | CMOS_WRITE(rtc_control, RTC_CONTROL); | 1134 | */ |
1077 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); | 1135 | if (use_acpi_alarm) |
1078 | rtc_update_irq(cmos->rtc, 1, rtc_intr); | 1136 | cmos_interrupt(0, (void *)cmos->rtc); |
1137 | else { | ||
1138 | /* Fix me: can we use cmos_interrupt() here as well? */ | ||
1139 | spin_lock_irqsave(&rtc_lock, flags); | ||
1140 | if (cmos_rtc.suspend_ctrl) | ||
1141 | rtc_control = CMOS_READ(RTC_CONTROL); | ||
1142 | if (rtc_control & RTC_AIE) { | ||
1143 | cmos_rtc.suspend_ctrl &= ~RTC_AIE; | ||
1144 | CMOS_WRITE(rtc_control, RTC_CONTROL); | ||
1145 | rtc_intr = CMOS_READ(RTC_INTR_FLAGS); | ||
1146 | rtc_update_irq(cmos->rtc, 1, rtc_intr); | ||
1147 | } | ||
1148 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
1079 | } | 1149 | } |
1080 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
1081 | 1150 | ||
1082 | pm_wakeup_hard_event(dev); | 1151 | pm_wakeup_hard_event(dev); |
1083 | acpi_clear_event(ACPI_EVENT_RTC); | 1152 | acpi_clear_event(ACPI_EVENT_RTC); |
@@ -1107,6 +1176,28 @@ static void rtc_wake_off(struct device *dev) | |||
1107 | acpi_disable_event(ACPI_EVENT_RTC, 0); | 1176 | acpi_disable_event(ACPI_EVENT_RTC, 0); |
1108 | } | 1177 | } |
1109 | 1178 | ||
1179 | #ifdef CONFIG_X86 | ||
1180 | /* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */ | ||
1181 | static void use_acpi_alarm_quirks(void) | ||
1182 | { | ||
1183 | int year; | ||
1184 | |||
1185 | if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) | ||
1186 | return; | ||
1187 | |||
1188 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) | ||
1189 | return; | ||
1190 | |||
1191 | if (!is_hpet_enabled()) | ||
1192 | return; | ||
1193 | |||
1194 | if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2015) | ||
1195 | use_acpi_alarm = true; | ||
1196 | } | ||
1197 | #else | ||
1198 | static inline void use_acpi_alarm_quirks(void) { } | ||
1199 | #endif | ||
1200 | |||
1110 | /* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find | 1201 | /* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find |
1111 | * its device node and pass extra config data. This helps its driver use | 1202 | * its device node and pass extra config data. This helps its driver use |
1112 | * capabilities that the now-obsolete mc146818 didn't have, and informs it | 1203 | * capabilities that the now-obsolete mc146818 didn't have, and informs it |
@@ -1119,6 +1210,8 @@ static void cmos_wake_setup(struct device *dev) | |||
1119 | if (acpi_disabled) | 1210 | if (acpi_disabled) |
1120 | return; | 1211 | return; |
1121 | 1212 | ||
1213 | use_acpi_alarm_quirks(); | ||
1214 | |||
1122 | rtc_wake_setup(dev); | 1215 | rtc_wake_setup(dev); |
1123 | acpi_rtc_info.wake_on = rtc_wake_on; | 1216 | acpi_rtc_info.wake_on = rtc_wake_on; |
1124 | acpi_rtc_info.wake_off = rtc_wake_off; | 1217 | acpi_rtc_info.wake_off = rtc_wake_off; |
diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c index bf7ced095c94..e5444296075e 100644 --- a/drivers/rtc/rtc-cros-ec.c +++ b/drivers/rtc/rtc-cros-ec.c | |||
@@ -1,19 +1,8 @@ | |||
1 | /* | 1 | // SPDX-License-Identifier: GPL-2.0 |
2 | * RTC driver for Chrome OS Embedded Controller | 2 | // RTC driver for ChromeOS Embedded Controller. |
3 | * | 3 | // |
4 | * Copyright (c) 2017, Google, Inc | 4 | // Copyright (C) 2017 Google, Inc. |
5 | * | 5 | // Author: Stephen Barber <smbarber@chromium.org> |
6 | * Author: Stephen Barber <smbarber@chromium.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms and conditions of the GNU General Public License, | ||
10 | * version 2, as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
15 | * more details. | ||
16 | */ | ||
17 | 6 | ||
18 | #include <linux/kernel.h> | 7 | #include <linux/kernel.h> |
19 | #include <linux/mfd/cros_ec.h> | 8 | #include <linux/mfd/cros_ec.h> |
@@ -409,5 +398,5 @@ module_platform_driver(cros_ec_rtc_driver); | |||
409 | 398 | ||
410 | MODULE_DESCRIPTION("RTC driver for Chrome OS ECs"); | 399 | MODULE_DESCRIPTION("RTC driver for Chrome OS ECs"); |
411 | MODULE_AUTHOR("Stephen Barber <smbarber@chromium.org>"); | 400 | MODULE_AUTHOR("Stephen Barber <smbarber@chromium.org>"); |
412 | MODULE_LICENSE("GPL"); | 401 | MODULE_LICENSE("GPL v2"); |
413 | MODULE_ALIAS("platform:" DRV_NAME); | 402 | MODULE_ALIAS("platform:" DRV_NAME); |
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c index 5f158715fb4c..50fabe1cd286 100644 --- a/drivers/rtc/rtc-ds1216.c +++ b/drivers/rtc/rtc-ds1216.c | |||
@@ -76,8 +76,7 @@ static void ds1216_switch_ds_to_clock(u8 __iomem *ioaddr) | |||
76 | 76 | ||
77 | static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm) | 77 | static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm) |
78 | { | 78 | { |
79 | struct platform_device *pdev = to_platform_device(dev); | 79 | struct ds1216_priv *priv = dev_get_drvdata(dev); |
80 | struct ds1216_priv *priv = platform_get_drvdata(pdev); | ||
81 | struct ds1216_regs regs; | 80 | struct ds1216_regs regs; |
82 | 81 | ||
83 | ds1216_switch_ds_to_clock(priv->ioaddr); | 82 | ds1216_switch_ds_to_clock(priv->ioaddr); |
@@ -104,8 +103,7 @@ static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
104 | 103 | ||
105 | static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm) | 104 | static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm) |
106 | { | 105 | { |
107 | struct platform_device *pdev = to_platform_device(dev); | 106 | struct ds1216_priv *priv = dev_get_drvdata(dev); |
108 | struct ds1216_priv *priv = platform_get_drvdata(pdev); | ||
109 | struct ds1216_regs regs; | 107 | struct ds1216_regs regs; |
110 | 108 | ||
111 | ds1216_switch_ds_to_clock(priv->ioaddr); | 109 | ds1216_switch_ds_to_clock(priv->ioaddr); |
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index a13e59edff53..e9ec4160d7f6 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c | |||
@@ -201,6 +201,7 @@ static const struct chip_desc chips[last_ds_type] = { | |||
201 | .century_reg = DS1307_REG_HOUR, | 201 | .century_reg = DS1307_REG_HOUR, |
202 | .century_enable_bit = DS1340_BIT_CENTURY_EN, | 202 | .century_enable_bit = DS1340_BIT_CENTURY_EN, |
203 | .century_bit = DS1340_BIT_CENTURY, | 203 | .century_bit = DS1340_BIT_CENTURY, |
204 | .do_trickle_setup = &do_trickle_setup_ds1339, | ||
204 | .trickle_charger_reg = 0x08, | 205 | .trickle_charger_reg = 0x08, |
205 | }, | 206 | }, |
206 | [ds_1341] = { | 207 | [ds_1341] = { |
@@ -1371,6 +1372,7 @@ static void ds1307_clks_register(struct ds1307 *ds1307) | |||
1371 | static const struct regmap_config regmap_config = { | 1372 | static const struct regmap_config regmap_config = { |
1372 | .reg_bits = 8, | 1373 | .reg_bits = 8, |
1373 | .val_bits = 8, | 1374 | .val_bits = 8, |
1375 | .max_register = 0x9, | ||
1374 | }; | 1376 | }; |
1375 | 1377 | ||
1376 | static int ds1307_probe(struct i2c_client *client, | 1378 | static int ds1307_probe(struct i2c_client *client, |
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c index a7d5ca428d68..b8b6e51c0461 100644 --- a/drivers/rtc/rtc-ds1511.c +++ b/drivers/rtc/rtc-ds1511.c | |||
@@ -314,8 +314,7 @@ ds1511_rtc_update_alarm(struct rtc_plat_data *pdata) | |||
314 | static int | 314 | static int |
315 | ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 315 | ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
316 | { | 316 | { |
317 | struct platform_device *pdev = to_platform_device(dev); | 317 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
318 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
319 | 318 | ||
320 | if (pdata->irq <= 0) | 319 | if (pdata->irq <= 0) |
321 | return -EINVAL; | 320 | return -EINVAL; |
@@ -334,8 +333,7 @@ ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
334 | static int | 333 | static int |
335 | ds1511_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 334 | ds1511_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
336 | { | 335 | { |
337 | struct platform_device *pdev = to_platform_device(dev); | 336 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
338 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
339 | 337 | ||
340 | if (pdata->irq <= 0) | 338 | if (pdata->irq <= 0) |
341 | return -EINVAL; | 339 | return -EINVAL; |
@@ -373,8 +371,7 @@ ds1511_interrupt(int irq, void *dev_id) | |||
373 | 371 | ||
374 | static int ds1511_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | 372 | static int ds1511_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
375 | { | 373 | { |
376 | struct platform_device *pdev = to_platform_device(dev); | 374 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
377 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
378 | 375 | ||
379 | if (pdata->irq <= 0) | 376 | if (pdata->irq <= 0) |
380 | return -EINVAL; | 377 | return -EINVAL; |
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c index 2441b9a2b366..34af7a802f43 100644 --- a/drivers/rtc/rtc-ds1553.c +++ b/drivers/rtc/rtc-ds1553.c | |||
@@ -73,8 +73,7 @@ struct rtc_plat_data { | |||
73 | 73 | ||
74 | static int ds1553_rtc_set_time(struct device *dev, struct rtc_time *tm) | 74 | static int ds1553_rtc_set_time(struct device *dev, struct rtc_time *tm) |
75 | { | 75 | { |
76 | struct platform_device *pdev = to_platform_device(dev); | 76 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
77 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
78 | void __iomem *ioaddr = pdata->ioaddr; | 77 | void __iomem *ioaddr = pdata->ioaddr; |
79 | u8 century; | 78 | u8 century; |
80 | 79 | ||
@@ -98,8 +97,7 @@ static int ds1553_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
98 | 97 | ||
99 | static int ds1553_rtc_read_time(struct device *dev, struct rtc_time *tm) | 98 | static int ds1553_rtc_read_time(struct device *dev, struct rtc_time *tm) |
100 | { | 99 | { |
101 | struct platform_device *pdev = to_platform_device(dev); | 100 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
102 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
103 | void __iomem *ioaddr = pdata->ioaddr; | 101 | void __iomem *ioaddr = pdata->ioaddr; |
104 | unsigned int year, month, day, hour, minute, second, week; | 102 | unsigned int year, month, day, hour, minute, second, week; |
105 | unsigned int century; | 103 | unsigned int century; |
@@ -155,8 +153,7 @@ static void ds1553_rtc_update_alarm(struct rtc_plat_data *pdata) | |||
155 | 153 | ||
156 | static int ds1553_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 154 | static int ds1553_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
157 | { | 155 | { |
158 | struct platform_device *pdev = to_platform_device(dev); | 156 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
159 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
160 | 157 | ||
161 | if (pdata->irq <= 0) | 158 | if (pdata->irq <= 0) |
162 | return -EINVAL; | 159 | return -EINVAL; |
@@ -172,8 +169,7 @@ static int ds1553_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
172 | 169 | ||
173 | static int ds1553_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 170 | static int ds1553_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
174 | { | 171 | { |
175 | struct platform_device *pdev = to_platform_device(dev); | 172 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
176 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
177 | 173 | ||
178 | if (pdata->irq <= 0) | 174 | if (pdata->irq <= 0) |
179 | return -EINVAL; | 175 | return -EINVAL; |
@@ -208,8 +204,7 @@ static irqreturn_t ds1553_rtc_interrupt(int irq, void *dev_id) | |||
208 | 204 | ||
209 | static int ds1553_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | 205 | static int ds1553_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
210 | { | 206 | { |
211 | struct platform_device *pdev = to_platform_device(dev); | 207 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
212 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
213 | 208 | ||
214 | if (pdata->irq <= 0) | 209 | if (pdata->irq <= 0) |
215 | return -EINVAL; | 210 | return -EINVAL; |
diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c index 1a39829d2b40..5c0db6c8134c 100644 --- a/drivers/rtc/rtc-ds1685.c +++ b/drivers/rtc/rtc-ds1685.c | |||
@@ -267,8 +267,7 @@ ds1685_rtc_get_ssn(struct ds1685_priv *rtc, u8 *ssn) | |||
267 | static int | 267 | static int |
268 | ds1685_rtc_read_time(struct device *dev, struct rtc_time *tm) | 268 | ds1685_rtc_read_time(struct device *dev, struct rtc_time *tm) |
269 | { | 269 | { |
270 | struct platform_device *pdev = to_platform_device(dev); | 270 | struct ds1685_priv *rtc = dev_get_drvdata(dev); |
271 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); | ||
272 | u8 ctrlb, century; | 271 | u8 ctrlb, century; |
273 | u8 seconds, minutes, hours, wday, mday, month, years; | 272 | u8 seconds, minutes, hours, wday, mday, month, years; |
274 | 273 | ||
@@ -317,8 +316,7 @@ ds1685_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
317 | static int | 316 | static int |
318 | ds1685_rtc_set_time(struct device *dev, struct rtc_time *tm) | 317 | ds1685_rtc_set_time(struct device *dev, struct rtc_time *tm) |
319 | { | 318 | { |
320 | struct platform_device *pdev = to_platform_device(dev); | 319 | struct ds1685_priv *rtc = dev_get_drvdata(dev); |
321 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); | ||
322 | u8 ctrlb, seconds, minutes, hours, wday, mday, month, years, century; | 320 | u8 ctrlb, seconds, minutes, hours, wday, mday, month, years, century; |
323 | 321 | ||
324 | /* Fetch the time info from rtc_time. */ | 322 | /* Fetch the time info from rtc_time. */ |
@@ -394,8 +392,7 @@ ds1685_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
394 | static int | 392 | static int |
395 | ds1685_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 393 | ds1685_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
396 | { | 394 | { |
397 | struct platform_device *pdev = to_platform_device(dev); | 395 | struct ds1685_priv *rtc = dev_get_drvdata(dev); |
398 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); | ||
399 | u8 seconds, minutes, hours, mday, ctrlb, ctrlc; | 396 | u8 seconds, minutes, hours, mday, ctrlb, ctrlc; |
400 | int ret; | 397 | int ret; |
401 | 398 | ||
@@ -453,8 +450,7 @@ ds1685_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
453 | static int | 450 | static int |
454 | ds1685_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 451 | ds1685_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
455 | { | 452 | { |
456 | struct platform_device *pdev = to_platform_device(dev); | 453 | struct ds1685_priv *rtc = dev_get_drvdata(dev); |
457 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); | ||
458 | u8 ctrlb, seconds, minutes, hours, mday; | 454 | u8 ctrlb, seconds, minutes, hours, mday; |
459 | int ret; | 455 | int ret; |
460 | 456 | ||
@@ -1119,8 +1115,7 @@ static ssize_t | |||
1119 | ds1685_rtc_sysfs_battery_show(struct device *dev, | 1115 | ds1685_rtc_sysfs_battery_show(struct device *dev, |
1120 | struct device_attribute *attr, char *buf) | 1116 | struct device_attribute *attr, char *buf) |
1121 | { | 1117 | { |
1122 | struct platform_device *pdev = to_platform_device(dev); | 1118 | struct ds1685_priv *rtc = dev_get_drvdata(dev); |
1123 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); | ||
1124 | u8 ctrld; | 1119 | u8 ctrld; |
1125 | 1120 | ||
1126 | ctrld = rtc->read(rtc, RTC_CTRL_D); | 1121 | ctrld = rtc->read(rtc, RTC_CTRL_D); |
@@ -1140,8 +1135,7 @@ static ssize_t | |||
1140 | ds1685_rtc_sysfs_auxbatt_show(struct device *dev, | 1135 | ds1685_rtc_sysfs_auxbatt_show(struct device *dev, |
1141 | struct device_attribute *attr, char *buf) | 1136 | struct device_attribute *attr, char *buf) |
1142 | { | 1137 | { |
1143 | struct platform_device *pdev = to_platform_device(dev); | 1138 | struct ds1685_priv *rtc = dev_get_drvdata(dev); |
1144 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); | ||
1145 | u8 ctrl4a; | 1139 | u8 ctrl4a; |
1146 | 1140 | ||
1147 | ds1685_rtc_switch_to_bank1(rtc); | 1141 | ds1685_rtc_switch_to_bank1(rtc); |
@@ -1163,8 +1157,7 @@ static ssize_t | |||
1163 | ds1685_rtc_sysfs_serial_show(struct device *dev, | 1157 | ds1685_rtc_sysfs_serial_show(struct device *dev, |
1164 | struct device_attribute *attr, char *buf) | 1158 | struct device_attribute *attr, char *buf) |
1165 | { | 1159 | { |
1166 | struct platform_device *pdev = to_platform_device(dev); | 1160 | struct ds1685_priv *rtc = dev_get_drvdata(dev); |
1167 | struct ds1685_priv *rtc = platform_get_drvdata(pdev); | ||
1168 | u8 ssn[8]; | 1161 | u8 ssn[8]; |
1169 | 1162 | ||
1170 | ds1685_rtc_switch_to_bank1(rtc); | 1163 | ds1685_rtc_switch_to_bank1(rtc); |
@@ -2044,6 +2037,26 @@ ds1685_rtc_probe(struct platform_device *pdev) | |||
2044 | rtc->write(rtc, RTC_EXT_CTRL_4B, | 2037 | rtc->write(rtc, RTC_EXT_CTRL_4B, |
2045 | (rtc->read(rtc, RTC_EXT_CTRL_4B) | RTC_CTRL_4B_KSE)); | 2038 | (rtc->read(rtc, RTC_EXT_CTRL_4B) | RTC_CTRL_4B_KSE)); |
2046 | 2039 | ||
2040 | rtc_dev = devm_rtc_allocate_device(&pdev->dev); | ||
2041 | if (IS_ERR(rtc_dev)) | ||
2042 | return PTR_ERR(rtc_dev); | ||
2043 | |||
2044 | rtc_dev->ops = &ds1685_rtc_ops; | ||
2045 | |||
2046 | /* Century bit is useless because leap year fails in 1900 and 2100 */ | ||
2047 | rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000; | ||
2048 | rtc_dev->range_max = RTC_TIMESTAMP_END_2099; | ||
2049 | |||
2050 | /* Maximum periodic rate is 8192Hz (0.122070ms). */ | ||
2051 | rtc_dev->max_user_freq = RTC_MAX_USER_FREQ; | ||
2052 | |||
2053 | /* See if the platform doesn't support UIE. */ | ||
2054 | if (pdata->uie_unsupported) | ||
2055 | rtc_dev->uie_unsupported = 1; | ||
2056 | rtc->uie_unsupported = pdata->uie_unsupported; | ||
2057 | |||
2058 | rtc->dev = rtc_dev; | ||
2059 | |||
2047 | /* | 2060 | /* |
2048 | * Fetch the IRQ and setup the interrupt handler. | 2061 | * Fetch the IRQ and setup the interrupt handler. |
2049 | * | 2062 | * |
@@ -2076,32 +2089,13 @@ ds1685_rtc_probe(struct platform_device *pdev) | |||
2076 | /* Setup complete. */ | 2089 | /* Setup complete. */ |
2077 | ds1685_rtc_switch_to_bank0(rtc); | 2090 | ds1685_rtc_switch_to_bank0(rtc); |
2078 | 2091 | ||
2079 | /* Register the device as an RTC. */ | ||
2080 | rtc_dev = rtc_device_register(pdev->name, &pdev->dev, | ||
2081 | &ds1685_rtc_ops, THIS_MODULE); | ||
2082 | |||
2083 | /* Success? */ | ||
2084 | if (IS_ERR(rtc_dev)) | ||
2085 | return PTR_ERR(rtc_dev); | ||
2086 | |||
2087 | /* Maximum periodic rate is 8192Hz (0.122070ms). */ | ||
2088 | rtc_dev->max_user_freq = RTC_MAX_USER_FREQ; | ||
2089 | |||
2090 | /* See if the platform doesn't support UIE. */ | ||
2091 | if (pdata->uie_unsupported) | ||
2092 | rtc_dev->uie_unsupported = 1; | ||
2093 | rtc->uie_unsupported = pdata->uie_unsupported; | ||
2094 | |||
2095 | rtc->dev = rtc_dev; | ||
2096 | |||
2097 | #ifdef CONFIG_SYSFS | 2092 | #ifdef CONFIG_SYSFS |
2098 | ret = ds1685_rtc_sysfs_register(&pdev->dev); | 2093 | ret = ds1685_rtc_sysfs_register(&pdev->dev); |
2099 | if (ret) | 2094 | if (ret) |
2100 | rtc_device_unregister(rtc->dev); | 2095 | return ret; |
2101 | #endif | 2096 | #endif |
2102 | 2097 | ||
2103 | /* Done! */ | 2098 | return rtc_register_device(rtc_dev); |
2104 | return ret; | ||
2105 | } | 2099 | } |
2106 | 2100 | ||
2107 | /** | 2101 | /** |
@@ -2117,8 +2111,6 @@ ds1685_rtc_remove(struct platform_device *pdev) | |||
2117 | ds1685_rtc_sysfs_unregister(&pdev->dev); | 2111 | ds1685_rtc_sysfs_unregister(&pdev->dev); |
2118 | #endif | 2112 | #endif |
2119 | 2113 | ||
2120 | rtc_device_unregister(rtc->dev); | ||
2121 | |||
2122 | /* Read Ctrl B and clear PIE/AIE/UIE. */ | 2114 | /* Read Ctrl B and clear PIE/AIE/UIE. */ |
2123 | rtc->write(rtc, RTC_CTRL_B, | 2115 | rtc->write(rtc, RTC_CTRL_B, |
2124 | (rtc->read(rtc, RTC_CTRL_B) & | 2116 | (rtc->read(rtc, RTC_CTRL_B) & |
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c index 2d781180e968..5a4c2c5e86fe 100644 --- a/drivers/rtc/rtc-ds1742.c +++ b/drivers/rtc/rtc-ds1742.c | |||
@@ -58,8 +58,7 @@ struct rtc_plat_data { | |||
58 | 58 | ||
59 | static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm) | 59 | static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm) |
60 | { | 60 | { |
61 | struct platform_device *pdev = to_platform_device(dev); | 61 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
62 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
63 | void __iomem *ioaddr = pdata->ioaddr_rtc; | 62 | void __iomem *ioaddr = pdata->ioaddr_rtc; |
64 | u8 century; | 63 | u8 century; |
65 | 64 | ||
@@ -83,8 +82,7 @@ static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
83 | 82 | ||
84 | static int ds1742_rtc_read_time(struct device *dev, struct rtc_time *tm) | 83 | static int ds1742_rtc_read_time(struct device *dev, struct rtc_time *tm) |
85 | { | 84 | { |
86 | struct platform_device *pdev = to_platform_device(dev); | 85 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
87 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
88 | void __iomem *ioaddr = pdata->ioaddr_rtc; | 86 | void __iomem *ioaddr = pdata->ioaddr_rtc; |
89 | unsigned int year, month, day, hour, minute, second, week; | 87 | unsigned int year, month, day, hour, minute, second, week; |
90 | unsigned int century; | 88 | unsigned int century; |
@@ -154,8 +152,6 @@ static int ds1742_rtc_probe(struct platform_device *pdev) | |||
154 | int ret = 0; | 152 | int ret = 0; |
155 | struct nvmem_config nvmem_cfg = { | 153 | struct nvmem_config nvmem_cfg = { |
156 | .name = "ds1742_nvram", | 154 | .name = "ds1742_nvram", |
157 | .word_size = 1, | ||
158 | .stride = 1, | ||
159 | .reg_read = ds1742_nvram_read, | 155 | .reg_read = ds1742_nvram_read, |
160 | .reg_write = ds1742_nvram_write, | 156 | .reg_write = ds1742_nvram_write, |
161 | }; | 157 | }; |
diff --git a/drivers/rtc/rtc-ftrtc010.c b/drivers/rtc/rtc-ftrtc010.c index af8d6beae20c..61f798c6101f 100644 --- a/drivers/rtc/rtc-ftrtc010.c +++ b/drivers/rtc/rtc-ftrtc010.c | |||
@@ -73,8 +73,8 @@ static int ftrtc010_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
73 | { | 73 | { |
74 | struct ftrtc010_rtc *rtc = dev_get_drvdata(dev); | 74 | struct ftrtc010_rtc *rtc = dev_get_drvdata(dev); |
75 | 75 | ||
76 | unsigned int days, hour, min, sec; | 76 | u32 days, hour, min, sec, offset; |
77 | unsigned long offset, time; | 77 | timeu64_t time; |
78 | 78 | ||
79 | sec = readl(rtc->rtc_base + FTRTC010_RTC_SECOND); | 79 | sec = readl(rtc->rtc_base + FTRTC010_RTC_SECOND); |
80 | min = readl(rtc->rtc_base + FTRTC010_RTC_MINUTE); | 80 | min = readl(rtc->rtc_base + FTRTC010_RTC_MINUTE); |
@@ -84,7 +84,7 @@ static int ftrtc010_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
84 | 84 | ||
85 | time = offset + days * 86400 + hour * 3600 + min * 60 + sec; | 85 | time = offset + days * 86400 + hour * 3600 + min * 60 + sec; |
86 | 86 | ||
87 | rtc_time_to_tm(time, tm); | 87 | rtc_time64_to_tm(time, tm); |
88 | 88 | ||
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
@@ -92,13 +92,10 @@ static int ftrtc010_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
92 | static int ftrtc010_rtc_set_time(struct device *dev, struct rtc_time *tm) | 92 | static int ftrtc010_rtc_set_time(struct device *dev, struct rtc_time *tm) |
93 | { | 93 | { |
94 | struct ftrtc010_rtc *rtc = dev_get_drvdata(dev); | 94 | struct ftrtc010_rtc *rtc = dev_get_drvdata(dev); |
95 | unsigned int sec, min, hour, day; | 95 | u32 sec, min, hour, day, offset; |
96 | unsigned long offset, time; | 96 | timeu64_t time; |
97 | 97 | ||
98 | if (tm->tm_year >= 2148) /* EPOCH Year + 179 */ | 98 | time = rtc_tm_to_time64(tm); |
99 | return -EINVAL; | ||
100 | |||
101 | rtc_tm_to_time(tm, &time); | ||
102 | 99 | ||
103 | sec = readl(rtc->rtc_base + FTRTC010_RTC_SECOND); | 100 | sec = readl(rtc->rtc_base + FTRTC010_RTC_SECOND); |
104 | min = readl(rtc->rtc_base + FTRTC010_RTC_MINUTE); | 101 | min = readl(rtc->rtc_base + FTRTC010_RTC_MINUTE); |
@@ -120,6 +117,7 @@ static const struct rtc_class_ops ftrtc010_rtc_ops = { | |||
120 | 117 | ||
121 | static int ftrtc010_rtc_probe(struct platform_device *pdev) | 118 | static int ftrtc010_rtc_probe(struct platform_device *pdev) |
122 | { | 119 | { |
120 | u32 days, hour, min, sec; | ||
123 | struct ftrtc010_rtc *rtc; | 121 | struct ftrtc010_rtc *rtc; |
124 | struct device *dev = &pdev->dev; | 122 | struct device *dev = &pdev->dev; |
125 | struct resource *res; | 123 | struct resource *res; |
@@ -166,14 +164,27 @@ static int ftrtc010_rtc_probe(struct platform_device *pdev) | |||
166 | if (!rtc->rtc_base) | 164 | if (!rtc->rtc_base) |
167 | return -ENOMEM; | 165 | return -ENOMEM; |
168 | 166 | ||
167 | rtc->rtc_dev = devm_rtc_allocate_device(dev); | ||
168 | if (IS_ERR(rtc->rtc_dev)) | ||
169 | return PTR_ERR(rtc->rtc_dev); | ||
170 | |||
171 | rtc->rtc_dev->ops = &ftrtc010_rtc_ops; | ||
172 | |||
173 | sec = readl(rtc->rtc_base + FTRTC010_RTC_SECOND); | ||
174 | min = readl(rtc->rtc_base + FTRTC010_RTC_MINUTE); | ||
175 | hour = readl(rtc->rtc_base + FTRTC010_RTC_HOUR); | ||
176 | days = readl(rtc->rtc_base + FTRTC010_RTC_DAYS); | ||
177 | |||
178 | rtc->rtc_dev->range_min = (u64)days * 86400 + hour * 3600 + | ||
179 | min * 60 + sec; | ||
180 | rtc->rtc_dev->range_max = U32_MAX + rtc->rtc_dev->range_min; | ||
181 | |||
169 | ret = devm_request_irq(dev, rtc->rtc_irq, ftrtc010_rtc_interrupt, | 182 | ret = devm_request_irq(dev, rtc->rtc_irq, ftrtc010_rtc_interrupt, |
170 | IRQF_SHARED, pdev->name, dev); | 183 | IRQF_SHARED, pdev->name, dev); |
171 | if (unlikely(ret)) | 184 | if (unlikely(ret)) |
172 | return ret; | 185 | return ret; |
173 | 186 | ||
174 | rtc->rtc_dev = rtc_device_register(pdev->name, dev, | 187 | return rtc_register_device(rtc->rtc_dev); |
175 | &ftrtc010_rtc_ops, THIS_MODULE); | ||
176 | return PTR_ERR_OR_ZERO(rtc->rtc_dev); | ||
177 | } | 188 | } |
178 | 189 | ||
179 | static int ftrtc010_rtc_remove(struct platform_device *pdev) | 190 | static int ftrtc010_rtc_remove(struct platform_device *pdev) |
@@ -184,7 +195,6 @@ static int ftrtc010_rtc_remove(struct platform_device *pdev) | |||
184 | clk_disable_unprepare(rtc->extclk); | 195 | clk_disable_unprepare(rtc->extclk); |
185 | if (!IS_ERR(rtc->pclk)) | 196 | if (!IS_ERR(rtc->pclk)) |
186 | clk_disable_unprepare(rtc->pclk); | 197 | clk_disable_unprepare(rtc->pclk); |
187 | rtc_device_unregister(rtc->rtc_dev); | ||
188 | 198 | ||
189 | return 0; | 199 | return 0; |
190 | } | 200 | } |
diff --git a/drivers/rtc/rtc-lpc32xx.c b/drivers/rtc/rtc-lpc32xx.c index 3ba87239aacc..910e600275b9 100644 --- a/drivers/rtc/rtc-lpc32xx.c +++ b/drivers/rtc/rtc-lpc32xx.c | |||
@@ -294,11 +294,10 @@ static int lpc32xx_rtc_remove(struct platform_device *pdev) | |||
294 | #ifdef CONFIG_PM | 294 | #ifdef CONFIG_PM |
295 | static int lpc32xx_rtc_suspend(struct device *dev) | 295 | static int lpc32xx_rtc_suspend(struct device *dev) |
296 | { | 296 | { |
297 | struct platform_device *pdev = to_platform_device(dev); | 297 | struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); |
298 | struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); | ||
299 | 298 | ||
300 | if (rtc->irq >= 0) { | 299 | if (rtc->irq >= 0) { |
301 | if (device_may_wakeup(&pdev->dev)) | 300 | if (device_may_wakeup(dev)) |
302 | enable_irq_wake(rtc->irq); | 301 | enable_irq_wake(rtc->irq); |
303 | else | 302 | else |
304 | disable_irq_wake(rtc->irq); | 303 | disable_irq_wake(rtc->irq); |
@@ -309,10 +308,9 @@ static int lpc32xx_rtc_suspend(struct device *dev) | |||
309 | 308 | ||
310 | static int lpc32xx_rtc_resume(struct device *dev) | 309 | static int lpc32xx_rtc_resume(struct device *dev) |
311 | { | 310 | { |
312 | struct platform_device *pdev = to_platform_device(dev); | 311 | struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); |
313 | struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); | ||
314 | 312 | ||
315 | if (rtc->irq >= 0 && device_may_wakeup(&pdev->dev)) | 313 | if (rtc->irq >= 0 && device_may_wakeup(dev)) |
316 | disable_irq_wake(rtc->irq); | 314 | disable_irq_wake(rtc->irq); |
317 | 315 | ||
318 | return 0; | 316 | return 0; |
@@ -321,8 +319,7 @@ static int lpc32xx_rtc_resume(struct device *dev) | |||
321 | /* Unconditionally disable the alarm */ | 319 | /* Unconditionally disable the alarm */ |
322 | static int lpc32xx_rtc_freeze(struct device *dev) | 320 | static int lpc32xx_rtc_freeze(struct device *dev) |
323 | { | 321 | { |
324 | struct platform_device *pdev = to_platform_device(dev); | 322 | struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); |
325 | struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); | ||
326 | 323 | ||
327 | spin_lock_irq(&rtc->lock); | 324 | spin_lock_irq(&rtc->lock); |
328 | 325 | ||
@@ -337,8 +334,7 @@ static int lpc32xx_rtc_freeze(struct device *dev) | |||
337 | 334 | ||
338 | static int lpc32xx_rtc_thaw(struct device *dev) | 335 | static int lpc32xx_rtc_thaw(struct device *dev) |
339 | { | 336 | { |
340 | struct platform_device *pdev = to_platform_device(dev); | 337 | struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); |
341 | struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); | ||
342 | 338 | ||
343 | if (rtc->alarm_enabled) { | 339 | if (rtc->alarm_enabled) { |
344 | spin_lock_irq(&rtc->lock); | 340 | spin_lock_irq(&rtc->lock); |
diff --git a/drivers/rtc/rtc-ls1x.c b/drivers/rtc/rtc-ls1x.c index 045af1135e48..f4c248655edd 100644 --- a/drivers/rtc/rtc-ls1x.c +++ b/drivers/rtc/rtc-ls1x.c | |||
@@ -87,16 +87,17 @@ | |||
87 | 87 | ||
88 | static int ls1x_rtc_read_time(struct device *dev, struct rtc_time *rtm) | 88 | static int ls1x_rtc_read_time(struct device *dev, struct rtc_time *rtm) |
89 | { | 89 | { |
90 | unsigned long v, t; | 90 | unsigned long v; |
91 | time64_t t; | ||
91 | 92 | ||
92 | v = readl(SYS_TOYREAD0); | 93 | v = readl(SYS_TOYREAD0); |
93 | t = readl(SYS_TOYREAD1); | 94 | t = readl(SYS_TOYREAD1); |
94 | 95 | ||
95 | memset(rtm, 0, sizeof(struct rtc_time)); | 96 | memset(rtm, 0, sizeof(struct rtc_time)); |
96 | t = mktime((t & LS1X_YEAR_MASK), ls1x_get_month(v), | 97 | t = mktime64((t & LS1X_YEAR_MASK), ls1x_get_month(v), |
97 | ls1x_get_day(v), ls1x_get_hour(v), | 98 | ls1x_get_day(v), ls1x_get_hour(v), |
98 | ls1x_get_min(v), ls1x_get_sec(v)); | 99 | ls1x_get_min(v), ls1x_get_sec(v)); |
99 | rtc_time_to_tm(t, rtm); | 100 | rtc_time64_to_tm(t, rtm); |
100 | 101 | ||
101 | return 0; | 102 | return 0; |
102 | } | 103 | } |
@@ -147,15 +148,13 @@ static int ls1x_rtc_probe(struct platform_device *pdev) | |||
147 | { | 148 | { |
148 | struct rtc_device *rtcdev; | 149 | struct rtc_device *rtcdev; |
149 | unsigned long v; | 150 | unsigned long v; |
150 | int ret; | ||
151 | 151 | ||
152 | v = readl(SYS_COUNTER_CNTRL); | 152 | v = readl(SYS_COUNTER_CNTRL); |
153 | if (!(v & RTC_CNTR_OK)) { | 153 | if (!(v & RTC_CNTR_OK)) { |
154 | dev_err(&pdev->dev, "rtc counters not working\n"); | 154 | dev_err(&pdev->dev, "rtc counters not working\n"); |
155 | ret = -ENODEV; | 155 | return -ENODEV; |
156 | goto err; | ||
157 | } | 156 | } |
158 | ret = -ETIMEDOUT; | 157 | |
159 | /* set to 1 HZ if needed */ | 158 | /* set to 1 HZ if needed */ |
160 | if (readl(SYS_TOYTRIM) != 32767) { | 159 | if (readl(SYS_TOYTRIM) != 32767) { |
161 | v = 0x100000; | 160 | v = 0x100000; |
@@ -164,7 +163,7 @@ static int ls1x_rtc_probe(struct platform_device *pdev) | |||
164 | 163 | ||
165 | if (!v) { | 164 | if (!v) { |
166 | dev_err(&pdev->dev, "time out\n"); | 165 | dev_err(&pdev->dev, "time out\n"); |
167 | goto err; | 166 | return -ETIMEDOUT; |
168 | } | 167 | } |
169 | writel(32767, SYS_TOYTRIM); | 168 | writel(32767, SYS_TOYTRIM); |
170 | } | 169 | } |
@@ -172,17 +171,16 @@ static int ls1x_rtc_probe(struct platform_device *pdev) | |||
172 | while (readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_TTS) | 171 | while (readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_TTS) |
173 | usleep_range(1000, 3000); | 172 | usleep_range(1000, 3000); |
174 | 173 | ||
175 | rtcdev = devm_rtc_device_register(&pdev->dev, "ls1x-rtc", | 174 | rtcdev = devm_rtc_allocate_device(&pdev->dev); |
176 | &ls1x_rtc_ops , THIS_MODULE); | 175 | if (IS_ERR(rtcdev)) |
177 | if (IS_ERR(rtcdev)) { | 176 | return PTR_ERR(rtcdev); |
178 | ret = PTR_ERR(rtcdev); | ||
179 | goto err; | ||
180 | } | ||
181 | 177 | ||
182 | platform_set_drvdata(pdev, rtcdev); | 178 | platform_set_drvdata(pdev, rtcdev); |
183 | return 0; | 179 | rtcdev->ops = &ls1x_rtc_ops; |
184 | err: | 180 | rtcdev->range_min = RTC_TIMESTAMP_BEGIN_1900; |
185 | return ret; | 181 | rtcdev->range_max = RTC_TIMESTAMP_END_2099; |
182 | |||
183 | return rtc_register_device(rtcdev); | ||
186 | } | 184 | } |
187 | 185 | ||
188 | static struct platform_driver ls1x_rtc_driver = { | 186 | static struct platform_driver ls1x_rtc_driver = { |
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c index 216fac62c888..1053a406b3aa 100644 --- a/drivers/rtc/rtc-m48t59.c +++ b/drivers/rtc/rtc-m48t59.c | |||
@@ -47,8 +47,7 @@ struct m48t59_private { | |||
47 | static void | 47 | static void |
48 | m48t59_mem_writeb(struct device *dev, u32 ofs, u8 val) | 48 | m48t59_mem_writeb(struct device *dev, u32 ofs, u8 val) |
49 | { | 49 | { |
50 | struct platform_device *pdev = to_platform_device(dev); | 50 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
51 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
52 | 51 | ||
53 | writeb(val, m48t59->ioaddr+ofs); | 52 | writeb(val, m48t59->ioaddr+ofs); |
54 | } | 53 | } |
@@ -56,8 +55,7 @@ m48t59_mem_writeb(struct device *dev, u32 ofs, u8 val) | |||
56 | static u8 | 55 | static u8 |
57 | m48t59_mem_readb(struct device *dev, u32 ofs) | 56 | m48t59_mem_readb(struct device *dev, u32 ofs) |
58 | { | 57 | { |
59 | struct platform_device *pdev = to_platform_device(dev); | 58 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
60 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
61 | 59 | ||
62 | return readb(m48t59->ioaddr+ofs); | 60 | return readb(m48t59->ioaddr+ofs); |
63 | } | 61 | } |
@@ -67,9 +65,8 @@ m48t59_mem_readb(struct device *dev, u32 ofs) | |||
67 | */ | 65 | */ |
68 | static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm) | 66 | static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm) |
69 | { | 67 | { |
70 | struct platform_device *pdev = to_platform_device(dev); | 68 | struct m48t59_plat_data *pdata = dev_get_platdata(dev); |
71 | struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); | 69 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
72 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
73 | unsigned long flags; | 70 | unsigned long flags; |
74 | u8 val; | 71 | u8 val; |
75 | 72 | ||
@@ -110,9 +107,8 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
110 | 107 | ||
111 | static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) | 108 | static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) |
112 | { | 109 | { |
113 | struct platform_device *pdev = to_platform_device(dev); | 110 | struct m48t59_plat_data *pdata = dev_get_platdata(dev); |
114 | struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); | 111 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
115 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
116 | unsigned long flags; | 112 | unsigned long flags; |
117 | u8 val = 0; | 113 | u8 val = 0; |
118 | int year = tm->tm_year; | 114 | int year = tm->tm_year; |
@@ -157,9 +153,8 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
157 | */ | 153 | */ |
158 | static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) | 154 | static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) |
159 | { | 155 | { |
160 | struct platform_device *pdev = to_platform_device(dev); | 156 | struct m48t59_plat_data *pdata = dev_get_platdata(dev); |
161 | struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); | 157 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
162 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
163 | struct rtc_time *tm = &alrm->time; | 158 | struct rtc_time *tm = &alrm->time; |
164 | unsigned long flags; | 159 | unsigned long flags; |
165 | u8 val; | 160 | u8 val; |
@@ -204,9 +199,8 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
204 | */ | 199 | */ |
205 | static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | 200 | static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) |
206 | { | 201 | { |
207 | struct platform_device *pdev = to_platform_device(dev); | 202 | struct m48t59_plat_data *pdata = dev_get_platdata(dev); |
208 | struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); | 203 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
209 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
210 | struct rtc_time *tm = &alrm->time; | 204 | struct rtc_time *tm = &alrm->time; |
211 | u8 mday, hour, min, sec; | 205 | u8 mday, hour, min, sec; |
212 | unsigned long flags; | 206 | unsigned long flags; |
@@ -265,9 +259,8 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
265 | */ | 259 | */ |
266 | static int m48t59_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | 260 | static int m48t59_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
267 | { | 261 | { |
268 | struct platform_device *pdev = to_platform_device(dev); | 262 | struct m48t59_plat_data *pdata = dev_get_platdata(dev); |
269 | struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); | 263 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
270 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
271 | unsigned long flags; | 264 | unsigned long flags; |
272 | 265 | ||
273 | spin_lock_irqsave(&m48t59->lock, flags); | 266 | spin_lock_irqsave(&m48t59->lock, flags); |
@@ -282,9 +275,8 @@ static int m48t59_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | |||
282 | 275 | ||
283 | static int m48t59_rtc_proc(struct device *dev, struct seq_file *seq) | 276 | static int m48t59_rtc_proc(struct device *dev, struct seq_file *seq) |
284 | { | 277 | { |
285 | struct platform_device *pdev = to_platform_device(dev); | 278 | struct m48t59_plat_data *pdata = dev_get_platdata(dev); |
286 | struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); | 279 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
287 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
288 | unsigned long flags; | 280 | unsigned long flags; |
289 | u8 val; | 281 | u8 val; |
290 | 282 | ||
@@ -303,9 +295,8 @@ static int m48t59_rtc_proc(struct device *dev, struct seq_file *seq) | |||
303 | static irqreturn_t m48t59_rtc_interrupt(int irq, void *dev_id) | 295 | static irqreturn_t m48t59_rtc_interrupt(int irq, void *dev_id) |
304 | { | 296 | { |
305 | struct device *dev = (struct device *)dev_id; | 297 | struct device *dev = (struct device *)dev_id; |
306 | struct platform_device *pdev = to_platform_device(dev); | 298 | struct m48t59_plat_data *pdata = dev_get_platdata(dev); |
307 | struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); | 299 | struct m48t59_private *m48t59 = dev_get_drvdata(dev); |
308 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | ||
309 | u8 event; | 300 | u8 event; |
310 | 301 | ||
311 | spin_lock(&m48t59->lock); | 302 | spin_lock(&m48t59->lock); |
diff --git a/drivers/rtc/rtc-mrst.c b/drivers/rtc/rtc-mrst.c index fcb9de5218b2..097a4d4e2aba 100644 --- a/drivers/rtc/rtc-mrst.c +++ b/drivers/rtc/rtc-mrst.c | |||
@@ -45,7 +45,6 @@ struct mrst_rtc { | |||
45 | struct rtc_device *rtc; | 45 | struct rtc_device *rtc; |
46 | struct device *dev; | 46 | struct device *dev; |
47 | int irq; | 47 | int irq; |
48 | struct resource *iomem; | ||
49 | 48 | ||
50 | u8 enabled_wake; | 49 | u8 enabled_wake; |
51 | u8 suspend_ctrl; | 50 | u8 suspend_ctrl; |
@@ -329,24 +328,22 @@ static int vrtc_mrst_do_probe(struct device *dev, struct resource *iomem, | |||
329 | if (!iomem) | 328 | if (!iomem) |
330 | return -ENODEV; | 329 | return -ENODEV; |
331 | 330 | ||
332 | iomem = request_mem_region(iomem->start, resource_size(iomem), | 331 | iomem = devm_request_mem_region(dev, iomem->start, resource_size(iomem), |
333 | driver_name); | 332 | driver_name); |
334 | if (!iomem) { | 333 | if (!iomem) { |
335 | dev_dbg(dev, "i/o mem already in use.\n"); | 334 | dev_dbg(dev, "i/o mem already in use.\n"); |
336 | return -EBUSY; | 335 | return -EBUSY; |
337 | } | 336 | } |
338 | 337 | ||
339 | mrst_rtc.irq = rtc_irq; | 338 | mrst_rtc.irq = rtc_irq; |
340 | mrst_rtc.iomem = iomem; | ||
341 | mrst_rtc.dev = dev; | 339 | mrst_rtc.dev = dev; |
342 | dev_set_drvdata(dev, &mrst_rtc); | 340 | dev_set_drvdata(dev, &mrst_rtc); |
343 | 341 | ||
344 | mrst_rtc.rtc = rtc_device_register(driver_name, dev, | 342 | mrst_rtc.rtc = devm_rtc_allocate_device(dev); |
345 | &mrst_rtc_ops, THIS_MODULE); | 343 | if (IS_ERR(mrst_rtc.rtc)) |
346 | if (IS_ERR(mrst_rtc.rtc)) { | 344 | return PTR_ERR(mrst_rtc.rtc); |
347 | retval = PTR_ERR(mrst_rtc.rtc); | 345 | |
348 | goto cleanup0; | 346 | mrst_rtc.rtc->ops = &mrst_rtc_ops; |
349 | } | ||
350 | 347 | ||
351 | rename_region(iomem, dev_name(&mrst_rtc.rtc->dev)); | 348 | rename_region(iomem, dev_name(&mrst_rtc.rtc->dev)); |
352 | 349 | ||
@@ -359,23 +356,27 @@ static int vrtc_mrst_do_probe(struct device *dev, struct resource *iomem, | |||
359 | dev_dbg(dev, "TODO: support more than 24-hr BCD mode\n"); | 356 | dev_dbg(dev, "TODO: support more than 24-hr BCD mode\n"); |
360 | 357 | ||
361 | if (rtc_irq) { | 358 | if (rtc_irq) { |
362 | retval = request_irq(rtc_irq, mrst_rtc_irq, | 359 | retval = devm_request_irq(dev, rtc_irq, mrst_rtc_irq, |
363 | 0, dev_name(&mrst_rtc.rtc->dev), | 360 | 0, dev_name(&mrst_rtc.rtc->dev), |
364 | mrst_rtc.rtc); | 361 | mrst_rtc.rtc); |
365 | if (retval < 0) { | 362 | if (retval < 0) { |
366 | dev_dbg(dev, "IRQ %d is already in use, err %d\n", | 363 | dev_dbg(dev, "IRQ %d is already in use, err %d\n", |
367 | rtc_irq, retval); | 364 | rtc_irq, retval); |
368 | goto cleanup1; | 365 | goto cleanup0; |
369 | } | 366 | } |
370 | } | 367 | } |
368 | |||
369 | retval = rtc_register_device(mrst_rtc.rtc); | ||
370 | if (retval) { | ||
371 | retval = PTR_ERR(mrst_rtc.rtc); | ||
372 | goto cleanup0; | ||
373 | } | ||
374 | |||
371 | dev_dbg(dev, "initialised\n"); | 375 | dev_dbg(dev, "initialised\n"); |
372 | return 0; | 376 | return 0; |
373 | 377 | ||
374 | cleanup1: | ||
375 | rtc_device_unregister(mrst_rtc.rtc); | ||
376 | cleanup0: | 378 | cleanup0: |
377 | mrst_rtc.dev = NULL; | 379 | mrst_rtc.dev = NULL; |
378 | release_mem_region(iomem->start, resource_size(iomem)); | ||
379 | dev_err(dev, "rtc-mrst: unable to initialise\n"); | 380 | dev_err(dev, "rtc-mrst: unable to initialise\n"); |
380 | return retval; | 381 | return retval; |
381 | } | 382 | } |
@@ -390,20 +391,10 @@ static void rtc_mrst_do_shutdown(void) | |||
390 | static void rtc_mrst_do_remove(struct device *dev) | 391 | static void rtc_mrst_do_remove(struct device *dev) |
391 | { | 392 | { |
392 | struct mrst_rtc *mrst = dev_get_drvdata(dev); | 393 | struct mrst_rtc *mrst = dev_get_drvdata(dev); |
393 | struct resource *iomem; | ||
394 | 394 | ||
395 | rtc_mrst_do_shutdown(); | 395 | rtc_mrst_do_shutdown(); |
396 | 396 | ||
397 | if (mrst->irq) | ||
398 | free_irq(mrst->irq, mrst->rtc); | ||
399 | |||
400 | rtc_device_unregister(mrst->rtc); | ||
401 | mrst->rtc = NULL; | 397 | mrst->rtc = NULL; |
402 | |||
403 | iomem = mrst->iomem; | ||
404 | release_mem_region(iomem->start, resource_size(iomem)); | ||
405 | mrst->iomem = NULL; | ||
406 | |||
407 | mrst->dev = NULL; | 398 | mrst->dev = NULL; |
408 | } | 399 | } |
409 | 400 | ||
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c index bc52dbb0c0e2..4b198b3778d3 100644 --- a/drivers/rtc/rtc-mv.c +++ b/drivers/rtc/rtc-mv.c | |||
@@ -176,8 +176,7 @@ static int mv_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) | |||
176 | 176 | ||
177 | static int mv_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | 177 | static int mv_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
178 | { | 178 | { |
179 | struct platform_device *pdev = to_platform_device(dev); | 179 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
180 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
181 | void __iomem *ioaddr = pdata->ioaddr; | 180 | void __iomem *ioaddr = pdata->ioaddr; |
182 | 181 | ||
183 | if (pdata->irq < 0) | 182 | if (pdata->irq < 0) |
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c index bce427d202ee..878c6ee82901 100644 --- a/drivers/rtc/rtc-mxc.c +++ b/drivers/rtc/rtc-mxc.c | |||
@@ -1,13 +1,6 @@ | |||
1 | /* | 1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | * Copyright 2004-2008 Freescale Semiconductor, Inc. All Rights Reserved. | 2 | // |
3 | * | 3 | // Copyright 2004-2008 Freescale Semiconductor, Inc. All Rights Reserved. |
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | 4 | ||
12 | #include <linux/io.h> | 5 | #include <linux/io.h> |
13 | #include <linux/rtc.h> | 6 | #include <linux/rtc.h> |
@@ -109,8 +102,7 @@ static inline int is_imx1_rtc(struct rtc_plat_data *data) | |||
109 | */ | 102 | */ |
110 | static time64_t get_alarm_or_time(struct device *dev, int time_alarm) | 103 | static time64_t get_alarm_or_time(struct device *dev, int time_alarm) |
111 | { | 104 | { |
112 | struct platform_device *pdev = to_platform_device(dev); | 105 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
113 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
114 | void __iomem *ioaddr = pdata->ioaddr; | 106 | void __iomem *ioaddr = pdata->ioaddr; |
115 | u32 day = 0, hr = 0, min = 0, sec = 0, hr_min = 0; | 107 | u32 day = 0, hr = 0, min = 0, sec = 0, hr_min = 0; |
116 | 108 | ||
@@ -139,8 +131,7 @@ static time64_t get_alarm_or_time(struct device *dev, int time_alarm) | |||
139 | static void set_alarm_or_time(struct device *dev, int time_alarm, time64_t time) | 131 | static void set_alarm_or_time(struct device *dev, int time_alarm, time64_t time) |
140 | { | 132 | { |
141 | u32 tod, day, hr, min, sec, temp; | 133 | u32 tod, day, hr, min, sec, temp; |
142 | struct platform_device *pdev = to_platform_device(dev); | 134 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
143 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
144 | void __iomem *ioaddr = pdata->ioaddr; | 135 | void __iomem *ioaddr = pdata->ioaddr; |
145 | 136 | ||
146 | day = div_s64_rem(time, 86400, &tod); | 137 | day = div_s64_rem(time, 86400, &tod); |
@@ -176,8 +167,7 @@ static void set_alarm_or_time(struct device *dev, int time_alarm, time64_t time) | |||
176 | static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm) | 167 | static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm) |
177 | { | 168 | { |
178 | time64_t time; | 169 | time64_t time; |
179 | struct platform_device *pdev = to_platform_device(dev); | 170 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
180 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
181 | void __iomem *ioaddr = pdata->ioaddr; | 171 | void __iomem *ioaddr = pdata->ioaddr; |
182 | 172 | ||
183 | time = rtc_tm_to_time64(alrm); | 173 | time = rtc_tm_to_time64(alrm); |
@@ -190,8 +180,7 @@ static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm) | |||
190 | static void mxc_rtc_irq_enable(struct device *dev, unsigned int bit, | 180 | static void mxc_rtc_irq_enable(struct device *dev, unsigned int bit, |
191 | unsigned int enabled) | 181 | unsigned int enabled) |
192 | { | 182 | { |
193 | struct platform_device *pdev = to_platform_device(dev); | 183 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
194 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
195 | void __iomem *ioaddr = pdata->ioaddr; | 184 | void __iomem *ioaddr = pdata->ioaddr; |
196 | u32 reg; | 185 | u32 reg; |
197 | 186 | ||
@@ -266,8 +255,7 @@ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
266 | */ | 255 | */ |
267 | static int mxc_rtc_set_mmss(struct device *dev, time64_t time) | 256 | static int mxc_rtc_set_mmss(struct device *dev, time64_t time) |
268 | { | 257 | { |
269 | struct platform_device *pdev = to_platform_device(dev); | 258 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
270 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
271 | 259 | ||
272 | /* | 260 | /* |
273 | * TTC_DAYR register is 9-bit in MX1 SoC, save time and day of year only | 261 | * TTC_DAYR register is 9-bit in MX1 SoC, save time and day of year only |
@@ -295,8 +283,7 @@ static int mxc_rtc_set_mmss(struct device *dev, time64_t time) | |||
295 | */ | 283 | */ |
296 | static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 284 | static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
297 | { | 285 | { |
298 | struct platform_device *pdev = to_platform_device(dev); | 286 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
299 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
300 | void __iomem *ioaddr = pdata->ioaddr; | 287 | void __iomem *ioaddr = pdata->ioaddr; |
301 | 288 | ||
302 | rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); | 289 | rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); |
@@ -310,8 +297,7 @@ static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
310 | */ | 297 | */ |
311 | static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 298 | static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
312 | { | 299 | { |
313 | struct platform_device *pdev = to_platform_device(dev); | 300 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
314 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
315 | 301 | ||
316 | rtc_update_alarm(dev, &alrm->time); | 302 | rtc_update_alarm(dev, &alrm->time); |
317 | 303 | ||
diff --git a/drivers/rtc/rtc-mxc_v2.c b/drivers/rtc/rtc-mxc_v2.c index 9e14efb990b2..c75f26dc8fcc 100644 --- a/drivers/rtc/rtc-mxc_v2.c +++ b/drivers/rtc/rtc-mxc_v2.c | |||
@@ -165,11 +165,6 @@ static int mxc_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
165 | time64_t time = rtc_tm_to_time64(tm); | 165 | time64_t time = rtc_tm_to_time64(tm); |
166 | int ret; | 166 | int ret; |
167 | 167 | ||
168 | if (time > U32_MAX) { | ||
169 | dev_err(dev, "RTC exceeded by %llus\n", time - U32_MAX); | ||
170 | return -EINVAL; | ||
171 | } | ||
172 | |||
173 | ret = mxc_rtc_lock(pdata); | 168 | ret = mxc_rtc_lock(pdata); |
174 | if (ret) | 169 | if (ret) |
175 | return ret; | 170 | return ret; |
@@ -198,7 +193,7 @@ static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
198 | if (ret) | 193 | if (ret) |
199 | return ret; | 194 | return ret; |
200 | 195 | ||
201 | rtc_time_to_tm(readl(ioaddr + SRTC_LPSAR), &alrm->time); | 196 | rtc_time64_to_tm(readl(ioaddr + SRTC_LPSAR), &alrm->time); |
202 | alrm->pending = !!(readl(ioaddr + SRTC_LPSR) & SRTC_LPSR_ALP); | 197 | alrm->pending = !!(readl(ioaddr + SRTC_LPSR) & SRTC_LPSR_ALP); |
203 | return mxc_rtc_unlock(pdata); | 198 | return mxc_rtc_unlock(pdata); |
204 | } | 199 | } |
@@ -248,11 +243,6 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
248 | if (ret) | 243 | if (ret) |
249 | return ret; | 244 | return ret; |
250 | 245 | ||
251 | if (time > U32_MAX) { | ||
252 | dev_err(dev, "Hopefully I am out of service by then :-(\n"); | ||
253 | return -EINVAL; | ||
254 | } | ||
255 | |||
256 | writel((u32)time, pdata->ioaddr + SRTC_LPSAR); | 246 | writel((u32)time, pdata->ioaddr + SRTC_LPSAR); |
257 | 247 | ||
258 | /* clear alarm interrupt status bit */ | 248 | /* clear alarm interrupt status bit */ |
@@ -343,6 +333,13 @@ static int mxc_rtc_probe(struct platform_device *pdev) | |||
343 | return ret; | 333 | return ret; |
344 | } | 334 | } |
345 | 335 | ||
336 | pdata->rtc = devm_rtc_allocate_device(&pdev->dev); | ||
337 | if (IS_ERR(pdata->rtc)) | ||
338 | return PTR_ERR(pdata->rtc); | ||
339 | |||
340 | pdata->rtc->ops = &mxc_rtc_ops; | ||
341 | pdata->rtc->range_max = U32_MAX; | ||
342 | |||
346 | clk_disable(pdata->clk); | 343 | clk_disable(pdata->clk); |
347 | platform_set_drvdata(pdev, pdata); | 344 | platform_set_drvdata(pdev, pdata); |
348 | ret = | 345 | ret = |
@@ -354,15 +351,11 @@ static int mxc_rtc_probe(struct platform_device *pdev) | |||
354 | return ret; | 351 | return ret; |
355 | } | 352 | } |
356 | 353 | ||
357 | pdata->rtc = | 354 | ret = rtc_register_device(pdata->rtc); |
358 | devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops, | 355 | if (ret < 0) |
359 | THIS_MODULE); | ||
360 | if (IS_ERR(pdata->rtc)) { | ||
361 | clk_unprepare(pdata->clk); | 356 | clk_unprepare(pdata->clk); |
362 | return PTR_ERR(pdata->rtc); | ||
363 | } | ||
364 | 357 | ||
365 | return 0; | 358 | return ret; |
366 | } | 359 | } |
367 | 360 | ||
368 | static int mxc_rtc_remove(struct platform_device *pdev) | 361 | static int mxc_rtc_remove(struct platform_device *pdev) |
diff --git a/drivers/rtc/rtc-pcap.c b/drivers/rtc/rtc-pcap.c index c05f524ba9af..f176cb9d0dbc 100644 --- a/drivers/rtc/rtc-pcap.c +++ b/drivers/rtc/rtc-pcap.c | |||
@@ -43,8 +43,7 @@ static irqreturn_t pcap_rtc_irq(int irq, void *_pcap_rtc) | |||
43 | 43 | ||
44 | static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 44 | static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
45 | { | 45 | { |
46 | struct platform_device *pdev = to_platform_device(dev); | 46 | struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); |
47 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
48 | struct rtc_time *tm = &alrm->time; | 47 | struct rtc_time *tm = &alrm->time; |
49 | unsigned long secs; | 48 | unsigned long secs; |
50 | u32 tod; /* time of day, seconds since midnight */ | 49 | u32 tod; /* time of day, seconds since midnight */ |
@@ -63,8 +62,7 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
63 | 62 | ||
64 | static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 63 | static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
65 | { | 64 | { |
66 | struct platform_device *pdev = to_platform_device(dev); | 65 | struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); |
67 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
68 | struct rtc_time *tm = &alrm->time; | 66 | struct rtc_time *tm = &alrm->time; |
69 | unsigned long secs; | 67 | unsigned long secs; |
70 | u32 tod, days; | 68 | u32 tod, days; |
@@ -82,8 +80,7 @@ static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
82 | 80 | ||
83 | static int pcap_rtc_read_time(struct device *dev, struct rtc_time *tm) | 81 | static int pcap_rtc_read_time(struct device *dev, struct rtc_time *tm) |
84 | { | 82 | { |
85 | struct platform_device *pdev = to_platform_device(dev); | 83 | struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); |
86 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
87 | unsigned long secs; | 84 | unsigned long secs; |
88 | u32 tod, days; | 85 | u32 tod, days; |
89 | 86 | ||
@@ -100,8 +97,7 @@ static int pcap_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
100 | 97 | ||
101 | static int pcap_rtc_set_mmss(struct device *dev, unsigned long secs) | 98 | static int pcap_rtc_set_mmss(struct device *dev, unsigned long secs) |
102 | { | 99 | { |
103 | struct platform_device *pdev = to_platform_device(dev); | 100 | struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); |
104 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
105 | u32 tod, days; | 101 | u32 tod, days; |
106 | 102 | ||
107 | tod = secs % SEC_PER_DAY; | 103 | tod = secs % SEC_PER_DAY; |
@@ -115,8 +111,7 @@ static int pcap_rtc_set_mmss(struct device *dev, unsigned long secs) | |||
115 | 111 | ||
116 | static int pcap_rtc_irq_enable(struct device *dev, int pirq, unsigned int en) | 112 | static int pcap_rtc_irq_enable(struct device *dev, int pirq, unsigned int en) |
117 | { | 113 | { |
118 | struct platform_device *pdev = to_platform_device(dev); | 114 | struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); |
119 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
120 | 115 | ||
121 | if (en) | 116 | if (en) |
122 | enable_irq(pcap_to_irq(pcap_rtc->pcap, pirq)); | 117 | enable_irq(pcap_to_irq(pcap_rtc->pcap, pirq)); |
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c index 47304f5664d8..e1887b86fdc7 100644 --- a/drivers/rtc/rtc-pxa.c +++ b/drivers/rtc/rtc-pxa.c | |||
@@ -363,7 +363,7 @@ static int __init pxa_rtc_probe(struct platform_device *pdev) | |||
363 | sa1100_rtc->rtar = pxa_rtc->base + 0x4; | 363 | sa1100_rtc->rtar = pxa_rtc->base + 0x4; |
364 | sa1100_rtc->rttr = pxa_rtc->base + 0xc; | 364 | sa1100_rtc->rttr = pxa_rtc->base + 0xc; |
365 | ret = sa1100_rtc_init(pdev, sa1100_rtc); | 365 | ret = sa1100_rtc_init(pdev, sa1100_rtc); |
366 | if (!ret) { | 366 | if (ret) { |
367 | dev_err(dev, "Unable to init SA1100 RTC sub-device\n"); | 367 | dev_err(dev, "Unable to init SA1100 RTC sub-device\n"); |
368 | return ret; | 368 | return ret; |
369 | } | 369 | } |
diff --git a/drivers/rtc/rtc-rx8581.c b/drivers/rtc/rtc-rx8581.c index 32caadf912ca..eac882169744 100644 --- a/drivers/rtc/rtc-rx8581.c +++ b/drivers/rtc/rtc-rx8581.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/i2c.h> | 16 | #include <linux/i2c.h> |
17 | #include <linux/bcd.h> | 17 | #include <linux/bcd.h> |
18 | #include <linux/regmap.h> | ||
18 | #include <linux/rtc.h> | 19 | #include <linux/rtc.h> |
19 | #include <linux/log2.h> | 20 | #include <linux/log2.h> |
20 | 21 | ||
@@ -51,52 +52,20 @@ | |||
51 | #define RX8581_CTRL_RESET 0x01 /* RESET bit */ | 52 | #define RX8581_CTRL_RESET 0x01 /* RESET bit */ |
52 | 53 | ||
53 | struct rx8581 { | 54 | struct rx8581 { |
54 | struct i2c_client *client; | 55 | struct regmap *regmap; |
55 | struct rtc_device *rtc; | 56 | struct rtc_device *rtc; |
56 | s32 (*read_block_data)(const struct i2c_client *client, u8 command, | ||
57 | u8 length, u8 *values); | ||
58 | s32 (*write_block_data)(const struct i2c_client *client, u8 command, | ||
59 | u8 length, const u8 *values); | ||
60 | }; | 57 | }; |
61 | 58 | ||
62 | static struct i2c_driver rx8581_driver; | ||
63 | |||
64 | static int rx8581_read_block_data(const struct i2c_client *client, u8 command, | ||
65 | u8 length, u8 *values) | ||
66 | { | ||
67 | s32 i, data; | ||
68 | |||
69 | for (i = 0; i < length; i++) { | ||
70 | data = i2c_smbus_read_byte_data(client, command + i); | ||
71 | if (data < 0) | ||
72 | return data; | ||
73 | values[i] = data; | ||
74 | } | ||
75 | return i; | ||
76 | } | ||
77 | |||
78 | static int rx8581_write_block_data(const struct i2c_client *client, u8 command, | ||
79 | u8 length, const u8 *values) | ||
80 | { | ||
81 | s32 i, ret; | ||
82 | |||
83 | for (i = 0; i < length; i++) { | ||
84 | ret = i2c_smbus_write_byte_data(client, command + i, | ||
85 | values[i]); | ||
86 | if (ret < 0) | ||
87 | return ret; | ||
88 | } | ||
89 | return length; | ||
90 | } | ||
91 | |||
92 | /* | 59 | /* |
93 | * In the routines that deal directly with the rx8581 hardware, we use | 60 | * In the routines that deal directly with the rx8581 hardware, we use |
94 | * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. | 61 | * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. |
95 | */ | 62 | */ |
96 | static int rx8581_get_datetime(struct i2c_client *client, struct rtc_time *tm) | 63 | static int rx8581_rtc_read_time(struct device *dev, struct rtc_time *tm) |
97 | { | 64 | { |
65 | struct i2c_client *client = to_i2c_client(dev); | ||
98 | unsigned char date[7]; | 66 | unsigned char date[7]; |
99 | int data, err; | 67 | unsigned int data; |
68 | int err; | ||
100 | struct rx8581 *rx8581 = i2c_get_clientdata(client); | 69 | struct rx8581 *rx8581 = i2c_get_clientdata(client); |
101 | 70 | ||
102 | /* First we ensure that the "update flag" is not set, we read the | 71 | /* First we ensure that the "update flag" is not set, we read the |
@@ -104,45 +73,38 @@ static int rx8581_get_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
104 | * has been set, we know that the time has changed during the read so | 73 | * has been set, we know that the time has changed during the read so |
105 | * we repeat the whole process again. | 74 | * we repeat the whole process again. |
106 | */ | 75 | */ |
107 | data = i2c_smbus_read_byte_data(client, RX8581_REG_FLAG); | 76 | err = regmap_read(rx8581->regmap, RX8581_REG_FLAG, &data); |
108 | if (data < 0) { | 77 | if (err < 0) |
109 | dev_err(&client->dev, "Unable to read device flags\n"); | 78 | return err; |
110 | return -EIO; | 79 | |
80 | if (data & RX8581_FLAG_VLF) { | ||
81 | dev_warn(dev, | ||
82 | "low voltage detected, date/time is not reliable.\n"); | ||
83 | return -EINVAL; | ||
111 | } | 84 | } |
112 | 85 | ||
113 | do { | 86 | do { |
114 | /* If update flag set, clear it */ | 87 | /* If update flag set, clear it */ |
115 | if (data & RX8581_FLAG_UF) { | 88 | if (data & RX8581_FLAG_UF) { |
116 | err = i2c_smbus_write_byte_data(client, | 89 | err = regmap_write(rx8581->regmap, RX8581_REG_FLAG, |
117 | RX8581_REG_FLAG, (data & ~RX8581_FLAG_UF)); | 90 | data & ~RX8581_FLAG_UF); |
118 | if (err != 0) { | 91 | if (err < 0) |
119 | dev_err(&client->dev, "Unable to write device flags\n"); | 92 | return err; |
120 | return -EIO; | ||
121 | } | ||
122 | } | 93 | } |
123 | 94 | ||
124 | /* Now read time and date */ | 95 | /* Now read time and date */ |
125 | err = rx8581->read_block_data(client, RX8581_REG_SC, | 96 | err = regmap_bulk_read(rx8581->regmap, RX8581_REG_SC, date, |
126 | 7, date); | 97 | sizeof(date)); |
127 | if (err < 0) { | 98 | if (err < 0) |
128 | dev_err(&client->dev, "Unable to read date\n"); | 99 | return err; |
129 | return -EIO; | ||
130 | } | ||
131 | 100 | ||
132 | /* Check flag register */ | 101 | /* Check flag register */ |
133 | data = i2c_smbus_read_byte_data(client, RX8581_REG_FLAG); | 102 | err = regmap_read(rx8581->regmap, RX8581_REG_FLAG, &data); |
134 | if (data < 0) { | 103 | if (err < 0) |
135 | dev_err(&client->dev, "Unable to read device flags\n"); | 104 | return err; |
136 | return -EIO; | ||
137 | } | ||
138 | } while (data & RX8581_FLAG_UF); | 105 | } while (data & RX8581_FLAG_UF); |
139 | 106 | ||
140 | if (data & RX8581_FLAG_VLF) | 107 | dev_dbg(dev, "%s: raw data is sec=%02x, min=%02x, hr=%02x, " |
141 | dev_info(&client->dev, | ||
142 | "low voltage detected, date/time is not reliable.\n"); | ||
143 | |||
144 | dev_dbg(&client->dev, | ||
145 | "%s: raw data is sec=%02x, min=%02x, hr=%02x, " | ||
146 | "wday=%02x, mday=%02x, mon=%02x, year=%02x\n", | 108 | "wday=%02x, mday=%02x, mon=%02x, year=%02x\n", |
147 | __func__, | 109 | __func__, |
148 | date[0], date[1], date[2], date[3], date[4], date[5], date[6]); | 110 | date[0], date[1], date[2], date[3], date[4], date[5], date[6]); |
@@ -153,12 +115,9 @@ static int rx8581_get_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
153 | tm->tm_wday = ilog2(date[RX8581_REG_DW] & 0x7F); | 115 | tm->tm_wday = ilog2(date[RX8581_REG_DW] & 0x7F); |
154 | tm->tm_mday = bcd2bin(date[RX8581_REG_DM] & 0x3F); | 116 | tm->tm_mday = bcd2bin(date[RX8581_REG_DM] & 0x3F); |
155 | tm->tm_mon = bcd2bin(date[RX8581_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ | 117 | tm->tm_mon = bcd2bin(date[RX8581_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ |
156 | tm->tm_year = bcd2bin(date[RX8581_REG_YR]); | 118 | tm->tm_year = bcd2bin(date[RX8581_REG_YR]) + 100; |
157 | if (tm->tm_year < 70) | ||
158 | tm->tm_year += 100; /* assume we are in 1970...2069 */ | ||
159 | |||
160 | 119 | ||
161 | dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " | 120 | dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " |
162 | "mday=%d, mon=%d, year=%d, wday=%d\n", | 121 | "mday=%d, mon=%d, year=%d, wday=%d\n", |
163 | __func__, | 122 | __func__, |
164 | tm->tm_sec, tm->tm_min, tm->tm_hour, | 123 | tm->tm_sec, tm->tm_min, tm->tm_hour, |
@@ -167,13 +126,14 @@ static int rx8581_get_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
167 | return 0; | 126 | return 0; |
168 | } | 127 | } |
169 | 128 | ||
170 | static int rx8581_set_datetime(struct i2c_client *client, struct rtc_time *tm) | 129 | static int rx8581_rtc_set_time(struct device *dev, struct rtc_time *tm) |
171 | { | 130 | { |
172 | int data, err; | 131 | struct i2c_client *client = to_i2c_client(dev); |
132 | int err; | ||
173 | unsigned char buf[7]; | 133 | unsigned char buf[7]; |
174 | struct rx8581 *rx8581 = i2c_get_clientdata(client); | 134 | struct rx8581 *rx8581 = i2c_get_clientdata(client); |
175 | 135 | ||
176 | dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " | 136 | dev_dbg(dev, "%s: secs=%d, mins=%d, hours=%d, " |
177 | "mday=%d, mon=%d, year=%d, wday=%d\n", | 137 | "mday=%d, mon=%d, year=%d, wday=%d\n", |
178 | __func__, | 138 | __func__, |
179 | tm->tm_sec, tm->tm_min, tm->tm_hour, | 139 | tm->tm_sec, tm->tm_min, tm->tm_hour, |
@@ -190,69 +150,30 @@ static int rx8581_set_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
190 | buf[RX8581_REG_MO] = bin2bcd(tm->tm_mon + 1); | 150 | buf[RX8581_REG_MO] = bin2bcd(tm->tm_mon + 1); |
191 | 151 | ||
192 | /* year and century */ | 152 | /* year and century */ |
193 | buf[RX8581_REG_YR] = bin2bcd(tm->tm_year % 100); | 153 | buf[RX8581_REG_YR] = bin2bcd(tm->tm_year - 100); |
194 | buf[RX8581_REG_DW] = (0x1 << tm->tm_wday); | 154 | buf[RX8581_REG_DW] = (0x1 << tm->tm_wday); |
195 | 155 | ||
196 | /* Stop the clock */ | 156 | /* Stop the clock */ |
197 | data = i2c_smbus_read_byte_data(client, RX8581_REG_CTRL); | 157 | err = regmap_update_bits(rx8581->regmap, RX8581_REG_CTRL, |
198 | if (data < 0) { | 158 | RX8581_CTRL_STOP, RX8581_CTRL_STOP); |
199 | dev_err(&client->dev, "Unable to read control register\n"); | 159 | if (err < 0) |
200 | return -EIO; | 160 | return err; |
201 | } | ||
202 | |||
203 | err = i2c_smbus_write_byte_data(client, RX8581_REG_CTRL, | ||
204 | (data | RX8581_CTRL_STOP)); | ||
205 | if (err < 0) { | ||
206 | dev_err(&client->dev, "Unable to write control register\n"); | ||
207 | return -EIO; | ||
208 | } | ||
209 | 161 | ||
210 | /* write register's data */ | 162 | /* write register's data */ |
211 | err = rx8581->write_block_data(client, RX8581_REG_SC, 7, buf); | 163 | err = regmap_bulk_write(rx8581->regmap, RX8581_REG_SC, |
212 | if (err < 0) { | 164 | buf, sizeof(buf)); |
213 | dev_err(&client->dev, "Unable to write to date registers\n"); | 165 | if (err < 0) |
214 | return -EIO; | 166 | return err; |
215 | } | ||
216 | 167 | ||
217 | /* get VLF and clear it */ | 168 | /* get VLF and clear it */ |
218 | data = i2c_smbus_read_byte_data(client, RX8581_REG_FLAG); | 169 | err = regmap_update_bits(rx8581->regmap, RX8581_REG_FLAG, |
219 | if (data < 0) { | 170 | RX8581_FLAG_VLF, 0); |
220 | dev_err(&client->dev, "Unable to read flag register\n"); | 171 | if (err < 0) |
221 | return -EIO; | 172 | return err; |
222 | } | ||
223 | |||
224 | err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG, | ||
225 | (data & ~(RX8581_FLAG_VLF))); | ||
226 | if (err != 0) { | ||
227 | dev_err(&client->dev, "Unable to write flag register\n"); | ||
228 | return -EIO; | ||
229 | } | ||
230 | 173 | ||
231 | /* Restart the clock */ | 174 | /* Restart the clock */ |
232 | data = i2c_smbus_read_byte_data(client, RX8581_REG_CTRL); | 175 | return regmap_update_bits(rx8581->regmap, RX8581_REG_CTRL, |
233 | if (data < 0) { | 176 | RX8581_CTRL_STOP, 0); |
234 | dev_err(&client->dev, "Unable to read control register\n"); | ||
235 | return -EIO; | ||
236 | } | ||
237 | |||
238 | err = i2c_smbus_write_byte_data(client, RX8581_REG_CTRL, | ||
239 | (data & ~(RX8581_CTRL_STOP))); | ||
240 | if (err != 0) { | ||
241 | dev_err(&client->dev, "Unable to write control register\n"); | ||
242 | return -EIO; | ||
243 | } | ||
244 | |||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | static int rx8581_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
249 | { | ||
250 | return rx8581_get_datetime(to_i2c_client(dev), tm); | ||
251 | } | ||
252 | |||
253 | static int rx8581_rtc_set_time(struct device *dev, struct rtc_time *tm) | ||
254 | { | ||
255 | return rx8581_set_datetime(to_i2c_client(dev), tm); | ||
256 | } | 177 | } |
257 | 178 | ||
258 | static const struct rtc_class_ops rx8581_rtc_ops = { | 179 | static const struct rtc_class_ops rx8581_rtc_ops = { |
@@ -264,38 +185,35 @@ static int rx8581_probe(struct i2c_client *client, | |||
264 | const struct i2c_device_id *id) | 185 | const struct i2c_device_id *id) |
265 | { | 186 | { |
266 | struct rx8581 *rx8581; | 187 | struct rx8581 *rx8581; |
188 | static const struct regmap_config config = { | ||
189 | .reg_bits = 8, | ||
190 | .val_bits = 8, | ||
191 | .max_register = 0xf, | ||
192 | }; | ||
267 | 193 | ||
268 | dev_dbg(&client->dev, "%s\n", __func__); | 194 | dev_dbg(&client->dev, "%s\n", __func__); |
269 | 195 | ||
270 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA) | ||
271 | && !i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) | ||
272 | return -EIO; | ||
273 | |||
274 | rx8581 = devm_kzalloc(&client->dev, sizeof(struct rx8581), GFP_KERNEL); | 196 | rx8581 = devm_kzalloc(&client->dev, sizeof(struct rx8581), GFP_KERNEL); |
275 | if (!rx8581) | 197 | if (!rx8581) |
276 | return -ENOMEM; | 198 | return -ENOMEM; |
277 | 199 | ||
278 | i2c_set_clientdata(client, rx8581); | 200 | i2c_set_clientdata(client, rx8581); |
279 | rx8581->client = client; | ||
280 | |||
281 | if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { | ||
282 | rx8581->read_block_data = i2c_smbus_read_i2c_block_data; | ||
283 | rx8581->write_block_data = i2c_smbus_write_i2c_block_data; | ||
284 | } else { | ||
285 | rx8581->read_block_data = rx8581_read_block_data; | ||
286 | rx8581->write_block_data = rx8581_write_block_data; | ||
287 | } | ||
288 | 201 | ||
289 | rx8581->rtc = devm_rtc_device_register(&client->dev, | 202 | rx8581->regmap = devm_regmap_init_i2c(client, &config); |
290 | rx8581_driver.driver.name, &rx8581_rtc_ops, THIS_MODULE); | 203 | if (IS_ERR(rx8581->regmap)) |
204 | return PTR_ERR(rx8581->regmap); | ||
291 | 205 | ||
292 | if (IS_ERR(rx8581->rtc)) { | 206 | rx8581->rtc = devm_rtc_allocate_device(&client->dev); |
293 | dev_err(&client->dev, | 207 | if (IS_ERR(rx8581->rtc)) |
294 | "unable to register the class device\n"); | ||
295 | return PTR_ERR(rx8581->rtc); | 208 | return PTR_ERR(rx8581->rtc); |
296 | } | ||
297 | 209 | ||
298 | return 0; | 210 | rx8581->rtc->ops = &rx8581_rtc_ops; |
211 | rx8581->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; | ||
212 | rx8581->rtc->range_max = RTC_TIMESTAMP_END_2099; | ||
213 | rx8581->rtc->start_secs = 0; | ||
214 | rx8581->rtc->set_start_time = true; | ||
215 | |||
216 | return rtc_register_device(rx8581->rtc); | ||
299 | } | 217 | } |
300 | 218 | ||
301 | static const struct i2c_device_id rx8581_id[] = { | 219 | static const struct i2c_device_id rx8581_id[] = { |
diff --git a/drivers/rtc/rtc-sc27xx.c b/drivers/rtc/rtc-sc27xx.c index 00d87d138984..deea5c3726ad 100644 --- a/drivers/rtc/rtc-sc27xx.c +++ b/drivers/rtc/rtc-sc27xx.c | |||
@@ -35,6 +35,8 @@ | |||
35 | #define SPRD_RTC_DAY_ALM_VALUE 0x4c | 35 | #define SPRD_RTC_DAY_ALM_VALUE 0x4c |
36 | #define SPRD_RTC_SPG_VALUE 0x50 | 36 | #define SPRD_RTC_SPG_VALUE 0x50 |
37 | #define SPRD_RTC_SPG_UPD 0x54 | 37 | #define SPRD_RTC_SPG_UPD 0x54 |
38 | #define SPRD_RTC_PWR_CTRL 0x58 | ||
39 | #define SPRD_RTC_PWR_STS 0x5c | ||
38 | #define SPRD_RTC_SEC_AUXALM_UPD 0x60 | 40 | #define SPRD_RTC_SEC_AUXALM_UPD 0x60 |
39 | #define SPRD_RTC_MIN_AUXALM_UPD 0x64 | 41 | #define SPRD_RTC_MIN_AUXALM_UPD 0x64 |
40 | #define SPRD_RTC_HOUR_AUXALM_UPD 0x68 | 42 | #define SPRD_RTC_HOUR_AUXALM_UPD 0x68 |
@@ -86,7 +88,13 @@ | |||
86 | 88 | ||
87 | /* SPG values definition for SPRD_RTC_SPG_UPD register */ | 89 | /* SPG values definition for SPRD_RTC_SPG_UPD register */ |
88 | #define SPRD_RTC_POWEROFF_ALM_FLAG BIT(8) | 90 | #define SPRD_RTC_POWEROFF_ALM_FLAG BIT(8) |
89 | #define SPRD_RTC_POWER_RESET_FLAG BIT(9) | 91 | |
92 | /* power control/status definition */ | ||
93 | #define SPRD_RTC_POWER_RESET_VALUE 0x96 | ||
94 | #define SPRD_RTC_POWER_STS_CLEAR GENMASK(7, 0) | ||
95 | #define SPRD_RTC_POWER_STS_SHIFT 8 | ||
96 | #define SPRD_RTC_POWER_STS_VALID \ | ||
97 | (~SPRD_RTC_POWER_RESET_VALUE << SPRD_RTC_POWER_STS_SHIFT) | ||
90 | 98 | ||
91 | /* timeout of synchronizing time and alarm registers (us) */ | 99 | /* timeout of synchronizing time and alarm registers (us) */ |
92 | #define SPRD_RTC_POLL_TIMEOUT 200000 | 100 | #define SPRD_RTC_POLL_TIMEOUT 200000 |
@@ -383,7 +391,6 @@ static int sprd_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
383 | { | 391 | { |
384 | struct sprd_rtc *rtc = dev_get_drvdata(dev); | 392 | struct sprd_rtc *rtc = dev_get_drvdata(dev); |
385 | time64_t secs = rtc_tm_to_time64(tm); | 393 | time64_t secs = rtc_tm_to_time64(tm); |
386 | u32 val; | ||
387 | int ret; | 394 | int ret; |
388 | 395 | ||
389 | ret = sprd_rtc_set_secs(rtc, SPRD_RTC_TIME, secs); | 396 | ret = sprd_rtc_set_secs(rtc, SPRD_RTC_TIME, secs); |
@@ -391,27 +398,20 @@ static int sprd_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
391 | return ret; | 398 | return ret; |
392 | 399 | ||
393 | if (!rtc->valid) { | 400 | if (!rtc->valid) { |
394 | /* | 401 | /* Clear RTC power status firstly */ |
395 | * Set SPRD_RTC_POWER_RESET_FLAG to indicate now RTC has valid | 402 | ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_PWR_CTRL, |
396 | * time values. | 403 | SPRD_RTC_POWER_STS_CLEAR); |
397 | */ | ||
398 | ret = regmap_update_bits(rtc->regmap, | ||
399 | rtc->base + SPRD_RTC_SPG_UPD, | ||
400 | SPRD_RTC_POWER_RESET_FLAG, | ||
401 | SPRD_RTC_POWER_RESET_FLAG); | ||
402 | if (ret) | 404 | if (ret) |
403 | return ret; | 405 | return ret; |
404 | 406 | ||
405 | ret = regmap_read_poll_timeout(rtc->regmap, | 407 | /* |
406 | rtc->base + SPRD_RTC_INT_RAW_STS, | 408 | * Set RTC power status to indicate now RTC has valid time |
407 | val, (val & SPRD_RTC_SPG_UPD_EN), | 409 | * values. |
408 | SPRD_RTC_POLL_DELAY_US, | 410 | */ |
409 | SPRD_RTC_POLL_TIMEOUT); | 411 | ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_PWR_CTRL, |
410 | if (ret) { | 412 | SPRD_RTC_POWER_STS_VALID); |
411 | dev_err(rtc->dev, "failed to update SPG value:%d\n", | 413 | if (ret) |
412 | ret); | ||
413 | return ret; | 414 | return ret; |
414 | } | ||
415 | 415 | ||
416 | rtc->valid = true; | 416 | rtc->valid = true; |
417 | } | 417 | } |
@@ -562,15 +562,16 @@ static int sprd_rtc_check_power_down(struct sprd_rtc *rtc) | |||
562 | u32 val; | 562 | u32 val; |
563 | int ret; | 563 | int ret; |
564 | 564 | ||
565 | ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_SPG_VALUE, &val); | 565 | ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_PWR_STS, &val); |
566 | if (ret) | 566 | if (ret) |
567 | return ret; | 567 | return ret; |
568 | 568 | ||
569 | /* | 569 | /* |
570 | * If the SPRD_RTC_POWER_RESET_FLAG was not set, which means the RTC has | 570 | * If the RTC power status value is SPRD_RTC_POWER_RESET_VALUE, which |
571 | * been powered down, so the RTC time values are invalid. | 571 | * means the RTC has been powered down, so the RTC time values are |
572 | * invalid. | ||
572 | */ | 573 | */ |
573 | rtc->valid = (val & SPRD_RTC_POWER_RESET_FLAG) ? true : false; | 574 | rtc->valid = val == SPRD_RTC_POWER_RESET_VALUE ? false : true; |
574 | return 0; | 575 | return 0; |
575 | } | 576 | } |
576 | 577 | ||
@@ -600,6 +601,10 @@ static int sprd_rtc_probe(struct platform_device *pdev) | |||
600 | return rtc->irq; | 601 | return rtc->irq; |
601 | } | 602 | } |
602 | 603 | ||
604 | rtc->rtc = devm_rtc_allocate_device(&pdev->dev); | ||
605 | if (IS_ERR(rtc->rtc)) | ||
606 | return PTR_ERR(rtc->rtc); | ||
607 | |||
603 | rtc->dev = &pdev->dev; | 608 | rtc->dev = &pdev->dev; |
604 | platform_set_drvdata(pdev, rtc); | 609 | platform_set_drvdata(pdev, rtc); |
605 | 610 | ||
@@ -626,10 +631,14 @@ static int sprd_rtc_probe(struct platform_device *pdev) | |||
626 | return ret; | 631 | return ret; |
627 | } | 632 | } |
628 | 633 | ||
629 | rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, | 634 | rtc->rtc->ops = &sprd_rtc_ops; |
630 | &sprd_rtc_ops, THIS_MODULE); | 635 | rtc->rtc->range_min = 0; |
631 | if (IS_ERR(rtc->rtc)) | 636 | rtc->rtc->range_max = 5662310399LL; |
632 | return PTR_ERR(rtc->rtc); | 637 | ret = rtc_register_device(rtc->rtc); |
638 | if (ret) { | ||
639 | dev_err(&pdev->dev, "failed to register rtc device\n"); | ||
640 | return ret; | ||
641 | } | ||
633 | 642 | ||
634 | device_init_wakeup(&pdev->dev, 1); | 643 | device_init_wakeup(&pdev->dev, 1); |
635 | return 0; | 644 | return 0; |
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c index 4e8ab370ce63..4f98543d1ea5 100644 --- a/drivers/rtc/rtc-sh.c +++ b/drivers/rtc/rtc-sh.c | |||
@@ -359,8 +359,7 @@ static int sh_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | |||
359 | 359 | ||
360 | static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm) | 360 | static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm) |
361 | { | 361 | { |
362 | struct platform_device *pdev = to_platform_device(dev); | 362 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
363 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
364 | unsigned int sec128, sec2, yr, yr100, cf_bit; | 363 | unsigned int sec128, sec2, yr, yr100, cf_bit; |
365 | 364 | ||
366 | do { | 365 | do { |
@@ -419,8 +418,7 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
419 | 418 | ||
420 | static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm) | 419 | static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm) |
421 | { | 420 | { |
422 | struct platform_device *pdev = to_platform_device(dev); | 421 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
423 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
424 | unsigned int tmp; | 422 | unsigned int tmp; |
425 | int year; | 423 | int year; |
426 | 424 | ||
@@ -475,8 +473,7 @@ static inline int sh_rtc_read_alarm_value(struct sh_rtc *rtc, int reg_off) | |||
475 | 473 | ||
476 | static int sh_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | 474 | static int sh_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) |
477 | { | 475 | { |
478 | struct platform_device *pdev = to_platform_device(dev); | 476 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
479 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
480 | struct rtc_time *tm = &wkalrm->time; | 477 | struct rtc_time *tm = &wkalrm->time; |
481 | 478 | ||
482 | spin_lock_irq(&rtc->lock); | 479 | spin_lock_irq(&rtc->lock); |
@@ -509,8 +506,7 @@ static inline void sh_rtc_write_alarm_value(struct sh_rtc *rtc, | |||
509 | 506 | ||
510 | static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | 507 | static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) |
511 | { | 508 | { |
512 | struct platform_device *pdev = to_platform_device(dev); | 509 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
513 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
514 | unsigned int rcr1; | 510 | unsigned int rcr1; |
515 | struct rtc_time *tm = &wkalrm->time; | 511 | struct rtc_time *tm = &wkalrm->time; |
516 | int mon; | 512 | int mon; |
@@ -723,8 +719,7 @@ static int __exit sh_rtc_remove(struct platform_device *pdev) | |||
723 | 719 | ||
724 | static void sh_rtc_set_irq_wake(struct device *dev, int enabled) | 720 | static void sh_rtc_set_irq_wake(struct device *dev, int enabled) |
725 | { | 721 | { |
726 | struct platform_device *pdev = to_platform_device(dev); | 722 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
727 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
728 | 723 | ||
729 | irq_set_irq_wake(rtc->periodic_irq, enabled); | 724 | irq_set_irq_wake(rtc->periodic_irq, enabled); |
730 | 725 | ||
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c index 9af591d5223c..8a75cc3af6e7 100644 --- a/drivers/rtc/rtc-snvs.c +++ b/drivers/rtc/rtc-snvs.c | |||
@@ -1,13 +1,6 @@ | |||
1 | /* | 1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | * Copyright (C) 2011-2012 Freescale Semiconductor, Inc. | 2 | // |
3 | * | 3 | // Copyright (C) 2011-2012 Freescale Semiconductor, Inc. |
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | 4 | ||
12 | #include <linux/init.h> | 5 | #include <linux/init.h> |
13 | #include <linux/io.h> | 6 | #include <linux/io.h> |
diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c index d5222667f892..bee75ca7ff79 100644 --- a/drivers/rtc/rtc-st-lpc.c +++ b/drivers/rtc/rtc-st-lpc.c | |||
@@ -212,6 +212,10 @@ static int st_rtc_probe(struct platform_device *pdev) | |||
212 | if (!rtc) | 212 | if (!rtc) |
213 | return -ENOMEM; | 213 | return -ENOMEM; |
214 | 214 | ||
215 | rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); | ||
216 | if (IS_ERR(rtc->rtc_dev)) | ||
217 | return PTR_ERR(rtc->rtc_dev); | ||
218 | |||
215 | spin_lock_init(&rtc->lock); | 219 | spin_lock_init(&rtc->lock); |
216 | 220 | ||
217 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 221 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
@@ -253,26 +257,19 @@ static int st_rtc_probe(struct platform_device *pdev) | |||
253 | 257 | ||
254 | platform_set_drvdata(pdev, rtc); | 258 | platform_set_drvdata(pdev, rtc); |
255 | 259 | ||
256 | rtc->rtc_dev = rtc_device_register("st-lpc-rtc", &pdev->dev, | 260 | rtc->rtc_dev->ops = &st_rtc_ops; |
257 | &st_rtc_ops, THIS_MODULE); | 261 | rtc->rtc_dev->range_max = U64_MAX; |
258 | if (IS_ERR(rtc->rtc_dev)) { | 262 | do_div(rtc->rtc_dev->range_max, rtc->clkrate); |
263 | |||
264 | ret = rtc_register_device(rtc->rtc_dev); | ||
265 | if (ret) { | ||
259 | clk_disable_unprepare(rtc->clk); | 266 | clk_disable_unprepare(rtc->clk); |
260 | return PTR_ERR(rtc->rtc_dev); | 267 | return ret; |
261 | } | 268 | } |
262 | 269 | ||
263 | return 0; | 270 | return 0; |
264 | } | 271 | } |
265 | 272 | ||
266 | static int st_rtc_remove(struct platform_device *pdev) | ||
267 | { | ||
268 | struct st_rtc *rtc = platform_get_drvdata(pdev); | ||
269 | |||
270 | if (likely(rtc->rtc_dev)) | ||
271 | rtc_device_unregister(rtc->rtc_dev); | ||
272 | |||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | #ifdef CONFIG_PM_SLEEP | 273 | #ifdef CONFIG_PM_SLEEP |
277 | static int st_rtc_suspend(struct device *dev) | 274 | static int st_rtc_suspend(struct device *dev) |
278 | { | 275 | { |
@@ -325,7 +322,6 @@ static struct platform_driver st_rtc_platform_driver = { | |||
325 | .of_match_table = st_rtc_match, | 322 | .of_match_table = st_rtc_match, |
326 | }, | 323 | }, |
327 | .probe = st_rtc_probe, | 324 | .probe = st_rtc_probe, |
328 | .remove = st_rtc_remove, | ||
329 | }; | 325 | }; |
330 | 326 | ||
331 | module_platform_driver(st_rtc_platform_driver); | 327 | module_platform_driver(st_rtc_platform_driver); |
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c index e70b78d17a98..fccbecbb2c98 100644 --- a/drivers/rtc/rtc-stk17ta8.c +++ b/drivers/rtc/rtc-stk17ta8.c | |||
@@ -74,8 +74,7 @@ struct rtc_plat_data { | |||
74 | 74 | ||
75 | static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm) | 75 | static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm) |
76 | { | 76 | { |
77 | struct platform_device *pdev = to_platform_device(dev); | 77 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
78 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
79 | void __iomem *ioaddr = pdata->ioaddr; | 78 | void __iomem *ioaddr = pdata->ioaddr; |
80 | u8 flags; | 79 | u8 flags; |
81 | 80 | ||
@@ -97,8 +96,7 @@ static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
97 | 96 | ||
98 | static int stk17ta8_rtc_read_time(struct device *dev, struct rtc_time *tm) | 97 | static int stk17ta8_rtc_read_time(struct device *dev, struct rtc_time *tm) |
99 | { | 98 | { |
100 | struct platform_device *pdev = to_platform_device(dev); | 99 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
101 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
102 | void __iomem *ioaddr = pdata->ioaddr; | 100 | void __iomem *ioaddr = pdata->ioaddr; |
103 | unsigned int year, month, day, hour, minute, second, week; | 101 | unsigned int year, month, day, hour, minute, second, week; |
104 | unsigned int century; | 102 | unsigned int century; |
@@ -163,8 +161,7 @@ static void stk17ta8_rtc_update_alarm(struct rtc_plat_data *pdata) | |||
163 | 161 | ||
164 | static int stk17ta8_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 162 | static int stk17ta8_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
165 | { | 163 | { |
166 | struct platform_device *pdev = to_platform_device(dev); | 164 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
167 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
168 | 165 | ||
169 | if (pdata->irq <= 0) | 166 | if (pdata->irq <= 0) |
170 | return -EINVAL; | 167 | return -EINVAL; |
@@ -180,8 +177,7 @@ static int stk17ta8_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
180 | 177 | ||
181 | static int stk17ta8_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 178 | static int stk17ta8_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
182 | { | 179 | { |
183 | struct platform_device *pdev = to_platform_device(dev); | 180 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
184 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
185 | 181 | ||
186 | if (pdata->irq <= 0) | 182 | if (pdata->irq <= 0) |
187 | return -EINVAL; | 183 | return -EINVAL; |
@@ -217,8 +213,7 @@ static irqreturn_t stk17ta8_rtc_interrupt(int irq, void *dev_id) | |||
217 | static int stk17ta8_rtc_alarm_irq_enable(struct device *dev, | 213 | static int stk17ta8_rtc_alarm_irq_enable(struct device *dev, |
218 | unsigned int enabled) | 214 | unsigned int enabled) |
219 | { | 215 | { |
220 | struct platform_device *pdev = to_platform_device(dev); | 216 | struct rtc_plat_data *pdata = dev_get_drvdata(dev); |
221 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); | ||
222 | 217 | ||
223 | if (pdata->irq <= 0) | 218 | if (pdata->irq <= 0) |
224 | return -EINVAL; | 219 | return -EINVAL; |
diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c index f25dabe8fd02..c5908cfea234 100644 --- a/drivers/rtc/rtc-stm32.c +++ b/drivers/rtc/rtc-stm32.c | |||
@@ -1,7 +1,7 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
1 | /* | 2 | /* |
2 | * Copyright (C) STMicroelectronics SA 2017 | 3 | * Copyright (C) STMicroelectronics 2017 |
3 | * Author: Amelie Delaunay <amelie.delaunay@st.com> for STMicroelectronics. | 4 | * Author: Amelie Delaunay <amelie.delaunay@st.com> |
4 | * License terms: GNU General Public License (GPL), version 2 | ||
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <linux/bcd.h> | 7 | #include <linux/bcd.h> |
@@ -11,20 +11,12 @@ | |||
11 | #include <linux/mfd/syscon.h> | 11 | #include <linux/mfd/syscon.h> |
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/of_device.h> | 13 | #include <linux/of_device.h> |
14 | #include <linux/pm_wakeirq.h> | ||
14 | #include <linux/regmap.h> | 15 | #include <linux/regmap.h> |
15 | #include <linux/rtc.h> | 16 | #include <linux/rtc.h> |
16 | 17 | ||
17 | #define DRIVER_NAME "stm32_rtc" | 18 | #define DRIVER_NAME "stm32_rtc" |
18 | 19 | ||
19 | /* STM32 RTC registers */ | ||
20 | #define STM32_RTC_TR 0x00 | ||
21 | #define STM32_RTC_DR 0x04 | ||
22 | #define STM32_RTC_CR 0x08 | ||
23 | #define STM32_RTC_ISR 0x0C | ||
24 | #define STM32_RTC_PRER 0x10 | ||
25 | #define STM32_RTC_ALRMAR 0x1C | ||
26 | #define STM32_RTC_WPR 0x24 | ||
27 | |||
28 | /* STM32_RTC_TR bit fields */ | 20 | /* STM32_RTC_TR bit fields */ |
29 | #define STM32_RTC_TR_SEC_SHIFT 0 | 21 | #define STM32_RTC_TR_SEC_SHIFT 0 |
30 | #define STM32_RTC_TR_SEC GENMASK(6, 0) | 22 | #define STM32_RTC_TR_SEC GENMASK(6, 0) |
@@ -48,7 +40,7 @@ | |||
48 | #define STM32_RTC_CR_ALRAE BIT(8) | 40 | #define STM32_RTC_CR_ALRAE BIT(8) |
49 | #define STM32_RTC_CR_ALRAIE BIT(12) | 41 | #define STM32_RTC_CR_ALRAIE BIT(12) |
50 | 42 | ||
51 | /* STM32_RTC_ISR bit fields */ | 43 | /* STM32_RTC_ISR/STM32_RTC_ICSR bit fields */ |
52 | #define STM32_RTC_ISR_ALRAWF BIT(0) | 44 | #define STM32_RTC_ISR_ALRAWF BIT(0) |
53 | #define STM32_RTC_ISR_INITS BIT(4) | 45 | #define STM32_RTC_ISR_INITS BIT(4) |
54 | #define STM32_RTC_ISR_RSF BIT(5) | 46 | #define STM32_RTC_ISR_RSF BIT(5) |
@@ -80,52 +72,87 @@ | |||
80 | #define STM32_RTC_ALRMXR_WDAY GENMASK(27, 24) | 72 | #define STM32_RTC_ALRMXR_WDAY GENMASK(27, 24) |
81 | #define STM32_RTC_ALRMXR_DATE_MASK BIT(31) | 73 | #define STM32_RTC_ALRMXR_DATE_MASK BIT(31) |
82 | 74 | ||
75 | /* STM32_RTC_SR/_SCR bit fields */ | ||
76 | #define STM32_RTC_SR_ALRA BIT(0) | ||
77 | |||
78 | /* STM32_RTC_VERR bit fields */ | ||
79 | #define STM32_RTC_VERR_MINREV_SHIFT 0 | ||
80 | #define STM32_RTC_VERR_MINREV GENMASK(3, 0) | ||
81 | #define STM32_RTC_VERR_MAJREV_SHIFT 4 | ||
82 | #define STM32_RTC_VERR_MAJREV GENMASK(7, 4) | ||
83 | |||
83 | /* STM32_RTC_WPR key constants */ | 84 | /* STM32_RTC_WPR key constants */ |
84 | #define RTC_WPR_1ST_KEY 0xCA | 85 | #define RTC_WPR_1ST_KEY 0xCA |
85 | #define RTC_WPR_2ND_KEY 0x53 | 86 | #define RTC_WPR_2ND_KEY 0x53 |
86 | #define RTC_WPR_WRONG_KEY 0xFF | 87 | #define RTC_WPR_WRONG_KEY 0xFF |
87 | 88 | ||
88 | /* | 89 | /* Max STM32 RTC register offset is 0x3FC */ |
89 | * RTC registers are protected against parasitic write access. | 90 | #define UNDEF_REG 0xFFFF |
90 | * PWR_CR_DBP bit must be set to enable write access to RTC registers. | 91 | |
91 | */ | 92 | struct stm32_rtc; |
92 | /* STM32_PWR_CR */ | 93 | |
93 | #define PWR_CR 0x00 | 94 | struct stm32_rtc_registers { |
94 | /* STM32_PWR_CR bit field */ | 95 | u16 tr; |
95 | #define PWR_CR_DBP BIT(8) | 96 | u16 dr; |
97 | u16 cr; | ||
98 | u16 isr; | ||
99 | u16 prer; | ||
100 | u16 alrmar; | ||
101 | u16 wpr; | ||
102 | u16 sr; | ||
103 | u16 scr; | ||
104 | u16 verr; | ||
105 | }; | ||
106 | |||
107 | struct stm32_rtc_events { | ||
108 | u32 alra; | ||
109 | }; | ||
96 | 110 | ||
97 | struct stm32_rtc_data { | 111 | struct stm32_rtc_data { |
112 | const struct stm32_rtc_registers regs; | ||
113 | const struct stm32_rtc_events events; | ||
114 | void (*clear_events)(struct stm32_rtc *rtc, unsigned int flags); | ||
98 | bool has_pclk; | 115 | bool has_pclk; |
116 | bool need_dbp; | ||
117 | bool has_wakeirq; | ||
99 | }; | 118 | }; |
100 | 119 | ||
101 | struct stm32_rtc { | 120 | struct stm32_rtc { |
102 | struct rtc_device *rtc_dev; | 121 | struct rtc_device *rtc_dev; |
103 | void __iomem *base; | 122 | void __iomem *base; |
104 | struct regmap *dbp; | 123 | struct regmap *dbp; |
105 | struct stm32_rtc_data *data; | 124 | unsigned int dbp_reg; |
125 | unsigned int dbp_mask; | ||
106 | struct clk *pclk; | 126 | struct clk *pclk; |
107 | struct clk *rtc_ck; | 127 | struct clk *rtc_ck; |
128 | const struct stm32_rtc_data *data; | ||
108 | int irq_alarm; | 129 | int irq_alarm; |
130 | int wakeirq_alarm; | ||
109 | }; | 131 | }; |
110 | 132 | ||
111 | static void stm32_rtc_wpr_unlock(struct stm32_rtc *rtc) | 133 | static void stm32_rtc_wpr_unlock(struct stm32_rtc *rtc) |
112 | { | 134 | { |
113 | writel_relaxed(RTC_WPR_1ST_KEY, rtc->base + STM32_RTC_WPR); | 135 | const struct stm32_rtc_registers *regs = &rtc->data->regs; |
114 | writel_relaxed(RTC_WPR_2ND_KEY, rtc->base + STM32_RTC_WPR); | 136 | |
137 | writel_relaxed(RTC_WPR_1ST_KEY, rtc->base + regs->wpr); | ||
138 | writel_relaxed(RTC_WPR_2ND_KEY, rtc->base + regs->wpr); | ||
115 | } | 139 | } |
116 | 140 | ||
117 | static void stm32_rtc_wpr_lock(struct stm32_rtc *rtc) | 141 | static void stm32_rtc_wpr_lock(struct stm32_rtc *rtc) |
118 | { | 142 | { |
119 | writel_relaxed(RTC_WPR_WRONG_KEY, rtc->base + STM32_RTC_WPR); | 143 | const struct stm32_rtc_registers *regs = &rtc->data->regs; |
144 | |||
145 | writel_relaxed(RTC_WPR_WRONG_KEY, rtc->base + regs->wpr); | ||
120 | } | 146 | } |
121 | 147 | ||
122 | static int stm32_rtc_enter_init_mode(struct stm32_rtc *rtc) | 148 | static int stm32_rtc_enter_init_mode(struct stm32_rtc *rtc) |
123 | { | 149 | { |
124 | unsigned int isr = readl_relaxed(rtc->base + STM32_RTC_ISR); | 150 | const struct stm32_rtc_registers *regs = &rtc->data->regs; |
151 | unsigned int isr = readl_relaxed(rtc->base + regs->isr); | ||
125 | 152 | ||
126 | if (!(isr & STM32_RTC_ISR_INITF)) { | 153 | if (!(isr & STM32_RTC_ISR_INITF)) { |
127 | isr |= STM32_RTC_ISR_INIT; | 154 | isr |= STM32_RTC_ISR_INIT; |
128 | writel_relaxed(isr, rtc->base + STM32_RTC_ISR); | 155 | writel_relaxed(isr, rtc->base + regs->isr); |
129 | 156 | ||
130 | /* | 157 | /* |
131 | * It takes around 2 rtc_ck clock cycles to enter in | 158 | * It takes around 2 rtc_ck clock cycles to enter in |
@@ -134,7 +161,7 @@ static int stm32_rtc_enter_init_mode(struct stm32_rtc *rtc) | |||
134 | * 1MHz, we poll every 10 us with a timeout of 100ms. | 161 | * 1MHz, we poll every 10 us with a timeout of 100ms. |
135 | */ | 162 | */ |
136 | return readl_relaxed_poll_timeout_atomic( | 163 | return readl_relaxed_poll_timeout_atomic( |
137 | rtc->base + STM32_RTC_ISR, | 164 | rtc->base + regs->isr, |
138 | isr, (isr & STM32_RTC_ISR_INITF), | 165 | isr, (isr & STM32_RTC_ISR_INITF), |
139 | 10, 100000); | 166 | 10, 100000); |
140 | } | 167 | } |
@@ -144,40 +171,50 @@ static int stm32_rtc_enter_init_mode(struct stm32_rtc *rtc) | |||
144 | 171 | ||
145 | static void stm32_rtc_exit_init_mode(struct stm32_rtc *rtc) | 172 | static void stm32_rtc_exit_init_mode(struct stm32_rtc *rtc) |
146 | { | 173 | { |
147 | unsigned int isr = readl_relaxed(rtc->base + STM32_RTC_ISR); | 174 | const struct stm32_rtc_registers *regs = &rtc->data->regs; |
175 | unsigned int isr = readl_relaxed(rtc->base + regs->isr); | ||
148 | 176 | ||
149 | isr &= ~STM32_RTC_ISR_INIT; | 177 | isr &= ~STM32_RTC_ISR_INIT; |
150 | writel_relaxed(isr, rtc->base + STM32_RTC_ISR); | 178 | writel_relaxed(isr, rtc->base + regs->isr); |
151 | } | 179 | } |
152 | 180 | ||
153 | static int stm32_rtc_wait_sync(struct stm32_rtc *rtc) | 181 | static int stm32_rtc_wait_sync(struct stm32_rtc *rtc) |
154 | { | 182 | { |
155 | unsigned int isr = readl_relaxed(rtc->base + STM32_RTC_ISR); | 183 | const struct stm32_rtc_registers *regs = &rtc->data->regs; |
184 | unsigned int isr = readl_relaxed(rtc->base + regs->isr); | ||
156 | 185 | ||
157 | isr &= ~STM32_RTC_ISR_RSF; | 186 | isr &= ~STM32_RTC_ISR_RSF; |
158 | writel_relaxed(isr, rtc->base + STM32_RTC_ISR); | 187 | writel_relaxed(isr, rtc->base + regs->isr); |
159 | 188 | ||
160 | /* | 189 | /* |
161 | * Wait for RSF to be set to ensure the calendar registers are | 190 | * Wait for RSF to be set to ensure the calendar registers are |
162 | * synchronised, it takes around 2 rtc_ck clock cycles | 191 | * synchronised, it takes around 2 rtc_ck clock cycles |
163 | */ | 192 | */ |
164 | return readl_relaxed_poll_timeout_atomic(rtc->base + STM32_RTC_ISR, | 193 | return readl_relaxed_poll_timeout_atomic(rtc->base + regs->isr, |
165 | isr, | 194 | isr, |
166 | (isr & STM32_RTC_ISR_RSF), | 195 | (isr & STM32_RTC_ISR_RSF), |
167 | 10, 100000); | 196 | 10, 100000); |
168 | } | 197 | } |
169 | 198 | ||
199 | static void stm32_rtc_clear_event_flags(struct stm32_rtc *rtc, | ||
200 | unsigned int flags) | ||
201 | { | ||
202 | rtc->data->clear_events(rtc, flags); | ||
203 | } | ||
204 | |||
170 | static irqreturn_t stm32_rtc_alarm_irq(int irq, void *dev_id) | 205 | static irqreturn_t stm32_rtc_alarm_irq(int irq, void *dev_id) |
171 | { | 206 | { |
172 | struct stm32_rtc *rtc = (struct stm32_rtc *)dev_id; | 207 | struct stm32_rtc *rtc = (struct stm32_rtc *)dev_id; |
173 | unsigned int isr, cr; | 208 | const struct stm32_rtc_registers *regs = &rtc->data->regs; |
209 | const struct stm32_rtc_events *evts = &rtc->data->events; | ||
210 | unsigned int status, cr; | ||
174 | 211 | ||
175 | mutex_lock(&rtc->rtc_dev->ops_lock); | 212 | mutex_lock(&rtc->rtc_dev->ops_lock); |
176 | 213 | ||
177 | isr = readl_relaxed(rtc->base + STM32_RTC_ISR); | 214 | status = readl_relaxed(rtc->base + regs->sr); |
178 | cr = readl_relaxed(rtc->base + STM32_RTC_CR); | 215 | cr = readl_relaxed(rtc->base + regs->cr); |
179 | 216 | ||
180 | if ((isr & STM32_RTC_ISR_ALRAF) && | 217 | if ((status & evts->alra) && |
181 | (cr & STM32_RTC_CR_ALRAIE)) { | 218 | (cr & STM32_RTC_CR_ALRAIE)) { |
182 | /* Alarm A flag - Alarm interrupt */ | 219 | /* Alarm A flag - Alarm interrupt */ |
183 | dev_dbg(&rtc->rtc_dev->dev, "Alarm occurred\n"); | 220 | dev_dbg(&rtc->rtc_dev->dev, "Alarm occurred\n"); |
@@ -185,9 +222,8 @@ static irqreturn_t stm32_rtc_alarm_irq(int irq, void *dev_id) | |||
185 | /* Pass event to the kernel */ | 222 | /* Pass event to the kernel */ |
186 | rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); | 223 | rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); |
187 | 224 | ||
188 | /* Clear event flag, otherwise new events won't be received */ | 225 | /* Clear event flags, otherwise new events won't be received */ |
189 | writel_relaxed(isr & ~STM32_RTC_ISR_ALRAF, | 226 | stm32_rtc_clear_event_flags(rtc, evts->alra); |
190 | rtc->base + STM32_RTC_ISR); | ||
191 | } | 227 | } |
192 | 228 | ||
193 | mutex_unlock(&rtc->rtc_dev->ops_lock); | 229 | mutex_unlock(&rtc->rtc_dev->ops_lock); |
@@ -234,11 +270,12 @@ static void bcd2tm(struct rtc_time *tm) | |||
234 | static int stm32_rtc_read_time(struct device *dev, struct rtc_time *tm) | 270 | static int stm32_rtc_read_time(struct device *dev, struct rtc_time *tm) |
235 | { | 271 | { |
236 | struct stm32_rtc *rtc = dev_get_drvdata(dev); | 272 | struct stm32_rtc *rtc = dev_get_drvdata(dev); |
273 | const struct stm32_rtc_registers *regs = &rtc->data->regs; | ||
237 | unsigned int tr, dr; | 274 | unsigned int tr, dr; |
238 | 275 | ||
239 | /* Time and Date in BCD format */ | 276 | /* Time and Date in BCD format */ |
240 | tr = readl_relaxed(rtc->base + STM32_RTC_TR); | 277 | tr = readl_relaxed(rtc->base + regs->tr); |
241 | dr = readl_relaxed(rtc->base + STM32_RTC_DR); | 278 | dr = readl_relaxed(rtc->base + regs->dr); |
242 | 279 | ||
243 | tm->tm_sec = (tr & STM32_RTC_TR_SEC) >> STM32_RTC_TR_SEC_SHIFT; | 280 | tm->tm_sec = (tr & STM32_RTC_TR_SEC) >> STM32_RTC_TR_SEC_SHIFT; |
244 | tm->tm_min = (tr & STM32_RTC_TR_MIN) >> STM32_RTC_TR_MIN_SHIFT; | 281 | tm->tm_min = (tr & STM32_RTC_TR_MIN) >> STM32_RTC_TR_MIN_SHIFT; |
@@ -259,6 +296,7 @@ static int stm32_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
259 | static int stm32_rtc_set_time(struct device *dev, struct rtc_time *tm) | 296 | static int stm32_rtc_set_time(struct device *dev, struct rtc_time *tm) |
260 | { | 297 | { |
261 | struct stm32_rtc *rtc = dev_get_drvdata(dev); | 298 | struct stm32_rtc *rtc = dev_get_drvdata(dev); |
299 | const struct stm32_rtc_registers *regs = &rtc->data->regs; | ||
262 | unsigned int tr, dr; | 300 | unsigned int tr, dr; |
263 | int ret = 0; | 301 | int ret = 0; |
264 | 302 | ||
@@ -283,8 +321,8 @@ static int stm32_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
283 | goto end; | 321 | goto end; |
284 | } | 322 | } |
285 | 323 | ||
286 | writel_relaxed(tr, rtc->base + STM32_RTC_TR); | 324 | writel_relaxed(tr, rtc->base + regs->tr); |
287 | writel_relaxed(dr, rtc->base + STM32_RTC_DR); | 325 | writel_relaxed(dr, rtc->base + regs->dr); |
288 | 326 | ||
289 | stm32_rtc_exit_init_mode(rtc); | 327 | stm32_rtc_exit_init_mode(rtc); |
290 | 328 | ||
@@ -298,12 +336,14 @@ end: | |||
298 | static int stm32_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 336 | static int stm32_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
299 | { | 337 | { |
300 | struct stm32_rtc *rtc = dev_get_drvdata(dev); | 338 | struct stm32_rtc *rtc = dev_get_drvdata(dev); |
339 | const struct stm32_rtc_registers *regs = &rtc->data->regs; | ||
340 | const struct stm32_rtc_events *evts = &rtc->data->events; | ||
301 | struct rtc_time *tm = &alrm->time; | 341 | struct rtc_time *tm = &alrm->time; |
302 | unsigned int alrmar, cr, isr; | 342 | unsigned int alrmar, cr, status; |
303 | 343 | ||
304 | alrmar = readl_relaxed(rtc->base + STM32_RTC_ALRMAR); | 344 | alrmar = readl_relaxed(rtc->base + regs->alrmar); |
305 | cr = readl_relaxed(rtc->base + STM32_RTC_CR); | 345 | cr = readl_relaxed(rtc->base + regs->cr); |
306 | isr = readl_relaxed(rtc->base + STM32_RTC_ISR); | 346 | status = readl_relaxed(rtc->base + regs->sr); |
307 | 347 | ||
308 | if (alrmar & STM32_RTC_ALRMXR_DATE_MASK) { | 348 | if (alrmar & STM32_RTC_ALRMXR_DATE_MASK) { |
309 | /* | 349 | /* |
@@ -356,7 +396,7 @@ static int stm32_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
356 | bcd2tm(tm); | 396 | bcd2tm(tm); |
357 | 397 | ||
358 | alrm->enabled = (cr & STM32_RTC_CR_ALRAE) ? 1 : 0; | 398 | alrm->enabled = (cr & STM32_RTC_CR_ALRAE) ? 1 : 0; |
359 | alrm->pending = (isr & STM32_RTC_ISR_ALRAF) ? 1 : 0; | 399 | alrm->pending = (status & evts->alra) ? 1 : 0; |
360 | 400 | ||
361 | return 0; | 401 | return 0; |
362 | } | 402 | } |
@@ -364,9 +404,11 @@ static int stm32_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
364 | static int stm32_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | 404 | static int stm32_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
365 | { | 405 | { |
366 | struct stm32_rtc *rtc = dev_get_drvdata(dev); | 406 | struct stm32_rtc *rtc = dev_get_drvdata(dev); |
367 | unsigned int isr, cr; | 407 | const struct stm32_rtc_registers *regs = &rtc->data->regs; |
408 | const struct stm32_rtc_events *evts = &rtc->data->events; | ||
409 | unsigned int cr; | ||
368 | 410 | ||
369 | cr = readl_relaxed(rtc->base + STM32_RTC_CR); | 411 | cr = readl_relaxed(rtc->base + regs->cr); |
370 | 412 | ||
371 | stm32_rtc_wpr_unlock(rtc); | 413 | stm32_rtc_wpr_unlock(rtc); |
372 | 414 | ||
@@ -375,12 +417,10 @@ static int stm32_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | |||
375 | cr |= (STM32_RTC_CR_ALRAIE | STM32_RTC_CR_ALRAE); | 417 | cr |= (STM32_RTC_CR_ALRAIE | STM32_RTC_CR_ALRAE); |
376 | else | 418 | else |
377 | cr &= ~(STM32_RTC_CR_ALRAIE | STM32_RTC_CR_ALRAE); | 419 | cr &= ~(STM32_RTC_CR_ALRAIE | STM32_RTC_CR_ALRAE); |
378 | writel_relaxed(cr, rtc->base + STM32_RTC_CR); | 420 | writel_relaxed(cr, rtc->base + regs->cr); |
379 | 421 | ||
380 | /* Clear event flag, otherwise new events won't be received */ | 422 | /* Clear event flags, otherwise new events won't be received */ |
381 | isr = readl_relaxed(rtc->base + STM32_RTC_ISR); | 423 | stm32_rtc_clear_event_flags(rtc, evts->alra); |
382 | isr &= ~STM32_RTC_ISR_ALRAF; | ||
383 | writel_relaxed(isr, rtc->base + STM32_RTC_ISR); | ||
384 | 424 | ||
385 | stm32_rtc_wpr_lock(rtc); | 425 | stm32_rtc_wpr_lock(rtc); |
386 | 426 | ||
@@ -389,9 +429,10 @@ static int stm32_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) | |||
389 | 429 | ||
390 | static int stm32_rtc_valid_alrm(struct stm32_rtc *rtc, struct rtc_time *tm) | 430 | static int stm32_rtc_valid_alrm(struct stm32_rtc *rtc, struct rtc_time *tm) |
391 | { | 431 | { |
432 | const struct stm32_rtc_registers *regs = &rtc->data->regs; | ||
392 | int cur_day, cur_mon, cur_year, cur_hour, cur_min, cur_sec; | 433 | int cur_day, cur_mon, cur_year, cur_hour, cur_min, cur_sec; |
393 | unsigned int dr = readl_relaxed(rtc->base + STM32_RTC_DR); | 434 | unsigned int dr = readl_relaxed(rtc->base + regs->dr); |
394 | unsigned int tr = readl_relaxed(rtc->base + STM32_RTC_TR); | 435 | unsigned int tr = readl_relaxed(rtc->base + regs->tr); |
395 | 436 | ||
396 | cur_day = (dr & STM32_RTC_DR_DATE) >> STM32_RTC_DR_DATE_SHIFT; | 437 | cur_day = (dr & STM32_RTC_DR_DATE) >> STM32_RTC_DR_DATE_SHIFT; |
397 | cur_mon = (dr & STM32_RTC_DR_MONTH) >> STM32_RTC_DR_MONTH_SHIFT; | 438 | cur_mon = (dr & STM32_RTC_DR_MONTH) >> STM32_RTC_DR_MONTH_SHIFT; |
@@ -425,6 +466,7 @@ static int stm32_rtc_valid_alrm(struct stm32_rtc *rtc, struct rtc_time *tm) | |||
425 | static int stm32_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 466 | static int stm32_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
426 | { | 467 | { |
427 | struct stm32_rtc *rtc = dev_get_drvdata(dev); | 468 | struct stm32_rtc *rtc = dev_get_drvdata(dev); |
469 | const struct stm32_rtc_registers *regs = &rtc->data->regs; | ||
428 | struct rtc_time *tm = &alrm->time; | 470 | struct rtc_time *tm = &alrm->time; |
429 | unsigned int cr, isr, alrmar; | 471 | unsigned int cr, isr, alrmar; |
430 | int ret = 0; | 472 | int ret = 0; |
@@ -456,15 +498,15 @@ static int stm32_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
456 | stm32_rtc_wpr_unlock(rtc); | 498 | stm32_rtc_wpr_unlock(rtc); |
457 | 499 | ||
458 | /* Disable Alarm */ | 500 | /* Disable Alarm */ |
459 | cr = readl_relaxed(rtc->base + STM32_RTC_CR); | 501 | cr = readl_relaxed(rtc->base + regs->cr); |
460 | cr &= ~STM32_RTC_CR_ALRAE; | 502 | cr &= ~STM32_RTC_CR_ALRAE; |
461 | writel_relaxed(cr, rtc->base + STM32_RTC_CR); | 503 | writel_relaxed(cr, rtc->base + regs->cr); |
462 | 504 | ||
463 | /* | 505 | /* |
464 | * Poll Alarm write flag to be sure that Alarm update is allowed: it | 506 | * Poll Alarm write flag to be sure that Alarm update is allowed: it |
465 | * takes around 2 rtc_ck clock cycles | 507 | * takes around 2 rtc_ck clock cycles |
466 | */ | 508 | */ |
467 | ret = readl_relaxed_poll_timeout_atomic(rtc->base + STM32_RTC_ISR, | 509 | ret = readl_relaxed_poll_timeout_atomic(rtc->base + regs->isr, |
468 | isr, | 510 | isr, |
469 | (isr & STM32_RTC_ISR_ALRAWF), | 511 | (isr & STM32_RTC_ISR_ALRAWF), |
470 | 10, 100000); | 512 | 10, 100000); |
@@ -475,7 +517,7 @@ static int stm32_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
475 | } | 517 | } |
476 | 518 | ||
477 | /* Write to Alarm register */ | 519 | /* Write to Alarm register */ |
478 | writel_relaxed(alrmar, rtc->base + STM32_RTC_ALRMAR); | 520 | writel_relaxed(alrmar, rtc->base + regs->alrmar); |
479 | 521 | ||
480 | if (alrm->enabled) | 522 | if (alrm->enabled) |
481 | stm32_rtc_alarm_irq_enable(dev, 1); | 523 | stm32_rtc_alarm_irq_enable(dev, 1); |
@@ -496,17 +538,95 @@ static const struct rtc_class_ops stm32_rtc_ops = { | |||
496 | .alarm_irq_enable = stm32_rtc_alarm_irq_enable, | 538 | .alarm_irq_enable = stm32_rtc_alarm_irq_enable, |
497 | }; | 539 | }; |
498 | 540 | ||
541 | static void stm32_rtc_clear_events(struct stm32_rtc *rtc, | ||
542 | unsigned int flags) | ||
543 | { | ||
544 | const struct stm32_rtc_registers *regs = &rtc->data->regs; | ||
545 | |||
546 | /* Flags are cleared by writing 0 in RTC_ISR */ | ||
547 | writel_relaxed(readl_relaxed(rtc->base + regs->isr) & ~flags, | ||
548 | rtc->base + regs->isr); | ||
549 | } | ||
550 | |||
499 | static const struct stm32_rtc_data stm32_rtc_data = { | 551 | static const struct stm32_rtc_data stm32_rtc_data = { |
500 | .has_pclk = false, | 552 | .has_pclk = false, |
553 | .need_dbp = true, | ||
554 | .has_wakeirq = false, | ||
555 | .regs = { | ||
556 | .tr = 0x00, | ||
557 | .dr = 0x04, | ||
558 | .cr = 0x08, | ||
559 | .isr = 0x0C, | ||
560 | .prer = 0x10, | ||
561 | .alrmar = 0x1C, | ||
562 | .wpr = 0x24, | ||
563 | .sr = 0x0C, /* set to ISR offset to ease alarm management */ | ||
564 | .scr = UNDEF_REG, | ||
565 | .verr = UNDEF_REG, | ||
566 | }, | ||
567 | .events = { | ||
568 | .alra = STM32_RTC_ISR_ALRAF, | ||
569 | }, | ||
570 | .clear_events = stm32_rtc_clear_events, | ||
501 | }; | 571 | }; |
502 | 572 | ||
503 | static const struct stm32_rtc_data stm32h7_rtc_data = { | 573 | static const struct stm32_rtc_data stm32h7_rtc_data = { |
504 | .has_pclk = true, | 574 | .has_pclk = true, |
575 | .need_dbp = true, | ||
576 | .has_wakeirq = false, | ||
577 | .regs = { | ||
578 | .tr = 0x00, | ||
579 | .dr = 0x04, | ||
580 | .cr = 0x08, | ||
581 | .isr = 0x0C, | ||
582 | .prer = 0x10, | ||
583 | .alrmar = 0x1C, | ||
584 | .wpr = 0x24, | ||
585 | .sr = 0x0C, /* set to ISR offset to ease alarm management */ | ||
586 | .scr = UNDEF_REG, | ||
587 | .verr = UNDEF_REG, | ||
588 | }, | ||
589 | .events = { | ||
590 | .alra = STM32_RTC_ISR_ALRAF, | ||
591 | }, | ||
592 | .clear_events = stm32_rtc_clear_events, | ||
593 | }; | ||
594 | |||
595 | static void stm32mp1_rtc_clear_events(struct stm32_rtc *rtc, | ||
596 | unsigned int flags) | ||
597 | { | ||
598 | struct stm32_rtc_registers regs = rtc->data->regs; | ||
599 | |||
600 | /* Flags are cleared by writing 1 in RTC_SCR */ | ||
601 | writel_relaxed(flags, rtc->base + regs.scr); | ||
602 | } | ||
603 | |||
604 | static const struct stm32_rtc_data stm32mp1_data = { | ||
605 | .has_pclk = true, | ||
606 | .need_dbp = false, | ||
607 | .has_wakeirq = true, | ||
608 | .regs = { | ||
609 | .tr = 0x00, | ||
610 | .dr = 0x04, | ||
611 | .cr = 0x18, | ||
612 | .isr = 0x0C, /* named RTC_ICSR on stm32mp1 */ | ||
613 | .prer = 0x10, | ||
614 | .alrmar = 0x40, | ||
615 | .wpr = 0x24, | ||
616 | .sr = 0x50, | ||
617 | .scr = 0x5C, | ||
618 | .verr = 0x3F4, | ||
619 | }, | ||
620 | .events = { | ||
621 | .alra = STM32_RTC_SR_ALRA, | ||
622 | }, | ||
623 | .clear_events = stm32mp1_rtc_clear_events, | ||
505 | }; | 624 | }; |
506 | 625 | ||
507 | static const struct of_device_id stm32_rtc_of_match[] = { | 626 | static const struct of_device_id stm32_rtc_of_match[] = { |
508 | { .compatible = "st,stm32-rtc", .data = &stm32_rtc_data }, | 627 | { .compatible = "st,stm32-rtc", .data = &stm32_rtc_data }, |
509 | { .compatible = "st,stm32h7-rtc", .data = &stm32h7_rtc_data }, | 628 | { .compatible = "st,stm32h7-rtc", .data = &stm32h7_rtc_data }, |
629 | { .compatible = "st,stm32mp1-rtc", .data = &stm32mp1_data }, | ||
510 | {} | 630 | {} |
511 | }; | 631 | }; |
512 | MODULE_DEVICE_TABLE(of, stm32_rtc_of_match); | 632 | MODULE_DEVICE_TABLE(of, stm32_rtc_of_match); |
@@ -514,6 +634,7 @@ MODULE_DEVICE_TABLE(of, stm32_rtc_of_match); | |||
514 | static int stm32_rtc_init(struct platform_device *pdev, | 634 | static int stm32_rtc_init(struct platform_device *pdev, |
515 | struct stm32_rtc *rtc) | 635 | struct stm32_rtc *rtc) |
516 | { | 636 | { |
637 | const struct stm32_rtc_registers *regs = &rtc->data->regs; | ||
517 | unsigned int prer, pred_a, pred_s, pred_a_max, pred_s_max, cr; | 638 | unsigned int prer, pred_a, pred_s, pred_a_max, pred_s_max, cr; |
518 | unsigned int rate; | 639 | unsigned int rate; |
519 | int ret = 0; | 640 | int ret = 0; |
@@ -554,14 +675,14 @@ static int stm32_rtc_init(struct platform_device *pdev, | |||
554 | } | 675 | } |
555 | 676 | ||
556 | prer = (pred_s << STM32_RTC_PRER_PRED_S_SHIFT) & STM32_RTC_PRER_PRED_S; | 677 | prer = (pred_s << STM32_RTC_PRER_PRED_S_SHIFT) & STM32_RTC_PRER_PRED_S; |
557 | writel_relaxed(prer, rtc->base + STM32_RTC_PRER); | 678 | writel_relaxed(prer, rtc->base + regs->prer); |
558 | prer |= (pred_a << STM32_RTC_PRER_PRED_A_SHIFT) & STM32_RTC_PRER_PRED_A; | 679 | prer |= (pred_a << STM32_RTC_PRER_PRED_A_SHIFT) & STM32_RTC_PRER_PRED_A; |
559 | writel_relaxed(prer, rtc->base + STM32_RTC_PRER); | 680 | writel_relaxed(prer, rtc->base + regs->prer); |
560 | 681 | ||
561 | /* Force 24h time format */ | 682 | /* Force 24h time format */ |
562 | cr = readl_relaxed(rtc->base + STM32_RTC_CR); | 683 | cr = readl_relaxed(rtc->base + regs->cr); |
563 | cr &= ~STM32_RTC_CR_FMT; | 684 | cr &= ~STM32_RTC_CR_FMT; |
564 | writel_relaxed(cr, rtc->base + STM32_RTC_CR); | 685 | writel_relaxed(cr, rtc->base + regs->cr); |
565 | 686 | ||
566 | stm32_rtc_exit_init_mode(rtc); | 687 | stm32_rtc_exit_init_mode(rtc); |
567 | 688 | ||
@@ -575,8 +696,8 @@ end: | |||
575 | static int stm32_rtc_probe(struct platform_device *pdev) | 696 | static int stm32_rtc_probe(struct platform_device *pdev) |
576 | { | 697 | { |
577 | struct stm32_rtc *rtc; | 698 | struct stm32_rtc *rtc; |
699 | const struct stm32_rtc_registers *regs; | ||
578 | struct resource *res; | 700 | struct resource *res; |
579 | const struct of_device_id *match; | ||
580 | int ret; | 701 | int ret; |
581 | 702 | ||
582 | rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); | 703 | rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); |
@@ -588,15 +709,32 @@ static int stm32_rtc_probe(struct platform_device *pdev) | |||
588 | if (IS_ERR(rtc->base)) | 709 | if (IS_ERR(rtc->base)) |
589 | return PTR_ERR(rtc->base); | 710 | return PTR_ERR(rtc->base); |
590 | 711 | ||
591 | rtc->dbp = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, | 712 | rtc->data = (struct stm32_rtc_data *) |
592 | "st,syscfg"); | 713 | of_device_get_match_data(&pdev->dev); |
593 | if (IS_ERR(rtc->dbp)) { | 714 | regs = &rtc->data->regs; |
594 | dev_err(&pdev->dev, "no st,syscfg\n"); | 715 | |
595 | return PTR_ERR(rtc->dbp); | 716 | if (rtc->data->need_dbp) { |
596 | } | 717 | rtc->dbp = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, |
718 | "st,syscfg"); | ||
719 | if (IS_ERR(rtc->dbp)) { | ||
720 | dev_err(&pdev->dev, "no st,syscfg\n"); | ||
721 | return PTR_ERR(rtc->dbp); | ||
722 | } | ||
723 | |||
724 | ret = of_property_read_u32_index(pdev->dev.of_node, "st,syscfg", | ||
725 | 1, &rtc->dbp_reg); | ||
726 | if (ret) { | ||
727 | dev_err(&pdev->dev, "can't read DBP register offset\n"); | ||
728 | return ret; | ||
729 | } | ||
597 | 730 | ||
598 | match = of_match_device(stm32_rtc_of_match, &pdev->dev); | 731 | ret = of_property_read_u32_index(pdev->dev.of_node, "st,syscfg", |
599 | rtc->data = (struct stm32_rtc_data *)match->data; | 732 | 2, &rtc->dbp_mask); |
733 | if (ret) { | ||
734 | dev_err(&pdev->dev, "can't read DBP register mask\n"); | ||
735 | return ret; | ||
736 | } | ||
737 | } | ||
600 | 738 | ||
601 | if (!rtc->data->has_pclk) { | 739 | if (!rtc->data->has_pclk) { |
602 | rtc->pclk = NULL; | 740 | rtc->pclk = NULL; |
@@ -624,11 +762,13 @@ static int stm32_rtc_probe(struct platform_device *pdev) | |||
624 | if (ret) | 762 | if (ret) |
625 | goto err; | 763 | goto err; |
626 | 764 | ||
627 | regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, PWR_CR_DBP); | 765 | if (rtc->data->need_dbp) |
766 | regmap_update_bits(rtc->dbp, rtc->dbp_reg, | ||
767 | rtc->dbp_mask, rtc->dbp_mask); | ||
628 | 768 | ||
629 | /* | 769 | /* |
630 | * After a system reset, RTC_ISR.INITS flag can be read to check if | 770 | * After a system reset, RTC_ISR.INITS flag can be read to check if |
631 | * the calendar has been initalized or not. INITS flag is reset by a | 771 | * the calendar has been initialized or not. INITS flag is reset by a |
632 | * power-on reset (no vbat, no power-supply). It is not reset if | 772 | * power-on reset (no vbat, no power-supply). It is not reset if |
633 | * rtc_ck parent clock has changed (so RTC prescalers need to be | 773 | * rtc_ck parent clock has changed (so RTC prescalers need to be |
634 | * changed). That's why we cannot rely on this flag to know if RTC | 774 | * changed). That's why we cannot rely on this flag to know if RTC |
@@ -645,15 +785,22 @@ static int stm32_rtc_probe(struct platform_device *pdev) | |||
645 | goto err; | 785 | goto err; |
646 | } | 786 | } |
647 | 787 | ||
648 | platform_set_drvdata(pdev, rtc); | ||
649 | |||
650 | ret = device_init_wakeup(&pdev->dev, true); | 788 | ret = device_init_wakeup(&pdev->dev, true); |
789 | if (rtc->data->has_wakeirq) { | ||
790 | rtc->wakeirq_alarm = platform_get_irq(pdev, 1); | ||
791 | if (rtc->wakeirq_alarm <= 0) | ||
792 | ret = rtc->wakeirq_alarm; | ||
793 | else | ||
794 | ret = dev_pm_set_dedicated_wake_irq(&pdev->dev, | ||
795 | rtc->wakeirq_alarm); | ||
796 | } | ||
651 | if (ret) | 797 | if (ret) |
652 | dev_warn(&pdev->dev, | 798 | dev_warn(&pdev->dev, "alarm can't wake up the system: %d", ret); |
653 | "alarm won't be able to wake up the system"); | 799 | |
800 | platform_set_drvdata(pdev, rtc); | ||
654 | 801 | ||
655 | rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, | 802 | rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, |
656 | &stm32_rtc_ops, THIS_MODULE); | 803 | &stm32_rtc_ops, THIS_MODULE); |
657 | if (IS_ERR(rtc->rtc_dev)) { | 804 | if (IS_ERR(rtc->rtc_dev)) { |
658 | ret = PTR_ERR(rtc->rtc_dev); | 805 | ret = PTR_ERR(rtc->rtc_dev); |
659 | dev_err(&pdev->dev, "rtc device registration failed, err=%d\n", | 806 | dev_err(&pdev->dev, "rtc device registration failed, err=%d\n", |
@@ -663,8 +810,7 @@ static int stm32_rtc_probe(struct platform_device *pdev) | |||
663 | 810 | ||
664 | /* Handle RTC alarm interrupts */ | 811 | /* Handle RTC alarm interrupts */ |
665 | ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_alarm, NULL, | 812 | ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_alarm, NULL, |
666 | stm32_rtc_alarm_irq, | 813 | stm32_rtc_alarm_irq, IRQF_ONESHOT, |
667 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, | ||
668 | pdev->name, rtc); | 814 | pdev->name, rtc); |
669 | if (ret) { | 815 | if (ret) { |
670 | dev_err(&pdev->dev, "IRQ%d (alarm interrupt) already claimed\n", | 816 | dev_err(&pdev->dev, "IRQ%d (alarm interrupt) already claimed\n", |
@@ -676,17 +822,27 @@ static int stm32_rtc_probe(struct platform_device *pdev) | |||
676 | * If INITS flag is reset (calendar year field set to 0x00), calendar | 822 | * If INITS flag is reset (calendar year field set to 0x00), calendar |
677 | * must be initialized | 823 | * must be initialized |
678 | */ | 824 | */ |
679 | if (!(readl_relaxed(rtc->base + STM32_RTC_ISR) & STM32_RTC_ISR_INITS)) | 825 | if (!(readl_relaxed(rtc->base + regs->isr) & STM32_RTC_ISR_INITS)) |
680 | dev_warn(&pdev->dev, "Date/Time must be initialized\n"); | 826 | dev_warn(&pdev->dev, "Date/Time must be initialized\n"); |
681 | 827 | ||
828 | if (regs->verr != UNDEF_REG) { | ||
829 | u32 ver = readl_relaxed(rtc->base + regs->verr); | ||
830 | |||
831 | dev_info(&pdev->dev, "registered rev:%d.%d\n", | ||
832 | (ver >> STM32_RTC_VERR_MAJREV_SHIFT) & 0xF, | ||
833 | (ver >> STM32_RTC_VERR_MINREV_SHIFT) & 0xF); | ||
834 | } | ||
835 | |||
682 | return 0; | 836 | return 0; |
683 | err: | 837 | err: |
684 | if (rtc->data->has_pclk) | 838 | if (rtc->data->has_pclk) |
685 | clk_disable_unprepare(rtc->pclk); | 839 | clk_disable_unprepare(rtc->pclk); |
686 | clk_disable_unprepare(rtc->rtc_ck); | 840 | clk_disable_unprepare(rtc->rtc_ck); |
687 | 841 | ||
688 | regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, 0); | 842 | if (rtc->data->need_dbp) |
843 | regmap_update_bits(rtc->dbp, rtc->dbp_reg, rtc->dbp_mask, 0); | ||
689 | 844 | ||
845 | dev_pm_clear_wake_irq(&pdev->dev); | ||
690 | device_init_wakeup(&pdev->dev, false); | 846 | device_init_wakeup(&pdev->dev, false); |
691 | 847 | ||
692 | return ret; | 848 | return ret; |
@@ -695,22 +851,25 @@ err: | |||
695 | static int stm32_rtc_remove(struct platform_device *pdev) | 851 | static int stm32_rtc_remove(struct platform_device *pdev) |
696 | { | 852 | { |
697 | struct stm32_rtc *rtc = platform_get_drvdata(pdev); | 853 | struct stm32_rtc *rtc = platform_get_drvdata(pdev); |
854 | const struct stm32_rtc_registers *regs = &rtc->data->regs; | ||
698 | unsigned int cr; | 855 | unsigned int cr; |
699 | 856 | ||
700 | /* Disable interrupts */ | 857 | /* Disable interrupts */ |
701 | stm32_rtc_wpr_unlock(rtc); | 858 | stm32_rtc_wpr_unlock(rtc); |
702 | cr = readl_relaxed(rtc->base + STM32_RTC_CR); | 859 | cr = readl_relaxed(rtc->base + regs->cr); |
703 | cr &= ~STM32_RTC_CR_ALRAIE; | 860 | cr &= ~STM32_RTC_CR_ALRAIE; |
704 | writel_relaxed(cr, rtc->base + STM32_RTC_CR); | 861 | writel_relaxed(cr, rtc->base + regs->cr); |
705 | stm32_rtc_wpr_lock(rtc); | 862 | stm32_rtc_wpr_lock(rtc); |
706 | 863 | ||
707 | clk_disable_unprepare(rtc->rtc_ck); | 864 | clk_disable_unprepare(rtc->rtc_ck); |
708 | if (rtc->data->has_pclk) | 865 | if (rtc->data->has_pclk) |
709 | clk_disable_unprepare(rtc->pclk); | 866 | clk_disable_unprepare(rtc->pclk); |
710 | 867 | ||
711 | /* Enable backup domain write protection */ | 868 | /* Enable backup domain write protection if needed */ |
712 | regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, 0); | 869 | if (rtc->data->need_dbp) |
870 | regmap_update_bits(rtc->dbp, rtc->dbp_reg, rtc->dbp_mask, 0); | ||
713 | 871 | ||
872 | dev_pm_clear_wake_irq(&pdev->dev); | ||
714 | device_init_wakeup(&pdev->dev, false); | 873 | device_init_wakeup(&pdev->dev, false); |
715 | 874 | ||
716 | return 0; | 875 | return 0; |
diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c index 2e6fb275acc8..2cd5a7b1a2e3 100644 --- a/drivers/rtc/rtc-sun6i.c +++ b/drivers/rtc/rtc-sun6i.c | |||
@@ -74,7 +74,7 @@ | |||
74 | #define SUN6I_ALARM_CONFIG_WAKEUP BIT(0) | 74 | #define SUN6I_ALARM_CONFIG_WAKEUP BIT(0) |
75 | 75 | ||
76 | #define SUN6I_LOSC_OUT_GATING 0x0060 | 76 | #define SUN6I_LOSC_OUT_GATING 0x0060 |
77 | #define SUN6I_LOSC_OUT_GATING_EN BIT(0) | 77 | #define SUN6I_LOSC_OUT_GATING_EN_OFFSET 0 |
78 | 78 | ||
79 | /* | 79 | /* |
80 | * Get date values | 80 | * Get date values |
@@ -255,7 +255,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node) | |||
255 | &clkout_name); | 255 | &clkout_name); |
256 | rtc->ext_losc = clk_register_gate(NULL, clkout_name, rtc->hw.init->name, | 256 | rtc->ext_losc = clk_register_gate(NULL, clkout_name, rtc->hw.init->name, |
257 | 0, rtc->base + SUN6I_LOSC_OUT_GATING, | 257 | 0, rtc->base + SUN6I_LOSC_OUT_GATING, |
258 | SUN6I_LOSC_OUT_GATING_EN, 0, | 258 | SUN6I_LOSC_OUT_GATING_EN_OFFSET, 0, |
259 | &rtc->lock); | 259 | &rtc->lock); |
260 | if (IS_ERR(rtc->ext_losc)) { | 260 | if (IS_ERR(rtc->ext_losc)) { |
261 | pr_crit("Couldn't register the LOSC external gate\n"); | 261 | pr_crit("Couldn't register the LOSC external gate\n"); |
diff --git a/drivers/rtc/rtc-sunxi.c b/drivers/rtc/rtc-sunxi.c index dadbf8b324ad..21865d3d8fe8 100644 --- a/drivers/rtc/rtc-sunxi.c +++ b/drivers/rtc/rtc-sunxi.c | |||
@@ -445,6 +445,10 @@ static int sunxi_rtc_probe(struct platform_device *pdev) | |||
445 | platform_set_drvdata(pdev, chip); | 445 | platform_set_drvdata(pdev, chip); |
446 | chip->dev = &pdev->dev; | 446 | chip->dev = &pdev->dev; |
447 | 447 | ||
448 | chip->rtc = devm_rtc_allocate_device(&pdev->dev); | ||
449 | if (IS_ERR(chip->rtc)) | ||
450 | return PTR_ERR(chip->rtc); | ||
451 | |||
448 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 452 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
449 | chip->base = devm_ioremap_resource(&pdev->dev, res); | 453 | chip->base = devm_ioremap_resource(&pdev->dev, res); |
450 | if (IS_ERR(chip->base)) | 454 | if (IS_ERR(chip->base)) |
@@ -481,11 +485,12 @@ static int sunxi_rtc_probe(struct platform_device *pdev) | |||
481 | writel(SUNXI_ALRM_IRQ_STA_CNT_IRQ_PEND, chip->base + | 485 | writel(SUNXI_ALRM_IRQ_STA_CNT_IRQ_PEND, chip->base + |
482 | SUNXI_ALRM_IRQ_STA); | 486 | SUNXI_ALRM_IRQ_STA); |
483 | 487 | ||
484 | chip->rtc = rtc_device_register("rtc-sunxi", &pdev->dev, | 488 | chip->rtc->ops = &sunxi_rtc_ops; |
485 | &sunxi_rtc_ops, THIS_MODULE); | 489 | |
486 | if (IS_ERR(chip->rtc)) { | 490 | ret = rtc_register_device(chip->rtc); |
491 | if (ret) { | ||
487 | dev_err(&pdev->dev, "unable to register device\n"); | 492 | dev_err(&pdev->dev, "unable to register device\n"); |
488 | return PTR_ERR(chip->rtc); | 493 | return ret; |
489 | } | 494 | } |
490 | 495 | ||
491 | dev_info(&pdev->dev, "RTC enabled\n"); | 496 | dev_info(&pdev->dev, "RTC enabled\n"); |
@@ -493,18 +498,8 @@ static int sunxi_rtc_probe(struct platform_device *pdev) | |||
493 | return 0; | 498 | return 0; |
494 | } | 499 | } |
495 | 500 | ||
496 | static int sunxi_rtc_remove(struct platform_device *pdev) | ||
497 | { | ||
498 | struct sunxi_rtc_dev *chip = platform_get_drvdata(pdev); | ||
499 | |||
500 | rtc_device_unregister(chip->rtc); | ||
501 | |||
502 | return 0; | ||
503 | } | ||
504 | |||
505 | static struct platform_driver sunxi_rtc_driver = { | 501 | static struct platform_driver sunxi_rtc_driver = { |
506 | .probe = sunxi_rtc_probe, | 502 | .probe = sunxi_rtc_probe, |
507 | .remove = sunxi_rtc_remove, | ||
508 | .driver = { | 503 | .driver = { |
509 | .name = "sunxi-rtc", | 504 | .name = "sunxi-rtc", |
510 | .of_match_table = sunxi_rtc_dt_ids, | 505 | .of_match_table = sunxi_rtc_dt_ids, |
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c index 3a2da4c892d6..8469256edc2a 100644 --- a/drivers/rtc/rtc-test.c +++ b/drivers/rtc/rtc-test.c | |||
@@ -13,135 +13,139 @@ | |||
13 | #include <linux/rtc.h> | 13 | #include <linux/rtc.h> |
14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
15 | 15 | ||
16 | static int test_mmss64; | 16 | #define MAX_RTC_TEST 3 |
17 | module_param(test_mmss64, int, 0644); | ||
18 | MODULE_PARM_DESC(test_mmss64, "Test struct rtc_class_ops.set_mmss64()."); | ||
19 | 17 | ||
20 | static struct platform_device *test0 = NULL, *test1 = NULL; | 18 | struct rtc_test_data { |
19 | struct rtc_device *rtc; | ||
20 | time64_t offset; | ||
21 | struct timer_list alarm; | ||
22 | bool alarm_en; | ||
23 | }; | ||
21 | 24 | ||
22 | static int test_rtc_read_alarm(struct device *dev, | 25 | struct platform_device *pdev[MAX_RTC_TEST]; |
23 | struct rtc_wkalrm *alrm) | ||
24 | { | ||
25 | return 0; | ||
26 | } | ||
27 | 26 | ||
28 | static int test_rtc_set_alarm(struct device *dev, | 27 | static int test_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
29 | struct rtc_wkalrm *alrm) | ||
30 | { | 28 | { |
31 | return 0; | 29 | struct rtc_test_data *rtd = dev_get_drvdata(dev); |
32 | } | 30 | time64_t alarm; |
31 | |||
32 | alarm = (rtd->alarm.expires - jiffies) / HZ; | ||
33 | alarm += ktime_get_real_seconds() + rtd->offset; | ||
34 | |||
35 | rtc_time64_to_tm(alarm, &alrm->time); | ||
36 | alrm->enabled = rtd->alarm_en; | ||
33 | 37 | ||
34 | static int test_rtc_read_time(struct device *dev, | ||
35 | struct rtc_time *tm) | ||
36 | { | ||
37 | rtc_time64_to_tm(ktime_get_real_seconds(), tm); | ||
38 | return 0; | 38 | return 0; |
39 | } | 39 | } |
40 | 40 | ||
41 | static int test_rtc_set_mmss64(struct device *dev, time64_t secs) | 41 | static int test_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
42 | { | 42 | { |
43 | dev_info(dev, "%s, secs = %lld\n", __func__, (long long)secs); | 43 | struct rtc_test_data *rtd = dev_get_drvdata(dev); |
44 | ktime_t timeout; | ||
45 | u64 expires; | ||
46 | |||
47 | timeout = rtc_tm_to_time64(&alrm->time) - ktime_get_real_seconds(); | ||
48 | timeout -= rtd->offset; | ||
49 | |||
50 | del_timer(&rtd->alarm); | ||
51 | |||
52 | expires = jiffies + timeout * HZ; | ||
53 | if (expires > U32_MAX) | ||
54 | expires = U32_MAX; | ||
55 | |||
56 | pr_err("ABE: %s +%d %s\n", __FILE__, __LINE__, __func__); | ||
57 | rtd->alarm.expires = expires; | ||
58 | |||
59 | if (alrm->enabled) | ||
60 | add_timer(&rtd->alarm); | ||
61 | |||
62 | rtd->alarm_en = alrm->enabled; | ||
63 | |||
44 | return 0; | 64 | return 0; |
45 | } | 65 | } |
46 | 66 | ||
47 | static int test_rtc_set_mmss(struct device *dev, unsigned long secs) | 67 | static int test_rtc_read_time(struct device *dev, struct rtc_time *tm) |
48 | { | 68 | { |
49 | dev_info(dev, "%s, secs = %lu\n", __func__, secs); | 69 | struct rtc_test_data *rtd = dev_get_drvdata(dev); |
70 | |||
71 | rtc_time64_to_tm(ktime_get_real_seconds() + rtd->offset, tm); | ||
72 | |||
50 | return 0; | 73 | return 0; |
51 | } | 74 | } |
52 | 75 | ||
53 | static int test_rtc_proc(struct device *dev, struct seq_file *seq) | 76 | static int test_rtc_set_mmss64(struct device *dev, time64_t secs) |
54 | { | 77 | { |
55 | struct platform_device *plat_dev = to_platform_device(dev); | 78 | struct rtc_test_data *rtd = dev_get_drvdata(dev); |
56 | 79 | ||
57 | seq_printf(seq, "test\t\t: yes\n"); | 80 | rtd->offset = secs - ktime_get_real_seconds(); |
58 | seq_printf(seq, "id\t\t: %d\n", plat_dev->id); | ||
59 | 81 | ||
60 | return 0; | 82 | return 0; |
61 | } | 83 | } |
62 | 84 | ||
63 | static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) | 85 | static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) |
64 | { | 86 | { |
87 | struct rtc_test_data *rtd = dev_get_drvdata(dev); | ||
88 | |||
89 | rtd->alarm_en = enable; | ||
90 | if (enable) | ||
91 | add_timer(&rtd->alarm); | ||
92 | else | ||
93 | del_timer(&rtd->alarm); | ||
94 | |||
65 | return 0; | 95 | return 0; |
66 | } | 96 | } |
67 | 97 | ||
68 | static struct rtc_class_ops test_rtc_ops = { | 98 | static const struct rtc_class_ops test_rtc_ops_noalm = { |
69 | .proc = test_rtc_proc, | 99 | .read_time = test_rtc_read_time, |
100 | .set_mmss64 = test_rtc_set_mmss64, | ||
101 | .alarm_irq_enable = test_rtc_alarm_irq_enable, | ||
102 | }; | ||
103 | |||
104 | static const struct rtc_class_ops test_rtc_ops = { | ||
70 | .read_time = test_rtc_read_time, | 105 | .read_time = test_rtc_read_time, |
71 | .read_alarm = test_rtc_read_alarm, | 106 | .read_alarm = test_rtc_read_alarm, |
72 | .set_alarm = test_rtc_set_alarm, | 107 | .set_alarm = test_rtc_set_alarm, |
73 | .set_mmss = test_rtc_set_mmss, | 108 | .set_mmss64 = test_rtc_set_mmss64, |
74 | .alarm_irq_enable = test_rtc_alarm_irq_enable, | 109 | .alarm_irq_enable = test_rtc_alarm_irq_enable, |
75 | }; | 110 | }; |
76 | 111 | ||
77 | static ssize_t test_irq_show(struct device *dev, | 112 | static void test_rtc_alarm_handler(struct timer_list *t) |
78 | struct device_attribute *attr, char *buf) | ||
79 | { | 113 | { |
80 | return sprintf(buf, "%d\n", 42); | 114 | struct rtc_test_data *rtd = from_timer(rtd, t, alarm); |
81 | } | ||
82 | static ssize_t test_irq_store(struct device *dev, | ||
83 | struct device_attribute *attr, | ||
84 | const char *buf, size_t count) | ||
85 | { | ||
86 | int retval; | ||
87 | struct platform_device *plat_dev = to_platform_device(dev); | ||
88 | struct rtc_device *rtc = platform_get_drvdata(plat_dev); | ||
89 | |||
90 | retval = count; | ||
91 | if (strncmp(buf, "tick", 4) == 0 && rtc->pie_enabled) | ||
92 | rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF); | ||
93 | else if (strncmp(buf, "alarm", 5) == 0) { | ||
94 | struct rtc_wkalrm alrm; | ||
95 | int err = rtc_read_alarm(rtc, &alrm); | ||
96 | |||
97 | if (!err && alrm.enabled) | ||
98 | rtc_update_irq(rtc, 1, RTC_AF | RTC_IRQF); | ||
99 | |||
100 | } else if (strncmp(buf, "update", 6) == 0 && rtc->uie_rtctimer.enabled) | ||
101 | rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF); | ||
102 | else | ||
103 | retval = -EINVAL; | ||
104 | 115 | ||
105 | return retval; | 116 | rtc_update_irq(rtd->rtc, 1, RTC_AF | RTC_IRQF); |
106 | } | 117 | } |
107 | static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store); | ||
108 | 118 | ||
109 | static int test_probe(struct platform_device *plat_dev) | 119 | static int test_probe(struct platform_device *plat_dev) |
110 | { | 120 | { |
111 | int err; | 121 | struct rtc_test_data *rtd; |
112 | struct rtc_device *rtc; | ||
113 | |||
114 | if (test_mmss64) { | ||
115 | test_rtc_ops.set_mmss64 = test_rtc_set_mmss64; | ||
116 | test_rtc_ops.set_mmss = NULL; | ||
117 | } | ||
118 | 122 | ||
119 | rtc = devm_rtc_device_register(&plat_dev->dev, "test", | 123 | rtd = devm_kzalloc(&plat_dev->dev, sizeof(*rtd), GFP_KERNEL); |
120 | &test_rtc_ops, THIS_MODULE); | 124 | if (!rtd) |
121 | if (IS_ERR(rtc)) { | 125 | return -ENOMEM; |
122 | return PTR_ERR(rtc); | ||
123 | } | ||
124 | 126 | ||
125 | err = device_create_file(&plat_dev->dev, &dev_attr_irq); | 127 | platform_set_drvdata(plat_dev, rtd); |
126 | if (err) | ||
127 | dev_err(&plat_dev->dev, "Unable to create sysfs entry: %s\n", | ||
128 | dev_attr_irq.attr.name); | ||
129 | 128 | ||
130 | platform_set_drvdata(plat_dev, rtc); | 129 | rtd->rtc = devm_rtc_allocate_device(&plat_dev->dev); |
130 | if (IS_ERR(rtd->rtc)) | ||
131 | return PTR_ERR(rtd->rtc); | ||
131 | 132 | ||
132 | return 0; | 133 | switch (plat_dev->id) { |
133 | } | 134 | case 0: |
135 | rtd->rtc->ops = &test_rtc_ops_noalm; | ||
136 | break; | ||
137 | default: | ||
138 | rtd->rtc->ops = &test_rtc_ops; | ||
139 | } | ||
134 | 140 | ||
135 | static int test_remove(struct platform_device *plat_dev) | 141 | timer_setup(&rtd->alarm, test_rtc_alarm_handler, 0); |
136 | { | 142 | rtd->alarm.expires = 0; |
137 | device_remove_file(&plat_dev->dev, &dev_attr_irq); | ||
138 | 143 | ||
139 | return 0; | 144 | return rtc_register_device(rtd->rtc); |
140 | } | 145 | } |
141 | 146 | ||
142 | static struct platform_driver test_driver = { | 147 | static struct platform_driver test_driver = { |
143 | .probe = test_probe, | 148 | .probe = test_probe, |
144 | .remove = test_remove, | ||
145 | .driver = { | 149 | .driver = { |
146 | .name = "rtc-test", | 150 | .name = "rtc-test", |
147 | }, | 151 | }, |
@@ -149,47 +153,45 @@ static struct platform_driver test_driver = { | |||
149 | 153 | ||
150 | static int __init test_init(void) | 154 | static int __init test_init(void) |
151 | { | 155 | { |
152 | int err; | 156 | int i, err; |
153 | 157 | ||
154 | if ((err = platform_driver_register(&test_driver))) | 158 | if ((err = platform_driver_register(&test_driver))) |
155 | return err; | 159 | return err; |
156 | 160 | ||
157 | if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) { | 161 | err = -ENOMEM; |
158 | err = -ENOMEM; | 162 | for (i = 0; i < MAX_RTC_TEST; i++) { |
159 | goto exit_driver_unregister; | 163 | pdev[i] = platform_device_alloc("rtc-test", i); |
164 | if (!pdev[i]) | ||
165 | goto exit_free_mem; | ||
160 | } | 166 | } |
161 | 167 | ||
162 | if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) { | 168 | for (i = 0; i < MAX_RTC_TEST; i++) { |
163 | err = -ENOMEM; | 169 | err = platform_device_add(pdev[i]); |
164 | goto exit_put_test0; | 170 | if (err) |
171 | goto exit_device_del; | ||
165 | } | 172 | } |
166 | 173 | ||
167 | if ((err = platform_device_add(test0))) | ||
168 | goto exit_put_test1; | ||
169 | |||
170 | if ((err = platform_device_add(test1))) | ||
171 | goto exit_del_test0; | ||
172 | |||
173 | return 0; | 174 | return 0; |
174 | 175 | ||
175 | exit_del_test0: | 176 | exit_device_del: |
176 | platform_device_del(test0); | 177 | for (; i > 0; i--) |
177 | 178 | platform_device_del(pdev[i - 1]); | |
178 | exit_put_test1: | ||
179 | platform_device_put(test1); | ||
180 | 179 | ||
181 | exit_put_test0: | 180 | exit_free_mem: |
182 | platform_device_put(test0); | 181 | for (i = 0; i < MAX_RTC_TEST; i++) |
182 | platform_device_put(pdev[i]); | ||
183 | 183 | ||
184 | exit_driver_unregister: | ||
185 | platform_driver_unregister(&test_driver); | 184 | platform_driver_unregister(&test_driver); |
186 | return err; | 185 | return err; |
187 | } | 186 | } |
188 | 187 | ||
189 | static void __exit test_exit(void) | 188 | static void __exit test_exit(void) |
190 | { | 189 | { |
191 | platform_device_unregister(test0); | 190 | int i; |
192 | platform_device_unregister(test1); | 191 | |
192 | for (i = 0; i < MAX_RTC_TEST; i++) | ||
193 | platform_device_unregister(pdev[i]); | ||
194 | |||
193 | platform_driver_unregister(&test_driver); | 195 | platform_driver_unregister(&test_driver); |
194 | } | 196 | } |
195 | 197 | ||
diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c index d7785ae0a2b4..d6434e514a52 100644 --- a/drivers/rtc/rtc-tps6586x.c +++ b/drivers/rtc/rtc-tps6586x.c | |||
@@ -58,7 +58,6 @@ struct tps6586x_rtc { | |||
58 | struct rtc_device *rtc; | 58 | struct rtc_device *rtc; |
59 | int irq; | 59 | int irq; |
60 | bool irq_en; | 60 | bool irq_en; |
61 | unsigned long long epoch_start; | ||
62 | }; | 61 | }; |
63 | 62 | ||
64 | static inline struct device *to_tps6586x_dev(struct device *dev) | 63 | static inline struct device *to_tps6586x_dev(struct device *dev) |
@@ -68,10 +67,9 @@ static inline struct device *to_tps6586x_dev(struct device *dev) | |||
68 | 67 | ||
69 | static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm) | 68 | static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm) |
70 | { | 69 | { |
71 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | ||
72 | struct device *tps_dev = to_tps6586x_dev(dev); | 70 | struct device *tps_dev = to_tps6586x_dev(dev); |
73 | unsigned long long ticks = 0; | 71 | unsigned long long ticks = 0; |
74 | unsigned long seconds; | 72 | time64_t seconds; |
75 | u8 buff[6]; | 73 | u8 buff[6]; |
76 | int ret; | 74 | int ret; |
77 | int i; | 75 | int i; |
@@ -88,26 +86,20 @@ static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
88 | } | 86 | } |
89 | 87 | ||
90 | seconds = ticks >> 10; | 88 | seconds = ticks >> 10; |
91 | seconds += rtc->epoch_start; | 89 | rtc_time64_to_tm(seconds, tm); |
92 | rtc_time_to_tm(seconds, tm); | 90 | |
93 | return 0; | 91 | return 0; |
94 | } | 92 | } |
95 | 93 | ||
96 | static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm) | 94 | static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm) |
97 | { | 95 | { |
98 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | ||
99 | struct device *tps_dev = to_tps6586x_dev(dev); | 96 | struct device *tps_dev = to_tps6586x_dev(dev); |
100 | unsigned long long ticks; | 97 | unsigned long long ticks; |
101 | unsigned long seconds; | 98 | time64_t seconds; |
102 | u8 buff[5]; | 99 | u8 buff[5]; |
103 | int ret; | 100 | int ret; |
104 | 101 | ||
105 | rtc_tm_to_time(tm, &seconds); | 102 | seconds = rtc_tm_to_time64(tm); |
106 | if (seconds < rtc->epoch_start) { | ||
107 | dev_err(dev, "requested time unsupported\n"); | ||
108 | return -EINVAL; | ||
109 | } | ||
110 | seconds -= rtc->epoch_start; | ||
111 | 103 | ||
112 | ticks = (unsigned long long)seconds << 10; | 104 | ticks = (unsigned long long)seconds << 10; |
113 | buff[0] = (ticks >> 32) & 0xff; | 105 | buff[0] = (ticks >> 32) & 0xff; |
@@ -155,9 +147,8 @@ static int tps6586x_rtc_alarm_irq_enable(struct device *dev, | |||
155 | 147 | ||
156 | static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 148 | static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
157 | { | 149 | { |
158 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | ||
159 | struct device *tps_dev = to_tps6586x_dev(dev); | 150 | struct device *tps_dev = to_tps6586x_dev(dev); |
160 | unsigned long seconds; | 151 | time64_t seconds; |
161 | unsigned long ticks; | 152 | unsigned long ticks; |
162 | unsigned long rtc_current_time; | 153 | unsigned long rtc_current_time; |
163 | unsigned long long rticks = 0; | 154 | unsigned long long rticks = 0; |
@@ -166,12 +157,7 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
166 | int ret; | 157 | int ret; |
167 | int i; | 158 | int i; |
168 | 159 | ||
169 | rtc_tm_to_time(&alrm->time, &seconds); | 160 | seconds = rtc_tm_to_time64(&alrm->time); |
170 | |||
171 | if (alrm->enabled && (seconds < rtc->epoch_start)) { | ||
172 | dev_err(dev, "can't set alarm to requested time\n"); | ||
173 | return -EINVAL; | ||
174 | } | ||
175 | 161 | ||
176 | ret = tps6586x_rtc_alarm_irq_enable(dev, alrm->enabled); | 162 | ret = tps6586x_rtc_alarm_irq_enable(dev, alrm->enabled); |
177 | if (ret < 0) { | 163 | if (ret < 0) { |
@@ -179,7 +165,6 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
179 | return ret; | 165 | return ret; |
180 | } | 166 | } |
181 | 167 | ||
182 | seconds -= rtc->epoch_start; | ||
183 | ret = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, | 168 | ret = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, |
184 | sizeof(rbuff), rbuff); | 169 | sizeof(rbuff), rbuff); |
185 | if (ret < 0) { | 170 | if (ret < 0) { |
@@ -210,10 +195,9 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
210 | 195 | ||
211 | static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 196 | static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
212 | { | 197 | { |
213 | struct tps6586x_rtc *rtc = dev_get_drvdata(dev); | ||
214 | struct device *tps_dev = to_tps6586x_dev(dev); | 198 | struct device *tps_dev = to_tps6586x_dev(dev); |
215 | unsigned long ticks; | 199 | unsigned long ticks; |
216 | unsigned long seconds; | 200 | time64_t seconds; |
217 | u8 buff[3]; | 201 | u8 buff[3]; |
218 | int ret; | 202 | int ret; |
219 | 203 | ||
@@ -225,9 +209,8 @@ static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
225 | 209 | ||
226 | ticks = (buff[0] << 16) | (buff[1] << 8) | buff[2]; | 210 | ticks = (buff[0] << 16) | (buff[1] << 8) | buff[2]; |
227 | seconds = ticks >> 10; | 211 | seconds = ticks >> 10; |
228 | seconds += rtc->epoch_start; | ||
229 | 212 | ||
230 | rtc_time_to_tm(seconds, &alrm->time); | 213 | rtc_time64_to_tm(seconds, &alrm->time); |
231 | return 0; | 214 | return 0; |
232 | } | 215 | } |
233 | 216 | ||
@@ -260,9 +243,6 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) | |||
260 | rtc->dev = &pdev->dev; | 243 | rtc->dev = &pdev->dev; |
261 | rtc->irq = platform_get_irq(pdev, 0); | 244 | rtc->irq = platform_get_irq(pdev, 0); |
262 | 245 | ||
263 | /* Set epoch start as 00:00:00:01:01:2009 */ | ||
264 | rtc->epoch_start = mktime(2009, 1, 1, 0, 0, 0); | ||
265 | |||
266 | /* 1 kHz tick mode, enable tick counting */ | 246 | /* 1 kHz tick mode, enable tick counting */ |
267 | ret = tps6586x_update(tps_dev, RTC_CTRL, | 247 | ret = tps6586x_update(tps_dev, RTC_CTRL, |
268 | RTC_ENABLE | OSC_SRC_SEL | | 248 | RTC_ENABLE | OSC_SRC_SEL | |
@@ -276,14 +256,18 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) | |||
276 | device_init_wakeup(&pdev->dev, 1); | 256 | device_init_wakeup(&pdev->dev, 1); |
277 | 257 | ||
278 | platform_set_drvdata(pdev, rtc); | 258 | platform_set_drvdata(pdev, rtc); |
279 | rtc->rtc = devm_rtc_device_register(&pdev->dev, dev_name(&pdev->dev), | 259 | rtc->rtc = devm_rtc_allocate_device(&pdev->dev); |
280 | &tps6586x_rtc_ops, THIS_MODULE); | ||
281 | if (IS_ERR(rtc->rtc)) { | 260 | if (IS_ERR(rtc->rtc)) { |
282 | ret = PTR_ERR(rtc->rtc); | 261 | ret = PTR_ERR(rtc->rtc); |
283 | dev_err(&pdev->dev, "RTC device register: ret %d\n", ret); | 262 | dev_err(&pdev->dev, "RTC allocate device: ret %d\n", ret); |
284 | goto fail_rtc_register; | 263 | goto fail_rtc_register; |
285 | } | 264 | } |
286 | 265 | ||
266 | rtc->rtc->ops = &tps6586x_rtc_ops; | ||
267 | rtc->rtc->range_max = (1ULL << 30) - 1; /* 30-bit seconds */ | ||
268 | rtc->rtc->start_secs = mktime64(2009, 1, 1, 0, 0, 0); | ||
269 | rtc->rtc->set_start_time = true; | ||
270 | |||
287 | ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, | 271 | ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, |
288 | tps6586x_rtc_irq, | 272 | tps6586x_rtc_irq, |
289 | IRQF_ONESHOT, | 273 | IRQF_ONESHOT, |
@@ -294,6 +278,13 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) | |||
294 | goto fail_rtc_register; | 278 | goto fail_rtc_register; |
295 | } | 279 | } |
296 | disable_irq(rtc->irq); | 280 | disable_irq(rtc->irq); |
281 | |||
282 | ret = rtc_register_device(rtc->rtc); | ||
283 | if (ret) { | ||
284 | dev_err(&pdev->dev, "RTC device register: ret %d\n", ret); | ||
285 | goto fail_rtc_register; | ||
286 | } | ||
287 | |||
297 | return 0; | 288 | return 0; |
298 | 289 | ||
299 | fail_rtc_register: | 290 | fail_rtc_register: |
diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c index d0244d7979fc..a9bbd022aeef 100644 --- a/drivers/rtc/rtc-tps65910.c +++ b/drivers/rtc/rtc-tps65910.c | |||
@@ -380,6 +380,10 @@ static int tps65910_rtc_probe(struct platform_device *pdev) | |||
380 | if (!tps_rtc) | 380 | if (!tps_rtc) |
381 | return -ENOMEM; | 381 | return -ENOMEM; |
382 | 382 | ||
383 | tps_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); | ||
384 | if (IS_ERR(tps_rtc->rtc)) | ||
385 | return PTR_ERR(tps_rtc->rtc); | ||
386 | |||
383 | /* Clear pending interrupts */ | 387 | /* Clear pending interrupts */ |
384 | ret = regmap_read(tps65910->regmap, TPS65910_RTC_STATUS, &rtc_reg); | 388 | ret = regmap_read(tps65910->regmap, TPS65910_RTC_STATUS, &rtc_reg); |
385 | if (ret < 0) | 389 | if (ret < 0) |
@@ -421,10 +425,12 @@ static int tps65910_rtc_probe(struct platform_device *pdev) | |||
421 | tps_rtc->irq = irq; | 425 | tps_rtc->irq = irq; |
422 | device_set_wakeup_capable(&pdev->dev, 1); | 426 | device_set_wakeup_capable(&pdev->dev, 1); |
423 | 427 | ||
424 | tps_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, | 428 | tps_rtc->rtc->ops = &tps65910_rtc_ops; |
425 | &tps65910_rtc_ops, THIS_MODULE); | 429 | tps_rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; |
426 | if (IS_ERR(tps_rtc->rtc)) { | 430 | tps_rtc->rtc->range_max = RTC_TIMESTAMP_END_2099; |
427 | ret = PTR_ERR(tps_rtc->rtc); | 431 | |
432 | ret = rtc_register_device(tps_rtc->rtc); | ||
433 | if (ret) { | ||
428 | dev_err(&pdev->dev, "RTC device register: err %d\n", ret); | 434 | dev_err(&pdev->dev, "RTC device register: err %d\n", ret); |
429 | return ret; | 435 | return ret; |
430 | } | 436 | } |
@@ -432,17 +438,6 @@ static int tps65910_rtc_probe(struct platform_device *pdev) | |||
432 | return 0; | 438 | return 0; |
433 | } | 439 | } |
434 | 440 | ||
435 | /* | ||
436 | * Disable tps65910 RTC interrupts. | ||
437 | * Sets status flag to free. | ||
438 | */ | ||
439 | static int tps65910_rtc_remove(struct platform_device *pdev) | ||
440 | { | ||
441 | tps65910_rtc_alarm_irq_enable(&pdev->dev, 0); | ||
442 | |||
443 | return 0; | ||
444 | } | ||
445 | |||
446 | #ifdef CONFIG_PM_SLEEP | 441 | #ifdef CONFIG_PM_SLEEP |
447 | static int tps65910_rtc_suspend(struct device *dev) | 442 | static int tps65910_rtc_suspend(struct device *dev) |
448 | { | 443 | { |
@@ -468,7 +463,6 @@ static SIMPLE_DEV_PM_OPS(tps65910_rtc_pm_ops, tps65910_rtc_suspend, | |||
468 | 463 | ||
469 | static struct platform_driver tps65910_rtc_driver = { | 464 | static struct platform_driver tps65910_rtc_driver = { |
470 | .probe = tps65910_rtc_probe, | 465 | .probe = tps65910_rtc_probe, |
471 | .remove = tps65910_rtc_remove, | ||
472 | .driver = { | 466 | .driver = { |
473 | .name = "tps65910-rtc", | 467 | .name = "tps65910-rtc", |
474 | .pm = &tps65910_rtc_pm_ops, | 468 | .pm = &tps65910_rtc_pm_ops, |
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c index 7ce22967fd16..70f013e692b0 100644 --- a/drivers/rtc/rtc-vr41xx.c +++ b/drivers/rtc/rtc-vr41xx.c | |||
@@ -88,7 +88,7 @@ static unsigned int alarm_enabled; | |||
88 | static int aie_irq; | 88 | static int aie_irq; |
89 | static int pie_irq; | 89 | static int pie_irq; |
90 | 90 | ||
91 | static inline unsigned long read_elapsed_second(void) | 91 | static inline time64_t read_elapsed_second(void) |
92 | { | 92 | { |
93 | 93 | ||
94 | unsigned long first_low, first_mid, first_high; | 94 | unsigned long first_low, first_mid, first_high; |
@@ -105,10 +105,10 @@ static inline unsigned long read_elapsed_second(void) | |||
105 | } while (first_low != second_low || first_mid != second_mid || | 105 | } while (first_low != second_low || first_mid != second_mid || |
106 | first_high != second_high); | 106 | first_high != second_high); |
107 | 107 | ||
108 | return (first_high << 17) | (first_mid << 1) | (first_low >> 15); | 108 | return ((u64)first_high << 17) | (first_mid << 1) | (first_low >> 15); |
109 | } | 109 | } |
110 | 110 | ||
111 | static inline void write_elapsed_second(unsigned long sec) | 111 | static inline void write_elapsed_second(time64_t sec) |
112 | { | 112 | { |
113 | spin_lock_irq(&rtc_lock); | 113 | spin_lock_irq(&rtc_lock); |
114 | 114 | ||
@@ -121,22 +121,22 @@ static inline void write_elapsed_second(unsigned long sec) | |||
121 | 121 | ||
122 | static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time) | 122 | static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time) |
123 | { | 123 | { |
124 | unsigned long epoch_sec, elapsed_sec; | 124 | time64_t epoch_sec, elapsed_sec; |
125 | 125 | ||
126 | epoch_sec = mktime(epoch, 1, 1, 0, 0, 0); | 126 | epoch_sec = mktime64(epoch, 1, 1, 0, 0, 0); |
127 | elapsed_sec = read_elapsed_second(); | 127 | elapsed_sec = read_elapsed_second(); |
128 | 128 | ||
129 | rtc_time_to_tm(epoch_sec + elapsed_sec, time); | 129 | rtc_time64_to_tm(epoch_sec + elapsed_sec, time); |
130 | 130 | ||
131 | return 0; | 131 | return 0; |
132 | } | 132 | } |
133 | 133 | ||
134 | static int vr41xx_rtc_set_time(struct device *dev, struct rtc_time *time) | 134 | static int vr41xx_rtc_set_time(struct device *dev, struct rtc_time *time) |
135 | { | 135 | { |
136 | unsigned long epoch_sec, current_sec; | 136 | time64_t epoch_sec, current_sec; |
137 | 137 | ||
138 | epoch_sec = mktime(epoch, 1, 1, 0, 0, 0); | 138 | epoch_sec = mktime64(epoch, 1, 1, 0, 0, 0); |
139 | current_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, | 139 | current_sec = mktime64(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, |
140 | time->tm_hour, time->tm_min, time->tm_sec); | 140 | time->tm_hour, time->tm_min, time->tm_sec); |
141 | 141 | ||
142 | write_elapsed_second(current_sec - epoch_sec); | 142 | write_elapsed_second(current_sec - epoch_sec); |
@@ -165,11 +165,11 @@ static int vr41xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | |||
165 | 165 | ||
166 | static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | 166 | static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) |
167 | { | 167 | { |
168 | unsigned long alarm_sec; | 168 | time64_t alarm_sec; |
169 | struct rtc_time *time = &wkalrm->time; | 169 | struct rtc_time *time = &wkalrm->time; |
170 | 170 | ||
171 | alarm_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, | 171 | alarm_sec = mktime64(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, |
172 | time->tm_hour, time->tm_min, time->tm_sec); | 172 | time->tm_hour, time->tm_min, time->tm_sec); |
173 | 173 | ||
174 | spin_lock_irq(&rtc_lock); | 174 | spin_lock_irq(&rtc_lock); |
175 | 175 | ||
@@ -292,13 +292,16 @@ static int rtc_probe(struct platform_device *pdev) | |||
292 | goto err_rtc1_iounmap; | 292 | goto err_rtc1_iounmap; |
293 | } | 293 | } |
294 | 294 | ||
295 | rtc = devm_rtc_device_register(&pdev->dev, rtc_name, &vr41xx_rtc_ops, | 295 | rtc = devm_rtc_allocate_device(&pdev->dev); |
296 | THIS_MODULE); | ||
297 | if (IS_ERR(rtc)) { | 296 | if (IS_ERR(rtc)) { |
298 | retval = PTR_ERR(rtc); | 297 | retval = PTR_ERR(rtc); |
299 | goto err_iounmap_all; | 298 | goto err_iounmap_all; |
300 | } | 299 | } |
301 | 300 | ||
301 | rtc->ops = &vr41xx_rtc_ops; | ||
302 | |||
303 | /* 48-bit counter at 32.768 kHz */ | ||
304 | rtc->range_max = (1ULL << 33) - 1; | ||
302 | rtc->max_user_freq = MAX_PERIODIC_RATE; | 305 | rtc->max_user_freq = MAX_PERIODIC_RATE; |
303 | 306 | ||
304 | spin_lock_irq(&rtc_lock); | 307 | spin_lock_irq(&rtc_lock); |
@@ -340,6 +343,10 @@ static int rtc_probe(struct platform_device *pdev) | |||
340 | 343 | ||
341 | dev_info(&pdev->dev, "Real Time Clock of NEC VR4100 series\n"); | 344 | dev_info(&pdev->dev, "Real Time Clock of NEC VR4100 series\n"); |
342 | 345 | ||
346 | retval = rtc_register_device(rtc); | ||
347 | if (retval) | ||
348 | goto err_iounmap_all; | ||
349 | |||
343 | return 0; | 350 | return 0; |
344 | 351 | ||
345 | err_iounmap_all: | 352 | err_iounmap_all: |
diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c index fba994dc31eb..c532bd13fbe5 100644 --- a/drivers/rtc/rtc-zynqmp.c +++ b/drivers/rtc/rtc-zynqmp.c | |||
@@ -278,10 +278,9 @@ static int xlnx_rtc_remove(struct platform_device *pdev) | |||
278 | 278 | ||
279 | static int __maybe_unused xlnx_rtc_suspend(struct device *dev) | 279 | static int __maybe_unused xlnx_rtc_suspend(struct device *dev) |
280 | { | 280 | { |
281 | struct platform_device *pdev = to_platform_device(dev); | 281 | struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); |
282 | struct xlnx_rtc_dev *xrtcdev = platform_get_drvdata(pdev); | ||
283 | 282 | ||
284 | if (device_may_wakeup(&pdev->dev)) | 283 | if (device_may_wakeup(dev)) |
285 | enable_irq_wake(xrtcdev->alarm_irq); | 284 | enable_irq_wake(xrtcdev->alarm_irq); |
286 | else | 285 | else |
287 | xlnx_rtc_alarm_irq_enable(dev, 0); | 286 | xlnx_rtc_alarm_irq_enable(dev, 0); |
@@ -291,10 +290,9 @@ static int __maybe_unused xlnx_rtc_suspend(struct device *dev) | |||
291 | 290 | ||
292 | static int __maybe_unused xlnx_rtc_resume(struct device *dev) | 291 | static int __maybe_unused xlnx_rtc_resume(struct device *dev) |
293 | { | 292 | { |
294 | struct platform_device *pdev = to_platform_device(dev); | 293 | struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); |
295 | struct xlnx_rtc_dev *xrtcdev = platform_get_drvdata(pdev); | ||
296 | 294 | ||
297 | if (device_may_wakeup(&pdev->dev)) | 295 | if (device_may_wakeup(dev)) |
298 | disable_irq_wake(xrtcdev->alarm_irq); | 296 | disable_irq_wake(xrtcdev->alarm_irq); |
299 | else | 297 | else |
300 | xlnx_rtc_alarm_irq_enable(dev, 1); | 298 | xlnx_rtc_alarm_irq_enable(dev, 1); |
diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 4c007f69082f..6268208760e9 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h | |||
@@ -285,7 +285,7 @@ void rtc_nvmem_unregister(struct rtc_device *rtc); | |||
285 | static inline int rtc_nvmem_register(struct rtc_device *rtc, | 285 | static inline int rtc_nvmem_register(struct rtc_device *rtc, |
286 | struct nvmem_config *nvmem_config) | 286 | struct nvmem_config *nvmem_config) |
287 | { | 287 | { |
288 | return -ENODEV; | 288 | return 0; |
289 | } | 289 | } |
290 | static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {} | 290 | static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {} |
291 | #endif | 291 | #endif |