1 /* 2 * Copyright (c) 2020, MediaTek Inc. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch_helpers.h> 8 #include <common/debug.h> 9 10 #include <mt_spm.h> 11 #include <mt_spm_cond.h> 12 #include <mt_spm_constraint.h> 13 #include <mt_spm_conservation.h> 14 #include <mt_spm_idle.h> 15 #include <mt_spm_internal.h> 16 #include <mt_spm_notifier.h> 17 #include <mt_spm_rc_internal.h> 18 #include <mt_spm_resource_req.h> 19 #include <mt_spm_reg.h> 20 #include <mt_spm_suspend.h> 21 #include <plat_pm.h> 22 23 #define CONSTRAINT_CPU_BUCK_PCM_FLAG \ 24 (SPM_FLAG_DISABLE_INFRA_PDN | \ 25 SPM_FLAG_DISABLE_VCORE_DVS | \ 26 SPM_FLAG_DISABLE_VCORE_DFS | \ 27 SPM_FLAG_SRAM_SLEEP_CTRL | \ 28 SPM_FLAG_KEEP_CSYSPWRACK_HIGH) 29 30 #define CONSTRAINT_CPU_BUCK_PCM_FLAG1 0U 31 32 #define CONSTRAINT_CPU_BUCK_RESOURCE_REQ \ 33 (MT_SPM_DRAM_S1 | \ 34 MT_SPM_DRAM_S0 | \ 35 MT_SPM_SYSPLL | \ 36 MT_SPM_INFRA | \ 37 MT_SPM_26M | \ 38 MT_SPM_XO_FPM) 39 40 41 static unsigned int cpubuckldo_status = MT_SPM_RC_VALID_SW; 42 static unsigned int cpubuckldo_enter_cnt; 43 44 static void spm_cpu_bcuk_ldo_conduct(struct spm_lp_scen *spm_lp, 45 unsigned int *resource_req) 46 { 47 spm_lp->pwrctrl->pcm_flags = (uint32_t)CONSTRAINT_CPU_BUCK_PCM_FLAG; 48 spm_lp->pwrctrl->pcm_flags1 = (uint32_t)CONSTRAINT_CPU_BUCK_PCM_FLAG1; 49 *resource_req |= CONSTRAINT_CPU_BUCK_RESOURCE_REQ; 50 } 51 52 bool spm_is_valid_rc_cpu_buck_ldo(unsigned int cpu, int state_id) 53 { 54 (void)cpu; 55 (void)state_id; 56 57 return IS_MT_RM_RC_READY(cpubuckldo_status); 58 } 59 60 unsigned int spm_allow_rc_cpu_buck_ldo(int state_id) 61 { 62 (void)state_id; 63 64 return MT_RM_CONSTRAINT_ALLOW_CPU_BUCK_OFF; 65 } 66 67 int spm_run_rc_cpu_buck_ldo(unsigned int cpu, int state_id) 68 { 69 (void)cpu; 70 71 #ifndef ATF_PLAT_SPM_SSPM_NOTIFIER_UNSUPPORT 72 mt_spm_sspm_notify_u32(MT_SPM_NOTIFY_LP_ENTER, 73 (IS_PLAT_SUSPEND_ID(state_id) ? 74 MT_RM_CONSTRAINT_ALLOW_AP_SUSPEND : 0U)); 75 #endif 76 if (IS_PLAT_SUSPEND_ID(state_id)) { 77 mt_spm_suspend_enter(state_id, 78 MT_SPM_EX_OP_SET_WDT, 79 CONSTRAINT_CPU_BUCK_RESOURCE_REQ); 80 } else { 81 mt_spm_idle_generic_enter(state_id, 0U, 82 spm_cpu_bcuk_ldo_conduct); 83 } 84 85 cpubuckldo_enter_cnt++; 86 87 return 0; 88 } 89 90 int spm_reset_rc_cpu_buck_ldo(unsigned int cpu, int state_id) 91 { 92 (void)cpu; 93 94 #ifndef ATF_PLAT_SPM_SSPM_NOTIFIER_UNSUPPORT 95 mt_spm_sspm_notify_u32(MT_SPM_NOTIFY_LP_LEAVE, 0U); 96 #endif 97 if (IS_PLAT_SUSPEND_ID(state_id)) { 98 mt_spm_suspend_resume(state_id, MT_SPM_EX_OP_SET_WDT, NULL); 99 } else { 100 mt_spm_idle_generic_resume(state_id, 0U, NULL); 101 } 102 103 return 0; 104 } 105