blob: 0263efda06f4ed38022070b357b76df199b1db9f [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*******************************************************************************
2 * Copyright (C) 2007, ZTE Corporation.
3 *
4 * File Name: drvs_pow.h
5 * File Mark:
6 * Description:
7 * Others:
8 * Version: 1.3.0
9 * Author: wangxia
10 * Date: 2009-6-10
11 * History 1:
12 * Date:
13 * Version:
14 * Author:
15 * Modification:
16 * History 2:
17 ********************************************************************************/
18
19#ifndef _DRVS_POW_H
20#define _DRVS_POW_H
21
22/****************************************************************************
23* Include files
24****************************************************************************/
25
26/****************************************************************************
27* macro define
28****************************************************************************/
29//#define _USE_PSM
30//#define _USE_PSM_DEBUG
31
32#ifdef _OS_LINUX
33#define PSM_CPU_CP 0
34#else
35#define PSM_CPU_CP 1
36#endif
37
38#ifdef _CPU_DFS_ON
39#define PSM_CPU_DFS 1
40#else
41#define PSM_CPU_DFS 0
42#endif
43
44#ifdef _AXI_DFS_ON
45#define PSM_AXI_DFS 1
46#else
47#define PSM_AXI_DFS 0
48#endif
49
50#ifdef _AXI_DFS_ON_HW
51#define PSM_AXI_DFS_HW 1 //axi change by hw
52#else
53#define PSM_AXI_DFS_HW 0
54#endif
55
56#ifdef _DDR_DFS_ON
57#define PSM_DDR_DFS 1
58 #if PSM_DDR_DFS
59 #define PSM_DDR_DFS_HW 1 //ddr change by hw
60 #endif
61#else
62#define PSM_DDR_DFS 0
63#define PSM_DDR_DFS_HW 0
64#endif
65
66#ifdef _VCORE_DVS_ON
67#define PSM_VCORE_DVS 1
68#else
69#define PSM_VCORE_DVS 0
70#endif
71
72
73#define POW_IDLE_TIMEOUT_MS (1)
74#define POW_IDLE_TIMEOUT_TCPIP (5*1000*POW_IDLE_TIMEOUT_MS)
75
76#define ICP2M0_PSM_AT_CMD_VALID 0x49435001
77#define ICP2M0_PSM_AXI_DFS 0x49435002
78
79/****************************************************************************
80* Global Variables
81****************************************************************************/
82
83
84/****************************************************************************
85* Types
86****************************************************************************/
87typedef enum
88{
89/*PS wake int dis reg1 begin*/
90 PS_RM_INT_DIS=1,
91 UART0_RXD_INT_DIS=2,
92 SD0_DATA1_INT_DIS=3,
93 PS_TIMER1_INT_DIS,
94 PS_TIMER2_INT_DIS,
95 ICP_AP2PS_INT_DIS,
96 USB2_POWERDWN_UP_INT_DIS,
97 USB2_POWERDWN_DOWN_INT_DIS,
98 HSIC_POWERDWN_UP_INT_DIS,
99 HSIC_POWERDWN_DOWN_INT_DIS,
100 ICP_PHY2PS_INT_DIS,
101 ICP_M02PS_INT_DIS,
102 RM_RTC_ALARM_INT_DIS,
103 RM_RTC_TIMER_INT_DIS,
104 RM_KEYPAD_INT_DIS,
105 SD1_DATA1_INT_DIS,
106 UART0_CTS_INT_DIS,
107 SPCU_PW_INT_DIS,
108 GSM_LPM_INT_DIS,
109 TD_LPM_TIMER_IND3_DIS=24,
110 TD_LPM_TIMER_IND4_DIS,
111 LTE_LPM_TIMER_IND2_DIS,
112 LTE_LPM_TIMER_IND4_DIS,
113 LTE_LPM_TIMER_IND5_DIS,
114 WD_LPM_TIMER_IND3_DIS,
115 WD_LPM_TIMER_IND4_DIS,
116 FRM_INT_ARM_32K_DIS=31,
117/*PS wake int dis reg1 end*/
118/*PS wake int dis reg2 begin*/
119 EXTERNAL_INT0_DIS=34,
120 EXTERNAL_INT1_DIS,
121 EXTERNAL_INT2_DIS,
122 EXTERNAL_INT3_DIS,
123 EXTERNAL_INT4_DIS,
124 EXTERNAL_INT5_DIS,
125 EXTERNAL_INT6_DIS,
126 EXTERNAL_INT7_DIS,
127 EXTERNAL_8IN1_INT0_DIS,
128 EXTERNAL_8IN1_INT1_DIS,
129 EXTERNAL_8IN1_INT2_DIS,
130 EXTERNAL_8IN1_INT3_DIS,
131 EXTERNAL_8IN1_INT4_DIS,
132 EXTERNAL_8IN1_INT5_DIS,
133 EXTERNAL_8IN1_INT6_DIS,
134 EXTERNAL_8IN1_INT7_DIS=49,
135
136 INVALID_WAKE_DIS_BIT
137/*PS wake int dis reg2 end*/
138}T_ZDrvPow_PsIntWakeDis;
139
140typedef enum
141{
142 PS_WAKE_INT,
143 PS_DIS_WAKE_INT,
144
145 INVALID_PS_WAKE_EN
146}T_ZDrvPow_PsWakeIntDis;
147
148
149typedef enum
150{
151 IDLE_FLAG_UICC =0,
152 IDLE_FLAG_USBENUM =1,
153 IDLE_FLAG_VOICE =2,
154 IDLE_FLAG_I2S=3,
155 IDLE_FLAG_AP2CP=4,
156 IDLE_FLAG_SLEEP=5,
157 IDLE_FLAG_WIFI=6,
158 IDLE_FLAG_KPD=7,
159 IDLE_FLAG_TCPIP=8,
160 IDLE_FLAG_NAND=9,
161 IDLE_FLAG_CHARGER=10,
162 IDLE_FLAG_LCD=11,
163 IDLE_FLAG_LED=12,
164 IDLE_FLAG_WIFI_IOCTRL=13,
165 IDLE_FLAG_WIFI_XMIT=14,
166 IDLE_FLAG_LAN=15,
167 IDLE_FLAG_HOSTENUM=16,
168 IDLE_FLAG_BLG=17,
169 IDLE_FLAG_UART=18,
170 IDLE_FLAG_TD_ICP=19,/*·ÀֹʹÄÜ×ÓÖ¡ÖжÏÓë×ÓÖ¡Öжϵ½À´ÆÚ¼ä½øÈëÐÝÃß*/
171 IDLE_FLAG_W_ICP=20,
172 IDLE_FLAG_LTE_ICP=21,
173 IDLE_FLAG_CAMERA=22,
174 IDLE_FLAG_SD=23,
175 IDLE_FLAG_PMIC=24,
176 IDLE_FLAG_I2C=25,
177 IDLE_FLAG_VSIM = 26,
178 IDLE_FLAG_EDCP=27,
179 IDLE_FLAG_TDM,
180 IDLE_FLAG_MAX
181
182}T_ZDrvPow_IdleFlag;
183
184/*plat begin*/
185typedef enum
186{
187 TD_PHY =0,
188 WD_PHY =1,
189 LTE_PHY =2,
190 PHY_ID_MAX
191
192}T_ZDrvPow_PhyId;
193
194typedef enum
195{
196 POW_BOOT_DEFAULT, /* Æô¶¯³õʼֵ */
197 POW_SYSINIT_FINISH, /* ϵͳ³õʼ»¯Íê³É,ÈçÐͺŻúÍê³ÉSysEntry */
198 POW_BOOT_FINISH /* ¿ª»úÍê³É£¬ÈçÐͺŻú³öÏÖ´ý»ú½çÃæ */
199}T_ZDrvPow_BootStage; /* Æô¶¯½×¶Î */
200/*plat begin*/
201
202/*sleep begin*/
203typedef struct _T_ZDrvPow_Opt
204{
205 VOID (*pow_RefBeforeSleep)(VOID);
206 VOID (*pow_RefAfterSleep)(VOID);
207}T_ZDrvPow_Opt;
208
209typedef enum
210{
211 KERNEL_SLEEP_MODE,
212 BOOT_SLEEP_MODE,
213 LOSSCOVERAGE_SLEEP_MODE,
214 AIRPLANE_SLEEP_MODE,
215 DEEP_SLEEP_MODE,
216 MAX_SLEEP_MODE
217}T_ZDrvPow_SleepMode;
218
219typedef enum
220{
221 FPI_CLK_32K = 0,
222 FPI_CLK_52M = 1,
223 FPI_INVALID_CLK
224}T_ZDrvPow_FpiClk;
225
226typedef enum
227{
228 ARM_PS_WAKE = 0,
229 ARM_PS_SLEEP = 1,
230 ARM_PS_INVALID_FLAG
231}T_ZDrvPow_PsSleepFlag;
232
233 /*sleep end*/
234
235 /*freq begin*/
236typedef enum
237{
238#if defined (_CHIP_ZX297520V2)
239 MAIN_CLK=0,
240 AON_MPLL_624M,
241 AON_DPLL_491M52,
242 MATRIX_MPLL_312M,
243 AON_MPLL_208M,
244 MATRIX_MPLL_104M,
245 MATRIX_MPLL_78M,
246 MATRIX_MPLL_52M=7,
247#else
248 MAIN_CLK=0,
249 AON_MPLL_624M,
250 MATRIX_MPLL_312M,
251 MATRIX_MPLL_156M,
252#endif
253 CORE_INVALID_FREQ
254}T_ZDrvPow_CoreFreq;
255
256typedef enum
257{
258#if defined (_CHIP_ZX297520V2)
259 AXI_26M,
260 AXI_39M,
261 AXI_52M,
262 AXI_78M,
263 AXI_104M,
264 AXI_122M88,
265 AXI_156M,
266#else
267 AXI_6M5=0,
268 AXI_26M,
269 AXI_39M,
270 AXI_52M,
271 AXI_78M,
272 AXI_104M,
273 AXI_124M8,
274 AXI_156M=7,
275#endif
276
277 AXI_INVALID_FREQ
278}T_ZDrvPow_AxiFreq;
279typedef enum
280{
281 VCORE_0V800,
282 VCORE_0V825,
283 VCORE_0V850,
284 VCORE_0V875,
285 VCORE_0V900,
286 VCORE_INVALID_VOL
287}T_ZDrvPow_Vcore;
288
289typedef enum
290{
291 CLK26M=26000000,
292 CLK624M=624000000,
293#if defined (_CHIP_ZX297520V2)
294#else
295 CLK156M=156000000,
296#endif
297 CLK312M=312000000,
298 CLK208M=208000000,
299 CLK78M=78000000,
300
301 CLK_INVALID_FREQ
302}T_ZDrvPow_PsFreqConst;
303
304#define DOWN_CPUFREQ CLK156M
305#define UP_CPUFREQ CLK312M
306#define PULL_CPUFREQ CLK624M
307#if PSM_DDR_DFS_HW
308 typedef enum
309 {
310 DDR_156M = 0, //ÐèÒªÖØÐ¿¼ÂÇÆµÂʵµ£¬×îÖÕÆµÂÊÇëÇóΪ¸÷ºËÇëÇóµþ¼ÓºÍ
311 DDR_208M = 0x4f,
312 DDR_312M = 0x9d,
313 DDR_400M = 0xc8,
314 DDR_CLKEND
315 }T_zDrvPow_DDRCLK;
316#else
317typedef enum
318{
319#if defined (_CHIP_ZX297520V2)
320 DDR_13M = 0,
321 DDR_52M = 1,
322 DDR_100M = 2,
323 DDR_104M = 3,
324 DDR_156M = 4,
325 DDR_208M = 5,
326 DDR_312M = 6,
327 DDR_400M = 7,
328 DDR_416M = 8,
329
330#else
331 DDR_156M ,
332 DDR_208M ,
333 DDR_312M ,
334 DDR_400M ,
335#endif
336 DDR_CLKEND
337}T_zDrvPow_DDRCLK;
338#endif
339
340 /*freq end*/
341
342/*gate begin*/
343typedef enum
344{
345 /*ps power domain*/
346 GSM_RAM_PWR = 0,
347 GSM_DSP_PWR = 1,
348 EDCP_PWR = 4,
349 /*3/4bits reserved*/
350 USB_CTRL_PWR = 8,
351 USB_HSIC_PWR = 9,
352
353 PS_ALL_PWR = 10,
354
355 MAX_PWR = 11
356
357}T_ZDrvPow_PwrId;
358
359typedef enum
360{
361 POW_ENABLE = 0,
362 POW_DISABLE = 1,
363
364 POW_ENABLE_ALL
365}T_ZDrvPow_PwrEn;
366/*gate end*/
367
368#ifdef _USE_WAKELOCK
369/*wakelock begin*/
370typedef struct _T_ZDrvWakeLock_Entry
371{
372 struct list_head node; /* node*/
373 char name[32];
374 BOOL active:1;
375 UINT32 active_count;
376 UINT32 relax_count;
377}T_ZDrvWakeLock_Entry;
378
379typedef struct _T_zDrvWakeLock_TAB
380{
381 struct list_head devList;
382 ZOSS_SEMAPHORE_ID opMutex;
383 UINT32 devListCount;
384}T_zDrvWakeLock_TAB;
385
386typedef void * T_ZDrvWakeLock_Handle;
387/*wakelock end*/
388#endif
389
390/****************************************************************************
391* function
392****************************************************************************/
393#ifdef _USE_WAKELOCK
394/*wakelock begin*/
395T_ZDrvWakeLock_Handle zDrvWakeLock_Register(const char *name);
396VOID zDrvWakeLock_Lock(T_ZDrvWakeLock_Handle handle);
397VOID zDrvWakeLock_Unlock(T_ZDrvWakeLock_Handle handle);
398BOOL zDrvWakeLock_DevStatue(VOID);
399/*wakelock end*/
400#endif
401
402typedef VOID (*psm_uartWakeExtApHook)(VOID); /*uart wake ext ap hook */
403typedef VOID (*psm_usbWakeExtApHook)(VOID); /*usb wake ext ap hook */
404
405typedef SINT32 (*pm_callback_fn)(void);
406
407extern SINT32 zx_pm_register_callback(pm_callback_fn enter_cb, pm_callback_fn exit_cb);
408
409VOID zDrvPow_SetWakeExtApHookOpt(psm_uartWakeExtApHook uartWakeExtApHook, psm_usbWakeExtApHook usbWakeExtApHook);
410
411
412/*plat begin*/
413SINT32 zDrvPow_GetLteSleepFlag(VOID);/*ЭÒéÕ»ÐèÇó£¬Óë7510±£³ÖÒ»ÖÂ*/
414VOID zDrvPow_ClearPhySleepFlag(VOID);
415SINT32 zDrvPow_GetPhySleepFlag(T_ZDrvPow_PhyId phyId);
416BOOL zDrvPow_PsmGetCampon(VOID);
417VOID zDrvPow_SetBootStage(T_ZDrvPow_BootStage stage);
418BOOL zDrvPow_PsmIdleFlag(VOID);
419VOID zDrvPow_DpramSendCmdWakePhy(T_ZDrvPow_PhyId phyId);
420VOID zDrvPow_Icp2ZspDebugInfo(T_ZDrvPow_PhyId phyId,SINT32 dwIcp);
421BOOL zDrvPow_UmtsSleep(VOID);
422VOID zDrvPow_ChangeRRCFreForGSM(VOID);
423UINT32 zDrvPow_Sleep_Func(T_ZDrvPow_SleepMode sleep_mode, UINT32 sleep_time);
424SINT32 zDrvPow_SetDevActive(T_ZDrvPow_IdleFlag devId);
425SINT32 zDrvPow_SetDevIdle(T_ZDrvPow_IdleFlag devId);
426UINT32 zDrvPow_PsmIdleFlagGet(VOID);
427UINT32 zDrvPow_PsmDeepSleepCnt(VOID);
428
429/*plat end*/
430
431 /*sleep begin*/
432SINT32 zDrvPow_SetOpt(T_ZDrvPow_Opt* pPowOpt);
433UINT32 zDrvPow_PsmDeepSleep(UINT32 ps_sleep_time);
434UINT32 zDrvPow_ChargerSleep(UINT32 sleep_time);
435VOID zDrvPow_KernelSleep(VOID);
436UINT32 zDrvPow_BootSleep(UINT32 sleep_time);
437VOID zDrvPow_ActiveSleep(UINT32 ms);
438SINT32 zDrvPow_SetPcuWakeInt(T_ZDrvPow_PsIntWakeDis intId,T_ZDrvPow_PsWakeIntDis intDis);
439SINT32 zDrvPow_PSM_Init(VOID);
440VOID zDrvPow_ChargerOnSleepInit(VOID);
441VOID zDrvPow_ChargerOnSleepOperation(VOID);
442 /*sleep end*/
443
444/*freq begin*/
445UINT32 zDrvPow_GetPsCoreFreq(VOID);
446
447SINT32 zDrvPow_SetArmPsCoreFreq(T_ZDrvPow_PsFreqConst workFreq);
448SINT32 zDrvPow_SetPsDdrFreq(T_zDrvPow_DDRCLK freq);
449/*freq end*/
450
451SINT32 zDrvPow_GetTdSfnFlag(VOID);
452VOID zDrvPow_PcuSetWakeSource(UINT32 *wake_source);
453VOID zDrvPow_PsmLed(BOOL onOff);
454/*power partition control*/
455SINT32 zDrvpow_SetPwrGate(T_ZDrvPow_PwrId partId, T_ZDrvPow_PwrEn ena);
456
457#endif/*_DRVS_POW_H*/
458