aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2013-11-07 04:25:55 -0500
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>2013-12-20 05:41:30 -0500
commit354e57f3a0a26120af3bcd6c92c355ad00a057c1 (patch)
tree6935c516167f34df47ebce43c579bbc8ce53f8d4 /drivers/tty
parent6a79799d5654bb7800614e8b7a009252be7ff90e (diff)
ARM/serial: at91: switch atmel serial to use gpiolib
This passes the errata fix using a GPIO to control the RTS pin on one of the AT91 chips to use gpiolib instead of the AT91-specific interfaces. Also remove the reliance on compile-time #defines and the cpu_* check and rely on the platform passing down the proper GPIO pin through platform data. This is a prerequisite for getting rid of the local GPIO implementation in the AT91 platform and move toward multiplatform. The patch also adds device tree support for getting the RTS GPIO pin from the device tree on DT boot paths. Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com> Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/serial/atmel_serial.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index c7d99af46a96..40d6c9b0d98b 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -35,21 +35,18 @@
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36#include <linux/of.h> 36#include <linux/of.h>
37#include <linux/of_device.h> 37#include <linux/of_device.h>
38#include <linux/of_gpio.h>
38#include <linux/dma-mapping.h> 39#include <linux/dma-mapping.h>
39#include <linux/atmel_pdc.h> 40#include <linux/atmel_pdc.h>
40#include <linux/atmel_serial.h> 41#include <linux/atmel_serial.h>
41#include <linux/uaccess.h> 42#include <linux/uaccess.h>
42#include <linux/platform_data/atmel.h> 43#include <linux/platform_data/atmel.h>
43#include <linux/timer.h> 44#include <linux/timer.h>
45#include <linux/gpio.h>
44 46
45#include <asm/io.h> 47#include <asm/io.h>
46#include <asm/ioctls.h> 48#include <asm/ioctls.h>
47 49
48#ifdef CONFIG_ARM
49#include <mach/cpu.h>
50#include <asm/gpio.h>
51#endif
52
53#define PDC_BUFFER_SIZE 512 50#define PDC_BUFFER_SIZE 512
54/* Revisit: We should calculate this based on the actual port settings */ 51/* Revisit: We should calculate this based on the actual port settings */
55#define PDC_RX_TIMEOUT (3 * 10) /* 3 bytes */ 52#define PDC_RX_TIMEOUT (3 * 10) /* 3 bytes */
@@ -168,6 +165,7 @@ struct atmel_uart_port {
168 struct circ_buf rx_ring; 165 struct circ_buf rx_ring;
169 166
170 struct serial_rs485 rs485; /* rs485 settings */ 167 struct serial_rs485 rs485; /* rs485 settings */
168 int rts_gpio; /* optional RTS GPIO */
171 unsigned int tx_done_mask; 169 unsigned int tx_done_mask;
172 bool is_usart; /* usart or uart */ 170 bool is_usart; /* usart or uart */
173 struct timer_list uart_timer; /* uart timer */ 171 struct timer_list uart_timer; /* uart timer */
@@ -301,20 +299,16 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
301 unsigned int mode; 299 unsigned int mode;
302 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 300 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
303 301
304#ifdef CONFIG_ARCH_AT91RM9200 302 /*
305 if (cpu_is_at91rm9200()) { 303 * AT91RM9200 Errata #39: RTS0 is not internally connected
306 /* 304 * to PA21. We need to drive the pin as a GPIO.
307 * AT91RM9200 Errata #39: RTS0 is not internally connected 305 */
308 * to PA21. We need to drive the pin manually. 306 if (gpio_is_valid(atmel_port->rts_gpio)) {
309 */ 307 if (mctrl & TIOCM_RTS)
310 if (port->mapbase == AT91RM9200_BASE_US0) { 308 gpio_set_value(atmel_port->rts_gpio, 0);
311 if (mctrl & TIOCM_RTS) 309 else
312 at91_set_gpio_value(AT91_PIN_PA21, 0); 310 gpio_set_value(atmel_port->rts_gpio, 1);
313 else
314 at91_set_gpio_value(AT91_PIN_PA21, 1);
315 }
316 } 311 }
317#endif
318 312
319 if (mctrl & TIOCM_RTS) 313 if (mctrl & TIOCM_RTS)
320 control |= ATMEL_US_RTSEN; 314 control |= ATMEL_US_RTSEN;
@@ -2379,6 +2373,25 @@ static int atmel_serial_probe(struct platform_device *pdev)
2379 port = &atmel_ports[ret]; 2373 port = &atmel_ports[ret];
2380 port->backup_imr = 0; 2374 port->backup_imr = 0;
2381 port->uart.line = ret; 2375 port->uart.line = ret;
2376 port->rts_gpio = -EINVAL; /* Invalid, zero could be valid */
2377 if (pdata)
2378 port->rts_gpio = pdata->rts_gpio;
2379 else if (np)
2380 port->rts_gpio = of_get_named_gpio(np, "rts-gpios", 0);
2381
2382 if (gpio_is_valid(port->rts_gpio)) {
2383 ret = devm_gpio_request(&pdev->dev, port->rts_gpio, "RTS");
2384 if (ret) {
2385 dev_err(&pdev->dev, "error requesting RTS GPIO\n");
2386 goto err;
2387 }
2388 /* Default to 1 as RTS is active low */
2389 ret = gpio_direction_output(port->rts_gpio, 1);
2390 if (ret) {
2391 dev_err(&pdev->dev, "error setting up RTS GPIO\n");
2392 goto err;
2393 }
2394 }
2382 2395
2383 ret = atmel_init_port(port, pdev); 2396 ret = atmel_init_port(port, pdev);
2384 if (ret) 2397 if (ret)