diff mbox series

watchdog: imx_sc_wdt: detect if already running

Message ID 20240828060212.108608-1-alexander.sverdlin@siemens.com
State New
Headers show
Series watchdog: imx_sc_wdt: detect if already running | expand

Commit Message

Sverdlin, Alexander Aug. 28, 2024, 6:02 a.m. UTC
From: Alexander Sverdlin <alexander.sverdlin@siemens.com>

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>
---
 drivers/watchdog/imx_sc_wdt.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Guenter Roeck Aug. 28, 2024, 3:29 p.m. UTC | #1
On 8/27/24 23:02, A. Sverdlin wrote:
> From: Alexander Sverdlin <alexander.sverdlin@siemens.com>
> 
> 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>

Guenter

> ---
>   drivers/watchdog/imx_sc_wdt.c | 22 ++++++++++++++++++++++
>   1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/watchdog/imx_sc_wdt.c b/drivers/watchdog/imx_sc_wdt.c
> index e51fe1b78518..e6d567b11795 100644
> --- a/drivers/watchdog/imx_sc_wdt.c
> +++ b/drivers/watchdog/imx_sc_wdt.c
> @@ -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);
>
diff mbox series

Patch

diff --git a/drivers/watchdog/imx_sc_wdt.c b/drivers/watchdog/imx_sc_wdt.c
index e51fe1b78518..e6d567b11795 100644
--- a/drivers/watchdog/imx_sc_wdt.c
+++ b/drivers/watchdog/imx_sc_wdt.c
@@ -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);