fix(pm): add mac/bb power down/up prepare for fix esp32c6 pll issue

This commit is contained in:
xiaqilin
2023-09-25 20:59:32 +08:00
committed by cjin
parent 4cecb6ac19
commit b9baf49782
5 changed files with 50 additions and 3 deletions

View File

@@ -40,6 +40,24 @@ void mac_bb_power_up_cb_execute(void);
#endif // CONFIG_MAC_BB_PD
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
/**
* @brief MAC and baseband power down operation
*
* In light sleep mode, execute IEEE802154/Bluetooth module MAC and baseband
* power up and backup prepare operations.
*/
void mac_bb_power_down_prepare(void);
/**
* @brief MAC and baseband power up operation
*
* In light sleep mode, execute IEEE802154/Bluetooth module MAC and baseband
* power up and restore prepare operations.
*/
void mac_bb_power_up_prepare(void);
#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
/**

View File

@@ -390,3 +390,22 @@ static void esp_pm_light_sleep_default_params_config(int min_freq_mhz, int max_f
}
}
#endif
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
static bool s_modem_sleep = false;
void IRAM_ATTR mac_bb_power_down_prepare(void)
{
if (s_modem_sleep == false) {
sleep_retention_do_extra_retention(true); // backup
s_modem_sleep = true;
}
}
void IRAM_ATTR mac_bb_power_up_prepare(void)
{
if (s_modem_sleep) {
sleep_retention_do_extra_retention(false); // restore
s_modem_sleep = false;
}
}
#endif /* SOC_PM_RETENTION_HAS_CLOCK_BUG */

View File

@@ -624,6 +624,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
// Will switch to XTAL turn down MSPI speed
mspi_timing_change_speed_mode_cache_safe(true);
/*
Since the modem requires a PLL clock to access modem REG,
it is necessary to back up the mac/bb REG before disabling the PLL clock.
*/
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
mac_bb_power_down_prepare();
#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG
// Save current frequency and switch to XTAL
rtc_cpu_freq_config_t cpu_freq_config;
rtc_clk_cpu_freq_get_config(&cpu_freq_config);

View File

@@ -505,10 +505,8 @@ uint32_t IRAM_ATTR sleep_retention_get_modules(void)
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
void sleep_retention_do_extra_retention(bool backup_or_restore)
{
_lock_acquire_recursive(&s_retention.lock);
if (s_retention.highpri < SLEEP_RETENTION_REGDMA_LINK_HIGHEST_PRIORITY ||
s_retention.highpri > SLEEP_RETENTION_REGDMA_LINK_LOWEST_PRIORITY) {
_lock_release_recursive(&s_retention.lock);
return;
}
const uint32_t clk_bug_modules = SLEEP_RETENTION_MODULE_BLE_MAC | SLEEP_RETENTION_MODULE_802154_MAC;
@@ -525,7 +523,6 @@ void sleep_retention_do_extra_retention(bool backup_or_restore)
}
}
int refs = s_retention.extra_refs;
_lock_release_recursive(&s_retention.lock);
assert(refs >= 0 && refs <= cnt_modules);
}

View File

@@ -999,6 +999,11 @@ void IRAM_ATTR esp_pm_impl_isr_hook(void)
}
#else
leave_idle();
/* it is necessary to restore the mac/bb REG before scheduling other tasks in FreeRTOS.*/
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
mac_bb_power_up_prepare();
#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG
#endif // CONFIG_FREERTOS_SYSTICK_USES_CCOUNT && portNUM_PROCESSORS == 2
#if CONFIG_FREERTOS_SMP
portRESTORE_INTERRUPTS(state);