summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-05-22 11:05:22 (GMT)
committerTom Rini <trini@konsulko.com>2017-06-05 18:13:03 (GMT)
commit9fb34b01f7757ed772b77dd90e463c6e7499fef8 (patch)
tree7b96448ed63e93432c87c282ceb95063990a0d54 /lib
parent9cb5eaf2cfb7ceb267fc10c743b69a57a1141bf7 (diff)
downloadu-boot-9fb34b01f7757ed772b77dd90e463c6e7499fef8.tar.xz
bootstage: Provide a default timer function
If CONFIG_SYS_TIMER_COUNTER is used we can provide a default microsecond timer implementation. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/time.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/time.c b/lib/time.c
index 3c49243..aed1a09 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -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