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/spinlock.h>
36 #include <linux/reboot.h>
37 #include <net/netlink.h>
38 #include <net/genetlink.h>
40 #include "thermal_core.h"
42 MODULE_AUTHOR("Zhang Rui");
43 MODULE_DESCRIPTION("Generic thermal management sysfs support");
44 MODULE_LICENSE("GPL");
46 static DEFINE_IDR(thermal_tz_idr);
47 static DEFINE_IDR(thermal_cdev_idr);
48 static DEFINE_MUTEX(thermal_idr_lock);
50 static LIST_HEAD(thermal_tz_list);
51 static LIST_HEAD(thermal_cdev_list);
52 static LIST_HEAD(thermal_governor_list);
54 static DEFINE_MUTEX(thermal_list_lock);
55 static DEFINE_MUTEX(thermal_governor_lock);
57 static struct thermal_governor *__find_governor(const char *name)
59 struct thermal_governor *pos;
61 list_for_each_entry(pos, &thermal_governor_list, governor_list)
62 if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
68 int thermal_register_governor(struct thermal_governor *governor)
72 struct thermal_zone_device *pos;
77 mutex_lock(&thermal_governor_lock);
80 if (__find_governor(governor->name) == NULL) {
82 list_add(&governor->governor_list, &thermal_governor_list);
85 mutex_lock(&thermal_list_lock);
87 list_for_each_entry(pos, &thermal_tz_list, node) {
91 name = pos->tzp->governor_name;
93 name = DEFAULT_THERMAL_GOVERNOR;
94 if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
95 pos->governor = governor;
98 mutex_unlock(&thermal_list_lock);
99 mutex_unlock(&thermal_governor_lock);
103 EXPORT_SYMBOL_GPL(thermal_register_governor);
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);
131 EXPORT_SYMBOL_GPL(thermal_unregister_governor);
133 static int get_idr(struct idr *idr, struct mutex *lock, int *id)
138 if (unlikely(idr_pre_get(idr, GFP_KERNEL) == 0))
143 err = idr_get_new(idr, NULL, id);
146 if (unlikely(err == -EAGAIN))
148 else if (unlikely(err))
151 *id = *id & MAX_IDR_MASK;
155 static void release_idr(struct idr *idr, struct mutex *lock, int id)
164 int get_tz_trend(struct thermal_zone_device *tz, int trip)
166 enum thermal_trend trend;
168 if (!tz->ops->get_trend || tz->ops->get_trend(tz, trip, &trend)) {
169 if (tz->temperature > tz->last_temperature)
170 trend = THERMAL_TREND_RAISING;
171 else if (tz->temperature < tz->last_temperature)
172 trend = THERMAL_TREND_DROPPING;
174 trend = THERMAL_TREND_STABLE;
179 EXPORT_SYMBOL(get_tz_trend);
181 struct thermal_instance *get_thermal_instance(struct thermal_zone_device *tz,
182 struct thermal_cooling_device *cdev, int trip)
184 struct thermal_instance *pos = NULL;
185 struct thermal_instance *target_instance = NULL;
187 mutex_lock(&tz->lock);
188 mutex_lock(&cdev->lock);
190 list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
191 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
192 target_instance = pos;
197 mutex_unlock(&cdev->lock);
198 mutex_unlock(&tz->lock);
200 return target_instance;
202 EXPORT_SYMBOL(get_thermal_instance);
204 static void print_bind_err_msg(struct thermal_zone_device *tz,
205 struct thermal_cooling_device *cdev, int ret)
207 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n",
208 tz->type, cdev->type, ret);
211 static void __bind(struct thermal_zone_device *tz, int mask,
212 struct thermal_cooling_device *cdev)
216 for (i = 0; i < tz->trips; i++) {
217 if (mask & (1 << i)) {
218 ret = thermal_zone_bind_cooling_device(tz, i, cdev,
219 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
221 print_bind_err_msg(tz, cdev, ret);
226 static void __unbind(struct thermal_zone_device *tz, int mask,
227 struct thermal_cooling_device *cdev)
231 for (i = 0; i < tz->trips; i++)
233 thermal_zone_unbind_cooling_device(tz, i, cdev);
236 static void bind_cdev(struct thermal_cooling_device *cdev)
239 const struct thermal_zone_params *tzp;
240 struct thermal_zone_device *pos = NULL;
242 mutex_lock(&thermal_list_lock);
244 list_for_each_entry(pos, &thermal_tz_list, node) {
245 if (!pos->tzp && !pos->ops->bind)
248 if (!pos->tzp && pos->ops->bind) {
249 ret = pos->ops->bind(pos, cdev);
251 print_bind_err_msg(pos, cdev, ret);
255 if (!tzp || !tzp->tbp)
258 for (i = 0; i < tzp->num_tbps; i++) {
259 if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
261 if (tzp->tbp[i].match(pos, cdev))
263 tzp->tbp[i].cdev = cdev;
264 __bind(pos, tzp->tbp[i].trip_mask, cdev);
268 mutex_unlock(&thermal_list_lock);
271 static void bind_tz(struct thermal_zone_device *tz)
274 struct thermal_cooling_device *pos = NULL;
275 const struct thermal_zone_params *tzp = tz->tzp;
277 if (!tzp && !tz->ops->bind)
280 mutex_lock(&thermal_list_lock);
282 /* If there is no platform data, try to use ops->bind */
283 if (!tzp && tz->ops->bind) {
284 list_for_each_entry(pos, &thermal_cdev_list, node) {
285 ret = tz->ops->bind(tz, pos);
287 print_bind_err_msg(tz, pos, ret);
292 if (!tzp || !tzp->tbp)
295 list_for_each_entry(pos, &thermal_cdev_list, node) {
296 for (i = 0; i < tzp->num_tbps; i++) {
297 if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
299 if (tzp->tbp[i].match(tz, pos))
301 tzp->tbp[i].cdev = pos;
302 __bind(tz, tzp->tbp[i].trip_mask, pos);
306 mutex_unlock(&thermal_list_lock);
309 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
313 mod_delayed_work(system_freezable_wq, &tz->poll_queue,
314 round_jiffies(msecs_to_jiffies(delay)));
316 mod_delayed_work(system_freezable_wq, &tz->poll_queue,
317 msecs_to_jiffies(delay));
319 cancel_delayed_work(&tz->poll_queue);
322 static void monitor_thermal_zone(struct thermal_zone_device *tz)
324 mutex_lock(&tz->lock);
327 thermal_zone_device_set_polling(tz, tz->passive_delay);
328 else if (tz->polling_delay)
329 thermal_zone_device_set_polling(tz, tz->polling_delay);
331 thermal_zone_device_set_polling(tz, 0);
333 mutex_unlock(&tz->lock);
336 static void handle_non_critical_trips(struct thermal_zone_device *tz,
337 int trip, enum thermal_trip_type trip_type)
339 tz->governor->throttle(tz, trip);
342 static void handle_critical_trips(struct thermal_zone_device *tz,
343 int trip, enum thermal_trip_type trip_type)
347 tz->ops->get_trip_temp(tz, trip, &trip_temp);
349 /* If we have not crossed the trip_temp, we do not care. */
350 if (tz->temperature < trip_temp)
354 tz->ops->notify(tz, trip, trip_type);
356 if (trip_type == THERMAL_TRIP_CRITICAL) {
357 pr_emerg("Critical temperature reached(%d C),shutting down\n",
358 tz->temperature / 1000);
359 orderly_poweroff(true);
363 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
365 enum thermal_trip_type type;
367 tz->ops->get_trip_type(tz, trip, &type);
369 if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT)
370 handle_critical_trips(tz, trip, type);
372 handle_non_critical_trips(tz, trip, type);
374 * Alright, we handled this trip successfully.
375 * So, start monitoring again.
377 monitor_thermal_zone(tz);
380 static void update_temperature(struct thermal_zone_device *tz)
385 mutex_lock(&tz->lock);
387 ret = tz->ops->get_temp(tz, &temp);
389 pr_warn("failed to read out thermal zone %d\n", tz->id);
393 tz->last_temperature = tz->temperature;
394 tz->temperature = temp;
397 mutex_unlock(&tz->lock);
400 void thermal_zone_device_update(struct thermal_zone_device *tz)
404 update_temperature(tz);
406 for (count = 0; count < tz->trips; count++)
407 handle_thermal_trip(tz, count);
409 EXPORT_SYMBOL(thermal_zone_device_update);
411 static void thermal_zone_device_check(struct work_struct *work)
413 struct thermal_zone_device *tz = container_of(work, struct
416 thermal_zone_device_update(tz);
419 /* sys I/F for thermal zone */
421 #define to_thermal_zone(_dev) \
422 container_of(_dev, struct thermal_zone_device, device)
425 type_show(struct device *dev, struct device_attribute *attr, char *buf)
427 struct thermal_zone_device *tz = to_thermal_zone(dev);
429 return sprintf(buf, "%s\n", tz->type);
433 temp_show(struct device *dev, struct device_attribute *attr, char *buf)
435 struct thermal_zone_device *tz = to_thermal_zone(dev);
439 if (!tz->ops->get_temp)
442 ret = tz->ops->get_temp(tz, &temperature);
447 return sprintf(buf, "%ld\n", temperature);
451 mode_show(struct device *dev, struct device_attribute *attr, char *buf)
453 struct thermal_zone_device *tz = to_thermal_zone(dev);
454 enum thermal_device_mode mode;
457 if (!tz->ops->get_mode)
460 result = tz->ops->get_mode(tz, &mode);
464 return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled"
469 mode_store(struct device *dev, struct device_attribute *attr,
470 const char *buf, size_t count)
472 struct thermal_zone_device *tz = to_thermal_zone(dev);
475 if (!tz->ops->set_mode)
478 if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
479 result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
480 else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
481 result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
492 trip_point_type_show(struct device *dev, struct device_attribute *attr,
495 struct thermal_zone_device *tz = to_thermal_zone(dev);
496 enum thermal_trip_type type;
499 if (!tz->ops->get_trip_type)
502 if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip))
505 result = tz->ops->get_trip_type(tz, trip, &type);
510 case THERMAL_TRIP_CRITICAL:
511 return sprintf(buf, "critical\n");
512 case THERMAL_TRIP_HOT:
513 return sprintf(buf, "hot\n");
514 case THERMAL_TRIP_PASSIVE:
515 return sprintf(buf, "passive\n");
516 case THERMAL_TRIP_ACTIVE:
517 return sprintf(buf, "active\n");
519 return sprintf(buf, "unknown\n");
524 trip_point_temp_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);
529 unsigned long temperature;
531 if (!tz->ops->set_trip_temp)
534 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
537 if (kstrtoul(buf, 10, &temperature))
540 ret = tz->ops->set_trip_temp(tz, trip, temperature);
542 return ret ? ret : count;
546 trip_point_temp_show(struct device *dev, struct device_attribute *attr,
549 struct thermal_zone_device *tz = to_thermal_zone(dev);
553 if (!tz->ops->get_trip_temp)
556 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
559 ret = tz->ops->get_trip_temp(tz, trip, &temperature);
564 return sprintf(buf, "%ld\n", temperature);
568 trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
569 const char *buf, size_t count)
571 struct thermal_zone_device *tz = to_thermal_zone(dev);
573 unsigned long temperature;
575 if (!tz->ops->set_trip_hyst)
578 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
581 if (kstrtoul(buf, 10, &temperature))
585 * We are not doing any check on the 'temperature' value
586 * here. The driver implementing 'set_trip_hyst' has to
589 ret = tz->ops->set_trip_hyst(tz, trip, temperature);
591 return ret ? ret : count;
595 trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
598 struct thermal_zone_device *tz = to_thermal_zone(dev);
600 unsigned long temperature;
602 if (!tz->ops->get_trip_hyst)
605 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
608 ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
610 return ret ? ret : sprintf(buf, "%ld\n", temperature);
614 passive_store(struct device *dev, struct device_attribute *attr,
615 const char *buf, size_t count)
617 struct thermal_zone_device *tz = to_thermal_zone(dev);
618 struct thermal_cooling_device *cdev = NULL;
621 if (!sscanf(buf, "%d\n", &state))
624 /* sanity check: values below 1000 millicelcius don't make sense
625 * and can cause the system to go into a thermal heart attack
627 if (state && state < 1000)
630 if (state && !tz->forced_passive) {
631 mutex_lock(&thermal_list_lock);
632 list_for_each_entry(cdev, &thermal_cdev_list, node) {
633 if (!strncmp("Processor", cdev->type,
634 sizeof("Processor")))
635 thermal_zone_bind_cooling_device(tz,
636 THERMAL_TRIPS_NONE, cdev,
640 mutex_unlock(&thermal_list_lock);
641 if (!tz->passive_delay)
642 tz->passive_delay = 1000;
643 } else if (!state && tz->forced_passive) {
644 mutex_lock(&thermal_list_lock);
645 list_for_each_entry(cdev, &thermal_cdev_list, node) {
646 if (!strncmp("Processor", cdev->type,
647 sizeof("Processor")))
648 thermal_zone_unbind_cooling_device(tz,
652 mutex_unlock(&thermal_list_lock);
653 tz->passive_delay = 0;
656 tz->forced_passive = state;
658 thermal_zone_device_update(tz);
664 passive_show(struct device *dev, struct device_attribute *attr,
667 struct thermal_zone_device *tz = to_thermal_zone(dev);
669 return sprintf(buf, "%d\n", tz->forced_passive);
673 policy_store(struct device *dev, struct device_attribute *attr,
674 const char *buf, size_t count)
677 struct thermal_zone_device *tz = to_thermal_zone(dev);
678 struct thermal_governor *gov;
680 mutex_lock(&thermal_governor_lock);
682 gov = __find_governor(buf);
690 mutex_unlock(&thermal_governor_lock);
695 policy_show(struct device *dev, struct device_attribute *devattr, char *buf)
697 struct thermal_zone_device *tz = to_thermal_zone(dev);
699 return sprintf(buf, "%s\n", tz->governor->name);
702 static DEVICE_ATTR(type, 0444, type_show, NULL);
703 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
704 static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
705 static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
706 static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
708 /* sys I/F for cooling device */
709 #define to_cooling_device(_dev) \
710 container_of(_dev, struct thermal_cooling_device, device)
713 thermal_cooling_device_type_show(struct device *dev,
714 struct device_attribute *attr, char *buf)
716 struct thermal_cooling_device *cdev = to_cooling_device(dev);
718 return sprintf(buf, "%s\n", cdev->type);
722 thermal_cooling_device_max_state_show(struct device *dev,
723 struct device_attribute *attr, char *buf)
725 struct thermal_cooling_device *cdev = to_cooling_device(dev);
729 ret = cdev->ops->get_max_state(cdev, &state);
732 return sprintf(buf, "%ld\n", state);
736 thermal_cooling_device_cur_state_show(struct device *dev,
737 struct device_attribute *attr, char *buf)
739 struct thermal_cooling_device *cdev = to_cooling_device(dev);
743 ret = cdev->ops->get_cur_state(cdev, &state);
746 return sprintf(buf, "%ld\n", state);
750 thermal_cooling_device_cur_state_store(struct device *dev,
751 struct device_attribute *attr,
752 const char *buf, size_t count)
754 struct thermal_cooling_device *cdev = to_cooling_device(dev);
758 if (!sscanf(buf, "%ld\n", &state))
764 result = cdev->ops->set_cur_state(cdev, state);
770 static struct device_attribute dev_attr_cdev_type =
771 __ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
772 static DEVICE_ATTR(max_state, 0444,
773 thermal_cooling_device_max_state_show, NULL);
774 static DEVICE_ATTR(cur_state, 0644,
775 thermal_cooling_device_cur_state_show,
776 thermal_cooling_device_cur_state_store);
779 thermal_cooling_device_trip_point_show(struct device *dev,
780 struct device_attribute *attr, char *buf)
782 struct thermal_instance *instance;
785 container_of(attr, struct thermal_instance, attr);
787 if (instance->trip == THERMAL_TRIPS_NONE)
788 return sprintf(buf, "-1\n");
790 return sprintf(buf, "%d\n", instance->trip);
793 /* Device management */
795 #if defined(CONFIG_THERMAL_HWMON)
798 #include <linux/hwmon.h>
800 /* thermal zone devices with the same type share one hwmon device */
801 struct thermal_hwmon_device {
802 char type[THERMAL_NAME_LENGTH];
803 struct device *device;
805 struct list_head tz_list;
806 struct list_head node;
809 struct thermal_hwmon_attr {
810 struct device_attribute attr;
814 /* one temperature input for each thermal zone */
815 struct thermal_hwmon_temp {
816 struct list_head hwmon_node;
817 struct thermal_zone_device *tz;
818 struct thermal_hwmon_attr temp_input; /* hwmon sys attr */
819 struct thermal_hwmon_attr temp_crit; /* hwmon sys attr */
822 static LIST_HEAD(thermal_hwmon_list);
825 name_show(struct device *dev, struct device_attribute *attr, char *buf)
827 struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
828 return sprintf(buf, "%s\n", hwmon->type);
830 static DEVICE_ATTR(name, 0444, name_show, NULL);
833 temp_input_show(struct device *dev, struct device_attribute *attr, char *buf)
837 struct thermal_hwmon_attr *hwmon_attr
838 = container_of(attr, struct thermal_hwmon_attr, attr);
839 struct thermal_hwmon_temp *temp
840 = container_of(hwmon_attr, struct thermal_hwmon_temp,
842 struct thermal_zone_device *tz = temp->tz;
844 ret = tz->ops->get_temp(tz, &temperature);
849 return sprintf(buf, "%ld\n", temperature);
853 temp_crit_show(struct device *dev, struct device_attribute *attr,
856 struct thermal_hwmon_attr *hwmon_attr
857 = container_of(attr, struct thermal_hwmon_attr, attr);
858 struct thermal_hwmon_temp *temp
859 = container_of(hwmon_attr, struct thermal_hwmon_temp,
861 struct thermal_zone_device *tz = temp->tz;
865 ret = tz->ops->get_trip_temp(tz, 0, &temperature);
869 return sprintf(buf, "%ld\n", temperature);
873 static struct thermal_hwmon_device *
874 thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz)
876 struct thermal_hwmon_device *hwmon;
878 mutex_lock(&thermal_list_lock);
879 list_for_each_entry(hwmon, &thermal_hwmon_list, node)
880 if (!strcmp(hwmon->type, tz->type)) {
881 mutex_unlock(&thermal_list_lock);
884 mutex_unlock(&thermal_list_lock);
889 /* Find the temperature input matching a given thermal zone */
890 static struct thermal_hwmon_temp *
891 thermal_hwmon_lookup_temp(const struct thermal_hwmon_device *hwmon,
892 const struct thermal_zone_device *tz)
894 struct thermal_hwmon_temp *temp;
896 mutex_lock(&thermal_list_lock);
897 list_for_each_entry(temp, &hwmon->tz_list, hwmon_node)
898 if (temp->tz == tz) {
899 mutex_unlock(&thermal_list_lock);
902 mutex_unlock(&thermal_list_lock);
908 thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
910 struct thermal_hwmon_device *hwmon;
911 struct thermal_hwmon_temp *temp;
912 int new_hwmon_device = 1;
915 hwmon = thermal_hwmon_lookup_by_type(tz);
917 new_hwmon_device = 0;
918 goto register_sys_interface;
921 hwmon = kzalloc(sizeof(struct thermal_hwmon_device), GFP_KERNEL);
925 INIT_LIST_HEAD(&hwmon->tz_list);
926 strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
927 hwmon->device = hwmon_device_register(NULL);
928 if (IS_ERR(hwmon->device)) {
929 result = PTR_ERR(hwmon->device);
932 dev_set_drvdata(hwmon->device, hwmon);
933 result = device_create_file(hwmon->device, &dev_attr_name);
937 register_sys_interface:
938 temp = kzalloc(sizeof(struct thermal_hwmon_temp), GFP_KERNEL);
941 goto unregister_name;
947 snprintf(temp->temp_input.name, sizeof(temp->temp_input.name),
948 "temp%d_input", hwmon->count);
949 temp->temp_input.attr.attr.name = temp->temp_input.name;
950 temp->temp_input.attr.attr.mode = 0444;
951 temp->temp_input.attr.show = temp_input_show;
952 sysfs_attr_init(&temp->temp_input.attr.attr);
953 result = device_create_file(hwmon->device, &temp->temp_input.attr);
957 if (tz->ops->get_crit_temp) {
958 unsigned long temperature;
959 if (!tz->ops->get_crit_temp(tz, &temperature)) {
960 snprintf(temp->temp_crit.name,
961 sizeof(temp->temp_crit.name),
962 "temp%d_crit", hwmon->count);
963 temp->temp_crit.attr.attr.name = temp->temp_crit.name;
964 temp->temp_crit.attr.attr.mode = 0444;
965 temp->temp_crit.attr.show = temp_crit_show;
966 sysfs_attr_init(&temp->temp_crit.attr.attr);
967 result = device_create_file(hwmon->device,
968 &temp->temp_crit.attr);
970 goto unregister_input;
974 mutex_lock(&thermal_list_lock);
975 if (new_hwmon_device)
976 list_add_tail(&hwmon->node, &thermal_hwmon_list);
977 list_add_tail(&temp->hwmon_node, &hwmon->tz_list);
978 mutex_unlock(&thermal_list_lock);
983 device_remove_file(hwmon->device, &temp->temp_input.attr);
987 if (new_hwmon_device) {
988 device_remove_file(hwmon->device, &dev_attr_name);
989 hwmon_device_unregister(hwmon->device);
992 if (new_hwmon_device)
999 thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
1001 struct thermal_hwmon_device *hwmon;
1002 struct thermal_hwmon_temp *temp;
1004 hwmon = thermal_hwmon_lookup_by_type(tz);
1005 if (unlikely(!hwmon)) {
1006 /* Should never happen... */
1007 dev_dbg(&tz->device, "hwmon device lookup failed!\n");
1011 temp = thermal_hwmon_lookup_temp(hwmon, tz);
1012 if (unlikely(!temp)) {
1013 /* Should never happen... */
1014 dev_dbg(&tz->device, "temperature input lookup failed!\n");
1018 device_remove_file(hwmon->device, &temp->temp_input.attr);
1019 if (tz->ops->get_crit_temp)
1020 device_remove_file(hwmon->device, &temp->temp_crit.attr);
1022 mutex_lock(&thermal_list_lock);
1023 list_del(&temp->hwmon_node);
1025 if (!list_empty(&hwmon->tz_list)) {
1026 mutex_unlock(&thermal_list_lock);
1029 list_del(&hwmon->node);
1030 mutex_unlock(&thermal_list_lock);
1032 device_remove_file(hwmon->device, &dev_attr_name);
1033 hwmon_device_unregister(hwmon->device);
1038 thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
1044 thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
1050 * thermal_zone_bind_cooling_device - bind a cooling device to a thermal zone
1051 * @tz: thermal zone device
1052 * @trip: indicates which trip point the cooling devices is
1053 * associated with in this thermal zone.
1054 * @cdev: thermal cooling device
1056 * This function is usually called in the thermal zone device .bind callback.
1058 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
1060 struct thermal_cooling_device *cdev,
1061 unsigned long upper, unsigned long lower)
1063 struct thermal_instance *dev;
1064 struct thermal_instance *pos;
1065 struct thermal_zone_device *pos1;
1066 struct thermal_cooling_device *pos2;
1067 unsigned long max_state;
1070 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
1073 list_for_each_entry(pos1, &thermal_tz_list, node) {
1077 list_for_each_entry(pos2, &thermal_cdev_list, node) {
1082 if (tz != pos1 || cdev != pos2)
1085 cdev->ops->get_max_state(cdev, &max_state);
1087 /* lower default 0, upper default max_state */
1088 lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
1089 upper = upper == THERMAL_NO_LIMIT ? max_state : upper;
1091 if (lower > upper || upper > max_state)
1095 kzalloc(sizeof(struct thermal_instance), GFP_KERNEL);
1103 dev->target = THERMAL_NO_TARGET;
1105 result = get_idr(&tz->idr, &tz->lock, &dev->id);
1109 sprintf(dev->name, "cdev%d", dev->id);
1111 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
1115 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
1116 sysfs_attr_init(&dev->attr.attr);
1117 dev->attr.attr.name = dev->attr_name;
1118 dev->attr.attr.mode = 0444;
1119 dev->attr.show = thermal_cooling_device_trip_point_show;
1120 result = device_create_file(&tz->device, &dev->attr);
1122 goto remove_symbol_link;
1124 mutex_lock(&tz->lock);
1125 mutex_lock(&cdev->lock);
1126 list_for_each_entry(pos, &tz->thermal_instances, tz_node)
1127 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
1132 list_add_tail(&dev->tz_node, &tz->thermal_instances);
1133 list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
1135 mutex_unlock(&cdev->lock);
1136 mutex_unlock(&tz->lock);
1141 device_remove_file(&tz->device, &dev->attr);
1143 sysfs_remove_link(&tz->device.kobj, dev->name);
1145 release_idr(&tz->idr, &tz->lock, dev->id);
1150 EXPORT_SYMBOL(thermal_zone_bind_cooling_device);
1153 * thermal_zone_unbind_cooling_device - unbind a cooling device from a thermal zone
1154 * @tz: thermal zone device
1155 * @trip: indicates which trip point the cooling devices is
1156 * associated with in this thermal zone.
1157 * @cdev: thermal cooling device
1159 * This function is usually called in the thermal zone device .unbind callback.
1161 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
1163 struct thermal_cooling_device *cdev)
1165 struct thermal_instance *pos, *next;
1167 mutex_lock(&tz->lock);
1168 mutex_lock(&cdev->lock);
1169 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
1170 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
1171 list_del(&pos->tz_node);
1172 list_del(&pos->cdev_node);
1173 mutex_unlock(&cdev->lock);
1174 mutex_unlock(&tz->lock);
1178 mutex_unlock(&cdev->lock);
1179 mutex_unlock(&tz->lock);
1184 device_remove_file(&tz->device, &pos->attr);
1185 sysfs_remove_link(&tz->device.kobj, pos->name);
1186 release_idr(&tz->idr, &tz->lock, pos->id);
1190 EXPORT_SYMBOL(thermal_zone_unbind_cooling_device);
1192 static void thermal_release(struct device *dev)
1194 struct thermal_zone_device *tz;
1195 struct thermal_cooling_device *cdev;
1197 if (!strncmp(dev_name(dev), "thermal_zone",
1198 sizeof("thermal_zone") - 1)) {
1199 tz = to_thermal_zone(dev);
1202 cdev = to_cooling_device(dev);
1207 static struct class thermal_class = {
1209 .dev_release = thermal_release,
1213 * thermal_cooling_device_register - register a new thermal cooling device
1214 * @type: the thermal cooling device type.
1215 * @devdata: device private data.
1216 * @ops: standard thermal cooling devices callbacks.
1218 struct thermal_cooling_device *
1219 thermal_cooling_device_register(char *type, void *devdata,
1220 const struct thermal_cooling_device_ops *ops)
1222 struct thermal_cooling_device *cdev;
1225 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1226 return ERR_PTR(-EINVAL);
1228 if (!ops || !ops->get_max_state || !ops->get_cur_state ||
1229 !ops->set_cur_state)
1230 return ERR_PTR(-EINVAL);
1232 cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL);
1234 return ERR_PTR(-ENOMEM);
1236 result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
1239 return ERR_PTR(result);
1242 strcpy(cdev->type, type ? : "");
1243 mutex_init(&cdev->lock);
1244 INIT_LIST_HEAD(&cdev->thermal_instances);
1246 cdev->updated = true;
1247 cdev->device.class = &thermal_class;
1248 cdev->devdata = devdata;
1249 dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
1250 result = device_register(&cdev->device);
1252 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1254 return ERR_PTR(result);
1259 result = device_create_file(&cdev->device, &dev_attr_cdev_type);
1264 result = device_create_file(&cdev->device, &dev_attr_max_state);
1268 result = device_create_file(&cdev->device, &dev_attr_cur_state);
1272 /* Add 'this' new cdev to the global cdev list */
1273 mutex_lock(&thermal_list_lock);
1274 list_add(&cdev->node, &thermal_cdev_list);
1275 mutex_unlock(&thermal_list_lock);
1277 /* Update binding information for 'this' new cdev */
1283 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1284 device_unregister(&cdev->device);
1285 return ERR_PTR(result);
1287 EXPORT_SYMBOL(thermal_cooling_device_register);
1290 * thermal_cooling_device_unregister - removes the registered thermal cooling device
1291 * @cdev: the thermal cooling device to remove.
1293 * thermal_cooling_device_unregister() must be called when the device is no
1296 void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
1299 const struct thermal_zone_params *tzp;
1300 struct thermal_zone_device *tz;
1301 struct thermal_cooling_device *pos = NULL;
1306 mutex_lock(&thermal_list_lock);
1307 list_for_each_entry(pos, &thermal_cdev_list, node)
1311 /* thermal cooling device not found */
1312 mutex_unlock(&thermal_list_lock);
1315 list_del(&cdev->node);
1317 /* Unbind all thermal zones associated with 'this' cdev */
1318 list_for_each_entry(tz, &thermal_tz_list, node) {
1319 if (tz->ops->unbind) {
1320 tz->ops->unbind(tz, cdev);
1324 if (!tz->tzp || !tz->tzp->tbp)
1328 for (i = 0; i < tzp->num_tbps; i++) {
1329 if (tzp->tbp[i].cdev == cdev) {
1330 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1331 tzp->tbp[i].cdev = NULL;
1336 mutex_unlock(&thermal_list_lock);
1339 device_remove_file(&cdev->device, &dev_attr_cdev_type);
1340 device_remove_file(&cdev->device, &dev_attr_max_state);
1341 device_remove_file(&cdev->device, &dev_attr_cur_state);
1343 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1344 device_unregister(&cdev->device);
1347 EXPORT_SYMBOL(thermal_cooling_device_unregister);
1349 void thermal_cdev_update(struct thermal_cooling_device *cdev)
1351 struct thermal_instance *instance;
1352 unsigned long target = 0;
1354 /* cooling device is updated*/
1358 mutex_lock(&cdev->lock);
1359 /* Make sure cdev enters the deepest cooling state */
1360 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
1361 if (instance->target == THERMAL_NO_TARGET)
1363 if (instance->target > target)
1364 target = instance->target;
1366 mutex_unlock(&cdev->lock);
1367 cdev->ops->set_cur_state(cdev, target);
1368 cdev->updated = true;
1370 EXPORT_SYMBOL(thermal_cdev_update);
1373 * notify_thermal_framework - Sensor drivers use this API to notify framework
1374 * @tz: thermal zone device
1375 * @trip: indicates which trip point has been crossed
1377 * This function handles the trip events from sensor drivers. It starts
1378 * throttling the cooling devices according to the policy configured.
1379 * For CRITICAL and HOT trip points, this notifies the respective drivers,
1380 * and does actual throttling for other trip points i.e ACTIVE and PASSIVE.
1381 * The throttling policy is based on the configured platform data; if no
1382 * platform data is provided, this uses the step_wise throttling policy.
1384 void notify_thermal_framework(struct thermal_zone_device *tz, int trip)
1386 handle_thermal_trip(tz, trip);
1388 EXPORT_SYMBOL(notify_thermal_framework);
1391 * create_trip_attrs - create attributes for trip points
1392 * @tz: the thermal zone device
1393 * @mask: Writeable trip point bitmap.
1395 static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
1398 int size = sizeof(struct thermal_attr) * tz->trips;
1400 tz->trip_type_attrs = kzalloc(size, GFP_KERNEL);
1401 if (!tz->trip_type_attrs)
1404 tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL);
1405 if (!tz->trip_temp_attrs) {
1406 kfree(tz->trip_type_attrs);
1410 if (tz->ops->get_trip_hyst) {
1411 tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL);
1412 if (!tz->trip_hyst_attrs) {
1413 kfree(tz->trip_type_attrs);
1414 kfree(tz->trip_temp_attrs);
1420 for (indx = 0; indx < tz->trips; indx++) {
1421 /* create trip type attribute */
1422 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
1423 "trip_point_%d_type", indx);
1425 sysfs_attr_init(&tz->trip_type_attrs[indx].attr.attr);
1426 tz->trip_type_attrs[indx].attr.attr.name =
1427 tz->trip_type_attrs[indx].name;
1428 tz->trip_type_attrs[indx].attr.attr.mode = S_IRUGO;
1429 tz->trip_type_attrs[indx].attr.show = trip_point_type_show;
1431 device_create_file(&tz->device,
1432 &tz->trip_type_attrs[indx].attr);
1434 /* create trip temp attribute */
1435 snprintf(tz->trip_temp_attrs[indx].name, THERMAL_NAME_LENGTH,
1436 "trip_point_%d_temp", indx);
1438 sysfs_attr_init(&tz->trip_temp_attrs[indx].attr.attr);
1439 tz->trip_temp_attrs[indx].attr.attr.name =
1440 tz->trip_temp_attrs[indx].name;
1441 tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
1442 tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
1443 if (mask & (1 << indx)) {
1444 tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
1445 tz->trip_temp_attrs[indx].attr.store =
1446 trip_point_temp_store;
1449 device_create_file(&tz->device,
1450 &tz->trip_temp_attrs[indx].attr);
1452 /* create Optional trip hyst attribute */
1453 if (!tz->ops->get_trip_hyst)
1455 snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH,
1456 "trip_point_%d_hyst", indx);
1458 sysfs_attr_init(&tz->trip_hyst_attrs[indx].attr.attr);
1459 tz->trip_hyst_attrs[indx].attr.attr.name =
1460 tz->trip_hyst_attrs[indx].name;
1461 tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
1462 tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
1463 if (tz->ops->set_trip_hyst) {
1464 tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
1465 tz->trip_hyst_attrs[indx].attr.store =
1466 trip_point_hyst_store;
1469 device_create_file(&tz->device,
1470 &tz->trip_hyst_attrs[indx].attr);
1475 static void remove_trip_attrs(struct thermal_zone_device *tz)
1479 for (indx = 0; indx < tz->trips; indx++) {
1480 device_remove_file(&tz->device,
1481 &tz->trip_type_attrs[indx].attr);
1482 device_remove_file(&tz->device,
1483 &tz->trip_temp_attrs[indx].attr);
1484 if (tz->ops->get_trip_hyst)
1485 device_remove_file(&tz->device,
1486 &tz->trip_hyst_attrs[indx].attr);
1488 kfree(tz->trip_type_attrs);
1489 kfree(tz->trip_temp_attrs);
1490 kfree(tz->trip_hyst_attrs);
1494 * thermal_zone_device_register - register a new thermal zone device
1495 * @type: the thermal zone device type
1496 * @trips: the number of trip points the thermal zone support
1497 * @mask: a bit string indicating the writeablility of trip points
1498 * @devdata: private device data
1499 * @ops: standard thermal zone device callbacks
1500 * @tzp: thermal zone platform parameters
1501 * @passive_delay: number of milliseconds to wait between polls when
1502 * performing passive cooling
1503 * @polling_delay: number of milliseconds to wait between polls when checking
1504 * whether trip points have been crossed (0 for interrupt
1507 * thermal_zone_device_unregister() must be called when the device is no
1508 * longer needed. The passive cooling depends on the .get_trend() return value.
1510 struct thermal_zone_device *thermal_zone_device_register(const char *type,
1511 int trips, int mask, void *devdata,
1512 const struct thermal_zone_device_ops *ops,
1513 const struct thermal_zone_params *tzp,
1514 int passive_delay, int polling_delay)
1516 struct thermal_zone_device *tz;
1517 enum thermal_trip_type trip_type;
1522 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1523 return ERR_PTR(-EINVAL);
1525 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
1526 return ERR_PTR(-EINVAL);
1528 if (!ops || !ops->get_temp)
1529 return ERR_PTR(-EINVAL);
1531 tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL);
1533 return ERR_PTR(-ENOMEM);
1535 INIT_LIST_HEAD(&tz->thermal_instances);
1537 mutex_init(&tz->lock);
1538 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
1541 return ERR_PTR(result);
1544 strcpy(tz->type, type ? : "");
1547 tz->device.class = &thermal_class;
1548 tz->devdata = devdata;
1550 tz->passive_delay = passive_delay;
1551 tz->polling_delay = polling_delay;
1553 dev_set_name(&tz->device, "thermal_zone%d", tz->id);
1554 result = device_register(&tz->device);
1556 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1558 return ERR_PTR(result);
1563 result = device_create_file(&tz->device, &dev_attr_type);
1568 result = device_create_file(&tz->device, &dev_attr_temp);
1572 if (ops->get_mode) {
1573 result = device_create_file(&tz->device, &dev_attr_mode);
1578 result = create_trip_attrs(tz, mask);
1582 for (count = 0; count < trips; count++) {
1583 tz->ops->get_trip_type(tz, count, &trip_type);
1584 if (trip_type == THERMAL_TRIP_PASSIVE)
1589 result = device_create_file(&tz->device, &dev_attr_passive);
1594 /* Create policy attribute */
1595 result = device_create_file(&tz->device, &dev_attr_policy);
1599 /* Update 'this' zone's governor information */
1600 mutex_lock(&thermal_governor_lock);
1603 tz->governor = __find_governor(tz->tzp->governor_name);
1605 tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
1607 mutex_unlock(&thermal_governor_lock);
1609 result = thermal_add_hwmon_sysfs(tz);
1613 mutex_lock(&thermal_list_lock);
1614 list_add_tail(&tz->node, &thermal_tz_list);
1615 mutex_unlock(&thermal_list_lock);
1617 /* Bind cooling devices for this zone */
1620 INIT_DELAYED_WORK(&(tz->poll_queue), thermal_zone_device_check);
1622 thermal_zone_device_update(tz);
1628 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1629 device_unregister(&tz->device);
1630 return ERR_PTR(result);
1632 EXPORT_SYMBOL(thermal_zone_device_register);
1635 * thermal_device_unregister - removes the registered thermal zone device
1636 * @tz: the thermal zone device to remove
1638 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1641 const struct thermal_zone_params *tzp;
1642 struct thermal_cooling_device *cdev;
1643 struct thermal_zone_device *pos = NULL;
1650 mutex_lock(&thermal_list_lock);
1651 list_for_each_entry(pos, &thermal_tz_list, node)
1655 /* thermal zone device not found */
1656 mutex_unlock(&thermal_list_lock);
1659 list_del(&tz->node);
1661 /* Unbind all cdevs associated with 'this' thermal zone */
1662 list_for_each_entry(cdev, &thermal_cdev_list, node) {
1663 if (tz->ops->unbind) {
1664 tz->ops->unbind(tz, cdev);
1668 if (!tzp || !tzp->tbp)
1671 for (i = 0; i < tzp->num_tbps; i++) {
1672 if (tzp->tbp[i].cdev == cdev) {
1673 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1674 tzp->tbp[i].cdev = NULL;
1679 mutex_unlock(&thermal_list_lock);
1681 thermal_zone_device_set_polling(tz, 0);
1684 device_remove_file(&tz->device, &dev_attr_type);
1685 device_remove_file(&tz->device, &dev_attr_temp);
1686 if (tz->ops->get_mode)
1687 device_remove_file(&tz->device, &dev_attr_mode);
1688 device_remove_file(&tz->device, &dev_attr_policy);
1689 remove_trip_attrs(tz);
1690 tz->governor = NULL;
1692 thermal_remove_hwmon_sysfs(tz);
1693 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1694 idr_destroy(&tz->idr);
1695 mutex_destroy(&tz->lock);
1696 device_unregister(&tz->device);
1699 EXPORT_SYMBOL(thermal_zone_device_unregister);
1702 static struct genl_family thermal_event_genl_family = {
1703 .id = GENL_ID_GENERATE,
1704 .name = THERMAL_GENL_FAMILY_NAME,
1705 .version = THERMAL_GENL_VERSION,
1706 .maxattr = THERMAL_GENL_ATTR_MAX,
1709 static struct genl_multicast_group thermal_event_mcgrp = {
1710 .name = THERMAL_GENL_MCAST_GROUP_NAME,
1713 int thermal_generate_netlink_event(u32 orig, enum events event)
1715 struct sk_buff *skb;
1716 struct nlattr *attr;
1717 struct thermal_genl_event *thermal_event;
1721 static unsigned int thermal_event_seqnum;
1723 /* allocate memory */
1724 size = nla_total_size(sizeof(struct thermal_genl_event)) +
1727 skb = genlmsg_new(size, GFP_ATOMIC);
1731 /* add the genetlink message header */
1732 msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++,
1733 &thermal_event_genl_family, 0,
1734 THERMAL_GENL_CMD_EVENT);
1741 attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT,
1742 sizeof(struct thermal_genl_event));
1749 thermal_event = nla_data(attr);
1750 if (!thermal_event) {
1755 memset(thermal_event, 0, sizeof(struct thermal_genl_event));
1757 thermal_event->orig = orig;
1758 thermal_event->event = event;
1760 /* send multicast genetlink message */
1761 result = genlmsg_end(skb, msg_header);
1767 result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC);
1769 pr_info("failed to send netlink event:%d\n", result);
1773 EXPORT_SYMBOL(thermal_generate_netlink_event);
1775 static int genetlink_init(void)
1779 result = genl_register_family(&thermal_event_genl_family);
1783 result = genl_register_mc_group(&thermal_event_genl_family,
1784 &thermal_event_mcgrp);
1786 genl_unregister_family(&thermal_event_genl_family);
1790 static void genetlink_exit(void)
1792 genl_unregister_family(&thermal_event_genl_family);
1794 #else /* !CONFIG_NET */
1795 static inline int genetlink_init(void) { return 0; }
1796 static inline void genetlink_exit(void) {}
1797 #endif /* !CONFIG_NET */
1799 static int __init thermal_init(void)
1803 result = class_register(&thermal_class);
1805 idr_destroy(&thermal_tz_idr);
1806 idr_destroy(&thermal_cdev_idr);
1807 mutex_destroy(&thermal_idr_lock);
1808 mutex_destroy(&thermal_list_lock);
1810 result = genetlink_init();
1814 static void __exit thermal_exit(void)
1816 class_unregister(&thermal_class);
1817 idr_destroy(&thermal_tz_idr);
1818 idr_destroy(&thermal_cdev_idr);
1819 mutex_destroy(&thermal_idr_lock);
1820 mutex_destroy(&thermal_list_lock);
1824 fs_initcall(thermal_init);
1825 module_exit(thermal_exit);