blob: 033e3c02ddd09f5e375777d336369f42b1cc491c [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein is
5 * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
6 * the prior written permission of MediaTek inc. and/or its licensors, any
7 * reproduction, modification, use or disclosure of MediaTek Software, and
8 * information contained herein, in whole or in part, shall be strictly
9 * prohibited.
10 *
11 * MediaTek Inc. (C) 2019. All rights reserved.
12 *
13 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
14 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
15 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
16 * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
17 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19 * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
20 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
21 * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
22 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
23 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
24 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
25 * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
26 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
27 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
28 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
29 * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
30 * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
31 * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
32 *
33 * The following software/firmware and/or related documentation ("MediaTek
34 * Software") have been modified by MediaTek Inc. All revisions are subject to
35 * any receiver's applicable license agreements with MediaTek Inc.
36 */
37#ifndef __PMIF_SW_H__
38#define __PMIF_SW_H__
39
40#define PMIF_PRELOADER 0
41#define PMIF_LK 0
42#define PMIF_KERNEL 0
43#define PMIF_CTP 0
44#define PMIF_MD 1
45
46/* SW ENV define */
47#define PMIF_DEBUG 1
48#define PMIF_MATCH_SUPPORT 0
49
50/* Read/write byte limitation, by project */
51#define PMIF_BYTECNT_MAX 1
52
53/* For BringUp. if BringUp doesn't had PMIC, need open this */
54#if (PMIF_PRELOADER)
55 #if CFG_FPGA_PLATFORM
56 #define PMIF_NO_PMIC 1
57 #else
58 #define PMIF_NO_PMIC 0
59 #define PMIF_TIMEOUT 0
60 #endif
61 #define PMIF_NORMAL_BOOT 1
62#elif (PMIF_LK)
63 #if defined(MACH_FPGA)
64 #define PMIF_NO_PMIC 1
65 #else
66 #define PMIF_NO_PMIC 0
67 #define PMIF_TIMEOUT 0
68 #endif
69 #define PMIF_NORMAL_BOOT 1
70#elif (PMIF_CTP)
71 #if defined(CONFIG_MTK_FPGA)
72 #define PMIF_NO_PMIC 1
73 #else
74 #define PMIF_NO_PMIC 0
75 #define PMIF_TIMEOUT 0
76 #endif
77 #define PMIF_NORMAL_BOOT 0
78#elif (PMIF_MD)
79 #ifdef __FPGA__
80 #define PMIF_NO_PMIC 1
81 #else
82 #define PMIF_NO_PMIC 0
83 #define PMIF_TIMEOUT 0
84 #endif
85 #define PMIF_NORMAL_BOOT 1
86#else
87 #define PMIF_NO_PMIC 1
88 #define PMIF_TIMEOUT 0
89#endif
90
91/* SW ENV header define */
92#if (PMIF_PRELOADER)
93 #include <sync_write.h>
94 #include <typedefs.h>
95 #include <gpio.h>
96 #include <mt6885.h>
97 #include <pll.h>
98 #include <pal_log.h>
99 #define INIT_CRITICAL()
100 #define ENTER_CRITICAL()
101 #define EXIT_CRITICAL()
102#elif (PMIF_LK)
103 #include <debug.h>
104 #include <platform/mt_typedefs.h>
105 #include <platform/mt_reg_base.h>
106 #include <platform/mt_gpt.h>
107 #include <platform/mt_irq.h>
108 #include <sys/types.h>
109 #include <platform/sync_write.h>
110 #include <platform/upmu_hw.h>
111 #include <pal_log.h>
112 #include <kernel/thread.h>
113 #define INIT_CRITICAL()
114 #define ENTER_CRITICAL() enter_critical_section();
115 #define EXIT_CRITICAL() exit_critical_section();
116#elif (PMIF_KERNEL)
117#elif (PMIF_CTP)
118 #include <sync_write.h>
119 #include <typedefs.h>
120 #include <reg_base.H>
121 #include <driver_api.h>
122 #define INIT_CRITICAL()
123 #define ENTER_CRITICAL()
124 #define EXIT_CRITICAL()
125#elif (PMIF_MD)
126 #include "reg_base.h"
127 #include "drv_comm.h"
128 #include "init.h"
129 #include "dcl.h"
130 #include "kal_public_api.h"
131 #include "kal_public_defs.h"
132 #include "kal_hrt_api.h"
133 #include "us_timer.h"
134 #include "event_info_utility.h" // for MODEM_WARNING_MESSAGE
135 #define INIT_CRITICAL()
136 #define ENTER_CRITICAL()
137 #define EXIT_CRITICAL()
138#else
139 ### Compile error, check SW ENV define
140#endif
141
142/* DEBUG MARCO */
143#define PMIFTAG "[PMIF] "
144#if (PMIF_PRELOADER)
145 #if PMIF_DEBUG
146 #define PMIF_CRI(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
147 #define PMIF_CRIL(fmt, arg...) pal_log_err(fmt, ##arg)
148 #define PMIF_ERR(fmt, arg...) \
149 pal_log_err(PMIFTAG "%d: "fmt, __LINE__, ##arg)
150 #define PMIF_WARN(fmt, arg...) pal_log_warn(PMIFTAG fmt, ##arg)
151 #define PMIF_INFO(fmt, arg...) pal_log_info(PMIFTAG fmt, ##arg)
152 #define PMIF_DBG(fmt, arg...) pal_log_debug(PMIFTAG fmt, ##arg)
153 #else
154 #define PMIF_CRI(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
155 #define PMIF_CRIL(fmt, arg...) pal_log_err(fmt, ##arg)
156 #define PMIF_ERR(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
157 #define PMIF_WARN(fmt, arg...) pal_log_info(PMIFTAG fmt, ##arg)
158 #define PMIF_INFO(fmt, arg...) do { } while(0)
159 #define PMIF_DBG(fmt, arg...) do { } while(0)
160 #endif
161#elif (PMIF_LK)
162 #if PMIF_DEBUG
163 #define PMIF_CRI(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
164 #define PMIF_CRIL(fmt, arg...) pal_log_err(fmt, ##arg)
165 #define PMIF_ERR(fmt, arg...) \
166 pal_log_err(PMIFTAG "%d: "fmt, __LINE__, ##arg)
167 #define PMIF_WARN(fmt, arg...) pal_log_warn(PMIFTAG fmt, ##arg)
168 #define PMIF_INFO(fmt, arg...) pal_log_info(PMIFTAG fmt, ##arg)
169 #define PMIF_DBG(fmt, arg...) pal_log_debug(PMIFTAG fmt, ##arg)
170 #else
171 #define PMIF_CRI(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
172 #define PMIF_CRIL(fmt, arg...) pal_log_err(fmt, ##arg)
173 #define PMIF_ERR(fmt, arg...) pal_log_err(PMIFTAG fmt, ##arg)
174 #define PMIF_WARN(fmt, arg...) pal_log_info(PMIFTAG fmt, ##arg)
175 #define PMIF_INFO(fmt, arg...) do { } while(0)
176 #define PMIF_DBG(fmt, arg...) do { } while(0)
177 #endif
178#elif (PMIF_KERNEL)
179#elif (PMIF_CTP)
180 #ifdef PMIF_DEBUG
181 #define PMIF_CRI(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
182 #define PMIF_CRIL(fmt, arg...) dbg_print(fmt, ##arg)
183 #define PMIF_ERR(fmt, arg...) \
184 dbg_print(PMIFTAG "%d: "fmt, __LINE__, ##arg)
185 #define PMIF_WARN(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
186 #define PMIF_INFO(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
187 #define PMIF_DBG(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
188 #else
189 #define PMIF_CRI(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
190 #define PMIF_CRIL(fmt, arg...) dbg_print(fmt, ##arg)
191 #define PMIF_ERR(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
192 #define PMIF_WARN(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
193 #define PMIF_INFO(fmt, arg...) do { } while(0)
194 #define PMIF_DBG(fmt, arg...) do { } while(0)
195 #endif /* end of #ifdef PMIF_DEBUG */
196#elif (PMIF_MD)
197 #if defined(DRV_DEBUG) || defined(ATEST_DRV_ENABLE)
198 #ifdef PMIF_DEBUG
199 #define PMIF_CRI(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
200 #define PMIF_CRIL(fmt, arg...) dbg_print(fmt, ##arg)
201 #define PMIF_ERR(fmt, arg...) \
202 dbg_print(PMIFTAG "%d: "fmt, __LINE__, ##arg)
203 #define PMIF_WARN(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
204 #define PMIF_INFO(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
205 #define PMIF_DBG(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
206 #else
207 #define PMIF_CRI(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
208 #define PMIF_CRIL(fmt, arg...) dbg_print(fmt, ##arg)
209 #define PMIF_ERR(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
210 #define PMIF_WARN(fmt, arg...) dbg_print(PMIFTAG fmt, ##arg)
211 #define PMIF_INFO(fmt, arg...) do { } while(0)
212 #define PMIF_DBG(fmt, arg...) do { } while(0)
213 #endif /* end of #ifdef PMIF_DEBUG */
214 #else
215 #define PMIF_CRI(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__)
216 #define PMIF_CRIL(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__)
217 #define PMIF_ERR(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__)
218 #define PMIF_WARN(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__)
219 #define PMIF_INFO(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__)
220 #define PMIF_DBG(string, ...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_DHL_READER, (char*)string, ##__VA_ARGS__)
221 #endif
222#else
223 ### Compile error, check SW ENV define
224#endif
225
226/* macro for SWINF_FSM */
227#define SWINF_FSM_IDLE (0x00)
228#define SWINF_FSM_REQ (0x02)
229#define SWINF_FSM_WFDLE (0x04)
230#define SWINF_FSM_WFVLDCLR (0x06)
231#define SWINF_INIT_DONE (0x01)
232/* indicate which number SW channel start, by project */
233#if defined(CHIP10992)
234#define PMIF_SWINF_0_CHAN_NO 6
235#define PMIF_SWINF_0_CHAN_NO_P 6
236#else
237#define PMIF_SWINF_0_CHAN_NO 4
238#define PMIF_SWINF_0_CHAN_NO_P 1
239#endif
240/* MD: 0, security domain: 1, AP: 2 */
241#if defined(CHIP10992)
242#define PMIF_AP_SWINF_NO 0
243#define PMIF_AP_SWINF_NO_P 0
244#else
245#define PMIF_AP_SWINF_NO 0
246#define PMIF_AP_SWINF_NO_P 3
247#endif
248/* 0: SPI, 1: SPMI */
249#define PMIF_PMIFID 1
250#define PMIF_PMIFID_2 2
251
252#ifndef EIO
253#define EIO 5 /* I/O error */
254#endif
255#ifndef EBUSY
256#define EBUSY 16 /* Device or resource busy */
257#endif
258#ifndef ENODEV
259#define ENODEV 19 /* No such device */
260#endif
261#ifndef EINVAL
262#define EINVAL 22 /* Invalid argument */
263#endif
264#ifndef EOPNOTSUPP
265#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
266#endif
267#ifndef ETIMEDOUT
268#define ETIMEDOUT 110 /* Connection timed out */
269#endif
270
271#ifndef BASE_INFRA_AO_CONFIG
272#define BASE_INFRA_AO_CONFIG (0xC0001000)
273#endif
274#ifndef INFRACFG_AO_BASE
275#define INFRACFG_AO_BASE BASE_INFRA_AO_CONFIG
276#endif
277#ifndef BASE_INFRA_AO_TOPCKGEN
278#define BASE_INFRA_AO_TOPCKGEN (0xC0000000)
279#endif
280#ifndef TOPCKGEN_BASE
281#define TOPCKGEN_BASE BASE_INFRA_AO_TOPCKGEN
282#endif
283#ifndef TOPRGU_BASE
284#define TOPRGU_BASE (0xC0007000)
285#endif
286/* macro for spmi clock config */
287#ifndef CLK_CFG_UPDATE1
288#define CLK_CFG_UPDATE1 (TOPCKGEN_BASE+0x008)
289#endif
290#ifndef CLK_CFG_UPDATE2
291#define CLK_CFG_UPDATE2 (TOPCKGEN_BASE+0x00c)
292#endif
293#ifndef CLK_CFG_8_SET
294#define CLK_CFG_8_SET (TOPCKGEN_BASE+0x094)
295#endif
296#ifndef CLK_CFG_8_CLR
297#define CLK_CFG_8_CLR (TOPCKGEN_BASE+0x098)
298#endif
299#ifndef CLK_CFG_16_CLR
300#define CLK_CFG_16_CLR (TOPCKGEN_BASE+0x118)
301#endif
302#ifndef MODULE_SW_CG_0_SET
303#define MODULE_SW_CG_0_SET (INFRACFG_AO_BASE+0x080)
304#endif
305#ifndef MODULE_SW_CG_0_CLR
306#define MODULE_SW_CG_0_CLR (INFRACFG_AO_BASE+0x084)
307#endif
308#ifndef MODULE_CLK_SEL
309#define MODULE_CLK_SEL (INFRACFG_AO_BASE+0x098)
310#endif
311#ifndef MODULE_SW_CG_2_SET
312#define MODULE_SW_CG_2_SET (INFRACFG_AO_BASE+0x0A4)
313#endif
314#ifndef MODULE_SW_CG_2_CLR
315#define MODULE_SW_CG_2_CLR (INFRACFG_AO_BASE+0x0A8)
316#endif
317#define INFRA_GLOBALCON_RST2_SET (INFRACFG_AO_BASE+0x140)
318#define INFRA_GLOBALCON_RST2_CLR (INFRACFG_AO_BASE+0x144)
319
320extern int spmi_pmif_dbg_init(struct pmif *arb);
321#endif /*__PMIF_SW_H__*/