diff --git a/components/esp_driver_gpio/src/rtc_io.c b/components/esp_driver_gpio/src/rtc_io.c index c382a7c9d8..fa7ce5ad9f 100644 --- a/components/esp_driver_gpio/src/rtc_io.c +++ b/components/esp_driver_gpio/src/rtc_io.c @@ -64,7 +64,7 @@ esp_err_t rtc_gpio_deinit(gpio_num_t gpio_num) rtcio_hal_function_select(rtc_io_number_get(gpio_num), RTCIO_LL_FUNC_DIGITAL); #if SOC_LP_IO_CLOCK_IS_INDEPENDENT - io_mux_enable_lp_io_clock(gpio_num, false); + io_mux_force_disable_lp_io_clock(gpio_num); #endif RTCIO_EXIT_CRITICAL(); diff --git a/components/esp_hw_support/include/esp_private/io_mux.h b/components/esp_hw_support/include/esp_private/io_mux.h index c2b9d39a77..71a9613949 100644 --- a/components/esp_hw_support/include/esp_private/io_mux.h +++ b/components/esp_hw_support/include/esp_private/io_mux.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -43,6 +43,12 @@ typedef struct { * @param enable true to enable the clock / false to disable the clock */ void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable); + +/** + * Force disable one LP_IO to clock dependency + * @param gpio_num GPIO number + */ +void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num); #endif #ifdef __cplusplus diff --git a/components/esp_hw_support/port/esp32c5/io_mux.c b/components/esp_hw_support/port/esp32c5/io_mux.c index 83f2e29c4a..ff043ef75c 100644 --- a/components/esp_hw_support/port/esp32c5/io_mux.c +++ b/components/esp_hw_support/port/esp32c5/io_mux.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -68,3 +68,16 @@ void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) } portEXIT_CRITICAL(&s_io_mux_spinlock); } + +void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) +{ + portENTER_CRITICAL(&s_io_mux_spinlock); + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] = 0; + s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); + if (s_rtc_io_status.rtc_io_using_mask == 0) { + RTCIO_RCC_ATOMIC() { + rtcio_ll_enable_io_clock(false); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} diff --git a/components/esp_hw_support/port/esp32c6/io_mux.c b/components/esp_hw_support/port/esp32c6/io_mux.c index eae8b2d771..6a6cf97b67 100644 --- a/components/esp_hw_support/port/esp32c6/io_mux.c +++ b/components/esp_hw_support/port/esp32c6/io_mux.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -69,3 +69,16 @@ void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) } portEXIT_CRITICAL(&s_io_mux_spinlock); } + +void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) +{ + portENTER_CRITICAL(&s_io_mux_spinlock); + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] = 0; + s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); + if (s_rtc_io_status.rtc_io_using_mask == 0) { + RTCIO_RCC_ATOMIC() { + rtcio_ll_enable_io_clock(false); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} diff --git a/components/esp_hw_support/port/esp32c61/io_mux.c b/components/esp_hw_support/port/esp32c61/io_mux.c index 46ab45360c..8f18bb3669 100644 --- a/components/esp_hw_support/port/esp32c61/io_mux.c +++ b/components/esp_hw_support/port/esp32c61/io_mux.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -67,3 +67,16 @@ void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) } portEXIT_CRITICAL(&s_io_mux_spinlock); } + +void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) +{ + portENTER_CRITICAL(&s_io_mux_spinlock); + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] = 0; + s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); + if (s_rtc_io_status.rtc_io_using_mask == 0) { + RTCIO_RCC_ATOMIC() { + rtcio_ll_enable_io_clock(false); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} diff --git a/components/esp_hw_support/port/esp32h2/io_mux.c b/components/esp_hw_support/port/esp32h2/io_mux.c index 3ff1884c10..65422c808d 100644 --- a/components/esp_hw_support/port/esp32h2/io_mux.c +++ b/components/esp_hw_support/port/esp32h2/io_mux.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -61,3 +61,16 @@ void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) } portEXIT_CRITICAL(&s_io_mux_spinlock); } + +void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) +{ + portENTER_CRITICAL(&s_io_mux_spinlock); + s_rtc_io_enabled_cnt[gpio_num] = 0; + s_rtc_io_using_mask &= ~(1ULL << gpio_num); + if (s_rtc_io_using_mask == 0) { + RTCIO_RCC_ATOMIC() { + rtcio_ll_enable_io_clock(false); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} diff --git a/components/esp_hw_support/port/esp32p4/io_mux.c b/components/esp_hw_support/port/esp32p4/io_mux.c index a8fe687f44..4bdd655523 100644 --- a/components/esp_hw_support/port/esp32p4/io_mux.c +++ b/components/esp_hw_support/port/esp32p4/io_mux.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -78,3 +78,20 @@ void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) } portEXIT_CRITICAL(&s_io_mux_spinlock); } + +void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) +{ + if (gpio_num > MAX_RTC_GPIO_NUM) { + assert(false && "RTCIO number error"); + return; + } + portENTER_CRITICAL(&s_io_mux_spinlock); + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] = 0; + s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); + if (s_rtc_io_status.rtc_io_using_mask == 0) { + RTCIO_RCC_ATOMIC() { + rtcio_ll_enable_io_clock(false); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} diff --git a/components/esp_hw_support/port/esp32s2/io_mux.c b/components/esp_hw_support/port/esp32s2/io_mux.c index d17a300030..4dc0131cf1 100644 --- a/components/esp_hw_support/port/esp32s2/io_mux.c +++ b/components/esp_hw_support/port/esp32s2/io_mux.c @@ -1,13 +1,67 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" +#include "esp_attr.h" +#include "freertos/FreeRTOS.h" #include "esp_private/io_mux.h" +#include "hal/rtc_io_ll.h" + +#define RTCIO_RCC_ATOMIC() \ + for (int _rc_cnt = 1; \ + _rc_cnt ? (portENTER_CRITICAL(&rtc_spinlock), 1) : 0; \ + portEXIT_CRITICAL(&rtc_spinlock), _rc_cnt--) esp_err_t io_mux_set_clock_source(soc_module_clk_t clk_src) { // IO MUX clock source is not selectable return ESP_OK; } + +extern portMUX_TYPE rtc_spinlock; +static portMUX_TYPE s_io_mux_spinlock = portMUX_INITIALIZER_UNLOCKED; + +static rtc_io_status_t s_rtc_io_status = { + .rtc_io_enabled_cnt = { 0 }, + .rtc_io_using_mask = 0 +}; + +void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) +{ + portENTER_CRITICAL(&s_io_mux_spinlock); + if (enable) { + if (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] == 0) { + s_rtc_io_status.rtc_io_using_mask |= (1ULL << gpio_num); + } + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num]++; + } else if (!enable && (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] > 0)) { + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num]--; + if (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] == 0) { + s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); + } + } + RTCIO_RCC_ATOMIC() { + if (s_rtc_io_status.rtc_io_using_mask == 0) { + rtcio_ll_enable_io_clock(false); + } else { + rtcio_ll_enable_io_clock(true); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} + +void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) +{ + portENTER_CRITICAL(&s_io_mux_spinlock); + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] = 0; + s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); + if (s_rtc_io_status.rtc_io_using_mask == 0) { + RTCIO_RCC_ATOMIC() { + rtcio_ll_enable_io_clock(false); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} diff --git a/components/esp_hw_support/port/esp32s3/io_mux.c b/components/esp_hw_support/port/esp32s3/io_mux.c index d17a300030..4dc0131cf1 100644 --- a/components/esp_hw_support/port/esp32s3/io_mux.c +++ b/components/esp_hw_support/port/esp32s3/io_mux.c @@ -1,13 +1,67 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" +#include "esp_attr.h" +#include "freertos/FreeRTOS.h" #include "esp_private/io_mux.h" +#include "hal/rtc_io_ll.h" + +#define RTCIO_RCC_ATOMIC() \ + for (int _rc_cnt = 1; \ + _rc_cnt ? (portENTER_CRITICAL(&rtc_spinlock), 1) : 0; \ + portEXIT_CRITICAL(&rtc_spinlock), _rc_cnt--) esp_err_t io_mux_set_clock_source(soc_module_clk_t clk_src) { // IO MUX clock source is not selectable return ESP_OK; } + +extern portMUX_TYPE rtc_spinlock; +static portMUX_TYPE s_io_mux_spinlock = portMUX_INITIALIZER_UNLOCKED; + +static rtc_io_status_t s_rtc_io_status = { + .rtc_io_enabled_cnt = { 0 }, + .rtc_io_using_mask = 0 +}; + +void io_mux_enable_lp_io_clock(gpio_num_t gpio_num, bool enable) +{ + portENTER_CRITICAL(&s_io_mux_spinlock); + if (enable) { + if (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] == 0) { + s_rtc_io_status.rtc_io_using_mask |= (1ULL << gpio_num); + } + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num]++; + } else if (!enable && (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] > 0)) { + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num]--; + if (s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] == 0) { + s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); + } + } + RTCIO_RCC_ATOMIC() { + if (s_rtc_io_status.rtc_io_using_mask == 0) { + rtcio_ll_enable_io_clock(false); + } else { + rtcio_ll_enable_io_clock(true); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} + +void io_mux_force_disable_lp_io_clock(gpio_num_t gpio_num) +{ + portENTER_CRITICAL(&s_io_mux_spinlock); + s_rtc_io_status.rtc_io_enabled_cnt[gpio_num] = 0; + s_rtc_io_status.rtc_io_using_mask &= ~(1ULL << gpio_num); + if (s_rtc_io_status.rtc_io_using_mask == 0) { + RTCIO_RCC_ATOMIC() { + rtcio_ll_enable_io_clock(false); + } + } + portEXIT_CRITICAL(&s_io_mux_spinlock); +} diff --git a/components/esp_hw_support/port/esp32s3/rtc_clk.c b/components/esp_hw_support/port/esp32s3/rtc_clk.c index d101a1d5d9..6f4f2ea352 100644 --- a/components/esp_hw_support/port/esp32s3/rtc_clk.c +++ b/components/esp_hw_support/port/esp32s3/rtc_clk.c @@ -20,6 +20,7 @@ #include "esp_hw_log.h" #include "hal/clk_tree_ll.h" #include "hal/regi2c_ctrl_ll.h" +#include "hal/rtc_io_ll.h" #include "esp_private/regi2c_ctrl.h" #include "soc/regi2c_dig_reg.h" #include "soc/sens_reg.h" @@ -66,7 +67,7 @@ void rtc_clk_32k_enable(bool enable) void rtc_clk_32k_enable_external(void) { PIN_INPUT_ENABLE(IO_MUX_GPIO15_REG); - SET_PERI_REG_MASK(SENS_SAR_PERI_CLK_GATE_CONF_REG, SENS_IOMUX_CLK_EN); + rtcio_ll_enable_io_clock(true); SET_PERI_REG_MASK(RTC_CNTL_PAD_HOLD_REG, RTC_CNTL_X32P_HOLD); clk_ll_xtal32k_enable(CLK_LL_XTAL32K_ENABLE_MODE_EXTERNAL); } diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 7439bc900a..5db5b21bb6 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1813,7 +1813,9 @@ static void ext0_wakeup_prepare(void) { int rtc_gpio_num = s_config.ext0_rtc_gpio_num; #if SOC_LP_IO_CLOCK_IS_INDEPENDENT - io_mux_enable_lp_io_clock(rtc_gpio_num, true); + // To suppress build errors about spinlock's __DECLARE_RCC_ATOMIC_ENV + int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); + rtcio_ll_enable_io_clock(true); #endif rtcio_hal_ext0_set_wakeup_pin(rtc_gpio_num, s_config.ext0_trigger_level); rtcio_hal_function_select(rtc_gpio_num, RTCIO_LL_FUNC_RTC); @@ -1946,7 +1948,9 @@ static void ext1_wakeup_prepare(void) continue; } #if SOC_LP_IO_CLOCK_IS_INDEPENDENT - io_mux_enable_lp_io_clock(rtc_pin, true); + // To suppress build errors about spinlock's __DECLARE_RCC_ATOMIC_ENV + int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); + rtcio_ll_enable_io_clock(true); #endif #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED // Route pad to RTC @@ -2020,6 +2024,11 @@ static void gpio_deep_sleep_wakeup_prepare(void) if ((s_config.gpio_wakeup_mask & BIT64(gpio_idx)) == 0) { continue; } +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + // To suppress build errors about spinlock's __DECLARE_RCC_ATOMIC_ENV + int __DECLARE_RCC_ATOMIC_ENV __attribute__ ((unused)); + rtcio_ll_enable_io_clock(true); +#endif #if CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS if (s_config.gpio_trigger_mode & BIT(gpio_idx)) { ESP_ERROR_CHECK(gpio_pullup_dis(gpio_idx)); diff --git a/components/hal/esp32s2/include/hal/rtc_io_ll.h b/components/hal/esp32s2/include/hal/rtc_io_ll.h index 739d2722dd..5e695ba145 100644 --- a/components/hal/esp32s2/include/hal/rtc_io_ll.h +++ b/components/hal/esp32s2/include/hal/rtc_io_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -13,6 +13,7 @@ #pragma once #include +#include #include "soc/rtc_io_struct.h" #include "soc/rtc_io_reg.h" #include "soc/rtc_periph.h" @@ -25,7 +26,7 @@ extern "C" { #endif typedef enum { - RTCIO_LL_FUNC_RTC = 0x0, /*!< The pin controled by RTC module. */ + RTCIO_LL_FUNC_RTC = 0x0, /*!< The pin controlled by RTC module. */ RTCIO_LL_FUNC_DIGITAL = 0x1, /*!< The pin controlled by DIGITAL module. */ } rtcio_ll_func_t; @@ -51,6 +52,16 @@ static inline void rtcio_ll_iomux_func_sel(int rtcio_num, int func) SET_PERI_REG_BITS(rtc_io_desc[rtcio_num].reg, 0x3, func, rtc_io_desc[rtcio_num].func); } +/** + * @brief Enable/Disable LP IOMUX clock. + * + * @param enable true to enable the clock / false to disable the clock + */ +static inline void rtcio_ll_enable_io_clock(bool enable) +{ + SENS.sar_io_mux_conf.iomux_clk_gate_en = enable; +} + /** * @brief Select the rtcio function. * @@ -61,14 +72,12 @@ static inline void rtcio_ll_iomux_func_sel(int rtcio_num, int func) static inline void rtcio_ll_function_select(int rtcio_num, rtcio_ll_func_t func) { if (func == RTCIO_LL_FUNC_RTC) { - SENS.sar_io_mux_conf.iomux_clk_gate_en = 1; // 0: GPIO connected to digital GPIO module. 1: GPIO connected to analog RTC module. SET_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, (rtc_io_desc[rtcio_num].mux)); //0:RTC FUNCTION 1,2,3:Reserved rtcio_ll_iomux_func_sel(rtcio_num, RTCIO_LL_PIN_FUNC); } else if (func == RTCIO_LL_FUNC_DIGITAL) { CLEAR_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, (rtc_io_desc[rtcio_num].mux)); - SENS.sar_io_mux_conf.iomux_clk_gate_en = 0; } } @@ -281,7 +290,6 @@ static inline void rtcio_ll_force_unhold_all(void) */ static inline void rtcio_ll_wakeup_enable(int rtcio_num, rtcio_ll_wake_type_t type) { - SENS.sar_io_mux_conf.iomux_clk_gate_en = 1; RTCIO.pin[rtcio_num].wakeup_enable = 1; RTCIO.pin[rtcio_num].int_type = type; } @@ -293,7 +301,6 @@ static inline void rtcio_ll_wakeup_enable(int rtcio_num, rtcio_ll_wake_type_t ty */ static inline void rtcio_ll_wakeup_disable(int rtcio_num) { - SENS.sar_io_mux_conf.iomux_clk_gate_en = 0; RTCIO.pin[rtcio_num].wakeup_enable = 0; RTCIO.pin[rtcio_num].int_type = RTCIO_LL_WAKEUP_DISABLE; } diff --git a/components/hal/esp32s3/include/hal/rtc_io_ll.h b/components/hal/esp32s3/include/hal/rtc_io_ll.h index 86d483b217..6cd31a3a00 100644 --- a/components/hal/esp32s3/include/hal/rtc_io_ll.h +++ b/components/hal/esp32s3/include/hal/rtc_io_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -13,6 +13,7 @@ #pragma once #include +#include #include "soc/rtc_io_struct.h" #include "soc/rtc_io_reg.h" #include "soc/rtc_periph.h" @@ -43,6 +44,16 @@ typedef enum { RTCIO_LL_OUTPUT_OD = 0x1, /*!< RTCIO output mode is open-drain. */ } rtcio_ll_out_mode_t; +/** + * @brief Enable/Disable LP IOMUX clock. + * + * @param enable true to enable the clock / false to disable the clock + */ +static inline void rtcio_ll_enable_io_clock(bool enable) +{ + SENS.sar_peri_clk_gate_conf.iomux_clk_en = enable; +} + /** * @brief Select a RTC IOMUX function for the RTC IO * @@ -68,14 +79,12 @@ static inline void rtcio_ll_function_select(int rtcio_num, rtcio_ll_func_t func) if (rtcio_num == rtc_io_num_map[USB_INT_PHY0_DM_GPIO_NUM] || rtcio_num == rtc_io_num_map[USB_INT_PHY0_DP_GPIO_NUM]) { USB_SERIAL_JTAG.conf0.usb_pad_enable = 0; } - SENS.sar_peri_clk_gate_conf.iomux_clk_en = 1; // 0: GPIO connected to digital GPIO module. 1: GPIO connected to analog RTC module. SET_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, (rtc_io_desc[rtcio_num].mux)); //0:RTC FUNCTION 1,2,3:Reserved rtcio_ll_iomux_func_sel(rtcio_num, RTCIO_LL_PIN_FUNC); } else if (func == RTCIO_LL_FUNC_DIGITAL) { CLEAR_PERI_REG_MASK(rtc_io_desc[rtcio_num].reg, (rtc_io_desc[rtcio_num].mux)); - SENS.sar_peri_clk_gate_conf.iomux_clk_en = 0; // USB Serial JTAG pad re-enable won't be done here (it requires both DM and DP pins not in rtc function) // Instead, USB_SERIAL_JTAG_USB_PAD_ENABLE needs to be guaranteed to be set in usb_serial_jtag driver } @@ -308,7 +317,6 @@ static inline void rtcio_ll_force_unhold_all(void) */ static inline void rtcio_ll_wakeup_enable(int rtcio_num, rtcio_ll_wake_type_t type) { - SENS.sar_peri_clk_gate_conf.iomux_clk_en = 1; RTCIO.pin[rtcio_num].wakeup_enable = 1; RTCIO.pin[rtcio_num].int_type = type; } diff --git a/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in index 2841ad1ce6..8110c9b64a 100644 --- a/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in @@ -667,6 +667,10 @@ config SOC_RTCIO_WAKE_SUPPORTED bool default y +config SOC_LP_IO_CLOCK_IS_INDEPENDENT + bool + default y + config SOC_SDM_GROUPS int default 1 diff --git a/components/soc/esp32s2/include/soc/soc_caps.h b/components/soc/esp32s2/include/soc/soc_caps.h index 2abc6274e8..377a1720ef 100644 --- a/components/soc/esp32s2/include/soc/soc_caps.h +++ b/components/soc/esp32s2/include/soc/soc_caps.h @@ -280,6 +280,8 @@ */ #define SOC_RTCIO_HOLD_SUPPORTED 1 #define SOC_RTCIO_WAKE_SUPPORTED 1 +// LP IO peripherals have independent clock gating to manage +#define SOC_LP_IO_CLOCK_IS_INDEPENDENT 1 /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ #define SOC_SDM_GROUPS 1U diff --git a/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in index eb8aaee6b1..de84378125 100644 --- a/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in @@ -835,6 +835,10 @@ config SOC_RTCIO_WAKE_SUPPORTED bool default y +config SOC_LP_IO_CLOCK_IS_INDEPENDENT + bool + default y + config SOC_SDM_GROUPS bool default y diff --git a/components/soc/esp32s3/include/soc/soc_caps.h b/components/soc/esp32s3/include/soc/soc_caps.h index 50e766c263..84d6683cdc 100644 --- a/components/soc/esp32s3/include/soc/soc_caps.h +++ b/components/soc/esp32s3/include/soc/soc_caps.h @@ -323,6 +323,8 @@ */ #define SOC_RTCIO_HOLD_SUPPORTED 1 #define SOC_RTCIO_WAKE_SUPPORTED 1 +// LP IO peripherals have independent clock gating to manage +#define SOC_LP_IO_CLOCK_IS_INDEPENDENT 1 /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ #define SOC_SDM_GROUPS 1 diff --git a/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h b/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h index d48e5fc817..b1b06416f1 100644 --- a/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h +++ b/components/ulp/ulp_riscv/ulp_core/include/ulp_riscv_gpio.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,10 +11,12 @@ extern "C" { #endif #include "sdkconfig.h" +#include "soc/soc_caps.h" #include "soc/rtc_io_reg.h" #include "soc/sens_reg.h" -#include "hal/gpio_types.h" #include "ulp_riscv_register_ops.h" +#include "hal/gpio_types.h" +#include "hal/rtc_io_ll.h" #include "ulp_riscv_interrupt.h" typedef enum { @@ -34,10 +36,8 @@ typedef enum { static inline void ulp_riscv_gpio_init(gpio_num_t gpio_num) { -#if CONFIG_IDF_TARGET_ESP32S2 - SET_PERI_REG_MASK(SENS_SAR_IO_MUX_CONF_REG, SENS_IOMUX_CLK_GATE_EN_M); -#elif CONFIG_IDF_TARGET_ESP32S3 - SET_PERI_REG_MASK(SENS_SAR_PERI_CLK_GATE_CONF_REG, SENS_IOMUX_CLK_EN_M); +#if SOC_LP_IO_CLOCK_IS_INDEPENDENT + rtcio_ll_enable_io_clock(true); #endif SET_PERI_REG_MASK(RTC_IO_TOUCH_PAD0_REG + gpio_num * 4, RTC_IO_TOUCH_PAD0_MUX_SEL); REG_SET_FIELD(RTC_IO_TOUCH_PAD0_REG + gpio_num * 4, RTC_IO_TOUCH_PAD0_FUN_SEL, 0);