Lines Matching refs:sc
95 uart_pps_print_mode(struct uart_softc *sc) in uart_pps_print_mode() argument
98 device_printf(sc->sc_dev, "PPS capture mode: "); in uart_pps_print_mode()
99 switch(sc->sc_pps_mode & UART_PPS_SIGNAL_MASK) { in uart_pps_print_mode()
113 if (sc->sc_pps_mode & UART_PPS_INVERT_PULSE) in uart_pps_print_mode()
115 if (sc->sc_pps_mode & UART_PPS_NARROW_PULSE) in uart_pps_print_mode()
123 struct uart_softc *sc; in uart_pps_mode_sysctl() local
126 sc = arg1; in uart_pps_mode_sysctl()
127 tmp = sc->sc_pps_mode; in uart_pps_mode_sysctl()
133 sc->sc_pps_mode = tmp; in uart_pps_mode_sysctl()
138 uart_pps_process(struct uart_softc *sc, int ser_sig) in uart_pps_process() argument
144 switch(sc->sc_pps_mode & UART_PPS_SIGNAL_MASK) { in uart_pps_process()
169 pps_capture(&sc->sc_pps); in uart_pps_process()
170 if (sc->sc_pps_mode & UART_PPS_NARROW_PULSE) { in uart_pps_process()
172 if (now > sc->sc_pps_captime + 500 * SBT_1MS) { in uart_pps_process()
173 sc->sc_pps_captime = now; in uart_pps_process()
174 pps_event(&sc->sc_pps, PPS_CAPTUREASSERT); in uart_pps_process()
175 pps_event(&sc->sc_pps, PPS_CAPTURECLEAR); in uart_pps_process()
179 if (sc->sc_pps_mode & UART_PPS_INVERT_PULSE) in uart_pps_process()
181 pps_event(&sc->sc_pps, is_assert ? PPS_CAPTUREASSERT : in uart_pps_process()
187 uart_pps_init(struct uart_softc *sc) in uart_pps_init() argument
192 ctx = device_get_sysctl_ctx(sc->sc_dev); in uart_pps_init()
193 tree = device_get_sysctl_tree(sc->sc_dev); in uart_pps_init()
203 sc->sc_pps_mode = UART_PPS_CTS; in uart_pps_init()
205 sc->sc_pps_mode = UART_PPS_DCD; in uart_pps_init()
207 TUNABLE_INT_FETCH("hw.uart.pps_mode", &sc->sc_pps_mode); in uart_pps_init()
209 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, sc, 0, in uart_pps_init()
213 if (!uart_pps_mode_valid(sc->sc_pps_mode)) { in uart_pps_init()
214 device_printf(sc->sc_dev, in uart_pps_init()
216 sc->sc_pps_mode); in uart_pps_init()
217 sc->sc_pps_mode = UART_PPS_DISABLED; in uart_pps_init()
219 uart_pps_print_mode(sc); in uart_pps_init()
222 sc->sc_pps.ppscap = PPS_CAPTUREBOTH; in uart_pps_init()
223 sc->sc_pps.driver_mtx = uart_tty_getlock(sc); in uart_pps_init()
224 sc->sc_pps.driver_abi = PPS_ABI_VERSION; in uart_pps_init()
225 pps_init_abi(&sc->sc_pps); in uart_pps_init()
269 uart_sched_softih(struct uart_softc *sc, uint32_t ipend) in uart_sched_softih() argument
274 old = sc->sc_ttypend; in uart_sched_softih()
276 } while (!atomic_cmpset_32(&sc->sc_ttypend, old, new)); in uart_sched_softih()
279 swi_sched(sc->sc_softih, 0); in uart_sched_softih()
294 struct uart_softc *sc = arg; in uart_intr_break() local
297 if (sc->sc_sysdev != NULL && sc->sc_sysdev->type == UART_DEV_CONSOLE) { in uart_intr_break()
302 if (sc->sc_opened) in uart_intr_break()
303 uart_sched_softih(sc, SER_INT_BREAK); in uart_intr_break()
325 struct uart_softc *sc = arg; in uart_intr_overrun() local
327 if (sc->sc_opened) { in uart_intr_overrun()
328 UART_RECEIVE(sc); in uart_intr_overrun()
329 if (uart_rx_put(sc, UART_STAT_OVERRUN)) in uart_intr_overrun()
330 sc->sc_rxbuf[sc->sc_rxput] = UART_STAT_OVERRUN; in uart_intr_overrun()
331 uart_sched_softih(sc, SER_INT_RXREADY); in uart_intr_overrun()
333 sc->sc_rxoverruns++; in uart_intr_overrun()
334 UART_FLUSH(sc, UART_FLUSH_RECEIVER); in uart_intr_overrun()
344 struct uart_softc *sc = arg; in uart_intr_rxready() local
348 rxp = sc->sc_rxput; in uart_intr_rxready()
350 UART_RECEIVE(sc); in uart_intr_rxready()
352 if (sc->sc_sysdev != NULL && sc->sc_sysdev->type == UART_DEV_CONSOLE) { in uart_intr_rxready()
353 while (rxp != sc->sc_rxput) { in uart_intr_rxready()
354 kdb_alt_break(sc->sc_rxbuf[rxp++], &sc->sc_altbrk); in uart_intr_rxready()
355 if (rxp == sc->sc_rxbufsz) in uart_intr_rxready()
360 if (sc->sc_opened) in uart_intr_rxready()
361 uart_sched_softih(sc, SER_INT_RXREADY); in uart_intr_rxready()
363 sc->sc_rxput = sc->sc_rxget; /* Ignore received data. */ in uart_intr_rxready()
377 struct uart_softc *sc = arg; in uart_intr_sigchg() local
380 sig = UART_GETSIG(sc); in uart_intr_sigchg()
386 if (sc->sc_pps.ppsparam.mode & PPS_CAPTUREBOTH) { in uart_intr_sigchg()
387 uart_pps_process(sc, sig); in uart_intr_sigchg()
398 old = sc->sc_ttypend; in uart_intr_sigchg()
401 } while (!atomic_cmpset_32(&sc->sc_ttypend, old, new)); in uart_intr_sigchg()
403 if (sc->sc_opened) in uart_intr_sigchg()
404 uart_sched_softih(sc, SER_INT_SIGCHG); in uart_intr_sigchg()
414 struct uart_softc *sc = arg; in uart_intr_txidle() local
416 if (sc->sc_txbusy) { in uart_intr_txidle()
417 sc->sc_txbusy = 0; in uart_intr_txidle()
418 uart_sched_softih(sc, SER_INT_TXIDLE); in uart_intr_txidle()
426 struct uart_softc *sc = arg; in uart_intr() local
429 if (sc->sc_leaving) in uart_intr()
433 testintr = sc->sc_testintr; in uart_intr()
434 while ((!testintr || cnt < 20) && (ipend = UART_IPEND(sc)) != 0) { in uart_intr()
437 uart_intr_overrun(sc); in uart_intr()
439 uart_intr_break(sc); in uart_intr()
441 uart_intr_rxready(sc); in uart_intr()
443 uart_intr_sigchg(sc); in uart_intr()
445 uart_intr_txidle(sc); in uart_intr()
448 if (sc->sc_polled) { in uart_intr()
449 callout_reset(&sc->sc_timer, hz / uart_poll_freq, in uart_intr()
450 (callout_func_t *)uart_intr, sc); in uart_intr()
480 struct uart_softc *sc; in uart_bus_ipend() local
482 sc = device_get_softc(dev); in uart_bus_ipend()
483 return (UART_IPEND(sc)); in uart_bus_ipend()
489 struct uart_softc *sc; in uart_bus_sysdev() local
491 sc = device_get_softc(dev); in uart_bus_sysdev()
492 return ((sc->sc_sysdev != NULL) ? 1 : 0); in uart_bus_sysdev()
498 struct uart_softc *sc; in uart_bus_probe() local
502 sc = device_get_softc(dev); in uart_bus_probe()
508 if (sc->sc_class == NULL) in uart_bus_probe()
518 kobj_init((kobj_t)sc, (kobj_class_t)sc->sc_class); in uart_bus_probe()
519 sc->sc_dev = dev; in uart_bus_probe()
521 device_set_desc(dev, uart_getname(sc->sc_class)); in uart_bus_probe()
530 sc->sc_rrid = rid; in uart_bus_probe()
531 sc->sc_rtype = SYS_RES_IOPORT; in uart_bus_probe()
532 sc->sc_rres = bus_alloc_resource_any(dev, sc->sc_rtype, &sc->sc_rrid, in uart_bus_probe()
534 if (sc->sc_rres == NULL) { in uart_bus_probe()
535 sc->sc_rrid = rid; in uart_bus_probe()
536 sc->sc_rtype = SYS_RES_MEMORY; in uart_bus_probe()
537 sc->sc_rres = bus_alloc_resource_any(dev, sc->sc_rtype, in uart_bus_probe()
538 &sc->sc_rrid, RF_ACTIVE); in uart_bus_probe()
539 if (sc->sc_rres == NULL) in uart_bus_probe()
550 sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres); in uart_bus_probe()
551 sc->sc_bas.bst = rman_get_bustag(sc->sc_rres); in uart_bus_probe()
552 sc->sc_bas.chan = chan; in uart_bus_probe()
553 sc->sc_bas.regshft = regshft; in uart_bus_probe()
554 sc->sc_bas.regiowidth = regiowidth; in uart_bus_probe()
555 sc->sc_bas.rclk = (rclk == 0) ? sc->sc_class->uc_rclk : rclk; in uart_bus_probe()
556 sc->sc_bas.busy_detect = !!(quirks & UART_F_BUSY_DETECT); in uart_bus_probe()
560 uart_cpu_eqres(&sc->sc_bas, &sysdev->bas)) { in uart_bus_probe()
562 sc->sc_sysdev = sysdev; in uart_bus_probe()
563 sysdev->bas.rclk = sc->sc_bas.rclk; in uart_bus_probe()
567 error = UART_PROBE(sc); in uart_bus_probe()
568 bus_release_resource(dev, sc->sc_rtype, sc->sc_rrid, sc->sc_rres); in uart_bus_probe()
575 struct uart_softc *sc, *sc0; in uart_bus_attach() local
587 sc = malloc(sc0->sc_class->size, M_UART, M_WAITOK|M_ZERO); in uart_bus_attach()
588 bcopy(sc0, sc, sizeof(*sc)); in uart_bus_attach()
589 device_set_softc(dev, sc); in uart_bus_attach()
591 sc = sc0; in uart_bus_attach()
597 if (sc->sc_sysdev != NULL) in uart_bus_attach()
598 sc->sc_sysdev->sc = sc; in uart_bus_attach()
605 sc->sc_leaving = 1; in uart_bus_attach()
607 mtx_init(&sc->sc_hwmtx_s, "uart_hwmtx", NULL, MTX_SPIN); in uart_bus_attach()
608 if (sc->sc_hwmtx == NULL) in uart_bus_attach()
609 sc->sc_hwmtx = &sc->sc_hwmtx_s; in uart_bus_attach()
615 sc->sc_rres = bus_alloc_resource_any(dev, sc->sc_rtype, &sc->sc_rrid, in uart_bus_attach()
617 if (sc->sc_rres == NULL) { in uart_bus_attach()
618 mtx_destroy(&sc->sc_hwmtx_s); in uart_bus_attach()
621 sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres); in uart_bus_attach()
622 sc->sc_bas.bst = rman_get_bustag(sc->sc_rres); in uart_bus_attach()
630 sc->sc_rxbufsz = MAX(384, sc->sc_rxfifosz * 3); in uart_bus_attach()
631 sc->sc_rxbuf = malloc(sc->sc_rxbufsz * sizeof(*sc->sc_rxbuf), in uart_bus_attach()
633 sc->sc_txbuf = malloc(sc->sc_txfifosz * sizeof(*sc->sc_txbuf), in uart_bus_attach()
636 error = UART_ATTACH(sc); in uart_bus_attach()
640 if (sc->sc_hwiflow || sc->sc_hwoflow) { in uart_bus_attach()
643 if (sc->sc_hwiflow) { in uart_bus_attach()
647 if (sc->sc_hwoflow) { in uart_bus_attach()
654 if (sc->sc_sysdev != NULL) { in uart_bus_attach()
655 if (sc->sc_sysdev->baudrate == 0) { in uart_bus_attach()
656 if (UART_IOCTL(sc, UART_IOCTL_BAUD, in uart_bus_attach()
657 (intptr_t)&sc->sc_sysdev->baudrate) != 0) in uart_bus_attach()
658 sc->sc_sysdev->baudrate = -1; in uart_bus_attach()
660 switch (sc->sc_sysdev->type) { in uart_bus_attach()
674 printf(" (%d,%c,%d,%d)\n", sc->sc_sysdev->baudrate, in uart_bus_attach()
675 "noems"[sc->sc_sysdev->parity], sc->sc_sysdev->databits, in uart_bus_attach()
676 sc->sc_sysdev->stopbits); in uart_bus_attach()
679 sc->sc_leaving = 0; in uart_bus_attach()
680 sc->sc_testintr = 1; in uart_bus_attach()
681 filt = uart_intr(sc); in uart_bus_attach()
682 sc->sc_testintr = 0; in uart_bus_attach()
690 sc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ, in uart_bus_attach()
691 &sc->sc_irid, RF_ACTIVE | RF_SHAREABLE); in uart_bus_attach()
693 if (sc->sc_ires != NULL) { in uart_bus_attach()
694 error = bus_setup_intr(dev, sc->sc_ires, INTR_TYPE_TTY, in uart_bus_attach()
695 uart_intr, NULL, sc, &sc->sc_icookie); in uart_bus_attach()
696 sc->sc_fastintr = (error == 0) ? 1 : 0; in uart_bus_attach()
698 if (!sc->sc_fastintr) in uart_bus_attach()
699 error = bus_setup_intr(dev, sc->sc_ires, in uart_bus_attach()
701 (driver_intr_t *)uart_intr, sc, &sc->sc_icookie); in uart_bus_attach()
705 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid, in uart_bus_attach()
706 sc->sc_ires); in uart_bus_attach()
707 sc->sc_ires = NULL; in uart_bus_attach()
710 if (sc->sc_ires == NULL) { in uart_bus_attach()
712 sc->sc_polled = 1; in uart_bus_attach()
713 callout_init(&sc->sc_timer, 1); in uart_bus_attach()
714 callout_reset(&sc->sc_timer, hz / uart_poll_freq, in uart_bus_attach()
715 (callout_func_t *)uart_intr, sc); in uart_bus_attach()
718 if (bootverbose && (sc->sc_fastintr || sc->sc_polled)) { in uart_bus_attach()
721 if (sc->sc_fastintr) { in uart_bus_attach()
725 if (sc->sc_polled) { in uart_bus_attach()
732 if (sc->sc_sysdev != NULL && sc->sc_sysdev->attach != NULL) { in uart_bus_attach()
733 if ((error = sc->sc_sysdev->attach(sc)) != 0) in uart_bus_attach()
736 if ((error = uart_tty_attach(sc)) != 0) in uart_bus_attach()
738 uart_pps_init(sc); in uart_bus_attach()
741 if (sc->sc_sysdev != NULL) in uart_bus_attach()
742 sc->sc_sysdev->hwmtx = sc->sc_hwmtx; in uart_bus_attach()
744 if (sc->sc_rxfifosz > 1) in uart_bus_attach()
747 "rx_overruns", CTLFLAG_RD, &sc->sc_rxoverruns, 0, in uart_bus_attach()
753 free(sc->sc_txbuf, M_UART); in uart_bus_attach()
754 free(sc->sc_rxbuf, M_UART); in uart_bus_attach()
756 if (sc->sc_ires != NULL) { in uart_bus_attach()
757 bus_teardown_intr(dev, sc->sc_ires, sc->sc_icookie); in uart_bus_attach()
758 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid, in uart_bus_attach()
759 sc->sc_ires); in uart_bus_attach()
761 bus_release_resource(dev, sc->sc_rtype, sc->sc_rrid, sc->sc_rres); in uart_bus_attach()
763 mtx_destroy(&sc->sc_hwmtx_s); in uart_bus_attach()
771 struct uart_softc *sc; in uart_bus_detach() local
773 sc = device_get_softc(dev); in uart_bus_detach()
775 sc->sc_leaving = 1; in uart_bus_detach()
777 if (sc->sc_sysdev != NULL) in uart_bus_detach()
778 sc->sc_sysdev->hwmtx = NULL; in uart_bus_detach()
780 UART_DETACH(sc); in uart_bus_detach()
782 if (sc->sc_sysdev != NULL && sc->sc_sysdev->detach != NULL) in uart_bus_detach()
783 (*sc->sc_sysdev->detach)(sc); in uart_bus_detach()
785 uart_tty_detach(sc); in uart_bus_detach()
787 free(sc->sc_txbuf, M_UART); in uart_bus_detach()
788 free(sc->sc_rxbuf, M_UART); in uart_bus_detach()
790 if (sc->sc_ires != NULL) { in uart_bus_detach()
791 bus_teardown_intr(dev, sc->sc_ires, sc->sc_icookie); in uart_bus_detach()
792 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid, in uart_bus_detach()
793 sc->sc_ires); in uart_bus_detach()
795 bus_release_resource(dev, sc->sc_rtype, sc->sc_rrid, sc->sc_rres); in uart_bus_detach()
797 mtx_destroy(&sc->sc_hwmtx_s); in uart_bus_detach()
799 if (sc->sc_class->size > device_get_driver(dev)->size) { in uart_bus_detach()
801 free(sc, M_UART); in uart_bus_detach()
810 struct uart_softc *sc; in uart_bus_resume() local
812 sc = device_get_softc(dev); in uart_bus_resume()
813 return (UART_ATTACH(sc)); in uart_bus_resume()
820 if (di->sc) in uart_grab()
821 UART_GRAB(di->sc); in uart_grab()
828 if (di->sc) in uart_ungrab()
829 UART_UNGRAB(di->sc); in uart_ungrab()