All of lore.kernel.org
 help / color / mirror / Atom feed
From: "René Bürgel" <r.buergel@unicontrol.de>
To: Wolfram Sang <w.sang@pengutronix.de>, linuxppc-dev@ozlabs.org
Subject: Re: [PATCH V3] workaround for mpc52xx erratum #364 (serial may not be reset in break state)
Date: Tue, 04 Nov 2008 20:40:09 +0100	[thread overview]
Message-ID: <4910A519.3030701@unicontrol.de> (raw)
In-Reply-To: <20081104111545.GB17864@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 936 bytes --]

Hey, folks

This is v3 of my patch to work around erratum #364 of the MPC5200(B). I 
removed most "magic" looking numbers, documenting the rest. As mentioned 
before, the previous patches weren't working for low baudrates (<9600). 
This should be fixed now.

But there's still one thing, that bothers me a bit - if there is REALLY 
a break on the line, closing the driver may take until it's gone. I 
don't know whether this is really satisfying, but i think it's better 
than the alternative: no serial connection until the next reboot.

-- 
René Bürgel
Software Engineer
Unicontrol Systemtechnik GmbH
OT Dittersbach
Sachsenburger Weg 34
09669 Frankenberg
 
Tel.: 03 72 06/ 88 73 - 19
Fax: 03 72 06/ 88 73 - 60
E-Mail: r.buergel@unicontrol.de
Internet: www.unicontrol.de
 
Unicontrol Systemtechnik GmbH
Geschäftsführer: Dipl.-Ing. Siegfried Heinze
Sitz der Gesellschaft: Frankenberg
Registergericht: Amtsgericht Chemnitz, HRB 15 475



[-- Attachment #2: 130-mpc52xx_erratum_364.patch --]
[-- Type: text/plain, Size: 3916 bytes --]

diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 6117d3d..a2bb4d9 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -496,6 +496,59 @@ mpc52xx_uart_break_ctl(struct uart_port *port, int ctl)
 	spin_unlock_irqrestore(&port->lock, flags);
 }
 
+/*
+ * This is a workaround for processor bug #364 described in MPC5200 (L25R) Errata.
+ * The bug is still present in MPC5200B, but currently not listed in its errata sheet
+ *
+ * The workaround resets the baudrate to the slowest possible,
+ * waits for a stable state and resets break state repeatedly if necessary.
+ * Optionally it can release the lock while waiting.
+ *
+ * That baudrate is roughly port->uartclk / (1000 * 1000)
+ * The minimum wait time for the first try has to include the time to wait for stop-bits and a character,
+ * we wait for 2 chars to be sure
+ * Consecutive waits must just receive one character.
+ */
+
+static void mpc52xx_uart_reset_rx(struct uart_port *port, bool unlock, unsigned long flags)
+{
+#ifdef CONFIG_PPC_MPC52xx
+	void reset_errors_and_wait(struct uart_port *port, bool unlock, unsigned long flags, unsigned int delay)
+	{
+		struct mpc52xx_psc __iomem *psc = PSC(port);
+		out_8(&psc->command,MPC52xx_PSC_RST_ERR_STAT);
+		if (unlock) {
+			disable_irq(port->irq);
+			spin_unlock_irqrestore(&port->lock, flags);
+		}
+		mdelay( delay );
+		if (unlock) {
+			spin_lock_irqsave(&port->lock, flags);
+			enable_irq(port->irq);
+		}
+	}
+
+
+	struct mpc52xx_psc __iomem *psc = PSC(port);
+
+	// One character on the serial port may consist of up to 12 bits.
+	// So the time to receive one char is 12 /*bits*/ / (port->uartclk / (1000 * 1000) /*MHz -> Hz*/) * 1000 /*s -> ms*/,
+	// but we'll wait 50% longer just to make sure
+	unsigned int one_char_receive_duration = (12 * 1000) / (port->uartclk / (1000 * 1000) );
+
+	/* CT=0xFFFF sets the serial line to the minimal possible baudrate depending on the uartclk. */
+	out_8(&psc->ctur, 0xFF);
+	out_8(&psc->ctlr, 0xFF);
+
+	reset_errors_and_wait( port, unlock, flags, one_char_receive_duration * 2 );
+
+	while ((in_be16(&psc->mpc52xx_psc_status)) & MPC52xx_PSC_SR_RB) {
+		reset_errors_and_wait( port, unlock, flags, one_char_receive_duration );
+	}
+#endif
+	out_8(&psc->command,MPC52xx_PSC_RST_RX);
+}
+
 static int
 mpc52xx_uart_startup(struct uart_port *port)
 {
@@ -510,7 +563,7 @@ mpc52xx_uart_startup(struct uart_port *port)
 		return ret;
 
 	/* Reset/activate the port, clear and enable interrupts */
-	out_8(&psc->command, MPC52xx_PSC_RST_RX);
+	mpc52xx_uart_reset_rx(port, false, 0);
 	out_8(&psc->command, MPC52xx_PSC_RST_TX);
 
 	out_be32(&psc->sicr, 0);	/* UART mode DCD ignored */
@@ -529,7 +582,7 @@ mpc52xx_uart_shutdown(struct uart_port *port)
 	struct mpc52xx_psc __iomem *psc = PSC(port);
 
 	/* Shut down the port.  Leave TX active if on a console port */
-	out_8(&psc->command, MPC52xx_PSC_RST_RX);
+	mpc52xx_uart_reset_rx(port, false, 0);
 	if (!uart_console(port))
 		out_8(&psc->command, MPC52xx_PSC_RST_TX);
 
@@ -588,9 +641,6 @@ mpc52xx_uart_set_termios(struct uart_port *port, struct ktermios *new,
 	/* Get the lock */
 	spin_lock_irqsave(&port->lock, flags);
 
-	/* Update the per-port timeout */
-	uart_update_timeout(port, new->c_cflag, baud);
-
 	/* Do our best to flush TX & RX, so we don't loose anything */
 	/* But we don't wait indefinitly ! */
 	j = 5000000;	/* Maximum wait */
@@ -607,9 +657,12 @@ mpc52xx_uart_set_termios(struct uart_port *port, struct ktermios *new,
 			"Some chars may have been lost.\n");
 
 	/* Reset the TX & RX */
-	out_8(&psc->command, MPC52xx_PSC_RST_RX);
+	mpc52xx_uart_reset_rx(port, true, flags);
 	out_8(&psc->command, MPC52xx_PSC_RST_TX);
 
+	/* Update the per-port timeout */
+	uart_update_timeout(port, new->c_cflag, baud);
+
 	/* Send new mode settings */
 	out_8(&psc->command, MPC52xx_PSC_SEL_MODE_REG_1);
 	out_8(&psc->mode, mr1);

  parent reply	other threads:[~2008-11-04 19:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-03 19:32 [PATCH] workaround for mpc52xx erratum #364 (serial may not be reset in break state) René Bürgel
2008-11-03 20:55 ` Grant Likely
2008-11-03 21:57   ` Matt Sealey
2008-11-03 22:15     ` Wolfram Sang
2008-11-03 22:55       ` Grant Likely
2008-11-04 18:18       ` Matt Sealey
2008-11-04 10:43   ` [PATCH V2] " René Bürgel
2008-11-04 11:15     ` Wolfram Sang
2008-11-04 14:13       ` René Bürgel
2008-11-04 19:40       ` René Bürgel [this message]
2008-11-04 21:21         ` [PATCH V3] " Wolfram Sang
2008-11-06  8:11           ` [PATCH V4] " René Bürgel
2008-11-06  8:11             ` René Bürgel
2008-11-14 19:09             ` Grant Likely
2008-11-14 19:09               ` Grant Likely
2008-11-04 18:23     ` [PATCH V2] " Matt Sealey
2008-11-06 17:01       ` René Bürgel
2008-11-06 22:41         ` Matt Sealey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4910A519.3030701@unicontrol.de \
    --to=r.buergel@unicontrol.de \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=w.sang@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.