linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: richard.genoud@gmail.com (Richard Genoud)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/8] tty/serial: at91: prepare for more gpio lines to come
Date: Fri,  7 Feb 2014 15:59:10 +0100	[thread overview]
Message-ID: <1391785155-18525-4-git-send-email-richard.genoud@gmail.com> (raw)
In-Reply-To: <1391785155-18525-1-git-send-email-richard.genoud@gmail.com>

There's no functionnal change, it will just be easier to review the
next patches.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 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)
-- 
1.8.5

  parent reply	other threads:[~2014-02-07 14:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-07 14:59 [PATCH 0/8] tty/serial: at91: Add missing modem signals to atmel_serial Richard Genoud
2014-02-07 14:59 ` [PATCH 1/8] tty/serial: at91: use dev_err instead of printk Richard Genoud
2014-02-07 14:59 ` [PATCH 2/8] tty/serial: at91: remove unused open/close hooks Richard Genoud
2014-02-07 14:59 ` Richard Genoud [this message]
2014-02-07 14:59 ` [PATCH 4/8] tty/serial: at91: add cts control via gpio Richard Genoud
2014-02-07 14:59 ` [PATCH 5/8] tty/serial: at91: add dtr " Richard Genoud
2014-02-07 15:21   ` Alexander Shiyan
2014-02-10 10:24     ` Richard Genoud
2014-02-10 10:37       ` Nicolas Ferre
2014-02-07 14:59 ` [PATCH 6/8] tty/serial: at91: add dsr " Richard Genoud
2014-02-07 14:59 ` [PATCH 7/8] tty/serial: at91: add ring " Richard Genoud
2014-02-07 14:59 ` [PATCH 8/8] tty/serial: at91: add dcd " Richard Genoud

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1391785155-18525-4-git-send-email-richard.genoud@gmail.com \
    --to=richard.genoud@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).