Merge branch 'bugfix/manage_i2c_clock_with_modem_clock_driver_v5.1' into 'release/v5.1'

fix(esp_hw_support): manage i2c_ana_mst clock witch modem clock driver (backport v5.1)

See merge request espressif/esp-idf!25164
This commit is contained in:
Jiang Jiang Jian 2023-08-04 17:39:14 +08:00
commit e5199390a3
7 changed files with 69 additions and 16 deletions

View File

@ -277,15 +277,17 @@ void IRAM_ATTR modem_clock_module_mac_reset(periph_module_t module)
portEXIT_CRITICAL_SAFE(&ctx->lock); portEXIT_CRITICAL_SAFE(&ctx->lock);
} }
#define WIFI_CLOCK_DEPS (BIT(MODEM_CLOCK_WIFI_MAC) | BIT(MODEM_CLOCK_FE) | BIT(MODEM_CLOCK_WIFI_BB) | BIT(MODEM_CLOCK_COEXIST)) #define WIFI_CLOCK_DEPS (BIT(MODEM_CLOCK_WIFI_MAC) | BIT(MODEM_CLOCK_WIFI_BB) | BIT(MODEM_CLOCK_COEXIST))
#define BLE_CLOCK_DEPS (BIT(MODEM_CLOCK_BLE_MAC) | BIT(MODEM_CLOCK_FE) | BIT(MODEM_CLOCK_BLE_BB) | BIT(MODEM_CLOCK_ETM) | BIT(MODEM_CLOCK_COEXIST)) #define BLE_CLOCK_DEPS (BIT(MODEM_CLOCK_BLE_MAC) | BIT(MODEM_CLOCK_BLE_BB) | BIT(MODEM_CLOCK_ETM) | BIT(MODEM_CLOCK_COEXIST))
#define IEEE802154_CLOCK_DEPS (BIT(MODEM_CLOCK_802154_MAC) | BIT(MODEM_CLOCK_FE) | BIT(MODEM_CLOCK_BLE_BB) | BIT(MODEM_CLOCK_ETM) | BIT(MODEM_CLOCK_COEXIST)) #define IEEE802154_CLOCK_DEPS (BIT(MODEM_CLOCK_802154_MAC) | BIT(MODEM_CLOCK_BLE_BB) | BIT(MODEM_CLOCK_ETM) | BIT(MODEM_CLOCK_COEXIST))
#define COEXIST_CLOCK_DEPS (BIT(MODEM_CLOCK_COEXIST)) #define COEXIST_CLOCK_DEPS (BIT(MODEM_CLOCK_COEXIST))
#define PHY_CLOCK_DEPS (BIT(MODEM_CLOCK_I2C_MASTER) | BIT(MODEM_CLOCK_FE)) #define PHY_CLOCK_DEPS (BIT(MODEM_CLOCK_I2C_MASTER) | BIT(MODEM_CLOCK_FE))
#define I2C_ANA_MST_CLOCK_DEPS (BIT(MODEM_CLOCK_I2C_MASTER))
static inline uint32_t modem_clock_get_module_deps(periph_module_t module) static inline uint32_t modem_clock_get_module_deps(periph_module_t module)
{ {
uint32_t deps = 0; uint32_t deps = 0;
if (module == PERIPH_ANA_I2C_MASTER_MODULE) {deps = I2C_ANA_MST_CLOCK_DEPS;}
if (module == PERIPH_PHY_MODULE) {deps = PHY_CLOCK_DEPS;} if (module == PERIPH_PHY_MODULE) {deps = PHY_CLOCK_DEPS;}
else if (module == PERIPH_COEX_MODULE) { deps = COEXIST_CLOCK_DEPS; } else if (module == PERIPH_COEX_MODULE) { deps = COEXIST_CLOCK_DEPS; }
#if SOC_WIFI_SUPPORTED #if SOC_WIFI_SUPPORTED

View File

@ -17,10 +17,15 @@
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
#include "hal/clk_tree_ll.h" #include "hal/clk_tree_ll.h"
#include "hal/regi2c_ctrl_ll.h" #include "hal/regi2c_ctrl_ll.h"
#include "hal/modem_lpcon_ll.h"
#include "soc/io_mux_reg.h" #include "soc/io_mux_reg.h"
#include "soc/lp_aon_reg.h" #include "soc/lp_aon_reg.h"
#ifdef BOOTLOADER_BUILD
#include "hal/modem_lpcon_ll.h"
#else
#include "esp_private/esp_modem_clock.h"
#endif
static const char *TAG = "rtc_clk"; static const char *TAG = "rtc_clk";
// Current PLL frequency, in 480MHz. Zero if PLL is not enabled. // Current PLL frequency, in 480MHz. Zero if PLL is not enabled.
@ -138,12 +143,25 @@ static void rtc_clk_bbpll_enable(void)
clk_ll_bbpll_enable(); clk_ll_bbpll_enable();
} }
static void rtc_clk_enable_i2c_ana_master_clock(bool enable)
{
#ifdef BOOTLOADER_BUILD
modem_lpcon_ll_enable_i2c_master_clock(&MODEM_LPCON, enable);
#else
if (enable) {
modem_clock_module_enable(PERIPH_ANA_I2C_MASTER_MODULE);
} else {
modem_clock_module_disable(PERIPH_ANA_I2C_MASTER_MODULE);
}
#endif
}
static void rtc_clk_bbpll_configure(rtc_xtal_freq_t xtal_freq, int pll_freq) static void rtc_clk_bbpll_configure(rtc_xtal_freq_t xtal_freq, int pll_freq)
{ {
/* Digital part */ /* Digital part */
clk_ll_bbpll_set_freq_mhz(pll_freq); clk_ll_bbpll_set_freq_mhz(pll_freq);
/* Analog part */ /* Analog part */
modem_lpcon_ll_enable_i2c_master_clock(&MODEM_LPCON, true); rtc_clk_enable_i2c_ana_master_clock(true);
/* BBPLL CALIBRATION START */ /* BBPLL CALIBRATION START */
regi2c_ctrl_ll_bbpll_calibration_start(); regi2c_ctrl_ll_bbpll_calibration_start();
clk_ll_bbpll_set_config(pll_freq, xtal_freq); clk_ll_bbpll_set_config(pll_freq, xtal_freq);
@ -151,8 +169,7 @@ static void rtc_clk_bbpll_configure(rtc_xtal_freq_t xtal_freq, int pll_freq)
while(!regi2c_ctrl_ll_bbpll_calibration_is_done()); while(!regi2c_ctrl_ll_bbpll_calibration_is_done());
/* BBPLL CALIBRATION STOP */ /* BBPLL CALIBRATION STOP */
regi2c_ctrl_ll_bbpll_calibration_stop(); regi2c_ctrl_ll_bbpll_calibration_stop();
modem_lpcon_ll_enable_i2c_master_clock(&MODEM_LPCON, false); rtc_clk_enable_i2c_ana_master_clock(false);
s_cur_pll_freq = pll_freq; s_cur_pll_freq = pll_freq;
} }

View File

@ -17,11 +17,16 @@
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
#include "hal/clk_tree_ll.h" #include "hal/clk_tree_ll.h"
#include "hal/regi2c_ctrl_ll.h" #include "hal/regi2c_ctrl_ll.h"
#include "hal/modem_lpcon_ll.h"
#include "soc/io_mux_reg.h" #include "soc/io_mux_reg.h"
#include "soc/lp_aon_reg.h" #include "soc/lp_aon_reg.h"
#include "soc/lp_clkrst_reg.h" #include "soc/lp_clkrst_reg.h"
#ifdef BOOTLOADER_BUILD
#include "hal/modem_lpcon_ll.h"
#else
#include "esp_private/esp_modem_clock.h"
#endif
static const char *TAG = "rtc_clk"; static const char *TAG = "rtc_clk";
// Current PLL frequency, in 96MHz. Zero if PLL is not enabled. // Current PLL frequency, in 96MHz. Zero if PLL is not enabled.
@ -155,12 +160,25 @@ static void rtc_clk_bbpll_enable(void)
clk_ll_bbpll_enable(); clk_ll_bbpll_enable();
} }
static void rtc_clk_enable_i2c_ana_master_clock(bool enable)
{
#ifdef BOOTLOADER_BUILD
modem_lpcon_ll_enable_i2c_master_clock(&MODEM_LPCON, enable);
#else
if (enable) {
modem_clock_module_enable(PERIPH_ANA_I2C_MASTER_MODULE);
} else {
modem_clock_module_disable(PERIPH_ANA_I2C_MASTER_MODULE);
}
#endif
}
static void rtc_clk_bbpll_configure(rtc_xtal_freq_t xtal_freq, int pll_freq) static void rtc_clk_bbpll_configure(rtc_xtal_freq_t xtal_freq, int pll_freq)
{ {
/* Digital part */ /* Digital part */
clk_ll_bbpll_set_freq_mhz(pll_freq); clk_ll_bbpll_set_freq_mhz(pll_freq);
/* Analog part */ /* Analog part */
modem_lpcon_ll_enable_i2c_master_clock(&MODEM_LPCON, true); rtc_clk_enable_i2c_ana_master_clock(true);
/* BBPLL CALIBRATION START */ /* BBPLL CALIBRATION START */
regi2c_ctrl_ll_bbpll_calibration_start(); regi2c_ctrl_ll_bbpll_calibration_start();
clk_ll_bbpll_set_config(pll_freq, xtal_freq); clk_ll_bbpll_set_config(pll_freq, xtal_freq);
@ -168,8 +186,7 @@ static void rtc_clk_bbpll_configure(rtc_xtal_freq_t xtal_freq, int pll_freq)
while(!regi2c_ctrl_ll_bbpll_calibration_is_done()); while(!regi2c_ctrl_ll_bbpll_calibration_is_done());
/* BBPLL CALIBRATION STOP */ /* BBPLL CALIBRATION STOP */
regi2c_ctrl_ll_bbpll_calibration_stop(); regi2c_ctrl_ll_bbpll_calibration_stop();
modem_lpcon_ll_enable_i2c_master_clock(&MODEM_LPCON, false); rtc_clk_enable_i2c_ana_master_clock(false);
s_cur_pll_freq = pll_freq; s_cur_pll_freq = pll_freq;
} }

View File

@ -898,11 +898,14 @@ static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
static esp_err_t esp_light_sleep_inner(uint32_t pd_flags, static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
uint32_t flash_enable_time_us) uint32_t flash_enable_time_us)
{ {
#if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED
rtc_vddsdio_config_t vddsdio_config = rtc_vddsdio_get_config();
#endif
// Enter sleep // Enter sleep
esp_err_t reject = esp_sleep_start(pd_flags, ESP_SLEEP_MODE_LIGHT_SLEEP); esp_err_t reject = esp_sleep_start(pd_flags, ESP_SLEEP_MODE_LIGHT_SLEEP);
#if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED #if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED
rtc_vddsdio_config_t vddsdio_config = rtc_vddsdio_get_config();
// If VDDSDIO regulator was controlled by RTC registers before sleep, // If VDDSDIO regulator was controlled by RTC registers before sleep,
// restore the configuration. // restore the configuration.
if (vddsdio_config.force) { if (vddsdio_config.force) {

View File

@ -9,6 +9,10 @@
#include "esp_phy_init.h" #include "esp_phy_init.h"
#include "esp_private/phy.h" #include "esp_private/phy.h"
#if SOC_MODEM_CLOCK_IS_INDEPENDENT
#include "esp_private/esp_modem_clock.h"
#endif
#define PHY_ENABLE_VERSION_PRINT 1 #define PHY_ENABLE_VERSION_PRINT 1
static DRAM_ATTR portMUX_TYPE s_phy_int_mux = portMUX_INITIALIZER_UNLOCKED; static DRAM_ATTR portMUX_TYPE s_phy_int_mux = portMUX_INITIALIZER_UNLOCKED;
@ -46,6 +50,9 @@ void esp_phy_enable(void)
{ {
_lock_acquire(&s_phy_access_lock); _lock_acquire(&s_phy_access_lock);
if (s_phy_access_ref == 0) { if (s_phy_access_ref == 0) {
#if SOC_MODEM_CLOCK_IS_INDEPENDENT
modem_clock_module_enable(PERIPH_PHY_MODULE);
#endif
if (!s_phy_is_enabled) { if (!s_phy_is_enabled) {
register_chipv7_phy(NULL, NULL, PHY_RF_CAL_FULL); register_chipv7_phy(NULL, NULL, PHY_RF_CAL_FULL);
phy_version_print(); phy_version_print();
@ -73,6 +80,9 @@ void esp_phy_disable(void)
phy_track_pll_deinit(); phy_track_pll_deinit();
phy_close_rf(); phy_close_rf();
phy_xpd_tsens(); phy_xpd_tsens();
#if SOC_MODEM_CLOCK_IS_INDEPENDENT
modem_clock_module_disable(PERIPH_PHY_MODULE);
#endif
} }
_lock_release(&s_phy_access_lock); _lock_release(&s_phy_access_lock);

View File

@ -49,11 +49,13 @@ typedef enum {
PERIPH_IEEE802154_MODULE, PERIPH_IEEE802154_MODULE,
PERIPH_COEX_MODULE, PERIPH_COEX_MODULE,
PERIPH_PHY_MODULE, PERIPH_PHY_MODULE,
PERIPH_ANA_I2C_MASTER_MODULE,
PERIPH_MODULE_MAX PERIPH_MODULE_MAX
/* !!! Don't append soc modules here !!! */
} periph_module_t; } periph_module_t;
#define PERIPH_MODEM_MODULE_MIN PERIPH_WIFI_MODULE #define PERIPH_MODEM_MODULE_MIN PERIPH_WIFI_MODULE
#define PERIPH_MODEM_MODULE_MAX PERIPH_PHY_MODULE #define PERIPH_MODEM_MODULE_MAX PERIPH_ANA_I2C_MASTER_MODULE
#define PERIPH_MODEM_MODULE_NUM (PERIPH_MODEM_MODULE_MAX - PERIPH_MODEM_MODULE_MIN + 1) #define PERIPH_MODEM_MODULE_NUM (PERIPH_MODEM_MODULE_MAX - PERIPH_MODEM_MODULE_MIN + 1)
#define IS_MODEM_MODULE(periph) ((periph>=PERIPH_MODEM_MODULE_MIN) && (periph<=PERIPH_MODEM_MODULE_MAX)) #define IS_MODEM_MODULE(periph) ((periph>=PERIPH_MODEM_MODULE_MIN) && (periph<=PERIPH_MODEM_MODULE_MAX))

View File

@ -47,11 +47,13 @@ typedef enum {
PERIPH_IEEE802154_MODULE, PERIPH_IEEE802154_MODULE,
PERIPH_COEX_MODULE, PERIPH_COEX_MODULE,
PERIPH_PHY_MODULE, PERIPH_PHY_MODULE,
PERIPH_ANA_I2C_MASTER_MODULE,
PERIPH_MODULE_MAX PERIPH_MODULE_MAX
/* !!! Don't append soc modules here !!! */
} periph_module_t; } periph_module_t;
#define PERIPH_MODEM_MODULE_MIN PERIPH_BT_MODULE #define PERIPH_MODEM_MODULE_MIN PERIPH_BT_MODULE
#define PERIPH_MODEM_MODULE_MAX PERIPH_PHY_MODULE #define PERIPH_MODEM_MODULE_MAX PERIPH_ANA_I2C_MASTER_MODULE
#define PERIPH_MODEM_MODULE_NUM (PERIPH_MODEM_MODULE_MAX - PERIPH_MODEM_MODULE_MIN + 1) #define PERIPH_MODEM_MODULE_NUM (PERIPH_MODEM_MODULE_MAX - PERIPH_MODEM_MODULE_MIN + 1)
#define IS_MODEM_MODULE(periph) ((periph>=PERIPH_MODEM_MODULE_MIN) && (periph<=PERIPH_MODEM_MODULE_MAX)) #define IS_MODEM_MODULE(periph) ((periph>=PERIPH_MODEM_MODULE_MIN) && (periph<=PERIPH_MODEM_MODULE_MAX))