change(esp_hw_support): optimize sleep_phy retention static RAM cost

This commit is contained in:
wuzhenghui
2026-08-10 22:04:28 +08:00
parent 64f8bdd2e1
commit 6be25041e0
4 changed files with 44 additions and 8 deletions

View File

@@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "esp_check.h"
#include "esp_attr.h"
@@ -53,7 +55,7 @@ static esp_err_t sleep_phy_retention_init(void *arg)
{
#define PHY_ENTRY() (BIT(SOC_PM_PAU_REGDMA_LINK_IDX_PHY))
static sleep_retention_entries_config_t phy_modem_config[] = {
static const sleep_retention_entries_config_t phy_modem_config_template[] = {
[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 = PHY_ENTRY() }, /* I2C MST enable */
/* Reset SET_FREQ fsm */
@@ -94,10 +96,17 @@ static esp_err_t sleep_phy_retention_init(void *arg)
[26] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x1a), PMU_SLP_WAKEUP_CNTL7_REG, 0x200000, 0xffff0000, 1, 0), .owner = PHY_ENTRY() },
[27] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x1b), PMU_SLP_WAKEUP_CNTL7_REG, 0x9730000, 0xffff0000, 0, 1), .owner = PHY_ENTRY() }
};
sleep_retention_entries_config_t *phy_modem_config = malloc(sizeof(phy_modem_config_template));
if (phy_modem_config == NULL) {
return ESP_ERR_NO_MEM;
}
memcpy(phy_modem_config, phy_modem_config_template, sizeof(phy_modem_config_template));
extern uint32_t phy_ana_i2c_master_burst_rf_onoff(bool on);
phy_modem_config[5].config.write_wait.value = phy_ana_i2c_master_burst_rf_onoff(true);
phy_modem_config[17].config.write_wait.value = phy_ana_i2c_master_burst_rf_onoff(false);
esp_err_t err = sleep_retention_entries_create(phy_modem_config, ARRAY_SIZE(phy_modem_config), 7, SLEEP_RETENTION_MODULE_MODEM_PHY);
esp_err_t err = sleep_retention_entries_create(phy_modem_config, ARRAY_SIZE(phy_modem_config_template), 7, SLEEP_RETENTION_MODULE_MODEM_PHY);
free(phy_modem_config);
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate modem phy link");
return ESP_OK;
}

View File

@@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdlib.h>
#include <string.h>
#include "esp_attr.h"
#include "soc/soc_caps.h"
@@ -51,7 +53,7 @@ esp_err_t sleep_phy_link_init(void **link_context)
esp_err_t err = ESP_OK;
#if SOC_PM_PAU_REGDMA_LINK_MODEM
static regdma_link_config_t phy_modem_config[] = {
static const regdma_link_config_t phy_modem_config_template[] = {
[0] = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_FE_LINK(0), MODEM_FE_DATA_BASE, MODEM_FE_DATA_BASE, 41, 0, 0),
[1] = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_FE_LINK(1), MODEM_FE_CTRL_BASE, MODEM_FE_CTRL_BASE, 87, 0, 0),
@@ -106,12 +108,18 @@ esp_err_t sleep_phy_link_init(void **link_context)
[39] = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x25), PMU_SLP_WAKEUP_CNTL7_REG, 0x200000, 0xffff0000, 1, 0),
[40] = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x26), PMU_SLP_WAKEUP_CNTL7_REG, 0x9730000, 0xffff0000, 0, 1)
};
regdma_link_config_t *phy_modem_config = malloc(sizeof(phy_modem_config_template));
if (phy_modem_config == NULL) {
return ESP_ERR_NO_MEM;
}
memcpy(phy_modem_config, phy_modem_config_template, sizeof(phy_modem_config_template));
extern uint32_t phy_ana_i2c_master_burst_rf_onoff(bool on);
phy_modem_config[8].write_wait.value = phy_ana_i2c_master_burst_rf_onoff(true);
phy_modem_config[24].write_wait.value = phy_ana_i2c_master_burst_rf_onoff(false);
void *link = NULL;
for (int i = ARRAY_SIZE(phy_modem_config) - 1; (err == ESP_OK) && (i >= 0); i--) {
for (int i = ARRAY_SIZE(phy_modem_config_template) - 1; (err == ESP_OK) && (i >= 0); i--) {
void *next = regdma_link_init_safe(&phy_modem_config[i], false, 0, link);
if (next) {
link = next;
@@ -120,6 +128,7 @@ esp_err_t sleep_phy_link_init(void **link_context)
err = ESP_ERR_NO_MEM;
}
}
free(phy_modem_config);
if (err == ESP_OK) {
pau_regdma_set_modem_link_addr(link);

View File

@@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdlib.h>
#include <string.h>
#include "esp_attr.h"
#include "soc/soc_caps.h"
@@ -48,7 +50,7 @@ esp_err_t sleep_phy_link_init(void **link_context)
esp_err_t err = ESP_OK;
#if SOC_PM_PAU_REGDMA_LINK_MODEM
static regdma_link_config_t phy_modem_config[] = {
static const regdma_link_config_t phy_modem_config_template[] = {
[0] = 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), /* I2C MST enable */
/* Reset SET_FREQ fsm */
@@ -101,12 +103,18 @@ esp_err_t sleep_phy_link_init(void **link_context)
[36] = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x24), PMU_SLP_WAKEUP_CNTL7_REG, 0x200000, 0xffff0000, 1, 0),
[37] = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x25), PMU_SLP_WAKEUP_CNTL7_REG, 0x9730000, 0xffff0000, 0, 1)
};
regdma_link_config_t *phy_modem_config = malloc(sizeof(phy_modem_config_template));
if (phy_modem_config == NULL) {
return ESP_ERR_NO_MEM;
}
memcpy(phy_modem_config, phy_modem_config_template, sizeof(phy_modem_config_template));
extern uint32_t phy_ana_i2c_master_burst_rf_onoff(bool on);
phy_modem_config[5].write_wait.value = phy_ana_i2c_master_burst_rf_onoff(true);
phy_modem_config[21].write_wait.value = phy_ana_i2c_master_burst_rf_onoff(false);
void *link = NULL;
for (int i = ARRAY_SIZE(phy_modem_config) - 1; (err == ESP_OK) && (i >= 0); i--) {
for (int i = ARRAY_SIZE(phy_modem_config_template) - 1; (err == ESP_OK) && (i >= 0); i--) {
void *next = regdma_link_init_safe(&phy_modem_config[i], false, 0, link);
if (next) {
link = next;
@@ -115,6 +123,7 @@ esp_err_t sleep_phy_link_init(void **link_context)
err = ESP_ERR_NO_MEM;
}
}
free(phy_modem_config);
if (err == ESP_OK) {
pau_regdma_set_modem_link_addr(link);

View File

@@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "esp_check.h"
#include "esp_attr.h"
@@ -50,7 +52,7 @@ static esp_err_t sleep_phy_retention_init(void *arg)
{
#define PHY_ENTRY() (BIT(SOC_PM_PAU_REGDMA_LINK_IDX_PHY))
static sleep_retention_entries_config_t phy_modem_config[] = {
static const sleep_retention_entries_config_t phy_modem_config_template[] = {
[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 = PHY_ENTRY() }, /* I2C MST enable */
/* PMU or software to trigger enable RF PHY */
@@ -88,10 +90,17 @@ static esp_err_t sleep_phy_retention_init(void *arg)
[24] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x18), PMU_SLP_WAKEUP_CNTL7_REG, 0x200000, 0xffff0000, 1, 0), .owner = PHY_ENTRY() },
[25] = { .config = REGDMA_LINK_WRITE_INIT(REGDMA_PHY_LINK(0x19), PMU_SLP_WAKEUP_CNTL7_REG, 0x9730000, 0xffff0000, 0, 1), .owner = PHY_ENTRY() }
};
sleep_retention_entries_config_t *phy_modem_config = malloc(sizeof(phy_modem_config_template));
if (phy_modem_config == NULL) {
return ESP_ERR_NO_MEM;
}
memcpy(phy_modem_config, phy_modem_config_template, sizeof(phy_modem_config_template));
extern uint32_t phy_ana_i2c_master_burst_rf_onoff(bool on);
phy_modem_config[4].config.write_wait.value = phy_ana_i2c_master_burst_rf_onoff(true);
phy_modem_config[15].config.write_wait.value = phy_ana_i2c_master_burst_rf_onoff(false);
esp_err_t err = sleep_retention_entries_create(phy_modem_config, ARRAY_SIZE(phy_modem_config), 7, SLEEP_RETENTION_MODULE_MODEM_PHY);
esp_err_t err = sleep_retention_entries_create(phy_modem_config, ARRAY_SIZE(phy_modem_config_template), 7, SLEEP_RETENTION_MODULE_MODEM_PHY);
free(phy_modem_config);
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate modem phy link");
return ESP_OK;
}