summaryrefslogtreecommitdiff
path: root/drivers/thermal
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2014-12-04 09:42:05 +0530
committerEduardo Valentin <edubezval@gmail.com>2014-12-08 14:10:08 -0400
commitb9f8b4160310e4459c08b54b918cd83da141f7f0 (patch)
tree39aee91d1f67d9bed5b890f5ed19381b557c5eed /drivers/thermal
parent2479bb6443d6a793f896219a34bfab0cc410f0b4 (diff)
thermal: cpu_cooling: Pass 'cpufreq_dev' to get_property()
We already know the value of 'cpufreq_dev->max_level' and so there is no need calculating that once again. For this, we need to send 'cpufreq_dev' to get_property(). Make all necessary changes for this change. Because cpufreq_cooling_get_level() doesn't have access to 'cpufreq_dev', it is updated to iterate over the list of cpufreq_cooling_devices to get cooling device for the cpu number passed to it. This also makes it robust to return levels only for the CPU registered via a cooling device. We don't have to support anything that isn't registered yet. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/cpu_cooling.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 32ff6dc5efee..7687922cb02e 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -118,7 +118,7 @@ enum cpufreq_cooling_property {
/**
* get_property - fetch a property of interest for a given cpu.
- * @cpu: cpu for which the property is required
+ * @cpufreq_dev: cpufreq_dev for which the property is required
* @input: query parameter
* @output: query return
* @property: type of query (frequency, level)
@@ -135,20 +135,20 @@ enum cpufreq_cooling_property {
*
* Return: 0 on success, -EINVAL when invalid parameters are passed.
*/
-static int get_property(unsigned int cpu, unsigned long input,
- unsigned int *output,
+static int get_property(struct cpufreq_cooling_device *cpufreq_dev,
+ unsigned long input, unsigned int *output,
enum cpufreq_cooling_property property)
{
int i;
- unsigned long max_level = 0, level = 0;
+ unsigned long level = 0;
unsigned int freq = CPUFREQ_ENTRY_INVALID;
int descend = -1;
- struct cpufreq_frequency_table *pos, *table =
- cpufreq_frequency_get_table(cpu);
+ struct cpufreq_frequency_table *pos, *table;
if (!output)
return -EINVAL;
+ table = cpufreq_frequency_get_table(cpumask_first(&cpufreq_dev->allowed_cpus));
if (!table)
return -EINVAL;
@@ -162,18 +162,10 @@ static int get_property(unsigned int cpu, unsigned long input,
descend = freq > pos->frequency;
freq = pos->frequency;
- max_level++;
}
- /* No valid cpu frequency entry */
- if (max_level == 0)
- return -EINVAL;
-
- /* max_level is an index, not a counter */
- max_level--;
-
if (property == GET_FREQ)
- level = descend ? input : (max_level - input);
+ level = descend ? input : (cpufreq_dev->max_level - input);
i = 0;
cpufreq_for_each_valid_entry(pos, table) {
@@ -186,7 +178,7 @@ static int get_property(unsigned int cpu, unsigned long input,
if (property == GET_LEVEL && (unsigned int)input == freq) {
/* get level by frequency */
- *output = descend ? i : (max_level - i);
+ *output = descend ? i : (cpufreq_dev->max_level - i);
return 0;
}
if (property == GET_FREQ && level == i) {
@@ -213,12 +205,25 @@ static int get_property(unsigned int cpu, unsigned long input,
*/
unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq)
{
- unsigned int val;
+ struct cpufreq_cooling_device *cpufreq_dev;
- if (get_property(cpu, (unsigned long)freq, &val, GET_LEVEL))
- return THERMAL_CSTATE_INVALID;
+ mutex_lock(&cooling_cpufreq_lock);
+ list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) {
+ if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) {
+ unsigned int val;
+
+ mutex_unlock(&cooling_cpufreq_lock);
+ if (get_property(cpufreq_dev, (unsigned long)freq, &val,
+ GET_LEVEL))
+ return THERMAL_CSTATE_INVALID;
+
+ return (unsigned long)val;
+ }
+ }
+ mutex_unlock(&cooling_cpufreq_lock);
- return (unsigned long)val;
+ pr_err("%s: cpu:%d not part of any cooling device\n", __func__, cpu);
+ return THERMAL_CSTATE_INVALID;
}
EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level);
@@ -323,7 +328,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
if (cpufreq_device->cpufreq_state == state)
return 0;
- ret = get_property(cpu, state, &clip_freq, GET_FREQ);
+ ret = get_property(cpufreq_device, state, &clip_freq, GET_FREQ);
if (ret)
return ret;
@@ -381,8 +386,7 @@ __cpufreq_cooling_register(struct device_node *np,
if (!cpufreq_dev)
return ERR_PTR(-ENOMEM);
- ret = get_property(cpumask_any(clip_cpus), 0, &cpufreq_dev->cpufreq_val,
- GET_FREQ);
+ ret = get_property(cpufreq_dev, 0, &cpufreq_dev->cpufreq_val, GET_FREQ);
if (ret) {
pr_err("%s: Failed to get frequency: %d", __func__, ret);
cool_dev = ERR_PTR(ret);