board_sata.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. ////////////////////////////////////////////////////////////////////////////////
  35. // Code
  36. ////////////////////////////////////////////////////////////////////////////////
  37. /*!
  38. * SATA power on
  39. */
  40. void sata_power_on(void)
  41. {
  42. //enable SATA_3V3 and SATA_5V with MX7310 U19 CTRL_0
  43. #if defined(BOARD_SMART_DEVICE)
  44. //AUX_5V_EN
  45. gpio_set_gpio(GPIO_PORT6, 10);
  46. gpio_set_direction(GPIO_PORT6, 10, GPIO_GDIR_OUTPUT);
  47. gpio_set_level(GPIO_PORT6, 10, GPIO_HIGH_LEVEL);
  48. #elif defined(BOARD_EVB)
  49. board_ioexpander_iomux_config();
  50. //enable SATA_3V3 and SATA_5V with MX7310 CTRL_0
  51. max7310_set_gpio_output(1, 0, GPIO_HIGH_LEVEL);
  52. // sata_phy_clk_sel = CCM_PLL_ENET;
  53. #else
  54. #endif
  55. }
  56. /*!
  57. * SATA power off
  58. */
  59. void sata_power_off(void)
  60. {
  61. board_ioexpander_iomux_config();
  62. //disable SATA_3V3 and SATA_5V with MX7310 U19 CTRL_0
  63. max7310_set_gpio_output(1, 0, GPIO_LOW_LEVEL);
  64. }
  65. // The external 100 MHz clock is used by SATA, which is only present on the mx6dq.
  66. void enable_extrn_100mhz_clk(uint32_t enable)
  67. {
  68. if (enable) {
  69. // Disable SATA clock gating used as external reference
  70. HW_CCM_ANALOG_PLL_ENET_SET(BM_CCM_ANALOG_PLL_ENET_ENABLE_100M);
  71. // Select SATA clock source and switch to output buffer.
  72. HW_PMU_MISC1_CLR(BM_PMU_MISC1_LVDSCLK1_IBEN);
  73. HW_PMU_MISC1.B.LVDS1_CLK_SEL = BV_PMU_MISC1_LVDS1_CLK_SEL__SATA_REF;
  74. HW_PMU_MISC1_SET(BM_PMU_MISC1_LVDSCLK1_OBEN);
  75. }
  76. }
  77. /*!
  78. * @brief SATA related clocks enable function
  79. */
  80. void sata_clock_enable(void)
  81. {
  82. // Set SATA timings 0x05932046
  83. reg32_write(0x020E0034, 0x05932044);
  84. hal_delay_us(1000);
  85. // Enable SATA PLL
  86. reg32_write(0x020E0034, 0x05932046);
  87. hal_delay_us(1000);
  88. //enable SATA_CLK in CCGR5
  89. clock_gating_config(SATA_BASE_ADDR, CLOCK_ON);
  90. //enable ENET_PLL (PLL8). done in freq_populate()
  91. //enale SATA_CLK in the ENET_PLL register
  92. HW_CCM_ANALOG_PLL_ENET_SET(BM_CCM_ANALOG_PLL_ENET_ENABLE_100M);
  93. //config ENET PLL div_select for SATA - 100MHz
  94. HW_CCM_ANALOG_PLL_ENET.B.DIV_SELECT = 0x2; // 0b10-100MHz
  95. }
  96. /*!
  97. * @brief SATA related clocks dis function
  98. */
  99. void sata_clock_disable(void)
  100. {
  101. //disable SATA_CLK in CCGR5.
  102. clock_gating_config(SATA_BASE_ADDR, CLOCK_OFF);
  103. //disable ENET_PLL (PLL8)
  104. HW_CCM_ANALOG_PLL_ENET_CLR(BM_CCM_ANALOG_PLL_ENET_ENABLE_100M);
  105. }
  106. /*!
  107. * @brief SATA related function to get the PHY source clock
  108. */
  109. void sata_get_phy_src_clk(sata_phy_ref_clk_t * phy_ref_clk)
  110. {
  111. *phy_ref_clk = CCM_PLL_ENET;
  112. }
  113. ////////////////////////////////////////////////////////////////////////////////
  114. // EOF
  115. ////////////////////////////////////////////////////////////////////////////////