[U-Boot] [PATCH] ppc: Increase precision of ticks2usec

Benoit Monin benoit.monin at laposte.net
Wed Mar 4 17:08:47 CET 2009


The tick of some PowerPC cpu is running at high frequency and
it can be used to get microsecond precision from it. Make use
of div64 to achieve this precision in ticks2usec.

Signed-off-by: Benoît Monin <bmonin at adeneo.eu>
---
 lib_ppc/time.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/lib_ppc/time.c b/lib_ppc/time.c
index 173ffab..ebda13a 100644
--- a/lib_ppc/time.c
+++ b/lib_ppc/time.c
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <div64.h>
 
 #ifndef CONFIG_WD_PERIOD
 # define CONFIG_WD_PERIOD	(10 * 1000 * 1000)	/* 10 seconds default*/
@@ -71,17 +72,11 @@ void udelay(unsigned long usec)
 unsigned long ticks2usec(unsigned long ticks)
 {
 	ulong tbclk = get_tbclk();
+	u64 tmp;
 
-	/* usec = ticks * 1000000 / tbclk
-	 * Multiplication would overflow at ~4.2e3 ticks,
-	 * so we break it up into
-	 * usec = ( ( ticks * 1000) / tbclk ) * 1000;
-	 */
-	ticks *= 1000L;
-	ticks /= tbclk;
-	ticks *= 1000L;
-
-	return ((ulong)ticks);
+	tmp = ticks * 1000000ULL;
+	do_div (tmp, tbclk);
+	return (unsigned long)tmp;
 }
 #endif
 /* ------------------------------------------------------------------------- */
-- 


 Créez votre adresse électronique prenom.nom at laposte.net 
 1 Go d'espace de stockage, anti-spam et anti-virus intégrés.


More information about the U-Boot mailing list