diff --git a/components/bt/controller/esp32/bt.c b/components/bt/controller/esp32/bt.c index 5bf5d8a318..6fe1b6c8b7 100644 --- a/components/bt/controller/esp32/bt.c +++ b/components/bt/controller/esp32/bt.c @@ -488,6 +488,18 @@ static void btdm_slp_tmr_callback(void *arg); #endif /* #ifdef CONFIG_PM_ENABLE */ +static inline void esp_bt_power_domain_on(void) +{ + // Bluetooth module power up + esp_wifi_bt_power_domain_on(); +} + +static inline void esp_bt_power_domain_off(void) +{ + // Bluetooth module power down + esp_wifi_bt_power_domain_off(); +} + static inline void btdm_check_and_init_bb(void) { /* init BT-BB if PHY/RF has been switched off since last BT-BB init */ @@ -1621,6 +1633,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto error; } + esp_bt_power_domain_on(); + btdm_controller_mem_init(); periph_module_enable(PERIPH_BT_MODULE); @@ -1774,6 +1788,8 @@ esp_err_t esp_bt_controller_deinit(void) btdm_lpcycle_us = 0; btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_NONE); + esp_bt_power_domain_off(); + return ESP_OK; } diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 8c1b116343..4a9fd237f0 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -408,7 +408,7 @@ static DRAM_ATTR esp_pm_lock_handle_t s_light_sleep_pm_lock; void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) { #if CONFIG_MAC_BB_PD - // le module power down + // Bluetooth module power down SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); @@ -419,7 +419,7 @@ void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void) { #if CONFIG_MAC_BB_PD - // le module power up + // Bluetooth module power up CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); @@ -427,6 +427,22 @@ void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void) #endif } +static inline void esp_bt_power_domain_on(void) +{ + // Bluetooth module power up + CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); + CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); + esp_wifi_bt_power_domain_on(); +} + +static inline void esp_bt_power_domain_off(void) +{ + // Bluetooth module power down + SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); + SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); + esp_wifi_bt_power_domain_off(); +} + void IRAM_ATTR btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem) { #if CONFIG_MAC_BB_PD @@ -956,6 +972,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) // overwrite some parameters cfg->magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL; + esp_bt_power_domain_on(); + btdm_controller_mem_init(); #if CONFIG_MAC_BB_PD @@ -1223,6 +1241,9 @@ esp_err_t esp_bt_controller_deinit(void) esp_unregister_mac_bb_pd_callback(btdm_mac_bb_power_down_cb); esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); #endif + + esp_bt_power_domain_off(); + free(osi_funcs_p); osi_funcs_p = NULL; diff --git a/components/bt/controller/esp32s3/bt.c b/components/bt/controller/esp32s3/bt.c index 4190c7b05a..a5966b8c16 100644 --- a/components/bt/controller/esp32s3/bt.c +++ b/components/bt/controller/esp32s3/bt.c @@ -407,10 +407,6 @@ static DRAM_ATTR esp_pm_lock_handle_t s_light_sleep_pm_lock; void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) { #if CONFIG_MAC_BB_PD - // le module power down - SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); - SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); - esp_mac_bb_power_down(); #endif } @@ -418,10 +414,6 @@ void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void) { #if CONFIG_MAC_BB_PD - // le module power up - CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); - CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); - esp_mac_bb_power_up(); #endif } @@ -433,6 +425,18 @@ void IRAM_ATTR btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uin #endif } +static inline void esp_bt_power_domain_on(void) +{ + // Bluetooth module power up + esp_wifi_bt_power_domain_on(); +} + +static inline void esp_bt_power_domain_off(void) +{ + // Bluetooth module power down + esp_wifi_bt_power_domain_off(); +} + static void interrupt_set_wrapper(int32_t cpu_no, int32_t intr_source, int32_t intr_num, int32_t intr_prio) { intr_matrix_set(cpu_no, intr_source, intr_num); @@ -936,6 +940,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) // overwrite some parameters cfg->magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL; + esp_bt_power_domain_on(); + btdm_controller_mem_init(); #if CONFIG_MAC_BB_PD @@ -1143,6 +1149,8 @@ error: esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); #endif + esp_bt_power_domain_off(); + if (osi_funcs_p != NULL) { free(osi_funcs_p); osi_funcs_p = NULL; diff --git a/components/bt/include/esp32/include/esp_bt.h b/components/bt/include/esp32/include/esp_bt.h index 7c8f2ea744..8696a3f761 100644 --- a/components/bt/include/esp32/include/esp_bt.h +++ b/components/bt/include/esp32/include/esp_bt.h @@ -530,6 +530,16 @@ esp_err_t esp_bt_sleep_disable(void); */ esp_err_t esp_ble_scan_dupilcate_list_flush(void); +/** + * @brief bt Wi-Fi power domain power on + */ +void esp_wifi_bt_power_domain_on(void); + +/** + * @brief bt Wi-Fi power domain power off + */ +void esp_wifi_bt_power_domain_off(void); + #ifdef __cplusplus } #endif diff --git a/components/bt/include/esp32c3/include/esp_bt.h b/components/bt/include/esp32c3/include/esp_bt.h index 8860d75ff6..152d908d69 100644 --- a/components/bt/include/esp32c3/include/esp_bt.h +++ b/components/bt/include/esp32c3/include/esp_bt.h @@ -527,6 +527,16 @@ void esp_bt_controller_wakeup_request(void); */ int esp_bt_h4tl_eif_io_event_notify(int event); +/** + * @brief bt Wi-Fi power domain power on + */ +void esp_wifi_bt_power_domain_on(void); + +/** + * @brief bt Wi-Fi power domain power off + */ +void esp_wifi_bt_power_domain_off(void); + #ifdef __cplusplus } #endif diff --git a/components/bt/include/esp32s3/include/esp_bt.h b/components/bt/include/esp32s3/include/esp_bt.h index 3bda8248f0..bb38729353 100644 --- a/components/bt/include/esp32s3/include/esp_bt.h +++ b/components/bt/include/esp32s3/include/esp_bt.h @@ -526,6 +526,16 @@ void esp_bt_controller_wakeup_request(void); */ int esp_bt_h4tl_eif_io_event_notify(int event); +/** + * @brief bt Wi-Fi power domain power on + */ +void esp_wifi_bt_power_domain_on(void); + +/** + * @brief bt Wi-Fi power domain power off + */ +void esp_wifi_bt_power_domain_off(void); + #ifdef __cplusplus } #endif