]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
watchdog: imx_sc_wdt: detect if already running
authorAlexander Sverdlin <alexander.sverdlin@siemens.com>
Wed, 28 Aug 2024 06:02:10 +0000 (08:02 +0200)
committerWim Van Sebroeck <wim@linux-watchdog.org>
Tue, 10 Sep 2024 09:08:46 +0000 (11:08 +0200)
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>
drivers/watchdog/imx_sc_wdt.c

index d73076b686d8ca81835b500d76a84ea6f55f6148..1280b9b1ec2ac4355872fd9930c5dd7e200fc1ae 100644 (file)
@@ -56,6 +56,25 @@ static int imx_sc_wdt_ping(struct watchdog_device *wdog)
        return 0;
 }
 
+static bool imx_sc_wdt_is_running(void)
+{
+       struct arm_smccc_res res;
+
+       arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_START_WDOG,
+                     0, 0, 0, 0, 0, 0, &res);
+
+       /* Already enabled (SC_TIMER_ERR_BUSY)? */
+       if (res.a0 == SC_TIMER_ERR_BUSY)
+               return true;
+
+       /* Undo only if that was us who has (successfully) enabled the WDT */
+       if (!res.a0)
+               arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_STOP_WDOG,
+                             0, 0, 0, 0, 0, 0, &res);
+
+       return false;
+}
+
 static int imx_sc_wdt_start(struct watchdog_device *wdog)
 {
        struct arm_smccc_res res;
@@ -183,6 +202,9 @@ static int imx_sc_wdt_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
+       if (imx_sc_wdt_is_running())
+               set_bit(WDOG_HW_RUNNING, &wdog->status);
+
        watchdog_stop_on_reboot(wdog);
        watchdog_stop_on_unregister(wdog);