Skip to content

Commit 2f7e8a1

Browse files
punitagrawalrafaeljw
authored andcommitted
cpufreq: arm_big_little: Add support to register a cpufreq cooling device
Register passive cooling devices when initialising cpufreq on big.LITTLE systems. If the device tree provides a dynamic power coefficient for the CPUs then the bound cooling device will support the extensions that allow it to be used with all the existing thermal governors including the power allocator governor. A cooling device will be created per individual frequency domain and can be bound to thermal zones via the thermal DT bindings. Signed-off-by: Punit Agrawal <punit.agrawal@arm.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent f8fa8ae commit 2f7e8a1

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎drivers/cpufreq/Kconfig.arm‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
config ARM_BIG_LITTLE_CPUFREQ
77
tristate "Generic ARM big LITTLE CPUfreq driver"
88
depends on (ARM_CPU_TOPOLOGY || ARM64) && HAVE_CLK
9+
# if CPU_THERMAL is on and THERMAL=m, ARM_BIT_LITTLE_CPUFREQ cannot be =y
10+
depends on !CPU_THERMAL || THERMAL
911
select PM_OPP
1012
help
1113
This enables the Generic CPUfreq driver for ARM big.LITTLE platforms.

‎drivers/cpufreq/arm_big_little.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/cpu.h>
2424
#include <linux/cpufreq.h>
2525
#include <linux/cpumask.h>
26+
#include <linux/cpu_cooling.h>
2627
#include <linux/export.h>
2728
#include <linux/module.h>
2829
#include <linux/mutex.h>
@@ -55,6 +56,7 @@ static bool bL_switching_enabled;
5556
#define ACTUAL_FREQ(cluster, freq) ((cluster == A7_CLUSTER) ? freq << 1 : freq)
5657
#define VIRT_FREQ(cluster, freq) ((cluster == A7_CLUSTER) ? freq >> 1 : freq)
5758

59+
static struct thermal_cooling_device *cdev[MAX_CLUSTERS];
5860
static struct cpufreq_arm_bL_ops *arm_bL_ops;
5961
static struct clk *clk[MAX_CLUSTERS];
6062
static struct cpufreq_frequency_table *freq_table[MAX_CLUSTERS + 1];
@@ -493,6 +495,12 @@ static int bL_cpufreq_init(struct cpufreq_policy *policy)
493495
static int bL_cpufreq_exit(struct cpufreq_policy *policy)
494496
{
495497
struct device *cpu_dev;
498+
int cur_cluster = cpu_to_cluster(policy->cpu);
499+
500+
if (cur_cluster < MAX_CLUSTERS) {
501+
cpufreq_cooling_unregister(cdev[cur_cluster]);
502+
cdev[cur_cluster] = NULL;
503+
}
496504

497505
cpu_dev = get_cpu_device(policy->cpu);
498506
if (!cpu_dev) {
@@ -507,6 +515,38 @@ static int bL_cpufreq_exit(struct cpufreq_policy *policy)
507515
return 0;
508516
}
509517

518+
static void bL_cpufreq_ready(struct cpufreq_policy *policy)
519+
{
520+
struct device *cpu_dev = get_cpu_device(policy->cpu);
521+
int cur_cluster = cpu_to_cluster(policy->cpu);
522+
struct device_node *np;
523+
524+
/* Do not register a cpu_cooling device if we are in IKS mode */
525+
if (cur_cluster >= MAX_CLUSTERS)
526+
return;
527+
528+
np = of_node_get(cpu_dev->of_node);
529+
if (WARN_ON(!np))
530+
return;
531+
532+
if (of_find_property(np, "#cooling-cells", NULL)) {
533+
u32 power_coefficient = 0;
534+
535+
of_property_read_u32(np, "dynamic-power-coefficient",
536+
&power_coefficient);
537+
538+
cdev[cur_cluster] = of_cpufreq_power_cooling_register(np,
539+
policy->related_cpus, power_coefficient, NULL);
540+
if (IS_ERR(cdev[cur_cluster])) {
541+
dev_err(cpu_dev,
542+
"running cpufreq without cooling device: %ld\n",
543+
PTR_ERR(cdev[cur_cluster]));
544+
cdev[cur_cluster] = NULL;
545+
}
546+
}
547+
of_node_put(np);
548+
}
549+
510550
static struct cpufreq_driver bL_cpufreq_driver = {
511551
.name = "arm-big-little",
512552
.flags = CPUFREQ_STICKY |
@@ -517,6 +557,7 @@ static struct cpufreq_driver bL_cpufreq_driver = {
517557
.get = bL_cpufreq_get_rate,
518558
.init = bL_cpufreq_init,
519559
.exit = bL_cpufreq_exit,
560+
.ready = bL_cpufreq_ready,
520561
.attr = cpufreq_generic_attr,
521562
};
522563

0 commit comments

Comments
 (0)