arm: timer: get frequency for arch timer armv7 in cp15 cntfrq
authorPatrick Delaunay <patrick.delaunay@st.com>
Tue, 20 Mar 2018 10:41:23 +0000 (11:41 +0100)
committerTom Rini <trini@konsulko.com>
Sat, 7 Apr 2018 00:45:28 +0000 (20:45 -0400)
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

index 545c5185066bd4b90033be7097a311cf7db0badc..3bcb944ec415972a26e843a6ddb882d91eb40a8f 100644 (file)
 
 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)