88#include "soc/pcr_reg.h"
99#include "modem/modem_syscon_reg.h"
1010#include "modem/modem_lpcon_reg.h"
11-
11+ #include "soc/i2c_ana_mst_reg.h"
12+ #include "soc/pmu_reg.h"
13+ #include "soc/lp_analog_peri_reg.h"
1214
1315static const char * TAG = "sleep_clock" ;
1416
1517esp_err_t sleep_clock_system_retention_init (void * arg )
1618{
1719 #define N_REGS_PCR () (((PCR_ZERO_DET_CLK_CONF_REG - DR_REG_PCR_BASE) / 4) + 1)
18-
1920 const static sleep_retention_entries_config_t pcr_regs_retention [] = {
2021 /* Clock configuration retention */
21- [0 ] = { .config = REGDMA_LINK_CONTINUOUS_INIT (REGDMA_PCR_LINK (0x0 ), DR_REG_PCR_BASE , DR_REG_PCR_BASE , N_REGS_PCR (), 0 , 0 ), .owner = ENTRY (0 ) | ENTRY (2 ) },
22- [1 ] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK (0x2 ), PCR_BUS_CLK_UPDATE_REG , PCR_BUS_CLOCK_UPDATE , PCR_BUS_CLOCK_UPDATE_M , 1 , 0 ), .owner = ENTRY (0 ) | ENTRY (2 ) },
23- [2 ] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_PCR_LINK (0x3 ), PCR_BUS_CLK_UPDATE_REG , 0x0 , PCR_BUS_CLOCK_UPDATE_M , 1 , 0 ), .owner = ENTRY (0 ) | ENTRY (2 ) }
22+ [0 ] = { .config = REGDMA_LINK_CONTINUOUS_INIT (REGDMA_PCR_LINK (0 ), DR_REG_PCR_BASE , DR_REG_PCR_BASE , N_REGS_PCR (), 0 , 0 ), .owner = ENTRY (0 ) | ENTRY (2 ) },
23+ [1 ] = { .config = REGDMA_LINK_CONTINUOUS_INIT (REGDMA_PCR_LINK (1 ), PCR_RESET_EVENT_BYPASS_REG , PCR_RESET_EVENT_BYPASS_REG , 1 , 0 , 0 ), .owner = ENTRY (0 ) | ENTRY (2 ) },
24+ [2 ] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_PCR_LINK (2 ), PCR_BUS_CLK_UPDATE_REG , PCR_BUS_CLOCK_UPDATE , PCR_BUS_CLOCK_UPDATE_M , 1 , 0 ), .owner = ENTRY (0 ) | ENTRY (2 ) },
25+ [3 ] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_PCR_LINK (3 ), PCR_BUS_CLK_UPDATE_REG , 0x0 , PCR_BUS_CLOCK_UPDATE_M , 1 , 0 ), .owner = ENTRY (0 ) | ENTRY (2 ) },
2426 };
2527
2628 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 );
@@ -31,15 +33,29 @@ esp_err_t sleep_clock_system_retention_init(void *arg)
3133 #undef N_REGS_PCR
3234}
3335
34- #if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE || SOC_PM_MODEM_CLK_RETENTION_WORKROUND
36+ #if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE || SOC_PM_MODEM_CLK_CONF_RETENTION
3537esp_err_t sleep_clock_modem_retention_init (void * arg )
3638{
3739 #define N_REGS_SYSCON () (((MODEM_SYSCON_MEM_RF2_CONF_REG - MODEM_SYSCON_TEST_CONF_REG) / 4) + 1)
3840 #define N_REGS_LPCON () (((MODEM_LPCON_MEM_CONF_REG - MODEM_LPCON_TEST_CONF_REG) / 4) + 1)
3941
42+ /* In ESP32H4, the I2C control registers (syscon, lpcon) are placed in the modem domain,
43+ and the BBPL requires I2C for calibration. This is the reason why the code for the BPLL enableq
44+ section needs to be placed in this function.*/
4045 const static sleep_retention_entries_config_t modem_regs_retention [] = {
41- [0 ] = { .config = REGDMA_LINK_CONTINUOUS_INIT (REGDMA_MODEMSYSCON_LINK (0 ), MODEM_SYSCON_TEST_CONF_REG , MODEM_SYSCON_TEST_CONF_REG , N_REGS_SYSCON (), 0 , 0 ), .owner = ENTRY (0 ) | ENTRY (1 ) }, /* MODEM SYSCON */
42- [1 ] = { .config = REGDMA_LINK_CONTINUOUS_INIT (REGDMA_MODEMLPCON_LINK (0 ), MODEM_LPCON_TEST_CONF_REG , MODEM_LPCON_TEST_CONF_REG , N_REGS_LPCON (), 0 , 0 ), .owner = ENTRY (0 ) | ENTRY (1 ) } /* MODEM LPCON */
46+ /* SYSCON LPCON configuration retention */
47+ [0 ] = { .config = REGDMA_LINK_CONTINUOUS_INIT (REGDMA_MODEMSYSCON_LINK (0 ), MODEM_SYSCON_TEST_CONF_REG , MODEM_SYSCON_TEST_CONF_REG , N_REGS_SYSCON (), 0 , 0 ), .owner = ENTRY (0 ) | ENTRY (1 ) }, /* MODEM SYSCON */
48+ [1 ] = { .config = REGDMA_LINK_CONTINUOUS_INIT (REGDMA_MODEMLPCON_LINK (0 ), MODEM_LPCON_TEST_CONF_REG , MODEM_LPCON_TEST_CONF_REG , N_REGS_LPCON (), 0 , 0 ), .owner = ENTRY (0 ) | ENTRY (1 ) }, /* MODEM LPCON */
49+ /* Enable i2c master clock */
50+ [2 ] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK (1 ), MODEM_LPCON_CLK_CONF_REG , MODEM_LPCON_CLK_I2C_MST_EN , MODEM_LPCON_CLK_I2C_MST_EN_M , 1 , 0 ), .owner = ENTRY (0 ) },
51+ /* Start BBPLL self-calibration */
52+ [3 ] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK (2 ), I2C_ANA_MST_ANA_CONF0_REG , 0 , I2C_MST_BBPLL_STOP_FORCE_HIGH , 1 , 0 ), .owner = ENTRY (0 ) },
53+ [4 ] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK (3 ), I2C_ANA_MST_ANA_CONF0_REG , I2C_MST_BBPLL_STOP_FORCE_LOW , I2C_MST_BBPLL_STOP_FORCE_LOW , 1 , 0 ), .owner = ENTRY (0 ) },
54+ /* Wait calibration done */
55+ [5 ] = { .config = REGDMA_LINK_WAIT_INIT (REGDMA_MODEMSYSCON_LINK (4 ), I2C_ANA_MST_ANA_CONF0_REG , I2C_MST_BBPLL_CAL_DONE , I2C_MST_BBPLL_CAL_DONE , 1 , 0 ), .owner = ENTRY (0 ) },
56+ /* Stop BBPLL self-calibration */
57+ [6 ] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK (5 ), I2C_ANA_MST_ANA_CONF0_REG , 0 , I2C_MST_BBPLL_STOP_FORCE_LOW , 1 , 0 ), .owner = ENTRY (0 ) },
58+ [7 ] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK (6 ), I2C_ANA_MST_ANA_CONF0_REG , I2C_MST_BBPLL_STOP_FORCE_HIGH , I2C_MST_BBPLL_STOP_FORCE_HIGH , 1 , 0 ), .owner = ENTRY (0 ) },
4359 };
4460
4561 esp_err_t err = sleep_retention_entries_create (modem_regs_retention , ARRAY_SIZE (modem_regs_retention ), REGDMA_LINK_PRI_MODEM_CLK , SLEEP_RETENTION_MODULE_CLOCK_MODEM );
@@ -58,12 +74,14 @@ bool clock_domain_pd_allowed(void)
5874 const sleep_retention_module_bitmap_t created_modules = sleep_retention_get_created_modules ();
5975 const sleep_retention_module_bitmap_t sys_clk_dep_modules = (sleep_retention_module_bitmap_t ){ .bitmap [SLEEP_RETENTION_MODULE_SYS_PERIPH >> 5 ] = BIT (SLEEP_RETENTION_MODULE_SYS_PERIPH % 32 ) };
6076
61- /* The clock and reset of MODEM (WiFi, BLE and 15.4) modules are managed
77+ /* The clock and reset of MODEM (BLE and 15.4) modules are managed
6278 * through MODEM_SYSCON, when one or more MODEMs are initialized, it is
6379 * necessary to check the state of CLOCK_MODEM to determine MODEM domain on
6480 * or off. The clock and reset of digital peripherals are managed through
6581 * PCR, with TOP domain similar to MODEM domain. */
66- __attribute__((unused )) sleep_retention_module_bitmap_t modem_clk_dep_modules = (sleep_retention_module_bitmap_t ){ .bitmap = { 0 } };
82+ #if SOC_BLE_SUPPORTED || SOC_IEEE802154_SUPPORTED
83+ sleep_retention_module_bitmap_t modem_clk_dep_modules = (sleep_retention_module_bitmap_t ){ .bitmap = { 0 } };
84+ #endif
6785#if SOC_BT_SUPPORTED
6886 modem_clk_dep_modules .bitmap [SLEEP_RETENTION_MODULE_BLE_MAC >> 5 ] |= BIT (SLEEP_RETENTION_MODULE_BLE_MAC % 32 );
6987 modem_clk_dep_modules .bitmap [SLEEP_RETENTION_MODULE_BT_BB >> 5 ] |= BIT (SLEEP_RETENTION_MODULE_BT_BB % 32 );
@@ -86,7 +104,7 @@ bool clock_domain_pd_allowed(void)
86104 mask .bitmap [SLEEP_RETENTION_MODULE_CLOCK_MODEM >> 5 ] |= BIT (SLEEP_RETENTION_MODULE_CLOCK_MODEM % 32 );
87105 }
88106#endif
89- #if SOC_PM_MODEM_CLK_RETENTION_WORKROUND
107+ #if SOC_PM_MODEM_CLK_CONF_RETENTION
90108 mask .bitmap [SLEEP_RETENTION_MODULE_CLOCK_MODEM >> 5 ] |= BIT (SLEEP_RETENTION_MODULE_CLOCK_MODEM % 32 );
91109#endif
92110 const sleep_retention_module_bitmap_t clock_domain_inited_modules = sleep_retention_module_bitmap_and (inited_modules , mask );
@@ -102,16 +120,16 @@ ESP_SYSTEM_INIT_FN(sleep_clock_startup_init, SECONDARY, BIT(0), 106)
102120 };
103121 sleep_retention_module_init (SLEEP_RETENTION_MODULE_CLOCK_SYSTEM , & init_param );
104122
105- #if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE || SOC_PM_MODEM_CLK_RETENTION_WORKROUND
123+ #if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE || SOC_PM_MODEM_CLK_CONF_RETENTION
106124 init_param = (sleep_retention_module_init_param_t ) {
107125 .cbs = { .create = { .handle = sleep_clock_modem_retention_init , .arg = NULL } },
108- #if !SOC_PM_MODEM_CLK_RETENTION_WORKROUND
126+ #if !SOC_PM_MODEM_CLK_CONF_RETENTION
109127 .attribute = SLEEP_RETENTION_MODULE_ATTR_PASSIVE
110128#endif
111129 };
112130 sleep_retention_module_init (SLEEP_RETENTION_MODULE_CLOCK_MODEM , & init_param );
113131#endif
114- #if SOC_PM_MODEM_CLK_RETENTION_WORKROUND
132+ #if SOC_PM_MODEM_CLK_CONF_RETENTION
115133 if (sleep_retention_module_allocate (SLEEP_RETENTION_MODULE_CLOCK_MODEM ) != ESP_OK ) {
116134 // even though the modem clock retention module create failed, sleep process can be executed without pd the modem domain, so just warning here
117135 ESP_LOGW (TAG , "create retention link failed on modem clock, modem power domain won't be turned off during sleep" );
0 commit comments