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>
61 if (!strncasecmp(name, pos->name, THERMAL_NAME_LENGTH)) in __find_governor()
68 * bind_previous_governor() - bind the previous governor of the thermal zone
78 if (tz->governor && tz->governor->bind_to_tz) { in bind_previous_governor()
79 if (tz->governor->bind_to_tz(tz)) { in bind_previous_governor()
80 dev_err(&tz->device, in bind_previous_governor()
82 failed_gov_name, tz->governor->name, tz->type); in bind_previous_governor()
83 tz->governor = NULL; in bind_previous_governor()
89 * thermal_set_governor() - Switch to another governor
102 if (tz->governor && tz->governor->unbind_from_tz) in thermal_set_governor()
103 tz->governor->unbind_from_tz(tz); in thermal_set_governor()
105 if (new_gov && new_gov->bind_to_tz) { in thermal_set_governor()
106 ret = new_gov->bind_to_tz(tz); in thermal_set_governor()
108 bind_previous_governor(tz, new_gov->name); in thermal_set_governor()
114 tz->governor = new_gov; in thermal_set_governor()
126 return -EINVAL; in thermal_register_governor()
130 err = -EBUSY; in thermal_register_governor()
131 if (!__find_governor(governor->name)) { in thermal_register_governor()
135 list_add(&governor->governor_list, &thermal_governor_list); in thermal_register_governor()
136 match_default = !strncmp(governor->name, in thermal_register_governor()
148 * only thermal zones with specified tz->tzp->governor_name in thermal_register_governor()
149 * may run with tz->govenor unset in thermal_register_governor()
151 if (pos->governor) in thermal_register_governor()
154 name = pos->tzp->governor_name; in thermal_register_governor()
156 if (!strncasecmp(name, governor->name, THERMAL_NAME_LENGTH)) { in thermal_register_governor()
161 dev_err(&pos->device, in thermal_register_governor()
163 governor->name, pos->type, ret); in thermal_register_governor()
182 if (!__find_governor(governor->name)) in thermal_unregister_governor()
188 if (!strncasecmp(pos->governor->name, governor->name, in thermal_unregister_governor()
194 list_del(&governor->governor_list); in thermal_unregister_governor()
203 int ret = -EINVAL; in thermal_zone_device_set_policy()
206 mutex_lock(&tz->lock); in thermal_zone_device_set_policy()
215 mutex_unlock(&tz->lock); in thermal_zone_device_set_policy()
218 thermal_notify_tz_gov_change(tz->id, policy); in thermal_zone_device_set_policy()
232 size = PAGE_SIZE - count; in thermal_build_list_of_policies()
233 count += scnprintf(buf + count, size, "%s ", pos->name); in thermal_build_list_of_policies()
259 (*governor)->name); in thermal_register_governors()
264 (*governor)->name); in thermal_register_governors()
287 * - Non-critical trips will invoke the governor responsible for that zone;
288 * - Hot trips will produce a notification to userspace;
289 * - Critical trip point will cause a system shutdown.
296 &tz->poll_queue, in thermal_zone_device_set_polling()
300 &tz->poll_queue, in thermal_zone_device_set_polling()
303 cancel_delayed_work(&tz->poll_queue); in thermal_zone_device_set_polling()
317 mutex_lock(&tz->lock); in monitor_thermal_zone()
319 if (!stop && tz->passive) in monitor_thermal_zone()
320 thermal_zone_device_set_polling(tz, tz->passive_delay); in monitor_thermal_zone()
321 else if (!stop && tz->polling_delay) in monitor_thermal_zone()
322 thermal_zone_device_set_polling(tz, tz->polling_delay); in monitor_thermal_zone()
326 mutex_unlock(&tz->lock); in monitor_thermal_zone()
331 tz->governor ? tz->governor->throttle(tz, trip) : in handle_non_critical_trips()
332 def_governor->throttle(tz, trip); in handle_non_critical_trips()
336 * thermal_emergency_poweroff_func - emergency poweroff work after a known delay
365 * thermal_emergency_poweroff - Trigger an emergency system poweroff
388 tz->ops->get_trip_temp(tz, trip, &trip_temp); in handle_critical_trips()
391 if (trip_temp <= 0 || tz->temperature < trip_temp) in handle_critical_trips()
396 if (tz->ops->notify) in handle_critical_trips()
397 tz->ops->notify(tz, trip, trip_type); in handle_critical_trips()
400 dev_emerg(&tz->device, in handle_critical_trips()
402 tz->temperature / 1000); in handle_critical_trips()
423 if (test_bit(trip, &tz->trips_disabled)) in handle_thermal_trip()
426 tz->ops->get_trip_temp(tz, trip, &trip_temp); in handle_thermal_trip()
427 tz->ops->get_trip_type(tz, trip, &type); in handle_thermal_trip()
428 if (tz->ops->get_trip_hyst) in handle_thermal_trip()
429 tz->ops->get_trip_hyst(tz, trip, &hyst); in handle_thermal_trip()
431 if (tz->last_temperature != THERMAL_TEMP_INVALID) { in handle_thermal_trip()
432 if (tz->last_temperature < trip_temp && in handle_thermal_trip()
433 tz->temperature >= trip_temp) in handle_thermal_trip()
434 thermal_notify_tz_trip_up(tz->id, trip); in handle_thermal_trip()
435 if (tz->last_temperature >= trip_temp && in handle_thermal_trip()
436 tz->temperature < (trip_temp - hyst)) in handle_thermal_trip()
437 thermal_notify_tz_trip_down(tz->id, trip); in handle_thermal_trip()
457 if (ret != -EAGAIN) in update_temperature()
458 dev_warn(&tz->device, in update_temperature()
464 mutex_lock(&tz->lock); in update_temperature()
465 tz->last_temperature = tz->temperature; in update_temperature()
466 tz->temperature = temp; in update_temperature()
467 mutex_unlock(&tz->lock); in update_temperature()
471 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
477 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
478 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
479 pos->initialized = false; in thermal_zone_device_init()
484 tz->passive = 0; in thermal_zone_device_reset()
493 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
496 if (mode == tz->mode) { in thermal_zone_device_set_mode()
497 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
502 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
503 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
506 tz->mode = mode; in thermal_zone_device_set_mode()
508 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
513 thermal_notify_tz_enable(tz->id); in thermal_zone_device_set_mode()
515 thermal_notify_tz_disable(tz->id); in thermal_zone_device_set_mode()
536 mutex_lock(&tz->lock); in thermal_zone_device_is_enabled()
538 mode = tz->mode; in thermal_zone_device_is_enabled()
540 mutex_unlock(&tz->lock); in thermal_zone_device_is_enabled()
556 if (!tz->ops->get_temp) in thermal_zone_device_update()
563 tz->notify_event = event; in thermal_zone_device_update()
565 for (count = 0; count < tz->trips; count++) in thermal_zone_device_update()
571 * thermal_notify_framework - Sensor drivers use this API to notify framework
572 * @tz: thermal zone device
576 * throttling the cooling devices according to the policy configured.
599 * Set of functions used to interact to cooling devices that know
604 * power_actor_get_max_power() - get the maximum power that a cdev can consume
609 * cooling device can currently consume and store it in @max_power.
611 * Return: 0 on success, -EINVAL if @cdev doesn't support the
612 * power_actor API or -E* on other error.
618 return -EINVAL; in power_actor_get_max_power()
620 return cdev->ops->state2power(cdev, 0, max_power); in power_actor_get_max_power()
624 * power_actor_get_min_power() - get the mainimum power that a cdev can consume
629 * cooling device can currently consume and store it in @min_power.
631 * Return: 0 on success, -EINVAL if @cdev doesn't support the
632 * power_actor API or -E* on other error.
641 return -EINVAL; in power_actor_get_min_power()
643 ret = cdev->ops->get_max_state(cdev, &max_state); in power_actor_get_min_power()
647 return cdev->ops->state2power(cdev, max_state, min_power); in power_actor_get_min_power()
651 * power_actor_set_power() - limit the maximum power a cooling device consumes
656 * Set the cooling device to consume at most @power milliwatts. The limit is
659 * Return: 0 on success, -EINVAL if the cooling device does not
660 * implement the power actor API or -E* for other failures.
669 return -EINVAL; in power_actor_set_power()
671 ret = cdev->ops->power2state(cdev, power, &state); in power_actor_set_power()
675 instance->target = state; in power_actor_set_power()
676 mutex_lock(&cdev->lock); in power_actor_set_power()
677 cdev->updated = false; in power_actor_set_power()
678 mutex_unlock(&cdev->lock); in power_actor_set_power()
692 if (strncmp(cdev_type, cdev->type, size)) in thermal_zone_device_rebind_exception()
761 if (tz->id == id) { in thermal_zone_get_by_id()
779 if (strncmp(cdev_type, cdev->type, size)) in thermal_zone_device_unbind_exception()
789 * Device management section: cooling devices, zones devices, and binding
792 * - cooling devices lifecycle: registration, unregistration,
794 * - thermal zone devices lifecycle: registration, unregistration,
799 * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
801 * @trip: indicates which trip point the cooling devices is
804 * @upper: the Maximum cooling state for this trip point.
806 * and the cooling device can be in max_state.
807 * @lower: the Minimum cooling state can be used for this trip point.
809 * and the cooling device can be in cooling state 0.
810 * @weight: The weight of the cooling device to be bound to the
814 * This interface function bind a thermal cooling device to the certain trip
815 * point of a thermal zone device.
816 * This function is usually called in the thermal zone device .bind callback.
833 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE)) in thermal_zone_bind_cooling_device()
834 return -EINVAL; in thermal_zone_bind_cooling_device()
846 return -EINVAL; in thermal_zone_bind_cooling_device()
848 ret = cdev->ops->get_max_state(cdev, &max_state); in thermal_zone_bind_cooling_device()
857 return -EINVAL; in thermal_zone_bind_cooling_device()
861 return -ENOMEM; in thermal_zone_bind_cooling_device()
862 dev->tz = tz; in thermal_zone_bind_cooling_device()
863 dev->cdev = cdev; in thermal_zone_bind_cooling_device()
864 dev->trip = trip; in thermal_zone_bind_cooling_device()
865 dev->upper = upper; in thermal_zone_bind_cooling_device()
866 dev->lower = lower; in thermal_zone_bind_cooling_device()
867 dev->target = THERMAL_NO_TARGET; in thermal_zone_bind_cooling_device()
868 dev->weight = weight; in thermal_zone_bind_cooling_device()
870 result = ida_simple_get(&tz->ida, 0, 0, GFP_KERNEL); in thermal_zone_bind_cooling_device()
874 dev->id = result; in thermal_zone_bind_cooling_device()
875 sprintf(dev->name, "cdev%d", dev->id); in thermal_zone_bind_cooling_device()
877 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
881 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id); in thermal_zone_bind_cooling_device()
882 sysfs_attr_init(&dev->attr.attr); in thermal_zone_bind_cooling_device()
883 dev->attr.attr.name = dev->attr_name; in thermal_zone_bind_cooling_device()
884 dev->attr.attr.mode = 0444; in thermal_zone_bind_cooling_device()
885 dev->attr.show = trip_point_show; in thermal_zone_bind_cooling_device()
886 result = device_create_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
890 sprintf(dev->weight_attr_name, "cdev%d_weight", dev->id); in thermal_zone_bind_cooling_device()
891 sysfs_attr_init(&dev->weight_attr.attr); in thermal_zone_bind_cooling_device()
892 dev->weight_attr.attr.name = dev->weight_attr_name; in thermal_zone_bind_cooling_device()
893 dev->weight_attr.attr.mode = S_IWUSR | S_IRUGO; in thermal_zone_bind_cooling_device()
894 dev->weight_attr.show = weight_show; in thermal_zone_bind_cooling_device()
895 dev->weight_attr.store = weight_store; in thermal_zone_bind_cooling_device()
896 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
900 mutex_lock(&tz->lock); in thermal_zone_bind_cooling_device()
901 mutex_lock(&cdev->lock); in thermal_zone_bind_cooling_device()
902 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_bind_cooling_device()
903 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_bind_cooling_device()
904 result = -EEXIST; in thermal_zone_bind_cooling_device()
908 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_zone_bind_cooling_device()
909 list_add_tail(&dev->cdev_node, &cdev->thermal_instances); in thermal_zone_bind_cooling_device()
910 atomic_set(&tz->need_update, 1); in thermal_zone_bind_cooling_device()
912 mutex_unlock(&cdev->lock); in thermal_zone_bind_cooling_device()
913 mutex_unlock(&tz->lock); in thermal_zone_bind_cooling_device()
918 device_remove_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
920 device_remove_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
922 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
924 ida_simple_remove(&tz->ida, dev->id); in thermal_zone_bind_cooling_device()
932 * thermal_zone_unbind_cooling_device() - unbind a cooling device from a
935 * @trip: indicates which trip point the cooling devices is
939 * This interface function unbind a thermal cooling device from the certain
940 * trip point of a thermal zone device.
941 * This function is usually called in the thermal zone device .unbind callback.
951 mutex_lock(&tz->lock); in thermal_zone_unbind_cooling_device()
952 mutex_lock(&cdev->lock); in thermal_zone_unbind_cooling_device()
953 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_zone_unbind_cooling_device()
954 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_unbind_cooling_device()
955 list_del(&pos->tz_node); in thermal_zone_unbind_cooling_device()
956 list_del(&pos->cdev_node); in thermal_zone_unbind_cooling_device()
957 mutex_unlock(&cdev->lock); in thermal_zone_unbind_cooling_device()
958 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
962 mutex_unlock(&cdev->lock); in thermal_zone_unbind_cooling_device()
963 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
965 return -ENODEV; in thermal_zone_unbind_cooling_device()
968 device_remove_file(&tz->device, &pos->weight_attr); in thermal_zone_unbind_cooling_device()
969 device_remove_file(&tz->device, &pos->attr); in thermal_zone_unbind_cooling_device()
970 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_zone_unbind_cooling_device()
971 ida_simple_remove(&tz->ida, pos->id); in thermal_zone_unbind_cooling_device()
977 static void thermal_release(struct device *dev) in thermal_release()
983 sizeof("thermal_zone") - 1)) { in thermal_release()
988 sizeof("cooling_device") - 1)) { in thermal_release()
1003 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
1004 tz->type, cdev->type, ret); in print_bind_err_msg()
1014 for (i = 0; i < tz->trips; i++) { in __bind()
1042 if (!pos->tzp && !pos->ops->bind) in bind_cdev()
1045 if (pos->ops->bind) { in bind_cdev()
1046 ret = pos->ops->bind(pos, cdev); in bind_cdev()
1052 tzp = pos->tzp; in bind_cdev()
1053 if (!tzp || !tzp->tbp) in bind_cdev()
1056 for (i = 0; i < tzp->num_tbps; i++) { in bind_cdev()
1057 if (tzp->tbp[i].cdev || !tzp->tbp[i].match) in bind_cdev()
1059 if (tzp->tbp[i].match(pos, cdev)) in bind_cdev()
1061 tzp->tbp[i].cdev = cdev; in bind_cdev()
1062 __bind(pos, tzp->tbp[i].trip_mask, cdev, in bind_cdev()
1063 tzp->tbp[i].binding_limits, in bind_cdev()
1064 tzp->tbp[i].weight); in bind_cdev()
1072 * __thermal_cooling_device_register() - register a new thermal cooling device
1073 * @np: a pointer to a device tree node.
1074 * @type: the thermal cooling device type.
1075 * @devdata: device private data.
1076 * @ops: standard thermal cooling devices callbacks.
1078 * This interface function adds a new thermal cooling device (fan/processor/...)
1079 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1081 * It also gives the opportunity to link the cooling device to a device tree
1082 * node, so that it can be bound to a thermal zone created out of device tree.
1097 return ERR_PTR(-EINVAL); in __thermal_cooling_device_register()
1099 if (!ops || !ops->get_max_state || !ops->get_cur_state || in __thermal_cooling_device_register()
1100 !ops->set_cur_state) in __thermal_cooling_device_register()
1101 return ERR_PTR(-EINVAL); in __thermal_cooling_device_register()
1105 return ERR_PTR(-ENOMEM); in __thermal_cooling_device_register()
1113 cdev->id = result; in __thermal_cooling_device_register()
1114 strlcpy(cdev->type, type ? : "", sizeof(cdev->type)); in __thermal_cooling_device_register()
1115 mutex_init(&cdev->lock); in __thermal_cooling_device_register()
1116 INIT_LIST_HEAD(&cdev->thermal_instances); in __thermal_cooling_device_register()
1117 cdev->np = np; in __thermal_cooling_device_register()
1118 cdev->ops = ops; in __thermal_cooling_device_register()
1119 cdev->updated = false; in __thermal_cooling_device_register()
1120 cdev->device.class = &thermal_class; in __thermal_cooling_device_register()
1121 cdev->devdata = devdata; in __thermal_cooling_device_register()
1123 dev_set_name(&cdev->device, "cooling_device%d", cdev->id); in __thermal_cooling_device_register()
1124 result = device_register(&cdev->device); in __thermal_cooling_device_register()
1126 ida_simple_remove(&thermal_cdev_ida, cdev->id); in __thermal_cooling_device_register()
1127 put_device(&cdev->device); in __thermal_cooling_device_register()
1133 list_add(&cdev->node, &thermal_cdev_list); in __thermal_cooling_device_register()
1141 if (atomic_cmpxchg(&pos->need_update, 1, 0)) in __thermal_cooling_device_register()
1150 * thermal_cooling_device_register() - register a new thermal cooling device
1151 * @type: the thermal cooling device type.
1152 * @devdata: device private data.
1153 * @ops: standard thermal cooling devices callbacks.
1155 * This interface function adds a new thermal cooling device (fan/processor/...)
1156 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1171 * thermal_of_cooling_device_register() - register an OF thermal cooling device
1172 * @np: a pointer to a device tree node.
1173 * @type: the thermal cooling device type.
1174 * @devdata: device private data.
1175 * @ops: standard thermal cooling devices callbacks.
1177 * This function will register a cooling device with device tree node reference.
1178 * This interface function adds a new thermal cooling device (fan/processor/...)
1179 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1194 static void thermal_cooling_device_release(struct device *dev, void *res) in thermal_cooling_device_release()
1201 * devm_thermal_of_cooling_device_register() - register an OF thermal cooling
1202 * device
1203 * @dev: a valid struct device pointer of a sensor device.
1204 * @np: a pointer to a device tree node.
1205 * @type: the thermal cooling device type.
1206 * @devdata: device private data.
1207 * @ops: standard thermal cooling devices callbacks.
1209 * This function will register a cooling device with device tree node reference.
1210 * This interface function adds a new thermal cooling device (fan/processor/...)
1211 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1218 devm_thermal_of_cooling_device_register(struct device *dev, in devm_thermal_of_cooling_device_register()
1228 return ERR_PTR(-ENOMEM); in devm_thermal_of_cooling_device_register()
1248 for (i = 0; i < tz->trips; i++) in __unbind()
1254 * thermal_cooling_device_unregister - removes a thermal cooling device
1255 * @cdev: the thermal cooling device to remove.
1258 * thermal cooling device is no longer needed.
1275 /* thermal cooling device not found */ in thermal_cooling_device_unregister()
1279 list_del(&cdev->node); in thermal_cooling_device_unregister()
1283 if (tz->ops->unbind) { in thermal_cooling_device_unregister()
1284 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1288 if (!tz->tzp || !tz->tzp->tbp) in thermal_cooling_device_unregister()
1291 tzp = tz->tzp; in thermal_cooling_device_unregister()
1292 for (i = 0; i < tzp->num_tbps; i++) { in thermal_cooling_device_unregister()
1293 if (tzp->tbp[i].cdev == cdev) { in thermal_cooling_device_unregister()
1294 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_cooling_device_unregister()
1295 tzp->tbp[i].cdev = NULL; in thermal_cooling_device_unregister()
1302 ida_simple_remove(&thermal_cdev_ida, cdev->id); in thermal_cooling_device_unregister()
1303 device_del(&cdev->device); in thermal_cooling_device_unregister()
1305 put_device(&cdev->device); in thermal_cooling_device_unregister()
1313 const struct thermal_zone_params *tzp = tz->tzp; in bind_tz()
1315 if (!tzp && !tz->ops->bind) in bind_tz()
1320 /* If there is ops->bind, try to use ops->bind */ in bind_tz()
1321 if (tz->ops->bind) { in bind_tz()
1323 ret = tz->ops->bind(tz, pos); in bind_tz()
1330 if (!tzp || !tzp->tbp) in bind_tz()
1334 for (i = 0; i < tzp->num_tbps; i++) { in bind_tz()
1335 if (tzp->tbp[i].cdev || !tzp->tbp[i].match) in bind_tz()
1337 if (tzp->tbp[i].match(tz, pos)) in bind_tz()
1339 tzp->tbp[i].cdev = pos; in bind_tz()
1340 __bind(tz, tzp->tbp[i].trip_mask, pos, in bind_tz()
1341 tzp->tbp[i].binding_limits, in bind_tz()
1342 tzp->tbp[i].weight); in bind_tz()
1350 * thermal_zone_device_register() - register a new thermal zone device
1351 * @type: the thermal zone device type
1354 * @devdata: private device data
1355 * @ops: standard thermal zone device callbacks
1358 * performing passive cooling
1363 * This interface function adds a new thermal zone device (sensor) to
1364 * /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the
1365 * thermal cooling devices registered at the same time.
1366 * thermal_zone_device_unregister() must be called when the device is no
1367 * longer needed. The passive cooling depends on the .get_trend() return value.
1389 return ERR_PTR(-EINVAL); in thermal_zone_device_register()
1395 return ERR_PTR(-EINVAL); in thermal_zone_device_register()
1400 return ERR_PTR(-EINVAL); in thermal_zone_device_register()
1404 pr_err("Error: Thermal zone device ops not defined\n"); in thermal_zone_device_register()
1405 return ERR_PTR(-EINVAL); in thermal_zone_device_register()
1408 if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp)) in thermal_zone_device_register()
1409 return ERR_PTR(-EINVAL); in thermal_zone_device_register()
1413 return ERR_PTR(-ENOMEM); in thermal_zone_device_register()
1415 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register()
1416 ida_init(&tz->ida); in thermal_zone_device_register()
1417 mutex_init(&tz->lock); in thermal_zone_device_register()
1424 tz->id = id; in thermal_zone_device_register()
1425 strlcpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register()
1426 tz->ops = ops; in thermal_zone_device_register()
1427 tz->tzp = tzp; in thermal_zone_device_register()
1428 tz->device.class = &thermal_class; in thermal_zone_device_register()
1429 tz->devdata = devdata; in thermal_zone_device_register()
1430 tz->trips = trips; in thermal_zone_device_register()
1431 tz->passive_delay = passive_delay; in thermal_zone_device_register()
1432 tz->polling_delay = polling_delay; in thermal_zone_device_register()
1441 atomic_set(&tz->need_update, 1); in thermal_zone_device_register()
1443 dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register()
1444 result = device_register(&tz->device); in thermal_zone_device_register()
1449 if (tz->ops->get_trip_type(tz, count, &trip_type)) in thermal_zone_device_register()
1450 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1451 if (tz->ops->get_trip_temp(tz, count, &trip_temp)) in thermal_zone_device_register()
1452 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1455 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1461 if (tz->tzp) in thermal_zone_device_register()
1462 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register()
1474 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register()
1481 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register()
1484 /* Bind cooling devices for this zone */ in thermal_zone_device_register()
1487 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_register()
1491 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register()
1494 thermal_notify_tz_create(tz->id, tz->type); in thermal_zone_device_register()
1499 device_del(&tz->device); in thermal_zone_device_register()
1501 put_device(&tz->device); in thermal_zone_device_register()
1512 * thermal_device_unregister - removes the registered thermal zone device
1513 * @tz: the thermal zone device to remove
1525 tzp = tz->tzp; in thermal_zone_device_unregister()
1526 tz_id = tz->id; in thermal_zone_device_unregister()
1533 /* thermal zone device not found */ in thermal_zone_device_unregister()
1537 list_del(&tz->node); in thermal_zone_device_unregister()
1541 if (tz->ops->unbind) { in thermal_zone_device_unregister()
1542 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1546 if (!tzp || !tzp->tbp) in thermal_zone_device_unregister()
1549 for (i = 0; i < tzp->num_tbps; i++) { in thermal_zone_device_unregister()
1550 if (tzp->tbp[i].cdev == cdev) { in thermal_zone_device_unregister()
1551 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_zone_device_unregister()
1552 tzp->tbp[i].cdev = NULL; in thermal_zone_device_unregister()
1559 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1564 ida_simple_remove(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1565 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1566 mutex_destroy(&tz->lock); in thermal_zone_device_unregister()
1567 device_unregister(&tz->device); in thermal_zone_device_unregister()
1574 * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
1580 * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
1581 * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
1585 struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL); in thermal_zone_get_zone_by_name()
1593 if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { in thermal_zone_get_zone_by_name()
1601 ref = ERR_PTR(-ENODEV); in thermal_zone_get_zone_by_name()
1604 ref = ERR_PTR(-EEXIST); in thermal_zone_get_zone_by_name()