public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alessandro Rubini <rubini-list@gnudd.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2] Nomadik: fix reset_timer()
Date: Fri, 6 Nov 2009 09:12:01 +0100	[thread overview]
Message-ID: <20091106081201.GA11903@mail.gnudd.com> (raw)

From: Alessandro Rubini <rubini@unipv.it>

Previously the code wrote 0 to reset the counter and used
negation to read an increasing value from the register. However,
a readback before 400us still returned 0, which was reported
as 1780 seconds, thus nand failed to work any now and then.
As suggested by Wolfgang Denk, this changes READ_TIMER to
just return the hardware counter (a declerasing one) and changes
code using the value.  Compile-tested only, at this point.

Signed-off-by: Alessandro Rubini <rubini@unipv.it>
Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
---

Please note that V3 is being posted at the same time. I prefer
V3 to this V2, but V2 is how I've been asked to do things.

 cpu/arm926ejs/nomadik/timer.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/cpu/arm926ejs/nomadik/timer.c b/cpu/arm926ejs/nomadik/timer.c
index 16067c9..c7dd65d 100644
--- a/cpu/arm926ejs/nomadik/timer.c
+++ b/cpu/arm926ejs/nomadik/timer.c
@@ -34,8 +34,8 @@
 #define TICKS_PER_HZ		(TIMER_CLOCK / CONFIG_SYS_HZ)
 #define TICKS_TO_HZ(x)		((x) / TICKS_PER_HZ)
 
-/* macro to read the 32 bit timer: since it decrements, we invert read value */
-#define READ_TIMER() (~readl(CONFIG_SYS_TIMERBASE + MTU_VAL(0)))
+/* macro to read the 32 bit timer: note however that the count decreases */
+#define READ_TIMER() readl(CONFIG_SYS_TIMERBASE + MTU_VAL(0))
 
 /* Configure a free-running, auto-wrap counter with no prescaler */
 int timer_init(void)
@@ -46,7 +46,7 @@ int timer_init(void)
 	return 0;
 }
 
-/* Restart counting from 0 */
+/* Restart counting from 0 (still, it is a decrementing counter) */
 void reset_timer(void)
 {
 	writel(0, CONFIG_SYS_TIMERBASE + MTU_LR(0)); /* Immediate effect */
@@ -55,7 +55,7 @@ void reset_timer(void)
 /* Return how many HZ passed since "base" */
 ulong get_timer(ulong base)
 {
-	return  TICKS_TO_HZ(READ_TIMER()) - base;
+	return  TICKS_TO_HZ(-READ_TIMER()) - base;
 }
 
 /* Delay x useconds */
@@ -63,8 +63,8 @@ void udelay(unsigned long usec)
 {
 	ulong ini, end;
 
-	ini = READ_TIMER();
-	end = ini + USEC_TO_COUNT(usec);
-	while ((signed)(end - READ_TIMER()) > 0)
+	ini = READ_TIMER(); /* decrementing value */
+	end = ini - USEC_TO_COUNT(usec);
+	while ((signed)(READ_TIMER() - end) > 0)
 		;
 }
-- 
1.6.0.2

                 reply	other threads:[~2009-11-06  8:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20091106081201.GA11903@mail.gnudd.com \
    --to=rubini-list@gnudd.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox