Merge branch 'feature/add_modem_module_rst_api_v5.1' into 'release/v5.1'

modem_clock: add modem module mac reset api (backport v5.1)

See merge request espressif/esp-idf!24441
This commit is contained in:
Jiang Jiang Jian 2023-07-04 12:15:33 +08:00
commit 159e80246b
8 changed files with 112 additions and 86 deletions

View File

@ -29,6 +29,16 @@ extern "C" {
* module depends on the wifi mac, wifi baseband and FE, when wifi module
* clock is enabled, the wifi MAC, baseband and FE clocks will be enabled
*
* This interface and modem_clock_module_disable will jointly maintain the
* ref_cnt of each device clock source. The ref_cnt indicates how many modules
* are relying on the clock source. Each enable ops will add 1 to the ref_cnt of
* the clock source that the module depends on, and only when the ref_cnt of
* the module is from 0 to 1 will the clock enable be actually configured.
*
* !!! Do not use the hal/ll layer interface to configure the clock for the
* consistency of the hardware state maintained in the driver and the hardware
* actual state.
*
* @param module modem module
*/
void modem_clock_module_enable(periph_module_t module);
@ -36,10 +46,28 @@ void modem_clock_module_enable(periph_module_t module);
/**
* @brief Disable the clock of modem module
*
* This interface and modem_clock_module_enable will jointly maintain the ref_cnt
* of each device clock source. The ref_cnt indicates how many modules are relying
* on the clock source. Each disable ops will minus 1 to the ref_cnt of the clock
* source that the module depends on, and only when the ref_cnt of the module is
* from 1 to 0 will the clock disable be actually configured.
*
* !!! Do not use the hal/ll layer interface to configure the clock for the
* consistency of the hardware state maintained in the driver and the hardware
* actual state.
*
* @param module modem module
*/
void modem_clock_module_disable(periph_module_t module);
/**
* @brief Reset the mac of modem module
*
* @param module modem module, must be one of
* PERIPH_WIFI_MODULE / PERIPH_BT_MODULE /PERIPH_IEEE802154_MODULE
*/
void modem_clock_module_mac_reset(periph_module_t module);
/**
* @brief Initialize the clock gating control signal of each clock domain of the modem
*

View File

@ -214,15 +214,34 @@ static void IRAM_ATTR modem_clock_device_disable(modem_clock_context_t *ctx, uin
assert(refs >= 0);
}
void IRAM_ATTR modem_clock_wifi_mac_reset(void)
void IRAM_ATTR modem_clock_module_mac_reset(periph_module_t module)
{
#if SOC_WIFI_SUPPORTED
modem_clock_context_t *ctx = MODEM_CLOCK_instance();
portENTER_CRITICAL_SAFE(&ctx->lock);
//TODO: IDF-5713
switch (module)
{
#if SOC_WIFI_SUPPORTED
case PERIPH_WIFI_MODULE:
modem_syscon_ll_reset_wifimac(ctx->hal->syscon_dev);
portEXIT_CRITICAL_SAFE(&ctx->lock);
break;
#endif
#if SOC_BT_SUPPORTED
case PERIPH_BT_MODULE:
modem_syscon_ll_reset_btmac(ctx->hal->syscon_dev);
modem_syscon_ll_reset_btmac_apb(ctx->hal->syscon_dev);
modem_syscon_ll_reset_ble_timer(ctx->hal->syscon_dev);
modem_syscon_ll_reset_modem_sec(ctx->hal->syscon_dev);
break;
#endif
#if SOC_IEEE802154_SUPPORTED
case PERIPH_IEEE802154_MODULE:
modem_syscon_ll_reset_zbmac(ctx->hal->syscon_dev);
break;
default:
#endif
assert(0);
}
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))

View File

@ -28,6 +28,7 @@
#include "esp_event.h"
#include "esp_heap_caps.h"
#include "esp_timer.h"
#include "esp_private/esp_modem_clock.h"
#include "esp_private/wifi_os_adapter.h"
#include "esp_private/wifi.h"
#include "esp_phy_init.h"
@ -297,9 +298,7 @@ static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat
static void wifi_reset_mac_wrapper(void)
{
// TODO: IDF-5713
modem_clock_wifi_mac_reset();
ESP_LOGW(TAG, "wifi_reset_mac_wrapper() has not been implemented yet");
modem_clock_module_mac_reset(PERIPH_WIFI_MODULE);
}
static void wifi_clock_enable_wrapper(void)

View File

@ -19,7 +19,7 @@ extern "C" {
#endif
static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
{ // TODO: IDF-5713
{
switch (periph) {
case PERIPH_SARADC_MODULE:
return PCR_SARADC_CLK_EN;
@ -82,25 +82,13 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
//TODO: LP_PERIPH modules are added temporarily and will be moved to a separate API (IDF-7374).
case PERIPH_LP_I2C0_MODULE:
return LPPERI_LP_EXT_I2C_CK_EN;
// case PERIPH_RNG_MODULE:
// return PCR_WIFI_CLK_RNG_EN;
// case PERIPH_WIFI_MODULE:
// return PCR_WIFI_CLK_WIFI_EN_M;
// case PERIPH_BT_MODULE:
// return PCR_WIFI_CLK_BT_EN_M;
// case PERIPH_WIFI_BT_COMMON_MODULE:
// return PCR_WIFI_CLK_WIFI_BT_COMMON_M;
// case PERIPH_BT_BASEBAND_MODULE:
// return PCR_BT_BASEBAND_EN;
// case PERIPH_BT_LC_MODULE:
// return PCR_BT_LC_EN;
default:
return 0;
}
}
static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool enable)
{ // TODO: IDF-5713
{
(void)enable; // unused
switch (periph) {
@ -178,34 +166,14 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en
//TODO: LP_PERIPH modules are added temporarily and will be moved to a separate API (IDF-7374).
case PERIPH_LP_I2C0_MODULE:
return LPPERI_LP_EXT_I2C_RESET_EN;
// case PERIPH_RNG_MODULE:
// return PCR_WIFI_CLK_RNG_EN;
// case PERIPH_WIFI_MODULE:
// return PCR_WIFI_CLK_WIFI_EN_M;
// case PERIPH_BT_MODULE:
// return PCR_WIFI_CLK_BT_EN_M;
// case PERIPH_WIFI_BT_COMMON_MODULE:
// return PCR_WIFI_CLK_WIFI_BT_COMMON_M;
// case PERIPH_BT_BASEBAND_MODULE:
// return PCR_BT_BASEBAND_EN;
// case PERIPH_BT_LC_MODULE:
// return PCR_BT_LC_EN;
default:
return 0;
}
}
static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
{ // TODO: IDF-5713
{
switch (periph) {
// case PERIPH_RNG_MODULE:
// case PERIPH_WIFI_MODULE:
// case PERIPH_BT_MODULE:
// case PERIPH_WIFI_BT_COMMON_MODULE:
// case PERIPH_BT_BASEBAND_MODULE:
// case PERIPH_BT_LC_MODULE:
// return SYSTEM_WIFI_CLK_EN_REG;
case PERIPH_SARADC_MODULE:
return PCR_SARADC_CONF_REG;
case PERIPH_RMT_MODULE:
@ -273,7 +241,7 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
}
static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph)
{ // TODO: IDF-5713
{
switch (periph) {
case PERIPH_SARADC_MODULE:
return PCR_SARADC_CONF_REG;

View File

@ -216,6 +216,34 @@ static inline void modem_lpcon_ll_set_lp_apb_icg_bitmap(modem_lpcon_dev_t *hw, u
hw->clk_conf_power_st.clk_lp_apb_st_map = bitmap;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_reset_wifipwr(modem_lpcon_dev_t *hw)
{
hw->rst_conf.rst_wifipwr = 1;
hw->rst_conf.rst_wifipwr = 0;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_reset_coex(modem_lpcon_dev_t *hw)
{
hw->rst_conf.rst_coex = 1;
hw->rst_conf.rst_coex = 0;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_reset_i2c_master(modem_lpcon_dev_t *hw)
{
hw->rst_conf.rst_i2c_mst = 1;
hw->rst_conf.rst_i2c_mst = 0;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_reset_ble_rtc_timer(modem_lpcon_dev_t *hw)
{
hw->rst_conf.rst_lp_timer = 1;
hw->rst_conf.rst_lp_timer = 0;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_reset_all(modem_lpcon_dev_t *hw)
{

View File

@ -204,31 +204,16 @@ static inline void modem_syscon_ll_reset_zbmac(modem_syscon_dev_t *hw)
hw->modem_rst_conf.rst_zbmac = 0;
}
__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_ecb(modem_syscon_dev_t *hw)
{
hw->modem_rst_conf.rst_modem_ecb = 1;
hw->modem_rst_conf.rst_modem_ecb = 0;
}
__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_ccm(modem_syscon_dev_t *hw)
{
hw->modem_rst_conf.rst_modem_ccm = 1;
hw->modem_rst_conf.rst_modem_ccm = 0;
}
__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_bah(modem_syscon_dev_t *hw)
{
hw->modem_rst_conf.rst_modem_bah = 1;
hw->modem_rst_conf.rst_modem_bah = 0;
}
__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw)
{
hw->modem_rst_conf.rst_modem_ecb = 1;
hw->modem_rst_conf.rst_modem_ccm = 1;
hw->modem_rst_conf.rst_modem_bah = 1;
hw->modem_rst_conf.rst_modem_sec = 1;
hw->modem_rst_conf.rst_modem_ecb = 0;
hw->modem_rst_conf.rst_modem_ccm = 0;
hw->modem_rst_conf.rst_modem_bah = 0;
hw->modem_rst_conf.rst_modem_sec = 0;
}

View File

@ -96,6 +96,20 @@ static inline void modem_lpcon_ll_enable_fe_mem_force_clock(modem_lpcon_dev_t *h
hw->clk_conf_force_on.clk_fe_mem_fo = en;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_reset_coex(modem_lpcon_dev_t *hw)
{
hw->rst_conf.rst_coex = 1;
hw->rst_conf.rst_coex = 0;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_reset_i2c_master(modem_lpcon_dev_t *hw)
{
hw->rst_conf.rst_i2c_mst = 1;
hw->rst_conf.rst_i2c_mst = 0;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_reset_all(modem_lpcon_dev_t *hw)
{

View File

@ -150,31 +150,16 @@ static inline void modem_syscon_ll_reset_zbmac(modem_syscon_dev_t *hw)
hw->modem_rst_conf.rst_zbmac = 0;
}
__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_ecb(modem_syscon_dev_t *hw)
{
hw->modem_rst_conf.rst_modem_ecb = 1;
hw->modem_rst_conf.rst_modem_ecb = 0;
}
__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_ccm(modem_syscon_dev_t *hw)
{
hw->modem_rst_conf.rst_modem_ccm = 1;
hw->modem_rst_conf.rst_modem_ccm = 0;
}
__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_bah(modem_syscon_dev_t *hw)
{
hw->modem_rst_conf.rst_modem_bah = 1;
hw->modem_rst_conf.rst_modem_bah = 0;
}
__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw)
{
hw->modem_rst_conf.rst_modem_ecb = 1;
hw->modem_rst_conf.rst_modem_ccm = 1;
hw->modem_rst_conf.rst_modem_bah = 1;
hw->modem_rst_conf.rst_modem_sec = 1;
hw->modem_rst_conf.rst_modem_ecb = 0;
hw->modem_rst_conf.rst_modem_ccm = 0;
hw->modem_rst_conf.rst_modem_bah = 0;
hw->modem_rst_conf.rst_modem_sec = 0;
}