Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: arm_smc_wdt: get wdt status through SMCWD_GET_TIMELEFT

The optional SMCWD_GET_TIMELEFT command can be used to detect if
the watchdog has already been started.
See the implementation in OP-TEE secure OS [1].

At probe time, check if the watchdog is already started and then
set WDOG_HW_RUNNING in the watchdog status. This will cause the
watchdog framework to ping the watchdog until a userspace watchdog
daemon takes over the control.

Link: https://github.com/OP-TEE/optee_os/commit/a7f2d4bd8632 [1]

Signed-off-by: Antonio Borneo <antonio.borneo@foss.st.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20250520085952.210723-1-antonio.borneo@foss.st.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>

authored by

Antonio Borneo and committed by
Wim Van Sebroeck
cc0df5eb 27a46a0f

+14 -3
+14 -3
drivers/watchdog/arm_smc_wdt.c
··· 46 46 return -ENODEV; 47 47 if (res->a0 == PSCI_RET_INVALID_PARAMS) 48 48 return -EINVAL; 49 + if (res->a0 == PSCI_RET_DISABLED) 50 + return -ENODATA; 49 51 if (res->a0 != PSCI_RET_SUCCESS) 50 52 return -EIO; 51 53 return 0; ··· 133 131 134 132 wdd->info = &smcwd_info; 135 133 /* get_timeleft is optional */ 136 - if (smcwd_call(wdd, SMCWD_GET_TIMELEFT, 0, NULL)) 137 - wdd->ops = &smcwd_ops; 138 - else 134 + err = smcwd_call(wdd, SMCWD_GET_TIMELEFT, 0, NULL); 135 + switch (err) { 136 + case 0: 137 + set_bit(WDOG_HW_RUNNING, &wdd->status); 138 + fallthrough; 139 + case -ENODATA: 139 140 wdd->ops = &smcwd_timeleft_ops; 141 + break; 142 + default: 143 + wdd->ops = &smcwd_ops; 144 + break; 145 + } 146 + 140 147 wdd->timeout = res.a2; 141 148 wdd->max_timeout = res.a2; 142 149 wdd->min_timeout = res.a1;