From patchwork Tue Nov 5 12:35:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 21334 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9969025B39 for ; Tue, 5 Nov 2013 12:36:11 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wp18sf27294038obc.1 for ; Tue, 05 Nov 2013 04:36:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=whP2AaAnpOjtvBrGhwIApdn5rlnUgfr1wKxbNSrcIuM=; b=M4PwIAxSXREtqzrpuFkL2l+LMu4aw8L9f/iHgzpfnLpTkS5z6Ffnk/5RFpTF+SfEeg E1cJGp+rqIS5dV/DkzQ0o9ScxIvpMnquZLFzejS16NqJMSrUkLjw6um5Y7mBB6eUkpwb hEZ5k3DdyBchnQkDrjD3G8zL4UYnAlhCBs+1AIrT4TTalqvrRKuqW4JwGXKFjTdXKX8J UVvoHzDlAfUop03+rv00qwRfTtDRXCl/kA6FEcBaGehPlzZ5MUBaFTIOodNZBZlTfmxK Q+fVbCpQQ8JarbwKuaoAo3XXyv91MkSfgA6NJTO9F/2dU2CC832MtFh0O62SHuulIkPh k8Qw== X-Gm-Message-State: ALoCoQndzQnLNUTpbf5YQhJHDU/9W+sRIVpN2geIn+4SuNq+zsdi+CnK0aFktAuaPVt6fVMbe8Vj X-Received: by 10.182.34.169 with SMTP id a9mr4346obj.49.1383654971163; Tue, 05 Nov 2013 04:36:11 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.4.196 with SMTP id m4ls190545qem.27.gmail; Tue, 05 Nov 2013 04:36:11 -0800 (PST) X-Received: by 10.58.67.9 with SMTP id j9mr15446688vet.3.1383654971040; Tue, 05 Nov 2013 04:36:11 -0800 (PST) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id gq10si6401453vdc.147.2013.11.05.04.36.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Nov 2013 04:36:11 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.50; Received: by mail-vb0-f50.google.com with SMTP id x16so2304171vbf.37 for ; Tue, 05 Nov 2013 04:36:11 -0800 (PST) X-Received: by 10.220.144.18 with SMTP id x18mr15467036vcu.15.1383654970932; Tue, 05 Nov 2013 04:36:10 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp203556vcz; Tue, 5 Nov 2013 04:36:10 -0800 (PST) X-Received: by 10.180.185.10 with SMTP id ey10mr16562856wic.29.1383654969827; Tue, 05 Nov 2013 04:36:09 -0800 (PST) Received: from mail-wg0-f53.google.com (mail-wg0-f53.google.com [74.125.82.53]) by mx.google.com with ESMTPS id gw4si2258241wib.67.2013.11.05.04.36.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Nov 2013 04:36:09 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.53 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=74.125.82.53; Received: by mail-wg0-f53.google.com with SMTP id y10so3460640wgg.32 for ; Tue, 05 Nov 2013 04:36:09 -0800 (PST) X-Received: by 10.180.198.5 with SMTP id iy5mr16582933wic.45.1383654968955; Tue, 05 Nov 2013 04:36:08 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id gg20sm34334618wic.1.2013.11.05.04.36.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Nov 2013 04:36:08 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Andrew Victor , Nicolas Ferre , Jean-Christophe Plagniol-Villard , linus-serial@vger.kernel.org, Greg Kroah-Hartman Cc: Alexandre Courbot , linux-arm-kernel@lists.infradead.org, Linus Walleij Subject: [PATCH] ARM/serial: at91: switch atmel serial to use gpiolib Date: Tue, 5 Nov 2013 13:35:59 +0100 Message-Id: <1383654959-18112-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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. This also makes way for device tree conversion: the RTS GPIO pin can be passed by standard GPIO bindings. Signed-off-by: Linus Walleij --- This is an alternative to the patch entitled "ARM/serial: at91: move machine quirk into machine" which needs testing to confirm this approach. Seeking ACKs on this if the approach seems OK to all parties. --- arch/arm/mach-at91/at91rm9200_devices.c | 1 + drivers/tty/serial/atmel_serial.c | 51 +++++++++++++++++++++------------ include/linux/platform_data/atmel.h | 1 + 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/arch/arm/mach-at91/at91rm9200_devices.c b/arch/arm/mach-at91/at91rm9200_devices.c index c721e9b08066..51d4c08962f6 100644 --- a/arch/arm/mach-at91/at91rm9200_devices.c +++ b/arch/arm/mach-at91/at91rm9200_devices.c @@ -961,6 +961,7 @@ static struct resource uart0_resources[] = { static struct atmel_uart_data uart0_data = { .use_dma_tx = 1, .use_dma_rx = 1, + .rts_gpio = AT91_PIN_PA21, }; static u64 uart0_dmamask = DMA_BIT_MASK(32); diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index d067285a2d20..3d5c848cdfe1 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -41,15 +41,11 @@ #include #include #include +#include #include #include -#ifdef CONFIG_ARM -#include -#include -#endif - #define PDC_BUFFER_SIZE 512 /* Revisit: We should calculate this based on the actual port settings */ #define PDC_RX_TIMEOUT (3 * 10) /* 3 bytes */ @@ -167,6 +163,7 @@ struct atmel_uart_port { struct circ_buf rx_ring; struct serial_rs485 rs485; /* rs485 settings */ + int rts_gpio; /* optional RTS GPIO */ unsigned int tx_done_mask; bool is_usart; /* usart or uart */ struct timer_list uart_timer; /* uart timer */ @@ -300,20 +297,17 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl) unsigned int mode; struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); -#ifdef CONFIG_ARCH_AT91RM9200 - if (cpu_is_at91rm9200()) { - /* - * AT91RM9200 Errata #39: RTS0 is not internally connected - * to PA21. We need to drive the pin manually. - */ - if (port->mapbase == AT91RM9200_BASE_US0) { - if (mctrl & TIOCM_RTS) - at91_set_gpio_value(AT91_PIN_PA21, 0); - else - at91_set_gpio_value(AT91_PIN_PA21, 1); - } + /* + * AT91RM9200 Errata #39: RTS0 is not internally connected + * to PA21. We need to drive the pin as a GPIO. + */ + if (gpio_is_valid(atmel_port->rts_gpio) && + port->mapbase == AT91RM9200_BASE_US0) { + if (mctrl & TIOCM_RTS) + gpio_set_value(atmel_port->rts_gpio, 0); + else + gpio_set_value(atmel_port->rts_gpio, 1); } -#endif if (mctrl & TIOCM_RTS) control |= ATMEL_US_RTSEN; @@ -2365,6 +2359,27 @@ static int atmel_serial_probe(struct platform_device *pdev) port = &atmel_ports[ret]; port->backup_imr = 0; port->uart.line = ret; + port->rts_gpio = -1; /* Invalid, zero could be valid */ + /* + * In theory the GPIO pin controlling RTS could be zero and + * this would be an improper check, but we know that the only + * existing case is != 0 and it's nice to use the zero-initialized + * structs to indicate "no RTS GPIO" instead of open-coding some + * invalid value everywhere. + */ + if (pdata->rts_gpio > 0) { + ret = devm_gpio_request(&pdev->dev, pdata->rts_gpio, "RTS"); + if (ret) { + dev_err(&pdev->dev, "error requesting RTS GPIO\n"); + goto err; + } + port->rts_gpio = pdata->rts_gpio; + ret = gpio_direction_output(port->rts_gpio, 0); + if (ret) { + dev_err(&pdev->dev, "error setting up RTS GPIO\n"); + goto err; + } + } ret = atmel_init_port(port, pdev); if (ret) diff --git a/include/linux/platform_data/atmel.h b/include/linux/platform_data/atmel.h index cea9f70133c5..e26b0c14edea 100644 --- a/include/linux/platform_data/atmel.h +++ b/include/linux/platform_data/atmel.h @@ -84,6 +84,7 @@ 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 */