Skip to content

Commit 2759356

Browse files
author
Chai Ji’e
committed
Merge branch 'feature/c5_ldo_dbias_read_from_efuse' into 'master'
feat(c5): active_sleep dbg and dbias get from efuse to fix the voltage Closes IDF-8667 and IDF-13007 See merge request espressif/esp-idf!38882
2 parents ac78393 + 6a7191b commit 2759356

File tree

7 files changed

+465
-92
lines changed

7 files changed

+465
-92
lines changed

components/esp_hw_support/port/esp32c5/ocode_init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ static void IRAM_ATTR calibrate_ocode(void)
8181

8282
void esp_ocode_calib_init(void)
8383
{
84+
uint32_t chip_version = efuse_hal_chip_revision();
8485
uint32_t blk_ver = efuse_hal_blk_version();
85-
if ((blk_ver >= 1) && (blk_ver < 100)) {
86+
if ((chip_version == 1 && blk_ver >= 1) || (chip_version >= 100 && blk_ver >= 2)) {
8687
set_ocode_by_efuse(1);
8788
ESP_HW_LOGD(TAG, "efuse ocode");
8889
} else {

components/esp_hw_support/port/esp32c5/pmu_param.c

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -13,6 +13,11 @@
1313
#include "soc/pmu_icg_mapping.h"
1414
#include "esp_private/esp_pmu.h"
1515
#include "soc/clk_tree_defs.h"
16+
#include "hal/efuse_ll.h"
17+
#include "hal/efuse_hal.h"
18+
#include "esp_hw_log.h"
19+
20+
static __attribute__((unused)) const char *TAG = "pmu_param";
1621

1722
#ifndef ARRAY_SIZE
1823
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
@@ -419,48 +424,47 @@ uint32_t get_act_hp_dbias(void)
419424
{
420425
/* hp_cali_dbias is read from efuse to ensure that the hp_active_voltage is close to 1.15V
421426
*/
427+
uint32_t chip_version = efuse_hal_chip_revision();
422428
uint32_t hp_cali_dbias = HP_CALI_DBIAS_DEFAULT;
423-
// uint32_t blk_version = efuse_hal_blk_version();
424-
// if (blk_version >= 3) {
425-
// hp_cali_dbias = efuse_ll_get_active_hp_dbias();
426-
// if (hp_cali_dbias != 0) {
427-
// //efuse dbias need to add 2 to meet the CPU frequency switching
428-
// if (hp_cali_dbias + 2 > 31) {
429-
// hp_cali_dbias = 31;
430-
// } else {
431-
// hp_cali_dbias += 2;
432-
// }
433-
// } else {
434-
// hp_cali_dbias = HP_CALI_DBIAS_DEFAULT;
435-
// ESP_HW_LOGD(TAG, "hp_cali_dbias not burnt in efuse or wrong value was burnt in blk version: %" PRIu32 "\n", blk_version);
436-
// }
437-
// }
438-
429+
uint32_t blk_version = efuse_hal_blk_version();
430+
uint32_t hp_cali_dbias_efuse = 0;
431+
if ((chip_version == 1 && blk_version >= 1) || (chip_version >= 100 && blk_version >= 2)) {
432+
hp_cali_dbias_efuse = efuse_ll_get_active_hp_dbias();
433+
}
434+
435+
if (hp_cali_dbias_efuse > 0) {
436+
//efuse dbias need to add 3 to meet the CPU frequency switching
437+
hp_cali_dbias = hp_cali_dbias_efuse + 16 + 3;
438+
if (hp_cali_dbias > 31) {
439+
hp_cali_dbias = 31;
440+
}
441+
} else {
442+
ESP_HW_LOGW(TAG, "hp_cali_dbias not burnt in efuse, use default.");
443+
}
439444
return hp_cali_dbias;
440445
}
441446

442447
uint32_t get_act_lp_dbias(void)
443448
{
444449
/* lp_cali_dbias is read from efuse to ensure that the lp_active_voltage is close to 1.15V
445450
*/
451+
uint32_t chip_version = efuse_hal_chip_revision();
452+
uint32_t blk_version = efuse_hal_blk_version();
446453
uint32_t lp_cali_dbias = LP_CALI_DBIAS_DEFAULT;
447-
// uint32_t blk_version = efuse_hal_blk_version();
448-
// if (blk_version >= 3) {
449-
// lp_cali_dbias = efuse_ll_get_active_lp_dbias();
450-
// if (lp_cali_dbias != 0) {
451-
// //efuse dbias need to add 2 to meet the CPU frequency switching
452-
// if (lp_cali_dbias + 2 > 31) {
453-
// lp_cali_dbias = 31;
454-
// } else {
455-
// lp_cali_dbias += 2;
456-
// }
457-
// } else {
458-
// lp_cali_dbias = LP_CALI_DBIAS_DEFAULT;
459-
// ESP_HW_LOGD(TAG, "lp_cali_dbias not burnt in efuse or wrong value was burnt in blk version: %" PRIu32 "\n", blk_version);
460-
// }
461-
// } else {
462-
// ESP_HW_LOGD(TAG, "blk_version is less than 3, act dbias not burnt in efuse\n");
463-
// }
454+
uint32_t lp_cali_dbias_efuse = 0;
455+
if ((chip_version == 1 && blk_version >= 1) || (chip_version >= 100 && blk_version >= 2)) {
456+
lp_cali_dbias_efuse = efuse_ll_get_active_lp_dbias();
457+
}
458+
459+
if (lp_cali_dbias_efuse > 0) {
460+
//efuse dbias need to add 3 to meet the CPU frequency switching
461+
lp_cali_dbias = lp_cali_dbias_efuse + 16 + 3;
462+
if (lp_cali_dbias > 31) {
463+
lp_cali_dbias = 31;
464+
}
465+
} else {
466+
ESP_HW_LOGW(TAG, "hp_cali_dbias not burnt in efuse, use default.");
467+
}
464468

465469
return lp_cali_dbias;
466470
}

components/esp_hw_support/port/esp32c5/pmu_sleep.c

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,73 @@
1919
#include "hal/efuse_hal.h"
2020
#include "esp_private/esp_pmu.h"
2121
#include "pmu_param.h"
22+
#include "hal/efuse_ll.h"
23+
#include "hal/efuse_hal.h"
24+
#include "esp_hw_log.h"
25+
26+
static __attribute__((unused)) const char *TAG = "pmu_sleep";
2227

2328
#define HP(state) (PMU_MODE_HP_ ## state)
2429
#define LP(state) (PMU_MODE_LP_ ## state)
2530

26-
2731
static bool s_pmu_sleep_regdma_backup_enabled;
2832

33+
static uint32_t get_lslp_dbg(void)
34+
{
35+
uint32_t pmu_dbg_atten_lightsleep = PMU_DBG_ATTEN_LIGHTSLEEP_DEFAULT;
36+
uint32_t chip_version = efuse_hal_chip_revision();
37+
uint32_t blk_version = efuse_hal_blk_version();
38+
if ((chip_version == 1 && blk_version >= 1) || (chip_version >= 100 && blk_version >= 2)) {
39+
pmu_dbg_atten_lightsleep = efuse_ll_get_lslp_dbg();
40+
} else {
41+
ESP_HW_LOGD(TAG, "lslp dbg not burnt in efuse\n");
42+
}
43+
44+
return pmu_dbg_atten_lightsleep;
45+
}
46+
47+
static uint32_t get_lslp_hp_dbias(void)
48+
{
49+
uint32_t pmu_hp_dbias_lightsleep_0v6 = PMU_HP_DBIAS_LIGHTSLEEP_0V6_DEFAULT;
50+
uint32_t chip_version = efuse_hal_chip_revision();
51+
uint32_t blk_version = efuse_hal_blk_version();
52+
if ((chip_version == 1 && blk_version >= 1) || (chip_version >= 100 && blk_version >= 2)) {
53+
pmu_hp_dbias_lightsleep_0v6 = efuse_ll_get_lslp_hp_dbias();
54+
} else {
55+
ESP_HW_LOGD(TAG, "lslp hp dbias not burnt in efuse\n");
56+
}
57+
58+
return pmu_hp_dbias_lightsleep_0v6;
59+
}
60+
61+
static uint32_t get_dslp_dbg(void)
62+
{
63+
uint32_t pmu_dbg_atten_deepsleep = PMU_DBG_ATTEN_DEEPSLEEP_DEFAULT;
64+
uint32_t chip_version = efuse_hal_chip_revision();
65+
uint32_t blk_version = efuse_hal_blk_version();
66+
if ((chip_version == 1 && blk_version >= 1) || (chip_version >= 100 && blk_version >= 2)) {
67+
pmu_dbg_atten_deepsleep = efuse_ll_get_dslp_dbg();
68+
} else {
69+
ESP_HW_LOGD(TAG, "dslp dbg not burnt in efuse\n");
70+
}
71+
72+
return pmu_dbg_atten_deepsleep;
73+
}
74+
75+
static uint32_t get_dslp_lp_dbias(void)
76+
{
77+
uint32_t pmu_lp_dbias_deepsleep_0v7 = PMU_LP_DBIAS_DEEPSLEEP_0V7_DEFAULT;
78+
uint32_t chip_version = efuse_hal_chip_revision();
79+
uint32_t blk_version = efuse_hal_blk_version();
80+
if ((chip_version == 1 && blk_version >= 1) || (chip_version >= 100 && blk_version >= 2)) {
81+
pmu_lp_dbias_deepsleep_0v7 = efuse_ll_get_dslp_lp_dbias();
82+
} else {
83+
ESP_HW_LOGD(TAG, "dslp lp dbias not burnt in efuse\n");
84+
}
85+
86+
return pmu_lp_dbias_deepsleep_0v7;
87+
}
88+
2989
void pmu_sleep_enable_regdma_backup(void)
3090
{
3191
if(!s_pmu_sleep_regdma_backup_enabled){
@@ -192,22 +252,28 @@ const pmu_sleep_config_t* pmu_sleep_config_default(
192252
config->digital = digital_default;
193253

194254
pmu_sleep_analog_config_t analog_default = PMU_SLEEP_ANALOG_DSLP_CONFIG_DEFAULT(sleep_flags);
255+
analog_default.lp_sys[LP(SLEEP)].analog.dbg_atten = get_dslp_dbg();
256+
analog_default.lp_sys[LP(SLEEP)].analog.dbias = get_dslp_lp_dbias();
257+
195258
config->analog = analog_default;
196259
} else {
197260
pmu_sleep_digital_config_t digital_default = PMU_SLEEP_DIGITAL_LSLP_CONFIG_DEFAULT(sleep_flags, clk_flags);
198261
config->digital = digital_default;
199262

200263
pmu_sleep_analog_config_t analog_default = PMU_SLEEP_ANALOG_LSLP_CONFIG_DEFAULT(sleep_flags);
264+
analog_default.hp_sys.analog.dbg_atten = get_lslp_dbg();
265+
analog_default.hp_sys.analog.dbias = get_lslp_hp_dbias();
266+
analog_default.lp_sys[LP(SLEEP)].analog.dbias = PMU_LP_DBIAS_LIGHTSLEEP_0V7_DEFAULT;
201267

202268
if (!(sleep_flags & PMU_SLEEP_PD_XTAL) || !(sleep_flags & PMU_SLEEP_PD_RC_FAST)){
203269
analog_default.hp_sys.analog.pd_cur = PMU_PD_CUR_SLEEP_ON;
204270
analog_default.hp_sys.analog.bias_sleep = PMU_BIASSLP_SLEEP_ON;
205-
analog_default.hp_sys.analog.dbias = HP_CALI_DBIAS_SLP_1V1;
271+
analog_default.hp_sys.analog.dbias = get_act_hp_dbias();
206272
analog_default.hp_sys.analog.dbg_atten = 0;
207273

208274
analog_default.lp_sys[LP(SLEEP)].analog.pd_cur = PMU_PD_CUR_SLEEP_ON;
209275
analog_default.lp_sys[LP(SLEEP)].analog.bias_sleep = PMU_BIASSLP_SLEEP_ON;
210-
analog_default.lp_sys[LP(SLEEP)].analog.dbias = LP_CALI_DBIAS_SLP_1V1;
276+
analog_default.lp_sys[LP(SLEEP)].analog.dbias = get_act_lp_dbias();
211277
analog_default.lp_sys[LP(SLEEP)].analog.dbg_atten = 0;
212278
}
213279

components/esp_hw_support/port/esp32c5/private_include/pmu_param.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ extern "C" {
4040
#define PMU_HP_XPD_LIGHTSLEEP 1
4141

4242
#define PMU_DBG_ATTEN_LIGHTSLEEP_DEFAULT 1
43-
#define PMU_HP_DBIAS_LIGHTSLEEP_0V6 0
44-
#define PMU_LP_DBIAS_LIGHTSLEEP_0V7 15
43+
#define PMU_HP_DBIAS_LIGHTSLEEP_0V6_DEFAULT 0
44+
#define PMU_LP_DBIAS_LIGHTSLEEP_0V7_DEFAULT 15
4545

4646
// FOR DEEPSLEEP
4747
#define PMU_DBG_HP_DEEPSLEEP 0
4848
#define PMU_HP_XPD_DEEPSLEEP 0
4949
#define PMU_LP_DRVB_DEEPSLEEP 0
5050

5151
#define PMU_DBG_ATTEN_DEEPSLEEP_DEFAULT 9
52-
#define PMU_LP_DBIAS_DEEPSLEEP_0V7 15
52+
#define PMU_LP_DBIAS_DEEPSLEEP_0V7_DEFAULT 15
5353

5454
uint32_t get_act_hp_dbias(void);
5555
uint32_t get_act_lp_dbias(void);
@@ -358,7 +358,7 @@ typedef struct {
358358
.bias_sleep = PMU_BIASSLP_SLEEP_DEFAULT, \
359359
.xpd = PMU_HP_XPD_LIGHTSLEEP, \
360360
.dbg_atten = PMU_DBG_ATTEN_LIGHTSLEEP_DEFAULT, \
361-
.dbias = PMU_HP_DBIAS_LIGHTSLEEP_0V6 \
361+
.dbias = PMU_HP_DBIAS_LIGHTSLEEP_0V6_DEFAULT \
362362
} \
363363
}, \
364364
.lp_sys[PMU_MODE_LP_SLEEP] = { \
@@ -370,7 +370,7 @@ typedef struct {
370370
.slp_dbias = PMU_LP_SLP_DBIAS_SLEEP_DEFAULT, \
371371
.xpd = PMU_LP_XPD_SLEEP_DEFAULT, \
372372
.dbg_atten = PMU_DBG_ATTEN_LIGHTSLEEP_DEFAULT, \
373-
.dbias = PMU_LP_DBIAS_LIGHTSLEEP_0V7 \
373+
.dbias = PMU_LP_DBIAS_LIGHTSLEEP_0V7_DEFAULT \
374374
} \
375375
} \
376376
}
@@ -393,7 +393,7 @@ typedef struct {
393393
.slp_dbias = PMU_LP_SLP_DBIAS_SLEEP_DEFAULT, \
394394
.xpd = PMU_LP_XPD_SLEEP_DEFAULT, \
395395
.dbg_atten = PMU_DBG_ATTEN_DEEPSLEEP_DEFAULT, \
396-
.dbias = PMU_LP_DBIAS_DEEPSLEEP_0V7 \
396+
.dbias = PMU_LP_DBIAS_DEEPSLEEP_0V7_DEFAULT \
397397
} \
398398
} \
399399
}

components/hal/esp32c5/include/hal/efuse_ll.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,42 @@ __attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(ecd
111111

112112
__attribute__((always_inline)) static inline uint32_t efuse_ll_get_ocode(void)
113113
{
114-
// TODO: IDF-13007
115-
return 0;
114+
return EFUSE.rd_sys_part1_data4.ocode;
115+
}
116+
117+
__attribute__((always_inline)) static inline uint32_t efuse_ll_get_active_hp_dbias(void)
118+
{
119+
return EFUSE.rd_mac_sys3.active_hp_dbias;
120+
}
121+
122+
__attribute__((always_inline)) static inline uint32_t efuse_ll_get_active_lp_dbias(void)
123+
{
124+
return EFUSE.rd_mac_sys3.active_lp_dbias;
125+
}
126+
127+
__attribute__((always_inline)) static inline uint32_t efuse_ll_get_lslp_dbg(void)
128+
{
129+
return EFUSE.rd_mac_sys3.lslp_hp_dbg;
130+
}
131+
132+
__attribute__((always_inline)) static inline uint32_t efuse_ll_get_lslp_hp_dbias(void)
133+
{
134+
return EFUSE.rd_mac_sys3.lslp_hp_dbias;
135+
}
136+
137+
__attribute__((always_inline)) static inline uint32_t efuse_ll_get_dslp_dbg(void)
138+
{
139+
return EFUSE.rd_mac_sys3.dslp_lp_dbg;
140+
}
141+
142+
__attribute__((always_inline)) static inline uint32_t efuse_ll_get_dslp_lp_dbias(void)
143+
{
144+
return (EFUSE.rd_mac_sys4.dslp_lp_dbias_1 << 4)|EFUSE.rd_mac_sys3.dslp_lp_dbias;
145+
}
146+
147+
__attribute__((always_inline)) static inline int32_t efuse_ll_get_dbias_vol_gap(void)
148+
{
149+
return EFUSE.rd_mac_sys4.lp_hp_dbias_vol_gap;
116150
}
117151

118152
/******************* eFuse control functions *************************/

0 commit comments

Comments
 (0)