1 /* 2 * Copyright (c) 2022, 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 <lib/bakery_lock.h> 11 #include <lib/spinlock.h> 12 #include <plat_mtk_lpm.h> 13 14 /* 15 * ARM v8.2, the cache will turn off automatically when cpu 16 * power down. Therefore, there is no doubt to use the spin_lock here. 17 */ 18 #if !HW_ASSISTED_COHERENCY 19 #define MT_SPM_USING_BAKERY_LOCK 20 #endif 21 22 #ifdef MT_SPM_USING_BAKERY_LOCK 23 DECLARE_BAKERY_LOCK(spm_lock); 24 #define plat_spm_lock() bakery_lock_get(&spm_lock) 25 #define plat_spm_unlock() bakery_lock_release(&spm_lock) 26 #else 27 extern spinlock_t spm_lock; 28 #define plat_spm_lock() spin_lock(&spm_lock) 29 #define plat_spm_unlock() spin_unlock(&spm_lock) 30 #endif 31 32 #define MT_SPM_USING_SRCLKEN_RC 33 34 /* spm extern operand definition */ 35 #define MT_SPM_EX_OP_CLR_26M_RECORD BIT(0) 36 #define MT_SPM_EX_OP_SET_WDT BIT(1) 37 #define MT_SPM_EX_OP_NON_GENERIC_RESOURCE_REQ BIT(2) 38 #define MT_SPM_EX_OP_SET_SUSPEND_MODE BIT(3) 39 #define MT_SPM_EX_OP_SET_IS_ADSP BIT(4) 40 #define MT_SPM_EX_OP_SRCLKEN_RC_BBLPM BIT(5) 41 #define MT_SPM_EX_OP_HW_S1_DETECT BIT(6) 42 #define MT_SPM_EX_OP_TRACE_LP BIT(7) 43 #define MT_SPM_EX_OP_TRACE_SUSPEND BIT(8) 44 #define MT_SPM_EX_OP_TRACE_TIMESTAMP_EN BIT(9) 45 #define MT_SPM_EX_OP_TIME_CHECK BIT(10) 46 #define MT_SPM_EX_OP_TIME_OBS BIT(11) 47 48 typedef enum { 49 WR_NONE = 0, 50 WR_UART_BUSY = 1, 51 WR_ABORT = 2, 52 WR_PCM_TIMER = 3, 53 WR_WAKE_SRC = 4, 54 WR_DVFSRC = 5, 55 WR_TWAM = 6, 56 WR_PMSR = 7, 57 WR_SPM_ACK_CHK = 8, 58 WR_UNKNOWN = 9, 59 } wake_reason_t; 60 61 /* for suspend vol. bin settings */ 62 enum MT_PLAT_SUSPEND_VCORE { 63 SPM_SUSPEND_VCORE_5500 = 0, 64 SPM_SUSPEND_VCORE_5250 = 1, 65 SPM_SUSPEND_VCORE_5000 = 2, 66 }; 67 68 extern void spm_boot_init(void); 69 70 static inline void spm_lock_get(void) 71 { 72 plat_spm_lock(); 73 } 74 75 static inline void spm_lock_release(void) 76 { 77 plat_spm_unlock(); 78 } 79 80 unsigned int spm_get_suspend_vcore_voltage_idx(void); 81 82 #endif /* MT_SPM_H */ 83