mt_spm_idle.c 8.0 KB

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