mt_spm.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stddef.h>
  7. #include <string.h>
  8. #include <common/debug.h>
  9. #include <lib/bakery_lock.h>
  10. #include <lib/mmio.h>
  11. #include <mt_lp_rm.h>
  12. #include <mt_spm.h>
  13. #include <mt_spm_cond.h>
  14. #include <mt_spm_conservation.h>
  15. #include <mt_spm_constraint.h>
  16. #include "mt_spm_extern.h"
  17. #include <mt_spm_idle.h>
  18. #include <mt_spm_internal.h>
  19. #include <mt_spm_pmic_wrap.h>
  20. #include <mt_spm_rc_internal.h>
  21. #include <mt_spm_reg.h>
  22. #include <mt_spm_resource_req.h>
  23. #include <mt_spm_suspend.h>
  24. #include <mtk_plat_common.h>
  25. #include <plat_mtk_lpm.h>
  26. #include <plat_pm.h>
  27. #include <platform_def.h>
  28. #include <sleep_def.h>
  29. #ifdef MT_SPM_USING_BAKERY_LOCK
  30. DEFINE_BAKERY_LOCK(spm_lock);
  31. #define plat_spm_lock_init() bakery_lock_init(&spm_lock)
  32. #else
  33. spinlock_t spm_lock;
  34. #define plat_spm_lock_init()
  35. #endif
  36. /* CLK_SCP_CFG_0 */
  37. #define CLK_SCP_CFG_0 (TOPCKGEN_BASE + 0x200)
  38. #define SPM_CK_CONTROL_EN (0x3FF)
  39. /* CLK_SCP_CFG_1 */
  40. #define CLK_SCP_CFG_1 (TOPCKGEN_BASE + 0x210)
  41. #define CLK_SCP_CFG_1_MASK (0x100C)
  42. #define CLK_SCP_CFG_1_SPM (0x3)
  43. #define MT_SPM_EX_OP_TIME_CHECK BIT(10)
  44. struct mt_resource_constraint plat_constraint_bus26m = {
  45. .is_valid = spm_is_valid_rc_bus26m,
  46. .update = spm_update_rc_bus26m,
  47. .allow = spm_allow_rc_bus26m,
  48. .run = spm_run_rc_bus26m,
  49. .reset = spm_reset_rc_bus26m,
  50. };
  51. struct mt_resource_constraint plat_constraint_syspll = {
  52. .is_valid = spm_is_valid_rc_syspll,
  53. .update = spm_update_rc_syspll,
  54. .allow = spm_allow_rc_syspll,
  55. .run = spm_run_rc_syspll,
  56. .reset = spm_reset_rc_syspll,
  57. };
  58. struct mt_resource_constraint plat_constraint_dram = {
  59. .is_valid = spm_is_valid_rc_dram,
  60. .update = spm_update_rc_dram,
  61. .allow = spm_allow_rc_dram,
  62. .run = spm_run_rc_dram,
  63. .reset = spm_reset_rc_dram,
  64. };
  65. /* Maybe remove when the spm won't cpu power control aymore */
  66. struct mt_resource_constraint plat_constraint_cpu = {
  67. .is_valid = spm_is_valid_rc_cpu_buck_ldo,
  68. .update = NULL,
  69. .allow = spm_allow_rc_cpu_buck_ldo,
  70. .run = spm_run_rc_cpu_buck_ldo,
  71. .reset = spm_reset_rc_cpu_buck_ldo,
  72. };
  73. struct mt_resource_constraint *plat_constraints[] = {
  74. &plat_constraint_bus26m,
  75. &plat_constraint_syspll,
  76. &plat_constraint_dram,
  77. &plat_constraint_cpu,
  78. NULL,
  79. };
  80. struct mt_resource_manager plat_mt8186_rm = {
  81. .update = mt_spm_cond_update,
  82. .consts = plat_constraints,
  83. };
  84. void spm_boot_init(void)
  85. {
  86. NOTICE("MT8186 %s\n", __func__);
  87. /* switch ck_off/axi_26m control to SPM */
  88. mmio_setbits_32(CLK_SCP_CFG_0, SPM_CK_CONTROL_EN);
  89. mmio_clrsetbits_32(CLK_SCP_CFG_1, CLK_SCP_CFG_1_MASK, CLK_SCP_CFG_1_SPM);
  90. plat_spm_lock_init();
  91. mt_spm_pmic_wrap_set_phase(PMIC_WRAP_PHASE_ALLINONE);
  92. mt_lp_rm_register(&plat_mt8186_rm);
  93. mt_spm_idle_generic_init();
  94. mt_spm_suspend_init();
  95. spm_extern_initialize();
  96. }