mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
feat(clk): add 100m/200m/400m cpu freq & change clk cal & change blk version
This commit is contained in:
committed by
armando
parent
5f3d7506ab
commit
ea4451d6b3
@@ -343,7 +343,7 @@ uint32_t get_act_hp_dbias(void)
|
||||
uint32_t hp_cali_dbias = HP_CALI_ACTIVE_DBIAS_DEFAULT;
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
uint32_t hp_cali_dbias_efuse = 0;
|
||||
if (blk_version >= 2) {
|
||||
if (blk_version >= 2 && blk_version < 100) {
|
||||
hp_cali_dbias_efuse = efuse_ll_get_active_hp_dbias();
|
||||
}
|
||||
if (hp_cali_dbias_efuse > 0) {
|
||||
@@ -364,7 +364,7 @@ uint32_t get_act_lp_dbias(void)
|
||||
uint32_t lp_cali_dbias = LP_CALI_ACTIVE_DBIAS_DEFAULT;
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
uint32_t lp_cali_dbias_efuse = 0;
|
||||
if (blk_version >= 2) {
|
||||
if (blk_version >= 2 && blk_version < 100) {
|
||||
lp_cali_dbias_efuse = efuse_ll_get_active_lp_dbias();
|
||||
}
|
||||
if (lp_cali_dbias_efuse > 0) {
|
||||
|
||||
@@ -34,7 +34,7 @@ static uint8_t get_lp_hp_gap(void)
|
||||
int8_t lp_hp_gap = 0;
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
uint8_t lp_hp_gap_efuse = 0;
|
||||
if (blk_version >= 2) {
|
||||
if (blk_version >= 2 && blk_version < 100) {
|
||||
lp_hp_gap_efuse = efuse_ll_get_dbias_vol_gap();
|
||||
bool gap_flag = lp_hp_gap_efuse >> 4;
|
||||
uint8_t gap_abs_value = lp_hp_gap_efuse & 0xf;
|
||||
@@ -78,7 +78,7 @@ static uint32_t pvt_get_lp_dbias(void)
|
||||
void pvt_auto_dbias_init(void)
|
||||
{
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
if (blk_version >= 2 && blk_version < 100) {
|
||||
SET_PERI_REG_MASK(HP_SYS_CLKRST_REF_CLK_CTRL2_REG, HP_SYS_CLKRST_REG_REF_160M_CLK_EN);
|
||||
SET_PERI_REG_MASK(HP_SYS_CLKRST_SOC_CLK_CTRL1_REG, HP_SYS_CLKRST_REG_PVT_SYS_CLK_EN);
|
||||
/*config for dbias func*/
|
||||
@@ -121,7 +121,7 @@ void pvt_auto_dbias_init(void)
|
||||
void pvt_func_enable(bool enable)
|
||||
{
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2){
|
||||
if (blk_version >= 2 && blk_version < 100){
|
||||
|
||||
if (enable) {
|
||||
SET_PERI_REG_MASK(HP_SYS_CLKRST_REF_CLK_CTRL2_REG, HP_SYS_CLKRST_REG_REF_160M_CLK_EN);
|
||||
|
||||
@@ -220,6 +220,7 @@ static void rtc_clk_cpu_freq_to_cpll_mhz(int cpu_freq_mhz, hal_utils_clk_div_t *
|
||||
uint32_t mem_divider = 1;
|
||||
uint32_t sys_divider = 1; // We are not going to change this
|
||||
uint32_t apb_divider = 1;
|
||||
#if CONFIG_ESP32P4_SELECTS_REV_LESS_V2
|
||||
switch (cpu_freq_mhz) {
|
||||
case 360:
|
||||
mem_divider = 2;
|
||||
@@ -240,6 +241,28 @@ static void rtc_clk_cpu_freq_to_cpll_mhz(int cpu_freq_mhz, hal_utils_clk_div_t *
|
||||
// To avoid such case, we will strictly do abort here.
|
||||
abort();
|
||||
}
|
||||
#else
|
||||
switch (cpu_freq_mhz) {
|
||||
case 400:
|
||||
mem_divider = 2;
|
||||
apb_divider = 2;
|
||||
break;
|
||||
case 200:
|
||||
mem_divider = 1;
|
||||
apb_divider = 2;
|
||||
break;
|
||||
case 100:
|
||||
mem_divider = 1;
|
||||
apb_divider = 1;
|
||||
break;
|
||||
default:
|
||||
// Unsupported configuration
|
||||
// This is dangerous to modify dividers. Hardware could automatically correct the divider, and it won't be
|
||||
// reflected to the registers. Therefore, you won't even be able to calculate out the real mem_clk, apb_clk freq.
|
||||
// To avoid such case, we will strictly do abort here.
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
// If it's upscaling, the divider of MEM/SYS/APB needs to be increased, to avoid illegal intermediate states,
|
||||
// the clock divider should be updated in the order from the APB_CLK to CPU_CLK.
|
||||
@@ -285,6 +308,7 @@ bool rtc_clk_cpu_freq_mhz_to_config(uint32_t freq_mhz, rtc_cpu_freq_config_t *ou
|
||||
|
||||
// Keep default CPLL at 360MHz
|
||||
uint32_t xtal_freq = (uint32_t)rtc_clk_xtal_freq_get();
|
||||
#if CONFIG_ESP32P4_SELECTS_REV_LESS_V2
|
||||
if (freq_mhz <= xtal_freq && freq_mhz != 0) {
|
||||
divider.integer = xtal_freq / freq_mhz;
|
||||
real_freq_mhz = (xtal_freq + divider.integer / 2) / divider.integer; /* round */
|
||||
@@ -292,7 +316,6 @@ bool rtc_clk_cpu_freq_mhz_to_config(uint32_t freq_mhz, rtc_cpu_freq_config_t *ou
|
||||
// no suitable divider
|
||||
return false;
|
||||
}
|
||||
|
||||
source_freq_mhz = xtal_freq;
|
||||
source = SOC_CPU_CLK_SRC_XTAL;
|
||||
} else if (freq_mhz == 90) {
|
||||
@@ -310,6 +333,30 @@ bool rtc_clk_cpu_freq_mhz_to_config(uint32_t freq_mhz, rtc_cpu_freq_config_t *ou
|
||||
source = SOC_CPU_CLK_SRC_CPLL;
|
||||
source_freq_mhz = CLK_LL_PLL_360M_FREQ_MHZ;
|
||||
divider.integer = 1;
|
||||
} else {
|
||||
// unsupported frequency
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if (freq_mhz <= xtal_freq && freq_mhz != 0) {
|
||||
divider.integer = xtal_freq / freq_mhz;
|
||||
real_freq_mhz = (xtal_freq + divider.integer / 2) / divider.integer; /* round */
|
||||
if (real_freq_mhz != freq_mhz) {
|
||||
// no suitable divider
|
||||
return false;
|
||||
}
|
||||
source_freq_mhz = xtal_freq;
|
||||
source = SOC_CPU_CLK_SRC_XTAL;
|
||||
} else if (freq_mhz == 100) {
|
||||
real_freq_mhz = freq_mhz;
|
||||
source = SOC_CPU_CLK_SRC_CPLL;
|
||||
source_freq_mhz = CLK_LL_PLL_400M_FREQ_MHZ;
|
||||
divider.integer = 4;
|
||||
} else if (freq_mhz == 200) {
|
||||
real_freq_mhz = freq_mhz;
|
||||
source = SOC_CPU_CLK_SRC_CPLL;
|
||||
source_freq_mhz = CLK_LL_PLL_400M_FREQ_MHZ;
|
||||
divider.integer = 2;
|
||||
} else if (freq_mhz == 400) {
|
||||
// If CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ selects 400MHz, then at app startup stage will need a CPLL calibration to raise its freq from 360MHz to 400MHz
|
||||
real_freq_mhz = freq_mhz;
|
||||
@@ -320,6 +367,7 @@ bool rtc_clk_cpu_freq_mhz_to_config(uint32_t freq_mhz, rtc_cpu_freq_config_t *ou
|
||||
// unsupported frequency
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
*out_config = (rtc_cpu_freq_config_t) {
|
||||
.source = source,
|
||||
.div = divider,
|
||||
|
||||
Reference in New Issue
Block a user