diff --git a/components/esp_hw_support/modem_clock.c b/components/esp_hw_support/modem_clock.c index 0e14ee4fc5..0348d68652 100644 --- a/components/esp_hw_support/modem_clock.c +++ b/components/esp_hw_support/modem_clock.c @@ -324,7 +324,7 @@ void modem_clock_select_lp_clock_source(periph_module_t module, modem_clock_lpcl modem_clock_hal_deselect_all_wifi_lpclk_source(MODEM_CLOCK_instance()->hal); modem_clock_hal_select_wifi_lpclk_source(MODEM_CLOCK_instance()->hal, src); modem_lpcon_ll_set_wifi_lpclk_divisor_value(MODEM_CLOCK_instance()->hal->lpcon_dev, divider); - modem_lpcon_ll_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal->lpcon_dev, true); + modem_clock_hal_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal, true); break; #endif // SOC_WIFI_SUPPORTED @@ -377,7 +377,7 @@ void modem_clock_deselect_lp_clock_source(periph_module_t module) #if SOC_WIFI_SUPPORTED case PERIPH_WIFI_MODULE: modem_clock_hal_deselect_all_wifi_lpclk_source(MODEM_CLOCK_instance()->hal); - modem_lpcon_ll_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal->lpcon_dev, false); + modem_clock_hal_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal, false); break; #endif // SOC_WIFI_SUPPORTED diff --git a/components/hal/esp32c6/modem_clock_hal.c b/components/hal/esp32c6/modem_clock_hal.c index a59aa84e2c..553c7cbfac 100644 --- a/components/hal/esp32c6/modem_clock_hal.c +++ b/components/hal/esp32c6/modem_clock_hal.c @@ -10,6 +10,7 @@ #include "esp_attr.h" #include "hal/modem_clock_hal.h" #include "hal/modem_clock_types.h" +#include "hal/efuse_hal.h" #include "hal/assert.h" typedef enum { @@ -239,3 +240,22 @@ void modem_clock_hal_select_wifi_lpclk_source(modem_clock_hal_context_t *hal, mo break; } } + +void modem_clock_hal_enable_wifipwr_clock(modem_clock_hal_context_t *hal, bool enable) +{ + if (efuse_hal_chip_revision() == 0) { /* eco0 */ + modem_lpcon_ll_enable_wifipwr_clock(hal->lpcon_dev, enable); + } else { + static int ref = 0; + if (enable) { + if (ref++ == 0) { + modem_lpcon_ll_enable_wifipwr_clock(hal->lpcon_dev, enable); + } + } else { + if (--ref == 0) { + modem_lpcon_ll_enable_wifipwr_clock(hal->lpcon_dev, enable); + } + } + HAL_ASSERT(ref > 0); + } +} diff --git a/components/hal/include/hal/modem_clock_hal.h b/components/hal/include/hal/modem_clock_hal.h index d7a7a8c5c7..04ba96575b 100644 --- a/components/hal/include/hal/modem_clock_hal.h +++ b/components/hal/include/hal/modem_clock_hal.h @@ -43,6 +43,7 @@ void modem_clock_hal_deselect_all_coex_lpclk_source(modem_clock_hal_context_t *h #if SOC_WIFI_SUPPORTED void modem_clock_hal_select_wifi_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src); void modem_clock_hal_deselect_all_wifi_lpclk_source(modem_clock_hal_context_t *hal); +void modem_clock_hal_enable_wifipwr_clock(modem_clock_hal_context_t *hal, bool enable); #endif #ifdef __cplusplus