drivers: regulator: fixed: refactor initialization code.

In some cases, the enable pin may be already enabled by a previous
stage, e.g. bootloader. Therefore, it is not desirable to disable
the pin, as it could cause malfunctioning of the device. Refactor init
procedure so that we pick the right GPIO flags during the first
configuration stage.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2023-04-27 09:24:26 +02:00 committed by Carles Cufí
commit 7fa4776948

View file

@ -58,6 +58,7 @@ static const struct regulator_driver_api regulator_fixed_api = {
static int regulator_fixed_init(const struct device *dev)
{
const struct regulator_fixed_config *cfg = dev->config;
bool init_enabled;
int ret;
regulator_common_data_init(dev);
@ -67,21 +68,23 @@ static int regulator_fixed_init(const struct device *dev)
return -ENODEV;
}
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_INACTIVE);
if (ret < 0) {
return ret;
}
init_enabled = regulator_common_is_init_enabled(dev);
ret = regulator_common_init(dev, false);
if (ret < 0) {
return ret;
}
if (init_enabled) {
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
return ret;
}
if (regulator_is_enabled(dev)) {
k_busy_wait(cfg->startup_delay_us);
} else {
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_INACTIVE);
if (ret < 0) {
return ret;
}
}
return 0;
return regulator_common_init(dev, init_enabled);
}
#define REGULATOR_FIXED_DEFINE(inst) \