feat(ldo): load calibration parameters from efuse

This commit is contained in:
morris
2024-12-06 16:12:43 +08:00
parent 3abe326490
commit 26545860f7
5 changed files with 121 additions and 70 deletions
@@ -24,6 +24,7 @@ typedef struct ldo_regulator_channel_t {
int ref_cnt;
struct {
uint32_t adjustable : 1;
uint32_t bypass : 1;
} flags;
} ldo_regulator_channel_t;
@@ -83,7 +84,7 @@ esp_err_t esp_ldo_acquire_channel(const esp_ldo_channel_config_t *config, esp_ld
uint8_t mul = 0;
// calculate the dref and mul
ldo_ll_voltage_to_dref_mul(unit_id, config->voltage_mv, &dref, &mul);
ldo_ll_adjust_voltage(unit_id, dref, mul);
ldo_ll_adjust_voltage(unit_id, dref, mul, config->flags.bypass);
// set the ldo unit owner ship
ldo_ll_set_owner(unit_id, config->flags.owned_by_hw ? LDO_LL_UNIT_OWNER_HW : LDO_LL_UNIT_OWNER_SW);
// suppress voltage ripple
@@ -94,6 +95,7 @@ esp_err_t esp_ldo_acquire_channel(const esp_ldo_channel_config_t *config, esp_ld
channel->ref_cnt++;
channel->voltage_mv = config->voltage_mv;
channel->flags.adjustable = config->flags.adjustable;
channel->flags.bypass = config->flags.bypass;
channel->chan_id = config->chan_id;
}
portEXIT_CRITICAL(&s_spinlock);
@@ -155,7 +157,7 @@ esp_err_t esp_ldo_channel_adjust_voltage(esp_ldo_channel_handle_t chan, int volt
uint8_t mul = 0;
// calculate the dref and mul
ldo_ll_voltage_to_dref_mul(unit_id, voltage_mv, &dref, &mul);
ldo_ll_adjust_voltage(unit_id, dref, mul);
ldo_ll_adjust_voltage(unit_id, dref, mul, chan->flags.bypass);
return ESP_OK;
}
@@ -30,7 +30,8 @@ typedef struct {
/// Extra flags of a LDO channel
struct ldo_extra_flags {
uint32_t adjustable : 1; /*!< Whether the LDO channel is adjustable, and the voltage can be updated by `esp_ldo_channel_adjust_voltage` */
uint32_t owned_by_hw: 1; /*!< If the LDO channel is owned by hardware, then software configurations will be overridden by hardware */
uint32_t owned_by_hw: 1; /*!< If the LDO channel is owned by hardware, then software configurations can be overridden by hardware (e.g. eFuse) */
uint32_t bypass: 1; /*!< Whether to bypass the regulator, i.e., the input voltage is sourced directly to the output */
} flags; /*!< Flags for the LDO channel */
} esp_ldo_channel_config_t;
@@ -25,7 +25,7 @@ TEST_CASE("LDO channel acquire and release (no adjustable)", "[LDO]")
TEST_ASSERT_EQUAL(success_ldo_chans[0], success_ldo_chans[1]);
TEST_ASSERT_EQUAL(success_ldo_chans[0], success_ldo_chans[2]);
// can't acquire with a different voltage
ldo_chan_config.voltage_mv = 3300;
ldo_chan_config.voltage_mv = 2500;
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_ldo_acquire_channel(&ldo_chan_config, &fail_ldo_chan));
// the channel has been acquired as "not adjustable" before, so we can't acquire it as "adjustable" again
ldo_chan_config = (esp_ldo_channel_config_t) {
@@ -36,7 +36,7 @@ TEST_CASE("LDO channel acquire and release (no adjustable)", "[LDO]")
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_ldo_acquire_channel(&ldo_chan_config, &fail_ldo_chan));
// can't change the voltage for a non-adjustable channel
TEST_ESP_ERR(ESP_ERR_NOT_SUPPORTED, esp_ldo_channel_adjust_voltage(success_ldo_chans[0], 3300));
TEST_ESP_ERR(ESP_ERR_NOT_SUPPORTED, esp_ldo_channel_adjust_voltage(success_ldo_chans[0], 1900));
for (int i = 0; i < 3; i++) {
TEST_ESP_OK(esp_ldo_release_channel(success_ldo_chans[i]));
@@ -62,7 +62,7 @@ TEST_CASE("LDO channel acquire and release (adjustable)", "[LDO]")
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_ldo_acquire_channel(&ldo_chan_config, &fail_ldo_chan));
// can change voltage for an adjustable channel
TEST_ESP_OK(esp_ldo_channel_adjust_voltage(success_ldo_chan, 3300));
TEST_ESP_OK(esp_ldo_channel_adjust_voltage(success_ldo_chan, 2500));
TEST_ESP_OK(esp_ldo_release_channel(success_ldo_chan));
}
@@ -71,7 +71,7 @@ TEST_CASE("LDO channel state dump", "[LDO][manual][ignore]")
esp_ldo_channel_handle_t success_ldo_chans[3] = {};
esp_ldo_channel_config_t ldo_chan_config = {
.chan_id = 2,
.voltage_mv = 1800,
.voltage_mv = 1900,
};
TEST_ESP_OK(esp_ldo_acquire_channel(&ldo_chan_config, &success_ldo_chans[0]));