diff mbox series

[U-Boot,1/4] arm: timer: get frequency for arch timer armv7 in cp15 cntfrq

Message ID 1521542486-4827-1-git-send-email-patrick.delaunay@st.com
State Accepted
Commit 46fc679ede5f692a6848f7f4d36f6404c3855971
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/4] arm: timer: get frequency for arch timer armv7 in cp15 cntfrq | expand

Commit Message

Patrick DELAUNAY March 20, 2018, 10:41 a.m. UTC
Manage dynamic value for armv7 arch clock timer,
when CONFIG_SYS_HZ_CLOCK is not defined.
Get frequency from CP15 cntfrq information, initialized for example
by first boot stage, clock driver or by BootRom.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

 arch/arm/cpu/armv7/arch_timer.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Tom Rini April 7, 2018, 1:25 p.m. UTC | #1
On Tue, Mar 20, 2018 at 11:41:23AM +0100, Patrick Delaunay wrote:

> Manage dynamic value for armv7 arch clock timer,
> when CONFIG_SYS_HZ_CLOCK is not defined.
> Get frequency from CP15 cntfrq information, initialized for example
> by first boot stage, clock driver or by BootRom.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/arch/arm/cpu/armv7/arch_timer.c b/arch/arm/cpu/armv7/arch_timer.c
index 545c518..3bcb944 100644
--- a/arch/arm/cpu/armv7/arch_timer.c
+++ b/arch/arm/cpu/armv7/arch_timer.c
@@ -12,12 +12,26 @@ 
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#ifndef CONFIG_SYS_HZ_CLOCK
+static inline u32 read_cntfrq(void)
+{
+	u32 frq;
+
+	asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (frq));
+	return frq;
+}
+#endif
+
 int timer_init(void)
 {
 	gd->arch.tbl = 0;
 	gd->arch.tbu = 0;
 
+#ifdef CONFIG_SYS_HZ_CLOCK
 	gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK;
+#else
+	gd->arch.timer_rate_hz = read_cntfrq();
+#endif
 	return 0;
 }
 
@@ -36,7 +50,7 @@  unsigned long long get_ticks(void)
 
 ulong timer_get_boot_us(void)
 {
-	return lldiv(get_ticks(), CONFIG_SYS_HZ_CLOCK / 1000000);
+	return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000);
 }
 
 ulong get_tbclk(void)