Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 1 | /* |
| 2 | * FSL SoC setup code |
| 3 | * |
| 4 | * Maintained by Kumar Gala (see MAINTAINERS for contact information) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/stddef.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/major.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/device.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/fsl_devices.h> |
| 24 | |
| 25 | #include <asm/system.h> |
| 26 | #include <asm/atomic.h> |
| 27 | #include <asm/io.h> |
| 28 | #include <asm/irq.h> |
| 29 | #include <asm/prom.h> |
| 30 | #include <sysdev/fsl_soc.h> |
| 31 | #include <mm/mmu_decl.h> |
| 32 | |
| 33 | static phys_addr_t immrbase = -1; |
| 34 | |
| 35 | phys_addr_t get_immrbase(void) |
| 36 | { |
| 37 | struct device_node *soc; |
| 38 | |
| 39 | if (immrbase != -1) |
| 40 | return immrbase; |
| 41 | |
| 42 | soc = of_find_node_by_type(NULL, "soc"); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 43 | if (soc) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 44 | unsigned int size; |
| 45 | void *prop = get_property(soc, "reg", &size); |
| 46 | immrbase = of_translate_address(soc, prop); |
| 47 | of_node_put(soc); |
| 48 | }; |
| 49 | |
| 50 | return immrbase; |
| 51 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 52 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 53 | EXPORT_SYMBOL(get_immrbase); |
| 54 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 55 | static int __init gfar_mdio_of_init(void) |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 56 | { |
| 57 | struct device_node *np; |
| 58 | unsigned int i; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 59 | struct platform_device *mdio_dev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 60 | struct resource res; |
| 61 | int ret; |
| 62 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 63 | for (np = NULL, i = 0; |
| 64 | (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; |
| 65 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 66 | int k; |
| 67 | struct device_node *child = NULL; |
| 68 | struct gianfar_mdio_data mdio_data; |
| 69 | |
| 70 | memset(&res, 0, sizeof(res)); |
| 71 | memset(&mdio_data, 0, sizeof(mdio_data)); |
| 72 | |
| 73 | ret = of_address_to_resource(np, 0, &res); |
| 74 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 75 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 76 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 77 | mdio_dev = |
| 78 | platform_device_register_simple("fsl-gianfar_mdio", |
| 79 | res.start, &res, 1); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 80 | if (IS_ERR(mdio_dev)) { |
| 81 | ret = PTR_ERR(mdio_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 82 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | for (k = 0; k < 32; k++) |
| 86 | mdio_data.irq[k] = -1; |
| 87 | |
| 88 | while ((child = of_get_next_child(np, child)) != NULL) { |
| 89 | if (child->n_intrs) { |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 90 | u32 *id = |
| 91 | (u32 *) get_property(child, "reg", NULL); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 92 | mdio_data.irq[*id] = child->intrs[0].line; |
| 93 | } |
| 94 | } |
| 95 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 96 | ret = |
| 97 | platform_device_add_data(mdio_dev, &mdio_data, |
| 98 | sizeof(struct gianfar_mdio_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 99 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 100 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 101 | } |
| 102 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 103 | return 0; |
| 104 | |
| 105 | unreg: |
| 106 | platform_device_unregister(mdio_dev); |
| 107 | err: |
| 108 | return ret; |
| 109 | } |
| 110 | |
| 111 | arch_initcall(gfar_mdio_of_init); |
| 112 | |
| 113 | static const char *gfar_tx_intr = "tx"; |
| 114 | static const char *gfar_rx_intr = "rx"; |
| 115 | static const char *gfar_err_intr = "error"; |
| 116 | |
| 117 | static int __init gfar_of_init(void) |
| 118 | { |
| 119 | struct device_node *np; |
| 120 | unsigned int i; |
| 121 | struct platform_device *gfar_dev; |
| 122 | struct resource res; |
| 123 | int ret; |
| 124 | |
| 125 | for (np = NULL, i = 0; |
| 126 | (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; |
| 127 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 128 | struct resource r[4]; |
| 129 | struct device_node *phy, *mdio; |
| 130 | struct gianfar_platform_data gfar_data; |
| 131 | unsigned int *id; |
| 132 | char *model; |
| 133 | void *mac_addr; |
| 134 | phandle *ph; |
| 135 | |
| 136 | memset(r, 0, sizeof(r)); |
| 137 | memset(&gfar_data, 0, sizeof(gfar_data)); |
| 138 | |
| 139 | ret = of_address_to_resource(np, 0, &r[0]); |
| 140 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 141 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 142 | |
| 143 | r[1].start = np->intrs[0].line; |
| 144 | r[1].end = np->intrs[0].line; |
| 145 | r[1].flags = IORESOURCE_IRQ; |
| 146 | |
| 147 | model = get_property(np, "model", NULL); |
| 148 | |
| 149 | /* If we aren't the FEC we have multiple interrupts */ |
| 150 | if (model && strcasecmp(model, "FEC")) { |
| 151 | r[1].name = gfar_tx_intr; |
| 152 | |
| 153 | r[2].name = gfar_rx_intr; |
| 154 | r[2].start = np->intrs[1].line; |
| 155 | r[2].end = np->intrs[1].line; |
| 156 | r[2].flags = IORESOURCE_IRQ; |
| 157 | |
| 158 | r[3].name = gfar_err_intr; |
| 159 | r[3].start = np->intrs[2].line; |
| 160 | r[3].end = np->intrs[2].line; |
| 161 | r[3].flags = IORESOURCE_IRQ; |
| 162 | } |
| 163 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 164 | gfar_dev = |
| 165 | platform_device_register_simple("fsl-gianfar", i, &r[0], |
| 166 | np->n_intrs + 1); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 167 | |
| 168 | if (IS_ERR(gfar_dev)) { |
| 169 | ret = PTR_ERR(gfar_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 170 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | mac_addr = get_property(np, "address", NULL); |
| 174 | memcpy(gfar_data.mac_addr, mac_addr, 6); |
| 175 | |
| 176 | if (model && !strcasecmp(model, "TSEC")) |
| 177 | gfar_data.device_flags = |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 178 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 179 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 180 | FSL_GIANFAR_DEV_HAS_RMON | |
| 181 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 182 | if (model && !strcasecmp(model, "eTSEC")) |
| 183 | gfar_data.device_flags = |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 184 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 185 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 186 | FSL_GIANFAR_DEV_HAS_RMON | |
| 187 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | |
| 188 | FSL_GIANFAR_DEV_HAS_CSUM | |
| 189 | FSL_GIANFAR_DEV_HAS_VLAN | |
| 190 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 191 | |
| 192 | ph = (phandle *) get_property(np, "phy-handle", NULL); |
| 193 | phy = of_find_node_by_phandle(*ph); |
| 194 | |
| 195 | if (phy == NULL) { |
| 196 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 197 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | mdio = of_get_parent(phy); |
| 201 | |
| 202 | id = (u32 *) get_property(phy, "reg", NULL); |
| 203 | ret = of_address_to_resource(mdio, 0, &res); |
| 204 | if (ret) { |
| 205 | of_node_put(phy); |
| 206 | of_node_put(mdio); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 207 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | gfar_data.phy_id = *id; |
| 211 | gfar_data.bus_id = res.start; |
| 212 | |
| 213 | of_node_put(phy); |
| 214 | of_node_put(mdio); |
| 215 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 216 | ret = |
| 217 | platform_device_add_data(gfar_dev, &gfar_data, |
| 218 | sizeof(struct |
| 219 | gianfar_platform_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 220 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 221 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 226 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 227 | platform_device_unregister(gfar_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 228 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 229 | return ret; |
| 230 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 231 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 232 | arch_initcall(gfar_of_init); |
| 233 | |
| 234 | static int __init fsl_i2c_of_init(void) |
| 235 | { |
| 236 | struct device_node *np; |
| 237 | unsigned int i; |
| 238 | struct platform_device *i2c_dev; |
| 239 | int ret; |
| 240 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 241 | for (np = NULL, i = 0; |
| 242 | (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL; |
| 243 | i++) { |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 244 | struct resource r[2]; |
| 245 | struct fsl_i2c_platform_data i2c_data; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 246 | unsigned char *flags = NULL; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 247 | |
| 248 | memset(&r, 0, sizeof(r)); |
| 249 | memset(&i2c_data, 0, sizeof(i2c_data)); |
| 250 | |
| 251 | ret = of_address_to_resource(np, 0, &r[0]); |
| 252 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 253 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 254 | |
| 255 | r[1].start = np->intrs[0].line; |
| 256 | r[1].end = np->intrs[0].line; |
| 257 | r[1].flags = IORESOURCE_IRQ; |
| 258 | |
| 259 | i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); |
| 260 | if (IS_ERR(i2c_dev)) { |
| 261 | ret = PTR_ERR(i2c_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 262 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | i2c_data.device_flags = 0; |
| 266 | flags = get_property(np, "dfsrr", NULL); |
| 267 | if (flags) |
| 268 | i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR; |
| 269 | |
| 270 | flags = get_property(np, "fsl5200-clocking", NULL); |
| 271 | if (flags) |
| 272 | i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; |
| 273 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 274 | ret = |
| 275 | platform_device_add_data(i2c_dev, &i2c_data, |
| 276 | sizeof(struct |
| 277 | fsl_i2c_platform_data)); |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 278 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 279 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | return 0; |
| 283 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 284 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 285 | platform_device_unregister(i2c_dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 286 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 287 | return ret; |
| 288 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 289 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 290 | arch_initcall(fsl_i2c_of_init); |
| 291 | |
| 292 | #ifdef CONFIG_PPC_83xx |
| 293 | static int __init mpc83xx_wdt_init(void) |
| 294 | { |
| 295 | struct resource r; |
| 296 | struct device_node *soc, *np; |
| 297 | struct platform_device *dev; |
| 298 | unsigned int *freq; |
| 299 | int ret; |
| 300 | |
| 301 | np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); |
| 302 | |
| 303 | if (!np) { |
| 304 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 305 | goto nodev; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | soc = of_find_node_by_type(NULL, "soc"); |
| 309 | |
| 310 | if (!soc) { |
| 311 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 312 | goto nosoc; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | freq = (unsigned int *)get_property(soc, "bus-frequency", NULL); |
| 316 | if (!freq) { |
| 317 | ret = -ENODEV; |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 318 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | memset(&r, 0, sizeof(r)); |
| 322 | |
| 323 | ret = of_address_to_resource(np, 0, &r); |
| 324 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 325 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 326 | |
| 327 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); |
| 328 | if (IS_ERR(dev)) { |
| 329 | ret = PTR_ERR(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 330 | goto err; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | ret = platform_device_add_data(dev, freq, sizeof(int)); |
| 334 | if (ret) |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 335 | goto unreg; |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 336 | |
| 337 | of_node_put(soc); |
| 338 | of_node_put(np); |
| 339 | |
| 340 | return 0; |
| 341 | |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 342 | unreg: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 343 | platform_device_unregister(dev); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 344 | err: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 345 | of_node_put(soc); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 346 | nosoc: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 347 | of_node_put(np); |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 348 | nodev: |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 349 | return ret; |
| 350 | } |
Kumar Gala | 2fb07d7 | 2006-01-23 16:58:04 -0600 | [diff] [blame] | 351 | |
Kumar Gala | eed3200 | 2006-01-13 11:19:13 -0600 | [diff] [blame] | 352 | arch_initcall(mpc83xx_wdt_init); |
| 353 | #endif |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 354 | |
| 355 | static enum fsl_usb2_phy_modes determine_usb_phy(char * phy_type) |
| 356 | { |
| 357 | if (!phy_type) |
| 358 | return FSL_USB2_PHY_NONE; |
| 359 | if (!strcasecmp(phy_type, "ulpi")) |
| 360 | return FSL_USB2_PHY_ULPI; |
| 361 | if (!strcasecmp(phy_type, "utmi")) |
| 362 | return FSL_USB2_PHY_UTMI; |
| 363 | if (!strcasecmp(phy_type, "utmi_wide")) |
| 364 | return FSL_USB2_PHY_UTMI_WIDE; |
| 365 | if (!strcasecmp(phy_type, "serial")) |
| 366 | return FSL_USB2_PHY_SERIAL; |
| 367 | |
| 368 | return FSL_USB2_PHY_NONE; |
| 369 | } |
| 370 | |
| 371 | static int __init fsl_usb_of_init(void) |
| 372 | { |
| 373 | struct device_node *np; |
| 374 | unsigned int i; |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 375 | struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 376 | int ret; |
| 377 | |
| 378 | for (np = NULL, i = 0; |
| 379 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL; |
| 380 | i++) { |
| 381 | struct resource r[2]; |
| 382 | struct fsl_usb2_platform_data usb_data; |
| 383 | unsigned char *prop = NULL; |
| 384 | |
| 385 | memset(&r, 0, sizeof(r)); |
| 386 | memset(&usb_data, 0, sizeof(usb_data)); |
| 387 | |
| 388 | ret = of_address_to_resource(np, 0, &r[0]); |
| 389 | if (ret) |
| 390 | goto err; |
| 391 | |
| 392 | r[1].start = np->intrs[0].line; |
| 393 | r[1].end = np->intrs[0].line; |
| 394 | r[1].flags = IORESOURCE_IRQ; |
| 395 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 396 | usb_dev_mph = |
| 397 | platform_device_register_simple("fsl-ehci", i, r, 2); |
| 398 | if (IS_ERR(usb_dev_mph)) { |
| 399 | ret = PTR_ERR(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 400 | goto err; |
| 401 | } |
| 402 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 403 | usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; |
| 404 | usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 405 | |
| 406 | usb_data.operating_mode = FSL_USB2_MPH_HOST; |
| 407 | |
| 408 | prop = get_property(np, "port0", NULL); |
| 409 | if (prop) |
| 410 | usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; |
| 411 | |
| 412 | prop = get_property(np, "port1", NULL); |
| 413 | if (prop) |
| 414 | usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; |
| 415 | |
| 416 | prop = get_property(np, "phy_type", NULL); |
| 417 | usb_data.phy_mode = determine_usb_phy(prop); |
| 418 | |
| 419 | ret = |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 420 | platform_device_add_data(usb_dev_mph, &usb_data, |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 421 | sizeof(struct |
| 422 | fsl_usb2_platform_data)); |
| 423 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 424 | goto unreg_mph; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 425 | } |
| 426 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 427 | for (np = NULL; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 428 | (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL; |
| 429 | i++) { |
| 430 | struct resource r[2]; |
| 431 | struct fsl_usb2_platform_data usb_data; |
| 432 | unsigned char *prop = NULL; |
| 433 | |
| 434 | memset(&r, 0, sizeof(r)); |
| 435 | memset(&usb_data, 0, sizeof(usb_data)); |
| 436 | |
| 437 | ret = of_address_to_resource(np, 0, &r[0]); |
| 438 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 439 | goto unreg_mph; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 440 | |
| 441 | r[1].start = np->intrs[0].line; |
| 442 | r[1].end = np->intrs[0].line; |
| 443 | r[1].flags = IORESOURCE_IRQ; |
| 444 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 445 | usb_dev_dr = |
| 446 | platform_device_register_simple("fsl-ehci", i, r, 2); |
| 447 | if (IS_ERR(usb_dev_dr)) { |
| 448 | ret = PTR_ERR(usb_dev_dr); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 449 | goto err; |
| 450 | } |
| 451 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 452 | usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL; |
| 453 | usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 454 | |
| 455 | usb_data.operating_mode = FSL_USB2_DR_HOST; |
| 456 | |
| 457 | prop = get_property(np, "phy_type", NULL); |
| 458 | usb_data.phy_mode = determine_usb_phy(prop); |
| 459 | |
| 460 | ret = |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 461 | platform_device_add_data(usb_dev_dr, &usb_data, |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 462 | sizeof(struct |
| 463 | fsl_usb2_platform_data)); |
| 464 | if (ret) |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 465 | goto unreg_dr; |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 466 | } |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 467 | return 0; |
| 468 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 469 | unreg_dr: |
| 470 | if (usb_dev_dr) |
| 471 | platform_device_unregister(usb_dev_dr); |
| 472 | unreg_mph: |
| 473 | if (usb_dev_mph) |
| 474 | platform_device_unregister(usb_dev_mph); |
Kumar Gala | 4b10cfd | 2006-02-02 12:31:00 -0600 | [diff] [blame] | 475 | err: |
| 476 | return ret; |
| 477 | } |
| 478 | |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 479 | arch_initcall(fsl_usb_of_init); |