Skip to content

Commit 2d105c4

Browse files
committed
[silicon_creator,pwrmgr] Create method to enable watchdog reset
Currently the library exports a very generic method to search for a bitmask in the DT and it requires users to manually poke at the pwrmgr registers. This is not really in the spirit of the silicon_creator libraries and it can be misused. This commit makes the search function internal and create a specific method to enable the watch reset request, which is the only user currently. Signed-off-by: Amaury Pouly <[email protected]>
1 parent 815779e commit 2d105c4

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

sw/device/silicon_creator/lib/drivers/pwrmgr.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "sw/device/silicon_creator/lib/drivers/pwrmgr.h"
66

7+
#include "hw/top/dt/dt_aon_timer.h"
78
#include "hw/top/dt/dt_api.h"
89
#include "hw/top/dt/dt_pwrmgr.h"
910
#include "sw/device/lib/base/abs_mmio.h"
@@ -21,6 +22,29 @@ enum {
2122
kSyncConfig = (1 << PWRMGR_CFG_CDC_SYNC_SYNC_BIT),
2223
};
2324

25+
/**
26+
* A power manager request type.
27+
*/
28+
typedef enum pwrmgr_req_type {
29+
kPwrmgrReqTypeWakeup,
30+
kPwrmgrReqTypeReset,
31+
} pwr_mgr_req_type_t;
32+
33+
/**
34+
* Obtain a bit index of wakeup/reset request for a device and a signal.
35+
*
36+
* Given a module instance (identified by its instance ID) and a wakeup
37+
* or reset request index from this module, return the source bit index
38+
* that, once shifted into a bitmask, can be programmed into the pwrmgr
39+
* `RESET_EN` register.
40+
*
41+
* @param req_type Request type (wake up or reset request).
42+
* @param inst_id A DT instance ID.
43+
* @param signal_idx Signal index.
44+
* @param[out] source_idx The source index corresponding to the wakeup or reset
45+
* requested.
46+
* @return `kErrorOk` if a signal matches, or a `kErrorPwrmgr` error otherwise.
47+
*/
2448
OT_WARN_UNUSED_RESULT
2549
rom_error_t pwrmgr_find_request_source(pwr_mgr_req_type_t req_type,
2650
dt_instance_id_t inst_id,
@@ -50,6 +74,22 @@ rom_error_t pwrmgr_find_request_source(pwr_mgr_req_type_t req_type,
5074
}
5175
}
5276

77+
void pwrmgr_enable_watchdog_reset_request(void) {
78+
uint32_t pwrmgr_base = dt_pwrmgr_primary_reg_block(kDtPwrmgrAon);
79+
uint32_t enabled_resets = 0;
80+
size_t reset_source = 0;
81+
82+
// Tell pwrmgr we want watchdog reset events to reset the chip.
83+
HARDENED_CHECK_EQ(
84+
pwrmgr_find_request_source(kPwrmgrReqTypeReset,
85+
dt_aon_timer_instance_id(kDtAonTimerAon),
86+
kDtAonTimerResetReqAonTimer, &reset_source),
87+
kErrorOk);
88+
enabled_resets = bitfield_bit32_write(0, reset_source, true);
89+
sec_mmio_write32(pwrmgr_base + PWRMGR_RESET_EN_REG_OFFSET, enabled_resets);
90+
pwrmgr_cdc_sync(1);
91+
}
92+
5393
void pwrmgr_cdc_sync(uint32_t n) {
5494
// We want to timeout if the CDC bit doesn't self clear. It should take
5595
// approximately 4 AON ticks to complete. We wait 25% longer (5 ticks).

sw/device/silicon_creator/lib/drivers/pwrmgr.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,9 @@ enum {
3131
};
3232

3333
/**
34-
* A power manager request type.
34+
* Enable the watchdog reset request so that the watchdog can reset the chip.
3535
*/
36-
typedef enum pwrmgr_req_type {
37-
kPwrmgrReqTypeWakeup,
38-
kPwrmgrReqTypeReset,
39-
} pwr_mgr_req_type_t;
40-
41-
/**
42-
* Obtain a bit index of wakeup/reset request for a device and a signal.
43-
*
44-
* Given a module instance (identified by its instance ID) and a wakeup
45-
* or reset request index from this module, return the source bit index
46-
* that, once shifted into a bitmask, can be programmed into the pwrmgr
47-
* `RESET_EN` register.
48-
*
49-
* @param req_type Request type (wake up or reset request).
50-
* @param inst_id A DT instance ID.
51-
* @param signal_idx Signal index.
52-
* @param[out] source_idx The source index corresponding to the wakeup or reset
53-
* requested.
54-
* @return `kErrorOk` if a signal matches, or a `kErrorPwrmgr` error otherwise.
55-
*/
56-
OT_WARN_UNUSED_RESULT
57-
rom_error_t pwrmgr_find_request_source(pwr_mgr_req_type_t req_type,
58-
dt_instance_id_t inst_id,
59-
size_t signal_idx, size_t *source_idx);
36+
void pwrmgr_enable_watchdog_reset_request(void);
6037

6138
/**
6239
* Synchronize across clock domain.

sw/device/silicon_creator/lib/drivers/watchdog.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "hw/top/dt/dt_aon_timer.h"
88
#include "hw/top/dt/dt_api.h"
9-
#include "hw/top/dt/dt_pwrmgr.h"
109
#include "sw/device/lib/base/abs_mmio.h"
1110
#include "sw/device/silicon_creator/lib/base/sec_mmio.h"
1211
#include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
@@ -75,19 +74,7 @@ void watchdog_init(lifecycle_state_t lc_state) {
7574

7675
void watchdog_configure(watchdog_config_t config) {
7776
SEC_MMIO_ASSERT_WRITE_INCREMENT(kWatchdogSecMmioConfigure, 4);
78-
uint32_t pwrmgr_base = dt_pwrmgr_primary_reg_block(kDtPwrmgrAon);
79-
uint32_t enabled_resets = 0;
80-
size_t reset_source = 0;
81-
82-
// Tell pwrmgr we want watchdog reset events to reset the chip.
83-
HARDENED_CHECK_EQ(
84-
pwrmgr_find_request_source(kPwrmgrReqTypeReset,
85-
dt_aon_timer_instance_id(kDtAonTimerAon),
86-
kDtAonTimerResetReqAonTimer, &reset_source),
87-
kErrorOk);
88-
enabled_resets = bitfield_bit32_write(0, reset_source, true);
89-
sec_mmio_write32(pwrmgr_base + PWRMGR_RESET_EN_REG_OFFSET, enabled_resets);
90-
pwrmgr_cdc_sync(1);
77+
pwrmgr_enable_watchdog_reset_request();
9178

9279
// Set the watchdog bite and bark thresholds.
9380
sec_mmio_write32(aon_timer_base() + AON_TIMER_WDOG_CTRL_REG_OFFSET,

0 commit comments

Comments
 (0)