linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: rv8803: Add power management support
@ 2023-11-22 18:16 Stefan Eichenberger
  2024-01-08  0:31 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Eichenberger @ 2023-11-22 18:16 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni; +Cc: linux-rtc, linux-kernel

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>
---
 drivers/rtc/rtc-rv8803.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
index 1a3ec1bb5b814..11e6b0d31f5d7 100644
--- a/drivers/rtc/rtc-rv8803.c
+++ b/drivers/rtc/rtc-rv8803.c
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/rtc.h>
+#include <linux/pm_wakeirq.h>
 
 #define RV8803_I2C_TRY_COUNT		4
 
@@ -607,6 +608,28 @@ static int rv8803_regs_configure(struct rv8803_data *rv8803)
 	return 0;
 }
 
+static int rv8803_resume(struct device *dev)
+{
+	struct rv8803_data *rv8803 = dev_get_drvdata(dev);
+
+	if (rv8803->client->irq > 0 && device_may_wakeup(dev))
+		disable_irq_wake(rv8803->client->irq);
+
+	return 0;
+}
+
+static int rv8803_suspend(struct device *dev)
+{
+	struct rv8803_data *rv8803 = dev_get_drvdata(dev);
+
+	if (rv8803->client->irq > 0 && device_may_wakeup(dev))
+		enable_irq_wake(rv8803->client->irq);
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(rv8803_pm_ops, rv8803_suspend, rv8803_resume);
+
 static const struct i2c_device_id rv8803_id[] = {
 	{ "rv8803", rv_8803 },
 	{ "rv8804", rx_8804 },
@@ -683,6 +706,11 @@ static int rv8803_probe(struct i2c_client *client)
 		if (err) {
 			dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
 			client->irq = 0;
+		} else {
+			device_init_wakeup(&client->dev, true);
+			err = dev_pm_set_wake_irq(&client->dev, client->irq);
+			if (err)
+				dev_err(&client->dev, "failed to set wake IRQ\n");
 		}
 	}
 	if (!client->irq)
@@ -737,6 +765,7 @@ static struct i2c_driver rv8803_driver = {
 	.driver = {
 		.name = "rtc-rv8803",
 		.of_match_table = of_match_ptr(rv8803_of_match),
+		.pm = &rv8803_pm_ops,
 	},
 	.probe		= rv8803_probe,
 	.id_table	= rv8803_id,
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtc: rv8803: Add power management support
  2023-11-22 18:16 [PATCH] rtc: rv8803: Add power management support Stefan Eichenberger
@ 2024-01-08  0:31 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2024-01-08  0:31 UTC (permalink / raw)
  To: a.zummo, Stefan Eichenberger; +Cc: linux-rtc, linux-kernel


On Wed, 22 Nov 2023 19:16:11 +0100, Stefan Eichenberger wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] rtc: rv8803: Add power management support
      commit: 2f80de657f83a1f6495e557096847f4626d57164

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-08  0:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22 18:16 [PATCH] rtc: rv8803: Add power management support Stefan Eichenberger
2024-01-08  0:31 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).