Lines Matching refs:tz

65 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, tz, str) \
68 acpi_handle_info(tz->device->handle, \
141 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
146 if (!tz)
149 tz->last_temperature = tz->temperature;
151 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
155 tz->temperature = tmp;
157 acpi_handle_debug(tz->device->handle, "Temperature is %lu dK\n",
158 tz->temperature);
163 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
168 if (!tz)
171 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
175 tz->polling_frequency = tmp;
176 acpi_handle_debug(tz->device->handle, "Polling frequency is %lu dS\n",
177 tz->polling_frequency);
182 static int acpi_thermal_temp(struct acpi_thermal *tz, int temp_deci_k)
188 tz->kelvin_offset);
191 static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
201 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp);
202 tz->trips.critical.temperature = tmp;
210 tz->trips.critical.valid = false;
211 acpi_handle_debug(tz->device->handle,
215 tz->trips.critical.valid = false;
217 tz->trips.critical.valid = true;
218 acpi_handle_debug(tz->device->handle,
220 tz->trips.critical.temperature);
222 if (tz->trips.critical.valid) {
224 tz->trips.critical.valid = false;
231 if (crt_k > tz->trips.critical.temperature)
234 tz->trips.critical.temperature = crt_k;
241 status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp);
243 tz->trips.hot.valid = false;
244 acpi_handle_debug(tz->device->handle,
247 tz->trips.hot.temperature = tmp;
248 tz->trips.hot.valid = true;
249 acpi_handle_debug(tz->device->handle,
251 tz->trips.hot.temperature);
256 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.trip.valid) ||
258 valid = tz->trips.passive.trip.valid;
265 status = acpi_evaluate_integer(tz->device->handle,
270 tz->trips.passive.trip.valid = false;
272 tz->trips.passive.trip.temperature = tmp;
273 tz->trips.passive.trip.valid = true;
275 status = acpi_evaluate_integer(tz->device->handle,
278 tz->trips.passive.trip.valid = false;
280 tz->trips.passive.tc1 = tmp;
282 status = acpi_evaluate_integer(tz->device->handle,
285 tz->trips.passive.trip.valid = false;
287 tz->trips.passive.tc2 = tmp;
289 status = acpi_evaluate_integer(tz->device->handle,
292 tz->trips.passive.trip.valid = false;
294 tz->trips.passive.tsp = tmp;
298 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.trip.valid) {
300 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
303 acpi_handle_info(tz->device->handle,
305 tz->trips.passive.trip.valid = false;
307 tz->trips.passive.trip.valid = true;
310 if (memcmp(&tz->trips.passive.devices, &devices,
312 memcpy(&tz->trips.passive.devices, &devices,
314 ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device");
318 if (valid != tz->trips.passive.trip.valid)
319 ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state");
325 valid = tz->trips.active[i].trip.valid;
331 tz->trips.active[i].trip.valid)) {
332 status = acpi_evaluate_integer(tz->device->handle,
335 tz->trips.active[i].trip.valid = false;
343 tz->trips.active[0].trip.temperature =
350 tz->trips.active[i-1].trip.temperature =
352 tz->trips.active[i-2].trip.temperature,
357 tz->trips.active[i].trip.temperature = tmp;
358 tz->trips.active[i].trip.valid = true;
363 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].trip.valid) {
365 status = acpi_evaluate_reference(tz->device->handle,
368 acpi_handle_info(tz->device->handle,
370 tz->trips.active[i].trip.valid = false;
372 tz->trips.active[i].trip.valid = true;
375 if (memcmp(&tz->trips.active[i].devices, &devices,
377 memcpy(&tz->trips.active[i].devices, &devices,
379 ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device");
383 if (valid != tz->trips.active[i].trip.valid)
384 ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state");
386 if (!tz->trips.active[i].trip.valid)
392 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
395 memcmp(&tz->devices, &devices, sizeof(devices))) {
396 tz->devices = devices;
397 ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device");
405 struct acpi_thermal *tz = data;
411 trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature);
421 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
425 __acpi_thermal_trips_update(tz, flag);
427 for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz);
430 static void acpi_queue_thermal_check(struct acpi_thermal *tz)
432 if (!work_pending(&tz->thermal_check_work))
433 queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work);
436 static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
438 struct acpi_device *adev = tz->device;
447 thermal_zone_device_exec(tz->thermal_zone,
449 acpi_queue_thermal_check(tz);
454 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
459 __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
461 valid = tz->trips.critical.valid |
462 tz->trips.hot.valid |
463 tz->trips.passive.trip.valid;
466 valid = valid || tz->trips.active[i].trip.valid;
479 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
482 if (!tz)
485 result = acpi_thermal_get_temperature(tz);
489 *temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature,
490 tz->kelvin_offset);
498 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
502 if (!tz || !trip)
511 t = tz->trips.passive.tc1 * (tz->temperature -
512 tz->last_temperature) +
513 tz->trips.passive.tc2 * (tz->temperature -
525 t = acpi_thermal_temp(tz, tz->temperature);
542 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
544 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
545 dev_name(&tz->device->dev),
551 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
553 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
554 dev_name(&tz->device->dev),
565 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
573 if (tz->trips.critical.valid)
576 if (tz->trips.hot.valid)
579 if (tz->trips.passive.trip.valid) {
581 for (i = 0; i < tz->trips.passive.devices.count; i++) {
582 handle = tz->trips.passive.devices.handles[i];
604 if (!tz->trips.active[i].trip.valid)
608 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
609 handle = tz->trips.active[i].devices.handles[j];
656 static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz)
658 struct device *tzdev = thermal_zone_device(tz->thermal_zone);
661 ret = sysfs_create_link(&tz->device->dev.kobj,
667 &tz->device->dev.kobj, "device");
669 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
674 static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
676 struct device *tzdev = thermal_zone_device(tz->thermal_zone);
678 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
682 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
691 if (tz->trips.critical.valid)
694 if (tz->trips.hot.valid)
697 if (tz->trips.passive.trip.valid) {
699 passive_delay = tz->trips.passive.tsp * 100;
702 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++)
709 tz->trip_table = trip;
711 if (tz->trips.critical.valid) {
713 trip->temperature = acpi_thermal_temp(tz, tz->trips.critical.temperature);
717 if (tz->trips.hot.valid) {
719 trip->temperature = acpi_thermal_temp(tz, tz->trips.hot.temperature);
723 acpi_trip = &tz->trips.passive.trip;
726 trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature);
732 acpi_trip = &tz->trips.active[i].trip;
738 trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature);
743 tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz",
744 tz->trip_table,
746 0, tz,
750 tz->polling_frequency * 100);
751 if (IS_ERR(tz->thermal_zone)) {
752 result = PTR_ERR(tz->thermal_zone);
756 result = acpi_thermal_zone_sysfs_add(tz);
760 result = thermal_zone_device_enable(tz->thermal_zone);
764 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
765 thermal_zone_device_id(tz->thermal_zone));
770 acpi_thermal_zone_sysfs_remove(tz);
772 thermal_zone_device_unregister(tz->thermal_zone);
774 kfree(tz->trip_table);
779 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
781 thermal_zone_device_disable(tz->thermal_zone);
782 acpi_thermal_zone_sysfs_remove(tz);
783 thermal_zone_device_unregister(tz->thermal_zone);
784 tz->thermal_zone = NULL;
795 struct acpi_thermal *tz = acpi_driver_data(device);
797 if (!tz)
802 acpi_queue_thermal_check(tz);
806 acpi_thermal_trips_update(tz, event);
827 static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
829 acpi_handle handle = tz->device->handle;
847 static int acpi_thermal_get_info(struct acpi_thermal *tz)
851 if (!tz)
854 acpi_thermal_aml_dependency_fix(tz);
857 result = acpi_thermal_get_trip_points(tz);
862 result = acpi_thermal_get_temperature(tz);
867 acpi_execute_simple_method(tz->device->handle, "_SCP",
872 tz->polling_frequency = tzp;
874 acpi_thermal_get_polling_frequency(tz);
889 static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
891 if (tz->trips.critical.valid &&
892 (tz->trips.critical.temperature % 5) == 1)
893 tz->kelvin_offset = 273100;
895 tz->kelvin_offset = 273200;
900 struct acpi_thermal *tz = container_of(work, struct acpi_thermal,
911 if (!refcount_dec_not_one(&tz->thermal_check_count))
914 mutex_lock(&tz->thermal_check_lock);
916 thermal_zone_device_update(tz->thermal_zone, THERMAL_EVENT_UNSPECIFIED);
918 refcount_inc(&tz->thermal_check_count);
920 mutex_unlock(&tz->thermal_check_lock);
925 struct acpi_thermal *tz;
931 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
932 if (!tz)
935 tz->device = device;
936 strcpy(tz->name, device->pnp.bus_id);
939 device->driver_data = tz;
941 result = acpi_thermal_get_info(tz);
945 acpi_thermal_guess_offset(tz);
947 result = acpi_thermal_register_thermal_zone(tz);
951 refcount_set(&tz->thermal_check_count, 3);
952 mutex_init(&tz->thermal_check_lock);
953 INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn);
956 acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature));
967 acpi_thermal_unregister_thermal_zone(tz);
969 kfree(tz);
976 struct acpi_thermal *tz;
981 tz = acpi_driver_data(device);
987 acpi_thermal_unregister_thermal_zone(tz);
988 kfree(tz->trip_table);
989 kfree(tz);
1002 struct acpi_thermal *tz;
1008 tz = acpi_driver_data(to_acpi_device(dev));
1009 if (!tz)
1013 if (!tz->trips.active[i].trip.valid)
1016 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1017 acpi_bus_update_power(tz->trips.active[i].devices.handles[j],
1022 acpi_queue_thermal_check(tz);