2023-02-14 01:35:05 -05:00
|
|
|
/*
|
2024-01-19 04:48:35 -05:00
|
|
|
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
2023-02-14 01:35:05 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "soc/soc_caps.h"
|
2024-01-19 04:48:35 -05:00
|
|
|
#include "soc/system_periph_retention.h"
|
2023-02-14 01:35:05 -05:00
|
|
|
|
|
|
|
#include "esp_sleep.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_check.h"
|
|
|
|
|
|
|
|
#include "esp_private/startup_internal.h"
|
|
|
|
#include "esp_private/sleep_retention.h"
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
static __attribute__((unused)) const char *TAG = "sleep_sys_periph";
|
2023-02-14 01:35:05 -05:00
|
|
|
|
|
|
|
#define SLEEP_RETENTION_PERIPHERALS_PRIORITY_DEFAULT (REGDMA_LINK_PRI_6)
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_intr_matrix_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
esp_err_t err = sleep_retention_entries_create(intr_matrix_regs_retention, ARRAY_SIZE(intr_matrix_regs_retention), REGDMA_LINK_PRI_5, SLEEP_RETENTION_MODULE_INTR_MATRIX);
|
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for digital peripherals (Interrupt matrix) retention");
|
|
|
|
ESP_LOGI(TAG, "Interrupt Matrix sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_hp_system_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
esp_err_t err = sleep_retention_entries_create(hp_system_regs_retention, ARRAY_SIZE(hp_system_regs_retention), REGDMA_LINK_PRI_5, SLEEP_RETENTION_MODULE_HP_SYSTEM);
|
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for digital peripherals (HP system) retention");
|
|
|
|
ESP_LOGI(TAG, "HP System sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_tee_apm_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
2023-09-06 02:57:46 -04:00
|
|
|
esp_err_t err = sleep_retention_entries_create(tee_apm_regs_retention, ARRAY_SIZE(tee_apm_regs_retention), REGDMA_LINK_PRI_4, SLEEP_RETENTION_MODULE_TEE_APM);
|
|
|
|
if (err == ESP_OK) {
|
2024-01-19 04:48:35 -05:00
|
|
|
err = sleep_retention_entries_create(tee_apm_highpri_regs_retention, ARRAY_SIZE(tee_apm_highpri_regs_retention), REGDMA_LINK_PRI_2, SLEEP_RETENTION_MODULE_TEE_APM);
|
2023-09-06 02:57:46 -04:00
|
|
|
}
|
2023-02-14 01:35:05 -05:00
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for digital peripherals (TEE/APM) retention");
|
|
|
|
ESP_LOGI(TAG, "TEE/APM sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_uart0_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
esp_err_t err = sleep_retention_entries_create(uart_regs_retention, ARRAY_SIZE(uart_regs_retention), REGDMA_LINK_PRI_5, SLEEP_RETENTION_MODULE_UART0);
|
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for digital peripherals (UART) retention");
|
|
|
|
ESP_LOGI(TAG, "UART sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_tg0_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
esp_err_t err = sleep_retention_entries_create(tg_regs_retention, ARRAY_SIZE(tg_regs_retention), SLEEP_RETENTION_PERIPHERALS_PRIORITY_DEFAULT, SLEEP_RETENTION_MODULE_TG0);
|
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for digital peripherals (Timer Group) retention");
|
|
|
|
ESP_LOGI(TAG, "Timer Group sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_iomux_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
esp_err_t err = sleep_retention_entries_create(iomux_regs_retention, ARRAY_SIZE(iomux_regs_retention), SLEEP_RETENTION_PERIPHERALS_PRIORITY_DEFAULT, SLEEP_RETENTION_MODULE_IOMUX);
|
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for digital peripherals (IO Matrix) retention");
|
|
|
|
ESP_LOGI(TAG, "IO Matrix sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_spimem_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
esp_err_t err = sleep_retention_entries_create(spimem_regs_retention, ARRAY_SIZE(spimem_regs_retention), SLEEP_RETENTION_PERIPHERALS_PRIORITY_DEFAULT, SLEEP_RETENTION_MODULE_SPIMEM);
|
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for digital peripherals (SPI mem) retention");
|
|
|
|
ESP_LOGI(TAG, "SPI Mem sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_systimer_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
esp_err_t err = sleep_retention_entries_create(systimer_regs_retention, ARRAY_SIZE(systimer_regs_retention), SLEEP_RETENTION_PERIPHERALS_PRIORITY_DEFAULT, SLEEP_RETENTION_MODULE_SYSTIMER);
|
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for digital peripherals (SysTimer) retention");
|
|
|
|
ESP_LOGI(TAG, "SysTimer sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-02-15 03:35:23 -05:00
|
|
|
esp_err_t sleep_sys_periph_retention_init(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
esp_err_t err;
|
2023-02-15 03:35:23 -05:00
|
|
|
err = sleep_sys_periph_intr_matrix_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
if(err) goto error;
|
2023-02-15 03:35:23 -05:00
|
|
|
err = sleep_sys_periph_hp_system_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
if(err) goto error;
|
2023-02-15 03:35:23 -05:00
|
|
|
err = sleep_sys_periph_tee_apm_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
if(err) goto error;
|
2023-02-15 03:35:23 -05:00
|
|
|
err = sleep_sys_periph_uart0_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
if(err) goto error;
|
2023-02-15 03:35:23 -05:00
|
|
|
err = sleep_sys_periph_tg0_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
if(err) goto error;
|
2023-02-15 03:35:23 -05:00
|
|
|
err = sleep_sys_periph_iomux_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
if(err) goto error;
|
2023-02-15 03:35:23 -05:00
|
|
|
err = sleep_sys_periph_spimem_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
if(err) goto error;
|
2023-02-15 03:35:23 -05:00
|
|
|
err = sleep_sys_periph_systimer_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
|
|
|
|
error:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-06-25 05:12:43 -04:00
|
|
|
bool peripheral_domain_pd_allowed(void)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
|
|
|
const uint32_t modules = sleep_retention_get_modules();
|
|
|
|
const uint32_t mask = (const uint32_t) (
|
2023-10-11 08:00:08 -04:00
|
|
|
SLEEP_RETENTION_MODULE_INTR_MATRIX | \
|
|
|
|
SLEEP_RETENTION_MODULE_HP_SYSTEM | \
|
|
|
|
SLEEP_RETENTION_MODULE_TEE_APM | \
|
|
|
|
SLEEP_RETENTION_MODULE_UART0 | \
|
|
|
|
SLEEP_RETENTION_MODULE_TG0 | \
|
|
|
|
SLEEP_RETENTION_MODULE_IOMUX | \
|
|
|
|
SLEEP_RETENTION_MODULE_SPIMEM | \
|
|
|
|
SLEEP_RETENTION_MODULE_SYSTIMER);
|
2023-02-14 01:35:05 -05:00
|
|
|
return ((modules & mask) == mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
|
2023-11-24 12:32:37 -05:00
|
|
|
ESP_SYSTEM_INIT_FN(sleep_sys_periph_startup_init, SECONDARY, BIT(0), 107)
|
2023-02-14 01:35:05 -05:00
|
|
|
{
|
2023-02-15 03:35:23 -05:00
|
|
|
sleep_sys_periph_retention_init();
|
2023-02-14 01:35:05 -05:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
#endif
|