Add sc16is7x2 driver
PATCH 1/1 Add sc16is7x2 driver
This patch adds support for the sc16is7x2 SPI to UART chips. Each chip has two UARTs and 8 GPIOs.
--- drivers/tty/serial/Kconfig | 10 + drivers/tty/serial/Makefile | 1 + drivers/tty/serial/sc16is7x2.c | 1065 ++++++++++++++++++++++++++++++++++++++ include/linux/serial_core.h | 3 + include/linux/serial_sc16is7x2.h | 17 + 5 files changed, 1096 insertions(+), 0 deletions(-) create mode 100644 drivers/tty/serial/sc16is7x2.c create mode 100755 include/linux/serial_sc16is7x2.h
drivers/tty/serial/Kconfig +10 -0
@@ -9,6 +9,16 @@ source "drivers/tty/serial/8250/Kconfig" comment "Non-8250 serial port support" +config SERIAL_SC16IS7X2 + tristate "SC16IS7X2 support" + depends on SPI_MASTER + select SERIAL_CORE + help + Selecting this option will add support for SC16IS7X2 SPI UARTs. + The GPIOs are exported via gpiolib interface. + + If unsure, say N. + config SERIAL_AMBA_PL010 tristate "ARM AMBA PL010 serial port support" depends on ARM_AMBA && (BROKEN || !ARCH_VERSATILE)
drivers/tty/serial/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_SERIAL_SUNSAB) += sunsab.o # Now bring in any enabled 8250/16450/16550 type drivers. obj-$(CONFIG_SERIAL_8250) += 8250/ +obj-$(CONFIG_SERIAL_SC16IS7X2) += sc16is7x2.o obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
drivers/tty/serial/sc16is7x2.c new file +1065 -0
1,065 lines not on this page · raw message
include/linux/serial_core.h +3 -0
@@ -210,6 +210,9 @@/* Atheros AR933X SoC */ #define PORT_AR933X 99 +/* NXP SC16IS7X2 */ +#define PORT_SC16IS7X2 100 +#ifdef __KERNEL__
include/linux/serial_sc16is7x2.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef LINUX_SPI_SC16IS752_H +#define LINUX_SPI_SC16IS752_H + +#define SC16IS7X2_NR_GPIOS 8 + +struct sc16is7x2_platform_data { +unsigned int uartclk; +/* uart line number of the first channel */ +unsigned uart_base; +/* number assigned to the first GPIO */ +unsigned gpio_base; +char *label; +/* list of GPIO names (array length = SC16IS7X2_NR_GPIOS) */ +const char *const *names; +}; + +#endif
Signature · 1 line
1.7.9
drivers/tty/serial/sc16is7x2.c line 142
Quoted 7 lines
drivers/tty/serial/sc16is7x2.c new file +7
-0+/* ******************************** IRQ ********************************* */ + +static void sc16is7x2_handle_rx (struct sc16is7x2_chip *ts,unsigned ch) +{ +struct sc16is7x2_channel *chan = &ts->channel[ch]; +struct uart_port *uart = &chan->uart; +struct tty_struct *tty = uart->state->port.tty;
What guarantees tty cannot go NULL during this ? - I think you need to hold references and check ? (tty_port_tty_get)
drivers/tty/serial/sc16is7x2.c line 365
Quoted 6 lines
drivers/tty/serial/sc16is7x2.c new file +6
-0+/* Trigger work thread*/ +static void sc16is7x2_dowork (struct sc16is7x2_channel *chan) +{ +if (!freezing (current)) +queue_work (chan->workqueue, &chan->work); +}
Threaded interrupt handler or is the single queue for work in tx and rx actually a nicer way to do it - just asking the question.
drivers/tty/serial/sc16is7x2.c line 433
Quoted 10 lines
drivers/tty/serial/sc16is7x2.c new file +10
-0+static void sc16is7x2_set_mctrl (struct uart_port *port,unsigned int mctrl) +{ +struct sc16is7x2_channel *chan =to_sc16is7x2_channel (port); +struct sc16is7x2_chip *ts = chan->chip; + +dev_dbg (&ts->spi->dev,"%s (0x%02x)\n" , __func__, mctrl); + +/* TODO: set DCD and DSR +* CTS/RTS is handled automatically +*/
Looks like it's not yet finished and ready for merging ?
Quoted 8 lines
drivers/tty/serial/sc16is7x2.c new file +8
-0+static void sc16is7x2_stop_rx (struct uart_port *port) +{ +struct sc16is7x2_channel *chan =to_sc16is7x2_channel (port); +struct sc16is7x2_chip *ts = chan->chip; + +dev_dbg (&ts->spi->dev,"%s\n" , __func__); + + chan->ier &= ~UART_IER_RLSI ;
drivers/tty/serial/sc16is7x2.c line 482
Quoted 10 lines
drivers/tty/serial/sc16is7x2.c new file +9
-0+ chan->uart.read_status_mask &= ~UART_LSR_DR ; + chan->handle_regs = true; +/* Trigger work thread for doing the actual configuration change */ +sc16is7x2_dowork (chan); +} +static void sc16is7x2_break_ctl (struct uart_port *port,int break_state) +{ +/* We don't support break control yet, do nothing */ +}
More unfinished bits
drivers/tty/serial/sc16is7x2.c line 509
Quoted 5 lines
drivers/tty/serial/sc16is7x2.c new file +5
-0+/* Setup IRQ. Actually we have a low active IRQ, but we want +* one shot behaviour */ +if (request_irq (ts->spi->irq, sc16is7x2_irq, +IRQF_TRIGGER_FALLING |IRQF_SHARED , +"sc16is7x2" , chan)) {
Is this a property of the device or of your board ?
drivers/tty/serial/sc16is7x2.c line 609
Quoted 9 lines
drivers/tty/serial/sc16is7x2.c new file +8
-0+static void +sc16is7x2_set_termios (struct uart_port *port,struct ktermios *termios, +struct ktermios *old) +{ +#ifdef CMSPAR +if (termios->c_cflag &CMSPAR ) + lcr |=UART_LCR_SPAR ; +#endif
ifdef shouldn't be needed
termios should write back the actual baud (see how 8250.c does it)
Quoted 1 line
+#ifdef
CONFIG_GPIOLIB
I wonder if this should be a separate driver and the device an MFD - would anyone ever be using it as gpio only ?
Looks basically sound. The GPIO question I think needs figuring out, and there are a few bits of unfinished code that need glancing it.
Alan