Skip to content

Commit 4d9d7d8

Browse files
tklausergregkh
authored andcommitted
serial: altera_uart: add earlycon support
Nios2 currently uses its own early printk implementation, rather than using unified earlycon support to show boot messages on altera_uart. Add earlycon support to altera_uart so that other archs may use it. Also, this (together with the corresponding patch for altera_jtaguart) will allow the early printk implementation in arch/nios2 to be removed in a future patch. Cc: Ley Foon Tan <lftan@altera.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a4199f5 commit 4d9d7d8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

drivers/tty/serial/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,7 @@ config SERIAL_ALTERA_UART_CONSOLE
13921392
bool "Altera UART console support"
13931393
depends on SERIAL_ALTERA_UART=y
13941394
select SERIAL_CORE_CONSOLE
1395+
select SERIAL_EARLYCON
13951396
help
13961397
Enable a Altera UART port to be the system console.
13971398

drivers/tty/serial/altera_uart.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,38 @@ console_initcall(altera_uart_console_init);
489489

490490
#define ALTERA_UART_CONSOLE (&altera_uart_console)
491491

492+
static void altera_uart_earlycon_write(struct console *co, const char *s,
493+
unsigned int count)
494+
{
495+
struct earlycon_device *dev = co->data;
496+
497+
uart_console_write(&dev->port, s, count, altera_uart_console_putc);
498+
}
499+
500+
static int __init altera_uart_earlycon_setup(struct earlycon_device *dev,
501+
const char *options)
502+
{
503+
struct uart_port *port = &dev->port;
504+
505+
if (!port->membase)
506+
return -ENODEV;
507+
508+
/* Enable RX interrupts now */
509+
writel(ALTERA_UART_CONTROL_RRDY_MSK,
510+
port->membase + ALTERA_UART_CONTROL_REG);
511+
512+
if (dev->baud) {
513+
unsigned int baudclk = port->uartclk / dev->baud;
514+
515+
writel(baudclk, port->membase + ALTERA_UART_DIVISOR_REG);
516+
}
517+
518+
dev->con->write = altera_uart_earlycon_write;
519+
return 0;
520+
}
521+
522+
OF_EARLYCON_DECLARE(uart, "altr,uart-1.0", altera_uart_earlycon_setup);
523+
492524
#else
493525

494526
#define ALTERA_UART_CONSOLE NULL

0 commit comments

Comments
 (0)