module-tx28.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_fec_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 struct fec_platform_data tx28_fec_data __initconst = {
  53. .phy = PHY_INTERFACE_MODE_RMII,
  54. };
  55. int __init tx28_add_fec0(void)
  56. {
  57. int i, ret;
  58. pr_debug("%s: Switching FEC PHY power off\n", __func__);
  59. ret = mxs_iomux_setup_multiple_pads(tx28_fec_gpio_pads,
  60. ARRAY_SIZE(tx28_fec_gpio_pads));
  61. for (i = 0; i < ARRAY_SIZE(tx28_fec_gpio_pads); i++) {
  62. unsigned int gpio = MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads[i]),
  63. PAD_PIN(tx28_fec_gpio_pads[i]));
  64. ret = gpio_request(gpio, "FEC");
  65. if (ret) {
  66. pr_err("Failed to request GPIO_%d_%d: %d\n",
  67. PAD_BANK(tx28_fec_gpio_pads[i]),
  68. PAD_PIN(tx28_fec_gpio_pads[i]), ret);
  69. goto free_gpios;
  70. }
  71. ret = gpio_direction_output(gpio, 0);
  72. if (ret) {
  73. pr_err("Failed to set direction of GPIO_%d_%d to output: %d\n",
  74. gpio / 32 + 1, gpio % 32, ret);
  75. goto free_gpios;
  76. }
  77. }
  78. /* Power up fec phy */
  79. pr_debug("%s: Switching FEC PHY power on\n", __func__);
  80. ret = gpio_direction_output(TX28_FEC_PHY_POWER, 1);
  81. if (ret) {
  82. pr_err("Failed to power on PHY: %d\n", ret);
  83. goto free_gpios;
  84. }
  85. mdelay(26); /* 25ms according to data sheet */
  86. /* nINT */
  87. gpio_direction_input(MXS_GPIO_NR(4, 5));
  88. /* Mode strap pins */
  89. gpio_direction_output(MXS_GPIO_NR(4, 2), 1);
  90. gpio_direction_output(MXS_GPIO_NR(4, 3), 1);
  91. gpio_direction_output(MXS_GPIO_NR(4, 4), 1);
  92. udelay(100); /* minimum assertion time for nRST */
  93. pr_debug("%s: Deasserting FEC PHY RESET\n", __func__);
  94. gpio_set_value(TX28_FEC_PHY_RESET, 1);
  95. ret = mxs_iomux_setup_multiple_pads(tx28_fec_pads,
  96. ARRAY_SIZE(tx28_fec_pads));
  97. if (ret) {
  98. pr_debug("%s: mxs_iomux_setup_multiple_pads() failed with rc: %d\n",
  99. __func__, ret);
  100. goto free_gpios;
  101. }
  102. pr_debug("%s: Registering FEC device\n", __func__);
  103. mx28_add_fec(0, &tx28_fec_data);
  104. return 0;
  105. free_gpios:
  106. while (--i >= 0) {
  107. unsigned int gpio = MXS_GPIO_NR(PAD_BANK(tx28_fec_gpio_pads[i]),
  108. PAD_PIN(tx28_fec_gpio_pads[i]));
  109. gpio_free(gpio);
  110. }
  111. return ret;
  112. }