2 * Copyright (c) 2003 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
34 #include <machine/bus.h>
35 #include <machine/fdt.h>
37 #include <dev/uart/uart.h>
38 #include <dev/uart/uart_cpu.h>
39 #include <dev/uart/uart_bus.h>
41 #include <dev/ic/ns16550.h>
42 #include <arm/lpc/lpcreg.h>
46 #define DEFAULT_RCLK (13 * 1000 * 1000)
48 static bus_space_handle_t bsh_clkpwr;
50 #define lpc_ns8250_get_clkreg(_bas, _reg) \
51 bus_space_read_4(fdtbus_bs_tag, bsh_clkpwr, (_reg))
52 #define lpc_ns8250_set_clkreg(_bas, _reg, _val) \
53 bus_space_write_4(fdtbus_bs_tag, bsh_clkpwr, (_reg), (_val))
56 * Clear pending interrupts. THRE is cleared by reading IIR. Data
57 * that may have been received gets lost here.
60 lpc_ns8250_clrint(struct uart_bas *bas)
64 iir = uart_getreg(bas, REG_IIR);
65 while ((iir & IIR_NOPEND) == 0) {
68 lsr = uart_getreg(bas, REG_LSR);
69 if (lsr & (LSR_BI|LSR_FE|LSR_PE))
70 (void)uart_getreg(bas, REG_DATA);
71 } else if (iir == IIR_RXRDY || iir == IIR_RXTOUT)
72 (void)uart_getreg(bas, REG_DATA);
73 else if (iir == IIR_MLSC)
74 (void)uart_getreg(bas, REG_MSR);
76 iir = uart_getreg(bas, REG_IIR);
81 lpc_ns8250_delay(struct uart_bas *bas)
86 uclk = lpc_ns8250_get_clkreg(bas, LPC_CLKPWR_UART_U5CLK);
88 x = (uclk >> 8) & 0xff;
91 return (16000000 / (bas->rclk * x / y));
95 lpc_ns8250_divisor(int rclk, int baudrate, int *x, int *y)
140 lpc_ns8250_drain(struct uart_bas *bas, int what)
144 delay = lpc_ns8250_delay(bas);
146 if (what & UART_DRAIN_TRANSMITTER) {
148 * Pick an arbitrary high limit to avoid getting stuck in
149 * an infinite loop when the hardware is broken. Make the
150 * limit high enough to handle large FIFOs.
153 while ((uart_getreg(bas, REG_LSR) & LSR_TEMT) == 0 && --limit)
156 /* printf("lpc_ns8250: transmitter appears stuck... "); */
161 if (what & UART_DRAIN_RECEIVER) {
163 * Pick an arbitrary high limit to avoid getting stuck in
164 * an infinite loop when the hardware is broken. Make the
165 * limit high enough to handle large FIFOs and integrated
166 * UARTs. The HP rx2600 for example has 3 UARTs on the
167 * management board that tend to get a lot of data send
168 * to it when the UART is first activated.
171 while ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) && --limit) {
172 (void)uart_getreg(bas, REG_DATA);
177 /* printf("lpc_ns8250: receiver appears broken... "); */
186 * We can only flush UARTs with FIFOs. UARTs without FIFOs should be
187 * drained. WARNING: this function clobbers the FIFO setting!
190 lpc_ns8250_flush(struct uart_bas *bas, int what)
195 if (what & UART_FLUSH_TRANSMITTER)
197 if (what & UART_FLUSH_RECEIVER)
199 uart_setreg(bas, REG_FCR, fcr);
204 lpc_ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits,
213 else if (databits == 7)
215 else if (databits == 6)
225 uart_setreg(bas, REG_LCR, lcr | LCR_DLAB);
227 uart_setreg(bas, REG_DLL, 0x00);
228 uart_setreg(bas, REG_DLH, 0x00);
231 lpc_ns8250_divisor(bas->rclk, baudrate, &xdiv, &ydiv);
232 lpc_ns8250_set_clkreg(bas,
233 LPC_CLKPWR_UART_U5CLK,
234 LPC_CLKPWR_UART_UCLK_X(xdiv) |
235 LPC_CLKPWR_UART_UCLK_Y(ydiv));
238 /* Set LCR and clear DLAB. */
239 uart_setreg(bas, REG_LCR, lcr);
245 * Low-level UART interface.
247 static int lpc_ns8250_probe(struct uart_bas *bas);
248 static void lpc_ns8250_init(struct uart_bas *bas, int, int, int, int);
249 static void lpc_ns8250_term(struct uart_bas *bas);
250 static void lpc_ns8250_putc(struct uart_bas *bas, int);
251 static int lpc_ns8250_rxready(struct uart_bas *bas);
252 static int lpc_ns8250_getc(struct uart_bas *bas, struct mtx *);
254 static struct uart_ops uart_lpc_ns8250_ops = {
255 .probe = lpc_ns8250_probe,
256 .init = lpc_ns8250_init,
257 .term = lpc_ns8250_term,
258 .putc = lpc_ns8250_putc,
259 .rxready = lpc_ns8250_rxready,
260 .getc = lpc_ns8250_getc,
264 lpc_ns8250_probe(struct uart_bas *bas)
269 /* Check known 0 bits that don't depend on DLAB. */
270 val = uart_getreg(bas, REG_IIR);
274 * Bit 6 of the MCR (= 0x40) appears to be 1 for the Sun1699
275 * chip, but otherwise doesn't seem to have a function. In
276 * other words, uart(4) works regardless. Ignore that bit so
277 * the probe succeeds.
279 val = uart_getreg(bas, REG_MCR);
287 lpc_ns8250_init(struct uart_bas *bas, int baudrate, int databits, int stopbits,
293 /* Enable UART clock */
294 bus_space_map(fdtbus_bs_tag, LPC_CLKPWR_PHYS_BASE, LPC_CLKPWR_SIZE, 0,
296 clkmode = lpc_ns8250_get_clkreg(bas, LPC_UART_CLKMODE);
297 lpc_ns8250_set_clkreg(bas, LPC_UART_CLKMODE, clkmode |
298 LPC_UART_CLKMODE_UART5(1));
301 /* Work around H/W bug */
302 uart_setreg(bas, REG_DATA, 0x00);
305 bas->rclk = DEFAULT_RCLK;
306 lpc_ns8250_param(bas, baudrate, databits, stopbits, parity);
308 /* Disable all interrupt sources. */
310 * We use 0xe0 instead of 0xf0 as the mask because the XScale PXA
311 * UARTs split the receive time-out interrupt bit out separately as
312 * 0x10. This gets handled by ier_mask and ier_rxbits below.
314 ier = uart_getreg(bas, REG_IER) & 0xe0;
315 uart_setreg(bas, REG_IER, ier);
318 /* Disable the FIFO (if present). */
319 uart_setreg(bas, REG_FCR, 0);
323 uart_setreg(bas, REG_MCR, MCR_IE | MCR_RTS | MCR_DTR);
326 lpc_ns8250_clrint(bas);
330 lpc_ns8250_term(struct uart_bas *bas)
333 /* Clear RTS & DTR. */
334 uart_setreg(bas, REG_MCR, MCR_IE);
339 lpc_ns8250_putc(struct uart_bas *bas, int c)
344 while ((uart_getreg(bas, REG_LSR) & LSR_THRE) == 0 && --limit)
346 uart_setreg(bas, REG_DATA, c);
349 while ((uart_getreg(bas, REG_LSR) & LSR_TEMT) == 0 && --limit)
354 lpc_ns8250_rxready(struct uart_bas *bas)
357 return ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) != 0 ? 1 : 0);
361 lpc_ns8250_getc(struct uart_bas *bas, struct mtx *hwmtx)
367 while ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) == 0) {
373 c = uart_getreg(bas, REG_DATA);
381 * High-level UART interface.
383 struct lpc_ns8250_softc {
384 struct uart_softc base;
393 static int lpc_ns8250_bus_attach(struct uart_softc *);
394 static int lpc_ns8250_bus_detach(struct uart_softc *);
395 static int lpc_ns8250_bus_flush(struct uart_softc *, int);
396 static int lpc_ns8250_bus_getsig(struct uart_softc *);
397 static int lpc_ns8250_bus_ioctl(struct uart_softc *, int, intptr_t);
398 static int lpc_ns8250_bus_ipend(struct uart_softc *);
399 static int lpc_ns8250_bus_param(struct uart_softc *, int, int, int, int);
400 static int lpc_ns8250_bus_probe(struct uart_softc *);
401 static int lpc_ns8250_bus_receive(struct uart_softc *);
402 static int lpc_ns8250_bus_setsig(struct uart_softc *, int);
403 static int lpc_ns8250_bus_transmit(struct uart_softc *);
404 static void lpc_ns8250_bus_grab(struct uart_softc *);
405 static void lpc_ns8250_bus_ungrab(struct uart_softc *);
407 static kobj_method_t lpc_ns8250_methods[] = {
408 KOBJMETHOD(uart_attach, lpc_ns8250_bus_attach),
409 KOBJMETHOD(uart_detach, lpc_ns8250_bus_detach),
410 KOBJMETHOD(uart_flush, lpc_ns8250_bus_flush),
411 KOBJMETHOD(uart_getsig, lpc_ns8250_bus_getsig),
412 KOBJMETHOD(uart_ioctl, lpc_ns8250_bus_ioctl),
413 KOBJMETHOD(uart_ipend, lpc_ns8250_bus_ipend),
414 KOBJMETHOD(uart_param, lpc_ns8250_bus_param),
415 KOBJMETHOD(uart_probe, lpc_ns8250_bus_probe),
416 KOBJMETHOD(uart_receive, lpc_ns8250_bus_receive),
417 KOBJMETHOD(uart_setsig, lpc_ns8250_bus_setsig),
418 KOBJMETHOD(uart_transmit, lpc_ns8250_bus_transmit),
419 KOBJMETHOD(uart_grab, lpc_ns8250_bus_grab),
420 KOBJMETHOD(uart_ungrab, lpc_ns8250_bus_ungrab),
424 struct uart_class uart_lpc_class = {
427 sizeof(struct lpc_ns8250_softc),
428 .uc_ops = &uart_lpc_ns8250_ops,
430 .uc_rclk = DEFAULT_RCLK
433 #define SIGCHG(c, i, s, d) \
435 i |= (i & s) ? s : s | d; \
437 i = (i & s) ? (i & ~s) | d : i; \
441 lpc_ns8250_bus_attach(struct uart_softc *sc)
443 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
444 struct uart_bas *bas;
449 lpc_ns8250->mcr = uart_getreg(bas, REG_MCR);
450 lpc_ns8250->fcr = FCR_ENABLE | FCR_DMA;
451 if (!resource_int_value("uart", device_get_unit(sc->sc_dev), "flags",
453 if (UART_FLAGS_FCR_RX_LOW(ivar))
454 lpc_ns8250->fcr |= FCR_RX_LOW;
455 else if (UART_FLAGS_FCR_RX_MEDL(ivar))
456 lpc_ns8250->fcr |= FCR_RX_MEDL;
457 else if (UART_FLAGS_FCR_RX_HIGH(ivar))
458 lpc_ns8250->fcr |= FCR_RX_HIGH;
460 lpc_ns8250->fcr |= FCR_RX_MEDH;
462 lpc_ns8250->fcr |= FCR_RX_HIGH;
466 resource_int_value("uart", device_get_unit(sc->sc_dev), "ier_mask",
468 lpc_ns8250->ier_mask = (uint8_t)(ivar & 0xff);
470 /* Get IER RX interrupt bits */
471 ivar = IER_EMSC | IER_ERLS | IER_ERXRDY;
472 resource_int_value("uart", device_get_unit(sc->sc_dev), "ier_rxbits",
474 lpc_ns8250->ier_rxbits = (uint8_t)(ivar & 0xff);
476 uart_setreg(bas, REG_FCR, lpc_ns8250->fcr);
478 lpc_ns8250_bus_flush(sc, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);
480 if (lpc_ns8250->mcr & MCR_DTR)
481 sc->sc_hwsig |= SER_DTR;
482 if (lpc_ns8250->mcr & MCR_RTS)
483 sc->sc_hwsig |= SER_RTS;
484 lpc_ns8250_bus_getsig(sc);
486 lpc_ns8250_clrint(bas);
487 lpc_ns8250->ier = uart_getreg(bas, REG_IER) & lpc_ns8250->ier_mask;
488 lpc_ns8250->ier |= lpc_ns8250->ier_rxbits;
489 uart_setreg(bas, REG_IER, lpc_ns8250->ier);
496 lpc_ns8250_bus_detach(struct uart_softc *sc)
498 struct lpc_ns8250_softc *lpc_ns8250;
499 struct uart_bas *bas;
502 lpc_ns8250 = (struct lpc_ns8250_softc *)sc;
504 ier = uart_getreg(bas, REG_IER) & lpc_ns8250->ier_mask;
505 uart_setreg(bas, REG_IER, ier);
507 lpc_ns8250_clrint(bas);
512 lpc_ns8250_bus_flush(struct uart_softc *sc, int what)
514 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
515 struct uart_bas *bas;
519 uart_lock(sc->sc_hwmtx);
520 if (sc->sc_rxfifosz > 1) {
521 lpc_ns8250_flush(bas, what);
522 uart_setreg(bas, REG_FCR, lpc_ns8250->fcr);
526 error = lpc_ns8250_drain(bas, what);
527 uart_unlock(sc->sc_hwmtx);
532 lpc_ns8250_bus_getsig(struct uart_softc *sc)
534 uint32_t new, old, sig;
540 uart_lock(sc->sc_hwmtx);
541 msr = uart_getreg(&sc->sc_bas, REG_MSR);
542 uart_unlock(sc->sc_hwmtx);
543 SIGCHG(msr & MSR_DSR, sig, SER_DSR, SER_DDSR);
544 SIGCHG(msr & MSR_CTS, sig, SER_CTS, SER_DCTS);
545 SIGCHG(msr & MSR_DCD, sig, SER_DCD, SER_DDCD);
546 SIGCHG(msr & MSR_RI, sig, SER_RI, SER_DRI);
547 new = sig & ~SER_MASK_DELTA;
548 } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new));
553 lpc_ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data)
555 struct uart_bas *bas;
556 int baudrate, divisor, error;
561 uart_lock(sc->sc_hwmtx);
563 case UART_IOCTL_BREAK:
564 lcr = uart_getreg(bas, REG_LCR);
569 uart_setreg(bas, REG_LCR, lcr);
572 case UART_IOCTL_IFLOW:
573 lcr = uart_getreg(bas, REG_LCR);
575 uart_setreg(bas, REG_LCR, 0xbf);
577 efr = uart_getreg(bas, REG_EFR);
582 uart_setreg(bas, REG_EFR, efr);
584 uart_setreg(bas, REG_LCR, lcr);
587 case UART_IOCTL_OFLOW:
588 lcr = uart_getreg(bas, REG_LCR);
590 uart_setreg(bas, REG_LCR, 0xbf);
592 efr = uart_getreg(bas, REG_EFR);
597 uart_setreg(bas, REG_EFR, efr);
599 uart_setreg(bas, REG_LCR, lcr);
602 case UART_IOCTL_BAUD:
603 lcr = uart_getreg(bas, REG_LCR);
604 uart_setreg(bas, REG_LCR, lcr | LCR_DLAB);
606 divisor = uart_getreg(bas, REG_DLL) |
607 (uart_getreg(bas, REG_DLH) << 8);
609 uart_setreg(bas, REG_LCR, lcr);
611 baudrate = (divisor > 0) ? bas->rclk / divisor / 16 : 0;
613 *(int*)data = baudrate;
621 uart_unlock(sc->sc_hwmtx);
626 lpc_ns8250_bus_ipend(struct uart_softc *sc)
628 struct uart_bas *bas;
629 struct lpc_ns8250_softc *lpc_ns8250;
633 lpc_ns8250 = (struct lpc_ns8250_softc *)sc;
635 uart_lock(sc->sc_hwmtx);
636 iir = uart_getreg(bas, REG_IIR);
637 if (iir & IIR_NOPEND) {
638 uart_unlock(sc->sc_hwmtx);
642 if (iir & IIR_RXRDY) {
643 lsr = uart_getreg(bas, REG_LSR);
645 ipend |= SER_INT_OVERRUN;
647 ipend |= SER_INT_BREAK;
649 ipend |= SER_INT_RXREADY;
651 if (iir & IIR_TXRDY) {
652 ipend |= SER_INT_TXIDLE;
653 uart_setreg(bas, REG_IER, lpc_ns8250->ier);
655 ipend |= SER_INT_SIGCHG;
658 lpc_ns8250_clrint(bas);
659 uart_unlock(sc->sc_hwmtx);
664 lpc_ns8250_bus_param(struct uart_softc *sc, int baudrate, int databits,
665 int stopbits, int parity)
667 struct uart_bas *bas;
671 uart_lock(sc->sc_hwmtx);
672 error = lpc_ns8250_param(bas, baudrate, databits, stopbits, parity);
673 uart_unlock(sc->sc_hwmtx);
678 lpc_ns8250_bus_probe(struct uart_softc *sc)
680 struct lpc_ns8250_softc *lpc_ns8250;
681 struct uart_bas *bas;
682 int count, delay, error, limit;
683 uint8_t lsr, mcr, ier;
685 lpc_ns8250 = (struct lpc_ns8250_softc *)sc;
688 error = lpc_ns8250_probe(bas);
693 if (sc->sc_sysdev == NULL) {
694 /* By using lpc_ns8250_init() we also set DTR and RTS. */
695 lpc_ns8250_init(bas, 115200, 8, 1, UART_PARITY_NONE);
697 mcr |= MCR_DTR | MCR_RTS;
699 error = lpc_ns8250_drain(bas, UART_DRAIN_TRANSMITTER);
704 * Set loopback mode. This avoids having garbage on the wire and
705 * also allows us send and receive data. We set DTR and RTS to
706 * avoid the possibility that automatic flow-control prevents
707 * any data from being sent.
709 uart_setreg(bas, REG_MCR, MCR_LOOPBACK | MCR_IE | MCR_DTR | MCR_RTS);
713 * Enable FIFOs. And check that the UART has them. If not, we're
714 * done. Since this is the first time we enable the FIFOs, we reset
717 uart_setreg(bas, REG_FCR, FCR_ENABLE);
719 if (!(uart_getreg(bas, REG_IIR) & IIR_FIFO_MASK)) {
721 * NS16450 or INS8250. We don't bother to differentiate
722 * between them. They're too old to be interesting.
724 uart_setreg(bas, REG_MCR, mcr);
726 sc->sc_rxfifosz = sc->sc_txfifosz = 1;
727 device_set_desc(sc->sc_dev, "8250 or 16450 or compatible");
731 uart_setreg(bas, REG_FCR, FCR_ENABLE | FCR_XMT_RST | FCR_RCV_RST);
735 delay = lpc_ns8250_delay(bas);
737 /* We have FIFOs. Drain the transmitter and receiver. */
738 error = lpc_ns8250_drain(bas, UART_DRAIN_RECEIVER|UART_DRAIN_TRANSMITTER);
740 uart_setreg(bas, REG_MCR, mcr);
741 uart_setreg(bas, REG_FCR, 0);
747 * We should have a sufficiently clean "pipe" to determine the
748 * size of the FIFOs. We send as much characters as is reasonable
749 * and wait for the overflow bit in the LSR register to be
750 * asserted, counting the characters as we send them. Based on
751 * that count we know the FIFO size.
754 uart_setreg(bas, REG_DATA, 0);
761 * LSR bits are cleared upon read, so we must accumulate
762 * them to be able to test LSR_OE below.
764 while (((lsr |= uart_getreg(bas, REG_LSR)) & LSR_TEMT) == 0 &&
768 ier = uart_getreg(bas, REG_IER) & lpc_ns8250->ier_mask;
769 uart_setreg(bas, REG_IER, ier);
770 uart_setreg(bas, REG_MCR, mcr);
771 uart_setreg(bas, REG_FCR, 0);
776 } while ((lsr & LSR_OE) == 0 && count < 130);
779 uart_setreg(bas, REG_MCR, mcr);
782 lpc_ns8250_flush(bas, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);
785 sc->sc_rxfifosz = 64;
786 device_set_desc(sc->sc_dev, "LPC32x0 UART with FIFOs");
789 * Force the Tx FIFO size to 16 bytes for now. We don't program the
790 * Tx trigger. Also, we assume that all data has been sent when the
793 sc->sc_txfifosz = 16;
797 * XXX there are some issues related to hardware flow control and
798 * it's likely that uart(4) is the cause. This basicly needs more
799 * investigation, but we avoid using for hardware flow control
802 /* 16650s or higher have automatic flow control. */
803 if (sc->sc_rxfifosz > 16) {
812 lpc_ns8250_bus_receive(struct uart_softc *sc)
814 struct uart_bas *bas;
819 uart_lock(sc->sc_hwmtx);
820 lsr = uart_getreg(bas, REG_LSR);
821 while (lsr & LSR_RXRDY) {
822 if (uart_rx_full(sc)) {
823 sc->sc_rxbuf[sc->sc_rxput] = UART_STAT_OVERRUN;
826 xc = uart_getreg(bas, REG_DATA);
828 xc |= UART_STAT_FRAMERR;
830 xc |= UART_STAT_PARERR;
832 lsr = uart_getreg(bas, REG_LSR);
834 /* Discard everything left in the Rx FIFO. */
835 while (lsr & LSR_RXRDY) {
836 (void)uart_getreg(bas, REG_DATA);
838 lsr = uart_getreg(bas, REG_LSR);
840 uart_unlock(sc->sc_hwmtx);
845 lpc_ns8250_bus_setsig(struct uart_softc *sc, int sig)
847 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
848 struct uart_bas *bas;
855 if (sig & SER_DDTR) {
856 SIGCHG(sig & SER_DTR, new, SER_DTR,
859 if (sig & SER_DRTS) {
860 SIGCHG(sig & SER_RTS, new, SER_RTS,
863 } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new));
864 uart_lock(sc->sc_hwmtx);
865 lpc_ns8250->mcr &= ~(MCR_DTR|MCR_RTS);
867 lpc_ns8250->mcr |= MCR_DTR;
869 lpc_ns8250->mcr |= MCR_RTS;
870 uart_setreg(bas, REG_MCR, lpc_ns8250->mcr);
872 uart_unlock(sc->sc_hwmtx);
877 lpc_ns8250_bus_transmit(struct uart_softc *sc)
879 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
880 struct uart_bas *bas;
884 uart_lock(sc->sc_hwmtx);
885 while ((uart_getreg(bas, REG_LSR) & LSR_THRE) == 0)
887 uart_setreg(bas, REG_IER, lpc_ns8250->ier | IER_ETXRDY);
889 for (i = 0; i < sc->sc_txdatasz; i++) {
890 uart_setreg(bas, REG_DATA, sc->sc_txbuf[i]);
894 uart_unlock(sc->sc_hwmtx);
899 lpc_ns8250_bus_grab(struct uart_softc *sc)
901 struct uart_bas *bas = &sc->sc_bas;
904 * turn off all interrupts to enter polling mode. Leave the
905 * saved mask alone. We'll restore whatever it was in ungrab.
906 * All pending interupt signals are reset when IER is set to 0.
908 uart_lock(sc->sc_hwmtx);
909 uart_setreg(bas, REG_IER, 0);
911 uart_unlock(sc->sc_hwmtx);
915 lpc_ns8250_bus_ungrab(struct uart_softc *sc)
917 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
918 struct uart_bas *bas = &sc->sc_bas;
921 * Restore previous interrupt mask
923 uart_lock(sc->sc_hwmtx);
924 uart_setreg(bas, REG_IER, lpc_ns8250->ier);
926 uart_unlock(sc->sc_hwmtx);