module-tx28.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2010 <LW@KARO-electronics.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU General Public License version 2 as published by the
  6. * Free Software Foundation.
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/fec.h>
  10. #include <linux/gpio.h>
  11. #include <mach/iomux-mx28.h>
  12. #include "../devices-mx28.h"
  13. #include "module-tx28.h"
  14. #define TX28_FEC_PHY_POWER MXS_GPIO_NR(3, 29)
  15. #define TX28_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
  16. static const iomux_cfg_t tx28_fec_gpio_pads[] __initconst = {
  17. /* PHY POWER */
  18. MX28_PAD_PWM4__GPIO_3_29 |
  19. MXS_PAD_4MA | MXS_PAD_NOPULL | MXS_PAD_3V3,
  20. /* PHY RESET */
  21. MX28_PAD_ENET0_RX_CLK__GPIO_4_13 |
  22. MXS_PAD_4MA | MXS_PAD_NOPULL | MXS_PAD_3V3,
  23. /* Mode strap pins 0-2 */
  24. MX28_PAD_ENET0_RXD0__GPIO_4_3 |
  25. MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3,
  26. MX28_PAD_ENET0_RXD1__GPIO_4_4 |
  27. MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3,
  28. MX28_PAD_ENET0_RX_EN__GPIO_4_2 |
  29. MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3,
  30. /* nINT */
  31. MX28_PAD_ENET0_TX_CLK__GPIO_4_5 |
  32. MXS_PAD_4MA | MXS_PAD_NOPULL | MXS_PAD_3V3,
  33. MX28_PAD_ENET0_MDC__GPIO_4_0,
  34. MX28_PAD_ENET0_MDIO__GPIO_4_1,
  35. MX28_PAD_ENET0_TX_EN__GPIO_4_6,
  36. MX28_PAD_ENET0_TXD0__GPIO_4_7,
  37. MX28_PAD_ENET0_TXD1__GPIO_4_8,
  38. MX28_PAD_ENET_CLK__GPIO_4_16,
  39. };
  40. #define FEC_MODE (MXS_PAD_8MA | MXS_PAD_PULLUP | MXS_PAD_3V3)
  41. static const iomux_cfg_t tx28_fec0_pads[] __initconst = {
  42. MX28_PAD_ENET0_MDC__ENET0_MDC | FEC_MODE,
  43. MX28_PAD_ENET0_MDIO__ENET0_MDIO | FEC_MODE,
  44. MX28_PAD_ENET0_RX_EN__ENET0_RX_EN | FEC_MODE,
  45. MX28_PAD_ENET0_RXD0__ENET0_RXD0 | FEC_MODE,
  46. MX28_PAD_ENET0_RXD1__ENET0_RXD1 | FEC_MODE,
  47. MX28_PAD_ENET0_TX_EN__ENET0_TX_EN | FEC_MODE,
  48. MX28_PAD_ENET0_TXD0__ENET0_TXD0 | FEC_MODE,
  49. MX28_PAD_ENET0_TXD1__ENET0_TXD1 | FEC_MODE,
  50. MX28_PAD_ENET_CLK__CLKCTRL_ENET | FEC_MODE,
  51. };
  52. static const iomux_cfg_t tx28_fec1_pads[] __initconst = {
  53. MX28_PAD_ENET0_RXD2__ENET1_RXD0,
  54. MX28_PAD_ENET0_RXD3__ENET1_RXD1,
  55. MX28_PAD_ENET0_TXD2__ENET1_TXD0,
  56. MX28_PAD_ENET0_TXD3__ENET1_TXD1,
  57. MX28_PAD_ENET0_COL__ENET1_TX_EN,
  58. MX28_PAD_ENET0_CRS__ENET1_RX_EN,
  59. };
  60. static const struct fec_platform_data tx28_fec0_data __initconst = {
  61. .phy = PHY_INTERFACE_MODE_RMII,
  62. };
  63. static const struct fec_platform_data tx28_fec1_data __initconst = {
  64. .phy = PHY_INTERFACE_MODE_RMII,
  65. };
  66. int __init tx28_add_fec0(void)
  67. {
  68. int i, ret;
  69. pr_debug("%s: Switching FEC PHY power off\n", __func__);
  70. ret = mxs_iomux_setup_multiple_pads(tx28_fec_gpio_pads,
  71. ARRAY_SIZE(tx28_fec_gpio_pads));
  72. for (i = 0; i < ARRAY_SIZE(tx28_fec_gpio_pads); i++) {
  73. unsigned int gpio = MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads[i]),
  74. PAD_PIN(tx28_fec_gpio_pads[i]));
  75. ret = gpio_request(gpio, "FEC");
  76. if (ret) {
  77. pr_err("Failed to request GPIO_%d_%d: %d\n",
  78. PAD_BANK(tx28_fec_gpio_pads[i]),
  79. PAD_PIN(tx28_fec_gpio_pads[i]), ret);
  80. goto free_gpios;
  81. }
  82. ret = gpio_direction_output(gpio, 0);
  83. if (ret) {
  84. pr_err("Failed to set direction of GPIO_%d_%d to output: %d\n",
  85. gpio / 32 + 1, gpio % 32, ret);
  86. goto free_gpios;
  87. }
  88. }
  89. /* Power up fec phy */
  90. pr_debug("%s: Switching FEC PHY power on\n", __func__);
  91. ret = gpio_direction_output(TX28_FEC_PHY_POWER, 1);
  92. if (ret) {
  93. pr_err("Failed to power on PHY: %d\n", ret);
  94. goto free_gpios;
  95. }
  96. mdelay(26); /* 25ms according to data sheet */
  97. /* nINT */
  98. gpio_direction_input(MXS_GPIO_NR(4, 5));
  99. /* Mode strap pins */
  100. gpio_direction_output(MXS_GPIO_NR(4, 2), 1);
  101. gpio_direction_output(MXS_GPIO_NR(4, 3), 1);
  102. gpio_direction_output(MXS_GPIO_NR(4, 4), 1);
  103. udelay(100); /* minimum assertion time for nRST */
  104. pr_debug("%s: Deasserting FEC PHY RESET\n", __func__);
  105. gpio_set_value(TX28_FEC_PHY_RESET, 1);
  106. ret = mxs_iomux_setup_multiple_pads(tx28_fec0_pads,
  107. ARRAY_SIZE(tx28_fec0_pads));
  108. if (ret) {
  109. pr_debug("%s: mxs_iomux_setup_multiple_pads() failed with rc: %d\n",
  110. __func__, ret);
  111. goto free_gpios;
  112. }
  113. pr_debug("%s: Registering FEC0 device\n", __func__);
  114. mx28_add_fec(0, &tx28_fec0_data);
  115. return 0;
  116. free_gpios:
  117. while (--i >= 0) {
  118. unsigned int gpio = MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads[i]),
  119. PAD_PIN(tx28_fec_gpio_pads[i]));
  120. gpio_free(gpio);
  121. }
  122. return ret;
  123. }
  124. int __init tx28_add_fec1(void)
  125. {
  126. int ret;
  127. ret = mxs_iomux_setup_multiple_pads(tx28_fec1_pads,
  128. ARRAY_SIZE(tx28_fec1_pads));
  129. if (ret) {
  130. pr_debug("%s: mxs_iomux_setup_multiple_pads() failed with rc: %d\n",
  131. __func__, ret);
  132. return ret;
  133. }
  134. pr_debug("%s: Registering FEC1 device\n", __func__);
  135. mx28_add_fec(1, &tx28_fec1_data);
  136. return 0;
  137. }