Lines Matching +full:thermal +full:- +full:zone

1 // SPDX-License-Identifier: GPL-2.0
3 * thermal.c - Generic Thermal Management Sysfs support.
18 #include <linux/thermal.h>
45 * Governor section: set of functions to handle thermal governors
47 * Functions to help in the life cycle of thermal governors within
48 * the thermal core and by the thermal governor code.
59 if (!strncasecmp(name, pos->name, THERMAL_NAME_LENGTH)) in __find_governor()
66 * bind_previous_governor() - bind the previous governor of the thermal zone
70 * Register the previous governor of the thermal zone after a new
76 if (tz->governor && tz->governor->bind_to_tz) { in bind_previous_governor()
77 if (tz->governor->bind_to_tz(tz)) { in bind_previous_governor()
78 dev_err(&tz->device, in bind_previous_governor()
79 …"governor %s failed to bind and the previous one (%s) failed to bind again, thermal zone %s has no… in bind_previous_governor()
80 failed_gov_name, tz->governor->name, tz->type); in bind_previous_governor()
81 tz->governor = NULL; in bind_previous_governor()
87 * thermal_set_governor() - Switch to another governor
91 * Change the governor of thermal zone @tz.
100 if (tz->governor && tz->governor->unbind_from_tz) in thermal_set_governor()
101 tz->governor->unbind_from_tz(tz); in thermal_set_governor()
103 if (new_gov && new_gov->bind_to_tz) { in thermal_set_governor()
104 ret = new_gov->bind_to_tz(tz); in thermal_set_governor()
106 bind_previous_governor(tz, new_gov->name); in thermal_set_governor()
112 tz->governor = new_gov; in thermal_set_governor()
124 return -EINVAL; in thermal_register_governor()
128 err = -EBUSY; in thermal_register_governor()
129 if (!__find_governor(governor->name)) { in thermal_register_governor()
133 list_add(&governor->governor_list, &thermal_governor_list); in thermal_register_governor()
134 match_default = !strncmp(governor->name, in thermal_register_governor()
146 * only thermal zones with specified tz->tzp->governor_name in thermal_register_governor()
147 * may run with tz->govenor unset in thermal_register_governor()
149 if (pos->governor) in thermal_register_governor()
152 name = pos->tzp->governor_name; in thermal_register_governor()
154 if (!strncasecmp(name, governor->name, THERMAL_NAME_LENGTH)) { in thermal_register_governor()
159 dev_err(&pos->device, in thermal_register_governor()
160 "Failed to set governor %s for thermal zone %s: %d\n", in thermal_register_governor()
161 governor->name, pos->type, ret); in thermal_register_governor()
177 if (!__find_governor(governor->name)) in thermal_unregister_governor()
180 list_del(&governor->governor_list); in thermal_unregister_governor()
185 if (!strncasecmp(pos->governor->name, governor->name, in thermal_unregister_governor()
195 int ret = -EINVAL; in thermal_zone_device_set_policy()
217 count += sysfs_emit_at(buf, count, "%s ", pos->name); in thermal_build_list_of_policies()
241 (*governor)->name); in thermal_register_governors()
245 pr_info("Registered thermal governor '%s'", in thermal_register_governors()
246 (*governor)->name); in thermal_register_governors()
265 if (tz->ops.change_mode) { in __thermal_zone_device_set_mode()
268 ret = tz->ops.change_mode(tz, mode); in __thermal_zone_device_set_mode()
273 tz->mode = mode; in __thermal_zone_device_set_mode()
282 dev_err(&tz->device, "Unable to get temperature, disabling!\n"); in thermal_zone_broken_disable()
284 * This function only runs for enabled thermal zones, so no need to in thermal_zone_broken_disable()
291 if (td->trip.type == THERMAL_TRIP_CRITICAL && in thermal_zone_broken_disable()
292 td->trip.temperature > THERMAL_TEMP_INVALID) { in thermal_zone_broken_disable()
293 dev_crit(&tz->device, in thermal_zone_broken_disable()
294 "Disabled thermal zone with critical trip point\n"); in thermal_zone_broken_disable()
301 * Zone update section: main control loop applied to each zone while monitoring
303 * Same update may be done on a zone by calling thermal_zone_device_update().
306 * - Non-critical trips will invoke the governor responsible for that zone;
307 * - Hot trips will produce a notification to userspace;
308 * - Critical trip point will cause a system shutdown.
316 mod_delayed_work(system_freezable_power_efficient_wq, &tz->poll_queue, delay); in thermal_zone_device_set_polling()
321 if (error == -EAGAIN) { in thermal_zone_recheck()
331 if (tz->recheck_delay_jiffies == THERMAL_RECHECK_DELAY) in thermal_zone_recheck()
332 dev_info(&tz->device, "Temperature check failed (%d)\n", error); in thermal_zone_recheck()
334 thermal_zone_device_set_polling(tz, tz->recheck_delay_jiffies); in thermal_zone_recheck()
336 tz->recheck_delay_jiffies += max(tz->recheck_delay_jiffies >> 1, 1ULL); in thermal_zone_recheck()
337 if (tz->recheck_delay_jiffies > THERMAL_MAX_RECHECK_DELAY) { in thermal_zone_recheck()
340 * Restore the original recheck delay value to allow the thermal in thermal_zone_recheck()
341 * zone to try to recover when it is reenabled by user space. in thermal_zone_recheck()
343 tz->recheck_delay_jiffies = THERMAL_RECHECK_DELAY; in thermal_zone_recheck()
349 if (tz->passive > 0 && tz->passive_delay_jiffies) in monitor_thermal_zone()
350 thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies); in monitor_thermal_zone()
351 else if (tz->polling_delay_jiffies) in monitor_thermal_zone()
352 thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); in monitor_thermal_zone()
357 if (tz->governor) in thermal_get_tz_governor()
358 return tz->governor; in thermal_get_tz_governor()
366 if (!tz->governor || !tz->governor->update_tz) in thermal_governor_update_tz()
369 tz->governor->update_tz(tz, reason); in thermal_governor_update_tz()
381 dev_emerg(&tz->device, "%s: critical temperature reached\n", tz->type); in thermal_zone_device_halt()
403 trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type); in handle_critical_trips()
405 if (trip->type == THERMAL_TRIP_CRITICAL) in handle_critical_trips()
406 tz->ops.critical(tz); in handle_critical_trips()
407 else if (tz->ops.hot) in handle_critical_trips()
408 tz->ops.hot(tz); in handle_critical_trips()
420 list_del(&td->list_node); in move_trip_to_sorted_list()
424 if (entry->threshold <= td->threshold) { in move_trip_to_sorted_list()
425 list_add(&td->list_node, &entry->list_node); in move_trip_to_sorted_list()
429 list_add(&td->list_node, list); in move_trip_to_sorted_list()
435 td->threshold = td->trip.temperature; in move_to_trips_high()
436 move_trip_to_sorted_list(td, &tz->trips_high); in move_to_trips_high()
442 td->threshold = td->trip.temperature - td->trip.hysteresis; in move_to_trips_reached()
443 move_trip_to_sorted_list(td, &tz->trips_reached); in move_to_trips_reached()
449 td->threshold = INT_MAX; in move_to_trips_invalid()
450 list_move(&td->list_node, &tz->trips_invalid); in move_to_trips_invalid()
458 if (trip->type == THERMAL_TRIP_HOT || trip->type == THERMAL_TRIP_CRITICAL) in thermal_governor_trip_crossed()
461 if (governor->trip_crossed) in thermal_governor_trip_crossed()
462 governor->trip_crossed(tz, trip, upward); in thermal_governor_trip_crossed()
470 const struct thermal_trip *trip = &td->trip; in thermal_trip_crossed()
473 if (trip->type == THERMAL_TRIP_PASSIVE) in thermal_trip_crossed()
474 tz->passive++; in thermal_trip_crossed()
475 else if (trip->type == THERMAL_TRIP_CRITICAL || in thermal_trip_crossed()
476 trip->type == THERMAL_TRIP_HOT) in thermal_trip_crossed()
482 if (trip->type == THERMAL_TRIP_PASSIVE) { in thermal_trip_crossed()
483 tz->passive--; in thermal_trip_crossed()
484 WARN_ON(tz->passive < 0); in thermal_trip_crossed()
497 WRITE_ONCE(trip->hysteresis, hyst); in thermal_zone_set_trip_hyst()
500 * If the zone temperature is above or at the trip tmperature, the trip in thermal_zone_set_trip_hyst()
505 if (tz->temperature >= td->threshold) in thermal_zone_set_trip_hyst()
513 int old_temp = trip->temperature; in thermal_zone_set_trip_temp()
518 WRITE_ONCE(trip->temperature, temp); in thermal_zone_set_trip_temp()
539 if (tz->temperature >= td->threshold) in thermal_zone_set_trip_temp()
551 if (tz->temperature >= td->threshold) in thermal_zone_set_trip_temp()
565 /* Check the trips that were below or at the zone temperature. */ in thermal_zone_handle_trips()
566 list_for_each_entry_safe_reverse(td, next, &tz->trips_reached, list_node) { in thermal_zone_handle_trips()
567 if (td->threshold <= tz->temperature) in thermal_zone_handle_trips()
575 list_move(&td->list_node, &way_down_list); in thermal_zone_handle_trips()
577 /* Check the trips that were previously above the zone temperature. */ in thermal_zone_handle_trips()
578 list_for_each_entry_safe(td, next, &tz->trips_high, list_node) { in thermal_zone_handle_trips()
579 if (td->threshold > tz->temperature) in thermal_zone_handle_trips()
589 if (!list_empty(&tz->trips_reached)) { in thermal_zone_handle_trips()
590 td = list_last_entry(&tz->trips_reached, in thermal_zone_handle_trips()
594 * the zone temperature is at that threshold and stays there, in thermal_zone_handle_trips()
597 *low = td->threshold - 1; in thermal_zone_handle_trips()
599 if (!list_empty(&tz->trips_high)) { in thermal_zone_handle_trips()
600 td = list_first_entry(&tz->trips_high, in thermal_zone_handle_trips()
602 *high = td->threshold; in thermal_zone_handle_trips()
610 int low = -INT_MAX, high = INT_MAX; in __thermal_zone_device_update()
613 if (tz->state != TZ_STATE_READY || tz->mode != THERMAL_DEVICE_ENABLED) in __thermal_zone_device_update()
623 * the zone owner does not want the core to do anything about in __thermal_zone_device_update()
624 * it. Continue regular zone polling if needed, so that this in __thermal_zone_device_update()
630 tz->recheck_delay_jiffies = THERMAL_RECHECK_DELAY; in __thermal_zone_device_update()
632 tz->last_temperature = tz->temperature; in __thermal_zone_device_update()
633 tz->temperature = temp; in __thermal_zone_device_update()
637 thermal_genl_sampling_temp(tz->id, temp); in __thermal_zone_device_update()
639 tz->notify_event = event; in __thermal_zone_device_update()
647 if (governor->manage) in __thermal_zone_device_update()
648 governor->manage(tz); in __thermal_zone_device_update()
664 if (mode == tz->mode) in thermal_zone_device_set_mode()
695 return !list_empty(&tz->node); in thermal_zone_is_present()
769 if (tz->id == id) { in thermal_zone_get_by_id()
770 get_device(&tz->device); in thermal_zone_get_by_id()
781 * Set of functions provided by the thermal core for:
782 * - cooling devices lifecycle: registration, unregistration,
784 * - thermal zone devices lifecycle: registration, unregistration,
794 list_for_each_entry(instance, &td->thermal_instances, trip_node) { in thermal_instance_add()
795 if (instance->cdev == cdev) in thermal_instance_add()
796 return -EEXIST; in thermal_instance_add()
799 list_add_tail(&new_instance->trip_node, &td->thermal_instances); in thermal_instance_add()
803 list_add_tail(&new_instance->cdev_node, &cdev->thermal_instances); in thermal_instance_add()
809 * thermal_bind_cdev_to_trip - bind a cooling device to a thermal zone
815 * This interface function bind a thermal cooling device to the certain trip
816 * point of a thermal zone device.
817 * This function is usually called in the thermal zone device .bind callback.
831 if (cool_spec->lower == THERMAL_NO_LIMIT) in thermal_bind_cdev_to_trip()
832 cool_spec->lower = 0; in thermal_bind_cdev_to_trip()
834 if (cool_spec->upper == THERMAL_NO_LIMIT) { in thermal_bind_cdev_to_trip()
835 cool_spec->upper = cdev->max_state; in thermal_bind_cdev_to_trip()
841 if (cool_spec->lower > cool_spec->upper || cool_spec->upper > cdev->max_state) in thermal_bind_cdev_to_trip()
842 return -EINVAL; in thermal_bind_cdev_to_trip()
846 return -ENOMEM; in thermal_bind_cdev_to_trip()
848 dev->cdev = cdev; in thermal_bind_cdev_to_trip()
849 dev->trip = &td->trip; in thermal_bind_cdev_to_trip()
850 dev->upper = cool_spec->upper; in thermal_bind_cdev_to_trip()
851 dev->upper_no_limit = upper_no_limit; in thermal_bind_cdev_to_trip()
852 dev->lower = cool_spec->lower; in thermal_bind_cdev_to_trip()
853 dev->target = THERMAL_NO_TARGET; in thermal_bind_cdev_to_trip()
854 dev->weight = cool_spec->weight; in thermal_bind_cdev_to_trip()
856 result = ida_alloc(&tz->ida, GFP_KERNEL); in thermal_bind_cdev_to_trip()
860 dev->id = result; in thermal_bind_cdev_to_trip()
861 sprintf(dev->name, "cdev%d", dev->id); in thermal_bind_cdev_to_trip()
863 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_bind_cdev_to_trip()
867 snprintf(dev->attr_name, sizeof(dev->attr_name), "cdev%d_trip_point", in thermal_bind_cdev_to_trip()
868 dev->id); in thermal_bind_cdev_to_trip()
869 sysfs_attr_init(&dev->attr.attr); in thermal_bind_cdev_to_trip()
870 dev->attr.attr.name = dev->attr_name; in thermal_bind_cdev_to_trip()
871 dev->attr.attr.mode = 0444; in thermal_bind_cdev_to_trip()
872 dev->attr.show = trip_point_show; in thermal_bind_cdev_to_trip()
873 result = device_create_file(&tz->device, &dev->attr); in thermal_bind_cdev_to_trip()
877 snprintf(dev->weight_attr_name, sizeof(dev->weight_attr_name), in thermal_bind_cdev_to_trip()
878 "cdev%d_weight", dev->id); in thermal_bind_cdev_to_trip()
879 sysfs_attr_init(&dev->weight_attr.attr); in thermal_bind_cdev_to_trip()
880 dev->weight_attr.attr.name = dev->weight_attr_name; in thermal_bind_cdev_to_trip()
881 dev->weight_attr.attr.mode = S_IWUSR | S_IRUGO; in thermal_bind_cdev_to_trip()
882 dev->weight_attr.show = weight_show; in thermal_bind_cdev_to_trip()
883 dev->weight_attr.store = weight_store; in thermal_bind_cdev_to_trip()
884 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_bind_cdev_to_trip()
897 device_remove_file(&tz->device, &dev->weight_attr); in thermal_bind_cdev_to_trip()
899 device_remove_file(&tz->device, &dev->attr); in thermal_bind_cdev_to_trip()
901 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_bind_cdev_to_trip()
903 ida_free(&tz->ida, dev->id); in thermal_bind_cdev_to_trip()
911 list_del(&instance->trip_node); in thermal_instance_delete()
913 guard(cooling_dev)(instance->cdev); in thermal_instance_delete()
915 list_del(&instance->cdev_node); in thermal_instance_delete()
919 * thermal_unbind_cdev_from_trip - unbind a cooling device from a thermal zone.
924 * This interface function unbind a thermal cooling device from the certain
925 * trip point of a thermal zone device.
926 * This function is usually called in the thermal zone device .unbind callback.
934 list_for_each_entry_safe(pos, next, &td->thermal_instances, trip_node) { in thermal_unbind_cdev_from_trip()
935 if (pos->cdev == cdev) { in thermal_unbind_cdev_from_trip()
946 device_remove_file(&tz->device, &pos->weight_attr); in thermal_unbind_cdev_from_trip()
947 device_remove_file(&tz->device, &pos->attr); in thermal_unbind_cdev_from_trip()
948 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_unbind_cdev_from_trip()
949 ida_free(&tz->ida, pos->id); in thermal_unbind_cdev_from_trip()
959 sizeof("thermal_zone") - 1)) { in thermal_release()
962 mutex_destroy(&tz->lock); in thermal_release()
963 complete(&tz->removal); in thermal_release()
965 sizeof("cooling_device") - 1)) { in thermal_release()
968 kfree_const(cdev->type); in thermal_release()
969 ida_free(&thermal_cdev_ida, cdev->id); in thermal_release()
981 dev_err(&tz->device, "binding cdev %s to trip %d failed: %d\n", in print_bind_err_msg()
982 cdev->type, thermal_zone_trip_id(tz, &td->trip), ret); in print_bind_err_msg()
991 if (!tz->ops.should_bind) in __thermal_zone_cdev_bind()
1002 if (!tz->ops.should_bind(tz, &td->trip, cdev, &c)) in __thermal_zone_cdev_bind()
1032 list_add(&cdev->node, &thermal_cdev_list); in thermal_cooling_device_init_complete()
1039 * __thermal_cooling_device_register() - register a new thermal cooling device
1041 * @type: the thermal cooling device type.
1043 * @ops: standard thermal cooling devices callbacks.
1045 * This interface function adds a new thermal cooling device (fan/processor/...)
1046 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1047 * to all the thermal zone devices registered at the same time.
1049 * node, so that it can be bound to a thermal zone created out of device tree.
1063 if (!ops || !ops->get_max_state || !ops->get_cur_state || in __thermal_cooling_device_register()
1064 !ops->set_cur_state) in __thermal_cooling_device_register()
1065 return ERR_PTR(-EINVAL); in __thermal_cooling_device_register()
1068 return ERR_PTR(-ENODEV); in __thermal_cooling_device_register()
1072 return ERR_PTR(-ENOMEM); in __thermal_cooling_device_register()
1077 cdev->id = ret; in __thermal_cooling_device_register()
1080 cdev->type = kstrdup_const(type ? type : "", GFP_KERNEL); in __thermal_cooling_device_register()
1081 if (!cdev->type) { in __thermal_cooling_device_register()
1082 ret = -ENOMEM; in __thermal_cooling_device_register()
1086 mutex_init(&cdev->lock); in __thermal_cooling_device_register()
1087 INIT_LIST_HEAD(&cdev->thermal_instances); in __thermal_cooling_device_register()
1088 cdev->np = np; in __thermal_cooling_device_register()
1089 cdev->ops = ops; in __thermal_cooling_device_register()
1090 cdev->updated = false; in __thermal_cooling_device_register()
1091 cdev->device.class = thermal_class; in __thermal_cooling_device_register()
1092 cdev->devdata = devdata; in __thermal_cooling_device_register()
1094 ret = cdev->ops->get_max_state(cdev, &cdev->max_state); in __thermal_cooling_device_register()
1106 ret = cdev->ops->get_cur_state(cdev, &current_state); in __thermal_cooling_device_register()
1112 ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id); in __thermal_cooling_device_register()
1116 ret = device_register(&cdev->device); in __thermal_cooling_device_register()
1119 put_device(&cdev->device); in __thermal_cooling_device_register()
1123 if (current_state <= cdev->max_state) in __thermal_cooling_device_register()
1133 kfree_const(cdev->type); in __thermal_cooling_device_register()
1142 * thermal_cooling_device_register() - register a new thermal cooling device
1143 * @type: the thermal cooling device type.
1145 * @ops: standard thermal cooling devices callbacks.
1147 * This interface function adds a new thermal cooling device (fan/processor/...)
1148 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1149 * to all the thermal zone devices registered at the same time.
1163 * thermal_of_cooling_device_register() - register an OF thermal cooling device
1165 * @type: the thermal cooling device type.
1167 * @ops: standard thermal cooling devices callbacks.
1170 * This interface function adds a new thermal cooling device (fan/processor/...)
1171 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1172 * to all the thermal zone devices registered at the same time.
1193 * devm_thermal_of_cooling_device_register() - register an OF thermal cooling
1197 * @type: the thermal cooling device type.
1199 * @ops: standard thermal cooling devices callbacks.
1202 * This interface function adds a new thermal cooling device (fan/processor/...)
1203 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1204 * to all the thermal zone devices registered at the same time.
1220 return ERR_PTR(-ENOMEM); in devm_thermal_of_cooling_device_register()
1248 * thermal_cooling_device_update - Update a cooling device object
1280 if (cdev->ops->get_max_state(cdev, &cdev->max_state)) in thermal_cooling_device_update()
1285 list_for_each_entry(ti, &cdev->thermal_instances, cdev_node) { in thermal_cooling_device_update()
1286 if (ti->upper == cdev->max_state) in thermal_cooling_device_update()
1289 if (ti->upper < cdev->max_state) { in thermal_cooling_device_update()
1290 if (ti->upper_no_limit) in thermal_cooling_device_update()
1291 ti->upper = cdev->max_state; in thermal_cooling_device_update()
1296 ti->upper = cdev->max_state; in thermal_cooling_device_update()
1297 if (ti->lower > ti->upper) in thermal_cooling_device_update()
1298 ti->lower = ti->upper; in thermal_cooling_device_update()
1300 if (ti->target == THERMAL_NO_TARGET) in thermal_cooling_device_update()
1303 if (ti->target > ti->upper) in thermal_cooling_device_update()
1304 ti->target = ti->upper; in thermal_cooling_device_update()
1307 if (cdev->ops->get_cur_state(cdev, &state) || state > cdev->max_state) in thermal_cooling_device_update()
1340 list_del(&cdev->node); in thermal_cooling_device_exit()
1349 * thermal_cooling_device_unregister() - removes a thermal cooling device
1350 * @cdev: Thermal cooling device to remove.
1360 device_unregister(&cdev->device); in thermal_cooling_device_unregister()
1367 int ret = -EINVAL; in thermal_zone_get_crit_temp()
1369 if (tz->ops.get_crit_temp) in thermal_zone_get_crit_temp()
1370 return tz->ops.get_crit_temp(tz, temp); in thermal_zone_get_crit_temp()
1375 const struct thermal_trip *trip = &td->trip; in thermal_zone_get_crit_temp()
1377 if (trip->type == THERMAL_TRIP_CRITICAL) { in thermal_zone_get_crit_temp()
1378 *temp = trip->temperature; in thermal_zone_get_crit_temp()
1400 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_init()
1402 tz->temperature = THERMAL_TEMP_INIT; in thermal_zone_device_init()
1403 tz->passive = 0; in thermal_zone_device_init()
1404 tz->prev_low_trip = -INT_MAX; in thermal_zone_device_init()
1405 tz->prev_high_trip = INT_MAX; in thermal_zone_device_init()
1409 list_for_each_entry(instance, &td->thermal_instances, trip_node) in thermal_zone_device_init()
1410 instance->initialized = false; in thermal_zone_device_init()
1414 * mitigation can be started if the zone temperature is above them. in thermal_zone_device_init()
1416 list_for_each_entry_safe(td, next, &tz->trips_invalid, list_node) { in thermal_zone_device_init()
1417 if (td->trip.temperature != THERMAL_TEMP_INVALID) in thermal_zone_device_init()
1421 list_for_each_entry_safe(td, next, &tz->trips_reached, list_node) { in thermal_zone_device_init()
1422 if (td->trip.temperature == THERMAL_TEMP_INVALID) in thermal_zone_device_init()
1435 if (tz->tzp) in thermal_zone_init_governor()
1436 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_init_governor()
1449 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_init_complete()
1453 /* Bind cooling devices for this zone. */ in thermal_zone_init_complete()
1457 tz->state &= ~TZ_STATE_FLAG_INIT; in thermal_zone_init_complete()
1460 * new thermal zone needs to be marked as suspended because in thermal_zone_init_complete()
1464 tz->state |= TZ_STATE_FLAG_SUSPENDED; in thermal_zone_init_complete()
1470 * thermal_zone_device_register_with_trips() - register a new thermal zone device
1471 * @type: the thermal zone device type
1472 * @trips: a pointer to an array of thermal trips
1473 * @num_trips: the number of trip points the thermal zone support
1475 * @ops: standard thermal zone device callbacks
1476 * @tzp: thermal zone platform parameters
1483 * This interface function adds a new thermal zone device (sensor) to
1484 * /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the
1485 * thermal cooling devices registered at the same time.
1509 pr_err("No thermal zone type defined\n"); in thermal_zone_device_register_with_trips()
1510 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1514 pr_err("Thermal zone name (%s) too long, should be under %d chars\n", in thermal_zone_device_register_with_trips()
1516 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1520 pr_err("Incorrect number of thermal trips\n"); in thermal_zone_device_register_with_trips()
1521 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1524 if (!ops || !ops->get_temp) { in thermal_zone_device_register_with_trips()
1525 pr_err("Thermal zone device ops not defined or invalid\n"); in thermal_zone_device_register_with_trips()
1526 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1530 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1533 return ERR_PTR(-EINVAL); in thermal_zone_device_register_with_trips()
1536 return ERR_PTR(-ENODEV); in thermal_zone_device_register_with_trips()
1540 return ERR_PTR(-ENOMEM); in thermal_zone_device_register_with_trips()
1543 tz->tzp = kmemdup(tzp, sizeof(*tzp), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1544 if (!tz->tzp) { in thermal_zone_device_register_with_trips()
1545 result = -ENOMEM; in thermal_zone_device_register_with_trips()
1550 INIT_LIST_HEAD(&tz->node); in thermal_zone_device_register_with_trips()
1551 INIT_LIST_HEAD(&tz->trips_high); in thermal_zone_device_register_with_trips()
1552 INIT_LIST_HEAD(&tz->trips_reached); in thermal_zone_device_register_with_trips()
1553 INIT_LIST_HEAD(&tz->trips_invalid); in thermal_zone_device_register_with_trips()
1554 ida_init(&tz->ida); in thermal_zone_device_register_with_trips()
1555 mutex_init(&tz->lock); in thermal_zone_device_register_with_trips()
1556 init_completion(&tz->removal); in thermal_zone_device_register_with_trips()
1557 init_completion(&tz->resume); in thermal_zone_device_register_with_trips()
1564 tz->id = id; in thermal_zone_device_register_with_trips()
1565 strscpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register_with_trips()
1567 tz->ops = *ops; in thermal_zone_device_register_with_trips()
1568 if (!tz->ops.critical) in thermal_zone_device_register_with_trips()
1569 tz->ops.critical = thermal_zone_device_critical; in thermal_zone_device_register_with_trips()
1571 tz->device.class = thermal_class; in thermal_zone_device_register_with_trips()
1572 tz->devdata = devdata; in thermal_zone_device_register_with_trips()
1573 tz->num_trips = num_trips; in thermal_zone_device_register_with_trips()
1575 td->trip = *trip++; in thermal_zone_device_register_with_trips()
1576 INIT_LIST_HEAD(&td->thermal_instances); in thermal_zone_device_register_with_trips()
1577 INIT_LIST_HEAD(&td->list_node); in thermal_zone_device_register_with_trips()
1586 tz->polling_delay_jiffies = msecs_to_jiffies(polling_delay); in thermal_zone_device_register_with_trips()
1587 tz->passive_delay_jiffies = msecs_to_jiffies(passive_delay); in thermal_zone_device_register_with_trips()
1588 tz->recheck_delay_jiffies = THERMAL_RECHECK_DELAY; in thermal_zone_device_register_with_trips()
1590 tz->state = TZ_STATE_FLAG_INIT; in thermal_zone_device_register_with_trips()
1598 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register_with_trips()
1604 result = device_register(&tz->device); in thermal_zone_device_register_with_trips()
1612 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register_with_trips()
1633 device_del(&tz->device); in thermal_zone_device_register_with_trips()
1635 put_device(&tz->device); in thermal_zone_device_register_with_trips()
1639 kfree(tz->tzp); in thermal_zone_device_register_with_trips()
1659 return tzd->devdata; in thermal_zone_device_priv()
1665 return tzd->type; in thermal_zone_device_type()
1671 return tzd->id; in thermal_zone_device_id()
1677 return &tzd->device; in thermal_zone_device()
1687 if (list_empty(&tz->node)) in thermal_zone_exit()
1692 tz->state |= TZ_STATE_FLAG_EXIT; in thermal_zone_exit()
1693 list_del_init(&tz->node); in thermal_zone_exit()
1695 /* Unbind all cdevs associated with this thermal zone. */ in thermal_zone_exit()
1703 * thermal_zone_device_unregister - removes the registered thermal zone device
1704 * @tz: the thermal zone device to remove
1716 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1722 ida_free(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1723 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1725 device_del(&tz->device); in thermal_zone_device_unregister()
1726 put_device(&tz->device); in thermal_zone_device_unregister()
1730 wait_for_completion(&tz->removal); in thermal_zone_device_unregister()
1731 kfree(tz->tzp); in thermal_zone_device_unregister()
1737 * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
1738 * @name: thermal zone name to fetch the temperature
1740 * When only one zone is found with the passed name, returns a reference to it.
1742 * Return: On success returns a reference to an unique thermal zone with
1743 * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
1744 * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
1748 struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL); in thermal_zone_get_zone_by_name()
1752 return ERR_PTR(-EINVAL); in thermal_zone_get_zone_by_name()
1757 if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { in thermal_zone_get_zone_by_name()
1763 return ERR_PTR(-ENODEV); in thermal_zone_get_zone_by_name()
1765 /* Success only when one zone is found. */ in thermal_zone_get_zone_by_name()
1767 return ERR_PTR(-EEXIST); in thermal_zone_get_zone_by_name()
1781 tz->state &= ~(TZ_STATE_FLAG_SUSPENDED | TZ_STATE_FLAG_RESUMING); in thermal_zone_device_resume()
1788 complete(&tz->resume); in thermal_zone_device_resume()
1795 if (tz->state & TZ_STATE_FLAG_RESUMING) { in thermal_zone_pm_prepare()
1797 * thermal_zone_device_resume() queued up for this zone has not in thermal_zone_pm_prepare()
1802 wait_for_completion(&tz->resume); in thermal_zone_pm_prepare()
1806 tz->state |= TZ_STATE_FLAG_SUSPENDED; in thermal_zone_pm_prepare()
1825 cancel_delayed_work(&tz->poll_queue); in thermal_zone_pm_complete()
1827 reinit_completion(&tz->resume); in thermal_zone_pm_complete()
1828 tz->state |= TZ_STATE_FLAG_RESUMING; in thermal_zone_pm_complete()
1834 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_resume); in thermal_zone_pm_complete()
1836 mod_delayed_work(system_freezable_power_efficient_wq, &tz->poll_queue, 0); in thermal_zone_pm_complete()
1874 * Run at the lowest priority to avoid interference between the thermal
1875 * zone resume work items spawned by thermal_pm_notify() and the other
1897 result = -ENOMEM; in thermal_init()
1901 thermal_class->name = "thermal"; in thermal_init()
1902 thermal_class->dev_release = thermal_release; in thermal_init()
1913 pr_warn("Thermal: Can not register suspend notifier, return %d\n", in thermal_init()