Skip to contentSkip to conversation

serial: Add driver for LPC32xx High Speed UARTs

PATCH Superseded Roland Stigge 2 participants 2 messages May 30, 2012

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: Add driver for LPC32xx High Speed UARTs

This patch adds a driver for the 3 High Speed UARTs of the LPC32xx SoC that support up to 900kbps. These UARTs are different from the 4 "Standard" UARTs of the LPC32xx.

---
Applies to v3.4

 Documentation/devicetree/bindings/tty/serial/nxp-lpc32xx-hsuart.txt |   14 
 drivers/tty/serial/Kconfig                                          |   19 
 drivers/tty/serial/Makefile                                         |    1 
 drivers/tty/serial/lpc32xx_hs.c                                     |  810 ++++++++++
 4 files changed, 844 insertions(+)
Documentation/devicetree/bindings/tty/serial/nxp-lpc32xx-hsuart.txt new file +14 -0
@@ -0,0 +1,14 @@
+* NXP LPC32xx SoC High Speed UART
+
+Required properties:
+- compatible: Should be "nxp,lpc3220-hsuart"
+- reg: Should contain registers location and length
+- interrupts: Should contain interrupt
+
+Example:
+
+	uart1: serial at 40014000 {
+		compatible = "nxp,lpc3220-hsuart";
+		reg = <0x40014000 0x1000>;
+		interrupts = <26 0>;
+	};
drivers/tty/serial/Kconfig +19 -0
@@ -704,6 +704,25 @@ config SERIAL_PNX8XXX_CONSOLE
 	  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_HS_LPC32XX
+	tristate "LPC32XX high speed serial port support"
+	depends on ARCH_LPC32XX && OF
+	select SERIAL_CORE
+	help
+	  Support for the LPC32XX high speed serial ports (up to 900kbps).
+	  Those are UARTs completely different from the Standard UARTs on the
+	  LPC32XX SoC.
+	  Choose M or Y here to build this driver.
+
+config SERIAL_HS_LPC32XX_CONSOLE
+	bool "Enable LPC32XX high speed UART serial console"
+	depends on SERIAL_HS_LPC32XX
+	select SERIAL_CORE_CONSOLE
+	help
+	  If you would like to be able to use one of the high speed serial
+	  ports on the LPC32XX as the console, you can do so by answering
+	  Y to this option.
+
 config SERIAL_CORE
 	tristate
 
drivers/tty/serial/Makefile +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_SERIAL_MUX) += mux.o
 obj-$(CONFIG_SERIAL_68328) += 68328serial.o
 obj-$(CONFIG_SERIAL_MCF) += mcf.o
 obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o
+obj-$(CONFIG_SERIAL_HS_LPC32XX) += lpc32xx_hs.o
 obj-$(CONFIG_SERIAL_DZ) += dz.o
 obj-$(CONFIG_SERIAL_ZS) += zs.o
 obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o
drivers/tty/serial/lpc32xx_hs.c new file +810 -0

810 lines not on this page · raw message

#1 lore raw

drivers/tty/serial/lpc32xx_hs.c line 103

Quoted 2 lines
drivers/tty/serial/lpc32xx_hs.c new file +2 -0
+#define LPC32XX_TTY_MINOR_START	196
+#define LPC32XX_TTY_MAJOR 204

NAK - please use dynamic allocations.

Quoted 10 lines
drivers/tty/serial/lpc32xx_hs.c new file +10 -0
+	/* Read data from FIFO and push into terminal */
+	tmp = readl(LPC32XX_HSUART_FIFO(port->membase));
+	while (!(tmp & LPC32XX_HSU_RX_EMPTY)) {
+		flag = TTY_NORMAL;
+		port->icount.rx++;
+
+		if (tmp & LPC32XX_HSU_ERROR_DATA) {
+			/* Framing error */
+			writel(LPC32XX_HSU_FE_INT,
+			       LPC32XX_HSUART_IIR(port->membase));

drivers/tty/serial/lpc32xx_hs.c line 285

Quoted 10 lines
drivers/tty/serial/lpc32xx_hs.c new file +10 -0
+			port->icount.frame++;
+			flag = TTY_FRAME;
+			tty_insert_flip_char(port->state->port.tty, 0,
+					     TTY_FRAME);
+			tty_schedule_flip(port->state->port.tty);
+		}
+
+		tty_insert_flip_char(port->state->port.tty, (tmp & 0xFF), flag);
+
+		tmp = readl(LPC32XX_HSUART_FIFO(port->membase));

This seems odd - you don't need to schedule the flip of the framing error separately. It all just ends up in the queue and can be kicked in one go.

Also if the last byte is a normal char - who ensures the buffer is pushed and not wedged until a future I/O ?

Second problem is port->state->port.tty can be or go to NULL. Take a look how drivers use tty_port_tty_get(), and tty_kref_put.

drivers/tty/serial/lpc32xx_hs.c line 362

Quoted 7 lines
drivers/tty/serial/lpc32xx_hs.c new file +7 -0
+	/* Data received? */
+	if (status & (LPC32XX_HSU_RX_TIMEOUT_INT | LPC32XX_HSU_RX_TRIG_INT)) {
+		__serial_lpc32xx_rx(port);
+		spin_unlock(&port->lock);
+		tty_flip_buffer_push(port->state->port.tty);
+		spin_lock(&port->lock);
+	}

Not sure what the locking is about here - you shouldn't need to fiddle with locks unless you are using low latency and you can't use low latency safely from an IRQ handler...

(Also again tty and NULL - you may want to grab it once at the start of the handler)

Quoted 6 lines
drivers/tty/serial/lpc32xx_hs.c new file +6 -0
+static void serial_lpc32xx_set_termios(struct uart_port *port,
+				       struct ktermios *termios,
+				       struct ktermios *old)
+{
+	unsigned long flags;
+	unsigned int baud, quot;

drivers/tty/serial/lpc32xx_hs.c line 559

Quoted 10 lines
drivers/tty/serial/lpc32xx_hs.c new file +10 -0
+	u32 tmp;
+
+	/* Always 8-bit, no parity, 1 stop bit */
+	termios->c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD);
+	termios->c_cflag |= CS8;
+
+	termios->c_cflag &= ~(HUPCL | CMSPAR | CLOCAL | CRTSCTS);
+
+	baud = uart_get_baud_rate(port, termios, old, 0,
+				  port->uartclk / 14);

You want to set the resulting baud rate back into the struct - see 8250.c for an example.

Alan