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