Skip to contentSkip to conversation

Various fixes for the da9052 watchdog

PATCH Superseded Marcus Folkesson 2 participants 9 messages Mar 25, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Various fixes for the da9052 watchdog

Add support for the nowayout and timeout module parameters and treat them in a standard way.

Respect twdmin, without this the watchdog timer will immediately assert TWD_ERROR and power down to reset mode.

Do not stop the watchdog during probe. If the watchdog is enabled in the bootloader, it should propably supposed to stay on.

---
Changes in v2:
- Fix warning found by kernel test robot
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Marcus Folkesson (4):
watchdog: da9052_wdt: add support for nowayout
watchdog: da9052_wdt: use timeout value from external inputs
watchdog: da9052_wdt: do not disable wdt during probe
watchdog: da9052_wdt: respect TWDMIN

 drivers/watchdog/da9052_wdt.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

---
base-commit: 0fed89a961ea851945d23cc35beb59d6e56c0964
change-id: 20250313-da9052-fixes-186674b34993

Best regards,

Signature · 1 line
Marcus Folkesson <[email protected]>
#1 lore raw

PATCH v2 1/4 watchdog: da9052_wdt: add support for nowayout

Add nowayout module parameter for not stopping the watchdog when userspae application quits.

---
 drivers/watchdog/da9052_wdt.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/watchdog/da9052_wdt.c +7 -0
index 77039f2f0be54273df1666fe40c413b6c89285a1..a8ff1e6a7903f6f139c5bb60d7d92ca39077ee04 100644
@@ -30,6 +30,12 @@ struct da9052_wdt_data {
 	unsigned long jpast;
 };
 
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout,
+		 "Watchdog cannot be stopped once started (default="
+		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
 static const struct {
 	u8 reg_val;
 	int time;  /* Seconds */
@@ -172,6 +178,7 @@ static int da9052_wdt_probe(struct platform_device *pdev)
 	da9052_wdt->ops = &da9052_wdt_ops;
 	da9052_wdt->parent = dev;
 	watchdog_set_drvdata(da9052_wdt, driver_data);
+	watchdog_set_nowayout(da9052_wdt, nowayout);
 
 	if (da9052->fault_log & DA9052_FAULTLOG_TWDERROR)
 		da9052_wdt->bootstatus |= WDIOF_CARDRESET;
Signature · 1 line
2.48.1
#3 lore raw

PATCH v2 2/4 watchdog: da9052_wdt: use timeout value from external inputs

In reply to Marcus Folkesson

Introduce the timeout module parameter and pass it to watchdog_init_timeout(). If the parameter is not set or contains an invalid value, fallback on the timeout-secs devicetree property value.

If none of the above is valid, go for the old default value.

---
 drivers/watchdog/da9052_wdt.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/watchdog/da9052_wdt.c +7 -0
index a8ff1e6a7903f6f139c5bb60d7d92ca39077ee04..fa9078d4c136a52f1193768fe93dc04189519679 100644
@@ -36,6 +36,12 @@ MODULE_PARM_DESC(nowayout,
 		 "Watchdog cannot be stopped once started (default="
 		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
 
+static int timeout;
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(timeout,
+	"Watchdog timeout in seconds. (default = "
+	__MODULE_STRING(WDT_DEFAULT_TIMEOUT) ")");
+
 static const struct {
 	u8 reg_val;
 	int time;  /* Seconds */
@@ -178,6 +184,7 @@ static int da9052_wdt_probe(struct platform_device *pdev)
 	da9052_wdt->ops = &da9052_wdt_ops;
 	da9052_wdt->parent = dev;
 	watchdog_set_drvdata(da9052_wdt, driver_data);
+	watchdog_init_timeout(da9052_wdt, timeout, dev);
 	watchdog_set_nowayout(da9052_wdt, nowayout);
 
 	if (da9052->fault_log & DA9052_FAULTLOG_TWDERROR)
Signature · 1 line
2.48.1
maintainer Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] watchdog: da9052_wdt: use timeout value from external inputs

Quoted 7 lines · Marcus Folkesson

Introduce the timeout module parameter and pass it to watchdog_init_timeout(). If the parameter is not set or contains an invalid value, fallback on the timeout-secs devicetree property value.

If none of the above is valid, go for the old default value.

#5 lore raw

PATCH v2 3/4 watchdog: da9052_wdt: do not disable wdt during probe

In reply to Marcus Folkesson

If the watchog is started by the bootloader, we do not want the watchdog to be disabled.

---
 drivers/watchdog/da9052_wdt.c | 8 --------
 1 file changed, 8 deletions(-)
drivers/watchdog/da9052_wdt.c +0 -8
index fa9078d4c136a52f1193768fe93dc04189519679..b821006fca70480bf3b23a62bded4e66851a537e 100644
@@ -170,7 +170,6 @@ static int da9052_wdt_probe(struct platform_device *pdev)
 	struct da9052 *da9052 = dev_get_drvdata(dev->parent);
 	struct da9052_wdt_data *driver_data;
 	struct watchdog_device *da9052_wdt;
-	int ret;
 
 	driver_data = devm_kzalloc(dev, sizeof(*driver_data), GFP_KERNEL);
 	if (!driver_data)
@@ -194,13 +193,6 @@ static int da9052_wdt_probe(struct platform_device *pdev)
 	if (da9052->fault_log & DA9052_FAULTLOG_VDDFAULT)
 		da9052_wdt->bootstatus |= WDIOF_POWERUNDER;
 
-	ret = da9052_reg_update(da9052, DA9052_CONTROL_D_REG,
-				DA9052_CONTROLD_TWDSCALE, 0);
-	if (ret < 0) {
-		dev_err(dev, "Failed to disable watchdog bits, %d\n", ret);
-		return ret;
-	}
-
 	return devm_watchdog_register_device(dev, &driver_data->wdt);
 }
 
Signature · 1 line
2.48.1
maintainer
#6 lore raw

Re: [PATCH v2 3/4] watchdog: da9052_wdt: do not disable wdt during probe

Quoted 3 lines · Marcus Folkesson

If the watchog is started by the bootloader, we do not want the watchdog to be disabled.

If the watchdog is left running, the watchdog core should be notified by setting WDOG_HW_RUNNING. Please see other drivers for examples.

Thanks,
Guenter

#7 lore raw

PATCH v2 4/4 watchdog: da9052_wdt: respect TWDMIN

In reply to Marcus Folkesson

We have to wait at least the minimium time for the watchdog window (TWDMIN) before writings to the wdt register after the watchdog is activated.
Otherwise the chip will assert TWD_ERROR and power down to reset mode.

---
 drivers/watchdog/da9052_wdt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/watchdog/da9052_wdt.c +1 -0
index b821006fca70480bf3b23a62bded4e66851a537e..1e49cbae7eaec3015264dec891032a56f56e36cc 100644
@@ -179,6 +179,7 @@ static int da9052_wdt_probe(struct platform_device *pdev)
 	da9052_wdt = &driver_data->wdt;
 
 	da9052_wdt->timeout = DA9052_DEF_TIMEOUT;
+	da9052_wdt->min_hw_heartbeat_ms = DA9052_TWDMIN;
 	da9052_wdt->info = &da9052_wdt_info;
 	da9052_wdt->ops = &da9052_wdt_ops;
 	da9052_wdt->parent = dev;
Signature · 1 line
2.48.1
maintainer Reviewed-by on v2 4/4
#8 lore raw

Re: [PATCH v2 4/4] watchdog: da9052_wdt: respect TWDMIN

Quoted 6 lines · Marcus Folkesson

We have to wait at least the minimium time for the watchdog window (TWDMIN) before writings to the wdt register after the watchdog is activated.
Otherwise the chip will assert TWD_ERROR and power down to reset mode.

Quoted 21 lines
---
 drivers/watchdog/da9052_wdt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/watchdog/da9052_wdt.c +1 -0
index b821006fca70480bf3b23a62bded4e66851a537e..1e49cbae7eaec3015264dec891032a56f56e36cc 100644
@@ -179,6 +179,7 @@ static int da9052_wdt_probe(struct platform_device *pdev)
 	da9052_wdt = &driver_data->wdt;
 
 	da9052_wdt->timeout = DA9052_DEF_TIMEOUT;
+	da9052_wdt->min_hw_heartbeat_ms = DA9052_TWDMIN;
 	da9052_wdt->info = &da9052_wdt_info;
 	da9052_wdt->ops = &da9052_wdt_ops;
 	da9052_wdt->parent = dev;
Signature · 2 lines
-- 
2.48.1