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);
455 void thermal_zone_device_update(struct thermal_zone_device *tz)
459 update_temperature(tz);
461 for (count = 0; count < tz->trips; count++)
462 handle_thermal_trip(tz, count);
464 EXPORT_SYMBOL_GPL(thermal_zone_device_update);
466 static void thermal_zone_device_check(struct work_struct *work)
468 struct thermal_zone_device *tz = container_of(work, struct
471 thermal_zone_device_update(tz);
474 /* sys I/F for thermal zone */
476 #define to_thermal_zone(_dev) \
477 container_of(_dev, struct thermal_zone_device, device)
480 type_show(struct device *dev, struct device_attribute *attr, char *buf)
482 struct thermal_zone_device *tz = to_thermal_zone(dev);
484 return sprintf(buf, "%s\n", tz->type);
488 temp_show(struct device *dev, struct device_attribute *attr, char *buf)
490 struct thermal_zone_device *tz = to_thermal_zone(dev);
494 ret = thermal_zone_get_temp(tz, &temperature);
499 return sprintf(buf, "%ld\n", temperature);
503 mode_show(struct device *dev, struct device_attribute *attr, char *buf)
505 struct thermal_zone_device *tz = to_thermal_zone(dev);
506 enum thermal_device_mode mode;
509 if (!tz->ops->get_mode)
512 result = tz->ops->get_mode(tz, &mode);
516 return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled"
521 mode_store(struct device *dev, struct device_attribute *attr,
522 const char *buf, size_t count)
524 struct thermal_zone_device *tz = to_thermal_zone(dev);
527 if (!tz->ops->set_mode)
530 if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
531 result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
532 else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
533 result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
544 trip_point_type_show(struct device *dev, struct device_attribute *attr,
547 struct thermal_zone_device *tz = to_thermal_zone(dev);
548 enum thermal_trip_type type;
551 if (!tz->ops->get_trip_type)
554 if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip))
557 result = tz->ops->get_trip_type(tz, trip, &type);
562 case THERMAL_TRIP_CRITICAL:
563 return sprintf(buf, "critical\n");
564 case THERMAL_TRIP_HOT:
565 return sprintf(buf, "hot\n");
566 case THERMAL_TRIP_PASSIVE:
567 return sprintf(buf, "passive\n");
568 case THERMAL_TRIP_ACTIVE:
569 return sprintf(buf, "active\n");
571 return sprintf(buf, "unknown\n");
576 trip_point_temp_store(struct device *dev, struct device_attribute *attr,
577 const char *buf, size_t count)
579 struct thermal_zone_device *tz = to_thermal_zone(dev);
581 unsigned long temperature;
583 if (!tz->ops->set_trip_temp)
586 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
589 if (kstrtoul(buf, 10, &temperature))
592 ret = tz->ops->set_trip_temp(tz, trip, temperature);
594 return ret ? ret : count;
598 trip_point_temp_show(struct device *dev, struct device_attribute *attr,
601 struct thermal_zone_device *tz = to_thermal_zone(dev);
605 if (!tz->ops->get_trip_temp)
608 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
611 ret = tz->ops->get_trip_temp(tz, trip, &temperature);
616 return sprintf(buf, "%ld\n", temperature);
620 trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
621 const char *buf, size_t count)
623 struct thermal_zone_device *tz = to_thermal_zone(dev);
625 unsigned long temperature;
627 if (!tz->ops->set_trip_hyst)
630 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
633 if (kstrtoul(buf, 10, &temperature))
637 * We are not doing any check on the 'temperature' value
638 * here. The driver implementing 'set_trip_hyst' has to
641 ret = tz->ops->set_trip_hyst(tz, trip, temperature);
643 return ret ? ret : count;
647 trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
650 struct thermal_zone_device *tz = to_thermal_zone(dev);
652 unsigned long temperature;
654 if (!tz->ops->get_trip_hyst)
657 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
660 ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
662 return ret ? ret : sprintf(buf, "%ld\n", temperature);
666 passive_store(struct device *dev, struct device_attribute *attr,
667 const char *buf, size_t count)
669 struct thermal_zone_device *tz = to_thermal_zone(dev);
670 struct thermal_cooling_device *cdev = NULL;
673 if (!sscanf(buf, "%d\n", &state))
676 /* sanity check: values below 1000 millicelcius don't make sense
677 * and can cause the system to go into a thermal heart attack
679 if (state && state < 1000)
682 if (state && !tz->forced_passive) {
683 mutex_lock(&thermal_list_lock);
684 list_for_each_entry(cdev, &thermal_cdev_list, node) {
685 if (!strncmp("Processor", cdev->type,
686 sizeof("Processor")))
687 thermal_zone_bind_cooling_device(tz,
688 THERMAL_TRIPS_NONE, cdev,
692 mutex_unlock(&thermal_list_lock);
693 if (!tz->passive_delay)
694 tz->passive_delay = 1000;
695 } else if (!state && tz->forced_passive) {
696 mutex_lock(&thermal_list_lock);
697 list_for_each_entry(cdev, &thermal_cdev_list, node) {
698 if (!strncmp("Processor", cdev->type,
699 sizeof("Processor")))
700 thermal_zone_unbind_cooling_device(tz,
704 mutex_unlock(&thermal_list_lock);
705 tz->passive_delay = 0;
708 tz->forced_passive = state;
710 thermal_zone_device_update(tz);
716 passive_show(struct device *dev, struct device_attribute *attr,
719 struct thermal_zone_device *tz = to_thermal_zone(dev);
721 return sprintf(buf, "%d\n", tz->forced_passive);
725 policy_store(struct device *dev, struct device_attribute *attr,
726 const char *buf, size_t count)
729 struct thermal_zone_device *tz = to_thermal_zone(dev);
730 struct thermal_governor *gov;
731 char name[THERMAL_NAME_LENGTH];
733 snprintf(name, sizeof(name), "%s", buf);
735 mutex_lock(&thermal_governor_lock);
737 gov = __find_governor(strim(name));
745 mutex_unlock(&thermal_governor_lock);
750 policy_show(struct device *dev, struct device_attribute *devattr, char *buf)
752 struct thermal_zone_device *tz = to_thermal_zone(dev);
754 return sprintf(buf, "%s\n", tz->governor->name);
757 #ifdef CONFIG_THERMAL_EMULATION
759 emul_temp_store(struct device *dev, struct device_attribute *attr,
760 const char *buf, size_t count)
762 struct thermal_zone_device *tz = to_thermal_zone(dev);
764 unsigned long temperature;
766 if (kstrtoul(buf, 10, &temperature))
769 if (!tz->ops->set_emul_temp) {
770 mutex_lock(&tz->lock);
771 tz->emul_temperature = temperature;
772 mutex_unlock(&tz->lock);
774 ret = tz->ops->set_emul_temp(tz, temperature);
777 return ret ? ret : count;
779 static DEVICE_ATTR(emul_temp, S_IWUSR, NULL, emul_temp_store);
780 #endif/*CONFIG_THERMAL_EMULATION*/
782 static DEVICE_ATTR(type, 0444, type_show, NULL);
783 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
784 static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
785 static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
786 static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
788 /* sys I/F for cooling device */
789 #define to_cooling_device(_dev) \
790 container_of(_dev, struct thermal_cooling_device, device)
793 thermal_cooling_device_type_show(struct device *dev,
794 struct device_attribute *attr, char *buf)
796 struct thermal_cooling_device *cdev = to_cooling_device(dev);
798 return sprintf(buf, "%s\n", cdev->type);
802 thermal_cooling_device_max_state_show(struct device *dev,
803 struct device_attribute *attr, char *buf)
805 struct thermal_cooling_device *cdev = to_cooling_device(dev);
809 ret = cdev->ops->get_max_state(cdev, &state);
812 return sprintf(buf, "%ld\n", state);
816 thermal_cooling_device_cur_state_show(struct device *dev,
817 struct device_attribute *attr, char *buf)
819 struct thermal_cooling_device *cdev = to_cooling_device(dev);
823 ret = cdev->ops->get_cur_state(cdev, &state);
826 return sprintf(buf, "%ld\n", state);
830 thermal_cooling_device_cur_state_store(struct device *dev,
831 struct device_attribute *attr,
832 const char *buf, size_t count)
834 struct thermal_cooling_device *cdev = to_cooling_device(dev);
838 if (!sscanf(buf, "%ld\n", &state))
844 result = cdev->ops->set_cur_state(cdev, state);
850 static struct device_attribute dev_attr_cdev_type =
851 __ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
852 static DEVICE_ATTR(max_state, 0444,
853 thermal_cooling_device_max_state_show, NULL);
854 static DEVICE_ATTR(cur_state, 0644,
855 thermal_cooling_device_cur_state_show,
856 thermal_cooling_device_cur_state_store);
859 thermal_cooling_device_trip_point_show(struct device *dev,
860 struct device_attribute *attr, char *buf)
862 struct thermal_instance *instance;
865 container_of(attr, struct thermal_instance, attr);
867 if (instance->trip == THERMAL_TRIPS_NONE)
868 return sprintf(buf, "-1\n");
870 return sprintf(buf, "%d\n", instance->trip);
873 /* Device management */
876 * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
877 * @tz: pointer to struct thermal_zone_device
878 * @trip: indicates which trip point the cooling devices is
879 * associated with in this thermal zone.
880 * @cdev: pointer to struct thermal_cooling_device
881 * @upper: the Maximum cooling state for this trip point.
882 * THERMAL_NO_LIMIT means no upper limit,
883 * and the cooling device can be in max_state.
884 * @lower: the Minimum cooling state can be used for this trip point.
885 * THERMAL_NO_LIMIT means no lower limit,
886 * and the cooling device can be in cooling state 0.
888 * This interface function bind a thermal cooling device to the certain trip
889 * point of a thermal zone device.
890 * This function is usually called in the thermal zone device .bind callback.
892 * Return: 0 on success, the proper error value otherwise.
894 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
896 struct thermal_cooling_device *cdev,
897 unsigned long upper, unsigned long lower)
899 struct thermal_instance *dev;
900 struct thermal_instance *pos;
901 struct thermal_zone_device *pos1;
902 struct thermal_cooling_device *pos2;
903 unsigned long max_state;
906 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
909 list_for_each_entry(pos1, &thermal_tz_list, node) {
913 list_for_each_entry(pos2, &thermal_cdev_list, node) {
918 if (tz != pos1 || cdev != pos2)
921 cdev->ops->get_max_state(cdev, &max_state);
923 /* lower default 0, upper default max_state */
924 lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
925 upper = upper == THERMAL_NO_LIMIT ? max_state : upper;
927 if (lower > upper || upper > max_state)
931 kzalloc(sizeof(struct thermal_instance), GFP_KERNEL);
939 dev->target = THERMAL_NO_TARGET;
941 result = get_idr(&tz->idr, &tz->lock, &dev->id);
945 sprintf(dev->name, "cdev%d", dev->id);
947 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
951 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
952 sysfs_attr_init(&dev->attr.attr);
953 dev->attr.attr.name = dev->attr_name;
954 dev->attr.attr.mode = 0444;
955 dev->attr.show = thermal_cooling_device_trip_point_show;
956 result = device_create_file(&tz->device, &dev->attr);
958 goto remove_symbol_link;
960 mutex_lock(&tz->lock);
961 mutex_lock(&cdev->lock);
962 list_for_each_entry(pos, &tz->thermal_instances, tz_node)
963 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
968 list_add_tail(&dev->tz_node, &tz->thermal_instances);
969 list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
971 mutex_unlock(&cdev->lock);
972 mutex_unlock(&tz->lock);
977 device_remove_file(&tz->device, &dev->attr);
979 sysfs_remove_link(&tz->device.kobj, dev->name);
981 release_idr(&tz->idr, &tz->lock, dev->id);
986 EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
989 * thermal_zone_unbind_cooling_device() - unbind a cooling device from a
991 * @tz: pointer to a struct thermal_zone_device.
992 * @trip: indicates which trip point the cooling devices is
993 * associated with in this thermal zone.
994 * @cdev: pointer to a struct thermal_cooling_device.
996 * This interface function unbind a thermal cooling device from the certain
997 * trip point of a thermal zone device.
998 * This function is usually called in the thermal zone device .unbind callback.
1000 * Return: 0 on success, the proper error value otherwise.
1002 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
1004 struct thermal_cooling_device *cdev)
1006 struct thermal_instance *pos, *next;
1008 mutex_lock(&tz->lock);
1009 mutex_lock(&cdev->lock);
1010 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
1011 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
1012 list_del(&pos->tz_node);
1013 list_del(&pos->cdev_node);
1014 mutex_unlock(&cdev->lock);
1015 mutex_unlock(&tz->lock);
1019 mutex_unlock(&cdev->lock);
1020 mutex_unlock(&tz->lock);
1025 device_remove_file(&tz->device, &pos->attr);
1026 sysfs_remove_link(&tz->device.kobj, pos->name);
1027 release_idr(&tz->idr, &tz->lock, pos->id);
1031 EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);
1033 static void thermal_release(struct device *dev)
1035 struct thermal_zone_device *tz;
1036 struct thermal_cooling_device *cdev;
1038 if (!strncmp(dev_name(dev), "thermal_zone",
1039 sizeof("thermal_zone") - 1)) {
1040 tz = to_thermal_zone(dev);
1042 } else if(!strncmp(dev_name(dev), "cooling_device",
1043 sizeof("cooling_device") - 1)){
1044 cdev = to_cooling_device(dev);
1049 static struct class thermal_class = {
1051 .dev_release = thermal_release,
1055 * thermal_cooling_device_register() - register a new thermal cooling device
1056 * @type: the thermal cooling device type.
1057 * @devdata: device private data.
1058 * @ops: standard thermal cooling devices callbacks.
1060 * This interface function adds a new thermal cooling device (fan/processor/...)
1061 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1062 * to all the thermal zone devices registered at the same time.
1064 * Return: a pointer to the created struct thermal_cooling_device or an
1065 * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
1067 struct thermal_cooling_device *
1068 thermal_cooling_device_register(char *type, void *devdata,
1069 const struct thermal_cooling_device_ops *ops)
1071 struct thermal_cooling_device *cdev;
1074 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1075 return ERR_PTR(-EINVAL);
1077 if (!ops || !ops->get_max_state || !ops->get_cur_state ||
1078 !ops->set_cur_state)
1079 return ERR_PTR(-EINVAL);
1081 cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL);
1083 return ERR_PTR(-ENOMEM);
1085 result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
1088 return ERR_PTR(result);
1091 strlcpy(cdev->type, type ? : "", sizeof(cdev->type));
1092 mutex_init(&cdev->lock);
1093 INIT_LIST_HEAD(&cdev->thermal_instances);
1095 cdev->updated = true;
1096 cdev->device.class = &thermal_class;
1097 cdev->devdata = devdata;
1098 dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
1099 result = device_register(&cdev->device);
1101 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1103 return ERR_PTR(result);
1108 result = device_create_file(&cdev->device, &dev_attr_cdev_type);
1113 result = device_create_file(&cdev->device, &dev_attr_max_state);
1117 result = device_create_file(&cdev->device, &dev_attr_cur_state);
1121 /* Add 'this' new cdev to the global cdev list */
1122 mutex_lock(&thermal_list_lock);
1123 list_add(&cdev->node, &thermal_cdev_list);
1124 mutex_unlock(&thermal_list_lock);
1126 /* Update binding information for 'this' new cdev */
1132 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1133 device_unregister(&cdev->device);
1134 return ERR_PTR(result);
1136 EXPORT_SYMBOL_GPL(thermal_cooling_device_register);
1139 * thermal_cooling_device_unregister - removes the registered thermal cooling device
1140 * @cdev: the thermal cooling device to remove.
1142 * thermal_cooling_device_unregister() must be called when the device is no
1145 void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
1148 const struct thermal_zone_params *tzp;
1149 struct thermal_zone_device *tz;
1150 struct thermal_cooling_device *pos = NULL;
1155 mutex_lock(&thermal_list_lock);
1156 list_for_each_entry(pos, &thermal_cdev_list, node)
1160 /* thermal cooling device not found */
1161 mutex_unlock(&thermal_list_lock);
1164 list_del(&cdev->node);
1166 /* Unbind all thermal zones associated with 'this' cdev */
1167 list_for_each_entry(tz, &thermal_tz_list, node) {
1168 if (tz->ops->unbind) {
1169 tz->ops->unbind(tz, cdev);
1173 if (!tz->tzp || !tz->tzp->tbp)
1177 for (i = 0; i < tzp->num_tbps; i++) {
1178 if (tzp->tbp[i].cdev == cdev) {
1179 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1180 tzp->tbp[i].cdev = NULL;
1185 mutex_unlock(&thermal_list_lock);
1188 device_remove_file(&cdev->device, &dev_attr_cdev_type);
1189 device_remove_file(&cdev->device, &dev_attr_max_state);
1190 device_remove_file(&cdev->device, &dev_attr_cur_state);
1192 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1193 device_unregister(&cdev->device);
1196 EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
1198 void thermal_cdev_update(struct thermal_cooling_device *cdev)
1200 struct thermal_instance *instance;
1201 unsigned long target = 0;
1203 /* cooling device is updated*/
1207 mutex_lock(&cdev->lock);
1208 /* Make sure cdev enters the deepest cooling state */
1209 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
1210 if (instance->target == THERMAL_NO_TARGET)
1212 if (instance->target > target)
1213 target = instance->target;
1215 mutex_unlock(&cdev->lock);
1216 cdev->ops->set_cur_state(cdev, target);
1217 cdev->updated = true;
1219 EXPORT_SYMBOL(thermal_cdev_update);
1222 * thermal_notify_framework - Sensor drivers use this API to notify framework
1223 * @tz: thermal zone device
1224 * @trip: indicates which trip point has been crossed
1226 * This function handles the trip events from sensor drivers. It starts
1227 * throttling the cooling devices according to the policy configured.
1228 * For CRITICAL and HOT trip points, this notifies the respective drivers,
1229 * and does actual throttling for other trip points i.e ACTIVE and PASSIVE.
1230 * The throttling policy is based on the configured platform data; if no
1231 * platform data is provided, this uses the step_wise throttling policy.
1233 void thermal_notify_framework(struct thermal_zone_device *tz, int trip)
1235 handle_thermal_trip(tz, trip);
1237 EXPORT_SYMBOL_GPL(thermal_notify_framework);
1240 * create_trip_attrs() - create attributes for trip points
1241 * @tz: the thermal zone device
1242 * @mask: Writeable trip point bitmap.
1244 * helper function to instantiate sysfs entries for every trip
1245 * point and its properties of a struct thermal_zone_device.
1247 * Return: 0 on success, the proper error value otherwise.
1249 static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
1252 int size = sizeof(struct thermal_attr) * tz->trips;
1254 tz->trip_type_attrs = kzalloc(size, GFP_KERNEL);
1255 if (!tz->trip_type_attrs)
1258 tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL);
1259 if (!tz->trip_temp_attrs) {
1260 kfree(tz->trip_type_attrs);
1264 if (tz->ops->get_trip_hyst) {
1265 tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL);
1266 if (!tz->trip_hyst_attrs) {
1267 kfree(tz->trip_type_attrs);
1268 kfree(tz->trip_temp_attrs);
1274 for (indx = 0; indx < tz->trips; indx++) {
1275 /* create trip type attribute */
1276 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
1277 "trip_point_%d_type", indx);
1279 sysfs_attr_init(&tz->trip_type_attrs[indx].attr.attr);
1280 tz->trip_type_attrs[indx].attr.attr.name =
1281 tz->trip_type_attrs[indx].name;
1282 tz->trip_type_attrs[indx].attr.attr.mode = S_IRUGO;
1283 tz->trip_type_attrs[indx].attr.show = trip_point_type_show;
1285 device_create_file(&tz->device,
1286 &tz->trip_type_attrs[indx].attr);
1288 /* create trip temp attribute */
1289 snprintf(tz->trip_temp_attrs[indx].name, THERMAL_NAME_LENGTH,
1290 "trip_point_%d_temp", indx);
1292 sysfs_attr_init(&tz->trip_temp_attrs[indx].attr.attr);
1293 tz->trip_temp_attrs[indx].attr.attr.name =
1294 tz->trip_temp_attrs[indx].name;
1295 tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
1296 tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
1297 if (mask & (1 << indx)) {
1298 tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
1299 tz->trip_temp_attrs[indx].attr.store =
1300 trip_point_temp_store;
1303 device_create_file(&tz->device,
1304 &tz->trip_temp_attrs[indx].attr);
1306 /* create Optional trip hyst attribute */
1307 if (!tz->ops->get_trip_hyst)
1309 snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH,
1310 "trip_point_%d_hyst", indx);
1312 sysfs_attr_init(&tz->trip_hyst_attrs[indx].attr.attr);
1313 tz->trip_hyst_attrs[indx].attr.attr.name =
1314 tz->trip_hyst_attrs[indx].name;
1315 tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
1316 tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
1317 if (tz->ops->set_trip_hyst) {
1318 tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
1319 tz->trip_hyst_attrs[indx].attr.store =
1320 trip_point_hyst_store;
1323 device_create_file(&tz->device,
1324 &tz->trip_hyst_attrs[indx].attr);
1329 static void remove_trip_attrs(struct thermal_zone_device *tz)
1333 for (indx = 0; indx < tz->trips; indx++) {
1334 device_remove_file(&tz->device,
1335 &tz->trip_type_attrs[indx].attr);
1336 device_remove_file(&tz->device,
1337 &tz->trip_temp_attrs[indx].attr);
1338 if (tz->ops->get_trip_hyst)
1339 device_remove_file(&tz->device,
1340 &tz->trip_hyst_attrs[indx].attr);
1342 kfree(tz->trip_type_attrs);
1343 kfree(tz->trip_temp_attrs);
1344 kfree(tz->trip_hyst_attrs);
1348 * thermal_zone_device_register() - register a new thermal zone device
1349 * @type: the thermal zone device type
1350 * @trips: the number of trip points the thermal zone support
1351 * @mask: a bit string indicating the writeablility of trip points
1352 * @devdata: private device data
1353 * @ops: standard thermal zone device callbacks
1354 * @tzp: thermal zone platform parameters
1355 * @passive_delay: number of milliseconds to wait between polls when
1356 * performing passive cooling
1357 * @polling_delay: number of milliseconds to wait between polls when checking
1358 * whether trip points have been crossed (0 for interrupt
1361 * This interface function adds a new thermal zone device (sensor) to
1362 * /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the
1363 * thermal cooling devices registered at the same time.
1364 * thermal_zone_device_unregister() must be called when the device is no
1365 * longer needed. The passive cooling depends on the .get_trend() return value.
1367 * Return: a pointer to the created struct thermal_zone_device or an
1368 * in case of error, an ERR_PTR. Caller must check return value with
1369 * IS_ERR*() helpers.
1371 struct thermal_zone_device *thermal_zone_device_register(const char *type,
1372 int trips, int mask, void *devdata,
1373 const struct thermal_zone_device_ops *ops,
1374 const struct thermal_zone_params *tzp,
1375 int passive_delay, int polling_delay)
1377 struct thermal_zone_device *tz;
1378 enum thermal_trip_type trip_type;
1383 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1384 return ERR_PTR(-EINVAL);
1386 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
1387 return ERR_PTR(-EINVAL);
1389 if (!ops || !ops->get_temp)
1390 return ERR_PTR(-EINVAL);
1392 if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp))
1393 return ERR_PTR(-EINVAL);
1395 tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL);
1397 return ERR_PTR(-ENOMEM);
1399 INIT_LIST_HEAD(&tz->thermal_instances);
1401 mutex_init(&tz->lock);
1402 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
1405 return ERR_PTR(result);
1408 strlcpy(tz->type, type ? : "", sizeof(tz->type));
1411 tz->device.class = &thermal_class;
1412 tz->devdata = devdata;
1414 tz->passive_delay = passive_delay;
1415 tz->polling_delay = polling_delay;
1417 dev_set_name(&tz->device, "thermal_zone%d", tz->id);
1418 result = device_register(&tz->device);
1420 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1422 return ERR_PTR(result);
1427 result = device_create_file(&tz->device, &dev_attr_type);
1432 result = device_create_file(&tz->device, &dev_attr_temp);
1436 if (ops->get_mode) {
1437 result = device_create_file(&tz->device, &dev_attr_mode);
1442 result = create_trip_attrs(tz, mask);
1446 for (count = 0; count < trips; count++) {
1447 tz->ops->get_trip_type(tz, count, &trip_type);
1448 if (trip_type == THERMAL_TRIP_PASSIVE)
1453 result = device_create_file(&tz->device, &dev_attr_passive);
1458 #ifdef CONFIG_THERMAL_EMULATION
1459 result = device_create_file(&tz->device, &dev_attr_emul_temp);
1463 /* Create policy attribute */
1464 result = device_create_file(&tz->device, &dev_attr_policy);
1468 /* Update 'this' zone's governor information */
1469 mutex_lock(&thermal_governor_lock);
1472 tz->governor = __find_governor(tz->tzp->governor_name);
1474 tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
1476 mutex_unlock(&thermal_governor_lock);
1478 if (!tz->tzp || !tz->tzp->no_hwmon) {
1479 result = thermal_add_hwmon_sysfs(tz);
1484 mutex_lock(&thermal_list_lock);
1485 list_add_tail(&tz->node, &thermal_tz_list);
1486 mutex_unlock(&thermal_list_lock);
1488 /* Bind cooling devices for this zone */
1491 INIT_DELAYED_WORK(&(tz->poll_queue), thermal_zone_device_check);
1493 thermal_zone_device_update(tz);
1499 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1500 device_unregister(&tz->device);
1501 return ERR_PTR(result);
1503 EXPORT_SYMBOL_GPL(thermal_zone_device_register);
1506 * thermal_device_unregister - removes the registered thermal zone device
1507 * @tz: the thermal zone device to remove
1509 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1512 const struct thermal_zone_params *tzp;
1513 struct thermal_cooling_device *cdev;
1514 struct thermal_zone_device *pos = NULL;
1521 mutex_lock(&thermal_list_lock);
1522 list_for_each_entry(pos, &thermal_tz_list, node)
1526 /* thermal zone device not found */
1527 mutex_unlock(&thermal_list_lock);
1530 list_del(&tz->node);
1532 /* Unbind all cdevs associated with 'this' thermal zone */
1533 list_for_each_entry(cdev, &thermal_cdev_list, node) {
1534 if (tz->ops->unbind) {
1535 tz->ops->unbind(tz, cdev);
1539 if (!tzp || !tzp->tbp)
1542 for (i = 0; i < tzp->num_tbps; i++) {
1543 if (tzp->tbp[i].cdev == cdev) {
1544 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1545 tzp->tbp[i].cdev = NULL;
1550 mutex_unlock(&thermal_list_lock);
1552 thermal_zone_device_set_polling(tz, 0);
1555 device_remove_file(&tz->device, &dev_attr_type);
1556 device_remove_file(&tz->device, &dev_attr_temp);
1557 if (tz->ops->get_mode)
1558 device_remove_file(&tz->device, &dev_attr_mode);
1559 device_remove_file(&tz->device, &dev_attr_policy);
1560 remove_trip_attrs(tz);
1561 tz->governor = NULL;
1563 thermal_remove_hwmon_sysfs(tz);
1564 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1565 idr_destroy(&tz->idr);
1566 mutex_destroy(&tz->lock);
1567 device_unregister(&tz->device);
1570 EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
1573 * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
1574 * @name: thermal zone name to fetch the temperature
1576 * When only one zone is found with the passed name, returns a reference to it.
1578 * Return: On success returns a reference to an unique thermal zone with
1579 * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
1580 * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
1582 struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
1584 struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
1585 unsigned int found = 0;
1590 mutex_lock(&thermal_list_lock);
1591 list_for_each_entry(pos, &thermal_tz_list, node)
1592 if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
1596 mutex_unlock(&thermal_list_lock);
1598 /* nothing has been found, thus an error code for it */
1600 ref = ERR_PTR(-ENODEV);
1602 /* Success only when an unique zone is found */
1603 ref = ERR_PTR(-EEXIST);
1608 EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
1611 static struct genl_family thermal_event_genl_family = {
1612 .id = GENL_ID_GENERATE,
1613 .name = THERMAL_GENL_FAMILY_NAME,
1614 .version = THERMAL_GENL_VERSION,
1615 .maxattr = THERMAL_GENL_ATTR_MAX,
1618 static struct genl_multicast_group thermal_event_mcgrp = {
1619 .name = THERMAL_GENL_MCAST_GROUP_NAME,
1622 int thermal_generate_netlink_event(struct thermal_zone_device *tz,
1625 struct sk_buff *skb;
1626 struct nlattr *attr;
1627 struct thermal_genl_event *thermal_event;
1631 static unsigned int thermal_event_seqnum;
1636 /* allocate memory */
1637 size = nla_total_size(sizeof(struct thermal_genl_event)) +
1640 skb = genlmsg_new(size, GFP_ATOMIC);
1644 /* add the genetlink message header */
1645 msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++,
1646 &thermal_event_genl_family, 0,
1647 THERMAL_GENL_CMD_EVENT);
1654 attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT,
1655 sizeof(struct thermal_genl_event));
1662 thermal_event = nla_data(attr);
1663 if (!thermal_event) {
1668 memset(thermal_event, 0, sizeof(struct thermal_genl_event));
1670 thermal_event->orig = tz->id;
1671 thermal_event->event = event;
1673 /* send multicast genetlink message */
1674 result = genlmsg_end(skb, msg_header);
1680 result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC);
1682 dev_err(&tz->device, "Failed to send netlink event:%d", result);
1686 EXPORT_SYMBOL_GPL(thermal_generate_netlink_event);
1688 static int genetlink_init(void)
1692 result = genl_register_family(&thermal_event_genl_family);
1696 result = genl_register_mc_group(&thermal_event_genl_family,
1697 &thermal_event_mcgrp);
1699 genl_unregister_family(&thermal_event_genl_family);
1703 static void genetlink_exit(void)
1705 genl_unregister_family(&thermal_event_genl_family);
1707 #else /* !CONFIG_NET */
1708 static inline int genetlink_init(void) { return 0; }
1709 static inline void genetlink_exit(void) {}
1710 #endif /* !CONFIG_NET */
1712 static int __init thermal_register_governors(void)
1716 result = thermal_gov_step_wise_register();
1720 result = thermal_gov_fair_share_register();
1724 return thermal_gov_user_space_register();
1727 static void thermal_unregister_governors(void)
1729 thermal_gov_step_wise_unregister();
1730 thermal_gov_fair_share_unregister();
1731 thermal_gov_user_space_unregister();
1734 static int __init thermal_init(void)
1738 result = thermal_register_governors();
1742 result = class_register(&thermal_class);
1744 goto unregister_governors;
1746 result = genetlink_init();
1748 goto unregister_class;
1752 unregister_governors:
1753 thermal_unregister_governors();
1755 class_unregister(&thermal_class);
1757 idr_destroy(&thermal_tz_idr);
1758 idr_destroy(&thermal_cdev_idr);
1759 mutex_destroy(&thermal_idr_lock);
1760 mutex_destroy(&thermal_list_lock);
1761 mutex_destroy(&thermal_governor_lock);
1765 static void __exit thermal_exit(void)
1768 class_unregister(&thermal_class);
1769 thermal_unregister_governors();
1770 idr_destroy(&thermal_tz_idr);
1771 idr_destroy(&thermal_cdev_idr);
1772 mutex_destroy(&thermal_idr_lock);
1773 mutex_destroy(&thermal_list_lock);
1774 mutex_destroy(&thermal_governor_lock);
1777 fs_initcall(thermal_init);
1778 module_exit(thermal_exit);