23 #include <linux/kernel.h>
24 #include <linux/module.h>
29 #include <linux/slab.h>
62 static struct mutex cooling_cpufreq_lock;
65 #define NOTIFY_INVALID NULL
73 static int get_idr(
struct idr *
idr,
int *
id)
98 static void release_idr(
struct idr *
idr,
int id)
111 static int is_cpufreq_valid(
int cpu)
123 static unsigned int get_cpu_frequency(
unsigned int cpu,
unsigned long level)
126 unsigned long level_index;
127 bool descend =
false;
145 if (descend &&
i == level)
151 if (level >
i || descend)
160 if (
i == level_index)
174 unsigned long cooling_state)
176 unsigned int cpuid, clip_freq;
185 clip_freq = get_cpu_frequency(cpu, cooling_state);
191 notify_device = cpufreq_device;
194 if (is_cpufreq_valid(cpuid))
213 unsigned long max_freq = 0;
225 if (policy->
max != max_freq)
226 cpufreq_verify_within_limits(policy, 0, max_freq);
241 unsigned long *
state)
251 if (cpufreq_device && cpufreq_device->
cool_dev == cdev)
254 if (cpufreq_device ==
NULL)
255 goto return_get_max_state;
263 goto return_get_max_state;
276 return_get_max_state:
287 unsigned long *state)
294 if (cpufreq_device && cpufreq_device->
cool_dev == cdev) {
318 if (cpufreq_device && cpufreq_device->
cool_dev == cdev) {
324 ret = cpufreq_apply_cooling(cpufreq_device, state);
333 .get_max_state = cpufreq_get_max_state,
334 .get_cur_state = cpufreq_get_cur_state,
335 .set_cur_state = cpufreq_set_cur_state,
340 .notifier_call = cpufreq_thermal_notifier,
352 unsigned int cpufreq_dev_count = 0,
min = 0,
max = 0;
365 if (
min == 0 &&
max == 0) {
381 if (cpufreq_dev_count == 0)
384 ret = get_idr(&cpufreq_idr, &cpufreq_dev->
id);
390 sprintf(dev_name,
"thermal-cpufreq-%d", cpufreq_dev->
id);
393 &cpufreq_cooling_ops);
395 release_idr(&cpufreq_idr, cpufreq_dev->
id);
405 if (cpufreq_dev_count == 0)
421 unsigned int cpufreq_dev_count = 0;
425 if (cpufreq_dev && cpufreq_dev->
cool_dev == cdev)
430 if (!cpufreq_dev || cpufreq_dev->
cool_dev != cdev) {
438 if (cpufreq_dev_count == 1) {
444 release_idr(&cpufreq_idr, cpufreq_dev->
id);
445 if (cpufreq_dev_count == 1)