Lines Matching +full:- +full:- +full:valid +full:- +full:-
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $)
60 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
61 * when re-evaluating the AML code.
63 * We need to re-bind the cooling devices of a thermal zone when this occurs.
68 acpi_handle_info(tz->device->handle, \
70 "Please report to linux-acpi@vger.kernel.org\n", str); \
97 bool valid; member
137 /* --------------------------------------------------------------------------
139 -------------------------------------------------------------------------- */
147 return -EINVAL; in acpi_thermal_get_temperature()
149 tz->last_temperature = tz->temperature; in acpi_thermal_get_temperature()
151 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); in acpi_thermal_get_temperature()
153 return -ENODEV; in acpi_thermal_get_temperature()
155 tz->temperature = tmp; in acpi_thermal_get_temperature()
157 acpi_handle_debug(tz->device->handle, "Temperature is %lu dK\n", in acpi_thermal_get_temperature()
158 tz->temperature); in acpi_thermal_get_temperature()
169 return -EINVAL; in acpi_thermal_get_polling_frequency()
171 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp); in acpi_thermal_get_polling_frequency()
173 return -ENODEV; in acpi_thermal_get_polling_frequency()
175 tz->polling_frequency = tmp; in acpi_thermal_get_polling_frequency()
176 acpi_handle_debug(tz->device->handle, "Polling frequency is %lu dS\n", in acpi_thermal_get_polling_frequency()
177 tz->polling_frequency); in acpi_thermal_get_polling_frequency()
188 tz->kelvin_offset); in acpi_thermal_temp()
196 bool valid = false; in __acpi_thermal_trips_update() local
201 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); in __acpi_thermal_trips_update()
202 tz->trips.critical.temperature = tmp; in __acpi_thermal_trips_update()
210 tz->trips.critical.valid = false; in __acpi_thermal_trips_update()
211 acpi_handle_debug(tz->device->handle, in __acpi_thermal_trips_update()
215 tz->trips.critical.valid = false; in __acpi_thermal_trips_update()
217 tz->trips.critical.valid = true; in __acpi_thermal_trips_update()
218 acpi_handle_debug(tz->device->handle, in __acpi_thermal_trips_update()
220 tz->trips.critical.temperature); in __acpi_thermal_trips_update()
222 if (tz->trips.critical.valid) { in __acpi_thermal_trips_update()
223 if (crt == -1) { in __acpi_thermal_trips_update()
224 tz->trips.critical.valid = false; in __acpi_thermal_trips_update()
231 if (crt_k > tz->trips.critical.temperature) in __acpi_thermal_trips_update()
234 tz->trips.critical.temperature = crt_k; in __acpi_thermal_trips_update()
241 status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); in __acpi_thermal_trips_update()
243 tz->trips.hot.valid = false; in __acpi_thermal_trips_update()
244 acpi_handle_debug(tz->device->handle, in __acpi_thermal_trips_update()
247 tz->trips.hot.temperature = tmp; in __acpi_thermal_trips_update()
248 tz->trips.hot.valid = true; in __acpi_thermal_trips_update()
249 acpi_handle_debug(tz->device->handle, in __acpi_thermal_trips_update()
251 tz->trips.hot.temperature); in __acpi_thermal_trips_update()
256 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.trip.valid) || in __acpi_thermal_trips_update()
258 valid = tz->trips.passive.trip.valid; in __acpi_thermal_trips_update()
259 if (psv == -1) { in __acpi_thermal_trips_update()
265 status = acpi_evaluate_integer(tz->device->handle, in __acpi_thermal_trips_update()
270 tz->trips.passive.trip.valid = false; in __acpi_thermal_trips_update()
272 tz->trips.passive.trip.temperature = tmp; in __acpi_thermal_trips_update()
273 tz->trips.passive.trip.valid = true; in __acpi_thermal_trips_update()
275 status = acpi_evaluate_integer(tz->device->handle, in __acpi_thermal_trips_update()
278 tz->trips.passive.trip.valid = false; in __acpi_thermal_trips_update()
280 tz->trips.passive.tc1 = tmp; in __acpi_thermal_trips_update()
282 status = acpi_evaluate_integer(tz->device->handle, in __acpi_thermal_trips_update()
285 tz->trips.passive.trip.valid = false; in __acpi_thermal_trips_update()
287 tz->trips.passive.tc2 = tmp; in __acpi_thermal_trips_update()
289 status = acpi_evaluate_integer(tz->device->handle, in __acpi_thermal_trips_update()
292 tz->trips.passive.trip.valid = false; in __acpi_thermal_trips_update()
294 tz->trips.passive.tsp = tmp; in __acpi_thermal_trips_update()
298 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.trip.valid) { in __acpi_thermal_trips_update()
300 status = acpi_evaluate_reference(tz->device->handle, "_PSL", in __acpi_thermal_trips_update()
303 acpi_handle_info(tz->device->handle, in __acpi_thermal_trips_update()
305 tz->trips.passive.trip.valid = false; in __acpi_thermal_trips_update()
307 tz->trips.passive.trip.valid = true; in __acpi_thermal_trips_update()
310 if (memcmp(&tz->trips.passive.devices, &devices, in __acpi_thermal_trips_update()
312 memcpy(&tz->trips.passive.devices, &devices, in __acpi_thermal_trips_update()
318 if (valid != tz->trips.passive.trip.valid) in __acpi_thermal_trips_update()
325 valid = tz->trips.active[i].trip.valid; in __acpi_thermal_trips_update()
327 if (act == -1) in __acpi_thermal_trips_update()
331 tz->trips.active[i].trip.valid)) { in __acpi_thermal_trips_update()
332 status = acpi_evaluate_integer(tz->device->handle, in __acpi_thermal_trips_update()
335 tz->trips.active[i].trip.valid = false; in __acpi_thermal_trips_update()
343 tz->trips.active[0].trip.temperature = in __acpi_thermal_trips_update()
350 tz->trips.active[i-1].trip.temperature = in __acpi_thermal_trips_update()
352 tz->trips.active[i-2].trip.temperature, in __acpi_thermal_trips_update()
357 tz->trips.active[i].trip.temperature = tmp; in __acpi_thermal_trips_update()
358 tz->trips.active[i].trip.valid = true; in __acpi_thermal_trips_update()
363 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].trip.valid) { in __acpi_thermal_trips_update()
365 status = acpi_evaluate_reference(tz->device->handle, in __acpi_thermal_trips_update()
368 acpi_handle_info(tz->device->handle, in __acpi_thermal_trips_update()
370 tz->trips.active[i].trip.valid = false; in __acpi_thermal_trips_update()
372 tz->trips.active[i].trip.valid = true; in __acpi_thermal_trips_update()
375 if (memcmp(&tz->trips.active[i].devices, &devices, in __acpi_thermal_trips_update()
377 memcpy(&tz->trips.active[i].devices, &devices, in __acpi_thermal_trips_update()
383 if (valid != tz->trips.active[i].trip.valid) in __acpi_thermal_trips_update()
386 if (!tz->trips.active[i].trip.valid) in __acpi_thermal_trips_update()
392 status = acpi_evaluate_reference(tz->device->handle, "_TZD", in __acpi_thermal_trips_update()
395 memcmp(&tz->devices, &devices, sizeof(devices))) { in __acpi_thermal_trips_update()
396 tz->devices = devices; in __acpi_thermal_trips_update()
404 struct acpi_thermal_trip *acpi_trip = trip->priv; in acpi_thermal_adjust_trip()
410 if (acpi_trip->valid) in acpi_thermal_adjust_trip()
411 trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); in acpi_thermal_adjust_trip()
413 trip->temperature = THERMAL_TEMP_INVALID; in acpi_thermal_adjust_trip()
427 for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz); in acpi_thermal_adjust_thermal_zone()
432 if (!work_pending(&tz->thermal_check_work)) in acpi_queue_thermal_check()
433 queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work); in acpi_queue_thermal_check()
438 struct acpi_device *adev = tz->device; in acpi_thermal_trips_update()
447 thermal_zone_device_exec(tz->thermal_zone, in acpi_thermal_trips_update()
450 acpi_bus_generate_netlink_event(adev->pnp.device_class, in acpi_thermal_trips_update()
451 dev_name(&adev->dev), event, 0); in acpi_thermal_trips_update()
456 bool valid; in acpi_thermal_get_trip_points() local
461 valid = tz->trips.critical.valid | in acpi_thermal_get_trip_points()
462 tz->trips.hot.valid | in acpi_thermal_get_trip_points()
463 tz->trips.passive.trip.valid; in acpi_thermal_get_trip_points()
466 valid = valid || tz->trips.active[i].trip.valid; in acpi_thermal_get_trip_points()
468 if (!valid) { in acpi_thermal_get_trip_points()
469 pr_warn(FW_BUG "No valid trip found\n"); in acpi_thermal_get_trip_points()
470 return -ENODEV; in acpi_thermal_get_trip_points()
483 return -EINVAL; in thermal_get_temp()
489 *temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature, in thermal_get_temp()
490 tz->kelvin_offset); in thermal_get_temp()
503 return -EINVAL; in thermal_get_trend()
505 acpi_trip = trip->priv; in thermal_get_trend()
506 if (!acpi_trip || !acpi_trip->valid) in thermal_get_trend()
507 return -EINVAL; in thermal_get_trend()
509 switch (trip->type) { in thermal_get_trend()
511 t = tz->trips.passive.tc1 * (tz->temperature - in thermal_get_trend()
512 tz->last_temperature) + in thermal_get_trend()
513 tz->trips.passive.tc2 * (tz->temperature - in thermal_get_trend()
514 acpi_trip->temperature); in thermal_get_trend()
525 t = acpi_thermal_temp(tz, tz->temperature); in thermal_get_trend()
526 if (t <= trip->temperature) in thermal_get_trend()
537 return -EINVAL; in thermal_get_trend()
544 acpi_bus_generate_netlink_event(tz->device->pnp.device_class, in acpi_thermal_zone_device_hot()
545 dev_name(&tz->device->dev), in acpi_thermal_zone_device_hot()
553 acpi_bus_generate_netlink_event(tz->device->pnp.device_class, in acpi_thermal_zone_device_critical()
554 dev_name(&tz->device->dev), in acpi_thermal_zone_device_critical()
564 struct acpi_device *device = cdev->devdata; in acpi_thermal_cooling_device_cb()
570 int trip = -1; in acpi_thermal_cooling_device_cb()
573 if (tz->trips.critical.valid) in acpi_thermal_cooling_device_cb()
576 if (tz->trips.hot.valid) in acpi_thermal_cooling_device_cb()
579 if (tz->trips.passive.trip.valid) { in acpi_thermal_cooling_device_cb()
581 for (i = 0; i < tz->trips.passive.devices.count; i++) { in acpi_thermal_cooling_device_cb()
582 handle = tz->trips.passive.devices.handles[i]; in acpi_thermal_cooling_device_cb()
604 if (!tz->trips.active[i].trip.valid) in acpi_thermal_cooling_device_cb()
608 for (j = 0; j < tz->trips.active[i].devices.count; j++) { in acpi_thermal_cooling_device_cb()
609 handle = tz->trips.active[i].devices.handles[j]; in acpi_thermal_cooling_device_cb()
658 struct device *tzdev = thermal_zone_device(tz->thermal_zone); in acpi_thermal_zone_sysfs_add()
661 ret = sysfs_create_link(&tz->device->dev.kobj, in acpi_thermal_zone_sysfs_add()
662 &tzdev->kobj, "thermal_zone"); in acpi_thermal_zone_sysfs_add()
666 ret = sysfs_create_link(&tzdev->kobj, in acpi_thermal_zone_sysfs_add()
667 &tz->device->dev.kobj, "device"); in acpi_thermal_zone_sysfs_add()
669 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); in acpi_thermal_zone_sysfs_add()
676 struct device *tzdev = thermal_zone_device(tz->thermal_zone); in acpi_thermal_zone_sysfs_remove()
678 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); in acpi_thermal_zone_sysfs_remove()
679 sysfs_remove_link(&tzdev->kobj, "device"); in acpi_thermal_zone_sysfs_remove()
691 if (tz->trips.critical.valid) in acpi_thermal_register_thermal_zone()
694 if (tz->trips.hot.valid) in acpi_thermal_register_thermal_zone()
697 if (tz->trips.passive.trip.valid) { in acpi_thermal_register_thermal_zone()
699 passive_delay = tz->trips.passive.tsp * 100; in acpi_thermal_register_thermal_zone()
702 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++) in acpi_thermal_register_thermal_zone()
707 return -ENOMEM; in acpi_thermal_register_thermal_zone()
709 tz->trip_table = trip; in acpi_thermal_register_thermal_zone()
711 if (tz->trips.critical.valid) { in acpi_thermal_register_thermal_zone()
712 trip->type = THERMAL_TRIP_CRITICAL; in acpi_thermal_register_thermal_zone()
713 trip->temperature = acpi_thermal_temp(tz, tz->trips.critical.temperature); in acpi_thermal_register_thermal_zone()
717 if (tz->trips.hot.valid) { in acpi_thermal_register_thermal_zone()
718 trip->type = THERMAL_TRIP_HOT; in acpi_thermal_register_thermal_zone()
719 trip->temperature = acpi_thermal_temp(tz, tz->trips.hot.temperature); in acpi_thermal_register_thermal_zone()
723 acpi_trip = &tz->trips.passive.trip; in acpi_thermal_register_thermal_zone()
724 if (acpi_trip->valid) { in acpi_thermal_register_thermal_zone()
725 trip->type = THERMAL_TRIP_PASSIVE; in acpi_thermal_register_thermal_zone()
726 trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); in acpi_thermal_register_thermal_zone()
727 trip->priv = acpi_trip; in acpi_thermal_register_thermal_zone()
732 acpi_trip = &tz->trips.active[i].trip; in acpi_thermal_register_thermal_zone()
734 if (!acpi_trip->valid) in acpi_thermal_register_thermal_zone()
737 trip->type = THERMAL_TRIP_ACTIVE; in acpi_thermal_register_thermal_zone()
738 trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); in acpi_thermal_register_thermal_zone()
739 trip->priv = acpi_trip; in acpi_thermal_register_thermal_zone()
743 tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz", in acpi_thermal_register_thermal_zone()
744 tz->trip_table, in acpi_thermal_register_thermal_zone()
750 tz->polling_frequency * 100); in acpi_thermal_register_thermal_zone()
751 if (IS_ERR(tz->thermal_zone)) { in acpi_thermal_register_thermal_zone()
752 result = PTR_ERR(tz->thermal_zone); in acpi_thermal_register_thermal_zone()
760 result = thermal_zone_device_enable(tz->thermal_zone); in acpi_thermal_register_thermal_zone()
764 dev_info(&tz->device->dev, "registered as thermal_zone%d\n", in acpi_thermal_register_thermal_zone()
765 thermal_zone_device_id(tz->thermal_zone)); in acpi_thermal_register_thermal_zone()
772 thermal_zone_device_unregister(tz->thermal_zone); in acpi_thermal_register_thermal_zone()
774 kfree(tz->trip_table); in acpi_thermal_register_thermal_zone()
781 thermal_zone_device_disable(tz->thermal_zone); in acpi_thermal_unregister_thermal_zone()
783 thermal_zone_device_unregister(tz->thermal_zone); in acpi_thermal_unregister_thermal_zone()
784 tz->thermal_zone = NULL; in acpi_thermal_unregister_thermal_zone()
788 /* --------------------------------------------------------------------------
790 -------------------------------------------------------------------------- */
809 acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", in acpi_thermal_notify()
818 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
829 acpi_handle handle = tz->device->handle; in acpi_thermal_aml_dependency_fix()
852 return -EINVAL; in acpi_thermal_get_info()
867 acpi_execute_simple_method(tz->device->handle, "_SCP", in acpi_thermal_get_info()
872 tz->polling_frequency = tzp; in acpi_thermal_get_info()
891 if (tz->trips.critical.valid && in acpi_thermal_guess_offset()
892 (tz->trips.critical.temperature % 5) == 1) in acpi_thermal_guess_offset()
893 tz->kelvin_offset = 273100; in acpi_thermal_guess_offset()
895 tz->kelvin_offset = 273200; in acpi_thermal_guess_offset()
911 if (!refcount_dec_not_one(&tz->thermal_check_count)) in acpi_thermal_check_fn()
914 mutex_lock(&tz->thermal_check_lock); in acpi_thermal_check_fn()
916 thermal_zone_device_update(tz->thermal_zone, THERMAL_EVENT_UNSPECIFIED); in acpi_thermal_check_fn()
918 refcount_inc(&tz->thermal_check_count); in acpi_thermal_check_fn()
920 mutex_unlock(&tz->thermal_check_lock); in acpi_thermal_check_fn()
929 return -EINVAL; in acpi_thermal_add()
933 return -ENOMEM; in acpi_thermal_add()
935 tz->device = device; in acpi_thermal_add()
936 strcpy(tz->name, device->pnp.bus_id); in acpi_thermal_add()
939 device->driver_data = tz; in acpi_thermal_add()
951 refcount_set(&tz->thermal_check_count, 3); in acpi_thermal_add()
952 mutex_init(&tz->thermal_check_lock); in acpi_thermal_add()
953 INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn); in acpi_thermal_add()
956 acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature)); in acpi_thermal_add()
988 kfree(tz->trip_table); in acpi_thermal_remove()
1006 return -EINVAL; in acpi_thermal_resume()
1010 return -EINVAL; in acpi_thermal_resume()
1013 if (!tz->trips.active[i].trip.valid) in acpi_thermal_resume()
1016 for (j = 0; j < tz->trips.active[i].devices.count; j++) { in acpi_thermal_resume()
1017 acpi_bus_update_power(tz->trips.active[i].devices.handles[j], in acpi_thermal_resume()
1052 d->ident); in thermal_act()
1053 act = -1; in thermal_act()
1059 d->ident); in thermal_nocrt()
1060 crt = -1; in thermal_nocrt()
1066 d->ident); in thermal_tzp()
1074 d->ident); in thermal_psv()
1075 psv = -1; in thermal_psv()
1087 .ident = "AOpen i915GMm-HFS",
1090 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1095 .ident = "AOpen i915GMm-HFS",
1098 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1103 .ident = "AOpen i915GMm-HFS",
1106 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1111 .ident = "Gigabyte GA-7ZX",
1128 return -ENODEV; in acpi_thermal_init()
1134 return -ENODEV; in acpi_thermal_init()
1139 return -ENODEV; in acpi_thermal_init()