diff mbox series

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

Message ID 20200313224244.4502-3-nicolas.heemeryck@gmail.com
State Accepted
Commit 5b5699cdc97122e08e7fd0886a9e4474ca3ccb35
Headers show
Series timer: sti: mimic Linux declaration and usage | expand

Commit Message

Nicolas Heemeryck March 13, 2020, 10:42 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 at gmail.com>
Cc: Patrice Chotard <patrice.chotard at st.com>

---

Changes for v2:

- Fall back on CONFIG_SYS_HZ_CLOCK if clk_get_by_index returns an
error or no clock driver is provided.
---
 drivers/timer/sti-timer.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

Comments

Patrice CHOTARD March 17, 2020, 3:34 p.m. UTC | #1
Hi Nicolas

On 3/13/20 11:42 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>
> Cc: Patrice Chotard <patrice.chotard at st.com>
>
> ---
>
> Changes for v2:
>
> - Fall back on CONFIG_SYS_HZ_CLOCK if clk_get_by_index returns an
> error or no clock driver is provided.
> ---
>  drivers/timer/sti-timer.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c
> index eac22ae39b..ff42056abd 100644
> --- a/drivers/timer/sti-timer.c
> +++ b/drivers/timer/sti-timer.c
> @@ -6,7 +6,9 @@
>  
>  #include <common.h>
>  #include <dm.h>
> +#include <clk.h>
>  #include <timer.h>
> +#include <linux/err.h>
>  
>  #include <asm/io.h>
>  #include <asm/arch-armv7/globaltimer.h>
> @@ -41,14 +43,25 @@ 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 err;
> +	ulong ret;
>  
>  	/* get arm global timer base address */
>  	priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
>  	if (!priv->global_timer)
>  		return -ENOENT;
>  
> +	err = clk_get_by_index(dev, 0, &clk);
> +	if (!err) {
> +		ret = clk_get_rate(&clk);
> +		if (IS_ERR_VALUE(ret))
> +			return ret;
> +		uc_priv->clock_rate = ret;
> +	} else {
> +		uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
> +	}
> +
>  	/* init timer */
>  	writel(0x01, &priv->global_timer->ctl);
>  

Acked-by: Patrice Chotard <patrice.chotard at st.com>

Thanks

Patrice
Patrick Delaunay March 19, 2020, 9:29 a.m. UTC | #2
Hi,

> From: U-Boot <u-boot-bounces at lists.denx.de> On Behalf Of Nicolas Heemeryck
> Sent: vendredi 13 mars 2020 23:43
> 
> 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>
> Cc: Patrice Chotard <patrice.chotard at st.com>
> 
> ---


Applied to u-boot-stm/next, thanks!

Regards

Patrick
diff mbox series

Patch

diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c
index eac22ae39b..ff42056abd 100644
--- a/drivers/timer/sti-timer.c
+++ b/drivers/timer/sti-timer.c
@@ -6,7 +6,9 @@ 
 
 #include <common.h>
 #include <dm.h>
+#include <clk.h>
 #include <timer.h>
+#include <linux/err.h>
 
 #include <asm/io.h>
 #include <asm/arch-armv7/globaltimer.h>
@@ -41,14 +43,25 @@  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 err;
+	ulong ret;
 
 	/* get arm global timer base address */
 	priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
 	if (!priv->global_timer)
 		return -ENOENT;
 
+	err = clk_get_by_index(dev, 0, &clk);
+	if (!err) {
+		ret = clk_get_rate(&clk);
+		if (IS_ERR_VALUE(ret))
+			return ret;
+		uc_priv->clock_rate = ret;
+	} else {
+		uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
+	}
+
 	/* init timer */
 	writel(0x01, &priv->global_timer->ctl);