Thread (42 messages) 42 messages, 5 authors, 2022-07-02
STALE1486d
Revisions (4)
  1. v1 current
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v4 [diff vs current]

[PATCH 1/8] serial: core: only get RS485 termination gpio if supported

From: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Date: 2022-06-22 15:48:07
Also in: linux-arm-kernel, linux-serial, lkml
Subsystem: the rest, tty layer and serial drivers · Maintainers: Linus Torvalds, Greg Kroah-Hartman, Jiri Slaby

From: Lino Sanfilippo <redacted>

In uart_get_rs485_mode() only try to get a termination GPIO if RS485 bus
termination is supported by the driver.

Signed-off-by: Lino Sanfilippo <redacted>
---
 drivers/tty/serial/serial_core.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 1368b0ef7d7f..015f4e1da647 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3384,17 +3384,20 @@ int uart_get_rs485_mode(struct uart_port *port)
 		rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
 	}
 
-	/*
-	 * Disabling termination by default is the safe choice:  Else if many
-	 * bus participants enable it, no communication is possible at all.
-	 * Works fine for short cables and users may enable for longer cables.
-	 */
-	port->rs485_term_gpio = devm_gpiod_get_optional(dev, "rs485-term",
-							GPIOD_OUT_LOW);
-	if (IS_ERR(port->rs485_term_gpio)) {
-		ret = PTR_ERR(port->rs485_term_gpio);
-		port->rs485_term_gpio = NULL;
-		return dev_err_probe(dev, ret, "Cannot get rs485-term-gpios\n");
+	if (port->rs485_supported->flags & SER_RS485_TERMINATE_BUS) {
+		/*
+		 * Disabling termination by default is the safe choice:  Else if
+		 * many bus participants enable it, no communication is possible
+		 * at all. Works fine for short cables and users may enable for
+		 * longer cables.
+		 */
+		port->rs485_term_gpio = devm_gpiod_get_optional(dev, "rs485-term",
+								GPIOD_OUT_LOW);
+		if (IS_ERR(port->rs485_term_gpio)) {
+			ret = PTR_ERR(port->rs485_term_gpio);
+			port->rs485_term_gpio = NULL;
+			return dev_err_probe(dev, ret, "Cannot get rs485-term-gpios\n");
+		}
 	}
 
 	return 0;
-- 
2.36.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help