[v5,4/6] serial: 8250: set rx-enable gpio state when rs485 is disabled
Commit Message
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(-)
@@ -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;
}
@@ -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;
@@ -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 */
};