cb75f136561513d86958a46740430c27d93ac32c
[linux-2.6-microblaze.git] / drivers / thermal / cpufreq_cooling.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  linux/drivers/thermal/cpufreq_cooling.c
4  *
5  *  Copyright (C) 2012  Samsung Electronics Co., Ltd(http://www.samsung.com)
6  *
7  *  Copyright (C) 2012-2018 Linaro Limited.
8  *
9  *  Authors:    Amit Daniel <amit.kachhap@linaro.org>
10  *              Viresh Kumar <viresh.kumar@linaro.org>
11  *
12  */
13 #include <linux/cpu.h>
14 #include <linux/cpufreq.h>
15 #include <linux/cpu_cooling.h>
16 #include <linux/device.h>
17 #include <linux/energy_model.h>
18 #include <linux/err.h>
19 #include <linux/export.h>
20 #include <linux/pm_opp.h>
21 #include <linux/pm_qos.h>
22 #include <linux/slab.h>
23 #include <linux/thermal.h>
24 #include <linux/units.h>
25
26 #include <trace/events/thermal.h>
27
28 /*
29  * Cooling state <-> CPUFreq frequency
30  *
31  * Cooling states are translated to frequencies throughout this driver and this
32  * is the relation between them.
33  *
34  * Highest cooling state corresponds to lowest possible frequency.
35  *
36  * i.e.
37  *      level 0 --> 1st Max Freq
38  *      level 1 --> 2nd Max Freq
39  *      ...
40  */
41
42 /**
43  * struct time_in_idle - Idle time stats
44  * @time: previous reading of the absolute time that this cpu was idle
45  * @timestamp: wall time of the last invocation of get_cpu_idle_time_us()
46  */
47 struct time_in_idle {
48         u64 time;
49         u64 timestamp;
50 };
51
52 /**
53  * struct cpufreq_cooling_device - data for cooling device with cpufreq
54  * @last_load: load measured by the latest call to cpufreq_get_requested_power()
55  * @cpufreq_state: integer value representing the current state of cpufreq
56  *      cooling devices.
57  * @max_level: maximum cooling level. One less than total number of valid
58  *      cpufreq frequencies.
59  * @em: Reference on the Energy Model of the device
60  * @cdev: thermal_cooling_device pointer to keep track of the
61  *      registered cooling device.
62  * @policy: cpufreq policy.
63  * @idle_time: idle time stats
64  * @qos_req: PM QoS contraint to apply
65  *
66  * This structure is required for keeping information of each registered
67  * cpufreq_cooling_device.
68  */
69 struct cpufreq_cooling_device {
70         u32 last_load;
71         unsigned int cpufreq_state;
72         unsigned int max_level;
73         struct em_perf_domain *em;
74         struct cpufreq_policy *policy;
75 #ifndef CONFIG_SMP
76         struct time_in_idle *idle_time;
77 #endif
78         struct freq_qos_request qos_req;
79 };
80
81 #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
82 /**
83  * get_level: Find the level for a particular frequency
84  * @cpufreq_cdev: cpufreq_cdev for which the property is required
85  * @freq: Frequency
86  *
87  * Return: level corresponding to the frequency.
88  */
89 static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev,
90                                unsigned int freq)
91 {
92         int i;
93
94         for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) {
95                 if (freq > cpufreq_cdev->em->table[i].frequency)
96                         break;
97         }
98
99         return cpufreq_cdev->max_level - i - 1;
100 }
101
102 static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev,
103                              u32 freq)
104 {
105         unsigned long power_mw;
106         int i;
107
108         for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) {
109                 if (freq > cpufreq_cdev->em->table[i].frequency)
110                         break;
111         }
112
113         power_mw = cpufreq_cdev->em->table[i + 1].power;
114         power_mw /= MICROWATT_PER_MILLIWATT;
115
116         return power_mw;
117 }
118
119 static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev,
120                              u32 power)
121 {
122         unsigned long em_power_mw;
123         int i;
124
125         for (i = cpufreq_cdev->max_level; i > 0; i--) {
126                 /* Convert EM power to milli-Watts to make safe comparison */
127                 em_power_mw = cpufreq_cdev->em->table[i].power;
128                 em_power_mw /= MICROWATT_PER_MILLIWATT;
129                 if (power >= em_power_mw)
130                         break;
131         }
132
133         return cpufreq_cdev->em->table[i].frequency;
134 }
135
136 /**
137  * get_load() - get load for a cpu
138  * @cpufreq_cdev: struct cpufreq_cooling_device for the cpu
139  * @cpu: cpu number
140  * @cpu_idx: index of the cpu in time_in_idle array
141  *
142  * Return: The average load of cpu @cpu in percentage since this
143  * function was last called.
144  */
145 #ifdef CONFIG_SMP
146 static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu,
147                     int cpu_idx)
148 {
149         unsigned long util = sched_cpu_util(cpu);
150
151         return (util * 100) / arch_scale_cpu_capacity(cpu);
152 }
153 #else /* !CONFIG_SMP */
154 static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu,
155                     int cpu_idx)
156 {
157         u32 load;
158         u64 now, now_idle, delta_time, delta_idle;
159         struct time_in_idle *idle_time = &cpufreq_cdev->idle_time[cpu_idx];
160
161         now_idle = get_cpu_idle_time(cpu, &now, 0);
162         delta_idle = now_idle - idle_time->time;
163         delta_time = now - idle_time->timestamp;
164
165         if (delta_time <= delta_idle)
166                 load = 0;
167         else
168                 load = div64_u64(100 * (delta_time - delta_idle), delta_time);
169
170         idle_time->time = now_idle;
171         idle_time->timestamp = now;
172
173         return load;
174 }
175 #endif /* CONFIG_SMP */
176
177 /**
178  * get_dynamic_power() - calculate the dynamic power
179  * @cpufreq_cdev:       &cpufreq_cooling_device for this cdev
180  * @freq:       current frequency
181  *
182  * Return: the dynamic power consumed by the cpus described by
183  * @cpufreq_cdev.
184  */
185 static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev,
186                              unsigned long freq)
187 {
188         u32 raw_cpu_power;
189
190         raw_cpu_power = cpu_freq_to_power(cpufreq_cdev, freq);
191         return (raw_cpu_power * cpufreq_cdev->last_load) / 100;
192 }
193
194 /**
195  * cpufreq_get_requested_power() - get the current power
196  * @cdev:       &thermal_cooling_device pointer
197  * @power:      pointer in which to store the resulting power
198  *
199  * Calculate the current power consumption of the cpus in milliwatts
200  * and store it in @power.  This function should actually calculate
201  * the requested power, but it's hard to get the frequency that
202  * cpufreq would have assigned if there were no thermal limits.
203  * Instead, we calculate the current power on the assumption that the
204  * immediate future will look like the immediate past.
205  *
206  * We use the current frequency and the average load since this
207  * function was last called.  In reality, there could have been
208  * multiple opps since this function was last called and that affects
209  * the load calculation.  While it's not perfectly accurate, this
210  * simplification is good enough and works.  REVISIT this, as more
211  * complex code may be needed if experiments show that it's not
212  * accurate enough.
213  *
214  * Return: 0 on success, -E* if getting the static power failed.
215  */
216 static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
217                                        u32 *power)
218 {
219         unsigned long freq;
220         int i = 0, cpu;
221         u32 total_load = 0;
222         struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
223         struct cpufreq_policy *policy = cpufreq_cdev->policy;
224         u32 *load_cpu = NULL;
225
226         freq = cpufreq_quick_get(policy->cpu);
227
228         if (trace_thermal_power_cpu_get_power_enabled()) {
229                 u32 ncpus = cpumask_weight(policy->related_cpus);
230
231                 load_cpu = kcalloc(ncpus, sizeof(*load_cpu), GFP_KERNEL);
232         }
233
234         for_each_cpu(cpu, policy->related_cpus) {
235                 u32 load;
236
237                 if (cpu_online(cpu))
238                         load = get_load(cpufreq_cdev, cpu, i);
239                 else
240                         load = 0;
241
242                 total_load += load;
243                 if (load_cpu)
244                         load_cpu[i] = load;
245
246                 i++;
247         }
248
249         cpufreq_cdev->last_load = total_load;
250
251         *power = get_dynamic_power(cpufreq_cdev, freq);
252
253         if (load_cpu) {
254                 trace_thermal_power_cpu_get_power(policy->related_cpus, freq,
255                                                   load_cpu, i, *power);
256
257                 kfree(load_cpu);
258         }
259
260         return 0;
261 }
262
263 /**
264  * cpufreq_state2power() - convert a cpu cdev state to power consumed
265  * @cdev:       &thermal_cooling_device pointer
266  * @state:      cooling device state to be converted
267  * @power:      pointer in which to store the resulting power
268  *
269  * Convert cooling device state @state into power consumption in
270  * milliwatts assuming 100% load.  Store the calculated power in
271  * @power.
272  *
273  * Return: 0 on success, -EINVAL if the cooling device state could not
274  * be converted into a frequency or other -E* if there was an error
275  * when calculating the static power.
276  */
277 static int cpufreq_state2power(struct thermal_cooling_device *cdev,
278                                unsigned long state, u32 *power)
279 {
280         unsigned int freq, num_cpus, idx;
281         struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
282
283         /* Request state should be less than max_level */
284         if (state > cpufreq_cdev->max_level)
285                 return -EINVAL;
286
287         num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus);
288
289         idx = cpufreq_cdev->max_level - state;
290         freq = cpufreq_cdev->em->table[idx].frequency;
291         *power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus;
292
293         return 0;
294 }
295
296 /**
297  * cpufreq_power2state() - convert power to a cooling device state
298  * @cdev:       &thermal_cooling_device pointer
299  * @power:      power in milliwatts to be converted
300  * @state:      pointer in which to store the resulting state
301  *
302  * Calculate a cooling device state for the cpus described by @cdev
303  * that would allow them to consume at most @power mW and store it in
304  * @state.  Note that this calculation depends on external factors
305  * such as the cpu load or the current static power.  Calling this
306  * function with the same power as input can yield different cooling
307  * device states depending on those external factors.
308  *
309  * Return: 0 on success, -ENODEV if no cpus are online or -EINVAL if
310  * the calculated frequency could not be converted to a valid state.
311  * The latter should not happen unless the frequencies available to
312  * cpufreq have changed since the initialization of the cpu cooling
313  * device.
314  */
315 static int cpufreq_power2state(struct thermal_cooling_device *cdev,
316                                u32 power, unsigned long *state)
317 {
318         unsigned int target_freq;
319         u32 last_load, normalised_power;
320         struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
321         struct cpufreq_policy *policy = cpufreq_cdev->policy;
322
323         last_load = cpufreq_cdev->last_load ?: 1;
324         normalised_power = (power * 100) / last_load;
325         target_freq = cpu_power_to_freq(cpufreq_cdev, normalised_power);
326
327         *state = get_level(cpufreq_cdev, target_freq);
328         trace_thermal_power_cpu_limit(policy->related_cpus, target_freq, *state,
329                                       power);
330         return 0;
331 }
332
333 static inline bool em_is_sane(struct cpufreq_cooling_device *cpufreq_cdev,
334                               struct em_perf_domain *em) {
335         struct cpufreq_policy *policy;
336         unsigned int nr_levels;
337
338         if (!em || em_is_artificial(em))
339                 return false;
340
341         policy = cpufreq_cdev->policy;
342         if (!cpumask_equal(policy->related_cpus, em_span_cpus(em))) {
343                 pr_err("The span of pd %*pbl is misaligned with cpufreq policy %*pbl\n",
344                         cpumask_pr_args(em_span_cpus(em)),
345                         cpumask_pr_args(policy->related_cpus));
346                 return false;
347         }
348
349         nr_levels = cpufreq_cdev->max_level + 1;
350         if (em_pd_nr_perf_states(em) != nr_levels) {
351                 pr_err("The number of performance states in pd %*pbl (%u) doesn't match the number of cooling levels (%u)\n",
352                         cpumask_pr_args(em_span_cpus(em)),
353                         em_pd_nr_perf_states(em), nr_levels);
354                 return false;
355         }
356
357         return true;
358 }
359 #endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */
360
361 #ifdef CONFIG_SMP
362 static inline int allocate_idle_time(struct cpufreq_cooling_device *cpufreq_cdev)
363 {
364         return 0;
365 }
366
367 static inline void free_idle_time(struct cpufreq_cooling_device *cpufreq_cdev)
368 {
369 }
370 #else
371 static int allocate_idle_time(struct cpufreq_cooling_device *cpufreq_cdev)
372 {
373         unsigned int num_cpus = cpumask_weight(cpufreq_cdev->policy->related_cpus);
374
375         cpufreq_cdev->idle_time = kcalloc(num_cpus,
376                                           sizeof(*cpufreq_cdev->idle_time),
377                                           GFP_KERNEL);
378         if (!cpufreq_cdev->idle_time)
379                 return -ENOMEM;
380
381         return 0;
382 }
383
384 static void free_idle_time(struct cpufreq_cooling_device *cpufreq_cdev)
385 {
386         kfree(cpufreq_cdev->idle_time);
387         cpufreq_cdev->idle_time = NULL;
388 }
389 #endif /* CONFIG_SMP */
390
391 static unsigned int get_state_freq(struct cpufreq_cooling_device *cpufreq_cdev,
392                                    unsigned long state)
393 {
394         struct cpufreq_policy *policy;
395         unsigned long idx;
396
397 #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
398         /* Use the Energy Model table if available */
399         if (cpufreq_cdev->em) {
400                 idx = cpufreq_cdev->max_level - state;
401                 return cpufreq_cdev->em->table[idx].frequency;
402         }
403 #endif
404
405         /* Otherwise, fallback on the CPUFreq table */
406         policy = cpufreq_cdev->policy;
407         if (policy->freq_table_sorted == CPUFREQ_TABLE_SORTED_ASCENDING)
408                 idx = cpufreq_cdev->max_level - state;
409         else
410                 idx = state;
411
412         return policy->freq_table[idx].frequency;
413 }
414
415 /* cpufreq cooling device callback functions are defined below */
416
417 /**
418  * cpufreq_get_max_state - callback function to get the max cooling state.
419  * @cdev: thermal cooling device pointer.
420  * @state: fill this variable with the max cooling state.
421  *
422  * Callback for the thermal cooling device to return the cpufreq
423  * max cooling state.
424  *
425  * Return: 0 on success, an error code otherwise.
426  */
427 static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
428                                  unsigned long *state)
429 {
430         struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
431
432         *state = cpufreq_cdev->max_level;
433         return 0;
434 }
435
436 /**
437  * cpufreq_get_cur_state - callback function to get the current cooling state.
438  * @cdev: thermal cooling device pointer.
439  * @state: fill this variable with the current cooling state.
440  *
441  * Callback for the thermal cooling device to return the cpufreq
442  * current cooling state.
443  *
444  * Return: 0 on success, an error code otherwise.
445  */
446 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
447                                  unsigned long *state)
448 {
449         struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
450
451         *state = cpufreq_cdev->cpufreq_state;
452
453         return 0;
454 }
455
456 /**
457  * cpufreq_set_cur_state - callback function to set the current cooling state.
458  * @cdev: thermal cooling device pointer.
459  * @state: set this variable to the current cooling state.
460  *
461  * Callback for the thermal cooling device to change the cpufreq
462  * current cooling state.
463  *
464  * Return: 0 on success, an error code otherwise.
465  */
466 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
467                                  unsigned long state)
468 {
469         struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
470         struct cpumask *cpus;
471         unsigned int frequency;
472         int ret;
473
474         /* Request state should be less than max_level */
475         if (state > cpufreq_cdev->max_level)
476                 return -EINVAL;
477
478         /* Check if the old cooling action is same as new cooling action */
479         if (cpufreq_cdev->cpufreq_state == state)
480                 return 0;
481
482         frequency = get_state_freq(cpufreq_cdev, state);
483
484         ret = freq_qos_update_request(&cpufreq_cdev->qos_req, frequency);
485         if (ret >= 0) {
486                 cpufreq_cdev->cpufreq_state = state;
487                 cpus = cpufreq_cdev->policy->related_cpus;
488                 arch_update_thermal_pressure(cpus, frequency);
489                 ret = 0;
490         }
491
492         return ret;
493 }
494
495 /* Bind cpufreq callbacks to thermal cooling device ops */
496
497 static struct thermal_cooling_device_ops cpufreq_cooling_ops = {
498         .get_max_state          = cpufreq_get_max_state,
499         .get_cur_state          = cpufreq_get_cur_state,
500         .set_cur_state          = cpufreq_set_cur_state,
501 };
502
503 /**
504  * __cpufreq_cooling_register - helper function to create cpufreq cooling device
505  * @np: a valid struct device_node to the cooling device device tree node
506  * @policy: cpufreq policy
507  * Normally this should be same as cpufreq policy->related_cpus.
508  * @em: Energy Model of the cpufreq policy
509  *
510  * This interface function registers the cpufreq cooling device with the name
511  * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
512  * cooling devices. It also gives the opportunity to link the cooling device
513  * with a device tree node, in order to bind it via the thermal DT code.
514  *
515  * Return: a valid struct thermal_cooling_device pointer on success,
516  * on failure, it returns a corresponding ERR_PTR().
517  */
518 static struct thermal_cooling_device *
519 __cpufreq_cooling_register(struct device_node *np,
520                         struct cpufreq_policy *policy,
521                         struct em_perf_domain *em)
522 {
523         struct thermal_cooling_device *cdev;
524         struct cpufreq_cooling_device *cpufreq_cdev;
525         unsigned int i;
526         struct device *dev;
527         int ret;
528         struct thermal_cooling_device_ops *cooling_ops;
529         char *name;
530
531         dev = get_cpu_device(policy->cpu);
532         if (unlikely(!dev)) {
533                 pr_warn("No cpu device for cpu %d\n", policy->cpu);
534                 return ERR_PTR(-ENODEV);
535         }
536
537         if (IS_ERR_OR_NULL(policy)) {
538                 pr_err("%s: cpufreq policy isn't valid: %p\n", __func__, policy);
539                 return ERR_PTR(-EINVAL);
540         }
541
542         i = cpufreq_table_count_valid_entries(policy);
543         if (!i) {
544                 pr_debug("%s: CPUFreq table not found or has no valid entries\n",
545                          __func__);
546                 return ERR_PTR(-ENODEV);
547         }
548
549         cpufreq_cdev = kzalloc(sizeof(*cpufreq_cdev), GFP_KERNEL);
550         if (!cpufreq_cdev)
551                 return ERR_PTR(-ENOMEM);
552
553         cpufreq_cdev->policy = policy;
554
555         ret = allocate_idle_time(cpufreq_cdev);
556         if (ret) {
557                 cdev = ERR_PTR(ret);
558                 goto free_cdev;
559         }
560
561         /* max_level is an index, not a counter */
562         cpufreq_cdev->max_level = i - 1;
563
564         cooling_ops = &cpufreq_cooling_ops;
565
566 #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
567         if (em_is_sane(cpufreq_cdev, em)) {
568                 cpufreq_cdev->em = em;
569                 cooling_ops->get_requested_power = cpufreq_get_requested_power;
570                 cooling_ops->state2power = cpufreq_state2power;
571                 cooling_ops->power2state = cpufreq_power2state;
572         } else
573 #endif
574         if (policy->freq_table_sorted == CPUFREQ_TABLE_UNSORTED) {
575                 pr_err("%s: unsorted frequency tables are not supported\n",
576                        __func__);
577                 cdev = ERR_PTR(-EINVAL);
578                 goto free_idle_time;
579         }
580
581         ret = freq_qos_add_request(&policy->constraints,
582                                    &cpufreq_cdev->qos_req, FREQ_QOS_MAX,
583                                    get_state_freq(cpufreq_cdev, 0));
584         if (ret < 0) {
585                 pr_err("%s: Failed to add freq constraint (%d)\n", __func__,
586                        ret);
587                 cdev = ERR_PTR(ret);
588                 goto free_idle_time;
589         }
590
591         cdev = ERR_PTR(-ENOMEM);
592         name = kasprintf(GFP_KERNEL, "cpufreq-%s", dev_name(dev));
593         if (!name)
594                 goto remove_qos_req;
595
596         cdev = thermal_of_cooling_device_register(np, name, cpufreq_cdev,
597                                                   cooling_ops);
598         kfree(name);
599
600         if (IS_ERR(cdev))
601                 goto remove_qos_req;
602
603         return cdev;
604
605 remove_qos_req:
606         freq_qos_remove_request(&cpufreq_cdev->qos_req);
607 free_idle_time:
608         free_idle_time(cpufreq_cdev);
609 free_cdev:
610         kfree(cpufreq_cdev);
611         return cdev;
612 }
613
614 /**
615  * cpufreq_cooling_register - function to create cpufreq cooling device.
616  * @policy: cpufreq policy
617  *
618  * This interface function registers the cpufreq cooling device with the name
619  * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
620  * cooling devices.
621  *
622  * Return: a valid struct thermal_cooling_device pointer on success,
623  * on failure, it returns a corresponding ERR_PTR().
624  */
625 struct thermal_cooling_device *
626 cpufreq_cooling_register(struct cpufreq_policy *policy)
627 {
628         return __cpufreq_cooling_register(NULL, policy, NULL);
629 }
630 EXPORT_SYMBOL_GPL(cpufreq_cooling_register);
631
632 /**
633  * of_cpufreq_cooling_register - function to create cpufreq cooling device.
634  * @policy: cpufreq policy
635  *
636  * This interface function registers the cpufreq cooling device with the name
637  * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
638  * cooling devices. Using this API, the cpufreq cooling device will be
639  * linked to the device tree node provided.
640  *
641  * Using this function, the cooling device will implement the power
642  * extensions by using a simple cpu power model.  The cpus must have
643  * registered their OPPs using the OPP library.
644  *
645  * It also takes into account, if property present in policy CPU node, the
646  * static power consumed by the cpu.
647  *
648  * Return: a valid struct thermal_cooling_device pointer on success,
649  * and NULL on failure.
650  */
651 struct thermal_cooling_device *
652 of_cpufreq_cooling_register(struct cpufreq_policy *policy)
653 {
654         struct device_node *np = of_get_cpu_node(policy->cpu, NULL);
655         struct thermal_cooling_device *cdev = NULL;
656
657         if (!np) {
658                 pr_err("cpufreq_cooling: OF node not available for cpu%d\n",
659                        policy->cpu);
660                 return NULL;
661         }
662
663         if (of_find_property(np, "#cooling-cells", NULL)) {
664                 struct em_perf_domain *em = em_cpu_get(policy->cpu);
665
666                 cdev = __cpufreq_cooling_register(np, policy, em);
667                 if (IS_ERR(cdev)) {
668                         pr_err("cpufreq_cooling: cpu%d failed to register as cooling device: %ld\n",
669                                policy->cpu, PTR_ERR(cdev));
670                         cdev = NULL;
671                 }
672         }
673
674         of_node_put(np);
675         return cdev;
676 }
677 EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register);
678
679 /**
680  * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
681  * @cdev: thermal cooling device pointer.
682  *
683  * This interface function unregisters the "thermal-cpufreq-%x" cooling device.
684  */
685 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
686 {
687         struct cpufreq_cooling_device *cpufreq_cdev;
688
689         if (!cdev)
690                 return;
691
692         cpufreq_cdev = cdev->devdata;
693
694         thermal_cooling_device_unregister(cdev);
695         freq_qos_remove_request(&cpufreq_cdev->qos_req);
696         free_idle_time(cpufreq_cdev);
697         kfree(cpufreq_cdev);
698 }
699 EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister);