]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/tty/serial/8250/8250_fsl.c
serial: 8250: Process sysrq at port unlock time
[mirror_ubuntu-jammy-kernel.git] / drivers / tty / serial / 8250 / 8250_fsl.c
CommitLineData
e3b3d0f5 1// SPDX-License-Identifier: GPL-2.0
596f63da
DA
2#if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
3#define SUPPORT_SYSRQ
4#endif
5
9deaa53a
PG
6#include <linux/serial_reg.h>
7#include <linux/serial_8250.h>
8
9#include "8250.h"
10
11/*
12 * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker.
13 *
9deaa53a
PG
14 * This isn't a full driver; it just provides an alternate IRQ
15 * handler to deal with an errata. Everything else is just
16 * using the bog standard 8250 support.
17 *
18 * We follow code flow of serial8250_default_handle_irq() but add
19 * a check for a break and insert a dummy read on the Rx for the
20 * immediately following IRQ event.
21 *
22 * We re-use the already existing "bug handling" lsr_saved_flags
23 * field to carry the "what we just did" information from the one
24 * IRQ event to the next one.
25 */
26
27int fsl8250_handle_irq(struct uart_port *port)
28{
29 unsigned char lsr, orig_lsr;
30 unsigned long flags;
31 unsigned int iir;
b1261c86 32 struct uart_8250_port *up = up_to_u8250p(port);
9deaa53a
PG
33
34 spin_lock_irqsave(&up->port.lock, flags);
35
36 iir = port->serial_in(port, UART_IIR);
37 if (iir & UART_IIR_NO_INT) {
38 spin_unlock_irqrestore(&up->port.lock, flags);
39 return 0;
40 }
41
42 /* This is the WAR; if last event was BRK, then read and return */
43 if (unlikely(up->lsr_saved_flags & UART_LSR_BI)) {
44 up->lsr_saved_flags &= ~UART_LSR_BI;
45 port->serial_in(port, UART_RX);
46 spin_unlock_irqrestore(&up->port.lock, flags);
47 return 1;
48 }
49
50 lsr = orig_lsr = up->port.serial_in(&up->port, UART_LSR);
51
52 if (lsr & (UART_LSR_DR | UART_LSR_BI))
53 lsr = serial8250_rx_chars(up, lsr);
54
55 serial8250_modem_status(up);
56
57 if (lsr & UART_LSR_THRE)
58 serial8250_tx_chars(up);
59
60 up->lsr_saved_flags = orig_lsr;
596f63da 61 uart_unlock_and_check_sysrq(&up->port, flags);
9deaa53a
PG
62 return 1;
63}
bd63acf9 64EXPORT_SYMBOL_GPL(fsl8250_handle_irq);