Skip to content

Commit 3abb1ad

Browse files
simonguinotalexandrebelloni
authored andcommitted
rtc: ds1307: fix alarm reading at probe time
With the actual code, read_alarm() always returns -EINVAL when called during the RTC device registration. This prevents from retrieving an already configured alarm in hardware. This patch fixes the issue by moving the HAS_ALARM bit configuration (if supported by the hardware) above the rtc_device_register() call. Signed-off-by: Simon Guinot <simon.guinot@sequanux.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
1 parent 51c4cfe commit 3abb1ad

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/rtc/rtc-ds1307.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,10 @@ static int ds1307_probe(struct i2c_client *client,
11341134
bin2bcd(tmp));
11351135
}
11361136

1137-
device_set_wakeup_capable(&client->dev, want_irq);
1137+
if (want_irq) {
1138+
device_set_wakeup_capable(&client->dev, true);
1139+
set_bit(HAS_ALARM, &ds1307->flags);
1140+
}
11381141
ds1307->rtc = devm_rtc_device_register(&client->dev, client->name,
11391142
rtc_ops, THIS_MODULE);
11401143
if (IS_ERR(ds1307->rtc)) {
@@ -1148,12 +1151,11 @@ static int ds1307_probe(struct i2c_client *client,
11481151
ds1307->rtc->name, client);
11491152
if (err) {
11501153
client->irq = 0;
1154+
device_set_wakeup_capable(&client->dev, false);
1155+
clear_bit(HAS_ALARM, &ds1307->flags);
11511156
dev_err(&client->dev, "unable to request IRQ!\n");
1152-
} else {
1153-
1154-
set_bit(HAS_ALARM, &ds1307->flags);
1157+
} else
11551158
dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
1156-
}
11571159
}
11581160

11591161
if (chip->nvram_size) {

0 commit comments

Comments
 (0)