2 * thermal.c - Generic Thermal Management Sysfs support.
4 * Copyright (C) 2008 Intel Corp
5 * Copyright (C) 2008 Zhang Rui <rui.zhang@intel.com>
6 * Copyright (C) 2008 Sujith Thomas <sujith.thomas@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/module.h>
29 #include <linux/device.h>
30 #include <linux/err.h>
31 #include <linux/slab.h>
32 #include <linux/kdev_t.h>
33 #include <linux/idr.h>
34 #include <linux/thermal.h>
35 #include <linux/reboot.h>
36 #include <linux/string.h>
37 #include <net/netlink.h>
38 #include <net/genetlink.h>
40 #include "thermal_core.h"
41 #include "thermal_hwmon.h"
43 MODULE_AUTHOR("Zhang Rui");
44 MODULE_DESCRIPTION("Generic thermal management sysfs support");
45 MODULE_LICENSE("GPL v2");
47 static DEFINE_IDR(thermal_tz_idr);
48 static DEFINE_IDR(thermal_cdev_idr);
49 static DEFINE_MUTEX(thermal_idr_lock);
51 static LIST_HEAD(thermal_tz_list);
52 static LIST_HEAD(thermal_cdev_list);
53 static LIST_HEAD(thermal_governor_list);
55 static DEFINE_MUTEX(thermal_list_lock);
56 static DEFINE_MUTEX(thermal_governor_lock);
58 static struct thermal_governor *__find_governor(const char *name)
60 struct thermal_governor *pos;
62 list_for_each_entry(pos, &thermal_governor_list, governor_list)
63 if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
69 int thermal_register_governor(struct thermal_governor *governor)
73 struct thermal_zone_device *pos;
78 mutex_lock(&thermal_governor_lock);
81 if (__find_governor(governor->name) == NULL) {
83 list_add(&governor->governor_list, &thermal_governor_list);
86 mutex_lock(&thermal_list_lock);
88 list_for_each_entry(pos, &thermal_tz_list, node) {
92 name = pos->tzp->governor_name;
94 name = DEFAULT_THERMAL_GOVERNOR;
95 if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
96 pos->governor = governor;
99 mutex_unlock(&thermal_list_lock);
100 mutex_unlock(&thermal_governor_lock);
105 void thermal_unregister_governor(struct thermal_governor *governor)
107 struct thermal_zone_device *pos;
112 mutex_lock(&thermal_governor_lock);
114 if (__find_governor(governor->name) == NULL)
117 mutex_lock(&thermal_list_lock);
119 list_for_each_entry(pos, &thermal_tz_list, node) {
120 if (!strnicmp(pos->governor->name, governor->name,
121 THERMAL_NAME_LENGTH))
122 pos->governor = NULL;
125 mutex_unlock(&thermal_list_lock);
126 list_del(&governor->governor_list);
128 mutex_unlock(&thermal_governor_lock);
132 static int get_idr(struct idr *idr, struct mutex *lock, int *id)
138 ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
141 if (unlikely(ret < 0))
147 static void release_idr(struct idr *idr, struct mutex *lock, int id)
156 int get_tz_trend(struct thermal_zone_device *tz, int trip)
158 enum thermal_trend trend;
160 if (tz->emul_temperature || !tz->ops->get_trend ||
161 tz->ops->get_trend(tz, trip, &trend)) {
162 if (tz->temperature > tz->last_temperature)
163 trend = THERMAL_TREND_RAISING;
164 else if (tz->temperature < tz->last_temperature)
165 trend = THERMAL_TREND_DROPPING;
167 trend = THERMAL_TREND_STABLE;
172 EXPORT_SYMBOL(get_tz_trend);
174 struct thermal_instance *get_thermal_instance(struct thermal_zone_device *tz,
175 struct thermal_cooling_device *cdev, int trip)
177 struct thermal_instance *pos = NULL;
178 struct thermal_instance *target_instance = NULL;
180 mutex_lock(&tz->lock);
181 mutex_lock(&cdev->lock);
183 list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
184 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
185 target_instance = pos;
190 mutex_unlock(&cdev->lock);
191 mutex_unlock(&tz->lock);
193 return target_instance;
195 EXPORT_SYMBOL(get_thermal_instance);
197 static void print_bind_err_msg(struct thermal_zone_device *tz,
198 struct thermal_cooling_device *cdev, int ret)
200 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n",
201 tz->type, cdev->type, ret);
204 static void __bind(struct thermal_zone_device *tz, int mask,
205 struct thermal_cooling_device *cdev,
206 unsigned long *limits)
210 for (i = 0; i < tz->trips; i++) {
211 if (mask & (1 << i)) {
212 unsigned long upper, lower;
214 upper = THERMAL_NO_LIMIT;
215 lower = THERMAL_NO_LIMIT;
217 lower = limits[i * 2];
218 upper = limits[i * 2 + 1];
220 ret = thermal_zone_bind_cooling_device(tz, i, cdev,
223 print_bind_err_msg(tz, cdev, ret);
228 static void __unbind(struct thermal_zone_device *tz, int mask,
229 struct thermal_cooling_device *cdev)
233 for (i = 0; i < tz->trips; i++)
235 thermal_zone_unbind_cooling_device(tz, i, cdev);
238 static void bind_cdev(struct thermal_cooling_device *cdev)
241 const struct thermal_zone_params *tzp;
242 struct thermal_zone_device *pos = NULL;
244 mutex_lock(&thermal_list_lock);
246 list_for_each_entry(pos, &thermal_tz_list, node) {
247 if (!pos->tzp && !pos->ops->bind)
250 if (pos->ops->bind) {
251 ret = pos->ops->bind(pos, cdev);
253 print_bind_err_msg(pos, cdev, ret);
258 if (!tzp || !tzp->tbp)
261 for (i = 0; i < tzp->num_tbps; i++) {
262 if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
264 if (tzp->tbp[i].match(pos, cdev))
266 tzp->tbp[i].cdev = cdev;
267 __bind(pos, tzp->tbp[i].trip_mask, cdev,
268 tzp->tbp[i].binding_limits);
272 mutex_unlock(&thermal_list_lock);
275 static void bind_tz(struct thermal_zone_device *tz)
278 struct thermal_cooling_device *pos = NULL;
279 const struct thermal_zone_params *tzp = tz->tzp;
281 if (!tzp && !tz->ops->bind)
284 mutex_lock(&thermal_list_lock);
286 /* If there is ops->bind, try to use ops->bind */
288 list_for_each_entry(pos, &thermal_cdev_list, node) {
289 ret = tz->ops->bind(tz, pos);
291 print_bind_err_msg(tz, pos, ret);
296 if (!tzp || !tzp->tbp)
299 list_for_each_entry(pos, &thermal_cdev_list, node) {
300 for (i = 0; i < tzp->num_tbps; i++) {
301 if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
303 if (tzp->tbp[i].match(tz, pos))
305 tzp->tbp[i].cdev = pos;
306 __bind(tz, tzp->tbp[i].trip_mask, pos,
307 tzp->tbp[i].binding_limits);
311 mutex_unlock(&thermal_list_lock);
314 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
318 mod_delayed_work(system_freezable_wq, &tz->poll_queue,
319 round_jiffies(msecs_to_jiffies(delay)));
321 mod_delayed_work(system_freezable_wq, &tz->poll_queue,
322 msecs_to_jiffies(delay));
324 cancel_delayed_work(&tz->poll_queue);
327 static void monitor_thermal_zone(struct thermal_zone_device *tz)
329 mutex_lock(&tz->lock);
332 thermal_zone_device_set_polling(tz, tz->passive_delay);
333 else if (tz->polling_delay)
334 thermal_zone_device_set_polling(tz, tz->polling_delay);
336 thermal_zone_device_set_polling(tz, 0);
338 mutex_unlock(&tz->lock);
341 static void handle_non_critical_trips(struct thermal_zone_device *tz,
342 int trip, enum thermal_trip_type trip_type)
345 tz->governor->throttle(tz, trip);
348 static void handle_critical_trips(struct thermal_zone_device *tz,
349 int trip, enum thermal_trip_type trip_type)
353 tz->ops->get_trip_temp(tz, trip, &trip_temp);
355 /* If we have not crossed the trip_temp, we do not care. */
356 if (tz->temperature < trip_temp)
360 tz->ops->notify(tz, trip, trip_type);
362 if (trip_type == THERMAL_TRIP_CRITICAL) {
363 dev_emerg(&tz->device,
364 "critical temperature reached(%d C),shutting down\n",
365 tz->temperature / 1000);
366 orderly_poweroff(true);
370 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
372 enum thermal_trip_type type;
374 tz->ops->get_trip_type(tz, trip, &type);
376 if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT)
377 handle_critical_trips(tz, trip, type);
379 handle_non_critical_trips(tz, trip, type);
381 * Alright, we handled this trip successfully.
382 * So, start monitoring again.
384 monitor_thermal_zone(tz);
388 * thermal_zone_get_temp() - returns its the temperature of thermal zone
389 * @tz: a valid pointer to a struct thermal_zone_device
390 * @temp: a valid pointer to where to store the resulting temperature.
392 * When a valid thermal zone reference is passed, it will fetch its
393 * temperature and fill @temp.
395 * Return: On success returns 0, an error code otherwise
397 int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
400 #ifdef CONFIG_THERMAL_EMULATION
402 unsigned long crit_temp = -1UL;
403 enum thermal_trip_type type;
406 if (!tz || IS_ERR(tz))
409 mutex_lock(&tz->lock);
411 ret = tz->ops->get_temp(tz, temp);
412 #ifdef CONFIG_THERMAL_EMULATION
413 if (!tz->emul_temperature)
416 for (count = 0; count < tz->trips; count++) {
417 ret = tz->ops->get_trip_type(tz, count, &type);
418 if (!ret && type == THERMAL_TRIP_CRITICAL) {
419 ret = tz->ops->get_trip_temp(tz, count, &crit_temp);
427 if (*temp < crit_temp)
428 *temp = tz->emul_temperature;
431 mutex_unlock(&tz->lock);
435 EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
437 static void update_temperature(struct thermal_zone_device *tz)
442 ret = thermal_zone_get_temp(tz, &temp);
444 dev_warn(&tz->device, "failed to read out thermal zone %d\n",
449 mutex_lock(&tz->lock);
450 tz->last_temperature = tz->temperature;
451 tz->temperature = temp;
452 mutex_unlock(&tz->lock);
454 dev_dbg(&tz->device, "last_temperature=%d, current_temperature=%d\n",
455 tz->last_temperature, tz->temperature);
458 void thermal_zone_device_update(struct thermal_zone_device *tz)
462 update_temperature(tz);
464 for (count = 0; count < tz->trips; count++)
465 handle_thermal_trip(tz, count);
467 EXPORT_SYMBOL_GPL(thermal_zone_device_update);
469 static void thermal_zone_device_check(struct work_struct *work)
471 struct thermal_zone_device *tz = container_of(work, struct
474 thermal_zone_device_update(tz);
477 /* sys I/F for thermal zone */
479 #define to_thermal_zone(_dev) \
480 container_of(_dev, struct thermal_zone_device, device)
483 type_show(struct device *dev, struct device_attribute *attr, char *buf)
485 struct thermal_zone_device *tz = to_thermal_zone(dev);
487 return sprintf(buf, "%s\n", tz->type);
491 temp_show(struct device *dev, struct device_attribute *attr, char *buf)
493 struct thermal_zone_device *tz = to_thermal_zone(dev);
497 ret = thermal_zone_get_temp(tz, &temperature);
502 return sprintf(buf, "%ld\n", temperature);
506 mode_show(struct device *dev, struct device_attribute *attr, char *buf)
508 struct thermal_zone_device *tz = to_thermal_zone(dev);
509 enum thermal_device_mode mode;
512 if (!tz->ops->get_mode)
515 result = tz->ops->get_mode(tz, &mode);
519 return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled"
524 mode_store(struct device *dev, struct device_attribute *attr,
525 const char *buf, size_t count)
527 struct thermal_zone_device *tz = to_thermal_zone(dev);
530 if (!tz->ops->set_mode)
533 if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
534 result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
535 else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
536 result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
547 trip_point_type_show(struct device *dev, struct device_attribute *attr,
550 struct thermal_zone_device *tz = to_thermal_zone(dev);
551 enum thermal_trip_type type;
554 if (!tz->ops->get_trip_type)
557 if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip))
560 result = tz->ops->get_trip_type(tz, trip, &type);
565 case THERMAL_TRIP_CRITICAL:
566 return sprintf(buf, "critical\n");
567 case THERMAL_TRIP_HOT:
568 return sprintf(buf, "hot\n");
569 case THERMAL_TRIP_PASSIVE:
570 return sprintf(buf, "passive\n");
571 case THERMAL_TRIP_ACTIVE:
572 return sprintf(buf, "active\n");
574 return sprintf(buf, "unknown\n");
579 trip_point_temp_store(struct device *dev, struct device_attribute *attr,
580 const char *buf, size_t count)
582 struct thermal_zone_device *tz = to_thermal_zone(dev);
584 unsigned long temperature;
586 if (!tz->ops->set_trip_temp)
589 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
592 if (kstrtoul(buf, 10, &temperature))
595 ret = tz->ops->set_trip_temp(tz, trip, temperature);
597 return ret ? ret : count;
601 trip_point_temp_show(struct device *dev, struct device_attribute *attr,
604 struct thermal_zone_device *tz = to_thermal_zone(dev);
608 if (!tz->ops->get_trip_temp)
611 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
614 ret = tz->ops->get_trip_temp(tz, trip, &temperature);
619 return sprintf(buf, "%ld\n", temperature);
623 trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
624 const char *buf, size_t count)
626 struct thermal_zone_device *tz = to_thermal_zone(dev);
628 unsigned long temperature;
630 if (!tz->ops->set_trip_hyst)
633 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
636 if (kstrtoul(buf, 10, &temperature))
640 * We are not doing any check on the 'temperature' value
641 * here. The driver implementing 'set_trip_hyst' has to
644 ret = tz->ops->set_trip_hyst(tz, trip, temperature);
646 return ret ? ret : count;
650 trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
653 struct thermal_zone_device *tz = to_thermal_zone(dev);
655 unsigned long temperature;
657 if (!tz->ops->get_trip_hyst)
660 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
663 ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
665 return ret ? ret : sprintf(buf, "%ld\n", temperature);
669 passive_store(struct device *dev, struct device_attribute *attr,
670 const char *buf, size_t count)
672 struct thermal_zone_device *tz = to_thermal_zone(dev);
673 struct thermal_cooling_device *cdev = NULL;
676 if (!sscanf(buf, "%d\n", &state))
679 /* sanity check: values below 1000 millicelcius don't make sense
680 * and can cause the system to go into a thermal heart attack
682 if (state && state < 1000)
685 if (state && !tz->forced_passive) {
686 mutex_lock(&thermal_list_lock);
687 list_for_each_entry(cdev, &thermal_cdev_list, node) {
688 if (!strncmp("Processor", cdev->type,
689 sizeof("Processor")))
690 thermal_zone_bind_cooling_device(tz,
691 THERMAL_TRIPS_NONE, cdev,
695 mutex_unlock(&thermal_list_lock);
696 if (!tz->passive_delay)
697 tz->passive_delay = 1000;
698 } else if (!state && tz->forced_passive) {
699 mutex_lock(&thermal_list_lock);
700 list_for_each_entry(cdev, &thermal_cdev_list, node) {
701 if (!strncmp("Processor", cdev->type,
702 sizeof("Processor")))
703 thermal_zone_unbind_cooling_device(tz,
707 mutex_unlock(&thermal_list_lock);
708 tz->passive_delay = 0;
711 tz->forced_passive = state;
713 thermal_zone_device_update(tz);
719 passive_show(struct device *dev, struct device_attribute *attr,
722 struct thermal_zone_device *tz = to_thermal_zone(dev);
724 return sprintf(buf, "%d\n", tz->forced_passive);
728 policy_store(struct device *dev, struct device_attribute *attr,
729 const char *buf, size_t count)
732 struct thermal_zone_device *tz = to_thermal_zone(dev);
733 struct thermal_governor *gov;
734 char name[THERMAL_NAME_LENGTH];
736 snprintf(name, sizeof(name), "%s", buf);
738 mutex_lock(&thermal_governor_lock);
740 gov = __find_governor(strim(name));
748 mutex_unlock(&thermal_governor_lock);
753 policy_show(struct device *dev, struct device_attribute *devattr, char *buf)
755 struct thermal_zone_device *tz = to_thermal_zone(dev);
757 return sprintf(buf, "%s\n", tz->governor->name);
760 #ifdef CONFIG_THERMAL_EMULATION
762 emul_temp_store(struct device *dev, struct device_attribute *attr,
763 const char *buf, size_t count)
765 struct thermal_zone_device *tz = to_thermal_zone(dev);
767 unsigned long temperature;
769 if (kstrtoul(buf, 10, &temperature))
772 if (!tz->ops->set_emul_temp) {
773 mutex_lock(&tz->lock);
774 tz->emul_temperature = temperature;
775 mutex_unlock(&tz->lock);
777 ret = tz->ops->set_emul_temp(tz, temperature);
780 return ret ? ret : count;
782 static DEVICE_ATTR(emul_temp, S_IWUSR, NULL, emul_temp_store);
783 #endif/*CONFIG_THERMAL_EMULATION*/
785 static DEVICE_ATTR(type, 0444, type_show, NULL);
786 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
787 static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
788 static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
789 static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
791 /* sys I/F for cooling device */
792 #define to_cooling_device(_dev) \
793 container_of(_dev, struct thermal_cooling_device, device)
796 thermal_cooling_device_type_show(struct device *dev,
797 struct device_attribute *attr, char *buf)
799 struct thermal_cooling_device *cdev = to_cooling_device(dev);
801 return sprintf(buf, "%s\n", cdev->type);
805 thermal_cooling_device_max_state_show(struct device *dev,
806 struct device_attribute *attr, char *buf)
808 struct thermal_cooling_device *cdev = to_cooling_device(dev);
812 ret = cdev->ops->get_max_state(cdev, &state);
815 return sprintf(buf, "%ld\n", state);
819 thermal_cooling_device_cur_state_show(struct device *dev,
820 struct device_attribute *attr, char *buf)
822 struct thermal_cooling_device *cdev = to_cooling_device(dev);
826 ret = cdev->ops->get_cur_state(cdev, &state);
829 return sprintf(buf, "%ld\n", state);
833 thermal_cooling_device_cur_state_store(struct device *dev,
834 struct device_attribute *attr,
835 const char *buf, size_t count)
837 struct thermal_cooling_device *cdev = to_cooling_device(dev);
841 if (!sscanf(buf, "%ld\n", &state))
847 result = cdev->ops->set_cur_state(cdev, state);
853 static struct device_attribute dev_attr_cdev_type =
854 __ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
855 static DEVICE_ATTR(max_state, 0444,
856 thermal_cooling_device_max_state_show, NULL);
857 static DEVICE_ATTR(cur_state, 0644,
858 thermal_cooling_device_cur_state_show,
859 thermal_cooling_device_cur_state_store);
862 thermal_cooling_device_trip_point_show(struct device *dev,
863 struct device_attribute *attr, char *buf)
865 struct thermal_instance *instance;
868 container_of(attr, struct thermal_instance, attr);
870 if (instance->trip == THERMAL_TRIPS_NONE)
871 return sprintf(buf, "-1\n");
873 return sprintf(buf, "%d\n", instance->trip);
876 /* Device management */
879 * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
880 * @tz: pointer to struct thermal_zone_device
881 * @trip: indicates which trip point the cooling devices is
882 * associated with in this thermal zone.
883 * @cdev: pointer to struct thermal_cooling_device
884 * @upper: the Maximum cooling state for this trip point.
885 * THERMAL_NO_LIMIT means no upper limit,
886 * and the cooling device can be in max_state.
887 * @lower: the Minimum cooling state can be used for this trip point.
888 * THERMAL_NO_LIMIT means no lower limit,
889 * and the cooling device can be in cooling state 0.
891 * This interface function bind a thermal cooling device to the certain trip
892 * point of a thermal zone device.
893 * This function is usually called in the thermal zone device .bind callback.
895 * Return: 0 on success, the proper error value otherwise.
897 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
899 struct thermal_cooling_device *cdev,
900 unsigned long upper, unsigned long lower)
902 struct thermal_instance *dev;
903 struct thermal_instance *pos;
904 struct thermal_zone_device *pos1;
905 struct thermal_cooling_device *pos2;
906 unsigned long max_state;
909 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
912 list_for_each_entry(pos1, &thermal_tz_list, node) {
916 list_for_each_entry(pos2, &thermal_cdev_list, node) {
921 if (tz != pos1 || cdev != pos2)
924 cdev->ops->get_max_state(cdev, &max_state);
926 /* lower default 0, upper default max_state */
927 lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
928 upper = upper == THERMAL_NO_LIMIT ? max_state : upper;
930 if (lower > upper || upper > max_state)
934 kzalloc(sizeof(struct thermal_instance), GFP_KERNEL);
942 dev->target = THERMAL_NO_TARGET;
944 result = get_idr(&tz->idr, &tz->lock, &dev->id);
948 sprintf(dev->name, "cdev%d", dev->id);
950 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
954 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
955 sysfs_attr_init(&dev->attr.attr);
956 dev->attr.attr.name = dev->attr_name;
957 dev->attr.attr.mode = 0444;
958 dev->attr.show = thermal_cooling_device_trip_point_show;
959 result = device_create_file(&tz->device, &dev->attr);
961 goto remove_symbol_link;
963 mutex_lock(&tz->lock);
964 mutex_lock(&cdev->lock);
965 list_for_each_entry(pos, &tz->thermal_instances, tz_node)
966 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
971 list_add_tail(&dev->tz_node, &tz->thermal_instances);
972 list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
974 mutex_unlock(&cdev->lock);
975 mutex_unlock(&tz->lock);
980 device_remove_file(&tz->device, &dev->attr);
982 sysfs_remove_link(&tz->device.kobj, dev->name);
984 release_idr(&tz->idr, &tz->lock, dev->id);
989 EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
992 * thermal_zone_unbind_cooling_device() - unbind a cooling device from a
994 * @tz: pointer to a struct thermal_zone_device.
995 * @trip: indicates which trip point the cooling devices is
996 * associated with in this thermal zone.
997 * @cdev: pointer to a struct thermal_cooling_device.
999 * This interface function unbind a thermal cooling device from the certain
1000 * trip point of a thermal zone device.
1001 * This function is usually called in the thermal zone device .unbind callback.
1003 * Return: 0 on success, the proper error value otherwise.
1005 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
1007 struct thermal_cooling_device *cdev)
1009 struct thermal_instance *pos, *next;
1011 mutex_lock(&tz->lock);
1012 mutex_lock(&cdev->lock);
1013 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
1014 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
1015 list_del(&pos->tz_node);
1016 list_del(&pos->cdev_node);
1017 mutex_unlock(&cdev->lock);
1018 mutex_unlock(&tz->lock);
1022 mutex_unlock(&cdev->lock);
1023 mutex_unlock(&tz->lock);
1028 device_remove_file(&tz->device, &pos->attr);
1029 sysfs_remove_link(&tz->device.kobj, pos->name);
1030 release_idr(&tz->idr, &tz->lock, pos->id);
1034 EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);
1036 static void thermal_release(struct device *dev)
1038 struct thermal_zone_device *tz;
1039 struct thermal_cooling_device *cdev;
1041 if (!strncmp(dev_name(dev), "thermal_zone",
1042 sizeof("thermal_zone") - 1)) {
1043 tz = to_thermal_zone(dev);
1045 } else if(!strncmp(dev_name(dev), "cooling_device",
1046 sizeof("cooling_device") - 1)){
1047 cdev = to_cooling_device(dev);
1052 static struct class thermal_class = {
1054 .dev_release = thermal_release,
1058 * thermal_cooling_device_register() - register a new thermal cooling device
1059 * @type: the thermal cooling device type.
1060 * @devdata: device private data.
1061 * @ops: standard thermal cooling devices callbacks.
1063 * This interface function adds a new thermal cooling device (fan/processor/...)
1064 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1065 * to all the thermal zone devices registered at the same time.
1067 * Return: a pointer to the created struct thermal_cooling_device or an
1068 * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
1070 struct thermal_cooling_device *
1071 thermal_cooling_device_register(char *type, void *devdata,
1072 const struct thermal_cooling_device_ops *ops)
1074 struct thermal_cooling_device *cdev;
1077 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1078 return ERR_PTR(-EINVAL);
1080 if (!ops || !ops->get_max_state || !ops->get_cur_state ||
1081 !ops->set_cur_state)
1082 return ERR_PTR(-EINVAL);
1084 cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL);
1086 return ERR_PTR(-ENOMEM);
1088 result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
1091 return ERR_PTR(result);
1094 strlcpy(cdev->type, type ? : "", sizeof(cdev->type));
1095 mutex_init(&cdev->lock);
1096 INIT_LIST_HEAD(&cdev->thermal_instances);
1098 cdev->updated = true;
1099 cdev->device.class = &thermal_class;
1100 cdev->devdata = devdata;
1101 dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
1102 result = device_register(&cdev->device);
1104 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1106 return ERR_PTR(result);
1111 result = device_create_file(&cdev->device, &dev_attr_cdev_type);
1116 result = device_create_file(&cdev->device, &dev_attr_max_state);
1120 result = device_create_file(&cdev->device, &dev_attr_cur_state);
1124 /* Add 'this' new cdev to the global cdev list */
1125 mutex_lock(&thermal_list_lock);
1126 list_add(&cdev->node, &thermal_cdev_list);
1127 mutex_unlock(&thermal_list_lock);
1129 /* Update binding information for 'this' new cdev */
1135 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1136 device_unregister(&cdev->device);
1137 return ERR_PTR(result);
1139 EXPORT_SYMBOL_GPL(thermal_cooling_device_register);
1142 * thermal_cooling_device_unregister - removes the registered thermal cooling device
1143 * @cdev: the thermal cooling device to remove.
1145 * thermal_cooling_device_unregister() must be called when the device is no
1148 void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
1151 const struct thermal_zone_params *tzp;
1152 struct thermal_zone_device *tz;
1153 struct thermal_cooling_device *pos = NULL;
1158 mutex_lock(&thermal_list_lock);
1159 list_for_each_entry(pos, &thermal_cdev_list, node)
1163 /* thermal cooling device not found */
1164 mutex_unlock(&thermal_list_lock);
1167 list_del(&cdev->node);
1169 /* Unbind all thermal zones associated with 'this' cdev */
1170 list_for_each_entry(tz, &thermal_tz_list, node) {
1171 if (tz->ops->unbind) {
1172 tz->ops->unbind(tz, cdev);
1176 if (!tz->tzp || !tz->tzp->tbp)
1180 for (i = 0; i < tzp->num_tbps; i++) {
1181 if (tzp->tbp[i].cdev == cdev) {
1182 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1183 tzp->tbp[i].cdev = NULL;
1188 mutex_unlock(&thermal_list_lock);
1191 device_remove_file(&cdev->device, &dev_attr_cdev_type);
1192 device_remove_file(&cdev->device, &dev_attr_max_state);
1193 device_remove_file(&cdev->device, &dev_attr_cur_state);
1195 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1196 device_unregister(&cdev->device);
1199 EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
1201 void thermal_cdev_update(struct thermal_cooling_device *cdev)
1203 struct thermal_instance *instance;
1204 unsigned long target = 0;
1206 /* cooling device is updated*/
1210 mutex_lock(&cdev->lock);
1211 /* Make sure cdev enters the deepest cooling state */
1212 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
1213 dev_dbg(&cdev->device, "zone%d->target=%lu\n",
1214 instance->tz->id, instance->target);
1215 if (instance->target == THERMAL_NO_TARGET)
1217 if (instance->target > target)
1218 target = instance->target;
1220 mutex_unlock(&cdev->lock);
1221 cdev->ops->set_cur_state(cdev, target);
1222 cdev->updated = true;
1223 dev_dbg(&cdev->device, "set to state %lu\n", target);
1225 EXPORT_SYMBOL(thermal_cdev_update);
1228 * thermal_notify_framework - Sensor drivers use this API to notify framework
1229 * @tz: thermal zone device
1230 * @trip: indicates which trip point has been crossed
1232 * This function handles the trip events from sensor drivers. It starts
1233 * throttling the cooling devices according to the policy configured.
1234 * For CRITICAL and HOT trip points, this notifies the respective drivers,
1235 * and does actual throttling for other trip points i.e ACTIVE and PASSIVE.
1236 * The throttling policy is based on the configured platform data; if no
1237 * platform data is provided, this uses the step_wise throttling policy.
1239 void thermal_notify_framework(struct thermal_zone_device *tz, int trip)
1241 handle_thermal_trip(tz, trip);
1243 EXPORT_SYMBOL_GPL(thermal_notify_framework);
1246 * create_trip_attrs() - create attributes for trip points
1247 * @tz: the thermal zone device
1248 * @mask: Writeable trip point bitmap.
1250 * helper function to instantiate sysfs entries for every trip
1251 * point and its properties of a struct thermal_zone_device.
1253 * Return: 0 on success, the proper error value otherwise.
1255 static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
1258 int size = sizeof(struct thermal_attr) * tz->trips;
1260 tz->trip_type_attrs = kzalloc(size, GFP_KERNEL);
1261 if (!tz->trip_type_attrs)
1264 tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL);
1265 if (!tz->trip_temp_attrs) {
1266 kfree(tz->trip_type_attrs);
1270 if (tz->ops->get_trip_hyst) {
1271 tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL);
1272 if (!tz->trip_hyst_attrs) {
1273 kfree(tz->trip_type_attrs);
1274 kfree(tz->trip_temp_attrs);
1280 for (indx = 0; indx < tz->trips; indx++) {
1281 /* create trip type attribute */
1282 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
1283 "trip_point_%d_type", indx);
1285 sysfs_attr_init(&tz->trip_type_attrs[indx].attr.attr);
1286 tz->trip_type_attrs[indx].attr.attr.name =
1287 tz->trip_type_attrs[indx].name;
1288 tz->trip_type_attrs[indx].attr.attr.mode = S_IRUGO;
1289 tz->trip_type_attrs[indx].attr.show = trip_point_type_show;
1291 device_create_file(&tz->device,
1292 &tz->trip_type_attrs[indx].attr);
1294 /* create trip temp attribute */
1295 snprintf(tz->trip_temp_attrs[indx].name, THERMAL_NAME_LENGTH,
1296 "trip_point_%d_temp", indx);
1298 sysfs_attr_init(&tz->trip_temp_attrs[indx].attr.attr);
1299 tz->trip_temp_attrs[indx].attr.attr.name =
1300 tz->trip_temp_attrs[indx].name;
1301 tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
1302 tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
1303 if (mask & (1 << indx)) {
1304 tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
1305 tz->trip_temp_attrs[indx].attr.store =
1306 trip_point_temp_store;
1309 device_create_file(&tz->device,
1310 &tz->trip_temp_attrs[indx].attr);
1312 /* create Optional trip hyst attribute */
1313 if (!tz->ops->get_trip_hyst)
1315 snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH,
1316 "trip_point_%d_hyst", indx);
1318 sysfs_attr_init(&tz->trip_hyst_attrs[indx].attr.attr);
1319 tz->trip_hyst_attrs[indx].attr.attr.name =
1320 tz->trip_hyst_attrs[indx].name;
1321 tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
1322 tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
1323 if (tz->ops->set_trip_hyst) {
1324 tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
1325 tz->trip_hyst_attrs[indx].attr.store =
1326 trip_point_hyst_store;
1329 device_create_file(&tz->device,
1330 &tz->trip_hyst_attrs[indx].attr);
1335 static void remove_trip_attrs(struct thermal_zone_device *tz)
1339 for (indx = 0; indx < tz->trips; indx++) {
1340 device_remove_file(&tz->device,
1341 &tz->trip_type_attrs[indx].attr);
1342 device_remove_file(&tz->device,
1343 &tz->trip_temp_attrs[indx].attr);
1344 if (tz->ops->get_trip_hyst)
1345 device_remove_file(&tz->device,
1346 &tz->trip_hyst_attrs[indx].attr);
1348 kfree(tz->trip_type_attrs);
1349 kfree(tz->trip_temp_attrs);
1350 kfree(tz->trip_hyst_attrs);
1354 * thermal_zone_device_register() - register a new thermal zone device
1355 * @type: the thermal zone device type
1356 * @trips: the number of trip points the thermal zone support
1357 * @mask: a bit string indicating the writeablility of trip points
1358 * @devdata: private device data
1359 * @ops: standard thermal zone device callbacks
1360 * @tzp: thermal zone platform parameters
1361 * @passive_delay: number of milliseconds to wait between polls when
1362 * performing passive cooling
1363 * @polling_delay: number of milliseconds to wait between polls when checking
1364 * whether trip points have been crossed (0 for interrupt
1367 * This interface function adds a new thermal zone device (sensor) to
1368 * /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the
1369 * thermal cooling devices registered at the same time.
1370 * thermal_zone_device_unregister() must be called when the device is no
1371 * longer needed. The passive cooling depends on the .get_trend() return value.
1373 * Return: a pointer to the created struct thermal_zone_device or an
1374 * in case of error, an ERR_PTR. Caller must check return value with
1375 * IS_ERR*() helpers.
1377 struct thermal_zone_device *thermal_zone_device_register(const char *type,
1378 int trips, int mask, void *devdata,
1379 const struct thermal_zone_device_ops *ops,
1380 const struct thermal_zone_params *tzp,
1381 int passive_delay, int polling_delay)
1383 struct thermal_zone_device *tz;
1384 enum thermal_trip_type trip_type;
1389 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1390 return ERR_PTR(-EINVAL);
1392 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
1393 return ERR_PTR(-EINVAL);
1395 if (!ops || !ops->get_temp)
1396 return ERR_PTR(-EINVAL);
1398 if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp))
1399 return ERR_PTR(-EINVAL);
1401 tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL);
1403 return ERR_PTR(-ENOMEM);
1405 INIT_LIST_HEAD(&tz->thermal_instances);
1407 mutex_init(&tz->lock);
1408 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
1411 return ERR_PTR(result);
1414 strlcpy(tz->type, type ? : "", sizeof(tz->type));
1417 tz->device.class = &thermal_class;
1418 tz->devdata = devdata;
1420 tz->passive_delay = passive_delay;
1421 tz->polling_delay = polling_delay;
1423 dev_set_name(&tz->device, "thermal_zone%d", tz->id);
1424 result = device_register(&tz->device);
1426 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1428 return ERR_PTR(result);
1433 result = device_create_file(&tz->device, &dev_attr_type);
1438 result = device_create_file(&tz->device, &dev_attr_temp);
1442 if (ops->get_mode) {
1443 result = device_create_file(&tz->device, &dev_attr_mode);
1448 result = create_trip_attrs(tz, mask);
1452 for (count = 0; count < trips; count++) {
1453 tz->ops->get_trip_type(tz, count, &trip_type);
1454 if (trip_type == THERMAL_TRIP_PASSIVE)
1459 result = device_create_file(&tz->device, &dev_attr_passive);
1464 #ifdef CONFIG_THERMAL_EMULATION
1465 result = device_create_file(&tz->device, &dev_attr_emul_temp);
1469 /* Create policy attribute */
1470 result = device_create_file(&tz->device, &dev_attr_policy);
1474 /* Update 'this' zone's governor information */
1475 mutex_lock(&thermal_governor_lock);
1478 tz->governor = __find_governor(tz->tzp->governor_name);
1480 tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
1482 mutex_unlock(&thermal_governor_lock);
1484 if (!tz->tzp || !tz->tzp->no_hwmon) {
1485 result = thermal_add_hwmon_sysfs(tz);
1490 mutex_lock(&thermal_list_lock);
1491 list_add_tail(&tz->node, &thermal_tz_list);
1492 mutex_unlock(&thermal_list_lock);
1494 /* Bind cooling devices for this zone */
1497 INIT_DELAYED_WORK(&(tz->poll_queue), thermal_zone_device_check);
1499 thermal_zone_device_update(tz);
1505 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1506 device_unregister(&tz->device);
1507 return ERR_PTR(result);
1509 EXPORT_SYMBOL_GPL(thermal_zone_device_register);
1512 * thermal_device_unregister - removes the registered thermal zone device
1513 * @tz: the thermal zone device to remove
1515 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1518 const struct thermal_zone_params *tzp;
1519 struct thermal_cooling_device *cdev;
1520 struct thermal_zone_device *pos = NULL;
1527 mutex_lock(&thermal_list_lock);
1528 list_for_each_entry(pos, &thermal_tz_list, node)
1532 /* thermal zone device not found */
1533 mutex_unlock(&thermal_list_lock);
1536 list_del(&tz->node);
1538 /* Unbind all cdevs associated with 'this' thermal zone */
1539 list_for_each_entry(cdev, &thermal_cdev_list, node) {
1540 if (tz->ops->unbind) {
1541 tz->ops->unbind(tz, cdev);
1545 if (!tzp || !tzp->tbp)
1548 for (i = 0; i < tzp->num_tbps; i++) {
1549 if (tzp->tbp[i].cdev == cdev) {
1550 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1551 tzp->tbp[i].cdev = NULL;
1556 mutex_unlock(&thermal_list_lock);
1558 thermal_zone_device_set_polling(tz, 0);
1561 device_remove_file(&tz->device, &dev_attr_type);
1562 device_remove_file(&tz->device, &dev_attr_temp);
1563 if (tz->ops->get_mode)
1564 device_remove_file(&tz->device, &dev_attr_mode);
1565 device_remove_file(&tz->device, &dev_attr_policy);
1566 remove_trip_attrs(tz);
1567 tz->governor = NULL;
1569 thermal_remove_hwmon_sysfs(tz);
1570 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1571 idr_destroy(&tz->idr);
1572 mutex_destroy(&tz->lock);
1573 device_unregister(&tz->device);
1576 EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
1579 * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
1580 * @name: thermal zone name to fetch the temperature
1582 * When only one zone is found with the passed name, returns a reference to it.
1584 * Return: On success returns a reference to an unique thermal zone with
1585 * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
1586 * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
1588 struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
1590 struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
1591 unsigned int found = 0;
1596 mutex_lock(&thermal_list_lock);
1597 list_for_each_entry(pos, &thermal_tz_list, node)
1598 if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
1602 mutex_unlock(&thermal_list_lock);
1604 /* nothing has been found, thus an error code for it */
1606 ref = ERR_PTR(-ENODEV);
1608 /* Success only when an unique zone is found */
1609 ref = ERR_PTR(-EEXIST);
1614 EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
1617 static const struct genl_multicast_group thermal_event_mcgrps[] = {
1618 { .name = THERMAL_GENL_MCAST_GROUP_NAME, },
1621 static struct genl_family thermal_event_genl_family = {
1622 .id = GENL_ID_GENERATE,
1623 .name = THERMAL_GENL_FAMILY_NAME,
1624 .version = THERMAL_GENL_VERSION,
1625 .maxattr = THERMAL_GENL_ATTR_MAX,
1626 .mcgrps = thermal_event_mcgrps,
1627 .n_mcgrps = ARRAY_SIZE(thermal_event_mcgrps),
1630 int thermal_generate_netlink_event(struct thermal_zone_device *tz,
1633 struct sk_buff *skb;
1634 struct nlattr *attr;
1635 struct thermal_genl_event *thermal_event;
1639 static unsigned int thermal_event_seqnum;
1644 /* allocate memory */
1645 size = nla_total_size(sizeof(struct thermal_genl_event)) +
1648 skb = genlmsg_new(size, GFP_ATOMIC);
1652 /* add the genetlink message header */
1653 msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++,
1654 &thermal_event_genl_family, 0,
1655 THERMAL_GENL_CMD_EVENT);
1662 attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT,
1663 sizeof(struct thermal_genl_event));
1670 thermal_event = nla_data(attr);
1671 if (!thermal_event) {
1676 memset(thermal_event, 0, sizeof(struct thermal_genl_event));
1678 thermal_event->orig = tz->id;
1679 thermal_event->event = event;
1681 /* send multicast genetlink message */
1682 result = genlmsg_end(skb, msg_header);
1688 result = genlmsg_multicast(&thermal_event_genl_family, skb, 0,
1691 dev_err(&tz->device, "Failed to send netlink event:%d", result);
1695 EXPORT_SYMBOL_GPL(thermal_generate_netlink_event);
1697 static int genetlink_init(void)
1699 return genl_register_family(&thermal_event_genl_family);
1702 static void genetlink_exit(void)
1704 genl_unregister_family(&thermal_event_genl_family);
1706 #else /* !CONFIG_NET */
1707 static inline int genetlink_init(void) { return 0; }
1708 static inline void genetlink_exit(void) {}
1709 #endif /* !CONFIG_NET */
1711 static int __init thermal_register_governors(void)
1715 result = thermal_gov_step_wise_register();
1719 result = thermal_gov_fair_share_register();
1723 return thermal_gov_user_space_register();
1726 static void thermal_unregister_governors(void)
1728 thermal_gov_step_wise_unregister();
1729 thermal_gov_fair_share_unregister();
1730 thermal_gov_user_space_unregister();
1733 static int __init thermal_init(void)
1737 result = thermal_register_governors();
1741 result = class_register(&thermal_class);
1743 goto unregister_governors;
1745 result = genetlink_init();
1747 goto unregister_class;
1751 unregister_governors:
1752 thermal_unregister_governors();
1754 class_unregister(&thermal_class);
1756 idr_destroy(&thermal_tz_idr);
1757 idr_destroy(&thermal_cdev_idr);
1758 mutex_destroy(&thermal_idr_lock);
1759 mutex_destroy(&thermal_list_lock);
1760 mutex_destroy(&thermal_governor_lock);
1764 static void __exit thermal_exit(void)
1767 class_unregister(&thermal_class);
1768 thermal_unregister_governors();
1769 idr_destroy(&thermal_tz_idr);
1770 idr_destroy(&thermal_cdev_idr);
1771 mutex_destroy(&thermal_idr_lock);
1772 mutex_destroy(&thermal_list_lock);
1773 mutex_destroy(&thermal_governor_lock);
1776 fs_initcall(thermal_init);
1777 module_exit(thermal_exit);