diff mbox

[U-Boot,01/15] bootstage: Provide a default timer function

Message ID 20170522110536.6231-2-sjg@chromium.org
State Accepted
Commit 9fb34b01f7757ed772b77dd90e463c6e7499fef8
Delegated to: Tom Rini
Headers show

Commit Message

Simon Glass May 22, 2017, 11:05 a.m. UTC
If CONFIG_SYS_TIMER_COUNTER is used we can provide a default microsecond
timer implementation.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/time.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Tom Rini June 6, 2017, 12:21 a.m. UTC | #1
On Mon, May 22, 2017 at 05:05:22AM -0600, Simon Glass wrote:

> If CONFIG_SYS_TIMER_COUNTER is used we can provide a default microsecond
> timer implementation.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

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

Patch

diff --git a/lib/time.c b/lib/time.c
index 3c49243e6a..aed1a091f2 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