Skip to content

Commit 1e786b0

Browse files
MikeLooijmansalexandrebelloni
authored andcommitted
rtc: pcf85363: Allow to wake up system without IRQ
When wakeup-source is set in the devicetree, set up the device for using the output as interrupt instead of clock. This is similar to how other RTC devices handle this. This allows the clock chip to turn on the board when wired to do so in hardware. Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl> Link: https://lore.kernel.org/r/20230821072013.7072-1-mike.looijmans@topic.nl Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 6ec3f5e commit 1e786b0

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

drivers/rtc/rtc-pcf85363.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ static int pcf85363_probe(struct i2c_client *client)
402402
},
403403
};
404404
int ret, i, err;
405+
bool wakeup_source;
405406

406407
if (data)
407408
config = data;
@@ -431,25 +432,36 @@ static int pcf85363_probe(struct i2c_client *client)
431432
pcf85363->rtc->ops = &rtc_ops;
432433
pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
433434
pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
434-
clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
435+
436+
wakeup_source = device_property_read_bool(&client->dev,
437+
"wakeup-source");
438+
if (client->irq > 0 || wakeup_source) {
439+
regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
440+
regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
441+
PIN_IO_INTA_OUT, PIN_IO_INTAPM);
442+
}
435443

436444
if (client->irq > 0) {
437445
unsigned long irqflags = IRQF_TRIGGER_LOW;
438446

439447
if (dev_fwnode(&client->dev))
440448
irqflags = 0;
441-
442-
regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
443-
regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
444-
PIN_IO_INTA_OUT, PIN_IO_INTAPM);
445449
ret = devm_request_threaded_irq(&client->dev, client->irq,
446450
NULL, pcf85363_rtc_handle_irq,
447451
irqflags | IRQF_ONESHOT,
448452
"pcf85363", client);
449-
if (ret)
450-
dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
451-
else
452-
set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
453+
if (ret) {
454+
dev_warn(&client->dev,
455+
"unable to request IRQ, alarms disabled\n");
456+
client->irq = 0;
457+
}
458+
}
459+
460+
if (client->irq > 0 || wakeup_source) {
461+
device_init_wakeup(&client->dev, true);
462+
set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
463+
} else {
464+
clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features);
453465
}
454466

455467
ret = devm_rtc_register_device(pcf85363->rtc);

0 commit comments

Comments
 (0)