tty: serial: atmel: add earlycon support
authorMichael Walle <michael@walle.cc>
Thu, 17 Feb 2022 09:46:20 +0000 (10:46 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Feb 2022 18:47:42 +0000 (19:47 +0100)
Add early console support which relies on the bootloader for the
initialization of the UART.
Please note, that the compatibles are taken from at91-usart MFD
driver.

Tested-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Acked-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20220217094620.1148571-1-michael@walle.cc
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/Kconfig
drivers/tty/serial/atmel_serial.c

index 0e5ccb25bdb178fc3d1276fcf15f6b6783e07ff3..407a98ec0791af96cf5a0c493646375a806deae4 100644 (file)
@@ -139,6 +139,7 @@ config SERIAL_ATMEL_CONSOLE
        bool "Support for console on AT91 serial port"
        depends on SERIAL_ATMEL=y
        select SERIAL_CORE_CONSOLE
+       select SERIAL_EARLYCON
        help
          Say Y here if you wish to use an on-chip UART on a Atmel
          AT91 processor as the system console (the system
index 2d09a89974a225ee2bcaf7f1fd37dc4ebcb85e16..73d43919898d4a0c663ba3b87e9d01cf712f5d8d 100644 (file)
@@ -2673,6 +2673,30 @@ static struct console atmel_console = {
        .data           = &atmel_uart,
 };
 
+static void atmel_serial_early_write(struct console *con, const char *s,
+                                    unsigned int n)
+{
+       struct earlycon_device *dev = con->data;
+
+       uart_console_write(&dev->port, s, n, atmel_console_putchar);
+}
+
+static int __init atmel_early_console_setup(struct earlycon_device *device,
+                                           const char *options)
+{
+       if (!device->port.membase)
+               return -ENODEV;
+
+       device->con->write = atmel_serial_early_write;
+
+       return 0;
+}
+
+OF_EARLYCON_DECLARE(atmel_serial, "atmel,at91rm9200-usart",
+                   atmel_early_console_setup);
+OF_EARLYCON_DECLARE(atmel_serial, "atmel,at91sam9260-usart",
+                   atmel_early_console_setup);
+
 #define ATMEL_CONSOLE_DEVICE   (&atmel_console)
 
 #else