Skip to content

Commit df8ba0f

Browse files
vireshkAlex Shi
authored andcommitted
PM / OPP: Parse clock-latency and voltage-tolerance for v1 bindings
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> (cherry picked from commit 50f8cfbd5897ca182d43f4caf19937153f17a604) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 2f5f3fb commit df8ba0f

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

drivers/base/power/opp/core.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ static struct device_opp *_add_device_opp(struct device *dev)
582582
{
583583
struct device_opp *dev_opp;
584584
struct device_list_opp *list_dev;
585+
struct device_node *np;
585586

586587
/* Check for existing list for 'dev' first */
587588
dev_opp = _find_device_opp(dev);
@@ -604,6 +605,21 @@ static struct device_opp *_add_device_opp(struct device *dev)
604605
return NULL;
605606
}
606607

608+
/*
609+
* Only required for backward compatibility with v1 bindings, but isn't
610+
* harmful for other cases. And so we do it unconditionally.
611+
*/
612+
np = of_node_get(dev->of_node);
613+
if (np) {
614+
u32 val;
615+
616+
if (!of_property_read_u32(np, "clock-latency", &val))
617+
dev_opp->clock_latency_ns_max = val;
618+
of_property_read_u32(np, "voltage-tolerance",
619+
&dev_opp->voltage_tolerance_v1);
620+
of_node_put(np);
621+
}
622+
607623
srcu_init_notifier_head(&dev_opp->srcu_head);
608624
INIT_LIST_HEAD(&dev_opp->opp_list);
609625

@@ -861,6 +877,7 @@ static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt,
861877
{
862878
struct device_opp *dev_opp;
863879
struct dev_pm_opp *new_opp;
880+
unsigned long tol;
864881
int ret;
865882

866883
/* Hold our list modification lock here */
@@ -874,7 +891,10 @@ static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt,
874891

875892
/* populate the opp table */
876893
new_opp->rate = freq;
894+
tol = u_volt * dev_opp->voltage_tolerance_v1 / 100;
877895
new_opp->u_volt = u_volt;
896+
new_opp->u_volt_min = u_volt - tol;
897+
new_opp->u_volt_max = u_volt + tol;
878898
new_opp->available = true;
879899
new_opp->dynamic = dynamic;
880900

drivers/base/power/opp/opp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ struct device_list_opp {
138138
* @dentry: debugfs dentry pointer of the real device directory (not links).
139139
* @dentry_name: Name of the real dentry.
140140
*
141+
* @voltage_tolerance_v1: In percentage, for v1 bindings only.
142+
*
141143
* This is an internal data structure maintaining the link to opps attached to
142144
* a device. This structure is not meant to be shared to users as it is
143145
* meant for book keeping and private to OPP library.
@@ -156,6 +158,10 @@ struct device_opp {
156158

157159
struct device_node *np;
158160
unsigned long clock_latency_ns_max;
161+
162+
/* For backward compatibility with v1 bindings */
163+
unsigned int voltage_tolerance_v1;
164+
159165
bool shared_opp;
160166
struct dev_pm_opp *suspend_opp;
161167

0 commit comments

Comments
 (0)