Skip to content

Commit 2f80de6

Browse files
eichenbergeralexandrebelloni
authored andcommitted
rtc: rv8803: Add power management support
Add power management support to the driver. This allows a SoC to wake from suspend using the nINT provided by the RTC. Only register it as a wakeup device if the interrupt is provided and handled. Signed-off-by: Stefan Eichenberger <eichest@gmail.com> Link: https://lore.kernel.org/r/20231122181611.164792-1-eichest@gmail.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 3628d99 commit 2f80de6

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

drivers/rtc/rtc-rv8803.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/module.h>
1818
#include <linux/of.h>
1919
#include <linux/rtc.h>
20+
#include <linux/pm_wakeirq.h>
2021

2122
#define RV8803_I2C_TRY_COUNT 4
2223

@@ -607,6 +608,28 @@ static int rv8803_regs_configure(struct rv8803_data *rv8803)
607608
return 0;
608609
}
609610

611+
static int rv8803_resume(struct device *dev)
612+
{
613+
struct rv8803_data *rv8803 = dev_get_drvdata(dev);
614+
615+
if (rv8803->client->irq > 0 && device_may_wakeup(dev))
616+
disable_irq_wake(rv8803->client->irq);
617+
618+
return 0;
619+
}
620+
621+
static int rv8803_suspend(struct device *dev)
622+
{
623+
struct rv8803_data *rv8803 = dev_get_drvdata(dev);
624+
625+
if (rv8803->client->irq > 0 && device_may_wakeup(dev))
626+
enable_irq_wake(rv8803->client->irq);
627+
628+
return 0;
629+
}
630+
631+
static DEFINE_SIMPLE_DEV_PM_OPS(rv8803_pm_ops, rv8803_suspend, rv8803_resume);
632+
610633
static const struct i2c_device_id rv8803_id[] = {
611634
{ "rv8803", rv_8803 },
612635
{ "rv8804", rx_8804 },
@@ -683,6 +706,11 @@ static int rv8803_probe(struct i2c_client *client)
683706
if (err) {
684707
dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
685708
client->irq = 0;
709+
} else {
710+
device_init_wakeup(&client->dev, true);
711+
err = dev_pm_set_wake_irq(&client->dev, client->irq);
712+
if (err)
713+
dev_err(&client->dev, "failed to set wake IRQ\n");
686714
}
687715
}
688716
if (!client->irq)
@@ -737,6 +765,7 @@ static struct i2c_driver rv8803_driver = {
737765
.driver = {
738766
.name = "rtc-rv8803",
739767
.of_match_table = of_match_ptr(rv8803_of_match),
768+
.pm = &rv8803_pm_ops,
740769
},
741770
.probe = rv8803_probe,
742771
.id_table = rv8803_id,

0 commit comments

Comments
 (0)