From patchwork Fri Feb 7 14:59:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 3605821 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 21BBCBF418 for ; Fri, 7 Feb 2014 15:07:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3C10420154 for ; Fri, 7 Feb 2014 15:07:07 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A550200F4 for ; Fri, 7 Feb 2014 15:07:06 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBn0E-0003BH-2O; Fri, 07 Feb 2014 15:06:02 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBmvK-0004Gn-G1; Fri, 07 Feb 2014 15:00:58 +0000 Received: from mail-wg0-x232.google.com ([2a00:1450:400c:c00::232]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBmv0-0004D3-NM for linux-arm-kernel@lists.infradead.org; Fri, 07 Feb 2014 15:00:41 +0000 Received: by mail-wg0-f50.google.com with SMTP id l18so2367836wgh.29 for ; Fri, 07 Feb 2014 07:00:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6AYaqhsRke8iNd40n+7W3WSCiBrjvBvKOsA5N/Fl26M=; b=Zx66G6zbYnnGHk4W0WVtXoNUj8GeWLzweihh3Cnz3JJXM8YnUONqWKSUMr0cOsEsVV YkLtOS6LBQDblU5ExceYhpgQyLUYslX64ytmt2D2X93Ay6eeTneQfyjECK5Zq8+7sSiB ld+r6CLrSv+x9BKt8zK5NNOK6BsPjlf8xU/Vl30dy0QxwByIkRdTjSZu4iObiIfk5lh5 BQs8HhbW1WqhS1J4khqTWX2QOv/8A5CJzD6xSZpzqeU8jbYcGMBtzpNt8RxwnJ5Amrus 1qMyCaSQn9//y7fEuHOgegwYab3YBJGQBUzdqC8fJFGNEjljDedY5T2eFhw0A7buG4lQ c/ww== X-Received: by 10.180.164.229 with SMTP id yt5mr93075wib.49.1391785216050; Fri, 07 Feb 2014 07:00:16 -0800 (PST) Received: from lnx-rg.pr (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPSA id ha1sm11330842wjc.23.2014.02.07.07.00.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Feb 2014 07:00:15 -0800 (PST) From: Richard Genoud To: Greg Kroah-Hartman Subject: [PATCH 3/8] tty/serial: at91: prepare for more gpio lines to come Date: Fri, 7 Feb 2014 15:59:10 +0100 Message-Id: <1391785155-18525-4-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.8.5 In-Reply-To: <1391785155-18525-1-git-send-email-richard.genoud@gmail.com> References: <1391785155-18525-1-git-send-email-richard.genoud@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140207_100038_947185_75121510 X-CRM114-Status: GOOD ( 16.72 ) X-Spam-Score: -2.0 (--) Cc: Richard Genoud , Linus Walleij , Nicolas Ferre , linux-serial@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's no functionnal change, it will just be easier to review the next patches. Signed-off-by: Richard Genoud --- drivers/tty/serial/atmel_serial.c | 73 ++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index a51b3a762948..7ef99d7e070b 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -126,6 +126,10 @@ struct atmel_uart_char { #define ATMEL_SERIAL_RINGSIZE 1024 +struct gpio_lines { + int rts; /* optional RTS GPIO */ +}; + /* * We wrap our port structure around the generic uart_port. */ @@ -162,7 +166,7 @@ struct atmel_uart_port { struct circ_buf rx_ring; struct serial_rs485 rs485; /* rs485 settings */ - int rts_gpio; /* optional RTS GPIO */ + struct gpio_lines gpio; unsigned int tx_done_mask; bool is_usart; /* usart or uart */ struct timer_list uart_timer; /* uart timer */ @@ -300,11 +304,11 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl) * 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)) { + if (gpio_is_valid(atmel_port->gpio.rts)) { if (mctrl & TIOCM_RTS) - gpio_set_value(atmel_port->rts_gpio, 0); + gpio_set_value(atmel_port->gpio.rts, 0); else - gpio_set_value(atmel_port->rts_gpio, 1); + gpio_set_value(atmel_port->gpio.rts, 1); } if (mctrl & TIOCM_RTS) @@ -2327,6 +2331,45 @@ static int atmel_serial_resume(struct platform_device *pdev) #define atmel_serial_resume NULL #endif +static int atmel_request_gpio(struct device *dev, int gpio, + const char *label, int *irq) +{ + int ret = 0; + + if (gpio_is_valid(gpio)) { + ret = devm_gpio_request(dev, gpio, label); + if (ret) { + dev_err(dev, "error requesting %s GPIO\n", label); + goto err; + } + + if (irq == NULL) { + /* Default to 1 as all signals are active low */ + ret = gpio_direction_output(gpio, 1); + } else { + ret = gpio_direction_input(gpio); + *irq = gpio_to_irq(gpio); + } + if (ret) { + dev_err(dev, "error setting up %s GPIO\n", label); + goto err; + } + } + +err: + return ret; +} + +static int atmel_init_gpios(struct atmel_uart_port *atmel_port, + struct platform_device *pdev) +{ + int ret; + + ret = atmel_request_gpio(&pdev->dev, atmel_port->gpio.rts, + "RTS", NULL); + return ret; +} + static int atmel_serial_probe(struct platform_device *pdev) { struct atmel_uart_port *port; @@ -2362,25 +2405,15 @@ static int atmel_serial_probe(struct platform_device *pdev) port = &atmel_ports[ret]; port->backup_imr = 0; port->uart.line = ret; - port->rts_gpio = -EINVAL; /* Invalid, zero could be valid */ + port->gpio.rts = -EINVAL; /* Invalid, zero could be valid */ if (pdata) - port->rts_gpio = pdata->rts_gpio; + port->gpio.rts = pdata->rts_gpio; else if (np) - port->rts_gpio = of_get_named_gpio(np, "rts-gpios", 0); + port->gpio.rts = of_get_named_gpio(np, "rts-gpios", 0); - if (gpio_is_valid(port->rts_gpio)) { - ret = devm_gpio_request(&pdev->dev, port->rts_gpio, "RTS"); - if (ret) { - dev_err(&pdev->dev, "error requesting RTS GPIO\n"); - goto err; - } - /* Default to 1 as RTS is active low */ - ret = gpio_direction_output(port->rts_gpio, 1); - if (ret) { - dev_err(&pdev->dev, "error setting up RTS GPIO\n"); - goto err; - } - } + ret = atmel_init_gpios(port, pdev); + if (ret) + goto err; ret = atmel_init_port(port, pdev); if (ret)