PM / OPP: Disable OPPs that aren't supported by the regulator
authorViresh Kumar <viresh.kumar@linaro.org>
Tue, 9 Feb 2016 05:00:34 +0000 (10:30 +0530)
committerAlex Shi <alex.shi@linaro.org>
Fri, 8 Apr 2016 03:24:24 +0000 (11:24 +0800)
Disable any OPPs where the connected regulator isn't able to provide the
specified voltage.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
(cherry picked from commit 7d34d56ef3349cd5f29cf7aab6650f3414fa81b9)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
drivers/base/power/opp/core.c

index 1e22b71abf1ee4afd1d068d089ad5c2d93f10cde..71545becfca1bf7183ff4a3758659a91a8d15a0a 100644 (file)
@@ -687,6 +687,22 @@ static struct dev_pm_opp *_allocate_opp(struct device *dev,
        return opp;
 }
 
+static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
+                                        struct device_opp *dev_opp)
+{
+       struct regulator *reg = dev_opp->regulator;
+
+       if (!IS_ERR(reg) &&
+           !regulator_is_supported_voltage(reg, opp->u_volt_min,
+                                           opp->u_volt_max)) {
+               pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n",
+                       __func__, opp->u_volt_min, opp->u_volt_max);
+               return false;
+       }
+
+       return true;
+}
+
 static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
                    struct device_opp *dev_opp)
 {
@@ -728,6 +744,12 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
                dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n",
                        __func__, ret);
 
+       if (!_opp_supported_by_regulators(new_opp, dev_opp)) {
+               new_opp->available = false;
+               dev_warn(dev, "%s: OPP not supported by regulators (%lu)\n",
+                        __func__, new_opp->rate);
+       }
+
        return 0;
 }