Skip to content

Commit 009acd1

Browse files
vireshkrafaeljw
authored andcommitted
PM / OPP: Support updating performance state of device's power domain
The genpd framework now provides an API to request device's power domain to update its performance state. Use that interface from the OPP core for devices whose power domains support performance states. Note that this commit doesn't add any mechanism by which performance states are made available to the OPP core. That would be done by a later commit. Note that the current implementation is restricted to the case where the device doesn't have separate regulators for itself. We shouldn't over engineer the code before we have real use case for them. We can always come back and add more code to support such cases later on. Tested-by: Rajendra Nayak <rnayak@codeaurora.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 69f658e commit 009acd1

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

‎drivers/opp/core.c‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/slab.h>
2020
#include <linux/device.h>
2121
#include <linux/export.h>
22+
#include <linux/pm_domain.h>
2223
#include <linux/regulator/consumer.h>
2324

2425
#include "opp.h"
@@ -535,6 +536,44 @@ _generic_set_opp_clk_only(struct device *dev, struct clk *clk,
535536
return ret;
536537
}
537538

539+
static inline int
540+
_generic_set_opp_domain(struct device *dev, struct clk *clk,
541+
unsigned long old_freq, unsigned long freq,
542+
unsigned int old_pstate, unsigned int new_pstate)
543+
{
544+
int ret;
545+
546+
/* Scaling up? Scale domain performance state before frequency */
547+
if (freq > old_freq) {
548+
ret = dev_pm_genpd_set_performance_state(dev, new_pstate);
549+
if (ret)
550+
return ret;
551+
}
552+
553+
ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq);
554+
if (ret)
555+
goto restore_domain_state;
556+
557+
/* Scaling down? Scale domain performance state after frequency */
558+
if (freq < old_freq) {
559+
ret = dev_pm_genpd_set_performance_state(dev, new_pstate);
560+
if (ret)
561+
goto restore_freq;
562+
}
563+
564+
return 0;
565+
566+
restore_freq:
567+
if (_generic_set_opp_clk_only(dev, clk, freq, old_freq))
568+
dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
569+
__func__, old_freq);
570+
restore_domain_state:
571+
if (freq > old_freq)
572+
dev_pm_genpd_set_performance_state(dev, old_pstate);
573+
574+
return ret;
575+
}
576+
538577
static int _generic_set_opp_regulator(const struct opp_table *opp_table,
539578
struct device *dev,
540579
unsigned long old_freq,
@@ -653,7 +692,16 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
653692

654693
/* Only frequency scaling */
655694
if (!opp_table->regulators) {
656-
ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq);
695+
/*
696+
* We don't support devices with both regulator and
697+
* domain performance-state for now.
698+
*/
699+
if (opp_table->genpd_performance_state)
700+
ret = _generic_set_opp_domain(dev, clk, old_freq, freq,
701+
IS_ERR(old_opp) ? 0 : old_opp->pstate,
702+
opp->pstate);
703+
else
704+
ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq);
657705
} else if (!opp_table->set_opp) {
658706
ret = _generic_set_opp_regulator(opp_table, dev, old_freq, freq,
659707
IS_ERR(old_opp) ? NULL : old_opp->supplies,
@@ -1706,6 +1754,13 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev,
17061754
if (remove_all || !opp->dynamic)
17071755
dev_pm_opp_put(opp);
17081756
}
1757+
1758+
/*
1759+
* The OPP table is getting removed, drop the performance state
1760+
* constraints.
1761+
*/
1762+
if (opp_table->genpd_performance_state)
1763+
dev_pm_genpd_set_performance_state(dev, 0);
17091764
} else {
17101765
_remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table);
17111766
}

‎drivers/opp/debugfs.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table)
9999
if (!debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend))
100100
return -ENOMEM;
101101

102+
if (!debugfs_create_u32("performance_state", S_IRUGO, d, &opp->pstate))
103+
return -ENOMEM;
104+
102105
if (!debugfs_create_ulong("rate_hz", S_IRUGO, d, &opp->rate))
103106
return -ENOMEM;
104107

‎drivers/opp/opp.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extern struct list_head opp_tables;
5858
* @dynamic: not-created from static DT entries.
5959
* @turbo: true if turbo (boost) OPP
6060
* @suspend: true if suspend OPP
61+
* @pstate: Device's power domain's performance state.
6162
* @rate: Frequency in hertz
6263
* @supplies: Power supplies voltage/current values
6364
* @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
@@ -76,6 +77,7 @@ struct dev_pm_opp {
7677
bool dynamic;
7778
bool turbo;
7879
bool suspend;
80+
unsigned int pstate;
7981
unsigned long rate;
8082

8183
struct dev_pm_opp_supply *supplies;
@@ -135,6 +137,7 @@ enum opp_table_access {
135137
* @clk: Device's clock handle
136138
* @regulators: Supply regulators
137139
* @regulator_count: Number of power supply regulators
140+
* @genpd_performance_state: Device's power domain support performance state.
138141
* @set_opp: Platform specific set_opp callback
139142
* @set_opp_data: Data to be passed to set_opp callback
140143
* @dentry: debugfs dentry pointer of the real device directory (not links).
@@ -170,6 +173,7 @@ struct opp_table {
170173
struct clk *clk;
171174
struct regulator **regulators;
172175
unsigned int regulator_count;
176+
bool genpd_performance_state;
173177

174178
int (*set_opp)(struct dev_pm_set_opp_data *data);
175179
struct dev_pm_set_opp_data *set_opp_data;

0 commit comments

Comments
 (0)