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
);
108 if (!tz
->ops
->get_temp
)
111 return tz
->ops
->get_temp(tz
, buf
);
115 mode_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
117 struct thermal_zone_device
*tz
= to_thermal_zone(dev
);
119 if (!tz
->ops
->get_mode
)
122 return tz
->ops
->get_mode(tz
, buf
);
126 mode_store(struct device
*dev
, struct device_attribute
*attr
,
127 const char *buf
, size_t count
)
129 struct thermal_zone_device
*tz
= to_thermal_zone(dev
);
132 if (!tz
->ops
->set_mode
)
135 result
= tz
->ops
->set_mode(tz
, buf
);
143 trip_point_type_show(struct device
*dev
, struct device_attribute
*attr
,
146 struct thermal_zone_device
*tz
= to_thermal_zone(dev
);
149 if (!tz
->ops
->get_trip_type
)
152 if (!sscanf(attr
->attr
.name
, "trip_point_%d_type", &trip
))
155 return tz
->ops
->get_trip_type(tz
, trip
, buf
);
159 trip_point_temp_show(struct device
*dev
, struct device_attribute
*attr
,
162 struct thermal_zone_device
*tz
= to_thermal_zone(dev
);
165 if (!tz
->ops
->get_trip_temp
)
168 if (!sscanf(attr
->attr
.name
, "trip_point_%d_temp", &trip
))
171 return tz
->ops
->get_trip_temp(tz
, trip
, buf
);
174 static DEVICE_ATTR(type
, 0444, type_show
, NULL
);
175 static DEVICE_ATTR(temp
, 0444, temp_show
, NULL
);
176 static DEVICE_ATTR(mode
, 0644, mode_show
, mode_store
);
178 static struct device_attribute trip_point_attrs
[] = {
179 __ATTR(trip_point_0_type
, 0444, trip_point_type_show
, NULL
),
180 __ATTR(trip_point_0_temp
, 0444, trip_point_temp_show
, NULL
),
181 __ATTR(trip_point_1_type
, 0444, trip_point_type_show
, NULL
),
182 __ATTR(trip_point_1_temp
, 0444, trip_point_temp_show
, NULL
),
183 __ATTR(trip_point_2_type
, 0444, trip_point_type_show
, NULL
),
184 __ATTR(trip_point_2_temp
, 0444, trip_point_temp_show
, NULL
),
185 __ATTR(trip_point_3_type
, 0444, trip_point_type_show
, NULL
),
186 __ATTR(trip_point_3_temp
, 0444, trip_point_temp_show
, NULL
),
187 __ATTR(trip_point_4_type
, 0444, trip_point_type_show
, NULL
),
188 __ATTR(trip_point_4_temp
, 0444, trip_point_temp_show
, NULL
),
189 __ATTR(trip_point_5_type
, 0444, trip_point_type_show
, NULL
),
190 __ATTR(trip_point_5_temp
, 0444, trip_point_temp_show
, NULL
),
191 __ATTR(trip_point_6_type
, 0444, trip_point_type_show
, NULL
),
192 __ATTR(trip_point_6_temp
, 0444, trip_point_temp_show
, NULL
),
193 __ATTR(trip_point_7_type
, 0444, trip_point_type_show
, NULL
),
194 __ATTR(trip_point_7_temp
, 0444, trip_point_temp_show
, NULL
),
195 __ATTR(trip_point_8_type
, 0444, trip_point_type_show
, NULL
),
196 __ATTR(trip_point_8_temp
, 0444, trip_point_temp_show
, NULL
),
197 __ATTR(trip_point_9_type
, 0444, trip_point_type_show
, NULL
),
198 __ATTR(trip_point_9_temp
, 0444, trip_point_temp_show
, NULL
),
199 __ATTR(trip_point_10_type
, 0444, trip_point_type_show
, NULL
),
200 __ATTR(trip_point_10_temp
, 0444, trip_point_temp_show
, NULL
),
201 __ATTR(trip_point_11_type
, 0444, trip_point_type_show
, NULL
),
202 __ATTR(trip_point_11_temp
, 0444, trip_point_temp_show
, NULL
),
205 #define TRIP_POINT_ATTR_ADD(_dev, _index, result) \
207 result = device_create_file(_dev, \
208 &trip_point_attrs[_index * 2]); \
211 result = device_create_file(_dev, \
212 &trip_point_attrs[_index * 2 + 1]); \
215 #define TRIP_POINT_ATTR_REMOVE(_dev, _index) \
217 device_remove_file(_dev, &trip_point_attrs[_index * 2]); \
218 device_remove_file(_dev, &trip_point_attrs[_index * 2 + 1]); \
221 /* sys I/F for cooling device */
222 #define to_cooling_device(_dev) \
223 container_of(_dev, struct thermal_cooling_device, device)
226 thermal_cooling_device_type_show(struct device
*dev
,
227 struct device_attribute
*attr
, char *buf
)
229 struct thermal_cooling_device
*cdev
= to_cooling_device(dev
);
231 return sprintf(buf
, "%s\n", cdev
->type
);
235 thermal_cooling_device_max_state_show(struct device
*dev
,
236 struct device_attribute
*attr
, char *buf
)
238 struct thermal_cooling_device
*cdev
= to_cooling_device(dev
);
240 return cdev
->ops
->get_max_state(cdev
, buf
);
244 thermal_cooling_device_cur_state_show(struct device
*dev
,
245 struct device_attribute
*attr
, char *buf
)
247 struct thermal_cooling_device
*cdev
= to_cooling_device(dev
);
249 return cdev
->ops
->get_cur_state(cdev
, buf
);
253 thermal_cooling_device_cur_state_store(struct device
*dev
,
254 struct device_attribute
*attr
,
255 const char *buf
, size_t count
)
257 struct thermal_cooling_device
*cdev
= to_cooling_device(dev
);
261 if (!sscanf(buf
, "%d\n", &state
))
267 result
= cdev
->ops
->set_cur_state(cdev
, state
);
273 static struct device_attribute dev_attr_cdev_type
=
274 __ATTR(type
, 0444, thermal_cooling_device_type_show
, NULL
);
275 static DEVICE_ATTR(max_state
, 0444,
276 thermal_cooling_device_max_state_show
, NULL
);
277 static DEVICE_ATTR(cur_state
, 0644,
278 thermal_cooling_device_cur_state_show
,
279 thermal_cooling_device_cur_state_store
);
282 thermal_cooling_device_trip_point_show(struct device
*dev
,
283 struct device_attribute
*attr
, char *buf
)
285 struct thermal_cooling_device_instance
*instance
;
288 container_of(attr
, struct thermal_cooling_device_instance
, attr
);
290 if (instance
->trip
== THERMAL_TRIPS_NONE
)
291 return sprintf(buf
, "-1\n");
293 return sprintf(buf
, "%d\n", instance
->trip
);
296 /* Device management */
298 #if defined(CONFIG_THERMAL_HWMON)
301 #include <linux/hwmon.h>
302 static LIST_HEAD(thermal_hwmon_list
);
305 name_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
307 struct thermal_hwmon_device
*hwmon
= dev
->driver_data
;
308 return sprintf(buf
, "%s\n", hwmon
->type
);
310 static DEVICE_ATTR(name
, 0444, name_show
, NULL
);
313 temp_input_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
315 struct thermal_hwmon_attr
*hwmon_attr
316 = container_of(attr
, struct thermal_hwmon_attr
, attr
);
317 struct thermal_zone_device
*tz
318 = container_of(hwmon_attr
, struct thermal_zone_device
,
321 return tz
->ops
->get_temp(tz
, buf
);
325 temp_crit_show(struct device
*dev
, struct device_attribute
*attr
,
328 struct thermal_hwmon_attr
*hwmon_attr
329 = container_of(attr
, struct thermal_hwmon_attr
, attr
);
330 struct thermal_zone_device
*tz
331 = container_of(hwmon_attr
, struct thermal_zone_device
,
334 return tz
->ops
->get_trip_temp(tz
, 0, buf
);
339 thermal_add_hwmon_sysfs(struct thermal_zone_device
*tz
)
341 struct thermal_hwmon_device
*hwmon
;
342 int new_hwmon_device
= 1;
345 mutex_lock(&thermal_list_lock
);
346 list_for_each_entry(hwmon
, &thermal_hwmon_list
, node
)
347 if (!strcmp(hwmon
->type
, tz
->type
)) {
348 new_hwmon_device
= 0;
349 mutex_unlock(&thermal_list_lock
);
350 goto register_sys_interface
;
352 mutex_unlock(&thermal_list_lock
);
354 hwmon
= kzalloc(sizeof(struct thermal_hwmon_device
), GFP_KERNEL
);
358 INIT_LIST_HEAD(&hwmon
->tz_list
);
359 strlcpy(hwmon
->type
, tz
->type
, THERMAL_NAME_LENGTH
);
360 hwmon
->device
= hwmon_device_register(NULL
);
361 if (IS_ERR(hwmon
->device
)) {
362 result
= PTR_ERR(hwmon
->device
);
365 hwmon
->device
->driver_data
= hwmon
;
366 result
= device_create_file(hwmon
->device
, &dev_attr_name
);
368 goto unregister_hwmon_device
;
370 register_sys_interface
:
374 snprintf(tz
->temp_input
.name
, THERMAL_NAME_LENGTH
,
375 "temp%d_input", hwmon
->count
);
376 tz
->temp_input
.attr
.attr
.name
= tz
->temp_input
.name
;
377 tz
->temp_input
.attr
.attr
.mode
= 0444;
378 tz
->temp_input
.attr
.show
= temp_input_show
;
379 result
= device_create_file(hwmon
->device
, &tz
->temp_input
.attr
);
381 goto unregister_hwmon_device
;
383 if (tz
->ops
->get_crit_temp
) {
384 unsigned long temperature
;
385 if (!tz
->ops
->get_crit_temp(tz
, &temperature
)) {
386 snprintf(tz
->temp_crit
.name
, THERMAL_NAME_LENGTH
,
387 "temp%d_crit", hwmon
->count
);
388 tz
->temp_crit
.attr
.attr
.name
= tz
->temp_crit
.name
;
389 tz
->temp_crit
.attr
.attr
.mode
= 0444;
390 tz
->temp_crit
.attr
.show
= temp_crit_show
;
391 result
= device_create_file(hwmon
->device
,
392 &tz
->temp_crit
.attr
);
394 goto unregister_hwmon_device
;
398 mutex_lock(&thermal_list_lock
);
399 if (new_hwmon_device
)
400 list_add_tail(&hwmon
->node
, &thermal_hwmon_list
);
401 list_add_tail(&tz
->hwmon_node
, &hwmon
->tz_list
);
402 mutex_unlock(&thermal_list_lock
);
406 unregister_hwmon_device
:
407 device_remove_file(hwmon
->device
, &tz
->temp_crit
.attr
);
408 device_remove_file(hwmon
->device
, &tz
->temp_input
.attr
);
409 if (new_hwmon_device
) {
410 device_remove_file(hwmon
->device
, &dev_attr_name
);
411 hwmon_device_unregister(hwmon
->device
);
414 if (new_hwmon_device
)
421 thermal_remove_hwmon_sysfs(struct thermal_zone_device
*tz
)
423 struct thermal_hwmon_device
*hwmon
= tz
->hwmon
;
426 device_remove_file(hwmon
->device
, &tz
->temp_input
.attr
);
427 device_remove_file(hwmon
->device
, &tz
->temp_crit
.attr
);
429 mutex_lock(&thermal_list_lock
);
430 list_del(&tz
->hwmon_node
);
431 if (!list_empty(&hwmon
->tz_list
)) {
432 mutex_unlock(&thermal_list_lock
);
435 list_del(&hwmon
->node
);
436 mutex_unlock(&thermal_list_lock
);
438 device_remove_file(hwmon
->device
, &dev_attr_name
);
439 hwmon_device_unregister(hwmon
->device
);
444 thermal_add_hwmon_sysfs(struct thermal_zone_device
*tz
)
450 thermal_remove_hwmon_sysfs(struct thermal_zone_device
*tz
)
457 * thermal_zone_bind_cooling_device - bind a cooling device to a thermal zone
458 * @tz: thermal zone device
459 * @trip: indicates which trip point the cooling devices is
460 * associated with in this thermal zone.
461 * @cdev: thermal cooling device
463 * This function is usually called in the thermal zone device .bind callback.
465 int thermal_zone_bind_cooling_device(struct thermal_zone_device
*tz
,
467 struct thermal_cooling_device
*cdev
)
469 struct thermal_cooling_device_instance
*dev
;
470 struct thermal_cooling_device_instance
*pos
;
471 struct thermal_zone_device
*pos1
;
472 struct thermal_cooling_device
*pos2
;
475 if (trip
>= tz
->trips
|| (trip
< 0 && trip
!= THERMAL_TRIPS_NONE
))
478 list_for_each_entry(pos1
, &thermal_tz_list
, node
) {
482 list_for_each_entry(pos2
, &thermal_cdev_list
, node
) {
487 if (tz
!= pos1
|| cdev
!= pos2
)
491 kzalloc(sizeof(struct thermal_cooling_device_instance
), GFP_KERNEL
);
497 result
= get_idr(&tz
->idr
, &tz
->lock
, &dev
->id
);
501 sprintf(dev
->name
, "cdev%d", dev
->id
);
503 sysfs_create_link(&tz
->device
.kobj
, &cdev
->device
.kobj
, dev
->name
);
507 sprintf(dev
->attr_name
, "cdev%d_trip_point", dev
->id
);
508 dev
->attr
.attr
.name
= dev
->attr_name
;
509 dev
->attr
.attr
.mode
= 0444;
510 dev
->attr
.show
= thermal_cooling_device_trip_point_show
;
511 result
= device_create_file(&tz
->device
, &dev
->attr
);
513 goto remove_symbol_link
;
515 mutex_lock(&tz
->lock
);
516 list_for_each_entry(pos
, &tz
->cooling_devices
, node
)
517 if (pos
->tz
== tz
&& pos
->trip
== trip
&& pos
->cdev
== cdev
) {
522 list_add_tail(&dev
->node
, &tz
->cooling_devices
);
523 mutex_unlock(&tz
->lock
);
528 device_remove_file(&tz
->device
, &dev
->attr
);
530 sysfs_remove_link(&tz
->device
.kobj
, dev
->name
);
532 release_idr(&tz
->idr
, &tz
->lock
, dev
->id
);
538 EXPORT_SYMBOL(thermal_zone_bind_cooling_device
);
541 * thermal_zone_unbind_cooling_device - unbind a cooling device from a thermal zone
542 * @tz: thermal zone device
543 * @trip: indicates which trip point the cooling devices is
544 * associated with in this thermal zone.
545 * @cdev: thermal cooling device
547 * This function is usually called in the thermal zone device .unbind callback.
549 int thermal_zone_unbind_cooling_device(struct thermal_zone_device
*tz
,
551 struct thermal_cooling_device
*cdev
)
553 struct thermal_cooling_device_instance
*pos
, *next
;
555 mutex_lock(&tz
->lock
);
556 list_for_each_entry_safe(pos
, next
, &tz
->cooling_devices
, node
) {
557 if (pos
->tz
== tz
&& pos
->trip
== trip
&& pos
->cdev
== cdev
) {
558 list_del(&pos
->node
);
559 mutex_unlock(&tz
->lock
);
563 mutex_unlock(&tz
->lock
);
568 device_remove_file(&tz
->device
, &pos
->attr
);
569 sysfs_remove_link(&tz
->device
.kobj
, pos
->name
);
570 release_idr(&tz
->idr
, &tz
->lock
, pos
->id
);
575 EXPORT_SYMBOL(thermal_zone_unbind_cooling_device
);
577 static void thermal_release(struct device
*dev
)
579 struct thermal_zone_device
*tz
;
580 struct thermal_cooling_device
*cdev
;
582 if (!strncmp(dev
->bus_id
, "thermal_zone", sizeof "thermal_zone" - 1)) {
583 tz
= to_thermal_zone(dev
);
586 cdev
= to_cooling_device(dev
);
591 static struct class thermal_class
= {
593 .dev_release
= thermal_release
,
597 * thermal_cooling_device_register - register a new thermal cooling device
598 * @type: the thermal cooling device type.
599 * @devdata: device private data.
600 * @ops: standard thermal cooling devices callbacks.
602 struct thermal_cooling_device
*thermal_cooling_device_register(char *type
,
605 thermal_cooling_device_ops
608 struct thermal_cooling_device
*cdev
;
609 struct thermal_zone_device
*pos
;
612 if (strlen(type
) >= THERMAL_NAME_LENGTH
)
613 return ERR_PTR(-EINVAL
);
615 if (!ops
|| !ops
->get_max_state
|| !ops
->get_cur_state
||
617 return ERR_PTR(-EINVAL
);
619 cdev
= kzalloc(sizeof(struct thermal_cooling_device
), GFP_KERNEL
);
621 return ERR_PTR(-ENOMEM
);
623 result
= get_idr(&thermal_cdev_idr
, &thermal_idr_lock
, &cdev
->id
);
626 return ERR_PTR(result
);
629 strcpy(cdev
->type
, type
);
631 cdev
->device
.class = &thermal_class
;
632 cdev
->devdata
= devdata
;
633 sprintf(cdev
->device
.bus_id
, "cooling_device%d", cdev
->id
);
634 result
= device_register(&cdev
->device
);
636 release_idr(&thermal_cdev_idr
, &thermal_idr_lock
, cdev
->id
);
638 return ERR_PTR(result
);
643 result
= device_create_file(&cdev
->device
, &dev_attr_cdev_type
);
648 result
= device_create_file(&cdev
->device
, &dev_attr_max_state
);
652 result
= device_create_file(&cdev
->device
, &dev_attr_cur_state
);
656 mutex_lock(&thermal_list_lock
);
657 list_add(&cdev
->node
, &thermal_cdev_list
);
658 list_for_each_entry(pos
, &thermal_tz_list
, node
) {
661 result
= pos
->ops
->bind(pos
, cdev
);
666 mutex_unlock(&thermal_list_lock
);
672 release_idr(&thermal_cdev_idr
, &thermal_idr_lock
, cdev
->id
);
673 device_unregister(&cdev
->device
);
674 return ERR_PTR(result
);
677 EXPORT_SYMBOL(thermal_cooling_device_register
);
680 * thermal_cooling_device_unregister - removes the registered thermal cooling device
681 * @cdev: the thermal cooling device to remove.
683 * thermal_cooling_device_unregister() must be called when the device is no
686 void thermal_cooling_device_unregister(struct
687 thermal_cooling_device
690 struct thermal_zone_device
*tz
;
691 struct thermal_cooling_device
*pos
= NULL
;
696 mutex_lock(&thermal_list_lock
);
697 list_for_each_entry(pos
, &thermal_cdev_list
, node
)
701 /* thermal cooling device not found */
702 mutex_unlock(&thermal_list_lock
);
705 list_del(&cdev
->node
);
706 list_for_each_entry(tz
, &thermal_tz_list
, node
) {
707 if (!tz
->ops
->unbind
)
709 tz
->ops
->unbind(tz
, cdev
);
711 mutex_unlock(&thermal_list_lock
);
713 device_remove_file(&cdev
->device
, &dev_attr_cdev_type
);
714 device_remove_file(&cdev
->device
, &dev_attr_max_state
);
715 device_remove_file(&cdev
->device
, &dev_attr_cur_state
);
717 release_idr(&thermal_cdev_idr
, &thermal_idr_lock
, cdev
->id
);
718 device_unregister(&cdev
->device
);
722 EXPORT_SYMBOL(thermal_cooling_device_unregister
);
725 * thermal_zone_device_register - register a new thermal zone device
726 * @type: the thermal zone device type
727 * @trips: the number of trip points the thermal zone support
728 * @devdata: private device data
729 * @ops: standard thermal zone device callbacks
731 * thermal_zone_device_unregister() must be called when the device is no
734 struct thermal_zone_device
*thermal_zone_device_register(char *type
,
736 void *devdata
, struct
737 thermal_zone_device_ops
740 struct thermal_zone_device
*tz
;
741 struct thermal_cooling_device
*pos
;
745 if (strlen(type
) >= THERMAL_NAME_LENGTH
)
746 return ERR_PTR(-EINVAL
);
748 if (trips
> THERMAL_MAX_TRIPS
|| trips
< 0)
749 return ERR_PTR(-EINVAL
);
751 if (!ops
|| !ops
->get_temp
)
752 return ERR_PTR(-EINVAL
);
754 tz
= kzalloc(sizeof(struct thermal_zone_device
), GFP_KERNEL
);
756 return ERR_PTR(-ENOMEM
);
758 INIT_LIST_HEAD(&tz
->cooling_devices
);
760 mutex_init(&tz
->lock
);
761 result
= get_idr(&thermal_tz_idr
, &thermal_idr_lock
, &tz
->id
);
764 return ERR_PTR(result
);
767 strcpy(tz
->type
, type
);
769 tz
->device
.class = &thermal_class
;
770 tz
->devdata
= devdata
;
772 sprintf(tz
->device
.bus_id
, "thermal_zone%d", tz
->id
);
773 result
= device_register(&tz
->device
);
775 release_idr(&thermal_tz_idr
, &thermal_idr_lock
, tz
->id
);
777 return ERR_PTR(result
);
782 result
= device_create_file(&tz
->device
, &dev_attr_type
);
787 result
= device_create_file(&tz
->device
, &dev_attr_temp
);
792 result
= device_create_file(&tz
->device
, &dev_attr_mode
);
797 for (count
= 0; count
< trips
; count
++) {
798 TRIP_POINT_ATTR_ADD(&tz
->device
, count
, result
);
803 result
= thermal_add_hwmon_sysfs(tz
);
807 mutex_lock(&thermal_list_lock
);
808 list_add_tail(&tz
->node
, &thermal_tz_list
);
810 list_for_each_entry(pos
, &thermal_cdev_list
, node
) {
811 result
= ops
->bind(tz
, pos
);
815 mutex_unlock(&thermal_list_lock
);
821 release_idr(&thermal_tz_idr
, &thermal_idr_lock
, tz
->id
);
822 device_unregister(&tz
->device
);
823 return ERR_PTR(result
);
826 EXPORT_SYMBOL(thermal_zone_device_register
);
829 * thermal_device_unregister - removes the registered thermal zone device
830 * @tz: the thermal zone device to remove
832 void thermal_zone_device_unregister(struct thermal_zone_device
*tz
)
834 struct thermal_cooling_device
*cdev
;
835 struct thermal_zone_device
*pos
= NULL
;
841 mutex_lock(&thermal_list_lock
);
842 list_for_each_entry(pos
, &thermal_tz_list
, node
)
846 /* thermal zone device not found */
847 mutex_unlock(&thermal_list_lock
);
852 list_for_each_entry(cdev
, &thermal_cdev_list
, node
)
853 tz
->ops
->unbind(tz
, cdev
);
854 mutex_unlock(&thermal_list_lock
);
857 device_remove_file(&tz
->device
, &dev_attr_type
);
858 device_remove_file(&tz
->device
, &dev_attr_temp
);
859 if (tz
->ops
->get_mode
)
860 device_remove_file(&tz
->device
, &dev_attr_mode
);
862 for (count
= 0; count
< tz
->trips
; count
++)
863 TRIP_POINT_ATTR_REMOVE(&tz
->device
, count
);
865 thermal_remove_hwmon_sysfs(tz
);
866 release_idr(&thermal_tz_idr
, &thermal_idr_lock
, tz
->id
);
867 idr_destroy(&tz
->idr
);
868 mutex_destroy(&tz
->lock
);
869 device_unregister(&tz
->device
);
873 EXPORT_SYMBOL(thermal_zone_device_unregister
);
875 static int __init
thermal_init(void)
879 result
= class_register(&thermal_class
);
881 idr_destroy(&thermal_tz_idr
);
882 idr_destroy(&thermal_cdev_idr
);
883 mutex_destroy(&thermal_idr_lock
);
884 mutex_destroy(&thermal_list_lock
);
889 static void __exit
thermal_exit(void)
891 class_unregister(&thermal_class
);
892 idr_destroy(&thermal_tz_idr
);
893 idr_destroy(&thermal_cdev_idr
);
894 mutex_destroy(&thermal_idr_lock
);
895 mutex_destroy(&thermal_list_lock
);
898 subsys_initcall(thermal_init
);
899 module_exit(thermal_exit
);