* [U-Boot] [PATCH] davinci: Rewrite timer.c to use tbl/tbu emulation variables in gd
@ 2010-12-02 13:57 Nick Thompson
2010-12-02 14:18 ` Ben Gardiner
2010-12-03 8:59 ` Sudhakar Rajashekhara
0 siblings, 2 replies; 4+ messages in thread
From: Nick Thompson @ 2010-12-02 13:57 UTC (permalink / raw)
To: u-boot
This change allows the davinci timer functions to be used before
relocation since it avoids using static variables prior to BSS being
made available.
The code is based on that used in the at91 timers, modified to use
a davinci specific hardware timer. It also maintains reset_timer()
to allow deprecated timer usage to continue to work (for example,
in nand_base.c)
Signed-off-by: Nick Thompson <nick.thompson@ge.com>
---
This patch relies on http://patchwork.ozlabs.org/patch/73758/ which has not been
accepted yet. I have made a comment on it, suggesting that it should be changed:
http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/90040/focus=90162
arch/arm/cpu/arm926ejs/davinci/timer.c | 77 ++++++++++++--------------------
1 files changed, 28 insertions(+), 49 deletions(-)
diff --git a/arch/arm/cpu/arm926ejs/davinci/timer.c b/arch/arm/cpu/arm926ejs/davinci/timer.c
index 9da7443..bfc6b40 100644
--- a/arch/arm/cpu/arm926ejs/davinci/timer.c
+++ b/arch/arm/cpu/arm926ejs/davinci/timer.c
@@ -40,6 +40,8 @@
#include <common.h>
#include <asm/io.h>
+DECLARE_GLOBAL_DATA_PTR;
+
struct davinci_timer {
u_int32_t pid12;
u_int32_t emumgt;
@@ -57,11 +59,9 @@ struct davinci_timer {
static struct davinci_timer * const timer =
(struct davinci_timer *)CONFIG_SYS_TIMERBASE;
-#define TIMER_LOAD_VAL (CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ)
-#define TIM_CLK_DIV 16
+#define TIMER_LOAD_VAL 0xffffffff
-static ulong timestamp;
-static ulong lastinc;
+#define TIM_CLK_DIV 16
int timer_init(void)
{
@@ -71,72 +71,51 @@ int timer_init(void)
writel(0x06 | ((TIM_CLK_DIV - 1) << 8), &timer->tgcr);
writel(0x0, &timer->tim34);
writel(TIMER_LOAD_VAL, &timer->prd34);
- lastinc = 0;
- timestamp = 0;
writel(2 << 22, &timer->tcr);
+ gd->timer_rate_hz = CONFIG_SYS_HZ_CLOCK / TIM_CLK_DIV;
+ gd->timer_reset_value = 0;
return(0);
}
void reset_timer(void)
{
- writel(0x0, &timer->tcr);
- writel(0x0, &timer->tim34);
- lastinc = 0;
- timestamp = 0;
- writel(2 << 22, &timer->tcr);
+ gd->timer_reset_value = get_ticks();
}
-static ulong get_timer_raw(void)
+/*
+ * Get the current 64 bit timer tick count
+ */
+unsigned long long get_ticks(void)
{
- ulong now = readl(&timer->tim34);
-
- if (now >= lastinc) {
- /* normal mode */
- timestamp += now - lastinc;
- } else {
- /* overflow ... */
- timestamp += now + TIMER_LOAD_VAL - lastinc;
- }
- lastinc = now;
- return timestamp;
+ unsigned long now = readl(&timer->tim34);
+
+ /* increment tbu if tbl has rolled over */
+ if (now < gd->tbl)
+ gd->tbu++;
+ gd->tbl = now;
+
+ return (((unsigned long long)gd->tbu) << 32) | gd->tbl;
}
ulong get_timer(ulong base)
{
- return((get_timer_raw() / (TIMER_LOAD_VAL / TIM_CLK_DIV)) - base);
-}
+ unsigned long long timer_diff;
-void set_timer(ulong t)
-{
- timestamp = t;
+ timer_diff = get_ticks() - gd->timer_reset_value;
+
+ return (timer_diff / (gd->timer_rate_hz / CONFIG_SYS_HZ)) - base;
}
void __udelay(unsigned long usec)
{
- ulong tmo;
- ulong endtime;
- signed long diff;
-
- tmo = CONFIG_SYS_HZ_CLOCK / 1000;
- tmo *= usec;
- tmo /= (1000 * TIM_CLK_DIV);
-
- endtime = get_timer_raw() + tmo;
+ unsigned long long endtime;
- do {
- ulong now = get_timer_raw();
- diff = endtime - now;
- } while (diff >= 0);
-}
+ endtime = ((unsigned long long )usec * gd->timer_rate_hz) / 1000000UL;
+ endtime += get_ticks();
-/*
- * This function is derived from PowerPC code (read timebase as long long).
- * On ARM it just returns the timer value.
- */
-unsigned long long get_ticks(void)
-{
- return(get_timer(0));
+ while (get_ticks() < endtime)
+ ;
}
/*
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] davinci: Rewrite timer.c to use tbl/tbu emulation variables in gd
2010-12-02 13:57 [U-Boot] [PATCH] davinci: Rewrite timer.c to use tbl/tbu emulation variables in gd Nick Thompson
@ 2010-12-02 14:18 ` Ben Gardiner
2010-12-02 14:37 ` Nick Thompson
2010-12-03 8:59 ` Sudhakar Rajashekhara
1 sibling, 1 reply; 4+ messages in thread
From: Ben Gardiner @ 2010-12-02 14:18 UTC (permalink / raw)
To: u-boot
Hi Nick,
On Thu, Dec 2, 2010 at 8:57 AM, Nick Thompson <nick.thompson@ge.com> wrote:
> This change allows the davinci timer functions to be used before
> relocation since it avoids using static variables prior to BSS being
> made available.
>
> The code is based on that used in the at91 timers, modified to use
> a davinci specific hardware timer. It also maintains reset_timer()
> to allow deprecated timer usage to continue to work (for example,
> in nand_base.c)
>
> Signed-off-by: Nick Thompson <nick.thompson@ge.com>
> ---
> This patch relies on http://patchwork.ozlabs.org/patch/73758/ which has not been
> accepted yet. I have made a comment on it, suggesting that it should be changed:
> http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/90040/focus=90162
>
> ?arch/arm/cpu/arm926ejs/davinci/timer.c | ? 77 ++++++++++++--------------------
> ?1 files changed, 28 insertions(+), 49 deletions(-)
Applies cleanly to v2010.12-rc2 on top of
http://patchwork.ozlabs.org/patch/73758/
Tested on da850evm w/o any config changes. This fixes the freeze on
boot: 10/10 times.
You're awesome, Nick!
Tested-by: Ben Gardiner <bengardiner@nanometrics.ca>
> diff --git a/arch/arm/cpu/arm926ejs/davinci/timer.c b/arch/arm/cpu/arm926ejs/davinci/timer.c
> [...]
> ?void __udelay(unsigned long usec)
> ?{
> - ? ? ? ulong tmo;
> - ? ? ? ulong endtime;
> - ? ? ? signed long diff;
> -
> - ? ? ? tmo = CONFIG_SYS_HZ_CLOCK / 1000;
> - ? ? ? tmo *= usec;
> - ? ? ? tmo /= (1000 * TIM_CLK_DIV);
> -
> - ? ? ? endtime = get_timer_raw() + tmo;
> + ? ? ? unsigned long long endtime;
>
> - ? ? ? do {
> - ? ? ? ? ? ? ? ulong now = get_timer_raw();
> - ? ? ? ? ? ? ? diff = endtime - now;
> - ? ? ? } while (diff >= 0);
> -}
> + ? ? ? endtime = ((unsigned long long )usec * gd->timer_rate_hz) / 1000000UL;
just one minor checkpatch.pl warning; should be (unsigned long long)
-- no space before ')'
Best Regards,
Ben Gardiner
---
Nanometrics Inc.
http://www.nanometrics.ca
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] davinci: Rewrite timer.c to use tbl/tbu emulation variables in gd
2010-12-02 14:18 ` Ben Gardiner
@ 2010-12-02 14:37 ` Nick Thompson
0 siblings, 0 replies; 4+ messages in thread
From: Nick Thompson @ 2010-12-02 14:37 UTC (permalink / raw)
To: u-boot
On 02/12/10 14:18, Ben Gardiner wrote:
> Hi Nick,
>
> On Thu, Dec 2, 2010 at 8:57 AM, Nick Thompson <nick.thompson@ge.com> wrote:
>> This change allows the davinci timer functions to be used before
>> relocation since it avoids using static variables prior to BSS being
>> made available.
>> Signed-off-by: Nick Thompson <nick.thompson@ge.com>
>> ---
>> This patch relies on http://patchwork.ozlabs.org/patch/73758/ which has not been
>> accepted yet. I have made a comment on it, suggesting that it should be changed:
>> http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/90040/focus=90162
>
> Applies cleanly to v2010.12-rc2 on top of
> http://patchwork.ozlabs.org/patch/73758/
>
> Tested on da850evm w/o any config changes. This fixes the freeze on
> boot: 10/10 times.
>
> You're awesome, Nick!
>
> Tested-by: Ben Gardiner <bengardiner@nanometrics.ca>
I thought it sounded like the problem you where having. Glad it helps.
Thanks for the Tested-by.
>> + endtime = ((unsigned long long )usec * gd->timer_rate_hz) / 1000000UL;
>
> just one minor checkpatch.pl warning; should be (unsigned long long)
> -- no space before ')'
Good spot. I've fixed that locally and will submit a v2 if the depending
patch finds favour - Alternative approaches have been suggested, this one
is *my* short-term favourite.
Thanks,
Nick.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] davinci: Rewrite timer.c to use tbl/tbu emulation variables in gd
2010-12-02 13:57 [U-Boot] [PATCH] davinci: Rewrite timer.c to use tbl/tbu emulation variables in gd Nick Thompson
2010-12-02 14:18 ` Ben Gardiner
@ 2010-12-03 8:59 ` Sudhakar Rajashekhara
1 sibling, 0 replies; 4+ messages in thread
From: Sudhakar Rajashekhara @ 2010-12-03 8:59 UTC (permalink / raw)
To: u-boot
Hi Nick,
On Thu, Dec 02, 2010 at 19:27:24, Nick Thompson wrote:
> This change allows the davinci timer functions to be used before
> relocation since it avoids using static variables prior to BSS being
> made available.
>
> The code is based on that used in the at91 timers, modified to use
> a davinci specific hardware timer. It also maintains reset_timer()
> to allow deprecated timer usage to continue to work (for example,
> in nand_base.c)
>
> Signed-off-by: Nick Thompson <nick.thompson@ge.com>
> ---
> This patch relies on http://patchwork.ozlabs.org/patch/73758/ which has not been
> accepted yet. I have made a comment on it, suggesting that it should be changed:
> http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/90040/focus=90162
>
> arch/arm/cpu/arm926ejs/davinci/timer.c | 77 ++++++++++++--------------------
> 1 files changed, 28 insertions(+), 49 deletions(-)
>
I applied this patch on top of http://patchwork.ozlabs.org/patch/73758/
and tested on DM365 without any config changes. Now the board boots fine
without any hang.
Tested-by: Sudhakar Rajashekhara <sudhakar.raj@ti.com>
Thanks,
Sudhakar
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-12-03 8:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-02 13:57 [U-Boot] [PATCH] davinci: Rewrite timer.c to use tbl/tbu emulation variables in gd Nick Thompson
2010-12-02 14:18 ` Ben Gardiner
2010-12-02 14:37 ` Nick Thompson
2010-12-03 8:59 ` Sudhakar Rajashekhara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox