Lines Matching +full:device +full:- +full:handle

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $)
27 #include <linux/device.h>
76 static int acpi_thermal_add(struct acpi_device *device);
77 static int acpi_thermal_remove(struct acpi_device *device);
78 static void acpi_thermal_notify(struct acpi_device *device, u32 event);
87 static int acpi_thermal_suspend(struct device *dev);
88 static int acpi_thermal_resume(struct device *dev);
161 struct acpi_device * device; 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()
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); \
273 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
275 tz->trips.critical.temperature = tmp; in acpi_thermal_trips_update()
283 tz->trips.critical.flags.valid = 0; in acpi_thermal_trips_update()
284 acpi_handle_debug(tz->device->handle, in acpi_thermal_trips_update()
289 tz->trips.critical.flags.valid = 0; in acpi_thermal_trips_update()
291 tz->trips.critical.flags.valid = 1; in acpi_thermal_trips_update()
292 acpi_handle_debug(tz->device->handle, in acpi_thermal_trips_update()
294 tz->trips.critical.temperature); in acpi_thermal_trips_update()
296 if (tz->trips.critical.flags.valid == 1) { in acpi_thermal_trips_update()
297 if (crt == -1) { in acpi_thermal_trips_update()
298 tz->trips.critical.flags.valid = 0; in acpi_thermal_trips_update()
305 if (crt_k > tz->trips.critical.temperature) in acpi_thermal_trips_update()
308 tz->trips.critical.temperature = crt_k; in acpi_thermal_trips_update()
315 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
318 tz->trips.hot.flags.valid = 0; in acpi_thermal_trips_update()
319 acpi_handle_debug(tz->device->handle, in acpi_thermal_trips_update()
322 tz->trips.hot.temperature = tmp; in acpi_thermal_trips_update()
323 tz->trips.hot.flags.valid = 1; in acpi_thermal_trips_update()
324 acpi_handle_debug(tz->device->handle, in acpi_thermal_trips_update()
326 tz->trips.hot.temperature); in acpi_thermal_trips_update()
331 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || in acpi_thermal_trips_update()
333 valid = tz->trips.passive.flags.valid; in acpi_thermal_trips_update()
334 if (psv == -1) { in acpi_thermal_trips_update()
340 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
345 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
347 tz->trips.passive.temperature = tmp; in acpi_thermal_trips_update()
348 tz->trips.passive.flags.valid = 1; in acpi_thermal_trips_update()
351 tz->device->handle, "_TC1", in acpi_thermal_trips_update()
354 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
356 tz->trips.passive.tc1 = tmp; in acpi_thermal_trips_update()
358 tz->device->handle, "_TC2", in acpi_thermal_trips_update()
361 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
363 tz->trips.passive.tc2 = tmp; in acpi_thermal_trips_update()
365 tz->device->handle, "_TSP", in acpi_thermal_trips_update()
368 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
370 tz->trips.passive.tsp = tmp; in acpi_thermal_trips_update()
374 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { in acpi_thermal_trips_update()
376 status = acpi_evaluate_reference(tz->device->handle, "_PSL", in acpi_thermal_trips_update()
379 acpi_handle_info(tz->device->handle, in acpi_thermal_trips_update()
381 tz->trips.passive.flags.valid = 0; in acpi_thermal_trips_update()
384 tz->trips.passive.flags.valid = 1; in acpi_thermal_trips_update()
386 if (memcmp(&tz->trips.passive.devices, &devices, in acpi_thermal_trips_update()
388 memcpy(&tz->trips.passive.devices, &devices, in acpi_thermal_trips_update()
390 ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); in acpi_thermal_trips_update()
394 if (valid != tz->trips.passive.flags.valid) in acpi_thermal_trips_update()
401 valid = tz->trips.active[i].flags.valid; in acpi_thermal_trips_update()
403 if (act == -1) in acpi_thermal_trips_update()
407 tz->trips.active[i].flags.valid)) { in acpi_thermal_trips_update()
408 status = acpi_evaluate_integer(tz->device->handle, in acpi_thermal_trips_update()
411 tz->trips.active[i].flags.valid = 0; in acpi_thermal_trips_update()
417 tz->trips.active[0].temperature = in acpi_thermal_trips_update()
424 tz->trips.active[i - 1].temperature = in acpi_thermal_trips_update()
425 (tz->trips.active[i - 2].temperature < in acpi_thermal_trips_update()
427 tz->trips.active[i - 2].temperature : in acpi_thermal_trips_update()
431 tz->trips.active[i].temperature = tmp; in acpi_thermal_trips_update()
432 tz->trips.active[i].flags.valid = 1; in acpi_thermal_trips_update()
437 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { in acpi_thermal_trips_update()
439 status = acpi_evaluate_reference(tz->device->handle, in acpi_thermal_trips_update()
442 acpi_handle_info(tz->device->handle, in acpi_thermal_trips_update()
444 tz->trips.active[i].flags.valid = 0; in acpi_thermal_trips_update()
447 tz->trips.active[i].flags.valid = 1; in acpi_thermal_trips_update()
449 if (memcmp(&tz->trips.active[i].devices, &devices, in acpi_thermal_trips_update()
451 memcpy(&tz->trips.active[i].devices, &devices, in acpi_thermal_trips_update()
453 ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); in acpi_thermal_trips_update()
457 if (valid != tz->trips.active[i].flags.valid) in acpi_thermal_trips_update()
460 if (!tz->trips.active[i].flags.valid) in acpi_thermal_trips_update()
466 status = acpi_evaluate_reference(tz->device->handle, "_TZD", in acpi_thermal_trips_update()
469 && memcmp(&tz->devices, &devices, sizeof(devices))) { in acpi_thermal_trips_update()
470 tz->devices = devices; in acpi_thermal_trips_update()
471 ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); in acpi_thermal_trips_update()
485 valid = tz->trips.critical.flags.valid | in acpi_thermal_get_trip_points()
486 tz->trips.hot.flags.valid | in acpi_thermal_get_trip_points()
487 tz->trips.passive.flags.valid; in acpi_thermal_get_trip_points()
490 valid |= tz->trips.active[i].flags.valid; in acpi_thermal_get_trip_points()
494 return -ENODEV; in acpi_thermal_get_trip_points()
503 struct acpi_thermal *tz = thermal->devdata; in thermal_get_temp()
507 return -EINVAL; in thermal_get_temp()
513 *temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature, in thermal_get_temp()
514 tz->kelvin_offset); in thermal_get_temp()
521 struct acpi_thermal *tz = thermal->devdata; in thermal_get_trip_type()
525 return -EINVAL; in thermal_get_trip_type()
527 if (tz->trips.critical.flags.valid) { in thermal_get_trip_type()
532 trip--; in thermal_get_trip_type()
535 if (tz->trips.hot.flags.valid) { in thermal_get_trip_type()
540 trip--; in thermal_get_trip_type()
543 if (tz->trips.passive.flags.valid) { in thermal_get_trip_type()
548 trip--; in thermal_get_trip_type()
552 tz->trips.active[i].flags.valid; i++) { in thermal_get_trip_type()
557 trip--; in thermal_get_trip_type()
560 return -EINVAL; in thermal_get_trip_type()
566 struct acpi_thermal *tz = thermal->devdata; in thermal_get_trip_temp()
570 return -EINVAL; in thermal_get_trip_temp()
572 if (tz->trips.critical.flags.valid) { in thermal_get_trip_temp()
575 tz->trips.critical.temperature, in thermal_get_trip_temp()
576 tz->kelvin_offset); in thermal_get_trip_temp()
579 trip--; in thermal_get_trip_temp()
582 if (tz->trips.hot.flags.valid) { in thermal_get_trip_temp()
585 tz->trips.hot.temperature, in thermal_get_trip_temp()
586 tz->kelvin_offset); in thermal_get_trip_temp()
589 trip--; in thermal_get_trip_temp()
592 if (tz->trips.passive.flags.valid) { in thermal_get_trip_temp()
595 tz->trips.passive.temperature, in thermal_get_trip_temp()
596 tz->kelvin_offset); in thermal_get_trip_temp()
599 trip--; in thermal_get_trip_temp()
603 tz->trips.active[i].flags.valid; i++) { in thermal_get_trip_temp()
606 tz->trips.active[i].temperature, in thermal_get_trip_temp()
607 tz->kelvin_offset); in thermal_get_trip_temp()
610 trip--; in thermal_get_trip_temp()
613 return -EINVAL; in thermal_get_trip_temp()
619 struct acpi_thermal *tz = thermal->devdata; in thermal_get_crit_temp()
621 if (tz->trips.critical.flags.valid) { in thermal_get_crit_temp()
623 tz->trips.critical.temperature, in thermal_get_crit_temp()
624 tz->kelvin_offset); in thermal_get_crit_temp()
627 return -EINVAL; in thermal_get_crit_temp()
633 struct acpi_thermal *tz = thermal->devdata; in thermal_get_trend()
638 return -EINVAL; in thermal_get_trend()
643 tz->temperature, tz->kelvin_offset); in thermal_get_trend()
645 return -EINVAL; in thermal_get_trend()
652 return -EINVAL; in thermal_get_trend()
657 * tz->temperature has already been updated by generic thermal layer, in thermal_get_trend()
660 i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) in thermal_get_trend()
661 + (tz->trips.passive.tc2 in thermal_get_trend()
662 * (tz->temperature - tz->trips.passive.temperature)); in thermal_get_trend()
675 struct acpi_thermal *tz = thermal->devdata; in acpi_thermal_zone_device_hot()
677 acpi_bus_generate_netlink_event(tz->device->pnp.device_class, in acpi_thermal_zone_device_hot()
678 dev_name(&tz->device->dev), in acpi_thermal_zone_device_hot()
684 struct acpi_thermal *tz = thermal->devdata; in acpi_thermal_zone_device_critical()
686 acpi_bus_generate_netlink_event(tz->device->pnp.device_class, in acpi_thermal_zone_device_critical()
687 dev_name(&tz->device->dev), in acpi_thermal_zone_device_critical()
697 struct acpi_device *device = cdev->devdata; in acpi_thermal_cooling_device_cb() local
698 struct acpi_thermal *tz = thermal->devdata; in acpi_thermal_cooling_device_cb()
701 acpi_handle handle; in acpi_thermal_cooling_device_cb() local
704 int trip = -1; in acpi_thermal_cooling_device_cb()
707 if (tz->trips.critical.flags.valid) in acpi_thermal_cooling_device_cb()
710 if (tz->trips.hot.flags.valid) in acpi_thermal_cooling_device_cb()
713 if (tz->trips.passive.flags.valid) { in acpi_thermal_cooling_device_cb()
715 for (i = 0; i < tz->trips.passive.devices.count; in acpi_thermal_cooling_device_cb()
717 handle = tz->trips.passive.devices.handles[i]; in acpi_thermal_cooling_device_cb()
718 status = acpi_bus_get_device(handle, &dev); in acpi_thermal_cooling_device_cb()
719 if (ACPI_FAILURE(status) || dev != device) in acpi_thermal_cooling_device_cb()
737 if (!tz->trips.active[i].flags.valid) in acpi_thermal_cooling_device_cb()
741 j < tz->trips.active[i].devices.count; in acpi_thermal_cooling_device_cb()
743 handle = tz->trips.active[i].devices.handles[j]; in acpi_thermal_cooling_device_cb()
744 status = acpi_bus_get_device(handle, &dev); in acpi_thermal_cooling_device_cb()
745 if (ACPI_FAILURE(status) || dev != device) 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()
807 tz->trips.active[i].flags.valid; i++, trips++); in acpi_thermal_register_thermal_zone()
809 if (tz->trips.passive.flags.valid) in acpi_thermal_register_thermal_zone()
810 tz->thermal_zone = in acpi_thermal_register_thermal_zone()
813 tz->trips.passive.tsp*100, in acpi_thermal_register_thermal_zone()
814 tz->polling_frequency*100); in acpi_thermal_register_thermal_zone()
816 tz->thermal_zone = in acpi_thermal_register_thermal_zone()
819 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()
881 static void acpi_thermal_notify(struct acpi_device *device, u32 event) in acpi_thermal_notify() argument
883 struct acpi_thermal *tz = acpi_driver_data(device); in acpi_thermal_notify()
896 acpi_bus_generate_netlink_event(device->pnp.device_class, in acpi_thermal_notify()
897 dev_name(&device->dev), event, 0); in acpi_thermal_notify()
902 acpi_bus_generate_netlink_event(device->pnp.device_class, in acpi_thermal_notify()
903 dev_name(&device->dev), event, 0); in acpi_thermal_notify()
906 acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", in acpi_thermal_notify()
915 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
926 acpi_handle handle = tz->device->handle; in acpi_thermal_aml_dependency_fix() local
930 acpi_evaluate_integer(handle, "_CRT", NULL, &value); in acpi_thermal_aml_dependency_fix()
931 acpi_evaluate_integer(handle, "_HOT", NULL, &value); in acpi_thermal_aml_dependency_fix()
932 acpi_evaluate_integer(handle, "_PSV", NULL, &value); in acpi_thermal_aml_dependency_fix()
937 status = acpi_evaluate_integer(handle, name, NULL, &value); in acpi_thermal_aml_dependency_fix()
941 acpi_evaluate_integer(handle, "_TMP", NULL, &value); in acpi_thermal_aml_dependency_fix()
950 return -EINVAL; in acpi_thermal_get_info()
967 tz->flags.cooling_mode = 1; in acpi_thermal_get_info()
971 tz->polling_frequency = tzp; in acpi_thermal_get_info()
990 if (tz->trips.critical.flags.valid && in acpi_thermal_guess_offset()
991 (tz->trips.critical.temperature % 5) == 1) in acpi_thermal_guess_offset()
992 tz->kelvin_offset = 273100; in acpi_thermal_guess_offset()
994 tz->kelvin_offset = 273200; in acpi_thermal_guess_offset()
1010 if (!refcount_dec_not_one(&tz->thermal_check_count)) in acpi_thermal_check_fn()
1013 mutex_lock(&tz->thermal_check_lock); in acpi_thermal_check_fn()
1015 thermal_zone_device_update(tz->thermal_zone, THERMAL_EVENT_UNSPECIFIED); in acpi_thermal_check_fn()
1017 refcount_inc(&tz->thermal_check_count); in acpi_thermal_check_fn()
1019 mutex_unlock(&tz->thermal_check_lock); in acpi_thermal_check_fn()
1022 static int acpi_thermal_add(struct acpi_device *device) in acpi_thermal_add() argument
1028 if (!device) in acpi_thermal_add()
1029 return -EINVAL; in acpi_thermal_add()
1033 return -ENOMEM; in acpi_thermal_add()
1035 tz->device = device; in acpi_thermal_add()
1036 strcpy(tz->name, device->pnp.bus_id); in acpi_thermal_add()
1037 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); in acpi_thermal_add()
1038 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); in acpi_thermal_add()
1039 device->driver_data = tz; in acpi_thermal_add()
1051 refcount_set(&tz->thermal_check_count, 3); in acpi_thermal_add()
1052 mutex_init(&tz->thermal_check_lock); in acpi_thermal_add()
1053 INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn); in acpi_thermal_add()
1055 pr_info("%s [%s] (%ld C)\n", acpi_device_name(device), in acpi_thermal_add()
1056 acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature)); in acpi_thermal_add()
1065 static int acpi_thermal_remove(struct acpi_device *device) in acpi_thermal_remove() argument
1069 if (!device || !acpi_driver_data(device)) in acpi_thermal_remove()
1070 return -EINVAL; in acpi_thermal_remove()
1073 tz = acpi_driver_data(device); in acpi_thermal_remove()
1081 static int acpi_thermal_suspend(struct device *dev) in acpi_thermal_suspend()
1088 static int acpi_thermal_resume(struct device *dev) in acpi_thermal_resume()
1094 return -EINVAL; in acpi_thermal_resume()
1098 return -EINVAL; in acpi_thermal_resume()
1101 if (!(&tz->trips.active[i])) in acpi_thermal_resume()
1103 if (!tz->trips.active[i].flags.valid) in acpi_thermal_resume()
1105 tz->trips.active[i].flags.enabled = 1; in acpi_thermal_resume()
1106 for (j = 0; j < tz->trips.active[i].devices.count; j++) { in acpi_thermal_resume()
1108 tz->trips.active[i].devices.handles[j], in acpi_thermal_resume()
1111 tz->trips.active[i].flags.enabled = 0; in acpi_thermal_resume()
1115 tz->state.active |= tz->trips.active[i].flags.enabled; in acpi_thermal_resume()
1128 d->ident); in thermal_act()
1129 act = -1; in thermal_act()
1136 d->ident); in thermal_nocrt()
1144 d->ident); in thermal_tzp()
1153 d->ident); in thermal_psv()
1154 psv = -1; in thermal_psv()
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 = "AOpen i915GMm-HFS",
1185 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1190 .ident = "Gigabyte GA-7ZX",
1207 return -ENODEV; in acpi_thermal_init()
1213 return -ENODEV; in acpi_thermal_init()
1218 return -ENODEV; in acpi_thermal_init()