Nomadik: fix reset_timer()
PATCH v2 1/1 Nomadik: fix reset_timer()
From: Alessandro Rubini <[email protected]>
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 <[email protected]>
Acked-by Andrea Gallo <[email protected]>
---
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(-)
cpu/arm926ejs/nomadik/timer.c +7 -7
@@ -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 ) ; }
Signature · 1 line
1.6.0.2