From cf744f946651e6f260dc6b1dfe3f5a7cd2a7f920 Mon Sep 17 00:00:00 2001 From: cjin Date: Mon, 26 Jun 2023 12:11:04 +0800 Subject: [PATCH] ble: support eco1 BLE light sleep --- components/esp_hw_support/modem_clock.c | 21 +++++++++++++++---- .../esp32c6/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32c6/include/soc/soc_caps.h | 2 ++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/components/esp_hw_support/modem_clock.c b/components/esp_hw_support/modem_clock.c index 443b7c78bb..715a8ac211 100644 --- a/components/esp_hw_support/modem_clock.c +++ b/components/esp_hw_support/modem_clock.c @@ -16,6 +16,7 @@ #include "esp_private/esp_modem_clock.h" #include "esp_private/esp_pmu.h" #include "esp_sleep.h" +#include "hal/efuse_hal.h" // Please define the frequently called modules in the low bit, // which will improve the execution efficiency @@ -334,9 +335,15 @@ void modem_clock_select_lp_clock_source(periph_module_t module, modem_clock_lpcl modem_clock_hal_select_ble_rtc_timer_lpclk_source(MODEM_CLOCK_instance()->hal, src); modem_clock_hal_set_ble_rtc_timer_divisor_value(MODEM_CLOCK_instance()->hal, divider); modem_clock_hal_enable_ble_rtc_timer_clock(MODEM_CLOCK_instance()->hal, true); - if (src == MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL) { - pmu_sleep_enable_hp_sleep_sysclk(true); +#if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND + if (efuse_hal_chip_revision() != 0) { + if (src == MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL) { + pmu_sleep_enable_hp_sleep_sysclk(true); + } + modem_clock_hal_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal, true); + modem_clock_domain_clk_gate_disable(MODEM_CLOCK_DOMAIN_WIFIPWR, PMU_HP_ICG_MODEM_CODE_SLEEP); } +#endif break; #endif // SOC_BT_SUPPORTED @@ -390,9 +397,15 @@ void modem_clock_deselect_lp_clock_source(periph_module_t module) case PERIPH_BT_MODULE: modem_clock_hal_deselect_all_ble_rtc_timer_lpclk_source(MODEM_CLOCK_instance()->hal); modem_clock_hal_enable_ble_rtc_timer_clock(MODEM_CLOCK_instance()->hal, false); - if (last_src == MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL) { - pmu_sleep_enable_hp_sleep_sysclk(false); +#if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND + if (efuse_hal_chip_revision() != 0) { + if (last_src == MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL) { + pmu_sleep_enable_hp_sleep_sysclk(false); + } + modem_clock_hal_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal, false); + modem_clock_domain_clk_gate_enable(MODEM_CLOCK_DOMAIN_WIFI, PMU_HP_ICG_MODEM_CODE_SLEEP); } +#endif break; #endif // SOC_BT_SUPPORTED case PERIPH_COEX_MODULE: diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 5246b7f276..3c3471b06f 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -1310,3 +1310,7 @@ config SOC_BLE_POWER_CONTROL_SUPPORTED config SOC_BLUFI_SUPPORTED bool default y + +config SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND + bool + default y diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index f64ef21805..73859e2cb5 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -532,3 +532,5 @@ #define SOC_BLE_DEVICE_PRIVACY_SUPPORTED (1) /*!< Support BLE device privacy mode */ #define SOC_BLE_POWER_CONTROL_SUPPORTED (1) /*!< Support Bluetooth Power Control */ #define SOC_BLUFI_SUPPORTED (1) /*!< Support BLUFI */ + +#define SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND (1)