tsi108_dev.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 <linux/of_net.h>
  22. #include <asm/tsi108.h>
  23. #include <asm/system.h>
  24. #include <asm/atomic.h>
  25. #include <asm/io.h>
  26. #include <asm/irq.h>
  27. #include <asm/prom.h>
  28. #include <mm/mmu_decl.h>
  29. #undef DEBUG
  30. #ifdef DEBUG
  31. #define DBG(fmt...) do { printk(fmt); } while(0)
  32. #else
  33. #define DBG(fmt...) do { } while(0)
  34. #endif
  35. static phys_addr_t tsi108_csr_base = -1;
  36. phys_addr_t get_csrbase(void)
  37. {
  38. struct device_node *tsi;
  39. if (tsi108_csr_base != -1)
  40. return tsi108_csr_base;
  41. tsi = of_find_node_by_type(NULL, "tsi-bridge");
  42. if (tsi) {
  43. unsigned int size;
  44. const void *prop = of_get_property(tsi, "reg", &size);
  45. tsi108_csr_base = of_translate_address(tsi, prop);
  46. of_node_put(tsi);
  47. };
  48. return tsi108_csr_base;
  49. }
  50. u32 get_vir_csrbase(void)
  51. {
  52. return (u32) (ioremap(get_csrbase(), 0x10000));
  53. }
  54. EXPORT_SYMBOL(get_csrbase);
  55. EXPORT_SYMBOL(get_vir_csrbase);
  56. static int __init tsi108_eth_of_init(void)
  57. {
  58. struct device_node *np;
  59. unsigned int i = 0;
  60. struct platform_device *tsi_eth_dev;
  61. struct resource res;
  62. int ret;
  63. for_each_compatible_node(np, "network", "tsi108-ethernet") {
  64. struct resource r[2];
  65. struct device_node *phy, *mdio;
  66. hw_info tsi_eth_data;
  67. const unsigned int *phy_id;
  68. const void *mac_addr;
  69. const phandle *ph;
  70. memset(r, 0, sizeof(r));
  71. memset(&tsi_eth_data, 0, sizeof(tsi_eth_data));
  72. ret = of_address_to_resource(np, 0, &r[0]);
  73. DBG("%s: name:start->end = %s:%pR\n",
  74. __func__, r[0].name, &r[0]);
  75. if (ret)
  76. goto err;
  77. r[1].name = "tx";
  78. r[1].start = irq_of_parse_and_map(np, 0);
  79. r[1].end = irq_of_parse_and_map(np, 0);
  80. r[1].flags = IORESOURCE_IRQ;
  81. DBG("%s: name:start->end = %s:%pR\n",
  82. __func__, r[1].name, &r[1]);
  83. tsi_eth_dev =
  84. platform_device_register_simple("tsi-ethernet", i++, &r[0],
  85. 1);
  86. if (IS_ERR(tsi_eth_dev)) {
  87. ret = PTR_ERR(tsi_eth_dev);
  88. goto err;
  89. }
  90. mac_addr = of_get_mac_address(np);
  91. if (mac_addr)
  92. memcpy(tsi_eth_data.mac_addr, mac_addr, 6);
  93. ph = of_get_property(np, "mdio-handle", NULL);
  94. mdio = of_find_node_by_phandle(*ph);
  95. ret = of_address_to_resource(mdio, 0, &res);
  96. of_node_put(mdio);
  97. if (ret)
  98. goto unreg;
  99. ph = of_get_property(np, "phy-handle", NULL);
  100. phy = of_find_node_by_phandle(*ph);
  101. if (phy == NULL) {
  102. ret = -ENODEV;
  103. goto unreg;
  104. }
  105. phy_id = of_get_property(phy, "reg", NULL);
  106. tsi_eth_data.regs = r[0].start;
  107. tsi_eth_data.phyregs = res.start;
  108. tsi_eth_data.phy = *phy_id;
  109. tsi_eth_data.irq_num = irq_of_parse_and_map(np, 0);
  110. /* Some boards with the TSI108 bridge (e.g. Holly)
  111. * have a miswiring of the ethernet PHYs which
  112. * requires a workaround. The special
  113. * "txc-rxc-delay-disable" property enables this
  114. * workaround. FIXME: Need to port the tsi108_eth
  115. * driver itself to phylib and use a non-misleading
  116. * name for the workaround flag - it's not actually to
  117. * do with the model of PHY in use */
  118. if (of_get_property(phy, "txc-rxc-delay-disable", NULL))
  119. tsi_eth_data.phy_type = TSI108_PHY_BCM54XX;
  120. of_node_put(phy);
  121. ret =
  122. platform_device_add_data(tsi_eth_dev, &tsi_eth_data,
  123. sizeof(hw_info));
  124. if (ret)
  125. goto unreg;
  126. }
  127. return 0;
  128. unreg:
  129. platform_device_unregister(tsi_eth_dev);
  130. err:
  131. of_node_put(np);
  132. return ret;
  133. }
  134. arch_initcall(tsi108_eth_of_init);