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 #include <linux/module.h>
27 #include <linux/device.h>
28 #include <linux/err.h>
29 #include <linux/kdev_t.h>
30 #include <linux/idr.h>
31 #include <linux/thermal.h>
32 #include <linux/spinlock.h>
34 MODULE_AUTHOR("Zhang Rui");
35 MODULE_DESCRIPTION("Generic thermal management sysfs support");
36 MODULE_LICENSE("GPL");
38 #define PREFIX "Thermal: "
40 struct thermal_cooling_device_instance {
42 char name[THERMAL_NAME_LENGTH];
43 struct thermal_zone_device *tz;
44 struct thermal_cooling_device *cdev;
46 char attr_name[THERMAL_NAME_LENGTH];
47 struct device_attribute attr;
48 struct list_head node;
51 static DEFINE_IDR(thermal_tz_idr);
52 static DEFINE_IDR(thermal_cdev_idr);
53 static DEFINE_MUTEX(thermal_idr_lock);
55 static LIST_HEAD(thermal_tz_list);
56 static LIST_HEAD(thermal_cdev_list);
57 static DEFINE_MUTEX(thermal_list_lock);
59 static int get_idr(struct idr *idr, struct mutex *lock, int *id)
64 if (unlikely(idr_pre_get(idr, GFP_KERNEL) == 0))
69 err = idr_get_new(idr, NULL, id);
72 if (unlikely(err == -EAGAIN))
74 else if (unlikely(err))
77 *id = *id & MAX_ID_MASK;
81 static void release_idr(struct idr *idr, struct mutex *lock, int id)
90 /* sys I/F for thermal zone */
92 #define to_thermal_zone(_dev) \
93 container_of(_dev, struct thermal_zone_device, device)
96 type_show(struct device *dev, struct device_attribute *attr, char *buf)
98 struct thermal_zone_device *tz = to_thermal_zone(dev);
100 return sprintf(buf, "%s\n", tz->type);
104 temp_show(struct device *dev, struct device_attribute *attr, char *buf)
106 struct thermal_zone_device *tz = to_thermal_zone(dev);
110 if (!tz->ops->get_temp)
113 ret = tz->ops->get_temp(tz, &temperature);
118 return sprintf(buf, "%ld\n", temperature);
122 mode_show(struct device *dev, struct device_attribute *attr, char *buf)
124 struct thermal_zone_device *tz = to_thermal_zone(dev);
125 enum thermal_device_mode mode;
128 if (!tz->ops->get_mode)
131 result = tz->ops->get_mode(tz, &mode);
135 return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled"
140 mode_store(struct device *dev, struct device_attribute *attr,
141 const char *buf, size_t count)
143 struct thermal_zone_device *tz = to_thermal_zone(dev);
146 if (!tz->ops->set_mode)
149 if (!strncmp(buf, "enabled", sizeof("enabled")))
150 result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
151 else if (!strncmp(buf, "disabled", sizeof("disabled")))
152 result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
163 trip_point_type_show(struct device *dev, struct device_attribute *attr,
166 struct thermal_zone_device *tz = to_thermal_zone(dev);
167 enum thermal_trip_type type;
170 if (!tz->ops->get_trip_type)
173 if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip))
176 result = tz->ops->get_trip_type(tz, trip, &type);
181 case THERMAL_TRIP_CRITICAL:
182 return sprintf(buf, "critical");
183 case THERMAL_TRIP_HOT:
184 return sprintf(buf, "hot");
185 case THERMAL_TRIP_PASSIVE:
186 return sprintf(buf, "passive");
187 case THERMAL_TRIP_ACTIVE:
188 return sprintf(buf, "active");
190 return sprintf(buf, "unknown");
195 trip_point_temp_show(struct device *dev, struct device_attribute *attr,
198 struct thermal_zone_device *tz = to_thermal_zone(dev);
202 if (!tz->ops->get_trip_temp)
205 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
208 ret = tz->ops->get_trip_temp(tz, trip, &temperature);
213 return sprintf(buf, "%ld\n", temperature);
216 static DEVICE_ATTR(type, 0444, type_show, NULL);
217 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
218 static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
220 static struct device_attribute trip_point_attrs[] = {
221 __ATTR(trip_point_0_type, 0444, trip_point_type_show, NULL),
222 __ATTR(trip_point_0_temp, 0444, trip_point_temp_show, NULL),
223 __ATTR(trip_point_1_type, 0444, trip_point_type_show, NULL),
224 __ATTR(trip_point_1_temp, 0444, trip_point_temp_show, NULL),
225 __ATTR(trip_point_2_type, 0444, trip_point_type_show, NULL),
226 __ATTR(trip_point_2_temp, 0444, trip_point_temp_show, NULL),
227 __ATTR(trip_point_3_type, 0444, trip_point_type_show, NULL),
228 __ATTR(trip_point_3_temp, 0444, trip_point_temp_show, NULL),
229 __ATTR(trip_point_4_type, 0444, trip_point_type_show, NULL),
230 __ATTR(trip_point_4_temp, 0444, trip_point_temp_show, NULL),
231 __ATTR(trip_point_5_type, 0444, trip_point_type_show, NULL),
232 __ATTR(trip_point_5_temp, 0444, trip_point_temp_show, NULL),
233 __ATTR(trip_point_6_type, 0444, trip_point_type_show, NULL),
234 __ATTR(trip_point_6_temp, 0444, trip_point_temp_show, NULL),
235 __ATTR(trip_point_7_type, 0444, trip_point_type_show, NULL),
236 __ATTR(trip_point_7_temp, 0444, trip_point_temp_show, NULL),
237 __ATTR(trip_point_8_type, 0444, trip_point_type_show, NULL),
238 __ATTR(trip_point_8_temp, 0444, trip_point_temp_show, NULL),
239 __ATTR(trip_point_9_type, 0444, trip_point_type_show, NULL),
240 __ATTR(trip_point_9_temp, 0444, trip_point_temp_show, NULL),
241 __ATTR(trip_point_10_type, 0444, trip_point_type_show, NULL),
242 __ATTR(trip_point_10_temp, 0444, trip_point_temp_show, NULL),
243 __ATTR(trip_point_11_type, 0444, trip_point_type_show, NULL),
244 __ATTR(trip_point_11_temp, 0444, trip_point_temp_show, NULL),
247 #define TRIP_POINT_ATTR_ADD(_dev, _index, result) \
249 result = device_create_file(_dev, \
250 &trip_point_attrs[_index * 2]); \
253 result = device_create_file(_dev, \
254 &trip_point_attrs[_index * 2 + 1]); \
257 #define TRIP_POINT_ATTR_REMOVE(_dev, _index) \
259 device_remove_file(_dev, &trip_point_attrs[_index * 2]); \
260 device_remove_file(_dev, &trip_point_attrs[_index * 2 + 1]); \
263 /* sys I/F for cooling device */
264 #define to_cooling_device(_dev) \
265 container_of(_dev, struct thermal_cooling_device, device)
268 thermal_cooling_device_type_show(struct device *dev,
269 struct device_attribute *attr, char *buf)
271 struct thermal_cooling_device *cdev = to_cooling_device(dev);
273 return sprintf(buf, "%s\n", cdev->type);
277 thermal_cooling_device_max_state_show(struct device *dev,
278 struct device_attribute *attr, char *buf)
280 struct thermal_cooling_device *cdev = to_cooling_device(dev);
284 ret = cdev->ops->get_max_state(cdev, &state);
287 return sprintf(buf, "%ld\n", state);
291 thermal_cooling_device_cur_state_show(struct device *dev,
292 struct device_attribute *attr, char *buf)
294 struct thermal_cooling_device *cdev = to_cooling_device(dev);
298 ret = cdev->ops->get_cur_state(cdev, &state);
301 return sprintf(buf, "%ld\n", state);
305 thermal_cooling_device_cur_state_store(struct device *dev,
306 struct device_attribute *attr,
307 const char *buf, size_t count)
309 struct thermal_cooling_device *cdev = to_cooling_device(dev);
313 if (!sscanf(buf, "%ld\n", &state))
319 result = cdev->ops->set_cur_state(cdev, state);
325 static struct device_attribute dev_attr_cdev_type =
326 __ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
327 static DEVICE_ATTR(max_state, 0444,
328 thermal_cooling_device_max_state_show, NULL);
329 static DEVICE_ATTR(cur_state, 0644,
330 thermal_cooling_device_cur_state_show,
331 thermal_cooling_device_cur_state_store);
334 thermal_cooling_device_trip_point_show(struct device *dev,
335 struct device_attribute *attr, char *buf)
337 struct thermal_cooling_device_instance *instance;
340 container_of(attr, struct thermal_cooling_device_instance, attr);
342 if (instance->trip == THERMAL_TRIPS_NONE)
343 return sprintf(buf, "-1\n");
345 return sprintf(buf, "%d\n", instance->trip);
348 /* Device management */
350 #if defined(CONFIG_THERMAL_HWMON)
353 #include <linux/hwmon.h>
354 static LIST_HEAD(thermal_hwmon_list);
357 name_show(struct device *dev, struct device_attribute *attr, char *buf)
359 struct thermal_hwmon_device *hwmon = dev->driver_data;
360 return sprintf(buf, "%s\n", hwmon->type);
362 static DEVICE_ATTR(name, 0444, name_show, NULL);
365 temp_input_show(struct device *dev, struct device_attribute *attr, char *buf)
369 struct thermal_hwmon_attr *hwmon_attr
370 = container_of(attr, struct thermal_hwmon_attr, attr);
371 struct thermal_zone_device *tz
372 = container_of(hwmon_attr, struct thermal_zone_device,
375 ret = tz->ops->get_temp(tz, &temperature);
380 return sprintf(buf, "%ld\n", temperature);
384 temp_crit_show(struct device *dev, struct device_attribute *attr,
387 struct thermal_hwmon_attr *hwmon_attr
388 = container_of(attr, struct thermal_hwmon_attr, attr);
389 struct thermal_zone_device *tz
390 = container_of(hwmon_attr, struct thermal_zone_device,
395 ret = tz->ops->get_trip_temp(tz, 0, &temperature);
399 return sprintf(buf, "%ld\n", temperature);
404 thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
406 struct thermal_hwmon_device *hwmon;
407 int new_hwmon_device = 1;
410 mutex_lock(&thermal_list_lock);
411 list_for_each_entry(hwmon, &thermal_hwmon_list, node)
412 if (!strcmp(hwmon->type, tz->type)) {
413 new_hwmon_device = 0;
414 mutex_unlock(&thermal_list_lock);
415 goto register_sys_interface;
417 mutex_unlock(&thermal_list_lock);
419 hwmon = kzalloc(sizeof(struct thermal_hwmon_device), GFP_KERNEL);
423 INIT_LIST_HEAD(&hwmon->tz_list);
424 strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
425 hwmon->device = hwmon_device_register(NULL);
426 if (IS_ERR(hwmon->device)) {
427 result = PTR_ERR(hwmon->device);
430 hwmon->device->driver_data = hwmon;
431 result = device_create_file(hwmon->device, &dev_attr_name);
433 goto unregister_hwmon_device;
435 register_sys_interface:
439 snprintf(tz->temp_input.name, THERMAL_NAME_LENGTH,
440 "temp%d_input", hwmon->count);
441 tz->temp_input.attr.attr.name = tz->temp_input.name;
442 tz->temp_input.attr.attr.mode = 0444;
443 tz->temp_input.attr.show = temp_input_show;
444 result = device_create_file(hwmon->device, &tz->temp_input.attr);
446 goto unregister_hwmon_device;
448 if (tz->ops->get_crit_temp) {
449 unsigned long temperature;
450 if (!tz->ops->get_crit_temp(tz, &temperature)) {
451 snprintf(tz->temp_crit.name, THERMAL_NAME_LENGTH,
452 "temp%d_crit", hwmon->count);
453 tz->temp_crit.attr.attr.name = tz->temp_crit.name;
454 tz->temp_crit.attr.attr.mode = 0444;
455 tz->temp_crit.attr.show = temp_crit_show;
456 result = device_create_file(hwmon->device,
457 &tz->temp_crit.attr);
459 goto unregister_hwmon_device;
463 mutex_lock(&thermal_list_lock);
464 if (new_hwmon_device)
465 list_add_tail(&hwmon->node, &thermal_hwmon_list);
466 list_add_tail(&tz->hwmon_node, &hwmon->tz_list);
467 mutex_unlock(&thermal_list_lock);
471 unregister_hwmon_device:
472 device_remove_file(hwmon->device, &tz->temp_crit.attr);
473 device_remove_file(hwmon->device, &tz->temp_input.attr);
474 if (new_hwmon_device) {
475 device_remove_file(hwmon->device, &dev_attr_name);
476 hwmon_device_unregister(hwmon->device);
479 if (new_hwmon_device)
486 thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
488 struct thermal_hwmon_device *hwmon = tz->hwmon;
491 device_remove_file(hwmon->device, &tz->temp_input.attr);
492 device_remove_file(hwmon->device, &tz->temp_crit.attr);
494 mutex_lock(&thermal_list_lock);
495 list_del(&tz->hwmon_node);
496 if (!list_empty(&hwmon->tz_list)) {
497 mutex_unlock(&thermal_list_lock);
500 list_del(&hwmon->node);
501 mutex_unlock(&thermal_list_lock);
503 device_remove_file(hwmon->device, &dev_attr_name);
504 hwmon_device_unregister(hwmon->device);
509 thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
515 thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
522 * thermal_zone_bind_cooling_device - bind a cooling device to a thermal zone
523 * @tz: thermal zone device
524 * @trip: indicates which trip point the cooling devices is
525 * associated with in this thermal zone.
526 * @cdev: thermal cooling device
528 * This function is usually called in the thermal zone device .bind callback.
530 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
532 struct thermal_cooling_device *cdev)
534 struct thermal_cooling_device_instance *dev;
535 struct thermal_cooling_device_instance *pos;
536 struct thermal_zone_device *pos1;
537 struct thermal_cooling_device *pos2;
540 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
543 list_for_each_entry(pos1, &thermal_tz_list, node) {
547 list_for_each_entry(pos2, &thermal_cdev_list, node) {
552 if (tz != pos1 || cdev != pos2)
556 kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL);
562 result = get_idr(&tz->idr, &tz->lock, &dev->id);
566 sprintf(dev->name, "cdev%d", dev->id);
568 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
572 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
573 dev->attr.attr.name = dev->attr_name;
574 dev->attr.attr.mode = 0444;
575 dev->attr.show = thermal_cooling_device_trip_point_show;
576 result = device_create_file(&tz->device, &dev->attr);
578 goto remove_symbol_link;
580 mutex_lock(&tz->lock);
581 list_for_each_entry(pos, &tz->cooling_devices, node)
582 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
587 list_add_tail(&dev->node, &tz->cooling_devices);
588 mutex_unlock(&tz->lock);
593 device_remove_file(&tz->device, &dev->attr);
595 sysfs_remove_link(&tz->device.kobj, dev->name);
597 release_idr(&tz->idr, &tz->lock, dev->id);
603 EXPORT_SYMBOL(thermal_zone_bind_cooling_device);
606 * thermal_zone_unbind_cooling_device - unbind a cooling device from a thermal zone
607 * @tz: thermal zone device
608 * @trip: indicates which trip point the cooling devices is
609 * associated with in this thermal zone.
610 * @cdev: thermal cooling device
612 * This function is usually called in the thermal zone device .unbind callback.
614 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
616 struct thermal_cooling_device *cdev)
618 struct thermal_cooling_device_instance *pos, *next;
620 mutex_lock(&tz->lock);
621 list_for_each_entry_safe(pos, next, &tz->cooling_devices, node) {
622 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
623 list_del(&pos->node);
624 mutex_unlock(&tz->lock);
628 mutex_unlock(&tz->lock);
633 device_remove_file(&tz->device, &pos->attr);
634 sysfs_remove_link(&tz->device.kobj, pos->name);
635 release_idr(&tz->idr, &tz->lock, pos->id);
640 EXPORT_SYMBOL(thermal_zone_unbind_cooling_device);
642 static void thermal_release(struct device *dev)
644 struct thermal_zone_device *tz;
645 struct thermal_cooling_device *cdev;
647 if (!strncmp(dev_name(dev), "thermal_zone", sizeof "thermal_zone" - 1)) {
648 tz = to_thermal_zone(dev);
651 cdev = to_cooling_device(dev);
656 static struct class thermal_class = {
658 .dev_release = thermal_release,
662 * thermal_cooling_device_register - register a new thermal cooling device
663 * @type: the thermal cooling device type.
664 * @devdata: device private data.
665 * @ops: standard thermal cooling devices callbacks.
667 struct thermal_cooling_device *thermal_cooling_device_register(char *type,
670 thermal_cooling_device_ops
673 struct thermal_cooling_device *cdev;
674 struct thermal_zone_device *pos;
677 if (strlen(type) >= THERMAL_NAME_LENGTH)
678 return ERR_PTR(-EINVAL);
680 if (!ops || !ops->get_max_state || !ops->get_cur_state ||
682 return ERR_PTR(-EINVAL);
684 cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL);
686 return ERR_PTR(-ENOMEM);
688 result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
691 return ERR_PTR(result);
694 strcpy(cdev->type, type);
696 cdev->device.class = &thermal_class;
697 cdev->devdata = devdata;
698 dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
699 result = device_register(&cdev->device);
701 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
703 return ERR_PTR(result);
708 result = device_create_file(&cdev->device, &dev_attr_cdev_type);
713 result = device_create_file(&cdev->device, &dev_attr_max_state);
717 result = device_create_file(&cdev->device, &dev_attr_cur_state);
721 mutex_lock(&thermal_list_lock);
722 list_add(&cdev->node, &thermal_cdev_list);
723 list_for_each_entry(pos, &thermal_tz_list, node) {
726 result = pos->ops->bind(pos, cdev);
731 mutex_unlock(&thermal_list_lock);
737 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
738 device_unregister(&cdev->device);
739 return ERR_PTR(result);
742 EXPORT_SYMBOL(thermal_cooling_device_register);
745 * thermal_cooling_device_unregister - removes the registered thermal cooling device
746 * @cdev: the thermal cooling device to remove.
748 * thermal_cooling_device_unregister() must be called when the device is no
751 void thermal_cooling_device_unregister(struct
752 thermal_cooling_device
755 struct thermal_zone_device *tz;
756 struct thermal_cooling_device *pos = NULL;
761 mutex_lock(&thermal_list_lock);
762 list_for_each_entry(pos, &thermal_cdev_list, node)
766 /* thermal cooling device not found */
767 mutex_unlock(&thermal_list_lock);
770 list_del(&cdev->node);
771 list_for_each_entry(tz, &thermal_tz_list, node) {
772 if (!tz->ops->unbind)
774 tz->ops->unbind(tz, cdev);
776 mutex_unlock(&thermal_list_lock);
778 device_remove_file(&cdev->device, &dev_attr_cdev_type);
779 device_remove_file(&cdev->device, &dev_attr_max_state);
780 device_remove_file(&cdev->device, &dev_attr_cur_state);
782 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
783 device_unregister(&cdev->device);
787 EXPORT_SYMBOL(thermal_cooling_device_unregister);
790 * thermal_zone_device_register - register a new thermal zone device
791 * @type: the thermal zone device type
792 * @trips: the number of trip points the thermal zone support
793 * @devdata: private device data
794 * @ops: standard thermal zone device callbacks
796 * thermal_zone_device_unregister() must be called when the device is no
799 struct thermal_zone_device *thermal_zone_device_register(char *type,
801 void *devdata, struct
802 thermal_zone_device_ops
805 struct thermal_zone_device *tz;
806 struct thermal_cooling_device *pos;
810 if (strlen(type) >= THERMAL_NAME_LENGTH)
811 return ERR_PTR(-EINVAL);
813 if (trips > THERMAL_MAX_TRIPS || trips < 0)
814 return ERR_PTR(-EINVAL);
816 if (!ops || !ops->get_temp)
817 return ERR_PTR(-EINVAL);
819 tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL);
821 return ERR_PTR(-ENOMEM);
823 INIT_LIST_HEAD(&tz->cooling_devices);
825 mutex_init(&tz->lock);
826 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
829 return ERR_PTR(result);
832 strcpy(tz->type, type);
834 tz->device.class = &thermal_class;
835 tz->devdata = devdata;
837 dev_set_name(&tz->device, "thermal_zone%d", tz->id);
838 result = device_register(&tz->device);
840 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
842 return ERR_PTR(result);
847 result = device_create_file(&tz->device, &dev_attr_type);
852 result = device_create_file(&tz->device, &dev_attr_temp);
857 result = device_create_file(&tz->device, &dev_attr_mode);
862 for (count = 0; count < trips; count++) {
863 TRIP_POINT_ATTR_ADD(&tz->device, count, result);
868 result = thermal_add_hwmon_sysfs(tz);
872 mutex_lock(&thermal_list_lock);
873 list_add_tail(&tz->node, &thermal_tz_list);
875 list_for_each_entry(pos, &thermal_cdev_list, node) {
876 result = ops->bind(tz, pos);
880 mutex_unlock(&thermal_list_lock);
886 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
887 device_unregister(&tz->device);
888 return ERR_PTR(result);
891 EXPORT_SYMBOL(thermal_zone_device_register);
894 * thermal_device_unregister - removes the registered thermal zone device
895 * @tz: the thermal zone device to remove
897 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
899 struct thermal_cooling_device *cdev;
900 struct thermal_zone_device *pos = NULL;
906 mutex_lock(&thermal_list_lock);
907 list_for_each_entry(pos, &thermal_tz_list, node)
911 /* thermal zone device not found */
912 mutex_unlock(&thermal_list_lock);
917 list_for_each_entry(cdev, &thermal_cdev_list, node)
918 tz->ops->unbind(tz, cdev);
919 mutex_unlock(&thermal_list_lock);
922 device_remove_file(&tz->device, &dev_attr_type);
923 device_remove_file(&tz->device, &dev_attr_temp);
924 if (tz->ops->get_mode)
925 device_remove_file(&tz->device, &dev_attr_mode);
927 for (count = 0; count < tz->trips; count++)
928 TRIP_POINT_ATTR_REMOVE(&tz->device, count);
930 thermal_remove_hwmon_sysfs(tz);
931 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
932 idr_destroy(&tz->idr);
933 mutex_destroy(&tz->lock);
934 device_unregister(&tz->device);
938 EXPORT_SYMBOL(thermal_zone_device_unregister);
940 static int __init thermal_init(void)
944 result = class_register(&thermal_class);
946 idr_destroy(&thermal_tz_idr);
947 idr_destroy(&thermal_cdev_idr);
948 mutex_destroy(&thermal_idr_lock);
949 mutex_destroy(&thermal_list_lock);
954 static void __exit thermal_exit(void)
956 class_unregister(&thermal_class);
957 idr_destroy(&thermal_tz_idr);
958 idr_destroy(&thermal_cdev_idr);
959 mutex_destroy(&thermal_idr_lock);
960 mutex_destroy(&thermal_list_lock);
963 subsys_initcall(thermal_init);
964 module_exit(thermal_exit);