On Intel SoC FPGA platform, Stratix10 or Agilex, the watchdog is started in u-boot, so kernel will create a timer and work to keep watchdog alive. But when user executes commands "halt", "poweroff" or "shutdown", the system is reset when watchdog triggers timeout. The root cause is that the watchdog not stopped properly. So, register notify callback to stop watchdog when shuting down system.
Signed-off-by: Meng Li <[email protected]> --- drivers/watchdog/dw_wdt.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c index 61af5d1332ac..e93150b92040 100644 --- a/drivers/watchdog/dw_wdt.c +++ b/drivers/watchdog/dw_wdt.c @@ -28,6 +28,8 @@ #include <linux/pm.h> #include <linux/reset.h> #include <linux/watchdog.h> +#include <linux/notifier.h> +#include <linux/reboot.h> #define WDOG_CONTROL_REG_OFFSET 0x00 #define WDOG_CONTROL_REG_WDT_EN_MASK 0x01 @@ -492,6 +494,19 @@ static int dw_wdt_init_timeouts(struct dw_wdt *dw_wdt, struct device *dev) return 0; } +static int dw_wdt_notify(struct notifier_block *nb, + unsigned long code, void *data) +{ + struct watchdog_device *wdd; + + wdd = container_of(nb, struct watchdog_device, reboot_nb); + if (code == SYS_HALT || code == SYS_POWER_OFF) + if (!nowayout) + dw_wdt_stop(wdd); + + return NOTIFY_DONE; +} + #ifdef CONFIG_DEBUG_FS #define DW_WDT_DBGFS_REG(_name, _off) \ @@ -664,14 +679,22 @@ static int dw_wdt_drv_probe(struct platform_device *pdev) watchdog_set_restart_priority(wdd, 128); - ret = watchdog_register_device(wdd); + wdd->reboot_nb.notifier_call = dw_wdt_notify; + ret = register_reboot_notifier(&wdd->reboot_nb); if (ret) goto out_assert_rst; + ret = watchdog_register_device(wdd); + if (ret) + goto err_out_notifier; + dw_wdt_dbgfs_init(dw_wdt); return 0; +err_out_notifier: + unregister_reboot_notifier(&wdd->reboot_nb); + out_assert_rst: reset_control_assert(dw_wdt->rst); -- 2.34.1
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#12823): https://lists.yoctoproject.org/g/linux-yocto/message/12823 Mute This Topic: https://lists.yoctoproject.org/mt/99844366/21656 Group Owner: [email protected] Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
