X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Ftime.c;h=aed1a091f27971a6aa0004b4c671f4c5c2069294;hb=7f586d6fc4f048a9a334d4513a7a7ea40750831b;hp=e9f6861b9843773f780ec3bd278340dcb55a2a2e;hpb=c8336975381d481829e3e6a81c38cd118826ca03;p=oweals%2Fu-boot.git diff --git a/lib/time.c b/lib/time.c index e9f6861b98..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 @@ -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); -}