diff mbox

[U-Boot,3/5] dm: x86: Update timer_get_boot_us to work before DM is ready

Message ID 20170715234120.177264-4-sjg@chromium.org
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Simon Glass July 15, 2017, 11:41 p.m. UTC
Use the new separate init function so that we can make use of the timer
before driver model is started up.

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

 drivers/timer/tsc_timer.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/drivers/timer/tsc_timer.c b/drivers/timer/tsc_timer.c
index 9f1cfb1242..91e5cb11c1 100644
--- a/drivers/timer/tsc_timer.c
+++ b/drivers/timer/tsc_timer.c
@@ -301,11 +301,6 @@  ulong notrace timer_get_us(void)
 	return get_ticks() / get_tbclk_mhz();
 }
 
-ulong timer_get_boot_us(void)
-{
-	return timer_get_us();
-}
-
 void __udelay(unsigned long usec)
 {
 	u64 now = get_ticks();
@@ -368,6 +363,21 @@  static int tsc_timer_probe(struct udevice *dev)
 	return 0;
 }
 
+ulong timer_get_boot_us(void)
+{
+	if (!gd->timer) {
+		u64 now_tick;
+
+		tsc_timer_ensure_setup();
+		now_tick = rdtsc();
+
+		now_tick -= gd->arch.tsc_base;
+		return now_tick / (gd->arch.clock_rate / 1000000);
+	}
+
+	return timer_get_us();
+}
+
 static const struct timer_ops tsc_timer_ops = {
 	.get_count = tsc_timer_get_count,
 };