mt_spm.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2020, 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_idle.h>
  17. #include <mt_spm_internal.h>
  18. #include <mt_spm_pmic_wrap.h>
  19. #include <mt_spm_rc_internal.h>
  20. #include <mt_spm_reg.h>
  21. #include <mt_spm_resource_req.h>
  22. #include <mt_spm_suspend.h>
  23. #include <mtk_plat_common.h>
  24. #include <plat_mtk_lpm.h>
  25. #include <plat_pm.h>
  26. #include <platform_def.h>
  27. #include <sleep_def.h>
  28. #ifdef MT_SPM_USING_BAKERY_LOCK
  29. DEFINE_BAKERY_LOCK(spm_lock);
  30. #define plat_spm_lock_init() bakery_lock_init(&spm_lock)
  31. #else
  32. spinlock_t spm_lock;
  33. #define plat_spm_lock_init()
  34. #endif
  35. /* CLK_SCP_CFG_0 */
  36. #define CLK_SCP_CFG_0 (TOPCKGEN_BASE + 0x200)
  37. #define SPM_CK_CONTROL_EN 0x3FF
  38. /* CLK_SCP_CFG_1 */
  39. #define CLK_SCP_CFG_1 (TOPCKGEN_BASE + 0x210)
  40. #define CLK_SCP_CFG_1_MASK 0x100C
  41. #define CLK_SCP_CFG_1_SPM 0x3
  42. struct mt_resource_constraint plat_constraint_bus26m = {
  43. .is_valid = spm_is_valid_rc_bus26m,
  44. .update = spm_update_rc_bus26m,
  45. .allow = spm_allow_rc_bus26m,
  46. .run = spm_run_rc_bus26m,
  47. .reset = spm_reset_rc_bus26m,
  48. };
  49. struct mt_resource_constraint plat_constraint_syspll = {
  50. .is_valid = spm_is_valid_rc_syspll,
  51. .update = spm_update_rc_syspll,
  52. .allow = spm_allow_rc_syspll,
  53. .run = spm_run_rc_syspll,
  54. .reset = spm_reset_rc_syspll,
  55. };
  56. struct mt_resource_constraint plat_constraint_dram = {
  57. .is_valid = spm_is_valid_rc_dram,
  58. .update = spm_update_rc_dram,
  59. .allow = spm_allow_rc_dram,
  60. .run = spm_run_rc_dram,
  61. .reset = spm_reset_rc_dram,
  62. };
  63. struct mt_resource_constraint plat_constraint_cpu = {
  64. .is_valid = spm_is_valid_rc_cpu_buck_ldo,
  65. .update = NULL,
  66. .allow = spm_allow_rc_cpu_buck_ldo,
  67. .run = spm_run_rc_cpu_buck_ldo,
  68. .reset = spm_reset_rc_cpu_buck_ldo,
  69. };
  70. struct mt_resource_constraint *plat_constraints[] = {
  71. &plat_constraint_bus26m,
  72. &plat_constraint_syspll,
  73. &plat_constraint_dram,
  74. &plat_constraint_cpu,
  75. NULL,
  76. };
  77. struct mt_resource_manager plat_mt8192_rm = {
  78. .update = mt_spm_cond_update,
  79. .consts = plat_constraints,
  80. };
  81. void spm_boot_init(void)
  82. {
  83. /* switch ck_off/axi_26m control to SPM */
  84. mmio_setbits_32(CLK_SCP_CFG_0, SPM_CK_CONTROL_EN);
  85. mmio_clrsetbits_32(CLK_SCP_CFG_1, CLK_SCP_CFG_1_MASK,
  86. CLK_SCP_CFG_1_SPM);
  87. plat_spm_lock_init();
  88. mt_spm_pmic_wrap_set_phase(PMIC_WRAP_PHASE_ALLINONE);
  89. mt_lp_rm_register(&plat_mt8192_rm);
  90. mt_spm_idle_generic_init();
  91. mt_spm_suspend_init();
  92. }