mt_spm_idle.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (c) 2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <lib/mmio.h>
  8. #include <mt_spm.h>
  9. #include <mt_spm_conservation.h>
  10. #include <mt_spm_idle.h>
  11. #include <mt_spm_internal.h>
  12. #include <mt_spm_reg.h>
  13. #include <mt_spm_resource_req.h>
  14. #include <plat_pm.h>
  15. #define __WAKE_SRC_FOR_SUSPEND_COMMON__ \
  16. (R12_PCM_TIMER | \
  17. R12_KP_IRQ_B | \
  18. R12_APWDT_EVENT_B | \
  19. R12_APXGPT1_EVENT_B | \
  20. R12_CONN2AP_SPM_WAKEUP_B | \
  21. R12_EINT_EVENT_B | \
  22. R12_CONN_WDT_IRQ_B | \
  23. R12_SSPM2SPM_WAKEUP_B | \
  24. R12_SCP2SPM_WAKEUP_B | \
  25. R12_ADSP2SPM_WAKEUP_B | \
  26. R12_USBX_CDSC_B | \
  27. R12_USBX_POWERDWN_B | \
  28. R12_SYS_TIMER_EVENT_B | \
  29. R12_EINT_EVENT_SECURE_B | \
  30. R12_AFE_IRQ_MCU_B | \
  31. R12_SYS_CIRQ_IRQ_B | \
  32. R12_NNA_WAKEUP | \
  33. R12_SEJ_EVENT_B | \
  34. R12_REG_CPU_WAKEUP)
  35. #if defined(CFG_MICROTRUST_TEE_SUPPORT)
  36. #define WAKE_SRC_FOR_SUSPEND (__WAKE_SRC_FOR_SUSPEND_COMMON__)
  37. #else
  38. #define WAKE_SRC_FOR_SUSPEND \
  39. (__WAKE_SRC_FOR_SUSPEND_COMMON__ | \
  40. R12_SEJ_EVENT_B)
  41. #endif
  42. static struct pwr_ctrl idle_spm_pwr = {
  43. .timer_val = 0x28000,
  44. .wake_src = WAKE_SRC_FOR_SUSPEND,
  45. /* Auto-gen Start */
  46. /* SPM_AP_STANDBY_CON */
  47. .reg_wfi_op = 0,
  48. .reg_wfi_type = 0,
  49. .reg_mp0_cputop_idle_mask = 0,
  50. .reg_mp1_cputop_idle_mask = 0,
  51. .reg_mcusys_idle_mask = 0,
  52. .reg_md_apsrc_1_sel = 0,
  53. .reg_md_apsrc_0_sel = 0,
  54. .reg_conn_apsrc_sel = 0,
  55. /* SPM_SRC6_MASK */
  56. .reg_ccif_event_infra_req_mask_b = 0,
  57. .reg_ccif_event_apsrc_req_mask_b = 0,
  58. /* SPM_SRC_REQ */
  59. .reg_spm_apsrc_req = 0,
  60. .reg_spm_f26m_req = 0,
  61. .reg_spm_infra_req = 0,
  62. .reg_spm_vrf18_req = 0,
  63. .reg_spm_ddren_req = 0,
  64. .reg_spm_dvfs_req = 0,
  65. .reg_spm_sw_mailbox_req = 0,
  66. .reg_spm_sspm_mailbox_req = 0,
  67. .reg_spm_adsp_mailbox_req = 0,
  68. .reg_spm_scp_mailbox_req = 0,
  69. /* SPM_SRC_MASK */
  70. .reg_md_0_srcclkena_mask_b = 0,
  71. .reg_md_0_infra_req_mask_b = 0,
  72. .reg_md_0_apsrc_req_mask_b = 0,
  73. .reg_md_0_vrf18_req_mask_b = 0,
  74. .reg_md_0_ddren_req_mask_b = 0,
  75. .reg_md_1_srcclkena_mask_b = 0,
  76. .reg_md_1_infra_req_mask_b = 0,
  77. .reg_md_1_apsrc_req_mask_b = 0,
  78. .reg_md_1_vrf18_req_mask_b = 0,
  79. .reg_md_1_ddren_req_mask_b = 0,
  80. .reg_conn_srcclkena_mask_b = 1,
  81. .reg_conn_srcclkenb_mask_b = 0,
  82. .reg_conn_infra_req_mask_b = 1,
  83. .reg_conn_apsrc_req_mask_b = 1,
  84. .reg_conn_vrf18_req_mask_b = 1,
  85. .reg_conn_ddren_req_mask_b = 1,
  86. .reg_conn_vfe28_mask_b = 0,
  87. .reg_srcclkeni_srcclkena_mask_b = 1,
  88. .reg_srcclkeni_infra_req_mask_b = 1,
  89. .reg_infrasys_apsrc_req_mask_b = 0,
  90. .reg_infrasys_ddren_req_mask_b = 1,
  91. .reg_sspm_srcclkena_mask_b = 1,
  92. .reg_sspm_infra_req_mask_b = 1,
  93. .reg_sspm_apsrc_req_mask_b = 1,
  94. .reg_sspm_vrf18_req_mask_b = 1,
  95. .reg_sspm_ddren_req_mask_b = 1,
  96. /* SPM_SRC2_MASK */
  97. .reg_scp_srcclkena_mask_b = 1,
  98. .reg_scp_infra_req_mask_b = 1,
  99. .reg_scp_apsrc_req_mask_b = 1,
  100. .reg_scp_vrf18_req_mask_b = 1,
  101. .reg_scp_ddren_req_mask_b = 1,
  102. .reg_audio_dsp_srcclkena_mask_b = 1,
  103. .reg_audio_dsp_infra_req_mask_b = 1,
  104. .reg_audio_dsp_apsrc_req_mask_b = 1,
  105. .reg_audio_dsp_vrf18_req_mask_b = 1,
  106. .reg_audio_dsp_ddren_req_mask_b = 1,
  107. .reg_ufs_srcclkena_mask_b = 1,
  108. .reg_ufs_infra_req_mask_b = 1,
  109. .reg_ufs_apsrc_req_mask_b = 1,
  110. .reg_ufs_vrf18_req_mask_b = 1,
  111. .reg_ufs_ddren_req_mask_b = 1,
  112. .reg_disp0_apsrc_req_mask_b = 1,
  113. .reg_disp0_ddren_req_mask_b = 1,
  114. .reg_disp1_apsrc_req_mask_b = 1,
  115. .reg_disp1_ddren_req_mask_b = 1,
  116. .reg_gce_infra_req_mask_b = 1,
  117. .reg_gce_apsrc_req_mask_b = 1,
  118. .reg_gce_vrf18_req_mask_b = 1,
  119. .reg_gce_ddren_req_mask_b = 1,
  120. .reg_apu_srcclkena_mask_b = 0,
  121. .reg_apu_infra_req_mask_b = 0,
  122. .reg_apu_apsrc_req_mask_b = 0,
  123. .reg_apu_vrf18_req_mask_b = 0,
  124. .reg_apu_ddren_req_mask_b = 0,
  125. .reg_cg_check_srcclkena_mask_b = 0,
  126. .reg_cg_check_apsrc_req_mask_b = 0,
  127. .reg_cg_check_vrf18_req_mask_b = 0,
  128. .reg_cg_check_ddren_req_mask_b = 0,
  129. /* SPM_SRC3_MASK */
  130. .reg_dvfsrc_event_trigger_mask_b = 1,
  131. .reg_sw2spm_wakeup_mask_b = 0,
  132. .reg_adsp2spm_wakeup_mask_b = 0,
  133. .reg_sspm2spm_wakeup_mask_b = 0,
  134. .reg_scp2spm_wakeup_mask_b = 0,
  135. .reg_csyspwrup_ack_mask = 1,
  136. .reg_spm_reserved_srcclkena_mask_b = 0,
  137. .reg_spm_reserved_infra_req_mask_b = 0,
  138. .reg_spm_reserved_apsrc_req_mask_b = 0,
  139. .reg_spm_reserved_vrf18_req_mask_b = 0,
  140. .reg_spm_reserved_ddren_req_mask_b = 0,
  141. .reg_mcupm_srcclkena_mask_b = 0,
  142. .reg_mcupm_infra_req_mask_b = 0,
  143. .reg_mcupm_apsrc_req_mask_b = 0,
  144. .reg_mcupm_vrf18_req_mask_b = 0,
  145. .reg_mcupm_ddren_req_mask_b = 0,
  146. .reg_msdc0_srcclkena_mask_b = 1,
  147. .reg_msdc0_infra_req_mask_b = 1,
  148. .reg_msdc0_apsrc_req_mask_b = 1,
  149. .reg_msdc0_vrf18_req_mask_b = 1,
  150. .reg_msdc0_ddren_req_mask_b = 1,
  151. .reg_msdc1_srcclkena_mask_b = 1,
  152. .reg_msdc1_infra_req_mask_b = 1,
  153. .reg_msdc1_apsrc_req_mask_b = 1,
  154. .reg_msdc1_vrf18_req_mask_b = 1,
  155. .reg_msdc1_ddren_req_mask_b = 1,
  156. /* SPM_SRC4_MASK */
  157. .reg_ccif_event_srcclkena_mask_b = 0,
  158. .reg_bak_psri_srcclkena_mask_b = 0,
  159. .reg_bak_psri_infra_req_mask_b = 0,
  160. .reg_bak_psri_apsrc_req_mask_b = 0,
  161. .reg_bak_psri_vrf18_req_mask_b = 0,
  162. .reg_bak_psri_ddren_req_mask_b = 0,
  163. .reg_dramc_md32_infra_req_mask_b = 0,
  164. .reg_dramc_md32_vrf18_req_mask_b = 0,
  165. .reg_conn_srcclkenb2pwrap_mask_b = 0,
  166. .reg_dramc_md32_apsrc_req_mask_b = 0,
  167. /* SPM_SRC5_MASK */
  168. .reg_mcusys_merge_apsrc_req_mask_b = 0x83,
  169. .reg_mcusys_merge_ddren_req_mask_b = 0x83,
  170. .reg_afe_srcclkena_mask_b = 1,
  171. .reg_afe_infra_req_mask_b = 1,
  172. .reg_afe_apsrc_req_mask_b = 1,
  173. .reg_afe_vrf18_req_mask_b = 1,
  174. .reg_afe_ddren_req_mask_b = 1,
  175. .reg_msdc2_srcclkena_mask_b = 0,
  176. .reg_msdc2_infra_req_mask_b = 0,
  177. .reg_msdc2_apsrc_req_mask_b = 0,
  178. .reg_msdc2_vrf18_req_mask_b = 0,
  179. .reg_msdc2_ddren_req_mask_b = 0,
  180. /* SPM_WAKEUP_EVENT_MASK */
  181. .reg_wakeup_event_mask = 0xE1283203,
  182. /* SPM_WAKEUP_EVENT_EXT_MASK */
  183. .reg_ext_wakeup_event_mask = 0xFFFFFFFF,
  184. /* SPM_SRC7_MASK */
  185. .reg_pcie_srcclkena_mask_b = 0,
  186. .reg_pcie_infra_req_mask_b = 0,
  187. .reg_pcie_apsrc_req_mask_b = 0,
  188. .reg_pcie_vrf18_req_mask_b = 0,
  189. .reg_pcie_ddren_req_mask_b = 0,
  190. .reg_dpmaif_srcclkena_mask_b = 1,
  191. .reg_dpmaif_infra_req_mask_b = 1,
  192. .reg_dpmaif_apsrc_req_mask_b = 1,
  193. .reg_dpmaif_vrf18_req_mask_b = 1,
  194. .reg_dpmaif_ddren_req_mask_b = 1,
  195. /* Auto-gen End */
  196. };
  197. struct spm_lp_scen idle_spm_lp = {
  198. .pwrctrl = &idle_spm_pwr,
  199. };
  200. int mt_spm_idle_generic_enter(int state_id, unsigned int ext_opand,
  201. spm_idle_conduct fn)
  202. {
  203. unsigned int src_req = 0U;
  204. if (fn != NULL) {
  205. fn(&idle_spm_lp, &src_req);
  206. }
  207. return spm_conservation(state_id, ext_opand, &idle_spm_lp, src_req);
  208. }
  209. void mt_spm_idle_generic_resume(int state_id, unsigned int ext_opand,
  210. struct wake_status **status,
  211. spm_idle_conduct_restore fn)
  212. {
  213. ext_opand |= (MT_SPM_EX_OP_TIME_CHECK | MT_SPM_EX_OP_TIME_OBS);
  214. spm_conservation_finish(state_id, ext_opand, &idle_spm_lp, status);
  215. }
  216. void mt_spm_idle_generic_init(void)
  217. {
  218. spm_conservation_pwrctrl_init(idle_spm_lp.pwrctrl);
  219. }