Lines Matching +full:switch +full:- +full:freq +full:- +full:select
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
84 TUNABLE_INT("hw.i8254.freq", &i8254_freq);
111 static int timer0_period = -2;
141 if (i8254_timecounter && sc->period != 0) {
153 if (sc->et.et_active && sc->mode != MODE_STOP)
154 sc->et.et_event_cb(&sc->et, sc->et.et_arg);
167 return (-1);
173 * knew the rate. Use of splclock() limits glitches to 10-100us,
188 return (-1);
197 timer_spkr_setfreq(int freq)
200 freq = i8254_freq / freq;
202 outb(TIMER_CNTR2, freq & 0xff);
203 outb(TIMER_CNTR2, freq >> 8);
214 /* Select timer0 and latch counter value. */
265 n -= 0; /* XXX actually guess no initial overhead */
279 ticks_left = ((u_int)n * 39099 + (1 << 15) - 1) >> 15;
282 * Don't bother using fixed point, although gcc-2.7.2
294 tick = prev_tick - 1;
303 delta = prev_tick - tick;
316 ticks_left -= delta;
336 new_count = -1;
344 timer0_period = (mode == MODE_PERIODIC) ? new_count : -1;
345 switch (mode) {
385 timer0_period = -2;
389 set_i8254_freq(attimer_sc->mode, attimer_sc->period);
440 u_int freq;
446 freq = i8254_freq;
447 error = sysctl_handle_int(oidp, &freq, 0, req);
448 if (error == 0 && req->newptr != NULL) {
449 i8254_freq = freq;
451 set_i8254_freq(attimer_sc->mode, attimer_sc->period);
452 attimer_sc->tc.tc_frequency = freq;
468 device_t dev = (device_t)tc->tc_priv;
474 if (sc->period == 0)
475 return (i8254_max_count - getit());
484 /* Select timer0 and latch counter value. */
489 count = i8254_max_count - ((high << 8) | low);
507 device_t dev = (device_t)et->et_priv;
511 sc->mode = MODE_PERIODIC;
512 sc->period = period;
514 sc->mode = MODE_ONESHOT;
515 sc->period = first;
517 if (!sc->intr_en) {
518 i8254_intsrc->is_pic->pic_enable_source(i8254_intsrc);
519 sc->intr_en = 1;
521 set_i8254_freq(sc->mode, sc->period);
528 device_t dev = (device_t)et->et_priv;
531 sc->mode = MODE_STOP;
532 sc->period = 0;
533 set_i8254_freq(sc->mode, sc->period);
552 /* ENOENT means no PnP-ID, device is hinted. */
569 if (!(sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
570 &sc->port_rid, IO_TIMER1, IO_TIMER1 + 3, 4, RF_ACTIVE)))
574 i8254_pending = i8254_intsrc->is_pic->pic_source_pending;
579 sc->tc.tc_get_timecount = i8254_get_timecount;
580 sc->tc.tc_counter_mask = 0xffff;
581 sc->tc.tc_frequency = i8254_freq;
582 sc->tc.tc_name = "i8254";
583 sc->tc.tc_quality = 0;
584 sc->tc.tc_priv = dev;
585 tc_init(&sc->tc);
589 sc->intr_rid = 0;
590 while (bus_get_resource(dev, SYS_RES_IRQ, sc->intr_rid,
592 sc->intr_rid++;
593 if (!(sc->intr_res = bus_alloc_resource(dev, SYS_RES_IRQ,
594 &sc->intr_rid, 0, 0, 1, RF_ACTIVE))) {
599 i8254_intsrc->is_handlers++;
600 if ((bus_setup_intr(dev, sc->intr_res,
603 sc, &sc->intr_handler))) {
605 i8254_intsrc->is_handlers--;
608 i8254_intsrc->is_handlers--;
609 i8254_intsrc->is_pic->pic_enable_intr(i8254_intsrc);
610 sc->et.et_name = "i8254";
611 sc->et.et_flags = ET_FLAGS_PERIODIC;
613 sc->et.et_flags |= ET_FLAGS_ONESHOT;
614 sc->et.et_quality = 100;
615 sc->et.et_frequency = i8254_freq;
616 sc->et.et_min_period = (0x0002LLU << 32) / i8254_freq;
617 sc->et.et_max_period = (0xfffeLLU << 32) / i8254_freq;
618 sc->et.et_start = attimer_start;
619 sc->et.et_stop = attimer_stop;
620 sc->et.et_priv = dev;
621 et_register(&sc->et);