blob: 40a39291861f2d5b1c9f03f8100e37089bda97d5 [file] [log] [blame]
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +11001#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>
7#include <asm/io.h>
8#include <asm/mmu.h>
9#include <asm/prom.h>
10#include <asm/serial.h>
11#include <asm/udbg.h>
12#include <asm/pci-bridge.h>
13#include <asm/ppc-pci.h>
14
15#undef DEBUG
16
17#ifdef DEBUG
18#define DBG(fmt...) do { printk(fmt); } while(0)
19#else
20#define DBG(fmt...) do { } while(0)
21#endif
22
23#define MAX_LEGACY_SERIAL_PORTS 8
24
25static struct plat_serial8250_port
26legacy_serial_ports[MAX_LEGACY_SERIAL_PORTS+1];
27static struct legacy_serial_info {
28 struct device_node *np;
29 unsigned int speed;
30 unsigned int clock;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100031 int irq_check_parent;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110032 phys_addr_t taddr;
33} legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
34static unsigned int legacy_serial_count;
35static int legacy_serial_console = -1;
36
37static int __init add_legacy_port(struct device_node *np, int want_index,
38 int iotype, phys_addr_t base,
Kumar Galab580d462005-12-20 16:16:52 -060039 phys_addr_t taddr, unsigned long irq,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100040 upf_t flags, int irq_check_parent)
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110041{
Benjamin Herrenschmidt8dacaed2005-11-29 11:21:59 +110042 u32 *clk, *spd, clock = BASE_BAUD * 16;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110043 int index;
44
45 /* get clock freq. if present */
46 clk = (u32 *)get_property(np, "clock-frequency", NULL);
David Woodhouse31df1672005-11-24 17:08:56 +000047 if (clk && *clk)
48 clock = *clk;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110049
50 /* get default speed if present */
51 spd = (u32 *)get_property(np, "current-speed", NULL);
52
53 /* If we have a location index, then try to use it */
54 if (want_index >= 0 && want_index < MAX_LEGACY_SERIAL_PORTS)
55 index = want_index;
56 else
57 index = legacy_serial_count;
58
59 /* if our index is still out of range, that mean that
60 * array is full, we could scan for a free slot but that
61 * make little sense to bother, just skip the port
62 */
63 if (index >= MAX_LEGACY_SERIAL_PORTS)
64 return -1;
65 if (index >= legacy_serial_count)
66 legacy_serial_count = index + 1;
67
68 /* Check if there is a port who already claimed our slot */
69 if (legacy_serial_infos[index].np != 0) {
70 /* if we still have some room, move it, else override */
71 if (legacy_serial_count < MAX_LEGACY_SERIAL_PORTS) {
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100072 printk(KERN_DEBUG "Moved legacy port %d -> %d\n",
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110073 index, legacy_serial_count);
74 legacy_serial_ports[legacy_serial_count] =
75 legacy_serial_ports[index];
76 legacy_serial_infos[legacy_serial_count] =
77 legacy_serial_infos[index];
78 legacy_serial_count++;
79 } else {
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100080 printk(KERN_DEBUG "Replacing legacy port %d\n", index);
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110081 }
82 }
83
84 /* Now fill the entry */
85 memset(&legacy_serial_ports[index], 0,
86 sizeof(struct plat_serial8250_port));
87 if (iotype == UPIO_PORT)
88 legacy_serial_ports[index].iobase = base;
89 else
Benjamin Herrenschmidt8dacaed2005-11-29 11:21:59 +110090 legacy_serial_ports[index].mapbase = base;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110091 legacy_serial_ports[index].iotype = iotype;
92 legacy_serial_ports[index].uartclk = clock;
93 legacy_serial_ports[index].irq = irq;
Kumar Galab580d462005-12-20 16:16:52 -060094 legacy_serial_ports[index].flags = flags;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110095 legacy_serial_infos[index].taddr = taddr;
96 legacy_serial_infos[index].np = of_node_get(np);
97 legacy_serial_infos[index].clock = clock;
98 legacy_serial_infos[index].speed = spd ? *spd : 0;
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100099 legacy_serial_infos[index].irq_check_parent = irq_check_parent;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100100
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000101 printk(KERN_DEBUG "Found legacy serial port %d for %s\n",
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100102 index, np->full_name);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000103 printk(KERN_DEBUG " %s=%llx, taddr=%llx, irq=%lx, clk=%d, speed=%d\n",
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100104 (iotype == UPIO_PORT) ? "port" : "mem",
105 (unsigned long long)base, (unsigned long long)taddr, irq,
106 legacy_serial_ports[index].uartclk,
107 legacy_serial_infos[index].speed);
108
109 return index;
110}
111
Kumar Galab580d462005-12-20 16:16:52 -0600112static int __init add_legacy_soc_port(struct device_node *np,
113 struct device_node *soc_dev)
114{
Benjamin Herrenschmidt45507ff2006-07-04 14:14:07 +1000115 u64 addr;
Kumar Galab580d462005-12-20 16:16:52 -0600116 u32 *addrp;
Stephen Rothwellaf308372006-03-23 17:38:10 +1100117 upf_t flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ;
Zang Roy-r61911be9633e2006-08-23 10:20:27 +0800118 struct device_node *tsi = of_get_parent(np);
Kumar Galab580d462005-12-20 16:16:52 -0600119
120 /* We only support ports that have a clock frequency properly
121 * encoded in the device-tree.
122 */
123 if (get_property(np, "clock-frequency", NULL) == NULL)
124 return -1;
125
126 /* Get the address */
127 addrp = of_get_address(soc_dev, 0, NULL, NULL);
128 if (addrp == NULL)
129 return -1;
130
131 addr = of_translate_address(soc_dev, addrp);
Benjamin Herrenschmidt7c6efda2006-07-03 17:24:15 +1000132 if (addr == OF_BAD_ADDR)
133 return -1;
Kumar Galab580d462005-12-20 16:16:52 -0600134
135 /* Add port, irq will be dealt with later. We passed a translated
136 * IO port value. It will be fixed up later along with the irq
137 */
Zang Roy-r61911be9633e2006-08-23 10:20:27 +0800138 if (tsi && !strcmp(tsi->type, "tsi-bridge"))
139 return add_legacy_port(np, -1, UPIO_TSI, addr, addr, NO_IRQ, flags, 0);
140 else
141 return add_legacy_port(np, -1, UPIO_MEM, addr, addr, NO_IRQ, flags, 0);
Kumar Galab580d462005-12-20 16:16:52 -0600142}
143
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100144static int __init add_legacy_isa_port(struct device_node *np,
Kumar Gala017e0fa2006-01-03 16:15:21 -0600145 struct device_node *isa_brg)
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100146{
147 u32 *reg;
148 char *typep;
149 int index = -1;
Benjamin Herrenschmidt45507ff2006-07-04 14:14:07 +1000150 u64 taddr;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100151
Benjamin Herrenschmidt7c6efda2006-07-03 17:24:15 +1000152 DBG(" -> add_legacy_isa_port(%s)\n", np->full_name);
153
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100154 /* Get the ISA port number */
155 reg = (u32 *)get_property(np, "reg", NULL);
156 if (reg == NULL)
157 return -1;
158
159 /* Verify it's an IO port, we don't support anything else */
160 if (!(reg[0] & 0x00000001))
161 return -1;
162
163 /* Now look for an "ibm,aix-loc" property that gives us ordering
164 * if any...
165 */
166 typep = (char *)get_property(np, "ibm,aix-loc", NULL);
167
168 /* If we have a location index, then use it */
169 if (typep && *typep == 'S')
170 index = simple_strtol(typep+1, NULL, 0) - 1;
171
Benjamin Herrenschmidt45507ff2006-07-04 14:14:07 +1000172 /* Translate ISA address. If it fails, we still register the port
173 * with no translated address so that it can be picked up as an IO
174 * port later by the serial driver
175 */
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100176 taddr = of_translate_address(np, reg);
Benjamin Herrenschmidt7c6efda2006-07-03 17:24:15 +1000177 if (taddr == OF_BAD_ADDR)
Benjamin Herrenschmidt45507ff2006-07-04 14:14:07 +1000178 taddr = 0;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100179
180 /* Add port, irq will be dealt with later */
Benjamin Herrenschmidt7c6efda2006-07-03 17:24:15 +1000181 return add_legacy_port(np, index, UPIO_PORT, reg[1], taddr,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000182 NO_IRQ, UPF_BOOT_AUTOCONF, 0);
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100183
184}
185
Kumar Gala017e0fa2006-01-03 16:15:21 -0600186#ifdef CONFIG_PCI
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100187static int __init add_legacy_pci_port(struct device_node *np,
188 struct device_node *pci_dev)
189{
Benjamin Herrenschmidt45507ff2006-07-04 14:14:07 +1000190 u64 addr, base;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100191 u32 *addrp;
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +1100192 unsigned int flags;
Benjamin Herrenschmidt8dacaed2005-11-29 11:21:59 +1100193 int iotype, index = -1, lindex = 0;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100194
Benjamin Herrenschmidt7c6efda2006-07-03 17:24:15 +1000195 DBG(" -> add_legacy_pci_port(%s)\n", np->full_name);
196
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100197 /* We only support ports that have a clock frequency properly
198 * encoded in the device-tree (that is have an fcode). Anything
199 * else can't be used that early and will be normally probed by
Benjamin Herrenschmidt8dacaed2005-11-29 11:21:59 +1100200 * the generic 8250_pci driver later on. The reason is that 8250
201 * compatible UARTs on PCI need all sort of quirks (port offsets
202 * etc...) that this code doesn't know about
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100203 */
204 if (get_property(np, "clock-frequency", NULL) == NULL)
205 return -1;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100206
207 /* Get the PCI address. Assume BAR 0 */
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +1100208 addrp = of_get_pci_address(pci_dev, 0, NULL, &flags);
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100209 if (addrp == NULL)
210 return -1;
211
212 /* We only support BAR 0 for now */
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +1100213 iotype = (flags & IORESOURCE_MEM) ? UPIO_MEM : UPIO_PORT;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100214 addr = of_translate_address(pci_dev, addrp);
Benjamin Herrenschmidt7c6efda2006-07-03 17:24:15 +1000215 if (addr == OF_BAD_ADDR)
216 return -1;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100217
218 /* Set the IO base to the same as the translated address for MMIO,
219 * or to the domain local IO base for PIO (it will be fixed up later)
220 */
221 if (iotype == UPIO_MEM)
222 base = addr;
223 else
224 base = addrp[2];
225
226 /* Try to guess an index... If we have subdevices of the pci dev,
227 * we get to their "reg" property
228 */
229 if (np != pci_dev) {
230 u32 *reg = (u32 *)get_property(np, "reg", NULL);
231 if (reg && (*reg < 4))
Benjamin Herrenschmidt8dacaed2005-11-29 11:21:59 +1100232 index = lindex = *reg;
233 }
234
235 /* Local index means it's the Nth port in the PCI chip. Unfortunately
236 * the offset to add here is device specific. We know about those
237 * EXAR ports and we default to the most common case. If your UART
238 * doesn't work for these settings, you'll have to add your own special
239 * cases here
240 */
241 if (device_is_compatible(pci_dev, "pci13a8,152") ||
242 device_is_compatible(pci_dev, "pci13a8,154") ||
243 device_is_compatible(pci_dev, "pci13a8,158")) {
244 addr += 0x200 * lindex;
245 base += 0x200 * lindex;
246 } else {
247 addr += 8 * lindex;
248 base += 8 * lindex;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100249 }
250
251 /* Add port, irq will be dealt with later. We passed a translated
252 * IO port value. It will be fixed up later along with the irq
253 */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000254 return add_legacy_port(np, index, iotype, base, addr, NO_IRQ,
255 UPF_BOOT_AUTOCONF, np != pci_dev);
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100256}
Kumar Gala017e0fa2006-01-03 16:15:21 -0600257#endif
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100258
Michael Neuling37a801c2006-03-26 10:07:35 +1000259static void __init setup_legacy_serial_console(int console)
260{
261 struct legacy_serial_info *info =
262 &legacy_serial_infos[console];
263 void __iomem *addr;
264
265 if (info->taddr == 0)
266 return;
267 addr = ioremap(info->taddr, 0x1000);
268 if (addr == NULL)
269 return;
270 if (info->speed == 0)
271 info->speed = udbg_probe_uart_speed(addr, info->clock);
272 DBG("default console speed = %d\n", info->speed);
273 udbg_init_uart(addr, info->speed, info->clock);
274}
275
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100276/*
277 * This is called very early, as part of setup_system() or eventually
278 * setup_arch(), basically before anything else in this file. This function
279 * will try to build a list of all the available 8250-compatible serial ports
280 * in the machine using the Open Firmware device-tree. It currently only deals
281 * with ISA and PCI busses but could be extended. It allows a very early boot
282 * console to be initialized, that list is also used later to provide 8250 with
283 * the machine non-PCI ports and to properly pick the default console port
284 */
285void __init find_legacy_serial_ports(void)
286{
Kumar Galab580d462005-12-20 16:16:52 -0600287 struct device_node *np, *stdout = NULL;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100288 char *path;
289 int index;
290
291 DBG(" -> find_legacy_serial_port()\n");
292
293 /* Now find out if one of these is out firmware console */
294 path = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
Kumar Galab580d462005-12-20 16:16:52 -0600295 if (path != NULL) {
296 stdout = of_find_node_by_path(path);
297 if (stdout)
298 DBG("stdout is %s\n", stdout->full_name);
299 } else {
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100300 DBG(" no linux,stdout-path !\n");
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100301 }
Kumar Galab580d462005-12-20 16:16:52 -0600302
303 /* First fill our array with SOC ports */
304 for (np = NULL; (np = of_find_compatible_node(np, "serial", "ns16550")) != NULL;) {
305 struct device_node *soc = of_get_parent(np);
306 if (soc && !strcmp(soc->type, "soc")) {
307 index = add_legacy_soc_port(np, np);
308 if (index >= 0 && np == stdout)
309 legacy_serial_console = index;
310 }
311 of_node_put(soc);
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100312 }
313
314 /* First fill our array with ISA ports */
315 for (np = NULL; (np = of_find_node_by_type(np, "serial"));) {
316 struct device_node *isa = of_get_parent(np);
317 if (isa && !strcmp(isa->name, "isa")) {
318 index = add_legacy_isa_port(np, isa);
319 if (index >= 0 && np == stdout)
320 legacy_serial_console = index;
321 }
322 of_node_put(isa);
323 }
324
Zang Roy-r61911c5d56332006-06-13 15:07:15 +0800325 /* First fill our array with tsi-bridge ports */
326 for (np = NULL; (np = of_find_compatible_node(np, "serial", "ns16550")) != NULL;) {
327 struct device_node *tsi = of_get_parent(np);
328 if (tsi && !strcmp(tsi->type, "tsi-bridge")) {
329 index = add_legacy_soc_port(np, np);
330 if (index >= 0 && np == stdout)
331 legacy_serial_console = index;
332 }
333 of_node_put(tsi);
334 }
335
Kumar Gala017e0fa2006-01-03 16:15:21 -0600336#ifdef CONFIG_PCI
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100337 /* Next, try to locate PCI ports */
338 for (np = NULL; (np = of_find_all_nodes(np));) {
339 struct device_node *pci, *parent = of_get_parent(np);
340 if (parent && !strcmp(parent->name, "isa")) {
341 of_node_put(parent);
342 continue;
343 }
344 if (strcmp(np->name, "serial") && strcmp(np->type, "serial")) {
345 of_node_put(parent);
346 continue;
347 }
348 /* Check for known pciclass, and also check wether we have
349 * a device with child nodes for ports or not
350 */
351 if (device_is_compatible(np, "pciclass,0700") ||
352 device_is_compatible(np, "pciclass,070002"))
353 pci = np;
354 else if (device_is_compatible(parent, "pciclass,0700") ||
355 device_is_compatible(parent, "pciclass,070002"))
356 pci = parent;
357 else {
358 of_node_put(parent);
359 continue;
360 }
361 index = add_legacy_pci_port(np, pci);
362 if (index >= 0 && np == stdout)
363 legacy_serial_console = index;
364 of_node_put(parent);
365 }
Kumar Gala017e0fa2006-01-03 16:15:21 -0600366#endif
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100367
368 DBG("legacy_serial_console = %d\n", legacy_serial_console);
Michael Neuling37a801c2006-03-26 10:07:35 +1000369 if (legacy_serial_console >= 0)
370 setup_legacy_serial_console(legacy_serial_console);
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100371 DBG(" <- find_legacy_serial_port()\n");
372}
373
374static struct platform_device serial_device = {
375 .name = "serial8250",
376 .id = PLAT8250_DEV_PLATFORM,
377 .dev = {
378 .platform_data = legacy_serial_ports,
379 },
380};
381
382static void __init fixup_port_irq(int index,
383 struct device_node *np,
384 struct plat_serial8250_port *port)
385{
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000386 unsigned int virq;
387
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100388 DBG("fixup_port_irq(%d)\n", index);
389
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000390 virq = irq_of_parse_and_map(np, 0);
391 if (virq == NO_IRQ && legacy_serial_infos[index].irq_check_parent) {
392 np = of_get_parent(np);
393 if (np == NULL)
394 return;
395 virq = irq_of_parse_and_map(np, 0);
396 of_node_put(np);
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100397 }
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000398 if (virq == NO_IRQ)
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100399 return;
400
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000401 port->irq = virq;
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100402}
403
404static void __init fixup_port_pio(int index,
405 struct device_node *np,
406 struct plat_serial8250_port *port)
407{
Kumar Gala017e0fa2006-01-03 16:15:21 -0600408#ifdef CONFIG_PCI
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100409 struct pci_controller *hose;
410
411 DBG("fixup_port_pio(%d)\n", index);
412
413 hose = pci_find_hose_for_OF_device(np);
414 if (hose) {
415 unsigned long offset = (unsigned long)hose->io_base_virt -
416#ifdef CONFIG_PPC64
417 pci_io_base;
418#else
419 isa_io_base;
420#endif
421 DBG("port %d, IO %lx -> %lx\n",
422 index, port->iobase, port->iobase + offset);
423 port->iobase += offset;
424 }
Kumar Gala017e0fa2006-01-03 16:15:21 -0600425#endif
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100426}
427
Benjamin Herrenschmidt8dacaed2005-11-29 11:21:59 +1100428static void __init fixup_port_mmio(int index,
429 struct device_node *np,
430 struct plat_serial8250_port *port)
431{
432 DBG("fixup_port_mmio(%d)\n", index);
433
434 port->membase = ioremap(port->mapbase, 0x100);
435}
436
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100437/*
438 * This is called as an arch initcall, hopefully before the PCI bus is
439 * probed and/or the 8250 driver loaded since we need to register our
440 * platform devices before 8250 PCI ones are detected as some of them
441 * must properly "override" the platform ones.
442 *
443 * This function fixes up the interrupt value for platform ports as it
444 * couldn't be done earlier before interrupt maps have been parsed. It
445 * also "corrects" the IO address for PIO ports for the same reason,
446 * since earlier, the PHBs virtual IO space wasn't assigned yet. It then
447 * registers all those platform ports for use by the 8250 driver when it
448 * finally loads.
449 */
450static int __init serial_dev_init(void)
451{
452 int i;
453
454 if (legacy_serial_count == 0)
455 return -ENODEV;
456
457 /*
458 * Before we register the platfrom serial devices, we need
459 * to fixup their interrutps and their IO ports.
460 */
461 DBG("Fixing serial ports interrupts and IO ports ...\n");
462
463 for (i = 0; i < legacy_serial_count; i++) {
464 struct plat_serial8250_port *port = &legacy_serial_ports[i];
465 struct device_node *np = legacy_serial_infos[i].np;
466
467 if (port->irq == NO_IRQ)
468 fixup_port_irq(i, np, port);
469 if (port->iotype == UPIO_PORT)
470 fixup_port_pio(i, np, port);
Zang Roy-r61911be9633e2006-08-23 10:20:27 +0800471 if ((port->iotype == UPIO_MEM) || (port->iotype == UPIO_TSI))
Benjamin Herrenschmidt8dacaed2005-11-29 11:21:59 +1100472 fixup_port_mmio(i, np, port);
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100473 }
474
475 DBG("Registering platform serial ports\n");
476
477 return platform_device_register(&serial_device);
478}
479arch_initcall(serial_dev_init);
480
481
482/*
483 * This is called very early, as part of console_init() (typically just after
484 * time_init()). This function is respondible for trying to find a good
485 * default console on serial ports. It tries to match the open firmware
486 * default output with one of the available serial console drivers, either
487 * one of the platform serial ports that have been probed earlier by
488 * find_legacy_serial_ports() or some more platform specific ones.
489 */
490static int __init check_legacy_serial_console(void)
491{
492 struct device_node *prom_stdout = NULL;
493 int speed = 0, offset = 0;
494 char *name;
495 u32 *spd;
496
497 DBG(" -> check_legacy_serial_console()\n");
498
499 /* The user has requested a console so this is already set up. */
500 if (strstr(saved_command_line, "console=")) {
501 DBG(" console was specified !\n");
502 return -EBUSY;
503 }
504
505 if (!of_chosen) {
506 DBG(" of_chosen is NULL !\n");
507 return -ENODEV;
508 }
Kumar Galab580d462005-12-20 16:16:52 -0600509
510 if (legacy_serial_console < 0) {
511 DBG(" legacy_serial_console not found !\n");
512 return -ENODEV;
513 }
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100514 /* We are getting a weird phandle from OF ... */
515 /* ... So use the full path instead */
516 name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
517 if (name == NULL) {
518 DBG(" no linux,stdout-path !\n");
519 return -ENODEV;
520 }
521 prom_stdout = of_find_node_by_path(name);
522 if (!prom_stdout) {
523 DBG(" can't find stdout package %s !\n", name);
524 return -ENODEV;
525 }
526 DBG("stdout is %s\n", prom_stdout->full_name);
527
528 name = (char *)get_property(prom_stdout, "name", NULL);
529 if (!name) {
530 DBG(" stdout package has no name !\n");
531 goto not_found;
532 }
533 spd = (u32 *)get_property(prom_stdout, "current-speed", NULL);
534 if (spd)
535 speed = *spd;
536
537 if (0)
538 ;
539#ifdef CONFIG_SERIAL_8250_CONSOLE
540 else if (strcmp(name, "serial") == 0) {
541 int i;
542 /* Look for it in probed array */
543 for (i = 0; i < legacy_serial_count; i++) {
544 if (prom_stdout != legacy_serial_infos[i].np)
545 continue;
546 offset = i;
547 speed = legacy_serial_infos[i].speed;
548 break;
549 }
550 if (i >= legacy_serial_count)
551 goto not_found;
552 }
553#endif /* CONFIG_SERIAL_8250_CONSOLE */
554#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
555 else if (strcmp(name, "ch-a") == 0)
556 offset = 0;
557 else if (strcmp(name, "ch-b") == 0)
558 offset = 1;
559#endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */
560 else
561 goto not_found;
562 of_node_put(prom_stdout);
563
564 DBG("Found serial console at ttyS%d\n", offset);
565
566 if (speed) {
567 static char __initdata opt[16];
568 sprintf(opt, "%d", speed);
569 return add_preferred_console("ttyS", offset, opt);
570 } else
571 return add_preferred_console("ttyS", offset, NULL);
572
573 not_found:
574 DBG("No preferred console found !\n");
575 of_node_put(prom_stdout);
576 return -ENODEV;
577}
578console_initcall(check_legacy_serial_console);
579