1 /* 2 * Copyright (c) 2025, Mediatek Inc. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef MT_SPM_H 8 #define MT_SPM_H 9 10 #include <stdint.h> 11 #include <stdio.h> 12 13 #include <lib/pm/mtk_pm.h> 14 #include <lpm_v2/mt_lp_rq.h> 15 16 #ifdef __GNUC__ 17 #define spm_likely(x) __builtin_expect(!!(x), 1) 18 #define spm_unlikely(x) __builtin_expect(!!(x), 0) 19 #else 20 #define spm_likely(x) (x) 21 #define spm_unlikely(x) (x) 22 #endif 23 24 #define CLK_SCP_CFG_0 (CKSYS_BASE + 0x1A0) 25 #define INFRA_BUS_DCM_CTRL (INFRACFG_AO_BASE + 0x070) 26 #define RG_AXI_DCM_DIS_EN BIT(21) 27 #define RG_PLLCK_SEL_NO_SPM BIT(22) 28 29 #define MT_SPM_TIME_GET(tm) ({ (tm) = el3_uptime(); }) 30 31 #define SPM_FW_NO_RESUME 1 32 #define MCUSYS_MTCMOS_ON 0 33 #define WAKEUP_LOG_ON 0 34 35 #define MT_SPM_USING_SRCLKEN_RC 36 /* SPM extern operand definition */ 37 #define MT_SPM_EX_OP_CLR_26M_RECORD BIT(0) 38 #define MT_SPM_EX_OP_SET_WDT BIT(1) 39 #define MT_SPM_EX_OP_NON_GENERIC_RESOURCE_REQ BIT(2) 40 #define MT_SPM_EX_OP_SET_SUSPEND_MODE BIT(3) 41 #define MT_SPM_EX_OP_SET_IS_ADSP BIT(4) 42 #define MT_SPM_EX_OP_SRCLKEN_RC_BBLPM BIT(5) 43 #define MT_SPM_EX_OP_HW_S1_DETECT BIT(6) 44 #define MT_SPM_EX_OP_TRACE_LP BIT(7) 45 #define MT_SPM_EX_OP_TRACE_SUSPEND BIT(8) 46 #define MT_SPM_EX_OP_TRACE_TIMESTAMP_EN BIT(9) 47 #define MT_SPM_EX_OP_TIME_CHECK BIT(10) 48 #define MT_SPM_EX_OP_TIME_OBS BIT(11) 49 #define MT_SPM_EX_OP_SET_IS_USB_HEADSET BIT(12) 50 #define MT_SPM_EX_OP_SET_IS_FM_AUDIO BIT(13) 51 #define MT_SPM_EX_OP_DEVICES_SAVE BIT(14) 52 #define MT_SPM_EX_OP_NOTIFY_INFRA_OFF BIT(15) 53 54 #define MT_BUS26M_EXT_LP_26M_ON_MODE (MT_SPM_EX_OP_SET_IS_ADSP | \ 55 MT_SPM_EX_OP_SET_IS_FM_AUDIO) 56 57 #define MT_VCORE_EXT_LP_VCORE_ON_MODE (MT_SPM_EX_OP_SET_IS_ADSP | \ 58 MT_SPM_EX_OP_SET_IS_FM_AUDIO) 59 60 /* EN SPM INFRA DEBUG OUT */ 61 #define DEBUGSYS_DEBUG_EN_REG (DBGSYS_DEM_BASE + 0x94) 62 63 /* INFRA_AO_DEBUG_CON */ 64 #define INFRA_AO_DBG_CON0 (INFRACFG_AO_BASE + 0x500) 65 #define INFRA_AO_DBG_CON1 (INFRACFG_AO_BASE + 0x504) 66 #define INFRA_AO_DBG_CON2 (INFRACFG_AO_BASE + 0x508) 67 #define INFRA_AO_DBG_CON3 (INFRACFG_AO_BASE + 0x50C) 68 69 /* SPM init. related registers */ 70 #define VLP_AO_APC_CON (VLP_AO_DEVAPC_APB_BASE + 0xF00) 71 #define VLP_AO_MAS_SEC_0 (VLP_AO_DEVAPC_APB_BASE + 0xA00) 72 #define SCP_CFGREG_PERI_BUS_CTRL0 (SCP_CFGREG_BASE + 0x24) 73 #define MODULE_SW_CG_0_MASK (INFRACFG_AO_BASE + 0x060) 74 #define VLP_DBG_MON_SEL0_ADDR (VLPCFG_BUS_BASE + 0x108) 75 #define VLP_DBG_MON_SEL1_ADDR (VLPCFG_BUS_BASE + 0x10C) 76 #define VLP_CLKSQ_CON1 (VLP_CKSYS_BASE + 0x224) 77 #define VLP_AP_PLL_CON3 (VLP_CKSYS_BASE + 0x264) 78 79 /* SPM SRAM Data */ 80 #define SPM_SRAM_TIMESTAMP_START (SPM_SRAM_BASE + 0xF80) 81 #define SPM_SRAM_TIMESTAMP_END (SPM_SRAM_BASE + 0xFFC) 82 #define SPM_SRAM_TIMESTAMP_SIZE \ 83 (((SPM_SRAM_TIMESTAMP_END - SPM_SRAM_TIMESTAMP_START) >> 2) + 1) 84 85 /* AP_MDSRC_REQ MD 26M ON settle time (3ms) */ 86 #define AP_MDSRC_REQ_MD_26M_SETTLE 3 87 88 /* Setting the SPM settle time*/ 89 #define SPM_SYSCLK_SETTLE 0x60FE /* 1685us */ 90 91 /* Setting the SPM req/ack time*/ 92 #define SPM_ACK_TIMEOUT_US 1000 93 94 /* Settine the firmware status check for SPM PC */ 95 #define SPM_PC_CHECKABLE 96 97 enum { 98 SPM_ARGS_SPMFW_IDX_KICK = 0, 99 SPM_ARGS_SPMFW_INIT, 100 SPM_ARGS_SUSPEND, 101 SPM_ARGS_SUSPEND_FINISH, 102 SPM_ARGS_SODI, 103 SPM_ARGS_SODI_FINISH, 104 SPM_ARGS_DPIDLE, 105 SPM_ARGS_DPIDLE_FINISH, 106 SPM_ARGS_PCM_WDT, 107 SPM_ARGS_SUSPEND_CALLBACK, 108 SPM_ARGS_HARDWARE_CG_CHECK, 109 SPM_ARGS_NUM, 110 }; 111 112 typedef enum { 113 WR_NONE = 0, 114 WR_UART_BUSY, 115 WR_ABORT, 116 WR_PCM_TIMER, 117 WR_WAKE_SRC, 118 WR_DVFSRC, 119 WR_TWAM, 120 WR_PMSR, 121 WR_SPM_ACK_CHK, 122 WR_UNKNOWN, 123 } wake_reason_t; 124 125 struct pwr_ctrl; 126 struct spm_lp_scen; 127 128 void spm_set_irq_num(uint32_t num); 129 void spm_irq0_handler(uint64_t x1, uint64_t x2); 130 struct mt_lp_resource_user *get_spm_res_user(void); 131 int mt_spm_common_sodi_get_spm_pcm_flag(uint32_t *lp, uint32_t idx); 132 void mt_spm_common_sodi_en(bool en); 133 int mt_spm_common_sodi_get_spm_lp(struct spm_lp_scen **lp); 134 void mt_spm_set_common_sodi_pwrctr(void); 135 void mt_spm_set_common_sodi_pcm_flags(void); 136 int spm_boot_init(void); 137 void spm_dvfsfw_init(uint64_t boot_up_opp, uint64_t dram_issue); 138 extern struct pwr_ctrl spm_init_ctrl; 139 /* Support by bl31_plat_setup.c */ 140 uint32_t is_abnormal_boot(void); 141 142 #endif /* MT_SPM_H */ 143