mt_spm_rc_dram.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2022, 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_conservation.h>
  12. #include <mt_spm_constraint.h>
  13. #include <mt_spm_idle.h>
  14. #include <mt_spm_internal.h>
  15. #include <mt_spm_notifier.h>
  16. #include <mt_spm_rc_internal.h>
  17. #include <mt_spm_reg.h>
  18. #include <mt_spm_resource_req.h>
  19. #include <mt_spm_suspend.h>
  20. #include <plat_mtk_lpm.h>
  21. #include <plat_pm.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. #define CONSTRAINT_DRAM_PCM_FLAG1 (0U)
  33. #define CONSTRAINT_DRAM_RESOURCE_REQ \
  34. (MT_SPM_SYSPLL | \
  35. MT_SPM_INFRA | \
  36. MT_SPM_26M)
  37. static struct mt_spm_cond_tables cond_dram = {
  38. .name = "dram",
  39. .table_cg = {
  40. 0x0385E03C, /* MTCMOS1 */
  41. 0x003F0100, /* INFRA0 */
  42. 0x08040802, /* INFRA1 */
  43. 0x06015641, /* INFRA2 */
  44. 0x00000000, /* INFRA3 */
  45. 0x00000000, /* INFRA4 */
  46. 0x00000000, /* INFRA5 */
  47. 0x02300020, /* MMSYS0 */
  48. 0x00000000, /* MMSYS1 */
  49. 0x00000000, /* MMSYS2 */
  50. 0x00015111, /* MMSYS3 */
  51. },
  52. .table_pll = 0U,
  53. };
  54. static struct mt_spm_cond_tables cond_dram_res = {
  55. .table_cg = {0U},
  56. .table_pll = 0U,
  57. };
  58. static struct constraint_status status = {
  59. .id = MT_RM_CONSTRAINT_ID_DRAM,
  60. .valid = (MT_SPM_RC_VALID_SW |
  61. MT_SPM_RC_VALID_COND_LATCH |
  62. MT_SPM_RC_VALID_XSOC_BBLPM),
  63. .cond_block = 0U,
  64. .enter_cnt = 0U,
  65. .cond_res = &cond_dram_res,
  66. };
  67. static void spm_dram_conduct(struct spm_lp_scen *spm_lp,
  68. unsigned int *resource_req)
  69. {
  70. spm_lp->pwrctrl->pcm_flags = (uint32_t)CONSTRAINT_DRAM_PCM_FLAG;
  71. spm_lp->pwrctrl->pcm_flags1 = (uint32_t)CONSTRAINT_DRAM_PCM_FLAG1;
  72. *resource_req |= CONSTRAINT_DRAM_RESOURCE_REQ;
  73. }
  74. bool spm_is_valid_rc_dram(unsigned int cpu, int state_id)
  75. {
  76. (void)cpu;
  77. (void)state_id;
  78. return ((status.cond_block == 0U) && IS_MT_RM_RC_READY(status.valid));
  79. }
  80. int spm_update_rc_dram(int state_id, int type, const void *val)
  81. {
  82. const struct mt_spm_cond_tables *tlb;
  83. const struct mt_spm_cond_tables *tlb_check;
  84. int res = MT_RM_STATUS_OK;
  85. if (val == NULL) {
  86. res = MT_RM_STATUS_BAD;
  87. } else {
  88. if (type == PLAT_RC_UPDATE_CONDITION) {
  89. tlb = (const struct mt_spm_cond_tables *)val;
  90. tlb_check = (const struct mt_spm_cond_tables *)&cond_dram;
  91. status.cond_block =
  92. mt_spm_cond_check(state_id, tlb, tlb_check,
  93. ((status.valid &
  94. MT_SPM_RC_VALID_COND_LATCH) != 0U) ?
  95. (&cond_dram_res) : (NULL));
  96. } else {
  97. res = MT_RM_STATUS_BAD;
  98. }
  99. }
  100. return res;
  101. }
  102. unsigned int spm_allow_rc_dram(int state_id)
  103. {
  104. (void)state_id;
  105. return CONSTRAINT_DRAM_ALLOW;
  106. }
  107. int spm_run_rc_dram(unsigned int cpu, int state_id)
  108. {
  109. unsigned int ext_op = MT_SPM_EX_OP_HW_S1_DETECT;
  110. unsigned int allows = CONSTRAINT_DRAM_ALLOW;
  111. (void)cpu;
  112. if (IS_MT_SPM_RC_BBLPM_MODE(status.valid)) {
  113. #ifdef MT_SPM_USING_SRCLKEN_RC
  114. ext_op |= MT_SPM_EX_OP_SRCLKEN_RC_BBLPM;
  115. #else
  116. allows |= MT_RM_CONSTRAINT_ALLOW_BBLPM;
  117. #endif
  118. }
  119. #ifndef ATF_PLAT_SPM_SSPM_NOTIFIER_UNSUPPORT
  120. mt_spm_sspm_notify_u32(MT_SPM_NOTIFY_LP_ENTER, allows | (IS_PLAT_SUSPEND_ID(state_id) ?
  121. (MT_RM_CONSTRAINT_ALLOW_AP_SUSPEND) : (0U)));
  122. #else
  123. (void)allows;
  124. #endif
  125. if (IS_PLAT_SUSPEND_ID(state_id)) {
  126. mt_spm_suspend_enter(state_id,
  127. (MT_SPM_EX_OP_SET_WDT | MT_SPM_EX_OP_HW_S1_DETECT),
  128. CONSTRAINT_DRAM_RESOURCE_REQ);
  129. } else {
  130. mt_spm_idle_generic_enter(state_id, ext_op, spm_dram_conduct);
  131. }
  132. return 0;
  133. }
  134. int spm_reset_rc_dram(unsigned int cpu, int state_id)
  135. {
  136. unsigned int ext_op = MT_SPM_EX_OP_HW_S1_DETECT;
  137. unsigned int allows = CONSTRAINT_DRAM_ALLOW;
  138. (void)cpu;
  139. if (IS_MT_SPM_RC_BBLPM_MODE(status.valid)) {
  140. #ifdef MT_SPM_USING_SRCLKEN_RC
  141. ext_op |= MT_SPM_EX_OP_SRCLKEN_RC_BBLPM;
  142. #else
  143. allows |= MT_RM_CONSTRAINT_ALLOW_BBLPM;
  144. #endif
  145. }
  146. #ifndef ATF_PLAT_SPM_SSPM_NOTIFIER_UNSUPPORT
  147. mt_spm_sspm_notify_u32(MT_SPM_NOTIFY_LP_LEAVE, allows);
  148. #else
  149. (void)allows;
  150. #endif
  151. if (IS_PLAT_SUSPEND_ID(state_id)) {
  152. mt_spm_suspend_resume(state_id,
  153. (MT_SPM_EX_OP_SET_WDT | MT_SPM_EX_OP_HW_S1_DETECT),
  154. NULL);
  155. } else {
  156. mt_spm_idle_generic_resume(state_id, ext_op, NULL, NULL);
  157. status.enter_cnt++;
  158. }
  159. return 0;
  160. }