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 $)
117 u8 valid:1; member
178 /* --------------------------------------------------------------------------
180 -------------------------------------------------------------------------- */
188 return -EINVAL; in acpi_thermal_get_temperature()
190 tz->last_temperature = tz->temperature; in acpi_thermal_get_temperature()
192 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); in acpi_thermal_get_temperature()
194 return -ENODEV; in acpi_thermal_get_temperature()
196 tz->temperature = tmp; in acpi_thermal_get_temperature()
198 acpi_handle_debug(tz->device->handle, "Temperature is %lu dK\n", in acpi_thermal_get_temperature()
199 tz->temperature); in acpi_thermal_get_temperature()
210 return -EINVAL; in acpi_thermal_get_polling_frequency()
212 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp); in acpi_thermal_get_polling_frequency()
214 return -ENODEV; in acpi_thermal_get_polling_frequency()
216 tz->polling_frequency = tmp; in acpi_thermal_get_polling_frequency()
217 acpi_handle_debug(tz->device->handle, "Polling frequency is %lu dS\n", in acpi_thermal_get_polling_frequency()
218 tz->polling_frequency); in acpi_thermal_get_polling_frequency()
226 return -EINVAL; in acpi_thermal_set_cooling_mode()
228 if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle, in acpi_thermal_set_cooling_mode()
230 return -ENODEV; in acpi_thermal_set_cooling_mode()
250 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
251 * when re-evaluating the AML code.
253 * We need to re-bind the cooling devices of a thermal zone when this occurs.
258 acpi_handle_info(tz->device->handle, \
260 "Please report to linux-acpi@vger.kernel.org\n", str); \
268 int valid = 0; in acpi_thermal_trips_update() local
273 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); in acpi_thermal_trips_update()
274 tz->trips.critical.temperature = tmp; in acpi_thermal_trips_update()
282 tz->trips.critical.flags.valid = 0; in acpi_thermal_trips_update()
283 acpi_handle_debug(tz->device->handle, in acpi_thermal_trips_update()
287 tz->trips.critical.flags.valid = 0; in acpi_thermal_trips_update()
289 tz->trips.critical.flags.valid = 1; in acpi_thermal_trips_update()
290 acpi_handle_debug(tz->device->handle, in acpi_thermal_trips_update()
292 tz->trips.critical.temperature); in acpi_thermal_trips_update()
294 if (tz->trips.critical.flags.valid == 1) { in acpi_thermal_trips_update()
295 if (crt == -1) { in acpi_thermal_trips_update()
296 tz->trips.critical.flags.valid = 0; in acpi_thermal_trips_update()
303 if (crt_k > tz->trips.critical.temperature) in acpi_thermal_trips_update()
306 tz->trips.critical.temperature = crt_k; in acpi_thermal_trips_update()
313 status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); in acpi_thermal_trips_update()
315 tz->trips.hot.flags.valid = 0; in acpi_thermal_trips_update()
316 acpi_handle_debug(tz->device->handle, in acpi_thermal_trips_update()
319 tz->trips.hot.temperature = tmp; in acpi_thermal_trips_update()
320 tz->trips.hot.flags.valid = 1; in acpi_thermal_trips_update()
321 acpi_handle_debug(tz->device->handle, in acpi_thermal_trips_update()
323 tz->trips.hot.temperature); in acpi_thermal_trips_update()
328 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || in acpi_thermal_trips_update()
330 valid = tz->trips.passive.flags.valid; in acpi_thermal_trips_update()
331 if (psv == -1) { in acpi_thermal_trips_update()
337 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
342 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
344 tz->trips.passive.temperature = tmp; in acpi_thermal_trips_update()
345 tz->trips.passive.flags.valid = 1; in acpi_thermal_trips_update()
347 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
350 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
352 tz->trips.passive.tc1 = tmp; in acpi_thermal_trips_update()
354 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
357 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
359 tz->trips.passive.tc2 = tmp; in acpi_thermal_trips_update()
361 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
364 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
366 tz->trips.passive.tsp = tmp; in acpi_thermal_trips_update()
370 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { in acpi_thermal_trips_update()
372 status = acpi_evaluate_reference(tz->device->handle, "_PSL", in acpi_thermal_trips_update()
375 acpi_handle_info(tz->device->handle, in acpi_thermal_trips_update()
377 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
379 tz->trips.passive.flags.valid = 1; in acpi_thermal_trips_update()
382 if (memcmp(&tz->trips.passive.devices, &devices, in acpi_thermal_trips_update()
384 memcpy(&tz->trips.passive.devices, &devices, in acpi_thermal_trips_update()
390 if (valid != tz->trips.passive.flags.valid) in acpi_thermal_trips_update()
397 valid = tz->trips.active[i].flags.valid; in acpi_thermal_trips_update()
399 if (act == -1) in acpi_thermal_trips_update()
403 tz->trips.active[i].flags.valid)) { in acpi_thermal_trips_update()
404 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
407 tz->trips.active[i].flags.valid = 0; in acpi_thermal_trips_update()
415 tz->trips.active[0].temperature = celsius_to_deci_kelvin(act); in acpi_thermal_trips_update()
421 tz->trips.active[i-1].temperature = in acpi_thermal_trips_update()
422 (tz->trips.active[i-2].temperature < in acpi_thermal_trips_update()
424 tz->trips.active[i-2].temperature : in acpi_thermal_trips_update()
429 tz->trips.active[i].temperature = tmp; in acpi_thermal_trips_update()
430 tz->trips.active[i].flags.valid = 1; in acpi_thermal_trips_update()
435 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid) { in acpi_thermal_trips_update()
437 status = acpi_evaluate_reference(tz->device->handle, in acpi_thermal_trips_update()
440 acpi_handle_info(tz->device->handle, in acpi_thermal_trips_update()
442 tz->trips.active[i].flags.valid = 0; in acpi_thermal_trips_update()
444 tz->trips.active[i].flags.valid = 1; in acpi_thermal_trips_update()
447 if (memcmp(&tz->trips.active[i].devices, &devices, in acpi_thermal_trips_update()
449 memcpy(&tz->trips.active[i].devices, &devices, in acpi_thermal_trips_update()
455 if (valid != tz->trips.active[i].flags.valid) in acpi_thermal_trips_update()
458 if (!tz->trips.active[i].flags.valid) in acpi_thermal_trips_update()
464 status = acpi_evaluate_reference(tz->device->handle, "_TZD", in acpi_thermal_trips_update()
467 memcmp(&tz->devices, &devices, sizeof(devices))) { in acpi_thermal_trips_update()
468 tz->devices = devices; in acpi_thermal_trips_update()
478 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); in acpi_thermal_get_trip_points() local
483 valid = tz->trips.critical.flags.valid | in acpi_thermal_get_trip_points()
484 tz->trips.hot.flags.valid | in acpi_thermal_get_trip_points()
485 tz->trips.passive.flags.valid; in acpi_thermal_get_trip_points()
488 valid |= tz->trips.active[i].flags.valid; in acpi_thermal_get_trip_points()
490 if (!valid) { in acpi_thermal_get_trip_points()
491 pr_warn(FW_BUG "No valid trip found\n"); in acpi_thermal_get_trip_points()
492 return -ENODEV; in acpi_thermal_get_trip_points()
501 struct acpi_thermal *tz = thermal->devdata; in thermal_get_temp()
505 return -EINVAL; in thermal_get_temp()
511 *temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature, in thermal_get_temp()
512 tz->kelvin_offset); in thermal_get_temp()
519 struct acpi_thermal *tz = thermal->devdata; in thermal_get_trip_type()
523 return -EINVAL; in thermal_get_trip_type()
525 if (tz->trips.critical.flags.valid) { in thermal_get_trip_type()
530 trip--; in thermal_get_trip_type()
533 if (tz->trips.hot.flags.valid) { in thermal_get_trip_type()
538 trip--; in thermal_get_trip_type()
541 if (tz->trips.passive.flags.valid) { in thermal_get_trip_type()
546 trip--; in thermal_get_trip_type()
549 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].flags.valid; i++) { in thermal_get_trip_type()
554 trip--; in thermal_get_trip_type()
557 return -EINVAL; in thermal_get_trip_type()
563 struct acpi_thermal *tz = thermal->devdata; in thermal_get_trip_temp()
567 return -EINVAL; in thermal_get_trip_temp()
569 if (tz->trips.critical.flags.valid) { in thermal_get_trip_temp()
572 tz->trips.critical.temperature, in thermal_get_trip_temp()
573 tz->kelvin_offset); in thermal_get_trip_temp()
576 trip--; in thermal_get_trip_temp()
579 if (tz->trips.hot.flags.valid) { in thermal_get_trip_temp()
582 tz->trips.hot.temperature, in thermal_get_trip_temp()
583 tz->kelvin_offset); in thermal_get_trip_temp()
586 trip--; in thermal_get_trip_temp()
589 if (tz->trips.passive.flags.valid) { in thermal_get_trip_temp()
592 tz->trips.passive.temperature, in thermal_get_trip_temp()
593 tz->kelvin_offset); in thermal_get_trip_temp()
596 trip--; in thermal_get_trip_temp()
600 tz->trips.active[i].flags.valid; i++) { in thermal_get_trip_temp()
603 tz->trips.active[i].temperature, in thermal_get_trip_temp()
604 tz->kelvin_offset); in thermal_get_trip_temp()
607 trip--; in thermal_get_trip_temp()
610 return -EINVAL; in thermal_get_trip_temp()
616 struct acpi_thermal *tz = thermal->devdata; in thermal_get_crit_temp()
618 if (tz->trips.critical.flags.valid) { in thermal_get_crit_temp()
620 tz->trips.critical.temperature, in thermal_get_crit_temp()
621 tz->kelvin_offset); in thermal_get_crit_temp()
625 return -EINVAL; in thermal_get_crit_temp()
631 struct acpi_thermal *tz = thermal->devdata; in thermal_get_trend()
636 return -EINVAL; in thermal_get_trend()
641 tz->temperature, tz->kelvin_offset); in thermal_get_trend()
643 return -EINVAL; in thermal_get_trend()
650 return -EINVAL; in thermal_get_trend()
655 * tz->temperature has already been updated by generic thermal layer, in thermal_get_trend()
658 i = tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature) + in thermal_get_trend()
659 tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.temperature); in thermal_get_trend()
673 struct acpi_thermal *tz = thermal->devdata; in acpi_thermal_zone_device_hot()
675 acpi_bus_generate_netlink_event(tz->device->pnp.device_class, in acpi_thermal_zone_device_hot()
676 dev_name(&tz->device->dev), in acpi_thermal_zone_device_hot()
682 struct acpi_thermal *tz = thermal->devdata; in acpi_thermal_zone_device_critical()
684 acpi_bus_generate_netlink_event(tz->device->pnp.device_class, in acpi_thermal_zone_device_critical()
685 dev_name(&tz->device->dev), in acpi_thermal_zone_device_critical()
695 struct acpi_device *device = cdev->devdata; in acpi_thermal_cooling_device_cb()
696 struct acpi_thermal *tz = thermal->devdata; in acpi_thermal_cooling_device_cb()
701 int trip = -1; in acpi_thermal_cooling_device_cb()
704 if (tz->trips.critical.flags.valid) in acpi_thermal_cooling_device_cb()
707 if (tz->trips.hot.flags.valid) in acpi_thermal_cooling_device_cb()
710 if (tz->trips.passive.flags.valid) { in acpi_thermal_cooling_device_cb()
712 for (i = 0; i < tz->trips.passive.devices.count; i++) { in acpi_thermal_cooling_device_cb()
713 handle = tz->trips.passive.devices.handles[i]; in acpi_thermal_cooling_device_cb()
735 if (!tz->trips.active[i].flags.valid) in acpi_thermal_cooling_device_cb()
739 for (j = 0; j < tz->trips.active[i].devices.count; j++) { in acpi_thermal_cooling_device_cb()
740 handle = tz->trips.active[i].devices.handles[j]; in acpi_thermal_cooling_device_cb()
797 if (tz->trips.critical.flags.valid) in acpi_thermal_register_thermal_zone()
800 if (tz->trips.hot.flags.valid) in acpi_thermal_register_thermal_zone()
803 if (tz->trips.passive.flags.valid) in acpi_thermal_register_thermal_zone()
806 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].flags.valid; in acpi_thermal_register_thermal_zone()
809 if (tz->trips.passive.flags.valid) in acpi_thermal_register_thermal_zone()
810 tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz, in acpi_thermal_register_thermal_zone()
812 tz->trips.passive.tsp * 100, in acpi_thermal_register_thermal_zone()
813 tz->polling_frequency * 100); in acpi_thermal_register_thermal_zone()
815 tz->thermal_zone = in acpi_thermal_register_thermal_zone()
818 0, tz->polling_frequency * 100); in acpi_thermal_register_thermal_zone()
820 if (IS_ERR(tz->thermal_zone)) in acpi_thermal_register_thermal_zone()
821 return -ENODEV; in acpi_thermal_register_thermal_zone()
823 result = sysfs_create_link(&tz->device->dev.kobj, in acpi_thermal_register_thermal_zone()
824 &tz->thermal_zone->device.kobj, "thermal_zone"); in acpi_thermal_register_thermal_zone()
828 result = sysfs_create_link(&tz->thermal_zone->device.kobj, in acpi_thermal_register_thermal_zone()
829 &tz->device->dev.kobj, "device"); in acpi_thermal_register_thermal_zone()
833 status = acpi_bus_attach_private_data(tz->device->handle, in acpi_thermal_register_thermal_zone()
834 tz->thermal_zone); in acpi_thermal_register_thermal_zone()
836 result = -ENODEV; in acpi_thermal_register_thermal_zone()
840 result = thermal_zone_device_enable(tz->thermal_zone); in acpi_thermal_register_thermal_zone()
844 dev_info(&tz->device->dev, "registered as thermal_zone%d\n", in acpi_thermal_register_thermal_zone()
845 tz->thermal_zone->id); in acpi_thermal_register_thermal_zone()
850 acpi_bus_detach_private_data(tz->device->handle); in acpi_thermal_register_thermal_zone()
852 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); in acpi_thermal_register_thermal_zone()
854 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); in acpi_thermal_register_thermal_zone()
856 thermal_zone_device_unregister(tz->thermal_zone); in acpi_thermal_register_thermal_zone()
863 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); in acpi_thermal_unregister_thermal_zone()
864 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); in acpi_thermal_unregister_thermal_zone()
865 thermal_zone_device_unregister(tz->thermal_zone); in acpi_thermal_unregister_thermal_zone()
866 tz->thermal_zone = NULL; in acpi_thermal_unregister_thermal_zone()
867 acpi_bus_detach_private_data(tz->device->handle); in acpi_thermal_unregister_thermal_zone()
871 /* --------------------------------------------------------------------------
873 -------------------------------------------------------------------------- */
877 if (!work_pending(&tz->thermal_check_work)) in acpi_queue_thermal_check()
878 queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work); in acpi_queue_thermal_check()
895 acpi_bus_generate_netlink_event(device->pnp.device_class, in acpi_thermal_notify()
896 dev_name(&device->dev), event, 0); in acpi_thermal_notify()
901 acpi_bus_generate_netlink_event(device->pnp.device_class, in acpi_thermal_notify()
902 dev_name(&device->dev), event, 0); in acpi_thermal_notify()
905 acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", in acpi_thermal_notify()
914 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
925 acpi_handle handle = tz->device->handle; in acpi_thermal_aml_dependency_fix()
948 return -EINVAL; in acpi_thermal_get_info()
965 tz->flags.cooling_mode = 1; in acpi_thermal_get_info()
969 tz->polling_frequency = tzp; in acpi_thermal_get_info()
988 if (tz->trips.critical.flags.valid && in acpi_thermal_guess_offset()
989 (tz->trips.critical.temperature % 5) == 1) in acpi_thermal_guess_offset()
990 tz->kelvin_offset = 273100; in acpi_thermal_guess_offset()
992 tz->kelvin_offset = 273200; in acpi_thermal_guess_offset()
1008 if (!refcount_dec_not_one(&tz->thermal_check_count)) in acpi_thermal_check_fn()
1011 mutex_lock(&tz->thermal_check_lock); in acpi_thermal_check_fn()
1013 thermal_zone_device_update(tz->thermal_zone, THERMAL_EVENT_UNSPECIFIED); in acpi_thermal_check_fn()
1015 refcount_inc(&tz->thermal_check_count); in acpi_thermal_check_fn()
1017 mutex_unlock(&tz->thermal_check_lock); in acpi_thermal_check_fn()
1026 return -EINVAL; in acpi_thermal_add()
1030 return -ENOMEM; in acpi_thermal_add()
1032 tz->device = device; in acpi_thermal_add()
1033 strcpy(tz->name, device->pnp.bus_id); in acpi_thermal_add()
1036 device->driver_data = tz; in acpi_thermal_add()
1048 refcount_set(&tz->thermal_check_count, 3); in acpi_thermal_add()
1049 mutex_init(&tz->thermal_check_lock); in acpi_thermal_add()
1050 INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn); in acpi_thermal_add()
1053 acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature)); in acpi_thermal_add()
1067 return -EINVAL; in acpi_thermal_remove()
1091 return -EINVAL; in acpi_thermal_resume()
1095 return -EINVAL; in acpi_thermal_resume()
1098 if (!tz->trips.active[i].flags.valid) in acpi_thermal_resume()
1101 tz->trips.active[i].flags.enabled = 1; in acpi_thermal_resume()
1102 for (j = 0; j < tz->trips.active[i].devices.count; j++) { in acpi_thermal_resume()
1104 tz->trips.active[i].devices.handles[j], in acpi_thermal_resume()
1107 tz->trips.active[i].flags.enabled = 0; in acpi_thermal_resume()
1111 tz->state.active |= tz->trips.active[i].flags.enabled; in acpi_thermal_resume()
1123 d->ident); in thermal_act()
1124 act = -1; in thermal_act()
1130 d->ident); in thermal_nocrt()
1137 d->ident); in thermal_tzp()
1145 d->ident); in thermal_psv()
1146 psv = -1; in thermal_psv()
1158 .ident = "AOpen i915GMm-HFS",
1161 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1166 .ident = "AOpen i915GMm-HFS",
1169 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1174 .ident = "AOpen i915GMm-HFS",
1177 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1182 .ident = "Gigabyte GA-7ZX",
1199 return -ENODEV; in acpi_thermal_init()
1205 return -ENODEV; in acpi_thermal_init()
1210 return -ENODEV; in acpi_thermal_init()