13 #include "pwrmgr_regs.h"
28 (1u << (PWRMGR_CONTROL_CORE_CLK_EN_BIT -
29 PWRMGR_CONTROL_CORE_CLK_EN_BIT)),
30 "Layout of control register changed.");
33 (1u << (PWRMGR_CONTROL_IO_CLK_EN_BIT -
34 PWRMGR_CONTROL_CORE_CLK_EN_BIT)),
35 "Layout of control register changed.");
38 (1u << (PWRMGR_CONTROL_USB_CLK_EN_LP_BIT -
39 PWRMGR_CONTROL_CORE_CLK_EN_BIT)),
40 "Layout of control register changed.");
43 (1u << (PWRMGR_CONTROL_USB_CLK_EN_ACTIVE_BIT -
44 PWRMGR_CONTROL_CORE_CLK_EN_BIT)),
45 "Layout of control register changed.");
48 (1u << (PWRMGR_CONTROL_MAIN_PD_N_BIT -
49 PWRMGR_CONTROL_CORE_CLK_EN_BIT)),
50 "Layout of control register changed.");
62 .index = PWRMGR_CONTROL_CORE_CLK_EN_BIT,
69 static_assert(kDifPwrmgrWakeupRequestSourceOne ==
70 (1u << PWRMGR_WAKEUP_EN_EN_0_BIT),
71 "Layout of WAKEUP_EN register changed.");
72 static_assert(kDifPwrmgrWakeupRequestSourceOne ==
73 (1u << PWRMGR_PARAM_SYSRST_CTRL_AON_WKUP_REQ_IDX),
74 "Layout of WAKE_INFO register changed.");
75 static_assert(kDifPwrmgrWakeupRequestSourceTwo ==
76 (1u << PWRMGR_PARAM_ADC_CTRL_AON_WKUP_REQ_IDX),
77 "Layout of WAKE_INFO register changed.");
78 static_assert(kDifPwrmgrWakeupRequestSourceThree ==
79 (1u << PWRMGR_PARAM_PINMUX_AON_PIN_WKUP_REQ_IDX),
80 "Layout of WAKE_INFO register changed.");
81 static_assert(kDifPwrmgrWakeupRequestSourceFour ==
82 (1u << PWRMGR_PARAM_PINMUX_AON_USB_WKUP_REQ_IDX),
83 "Layout of WAKE_INFO register changed.");
84 static_assert(kDifPwrmgrWakeupRequestSourceFive ==
85 (1u << PWRMGR_PARAM_AON_TIMER_AON_WKUP_REQ_IDX),
86 "Layout of WAKE_INFO register changed.");
87 static_assert(kDifPwrmgrWakeupRequestSourceSix ==
88 (1u << PWRMGR_PARAM_SENSOR_CTRL_AON_WKUP_REQ_IDX),
89 "Layout of WAKE_INFO register changed.");
95 static_assert(kDifPwrmgrResetRequestSourceOne ==
96 (1u << PWRMGR_RESET_EN_EN_0_BIT),
97 "Layout of RESET_EN register changed.");
98 static_assert(kDifPwrmgrResetRequestSourceTwo ==
99 (1u << PWRMGR_RESET_EN_EN_1_BIT),
100 "Layout of RESET_EN register changed.");
106 "Layout of interrupt registers changed.");
112 ptrdiff_t write_enable_reg_offset;
114 ptrdiff_t sources_enable_reg_offset;
115 ptrdiff_t cur_req_sources_reg_offset;
129 .write_enable_reg_offset = PWRMGR_WAKEUP_EN_REGWEN_REG_OFFSET,
130 .write_enable_bit_index = PWRMGR_WAKEUP_EN_REGWEN_EN_BIT,
131 .sources_enable_reg_offset = PWRMGR_WAKEUP_EN_REG_OFFSET,
132 .cur_req_sources_reg_offset = PWRMGR_WAKE_STATUS_REG_OFFSET,
135 .mask = kDifPwrmgrWakeupRequestSourceOne |
136 kDifPwrmgrWakeupRequestSourceTwo |
137 kDifPwrmgrWakeupRequestSourceThree |
138 kDifPwrmgrWakeupRequestSourceFour |
139 kDifPwrmgrWakeupRequestSourceFive |
140 kDifPwrmgrWakeupRequestSourceSix,
146 .write_enable_reg_offset = PWRMGR_RESET_EN_REGWEN_REG_OFFSET,
147 .write_enable_bit_index = PWRMGR_RESET_EN_REGWEN_EN_BIT,
148 .sources_enable_reg_offset = PWRMGR_RESET_EN_REG_OFFSET,
149 .cur_req_sources_reg_offset = PWRMGR_RESET_STATUS_REG_OFFSET,
152 .mask = kDifPwrmgrResetRequestSourceOne |
153 kDifPwrmgrResetRequestSourceTwo,
173 return (val & bitfield.
mask) == val;
183 static bool control_register_is_locked(
const dif_pwrmgr_t *pwrmgr) {
186 mmio_region_read32(pwrmgr->
base_addr, PWRMGR_CTRL_CFG_REGWEN_REG_OFFSET),
187 PWRMGR_CTRL_CFG_REGWEN_EN_BIT);
196 static void sync_slow_clock_domain_polled(
const dif_pwrmgr_t *pwrmgr) {
199 pwrmgr->
base_addr, PWRMGR_CFG_CDC_SYNC_REG_OFFSET,
202 mmio_region_read32(pwrmgr->
base_addr, PWRMGR_CFG_CDC_SYNC_REG_OFFSET),
203 PWRMGR_CFG_CDC_SYNC_SYNC_BIT)) {
211 static bool request_sources_is_locked(
const dif_pwrmgr_t *pwrmgr,
215 mmio_region_read32(pwrmgr->
base_addr, reg_info.write_enable_reg_offset);
228 if (control_register_is_locked(pwrmgr)) {
233 mmio_region_read32(pwrmgr->
base_addr, PWRMGR_CONTROL_REG_OFFSET);
236 mmio_region_write32(pwrmgr->
base_addr, PWRMGR_CONTROL_REG_OFFSET, reg_val);
240 sync_slow_clock_domain_polled(pwrmgr);
247 if (pwrmgr == NULL || cur_state == NULL) {
252 mmio_region_read32(pwrmgr->
base_addr, PWRMGR_CONTROL_REG_OFFSET);
262 if (pwrmgr == NULL || !is_valid_for_bitfield(config, kDomainConfigBitfield) ||
267 if (control_register_is_locked(pwrmgr)) {
272 mmio_region_read32(pwrmgr->
base_addr, PWRMGR_CONTROL_REG_OFFSET);
274 mmio_region_write32(pwrmgr->
base_addr, PWRMGR_CONTROL_REG_OFFSET, reg_val);
278 sync_slow_clock_domain_polled(pwrmgr);
285 if (pwrmgr == NULL || config == NULL) {
290 mmio_region_read32(pwrmgr->
base_addr, PWRMGR_CONTROL_REG_OFFSET);
292 reg_val, kDomainConfigBitfield);
300 if (pwrmgr == NULL || !is_valid_req_type(req_type) ||
307 if (!is_valid_for_bitfield(sources, reg_info.bitfield)) {
312 if (request_sources_is_locked(pwrmgr, req_type)) {
318 mmio_region_write32(pwrmgr->
base_addr, reg_info.sources_enable_reg_offset,
322 sync_slow_clock_domain_polled(pwrmgr);
330 if (pwrmgr == NULL || !is_valid_req_type(req_type) || sources == NULL) {
336 mmio_region_read32(pwrmgr->
base_addr, reg_info.sources_enable_reg_offset);
345 if (pwrmgr == NULL || !is_valid_req_type(req_type) || sources == NULL) {
350 uint32_t reg_val = mmio_region_read32(pwrmgr->
base_addr,
351 reg_info.cur_req_sources_reg_offset);
359 if (pwrmgr == NULL || !is_valid_req_type(req_type)) {
366 request_reg_infos[req_type].write_enable_reg_offset, 0);
374 if (pwrmgr == NULL || !is_valid_req_type(req_type) || is_locked == NULL) {
378 *is_locked = request_sources_is_locked(pwrmgr, req_type);
394 PWRMGR_WAKE_INFO_CAPTURE_DIS_REG_OFFSET, reg_val);
401 if (pwrmgr == NULL || cur_state == NULL) {
405 uint32_t reg_val = mmio_region_read32(
406 pwrmgr->
base_addr, PWRMGR_WAKE_INFO_CAPTURE_DIS_REG_OFFSET);
416 if (pwrmgr == NULL || reason == NULL) {
421 mmio_region_read32(pwrmgr->
base_addr, PWRMGR_WAKE_INFO_REG_OFFSET);
433 if (request_sources != 0) {
439 .request_sources = request_sources,
446 if (pwrmgr == NULL) {
450 mmio_region_write32(pwrmgr->
base_addr, PWRMGR_WAKE_INFO_REG_OFFSET,
458 if (pwrmgr == NULL || codes == NULL) {
462 mmio_region_read32(pwrmgr->
base_addr, PWRMGR_FAULT_STATUS_REG_OFFSET);