]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - lib/time.c
Merge tag 'xilinx-fixes-for-v2017.11' of git://www.denx.de/git/u-boot-microblaze
[people/ms/u-boot.git] / lib / time.c
index e9f6861b9843773f780ec3bd278340dcb55a2a2e..aed1a091f27971a6aa0004b4c671f4c5c2069294 100644 (file)
@@ -36,6 +36,23 @@ unsigned long notrace timer_read_counter(void)
        return readl(CONFIG_SYS_TIMER_COUNTER);
 #endif
 }
+
+ulong timer_get_boot_us(void)
+{
+       ulong count = timer_read_counter();
+
+#if CONFIG_SYS_TIMER_RATE == 1000000
+       return count;
+#elif CONFIG_SYS_TIMER_RATE > 1000000
+       return lldiv(count, CONFIG_SYS_TIMER_RATE / 1000000);
+#elif defined(CONFIG_SYS_TIMER_RATE)
+       return (unsigned long long)count * 1000000 / CONFIG_SYS_TIMER_RATE;
+#else
+       /* Assume the counter is in microseconds */
+       return count;
+#endif
+}
+
 #else
 extern unsigned long __weak timer_read_counter(void);
 #endif
@@ -43,11 +60,17 @@ extern unsigned long __weak timer_read_counter(void);
 #ifdef CONFIG_TIMER
 ulong notrace get_tbclk(void)
 {
-       int ret;
+       if (!gd->timer) {
+#ifdef CONFIG_TIMER_EARLY
+               return timer_early_get_rate();
+#else
+               int ret;
 
-       ret = dm_timer_init();
-       if (ret)
-               return ret;
+               ret = dm_timer_init();
+               if (ret)
+                       return ret;
+#endif
+       }
 
        return timer_get_rate(gd->timer);
 }
@@ -57,9 +80,17 @@ uint64_t notrace get_ticks(void)
        u64 count;
        int ret;
 
-       ret = dm_timer_init();
-       if (ret)
-               return ret;
+       if (!gd->timer) {
+#ifdef CONFIG_TIMER_EARLY
+               return timer_early_get_count();
+#else
+               int ret;
+
+               ret = dm_timer_init();
+               if (ret)
+                       return ret;
+#endif
+       }
 
        ret = timer_get_count(gd->timer, &count);
        if (ret)
@@ -140,9 +171,3 @@ void udelay(unsigned long usec)
                usec -= kv;
        } while(usec);
 }
-
-void mdelay(unsigned long msec)
-{
-       while (msec--)
-               udelay(1000);
-}