Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial-uartlite: add earlycon support

Microblaze currently uses the old earlyprintk system, rather than the
unified earlycon support, to show boot messages on uartlite. Add
earlycon support so that other archs using uartlite can benefit from
it. The new code in uartlite.c is copied almost verbatim from
arch/microblaze/kernel/early_printk.c.

Signed-off-by: Rich Felker <dalias@libc.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rich Felker and committed by
Greg Kroah-Hartman
7cdcc29e cafe1ac6

+42
+1
drivers/tty/serial/Kconfig
··· 610 610 bool "Support for console on Xilinx uartlite serial port" 611 611 depends on SERIAL_UARTLITE=y 612 612 select SERIAL_CORE_CONSOLE 613 + select SERIAL_EARLYCON 613 614 help 614 615 Say Y here if you wish to use a Xilinx uartlite as the system 615 616 console (the system console is the device which receives all kernel
+41
drivers/tty/serial/uartlite.c
··· 519 519 520 520 console_initcall(ulite_console_init); 521 521 522 + static void early_uartlite_putc(struct uart_port *port, int c) 523 + { 524 + /* 525 + * Limit how many times we'll spin waiting for TX FIFO status. 526 + * This will prevent lockups if the base address is incorrectly 527 + * set, or any other issue on the UARTLITE. 528 + * This limit is pretty arbitrary, unless we are at about 10 baud 529 + * we'll never timeout on a working UART. 530 + */ 531 + 532 + unsigned retries = 1000000; 533 + /* read status bit - 0x8 offset */ 534 + while (--retries && (readl(port->membase + 8) & (1 << 3))) 535 + ; 536 + 537 + /* Only attempt the iowrite if we didn't timeout */ 538 + /* write to TX_FIFO - 0x4 offset */ 539 + if (retries) 540 + writel(c & 0xff, port->membase + 4); 541 + } 542 + 543 + static void early_uartlite_write(struct console *console, 544 + const char *s, unsigned n) 545 + { 546 + struct earlycon_device *device = console->data; 547 + uart_console_write(&device->port, s, n, early_uartlite_putc); 548 + } 549 + 550 + static int __init early_uartlite_setup(struct earlycon_device *device, 551 + const char *options) 552 + { 553 + if (!device->port.membase) 554 + return -ENODEV; 555 + 556 + device->con->write = early_uartlite_write; 557 + return 0; 558 + } 559 + EARLYCON_DECLARE(uartlite, early_uartlite_setup); 560 + OF_EARLYCON_DECLARE(uartlite_b, "xlnx,opb-uartlite-1.00.b", early_uartlite_setup); 561 + OF_EARLYCON_DECLARE(uartlite_a, "xlnx,xps-uartlite-1.00.a", early_uartlite_setup); 562 + 522 563 #endif /* CONFIG_SERIAL_UARTLITE_CONSOLE */ 523 564 524 565 static struct uart_driver ulite_uart_driver = {