Skip to content

Commit 3edbd07

Browse files
committed
Merge branch 'feat/esp32c5_wifi_sleep' into 'master'
esp32c5 wifi legacy sleep and modem state support Closes WIFI-6424, WIFI-6425, PM-185, IDF-10597, and IDF-10601 See merge request espressif/esp-idf!33225
2 parents a71e0fc + 072ea6b commit 3edbd07

File tree

20 files changed

+475
-130
lines changed

20 files changed

+475
-130
lines changed

components/esp_hw_support/include/esp_private/sleep_modem.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -120,7 +120,7 @@ bool modem_domain_pd_allowed(void);
120120
uint32_t sleep_modem_reject_triggers(void);
121121

122122
/**
123-
* @brief Configure the parameters of the modem subsytem during the sleep process
123+
* @brief Configure the parameters of the modem subsystem during the sleep process
124124
*
125125
* In light sleep mode, the wake-up early time of the WiFi module and the TBTT
126126
* interrupt early time (trigger enabling RF) are determined by the maximum and
@@ -132,7 +132,7 @@ uint32_t sleep_modem_reject_triggers(void);
132132
*
133133
* @param max_freq_mhz the maximum frequency of system
134134
* @param min_freq_mhz the minimum frequency of system
135-
* @param light_sleep_enable ture or false for enable or disable light sleep mode, respectively
135+
* @param light_sleep_enable true or false for enable or disable light sleep mode, respectively
136136
*
137137
* @return
138138
* - ESP_OK on success
@@ -225,6 +225,27 @@ void sleep_modem_wifi_modem_state_deinit(void);
225225
* - false not skip light sleep
226226
*/
227227
bool sleep_modem_wifi_modem_state_skip_light_sleep(void);
228+
229+
/**
230+
* @brief Function to initialize and create the modem state phy link
231+
* @param link_head the pointer that point to the head of the created phy link
232+
* @return
233+
* - ESP_OK on success
234+
* - ESP_ERR_NO_MEM if no memory for link
235+
* - ESP_ERR_INVALID_ARG if value is out of range
236+
* - ESP_ERR_INVALID_STATE if the phy module retention state is invalid
237+
*/
238+
esp_err_t sleep_modem_state_phy_link_init(void **link_head);
239+
240+
/**
241+
* @brief Function to destroy and de-initialize modem state phy link
242+
* @param link_head the phy link head will be destroyed
243+
* @return
244+
* - ESP_OK on success
245+
* - ESP_ERR_INVALID_ARG if value is out of range
246+
* - ESP_ERR_INVALID_STATE if the phy module retention state is invalid
247+
*/
248+
esp_err_t sleep_modem_state_phy_link_deinit(void *link_head);
228249
#endif
229250

230251
#ifdef __cplusplus

components/esp_hw_support/lowpower/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ if((CONFIG_SOC_PM_SUPPORT_MODEM_PD OR CONFIG_SOC_PM_SUPPORT_TOP_PD) AND CONFIG_S
2424
list(APPEND srcs "port/${target}/sleep_clock.c")
2525
endif()
2626

27+
if(CONFIG_SOC_PM_SUPPORT_PMU_MODEM_STATE)
28+
list(APPEND srcs "port/${target}/sleep_modem_state.c")
29+
endif()
30+
2731
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")
2832

2933
target_sources(${COMPONENT_LIB} PRIVATE "${srcs}")

components/esp_hw_support/lowpower/port/esp32c5/sleep_clock.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "esp_private/sleep_clock.h"
88
#include "soc/pcr_reg.h"
9+
#include "soc/rtc.h"
910
#include "modem/modem_syscon_reg.h"
1011
#include "modem/modem_lpcon_reg.h"
1112
#include "soc/i2c_ana_mst_reg.h"
@@ -14,13 +15,43 @@ static const char *TAG = "sleep_clock";
1415

1516
esp_err_t sleep_clock_system_retention_init(void *arg)
1617
{
17-
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
1818
const static sleep_retention_entries_config_t pcr_regs_retention[] = {
19-
[0] = { .config = REGDMA_LINK_ADDR_MAP_INIT(REGDMA_PCR_LINK(0), DR_REG_PCR_BASE, DR_REG_PCR_BASE, 74, 0, 0, 0xffffffff, 0xffffffff, 0x7f7, 0x0), .owner = ENTRY(0) | ENTRY(1) },
19+
[0] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK(0), PCR_AHB_FREQ_CONF_REG, 0, PCR_AHB_DIV_NUM, 1, 0), .owner = ENTRY(0) | ENTRY(1) }, /* Set AHB bus frequency to XTAL frequency */
20+
[1] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK(1), PCR_BUS_CLK_UPDATE_REG, 1, PCR_BUS_CLOCK_UPDATE, 1, 0), .owner = ENTRY(0) | ENTRY(1) },
21+
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
22+
[2] = { .config = REGDMA_LINK_ADDR_MAP_INIT(REGDMA_PCR_LINK(2), DR_REG_PCR_BASE, DR_REG_PCR_BASE, 74, 0, 0, 0xffffffff, 0xffffffff, 0x7f7, 0x0), .owner = ENTRY(0) | ENTRY(1) },
23+
#endif
2024
};
2125
esp_err_t err = sleep_retention_entries_create(pcr_regs_retention, ARRAY_SIZE(pcr_regs_retention), REGDMA_LINK_PRI_SYS_CLK, SLEEP_RETENTION_MODULE_CLOCK_SYSTEM);
2226
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for system (PCR) retention");
27+
28+
const static sleep_retention_entries_config_t modem_ahb_config[] = {
29+
[0] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK(3), PCR_AHB_FREQ_CONF_REG, 3, PCR_AHB_DIV_NUM, 1, 0), .owner = ENTRY(1) }, /* Set AHB bus frequency to 40 MHz under PMU MODEM state */
30+
[1] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK(4), PCR_BUS_CLK_UPDATE_REG, 1, PCR_BUS_CLOCK_UPDATE, 1, 0), .owner = ENTRY(1) },
31+
};
32+
err = sleep_retention_entries_create(modem_ahb_config, ARRAY_SIZE(modem_ahb_config), REGDMA_LINK_PRI_4, SLEEP_RETENTION_MODULE_CLOCK_SYSTEM);
33+
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for system (PCR) retention, 4 level priority");
34+
35+
#if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP && CONFIG_XTAL_FREQ_AUTO
36+
uint32_t xtal_freq_mhz = (uint32_t)rtc_clk_xtal_freq_get();
37+
if (xtal_freq_mhz == SOC_XTAL_FREQ_48M) {
38+
39+
/* For the 48 MHz main XTAL, we need regdma to configured BBPLL by exec
40+
* the PHY_I2C_MST_CMD_TYPE_BBPLL_CFG command from PHY i2c master
41+
* command memory */
42+
sleep_retention_entries_config_t bbpll_config[] = {
43+
[0] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK(5), MODEM_LPCON_CLK_CONF_REG, MODEM_LPCON_CLK_I2C_MST_EN, MODEM_LPCON_CLK_I2C_MST_EN_M, 1, 0), .owner = ENTRY(1) }, /* I2C MST enable */
44+
[1] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK(6), I2C_ANA_MST_I2C_BURST_CONF_REG, 0, 0xffffffff, 1, 0), .owner = ENTRY(1) },
45+
[2] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_PCR_LINK(7), I2C_ANA_MST_I2C_BURST_STATUS_REG, I2C_ANA_MST_BURST_DONE, 0x1, 1, 0), .owner = ENTRY(1) },
46+
[3] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK(8), MODEM_LPCON_CLK_CONF_REG, 0, MODEM_LPCON_CLK_I2C_MST_EN_M, 1, 0), .owner = ENTRY(1) }, /* I2C MST disable */
47+
};
48+
extern uint32_t phy_ana_i2c_master_burst_bbpll_config(void);
49+
bbpll_config[1].config.write_wait.value = phy_ana_i2c_master_burst_bbpll_config();
50+
err = sleep_retention_entries_create(bbpll_config, ARRAY_SIZE(bbpll_config), REGDMA_LINK_PRI_SYS_CLK, SLEEP_RETENTION_MODULE_CLOCK_SYSTEM);
51+
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for bbpll configure, 0 level priority");
52+
}
2353
#endif
54+
2455
ESP_LOGI(TAG, "System Power, Clock and Reset sleep retention initialization");
2556
return ESP_OK;
2657
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include "esp_log.h"
7+
#include "esp_check.h"
8+
9+
#include "soc/soc_caps.h"
10+
#include "soc/i2c_ana_mst_reg.h"
11+
#include "soc/pmu_reg.h"
12+
13+
#include "modem/modem_syscon_reg.h"
14+
#include "modem/modem_lpcon_reg.h"
15+
16+
#include "esp_private/sleep_modem.h"
17+
#include "esp_private/sleep_retention.h"
18+
19+
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
20+
21+
#define SARADC_TSENS_REG (0x6000e058)
22+
#define SARADC_TSENS_PU (BIT(22))
23+
#define PMU_RF_PWR_REG (0x600b0158)
24+
25+
#define FECOEX_SET_FREQ_SET_CHAN_REG (0x600a001c)
26+
#define FECOEX_SET_CHAN_EN (BIT(17))
27+
#define FECOEX_SET_FREQ_SET_CHAN_ST_REG (0x600a0028)
28+
#define FECOEX_SET_CHAN_DONE (BIT(8))
29+
#define FECOEX_AGC_CONF_REG (0x600a7030)
30+
#define FECOEX_AGC_DIS (BIT(29))
31+
32+
#define WDEVTXQ_BLOCK (0x600A4ca8)
33+
#define WDEV_RXBLOCK (BIT(12))
34+
#define MODEM_FE_DATA_BASE (0x600a0400)
35+
#define MODEM_FE_CTRL_BASE (0x600a0800)
36+
37+
static __attribute__((unused)) const char *TAG = "sleep";
38+
39+
#if SOC_PM_PAU_REGDMA_LINK_IDX_WIFIMAC
40+
static esp_err_t sleep_modem_state_phy_wifi_init(void *arg)
41+
{
42+
#define WIFIMAC_ENTRY() (BIT(SOC_PM_PAU_REGDMA_LINK_IDX_WIFIMAC))
43+
44+
static sleep_retention_entries_config_t wifi_modem_config[] = {
45+
[0] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x00), MODEM_LPCON_CLK_CONF_REG, MODEM_LPCON_CLK_I2C_MST_EN, MODEM_LPCON_CLK_I2C_MST_EN_M, 1, 0), .owner = WIFIMAC_ENTRY() }, /* I2C MST enable */
46+
47+
/* PMU or software to trigger enable RF PHY */
48+
[1] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x01), I2C_ANA_MST_ANA_CONF0_REG, 0x8, 0xc, 1, 0), .owner = WIFIMAC_ENTRY() }, /* BBPLL calibration enable */
49+
[2] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x02), PMU_RF_PWR_REG, 0xf3800000, 0xf3800000, 1, 0), .owner = WIFIMAC_ENTRY() },
50+
[3] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x03), SARADC_TSENS_REG, SARADC_TSENS_PU, 0x400000, 1, 0), .owner = WIFIMAC_ENTRY() },
51+
[4] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x04), I2C_ANA_MST_I2C_BURST_CONF_REG, 0, 0xffffffff, 1, 0), .owner = WIFIMAC_ENTRY() },
52+
[5] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_PHY_LINK(0x05), I2C_ANA_MST_I2C_BURST_STATUS_REG, I2C_ANA_MST_BURST_DONE, 0x1, 1, 0), .owner = WIFIMAC_ENTRY() },
53+
[6] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x06), FECOEX_SET_FREQ_SET_CHAN_REG, FECOEX_SET_CHAN_EN, 0x20000, 1, 0), .owner = WIFIMAC_ENTRY() },
54+
[7] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x07), FECOEX_SET_FREQ_SET_CHAN_REG, 0, 0x20000, 1, 0), .owner = WIFIMAC_ENTRY() },
55+
[8] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_PHY_LINK(0x08), FECOEX_SET_FREQ_SET_CHAN_ST_REG, FECOEX_SET_CHAN_DONE, 0x100, 1, 0), .owner = WIFIMAC_ENTRY() },
56+
[9] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x09), MODEM_SYSCON_WIFI_BB_CFG_REG, BIT(1), 0x2, 1, 0), .owner = WIFIMAC_ENTRY() },
57+
[10] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x0a), FECOEX_AGC_CONF_REG, 0, 0x20000000, 1, 0), .owner = WIFIMAC_ENTRY() },
58+
59+
/* PMU to trigger enable RXBLOCK */
60+
[11] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x0b), WDEVTXQ_BLOCK, 0, 0x1000, 1, 0), .owner = WIFIMAC_ENTRY() },
61+
62+
/* PMU or software to trigger disable RF PHY */
63+
[12] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x0c), FECOEX_AGC_CONF_REG, FECOEX_AGC_DIS, 0x20000000, 0, 1), .owner = WIFIMAC_ENTRY() },
64+
[13] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x0d), MODEM_SYSCON_WIFI_BB_CFG_REG, 0, 0x2, 0, 1), .owner = WIFIMAC_ENTRY() },
65+
[14] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x0e), FECOEX_SET_FREQ_SET_CHAN_REG, 0, 0x20000, 0, 1), .owner = WIFIMAC_ENTRY() },
66+
[15] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x0f), I2C_ANA_MST_I2C_BURST_CONF_REG, 0, 0xffffffff, 1, 1), .owner = WIFIMAC_ENTRY() },
67+
[16] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_PHY_LINK(0x10), I2C_ANA_MST_I2C_BURST_STATUS_REG, I2C_ANA_MST_BURST_DONE, 0x1, 1, 1), .owner = WIFIMAC_ENTRY() },
68+
[17] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x11), SARADC_TSENS_REG, 0, 0x400000, 0, 1), .owner = WIFIMAC_ENTRY() },
69+
[18] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x12), PMU_RF_PWR_REG, 0, 0xf3800000, 0, 1), .owner = WIFIMAC_ENTRY() },
70+
[19] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x13), I2C_ANA_MST_ANA_CONF0_REG, 0x4, 0xc, 0, 1), .owner = WIFIMAC_ENTRY() }, /* BBPLL calibration disable */
71+
72+
[20] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x14), MODEM_LPCON_CLK_CONF_REG, 0, MODEM_LPCON_CLK_I2C_MST_EN_M, 0, 1), .owner = WIFIMAC_ENTRY() }, /* I2C MST disable */
73+
74+
/* PMU to trigger disable RXBLOCK */
75+
[21] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_PHY_LINK(0x15), WDEVTXQ_BLOCK, 0, 0x6000, 0, 1), .owner = WIFIMAC_ENTRY() },
76+
[22] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x16), WDEVTXQ_BLOCK, WDEV_RXBLOCK, 0x1000, 0, 1), .owner = WIFIMAC_ENTRY() },
77+
[23] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_PHY_LINK(0x17), WDEVTXQ_BLOCK, 0, 0x6000, 0, 1), .owner = WIFIMAC_ENTRY() },
78+
79+
[24] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x18), PMU_SLP_WAKEUP_CNTL7_REG, 0x200000, 0xffff0000, 1, 0), .owner = WIFIMAC_ENTRY() },
80+
[25] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x19), PMU_SLP_WAKEUP_CNTL7_REG, 0x9730000, 0xffff0000, 0, 1), .owner = WIFIMAC_ENTRY() }
81+
};
82+
extern uint32_t phy_ana_i2c_master_burst_rf_onoff(bool on);
83+
wifi_modem_config[4].config.write_wait.value = phy_ana_i2c_master_burst_rf_onoff(true);
84+
wifi_modem_config[15].config.write_wait.value = phy_ana_i2c_master_burst_rf_onoff(false);
85+
esp_err_t err = sleep_retention_entries_create(wifi_modem_config, ARRAY_SIZE(wifi_modem_config), 7, SLEEP_RETENTION_MODULE_MODEM_PHY);
86+
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate modem phy link for wifi modem state");
87+
return ESP_OK;
88+
}
89+
#endif
90+
91+
esp_err_t sleep_modem_state_phy_link_init(void **link_head)
92+
{
93+
esp_err_t err = ESP_OK;
94+
95+
#if SOC_PM_PAU_REGDMA_LINK_IDX_WIFIMAC
96+
sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_modem_state_phy_wifi_init, .arg = NULL } } };
97+
err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_MODEM_PHY, &init_param);
98+
if (err == ESP_OK) {
99+
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_MODEM_PHY);
100+
if (err == ESP_OK) {
101+
*link_head = sleep_retention_find_link_by_id(REGDMA_PHY_LINK(0x00));
102+
}
103+
}
104+
#endif
105+
return err;
106+
}
107+
108+
esp_err_t sleep_modem_state_phy_link_deinit(void *link_head)
109+
{
110+
esp_err_t err = ESP_OK;
111+
#if SOC_PM_PAU_REGDMA_LINK_IDX_WIFIMAC
112+
err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_MODEM_PHY);
113+
if (err == ESP_OK) {
114+
sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_MODEM_PHY);
115+
}
116+
#endif
117+
return err;
118+
}
119+
120+
#endif /* SOC_PM_SUPPORT_PMU_MODEM_STATE */

0 commit comments

Comments
 (0)