[PATCH 2/3] serial: pl011: handle corruption at high clock speeds

Linus Walleij linus.walleij at stericsson.com
Thu Sep 20 05:46:00 EDT 2012


From: Linus Walleij <linus.walleij at linaro.org>

This works around a few glitches in the ST version of the PL011
serial driver when using very high baud rates, as we do in the
Ux500: 3, 3.25, 4 and 4.05 Mbps are used in our platform.

Problem Observed/rootcause:

In case of high baud-rates, where the baud-rate*8 is getting close to
the provided clock frequency (so a division factor close to 1) when
using bursts of characters (so they are abutted), then it seems as if
there is not enough time to detect the beginning of the start-bit which
is a timing reference for the entire character, and thus the sampling
moment of character bits is moving towards the end of each bit, instead
of the middle.

Fix:
Increase slightly the RX baud rate of the UART above the theoretical
baudrate by 5%. This will definitely give more margin time to the
UART_RX to sample correctly the data at the middle of the bit period.

Cc: Bibek Basu <bibek.basu at stericsson.com>
Cc: Par-Gunnar Hjalmdahl <par-gunnar.hjalmdahl at stericsson.com>
Signed-off-by: Guillaume Jaunet <guillaume.jaunet at stericsson.com>
Signed-off-by: Christophe Arnal <christophe.arnal at stericsson.com>
Signed-off-by: Matthias Locher <matthias.locher at stericsson.com>
Signed-off-by: Rajanikanth H.V <rajanikanth.hv at stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij at linaro.org>
---
 drivers/tty/serial/amba-pl011.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 9e16ea6..32240a7 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -1601,13 +1601,26 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios,
 			old_cr &= ~ST_UART011_CR_OVSFACT;
 	}
 
+	/*
+	 * Workaround for the ST Micro oversampling variants to
+	 * increase the bitrate slightly, by lowering the divisor,
+	 * to avoid delayed sampling of start bit at high speeds,
+	 * else we see data corruption.
+	 */
+	if (uap->vendor->oversampling) {
+		if (baud > 3000000 && baud < 3250000 && quot > 1)
+			quot -= 1;
+		else if (baud > 3250000 && quot > 2)
+			quot -= 2;
+	}
 	/* Set baud rate */
 	writew(quot & 0x3f, port->membase + UART011_FBRD);
 	writew(quot >> 6, port->membase + UART011_IBRD);
 
 	/*
 	 * ----------v----------v----------v----------v-----
-	 * NOTE: MUST BE WRITTEN AFTER UARTLCR_M & UARTLCR_L
+	 * NOTE: lcrh_tx and lcrh_rx MUST BE WRITTEN AFTER
+	 * UARTLCR_M(IBRD)  & UARTLCR_L(FBRD).
 	 * ----------^----------^----------^----------^-----
 	 */
 	writew(lcr_h, port->membase + uap->lcrh_rx);
-- 
1.7.11.3




More information about the linux-arm-kernel mailing list