m28evk.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <asm/gpio.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/imx-regs.h>
  13. #include <asm/arch/iomux-mx28.h>
  14. #include <asm/arch/clock.h>
  15. #include <asm/arch/sys_proto.h>
  16. #include <linux/mii.h>
  17. #include <miiphy.h>
  18. #include <netdev.h>
  19. #include <errno.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. /*
  22. * Functions
  23. */
  24. int board_early_init_f(void)
  25. {
  26. /* IO0 clock at 480MHz */
  27. mxs_set_ioclk(MXC_IOCLK0, 480000);
  28. /* IO1 clock at 480MHz */
  29. mxs_set_ioclk(MXC_IOCLK1, 480000);
  30. /* SSP0 clock at 96MHz */
  31. mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
  32. /* SSP2 clock at 160MHz */
  33. mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
  34. #ifdef CONFIG_CMD_USB
  35. mxs_iomux_setup_pad(MX28_PAD_SSP2_SS1__USB1_OVERCURRENT);
  36. mxs_iomux_setup_pad(MX28_PAD_AUART3_TX__GPIO_3_13 |
  37. MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP);
  38. gpio_direction_output(MX28_PAD_AUART3_TX__GPIO_3_13, 0);
  39. mxs_iomux_setup_pad(MX28_PAD_AUART3_RX__GPIO_3_12 |
  40. MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP);
  41. gpio_direction_output(MX28_PAD_AUART3_RX__GPIO_3_12, 0);
  42. #endif
  43. return 0;
  44. }
  45. int board_init(void)
  46. {
  47. /* Adress of boot parameters */
  48. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  49. return 0;
  50. }
  51. int dram_init(void)
  52. {
  53. return mxs_dram_init();
  54. }
  55. #ifdef CONFIG_CMD_MMC
  56. static int m28_mmc_wp(int id)
  57. {
  58. if (id != 0) {
  59. printf("MXS MMC: Invalid card selected (card id = %d)\n", id);
  60. return 1;
  61. }
  62. return gpio_get_value(MX28_PAD_AUART2_CTS__GPIO_3_10);
  63. }
  64. int board_mmc_init(bd_t *bis)
  65. {
  66. /* Configure WP as input. */
  67. gpio_direction_input(MX28_PAD_AUART2_CTS__GPIO_3_10);
  68. /* Turn on the power to the card. */
  69. gpio_direction_output(MX28_PAD_PWM3__GPIO_3_28, 0);
  70. return mxsmmc_initialize(bis, 0, m28_mmc_wp, NULL);
  71. }
  72. #endif
  73. #ifdef CONFIG_CMD_NET
  74. #define MII_OPMODE_STRAP_OVERRIDE 0x16
  75. #define MII_PHY_CTRL1 0x1e
  76. #define MII_PHY_CTRL2 0x1f
  77. int fecmxc_mii_postcall(int phy)
  78. {
  79. #if defined(CONFIG_DENX_M28_V11) || defined(CONFIG_DENX_M28_V10)
  80. /* KZ8031 PHY on old boards. */
  81. const uint32_t freq = 0x0080;
  82. #else
  83. /* KZ8021 PHY on new boards. */
  84. const uint32_t freq = 0x0000;
  85. #endif
  86. miiphy_write("FEC1", phy, MII_BMCR, 0x9000);
  87. miiphy_write("FEC1", phy, MII_OPMODE_STRAP_OVERRIDE, 0x0202);
  88. if (phy == 3)
  89. miiphy_write("FEC1", 3, MII_PHY_CTRL2, 0x8100 | freq);
  90. return 0;
  91. }
  92. int board_eth_init(bd_t *bis)
  93. {
  94. struct mxs_clkctrl_regs *clkctrl_regs =
  95. (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
  96. struct eth_device *dev;
  97. int ret;
  98. ret = cpu_eth_init(bis);
  99. if (ret)
  100. return ret;
  101. clrsetbits_le32(&clkctrl_regs->hw_clkctrl_enet,
  102. CLKCTRL_ENET_TIME_SEL_MASK | CLKCTRL_ENET_CLK_OUT_EN,
  103. CLKCTRL_ENET_TIME_SEL_RMII_CLK);
  104. #if !defined(CONFIG_DENX_M28_V11) && !defined(CONFIG_DENX_M28_V10)
  105. /* Reset the new PHY */
  106. gpio_direction_output(MX28_PAD_AUART2_RTS__GPIO_3_11, 0);
  107. udelay(10000);
  108. gpio_set_value(MX28_PAD_AUART2_RTS__GPIO_3_11, 1);
  109. udelay(10000);
  110. #endif
  111. ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE);
  112. if (ret) {
  113. printf("FEC MXS: Unable to init FEC0\n");
  114. return ret;
  115. }
  116. ret = fecmxc_initialize_multi(bis, 1, 3, MXS_ENET1_BASE);
  117. if (ret) {
  118. printf("FEC MXS: Unable to init FEC1\n");
  119. return ret;
  120. }
  121. dev = eth_get_dev_by_name("FEC0");
  122. if (!dev) {
  123. printf("FEC MXS: Unable to get FEC0 device entry\n");
  124. return -EINVAL;
  125. }
  126. ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
  127. if (ret) {
  128. printf("FEC MXS: Unable to register FEC0 mii postcall\n");
  129. return ret;
  130. }
  131. dev = eth_get_dev_by_name("FEC1");
  132. if (!dev) {
  133. printf("FEC MXS: Unable to get FEC1 device entry\n");
  134. return -EINVAL;
  135. }
  136. ret = fecmxc_register_mii_postcall(dev, fecmxc_mii_postcall);
  137. if (ret) {
  138. printf("FEC MXS: Unable to register FEC1 mii postcall\n");
  139. return ret;
  140. }
  141. return ret;
  142. }
  143. #endif