Skip to content

Commit

Permalink
Merge branch 'feature/add_modem_module_rst_api_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
modem_clock: add modem module mac reset api (backport v5.1)

See merge request espressif/esp-idf!24441
  • Loading branch information
jack0c committed Jul 4, 2023
2 parents 11d34b1 + afc889e commit 159e802
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 82 deletions.
28 changes: 28 additions & 0 deletions components/esp_hw_support/include/esp_private/esp_modem_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,45 @@ 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);

/**
* @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
*
Expand Down
29 changes: 24 additions & 5 deletions components/esp_hw_support/modem_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
modem_syscon_ll_reset_wifimac(ctx->hal->syscon_dev);
portEXIT_CRITICAL_SAFE(&ctx->lock);
switch (module)
{
#if SOC_WIFI_SUPPORTED
case PERIPH_WIFI_MODULE:
modem_syscon_ll_reset_wifimac(ctx->hal->syscon_dev);
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))
Expand Down
5 changes: 2 additions & 3 deletions components/esp_wifi/esp32c6/esp_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 4 additions & 36 deletions components/hal/esp32c6/include/hal/clk_gate_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions components/hal/esp32c6/include/hal/modem_lpcon_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
23 changes: 4 additions & 19 deletions components/hal/esp32c6/include/hal/modem_syscon_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,30 +205,15 @@ static inline void modem_syscon_ll_reset_zbmac(modem_syscon_dev_t *hw)
}

__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_ecb(modem_syscon_dev_t *hw)
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_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_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;
}

Expand Down
14 changes: 14 additions & 0 deletions components/hal/esp32h2/include/hal/modem_lpcon_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
23 changes: 4 additions & 19 deletions components/hal/esp32h2/include/hal/modem_syscon_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,15 @@ static inline void modem_syscon_ll_reset_zbmac(modem_syscon_dev_t *hw)
}

__attribute__((always_inline))
static inline void modem_syscon_ll_reset_modem_ecb(modem_syscon_dev_t *hw)
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_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_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;
}

Expand Down

0 comments on commit 159e802

Please sign in to comment.