Patchwork [U-Boot,3/9] time: create default __udelay

login
register
mail settings
Submitter Rob Herring
Date Sept. 8, 2013, 8:12 p.m.
Message ID <1378671174-18535-4-git-send-email-robherring2@gmail.com>
Download mbox | patch
Permalink /patch/273463/
State Superseded
Delegated to: Tom Rini
Headers show

Comments

Rob Herring - Sept. 8, 2013, 8:12 p.m.
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(+)

Patch

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)