change(mpll): clean up mpll clock acquire with ldo driver

This commit is contained in:
morris 2024-03-17 21:40:57 +08:00
parent 4c2569e2fc
commit cf59c00564
11 changed files with 47 additions and 189 deletions

View File

@ -75,9 +75,6 @@ if(NOT BOOTLOADER_BUILD)
if(CONFIG_SOC_GP_LDO_SUPPORTED)
list(APPEND srcs "ldo/esp_ldo.c" "ldo/esp_ldo_regulator.c")
if(CONFIG_SPIRAM OR CONFIG_SOC_CLK_MPLL_SUPPORTED)
list(APPEND srcs "ldo/esp_ldo_psram.c")
endif()
endif()
if(CONFIG_SOC_ASYNC_MEMCPY_SUPPORTED)

View File

@ -331,10 +331,7 @@ menu "Hardware Settings"
endmenu
menu "LDO Config"
depends on SOC_MULTI_USAGE_LDO_SUPPORTED
orsource "./port/$IDF_TARGET/Kconfig.ldo"
endmenu
orsource "./port/$IDF_TARGET/Kconfig.ldo"
# Invisible bringup bypass options for esp_hw_support component
config ESP_BRINGUP_BYPASS_CPU_CLK_SETTING

View File

@ -7,11 +7,11 @@
#include <freertos/FreeRTOS.h>
#include "clk_ctrl_os.h"
#include "soc/rtc.h"
#include "esp_ldo_regulator.h"
#include "esp_private/esp_clk_tree_common.h"
#include "esp_check.h"
#if SOC_CLK_MPLL_SUPPORTED
#include "rtc_clk.h"
#include "esp_private/esp_ldo_psram.h"
#endif
#if SOC_CLK_APLL_SUPPORTED || SOC_CLK_MPLL_SUPPORTED
@ -30,7 +30,7 @@ static int s_apll_ref_cnt = 0;
#if SOC_CLK_MPLL_SUPPORTED
static uint32_t s_cur_mpll_freq = 0;
static int s_mpll_ref_cnt = 0;
static esp_ldo_unit_handle_t s_ldo_unit_hndl = NULL;
static esp_ldo_channel_handle_t s_ldo_chan = NULL;
#endif
bool periph_rtc_dig_clk8m_enable(void)
@ -125,7 +125,7 @@ esp_err_t periph_rtc_apll_freq_set(uint32_t expt_freq, uint32_t *real_freq)
if (need_config) {
ESP_LOGD(TAG, "APLL will working at %"PRIu32" Hz with coefficients [sdm0] %"PRIu32" [sdm1] %"PRIu32" [sdm2] %"PRIu32" [o_div] %"PRIu32"",
apll_freq, sdm0, sdm1, sdm2, o_div);
apll_freq, sdm0, sdm1, sdm2, o_div);
/* Set coefficients for APLL, notice that it doesn't mean APLL will start */
rtc_clk_apll_coeff_set(o_div, sdm0, sdm1, sdm2);
} else {
@ -137,51 +137,34 @@ esp_err_t periph_rtc_apll_freq_set(uint32_t expt_freq, uint32_t *real_freq)
#endif // SOC_CLK_APLL_SUPPORTED
#if SOC_CLK_MPLL_SUPPORTED
void periph_rtc_mpll_early_acquire(void)
{
portENTER_CRITICAL(&periph_spinlock);
s_mpll_ref_cnt++;
if (s_mpll_ref_cnt == 1) {
#if SOC_PSRAM_VDD_POWER_MPLL
// configure MPPL power (MPLL power pin is the same as for the PSRAM)
s_ldo_unit_hndl = esp_ldo_vdd_psram_early_init();
#endif
// For the first time enable MPLL, need to set power up
rtc_clk_mpll_enable();
}
portEXIT_CRITICAL(&periph_spinlock);
}
esp_err_t periph_rtc_mpll_acquire(void)
{
esp_err_t ret = ESP_OK;
// power up LDO for the MPLL
#if defined(CONFIG_ESP_LDO_CHAN_PSRAM_DOMAIN) && CONFIG_ESP_LDO_CHAN_PSRAM_DOMAIN != -1
esp_ldo_channel_config_t ldo_mpll_config = {
.chan_id = CONFIG_ESP_LDO_CHAN_PSRAM_DOMAIN,
.voltage_mv = CONFIG_ESP_LDO_VOLTAGE_PSRAM_DOMAIN,
};
ESP_RETURN_ON_ERROR(esp_ldo_acquire_channel(&ldo_mpll_config, &s_ldo_chan), TAG, "acquire internal LDO for MPLL failed");
#endif
portENTER_CRITICAL(&periph_spinlock);
s_mpll_ref_cnt++;
if (s_mpll_ref_cnt == 1) {
#if SOC_PSRAM_VDD_POWER_MPLL
// configure MPPL power (MPLL power pin is the same as for the PSRAM)
ret = esp_ldo_vdd_psram_init(&s_ldo_unit_hndl);
// external power supply in use is a valid condition
if (ret == ESP_ERR_INVALID_STATE) {
ret = ESP_OK;
} else if (ret != ESP_OK ) {
portEXIT_CRITICAL(&periph_spinlock);
ESP_LOGE(TAG, "failed to initialize PSRAM internal LDO");
goto err;
}
#endif
// For the first time enable MPLL, need to set power up
rtc_clk_mpll_enable();
}
portEXIT_CRITICAL(&periph_spinlock);
#if SOC_PSRAM_VDD_POWER_MPLL
err:
#endif
return ret;
return ESP_OK;
}
void periph_rtc_mpll_release(void)
{
#if defined(CONFIG_ESP_LDO_CHAN_PSRAM_DOMAIN) && CONFIG_ESP_LDO_CHAN_PSRAM_DOMAIN != -1
if (s_ldo_chan) {
esp_ldo_release_channel(s_ldo_chan);
}
#endif
portENTER_CRITICAL(&periph_spinlock);
assert(s_mpll_ref_cnt > 0);
s_mpll_ref_cnt--;
@ -189,11 +172,6 @@ void periph_rtc_mpll_release(void)
// If there is no peripheral using MPLL, shut down the power
s_cur_mpll_freq = 0;
rtc_clk_mpll_disable();
#if SOC_PSRAM_VDD_POWER_MPLL
if (s_ldo_unit_hndl) {
esp_ldo_vdd_psram_deinit(s_ldo_unit_hndl);
}
#endif
}
portEXIT_CRITICAL(&periph_spinlock);
}

View File

@ -73,11 +73,6 @@ esp_err_t periph_rtc_apll_freq_set(uint32_t expt_freq, uint32_t *real_freq);
#endif // SOC_CLK_APLL_SUPPORTED
#if SOC_CLK_MPLL_SUPPORTED
/**
* @brief Enable MPLL power if it has not enabled (early version)
*/
void periph_rtc_mpll_early_acquire(void);
/**
* @brief Enable MPLL power if it has not enabled
*/

View File

@ -1,49 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "esp_private/esp_ldo.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Init PSRAM VDD LDO during early stage
*
* @return
* - LDO unit handle on success
* - NULL when external power supply is configured to be used
*/
esp_ldo_unit_handle_t esp_ldo_vdd_psram_early_init(void);
/**
* @brief Init PSRAM VDD LDO
*
* @param[out] ldo_unit LDO unit handle
*
* @return
* - ESP_OK Successful.
* - ESP_ERR_INVALID_STATE External power supply is configured to be used
* - ESP_ERR_INVALID_ARG Arguments is NULL or invalid LDO configuration.
* - other error codes from lower-level driver.
*
*/
esp_err_t esp_ldo_vdd_psram_init(esp_ldo_unit_handle_t *ldo_unit);
/**
* @brief De-init PSRAM VDD LDO
*
* @param[in] ldo_unit LDO unit handle
*/
esp_err_t esp_ldo_vdd_psram_deinit(esp_ldo_unit_handle_t ldo_unit);
#ifdef __cplusplus
}
#endif

View File

@ -1,62 +0,0 @@
/*
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdlib.h>
#include <string.h>
#include "sdkconfig.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_check.h"
#include "soc/soc_caps.h"
#include "hal/ldo_ll.h"
#include "esp_private/esp_ldo_psram.h"
static const char *TAG = "ldo_psram";
esp_ldo_unit_handle_t esp_ldo_vdd_psram_early_init(void)
{
if (CONFIG_ESP_VDD_PSRAM_LDO_ID != -1) {
esp_ldo_unit_init_cfg_t unit_cfg = {
.unit_id = CONFIG_ESP_VDD_PSRAM_LDO_ID,
.cfg = {
.voltage_mv = CONFIG_ESP_VDD_PSRAM_LDO_VOLTAGE_MV,
},
.flags.enable_unit = true,
.flags.shared_ldo = true,
};
esp_ldo_unit_handle_t early_unit = esp_ldo_init_unit_early(&unit_cfg);
assert(early_unit);
return early_unit;
}
return NULL;
}
esp_err_t esp_ldo_vdd_psram_init(esp_ldo_unit_handle_t *ldo_unit)
{
esp_err_t ret = ESP_OK;
ESP_RETURN_ON_FALSE(ldo_unit, ESP_ERR_INVALID_ARG, TAG, "null pointer");
if (CONFIG_ESP_VDD_PSRAM_LDO_ID != -1) {
esp_ldo_unit_init_cfg_t unit_cfg = {
.unit_id = LDO_ID2UNIT(CONFIG_ESP_VDD_PSRAM_LDO_ID),
.cfg = {
.voltage_mv = CONFIG_ESP_VDD_PSRAM_LDO_VOLTAGE_MV,
},
.flags.enable_unit = true,
.flags.shared_ldo = true,
};
ESP_RETURN_ON_ERROR(esp_ldo_init_unit(&unit_cfg, ldo_unit), TAG, "internal LDO init failed");
} else {
ESP_LOGD(TAG, "internal LDO not initialized, external power supply is configured to be used");
*ldo_unit = NULL;
return ESP_ERR_INVALID_STATE;
}
return ret;
}
esp_err_t esp_ldo_vdd_psram_deinit(esp_ldo_unit_handle_t ldo_unit)
{
return esp_ldo_deinit_unit(ldo_unit);
}

View File

@ -1,24 +1,28 @@
config ESP_VDD_PSRAM_LDO_ID
int "PSRAM VDD connected LDO ID, set -1 for using external power supply and disable internal LDO"
default 2
range -1 4
help
PSRAM VDD pin connected LDO ID.
PSRAM VDD needs to be connected to an voltage output. This option selects the on-chip
LDO which is connected to the PSRAM VDD.
Set to -1 for connecting to external voltage output.
menu "LDO Regulator Configurations"
depends on SOC_GP_LDO_SUPPORTED
choice ESP_VDD_PSRAM_LDO_VOLTAGE_MV
prompt "PSRAM VDD connected LDO voltage"
depends on ESP_VDD_PSRAM_LDO_ID != -1
default ESP_VDD_PSRAM_LDO_VOLTAGE_MV_1900
help
Select the LDO (ESP_VDD_PSRAM_LDO_ID) voltage output
config ESP_LDO_CHAN_PSRAM_DOMAIN
int "LDO regulator channel that used to power PSRAM and MPLL (READ HELP)"
default 2
range -1 4
help
The internal LDO regulator can be used to power the PSRAM specific power domain.
This option is to select which LDO channel to connect to that domain.
Please set this option correctly according to your schematic.
Set to -1 if the PSRAM is using any external power supply.
config ESP_VDD_PSRAM_LDO_VOLTAGE_MV_1900
bool "1.9V"
endchoice
choice ESP_LDO_VOLTAGE_PSRAM_DOMAIN
prompt "PSRAM power domain voltage"
depends on ESP_LDO_CHAN_PSRAM_DOMAIN != -1
default ESP_LDO_VOLTAGE_PSRAM_1900_MV
help
Select the voltage used by the PSRAM power domain.
config ESP_VDD_PSRAM_LDO_VOLTAGE_MV
int
default 1900 if ESP_VDD_PSRAM_LDO_VOLTAGE_MV_1900
config ESP_LDO_VOLTAGE_PSRAM_1900_MV
bool "1.9V"
endchoice
config ESP_LDO_VOLTAGE_PSRAM_DOMAIN
int
default 1900 if ESP_LDO_VOLTAGE_PSRAM_1900_MV
endmenu

View File

@ -9,7 +9,6 @@
#include "esp_err.h"
#include "esp_log.h"
#include "esp_private/periph_ctrl.h"
#include "esp_private/esp_ldo_psram.h"
#include "esp_private/mspi_timing_tuning.h"
#include "../esp_psram_impl.h"
#include "hal/psram_ctrlr_ll.h"
@ -366,7 +365,7 @@ static void s_configure_psram_ecc(void)
esp_err_t esp_psram_impl_enable(void)
{
#if SOC_CLK_MPLL_SUPPORTED
periph_rtc_mpll_early_acquire();
periph_rtc_mpll_acquire();
periph_rtc_mpll_freq_set(AP_HEX_PSRAM_MPLL_DEFAULT_FREQ_MHZ * 1000000, NULL);
#endif

View File

@ -76,7 +76,6 @@
#endif
#include "esp_private/rtc_clk.h"
#include "esp_private/esp_ldo_psram.h"
#if SOC_INT_CLIC_SUPPORTED
#include "hal/interrupt_clic_ll.h"

View File

@ -32,7 +32,7 @@ Hardware
Some PSRAM chips are 1.8 V devices and some are 3.3 V. Consult the datasheet for your PSRAM chip and {IDF_TARGET_NAME} device to find out the working voltages.
By default, the PSRAM is powered up by the on-chip LDO2. You can use :ref:`CONFIG_ESP_VDD_PSRAM_LDO_ID` to switch the LDO ID accordingly. Set this value to -1 to use an external power supply, which means the on-chip LDO will not be used. By default, the PSRAM connected to LDO is set to the correct voltage based on the Espressif module used. You can still use :ref:`CONFIG_ESP_VDD_PSRAM_LDO_VOLTAGE_MV` to select the LDO output voltage if you are not using an Espressif module. When using an external power supply, this option does not exist.
By default, the PSRAM is powered up by the on-chip LDO2. You can use :ref:`CONFIG_ESP_LDO_CHAN_PSRAM_DOMAIN` to switch the LDO channel accordingly. Set this value to -1 to use an external power supply, which means the on-chip LDO will not be used. By default, the PSRAM connected to LDO is set to the correct voltage based on the Espressif module used. You can still use :ref:`CONFIG_ESP_LDO_VOLTAGE_PSRAM_DOMAIN` to select the LDO output voltage if you are not using an Espressif module. When using an external power supply, this option does not exist.
.. note::

View File

@ -32,7 +32,7 @@
请查询相应 PSRAM 芯片以及 {IDF_TARGET_NAME} 的技术规格书获取准确的工作电压。
PSRAM 默认由片上 LDO2 供电。可设置 :ref:`CONFIG_ESP_VDD_PSRAM_LDO_ID` 来切换相应的 LDO ID,将该值设为 -1 表示使用外部电源,即不使用片上 LDO。默认情况下连接到 LDO 的 PSRAM 会基于所使用的乐鑫模组设置正确电压。如果未使用乐鑫模组,仍可设置 :ref:`CONFIG_ESP_VDD_PSRAM_LDO_VOLTAGE_MV` 来选择 LDO 输出电压。使用外部电源时,该选项不存在。
PSRAM 默认由片上 LDO2 供电。可设置 :ref:`CONFIG_ESP_LDO_CHAN_PSRAM_DOMAIN` 来切换相应的 LDO 输出通道,将该值设为 -1 表示使用外部电源,即不使用片上 LDO。默认情况下连接到 LDO 的 PSRAM 会基于所使用的乐鑫模组设置正确电压。如果未使用乐鑫模组,仍可设置 :ref:`CONFIG_ESP_LDO_VOLTAGE_PSRAM_DOMAIN` 来选择 LDO 输出电压。使用外部电源时,该选项不存在。
.. note::