mach-mx28evk.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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_FLEXCAN_SWITCH MXS_GPIO_NR(2, 13)
  27. #define MX28EVK_FEC_PHY_POWER MXS_GPIO_NR(2, 15)
  28. #define MX28EVK_FEC_PHY_RESET MXS_GPIO_NR(4, 13)
  29. static const iomux_cfg_t mx28evk_pads[] __initconst = {
  30. /* duart */
  31. MX28_PAD_PWM0__DUART_RX | MXS_PAD_CTRL,
  32. MX28_PAD_PWM1__DUART_TX | MXS_PAD_CTRL,
  33. /* auart0 */
  34. MX28_PAD_AUART0_RX__AUART0_RX | MXS_PAD_CTRL,
  35. MX28_PAD_AUART0_TX__AUART0_TX | MXS_PAD_CTRL,
  36. MX28_PAD_AUART0_CTS__AUART0_CTS | MXS_PAD_CTRL,
  37. MX28_PAD_AUART0_RTS__AUART0_RTS | MXS_PAD_CTRL,
  38. /* auart3 */
  39. MX28_PAD_AUART3_RX__AUART3_RX | MXS_PAD_CTRL,
  40. MX28_PAD_AUART3_TX__AUART3_TX | MXS_PAD_CTRL,
  41. MX28_PAD_AUART3_CTS__AUART3_CTS | MXS_PAD_CTRL,
  42. MX28_PAD_AUART3_RTS__AUART3_RTS | MXS_PAD_CTRL,
  43. #define MXS_PAD_FEC (MXS_PAD_8MA | MXS_PAD_3V3 | MXS_PAD_PULLUP)
  44. /* fec0 */
  45. MX28_PAD_ENET0_MDC__ENET0_MDC | MXS_PAD_FEC,
  46. MX28_PAD_ENET0_MDIO__ENET0_MDIO | MXS_PAD_FEC,
  47. MX28_PAD_ENET0_RX_EN__ENET0_RX_EN | MXS_PAD_FEC,
  48. MX28_PAD_ENET0_RXD0__ENET0_RXD0 | MXS_PAD_FEC,
  49. MX28_PAD_ENET0_RXD1__ENET0_RXD1 | MXS_PAD_FEC,
  50. MX28_PAD_ENET0_TX_EN__ENET0_TX_EN | MXS_PAD_FEC,
  51. MX28_PAD_ENET0_TXD0__ENET0_TXD0 | MXS_PAD_FEC,
  52. MX28_PAD_ENET0_TXD1__ENET0_TXD1 | MXS_PAD_FEC,
  53. MX28_PAD_ENET_CLK__CLKCTRL_ENET | MXS_PAD_FEC,
  54. /* fec1 */
  55. MX28_PAD_ENET0_CRS__ENET1_RX_EN | MXS_PAD_FEC,
  56. MX28_PAD_ENET0_RXD2__ENET1_RXD0 | MXS_PAD_FEC,
  57. MX28_PAD_ENET0_RXD3__ENET1_RXD1 | MXS_PAD_FEC,
  58. MX28_PAD_ENET0_COL__ENET1_TX_EN | MXS_PAD_FEC,
  59. MX28_PAD_ENET0_TXD2__ENET1_TXD0 | MXS_PAD_FEC,
  60. MX28_PAD_ENET0_TXD3__ENET1_TXD1 | MXS_PAD_FEC,
  61. /* phy power line */
  62. MX28_PAD_SSP1_DATA3__GPIO_2_15 | MXS_PAD_CTRL,
  63. /* phy reset line */
  64. MX28_PAD_ENET0_RX_CLK__GPIO_4_13 | MXS_PAD_CTRL,
  65. /* flexcan0 */
  66. MX28_PAD_GPMI_RDY2__CAN0_TX,
  67. MX28_PAD_GPMI_RDY3__CAN0_RX,
  68. /* flexcan1 */
  69. MX28_PAD_GPMI_CE2N__CAN1_TX,
  70. MX28_PAD_GPMI_CE3N__CAN1_RX,
  71. /* transceiver power control */
  72. MX28_PAD_SSP1_CMD__GPIO_2_13,
  73. };
  74. /* fec */
  75. static void __init mx28evk_fec_reset(void)
  76. {
  77. int ret;
  78. struct clk *clk;
  79. /* Enable fec phy clock */
  80. clk = clk_get_sys("pll2", NULL);
  81. if (!IS_ERR(clk))
  82. clk_enable(clk);
  83. /* Power up fec phy */
  84. ret = gpio_request(MX28EVK_FEC_PHY_POWER, "fec-phy-power");
  85. if (ret) {
  86. pr_err("Failed to request gpio fec-phy-%s: %d\n", "power", ret);
  87. return;
  88. }
  89. ret = gpio_direction_output(MX28EVK_FEC_PHY_POWER, 0);
  90. if (ret) {
  91. pr_err("Failed to drive gpio fec-phy-%s: %d\n", "power", ret);
  92. return;
  93. }
  94. /* Reset fec phy */
  95. ret = gpio_request(MX28EVK_FEC_PHY_RESET, "fec-phy-reset");
  96. if (ret) {
  97. pr_err("Failed to request gpio fec-phy-%s: %d\n", "reset", ret);
  98. return;
  99. }
  100. gpio_direction_output(MX28EVK_FEC_PHY_RESET, 0);
  101. if (ret) {
  102. pr_err("Failed to drive gpio fec-phy-%s: %d\n", "reset", ret);
  103. return;
  104. }
  105. mdelay(1);
  106. gpio_set_value(MX28EVK_FEC_PHY_RESET, 1);
  107. }
  108. static struct fec_platform_data mx28_fec_pdata[] __initdata = {
  109. {
  110. /* fec0 */
  111. .phy = PHY_INTERFACE_MODE_RMII,
  112. }, {
  113. /* fec1 */
  114. .phy = PHY_INTERFACE_MODE_RMII,
  115. },
  116. };
  117. static int __init mx28evk_fec_get_mac(void)
  118. {
  119. int i;
  120. u32 val;
  121. const u32 *ocotp = mxs_get_ocotp();
  122. if (!ocotp)
  123. goto error;
  124. /*
  125. * OCOTP only stores the last 4 octets for each mac address,
  126. * so hard-code Freescale OUI (00:04:9f) here.
  127. */
  128. for (i = 0; i < 2; i++) {
  129. val = ocotp[i * 4];
  130. mx28_fec_pdata[i].mac[0] = 0x00;
  131. mx28_fec_pdata[i].mac[1] = 0x04;
  132. mx28_fec_pdata[i].mac[2] = 0x9f;
  133. mx28_fec_pdata[i].mac[3] = (val >> 16) & 0xff;
  134. mx28_fec_pdata[i].mac[4] = (val >> 8) & 0xff;
  135. mx28_fec_pdata[i].mac[5] = (val >> 0) & 0xff;
  136. }
  137. return 0;
  138. error:
  139. pr_err("%s: timeout when reading fec mac from OCOTP\n", __func__);
  140. return -ETIMEDOUT;
  141. }
  142. /*
  143. * MX28EVK_FLEXCAN_SWITCH is shared between both flexcan controllers
  144. */
  145. static int flexcan0_en, flexcan1_en;
  146. static void mx28evk_flexcan_switch(void)
  147. {
  148. if (flexcan0_en || flexcan1_en)
  149. gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 1);
  150. else
  151. gpio_set_value(MX28EVK_FLEXCAN_SWITCH, 0);
  152. }
  153. static void mx28evk_flexcan0_switch(int enable)
  154. {
  155. flexcan0_en = enable;
  156. mx28evk_flexcan_switch();
  157. }
  158. static void mx28evk_flexcan1_switch(int enable)
  159. {
  160. flexcan1_en = enable;
  161. mx28evk_flexcan_switch();
  162. }
  163. static const struct flexcan_platform_data
  164. mx28evk_flexcan_pdata[] __initconst = {
  165. {
  166. .transceiver_switch = mx28evk_flexcan0_switch,
  167. }, {
  168. .transceiver_switch = mx28evk_flexcan1_switch,
  169. }
  170. };
  171. static void __init mx28evk_init(void)
  172. {
  173. int ret;
  174. mxs_iomux_setup_multiple_pads(mx28evk_pads, ARRAY_SIZE(mx28evk_pads));
  175. mx28_add_duart();
  176. mx28_add_auart0();
  177. mx28_add_auart3();
  178. if (mx28evk_fec_get_mac())
  179. pr_warn("%s: failed on fec mac setup\n", __func__);
  180. mx28evk_fec_reset();
  181. mx28_add_fec(0, &mx28_fec_pdata[0]);
  182. mx28_add_fec(1, &mx28_fec_pdata[1]);
  183. ret = gpio_request_one(MX28EVK_FLEXCAN_SWITCH, GPIOF_DIR_OUT,
  184. "flexcan-switch");
  185. if (ret) {
  186. pr_err("failed to request gpio flexcan-switch: %d\n", ret);
  187. } else {
  188. mx28_add_flexcan(0, &mx28evk_flexcan_pdata[0]);
  189. mx28_add_flexcan(1, &mx28evk_flexcan_pdata[1]);
  190. }
  191. }
  192. static void __init mx28evk_timer_init(void)
  193. {
  194. mx28_clocks_init();
  195. }
  196. static struct sys_timer mx28evk_timer = {
  197. .init = mx28evk_timer_init,
  198. };
  199. MACHINE_START(MX28EVK, "Freescale MX28 EVK")
  200. /* Maintainer: Freescale Semiconductor, Inc. */
  201. .map_io = mx28_map_io,
  202. .init_irq = mx28_init_irq,
  203. .init_machine = mx28evk_init,
  204. .timer = &mx28evk_timer,
  205. MACHINE_END