From 8604389b03f657cf392f253b9a04eba442680126 Mon Sep 17 00:00:00 2001 From: tao89959 <1036524114@qq.com> Date: Thu, 26 Mar 2026 16:30:03 +0800 Subject: [PATCH] drivers: watchdog: support setup watchdog timeout when close enable watchdog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changelog: 看门狗驱动支持在关机调用看门狗时设置超时时间 Signed-off-by: maoxiaochuan --- drivers/watchdog/Kconfig | 9 +++++++++ drivers/watchdog/watchdog_dev.c | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 20eee9b05..b6f2c5965 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -47,6 +47,15 @@ config WATCHDOG_NOWAYOUT get killed. If you say Y here, the watchdog cannot be stopped once it has been started. +config WATCHDOG_TIMEOUT_ON_CLOSE + int "Timeout value for opening watchdog device" + default 5 + depends on !WATCHDOG_NOWAYOUT + help + if not WATCHDOG_NOWAYOUT, mean setup watchdog daemon when poweroff + so this option is second about watchdog timeout. + if setup <= 0 mean not setup watchdog timeout. but ping watchdog also will exec + config WATCHDOG_HANDLE_BOOT_ENABLED bool "Update boot-enabled watchdog until userspace takes over" default y diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 4190cb800..615838d1f 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -966,6 +966,10 @@ static int watchdog_release(struct inode *inode, struct file *file) /* If the watchdog was not stopped, send a keepalive ping */ if (err < 0) { pr_crit("watchdog%d: watchdog did not stop!\n", wdd->id); +#ifdef CONFIG_WATCHDOG_TIMEOUT_ON_CLOSE + if (wdd->ops->set_timeout && CONFIG_WATCHDOG_TIMEOUT_ON_CLOSE > 0) + wdd->ops->set_timeout(wdd, CONFIG_WATCHDOG_TIMEOUT_ON_CLOSE); +#endif watchdog_ping(wdd); }