mt_spm_rc_dram.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 2021, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <common/debug.h>
  8. #include <mt_lp_rm.h>
  9. #include <mt_spm.h>
  10. #include <mt_spm_cond.h>
  11. #include <mt_spm_constraint.h>
  12. #include <mt_spm_conservation.h>
  13. #include <mt_spm_idle.h>
  14. #include <mt_spm_internal.h>
  15. #include <mt_spm_notifier.h>
  16. #include <mt_spm_resource_req.h>
  17. #include <mt_spm_reg.h>
  18. #include <mt_spm_rc_internal.h>
  19. #include <mt_spm_suspend.h>
  20. #include <plat_pm.h>
  21. #include <plat_mtk_lpm.h>
  22. #define CONSTRAINT_DRAM_ALLOW \
  23. (MT_RM_CONSTRAINT_ALLOW_DRAM_S0 | \
  24. MT_RM_CONSTRAINT_ALLOW_DRAM_S1 | \
  25. MT_RM_CONSTRAINT_ALLOW_CPU_BUCK_OFF)
  26. #define CONSTRAINT_DRAM_PCM_FLAG \
  27. (SPM_FLAG_DISABLE_INFRA_PDN | \
  28. SPM_FLAG_DISABLE_VCORE_DVS | \
  29. SPM_FLAG_DISABLE_VCORE_DFS | \
  30. SPM_FLAG_SRAM_SLEEP_CTRL | \
  31. SPM_FLAG_KEEP_CSYSPWRACK_HIGH | \
  32. SPM_FLAG_DISABLE_DRAMC_MCU_SRAM_SLEEP)
  33. #define CONSTRAINT_DRAM_PCM_FLAG1 0U
  34. #define CONSTRAINT_DRAM_RESOURCE_REQ \
  35. (MT_SPM_SYSPLL | \
  36. MT_SPM_INFRA | \
  37. MT_SPM_26M)
  38. static struct mt_spm_cond_tables cond_dram = {
  39. .name = "dram",
  40. .table_cg = {
  41. 0xFFFDD008, /* MTCMOS1 */
  42. 0x20040802, /* INFRA0 */
  43. 0x27AF8000, /* INFRA1 */
  44. 0x86040640, /* INFRA2 */
  45. 0x00000000, /* INFRA3 */
  46. 0x80000000, /* INFRA4 */
  47. 0x00000000, /* PERI0 */
  48. 0x00004000, /* VPPSYS0_0 */
  49. 0x08803000, /* VPPSYS0_1 */
  50. 0x00000000, /* VPPSYS0_2 */
  51. 0x80005555, /* VPPSYS1_0 */
  52. 0x00009008, /* VPPSYS1_1 */
  53. 0x60060000, /* VDOSYS0_0 */
  54. 0x00000000, /* VDOSYS0_1 */
  55. 0x201E01F8, /* VDOSYS1_0 */
  56. 0x00800000, /* VDOSYS1_1 */
  57. 0x00000000, /* VDOSYS1_2 */
  58. 0x00000080, /* I2C */
  59. },
  60. .table_pll = 0U,
  61. };
  62. static struct mt_spm_cond_tables cond_dram_res = {
  63. .table_cg = { 0U },
  64. .table_pll = 0U,
  65. };
  66. static struct constraint_status status = {
  67. .id = MT_RM_CONSTRAINT_ID_DRAM,
  68. .valid = (MT_SPM_RC_VALID_SW |
  69. MT_SPM_RC_VALID_COND_LATCH |
  70. MT_SPM_RC_VALID_XSOC_BBLPM),
  71. .cond_block = 0U,
  72. .enter_cnt = 0U,
  73. .cond_res = &cond_dram_res,
  74. };
  75. static void spm_dram_conduct(struct spm_lp_scen *spm_lp,
  76. unsigned int *resource_req)
  77. {
  78. spm_lp->pwrctrl->pcm_flags = (uint32_t)CONSTRAINT_DRAM_PCM_FLAG;
  79. spm_lp->pwrctrl->pcm_flags1 = (uint32_t)CONSTRAINT_DRAM_PCM_FLAG1;
  80. *resource_req |= CONSTRAINT_DRAM_RESOURCE_REQ;
  81. }
  82. bool spm_is_valid_rc_dram(unsigned int cpu, int state_id)
  83. {
  84. (void)cpu;
  85. (void)state_id;
  86. return (status.cond_block == 0U) && IS_MT_RM_RC_READY(status.valid);
  87. }
  88. int spm_update_rc_dram(int state_id, int type, const void *val)
  89. {
  90. const struct mt_spm_cond_tables *tlb;
  91. const struct mt_spm_cond_tables *tlb_check;
  92. int res = MT_RM_STATUS_OK;
  93. if (val == NULL) {
  94. return MT_RM_STATUS_BAD;
  95. }
  96. if (type == PLAT_RC_UPDATE_CONDITION) {
  97. tlb = (const struct mt_spm_cond_tables *)val;
  98. tlb_check = (const struct mt_spm_cond_tables *)&cond_dram;
  99. status.cond_block =
  100. mt_spm_cond_check(state_id, tlb, tlb_check,
  101. ((status.valid &
  102. MT_SPM_RC_VALID_COND_LATCH) != 0U) ?
  103. &cond_dram_res : NULL);
  104. } else {
  105. res = MT_RM_STATUS_BAD;
  106. }
  107. return res;
  108. }
  109. unsigned int spm_allow_rc_dram(int state_id)
  110. {
  111. (void)state_id;
  112. return CONSTRAINT_DRAM_ALLOW;
  113. }
  114. int spm_run_rc_dram(unsigned int cpu, int state_id)
  115. {
  116. unsigned int ext_op = MT_SPM_EX_OP_HW_S1_DETECT;
  117. unsigned int allows = CONSTRAINT_DRAM_ALLOW;
  118. (void)cpu;
  119. if (IS_MT_SPM_RC_BBLPM_MODE(status.valid)) {
  120. #ifdef MT_SPM_USING_SRCLKEN_RC
  121. ext_op |= MT_SPM_EX_OP_SRCLKEN_RC_BBLPM;
  122. #else
  123. allows |= MT_RM_CONSTRAINT_ALLOW_BBLPM;
  124. #endif
  125. }
  126. #ifndef ATF_PLAT_SPM_SSPM_NOTIFIER_UNSUPPORT
  127. mt_spm_sspm_notify_u32(MT_SPM_NOTIFY_LP_ENTER, allows |
  128. (IS_PLAT_SUSPEND_ID(state_id) ?
  129. MT_RM_CONSTRAINT_ALLOW_AP_SUSPEND : 0U));
  130. #else
  131. (void)allows;
  132. #endif
  133. if (IS_PLAT_SUSPEND_ID(state_id)) {
  134. mt_spm_suspend_enter(state_id,
  135. (MT_SPM_EX_OP_SET_WDT |
  136. MT_SPM_EX_OP_SET_SUSPEND_MODE |
  137. MT_SPM_EX_OP_HW_S1_DETECT),
  138. CONSTRAINT_DRAM_RESOURCE_REQ);
  139. } else {
  140. mt_spm_idle_generic_enter(state_id, ext_op, spm_dram_conduct);
  141. }
  142. return 0;
  143. }
  144. int spm_reset_rc_dram(unsigned int cpu, int state_id)
  145. {
  146. unsigned int ext_op = MT_SPM_EX_OP_HW_S1_DETECT;
  147. unsigned int allows = CONSTRAINT_DRAM_ALLOW;
  148. (void)cpu;
  149. if (IS_MT_SPM_RC_BBLPM_MODE(status.valid)) {
  150. #ifdef MT_SPM_USING_SRCLKEN_RC
  151. ext_op |= MT_SPM_EX_OP_SRCLKEN_RC_BBLPM;
  152. #else
  153. allows |= MT_RM_CONSTRAINT_ALLOW_BBLPM;
  154. #endif
  155. }
  156. #ifndef ATF_PLAT_SPM_SSPM_NOTIFIER_UNSUPPORT
  157. mt_spm_sspm_notify_u32(MT_SPM_NOTIFY_LP_LEAVE, allows);
  158. #else
  159. (void)allows;
  160. #endif
  161. if (IS_PLAT_SUSPEND_ID(state_id)) {
  162. mt_spm_suspend_resume(state_id,
  163. (MT_SPM_EX_OP_SET_WDT |
  164. MT_SPM_EX_OP_HW_S1_DETECT),
  165. NULL);
  166. } else {
  167. mt_spm_idle_generic_resume(state_id, ext_op, NULL);
  168. status.enter_cnt++;
  169. }
  170. return 0;
  171. }