diff mbox series

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

Message ID 20200308132057.256-3-nicolas.heemeryck@gmail.com
State Superseded
Delegated to: Patrice Chotard
Headers show
Series timer: sti: mimic Linux declaration and usage | expand

Commit Message

Nicolas Heemeryck March 8, 2020, 1:20 p.m. UTC
Retrieve clock rate through device tree. This mimics the behavior of
arm_global_timer in Linux.

Signed-off-by: Nicolas Heemeryck <nicolas.heemeryck@gmail.com>
---
 drivers/timer/sti-timer.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Patrice CHOTARD March 12, 2020, 12:37 p.m. UTC | #1
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@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
diff mbox series

Patch

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);