m28evk.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * DENX M28 module
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. * on behalf of DENX Software Engineering GmbH
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/gpio.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/imx-regs.h>
  29. #include <asm/arch/iomux-mx28.h>
  30. #include <asm/arch/clock.h>
  31. #include <asm/arch/sys_proto.h>
  32. #include <linux/mii.h>
  33. #include <miiphy.h>
  34. #include <netdev.h>
  35. #include <errno.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /*
  38. * Functions
  39. */
  40. int board_early_init_f(void)
  41. {
  42. /* IO0 clock at 480MHz */
  43. mx28_set_ioclk(MXC_IOCLK0, 480000);
  44. /* IO1 clock at 480MHz */
  45. mx28_set_ioclk(MXC_IOCLK1, 480000);
  46. /* SSP0 clock at 96MHz */
  47. mx28_set_sspclk(MXC_SSPCLK0, 96000, 0);
  48. /* SSP2 clock at 96MHz */
  49. mx28_set_sspclk(MXC_SSPCLK2, 96000, 0);
  50. #ifdef CONFIG_CMD_USB
  51. mxs_iomux_setup_pad(MX28_PAD_SSP2_SS1__USB1_OVERCURRENT);
  52. mxs_iomux_setup_pad(MX28_PAD_AUART3_TX__GPIO_3_13 |
  53. MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP);
  54. gpio_direction_output(MX28_PAD_AUART3_TX__GPIO_3_13, 0);
  55. #endif
  56. return 0;
  57. }
  58. int board_init(void)
  59. {
  60. /* Adress of boot parameters */
  61. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  62. return 0;
  63. }
  64. #define HW_DIGCTRL_SCRATCH0 0x8001c280
  65. #define HW_DIGCTRL_SCRATCH1 0x8001c290
  66. int dram_init(void)
  67. {
  68. uint32_t sz[2];
  69. sz[0] = readl(HW_DIGCTRL_SCRATCH0);
  70. sz[1] = readl(HW_DIGCTRL_SCRATCH1);
  71. if (sz[0] != sz[1]) {
  72. printf("MX28:\n"
  73. "Error, the RAM size in HW_DIGCTRL_SCRATCH0 and\n"
  74. "HW_DIGCTRL_SCRATCH1 is not the same. Please\n"
  75. "verify these two registers contain valid RAM size!\n");
  76. hang();
  77. }
  78. gd->ram_size = sz[0];
  79. return 0;
  80. }
  81. #ifdef CONFIG_CMD_MMC
  82. static int m28_mmc_wp(int id)
  83. {
  84. if (id != 0) {
  85. printf("MXS MMC: Invalid card selected (card id = %d)\n", id);
  86. return 1;
  87. }
  88. return gpio_get_value(MX28_PAD_AUART2_CTS__GPIO_3_10);
  89. }
  90. int board_mmc_init(bd_t *bis)
  91. {
  92. /* Configure WP as input. */
  93. gpio_direction_input(MX28_PAD_AUART2_CTS__GPIO_3_10);
  94. return mxsmmc_initialize(bis, 0, m28_mmc_wp);
  95. }
  96. #endif
  97. #ifdef CONFIG_CMD_NET
  98. #define MII_OPMODE_STRAP_OVERRIDE 0x16
  99. #define MII_PHY_CTRL1 0x1e
  100. #define MII_PHY_CTRL2 0x1f
  101. int fecmxc_mii_postcall(int phy)
  102. {
  103. miiphy_write("FEC1", phy, MII_BMCR, 0x9000);
  104. miiphy_write("FEC1", phy, MII_OPMODE_STRAP_OVERRIDE, 0x0202);
  105. if (phy == 3)
  106. miiphy_write("FEC1", 3, MII_PHY_CTRL2, 0x8180);
  107. return 0;
  108. }
  109. int board_eth_init(bd_t *bis)
  110. {
  111. struct mx28_clkctrl_regs *clkctrl_regs =
  112. (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
  113. struct eth_device *dev;
  114. int ret;
  115. ret = cpu_eth_init(bis);
  116. clrsetbits_le32(&clkctrl_regs->hw_clkctrl_enet,
  117. CLKCTRL_ENET_TIME_SEL_MASK | CLKCTRL_ENET_CLK_OUT_EN,
  118. CLKCTRL_ENET_TIME_SEL_RMII_CLK);
  119. ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE);
  120. if (ret) {
  121. printf("FEC MXS: Unable to init FEC0\n");
  122. return ret;
  123. }
  124. ret = fecmxc_initialize_multi(bis, 1, 3, MXS_ENET1_BASE);
  125. if (ret) {
  126. printf("FEC MXS: Unable to init FEC1\n");
  127. return ret;
  128. }
  129. dev = eth_get_dev_by_name("FEC0");
  130. if (!dev) {
  131. printf("FEC MXS: Unable to get FEC0 device entry\n");
  132. return -EINVAL;
  133. }
  134. ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
  135. if (ret) {
  136. printf("FEC MXS: Unable to register FEC0 mii postcall\n");
  137. return ret;
  138. }
  139. dev = eth_get_dev_by_name("FEC1");
  140. if (!dev) {
  141. printf("FEC MXS: Unable to get FEC1 device entry\n");
  142. return -EINVAL;
  143. }
  144. ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
  145. if (ret) {
  146. printf("FEC MXS: Unable to register FEC1 mii postcall\n");
  147. return ret;
  148. }
  149. return ret;
  150. }
  151. #ifdef CONFIG_M28_FEC_MAC_IN_OCOTP
  152. #define MXS_OCOTP_MAX_TIMEOUT 1000000
  153. void imx_get_mac_from_fuse(char *mac)
  154. {
  155. struct mx28_ocotp_regs *ocotp_regs =
  156. (struct mx28_ocotp_regs *)MXS_OCOTP_BASE;
  157. uint32_t data;
  158. memset(mac, 0, 6);
  159. writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
  160. if (mx28_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
  161. MXS_OCOTP_MAX_TIMEOUT)) {
  162. printf("MXS FEC: Can't get MAC from OCOTP\n");
  163. return;
  164. }
  165. data = readl(&ocotp_regs->hw_ocotp_cust0);
  166. mac[0] = 0x00;
  167. mac[1] = 0x04;
  168. mac[2] = (data >> 24) & 0xff;
  169. mac[3] = (data >> 16) & 0xff;
  170. mac[4] = (data >> 8) & 0xff;
  171. mac[5] = data & 0xff;
  172. }
  173. #else
  174. void imx_get_mac_from_fuse(char *mac)
  175. {
  176. memset(mac, 0, 6);
  177. }
  178. #endif
  179. #endif