2017-11-06 17:11:51 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Early serial console for 8250/16550 devices
|
|
|
|
*
|
|
|
|
* (c) Copyright 2004 Hewlett-Packard Development Company, L.P.
|
|
|
|
* Bjorn Helgaas <bjorn.helgaas@hp.com>
|
|
|
|
*
|
|
|
|
* Based on the 8250.c serial driver, Copyright (C) 2001 Russell King,
|
|
|
|
* and on early_printk.c by Andi Kleen.
|
|
|
|
*
|
|
|
|
* This is for use before the serial driver has initialized, in
|
|
|
|
* particular, before the UARTs have been discovered and named.
|
|
|
|
* Instead of specifying the console device as, e.g., "ttyS0",
|
|
|
|
* we locate the device directly by its MMIO or I/O port address.
|
|
|
|
*
|
|
|
|
* The user can specify the device directly, e.g.,
|
serial: convert early_uart to earlycon for 8250
Beacuse SERIAL_PORT_DFNS is removed from include/asm-i386/serial.h and
include/asm-x86_64/serial.h. the serial8250_ports need to be probed late in
serial initializing stage. the console_init=>serial8250_console_init=>
register_console=>serial8250_console_setup will return -ENDEV, and console
ttyS0 can not be enabled at that time. need to wait till uart_add_one_port in
drivers/serial/serial_core.c to call register_console to get console ttyS0.
that is too late.
Make early_uart to use early_param, so uart console can be used earlier. Make
it to be bootconsole with CON_BOOT flag, so can use console handover feature.
and it will switch to corresponding normal serial console automatically.
new command line will be:
console=uart8250,io,0x3f8,9600n8
console=uart8250,mmio,0xff5e0000,115200n8
or
earlycon=uart8250,io,0x3f8,9600n8
earlycon=uart8250,mmio,0xff5e0000,115200n8
it will print in very early stage:
Early serial console at I/O port 0x3f8 (options '9600n8')
console [uart0] enabled
later for console it will print:
console handover: boot [uart0] -> real [ttyS0]
Signed-off-by: <yinghai.lu@sun.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 06:37:59 +00:00
|
|
|
* earlycon=uart8250,io,0x3f8,9600n8
|
|
|
|
* earlycon=uart8250,mmio,0xff5e0000,115200n8
|
2010-07-20 22:26:51 +00:00
|
|
|
* earlycon=uart8250,mmio32,0xff5e0000,115200n8
|
serial: convert early_uart to earlycon for 8250
Beacuse SERIAL_PORT_DFNS is removed from include/asm-i386/serial.h and
include/asm-x86_64/serial.h. the serial8250_ports need to be probed late in
serial initializing stage. the console_init=>serial8250_console_init=>
register_console=>serial8250_console_setup will return -ENDEV, and console
ttyS0 can not be enabled at that time. need to wait till uart_add_one_port in
drivers/serial/serial_core.c to call register_console to get console ttyS0.
that is too late.
Make early_uart to use early_param, so uart console can be used earlier. Make
it to be bootconsole with CON_BOOT flag, so can use console handover feature.
and it will switch to corresponding normal serial console automatically.
new command line will be:
console=uart8250,io,0x3f8,9600n8
console=uart8250,mmio,0xff5e0000,115200n8
or
earlycon=uart8250,io,0x3f8,9600n8
earlycon=uart8250,mmio,0xff5e0000,115200n8
it will print in very early stage:
Early serial console at I/O port 0x3f8 (options '9600n8')
console [uart0] enabled
later for console it will print:
console handover: boot [uart0] -> real [ttyS0]
Signed-off-by: <yinghai.lu@sun.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 06:37:59 +00:00
|
|
|
* or
|
|
|
|
* console=uart8250,io,0x3f8,9600n8
|
|
|
|
* console=uart8250,mmio,0xff5e0000,115200n8
|
2010-07-20 22:26:51 +00:00
|
|
|
* console=uart8250,mmio32,0xff5e0000,115200n8
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/console.h>
|
2015-09-15 00:56:03 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/serial_reg.h>
|
|
|
|
#include <linux/serial.h>
|
serial: convert early_uart to earlycon for 8250
Beacuse SERIAL_PORT_DFNS is removed from include/asm-i386/serial.h and
include/asm-x86_64/serial.h. the serial8250_ports need to be probed late in
serial initializing stage. the console_init=>serial8250_console_init=>
register_console=>serial8250_console_setup will return -ENDEV, and console
ttyS0 can not be enabled at that time. need to wait till uart_add_one_port in
drivers/serial/serial_core.c to call register_console to get console ttyS0.
that is too late.
Make early_uart to use early_param, so uart console can be used earlier. Make
it to be bootconsole with CON_BOOT flag, so can use console handover feature.
and it will switch to corresponding normal serial console automatically.
new command line will be:
console=uart8250,io,0x3f8,9600n8
console=uart8250,mmio,0xff5e0000,115200n8
or
earlycon=uart8250,io,0x3f8,9600n8
earlycon=uart8250,mmio,0xff5e0000,115200n8
it will print in very early stage:
Early serial console at I/O port 0x3f8 (options '9600n8')
console [uart0] enabled
later for console it will print:
console handover: boot [uart0] -> real [ttyS0]
Signed-off-by: <yinghai.lu@sun.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 06:37:59 +00:00
|
|
|
#include <linux/serial_8250.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/serial.h>
|
|
|
|
|
2017-07-18 06:02:58 +00:00
|
|
|
static unsigned int serial8250_early_in(struct uart_port *port, int offset)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-04-10 09:47:09 +00:00
|
|
|
int reg_offset = offset;
|
2016-01-16 23:23:47 +00:00
|
|
|
offset <<= port->regshift;
|
|
|
|
|
2010-07-20 22:26:51 +00:00
|
|
|
switch (port->iotype) {
|
|
|
|
case UPIO_MEM:
|
2005-04-16 22:20:36 +00:00
|
|
|
return readb(port->membase + offset);
|
2015-10-28 03:46:05 +00:00
|
|
|
case UPIO_MEM16:
|
2016-01-16 23:23:47 +00:00
|
|
|
return readw(port->membase + offset);
|
2010-07-20 22:26:51 +00:00
|
|
|
case UPIO_MEM32:
|
2016-01-16 23:23:47 +00:00
|
|
|
return readl(port->membase + offset);
|
2015-04-09 20:05:17 +00:00
|
|
|
case UPIO_MEM32BE:
|
2016-01-16 23:23:47 +00:00
|
|
|
return ioread32be(port->membase + offset);
|
2010-07-20 22:26:51 +00:00
|
|
|
case UPIO_PORT:
|
2005-04-16 22:20:36 +00:00
|
|
|
return inb(port->iobase + offset);
|
2017-04-10 09:47:09 +00:00
|
|
|
case UPIO_AU:
|
|
|
|
return port->serial_in(port, reg_offset);
|
2010-07-20 22:26:51 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 06:02:58 +00:00
|
|
|
static void serial8250_early_out(struct uart_port *port, int offset, int value)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-04-10 09:47:09 +00:00
|
|
|
int reg_offset = offset;
|
2016-01-16 23:23:47 +00:00
|
|
|
offset <<= port->regshift;
|
|
|
|
|
2010-07-20 22:26:51 +00:00
|
|
|
switch (port->iotype) {
|
|
|
|
case UPIO_MEM:
|
2005-04-16 22:20:36 +00:00
|
|
|
writeb(value, port->membase + offset);
|
2010-07-20 22:26:51 +00:00
|
|
|
break;
|
2015-10-28 03:46:05 +00:00
|
|
|
case UPIO_MEM16:
|
2016-01-16 23:23:47 +00:00
|
|
|
writew(value, port->membase + offset);
|
2015-10-28 03:46:05 +00:00
|
|
|
break;
|
2010-07-20 22:26:51 +00:00
|
|
|
case UPIO_MEM32:
|
2016-01-16 23:23:47 +00:00
|
|
|
writel(value, port->membase + offset);
|
2010-07-20 22:26:51 +00:00
|
|
|
break;
|
2015-04-09 20:05:17 +00:00
|
|
|
case UPIO_MEM32BE:
|
2016-01-16 23:23:47 +00:00
|
|
|
iowrite32be(value, port->membase + offset);
|
2015-04-09 20:05:17 +00:00
|
|
|
break;
|
2010-07-20 22:26:51 +00:00
|
|
|
case UPIO_PORT:
|
2005-04-16 22:20:36 +00:00
|
|
|
outb(value, port->iobase + offset);
|
2010-07-20 22:26:51 +00:00
|
|
|
break;
|
2017-04-10 09:47:09 +00:00
|
|
|
case UPIO_AU:
|
|
|
|
port->serial_out(port, reg_offset, value);
|
|
|
|
break;
|
2010-07-20 22:26:51 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
|
|
|
|
|
2017-07-18 06:02:58 +00:00
|
|
|
static void serial_putc(struct uart_port *port, int c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned int status;
|
|
|
|
|
2015-10-30 02:39:05 +00:00
|
|
|
serial8250_early_out(port, UART_TX, c);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
for (;;) {
|
2012-11-16 05:03:05 +00:00
|
|
|
status = serial8250_early_in(port, UART_LSR);
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((status & BOTH_EMPTY) == BOTH_EMPTY)
|
2015-10-30 02:39:05 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 06:02:58 +00:00
|
|
|
static void early_serial8250_write(struct console *console,
|
2008-02-08 12:18:49 +00:00
|
|
|
const char *s, unsigned int count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2015-03-09 20:27:14 +00:00
|
|
|
struct earlycon_device *device = console->data;
|
|
|
|
struct uart_port *port = &device->port;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-11-05 22:50:53 +00:00
|
|
|
uart_console_write(port, s, count, serial_putc);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 20:08:49 +00:00
|
|
|
#ifdef CONFIG_CONSOLE_POLL
|
|
|
|
static int early_serial8250_read(struct console *console,
|
|
|
|
char *s, unsigned int count)
|
|
|
|
{
|
|
|
|
struct earlycon_device *device = console->data;
|
|
|
|
struct uart_port *port = &device->port;
|
|
|
|
unsigned int status;
|
|
|
|
int num_read = 0;
|
|
|
|
|
|
|
|
while (num_read < count) {
|
|
|
|
status = serial8250_early_in(port, UART_LSR);
|
|
|
|
if (!(status & UART_LSR_DR))
|
|
|
|
break;
|
|
|
|
s[num_read++] = serial8250_early_in(port, UART_RX);
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_read;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define early_serial8250_read NULL
|
|
|
|
#endif
|
|
|
|
|
2014-04-18 22:19:56 +00:00
|
|
|
static void __init init_port(struct earlycon_device *device)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct uart_port *port = &device->port;
|
|
|
|
unsigned int divisor;
|
|
|
|
unsigned char c;
|
2015-01-27 04:50:09 +00:00
|
|
|
unsigned int ier;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-16 05:03:05 +00:00
|
|
|
serial8250_early_out(port, UART_LCR, 0x3); /* 8n1 */
|
2015-01-27 04:50:09 +00:00
|
|
|
ier = serial8250_early_in(port, UART_IER);
|
|
|
|
serial8250_early_out(port, UART_IER, ier & UART_IER_UUE); /* no interrupt */
|
2012-11-16 05:03:05 +00:00
|
|
|
serial8250_early_out(port, UART_FCR, 0); /* no fifo */
|
|
|
|
serial8250_early_out(port, UART_MCR, 0x3); /* DTR + RTS */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-04-23 09:18:11 +00:00
|
|
|
if (port->uartclk) {
|
2017-11-22 09:57:28 +00:00
|
|
|
divisor = DIV_ROUND_CLOSEST(port->uartclk, 16 * device->baud);
|
|
|
|
c = serial8250_early_in(port, UART_LCR);
|
|
|
|
serial8250_early_out(port, UART_LCR, c | UART_LCR_DLAB);
|
|
|
|
serial8250_early_out(port, UART_DLL, divisor & 0xff);
|
|
|
|
serial8250_early_out(port, UART_DLM, (divisor >> 8) & 0xff);
|
|
|
|
serial8250_early_out(port, UART_LCR, c & ~UART_LCR_DLAB);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 13:40:32 +00:00
|
|
|
int __init early_serial8250_setup(struct earlycon_device *device,
|
2014-04-18 22:19:56 +00:00
|
|
|
const char *options)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-04-18 22:19:56 +00:00
|
|
|
if (!(device->port.membase || device->port.iobase))
|
2015-03-09 20:27:17 +00:00
|
|
|
return -ENODEV;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-06-12 17:52:44 +00:00
|
|
|
if (!device->baud) {
|
2015-03-09 20:27:16 +00:00
|
|
|
struct uart_port *port = &device->port;
|
|
|
|
unsigned int ier;
|
|
|
|
|
|
|
|
/* assume the device was initialized, only mask interrupts */
|
|
|
|
ier = serial8250_early_in(port, UART_IER);
|
|
|
|
serial8250_early_out(port, UART_IER, ier & UART_IER_UUE);
|
|
|
|
} else
|
|
|
|
init_port(device);
|
serial: convert early_uart to earlycon for 8250
Beacuse SERIAL_PORT_DFNS is removed from include/asm-i386/serial.h and
include/asm-x86_64/serial.h. the serial8250_ports need to be probed late in
serial initializing stage. the console_init=>serial8250_console_init=>
register_console=>serial8250_console_setup will return -ENDEV, and console
ttyS0 can not be enabled at that time. need to wait till uart_add_one_port in
drivers/serial/serial_core.c to call register_console to get console ttyS0.
that is too late.
Make early_uart to use early_param, so uart console can be used earlier. Make
it to be bootconsole with CON_BOOT flag, so can use console handover feature.
and it will switch to corresponding normal serial console automatically.
new command line will be:
console=uart8250,io,0x3f8,9600n8
console=uart8250,mmio,0xff5e0000,115200n8
or
earlycon=uart8250,io,0x3f8,9600n8
earlycon=uart8250,mmio,0xff5e0000,115200n8
it will print in very early stage:
Early serial console at I/O port 0x3f8 (options '9600n8')
console [uart0] enabled
later for console it will print:
console handover: boot [uart0] -> real [ttyS0]
Signed-off-by: <yinghai.lu@sun.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 06:37:59 +00:00
|
|
|
|
2014-04-18 22:19:56 +00:00
|
|
|
device->con->write = early_serial8250_write;
|
2020-05-07 20:08:49 +00:00
|
|
|
device->con->read = early_serial8250_read;
|
serial: convert early_uart to earlycon for 8250
Beacuse SERIAL_PORT_DFNS is removed from include/asm-i386/serial.h and
include/asm-x86_64/serial.h. the serial8250_ports need to be probed late in
serial initializing stage. the console_init=>serial8250_console_init=>
register_console=>serial8250_console_setup will return -ENDEV, and console
ttyS0 can not be enabled at that time. need to wait till uart_add_one_port in
drivers/serial/serial_core.c to call register_console to get console ttyS0.
that is too late.
Make early_uart to use early_param, so uart console can be used earlier. Make
it to be bootconsole with CON_BOOT flag, so can use console handover feature.
and it will switch to corresponding normal serial console automatically.
new command line will be:
console=uart8250,io,0x3f8,9600n8
console=uart8250,mmio,0xff5e0000,115200n8
or
earlycon=uart8250,io,0x3f8,9600n8
earlycon=uart8250,mmio,0xff5e0000,115200n8
it will print in very early stage:
Early serial console at I/O port 0x3f8 (options '9600n8')
console [uart0] enabled
later for console it will print:
console handover: boot [uart0] -> real [ttyS0]
Signed-off-by: <yinghai.lu@sun.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Gerd Hoffmann <kraxel@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 06:37:59 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2014-04-18 22:19:56 +00:00
|
|
|
EARLYCON_DECLARE(uart8250, early_serial8250_setup);
|
|
|
|
EARLYCON_DECLARE(uart, early_serial8250_setup);
|
2015-09-15 00:56:03 +00:00
|
|
|
OF_EARLYCON_DECLARE(ns16550, "ns16550", early_serial8250_setup);
|
|
|
|
OF_EARLYCON_DECLARE(ns16550a, "ns16550a", early_serial8250_setup);
|
2016-02-08 16:27:35 +00:00
|
|
|
OF_EARLYCON_DECLARE(uart, "nvidia,tegra20-uart", early_serial8250_setup);
|
2016-05-11 06:06:01 +00:00
|
|
|
OF_EARLYCON_DECLARE(uart, "snps,dw-apb-uart", early_serial8250_setup);
|
2016-01-16 23:23:49 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_OMAP
|
|
|
|
|
|
|
|
static int __init early_omap8250_setup(struct earlycon_device *device,
|
|
|
|
const char *options)
|
|
|
|
{
|
|
|
|
struct uart_port *port = &device->port;
|
|
|
|
|
|
|
|
if (!(device->port.membase || device->port.iobase))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
port->regshift = 2;
|
|
|
|
device->con->write = early_serial8250_write;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
OF_EARLYCON_DECLARE(omap8250, "ti,omap2-uart", early_omap8250_setup);
|
|
|
|
OF_EARLYCON_DECLARE(omap8250, "ti,omap3-uart", early_omap8250_setup);
|
|
|
|
OF_EARLYCON_DECLARE(omap8250, "ti,omap4-uart", early_omap8250_setup);
|
|
|
|
|
|
|
|
#endif
|
2017-04-10 09:47:09 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RT288X
|
|
|
|
|
|
|
|
unsigned int au_serial_in(struct uart_port *p, int offset);
|
|
|
|
void au_serial_out(struct uart_port *p, int offset, int value);
|
|
|
|
|
|
|
|
static int __init early_au_setup(struct earlycon_device *dev, const char *opt)
|
|
|
|
{
|
|
|
|
dev->port.serial_in = au_serial_in;
|
|
|
|
dev->port.serial_out = au_serial_out;
|
|
|
|
dev->port.iotype = UPIO_AU;
|
|
|
|
dev->con->write = early_serial8250_write;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
OF_EARLYCON_DECLARE(palmchip, "ralink,rt2880-uart", early_au_setup);
|
|
|
|
|
|
|
|
#endif
|