Skip to contentSkip to conversation

Garbage on serial console after serial driver loads

DISCUSSION Phil Oester 5 participants 9 messages Mar 28, 2005 – May 3, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 6 lines · Russell King

Doesn't matter. The problem is that dwmw2's NS16550A patch (from ages ago) changes the prescaler setting for this device so we can use the higher speed baud rates. This means any programmed divisor (programmed at early serial console initialisation time) suddenly becomes wrong as soon as we fiddle with the prescaler during normal UART initialisation time.

Seems like you are correct, given the below patch fixes the garbage output for me.

Phil

drivers/serial/8250.c +1 -1
@@ -698,7 +698,7 @@
 		serial_outp(up, UART_MCR, status1);
 
 		if ((status2 ^ status1) & UART_MCR_LOOP) {
-#ifndef CONFIG_PPC
+#if 0
 			serial_outp(up, UART_LCR, 0xE0);
 			status1 = serial_in(up, 0x04); /* EXCR1 */
 			status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
#1 lore raw
Quoted 10 lines · Phil Oester
Quoted 6 lines · Russell King

Doesn't matter. The problem is that dwmw2's NS16550A patch (from ages ago) changes the prescaler setting for this device so we can use the higher speed baud rates. This means any programmed divisor (programmed at early serial console initialisation time) suddenly becomes wrong as soon as we fiddle with the prescaler during normal UART initialisation time.

Seems like you are correct, given the below patch fixes the garbage output for me.

David,

Is this patch ok for you?

drivers/serial/8250.c +1 -1
@@ -698,7 +698,7 @@
 		serial_outp(up, UART_MCR, status1);
 
 		if ((status2 ^ status1) & UART_MCR_LOOP) {
-#ifndef CONFIG_PPC
+#if 0
 			serial_outp(up, UART_LCR, 0xE0);
 			status1 = serial_in(up, 0x04); /* EXCR1 */
 			status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#2 lore raw
Quoted 7 lines
Quoted 3 lines

Seems like you are correct, given the below patch fixes the garbage output for me.

David,

Is this patch ok for you?

Just an aside, I've had this patch in my own internal tree for over a year I never thought it would be kernel acceptable... but I noticed this problem a long time ago and thought it was an issue with my internal hardware as I never saw it on a normal board...

Dave.

#3 lore raw
In reply to Russell King
Quoted 1 line · Russell King

Is this patch ok for you?

Not really; it's just a quick hack applied without any real consideration of the problem. If we're messing up the baud rate when we change the master clock, then just make it change the divisor accordingly at the same time. We don't seem to store the active parameters of the serial console anywhere useful; we can do it just by reading back the divisor and multiplying by eight though...

Tom, does this also mean you don't need the 'ifndef ppc'?

drivers/serial/8250.c renamed from drivers/serial/8250.c~ +13 -1
@@ -567,13 +567,25 @@ static void autoconfig_16550a(struct uar
 
 		if ((status2 ^ status1) & UART_MCR_LOOP) {
 #ifndef CONFIG_PPC
+			unsigned short quot;
+
 			serial_outp(up, UART_LCR, 0xE0);
 			status1 = serial_in(up, 0x04); /* EXCR1 */
 			status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
 			status1 |= 0x10;  /* 1.625 divisor for baud_base --> 921600 */
 			serial_outp(up, 0x04, status1);
-			serial_outp(up, UART_LCR, 0);
 			up->port.uartclk = 921600*16;
+			
+			/* Adjust the baud rate to match, in case we're
+			   already using the port */
+			quot = serial_inp(up, UART_DLM) << 8;
+			quot += serial_inp(up, UART_DLL);
+			quot <<= 3;
+			serial_outp(up, UART_DLL, quot & 0xff);
+			serial_outp(up, UART_DLM, quot >> 8);
+
+			serial_outp(up, UART_LCR, 0);
+
 #endif
 
 			up->port.type = PORT_NS16550A;
Signature · 1 line
dwmw2
#4 lore raw
Quoted 6 lines · David Woodhouse

Not really; it's just a quick hack applied without any real consideration of the problem. If we're messing up the baud rate when we change the master clock, then just make it change the divisor accordingly at the same time. We don't seem to store the active parameters of the serial console anywhere useful; we can do it just by reading back the divisor and multiplying by eight though...

FYI, just tested this patch, and it does solve the garbage problem for me.

Thanks,
Phil

#5 lore raw
In reply to David Woodhouse
Quoted 11 lines · David Woodhouse
Quoted 1 line · Russell King

Is this patch ok for you?

Not really; it's just a quick hack applied without any real consideration of the problem. If we're messing up the baud rate when we change the master clock, then just make it change the divisor accordingly at the same time. We don't seem to store the active parameters of the serial console anywhere useful; we can do it just by reading back the divisor and multiplying by eight though...

Tom, does this also mean you don't need the 'ifndef ppc'?

I don't recall the problem well enough right now, but I'll go toss this into a current git tree and let you know.

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#6 lore raw
Quoted 2 lines · Tom Rini

I don't recall the problem well enough right now, but I'll go toss this into a current git tree and let you know.

With what hardware are you testing? Was this really a NatSemi SuperIO chip, or was it a false positive in the detection?

Signature · 1 line
dwmw2
#7 lore raw
Quoted 6 lines · David Woodhouse
Quoted 2 lines · Tom Rini

I don't recall the problem well enough right now, but I'll go toss this into a current git tree and let you know.

With what hardware are you testing? Was this really a NatSemi SuperIO chip, or was it a false positive in the detection?

This was on, I believe, the Motorola Sandpoint, which really does have a NatSemi SuperIO.

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#8 lore raw
In reply to Tom Rini
Quoted 11 lines · Tom Rini
Quoted 10 lines · David Woodhouse
Quoted 1 line · Russell King

Is this patch ok for you?

Not really; it's just a quick hack applied without any real consideration of the problem. If we're messing up the baud rate when we change the master clock, then just make it change the divisor accordingly at the same time. We don't seem to store the active parameters of the serial console anywhere useful; we can do it just by reading back the divisor and multiplying by eight though...

Quoted 4 lines
Quoted 1 line

Tom, does this also mean you don't need the 'ifndef ppc'?

I don't recall the problem well enough right now, but I'll go toss this into a current git tree and let you know.

Dropping the 'ifndef ppc' is fine on my Motorola Sandpoint which I do believe exhibited the problem previously. I've cc'd Kumar Gala since I see on IRC that 85xx boards might also have had a problem here.

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/