Lines Matching +full:cooling +full:- +full:device

1 // SPDX-License-Identifier: GPL-2.0
3 * thermal.c - Generic Thermal Management Sysfs support.
12 #include <linux/device.h>
57 if (!strncasecmp(name, pos->name, THERMAL_NAME_LENGTH)) in __find_governor()
64 * bind_previous_governor() - bind the previous governor of the thermal zone
74 if (tz->governor && tz->governor->bind_to_tz) { in bind_previous_governor()
75 if (tz->governor->bind_to_tz(tz)) { in bind_previous_governor()
76 dev_err(&tz->device, in bind_previous_governor()
78 failed_gov_name, tz->governor->name, tz->type); in bind_previous_governor()
79 tz->governor = NULL; in bind_previous_governor()
85 * thermal_set_governor() - Switch to another governor
98 if (tz->governor && tz->governor->unbind_from_tz) in thermal_set_governor()
99 tz->governor->unbind_from_tz(tz); in thermal_set_governor()
101 if (new_gov && new_gov->bind_to_tz) { in thermal_set_governor()
102 ret = new_gov->bind_to_tz(tz); in thermal_set_governor()
104 bind_previous_governor(tz, new_gov->name); in thermal_set_governor()
110 tz->governor = new_gov; in thermal_set_governor()
122 return -EINVAL; in thermal_register_governor()
126 err = -EBUSY; in thermal_register_governor()
127 if (!__find_governor(governor->name)) { in thermal_register_governor()
131 list_add(&governor->governor_list, &thermal_governor_list); in thermal_register_governor()
132 match_default = !strncmp(governor->name, in thermal_register_governor()
144 * only thermal zones with specified tz->tzp->governor_name in thermal_register_governor()
145 * may run with tz->govenor unset in thermal_register_governor()
147 if (pos->governor) in thermal_register_governor()
150 name = pos->tzp->governor_name; in thermal_register_governor()
152 if (!strncasecmp(name, governor->name, THERMAL_NAME_LENGTH)) { in thermal_register_governor()
157 dev_err(&pos->device, in thermal_register_governor()
159 governor->name, pos->type, ret); in thermal_register_governor()
178 if (!__find_governor(governor->name)) in thermal_unregister_governor()
184 if (!strncasecmp(pos->governor->name, governor->name, in thermal_unregister_governor()
190 list_del(&governor->governor_list); in thermal_unregister_governor()
199 int ret = -EINVAL; in thermal_zone_device_set_policy()
202 mutex_lock(&tz->lock); in thermal_zone_device_set_policy()
211 mutex_unlock(&tz->lock); in thermal_zone_device_set_policy()
227 count += sysfs_emit_at(buf, count, "%s ", pos->name); in thermal_build_list_of_policies()
253 (*governor)->name); in thermal_register_governors()
258 (*governor)->name); in thermal_register_governors()
281 * - Non-critical trips will invoke the governor responsible for that zone;
282 * - Hot trips will produce a notification to userspace;
283 * - Critical trip point will cause a system shutdown.
290 &tz->poll_queue, delay); in thermal_zone_device_set_polling()
292 cancel_delayed_work(&tz->poll_queue); in thermal_zone_device_set_polling()
297 if (tz->mode != THERMAL_DEVICE_ENABLED) in monitor_thermal_zone()
299 else if (tz->passive) in monitor_thermal_zone()
300 thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies); in monitor_thermal_zone()
301 else if (tz->polling_delay_jiffies) in monitor_thermal_zone()
302 thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); in monitor_thermal_zone()
308 tz->governor ? tz->governor->throttle(tz, trip) : in handle_non_critical_trips()
309 def_governor->throttle(tz, trip); in handle_non_critical_trips()
315 if (!tz->governor || !tz->governor->update_tz) in thermal_governor_update_tz()
318 tz->governor->update_tz(tz, reason); in thermal_governor_update_tz()
330 dev_emerg(&tz->device, "%s: critical temperature reached\n", tz->type); in thermal_zone_device_halt()
353 if (trip->temperature <= 0 || tz->temperature < trip->temperature) in handle_critical_trips()
356 trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type); in handle_critical_trips()
358 if (trip->type == THERMAL_TRIP_CRITICAL) in handle_critical_trips()
359 tz->ops->critical(tz); in handle_critical_trips()
360 else if (tz->ops->hot) in handle_critical_trips()
361 tz->ops->hot(tz); in handle_critical_trips()
367 if (trip->temperature == THERMAL_TEMP_INVALID) in handle_thermal_trip()
370 if (tz->last_temperature == THERMAL_TEMP_INVALID) { in handle_thermal_trip()
372 trip->threshold = trip->temperature; in handle_thermal_trip()
373 if (tz->temperature >= trip->threshold) in handle_thermal_trip()
374 trip->threshold -= trip->hysteresis; in handle_thermal_trip()
375 } else if (tz->last_temperature < trip->threshold) { in handle_thermal_trip()
383 if (tz->temperature >= trip->temperature) { in handle_thermal_trip()
386 trip->threshold = trip->temperature - trip->hysteresis; in handle_thermal_trip()
388 trip->threshold = trip->temperature; in handle_thermal_trip()
401 if (tz->temperature < trip->temperature - trip->hysteresis) { in handle_thermal_trip()
404 trip->threshold = trip->temperature; in handle_thermal_trip()
406 trip->threshold = trip->temperature - trip->hysteresis; in handle_thermal_trip()
410 if (trip->type == THERMAL_TRIP_CRITICAL || trip->type == THERMAL_TRIP_HOT) in handle_thermal_trip()
422 if (ret != -EAGAIN) in update_temperature()
423 dev_warn(&tz->device, in update_temperature()
429 tz->last_temperature = tz->temperature; in update_temperature()
430 tz->temperature = temp; in update_temperature()
434 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
450 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_init()
452 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
453 tz->prev_low_trip = -INT_MAX; in thermal_zone_device_init()
454 tz->prev_high_trip = INT_MAX; in thermal_zone_device_init()
455 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
456 pos->initialized = false; in thermal_zone_device_init()
464 if (tz->suspended) in __thermal_zone_device_update()
474 tz->notify_event = event; in __thermal_zone_device_update()
487 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
490 if (mode == tz->mode) { in thermal_zone_device_set_mode()
491 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
496 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
497 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
500 tz->mode = mode; in thermal_zone_device_set_mode()
504 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
528 lockdep_assert_held(&tz->lock); in thermal_zone_device_is_enabled()
530 return tz->mode == THERMAL_DEVICE_ENABLED; in thermal_zone_device_is_enabled()
535 return !list_empty(&tz->node); in thermal_zone_is_present()
541 mutex_lock(&tz->lock); in thermal_zone_device_update()
544 mutex_unlock(&tz->lock); in thermal_zone_device_update()
605 if (tz->id == id) { in thermal_zone_get_by_id()
616 * Device management section: cooling devices, zones devices, and binding
619 * - cooling devices lifecycle: registration, unregistration,
621 * - thermal zone devices lifecycle: registration, unregistration,
626 * thermal_bind_cdev_to_trip - bind a cooling device to a thermal zone
628 * @trip: trip point the cooling devices is associated with in this zone.
630 * @upper: the Maximum cooling state for this trip point.
632 * and the cooling device can be in max_state.
633 * @lower: the Minimum cooling state can be used for this trip point.
635 * and the cooling device can be in cooling state 0.
636 * @weight: The weight of the cooling device to be bound to the
640 * This interface function bind a thermal cooling device to the certain trip
641 * point of a thermal zone device.
642 * This function is usually called in the thermal zone device .bind callback.
669 return -EINVAL; in thermal_bind_cdev_to_trip()
675 upper = cdev->max_state; in thermal_bind_cdev_to_trip()
681 if (lower > upper || upper > cdev->max_state) in thermal_bind_cdev_to_trip()
682 return -EINVAL; in thermal_bind_cdev_to_trip()
686 return -ENOMEM; in thermal_bind_cdev_to_trip()
687 dev->tz = tz; in thermal_bind_cdev_to_trip()
688 dev->cdev = cdev; in thermal_bind_cdev_to_trip()
689 dev->trip = trip; in thermal_bind_cdev_to_trip()
690 dev->upper = upper; in thermal_bind_cdev_to_trip()
691 dev->upper_no_limit = upper_no_limit; in thermal_bind_cdev_to_trip()
692 dev->lower = lower; in thermal_bind_cdev_to_trip()
693 dev->target = THERMAL_NO_TARGET; in thermal_bind_cdev_to_trip()
694 dev->weight = weight; in thermal_bind_cdev_to_trip()
696 result = ida_alloc(&tz->ida, GFP_KERNEL); in thermal_bind_cdev_to_trip()
700 dev->id = result; in thermal_bind_cdev_to_trip()
701 sprintf(dev->name, "cdev%d", dev->id); in thermal_bind_cdev_to_trip()
703 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_bind_cdev_to_trip()
707 snprintf(dev->attr_name, sizeof(dev->attr_name), "cdev%d_trip_point", in thermal_bind_cdev_to_trip()
708 dev->id); in thermal_bind_cdev_to_trip()
709 sysfs_attr_init(&dev->attr.attr); in thermal_bind_cdev_to_trip()
710 dev->attr.attr.name = dev->attr_name; in thermal_bind_cdev_to_trip()
711 dev->attr.attr.mode = 0444; in thermal_bind_cdev_to_trip()
712 dev->attr.show = trip_point_show; in thermal_bind_cdev_to_trip()
713 result = device_create_file(&tz->device, &dev->attr); in thermal_bind_cdev_to_trip()
717 snprintf(dev->weight_attr_name, sizeof(dev->weight_attr_name), in thermal_bind_cdev_to_trip()
718 "cdev%d_weight", dev->id); in thermal_bind_cdev_to_trip()
719 sysfs_attr_init(&dev->weight_attr.attr); in thermal_bind_cdev_to_trip()
720 dev->weight_attr.attr.name = dev->weight_attr_name; in thermal_bind_cdev_to_trip()
721 dev->weight_attr.attr.mode = S_IWUSR | S_IRUGO; in thermal_bind_cdev_to_trip()
722 dev->weight_attr.show = weight_show; in thermal_bind_cdev_to_trip()
723 dev->weight_attr.store = weight_store; in thermal_bind_cdev_to_trip()
724 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_bind_cdev_to_trip()
728 mutex_lock(&tz->lock); in thermal_bind_cdev_to_trip()
729 mutex_lock(&cdev->lock); in thermal_bind_cdev_to_trip()
730 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_bind_cdev_to_trip()
731 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_bind_cdev_to_trip()
732 result = -EEXIST; in thermal_bind_cdev_to_trip()
736 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_bind_cdev_to_trip()
737 list_add_tail(&dev->cdev_node, &cdev->thermal_instances); in thermal_bind_cdev_to_trip()
738 atomic_set(&tz->need_update, 1); in thermal_bind_cdev_to_trip()
742 mutex_unlock(&cdev->lock); in thermal_bind_cdev_to_trip()
743 mutex_unlock(&tz->lock); in thermal_bind_cdev_to_trip()
748 device_remove_file(&tz->device, &dev->weight_attr); in thermal_bind_cdev_to_trip()
750 device_remove_file(&tz->device, &dev->attr); in thermal_bind_cdev_to_trip()
752 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_bind_cdev_to_trip()
754 ida_free(&tz->ida, dev->id); in thermal_bind_cdev_to_trip()
767 if (trip_index < 0 || trip_index >= tz->num_trips) in thermal_zone_bind_cooling_device()
768 return -EINVAL; in thermal_zone_bind_cooling_device()
770 return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index], cdev, in thermal_zone_bind_cooling_device()
776 * thermal_unbind_cdev_from_trip - unbind a cooling device from a thermal zone.
778 * @trip: trip point the cooling devices is associated with in this zone.
781 * This interface function unbind a thermal cooling device from the certain
782 * trip point of a thermal zone device.
783 * This function is usually called in the thermal zone device .unbind callback.
793 mutex_lock(&tz->lock); in thermal_unbind_cdev_from_trip()
794 mutex_lock(&cdev->lock); in thermal_unbind_cdev_from_trip()
795 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_unbind_cdev_from_trip()
796 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_unbind_cdev_from_trip()
797 list_del(&pos->tz_node); in thermal_unbind_cdev_from_trip()
798 list_del(&pos->cdev_node); in thermal_unbind_cdev_from_trip()
802 mutex_unlock(&cdev->lock); in thermal_unbind_cdev_from_trip()
803 mutex_unlock(&tz->lock); in thermal_unbind_cdev_from_trip()
807 mutex_unlock(&cdev->lock); in thermal_unbind_cdev_from_trip()
808 mutex_unlock(&tz->lock); in thermal_unbind_cdev_from_trip()
810 return -ENODEV; in thermal_unbind_cdev_from_trip()
813 device_remove_file(&tz->device, &pos->weight_attr); in thermal_unbind_cdev_from_trip()
814 device_remove_file(&tz->device, &pos->attr); in thermal_unbind_cdev_from_trip()
815 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_unbind_cdev_from_trip()
816 ida_free(&tz->ida, pos->id); in thermal_unbind_cdev_from_trip()
826 if (trip_index < 0 || trip_index >= tz->num_trips) in thermal_zone_unbind_cooling_device()
827 return -EINVAL; in thermal_zone_unbind_cooling_device()
829 return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index], cdev); in thermal_zone_unbind_cooling_device()
833 static void thermal_release(struct device *dev) in thermal_release()
839 sizeof("thermal_zone") - 1)) { in thermal_release()
842 mutex_destroy(&tz->lock); in thermal_release()
843 complete(&tz->removal); in thermal_release()
845 sizeof("cooling_device") - 1)) { in thermal_release()
848 kfree_const(cdev->type); in thermal_release()
849 ida_free(&thermal_cdev_ida, cdev->id); in thermal_release()
860 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
861 tz->type, cdev->type, ret); in print_bind_err_msg()
870 if (pos->ops->bind) { in bind_cdev()
871 ret = pos->ops->bind(pos, cdev); in bind_cdev()
879 * __thermal_cooling_device_register() - register a new thermal cooling device
880 * @np: a pointer to a device tree node.
881 * @type: the thermal cooling device type.
882 * @devdata: device private data.
883 * @ops: standard thermal cooling devices callbacks.
885 * This interface function adds a new thermal cooling device (fan/processor/...)
886 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
888 * It also gives the opportunity to link the cooling device to a device tree
889 * node, so that it can be bound to a thermal zone created out of device tree.
903 if (!ops || !ops->get_max_state || !ops->get_cur_state || in __thermal_cooling_device_register()
904 !ops->set_cur_state) in __thermal_cooling_device_register()
905 return ERR_PTR(-EINVAL); in __thermal_cooling_device_register()
908 return ERR_PTR(-ENODEV); in __thermal_cooling_device_register()
912 return ERR_PTR(-ENOMEM); in __thermal_cooling_device_register()
917 cdev->id = ret; in __thermal_cooling_device_register()
920 cdev->type = kstrdup_const(type ? type : "", GFP_KERNEL); in __thermal_cooling_device_register()
921 if (!cdev->type) { in __thermal_cooling_device_register()
922 ret = -ENOMEM; in __thermal_cooling_device_register()
926 mutex_init(&cdev->lock); in __thermal_cooling_device_register()
927 INIT_LIST_HEAD(&cdev->thermal_instances); in __thermal_cooling_device_register()
928 cdev->np = np; in __thermal_cooling_device_register()
929 cdev->ops = ops; in __thermal_cooling_device_register()
930 cdev->updated = false; in __thermal_cooling_device_register()
931 cdev->device.class = thermal_class; in __thermal_cooling_device_register()
932 cdev->devdata = devdata; in __thermal_cooling_device_register()
934 ret = cdev->ops->get_max_state(cdev, &cdev->max_state); in __thermal_cooling_device_register()
940 ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id); in __thermal_cooling_device_register()
944 ret = device_register(&cdev->device); in __thermal_cooling_device_register()
947 put_device(&cdev->device); in __thermal_cooling_device_register()
954 list_add(&cdev->node, &thermal_cdev_list); in __thermal_cooling_device_register()
960 if (atomic_cmpxchg(&pos->need_update, 1, 0)) in __thermal_cooling_device_register()
973 kfree_const(cdev->type); in __thermal_cooling_device_register()
982 * thermal_cooling_device_register() - register a new thermal cooling device
983 * @type: the thermal cooling device type.
984 * @devdata: device private data.
985 * @ops: standard thermal cooling devices callbacks.
987 * This interface function adds a new thermal cooling device (fan/processor/...)
988 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1003 * thermal_of_cooling_device_register() - register an OF thermal cooling device
1004 * @np: a pointer to a device tree node.
1005 * @type: the thermal cooling device type.
1006 * @devdata: device private data.
1007 * @ops: standard thermal cooling devices callbacks.
1009 * This function will register a cooling device with device tree node reference.
1010 * This interface function adds a new thermal cooling device (fan/processor/...)
1011 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1026 static void thermal_cooling_device_release(struct device *dev, void *res) in thermal_cooling_device_release()
1033 * devm_thermal_of_cooling_device_register() - register an OF thermal cooling
1034 * device
1035 * @dev: a valid struct device pointer of a sensor device.
1036 * @np: a pointer to a device tree node.
1037 * @type: the thermal cooling device type.
1038 * @devdata: device private data.
1039 * @ops: standard thermal cooling devices callbacks.
1041 * This function will register a cooling device with device tree node reference.
1042 * This interface function adds a new thermal cooling device (fan/processor/...)
1043 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1050 devm_thermal_of_cooling_device_register(struct device *dev, in devm_thermal_of_cooling_device_register()
1060 return ERR_PTR(-ENOMEM); in devm_thermal_of_cooling_device_register()
1088 * thermal_cooling_device_update - Update a cooling device object
1089 * @cdev: Target cooling device.
1093 * Must be called when the maximum cooling state of @cdev becomes invalid and so
1095 * cooling state value.
1106 * Hold thermal_list_lock throughout the update to prevent the device in thermal_cooling_device_update()
1118 mutex_lock(&cdev->lock); in thermal_cooling_device_update()
1120 if (cdev->ops->get_max_state(cdev, &cdev->max_state)) in thermal_cooling_device_update()
1125 list_for_each_entry(ti, &cdev->thermal_instances, cdev_node) { in thermal_cooling_device_update()
1126 if (ti->upper == cdev->max_state) in thermal_cooling_device_update()
1129 if (ti->upper < cdev->max_state) { in thermal_cooling_device_update()
1130 if (ti->upper_no_limit) in thermal_cooling_device_update()
1131 ti->upper = cdev->max_state; in thermal_cooling_device_update()
1136 ti->upper = cdev->max_state; in thermal_cooling_device_update()
1137 if (ti->lower > ti->upper) in thermal_cooling_device_update()
1138 ti->lower = ti->upper; in thermal_cooling_device_update()
1140 if (ti->target == THERMAL_NO_TARGET) in thermal_cooling_device_update()
1143 if (ti->target > ti->upper) in thermal_cooling_device_update()
1144 ti->target = ti->upper; in thermal_cooling_device_update()
1147 if (cdev->ops->get_cur_state(cdev, &state) || state > cdev->max_state) in thermal_cooling_device_update()
1153 mutex_unlock(&cdev->lock); in thermal_cooling_device_update()
1161 * thermal_cooling_device_unregister - removes a thermal cooling device
1162 * @cdev: the thermal cooling device to remove.
1165 * thermal cooling device is no longer needed.
1183 list_del(&cdev->node); in thermal_cooling_device_unregister()
1187 if (tz->ops->unbind) in thermal_cooling_device_unregister()
1188 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1193 device_unregister(&cdev->device); in thermal_cooling_device_unregister()
1202 if (!tz->ops->bind) in bind_tz()
1208 ret = tz->ops->bind(tz, pos); in bind_tz()
1225 int i, ret = -EINVAL; in thermal_zone_get_crit_temp()
1227 if (tz->ops->get_crit_temp) in thermal_zone_get_crit_temp()
1228 return tz->ops->get_crit_temp(tz, temp); in thermal_zone_get_crit_temp()
1230 if (!tz->trips) in thermal_zone_get_crit_temp()
1231 return -EINVAL; in thermal_zone_get_crit_temp()
1233 mutex_lock(&tz->lock); in thermal_zone_get_crit_temp()
1235 for (i = 0; i < tz->num_trips; i++) { in thermal_zone_get_crit_temp()
1236 if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) { in thermal_zone_get_crit_temp()
1237 *temp = tz->trips[i].temperature; in thermal_zone_get_crit_temp()
1243 mutex_unlock(&tz->lock); in thermal_zone_get_crit_temp()
1250 * thermal_zone_device_register_with_trips() - register a new thermal zone device
1251 * @type: the thermal zone device type
1255 * @devdata: private device data
1256 * @ops: standard thermal zone device callbacks
1259 * performing passive cooling
1264 * This interface function adds a new thermal zone device (sensor) to
1265 * /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the
1266 * thermal cooling devices registered at the same time.
1267 * thermal_zone_device_unregister() must be called when the device is no
1268 * longer needed. The passive cooling depends on the .get_trend() return value.
1287 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1293 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1299 * warning: right shift count >= width of type [-Wshift-count- overflow] in thermal_zone_device_register_with_trips()
1309 if (num_trips > (BITS_PER_TYPE(int) - 1) || num_trips < 0 || mask >> num_trips) { in thermal_zone_device_register_with_trips()
1311 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1314 if (!ops || !ops->get_temp) { in thermal_zone_device_register_with_trips()
1315 pr_err("Thermal zone device ops not defined\n"); in thermal_zone_device_register_with_trips()
1316 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1320 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1323 return ERR_PTR(-ENODEV); in thermal_zone_device_register_with_trips()
1327 return ERR_PTR(-ENOMEM); in thermal_zone_device_register_with_trips()
1330 tz->tzp = kmemdup(tzp, sizeof(*tzp), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1331 if (!tz->tzp) { in thermal_zone_device_register_with_trips()
1332 result = -ENOMEM; in thermal_zone_device_register_with_trips()
1337 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register_with_trips()
1338 INIT_LIST_HEAD(&tz->node); in thermal_zone_device_register_with_trips()
1339 ida_init(&tz->ida); in thermal_zone_device_register_with_trips()
1340 mutex_init(&tz->lock); in thermal_zone_device_register_with_trips()
1341 init_completion(&tz->removal); in thermal_zone_device_register_with_trips()
1348 tz->id = id; in thermal_zone_device_register_with_trips()
1349 strscpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register_with_trips()
1351 if (!ops->critical) in thermal_zone_device_register_with_trips()
1352 ops->critical = thermal_zone_device_critical; in thermal_zone_device_register_with_trips()
1354 tz->ops = ops; in thermal_zone_device_register_with_trips()
1355 tz->device.class = thermal_class; in thermal_zone_device_register_with_trips()
1356 tz->devdata = devdata; in thermal_zone_device_register_with_trips()
1357 tz->trips = trips; in thermal_zone_device_register_with_trips()
1358 tz->num_trips = num_trips; in thermal_zone_device_register_with_trips()
1360 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); in thermal_zone_device_register_with_trips()
1361 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay); in thermal_zone_device_register_with_trips()
1370 atomic_set(&tz->need_update, 1); in thermal_zone_device_register_with_trips()
1372 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register_with_trips()
1377 result = device_register(&tz->device); in thermal_zone_device_register_with_trips()
1384 if (tz->tzp) in thermal_zone_device_register_with_trips()
1385 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register_with_trips()
1397 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register_with_trips()
1404 mutex_lock(&tz->lock); in thermal_zone_device_register_with_trips()
1405 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register_with_trips()
1406 mutex_unlock(&tz->lock); in thermal_zone_device_register_with_trips()
1409 /* Bind cooling devices for this zone */ in thermal_zone_device_register_with_trips()
1414 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register_with_trips()
1424 device_del(&tz->device); in thermal_zone_device_register_with_trips()
1426 put_device(&tz->device); in thermal_zone_device_register_with_trips()
1430 kfree(tz->tzp); in thermal_zone_device_register_with_trips()
1450 return tzd->devdata; in thermal_zone_device_priv()
1456 return tzd->type; in thermal_zone_device_type()
1462 return tzd->id; in thermal_zone_device_id()
1466 struct device *thermal_zone_device(struct thermal_zone_device *tzd) in thermal_zone_device()
1468 return &tzd->device; in thermal_zone_device()
1473 * thermal_zone_device_unregister - removes the registered thermal zone device
1474 * @tz: the thermal zone device to remove
1491 /* thermal zone device not found */ in thermal_zone_device_unregister()
1496 mutex_lock(&tz->lock); in thermal_zone_device_unregister()
1497 list_del(&tz->node); in thermal_zone_device_unregister()
1498 mutex_unlock(&tz->lock); in thermal_zone_device_unregister()
1502 if (tz->ops->unbind) in thermal_zone_device_unregister()
1503 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1507 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1512 ida_free(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1513 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1515 device_del(&tz->device); in thermal_zone_device_unregister()
1517 kfree(tz->tzp); in thermal_zone_device_unregister()
1519 put_device(&tz->device); in thermal_zone_device_unregister()
1523 wait_for_completion(&tz->removal); in thermal_zone_device_unregister()
1529 * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
1535 * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
1536 * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
1540 struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL); in thermal_zone_get_zone_by_name()
1548 if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { in thermal_zone_get_zone_by_name()
1556 ref = ERR_PTR(-ENODEV); in thermal_zone_get_zone_by_name()
1559 ref = ERR_PTR(-EEXIST); in thermal_zone_get_zone_by_name()
1572 mutex_lock(&tz->lock); in thermal_zone_device_resume()
1574 tz->suspended = false; in thermal_zone_device_resume()
1579 mutex_unlock(&tz->lock); in thermal_zone_device_resume()
1594 mutex_lock(&tz->lock); in thermal_pm_notify()
1596 tz->suspended = true; in thermal_pm_notify()
1598 mutex_unlock(&tz->lock); in thermal_pm_notify()
1609 mutex_lock(&tz->lock); in thermal_pm_notify()
1611 cancel_delayed_work(&tz->poll_queue); in thermal_pm_notify()
1618 INIT_DELAYED_WORK(&tz->poll_queue, in thermal_pm_notify()
1622 &tz->poll_queue, 0); in thermal_pm_notify()
1624 mutex_unlock(&tz->lock); in thermal_pm_notify()
1655 result = -ENOMEM; in thermal_init()
1659 thermal_class->name = "thermal"; in thermal_init()
1660 thermal_class->dev_release = thermal_release; in thermal_init()