serial: 8250: handle DTR in rs485 emulation

A patch from »serial: 8250: Add rs485 emulation to 8250_dw« in state Mainline for linux-kernel

From: Heiko Stuebner <heiko.stuebner@...> Date: Thu, 12 Mar 2020 15:15:13 +0100

Commit-Message

While in a lot of cases only RTS is needed as DE signal, sometimes the RE signals is to be controlled separately, as DTR pin. So add necessary control functions for it. Signed-off-by: Heiko Stuebner <heiko.stuebner@...>

Patch-Comment

drivers/tty/serial/8250/8250_port.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)

Statistics

  • 13 lines added
  • 0 lines removed

Changes

--------------------- drivers/tty/serial/8250/8250_port.c ----------------------
index 3d1d8490bc42..f8e5c096ed51 100644
@@ -572,6 +572,10 @@ static inline void serial8250_em485_rts_after_send(struct uart_8250_port *p)
mcr &= ~UART_MCR_RTS;
p->port.mctrl &= ~TIOCM_RTS;
}
+
+ mcr |= UART_MCR_DTR;
+ p->port.mctrl |= TIOCM_DTR;
+
serial8250_out_MCR(p, mcr);
}
@@ -1558,6 +1562,13 @@ static inline void start_tx_rs485(struct uart_port *port)
em485->active_timer = NULL;
mcr = serial8250_in_MCR(up);
+
+ /* in rx_during_tx mode keep DTR active, to receive data */
+ if (up->port.rs485.flags & SER_RS485_RX_DURING_TX)
+ mcr |= UART_MCR_DTR;
+ else
+ mcr &= ~UART_MCR_DTR;
+
if (!!(up->port.rs485.flags & SER_RS485_RTS_ON_SEND) !=
!!(mcr & UART_MCR_RTS)) {
if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND)
@@ -1572,6 +1583,8 @@ static inline void start_tx_rs485(struct uart_port *port)
up->port.rs485.delay_rts_before_send);
return;
}
+ } else {
+ serial8250_out_MCR(up, mcr);
}
__start_tx(port);
 
 

Recent Patches

About Us

Sed lacus. Donec lectus. Nullam pretium nibh ut turpis. Nam bibendum. In nulla tortor, elementum vel, tempor at, varius non, purus. Mauris vitae nisl nec metus placerat consectetuer.

Read More...