@@ -2700,3 +2700,54 @@ int dev_pm_opp_sync_regulators(struct device *dev)
return ret;
}
EXPORT_SYMBOL_GPL(dev_pm_opp_sync_regulators);
+
+/**
+ * dev_pm_opp_set_voltage() - Change voltage of regulators
+ * @dev: device for which we do this operation
+ * @opp: opp based on which the voltages are to be configured
+ *
+ * Change voltage of the OPP table regulators.
+ *
+ * Return: 0 on success or a negative error value.
+ */
+int dev_pm_opp_set_voltage(struct device *dev, struct dev_pm_opp *opp)
+{
+ struct opp_table *opp_table;
+ struct regulator *reg;
+ int ret = 0;
+
+ /* Device may not have OPP table */
+ opp_table = _find_opp_table(dev);
+ if (IS_ERR(opp_table))
+ return 0;
+
+ /* Regulator may not be required for the device */
+ if (!opp_table->regulators)
+ goto put_table;
+
+ /* This function only supports single regulator per device */
+ if (WARN_ON(opp_table->regulator_count > 1)) {
+ dev_err(dev, "multiple regulators are not supported\n");
+ ret = -EINVAL;
+ goto put_table;
+ }
+
+ reg = opp_table->regulators[0];
+ ret = _set_opp_voltage(dev, reg, opp->supplies);
+
+ if (!opp_table->enabled) {
+ ret = regulator_enable(reg);
+ if (ret < 0) {
+ dev_warn(dev, "Failed to enable regulator: %d", ret);
+ goto put_table;
+ }
+
+ opp_table->enabled = true;
+ }
+put_table:
+ /* Drop reference taken by _find_opp_table() */
+ dev_pm_opp_put_opp_table(opp_table);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_set_voltage);
@@ -164,6 +164,7 @@ int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
void dev_pm_opp_remove_table(struct device *dev);
void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
int dev_pm_opp_sync_regulators(struct device *dev);
+int dev_pm_opp_set_voltage(struct device *dev, struct dev_pm_opp *opp);
#else
static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
{
@@ -405,6 +406,11 @@ static inline int dev_pm_opp_sync_regulators(struct device *dev)
return -ENOTSUPP;
}
+static inline int dev_pm_opp_set_voltage(struct device *dev, struct dev_pm_opp *opp)
+{
+ return -ENOTSUPP;
+}
+
#endif /* CONFIG_PM_OPP */
#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)