drivers: regulator: add common init enable API
Add a new API for drivers that can be called to initialize the regulator at init time if `regulator-boot-on` or `regulator-always-on` are set. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
9b5152153b
commit
539d4aa6e6
4 changed files with 49 additions and 16 deletions
|
@ -14,6 +14,30 @@ void regulator_common_data_init(const struct device *dev)
|
|||
data->refcnt = 0;
|
||||
}
|
||||
|
||||
int regulator_common_init_enable(const struct device *dev)
|
||||
{
|
||||
const struct regulator_common_config *config =
|
||||
(struct regulator_common_config *)dev->config;
|
||||
struct regulator_common_data *data =
|
||||
(struct regulator_common_data *)dev->data;
|
||||
|
||||
if ((config->flags & REGULATOR_INIT_ENABLED) != 0U) {
|
||||
const struct regulator_driver_api *api =
|
||||
(const struct regulator_driver_api *)dev->api;
|
||||
|
||||
int ret;
|
||||
|
||||
ret = api->enable(dev);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
data->refcnt++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int regulator_enable(const struct device *dev)
|
||||
{
|
||||
const struct regulator_driver_api *api =
|
||||
|
|
|
@ -67,18 +67,18 @@ static int regulator_fixed_init(const struct device *dev)
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
if ((cfg->common.flags & REGULATOR_INIT_ENABLED) != 0U) {
|
||||
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_ACTIVE);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT_INACTIVE);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = regulator_common_init_enable(dev);
|
||||
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;
|
||||
|
|
|
@ -300,7 +300,6 @@ static int regulator_pca9420_init(const struct device *dev)
|
|||
{
|
||||
const struct regulator_pca9420_config *config = dev->config;
|
||||
const struct regulator_pca9420_common_config *cconfig = config->parent->config;
|
||||
int rc = 0;
|
||||
|
||||
regulator_common_data_init(dev);
|
||||
|
||||
|
@ -344,11 +343,7 @@ static int regulator_pca9420_init(const struct device *dev)
|
|||
}
|
||||
}
|
||||
|
||||
if ((config->common.flags & REGULATOR_INIT_ENABLED) != 0U) {
|
||||
rc = regulator_pca9420_enable(dev);
|
||||
}
|
||||
|
||||
return rc;
|
||||
return regulator_common_init_enable(dev);
|
||||
}
|
||||
|
||||
int regulator_pca9420_dvs_state_set(const struct device *dev,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue