diff mbox series

[2/2] watchdog: imx2_wdg: notify wdog subsystem about wdog suspend/resume

Message ID 20210615123904.2568052-3-grzegorz.jaszczyk@linaro.org
State New
Headers show
Series introduce watchdog_dev_suspend/resume | expand

Commit Message

Grzegorz Jaszczyk June 15, 2021, 12:39 p.m. UTC
Suspend routine disables wdog clk. Nevertheless, the watchdog subsystem
is not aware of that and can still try to ping wdog through
watchdog_ping_work. In order to prevent such condition and therefore
prevent from system hang (caused by the wdog register access issued
while the wdog clock is disabled) take advantage of
watchdog_dev_suspend/resume routines which will take care of watchdog
ping worker cancel and restore.

Additionally remove hw ping from suspend/resume since it will be
issued by watchdog_dev_suspend/resume routines.

Signed-off-by: Michal Koziel <michal.koziel@emlogic.no>

Signed-off-by: Grzegorz Jaszczyk <grzegorz.jaszczyk@linaro.org>

---
 drivers/watchdog/imx2_wdt.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

-- 
2.29.0
diff mbox series

Patch

diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index b84f80f7d342..24e3a4d2b529 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -348,6 +348,17 @@  static int __maybe_unused imx2_wdt_suspend(struct device *dev)
 {
 	struct watchdog_device *wdog = dev_get_drvdata(dev);
 	struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
+	int ret;
+
+	/*
+	 * Before disabling clk we need to notify wdog subsystem that HW wdog
+	 * is being suspended. This e.g. prevents watchdog_ping_work to fire
+	 * when the clk is disabled, which would result with system hang caused
+	 * by wdog register access while wdog clock is disabled.
+	 */
+	ret = watchdog_dev_suspend(wdog);
+	if (ret)
+		return ret;
 
 	/* The watchdog IP block is running */
 	if (imx2_wdt_is_running(wdev)) {
@@ -356,7 +367,6 @@  static int __maybe_unused imx2_wdt_suspend(struct device *dev)
 		 * during resume.
 		 */
 		__imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
-		imx2_wdt_ping(wdog);
 	}
 
 	clk_disable_unprepare(wdev->clk);
@@ -383,12 +393,12 @@  static int __maybe_unused imx2_wdt_resume(struct device *dev)
 		 */
 		imx2_wdt_setup(wdog);
 	}
-	if (imx2_wdt_is_running(wdev)) {
+	if (imx2_wdt_is_running(wdev))
 		imx2_wdt_set_timeout(wdog, wdog->timeout);
-		imx2_wdt_ping(wdog);
-	}
 
-	return 0;
+	ret = watchdog_dev_resume(wdog);
+
+	return ret;
 }
 
 static SIMPLE_DEV_PM_OPS(imx2_wdt_pm_ops, imx2_wdt_suspend,