Lines Matching refs:t

81 static void npcm7xx_timer_start(NPCM7xxBaseTimer *t)  in npcm7xx_timer_start()  argument
86 t->expires_ns = now + t->remaining_ns; in npcm7xx_timer_start()
87 timer_mod(&t->qtimer, t->expires_ns); in npcm7xx_timer_start()
91 static void npcm7xx_timer_pause(NPCM7xxBaseTimer *t) in npcm7xx_timer_pause() argument
95 timer_del(&t->qtimer); in npcm7xx_timer_pause()
97 t->remaining_ns = t->expires_ns - now; in npcm7xx_timer_pause()
101 static void npcm7xx_timer_clear(NPCM7xxBaseTimer *t) in npcm7xx_timer_clear() argument
103 timer_del(&t->qtimer); in npcm7xx_timer_clear()
104 t->expires_ns = 0; in npcm7xx_timer_clear()
105 t->remaining_ns = 0; in npcm7xx_timer_clear()
129 static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count) in npcm7xx_timer_count_to_ns() argument
133 ticks *= npcm7xx_tcsr_prescaler(t->tcsr); in npcm7xx_timer_count_to_ns()
135 return clock_ticks_to_ns(t->ctrl->clock, ticks); in npcm7xx_timer_count_to_ns()
139 static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns) in npcm7xx_timer_ns_to_count() argument
144 return clock_ns_to_ticks(t->ctrl->clock, ns) / in npcm7xx_timer_ns_to_count()
145 npcm7xx_tcsr_prescaler(t->tcsr); in npcm7xx_timer_ns_to_count()
148 static uint32_t npcm7xx_watchdog_timer_prescaler(const NPCM7xxWatchdogTimer *t) in npcm7xx_watchdog_timer_prescaler() argument
150 switch (NPCM7XX_WTCR_WTCLK(t->wtcr)) { in npcm7xx_watchdog_timer_prescaler()
164 static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t, in npcm7xx_watchdog_timer_reset_cycles() argument
167 int64_t ticks = cycles * npcm7xx_watchdog_timer_prescaler(t); in npcm7xx_watchdog_timer_reset_cycles()
168 int64_t ns = clock_ticks_to_ns(t->ctrl->clock, ticks); in npcm7xx_watchdog_timer_reset_cycles()
175 npcm7xx_timer_clear(&t->base_timer); in npcm7xx_watchdog_timer_reset_cycles()
177 t->base_timer.remaining_ns = ns; in npcm7xx_watchdog_timer_reset_cycles()
180 static void npcm7xx_watchdog_timer_reset(NPCM7xxWatchdogTimer *t) in npcm7xx_watchdog_timer_reset() argument
183 uint32_t s = NPCM7XX_WTCR_WTIS(t->wtcr); in npcm7xx_watchdog_timer_reset()
190 npcm7xx_watchdog_timer_reset_cycles(t, cycles); in npcm7xx_watchdog_timer_reset()
197 static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t) in npcm7xx_timer_check_interrupt() argument
199 NPCM7xxTimerCtrlState *tc = t->ctrl; in npcm7xx_timer_check_interrupt()
200 int index = npcm7xx_timer_index(tc, t); in npcm7xx_timer_check_interrupt()
201 bool pending = (t->tcsr & NPCM7XX_TCSR_IE) && (tc->tisr & BIT(index)); in npcm7xx_timer_check_interrupt()
203 qemu_set_irq(t->irq, pending); in npcm7xx_timer_check_interrupt()
211 static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) in npcm7xx_timer_reached_zero() argument
213 NPCM7xxTimerCtrlState *tc = t->ctrl; in npcm7xx_timer_reached_zero()
214 int index = npcm7xx_timer_index(tc, t); in npcm7xx_timer_reached_zero()
218 if (t->tcsr & NPCM7XX_TCSR_PERIODIC) { in npcm7xx_timer_reached_zero()
219 t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); in npcm7xx_timer_reached_zero()
220 if (t->tcsr & NPCM7XX_TCSR_CEN) { in npcm7xx_timer_reached_zero()
221 npcm7xx_timer_start(&t->base_timer); in npcm7xx_timer_reached_zero()
224 t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT); in npcm7xx_timer_reached_zero()
227 npcm7xx_timer_check_interrupt(t); in npcm7xx_timer_reached_zero()
237 static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr) in npcm7xx_timer_restart() argument
239 t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); in npcm7xx_timer_restart()
241 if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { in npcm7xx_timer_restart()
242 npcm7xx_timer_start(&t->base_timer); in npcm7xx_timer_restart()
248 static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t) in npcm7xx_timer_read_tdr() argument
250 if (t->tcsr & NPCM7XX_TCSR_CEN) { in npcm7xx_timer_read_tdr()
253 return npcm7xx_timer_ns_to_count(t, t->base_timer.expires_ns - now); in npcm7xx_timer_read_tdr()
256 return npcm7xx_timer_ns_to_count(t, t->base_timer.remaining_ns); in npcm7xx_timer_read_tdr()
259 static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) in npcm7xx_timer_write_tcsr() argument
261 uint32_t old_tcsr = t->tcsr; in npcm7xx_timer_write_tcsr()
282 tdr = npcm7xx_timer_read_tdr(t); in npcm7xx_timer_write_tcsr()
284 t->tcsr = (t->tcsr & NPCM7XX_TCSR_CACT) | new_tcsr; in npcm7xx_timer_write_tcsr()
288 t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); in npcm7xx_timer_write_tcsr()
289 if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { in npcm7xx_timer_write_tcsr()
290 npcm7xx_timer_start(&t->base_timer); in npcm7xx_timer_write_tcsr()
295 npcm7xx_timer_check_interrupt(t); in npcm7xx_timer_write_tcsr()
298 npcm7xx_timer_restart(t, old_tcsr); in npcm7xx_timer_write_tcsr()
299 t->tcsr &= ~NPCM7XX_TCSR_CRST; in npcm7xx_timer_write_tcsr()
303 t->tcsr |= NPCM7XX_TCSR_CACT; in npcm7xx_timer_write_tcsr()
304 npcm7xx_timer_start(&t->base_timer); in npcm7xx_timer_write_tcsr()
306 t->tcsr &= ~NPCM7XX_TCSR_CACT; in npcm7xx_timer_write_tcsr()
307 npcm7xx_timer_pause(&t->base_timer); in npcm7xx_timer_write_tcsr()
308 if (t->base_timer.remaining_ns <= 0) { in npcm7xx_timer_write_tcsr()
309 npcm7xx_timer_reached_zero(t); in npcm7xx_timer_write_tcsr()
315 static void npcm7xx_timer_write_ticr(NPCM7xxTimer *t, uint32_t new_ticr) in npcm7xx_timer_write_ticr() argument
317 t->ticr = new_ticr; in npcm7xx_timer_write_ticr()
319 npcm7xx_timer_restart(t, t->tcsr); in npcm7xx_timer_write_ticr()
335 static void npcm7xx_timer_write_wtcr(NPCM7xxWatchdogTimer *t, uint32_t new_wtcr) in npcm7xx_timer_write_wtcr() argument
337 uint32_t old_wtcr = t->wtcr; in npcm7xx_timer_write_wtcr()
354 t->wtcr = new_wtcr; in npcm7xx_timer_write_wtcr()
357 t->wtcr &= ~NPCM7XX_WTCR_WTR; in npcm7xx_timer_write_wtcr()
358 npcm7xx_watchdog_timer_reset(t); in npcm7xx_timer_write_wtcr()
360 npcm7xx_timer_start(&t->base_timer); in npcm7xx_timer_write_wtcr()
364 npcm7xx_timer_start(&t->base_timer); in npcm7xx_timer_write_wtcr()
366 npcm7xx_timer_pause(&t->base_timer); in npcm7xx_timer_write_wtcr()
542 NPCM7xxTimer *t = opaque; in npcm7xx_timer_expired() local
544 if (t->tcsr & NPCM7XX_TCSR_CEN) { in npcm7xx_timer_expired()
545 npcm7xx_timer_reached_zero(t); in npcm7xx_timer_expired()
555 NPCM7xxTimer *t = &s->timer[i]; in npcm7xx_timer_enter_reset() local
557 npcm7xx_timer_clear(&t->base_timer); in npcm7xx_timer_enter_reset()
558 t->tcsr = 0x00000005; in npcm7xx_timer_enter_reset()
559 t->ticr = 0x00000000; in npcm7xx_timer_enter_reset()
573 NPCM7xxWatchdogTimer *t = opaque; in npcm7xx_watchdog_timer_expired() local
575 if (t->wtcr & NPCM7XX_WTCR_WTE) { in npcm7xx_watchdog_timer_expired()
576 if (t->wtcr & NPCM7XX_WTCR_WTIF) { in npcm7xx_watchdog_timer_expired()
577 if (t->wtcr & NPCM7XX_WTCR_WTRE) { in npcm7xx_watchdog_timer_expired()
578 t->wtcr |= NPCM7XX_WTCR_WTRF; in npcm7xx_watchdog_timer_expired()
580 qemu_irq_raise(t->reset_signal); in npcm7xx_watchdog_timer_expired()
583 t->wtcr |= NPCM7XX_WTCR_WTIF; in npcm7xx_watchdog_timer_expired()
584 if (t->wtcr & NPCM7XX_WTCR_WTIE) { in npcm7xx_watchdog_timer_expired()
586 qemu_irq_raise(t->irq); in npcm7xx_watchdog_timer_expired()
588 npcm7xx_watchdog_timer_reset_cycles(t, in npcm7xx_watchdog_timer_expired()
590 npcm7xx_timer_start(&t->base_timer); in npcm7xx_watchdog_timer_expired()
615 NPCM7xxTimer *t = &s->timer[i]; in npcm7xx_timer_init() local
616 t->ctrl = s; in npcm7xx_timer_init()
617 timer_init_ns(&t->base_timer.qtimer, QEMU_CLOCK_VIRTUAL, in npcm7xx_timer_init()
618 npcm7xx_timer_expired, t); in npcm7xx_timer_init()
619 sysbus_init_irq(sbd, &t->irq); in npcm7xx_timer_init()