serial: mps2-uart: add support for early console
authorVladimir Murzin <vladimir.murzin@arm.com>
Mon, 25 Apr 2016 08:47:48 +0000 (09:47 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Apr 2016 16:26:55 +0000 (09:26 -0700)
This adds support early console for MPS2 UART which can be enabled via
earlycon=mps2,0x40004000

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/Kconfig
drivers/tty/serial/mps2-uart.c

index 3b0a9b3ec4e1950f15ab523b218a7f3e02ffc617..331638db64661e0dfbf09006c70830bf90c8694e 100644 (file)
@@ -1452,6 +1452,7 @@ config SERIAL_MPS2_UART_CONSOLE
        bool "MPS2 UART console support"
        depends on SERIAL_MPS2_UART
        select SERIAL_CORE_CONSOLE
+       select SERIAL_EARLYCON
 
 config SERIAL_MPS2_UART
        bool "MPS2 UART port"
index e571e4cdfab39c9bda25c1de3a4e544019530754..da9e27d3c2639dbe26d1cbd5566053d4bcd72d55 100644 (file)
@@ -450,6 +450,34 @@ static struct console mps2_uart_console = {
 
 #define MPS2_SERIAL_CONSOLE (&mps2_uart_console)
 
+static void mps2_early_putchar(struct uart_port *port, int ch)
+{
+       while (readb(port->membase + UARTn_STATE) & UARTn_STATE_TX_FULL)
+               cpu_relax();
+
+       writeb((unsigned char)ch, port->membase + UARTn_DATA);
+}
+
+static void mps2_early_write(struct console *con, const char *s, unsigned int n)
+{
+       struct earlycon_device *dev = con->data;
+
+       uart_console_write(&dev->port, s, n, mps2_early_putchar);
+}
+
+static int __init mps2_early_console_setup(struct earlycon_device *device,
+                                          const char *opt)
+{
+       if (!device->port.membase)
+               return -ENODEV;
+
+       device->con->write = mps2_early_write;
+
+       return 0;
+}
+
+OF_EARLYCON_DECLARE(mps2, "arm,mps2-uart", mps2_early_console_setup);
+
 #else
 #define MPS2_SERIAL_CONSOLE NULL
 #endif