tsi108_dev.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * tsi108/109 device setup code
  3. *
  4. * Maintained by Roy Zang < tie-fei.zang@freescale.com >
  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. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/errno.h>
  15. #include <linux/major.h>
  16. #include <linux/delay.h>
  17. #include <linux/irq.h>
  18. #include <linux/module.h>
  19. #include <linux/device.h>
  20. #include <linux/platform_device.h>
  21. #include <asm/tsi108.h>
  22. #include <asm/system.h>
  23. #include <asm/atomic.h>
  24. #include <asm/io.h>
  25. #include <asm/irq.h>
  26. #include <asm/prom.h>
  27. #include <mm/mmu_decl.h>
  28. #undef DEBUG
  29. #ifdef DEBUG
  30. #define DBG(fmt...) do { printk(fmt); } while(0)
  31. #else
  32. #define DBG(fmt...) do { } while(0)
  33. #endif
  34. static phys_addr_t tsi108_csr_base = -1;
  35. phys_addr_t get_csrbase(void)
  36. {
  37. struct device_node *tsi;
  38. if (tsi108_csr_base != -1)
  39. return tsi108_csr_base;
  40. tsi = of_find_node_by_type(NULL, "tsi-bridge");
  41. if (tsi) {
  42. unsigned int size;
  43. void *prop = get_property(tsi, "reg", &size);
  44. tsi108_csr_base = of_translate_address(tsi, prop);
  45. of_node_put(tsi);
  46. };
  47. return tsi108_csr_base;
  48. }
  49. u32 get_vir_csrbase(void)
  50. {
  51. return (u32) (ioremap(get_csrbase(), 0x10000));
  52. }
  53. EXPORT_SYMBOL(get_csrbase);
  54. EXPORT_SYMBOL(get_vir_csrbase);
  55. static int __init tsi108_eth_of_init(void)
  56. {
  57. struct device_node *np;
  58. unsigned int i;
  59. struct platform_device *tsi_eth_dev;
  60. struct resource res;
  61. int ret;
  62. for (np = NULL, i = 0;
  63. (np = of_find_compatible_node(np, "network", "tsi-ethernet")) != NULL;
  64. i++) {
  65. struct resource r[2];
  66. struct device_node *phy;
  67. hw_info tsi_eth_data;
  68. unsigned int *id;
  69. unsigned int *phy_id;
  70. void *mac_addr;
  71. phandle *ph;
  72. memset(r, 0, sizeof(r));
  73. memset(&tsi_eth_data, 0, sizeof(tsi_eth_data));
  74. ret = of_address_to_resource(np, 0, &r[0]);
  75. DBG("%s: name:start->end = %s:0x%lx-> 0x%lx\n",
  76. __FUNCTION__,r[0].name, r[0].start, r[0].end);
  77. if (ret)
  78. goto err;
  79. r[1].name = "tx";
  80. r[1].start = irq_of_parse_and_map(np, 0);
  81. r[1].end = irq_of_parse_and_map(np, 0);
  82. r[1].flags = IORESOURCE_IRQ;
  83. DBG("%s: name:start->end = %s:0x%lx-> 0x%lx\n",
  84. __FUNCTION__,r[1].name, r[1].start, r[1].end);
  85. tsi_eth_dev =
  86. platform_device_register_simple("tsi-ethernet", i, &r[0],
  87. 1);
  88. if (IS_ERR(tsi_eth_dev)) {
  89. ret = PTR_ERR(tsi_eth_dev);
  90. goto err;
  91. }
  92. mac_addr = get_property(np, "address", NULL);
  93. memcpy(tsi_eth_data.mac_addr, mac_addr, 6);
  94. ph = (phandle *) get_property(np, "phy-handle", NULL);
  95. phy = of_find_node_by_phandle(*ph);
  96. if (phy == NULL) {
  97. ret = -ENODEV;
  98. goto unreg;
  99. }
  100. id = (u32 *) get_property(phy, "reg", NULL);
  101. phy_id = (u32 *) get_property(phy, "phy-id", NULL);
  102. ret = of_address_to_resource(phy, 0, &res);
  103. if (ret) {
  104. of_node_put(phy);
  105. goto unreg;
  106. }
  107. tsi_eth_data.regs = r[0].start;
  108. tsi_eth_data.phyregs = res.start;
  109. tsi_eth_data.phy = *phy_id;
  110. tsi_eth_data.irq_num = irq_of_parse_and_map(np, 0);
  111. of_node_put(phy);
  112. ret =
  113. platform_device_add_data(tsi_eth_dev, &tsi_eth_data,
  114. sizeof(hw_info));
  115. if (ret)
  116. goto unreg;
  117. }
  118. return 0;
  119. unreg:
  120. platform_device_unregister(tsi_eth_dev);
  121. err:
  122. return ret;
  123. }
  124. arch_initcall(tsi108_eth_of_init);