* [PATCH v5 1/6] dt-bindings: serial: Add binding for rs485 receiver enable GPIO
2024-01-26 17:27 [PATCH v5 0/6] serial: 8250: Add support for rs485 half/full duplex on puma/ringneck-haikou Farouk Bouabid
@ 2024-01-26 17:27 ` Farouk Bouabid
2024-01-30 22:56 ` Rob Herring
2024-01-26 17:27 ` [PATCH v5 2/6] serial: 8250: Support separate rs485 rx-enable GPIO Farouk Bouabid
` (4 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Farouk Bouabid @ 2024-01-26 17:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz, Heiko Stuebner,
Farouk Bouabid
From: Heiko Stuebner <heiko.stuebner@cherry.de>
RS485 has two signals to control transmissions "driver enable" (DE) and
"receiver enable" (RE). DE is already handled via the uarts RTS signal
while the RE signal on most implementations doesn't get handled
separately at all.
As there still will be cases where this is needed though add a gpio
property for declaring this signal pin.
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
---
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 9418fd66a8e9..b64577036b5c 100644
--- a/Documentation/devicetree/bindings/serial/rs485.yaml
+++ b/Documentation/devicetree/bindings/serial/rs485.yaml
@@ -51,6 +51,10 @@ properties:
description: enables the receiving of data even while sending data.
$ref: /schemas/types.yaml#/definitions/flag
+ rs485-rx-enable-gpios:
+ description: GPIO to handle a separate RS485 receive enable signal
+ maxItems: 1
+
rs485-term-gpios:
description: GPIO pin to enable RS485 bus termination.
maxItems: 1
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v5 1/6] dt-bindings: serial: Add binding for rs485 receiver enable GPIO
2024-01-26 17:27 ` [PATCH v5 1/6] dt-bindings: serial: Add binding for rs485 receiver enable GPIO Farouk Bouabid
@ 2024-01-30 22:56 ` Rob Herring
0 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2024-01-30 22:56 UTC (permalink / raw)
To: Farouk Bouabid
Cc: Conor Dooley, Rob Herring, linux-serial, Heiko Stuebner,
linux-arm-kernel, linux-rockchip, Greg Kroah-Hartman, Jiri Slaby,
Heiko Stuebner, devicetree, linux-kernel, quentin.schulz,
Krzysztof Kozlowski
On Fri, 26 Jan 2024 18:27:42 +0100, Farouk Bouabid wrote:
> From: Heiko Stuebner <heiko.stuebner@cherry.de>
>
> RS485 has two signals to control transmissions "driver enable" (DE) and
> "receiver enable" (RE). DE is already handled via the uarts RTS signal
> while the RE signal on most implementations doesn't get handled
> separately at all.
>
> As there still will be cases where this is needed though add a gpio
> property for declaring this signal pin.
>
> Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
> Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
> ---
> Documentation/devicetree/bindings/serial/rs485.yaml | 4 ++++
> 1 file changed, 4 insertions(+)
>
Reviewed-by: Rob Herring <robh@kernel.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v5 2/6] serial: 8250: Support separate rs485 rx-enable GPIO
2024-01-26 17:27 [PATCH v5 0/6] serial: 8250: Add support for rs485 half/full duplex on puma/ringneck-haikou Farouk Bouabid
2024-01-26 17:27 ` [PATCH v5 1/6] dt-bindings: serial: Add binding for rs485 receiver enable GPIO Farouk Bouabid
@ 2024-01-26 17:27 ` Farouk Bouabid
2024-01-26 19:58 ` Lino Sanfilippo
2024-01-26 17:27 ` [PATCH v5 3/6] dt-bindings: serial: add binding for rs485 rx-enable state when rs485 is disabled Farouk Bouabid
` (3 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Farouk Bouabid @ 2024-01-26 17:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz, Heiko Stuebner,
Farouk Bouabid
From: Heiko Stuebner <heiko.stuebner@cherry.de>
The RE signal is used to control the duplex mode of transmissions,
aka receiving data while sending in full duplex mode, while stopping
receiving data in half-duplex mode.
On a number of boards the !RE signal is tied to ground so reception
is always enabled except if the UART allows disabling the receiver.
This can be taken advantage of to implement half-duplex mode - like
done on 8250_bcm2835aux.
Another solution is to tie !RE to RTS always forcing half-duplex mode.
And finally there is the option to control the RE signal separately,
like done here by introducing a new rs485-specific gpio that can be
set depending on the RX_DURING_TX setting in the common em485 callbacks.
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
---
drivers/tty/serial/8250/8250_port.c | 7 ++++++-
drivers/tty/serial/serial_core.c | 7 +++++++
include/linux/serial_core.h | 1 +
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 8ca061d3bbb9..54d8f809b81e 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1402,6 +1402,7 @@ static void serial8250_stop_rx(struct uart_port *port)
void serial8250_em485_stop_tx(struct uart_8250_port *p)
{
unsigned char mcr = serial8250_in_MCR(p);
+ struct uart_port *port = &p->port;
/* Port locked to synchronize UART_IER access against the console. */
lockdep_assert_held_once(&p->port.lock);
@@ -1418,6 +1419,7 @@ void serial8250_em485_stop_tx(struct uart_8250_port *p)
* Enable previously disabled RX interrupts.
*/
if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX)) {
+ gpiod_set_value(port->rs485_re_gpio, 1);
serial8250_clear_and_reinit_fifos(p);
p->ier |= UART_IER_RLSI | UART_IER_RDI;
@@ -1567,9 +1569,12 @@ static inline void __start_tx(struct uart_port *port)
void serial8250_em485_start_tx(struct uart_8250_port *up)
{
unsigned char mcr = serial8250_in_MCR(up);
+ struct uart_port *port = &up->port;
- if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX))
+ if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) {
+ gpiod_set_value(port->rs485_re_gpio, 0);
serial8250_stop_rx(&up->port);
+ }
if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND)
mcr |= UART_MCR_RTS;
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index b56ed8c376b2..8067d20c5275 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3663,6 +3663,13 @@ int uart_get_rs485_mode(struct uart_port *port)
if (port->rs485_rx_during_tx_gpio)
port->rs485_supported.flags |= SER_RS485_RX_DURING_TX;
+ port->rs485_re_gpio = devm_gpiod_get_optional(dev, "rs485-rx-enable", GPIOD_OUT_HIGH);
+ if (IS_ERR(port->rs485_re_gpio)) {
+ ret = PTR_ERR(port->rs485_re_gpio);
+ port->rs485_re_gpio = NULL;
+ return dev_err_probe(dev, ret, "Cannot get rs485-rx-enable-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 536b2581d3e2..364583203a24 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -584,6 +584,7 @@ struct uart_port {
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 gpio_desc *rs485_re_gpio; /* gpio RS485 receive enable */
struct serial_iso7816 iso7816;
void *private_data; /* generic platform data pointer */
};
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v5 2/6] serial: 8250: Support separate rs485 rx-enable GPIO
2024-01-26 17:27 ` [PATCH v5 2/6] serial: 8250: Support separate rs485 rx-enable GPIO Farouk Bouabid
@ 2024-01-26 19:58 ` Lino Sanfilippo
2024-01-29 8:57 ` Farouk Bouabid
0 siblings, 1 reply; 13+ messages in thread
From: Lino Sanfilippo @ 2024-01-26 19:58 UTC (permalink / raw)
To: Farouk Bouabid, Greg Kroah-Hartman, Jiri Slaby, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz, Heiko Stuebner
Hi,
On 26.01.24 18:27, Farouk Bouabid wrote:
> From: Heiko Stuebner <heiko.stuebner@cherry.de>
>
> The RE signal is used to control the duplex mode of transmissions,
> aka receiving data while sending in full duplex mode, while stopping
> receiving data in half-duplex mode.
>
> On a number of boards the !RE signal is tied to ground so reception
> is always enabled except if the UART allows disabling the receiver.
> This can be taken advantage of to implement half-duplex mode - like
> done on 8250_bcm2835aux.
>
> Another solution is to tie !RE to RTS always forcing half-duplex mode.
>
> And finally there is the option to control the RE signal separately,
> like done here by introducing a new rs485-specific gpio that can be
> set depending on the RX_DURING_TX setting in the common em485 callbacks.
>
we just added the rx_during_tx_gpio to the serial core.
Why cant you use this GPIO for your purpose?
Regards,
Lino
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v5 2/6] serial: 8250: Support separate rs485 rx-enable GPIO
2024-01-26 19:58 ` Lino Sanfilippo
@ 2024-01-29 8:57 ` Farouk Bouabid
2024-01-30 12:29 ` Christoph Niedermaier
0 siblings, 1 reply; 13+ messages in thread
From: Farouk Bouabid @ 2024-01-29 8:57 UTC (permalink / raw)
To: Lino Sanfilippo, Greg Kroah-Hartman, Jiri Slaby, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz, Heiko Stuebner
Hi,
On 26.01.24 20:58, Lino Sanfilippo wrote:
> [Some people who received this message don't often get email from linosanfilippo@gmx.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Hi,
>
> On 26.01.24 18:27, Farouk Bouabid wrote:
>> From: Heiko Stuebner <heiko.stuebner@cherry.de>
>>
>> The RE signal is used to control the duplex mode of transmissions,
>> aka receiving data while sending in full duplex mode, while stopping
>> receiving data in half-duplex mode.
>>
>> On a number of boards the !RE signal is tied to ground so reception
>> is always enabled except if the UART allows disabling the receiver.
>> This can be taken advantage of to implement half-duplex mode - like
>> done on 8250_bcm2835aux.
>>
>> Another solution is to tie !RE to RTS always forcing half-duplex mode.
>>
>> And finally there is the option to control the RE signal separately,
>> like done here by introducing a new rs485-specific gpio that can be
>> set depending on the RX_DURING_TX setting in the common em485 callbacks.
>>
> we just added the rx_during_tx_gpio to the serial core.
> Why cant you use this GPIO for your purpose?
>
> Regards,
> Lino.
What we are trying to implement is a gpio that emulates the RTS signal
itself as we do not have a dedicated RTS signal that can be controlled
through MCR. The rx during tx state in our case is a fixed state of
"NO_RX_WHILE_TX"
Regards,
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [PATCH v5 2/6] serial: 8250: Support separate rs485 rx-enable GPIO
2024-01-29 8:57 ` Farouk Bouabid
@ 2024-01-30 12:29 ` Christoph Niedermaier
2024-02-08 15:46 ` Farouk Bouabid
0 siblings, 1 reply; 13+ messages in thread
From: Christoph Niedermaier @ 2024-01-30 12:29 UTC (permalink / raw)
To: Farouk Bouabid, Lino Sanfilippo, Greg Kroah-Hartman, Jiri Slaby,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org,
quentin.schulz@theobroma-systems.com, Heiko Stuebner
From: Farouk Bouabid
Sent: Monday, January 29, 2024 9:57 AM
Hi,
> On 26.01.24 20:58, Lino Sanfilippo wrote:
>> [Some people who received this message don't often get email from linosanfilippo@gmx.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>>
>> Hi,
>>
>> On 26.01.24 18:27, Farouk Bouabid wrote:
>>> From: Heiko Stuebner <heiko.stuebner@cherry.de>
>>>
>>> The RE signal is used to control the duplex mode of transmissions,
>>> aka receiving data while sending in full duplex mode, while stopping
>>> receiving data in half-duplex mode.
>>>
>>> On a number of boards the !RE signal is tied to ground so reception
>>> is always enabled except if the UART allows disabling the receiver.
>>> This can be taken advantage of to implement half-duplex mode - like
>>> done on 8250_bcm2835aux.
>>>
>>> Another solution is to tie !RE to RTS always forcing half-duplex mode.
>>>
>>> And finally there is the option to control the RE signal separately,
>>> like done here by introducing a new rs485-specific gpio that can be
>>> set depending on the RX_DURING_TX setting in the common em485 callbacks.
>>>
>> we just added the rx_during_tx_gpio to the serial core.
>> Why cant you use this GPIO for your purpose?
>>
>> Regards,
>> Lino.
> What we are trying to implement is a gpio that emulates the RTS signal
> itself as we do not have a dedicated RTS signal that can be controlled
> through MCR. The rx during tx state in our case is a fixed state of
> "NO_RX_WHILE_TX"
Why can't the property rts-gpios be used here for this purpose?
Regards
Christoph
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v5 2/6] serial: 8250: Support separate rs485 rx-enable GPIO
2024-01-30 12:29 ` Christoph Niedermaier
@ 2024-02-08 15:46 ` Farouk Bouabid
0 siblings, 0 replies; 13+ messages in thread
From: Farouk Bouabid @ 2024-02-08 15:46 UTC (permalink / raw)
To: Christoph Niedermaier, Lino Sanfilippo, Greg Kroah-Hartman,
Jiri Slaby, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Heiko Stuebner
Cc: Rob Herring, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org,
quentin.schulz@theobroma-systems.com, Heiko Stuebner
Hi Christoph,
On 30.01.24 13:29, Christoph Niedermaier wrote:
> [Einige Personen, die diese Nachricht erhalten haben, erhalten häufig keine E-Mails von cniedermaier@dh-electronics.com. Weitere Informationen, warum dies wichtig ist, finden Sie unter https://aka.ms/LearnAboutSenderIdentification ]
>
> From: Farouk Bouabid
> Sent: Monday, January 29, 2024 9:57 AM
>
> Hi,
>
>> On 26.01.24 20:58, Lino Sanfilippo wrote:
>>> [Some people who received this message don't often get email from linosanfilippo@gmx.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>>>
>>> Hi,
>>>
>>> On 26.01.24 18:27, Farouk Bouabid wrote:
>>>> From: Heiko Stuebner <heiko.stuebner@cherry.de>
>>>>
>>>> The RE signal is used to control the duplex mode of transmissions,
>>>> aka receiving data while sending in full duplex mode, while stopping
>>>> receiving data in half-duplex mode.
>>>>
>>>> On a number of boards the !RE signal is tied to ground so reception
>>>> is always enabled except if the UART allows disabling the receiver.
>>>> This can be taken advantage of to implement half-duplex mode - like
>>>> done on 8250_bcm2835aux.
>>>>
>>>> Another solution is to tie !RE to RTS always forcing half-duplex mode.
>>>>
>>>> And finally there is the option to control the RE signal separately,
>>>> like done here by introducing a new rs485-specific gpio that can be
>>>> set depending on the RX_DURING_TX setting in the common em485 callbacks.
>>>>
>>> we just added the rx_during_tx_gpio to the serial core.
>>> Why cant you use this GPIO for your purpose?
>>>
>>> Regards,
>>> Lino.
>> What we are trying to implement is a gpio that emulates the RTS signal
>> itself as we do not have a dedicated RTS signal that can be controlled
>> through MCR. The rx during tx state in our case is a fixed state of
>> "NO_RX_WHILE_TX"
> Why can't the property rts-gpios be used here for this purpose?
Yes that indeed serves our purpose. Thank you for the suggestion.
Regards
Farouk
>
>
> Regards
> Christoph
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v5 3/6] dt-bindings: serial: add binding for rs485 rx-enable state when rs485 is disabled
2024-01-26 17:27 [PATCH v5 0/6] serial: 8250: Add support for rs485 half/full duplex on puma/ringneck-haikou Farouk Bouabid
2024-01-26 17:27 ` [PATCH v5 1/6] dt-bindings: serial: Add binding for rs485 receiver enable GPIO Farouk Bouabid
2024-01-26 17:27 ` [PATCH v5 2/6] serial: 8250: Support separate rs485 rx-enable GPIO Farouk Bouabid
@ 2024-01-26 17:27 ` Farouk Bouabid
2024-01-30 23:02 ` Rob Herring
2024-01-26 17:27 ` [PATCH v5 4/6] serial: 8250: set rx-enable gpio " Farouk Bouabid
` (2 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Farouk Bouabid @ 2024-01-26 17:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz, Farouk Bouabid
RS485 can have a receiver-enable gpio (rx-enable-gpios). When rs485 is
enabled, this gpio, if provided, must be driven active while receiving.
However when RS485 is disabled this gpio should not have an undefined
state. In that case, as DE and RE pins can be connected both to this gpio,
if its state is not properly defined, can cause unexpected transceiver
behavior.
This binding depend on rx-enable-gpios to be implemented.
Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
---
Documentation/devicetree/bindings/serial/rs485.yaml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
index b64577036b5c..4c79dfaaf460 100644
--- a/Documentation/devicetree/bindings/serial/rs485.yaml
+++ b/Documentation/devicetree/bindings/serial/rs485.yaml
@@ -55,6 +55,11 @@ properties:
description: GPIO to handle a separate RS485 receive enable signal
maxItems: 1
+ rs485-rx-enable-inactive-when-rs485-disabled:
+ description: rx-enable GPIO is not active when RS485 is disabled. If missing, active-state
+ is assumed.
+ $ref: /schemas/types.yaml#/definitions/flag
+
rs485-term-gpios:
description: GPIO pin to enable RS485 bus termination.
maxItems: 1
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v5 3/6] dt-bindings: serial: add binding for rs485 rx-enable state when rs485 is disabled
2024-01-26 17:27 ` [PATCH v5 3/6] dt-bindings: serial: add binding for rs485 rx-enable state when rs485 is disabled Farouk Bouabid
@ 2024-01-30 23:02 ` Rob Herring
0 siblings, 0 replies; 13+ messages in thread
From: Rob Herring @ 2024-01-30 23:02 UTC (permalink / raw)
To: Farouk Bouabid
Cc: Greg Kroah-Hartman, Jiri Slaby, Krzysztof Kozlowski, Conor Dooley,
Heiko Stuebner, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz
On Fri, Jan 26, 2024 at 06:27:44PM +0100, Farouk Bouabid wrote:
> RS485 can have a receiver-enable gpio (rx-enable-gpios). When rs485 is
s/gpio/GPIO/
> enabled, this gpio, if provided, must be driven active while receiving.
> However when RS485 is disabled this gpio should not have an undefined
> state. In that case, as DE and RE pins can be connected both to this gpio,
> if its state is not properly defined, can cause unexpected transceiver
> behavior.
> This binding depend on rx-enable-gpios to be implemented.
Sounds like a constraint:
dependencies:
rs485-rx-enable-inactive-when-rs485-disabled: [ rx-enable-gpios ]
>
> Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
> ---
> Documentation/devicetree/bindings/serial/rs485.yaml | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml
> index b64577036b5c..4c79dfaaf460 100644
> --- a/Documentation/devicetree/bindings/serial/rs485.yaml
> +++ b/Documentation/devicetree/bindings/serial/rs485.yaml
> @@ -55,6 +55,11 @@ properties:
> description: GPIO to handle a separate RS485 receive enable signal
> maxItems: 1
>
> + rs485-rx-enable-inactive-when-rs485-disabled:
For something a bit shorter, perhaps: rs485-rx-enable-inactive-on-disable
> + description: rx-enable GPIO is not active when RS485 is disabled. If missing, active-state
> + is assumed.
> + $ref: /schemas/types.yaml#/definitions/flag
> +
> rs485-term-gpios:
> description: GPIO pin to enable RS485 bus termination.
> maxItems: 1
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v5 4/6] serial: 8250: set rx-enable gpio state when rs485 is disabled
2024-01-26 17:27 [PATCH v5 0/6] serial: 8250: Add support for rs485 half/full duplex on puma/ringneck-haikou Farouk Bouabid
` (2 preceding siblings ...)
2024-01-26 17:27 ` [PATCH v5 3/6] dt-bindings: serial: add binding for rs485 rx-enable state when rs485 is disabled Farouk Bouabid
@ 2024-01-26 17:27 ` Farouk Bouabid
2024-01-26 17:27 ` [PATCH v5 5/6] arm64: dts: rockchip: rk3399-puma-haikou: add rs485 support on uart2 Farouk Bouabid
2024-01-26 17:27 ` [PATCH v5 6/6] arm64: dts: rockchip: px30-ringneck-haikou: add rs485 support on uart5 Farouk Bouabid
5 siblings, 0 replies; 13+ messages in thread
From: Farouk Bouabid @ 2024-01-26 17:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz, Farouk Bouabid
Add the possibility to de-activate rx-enable gpio when rs485 is disabled.
This defines the state of RE or DE/RE signal when em485 is disabled.
Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
---
drivers/tty/serial/8250/8250_port.c | 4 ++++
drivers/tty/serial/serial_core.c | 6 +++++-
include/linux/serial_core.h | 1 +
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 54d8f809b81e..fbd0212d2397 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -582,12 +582,16 @@ static int serial8250_em485_init(struct uart_8250_port *p)
*/
void serial8250_em485_destroy(struct uart_8250_port *p)
{
+ struct uart_port *port = &p->port;
+
if (!p->em485)
return;
hrtimer_cancel(&p->em485->start_tx_timer);
hrtimer_cancel(&p->em485->stop_tx_timer);
+ gpiod_set_value(port->rs485_re_gpio, !port->rs485_re_gpio_inactive_when_rs485_disabled);
+
kfree(p->em485);
p->em485 = NULL;
}
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 8067d20c5275..abcba88dd5a7 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3663,7 +3663,11 @@ int uart_get_rs485_mode(struct uart_port *port)
if (port->rs485_rx_during_tx_gpio)
port->rs485_supported.flags |= SER_RS485_RX_DURING_TX;
- port->rs485_re_gpio = devm_gpiod_get_optional(dev, "rs485-rx-enable", GPIOD_OUT_HIGH);
+ port->rs485_re_gpio_inactive_when_rs485_disabled = device_property_read_bool(dev,
+ "rs485-rx-enable-inactive-when-rs485-disabled");
+
+ port->rs485_re_gpio = devm_gpiod_get_optional(dev, "rs485-rx-enable",
+ port->rs485_re_gpio_inactive_when_rs485_disabled ? GPIOD_OUT_LOW : GPIOD_OUT_HIGH);
if (IS_ERR(port->rs485_re_gpio)) {
ret = PTR_ERR(port->rs485_re_gpio);
port->rs485_re_gpio = NULL;
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 364583203a24..fa5a92b56360 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -585,6 +585,7 @@ struct uart_port {
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 gpio_desc *rs485_re_gpio; /* gpio RS485 receive enable */
+ bool rs485_re_gpio_inactive_when_rs485_disabled;
struct serial_iso7816 iso7816;
void *private_data; /* generic platform data pointer */
};
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v5 5/6] arm64: dts: rockchip: rk3399-puma-haikou: add rs485 support on uart2
2024-01-26 17:27 [PATCH v5 0/6] serial: 8250: Add support for rs485 half/full duplex on puma/ringneck-haikou Farouk Bouabid
` (3 preceding siblings ...)
2024-01-26 17:27 ` [PATCH v5 4/6] serial: 8250: set rx-enable gpio " Farouk Bouabid
@ 2024-01-26 17:27 ` Farouk Bouabid
2024-01-26 17:27 ` [PATCH v5 6/6] arm64: dts: rockchip: px30-ringneck-haikou: add rs485 support on uart5 Farouk Bouabid
5 siblings, 0 replies; 13+ messages in thread
From: Farouk Bouabid @ 2024-01-26 17:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz, Farouk Bouabid
A hardware switch can set the rs485 transceiver into half or full duplex
mode.
Switching to the half-duplex mode requires the user to enable em485 on
uart2 using ioctl, DE/RE are both connected to GPIO2_C3 which is the
RTS signal for uart0. Which means GPIO2_C3 is implemented as rs485
rx-enable gpio.
In full-duplex mode (em485 is disabled), DE is connected to GPIO2_C3 and
RE is grounded (enabled). This requires rx-enable gpio to be inactive to
enable DE as well.
Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
---
arch/arm64/boot/dts/rockchip/rk3399-puma-haikou.dts | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/boot/dts/rockchip/rk3399-puma-haikou.dts b/arch/arm64/boot/dts/rockchip/rk3399-puma-haikou.dts
index 18a98c4648ea..576024c745ed 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-puma-haikou.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-puma-haikou.dts
@@ -273,11 +273,13 @@ &u2phy0_host {
&uart0 {
pinctrl-names = "default";
- pinctrl-0 = <&uart0_xfer &uart0_cts &uart0_rts>;
+ pinctrl-0 = <&uart0_xfer>;
status = "okay";
};
&uart2 {
+ rs485-rx-enable-gpios = <&gpio2 RK_PC3 GPIO_ACTIVE_LOW>;
+ rs485-rx-enable-inactive-when-rs485-disabled;
status = "okay";
};
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v5 6/6] arm64: dts: rockchip: px30-ringneck-haikou: add rs485 support on uart5
2024-01-26 17:27 [PATCH v5 0/6] serial: 8250: Add support for rs485 half/full duplex on puma/ringneck-haikou Farouk Bouabid
` (4 preceding siblings ...)
2024-01-26 17:27 ` [PATCH v5 5/6] arm64: dts: rockchip: rk3399-puma-haikou: add rs485 support on uart2 Farouk Bouabid
@ 2024-01-26 17:27 ` Farouk Bouabid
5 siblings, 0 replies; 13+ messages in thread
From: Farouk Bouabid @ 2024-01-26 17:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Heiko Stuebner
Cc: Rob Herring, linux-kernel, linux-serial, devicetree,
linux-arm-kernel, linux-rockchip, quentin.schulz, Farouk Bouabid
A hardware switch can set the rs485 transceiver into half or full duplex
mode.
Switching to the half-duplex mode requires the user to enable em485 on
uart5 using ioctl, DE/RE are both connected to GPIO0_B5 which is the
RTS signal for uart5. Which means GPIO0_B5 is implemented as rs485
rx-enable gpio.
In full-duplex mode (em485 is disabled), DE is connected to GPIO0_B5 and
RE is grounded (active). This requires rx-enable gpio to be inactive to
enable DE as well.
Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
---
arch/arm64/boot/dts/rockchip/px30-ringneck-haikou.dts | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm64/boot/dts/rockchip/px30-ringneck-haikou.dts b/arch/arm64/boot/dts/rockchip/px30-ringneck-haikou.dts
index 16798eb77077..369a6518a487 100644
--- a/arch/arm64/boot/dts/rockchip/px30-ringneck-haikou.dts
+++ b/arch/arm64/boot/dts/rockchip/px30-ringneck-haikou.dts
@@ -227,6 +227,8 @@ &uart0 {
&uart5 {
pinctrl-0 = <&uart5_xfer>;
+ rs485-rx-enable-gpios = <&gpio0 RK_PB5 GPIO_ACTIVE_LOW>;
+ rs485-rx-enable-inactive-when-rs485-disabled;
status = "okay";
};
--
2.34.1
^ permalink raw reply related [flat|nested] 13+ messages in thread