serial: imx: add earlycon support
authorLucas Stach <l.stach@pengutronix.de>
Fri, 28 Aug 2015 09:56:19 +0000 (11:56 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 4 Oct 2015 16:49:27 +0000 (17:49 +0100)
Earlycon allows to have an early debugging console that doesn't need
to be statically configured in the kernel config, like earlyprintk,
but is set up through the stdout-path DT property.

This allows to have the early debugging always built into the
kernel and enabled on demand without clashing between different boards
or architectures.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/Kconfig
drivers/tty/serial/imx.c

index f57bb907dc541e57ab8606f40c9351c32d87d7f3..9e2cc51d205a75d8c27b5127187a4eb9a3bbbc0e 100644 (file)
@@ -582,6 +582,7 @@ config SERIAL_IMX_CONSOLE
        bool "Console on IMX serial port"
        depends on SERIAL_IMX=y
        select SERIAL_CORE_CONSOLE
+       select SERIAL_EARLYCON if OF
        help
          If you have enabled the serial port on the Freescale IMX
          CPU you can make it the console by answering Y to this option.
index fe3d41cc841632134fd907b1fb7af08f0e9d6e81..52629ca80437ccb584574a7ad7b3f3d6f1219b3f 100644 (file)
@@ -1795,6 +1795,38 @@ static struct console imx_console = {
 };
 
 #define IMX_CONSOLE    &imx_console
+
+#ifdef CONFIG_OF
+static void imx_console_early_putchar(struct uart_port *port, int ch)
+{
+       while (readl_relaxed(port->membase + IMX21_UTS) & UTS_TXFULL)
+               cpu_relax();
+
+       writel_relaxed(ch, port->membase + URTX0);
+}
+
+static void imx_console_early_write(struct console *con, const char *s,
+                                   unsigned count)
+{
+       struct earlycon_device *dev = con->data;
+
+       uart_console_write(&dev->port, s, count, imx_console_early_putchar);
+}
+
+static int __init
+imx_console_early_setup(struct earlycon_device *dev, const char *opt)
+{
+       if (!dev->port.membase)
+               return -ENODEV;
+
+       dev->con->write = imx_console_early_write;
+
+       return 0;
+}
+OF_EARLYCON_DECLARE(ec_imx6q, "fsl,imx6q-uart", imx_console_early_setup);
+OF_EARLYCON_DECLARE(ec_imx21, "fsl,imx21-uart", imx_console_early_setup);
+#endif
+
 #else
 #define IMX_CONSOLE    NULL
 #endif