linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
@ 2022-11-23 12:30 Christoph Niedermaier
  2022-11-23 12:30 ` [PATCH V2 2/4] serial: core: Add option to output RS485 RX_DURING_TX state via GPIO Christoph Niedermaier
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Christoph Niedermaier @ 2022-11-23 12:30 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Rob Herring, Alexander Dahl, kernel,
	devicetree

This patch adds a binding for a generic definition of an output GPIO that
indicates the state of rs485-rx-during-tx. The idea is that the hardware
already controls the option receiving during sending before it gets to the
signal receiving hardware. The standard RS485 is a half-duplex bus that in
most cases is driven by an UART controller. The advantage of using this
GPIO is that it is independent of the capabilities of the UART core and
the UART driver. On the hardware side 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 the RX signal of the UART controller.
The GPIO 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.

A possible circuit diagram could look like this:
                                  ┌──────────────────┐
                                  │       RS485      │
                TX ───────────────┤D                 │
                                  │    Transceiver   │
               RTS ────┬──────────┤DE                │
                       │          │                  │
                       │ ┌─────┐  │                  │
                       └─┤&    │  │                  │
                         │     ├──┤!RE               │
!rx_during_tx_gpio ──────┤     │  │                  │
                         └─────┘  │                  │
                                  │                  │
                RX ───────────────┤R                 │
                                  │                  │
                                  └──────────────────┘

Here the RTS pin of the UART core is used to control TX via the transceiver
pin DE (Drive Enable). RE and rx_during_tx_gpio are active low.

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: Alexander Dahl <ada@thorsis.com>
Cc: Marek Vasut <marex@denx.de>
Cc: kernel@dh-electronics.com
Cc: devicetree@vger.kernel.org
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
V2: - Rework of the commit message
    - Rework GPIO property comment
---
 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..6d780911e342 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: Output GPIO pin that indicates the state of rs485-rx-during-tx.
+    maxItems: 1
+
 additionalProperties: true
 
 ...
-- 
2.11.0


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

* [PATCH V2 2/4] serial: core: Add option to output RS485 RX_DURING_TX state via GPIO
  2022-11-23 12:30 [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Christoph Niedermaier
@ 2022-11-23 12:30 ` Christoph Niedermaier
  2022-11-23 12:30 ` [PATCH V2 3/4] serial: imx: Add support for RS485 RX_DURING_TX output GPIO Christoph Niedermaier
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Niedermaier @ 2022-11-23 12:30 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Alexander Dahl, kernel, Linux Team

This patch provides a generic GPIO variable for outputting the state
of RS485 RX_DURING_TX. 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: Alexander Dahl <ada@thorsis.com>
Cc: Marek Vasut <marex@denx.de>
Cc: kernel@dh-electronics.com
Cc: Linux Team <linux-imx@nxp.com>
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
V2: - Rework of the commit message
    - Rework GPIO property comment
---
 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 b9fbbee598b8..867f2675caca 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 fd59f600094a..e0c83d05ae7b 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; /* Output GPIO that indicates the state of RS485 RX during TX */
 	struct serial_iso7816   iso7816;
 	void			*private_data;		/* generic platform data pointer */
 };
-- 
2.11.0


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

* [PATCH V2 3/4] serial: imx: Add support for RS485 RX_DURING_TX output GPIO
  2022-11-23 12:30 [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Christoph Niedermaier
  2022-11-23 12:30 ` [PATCH V2 2/4] serial: core: Add option to output RS485 RX_DURING_TX state via GPIO Christoph Niedermaier
@ 2022-11-23 12:30 ` Christoph Niedermaier
  2022-11-23 12:30 ` [PATCH V2 4/4] serial: stm32: Add support for rs485 " Christoph Niedermaier
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Niedermaier @ 2022-11-23 12:30 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, Alexander Dahl, Fabio Estevam, kernel,
	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: Alexander Dahl <ada@thorsis.com>
Cc: Fabio Estevam <festevam@denx.de>
Cc: Marek Vasut <marex@denx.de>
Cc: kernel@dh-electronics.com
Cc: Linux Team <linux-imx@nxp.com>
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
V2: - Rework of the commit message
---
 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 757825edb0cd..f241f16472f2 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;
 		}
@@ -705,7 +706,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;
@@ -1955,6 +1957,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] 6+ messages in thread

* [PATCH V2 4/4] serial: stm32: Add support for rs485 RX_DURING_TX output GPIO
  2022-11-23 12:30 [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Christoph Niedermaier
  2022-11-23 12:30 ` [PATCH V2 2/4] serial: core: Add option to output RS485 RX_DURING_TX state via GPIO Christoph Niedermaier
  2022-11-23 12:30 ` [PATCH V2 3/4] serial: imx: Add support for RS485 RX_DURING_TX output GPIO Christoph Niedermaier
@ 2022-11-23 12:30 ` Christoph Niedermaier
  2022-11-24 10:03 ` [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Krzysztof Kozlowski
  2022-11-30 21:15 ` Rob Herring
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Niedermaier @ 2022-11-23 12:30 UTC (permalink / raw)
  To: linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Christoph Niedermaier,
	Greg Kroah-Hartman, Maxime Coquelin, Alexandre Torgue,
	Alexander Dahl, kernel, 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: Alexander Dahl <ada@thorsis.com>
Cc: Marek Vasut <marex@denx.de>
Cc: kernel@dh-electronics.com
Cc: linux-stm32@st-md-mailman.stormreply.com
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
V2: - Rework of the commit message
---
 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 24def72b2565..f1bef784b020 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] 6+ messages in thread

* Re: [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx
  2022-11-23 12:30 [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Christoph Niedermaier
                   ` (2 preceding siblings ...)
  2022-11-23 12:30 ` [PATCH V2 4/4] serial: stm32: Add support for rs485 " Christoph Niedermaier
@ 2022-11-24 10:03 ` Krzysztof Kozlowski
  2022-11-30 21:15 ` Rob Herring
  4 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-24 10:03 UTC (permalink / raw)
  To: Christoph Niedermaier, linux-serial, linux-arm-kernel
  Cc: krzysztof.kozlowski+dt, marex, jirislaby, Greg Kroah-Hartman,
	Rob Herring, Alexander Dahl, kernel, devicetree

On 23/11/2022 13:30, Christoph Niedermaier wrote:
> This patch adds a binding for a generic definition of an output GPIO that

Do not use "This commit/patch".
https://elixir.bootlin.com/linux/v5.17.1/source/Documentation/process/submitting-patches.rst#L95

> indicates the state of rs485-rx-during-tx. The idea is that the hardware

1. Use subject prefixes matching the subsystem (git log --oneline -- ...).
(no underscores)

2. Subject: drop second, redundant "bindings".

So it could look like:
dt-bindings: serial: rs485: Add GPIO controlling RX enable during TX

For the ack of contents, I'll leave it to Rob as he was involved in v1
discussion.

Best regards,
Krzysztof


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

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

On Wed, Nov 23, 2022 at 01:30:01PM +0100, Christoph Niedermaier wrote:
> This patch adds a binding for a generic definition of an output GPIO that
> indicates the state of rs485-rx-during-tx. The idea is that the hardware
> already controls the option receiving during sending before it gets to the
> signal receiving hardware. The standard RS485 is a half-duplex bus that in
> most cases is driven by an UART controller. The advantage of using this
> GPIO is that it is independent of the capabilities of the UART core and
> the UART driver. On the hardware side 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 the RX signal of the UART controller.
> The GPIO 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.
> 
> A possible circuit diagram could look like this:
>                                   ┌──────────────────┐
>                                   │       RS485      │
>                 TX ───────────────┤D                 │
>                                   │    Transceiver   │
>                RTS ────┬──────────┤DE                │
>                        │          │                  │
>                        │ ┌─────┐  │                  │
>                        └─┤&    │  │                  │
>                          │     ├──┤!RE               │
> !rx_during_tx_gpio ──────┤     │  │                  │
>                          └─────┘  │                  │
>                                   │                  │
>                 RX ───────────────┤R                 │
>                                   │                  │
>                                   └──────────────────┘
> 
> Here the RTS pin of the UART core is used to control TX via the transceiver
> pin DE (Drive Enable). RE and rx_during_tx_gpio are active low.
> 
> 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: Alexander Dahl <ada@thorsis.com>
> Cc: Marek Vasut <marex@denx.de>
> Cc: kernel@dh-electronics.com
> Cc: devicetree@vger.kernel.org
> To: linux-serial@vger.kernel.org
> To: linux-arm-kernel@lists.infradead.org
> ---
> V2: - Rework of the commit message
>     - Rework GPIO property comment
> ---
>  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..6d780911e342 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: Output GPIO pin that indicates the state of rs485-rx-during-tx.

An output sets the state. An input samples or indicates the state.

This should include something about the active state: The active state 
enables RX during TX.

> +    maxItems: 1
> +
>  additionalProperties: true
>  
>  ...
> -- 
> 2.11.0
> 
> 

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

end of thread, other threads:[~2022-11-30 21:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 12:30 [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Christoph Niedermaier
2022-11-23 12:30 ` [PATCH V2 2/4] serial: core: Add option to output RS485 RX_DURING_TX state via GPIO Christoph Niedermaier
2022-11-23 12:30 ` [PATCH V2 3/4] serial: imx: Add support for RS485 RX_DURING_TX output GPIO Christoph Niedermaier
2022-11-23 12:30 ` [PATCH V2 4/4] serial: stm32: Add support for rs485 " Christoph Niedermaier
2022-11-24 10:03 ` [PATCH V2 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Krzysztof Kozlowski
2022-11-30 21:15 ` Rob Herring

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).