Lines Matching +full:qemu +full:- +full:1 +full:- +full:setup

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
11 * 1. Redistributions of source code must retain the above copyright
55 #define TIMER_CONTROL_EN (1 << 7)
57 #define TIMER_CONTROL_PERIODIC (1 << 6)
58 #define TIMER_CONTROL_INTREN (1 << 5)
60 #define TIMER_CONTROL_DIV16 (1 << 2)
62 #define TIMER_CONTROL_32BIT (1 << 1)
63 #define TIMER_CONTROL_ONESHOT (1 << 0)
87 * QEMU seems to have problem with full frequency
107 bus_space_read_4(sc->bst, sc->bsh, reg)
110 bus_space_write_4(sc->bst, sc->bsh, reg, val)
118 struct sp804_timer_softc *sc = tc->tc_priv; in sp804_timer_tc_get_timecount()
119 return 0xffffffff - sp804_timer_tc_read_4(SP804_TIMER1_VALUE); in sp804_timer_tc_get_timecount()
125 struct sp804_timer_softc *sc = et->et_priv; in sp804_timer_start()
129 sc->et_enabled = 1; in sp804_timer_start()
131 count = ((uint32_t)et->et_frequency * first) >> 32; in sp804_timer_start()
152 struct sp804_timer_softc *sc = et->et_priv; in sp804_timer_stop()
155 sc->et_enabled = 0; in sp804_timer_stop()
170 sp804_timer_tc_write_4(SP804_TIMER2_INTCLR, 1); in sp804_timer_intr()
171 if (sc->et_enabled) { in sp804_timer_intr()
172 if (sc->et.et_active) { in sp804_timer_intr()
173 sc->et.et_event_cb(&sc->et, sc->et.et_arg); in sp804_timer_intr()
205 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); in sp804_timer_attach()
206 if (sc->mem_res == NULL) { in sp804_timer_attach()
211 sc->bst = rman_get_bustag(sc->mem_res); in sp804_timer_attach()
212 sc->bsh = rman_get_bushandle(sc->mem_res); in sp804_timer_attach()
215 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); in sp804_timer_attach()
216 if (sc->irq_res == NULL) { in sp804_timer_attach()
221 sc->sysclk_freq = DEFAULT_FREQUENCY; in sp804_timer_attach()
224 if ((OF_getencprop(node, "clock-frequency", &clock, sizeof(clock))) > 0) { in sp804_timer_attach()
225 sc->sysclk_freq = clock; in sp804_timer_attach()
228 /* Setup and enable the timer */ in sp804_timer_attach()
229 if (bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CLK, in sp804_timer_attach()
231 &sc->intr_hl) != 0) { in sp804_timer_attach()
233 sc->irq_res); in sp804_timer_attach()
234 device_printf(dev, "Unable to setup the clock irq handler.\n"); in sp804_timer_attach()
242 * Timer 1, timecounter in sp804_timer_attach()
244 sc->tc.tc_frequency = sc->sysclk_freq; in sp804_timer_attach()
245 sc->tc.tc_name = "SP804-1"; in sp804_timer_attach()
246 sc->tc.tc_get_timecount = sp804_timer_tc_get_timecount; in sp804_timer_attach()
247 sc->tc.tc_poll_pps = NULL; in sp804_timer_attach()
248 sc->tc.tc_counter_mask = ~0u; in sp804_timer_attach()
249 sc->tc.tc_quality = 1000; in sp804_timer_attach()
250 sc->tc.tc_priv = sc; in sp804_timer_attach()
258 tc_init(&sc->tc); in sp804_timer_attach()
263 sc->et_enabled = 0; in sp804_timer_attach()
264 sc->et.et_name = "SP804-2"; in sp804_timer_attach()
265 sc->et.et_flags = ET_FLAGS_PERIODIC | ET_FLAGS_ONESHOT; in sp804_timer_attach()
266 sc->et.et_quality = 1000; in sp804_timer_attach()
267 sc->et.et_frequency = sc->sysclk_freq / DEFAULT_DIVISOR; in sp804_timer_attach()
268 sc->et.et_min_period = (0x00000002LLU << 32) / sc->et.et_frequency; in sp804_timer_attach()
269 sc->et.et_max_period = (0xfffffffeLLU << 32) / sc->et.et_frequency; in sp804_timer_attach()
270 sc->et.et_start = sp804_timer_start; in sp804_timer_attach()
271 sc->et.et_stop = sp804_timer_stop; in sp804_timer_attach()
272 sc->et.et_priv = sc; in sp804_timer_attach()
273 et_register(&sc->et); in sp804_timer_attach()
276 for (i = 3; i >= 0; i--) { in sp804_timer_attach()
284 for (i = 3; i >= 0; i--) { in sp804_timer_attach()
293 sc->timer_initialized = 1; in sp804_timer_attach()
320 counts = usec * ((sc->tc.tc_frequency / 1000000) + 1); in sp804_timer_delay()
322 first = sp804_timer_tc_get_timecount(&sc->tc); in sp804_timer_delay()
325 last = sp804_timer_tc_get_timecount(&sc->tc); in sp804_timer_delay()
329 counts -= (int32_t)(last - first); in sp804_timer_delay()
331 counts -= (int32_t)((0xFFFFFFFF - first) + last); in sp804_timer_delay()