diff --git a/components/esp_hw_support/include/esp_private/esp_regdma.h b/components/esp_hw_support/include/esp_private/esp_regdma.h index 3cd96a0a4b..a74fc6746b 100644 --- a/components/esp_hw_support/include/esp_private/esp_regdma.h +++ b/components/esp_hw_support/include/esp_private/esp_regdma.h @@ -536,6 +536,13 @@ void *regdma_link_new_branch_wait_default(void *backup, uint32_t value, uint32_t */ void *regdma_link_init(const regdma_link_config_t *config, bool branch, uint32_t module, int nentry, ...); +/** + * @brief Get REGDMA linked list node mode through configuration parameters + * @param config REGDMA linked node configuration parameters + * @return REGDMA linked list node mode + */ +regdma_link_mode_t regdma_link_get_config_mode(const regdma_link_config_t *config); + /** * @brief Recurse the REGDMA linked list and call the hook subroutine for each node * @param link The REGDMA linkded list head pointer diff --git a/components/esp_hw_support/port/regdma_link.c b/components/esp_hw_support/port/regdma_link.c index e1df99c925..25fcfc2345 100644 --- a/components/esp_hw_support/port/regdma_link.c +++ b/components/esp_hw_support/port/regdma_link.c @@ -710,6 +710,12 @@ void * regdma_find_prev_module_link_tail(void *link, void *tail, int entry, uint return NULL; } +regdma_link_mode_t regdma_link_get_config_mode(const regdma_link_config_t *config) +{ + assert(config != NULL); + return (regdma_link_mode_t)config->head.mode; +} + #if REGDMA_LINK_DBG static __attribute__((unused)) const char *TAG = "regdma_link"; diff --git a/components/esp_hw_support/sleep_retention.c b/components/esp_hw_support/sleep_retention.c index c7b88c648a..427c0a88f9 100644 --- a/components/esp_hw_support/sleep_retention.c +++ b/components/esp_hw_support/sleep_retention.c @@ -21,6 +21,10 @@ #include "sdkconfig.h" #include "esp_pmu.h" +#if SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE +#include "soc/pmu_reg.h" // for PMU_DATE_REG, it can provide full 32 bit read and write access +#endif + static __attribute__((unused)) const char *TAG = "sleep"; struct sleep_retention_module_object { @@ -474,8 +478,9 @@ static void sleep_retention_entries_destroy(sleep_retention_module_t module) static esp_err_t sleep_retention_entries_create_impl(const sleep_retention_entries_config_t retent[], int num, regdma_link_priority_t priority, sleep_retention_module_t module) { + esp_err_t err = ESP_OK; _lock_acquire_recursive(&s_retention.lock); - for (int i = num - 1; i >= 0; i--) { + for (int i = num - 1; (i >= 0) && (err == ESP_OK); i--) { #if SOC_PM_RETENTION_HAS_CLOCK_BUG if ((retent[i].owner > BIT(EXTRA_LINK_NUM)) && (retent[i].config.id != 0xffff)) { _lock_release_recursive(&s_retention.lock); @@ -483,16 +488,40 @@ static esp_err_t sleep_retention_entries_create_impl(const sleep_retention_entri return ESP_ERR_NOT_SUPPORTED; } #endif - void *link = sleep_retention_entries_try_create(&retent[i].config, retent[i].owner, priority, module); - if (link == NULL) { - _lock_release_recursive(&s_retention.lock); - sleep_retention_entries_do_destroy(module); - return ESP_ERR_NO_MEM; +#if SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE + /* There is a bug in REGDMA wait mode, when two wait nodes need to wait for the + * same value (_val & _mask), the second wait node will immediately return to + * wait done, The reason is that the wait mode comparison output logic immediate + * compares the value of the previous wait register cached inside the + * digital logic before reading out he register contents specified by _backup. + */ + #define config_is_wait_mode(_config) (regdma_link_get_config_mode(_config) == REGDMA_LINK_MODE_WAIT) + if ((retent[i].config.id != 0xffff) && config_is_wait_mode(&(retent[i].config)) && (retent[i].config.id != 0xfffe)) { + uint32_t value = retent[i].config.write_wait.value; + uint32_t mask = retent[i].config.write_wait.mask; + bool skip_b = retent[i].config.head.skip_b; + bool skip_r = retent[i].config.head.skip_r; + sleep_retention_entries_config_t wait_bug_workaround[] = { + [0] = { .config = REGDMA_LINK_WRITE_INIT(0xfffe, PMU_DATE_REG, ~value, mask, skip_b, skip_r), .owner = retent[i].owner }, + [1] = { .config = REGDMA_LINK_WAIT_INIT (0xfffe, PMU_DATE_REG, ~value, mask, skip_b, skip_r), .owner = retent[i].owner } + }; + err = sleep_retention_entries_create_impl(wait_bug_workaround, ARRAY_SIZE(wait_bug_workaround), priority, module); + } +#endif + if (err == ESP_OK) { + void *link = sleep_retention_entries_try_create(&retent[i].config, retent[i].owner, priority, module); + if (link == NULL) { + _lock_release_recursive(&s_retention.lock); + sleep_retention_entries_do_destroy(module); + return ESP_ERR_NO_MEM; + } + sleep_retention_entries_update(retent[i].owner, link, priority); + } else { + break; } - sleep_retention_entries_update(retent[i].owner, link, priority); } _lock_release_recursive(&s_retention.lock); - return ESP_OK; + return err; } static esp_err_t sleep_retention_entries_create_bonding(regdma_link_priority_t priority, sleep_retention_module_t module) diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 3077fa5e15..2255ccfa45 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -1191,6 +1191,10 @@ config SOC_PM_PAU_LINK_NUM int default 4 +config SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE + bool + default y + config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index 270078fb34..05440c48e3 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -498,6 +498,8 @@ #define SOC_PM_PAU_LINK_NUM (4) +#define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) + /*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/ #define SOC_CLK_RC_FAST_SUPPORT_CALIBRATION (1) #define SOC_MODEM_CLOCK_IS_INDEPENDENT (1) diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index bf03f79b4a..087c0e4283 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -1147,6 +1147,10 @@ config SOC_PM_CPU_RETENTION_BY_SW bool default y +config SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE + bool + default y + config SOC_PM_MODEM_RETENTION_BY_REGDMA bool default y diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index e46dabc2e4..710b286ce2 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -473,6 +473,9 @@ #define SOC_PM_SUPPORT_TOP_PD (1) #define SOC_PM_PAU_LINK_NUM (4) #define SOC_PM_CPU_RETENTION_BY_SW (1) + +#define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) + #define SOC_PM_MODEM_RETENTION_BY_REGDMA (1) #define SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY (1) /*!