tty/serial: Add helpers to use GPIOs to control modem lines and implement atmel_serial.c
Subsystems (6)
v4 cover tty/serial: Add helpers to use GPIOs to control modem lines and implement atmel_serial.c
The USART controller on sam9x5 chips (and also all AT91/SAMA5 chips but at91rm9200) are not capable of handling DTR/DSR/DCD/RI signal. Moreover, even if the controller can handle CTS/RTS, the dedicated CTS/RTS pins are already muxed for other peripherals (LCDC/EMAC/MMC).
So this patchset adds the possibility to control those lines via GPIO, as it is done for RTS in the patch "switch atmel serial to use gpiolib"
As it was suggested by Alexander Shiyan, I made that available for every board.
Patch 1 implements the generic helpers to control modem lines via GPIO Patches 2 and 3 are just a little tidy up of atmel_serial.c. Patch 4 implements modem control lines in atmel_serial atmel_serial. Patch 5 implement the interrupts of CTS/DSR/DCD/RI.
This is based on next-20140226 + [PATCH v3 5/7] ARM: at91: gpio: implement get_direction That Nicolas (has/will/might) appl(ied/y) on AT91 tree.
Tested on at91sam9g35, with a null modem cable between 2 serial ports, one with CTS/RTS controlled by the USART controller, the other via GPIO, full duplex transfers.
Did some tests also with null modem cables on a PC, and with real modems.
Updates from v3:
- add static keyword on struct uart0_gpios_table.
- add use an index at the mctrl_gpio_init() function to make it usable by driver that allocates several ports at once.
- hide struct gpio_desc from users.
- patch "pinctrl: at91: implement get_direction" has been picked by Linus.
- patch "ARM: at91: gpio: implement get_direction" has been acked by Linus.
Updates from v2:
- remove UART_GPIO_MIN/UART_GPIO_MAX_INPUT and use a direction boolean instead.
- implement get_direction in at91 pinctrl and mach-at91/gpio.c.
- remove the get_mctrl_gpio_name() function that was used for logs only.
- split atmel_serial.c patch in 2.
- use a gpio lookup table to declare modem gpios in platform devices boards. So there's no more special case for platform data gpios in atmel_serial.c.
Updates from v1:
- Instead of controlling modem signal only on atmel board, the code is now available for every board.
- The active low flag from device tree is now used.
Richard Genoud (5):
tty/serial: Add GPIOLIB helpers for controlling modem lines tty/serial: at91: use dev_err instead of printk tty/serial: at91: remove unused open/close hooks tty/serial: at91: use mctrl_gpio helpers tty/serial: at91: add interrupts for modem control lines
Documentation/serial/driver | 25 +++ arch/arm/mach-at91/at91rm9200_devices.c | 16 +- arch/arm/mach-at91/at91sam9260_devices.c | 7 - arch/arm/mach-at91/at91sam9261_devices.c | 4 - arch/arm/mach-at91/at91sam9263_devices.c | 4 - arch/arm/mach-at91/at91sam9g45_devices.c | 5 - arch/arm/mach-at91/at91sam9rl_devices.c | 5 - drivers/tty/serial/Kconfig | 4 + drivers/tty/serial/Makefile | 3 + drivers/tty/serial/atmel_serial.c | 259 ++++++++++++++++++++++++------- drivers/tty/serial/serial_mctrl_gpio.c | 146 +++++++++++++++++ drivers/tty/serial/serial_mctrl_gpio.h | 109 +++++++++++++ include/linux/platform_data/atmel.h | 1 - 13 files changed, 496 insertions(+), 92 deletions(-) create mode 100644 drivers/tty/serial/serial_mctrl_gpio.c create mode 100644 drivers/tty/serial/serial_mctrl_gpio.h
Signature · 1 line
1.8.5
PATCH v4 1/5 tty/serial: Add GPIOLIB helpers for controlling modem lines
This patch add some helpers to control modem lines (CTS/RTS/DSR...) via GPIO.
This will be useful for many boards which have a serial controller that only handle CTS/RTS pins (or even just RX/TX).
--- Documentation/serial/driver | 25 ++++++ drivers/tty/serial/Kconfig | 3 + drivers/tty/serial/Makefile | 3 + drivers/tty/serial/serial_mctrl_gpio.c | 146 +++++++++++++++++++++++++++++++++ drivers/tty/serial/serial_mctrl_gpio.h | 109 ++++++++++++++++++++++++ 5 files changed, 286 insertions(+) create mode 100644 drivers/tty/serial/serial_mctrl_gpio.c create mode 100644 drivers/tty/serial/serial_mctrl_gpio.h
Documentation/serial/driver +25 -0
@@ -429,3 +429,28 @@ thus: struct uart_port port; int my_stuff; }; + +Modem control lines via GPIO +---------------------------- + +Some helpers are provided in order to set/get modem control lines via GPIO. + +mctrl_gpio_init(dev, idx): + This will get the {cts,rts,...}-gpios from device tree if they are + present and request them, set direction etc, and return an + allocated structure. devm_* functions are used, so there's no need + to call mctrl_gpio_free(). + +mctrl_gpio_free(dev, gpios): + This will free the requested gpios in mctrl_gpio_init(). + As devm_* function are used, there's generally no need to call + this function. + +mctrl_gpio_to_gpiod(gpios, gidx) + This returns the gpio structure associated to the modem line index. + +mctrl_gpio_set(gpios, mctrl): + This will sets the gpios according to the mctrl state. + +mctrl_gpio_get(gpios, mctrl): + This will update mctrl with the gpios values.
drivers/tty/serial/Kconfig +3 -0
@@ -1509,4 +1509,7 @@ config SERIAL_ST_ASC_CONSOLE endmenu +config SERIAL_MCTRL_GPIO + tristate + endif # TTY
drivers/tty/serial/Makefile +3 -0
@@ -87,3 +87,6 @@ obj-$(CONFIG_SERIAL_EFM32_UART) += efm32-uart.o obj-$(CONFIG_SERIAL_ARC) += arc_uart.o obj-$(CONFIG_SERIAL_RP2) += rp2.o obj-$(CONFIG_SERIAL_FSL_LPUART) += fsl_lpuart.o + +# GPIOLIB helpers for modem control lines +obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
drivers/tty/serial/serial_mctrl_gpio.c new file +146 -0
146 lines not on this page · raw message
drivers/tty/serial/serial_mctrl_gpio.h new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
1.8.5
Re: [PATCH v4 1/5] tty/serial: Add GPIOLIB helpers for controlling modem lines
Hello Richard.
?????, 26 ??????? 2014, 17:19 +01:00 ?? Richard Genoud <[email protected]>:
Quoted 6 lines
This patch add some helpers to control modem lines (CTS/RTS/DSR...) via GPIO.
This will be useful for many boards which have a serial controller that only handle CTS/RTS pins (or even just RX/TX).Signed-off-by Richard Genoud <[email protected]>
Better, but I found few bugs... :)
...
Documentation/serial/driver thus: · line 438
Quoted 6 lines
Documentation/serial/driver +6
-0+Modem control lines via GPIO +---------------------------- + +Some helpers are provided in order to set/get modem control lines via GPIO. + +mctrl_gpio_init(dev, idx):
I think we should indicate variable types used in these functions.
...
drivers/tty/serial/serial_mctrl_gpio.c line 49
Quoted 6 lines
drivers/tty/serial/serial_mctrl_gpio.c new file +6
-0+void mctrl_gpio_set (struct mctrl_gpios *gpios,unsigned int mctrl) +{ +enum mctrl_gpio_idx i; + +if (IS_ERR_OR_NULL (gpios)) +return ;
No. IS_ERR_OR_NULL() is not valid here. This is allocated by kzalloc(), so you should check valid pointer only, ie (!gpios).
Same in other places.
drivers/tty/serial/serial_mctrl_gpio.c line 125
Quoted 7 lines
drivers/tty/serial/serial_mctrl_gpio.c new file +7
-0+if (err) { +dev_err (dev,"Unable to set direction for %s GPIO" , + mctrl_gpios_desc[i].name); +devm_gpiod_put (dev, gpios->gpio[i]); + gpios->gpio[i] =NULL ; + } + }
Let's use dev_dbg().
Thanks.
---
PATCH v4 1/5 tty/serial: Add GPIOLIB helpers for controlling modem lines
2014-02-26 17:37 GMT+01:00 Alexander Shiyan <[email protected]>:
Quoted 12 lines
Hello Richard.
?????, 26 ??????? 2014, 17:19 +01:00 ?? Richard Genoud <[email protected]>:
Quoted 6 lines
This patch add some helpers to control modem lines (CTS/RTS/DSR...) via GPIO.
This will be useful for many boards which have a serial controller that only handle CTS/RTS pins (or even just RX/TX).Signed-off-by Richard Genoud <[email protected]>Better, but I found few bugs... :)
...
Quoted 8 lines
Documentation/serial/driver thus: · line 438
Quoted 6 lines
Documentation/serial/driver +6
-0+Modem control lines via GPIO +---------------------------- + +Some helpers are provided in order to set/get modem control lines via GPIO. + +mctrl_gpio_init(dev, idx):I think we should indicate variable types used in these functions.
In the whole file, the variable type are not indicated. So, for consistency, I think it's better like that.
...
Quoted 10 lines
drivers/tty/serial/serial_mctrl_gpio.c line 49
Quoted 6 lines
drivers/tty/serial/serial_mctrl_gpio.c new file +6
-0+void mctrl_gpio_set (struct mctrl_gpios *gpios,unsigned int mctrl) +{ +enum mctrl_gpio_idx i; + +if (IS_ERR_OR_NULL (gpios)) +return ;No.
IS_ERR_OR_NULL()is not valid here. This is allocated bykzalloc(), so you should check valid pointer only, ie (!gpios).
Same in other places.
You're right !
Quoted 10 lines
drivers/tty/serial/serial_mctrl_gpio.c line 125
Quoted 8 lines
drivers/tty/serial/serial_mctrl_gpio.c new file +7
-0+if (err) { +dev_err (dev,"Unable to set direction for %s GPIO" , + mctrl_gpios_desc[i].name); +devm_gpiod_put (dev, gpios->gpio[i]); + gpios->gpio[i] =NULL ; + } + }Let's use
dev_dbg().
Why dbg ? I agree that _err may be a bit strong, we could use dev_warn() instead.
But as it really should not happen, I'm a bit reluctant to set it as debug. Or have you something else in mind ?
Quoted 2 lines
Thanks.
---
Thanks for reviewing !
PATCH v4 2/5 tty/serial: at91: use dev_err instead of printk
In reply to Richard GenoudFor better consistency.
--- drivers/tty/serial/atmel_serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/atmel_serial.c +2 -2
@@ -1549,7 +1549,7 @@ static int atmel_startup(struct uart_port *port) retval =request_irq (port->irq, atmel_interrupt,IRQF_SHARED , tty ? tty->name :"atmel_serial" , port);if (retval) { -printk ("atmel_serial: atmel_startup - Can't get irq\n" ); +dev_err (port->dev,"atmel_startup - Can't get irq\n" );return retval; }
@@ -1732,7 +1732,7 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state,clk_disable_unprepare (atmel_port->clk);break ;default : -printk (KERN_ERR "atmel_serial: unknown pm %d\n" , state); +dev_err (port->dev,"atmel_serial: unknown pm %d\n" , state); } }
Signature · 1 line
1.8.5
PATCH v4 3/5 tty/serial: at91: remove unused open/close hooks
In reply to Richard Genoudcommit 95e629b761ce36996d1befe2824d5346b5a220b9 removed the use of board specific hooks in serial_at91.h, so now, the open/close hook are just dead code.
--- drivers/tty/serial/atmel_serial.c | 21 --------------------- 1 file changed, 21 deletions(-)
drivers/tty/serial/atmel_serial.c +0 -21
@@ -112,9 +112,6 @@ static void atmel_stop_rx(struct uart_port *port);#define UART_PUT_TCR (port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_TCR)#define UART_GET_TCR (port) __raw_readl((port)->membase + ATMEL_PDC_TCR) -static int (*atmel_open_hook)(struct uart_port *); -static void (*atmel_close_hook)(struct uart_port *); -struct atmel_dma_buffer {unsigned char *buf;dma_addr_t dma_addr;
@@ -1569,17 +1566,6 @@ static int atmel_startup(struct uart_port *port)if (retval <0 )atmel_set_ops (port); } -/* -* If there is a specific "open" function (to register -* control line interrupts) -*/ -if (atmel_open_hook) { - retval =atmel_open_hook (port); -if (retval) { -free_irq (port->irq, port); -return retval; - } - }/* Save current CSR for comparison in atmel_tasklet_func() */ atmel_port->irq_status_prev =UART_GET_CSR (port);
@@ -1678,13 +1664,6 @@ static void atmel_shutdown(struct uart_port *port)* Free the interrupt */ free_irq (port->irq, port); - -/* -* If there is a specific "close" function (to unregister -* control line interrupts) -*/ -if (atmel_close_hook) -atmel_close_hook (port); }/*
Signature · 1 line
1.8.5
PATCH v4 4/5 tty/serial: at91: use mctrl_gpio helpers
In reply to Richard GenoudOn sam9x5, dedicated CTS (and RTS) pins are unusable together with the LCDC, the EMAC, or the MMC because they share the same line.
Moreover, the USART controller doesn't handle DTR/DSR/DCD/RI signals, so we have to control them via GPIO.
This patch permits to use GPIOs to control the CTS/RTS/DTR/DSR/DCD/RI signals.
--- arch/arm/mach-at91/at91rm9200_devices.c | 16 +++-- arch/arm/mach-at91/at91sam9260_devices.c | 7 -- arch/arm/mach-at91/at91sam9261_devices.c | 4 -- arch/arm/mach-at91/at91sam9263_devices.c | 4 -- arch/arm/mach-at91/at91sam9g45_devices.c | 5 -- arch/arm/mach-at91/at91sam9rl_devices.c | 5 -- drivers/tty/serial/Kconfig | 1 + drivers/tty/serial/atmel_serial.c | 107 +++++++++++++++++++++---------- include/linux/platform_data/atmel.h | 1 - 9 files changed, 83 insertions(+), 67 deletions(-)
arch/arm/mach-at91/at91rm9200_devices.c +10 -6
@@ -15,6 +15,7 @@#include <linux/dma-mapping.h> #include <linux/gpio.h> +#include <linux/gpio/driver.h> #include <linux/platform_device.h> #include <linux/i2c-gpio.h>
@@ -923,7 +924,6 @@ static struct resource dbgu_resources[] = {static struct atmel_uart_data dbgu_data = { .use_dma_tx =0 , .use_dma_rx =0 ,/* DBGU not capable of receive DMA */ - .rts_gpio = -EINVAL , };static u64 dbgu_dmamask =DMA_BIT_MASK (32 );
@@ -962,7 +962,14 @@ static struct resource uart0_resources[] = {static struct atmel_uart_data uart0_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , +}; + +static struct gpiod_lookup_table uart0_gpios_table = { + .dev_id ="atmel_usart" , + .table = { +GPIO_LOOKUP ("pioA" ,21 ,"rts" ,GPIO_ACTIVE_LOW ), + { }, + }, };static u64 uart0_dmamask =DMA_BIT_MASK (32 );
@@ -993,7 +1000,7 @@ static inline void configure_usart0_pins(unsigned pins)* We need to drive the pin manually. The serial driver will driver * this to high when initializing. */ - uart0_data.rts_gpio =AT91_PIN_PA21 ; +gpiod_add_lookup_table (&uart0_gpios_table); } }
@@ -1013,7 +1020,6 @@ static struct resource uart1_resources[] = {static struct atmel_uart_data uart1_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart1_dmamask =DMA_BIT_MASK (32 );
@@ -1065,7 +1071,6 @@ static struct resource uart2_resources[] = {static struct atmel_uart_data uart2_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart2_dmamask =DMA_BIT_MASK (32 );
@@ -1109,7 +1114,6 @@ static struct resource uart3_resources[] = {static struct atmel_uart_data uart3_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart3_dmamask =DMA_BIT_MASK (32 );
arch/arm/mach-at91/at91sam9260_devices.c +0 -7
@@ -820,7 +820,6 @@ static struct resource dbgu_resources[] = {static struct atmel_uart_data dbgu_data = { .use_dma_tx =0 , .use_dma_rx =0 ,/* DBGU not capable of receive DMA */ - .rts_gpio = -EINVAL , };static u64 dbgu_dmamask =DMA_BIT_MASK (32 );
@@ -859,7 +858,6 @@ static struct resource uart0_resources[] = {static struct atmel_uart_data uart0_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart0_dmamask =DMA_BIT_MASK (32 );
@@ -911,7 +909,6 @@ static struct resource uart1_resources[] = {static struct atmel_uart_data uart1_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart1_dmamask =DMA_BIT_MASK (32 );
@@ -955,7 +952,6 @@ static struct resource uart2_resources[] = {static struct atmel_uart_data uart2_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart2_dmamask =DMA_BIT_MASK (32 );
@@ -999,7 +995,6 @@ static struct resource uart3_resources[] = {static struct atmel_uart_data uart3_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart3_dmamask =DMA_BIT_MASK (32 );
@@ -1043,7 +1038,6 @@ static struct resource uart4_resources[] = {static struct atmel_uart_data uart4_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart4_dmamask =DMA_BIT_MASK (32 );
@@ -1082,7 +1076,6 @@ static struct resource uart5_resources[] = {static struct atmel_uart_data uart5_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart5_dmamask =DMA_BIT_MASK (32 );
arch/arm/mach-at91/at91sam9261_devices.c +0 -4
@@ -881,7 +881,6 @@ static struct resource dbgu_resources[] = {static struct atmel_uart_data dbgu_data = { .use_dma_tx =0 , .use_dma_rx =0 ,/* DBGU not capable of receive DMA */ - .rts_gpio = -EINVAL , };static u64 dbgu_dmamask =DMA_BIT_MASK (32 );
@@ -920,7 +919,6 @@ static struct resource uart0_resources[] = {static struct atmel_uart_data uart0_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart0_dmamask =DMA_BIT_MASK (32 );
@@ -964,7 +962,6 @@ static struct resource uart1_resources[] = {static struct atmel_uart_data uart1_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart1_dmamask =DMA_BIT_MASK (32 );
@@ -1008,7 +1005,6 @@ static struct resource uart2_resources[] = {static struct atmel_uart_data uart2_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart2_dmamask =DMA_BIT_MASK (32 );
arch/arm/mach-at91/at91sam9263_devices.c +0 -4
@@ -1325,7 +1325,6 @@ static struct resource dbgu_resources[] = {static struct atmel_uart_data dbgu_data = { .use_dma_tx =0 , .use_dma_rx =0 ,/* DBGU not capable of receive DMA */ - .rts_gpio = -EINVAL , };static u64 dbgu_dmamask =DMA_BIT_MASK (32 );
@@ -1364,7 +1363,6 @@ static struct resource uart0_resources[] = {static struct atmel_uart_data uart0_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart0_dmamask =DMA_BIT_MASK (32 );
@@ -1408,7 +1406,6 @@ static struct resource uart1_resources[] = {static struct atmel_uart_data uart1_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart1_dmamask =DMA_BIT_MASK (32 );
@@ -1452,7 +1449,6 @@ static struct resource uart2_resources[] = {static struct atmel_uart_data uart2_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart2_dmamask =DMA_BIT_MASK (32 );
arch/arm/mach-at91/at91sam9g45_devices.c +0 -5
@@ -1588,7 +1588,6 @@ static struct resource dbgu_resources[] = {static struct atmel_uart_data dbgu_data = { .use_dma_tx =0 , .use_dma_rx =0 , - .rts_gpio = -EINVAL , };static u64 dbgu_dmamask =DMA_BIT_MASK (32 );
@@ -1627,7 +1626,6 @@ static struct resource uart0_resources[] = {static struct atmel_uart_data uart0_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart0_dmamask =DMA_BIT_MASK (32 );
@@ -1671,7 +1669,6 @@ static struct resource uart1_resources[] = {static struct atmel_uart_data uart1_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart1_dmamask =DMA_BIT_MASK (32 );
@@ -1715,7 +1712,6 @@ static struct resource uart2_resources[] = {static struct atmel_uart_data uart2_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart2_dmamask =DMA_BIT_MASK (32 );
@@ -1759,7 +1755,6 @@ static struct resource uart3_resources[] = {static struct atmel_uart_data uart3_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart3_dmamask =DMA_BIT_MASK (32 );
arch/arm/mach-at91/at91sam9rl_devices.c +0 -5
@@ -957,7 +957,6 @@ static struct resource dbgu_resources[] = {static struct atmel_uart_data dbgu_data = { .use_dma_tx =0 , .use_dma_rx =0 ,/* DBGU not capable of receive DMA */ - .rts_gpio = -EINVAL , };static u64 dbgu_dmamask =DMA_BIT_MASK (32 );
@@ -996,7 +995,6 @@ static struct resource uart0_resources[] = {static struct atmel_uart_data uart0_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart0_dmamask =DMA_BIT_MASK (32 );
@@ -1048,7 +1046,6 @@ static struct resource uart1_resources[] = {static struct atmel_uart_data uart1_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart1_dmamask =DMA_BIT_MASK (32 );
@@ -1092,7 +1089,6 @@ static struct resource uart2_resources[] = {static struct atmel_uart_data uart2_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart2_dmamask =DMA_BIT_MASK (32 );
@@ -1136,7 +1132,6 @@ static struct resource uart3_resources[] = {static struct atmel_uart_data uart3_data = { .use_dma_tx =1 , .use_dma_rx =1 , - .rts_gpio = -EINVAL , };static u64 uart3_dmamask =DMA_BIT_MASK (32 );
drivers/tty/serial/Kconfig +1 -0
@@ -97,6 +97,7 @@ config SERIAL_ATMEL bool "AT91 / AT32 on-chip serial port support" depends on ARCH_AT91 || AVR32 select SERIAL_CORE + select SERIAL_MCTRL_GPIO help This enables the driver for the on-chip UARTs of the Atmel AT91 and AT32 processors.
drivers/tty/serial/atmel_serial.c +72 -35
179 lines not on this page · raw message
include/linux/platform_data/atmel.h +0 -1
@@ -84,7 +84,6 @@ struct atmel_uart_data {short use_dma_rx;/* use receive DMA? */ void __iomem *regs;/* virt. base address, if any */ struct serial_rs485 rs485;/* rs485 settings */ -int rts_gpio;/* optional RTS GPIO */ };/* Touchscreen Controller */
Signature · 1 line
1.8.5
PATCH v4 5/5 tty/serial: at91: add interrupts for modem control lines
In reply to Richard GenoudHandle CTS/DSR/RI/DCD GPIO interrupts in atmel_serial.
--- drivers/tty/serial/atmel_serial.c | 129 +++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 3 deletions(-)
drivers/tty/serial/atmel_serial.c +126 -3
@@ -45,6 +45,7 @@#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/err.h> +#include <linux/irq.h> #include <asm/io.h> #include <asm/ioctls.h>
@@ -167,7 +168,9 @@ struct atmel_uart_port {struct serial_rs485 rs485;/* rs485 settings */ struct mctrl_gpios *gpios; +int gpio_irq[UART_GPIO_MAX ];unsigned int tx_done_mask; +bool ms_irq_enabled;bool is_usart;/* usart or uart */ struct timer_list uart_timer;/* uart timer */ int (*prepare_rx)(struct uart_port *port);
@@ -489,8 +492,38 @@ static void atmel_stop_rx(struct uart_port *port)*/ static void atmel_enable_ms (struct uart_port *port) { -UART_PUT_IER (port,ATMEL_US_RIIC |ATMEL_US_DSRIC - |ATMEL_US_DCDIC |ATMEL_US_CTSIC ); +struct atmel_uart_port *atmel_port =to_atmel_uart_port (port); +uint32_t ier =0 ; + +/* +* Interrupt should not be enabled twice +*/ +if (atmel_port->ms_irq_enabled) +return ; + + atmel_port->ms_irq_enabled = true; + +if (atmel_port->gpio_irq[UART_GPIO_CTS ] >=0 ) +enable_irq (atmel_port->gpio_irq[UART_GPIO_CTS ]); +else + ier |=ATMEL_US_CTSIC ; + +if (atmel_port->gpio_irq[UART_GPIO_DSR ] >=0 ) +enable_irq (atmel_port->gpio_irq[UART_GPIO_DSR ]); +else + ier |=ATMEL_US_DSRIC ; + +if (atmel_port->gpio_irq[UART_GPIO_RI ] >=0 ) +enable_irq (atmel_port->gpio_irq[UART_GPIO_RI ]); +else + ier |=ATMEL_US_RIIC ; + +if (atmel_port->gpio_irq[UART_GPIO_DCD ] >=0 ) +enable_irq (atmel_port->gpio_irq[UART_GPIO_DCD ]); +else + ier |=ATMEL_US_DCDIC ; + +UART_PUT_IER (port, ier); }/*
@@ -1079,11 +1112,35 @@ atmel_handle_status(struct uart_port *port, unsigned int pending,static irqreturn_t atmel_interrupt (int irq,void *dev_id) {struct uart_port *port = dev_id; +struct atmel_uart_port *atmel_port =to_atmel_uart_port (port);unsigned int status, pending, pass_counter =0 ; +bool gpio_handled = false; do { status = atmel_get_lines_status(port); pending = status & UART_GET_IMR(port); + if (!gpio_handled) { + /* + * Dealing with GPIO interrupt + */ + if ((irq >= 0) && + (irq == atmel_port->gpio_irq[UART_GPIO_CTS])) + pending |= ATMEL_US_CTSIC; + + if ((irq >= 0) && + (irq == atmel_port->gpio_irq[UART_GPIO_DSR])) + pending |= ATMEL_US_DSRIC; + + if ((irq >= 0) && + (irq == atmel_port->gpio_irq[UART_GPIO_RI])) + pending |= ATMEL_US_RIIC; + + if ((irq >= 0) && + (irq == atmel_port->gpio_irq[UART_GPIO_DCD])) + pending |= ATMEL_US_DCDIC; + + gpio_handled = true; + } if (!pending) break;
@@ -1563,6 +1620,45 @@ static void atmel_get_ip_name(struct uart_port *port) } } +static void atmel_free_gpio_irq (struct uart_port *port) +{ +struct atmel_uart_port *atmel_port =to_atmel_uart_port (port); +enum mctrl_gpio_idx i; + +for (i =0 ; i <UART_GPIO_MAX ; i++) +if (atmel_port->gpio_irq[i] >=0 ) +free_irq (atmel_port->gpio_irq[i], port); +} + +static int atmel_request_gpio_irq (struct uart_port *port) +{ +struct atmel_uart_port *atmel_port =to_atmel_uart_port (port); +int *irq = atmel_port->gpio_irq; +enum mctrl_gpio_idx i; +int err =0 ; + +for (i =0 ; (i <UART_GPIO_MAX ) && !err; i++) { +if (irq[i] <0 ) +continue ; + +irq_set_status_flags (irq[i],IRQ_NOAUTOEN ); + err =request_irq (irq[i], atmel_interrupt,IRQ_TYPE_EDGE_BOTH , +"atmel_serial" , port); +if (err) +dev_err (port->dev,"atmel_startup - Can't get %d irq\n" , + irq[i]); + } + +/* +* If something went wrong, rollback. +*/ +while (err && --i) +if (irq[i] >=0 ) +free_irq (irq[i], port); + +return err; +} +/* * Perform initialization and enable port for reception */
@@ -1579,6 +1675,7 @@ static int atmel_startup(struct uart_port *port)* handle an unexpected interrupt */ UART_PUT_IDR (port,-1 ); + atmel_port->ms_irq_enabled = false;/* * Allocate the IRQ
@@ -1591,6 +1688,13 @@ static int atmel_startup(struct uart_port *port) }/* +* Get the GPIO lines IRQ +*/ + retval =atmel_request_gpio_irq (port); +if (retval) + goto free_irq; + +/* * Initialize DMA (if necessary) */ atmel_init_property (atmel_port, pdev);
@@ -1654,6 +1758,11 @@ static int atmel_startup(struct uart_port *port) }return 0 ; + +free_irq: +free_irq (port->irq, port); + +return retval; }/*
@@ -1701,9 +1810,12 @@ static void atmel_shutdown(struct uart_port *port) atmel_port->rx_ring.tail =0 ;/* -* Free the interrupt +* Free the interrupts */ free_irq (port->irq, port); +atmel_free_gpio_irq (port); + + atmel_port->ms_irq_enabled = false; }/*
@@ -2366,12 +2478,23 @@ static int atmel_serial_resume(struct platform_device *pdev)static int atmel_init_gpios (struct atmel_uart_port *p,struct device *dev) { +enum mctrl_gpio_idx i; +struct gpio_desc *gpiod;int err =0 ; p->gpios =mctrl_gpio_init (dev,0 );if (IS_ERR_OR_NULL (p->gpios)) err =PTR_ERR (p->gpios); +for (i =0 ; i <UART_GPIO_MAX ; i++) { + gpiod =mctrl_gpio_to_gpiod (p->gpios, i); +if (!IS_ERR_OR_NULL (gpiod) && + (gpiod_get_direction (gpiod) ==GPIOF_DIR_IN )) + p->gpio_irq[i] =gpiod_to_irq (gpiod); +else + p->gpio_irq[i] = -EINVAL ; + } +return err; }
Signature · 1 line
1.8.5