Skip to content

Commit

Permalink
Merge branch 'feature/esp32c5beta3_light_sleep_support_stage_0' into …
Browse files Browse the repository at this point in the history
…'master'

feat(esp_hw_support): esp32c5 sleep support (Stage 1: support modem clock)

Closes IDF-8845

See merge request espressif/esp-idf!29839
  • Loading branch information
10086loutianhao committed Mar 27, 2024
2 parents bfd3586 + 85e803d commit 5fa57d1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void modem_clock_module_disable(periph_module_t module);
*/
void modem_clock_module_mac_reset(periph_module_t module);

#if SOC_PMU_SUPPORTED
#if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND
/**
* @brief Enable modem clock domain clock gate to gate it's output
*
Expand Down
17 changes: 10 additions & 7 deletions components/esp_hw_support/modem_clock.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -75,6 +75,7 @@ static void IRAM_ATTR modem_clock_wifi_bb_configure(modem_clock_context_t *ctx,
#if SOC_BT_SUPPORTED
static void IRAM_ATTR modem_clock_ble_mac_configure(modem_clock_context_t *ctx, bool enable)
{
modem_syscon_ll_enable_bt_mac_clock(ctx->hal->syscon_dev, enable);
modem_syscon_ll_enable_modem_sec_clock(ctx->hal->syscon_dev, enable);
modem_syscon_ll_enable_ble_timer_clock(ctx->hal->syscon_dev, enable);
}
Expand Down Expand Up @@ -156,7 +157,7 @@ modem_clock_context_t * __attribute__((weak)) IRAM_ATTR MODEM_CLOCK_instance(voi
return &modem_clock_context;
}

#if SOC_PM_SUPPORT_PMU_MODEM_STATE
#if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND
esp_err_t modem_clock_domain_clk_gate_enable(modem_clock_domain_t domain, pmu_hp_icg_modem_mode_t mode)
{
if (domain >= MODEM_CLOCK_DOMAIN_MAX || domain < MODEM_CLOCK_DOMAIN_MODEM_APB) {
Expand Down Expand Up @@ -188,7 +189,7 @@ esp_err_t modem_clock_domain_clk_gate_disable(modem_clock_domain_t domain, pmu_h
portEXIT_CRITICAL_SAFE(&MODEM_CLOCK_instance()->lock);
return ESP_OK;
}
#endif // #if SOC_PM_SUPPORT_PMU_MODEM_STATE
#endif // #if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND

static void IRAM_ATTR modem_clock_device_enable(modem_clock_context_t *ctx, uint32_t dev_map)
{
Expand Down Expand Up @@ -289,13 +290,13 @@ static IRAM_ATTR uint32_t modem_clock_get_module_deps(periph_module_t module)
return deps;
}

#if SOC_PM_SUPPORT_PMU_MODEM_STATE
/* the ICG code's bit 0, 1 and 2 indicates the ICG state
* of pmu SLEEP, MODEM and ACTIVE mode respectively */
#define ICG_NOGATING_ACTIVE (BIT(PMU_HP_ICG_MODEM_CODE_ACTIVE))
#define ICG_NOGATING_SLEEP (BIT(PMU_HP_ICG_MODEM_CODE_SLEEP))
#define ICG_NOGATING_MODEM (BIT(PMU_HP_ICG_MODEM_CODE_MODEM))
#define ICG_NOGATING_ACTIVE (BIT(PMU_HP_ICG_MODEM_CODE_ACTIVE))

#if !CONFIG_IDF_TARGET_ESP32H2
static const DRAM_ATTR uint32_t initial_gating_mode[MODEM_CLOCK_DOMAIN_MAX] = {
[MODEM_CLOCK_DOMAIN_MODEM_APB] = ICG_NOGATING_ACTIVE | ICG_NOGATING_MODEM,
[MODEM_CLOCK_DOMAIN_MODEM_PERIPH] = ICG_NOGATING_ACTIVE,
Expand All @@ -308,7 +309,9 @@ static const DRAM_ATTR uint32_t initial_gating_mode[MODEM_CLOCK_DOMAIN_MAX] = {
[MODEM_CLOCK_DOMAIN_COEX] = ICG_NOGATING_ACTIVE | ICG_NOGATING_MODEM,
[MODEM_CLOCK_DOMAIN_WIFIPWR] = ICG_NOGATING_ACTIVE | ICG_NOGATING_MODEM,
};
#endif

#if !CONFIG_IDF_TARGET_ESP32H2 //TODO: PM-92
static IRAM_ATTR void modem_clock_module_icg_map_init_all(void)
{
portENTER_CRITICAL_SAFE(&MODEM_CLOCK_instance()->lock);
Expand All @@ -318,12 +321,12 @@ static IRAM_ATTR void modem_clock_module_icg_map_init_all(void)
}
portEXIT_CRITICAL_SAFE(&MODEM_CLOCK_instance()->lock);
}
#endif // SOC_PM_SUPPORT_PMU_MODEM_STATE
#endif

void IRAM_ATTR modem_clock_module_enable(periph_module_t module)
{
assert(IS_MODEM_MODULE(module));
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
#if !CONFIG_IDF_TARGET_ESP32H2
modem_clock_module_icg_map_init_all();
#endif
uint32_t deps = modem_clock_get_module_deps(module);
Expand Down
24 changes: 19 additions & 5 deletions components/hal/esp32c5/include/hal/modem_syscon_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,30 @@ static inline void modem_syscon_ll_enable_fe_160m_clock(modem_syscon_dev_t *hw,
}

__attribute__((always_inline))
static inline void modem_syscon_ll_enable_fe_cal_160m_clock(modem_syscon_dev_t *hw, bool en)
static inline void modem_syscon_ll_enable_fe_apb_clock(modem_syscon_dev_t *hw, bool en)
{
HAL_ASSERT(0 && "not implemented yet");
// hw->clk_conf1.clk_fe_cal_160m_en = en;
hw->clk_conf1.clk_fe_apb_en = en;
}

// The modem_syscon of esp32c5beta3 adds the enablement of the adc clock on the analog front end compared to esp32h2 and esp32c6.
__attribute__((always_inline))
static inline void modem_syscon_ll_enable_fe_apb_clock(modem_syscon_dev_t *hw, bool en)
static inline void modem_syscon_ll_enable_fe_adc_clock(modem_syscon_dev_t *hw, bool en)
{
hw->clk_conf1.clk_fe_apb_en = en;
hw->clk_conf1.clk_fe_adc_en = en;
}

// The modem_syscon of esp32c5beta3 adds the enablement of the dac clock on the analog front end compared to esp32h2 and esp32c6.
__attribute__((always_inline))
static inline void modem_syscon_ll_enable_fe_dac_clock(modem_syscon_dev_t *hw, bool en)
{
hw->clk_conf1.clk_fe_dac_en = en;
}

// The modem_syscon of esp32c5beta3 adds the enablement of the analog power detect clock on the analog front end compared to esp32h2 and esp32c6.
__attribute__((always_inline))
static inline void modem_syscon_ll_enable_fe_pwdet_clock(modem_syscon_dev_t *hw, bool en)
{
hw->clk_conf1.clk_fe_pwdet_adc_en = en;
}

__attribute__((always_inline))
Expand Down
4 changes: 3 additions & 1 deletion components/hal/esp32c5/modem_clock_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ uint32_t modem_clock_hal_get_clock_domain_icg_bitmap(modem_clock_hal_context_t *
void IRAM_ATTR modem_clock_hal_enable_modem_adc_common_fe_clock(modem_clock_hal_context_t *hal, bool enable)
{
if (enable) {
modem_syscon_ll_enable_fe_adc_clock(hal->syscon_dev, enable);
modem_syscon_ll_enable_fe_dac_clock(hal->syscon_dev, enable);
modem_syscon_ll_enable_fe_pwdet_clock(hal->syscon_dev, enable);
modem_syscon_ll_enable_fe_apb_clock(hal->syscon_dev, enable);
modem_syscon_ll_enable_fe_80m_clock(hal->syscon_dev, enable);
}
Expand All @@ -112,7 +115,6 @@ void IRAM_ATTR modem_clock_hal_enable_modem_adc_common_fe_clock(modem_clock_hal_
void IRAM_ATTR modem_clock_hal_enable_modem_private_fe_clock(modem_clock_hal_context_t *hal, bool enable)
{
if (enable) {
modem_syscon_ll_enable_fe_cal_160m_clock(hal->syscon_dev, enable);
modem_syscon_ll_enable_fe_160m_clock(hal->syscon_dev, enable);
}
}
Expand Down
5 changes: 5 additions & 0 deletions components/hal/esp32c6/include/hal/modem_syscon_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ static inline void modem_syscon_ll_enable_bt_apb_clock(modem_syscon_dev_t *hw, b
hw->clk_conf1.clk_bt_apb_en = en;
}

__attribute__((always_inline))
static inline void modem_syscon_ll_enable_bt_mac_clock(modem_syscon_dev_t *hw, bool en)
{
}

__attribute__((always_inline))
static inline void modem_syscon_ll_enable_bt_clock(modem_syscon_dev_t *hw, bool en)
{
Expand Down
5 changes: 5 additions & 0 deletions components/hal/esp32h2/include/hal/modem_syscon_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ static inline void modem_syscon_ll_enable_bt_apb_clock(modem_syscon_dev_t *hw, b
hw->clk_conf1.clk_bt_apb_en = en;
}

__attribute__((always_inline))
static inline void modem_syscon_ll_enable_bt_mac_clock(modem_syscon_dev_t *hw, bool en)
{
}

__attribute__((always_inline))
static inline void modem_syscon_ll_enable_bt_clock(modem_syscon_dev_t *hw, bool en)
{
Expand Down
3 changes: 2 additions & 1 deletion components/hal/include/hal/modem_clock_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "soc/soc_caps.h"
#include "sdkconfig.h"
#if SOC_MODEM_CLOCK_IS_INDEPENDENT && SOC_MODEM_CLOCK_SUPPORTED
#include "hal/modem_syscon_ll.h"
#include "hal/modem_lpcon_ll.h"
Expand All @@ -23,7 +24,7 @@ typedef struct {
modem_lpcon_dev_t *lpcon_dev;
} modem_clock_hal_context_t;

#if MAC_SUPPORT_PMU_MODEM_STATE
#if !CONFIG_IDF_TARGET_ESP32H2 //TODO: PM-92
void modem_clock_hal_set_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain, uint32_t bitmap);
uint32_t modem_clock_hal_get_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain);
#endif
Expand Down

0 comments on commit 5fa57d1

Please sign in to comment.