dt-bindings: serial: rs485: Add GPIO controlling RX enable during TX
PATCH v4 1/4 dt-bindings: serial: rs485: Add GPIO controlling RX enable during TX
Add a binding for a generic definition of an output GPIO that sets 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.
---
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Alexander Dahl <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
---
V2: - Rework of the commit message
- Rework GPIO property comment
V3: - Rework the binding description
- Rework message title
- Rework of the commit message
V4: - Add Reviewed-by tag
--- Documentation/devicetree/bindings/serial/rs485.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/serial/rs485.yaml +6 -0
@@ -51,6 +51,12 @@ properties: description: GPIO pin to enable RS485 bus termination. maxItems: 1 + rs485-rx-during-tx-gpios: + description: Output GPIO pin that sets the state of rs485-rx-during-tx. This + signal can be used to control the RX part of an RS485 transceiver. Thereby + the active state enables RX during TX. + maxItems: 1 + additionalProperties: true ...
Signature · 1 line
2.11.0
PATCH v4 2/4 serial: core: Add option to output RS485 RX_DURING_TX state via GPIO
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.
---
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Alexander Dahl <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: [email protected]
Cc: Linux Team <[email protected]>
To: [email protected]
To: [email protected]
---
V2: - Rework of the commit message
- Rework GPIO property comment
V3: - Rework GPIO property comment
V4: - No changes
--- drivers/tty/serial/serial_core.c | 12 ++++++++++++ include/linux/serial_core.h | 1 + 2 files changed, 13 insertions(+)
drivers/tty/serial/serial_core.c +12 -0
@@ -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);
include/linux/serial_core.h +1 -0
@@ -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 sets the state of RS485 RX during TX */ struct serial_iso7816 iso7816;void *private_data;/* generic platform data pointer */ };
Signature · 1 line
2.11.0
PATCH v4 3/4 serial: imx: Add support for RS485 RX_DURING_TX output GPIO
In reply to Christoph NiedermaierIf 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.
---
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Alexander Dahl <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: [email protected]
Cc: Linux Team <[email protected]>
To: [email protected]
To: [email protected]
---
V2: - Rework of the commit message
V3: - No changes
V4: - Direct call of gpiod_set_value_cansleep() without if statement
--- drivers/tty/serial/imx.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/tty/serial/imx.c +8 -2
@@ -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,10 @@ 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) +gpiod_set_value_cansleep (port->rs485_rx_during_tx_gpio, + !!(rs485conf->flags &SER_RS485_RX_DURING_TX )); +return 0 ; }
Signature · 1 line
2.11.0
PATCH v4 4/4 serial: stm32: Add support for rs485 RX_DURING_TX output GPIO
In reply to Christoph NiedermaierIf 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.
---
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: Alexander Dahl <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: [email protected]
Cc: [email protected]
To: [email protected]
To: [email protected]
---
V2: - Rework of the commit message
V3: - No changes
V4: - Direct call of gpiod_set_value_cansleep() without if statement
--- drivers/tty/serial/stm32-usart.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/tty/serial/stm32-usart.c +5 -1
@@ -226,7 +226,11 @@ static int stm32_usart_config_rs485(struct uart_port *port, struct ktermios *terstm32_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) +gpiod_set_value_cansleep (port->rs485_rx_during_tx_gpio, + !!(rs485conf->flags &SER_RS485_RX_DURING_TX )); +else + rs485conf->flags |=SER_RS485_RX_DURING_TX ;if (rs485conf->flags &SER_RS485_ENABLED ) { cr1 =readl_relaxed (port->membase + ofs->cr1);
Signature · 7 lines
2.11.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel