|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include "esp_private/sleep_clock.h" |
| 8 | +#include "soc/pcr_reg.h" |
| 9 | +#include "modem/modem_syscon_reg.h" |
| 10 | + |
| 11 | +static const char *TAG = "sleep_clock"; |
| 12 | + |
| 13 | +esp_err_t sleep_clock_system_retention_init(void *arg) |
| 14 | +{ |
| 15 | + const static sleep_retention_entries_config_t pcr_regs_retention[] = { |
| 16 | + [0] = { .config = REGDMA_LINK_ADDR_MAP_INIT(REGDMA_PCR_LINK(0), DR_REG_PCR_BASE, DR_REG_PCR_BASE, 62, 0, 0, 0xfd73ffff, 0xfdffffff, 0xc001, 0x0), .owner = ENTRY(0) | ENTRY(1) }, |
| 17 | + }; |
| 18 | + |
| 19 | + 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); |
| 20 | + ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for system (PCR) retention"); |
| 21 | + ESP_LOGI(TAG, "System Power, Clock and Reset sleep retention initialization"); |
| 22 | + return ESP_OK; |
| 23 | +} |
| 24 | + |
| 25 | +#if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE |
| 26 | +esp_err_t sleep_clock_modem_retention_init(void *arg) |
| 27 | +{ |
| 28 | + #define N_REGS_SYSCON() (((MODEM_SYSCON_MEM_CONF_REG - MODEM_SYSCON_TEST_CONF_REG) / 4) + 1) |
| 29 | + |
| 30 | + const static sleep_retention_entries_config_t modem_regs_retention[] = { |
| 31 | + [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 */ |
| 32 | + }; |
| 33 | + |
| 34 | + 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); |
| 35 | + ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for modem (SYSCON) retention, 1 level priority"); |
| 36 | + ESP_LOGI(TAG, "Modem Power, Clock and Reset sleep retention initialization"); |
| 37 | + return ESP_OK; |
| 38 | +} |
| 39 | +#endif |
| 40 | + |
| 41 | +bool clock_domain_pd_allowed(void) |
| 42 | +{ |
| 43 | + const uint32_t inited_modules = sleep_retention_get_inited_modules(); |
| 44 | + const uint32_t created_modules = sleep_retention_get_created_modules(); |
| 45 | + const uint32_t sys_clk_dep_modules = (const uint32_t) (BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH)); |
| 46 | + |
| 47 | + /* The clock and reset of MODEM (WiFi, BLE and 15.4) modules are managed |
| 48 | + * through MODEM_SYSCON, when one or more MODEMs are initialized, it is |
| 49 | + * necessary to check the state of CLOCK_MODEM to determine MODEM domain on |
| 50 | + * or off. The clock and reset of digital peripherals are managed through |
| 51 | + * PCR, with TOP domain similar to MODEM domain. */ |
| 52 | + uint32_t modem_clk_dep_modules = 0; |
| 53 | +#if SOC_WIFI_SUPPORTED |
| 54 | + modem_clk_dep_modules |= BIT(SLEEP_RETENTION_MODULE_WIFI_MAC) | BIT(SLEEP_RETENTION_MODULE_WIFI_BB); |
| 55 | +#endif |
| 56 | +#if SOC_BT_SUPPORTED |
| 57 | + modem_clk_dep_modules |= BIT(SLEEP_RETENTION_MODULE_BLE_MAC) | BIT(SLEEP_RETENTION_MODULE_BT_BB); |
| 58 | +#endif |
| 59 | +#if SOC_IEEE802154_SUPPORTED |
| 60 | + modem_clk_dep_modules |= BIT(SLEEP_RETENTION_MODULE_802154_MAC) | BIT(SLEEP_RETENTION_MODULE_BT_BB); |
| 61 | +#endif |
| 62 | + |
| 63 | + uint32_t mask = 0; |
| 64 | + if (inited_modules & sys_clk_dep_modules) { |
| 65 | + mask |= BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM); |
| 66 | + } |
| 67 | + if (inited_modules & modem_clk_dep_modules) { |
| 68 | +#if SOC_WIFI_SUPPORTED || SOC_BT_SUPPORTED || SOC_IEEE802154_SUPPORTED |
| 69 | + mask |= BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM); |
| 70 | +#endif |
| 71 | + } |
| 72 | + return ((inited_modules & mask) == (created_modules & mask)); |
| 73 | +} |
| 74 | + |
| 75 | +ESP_SYSTEM_INIT_FN(sleep_clock_startup_init, SECONDARY, BIT(0), 106) |
| 76 | +{ |
| 77 | + sleep_retention_module_init_param_t init_param = { |
| 78 | + .cbs = { .create = { .handle = sleep_clock_system_retention_init, .arg = NULL } }, |
| 79 | + .attribute = SLEEP_RETENTION_MODULE_ATTR_PASSIVE |
| 80 | + }; |
| 81 | + sleep_retention_module_init(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM, &init_param); |
| 82 | + |
| 83 | +#if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE |
| 84 | + init_param = (sleep_retention_module_init_param_t) { |
| 85 | + .cbs = { .create = { .handle = sleep_clock_modem_retention_init, .arg = NULL } }, |
| 86 | + .attribute = SLEEP_RETENTION_MODULE_ATTR_PASSIVE |
| 87 | + }; |
| 88 | + sleep_retention_module_init(SLEEP_RETENTION_MODULE_CLOCK_MODEM, &init_param); |
| 89 | +#endif |
| 90 | + return ESP_OK; |
| 91 | +} |
0 commit comments