rtc: pcf8523: add suspend handlers for alarm IRQ
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Tue, 27 Feb 2024 21:18:32 +0000 (22:18 +0100)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Thu, 29 Feb 2024 21:17:23 +0000 (22:17 +0100)
Ensure the RTC is able to wake up the system from suspend.

Link: https://lore.kernel.org/r/20240227211833.1820800-1-alexandre.belloni@bootlin.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-pcf8523.c

index d1efde3e7a8094e01b4f34b66f2f5990258ca3cb..98b77f790b0c5a63595caacd6a17ba6ba4e3b222 100644 (file)
@@ -370,6 +370,30 @@ static int pcf8523_rtc_set_offset(struct device *dev, long offset)
        return regmap_write(pcf8523->regmap, PCF8523_REG_OFFSET, value);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int pcf8523_suspend(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+
+       if (client->irq > 0 && device_may_wakeup(dev))
+               enable_irq_wake(client->irq);
+
+       return 0;
+}
+
+static int pcf8523_resume(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+
+       if (client->irq > 0 && device_may_wakeup(dev))
+               disable_irq_wake(client->irq);
+
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(pcf8523_pm, pcf8523_suspend, pcf8523_resume);
+
 static const struct rtc_class_ops pcf8523_rtc_ops = {
        .read_time = pcf8523_rtc_read_time,
        .set_time = pcf8523_rtc_set_time,
@@ -487,6 +511,7 @@ static struct i2c_driver pcf8523_driver = {
        .driver = {
                .name = "rtc-pcf8523",
                .of_match_table = pcf8523_of_match,
+               .pm = &pcf8523_pm,
        },
        .probe = pcf8523_probe,
        .id_table = pcf8523_id,