On 5/23/25 11:46, Antonio Borneo wrote:
> 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
> call wdt_set_force_autostart(). This will keep U-Boot pinging the
> watchdog even when the property 'u-boot,noautostart' is present.
> 
> Link: https://github.com/OP-TEE/optee_os/commit/a7f2d4bd8632 [1]
> 
> Signed-off-by: Antonio Borneo <antonio.bor...@foss.st.com>
> ---
>  drivers/watchdog/arm_smc_wdt.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/watchdog/arm_smc_wdt.c b/drivers/watchdog/arm_smc_wdt.c
> index 0ea44445700..f6854aa9ac9 100644
> --- a/drivers/watchdog/arm_smc_wdt.c
> +++ b/drivers/watchdog/arm_smc_wdt.c
> @@ -46,6 +46,8 @@ static int smcwd_call(struct udevice *dev, enum smcwd_call 
> call,
>               return -ENODEV;
>       if (res->a0 == PSCI_RET_INVALID_PARAMS)
>               return -EINVAL;
> +     if (res->a0 == PSCI_RET_DISABLED)
> +             return -ENODATA;
>       if (res->a0 != PSCI_RET_SUCCESS)
>               return -EIO;
>  
> @@ -99,6 +101,21 @@ static int smcwd_probe(struct udevice *dev)
>       priv->min_timeout = res.a1;
>       priv->max_timeout = res.a2;
>  
> +     /* If already started, then force u-boot to use it */
> +     err = smcwd_call(dev, SMCWD_GET_TIMELEFT, 0, NULL);
> +     switch (err) {
> +     case 0:
> +             dev_dbg(dev, "Already started\n");
> +             wdt_set_force_autostart(dev);
> +             break;
> +     case -ENODATA:
> +             dev_dbg(dev, "Not already started\n");
> +             break;
> +     default:
> +             /* Optional SMCWD_GET_TIMELEFT not implemented */
> +             break;
> +     }
> +
>       return 0;
>  }
>  
Reviewed-by: Patrice Chotard <patrice.chot...@foss.st.com>

Thanks
Patrice

Reply via email to