1 #ifndef _FREERTOS_PMU_H_
2 #define _FREERTOS_PMU_H_
3 
4 typedef enum {
5 	PMU_OS					=0,
6 	PMU_WLAN_DEVICE		=1,
7 	PMU_LOGUART_DEVICE	=2,
8 	PMU_KM4_RUN			=3,
9 
10 	PMU_UART0_DEVICE		=4,
11 	PMU_UART1_DEVICE		=5,
12 	PMU_I2C0_DEVICE		=6,
13 	PMU_TOUCH_DEVICE		=7,
14 	PMU_USOC_DEVICE		=8,
15 	PMU_DONGLE_DEVICE	=9,
16 	PMU_RTC_DEVICE		=10,
17 	PMU_CONSOL_DEVICE	=11,
18 	PMU_ADC_DEVICE	=12,
19 	PMU_WAKWLOCK_TIMEOUT=13,
20 	PMU_KEYSCAN_DEVICE	=14,
21 	PMU_PSRAM_DEVICE	=15,
22 	PMU_DEV_USER_BASE	=16, /*number 16 ~ 31 is reserved for customer use*/
23 
24 	PMU_MAX				=31
25 } PMU_DEVICE;
26 
27 enum SLEEP_TYPE {
28 	SLEEP_PG	= 0,
29 	SLEEP_CG	= 1,
30 };
31 
32 // default locked by OS and not to sleep until OS release wakelock in somewhere
33 #define DEFAULT_WAKELOCK		(BIT(PMU_OS))
34 #define DEFAULT_DEEP_WAKELOCK		(BIT(PMU_OS))
35 #define SLEEP_MAX_DELAY		(u32) 0xffffffffUL
36 
37 typedef uint32_t (*PSM_HOOK_FUN)( unsigned int, void* param_ptr );
38 
39 #define PMU_DEVICE_TIMER_DEFAULT_INTERVAL	2000
40 #define PMU_DEVICE_TIMER_MAX_INTERVAL		(1000*30) /* max 30sec */
41 
42 typedef struct
43 {
44 	u32					nDeviceId;
45 	PSM_HOOK_FUN		sleep_hook_fun;
46 	void*				sleep_param_ptr;
47 	PSM_HOOK_FUN		wakeup_hook_fun;
48 	void*				wakeup_param_ptr;
49 }PSM_DD_HOOK_INFO;
50 
51 
52 /**
53   * @brief  init system active timer for PMU.
54   * @param  none.
55   * @retval status value:
56   *          - 0: _FAIL
57   *          - 1: _SUCCESS
58   * @note can just used in late resume or later, can not used in wakeup_hook_fun.
59   */
60 uint32_t pmu_yield_os_check(void);
61 u32 pmu_exec_sleep_hook_funs(void);
62 void pmu_exec_wakeup_hook_funs(u32 nDeviceIdMax);
63 uint32_t pmu_set_sleep_type(uint32_t type);
64 uint32_t pmu_get_sleep_type(void);
65 void pmu_set_max_sleep_time(uint32_t timer_ms);
66 #ifndef CONFIG_BUILD_ROM
67 void pmu_deepsleep_cmd(u32 NewStatus);
68 #endif
69 void pmu_tickless_debug(u32 NewStatus);
70 
71 void pmu_set_dsleep_active_time(uint32_t TimeOutMs);
72 void pmu_acquire_deepwakelock(uint32_t nDeviceId);
73 void pmu_release_deepwakelock(uint32_t nDeviceId);
74 
75 void pmu_set_dev_wakeup_tick(u32 nDeviceId, u32 Ms);
76 uint32_t pmu_set_sysactive_time(uint32_t timeout);
77 void pmu_register_sleep_callback(u32 nDeviceId, PSM_HOOK_FUN sleep_hook_fun, void* sleep_param_ptr, PSM_HOOK_FUN wakeup_hook_fun, void* wakeup_param_ptr);
78 void pmu_unregister_sleep_callback(u32 nDeviceId);
79 
80 int freertos_ready_to_sleep(void);
81 int freertos_ready_to_dsleep(void);
82 void freertos_pre_sleep_processing(unsigned int *expected_idle_time);
83 void freertos_post_sleep_processing(unsigned int *expected_idle_time);
84 
85 void pmu_acquire_wakelock(uint32_t nDeviceId);
86 void pmu_release_wakelock(uint32_t nDeviceId);
87 uint32_t pmu_get_wakelock_status(void);
88 uint32_t pmu_get_deepwakelock_status(void);
89 
90 extern u32 tickless_debug;
91 extern u32 tick_last_tcp;
92 #endif
93