From 30a67ed72c42ad34125391f47ca062640c39e1b0 Mon Sep 17 00:00:00 2001 From: cjin Date: Tue, 13 Jun 2023 19:18:57 +0800 Subject: [PATCH] btbb: support register retention in esp32c6 --- .../include/esp_private/esp_regdma.h | 2 +- .../esp32c6/include/btbb_retention_reg.h | 24 +++++++++++ components/esp_phy/src/btbb_init.c | 43 ++++++++++++++++++- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 components/esp_phy/esp32c6/include/btbb_retention_reg.h diff --git a/components/esp_hw_support/include/esp_private/esp_regdma.h b/components/esp_hw_support/include/esp_private/esp_regdma.h index 66b63ae365..b1f0115556 100644 --- a/components/esp_hw_support/include/esp_private/esp_regdma.h +++ b/components/esp_hw_support/include/esp_private/esp_regdma.h @@ -40,7 +40,7 @@ extern "C" { #define REGDMA_SPIMEM_LINK(_pri) ((0x13 << 8) | _pri) #define REGDMA_SYSTIMER_LINK(_pri) ((0x14 << 8) | _pri) #define REGDMA_BLE_MAC_LINK(_pri) ((0x15 << 8) | _pri) -#define REGDMA_BB_LINK(_pri) ((0x16 << 8) | _pri) +#define REGDMA_MODEM_BT_BB_LINK(_pri) ((0x16 << 8) | _pri) #define REGDMA_MODEM_FE_LINK(_pri) ((0xFF << 8) | _pri) typedef enum { diff --git a/components/esp_phy/esp32c6/include/btbb_retention_reg.h b/components/esp_phy/esp32c6/include/btbb_retention_reg.h new file mode 100644 index 0000000000..54a3b3d193 --- /dev/null +++ b/components/esp_phy/esp32c6/include/btbb_retention_reg.h @@ -0,0 +1,24 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +// btbb sleep retention reg + +#define BB_PART_0_SIZE 93 +#define BB_PART_1_SIZE 62 +#define BB_PART_2_SIZE 19 +#define BB_PART_0_ADDR 0x600A2000 +#define BB_PART_1_ADDR 0x600A2800 +#define BB_PART_2_ADDR 0x600A2C00 + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_phy/src/btbb_init.c b/components/esp_phy/src/btbb_init.c index 726afd0e9d..efe7b19013 100644 --- a/components/esp_phy/src/btbb_init.c +++ b/components/esp_phy/src/btbb_init.c @@ -5,6 +5,8 @@ */ #include +#include "esp_check.h" +#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "esp_private/btbb.h" @@ -14,11 +16,46 @@ static _lock_t s_btbb_access_lock; /* Reference count of enabling BT BB */ static uint8_t s_btbb_access_ref = 0; + +#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE +#include "esp_private/sleep_retention.h" +#include "btbb_retention_reg.h" +static const char* TAG = "btbb_init"; + +#if SOC_PM_RETENTION_HAS_CLOCK_BUG +#define BTBB_LINK_OWNER ENTRY(3) +#else +#define BTBB_LINK_OWNER ENTRY(0) | ENTRY(2) +#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG + +static esp_err_t btbb_sleep_retention_init(void) +{ + const static sleep_retention_entries_config_t btbb_regs_retention[] = { + [0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_BT_BB_LINK(0x00), BB_PART_0_ADDR, BB_PART_0_ADDR, BB_PART_0_SIZE, 0, 0), .owner = BTBB_LINK_OWNER }, + [1] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_BT_BB_LINK(0x01), BB_PART_1_ADDR, BB_PART_1_ADDR, BB_PART_1_SIZE, 0, 0), .owner = BTBB_LINK_OWNER }, + [2] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_BT_BB_LINK(0x02), BB_PART_2_ADDR, BB_PART_2_ADDR, BB_PART_2_SIZE, 0, 0), .owner = BTBB_LINK_OWNER } + }; + esp_err_t err = sleep_retention_entries_create(btbb_regs_retention, ARRAY_SIZE(btbb_regs_retention), REGDMA_LINK_PRI_5, SLEEP_RETENTION_MODULE_BLE_BB); + ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for btbb retention"); + ESP_LOGI(TAG, "btbb sleep retention initialization"); + return ESP_OK; +} + +static void btbb_sleep_retention_deinit(void) +{ + sleep_retention_entries_destroy(SLEEP_RETENTION_MODULE_BLE_BB); +} +#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE + + void esp_btbb_enable(void) { _lock_acquire(&s_btbb_access_lock); if (s_btbb_access_ref == 0) { bt_bb_v2_init_cmplx(BTBB_ENABLE_VERSION_PRINT); +#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE + btbb_sleep_retention_init(); +#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE } s_btbb_access_ref++; _lock_release(&s_btbb_access_lock); @@ -27,8 +64,10 @@ void esp_btbb_enable(void) void esp_btbb_disable(void) { _lock_acquire(&s_btbb_access_lock); - if (s_btbb_access_ref > 0) { - s_btbb_access_ref--; + if (s_btbb_access_ref && (--s_btbb_access_ref == 0)) { +#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE + btbb_sleep_retention_deinit(); +#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE } _lock_release(&s_btbb_access_lock); }