]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
timer: sti: use clk API to get timer clock rate
authorNicolas Heemeryck <nicolas.heemeryck@gmail.com>
Fri, 13 Mar 2020 22:42:44 +0000 (23:42 +0100)
committerPatrick Delaunay <patrick.delaunay@st.com>
Tue, 24 Mar 2020 13:23:35 +0000 (14:23 +0100)
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>
Cc: Patrice Chotard <patrice.chotard@st.com>
Acked-by: Patrice Chotard <patrice.chotard@st.com>
drivers/timer/sti-timer.c

index eac22ae39b01c7b1c885b21f19f48bba6ff88b6e..ff42056abdd1aa2f5abd2a9438272d820bad7ab3 100644 (file)
@@ -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);