[PATCH v2 05/10] watchdog: wdt-uclass.c: keep track of each device's running state

Stefan Roese sr at denx.de
Tue Jun 29 08:04:42 CEST 2021


On 28.05.21 00:00, Rasmus Villemoes wrote:
> As a step towards handling all DM watchdogs in watchdog_reset(), use a
> per-device flag to keep track of whether the device has been started
> instead of a bit in gd->flags.
> 
> We will still need that bit to know whether we are past
> initr_watchdog() and hence have populated gd->watchdog_dev -
> incidentally, that is how it was used prior to commit 9c44ff1c5f3c.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>

Reviewed-by: Stefan Roese <sr at denx.de>

Thanks,
Stefan

> ---
>   drivers/watchdog/wdt-uclass.c | 19 +++++++++++++++----
>   1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c
> index 5d5dbcd0f7..026b6d1eb4 100644
> --- a/drivers/watchdog/wdt-uclass.c
> +++ b/drivers/watchdog/wdt-uclass.c
> @@ -22,6 +22,7 @@ struct wdt_priv {
>   	u32 timeout;
>   	ulong reset_period;
>   	ulong next_reset;
> +	bool running;
>   };
>   
>   static void init_watchdog_dev(struct udevice *dev)
> @@ -63,6 +64,7 @@ int initr_watchdog(void)
>   	}
>   	init_watchdog_dev(gd->watchdog_dev);
>   
> +	gd->flags |= GD_FLG_WDT_READY;
>   	return 0;
>   }
>   
> @@ -75,8 +77,11 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
>   		return -ENOSYS;
>   
>   	ret = ops->start(dev, timeout_ms, flags);
> -	if (ret == 0)
> -		gd->flags |= GD_FLG_WDT_READY;
> +	if (ret == 0) {
> +		struct wdt_priv *priv = dev_get_uclass_priv(dev);
> +
> +		priv->running = true;
> +	}
>   
>   	return ret;
>   }
> @@ -90,8 +95,11 @@ int wdt_stop(struct udevice *dev)
>   		return -ENOSYS;
>   
>   	ret = ops->stop(dev);
> -	if (ret == 0)
> -		gd->flags &= ~GD_FLG_WDT_READY;
> +	if (ret == 0) {
> +		struct wdt_priv *priv = dev_get_uclass_priv(dev);
> +
> +		priv->running = false;
> +	}
>   
>   	return ret;
>   }
> @@ -145,6 +153,9 @@ void watchdog_reset(void)
>   
>   	dev = gd->watchdog_dev;
>   	priv = dev_get_uclass_priv(dev);
> +	if (!priv->running)
> +		return;
> +
>   	/* Do not reset the watchdog too often */
>   	now = get_timer(0);
>   	if (time_after_eq(now, priv->next_reset)) {
> 


Viele Grüße,
Stefan

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de


More information about the U-Boot mailing list