Blob Blame History Raw
From a0a60bf9372aa771344e261c4f86c174c331fc71 Mon Sep 17 00:00:00 2001
From: Marco Felsch <m.felsch@pengutronix.de>
Date: Mon, 28 May 2018 08:45:46 +0200
Subject: [PATCH] watchdog: da9063: Fix timeout handling during probe
Patch-mainline: v4.18-rc1
Git-commit: be9e9c2ad52baea131a5395b15f52ae4f86bfbe3
References: bsc#1100843

The watchdog can be enabled in previous steps (e.g. the bootloader). Set
the driver default timeout value (8s) if the watchdog is already running
and the HW_RUNNING flag. So the watchdog core framework will ping the
watchdog till the user space activates the watchdog explicit with the
desired timeout value.

Fixes: 5e9c16e37608 ("watchdog: Add DA9063 PMIC watchdog driver.")
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
Acked-by: Yadan Fan <ydfan@suse.com>
---
 drivers/watchdog/da9063_wdt.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

--- a/drivers/watchdog/da9063_wdt.c
+++ b/drivers/watchdog/da9063_wdt.c
@@ -48,6 +48,18 @@ static unsigned int da9063_wdt_timeout_t
 	return DA9063_TWDSCALE_MAX;
 }
 
+/*
+ * Return 0 if watchdog is disabled, else non zero.
+ */
+static unsigned int da9063_wdt_is_running(struct da9063 *da9063)
+{
+	unsigned int val;
+
+	regmap_read(da9063->regmap, DA9063_REG_CONTROL_D, &val);
+
+	return val & DA9063_TWDSCALE_MASK;
+}
+
 static int da9063_wdt_disable_timer(struct da9063 *da9063)
 {
 	return regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_D,
@@ -209,6 +221,15 @@ static int da9063_wdt_probe(struct platf
 
 	watchdog_set_drvdata(wdd, da9063);
 
+	/* Change the timeout to the default value if the watchdog is running */
+	if (da9063_wdt_is_running(da9063)) {
+		unsigned int timeout;
+
+		timeout = da9063_wdt_timeout_to_sel(DA9063_WDG_TIMEOUT);
+		_da9063_wdt_set_timeout(da9063, timeout);
+		set_bit(WDOG_HW_RUNNING, &wdd->status);
+	}
+
 	return devm_watchdog_register_device(&pdev->dev, wdd);
 }