
Description:
When CONFIG_TIMER_EARLY is selected only the timer_early_* functions will be called. With this patch first gd->timer will be checked, if the DM timer is available, it uses the DM timer. When gd->timer is empty, the timer_early_* functions will be called.
Signed-off-by: Johannes Krottmayer krjdev@gmail.com Cc: Tom Rini trini@konsulko.com --- lib/time.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-)
diff --git a/lib/time.c b/lib/time.c index 96074b84af..85803d8ff5 100644 --- a/lib/time.c +++ b/lib/time.c @@ -5,7 +5,6 @@ */
#include <common.h> -#include <clock_legacy.h> #include <bootstage.h> #include <dm.h> #include <errno.h> @@ -66,17 +65,22 @@ extern unsigned long __weak timer_read_counter(void); #if CONFIG_IS_ENABLED(TIMER) ulong notrace get_tbclk(void) { - if (!gd->timer) { + int ret; + #ifdef CONFIG_TIMER_EARLY + if (!gd->timer) return timer_early_get_rate(); + + ret = dm_timer_init(); + + if (ret) + return ret; #else - int ret; + ret = dm_timer_init();
- ret = dm_timer_init(); - if (ret) - return ret; + if (ret) + return ret; #endif - }
return timer_get_rate(gd->timer); } @@ -86,19 +90,32 @@ uint64_t notrace get_ticks(void) u64 count; int ret;
- if (!gd->timer) { #ifdef CONFIG_TIMER_EARLY + if (!gd->timer) return timer_early_get_count(); -#else - int ret;
- ret = dm_timer_init(); - if (ret) - panic("Could not initialize timer (err %d)\n", ret); -#endif + ret = dm_timer_init(); + + if (ret) + panic("Could not initialize timer (err %d)\n", ret); + + ret = timer_get_count(gd->timer, &count); + + if (ret) { + if (spl_phase() > PHASE_TPL) + panic("Could not read count from timer (err %d)\n", + ret); + else + panic("no timer (err %d)\n", ret); } +#else + ret = dm_timer_init(); + + if (ret) + panic("Could not initialize timer (err %d)\n", ret);
ret = timer_get_count(gd->timer, &count); + if (ret) { if (spl_phase() > PHASE_TPL) panic("Could not read count from timer (err %d)\n", @@ -106,6 +123,7 @@ uint64_t notrace get_ticks(void) else panic("no timer (err %d)\n", ret); } +#endif
return count; }