diff --git a/components/esp_hal_pmu/CMakeLists.txt b/components/esp_hal_pmu/CMakeLists.txt new file mode 100644 index 00000000000..75f9e18bb95 --- /dev/null +++ b/components/esp_hal_pmu/CMakeLists.txt @@ -0,0 +1,27 @@ +idf_build_get_property(target IDF_TARGET) +if(${target} STREQUAL "linux") + return() # This component is not supported by the POSIX/Linux simulator +endif() + +set(srcs) +set(public_include "include" "${target}/include") + +# New chips with PMU peripheral +if(CONFIG_SOC_PMU_SUPPORTED) + list(APPEND srcs "${target}/pmu_hal.c") +endif() + +# Legacy chips with RTC_CNTL peripheral +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/rtc_cntl_hal.c") + list(APPEND srcs "${target}/rtc_cntl_hal.c") +endif() + +# Chips with PAU (Power Assist Unit) peripheral +if(CONFIG_SOC_PAU_SUPPORTED) + list(APPEND srcs "${target}/pau_hal.c") +endif() + +idf_component_register(SRCS ${srcs} + INCLUDE_DIRS ${public_include} + REQUIRES soc hal esp_rom + LDFRAGMENTS linker.lf) diff --git a/components/esp_hal_pmu/README.md b/components/esp_hal_pmu/README.md new file mode 100644 index 00000000000..b9912eda538 --- /dev/null +++ b/components/esp_hal_pmu/README.md @@ -0,0 +1,78 @@ +# ESP Hardware Abstraction Layer for PMU and RTC Control Peripherals + +> [!NOTE] +> This component is currently in beta. Its API, behavior, and compatibility may change at any time and without notice; backward compatibility is not guaranteed. Use caution when integrating into production systems. + +## Overview + +The `esp_hal_pmu` component provides a **Hardware Abstraction Layer** for Power Management Unit (PMU) and legacy RTC Control (RTC_CNTL) peripherals across ESP-IDF supported targets. This HAL enables unified power management operations including sleep mode control, power domain management, wakeup configuration, and retention control across different ESP chip families. + +The component consolidates power management functionality from three different peripheral implementations: +- **PMU**: Modern power management unit in newer ESP chips +- **RTC_CNTL**: Legacy RTC control peripheral in older ESP chips +- **PAU**: Power Assist Unit for register retention and backup/restore operations + +## Architecture + +The HAL architecture consists of two primary layers: + +1. **HAL Layer (Upper)**: Defines the operational sequences and data structures required to interact with PMU/RTC_CNTL/PAU peripherals, including: + - Power domain configuration and control + - Sleep mode management + - Wakeup source configuration + - Retention control (CPU, tagmem) + - Power-up/down wait cycle configuration + - Backup enable/disable operations + - REGDMA link configuration and control + +2. **Low-Level Layer (Bottom)**: Acts as a translation layer between the HAL and the register definitions in the `soc` component, handling: + - Register access abstractions + - Chip-specific register configurations + - Hardware feature compatibility + - Power domain and clock control + +## Features + +### Power Management +- Power domain control (HP/LP system power domains) +- Digital power supply and power-up wait cycle configuration +- Control ready wait cycle configuration (isolate/reset) +- Power mode transitions (active, sleep, modem) + +### Sleep and Wakeup +- Sleep mode configuration +- Wakeup source management +- Sleep rejection handling +- Wakeup cause detection + +### Retention Control +- CPU retention enable/disable +- Tagmem retention support (on supported chips) +- DMA link buffer configuration for retention + +### Backup Operations +- Sleep-to-active backup enable/disable +- Sleep-to-modem backup enable/disable +- Modem-to-active backup enable/disable + +### REGDMA (Register DMA) Support +- REGDMA entry link address configuration +- REGDMA modem link control (backup/restore) +- REGDMA system link control +- REGDMA extra link control +- REGDMA timeout configuration +- REGDMA clock configuration + +## Usage +This component is primarily used by ESP-IDF system services such as: +- **esp_pm**: Power management framework +- **esp_hw_support**: Hardware support layer for sleep modes, power management, and register retention +- **ulp**: Ultra-low-power coprocessor support + +For advanced developers implementing custom power management solutions, the HAL functions can be used directly. However, please note that the interfaces provided by this component are internal to ESP-IDF and are subject to change. + +## Dependencies + +- `soc`: Provides chip-specific register definitions and peripheral capabilities +- `hal`: Core hardware abstraction utilities and macros +- `esp_rom`: ROM function interfaces (where applicable) diff --git a/components/hal/esp32/include/hal/rtc_cntl_ll.h b/components/esp_hal_pmu/esp32/include/hal/rtc_cntl_ll.h similarity index 95% rename from components/hal/esp32/include/hal/rtc_cntl_ll.h rename to components/esp_hal_pmu/esp32/include/hal/rtc_cntl_ll.h index 387c73f2887..a30c657637a 100644 --- a/components/hal/esp32/include/hal/rtc_cntl_ll.h +++ b/components/esp_hal_pmu/esp32/include/hal/rtc_cntl_ll.h @@ -8,7 +8,7 @@ #include "soc/soc.h" #include "esp_attr.h" -#include "clk_tree_ll.h" +#include "hal/clk_tree_ll.h" #include "esp_rom_sys.h" #include "hal/assert.h" @@ -39,10 +39,10 @@ FORCE_INLINE_ATTR void rtc_cntl_ll_ext1_set_wakeup_pins(uint32_t io_mask, uint32 REG_SET_FIELD(RTC_CNTL_EXT_WAKEUP1_REG, RTC_CNTL_EXT_WAKEUP1_SEL, io_mask); if ((io_mask & mode_mask) == io_mask) { SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 1, RTC_CNTL_EXT_WAKEUP1_LV_S); + 1, RTC_CNTL_EXT_WAKEUP1_LV_S); } else { SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 0, RTC_CNTL_EXT_WAKEUP1_LV_S); + 0, RTC_CNTL_EXT_WAKEUP1_LV_S); } } diff --git a/components/hal/esp32c2/include/hal/rtc_cntl_ll.h b/components/esp_hal_pmu/esp32c2/include/hal/rtc_cntl_ll.h similarity index 100% rename from components/hal/esp32c2/include/hal/rtc_cntl_ll.h rename to components/esp_hal_pmu/esp32c2/include/hal/rtc_cntl_ll.h diff --git a/components/hal/esp32c2/rtc_cntl_hal.c b/components/esp_hal_pmu/esp32c2/rtc_cntl_hal.c similarity index 97% rename from components/hal/esp32c2/rtc_cntl_hal.c rename to components/esp_hal_pmu/esp32c2/rtc_cntl_hal.c index 7ee75a484dd..877953a48b5 100644 --- a/components/hal/esp32c2/rtc_cntl_hal.c +++ b/components/esp_hal_pmu/esp32c2/rtc_cntl_hal.c @@ -48,7 +48,7 @@ void rtc_cntl_hal_enable_cpu_retention(void *addr) pbuf->cfg[0] = 0; pbuf->cfg[1] = 0; pbuf->cfg[2] = 0; - pbuf->cfg[3] = (uint32_t)-1; + pbuf->cfg[3] = (uint32_t) -1; rtc_cntl_ll_enable_cpu_retention((uint32_t)addr); } diff --git a/components/hal/esp32c3/include/hal/rtc_cntl_ll.h b/components/esp_hal_pmu/esp32c3/include/hal/rtc_cntl_ll.h similarity index 100% rename from components/hal/esp32c3/include/hal/rtc_cntl_ll.h rename to components/esp_hal_pmu/esp32c3/include/hal/rtc_cntl_ll.h diff --git a/components/hal/esp32c3/rtc_cntl_hal.c b/components/esp_hal_pmu/esp32c3/rtc_cntl_hal.c similarity index 98% rename from components/hal/esp32c3/rtc_cntl_hal.c rename to components/esp_hal_pmu/esp32c3/rtc_cntl_hal.c index aa7f90a442d..8c92189f7b3 100644 --- a/components/hal/esp32c3/rtc_cntl_hal.c +++ b/components/esp_hal_pmu/esp32c3/rtc_cntl_hal.c @@ -53,7 +53,7 @@ void rtc_cntl_hal_enable_cpu_retention(void *addr) pbuf->cfg[0] = 0; pbuf->cfg[1] = 0; pbuf->cfg[2] = 0; - pbuf->cfg[3] = (uint32_t)-1; + pbuf->cfg[3] = (uint32_t) -1; rtc_cntl_ll_set_cpu_retention_link_addr((uint32_t)plink); rtc_cntl_ll_enable_cpu_retention_clock(); diff --git a/components/hal/esp32c5/include/hal/pau_ll.h b/components/esp_hal_pmu/esp32c5/include/hal/pau_ll.h similarity index 99% rename from components/hal/esp32c5/include/hal/pau_ll.h rename to components/esp_hal_pmu/esp32c5/include/hal/pau_ll.h index 8235ddf0fdd..877bb992b46 100644 --- a/components/hal/esp32c5/include/hal/pau_ll.h +++ b/components/esp_hal_pmu/esp32c5/include/hal/pau_ll.h @@ -104,7 +104,6 @@ static inline void pau_ll_clear_regdma_backup_error_intr_state(pau_dev_t *dev) dev->int_clr.val = 0x2; } - /** * @brief Set the maximum number of linked lists supported by REGDMA * @param count: the maximum number of regdma link diff --git a/components/hal/esp32c5/include/hal/pmu_hal.h b/components/esp_hal_pmu/esp32c5/include/hal/pmu_hal.h similarity index 100% rename from components/hal/esp32c5/include/hal/pmu_hal.h rename to components/esp_hal_pmu/esp32c5/include/hal/pmu_hal.h diff --git a/components/hal/esp32c5/include/hal/pmu_ll.h b/components/esp_hal_pmu/esp32c5/include/hal/pmu_ll.h similarity index 99% rename from components/hal/esp32c5/include/hal/pmu_ll.h rename to components/esp_hal_pmu/esp32c5/include/hal/pmu_ll.h index 8e188cba458..0c331f5f729 100644 --- a/components/hal/esp32c5/include/hal/pmu_ll.h +++ b/components/esp_hal_pmu/esp32c5/include/hal/pmu_ll.h @@ -239,7 +239,6 @@ FORCE_INLINE_ATTR void pmu_ll_hp_set_regulator_driver_bar(pmu_dev_t *hw, pmu_hp_ hw->hp_sys[mode].regulator1.drv_b = drv_b; } - FORCE_INLINE_ATTR void pmu_ll_lp_set_regulator_slp_xpd(pmu_dev_t *hw, pmu_lp_mode_t mode, bool slp_xpd) { hw->lp_sys[mode].regulator0.slp_xpd = slp_xpd; @@ -271,7 +270,6 @@ FORCE_INLINE_ATTR void pmu_ll_lp_set_xtal_xpd(pmu_dev_t *hw, pmu_lp_mode_t mode, hw->lp_sys[mode].xtal.xpd_xtal = xpd_xtal; } - FORCE_INLINE_ATTR void pmu_ll_lp_set_dig_power(pmu_dev_t *hw, pmu_lp_mode_t mode, uint32_t flag) { hw->lp_sys[mode].dig_power.val = flag; @@ -311,7 +309,6 @@ FORCE_INLINE_ATTR void pmu_ll_lp_set_bias_sleep_enable(pmu_dev_t *hw, pmu_lp_mod hw->lp_sys[mode].bias.bias_sleep = en; } - /****/ FORCE_INLINE_ATTR void pmu_ll_imm_set_clk_power(pmu_dev_t *hw, uint32_t flag) { @@ -697,7 +694,6 @@ FORCE_INLINE_ATTR uint32_t pmu_ll_get_sysclk_sleep_select_state(pmu_dev_t *hw) return hw->clk_state0.sysclk_slp_sel; } - FORCE_INLINE_ATTR uint32_t pmu_ll_lp_get_interrupt_raw(pmu_dev_t *hw) { return hw->lp_ext.int_raw.val; diff --git a/components/hal/esp32c5/pau_hal.c b/components/esp_hal_pmu/esp32c5/pau_hal.c similarity index 100% rename from components/hal/esp32c5/pau_hal.c rename to components/esp_hal_pmu/esp32c5/pau_hal.c diff --git a/components/hal/esp32c5/pmu_hal.c b/components/esp_hal_pmu/esp32c5/pmu_hal.c similarity index 100% rename from components/hal/esp32c5/pmu_hal.c rename to components/esp_hal_pmu/esp32c5/pmu_hal.c diff --git a/components/hal/esp32c6/include/hal/pau_ll.h b/components/esp_hal_pmu/esp32c6/include/hal/pau_ll.h similarity index 100% rename from components/hal/esp32c6/include/hal/pau_ll.h rename to components/esp_hal_pmu/esp32c6/include/hal/pau_ll.h diff --git a/components/hal/esp32c6/include/hal/pmu_hal.h b/components/esp_hal_pmu/esp32c6/include/hal/pmu_hal.h similarity index 100% rename from components/hal/esp32c6/include/hal/pmu_hal.h rename to components/esp_hal_pmu/esp32c6/include/hal/pmu_hal.h diff --git a/components/hal/esp32c6/include/hal/pmu_ll.h b/components/esp_hal_pmu/esp32c6/include/hal/pmu_ll.h similarity index 99% rename from components/hal/esp32c6/include/hal/pmu_ll.h rename to components/esp_hal_pmu/esp32c6/include/hal/pmu_ll.h index ed55a8c0f91..24f31334aa8 100644 --- a/components/hal/esp32c6/include/hal/pmu_ll.h +++ b/components/esp_hal_pmu/esp32c6/include/hal/pmu_ll.h @@ -239,7 +239,6 @@ FORCE_INLINE_ATTR void pmu_ll_hp_set_regulator_driver_bar(pmu_dev_t *hw, pmu_hp_ hw->hp_sys[mode].regulator1.drv_b = drv_b; } - FORCE_INLINE_ATTR void pmu_ll_lp_set_regulator_slp_xpd(pmu_dev_t *hw, pmu_lp_mode_t mode, bool slp_xpd) { hw->lp_sys[mode].regulator0.slp_xpd = slp_xpd; @@ -271,7 +270,6 @@ FORCE_INLINE_ATTR void pmu_ll_lp_set_xtal_xpd(pmu_dev_t *hw, pmu_lp_mode_t mode, hw->lp_sys[mode].xtal.xpd_xtal = xpd_xtal; } - FORCE_INLINE_ATTR void pmu_ll_lp_set_dig_power(pmu_dev_t *hw, pmu_lp_mode_t mode, uint32_t flag) { hw->lp_sys[mode].dig_power.val = flag; @@ -311,7 +309,6 @@ FORCE_INLINE_ATTR void pmu_ll_lp_set_bias_sleep_enable(pmu_dev_t *hw, pmu_lp_mod hw->lp_sys[mode].bias.bias_sleep = en; } - /****/ FORCE_INLINE_ATTR void pmu_ll_imm_set_clk_power(pmu_dev_t *hw, uint32_t flag) { diff --git a/components/hal/esp32c6/pau_hal.c b/components/esp_hal_pmu/esp32c6/pau_hal.c similarity index 100% rename from components/hal/esp32c6/pau_hal.c rename to components/esp_hal_pmu/esp32c6/pau_hal.c diff --git a/components/hal/esp32c6/pmu_hal.c b/components/esp_hal_pmu/esp32c6/pmu_hal.c similarity index 100% rename from components/hal/esp32c6/pmu_hal.c rename to components/esp_hal_pmu/esp32c6/pmu_hal.c diff --git a/components/hal/esp32c61/include/hal/pau_ll.h b/components/esp_hal_pmu/esp32c61/include/hal/pau_ll.h similarity index 100% rename from components/hal/esp32c61/include/hal/pau_ll.h rename to components/esp_hal_pmu/esp32c61/include/hal/pau_ll.h diff --git a/components/hal/esp32c61/include/hal/pmu_hal.h b/components/esp_hal_pmu/esp32c61/include/hal/pmu_hal.h similarity index 100% rename from components/hal/esp32c61/include/hal/pmu_hal.h rename to components/esp_hal_pmu/esp32c61/include/hal/pmu_hal.h diff --git a/components/hal/esp32c61/include/hal/pmu_ll.h b/components/esp_hal_pmu/esp32c61/include/hal/pmu_ll.h similarity index 99% rename from components/hal/esp32c61/include/hal/pmu_ll.h rename to components/esp_hal_pmu/esp32c61/include/hal/pmu_ll.h index 62e045c6db1..2353926ad59 100644 --- a/components/hal/esp32c61/include/hal/pmu_ll.h +++ b/components/esp_hal_pmu/esp32c61/include/hal/pmu_ll.h @@ -17,7 +17,6 @@ #include "hal/pmu_types.h" #include "hal/misc.h" - #ifdef __cplusplus extern "C" { #endif @@ -240,7 +239,6 @@ FORCE_INLINE_ATTR void pmu_ll_hp_set_regulator_driver_bar(pmu_dev_t *hw, pmu_hp_ hw->hp_sys[mode].regulator1.drv_b = drv_b; } - FORCE_INLINE_ATTR void pmu_ll_lp_set_regulator_slp_xpd(pmu_dev_t *hw, pmu_lp_mode_t mode, bool slp_xpd) { hw->lp_sys[mode].regulator0.slp_xpd = slp_xpd; @@ -272,7 +270,6 @@ FORCE_INLINE_ATTR void pmu_ll_lp_set_xtal_xpd(pmu_dev_t *hw, pmu_lp_mode_t mode, hw->lp_sys[mode].xtal.xpd_xtal = xpd_xtal; } - FORCE_INLINE_ATTR void pmu_ll_lp_set_dig_power(pmu_dev_t *hw, pmu_lp_mode_t mode, uint32_t flag) { hw->lp_sys[mode].dig_power.val = flag; @@ -312,7 +309,6 @@ FORCE_INLINE_ATTR void pmu_ll_lp_set_bias_sleep_enable(pmu_dev_t *hw, pmu_lp_mod hw->lp_sys[mode].bias.bias_sleep = en; } - /****/ FORCE_INLINE_ATTR void pmu_ll_imm_set_clk_power(pmu_dev_t *hw, uint32_t flag) { diff --git a/components/hal/esp32c61/pau_hal.c b/components/esp_hal_pmu/esp32c61/pau_hal.c similarity index 100% rename from components/hal/esp32c61/pau_hal.c rename to components/esp_hal_pmu/esp32c61/pau_hal.c diff --git a/components/hal/esp32c61/pmu_hal.c b/components/esp_hal_pmu/esp32c61/pmu_hal.c similarity index 100% rename from components/hal/esp32c61/pmu_hal.c rename to components/esp_hal_pmu/esp32c61/pmu_hal.c diff --git a/components/hal/esp32h2/include/hal/pau_ll.h b/components/esp_hal_pmu/esp32h2/include/hal/pau_ll.h similarity index 100% rename from components/hal/esp32h2/include/hal/pau_ll.h rename to components/esp_hal_pmu/esp32h2/include/hal/pau_ll.h diff --git a/components/hal/esp32h2/include/hal/pmu_hal.h b/components/esp_hal_pmu/esp32h2/include/hal/pmu_hal.h similarity index 100% rename from components/hal/esp32h2/include/hal/pmu_hal.h rename to components/esp_hal_pmu/esp32h2/include/hal/pmu_hal.h diff --git a/components/hal/esp32h2/include/hal/pmu_ll.h b/components/esp_hal_pmu/esp32h2/include/hal/pmu_ll.h similarity index 100% rename from components/hal/esp32h2/include/hal/pmu_ll.h rename to components/esp_hal_pmu/esp32h2/include/hal/pmu_ll.h diff --git a/components/hal/esp32h2/pau_hal.c b/components/esp_hal_pmu/esp32h2/pau_hal.c similarity index 100% rename from components/hal/esp32h2/pau_hal.c rename to components/esp_hal_pmu/esp32h2/pau_hal.c diff --git a/components/hal/esp32h2/pmu_hal.c b/components/esp_hal_pmu/esp32h2/pmu_hal.c similarity index 100% rename from components/hal/esp32h2/pmu_hal.c rename to components/esp_hal_pmu/esp32h2/pmu_hal.c diff --git a/components/hal/esp32h21/include/hal/pau_ll.h b/components/esp_hal_pmu/esp32h21/include/hal/pau_ll.h similarity index 100% rename from components/hal/esp32h21/include/hal/pau_ll.h rename to components/esp_hal_pmu/esp32h21/include/hal/pau_ll.h diff --git a/components/hal/esp32h21/include/hal/pmu_hal.h b/components/esp_hal_pmu/esp32h21/include/hal/pmu_hal.h similarity index 100% rename from components/hal/esp32h21/include/hal/pmu_hal.h rename to components/esp_hal_pmu/esp32h21/include/hal/pmu_hal.h diff --git a/components/hal/esp32h21/include/hal/pmu_ll.h b/components/esp_hal_pmu/esp32h21/include/hal/pmu_ll.h similarity index 99% rename from components/hal/esp32h21/include/hal/pmu_ll.h rename to components/esp_hal_pmu/esp32h21/include/hal/pmu_ll.h index 0f6bed916a9..3a547620ddb 100644 --- a/components/hal/esp32h21/include/hal/pmu_ll.h +++ b/components/esp_hal_pmu/esp32h21/include/hal/pmu_ll.h @@ -139,7 +139,6 @@ FORCE_INLINE_ATTR void pmu_ll_hp_set_discnnt_dig_rtc(pmu_dev_t *hw, pmu_hp_mode_ hw->hp_sys[mode].bias.discnnt_dig_rtc = discnnt; } - FORCE_INLINE_ATTR void pmu_ll_hp_set_current_power_off(pmu_dev_t *hw, pmu_hp_mode_t mode, bool off) { hw->hp_sys[mode].bias.pd_cur = off; diff --git a/components/hal/esp32h21/pau_hal.c b/components/esp_hal_pmu/esp32h21/pau_hal.c similarity index 100% rename from components/hal/esp32h21/pau_hal.c rename to components/esp_hal_pmu/esp32h21/pau_hal.c diff --git a/components/hal/esp32h21/pmu_hal.c b/components/esp_hal_pmu/esp32h21/pmu_hal.c similarity index 100% rename from components/hal/esp32h21/pmu_hal.c rename to components/esp_hal_pmu/esp32h21/pmu_hal.c diff --git a/components/hal/esp32h4/include/hal/pau_ll.h b/components/esp_hal_pmu/esp32h4/include/hal/pau_ll.h similarity index 100% rename from components/hal/esp32h4/include/hal/pau_ll.h rename to components/esp_hal_pmu/esp32h4/include/hal/pau_ll.h diff --git a/components/hal/esp32h4/include/hal/pmu_hal.h b/components/esp_hal_pmu/esp32h4/include/hal/pmu_hal.h similarity index 100% rename from components/hal/esp32h4/include/hal/pmu_hal.h rename to components/esp_hal_pmu/esp32h4/include/hal/pmu_hal.h diff --git a/components/hal/esp32h4/include/hal/pmu_ll.h b/components/esp_hal_pmu/esp32h4/include/hal/pmu_ll.h similarity index 100% rename from components/hal/esp32h4/include/hal/pmu_ll.h rename to components/esp_hal_pmu/esp32h4/include/hal/pmu_ll.h diff --git a/components/hal/esp32h4/pau_hal.c b/components/esp_hal_pmu/esp32h4/pau_hal.c similarity index 100% rename from components/hal/esp32h4/pau_hal.c rename to components/esp_hal_pmu/esp32h4/pau_hal.c diff --git a/components/hal/esp32h4/pmu_hal.c b/components/esp_hal_pmu/esp32h4/pmu_hal.c similarity index 100% rename from components/hal/esp32h4/pmu_hal.c rename to components/esp_hal_pmu/esp32h4/pmu_hal.c diff --git a/components/hal/esp32p4/include/hal/pau_ll.h b/components/esp_hal_pmu/esp32p4/include/hal/pau_ll.h similarity index 100% rename from components/hal/esp32p4/include/hal/pau_ll.h rename to components/esp_hal_pmu/esp32p4/include/hal/pau_ll.h diff --git a/components/hal/esp32p4/include/hal/pmu_hal.h b/components/esp_hal_pmu/esp32p4/include/hal/pmu_hal.h similarity index 100% rename from components/hal/esp32p4/include/hal/pmu_hal.h rename to components/esp_hal_pmu/esp32p4/include/hal/pmu_hal.h diff --git a/components/hal/esp32p4/include/hal/pmu_ll.h b/components/esp_hal_pmu/esp32p4/include/hal/pmu_ll.h similarity index 99% rename from components/hal/esp32p4/include/hal/pmu_ll.h rename to components/esp_hal_pmu/esp32p4/include/hal/pmu_ll.h index 35c7629ebe9..b43ef8f40c4 100644 --- a/components/hal/esp32p4/include/hal/pmu_ll.h +++ b/components/esp_hal_pmu/esp32p4/include/hal/pmu_ll.h @@ -156,7 +156,6 @@ FORCE_INLINE_ATTR void pmu_ll_hp_set_sleep_to_active_backup_disable(pmu_dev_t *h hw->hp_sys[PMU_MODE_HP_ACTIVE].backup.hp_sleep2active_backup_en = 0; } - FORCE_INLINE_ATTR void pmu_ll_hp_set_active_to_sleep_backup_enable(pmu_dev_t *hw) { hw->hp_sys[PMU_MODE_HP_SLEEP].backup.hp_active2sleep_backup_en = 1; @@ -234,7 +233,6 @@ FORCE_INLINE_ATTR void pmu_ll_hp_set_regulator_driver_bar(pmu_dev_t *hw, pmu_hp_ hw->hp_sys[mode].regulator1.drv_b = drv_b; } - FORCE_INLINE_ATTR void pmu_ll_lp_set_regulator_slp_xpd(pmu_dev_t *hw, pmu_lp_mode_t mode, bool slp_xpd) { hw->lp_sys[mode].regulator0.slp_xpd = slp_xpd; @@ -266,7 +264,6 @@ FORCE_INLINE_ATTR void pmu_ll_lp_set_xtal_xpd(pmu_dev_t *hw, pmu_lp_mode_t mode, hw->lp_sys[mode].xtal.xpd_xtal = xpd_xtal; } - FORCE_INLINE_ATTR void pmu_ll_lp_set_dig_power(pmu_dev_t *hw, pmu_lp_mode_t mode, uint32_t flag) { hw->lp_sys[mode].dig_power.val = flag; diff --git a/components/hal/esp32p4/pau_hal.c b/components/esp_hal_pmu/esp32p4/pau_hal.c similarity index 100% rename from components/hal/esp32p4/pau_hal.c rename to components/esp_hal_pmu/esp32p4/pau_hal.c diff --git a/components/hal/esp32p4/pmu_hal.c b/components/esp_hal_pmu/esp32p4/pmu_hal.c similarity index 100% rename from components/hal/esp32p4/pmu_hal.c rename to components/esp_hal_pmu/esp32p4/pmu_hal.c diff --git a/components/hal/esp32s2/include/hal/rtc_cntl_ll.h b/components/esp_hal_pmu/esp32s2/include/hal/rtc_cntl_ll.h similarity index 96% rename from components/hal/esp32s2/include/hal/rtc_cntl_ll.h rename to components/esp_hal_pmu/esp32s2/include/hal/rtc_cntl_ll.h index d1f1817e52b..9e5d028ad95 100644 --- a/components/hal/esp32s2/include/hal/rtc_cntl_ll.h +++ b/components/esp_hal_pmu/esp32s2/include/hal/rtc_cntl_ll.h @@ -41,10 +41,10 @@ FORCE_INLINE_ATTR void rtc_cntl_ll_ext1_set_wakeup_pins(uint32_t io_mask, uint32 REG_SET_FIELD(RTC_CNTL_EXT_WAKEUP1_REG, RTC_CNTL_EXT_WAKEUP1_SEL, io_mask); if ((io_mask & mode_mask) == io_mask) { SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 1, RTC_CNTL_EXT_WAKEUP1_LV_S); + 1, RTC_CNTL_EXT_WAKEUP1_LV_S); } else { SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 0, RTC_CNTL_EXT_WAKEUP1_LV_S); + 0, RTC_CNTL_EXT_WAKEUP1_LV_S); } } diff --git a/components/hal/esp32s3/include/hal/rtc_cntl_ll.h b/components/esp_hal_pmu/esp32s3/include/hal/rtc_cntl_ll.h similarity index 98% rename from components/hal/esp32s3/include/hal/rtc_cntl_ll.h rename to components/esp_hal_pmu/esp32s3/include/hal/rtc_cntl_ll.h index 027dd79d7ba..83c851eb317 100644 --- a/components/hal/esp32s3/include/hal/rtc_cntl_ll.h +++ b/components/esp_hal_pmu/esp32s3/include/hal/rtc_cntl_ll.h @@ -45,10 +45,10 @@ FORCE_INLINE_ATTR void rtc_cntl_ll_ext1_set_wakeup_pins(uint32_t io_mask, uint32 REG_SET_FIELD(RTC_CNTL_EXT_WAKEUP1_REG, RTC_CNTL_EXT_WAKEUP1_SEL, io_mask); if ((io_mask & mode_mask) == io_mask) { SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 1, RTC_CNTL_EXT_WAKEUP1_LV_S); + 1, RTC_CNTL_EXT_WAKEUP1_LV_S); } else { SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, - 0, RTC_CNTL_EXT_WAKEUP1_LV_S); + 0, RTC_CNTL_EXT_WAKEUP1_LV_S); } } diff --git a/components/hal/esp32s3/rtc_cntl_hal.c b/components/esp_hal_pmu/esp32s3/rtc_cntl_hal.c similarity index 89% rename from components/hal/esp32s3/rtc_cntl_hal.c rename to components/esp_hal_pmu/esp32s3/rtc_cntl_hal.c index 94c74908b7c..42ce5eca073 100644 --- a/components/hal/esp32s3/rtc_cntl_hal.c +++ b/components/esp_hal_pmu/esp32s3/rtc_cntl_hal.c @@ -62,10 +62,10 @@ void rtc_cntl_hal_enable_cpu_retention(void *addr) rtc_cntl_ll_set_cpu_retention_link_addr((uint32_t)plink); rtc_cntl_ll_config_cpu_retention_timing( - DEFAULT_RETENTION_WAIT_CYCLES, - DEFAULT_RETENTION_CLKOFF_WAIT_CYCLES, - DEFAULT_RETENTION_DONE_WAIT_CYCLES - ); + DEFAULT_RETENTION_WAIT_CYCLES, + DEFAULT_RETENTION_CLKOFF_WAIT_CYCLES, + DEFAULT_RETENTION_DONE_WAIT_CYCLES + ); rtc_cntl_ll_enable_cpu_retention_clock(); rtc_cntl_ll_enable_cpu_retention(); #if SOC_PM_SUPPORT_TAGMEM_PD @@ -119,17 +119,17 @@ void rtc_cntl_hal_enable_tagmem_retention(void *addr) rtc_cntl_ll_enable_tagmem_retention(); if (retent->tagmem.icache.enable) { rtc_cntl_ll_enable_icache_tagmem_retention( - retent->tagmem.icache.start_point, - retent->tagmem.icache.vld_size, - retent->tagmem.icache.size - ); + retent->tagmem.icache.start_point, + retent->tagmem.icache.vld_size, + retent->tagmem.icache.size + ); } if (retent->tagmem.dcache.enable) { rtc_cntl_ll_enable_dcache_tagmem_retention( - retent->tagmem.dcache.start_point, - retent->tagmem.dcache.vld_size, - retent->tagmem.dcache.size - ); + retent->tagmem.dcache.start_point, + retent->tagmem.dcache.vld_size, + retent->tagmem.dcache.size + ); } } } diff --git a/components/esp_hal_pmu/esp32s31/include/hal/pmu_hal.h b/components/esp_hal_pmu/esp32s31/include/hal/pmu_hal.h new file mode 100644 index 00000000000..310e1e5d2d8 --- /dev/null +++ b/components/esp_hal_pmu/esp32s31/include/hal/pmu_hal.h @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// The HAL layer for PMU + +#pragma once + +#include "soc/soc_caps.h" +#include "hal/pmu_ll.h" +#include "hal/pmu_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// TODO: ["ESP32S31"] IDF-14653 + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_hal_pmu/esp32s31/include/hal/pmu_ll.h b/components/esp_hal_pmu/esp32s31/include/hal/pmu_ll.h new file mode 100644 index 00000000000..df367ee7acb --- /dev/null +++ b/components/esp_hal_pmu/esp32s31/include/hal/pmu_ll.h @@ -0,0 +1,29 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// The LL layer for ESP32-S31 PMU register operations + +#pragma once + +#include +#include +#include "soc/soc.h" +#include "esp_attr.h" +#include "hal/assert.h" +#include "soc/pmu_struct.h" +#include "hal/pmu_types.h" +#include "hal/misc.h" +#include "hal/config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// TODO: ["ESP32S31"] IDF-14653 + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_hal_pmu/esp32s31/pmu_hal.c b/components/esp_hal_pmu/esp32s31/pmu_hal.c new file mode 100644 index 00000000000..260f27086e7 --- /dev/null +++ b/components/esp_hal_pmu/esp32s31/pmu_hal.c @@ -0,0 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// The HAL layer for PMU (ESP32-S31 specific part) + +// TODO: ["ESP32S31"] IDF-14653 diff --git a/components/hal/include/hal/pau_hal.h b/components/esp_hal_pmu/include/hal/pau_hal.h similarity index 99% rename from components/hal/include/hal/pau_hal.h rename to components/esp_hal_pmu/include/hal/pau_hal.h index 5311e6bc617..522889a85b6 100644 --- a/components/hal/include/hal/pau_hal.h +++ b/components/esp_hal_pmu/include/hal/pau_hal.h @@ -17,7 +17,6 @@ extern "C" { #include "hal/pau_ll.h" #include "hal/pau_types.h" - typedef struct { pau_dev_t *dev; } pau_hal_context_t; diff --git a/components/hal/include/hal/pau_types.h b/components/esp_hal_pmu/include/hal/pau_types.h similarity index 100% rename from components/hal/include/hal/pau_types.h rename to components/esp_hal_pmu/include/hal/pau_types.h diff --git a/components/hal/include/hal/pmu_types.h b/components/esp_hal_pmu/include/hal/pmu_types.h similarity index 100% rename from components/hal/include/hal/pmu_types.h rename to components/esp_hal_pmu/include/hal/pmu_types.h diff --git a/components/hal/include/hal/rtc_hal.h b/components/esp_hal_pmu/include/hal/rtc_hal.h similarity index 100% rename from components/hal/include/hal/rtc_hal.h rename to components/esp_hal_pmu/include/hal/rtc_hal.h diff --git a/components/esp_hal_pmu/linker.lf b/components/esp_hal_pmu/linker.lf new file mode 100644 index 00000000000..68cf8a27200 --- /dev/null +++ b/components/esp_hal_pmu/linker.lf @@ -0,0 +1,5 @@ +[mapping:esp_hal_pmu] +archive: libesp_hal_pmu.a +entries: + if SOC_PMU_SUPPORTED = y: + pmu_hal (noflash) diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index b2cc4aac1d4..3c3b6516813 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -9,7 +9,7 @@ if(${target} STREQUAL "linux") return() endif() -set(requires esp_hal_dma esp_hal_gpio esp_hal_usb) +set(requires esp_hal_dma esp_hal_gpio esp_hal_usb esp_hal_pmu) # only esp_hw_support/adc_share_hw_ctrl.c requires efuse component set(priv_requires efuse spi_flash bootloader_support esp_hal_wdt) diff --git a/components/esp_pm/linker.lf b/components/esp_pm/linker.lf index a95de76a257..97f406f72b2 100644 --- a/components/esp_pm/linker.lf +++ b/components/esp_pm/linker.lf @@ -81,14 +81,18 @@ entries: esp_time_impl:esp_time_impl_get_boot_time (noflash) esp_time_impl:esp_set_time_from_rtc (noflash) -[mapping:hal_pm] -archive: libhal.a +[mapping:esp_hal_pmu_pm] +archive: libesp_hal_pmu.a entries: if SOC_PM_CPU_RETENTION_BY_RTCCNTL = y: if PM_SLP_IRAM_OPT = y && PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP = y: rtc_cntl_hal:rtc_cntl_hal_enable_cpu_retention (noflash) if PM_SLP_IRAM_OPT = y && PM_RESTORE_CACHE_TAGMEM_AFTER_LIGHT_SLEEP = y: rtc_cntl_hal:rtc_cntl_hal_enable_tagmem_retention (noflash) + +[mapping:hal_pm] +archive: libhal.a +entries: if SOC_TEMP_SENSOR_SUPPORTED = y: if PM_SLP_IRAM_OPT = y: temperature_sensor_hal:temperature_sensor_hal_get_raw_value (noflash) diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 35b6b3bc985..60c3356a424 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -120,10 +120,6 @@ elseif(NOT BOOTLOADER_BUILD) list(APPEND srcs "${target}/modem_clock_hal.c") endif() - if(CONFIG_SOC_PAU_SUPPORTED) - list(APPEND srcs "${target}/pau_hal.c") - endif() - if(CONFIG_SOC_BOD_SUPPORTED) list(APPEND srcs "brownout_hal.c") endif() @@ -140,10 +136,6 @@ elseif(NOT BOOTLOADER_BUILD) list(APPEND srcs "sdio_slave_hal.c") endif() - if(CONFIG_SOC_PMU_SUPPORTED) - list(APPEND srcs "${target}/pmu_hal.c") - endif() - if(CONFIG_SOC_APM_SUPPORTED) list(APPEND srcs "apm_hal.c") endif() @@ -161,11 +153,6 @@ elseif(NOT BOOTLOADER_BUILD) if(CONFIG_SOC_TEMP_SENSOR_SUPPORTED) list(APPEND srcs "temperature_sensor_hal.c") endif() - - if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/rtc_cntl_hal.c") - list(APPEND srcs "${target}/rtc_cntl_hal.c") - endif() - endif() idf_component_register(SRCS ${srcs} diff --git a/components/hal/linker.lf b/components/hal/linker.lf index c9116c144ce..ae63d55e2e6 100644 --- a/components/hal/linker.lf +++ b/components/hal/linker.lf @@ -9,5 +9,3 @@ entries: cache_hal (noflash) if SOC_SYSTIMER_SUPPORTED = y && HAL_SYSTIMER_USE_ROM_IMPL = n: systimer_hal (noflash) - if SOC_PMU_SUPPORTED = y: - pmu_hal (noflash) diff --git a/components/ulp/CMakeLists.txt b/components/ulp/CMakeLists.txt index 41ee4bbd5f9..c9098f9a808 100644 --- a/components/ulp/CMakeLists.txt +++ b/components/ulp/CMakeLists.txt @@ -97,5 +97,6 @@ endif() idf_component_register( SRCS ${srcs} INCLUDE_DIRS ${includes} - REQUIRES esp_adc esp_driver_gpio esp_driver_uart esp_driver_i2s esp_hal_i2c esp_hal_touch_sens esp_hal_gpspi + REQUIRES esp_adc esp_driver_gpio esp_driver_uart esp_driver_i2s + esp_hal_i2c esp_hal_touch_sens esp_hal_gpspi esp_hal_pmu ) diff --git a/tools/test_apps/system/g1_components/CMakeLists.txt b/tools/test_apps/system/g1_components/CMakeLists.txt index f0774c2f347..d902b0184f0 100644 --- a/tools/test_apps/system/g1_components/CMakeLists.txt +++ b/tools/test_apps/system/g1_components/CMakeLists.txt @@ -21,6 +21,7 @@ set(esp_hal_components esp_hal_usb esp_hal_wdt esp_hal_gpspi + esp_hal_pmu ) set(COMPONENTS ${g0_components} ${g1_components} ${esp_hal_components} main)