Skip to content

Commit f5cb528

Browse files
SherrySun5gregkh
authored andcommitted
tty: serial: fsl_lpuart: disable transmitter before changing RS485 related registers
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 5c7e289 commit f5cb528

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/tty/serial/fsl_lpuart.c

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

14851485
unsigned long modem = lpuart32_read(&sport->port, UARTMODIR)
14861486
& ~(UARTMODIR_TXRTSPOL | UARTMODIR_TXRTSE);
1487+
u32 ctrl;
1488+
1489+
/* TXRTSE and TXRTSPOL only can be changed when transmitter is disabled. */
1490+
ctrl = lpuart32_read(&sport->port, UARTCTRL);
1491+
if (ctrl & UARTCTRL_TE) {
1492+
/* wait for the transmit engine to complete */
1493+
lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC);
1494+
lpuart32_write(&sport->port, ctrl & ~UARTCTRL_TE, UARTCTRL);
1495+
1496+
while (lpuart32_read(&sport->port, UARTCTRL) & UARTCTRL_TE)
1497+
cpu_relax();
1498+
}
1499+
14871500
lpuart32_write(&sport->port, modem, UARTMODIR);
14881501

14891502
if (rs485->flags & SER_RS485_ENABLED) {
@@ -1503,6 +1516,10 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio
15031516
}
15041517

15051518
lpuart32_write(&sport->port, modem, UARTMODIR);
1519+
1520+
if (ctrl & UARTCTRL_TE)
1521+
lpuart32_write(&sport->port, ctrl, UARTCTRL);
1522+
15061523
return 0;
15071524
}
15081525

0 commit comments

Comments
 (0)