David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 1 | #include <linux/string.h> |
| 2 | #include <linux/kernel.h> |
Stephen Rothwell | f85ff30 | 2007-05-01 16:40:36 +1000 | [diff] [blame] | 3 | #include <linux/of.h> |
David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 4 | #include <linux/init.h> |
David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 5 | #include <linux/mod_devicetable.h> |
| 6 | #include <linux/slab.h> |
Stephen Rothwell | 3f23de1 | 2007-05-03 02:38:57 +1000 | [diff] [blame] | 7 | #include <linux/errno.h> |
Robert Reif | c9f5b7e | 2009-06-04 02:00:02 -0700 | [diff] [blame] | 8 | #include <linux/irq.h> |
Stephen Rothwell | 3f23de1 | 2007-05-03 02:38:57 +1000 | [diff] [blame] | 9 | #include <linux/of_device.h> |
| 10 | #include <linux/of_platform.h> |
Konrad Eisele | e63829d | 2009-08-17 00:13:32 +0000 | [diff] [blame] | 11 | #include <asm/leon.h> |
| 12 | #include <asm/leon_amba.h> |
David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 13 | |
Robert Reif | c9f5b7e | 2009-06-04 02:00:02 -0700 | [diff] [blame] | 14 | #include "of_device_common.h" |
Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 15 | #include "irq.h" |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 16 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 17 | /* |
| 18 | * PCI bus specific translator |
| 19 | */ |
| 20 | |
| 21 | static int of_bus_pci_match(struct device_node *np) |
| 22 | { |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 23 | if (!strcmp(np->type, "pci") || !strcmp(np->type, "pciex")) { |
| 24 | /* Do not do PCI specific frobbing if the |
| 25 | * PCI bridge lacks a ranges property. We |
| 26 | * want to pass it through up to the next |
| 27 | * parent as-is, not with the PCI translate |
| 28 | * method which chops off the top address cell. |
| 29 | */ |
| 30 | if (!of_find_property(np, "ranges", NULL)) |
| 31 | return 0; |
| 32 | |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static void of_bus_pci_count_cells(struct device_node *np, |
| 40 | int *addrc, int *sizec) |
| 41 | { |
| 42 | if (addrc) |
| 43 | *addrc = 3; |
| 44 | if (sizec) |
| 45 | *sizec = 2; |
| 46 | } |
| 47 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 48 | static int of_bus_pci_map(u32 *addr, const u32 *range, |
| 49 | int na, int ns, int pna) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 50 | { |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 51 | u32 result[OF_MAX_ADDR_CELLS]; |
| 52 | int i; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 53 | |
| 54 | /* Check address type match */ |
| 55 | if ((addr[0] ^ range[0]) & 0x03000000) |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 56 | return -EINVAL; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 57 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 58 | if (of_out_of_range(addr + 1, range + 1, range + na + pna, |
| 59 | na - 1, ns)) |
| 60 | return -EINVAL; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 61 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 62 | /* Start with the parent range base. */ |
| 63 | memcpy(result, range + na, pna * 4); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 64 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 65 | /* Add in the child address offset, skipping high cell. */ |
| 66 | for (i = 0; i < na - 1; i++) |
| 67 | result[pna - 1 - i] += |
| 68 | (addr[na - 1 - i] - |
| 69 | range[na - 1 - i]); |
| 70 | |
| 71 | memcpy(addr, result, pna * 4); |
| 72 | |
| 73 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 74 | } |
| 75 | |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 76 | static unsigned long of_bus_pci_get_flags(const u32 *addr, unsigned long flags) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 77 | { |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 78 | u32 w = addr[0]; |
| 79 | |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 80 | /* For PCI, we override whatever child busses may have used. */ |
| 81 | flags = 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 82 | switch((w >> 24) & 0x03) { |
| 83 | case 0x01: |
| 84 | flags |= IORESOURCE_IO; |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 85 | break; |
| 86 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 87 | case 0x02: /* 32 bits */ |
| 88 | case 0x03: /* 64 bits */ |
| 89 | flags |= IORESOURCE_MEM; |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 90 | break; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 91 | } |
| 92 | if (w & 0x40000000) |
| 93 | flags |= IORESOURCE_PREFETCH; |
| 94 | return flags; |
| 95 | } |
| 96 | |
David S. Miller | bdba4d6 | 2008-09-10 23:38:51 -0700 | [diff] [blame] | 97 | static unsigned long of_bus_sbus_get_flags(const u32 *addr, unsigned long flags) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 98 | { |
| 99 | return IORESOURCE_MEM; |
| 100 | } |
| 101 | |
Konrad Eisele | e63829d | 2009-08-17 00:13:32 +0000 | [diff] [blame] | 102 | /* |
| 103 | * AMBAPP bus specific translator |
| 104 | */ |
| 105 | |
| 106 | static int of_bus_ambapp_match(struct device_node *np) |
| 107 | { |
Kristoffer Glembo | d7ecfb3 | 2010-02-15 16:10:28 +0100 | [diff] [blame] | 108 | return !strcmp(np->type, "ambapp"); |
Konrad Eisele | e63829d | 2009-08-17 00:13:32 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static void of_bus_ambapp_count_cells(struct device_node *child, |
| 112 | int *addrc, int *sizec) |
| 113 | { |
| 114 | if (addrc) |
| 115 | *addrc = 1; |
| 116 | if (sizec) |
| 117 | *sizec = 1; |
| 118 | } |
| 119 | |
| 120 | static int of_bus_ambapp_map(u32 *addr, const u32 *range, |
| 121 | int na, int ns, int pna) |
| 122 | { |
| 123 | return of_bus_default_map(addr, range, na, ns, pna); |
| 124 | } |
| 125 | |
| 126 | static unsigned long of_bus_ambapp_get_flags(const u32 *addr, |
| 127 | unsigned long flags) |
| 128 | { |
| 129 | return IORESOURCE_MEM; |
| 130 | } |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Array of bus specific translators |
| 134 | */ |
| 135 | |
| 136 | static struct of_bus of_busses[] = { |
| 137 | /* PCI */ |
| 138 | { |
| 139 | .name = "pci", |
| 140 | .addr_prop_name = "assigned-addresses", |
| 141 | .match = of_bus_pci_match, |
| 142 | .count_cells = of_bus_pci_count_cells, |
| 143 | .map = of_bus_pci_map, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 144 | .get_flags = of_bus_pci_get_flags, |
| 145 | }, |
| 146 | /* SBUS */ |
| 147 | { |
| 148 | .name = "sbus", |
| 149 | .addr_prop_name = "reg", |
| 150 | .match = of_bus_sbus_match, |
| 151 | .count_cells = of_bus_sbus_count_cells, |
Robert Reif | c9f5b7e | 2009-06-04 02:00:02 -0700 | [diff] [blame] | 152 | .map = of_bus_default_map, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 153 | .get_flags = of_bus_sbus_get_flags, |
| 154 | }, |
Konrad Eisele | e63829d | 2009-08-17 00:13:32 +0000 | [diff] [blame] | 155 | /* AMBA */ |
| 156 | { |
| 157 | .name = "ambapp", |
| 158 | .addr_prop_name = "reg", |
| 159 | .match = of_bus_ambapp_match, |
| 160 | .count_cells = of_bus_ambapp_count_cells, |
| 161 | .map = of_bus_ambapp_map, |
| 162 | .get_flags = of_bus_ambapp_get_flags, |
| 163 | }, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 164 | /* Default */ |
| 165 | { |
| 166 | .name = "default", |
| 167 | .addr_prop_name = "reg", |
| 168 | .match = NULL, |
| 169 | .count_cells = of_bus_default_count_cells, |
| 170 | .map = of_bus_default_map, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 171 | .get_flags = of_bus_default_get_flags, |
| 172 | }, |
| 173 | }; |
| 174 | |
| 175 | static struct of_bus *of_match_bus(struct device_node *np) |
| 176 | { |
| 177 | int i; |
| 178 | |
| 179 | for (i = 0; i < ARRAY_SIZE(of_busses); i ++) |
| 180 | if (!of_busses[i].match || of_busses[i].match(np)) |
| 181 | return &of_busses[i]; |
| 182 | BUG(); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | static int __init build_one_resource(struct device_node *parent, |
| 187 | struct of_bus *bus, |
| 188 | struct of_bus *pbus, |
| 189 | u32 *addr, |
| 190 | int na, int ns, int pna) |
| 191 | { |
Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 192 | const u32 *ranges; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 193 | unsigned int rlen; |
| 194 | int rone; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 195 | |
| 196 | ranges = of_get_property(parent, "ranges", &rlen); |
| 197 | if (ranges == NULL || rlen == 0) { |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 198 | u32 result[OF_MAX_ADDR_CELLS]; |
| 199 | int i; |
| 200 | |
| 201 | memset(result, 0, pna * 4); |
| 202 | for (i = 0; i < na; i++) |
| 203 | result[pna - 1 - i] = |
| 204 | addr[na - 1 - i]; |
| 205 | |
| 206 | memcpy(addr, result, pna * 4); |
| 207 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /* Now walk through the ranges */ |
| 211 | rlen /= 4; |
| 212 | rone = na + pna + ns; |
| 213 | for (; rlen >= rone; rlen -= rone, ranges += rone) { |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 214 | if (!bus->map(addr, ranges, na, ns, pna)) |
| 215 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 216 | } |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 217 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 218 | return 1; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 219 | } |
| 220 | |
David S. Miller | 5280267 | 2008-09-03 02:04:41 -0700 | [diff] [blame] | 221 | static int __init use_1to1_mapping(struct device_node *pp) |
| 222 | { |
| 223 | /* If we have a ranges property in the parent, use it. */ |
| 224 | if (of_find_property(pp, "ranges", NULL) != NULL) |
| 225 | return 0; |
| 226 | |
| 227 | /* Some SBUS devices use intermediate nodes to express |
| 228 | * hierarchy within the device itself. These aren't |
| 229 | * real bus nodes, and don't have a 'ranges' property. |
| 230 | * But, we should still pass the translation work up |
| 231 | * to the SBUS itself. |
| 232 | */ |
| 233 | if (!strcmp(pp->name, "dma") || |
| 234 | !strcmp(pp->name, "espdma") || |
| 235 | !strcmp(pp->name, "ledma") || |
| 236 | !strcmp(pp->name, "lebuffer")) |
| 237 | return 0; |
| 238 | |
| 239 | return 1; |
| 240 | } |
| 241 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 242 | static int of_resource_verbose; |
| 243 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 244 | static void __init build_device_resources(struct platform_device *op, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 245 | struct device *parent) |
| 246 | { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 247 | struct platform_device *p_op; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 248 | struct of_bus *bus; |
| 249 | int na, ns; |
| 250 | int index, num_reg; |
Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 251 | const void *preg; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 252 | |
| 253 | if (!parent) |
| 254 | return; |
| 255 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 256 | p_op = to_platform_device(parent); |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 257 | bus = of_match_bus(p_op->dev.of_node); |
| 258 | bus->count_cells(op->dev.of_node, &na, &ns); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 259 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 260 | preg = of_get_property(op->dev.of_node, bus->addr_prop_name, &num_reg); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 261 | if (!preg || num_reg == 0) |
| 262 | return; |
| 263 | |
| 264 | /* Convert to num-cells. */ |
| 265 | num_reg /= 4; |
| 266 | |
| 267 | /* Conver to num-entries. */ |
| 268 | num_reg /= na + ns; |
| 269 | |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 270 | op->resource = op->archdata.resource; |
| 271 | op->num_resources = num_reg; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 272 | for (index = 0; index < num_reg; index++) { |
| 273 | struct resource *r = &op->resource[index]; |
| 274 | u32 addr[OF_MAX_ADDR_CELLS]; |
Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 275 | const u32 *reg = (preg + (index * ((na + ns) * 4))); |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 276 | struct device_node *dp = op->dev.of_node; |
| 277 | struct device_node *pp = p_op->dev.of_node; |
David S. Miller | b85cdd4 | 2007-02-28 23:20:12 -0800 | [diff] [blame] | 278 | struct of_bus *pbus, *dbus; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 279 | u64 size, result = OF_BAD_ADDR; |
| 280 | unsigned long flags; |
| 281 | int dna, dns; |
| 282 | int pna, pns; |
| 283 | |
| 284 | size = of_read_addr(reg + na, ns); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 285 | |
| 286 | memcpy(addr, reg, na * 4); |
| 287 | |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 288 | flags = bus->get_flags(reg, 0); |
| 289 | |
David S. Miller | 5280267 | 2008-09-03 02:04:41 -0700 | [diff] [blame] | 290 | if (use_1to1_mapping(pp)) { |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 291 | result = of_read_addr(addr, na); |
| 292 | goto build_res; |
| 293 | } |
| 294 | |
| 295 | dna = na; |
| 296 | dns = ns; |
David S. Miller | b85cdd4 | 2007-02-28 23:20:12 -0800 | [diff] [blame] | 297 | dbus = bus; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 298 | |
| 299 | while (1) { |
| 300 | dp = pp; |
| 301 | pp = dp->parent; |
| 302 | if (!pp) { |
| 303 | result = of_read_addr(addr, dna); |
| 304 | break; |
| 305 | } |
| 306 | |
| 307 | pbus = of_match_bus(pp); |
| 308 | pbus->count_cells(dp, &pna, &pns); |
| 309 | |
David S. Miller | b85cdd4 | 2007-02-28 23:20:12 -0800 | [diff] [blame] | 310 | if (build_one_resource(dp, dbus, pbus, addr, |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 311 | dna, dns, pna)) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 312 | break; |
| 313 | |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 314 | flags = pbus->get_flags(addr, flags); |
| 315 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 316 | dna = pna; |
| 317 | dns = pns; |
David S. Miller | b85cdd4 | 2007-02-28 23:20:12 -0800 | [diff] [blame] | 318 | dbus = pbus; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | build_res: |
| 322 | memset(r, 0, sizeof(*r)); |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 323 | |
| 324 | if (of_resource_verbose) |
| 325 | printk("%s reg[%d] -> %llx\n", |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 326 | op->dev.of_node->full_name, index, |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 327 | result); |
| 328 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 329 | if (result != OF_BAD_ADDR) { |
David S. Miller | 95714e1 | 2006-06-29 14:35:14 -0700 | [diff] [blame] | 330 | r->start = result & 0xffffffff; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 331 | r->end = result + size - 1; |
David S. Miller | 95714e1 | 2006-06-29 14:35:14 -0700 | [diff] [blame] | 332 | r->flags = flags | ((result >> 32ULL) & 0xffUL); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 333 | } |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 334 | r->name = op->dev.of_node->name; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 338 | static struct platform_device * __init scan_one_device(struct device_node *dp, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 339 | struct device *parent) |
| 340 | { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 341 | struct platform_device *op = kzalloc(sizeof(*op), GFP_KERNEL); |
Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 342 | const struct linux_prom_irqs *intr; |
David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 343 | struct dev_archdata *sd; |
David S. Miller | 8f96cd1 | 2006-06-29 15:08:02 -0700 | [diff] [blame] | 344 | int len, i; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 345 | |
| 346 | if (!op) |
| 347 | return NULL; |
| 348 | |
David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 349 | sd = &op->dev.archdata; |
David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 350 | sd->op = op; |
| 351 | |
Grant Likely | d706c1b | 2010-04-13 16:12:28 -0700 | [diff] [blame] | 352 | op->dev.of_node = dp; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 353 | |
David S. Miller | 8f96cd1 | 2006-06-29 15:08:02 -0700 | [diff] [blame] | 354 | intr = of_get_property(dp, "intr", &len); |
| 355 | if (intr) { |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 356 | op->archdata.num_irqs = len / sizeof(struct linux_prom_irqs); |
| 357 | for (i = 0; i < op->archdata.num_irqs; i++) |
Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 358 | op->archdata.irqs[i] = |
Sam Ravnborg | 472bc4f | 2012-04-04 13:21:13 +0200 | [diff] [blame] | 359 | sparc_config.build_device_irq(op, intr[i].pri); |
David S. Miller | 8f96cd1 | 2006-06-29 15:08:02 -0700 | [diff] [blame] | 360 | } else { |
Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 361 | const unsigned int *irq = |
| 362 | of_get_property(dp, "interrupts", &len); |
David S. Miller | 8f96cd1 | 2006-06-29 15:08:02 -0700 | [diff] [blame] | 363 | |
| 364 | if (irq) { |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 365 | op->archdata.num_irqs = len / sizeof(unsigned int); |
| 366 | for (i = 0; i < op->archdata.num_irqs; i++) |
Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 367 | op->archdata.irqs[i] = |
Sam Ravnborg | 472bc4f | 2012-04-04 13:21:13 +0200 | [diff] [blame] | 368 | sparc_config.build_device_irq(op, irq[i]); |
David S. Miller | 8f96cd1 | 2006-06-29 15:08:02 -0700 | [diff] [blame] | 369 | } else { |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 370 | op->archdata.num_irqs = 0; |
David S. Miller | 8f96cd1 | 2006-06-29 15:08:02 -0700 | [diff] [blame] | 371 | } |
| 372 | } |
David S. Miller | 9d7ab1f | 2006-07-17 21:39:09 -0700 | [diff] [blame] | 373 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 374 | build_device_resources(op, parent); |
| 375 | |
| 376 | op->dev.parent = parent; |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 377 | op->dev.bus = &platform_bus_type; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 378 | if (!parent) |
Kay Sievers | 5acdc1f | 2008-11-12 23:48:40 -0800 | [diff] [blame] | 379 | dev_set_name(&op->dev, "root"); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 380 | else |
Grant Likely | 6016a36 | 2010-01-28 14:06:53 -0700 | [diff] [blame] | 381 | dev_set_name(&op->dev, "%08x", dp->phandle); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 382 | |
| 383 | if (of_device_register(op)) { |
| 384 | printk("%s: Could not register of device.\n", |
| 385 | dp->full_name); |
| 386 | kfree(op); |
| 387 | op = NULL; |
| 388 | } |
| 389 | |
| 390 | return op; |
| 391 | } |
| 392 | |
| 393 | static void __init scan_tree(struct device_node *dp, struct device *parent) |
| 394 | { |
| 395 | while (dp) { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 396 | struct platform_device *op = scan_one_device(dp, parent); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 397 | |
| 398 | if (op) |
| 399 | scan_tree(dp->child, &op->dev); |
| 400 | |
| 401 | dp = dp->sibling; |
| 402 | } |
| 403 | } |
| 404 | |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 405 | static int __init scan_of_devices(void) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 406 | { |
| 407 | struct device_node *root = of_find_node_by_path("/"); |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 408 | struct platform_device *parent; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 409 | |
| 410 | parent = scan_one_device(root, NULL); |
| 411 | if (!parent) |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 412 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 413 | |
| 414 | scan_tree(root->child, &parent->dev); |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 415 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 416 | } |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 417 | postcore_initcall(scan_of_devices); |
David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 418 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 419 | static int __init of_debug(char *str) |
| 420 | { |
| 421 | int val = 0; |
| 422 | |
| 423 | get_option(&str, &val); |
| 424 | if (val & 1) |
| 425 | of_resource_verbose = 1; |
| 426 | return 1; |
| 427 | } |
| 428 | |
| 429 | __setup("of_debug=", of_debug); |