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