Skip to contentSkip to conversation

OMAP[34]: fix broken timer

PATCH New John Rigby 3 participants 3 messages Dec 28, 2010 – Jun 29, 2011 Arm (32-bit)

lore
Share & tools
lore

John Rigby

author
#0 lore raw

PATCH 1/1 OMAP[34]: fix broken timer

As implemented now the timer used to implement __udelay counts to 0xffffffff and then gets stuck there because the the programmed reload value is 0xffffffff. This value is not only wrong but illegal according to the reference manual.

One can reproduce the bug by leaving a board at the u-boot prompt for sometime then issuing a sleep command. The sleep will hang forever.

The timer is a count up timer that reloads as it rolls over from 0xffffffff so the correct load value is 0.

Change TIMER_LOAD_VAL from 0xffffffff to 0 and introduce a new constant called TIMER_OVERFLOW_VAL set to 0xffffffff.

---
 arch/arm/cpu/armv7/omap-common/timer.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/arm/cpu/armv7/omap-common/timer.c +4 -3
index 9beebb1..59bbca8 100644
@@ -43,8 +43,9 @@ static struct gptimer *timer_base = (struct gptimer *)CONFIG_SYS_TIMERBASE;
  * Nothing really to do with interrupts, just starts up a counter.
  */
 
-#define TIMER_CLOCK	(V_SCLK / (2 << CONFIG_SYS_PTV))
-#define TIMER_LOAD_VAL	0xffffffff
+#define TIMER_CLOCK		(V_SCLK / (2 << CONFIG_SYS_PTV))
+#define TIMER_OVERFLOW_VAL	0xffffffff
+#define TIMER_LOAD_VAL		0
 
 int timer_init(void)
 {
@@ -86,7 +87,7 @@ void __udelay(unsigned long usec)
 	while (tmo > 0) {
 		now = readl(&timer_base->tcrr);
 		if (last > now) /* count up timer overflow */
-			tmo -= TIMER_LOAD_VAL - last + now;
+			tmo -= TIMER_OVERFLOW_VAL - last + now + 1;
 		else
 			tmo -= now - last;
 		last = now;
Signature · 1 line
1.7.3.1.120.g38a18
#1 lore raw

PATCH 1/1 OMAP[34]: fix broken timer

Sandeep, Albert,

Please, apply this patch. It fixes a real issue with timer on omap.

Thanks

Quoted 9 lines · John Rigby

As implemented now the timer used to implement __udelay counts to 0xffffffff and then gets stuck there because the the programmed reload value is 0xffffffff. This value is not only wrong but illegal according to the reference manual.

One can reproduce the bug by leaving a board at the u-boot prompt for sometime then issuing a sleep command. The sleep will hang forever.

Quoted 7 lines

The timer is a count up timer that reloads as it rolls over from 0xffffffff so the correct load value is 0.

Change TIMER_LOAD_VAL from 0xffffffff to 0 and introduce a new constant called TIMER_OVERFLOW_VAL set to 0xffffffff.

On DM3730, AM3703, OMAP3530.

Quoted 29 lines
---
 arch/arm/cpu/armv7/omap-common/timer.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/arm/cpu/armv7/omap-common/timer.c +4 -3
index 9beebb1..59bbca8 100644
@@ -43,8 +43,9 @@ static struct gptimer *timer_base = (struct gptimer *)CONFIG_SYS_TIMERBASE;
  * Nothing really to do with interrupts, just starts up a counter.
  */
 
-#define TIMER_CLOCK	(V_SCLK / (2 << CONFIG_SYS_PTV))
-#define TIMER_LOAD_VAL	0xffffffff
+#define TIMER_CLOCK		(V_SCLK / (2 << CONFIG_SYS_PTV))
+#define TIMER_OVERFLOW_VAL	0xffffffff
+#define TIMER_LOAD_VAL		0
 
 int timer_init(void)
 {
@@ -86,7 +87,7 @@ void __udelay(unsigned long usec)
 	while (tmo > 0) {
 		now = readl(&timer_base->tcrr);
 		if (last > now) /* count up timer overflow */
-			tmo -= TIMER_LOAD_VAL - last + now;
+			tmo -= TIMER_OVERFLOW_VAL - last + now + 1;
 		else
 			tmo -= now - last;
 		last = now;
Signature · 2 lines
Regards,
Igor.
#2 lore raw

PATCH 1/1 OMAP[34]: fix broken timer

In reply to John Rigby

Hi John,

Le 28/12/2010 01:33, John Rigby a ?crit :

Quoted 9 lines

As implemented now the timer used to implement __udelay counts to 0xffffffff and then gets stuck there because the the programmed reload value is 0xffffffff. This value is not only wrong but illegal according to the reference manual.

One can reproduce the bug by leaving a board at the u-boot prompt for sometime then issuing a sleep command. The sleep will hang forever.

Quoted 7 lines

The timer is a count up timer that reloads as it rolls over from 0xffffffff so the correct load value is 0.

Change TIMER_LOAD_VAL from 0xffffffff to 0 and introduce a new constant called TIMER_OVERFLOW_VAL set to 0xffffffff.

Applied to u-boot-arm/master, thanks.

Amicalement,

Signature · 1 line
Albert.