fix(btbb): add sleep retention attach/detach at btbb enable/disable

This commit is contained in:
cjin
2026-05-21 11:46:16 +08:00
committed by BOT
parent e28ee420ac
commit 03686080ac
3 changed files with 48 additions and 17 deletions
+5
View File
@@ -54,6 +54,9 @@ void jpeg_create_retention_module(jpeg_codec_handle_t jpeg_codec)
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) {
ESP_LOGW(TAG, "attach retention module failed, power domain can't turn off");
}
}
}
_lock_release(&s_jpeg_platform.mutex);
@@ -90,6 +93,7 @@ esp_err_t jpeg_acquire_codec_handle(jpeg_codec_handle_t *jpeg_new_codec)
.arg = (void *)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);
@@ -147,6 +151,7 @@ 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_deinit(jpeg_regs_retention.module_id);
@@ -170,6 +170,7 @@ esp_err_t esp_lcd_new_i80_bus(const esp_lcd_i80_bus_config_t *bus_config, esp_lc
.arg = bus,
},
},
.attribute = SLEEP_RETENTION_MODULE_ATTR_ATTACH,
.depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_SYSTEM)
};
if (sleep_retention_module_init(module_id, &init_param) != ESP_OK) {
@@ -282,6 +283,7 @@ esp_err_t esp_lcd_del_i80_bus(esp_lcd_i80_bus_handle_t bus)
}
#if I80_USE_RETENTION_LINK
const periph_retention_module_t module_id = soc_i80_lcd_retention_info[bus_id].retention_module;
sleep_retention_module_detach(module_id);
if (sleep_retention_is_module_created(module_id)) {
assert(sleep_retention_is_module_inited(module_id));
sleep_retention_module_free(module_id);
@@ -618,6 +620,10 @@ static void lcd_i80_create_retention_module(esp_lcd_i80_bus_t *bus)
if (sleep_retention_module_allocate(module_id) != ESP_OK) {
// even though the sleep retention module create failed, LCD driver should still work, so just warning here
ESP_LOGW(TAG, "create retention module failed, power domain can't turn off");
} else {
if (sleep_retention_module_attach(module_id) != ESP_OK) {
ESP_LOGW(TAG, "attach retention module failed, power domain can't turn off");
}
}
}
}
+37 -17
View File
@@ -47,17 +47,45 @@ static esp_err_t btbb_sleep_retention_init(void *arg)
return ESP_OK;
}
static void btbb_sleep_retention_deinit(void)
static void btbb_sleep_retention_disable(void)
{
esp_err_t err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_BT_BB);
esp_err_t err = sleep_retention_module_detach(SLEEP_RETENTION_MODULE_BT_BB);
if (err != ESP_OK) {
ESP_LOGW(TAG, "failed to destroy sleep retention linked list for btbb retention");
ESP_LOGW(TAG, "failed to detach sleep retention linked list for btbb retention");
}
err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_BT_BB);
if (err != ESP_OK) {
ESP_LOGW(TAG, "failed to free sleep retention linked list for btbb retention");
}
err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_BT_BB);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Modem BT BB retention callback unregister failed");
}
}
static esp_err_t btbb_sleep_retention_enable(void)
{
sleep_retention_module_init_param_t init_param = {
.cbs = { .create = { .handle = btbb_sleep_retention_init, .arg = NULL } },
.attribute = SLEEP_RETENTION_MODULE_ATTR_ATTACH,
.depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM)
};
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BT_BB, &init_param);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Modem BT BB retention callback register failed");
return err;
}
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_BT_BB);
if (err != ESP_OK) {
ESP_LOGW(TAG, "failed to allocate sleep retention linked list for btbb retention");
return err;
}
err = sleep_retention_module_attach(SLEEP_RETENTION_MODULE_BT_BB);
if (err != ESP_OK) {
ESP_LOGW(TAG, "failed to attach sleep retention linked list for btbb retention");
}
return err;
}
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
void esp_btbb_enable(void)
@@ -66,19 +94,11 @@ void esp_btbb_enable(void)
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
sleep_retention_module_init_param_t init_param = {
.cbs = { .create = { .handle = btbb_sleep_retention_init, .arg = NULL } },
.attribute = SLEEP_RETENTION_MODULE_ATTR_ATTACH,
.depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM)
};
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BT_BB, &init_param);
if (err == ESP_OK) {
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_BT_BB);
if (err != ESP_OK) {
ESP_LOGW(TAG, "failed to allocate sleep retention linked list for btbb retention");
}
} else {
ESP_LOGW(TAG, "Modem BT BB retention callback register failed");
esp_err_t err = btbb_sleep_retention_enable();
if (err != ESP_OK) {
btbb_sleep_retention_disable();
_lock_release(&s_btbb_access_lock);
return;
}
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
}
@@ -91,7 +111,7 @@ void esp_btbb_disable(void)
_lock_acquire(&s_btbb_access_lock);
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();
btbb_sleep_retention_disable();
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
}
_lock_release(&s_btbb_access_lock);