[PATCH 2/2] timer: sti: use clk API to get timer clock rate

Patrice CHOTARD patrice.chotard at st.com
Thu Mar 12 13:37:52 CET 2020


Hi Nicolas

On 3/8/20 2:20 PM, Nicolas Heemeryck wrote:
> Retrieve clock rate through device tree. This mimics the behavior of
> arm_global_timer in Linux.
>
> Signed-off-by: Nicolas Heemeryck <nicolas.heemeryck at gmail.com>
> ---
>  drivers/timer/sti-timer.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c
> index eac22ae39b..123fac04a9 100644
> --- a/drivers/timer/sti-timer.c
> +++ b/drivers/timer/sti-timer.c
> @@ -6,6 +6,7 @@
>  
>  #include <common.h>
>  #include <dm.h>
> +#include <clk.h>
>  #include <timer.h>
>  
>  #include <asm/io.h>
> @@ -41,14 +42,22 @@ static int sti_timer_probe(struct udevice *dev)
>  {
>  	struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
>  	struct sti_timer_priv *priv = dev_get_priv(dev);
> -
> -	uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
> +	struct clk clk;
> +	int ret;
>  
>  	/* get arm global timer base address */
>  	priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
>  	if (!priv->global_timer)
>  		return -ENOENT;
>  
> +	ret = clk_get_by_index(dev, 0, &clk);
> +	if (ret)
> +		return ret;
> +
> +	uc_priv->clock_rate = clk_get_rate(&clk);
> +	if (!uc_priv->clock_rate)
> +		return -EINVAL;
> +
>  	/* init timer */
>  	writel(0x01, &priv->global_timer->ctl);
>  

Nack, for STi board, there is no clock driver (all clock are enabled by default).

So clk_get_by_index() will return an error and will avoid timer driver to probe properly.

Thanks

Patrice


More information about the U-Boot mailing list