Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1573008

[PATCH v4 04/10] serial: st-asc: (De)Register GPIOD and swap Pinctrl profiles

From Lee Jones <lee.jones@linaro.org>
Newsgroups linux.kernel
Subject [PATCH v4 04/10] serial: st-asc: (De)Register GPIOD and swap Pinctrl profiles
Date 2017-02-03 11:30 +0100
Message-ID <t6JhT-kD-11@gated-at.bofh.it> (permalink)
References <t6JhT-kD-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


When hardware flow-control is disabled, manual toggling of the UART's
reset line (RTS) using userland applications (e.g. stty) is not
possible, since the ASC IP does not provide this functionality in the
same was as some other IPs do.  Thus, we have to do this manually.

This patch ensures that when HW flow-control is disabled the RTS/CTS
lines are free to be registered via the GPIO API.  It also ensures
any registered GPIO lines are unregistered when HW flow-control is
requested, allowing the IP to control them automatically.

Acked-by: Peter Griffin <peter.griffin@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/tty/serial/st-asc.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index 1058020..e521078 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -513,6 +513,8 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
 			    struct ktermios *old)
 {
 	struct asc_port *ascport = to_asc_port(port);
+	struct device_node *np = port->dev->of_node;
+	struct gpio_desc *gpiod;
 	unsigned int baud;
 	u32 ctrl_val;
 	tcflag_t cflag;
@@ -556,9 +558,32 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
 		ctrl_val |= ASC_CTL_PARITYODD;
 
 	/* hardware flow control */
-	if ((cflag & CRTSCTS))
+	if ((cflag & CRTSCTS)) {
 		ctrl_val |= ASC_CTL_CTSENABLE;
 
+		/* If flow-control selected, stop handling RTS manually */
+		if (ascport->rts) {
+			devm_gpiod_put(port->dev, ascport->rts);
+			ascport->rts = NULL;
+
+			pinctrl_select_state(ascport->pinctrl,
+					     ascport->states[DEFAULT]);
+		}
+	} else {
+		/* If flow-control disabled, it's safe to handle RTS manually */
+		if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) {
+			pinctrl_select_state(ascport->pinctrl,
+					     ascport->states[NO_HW_FLOWCTRL]);
+
+			gpiod =	devm_get_gpiod_from_child(port->dev, "rts",
+							  &np->fwnode);
+			if (!IS_ERR(gpiod)) {
+				gpiod_direction_output(gpiod, 0);
+				ascport->rts = gpiod;
+			}
+		}
+	}
+
 	if ((baud < 19200) && !ascport->force_m1) {
 		asc_out(port, ASC_BAUDRATE, (port->uartclk / (16 * baud)));
 	} else {
-- 
2.9.3

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/10] serial: st-asc: Allow handling of RTS lin Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100
  [PATCH v4 04/10] serial: st-asc: (De)Register GPIOD and swap Pinctrl profiles Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100
  [PATCH v4 01/10] serial: st-asc: Ignore the parity error bit if 8-bit mode is enabled Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100
  [PATCH v4 09/10] ARM: dts: STiH407-family: Use new Pinctrl groups Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100
  [PATCH v4 07/10] ARM: dts: STiH410-b2260: Identify the UART RTS line Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100
  [PATCH v4 08/10] ARM: dts: STiH407-pinctrl: Add Pinctrl group for HW flow-control Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100
  [PATCH v4 06/10] dt-bindings: serial: Update 'uart-has-rtscts' description Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100
    Re: [PATCH v4 06/10] dt-bindings: serial: Update 'uart-has-rtscts'  description Rob Herring <robh@kernel.org> - 2017-02-08 22:20 +0100
  [PATCH v4 10/10] ARM: dts: STiH410-b2260: Enable HW flow-control Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100
  [PATCH v4 02/10] serial: st-asc: Provide RTS functionality Lee Jones <lee.jones@linaro.org> - 2017-02-03 11:30 +0100

csiph-web