public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] OMAP[34]: fix broken timer
@ 2010-12-28  0:33 John Rigby
  2011-06-28  5:43 ` Igor Grinberg
  2011-06-29  6:35 ` Albert ARIBAUD
  0 siblings, 2 replies; 3+ messages in thread
From: John Rigby @ 2010-12-28  0:33 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: John Rigby <john.rigby@linaro.org>
---
 arch/arm/cpu/armv7/omap-common/timer.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/armv7/omap-common/timer.c b/arch/arm/cpu/armv7/omap-common/timer.c
index 9beebb1..59bbca8 100644
--- a/arch/arm/cpu/armv7/omap-common/timer.c
+++ b/arch/arm/cpu/armv7/omap-common/timer.c
@@ -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;
-- 
1.7.3.1.120.g38a18

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] OMAP[34]: fix broken timer
  2010-12-28  0:33 [U-Boot] [PATCH] OMAP[34]: fix broken timer John Rigby
@ 2011-06-28  5:43 ` Igor Grinberg
  2011-06-29  6:35 ` Albert ARIBAUD
  1 sibling, 0 replies; 3+ messages in thread
From: Igor Grinberg @ 2011-06-28  5:43 UTC (permalink / raw)
  To: u-boot

Sandeep, Albert,


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


Thanks


On 12/28/10 02:33, John Rigby wrote:

> 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.
>
> Signed-off-by: John Rigby <john.rigby@linaro.org>

Tested-by: Igor Grinberg <grinberg@compulab.co.il>

On DM3730, AM3703, OMAP3530.

> ---
>  arch/arm/cpu/armv7/omap-common/timer.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm/cpu/armv7/omap-common/timer.c b/arch/arm/cpu/armv7/omap-common/timer.c
> index 9beebb1..59bbca8 100644
> --- a/arch/arm/cpu/armv7/omap-common/timer.c
> +++ b/arch/arm/cpu/armv7/omap-common/timer.c
> @@ -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;

-- 
Regards,
Igor.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] OMAP[34]: fix broken timer
  2010-12-28  0:33 [U-Boot] [PATCH] OMAP[34]: fix broken timer John Rigby
  2011-06-28  5:43 ` Igor Grinberg
@ 2011-06-29  6:35 ` Albert ARIBAUD
  1 sibling, 0 replies; 3+ messages in thread
From: Albert ARIBAUD @ 2011-06-29  6:35 UTC (permalink / raw)
  To: u-boot

Hi John,

Le 28/12/2010 01:33, John Rigby a ?crit :
> 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.
>
> Signed-off-by: John Rigby<john.rigby@linaro.org>

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

Amicalement,
-- 
Albert.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-29  6:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-28  0:33 [U-Boot] [PATCH] OMAP[34]: fix broken timer John Rigby
2011-06-28  5:43 ` Igor Grinberg
2011-06-29  6:35 ` Albert ARIBAUD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox