Skip to content

Commit 1aaccb5

Browse files
committed
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 ...
2 parents ab0b2e5 + e4302ae commit 1aaccb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+904
-841
lines changed

Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Optional properties:
99

1010
Example:
1111

12-
rtc: nxp,rtc-pcf2123@3 {
12+
pcf2123: rtc@3 {
1313
compatible = "nxp,rtc-pcf2123"
1414
reg = <3>
1515
spi-cs-high;
Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
STM32 Real Time Clock
22

33
Required properties:
4-
- compatible: can be either "st,stm32-rtc" or "st,stm32h7-rtc", depending on
5-
the device is compatible with stm32(f4/f7) or stm32h7.
4+
- compatible: can be one of the following:
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.
68
- reg: address range of rtc register set.
79
- clocks: can use up to two clocks, depending on part used:
810
- "rtc_ck": RTC clock source.
9-
It is required on stm32(f4/f7) and stm32h7.
1011
- "pclk": RTC APB interface clock.
1112
It is not present on stm32(f4/f7).
12-
It is required on stm32h7.
13+
It is required on stm32(h7/mp1).
1314
- clock-names: must be "rtc_ck" and "pclk".
14-
It is required only on stm32h7.
15+
It is required on stm32(h7/mp1).
1516
- interrupt-parent: phandle for the interrupt controller.
16-
- interrupts: rtc alarm interrupt.
17-
- st,syscfg: phandle for pwrcfg, mandatory to disable/enable backup domain
18-
(RTC registers) write protection.
17+
It is required on stm32(f4/f7/h7).
18+
- interrupts: rtc alarm interrupt. On stm32mp1, a second interrupt is required
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).
1925

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):
2127
- assigned-clocks: reference to the rtc_ck clock entry.
2228
- assigned-clock-parents: phandle of the new parent clock of rtc_ck.
2329

@@ -31,7 +37,7 @@ Example:
3137
assigned-clock-parents = <&rcc 1 CLK_LSE>;
3238
interrupt-parent = <&exti>;
3339
interrupts = <17 1>;
34-
st,syscfg = <&pwrcfg>;
40+
st,syscfg = <&pwrcfg 0x00 0x100>;
3541
};
3642

3743
rtc: rtc@58004000 {
@@ -44,5 +50,14 @@ Example:
4450
interrupt-parent = <&exti>;
4551
interrupts = <17 1>;
4652
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>;
4863
};

drivers/rtc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ config RTC_DRV_JZ4740
16131613
If you say yes here you get support for the Ingenic JZ47xx SoCs RTC
16141614
controllers.
16151615

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
16171617
will be called rtc-jz4740.
16181618

16191619
config RTC_DRV_LPC24XX

drivers/rtc/interface.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,11 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
441441
{
442442
int err;
443443

444+
if (!rtc->ops)
445+
return -ENODEV;
446+
else if (!rtc->ops->set_alarm)
447+
return -EINVAL;
448+
444449
err = rtc_valid_tm(&alarm->time);
445450
if (err != 0)
446451
return err;

drivers/rtc/nvmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int rtc_nvmem_register(struct rtc_device *rtc,
9494
nvmem_config->dev = rtc->dev.parent;
9595
nvmem_config->owner = rtc->owner;
9696
rtc->nvmem = nvmem_register(nvmem_config);
97-
if (IS_ERR_OR_NULL(rtc->nvmem))
97+
if (IS_ERR(rtc->nvmem))
9898
return PTR_ERR(rtc->nvmem);
9999

100100
/* Register the old ABI */

drivers/rtc/rtc-88pm80x.c

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ struct pm80x_rtc_info {
5252
struct regmap *map;
5353
struct rtc_device *rtc_dev;
5454
struct device *dev;
55-
struct delayed_work calib_work;
5655

5756
int irq;
58-
int vrtc;
5957
};
6058

6159
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,
10098
next->tm_min = alrm->tm_min;
10199
next->tm_sec = alrm->tm_sec;
102100

103-
rtc_tm_to_time(now, &now_time);
104-
rtc_tm_to_time(next, &next_time);
101+
now_time = rtc_tm_to_time64(now);
102+
next_time = rtc_tm_to_time64(next);
105103

106104
if (next_time < now_time) {
107105
/* Advance one day */
108106
next_time += 60 * 60 * 24;
109-
rtc_time_to_tm(next_time, next);
107+
rtc_time64_to_tm(next_time, next);
110108
}
111109
}
112110

@@ -125,7 +123,7 @@ static int pm80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
125123
ticks = base + data;
126124
dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
127125
base, data, ticks);
128-
rtc_time_to_tm(ticks, tm);
126+
rtc_time64_to_tm(ticks, tm);
129127
return 0;
130128
}
131129

@@ -134,13 +132,8 @@ static int pm80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
134132
struct pm80x_rtc_info *info = dev_get_drvdata(dev);
135133
unsigned char buf[4];
136134
unsigned long ticks, base, data;
137-
if (tm->tm_year > 206) {
138-
dev_dbg(info->dev,
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);
135+
136+
ticks = rtc_tm_to_time64(tm);
144137

145138
/* load 32-bit read-only counter */
146139
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)
174167
dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
175168
base, data, ticks);
176169

177-
rtc_time_to_tm(ticks, &alrm->time);
170+
rtc_time64_to_tm(ticks, &alrm->time);
178171
regmap_read(info->map, PM800_RTC_CONTROL, &ret);
179172
alrm->enabled = (ret & PM800_ALARM1_EN) ? 1 : 0;
180173
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)
202195
dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
203196
base, data, ticks);
204197

205-
rtc_time_to_tm(ticks, &now_tm);
198+
rtc_time64_to_tm(ticks, &now_tm);
206199
dev_dbg(info->dev, "%s, now time : %lu\n", __func__, ticks);
207200
rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time);
208201
/* get new ticks for alarm in 24 hours */
209-
rtc_tm_to_time(&alarm_tm, &ticks);
202+
ticks = rtc_tm_to_time64(&alarm_tm);
210203
dev_dbg(info->dev, "%s, alarm time: %lu\n", __func__, ticks);
211204
data = ticks - base;
212205

@@ -254,8 +247,6 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
254247
struct pm80x_rtc_pdata *pdata = dev_get_platdata(&pdev->dev);
255248
struct pm80x_rtc_info *info;
256249
struct device_node *node = pdev->dev.of_node;
257-
struct rtc_time tm;
258-
unsigned long ticks = 0;
259250
int ret;
260251

261252
if (!pdata && !node) {
@@ -294,6 +285,10 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
294285
info->dev = &pdev->dev;
295286
dev_set_drvdata(&pdev->dev, info);
296287

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+
297292
ret = pm80x_request_irq(chip, info->irq, rtc_update_handler,
298293
IRQF_ONESHOT, "rtc", info);
299294
if (ret < 0) {
@@ -302,30 +297,11 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
302297
goto out;
303298
}
304299

305-
ret = pm80x_rtc_read_time(&pdev->dev, &tm);
306-
if (ret < 0) {
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);
300+
info->rtc_dev->ops = &pm80x_rtc_ops;
301+
info->rtc_dev->range_max = U32_MAX;
324302

325-
info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm80x-rtc",
326-
&pm80x_rtc_ops, THIS_MODULE);
327-
if (IS_ERR(info->rtc_dev)) {
328-
ret = PTR_ERR(info->rtc_dev);
303+
ret = rtc_register_device(info->rtc_dev);
304+
if (ret) {
329305
dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
330306
goto out_rtc;
331307
}

drivers/rtc/rtc-ab-b5ze-s3.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,6 @@ static int abb5zes3_rtc_set_time(struct device *dev, struct rtc_time *tm)
265265
u8 regs[ABB5ZES3_REG_RTC_SC + ABB5ZES3_RTC_SEC_LEN];
266266
int ret;
267267

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-
277268
regs[ABB5ZES3_REG_RTC_SC] = bin2bcd(tm->tm_sec); /* MSB=0 clears OSC */
278269
regs[ABB5ZES3_REG_RTC_MN] = bin2bcd(tm->tm_min);
279270
regs[ABB5ZES3_REG_RTC_HR] = bin2bcd(tm->tm_hour); /* 24-hour format */
@@ -925,6 +916,14 @@ static int abb5zes3_probe(struct i2c_client *client,
925916
if (ret)
926917
goto err;
927918

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+
928927
if (client->irq > 0) {
929928
ret = devm_request_threaded_irq(dev, client->irq, NULL,
930929
_abb5zes3_rtc_interrupt,
@@ -942,14 +941,9 @@ static int abb5zes3_probe(struct i2c_client *client,
942941
}
943942
}
944943

945-
data->rtc = devm_rtc_device_register(dev, DRV_NAME, &rtc_ops,
946-
THIS_MODULE);
947-
ret = PTR_ERR_OR_ZERO(data->rtc);
948-
if (ret) {
949-
dev_err(dev, "%s: unable to register RTC device (%d)\n",
950-
__func__, ret);
951-
goto err;
952-
}
944+
data->rtc->ops = &rtc_ops;
945+
data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
946+
data->rtc->range_max = RTC_TIMESTAMP_END_2099;
953947

954948
/* Enable battery low detection interrupt if battery not already low */
955949
if (!data->battery_low && data->irq) {
@@ -961,6 +955,8 @@ static int abb5zes3_probe(struct i2c_client *client,
961955
}
962956
}
963957

958+
ret = rtc_register_device(data->rtc);
959+
964960
err:
965961
if (ret && data && data->irq)
966962
device_init_wakeup(dev, false);

drivers/rtc/rtc-at91rm9200.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
440440
device_init_wakeup(&pdev->dev, 1);
441441

442442
rtc->ops = &at91_rtc_ops;
443+
rtc->range_min = RTC_TIMESTAMP_BEGIN_1900;
444+
rtc->range_max = RTC_TIMESTAMP_END_2099;
443445
ret = rtc_register_device(rtc);
444446
if (ret)
445447
goto err_clk;

drivers/rtc/rtc-bq4802.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ static void bq4802_write_mem(struct bq4802 *p, int off, u8 val)
4848

4949
static int bq4802_read_time(struct device *dev, struct rtc_time *tm)
5050
{
51-
struct platform_device *pdev = to_platform_device(dev);
52-
struct bq4802 *p = platform_get_drvdata(pdev);
51+
struct bq4802 *p = dev_get_drvdata(dev);
5352
unsigned long flags;
5453
unsigned int century;
5554
u8 val;
@@ -91,8 +90,7 @@ static int bq4802_read_time(struct device *dev, struct rtc_time *tm)
9190

9291
static int bq4802_set_time(struct device *dev, struct rtc_time *tm)
9392
{
94-
struct platform_device *pdev = to_platform_device(dev);
95-
struct bq4802 *p = platform_get_drvdata(pdev);
93+
struct bq4802 *p = dev_get_drvdata(dev);
9694
u8 sec, min, hrs, day, mon, yrs, century, val;
9795
unsigned long flags;
9896
unsigned int year;

drivers/rtc/rtc-brcmstb-waketimer.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ static int brcmstb_waketmr_settime(struct device *dev,
145145

146146
sec = rtc_tm_to_time64(tm);
147147

148-
if (sec > U32_MAX || sec < 0)
149-
return -EINVAL;
150-
151148
writel_relaxed(sec, timer->base + BRCMSTB_WKTMR_COUNTER);
152149

153150
return 0;
@@ -184,9 +181,6 @@ static int brcmstb_waketmr_setalarm(struct device *dev,
184181
else
185182
sec = 0;
186183

187-
if (sec > U32_MAX || sec < 0)
188-
return -EINVAL;
189-
190184
brcmstb_waketmr_set_alarm(timer, sec);
191185

192186
return 0;
@@ -229,6 +223,10 @@ static int brcmstb_waketmr_probe(struct platform_device *pdev)
229223
if (IS_ERR(timer->base))
230224
return PTR_ERR(timer->base);
231225

226+
timer->rtc = devm_rtc_allocate_device(dev);
227+
if (IS_ERR(timer->rtc))
228+
return PTR_ERR(timer->rtc);
229+
232230
/*
233231
* Set wakeup capability before requesting wakeup interrupt, so we can
234232
* process boot-time "wakeups" (e.g., from S5 soft-off)
@@ -261,11 +259,12 @@ static int brcmstb_waketmr_probe(struct platform_device *pdev)
261259
timer->reboot_notifier.notifier_call = brcmstb_waketmr_reboot;
262260
register_reboot_notifier(&timer->reboot_notifier);
263261

264-
timer->rtc = rtc_device_register("brcmstb-waketmr", dev,
265-
&brcmstb_waketmr_ops, THIS_MODULE);
266-
if (IS_ERR(timer->rtc)) {
262+
timer->rtc->ops = &brcmstb_waketmr_ops;
263+
timer->rtc->range_max = U32_MAX;
264+
265+
ret = rtc_register_device(timer->rtc);
266+
if (ret) {
267267
dev_err(dev, "unable to register device\n");
268-
ret = PTR_ERR(timer->rtc);
269268
goto err_notifier;
270269
}
271270

@@ -288,7 +287,6 @@ static int brcmstb_waketmr_remove(struct platform_device *pdev)
288287
struct brcmstb_waketmr *timer = dev_get_drvdata(&pdev->dev);
289288

290289
unregister_reboot_notifier(&timer->reboot_notifier);
291-
rtc_device_unregister(timer->rtc);
292290

293291
return 0;
294292
}

0 commit comments

Comments
 (0)