hal_pwr.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * Copyright (c) 2020-2021 Rockchip Electronics Co., Ltd.
  4. */
  5. #include "hal_conf.h"
  6. /** @addtogroup RK_HAL_Driver
  7. * @{
  8. */
  9. /** @addtogroup PWR
  10. * @{
  11. */
  12. #ifndef _HAL_PWR_H_
  13. #define _HAL_PWR_H_
  14. #include "hal_def.h"
  15. /** @defgroup PWR_Exported_Definition_Group1 Basic Definition
  16. * @{
  17. */
  18. /***************************** MACRO Definition ******************************/
  19. typedef enum {
  20. PWR_ID_NULL = 0,
  21. PWR_ID_CORE,
  22. PWR_ID_LOG,
  23. PWR_ID_DSP_CORE,
  24. PWR_ID_VCC_MIPI,
  25. PWR_ID_VCC_AUDIO,
  26. PWR_ID_DSP_VCC_MIPI,
  27. PWR_ID_MEMORY, /**< for share memory and sram */
  28. PWR_ID_TOP,
  29. PWR_ID_BUCK_1V8, /**< Usually as a transition between high and low voltage */
  30. PWR_ID_VCCIO_3V3,
  31. PWR_ID_VDD_1V1,
  32. PWR_ID_VCCIO_1V8,
  33. PWR_ID_VCCIO_1V8_PMU,
  34. PWR_ID_VCC_3V0_BL,
  35. PWR_ID_VCC_1V8_BUCK,
  36. PWR_ID_VCC_1V8_LDO,
  37. PWR_ID_VCC33_CODEC,
  38. PWR_ID_VCC33_AUDIO,
  39. PWR_ID_VCC1,
  40. PWR_ID_VLDO3,
  41. PWR_ID_VLDO6,
  42. PWR_ID_MAX,
  43. } ePWR_ID;
  44. typedef enum {
  45. PWR_CTRL_VOLT_RUN = 0, /**< run mode voltage */
  46. PWR_CTRL_VOLT_SSPD, /**< suspend mode voltage */
  47. PWR_CTRL_PWR_EN, /**< enable a regulator */
  48. PWR_CTRL_PWR_SSPD, /**< suspend mode enable a regulator */
  49. PWR_CTRL_VOLT_ST, /**< get a regulator state */
  50. PWR_CTRL_MAX
  51. } ePWR_CtrlType;
  52. #define PWR_FLG_VOLT_RUN HAL_BIT(PWR_CTRL_VOLT_RUN)
  53. #define PWR_FLG_VOLT_SSPD HAL_BIT(PWR_CTRL_VOLT_SSPD)
  54. #define PWR_FLG_PWR_EN HAL_BIT(PWR_CTRL_PWR_EN)
  55. #define PWR_FLG_PWR_SSPD HAL_BIT(PWR_CTRL_PWR_SSPD)
  56. #define PWR_FLG_VOLT_ST HAL_BIT(PWR_CTRL_VOLT_ST)
  57. #define PWR_FLG_LINEAR HAL_BIT(PWR_CTRL_MAX)
  58. #define PWR_FLG_FIXED (PWR_FLG_LINEAR << 1)
  59. #define PWR_FLG_ALWAYSON (PWR_FLG_FIXED << 1)
  60. #define PWR_FLG_ENMASK (PWR_FLG_ALWAYSON << 1)
  61. #define DESC_FLAG_LINEAR(flag) (PWR_FLG_LINEAR | PWR_FLG_VOLT_RUN | (flag))
  62. #define DESC_FLAG_N_LINEAR(flag) (PWR_FLG_VOLT_RUN | (flag))
  63. #define PWR_INTREG_SHIFT_RUN(reg, sft) \
  64. .preg[PWR_CTRL_VOLT_RUN] = (uint32_t *)(reg), \
  65. .shift[PWR_CTRL_VOLT_RUN] = (sft)
  66. #define PWR_INTREG_SHIFT_SSPD(reg, sft) \
  67. .preg[PWR_CTRL_VOLT_SSPD] = (uint32_t *)(reg), \
  68. .shift[PWR_CTRL_VOLT_SSPD] = (sft)
  69. #define PWR_INTREG_SHIFT_EN(reg, sft) \
  70. .preg[PWR_CTRL_PWR_EN] = (uint32_t *)(reg), \
  71. .shift[PWR_CTRL_PWR_EN] = (sft)
  72. #define PWR_INTREG_SHIFT_ST(reg, sft) \
  73. .preg[PWR_CTRL_VOLT_ST] = (uint32_t *)(reg), \
  74. .shift[PWR_CTRL_VOLT_ST] = (sft)
  75. #define PWR_DESC_LINEAR_VOLT(min, max, step) \
  76. .voltCnt = (((max)-(min))/(step)) + 1, \
  77. .minVolt = (min), \
  78. .volt_list = { \
  79. .stepVolt = (step) \
  80. }
  81. #define POWER_LINEAR_RANGE(_minUV, _minSel, _maxSel, _stepUV) \
  82. { \
  83. .minUV = _minUV, \
  84. .minSel = _minSel, \
  85. .maxSel = _maxSel, \
  86. .uVStep = _stepUV, \
  87. }
  88. /***************************** Structure Definition **************************/
  89. struct PWR_LINEAR_RANGE {
  90. unsigned int minUV;
  91. unsigned int minSel;
  92. unsigned int maxSel;
  93. unsigned int uVStep;
  94. };
  95. struct PWR_LINEAR_RANGE_TABLE {
  96. int nEntry;
  97. struct PWR_LINEAR_RANGE *entry;
  98. };
  99. union U_PWR_VOLT_LIST {
  100. int stepVolt;
  101. const uint32_t *voltTable;
  102. struct PWR_LINEAR_RANGE_TABLE linearTables;
  103. };
  104. struct PWR_CTRL_INFO {
  105. uint16_t pwrId : 8;
  106. uint16_t enCnt : 4;
  107. };
  108. struct PWR_INTREG_DESC {
  109. struct PWR_CTRL_INFO info;
  110. uint16_t flag;
  111. uint8_t voltMask;
  112. uint8_t voltCnt;
  113. __IO uint32_t *preg[PWR_CTRL_MAX];
  114. uint8_t shift[PWR_CTRL_MAX];
  115. uint32_t minVolt;
  116. union U_PWR_VOLT_LIST volt_list;
  117. };
  118. /** @} */
  119. /***************************** Function Declare ******************************/
  120. /** @defgroup PWR_Public_Function_Declare Public Function Declare
  121. * @{
  122. */
  123. #ifdef HAL_PWR_INTBUS_MODULE_ENABLED
  124. int HAL_PWR_GetEnableState(struct PWR_INTREG_DESC *desc);
  125. uint32_t HAL_PWR_GetVoltage(struct PWR_INTREG_DESC *desc);
  126. uint32_t HAL_PWR_GetVoltageSuspend(struct PWR_INTREG_DESC *desc);
  127. uint32_t HAL_PWR_GetVoltageReal(struct PWR_INTREG_DESC *desc);
  128. HAL_Status HAL_PWR_SetVoltage(struct PWR_INTREG_DESC *desc, uint32_t volt);
  129. HAL_Status HAL_PWR_SetVoltageSuspend(struct PWR_INTREG_DESC *desc, uint32_t volt);
  130. HAL_Status HAL_PWR_Enable(struct PWR_INTREG_DESC *desc);
  131. HAL_Status HAL_PWR_Disable(struct PWR_INTREG_DESC *desc);
  132. HAL_Check HAL_PWR_CheckDescByPwrId(struct PWR_INTREG_DESC *pdesc,
  133. ePWR_ID pwrId);
  134. uint32_t HAL_PWR_RoundVoltage(struct PWR_INTREG_DESC *desc, uint32_t volt);
  135. #endif
  136. int HAL_PWR_LinearRangeSelToVolt(const struct PWR_LINEAR_RANGE_TABLE *linearTables, uint32_t sel);
  137. int HAL_PWR_LinearRangeVoltToSel(const struct PWR_LINEAR_RANGE_TABLE *linearTables, uint32_t volt);
  138. /** @} */
  139. #endif
  140. /** @} */
  141. /** @} */