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_cpu_fdt.h>
40 #include <dev/uart/uart_bus.h>
42 #include <dev/ic/ns16550.h>
43 #include <arm/lpc/lpcreg.h>
47 #define DEFAULT_RCLK (13 * 1000 * 1000)
49 static bus_space_handle_t bsh_clkpwr;
51 #define lpc_ns8250_get_clkreg(_bas, _reg) \
52 bus_space_read_4(fdtbus_bs_tag, bsh_clkpwr, (_reg))
53 #define lpc_ns8250_set_clkreg(_bas, _reg, _val) \
54 bus_space_write_4(fdtbus_bs_tag, bsh_clkpwr, (_reg), (_val))
57 * Clear pending interrupts. THRE is cleared by reading IIR. Data
58 * that may have been received gets lost here.
61 lpc_ns8250_clrint(struct uart_bas *bas)
65 iir = uart_getreg(bas, REG_IIR);
66 while ((iir & IIR_NOPEND) == 0) {
69 lsr = uart_getreg(bas, REG_LSR);
70 if (lsr & (LSR_BI|LSR_FE|LSR_PE))
71 (void)uart_getreg(bas, REG_DATA);
72 } else if (iir == IIR_RXRDY || iir == IIR_RXTOUT)
73 (void)uart_getreg(bas, REG_DATA);
74 else if (iir == IIR_MLSC)
75 (void)uart_getreg(bas, REG_MSR);
77 iir = uart_getreg(bas, REG_IIR);
82 lpc_ns8250_delay(struct uart_bas *bas)
87 uclk = lpc_ns8250_get_clkreg(bas, LPC_CLKPWR_UART_U5CLK);
89 x = (uclk >> 8) & 0xff;
92 return (16000000 / (bas->rclk * x / y));
96 lpc_ns8250_divisor(int rclk, int baudrate, int *x, int *y)
141 lpc_ns8250_drain(struct uart_bas *bas, int what)
145 delay = lpc_ns8250_delay(bas);
147 if (what & UART_DRAIN_TRANSMITTER) {
149 * Pick an arbitrary high limit to avoid getting stuck in
150 * an infinite loop when the hardware is broken. Make the
151 * limit high enough to handle large FIFOs.
154 while ((uart_getreg(bas, REG_LSR) & LSR_TEMT) == 0 && --limit)
157 /* printf("lpc_ns8250: transmitter appears stuck... "); */
162 if (what & UART_DRAIN_RECEIVER) {
164 * Pick an arbitrary high limit to avoid getting stuck in
165 * an infinite loop when the hardware is broken. Make the
166 * limit high enough to handle large FIFOs and integrated
167 * UARTs. The HP rx2600 for example has 3 UARTs on the
168 * management board that tend to get a lot of data send
169 * to it when the UART is first activated.
172 while ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) && --limit) {
173 (void)uart_getreg(bas, REG_DATA);
178 /* printf("lpc_ns8250: receiver appears broken... "); */
187 * We can only flush UARTs with FIFOs. UARTs without FIFOs should be
188 * drained. WARNING: this function clobbers the FIFO setting!
191 lpc_ns8250_flush(struct uart_bas *bas, int what)
196 if (what & UART_FLUSH_TRANSMITTER)
198 if (what & UART_FLUSH_RECEIVER)
200 uart_setreg(bas, REG_FCR, fcr);
205 lpc_ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits,
214 else if (databits == 7)
216 else if (databits == 6)
226 uart_setreg(bas, REG_LCR, lcr | LCR_DLAB);
228 uart_setreg(bas, REG_DLL, 0x00);
229 uart_setreg(bas, REG_DLH, 0x00);
232 lpc_ns8250_divisor(bas->rclk, baudrate, &xdiv, &ydiv);
233 lpc_ns8250_set_clkreg(bas,
234 LPC_CLKPWR_UART_U5CLK,
235 LPC_CLKPWR_UART_UCLK_X(xdiv) |
236 LPC_CLKPWR_UART_UCLK_Y(ydiv));
239 /* Set LCR and clear DLAB. */
240 uart_setreg(bas, REG_LCR, lcr);
246 * Low-level UART interface.
248 static int lpc_ns8250_probe(struct uart_bas *bas);
249 static void lpc_ns8250_init(struct uart_bas *bas, int, int, int, int);
250 static void lpc_ns8250_term(struct uart_bas *bas);
251 static void lpc_ns8250_putc(struct uart_bas *bas, int);
252 static int lpc_ns8250_rxready(struct uart_bas *bas);
253 static int lpc_ns8250_getc(struct uart_bas *bas, struct mtx *);
255 static struct uart_ops uart_lpc_ns8250_ops = {
256 .probe = lpc_ns8250_probe,
257 .init = lpc_ns8250_init,
258 .term = lpc_ns8250_term,
259 .putc = lpc_ns8250_putc,
260 .rxready = lpc_ns8250_rxready,
261 .getc = lpc_ns8250_getc,
265 lpc_ns8250_probe(struct uart_bas *bas)
270 /* Check known 0 bits that don't depend on DLAB. */
271 val = uart_getreg(bas, REG_IIR);
275 * Bit 6 of the MCR (= 0x40) appears to be 1 for the Sun1699
276 * chip, but otherwise doesn't seem to have a function. In
277 * other words, uart(4) works regardless. Ignore that bit so
278 * the probe succeeds.
280 val = uart_getreg(bas, REG_MCR);
288 lpc_ns8250_init(struct uart_bas *bas, int baudrate, int databits, int stopbits,
294 /* Enable UART clock */
295 bus_space_map(fdtbus_bs_tag, LPC_CLKPWR_PHYS_BASE, LPC_CLKPWR_SIZE, 0,
297 clkmode = lpc_ns8250_get_clkreg(bas, LPC_UART_CLKMODE);
298 lpc_ns8250_set_clkreg(bas, LPC_UART_CLKMODE, clkmode |
299 LPC_UART_CLKMODE_UART5(1));
302 /* Work around H/W bug */
303 uart_setreg(bas, REG_DATA, 0x00);
306 bas->rclk = DEFAULT_RCLK;
307 lpc_ns8250_param(bas, baudrate, databits, stopbits, parity);
309 /* Disable all interrupt sources. */
311 * We use 0xe0 instead of 0xf0 as the mask because the XScale PXA
312 * UARTs split the receive time-out interrupt bit out separately as
313 * 0x10. This gets handled by ier_mask and ier_rxbits below.
315 ier = uart_getreg(bas, REG_IER) & 0xe0;
316 uart_setreg(bas, REG_IER, ier);
319 /* Disable the FIFO (if present). */
320 uart_setreg(bas, REG_FCR, 0);
324 uart_setreg(bas, REG_MCR, MCR_IE | MCR_RTS | MCR_DTR);
327 lpc_ns8250_clrint(bas);
331 lpc_ns8250_term(struct uart_bas *bas)
334 /* Clear RTS & DTR. */
335 uart_setreg(bas, REG_MCR, MCR_IE);
340 lpc_ns8250_putc(struct uart_bas *bas, int c)
345 while ((uart_getreg(bas, REG_LSR) & LSR_THRE) == 0 && --limit)
347 uart_setreg(bas, REG_DATA, c);
350 while ((uart_getreg(bas, REG_LSR) & LSR_TEMT) == 0 && --limit)
355 lpc_ns8250_rxready(struct uart_bas *bas)
358 return ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) != 0 ? 1 : 0);
362 lpc_ns8250_getc(struct uart_bas *bas, struct mtx *hwmtx)
368 while ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) == 0) {
374 c = uart_getreg(bas, REG_DATA);
382 * High-level UART interface.
384 struct lpc_ns8250_softc {
385 struct uart_softc base;
394 static int lpc_ns8250_bus_attach(struct uart_softc *);
395 static int lpc_ns8250_bus_detach(struct uart_softc *);
396 static int lpc_ns8250_bus_flush(struct uart_softc *, int);
397 static int lpc_ns8250_bus_getsig(struct uart_softc *);
398 static int lpc_ns8250_bus_ioctl(struct uart_softc *, int, intptr_t);
399 static int lpc_ns8250_bus_ipend(struct uart_softc *);
400 static int lpc_ns8250_bus_param(struct uart_softc *, int, int, int, int);
401 static int lpc_ns8250_bus_probe(struct uart_softc *);
402 static int lpc_ns8250_bus_receive(struct uart_softc *);
403 static int lpc_ns8250_bus_setsig(struct uart_softc *, int);
404 static int lpc_ns8250_bus_transmit(struct uart_softc *);
405 static void lpc_ns8250_bus_grab(struct uart_softc *);
406 static void lpc_ns8250_bus_ungrab(struct uart_softc *);
408 static kobj_method_t lpc_ns8250_methods[] = {
409 KOBJMETHOD(uart_attach, lpc_ns8250_bus_attach),
410 KOBJMETHOD(uart_detach, lpc_ns8250_bus_detach),
411 KOBJMETHOD(uart_flush, lpc_ns8250_bus_flush),
412 KOBJMETHOD(uart_getsig, lpc_ns8250_bus_getsig),
413 KOBJMETHOD(uart_ioctl, lpc_ns8250_bus_ioctl),
414 KOBJMETHOD(uart_ipend, lpc_ns8250_bus_ipend),
415 KOBJMETHOD(uart_param, lpc_ns8250_bus_param),
416 KOBJMETHOD(uart_probe, lpc_ns8250_bus_probe),
417 KOBJMETHOD(uart_receive, lpc_ns8250_bus_receive),
418 KOBJMETHOD(uart_setsig, lpc_ns8250_bus_setsig),
419 KOBJMETHOD(uart_transmit, lpc_ns8250_bus_transmit),
420 KOBJMETHOD(uart_grab, lpc_ns8250_bus_grab),
421 KOBJMETHOD(uart_ungrab, lpc_ns8250_bus_ungrab),
425 static struct uart_class uart_lpc_class = {
428 sizeof(struct lpc_ns8250_softc),
429 .uc_ops = &uart_lpc_ns8250_ops,
431 .uc_rclk = DEFAULT_RCLK,
435 static struct ofw_compat_data compat_data[] = {
436 {"lpc,uart", (uintptr_t)&uart_lpc_class},
437 {NULL, (uintptr_t)NULL},
439 UART_FDT_CLASS_AND_DEVICE(compat_data);
441 #define SIGCHG(c, i, s, d) \
443 i |= (i & s) ? s : s | d; \
445 i = (i & s) ? (i & ~s) | d : i; \
449 lpc_ns8250_bus_attach(struct uart_softc *sc)
451 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
452 struct uart_bas *bas;
457 lpc_ns8250->mcr = uart_getreg(bas, REG_MCR);
458 lpc_ns8250->fcr = FCR_ENABLE | FCR_DMA;
459 if (!resource_int_value("uart", device_get_unit(sc->sc_dev), "flags",
461 if (UART_FLAGS_FCR_RX_LOW(ivar))
462 lpc_ns8250->fcr |= FCR_RX_LOW;
463 else if (UART_FLAGS_FCR_RX_MEDL(ivar))
464 lpc_ns8250->fcr |= FCR_RX_MEDL;
465 else if (UART_FLAGS_FCR_RX_HIGH(ivar))
466 lpc_ns8250->fcr |= FCR_RX_HIGH;
468 lpc_ns8250->fcr |= FCR_RX_MEDH;
470 lpc_ns8250->fcr |= FCR_RX_HIGH;
474 resource_int_value("uart", device_get_unit(sc->sc_dev), "ier_mask",
476 lpc_ns8250->ier_mask = (uint8_t)(ivar & 0xff);
478 /* Get IER RX interrupt bits */
479 ivar = IER_EMSC | IER_ERLS | IER_ERXRDY;
480 resource_int_value("uart", device_get_unit(sc->sc_dev), "ier_rxbits",
482 lpc_ns8250->ier_rxbits = (uint8_t)(ivar & 0xff);
484 uart_setreg(bas, REG_FCR, lpc_ns8250->fcr);
486 lpc_ns8250_bus_flush(sc, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);
488 if (lpc_ns8250->mcr & MCR_DTR)
489 sc->sc_hwsig |= SER_DTR;
490 if (lpc_ns8250->mcr & MCR_RTS)
491 sc->sc_hwsig |= SER_RTS;
492 lpc_ns8250_bus_getsig(sc);
494 lpc_ns8250_clrint(bas);
495 lpc_ns8250->ier = uart_getreg(bas, REG_IER) & lpc_ns8250->ier_mask;
496 lpc_ns8250->ier |= lpc_ns8250->ier_rxbits;
497 uart_setreg(bas, REG_IER, lpc_ns8250->ier);
504 lpc_ns8250_bus_detach(struct uart_softc *sc)
506 struct lpc_ns8250_softc *lpc_ns8250;
507 struct uart_bas *bas;
510 lpc_ns8250 = (struct lpc_ns8250_softc *)sc;
512 ier = uart_getreg(bas, REG_IER) & lpc_ns8250->ier_mask;
513 uart_setreg(bas, REG_IER, ier);
515 lpc_ns8250_clrint(bas);
520 lpc_ns8250_bus_flush(struct uart_softc *sc, int what)
522 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
523 struct uart_bas *bas;
527 uart_lock(sc->sc_hwmtx);
528 if (sc->sc_rxfifosz > 1) {
529 lpc_ns8250_flush(bas, what);
530 uart_setreg(bas, REG_FCR, lpc_ns8250->fcr);
534 error = lpc_ns8250_drain(bas, what);
535 uart_unlock(sc->sc_hwmtx);
540 lpc_ns8250_bus_getsig(struct uart_softc *sc)
542 uint32_t new, old, sig;
548 uart_lock(sc->sc_hwmtx);
549 msr = uart_getreg(&sc->sc_bas, REG_MSR);
550 uart_unlock(sc->sc_hwmtx);
551 SIGCHG(msr & MSR_DSR, sig, SER_DSR, SER_DDSR);
552 SIGCHG(msr & MSR_CTS, sig, SER_CTS, SER_DCTS);
553 SIGCHG(msr & MSR_DCD, sig, SER_DCD, SER_DDCD);
554 SIGCHG(msr & MSR_RI, sig, SER_RI, SER_DRI);
555 new = sig & ~SER_MASK_DELTA;
556 } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new));
561 lpc_ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data)
563 struct uart_bas *bas;
564 int baudrate, divisor, error;
569 uart_lock(sc->sc_hwmtx);
571 case UART_IOCTL_BREAK:
572 lcr = uart_getreg(bas, REG_LCR);
577 uart_setreg(bas, REG_LCR, lcr);
580 case UART_IOCTL_IFLOW:
581 lcr = uart_getreg(bas, REG_LCR);
583 uart_setreg(bas, REG_LCR, 0xbf);
585 efr = uart_getreg(bas, REG_EFR);
590 uart_setreg(bas, REG_EFR, efr);
592 uart_setreg(bas, REG_LCR, lcr);
595 case UART_IOCTL_OFLOW:
596 lcr = uart_getreg(bas, REG_LCR);
598 uart_setreg(bas, REG_LCR, 0xbf);
600 efr = uart_getreg(bas, REG_EFR);
605 uart_setreg(bas, REG_EFR, efr);
607 uart_setreg(bas, REG_LCR, lcr);
610 case UART_IOCTL_BAUD:
611 lcr = uart_getreg(bas, REG_LCR);
612 uart_setreg(bas, REG_LCR, lcr | LCR_DLAB);
614 divisor = uart_getreg(bas, REG_DLL) |
615 (uart_getreg(bas, REG_DLH) << 8);
617 uart_setreg(bas, REG_LCR, lcr);
619 baudrate = (divisor > 0) ? bas->rclk / divisor / 16 : 0;
621 *(int*)data = baudrate;
629 uart_unlock(sc->sc_hwmtx);
634 lpc_ns8250_bus_ipend(struct uart_softc *sc)
636 struct uart_bas *bas;
637 struct lpc_ns8250_softc *lpc_ns8250;
641 lpc_ns8250 = (struct lpc_ns8250_softc *)sc;
643 uart_lock(sc->sc_hwmtx);
644 iir = uart_getreg(bas, REG_IIR);
645 if (iir & IIR_NOPEND) {
646 uart_unlock(sc->sc_hwmtx);
650 if (iir & IIR_RXRDY) {
651 lsr = uart_getreg(bas, REG_LSR);
653 ipend |= SER_INT_OVERRUN;
655 ipend |= SER_INT_BREAK;
657 ipend |= SER_INT_RXREADY;
659 if (iir & IIR_TXRDY) {
660 ipend |= SER_INT_TXIDLE;
661 uart_setreg(bas, REG_IER, lpc_ns8250->ier);
663 ipend |= SER_INT_SIGCHG;
666 lpc_ns8250_clrint(bas);
667 uart_unlock(sc->sc_hwmtx);
672 lpc_ns8250_bus_param(struct uart_softc *sc, int baudrate, int databits,
673 int stopbits, int parity)
675 struct uart_bas *bas;
679 uart_lock(sc->sc_hwmtx);
680 error = lpc_ns8250_param(bas, baudrate, databits, stopbits, parity);
681 uart_unlock(sc->sc_hwmtx);
686 lpc_ns8250_bus_probe(struct uart_softc *sc)
688 struct lpc_ns8250_softc *lpc_ns8250;
689 struct uart_bas *bas;
690 int count, delay, error, limit;
691 uint8_t lsr, mcr, ier;
693 lpc_ns8250 = (struct lpc_ns8250_softc *)sc;
696 error = lpc_ns8250_probe(bas);
701 if (sc->sc_sysdev == NULL) {
702 /* By using lpc_ns8250_init() we also set DTR and RTS. */
703 lpc_ns8250_init(bas, 115200, 8, 1, UART_PARITY_NONE);
705 mcr |= MCR_DTR | MCR_RTS;
707 error = lpc_ns8250_drain(bas, UART_DRAIN_TRANSMITTER);
712 * Set loopback mode. This avoids having garbage on the wire and
713 * also allows us send and receive data. We set DTR and RTS to
714 * avoid the possibility that automatic flow-control prevents
715 * any data from being sent.
717 uart_setreg(bas, REG_MCR, MCR_LOOPBACK | MCR_IE | MCR_DTR | MCR_RTS);
721 * Enable FIFOs. And check that the UART has them. If not, we're
722 * done. Since this is the first time we enable the FIFOs, we reset
725 uart_setreg(bas, REG_FCR, FCR_ENABLE);
727 if (!(uart_getreg(bas, REG_IIR) & IIR_FIFO_MASK)) {
729 * NS16450 or INS8250. We don't bother to differentiate
730 * between them. They're too old to be interesting.
732 uart_setreg(bas, REG_MCR, mcr);
734 sc->sc_rxfifosz = sc->sc_txfifosz = 1;
735 device_set_desc(sc->sc_dev, "8250 or 16450 or compatible");
739 uart_setreg(bas, REG_FCR, FCR_ENABLE | FCR_XMT_RST | FCR_RCV_RST);
743 delay = lpc_ns8250_delay(bas);
745 /* We have FIFOs. Drain the transmitter and receiver. */
746 error = lpc_ns8250_drain(bas, UART_DRAIN_RECEIVER|UART_DRAIN_TRANSMITTER);
748 uart_setreg(bas, REG_MCR, mcr);
749 uart_setreg(bas, REG_FCR, 0);
755 * We should have a sufficiently clean "pipe" to determine the
756 * size of the FIFOs. We send as much characters as is reasonable
757 * and wait for the overflow bit in the LSR register to be
758 * asserted, counting the characters as we send them. Based on
759 * that count we know the FIFO size.
762 uart_setreg(bas, REG_DATA, 0);
769 * LSR bits are cleared upon read, so we must accumulate
770 * them to be able to test LSR_OE below.
772 while (((lsr |= uart_getreg(bas, REG_LSR)) & LSR_TEMT) == 0 &&
776 ier = uart_getreg(bas, REG_IER) & lpc_ns8250->ier_mask;
777 uart_setreg(bas, REG_IER, ier);
778 uart_setreg(bas, REG_MCR, mcr);
779 uart_setreg(bas, REG_FCR, 0);
784 } while ((lsr & LSR_OE) == 0 && count < 130);
787 uart_setreg(bas, REG_MCR, mcr);
790 lpc_ns8250_flush(bas, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);
793 sc->sc_rxfifosz = 64;
794 device_set_desc(sc->sc_dev, "LPC32x0 UART with FIFOs");
797 * Force the Tx FIFO size to 16 bytes for now. We don't program the
798 * Tx trigger. Also, we assume that all data has been sent when the
801 sc->sc_txfifosz = 16;
805 * XXX there are some issues related to hardware flow control and
806 * it's likely that uart(4) is the cause. This basicly needs more
807 * investigation, but we avoid using for hardware flow control
810 /* 16650s or higher have automatic flow control. */
811 if (sc->sc_rxfifosz > 16) {
820 lpc_ns8250_bus_receive(struct uart_softc *sc)
822 struct uart_bas *bas;
827 uart_lock(sc->sc_hwmtx);
828 lsr = uart_getreg(bas, REG_LSR);
829 while (lsr & LSR_RXRDY) {
830 if (uart_rx_full(sc)) {
831 sc->sc_rxbuf[sc->sc_rxput] = UART_STAT_OVERRUN;
834 xc = uart_getreg(bas, REG_DATA);
836 xc |= UART_STAT_FRAMERR;
838 xc |= UART_STAT_PARERR;
840 lsr = uart_getreg(bas, REG_LSR);
842 /* Discard everything left in the Rx FIFO. */
843 while (lsr & LSR_RXRDY) {
844 (void)uart_getreg(bas, REG_DATA);
846 lsr = uart_getreg(bas, REG_LSR);
848 uart_unlock(sc->sc_hwmtx);
853 lpc_ns8250_bus_setsig(struct uart_softc *sc, int sig)
855 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
856 struct uart_bas *bas;
863 if (sig & SER_DDTR) {
864 SIGCHG(sig & SER_DTR, new, SER_DTR,
867 if (sig & SER_DRTS) {
868 SIGCHG(sig & SER_RTS, new, SER_RTS,
871 } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new));
872 uart_lock(sc->sc_hwmtx);
873 lpc_ns8250->mcr &= ~(MCR_DTR|MCR_RTS);
875 lpc_ns8250->mcr |= MCR_DTR;
877 lpc_ns8250->mcr |= MCR_RTS;
878 uart_setreg(bas, REG_MCR, lpc_ns8250->mcr);
880 uart_unlock(sc->sc_hwmtx);
885 lpc_ns8250_bus_transmit(struct uart_softc *sc)
887 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
888 struct uart_bas *bas;
892 uart_lock(sc->sc_hwmtx);
893 while ((uart_getreg(bas, REG_LSR) & LSR_THRE) == 0)
895 uart_setreg(bas, REG_IER, lpc_ns8250->ier | IER_ETXRDY);
897 for (i = 0; i < sc->sc_txdatasz; i++) {
898 uart_setreg(bas, REG_DATA, sc->sc_txbuf[i]);
902 uart_unlock(sc->sc_hwmtx);
907 lpc_ns8250_bus_grab(struct uart_softc *sc)
909 struct uart_bas *bas = &sc->sc_bas;
912 * turn off all interrupts to enter polling mode. Leave the
913 * saved mask alone. We'll restore whatever it was in ungrab.
914 * All pending interupt signals are reset when IER is set to 0.
916 uart_lock(sc->sc_hwmtx);
917 uart_setreg(bas, REG_IER, 0);
919 uart_unlock(sc->sc_hwmtx);
923 lpc_ns8250_bus_ungrab(struct uart_softc *sc)
925 struct lpc_ns8250_softc *lpc_ns8250 = (struct lpc_ns8250_softc*)sc;
926 struct uart_bas *bas = &sc->sc_bas;
929 * Restore previous interrupt mask
931 uart_lock(sc->sc_hwmtx);
932 uart_setreg(bas, REG_IER, lpc_ns8250->ier);
934 uart_unlock(sc->sc_hwmtx);