tsi108_dev.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/export.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 <linux/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. const void *prop = of_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 = 0;
  59. struct platform_device *tsi_eth_dev;
  60. struct resource res;
  61. int ret;
  62. for_each_compatible_node(np, "network", "tsi108-ethernet") {
  63. struct resource r[2];
  64. struct device_node *phy, *mdio;
  65. hw_info tsi_eth_data;
  66. const unsigned int *phy_id;
  67. const void *mac_addr;
  68. const phandle *ph;
  69. memset(r, 0, sizeof(r));
  70. memset(&tsi_eth_data, 0, sizeof(tsi_eth_data));
  71. ret = of_address_to_resource(np, 0, &r[0]);
  72. DBG("%s: name:start->end = %s:%pR\n",
  73. __func__, r[0].name, &r[0]);
  74. if (ret)
  75. goto err;
  76. r[1].name = "tx";
  77. r[1].start = irq_of_parse_and_map(np, 0);
  78. r[1].end = irq_of_parse_and_map(np, 0);
  79. r[1].flags = IORESOURCE_IRQ;
  80. DBG("%s: name:start->end = %s:%pR\n",
  81. __func__, r[1].name, &r[1]);
  82. tsi_eth_dev =
  83. platform_device_register_simple("tsi-ethernet", i++, &r[0],
  84. 1);
  85. if (IS_ERR(tsi_eth_dev)) {
  86. ret = PTR_ERR(tsi_eth_dev);
  87. goto err;
  88. }
  89. mac_addr = of_get_mac_address(np);
  90. if (mac_addr)
  91. memcpy(tsi_eth_data.mac_addr, mac_addr, 6);
  92. ph = of_get_property(np, "mdio-handle", NULL);
  93. mdio = of_find_node_by_phandle(*ph);
  94. ret = of_address_to_resource(mdio, 0, &res);
  95. of_node_put(mdio);
  96. if (ret)
  97. goto unreg;
  98. ph = of_get_property(np, "phy-handle", NULL);
  99. phy = of_find_node_by_phandle(*ph);
  100. if (phy == NULL) {
  101. ret = -ENODEV;
  102. goto unreg;
  103. }
  104. phy_id = of_get_property(phy, "reg", NULL);
  105. tsi_eth_data.regs = r[0].start;
  106. tsi_eth_data.phyregs = res.start;
  107. tsi_eth_data.phy = *phy_id;
  108. tsi_eth_data.irq_num = irq_of_parse_and_map(np, 0);
  109. /* Some boards with the TSI108 bridge (e.g. Holly)
  110. * have a miswiring of the ethernet PHYs which
  111. * requires a workaround. The special
  112. * "txc-rxc-delay-disable" property enables this
  113. * workaround. FIXME: Need to port the tsi108_eth
  114. * driver itself to phylib and use a non-misleading
  115. * name for the workaround flag - it's not actually to
  116. * do with the model of PHY in use */
  117. if (of_get_property(phy, "txc-rxc-delay-disable", NULL))
  118. tsi_eth_data.phy_type = TSI108_PHY_BCM54XX;
  119. of_node_put(phy);
  120. ret =
  121. platform_device_add_data(tsi_eth_dev, &tsi_eth_data,
  122. sizeof(hw_info));
  123. if (ret)
  124. goto unreg;
  125. }
  126. return 0;
  127. unreg:
  128. platform_device_unregister(tsi_eth_dev);
  129. err:
  130. of_node_put(np);
  131. return ret;
  132. }
  133. arch_initcall(tsi108_eth_of_init);