2017-11-07 00:11:51 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 05:20:36 +07: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 13:37:59 +07:00
|
|
|
* earlycon=uart8250,io,0x3f8,9600n8
|
|
|
|
* earlycon=uart8250,mmio,0xff5e0000,115200n8
|
2010-07-21 05:26:51 +07: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 13:37:59 +07:00
|
|
|
* or
|
|
|
|
* console=uart8250,io,0x3f8,9600n8
|
|
|
|
* console=uart8250,mmio,0xff5e0000,115200n8
|
2010-07-21 05:26:51 +07:00
|
|
|
* console=uart8250,mmio32,0xff5e0000,115200n8
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/console.h>
|
2015-09-15 07:56:03 +07:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2005-04-17 05:20:36 +07: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 13:37:59 +07:00
|
|
|
#include <linux/serial_8250.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/serial.h>
|
|
|
|
|
2017-07-18 13:02:58 +07:00
|
|
|
static unsigned int serial8250_early_in(struct uart_port *port, int offset)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2017-04-10 16:47:09 +07:00
|
|
|
int reg_offset = offset;
|
2016-01-17 06:23:47 +07:00
|
|
|
offset <<= port->regshift;
|
|
|
|
|
2010-07-21 05:26:51 +07:00
|
|
|
switch (port->iotype) {
|
|
|
|
case UPIO_MEM:
|
2005-04-17 05:20:36 +07:00
|
|
|
return readb(port->membase + offset);
|
2015-10-28 10:46:05 +07:00
|
|
|
case UPIO_MEM16:
|
2016-01-17 06:23:47 +07:00
|
|
|
return readw(port->membase + offset);
|
2010-07-21 05:26:51 +07:00
|
|
|
case UPIO_MEM32:
|
2016-01-17 06:23:47 +07:00
|
|
|
return readl(port->membase + offset);
|
2015-04-10 03:05:17 +07:00
|
|
|
case UPIO_MEM32BE:
|
2016-01-17 06:23:47 +07:00
|
|
|
return ioread32be(port->membase + offset);
|
2010-07-21 05:26:51 +07:00
|
|
|
case UPIO_PORT:
|
2005-04-17 05:20:36 +07:00
|
|
|
return inb(port->iobase + offset);
|
2017-04-10 16:47:09 +07:00
|
|
|
case UPIO_AU:
|
|
|
|
return port->serial_in(port, reg_offset);
|
2010-07-21 05:26:51 +07:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2017-07-18 13:02:58 +07:00
|
|
|
static void serial8250_early_out(struct uart_port *port, int offset, int value)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2017-04-10 16:47:09 +07:00
|
|
|
int reg_offset = offset;
|
2016-01-17 06:23:47 +07:00
|
|
|
offset <<= port->regshift;
|
|
|
|
|
2010-07-21 05:26:51 +07:00
|
|
|
switch (port->iotype) {
|
|
|
|
case UPIO_MEM:
|
2005-04-17 05:20:36 +07:00
|
|
|
writeb(value, port->membase + offset);
|
2010-07-21 05:26:51 +07:00
|
|
|
break;
|
2015-10-28 10:46:05 +07:00
|
|
|
case UPIO_MEM16:
|
2016-01-17 06:23:47 +07:00
|
|
|
writew(value, port->membase + offset);
|
2015-10-28 10:46:05 +07:00
|
|
|
break;
|
2010-07-21 05:26:51 +07:00
|
|
|
case UPIO_MEM32:
|
2016-01-17 06:23:47 +07:00
|
|
|
writel(value, port->membase + offset);
|
2010-07-21 05:26:51 +07:00
|
|
|
break;
|
2015-04-10 03:05:17 +07:00
|
|
|
case UPIO_MEM32BE:
|
2016-01-17 06:23:47 +07:00
|
|
|
iowrite32be(value, port->membase + offset);
|
2015-04-10 03:05:17 +07:00
|
|
|
break;
|
2010-07-21 05:26:51 +07:00
|
|
|
case UPIO_PORT:
|
2005-04-17 05:20:36 +07:00
|
|
|
outb(value, port->iobase + offset);
|
2010-07-21 05:26:51 +07:00
|
|
|
break;
|
2017-04-10 16:47:09 +07:00
|
|
|
case UPIO_AU:
|
|
|
|
port->serial_out(port, reg_offset, value);
|
|
|
|
break;
|
2010-07-21 05:26:51 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
|
|
|
|
|
2017-07-18 13:02:58 +07:00
|
|
|
static void serial_putc(struct uart_port *port, int c)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
unsigned int status;
|
|
|
|
|
2015-10-30 09:39:05 +07:00
|
|
|
serial8250_early_out(port, UART_TX, c);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
for (;;) {
|
2012-11-16 12:03:05 +07:00
|
|
|
status = serial8250_early_in(port, UART_LSR);
|
2005-04-17 05:20:36 +07:00
|
|
|
if ((status & BOTH_EMPTY) == BOTH_EMPTY)
|
2015-10-30 09:39:05 +07:00
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 13:02:58 +07:00
|
|
|
static void early_serial8250_write(struct console *console,
|
2008-02-08 19:18:49 +07:00
|
|
|
const char *s, unsigned int count)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2015-03-10 03:27:14 +07:00
|
|
|
struct earlycon_device *device = console->data;
|
|
|
|
struct uart_port *port = &device->port;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-11-06 05:50:53 +07:00
|
|
|
uart_console_write(port, s, count, serial_putc);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2014-04-19 05:19:56 +07:00
|
|
|
static void __init init_port(struct earlycon_device *device)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct uart_port *port = &device->port;
|
|
|
|
unsigned int divisor;
|
|
|
|
unsigned char c;
|
2015-01-27 11:50:09 +07:00
|
|
|
unsigned int ier;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-11-16 12:03:05 +07:00
|
|
|
serial8250_early_out(port, UART_LCR, 0x3); /* 8n1 */
|
2015-01-27 11:50:09 +07:00
|
|
|
ier = serial8250_early_in(port, UART_IER);
|
|
|
|
serial8250_early_out(port, UART_IER, ier & UART_IER_UUE); /* no interrupt */
|
2012-11-16 12:03:05 +07:00
|
|
|
serial8250_early_out(port, UART_FCR, 0); /* no fifo */
|
|
|
|
serial8250_early_out(port, UART_MCR, 0x3); /* DTR + RTS */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-10-03 19:27:43 +07:00
|
|
|
divisor = DIV_ROUND_CLOSEST(port->uartclk, 16 * device->baud);
|
2012-11-16 12:03:05 +07:00
|
|
|
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-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2015-04-28 20:40:32 +07:00
|
|
|
int __init early_serial8250_setup(struct earlycon_device *device,
|
2014-04-19 05:19:56 +07:00
|
|
|
const char *options)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2014-04-19 05:19:56 +07:00
|
|
|
if (!(device->port.membase || device->port.iobase))
|
2015-03-10 03:27:17 +07:00
|
|
|
return -ENODEV;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-06-13 00:52:44 +07:00
|
|
|
if (!device->baud) {
|
2015-03-10 03:27:16 +07: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 13:37:59 +07:00
|
|
|
|
2014-04-19 05:19:56 +07:00
|
|
|
device->con->write = early_serial8250_write;
|
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 13:37:59 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2014-04-19 05:19:56 +07:00
|
|
|
EARLYCON_DECLARE(uart8250, early_serial8250_setup);
|
|
|
|
EARLYCON_DECLARE(uart, early_serial8250_setup);
|
2015-09-15 07:56:03 +07:00
|
|
|
OF_EARLYCON_DECLARE(ns16550, "ns16550", early_serial8250_setup);
|
|
|
|
OF_EARLYCON_DECLARE(ns16550a, "ns16550a", early_serial8250_setup);
|
2016-02-08 23:27:35 +07:00
|
|
|
OF_EARLYCON_DECLARE(uart, "nvidia,tegra20-uart", early_serial8250_setup);
|
2016-05-11 13:06:01 +07:00
|
|
|
OF_EARLYCON_DECLARE(uart, "snps,dw-apb-uart", early_serial8250_setup);
|
2016-01-17 06:23:49 +07: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 16:47:09 +07: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
|