pwr_ctrl.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright 2023 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef PWR_CTRL_H
  7. #define PWR_CTRL_H
  8. #include <stdbool.h>
  9. #include <lib/mmio.h>
  10. #include <platform_def.h>
  11. /*******************************************************************************
  12. * GPC definitions & declarations
  13. ******************************************************************************/
  14. /* GPC GLOBAL */
  15. #define GPC_GLOBAL_BASE U(GPC_BASE + 0x4000)
  16. #define GPC_AUTHEN_CTRL U(0x4)
  17. #define GPC_DOMAIN U(0x10)
  18. #define GPC_MASTER U(0x1c)
  19. #define GPC_SYS_SLEEP U(0x40)
  20. #define PMIC_CTRL U(0x100)
  21. #define PMIC_PRE_DLY_CTRL U(0x104)
  22. #define PMIC_STBY_ACK_CTRL U(0x108)
  23. #define GPC_ROSC_CTRL U(0x200)
  24. #define GPC_AON_MEM_CTRL U(0x204)
  25. #define GPC_EFUSE_CTRL U(0x208)
  26. #define FORCE_CPUx_DISABLE(x) (1 << (16 + (x)))
  27. #define PMIC_STBY_EN BIT(0)
  28. #define ROSC_OFF_EN BIT(0)
  29. /* GPC CPU_CTRL */
  30. #define CM_SLICE(x) (GPC_BASE + 0x800 * (x))
  31. #define CM_AUTHEN_CTRL U(0x4)
  32. #define CM_MISC U(0xc)
  33. #define CM_MODE_CTRL U(0x10)
  34. #define CM_IRQ_WAKEUP_MASK0 U(0x100)
  35. #define CM_SYS_SLEEP_CTRL U(0x380)
  36. #define IMR_NUM U(8)
  37. /* CM_MISC */
  38. #define SLEEP_HOLD_EN BIT(1)
  39. #define IRQ_MUX BIT(5)
  40. #define SW_WAKEUP BIT(6)
  41. /* CM_SYS_SLEEP_CTRL */
  42. #define SS_WAIT BIT(0)
  43. #define SS_STOP BIT(1)
  44. #define SS_SUSPEND BIT(2)
  45. #define CM_MODE_RUN U(0x0)
  46. #define CM_MODE_WAIT U(0x1)
  47. #define CM_MODE_STOP U(0x2)
  48. #define CM_MODE_SUSPEND U(0x3)
  49. #define LPM_SETTING(d, m) ((m) << (((d) % 8) * 4))
  50. enum gpc_cmc_slice {
  51. CPU_M33,
  52. CPU_A55C0,
  53. CPU_A55C1,
  54. CPU_A55_PLAT,
  55. };
  56. /* set gpc domain assignment */
  57. static inline void gpc_assign_domains(unsigned int domains)
  58. {
  59. mmio_write_32(GPC_GLOBAL_BASE + GPC_DOMAIN, domains);
  60. }
  61. /* force a cpu into sleep status */
  62. static inline void gpc_force_cpu_suspend(unsigned int cpu)
  63. {
  64. mmio_setbits_32(GPC_GLOBAL_BASE + GPC_SYS_SLEEP, FORCE_CPUx_DISABLE(cpu));
  65. }
  66. static inline void gpc_pmic_stby_en(bool en)
  67. {
  68. mmio_write_32(GPC_GLOBAL_BASE + PMIC_CTRL, en ? 1 : 0);
  69. }
  70. static inline void gpc_rosc_off(bool off)
  71. {
  72. mmio_write_32(GPC_GLOBAL_BASE + GPC_ROSC_CTRL, off ? 1 : 0);
  73. }
  74. static inline void gpc_set_cpu_mode(unsigned int cpu, unsigned int mode)
  75. {
  76. mmio_write_32(CM_SLICE(cpu) + CM_MODE_CTRL, mode);
  77. }
  78. static inline void gpc_select_wakeup_gic(unsigned int cpu)
  79. {
  80. mmio_setbits_32(CM_SLICE(cpu) + CM_MISC, IRQ_MUX);
  81. }
  82. static inline void gpc_select_wakeup_raw_irq(unsigned int cpu)
  83. {
  84. mmio_clrbits_32(CM_SLICE(cpu) + CM_MISC, IRQ_MUX);
  85. }
  86. static inline void gpc_assert_sw_wakeup(unsigned int cpu)
  87. {
  88. mmio_setbits_32(CM_SLICE(cpu) + CM_MISC, SW_WAKEUP);
  89. }
  90. static inline void gpc_deassert_sw_wakeup(unsigned int cpu)
  91. {
  92. mmio_clrbits_32(CM_SLICE(cpu) + CM_MISC, SW_WAKEUP);
  93. }
  94. static inline void gpc_clear_cpu_sleep_hold(unsigned int cpu)
  95. {
  96. mmio_clrbits_32(CM_SLICE(cpu) + CM_MISC, SLEEP_HOLD_EN);
  97. }
  98. static inline void gpc_set_irq_mask(unsigned int cpu, unsigned int idx, uint32_t mask)
  99. {
  100. mmio_write_32(CM_SLICE(cpu) + idx * 0x4 + CM_IRQ_WAKEUP_MASK0, mask);
  101. }
  102. /*******************************************************************************
  103. * SRC definitions & declarations
  104. ******************************************************************************/
  105. #define SRC_SLICE(x) (SRC_BASE + 0x400 * (x))
  106. #define SRC_AUTHEN_CTRL U(0x4)
  107. #define SRC_LPM_SETTING0 U(0x10)
  108. #define SRC_LPM_SETTING1 U(0x14)
  109. #define SRC_LPM_SETTING2 U(0x18)
  110. #define SRC_SLICE_SW_CTRL U(0x20)
  111. #define SRC_MEM_CTRL U(0x4)
  112. #define MEM_LP_EN BIT(2)
  113. #define MEM_LP_RETN BIT(1)
  114. enum mix_mem_mode {
  115. MEM_OFF,
  116. MEM_RETN,
  117. };
  118. enum src_mix_mem_slice {
  119. SRC_GLOBAL,
  120. /* MIX slice */
  121. SRC_SENTINEL,
  122. SRC_AON,
  123. SRC_WKUP,
  124. SRC_DDR,
  125. SRC_DPHY,
  126. SRC_ML,
  127. SRC_NIC,
  128. SRC_HSIO,
  129. SRC_MEDIA,
  130. SRC_M33P,
  131. SRC_A55C0,
  132. SRC_A55C1,
  133. SRC_A55P,
  134. /* MEM slice */
  135. SRC_AON_MEM,
  136. SRC_WKUP_MEM,
  137. SRC_DDR_MEM,
  138. SRC_DPHY_MEM,
  139. SRC_ML_MEM,
  140. SRC_NIC_MEM,
  141. SRC_NIC_OCRAM,
  142. SRC_HSIO_MEM,
  143. SRC_MEDIA_MEM,
  144. SRC_A55P0_MEM,
  145. SRC_A55P1_MEM,
  146. SRC_A55_SCU_MEM,
  147. SRC_A55_L3_MEM,
  148. };
  149. static inline void src_authen_config(unsigned int mix, unsigned int wlist,
  150. unsigned int lpm_en)
  151. {
  152. mmio_write_32(SRC_SLICE(mix) + SRC_AUTHEN_CTRL, (wlist << 16) | (lpm_en << 2));
  153. }
  154. static inline void src_mix_set_lpm(unsigned int mix, unsigned int did, unsigned int lpm_mode)
  155. {
  156. mmio_clrsetbits_32(SRC_SLICE(mix) + SRC_LPM_SETTING1 + (did / 8) * 0x4,
  157. LPM_SETTING(did, 0x7), LPM_SETTING(did, lpm_mode));
  158. }
  159. static inline void src_mem_lpm_en(unsigned int mix, bool retn)
  160. {
  161. mmio_setbits_32(SRC_SLICE(mix) + SRC_MEM_CTRL, MEM_LP_EN | (retn ? MEM_LP_RETN : 0));
  162. }
  163. static inline void src_mem_lpm_dis(unsigned int mix)
  164. {
  165. mmio_clrbits_32(SRC_SLICE(mix) + SRC_MEM_CTRL, MEM_LP_EN | MEM_LP_RETN);
  166. }
  167. /*******************************************************************************
  168. * BLK_CTRL_S definitions & declarations
  169. ******************************************************************************/
  170. #define HW_LP_HANDHSK U(0x110)
  171. #define HW_LP_HANDHSK2 U(0x114)
  172. #define CA55_CPUWAIT U(0x118)
  173. #define CA55_RVBADDR0_L U(0x11c)
  174. #define CA55_RVBADDR0_H U(0x120)
  175. /*******************************************************************************
  176. * Other definitions & declarations
  177. ******************************************************************************/
  178. void pwr_sys_init(void);
  179. #endif /* PWR_CTRL_H */