Skip to contentSkip to conversation

timer: sti: mimic Linux declaration and usage

PATCH Superseded Nicolas Heemeryck 3 participants 12 messages Mar 8, 2020 – Mar 19, 2020

lore
Share & tools
lore
#0 lore raw

cover timer: sti: mimic Linux declaration and usage

This series update the sti-timer for cortex-a9 CPU (arm global timer) to mimic the behavior presents in Linux.
Therefor, the same device tree node can be use for U-Boot and Linux.

Nicolas Heemeryck (2):
timer: sti: convert to livetree
timer: sti: use clk API to get timer clock rate

 drivers/timer/sti-timer.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 timer: sti: convert to livetree

Update STI timer to support a live tree

---
 drivers/timer/sti-timer.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/timer/sti-timer.c +3 -6
index 9def7e02f4..eac22ae39b 100644
@@ -6,14 +6,11 @@
 
 #include <common.h>
 #include <dm.h>
-#include <fdtdec.h>
 #include <timer.h>
 
 #include <asm/io.h>
 #include <asm/arch-armv7/globaltimer.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct sti_timer_priv {
 	struct globaltimer *global_timer;
 };
@@ -44,13 +41,13 @@ 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);
-	fdt_addr_t addr;
 
 	uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
 
 	/* get arm global timer base address */
-	addr = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), "reg");
-	priv->global_timer = (struct globaltimer *)addr;
+	priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
+	if (!priv->global_timer)
+		return -ENOENT;
 
 	/* init timer */
 	writel(0x01, &priv->global_timer->ctl);
Signature · 1 line
2.20.1
#2 lore raw

PATCH 1/2 timer: sti: convert to livetree

Hi Nicolas

Quoted 33 lines · Nicolas Heemeryck

Update STI timer to support a live tree

---
 drivers/timer/sti-timer.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/timer/sti-timer.c +0 -4
index 9def7e02f4..eac22ae39b 100644
@@ -6,14 +6,11 @@
 
 #include <common.h>
 #include <dm.h>
-#include <fdtdec.h>
 #include <timer.h>
 
 #include <asm/io.h>
 #include <asm/arch-armv7/globaltimer.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct sti_timer_priv {
 	struct globaltimer *global_timer;
 };
@@ -44,13 +41,13 @@ 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);
-	fdt_addr_t addr;
 
 	uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;

drivers/timer/sti-timer.c static int sti_timer_probe(struct udevice *dev) · line 53

Quoted 10 lines
drivers/timer/sti-timer.c +3 -2
 
 	/* get arm global timer base address */
-	addr = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), "reg");
-	priv->global_timer = (struct globaltimer *)addr;
+	priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
+	if (!priv->global_timer)
+		return -ENOENT;
 
 	/* init timer */
 	writel(0x01, &priv->global_timer->ctl);

Thanks

Patrice

#3 lore raw

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

In reply to Nicolas Heemeryck

Retrieve clock rate through device tree. This mimics the behavior of arm_global_timer in Linux.

---
 drivers/timer/sti-timer.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/timer/sti-timer.c +11 -2
index eac22ae39b..123fac04a9 100644
@@ -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);
 
Signature · 1 line
2.20.1
#4 lore raw

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

Hi Nicolas

Quoted 35 lines · Nicolas Heemeryck

Retrieve clock rate through device tree. This mimics the behavior of arm_global_timer in Linux.

---
 drivers/timer/sti-timer.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/timer/sti-timer.c +4 -2
index eac22ae39b..123fac04a9 100644
@@ -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);

drivers/timer/sti-timer.c static int sti_timer_probe(struct udevice *dev) · line 63

Quoted 10 lines
drivers/timer/sti-timer.c +7 -0
+	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);
 

Nack, for STi board, there is no clock driver (all clock are enabled by default).

So clk_get_by_index() will return an error and will avoid timer driver to probe properly.

Thanks

Patrice

#5 lore raw

v2 cover timer: sti: mimic Linux declaration and usage

This series update the sti-timer for cortex-a9 CPU (arm global timer) to mimic the behavior presents in Linux.
Therefor, the same device tree node can be use for U-Boot and Linux.

Changes in v2:

Since some boards do not necessary have a clock driver, fall back on CONFIG_SYS_HZ_CLOCK. This is similar to what we can find on timer-uclass timer_pre_probe function.

Cc Patrice Chotard <[email protected]>

Nicolas Heemeryck (2):
timer: sti: convert to livetree
timer: sti: use clk API to get timer clock rate

 drivers/timer/sti-timer.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
Signature · 1 line
2.20.1
#6 lore raw

PATCH v2 1/2 timer: sti: convert to livetree

Update STI timer to support a live tree

---

Changes for v2: None

---
 drivers/timer/sti-timer.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/timer/sti-timer.c +3 -6
index 9def7e02f4..eac22ae39b 100644
@@ -6,14 +6,11 @@
 
 #include <common.h>
 #include <dm.h>
-#include <fdtdec.h>
 #include <timer.h>
 
 #include <asm/io.h>
 #include <asm/arch-armv7/globaltimer.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct sti_timer_priv {
 	struct globaltimer *global_timer;
 };
@@ -44,13 +41,13 @@ 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);
-	fdt_addr_t addr;
 
 	uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
 
 	/* get arm global timer base address */
-	addr = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), "reg");
-	priv->global_timer = (struct globaltimer *)addr;
+	priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
+	if (!priv->global_timer)
+		return -ENOENT;
 
 	/* init timer */
 	writel(0x01, &priv->global_timer->ctl);
Signature · 1 line
2.20.1
#7 lore raw

PATCH v2 1/2 timer: sti: convert to livetree

Hi Nicolas

Quoted 38 lines · Nicolas Heemeryck

Update STI timer to support a live tree

---

Changes for v2: None

---
 drivers/timer/sti-timer.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/timer/sti-timer.c +0 -4
index 9def7e02f4..eac22ae39b 100644
@@ -6,14 +6,11 @@
 
 #include <common.h>
 #include <dm.h>
-#include <fdtdec.h>
 #include <timer.h>
 
 #include <asm/io.h>
 #include <asm/arch-armv7/globaltimer.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct sti_timer_priv {
 	struct globaltimer *global_timer;
 };
@@ -44,13 +41,13 @@ 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);
-	fdt_addr_t addr;
 
 	uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;

drivers/timer/sti-timer.c static int sti_timer_probe(struct udevice *dev) · line 53

Quoted 10 lines
drivers/timer/sti-timer.c +3 -2
 
 	/* get arm global timer base address */
-	addr = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), "reg");
-	priv->global_timer = (struct globaltimer *)addr;
+	priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
+	if (!priv->global_timer)
+		return -ENOENT;
 
 	/* init timer */
 	writel(0x01, &priv->global_timer->ctl);

Thanks

Patrice

#9 lore raw

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

In reply to Nicolas Heemeryck

Retrieve clock rate through device tree. This mimics the behavior of arm_global_timer in Linux.

---

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(-)
drivers/timer/sti-timer.c +15 -2
index eac22ae39b..ff42056abd 100644
@@ -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);
 
Signature · 1 line
2.20.1
#10 lore raw

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

Hi Nicolas

Quoted 48 lines · Nicolas Heemeryck

Retrieve clock rate through device tree. This mimics the behavior of arm_global_timer in Linux.

---

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(-)
drivers/timer/sti-timer.c +8 -2
index eac22ae39b..ff42056abd 100644
@@ -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);

drivers/timer/sti-timer.c static int sti_timer_probe(struct udevice *dev) · line 67

Quoted 10 lines
drivers/timer/sti-timer.c +7 -0
+		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);
 

Thanks

Patrice