Add sc16is7x2 driver
Subsystems (2)
PATCH 1/1 Add sc16is7x2 driver
This patch adds support for the sc16is7x2 chips.
--- drivers/serial/Kconfig | 7 + drivers/serial/Makefile | 1 + drivers/serial/sc16is7x2.c | 1351 +++++++++++++++++++++++++++++++++++++++++ include/linux/serial_core.h | 3 + include/linux/spi/sc16is7x2.h | 17 + 5 files changed, 1379 insertions(+), 0 deletions(-)
drivers/serial/Kconfig +7 -0
@@ -269,6 +269,13 @@ config SERIAL_8250_RM9K comment "Non-8250 serial port support" +config SERIAL_SC16IS7X2 + tristate "SC16IS7x2 chips" + depends on SPI_MASTER && GPIOLIB + select SERIAL_CORE + help + gpio driver for SC16IS7x2 SPI UARTs. + config SERIAL_AMBA_PL010 tristate "ARM AMBA PL010 serial port support" depends on ARM_AMBA && (BROKEN || !ARCH_VERSATILE)
drivers/serial/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_SERIAL_8250_BOCA) += 8250_boca.o obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o +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/serial/sc16is7x2.c new file +1351 -0
1,351 lines not on this page · raw message
include/linux/serial_core.h +3 -0
@@ -46,6 +46,9 @@#define PORT_AR7 18/* Texas Instruments AR7 internal UART */ #define PORT_MAX_8250 18/* max port ID */ +/* SC16IS7x2 SPI UART */ +#define PORT_SC16IS7X2 19 +/* * ARM specific type numbers. These are not currently guaranteed * to be implemented, and will change in the future. These are
include/linux/spi/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
Quoted 2 lines · On Fri, 03 Sep 2010 15:11:53 +0200 Manuel Stahl…
This patch adds support for the sc16is7x2 chips.
The patch was pretty badly wordwrapped.
drivers/serial/sc16is7x2.c line 62
Quoted 5 lines
...
drivers/serial/sc16is7x2.c new file +2
-0+#define WRITE_CMD (reg, ch) (REG_WRITE | (reg & 0xf) << 3 | (ch & 0x1) << 1) +#define READ_CMD (reg, ch) (REG_READ | (reg & 0xf) << 3 | (ch & 0x1) << 1)
It would be better to implement these as lower-case-named inlined C functions.
drivers/serial/sc16is7x2.c line 68
Quoted 6 lines
drivers/serial/sc16is7x2.c new file +6
-0+ +/* 16bit SPI command to read or write a register */ +struct sc16is7x2_spi_reg { +u8 cmd; +u8 value; +} __attribute__ ((packed));
We have a __packed helper macro for this.
drivers/serial/sc16is7x2.c line 74
Quoted 5 lines
drivers/serial/sc16is7x2.c new file +5
-0+struct sc16is7x2_chip ; + +/* +* Some registers must be read back to modify. +* To save time we cache them here in memory
That implies that the caches have some locking (the mutex, perhaps?). Documenting that here would be appropriate.
drivers/serial/sc16is7x2.c line 131
Quoted 10 lines
...
+/* ******************************** SPI
********************************* */drivers/serial/sc16is7x2.c new file +5
-0+ + +/* +* Reserve memory for command sequence +* @param cnt number of commands
This "@param" stuff is some form of markup which the kernel does not use. Please use standard kerneldoc markup throughout the driver, or just plain old English-language comments.
drivers/serial/sc16is7x2.c line 136
Quoted 5 lines
+ */
drivers/serial/sc16is7x2.c new file +4
-0+static inline struct sc16is7x2_spi_reg * +sc16is7x2_alloc_spi_cmds (unsigned cnt) +{ +return kzalloc (sizeof (struct sc16is7x2_spi_reg )*cnt,GFP_KERNEL );
Use kcalloc() here.
Quoted 10 lines
drivers/serial/sc16is7x2.c new file +6
-0+} + +/* +* sc16is7x2_write_async - Write a new register content (async) +*/ +static inline int sc16is7x2_write_async(struct spi_device *spi, u8 reg,u8 ch,
drivers/serial/sc16is7x2.c line 208
Quoted 8 lines
drivers/serial/sc16is7x2.c new file +8
-0+ u8 value) +{ +struct sc16is7x2_spi_reg *cmd =sc16is7x2_alloc_spi_cmds (1 ); +if (!cmd) +return -ENOMEM ; +sc16is7x2_add_write_cmd (cmd, reg, ch, value); +return sc16is7x2_spi_async (spi, cmd,1 ); +}
It's comventional to place a blank line between end-of-definitions and start-of-code. The driver has many instances of this.
drivers/serial/sc16is7x2.c line 217
Quoted 8 lines
drivers/serial/sc16is7x2.c new file +8
-0+/* +* sc16is7x2_write - Write a new register content (sync) +*/ +static int sc16is7x2_write (struct spi_device *spi,u8 reg,u8 ch,u8 val) +{ +u16 word =REG_WRITE | (reg &0xf ) <<3 | (ch &0x3 ) <<1 | val <<8 ; +return spi_write (spi, (const u8 *)&word,sizeof (word)); +}
There's another.
Quoted 8 lines
+/**
+ *sc16is7x2_read- Read back register content
+ * @spi: The SPI device
+ * @reg: Register offset
+ *
+ * Returns positive 8 bit value from device if successful or a
+ * negative value on error
+ */
ah-hah. That's a correct kerneldoc comment.
Quoted 13 lines
+static int
sc16is7x2_read(struct spi_device *spi, unsigned reg, unsigned ch)drivers/serial/sc16is7x2.c new file +6
-0+{ +u8 cmd =REG_READ | (reg &0xf ) <<3 | (ch &0x3 ) <<1 ; +return spi_w8r8 (spi, cmd); +} + +/* ******************************** UART ********************************* */
drivers/serial/sc16is7x2.c new file +3
-0+ +/* Uart divisor latch write */ +static inline void sc16is7x2_add_dl_write_cmd(struct sc16is7x2_spi_reg*cmd,
drivers/serial/sc16is7x2.c line 241
Quoted 5 lines
drivers/serial/sc16is7x2.c new file +5
-0+ u8 ch, int value) +{ +sc16is7x2_add_write_cmd (&cmd[0 ],UART_DLL , ch, value &0xff ); +sc16is7x2_add_write_cmd (&cmd[1 ],UART_DLM , ch, value >>8 &0xff ); +}
Probably the driver doesn't need any explicit "inline" usage at all - modern gcc's work all that out for themselves. And if gcc disagreed with your inline directive, it will just ignore it.
drivers/serial/sc16is7x2.c line 254
Quoted 12 lines
drivers/serial/sc16is7x2.c new file +12
-0+static unsigned int sc16is7x2_tx_empty (struct uart_port *port) +{ +struct sc16is7x2_channel *chan = + container_of(port, struct sc16is7x2_channel, uart); +struct sc16is7x2_chip *ts = chan->chip; +unsigned lsr; + +dev_dbg (&ts->spi->dev,"%s\n" , __func__); + +mutex_lock (&chan->lock); + lsr = chan->lsr; +mutex_unlock (&chan->lock);
It's strange to put locking around a single atomic read. What are we trying to do here?
Quoted 12 lines
drivers/serial/sc16is7x2.c new file +9
-0+return lsr &UART_LSR_TEMT ?TIOCSER_TEMT :0 ; +} + +static void sc16is7x2_break_ctl (struct uart_port *port,int break_state) +{ +struct sc16is7x2_channel *chan = + container_of(port, struct sc16is7x2_channel, uart); +struct sc16is7x2_chip *ts = chan->chip; +unsigned ch = port->line &0x01 ;
drivers/serial/sc16is7x2.c line 386
Quoted 10 lines
drivers/serial/sc16is7x2.c new file +10
-0+unsigned long flags; + +dev_dbg (&ts->spi->dev,"%s\n" , __func__); + +spin_lock_irqsave (&chan->uart.lock, flags); +if (break_state ==-1 ) + chan->lcr |=UART_LCR_SBC ; +else + chan->lcr &= ~UART_LCR_SBC ; +spin_unlock_irqrestore (&chan->uart.lock, flags);
hm. Above we use the mutex to protect char->lcr but here we're using a spinlock.
drivers/serial/sc16is7x2.c
Quoted 7 lines
drivers/serial/sc16is7x2.c new file +4
-0+sc16is7x2_write_async (ts->spi,UART_LCR , ch, chan->lcr); +} + +#define MIN (a, b) ((a < b) ? (a) : (b))
Nope. Use the min() from include/linux/kernel.h.
Quoted 5 lines
...
drivers/serial/sc16is7x2.c new file +2
-0+static irqreturn_t sc16is7x2_interrupt (int irq,void *dev_id) +{
drivers/serial/sc16is7x2.c line 1097
Quoted 10 lines
drivers/serial/sc16is7x2.c new file +10
-0+struct sc16is7x2_chip *ts = dev_id; + +dev_dbg (&ts->spi->dev,"%s\n" , __func__); + +if (!ts->force_end_work && !work_pending (&ts->work) && + !freezing (current) && !ts->suspending) +queue_work (ts->workqueue, &ts->work); + +return IRQ_HANDLED ; +}
The kernel has infrastructure for "threaded irqs" nowadays. What this driver is doing basically reimplements that concept. Did you consider using threaded IRQs directly?
Quoted 3 lines
...
Hi Andrew,
thank you for reviewing this driver. A cleaned up patch is attached.
Am 14.09.2010 02:25, schrieb Andrew Morton:
Quoted 7 lines
Quoted 2 lines · On Fri, 03 Sep 2010 15:11:53 +0200 Manuel…
This patch adds support for the sc16is7x2 chips.
The patch was pretty badly wordwrapped.
Can you point out a few such places?
Quoted 33 lines
Review
Quoted 12 lines
(quoted diff) +12
-0+static unsigned int sc16is7x2_tx_empty(struct uart_port *port) +{ + struct sc16is7x2_channel *chan = + container_of(port, struct sc16is7x2_channel, uart); + struct sc16is7x2_chip *ts = chan->chip; + unsigned lsr; + + dev_dbg(&ts->spi->dev, "%s\n", __func__); + + mutex_lock(&chan->lock); + lsr = chan->lsr; + mutex_unlock(&chan->lock);It's strange to put locking around a single atomic read. What are we trying to do here?
Quoted 17 lines
(quoted diff) +14
-0+ return lsr& UART_LSR_TEMT ? TIOCSER_TEMT : 0; +} + +static void sc16is7x2_break_ctl(struct uart_port *port, int break_state) +{ + struct sc16is7x2_channel *chan = + container_of(port, struct sc16is7x2_channel, uart); + struct sc16is7x2_chip *ts = chan->chip; + unsigned ch = port->line& 0x01; + unsigned long flags; + + dev_dbg(&ts->spi->dev, "%s\n", __func__); + + spin_lock_irqsave(&chan->uart.lock, flags);
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (break_state == -1) + chan->lcr |= UART_LCR_SBC; + else + chan->lcr&= ~UART_LCR_SBC; + spin_unlock_irqrestore(&chan->uart.lock, flags);hm. Above we use the mutex to protect
char->lcrbut here we're using a spinlock.
I think in the break_ctl function it's not possible to use mutexes. What would be the right way to protect the register cache?
Quoted 19 lines
Quoted 5 lines
...
(quoted diff) +2
-0+static irqreturn_t sc16is7x2_interrupt(int irq, void *dev_id) +{Review
Quoted 10 lines
(quoted diff) +10
-0+ struct sc16is7x2_chip *ts = dev_id; + + dev_dbg(&ts->spi->dev, "%s\n", __func__); + + if (!ts->force_end_work&& !work_pending(&ts->work)&& + !freezing(current)&& !ts->suspending) + queue_work(ts->workqueue,&ts->work); + + return IRQ_HANDLED; +}The kernel has infrastructure for "threaded irqs" nowadays. What this driver is doing basically reimplements that concept. Did you consider using threaded IRQs directly?
Ah, I didn't know that. The irq stuff is based on the max3100 driver. Where can I find some example how to use the new threaded irqs?
Regards,
Signature · 6 lines
Dipl.-Inf. Manuel Stahl Fraunhofer-Institut für Integrierte Schaltungen IIS - Leistungsoptimierte Systeme - Nordostpark 93 Telefon +49 (0)911/58061-6419 90411 Nürnberg Fax +49 (0)911/58061-6398 http://www.iis.fraunhofer.de [email protected]
This patch adds support for the sc16is7x2 chips.
--- drivers/serial/Kconfig | 9 + drivers/serial/Makefile | 1 + drivers/serial/sc16is7x2.c | 1375 +++++++++++++++++++++++++++++++++++++++++ include/linux/serial_core.h | 3 + include/linux/spi/sc16is7x2.h | 17 + 5 files changed, 1405 insertions(+), 0 deletions(-)
drivers/serial/Kconfig +9 -0
@@ -269,6 +269,15 @@ config SERIAL_8250_RM9K comment "Non-8250 serial port support" +config SERIAL_SC16IS7X2 + tristate "SC16IS7x2 chips" + depends on SPI_MASTER && GPIOLIB + 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/serial/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_SERIAL_8250_BOCA) += 8250_boca.o obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o +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/serial/sc16is7x2.c new file +1375 -0
1,375 lines not on this page · raw message
include/linux/serial_core.h +3 -0
@@ -47,6 +47,9 @@#define PORT_U6_16550A 19/* ST-Ericsson U6xxx internal UART */ #define PORT_MAX_8250 19/* max port ID */ +/* SC16IS7x2 SPI UART */ +#define PORT_SC16IS7X2 19 +/* * ARM specific type numbers. These are not currently guaranteed * to be implemented, and will change in the future. These are
include/linux/spi/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
Quoted 1 line · On Tue, 14 Sep 2010 15:07:13 +0200 Manuel Stahl…
Where can I find some example how to use the new threaded irqs?
Basic description here: http://lwn.net/Articles/302043/
If you grep request_threaded_irq() in drivers/, you'll certainly find some real-world examples.
jon
OK, here is an implementation with threaded irqs. Still not sure about the locking stuff. Maybe someone experienced with uart drivers can help?
Am 14.09.2010 15:27, schrieb Jonathan Corbet:
Quoted 11 lines
Quoted 1 line · On Tue, 14 Sep 2010 15:07:13 +0200 Manuel…
Where can I find some example how to use the new threaded irqs?
Basic description here: http://lwn.net/Articles/302043/
If you grep
request_threaded_irq()indrivers/, you'll certainly find some real-world examples.jon
sc16is7x2: use threaded irqs
--- drivers/serial/sc16is7x2.c | 115 +++++++++++++++---------------------------- 1 files changed, 40 insertions(+), 75 deletions(-)
drivers/serial/sc16is7x2.c +40 -75
@@ -92,28 +92,13 @@ struct sc16is7x2_channel {struct sc16is7x2_chip {struct spi_device *spi;struct gpio_chip gpio; -struct mutex lock;struct sc16is7x2_channel channel[2 ]; -/* for handling irqs: need workqueue since we do spi_sync */ -struct workqueue_struct *workqueue; -struct work_struct work; -/* set to 1 to make the workhandler exit as soon as possible */ -int force_end_work; -/* need to know we are suspending to avoid deadlock on workqueue */ -int suspending; - +/* set to true to make the work thread exit as soon as possible */ +bool force_end_work;struct spi_message fifo_message; -#define UART_BUG_TXEN BIT(1)/* UART has buggy TX IIR status */ -#define UART_BUG_NOMSR BIT(2)/* UART has buggy MSR status bits (Au1x00) */ -#define UART_BUG_THRE BIT(3)/* UART has buggy THRE reassertion */ -u16 bugs;/* port bugs */ - -#define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS -u8 lsr_saved_flags; -#define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA -u8 msr_saved_flags; +struct mutex io_lock;/* lock for GPIO functions */ u8 io_dir;/* cache for IODir register */ u8 io_state;/* cache for IOState register */ u8 io_gpio;/* PIN is GPIO */
@@ -451,7 +436,7 @@ static void sc16is7x2_shutdown(struct uart_port *port)BUG_ON (!chan);BUG_ON (!ts); -if (ts->suspending) +if (ts->force_end_work)return ;/* Disable interrupts from this port */
@@ -639,7 +624,7 @@ static void sc16is7x2_release_port(struct uart_port *port)struct sc16is7x2_chip *ts = chan->chip;dev_dbg (&ts->spi->dev,"%s\n" , __func__); - ts->force_end_work =1 ; + ts->force_end_work = true; }static int sc16is7x2_request_port (struct uart_port *port)
@@ -709,7 +694,7 @@ static int sc16is7x2_gpio_request(struct gpio_chip *gpio, unsigned offset)BUG_ON (offset >8 );dev_dbg (&ts->spi->dev,"%s: offset = %d\n" , __func__, offset); -mutex_lock (&ts->lock); +mutex_lock (&ts->io_lock);/* GPIO 0:3 and 4:7 can only be controlled as block */ ts->io_gpio |=BIT (offset);
@@ -720,7 +705,7 @@ static int sc16is7x2_gpio_request(struct gpio_chip *gpio, unsigned offset) ret =sc16is7x2_write (ts->spi,REG_IOC ,0 , ts->io_control); } -mutex_unlock (&ts->lock); +mutex_unlock (&ts->io_lock);return ret; }
@@ -734,7 +719,7 @@ static void sc16is7x2_gpio_free(struct gpio_chip *gpio, unsigned offset)BUG_ON (offset >8 ); -mutex_lock (&ts->lock); +mutex_lock (&ts->io_lock);/* GPIO 0:3 and 4:7 can only be controlled as block */ ts->io_gpio &= ~BIT (offset);
@@ -746,7 +731,7 @@ static void sc16is7x2_gpio_free(struct gpio_chip *gpio, unsigned offset)sc16is7x2_write (ts->spi,REG_IOC ,0 , ts->io_control); } -mutex_unlock (&ts->lock); +mutex_unlock (&ts->io_lock); }static int sc16is7x2_direction_input (struct gpio_chip *gpio,unsigned offset)
@@ -757,12 +742,12 @@ static int sc16is7x2_direction_input(struct gpio_chip *gpio, unsigned offset)BUG_ON (offset >8 ); -mutex_lock (&ts->lock); +mutex_lock (&ts->io_lock); ts->io_dir &= ~BIT (offset); io_dir = ts->io_dir; -mutex_unlock (&ts->lock); +mutex_unlock (&ts->io_lock);return sc16is7x2_write_async (ts->spi,REG_IOD ,0 , io_dir); }
@@ -776,7 +761,7 @@ static int sc16is7x2_direction_output(struct gpio_chip *gpio, unsigned offset,BUG_ON (offset >8 ); -mutex_lock (&ts->lock); +mutex_lock (&ts->io_lock);if (value) ts->io_state |=BIT (offset);
@@ -791,7 +776,7 @@ static int sc16is7x2_direction_output(struct gpio_chip *gpio, unsigned offset,sc16is7x2_add_write_cmd (&cmds[1 ],REG_IOD ,0 , ts->io_dir); } -mutex_unlock (&ts->lock); +mutex_unlock (&ts->io_lock);return sc16is7x2_spi_async (ts->spi, cmds,2 ); }
@@ -804,7 +789,7 @@ static int sc16is7x2_get(struct gpio_chip *gpio, unsigned offset)BUG_ON (offset >8 ); -mutex_lock (&ts->lock); +mutex_lock (&ts->io_lock);if (ts->io_dir &BIT (offset)) {/* Output: return cached level */
@@ -818,7 +803,7 @@ static int sc16is7x2_get(struct gpio_chip *gpio, unsigned offset) } } -mutex_unlock (&ts->lock); +mutex_unlock (&ts->io_lock);return level; }
@@ -831,7 +816,7 @@ static void sc16is7x2_set(struct gpio_chip *gpio, unsigned offset, int value)BUG_ON (offset >8 ); -mutex_lock (&ts->lock); +mutex_lock (&ts->io_lock);if (value) ts->io_state |=BIT (offset);
@@ -839,7 +824,7 @@ static void sc16is7x2_set(struct gpio_chip *gpio, unsigned offset, int value) ts->io_state &= ~BIT (offset); io_state = ts->io_state; -mutex_unlock (&ts->lock); +mutex_unlock (&ts->io_lock);sc16is7x2_write_async (ts->spi,REG_IOS ,0 , io_state); }
@@ -971,7 +956,7 @@ static bool sc16is7x2_msg_add_fifo_tx(struct sc16is7x2_chip *ts, unsigned ch) } txlvl =sc16is7x2_read (ts->spi,REG_TXLVL , ch); -if (txlvl <=0 ) { +if (txlvl ==0 ) {dev_dbg (&ts->spi->dev," fifo full\n" );return false; }
@@ -1066,21 +1051,18 @@ static bool sc16is7x2_handle_channel(struct sc16is7x2_chip *ts, unsigned ch)return (chan->iir &UART_IIR_NO_INT ) ==0x00 ; } -static void sc16is7x2_work (struct work_struct *w) +static irqreturn_t sc16is7x2_work (int irq,void *data) { -struct sc16is7x2_chip *ts = - container_of(w, struct sc16is7x2_chip, work); +struct sc16is7x2_chip *ts = (struct sc16is7x2_chip *)data;unsigned pending =0 ;unsigned ch =0 ;dev_dbg (&ts->spi->dev,"%s\n" , __func__); -BUG_ON (!w);BUG_ON (!ts); -if (ts->force_end_work) {dev_dbg (&ts->spi->dev,"%s: force end!\n" , __func__); -return ; +return IRQ_NONE ; }if (ts->channel[0 ].active)
@@ -1089,29 +1071,28 @@ static void sc16is7x2_work(struct work_struct *w) pending |=BIT (1 );do { -mutex_lock (&(ts->channel[ch].lock));if (pending &BIT (ch) && ts->channel[ch].active) {if (!sc16is7x2_handle_channel (ts, ch)) pending &= ~BIT (ch); } -mutex_unlock (&(ts->channel[ch].lock)); ch ^=1 ;/* switch channel */ - }while (!ts->force_end_work && !freezing (current) && pending); + }while (!ts->force_end_work && pending);dev_dbg (&ts->spi->dev,"%s finished\n" , __func__); + +return IRQ_HANDLED ; } -static irqreturn_t sc16is7x2_interrupt (int irq,void *dev_id) +static irqreturn_t sc16is7x2_irq (int irq,void *data) { -struct sc16is7x2_chip *ts = dev_id; - -dev_dbg (&ts->spi->dev,"%s\n" , __func__); +struct sc16is7x2_chip *ts = (struct sc16is7x2_channel *)data; -if (!ts->force_end_work && !work_pending (&ts->work) && - !freezing (current) && !ts->suspending) -queue_work (ts->workqueue, &ts->work); - -return IRQ_HANDLED ; +/* It takes too long to read the regs over SPI, +* so just wake up the thread */ +if (ts->channel[0 ].active || ts->channel[1 ].active) +return IRQ_WAKE_THREAD ; +else +return IRQ_NONE ; }/* ******************************** INIT ********************************* */
@@ -1229,16 +1210,16 @@ static int __devinit sc16is7x2_probe(struct spi_device *spi)if (!ts)return -ENOMEM ; -mutex_init (&ts->lock); +mutex_init (&ts->io_lock);spi_set_drvdata (spi, ts); ts->spi = spi; - ts->force_end_work =1 ; + ts->force_end_work = true;/* Reset the chip TODO: and disable IRQ output */ sc16is7x2_write (spi,REG_IOC ,0 ,IOC_SRESET ); - ret =request_irq (spi->irq, sc16is7x2_interrupt, -IRQF_TRIGGER_FALLING |IRQF_SHARED ,"sc16is7x2" , ts); + ret =request_threaded_irq (spi->irq, sc16is7x2_irq, sc16is7x2_work, +IRQF_TRIGGER_FALLING |IRQF_SHARED ,DRIVER_NAME , ts);if (ret) {dev_warn (&ts->spi->dev,"cannot register interrupt\n" ); goto exit_destroy;
@@ -1255,14 +1236,7 @@ static int __devinit sc16is7x2_probe(struct spi_device *spi)if (ret) goto exit_uart1; - ts->workqueue =create_freezeable_workqueue (DRIVER_NAME ); -if (!ts->workqueue) { -dev_warn (&ts->spi->dev,"cannot create workqueue\n" ); - ret = -EBUSY ; - goto exit_gpio; - } -INIT_WORK (&ts->work, sc16is7x2_work); - ts->force_end_work =0 ; + ts->force_end_work = false; printk(KERN_INFO DRIVER_NAME " at CS%d (irq %d), 2 UARTs, 8 GPIOs\n" " eser%d, eser%d, gpiochip%d\n",
@@ -1272,9 +1246,6 @@ static int __devinit sc16is7x2_probe(struct spi_device *spi)return ret; -exit_gpio: - ret =gpiochip_remove (&ts->gpio); - exit_uart1:sc16is7x2_unregister_uart_port (ts,1 );
@@ -1286,7 +1257,7 @@ exit_irq: exit_destroy:dev_set_drvdata (&spi->dev,NULL ); -mutex_destroy (&ts->lock); +mutex_destroy (&ts->io_lock);kfree (ts);return ret; }
@@ -1299,14 +1270,8 @@ static int __devexit sc16is7x2_remove(struct spi_device *spi)if (ts ==NULL )return -ENODEV ; + ts->force_end_work = true;free_irq (spi->irq, ts); - ts->force_end_work =1 ; - -if (ts->workqueue) { -flush_workqueue (ts->workqueue); -destroy_workqueue (ts->workqueue); - ts->workqueue =NULL ; - } ret =sc16is7x2_unregister_uart_port (ts,0 );if (ret)
@@ -1321,7 +1286,7 @@ static int __devexit sc16is7x2_remove(struct spi_device *spi) goto exit_error; } -mutex_destroy (&ts->lock); +mutex_destroy (&ts->io_lock);kfree (ts); exit_error:
Signature · 1 line
1.7.2.3
Quoted 1 line · On Wed, 15 Sep 2010 15:42:14 +0200 Manuel Stahl…
OK, here is an implementation with threaded irqs.
That simplified things nicely. Does it still work?
Quoted 2 lines
Still not sure about
the locking stuff. Maybe someone experienced with uart drivers can help?
The question is too general for anyone to answer, really. Please describe the specific issues in resonable detail?
include/linux/serial_core.h line 51
Quoted 8 lines · Manuel Stahl
include/linux/serial_core.h +2
-0@@ -47,6 +47,9 @@#define PORT_U6_16550A 19/* ST-Ericsson U6xxx internal UART */ #define PORT_MAX_8250 19/* max port ID */ +/* SC16IS7x2 SPI UART */ +#define PORT_SC16IS7X2 19
Hm, didn't you just duplicate the number here? Shouldn't that be "20" and you bump the max up?
In the end, we need to just drop those, I don't think we need defines anymore, but I need to look at it some more to find out.
thanks,
greg k-h
Am 21.09.2010 22:42, schrieb Greg KH:
Quoted 7 lines · Manuel Stahl
Quoted 6 lines
include/linux/serial_core.h +0
-0@@ -47,6 +47,9 @@#define PORT_U6_16550A 19/* ST-Ericsson U6xxx internal UART */ #define PORT_MAX_8250 19/* max port ID */
Quoted 5 lines
include/linux/serial_core.h line 51
Quoted 2 lines
include/linux/serial_core.h +2
-0+/* SC16IS7x2 SPI UART */ +#define PORT_SC16IS7X2 19Hm, didn't you just duplicate the number here? Shouldn't that be "20" and you bump the max up?
Oh, that might be true.
Quoted 2 lines
In the end, we need to just drop those, I don't think we need defines anymore, but I need to look at it some more to find out.
Thank you for doing that, Greg.
Regards,
Signature · 10 lines
Dipl.-Inf. Manuel Stahl Fraunhofer-Institut für Integrierte Schaltungen IIS - Leistungsoptimierte Systeme - Nordostpark 93 Telefon +49 (0)911/58061-6419 90411 Nürnberg Fax +49 (0)911/58061-6398 http://www.iis.fraunhofer.de [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html