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:
Gerard Marull-Paretas 2023-01-12 15:25:21 +01:00 committed by Carles Cufí
commit 240be492fa
2 changed files with 19 additions and 5 deletions

View file

@ -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) {
data->refcnt++;
} else if ((config->flags & REGULATOR_INIT_ENABLED) != 0U) {