1 #include <linux/kernel.h>
2 #include <linux/serial.h>
4 #include <linux/serial_core.h>
13 #include <asm/serial.h>
15 #include <asm/pci-bridge.h>
21 #define DBG(fmt...) do { printk(fmt); } while(0)
23 #define DBG(fmt...) do { } while(0)
26 #define MAX_LEGACY_SERIAL_PORTS 8
30 static struct legacy_serial_info {
40 {.type =
"tsi-bridge",},
42 {.compatible =
"ibm,opb",},
43 {.compatible =
"simple-bus",},
44 {.compatible =
"wrs,epld-localbus",},
48 static unsigned int legacy_serial_count;
49 static int legacy_serial_console = -1;
57 return (tmp >> 16) & 0xff;
62 static void tsi_serial_out(
struct uart_port *p,
int offset,
int value)
90 index = legacy_serial_count;
98 if (index >= legacy_serial_count)
99 legacy_serial_count = index + 1;
102 if (legacy_serial_infos[index].np != 0) {
106 index, legacy_serial_count);
107 legacy_serial_ports[legacy_serial_count] =
108 legacy_serial_ports[
index];
109 legacy_serial_infos[legacy_serial_count] =
110 legacy_serial_infos[
index];
111 legacy_serial_count++;
118 memset(&legacy_serial_ports[index], 0,
121 legacy_serial_ports[
index].iobase = base;
123 legacy_serial_ports[
index].mapbase = base;
125 legacy_serial_ports[
index].iotype = iotype;
127 legacy_serial_ports[
index].irq = irq;
129 legacy_serial_infos[
index].taddr = taddr;
130 legacy_serial_infos[
index].np = of_node_get(np);
133 legacy_serial_infos[
index].irq_check_parent = irq_check_parent;
136 legacy_serial_ports[
index].serial_in = tsi_serial_in;
137 legacy_serial_ports[
index].serial_out = tsi_serial_out;
144 (
unsigned long long)base, (
unsigned long long)taddr, irq,
145 legacy_serial_ports[index].uartclk,
146 legacy_serial_infos[index].speed);
181 if (addr == OF_BAD_ADDR)
188 return add_legacy_port(np, -1,
UPIO_TSI, addr, addr,
NO_IRQ, flags, 0);
190 return add_legacy_port(np, -1,
UPIO_MEM, addr, addr,
NO_IRQ, flags, 0);
218 if (typep && *typep ==
'S')
226 if (taddr == OF_BAD_ADDR)
242 int iotype, index = -1, lindex = 0;
257 addrp = of_get_pci_address(pci_dev, 0,
NULL, &flags);
264 if (addr == OF_BAD_ADDR)
293 addr += 0x200 * lindex;
294 base += 0x200 * lindex;
303 return add_legacy_port(np, index, iotype, base, addr,
NO_IRQ,
310 struct legacy_serial_info *
info =
314 if (info->taddr == 0)
316 addr =
ioremap(info->taddr, 0x1000);
319 if (info->speed == 0)
321 DBG(
"default console speed = %d\n", info->speed);
340 DBG(
" -> find_legacy_serial_port()\n");
349 DBG(
" no linux,stdout-path !\n");
353 for_each_compatible_node(np,
"serial",
"ns16550") {
359 index = add_legacy_soc_port(np, np);
360 if (index >= 0 && np == stdout)
361 legacy_serial_console =
index;
368 for_each_node_by_type(np,
"serial") {
371 index = add_legacy_isa_port(np, isa);
372 if (index >= 0 && np == stdout)
373 legacy_serial_console =
index;
403 index = add_legacy_pci_port(np, pci);
404 if (index >= 0 && np == stdout)
405 legacy_serial_console =
index;
410 DBG(
"legacy_serial_console = %d\n", legacy_serial_console);
411 if (legacy_serial_console >= 0)
412 setup_legacy_serial_console(legacy_serial_console);
413 DBG(
" <- find_legacy_serial_port()\n");
417 .name =
"serial8250",
420 .platform_data = legacy_serial_ports,
424 static void __init fixup_port_irq(
int index,
430 DBG(
"fixup_port_irq(%d)\n", index);
433 if (virq ==
NO_IRQ && legacy_serial_infos[index].irq_check_parent) {
445 #ifdef CONFIG_SERIAL_8250_FSL
451 static void __init fixup_port_pio(
int index,
458 DBG(
"fixup_port_pio(%d)\n", index);
462 unsigned long offset = (
unsigned long)hose->io_base_virt -
468 DBG(
"port %d, IO %lx -> %lx\n",
475 static void __init fixup_port_mmio(
int index,
479 DBG(
"fixup_port_mmio(%d)\n", index);
497 static int __init serial_dev_init(
void)
501 if (legacy_serial_count == 0)
508 DBG(
"Fixing serial ports interrupts and IO ports ...\n");
510 for (i = 0; i < legacy_serial_count; i++) {
515 fixup_port_irq(i, np, port);
517 fixup_port_pio(i, np, port);
519 fixup_port_mmio(i, np, port);
522 DBG(
"Registering platform serial ports\n");
529 #ifdef CONFIG_SERIAL_8250_CONSOLE
537 static int __init check_legacy_serial_console(
void)
540 int i,
speed = 0, offset = 0;
544 DBG(
" -> check_legacy_serial_console()\n");
548 DBG(
" console was specified !\n");
553 DBG(
" of_chosen is NULL !\n");
557 if (legacy_serial_console < 0) {
558 DBG(
" legacy_serial_console not found !\n");
565 DBG(
" no linux,stdout-path !\n");
570 DBG(
" can't find stdout package %s !\n", name);
577 DBG(
" stdout package has no name !\n");
584 if (
strcmp(name,
"serial") != 0)
588 for (i = 0; i < legacy_serial_count; i++) {
589 if (prom_stdout != legacy_serial_infos[i].np)
592 speed = legacy_serial_infos[
i].speed;
595 if (i >= legacy_serial_count)
598 of_node_put(prom_stdout);
600 DBG(
"Found serial console at ttyS%d\n", offset);
610 DBG(
"No preferred console found !\n");
611 of_node_put(prom_stdout);