Skip to content

Commit 53a005d

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 <[email protected]> Signed-off-by: Sherry Sun <[email protected]> Reviewed-by: Frank Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 27bd86d commit 53a005d

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
@@ -1483,6 +1483,19 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio
14831483

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

14881501
if (rs485->flags & SER_RS485_ENABLED) {
@@ -1502,6 +1515,10 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio
15021515
}
15031516

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

0 commit comments

Comments
 (0)