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