Skip to contentSkip to conversation

UART driver for PNX8550/8950 and friends

PATCH/RFC Vitaly Wool 2 participants 2 messages Aug 18, 2006 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

Ho Russell,

as a follow-up on the email thread "ip3106_uart oddity", i'm inlining the patch that enables UART support on PNX8550 MIPS board, reworked to use platform_driver and with your comments on the previous version taken into account.

 drivers/serial/Kconfig         |   16
 drivers/serial/Makefile        |    1
 drivers/serial/pnx8xxx_uart.c  |  872 +++++++++++++++++++++++++++++++++++++++++
 include/linux/serial_core.h    |    2
 include/linux/serial_ip3106.h  |   81 ---
 include/linux/serial_pnx8xxx.h |   81 +++
 6 files changed, 971 insertions(+), 82 deletions(-)
drivers/serial/Kconfig +16 -0
Index: powerpc.git/drivers/serial/Kconfig
===================================================================
@@ -651,6 +651,22 @@ config SERIAL_SH_SCI_CONSOLE
 	depends on SERIAL_SH_SCI=y
 	select SERIAL_CORE_CONSOLE
 
+config SERIAL_PNX8XXX
+	bool "Enable PNX8XXX SoCs' UART Support"
+	depends on MIPS && SOC_PNX8550
+	select SERIAL_CORE
+	help
+	  If you have a MIPS-based Philips SoC such as PNX8550 or PNX8330
+	  and you want to use serial ports, say Y.  Otherwise, say N.
+
+config SERIAL_PNX8XXX_CONSOLE
+	bool "Enable PNX8XX0 serial console"
+	depends on SERIAL_PNX8XXX
+	select SERIAL_CORE_CONSOLE
+	help
+	  If you have a MIPS-based Philips SoC such as PNX8550 or PNX8330
+	  and you want to use serial console, say Y. Otherwise, say N.
+
 config SERIAL_CORE
 	tristate
 
drivers/serial/pnx8xxx_uart.c new file +872 -0

872 lines not on this page · raw message

drivers/serial/Makefile +1 -0
Index: powerpc.git/drivers/serial/Makefile
===================================================================
@@ -45,6 +45,7 @@ obj-$(CONFIG_SERIAL_SGI_L1_CONSOLE) += s
 obj-$(CONFIG_SERIAL_CPM) += cpm_uart/
 obj-$(CONFIG_SERIAL_IMX) += imx.o
 obj-$(CONFIG_SERIAL_MPC52xx) += mpc52xx_uart.o
+obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_ICOM) += icom.o
 obj-$(CONFIG_SERIAL_M32R_SIO) += m32r_sio.o
 obj-$(CONFIG_SERIAL_MPSC) += mpsc.o
include/linux/serial_ip3106.h deleted +0 -81

81 lines not on this page · raw message

include/linux/serial_pnx8xxx.h new file +81 -0

81 lines not on this page · raw message

include/linux/serial_core.h +1 -1
Index: powerpc.git/include/linux/serial_core.h
===================================================================
@@ -122,7 +122,7 @@
 /*Digi jsm */
 #define PORT_JSM        69
 
-#define PORT_IP3106	70
+#define PORT_PNX8XXX	70
 
 /* Hilscher netx */
 #define PORT_NETX	71
#1 lore raw
Quoted 1 line · Vitaly Wool

+/* We've been assigned a range on the "Low-density serial ports" major */

No you haven't. You're re-using the StrongARM sa1100 serial port major/ minor.

Quoted 2 lines
drivers/serial/pnx8xxx_uart.c new file +2 -0
+#define SERIAL_PNX8XXX_MAJOR	204
+#define MINOR_START		5

...

Quoted 11 lines
drivers/serial/pnx8xxx_uart.c new file +11 -0
+static void
+pnx8xxx_rx_chars(struct pnx8xxx_port *sport, struct pt_regs *regs)
+{
+	struct tty_struct *tty = sport->port.info->tty;
+	unsigned int status, ch, flg;
+
+	status = FIFO_TO_SM(serial_in(sport, PNX8XXX_FIFO)) |
+		 ISTAT_TO_SM(serial_in(sport, PNX8XXX_ISTAT));
+	while (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFIFO)) {
+		ch = serial_in(sport, PNX8XXX_FIFO);
+

drivers/serial/pnx8xxx_uart.c line 208

Quoted 10 lines
drivers/serial/pnx8xxx_uart.c new file +10 -0
+		sport->port.icount.rx++;
+
+		flg = TTY_NORMAL;
+
+		/*
+		 * note that the error handling code is
+		 * out of the main execution path
+		 */
+		if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE |
+					PNX8XXX_UART_FIFO_RXPAR)) {

What about overrun status?

drivers/serial/pnx8xxx_uart.c line 214

Quoted 6 lines
drivers/serial/pnx8xxx_uart.c new file +6 -0
+			if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR))
+				sport->port.icount.parity++;
+			else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE))
+				sport->port.icount.frame++;
+			if (status & ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN))
+				sport->port.icount.overrun++;

You're not masking with the status that we want to know about - which means you're going to be marking characters with parity/frame errors which should otherwise be ignored. This is important since there's termios modes to enable parity checking by the port _but_ ignore the status when it occurs.

Quoted 5 lines
drivers/serial/pnx8xxx_uart.c new file +5 -0
+
+			if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR))
+				flg = TTY_PARITY;
+			else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE))
+				flg = TTY_FRAME;

drivers/serial/pnx8xxx_uart.c line 229

Quoted 10 lines
drivers/serial/pnx8xxx_uart.c new file +10 -0
+
+#ifdef SUPPORT_SYSRQ
+			sport->port.sysrq = 0;
+#endif
+	}
+
+		if (uart_handle_sysrq_char(&sport->port, ch, regs))
+			goto ignore_char;
+
+		uart_insert_char(&sport->port, status, UART_LSR_OE, ch, flg);

Does UART_LSR_OE really tie up with one of your flags in "status" meaning "overrun" ?

When you get an overrun status flag set, is the character you read valid? If it isn't, you shouldn't use uart_insert_char() since that assumes it is valid.

Quoted 9 lines
drivers/serial/pnx8xxx_uart.c new file +9 -0
+
+	ignore_char:
+		serial_out(sport, PNX8XXX_LCR, serial_in(sport, PNX8XXX_LCR) |
+				PNX8XXX_UART_LCR_RX_NEXT);
+		status = FIFO_TO_SM(serial_in(sport, PNX8XXX_FIFO)) |
+			 ISTAT_TO_SM(serial_in(sport, PNX8XXX_ISTAT));
+	}
+	tty_flip_buffer_push(tty);
+}

...

Quoted 15 lines
drivers/serial/pnx8xxx_uart.c new file +15 -0
+static irqreturn_t pnx8xxx_int(int irq, void *dev_id, struct pt_regs *regs)
+{
+	struct pnx8xxx_port *sport = dev_id;
+	unsigned int status;
+
+	spin_lock(&sport->port.lock);
+	/* Get the interrupts */
+	status  = serial_in(sport, PNX8XXX_ISTAT) & serial_in(sport, PNX8XXX_IEN);
+
+	/* RX Receiver Holding Register Overrun */
+	if (status & PNX8XXX_UART_INT_RXOVRN) {
+		sport->port.icount.overrun++;
+		serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_RXOVRN);
+	}
+

drivers/serial/pnx8xxx_uart.c line 305

Quoted 10 lines
drivers/serial/pnx8xxx_uart.c new file +10 -0
+	/* RX Frame Error */
+	if (status & PNX8XXX_UART_INT_FRERR) {
+		sport->port.icount.frame++;
+		serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_FRERR);
+	}
+
+	/* Break signal received */
+	if (status & PNX8XXX_UART_INT_BREAK) {
+		sport->port.icount.brk++;
+		serial_out(sport, PNX8XXX_ICLR, PNX8XXX_UART_INT_BREAK);

If there's no break handling, you can remove the call to uart_handle_sysrq_char() in your receive function - it'll never do anything useful.

Quoted 2 lines
(quoted diff) +2 -0
+	}
+

...

Quoted 35 lines
drivers/serial/pnx8xxx_uart.c new file +35 -0
+static void
+pnx8xxx_set_termios(struct uart_port *port, struct termios *termios,
+		   struct termios *old)
+{
+	struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port;
+	unsigned long flags;
+	unsigned int lcr_fcr, old_ien, baud, quot;
+	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+
+	/*
+	 * We only support CS7 and CS8.
+	 */
+	while ((termios->c_cflag & CSIZE) != CS7 &&
+	       (termios->c_cflag & CSIZE) != CS8) {
+		termios->c_cflag &= ~CSIZE;
+		termios->c_cflag |= old_csize;
+		old_csize = CS8;
+	}
+
+	if ((termios->c_cflag & CSIZE) == CS8)
+		lcr_fcr = PNX8XXX_UART_LCR_8BIT;
+	else
+		lcr_fcr = 0;
+
+	if (termios->c_cflag & CSTOPB)
+		lcr_fcr |= PNX8XXX_UART_LCR_2STOPB;
+	if (termios->c_cflag & PARENB) {
+		lcr_fcr |= PNX8XXX_UART_LCR_PAREN;
+		if (!(termios->c_cflag & PARODD))
+			lcr_fcr |= PNX8XXX_UART_LCR_PAREVN;
+	}
+
+	/*
+	 * Ask the core to calculate the divisor for us.
+	 */

drivers/serial/pnx8xxx_uart.c line 503

Quoted 10 lines
drivers/serial/pnx8xxx_uart.c new file +10 -0
+	baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
+	quot = uart_get_divisor(port, baud);
+
+	spin_lock_irqsave(&sport->port.lock, flags);
+
+	sport->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
+	if (termios->c_iflag & INPCK)
+		sport->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
+	if (termios->c_iflag & (BRKINT | PARMRK))
+		sport->port.read_status_mask |= UART_LSR_BI;

Doubt this is correct.

Quoted 6 lines
drivers/serial/pnx8xxx_uart.c new file +6 -0
+
+	/*
+	 * Characters to ignore
+	 */
+	sport->port.ignore_status_mask = 0;
+	if (termios->c_iflag & IGNPAR)

drivers/serial/pnx8xxx_uart.c line 519

Quoted 10 lines
drivers/serial/pnx8xxx_uart.c new file +10 -0
+		sport->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
+	if (termios->c_iflag & IGNBRK) {
+		sport->port.ignore_status_mask |= UART_LSR_BI;
+		/*
+		 * If we're ignoring parity and break indicators,
+		 * ignore overruns too (for real raw support).
+		 */
+		if (termios->c_iflag & IGNPAR)
+			sport->port.ignore_status_mask |= UART_LSR_OE;
+	}

Ditto. In which case you probably don't want serial_reg.h included (you don't want it in any case - your device is not 8250 compatible and you're using your own register definitions.)

...

drivers/serial/pnx8xxx_uart.c line 784

Quoted 5 lines
drivers/serial/pnx8xxx_uart.c new file +5 -0
+static int pnx8xxx_serial_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct pnx8xxx_port *sport = platform_get_drvdata(pdev);
+
+	uart_suspend_port(&pnx8xxx_reg, &sport->port);

What if uart_suspend_port() wanted to return an error?

drivers/serial/pnx8xxx_uart.c line 792

Quoted 8 lines
drivers/serial/pnx8xxx_uart.c new file +8 -0
+	return 0;
+}
+
+static int pnx8xxx_serial_resume(struct platform_device *pdev)
+{
+	struct pnx8xxx_port *sport = platform_get_drvdata(pdev);
+
+	uart_resume_port(&pnx8xxx_reg, &sport->port);

What if uart_resume_port() wanted to return an error?

Quoted 3 lines
drivers/serial/pnx8xxx_uart.c new file +3 -0
+
+	return 0;
+}
Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core