Lines Matching refs:sc

94 uart_pps_print_mode(struct uart_softc *sc)  in uart_pps_print_mode()  argument
97 device_printf(sc->sc_dev, "PPS capture mode: "); in uart_pps_print_mode()
98 switch(sc->sc_pps_mode & UART_PPS_SIGNAL_MASK) { in uart_pps_print_mode()
112 if (sc->sc_pps_mode & UART_PPS_INVERT_PULSE) in uart_pps_print_mode()
114 if (sc->sc_pps_mode & UART_PPS_NARROW_PULSE) in uart_pps_print_mode()
122 struct uart_softc *sc; in uart_pps_mode_sysctl() local
125 sc = arg1; in uart_pps_mode_sysctl()
126 tmp = sc->sc_pps_mode; in uart_pps_mode_sysctl()
132 sc->sc_pps_mode = tmp; in uart_pps_mode_sysctl()
137 uart_pps_process(struct uart_softc *sc, int ser_sig) in uart_pps_process() argument
143 switch(sc->sc_pps_mode & UART_PPS_SIGNAL_MASK) { in uart_pps_process()
168 pps_capture(&sc->sc_pps); in uart_pps_process()
169 if (sc->sc_pps_mode & UART_PPS_NARROW_PULSE) { in uart_pps_process()
171 if (now > sc->sc_pps_captime + 500 * SBT_1MS) { in uart_pps_process()
172 sc->sc_pps_captime = now; in uart_pps_process()
173 pps_event(&sc->sc_pps, PPS_CAPTUREASSERT); in uart_pps_process()
174 pps_event(&sc->sc_pps, PPS_CAPTURECLEAR); in uart_pps_process()
178 if (sc->sc_pps_mode & UART_PPS_INVERT_PULSE) in uart_pps_process()
180 pps_event(&sc->sc_pps, is_assert ? PPS_CAPTUREASSERT : in uart_pps_process()
186 uart_pps_init(struct uart_softc *sc) in uart_pps_init() argument
191 ctx = device_get_sysctl_ctx(sc->sc_dev); in uart_pps_init()
192 tree = device_get_sysctl_tree(sc->sc_dev); in uart_pps_init()
202 sc->sc_pps_mode = UART_PPS_CTS; in uart_pps_init()
204 sc->sc_pps_mode = UART_PPS_DCD; in uart_pps_init()
206 TUNABLE_INT_FETCH("hw.uart.pps_mode", &sc->sc_pps_mode); in uart_pps_init()
208 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, sc, 0, in uart_pps_init()
212 if (!uart_pps_mode_valid(sc->sc_pps_mode)) { in uart_pps_init()
213 device_printf(sc->sc_dev, in uart_pps_init()
215 sc->sc_pps_mode); in uart_pps_init()
216 sc->sc_pps_mode = UART_PPS_DISABLED; in uart_pps_init()
218 uart_pps_print_mode(sc); in uart_pps_init()
221 sc->sc_pps.ppscap = PPS_CAPTUREBOTH; in uart_pps_init()
222 sc->sc_pps.driver_mtx = uart_tty_getlock(sc); in uart_pps_init()
223 sc->sc_pps.driver_abi = PPS_ABI_VERSION; in uart_pps_init()
224 pps_init_abi(&sc->sc_pps); in uart_pps_init()
268 uart_sched_softih(struct uart_softc *sc, uint32_t ipend) in uart_sched_softih() argument
273 old = sc->sc_ttypend; in uart_sched_softih()
275 } while (!atomic_cmpset_32(&sc->sc_ttypend, old, new)); in uart_sched_softih()
278 swi_sched(sc->sc_softih, 0); in uart_sched_softih()
293 struct uart_softc *sc = arg; in uart_intr_break() local
296 if (sc->sc_sysdev != NULL && sc->sc_sysdev->type == UART_DEV_CONSOLE) { in uart_intr_break()
301 if (sc->sc_opened) in uart_intr_break()
302 uart_sched_softih(sc, SER_INT_BREAK); in uart_intr_break()
324 struct uart_softc *sc = arg; in uart_intr_overrun() local
326 if (sc->sc_opened) { in uart_intr_overrun()
327 UART_RECEIVE(sc); in uart_intr_overrun()
328 if (uart_rx_put(sc, UART_STAT_OVERRUN)) in uart_intr_overrun()
329 sc->sc_rxbuf[sc->sc_rxput] = UART_STAT_OVERRUN; in uart_intr_overrun()
330 uart_sched_softih(sc, SER_INT_RXREADY); in uart_intr_overrun()
332 sc->sc_rxoverruns++; in uart_intr_overrun()
333 UART_FLUSH(sc, UART_FLUSH_RECEIVER); in uart_intr_overrun()
343 struct uart_softc *sc = arg; in uart_intr_rxready() local
347 rxp = sc->sc_rxput; in uart_intr_rxready()
349 UART_RECEIVE(sc); in uart_intr_rxready()
351 if (sc->sc_sysdev != NULL && sc->sc_sysdev->type == UART_DEV_CONSOLE) { in uart_intr_rxready()
352 while (rxp != sc->sc_rxput) { in uart_intr_rxready()
353 kdb_alt_break(sc->sc_rxbuf[rxp++], &sc->sc_altbrk); in uart_intr_rxready()
354 if (rxp == sc->sc_rxbufsz) in uart_intr_rxready()
359 if (sc->sc_opened) in uart_intr_rxready()
360 uart_sched_softih(sc, SER_INT_RXREADY); in uart_intr_rxready()
362 sc->sc_rxput = sc->sc_rxget; /* Ignore received data. */ in uart_intr_rxready()
376 struct uart_softc *sc = arg; in uart_intr_sigchg() local
379 sig = UART_GETSIG(sc); in uart_intr_sigchg()
385 if (sc->sc_pps.ppsparam.mode & PPS_CAPTUREBOTH) { in uart_intr_sigchg()
386 uart_pps_process(sc, sig); in uart_intr_sigchg()
397 old = sc->sc_ttypend; in uart_intr_sigchg()
400 } while (!atomic_cmpset_32(&sc->sc_ttypend, old, new)); in uart_intr_sigchg()
402 if (sc->sc_opened) in uart_intr_sigchg()
403 uart_sched_softih(sc, SER_INT_SIGCHG); in uart_intr_sigchg()
413 struct uart_softc *sc = arg; in uart_intr_txidle() local
415 if (sc->sc_txbusy) { in uart_intr_txidle()
416 sc->sc_txbusy = 0; in uart_intr_txidle()
417 uart_sched_softih(sc, SER_INT_TXIDLE); in uart_intr_txidle()
425 struct uart_softc *sc = arg; in uart_intr() local
428 if (sc->sc_leaving) in uart_intr()
432 testintr = sc->sc_testintr; in uart_intr()
433 while ((!testintr || cnt < 20) && (ipend = UART_IPEND(sc)) != 0) { in uart_intr()
436 uart_intr_overrun(sc); in uart_intr()
438 uart_intr_break(sc); in uart_intr()
440 uart_intr_rxready(sc); in uart_intr()
442 uart_intr_sigchg(sc); in uart_intr()
444 uart_intr_txidle(sc); in uart_intr()
447 if (sc->sc_polled) { in uart_intr()
448 callout_reset(&sc->sc_timer, hz / uart_poll_freq, in uart_intr()
449 (callout_func_t *)uart_intr, sc); in uart_intr()
479 struct uart_softc *sc; in uart_bus_ipend() local
481 sc = device_get_softc(dev); in uart_bus_ipend()
482 return (UART_IPEND(sc)); in uart_bus_ipend()
488 struct uart_softc *sc; in uart_bus_sysdev() local
490 sc = device_get_softc(dev); in uart_bus_sysdev()
491 return ((sc->sc_sysdev != NULL) ? 1 : 0); in uart_bus_sysdev()
497 struct uart_softc *sc; in uart_bus_probe() local
501 sc = device_get_softc(dev); in uart_bus_probe()
507 if (sc->sc_class == NULL) in uart_bus_probe()
517 kobj_init((kobj_t)sc, (kobj_class_t)sc->sc_class); in uart_bus_probe()
518 sc->sc_dev = dev; in uart_bus_probe()
520 device_set_desc(dev, uart_getname(sc->sc_class)); in uart_bus_probe()
529 sc->sc_rrid = rid; in uart_bus_probe()
530 sc->sc_rtype = SYS_RES_IOPORT; in uart_bus_probe()
531 sc->sc_rres = bus_alloc_resource_any(dev, sc->sc_rtype, &sc->sc_rrid, in uart_bus_probe()
533 if (sc->sc_rres == NULL) { in uart_bus_probe()
534 sc->sc_rrid = rid; in uart_bus_probe()
535 sc->sc_rtype = SYS_RES_MEMORY; in uart_bus_probe()
536 sc->sc_rres = bus_alloc_resource_any(dev, sc->sc_rtype, in uart_bus_probe()
537 &sc->sc_rrid, RF_ACTIVE); in uart_bus_probe()
538 if (sc->sc_rres == NULL) in uart_bus_probe()
549 sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres); in uart_bus_probe()
550 sc->sc_bas.bst = rman_get_bustag(sc->sc_rres); in uart_bus_probe()
551 sc->sc_bas.chan = chan; in uart_bus_probe()
552 sc->sc_bas.regshft = regshft; in uart_bus_probe()
553 sc->sc_bas.regiowidth = regiowidth; in uart_bus_probe()
554 sc->sc_bas.rclk = (rclk == 0) ? sc->sc_class->uc_rclk : rclk; in uart_bus_probe()
555 sc->sc_bas.busy_detect = !!(quirks & UART_F_BUSY_DETECT); in uart_bus_probe()
559 uart_cpu_eqres(&sc->sc_bas, &sysdev->bas)) { in uart_bus_probe()
561 sc->sc_sysdev = sysdev; in uart_bus_probe()
564 sc->sc_bas.rclk = sysdev->bas.rclk; in uart_bus_probe()
567 sysdev->bas.rclk = sc->sc_bas.rclk; in uart_bus_probe()
572 error = UART_PROBE(sc); in uart_bus_probe()
573 bus_release_resource(dev, sc->sc_rtype, sc->sc_rrid, sc->sc_rres); in uart_bus_probe()
580 struct uart_softc *sc, *sc0; in uart_bus_attach() local
592 sc = malloc(sc0->sc_class->size, M_UART, M_WAITOK|M_ZERO); in uart_bus_attach()
593 bcopy(sc0, sc, sizeof(*sc)); in uart_bus_attach()
594 device_set_softc(dev, sc); in uart_bus_attach()
596 sc = sc0; in uart_bus_attach()
602 if (sc->sc_sysdev != NULL) in uart_bus_attach()
603 sc->sc_sysdev->sc = sc; in uart_bus_attach()
610 sc->sc_leaving = 1; in uart_bus_attach()
612 mtx_init(&sc->sc_hwmtx_s, "uart_hwmtx", NULL, MTX_SPIN); in uart_bus_attach()
613 if (sc->sc_hwmtx == NULL) in uart_bus_attach()
614 sc->sc_hwmtx = &sc->sc_hwmtx_s; in uart_bus_attach()
620 sc->sc_rres = bus_alloc_resource_any(dev, sc->sc_rtype, &sc->sc_rrid, in uart_bus_attach()
622 if (sc->sc_rres == NULL) { in uart_bus_attach()
623 mtx_destroy(&sc->sc_hwmtx_s); in uart_bus_attach()
626 sc->sc_bas.bsh = rman_get_bushandle(sc->sc_rres); in uart_bus_attach()
627 sc->sc_bas.bst = rman_get_bustag(sc->sc_rres); in uart_bus_attach()
635 sc->sc_rxbufsz = MAX(384, sc->sc_rxfifosz * 3); in uart_bus_attach()
636 sc->sc_rxbuf = malloc(sc->sc_rxbufsz * sizeof(*sc->sc_rxbuf), in uart_bus_attach()
638 sc->sc_txbuf = malloc(sc->sc_txfifosz * sizeof(*sc->sc_txbuf), in uart_bus_attach()
641 error = UART_ATTACH(sc); in uart_bus_attach()
645 if (sc->sc_hwiflow || sc->sc_hwoflow) { in uart_bus_attach()
648 if (sc->sc_hwiflow) { in uart_bus_attach()
652 if (sc->sc_hwoflow) { in uart_bus_attach()
659 if (sc->sc_sysdev != NULL) { in uart_bus_attach()
660 if (sc->sc_sysdev->baudrate == 0) { in uart_bus_attach()
661 if (UART_IOCTL(sc, UART_IOCTL_BAUD, in uart_bus_attach()
662 (intptr_t)&sc->sc_sysdev->baudrate) != 0) in uart_bus_attach()
663 sc->sc_sysdev->baudrate = -1; in uart_bus_attach()
665 switch (sc->sc_sysdev->type) { in uart_bus_attach()
679 printf(" (%d,%c,%d,%d)\n", sc->sc_sysdev->baudrate, in uart_bus_attach()
680 "noems"[sc->sc_sysdev->parity], sc->sc_sysdev->databits, in uart_bus_attach()
681 sc->sc_sysdev->stopbits); in uart_bus_attach()
684 sc->sc_leaving = 0; in uart_bus_attach()
685 sc->sc_testintr = 1; in uart_bus_attach()
686 filt = uart_intr(sc); in uart_bus_attach()
687 sc->sc_testintr = 0; in uart_bus_attach()
695 sc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ, in uart_bus_attach()
696 &sc->sc_irid, RF_ACTIVE | RF_SHAREABLE); in uart_bus_attach()
698 if (sc->sc_ires != NULL) { in uart_bus_attach()
699 error = bus_setup_intr(dev, sc->sc_ires, INTR_TYPE_TTY, in uart_bus_attach()
700 uart_intr, NULL, sc, &sc->sc_icookie); in uart_bus_attach()
701 sc->sc_fastintr = (error == 0) ? 1 : 0; in uart_bus_attach()
703 if (!sc->sc_fastintr) in uart_bus_attach()
704 error = bus_setup_intr(dev, sc->sc_ires, in uart_bus_attach()
706 (driver_intr_t *)uart_intr, sc, &sc->sc_icookie); in uart_bus_attach()
710 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid, in uart_bus_attach()
711 sc->sc_ires); in uart_bus_attach()
712 sc->sc_ires = NULL; in uart_bus_attach()
715 if (sc->sc_ires == NULL) { in uart_bus_attach()
717 sc->sc_polled = 1; in uart_bus_attach()
718 callout_init(&sc->sc_timer, 1); in uart_bus_attach()
719 callout_reset(&sc->sc_timer, hz / uart_poll_freq, in uart_bus_attach()
720 (callout_func_t *)uart_intr, sc); in uart_bus_attach()
723 if (bootverbose && (sc->sc_fastintr || sc->sc_polled)) { in uart_bus_attach()
726 if (sc->sc_fastintr) { in uart_bus_attach()
730 if (sc->sc_polled) { in uart_bus_attach()
737 if (sc->sc_sysdev != NULL && sc->sc_sysdev->attach != NULL) { in uart_bus_attach()
738 if ((error = sc->sc_sysdev->attach(sc)) != 0) in uart_bus_attach()
741 if ((error = uart_tty_attach(sc)) != 0) in uart_bus_attach()
743 uart_pps_init(sc); in uart_bus_attach()
746 if (sc->sc_sysdev != NULL) in uart_bus_attach()
747 sc->sc_sysdev->hwmtx = sc->sc_hwmtx; in uart_bus_attach()
749 if (sc->sc_rxfifosz > 1) in uart_bus_attach()
752 "rx_overruns", CTLFLAG_RD, &sc->sc_rxoverruns, 0, in uart_bus_attach()
757 "rclk", CTLFLAG_RD, &sc->sc_bas.rclk, 0, in uart_bus_attach()
763 free(sc->sc_txbuf, M_UART); in uart_bus_attach()
764 free(sc->sc_rxbuf, M_UART); in uart_bus_attach()
766 if (sc->sc_ires != NULL) { in uart_bus_attach()
767 bus_teardown_intr(dev, sc->sc_ires, sc->sc_icookie); in uart_bus_attach()
768 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid, in uart_bus_attach()
769 sc->sc_ires); in uart_bus_attach()
771 bus_release_resource(dev, sc->sc_rtype, sc->sc_rrid, sc->sc_rres); in uart_bus_attach()
773 mtx_destroy(&sc->sc_hwmtx_s); in uart_bus_attach()
781 struct uart_softc *sc; in uart_bus_detach() local
783 sc = device_get_softc(dev); in uart_bus_detach()
785 sc->sc_leaving = 1; in uart_bus_detach()
787 if (sc->sc_sysdev != NULL) in uart_bus_detach()
788 sc->sc_sysdev->hwmtx = NULL; in uart_bus_detach()
790 UART_DETACH(sc); in uart_bus_detach()
792 if (sc->sc_sysdev != NULL && sc->sc_sysdev->detach != NULL) in uart_bus_detach()
793 (*sc->sc_sysdev->detach)(sc); in uart_bus_detach()
795 uart_tty_detach(sc); in uart_bus_detach()
797 free(sc->sc_txbuf, M_UART); in uart_bus_detach()
798 free(sc->sc_rxbuf, M_UART); in uart_bus_detach()
800 if (sc->sc_ires != NULL) { in uart_bus_detach()
801 bus_teardown_intr(dev, sc->sc_ires, sc->sc_icookie); in uart_bus_detach()
802 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irid, in uart_bus_detach()
803 sc->sc_ires); in uart_bus_detach()
805 bus_release_resource(dev, sc->sc_rtype, sc->sc_rrid, sc->sc_rres); in uart_bus_detach()
807 mtx_destroy(&sc->sc_hwmtx_s); in uart_bus_detach()
809 if (sc->sc_class->size > device_get_driver(dev)->size) { in uart_bus_detach()
811 free(sc, M_UART); in uart_bus_detach()
820 struct uart_softc *sc; in uart_bus_resume() local
822 sc = device_get_softc(dev); in uart_bus_resume()
823 return (UART_ATTACH(sc)); in uart_bus_resume()
830 if (di->sc) in uart_grab()
831 UART_GRAB(di->sc); in uart_grab()
838 if (di->sc) in uart_ungrab()
839 UART_UNGRAB(di->sc); in uart_ungrab()