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

Nicolas Heemeryck nicolas.heemeryck at gmail.com
Sun Mar 8 14:20:57 CET 2020


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



More information about the U-Boot mailing list