aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thermal/cpu_cooling.c
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2014-12-03 23:12:02 -0500
committerEduardo Valentin <edubezval@gmail.com>2014-12-08 13:07:10 -0500
commitdcc6c7fdef9e705b1300be22213fb23e3fd1994d (patch)
tree605b149f51bbde723335f84a37eb24894ac76fb2 /drivers/thermal/cpu_cooling.c
parent521a2e5831704efef8aa826d6b22abef55650d59 (diff)
thermal: cpu_cooling: find max level during device registration
CPU frequency tables don't update after the driver is registered and so we don't need to iterate over them to find total number of states every time cpufreq_get_max_state() is called. Do it once at boot time. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Diffstat (limited to 'drivers/thermal/cpu_cooling.c')
-rw-r--r--drivers/thermal/cpu_cooling.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 2c4c4853cd9f..d34cc5b27021 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -52,6 +52,8 @@
52 * cooling devices. 52 * cooling devices.
53 * @cpufreq_val: integer value representing the absolute value of the clipped 53 * @cpufreq_val: integer value representing the absolute value of the clipped
54 * frequency. 54 * frequency.
55 * @max_level: maximum cooling level. One less than total number of valid
56 * cpufreq frequencies.
55 * @allowed_cpus: all the cpus involved for this cpufreq_cooling_device. 57 * @allowed_cpus: all the cpus involved for this cpufreq_cooling_device.
56 * 58 *
57 * This structure is required for keeping information of each registered 59 * This structure is required for keeping information of each registered
@@ -62,6 +64,7 @@ struct cpufreq_cooling_device {
62 struct thermal_cooling_device *cool_dev; 64 struct thermal_cooling_device *cool_dev;
63 unsigned int cpufreq_state; 65 unsigned int cpufreq_state;
64 unsigned int cpufreq_val; 66 unsigned int cpufreq_val;
67 unsigned int max_level;
65 struct cpumask allowed_cpus; 68 struct cpumask allowed_cpus;
66 struct list_head node; 69 struct list_head node;
67}; 70};
@@ -283,19 +286,9 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
283 unsigned long *state) 286 unsigned long *state)
284{ 287{
285 struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; 288 struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
286 struct cpumask *mask = &cpufreq_device->allowed_cpus;
287 unsigned int cpu;
288 unsigned int count = 0;
289 int ret;
290
291 cpu = cpumask_any(mask);
292
293 ret = get_property(cpu, 0, &count, GET_MAXL);
294
295 if (count > 0)
296 *state = count;
297 289
298 return ret; 290 *state = cpufreq_device->max_level;
291 return 0;
299} 292}
300 293
301/** 294/**
@@ -385,9 +378,11 @@ __cpufreq_cooling_register(struct device_node *np,
385 struct thermal_cooling_device *cool_dev; 378 struct thermal_cooling_device *cool_dev;
386 struct cpufreq_cooling_device *cpufreq_dev; 379 struct cpufreq_cooling_device *cpufreq_dev;
387 char dev_name[THERMAL_NAME_LENGTH]; 380 char dev_name[THERMAL_NAME_LENGTH];
381 struct cpufreq_frequency_table *pos, *table;
388 int ret; 382 int ret;
389 383
390 if (!cpufreq_frequency_get_table(cpumask_first(clip_cpus))) { 384 table = cpufreq_frequency_get_table(cpumask_first(clip_cpus));
385 if (!table) {
391 pr_debug("%s: CPUFreq table not found\n", __func__); 386 pr_debug("%s: CPUFreq table not found\n", __func__);
392 return ERR_PTR(-EPROBE_DEFER); 387 return ERR_PTR(-EPROBE_DEFER);
393 } 388 }
@@ -404,6 +399,13 @@ __cpufreq_cooling_register(struct device_node *np,
404 goto free_cdev; 399 goto free_cdev;
405 } 400 }
406 401
402 /* Find max levels */
403 cpufreq_for_each_valid_entry(pos, table)
404 cpufreq_dev->max_level++;
405
406 /* max_level is an index, not a counter */
407 cpufreq_dev->max_level--;
408
407 cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); 409 cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus);
408 410
409 ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); 411 ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);