2 * Copyright (C) 2014 Linaro Ltd.
3 * Author: Rob Herring <robh@kernel.org>
5 * Based on 8250 earlycon:
6 * (c) Copyright 2004 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 #include <linux/console.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
17 #include <linux/serial_core.h>
19 #ifdef CONFIG_FIX_EARLYCON_MEM
20 #include <asm/fixmap.h>
23 #include <asm/serial.h>
25 static struct console early_con
= {
27 .flags
= CON_PRINTBUFFER
| CON_BOOT
,
31 static struct earlycon_device early_console_dev
= {
35 static void __iomem
* __init
earlycon_map(unsigned long paddr
, size_t size
)
38 #ifdef CONFIG_FIX_EARLYCON_MEM
39 set_fixmap_io(FIX_EARLYCON_MEM_BASE
, paddr
& PAGE_MASK
);
40 base
= (void __iomem
*)__fix_to_virt(FIX_EARLYCON_MEM_BASE
);
41 base
+= paddr
& ~PAGE_MASK
;
43 base
= ioremap(paddr
, size
);
46 pr_err("%s: Couldn't map 0x%llx\n", __func__
,
47 (unsigned long long)paddr
);
52 static int __init
parse_options(struct earlycon_device
*device
,
55 struct uart_port
*port
= &device
->port
;
56 int mmio
, mmio32
, length
;
62 mmio
= !strncmp(options
, "mmio,", 5);
63 mmio32
= !strncmp(options
, "mmio32,", 7);
65 port
->iotype
= (mmio
? UPIO_MEM
: UPIO_MEM32
);
66 options
+= mmio
? 5 : 7;
67 addr
= simple_strtoul(options
, NULL
, 0);
71 } else if (!strncmp(options
, "io,", 3)) {
72 port
->iotype
= UPIO_PORT
;
74 addr
= simple_strtoul(options
, NULL
, 0);
77 } else if (!strncmp(options
, "0x", 2)) {
78 port
->iotype
= UPIO_MEM
;
79 addr
= simple_strtoul(options
, NULL
, 0);
85 port
->uartclk
= BASE_BAUD
* 16;
87 options
= strchr(options
, ',');
90 device
->baud
= simple_strtoul(options
, NULL
, 0);
91 length
= min(strcspn(options
, " ") + 1,
92 (size_t)(sizeof(device
->options
)));
93 strlcpy(device
->options
, options
, length
);
97 pr_info("Early serial console at MMIO%s 0x%llx (options '%s')\n",
99 (unsigned long long)port
->mapbase
,
102 pr_info("Early serial console at I/O port 0x%lx (options '%s')\n",
109 int __init
setup_earlycon(char *buf
, const char *match
,
110 int (*setup
)(struct earlycon_device
*, const char *))
114 struct uart_port
*port
= &early_console_dev
.port
;
116 if (!buf
|| !match
|| !setup
)
120 if (strncmp(buf
, match
, len
))
122 if (buf
[len
] && (buf
[len
] != ','))
127 err
= parse_options(&early_console_dev
, buf
);
128 /* On parsing error, pass the options buf to the setup function */
133 port
->membase
= earlycon_map(port
->mapbase
, 64);
135 early_console_dev
.con
->data
= &early_console_dev
;
136 err
= setup(&early_console_dev
, buf
);
139 if (!early_console_dev
.con
->write
)
142 register_console(early_console_dev
.con
);