diff mbox series

[RFC] rtc: class: register for late suspend / early resume

Message ID 20200610132403.2539519-1-martin@geanix.com
State New
Headers show
Series [RFC] rtc: class: register for late suspend / early resume | expand

Commit Message

Martin Hundebøll June 10, 2020, 1:24 p.m. UTC
When running on hardware with no persistent clock, and no non-stop
clocksource, the timekeeping resume code relies on the rtc class to
inject the suspend time.

Other drivers might call into the timekeeping code to sync time in their
devices. If such devices are resumed before the rtc class (and rtc is
the only time source running in suspend) they currently get the
pre-suspend time.

Move the rtc class suspend/resume functions to be called late/early in
the cycle to make sure timekeeping is synchronised when other devices
are resumed.

This works in our case on an i.MX6, where the rtc driver only has
_suspend_noirq()/_resume_noirq(). I imagine it fails with drivers that
has regular _suspend()/_resume() functions. Any hints are welcome.

--

 drivers/rtc/class.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Alexandre Belloni June 29, 2020, 9:54 p.m. UTC | #1
Hi,

On 10/06/2020 15:24:03+0200, Martin Hundebøll wrote:
> When running on hardware with no persistent clock, and no non-stop
> clocksource, the timekeeping resume code relies on the rtc class to
> inject the suspend time.
> 
> Other drivers might call into the timekeeping code to sync time in their
> devices. If such devices are resumed before the rtc class (and rtc is
> the only time source running in suspend) they currently get the
> pre-suspend time.
> 
> Move the rtc class suspend/resume functions to be called late/early in
> the cycle to make sure timekeeping is synchronised when other devices
> are resumed.
> 
> This works in our case on an i.MX6, where the rtc driver only has
> _suspend_noirq()/_resume_noirq(). I imagine it fails with drivers that
> has regular _suspend()/_resume() functions. Any hints are welcome.
> 

Just to let you know that I've seen the previous thread and also this
patch. I'm not sure about the patch, especially regarding RTCs on an i2c
or SPI bus were wee need the bus to be suspended after the RTC and
resumed before the RTC. The order is properly handled when using
but I need to check whether it is correct when using _late. I remember
having issues with that with regulators.

I must admit my time is a bit scarce right now. Maybe you can get input
from the PM guys?

Regards,
diff mbox series

Patch

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 7c88d190c51fc..737b67a1045ab 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -183,7 +183,9 @@  static int rtc_resume(struct device *dev)
 	return 0;
 }
 
-static SIMPLE_DEV_PM_OPS(rtc_class_dev_pm_ops, rtc_suspend, rtc_resume);
+static const struct dev_pm_ops rtc_class_dev_pm_ops = {
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(rtc_suspend, rtc_resume)
+};
 #define RTC_CLASS_DEV_PM_OPS	(&rtc_class_dev_pm_ops)
 #else
 #define RTC_CLASS_DEV_PM_OPS	NULL