fsl_power.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright (c) 2016, NXP
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * o Redistributions of source code must retain the above copyright notice, this list
  10. * of conditions and the following disclaimer.
  11. *
  12. * o Redistributions in binary form must reproduce the above copyright notice, this
  13. * list of conditions and the following disclaimer in the documentation and/or
  14. * other materials provided with the distribution.
  15. *
  16. * o Neither the name of copyright holder nor the names of its
  17. * contributors may be used to endorse or promote products derived from this
  18. * software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  24. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  27. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef _FSL_POWER_H_
  32. #define _FSL_POWER_H_
  33. #include "fsl_common.h"
  34. /*******************************************************************************
  35. * Definitions
  36. ******************************************************************************/
  37. #define MAKE_PD_BITS(reg, slot) ((reg << 8) | slot)
  38. #define PDRCFG0 0x0U
  39. #define PDRCFG1 0x1U
  40. typedef enum pd_bits
  41. {
  42. kPDRUNCFG_LP_REG = MAKE_PD_BITS(PDRCFG0, 2U),
  43. kPDRUNCFG_PD_FRO_EN = MAKE_PD_BITS(PDRCFG0, 4U),
  44. kPDRUNCFG_PD_TS = MAKE_PD_BITS(PDRCFG0, 6U),
  45. kPDRUNCFG_PD_BOD_RESET = MAKE_PD_BITS(PDRCFG0, 7U),
  46. kPDRUNCFG_PD_BOD_INTR = MAKE_PD_BITS(PDRCFG0, 8U),
  47. kPDRUNCFG_PD_VD2_ANA = MAKE_PD_BITS(PDRCFG0, 9U),
  48. kPDRUNCFG_PD_ADC0 = MAKE_PD_BITS(PDRCFG0, 10U),
  49. kPDRUNCFG_PD_RAM0 = MAKE_PD_BITS(PDRCFG0, 13U),
  50. kPDRUNCFG_PD_RAM1 = MAKE_PD_BITS(PDRCFG0, 14U),
  51. kPDRUNCFG_PD_RAM2 = MAKE_PD_BITS(PDRCFG0, 15U),
  52. kPDRUNCFG_PD_RAM3 = MAKE_PD_BITS(PDRCFG0, 16U),
  53. kPDRUNCFG_PD_ROM = MAKE_PD_BITS(PDRCFG0, 17U),
  54. kPDRUNCFG_PD_VDDA = MAKE_PD_BITS(PDRCFG0, 19U),
  55. kPDRUNCFG_PD_WDT_OSC = MAKE_PD_BITS(PDRCFG0, 20U),
  56. kPDRUNCFG_PD_USB0_PHY = MAKE_PD_BITS(PDRCFG0, 21U),
  57. kPDRUNCFG_PD_SYS_PLL0 = MAKE_PD_BITS(PDRCFG0, 22U),
  58. kPDRUNCFG_PD_VREFP = MAKE_PD_BITS(PDRCFG0, 23U),
  59. kPDRUNCFG_PD_FLASH_BG = MAKE_PD_BITS(PDRCFG0, 25U),
  60. kPDRUNCFG_PD_VD3 = MAKE_PD_BITS(PDRCFG0, 26U),
  61. kPDRUNCFG_PD_VD4 = MAKE_PD_BITS(PDRCFG0, 27U),
  62. kPDRUNCFG_PD_VD5 = MAKE_PD_BITS(PDRCFG0, 28U),
  63. kPDRUNCFG_PD_VD6 = MAKE_PD_BITS(PDRCFG0, 29U),
  64. kPDRUNCFG_REQ_DELAY = MAKE_PD_BITS(PDRCFG0, 30U),
  65. kPDRUNCFG_FORCE_RBB = MAKE_PD_BITS(PDRCFG0, 31U),
  66. kPDRUNCFG_PD_USB1_PHY = MAKE_PD_BITS(PDRCFG1, 0U),
  67. kPDRUNCFG_PD_USB_PLL = MAKE_PD_BITS(PDRCFG1, 1U),
  68. kPDRUNCFG_PD_AUDIO_PLL = MAKE_PD_BITS(PDRCFG1, 2U),
  69. kPDRUNCFG_PD_SYS_OSC = MAKE_PD_BITS(PDRCFG1, 3U),
  70. kPDRUNCFG_PD_EEPROM = MAKE_PD_BITS(PDRCFG1, 5U),
  71. kPDRUNCFG_PD_rng = MAKE_PD_BITS(PDRCFG1, 6U),
  72. kPDRUNCFG_ForceUnsigned = 0x80000000U,
  73. } pd_bit_t;
  74. /* Power mode configuration API parameter */
  75. typedef enum _power_mode_config
  76. {
  77. kPmu_Sleep = 0U,
  78. kPmu_Deep_Sleep = 1U,
  79. kPmu_Deep_PowerDown = 2U,
  80. } power_mode_cfg_t;
  81. /*******************************************************************************
  82. * API
  83. ******************************************************************************/
  84. #ifdef __cplusplus
  85. extern "C" {
  86. #endif
  87. /*!
  88. * @name Power Configuration
  89. * @{
  90. */
  91. /*!
  92. * @brief API to enable PDRUNCFG bit in the Syscon. Note that enabling the bit powers down the peripheral
  93. *
  94. * @param en peripheral for which to enable the PDRUNCFG bit
  95. * @return none
  96. */
  97. static inline void POWER_EnablePD(pd_bit_t en)
  98. {
  99. /* PDRUNCFGSET */
  100. SYSCON->PDRUNCFGSET[(en >> 8UL)] = (1UL << (en & 0xffU));
  101. }
  102. /*!
  103. * @brief API to disable PDRUNCFG bit in the Syscon. Note that disabling the bit powers up the peripheral
  104. *
  105. * @param en peripheral for which to disable the PDRUNCFG bit
  106. * @return none
  107. */
  108. static inline void POWER_DisablePD(pd_bit_t en)
  109. {
  110. /* PDRUNCFGCLR */
  111. SYSCON->PDRUNCFGCLR[(en >> 8UL)] = (1UL << (en & 0xffU));
  112. }
  113. /*!
  114. * @brief API to enable deep sleep bit in the ARM Core.
  115. *
  116. * @param none
  117. * @return none
  118. */
  119. static inline void POWER_EnableDeepSleep(void)
  120. {
  121. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  122. }
  123. /*!
  124. * @brief API to disable deep sleep bit in the ARM Core.
  125. *
  126. * @param none
  127. * @return none
  128. */
  129. static inline void POWER_DisableDeepSleep(void)
  130. {
  131. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  132. }
  133. /*!
  134. * @brief API to power down flash controller.
  135. *
  136. * @param none
  137. * @return none
  138. */
  139. static inline void POWER_PowerDownFlash(void)
  140. {
  141. /* TURN OFF clock ip_2113 (only needed for FLASH programming, will be turned on by ROM API) */
  142. CLOCK_DisableClock(kCLOCK_Flash);
  143. /* TURN OFF clock ip_2113 (only needed for FLASH programming, will be turned on by ROM API) */
  144. CLOCK_DisableClock(kCLOCK_Fmc);
  145. }
  146. /*!
  147. * @brief API to power up flash controller.
  148. *
  149. * @param none
  150. * @return none
  151. */
  152. static inline void POWER_PowerUpFlash(void)
  153. {
  154. /* TURN OFF clock ip_2113 (only needed for FLASH programming, will be turned on by ROM API) */
  155. CLOCK_EnableClock(kCLOCK_Fmc);
  156. }
  157. /*!
  158. * @brief Power Library API to power the PLLs.
  159. *
  160. * @param none
  161. * @return none
  162. */
  163. void POWER_SetPLL(void);
  164. /*!
  165. * @brief Power Library API to power the USB PHY.
  166. *
  167. * @param none
  168. * @return none
  169. */
  170. void POWER_SetUsbPhy(void);
  171. /*!
  172. * @brief Power Library API to enter different power mode.
  173. *
  174. * @param exclude_from_pd Bit mask of the PDRUNCFG0(low 32bits) and PDRUNCFG1(high 32bits) that needs to be powered on during power mode selected.
  175. * @return none
  176. */
  177. void POWER_EnterPowerMode(power_mode_cfg_t mode, uint64_t exclude_from_pd);
  178. /*!
  179. * @brief Power Library API to enter sleep mode.
  180. *
  181. * @return none
  182. */
  183. void POWER_EnterSleep(void);
  184. /*!
  185. * @brief Power Library API to enter deep sleep mode.
  186. *
  187. * @param exclude_from_pd Bit mask of the PDRUNCFG0(low 32bits) and PDRUNCFG1(high 32bits) bits that needs to be powered on during deep sleep
  188. * @return none
  189. */
  190. void POWER_EnterDeepSleep(uint64_t exclude_from_pd);
  191. /*!
  192. * @brief Power Library API to enter deep power down mode.
  193. *
  194. * @param exclude_from_pd Bit mask of the PDRUNCFG0(low 32bits) and PDRUNCFG1(high 32bits) that needs to be powered on during deep power
  195. * down mode, but this is has no effect as the voltages are cut off.
  196. * @return none
  197. */
  198. void POWER_EnterDeepPowerDown(uint64_t exclude_from_pd);
  199. /*!
  200. * @brief Power Library API to choose normal regulation and set the voltage for the desired operating frequency.
  201. *
  202. * @param freq - The desired frequency at which the part would like to operate,
  203. * note that the voltage and flash wait states should be set before changing frequency
  204. * @return none
  205. */
  206. void POWER_SetVoltageForFreq(uint32_t freq);
  207. /*!
  208. * @brief Power Library API to return the library version.
  209. *
  210. * @param none
  211. * @return version number of the power library
  212. */
  213. uint32_t POWER_GetLibVersion(void);
  214. #ifdef __cplusplus
  215. }
  216. #endif
  217. #endif /* _FSL_POWER_H_ */