[PATCH 2/7] serial: 8250_dwlib: RS485 HW full duplex support

From: Ilpo Järvinen
Date: Wed Mar 02 2022 - 04:57:16 EST


The Synopsys DesignWare UART has a build-in support for the
RS485 protocol from IP version 4.0 onward. This patch enables
the support of HW Full Duplex mode support for it.

To ask for full duplex mode, userspace sets SER_RS485_RX_DURING_TX
flag and HW will take care of the rest.

Co-developed-by: Raymond Tan <raymond.tan@xxxxxxxxx>
Signed-off-by: Raymond Tan <raymond.tan@xxxxxxxxx>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
---
drivers/tty/serial/8250/8250_dwlib.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dwlib.c b/drivers/tty/serial/8250/8250_dwlib.c
index a4f09a95049b..d26792999984 100644
--- a/drivers/tty/serial/8250/8250_dwlib.c
+++ b/drivers/tty/serial/8250/8250_dwlib.c
@@ -110,9 +110,14 @@ static int dw8250_rs485_config(struct uart_port *p, struct serial_rs485 *rs485)

if (rs485->flags & SER_RS485_ENABLED) {
/* Clearing unsupported flags. */
- rs485->flags &= SER_RS485_ENABLED;
-
- tcr |= DW_UART_TCR_RS485_EN | DW_UART_TCR_XFER_MODE_DE_OR_RE;
+ rs485->flags &= SER_RS485_ENABLED | SER_RS485_RX_DURING_TX;
+ tcr |= DW_UART_TCR_RS485_EN;
+
+ if (rs485->flags & SER_RS485_RX_DURING_TX) {
+ tcr |= DW_UART_TCR_XFER_MODE_DE_DURING_RE;
+ } else {
+ tcr |= DW_UART_TCR_XFER_MODE_DE_OR_RE;
+ }
dw8250_writel_ext(p, DW_UART_DE_EN, 1);
dw8250_writel_ext(p, DW_UART_RE_EN, 1);
} else {
--
2.30.2