[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

Join cip-dev@lists.cip-project.org to automatically receive all group messages.