Skip to content

Commit a34024d

Browse files
committed
Merge branches 'pm-devfreq', 'powercap', 'pm-docs' and 'pm-tools'
* pm-devfreq: PM / devfreq: Use lockdep asserts instead of manual checks for locked mutex PM / devfreq: imx-bus: Fix inconsistent IS_ERR and PTR_ERR PM / devfreq: Replace strncpy with strscpy PM / devfreq: imx: Register interconnect device PM / devfreq: Add generic imx bus scaling driver PM / devfreq: tegra30: Delete an error message in tegra_devfreq_probe() PM / devfreq: tegra30: Make CPUFreq notifier to take into account boosting * powercap: powercap: RAPL: remove unused local MSR define powercap/intel_rapl: add support for ElkhartLake * pm-docs: Documentation: admin-guide: pm: Document intel-speed-select * pm-tools: cpupower: Remove unneeded semicolon
5 parents ac7ccfc + 86954c9 + 03c3b41 + 213081d + 5ed909b commit a34024d

File tree

15 files changed

+1127
-27
lines changed

15 files changed

+1127
-27
lines changed

Documentation/admin-guide/pm/intel-speed-select.rst

Lines changed: 917 additions & 0 deletions
Large diffs are not rendered by default.

Documentation/admin-guide/pm/working-state.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Working-State Power Management
1313
intel_pstate
1414
cpufreq_drivers
1515
intel_epb
16+
intel-speed-select

drivers/devfreq/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ config ARM_EXYNOS_BUS_DEVFREQ
9191
and adjusts the operating frequencies and voltages with OPP support.
9292
This does not yet operate with optimal voltages.
9393

94+
config ARM_IMX_BUS_DEVFREQ
95+
tristate "i.MX Generic Bus DEVFREQ Driver"
96+
depends on ARCH_MXC || COMPILE_TEST
97+
select DEVFREQ_GOV_USERSPACE
98+
help
99+
This adds the generic DEVFREQ driver for i.MX interconnects. It
100+
allows adjusting NIC/NOC frequency.
101+
94102
config ARM_IMX8M_DDRC_DEVFREQ
95103
tristate "i.MX8M DDRC DEVFREQ Driver"
96104
depends on (ARCH_MXC && HAVE_ARM_SMCCC) || \

drivers/devfreq/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o
99

1010
# DEVFREQ Drivers
1111
obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o
12+
obj-$(CONFIG_ARM_IMX_BUS_DEVFREQ) += imx-bus.o
1213
obj-$(CONFIG_ARM_IMX8M_DDRC_DEVFREQ) += imx8m-ddrc.o
1314
obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o
1415
obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o

drivers/devfreq/devfreq.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ static struct devfreq *find_device_devfreq(struct device *dev)
6060
{
6161
struct devfreq *tmp_devfreq;
6262

63+
lockdep_assert_held(&devfreq_list_lock);
64+
6365
if (IS_ERR_OR_NULL(dev)) {
6466
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
6567
return ERR_PTR(-EINVAL);
6668
}
67-
WARN(!mutex_is_locked(&devfreq_list_lock),
68-
"devfreq_list_lock must be locked.");
6969

7070
list_for_each_entry(tmp_devfreq, &devfreq_list, node) {
7171
if (tmp_devfreq->dev.parent == dev)
@@ -258,12 +258,12 @@ static struct devfreq_governor *find_devfreq_governor(const char *name)
258258
{
259259
struct devfreq_governor *tmp_governor;
260260

261+
lockdep_assert_held(&devfreq_list_lock);
262+
261263
if (IS_ERR_OR_NULL(name)) {
262264
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
263265
return ERR_PTR(-EINVAL);
264266
}
265-
WARN(!mutex_is_locked(&devfreq_list_lock),
266-
"devfreq_list_lock must be locked.");
267267

268268
list_for_each_entry(tmp_governor, &devfreq_governor_list, node) {
269269
if (!strncmp(tmp_governor->name, name, DEVFREQ_NAME_LEN))
@@ -289,12 +289,12 @@ static struct devfreq_governor *try_then_request_governor(const char *name)
289289
struct devfreq_governor *governor;
290290
int err = 0;
291291

292+
lockdep_assert_held(&devfreq_list_lock);
293+
292294
if (IS_ERR_OR_NULL(name)) {
293295
pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
294296
return ERR_PTR(-EINVAL);
295297
}
296-
WARN(!mutex_is_locked(&devfreq_list_lock),
297-
"devfreq_list_lock must be locked.");
298298

299299
governor = find_devfreq_governor(name);
300300
if (IS_ERR(governor)) {
@@ -392,10 +392,7 @@ int update_devfreq(struct devfreq *devfreq)
392392
int err = 0;
393393
u32 flags = 0;
394394

395-
if (!mutex_is_locked(&devfreq->lock)) {
396-
WARN(true, "devfreq->lock must be locked by the caller.\n");
397-
return -EINVAL;
398-
}
395+
lockdep_assert_held(&devfreq->lock);
399396

400397
if (!devfreq->governor)
401398
return -EINVAL;
@@ -768,7 +765,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
768765
devfreq->dev.release = devfreq_dev_release;
769766
INIT_LIST_HEAD(&devfreq->node);
770767
devfreq->profile = profile;
771-
strncpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
768+
strscpy(devfreq->governor_name, governor_name, DEVFREQ_NAME_LEN);
772769
devfreq->previous_freq = profile->initial_freq;
773770
devfreq->last_status.current_frequency = profile->initial_freq;
774771
devfreq->data = data;

drivers/devfreq/imx-bus.c

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright 2019 NXP
4+
*/
5+
6+
#include <linux/clk.h>
7+
#include <linux/devfreq.h>
8+
#include <linux/device.h>
9+
#include <linux/module.h>
10+
#include <linux/of_device.h>
11+
#include <linux/pm_opp.h>
12+
#include <linux/platform_device.h>
13+
#include <linux/slab.h>
14+
15+
struct imx_bus {
16+
struct devfreq_dev_profile profile;
17+
struct devfreq *devfreq;
18+
struct clk *clk;
19+
struct platform_device *icc_pdev;
20+
};
21+
22+
static int imx_bus_target(struct device *dev,
23+
unsigned long *freq, u32 flags)
24+
{
25+
struct dev_pm_opp *new_opp;
26+
int ret;
27+
28+
new_opp = devfreq_recommended_opp(dev, freq, flags);
29+
if (IS_ERR(new_opp)) {
30+
ret = PTR_ERR(new_opp);
31+
dev_err(dev, "failed to get recommended opp: %d\n", ret);
32+
return ret;
33+
}
34+
dev_pm_opp_put(new_opp);
35+
36+
return dev_pm_opp_set_rate(dev, *freq);
37+
}
38+
39+
static int imx_bus_get_cur_freq(struct device *dev, unsigned long *freq)
40+
{
41+
struct imx_bus *priv = dev_get_drvdata(dev);
42+
43+
*freq = clk_get_rate(priv->clk);
44+
45+
return 0;
46+
}
47+
48+
static int imx_bus_get_dev_status(struct device *dev,
49+
struct devfreq_dev_status *stat)
50+
{
51+
struct imx_bus *priv = dev_get_drvdata(dev);
52+
53+
stat->busy_time = 0;
54+
stat->total_time = 0;
55+
stat->current_frequency = clk_get_rate(priv->clk);
56+
57+
return 0;
58+
}
59+
60+
static void imx_bus_exit(struct device *dev)
61+
{
62+
struct imx_bus *priv = dev_get_drvdata(dev);
63+
64+
dev_pm_opp_of_remove_table(dev);
65+
platform_device_unregister(priv->icc_pdev);
66+
}
67+
68+
/* imx_bus_init_icc() - register matching icc provider if required */
69+
static int imx_bus_init_icc(struct device *dev)
70+
{
71+
struct imx_bus *priv = dev_get_drvdata(dev);
72+
const char *icc_driver_name;
73+
74+
if (!of_get_property(dev->of_node, "#interconnect-cells", 0))
75+
return 0;
76+
if (!IS_ENABLED(CONFIG_INTERCONNECT_IMX)) {
77+
dev_warn(dev, "imx interconnect drivers disabled\n");
78+
return 0;
79+
}
80+
81+
icc_driver_name = of_device_get_match_data(dev);
82+
if (!icc_driver_name) {
83+
dev_err(dev, "unknown interconnect driver\n");
84+
return 0;
85+
}
86+
87+
priv->icc_pdev = platform_device_register_data(
88+
dev, icc_driver_name, -1, NULL, 0);
89+
if (IS_ERR(priv->icc_pdev)) {
90+
dev_err(dev, "failed to register icc provider %s: %ld\n",
91+
icc_driver_name, PTR_ERR(priv->icc_pdev));
92+
return PTR_ERR(priv->icc_pdev);
93+
}
94+
95+
return 0;
96+
}
97+
98+
static int imx_bus_probe(struct platform_device *pdev)
99+
{
100+
struct device *dev = &pdev->dev;
101+
struct imx_bus *priv;
102+
const char *gov = DEVFREQ_GOV_USERSPACE;
103+
int ret;
104+
105+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
106+
if (!priv)
107+
return -ENOMEM;
108+
109+
/*
110+
* Fetch the clock to adjust but don't explicitly enable.
111+
*
112+
* For imx bus clock clk_set_rate is safe no matter if the clock is on
113+
* or off and some peripheral side-buses might be off unless enabled by
114+
* drivers for devices on those specific buses.
115+
*
116+
* Rate adjustment on a disabled bus clock just takes effect later.
117+
*/
118+
priv->clk = devm_clk_get(dev, NULL);
119+
if (IS_ERR(priv->clk)) {
120+
ret = PTR_ERR(priv->clk);
121+
dev_err(dev, "failed to fetch clk: %d\n", ret);
122+
return ret;
123+
}
124+
platform_set_drvdata(pdev, priv);
125+
126+
ret = dev_pm_opp_of_add_table(dev);
127+
if (ret < 0) {
128+
dev_err(dev, "failed to get OPP table\n");
129+
return ret;
130+
}
131+
132+
priv->profile.polling_ms = 1000;
133+
priv->profile.target = imx_bus_target;
134+
priv->profile.get_dev_status = imx_bus_get_dev_status;
135+
priv->profile.exit = imx_bus_exit;
136+
priv->profile.get_cur_freq = imx_bus_get_cur_freq;
137+
priv->profile.initial_freq = clk_get_rate(priv->clk);
138+
139+
priv->devfreq = devm_devfreq_add_device(dev, &priv->profile,
140+
gov, NULL);
141+
if (IS_ERR(priv->devfreq)) {
142+
ret = PTR_ERR(priv->devfreq);
143+
dev_err(dev, "failed to add devfreq device: %d\n", ret);
144+
goto err;
145+
}
146+
147+
ret = imx_bus_init_icc(dev);
148+
if (ret)
149+
goto err;
150+
151+
return 0;
152+
153+
err:
154+
dev_pm_opp_of_remove_table(dev);
155+
return ret;
156+
}
157+
158+
static const struct of_device_id imx_bus_of_match[] = {
159+
{ .compatible = "fsl,imx8mq-noc", .data = "imx8mq-interconnect", },
160+
{ .compatible = "fsl,imx8mm-noc", .data = "imx8mm-interconnect", },
161+
{ .compatible = "fsl,imx8mn-noc", .data = "imx8mn-interconnect", },
162+
{ .compatible = "fsl,imx8m-noc", },
163+
{ .compatible = "fsl,imx8m-nic", },
164+
{ /* sentinel */ },
165+
};
166+
MODULE_DEVICE_TABLE(of, imx_bus_of_match);
167+
168+
static struct platform_driver imx_bus_platdrv = {
169+
.probe = imx_bus_probe,
170+
.driver = {
171+
.name = "imx-bus-devfreq",
172+
.of_match_table = of_match_ptr(imx_bus_of_match),
173+
},
174+
};
175+
module_platform_driver(imx_bus_platdrv);
176+
177+
MODULE_DESCRIPTION("Generic i.MX bus frequency scaling driver");
178+
MODULE_AUTHOR("Leonard Crestez <[email protected]>");
179+
MODULE_LICENSE("GPL v2");

drivers/devfreq/tegra30-devfreq.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ tegra_actmon_cpufreq_contribution(struct tegra_devfreq *tegra,
420420

421421
static_cpu_emc_freq = actmon_cpu_to_emc_rate(tegra, cpu_freq);
422422

423-
if (dev_freq >= static_cpu_emc_freq)
423+
if (dev_freq + actmon_dev->boost_freq >= static_cpu_emc_freq)
424424
return 0;
425425

426426
return static_cpu_emc_freq;
@@ -807,10 +807,9 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
807807
}
808808

809809
err = platform_get_irq(pdev, 0);
810-
if (err < 0) {
811-
dev_err(&pdev->dev, "Failed to get IRQ: %d\n", err);
810+
if (err < 0)
812811
return err;
813-
}
812+
814813
tegra->irq = err;
815814

816815
irq_set_status_flags(tegra->irq, IRQ_NOAUTOEN);

drivers/powercap/intel_rapl_common.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
#include <asm/cpu_device_id.h>
2727
#include <asm/intel-family.h>
2828

29-
/* Local defines */
30-
#define MSR_PLATFORM_POWER_LIMIT 0x0000065C
31-
3229
/* bitmasks for RAPL MSRs, used by primitive access functions */
3330
#define ENERGY_STATUS_MASK 0xffffffff
3431

@@ -989,6 +986,7 @@ static const struct x86_cpu_id rapl_ids[] __initconst = {
989986
X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT, &rapl_defaults_core),
990987
X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_PLUS, &rapl_defaults_core),
991988
X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_D, &rapl_defaults_core),
989+
X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT, &rapl_defaults_core),
992990
X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_D, &rapl_defaults_core),
993991
X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_L, &rapl_defaults_core),
994992

tools/power/cpupower/utils/cpupower-info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int cmd_info(int argc, char **argv)
6262
default:
6363
print_wrong_arg_exit();
6464
}
65-
};
65+
}
6666

6767
if (!params.params)
6868
params.params = 0x7;

tools/power/cpupower/utils/cpupower-set.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int cmd_set(int argc, char **argv)
7272
default:
7373
print_wrong_arg_exit();
7474
}
75-
};
75+
}
7676

7777
if (!params.params)
7878
print_wrong_arg_exit();

0 commit comments

Comments
 (0)