All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benoit Monin <benoit.monin@laposte.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] ppc: Increase precision of ticks2usec
Date: Wed,  4 Mar 2009 17:08:47 +0100 (CET)	[thread overview]
Message-ID: <9454366.19868.1236182927234.JavaMail.www@wwinf8202> (raw)


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@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.

             reply	other threads:[~2009-03-04 16:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-04 16:08 Benoit Monin [this message]
2009-03-08 22:46 ` [U-Boot] [PATCH] ppc: Increase precision of ticks2usec Wolfgang Denk
  -- strict thread matches above, loose matches on Subject: below --
2009-03-10 14:20 Benoit Monin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9454366.19868.1236182927234.JavaMail.www@wwinf8202 \
    --to=benoit.monin@laposte.net \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.