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)
139 ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
142 if (unlikely(ret < 0))
148 static void release_idr(struct idr *idr, struct mutex *lock, int id)
157 int get_tz_trend(struct thermal_zone_device *tz, int trip)
159 enum thermal_trend trend;
161 if (!tz->ops->get_trend || 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)
209 for (i = 0; i < tz->trips; i++) {
210 if (mask & (1 << i)) {
211 ret = thermal_zone_bind_cooling_device(tz, i, cdev,
212 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
214 print_bind_err_msg(tz, cdev, ret);
219 static void __unbind(struct thermal_zone_device *tz, int mask,
220 struct thermal_cooling_device *cdev)
224 for (i = 0; i < tz->trips; i++)
226 thermal_zone_unbind_cooling_device(tz, i, cdev);
229 static void bind_cdev(struct thermal_cooling_device *cdev)
232 const struct thermal_zone_params *tzp;
233 struct thermal_zone_device *pos = NULL;
235 mutex_lock(&thermal_list_lock);
237 list_for_each_entry(pos, &thermal_tz_list, node) {
238 if (!pos->tzp && !pos->ops->bind)
241 if (!pos->tzp && pos->ops->bind) {
242 ret = pos->ops->bind(pos, cdev);
244 print_bind_err_msg(pos, cdev, ret);
248 if (!tzp || !tzp->tbp)
251 for (i = 0; i < tzp->num_tbps; i++) {
252 if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
254 if (tzp->tbp[i].match(pos, cdev))
256 tzp->tbp[i].cdev = cdev;
257 __bind(pos, tzp->tbp[i].trip_mask, cdev);
261 mutex_unlock(&thermal_list_lock);
264 static void bind_tz(struct thermal_zone_device *tz)
267 struct thermal_cooling_device *pos = NULL;
268 const struct thermal_zone_params *tzp = tz->tzp;
270 if (!tzp && !tz->ops->bind)
273 mutex_lock(&thermal_list_lock);
275 /* If there is no platform data, try to use ops->bind */
276 if (!tzp && tz->ops->bind) {
277 list_for_each_entry(pos, &thermal_cdev_list, node) {
278 ret = tz->ops->bind(tz, pos);
280 print_bind_err_msg(tz, pos, ret);
285 if (!tzp || !tzp->tbp)
288 list_for_each_entry(pos, &thermal_cdev_list, node) {
289 for (i = 0; i < tzp->num_tbps; i++) {
290 if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
292 if (tzp->tbp[i].match(tz, pos))
294 tzp->tbp[i].cdev = pos;
295 __bind(tz, tzp->tbp[i].trip_mask, pos);
299 mutex_unlock(&thermal_list_lock);
302 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
306 mod_delayed_work(system_freezable_wq, &tz->poll_queue,
307 round_jiffies(msecs_to_jiffies(delay)));
309 mod_delayed_work(system_freezable_wq, &tz->poll_queue,
310 msecs_to_jiffies(delay));
312 cancel_delayed_work(&tz->poll_queue);
315 static void monitor_thermal_zone(struct thermal_zone_device *tz)
317 mutex_lock(&tz->lock);
320 thermal_zone_device_set_polling(tz, tz->passive_delay);
321 else if (tz->polling_delay)
322 thermal_zone_device_set_polling(tz, tz->polling_delay);
324 thermal_zone_device_set_polling(tz, 0);
326 mutex_unlock(&tz->lock);
329 static void handle_non_critical_trips(struct thermal_zone_device *tz,
330 int trip, enum thermal_trip_type trip_type)
333 tz->governor->throttle(tz, trip);
336 static void handle_critical_trips(struct thermal_zone_device *tz,
337 int trip, enum thermal_trip_type trip_type)
341 tz->ops->get_trip_temp(tz, trip, &trip_temp);
343 /* If we have not crossed the trip_temp, we do not care. */
344 if (tz->temperature < trip_temp)
348 tz->ops->notify(tz, trip, trip_type);
350 if (trip_type == THERMAL_TRIP_CRITICAL) {
351 pr_emerg("Critical temperature reached(%d C),shutting down\n",
352 tz->temperature / 1000);
353 orderly_poweroff(true);
357 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
359 enum thermal_trip_type type;
361 tz->ops->get_trip_type(tz, trip, &type);
363 if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT)
364 handle_critical_trips(tz, trip, type);
366 handle_non_critical_trips(tz, trip, type);
368 * Alright, we handled this trip successfully.
369 * So, start monitoring again.
371 monitor_thermal_zone(tz);
374 static void update_temperature(struct thermal_zone_device *tz)
379 mutex_lock(&tz->lock);
381 ret = tz->ops->get_temp(tz, &temp);
383 pr_warn("failed to read out thermal zone %d\n", tz->id);
387 tz->last_temperature = tz->temperature;
388 tz->temperature = temp;
391 mutex_unlock(&tz->lock);
394 void thermal_zone_device_update(struct thermal_zone_device *tz)
398 update_temperature(tz);
400 for (count = 0; count < tz->trips; count++)
401 handle_thermal_trip(tz, count);
403 EXPORT_SYMBOL(thermal_zone_device_update);
405 static void thermal_zone_device_check(struct work_struct *work)
407 struct thermal_zone_device *tz = container_of(work, struct
410 thermal_zone_device_update(tz);
413 /* sys I/F for thermal zone */
415 #define to_thermal_zone(_dev) \
416 container_of(_dev, struct thermal_zone_device, device)
419 type_show(struct device *dev, struct device_attribute *attr, char *buf)
421 struct thermal_zone_device *tz = to_thermal_zone(dev);
423 return sprintf(buf, "%s\n", tz->type);
427 temp_show(struct device *dev, struct device_attribute *attr, char *buf)
429 struct thermal_zone_device *tz = to_thermal_zone(dev);
433 if (!tz->ops->get_temp)
436 ret = tz->ops->get_temp(tz, &temperature);
441 return sprintf(buf, "%ld\n", temperature);
445 mode_show(struct device *dev, struct device_attribute *attr, char *buf)
447 struct thermal_zone_device *tz = to_thermal_zone(dev);
448 enum thermal_device_mode mode;
451 if (!tz->ops->get_mode)
454 result = tz->ops->get_mode(tz, &mode);
458 return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled"
463 mode_store(struct device *dev, struct device_attribute *attr,
464 const char *buf, size_t count)
466 struct thermal_zone_device *tz = to_thermal_zone(dev);
469 if (!tz->ops->set_mode)
472 if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
473 result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
474 else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
475 result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
486 trip_point_type_show(struct device *dev, struct device_attribute *attr,
489 struct thermal_zone_device *tz = to_thermal_zone(dev);
490 enum thermal_trip_type type;
493 if (!tz->ops->get_trip_type)
496 if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip))
499 result = tz->ops->get_trip_type(tz, trip, &type);
504 case THERMAL_TRIP_CRITICAL:
505 return sprintf(buf, "critical\n");
506 case THERMAL_TRIP_HOT:
507 return sprintf(buf, "hot\n");
508 case THERMAL_TRIP_PASSIVE:
509 return sprintf(buf, "passive\n");
510 case THERMAL_TRIP_ACTIVE:
511 return sprintf(buf, "active\n");
513 return sprintf(buf, "unknown\n");
518 trip_point_temp_store(struct device *dev, struct device_attribute *attr,
519 const char *buf, size_t count)
521 struct thermal_zone_device *tz = to_thermal_zone(dev);
523 unsigned long temperature;
525 if (!tz->ops->set_trip_temp)
528 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
531 if (kstrtoul(buf, 10, &temperature))
534 ret = tz->ops->set_trip_temp(tz, trip, temperature);
536 return ret ? ret : count;
540 trip_point_temp_show(struct device *dev, struct device_attribute *attr,
543 struct thermal_zone_device *tz = to_thermal_zone(dev);
547 if (!tz->ops->get_trip_temp)
550 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
553 ret = tz->ops->get_trip_temp(tz, trip, &temperature);
558 return sprintf(buf, "%ld\n", temperature);
562 trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
563 const char *buf, size_t count)
565 struct thermal_zone_device *tz = to_thermal_zone(dev);
567 unsigned long temperature;
569 if (!tz->ops->set_trip_hyst)
572 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
575 if (kstrtoul(buf, 10, &temperature))
579 * We are not doing any check on the 'temperature' value
580 * here. The driver implementing 'set_trip_hyst' has to
583 ret = tz->ops->set_trip_hyst(tz, trip, temperature);
585 return ret ? ret : count;
589 trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
592 struct thermal_zone_device *tz = to_thermal_zone(dev);
594 unsigned long temperature;
596 if (!tz->ops->get_trip_hyst)
599 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
602 ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
604 return ret ? ret : sprintf(buf, "%ld\n", temperature);
608 passive_store(struct device *dev, struct device_attribute *attr,
609 const char *buf, size_t count)
611 struct thermal_zone_device *tz = to_thermal_zone(dev);
612 struct thermal_cooling_device *cdev = NULL;
615 if (!sscanf(buf, "%d\n", &state))
618 /* sanity check: values below 1000 millicelcius don't make sense
619 * and can cause the system to go into a thermal heart attack
621 if (state && state < 1000)
624 if (state && !tz->forced_passive) {
625 mutex_lock(&thermal_list_lock);
626 list_for_each_entry(cdev, &thermal_cdev_list, node) {
627 if (!strncmp("Processor", cdev->type,
628 sizeof("Processor")))
629 thermal_zone_bind_cooling_device(tz,
630 THERMAL_TRIPS_NONE, cdev,
634 mutex_unlock(&thermal_list_lock);
635 if (!tz->passive_delay)
636 tz->passive_delay = 1000;
637 } else if (!state && tz->forced_passive) {
638 mutex_lock(&thermal_list_lock);
639 list_for_each_entry(cdev, &thermal_cdev_list, node) {
640 if (!strncmp("Processor", cdev->type,
641 sizeof("Processor")))
642 thermal_zone_unbind_cooling_device(tz,
646 mutex_unlock(&thermal_list_lock);
647 tz->passive_delay = 0;
650 tz->forced_passive = state;
652 thermal_zone_device_update(tz);
658 passive_show(struct device *dev, struct device_attribute *attr,
661 struct thermal_zone_device *tz = to_thermal_zone(dev);
663 return sprintf(buf, "%d\n", tz->forced_passive);
667 policy_store(struct device *dev, struct device_attribute *attr,
668 const char *buf, size_t count)
671 struct thermal_zone_device *tz = to_thermal_zone(dev);
672 struct thermal_governor *gov;
674 mutex_lock(&thermal_governor_lock);
676 gov = __find_governor(buf);
684 mutex_unlock(&thermal_governor_lock);
689 policy_show(struct device *dev, struct device_attribute *devattr, char *buf)
691 struct thermal_zone_device *tz = to_thermal_zone(dev);
693 return sprintf(buf, "%s\n", tz->governor->name);
696 static DEVICE_ATTR(type, 0444, type_show, NULL);
697 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
698 static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
699 static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
700 static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
702 /* sys I/F for cooling device */
703 #define to_cooling_device(_dev) \
704 container_of(_dev, struct thermal_cooling_device, device)
707 thermal_cooling_device_type_show(struct device *dev,
708 struct device_attribute *attr, char *buf)
710 struct thermal_cooling_device *cdev = to_cooling_device(dev);
712 return sprintf(buf, "%s\n", cdev->type);
716 thermal_cooling_device_max_state_show(struct device *dev,
717 struct device_attribute *attr, char *buf)
719 struct thermal_cooling_device *cdev = to_cooling_device(dev);
723 ret = cdev->ops->get_max_state(cdev, &state);
726 return sprintf(buf, "%ld\n", state);
730 thermal_cooling_device_cur_state_show(struct device *dev,
731 struct device_attribute *attr, char *buf)
733 struct thermal_cooling_device *cdev = to_cooling_device(dev);
737 ret = cdev->ops->get_cur_state(cdev, &state);
740 return sprintf(buf, "%ld\n", state);
744 thermal_cooling_device_cur_state_store(struct device *dev,
745 struct device_attribute *attr,
746 const char *buf, size_t count)
748 struct thermal_cooling_device *cdev = to_cooling_device(dev);
752 if (!sscanf(buf, "%ld\n", &state))
758 result = cdev->ops->set_cur_state(cdev, state);
764 static struct device_attribute dev_attr_cdev_type =
765 __ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
766 static DEVICE_ATTR(max_state, 0444,
767 thermal_cooling_device_max_state_show, NULL);
768 static DEVICE_ATTR(cur_state, 0644,
769 thermal_cooling_device_cur_state_show,
770 thermal_cooling_device_cur_state_store);
773 thermal_cooling_device_trip_point_show(struct device *dev,
774 struct device_attribute *attr, char *buf)
776 struct thermal_instance *instance;
779 container_of(attr, struct thermal_instance, attr);
781 if (instance->trip == THERMAL_TRIPS_NONE)
782 return sprintf(buf, "-1\n");
784 return sprintf(buf, "%d\n", instance->trip);
787 /* Device management */
789 #if defined(CONFIG_THERMAL_HWMON)
792 #include <linux/hwmon.h>
794 /* thermal zone devices with the same type share one hwmon device */
795 struct thermal_hwmon_device {
796 char type[THERMAL_NAME_LENGTH];
797 struct device *device;
799 struct list_head tz_list;
800 struct list_head node;
803 struct thermal_hwmon_attr {
804 struct device_attribute attr;
808 /* one temperature input for each thermal zone */
809 struct thermal_hwmon_temp {
810 struct list_head hwmon_node;
811 struct thermal_zone_device *tz;
812 struct thermal_hwmon_attr temp_input; /* hwmon sys attr */
813 struct thermal_hwmon_attr temp_crit; /* hwmon sys attr */
816 static LIST_HEAD(thermal_hwmon_list);
819 name_show(struct device *dev, struct device_attribute *attr, char *buf)
821 struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
822 return sprintf(buf, "%s\n", hwmon->type);
824 static DEVICE_ATTR(name, 0444, name_show, NULL);
827 temp_input_show(struct device *dev, struct device_attribute *attr, char *buf)
831 struct thermal_hwmon_attr *hwmon_attr
832 = container_of(attr, struct thermal_hwmon_attr, attr);
833 struct thermal_hwmon_temp *temp
834 = container_of(hwmon_attr, struct thermal_hwmon_temp,
836 struct thermal_zone_device *tz = temp->tz;
838 ret = tz->ops->get_temp(tz, &temperature);
843 return sprintf(buf, "%ld\n", temperature);
847 temp_crit_show(struct device *dev, struct device_attribute *attr,
850 struct thermal_hwmon_attr *hwmon_attr
851 = container_of(attr, struct thermal_hwmon_attr, attr);
852 struct thermal_hwmon_temp *temp
853 = container_of(hwmon_attr, struct thermal_hwmon_temp,
855 struct thermal_zone_device *tz = temp->tz;
859 ret = tz->ops->get_trip_temp(tz, 0, &temperature);
863 return sprintf(buf, "%ld\n", temperature);
867 static struct thermal_hwmon_device *
868 thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz)
870 struct thermal_hwmon_device *hwmon;
872 mutex_lock(&thermal_list_lock);
873 list_for_each_entry(hwmon, &thermal_hwmon_list, node)
874 if (!strcmp(hwmon->type, tz->type)) {
875 mutex_unlock(&thermal_list_lock);
878 mutex_unlock(&thermal_list_lock);
883 /* Find the temperature input matching a given thermal zone */
884 static struct thermal_hwmon_temp *
885 thermal_hwmon_lookup_temp(const struct thermal_hwmon_device *hwmon,
886 const struct thermal_zone_device *tz)
888 struct thermal_hwmon_temp *temp;
890 mutex_lock(&thermal_list_lock);
891 list_for_each_entry(temp, &hwmon->tz_list, hwmon_node)
892 if (temp->tz == tz) {
893 mutex_unlock(&thermal_list_lock);
896 mutex_unlock(&thermal_list_lock);
902 thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
904 struct thermal_hwmon_device *hwmon;
905 struct thermal_hwmon_temp *temp;
906 int new_hwmon_device = 1;
909 hwmon = thermal_hwmon_lookup_by_type(tz);
911 new_hwmon_device = 0;
912 goto register_sys_interface;
915 hwmon = kzalloc(sizeof(struct thermal_hwmon_device), GFP_KERNEL);
919 INIT_LIST_HEAD(&hwmon->tz_list);
920 strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
921 hwmon->device = hwmon_device_register(NULL);
922 if (IS_ERR(hwmon->device)) {
923 result = PTR_ERR(hwmon->device);
926 dev_set_drvdata(hwmon->device, hwmon);
927 result = device_create_file(hwmon->device, &dev_attr_name);
931 register_sys_interface:
932 temp = kzalloc(sizeof(struct thermal_hwmon_temp), GFP_KERNEL);
935 goto unregister_name;
941 snprintf(temp->temp_input.name, sizeof(temp->temp_input.name),
942 "temp%d_input", hwmon->count);
943 temp->temp_input.attr.attr.name = temp->temp_input.name;
944 temp->temp_input.attr.attr.mode = 0444;
945 temp->temp_input.attr.show = temp_input_show;
946 sysfs_attr_init(&temp->temp_input.attr.attr);
947 result = device_create_file(hwmon->device, &temp->temp_input.attr);
951 if (tz->ops->get_crit_temp) {
952 unsigned long temperature;
953 if (!tz->ops->get_crit_temp(tz, &temperature)) {
954 snprintf(temp->temp_crit.name,
955 sizeof(temp->temp_crit.name),
956 "temp%d_crit", hwmon->count);
957 temp->temp_crit.attr.attr.name = temp->temp_crit.name;
958 temp->temp_crit.attr.attr.mode = 0444;
959 temp->temp_crit.attr.show = temp_crit_show;
960 sysfs_attr_init(&temp->temp_crit.attr.attr);
961 result = device_create_file(hwmon->device,
962 &temp->temp_crit.attr);
964 goto unregister_input;
968 mutex_lock(&thermal_list_lock);
969 if (new_hwmon_device)
970 list_add_tail(&hwmon->node, &thermal_hwmon_list);
971 list_add_tail(&temp->hwmon_node, &hwmon->tz_list);
972 mutex_unlock(&thermal_list_lock);
977 device_remove_file(hwmon->device, &temp->temp_input.attr);
981 if (new_hwmon_device) {
982 device_remove_file(hwmon->device, &dev_attr_name);
983 hwmon_device_unregister(hwmon->device);
986 if (new_hwmon_device)
993 thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
995 struct thermal_hwmon_device *hwmon;
996 struct thermal_hwmon_temp *temp;
998 hwmon = thermal_hwmon_lookup_by_type(tz);
999 if (unlikely(!hwmon)) {
1000 /* Should never happen... */
1001 dev_dbg(&tz->device, "hwmon device lookup failed!\n");
1005 temp = thermal_hwmon_lookup_temp(hwmon, tz);
1006 if (unlikely(!temp)) {
1007 /* Should never happen... */
1008 dev_dbg(&tz->device, "temperature input lookup failed!\n");
1012 device_remove_file(hwmon->device, &temp->temp_input.attr);
1013 if (tz->ops->get_crit_temp)
1014 device_remove_file(hwmon->device, &temp->temp_crit.attr);
1016 mutex_lock(&thermal_list_lock);
1017 list_del(&temp->hwmon_node);
1019 if (!list_empty(&hwmon->tz_list)) {
1020 mutex_unlock(&thermal_list_lock);
1023 list_del(&hwmon->node);
1024 mutex_unlock(&thermal_list_lock);
1026 device_remove_file(hwmon->device, &dev_attr_name);
1027 hwmon_device_unregister(hwmon->device);
1032 thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
1038 thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
1044 * thermal_zone_bind_cooling_device - bind a cooling device to a thermal zone
1045 * @tz: thermal zone device
1046 * @trip: indicates which trip point the cooling devices is
1047 * associated with in this thermal zone.
1048 * @cdev: thermal cooling device
1050 * This function is usually called in the thermal zone device .bind callback.
1052 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
1054 struct thermal_cooling_device *cdev,
1055 unsigned long upper, unsigned long lower)
1057 struct thermal_instance *dev;
1058 struct thermal_instance *pos;
1059 struct thermal_zone_device *pos1;
1060 struct thermal_cooling_device *pos2;
1061 unsigned long max_state;
1064 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
1067 list_for_each_entry(pos1, &thermal_tz_list, node) {
1071 list_for_each_entry(pos2, &thermal_cdev_list, node) {
1076 if (tz != pos1 || cdev != pos2)
1079 cdev->ops->get_max_state(cdev, &max_state);
1081 /* lower default 0, upper default max_state */
1082 lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
1083 upper = upper == THERMAL_NO_LIMIT ? max_state : upper;
1085 if (lower > upper || upper > max_state)
1089 kzalloc(sizeof(struct thermal_instance), GFP_KERNEL);
1097 dev->target = THERMAL_NO_TARGET;
1099 result = get_idr(&tz->idr, &tz->lock, &dev->id);
1103 sprintf(dev->name, "cdev%d", dev->id);
1105 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
1109 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
1110 sysfs_attr_init(&dev->attr.attr);
1111 dev->attr.attr.name = dev->attr_name;
1112 dev->attr.attr.mode = 0444;
1113 dev->attr.show = thermal_cooling_device_trip_point_show;
1114 result = device_create_file(&tz->device, &dev->attr);
1116 goto remove_symbol_link;
1118 mutex_lock(&tz->lock);
1119 mutex_lock(&cdev->lock);
1120 list_for_each_entry(pos, &tz->thermal_instances, tz_node)
1121 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
1126 list_add_tail(&dev->tz_node, &tz->thermal_instances);
1127 list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
1129 mutex_unlock(&cdev->lock);
1130 mutex_unlock(&tz->lock);
1135 device_remove_file(&tz->device, &dev->attr);
1137 sysfs_remove_link(&tz->device.kobj, dev->name);
1139 release_idr(&tz->idr, &tz->lock, dev->id);
1144 EXPORT_SYMBOL(thermal_zone_bind_cooling_device);
1147 * thermal_zone_unbind_cooling_device - unbind a cooling device from a thermal zone
1148 * @tz: thermal zone device
1149 * @trip: indicates which trip point the cooling devices is
1150 * associated with in this thermal zone.
1151 * @cdev: thermal cooling device
1153 * This function is usually called in the thermal zone device .unbind callback.
1155 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
1157 struct thermal_cooling_device *cdev)
1159 struct thermal_instance *pos, *next;
1161 mutex_lock(&tz->lock);
1162 mutex_lock(&cdev->lock);
1163 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
1164 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
1165 list_del(&pos->tz_node);
1166 list_del(&pos->cdev_node);
1167 mutex_unlock(&cdev->lock);
1168 mutex_unlock(&tz->lock);
1172 mutex_unlock(&cdev->lock);
1173 mutex_unlock(&tz->lock);
1178 device_remove_file(&tz->device, &pos->attr);
1179 sysfs_remove_link(&tz->device.kobj, pos->name);
1180 release_idr(&tz->idr, &tz->lock, pos->id);
1184 EXPORT_SYMBOL(thermal_zone_unbind_cooling_device);
1186 static void thermal_release(struct device *dev)
1188 struct thermal_zone_device *tz;
1189 struct thermal_cooling_device *cdev;
1191 if (!strncmp(dev_name(dev), "thermal_zone",
1192 sizeof("thermal_zone") - 1)) {
1193 tz = to_thermal_zone(dev);
1196 cdev = to_cooling_device(dev);
1201 static struct class thermal_class = {
1203 .dev_release = thermal_release,
1207 * thermal_cooling_device_register - register a new thermal cooling device
1208 * @type: the thermal cooling device type.
1209 * @devdata: device private data.
1210 * @ops: standard thermal cooling devices callbacks.
1212 struct thermal_cooling_device *
1213 thermal_cooling_device_register(char *type, void *devdata,
1214 const struct thermal_cooling_device_ops *ops)
1216 struct thermal_cooling_device *cdev;
1219 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1220 return ERR_PTR(-EINVAL);
1222 if (!ops || !ops->get_max_state || !ops->get_cur_state ||
1223 !ops->set_cur_state)
1224 return ERR_PTR(-EINVAL);
1226 cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL);
1228 return ERR_PTR(-ENOMEM);
1230 result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
1233 return ERR_PTR(result);
1236 strcpy(cdev->type, type ? : "");
1237 mutex_init(&cdev->lock);
1238 INIT_LIST_HEAD(&cdev->thermal_instances);
1240 cdev->updated = true;
1241 cdev->device.class = &thermal_class;
1242 cdev->devdata = devdata;
1243 dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
1244 result = device_register(&cdev->device);
1246 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1248 return ERR_PTR(result);
1253 result = device_create_file(&cdev->device, &dev_attr_cdev_type);
1258 result = device_create_file(&cdev->device, &dev_attr_max_state);
1262 result = device_create_file(&cdev->device, &dev_attr_cur_state);
1266 /* Add 'this' new cdev to the global cdev list */
1267 mutex_lock(&thermal_list_lock);
1268 list_add(&cdev->node, &thermal_cdev_list);
1269 mutex_unlock(&thermal_list_lock);
1271 /* Update binding information for 'this' new cdev */
1277 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1278 device_unregister(&cdev->device);
1279 return ERR_PTR(result);
1281 EXPORT_SYMBOL(thermal_cooling_device_register);
1284 * thermal_cooling_device_unregister - removes the registered thermal cooling device
1285 * @cdev: the thermal cooling device to remove.
1287 * thermal_cooling_device_unregister() must be called when the device is no
1290 void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
1293 const struct thermal_zone_params *tzp;
1294 struct thermal_zone_device *tz;
1295 struct thermal_cooling_device *pos = NULL;
1300 mutex_lock(&thermal_list_lock);
1301 list_for_each_entry(pos, &thermal_cdev_list, node)
1305 /* thermal cooling device not found */
1306 mutex_unlock(&thermal_list_lock);
1309 list_del(&cdev->node);
1311 /* Unbind all thermal zones associated with 'this' cdev */
1312 list_for_each_entry(tz, &thermal_tz_list, node) {
1313 if (tz->ops->unbind) {
1314 tz->ops->unbind(tz, cdev);
1318 if (!tz->tzp || !tz->tzp->tbp)
1322 for (i = 0; i < tzp->num_tbps; i++) {
1323 if (tzp->tbp[i].cdev == cdev) {
1324 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1325 tzp->tbp[i].cdev = NULL;
1330 mutex_unlock(&thermal_list_lock);
1333 device_remove_file(&cdev->device, &dev_attr_cdev_type);
1334 device_remove_file(&cdev->device, &dev_attr_max_state);
1335 device_remove_file(&cdev->device, &dev_attr_cur_state);
1337 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1338 device_unregister(&cdev->device);
1341 EXPORT_SYMBOL(thermal_cooling_device_unregister);
1343 void thermal_cdev_update(struct thermal_cooling_device *cdev)
1345 struct thermal_instance *instance;
1346 unsigned long target = 0;
1348 /* cooling device is updated*/
1352 mutex_lock(&cdev->lock);
1353 /* Make sure cdev enters the deepest cooling state */
1354 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
1355 if (instance->target == THERMAL_NO_TARGET)
1357 if (instance->target > target)
1358 target = instance->target;
1360 mutex_unlock(&cdev->lock);
1361 cdev->ops->set_cur_state(cdev, target);
1362 cdev->updated = true;
1364 EXPORT_SYMBOL(thermal_cdev_update);
1367 * notify_thermal_framework - Sensor drivers use this API to notify framework
1368 * @tz: thermal zone device
1369 * @trip: indicates which trip point has been crossed
1371 * This function handles the trip events from sensor drivers. It starts
1372 * throttling the cooling devices according to the policy configured.
1373 * For CRITICAL and HOT trip points, this notifies the respective drivers,
1374 * and does actual throttling for other trip points i.e ACTIVE and PASSIVE.
1375 * The throttling policy is based on the configured platform data; if no
1376 * platform data is provided, this uses the step_wise throttling policy.
1378 void notify_thermal_framework(struct thermal_zone_device *tz, int trip)
1380 handle_thermal_trip(tz, trip);
1382 EXPORT_SYMBOL(notify_thermal_framework);
1385 * create_trip_attrs - create attributes for trip points
1386 * @tz: the thermal zone device
1387 * @mask: Writeable trip point bitmap.
1389 static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
1392 int size = sizeof(struct thermal_attr) * tz->trips;
1394 tz->trip_type_attrs = kzalloc(size, GFP_KERNEL);
1395 if (!tz->trip_type_attrs)
1398 tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL);
1399 if (!tz->trip_temp_attrs) {
1400 kfree(tz->trip_type_attrs);
1404 if (tz->ops->get_trip_hyst) {
1405 tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL);
1406 if (!tz->trip_hyst_attrs) {
1407 kfree(tz->trip_type_attrs);
1408 kfree(tz->trip_temp_attrs);
1414 for (indx = 0; indx < tz->trips; indx++) {
1415 /* create trip type attribute */
1416 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
1417 "trip_point_%d_type", indx);
1419 sysfs_attr_init(&tz->trip_type_attrs[indx].attr.attr);
1420 tz->trip_type_attrs[indx].attr.attr.name =
1421 tz->trip_type_attrs[indx].name;
1422 tz->trip_type_attrs[indx].attr.attr.mode = S_IRUGO;
1423 tz->trip_type_attrs[indx].attr.show = trip_point_type_show;
1425 device_create_file(&tz->device,
1426 &tz->trip_type_attrs[indx].attr);
1428 /* create trip temp attribute */
1429 snprintf(tz->trip_temp_attrs[indx].name, THERMAL_NAME_LENGTH,
1430 "trip_point_%d_temp", indx);
1432 sysfs_attr_init(&tz->trip_temp_attrs[indx].attr.attr);
1433 tz->trip_temp_attrs[indx].attr.attr.name =
1434 tz->trip_temp_attrs[indx].name;
1435 tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
1436 tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
1437 if (mask & (1 << indx)) {
1438 tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
1439 tz->trip_temp_attrs[indx].attr.store =
1440 trip_point_temp_store;
1443 device_create_file(&tz->device,
1444 &tz->trip_temp_attrs[indx].attr);
1446 /* create Optional trip hyst attribute */
1447 if (!tz->ops->get_trip_hyst)
1449 snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH,
1450 "trip_point_%d_hyst", indx);
1452 sysfs_attr_init(&tz->trip_hyst_attrs[indx].attr.attr);
1453 tz->trip_hyst_attrs[indx].attr.attr.name =
1454 tz->trip_hyst_attrs[indx].name;
1455 tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
1456 tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
1457 if (tz->ops->set_trip_hyst) {
1458 tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
1459 tz->trip_hyst_attrs[indx].attr.store =
1460 trip_point_hyst_store;
1463 device_create_file(&tz->device,
1464 &tz->trip_hyst_attrs[indx].attr);
1469 static void remove_trip_attrs(struct thermal_zone_device *tz)
1473 for (indx = 0; indx < tz->trips; indx++) {
1474 device_remove_file(&tz->device,
1475 &tz->trip_type_attrs[indx].attr);
1476 device_remove_file(&tz->device,
1477 &tz->trip_temp_attrs[indx].attr);
1478 if (tz->ops->get_trip_hyst)
1479 device_remove_file(&tz->device,
1480 &tz->trip_hyst_attrs[indx].attr);
1482 kfree(tz->trip_type_attrs);
1483 kfree(tz->trip_temp_attrs);
1484 kfree(tz->trip_hyst_attrs);
1488 * thermal_zone_device_register - register a new thermal zone device
1489 * @type: the thermal zone device type
1490 * @trips: the number of trip points the thermal zone support
1491 * @mask: a bit string indicating the writeablility of trip points
1492 * @devdata: private device data
1493 * @ops: standard thermal zone device callbacks
1494 * @tzp: thermal zone platform parameters
1495 * @passive_delay: number of milliseconds to wait between polls when
1496 * performing passive cooling
1497 * @polling_delay: number of milliseconds to wait between polls when checking
1498 * whether trip points have been crossed (0 for interrupt
1501 * thermal_zone_device_unregister() must be called when the device is no
1502 * longer needed. The passive cooling depends on the .get_trend() return value.
1504 struct thermal_zone_device *thermal_zone_device_register(const char *type,
1505 int trips, int mask, void *devdata,
1506 const struct thermal_zone_device_ops *ops,
1507 const struct thermal_zone_params *tzp,
1508 int passive_delay, int polling_delay)
1510 struct thermal_zone_device *tz;
1511 enum thermal_trip_type trip_type;
1516 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1517 return ERR_PTR(-EINVAL);
1519 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
1520 return ERR_PTR(-EINVAL);
1522 if (!ops || !ops->get_temp)
1523 return ERR_PTR(-EINVAL);
1525 tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL);
1527 return ERR_PTR(-ENOMEM);
1529 INIT_LIST_HEAD(&tz->thermal_instances);
1531 mutex_init(&tz->lock);
1532 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
1535 return ERR_PTR(result);
1538 strcpy(tz->type, type ? : "");
1541 tz->device.class = &thermal_class;
1542 tz->devdata = devdata;
1544 tz->passive_delay = passive_delay;
1545 tz->polling_delay = polling_delay;
1547 dev_set_name(&tz->device, "thermal_zone%d", tz->id);
1548 result = device_register(&tz->device);
1550 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1552 return ERR_PTR(result);
1557 result = device_create_file(&tz->device, &dev_attr_type);
1562 result = device_create_file(&tz->device, &dev_attr_temp);
1566 if (ops->get_mode) {
1567 result = device_create_file(&tz->device, &dev_attr_mode);
1572 result = create_trip_attrs(tz, mask);
1576 for (count = 0; count < trips; count++) {
1577 tz->ops->get_trip_type(tz, count, &trip_type);
1578 if (trip_type == THERMAL_TRIP_PASSIVE)
1583 result = device_create_file(&tz->device, &dev_attr_passive);
1588 /* Create policy attribute */
1589 result = device_create_file(&tz->device, &dev_attr_policy);
1593 /* Update 'this' zone's governor information */
1594 mutex_lock(&thermal_governor_lock);
1597 tz->governor = __find_governor(tz->tzp->governor_name);
1599 tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
1601 mutex_unlock(&thermal_governor_lock);
1603 result = thermal_add_hwmon_sysfs(tz);
1607 mutex_lock(&thermal_list_lock);
1608 list_add_tail(&tz->node, &thermal_tz_list);
1609 mutex_unlock(&thermal_list_lock);
1611 /* Bind cooling devices for this zone */
1614 INIT_DELAYED_WORK(&(tz->poll_queue), thermal_zone_device_check);
1616 thermal_zone_device_update(tz);
1622 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1623 device_unregister(&tz->device);
1624 return ERR_PTR(result);
1626 EXPORT_SYMBOL(thermal_zone_device_register);
1629 * thermal_device_unregister - removes the registered thermal zone device
1630 * @tz: the thermal zone device to remove
1632 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1635 const struct thermal_zone_params *tzp;
1636 struct thermal_cooling_device *cdev;
1637 struct thermal_zone_device *pos = NULL;
1644 mutex_lock(&thermal_list_lock);
1645 list_for_each_entry(pos, &thermal_tz_list, node)
1649 /* thermal zone device not found */
1650 mutex_unlock(&thermal_list_lock);
1653 list_del(&tz->node);
1655 /* Unbind all cdevs associated with 'this' thermal zone */
1656 list_for_each_entry(cdev, &thermal_cdev_list, node) {
1657 if (tz->ops->unbind) {
1658 tz->ops->unbind(tz, cdev);
1662 if (!tzp || !tzp->tbp)
1665 for (i = 0; i < tzp->num_tbps; i++) {
1666 if (tzp->tbp[i].cdev == cdev) {
1667 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1668 tzp->tbp[i].cdev = NULL;
1673 mutex_unlock(&thermal_list_lock);
1675 thermal_zone_device_set_polling(tz, 0);
1678 device_remove_file(&tz->device, &dev_attr_type);
1679 device_remove_file(&tz->device, &dev_attr_temp);
1680 if (tz->ops->get_mode)
1681 device_remove_file(&tz->device, &dev_attr_mode);
1682 device_remove_file(&tz->device, &dev_attr_policy);
1683 remove_trip_attrs(tz);
1684 tz->governor = NULL;
1686 thermal_remove_hwmon_sysfs(tz);
1687 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1688 idr_destroy(&tz->idr);
1689 mutex_destroy(&tz->lock);
1690 device_unregister(&tz->device);
1693 EXPORT_SYMBOL(thermal_zone_device_unregister);
1696 static struct genl_family thermal_event_genl_family = {
1697 .id = GENL_ID_GENERATE,
1698 .name = THERMAL_GENL_FAMILY_NAME,
1699 .version = THERMAL_GENL_VERSION,
1700 .maxattr = THERMAL_GENL_ATTR_MAX,
1703 static struct genl_multicast_group thermal_event_mcgrp = {
1704 .name = THERMAL_GENL_MCAST_GROUP_NAME,
1707 int thermal_generate_netlink_event(u32 orig, enum events event)
1709 struct sk_buff *skb;
1710 struct nlattr *attr;
1711 struct thermal_genl_event *thermal_event;
1715 static unsigned int thermal_event_seqnum;
1717 /* allocate memory */
1718 size = nla_total_size(sizeof(struct thermal_genl_event)) +
1721 skb = genlmsg_new(size, GFP_ATOMIC);
1725 /* add the genetlink message header */
1726 msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++,
1727 &thermal_event_genl_family, 0,
1728 THERMAL_GENL_CMD_EVENT);
1735 attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT,
1736 sizeof(struct thermal_genl_event));
1743 thermal_event = nla_data(attr);
1744 if (!thermal_event) {
1749 memset(thermal_event, 0, sizeof(struct thermal_genl_event));
1751 thermal_event->orig = orig;
1752 thermal_event->event = event;
1754 /* send multicast genetlink message */
1755 result = genlmsg_end(skb, msg_header);
1761 result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC);
1763 pr_info("failed to send netlink event:%d\n", result);
1767 EXPORT_SYMBOL(thermal_generate_netlink_event);
1769 static int genetlink_init(void)
1773 result = genl_register_family(&thermal_event_genl_family);
1777 result = genl_register_mc_group(&thermal_event_genl_family,
1778 &thermal_event_mcgrp);
1780 genl_unregister_family(&thermal_event_genl_family);
1784 static void genetlink_exit(void)
1786 genl_unregister_family(&thermal_event_genl_family);
1788 #else /* !CONFIG_NET */
1789 static inline int genetlink_init(void) { return 0; }
1790 static inline void genetlink_exit(void) {}
1791 #endif /* !CONFIG_NET */
1793 static int __init thermal_init(void)
1797 result = class_register(&thermal_class);
1799 idr_destroy(&thermal_tz_idr);
1800 idr_destroy(&thermal_cdev_idr);
1801 mutex_destroy(&thermal_idr_lock);
1802 mutex_destroy(&thermal_list_lock);
1804 result = genetlink_init();
1808 static void __exit thermal_exit(void)
1810 class_unregister(&thermal_class);
1811 idr_destroy(&thermal_tz_idr);
1812 idr_destroy(&thermal_cdev_idr);
1813 mutex_destroy(&thermal_idr_lock);
1814 mutex_destroy(&thermal_list_lock);
1818 fs_initcall(thermal_init);
1819 module_exit(thermal_exit);