diff mbox series

[v2] watchdog: renesas_wdt: support handover from bootloader

Message ID 20190819173346.4019-1-wsa@the-dreams.de (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show
Series [v2] watchdog: renesas_wdt: support handover from bootloader | expand

Commit Message

Wolfram Sang Aug. 19, 2019, 5:33 p.m. UTC
From: Wolfram Sang <wsa+renesas@sang-engineering.com>

Support an already running watchdog by checking its enable bit and set
up the status accordingly before registering the device.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

Change since v1:

* removed custom code to handle RPM refcnt. The watchdog core does it
  already.

Tested again on a Renesas Salvator-XS (R-Car M3N) with and without the
'open_timeout' command line parameter.

After all these discussions, the patch became quite simple again :/
Still, thanks for all the discussions to make sure we didn't overlook
clock handling.

 drivers/watchdog/renesas_wdt.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Wolfram Sang Aug. 19, 2019, 5:44 p.m. UTC | #1
> After all these discussions, the patch became quite simple again :/
> Still, thanks for all the discussions to make sure we didn't overlook
> clock handling.

Except for the probe error path, sigh... v3 coming up.
diff mbox series

Patch

diff --git a/drivers/watchdog/renesas_wdt.c b/drivers/watchdog/renesas_wdt.c
index 00662a8e039c..47fce4de0110 100644
--- a/drivers/watchdog/renesas_wdt.c
+++ b/drivers/watchdog/renesas_wdt.c
@@ -194,6 +194,7 @@  static int rwdt_probe(struct platform_device *pdev)
 	struct clk *clk;
 	unsigned long clks_per_sec;
 	int ret, i;
+	u8 csra;
 
 	if (rwdt_blacklisted(dev))
 		return -ENODEV;
@@ -213,8 +214,8 @@  static int rwdt_probe(struct platform_device *pdev)
 	pm_runtime_enable(dev);
 	pm_runtime_get_sync(dev);
 	priv->clk_rate = clk_get_rate(clk);
-	priv->wdev.bootstatus = (readb_relaxed(priv->base + RWTCSRA) &
-				RWTCSRA_WOVF) ? WDIOF_CARDRESET : 0;
+	csra = readb_relaxed(priv->base + RWTCSRA);
+	priv->wdev.bootstatus = csra & RWTCSRA_WOVF ? WDIOF_CARDRESET : 0;
 	pm_runtime_put(dev);
 
 	if (!priv->clk_rate) {
@@ -252,6 +253,13 @@  static int rwdt_probe(struct platform_device *pdev)
 	/* This overrides the default timeout only if DT configuration was found */
 	watchdog_init_timeout(&priv->wdev, 0, dev);
 
+	/* Check if FW enabled the watchdog */
+	if (csra & RWTCSRA_TME) {
+		/* Ensure properly initialized dividers */
+		rwdt_start(&priv->wdev);
+		set_bit(WDOG_HW_RUNNING, &priv->wdev.status);
+	}
+
 	ret = watchdog_register_device(&priv->wdev);
 	if (ret < 0)
 		goto out_pm_disable;