msp_eth.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * The setup file for ethernet related hardware on PMC-Sierra MSP processors.
  3. *
  4. * Copyright 2010 PMC-Sierra, Inc.
  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. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  14. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  18. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 675 Mass Ave, Cambridge, MA 02139, USA.
  25. */
  26. #include <linux/init.h>
  27. #include <linux/kernel.h>
  28. #include <linux/ioport.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/delay.h>
  31. #include <msp_regs.h>
  32. #include <msp_int.h>
  33. #include <msp_gpio_macros.h>
  34. #define MSP_ETHERNET_GPIO0 14
  35. #define MSP_ETHERNET_GPIO1 15
  36. #define MSP_ETHERNET_GPIO2 16
  37. #ifdef CONFIG_MSP_HAS_TSMAC
  38. #define MSP_TSMAC_SIZE 0x10020
  39. #define MSP_TSMAC_ID "pmc_tsmac"
  40. static struct resource msp_tsmac0_resources[] = {
  41. [0] = {
  42. .start = MSP_MAC0_BASE,
  43. .end = MSP_MAC0_BASE + MSP_TSMAC_SIZE - 1,
  44. .flags = IORESOURCE_MEM,
  45. },
  46. [1] = {
  47. .start = MSP_INT_MAC0,
  48. .end = MSP_INT_MAC0,
  49. .flags = IORESOURCE_IRQ,
  50. },
  51. };
  52. static struct resource msp_tsmac1_resources[] = {
  53. [0] = {
  54. .start = MSP_MAC1_BASE,
  55. .end = MSP_MAC1_BASE + MSP_TSMAC_SIZE - 1,
  56. .flags = IORESOURCE_MEM,
  57. },
  58. [1] = {
  59. .start = MSP_INT_MAC1,
  60. .end = MSP_INT_MAC1,
  61. .flags = IORESOURCE_IRQ,
  62. },
  63. };
  64. static struct resource msp_tsmac2_resources[] = {
  65. [0] = {
  66. .start = MSP_MAC2_BASE,
  67. .end = MSP_MAC2_BASE + MSP_TSMAC_SIZE - 1,
  68. .flags = IORESOURCE_MEM,
  69. },
  70. [1] = {
  71. .start = MSP_INT_SAR,
  72. .end = MSP_INT_SAR,
  73. .flags = IORESOURCE_IRQ,
  74. },
  75. };
  76. static struct platform_device tsmac_device[] = {
  77. [0] = {
  78. .name = MSP_TSMAC_ID,
  79. .id = 0,
  80. .num_resources = ARRAY_SIZE(msp_tsmac0_resources),
  81. .resource = msp_tsmac0_resources,
  82. },
  83. [1] = {
  84. .name = MSP_TSMAC_ID,
  85. .id = 1,
  86. .num_resources = ARRAY_SIZE(msp_tsmac1_resources),
  87. .resource = msp_tsmac1_resources,
  88. },
  89. [2] = {
  90. .name = MSP_TSMAC_ID,
  91. .id = 2,
  92. .num_resources = ARRAY_SIZE(msp_tsmac2_resources),
  93. .resource = msp_tsmac2_resources,
  94. },
  95. };
  96. #define msp_eth_devs tsmac_device
  97. #else
  98. /* If it is not TSMAC assume MSP_ETH (100Mbps) */
  99. #define MSP_ETH_ID "pmc_mspeth"
  100. #define MSP_ETH_SIZE 0xE0
  101. static struct resource msp_eth0_resources[] = {
  102. [0] = {
  103. .start = MSP_MAC0_BASE,
  104. .end = MSP_MAC0_BASE + MSP_ETH_SIZE - 1,
  105. .flags = IORESOURCE_MEM,
  106. },
  107. [1] = {
  108. .start = MSP_INT_MAC0,
  109. .end = MSP_INT_MAC0,
  110. .flags = IORESOURCE_IRQ,
  111. },
  112. };
  113. static struct resource msp_eth1_resources[] = {
  114. [0] = {
  115. .start = MSP_MAC1_BASE,
  116. .end = MSP_MAC1_BASE + MSP_ETH_SIZE - 1,
  117. .flags = IORESOURCE_MEM,
  118. },
  119. [1] = {
  120. .start = MSP_INT_MAC1,
  121. .end = MSP_INT_MAC1,
  122. .flags = IORESOURCE_IRQ,
  123. },
  124. };
  125. static struct platform_device mspeth_device[] = {
  126. [0] = {
  127. .name = MSP_ETH_ID,
  128. .id = 0,
  129. .num_resources = ARRAY_SIZE(msp_eth0_resources),
  130. .resource = msp_eth0_resources,
  131. },
  132. [1] = {
  133. .name = MSP_ETH_ID,
  134. .id = 1,
  135. .num_resources = ARRAY_SIZE(msp_eth1_resources),
  136. .resource = msp_eth1_resources,
  137. },
  138. };
  139. #define msp_eth_devs mspeth_device
  140. #endif
  141. int __init msp_eth_setup(void)
  142. {
  143. int i, ret = 0;
  144. /* Configure the GPIO and take the ethernet PHY out of reset */
  145. msp_gpio_pin_mode(MSP_GPIO_OUTPUT, MSP_ETHERNET_GPIO0);
  146. msp_gpio_pin_hi(MSP_ETHERNET_GPIO0);
  147. #ifdef CONFIG_MSP_HAS_TSMAC
  148. /* 3 phys on boards with TSMAC */
  149. msp_gpio_pin_mode(MSP_GPIO_OUTPUT, MSP_ETHERNET_GPIO1);
  150. msp_gpio_pin_hi(MSP_ETHERNET_GPIO1);
  151. msp_gpio_pin_mode(MSP_GPIO_OUTPUT, MSP_ETHERNET_GPIO2);
  152. msp_gpio_pin_hi(MSP_ETHERNET_GPIO2);
  153. #endif
  154. for (i = 0; i < ARRAY_SIZE(msp_eth_devs); i++) {
  155. ret = platform_device_register(&msp_eth_devs[i]);
  156. printk(KERN_INFO "device: %d, return value = %d\n", i, ret);
  157. if (ret) {
  158. platform_device_unregister(&msp_eth_devs[i]);
  159. break;
  160. }
  161. }
  162. if (ret)
  163. printk(KERN_WARNING "Could not initialize "
  164. "MSPETH device structures.\n");
  165. return ret;
  166. }
  167. subsys_initcall(msp_eth_setup);