diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/thermal/cpu_cooling.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index a294921be650..c94bf2e5de62 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c | |||
@@ -64,6 +64,11 @@ static struct cpufreq_cooling_device *notify_device; | |||
64 | * get_idr - function to get a unique id. | 64 | * get_idr - function to get a unique id. |
65 | * @idr: struct idr * handle used to create a id. | 65 | * @idr: struct idr * handle used to create a id. |
66 | * @id: int * value generated by this function. | 66 | * @id: int * value generated by this function. |
67 | * | ||
68 | * This function will populate @id with an unique | ||
69 | * id, using the idr API. | ||
70 | * | ||
71 | * Return: 0 on success, an error code on failure. | ||
67 | */ | 72 | */ |
68 | static int get_idr(struct idr *idr, int *id) | 73 | static int get_idr(struct idr *idr, int *id) |
69 | { | 74 | { |
@@ -75,6 +80,7 @@ static int get_idr(struct idr *idr, int *id) | |||
75 | if (unlikely(ret < 0)) | 80 | if (unlikely(ret < 0)) |
76 | return ret; | 81 | return ret; |
77 | *id = ret; | 82 | *id = ret; |
83 | |||
78 | return 0; | 84 | return 0; |
79 | } | 85 | } |
80 | 86 | ||
@@ -105,6 +111,7 @@ static void release_idr(struct idr *idr, int id) | |||
105 | static int is_cpufreq_valid(int cpu) | 111 | static int is_cpufreq_valid(int cpu) |
106 | { | 112 | { |
107 | struct cpufreq_policy policy; | 113 | struct cpufreq_policy policy; |
114 | |||
108 | return !cpufreq_get_policy(&policy, cpu); | 115 | return !cpufreq_get_policy(&policy, cpu); |
109 | } | 116 | } |
110 | 117 | ||
@@ -134,7 +141,8 @@ enum cpufreq_cooling_property { | |||
134 | * Return: 0 on success, -EINVAL when invalid parameters are passed. | 141 | * Return: 0 on success, -EINVAL when invalid parameters are passed. |
135 | */ | 142 | */ |
136 | static int get_property(unsigned int cpu, unsigned long input, | 143 | static int get_property(unsigned int cpu, unsigned long input, |
137 | unsigned int* output, enum cpufreq_cooling_property property) | 144 | unsigned int *output, |
145 | enum cpufreq_cooling_property property) | ||
138 | { | 146 | { |
139 | int i, j; | 147 | int i, j; |
140 | unsigned long max_level = 0, level = 0; | 148 | unsigned long max_level = 0, level = 0; |
@@ -142,14 +150,13 @@ static int get_property(unsigned int cpu, unsigned long input, | |||
142 | int descend = -1; | 150 | int descend = -1; |
143 | struct cpufreq_frequency_table *table = | 151 | struct cpufreq_frequency_table *table = |
144 | cpufreq_frequency_get_table(cpu); | 152 | cpufreq_frequency_get_table(cpu); |
145 | 153 | ||
146 | if (!output) | 154 | if (!output) |
147 | return -EINVAL; | 155 | return -EINVAL; |
148 | 156 | ||
149 | if (!table) | 157 | if (!table) |
150 | return -EINVAL; | 158 | return -EINVAL; |
151 | 159 | ||
152 | |||
153 | for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { | 160 | for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { |
154 | /* ignore invalid entries */ | 161 | /* ignore invalid entries */ |
155 | if (table[i].frequency == CPUFREQ_ENTRY_INVALID) | 162 | if (table[i].frequency == CPUFREQ_ENTRY_INVALID) |
@@ -174,8 +181,7 @@ static int get_property(unsigned int cpu, unsigned long input, | |||
174 | } | 181 | } |
175 | 182 | ||
176 | if (property == GET_FREQ) | 183 | if (property == GET_FREQ) |
177 | level = descend ? input : (max_level - input -1); | 184 | level = descend ? input : (max_level - input - 1); |
178 | |||
179 | 185 | ||
180 | for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { | 186 | for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { |
181 | /* ignore invalid entry */ | 187 | /* ignore invalid entry */ |
@@ -201,6 +207,7 @@ static int get_property(unsigned int cpu, unsigned long input, | |||
201 | } | 207 | } |
202 | j++; | 208 | j++; |
203 | } | 209 | } |
210 | |||
204 | return -EINVAL; | 211 | return -EINVAL; |
205 | } | 212 | } |
206 | 213 | ||
@@ -221,6 +228,7 @@ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) | |||
221 | 228 | ||
222 | if (get_property(cpu, (unsigned long)freq, &val, GET_LEVEL)) | 229 | if (get_property(cpu, (unsigned long)freq, &val, GET_LEVEL)) |
223 | return THERMAL_CSTATE_INVALID; | 230 | return THERMAL_CSTATE_INVALID; |
231 | |||
224 | return (unsigned long)val; | 232 | return (unsigned long)val; |
225 | } | 233 | } |
226 | EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level); | 234 | EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level); |
@@ -245,6 +253,7 @@ static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level) | |||
245 | ret = get_property(cpu, level, &freq, GET_FREQ); | 253 | ret = get_property(cpu, level, &freq, GET_FREQ); |
246 | if (ret) | 254 | if (ret) |
247 | return 0; | 255 | return 0; |
256 | |||
248 | return freq; | 257 | return freq; |
249 | } | 258 | } |
250 | 259 | ||
@@ -261,7 +270,7 @@ static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level) | |||
261 | * cooling state). | 270 | * cooling state). |
262 | */ | 271 | */ |
263 | static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device, | 272 | static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device, |
264 | unsigned long cooling_state) | 273 | unsigned long cooling_state) |
265 | { | 274 | { |
266 | unsigned int cpuid, clip_freq; | 275 | unsigned int cpuid, clip_freq; |
267 | struct cpumask *mask = &cpufreq_device->allowed_cpus; | 276 | struct cpumask *mask = &cpufreq_device->allowed_cpus; |
@@ -303,7 +312,7 @@ static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device, | |||
303 | * Return: 0 (success) | 312 | * Return: 0 (success) |
304 | */ | 313 | */ |
305 | static int cpufreq_thermal_notifier(struct notifier_block *nb, | 314 | static int cpufreq_thermal_notifier(struct notifier_block *nb, |
306 | unsigned long event, void *data) | 315 | unsigned long event, void *data) |
307 | { | 316 | { |
308 | struct cpufreq_policy *policy = data; | 317 | struct cpufreq_policy *policy = data; |
309 | unsigned long max_freq = 0; | 318 | unsigned long max_freq = 0; |
@@ -314,7 +323,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, | |||
314 | if (cpumask_test_cpu(policy->cpu, ¬ify_device->allowed_cpus)) | 323 | if (cpumask_test_cpu(policy->cpu, ¬ify_device->allowed_cpus)) |
315 | max_freq = notify_device->cpufreq_val; | 324 | max_freq = notify_device->cpufreq_val; |
316 | 325 | ||
317 | /* Never exceed user_policy.max*/ | 326 | /* Never exceed user_policy.max */ |
318 | if (max_freq > policy->user_policy.max) | 327 | if (max_freq > policy->user_policy.max) |
319 | max_freq = policy->user_policy.max; | 328 | max_freq = policy->user_policy.max; |
320 | 329 | ||
@@ -324,9 +333,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, | |||
324 | return 0; | 333 | return 0; |
325 | } | 334 | } |
326 | 335 | ||
327 | /* | 336 | /* cpufreq cooling device callback functions are defined below */ |
328 | * cpufreq cooling device callback functions are defined below | ||
329 | */ | ||
330 | 337 | ||
331 | /** | 338 | /** |
332 | * cpufreq_get_max_state - callback function to get the max cooling state. | 339 | * cpufreq_get_max_state - callback function to get the max cooling state. |
@@ -373,6 +380,7 @@ static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, | |||
373 | struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; | 380 | struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; |
374 | 381 | ||
375 | *state = cpufreq_device->cpufreq_state; | 382 | *state = cpufreq_device->cpufreq_state; |
383 | |||
376 | return 0; | 384 | return 0; |
377 | } | 385 | } |
378 | 386 | ||
@@ -417,8 +425,8 @@ static struct notifier_block thermal_cpufreq_notifier_block = { | |||
417 | * Return: a valid struct thermal_cooling_device pointer on success, | 425 | * Return: a valid struct thermal_cooling_device pointer on success, |
418 | * on failure, it returns a corresponding ERR_PTR(). | 426 | * on failure, it returns a corresponding ERR_PTR(). |
419 | */ | 427 | */ |
420 | struct thermal_cooling_device *cpufreq_cooling_register( | 428 | struct thermal_cooling_device * |
421 | const struct cpumask *clip_cpus) | 429 | cpufreq_cooling_register(const struct cpumask *clip_cpus) |
422 | { | 430 | { |
423 | struct thermal_cooling_device *cool_dev; | 431 | struct thermal_cooling_device *cool_dev; |
424 | struct cpufreq_cooling_device *cpufreq_dev = NULL; | 432 | struct cpufreq_cooling_device *cpufreq_dev = NULL; |
@@ -427,9 +435,9 @@ struct thermal_cooling_device *cpufreq_cooling_register( | |||
427 | int ret = 0, i; | 435 | int ret = 0, i; |
428 | struct cpufreq_policy policy; | 436 | struct cpufreq_policy policy; |
429 | 437 | ||
430 | /*Verify that all the clip cpus have same freq_min, freq_max limit*/ | 438 | /* Verify that all the clip cpus have same freq_min, freq_max limit */ |
431 | for_each_cpu(i, clip_cpus) { | 439 | for_each_cpu(i, clip_cpus) { |
432 | /*continue if cpufreq policy not found and not return error*/ | 440 | /* continue if cpufreq policy not found and not return error */ |
433 | if (!cpufreq_get_policy(&policy, i)) | 441 | if (!cpufreq_get_policy(&policy, i)) |
434 | continue; | 442 | continue; |
435 | if (min == 0 && max == 0) { | 443 | if (min == 0 && max == 0) { |
@@ -437,12 +445,12 @@ struct thermal_cooling_device *cpufreq_cooling_register( | |||
437 | max = policy.cpuinfo.max_freq; | 445 | max = policy.cpuinfo.max_freq; |
438 | } else { | 446 | } else { |
439 | if (min != policy.cpuinfo.min_freq || | 447 | if (min != policy.cpuinfo.min_freq || |
440 | max != policy.cpuinfo.max_freq) | 448 | max != policy.cpuinfo.max_freq) |
441 | return ERR_PTR(-EINVAL); | 449 | return ERR_PTR(-EINVAL); |
442 | } | 450 | } |
443 | } | 451 | } |
444 | cpufreq_dev = kzalloc(sizeof(struct cpufreq_cooling_device), | 452 | cpufreq_dev = kzalloc(sizeof(struct cpufreq_cooling_device), |
445 | GFP_KERNEL); | 453 | GFP_KERNEL); |
446 | if (!cpufreq_dev) | 454 | if (!cpufreq_dev) |
447 | return ERR_PTR(-ENOMEM); | 455 | return ERR_PTR(-ENOMEM); |
448 | 456 | ||
@@ -458,7 +466,7 @@ struct thermal_cooling_device *cpufreq_cooling_register( | |||
458 | cpufreq_dev->id); | 466 | cpufreq_dev->id); |
459 | 467 | ||
460 | cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev, | 468 | cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev, |
461 | &cpufreq_cooling_ops); | 469 | &cpufreq_cooling_ops); |
462 | if (!cool_dev) { | 470 | if (!cool_dev) { |
463 | release_idr(&cpufreq_idr, cpufreq_dev->id); | 471 | release_idr(&cpufreq_idr, cpufreq_dev->id); |
464 | kfree(cpufreq_dev); | 472 | kfree(cpufreq_dev); |
@@ -471,10 +479,11 @@ struct thermal_cooling_device *cpufreq_cooling_register( | |||
471 | /* Register the notifier for first cpufreq cooling device */ | 479 | /* Register the notifier for first cpufreq cooling device */ |
472 | if (cpufreq_dev_count == 0) | 480 | if (cpufreq_dev_count == 0) |
473 | cpufreq_register_notifier(&thermal_cpufreq_notifier_block, | 481 | cpufreq_register_notifier(&thermal_cpufreq_notifier_block, |
474 | CPUFREQ_POLICY_NOTIFIER); | 482 | CPUFREQ_POLICY_NOTIFIER); |
475 | cpufreq_dev_count++; | 483 | cpufreq_dev_count++; |
476 | 484 | ||
477 | mutex_unlock(&cooling_cpufreq_lock); | 485 | mutex_unlock(&cooling_cpufreq_lock); |
486 | |||
478 | return cool_dev; | 487 | return cool_dev; |
479 | } | 488 | } |
480 | EXPORT_SYMBOL_GPL(cpufreq_cooling_register); | 489 | EXPORT_SYMBOL_GPL(cpufreq_cooling_register); |
@@ -495,8 +504,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) | |||
495 | /* Unregister the notifier for the last cpufreq cooling device */ | 504 | /* Unregister the notifier for the last cpufreq cooling device */ |
496 | if (cpufreq_dev_count == 0) | 505 | if (cpufreq_dev_count == 0) |
497 | cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, | 506 | cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, |
498 | CPUFREQ_POLICY_NOTIFIER); | 507 | CPUFREQ_POLICY_NOTIFIER); |
499 | |||
500 | mutex_unlock(&cooling_cpufreq_lock); | 508 | mutex_unlock(&cooling_cpufreq_lock); |
501 | 509 | ||
502 | thermal_cooling_device_unregister(cpufreq_dev->cool_dev); | 510 | thermal_cooling_device_unregister(cpufreq_dev->cool_dev); |