1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/serial_reg.h>
3 #include <linux/serial_8250.h>
8 * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker.
10 * This isn't a full driver; it just provides an alternate IRQ
11 * handler to deal with an errata. Everything else is just
12 * using the bog standard 8250 support.
14 * We follow code flow of serial8250_default_handle_irq() but add
15 * a check for a break and insert a dummy read on the Rx for the
16 * immediately following IRQ event.
18 * We re-use the already existing "bug handling" lsr_saved_flags
19 * field to carry the "what we just did" information from the one
20 * IRQ event to the next one.
23 int fsl8250_handle_irq(struct uart_port
*port
)
25 unsigned char lsr
, orig_lsr
;
28 struct uart_8250_port
*up
= up_to_u8250p(port
);
30 spin_lock_irqsave(&up
->port
.lock
, flags
);
32 iir
= port
->serial_in(port
, UART_IIR
);
33 if (iir
& UART_IIR_NO_INT
) {
34 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
38 /* This is the WAR; if last event was BRK, then read and return */
39 if (unlikely(up
->lsr_saved_flags
& UART_LSR_BI
)) {
40 up
->lsr_saved_flags
&= ~UART_LSR_BI
;
41 port
->serial_in(port
, UART_RX
);
42 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
46 lsr
= orig_lsr
= up
->port
.serial_in(&up
->port
, UART_LSR
);
48 /* Process incoming characters first */
49 if ((lsr
& (UART_LSR_DR
| UART_LSR_BI
)) &&
50 (up
->ier
& (UART_IER_RLSI
| UART_IER_RDI
))) {
51 lsr
= serial8250_rx_chars(up
, lsr
);
54 /* Stop processing interrupts on input overrun */
55 if ((orig_lsr
& UART_LSR_OE
) && (up
->overrun_backoff_time_ms
> 0)) {
58 up
->ier
= port
->serial_in(port
, UART_IER
);
59 if (up
->ier
& (UART_IER_RLSI
| UART_IER_RDI
)) {
60 port
->ops
->stop_rx(port
);
62 /* Keep restarting the timer until
63 * the input overrun subsides.
65 cancel_delayed_work(&up
->overrun_backoff
);
68 delay
= msecs_to_jiffies(up
->overrun_backoff_time_ms
);
69 schedule_delayed_work(&up
->overrun_backoff
, delay
);
72 serial8250_modem_status(up
);
74 if (lsr
& UART_LSR_THRE
)
75 serial8250_tx_chars(up
);
77 up
->lsr_saved_flags
= orig_lsr
;
78 uart_unlock_and_check_sysrq(&up
->port
, flags
);
81 EXPORT_SYMBOL_GPL(fsl8250_handle_irq
);