From bd6394db92d047cddb12aa3ee7e429b294e9a65f Mon Sep 17 00:00:00 2001 From: wangmengyang Date: Wed, 1 Nov 2017 17:05:38 +0800 Subject: [PATCH] component/bt: clean up WIFI_CLK_EN_REG settings for Bluetooth 1. move settings of WIFI_CLK_EN_REG for bluetooth into controller init/deinit APIs 2. modify the bit mask used in phy_rf init/deinit to use WIFI-BT shared bits --- components/bt/bt.c | 5 +++++ components/bt/lib | 2 +- components/driver/include/driver/periph_ctrl.h | 2 ++ components/driver/periph_ctrl.c | 9 +++++++++ components/esp32/phy_init.c | 5 +++-- components/soc/esp32/include/soc/dport_reg.h | 3 +++ 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/components/bt/bt.c b/components/bt/bt.c index 6f351cad18..d344914727 100644 --- a/components/bt/bt.c +++ b/components/bt/bt.c @@ -36,6 +36,7 @@ #include "esp_log.h" #include "esp_pm.h" #include "esp_ipc.h" +#include "driver/periph_ctrl.h" #if CONFIG_BT_ENABLED @@ -482,6 +483,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) btdm_controller_mem_init(); + periph_module_enable(PERIPH_BT_MODULE); + btdm_cfg_mask = btdm_config_mask_load(); ret = btdm_controller_init(btdm_cfg_mask, cfg); @@ -507,6 +510,8 @@ esp_err_t esp_bt_controller_deinit(void) return ESP_ERR_NO_MEM; } + periph_module_disable(PERIPH_BT_MODULE); + btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; #ifdef CONFIG_PM_ENABLE diff --git a/components/bt/lib b/components/bt/lib index 9a8e4ee159..8e62573de3 160000 --- a/components/bt/lib +++ b/components/bt/lib @@ -1 +1 @@ -Subproject commit 9a8e4ee159e59bb7308f3b5f6fcb89049da48777 +Subproject commit 8e62573de3dd9565b2209a3e8fe19a9900320b77 diff --git a/components/driver/include/driver/periph_ctrl.h b/components/driver/include/driver/periph_ctrl.h index e523598fa0..38770a060a 100644 --- a/components/driver/include/driver/periph_ctrl.h +++ b/components/driver/include/driver/periph_ctrl.h @@ -49,6 +49,8 @@ typedef enum { PERIPH_SDIO_SLAVE_MODULE, PERIPH_CAN_MODULE, PERIPH_EMAC_MODULE, + PERIPH_BT_MODULE, + PERIPH_WIFI_BT_COMMON_MODULE, } periph_module_t; /** diff --git a/components/driver/periph_ctrl.c b/components/driver/periph_ctrl.c index c61e2a4cc9..d63206df37 100644 --- a/components/driver/periph_ctrl.c +++ b/components/driver/periph_ctrl.c @@ -106,6 +106,10 @@ static uint32_t get_clk_en_mask(periph_module_t periph) return DPORT_CAN_CLK_EN; case PERIPH_EMAC_MODULE: return DPORT_WIFI_CLK_EMAC_EN; + case PERIPH_BT_MODULE: + return DPORT_WIFI_CLK_BT_EN_M; + case PERIPH_WIFI_BT_COMMON_MODULE: + return DPORT_WIFI_CLK_WIFI_BT_COMMON_M; default: return 0; } @@ -166,6 +170,9 @@ static uint32_t get_rst_en_mask(periph_module_t periph) return DPORT_CAN_RST; case PERIPH_EMAC_MODULE: return DPORT_WIFI_CLK_EMAC_EN; + case PERIPH_BT_MODULE: + case PERIPH_WIFI_BT_COMMON_MODULE: + return 0; default: return 0; } @@ -179,6 +186,8 @@ static bool is_wifi_clk_peripheral(periph_module_t periph) case PERIPH_SDMMC_MODULE: case PERIPH_SDIO_SLAVE_MODULE: case PERIPH_EMAC_MODULE: + case PERIPH_BT_MODULE: + case PERIPH_WIFI_BT_COMMON_MODULE: return true; default: return false; diff --git a/components/esp32/phy_init.c b/components/esp32/phy_init.c index f92f58abe2..ac114e9504 100644 --- a/components/esp32/phy_init.c +++ b/components/esp32/phy_init.c @@ -35,6 +35,7 @@ #include "phy.h" #include "phy_init_data.h" #include "esp_coexist.h" +#include "driver/periph_ctrl.h" static const char* TAG = "phy_init"; @@ -51,7 +52,7 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data, _lock_acquire(&s_phy_rf_init_lock); if (s_phy_rf_init_count == 0) { // Enable WiFi peripheral clock - DPORT_SET_PERI_REG_MASK(DPORT_WIFI_CLK_EN_REG, DPORT_WIFI_CLK_WIFI_EN | DPORT_WIFI_CLK_RNG_EN); + periph_module_enable(PERIPH_WIFI_BT_COMMON_MODULE); ESP_LOGV(TAG, "register_chipv7_phy, init_data=%p, cal_data=%p, mode=%d", init_data, calibration_data, mode); phy_set_wifi_mode_only(0); @@ -76,7 +77,7 @@ esp_err_t esp_phy_rf_deinit(void) // Disable PHY and RF. phy_close_rf(); // Disable WiFi peripheral clock. Do not disable clock for hardware RNG - DPORT_CLEAR_PERI_REG_MASK(DPORT_WIFI_CLK_EN_REG, DPORT_WIFI_CLK_WIFI_EN); + periph_module_disable(PERIPH_WIFI_BT_COMMON_MODULE); } else { #if CONFIG_SW_COEXIST_ENABLE coex_deinit(); diff --git a/components/soc/esp32/include/soc/dport_reg.h b/components/soc/esp32/include/soc/dport_reg.h index 98e6036526..3c2ae160d3 100644 --- a/components/soc/esp32/include/soc/dport_reg.h +++ b/components/soc/esp32/include/soc/dport_reg.h @@ -1053,6 +1053,9 @@ #define DPORT_WIFI_CLK_BT_EN_M ((DPORT_WIFI_CLK_BT_EN_V)<<(DPORT_WIFI_CLK_BT_EN_S)) #define DPORT_WIFI_CLK_BT_EN_V 0x61 #define DPORT_WIFI_CLK_BT_EN_S 11 +/* Mask for clock bits used by both WIFI and Bluetooth, bit 0, 3, 6, 7, 8, 9 */ +#define DPORT_WIFI_CLK_WIFI_BT_COMMON_M 0x000003c9 + /* Remaining single bit clock masks */ #define DPORT_WIFI_CLK_SDIOSLAVE_EN BIT(4) #define DPORT_WIFI_CLK_UNUSED_BIT5 BIT(5)