1 /* 2 * FSL SoC setup code 3 * 4 * Maintained by Kumar Gala (see MAINTAINERS for contact information) 5 * 6 * 2006 (c) MontaVista Software, Inc. 7 * Vitaly Bordug <vbordug@ru.mvista.com> 8 * 9 * This program is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU General Public License as published by the 11 * Free Software Foundation; either version 2 of the License, or (at your 12 * option) any later version. 13 */ 14 15 #include <linux/stddef.h> 16 #include <linux/kernel.h> 17 #include <linux/init.h> 18 #include <linux/errno.h> 19 #include <linux/major.h> 20 #include <linux/delay.h> 21 #include <linux/irq.h> 22 #include <linux/module.h> 23 #include <linux/device.h> 24 #include <linux/platform_device.h> 25 #include <linux/of_platform.h> 26 #include <linux/phy.h> 27 #include <linux/fsl_devices.h> 28 #include <linux/fs_enet_pd.h> 29 #include <linux/fs_uart_pd.h> 30 31 #include <asm/system.h> 32 #include <asm/atomic.h> 33 #include <asm/io.h> 34 #include <asm/irq.h> 35 #include <asm/time.h> 36 #include <asm/prom.h> 37 #include <sysdev/fsl_soc.h> 38 #include <mm/mmu_decl.h> 39 #include <asm/cpm2.h> 40 41 extern void init_fcc_ioports(struct fs_platform_info*); 42 extern void init_fec_ioports(struct fs_platform_info*); 43 extern void init_smc_ioports(struct fs_uart_platform_info*); 44 static phys_addr_t immrbase = -1; 45 46 phys_addr_t get_immrbase(void) 47 { 48 struct device_node *soc; 49 50 if (immrbase != -1) 51 return immrbase; 52 53 soc = of_find_node_by_type(NULL, "soc"); 54 if (soc) { 55 unsigned int size; 56 const void *prop = of_get_property(soc, "reg", &size); 57 58 if (prop) 59 immrbase = of_translate_address(soc, prop); 60 of_node_put(soc); 61 }; 62 63 return immrbase; 64 } 65 66 EXPORT_SYMBOL(get_immrbase); 67 68 #if defined(CONFIG_CPM2) || defined(CONFIG_8xx) 69 70 static u32 brgfreq = -1; 71 72 u32 get_brgfreq(void) 73 { 74 struct device_node *node; 75 76 if (brgfreq != -1) 77 return brgfreq; 78 79 node = of_find_node_by_type(NULL, "cpm"); 80 if (node) { 81 unsigned int size; 82 const unsigned int *prop = of_get_property(node, 83 "brg-frequency", &size); 84 85 if (prop) 86 brgfreq = *prop; 87 of_node_put(node); 88 }; 89 90 return brgfreq; 91 } 92 93 EXPORT_SYMBOL(get_brgfreq); 94 95 static u32 fs_baudrate = -1; 96 97 u32 get_baudrate(void) 98 { 99 struct device_node *node; 100 101 if (fs_baudrate != -1) 102 return fs_baudrate; 103 104 node = of_find_node_by_type(NULL, "serial"); 105 if (node) { 106 unsigned int size; 107 const unsigned int *prop = of_get_property(node, 108 "current-speed", &size); 109 110 if (prop) 111 fs_baudrate = *prop; 112 of_node_put(node); 113 }; 114 115 return fs_baudrate; 116 } 117 118 EXPORT_SYMBOL(get_baudrate); 119 #endif /* CONFIG_CPM2 */ 120 121 static int __init gfar_mdio_of_init(void) 122 { 123 struct device_node *np; 124 unsigned int i; 125 struct platform_device *mdio_dev; 126 struct resource res; 127 int ret; 128 129 for (np = NULL, i = 0; 130 (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; 131 i++) { 132 int k; 133 struct device_node *child = NULL; 134 struct gianfar_mdio_data mdio_data; 135 136 memset(&res, 0, sizeof(res)); 137 memset(&mdio_data, 0, sizeof(mdio_data)); 138 139 ret = of_address_to_resource(np, 0, &res); 140 if (ret) 141 goto err; 142 143 mdio_dev = 144 platform_device_register_simple("fsl-gianfar_mdio", 145 res.start, &res, 1); 146 if (IS_ERR(mdio_dev)) { 147 ret = PTR_ERR(mdio_dev); 148 goto err; 149 } 150 151 for (k = 0; k < 32; k++) 152 mdio_data.irq[k] = PHY_POLL; 153 154 while ((child = of_get_next_child(np, child)) != NULL) { 155 int irq = irq_of_parse_and_map(child, 0); 156 if (irq != NO_IRQ) { 157 const u32 *id = of_get_property(child, 158 "reg", NULL); 159 mdio_data.irq[*id] = irq; 160 } 161 } 162 163 ret = 164 platform_device_add_data(mdio_dev, &mdio_data, 165 sizeof(struct gianfar_mdio_data)); 166 if (ret) 167 goto unreg; 168 } 169 170 return 0; 171 172 unreg: 173 platform_device_unregister(mdio_dev); 174 err: 175 return ret; 176 } 177 178 arch_initcall(gfar_mdio_of_init); 179 180 static const char *gfar_tx_intr = "tx"; 181 static const char *gfar_rx_intr = "rx"; 182 static const char *gfar_err_intr = "error"; 183 184 185 static int __init gfar_of_init(void) 186 { 187 struct device_node *np; 188 unsigned int i; 189 struct platform_device *gfar_dev; 190 struct resource res; 191 int ret; 192 193 for (np = NULL, i = 0; 194 (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; 195 i++) { 196 struct resource r[4]; 197 struct device_node *phy, *mdio; 198 struct gianfar_platform_data gfar_data; 199 const unsigned int *id; 200 const char *model; 201 const char *ctype; 202 const void *mac_addr; 203 const phandle *ph; 204 int n_res = 2; 205 206 memset(r, 0, sizeof(r)); 207 memset(&gfar_data, 0, sizeof(gfar_data)); 208 209 ret = of_address_to_resource(np, 0, &r[0]); 210 if (ret) 211 goto err; 212 213 of_irq_to_resource(np, 0, &r[1]); 214 215 model = of_get_property(np, "model", NULL); 216 217 /* If we aren't the FEC we have multiple interrupts */ 218 if (model && strcasecmp(model, "FEC")) { 219 r[1].name = gfar_tx_intr; 220 221 r[2].name = gfar_rx_intr; 222 of_irq_to_resource(np, 1, &r[2]); 223 224 r[3].name = gfar_err_intr; 225 of_irq_to_resource(np, 2, &r[3]); 226 227 n_res += 2; 228 } 229 230 gfar_dev = 231 platform_device_register_simple("fsl-gianfar", i, &r[0], 232 n_res); 233 234 if (IS_ERR(gfar_dev)) { 235 ret = PTR_ERR(gfar_dev); 236 goto err; 237 } 238 239 mac_addr = of_get_mac_address(np); 240 if (mac_addr) 241 memcpy(gfar_data.mac_addr, mac_addr, 6); 242 243 if (model && !strcasecmp(model, "TSEC")) 244 gfar_data.device_flags = 245 FSL_GIANFAR_DEV_HAS_GIGABIT | 246 FSL_GIANFAR_DEV_HAS_COALESCE | 247 FSL_GIANFAR_DEV_HAS_RMON | 248 FSL_GIANFAR_DEV_HAS_MULTI_INTR; 249 if (model && !strcasecmp(model, "eTSEC")) 250 gfar_data.device_flags = 251 FSL_GIANFAR_DEV_HAS_GIGABIT | 252 FSL_GIANFAR_DEV_HAS_COALESCE | 253 FSL_GIANFAR_DEV_HAS_RMON | 254 FSL_GIANFAR_DEV_HAS_MULTI_INTR | 255 FSL_GIANFAR_DEV_HAS_CSUM | 256 FSL_GIANFAR_DEV_HAS_VLAN | 257 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; 258 259 ctype = of_get_property(np, "phy-connection-type", NULL); 260 261 /* We only care about rgmii-id. The rest are autodetected */ 262 if (ctype && !strcmp(ctype, "rgmii-id")) 263 gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID; 264 else 265 gfar_data.interface = PHY_INTERFACE_MODE_MII; 266 267 ph = of_get_property(np, "phy-handle", NULL); 268 phy = of_find_node_by_phandle(*ph); 269 270 if (phy == NULL) { 271 ret = -ENODEV; 272 goto unreg; 273 } 274 275 mdio = of_get_parent(phy); 276 277 id = of_get_property(phy, "reg", NULL); 278 ret = of_address_to_resource(mdio, 0, &res); 279 if (ret) { 280 of_node_put(phy); 281 of_node_put(mdio); 282 goto unreg; 283 } 284 285 gfar_data.phy_id = *id; 286 gfar_data.bus_id = res.start; 287 288 of_node_put(phy); 289 of_node_put(mdio); 290 291 ret = 292 platform_device_add_data(gfar_dev, &gfar_data, 293 sizeof(struct 294 gianfar_platform_data)); 295 if (ret) 296 goto unreg; 297 } 298 299 return 0; 300 301 unreg: 302 platform_device_unregister(gfar_dev); 303 err: 304 return ret; 305 } 306 307 arch_initcall(gfar_of_init); 308 309 #ifdef CONFIG_I2C_BOARDINFO 310 #include <linux/i2c.h> 311 struct i2c_driver_device { 312 char *of_device; 313 char *i2c_driver; 314 char *i2c_type; 315 }; 316 317 static struct i2c_driver_device i2c_devices[] __initdata = { 318 {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",}, 319 {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",}, 320 {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",}, 321 {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",}, 322 }; 323 324 static int __init of_find_i2c_driver(struct device_node *node, struct i2c_board_info *info) 325 { 326 int i; 327 328 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) { 329 if (!of_device_is_compatible(node, i2c_devices[i].of_device)) 330 continue; 331 strncpy(info->driver_name, i2c_devices[i].i2c_driver, KOBJ_NAME_LEN); 332 strncpy(info->type, i2c_devices[i].i2c_type, I2C_NAME_SIZE); 333 return 0; 334 } 335 return -ENODEV; 336 } 337 338 static void __init of_register_i2c_devices(struct device_node *adap_node, int bus_num) 339 { 340 struct device_node *node = NULL; 341 342 while ((node = of_get_next_child(adap_node, node))) { 343 struct i2c_board_info info; 344 const u32 *addr; 345 int len; 346 347 addr = of_get_property(node, "reg", &len); 348 if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) { 349 printk(KERN_WARNING "fsl_ioc.c: invalid i2c device entry\n"); 350 continue; 351 } 352 353 info.irq = irq_of_parse_and_map(node, 0); 354 if (info.irq == NO_IRQ) 355 info.irq = -1; 356 357 if (of_find_i2c_driver(node, &info) < 0) 358 continue; 359 360 info.platform_data = NULL; 361 info.addr = *addr; 362 363 i2c_register_board_info(bus_num, &info, 1); 364 } 365 } 366 367 static int __init fsl_i2c_of_init(void) 368 { 369 struct device_node *np; 370 unsigned int i; 371 struct platform_device *i2c_dev; 372 int ret; 373 374 for (np = NULL, i = 0; 375 (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL; 376 i++) { 377 struct resource r[2]; 378 struct fsl_i2c_platform_data i2c_data; 379 const unsigned char *flags = NULL; 380 381 memset(&r, 0, sizeof(r)); 382 memset(&i2c_data, 0, sizeof(i2c_data)); 383 384 ret = of_address_to_resource(np, 0, &r[0]); 385 if (ret) 386 goto err; 387 388 of_irq_to_resource(np, 0, &r[1]); 389 390 i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); 391 if (IS_ERR(i2c_dev)) { 392 ret = PTR_ERR(i2c_dev); 393 goto err; 394 } 395 396 i2c_data.device_flags = 0; 397 flags = of_get_property(np, "dfsrr", NULL); 398 if (flags) 399 i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR; 400 401 flags = of_get_property(np, "fsl5200-clocking", NULL); 402 if (flags) 403 i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; 404 405 ret = 406 platform_device_add_data(i2c_dev, &i2c_data, 407 sizeof(struct 408 fsl_i2c_platform_data)); 409 if (ret) 410 goto unreg; 411 412 of_register_i2c_devices(np, i); 413 } 414 415 return 0; 416 417 unreg: 418 platform_device_unregister(i2c_dev); 419 err: 420 return ret; 421 } 422 423 arch_initcall(fsl_i2c_of_init); 424 #endif 425 426 #ifdef CONFIG_PPC_83xx 427 static int __init mpc83xx_wdt_init(void) 428 { 429 struct resource r; 430 struct device_node *soc, *np; 431 struct platform_device *dev; 432 const unsigned int *freq; 433 int ret; 434 435 np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt"); 436 437 if (!np) { 438 ret = -ENODEV; 439 goto nodev; 440 } 441 442 soc = of_find_node_by_type(NULL, "soc"); 443 444 if (!soc) { 445 ret = -ENODEV; 446 goto nosoc; 447 } 448 449 freq = of_get_property(soc, "bus-frequency", NULL); 450 if (!freq) { 451 ret = -ENODEV; 452 goto err; 453 } 454 455 memset(&r, 0, sizeof(r)); 456 457 ret = of_address_to_resource(np, 0, &r); 458 if (ret) 459 goto err; 460 461 dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); 462 if (IS_ERR(dev)) { 463 ret = PTR_ERR(dev); 464 goto err; 465 } 466 467 ret = platform_device_add_data(dev, freq, sizeof(int)); 468 if (ret) 469 goto unreg; 470 471 of_node_put(soc); 472 of_node_put(np); 473 474 return 0; 475 476 unreg: 477 platform_device_unregister(dev); 478 err: 479 of_node_put(soc); 480 nosoc: 481 of_node_put(np); 482 nodev: 483 return ret; 484 } 485 486 arch_initcall(mpc83xx_wdt_init); 487 #endif 488 489 static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type) 490 { 491 if (!phy_type) 492 return FSL_USB2_PHY_NONE; 493 if (!strcasecmp(phy_type, "ulpi")) 494 return FSL_USB2_PHY_ULPI; 495 if (!strcasecmp(phy_type, "utmi")) 496 return FSL_USB2_PHY_UTMI; 497 if (!strcasecmp(phy_type, "utmi_wide")) 498 return FSL_USB2_PHY_UTMI_WIDE; 499 if (!strcasecmp(phy_type, "serial")) 500 return FSL_USB2_PHY_SERIAL; 501 502 return FSL_USB2_PHY_NONE; 503 } 504 505 static int __init fsl_usb_of_init(void) 506 { 507 struct device_node *np; 508 unsigned int i; 509 struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL, 510 *usb_dev_dr_client = NULL; 511 int ret; 512 513 for (np = NULL, i = 0; 514 (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL; 515 i++) { 516 struct resource r[2]; 517 struct fsl_usb2_platform_data usb_data; 518 const unsigned char *prop = NULL; 519 520 memset(&r, 0, sizeof(r)); 521 memset(&usb_data, 0, sizeof(usb_data)); 522 523 ret = of_address_to_resource(np, 0, &r[0]); 524 if (ret) 525 goto err; 526 527 of_irq_to_resource(np, 0, &r[1]); 528 529 usb_dev_mph = 530 platform_device_register_simple("fsl-ehci", i, r, 2); 531 if (IS_ERR(usb_dev_mph)) { 532 ret = PTR_ERR(usb_dev_mph); 533 goto err; 534 } 535 536 usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL; 537 usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask; 538 539 usb_data.operating_mode = FSL_USB2_MPH_HOST; 540 541 prop = of_get_property(np, "port0", NULL); 542 if (prop) 543 usb_data.port_enables |= FSL_USB2_PORT0_ENABLED; 544 545 prop = of_get_property(np, "port1", NULL); 546 if (prop) 547 usb_data.port_enables |= FSL_USB2_PORT1_ENABLED; 548 549 prop = of_get_property(np, "phy_type", NULL); 550 usb_data.phy_mode = determine_usb_phy(prop); 551 552 ret = 553 platform_device_add_data(usb_dev_mph, &usb_data, 554 sizeof(struct 555 fsl_usb2_platform_data)); 556 if (ret) 557 goto unreg_mph; 558 } 559 560 for (np = NULL; 561 (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL; 562 i++) { 563 struct resource r[2]; 564 struct fsl_usb2_platform_data usb_data; 565 const unsigned char *prop = NULL; 566 567 memset(&r, 0, sizeof(r)); 568 memset(&usb_data, 0, sizeof(usb_data)); 569 570 ret = of_address_to_resource(np, 0, &r[0]); 571 if (ret) 572 goto unreg_mph; 573 574 of_irq_to_resource(np, 0, &r[1]); 575 576 prop = of_get_property(np, "dr_mode", NULL); 577 578 if (!prop || !strcmp(prop, "host")) { 579 usb_data.operating_mode = FSL_USB2_DR_HOST; 580 usb_dev_dr_host = platform_device_register_simple( 581 "fsl-ehci", i, r, 2); 582 if (IS_ERR(usb_dev_dr_host)) { 583 ret = PTR_ERR(usb_dev_dr_host); 584 goto err; 585 } 586 } else if (prop && !strcmp(prop, "peripheral")) { 587 usb_data.operating_mode = FSL_USB2_DR_DEVICE; 588 usb_dev_dr_client = platform_device_register_simple( 589 "fsl-usb2-udc", i, r, 2); 590 if (IS_ERR(usb_dev_dr_client)) { 591 ret = PTR_ERR(usb_dev_dr_client); 592 goto err; 593 } 594 } else if (prop && !strcmp(prop, "otg")) { 595 usb_data.operating_mode = FSL_USB2_DR_OTG; 596 usb_dev_dr_host = platform_device_register_simple( 597 "fsl-ehci", i, r, 2); 598 if (IS_ERR(usb_dev_dr_host)) { 599 ret = PTR_ERR(usb_dev_dr_host); 600 goto err; 601 } 602 usb_dev_dr_client = platform_device_register_simple( 603 "fsl-usb2-udc", i, r, 2); 604 if (IS_ERR(usb_dev_dr_client)) { 605 ret = PTR_ERR(usb_dev_dr_client); 606 goto err; 607 } 608 } else { 609 ret = -EINVAL; 610 goto err; 611 } 612 613 prop = of_get_property(np, "phy_type", NULL); 614 usb_data.phy_mode = determine_usb_phy(prop); 615 616 if (usb_dev_dr_host) { 617 usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL; 618 usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host-> 619 dev.coherent_dma_mask; 620 if ((ret = platform_device_add_data(usb_dev_dr_host, 621 &usb_data, sizeof(struct 622 fsl_usb2_platform_data)))) 623 goto unreg_dr; 624 } 625 if (usb_dev_dr_client) { 626 usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL; 627 usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client-> 628 dev.coherent_dma_mask; 629 if ((ret = platform_device_add_data(usb_dev_dr_client, 630 &usb_data, sizeof(struct 631 fsl_usb2_platform_data)))) 632 goto unreg_dr; 633 } 634 } 635 return 0; 636 637 unreg_dr: 638 if (usb_dev_dr_host) 639 platform_device_unregister(usb_dev_dr_host); 640 if (usb_dev_dr_client) 641 platform_device_unregister(usb_dev_dr_client); 642 unreg_mph: 643 if (usb_dev_mph) 644 platform_device_unregister(usb_dev_mph); 645 err: 646 return ret; 647 } 648 649 arch_initcall(fsl_usb_of_init); 650 651 #ifdef CONFIG_CPM2 652 653 extern void init_scc_ioports(struct fs_uart_platform_info*); 654 655 static const char fcc_regs[] = "fcc_regs"; 656 static const char fcc_regs_c[] = "fcc_regs_c"; 657 static const char fcc_pram[] = "fcc_pram"; 658 static char bus_id[9][BUS_ID_SIZE]; 659 660 static int __init fs_enet_of_init(void) 661 { 662 struct device_node *np; 663 unsigned int i; 664 struct platform_device *fs_enet_dev; 665 struct resource res; 666 int ret; 667 668 for (np = NULL, i = 0; 669 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; 670 i++) { 671 struct resource r[4]; 672 struct device_node *phy, *mdio; 673 struct fs_platform_info fs_enet_data; 674 const unsigned int *id, *phy_addr, *phy_irq; 675 const void *mac_addr; 676 const phandle *ph; 677 const char *model; 678 679 memset(r, 0, sizeof(r)); 680 memset(&fs_enet_data, 0, sizeof(fs_enet_data)); 681 682 ret = of_address_to_resource(np, 0, &r[0]); 683 if (ret) 684 goto err; 685 r[0].name = fcc_regs; 686 687 ret = of_address_to_resource(np, 1, &r[1]); 688 if (ret) 689 goto err; 690 r[1].name = fcc_pram; 691 692 ret = of_address_to_resource(np, 2, &r[2]); 693 if (ret) 694 goto err; 695 r[2].name = fcc_regs_c; 696 fs_enet_data.fcc_regs_c = r[2].start; 697 698 of_irq_to_resource(np, 0, &r[3]); 699 700 fs_enet_dev = 701 platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4); 702 703 if (IS_ERR(fs_enet_dev)) { 704 ret = PTR_ERR(fs_enet_dev); 705 goto err; 706 } 707 708 model = of_get_property(np, "model", NULL); 709 if (model == NULL) { 710 ret = -ENODEV; 711 goto unreg; 712 } 713 714 mac_addr = of_get_mac_address(np); 715 if (mac_addr) 716 memcpy(fs_enet_data.macaddr, mac_addr, 6); 717 718 ph = of_get_property(np, "phy-handle", NULL); 719 phy = of_find_node_by_phandle(*ph); 720 721 if (phy == NULL) { 722 ret = -ENODEV; 723 goto unreg; 724 } 725 726 phy_addr = of_get_property(phy, "reg", NULL); 727 fs_enet_data.phy_addr = *phy_addr; 728 729 phy_irq = of_get_property(phy, "interrupts", NULL); 730 731 id = of_get_property(np, "device-id", NULL); 732 fs_enet_data.fs_no = *id; 733 strcpy(fs_enet_data.fs_type, model); 734 735 mdio = of_get_parent(phy); 736 ret = of_address_to_resource(mdio, 0, &res); 737 if (ret) { 738 of_node_put(phy); 739 of_node_put(mdio); 740 goto unreg; 741 } 742 743 fs_enet_data.clk_rx = *((u32 *)of_get_property(np, 744 "rx-clock", NULL)); 745 fs_enet_data.clk_tx = *((u32 *)of_get_property(np, 746 "tx-clock", NULL)); 747 748 if (strstr(model, "FCC")) { 749 int fcc_index = *id - 1; 750 const unsigned char *mdio_bb_prop; 751 752 fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0); 753 fs_enet_data.rx_ring = 32; 754 fs_enet_data.tx_ring = 32; 755 fs_enet_data.rx_copybreak = 240; 756 fs_enet_data.use_napi = 0; 757 fs_enet_data.napi_weight = 17; 758 fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index); 759 fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index); 760 fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index); 761 762 snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x", 763 (u32)res.start, fs_enet_data.phy_addr); 764 fs_enet_data.bus_id = (char*)&bus_id[(*id)]; 765 fs_enet_data.init_ioports = init_fcc_ioports; 766 767 mdio_bb_prop = of_get_property(phy, "bitbang", NULL); 768 if (mdio_bb_prop) { 769 struct platform_device *fs_enet_mdio_bb_dev; 770 struct fs_mii_bb_platform_info fs_enet_mdio_bb_data; 771 772 fs_enet_mdio_bb_dev = 773 platform_device_register_simple("fsl-bb-mdio", 774 i, NULL, 0); 775 memset(&fs_enet_mdio_bb_data, 0, 776 sizeof(struct fs_mii_bb_platform_info)); 777 fs_enet_mdio_bb_data.mdio_dat.bit = 778 mdio_bb_prop[0]; 779 fs_enet_mdio_bb_data.mdio_dir.bit = 780 mdio_bb_prop[1]; 781 fs_enet_mdio_bb_data.mdc_dat.bit = 782 mdio_bb_prop[2]; 783 fs_enet_mdio_bb_data.mdio_port = 784 mdio_bb_prop[3]; 785 fs_enet_mdio_bb_data.mdc_port = 786 mdio_bb_prop[4]; 787 fs_enet_mdio_bb_data.delay = 788 mdio_bb_prop[5]; 789 790 fs_enet_mdio_bb_data.irq[0] = phy_irq[0]; 791 fs_enet_mdio_bb_data.irq[1] = -1; 792 fs_enet_mdio_bb_data.irq[2] = -1; 793 fs_enet_mdio_bb_data.irq[3] = phy_irq[0]; 794 fs_enet_mdio_bb_data.irq[31] = -1; 795 796 fs_enet_mdio_bb_data.mdio_dat.offset = 797 (u32)&cpm2_immr->im_ioport.iop_pdatc; 798 fs_enet_mdio_bb_data.mdio_dir.offset = 799 (u32)&cpm2_immr->im_ioport.iop_pdirc; 800 fs_enet_mdio_bb_data.mdc_dat.offset = 801 (u32)&cpm2_immr->im_ioport.iop_pdatc; 802 803 ret = platform_device_add_data( 804 fs_enet_mdio_bb_dev, 805 &fs_enet_mdio_bb_data, 806 sizeof(struct fs_mii_bb_platform_info)); 807 if (ret) 808 goto unreg; 809 } 810 811 of_node_put(phy); 812 of_node_put(mdio); 813 814 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, 815 sizeof(struct 816 fs_platform_info)); 817 if (ret) 818 goto unreg; 819 } 820 } 821 return 0; 822 823 unreg: 824 platform_device_unregister(fs_enet_dev); 825 err: 826 return ret; 827 } 828 829 arch_initcall(fs_enet_of_init); 830 831 static const char scc_regs[] = "regs"; 832 static const char scc_pram[] = "pram"; 833 834 static int __init cpm_uart_of_init(void) 835 { 836 struct device_node *np; 837 unsigned int i; 838 struct platform_device *cpm_uart_dev; 839 int ret; 840 841 for (np = NULL, i = 0; 842 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; 843 i++) { 844 struct resource r[3]; 845 struct fs_uart_platform_info cpm_uart_data; 846 const int *id; 847 const char *model; 848 849 memset(r, 0, sizeof(r)); 850 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); 851 852 ret = of_address_to_resource(np, 0, &r[0]); 853 if (ret) 854 goto err; 855 856 r[0].name = scc_regs; 857 858 ret = of_address_to_resource(np, 1, &r[1]); 859 if (ret) 860 goto err; 861 r[1].name = scc_pram; 862 863 of_irq_to_resource(np, 0, &r[2]); 864 865 cpm_uart_dev = 866 platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3); 867 868 if (IS_ERR(cpm_uart_dev)) { 869 ret = PTR_ERR(cpm_uart_dev); 870 goto err; 871 } 872 873 id = of_get_property(np, "device-id", NULL); 874 cpm_uart_data.fs_no = *id; 875 876 model = of_get_property(np, "model", NULL); 877 strcpy(cpm_uart_data.fs_type, model); 878 879 cpm_uart_data.uart_clk = ppc_proc_freq; 880 881 cpm_uart_data.tx_num_fifo = 4; 882 cpm_uart_data.tx_buf_size = 32; 883 cpm_uart_data.rx_num_fifo = 4; 884 cpm_uart_data.rx_buf_size = 32; 885 cpm_uart_data.clk_rx = *((u32 *)of_get_property(np, 886 "rx-clock", NULL)); 887 cpm_uart_data.clk_tx = *((u32 *)of_get_property(np, 888 "tx-clock", NULL)); 889 890 ret = 891 platform_device_add_data(cpm_uart_dev, &cpm_uart_data, 892 sizeof(struct 893 fs_uart_platform_info)); 894 if (ret) 895 goto unreg; 896 } 897 898 return 0; 899 900 unreg: 901 platform_device_unregister(cpm_uart_dev); 902 err: 903 return ret; 904 } 905 906 arch_initcall(cpm_uart_of_init); 907 #endif /* CONFIG_CPM2 */ 908 909 #ifdef CONFIG_8xx 910 911 extern void init_scc_ioports(struct fs_platform_info*); 912 extern int platform_device_skip(const char *model, int id); 913 914 static int __init fs_enet_mdio_of_init(void) 915 { 916 struct device_node *np; 917 unsigned int i; 918 struct platform_device *mdio_dev; 919 struct resource res; 920 int ret; 921 922 for (np = NULL, i = 0; 923 (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL; 924 i++) { 925 struct fs_mii_fec_platform_info mdio_data; 926 927 memset(&res, 0, sizeof(res)); 928 memset(&mdio_data, 0, sizeof(mdio_data)); 929 930 ret = of_address_to_resource(np, 0, &res); 931 if (ret) 932 goto err; 933 934 mdio_dev = 935 platform_device_register_simple("fsl-cpm-fec-mdio", 936 res.start, &res, 1); 937 if (IS_ERR(mdio_dev)) { 938 ret = PTR_ERR(mdio_dev); 939 goto err; 940 } 941 942 mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1; 943 944 ret = 945 platform_device_add_data(mdio_dev, &mdio_data, 946 sizeof(struct fs_mii_fec_platform_info)); 947 if (ret) 948 goto unreg; 949 } 950 return 0; 951 952 unreg: 953 platform_device_unregister(mdio_dev); 954 err: 955 return ret; 956 } 957 958 arch_initcall(fs_enet_mdio_of_init); 959 960 static const char *enet_regs = "regs"; 961 static const char *enet_pram = "pram"; 962 static const char *enet_irq = "interrupt"; 963 static char bus_id[9][BUS_ID_SIZE]; 964 965 static int __init fs_enet_of_init(void) 966 { 967 struct device_node *np; 968 unsigned int i; 969 struct platform_device *fs_enet_dev = NULL; 970 struct resource res; 971 int ret; 972 973 for (np = NULL, i = 0; 974 (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL; 975 i++) { 976 struct resource r[4]; 977 struct device_node *phy = NULL, *mdio = NULL; 978 struct fs_platform_info fs_enet_data; 979 const unsigned int *id; 980 const unsigned int *phy_addr; 981 const void *mac_addr; 982 const phandle *ph; 983 const char *model; 984 985 memset(r, 0, sizeof(r)); 986 memset(&fs_enet_data, 0, sizeof(fs_enet_data)); 987 988 model = of_get_property(np, "model", NULL); 989 if (model == NULL) { 990 ret = -ENODEV; 991 goto unreg; 992 } 993 994 id = of_get_property(np, "device-id", NULL); 995 fs_enet_data.fs_no = *id; 996 997 if (platform_device_skip(model, *id)) 998 continue; 999 1000 ret = of_address_to_resource(np, 0, &r[0]); 1001 if (ret) 1002 goto err; 1003 r[0].name = enet_regs; 1004 1005 mac_addr = of_get_mac_address(np); 1006 if (mac_addr) 1007 memcpy(fs_enet_data.macaddr, mac_addr, 6); 1008 1009 ph = of_get_property(np, "phy-handle", NULL); 1010 if (ph != NULL) 1011 phy = of_find_node_by_phandle(*ph); 1012 1013 if (phy != NULL) { 1014 phy_addr = of_get_property(phy, "reg", NULL); 1015 fs_enet_data.phy_addr = *phy_addr; 1016 fs_enet_data.has_phy = 1; 1017 1018 mdio = of_get_parent(phy); 1019 ret = of_address_to_resource(mdio, 0, &res); 1020 if (ret) { 1021 of_node_put(phy); 1022 of_node_put(mdio); 1023 goto unreg; 1024 } 1025 } 1026 1027 model = of_get_property(np, "model", NULL); 1028 strcpy(fs_enet_data.fs_type, model); 1029 1030 if (strstr(model, "FEC")) { 1031 r[1].start = r[1].end = irq_of_parse_and_map(np, 0); 1032 r[1].flags = IORESOURCE_IRQ; 1033 r[1].name = enet_irq; 1034 1035 fs_enet_dev = 1036 platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2); 1037 1038 if (IS_ERR(fs_enet_dev)) { 1039 ret = PTR_ERR(fs_enet_dev); 1040 goto err; 1041 } 1042 1043 fs_enet_data.rx_ring = 128; 1044 fs_enet_data.tx_ring = 16; 1045 fs_enet_data.rx_copybreak = 240; 1046 fs_enet_data.use_napi = 1; 1047 fs_enet_data.napi_weight = 17; 1048 1049 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x", 1050 (u32)res.start, fs_enet_data.phy_addr); 1051 fs_enet_data.bus_id = (char*)&bus_id[i]; 1052 fs_enet_data.init_ioports = init_fec_ioports; 1053 } 1054 if (strstr(model, "SCC")) { 1055 ret = of_address_to_resource(np, 1, &r[1]); 1056 if (ret) 1057 goto err; 1058 r[1].name = enet_pram; 1059 1060 r[2].start = r[2].end = irq_of_parse_and_map(np, 0); 1061 r[2].flags = IORESOURCE_IRQ; 1062 r[2].name = enet_irq; 1063 1064 fs_enet_dev = 1065 platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3); 1066 1067 if (IS_ERR(fs_enet_dev)) { 1068 ret = PTR_ERR(fs_enet_dev); 1069 goto err; 1070 } 1071 1072 fs_enet_data.rx_ring = 64; 1073 fs_enet_data.tx_ring = 8; 1074 fs_enet_data.rx_copybreak = 240; 1075 fs_enet_data.use_napi = 1; 1076 fs_enet_data.napi_weight = 17; 1077 1078 snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1"); 1079 fs_enet_data.bus_id = (char*)&bus_id[i]; 1080 fs_enet_data.init_ioports = init_scc_ioports; 1081 } 1082 1083 of_node_put(phy); 1084 of_node_put(mdio); 1085 1086 ret = platform_device_add_data(fs_enet_dev, &fs_enet_data, 1087 sizeof(struct 1088 fs_platform_info)); 1089 if (ret) 1090 goto unreg; 1091 } 1092 return 0; 1093 1094 unreg: 1095 platform_device_unregister(fs_enet_dev); 1096 err: 1097 return ret; 1098 } 1099 1100 arch_initcall(fs_enet_of_init); 1101 1102 static int __init fsl_pcmcia_of_init(void) 1103 { 1104 struct device_node *np = NULL; 1105 /* 1106 * Register all the devices which type is "pcmcia" 1107 */ 1108 while ((np = of_find_compatible_node(np, 1109 "pcmcia", "fsl,pq-pcmcia")) != NULL) 1110 of_platform_device_create(np, "m8xx-pcmcia", NULL); 1111 return 0; 1112 } 1113 1114 arch_initcall(fsl_pcmcia_of_init); 1115 1116 static const char *smc_regs = "regs"; 1117 static const char *smc_pram = "pram"; 1118 1119 static int __init cpm_smc_uart_of_init(void) 1120 { 1121 struct device_node *np; 1122 unsigned int i; 1123 struct platform_device *cpm_uart_dev; 1124 int ret; 1125 1126 for (np = NULL, i = 0; 1127 (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL; 1128 i++) { 1129 struct resource r[3]; 1130 struct fs_uart_platform_info cpm_uart_data; 1131 const int *id; 1132 const char *model; 1133 1134 memset(r, 0, sizeof(r)); 1135 memset(&cpm_uart_data, 0, sizeof(cpm_uart_data)); 1136 1137 ret = of_address_to_resource(np, 0, &r[0]); 1138 if (ret) 1139 goto err; 1140 1141 r[0].name = smc_regs; 1142 1143 ret = of_address_to_resource(np, 1, &r[1]); 1144 if (ret) 1145 goto err; 1146 r[1].name = smc_pram; 1147 1148 r[2].start = r[2].end = irq_of_parse_and_map(np, 0); 1149 r[2].flags = IORESOURCE_IRQ; 1150 1151 cpm_uart_dev = 1152 platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3); 1153 1154 if (IS_ERR(cpm_uart_dev)) { 1155 ret = PTR_ERR(cpm_uart_dev); 1156 goto err; 1157 } 1158 1159 model = of_get_property(np, "model", NULL); 1160 strcpy(cpm_uart_data.fs_type, model); 1161 1162 id = of_get_property(np, "device-id", NULL); 1163 cpm_uart_data.fs_no = *id; 1164 cpm_uart_data.uart_clk = ppc_proc_freq; 1165 1166 cpm_uart_data.tx_num_fifo = 4; 1167 cpm_uart_data.tx_buf_size = 32; 1168 cpm_uart_data.rx_num_fifo = 4; 1169 cpm_uart_data.rx_buf_size = 32; 1170 1171 ret = 1172 platform_device_add_data(cpm_uart_dev, &cpm_uart_data, 1173 sizeof(struct 1174 fs_uart_platform_info)); 1175 if (ret) 1176 goto unreg; 1177 } 1178 1179 return 0; 1180 1181 unreg: 1182 platform_device_unregister(cpm_uart_dev); 1183 err: 1184 return ret; 1185 } 1186 1187 arch_initcall(cpm_smc_uart_of_init); 1188 1189 #endif /* CONFIG_8xx */ 1190