Lines Matching refs:tz
59 #define ACPI_THERMAL_TRIPS_EXCEPTION(tz, str) \
61 acpi_handle_info(tz->device->handle, \
128 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
133 if (!tz)
136 tz->last_temp_dk = tz->temp_dk;
138 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
142 tz->temp_dk = tmp;
144 acpi_handle_debug(tz->device->handle, "Temperature is %lu dK\n",
145 tz->temp_dk);
150 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
155 if (!tz)
158 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
162 tz->polling_frequency = tmp;
163 acpi_handle_debug(tz->device->handle, "Polling frequency is %lu dS\n",
164 tz->polling_frequency);
169 static int acpi_thermal_temp(struct acpi_thermal *tz, int temp_deci_k)
177 tz->kelvin_offset);
189 static int active_trip_index(struct acpi_thermal *tz,
195 return active - tz->trips.active;
198 static long get_passive_temp(struct acpi_thermal *tz)
202 if (acpi_passive_trip_temp(tz->device, &temp))
208 static long get_active_temp(struct acpi_thermal *tz, int index)
212 if (acpi_active_trip_temp(tz->device, index, &temp))
228 static void acpi_thermal_update_trip(struct acpi_thermal *tz,
237 acpi_trip->temp_dk = get_passive_temp(tz);
239 int index = active_trip_index(tz, acpi_trip);
241 acpi_trip->temp_dk = get_active_temp(tz, index);
245 ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
248 static bool update_trip_devices(struct acpi_thermal *tz,
261 if (!acpi_evaluate_reference(tz->device->handle, method, NULL, &devices)) {
262 acpi_handle_info(tz->device->handle, "%s evaluation failure\n", method);
272 ACPI_THERMAL_TRIPS_EXCEPTION(tz, "device");
278 static void acpi_thermal_update_trip_devices(struct acpi_thermal *tz,
283 ACPI_THERMAL_TRIP_PASSIVE : active_trip_index(tz, acpi_trip);
285 if (update_trip_devices(tz, acpi_trip, index, true))
289 ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
293 struct acpi_thermal *tz;
301 struct acpi_thermal *tz = atd->tz;
308 acpi_thermal_update_trip(tz, trip);
310 acpi_thermal_update_trip_devices(tz, trip);
313 temp = acpi_thermal_temp(tz, acpi_trip->temp_dk);
317 thermal_zone_set_trip_temp(tz->thermal_zone, trip, temp);
322 static void acpi_queue_thermal_check(struct acpi_thermal *tz)
324 if (!work_pending(&tz->thermal_check_work))
325 queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work);
328 static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
330 struct adjust_trip_data atd = { .tz = tz, .event = event };
331 struct acpi_device *adev = tz->device;
340 thermal_zone_for_each_trip(tz->thermal_zone,
342 acpi_queue_thermal_check(tz);
347 static int acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
356 acpi_handle_debug(tz->device->handle, "Critical threshold disabled\n");
360 if (acpi_critical_trip_temp(tz->device, &temp))
373 acpi_handle_debug(tz->device->handle, "Critical threshold [%d]\n", temp);
377 static int acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
381 if (acpi_hot_trip_temp(tz->device, &temp) || temp == THERMAL_TEMP_INVALID) {
382 acpi_handle_debug(tz->device->handle, "No hot threshold\n");
386 acpi_handle_debug(tz->device->handle, "Hot threshold [%d]\n", temp);
390 static bool passive_trip_params_init(struct acpi_thermal *tz)
395 status = acpi_evaluate_integer(tz->device->handle, "_TC1", NULL, &tmp);
399 tz->trips.passive.tc1 = tmp;
401 status = acpi_evaluate_integer(tz->device->handle, "_TC2", NULL, &tmp);
405 tz->trips.passive.tc2 = tmp;
407 status = acpi_evaluate_integer(tz->device->handle, "_TFP", NULL, &tmp);
409 tz->trips.passive.delay = tmp;
413 status = acpi_evaluate_integer(tz->device->handle, "_TSP", NULL, &tmp);
417 tz->trips.passive.delay = tmp * 100;
422 static bool acpi_thermal_init_trip(struct acpi_thermal *tz, int index)
428 acpi_trip = &tz->trips.passive.trip;
433 if (!passive_trip_params_init(tz))
437 get_passive_temp(tz);
439 acpi_trip = &tz->trips.active[index].trip;
444 temp = get_active_temp(tz, index);
450 if (!update_trip_devices(tz, acpi_trip, index, false))
461 static void acpi_thermal_get_trip_points(struct acpi_thermal *tz)
465 acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE);
468 if (!acpi_thermal_init_trip(tz, i))
473 tz->trips.active[i].trip.temp_dk = THERMAL_TEMP_INVALID;
480 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
483 if (!tz)
486 result = acpi_thermal_get_temperature(tz);
490 *temp = deci_kelvin_to_millicelsius_with_offset(tz->temp_dk,
491 tz->kelvin_offset);
499 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
503 if (!tz || !trip)
512 t = tz->trips.passive.tc1 * (tz->temp_dk -
513 tz->last_temp_dk) +
514 tz->trips.passive.tc2 * (tz->temp_dk -
526 t = acpi_thermal_temp(tz, tz->temp_dk);
543 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
546 dev_name(&tz->device->dev),
552 struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
555 dev_name(&tz->device->dev),
592 static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz)
594 struct device *tzdev = thermal_zone_device(tz->thermal_zone);
597 ret = sysfs_create_link(&tz->device->dev.kobj,
603 &tz->device->dev.kobj, "device");
605 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
610 static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
612 struct device *tzdev = thermal_zone_device(tz->thermal_zone);
614 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
618 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz,
626 tz->thermal_zone = thermal_zone_device_register_with_trips(
627 "acpitz", trip_table, trip_count, tz,
629 tz->polling_frequency * 100);
631 tz->thermal_zone = thermal_tripless_zone_device_register(
632 "acpitz", tz, &acpi_thermal_zone_ops, NULL);
634 if (IS_ERR(tz->thermal_zone))
635 return PTR_ERR(tz->thermal_zone);
637 result = acpi_thermal_zone_sysfs_add(tz);
641 result = thermal_zone_device_enable(tz->thermal_zone);
645 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
646 thermal_zone_device_id(tz->thermal_zone));
651 acpi_thermal_zone_sysfs_remove(tz);
653 thermal_zone_device_unregister(tz->thermal_zone);
660 struct acpi_thermal *tz = data;
664 thermal_zone_device_disable(tz->thermal_zone);
665 acpi_thermal_zone_sysfs_remove(tz);
666 thermal_zone_device_unregister(tz->thermal_zone);
667 tz->thermal_zone = NULL;
677 struct acpi_thermal *tz = data;
679 if (!tz)
684 acpi_queue_thermal_check(tz);
688 acpi_thermal_trips_update(tz, event);
691 acpi_handle_debug(tz->device->handle,
709 static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
711 acpi_handle handle = tz->device->handle;
739 static void acpi_thermal_guess_offset(struct acpi_thermal *tz, long crit_temp)
742 tz->kelvin_offset = 273100;
744 tz->kelvin_offset = 273200;
749 struct acpi_thermal *tz = container_of(work, struct acpi_thermal,
760 if (!refcount_dec_not_one(&tz->thermal_check_count))
763 mutex_lock(&tz->thermal_check_lock);
765 thermal_zone_device_update(tz->thermal_zone, THERMAL_EVENT_UNSPECIFIED);
767 refcount_inc(&tz->thermal_check_count);
769 mutex_unlock(&tz->thermal_check_lock);
774 struct acpi_thermal *tz = data;
777 acpi_handle_list_free(&tz->trips.passive.trip.devices);
779 acpi_handle_list_free(&tz->trips.active[i].trip.devices);
781 kfree(tz);
791 struct acpi_thermal *tz;
800 tz = kzalloc_obj(struct acpi_thermal);
801 if (!tz)
804 result = devm_add_action_or_reset(dev, acpi_thermal_zone_free, tz);
808 platform_set_drvdata(pdev, tz);
810 tz->device = device;
811 strscpy(tz->name, device->pnp.bus_id);
813 acpi_thermal_aml_dependency_fix(tz);
819 acpi_execute_simple_method(tz->device->handle, "_SCP", ACPI_THERMAL_MODE_ACTIVE);
822 acpi_thermal_get_trip_points(tz);
824 crit_temp = acpi_thermal_get_critical_trip(tz);
825 hot_temp = acpi_thermal_get_hot_trip(tz);
828 result = acpi_thermal_get_temperature(tz);
834 tz->polling_frequency = tzp;
836 acpi_thermal_get_polling_frequency(tz);
838 acpi_thermal_guess_offset(tz, crit_temp);
844 trip->temperature = acpi_thermal_temp(tz, crit_temp);
850 trip->temperature = acpi_thermal_temp(tz, hot_temp);
854 acpi_trip = &tz->trips.passive.trip;
856 passive_delay = tz->trips.passive.delay;
859 trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk);
865 acpi_trip = &tz->trips.active[i].trip;
871 trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk);
879 result = acpi_thermal_register_thermal_zone(tz, trip_table,
885 result = devm_add_action_or_reset(dev, acpi_thermal_zone_unregister, tz);
889 refcount_set(&tz->thermal_check_count, 3);
890 mutex_init(&tz->thermal_check_lock);
891 INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn);
894 deci_kelvin_to_celsius(tz->temp_dk));
897 acpi_thermal_notify, tz);