From: Rob Herring <rob.herr...@calxeda.com>

Implement a default __udelay using get_tbclk and get_ticks.

Signed-off-by: Rob Herring <rob.herr...@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)
-- 
1.8.1.2

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to