Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: add irq handler for Freescale 16550 errata.

Sending a break on the SOC UARTs found in some MPC83xx/85xx/86xx
chips seems to cause a short lived IRQ storm (/proc/interrupts
typically shows somewhere between 300 and 1500 events). Unfortunately
this renders SysRQ over the serial console completely inoperable.

The suggested workaround in the errata is to read the Rx register,
wait one character period, and then read the Rx register again.
We achieve this by tracking the old LSR value, and on the subsequent
interrupt event after a break, we don't read LSR, instead we just
read the RBR again and return immediately.

The "fsl,ns16550" is used in the compatible field of the serial
device to mark UARTs known to have this issue.

Thanks to Scott Wood for providing the errata data which led to
a much cleaner fix.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Paul Gortmaker and committed by
Greg Kroah-Hartman
9deaa53a 86b21199

+73
+3
arch/powerpc/kernel/legacy_serial.c
··· 441 441 return; 442 442 443 443 port->irq = virq; 444 + 445 + if (of_device_is_compatible(np, "fsl,ns16550")) 446 + port->handle_irq = fsl8250_handle_irq; 444 447 } 445 448 446 449 static void __init fixup_port_pio(int index,
+63
drivers/tty/serial/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 = 32 + container_of(port, struct uart_8250_port, port); 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; 61 + spin_unlock_irqrestore(&up->port.lock, flags); 62 + return 1; 63 + }
+5
drivers/tty/serial/Kconfig
··· 97 97 This builds standard PNP serial support. You may be able to 98 98 disable this feature if you only need legacy serial support. 99 99 100 + config SERIAL_8250_FSL 101 + bool 102 + depends on SERIAL_8250 && PPC 103 + default PPC 104 + 100 105 config SERIAL_8250_HP300 101 106 tristate 102 107 depends on SERIAL_8250 && HP300
+1
drivers/tty/serial/Makefile
··· 28 28 obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o 29 29 obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o 30 30 obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o 31 + obj-$(CONFIG_SERIAL_8250_FSL) += 8250_fsl.o 31 32 obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o 32 33 obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o 33 34 obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o
+1
include/linux/serial_8250.h
··· 82 82 struct ktermios *termios, struct ktermios *old); 83 83 extern void serial8250_do_pm(struct uart_port *port, unsigned int state, 84 84 unsigned int oldstate); 85 + extern int fsl8250_handle_irq(struct uart_port *port); 85 86 int serial8250_handle_irq(struct uart_port *port, unsigned int iir); 86 87 unsigned char serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr); 87 88 void serial8250_tx_chars(struct uart_8250_port *up);