Skip to content

Commit 28da439

Browse files
committed
Merge branches 'pm-cpufreq-sched' and 'pm-opp'
* pm-cpufreq-sched: cpufreq: schedutil: Reset cached_raw_freq when not in sync with next_freq * pm-opp: PM / OPP: Add dev_pm_opp_{un}register_get_pstate_helper() PM / OPP: Support updating performance state of device's power domain PM / OPP: add missing of_node_put() for of_get_cpu_node() PM / OPP: Rename dev_pm_opp_register_put_opp_helper() PM / OPP: Add missing of_node_put(np) PM / OPP: Move error message to debug level PM / OPP: Use snprintf() to avoid kasprintf() and kfree() PM / OPP: Move the OPP directory out of power/
3 parents 60af981 + 07458f6 + b6aa983 commit 28da439

14 files changed

Lines changed: 188 additions & 30 deletions

File tree

‎MAINTAINERS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10049,7 +10049,7 @@ M: Stephen Boyd <sboyd@codeaurora.org>
1004910049
L: linux-pm@vger.kernel.org
1005010050
S: Maintained
1005110051
T: git git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git
10052-
F: drivers/base/power/opp/
10052+
F: drivers/opp/
1005310053
F: include/linux/pm_opp.h
1005410054
F: Documentation/power/opp.txt
1005510055
F: Documentation/devicetree/bindings/opp/

‎drivers/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,6 @@ source "drivers/tee/Kconfig"
209209

210210
source "drivers/mux/Kconfig"
211211

212+
source "drivers/opp/Kconfig"
213+
212214
endmenu

‎drivers/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ obj-$(CONFIG_ACCESSIBILITY) += accessibility/
126126
obj-$(CONFIG_ISDN) += isdn/
127127
obj-$(CONFIG_EDAC) += edac/
128128
obj-$(CONFIG_EISA) += eisa/
129+
obj-$(CONFIG_PM_OPP) += opp/
129130
obj-$(CONFIG_CPU_FREQ) += cpufreq/
130131
obj-$(CONFIG_CPU_IDLE) += cpuidle/
131132
obj-y += mmc/

‎drivers/base/power/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o
33
obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o
44
obj-$(CONFIG_PM_TRACE_RTC) += trace.o
5-
obj-$(CONFIG_PM_OPP) += opp/
65
obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o
76
obj-$(CONFIG_HAVE_CLK) += clock_ops.o
87

‎drivers/opp/Kconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
config PM_OPP
2+
bool
3+
select SRCU
4+
---help---
5+
SOCs have a standard set of tuples consisting of frequency and
6+
voltage pairs that the device will support per voltage domain. This
7+
is called Operating Performance Point or OPP. The actual definitions
8+
of OPP varies over silicon within the same family of devices.
9+
10+
OPP layer organizes the data internally using device pointers
11+
representing individual voltage domains and provides SOC
12+
implementations a ready to use framework to manage OPPs.
13+
For more information, read <file:Documentation/power/opp.txt>
Lines changed: 138 additions & 5 deletions
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"
@@ -296,7 +297,7 @@ int dev_pm_opp_get_opp_count(struct device *dev)
296297
opp_table = _find_opp_table(dev);
297298
if (IS_ERR(opp_table)) {
298299
count = PTR_ERR(opp_table);
299-
dev_err(dev, "%s: OPP table not found (%d)\n",
300+
dev_dbg(dev, "%s: OPP table not found (%d)\n",
300301
__func__, count);
301302
return count;
302303
}
@@ -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,
@@ -988,6 +1036,9 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
9881036
return ret;
9891037
}
9901038

1039+
if (opp_table->get_pstate)
1040+
new_opp->pstate = opp_table->get_pstate(dev, new_opp->rate);
1041+
9911042
list_add(&new_opp->node, head);
9921043
mutex_unlock(&opp_table->lock);
9931044

@@ -1476,13 +1527,13 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
14761527
EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper);
14771528

14781529
/**
1479-
* dev_pm_opp_register_put_opp_helper() - Releases resources blocked for
1530+
* dev_pm_opp_unregister_set_opp_helper() - Releases resources blocked for
14801531
* set_opp helper
14811532
* @opp_table: OPP table returned from dev_pm_opp_register_set_opp_helper().
14821533
*
14831534
* Release resources blocked for platform specific set_opp helper.
14841535
*/
1485-
void dev_pm_opp_register_put_opp_helper(struct opp_table *opp_table)
1536+
void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table)
14861537
{
14871538
if (!opp_table->set_opp) {
14881539
pr_err("%s: Doesn't have custom set_opp helper set\n",
@@ -1497,7 +1548,82 @@ void dev_pm_opp_register_put_opp_helper(struct opp_table *opp_table)
14971548

14981549
dev_pm_opp_put_opp_table(opp_table);
14991550
}
1500-
EXPORT_SYMBOL_GPL(dev_pm_opp_register_put_opp_helper);
1551+
EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper);
1552+
1553+
/**
1554+
* dev_pm_opp_register_get_pstate_helper() - Register get_pstate() helper.
1555+
* @dev: Device for which the helper is getting registered.
1556+
* @get_pstate: Helper.
1557+
*
1558+
* TODO: Remove this callback after the same information is available via Device
1559+
* Tree.
1560+
*
1561+
* This allows a platform to initialize the performance states of individual
1562+
* OPPs for its devices, until we get similar information directly from DT.
1563+
*
1564+
* This must be called before the OPPs are initialized for the device.
1565+
*/
1566+
struct opp_table *dev_pm_opp_register_get_pstate_helper(struct device *dev,
1567+
int (*get_pstate)(struct device *dev, unsigned long rate))
1568+
{
1569+
struct opp_table *opp_table;
1570+
int ret;
1571+
1572+
if (!get_pstate)
1573+
return ERR_PTR(-EINVAL);
1574+
1575+
opp_table = dev_pm_opp_get_opp_table(dev);
1576+
if (!opp_table)
1577+
return ERR_PTR(-ENOMEM);
1578+
1579+
/* This should be called before OPPs are initialized */
1580+
if (WARN_ON(!list_empty(&opp_table->opp_list))) {
1581+
ret = -EBUSY;
1582+
goto err;
1583+
}
1584+
1585+
/* Already have genpd_performance_state set */
1586+
if (WARN_ON(opp_table->genpd_performance_state)) {
1587+
ret = -EBUSY;
1588+
goto err;
1589+
}
1590+
1591+
opp_table->genpd_performance_state = true;
1592+
opp_table->get_pstate = get_pstate;
1593+
1594+
return opp_table;
1595+
1596+
err:
1597+
dev_pm_opp_put_opp_table(opp_table);
1598+
1599+
return ERR_PTR(ret);
1600+
}
1601+
EXPORT_SYMBOL_GPL(dev_pm_opp_register_get_pstate_helper);
1602+
1603+
/**
1604+
* dev_pm_opp_unregister_get_pstate_helper() - Releases resources blocked for
1605+
* get_pstate() helper
1606+
* @opp_table: OPP table returned from dev_pm_opp_register_get_pstate_helper().
1607+
*
1608+
* Release resources blocked for platform specific get_pstate() helper.
1609+
*/
1610+
void dev_pm_opp_unregister_get_pstate_helper(struct opp_table *opp_table)
1611+
{
1612+
if (!opp_table->genpd_performance_state) {
1613+
pr_err("%s: Doesn't have performance states set\n",
1614+
__func__);
1615+
return;
1616+
}
1617+
1618+
/* Make sure there are no concurrent readers while updating opp_table */
1619+
WARN_ON(!list_empty(&opp_table->opp_list));
1620+
1621+
opp_table->genpd_performance_state = false;
1622+
opp_table->get_pstate = NULL;
1623+
1624+
dev_pm_opp_put_opp_table(opp_table);
1625+
}
1626+
EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_get_pstate_helper);
15011627

15021628
/**
15031629
* dev_pm_opp_add() - Add an OPP table from a table definitions
@@ -1706,6 +1832,13 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev,
17061832
if (remove_all || !opp->dynamic)
17071833
dev_pm_opp_put(opp);
17081834
}
1835+
1836+
/*
1837+
* The OPP table is getting removed, drop the performance state
1838+
* constraints.
1839+
*/
1840+
if (opp_table->genpd_performance_state)
1841+
dev_pm_genpd_set_performance_state(dev, 0);
17091842
} else {
17101843
_remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table);
17111844
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@ static bool opp_debug_create_supplies(struct dev_pm_opp *opp,
4141
{
4242
struct dentry *d;
4343
int i;
44-
char *name;
4544

4645
for (i = 0; i < opp_table->regulator_count; i++) {
47-
name = kasprintf(GFP_KERNEL, "supply-%d", i);
46+
char name[15];
47+
48+
snprintf(name, sizeof(name), "supply-%d", i);
4849

4950
/* Create per-opp directory */
5051
d = debugfs_create_dir(name, pdentry);
5152

52-
kfree(name);
53-
5453
if (!d)
5554
return false;
5655

@@ -100,6 +99,9 @@ int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table)
10099
if (!debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend))
101100
return -ENOMEM;
102101

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <linux/cpu.h>
1717
#include <linux/errno.h>
1818
#include <linux/device.h>
19-
#include <linux/of.h>
19+
#include <linux/of_device.h>
2020
#include <linux/slab.h>
2121
#include <linux/export.h>
2222

@@ -397,6 +397,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
397397
dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
398398
ret);
399399
_dev_pm_opp_remove_table(opp_table, dev, false);
400+
of_node_put(np);
400401
goto put_opp_table;
401402
}
402403
}
@@ -603,7 +604,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,
603604
if (cpu == cpu_dev->id)
604605
continue;
605606

606-
cpu_np = of_get_cpu_node(cpu, NULL);
607+
cpu_np = of_cpu_device_node_get(cpu);
607608
if (!cpu_np) {
608609
dev_err(cpu_dev, "%s: failed to get cpu%d node\n",
609610
__func__, cpu);
@@ -613,6 +614,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,
613614

614615
/* Get OPP descriptor node */
615616
tmp_np = _opp_of_get_opp_desc_node(cpu_np);
617+
of_node_put(cpu_np);
616618
if (!tmp_np) {
617619
pr_err("%pOF: Couldn't find opp node\n", cpu_np);
618620
ret = -ENOENT;

0 commit comments

Comments
 (0)