aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thermal
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2014-12-03 23:12:05 -0500
committerEduardo Valentin <edubezval@gmail.com>2014-12-08 13:10:08 -0500
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 {
118 118
119/** 119/**
120 * get_property - fetch a property of interest for a given cpu. 120 * get_property - fetch a property of interest for a given cpu.
121 * @cpu: cpu for which the property is required 121 * @cpufreq_dev: cpufreq_dev for which the property is required
122 * @input: query parameter 122 * @input: query parameter
123 * @output: query return 123 * @output: query return
124 * @property: type of query (frequency, level) 124 * @property: type of query (frequency, level)
@@ -135,20 +135,20 @@ enum cpufreq_cooling_property {
135 * 135 *
136 * Return: 0 on success, -EINVAL when invalid parameters are passed. 136 * Return: 0 on success, -EINVAL when invalid parameters are passed.
137 */ 137 */
138static int get_property(unsigned int cpu, unsigned long input, 138static int get_property(struct cpufreq_cooling_device *cpufreq_dev,
139 unsigned int *output, 139 unsigned long input, unsigned int *output,
140 enum cpufreq_cooling_property property) 140 enum cpufreq_cooling_property property)
141{ 141{
142 int i; 142 int i;
143 unsigned long max_level = 0, level = 0; 143 unsigned long level = 0;
144 unsigned int freq = CPUFREQ_ENTRY_INVALID; 144 unsigned int freq = CPUFREQ_ENTRY_INVALID;
145 int descend = -1; 145 int descend = -1;
146 struct cpufreq_frequency_table *pos, *table = 146 struct cpufreq_frequency_table *pos, *table;
147 cpufreq_frequency_get_table(cpu);
148 147
149 if (!output) 148 if (!output)
150 return -EINVAL; 149 return -EINVAL;
151 150
151 table = cpufreq_frequency_get_table(cpumask_first(&cpufreq_dev->allowed_cpus));
152 if (!table) 152 if (!table)
153 return -EINVAL; 153 return -EINVAL;
154 154
@@ -162,18 +162,10 @@ static int get_property(unsigned int cpu, unsigned long input,
162 descend = freq > pos->frequency; 162 descend = freq > pos->frequency;
163 163
164 freq = pos->frequency; 164 freq = pos->frequency;
165 max_level++;
166 } 165 }
167 166
168 /* No valid cpu frequency entry */
169 if (max_level == 0)
170 return -EINVAL;
171
172 /* max_level is an index, not a counter */
173 max_level--;
174
175 if (property == GET_FREQ) 167 if (property == GET_FREQ)
176 level = descend ? input : (max_level - input); 168 level = descend ? input : (cpufreq_dev->max_level - input);
177 169
178 i = 0; 170 i = 0;
179 cpufreq_for_each_valid_entry(pos, table) { 171 cpufreq_for_each_valid_entry(pos, table) {
@@ -186,7 +178,7 @@ static int get_property(unsigned int cpu, unsigned long input,
186 178
187 if (property == GET_LEVEL && (unsigned int)input == freq) { 179 if (property == GET_LEVEL && (unsigned int)input == freq) {
188 /* get level by frequency */ 180 /* get level by frequency */
189 *output = descend ? i : (max_level - i); 181 *output = descend ? i : (cpufreq_dev->max_level - i);
190 return 0; 182 return 0;
191 } 183 }
192 if (property == GET_FREQ && level == i) { 184 if (property == GET_FREQ && level == i) {
@@ -213,12 +205,25 @@ static int get_property(unsigned int cpu, unsigned long input,
213 */ 205 */
214unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) 206unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq)
215{ 207{
216 unsigned int val; 208 struct cpufreq_cooling_device *cpufreq_dev;
217 209
218 if (get_property(cpu, (unsigned long)freq, &val, GET_LEVEL)) 210 mutex_lock(&cooling_cpufreq_lock);
219 return THERMAL_CSTATE_INVALID; 211 list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) {
212 if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) {
213 unsigned int val;
214
215 mutex_unlock(&cooling_cpufreq_lock);
216 if (get_property(cpufreq_dev, (unsigned long)freq, &val,
217 GET_LEVEL))
218 return THERMAL_CSTATE_INVALID;
219
220 return (unsigned long)val;
221 }
222 }
223 mutex_unlock(&cooling_cpufreq_lock);
220 224
221 return (unsigned long)val; 225 pr_err("%s: cpu:%d not part of any cooling device\n", __func__, cpu);
226 return THERMAL_CSTATE_INVALID;
222} 227}
223EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level); 228EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level);
224 229
@@ -323,7 +328,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
323 if (cpufreq_device->cpufreq_state == state) 328 if (cpufreq_device->cpufreq_state == state)
324 return 0; 329 return 0;
325 330
326 ret = get_property(cpu, state, &clip_freq, GET_FREQ); 331 ret = get_property(cpufreq_device, state, &clip_freq, GET_FREQ);
327 if (ret) 332 if (ret)
328 return ret; 333 return ret;
329 334
@@ -381,8 +386,7 @@ __cpufreq_cooling_register(struct device_node *np,
381 if (!cpufreq_dev) 386 if (!cpufreq_dev)
382 return ERR_PTR(-ENOMEM); 387 return ERR_PTR(-ENOMEM);
383 388
384 ret = get_property(cpumask_any(clip_cpus), 0, &cpufreq_dev->cpufreq_val, 389 ret = get_property(cpufreq_dev, 0, &cpufreq_dev->cpufreq_val, GET_FREQ);
385 GET_FREQ);
386 if (ret) { 390 if (ret) {
387 pr_err("%s: Failed to get frequency: %d", __func__, ret); 391 pr_err("%s: Failed to get frequency: %d", __func__, ret);
388 cool_dev = ERR_PTR(ret); 392 cool_dev = ERR_PTR(ret);