mt_spm.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (c) 2023, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <stddef.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <arch.h>
  11. #include <common/debug.h>
  12. #include <drivers/console.h>
  13. #include <lib/mmio.h>
  14. #include <lib/utils_def.h>
  15. #include "constraints/mt_spm_rc_internal.h"
  16. #include <drivers/spm/mt_spm_resource_req.h>
  17. #include <lib/mtk_init/mtk_init.h>
  18. #include <lib/pm/mtk_pm.h>
  19. #include <lpm/mt_lp_rm.h>
  20. #include <lpm/mt_lp_rqm.h>
  21. #include <lpm/mt_lpm_smc.h>
  22. #include "mt_spm.h"
  23. #include "mt_spm_cond.h"
  24. #include "mt_spm_conservation.h"
  25. #include "mt_spm_constraint.h"
  26. #include "mt_spm_idle.h"
  27. #include "mt_spm_internal.h"
  28. #include "mt_spm_pmic_wrap.h"
  29. #include "mt_spm_reg.h"
  30. #include "mt_spm_suspend.h"
  31. #include <mtk_mmap_pool.h>
  32. #include <platform_def.h>
  33. #include "sleep_def.h"
  34. /*
  35. * System Power Manager (SPM) is a hardware module which provides CPU idle
  36. * and system suspend features.
  37. */
  38. spinlock_t spm_lock;
  39. #ifdef MTK_PLAT_SPM_UNSUPPORT
  40. struct mt_resource_manager plat_mt8188_rm = {
  41. };
  42. #else
  43. struct mt_lp_res_req rq_xo_fpm = {
  44. .res_id = MT_LP_RQ_XO_FPM,
  45. .res_rq = MT_SPM_XO_FPM,
  46. .res_usage = 0,
  47. };
  48. struct mt_lp_res_req rq_26m = {
  49. .res_id = MT_LP_RQ_26M,
  50. .res_rq = MT_SPM_26M,
  51. .res_usage = 0,
  52. };
  53. struct mt_lp_res_req rq_infra = {
  54. .res_id = MT_LP_RQ_INFRA,
  55. .res_rq = MT_SPM_INFRA,
  56. .res_usage = 0,
  57. };
  58. struct mt_lp_res_req rq_syspll = {
  59. .res_id = MT_LP_RQ_SYSPLL,
  60. .res_rq = MT_SPM_SYSPLL,
  61. .res_usage = 0,
  62. };
  63. struct mt_lp_res_req rq_dram_s0 = {
  64. .res_id = MT_LP_RQ_DRAM,
  65. .res_rq = MT_SPM_DRAM_S0,
  66. .res_usage = 0,
  67. };
  68. struct mt_lp_res_req rq_dram_s1 = {
  69. .res_id = MT_LP_RQ_DRAM,
  70. .res_rq = MT_SPM_DRAM_S1,
  71. .res_usage = 0,
  72. };
  73. struct mt_lp_res_req *spm_resources[] = {
  74. &rq_xo_fpm,
  75. &rq_26m,
  76. &rq_infra,
  77. &rq_syspll,
  78. &rq_dram_s0,
  79. &rq_dram_s1,
  80. NULL,
  81. };
  82. struct mt_resource_req_manager plat_mt8188_rq = {
  83. .res = spm_resources,
  84. };
  85. struct mt_resource_constraint plat_constraint_bus26m = {
  86. .is_valid = spm_is_valid_rc_bus26m,
  87. .update = spm_update_rc_bus26m,
  88. .allow = spm_allow_rc_bus26m,
  89. .run = spm_run_rc_bus26m,
  90. .reset = spm_reset_rc_bus26m,
  91. .get_status = spm_get_status_rc_bus26m,
  92. };
  93. struct mt_resource_constraint plat_constraint_syspll = {
  94. .is_valid = spm_is_valid_rc_syspll,
  95. .update = spm_update_rc_syspll,
  96. .allow = spm_allow_rc_syspll,
  97. .run = spm_run_rc_syspll,
  98. .reset = spm_reset_rc_syspll,
  99. .get_status = spm_get_status_rc_syspll,
  100. };
  101. struct mt_resource_constraint plat_constraint_dram = {
  102. .is_valid = spm_is_valid_rc_dram,
  103. .update = spm_update_rc_dram,
  104. .allow = spm_allow_rc_dram,
  105. .run = spm_run_rc_dram,
  106. .reset = spm_reset_rc_dram,
  107. .get_status = spm_get_status_rc_dram,
  108. };
  109. struct mt_resource_constraint plat_constraint_cpu = {
  110. .is_valid = spm_is_valid_rc_cpu_buck_ldo,
  111. .update = spm_update_rc_cpu_buck_ldo,
  112. .allow = spm_allow_rc_cpu_buck_ldo,
  113. .run = spm_run_rc_cpu_buck_ldo,
  114. .reset = spm_reset_rc_cpu_buck_ldo,
  115. .get_status = spm_get_status_rc_cpu_buck_ldo,
  116. };
  117. struct mt_resource_constraint *plat_constraints[] = {
  118. &plat_constraint_bus26m,
  119. &plat_constraint_syspll,
  120. &plat_constraint_dram,
  121. &plat_constraint_cpu,
  122. NULL,
  123. };
  124. struct mt_resource_manager plat_mt8188_rm = {
  125. .update = mt_spm_cond_update,
  126. .consts = plat_constraints,
  127. };
  128. #endif
  129. /* Determine for SPM software resource user */
  130. static struct mt_lp_resource_user spm_res_user;
  131. struct mt_lp_resource_user *get_spm_res_user(void)
  132. {
  133. return &spm_res_user;
  134. }
  135. int spm_boot_init(void)
  136. {
  137. mt_spm_pmic_wrap_set_phase(PMIC_WRAP_PHASE_ALLINONE);
  138. mt_lp_rm_register(&plat_mt8188_rm);
  139. /* SPM service won't run when SPM not ready */
  140. #ifndef MTK_PLAT_SPM_UNSUPPORT
  141. mt_lp_resource_request_manager_register(&plat_mt8188_rq);
  142. mt_lp_resource_user_register("SPM", &spm_res_user);
  143. #endif
  144. return 0;
  145. }
  146. MTK_ARCH_INIT(spm_boot_init);