board_pcie.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "sdk.h"
  31. #include "registers/regsccm.h"
  32. #include "registers/regsccmanalog.h"
  33. #include "registers/regspmu.h"
  34. #include "registers/regsiomuxc.h"
  35. ////////////////////////////////////////////////////////////////////////////////
  36. // Code
  37. ////////////////////////////////////////////////////////////////////////////////
  38. void pcie_clk_setup(uint32_t enable)
  39. {
  40. if (enable) {
  41. // gate on pci-e clks
  42. HW_CCM_CCGR4.B.CG0 = CLOCK_ON;
  43. // clear the powerdown bit
  44. HW_CCM_ANALOG_PLL_ENET_CLR(BM_CCM_ANALOG_PLL_ENET_POWERDOWN);
  45. // enable pll
  46. HW_CCM_ANALOG_PLL_ENET_SET(BM_CCM_ANALOG_PLL_ENET_ENABLE);
  47. // wait the pll locked
  48. while (!HW_CCM_ANALOG_PLL_ENET.B.LOCK) ;
  49. // Disable bypass
  50. HW_CCM_ANALOG_PLL_ENET_CLR(BM_CCM_ANALOG_PLL_ENET_BYPASS);
  51. // enable pci-e ref clk
  52. HW_CCM_ANALOG_PLL_ENET_SET(BM_CCM_ANALOG_PLL_ENET_ENABLE_125M);
  53. }
  54. }
  55. void pcie_card_pwr_setup(uint32_t enable)
  56. {
  57. #if defined(BOARD_EVB)
  58. i2c_init(I2C3_BASE_ADDR, 100000);
  59. board_ioexpander_iomux_config();
  60. if (enable) {
  61. //enable pciemini_3.3v
  62. max7310_set_gpio_output(1, 2, 1);
  63. } else {
  64. max7310_set_gpio_output(1, 2, 0);
  65. }
  66. #endif
  67. #if defined(BOARD_SMART_DEVICE)
  68. gpio_set_gpio(GPIO_PORT3, 19);
  69. gpio_set_direction(GPIO_PORT3, 19, GPIO_GDIR_OUTPUT);
  70. if(enable){
  71. gpio_set_level(GPIO_PORT3, 19, GPIO_HIGH_LEVEL);
  72. }else{
  73. gpio_set_level(GPIO_PORT3, 19, GPIO_LOW_LEVEL);
  74. }
  75. #endif
  76. }
  77. void pcie_enable_extrn_125mhz_clk(uint32_t enable)
  78. {
  79. if (enable) {
  80. //Enable 125MHz output of Enet_PLL
  81. HW_CCM_ANALOG_PLL_ENET_SET(BM_CCM_ANALOG_PLL_ENET_ENABLE_125M);
  82. // Select PCIe clock source and switch to output buffer, ie, CLK1_N/CLK1_P
  83. HW_PMU_MISC1_CLR(BM_PMU_MISC1_LVDSCLK1_IBEN);
  84. HW_PMU_MISC1.B.LVDS1_CLK_SEL = BV_PMU_MISC1_LVDS1_CLK_SEL__PCIE_REF;
  85. HW_PMU_MISC1_SET(BM_PMU_MISC1_LVDSCLK1_OBEN);
  86. }
  87. }
  88. // The external 100 MHz clock
  89. void pcie_enable_extrn_100mhz_clk(uint32_t enable)
  90. {
  91. #if defined(CHIP_MX6SDL)
  92. #define BV_PMU_MISC1_LVDS1_CLK_SEL__SATA_REF 11
  93. #endif
  94. if (enable) {
  95. //Enable 100MHz output of Enet_PLL
  96. HW_CCM_ANALOG_PLL_ENET_SET(BM_CCM_ANALOG_PLL_ENET_ENABLE_100M);
  97. HW_PMU_MISC1_CLR(BM_PMU_MISC1_LVDSCLK1_IBEN);
  98. HW_PMU_MISC1.B.LVDS1_CLK_SEL = BV_PMU_MISC1_LVDS1_CLK_SEL__SATA_REF;
  99. HW_PMU_MISC1_SET(BM_PMU_MISC1_LVDSCLK1_OBEN);
  100. }
  101. }
  102. void pcie_card_rst(void)
  103. {
  104. #if defined(BOARD_EVB)
  105. i2c_init(I2C3_BASE_ADDR, 100000);
  106. board_ioexpander_iomux_config();
  107. max7310_set_gpio_output(0, 2, 0);
  108. hal_delay_us(200 * 1000);
  109. max7310_set_gpio_output(0, 2, 1);
  110. #endif
  111. #if defined(BOARD_SMART_DEVICE)
  112. gpio_set_gpio(GPIO_PORT4, 5);
  113. gpio_set_direction(GPIO_PORT4, 5, GPIO_GDIR_OUTPUT);
  114. gpio_set_level(GPIO_PORT4, 5, GPIO_LOW_LEVEL);
  115. hal_delay_us(200 * 1000);
  116. gpio_set_level(GPIO_PORT4, 5, GPIO_HIGH_LEVEL);
  117. #endif
  118. }
  119. ////////////////////////////////////////////////////////////////////////////////
  120. // EOF
  121. ////////////////////////////////////////////////////////////////////////////////