serial: change the divisor latch only when prescalar actually changed
authorYin Kangkai <kangkai.yin@linux.intel.com>
Wed, 9 Feb 2011 03:35:18 +0000 (11:35 +0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 17 Feb 2011 19:23:50 +0000 (11:23 -0800)
In 8250.c original ns16550 autoconfig code, we change the divisor latch when
we goto to high speed mode, we're assuming the previous speed is legacy. This
some times is not true.

For example in a system with both CONFIG_SERIAL_8250 and
CONFIG_SERIAL_8250_PNP set, in this case, the code (autoconfig) will be called
twice, one in serial8250_init/probe() and the other is from
serial_pnp_probe. When serial_pnp_probe calls the autoconfig for NS16550A,
it's already in high speed mode, change the divisor latch (quot << 3) in this
case will make the UART console garbled.

CC: Greg Kroah-Hartman <greg@kroah.com>
CC: David Woodhouse <dwmw2@infradead.org>
CC: linux-kernel@vger.kernel.org
CC: stable@kernel.org
Signed-off-by: Yin Kangkai <kangkai.yin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/tty/serial/8250.c

index c10a6a909c7641658aee66f0355f4fe309997e88..b3b881bc4712f47983c84ac2069a6f5c0b07b55e 100644 (file)
@@ -954,6 +954,23 @@ static int broken_efr(struct uart_8250_port *up)
        return 0;
 }
 
+static inline int ns16550a_goto_highspeed(struct uart_8250_port *up)
+{
+       unsigned char status;
+
+       status = serial_in(up, 0x04); /* EXCR2 */
+#define PRESL(x) ((x) & 0x30)
+       if (PRESL(status) == 0x10) {
+               /* already in high speed mode */
+               return 0;
+       } else {
+               status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
+               status |= 0x10;  /* 1.625 divisor for baud_base --> 921600 */
+               serial_outp(up, 0x04, status);
+       }
+       return 1;
+}
+
 /*
  * We know that the chip has FIFOs.  Does it have an EFR?  The
  * EFR is located in the same register position as the IIR and
@@ -1025,12 +1042,8 @@ static void autoconfig_16550a(struct uart_8250_port *up)
                        quot = serial_dl_read(up);
                        quot <<= 3;
 
-                       status1 = serial_in(up, 0x04); /* EXCR2 */
-                       status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
-                       status1 |= 0x10;  /* 1.625 divisor for baud_base --> 921600 */
-                       serial_outp(up, 0x04, status1);
-
-                       serial_dl_write(up, quot);
+                       if (ns16550a_goto_highspeed(up))
+                               serial_dl_write(up, quot);
 
                        serial_outp(up, UART_LCR, 0);
 
@@ -3025,15 +3038,10 @@ void serial8250_resume_port(int line)
        struct uart_8250_port *up = &serial8250_ports[line];
 
        if (up->capabilities & UART_NATSEMI) {
-               unsigned char tmp;
-
                /* Ensure it's still in high speed mode */
                serial_outp(up, UART_LCR, 0xE0);
 
-               tmp = serial_in(up, 0x04); /* EXCR2 */
-               tmp &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
-               tmp |= 0x10;  /* 1.625 divisor for baud_base --> 921600 */
-               serial_outp(up, 0x04, tmp);
+               ns16550a_goto_highspeed(up);
 
                serial_outp(up, UART_LCR, 0);
                up->port.uartclk = 921600*16;