X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Ftime.c;h=9c55da6f1b3914adde3bf67107896a962bc29d44;hb=399a39e34af00e7342406405dc0300da0557277b;hp=3c49243e6a1ee0f3c7f95d73e9b081581e44be36;hpb=f253f2933b7373556329c0174dd5b101039a4056;p=oweals%2Fu-boot.git diff --git a/lib/time.c b/lib/time.c index 3c49243e6a..9c55da6f1b 100644 --- a/lib/time.c +++ b/lib/time.c @@ -1,8 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -36,11 +35,28 @@ 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 -#ifdef CONFIG_TIMER +#if CONFIG_IS_ENABLED(TIMER) ulong notrace get_tbclk(void) { if (!gd->timer) {