Commit | Line | Data |
---|---|---|
463ce0e1 BH |
1 | #include <linux/kernel.h> |
2 | #include <linux/serial.h> | |
3 | #include <linux/serial_8250.h> | |
4 | #include <linux/serial_core.h> | |
5 | #include <linux/console.h> | |
6 | #include <linux/pci.h> | |
1a7507c7 | 7 | #include <linux/of_device.h> |
463ce0e1 BH |
8 | #include <asm/io.h> |
9 | #include <asm/mmu.h> | |
10 | #include <asm/prom.h> | |
11 | #include <asm/serial.h> | |
12 | #include <asm/udbg.h> | |
13 | #include <asm/pci-bridge.h> | |
14 | #include <asm/ppc-pci.h> | |
15 | ||
16 | #undef DEBUG | |
17 | ||
18 | #ifdef DEBUG | |
19 | #define DBG(fmt...) do { printk(fmt); } while(0) | |
20 | #else | |
21 | #define DBG(fmt...) do { } while(0) | |
22 | #endif | |
23 | ||
24 | #define MAX_LEGACY_SERIAL_PORTS 8 | |
25 | ||
26 | static struct plat_serial8250_port | |
27 | legacy_serial_ports[MAX_LEGACY_SERIAL_PORTS+1]; | |
28 | static struct legacy_serial_info { | |
29 | struct device_node *np; | |
30 | unsigned int speed; | |
31 | unsigned int clock; | |
0ebfff14 | 32 | int irq_check_parent; |
463ce0e1 BH |
33 | phys_addr_t taddr; |
34 | } legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS]; | |
1a7507c7 | 35 | |
3bc5ab9b | 36 | static struct __initdata of_device_id legacy_serial_parents[] = { |
1a7507c7 PG |
37 | {.type = "soc",}, |
38 | {.type = "tsi-bridge",}, | |
f5903ede ME |
39 | {.type = "opb", }, |
40 | {.compatible = "ibm,opb",}, | |
1a7507c7 PG |
41 | {.compatible = "simple-bus",}, |
42 | {.compatible = "wrs,epld-localbus",}, | |
3bc5ab9b | 43 | {}, |
1a7507c7 PG |
44 | }; |
45 | ||
463ce0e1 BH |
46 | static unsigned int legacy_serial_count; |
47 | static int legacy_serial_console = -1; | |
48 | ||
49 | static int __init add_legacy_port(struct device_node *np, int want_index, | |
50 | int iotype, phys_addr_t base, | |
b580d46c | 51 | phys_addr_t taddr, unsigned long irq, |
0ebfff14 | 52 | upf_t flags, int irq_check_parent) |
463ce0e1 | 53 | { |
a7f67bdf JK |
54 | const u32 *clk, *spd; |
55 | u32 clock = BASE_BAUD * 16; | |
463ce0e1 BH |
56 | int index; |
57 | ||
58 | /* get clock freq. if present */ | |
e2eb6392 | 59 | clk = of_get_property(np, "clock-frequency", NULL); |
31df1678 DW |
60 | if (clk && *clk) |
61 | clock = *clk; | |
463ce0e1 BH |
62 | |
63 | /* get default speed if present */ | |
e2eb6392 | 64 | spd = of_get_property(np, "current-speed", NULL); |
463ce0e1 BH |
65 | |
66 | /* If we have a location index, then try to use it */ | |
67 | if (want_index >= 0 && want_index < MAX_LEGACY_SERIAL_PORTS) | |
68 | index = want_index; | |
69 | else | |
70 | index = legacy_serial_count; | |
71 | ||
72 | /* if our index is still out of range, that mean that | |
73 | * array is full, we could scan for a free slot but that | |
74 | * make little sense to bother, just skip the port | |
75 | */ | |
76 | if (index >= MAX_LEGACY_SERIAL_PORTS) | |
77 | return -1; | |
78 | if (index >= legacy_serial_count) | |
79 | legacy_serial_count = index + 1; | |
80 | ||
81 | /* Check if there is a port who already claimed our slot */ | |
82 | if (legacy_serial_infos[index].np != 0) { | |
83 | /* if we still have some room, move it, else override */ | |
84 | if (legacy_serial_count < MAX_LEGACY_SERIAL_PORTS) { | |
0ebfff14 | 85 | printk(KERN_DEBUG "Moved legacy port %d -> %d\n", |
463ce0e1 BH |
86 | index, legacy_serial_count); |
87 | legacy_serial_ports[legacy_serial_count] = | |
88 | legacy_serial_ports[index]; | |
89 | legacy_serial_infos[legacy_serial_count] = | |
90 | legacy_serial_infos[index]; | |
91 | legacy_serial_count++; | |
92 | } else { | |
0ebfff14 | 93 | printk(KERN_DEBUG "Replacing legacy port %d\n", index); |
463ce0e1 BH |
94 | } |
95 | } | |
96 | ||
97 | /* Now fill the entry */ | |
98 | memset(&legacy_serial_ports[index], 0, | |
99 | sizeof(struct plat_serial8250_port)); | |
100 | if (iotype == UPIO_PORT) | |
101 | legacy_serial_ports[index].iobase = base; | |
102 | else | |
8dacaedf | 103 | legacy_serial_ports[index].mapbase = base; |
463ce0e1 BH |
104 | legacy_serial_ports[index].iotype = iotype; |
105 | legacy_serial_ports[index].uartclk = clock; | |
106 | legacy_serial_ports[index].irq = irq; | |
b580d46c | 107 | legacy_serial_ports[index].flags = flags; |
463ce0e1 BH |
108 | legacy_serial_infos[index].taddr = taddr; |
109 | legacy_serial_infos[index].np = of_node_get(np); | |
110 | legacy_serial_infos[index].clock = clock; | |
111 | legacy_serial_infos[index].speed = spd ? *spd : 0; | |
0ebfff14 | 112 | legacy_serial_infos[index].irq_check_parent = irq_check_parent; |
463ce0e1 | 113 | |
0ebfff14 | 114 | printk(KERN_DEBUG "Found legacy serial port %d for %s\n", |
463ce0e1 | 115 | index, np->full_name); |
0ebfff14 | 116 | printk(KERN_DEBUG " %s=%llx, taddr=%llx, irq=%lx, clk=%d, speed=%d\n", |
463ce0e1 BH |
117 | (iotype == UPIO_PORT) ? "port" : "mem", |
118 | (unsigned long long)base, (unsigned long long)taddr, irq, | |
119 | legacy_serial_ports[index].uartclk, | |
120 | legacy_serial_infos[index].speed); | |
121 | ||
122 | return index; | |
123 | } | |
124 | ||
b580d46c KG |
125 | static int __init add_legacy_soc_port(struct device_node *np, |
126 | struct device_node *soc_dev) | |
127 | { | |
f704b8d1 | 128 | u64 addr; |
a7f67bdf | 129 | const u32 *addrp; |
abb4a239 DG |
130 | upf_t flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ |
131 | | UPF_FIXED_PORT; | |
be9633e9 | 132 | struct device_node *tsi = of_get_parent(np); |
b580d46c KG |
133 | |
134 | /* We only support ports that have a clock frequency properly | |
135 | * encoded in the device-tree. | |
136 | */ | |
e2eb6392 | 137 | if (of_get_property(np, "clock-frequency", NULL) == NULL) |
b580d46c KG |
138 | return -1; |
139 | ||
1e6d1f26 JL |
140 | /* if reg-shift or offset, don't try to use it */ |
141 | if ((of_get_property(np, "reg-shift", NULL) != NULL) || | |
142 | (of_get_property(np, "reg-offset", NULL) != NULL)) | |
143 | return -1; | |
144 | ||
8d38a5b2 | 145 | /* if rtas uses this device, don't try to use it as well */ |
e2eb6392 | 146 | if (of_get_property(np, "used-by-rtas", NULL) != NULL) |
8d38a5b2 AB |
147 | return -1; |
148 | ||
b580d46c KG |
149 | /* Get the address */ |
150 | addrp = of_get_address(soc_dev, 0, NULL, NULL); | |
151 | if (addrp == NULL) | |
152 | return -1; | |
153 | ||
154 | addr = of_translate_address(soc_dev, addrp); | |
7c6efda5 BH |
155 | if (addr == OF_BAD_ADDR) |
156 | return -1; | |
b580d46c KG |
157 | |
158 | /* Add port, irq will be dealt with later. We passed a translated | |
159 | * IO port value. It will be fixed up later along with the irq | |
160 | */ | |
be9633e9 ZR |
161 | if (tsi && !strcmp(tsi->type, "tsi-bridge")) |
162 | return add_legacy_port(np, -1, UPIO_TSI, addr, addr, NO_IRQ, flags, 0); | |
163 | else | |
164 | return add_legacy_port(np, -1, UPIO_MEM, addr, addr, NO_IRQ, flags, 0); | |
b580d46c KG |
165 | } |
166 | ||
463ce0e1 | 167 | static int __init add_legacy_isa_port(struct device_node *np, |
017e0fad | 168 | struct device_node *isa_brg) |
463ce0e1 | 169 | { |
a7f67bdf JK |
170 | const u32 *reg; |
171 | const char *typep; | |
463ce0e1 | 172 | int index = -1; |
f704b8d1 | 173 | u64 taddr; |
463ce0e1 | 174 | |
7c6efda5 BH |
175 | DBG(" -> add_legacy_isa_port(%s)\n", np->full_name); |
176 | ||
463ce0e1 | 177 | /* Get the ISA port number */ |
e2eb6392 | 178 | reg = of_get_property(np, "reg", NULL); |
463ce0e1 BH |
179 | if (reg == NULL) |
180 | return -1; | |
181 | ||
182 | /* Verify it's an IO port, we don't support anything else */ | |
183 | if (!(reg[0] & 0x00000001)) | |
184 | return -1; | |
185 | ||
186 | /* Now look for an "ibm,aix-loc" property that gives us ordering | |
187 | * if any... | |
188 | */ | |
e2eb6392 | 189 | typep = of_get_property(np, "ibm,aix-loc", NULL); |
463ce0e1 BH |
190 | |
191 | /* If we have a location index, then use it */ | |
192 | if (typep && *typep == 'S') | |
193 | index = simple_strtol(typep+1, NULL, 0) - 1; | |
194 | ||
f704b8d1 BH |
195 | /* Translate ISA address. If it fails, we still register the port |
196 | * with no translated address so that it can be picked up as an IO | |
197 | * port later by the serial driver | |
198 | */ | |
463ce0e1 | 199 | taddr = of_translate_address(np, reg); |
7c6efda5 | 200 | if (taddr == OF_BAD_ADDR) |
f704b8d1 | 201 | taddr = 0; |
463ce0e1 BH |
202 | |
203 | /* Add port, irq will be dealt with later */ | |
7c6efda5 | 204 | return add_legacy_port(np, index, UPIO_PORT, reg[1], taddr, |
0ebfff14 | 205 | NO_IRQ, UPF_BOOT_AUTOCONF, 0); |
463ce0e1 BH |
206 | |
207 | } | |
208 | ||
017e0fad | 209 | #ifdef CONFIG_PCI |
463ce0e1 BH |
210 | static int __init add_legacy_pci_port(struct device_node *np, |
211 | struct device_node *pci_dev) | |
212 | { | |
f704b8d1 | 213 | u64 addr, base; |
a7f67bdf | 214 | const u32 *addrp; |
d2dd482b | 215 | unsigned int flags; |
8dacaedf | 216 | int iotype, index = -1, lindex = 0; |
463ce0e1 | 217 | |
7c6efda5 BH |
218 | DBG(" -> add_legacy_pci_port(%s)\n", np->full_name); |
219 | ||
463ce0e1 BH |
220 | /* We only support ports that have a clock frequency properly |
221 | * encoded in the device-tree (that is have an fcode). Anything | |
222 | * else can't be used that early and will be normally probed by | |
8dacaedf BH |
223 | * the generic 8250_pci driver later on. The reason is that 8250 |
224 | * compatible UARTs on PCI need all sort of quirks (port offsets | |
225 | * etc...) that this code doesn't know about | |
463ce0e1 | 226 | */ |
e2eb6392 | 227 | if (of_get_property(np, "clock-frequency", NULL) == NULL) |
463ce0e1 | 228 | return -1; |
463ce0e1 BH |
229 | |
230 | /* Get the PCI address. Assume BAR 0 */ | |
d2dd482b | 231 | addrp = of_get_pci_address(pci_dev, 0, NULL, &flags); |
463ce0e1 BH |
232 | if (addrp == NULL) |
233 | return -1; | |
234 | ||
235 | /* We only support BAR 0 for now */ | |
d2dd482b | 236 | iotype = (flags & IORESOURCE_MEM) ? UPIO_MEM : UPIO_PORT; |
463ce0e1 | 237 | addr = of_translate_address(pci_dev, addrp); |
7c6efda5 BH |
238 | if (addr == OF_BAD_ADDR) |
239 | return -1; | |
463ce0e1 BH |
240 | |
241 | /* Set the IO base to the same as the translated address for MMIO, | |
242 | * or to the domain local IO base for PIO (it will be fixed up later) | |
243 | */ | |
244 | if (iotype == UPIO_MEM) | |
245 | base = addr; | |
246 | else | |
247 | base = addrp[2]; | |
248 | ||
249 | /* Try to guess an index... If we have subdevices of the pci dev, | |
250 | * we get to their "reg" property | |
251 | */ | |
252 | if (np != pci_dev) { | |
e2eb6392 | 253 | const u32 *reg = of_get_property(np, "reg", NULL); |
463ce0e1 | 254 | if (reg && (*reg < 4)) |
8dacaedf BH |
255 | index = lindex = *reg; |
256 | } | |
257 | ||
258 | /* Local index means it's the Nth port in the PCI chip. Unfortunately | |
259 | * the offset to add here is device specific. We know about those | |
260 | * EXAR ports and we default to the most common case. If your UART | |
261 | * doesn't work for these settings, you'll have to add your own special | |
262 | * cases here | |
263 | */ | |
55b61fec SR |
264 | if (of_device_is_compatible(pci_dev, "pci13a8,152") || |
265 | of_device_is_compatible(pci_dev, "pci13a8,154") || | |
266 | of_device_is_compatible(pci_dev, "pci13a8,158")) { | |
8dacaedf BH |
267 | addr += 0x200 * lindex; |
268 | base += 0x200 * lindex; | |
269 | } else { | |
270 | addr += 8 * lindex; | |
271 | base += 8 * lindex; | |
463ce0e1 BH |
272 | } |
273 | ||
274 | /* Add port, irq will be dealt with later. We passed a translated | |
275 | * IO port value. It will be fixed up later along with the irq | |
276 | */ | |
0ebfff14 BH |
277 | return add_legacy_port(np, index, iotype, base, addr, NO_IRQ, |
278 | UPF_BOOT_AUTOCONF, np != pci_dev); | |
463ce0e1 | 279 | } |
017e0fad | 280 | #endif |
463ce0e1 | 281 | |
37a801c7 MN |
282 | static void __init setup_legacy_serial_console(int console) |
283 | { | |
284 | struct legacy_serial_info *info = | |
285 | &legacy_serial_infos[console]; | |
286 | void __iomem *addr; | |
287 | ||
288 | if (info->taddr == 0) | |
289 | return; | |
290 | addr = ioremap(info->taddr, 0x1000); | |
291 | if (addr == NULL) | |
292 | return; | |
293 | if (info->speed == 0) | |
294 | info->speed = udbg_probe_uart_speed(addr, info->clock); | |
295 | DBG("default console speed = %d\n", info->speed); | |
296 | udbg_init_uart(addr, info->speed, info->clock); | |
297 | } | |
298 | ||
463ce0e1 BH |
299 | /* |
300 | * This is called very early, as part of setup_system() or eventually | |
301 | * setup_arch(), basically before anything else in this file. This function | |
302 | * will try to build a list of all the available 8250-compatible serial ports | |
303 | * in the machine using the Open Firmware device-tree. It currently only deals | |
304 | * with ISA and PCI busses but could be extended. It allows a very early boot | |
305 | * console to be initialized, that list is also used later to provide 8250 with | |
306 | * the machine non-PCI ports and to properly pick the default console port | |
307 | */ | |
308 | void __init find_legacy_serial_ports(void) | |
309 | { | |
b580d46c | 310 | struct device_node *np, *stdout = NULL; |
a7f67bdf | 311 | const char *path; |
463ce0e1 BH |
312 | int index; |
313 | ||
314 | DBG(" -> find_legacy_serial_port()\n"); | |
315 | ||
316 | /* Now find out if one of these is out firmware console */ | |
e2eb6392 | 317 | path = of_get_property(of_chosen, "linux,stdout-path", NULL); |
b580d46c KG |
318 | if (path != NULL) { |
319 | stdout = of_find_node_by_path(path); | |
320 | if (stdout) | |
321 | DBG("stdout is %s\n", stdout->full_name); | |
322 | } else { | |
463ce0e1 | 323 | DBG(" no linux,stdout-path !\n"); |
463ce0e1 | 324 | } |
b580d46c | 325 | |
1a7507c7 | 326 | /* Iterate over all the 16550 ports, looking for known parents */ |
3329c0d1 | 327 | for_each_compatible_node(np, "serial", "ns16550") { |
1a7507c7 PG |
328 | struct device_node *parent = of_get_parent(np); |
329 | if (!parent) | |
330 | continue; | |
3bc5ab9b | 331 | if (of_match_node(legacy_serial_parents, parent) != NULL) { |
b580d46c KG |
332 | index = add_legacy_soc_port(np, np); |
333 | if (index >= 0 && np == stdout) | |
334 | legacy_serial_console = index; | |
335 | } | |
1a7507c7 | 336 | of_node_put(parent); |
463ce0e1 BH |
337 | } |
338 | ||
1a7507c7 | 339 | /* Next, fill our array with ISA ports */ |
3329c0d1 | 340 | for_each_node_by_type(np, "serial") { |
463ce0e1 BH |
341 | struct device_node *isa = of_get_parent(np); |
342 | if (isa && !strcmp(isa->name, "isa")) { | |
343 | index = add_legacy_isa_port(np, isa); | |
344 | if (index >= 0 && np == stdout) | |
345 | legacy_serial_console = index; | |
346 | } | |
347 | of_node_put(isa); | |
348 | } | |
349 | ||
017e0fad | 350 | #ifdef CONFIG_PCI |
463ce0e1 BH |
351 | /* Next, try to locate PCI ports */ |
352 | for (np = NULL; (np = of_find_all_nodes(np));) { | |
353 | struct device_node *pci, *parent = of_get_parent(np); | |
354 | if (parent && !strcmp(parent->name, "isa")) { | |
355 | of_node_put(parent); | |
356 | continue; | |
357 | } | |
358 | if (strcmp(np->name, "serial") && strcmp(np->type, "serial")) { | |
359 | of_node_put(parent); | |
360 | continue; | |
361 | } | |
362 | /* Check for known pciclass, and also check wether we have | |
363 | * a device with child nodes for ports or not | |
364 | */ | |
55b61fec SR |
365 | if (of_device_is_compatible(np, "pciclass,0700") || |
366 | of_device_is_compatible(np, "pciclass,070002")) | |
463ce0e1 | 367 | pci = np; |
55b61fec SR |
368 | else if (of_device_is_compatible(parent, "pciclass,0700") || |
369 | of_device_is_compatible(parent, "pciclass,070002")) | |
463ce0e1 BH |
370 | pci = parent; |
371 | else { | |
372 | of_node_put(parent); | |
373 | continue; | |
374 | } | |
375 | index = add_legacy_pci_port(np, pci); | |
376 | if (index >= 0 && np == stdout) | |
377 | legacy_serial_console = index; | |
378 | of_node_put(parent); | |
379 | } | |
017e0fad | 380 | #endif |
463ce0e1 BH |
381 | |
382 | DBG("legacy_serial_console = %d\n", legacy_serial_console); | |
37a801c7 MN |
383 | if (legacy_serial_console >= 0) |
384 | setup_legacy_serial_console(legacy_serial_console); | |
463ce0e1 BH |
385 | DBG(" <- find_legacy_serial_port()\n"); |
386 | } | |
387 | ||
388 | static struct platform_device serial_device = { | |
389 | .name = "serial8250", | |
390 | .id = PLAT8250_DEV_PLATFORM, | |
391 | .dev = { | |
392 | .platform_data = legacy_serial_ports, | |
393 | }, | |
394 | }; | |
395 | ||
396 | static void __init fixup_port_irq(int index, | |
397 | struct device_node *np, | |
398 | struct plat_serial8250_port *port) | |
399 | { | |
0ebfff14 BH |
400 | unsigned int virq; |
401 | ||
463ce0e1 BH |
402 | DBG("fixup_port_irq(%d)\n", index); |
403 | ||
0ebfff14 BH |
404 | virq = irq_of_parse_and_map(np, 0); |
405 | if (virq == NO_IRQ && legacy_serial_infos[index].irq_check_parent) { | |
406 | np = of_get_parent(np); | |
407 | if (np == NULL) | |
408 | return; | |
409 | virq = irq_of_parse_and_map(np, 0); | |
410 | of_node_put(np); | |
463ce0e1 | 411 | } |
0ebfff14 | 412 | if (virq == NO_IRQ) |
463ce0e1 BH |
413 | return; |
414 | ||
0ebfff14 | 415 | port->irq = virq; |
463ce0e1 BH |
416 | } |
417 | ||
418 | static void __init fixup_port_pio(int index, | |
419 | struct device_node *np, | |
420 | struct plat_serial8250_port *port) | |
421 | { | |
017e0fad | 422 | #ifdef CONFIG_PCI |
463ce0e1 BH |
423 | struct pci_controller *hose; |
424 | ||
425 | DBG("fixup_port_pio(%d)\n", index); | |
426 | ||
427 | hose = pci_find_hose_for_OF_device(np); | |
428 | if (hose) { | |
429 | unsigned long offset = (unsigned long)hose->io_base_virt - | |
430 | #ifdef CONFIG_PPC64 | |
431 | pci_io_base; | |
432 | #else | |
433 | isa_io_base; | |
434 | #endif | |
435 | DBG("port %d, IO %lx -> %lx\n", | |
436 | index, port->iobase, port->iobase + offset); | |
437 | port->iobase += offset; | |
438 | } | |
017e0fad | 439 | #endif |
463ce0e1 BH |
440 | } |
441 | ||
8dacaedf BH |
442 | static void __init fixup_port_mmio(int index, |
443 | struct device_node *np, | |
444 | struct plat_serial8250_port *port) | |
445 | { | |
446 | DBG("fixup_port_mmio(%d)\n", index); | |
447 | ||
448 | port->membase = ioremap(port->mapbase, 0x100); | |
449 | } | |
450 | ||
463ce0e1 BH |
451 | /* |
452 | * This is called as an arch initcall, hopefully before the PCI bus is | |
453 | * probed and/or the 8250 driver loaded since we need to register our | |
454 | * platform devices before 8250 PCI ones are detected as some of them | |
455 | * must properly "override" the platform ones. | |
456 | * | |
457 | * This function fixes up the interrupt value for platform ports as it | |
458 | * couldn't be done earlier before interrupt maps have been parsed. It | |
459 | * also "corrects" the IO address for PIO ports for the same reason, | |
460 | * since earlier, the PHBs virtual IO space wasn't assigned yet. It then | |
461 | * registers all those platform ports for use by the 8250 driver when it | |
462 | * finally loads. | |
463 | */ | |
464 | static int __init serial_dev_init(void) | |
465 | { | |
466 | int i; | |
467 | ||
468 | if (legacy_serial_count == 0) | |
469 | return -ENODEV; | |
470 | ||
471 | /* | |
472 | * Before we register the platfrom serial devices, we need | |
00d70419 | 473 | * to fixup their interrupts and their IO ports. |
463ce0e1 BH |
474 | */ |
475 | DBG("Fixing serial ports interrupts and IO ports ...\n"); | |
476 | ||
477 | for (i = 0; i < legacy_serial_count; i++) { | |
478 | struct plat_serial8250_port *port = &legacy_serial_ports[i]; | |
479 | struct device_node *np = legacy_serial_infos[i].np; | |
480 | ||
481 | if (port->irq == NO_IRQ) | |
482 | fixup_port_irq(i, np, port); | |
483 | if (port->iotype == UPIO_PORT) | |
484 | fixup_port_pio(i, np, port); | |
be9633e9 | 485 | if ((port->iotype == UPIO_MEM) || (port->iotype == UPIO_TSI)) |
8dacaedf | 486 | fixup_port_mmio(i, np, port); |
463ce0e1 BH |
487 | } |
488 | ||
489 | DBG("Registering platform serial ports\n"); | |
490 | ||
491 | return platform_device_register(&serial_device); | |
492 | } | |
ee56c474 | 493 | device_initcall(serial_dev_init); |
463ce0e1 BH |
494 | |
495 | ||
025d7917 | 496 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
463ce0e1 BH |
497 | /* |
498 | * This is called very early, as part of console_init() (typically just after | |
499 | * time_init()). This function is respondible for trying to find a good | |
500 | * default console on serial ports. It tries to match the open firmware | |
025d7917 BH |
501 | * default output with one of the available serial console drivers that have |
502 | * been probed earlier by find_legacy_serial_ports() | |
463ce0e1 BH |
503 | */ |
504 | static int __init check_legacy_serial_console(void) | |
505 | { | |
506 | struct device_node *prom_stdout = NULL; | |
025d7917 | 507 | int i, speed = 0, offset = 0; |
a7f67bdf JK |
508 | const char *name; |
509 | const u32 *spd; | |
463ce0e1 BH |
510 | |
511 | DBG(" -> check_legacy_serial_console()\n"); | |
512 | ||
513 | /* The user has requested a console so this is already set up. */ | |
b8757b21 | 514 | if (strstr(boot_command_line, "console=")) { |
463ce0e1 BH |
515 | DBG(" console was specified !\n"); |
516 | return -EBUSY; | |
517 | } | |
518 | ||
519 | if (!of_chosen) { | |
520 | DBG(" of_chosen is NULL !\n"); | |
521 | return -ENODEV; | |
522 | } | |
b580d46c KG |
523 | |
524 | if (legacy_serial_console < 0) { | |
525 | DBG(" legacy_serial_console not found !\n"); | |
526 | return -ENODEV; | |
527 | } | |
463ce0e1 BH |
528 | /* We are getting a weird phandle from OF ... */ |
529 | /* ... So use the full path instead */ | |
e2eb6392 | 530 | name = of_get_property(of_chosen, "linux,stdout-path", NULL); |
463ce0e1 BH |
531 | if (name == NULL) { |
532 | DBG(" no linux,stdout-path !\n"); | |
533 | return -ENODEV; | |
534 | } | |
535 | prom_stdout = of_find_node_by_path(name); | |
536 | if (!prom_stdout) { | |
537 | DBG(" can't find stdout package %s !\n", name); | |
538 | return -ENODEV; | |
539 | } | |
540 | DBG("stdout is %s\n", prom_stdout->full_name); | |
541 | ||
e2eb6392 | 542 | name = of_get_property(prom_stdout, "name", NULL); |
463ce0e1 BH |
543 | if (!name) { |
544 | DBG(" stdout package has no name !\n"); | |
545 | goto not_found; | |
546 | } | |
e2eb6392 | 547 | spd = of_get_property(prom_stdout, "current-speed", NULL); |
463ce0e1 BH |
548 | if (spd) |
549 | speed = *spd; | |
550 | ||
025d7917 BH |
551 | if (strcmp(name, "serial") != 0) |
552 | goto not_found; | |
553 | ||
554 | /* Look for it in probed array */ | |
555 | for (i = 0; i < legacy_serial_count; i++) { | |
556 | if (prom_stdout != legacy_serial_infos[i].np) | |
557 | continue; | |
558 | offset = i; | |
559 | speed = legacy_serial_infos[i].speed; | |
560 | break; | |
463ce0e1 | 561 | } |
025d7917 | 562 | if (i >= legacy_serial_count) |
463ce0e1 | 563 | goto not_found; |
025d7917 | 564 | |
463ce0e1 BH |
565 | of_node_put(prom_stdout); |
566 | ||
567 | DBG("Found serial console at ttyS%d\n", offset); | |
568 | ||
569 | if (speed) { | |
570 | static char __initdata opt[16]; | |
571 | sprintf(opt, "%d", speed); | |
572 | return add_preferred_console("ttyS", offset, opt); | |
573 | } else | |
574 | return add_preferred_console("ttyS", offset, NULL); | |
575 | ||
576 | not_found: | |
577 | DBG("No preferred console found !\n"); | |
578 | of_node_put(prom_stdout); | |
579 | return -ENODEV; | |
580 | } | |
581 | console_initcall(check_legacy_serial_console); | |
582 | ||
025d7917 | 583 | #endif /* CONFIG_SERIAL_8250_CONSOLE */ |