From ffcec3305736be52a403d903ffdf9f269ac9b5df Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Tue, 7 Mar 2023 14:45:30 +0800 Subject: [PATCH] modem clock: enable all clock enable of wifi module when PMU switch to ACTIVE from sleep state --- components/esp_hw_support/modem_clock.c | 28 ++++++++-------- components/esp_hw_support/sleep_clock.c | 33 +------------------ .../hal/esp32c6/include/hal/modem_syscon_ll.h | 24 +++++++++++++- 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/components/esp_hw_support/modem_clock.c b/components/esp_hw_support/modem_clock.c index 2c66910b9c..73887054b2 100644 --- a/components/esp_hw_support/modem_clock.c +++ b/components/esp_hw_support/modem_clock.c @@ -48,21 +48,17 @@ typedef struct modem_clock_context { static void IRAM_ATTR modem_clock_wifi_mac_configure(modem_clock_context_t *ctx, bool enable) { - modem_syscon_ll_enable_wifi_apb_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifi_mac_clock(ctx->hal->syscon_dev, enable); + if (enable) { + modem_syscon_ll_enable_wifi_apb_clock(ctx->hal->syscon_dev, enable); + modem_syscon_ll_enable_wifi_mac_clock(ctx->hal->syscon_dev, enable); + } } static void IRAM_ATTR modem_clock_wifi_bb_configure(modem_clock_context_t *ctx, bool enable) { - modem_syscon_ll_enable_wifibb_160x1_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifibb_80x1_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifibb_40x1_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifibb_80x_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifibb_40x_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifibb_80m_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifibb_44m_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifibb_40m_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_wifibb_22m_clock(ctx->hal->syscon_dev, enable); + if (enable) { + modem_syscon_ll_clk_wifibb_configure(ctx->hal->syscon_dev, enable); + } } static void IRAM_ATTR modem_clock_ble_mac_configure(modem_clock_context_t *ctx, bool enable) @@ -91,10 +87,12 @@ static void IRAM_ATTR modem_clock_coex_configure(modem_clock_context_t *ctx, boo static void IRAM_ATTR modem_clock_fe_configure(modem_clock_context_t *ctx, bool enable) { - modem_syscon_ll_enable_fe_apb_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_fe_cal_160m_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_fe_160m_clock(ctx->hal->syscon_dev, enable); - modem_syscon_ll_enable_fe_80m_clock(ctx->hal->syscon_dev, enable); + if (enable) { + modem_syscon_ll_enable_fe_apb_clock(ctx->hal->syscon_dev, enable); + modem_syscon_ll_enable_fe_cal_160m_clock(ctx->hal->syscon_dev, enable); + modem_syscon_ll_enable_fe_160m_clock(ctx->hal->syscon_dev, enable); + modem_syscon_ll_enable_fe_80m_clock(ctx->hal->syscon_dev, enable); + } } static void IRAM_ATTR modem_clock_i2c_master_configure(modem_clock_context_t *ctx, bool enable) diff --git a/components/esp_hw_support/sleep_clock.c b/components/esp_hw_support/sleep_clock.c index 1e82041597..c504a801e4 100644 --- a/components/esp_hw_support/sleep_clock.c +++ b/components/esp_hw_support/sleep_clock.c @@ -48,43 +48,12 @@ esp_err_t sleep_clock_modem_retention_init(void) { #define N_REGS_SYSCON() (((MODEM_SYSCON_MEM_CONF_REG - MODEM_SYSCON_TEST_CONF_REG) / 4) + 1) - #define MODEM_WIFI_RETENTION_CLOCK (MODEM_SYSCON_CLK_WIFI_APB_EN | MODEM_SYSCON_CLK_FE_APB_EN) - - #define WIFI_MAC_MODEM_STATE_CLK_EN (MODEM_SYSCON_CLK_WIFIMAC_EN | MODEM_SYSCON_CLK_WIFI_APB_EN) - #define WIFI_BB_MODEM_STATE_CLK_EN (MODEM_SYSCON_CLK_WIFIBB_22M_EN | \ - MODEM_SYSCON_CLK_WIFIBB_40M_EN | \ - MODEM_SYSCON_CLK_WIFIBB_44M_EN | \ - MODEM_SYSCON_CLK_WIFIBB_80M_EN | \ - MODEM_SYSCON_CLK_WIFIBB_40X_EN | \ - MODEM_SYSCON_CLK_WIFIBB_80X_EN | \ - MODEM_SYSCON_CLK_WIFIBB_40X1_EN | \ - MODEM_SYSCON_CLK_WIFIBB_80X1_EN | \ - MODEM_SYSCON_CLK_WIFIBB_160X1_EN) - #define FE_MODEM_STATE_CLK_EN (MODEM_SYSCON_CLK_FE_80M_EN | \ - MODEM_SYSCON_CLK_FE_160M_EN | \ - MODEM_SYSCON_CLK_FE_CAL_160M_EN | \ - MODEM_SYSCON_CLK_FE_APB_EN) - #define WIFI_MODEM_STATE_CLOCK_EN (WIFI_MAC_MODEM_STATE_CLK_EN | WIFI_BB_MODEM_STATE_CLK_EN | FE_MODEM_STATE_CLK_EN) - - const static sleep_retention_entries_config_t modem_regs_retention[] = { - [0] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK(0x00), MODEM_SYSCON_CLK_CONF1_REG, 0x0, 0x200, 0, 1), .owner = ENTRY(0) }, /* WiFi MAC clock disable */ - [1] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEMSYSCON_LINK(0x01), MODEM_SYSCON_TEST_CONF_REG, MODEM_SYSCON_TEST_CONF_REG, N_REGS_SYSCON(), 0, 0), .owner = ENTRY(0) | ENTRY(1) }, /* MODEM SYSCON */ - [2] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK(0x02), MODEM_SYSCON_CLK_CONF1_REG, MODEM_SYSCON_CLK_WIFIMAC_EN,0x200, 1, 0), .owner = ENTRY(0) }, /* WiFi MAC clock enable */ - [3] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK(0x03), MODEM_SYSCON_CLK_CONF1_REG, MODEM_WIFI_RETENTION_CLOCK, 0x10400, 0, 0), .owner = ENTRY(0) }, /* WiFi (MAC, BB and FE) retention clock enable */ - [4] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK(0x04), MODEM_SYSCON_CLK_CONF1_REG, WIFI_MODEM_STATE_CLOCK_EN, 0x1e7ff, 1, 0), .owner = ENTRY(1) } - }; - - const static sleep_retention_entries_config_t modem_retention_clock[] = { - [0] = { .config = REGDMA_LINK_WRITE_INIT (REGDMA_MODEMSYSCON_LINK(0xff), MODEM_SYSCON_CLK_CONF1_REG, 0x0, 0x10400, 0, 0), .owner = ENTRY(0) } /* WiFi (MAC, BB and FE) retention clock disable */ + [0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEMSYSCON_LINK(0), MODEM_SYSCON_TEST_CONF_REG, MODEM_SYSCON_TEST_CONF_REG, N_REGS_SYSCON(), 0, 0), .owner = ENTRY(0) | ENTRY(1) }, /* MODEM SYSCON */ }; esp_err_t err = sleep_retention_entries_create(modem_regs_retention, ARRAY_SIZE(modem_regs_retention), REGDMA_LINK_PRI_2, SLEEP_RETENTION_MODULE_CLOCK_MODEM); ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for modem (SYSCON) retention, 2 level priority"); - - err = sleep_retention_entries_create(modem_retention_clock, ARRAY_SIZE(modem_retention_clock), REGDMA_LINK_PRI_7, SLEEP_RETENTION_MODULE_CLOCK_MODEM); - ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for modem (SYSCON) retention, lowest level priority"); - ESP_LOGI(TAG, "Modem Power, Clock and Reset sleep retention initialization"); return ESP_OK; } diff --git a/components/hal/esp32c6/include/hal/modem_syscon_ll.h b/components/hal/esp32c6/include/hal/modem_syscon_ll.h index 503472350d..f89e4f7d81 100644 --- a/components/hal/esp32c6/include/hal/modem_syscon_ll.h +++ b/components/hal/esp32c6/include/hal/modem_syscon_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -253,6 +253,28 @@ static inline void modem_syscon_ll_reset_all(modem_syscon_dev_t *hw) hw->modem_rst_conf.val = 0; } + +__attribute__((always_inline)) +static inline void modem_syscon_ll_clk_conf1_configure(modem_syscon_dev_t *hw, bool en, uint32_t mask) +{ + if(en){ + hw->clk_conf1.val = hw->clk_conf1.val | mask; + } else { + hw->clk_conf1.val = hw->clk_conf1.val & ~mask; + } +} + +__attribute__((always_inline)) +static inline void modem_syscon_ll_clk_wifibb_configure(modem_syscon_dev_t *hw, bool en) +{ + /* Configure + clk_wifibb_22m / clk_wifibb_40m / clk_wifibb_44m / clk_wifibb_80m + clk_wifibb_40x / clk_wifibb_80x / clk_wifibb_40x1 / clk_wifibb_80x1 + clk_wifibb_160x1 + */ + modem_syscon_ll_clk_conf1_configure(hw, en, 0x1ff); +} + __attribute__((always_inline)) static inline void modem_syscon_ll_enable_wifibb_22m_clock(modem_syscon_dev_t *hw, bool en) {