Merge branch 'master' of git://git.denx.de/u-boot-sh
[platform/kernel/u-boot.git] / arch / arm / cpu / armv7 / arch_timer.c
index 0588e2b..5de6305 100644 (file)
@@ -1,23 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2012-2014
  *     Texas Instruments Incorporated, <www.ti.com>
- *
- * SPDX-License-Identifier:     GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/io.h>
 #include <div64.h>
+#include <bootstage.h>
 
 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;
 
-       gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ;
-
+#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;
 }
 
@@ -34,22 +47,12 @@ unsigned long long get_ticks(void)
 }
 
 
-ulong get_timer(ulong base)
+ulong timer_get_boot_us(void)
 {
-       return lldiv(get_ticks(), gd->arch.timer_rate_hz) - base;
-}
-
-void __udelay(unsigned long usec)
-{
-       unsigned long long endtime;
-
-       endtime = lldiv((unsigned long long)usec * gd->arch.timer_rate_hz,
-                       1000UL);
-
-       endtime += get_ticks();
+       if (!gd->arch.timer_rate_hz)
+               timer_init();
 
-       while (get_ticks() < endtime)
-               ;
+       return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000);
 }
 
 ulong get_tbclk(void)