drivers: regulator: common: set regulator voltage before enabling
Regulator voltage needs to be within allowed range before enabling. It could happen that regulator default voltage is out of the allowed range, so the regulator could be enabled at boot time producing a not-allowed voltage. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
4eb74c8ed2
commit
240be492fa
2 changed files with 19 additions and 5 deletions
|
@ -27,6 +27,15 @@ int regulator_common_init(const struct device *dev, bool is_enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* regulator voltage needs to be within allowed range before enabling */
|
||||||
|
if ((config->min_uv > INT32_MIN) || (config->max_uv < INT32_MAX)) {
|
||||||
|
ret = regulator_set_voltage(dev, config->min_uv,
|
||||||
|
config->max_uv);
|
||||||
|
if ((ret < 0) && (ret != -ENOSYS)) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (is_enabled) {
|
if (is_enabled) {
|
||||||
data->refcnt++;
|
data->refcnt++;
|
||||||
} else if ((config->flags & REGULATOR_INIT_ENABLED) != 0U) {
|
} else if ((config->flags & REGULATOR_INIT_ENABLED) != 0U) {
|
||||||
|
|
|
@ -196,11 +196,16 @@ void regulator_common_data_init(const struct device *dev);
|
||||||
/**
|
/**
|
||||||
* @brief Common function to initialize the regulator at init time.
|
* @brief Common function to initialize the regulator at init time.
|
||||||
*
|
*
|
||||||
* This function can be called after drivers initialize the regulator. It
|
* This function needs to be called after drivers initialize the regulator. It
|
||||||
* will automatically enable the regulator if it is set to `regulator-boot-on`
|
* will:
|
||||||
* or `regulator-always-on` and increase its usage count. It will also configure
|
*
|
||||||
* the regulator mode if `regulator-initial-mode` is set. Regulators that are
|
* - Automatically enable the regulator if it is set to `regulator-boot-on`
|
||||||
* enabled by default in hardware, must set @p is_enabled to `true`.
|
* or `regulator-always-on` and increase its usage count.
|
||||||
|
* - Configure the regulator mode if `regulator-initial-mode` is set.
|
||||||
|
* - Ensure regulator voltage is set to a valid range.
|
||||||
|
*
|
||||||
|
* Regulators that are enabled by default in hardware, must set @p is_enabled to
|
||||||
|
* `true`.
|
||||||
*
|
*
|
||||||
* @param dev Regulator device instance
|
* @param dev Regulator device instance
|
||||||
* @param is_enabled Indicate if the regulator is enabled by default in
|
* @param is_enabled Indicate if the regulator is enabled by default in
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue