summaryrefslogtreecommitdiff
path: root/drivers/tty/serial/imx.c
diff options
context:
space:
mode:
authorDavid Jander <david@protonic.nl>2015-07-02 14:29:49 (GMT)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-07-24 00:39:08 (GMT)
commite95044ba4fee93f5ea8a1a24b2d921e148503833 (patch)
treef48a150eab7daf572b36ac9e41be73b38ef298a3 /drivers/tty/serial/imx.c
parente9b5a9825f6b02a9cf86697bcffafd3d7898f9f6 (diff)
downloadlinux-e95044ba4fee93f5ea8a1a24b2d921e148503833.tar.xz
tty: serial: imx.c: Reset UART before activating interrupts
If the UART has been in use before this driver was loaded, IRQs might be active and get fired as soon as we set the handler, which will crash in the spin_lock_irqsave(&sport->port.lock, flags) because port.lock is not initialized until the port is added at the end of probe. Signed-off-by: David Jander <david@protonic.nl> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/serial/imx.c')
-rw-r--r--drivers/tty/serial/imx.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 5b44d53..83b02d4 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -1098,10 +1098,23 @@ static void imx_disable_dma(struct imx_port *sport)
/* half the RX buffer size */
#define CTSTL 16
+static inline void imx_reset(struct imx_port *sport)
+{
+ int i = 100;
+ unsigned long temp;
+
+ temp = readl(sport->port.membase + UCR2);
+ temp &= ~UCR2_SRST;
+ writel(temp, sport->port.membase + UCR2);
+
+ while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) && (--i > 0))
+ udelay(1);
+}
+
static int imx_startup(struct uart_port *port)
{
struct imx_port *sport = (struct imx_port *)port;
- int retval, i;
+ int retval;
unsigned long flags, temp;
retval = clk_prepare_enable(sport->clk_per);
@@ -1133,14 +1146,7 @@ static int imx_startup(struct uart_port *port)
spin_lock_irqsave(&sport->port.lock, flags);
/* Reset fifo's and state machines */
- i = 100;
-
- temp = readl(sport->port.membase + UCR2);
- temp &= ~UCR2_SRST;
- writel(temp, sport->port.membase + UCR2);
-
- while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) && (--i > 0))
- udelay(1);
+ imx_reset(sport);
/*
* Finally, clear and enable interrupts
@@ -1976,6 +1982,14 @@ static int serial_imx_probe(struct platform_device *pdev)
clk_disable_unprepare(sport->clk_ipg);
/*
+ * Perform a complete reset of the UART device. Needed if we don't
+ * come straight out of reset.
+ */
+ writel(0, sport->port.membase + UCR2);
+ writel(0, sport->port.membase + UCR1);
+ imx_reset(sport);
+
+ /*
* Allocate the IRQ(s) i.MX1 has three interrupts whereas later
* chips only have one interrupt.
*/