mt_spm_suspend.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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_internal.h>
  11. #include <mt_spm_rc_internal.h>
  12. #include <mt_spm_reg.h>
  13. #include <mt_spm_resource_req.h>
  14. #include <mt_spm_suspend.h>
  15. #include <plat_pm.h>
  16. #include <uart.h>
  17. #define SPM_SUSPEND_SLEEP_PCM_FLAG \
  18. (SPM_FLAG_DISABLE_INFRA_PDN | \
  19. SPM_FLAG_DISABLE_VCORE_DVS | \
  20. SPM_FLAG_DISABLE_VCORE_DFS | \
  21. SPM_FLAG_USE_SRCCLKENO2)
  22. #define SPM_SUSPEND_SLEEP_PCM_FLAG1 (0U)
  23. #define SPM_SUSPEND_PCM_FLAG \
  24. (SPM_FLAG_DISABLE_VCORE_DVS | \
  25. SPM_FLAG_DISABLE_VCORE_DFS)
  26. #define SPM_SUSPEND_PCM_FLAG1 (0U)
  27. #define __WAKE_SRC_FOR_SUSPEND_COMMON__ \
  28. (R12_PCM_TIMER | \
  29. R12_KP_IRQ_B | \
  30. R12_APWDT_EVENT_B | \
  31. R12_CONN2AP_SPM_WAKEUP_B | \
  32. R12_EINT_EVENT_B | \
  33. R12_CONN_WDT_IRQ_B | \
  34. R12_SSPM2SPM_WAKEUP_B | \
  35. R12_SCP2SPM_WAKEUP_B | \
  36. R12_ADSP2SPM_WAKEUP_B | \
  37. R12_USBX_CDSC_B | \
  38. R12_USBX_POWERDWN_B | \
  39. R12_SYS_TIMER_EVENT_B | \
  40. R12_EINT_EVENT_SECURE_B | \
  41. R12_SYS_CIRQ_IRQ_B | \
  42. R12_NNA_WAKEUP | \
  43. R12_REG_CPU_WAKEUP)
  44. #if defined(CFG_MICROTRUST_TEE_SUPPORT)
  45. #define WAKE_SRC_FOR_SUSPEND (__WAKE_SRC_FOR_SUSPEND_COMMON__)
  46. #else
  47. #define WAKE_SRC_FOR_SUSPEND \
  48. (__WAKE_SRC_FOR_SUSPEND_COMMON__ | \
  49. R12_SEJ_EVENT_B)
  50. #endif
  51. static struct pwr_ctrl suspend_ctrl = {
  52. .wake_src = WAKE_SRC_FOR_SUSPEND,
  53. /* Auto-gen Start */
  54. /* SPM_AP_STANDBY_CON */
  55. .reg_wfi_op = 0,
  56. .reg_wfi_type = 0,
  57. .reg_mp0_cputop_idle_mask = 0,
  58. .reg_mp1_cputop_idle_mask = 0,
  59. .reg_mcusys_idle_mask = 0,
  60. .reg_md_apsrc_1_sel = 0,
  61. .reg_md_apsrc_0_sel = 0,
  62. .reg_conn_apsrc_sel = 0,
  63. /* SPM_SRC6_MASK */
  64. .reg_ccif_event_infra_req_mask_b = 0,
  65. .reg_ccif_event_apsrc_req_mask_b = 0,
  66. /* SPM_SRC_REQ */
  67. .reg_spm_apsrc_req = 0,
  68. .reg_spm_f26m_req = 0,
  69. .reg_spm_infra_req = 0,
  70. .reg_spm_vrf18_req = 0,
  71. .reg_spm_ddren_req = 0,
  72. .reg_spm_dvfs_req = 0,
  73. .reg_spm_sw_mailbox_req = 0,
  74. .reg_spm_sspm_mailbox_req = 0,
  75. .reg_spm_adsp_mailbox_req = 0,
  76. .reg_spm_scp_mailbox_req = 0,
  77. /* SPM_SRC_MASK */
  78. .reg_md_0_srcclkena_mask_b = 0,
  79. .reg_md_0_infra_req_mask_b = 0,
  80. .reg_md_0_apsrc_req_mask_b = 0,
  81. .reg_md_0_vrf18_req_mask_b = 0,
  82. .reg_md_0_ddren_req_mask_b = 0,
  83. .reg_md_1_srcclkena_mask_b = 0,
  84. .reg_md_1_infra_req_mask_b = 0,
  85. .reg_md_1_apsrc_req_mask_b = 0,
  86. .reg_md_1_vrf18_req_mask_b = 0,
  87. .reg_md_1_ddren_req_mask_b = 0,
  88. .reg_conn_srcclkena_mask_b = 1,
  89. .reg_conn_srcclkenb_mask_b = 0,
  90. .reg_conn_infra_req_mask_b = 1,
  91. .reg_conn_apsrc_req_mask_b = 1,
  92. .reg_conn_vrf18_req_mask_b = 1,
  93. .reg_conn_ddren_req_mask_b = 1,
  94. .reg_conn_vfe28_mask_b = 0,
  95. .reg_srcclkeni_srcclkena_mask_b = 1,
  96. .reg_srcclkeni_infra_req_mask_b = 1,
  97. .reg_infrasys_apsrc_req_mask_b = 0,
  98. .reg_infrasys_ddren_req_mask_b = 1,
  99. .reg_sspm_srcclkena_mask_b = 1,
  100. .reg_sspm_infra_req_mask_b = 1,
  101. .reg_sspm_apsrc_req_mask_b = 1,
  102. .reg_sspm_vrf18_req_mask_b = 1,
  103. .reg_sspm_ddren_req_mask_b = 1,
  104. /* SPM_SRC2_MASK */
  105. .reg_scp_srcclkena_mask_b = 1,
  106. .reg_scp_infra_req_mask_b = 1,
  107. .reg_scp_apsrc_req_mask_b = 1,
  108. .reg_scp_vrf18_req_mask_b = 1,
  109. .reg_scp_ddren_req_mask_b = 1,
  110. .reg_audio_dsp_srcclkena_mask_b = 1,
  111. .reg_audio_dsp_infra_req_mask_b = 1,
  112. .reg_audio_dsp_apsrc_req_mask_b = 1,
  113. .reg_audio_dsp_vrf18_req_mask_b = 1,
  114. .reg_audio_dsp_ddren_req_mask_b = 1,
  115. .reg_ufs_srcclkena_mask_b = 1,
  116. .reg_ufs_infra_req_mask_b = 1,
  117. .reg_ufs_apsrc_req_mask_b = 1,
  118. .reg_ufs_vrf18_req_mask_b = 1,
  119. .reg_ufs_ddren_req_mask_b = 1,
  120. .reg_disp0_apsrc_req_mask_b = 1,
  121. .reg_disp0_ddren_req_mask_b = 1,
  122. .reg_disp1_apsrc_req_mask_b = 1,
  123. .reg_disp1_ddren_req_mask_b = 1,
  124. .reg_gce_infra_req_mask_b = 1,
  125. .reg_gce_apsrc_req_mask_b = 1,
  126. .reg_gce_vrf18_req_mask_b = 1,
  127. .reg_gce_ddren_req_mask_b = 1,
  128. .reg_apu_srcclkena_mask_b = 0,
  129. .reg_apu_infra_req_mask_b = 0,
  130. .reg_apu_apsrc_req_mask_b = 0,
  131. .reg_apu_vrf18_req_mask_b = 0,
  132. .reg_apu_ddren_req_mask_b = 0,
  133. .reg_cg_check_srcclkena_mask_b = 0,
  134. .reg_cg_check_apsrc_req_mask_b = 0,
  135. .reg_cg_check_vrf18_req_mask_b = 0,
  136. .reg_cg_check_ddren_req_mask_b = 0,
  137. /* SPM_SRC3_MASK */
  138. .reg_dvfsrc_event_trigger_mask_b = 1,
  139. .reg_sw2spm_wakeup_mask_b = 0,
  140. .reg_adsp2spm_wakeup_mask_b = 0,
  141. .reg_sspm2spm_wakeup_mask_b = 0,
  142. .reg_scp2spm_wakeup_mask_b = 0,
  143. .reg_csyspwrup_ack_mask = 1,
  144. .reg_spm_reserved_srcclkena_mask_b = 0,
  145. .reg_spm_reserved_infra_req_mask_b = 0,
  146. .reg_spm_reserved_apsrc_req_mask_b = 0,
  147. .reg_spm_reserved_vrf18_req_mask_b = 0,
  148. .reg_spm_reserved_ddren_req_mask_b = 0,
  149. .reg_mcupm_srcclkena_mask_b = 0,
  150. .reg_mcupm_infra_req_mask_b = 0,
  151. .reg_mcupm_apsrc_req_mask_b = 0,
  152. .reg_mcupm_vrf18_req_mask_b = 0,
  153. .reg_mcupm_ddren_req_mask_b = 0,
  154. .reg_msdc0_srcclkena_mask_b = 1,
  155. .reg_msdc0_infra_req_mask_b = 1,
  156. .reg_msdc0_apsrc_req_mask_b = 1,
  157. .reg_msdc0_vrf18_req_mask_b = 1,
  158. .reg_msdc0_ddren_req_mask_b = 1,
  159. .reg_msdc1_srcclkena_mask_b = 1,
  160. .reg_msdc1_infra_req_mask_b = 1,
  161. .reg_msdc1_apsrc_req_mask_b = 1,
  162. .reg_msdc1_vrf18_req_mask_b = 1,
  163. .reg_msdc1_ddren_req_mask_b = 1,
  164. /* SPM_SRC4_MASK */
  165. .reg_ccif_event_srcclkena_mask_b = 0,
  166. .reg_bak_psri_srcclkena_mask_b = 0,
  167. .reg_bak_psri_infra_req_mask_b = 0,
  168. .reg_bak_psri_apsrc_req_mask_b = 0,
  169. .reg_bak_psri_vrf18_req_mask_b = 0,
  170. .reg_bak_psri_ddren_req_mask_b = 0,
  171. .reg_dramc_md32_infra_req_mask_b = 0,
  172. .reg_dramc_md32_vrf18_req_mask_b = 0,
  173. .reg_conn_srcclkenb2pwrap_mask_b = 0,
  174. .reg_dramc_md32_apsrc_req_mask_b = 0,
  175. /* SPM_SRC5_MASK */
  176. .reg_mcusys_merge_apsrc_req_mask_b = 0x83,
  177. .reg_mcusys_merge_ddren_req_mask_b = 0x83,
  178. .reg_afe_srcclkena_mask_b = 1,
  179. .reg_afe_infra_req_mask_b = 1,
  180. .reg_afe_apsrc_req_mask_b = 1,
  181. .reg_afe_vrf18_req_mask_b = 1,
  182. .reg_afe_ddren_req_mask_b = 1,
  183. .reg_msdc2_srcclkena_mask_b = 0,
  184. .reg_msdc2_infra_req_mask_b = 0,
  185. .reg_msdc2_apsrc_req_mask_b = 0,
  186. .reg_msdc2_vrf18_req_mask_b = 0,
  187. .reg_msdc2_ddren_req_mask_b = 0,
  188. /* SPM_WAKEUP_EVENT_MASK */
  189. .reg_wakeup_event_mask = 0x1383213,
  190. /* SPM_WAKEUP_EVENT_EXT_MASK */
  191. .reg_ext_wakeup_event_mask = 0xFFFFFFFF,
  192. /* SPM_SRC7_MASK */
  193. .reg_pcie_srcclkena_mask_b = 0,
  194. .reg_pcie_infra_req_mask_b = 0,
  195. .reg_pcie_apsrc_req_mask_b = 0,
  196. .reg_pcie_vrf18_req_mask_b = 0,
  197. .reg_pcie_ddren_req_mask_b = 0,
  198. .reg_dpmaif_srcclkena_mask_b = 1,
  199. .reg_dpmaif_infra_req_mask_b = 1,
  200. .reg_dpmaif_apsrc_req_mask_b = 1,
  201. .reg_dpmaif_vrf18_req_mask_b = 1,
  202. .reg_dpmaif_ddren_req_mask_b = 1,
  203. /* Auto-gen End */
  204. /*sw flag setting */
  205. .pcm_flags = SPM_SUSPEND_PCM_FLAG,
  206. .pcm_flags1 = SPM_SUSPEND_PCM_FLAG1,
  207. };
  208. struct spm_lp_scen __spm_suspend = {
  209. .pwrctrl = &suspend_ctrl,
  210. };
  211. int mt_spm_suspend_mode_set(int mode)
  212. {
  213. if (mode == MT_SPM_SUSPEND_SLEEP) {
  214. suspend_ctrl.pcm_flags = SPM_SUSPEND_SLEEP_PCM_FLAG;
  215. suspend_ctrl.pcm_flags1 = SPM_SUSPEND_SLEEP_PCM_FLAG1;
  216. } else {
  217. suspend_ctrl.pcm_flags = SPM_SUSPEND_PCM_FLAG;
  218. suspend_ctrl.pcm_flags1 = SPM_SUSPEND_PCM_FLAG1;
  219. }
  220. return 0;
  221. }
  222. int mt_spm_suspend_enter(int state_id, unsigned int ext_opand,
  223. unsigned int resource_req)
  224. {
  225. /* If FMAudio / ADSP is active, change to sleep suspend mode */
  226. if ((ext_opand & MT_SPM_EX_OP_SET_SUSPEND_MODE) != 0U) {
  227. mt_spm_suspend_mode_set(MT_SPM_SUSPEND_SLEEP);
  228. }
  229. /* Notify MCUPM that device is going suspend flow */
  230. mmio_write_32(MCUPM_MBOX_OFFSET_PDN, MCUPM_POWER_DOWN);
  231. /* Notify UART to sleep */
  232. mt_uart_save();
  233. return spm_conservation(state_id, ext_opand,
  234. &__spm_suspend, resource_req);
  235. }
  236. void mt_spm_suspend_resume(int state_id, unsigned int ext_opand,
  237. struct wake_status **status)
  238. {
  239. spm_conservation_finish(state_id, ext_opand, &__spm_suspend, status);
  240. /* Notify UART to wakeup */
  241. mt_uart_restore();
  242. /* Notify MCUPM that device leave suspend */
  243. mmio_write_32(MCUPM_MBOX_OFFSET_PDN, 0);
  244. /* If FMAudio / ADSP is active, change back to suspend mode */
  245. if ((ext_opand & MT_SPM_EX_OP_SET_SUSPEND_MODE) != 0U) {
  246. mt_spm_suspend_mode_set(MT_SPM_SUSPEND_SYSTEM_PDN);
  247. }
  248. }
  249. void mt_spm_suspend_init(void)
  250. {
  251. spm_conservation_pwrctrl_init(__spm_suspend.pwrctrl);
  252. }