mt_spm_idle.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * Copyright (c) 2021, 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_IDLE_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_CCIF0_EVENT_B | \
  24. R12_SSPM2SPM_WAKEUP_B | \
  25. R12_SCP2SPM_WAKEUP_B | \
  26. R12_ADSP2SPM_WAKEUP_B | \
  27. R12_USBX_CDSC_B | \
  28. R12_USBX_POWERDWN_B | \
  29. R12_SYS_TIMER_EVENT_B | \
  30. R12_EINT_EVENT_SECURE_B | \
  31. R12_AFE_IRQ_MCU_B | \
  32. R12_SYS_CIRQ_IRQ_B | \
  33. R12_MD2AP_PEER_EVENT_B | \
  34. R12_MD1_WDT_B | \
  35. R12_CLDMA_EVENT_B | \
  36. R12_REG_CPU_WAKEUP | \
  37. R12_APUSYS_WAKE_HOST_B)
  38. #if defined(CFG_MICROTRUST_TEE_SUPPORT)
  39. #define WAKE_SRC_FOR_IDLE (__WAKE_SRC_FOR_IDLE_COMMON__)
  40. #else
  41. #define WAKE_SRC_FOR_IDLE \
  42. (__WAKE_SRC_FOR_IDLE_COMMON__ | \
  43. R12_SEJ_EVENT_B)
  44. #endif
  45. static struct pwr_ctrl idle_spm_pwr = {
  46. .wake_src = WAKE_SRC_FOR_IDLE,
  47. /* SPM_AP_STANDBY_CON */
  48. /* [0] */
  49. .reg_wfi_op = 0,
  50. /* [1] */
  51. .reg_wfi_type = 0,
  52. /* [2] */
  53. .reg_mp0_cputop_idle_mask = 0,
  54. /* [3] */
  55. .reg_mp1_cputop_idle_mask = 0,
  56. /* [4] */
  57. .reg_mcusys_idle_mask = 0,
  58. /* [25] */
  59. .reg_md_apsrc_1_sel = 0,
  60. /* [26] */
  61. .reg_md_apsrc_0_sel = 0,
  62. /* [29] */
  63. .reg_conn_apsrc_sel = 0,
  64. /* SPM_SRC_REQ */
  65. /* [0] */
  66. .reg_spm_apsrc_req = 0,
  67. /* [1] */
  68. .reg_spm_f26m_req = 1,
  69. /* [3] */
  70. .reg_spm_infra_req = 1,
  71. /* [4] */
  72. .reg_spm_vrf18_req = 0,
  73. /* [7] FIXME: default disable HW Auto S1 */
  74. .reg_spm_ddr_en_req = 1,
  75. /* [8] */
  76. .reg_spm_dvfs_req = 0,
  77. /* [9] */
  78. .reg_spm_sw_mailbox_req = 0,
  79. /* [10] */
  80. .reg_spm_sspm_mailbox_req = 0,
  81. /* [11] */
  82. .reg_spm_adsp_mailbox_req = 0,
  83. /* [12] */
  84. .reg_spm_scp_mailbox_req = 0,
  85. /* SPM_SRC_MASK */
  86. /* [0] */
  87. .reg_sspm_srcclkena_0_mask_b = 1,
  88. /* [1] */
  89. .reg_sspm_infra_req_0_mask_b = 1,
  90. /* [2] */
  91. .reg_sspm_apsrc_req_0_mask_b = 1,
  92. /* [3] */
  93. .reg_sspm_vrf18_req_0_mask_b = 1,
  94. /* [4] */
  95. .reg_sspm_ddr_en_0_mask_b = 1,
  96. /* [5] */
  97. .reg_scp_srcclkena_mask_b = 1,
  98. /* [6] */
  99. .reg_scp_infra_req_mask_b = 1,
  100. /* [7] */
  101. .reg_scp_apsrc_req_mask_b = 1,
  102. /* [8] */
  103. .reg_scp_vrf18_req_mask_b = 1,
  104. /* [9] */
  105. .reg_scp_ddr_en_mask_b = 1,
  106. /* [10] */
  107. .reg_audio_dsp_srcclkena_mask_b = 1,
  108. /* [11] */
  109. .reg_audio_dsp_infra_req_mask_b = 1,
  110. /* [12] */
  111. .reg_audio_dsp_apsrc_req_mask_b = 1,
  112. /* [13] */
  113. .reg_audio_dsp_vrf18_req_mask_b = 1,
  114. /* [14] */
  115. .reg_audio_dsp_ddr_en_mask_b = 1,
  116. /* [15] */
  117. .reg_apu_srcclkena_mask_b = 1,
  118. /* [16] */
  119. .reg_apu_infra_req_mask_b = 1,
  120. /* [17] */
  121. .reg_apu_apsrc_req_mask_b = 1,
  122. /* [18] */
  123. .reg_apu_vrf18_req_mask_b = 1,
  124. /* [19] */
  125. .reg_apu_ddr_en_mask_b = 1,
  126. /* [20] */
  127. .reg_cpueb_srcclkena_mask_b = 1,
  128. /* [21] */
  129. .reg_cpueb_infra_req_mask_b = 1,
  130. /* [22] */
  131. .reg_cpueb_apsrc_req_mask_b = 1,
  132. /* [23] */
  133. .reg_cpueb_vrf18_req_mask_b = 1,
  134. /* [24] */
  135. .reg_cpueb_ddr_en_mask_b = 1,
  136. /* [25] */
  137. .reg_bak_psri_srcclkena_mask_b = 0,
  138. /* [26] */
  139. .reg_bak_psri_infra_req_mask_b = 0,
  140. /* [27] */
  141. .reg_bak_psri_apsrc_req_mask_b = 0,
  142. /* [28] */
  143. .reg_bak_psri_vrf18_req_mask_b = 0,
  144. /* [29] */
  145. .reg_bak_psri_ddr_en_mask_b = 0,
  146. /* SPM_SRC2_MASK */
  147. /* [0] */
  148. .reg_msdc0_srcclkena_mask_b = 1,
  149. /* [1] */
  150. .reg_msdc0_infra_req_mask_b = 1,
  151. /* [2] */
  152. .reg_msdc0_apsrc_req_mask_b = 1,
  153. /* [3] */
  154. .reg_msdc0_vrf18_req_mask_b = 1,
  155. /* [4] */
  156. .reg_msdc0_ddr_en_mask_b = 1,
  157. /* [5] */
  158. .reg_msdc1_srcclkena_mask_b = 1,
  159. /* [6] */
  160. .reg_msdc1_infra_req_mask_b = 1,
  161. /* [7] */
  162. .reg_msdc1_apsrc_req_mask_b = 1,
  163. /* [8] */
  164. .reg_msdc1_vrf18_req_mask_b = 1,
  165. /* [9] */
  166. .reg_msdc1_ddr_en_mask_b = 1,
  167. /* [10] */
  168. .reg_msdc2_srcclkena_mask_b = 1,
  169. /* [11] */
  170. .reg_msdc2_infra_req_mask_b = 1,
  171. /* [12] */
  172. .reg_msdc2_apsrc_req_mask_b = 1,
  173. /* [13] */
  174. .reg_msdc2_vrf18_req_mask_b = 1,
  175. /* [14] */
  176. .reg_msdc2_ddr_en_mask_b = 1,
  177. /* [15] */
  178. .reg_ufs_srcclkena_mask_b = 1,
  179. /* [16] */
  180. .reg_ufs_infra_req_mask_b = 1,
  181. /* [17] */
  182. .reg_ufs_apsrc_req_mask_b = 1,
  183. /* [18] */
  184. .reg_ufs_vrf18_req_mask_b = 1,
  185. /* [19] */
  186. .reg_ufs_ddr_en_mask_b = 1,
  187. /* [20] */
  188. .reg_usb_srcclkena_mask_b = 1,
  189. /* [21] */
  190. .reg_usb_infra_req_mask_b = 1,
  191. /* [22] */
  192. .reg_usb_apsrc_req_mask_b = 1,
  193. /* [23] */
  194. .reg_usb_vrf18_req_mask_b = 1,
  195. /* [24] */
  196. .reg_usb_ddr_en_mask_b = 1,
  197. /* [25] */
  198. .reg_pextp_p0_srcclkena_mask_b = 1,
  199. /* [26] */
  200. .reg_pextp_p0_infra_req_mask_b = 1,
  201. /* [27] */
  202. .reg_pextp_p0_apsrc_req_mask_b = 1,
  203. /* [28] */
  204. .reg_pextp_p0_vrf18_req_mask_b = 1,
  205. /* [29] */
  206. .reg_pextp_p0_ddr_en_mask_b = 1,
  207. /* SPM_SRC3_MASK */
  208. /* [0] */
  209. .reg_pextp_p1_srcclkena_mask_b = 1,
  210. /* [1] */
  211. .reg_pextp_p1_infra_req_mask_b = 1,
  212. /* [2] */
  213. .reg_pextp_p1_apsrc_req_mask_b = 1,
  214. /* [3] */
  215. .reg_pextp_p1_vrf18_req_mask_b = 1,
  216. /* [4] */
  217. .reg_pextp_p1_ddr_en_mask_b = 1,
  218. /* [5] */
  219. .reg_gce0_infra_req_mask_b = 1,
  220. /* [6] */
  221. .reg_gce0_apsrc_req_mask_b = 1,
  222. /* [7] */
  223. .reg_gce0_vrf18_req_mask_b = 1,
  224. /* [8] */
  225. .reg_gce0_ddr_en_mask_b = 1,
  226. /* [9] */
  227. .reg_gce1_infra_req_mask_b = 1,
  228. /* [10] */
  229. .reg_gce1_apsrc_req_mask_b = 1,
  230. /* [11] */
  231. .reg_gce1_vrf18_req_mask_b = 1,
  232. /* [12] */
  233. .reg_gce1_ddr_en_mask_b = 1,
  234. /* [13] */
  235. .reg_spm_srcclkena_reserved_mask_b = 1,
  236. /* [14] */
  237. .reg_spm_infra_req_reserved_mask_b = 1,
  238. /* [15] */
  239. .reg_spm_apsrc_req_reserved_mask_b = 1,
  240. /* [16] */
  241. .reg_spm_vrf18_req_reserved_mask_b = 1,
  242. /* [17] */
  243. .reg_spm_ddr_en_reserved_mask_b = 1,
  244. /* [18] */
  245. .reg_disp0_apsrc_req_mask_b = 1,
  246. /* [19] */
  247. .reg_disp0_ddr_en_mask_b = 1,
  248. /* [20] */
  249. .reg_disp1_apsrc_req_mask_b = 1,
  250. /* [21] */
  251. .reg_disp1_ddr_en_mask_b = 1,
  252. /* [22] */
  253. .reg_disp2_apsrc_req_mask_b = 1,
  254. /* [23] */
  255. .reg_disp2_ddr_en_mask_b = 1,
  256. /* [24] */
  257. .reg_disp3_apsrc_req_mask_b = 1,
  258. /* [25] */
  259. .reg_disp3_ddr_en_mask_b = 1,
  260. /* [26] */
  261. .reg_infrasys_apsrc_req_mask_b = 0,
  262. /* [27] */
  263. .reg_infrasys_ddr_en_mask_b = 1,
  264. /* [28] */
  265. .reg_cg_check_srcclkena_mask_b = 1,
  266. /* [29] */
  267. .reg_cg_check_apsrc_req_mask_b = 1,
  268. /* [30] */
  269. .reg_cg_check_vrf18_req_mask_b = 1,
  270. /* [31] */
  271. .reg_cg_check_ddr_en_mask_b = 1,
  272. /* SPM_SRC4_MASK */
  273. /* [8:0] */
  274. .reg_mcusys_merge_apsrc_req_mask_b = 0x17,
  275. /* [17:9] */
  276. .reg_mcusys_merge_ddr_en_mask_b = 0x17,
  277. /* [19:18] */
  278. .reg_dramc_md32_infra_req_mask_b = 0,
  279. /* [21:20] */
  280. .reg_dramc_md32_vrf18_req_mask_b = 0,
  281. /* [23:22] */
  282. .reg_dramc_md32_ddr_en_mask_b = 0,
  283. /* [24] */
  284. .reg_dvfsrc_event_trigger_mask_b = 1,
  285. /* SPM_WAKEUP_EVENT_MASK2 */
  286. /* [3:0] */
  287. .reg_sc_sw2spm_wakeup_mask_b = 0,
  288. /* [4] */
  289. .reg_sc_adsp2spm_wakeup_mask_b = 0,
  290. /* [8:5] */
  291. .reg_sc_sspm2spm_wakeup_mask_b = 0,
  292. /* [9] */
  293. .reg_sc_scp2spm_wakeup_mask_b = 0,
  294. /* [10] */
  295. .reg_csyspwrup_ack_mask = 0,
  296. /* [11] */
  297. .reg_csyspwrup_req_mask = 1,
  298. /* SPM_WAKEUP_EVENT_MASK */
  299. /* [31:0] */
  300. .reg_wakeup_event_mask = 0xC1282203,
  301. /* SPM_WAKEUP_EVENT_EXT_MASK */
  302. /* [31:0] */
  303. .reg_ext_wakeup_event_mask = 0xFFFFFFFF,
  304. };
  305. struct spm_lp_scen idle_spm_lp = {
  306. .pwrctrl = &idle_spm_pwr,
  307. };
  308. int mt_spm_idle_generic_enter(int state_id, unsigned int ext_opand,
  309. spm_idle_conduct fn)
  310. {
  311. unsigned int src_req = 0;
  312. if (fn != NULL) {
  313. fn(&idle_spm_lp, &src_req);
  314. }
  315. return spm_conservation(state_id, ext_opand, &idle_spm_lp, src_req);
  316. }
  317. void mt_spm_idle_generic_resume(int state_id, unsigned int ext_opand,
  318. struct wake_status **status)
  319. {
  320. spm_conservation_finish(state_id, ext_opand, &idle_spm_lp, status);
  321. }
  322. void mt_spm_idle_generic_init(void)
  323. {
  324. spm_conservation_pwrctrl_init(idle_spm_lp.pwrctrl);
  325. }