aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Herring2014-04-18 17:19:56 -0500
committerAlex Shi2014-08-29 06:24:06 -0500
commit97e7091e469ac45fc21def96705c3b975e0d8ebe (patch)
tree47f98d6eb37df7790967d0ff6a058126d5717691
parent9d7451bf0207967c5a65fbd02b13822a52c0512e (diff)
downloadkernel-video-97e7091e469ac45fc21def96705c3b975e0d8ebe.tar.gz
kernel-video-97e7091e469ac45fc21def96705c3b975e0d8ebe.tar.xz
kernel-video-97e7091e469ac45fc21def96705c3b975e0d8ebe.zip
tty/serial: convert 8250 to generic earlycon
With the generic earlycon infrastructure in place, convert the 8250 early console to use it. Signed-off-by: Rob Herring <robh@kernel.org> Cc: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit d2fd6810a823bcde1ee232668f5689837aafa772) Signed-off-by: Alex Shi <alex.shi@linaro.org>
-rw-r--r--drivers/tty/serial/8250/8250_early.c138
-rw-r--r--drivers/tty/serial/8250/Kconfig1
2 files changed, 16 insertions, 123 deletions
diff --git a/drivers/tty/serial/8250/8250_early.c b/drivers/tty/serial/8250/8250_early.c
index c100d6343d5..e83c9db3300 100644
--- a/drivers/tty/serial/8250/8250_early.c
+++ b/drivers/tty/serial/8250/8250_early.c
@@ -35,18 +35,8 @@
35#include <linux/serial_8250.h> 35#include <linux/serial_8250.h>
36#include <asm/io.h> 36#include <asm/io.h>
37#include <asm/serial.h> 37#include <asm/serial.h>
38#ifdef CONFIG_FIX_EARLYCON_MEM
39#include <asm/pgtable.h>
40#include <asm/fixmap.h>
41#endif
42 38
43struct early_serial8250_device { 39static struct earlycon_device *early_device;
44 struct uart_port port;
45 char options[16]; /* e.g., 115200n8 */
46 unsigned int baud;
47};
48
49static struct early_serial8250_device early_device;
50 40
51unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offset) 41unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offset)
52{ 42{
@@ -100,7 +90,7 @@ static void __init serial_putc(struct uart_port *port, int c)
100static void __init early_serial8250_write(struct console *console, 90static void __init early_serial8250_write(struct console *console,
101 const char *s, unsigned int count) 91 const char *s, unsigned int count)
102{ 92{
103 struct uart_port *port = &early_device.port; 93 struct uart_port *port = &early_device->port;
104 unsigned int ier; 94 unsigned int ier;
105 95
106 /* Save the IER and disable interrupts */ 96 /* Save the IER and disable interrupts */
@@ -129,7 +119,7 @@ static unsigned int __init probe_baud(struct uart_port *port)
129 return (port->uartclk / 16) / quot; 119 return (port->uartclk / 16) / quot;
130} 120}
131 121
132static void __init init_port(struct early_serial8250_device *device) 122static void __init init_port(struct earlycon_device *device)
133{ 123{
134 struct uart_port *port = &device->port; 124 struct uart_port *port = &device->port;
135 unsigned int divisor; 125 unsigned int divisor;
@@ -148,128 +138,32 @@ static void __init init_port(struct early_serial8250_device *device)
148 serial8250_early_out(port, UART_LCR, c & ~UART_LCR_DLAB); 138 serial8250_early_out(port, UART_LCR, c & ~UART_LCR_DLAB);
149} 139}
150 140
151static int __init parse_options(struct early_serial8250_device *device, 141static int __init early_serial8250_setup(struct earlycon_device *device,
152 char *options) 142 const char *options)
153{
154 struct uart_port *port = &device->port;
155 int mmio, mmio32, length;
156
157 if (!options)
158 return -ENODEV;
159
160 port->uartclk = BASE_BAUD * 16;
161
162 mmio = !strncmp(options, "mmio,", 5);
163 mmio32 = !strncmp(options, "mmio32,", 7);
164 if (mmio || mmio32) {
165 port->iotype = (mmio ? UPIO_MEM : UPIO_MEM32);
166 port->mapbase = simple_strtoul(options + (mmio ? 5 : 7),
167 &options, 0);
168 if (mmio32)
169 port->regshift = 2;
170#ifdef CONFIG_FIX_EARLYCON_MEM
171 set_fixmap_nocache(FIX_EARLYCON_MEM_BASE,
172 port->mapbase & PAGE_MASK);
173 port->membase =
174 (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
175 port->membase += port->mapbase & ~PAGE_MASK;
176#else
177 port->membase = ioremap_nocache(port->mapbase, 64);
178 if (!port->membase) {
179 printk(KERN_ERR "%s: Couldn't ioremap 0x%llx\n",
180 __func__,
181 (unsigned long long) port->mapbase);
182 return -ENOMEM;
183 }
184#endif
185 } else if (!strncmp(options, "io,", 3)) {
186 port->iotype = UPIO_PORT;
187 port->iobase = simple_strtoul(options + 3, &options, 0);
188 mmio = 0;
189 } else
190 return -EINVAL;
191
192 options = strchr(options, ',');
193 if (options) {
194 options++;
195 device->baud = simple_strtoul(options, NULL, 0);
196 length = min(strcspn(options, " ") + 1,
197 (size_t)(sizeof(device->options)));
198 strlcpy(device->options, options, length);
199 } else {
200 device->baud = probe_baud(port);
201 snprintf(device->options, sizeof(device->options), "%u",
202 device->baud);
203 }
204
205 if (mmio || mmio32)
206 printk(KERN_INFO
207 "Early serial console at MMIO%s 0x%llx (options '%s')\n",
208 mmio32 ? "32" : "",
209 (unsigned long long)port->mapbase,
210 device->options);
211 else
212 printk(KERN_INFO
213 "Early serial console at I/O port 0x%lx (options '%s')\n",
214 port->iobase,
215 device->options);
216
217 return 0;
218}
219
220static struct console early_serial8250_console __initdata = {
221 .name = "uart",
222 .write = early_serial8250_write,
223 .flags = CON_PRINTBUFFER | CON_BOOT,
224 .index = -1,
225};
226
227static int __init early_serial8250_setup(char *options)
228{ 143{
229 struct early_serial8250_device *device = &early_device; 144 if (!(device->port.membase || device->port.iobase))
230 int err;
231
232 if (device->port.membase || device->port.iobase)
233 return 0; 145 return 0;
234 146
235 err = parse_options(device, options); 147 if (!device->baud)
236 if (err < 0) 148 device->baud = probe_baud(&device->port);
237 return err;
238 149
239 init_port(device); 150 init_port(device);
240 return 0;
241}
242
243int __init setup_early_serial8250_console(char *cmdline)
244{
245 char *options;
246 int err;
247
248 options = strstr(cmdline, "uart8250,");
249 if (!options) {
250 options = strstr(cmdline, "uart,");
251 if (!options)
252 return 0;
253 }
254
255 options = strchr(cmdline, ',') + 1;
256 err = early_serial8250_setup(options);
257 if (err < 0)
258 return err;
259
260 register_console(&early_serial8250_console);
261 151
152 early_device = device;
153 device->con->write = early_serial8250_write;
262 return 0; 154 return 0;
263} 155}
156EARLYCON_DECLARE(uart8250, early_serial8250_setup);
157EARLYCON_DECLARE(uart, early_serial8250_setup);
264 158
265int serial8250_find_port_for_earlycon(void) 159int serial8250_find_port_for_earlycon(void)
266{ 160{
267 struct early_serial8250_device *device = &early_device; 161 struct earlycon_device *device = early_device;
268 struct uart_port *port = &device->port; 162 struct uart_port *port = device ? &device->port : NULL;
269 int line; 163 int line;
270 int ret; 164 int ret;
271 165
272 if (!device->port.membase && !device->port.iobase) 166 if (!port || (!port->membase && !port->iobase))
273 return -ENODEV; 167 return -ENODEV;
274 168
275 line = serial8250_find_port(port); 169 line = serial8250_find_port(port);
@@ -284,5 +178,3 @@ int serial8250_find_port_for_earlycon(void)
284 178
285 return ret; 179 return ret;
286} 180}
287
288early_param("earlycon", setup_early_serial8250_console);
diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
index 23329918f22..7f96b50a3ce 100644
--- a/drivers/tty/serial/8250/Kconfig
+++ b/drivers/tty/serial/8250/Kconfig
@@ -61,6 +61,7 @@ config SERIAL_8250_CONSOLE
61 bool "Console on 8250/16550 and compatible serial port" 61 bool "Console on 8250/16550 and compatible serial port"
62 depends on SERIAL_8250=y 62 depends on SERIAL_8250=y
63 select SERIAL_CORE_CONSOLE 63 select SERIAL_CORE_CONSOLE
64 select SERIAL_EARLYCON
64 ---help--- 65 ---help---
65 If you say Y here, it will be possible to use a serial port as the 66 If you say Y here, it will be possible to use a serial port as the
66 system console (the system console is the device which receives all 67 system console (the system console is the device which receives all