X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cpu%2Farm926ejs%2Fdavinci%2Ftimer.c;h=9da7443f30b5fea4df134a932ac49739f6c9e1ee;hb=8f0fec74ac6d0f3a7134ccebafa1ed9bd8c712ba;hp=4a1a54dcf1777675707a8610817c44df8f66b28c;hpb=94a78da26ce17af61fbb2b620de51ba79bc80597;p=oweals%2Fu-boot.git diff --git a/cpu/arm926ejs/davinci/timer.c b/cpu/arm926ejs/davinci/timer.c index 4a1a54dcf1..9da7443f30 100644 --- a/cpu/arm926ejs/davinci/timer.c +++ b/cpu/arm926ejs/davinci/timer.c @@ -11,7 +11,7 @@ * Alex Zuepke * * (C) Copyright 2002-2004 - * Gary Jennejohn, DENX Software Engineering, + * Gary Jennejohn, DENX Software Engineering, * * (C) Copyright 2004 * Philippe Robin, ARM Ltd. @@ -38,13 +38,13 @@ */ #include -#include +#include -typedef volatile struct { +struct davinci_timer { u_int32_t pid12; - u_int32_t emumgt_clksped; - u_int32_t gpint_en; - u_int32_t gpdir_dat; + u_int32_t emumgt; + u_int32_t na1; + u_int32_t na2; u_int32_t tim12; u_int32_t tim34; u_int32_t prd12; @@ -52,19 +52,13 @@ typedef volatile struct { u_int32_t tcr; u_int32_t tgcr; u_int32_t wdtcr; - u_int32_t tlgc; - u_int32_t tlmr; -} davinci_timer; +}; -davinci_timer *timer = (davinci_timer *)CFG_TIMERBASE; +static struct davinci_timer * const timer = + (struct davinci_timer *)CONFIG_SYS_TIMERBASE; -#define TIMER_LOAD_VAL (CFG_HZ_CLOCK / CFG_HZ) -#define READ_TIMER timer->tim34 - -/* Timer runs with CFG_HZ_CLOCK, currently 27MHz. To avoid wrap - around of timestamp already after min ~159s, divide it, e.g. by 16. - timestamp will then wrap around all min ~42min */ -#define DIV(x) ((x) >> 4) +#define TIMER_LOAD_VAL (CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ) +#define TIM_CLK_DIV 16 static ulong timestamp; static ulong lastinc; @@ -72,73 +66,61 @@ static ulong lastinc; int timer_init(void) { /* We are using timer34 in unchained 32-bit mode, full speed */ - timer->tcr = 0x0; - timer->tgcr = 0x0; - timer->tgcr = 0x06; - timer->tim34 = 0x0; - timer->prd34 = TIMER_LOAD_VAL; + writel(0x0, &timer->tcr); + writel(0x0, &timer->tgcr); + writel(0x06 | ((TIM_CLK_DIV - 1) << 8), &timer->tgcr); + writel(0x0, &timer->tim34); + writel(TIMER_LOAD_VAL, &timer->prd34); lastinc = 0; - timer->tcr = 0x80 << 16; timestamp = 0; + writel(2 << 22, &timer->tcr); return(0); } void reset_timer(void) { - reset_timer_masked(); -} - -ulong get_timer(ulong base) -{ - return(get_timer_masked() - base); -} - -void set_timer(ulong t) -{ - timestamp = t; -} - -void udelay(unsigned long usec) -{ - udelay_masked(usec); -} - -void reset_timer_masked(void) -{ - lastinc = DIV(READ_TIMER); + writel(0x0, &timer->tcr); + writel(0x0, &timer->tim34); + lastinc = 0; timestamp = 0; + writel(2 << 22, &timer->tcr); } -ulong get_timer_raw(void) +static ulong get_timer_raw(void) { - ulong now = DIV(READ_TIMER); + ulong now = readl(&timer->tim34); if (now >= lastinc) { /* normal mode */ timestamp += now - lastinc; } else { /* overflow ... */ - timestamp += now + DIV(TIMER_LOAD_VAL) - lastinc; + timestamp += now + TIMER_LOAD_VAL - lastinc; } lastinc = now; return timestamp; } -ulong get_timer_masked(void) +ulong get_timer(ulong base) +{ + return((get_timer_raw() / (TIMER_LOAD_VAL / TIM_CLK_DIV)) - base); +} + +void set_timer(ulong t) { - return(get_timer_raw() / DIV(TIMER_LOAD_VAL)); + timestamp = t; } -void udelay_masked(unsigned long usec) +void __udelay(unsigned long usec) { ulong tmo; ulong endtime; signed long diff; - tmo = CFG_HZ_CLOCK / 1000; + tmo = CONFIG_SYS_HZ_CLOCK / 1000; tmo *= usec; - tmo /= 1000; + tmo /= (1000 * TIM_CLK_DIV); endtime = get_timer_raw() + tmo; @@ -163,8 +145,5 @@ unsigned long long get_ticks(void) */ ulong get_tbclk(void) { - ulong tbclk; - - tbclk = CFG_HZ; - return(tbclk); + return CONFIG_SYS_HZ; }