mach-mx28evk.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/irq.h>
  18. #include <linux/clk.h>
  19. #include <asm/mach-types.h>
  20. #include <asm/mach/arch.h>
  21. #include <asm/mach/time.h>
  22. #include <mach/common.h>
  23. #include <mach/iomux-mx28.h>
  24. #include "devices-mx28.h"
  25. #include "gpio.h"
  26. #define MX28EVK_FEC_PHY_POWER MXS_GPIO_NR(2, 15)
  27. #define MX28EVK_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
  28. static const iomux_cfg_t mx28evk_pads[] __initconst = {
  29. /* duart */
  30. MX28_PAD_PWM0__DUART_RX |
  31. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  32. MX28_PAD_PWM1__DUART_TX |
  33. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  34. /* auart0 */
  35. MX28_PAD_AUART0_RX__AUART0_RX |
  36. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  37. MX28_PAD_AUART0_TX__AUART0_TX |
  38. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  39. MX28_PAD_AUART0_CTS__AUART0_CTS |
  40. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  41. MX28_PAD_AUART0_RTS__AUART0_RTS |
  42. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  43. /* auart3 */
  44. MX28_PAD_AUART3_RX__AUART3_RX |
  45. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  46. MX28_PAD_AUART3_TX__AUART3_TX |
  47. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  48. MX28_PAD_AUART3_CTS__AUART3_CTS |
  49. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  50. MX28_PAD_AUART3_RTS__AUART3_RTS |
  51. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  52. /* fec0 */
  53. MX28_PAD_ENET0_MDC__ENET0_MDC |
  54. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  55. MX28_PAD_ENET0_MDIO__ENET0_MDIO |
  56. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  57. MX28_PAD_ENET0_RX_EN__ENET0_RX_EN |
  58. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  59. MX28_PAD_ENET0_RXD0__ENET0_RXD0 |
  60. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  61. MX28_PAD_ENET0_RXD1__ENET0_RXD1 |
  62. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  63. MX28_PAD_ENET0_TX_EN__ENET0_TX_EN |
  64. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  65. MX28_PAD_ENET0_TXD0__ENET0_TXD0 |
  66. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  67. MX28_PAD_ENET0_TXD1__ENET0_TXD1 |
  68. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  69. MX28_PAD_ENET_CLK__CLKCTRL_ENET |
  70. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  71. /* fec1 */
  72. MX28_PAD_ENET0_CRS__ENET1_RX_EN |
  73. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  74. MX28_PAD_ENET0_RXD2__ENET1_RXD0 |
  75. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  76. MX28_PAD_ENET0_RXD3__ENET1_RXD1 |
  77. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  78. MX28_PAD_ENET0_COL__ENET1_TX_EN |
  79. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  80. MX28_PAD_ENET0_TXD2__ENET1_TXD0 |
  81. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  82. MX28_PAD_ENET0_TXD3__ENET1_TXD1 |
  83. (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP),
  84. /* phy power line */
  85. MX28_PAD_SSP1_DATA3__GPIO_2_15 |
  86. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  87. /* phy reset line */
  88. MX28_PAD_ENET0_RX_CLK__GPIO_4_13 |
  89. (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL),
  90. };
  91. /* fec */
  92. static void __init mx28evk_fec_reset(void)
  93. {
  94. int ret;
  95. struct clk *clk;
  96. /* Enable fec phy clock */
  97. clk = clk_get_sys("pll2", NULL);
  98. if (!IS_ERR(clk))
  99. clk_enable(clk);
  100. /* Power up fec phy */
  101. ret = gpio_request(MX28EVK_FEC_PHY_POWER, "fec-phy-power");
  102. if (ret) {
  103. pr_err("Failed to request gpio fec-phy-%s: %d\n", "power", ret);
  104. return;
  105. }
  106. ret = gpio_direction_output(MX28EVK_FEC_PHY_POWER, 0);
  107. if (ret) {
  108. pr_err("Failed to drive gpio fec-phy-%s: %d\n", "power", ret);
  109. return;
  110. }
  111. /* Reset fec phy */
  112. ret = gpio_request(MX28EVK_FEC_PHY_RESET, "fec-phy-reset");
  113. if (ret) {
  114. pr_err("Failed to request gpio fec-phy-%s: %d\n", "reset", ret);
  115. return;
  116. }
  117. gpio_direction_output(MX28EVK_FEC_PHY_RESET, 0);
  118. if (ret) {
  119. pr_err("Failed to drive gpio fec-phy-%s: %d\n", "reset", ret);
  120. return;
  121. }
  122. mdelay(1);
  123. gpio_set_value(MX28EVK_FEC_PHY_RESET, 1);
  124. }
  125. static struct fec_platform_data mx28_fec_pdata[] __initdata = {
  126. {
  127. /* fec0 */
  128. .phy = PHY_INTERFACE_MODE_RMII,
  129. }, {
  130. /* fec1 */
  131. .phy = PHY_INTERFACE_MODE_RMII,
  132. },
  133. };
  134. static int __init mx28evk_fec_get_mac(void)
  135. {
  136. int i;
  137. u32 val;
  138. const u32 *ocotp = mxs_get_ocotp();
  139. if (!ocotp)
  140. goto error;
  141. /*
  142. * OCOTP only stores the last 4 octets for each mac address,
  143. * so hard-code Freescale OUI (00:04:9f) here.
  144. */
  145. for (i = 0; i < 2; i++) {
  146. val = ocotp[i * 4];
  147. mx28_fec_pdata[i].mac[0] = 0x00;
  148. mx28_fec_pdata[i].mac[1] = 0x04;
  149. mx28_fec_pdata[i].mac[2] = 0x9f;
  150. mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
  151. mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
  152. mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
  153. }
  154. return 0;
  155. error:
  156. pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
  157. return -ETIMEDOUT;
  158. }
  159. static void __init mx28evk_init(void)
  160. {
  161. mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
  162. mx28_add_duart();
  163. mx28_add_auart0();
  164. mx28_add_auart3();
  165. if (mx28evk_fec_get_mac())
  166. pr_warn("%s: failed on fec mac setup\n", __func__);
  167. mx28evk_fec_reset();
  168. mx28_add_fec(0, &mx28_fec_pdata[0]);
  169. mx28_add_fec(1, &mx28_fec_pdata[1]);
  170. }
  171. static void __init mx28evk_timer_init(void)
  172. {
  173. mx28_clocks_init();
  174. }
  175. static struct sys_timer mx28evk_timer = {
  176. .init = mx28evk_timer_init,
  177. };
  178. MACHINE_START(MX28EVK, "Freescale MX28 EVK")
  179. /* Maintainer: Freescale Semiconductor, Inc. */
  180. .map_io = mx28_map_io,
  181. .init_irq = mx28_init_irq,
  182. .init_machine = mx28evk_init,
  183. .timer = &mx28evk_timer,
  184. MACHINE_END