Lines Matching +full:broken +full:- +full:turn +full:- +full:around

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
102 while ((inb(stat) & LSR_THRE) == 0 && --limit > 0)
160 return (16000000 * divisor / bas->rclk);
161 return (16000 * divisor / (bas->rclk / 1000));
179 error = ((actual_baud - baudrate) * 2000 / baudrate + 1) / 2;
182 if (error < -UART_DEV_TOLERANCE_PCT || error > UART_DEV_TOLERANCE_PCT)
198 * an infinite loop when the hardware is broken. Make the
202 while ((uart_getreg(bas, REG_LSR) & LSR_TEMT) == 0 && --limit)
213 * an infinite loop when the hardware is broken. Make the
224 while (limit && (uart_getreg(bas, REG_LSR) & LSR_RXRDY) && --limit) {
228 } while ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) && --limit);
233 /* printf("uart: ns8250: receiver appears broken... "); */
261 * Detect and work around emulated UARTs which don't implement the
264 * Firecracker VMM, aka. the rust-vmm/vm-superio emulation code:
265 * https://github.com/rust-vmm/vm-superio/issues/83
273 printf("uart: ns8250: UART FCR is broken\n");
285 /* Don't change settings when running on Hyper-V */
303 if (baudrate > 0 && bas->rclk > 0) {
304 divisor = ns8250_divisor(bas->rclk, baudrate);
321 * Low-level UART interface.
370 * UARTs split the receive time-out interrupt bit out separately as
384 if (bas->rclk_guess && bas->rclk == 0 && baudrate != 0) {
388 bas->rclk = baudrate * div * 16;
396 if (bas->rclk == 0 && baudrate != 0)
397 bas->rclk = DEFAULT_RCLK;
428 while ((uart_getreg(bas, REG_LSR) & LSR_THRE) == 0 && --limit)
492 * XXX -- refactor out ACPI and FDT ifdefs
505 {"PNP0501", &uart_ns8250_class, 0, 0, 0, 0, 0, "16550A-compatible COM port"},
506 {"PNP0502", &uart_ns8250_class, 0, 0, 0, 0, 0, "Multiport serial device (non-intelligent 16550)"},
507 {"PNP0510", &uart_ns8250_class, 0, 0, 0, 0, 0, "Generic IRDA-compatible device"},
508 {"PNP0511", &uart_ns8250_class, 0, 0, 0, 0, 0, "Generic IRDA-compatible device"},
526 /* Use token-pasting to form SER_ and MSR_ named constants. */
574 /* Check whether uart has a broken txfifo. */
575 node = ofw_bus_get_node(sc->sc_dev);
576 if ((OF_getencprop(node, "broken-txfifo", &cell, sizeof(cell))) > 0)
580 bas = &sc->sc_bas;
582 ns8250->busy_detect = bas->busy_detect;
583 ns8250->mcr = uart_getreg(bas, REG_MCR);
584 ns8250->fcr = FCR_ENABLE;
585 if (!resource_int_value("uart", device_get_unit(sc->sc_dev), "flags",
588 ns8250->fcr |= FCR_RX_LOW;
590 ns8250->fcr |= FCR_RX_MEDL;
592 ns8250->fcr |= FCR_RX_HIGH;
594 ns8250->fcr |= FCR_RX_MEDH;
596 ns8250->fcr |= FCR_RX_MEDH;
600 resource_int_value("uart", device_get_unit(sc->sc_dev), "ier_mask",
602 ns8250->ier_mask = (uint8_t)(ivar & 0xff);
606 resource_int_value("uart", device_get_unit(sc->sc_dev), "ier_rxbits",
608 ns8250->ier_rxbits = (uint8_t)(ivar & 0xff);
610 uart_setreg(bas, REG_FCR, ns8250->fcr);
614 if (ns8250->mcr & MCR_DTR)
615 sc->sc_hwsig |= SER_DTR;
616 if (ns8250->mcr & MCR_RTS)
617 sc->sc_hwsig |= SER_RTS;
621 ns8250->ier = uart_getreg(bas, REG_IER) & ns8250->ier_mask;
622 ns8250->ier |= ns8250->ier_rxbits;
623 uart_setreg(bas, REG_IER, ns8250->ier);
631 * ns8250_bus_ipend() -- which it accidentally had before r253161.
649 bas = &sc->sc_bas;
650 ier = uart_getreg(bas, REG_IER) & ns8250->ier_mask;
664 bas = &sc->sc_bas;
665 uart_lock(sc->sc_hwmtx);
666 if (sc->sc_rxfifosz > 1) {
668 uart_setreg(bas, REG_FCR, ns8250->fcr);
673 uart_unlock(sc->sc_hwmtx);
684 * The delta bits are reputed to be broken on some hardware, so use
689 * other (non-MSR) bits in sc_hwsig, so loop until it can successfully
695 old = sc->sc_hwsig;
697 uart_lock(sc->sc_hwmtx);
698 msr = uart_getreg(&sc->sc_bas, REG_MSR);
699 uart_unlock(sc->sc_hwmtx);
700 if (sc->sc_pps_mode & UART_PPS_NARROW_PULSE) {
710 } while (!atomic_cmpset_32(&sc->sc_hwsig, old, sig & ~SER_MASK_DELTA));
721 bas = &sc->sc_bas;
723 uart_lock(sc->sc_hwmtx);
766 baudrate = (divisor > 0) ? bas->rclk / divisor / 16 : 0;
776 uart_unlock(sc->sc_hwmtx);
789 bas = &sc->sc_bas;
790 uart_lock(sc->sc_hwmtx);
793 if (ns8250->busy_detect && (iir & IIR_BUSY) == IIR_BUSY) {
795 uart_unlock(sc->sc_hwmtx);
799 uart_unlock(sc->sc_hwmtx);
814 ns8250->ier &= ~IER_ETXRDY;
815 uart_setreg(bas, REG_IER, ns8250->ier);
822 uart_unlock(sc->sc_hwmtx);
835 bas = &sc->sc_bas;
836 uart_lock(sc->sc_hwmtx);
842 if (ns8250->busy_detect != 0) {
845 * an infinite loop in case when the hardware is broken.
849 --limit)
854 uart_unlock(sc->sc_hwmtx);
860 uart_unlock(sc->sc_hwmtx);
871 bas = &sc->sc_bas;
878 if (sc->sc_sysdev == NULL) {
891 * avoid the possibility that automatic flow-control prevents
911 sc->sc_rxfifosz = sc->sc_txfifosz = 1;
912 device_set_desc(sc->sc_dev, "8250 or 16450 or compatible");
950 --limit)
963 count--;
972 sc->sc_rxfifosz = 16;
973 device_set_desc(sc->sc_dev, "16550 or compatible");
975 sc->sc_rxfifosz = 32;
976 device_set_desc(sc->sc_dev, "16650 or compatible");
978 sc->sc_rxfifosz = 64;
979 device_set_desc(sc->sc_dev, "16750 or compatible");
981 sc->sc_rxfifosz = 128;
982 device_set_desc(sc->sc_dev, "16950 or compatible");
984 sc->sc_rxfifosz = 256;
985 device_set_desc(sc->sc_dev, "16x50 with 256 byte FIFO");
987 sc->sc_rxfifosz = 16;
988 device_set_desc(sc->sc_dev,
989 "Non-standard ns8250 class UART with FIFOs");
997 sc->sc_txfifosz = 16;
1007 if (sc->sc_rxfifosz > 16) {
1008 sc->sc_hwiflow = 1;
1009 sc->sc_hwoflow = 1;
1024 bas = &sc->sc_bas;
1025 uart_lock(sc->sc_hwmtx);
1029 sc->sc_rxbuf[sc->sc_rxput] = UART_STAT_OVERRUN;
1039 if (++ns8250->noise_count >= uart_noise_threshold)
1042 ns8250->noise_count = 0;
1057 uart_unlock(sc->sc_hwmtx);
1068 bas = &sc->sc_bas;
1070 old = sc->sc_hwsig;
1078 } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new));
1079 uart_lock(sc->sc_hwmtx);
1080 ns8250->mcr &= ~(MCR_DTR|MCR_RTS);
1082 ns8250->mcr |= MCR_DTR;
1084 ns8250->mcr |= MCR_RTS;
1085 uart_setreg(bas, REG_MCR, ns8250->mcr);
1087 uart_unlock(sc->sc_hwmtx);
1098 bas = &sc->sc_bas;
1099 uart_lock(sc->sc_hwmtx);
1102 for (i = 0; i < sc->sc_txdatasz; i++) {
1103 uart_setreg(bas, REG_DATA, sc->sc_txbuf[i]);
1107 ns8250->ier |= IER_ETXRDY;
1108 uart_setreg(bas, REG_IER, ns8250->ier);
1113 sc->sc_txbusy = 1;
1114 uart_unlock(sc->sc_hwmtx);
1123 struct uart_bas *bas = &sc->sc_bas;
1134 struct uart_bas *bas = &sc->sc_bas;
1139 * turn off all interrupts to enter polling mode. Leave the
1143 uart_lock(sc->sc_hwmtx);
1145 uart_setreg(bas, REG_IER, ier & ns8250->ier_mask);
1147 uart_unlock(sc->sc_hwmtx);
1154 struct uart_bas *bas = &sc->sc_bas;
1159 uart_lock(sc->sc_hwmtx);
1160 uart_setreg(bas, REG_IER, ns8250->ier);
1162 uart_unlock(sc->sc_hwmtx);