X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=arch%2Farm%2Fmach-iop3xx%2Fiop321-time.c;h=b2135e18e19628629fe9371ecc8063412562be5e;hb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;hp=be36c70690b153d38ade735e44cc0e6a27f0f0a3;hpb=a2c21200f1c81b08cb55e417b68150bba439b646;p=linux-2.6.git diff --git a/arch/arm/mach-iop3xx/iop321-time.c b/arch/arm/mach-iop3xx/iop321-time.c index be36c7069..b2135e18e 100644 --- a/arch/arm/mach-iop3xx/iop321-time.c +++ b/arch/arm/mach-iop3xx/iop321-time.c @@ -5,7 +5,7 @@ * * Author: Deepak Saxena * - * Copyright 2002 MontaVista Software Inc. + * Copyright 2002-2003 MontaVista Software Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -23,17 +23,25 @@ #include #include #include - +#include #include #include +#define IOP321_TIME_SYNC 0 + +static unsigned long iop321_latch; + +static inline unsigned long get_elapsed(void) +{ + return iop321_latch - *IOP321_TU_TCR0; +} + static unsigned long iop321_gettimeoffset(void) { unsigned long elapsed, usec; + u32 tisr1, tisr2; /* - * FIXME: Implement what is described in this comment. - * * If an interrupt was pending before we read the timer, * we've already wrapped. Factor this into the time. * If an interrupt was pending after we read the timer, @@ -42,12 +50,19 @@ static unsigned long iop321_gettimeoffset(void) * be sure its value is after the wrap. */ - elapsed = *IOP321_TU_TCR0; + asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr1)); + elapsed = get_elapsed(); + asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr2)); + + if(tisr1 & 1) + elapsed += iop321_latch; + else if (tisr2 & 1) + elapsed = iop321_latch + get_elapsed(); /* * Now convert them to usec. */ - usec = (unsigned long)((LATCH - elapsed) * (tick_nsec / 1000)) / LATCH; + usec = (unsigned long)(elapsed * (tick_nsec / 1000)) / iop321_latch; return usec; } @@ -56,6 +71,10 @@ static irqreturn_t iop321_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) { u32 tisr; +#ifdef IOP321_TIME_SYNC + u32 passed; +#define TM_THRESH (iop321_latch*2) +#endif asm volatile("mrc p6, 0, %0, c6, c1, 0" : "=r" (tisr)); @@ -63,7 +82,24 @@ iop321_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) asm volatile("mcr p6, 0, %0, c6, c1, 0" : : "r" (tisr)); - timer_tick(regs); +#ifdef IOP321_TIME_SYNC + passed = 0xffffffff - *IOP321_TU_TCR1; + + do + { + do_timer(regs); + if(passed < TM_THRESH) + break; + if(passed > iop321_latch) + passed -= iop321_latch; + else + passed = 0; + } while(1); + + asm volatile("mcr p6, 0, %0, c3, c1, 0" : : "r" (0xffffffff)); +#else + do_timer(regs); +#endif return IRQ_HANDLED; } @@ -79,17 +115,27 @@ extern int setup_arm_irq(int, struct irqaction*); void __init iop321_init_time(void) { u32 timer_ctl; - u32 latch = LATCH; + iop321_latch = (CLOCK_TICK_RATE + HZ / 2) / HZ; gettimeoffset = iop321_gettimeoffset; setup_irq(IRQ_IOP321_TIMER0, &iop321_timer_irq); timer_ctl = IOP321_TMR_EN | IOP321_TMR_PRIVILEGED | IOP321_TMR_RELOAD | IOP321_TMR_RATIO_1_1; - asm volatile("mcr p6, 0, %0, c4, c1, 0" : : "r" (LATCH)); + asm volatile("mcr p6, 0, %0, c4, c1, 0" : : "r" (iop321_latch)); asm volatile("mcr p6, 0, %0, c0, c1, 0" : : "r" (timer_ctl)); + +#ifdef IOP321_TIME_SYNC + /* Setup second timer */ + /* setup counter */ + timer_ctl = IOP321_TMR_EN | IOP321_TMR_PRIVILEGED | + IOP321_TMR_RATIO_1_1; + asm volatile("mcr p6, 0, %0, c3, c1, 0" : : "r" (0xffffffff)); + /* setup control */ + asm volatile("mcr p6, 0, %0, c1, c1, 0" : : "r" (timer_ctl)); +#endif }