GNU Linux-libre 4.14.303-gnu1
[releases.git] / drivers / tty / serial / 8250 / 8250_fsl.c
1 #include <linux/serial_reg.h>
2 #include <linux/serial_8250.h>
3
4 #include "8250.h"
5
6 /*
7  * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  *
13  * This isn't a full driver; it just provides an alternate IRQ
14  * handler to deal with an errata.  Everything else is just
15  * using the bog standard 8250 support.
16  *
17  * We follow code flow of serial8250_default_handle_irq() but add
18  * a check for a break and insert a dummy read on the Rx for the
19  * immediately following IRQ event.
20  *
21  * We re-use the already existing "bug handling" lsr_saved_flags
22  * field to carry the "what we just did" information from the one
23  * IRQ event to the next one.
24  */
25
26 int fsl8250_handle_irq(struct uart_port *port)
27 {
28         unsigned char lsr, orig_lsr;
29         unsigned long flags;
30         unsigned int iir;
31         struct uart_8250_port *up = up_to_u8250p(port);
32
33         spin_lock_irqsave(&up->port.lock, flags);
34
35         iir = port->serial_in(port, UART_IIR);
36         if (iir & UART_IIR_NO_INT) {
37                 spin_unlock_irqrestore(&up->port.lock, flags);
38                 return 0;
39         }
40
41         /* This is the WAR; if last event was BRK, then read and return */
42         if (unlikely(up->lsr_saved_flags & UART_LSR_BI)) {
43                 up->lsr_saved_flags &= ~UART_LSR_BI;
44                 port->serial_in(port, UART_RX);
45                 spin_unlock_irqrestore(&up->port.lock, flags);
46                 return 1;
47         }
48
49         lsr = orig_lsr = up->port.serial_in(&up->port, UART_LSR);
50
51         /* Process incoming characters first */
52         if ((lsr & (UART_LSR_DR | UART_LSR_BI)) &&
53             (up->ier & (UART_IER_RLSI | UART_IER_RDI))) {
54                 lsr = serial8250_rx_chars(up, lsr);
55         }
56
57         /* Stop processing interrupts on input overrun */
58         if ((orig_lsr & UART_LSR_OE) && (up->overrun_backoff_time_ms > 0)) {
59                 unsigned long delay;
60
61                 up->ier = port->serial_in(port, UART_IER);
62                 if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) {
63                         port->ops->stop_rx(port);
64                 } else {
65                         /* Keep restarting the timer until
66                          * the input overrun subsides.
67                          */
68                         cancel_delayed_work(&up->overrun_backoff);
69                 }
70
71                 delay = msecs_to_jiffies(up->overrun_backoff_time_ms);
72                 schedule_delayed_work(&up->overrun_backoff, delay);
73         }
74
75         serial8250_modem_status(up);
76
77         if (lsr & UART_LSR_THRE)
78                 serial8250_tx_chars(up);
79
80         up->lsr_saved_flags = orig_lsr;
81         spin_unlock_irqrestore(&up->port.lock, flags);
82         return 1;
83 }
84 EXPORT_SYMBOL_GPL(fsl8250_handle_irq);