tsi108_dev.c 3.6 KB

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