2022-11-11 05:29:58 -05:00
|
|
|
/*
|
2024-01-01 22:16:55 -05:00
|
|
|
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
2022-11-11 05:29:58 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "soc/soc_caps.h"
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_attr.h"
|
|
|
|
#include "esp_check.h"
|
|
|
|
#include "esp_regdma.h"
|
|
|
|
#include "esp_private/startup_internal.h"
|
|
|
|
#include "esp_private/sleep_retention.h"
|
|
|
|
#include "esp_private/sleep_clock.h"
|
|
|
|
|
|
|
|
#include "soc/pcr_reg.h"
|
|
|
|
#include "modem/modem_syscon_reg.h"
|
|
|
|
|
2023-12-14 22:29:02 -05:00
|
|
|
#if SOC_PM_RETENTION_SW_TRIGGER_REGDMA
|
2023-06-25 02:17:56 -04:00
|
|
|
#include "modem/modem_lpcon_reg.h"
|
|
|
|
#endif
|
|
|
|
|
2022-11-11 05:29:58 -05:00
|
|
|
static __attribute__((unused)) const char *TAG = "sleep_clock";
|
|
|
|
|
|
|
|
esp_err_t sleep_clock_system_retention_init(void)
|
|
|
|
{
|
2023-04-23 23:43:06 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32C6
|
2022-11-11 05:29:58 -05:00
|
|
|
#define N_REGS_PCR() (((PCR_SRAM_POWER_CONF_REG - DR_REG_PCR_BASE) / 4) + 1)
|
2024-01-01 22:16:55 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C5
|
2023-04-23 23:43:06 -04:00
|
|
|
#define N_REGS_PCR() (((PCR_PWDET_SAR_CLK_CONF_REG - DR_REG_PCR_BASE) / 4) + 1)
|
|
|
|
#endif
|
2022-11-11 05:29:58 -05:00
|
|
|
const static sleep_retention_entries_config_t pcr_regs_retention[] = {
|
|
|
|
[0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_PCR_LINK(0), DR_REG_PCR_BASE, DR_REG_PCR_BASE, N_REGS_PCR(), 0, 0), .owner = ENTRY(0) | ENTRY(2) } /* pcr */
|
|
|
|
};
|
|
|
|
|
2024-01-31 03:52:27 -05:00
|
|
|
esp_err_t err = sleep_retention_entries_create(pcr_regs_retention, ARRAY_SIZE(pcr_regs_retention), REGDMA_LINK_PRI_SYS_CLK, SLEEP_RETENTION_MODULE_CLOCK_SYSTEM);
|
2022-11-11 05:29:58 -05:00
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for system (PCR) retention");
|
|
|
|
ESP_LOGI(TAG, "System Power, Clock and Reset sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sleep_clock_system_retention_deinit(void)
|
|
|
|
{
|
|
|
|
sleep_retention_entries_destroy(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t sleep_clock_modem_retention_init(void)
|
|
|
|
{
|
2024-01-01 22:16:55 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32C5
|
|
|
|
#define N_REGS_SYSCON() (((MODEM_SYSCON_MEM_RF2_CONF_REG - MODEM_SYSCON_TEST_CONF_REG) / 4) + 1)
|
|
|
|
#else
|
2022-11-11 05:29:58 -05:00
|
|
|
#define N_REGS_SYSCON() (((MODEM_SYSCON_MEM_CONF_REG - MODEM_SYSCON_TEST_CONF_REG) / 4) + 1)
|
2024-01-01 22:16:55 -05:00
|
|
|
#endif
|
2023-12-14 22:29:02 -05:00
|
|
|
#if SOC_PM_RETENTION_SW_TRIGGER_REGDMA
|
2023-06-25 02:17:56 -04:00
|
|
|
#define N_REGS_LPCON() (((MODEM_LPCON_MEM_CONF_REG - MODEM_LPCON_TEST_CONF_REG) / 4) + 1)
|
|
|
|
#endif
|
2022-11-11 05:29:58 -05:00
|
|
|
|
|
|
|
const static sleep_retention_entries_config_t modem_regs_retention[] = {
|
2023-03-07 01:45:30 -05:00
|
|
|
[0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEMSYSCON_LINK(0), MODEM_SYSCON_TEST_CONF_REG, MODEM_SYSCON_TEST_CONF_REG, N_REGS_SYSCON(), 0, 0), .owner = ENTRY(0) | ENTRY(1) }, /* MODEM SYSCON */
|
2023-12-14 22:29:02 -05:00
|
|
|
#if SOC_PM_RETENTION_SW_TRIGGER_REGDMA
|
2023-06-25 02:17:56 -04:00
|
|
|
[1] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEMLPCON_LINK(0), MODEM_LPCON_TEST_CONF_REG, MODEM_LPCON_TEST_CONF_REG, N_REGS_LPCON(), 0, 0), .owner = ENTRY(0) | ENTRY(1) } /* MODEM LPCON */
|
|
|
|
#endif
|
2022-11-11 05:29:58 -05:00
|
|
|
};
|
|
|
|
|
2024-01-31 03:52:27 -05:00
|
|
|
esp_err_t err = sleep_retention_entries_create(modem_regs_retention, ARRAY_SIZE(modem_regs_retention), REGDMA_LINK_PRI_MODEM_CLK, SLEEP_RETENTION_MODULE_CLOCK_MODEM);
|
2022-03-13 23:33:01 -04:00
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for modem (SYSCON) retention, 2 level priority");
|
2022-11-11 05:29:58 -05:00
|
|
|
ESP_LOGI(TAG, "Modem Power, Clock and Reset sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sleep_clock_modem_retention_deinit(void)
|
|
|
|
{
|
|
|
|
sleep_retention_entries_destroy(SLEEP_RETENTION_MODULE_CLOCK_MODEM);
|
|
|
|
}
|
|
|
|
|
2023-06-25 05:12:43 -04:00
|
|
|
bool clock_domain_pd_allowed(void)
|
2022-11-11 05:29:58 -05:00
|
|
|
{
|
|
|
|
const uint32_t modules = sleep_retention_get_modules();
|
|
|
|
const uint32_t mask = (const uint32_t) (
|
|
|
|
SLEEP_RETENTION_MODULE_CLOCK_SYSTEM
|
2023-05-25 06:18:03 -04:00
|
|
|
#if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE
|
2022-11-11 05:29:58 -05:00
|
|
|
| SLEEP_RETENTION_MODULE_CLOCK_MODEM
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
return ((modules & mask) == mask);
|
|
|
|
}
|
|
|
|
|
2023-05-25 06:18:03 -04:00
|
|
|
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP || CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE
|
2023-11-24 12:32:37 -05:00
|
|
|
ESP_SYSTEM_INIT_FN(sleep_clock_startup_init, SECONDARY, BIT(0), 106)
|
2022-11-11 05:29:58 -05:00
|
|
|
{
|
2022-03-13 23:33:01 -04:00
|
|
|
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
|
2022-11-11 05:29:58 -05:00
|
|
|
sleep_clock_system_retention_init();
|
2022-03-13 23:33:01 -04:00
|
|
|
#endif
|
|
|
|
|
2023-05-25 06:18:03 -04:00
|
|
|
#if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE
|
2022-11-11 05:29:58 -05:00
|
|
|
sleep_clock_modem_retention_init();
|
|
|
|
#endif
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
#endif
|