On Fri, Mar 07, 2025 at 10:19:50AM +0800, Sherry Sun wrote: > 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: 67b01837861c ("tty: serial: lpuart: Add RS485 support for 32-bit uart flavour") > Signed-off-by: Sherry Sun <sherry.sun@xxxxxxx> Reviewed-by: Frank Li <Frank.Li@xxxxxxx> > --- > drivers/tty/serial/fsl_lpuart.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c > index 91d02c55c470..4dc2f3e2b8e0 100644 > --- a/drivers/tty/serial/fsl_lpuart.c > +++ b/drivers/tty/serial/fsl_lpuart.c > @@ -1484,6 +1484,16 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio > > unsigned long modem = lpuart32_read(&sport->port, UARTMODIR) > & ~(UARTMODIR_TXRTSPOL | UARTMODIR_TXRTSE); > + u32 ctrl; > + > + /* TXRTSE and TXRTSPOL only can be changed when transmitter is disabled. */ > + ctrl = lpuart32_read(&sport->port, UARTCTRL); > + if (ctrl & UARTCTRL_TE) { > + /* wait transmit engin complete */ > + lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC); > + lpuart32_write(&sport->port, ctrl & ~UARTCTRL_TE, UARTCTRL); > + } > + > lpuart32_write(&sport->port, modem, UARTMODIR); > > if (rs485->flags & SER_RS485_ENABLED) { > @@ -1503,6 +1513,10 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio > } > > lpuart32_write(&sport->port, modem, UARTMODIR); > + > + if (ctrl & UARTCTRL_TE) > + lpuart32_write(&sport->port, ctrl, UARTCTRL); > + > return 0; > } > > -- > 2.34.1 >