* [U-Boot] [PATCH 2/4] ep93xx timer: Fix resolution of get_ticks()
[not found] <a41656a7b95f18a5ef51428b285767d0a70cbbc7.1268169068.git.matthias@kaehlcke.net>
@ 2010-03-09 21:13 ` Matthias Kaehlcke
2010-03-09 21:13 ` [U-Boot] [PATCH 3/4] ep93xx timer: Rename struct timer_reg pointers Matthias Kaehlcke
2010-03-09 21:13 ` [U-Boot] [PATCH 4/4] ep93xx timer: refactoring Matthias Kaehlcke
2 siblings, 0 replies; 4+ messages in thread
From: Matthias Kaehlcke @ 2010-03-09 21:13 UTC (permalink / raw)
To: u-boot
ep93xx timer: Make get_ticks() return a value in CONFIG_SYS_HZ resolution,
as announced by get_tbclk()
Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net>
---
cpu/arm920t/ep93xx/timer.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/cpu/arm920t/ep93xx/timer.c b/cpu/arm920t/ep93xx/timer.c
index bc4ec8f..31304b7 100644
--- a/cpu/arm920t/ep93xx/timer.c
+++ b/cpu/arm920t/ep93xx/timer.c
@@ -69,7 +69,7 @@ static inline unsigned long read_timer(void)
}
/*
- * timer without interrupts
+ * Get the number of ticks (in CONFIG_SYS_HZ resolution)
*/
unsigned long long get_ticks(void)
{
@@ -83,12 +83,12 @@ unsigned long long get_ticks(void)
timer.last_update = now;
- return timer.ticks;
+ return clk_to_systicks(timer.ticks);
}
unsigned long get_timer_masked(void)
{
- return clk_to_systicks(get_ticks());
+ return get_ticks();
}
unsigned long get_timer(unsigned long base)
@@ -109,10 +109,13 @@ void reset_timer(void)
void __udelay(unsigned long usec)
{
- const unsigned long target = get_ticks() + usecs_to_ticks(usec);
+ /* read the timer and update timer.ticks */
+ get_ticks();
- while (get_ticks() < target)
- /* noop */;
+ const unsigned long long target = timer.ticks + usecs_to_ticks(usec);
+
+ while (timer.ticks < target)
+ get_ticks();
}
int timer_init(void)
--
1.6.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH 3/4] ep93xx timer: Rename struct timer_reg pointers
[not found] <a41656a7b95f18a5ef51428b285767d0a70cbbc7.1268169068.git.matthias@kaehlcke.net>
2010-03-09 21:13 ` [U-Boot] [PATCH 2/4] ep93xx timer: Fix resolution of get_ticks() Matthias Kaehlcke
@ 2010-03-09 21:13 ` Matthias Kaehlcke
2010-03-09 21:13 ` [U-Boot] [PATCH 4/4] ep93xx timer: refactoring Matthias Kaehlcke
2 siblings, 0 replies; 4+ messages in thread
From: Matthias Kaehlcke @ 2010-03-09 21:13 UTC (permalink / raw)
To: u-boot
ep93xx timer: Renamed pointers to struct timer_regs from name 'timer' to
'timer_regs' in order to avoid confusion with the global variable 'timer'
Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net>
---
cpu/arm920t/ep93xx/timer.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/cpu/arm920t/ep93xx/timer.c b/cpu/arm920t/ep93xx/timer.c
index 31304b7..943f193 100644
--- a/cpu/arm920t/ep93xx/timer.c
+++ b/cpu/arm920t/ep93xx/timer.c
@@ -63,9 +63,9 @@ static inline unsigned long long usecs_to_ticks(unsigned long usecs)
static inline unsigned long read_timer(void)
{
- struct timer_regs *timer = (struct timer_regs *)TIMER_BASE;
+ struct timer_regs *timer_regs = (struct timer_regs *)TIMER_BASE;
- return TIMER_MAX_VAL - readl(&timer->timer3.value);
+ return TIMER_MAX_VAL - readl(&timer_regs->timer3.value);
}
/*
@@ -120,17 +120,17 @@ void __udelay(unsigned long usec)
int timer_init(void)
{
- struct timer_regs *timer = (struct timer_regs *)TIMER_BASE;
+ struct timer_regs *timer_regs = (struct timer_regs *)TIMER_BASE;
/* use timer 3 with 508KHz and free running */
- writel(TIMER_CLKSEL, &timer->timer3.control);
+ writel(TIMER_CLKSEL, &timer_regs->timer3.control);
/* set initial timer value 3 */
- writel(TIMER_MAX_VAL, &timer->timer3.load);
+ writel(TIMER_MAX_VAL, &timer_regs->timer3.load);
/* Enable the timer */
writel(TIMER_ENABLE | TIMER_CLKSEL,
- &timer->timer3.control);
+ &timer_regs->timer3.control);
reset_timer_masked();
--
1.6.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH 4/4] ep93xx timer: refactoring
[not found] <a41656a7b95f18a5ef51428b285767d0a70cbbc7.1268169068.git.matthias@kaehlcke.net>
2010-03-09 21:13 ` [U-Boot] [PATCH 2/4] ep93xx timer: Fix resolution of get_ticks() Matthias Kaehlcke
2010-03-09 21:13 ` [U-Boot] [PATCH 3/4] ep93xx timer: Rename struct timer_reg pointers Matthias Kaehlcke
@ 2010-03-09 21:13 ` Matthias Kaehlcke
2010-03-13 20:32 ` Tom
2 siblings, 1 reply; 4+ messages in thread
From: Matthias Kaehlcke @ 2010-03-09 21:13 UTC (permalink / raw)
To: u-boot
ep93xx timer: Simplified the timer code by eliminating clk_to_systicks() and
performing (almost) all manipulation of the timer structure in read_timer()
Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net>
---
cpu/arm920t/ep93xx/timer.c | 52 ++++++++++++++++++++-----------------------
1 files changed, 24 insertions(+), 28 deletions(-)
diff --git a/cpu/arm920t/ep93xx/timer.c b/cpu/arm920t/ep93xx/timer.c
index 943f193..4a0ce4d 100644
--- a/cpu/arm920t/ep93xx/timer.c
+++ b/cpu/arm920t/ep93xx/timer.c
@@ -1,8 +1,7 @@
/*
* Cirrus Logic EP93xx timer support.
*
- * Copyright (C) 2009, 2010
- * Matthias Kaehlcke <matthias@kaehlcke.net>
+ * Copyright (C) 2009, 2010 Matthias Kaehlcke <matthias@kaehlcke.net>
*
* Copyright (C) 2004, 2005
* Cory T. Tusar, Videon Central, Inc., <ctusar@videon-central.com>
@@ -42,17 +41,9 @@
static struct ep93xx_timer
{
unsigned long long ticks;
- unsigned long last_update;
+ unsigned long last_read;
} timer;
-static inline unsigned long clk_to_systicks(unsigned long long clk_ticks)
-{
- unsigned long long sys_ticks = (clk_ticks * CONFIG_SYS_HZ);
- do_div(sys_ticks, TIMER_FREQ);
-
- return (unsigned long)sys_ticks;
-}
-
static inline unsigned long long usecs_to_ticks(unsigned long usecs)
{
unsigned long long ticks = (unsigned long long)usecs * TIMER_FREQ;
@@ -61,11 +52,18 @@ static inline unsigned long long usecs_to_ticks(unsigned long usecs)
return ticks;
}
-static inline unsigned long read_timer(void)
+static inline void read_timer(void)
{
struct timer_regs *timer_regs = (struct timer_regs *)TIMER_BASE;
+ const unsigned long now = TIMER_MAX_VAL - readl(&timer_regs->timer3.value);
+
+ if (now >= timer.last_read)
+ timer.ticks += now - timer.last_read;
+ else
+ /* an overflow occurred */
+ timer.ticks += TIMER_MAX_VAL - timer.last_read + now;
- return TIMER_MAX_VAL - readl(&timer_regs->timer3.value);
+ timer.last_read = now;
}
/*
@@ -73,17 +71,14 @@ static inline unsigned long read_timer(void)
*/
unsigned long long get_ticks(void)
{
- const unsigned long now = read_timer();
+ unsigned long long sys_ticks;
- if (now >= timer.last_update)
- timer.ticks += now - timer.last_update;
- else
- /* an overflow occurred */
- timer.ticks += TIMER_MAX_VAL - timer.last_update + now;
+ read_timer();
- timer.last_update = now;
+ sys_ticks = timer.ticks * CONFIG_SYS_HZ;
+ do_div(sys_ticks, TIMER_FREQ);
- return clk_to_systicks(timer.ticks);
+ return sys_ticks;
}
unsigned long get_timer_masked(void)
@@ -98,7 +93,7 @@ unsigned long get_timer(unsigned long base)
void reset_timer_masked(void)
{
- timer.last_update = read_timer();
+ read_timer();
timer.ticks = 0;
}
@@ -109,23 +104,24 @@ void reset_timer(void)
void __udelay(unsigned long usec)
{
- /* read the timer and update timer.ticks */
- get_ticks();
+ unsigned long long target;
+
+ read_timer();
- const unsigned long long target = timer.ticks + usecs_to_ticks(usec);
+ target = timer.ticks + usecs_to_ticks(usec);
while (timer.ticks < target)
- get_ticks();
+ read_timer();
}
int timer_init(void)
{
struct timer_regs *timer_regs = (struct timer_regs *)TIMER_BASE;
- /* use timer 3 with 508KHz and free running */
+ /* use timer 3 with 508KHz and free running, not enabled now */
writel(TIMER_CLKSEL, &timer_regs->timer3.control);
- /* set initial timer value 3 */
+ /* set initial timer value */
writel(TIMER_MAX_VAL, &timer_regs->timer3.load);
/* Enable the timer */
--
1.6.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH 4/4] ep93xx timer: refactoring
2010-03-09 21:13 ` [U-Boot] [PATCH 4/4] ep93xx timer: refactoring Matthias Kaehlcke
@ 2010-03-13 20:32 ` Tom
0 siblings, 0 replies; 4+ messages in thread
From: Tom @ 2010-03-13 20:32 UTC (permalink / raw)
To: u-boot
Matthias Kaehlcke wrote:
> ep93xx timer: Simplified the timer code by eliminating clk_to_systicks() and
> performing (almost) all manipulation of the timer structure in read_timer()
>
> Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net>
> ---
> cpu/arm920t/ep93xx/timer.c | 52 ++++++++++++++++++++-----------------------
> 1 files changed, 24 insertions(+), 28 deletions(-)
>
Applied this patchset.
Thanks,
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-03-13 20:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <a41656a7b95f18a5ef51428b285767d0a70cbbc7.1268169068.git.matthias@kaehlcke.net>
2010-03-09 21:13 ` [U-Boot] [PATCH 2/4] ep93xx timer: Fix resolution of get_ticks() Matthias Kaehlcke
2010-03-09 21:13 ` [U-Boot] [PATCH 3/4] ep93xx timer: Rename struct timer_reg pointers Matthias Kaehlcke
2010-03-09 21:13 ` [U-Boot] [PATCH 4/4] ep93xx timer: refactoring Matthias Kaehlcke
2010-03-13 20:32 ` Tom
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox