Skip to content

Commit 7675456

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'bugfix/esp32c5_eco1_wifi_ps' into 'master'
fix some wifi power save issues and optimize phy sleep for esp32c5 eco1 and beta5 Closes PM-306, PM-319, PM-320, PM-296, PM-308, PM-311, PM-310, PM-309, PM-295, PM-274, PM-271, IDFCI-2604, and IDFCI-2605 See merge request espressif/esp-idf!35093
2 parents d75ca96 + 84ecd39 commit 7675456

File tree

24 files changed

+294
-76
lines changed

24 files changed

+294
-76
lines changed

components/esp_hw_support/port/esp32c5/private_include/pmu_param.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ typedef struct pmu_sleep_machine_constant {
438438
} lp;
439439
struct {
440440
uint16_t min_slp_time_us; /* Minimum sleep protection time (unit: microsecond) */
441-
uint16_t clock_domain_sync_time_us; /* The Slow OSC clock domain synchronizes time with the Fast OSC domain, at least 4 slow clock cycles (unit: microsecond) */
441+
uint16_t clock_domain_sync_time_us; /* Synchronizing the rtc clock timer to modem system requires at least 1 us (unit: microsecond) */
442442
uint16_t system_dfs_up_work_time_us; /* System DFS up scaling work time (unit: microsecond) */
443443
uint16_t analog_wait_time_us; /* HP LDO power up wait time (unit: microsecond) */
444444
uint8_t isolate_wait_time_us; /* Waiting for all isolate signals to be ready (unit: microsecond) */
@@ -471,19 +471,19 @@ typedef struct pmu_sleep_machine_constant {
471471
}, \
472472
.hp = { \
473473
.min_slp_time_us = 450, \
474-
.clock_domain_sync_time_us = 150, \
474+
.clock_domain_sync_time_us = 2, \
475475
.system_dfs_up_work_time_us = 124, \
476476
.analog_wait_time_us = 154, \
477477
.isolate_wait_time_us = 1, \
478478
.reset_wait_time_us = 1, \
479479
.power_supply_wait_time_us = 2, \
480480
.power_up_wait_time_us = 2, \
481-
.regdma_s2m_work_time_us = 172, \
482-
.regdma_s2a_work_time_us = 480, \
483-
.regdma_m2a_work_time_us = 278, \
484-
.regdma_a2s_work_time_us = 382, \
485-
.regdma_rf_on_work_time_us = 70, \
486-
.regdma_rf_off_work_time_us = 23, \
481+
.regdma_s2m_work_time_us = 275, \
482+
.regdma_s2a_work_time_us = 587, \
483+
.regdma_m2a_work_time_us = 320, \
484+
.regdma_a2s_work_time_us = 494, \
485+
.regdma_rf_on_work_time_us = 60, \
486+
.regdma_rf_off_work_time_us = 25, \
487487
.xtal_wait_stable_time_us = 250, \
488488
.pll_wait_stable_time_us = 300 \
489489
} \

components/esp_hw_support/sleep_modes.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ FORCE_INLINE_ATTR void misc_modules_sleep_prepare(uint32_t pd_flags, bool deep_s
674674
}
675675
#endif
676676
#if CONFIG_MAC_BB_PD
677+
# if CONFIG_IDF_TARGET_ESP32C5
678+
clk_ll_soc_root_clk_auto_gating_bypass(false);
679+
# endif
677680
mac_bb_power_down_cb_execute();
678681
#endif
679682
#if CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL
@@ -736,6 +739,9 @@ FORCE_INLINE_ATTR void misc_modules_wake_prepare(uint32_t pd_flags)
736739
#endif
737740
#if CONFIG_MAC_BB_PD
738741
mac_bb_power_up_cb_execute();
742+
# if CONFIG_IDF_TARGET_ESP32C5
743+
clk_ll_soc_root_clk_auto_gating_bypass(true);
744+
# endif
739745
#endif
740746
#if REGI2C_ANA_CALI_PD_WORKAROUND
741747
regi2c_analog_cali_reg_write();

components/esp_phy/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ if(CONFIG_ESP_PHY_ENABLED)
101101

102102
if(CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION)
103103
idf_component_get_property(esp_common_dir esp_common COMPONENT_DIR)
104+
idf_component_get_property(esp_rom_dir esp_rom COMPONENT_DIR)
105+
idf_component_get_property(newlib_dir newlib COMPONENT_DIR)
106+
idf_component_get_property(soc_dir soc COMPONENT_DIR)
107+
idf_component_get_property(log_dir log COMPONENT_DIR)
104108
partition_table_get_partition_info(phy_partition_offset
105109
"--partition-type data --partition-subtype phy" "offset")
106110

@@ -118,8 +122,9 @@ if(CONFIG_ESP_PHY_ENABLED)
118122
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/phy_init_data.c
119123
COMMAND ${CMAKE_C_COMPILER} -c ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/phy_init_data.c
120124
-I ${esp_common_dir}/include -I ${CMAKE_CURRENT_LIST_DIR}/include
121-
-I ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include
122-
-I ${config_dir} -o phy_init_data.obj
125+
-I ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include -I ${esp_rom_dir}/include
126+
-I ${soc_dir}/${idf_target}/include -I ${newlib_dir}/platform_include
127+
-I ${log_dir}/include -I ${config_dir} -o phy_init_data.obj
123128
COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${phy_init_data_bin}
124129
)
125130
add_custom_target(phy_init_data ALL DEPENDS ${phy_init_data_bin})

components/esp_phy/esp32c5/phy_init_data.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66

77
#include "sdkconfig.h"
8+
#include "soc/soc_caps.h"
89
#include "phy_init_data.h"
10+
#include "esp_private/phy.h"
11+
#include "esp_check.h"
912

1013

1114
const char __attribute__((section(".rodata"))) phy_init_magic_pre[] = PHY_INIT_MAGIC;
@@ -273,3 +276,69 @@ const esp_phy_init_data_t phy_init_data= { {
273276
} };
274277

275278
const char __attribute__((section(".rodata"))) phy_init_magic_post[] = PHY_INIT_MAGIC;
279+
280+
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
281+
282+
#include "esp_private/sleep_retention.h"
283+
284+
static const char* TAG = "phy_sleep";
285+
286+
static esp_err_t sleep_retention_wifi_bb_init(void *arg)
287+
{
288+
#define N_REGS_WIFI_AGC() (126)
289+
#define N_REGS_WIFI_TX() (20)
290+
#define N_REGS_WIFI_NRX() (141)
291+
#define N_REGS_WIFI_BB() (63)
292+
#define N_REGS_WIFI_BRX() (39)
293+
#define N_REGS_WIFI_FE_COEX() (19)
294+
#define N_REGS_WIFI_FE_DATA() (31)
295+
#define N_REGS_WIFI_FE_CTRL() (55)
296+
297+
const static sleep_retention_entries_config_t bb_regs_retention[] = {
298+
[0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b00, 0x600a7000, 0x600a7000, N_REGS_WIFI_AGC(), 0, 0), .owner = BIT(0) | BIT(1) }, /* AGC */
299+
[1] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b01, 0x600a7400, 0x600a7400, N_REGS_WIFI_TX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* TX */
300+
[2] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b02, 0x600a7800, 0x600a7800, N_REGS_WIFI_NRX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* NRX */
301+
[3] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b03, 0x600a7c00, 0x600a7c00, N_REGS_WIFI_BB(), 0, 0), .owner = BIT(0) | BIT(1) }, /* BB */
302+
[4] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b05, 0x600a0000, 0x600a0000, N_REGS_WIFI_FE_COEX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* FE COEX */
303+
[5] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b06, 0x600a8000, 0x600a8000, N_REGS_WIFI_BRX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* BRX */
304+
[6] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b07, 0x600a0400, 0x600a0400, N_REGS_WIFI_FE_DATA(), 0, 0), .owner = BIT(0) | BIT(1) }, /* FE DATA */
305+
[7] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b08, 0x600a0800, 0x600a0800, N_REGS_WIFI_FE_CTRL(), 0, 0), .owner = BIT(0) | BIT(1) }, /* FE CTRL */
306+
[8] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b09, 0x600a0c00, 0x600a0c00, 20, 0, 0), .owner = BIT(0) | BIT(1) } /* FE WIFI DATA */
307+
};
308+
esp_err_t err = sleep_retention_entries_create(bb_regs_retention, ARRAY_SIZE(bb_regs_retention), 3, SLEEP_RETENTION_MODULE_WIFI_BB);
309+
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for modem (%s) retention", "WiFi BB");
310+
ESP_LOGD(TAG, "WiFi BB sleep retention initialization");
311+
return ESP_OK;
312+
}
313+
314+
void esp_phy_sleep_data_init(void)
315+
{
316+
sleep_retention_module_init_param_t init_param = {
317+
.cbs = { .create = { .handle = sleep_retention_wifi_bb_init, .arg = NULL } },
318+
.depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM)
319+
};
320+
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_WIFI_BB, &init_param);
321+
if (err != ESP_OK) {
322+
ESP_LOGW(TAG, "WiFi BB sleep retention init failed");
323+
return;
324+
}
325+
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_WIFI_BB);
326+
if (err != ESP_OK) {
327+
ESP_LOGW(TAG, "failed to allocate sleep retention linked list for wifi bb retention");
328+
}
329+
}
330+
331+
void esp_phy_sleep_data_deinit(void)
332+
{
333+
esp_err_t err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_WIFI_BB);
334+
if (err != ESP_OK) {
335+
ESP_LOGW(TAG, "failed to free sleep retention linked list for wifi bb retention");
336+
return;
337+
}
338+
err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_WIFI_BB);
339+
if (err != ESP_OK) {
340+
ESP_LOGW(TAG, "WiFi BB sleep retention deinit failed");
341+
}
342+
}
343+
344+
#endif /* SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD */

components/esp_phy/esp32c6/phy_init_data.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66

77
#include "sdkconfig.h"
8+
#include "soc/soc_caps.h"
89
#include "phy_init_data.h"
10+
#include "esp_private/phy.h"
11+
#include "esp_check.h"
912

1013
const char __attribute__((section(".rodata"))) phy_init_magic_pre[] = PHY_INIT_MAGIC;
1114

@@ -144,3 +147,63 @@ const esp_phy_init_data_t phy_init_data= { {
144147
} };
145148

146149
const char __attribute__((section(".rodata"))) phy_init_magic_post[] = PHY_INIT_MAGIC;
150+
151+
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
152+
153+
#include "esp_private/sleep_retention.h"
154+
155+
static const char* TAG = "phy_sleep";
156+
157+
static esp_err_t sleep_retention_wifi_bb_init(void *arg)
158+
{
159+
#define N_REGS_WIFI_AGC() (121)
160+
#define N_REGS_WIFI_TX() (14)
161+
#define N_REGS_WIFI_NRX() (136)
162+
#define N_REGS_WIFI_BB() (53)
163+
#define N_REGS_WIFI_BRX() (39)
164+
#define N_REGS_WIFI_FE_COEX() (58)
165+
166+
const static sleep_retention_entries_config_t bb_regs_retention[] = {
167+
[0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b00, 0x600a7000, 0x600a7000, N_REGS_WIFI_AGC(), 0, 0), .owner = BIT(0) | BIT(1) }, /* AGC */
168+
[1] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b01, 0x600a7400, 0x600a7400, N_REGS_WIFI_TX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* TX */
169+
[2] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b02, 0x600a7800, 0x600a7800, N_REGS_WIFI_NRX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* NRX */
170+
[3] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b03, 0x600a7c00, 0x600a7c00, N_REGS_WIFI_BB(), 0, 0), .owner = BIT(0) | BIT(1) }, /* BB */
171+
[4] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b05, 0x600a0000, 0x600a0000, N_REGS_WIFI_FE_COEX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* FE COEX */
172+
};
173+
esp_err_t err = sleep_retention_entries_create(bb_regs_retention, ARRAY_SIZE(bb_regs_retention), 3, SLEEP_RETENTION_MODULE_WIFI_BB);
174+
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for modem (%s) retention", "WiFi BB");
175+
ESP_LOGD(TAG, "WiFi BB sleep retention initialization");
176+
return ESP_OK;
177+
}
178+
179+
void esp_phy_sleep_data_init(void)
180+
{
181+
sleep_retention_module_init_param_t init_param = {
182+
.cbs = { .create = { .handle = sleep_retention_wifi_bb_init, .arg = NULL } },
183+
.depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM)
184+
};
185+
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_WIFI_BB, &init_param);
186+
if (err != ESP_OK) {
187+
ESP_LOGW(TAG, "WiFi BB sleep retention init failed");
188+
return;
189+
}
190+
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_WIFI_BB);
191+
if (err != ESP_OK) {
192+
ESP_LOGW(TAG, "failed to allocate sleep retention linked list for wifi bb retention");
193+
}
194+
}
195+
196+
void esp_phy_sleep_data_deinit(void)
197+
{
198+
esp_err_t err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_WIFI_BB);
199+
if (err != ESP_OK) {
200+
ESP_LOGW(TAG, "failed to free sleep retention linked list for wifi bb retention");
201+
return;
202+
}
203+
err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_WIFI_BB);
204+
if (err != ESP_OK) {
205+
ESP_LOGW(TAG, "WiFi BB sleep retention deinit failed");
206+
}
207+
}
208+
209+
#endif /* SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD */

components/esp_phy/esp32c61/phy_init_data.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66

77
#include "sdkconfig.h"
8+
#include "soc/soc_caps.h"
89
#include "phy_init_data.h"
10+
#include "esp_private/phy.h"
11+
#include "esp_check.h"
912

1013

1114
const char __attribute__((section(".rodata"))) phy_init_magic_pre[] = PHY_INIT_MAGIC;
@@ -145,3 +148,68 @@ const esp_phy_init_data_t phy_init_data= { {
145148
} };
146149

147150
const char __attribute__((section(".rodata"))) phy_init_magic_post[] = PHY_INIT_MAGIC;
151+
152+
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
153+
154+
#include "esp_private/sleep_retention.h"
155+
156+
static const char* TAG = "phy_sleep";
157+
158+
static esp_err_t sleep_retention_wifi_bb_init(void *arg)
159+
{
160+
#define N_REGS_WIFI_AGC() (121)
161+
#define N_REGS_WIFI_TX() (14)
162+
#define N_REGS_WIFI_NRX() (136)
163+
#define N_REGS_WIFI_BB() (53)
164+
#define N_REGS_WIFI_BRX() (39)
165+
#define N_REGS_WIFI_FE_COEX() (58)
166+
#define N_REGS_WIFI_FE_DATA() (41)
167+
#define N_REGS_WIFI_FE_CTRL() (87)
168+
169+
const static sleep_retention_entries_config_t bb_regs_retention[] = {
170+
[0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b00, 0x600a7000, 0x600a7000, N_REGS_WIFI_AGC(), 0, 0), .owner = BIT(0) | BIT(1) }, /* AGC */
171+
[1] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b01, 0x600a7400, 0x600a7400, N_REGS_WIFI_TX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* TX */
172+
[2] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b02, 0x600a7800, 0x600a7800, N_REGS_WIFI_NRX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* NRX */
173+
[3] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b03, 0x600a7c00, 0x600a7c00, N_REGS_WIFI_BB(), 0, 0), .owner = BIT(0) | BIT(1) }, /* BB */
174+
[4] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b05, 0x600a0000, 0x600a0000, N_REGS_WIFI_FE_COEX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* FE COEX */
175+
[5] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b06, 0x600a8000, 0x600a8000, N_REGS_WIFI_BRX(), 0, 0), .owner = BIT(0) | BIT(1) }, /* BRX */
176+
[6] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b07, 0x600a0400, 0x600a0400, N_REGS_WIFI_FE_DATA(), 0, 0), .owner = BIT(0) | BIT(1) }, /* FE DATA */
177+
[7] = { .config = REGDMA_LINK_CONTINUOUS_INIT(0x0b08, 0x600a0800, 0x600a0800, N_REGS_WIFI_FE_CTRL(), 0, 0), .owner = BIT(0) | BIT(1) }, /* FE CTRL */
178+
};
179+
esp_err_t err = sleep_retention_entries_create(bb_regs_retention, ARRAY_SIZE(bb_regs_retention), 3, SLEEP_RETENTION_MODULE_WIFI_BB);
180+
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for modem (%s) retention", "WiFi BB");
181+
ESP_LOGD(TAG, "WiFi BB sleep retention initialization");
182+
return ESP_OK;
183+
}
184+
185+
void esp_phy_sleep_data_init(void)
186+
{
187+
sleep_retention_module_init_param_t init_param = {
188+
.cbs = { .create = { .handle = sleep_retention_wifi_bb_init, .arg = NULL } },
189+
.depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM)
190+
};
191+
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_WIFI_BB, &init_param);
192+
if (err != ESP_OK) {
193+
ESP_LOGW(TAG, "WiFi BB sleep retention init failed");
194+
return;
195+
}
196+
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_WIFI_BB);
197+
if (err != ESP_OK) {
198+
ESP_LOGW(TAG, "failed to allocate sleep retention linked list for wifi bb retention");
199+
}
200+
}
201+
202+
void esp_phy_sleep_data_deinit(void)
203+
{
204+
esp_err_t err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_WIFI_BB);
205+
if (err != ESP_OK) {
206+
ESP_LOGW(TAG, "failed to free sleep retention linked list for wifi bb retention");
207+
return;
208+
}
209+
err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_WIFI_BB);
210+
if (err != ESP_OK) {
211+
ESP_LOGW(TAG, "WiFi BB sleep retention deinit failed");
212+
}
213+
}
214+
215+
#endif /* SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD */

components/esp_phy/include/esp_private/phy.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <sys/lock.h>
99
#include "sdkconfig.h"
1010
#include "esp_phy_init.h"
11+
#include "soc/soc_caps.h"
1112

1213
#ifdef __cplusplus
1314
extern "C" {
@@ -243,6 +244,18 @@ uint32_t phy_ana_i2c_master_burst_rf_onoff(bool on);
243244
void phy_wakeup_from_modem_state_extra_init(void);
244245
#endif
245246

247+
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
248+
/**
249+
* @brief PHY module sleep data (includes AGC, TX, NRX, BB, FE, etc..) initialize.
250+
*/
251+
void esp_phy_sleep_data_init(void);
252+
253+
/**
254+
* @brief PHY module sleep data de-initialize.
255+
*/
256+
void esp_phy_sleep_data_deinit(void);
257+
#endif
258+
246259
#ifdef __cplusplus
247260
}
248261
#endif

components/esp_phy/linker.lf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ entries:
2929
phy_init:esp_phy_enable (noflash)
3030
phy_init:esp_phy_disable (noflash)
3131
phy_init:esp_wifi_bt_power_domain_off (noflash)
32+
if PM_SLP_IRAM_OPT = y:
33+
phy_override:phy_get_tsens_value (noflash)

0 commit comments

Comments
 (0)