Date   

[PATCH 4.4.y-cip 23/23] PM / OPP: Update voltage in case freq == old_freq

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@gmail.com>

commit c5c2a97b3ac7d1ec19e7cff9e38caca6afefc3de upstream.

This commit fixes a rare but possible case when the clk rate is updated
without update of the regulator voltage.

At boot up, CPUfreq checks if the system is running at the right freq. Th=
is
is a sanity check in case a bootloader set clk rate that is outside of fr=
eq
table present with cpufreq core. In such cases system can be unstable so
better to change it to a freq that is preset in freq-table.

The CPUfreq takes next freq that is >=3D policy->cur and this is our
target_freq that needs to be set now.

dev_pm_opp_set_rate(dev, target_freq) checks the target_freq and the
old_freq (a current rate). If these are equal it returns early. If not,
it searches for OPP (old_opp) that fits best to old_freq (not listed in
the table) and updates old_freq (!).

Here, we can end up with old_freq =3D old_opp.rate =3D target_freq, which
is not handled in _generic_set_opp_regulator(). It's supposed to update
voltage only when freq > old_freq || freq > old_freq.

if (freq > old_freq) {
ret =3D _set_opp_voltage(dev, reg, new_supply);
[...]
if (freq < old_freq) {
ret =3D _set_opp_voltage(dev, reg, new_supply);
if (ret)

It results in, no voltage update while clk rate is updated.

Example:
freq-table =3D {
1000MHz 1.15V
666MHZ 1.10V
333MHz 1.05V
}
boot-up-freq =3D 800MHz # not listed in freq-table
freq =3D target_freq =3D 1GHz
old_freq =3D 800Mhz
old_opp =3D _find_freq_ceil(opp_table, &old_freq); #(old_freq is modifie=
d!)
old_freq =3D 1GHz

Fixes: 6a0712f6f199 ("PM / OPP: Add dev_pm_opp_set_rate()")
Cc: 4.6+ <stable@vger.kernel.org> # v4.6+
Signed-off-by: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@gmail.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index c91eacf8d2ed3..e93eba1ade4a0 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -661,7 +661,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned =
long target_freq)
rcu_read_unlock();
=20
/* Scaling up? Scale voltage before frequency */
- if (freq > old_freq) {
+ if (freq >=3D old_freq) {
ret =3D _set_opp_voltage(dev, reg, u_volt, u_volt_min,
u_volt_max);
if (ret)
--=20
2.27.0


[PATCH 4.4.y-cip 22/23] PM / OPP: Remove useless check

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 21f8a99ce61b2d4b74bd425a5bf7e9efbe162788 upstream.

Regulators are optional for devices using OPPs and the OPP core
shouldn't be printing any errors for such missing regulators.

It was fine before the commit 0c717d0f9cb4, but that failed to update
this part of the code to remove an 'always true' check and an extra
unwanted print message.

Fix that now.

Fixes: 0c717d0f9cb4 (PM / OPP: Initialize regulator pointer to an error v=
alue)
Reported-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index 7fc3848df17f5..c91eacf8d2ed3 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -259,9 +259,6 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct =
device *dev)
reg =3D opp_table->regulator;
if (IS_ERR(reg)) {
/* Regulator may not be required for device */
- if (reg)
- dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__,
- PTR_ERR(reg));
rcu_read_unlock();
return 0;
}
--=20
2.27.0


[PATCH 4.4.y-cip 21/23] cpufreq: dt: Drop stale comment

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit b318556479cc923970a79d6c2311138581c0db83 upstream.

The comment in file header doesn't hold true anymore, drop it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index f951f911786e0..5f8dbe640a202 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -4,9 +4,6 @@
* Copyright (C) 2014 Linaro.
* Viresh Kumar <viresh.kumar@linaro.org>
*
- * The OPP code in function set_target() is reused from
- * drivers/cpufreq/omap-cpufreq.c
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
--=20
2.27.0


[PATCH 4.4.y-cip 15/23] cpufreq: dt: No need to fetch voltage-tolerance

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit df2c8ec28e73d47392b8cb24828c15c54819da41 upstream.

Its already done by core and we don't need to get it anymore. And so,
we don't need to get of node in cpufreq_init() anymore, move that to
find_supply_name() instead.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 46 ++++++++++++++++++------------------
1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 150a172c7d0a7..bbafd7b63d1a2 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -33,7 +33,6 @@ struct private_data {
struct device *cpu_dev;
struct regulator *cpu_reg;
struct thermal_cooling_device *cdev;
- unsigned int voltage_tolerance; /* in percentage */
const char *reg_name;
};
=20
@@ -55,24 +54,38 @@ static int set_target(struct cpufreq_policy *policy, =
unsigned int index)
* An earlier version of opp-v1 bindings used to name the regulator
* "cpu0-supply", we still need to handle that for backwards compatibili=
ty.
*/
-static const char *find_supply_name(struct device *dev, struct device_no=
de *np)
+static const char *find_supply_name(struct device *dev)
{
+ struct device_node *np;
struct property *pp;
int cpu =3D dev->id;
+ const char *name =3D NULL;
+
+ np =3D of_node_get(dev->of_node);
+
+ /* This must be valid for sure */
+ if (WARN_ON(!np))
+ return NULL;
=20
/* Try "cpu0" for older DTs */
if (!cpu) {
pp =3D of_find_property(np, "cpu0-supply", NULL);
- if (pp)
- return "cpu0";
+ if (pp) {
+ name =3D "cpu0";
+ goto node_put;
+ }
}
=20
pp =3D of_find_property(np, "cpu-supply", NULL);
- if (pp)
- return "cpu";
+ if (pp) {
+ name =3D "cpu";
+ goto node_put;
+ }
=20
dev_dbg(dev, "no regulator for cpu%d\n", cpu);
- return NULL;
+node_put:
+ of_node_put(np);
+ return name;
}
=20
static int allocate_resources(int cpu, struct device **cdev,
@@ -147,7 +160,6 @@ try_again:
static int cpufreq_init(struct cpufreq_policy *policy)
{
struct cpufreq_frequency_table *freq_table;
- struct device_node *np;
struct private_data *priv;
struct device *cpu_dev;
struct regulator *cpu_reg;
@@ -164,13 +176,6 @@ static int cpufreq_init(struct cpufreq_policy *polic=
y)
return ret;
}
=20
- np =3D of_node_get(cpu_dev->of_node);
- if (!np) {
- dev_err(cpu_dev, "failed to find cpu%d node\n", policy->cpu);
- ret =3D -ENOENT;
- goto out_put_reg_clk;
- }
-
/* Get OPP-sharing information from "operating-points-v2" bindings */
ret =3D dev_pm_opp_of_get_sharing_cpus(cpu_dev, policy->cpus);
if (ret) {
@@ -181,20 +186,20 @@ static int cpufreq_init(struct cpufreq_policy *poli=
cy)
if (ret =3D=3D -ENOENT)
opp_v1 =3D true;
else
- goto out_node_put;
+ goto out_put_reg_clk;
}
=20
/*
* OPP layer will be taking care of regulators now, but it needs to kno=
w
* the name of the regulator first.
*/
- name =3D find_supply_name(cpu_dev, np);
+ name =3D find_supply_name(cpu_dev);
if (name) {
ret =3D dev_pm_opp_set_regulator(cpu_dev, name);
if (ret) {
dev_err(cpu_dev, "Failed to set regulator for cpu%d: %d\n",
policy->cpu, ret);
- goto out_node_put;
+ goto out_put_reg_clk;
}
}
=20
@@ -244,7 +249,6 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
}
=20
priv->reg_name =3D name;
- of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance)=
;
=20
ret =3D dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
if (ret) {
@@ -286,8 +290,6 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
=20
policy->cpuinfo.transition_latency =3D transition_latency;
=20
- of_node_put(np);
-
return 0;
=20
out_free_cpufreq_table:
@@ -298,8 +300,6 @@ out_free_opp:
dev_pm_opp_of_cpumask_remove_table(policy->cpus);
if (name)
dev_pm_opp_put_regulator(cpu_dev);
-out_node_put:
- of_node_put(np);
out_put_reg_clk:
clk_put(cpu_clk);
if (!IS_ERR(cpu_reg))
--=20
2.27.0


[PATCH 4.4.y-cip 19/23] PM / OPP: Fix incorrect comments

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit a5da64477ee79efa748df256928ec8840a2a7986 upstream.

Some comments were just copy/pasted from other sections and don't match
to the routines they were added for. Fix them.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index 72df25fae3864..ba574b814e30f 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -1254,7 +1254,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw);
=20
/**
* dev_pm_opp_put_supported_hw() - Releases resources blocked for suppor=
ted hw
- * @dev: Device for which supported-hw has to be set.
+ * @dev: Device for which supported-hw has to be put.
*
* This is required only for the V2 bindings, and is called for a matchi=
ng
* dev_pm_opp_set_supported_hw(). Until this is called, the device_opp s=
tructure
@@ -1303,7 +1303,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
=20
/**
* dev_pm_opp_set_prop_name() - Set prop-extn name
- * @dev: Device for which the regulator has to be set.
+ * @dev: Device for which the prop-name has to be set.
* @name: name to postfix to properties.
*
* This is required only for the V2 bindings, and it enables a platform =
to
@@ -1362,7 +1362,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name);
=20
/**
* dev_pm_opp_put_prop_name() - Releases resources blocked for prop-name
- * @dev: Device for which the regulator has to be set.
+ * @dev: Device for which the prop-name has to be put.
*
* This is required only for the V2 bindings, and is called for a matchi=
ng
* dev_pm_opp_set_prop_name(). Until this is called, the device_opp stru=
cture
--=20
2.27.0


[PATCH 4.4.y-cip 18/23] PM / OPP: Initialize regulator pointer to an error value

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 0c717d0f9cb46259dce5272705adce64a2d646d9 upstream.

We are currently required to do two checks for regulator pointer:
IS_ERR() and IS_NULL().

And multiple instances are reported, about both of these not being used
consistently and so resulting in crashes.

Fix that by initializing regulator pointer with an error value and
checking it only against an error.

This makes code more consistent and more efficient.

Fixes: 7d34d56ef334 (PM / OPP: Disable OPPs that aren't supported by the =
regulator)
Reported-and-tested-by: Jon Hunter <jonathanh@nvidia.com>
Reported-and-tested-by: Tony Lindgren <tony@atomide.com>
Reported-and-tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[ rjw: Initialize to -ENXIO ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index 067379f931662..72df25fae3864 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -257,7 +257,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct =
device *dev)
}
=20
reg =3D dev_opp->regulator;
- if (IS_ERR_OR_NULL(reg)) {
+ if (IS_ERR(reg)) {
/* Regulator may not be required for device */
if (reg)
dev_err(dev, "%s: Invalid regulator (%ld)\n", __func__,
@@ -798,6 +798,9 @@ static struct device_opp *_add_device_opp(struct devi=
ce *dev)
of_node_put(np);
}
=20
+ /* Set regulator to a non-NULL error value */
+ dev_opp->regulator =3D ERR_PTR(-ENXIO);
+
/* Find clk for the device */
dev_opp->clk =3D clk_get(dev, NULL);
if (IS_ERR(dev_opp->clk)) {
@@ -845,7 +848,7 @@ static void _remove_device_opp(struct device_opp *dev=
_opp)
if (dev_opp->prop_name)
return;
=20
- if (!IS_ERR_OR_NULL(dev_opp->regulator))
+ if (!IS_ERR(dev_opp->regulator))
return;
=20
/* Release clk */
@@ -975,7 +978,7 @@ static bool _opp_supported_by_regulators(struct dev_p=
m_opp *opp,
{
struct regulator *reg =3D dev_opp->regulator;
=20
- if (!IS_ERR_OR_NULL(reg) &&
+ 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",
@@ -1441,7 +1444,7 @@ int dev_pm_opp_set_regulator(struct device *dev, co=
nst char *name)
}
=20
/* Already have a regulator set */
- if (WARN_ON(!IS_ERR_OR_NULL(dev_opp->regulator))) {
+ if (WARN_ON(!IS_ERR(dev_opp->regulator))) {
ret =3D -EBUSY;
goto err;
}
@@ -1492,7 +1495,7 @@ void dev_pm_opp_put_regulator(struct device *dev)
goto unlock;
}
=20
- if (IS_ERR_OR_NULL(dev_opp->regulator)) {
+ if (IS_ERR(dev_opp->regulator)) {
dev_err(dev, "%s: Doesn't have regulator set\n", __func__);
goto unlock;
}
@@ -1501,7 +1504,7 @@ void dev_pm_opp_put_regulator(struct device *dev)
WARN_ON(!list_empty(&dev_opp->opp_list));
=20
regulator_put(dev_opp->regulator);
- dev_opp->regulator =3D ERR_PTR(-EINVAL);
+ dev_opp->regulator =3D ERR_PTR(-ENXIO);
=20
/* Try freeing device_opp if this was the last blocking resource */
_remove_device_opp(dev_opp);
--=20
2.27.0


[PATCH 4.4.y-cip 17/23] PM / OPP: Fix NULL pointer dereference crash when disabling OPPs

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Jon Hunter <jonathanh@nvidia.com>

commit 78ecc56247f0ec2bc0cf6f2f2af69e98d99767bc upstream.

Commit 7d34d56ef334 (PM / OPP: Disable OPPs that aren't supported by
the regulator) causes a crash to happen on Tegra124 Jetson TK1 when
using the DFLL clock source for the CPU. The DFLL manages the voltage
itself and so there is no regulator specified for the OPPs and so we
get a crash when we try to dereference the regulator pointer. Fix
this by checking to see if the regulator IS_ERR_OR_NULL before
dereferencing it.

Fixes: 7d34d56ef334 (PM / OPP: Disable OPPs that aren't supported by the =
regulator)
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reported-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
[ rjw: Changelog ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index 91b4cc261d84a..067379f931662 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -975,7 +975,7 @@ static bool _opp_supported_by_regulators(struct dev_p=
m_opp *opp,
{
struct regulator *reg =3D dev_opp->regulator;
=20
- if (!IS_ERR(reg) &&
+ if (!IS_ERR_OR_NULL(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",
--=20
2.27.0


[PATCH 4.4.y-cip 16/23] cpufreq: dt: No need to allocate resources anymore

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit dd02a3d920083b6cb0ee4f0eaf2c599b740bf5fe upstream.

OPP layer manages it now and cpufreq-dt driver doesn't need it. But, we
still need to check for availability of resources for deferred probing.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 112 ++++++++++++++---------------------
1 file changed, 45 insertions(+), 67 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index bbafd7b63d1a2..f951f911786e0 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -31,7 +31,6 @@
=20
struct private_data {
struct device *cpu_dev;
- struct regulator *cpu_reg;
struct thermal_cooling_device *cdev;
const char *reg_name;
};
@@ -88,73 +87,59 @@ node_put:
return name;
}
=20
-static int allocate_resources(int cpu, struct device **cdev,
- struct regulator **creg, struct clk **cclk)
+static int resources_available(void)
{
struct device *cpu_dev;
struct regulator *cpu_reg;
struct clk *cpu_clk;
int ret =3D 0;
- char *reg_cpu0 =3D "cpu0", *reg_cpu =3D "cpu", *reg;
+ const char *name;
=20
- cpu_dev =3D get_cpu_device(cpu);
+ cpu_dev =3D get_cpu_device(0);
if (!cpu_dev) {
- pr_err("failed to get cpu%d device\n", cpu);
+ pr_err("failed to get cpu0 device\n");
return -ENODEV;
}
=20
- /* Try "cpu0" for older DTs */
- if (!cpu)
- reg =3D reg_cpu0;
- else
- reg =3D reg_cpu;
-
-try_again:
- cpu_reg =3D regulator_get_optional(cpu_dev, reg);
- ret =3D PTR_ERR_OR_ZERO(cpu_reg);
+ cpu_clk =3D clk_get(cpu_dev, NULL);
+ ret =3D PTR_ERR_OR_ZERO(cpu_clk);
if (ret) {
/*
- * If cpu's regulator supply node is present, but regulator is
- * not yet registered, we should try defering probe.
+ * If cpu's clk node is present, but clock is not yet
+ * registered, we should try defering probe.
*/
- if (ret =3D=3D -EPROBE_DEFER) {
- dev_dbg(cpu_dev, "cpu%d regulator not ready, retry\n",
- cpu);
- return ret;
- }
-
- /* Try with "cpu-supply" */
- if (reg =3D=3D reg_cpu0) {
- reg =3D reg_cpu;
- goto try_again;
- }
+ if (ret =3D=3D -EPROBE_DEFER)
+ dev_dbg(cpu_dev, "clock not ready, retry\n");
+ else
+ dev_err(cpu_dev, "failed to get clock: %d\n", ret);
=20
- dev_dbg(cpu_dev, "no regulator for cpu%d: %d\n", cpu, ret);
+ return ret;
}
=20
- cpu_clk =3D clk_get(cpu_dev, NULL);
- ret =3D PTR_ERR_OR_ZERO(cpu_clk);
- if (ret) {
- /* put regulator */
- if (!IS_ERR(cpu_reg))
- regulator_put(cpu_reg);
+ clk_put(cpu_clk);
+
+ name =3D find_supply_name(cpu_dev);
+ /* Platform doesn't require regulator */
+ if (!name)
+ return 0;
=20
+ cpu_reg =3D regulator_get_optional(cpu_dev, name);
+ ret =3D PTR_ERR_OR_ZERO(cpu_reg);
+ if (ret) {
/*
- * If cpu's clk node is present, but clock is not yet
- * registered, we should try defering probe.
+ * If cpu's regulator supply node is present, but regulator is
+ * not yet registered, we should try defering probe.
*/
if (ret =3D=3D -EPROBE_DEFER)
- dev_dbg(cpu_dev, "cpu%d clock not ready, retry\n", cpu);
+ dev_dbg(cpu_dev, "cpu0 regulator not ready, retry\n");
else
- dev_err(cpu_dev, "failed to get cpu%d clock: %d\n", cpu,
- ret);
- } else {
- *cdev =3D cpu_dev;
- *creg =3D cpu_reg;
- *cclk =3D cpu_clk;
+ dev_dbg(cpu_dev, "no regulator for cpu0: %d\n", ret);
+
+ return ret;
}
=20
- return ret;
+ regulator_put(cpu_reg);
+ return 0;
}
=20
static int cpufreq_init(struct cpufreq_policy *policy)
@@ -162,7 +147,6 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
struct cpufreq_frequency_table *freq_table;
struct private_data *priv;
struct device *cpu_dev;
- struct regulator *cpu_reg;
struct clk *cpu_clk;
struct dev_pm_opp *suspend_opp;
unsigned int transition_latency;
@@ -170,9 +154,16 @@ static int cpufreq_init(struct cpufreq_policy *polic=
y)
const char *name;
int ret;
=20
- ret =3D allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk);
- if (ret) {
- pr_err("%s: Failed to allocate resources: %d\n", __func__, ret);
+ cpu_dev =3D get_cpu_device(policy->cpu);
+ if (!cpu_dev) {
+ pr_err("failed to get cpu%d device\n", policy->cpu);
+ return -ENODEV;
+ }
+
+ cpu_clk =3D clk_get(cpu_dev, NULL);
+ if (IS_ERR(cpu_clk)) {
+ ret =3D PTR_ERR(cpu_clk);
+ dev_err(cpu_dev, "%s: failed to get clk: %d\n", __func__, ret);
return ret;
}
=20
@@ -186,7 +177,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
if (ret =3D=3D -ENOENT)
opp_v1 =3D true;
else
- goto out_put_reg_clk;
+ goto out_put_clk;
}
=20
/*
@@ -199,7 +190,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
if (ret) {
dev_err(cpu_dev, "Failed to set regulator for cpu%d: %d\n",
policy->cpu, ret);
- goto out_put_reg_clk;
+ goto out_put_clk;
}
}
=20
@@ -257,9 +248,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
}
=20
priv->cpu_dev =3D cpu_dev;
- priv->cpu_reg =3D cpu_reg;
policy->driver_data =3D priv;
-
policy->clk =3D cpu_clk;
=20
rcu_read_lock();
@@ -300,10 +289,8 @@ out_free_opp:
dev_pm_opp_of_cpumask_remove_table(policy->cpus);
if (name)
dev_pm_opp_put_regulator(cpu_dev);
-out_put_reg_clk:
+out_put_clk:
clk_put(cpu_clk);
- if (!IS_ERR(cpu_reg))
- regulator_put(cpu_reg);
=20
return ret;
}
@@ -319,8 +306,6 @@ static int cpufreq_exit(struct cpufreq_policy *policy=
)
dev_pm_opp_put_regulator(priv->cpu_dev);
=20
clk_put(policy->clk);
- if (!IS_ERR(priv->cpu_reg))
- regulator_put(priv->cpu_reg);
kfree(priv);
=20
return 0;
@@ -373,9 +358,6 @@ static struct cpufreq_driver dt_cpufreq_driver =3D {
=20
static int dt_cpufreq_probe(struct platform_device *pdev)
{
- struct device *cpu_dev;
- struct regulator *cpu_reg;
- struct clk *cpu_clk;
int ret;
=20
/*
@@ -385,19 +367,15 @@ static int dt_cpufreq_probe(struct platform_device =
*pdev)
*
* FIXME: Is checking this only for CPU0 sufficient ?
*/
- ret =3D allocate_resources(0, &cpu_dev, &cpu_reg, &cpu_clk);
+ ret =3D resources_available();
if (ret)
return ret;
=20
- clk_put(cpu_clk);
- if (!IS_ERR(cpu_reg))
- regulator_put(cpu_reg);
-
dt_cpufreq_driver.driver_data =3D dev_get_platdata(&pdev->dev);
=20
ret =3D cpufreq_register_driver(&dt_cpufreq_driver);
if (ret)
- dev_err(cpu_dev, "failed register driver: %d\n", ret);
+ dev_err(&pdev->dev, "failed register driver: %d\n", ret);
=20
return ret;
}
--=20
2.27.0


[PATCH 4.4.y-cip 08/23] cpufreq: dt: Convert few pr_debug/err() calls to dev_dbg/err()

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 896d6a4c0f41a93809b83f9e58aad73874a89d99 upstream.

We have the device structure available now, lets use it for better print
messages.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 0ca74d0700583..ace0168274d4b 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -246,7 +246,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
*/
ret =3D dev_pm_opp_get_opp_count(cpu_dev);
if (ret <=3D 0) {
- pr_debug("OPP table is not ready, deferring probe\n");
+ dev_dbg(cpu_dev, "OPP table is not ready, deferring probe\n");
ret =3D -EPROBE_DEFER;
goto out_free_opp;
}
@@ -325,7 +325,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
=20
ret =3D dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
if (ret) {
- pr_err("failed to init cpufreq table: %d\n", ret);
+ dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
goto out_free_priv;
}
=20
--=20
2.27.0


[PATCH 4.4.y-cip 14/23] cpufreq: dt: Use dev_pm_opp_set_rate() to switch frequency

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 78c3ba5df96c875b1668e1cd3ee0a69e62454f32 upstream.

OPP core supports frequency/voltage changes based on the target
frequency now, use that instead of open coding the same in cpufreq-dt
driver.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 73 +-----------------------------------
1 file changed, 2 insertions(+), 71 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 6f80ce56b4eca..150a172c7d0a7 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -45,79 +45,10 @@ static struct freq_attr *cpufreq_dt_attr[] =3D {
=20
static int set_target(struct cpufreq_policy *policy, unsigned int index)
{
- struct dev_pm_opp *opp;
- struct cpufreq_frequency_table *freq_table =3D policy->freq_table;
- struct clk *cpu_clk =3D policy->clk;
struct private_data *priv =3D policy->driver_data;
- struct device *cpu_dev =3D priv->cpu_dev;
- struct regulator *cpu_reg =3D priv->cpu_reg;
- unsigned long volt =3D 0, tol =3D 0;
- int volt_old =3D 0;
- unsigned int old_freq, new_freq;
- long freq_Hz, freq_exact;
- int ret;
-
- freq_Hz =3D clk_round_rate(cpu_clk, freq_table[index].frequency * 1000)=
;
- if (freq_Hz <=3D 0)
- freq_Hz =3D freq_table[index].frequency * 1000;
-
- freq_exact =3D freq_Hz;
- new_freq =3D freq_Hz / 1000;
- old_freq =3D clk_get_rate(cpu_clk) / 1000;
-
- if (!IS_ERR(cpu_reg)) {
- unsigned long opp_freq;
-
- rcu_read_lock();
- opp =3D dev_pm_opp_find_freq_ceil(cpu_dev, &freq_Hz);
- if (IS_ERR(opp)) {
- rcu_read_unlock();
- dev_err(cpu_dev, "failed to find OPP for %ld\n",
- freq_Hz);
- return PTR_ERR(opp);
- }
- volt =3D dev_pm_opp_get_voltage(opp);
- opp_freq =3D dev_pm_opp_get_freq(opp);
- rcu_read_unlock();
- tol =3D volt * priv->voltage_tolerance / 100;
- volt_old =3D regulator_get_voltage(cpu_reg);
- dev_dbg(cpu_dev, "Found OPP: %ld kHz, %ld uV\n",
- opp_freq / 1000, volt);
- }
-
- dev_dbg(cpu_dev, "%u MHz, %d mV --> %u MHz, %ld mV\n",
- old_freq / 1000, (volt_old > 0) ? volt_old / 1000 : -1,
- new_freq / 1000, volt ? volt / 1000 : -1);
-
- /* scaling up? scale voltage before frequency */
- if (!IS_ERR(cpu_reg) && new_freq > old_freq) {
- ret =3D regulator_set_voltage_tol(cpu_reg, volt, tol);
- if (ret) {
- dev_err(cpu_dev, "failed to scale voltage up: %d\n",
- ret);
- return ret;
- }
- }
-
- ret =3D clk_set_rate(cpu_clk, freq_exact);
- if (ret) {
- dev_err(cpu_dev, "failed to set clock rate: %d\n", ret);
- if (!IS_ERR(cpu_reg) && volt_old > 0)
- regulator_set_voltage_tol(cpu_reg, volt_old, tol);
- return ret;
- }
=20
- /* scaling down? scale voltage after frequency */
- if (!IS_ERR(cpu_reg) && new_freq < old_freq) {
- ret =3D regulator_set_voltage_tol(cpu_reg, volt, tol);
- if (ret) {
- dev_err(cpu_dev, "failed to scale voltage down: %d\n",
- ret);
- clk_set_rate(cpu_clk, old_freq * 1000);
- }
- }
-
- return ret;
+ return dev_pm_opp_set_rate(priv->cpu_dev,
+ policy->freq_table[index].frequency * 1000);
}
=20
/*
--=20
2.27.0


[PATCH 4.4.y-cip 09/23] cpufreq: dt: Rename 'need_update' to 'opp_v1'

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 457e99e60a8f5a40b7da204c0bfc8a86ad2161b9 upstream.

That's the real purpose of this field, i.e. to take special care of old
OPP V1 bindings. Lets name it accordingly, so that it can be used
elsewhere.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index ace0168274d4b..0047d20803db7 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -199,7 +199,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
struct dev_pm_opp *suspend_opp;
unsigned long min_uV =3D ~0, max_uV =3D 0;
unsigned int transition_latency;
- bool need_update =3D false;
+ bool opp_v1 =3D false;
int ret;
=20
ret =3D allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk);
@@ -223,7 +223,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
* finding shared-OPPs for backward compatibility.
*/
if (ret =3D=3D -ENOENT)
- need_update =3D true;
+ opp_v1 =3D true;
else
goto out_node_put;
}
@@ -251,7 +251,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
goto out_free_opp;
}
=20
- if (need_update) {
+ if (opp_v1) {
struct cpufreq_dt_platform_data *pd =3D cpufreq_get_driver_data();
=20
if (!pd || !pd->independent_clocks)
--=20
2.27.0


[PATCH 4.4.y-cip 13/23] cpufreq: dt: Reuse dev_pm_opp_get_max_transition_latency()

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 755b888ff098c9f762717a9fbda7e05b16619069 upstream.

OPP layer has all the information now to calculate transition latency
(clock_latency + voltage_latency). Lets reuse the OPP layer helper
dev_pm_opp_get_max_transition_latency() instead of open coding the same
in cpufreq-dt driver.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 48 +++---------------------------------
1 file changed, 4 insertions(+), 44 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index c3fe89461ff45..6f80ce56b4eca 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -222,7 +222,6 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
struct regulator *cpu_reg;
struct clk *cpu_clk;
struct dev_pm_opp *suspend_opp;
- unsigned long min_uV =3D ~0, max_uV =3D 0;
unsigned int transition_latency;
bool opp_v1 =3D false;
const char *name;
@@ -316,49 +315,6 @@ static int cpufreq_init(struct cpufreq_policy *polic=
y)
priv->reg_name =3D name;
of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance)=
;
=20
- transition_latency =3D dev_pm_opp_get_max_clock_latency(cpu_dev);
- if (!transition_latency)
- transition_latency =3D CPUFREQ_ETERNAL;
-
- if (!IS_ERR(cpu_reg)) {
- unsigned long opp_freq =3D 0;
-
- /*
- * Disable any OPPs where the connected regulator isn't able to
- * provide the specified voltage and record minimum and maximum
- * voltage levels.
- */
- while (1) {
- struct dev_pm_opp *opp;
- unsigned long opp_uV, tol_uV;
-
- rcu_read_lock();
- opp =3D dev_pm_opp_find_freq_ceil(cpu_dev, &opp_freq);
- if (IS_ERR(opp)) {
- rcu_read_unlock();
- break;
- }
- opp_uV =3D dev_pm_opp_get_voltage(opp);
- rcu_read_unlock();
-
- tol_uV =3D opp_uV * priv->voltage_tolerance / 100;
- if (regulator_is_supported_voltage(cpu_reg,
- opp_uV - tol_uV,
- opp_uV + tol_uV)) {
- if (opp_uV < min_uV)
- min_uV =3D opp_uV;
- if (opp_uV > max_uV)
- max_uV =3D opp_uV;
- }
-
- opp_freq++;
- }
-
- ret =3D regulator_set_voltage_time(cpu_reg, min_uV, max_uV);
- if (ret > 0)
- transition_latency +=3D ret * 1000;
- }
-
ret =3D dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
if (ret) {
dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
@@ -393,6 +349,10 @@ static int cpufreq_init(struct cpufreq_policy *polic=
y)
cpufreq_dt_attr[1] =3D &cpufreq_freq_attr_scaling_boost_freqs;
}
=20
+ transition_latency =3D dev_pm_opp_get_max_transition_latency(cpu_dev);
+ if (!transition_latency)
+ transition_latency =3D CPUFREQ_ETERNAL;
+
policy->cpuinfo.transition_latency =3D transition_latency;
=20
of_node_put(np);
--=20
2.27.0


[PATCH 4.4.y-cip 10/23] cpufreq: dt: OPP layers handles clock-latency for V1 bindings as well

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 391d9aef8145204e0a5d67be3bd1fc45c5396dae upstream.

"clock-latency" is handled by OPP layer for all bindings and so there is
no need to make special calls for V1 bindings. Use
dev_pm_opp_get_max_clock_latency() for both the cases.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 0047d20803db7..4c9f8a828f6f1 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -265,10 +265,6 @@ static int cpufreq_init(struct cpufreq_policy *polic=
y)
if (ret)
dev_err(cpu_dev, "%s: failed to mark OPPs as shared: %d\n",
__func__, ret);
-
- of_property_read_u32(np, "clock-latency", &transition_latency);
- } else {
- transition_latency =3D dev_pm_opp_get_max_clock_latency(cpu_dev);
}
=20
priv =3D kzalloc(sizeof(*priv), GFP_KERNEL);
@@ -279,6 +275,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
=20
of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance)=
;
=20
+ transition_latency =3D dev_pm_opp_get_max_clock_latency(cpu_dev);
if (!transition_latency)
transition_latency =3D CPUFREQ_ETERNAL;
=20
--=20
2.27.0


[PATCH 4.4.y-cip 11/23] cpufreq: dt: Pass regulator name to the OPP core

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 050794aaebbb9f2c2c50b340b6998273e7c64189 upstream.

OPP core can handle the regulators by itself, and but it needs to know
the name of the regulator to fetch. Add support for that.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 46 ++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 4c9f8a828f6f1..2af75f8088bbb 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -34,6 +34,7 @@ struct private_data {
struct regulator *cpu_reg;
struct thermal_cooling_device *cdev;
unsigned int voltage_tolerance; /* in percentage */
+ const char *reg_name;
};
=20
static struct freq_attr *cpufreq_dt_attr[] =3D {
@@ -119,6 +120,30 @@ static int set_target(struct cpufreq_policy *policy,=
unsigned int index)
return ret;
}
=20
+/*
+ * An earlier version of opp-v1 bindings used to name the regulator
+ * "cpu0-supply", we still need to handle that for backwards compatibili=
ty.
+ */
+static const char *find_supply_name(struct device *dev, struct device_no=
de *np)
+{
+ struct property *pp;
+ int cpu =3D dev->id;
+
+ /* Try "cpu0" for older DTs */
+ if (!cpu) {
+ pp =3D of_find_property(np, "cpu0-supply", NULL);
+ if (pp)
+ return "cpu0";
+ }
+
+ pp =3D of_find_property(np, "cpu-supply", NULL);
+ if (pp)
+ return "cpu";
+
+ dev_dbg(dev, "no regulator for cpu%d\n", cpu);
+ return NULL;
+}
+
static int allocate_resources(int cpu, struct device **cdev,
struct regulator **creg, struct clk **cclk)
{
@@ -200,6 +225,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
unsigned long min_uV =3D ~0, max_uV =3D 0;
unsigned int transition_latency;
bool opp_v1 =3D false;
+ const char *name;
int ret;
=20
ret =3D allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk);
@@ -228,6 +254,20 @@ static int cpufreq_init(struct cpufreq_policy *polic=
y)
goto out_node_put;
}
=20
+ /*
+ * OPP layer will be taking care of regulators now, but it needs to kno=
w
+ * the name of the regulator first.
+ */
+ name =3D find_supply_name(cpu_dev, np);
+ if (name) {
+ ret =3D dev_pm_opp_set_regulator(cpu_dev, name);
+ if (ret) {
+ dev_err(cpu_dev, "Failed to set regulator for cpu%d: %d\n",
+ policy->cpu, ret);
+ goto out_node_put;
+ }
+ }
+
/*
* Initialize OPP tables for all policy->cpus. They will be shared by
* all CPUs which have marked their CPUs shared with OPP bindings.
@@ -273,6 +313,7 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
goto out_free_opp;
}
=20
+ priv->reg_name =3D name;
of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance)=
;
=20
transition_latency =3D dev_pm_opp_get_max_clock_latency(cpu_dev);
@@ -366,6 +407,8 @@ out_free_priv:
kfree(priv);
out_free_opp:
dev_pm_opp_of_cpumask_remove_table(policy->cpus);
+ if (name)
+ dev_pm_opp_put_regulator(cpu_dev);
out_node_put:
of_node_put(np);
out_put_reg_clk:
@@ -383,6 +426,9 @@ static int cpufreq_exit(struct cpufreq_policy *policy=
)
cpufreq_cooling_unregister(priv->cdev);
dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
dev_pm_opp_of_cpumask_remove_table(policy->related_cpus);
+ if (priv->reg_name)
+ dev_pm_opp_put_regulator(priv->cpu_dev);
+
clk_put(policy->clk);
if (!IS_ERR(priv->cpu_reg))
regulator_put(priv->cpu_reg);
--=20
2.27.0


[PATCH 4.4.y-cip 12/23] cpufreq: dt: Unsupported OPPs are already disabled

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 6def6ea75e6dea45f01a16ae3cfb5b5ce48dd5e9 upstream.

The core already have a valid regulator set for the device opp and the
unsupported OPPs are already disabled by the core. There is no need to
repeat that in the user drivers, get rid of it.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/cpufreq/cpufreq-dt.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 2af75f8088bbb..c3fe89461ff45 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -349,8 +349,6 @@ static int cpufreq_init(struct cpufreq_policy *policy=
)
min_uV =3D opp_uV;
if (opp_uV > max_uV)
max_uV =3D opp_uV;
- } else {
- dev_pm_opp_disable(cpu_dev, opp_freq);
}
=20
opp_freq++;
--=20
2.27.0


[PATCH 4.4.y-cip 06/23] PM / OPP: Manage device clk

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit d54974c2513f487e9e70fbdc79c5da51c53e23da upstream.

OPP core has got almost everything now to manage device's OPP
transitions, the only thing left is device's clk. Get that as well.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 15 +++++++++++++++
drivers/base/power/opp/opp.h | 3 +++
2 files changed, 18 insertions(+)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index e1f214fc75555..4fd3a59060e30 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -13,6 +13,7 @@
=20
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
=20
+#include <linux/clk.h>
#include <linux/errno.h>
#include <linux/err.h>
#include <linux/slab.h>
@@ -583,6 +584,7 @@ static struct device_opp *_add_device_opp(struct devi=
ce *dev)
struct device_opp *dev_opp;
struct device_list_opp *list_dev;
struct device_node *np;
+ int ret;
=20
/* Check for existing list for 'dev' first */
dev_opp =3D _find_device_opp(dev);
@@ -620,6 +622,15 @@ static struct device_opp *_add_device_opp(struct dev=
ice *dev)
of_node_put(np);
}
=20
+ /* Find clk for the device */
+ dev_opp->clk =3D clk_get(dev, NULL);
+ if (IS_ERR(dev_opp->clk)) {
+ ret =3D PTR_ERR(dev_opp->clk);
+ if (ret !=3D -EPROBE_DEFER)
+ dev_dbg(dev, "%s: Couldn't find clock: %d\n", __func__,
+ ret);
+ }
+
srcu_init_notifier_head(&dev_opp->srcu_head);
INIT_LIST_HEAD(&dev_opp->opp_list);
=20
@@ -661,6 +672,10 @@ static void _remove_device_opp(struct device_opp *de=
v_opp)
if (!IS_ERR_OR_NULL(dev_opp->regulator))
return;
=20
+ /* Release clk */
+ if (!IS_ERR(dev_opp->clk))
+ clk_put(dev_opp->clk);
+
list_dev =3D list_first_entry(&dev_opp->dev_list, struct device_list_op=
p,
node);
=20
diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h
index fe44beb404ba2..4f1bdfc7da03b 100644
--- a/drivers/base/power/opp/opp.h
+++ b/drivers/base/power/opp/opp.h
@@ -22,6 +22,7 @@
#include <linux/rculist.h>
#include <linux/rcupdate.h>
=20
+struct clk;
struct regulator;
=20
/* Lock to allow exclusive modification to the device and opp lists */
@@ -134,6 +135,7 @@ struct device_list_opp {
* @supported_hw: Array of version number to support.
* @supported_hw_count: Number of elements in supported_hw array.
* @prop_name: A name to postfix to many DT properties, while parsing th=
em.
+ * @clk: Device's clock handle
* @regulator: Supply regulator
* @dentry: debugfs dentry pointer of the real device directory (not lin=
ks).
* @dentry_name: Name of the real dentry.
@@ -168,6 +170,7 @@ struct device_opp {
unsigned int *supported_hw;
unsigned int supported_hw_count;
const char *prop_name;
+ struct clk *clk;
struct regulator *regulator;
=20
#ifdef CONFIG_DEBUG_FS
--=20
2.27.0


[PATCH 4.4.y-cip 07/23] PM / OPP: Add dev_pm_opp_set_rate()

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 6a0712f6f199e737aa5913d28ec4bd3a25de9660 upstream.

This adds a routine, dev_pm_opp_set_rate(), responsible for configuring
power-supply and clock source for an OPP.

The OPP is found by matching against the target_freq passed to the
routine. This shall replace similar code present in most of the OPP
users and help simplify them a lot.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 176 ++++++++++++++++++++++++++++++++++
include/linux/pm_opp.h | 6 ++
2 files changed, 182 insertions(+)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index 4fd3a59060e30..91b4cc261d84a 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -529,6 +529,182 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struc=
t device *dev,
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);
=20
+/*
+ * The caller needs to ensure that device_opp (and hence the clk) isn't =
freed,
+ * while clk returned here is used.
+ */
+static struct clk *_get_opp_clk(struct device *dev)
+{
+ struct device_opp *dev_opp;
+ struct clk *clk;
+
+ rcu_read_lock();
+
+ dev_opp =3D _find_device_opp(dev);
+ if (IS_ERR(dev_opp)) {
+ dev_err(dev, "%s: device opp doesn't exist\n", __func__);
+ clk =3D ERR_CAST(dev_opp);
+ goto unlock;
+ }
+
+ clk =3D dev_opp->clk;
+ if (IS_ERR(clk))
+ dev_err(dev, "%s: No clock available for the device\n",
+ __func__);
+
+unlock:
+ rcu_read_unlock();
+ return clk;
+}
+
+static int _set_opp_voltage(struct device *dev, struct regulator *reg,
+ unsigned long u_volt, unsigned long u_volt_min,
+ unsigned long u_volt_max)
+{
+ int ret;
+
+ /* Regulator not available for device */
+ if (IS_ERR(reg)) {
+ dev_dbg(dev, "%s: regulator not available: %ld\n", __func__,
+ PTR_ERR(reg));
+ return 0;
+ }
+
+ dev_dbg(dev, "%s: voltages (mV): %lu %lu %lu\n", __func__, u_volt_min,
+ u_volt, u_volt_max);
+
+ ret =3D regulator_set_voltage_triplet(reg, u_volt_min, u_volt,
+ u_volt_max);
+ if (ret)
+ dev_err(dev, "%s: failed to set voltage (%lu %lu %lu mV): %d\n",
+ __func__, u_volt_min, u_volt, u_volt_max, ret);
+
+ return ret;
+}
+
+/**
+ * dev_pm_opp_set_rate() - Configure new OPP based on frequency
+ * @dev: device for which we do this operation
+ * @target_freq: frequency to achieve
+ *
+ * This configures the power-supplies and clock source to the levels spe=
cified
+ * by the OPP corresponding to the target_freq.
+ *
+ * Locking: This function takes rcu_read_lock().
+ */
+int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
+{
+ struct device_opp *dev_opp;
+ struct dev_pm_opp *old_opp, *opp;
+ struct regulator *reg;
+ struct clk *clk;
+ unsigned long freq, old_freq;
+ unsigned long u_volt, u_volt_min, u_volt_max;
+ unsigned long ou_volt, ou_volt_min, ou_volt_max;
+ int ret;
+
+ if (unlikely(!target_freq)) {
+ dev_err(dev, "%s: Invalid target frequency %lu\n", __func__,
+ target_freq);
+ return -EINVAL;
+ }
+
+ clk =3D _get_opp_clk(dev);
+ if (IS_ERR(clk))
+ return PTR_ERR(clk);
+
+ freq =3D clk_round_rate(clk, target_freq);
+ if ((long)freq <=3D 0)
+ freq =3D target_freq;
+
+ old_freq =3D clk_get_rate(clk);
+
+ /* Return early if nothing to do */
+ if (old_freq =3D=3D freq) {
+ dev_dbg(dev, "%s: old/new frequencies (%lu Hz) are same, nothing to do=
\n",
+ __func__, freq);
+ return 0;
+ }
+
+ rcu_read_lock();
+
+ dev_opp =3D _find_device_opp(dev);
+ if (IS_ERR(dev_opp)) {
+ dev_err(dev, "%s: device opp doesn't exist\n", __func__);
+ rcu_read_unlock();
+ return PTR_ERR(dev_opp);
+ }
+
+ old_opp =3D dev_pm_opp_find_freq_ceil(dev, &old_freq);
+ if (!IS_ERR(old_opp)) {
+ ou_volt =3D old_opp->u_volt;
+ ou_volt_min =3D old_opp->u_volt_min;
+ ou_volt_max =3D old_opp->u_volt_max;
+ } else {
+ dev_err(dev, "%s: failed to find current OPP for freq %lu (%ld)\n",
+ __func__, old_freq, PTR_ERR(old_opp));
+ }
+
+ opp =3D dev_pm_opp_find_freq_ceil(dev, &freq);
+ if (IS_ERR(opp)) {
+ ret =3D PTR_ERR(opp);
+ dev_err(dev, "%s: failed to find OPP for freq %lu (%d)\n",
+ __func__, freq, ret);
+ rcu_read_unlock();
+ return ret;
+ }
+
+ u_volt =3D opp->u_volt;
+ u_volt_min =3D opp->u_volt_min;
+ u_volt_max =3D opp->u_volt_max;
+
+ reg =3D dev_opp->regulator;
+
+ rcu_read_unlock();
+
+ /* Scaling up? Scale voltage before frequency */
+ if (freq > old_freq) {
+ ret =3D _set_opp_voltage(dev, reg, u_volt, u_volt_min,
+ u_volt_max);
+ if (ret)
+ goto restore_voltage;
+ }
+
+ /* Change frequency */
+
+ dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n",
+ __func__, old_freq, freq);
+
+ ret =3D clk_set_rate(clk, freq);
+ if (ret) {
+ dev_err(dev, "%s: failed to set clock rate: %d\n", __func__,
+ ret);
+ goto restore_voltage;
+ }
+
+ /* Scaling down? Scale voltage after frequency */
+ if (freq < old_freq) {
+ ret =3D _set_opp_voltage(dev, reg, u_volt, u_volt_min,
+ u_volt_max);
+ if (ret)
+ goto restore_freq;
+ }
+
+ return 0;
+
+restore_freq:
+ if (clk_set_rate(clk, old_freq))
+ dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
+ __func__, old_freq);
+restore_voltage:
+ /* This shouldn't harm even if the voltages weren't updated earlier */
+ if (!IS_ERR(old_opp))
+ _set_opp_voltage(dev, reg, ou_volt, ou_volt_min, ou_volt_max);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_set_rate);
+
/* List-dev Helpers */
static void _kfree_list_dev_rcu(struct rcu_head *head)
{
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 59da3d9e11ea3..cccaf4a29e9f0 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -64,6 +64,7 @@ int dev_pm_opp_set_prop_name(struct device *dev, const =
char *name);
void dev_pm_opp_put_prop_name(struct device *dev);
int dev_pm_opp_set_regulator(struct device *dev, const char *name);
void dev_pm_opp_put_regulator(struct device *dev);
+int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
#else
static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *op=
p)
{
@@ -172,6 +173,11 @@ static inline int dev_pm_opp_set_regulator(struct de=
vice *dev, const char *name)
=20
static inline void dev_pm_opp_put_regulator(struct device *dev) {}
=20
+static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long =
target_freq)
+{
+ return -EINVAL;
+}
+
#endif /* CONFIG_PM_OPP */
=20
#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
--=20
2.27.0


[PATCH 4.4.y-cip 05/23] PM / OPP: Parse clock-latency and voltage-tolerance for v1 bindings

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 50f8cfbd5897ca182d43f4caf19937153f17a604 uptream.

V2 bindings have better support for clock-latency and voltage-tolerance
and doesn't need special care. To use callbacks, like
dev_pm_opp_get_max_{transition|volt}_latency(), irrespective of the
bindings, the core needs to know clock-latency/voltage-tolerance for the
earlier bindings.

This patch reads clock-latency/voltage-tolerance from the device node,
irrespective of the bindings (to keep it simple) and use them only for
V1 bindings.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 20 ++++++++++++++++++++
drivers/base/power/opp/opp.h | 6 ++++++
2 files changed, 26 insertions(+)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index d51ddcebcca00..e1f214fc75555 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -582,6 +582,7 @@ static struct device_opp *_add_device_opp(struct devi=
ce *dev)
{
struct device_opp *dev_opp;
struct device_list_opp *list_dev;
+ struct device_node *np;
=20
/* Check for existing list for 'dev' first */
dev_opp =3D _find_device_opp(dev);
@@ -604,6 +605,21 @@ static struct device_opp *_add_device_opp(struct dev=
ice *dev)
return NULL;
}
=20
+ /*
+ * Only required for backward compatibility with v1 bindings, but isn't
+ * harmful for other cases. And so we do it unconditionally.
+ */
+ np =3D of_node_get(dev->of_node);
+ if (np) {
+ u32 val;
+
+ if (!of_property_read_u32(np, "clock-latency", &val))
+ dev_opp->clock_latency_ns_max =3D val;
+ of_property_read_u32(np, "voltage-tolerance",
+ &dev_opp->voltage_tolerance_v1);
+ of_node_put(np);
+ }
+
srcu_init_notifier_head(&dev_opp->srcu_head);
INIT_LIST_HEAD(&dev_opp->opp_list);
=20
@@ -861,6 +877,7 @@ static int _opp_add_v1(struct device *dev, unsigned l=
ong freq, long u_volt,
{
struct device_opp *dev_opp;
struct dev_pm_opp *new_opp;
+ unsigned long tol;
int ret;
=20
/* Hold our list modification lock here */
@@ -874,7 +891,10 @@ static int _opp_add_v1(struct device *dev, unsigned =
long freq, long u_volt,
=20
/* populate the opp table */
new_opp->rate =3D freq;
+ tol =3D u_volt * dev_opp->voltage_tolerance_v1 / 100;
new_opp->u_volt =3D u_volt;
+ new_opp->u_volt_min =3D u_volt - tol;
+ new_opp->u_volt_max =3D u_volt + tol;
new_opp->available =3D true;
new_opp->dynamic =3D dynamic;
=20
diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h
index 416293b7da237..fe44beb404ba2 100644
--- a/drivers/base/power/opp/opp.h
+++ b/drivers/base/power/opp/opp.h
@@ -138,6 +138,8 @@ struct device_list_opp {
* @dentry: debugfs dentry pointer of the real device directory (not lin=
ks).
* @dentry_name: Name of the real dentry.
*
+ * @voltage_tolerance_v1: In percentage, for v1 bindings only.
+ *
* This is an internal data structure maintaining the link to opps attac=
hed to
* a device. This structure is not meant to be shared to users as it is
* meant for book keeping and private to OPP library.
@@ -156,6 +158,10 @@ struct device_opp {
=20
struct device_node *np;
unsigned long clock_latency_ns_max;
+
+ /* For backward compatibility with v1 bindings */
+ unsigned int voltage_tolerance_v1;
+
bool shared_opp;
struct dev_pm_opp *suspend_opp;
=20
--=20
2.27.0


[PATCH 4.4.y-cip 00/23] PM / OPP v2 & cpufreq backports part 2

Chen-Yu Tsai (Moxa) <wens@...>
 

Hi everyone,

This is part 2 of MOXA's PM / OPP / cpufreq backport series. The whole
series aims to backport patches related to PM / OPPv2 and cpufreq
which were included in the v4.4 kernel from TI's SDK. The end goal is
to include cpufreq-ti and convert am33xx to using it and OPPv2.

Part 2 here includes patches from the v4.6 cycle, as well as additional
fixed found through Fixes tags:

9f8ea969d5cf PM / OPP: get/put regulators from OPP core
7d34d56ef334 PM / OPP: Disable OPPs that aren't supported by the regu=
lator
655c9df96175 PM / OPP: Introduce dev_pm_opp_get_max_volt_latency()
2174344765f4 PM / OPP: Introduce dev_pm_opp_get_max_transition_latenc=
y()
50f8cfbd5897 PM / OPP: Parse clock-latency and voltage-tolerance for =
v1 bindings
d54974c2513f PM / OPP: Manage device clk
6a0712f6f199 PM / OPP: Add dev_pm_opp_set_rate()
896d6a4c0f41 cpufreq: dt: Convert few pr_debug/err() calls to dev_dbg=
/err()
457e99e60a8f cpufreq: dt: Rename 'need_update' to 'opp_v1'
391d9aef8145 cpufreq: dt: OPP layers handles clock-latency for V1 bin=
dings as well
050794aaebbb cpufreq: dt: Pass regulator name to the OPP core
6def6ea75e6d cpufreq: dt: Unsupported OPPs are already disabled
755b888ff098 cpufreq: dt: Reuse dev_pm_opp_get_max_transition_latency=
()
78c3ba5df96c cpufreq: dt: Use dev_pm_opp_set_rate() to switch frequen=
cy
df2c8ec28e73 cpufreq: dt: No need to fetch voltage-tolerance
dd02a3d92008 cpufreq: dt: No need to allocate resources anymore
78ecc56247f0 PM / OPP: Fix NULL pointer dereference crash when disabl=
ing OPPs
0c717d0f9cb4 PM / OPP: Initialize regulator pointer to an error value
a5da64477ee7 PM / OPP: Fix incorrect comments
2c2709dc6921 PM / OPP: Rename structures for clarity
b318556479cc cpufreq: dt: Drop stale comment
21f8a99ce61b PM / OPP: Remove useless check
c5c2a97b3ac7 PM / OPP: Update voltage in case freq =3D=3D old_freq

Of these,

b318556479cc cpufreq: dt: Drop stale comment

was found while looking through git logs.

21f8a99ce61b PM / OPP: Remove useless check
c5c2a97b3ac7 PM / OPP: Update voltage in case freq =3D=3D old_freq

were found by looking for commit hashes in Fixes tags.
All other patches were included from TI's SDK.

The patches apply cleanly on top of linux-4.4.y-cip. The last patch
involved some backporting due to path and code changes between v4.6
and v4.18.

Please have a look.


Regards
ChenYu


Jon Hunter (1):
PM / OPP: Fix NULL pointer dereference crash when disabling OPPs

Viresh Kumar (21):
PM / OPP: get/put regulators from OPP core
PM / OPP: Disable OPPs that aren't supported by the regulator
PM / OPP: Introduce dev_pm_opp_get_max_volt_latency()
PM / OPP: Introduce dev_pm_opp_get_max_transition_latency()
PM / OPP: Parse clock-latency and voltage-tolerance for v1 bindings
PM / OPP: Manage device clk
PM / OPP: Add dev_pm_opp_set_rate()
cpufreq: dt: Convert few pr_debug/err() calls to dev_dbg/err()
cpufreq: dt: Rename 'need_update' to 'opp_v1'
cpufreq: dt: OPP layers handles clock-latency for V1 bindings as well
cpufreq: dt: Pass regulator name to the OPP core
cpufreq: dt: Unsupported OPPs are already disabled
cpufreq: dt: Reuse dev_pm_opp_get_max_transition_latency()
cpufreq: dt: Use dev_pm_opp_set_rate() to switch frequency
cpufreq: dt: No need to fetch voltage-tolerance
cpufreq: dt: No need to allocate resources anymore
PM / OPP: Initialize regulator pointer to an error value
PM / OPP: Fix incorrect comments
PM / OPP: Rename structures for clarity
cpufreq: dt: Drop stale comment
PM / OPP: Remove useless check

Waldemar Rymarkiewicz (1):
PM / OPP: Update voltage in case freq =3D=3D old_freq

drivers/base/power/opp/core.c | 1066 +++++++++++++++++++++---------
drivers/base/power/opp/cpu.c | 22 +-
drivers/base/power/opp/debugfs.c | 85 ++-
drivers/base/power/opp/opp.h | 74 ++-
drivers/cpufreq/cpufreq-dt.c | 303 +++------
include/linux/pm_opp.h | 27 +
6 files changed, 973 insertions(+), 604 deletions(-)

--=20
2.27.0


[PATCH 4.4.y-cip 02/23] PM / OPP: Disable OPPs that aren't supported by the regulator

Chen-Yu Tsai (Moxa) <wens@...>
 

From: Viresh Kumar <viresh.kumar@linaro.org>

commit 7d34d56ef3349cd5f29cf7aab6650f3414fa81b9 upstream.

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>
Signed-off-by: Chen-Yu Tsai (Moxa) <wens@csie.org>
---
drivers/base/power/opp/core.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.=
c
index efdfcee48cac7..48ec88befffc9 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -687,6 +687,22 @@ static struct dev_pm_opp *_allocate_opp(struct devic=
e *dev,
return opp;
}
=20
+static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
+ struct device_opp *dev_opp)
+{
+ struct regulator *reg =3D 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_p=
m_opp *new_opp,
dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n",
__func__, ret);
=20
+ if (!_opp_supported_by_regulators(new_opp, dev_opp)) {
+ new_opp->available =3D false;
+ dev_warn(dev, "%s: OPP not supported by regulators (%lu)\n",
+ __func__, new_opp->rate);
+ }
+
return 0;
}
=20
--=20
2.27.0

1921 - 1940 of 6828