Skip to contentSkip to conversation

timer: Support clocks via phandle

PATCH Superseded Vlad Zakharov 2 participants 2 messages Nov 17, 2016 – Nov 19, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timer: Support clocks via phandle

Earlier timer driver needed a clock-frequency property in compatible device-tree nodes. Another way is to reference a clock via a phandle.

So now timer_pre_probe tries to get clock by reference through device tree. In case it is impossible to get clock device through the reference, clock-frequency property of the timer node is read to provide backward compatibility.

---
 drivers/timer/timer-uclass.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/timer/timer-uclass.c +12 -3
index f8ddf93..cca41f1 100644
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
+#include <clk.h>
 #include <errno.h>
 #include <timer.h>
 
@@ -42,9 +43,17 @@ unsigned long notrace timer_get_rate(struct udevice *dev)
 static int timer_pre_probe(struct udevice *dev)
 {
 	struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-
-	uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
-					     "clock-frequency", 0);
+	struct clk *timer_clk;
+	int err;
+
+	err = clk_get_by_index(dev, 0, timer_clk);
+	if (!err) {
+		uc_priv->clock_rate = clk_get_rate(timer_clk);
+		if (uc_priv->clock_rate < 0)
+			return uc_priv->clock_rate;
+	} else
+		uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob,
+				dev->of_offset,	"clock-frequency", 0);
 
 	return 0;
 }
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 timer: Support clocks via phandle

Hi Vlad,

Quoted 28 lines · Vlad Zakharov

Earlier timer driver needed a clock-frequency property in compatible device-tree nodes. Another way is to reference a clock via a phandle.

So now timer_pre_probe tries to get clock by reference through device tree. In case it is impossible to get clock device through the reference, clock-frequency property of the timer node is read to provide backward compatibility.

---
 drivers/timer/timer-uclass.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/timer/timer-uclass.c +1 -0
index f8ddf93..cca41f1 100644
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
+#include <clk.h>
 #include <errno.h>
 #include <timer.h>
 
@@ -42,9 +43,17 @@ unsigned long notrace timer_get_rate(struct udevice *dev)
 static int timer_pre_probe(struct udevice *dev)
 {

drivers/timer/timer-uclass.c unsigned long notrace timer_get_rate(struct udevice *dev) · line 51

Quoted 10 lines
drivers/timer/timer-uclass.c +6 -3
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-
-       uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
-                                            "clock-frequency", 0);
+       struct clk *timer_clk;
+       int err;
+
+       err = clk_get_by_index(dev, 0, timer_clk);
+       if (!err) {
+               uc_priv->clock_rate = clk_get_rate(timer_clk);

Please use a temporary variable here, like:

   ret = clk_get_rate(timer_clk);
   if (IS_ERR_VALUE(ret))
      return ret;
   uc_priv->clock_rate = ret;
Quoted 11 lines
drivers/timer/timer-uclass.c +5 -1
+               if (uc_priv->clock_rate < 0)
+                       return uc_priv->clock_rate;
+       } else
+               uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob,
+                               dev->of_offset, "clock-frequency", 0);
 
        return 0;
 }
--

2.7.4

Regards,
SImon