Skip to contentSkip to conversation

timer: Support clocks via phandle

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

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
Changes v1..v2:
- Use temporary variable when getting clock rate

 drivers/timer/timer-uclass.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/timer/timer-uclass.c +14 -3
index f8ddf93..a891a58 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,19 @@ 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;
+	ulong ret;
+
+	err = clk_get_by_index(dev, 0, timer_clk);
+	if (!err) {
+		ret = clk_get_rate(timer_clk);
+		if (IS_ERR_VALUE(ret))
+			return ret;
+		uc_priv->clock_rate = ret;
+	} 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 v2 1/1 timer: Support clocks via phandle

Hi Tom,

Quoted 49 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.

---
Changes v1..v2:
?- Use temporary variable when getting clock rate

?drivers/timer/timer-uclass.c | 17 ++++++++++++++--- ?1 file changed, 14 insertions(+), 3 deletions(-)

drivers/timer/timer-uclass.c +0 -0
index f8ddf93..a891a58 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>
?

drivers/timer/timer-uclass.c +13 -3
@@ -42,9 +43,19 @@ 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;
+	ulong ret;
+
+	err = clk_get_by_index(dev, 0, timer_clk);
+	if (!err) {
+		ret = clk_get_rate(timer_clk);
+		if (IS_ERR_VALUE(ret))
+			return ret;
+		uc_priv->clock_rate = ret;
+	} else
+		uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob,
+				dev->of_offset,	"clock-frequency", 0);
Quoted 3 lines

?
? return 0;
?}

Could you please apply this patch if there's no any objections or comments on it? Thanks.

Signature · 2 lines
Best regards,
Vlad Zakharov <[email protected]>
#2 lore raw

PATCH v2 1/1 timer: Support clocks via phandle

Quoted 50 lines · Vlad Zakharov

Hi Tom,

Quoted 47 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.

---
Changes v1..v2:
?- Use temporary variable when getting clock rate

?drivers/timer/timer-uclass.c | 17 ++++++++++++++--- ?1 file changed, 14 insertions(+), 3 deletions(-)

drivers/timer/timer-uclass.c +0 -0
index f8ddf93..a891a58 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>
?

drivers/timer/timer-uclass.c +11 -3
@@ -42,9 +43,19 @@ 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;
+	ulong ret;
+
+	err = clk_get_by_index(dev, 0, timer_clk);
+	if (!err) {
+		ret = clk_get_rate(timer_clk);
+		if (IS_ERR_VALUE(ret))
+			return ret;
+		uc_priv->clock_rate = ret;
+	} else
Quoted 8 lines
Quoted 5 lines
drivers/timer/timer-uclass.c +2 -0
+		uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob,
+				dev->of_offset,	"clock-frequency", 0);

?
? return 0;
?}

Could you please apply this patch if there's no any objections or comments on it? Thanks.

Is this required for the other series? If not, I'd like to let it "bake" a bit longer, but if it's needed, I'm OK with it coming in via the arc tree now as well. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161121/471410be/attachment.sig>
#3 lore raw

PATCH v2 1/1 timer: Support clocks via phandle

Hi again,

Quoted 62 lines · Tom Rini
Quoted 52 lines · Vlad Zakharov

Hi Tom,

Quoted 48 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.

---
Changes v1..v2:
?- Use temporary variable when getting clock rate

?drivers/timer/timer-uclass.c | 17 ++++++++++++++--- ?1 file changed, 14 insertions(+), 3 deletions(-)

drivers/timer/timer-uclass.c +0 -0
index f8ddf93..a891a58 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>
?

drivers/timer/timer-uclass.c +11 -3
@@ -42,9 +43,19 @@ 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;
+	ulong ret;
+
+	err = clk_get_by_index(dev, 0, timer_clk);
+	if (!err) {
+		ret = clk_get_rate(timer_clk);
+		if (IS_ERR_VALUE(ret))
+			return ret;
+		uc_priv->clock_rate = ret;
+	} else
Quoted 8 lines
Quoted 5 lines
drivers/timer/timer-uclass.c +2 -0
+		uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob,
+				dev->of_offset,	"clock-frequency", 0);

?
? return 0;
?}

Could you please apply this patch if there's no any objections or comments on it? Thanks.

Quoted 4 lines

Is this required for the other series???If not, I'd like to let it "bake" a bit longer, but if it's needed, I'm OK with it coming in via the arc tree now as well.??Thanks!

This update is not required for any patch series that have already been sent to mailing list.

Nevertheless this week I am going to send another series that introduces ARC clk driver and uses this driver to get timer clock via the reference in device tree. Therefore current patch will be required for the updates I have just described.

Thanks.

Signature · 2 lines
Best regards,
Vlad Zakharov <[email protected]>
#4 lore raw

PATCH v2 1/1 timer: Support clocks via phandle

In reply to Vlad Zakharov
Quoted 10 lines · Zakharov Vlad

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.

NAK:
sandbox: + sandbox_spl x
+(sandbox_spl) err = clk_get_by_index(dev, 0, timer_clk);
+(sandbox_spl) ^
w+(sandbox_spl) drivers/timer/timer-uclass.c: In function ?timer_pre_probe?:
w+(sandbox_spl) drivers/timer/timer-uclass.c:50:6: warning: ?timer_clk? is used uninitialized in this function [-Wuninitialized]

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161128/e6519008/attachment.sig>