drivers: regulator: common: allow to specify on by default
Some regulators are enabled by default, however, such condition cannot be captured now by the regulator driver API. Refactor regulator_common_init_enable to regulator_common_init (enable removed, as it also sets mode) and add a new argument to specify such condition. With this change, regulator_disable() and regulator_is_enabled() work as expected without a first call to regulator_enable(). Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
d37613d20a
commit
7feb008c85
6 changed files with 15 additions and 10 deletions
|
@ -13,7 +13,7 @@ void regulator_common_data_init(const struct device *dev)
|
|||
data->refcnt = 0;
|
||||
}
|
||||
|
||||
int regulator_common_init_enable(const struct device *dev)
|
||||
int regulator_common_init(const struct device *dev, bool is_enabled)
|
||||
{
|
||||
const struct regulator_driver_api *api = dev->api;
|
||||
const struct regulator_common_config *config = dev->config;
|
||||
|
@ -27,7 +27,9 @@ int regulator_common_init_enable(const struct device *dev)
|
|||
}
|
||||
}
|
||||
|
||||
if ((config->flags & REGULATOR_INIT_ENABLED) != 0U) {
|
||||
if (is_enabled) {
|
||||
data->refcnt++;
|
||||
} else if ((config->flags & REGULATOR_INIT_ENABLED) != 0U) {
|
||||
ret = api->enable(dev);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
|
|
|
@ -60,7 +60,7 @@ static int regulator_fake_init(const struct device *dev)
|
|||
{
|
||||
regulator_common_data_init(dev);
|
||||
|
||||
return regulator_common_init_enable(dev);
|
||||
return regulator_common_init(dev, false);
|
||||
}
|
||||
|
||||
/* parent regulator */
|
||||
|
|
|
@ -72,7 +72,7 @@ static int regulator_fixed_init(const struct device *dev)
|
|||
return ret;
|
||||
}
|
||||
|
||||
ret = regulator_common_init_enable(dev);
|
||||
ret = regulator_common_init(dev, false);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -603,8 +603,7 @@ static int regulator_npm6001_init(const struct device *dev)
|
|||
if (!device_is_ready(config->p)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
return regulator_common_init_enable(dev);
|
||||
return regulator_common_init(dev, false);
|
||||
}
|
||||
|
||||
static int regulator_npm6001_common_init(const struct device *dev)
|
||||
|
|
|
@ -343,7 +343,7 @@ static int regulator_pca9420_init(const struct device *dev)
|
|||
}
|
||||
}
|
||||
|
||||
return regulator_common_init_enable(dev);
|
||||
return regulator_common_init(dev, false);
|
||||
}
|
||||
|
||||
int regulator_pca9420_dvs_state_set(const struct device *dev,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue