29 #include "./hal/hal_global.h" 35 #define PM_MAX_SLEEP_TIME 0xFFFFFFFF 51 PM_ERR_INVALID_PARAM = -1,
52 PM_ERR_NOT_AVAIL = -2,
57 PM_RETN_EM_4K_A = 0x1,
58 PM_RETN_EM_4K_B = 0x2,
59 PM_RETN_EM_8K_A = 0x4,
60 PM_RETN_EM_8K_B = 0x8,
61 PM_RETN_EM_16K = 0x10,
62 PM_RETN_EM_ALL = 0x1F,
66 PM_RETN_DM_4K_A = 0x1,
67 PM_RETN_DM_4K_B = 0x2,
70 PM_RETN_DM_32K_A = 0x10,
71 PM_RETN_DM_32K_B = 0x20,
72 PM_RETN_DM_32K_C = 0x40,
73 PM_RETN_DM_ALL = 0x7F,
82 PM_WS_AON_TIMER2_EMIT0,
83 PM_WS_AON_TIMER2_EMIT1,
84 PM_WS_AON_SYSTICK_TIMER,
134 struct pm_module *prev;
135 struct pm_module *next;
137 int (*power_state)(
void *arg, uint32_t *slp_dur);
138 void (*power_down)(
void *arg, uint32_t slp_dur);
139 void (*power_up)(
void *arg);
146 static INLINE
void aon_slp_tmr_wup_enable(
void)
148 WR_WORD(AON_PS_REGS_AON_ST_WAKEUP_CTRL, 1);
151 static INLINE
void aon_slp_tmr_wup_disable(
void)
153 WR_WORD(AON_PS_REGS_AON_ST_WAKEUP_CTRL, 0);
156 static INLINE
void aon_ble_wup_enable(
void)
158 WR_WORD(AON_PS_REGS_BLE_ST_WAKEUP_CTRL, 1);
161 static INLINE
void aon_ble_wup_disable(
void)
163 WR_WORD(AON_PS_REGS_BLE_ST_WAKEUP_CTRL, 0);
166 static INLINE
void aon_brown_out_wup_enable(
void)
168 WR_WORD(AON_PS_REGS_BO_OUT_WAKEUP_CTRL, 1);
171 static INLINE
void aon_brown_out_wup_disable(
void)
173 WR_WORD(AON_PS_REGS_BO_OUT_WAKEUP_CTRL, 0);
176 static INLINE
void aon_mixed_signal_wup_enable(
void)
178 WR_WORD(AON_PS_REGS_MSIO_WAKEUP_CTRL, 1);
181 static INLINE
void aon_mixed_signal_wup_disable(
void)
183 WR_WORD(AON_PS_REGS_MSIO_WAKEUP_CTRL, 0);
186 static INLINE
void aon_deep_sleep_enable(
int force)
188 uint32_t reg = RD_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL);
191 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_FORCE;
193 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_FORCE;
195 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_PD_DOO_CORE_ENABLE;
197 WR_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL, reg);
200 static INLINE
void aon_deep_sleep_disable(
void)
202 uint32_t reg = RD_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL);
204 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_PD_DOO_CORE_ENABLE;
206 WR_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL, reg);
209 static INLINE
void aon_dm_reten(uint32_t retn)
211 uint32_t reg = RD_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL);
213 if (retn & PM_RETN_DM_4K_A)
214 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_4K_A_RET_ENABLE;
216 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_4K_A_RET_ENABLE;
218 if (retn & PM_RETN_DM_4K_B)
219 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_4K_B_RET_ENABLE;
221 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_4K_B_RET_ENABLE;
223 if (retn & PM_RETN_DM_8K)
224 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_8K_RET_ENABLE;
226 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_8K_RET_ENABLE;
228 if (retn & PM_RETN_DM_16K)
229 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_16K_RET_ENABLE;
231 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_16K_RET_ENABLE;
233 if (retn & PM_RETN_DM_32K_A)
234 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_32K_A_RET_ENABLE;
236 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_32K_A_RET_ENABLE;
238 if (retn & PM_RETN_DM_32K_B)
239 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_32K_B_RET_ENABLE;
241 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_32K_B_RET_ENABLE;
243 if (retn & PM_RETN_DM_32K_C)
244 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_32K_C_RET_ENABLE;
246 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_DM_32K_C_RET_ENABLE;
248 WR_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL, reg);
251 static INLINE
void aon_em_reten(uint32_t retn)
253 uint32_t reg = RD_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL);
255 if (retn & PM_RETN_EM_4K_A)
256 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_4K_A_RET_ENABLE;
258 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_4K_A_RET_ENABLE;
260 if (retn & PM_RETN_EM_4K_B)
261 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_4K_B_RET_ENABLE;
263 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_4K_B_RET_ENABLE;
265 if (retn & PM_RETN_EM_8K_A)
266 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_8K_A_RET_ENABLE;
268 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_8K_A_RET_ENABLE;
270 if (retn & PM_RETN_EM_8K_B)
271 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_8K_B_RET_ENABLE;
273 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_8K_B_RET_ENABLE;
275 if (retn & PM_RETN_EM_16K)
276 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_16K_A_RET_ENABLE;
278 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_EM_16K_A_RET_ENABLE;
280 WR_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL, reg);
283 static INLINE
void aon_trig_mem_retn(
int en)
285 uint32_t reg = RD_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL);
288 reg |= AON_PS_REGS_PD_DOO_SLEEP_CTRL_TRIG_RET_ENABLE;
290 reg &= ~AON_PS_REGS_PD_DOO_SLEEP_CTRL_TRIG_RET_ENABLE;
293 WR_WORD(AON_PS_REGS_PD_DOO_SLEEP_CTRL, reg);
296 static INLINE uint32_t aon_wup_raw_status(
void)
298 return (RD_WORD(AON_PS_REGS_RAW_WAKEUP_BITS));
301 static INLINE uint32_t aon_wup_service_req(
void)
303 return (RD_WORD(AON_PS_REGS_SERVICED_REQUEST));
306 static INLINE uint32_t aon_wup_active_req(
void)
308 return (RD_WORD(AON_PS_REGS_ACTIVE_REQUEST));
311 static INLINE uint32_t aon_wup_last_req(
void)
313 return (RD_WORD(AON_PS_REGS_LAST_REQUEST));
316 static INLINE uint32_t aon_wup_status_and_clear(
void)
318 uint32_t reg = RD_WORD(AON_PS_REGS_REQUEST_WITH_SOFT_CLR);
319 WR_WORD(AON_PS_REGS_REQUEST_WITH_SOFT_CLR, (reg | AON_PS_REGS_REQUEST_WITH_SOFT_CLR_CTL_REQUEST_CLR));
323 static INLINE
void aon_ble_ext_wup(
int en)
325 uint32_t reg = RD_WORD(AON_REG_AON_MISC_CTRL);
328 reg |= AON_REG_AON_MISC_CTRL_CTL_BLE_EXT_WAKEUP_ENABLE;
330 reg &= ~AON_REG_AON_MISC_CTRL_CTL_BLE_EXT_WAKEUP_ENABLE;
333 WR_WORD(AON_REG_AON_MISC_CTRL, reg);
336 static INLINE uint32_t pm_wakeup_source(
void)
338 return (RD_WORD(GLOBAL_REG_PD0_WAKEUP_SRC_PD1_RST_INFO) & GLOBAL_REG_PD0_WAKEUP_SRC_PD1_RST_INFO_STS_WAKEUP_SRC_MASK);
341 void pd1_tmr_init(
void);
342 void pd1_tmr_stop(
void);
343 void pd1_tmr_periodic_start(uint32_t usec);
364 int hal_pm_init(
int slp_wup,
int ble_wup,
int bod_wup,
int mix_wup,
int trig_retn, uint32_t dm_retn, uint32_t em_retn);
450 void hal_pm_mix_sig_wup_disable(
void);
455 #endif // HAL_POWER_H int hal_pm_reg_mod(struct pm_module *module)
Register power module function.
uint32_t hal_pm_suspend_and_resume(uint32_t os_sleep)
System shutdown and resume function.
int hal_pm_reg_ble_mod(struct pm_module *module)
Register BLE power module function.
int hal_pm_init(int slp_wup, int ble_wup, int bod_wup, int mix_wup, int trig_retn, uint32_t dm_retn, uint32_t em_retn)
Power Management initialization function.
void hal_pm_mix_sig_wup_enable(void)
Enable/Disable mix signal (GPIO PORT 2) wake up.
uint32_t hal_pm_get_wup_src(void)
Read the wake up source.
int hal_pm_unreg_ble_mod(struct pm_module *module)
Unregister BLE power module function.
int hal_pm_unreg_mod(struct pm_module *module)
Unregister power module function.