serial: liteuart: Add support for earlycon
authorStafford Horne <shorne@gmail.com>
Mon, 17 May 2021 11:54:52 +0000 (20:54 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 20 May 2021 14:35:01 +0000 (16:35 +0200)
Most litex boards using RISC-V soft cores us the sbi earlycon, however
this is not available for non RISC-V litex SoC's.  This patch enables
earlycon for liteuart which is available on all Litex SoC's making
support for earycon debugging more widely available.

Cc: Florent Kermarrec <florent@enjoy-digital.fr>
Cc: Mateusz Holenko <mholenko@antmicro.com>
Cc: Joel Stanley <joel@jms.id.au>
Cc: Gabriel L. Somlo <gsomlo@gmail.com>
Reviewed-and-tested-by: Gabriel Somlo <gsomlo@gmail.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Stafford Horne <shorne@gmail.com>
Link: https://lore.kernel.org/r/20210517115453.24365-1-shorne@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/admin-guide/kernel-parameters.txt
drivers/tty/serial/Kconfig
drivers/tty/serial/liteuart.c

index cb89dbdedc46381114cf94594d0fff68bf86e0a4..17bdf5df404c033c8679096ea87eec95c16897cb 100644 (file)
                        the driver will use only 32-bit accessors to read/write
                        the device registers.
 
+               liteuart,<addr>
+                       Start an early console on a litex serial port at the
+                       specified address. The serial port must already be
+                       setup and configured. Options are not yet supported.
+
                meson,<addr>
                        Start an early, polled-mode console on a meson serial
                        port at the specified address. The serial port must
index 682f9171c82cdf006641a922c2446190e68e733d..24282ad99d85029cb48a5a54c3c8ed079f760057 100644 (file)
@@ -1553,6 +1553,7 @@ config SERIAL_LITEUART_CONSOLE
        bool "LiteUART serial port console support"
        depends on SERIAL_LITEUART=y
        select SERIAL_CORE_CONSOLE
+       select SERIAL_EARLYCON
        help
          Say 'Y' or 'M' here if you wish to use the FPGA-based LiteUART serial
          controller from LiteX SoC builder as the system console
index 0b06770642cb3d0719b7d9e337f781441bef159a..dbc0559a9157546c6377a433a7071d0b0dd74251 100644 (file)
@@ -370,6 +370,27 @@ static int __init liteuart_console_init(void)
        return 0;
 }
 console_initcall(liteuart_console_init);
+
+static void early_liteuart_write(struct console *console, const char *s,
+                                   unsigned int count)
+{
+       struct earlycon_device *device = console->data;
+       struct uart_port *port = &device->port;
+
+       uart_console_write(port, s, count, liteuart_putchar);
+}
+
+static int __init early_liteuart_setup(struct earlycon_device *device,
+                                      const char *options)
+{
+       if (!device->port.membase)
+               return -ENODEV;
+
+       device->con->write = early_liteuart_write;
+       return 0;
+}
+
+OF_EARLYCON_DECLARE(liteuart, "litex,liteuart", early_liteuart_setup);
 #endif /* CONFIG_SERIAL_LITEUART_CONSOLE */
 
 static int __init liteuart_init(void)