
From: Rob Herring rob.herring@calxeda.com
Implement a default __udelay using get_tbclk and get_ticks.
Signed-off-by: Rob Herring rob.herring@calxeda.com --- lib/time.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/lib/time.c b/lib/time.c index 68b8ff4..55f05bb 100644 --- a/lib/time.c +++ b/lib/time.c @@ -7,11 +7,32 @@
#include <common.h> #include <watchdog.h> +#include <div64.h>
#ifndef CONFIG_WD_PERIOD # define CONFIG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default*/ #endif
+static unsigned long long usec_to_tick(unsigned long usec) +{ + unsigned long long tick = usec * get_tbclk(); + usec *= get_tbclk(); + do_div(tick, 1000000); + return tick; +} + +void __weak __udelay(unsigned long usec) +{ + unsigned long long tmp; + ulong tmo; + + tmo = usec_to_tick(usec); + tmp = get_ticks() + tmo; /* get current timestamp */ + + while (get_ticks() < tmp) /* loop till event */ + /*NOP*/; +} + /* ------------------------------------------------------------------------- */
void udelay(unsigned long usec)