Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac5b7607 authored by Ram Chandrasekar's avatar Ram Chandrasekar Committed by Manaf Meethalavalappu Pallikunhi
Browse files

qcom-cpufreq: Register cooling device in ready callback



Thermal cooling device has to be registered when the policy for a CPU is
ready. Cpufreq will get a callback when a cpufreq policy is ready and
register CPU cooling device as a part of this callback, so that the CPU
can be mitigated immediately if needed.

Ignore cpu cooling device registration when there is platform cooling
device available.

Change-Id: I7cfb8598aa8ead4091a617da3faddf86ff0fe6a8
Signed-off-by: default avatarRam Chandrasekar <rkumbako@codeaurora.org>
Signed-off-by: default avatarManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
parent 296c1f72
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -27,10 +27,13 @@
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/cpu_cooling.h>
#include <trace/events/power.h>

static DEFINE_MUTEX(l2bw_lock);

static struct thermal_cooling_device *cdev[NR_CPUS];
static struct clk *cpu_clk[NR_CPUS];
static struct clk *l2_clk;
static DEFINE_PER_CPU(struct cpufreq_frequency_table *, freq_table);
@@ -306,6 +309,50 @@ static struct freq_attr *msm_freq_attr[] = {
	NULL,
};

static void msm_cpufreq_ready(struct cpufreq_policy *policy)
{
	struct device_node *np, *lmh_node;
	unsigned int cpu = 0;

	if (cdev[policy->cpu])
		return;

	np = of_cpu_device_node_get(policy->cpu);
	if (WARN_ON(!np))
		return;

	/*
	 * For now, just loading the cooling device;
	 * thermal DT code takes care of matching them.
	 */
	if (of_find_property(np, "#cooling-cells", NULL)) {
		lmh_node = of_parse_phandle(np, "qcom,lmh-dcvs", 0);
		if (lmh_node) {
			of_node_put(lmh_node);
			goto ready_exit;
		}

		for_each_cpu(cpu, policy->related_cpus) {

			of_node_put(np);
			np = of_cpu_device_node_get(cpu);
			if (WARN_ON(!np))
				return;

			cdev[cpu] = of_cpufreq_cooling_register(np, policy);
			if (IS_ERR(cdev[cpu])) {
				pr_err(
				"running cpufreq for CPU%d without cooling dev: %ld\n",
				cpu, PTR_ERR(cdev[cpu]));
				cdev[cpu] = NULL;
			}
		}
	}

ready_exit:
	of_node_put(np);
}

static struct cpufreq_driver msm_cpufreq_driver = {
	/* lps calculations are handled here. */
	.flags		= CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS |
@@ -317,6 +364,7 @@ static struct cpufreq_driver msm_cpufreq_driver = {
	.get		= msm_cpufreq_get_freq,
	.name		= "msm",
	.attr		= msm_freq_attr,
	.ready		= msm_cpufreq_ready,
};

static struct cpufreq_frequency_table *cpufreq_parse_dt(struct device *dev,