diff --git a/drivers/regulator/regulator_common.c b/drivers/regulator/regulator_common.c index f9f9a41911c..d00e2f647fe 100644 --- a/drivers/regulator/regulator_common.c +++ b/drivers/regulator/regulator_common.c @@ -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) { diff --git a/include/zephyr/drivers/regulator.h b/include/zephyr/drivers/regulator.h index 7172cb5f229..8cda3a7e68b 100644 --- a/include/zephyr/drivers/regulator.h +++ b/include/zephyr/drivers/regulator.h @@ -196,11 +196,16 @@ void regulator_common_data_init(const struct device *dev); /** * @brief Common function to initialize the regulator at init time. * - * This function can be called after drivers initialize the regulator. It - * will automatically enable the regulator if it is set to `regulator-boot-on` - * 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 - * enabled by default in hardware, must set @p is_enabled to `true`. + * 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` + * 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 is_enabled Indicate if the regulator is enabled by default in