From e4b2ee8a8837d2ba1c8ab2f108c7d1226d865d4d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Jul 2021 10:17:21 +0800 Subject: [PATCH] serial: 8250_port: reset LSR DLAB before set MCR When setting the 16550 serial port baud rate, you need to configure the UART to loopback mode. After setting the DLL and DLH, you need to reset the LSR first, and then configure the MCR to make the UART return to the normal mode. If you do not reset the LSR first, an error will occur when the UART RX is still receiving data. Signed-off-by: Steven Liu Change-Id: Ia940b278554ef1d4e7a6c4550fe4a4600407a57e --- drivers/tty/serial/8250/8250_port.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 1d79bf098ce0..b05183c432d7 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -2681,6 +2681,8 @@ void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud, serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB); serial_dl_write(up, quot); + if (port->type != PORT_16750) + serial_port_out(port, UART_LCR, up->lcr); /* reset DLAB */ #ifdef CONFIG_ARCH_ROCKCHIP serial_port_out(port, UART_MCR, up->mcr); @@ -2852,10 +2854,11 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR * is written without DLAB set, this mode will be disabled. */ - if (port->type == PORT_16750) + if (port->type == PORT_16750) { serial_port_out(port, UART_FCR, up->fcr); + serial_port_out(port, UART_LCR, up->lcr); /* reset DLAB */ + } - serial_port_out(port, UART_LCR, up->lcr); /* reset DLAB */ if (port->type != PORT_16750) { /* emulated UARTs (Lucent Venus 167x) need two steps */ if (up->fcr & UART_FCR_ENABLE_FIFO)