jason-ch chen | fa82b9b | 2021-11-16 09:48:20 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2022, 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 | #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 | |
| 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 | static unsigned int cpubuckldo_status = MT_SPM_RC_VALID_SW; |
| 41 | static unsigned int cpubuckldo_enter_cnt; |
| 42 | |
| 43 | static void spm_cpu_bcuk_ldo_conduct(struct spm_lp_scen *spm_lp, |
| 44 | unsigned int *resource_req) |
| 45 | { |
| 46 | spm_lp->pwrctrl->pcm_flags = (uint32_t)CONSTRAINT_CPU_BUCK_PCM_FLAG; |
| 47 | spm_lp->pwrctrl->pcm_flags1 = (uint32_t)CONSTRAINT_CPU_BUCK_PCM_FLAG1; |
| 48 | *resource_req |= CONSTRAINT_CPU_BUCK_RESOURCE_REQ; |
| 49 | } |
| 50 | |
| 51 | bool spm_is_valid_rc_cpu_buck_ldo(unsigned int cpu, int state_id) |
| 52 | { |
| 53 | (void)cpu; |
| 54 | (void)state_id; |
| 55 | |
| 56 | return IS_MT_RM_RC_READY(cpubuckldo_status); |
| 57 | } |
| 58 | |
| 59 | unsigned int spm_allow_rc_cpu_buck_ldo(int state_id) |
| 60 | { |
| 61 | (void)state_id; |
| 62 | |
| 63 | return MT_RM_CONSTRAINT_ALLOW_CPU_BUCK_OFF; |
| 64 | } |
| 65 | |
| 66 | int spm_run_rc_cpu_buck_ldo(unsigned int cpu, int state_id) |
| 67 | { |
| 68 | (void)cpu; |
| 69 | unsigned int ext_op = 0U; |
| 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, ext_op, |
| 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 | unsigned int ext_op = 0U; |
| 94 | |
| 95 | #ifndef ATF_PLAT_SPM_SSPM_NOTIFIER_UNSUPPORT |
| 96 | mt_spm_sspm_notify_u32(MT_SPM_NOTIFY_LP_LEAVE, 0U); |
| 97 | #endif |
| 98 | if (IS_PLAT_SUSPEND_ID(state_id)) { |
| 99 | mt_spm_suspend_resume(state_id, MT_SPM_EX_OP_SET_WDT, NULL); |
| 100 | } else { |
| 101 | mt_spm_idle_generic_resume(state_id, ext_op, NULL, NULL); |
| 102 | } |
| 103 | |
| 104 | return 0; |
| 105 | } |