sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / tty / serial / 8250 / 8250_early.c
blob85a12f03240247494366a231d24fa86ba042dfdb
1 /*
2 * Early serial console for 8250/16550 devices
4 * (c) Copyright 2004 Hewlett-Packard Development Company, L.P.
5 * Bjorn Helgaas <bjorn.helgaas@hp.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Based on the 8250.c serial driver, Copyright (C) 2001 Russell King,
12 * and on early_printk.c by Andi Kleen.
14 * This is for use before the serial driver has initialized, in
15 * particular, before the UARTs have been discovered and named.
16 * Instead of specifying the console device as, e.g., "ttyS0",
17 * we locate the device directly by its MMIO or I/O port address.
19 * The user can specify the device directly, e.g.,
20 * earlycon=uart8250,io,0x3f8,9600n8
21 * earlycon=uart8250,mmio,0xff5e0000,115200n8
22 * earlycon=uart8250,mmio32,0xff5e0000,115200n8
23 * or
24 * console=uart8250,io,0x3f8,9600n8
25 * console=uart8250,mmio,0xff5e0000,115200n8
26 * console=uart8250,mmio32,0xff5e0000,115200n8
29 #include <linux/tty.h>
30 #include <linux/init.h>
31 #include <linux/console.h>
32 #include <linux/of.h>
33 #include <linux/of_device.h>
34 #include <linux/serial_reg.h>
35 #include <linux/serial.h>
36 #include <linux/serial_8250.h>
37 #include <asm/io.h>
38 #include <asm/serial.h>
40 static unsigned int __init serial8250_early_in(struct uart_port *port, int offset)
42 offset <<= port->regshift;
44 switch (port->iotype) {
45 case UPIO_MEM:
46 return readb(port->membase + offset);
47 case UPIO_MEM16:
48 return readw(port->membase + offset);
49 case UPIO_MEM32:
50 return readl(port->membase + offset);
51 case UPIO_MEM32BE:
52 return ioread32be(port->membase + offset);
53 case UPIO_PORT:
54 return inb(port->iobase + offset);
55 default:
56 return 0;
60 static void __init serial8250_early_out(struct uart_port *port, int offset, int value)
62 offset <<= port->regshift;
64 switch (port->iotype) {
65 case UPIO_MEM:
66 writeb(value, port->membase + offset);
67 break;
68 case UPIO_MEM16:
69 writew(value, port->membase + offset);
70 break;
71 case UPIO_MEM32:
72 writel(value, port->membase + offset);
73 break;
74 case UPIO_MEM32BE:
75 iowrite32be(value, port->membase + offset);
76 break;
77 case UPIO_PORT:
78 outb(value, port->iobase + offset);
79 break;
83 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
85 static void __init serial_putc(struct uart_port *port, int c)
87 unsigned int status;
89 serial8250_early_out(port, UART_TX, c);
91 for (;;) {
92 status = serial8250_early_in(port, UART_LSR);
93 if ((status & BOTH_EMPTY) == BOTH_EMPTY)
94 break;
95 cpu_relax();
99 static void __init early_serial8250_write(struct console *console,
100 const char *s, unsigned int count)
102 struct earlycon_device *device = console->data;
103 struct uart_port *port = &device->port;
105 uart_console_write(port, s, count, serial_putc);
108 static void __init init_port(struct earlycon_device *device)
110 struct uart_port *port = &device->port;
111 unsigned int divisor;
112 unsigned char c;
113 unsigned int ier;
115 serial8250_early_out(port, UART_LCR, 0x3); /* 8n1 */
116 ier = serial8250_early_in(port, UART_IER);
117 serial8250_early_out(port, UART_IER, ier & UART_IER_UUE); /* no interrupt */
118 serial8250_early_out(port, UART_FCR, 0); /* no fifo */
119 serial8250_early_out(port, UART_MCR, 0x3); /* DTR + RTS */
121 divisor = DIV_ROUND_CLOSEST(port->uartclk, 16 * device->baud);
122 c = serial8250_early_in(port, UART_LCR);
123 serial8250_early_out(port, UART_LCR, c | UART_LCR_DLAB);
124 serial8250_early_out(port, UART_DLL, divisor & 0xff);
125 serial8250_early_out(port, UART_DLM, (divisor >> 8) & 0xff);
126 serial8250_early_out(port, UART_LCR, c & ~UART_LCR_DLAB);
129 int __init early_serial8250_setup(struct earlycon_device *device,
130 const char *options)
132 if (!(device->port.membase || device->port.iobase))
133 return -ENODEV;
135 if (!device->baud) {
136 struct uart_port *port = &device->port;
137 unsigned int ier;
139 /* assume the device was initialized, only mask interrupts */
140 ier = serial8250_early_in(port, UART_IER);
141 serial8250_early_out(port, UART_IER, ier & UART_IER_UUE);
142 } else
143 init_port(device);
145 device->con->write = early_serial8250_write;
146 return 0;
148 EARLYCON_DECLARE(uart8250, early_serial8250_setup);
149 EARLYCON_DECLARE(uart, early_serial8250_setup);
150 OF_EARLYCON_DECLARE(ns16550, "ns16550", early_serial8250_setup);
151 OF_EARLYCON_DECLARE(ns16550a, "ns16550a", early_serial8250_setup);
152 OF_EARLYCON_DECLARE(uart, "nvidia,tegra20-uart", early_serial8250_setup);
153 OF_EARLYCON_DECLARE(uart, "snps,dw-apb-uart", early_serial8250_setup);
155 #ifdef CONFIG_SERIAL_8250_OMAP
157 static int __init early_omap8250_setup(struct earlycon_device *device,
158 const char *options)
160 struct uart_port *port = &device->port;
162 if (!(device->port.membase || device->port.iobase))
163 return -ENODEV;
165 port->regshift = 2;
166 device->con->write = early_serial8250_write;
167 return 0;
170 OF_EARLYCON_DECLARE(omap8250, "ti,omap2-uart", early_omap8250_setup);
171 OF_EARLYCON_DECLARE(omap8250, "ti,omap3-uart", early_omap8250_setup);
172 OF_EARLYCON_DECLARE(omap8250, "ti,omap4-uart", early_omap8250_setup);
174 #endif