static void arm_timer_write(void *opaque, target_phys_addr_t offset,

                            uint32_t value)

{

    arm_timer_state *s = (arm_timer_state *)opaque;

    int freq;



    switch (offset >> 2) {

    case 0: /* TimerLoad */

        s->limit = value;

        arm_timer_recalibrate(s, 1);

        break;

    case 1: /* TimerValue */

        /* ??? Linux seems to want to write to this readonly register.

           Ignore it.  */

        break;

    case 2: /* TimerControl */

        if (s->control & TIMER_CTRL_ENABLE) {

            /* Pause the timer if it is running.  This may cause some

               inaccuracy dure to rounding, but avoids a whole lot of other

               messyness.  */

            ptimer_stop(s->timer);

        }

        s->control = value;

        freq = s->freq;

        /* ??? Need to recalculate expiry time after changing divisor.  */

        switch ((value >> 2) & 3) {

        case 1: freq >>= 4; break;

        case 2: freq >>= 8; break;

        }

        arm_timer_recalibrate(s, 0);

        ptimer_set_freq(s->timer, freq);

        if (s->control & TIMER_CTRL_ENABLE) {

            /* Restart the timer if still enabled.  */

            ptimer_run(s->timer, (s->control & TIMER_CTRL_ONESHOT) != 0);

        }

        break;

    case 3: /* TimerIntClr */

        s->int_level = 0;

        break;

    case 6: /* TimerBGLoad */

        s->limit = value;

        arm_timer_recalibrate(s, 0);

        break;

    default:

        hw_error("arm_timer_write: Bad offset %x\n", (int)offset);

    }

    arm_timer_update(s);

}

static void arm_timer_write(void *opaque, target_phys_addr_t offset,

                            uint32_t value)

{

    arm_timer_state *s = (arm_timer_state *)opaque;

    int freq;



    switch (offset >> 2) {

    case 0: 

        s->limit = value;

        arm_timer_recalibrate(s, 1);

        break;

    case 1: 

        



        break;

    case 2: 

        if (s->control & TIMER_CTRL_ENABLE) {

            





            ptimer_stop(s->timer);

        }

        s->control = value;

        freq = s->freq;

        

        switch ((value >> 2) & 3) {

        case 1: freq >>= 4; break;

        case 2: freq >>= 8; break;

        }

        arm_timer_recalibrate(s, 0);

        ptimer_set_freq(s->timer, freq);

        if (s->control & TIMER_CTRL_ENABLE) {

            

            ptimer_run(s->timer, (s->control & TIMER_CTRL_ONESHOT) != 0);

        }

        break;

    case 3: 

        s->int_level = 0;

        break;

    case 6: 

        s->limit = value;

        arm_timer_recalibrate(s, 0);

        break;

    default:

        hw_error("arm_timer_write: Bad offset %x\n", (int)offset);

    }

    arm_timer_update(s);

}

static void FUNC_0(void *VAR_0, target_phys_addr_t VAR_1,

                            uint32_t VAR_2)

{

    arm_timer_state *s = (arm_timer_state *)VAR_0;

    int VAR_3;



    switch (VAR_1 >> 2) {

    case 0: 

        s->limit = VAR_2;

        arm_timer_recalibrate(s, 1);

        break;

    case 1: 

        



        break;

    case 2: 

        if (s->control & TIMER_CTRL_ENABLE) {

            





            ptimer_stop(s->timer);

        }

        s->control = VAR_2;

        VAR_3 = s->VAR_3;

        

        switch ((VAR_2 >> 2) & 3) {

        case 1: VAR_3 >>= 4; break;

        case 2: VAR_3 >>= 8; break;

        }

        arm_timer_recalibrate(s, 0);

        ptimer_set_freq(s->timer, VAR_3);

        if (s->control & TIMER_CTRL_ENABLE) {

            

            ptimer_run(s->timer, (s->control & TIMER_CTRL_ONESHOT) != 0);

        }

        break;

    case 3: 

        s->int_level = 0;

        break;

    case 6: 

        s->limit = VAR_2;

        arm_timer_recalibrate(s, 0);

        break;

    default:

        hw_error("FUNC_0: Bad VAR_1 %x\n", (int)VAR_1);

    }

    arm_timer_update(s);

}

static void FUNC_0(void *VAR_0, target_phys_addr_t VAR_1,
uint32_t VAR_2)
{ arm_timer_state *s = (arm_timer_state *)VAR_0; int VAR_3; switch (VAR_1 >> 2) { case 0:
s->limit = VAR_2; arm_timer_recalibrate(s, 1); break; case 1:
break; case 2:
if (s->control & TIMER_CTRL_ENABLE) { ptimer_stop(s->timer); } s->control = VAR_2; VAR_3 = s->VAR_3; switch ((VAR_2 >> 2) & 3) { case 1: VAR_3 >>= 4; break; case 2: VAR_3 >>= 8; break; } arm_timer_recalibrate(s, 0); ptimer_set_freq(s->timer, VAR_3); if (s->control & TIMER_CTRL_ENABLE) { ptimer_run(s->timer, (s->control & TIMER_CTRL_ONESHOT) != 0); } break; case 3:
s->int_level = 0; break; case 6:
s->limit = VAR_2; arm_timer_recalibrate(s, 0); break; default:
hw_error("FUNC_0: Bad VAR_1 %x\n", (int)VAR_1); } arm_timer_update(s); }