Skip to contentSkip to conversation

serial: liteuart: Add support for earlycon

PATCH In review Stafford Horne 3 participants 4 messages May 17, 2021 – May 18, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 serial: liteuart: Add support for earlycon

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 <[email protected]>
Cc Mateusz Holenko <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Gabriel L. Somlo <[email protected]>
Reviewed-and-tested-by Gabriel Somlo <[email protected]>

---
Changes since v1:
- Fixed subject
- Fixed ifdef and config issues pointed out by Jiri
- Use liteuart_putchar instead of early_liteuart_putc

 .../admin-guide/kernel-parameters.txt         |  5 +++++
 drivers/tty/serial/Kconfig                    |  1 +
 drivers/tty/serial/liteuart.c                 | 21 +++++++++++++++++++
 3 files changed, 27 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +5 -0
index 04545725f187..2d4a43af8de2 100644
@@ -1084,6 +1084,11 @@
 			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
drivers/tty/serial/Kconfig +1 -0
index 0c4cd4a348f4..af41e534483c 100644
@@ -1550,6 +1550,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
drivers/tty/serial/liteuart.c +21 -0
index 64842f3539e1..1b75a4bf7c56 100644
@@ -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)
Signature · 1 line
2.31.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Stafford Horne

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 <[email protected]>
Cc Mateusz Holenko <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Gabriel L. Somlo <[email protected]>
Reviewed-and-tested-by Gabriel Somlo <[email protected]>
Quoted 62 lines

---
Changes since v1:
- Fixed subject
- Fixed ifdef and config issues pointed out by Jiri
- Use liteuart_putchar instead of early_liteuart_putc

  .../admin-guide/kernel-parameters.txt         |  5 +++++
  drivers/tty/serial/Kconfig                    |  1 +
  drivers/tty/serial/liteuart.c                 | 21 +++++++++++++++++++
  3 files changed, 27 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +5 -0
index 04545725f187..2d4a43af8de2 100644
@@ -1084,6 +1084,11 @@
  			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
drivers/tty/serial/Kconfig +1 -0
index 0c4cd4a348f4..af41e534483c 100644
@@ -1550,6 +1550,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
drivers/tty/serial/liteuart.c +14 -0
index 64842f3539e1..1b75a4bf7c56 100644
@@ -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)

drivers/tty/serial/liteuart.c static int __init liteuart_console_init(void) · line 396

Quoted 10 lines
drivers/tty/serial/liteuart.c +7 -0
+		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)

thanks,

Signature · 2 lines
js
suse labs
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Stafford Horne
Quoted 6 lines · Stafford Horne

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.

Quoted 6 lines
Cc Florent Kermarrec <[email protected]>
Cc Mateusz Holenko <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Gabriel L. Somlo <[email protected]>
Reviewed-and-tested-by Gabriel Somlo <[email protected]>

Cheers,

Joel

#3 lore raw
Quoted 7 lines · Joel Stanley
Quoted 6 lines · Stafford Horne

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.

Quoted 8 lines
Quoted 6 lines
Cc Florent Kermarrec <[email protected]>
Cc Mateusz Holenko <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Gabriel L. Somlo <[email protected]>
Reviewed-and-tested-by Gabriel Somlo <[email protected]>

Thanks for reviewing.

-Stafford