Skip to content

Commit 5ec93d7

Browse files
SherrySun5gregkh
authored andcommitted
tty: serial: fsl_lpuart: disable transmitter before changing RS485 related registers
commit f5cb528 upstream. According to the LPUART reference manual, TXRTSE and TXRTSPOL of MODIR register only can be changed when the transmitter is disabled. So disable the transmitter before changing RS485 related registers and re-enable it after the change is done. Fixes: 67b0183 ("tty: serial: lpuart: Add RS485 support for 32-bit uart flavour") Cc: stable <stable@kernel.org> Signed-off-by: Sherry Sun <sherry.sun@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20250312022503.1342990-1-sherry.sun@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fe14cfb commit 5ec93d7

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

drivers/tty/serial/fsl_lpuart.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,19 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio
14881488

14891489
unsigned long modem = lpuart32_read(&sport->port, UARTMODIR)
14901490
& ~(UARTMODIR_TXRTSPOL | UARTMODIR_TXRTSE);
1491+
u32 ctrl;
1492+
1493+
/* TXRTSE and TXRTSPOL only can be changed when transmitter is disabled. */
1494+
ctrl = lpuart32_read(&sport->port, UARTCTRL);
1495+
if (ctrl & UARTCTRL_TE) {
1496+
/* wait for the transmit engine to complete */
1497+
lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC);
1498+
lpuart32_write(&sport->port, ctrl & ~UARTCTRL_TE, UARTCTRL);
1499+
1500+
while (lpuart32_read(&sport->port, UARTCTRL) & UARTCTRL_TE)
1501+
cpu_relax();
1502+
}
1503+
14911504
lpuart32_write(&sport->port, modem, UARTMODIR);
14921505

14931506
if (rs485->flags & SER_RS485_ENABLED) {
@@ -1507,6 +1520,10 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio
15071520
}
15081521

15091522
lpuart32_write(&sport->port, modem, UARTMODIR);
1523+
1524+
if (ctrl & UARTCTRL_TE)
1525+
lpuart32_write(&sport->port, ctrl, UARTCTRL);
1526+
15101527
return 0;
15111528
}
15121529

0 commit comments

Comments
 (0)