tsi108_dev.c 3.8 KB

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