fix(phy): add fe dependency when enable rf with regdma

This commit is contained in:
cjin
2026-07-29 09:59:38 +08:00
parent e90bd169d4
commit 74b9e617d5
4 changed files with 67 additions and 19 deletions

View File

@@ -30,6 +30,17 @@ typedef struct {
#define RETENTION_MODULE_BITMAP_INIT(module) { .bitmap[(SLEEP_RETENTION_MODULE_ ## module) >> 5] = BIT((SLEEP_RETENTION_MODULE_ ## module) % 32) }
uint32_t bitmap[SLEEP_RETENTION_MODULE_BITMAP_SZ];
} sleep_retention_module_bitmap_t;
/**
* @brief Set a bit in the retention module bitmap
*
* @param bitmap_ptr Pointer to the bitmap structure
* @param module Module number (e.g., SLEEP_RETENTION_MODULE_SYS_PERIPH)
*/
#define RETENTION_MODULE_BITMAP_SET(bitmap_ptr, module) \
do { \
(bitmap_ptr)->bitmap[(module) >> 5] |= BIT((module) % 32); \
} while (0)
typedef regdma_entry_buf_t sleep_retention_entries_t;
typedef regdma_entries_config_t sleep_retention_entries_config_t;

View File

@@ -148,12 +148,15 @@ const esp_phy_init_data_t phy_init_data= { {
const char __attribute__((section(".rodata"))) phy_init_magic_post[] = PHY_INIT_MAGIC;
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && (CONFIG_MAC_BB_PD || CONFIG_ESP_PHY_HW_SWITCH_RF)
#include "esp_private/sleep_retention.h"
static const char* TAG = "phy_sleep";
static _lock_t s_phy_fe_retention_lock;
uint8_t s_phy_fe_retention_ref = 0;
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && (CONFIG_MAC_BB_PD || CONFIG_ESP_PHY_HW_SWITCH_RF)
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
static esp_err_t sleep_retention_wifi_bb_init(void *arg)
{
#define N_REGS_WIFI_AGC() (121)
@@ -204,7 +207,9 @@ void esp_phy_sleep_data_deinit(void)
ESP_LOGW(TAG, "WiFi BB sleep retention deinit failed");
}
}
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && (CONFIG_MAC_BB_PD || CONFIG_ESP_PHY_HW_SWITCH_RF)
static esp_err_t sleep_retention_phy_fe_init(void *arg)
{
#define N_REGS_FE_COEX() (58)
@@ -219,25 +224,40 @@ static esp_err_t sleep_retention_phy_fe_init(void *arg)
return ESP_OK;
}
void esp_phy_fe_sleep_data_init(void)
esp_err_t esp_phy_fe_sleep_data_init(void)
{
sleep_retention_module_init_param_t init_param = {
.cbs = { .create = { .handle = sleep_retention_phy_fe_init, .arg = NULL } },
.attribute = SLEEP_RETENTION_MODULE_ATTR_PASSIVE | SLEEP_RETENTION_MODULE_ATTR_ATTACH
};
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_PHY_FE, &init_param);
if (err != ESP_OK) {
ESP_LOGW(TAG, "PHY FE sleep retention init failed");
return;
_lock_acquire(&s_phy_fe_retention_lock);
if (s_phy_fe_retention_ref++ == 0) {
sleep_retention_module_init_param_t init_param = {
.cbs = { .create = { .handle = sleep_retention_phy_fe_init, .arg = NULL } },
.attribute = SLEEP_RETENTION_MODULE_ATTR_PASSIVE
};
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_PHY_FE, &init_param);
if (err != ESP_OK) {
ESP_LOGW(TAG, "PHY FE sleep retention init failed");
s_phy_fe_retention_ref --;
_lock_release(&s_phy_fe_retention_lock);
return err;
}
}
_lock_release(&s_phy_fe_retention_lock);
return ESP_OK;
}
void esp_phy_fe_sleep_data_deinit(void)
{
esp_err_t err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_PHY_FE);
if (err != ESP_OK) {
ESP_LOGW(TAG, "PHY FE sleep retention deinit failed");
_lock_acquire(&s_phy_fe_retention_lock);
if (s_phy_fe_retention_ref == 0) {
_lock_release(&s_phy_fe_retention_lock);
return;
}
if (--s_phy_fe_retention_ref == 0) {
esp_err_t err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_PHY_FE);
if (err != ESP_OK) {
ESP_LOGW(TAG, "PHY FE sleep retention deinit failed");
}
}
_lock_release(&s_phy_fe_retention_lock);
}
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && (CONFIG_MAC_BB_PD || CONFIG_ESP_PHY_HW_SWITCH_RF)

View File

@@ -281,19 +281,19 @@ void phy_wait_freq_hw_hop_done(void);
*/
void phy_track_temp_debug(uint8_t debug_flag, uint8_t track_temp);
#endif
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && (CONFIG_MAC_BB_PD || CONFIG_ESP_PHY_HW_SWITCH_RF)
/**
* @brief PHY module common memory (FE) initialize
*
*/
void esp_phy_fe_sleep_data_init(void);
esp_err_t esp_phy_fe_sleep_data_init(void);
/**
* @brief PHY module common memory (FE) de-initialize
*
*/
void esp_phy_fe_sleep_data_deinit(void);
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && (CONFIG_MAC_BB_PD || CONFIG_ESP_PHY_HW_SWITCH_RF)
#ifdef __cplusplus
}

View File

@@ -67,14 +67,28 @@ void esp_btbb_enable(void)
if (s_btbb_access_ref == 0) {
bt_bb_v2_init_cmplx(BTBB_ENABLE_VERSION_PRINT);
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
esp_err_t err = ESP_OK;
#if CONFIG_ESP_PHY_HW_SWITCH_RF
err = esp_phy_fe_sleep_data_init();
if (err != ESP_OK) {
_lock_release(&s_btbb_access_lock);
return;
}
#endif // CONFIG_ESP_PHY_HW_SWITCH_RF
sleep_retention_module_init_param_t init_param = {
.cbs = { .create = { .handle = btbb_sleep_retention_init, .arg = NULL } },
.depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM)
};
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BT_BB, &init_param);
#if CONFIG_ESP_PHY_HW_SWITCH_RF
init_param.depends.bitmap[SLEEP_RETENTION_MODULE_PHY_FE >> 5] |= BIT(SLEEP_RETENTION_MODULE_PHY_FE % 32);
#endif // CONFIG_ESP_PHY_HW_SWITCH_RF
err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BT_BB, &init_param);
if (err == ESP_OK) {
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_BT_BB);
if (err != ESP_OK) {
#if CONFIG_ESP_PHY_HW_SWITCH_RF
esp_phy_fe_sleep_data_deinit();
#endif // CONFIG_ESP_PHY_HW_SWITCH_RF
ESP_LOGW(TAG, "failed to allocate sleep retention linked list for btbb retention");
}
} else {
@@ -92,6 +106,9 @@ void esp_btbb_disable(void)
if (s_btbb_access_ref && (--s_btbb_access_ref == 0)) {
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
btbb_sleep_retention_deinit();
#if CONFIG_ESP_PHY_HW_SWITCH_RF
esp_phy_fe_sleep_data_deinit();
#endif // CONFIG_ESP_PHY_HW_SWITCH_RF
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
}
_lock_release(&s_btbb_access_lock);