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>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <linux/serial_core.h>
|
|
|
|
#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>
|
|
|
|
|
2012-11-16 05:03:05 +00:00
|
|
|
unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offset)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
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);
|
2010-07-20 22:26:51 +00:00
|
|
|
case UPIO_MEM32:
|
|
|
|
return readl(port->membase + (offset << 2));
|
|
|
|
case UPIO_PORT:
|
2005-04-16 22:20:36 +00:00
|
|
|
return inb(port->iobase + offset);
|
2010-07-20 22:26:51 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 05:03:05 +00:00
|
|
|
void __weak __init serial8250_early_out(struct uart_port *port, int offset, int value)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
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;
|
|
|
|
case UPIO_MEM32:
|
|
|
|
writel(value, port->membase + (offset << 2));
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
|
|
|
|
|
|
|
|
static void __init wait_for_xmitr(struct uart_port *port)
|
|
|
|
{
|
|
|
|
unsigned int status;
|
|
|
|
|
|
|
|
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)
|
|
|
|
return;
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-05 22:50:53 +00:00
|
|
|
static void __init serial_putc(struct uart_port *port, int c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
wait_for_xmitr(port);
|
2012-11-16 05:03:05 +00:00
|
|
|
serial8250_early_out(port, UART_TX, c);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 12:18:49 +00:00
|
|
|
static void __init early_serial8250_write(struct console *console,
|
|
|
|
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
|
|
|
unsigned int ier;
|
|
|
|
|
2015-01-27 04:50:09 +00:00
|
|
|
/* Save the IER and disable interrupts preserving the UUE bit */
|
2012-11-16 05:03:05 +00:00
|
|
|
ier = serial8250_early_in(port, UART_IER);
|
2015-01-06 11:29:10 +00:00
|
|
|
if (ier)
|
2015-01-27 04:50:09 +00:00
|
|
|
serial8250_early_out(port, UART_IER, ier & UART_IER_UUE);
|
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
|
|
|
|
|
|
|
/* Wait for transmitter to become empty and restore the IER */
|
|
|
|
wait_for_xmitr(port);
|
2015-01-06 11:29:10 +00:00
|
|
|
|
|
|
|
if (ier)
|
|
|
|
serial8250_early_out(port, UART_IER, ier);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int __init probe_baud(struct uart_port *port)
|
|
|
|
{
|
|
|
|
unsigned char lcr, dll, dlm;
|
|
|
|
unsigned int quot;
|
|
|
|
|
2012-11-16 05:03:05 +00:00
|
|
|
lcr = serial8250_early_in(port, UART_LCR);
|
|
|
|
serial8250_early_out(port, UART_LCR, lcr | UART_LCR_DLAB);
|
|
|
|
dll = serial8250_early_in(port, UART_DLL);
|
|
|
|
dlm = serial8250_early_in(port, UART_DLM);
|
|
|
|
serial8250_early_out(port, UART_LCR, lcr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
quot = (dlm << 8) | dll;
|
|
|
|
return (port->uartclk / 16) / quot;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-10-03 12:27:43 +00:00
|
|
|
divisor = DIV_ROUND_CLOSEST(port->uartclk, 16 * device->baud);
|
2012-11-16 05:03:05 +00: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-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2014-04-18 22:19:56 +00:00
|
|
|
static int __init early_serial8250_setup(struct earlycon_device *device,
|
|
|
|
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;
|
|
|
|
|
2014-04-18 22:19:56 +00:00
|
|
|
device->baud = probe_baud(&device->port);
|
2014-06-12 17:52:44 +00:00
|
|
|
snprintf(device->options, sizeof(device->options), "%u",
|
|
|
|
device->baud);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-03-09 20:27:16 +00:00
|
|
|
/* 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;
|
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);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-05-01 00:48:28 +00:00
|
|
|
int __init setup_early_serial8250_console(char *cmdline)
|
|
|
|
{
|
|
|
|
char match[] = "uart8250";
|
|
|
|
|
|
|
|
if (cmdline && cmdline[4] == ',')
|
|
|
|
match[4] = '\0';
|
|
|
|
|
|
|
|
return setup_earlycon(cmdline, match, early_serial8250_setup);
|
|
|
|
}
|