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

watchdog: imx_sc_wdt: detect if already running

Firmware (SC) WDT can be already enabled in U-Boot. Detect this case and
make CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED functional by setting
WDOG_HW_RUNNING.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20240828060212.108608-1-alexander.sverdlin@siemens.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>

authored by

Alexander Sverdlin and committed by
Wim Van Sebroeck
db60d55e 6adb5591

+22
+22
drivers/watchdog/imx_sc_wdt.c
··· 56 56 return 0; 57 57 } 58 58 59 + static bool imx_sc_wdt_is_running(void) 60 + { 61 + struct arm_smccc_res res; 62 + 63 + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_START_WDOG, 64 + 0, 0, 0, 0, 0, 0, &res); 65 + 66 + /* Already enabled (SC_TIMER_ERR_BUSY)? */ 67 + if (res.a0 == SC_TIMER_ERR_BUSY) 68 + return true; 69 + 70 + /* Undo only if that was us who has (successfully) enabled the WDT */ 71 + if (!res.a0) 72 + arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_STOP_WDOG, 73 + 0, 0, 0, 0, 0, 0, &res); 74 + 75 + return false; 76 + } 77 + 59 78 static int imx_sc_wdt_start(struct watchdog_device *wdog) 60 79 { 61 80 struct arm_smccc_res res; ··· 201 182 ret = imx_sc_wdt_set_timeout(wdog, wdog->timeout); 202 183 if (ret) 203 184 return ret; 185 + 186 + if (imx_sc_wdt_is_running()) 187 + set_bit(WDOG_HW_RUNNING, &wdog->status); 204 188 205 189 watchdog_stop_on_reboot(wdog); 206 190 watchdog_stop_on_unregister(wdog);