diff --git a/components/esp_driver_jpeg/CMakeLists.txt b/components/esp_driver_jpeg/CMakeLists.txt index 49740cb8466..2741e9165a0 100644 --- a/components/esp_driver_jpeg/CMakeLists.txt +++ b/components/esp_driver_jpeg/CMakeLists.txt @@ -9,6 +9,9 @@ if(CONFIG_SOC_JPEG_CODEC_SUPPORTED) "jpeg_common.c" "jpeg_param.c" ) + if(CONFIG_SOC_PAU_SUPPORTED) + list(APPEND srcs "${target}/jpeg_retention.c") + endif() if(CONFIG_SOC_JPEG_DECODE_SUPPORTED) list(APPEND srcs "jpeg_parse_marker.c" @@ -33,6 +36,7 @@ endif() idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${public_include} + PRIV_INCLUDE_DIRS "." PRIV_REQUIRES "${priv_requires}" REQUIRES "${requires}" ) diff --git a/components/esp_driver_jpeg/esp32p4/jpeg_retention.c b/components/esp_driver_jpeg/esp32p4/jpeg_retention.c new file mode 100644 index 00000000000..bb5f60c39f0 --- /dev/null +++ b/components/esp_driver_jpeg/esp32p4/jpeg_retention.c @@ -0,0 +1,28 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "jpeg_private.h" + +// JPEG_CONFIG_REG JPEG_INT_ENA_REG +#define JPEG_RETENTION_REGS_CNT 2 +#define JPEG_RETENTION_REGS_BASE (DR_REG_JPEG_BASE + 0x0) +static const uint32_t jpeg_regs_map[4] = {0x8001, 0x0, 0x0, 0x0}; +static const regdma_entries_config_t jpeg_regdma_entries[] = { + [0] = { + .config = REGDMA_LINK_ADDR_MAP_INIT(REGDMA_JPEG_LINK(0x00), + JPEG_RETENTION_REGS_BASE, JPEG_RETENTION_REGS_BASE, + JPEG_RETENTION_REGS_CNT, 0, 0, + jpeg_regs_map[0], jpeg_regs_map[1], + jpeg_regs_map[2], jpeg_regs_map[3]), + .owner = ENTRY(0) | ENTRY(2), + }, +}; + +const jpeg_reg_retention_info_t jpeg_reg_retention_info = { + .entry_array = jpeg_regdma_entries, + .array_size = ARRAY_SIZE(jpeg_regdma_entries), + .module_id = SLEEP_RETENTION_MODULE_JPEG, +}; diff --git a/components/esp_driver_jpeg/esp32s31/jpeg_retention.c b/components/esp_driver_jpeg/esp32s31/jpeg_retention.c new file mode 100644 index 00000000000..bb5f60c39f0 --- /dev/null +++ b/components/esp_driver_jpeg/esp32s31/jpeg_retention.c @@ -0,0 +1,28 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "jpeg_private.h" + +// JPEG_CONFIG_REG JPEG_INT_ENA_REG +#define JPEG_RETENTION_REGS_CNT 2 +#define JPEG_RETENTION_REGS_BASE (DR_REG_JPEG_BASE + 0x0) +static const uint32_t jpeg_regs_map[4] = {0x8001, 0x0, 0x0, 0x0}; +static const regdma_entries_config_t jpeg_regdma_entries[] = { + [0] = { + .config = REGDMA_LINK_ADDR_MAP_INIT(REGDMA_JPEG_LINK(0x00), + JPEG_RETENTION_REGS_BASE, JPEG_RETENTION_REGS_BASE, + JPEG_RETENTION_REGS_CNT, 0, 0, + jpeg_regs_map[0], jpeg_regs_map[1], + jpeg_regs_map[2], jpeg_regs_map[3]), + .owner = ENTRY(0) | ENTRY(2), + }, +}; + +const jpeg_reg_retention_info_t jpeg_reg_retention_info = { + .entry_array = jpeg_regdma_entries, + .array_size = ARRAY_SIZE(jpeg_regdma_entries), + .module_id = SLEEP_RETENTION_MODULE_JPEG, +}; diff --git a/components/esp_driver_jpeg/jpeg_common.c b/components/esp_driver_jpeg/jpeg_common.c index d5c7ffdf6fc..27aa2845969 100644 --- a/components/esp_driver_jpeg/jpeg_common.c +++ b/components/esp_driver_jpeg/jpeg_common.c @@ -41,7 +41,7 @@ static jpeg_platform_t s_jpeg_platform = {}; // singleton platform #if JPEG_USE_RETENTION_LINK static esp_err_t s_jpeg_sleep_retention_init_cb(void *arg) { - esp_err_t ret = sleep_retention_entries_create(jpeg_regs_retention.link_list, jpeg_regs_retention.link_num, REGDMA_LINK_PRI_JPEG, jpeg_regs_retention.module_id); + esp_err_t ret = sleep_retention_entries_create(jpeg_reg_retention_info.entry_array, jpeg_reg_retention_info.array_size, REGDMA_LINK_PRI_JPEG, jpeg_reg_retention_info.module_id); ESP_RETURN_ON_ERROR(ret, TAG, "failed to allocate mem for sleep retention"); return ret; } @@ -50,12 +50,12 @@ void jpeg_create_retention_module(jpeg_codec_handle_t jpeg_codec) { _lock_acquire(&s_jpeg_platform.mutex); if (jpeg_codec->retention_link_created == false) { - if (sleep_retention_module_allocate(jpeg_regs_retention.module_id) != ESP_OK) { + if (sleep_retention_module_allocate(jpeg_reg_retention_info.module_id) != ESP_OK) { // even though the sleep retention module create failed, JPEG driver should still work, so just warning here ESP_LOGW(TAG, "create retention module failed, power domain can't turn off"); } else { jpeg_codec->retention_link_created = true; - if (sleep_retention_module_attach(jpeg_regs_retention.module_id) != ESP_OK) { + if (sleep_retention_module_attach(jpeg_reg_retention_info.module_id) != ESP_OK) { ESP_LOGW(TAG, "attach retention module failed, power domain can't turn off"); } } @@ -97,7 +97,7 @@ esp_err_t jpeg_acquire_codec_handle(jpeg_codec_handle_t *jpeg_new_codec) .attribute = SLEEP_RETENTION_MODULE_ATTR_ATTACH, .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_SYSTEM) }; - esp_err_t err = sleep_retention_module_init(jpeg_regs_retention.module_id, &init_param); + esp_err_t err = sleep_retention_module_init(jpeg_reg_retention_info.module_id, &init_param); if (err != ESP_OK) { ESP_LOGW(TAG, "init sleep retention failed on jpeg, jpeg configuration maybe lost after sleep wakeup"); } @@ -108,7 +108,7 @@ esp_err_t jpeg_acquire_codec_handle(jpeg_codec_handle_t *jpeg_new_codec) jpeg_ll_reset_module_register(); } #if CONFIG_PM_ENABLE - ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "jpeg_codec", &codec->pm_lock), TAG, "create pm lock failed"); + ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, soc_jpeg_signals[0].module_name, &codec->pm_lock), TAG, "create pm lock failed"); #endif jpeg_hal_init(&codec->hal); } else { @@ -152,10 +152,10 @@ esp_err_t jpeg_release_codec_handle(jpeg_codec_handle_t jpeg_codec) #if JPEG_USE_RETENTION_LINK if (jpeg_codec->retention_link_created) { - sleep_retention_module_detach(jpeg_regs_retention.module_id); - sleep_retention_module_free(jpeg_regs_retention.module_id); + sleep_retention_module_detach(jpeg_reg_retention_info.module_id); + sleep_retention_module_free(jpeg_reg_retention_info.module_id); } - sleep_retention_module_deinit(jpeg_regs_retention.module_id); + sleep_retention_module_deinit(jpeg_reg_retention_info.module_id); #endif PERIPH_RCC_ATOMIC() { @@ -194,7 +194,7 @@ esp_err_t jpeg_isr_register(jpeg_codec_handle_t jpeg_codec, intr_handler_t handl { if (jpeg_codec->intr_handle == NULL) { // The jpeg codec interrupt has not been allocated. - esp_err_t err = esp_intr_alloc_intrstatus(ETS_JPEG_INTR_SOURCE, flags, (uint32_t)jpeg_ll_get_interrupt_status_reg(jpeg_codec->hal.dev), JPEG_LL_DECODER_EVENT_INTR | JPEG_LL_ENCODER_EVENT_INTR, &jpeg_isr, jpeg_codec, &jpeg_codec->intr_handle); + esp_err_t err = esp_intr_alloc_intrstatus(soc_jpeg_signals[0].irq_id, flags, (uint32_t)jpeg_ll_get_interrupt_status_reg(jpeg_codec->hal.dev), JPEG_LL_DECODER_EVENT_INTR | JPEG_LL_ENCODER_EVENT_INTR, &jpeg_isr, jpeg_codec, &jpeg_codec->intr_handle); if (err != ESP_OK) { return err; } diff --git a/components/esp_driver_jpeg/jpeg_private.h b/components/esp_driver_jpeg/jpeg_private.h index 1b0838050a0..1a03c53f4ab 100644 --- a/components/esp_driver_jpeg/jpeg_private.h +++ b/components/esp_driver_jpeg/jpeg_private.h @@ -19,6 +19,10 @@ #include "esp_intr_types.h" #include "esp_pm.h" #include "sdkconfig.h" +#if SOC_PAU_SUPPORTED +#include "soc/regdma.h" +#include "soc/retention_periph_defs.h" +#endif #ifdef __cplusplus extern "C" { @@ -72,6 +76,16 @@ struct jpeg_codec_t { bool retention_link_created; // mark if the retention link is created. }; +#if SOC_PAU_SUPPORTED +typedef struct { + const regdma_entries_config_t *entry_array; + uint32_t array_size; + periph_retention_module_t module_id; +} jpeg_reg_retention_info_t; + +extern const jpeg_reg_retention_info_t jpeg_reg_retention_info; +#endif + typedef enum { JPEG_DEC_DIRECT_OUTPUT_HB = 0, /*!< Direct output */ JPEG_DEC_YUV444_HB = 1, /*!< output YUV444 format */ diff --git a/components/esp_hal_jpeg/esp32p4/jpeg_periph.c b/components/esp_hal_jpeg/esp32p4/jpeg_periph.c index f1777abe443..885caf94b51 100644 --- a/components/esp_hal_jpeg/esp32p4/jpeg_periph.c +++ b/components/esp_hal_jpeg/esp32p4/jpeg_periph.c @@ -5,24 +5,11 @@ */ #include "hal/jpeg_periph.h" +#include "soc/interrupts.h" -// JPEG_CONFIG_REG JPEG_INT_ENA_REG -#define JPEG_RETENTION_REGS_CNT 2 -#define JPEG_RETENTION_REGS_BASE (DR_REG_JPEG_BASE + 0x0) -static const uint32_t jpeg_regs_map[4] = {0x8001, 0x0, 0x0, 0x0}; -static const regdma_entries_config_t jpeg_regdma_entries[] = { +const soc_jpeg_signal_desc_t soc_jpeg_signals[1] = { [0] = { - .config = REGDMA_LINK_ADDR_MAP_INIT(REGDMA_JPEG_LINK(0x00), - JPEG_RETENTION_REGS_BASE, JPEG_RETENTION_REGS_BASE, - JPEG_RETENTION_REGS_CNT, 0, 0, - jpeg_regs_map[0], jpeg_regs_map[1], - jpeg_regs_map[2], jpeg_regs_map[3]), - .owner = ENTRY(0) | ENTRY(2), - }, -}; - -const jpeg_reg_ctx_link_t jpeg_regs_retention = { - .link_list = jpeg_regdma_entries, - .link_num = ARRAY_SIZE(jpeg_regdma_entries), - .module_id = SLEEP_RETENTION_MODULE_JPEG, + .module_name = "JPEG", + .irq_id = ETS_JPEG_INTR_SOURCE, + } }; diff --git a/components/esp_hal_jpeg/esp32s31/jpeg_periph.c b/components/esp_hal_jpeg/esp32s31/jpeg_periph.c index f1777abe443..885caf94b51 100644 --- a/components/esp_hal_jpeg/esp32s31/jpeg_periph.c +++ b/components/esp_hal_jpeg/esp32s31/jpeg_periph.c @@ -5,24 +5,11 @@ */ #include "hal/jpeg_periph.h" +#include "soc/interrupts.h" -// JPEG_CONFIG_REG JPEG_INT_ENA_REG -#define JPEG_RETENTION_REGS_CNT 2 -#define JPEG_RETENTION_REGS_BASE (DR_REG_JPEG_BASE + 0x0) -static const uint32_t jpeg_regs_map[4] = {0x8001, 0x0, 0x0, 0x0}; -static const regdma_entries_config_t jpeg_regdma_entries[] = { +const soc_jpeg_signal_desc_t soc_jpeg_signals[1] = { [0] = { - .config = REGDMA_LINK_ADDR_MAP_INIT(REGDMA_JPEG_LINK(0x00), - JPEG_RETENTION_REGS_BASE, JPEG_RETENTION_REGS_BASE, - JPEG_RETENTION_REGS_CNT, 0, 0, - jpeg_regs_map[0], jpeg_regs_map[1], - jpeg_regs_map[2], jpeg_regs_map[3]), - .owner = ENTRY(0) | ENTRY(2), - }, -}; - -const jpeg_reg_ctx_link_t jpeg_regs_retention = { - .link_list = jpeg_regdma_entries, - .link_num = ARRAY_SIZE(jpeg_regdma_entries), - .module_id = SLEEP_RETENTION_MODULE_JPEG, + .module_name = "JPEG", + .irq_id = ETS_JPEG_INTR_SOURCE, + } }; diff --git a/components/esp_hal_jpeg/include/hal/jpeg_periph.h b/components/esp_hal_jpeg/include/hal/jpeg_periph.h index f4a6a6c872c..75a22053a71 100644 --- a/components/esp_hal_jpeg/include/hal/jpeg_periph.h +++ b/components/esp_hal_jpeg/include/hal/jpeg_periph.h @@ -7,26 +7,18 @@ #pragma once #include "soc/soc_caps.h" -#if SOC_JPEG_CODEC_SUPPORTED -#include "soc/regdma.h" -#include "soc/interrupts.h" -#include "soc/retention_periph_defs.h" -#include "soc/jpeg_reg.h" #ifdef __cplusplus extern "C" { #endif typedef struct { - const regdma_entries_config_t *link_list; - uint32_t link_num; - periph_retention_module_t module_id; -} jpeg_reg_ctx_link_t; + const char *module_name; // Module name + const int irq_id; // interrupt source ID +} soc_jpeg_signal_desc_t; -extern const jpeg_reg_ctx_link_t jpeg_regs_retention; +extern const soc_jpeg_signal_desc_t soc_jpeg_signals[1]; #ifdef __cplusplus } #endif - -#endif // SOC_JPEG_CODEC_SUPPORTED