All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] tty: serial: Add ability to control rs485 RX_DURING_TX via a GPIO
@ 2022-10-26 16:50 ` Christoph Niedermaier
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier

This patch series add the ability to control the RS485 feature RX_DURING_TX via
a GPIO. Currently it is handled by the low level serial driver and it depends
on the ability of the serial hardware. In case of that RX_DURING_TX is disabled
the serial hardware must be capable to turn off the receiver during sending.
The idea is to have an electrical circuit that connects/disconnects the Rx by
using the RX_DURING_TX GPIO. On one hand by using this GPIO the use of RS485
RX_DURING_TX becomes independent of the capability of the serial hardware, and
on the other hand possible software-caused switch-off and switch-on times of the
receiver in case of RX_DURING_TX is disabled (default state) can also be avoided.

The core patch adds a generic GPIO variable for the use of this RS485 feature
controlled by a GPIO. The GPIO is defined by the devicetree property
"rs485-rx-during-tx-gpios".

The low-level implementation is done for the STM32 and the i.MX serial driver.
Other platforms are not covered in this series, but can easily be added.

I tested it with a DHCOM i.MX6DL and DHCOM STM32MP1 on a PicoITX board.

In this series the devicetree bindings description is also included.


Christoph Niedermaier (4):
  dt_bindings: rs485: Add binding for GPIO that controls Rx enable
    during Tx
  serial: core: Add option to control rs485 RX_DURING_TX by a GPIO
  serial: imx: Add support for rs485 RX_DURING_TX GPIO
  serial: stm32: Add support for rs485 RX_DURING_TX GPIO

 Documentation/devicetree/bindings/serial/rs485.yaml |  4 ++++
 drivers/tty/serial/imx.c                            | 13 +++++++++++--
 drivers/tty/serial/serial_core.c                    | 12 ++++++++++++
 drivers/tty/serial/stm32-usart.c                    |  9 ++++++++-
 include/linux/serial_core.h                         |  1 +
 5 files changed, 36 insertions(+), 3 deletions(-)

-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/4] tty: serial: Add ability to control rs485 RX_DURING_TX via a GPIO
@ 2022-10-26 16:50 ` Christoph Niedermaier
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier

This patch series add the ability to control the RS485 feature RX_DURING_TX via
a GPIO. Currently it is handled by the low level serial driver and it depends
on the ability of the serial hardware. In case of that RX_DURING_TX is disabled
the serial hardware must be capable to turn off the receiver during sending.
The idea is to have an electrical circuit that connects/disconnects the Rx by
using the RX_DURING_TX GPIO. On one hand by using this GPIO the use of RS485
RX_DURING_TX becomes independent of the capability of the serial hardware, and
on the other hand possible software-caused switch-off and switch-on times of the
receiver in case of RX_DURING_TX is disabled (default state) can also be avoided.

The core patch adds a generic GPIO variable for the use of this RS485 feature
controlled by a GPIO. The GPIO is defined by the devicetree property
"rs485-rx-during-tx-gpios".

The low-level implementation is done for the STM32 and the i.MX serial driver.
Other platforms are not covered in this series, but can easily be added.

I tested it with a DHCOM i.MX6DL and DHCOM STM32MP1 on a PicoITX board.

In this series the devicetree bindings description is also included.


Christoph Niedermaier (4):
  dt_bindings: rs485: Add binding for GPIO that controls Rx enable
    during Tx
  serial: core: Add option to control rs485 RX_DURING_TX by a GPIO
  serial: imx: Add support for rs485 RX_DURING_TX GPIO
  serial: stm32: Add support for rs485 RX_DURING_TX GPIO

 Documentation/devicetree/bindings/serial/rs485.yaml |  4 ++++
 drivers/tty/serial/imx.c                            | 13 +++++++++++--
 drivers/tty/serial/serial_core.c                    | 12 ++++++++++++
 drivers/tty/serial/stm32-usart.c                    |  9 ++++++++-
 include/linux/serial_core.h                         |  1 +
 5 files changed, 36 insertions(+), 3 deletions(-)

-- 
2.11.0


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
  2022-10-26 16:50 ` Christoph Niedermaier
@ 2022-10-26 16:50   ` Christoph Niedermaier
  -1 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Rob Herring, devicetree

Add the binding for a generic definition of a GPIO, that controls whether Rx
is connected or disconnected by an electrical circuit to have the ability
to receive the signals on the bus during sending or disable receiving during
sending.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Cc: Marek Vasut <marex@denx.de>
Cc: devicetree@vger.kernel.org
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
index 90a1bab40f05..0ebd7690f85d 100644
--- a/Documentation/devicetree/bindings/serial/rs485.yaml
+++ b/Documentation/devicetree/bindings/serial/rs485.yaml
@@ -51,6 +51,10 @@ properties:
     description: GPIO pin to enable RS485 bus termination.
     maxItems: 1
 
+  rs485-rx-during-tx-gpios:
+    description: GPIO pin to control RS485 Rx enable during Tx.
+    maxItems: 1
+
 additionalProperties: true
 
 ...
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
@ 2022-10-26 16:50   ` Christoph Niedermaier
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Rob Herring, devicetree

Add the binding for a generic definition of a GPIO, that controls whether Rx
is connected or disconnected by an electrical circuit to have the ability
to receive the signals on the bus during sending or disable receiving during
sending.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Cc: Marek Vasut <marex@denx.de>
Cc: devicetree@vger.kernel.org
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
index 90a1bab40f05..0ebd7690f85d 100644
--- a/Documentation/devicetree/bindings/serial/rs485.yaml
+++ b/Documentation/devicetree/bindings/serial/rs485.yaml
@@ -51,6 +51,10 @@ properties:
     description: GPIO pin to enable RS485 bus termination.
     maxItems: 1
 
+  rs485-rx-during-tx-gpios:
+    description: GPIO pin to control RS485 Rx enable during Tx.
+    maxItems: 1
+
 additionalProperties: true
 
 ...
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/4] serial: core: Add option to control rs485 RX_DURING_TX by a GPIO
  2022-10-26 16:50 ` Christoph Niedermaier
@ 2022-10-26 16:50   ` Christoph Niedermaier
  -1 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Linux Team

This patch provides a generic GPIO variable for the use of the rs485
feature RX_DURING_TX controlled by a GPIO. The GPIO is defined by the
devicetree property "rs485-rx-during-tx-gpios". To use it in a low
level serial driver, the evaluation of this variable must be
implemented there accordingly.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Marek Vasut <marex@denx.de>
Cc: Linux Team <linux-imx@nxp.com>
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 drivers/tty/serial/serial_core.c | 12 ++++++++++++
 include/linux/serial_core.h      |  1 +
 2 files changed, 13 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 179ee199df34..63150d922aa1 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3410,6 +3410,7 @@ int uart_get_rs485_mode(struct uart_port *port)
 	struct device *dev = port->dev;
 	u32 rs485_delay[2];
 	int ret;
+	int rx_during_tx_gpio_flag;
 
 	ret = device_property_read_u32_array(dev, "rs485-rts-delay",
 					     rs485_delay, 2);
@@ -3458,6 +3459,17 @@ int uart_get_rs485_mode(struct uart_port *port)
 	if (port->rs485_term_gpio)
 		port->rs485_supported.flags |= SER_RS485_TERMINATE_BUS;
 
+	rx_during_tx_gpio_flag = (rs485conf->flags & SER_RS485_RX_DURING_TX) ?
+				 GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
+	port->rs485_rx_during_tx_gpio = devm_gpiod_get_optional(dev,
+								"rs485-rx-during-tx",
+								rx_during_tx_gpio_flag);
+	if (IS_ERR(port->rs485_rx_during_tx_gpio)) {
+		ret = PTR_ERR(port->rs485_rx_during_tx_gpio);
+		port->rs485_rx_during_tx_gpio = NULL;
+		return dev_err_probe(dev, ret, "Cannot get rs485-rx-during-tx-gpios\n");
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(uart_get_rs485_mode);
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index d657f2a42a7b..b4cdeb6e952a 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -579,6 +579,7 @@ struct uart_port {
 	struct serial_rs485     rs485;
 	struct serial_rs485	rs485_supported;	/* Supported mask for serial_rs485 */
 	struct gpio_desc	*rs485_term_gpio;	/* enable RS485 bus termination */
+	struct gpio_desc	*rs485_rx_during_tx_gpio; /* Controls RS485 Rx enable during Tx */
 	struct serial_iso7816   iso7816;
 	void			*private_data;		/* generic platform data pointer */
 };
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/4] serial: core: Add option to control rs485 RX_DURING_TX by a GPIO
@ 2022-10-26 16:50   ` Christoph Niedermaier
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Linux Team

This patch provides a generic GPIO variable for the use of the rs485
feature RX_DURING_TX controlled by a GPIO. The GPIO is defined by the
devicetree property "rs485-rx-during-tx-gpios". To use it in a low
level serial driver, the evaluation of this variable must be
implemented there accordingly.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Marek Vasut <marex@denx.de>
Cc: Linux Team <linux-imx@nxp.com>
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 drivers/tty/serial/serial_core.c | 12 ++++++++++++
 include/linux/serial_core.h      |  1 +
 2 files changed, 13 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 179ee199df34..63150d922aa1 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3410,6 +3410,7 @@ int uart_get_rs485_mode(struct uart_port *port)
 	struct device *dev = port->dev;
 	u32 rs485_delay[2];
 	int ret;
+	int rx_during_tx_gpio_flag;
 
 	ret = device_property_read_u32_array(dev, "rs485-rts-delay",
 					     rs485_delay, 2);
@@ -3458,6 +3459,17 @@ int uart_get_rs485_mode(struct uart_port *port)
 	if (port->rs485_term_gpio)
 		port->rs485_supported.flags |= SER_RS485_TERMINATE_BUS;
 
+	rx_during_tx_gpio_flag = (rs485conf->flags & SER_RS485_RX_DURING_TX) ?
+				 GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
+	port->rs485_rx_during_tx_gpio = devm_gpiod_get_optional(dev,
+								"rs485-rx-during-tx",
+								rx_during_tx_gpio_flag);
+	if (IS_ERR(port->rs485_rx_during_tx_gpio)) {
+		ret = PTR_ERR(port->rs485_rx_during_tx_gpio);
+		port->rs485_rx_during_tx_gpio = NULL;
+		return dev_err_probe(dev, ret, "Cannot get rs485-rx-during-tx-gpios\n");
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(uart_get_rs485_mode);
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index d657f2a42a7b..b4cdeb6e952a 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -579,6 +579,7 @@ struct uart_port {
 	struct serial_rs485     rs485;
 	struct serial_rs485	rs485_supported;	/* Supported mask for serial_rs485 */
 	struct gpio_desc	*rs485_term_gpio;	/* enable RS485 bus termination */
+	struct gpio_desc	*rs485_rx_during_tx_gpio; /* Controls RS485 Rx enable during Tx */
 	struct serial_iso7816   iso7816;
 	void			*private_data;		/* generic platform data pointer */
 };
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/4] serial: imx: Add support for rs485 RX_DURING_TX GPIO
  2022-10-26 16:50 ` Christoph Niedermaier
@ 2022-10-26 16:50   ` Christoph Niedermaier
  -1 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Linux Team

If a RX_DURING_TX GPIO is defined by the DT property "rs485-rx-during-tx-gpios"
this patch switches this GPIO accordingly to the RS485 flag RX_DURING_TX in user
space. In addition, the i.MX UART receiver is no longer turned on and off during
sending, because now the hardware is responsible for connecting or disconnecting
Rx during Tx controlled by this GPIO.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Marek Vasut <marex@denx.de>
Cc: Linux Team <linux-imx@nxp.com>
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 drivers/tty/serial/imx.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 05b432dc7a85..16f8baaf4f12 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -476,7 +476,8 @@ static void imx_uart_stop_tx(struct uart_port *port)
 				imx_uart_rts_inactive(sport, &ucr2);
 			imx_uart_writel(sport, ucr2, UCR2);
 
-			imx_uart_start_rx(port);
+			if (!port->rs485_rx_during_tx_gpio)
+				imx_uart_start_rx(port);
 
 			sport->tx_state = OFF;
 		}
@@ -697,7 +698,8 @@ static void imx_uart_start_tx(struct uart_port *port)
 				imx_uart_rts_inactive(sport, &ucr2);
 			imx_uart_writel(sport, ucr2, UCR2);
 
-			if (!(port->rs485.flags & SER_RS485_RX_DURING_TX))
+			if (!(port->rs485.flags & SER_RS485_RX_DURING_TX) &&
+			    !port->rs485_rx_during_tx_gpio)
 				imx_uart_stop_rx(port);
 
 			sport->tx_state = WAIT_AFTER_RTS;
@@ -1931,6 +1933,13 @@ static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termio
 	    rs485conf->flags & SER_RS485_RX_DURING_TX)
 		imx_uart_start_rx(port);
 
+	if (port->rs485_rx_during_tx_gpio) {
+		if (rs485conf->flags & SER_RS485_RX_DURING_TX)
+			gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, 1);
+		else
+			gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, 0);
+	}
+
 	return 0;
 }
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/4] serial: imx: Add support for rs485 RX_DURING_TX GPIO
@ 2022-10-26 16:50   ` Christoph Niedermaier
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, Linux Team

If a RX_DURING_TX GPIO is defined by the DT property "rs485-rx-during-tx-gpios"
this patch switches this GPIO accordingly to the RS485 flag RX_DURING_TX in user
space. In addition, the i.MX UART receiver is no longer turned on and off during
sending, because now the hardware is responsible for connecting or disconnecting
Rx during Tx controlled by this GPIO.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Marek Vasut <marex@denx.de>
Cc: Linux Team <linux-imx@nxp.com>
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 drivers/tty/serial/imx.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 05b432dc7a85..16f8baaf4f12 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -476,7 +476,8 @@ static void imx_uart_stop_tx(struct uart_port *port)
 				imx_uart_rts_inactive(sport, &ucr2);
 			imx_uart_writel(sport, ucr2, UCR2);
 
-			imx_uart_start_rx(port);
+			if (!port->rs485_rx_during_tx_gpio)
+				imx_uart_start_rx(port);
 
 			sport->tx_state = OFF;
 		}
@@ -697,7 +698,8 @@ static void imx_uart_start_tx(struct uart_port *port)
 				imx_uart_rts_inactive(sport, &ucr2);
 			imx_uart_writel(sport, ucr2, UCR2);
 
-			if (!(port->rs485.flags & SER_RS485_RX_DURING_TX))
+			if (!(port->rs485.flags & SER_RS485_RX_DURING_TX) &&
+			    !port->rs485_rx_during_tx_gpio)
 				imx_uart_stop_rx(port);
 
 			sport->tx_state = WAIT_AFTER_RTS;
@@ -1931,6 +1933,13 @@ static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termio
 	    rs485conf->flags & SER_RS485_RX_DURING_TX)
 		imx_uart_start_rx(port);
 
+	if (port->rs485_rx_during_tx_gpio) {
+		if (rs485conf->flags & SER_RS485_RX_DURING_TX)
+			gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, 1);
+		else
+			gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, 0);
+	}
+
 	return 0;
 }
 
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/4] serial: stm32: Add support for rs485 RX_DURING_TX GPIO
  2022-10-26 16:50 ` Christoph Niedermaier
@ 2022-10-26 16:50   ` Christoph Niedermaier
  -1 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Maxime Coquelin, Alexandre Torgue,
	linux-stm32

If a RX_DURING_TX GPIO is defined by the DT property "rs485-rx-during-tx-gpios"
this patch switches this GPIO accordingly to the RS485 flag RX_DURING_TX in user
space. Controlled by this GPIO, now the hardware is responsible for connecting
or disconnecting Rx during Tx.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Marek Vasut <marex@denx.de>
Cc: linux-stm32@st-md-mailman.stormreply.com
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 drivers/tty/serial/stm32-usart.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index dfdbcf092fac..91ff6d386932 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -226,7 +226,14 @@ static int stm32_usart_config_rs485(struct uart_port *port, struct ktermios *ter
 
 	stm32_usart_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit));
 
-	rs485conf->flags |= SER_RS485_RX_DURING_TX;
+	if (port->rs485_rx_during_tx_gpio) {
+		if (rs485conf->flags & SER_RS485_RX_DURING_TX)
+			gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, 1);
+		else
+			gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, 0);
+	} else {
+		rs485conf->flags |= SER_RS485_RX_DURING_TX;
+	}
 
 	if (rs485conf->flags & SER_RS485_ENABLED) {
 		cr1 = readl_relaxed(port->membase + ofs->cr1);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/4] serial: stm32: Add support for rs485 RX_DURING_TX GPIO
@ 2022-10-26 16:50   ` Christoph Niedermaier
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-26 16:50 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Maxime Coquelin, Alexandre Torgue,
	linux-stm32

If a RX_DURING_TX GPIO is defined by the DT property "rs485-rx-during-tx-gpios"
this patch switches this GPIO accordingly to the RS485 flag RX_DURING_TX in user
space. Controlled by this GPIO, now the hardware is responsible for connecting
or disconnecting Rx during Tx.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Marek Vasut <marex@denx.de>
Cc: linux-stm32@st-md-mailman.stormreply.com
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 drivers/tty/serial/stm32-usart.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index dfdbcf092fac..91ff6d386932 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -226,7 +226,14 @@ static int stm32_usart_config_rs485(struct uart_port *port, struct ktermios *ter
 
 	stm32_usart_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit));
 
-	rs485conf->flags |= SER_RS485_RX_DURING_TX;
+	if (port->rs485_rx_during_tx_gpio) {
+		if (rs485conf->flags & SER_RS485_RX_DURING_TX)
+			gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, 1);
+		else
+			gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, 0);
+	} else {
+		rs485conf->flags |= SER_RS485_RX_DURING_TX;
+	}
 
 	if (rs485conf->flags & SER_RS485_ENABLED) {
 		cr1 = readl_relaxed(port->membase + ofs->cr1);
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
  2022-10-26 16:50   ` Christoph Niedermaier
@ 2022-10-26 20:59     ` Rob Herring
  -1 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2022-10-26 20:59 UTC (permalink / raw)
  To: Christoph Niedermaier
  Cc: linux-serial, linux-arm-kernel, krzysztof.kozlowski+dt, marex,
	jirislaby, Greg Kroah-Hartman, devicetree

On Wed, Oct 26, 2022 at 06:50:46PM +0200, Christoph Niedermaier wrote:
> Add the binding for a generic definition of a GPIO, that controls whether Rx
> is connected or disconnected by an electrical circuit to have the ability
> to receive the signals on the bus during sending or disable receiving during
> sending.
> 
> Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
> ---
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
> Cc: Marek Vasut <marex@denx.de>
> Cc: devicetree@vger.kernel.org
> To: linux-serial@vger.kernel.org
> To: linux-arm-kernel@lists.infradead.org
> ---
>  Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
> index 90a1bab40f05..0ebd7690f85d 100644
> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
> @@ -51,6 +51,10 @@ properties:
>      description: GPIO pin to enable RS485 bus termination.
>      maxItems: 1
>  
> +  rs485-rx-during-tx-gpios:
> +    description: GPIO pin to control RS485 Rx enable during Tx.

Active state means do what? And inactive? This is an output gating the 
RX signal or an input telling the receiver what to do during tx? The 
description is not adequate.

How does this property relate to 'rs485-rx-during-tx' Any combination of 
the 2 being present or not is okay? If not, you need some constraints.

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
@ 2022-10-26 20:59     ` Rob Herring
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2022-10-26 20:59 UTC (permalink / raw)
  To: Christoph Niedermaier
  Cc: linux-serial, linux-arm-kernel, krzysztof.kozlowski+dt, marex,
	jirislaby, Greg Kroah-Hartman, devicetree

On Wed, Oct 26, 2022 at 06:50:46PM +0200, Christoph Niedermaier wrote:
> Add the binding for a generic definition of a GPIO, that controls whether Rx
> is connected or disconnected by an electrical circuit to have the ability
> to receive the signals on the bus during sending or disable receiving during
> sending.
> 
> Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
> ---
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
> Cc: Marek Vasut <marex@denx.de>
> Cc: devicetree@vger.kernel.org
> To: linux-serial@vger.kernel.org
> To: linux-arm-kernel@lists.infradead.org
> ---
>  Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
> index 90a1bab40f05..0ebd7690f85d 100644
> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
> @@ -51,6 +51,10 @@ properties:
>      description: GPIO pin to enable RS485 bus termination.
>      maxItems: 1
>  
> +  rs485-rx-during-tx-gpios:
> +    description: GPIO pin to control RS485 Rx enable during Tx.

Active state means do what? And inactive? This is an output gating the 
RX signal or an input telling the receiver what to do during tx? The 
description is not adequate.

How does this property relate to 'rs485-rx-during-tx' Any combination of 
the 2 being present or not is okay? If not, you need some constraints.

Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
  2022-10-26 20:59     ` Rob Herring
@ 2022-10-27 12:06       ` Christoph Niedermaier
  -1 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-27 12:06 UTC (permalink / raw)
  To: Rob Herring
  Cc: linux-serial, linux-arm-kernel, krzysztof.kozlowski+dt, marex,
	jirislaby, Greg Kroah-Hartman, devicetree

From: Rob Herring [mailto:robh@kernel.org]
Sent: Wednesday, October 26, 2022 10:59 PM
> On Wed, Oct 26, 2022 at 06:50:46PM +0200, Christoph Niedermaier wrote:
>> Add the binding for a generic definition of a GPIO, that controls whether Rx
>> is connected or disconnected by an electrical circuit to have the ability
>> to receive the signals on the bus during sending or disable receiving during
>> sending.
>>
>> Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
>> ---
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: Rob Herring <robh+dt@kernel.org>
>> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
>> Cc: Marek Vasut <marex@denx.de>
>> Cc: devicetree@vger.kernel.org
>> To: linux-serial@vger.kernel.org
>> To: linux-arm-kernel@lists.infradead.org
>> ---
>>  Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
>> index 90a1bab40f05..0ebd7690f85d 100644
>> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
>> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
>> @@ -51,6 +51,10 @@ properties:
>>      description: GPIO pin to enable RS485 bus termination.
>>      maxItems: 1
>>
>> +  rs485-rx-during-tx-gpios:
>> +    description: GPIO pin to control RS485 Rx enable during Tx.
> 
> Active state means do what? And inactive? This is an output gating the
> RX signal or an input telling the receiver what to do during tx? The
> description is not adequate.
> 
> How does this property relate to 'rs485-rx-during-tx' Any combination of
> the 2 being present or not is okay? If not, you need some constraints.
> 
> Rob


Hi Rob,

I have improved the message:

The standard RS485 is a half-duplex bus that in most cased is driven by an
UART controller. The interface to the bus is controlled by a transceiver, that
has a pin called RE (Rx enable) or similar, which connects the bus to Rx signal
of the UART controller. This patch adds a binding for a generic definition of a
GPIO that can switch between two states to control the RE pin via an electrical
circuit:
- Active:
  The RE pin is always active. The UART Rx see everything on the bus and
  therefore also what happens with the Tx signal on the bus.
- Inactive:
  The RE pin is always active, but during sending on the bus the pin RE is
  inactive. So basically the receiving during sending is suppressed.

Is it now more understandable, or have I still not considered an aspect?


Thanks and regards
Christoph

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
@ 2022-10-27 12:06       ` Christoph Niedermaier
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-27 12:06 UTC (permalink / raw)
  To: Rob Herring
  Cc: linux-serial, linux-arm-kernel, krzysztof.kozlowski+dt, marex,
	jirislaby, Greg Kroah-Hartman, devicetree

From: Rob Herring [mailto:robh@kernel.org]
Sent: Wednesday, October 26, 2022 10:59 PM
> On Wed, Oct 26, 2022 at 06:50:46PM +0200, Christoph Niedermaier wrote:
>> Add the binding for a generic definition of a GPIO, that controls whether Rx
>> is connected or disconnected by an electrical circuit to have the ability
>> to receive the signals on the bus during sending or disable receiving during
>> sending.
>>
>> Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
>> ---
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: Rob Herring <robh+dt@kernel.org>
>> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
>> Cc: Marek Vasut <marex@denx.de>
>> Cc: devicetree@vger.kernel.org
>> To: linux-serial@vger.kernel.org
>> To: linux-arm-kernel@lists.infradead.org
>> ---
>>  Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
>> index 90a1bab40f05..0ebd7690f85d 100644
>> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
>> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
>> @@ -51,6 +51,10 @@ properties:
>>      description: GPIO pin to enable RS485 bus termination.
>>      maxItems: 1
>>
>> +  rs485-rx-during-tx-gpios:
>> +    description: GPIO pin to control RS485 Rx enable during Tx.
> 
> Active state means do what? And inactive? This is an output gating the
> RX signal or an input telling the receiver what to do during tx? The
> description is not adequate.
> 
> How does this property relate to 'rs485-rx-during-tx' Any combination of
> the 2 being present or not is okay? If not, you need some constraints.
> 
> Rob


Hi Rob,

I have improved the message:

The standard RS485 is a half-duplex bus that in most cased is driven by an
UART controller. The interface to the bus is controlled by a transceiver, that
has a pin called RE (Rx enable) or similar, which connects the bus to Rx signal
of the UART controller. This patch adds a binding for a generic definition of a
GPIO that can switch between two states to control the RE pin via an electrical
circuit:
- Active:
  The RE pin is always active. The UART Rx see everything on the bus and
  therefore also what happens with the Tx signal on the bus.
- Inactive:
  The RE pin is always active, but during sending on the bus the pin RE is
  inactive. So basically the receiving during sending is suppressed.

Is it now more understandable, or have I still not considered an aspect?


Thanks and regards
Christoph
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
  2022-10-27 12:06       ` Christoph Niedermaier
@ 2022-10-28  6:20         ` Alexander Dahl
  -1 siblings, 0 replies; 18+ messages in thread
From: Alexander Dahl @ 2022-10-28  6:20 UTC (permalink / raw)
  To: Christoph Niedermaier
  Cc: Rob Herring, linux-serial, linux-arm-kernel,
	krzysztof.kozlowski+dt, marex, jirislaby, Greg Kroah-Hartman,
	devicetree

Hello Christoph,

let me first say, for an upcoming new product we are currently
developing, we tried different wirings, all related to that !RE pin of
the transceiver.

In a first hardware revision the engineer doing the schematic
connected !RE to GND (always on) and it took me a while to recognize
what was going on: everything send through TX was mirrored on RX,
which makes using lots of standard applications on that port just
fail.  (To be fair, we need exactly that behaviour on a different
board.)

In a second iteration !RE is directly connected to DE now, so RE is
now always the opposite of DE.  DE itself is always connected to the
RTS line of the UART, which allows the driver to switch direction.

More below.

Am Thu, Oct 27, 2022 at 12:06:56PM +0000 schrieb Christoph Niedermaier:
> From: Rob Herring [mailto:robh@kernel.org]
> Sent: Wednesday, October 26, 2022 10:59 PM
> > On Wed, Oct 26, 2022 at 06:50:46PM +0200, Christoph Niedermaier wrote:
> >> Add the binding for a generic definition of a GPIO, that controls whether Rx
> >> is connected or disconnected by an electrical circuit to have the ability
> >> to receive the signals on the bus during sending or disable receiving during
> >> sending.
> >>
> >> Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
> >> ---
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Cc: Rob Herring <robh+dt@kernel.org>
> >> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
> >> Cc: Marek Vasut <marex@denx.de>
> >> Cc: devicetree@vger.kernel.org
> >> To: linux-serial@vger.kernel.org
> >> To: linux-arm-kernel@lists.infradead.org
> >> ---
> >>  Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
> >>  1 file changed, 4 insertions(+)
> >>
> >> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
> >> index 90a1bab40f05..0ebd7690f85d 100644
> >> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
> >> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
> >> @@ -51,6 +51,10 @@ properties:
> >>      description: GPIO pin to enable RS485 bus termination.
> >>      maxItems: 1
> >>
> >> +  rs485-rx-during-tx-gpios:
> >> +    description: GPIO pin to control RS485 Rx enable during Tx.
> > 
> > Active state means do what? And inactive? This is an output gating the
> > RX signal or an input telling the receiver what to do during tx? The
> > description is not adequate.
> > 
> > How does this property relate to 'rs485-rx-during-tx' Any combination of
> > the 2 being present or not is okay? If not, you need some constraints.
> > 
> > Rob
> 
> 
> Hi Rob,
> 
> I have improved the message:
> 
> The standard RS485 is a half-duplex bus that in most cased is driven by an
> UART controller. The interface to the bus is controlled by a transceiver, that
> has a pin called RE (Rx enable) or similar, which connects the bus to Rx signal
> of the UART controller. This patch adds a binding for a generic definition of a
> GPIO that can switch between two states to control the RE pin via an electrical
> circuit:
> - Active:
>   The RE pin is always active. The UART Rx see everything on the bus and
>   therefore also what happens with the Tx signal on the bus.
> - Inactive:
>   The RE pin is always active, but during sending on the bus the pin RE is
>   inactive. So basically the receiving during sending is suppressed.
> 
> Is it now more understandable, or have I still not considered an aspect?

Better.  But what about the questions Rob asked?  There's already a
property 'rs485-rx-during-tx' which leads to setting the flag
SER_RS485_RX_DURING_TX in serial core.  As far as I understood from a
quick glance at core and drivers, this deals with half or full duplex
from the UART point of view (not the transceiver).

You need to explain, what's the difference to the new property.
I suspect you want to somehow switch behaviour with that GPIO line?
Which driver should switch that line in the end and when?

(For third iteration of our hardware we thought about a GPIO
controlling whether !RE is always on or connected to DE, but that's
probably not what you have in mind?)

Maybe a simple generic schematic could help explain or maybe you find
a better name for the property?

Greets
Alex

> 
> 
> Thanks and regards
> Christoph

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
@ 2022-10-28  6:20         ` Alexander Dahl
  0 siblings, 0 replies; 18+ messages in thread
From: Alexander Dahl @ 2022-10-28  6:20 UTC (permalink / raw)
  To: Christoph Niedermaier
  Cc: Rob Herring, linux-serial, linux-arm-kernel,
	krzysztof.kozlowski+dt, marex, jirislaby, Greg Kroah-Hartman,
	devicetree

Hello Christoph,

let me first say, for an upcoming new product we are currently
developing, we tried different wirings, all related to that !RE pin of
the transceiver.

In a first hardware revision the engineer doing the schematic
connected !RE to GND (always on) and it took me a while to recognize
what was going on: everything send through TX was mirrored on RX,
which makes using lots of standard applications on that port just
fail.  (To be fair, we need exactly that behaviour on a different
board.)

In a second iteration !RE is directly connected to DE now, so RE is
now always the opposite of DE.  DE itself is always connected to the
RTS line of the UART, which allows the driver to switch direction.

More below.

Am Thu, Oct 27, 2022 at 12:06:56PM +0000 schrieb Christoph Niedermaier:
> From: Rob Herring [mailto:robh@kernel.org]
> Sent: Wednesday, October 26, 2022 10:59 PM
> > On Wed, Oct 26, 2022 at 06:50:46PM +0200, Christoph Niedermaier wrote:
> >> Add the binding for a generic definition of a GPIO, that controls whether Rx
> >> is connected or disconnected by an electrical circuit to have the ability
> >> to receive the signals on the bus during sending or disable receiving during
> >> sending.
> >>
> >> Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
> >> ---
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Cc: Rob Herring <robh+dt@kernel.org>
> >> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
> >> Cc: Marek Vasut <marex@denx.de>
> >> Cc: devicetree@vger.kernel.org
> >> To: linux-serial@vger.kernel.org
> >> To: linux-arm-kernel@lists.infradead.org
> >> ---
> >>  Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
> >>  1 file changed, 4 insertions(+)
> >>
> >> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
> >> index 90a1bab40f05..0ebd7690f85d 100644
> >> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
> >> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
> >> @@ -51,6 +51,10 @@ properties:
> >>      description: GPIO pin to enable RS485 bus termination.
> >>      maxItems: 1
> >>
> >> +  rs485-rx-during-tx-gpios:
> >> +    description: GPIO pin to control RS485 Rx enable during Tx.
> > 
> > Active state means do what? And inactive? This is an output gating the
> > RX signal or an input telling the receiver what to do during tx? The
> > description is not adequate.
> > 
> > How does this property relate to 'rs485-rx-during-tx' Any combination of
> > the 2 being present or not is okay? If not, you need some constraints.
> > 
> > Rob
> 
> 
> Hi Rob,
> 
> I have improved the message:
> 
> The standard RS485 is a half-duplex bus that in most cased is driven by an
> UART controller. The interface to the bus is controlled by a transceiver, that
> has a pin called RE (Rx enable) or similar, which connects the bus to Rx signal
> of the UART controller. This patch adds a binding for a generic definition of a
> GPIO that can switch between two states to control the RE pin via an electrical
> circuit:
> - Active:
>   The RE pin is always active. The UART Rx see everything on the bus and
>   therefore also what happens with the Tx signal on the bus.
> - Inactive:
>   The RE pin is always active, but during sending on the bus the pin RE is
>   inactive. So basically the receiving during sending is suppressed.
> 
> Is it now more understandable, or have I still not considered an aspect?

Better.  But what about the questions Rob asked?  There's already a
property 'rs485-rx-during-tx' which leads to setting the flag
SER_RS485_RX_DURING_TX in serial core.  As far as I understood from a
quick glance at core and drivers, this deals with half or full duplex
from the UART point of view (not the transceiver).

You need to explain, what's the difference to the new property.
I suspect you want to somehow switch behaviour with that GPIO line?
Which driver should switch that line in the end and when?

(For third iteration of our hardware we thought about a GPIO
controlling whether !RE is always on or connected to DE, but that's
probably not what you have in mind?)

Maybe a simple generic schematic could help explain or maybe you find
a better name for the property?

Greets
Alex

> 
> 
> Thanks and regards
> Christoph

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
  2022-10-28  6:20         ` Alexander Dahl
@ 2022-10-28  8:27           ` Christoph Niedermaier
  -1 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-28  8:27 UTC (permalink / raw)
  To: Alexander Dahl
  Cc: Rob Herring, linux-serial, linux-arm-kernel,
	krzysztof.kozlowski+dt, marex, jirislaby, Greg Kroah-Hartman,
	devicetree

From: Alexander Dahl [mailto:ada@thorsis.com]
Sent: Friday, October 28, 2022 8:21 AM
> 
> Hello Christoph,
> 

Hello Alex,

> let me first say, for an upcoming new product we are currently
> developing, we tried different wirings, all related to that !RE pin of
> the transceiver.
> 
> In a first hardware revision the engineer doing the schematic
> connected !RE to GND (always on) and it took me a while to recognize
> what was going on: everything send through TX was mirrored on RX,
> which makes using lots of standard applications on that port just
> fail.  (To be fair, we need exactly that behaviour on a different
> board.)
> 
> In a second iteration !RE is directly connected to DE now, so RE is
> now always the opposite of DE.  DE itself is always connected to the
> RTS line of the UART, which allows the driver to switch direction.
> 
> More below.
> 
> Am Thu, Oct 27, 2022 at 12:06:56PM +0000 schrieb Christoph Niedermaier:
>> From: Rob Herring [mailto:robh@kernel.org]
>> Sent: Wednesday, October 26, 2022 10:59 PM
>>> On Wed, Oct 26, 2022 at 06:50:46PM +0200, Christoph Niedermaier wrote:
>>>> Add the binding for a generic definition of a GPIO, that controls whether Rx
>>>> is connected or disconnected by an electrical circuit to have the ability
>>>> to receive the signals on the bus during sending or disable receiving during
>>>> sending.
>>>>
>>>> Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
>>>> ---
>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>> Cc: Rob Herring <robh+dt@kernel.org>
>>>> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
>>>> Cc: Marek Vasut <marex@denx.de>
>>>> Cc: devicetree@vger.kernel.org
>>>> To: linux-serial@vger.kernel.org
>>>> To: linux-arm-kernel@lists.infradead.org
>>>> ---
>>>>  Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
>>>>  1 file changed, 4 insertions(+)
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
>>>> index 90a1bab40f05..0ebd7690f85d 100644
>>>> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
>>>> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
>>>> @@ -51,6 +51,10 @@ properties:
>>>>      description: GPIO pin to enable RS485 bus termination.
>>>>      maxItems: 1
>>>>
>>>> +  rs485-rx-during-tx-gpios:
>>>> +    description: GPIO pin to control RS485 Rx enable during Tx.
>>>
>>> Active state means do what? And inactive? This is an output gating the
>>> RX signal or an input telling the receiver what to do during tx? The
>>> description is not adequate.
>>>
>>> How does this property relate to 'rs485-rx-during-tx' Any combination of
>>> the 2 being present or not is okay? If not, you need some constraints.
>>>
>>> Rob
>>
>>
>> Hi Rob,
>>
>> I have improved the message:
>>
>> The standard RS485 is a half-duplex bus that in most cased is driven by an
>> UART controller. The interface to the bus is controlled by a transceiver, that
>> has a pin called RE (Rx enable) or similar, which connects the bus to Rx signal
>> of the UART controller. This patch adds a binding for a generic definition of a
>> GPIO that can switch between two states to control the RE pin via an electrical
>> circuit:
>> - Active:
>>   The RE pin is always active. The UART Rx see everything on the bus and
>>   therefore also what happens with the Tx signal on the bus.
>> - Inactive:
>>   The RE pin is always active, but during sending on the bus the pin RE is
>>   inactive. So basically the receiving during sending is suppressed.
>>
>> Is it now more understandable, or have I still not considered an aspect?
> 
> Better.  But what about the questions Rob asked?  There's already a
> property 'rs485-rx-during-tx' which leads to setting the flag
> SER_RS485_RX_DURING_TX in serial core.  As far as I understood from a
> quick glance at core and drivers, this deals with half or full duplex
> from the UART point of view (not the transceiver).
> 
> You need to explain, what's the difference to the new property.
> I suspect you want to somehow switch behaviour with that GPIO line?
> Which driver should switch that line in the end and when?
> 
> (For third iteration of our hardware we thought about a GPIO
> controlling whether !RE is always on or connected to DE, but that's
> probably not what you have in mind?)
> 
> Maybe a simple generic schematic could help explain or maybe you find
> a better name for the property?
> 
> Greets
> Alex

Basically the idea is that this GPIO is an indicator for the state of the
flag 'rs485-rx-during-tx', so that the hardware knows which mode for the
receiving is wanted.

My schematics:
                                 ┌──────────────────┐
                                 │     RS484        │
               Tx ───────────────┤D                 │
                                 │     Transceiver  │
              RTS ────┬──────────┤DE                │
                      │          │                  │
                      │ ┌─────┐  │                  │
                      └─┤&    │  │                  │
                        │     ├──┤!RE               │
!rx_during_tx_gpio ─────┤     │  │                  │
                        └─────┘  │                  │
                                 │                  │
               Rx ───────────────┤R                 │
                                 │                  │
                                 └──────────────────┘

I muxed the UART CTS pin as GPIO and use it as rx_during_tx_gpio, because
in my case this pin is unused anyway. It should be noted that I then use
this pin LOW ACTIVE (in DT by GPIO_ACTIVE_LOW).

I hope it has become clearer what I am doing.
Do you still think I need another name?


Regards
Christoph

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
@ 2022-10-28  8:27           ` Christoph Niedermaier
  0 siblings, 0 replies; 18+ messages in thread
From: Christoph Niedermaier @ 2022-10-28  8:27 UTC (permalink / raw)
  To: Alexander Dahl
  Cc: Rob Herring, linux-serial, linux-arm-kernel,
	krzysztof.kozlowski+dt, marex, jirislaby, Greg Kroah-Hartman,
	devicetree

From: Alexander Dahl [mailto:ada@thorsis.com]
Sent: Friday, October 28, 2022 8:21 AM
> 
> Hello Christoph,
> 

Hello Alex,

> let me first say, for an upcoming new product we are currently
> developing, we tried different wirings, all related to that !RE pin of
> the transceiver.
> 
> In a first hardware revision the engineer doing the schematic
> connected !RE to GND (always on) and it took me a while to recognize
> what was going on: everything send through TX was mirrored on RX,
> which makes using lots of standard applications on that port just
> fail.  (To be fair, we need exactly that behaviour on a different
> board.)
> 
> In a second iteration !RE is directly connected to DE now, so RE is
> now always the opposite of DE.  DE itself is always connected to the
> RTS line of the UART, which allows the driver to switch direction.
> 
> More below.
> 
> Am Thu, Oct 27, 2022 at 12:06:56PM +0000 schrieb Christoph Niedermaier:
>> From: Rob Herring [mailto:robh@kernel.org]
>> Sent: Wednesday, October 26, 2022 10:59 PM
>>> On Wed, Oct 26, 2022 at 06:50:46PM +0200, Christoph Niedermaier wrote:
>>>> Add the binding for a generic definition of a GPIO, that controls whether Rx
>>>> is connected or disconnected by an electrical circuit to have the ability
>>>> to receive the signals on the bus during sending or disable receiving during
>>>> sending.
>>>>
>>>> Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
>>>> ---
>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>> Cc: Rob Herring <robh+dt@kernel.org>
>>>> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
>>>> Cc: Marek Vasut <marex@denx.de>
>>>> Cc: devicetree@vger.kernel.org
>>>> To: linux-serial@vger.kernel.org
>>>> To: linux-arm-kernel@lists.infradead.org
>>>> ---
>>>>  Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
>>>>  1 file changed, 4 insertions(+)
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
>>>> index 90a1bab40f05..0ebd7690f85d 100644
>>>> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
>>>> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
>>>> @@ -51,6 +51,10 @@ properties:
>>>>      description: GPIO pin to enable RS485 bus termination.
>>>>      maxItems: 1
>>>>
>>>> +  rs485-rx-during-tx-gpios:
>>>> +    description: GPIO pin to control RS485 Rx enable during Tx.
>>>
>>> Active state means do what? And inactive? This is an output gating the
>>> RX signal or an input telling the receiver what to do during tx? The
>>> description is not adequate.
>>>
>>> How does this property relate to 'rs485-rx-during-tx' Any combination of
>>> the 2 being present or not is okay? If not, you need some constraints.
>>>
>>> Rob
>>
>>
>> Hi Rob,
>>
>> I have improved the message:
>>
>> The standard RS485 is a half-duplex bus that in most cased is driven by an
>> UART controller. The interface to the bus is controlled by a transceiver, that
>> has a pin called RE (Rx enable) or similar, which connects the bus to Rx signal
>> of the UART controller. This patch adds a binding for a generic definition of a
>> GPIO that can switch between two states to control the RE pin via an electrical
>> circuit:
>> - Active:
>>   The RE pin is always active. The UART Rx see everything on the bus and
>>   therefore also what happens with the Tx signal on the bus.
>> - Inactive:
>>   The RE pin is always active, but during sending on the bus the pin RE is
>>   inactive. So basically the receiving during sending is suppressed.
>>
>> Is it now more understandable, or have I still not considered an aspect?
> 
> Better.  But what about the questions Rob asked?  There's already a
> property 'rs485-rx-during-tx' which leads to setting the flag
> SER_RS485_RX_DURING_TX in serial core.  As far as I understood from a
> quick glance at core and drivers, this deals with half or full duplex
> from the UART point of view (not the transceiver).
> 
> You need to explain, what's the difference to the new property.
> I suspect you want to somehow switch behaviour with that GPIO line?
> Which driver should switch that line in the end and when?
> 
> (For third iteration of our hardware we thought about a GPIO
> controlling whether !RE is always on or connected to DE, but that's
> probably not what you have in mind?)
> 
> Maybe a simple generic schematic could help explain or maybe you find
> a better name for the property?
> 
> Greets
> Alex

Basically the idea is that this GPIO is an indicator for the state of the
flag 'rs485-rx-during-tx', so that the hardware knows which mode for the
receiving is wanted.

My schematics:
                                 ┌──────────────────┐
                                 │     RS484        │
               Tx ───────────────┤D                 │
                                 │     Transceiver  │
              RTS ────┬──────────┤DE                │
                      │          │                  │
                      │ ┌─────┐  │                  │
                      └─┤&    │  │                  │
                        │     ├──┤!RE               │
!rx_during_tx_gpio ─────┤     │  │                  │
                        └─────┘  │                  │
                                 │                  │
               Rx ───────────────┤R                 │
                                 │                  │
                                 └──────────────────┘

I muxed the UART CTS pin as GPIO and use it as rx_during_tx_gpio, because
in my case this pin is unused anyway. It should be noted that I then use
this pin LOW ACTIVE (in DT by GPIO_ACTIVE_LOW).

I hope it has become clearer what I am doing.
Do you still think I need another name?


Regards
Christoph
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-10-28  8:38 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 16:50 [PATCH 0/4] tty: serial: Add ability to control rs485 RX_DURING_TX via a GPIO Christoph Niedermaier
2022-10-26 16:50 ` Christoph Niedermaier
2022-10-26 16:50 ` [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Christoph Niedermaier
2022-10-26 16:50   ` Christoph Niedermaier
2022-10-26 20:59   ` Rob Herring
2022-10-26 20:59     ` Rob Herring
2022-10-27 12:06     ` Christoph Niedermaier
2022-10-27 12:06       ` Christoph Niedermaier
2022-10-28  6:20       ` Alexander Dahl
2022-10-28  6:20         ` Alexander Dahl
2022-10-28  8:27         ` Christoph Niedermaier
2022-10-28  8:27           ` Christoph Niedermaier
2022-10-26 16:50 ` [PATCH 2/4] serial: core: Add option to control rs485 RX_DURING_TX by a GPIO Christoph Niedermaier
2022-10-26 16:50   ` Christoph Niedermaier
2022-10-26 16:50 ` [PATCH 3/4] serial: imx: Add support for rs485 RX_DURING_TX GPIO Christoph Niedermaier
2022-10-26 16:50   ` Christoph Niedermaier
2022-10-26 16:50 ` [PATCH 4/4] serial: stm32: " Christoph Niedermaier
2022-10-26 16:50   ` Christoph Niedermaier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.