Skip to content

Commit b2a6181

Browse files
committed
Merge branch 'cpufreq/arm/linux-next' of git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm
Pull ARM cpufreq driver changes for v5.15 from Viresh Kumar: "This contains: - Update cpufreq-dt blocklist with more platforms (Bjorn Andersson). - Allow freq changes from any CPU for qcom-hw driver (Taniya Das). - Add DSVS interrupt's support for qcom-hw driver (Thara Gopinath). - A new callback (->register_em()) to register EM at a more convenient point of time." * 'cpufreq/arm/linux-next' of git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm: cpufreq: qcom-hw: Set dvfs_possible_from_any_cpu cpufreq driver flag cpufreq: blocklist more Qualcomm platforms in cpufreq-dt-platdev cpufreq: qcom-cpufreq-hw: Add dcvs interrupt support cpufreq: scmi: Use .register_em() to register with energy model cpufreq: vexpress: Use .register_em() to register with energy model cpufreq: scpi: Use .register_em() to register with energy model cpufreq: qcom-cpufreq-hw: Use .register_em() to register with energy model cpufreq: omap: Use .register_em() to register with energy model cpufreq: mediatek: Use .register_em() to register with energy model cpufreq: imx6q: Use .register_em() to register with energy model cpufreq: dt: Use .register_em() to register with energy model cpufreq: Add callback to register with energy model cpufreq: vexpress: Set CPUFREQ_IS_COOLING_DEV flag
2 parents d0e936a + f0712ac commit b2a6181

File tree

12 files changed

+233
-54
lines changed

12 files changed

+233
-54
lines changed

drivers/base/arch_topology.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq,
149149
}
150150

151151
DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE;
152+
EXPORT_PER_CPU_SYMBOL_GPL(cpu_scale);
152153

153154
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
154155
{
@@ -165,6 +166,7 @@ void topology_set_thermal_pressure(const struct cpumask *cpus,
165166
for_each_cpu(cpu, cpus)
166167
WRITE_ONCE(per_cpu(thermal_pressure, cpu), th_pressure);
167168
}
169+
EXPORT_SYMBOL_GPL(topology_set_thermal_pressure);
168170

169171
static ssize_t cpu_capacity_show(struct device *dev,
170172
struct device_attribute *attr,

drivers/cpufreq/cpufreq-dt-platdev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,15 @@ static const struct of_device_id blocklist[] __initconst = {
137137
{ .compatible = "qcom,apq8096", },
138138
{ .compatible = "qcom,msm8996", },
139139
{ .compatible = "qcom,qcs404", },
140+
{ .compatible = "qcom,sa8155p" },
140141
{ .compatible = "qcom,sc7180", },
141142
{ .compatible = "qcom,sc7280", },
142143
{ .compatible = "qcom,sc8180x", },
143144
{ .compatible = "qcom,sdm845", },
145+
{ .compatible = "qcom,sm6350", },
144146
{ .compatible = "qcom,sm8150", },
147+
{ .compatible = "qcom,sm8250", },
148+
{ .compatible = "qcom,sm8350", },
145149

146150
{ .compatible = "st,stih407", },
147151
{ .compatible = "st,stih410", },

drivers/cpufreq/cpufreq-dt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ static int cpufreq_init(struct cpufreq_policy *policy)
143143
cpufreq_dt_attr[1] = &cpufreq_freq_attr_scaling_boost_freqs;
144144
}
145145

146-
dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
147-
148146
return 0;
149147

150148
out_clk_put:
@@ -184,6 +182,7 @@ static struct cpufreq_driver dt_cpufreq_driver = {
184182
.exit = cpufreq_exit,
185183
.online = cpufreq_online,
186184
.offline = cpufreq_offline,
185+
.register_em = cpufreq_register_em_with_opp,
187186
.name = "cpufreq-dt",
188187
.attr = cpufreq_dt_attr,
189188
.suspend = cpufreq_generic_suspend,

drivers/cpufreq/cpufreq.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,19 @@ static int cpufreq_online(unsigned int cpu)
14911491
write_lock_irqsave(&cpufreq_driver_lock, flags);
14921492
list_add(&policy->policy_list, &cpufreq_policy_list);
14931493
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1494+
1495+
/*
1496+
* Register with the energy model before
1497+
* sched_cpufreq_governor_change() is called, which will result
1498+
* in rebuilding of the sched domains, which should only be done
1499+
* once the energy model is properly initialized for the policy
1500+
* first.
1501+
*
1502+
* Also, this should be called before the policy is registered
1503+
* with cooling framework.
1504+
*/
1505+
if (cpufreq_driver->register_em)
1506+
cpufreq_driver->register_em(policy);
14941507
}
14951508

14961509
ret = cpufreq_init_policy(policy);

drivers/cpufreq/imx6q-cpufreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
192192
policy->clk = clks[ARM].clk;
193193
cpufreq_generic_init(policy, freq_table, transition_latency);
194194
policy->suspend_freq = max_freq;
195-
dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
196195

197196
return 0;
198197
}
@@ -204,6 +203,7 @@ static struct cpufreq_driver imx6q_cpufreq_driver = {
204203
.target_index = imx6q_set_target,
205204
.get = cpufreq_generic_get,
206205
.init = imx6q_cpufreq_init,
206+
.register_em = cpufreq_register_em_with_opp,
207207
.name = "imx6q-cpufreq",
208208
.attr = cpufreq_generic_attr,
209209
.suspend = cpufreq_generic_suspend,

drivers/cpufreq/mediatek-cpufreq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,6 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
448448
policy->driver_data = info;
449449
policy->clk = info->cpu_clk;
450450

451-
dev_pm_opp_of_register_em(info->cpu_dev, policy->cpus);
452-
453451
return 0;
454452
}
455453

@@ -471,6 +469,7 @@ static struct cpufreq_driver mtk_cpufreq_driver = {
471469
.get = cpufreq_generic_get,
472470
.init = mtk_cpufreq_init,
473471
.exit = mtk_cpufreq_exit,
472+
.register_em = cpufreq_register_em_with_opp,
474473
.name = "mtk-cpufreq",
475474
.attr = cpufreq_generic_attr,
476475
};

drivers/cpufreq/omap-cpufreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ static int omap_cpu_init(struct cpufreq_policy *policy)
131131

132132
/* FIXME: what's the actual transition time? */
133133
cpufreq_generic_init(policy, freq_table, 300 * 1000);
134-
dev_pm_opp_of_register_em(mpu_dev, policy->cpus);
135134

136135
return 0;
137136
}
@@ -150,6 +149,7 @@ static struct cpufreq_driver omap_driver = {
150149
.get = cpufreq_generic_get,
151150
.init = omap_cpu_init,
152151
.exit = omap_cpu_exit,
152+
.register_em = cpufreq_register_em_with_opp,
153153
.name = "omap",
154154
.attr = cpufreq_generic_attr,
155155
};

drivers/cpufreq/qcom-cpufreq-hw.c

Lines changed: 149 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
#include <linux/cpufreq.h>
88
#include <linux/init.h>
99
#include <linux/interconnect.h>
10+
#include <linux/interrupt.h>
1011
#include <linux/kernel.h>
1112
#include <linux/module.h>
1213
#include <linux/of_address.h>
1314
#include <linux/of_platform.h>
1415
#include <linux/pm_opp.h>
1516
#include <linux/slab.h>
17+
#include <linux/spinlock.h>
1618

1719
#define LUT_MAX_ENTRIES 40U
1820
#define LUT_SRC GENMASK(31, 30)
@@ -22,10 +24,13 @@
2224
#define CLK_HW_DIV 2
2325
#define LUT_TURBO_IND 1
2426

27+
#define HZ_PER_KHZ 1000
28+
2529
struct qcom_cpufreq_soc_data {
2630
u32 reg_enable;
2731
u32 reg_freq_lut;
2832
u32 reg_volt_lut;
33+
u32 reg_current_vote;
2934
u32 reg_perf_state;
3035
u8 lut_row_size;
3136
};
@@ -34,6 +39,16 @@ struct qcom_cpufreq_data {
3439
void __iomem *base;
3540
struct resource *res;
3641
const struct qcom_cpufreq_soc_data *soc_data;
42+
43+
/*
44+
* Mutex to synchronize between de-init sequence and re-starting LMh
45+
* polling/interrupts
46+
*/
47+
struct mutex throttle_lock;
48+
int throttle_irq;
49+
bool cancel_throttle;
50+
struct delayed_work throttle_work;
51+
struct cpufreq_policy *policy;
3752
};
3853

3954
static unsigned long cpu_hw_rate, xo_rate;
@@ -251,10 +266,92 @@ static void qcom_get_related_cpus(int index, struct cpumask *m)
251266
}
252267
}
253268

269+
static unsigned int qcom_lmh_get_throttle_freq(struct qcom_cpufreq_data *data)
270+
{
271+
unsigned int val = readl_relaxed(data->base + data->soc_data->reg_current_vote);
272+
273+
return (val & 0x3FF) * 19200;
274+
}
275+
276+
static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data)
277+
{
278+
unsigned long max_capacity, capacity, freq_hz, throttled_freq;
279+
struct cpufreq_policy *policy = data->policy;
280+
int cpu = cpumask_first(policy->cpus);
281+
struct device *dev = get_cpu_device(cpu);
282+
struct dev_pm_opp *opp;
283+
unsigned int freq;
284+
285+
/*
286+
* Get the h/w throttled frequency, normalize it using the
287+
* registered opp table and use it to calculate thermal pressure.
288+
*/
289+
freq = qcom_lmh_get_throttle_freq(data);
290+
freq_hz = freq * HZ_PER_KHZ;
291+
292+
opp = dev_pm_opp_find_freq_floor(dev, &freq_hz);
293+
if (IS_ERR(opp) && PTR_ERR(opp) == -ERANGE)
294+
dev_pm_opp_find_freq_ceil(dev, &freq_hz);
295+
296+
throttled_freq = freq_hz / HZ_PER_KHZ;
297+
298+
/* Update thermal pressure */
299+
300+
max_capacity = arch_scale_cpu_capacity(cpu);
301+
capacity = mult_frac(max_capacity, throttled_freq, policy->cpuinfo.max_freq);
302+
303+
/* Don't pass boost capacity to scheduler */
304+
if (capacity > max_capacity)
305+
capacity = max_capacity;
306+
307+
arch_set_thermal_pressure(policy->cpus, max_capacity - capacity);
308+
309+
/*
310+
* In the unlikely case policy is unregistered do not enable
311+
* polling or h/w interrupt
312+
*/
313+
mutex_lock(&data->throttle_lock);
314+
if (data->cancel_throttle)
315+
goto out;
316+
317+
/*
318+
* If h/w throttled frequency is higher than what cpufreq has requested
319+
* for, then stop polling and switch back to interrupt mechanism.
320+
*/
321+
if (throttled_freq >= qcom_cpufreq_hw_get(cpu))
322+
enable_irq(data->throttle_irq);
323+
else
324+
mod_delayed_work(system_highpri_wq, &data->throttle_work,
325+
msecs_to_jiffies(10));
326+
327+
out:
328+
mutex_unlock(&data->throttle_lock);
329+
}
330+
331+
static void qcom_lmh_dcvs_poll(struct work_struct *work)
332+
{
333+
struct qcom_cpufreq_data *data;
334+
335+
data = container_of(work, struct qcom_cpufreq_data, throttle_work.work);
336+
qcom_lmh_dcvs_notify(data);
337+
}
338+
339+
static irqreturn_t qcom_lmh_dcvs_handle_irq(int irq, void *data)
340+
{
341+
struct qcom_cpufreq_data *c_data = data;
342+
343+
/* Disable interrupt and enable polling */
344+
disable_irq_nosync(c_data->throttle_irq);
345+
qcom_lmh_dcvs_notify(c_data);
346+
347+
return 0;
348+
}
349+
254350
static const struct qcom_cpufreq_soc_data qcom_soc_data = {
255351
.reg_enable = 0x0,
256352
.reg_freq_lut = 0x110,
257353
.reg_volt_lut = 0x114,
354+
.reg_current_vote = 0x704,
258355
.reg_perf_state = 0x920,
259356
.lut_row_size = 32,
260357
};
@@ -274,6 +371,51 @@ static const struct of_device_id qcom_cpufreq_hw_match[] = {
274371
};
275372
MODULE_DEVICE_TABLE(of, qcom_cpufreq_hw_match);
276373

374+
static int qcom_cpufreq_hw_lmh_init(struct cpufreq_policy *policy, int index)
375+
{
376+
struct qcom_cpufreq_data *data = policy->driver_data;
377+
struct platform_device *pdev = cpufreq_get_driver_data();
378+
char irq_name[15];
379+
int ret;
380+
381+
/*
382+
* Look for LMh interrupt. If no interrupt line is specified /
383+
* if there is an error, allow cpufreq to be enabled as usual.
384+
*/
385+
data->throttle_irq = platform_get_irq(pdev, index);
386+
if (data->throttle_irq <= 0)
387+
return data->throttle_irq == -EPROBE_DEFER ? -EPROBE_DEFER : 0;
388+
389+
data->cancel_throttle = false;
390+
data->policy = policy;
391+
392+
mutex_init(&data->throttle_lock);
393+
INIT_DEFERRABLE_WORK(&data->throttle_work, qcom_lmh_dcvs_poll);
394+
395+
snprintf(irq_name, sizeof(irq_name), "dcvsh-irq-%u", policy->cpu);
396+
ret = request_threaded_irq(data->throttle_irq, NULL, qcom_lmh_dcvs_handle_irq,
397+
IRQF_ONESHOT, irq_name, data);
398+
if (ret) {
399+
dev_err(&pdev->dev, "Error registering %s: %d\n", irq_name, ret);
400+
return 0;
401+
}
402+
403+
return 0;
404+
}
405+
406+
static void qcom_cpufreq_hw_lmh_exit(struct qcom_cpufreq_data *data)
407+
{
408+
if (data->throttle_irq <= 0)
409+
return;
410+
411+
mutex_lock(&data->throttle_lock);
412+
data->cancel_throttle = true;
413+
mutex_unlock(&data->throttle_lock);
414+
415+
cancel_delayed_work_sync(&data->throttle_work);
416+
free_irq(data->throttle_irq, data);
417+
}
418+
277419
static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
278420
{
279421
struct platform_device *pdev = cpufreq_get_driver_data();
@@ -348,6 +490,7 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
348490
}
349491

350492
policy->driver_data = data;
493+
policy->dvfs_possible_from_any_cpu = true;
351494

352495
ret = qcom_cpufreq_hw_read_lut(cpu_dev, policy);
353496
if (ret) {
@@ -362,14 +505,16 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
362505
goto error;
363506
}
364507

365-
dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
366-
367508
if (policy_has_boost_freq(policy)) {
368509
ret = cpufreq_enable_boost_support();
369510
if (ret)
370511
dev_warn(cpu_dev, "failed to enable boost: %d\n", ret);
371512
}
372513

514+
ret = qcom_cpufreq_hw_lmh_init(policy, index);
515+
if (ret)
516+
goto error;
517+
373518
return 0;
374519
error:
375520
kfree(data);
@@ -389,6 +534,7 @@ static int qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy)
389534

390535
dev_pm_opp_remove_all_dynamic(cpu_dev);
391536
dev_pm_opp_of_cpumask_remove_table(policy->related_cpus);
537+
qcom_cpufreq_hw_lmh_exit(data);
392538
kfree(policy->freq_table);
393539
kfree(data);
394540
iounmap(base);
@@ -412,6 +558,7 @@ static struct cpufreq_driver cpufreq_qcom_hw_driver = {
412558
.get = qcom_cpufreq_hw_get,
413559
.init = qcom_cpufreq_hw_cpu_init,
414560
.exit = qcom_cpufreq_hw_cpu_exit,
561+
.register_em = cpufreq_register_em_with_opp,
415562
.fast_switch = qcom_cpufreq_hw_fast_switch,
416563
.name = "qcom-cpufreq-hw",
417564
.attr = qcom_cpufreq_hw_attr,

0 commit comments

Comments
 (0)