From 7fa4776948d5a31f8362223ecc2fbf622d1df4cb Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 27 Apr 2023 09:24:26 +0200 Subject: [PATCH] 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 --- drivers/regulator/regulator_fixed.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/regulator_fixed.c b/drivers/regulator/regulator_fixed.c index 3e12ee44187..2811712c0d2 100644 --- a/drivers/regulator/regulator_fixed.c +++ b/drivers/regulator/regulator_fixed.c @@ -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) \