diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 10c12e40f75..12e02ef6b1f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2556,6 +2556,42 @@ err: } EXPORT_SYMBOL_GPL(regulator_bulk_enable); +/** + * regulator_bulk_set_voltage - set voltage for multiple regulator consumers + * + * @num_consumers: Number of consumers + * @consumers: Consumer data; clients are stored here. + * @return 0 on success, an errno on failure + * + * This convenience API allows the voted voltage ranges of multiple regulator + * clients to be set in a single API call. If any consumers cannot have their + * voltages set, this function returns WITHOUT withdrawing votes for any + * consumers that have already been set. + */ +int regulator_bulk_set_voltage(int num_consumers, + struct regulator_bulk_data *consumers) +{ + int i; + int rc; + + for (i = 0; i < num_consumers; i++) { + if (!consumers[i].min_uV && !consumers[i].max_uV) + continue; + rc = regulator_set_voltage(consumers[i].consumer, + consumers[i].min_uV, + consumers[i].max_uV); + if (rc) + goto err; + } + + return 0; + +err: + pr_err("Failed to set voltage for %s: %d\n", consumers[i].supply, rc); + return rc; +} +EXPORT_SYMBOL_GPL(regulator_bulk_set_voltage); + /** * regulator_bulk_disable - disable multiple regulator consumers * diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 8c1ac316c81..23c72674d7f 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -117,6 +117,10 @@ struct regulator; * using the bulk regulator APIs. * @consumer: The regulator consumer for the supply. This will be managed * by the bulk API. + * @min_uV: The minimum requested voltage for the regulator (in microvolts), + * or 0 to not set a voltage. + * @max_uV: The maximum requested voltage for the regulator (in microvolts), + * or 0 to use @min_uV. * * The regulator APIs provide a series of regulator_bulk_() API calls as * a convenience to consumers which require multiple supplies. This @@ -125,6 +129,8 @@ struct regulator; struct regulator_bulk_data { const char *supply; struct regulator *consumer; + int min_uV; + int max_uV; /* private: Internal use */ int ret; @@ -155,6 +161,8 @@ int devm_regulator_bulk_get(struct device *dev, int num_consumers, struct regulator_bulk_data *consumers); int regulator_bulk_enable(int num_consumers, struct regulator_bulk_data *consumers); +int regulator_bulk_set_voltage(int num_consumers, + struct regulator_bulk_data *consumers); int regulator_bulk_disable(int num_consumers, struct regulator_bulk_data *consumers); int regulator_bulk_force_disable(int num_consumers,