Lines Matching refs:tz

65  * @tz:		a valid pointer to a struct thermal_zone_device
71 static void bind_previous_governor(struct thermal_zone_device *tz,
74 if (tz->governor && tz->governor->bind_to_tz) {
75 if (tz->governor->bind_to_tz(tz)) {
76 dev_err(&tz->device,
78 failed_gov_name, tz->governor->name, tz->type);
79 tz->governor = NULL;
86 * @tz: a valid pointer to a struct thermal_zone_device
89 * Change the governor of thermal zone @tz.
93 static int thermal_set_governor(struct thermal_zone_device *tz,
98 if (tz->governor && tz->governor->unbind_from_tz)
99 tz->governor->unbind_from_tz(tz);
102 ret = new_gov->bind_to_tz(tz);
104 bind_previous_governor(tz, new_gov->name);
110 tz->governor = new_gov;
144 * only thermal zones with specified tz->tzp->governor_name
145 * may run with tz->govenor unset
195 int thermal_zone_device_set_policy(struct thermal_zone_device *tz,
202 mutex_lock(&tz->lock);
208 ret = thermal_set_governor(tz, gov);
211 mutex_unlock(&tz->lock);
214 thermal_notify_tz_gov_change(tz, policy);
284 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
289 &tz->poll_queue, delay);
291 cancel_delayed_work(&tz->poll_queue);
294 static void monitor_thermal_zone(struct thermal_zone_device *tz)
296 if (tz->mode != THERMAL_DEVICE_ENABLED)
297 thermal_zone_device_set_polling(tz, 0);
298 else if (tz->passive)
299 thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies);
300 else if (tz->polling_delay_jiffies)
301 thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
304 static void handle_non_critical_trips(struct thermal_zone_device *tz,
307 tz->governor ? tz->governor->throttle(tz, trip) :
308 def_governor->throttle(tz, trip);
311 void thermal_governor_update_tz(struct thermal_zone_device *tz,
314 if (!tz->governor || !tz->governor->update_tz)
317 tz->governor->update_tz(tz, reason);
320 static void thermal_zone_device_halt(struct thermal_zone_device *tz, bool shutdown)
329 dev_emerg(&tz->device, "%s: critical temperature reached\n", tz->type);
337 void thermal_zone_device_critical(struct thermal_zone_device *tz)
339 thermal_zone_device_halt(tz, true);
343 void thermal_zone_device_critical_reboot(struct thermal_zone_device *tz)
345 thermal_zone_device_halt(tz, false);
348 static void handle_critical_trips(struct thermal_zone_device *tz,
352 if (trip->temperature <= 0 || tz->temperature < trip->temperature)
355 trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type);
358 tz->ops.critical(tz);
359 else if (tz->ops.hot)
360 tz->ops.hot(tz);
363 static void handle_thermal_trip(struct thermal_zone_device *tz,
369 if (tz->last_temperature == THERMAL_TEMP_INVALID) {
372 if (tz->temperature >= trip->threshold)
374 } else if (tz->last_temperature < trip->threshold) {
382 if (tz->temperature >= trip->temperature) {
383 thermal_notify_tz_trip_up(tz, trip);
384 thermal_debug_tz_trip_up(tz, trip);
400 if (tz->temperature < trip->temperature - trip->hysteresis) {
401 thermal_notify_tz_trip_down(tz, trip);
402 thermal_debug_tz_trip_down(tz, trip);
410 handle_critical_trips(tz, trip);
412 handle_non_critical_trips(tz, trip);
415 static void update_temperature(struct thermal_zone_device *tz)
419 ret = __thermal_zone_get_temp(tz, &temp);
422 dev_warn(&tz->device,
428 tz->last_temperature = tz->temperature;
429 tz->temperature = temp;
431 trace_thermal_temperature(tz);
433 thermal_genl_sampling_temp(tz->id, temp);
434 thermal_debug_update_temp(tz);
439 struct thermal_zone_device *tz = container_of(work, struct
442 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
445 static void thermal_zone_device_init(struct thermal_zone_device *tz)
449 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check);
451 tz->temperature = THERMAL_TEMP_INVALID;
452 tz->prev_low_trip = -INT_MAX;
453 tz->prev_high_trip = INT_MAX;
454 list_for_each_entry(pos, &tz->thermal_instances, tz_node)
458 void __thermal_zone_device_update(struct thermal_zone_device *tz,
463 if (tz->suspended)
466 if (!thermal_zone_device_is_enabled(tz))
469 update_temperature(tz);
471 __thermal_zone_set_trips(tz);
473 tz->notify_event = event;
475 for_each_trip(tz, trip)
476 handle_thermal_trip(tz, trip);
478 monitor_thermal_zone(tz);
481 static int thermal_zone_device_set_mode(struct thermal_zone_device *tz,
486 mutex_lock(&tz->lock);
489 if (mode == tz->mode) {
490 mutex_unlock(&tz->lock);
495 if (tz->ops.change_mode)
496 ret = tz->ops.change_mode(tz, mode);
499 tz->mode = mode;
501 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
503 mutex_unlock(&tz->lock);
506 thermal_notify_tz_enable(tz);
508 thermal_notify_tz_disable(tz);
513 int thermal_zone_device_enable(struct thermal_zone_device *tz)
515 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED);
519 int thermal_zone_device_disable(struct thermal_zone_device *tz)
521 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED);
525 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz)
527 lockdep_assert_held(&tz->lock);
529 return tz->mode == THERMAL_DEVICE_ENABLED;
532 static bool thermal_zone_is_present(struct thermal_zone_device *tz)
534 return !list_empty(&tz->node);
537 void thermal_zone_device_update(struct thermal_zone_device *tz,
540 mutex_lock(&tz->lock);
541 if (thermal_zone_is_present(tz))
542 __thermal_zone_device_update(tz, event);
543 mutex_unlock(&tz->lock);
584 struct thermal_zone_device *tz;
588 list_for_each_entry(tz, &thermal_tz_list, node) {
589 ret = cb(tz, data);
600 struct thermal_zone_device *tz, *match = NULL;
603 list_for_each_entry(tz, &thermal_tz_list, node) {
604 if (tz->id == id) {
605 match = tz;
626 * @tz: pointer to struct thermal_zone_device
645 int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
659 if (pos1 == tz)
667 if (tz != pos1 || cdev != pos2)
686 dev->tz = tz;
695 result = ida_alloc(&tz->ida, GFP_KERNEL);
702 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
712 result = device_create_file(&tz->device, &dev->attr);
723 result = device_create_file(&tz->device, &dev->weight_attr);
727 mutex_lock(&tz->lock);
729 list_for_each_entry(pos, &tz->thermal_instances, tz_node)
730 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
735 list_add_tail(&dev->tz_node, &tz->thermal_instances);
737 atomic_set(&tz->need_update, 1);
739 thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
742 mutex_unlock(&tz->lock);
747 device_remove_file(&tz->device, &dev->weight_attr);
749 device_remove_file(&tz->device, &dev->attr);
751 sysfs_remove_link(&tz->device.kobj, dev->name);
753 ida_free(&tz->ida, dev->id);
760 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
766 if (trip_index < 0 || trip_index >= tz->num_trips)
769 return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index], cdev,
776 * @tz: pointer to a struct thermal_zone_device.
786 int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
792 mutex_lock(&tz->lock);
794 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
795 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
799 thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV);
802 mutex_unlock(&tz->lock);
807 mutex_unlock(&tz->lock);
812 device_remove_file(&tz->device, &pos->weight_attr);
813 device_remove_file(&tz->device, &pos->attr);
814 sysfs_remove_link(&tz->device.kobj, pos->name);
815 ida_free(&tz->ida, pos->id);
821 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
825 if (trip_index < 0 || trip_index >= tz->num_trips)
828 return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index], cdev);
834 struct thermal_zone_device *tz;
839 tz = to_thermal_zone(dev);
840 thermal_zone_destroy_device_groups(tz);
841 mutex_destroy(&tz->lock);
842 complete(&tz->removal);
856 void print_bind_err_msg(struct thermal_zone_device *tz,
859 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n",
860 tz->type, cdev->type, ret);
1168 struct thermal_zone_device *tz;
1185 list_for_each_entry(tz, &thermal_tz_list, node) {
1186 if (tz->ops.unbind)
1187 tz->ops.unbind(tz, cdev);
1196 static void bind_tz(struct thermal_zone_device *tz)
1201 if (!tz->ops.bind)
1207 ret = tz->ops.bind(tz, pos);
1209 print_bind_err_msg(tz, pos, ret);
1222 int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp)
1226 if (tz->ops.get_crit_temp)
1227 return tz->ops.get_crit_temp(tz, temp);
1229 mutex_lock(&tz->lock);
1231 for (i = 0; i < tz->num_trips; i++) {
1232 if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) {
1233 *temp = tz->trips[i].temperature;
1239 mutex_unlock(&tz->lock);
1277 struct thermal_zone_device *tz;
1309 tz = kzalloc(struct_size(tz, trips, num_trips), GFP_KERNEL);
1310 if (!tz)
1314 tz->tzp = kmemdup(tzp, sizeof(*tzp), GFP_KERNEL);
1315 if (!tz->tzp) {
1321 INIT_LIST_HEAD(&tz->thermal_instances);
1322 INIT_LIST_HEAD(&tz->node);
1323 ida_init(&tz->ida);
1324 mutex_init(&tz->lock);
1325 init_completion(&tz->removal);
1332 tz->id = id;
1333 strscpy(tz->type, type, sizeof(tz->type));
1335 tz->ops = *ops;
1336 if (!tz->ops.critical)
1337 tz->ops.critical = thermal_zone_device_critical;
1339 tz->device.class = thermal_class;
1340 tz->devdata = devdata;
1341 tz->num_trips = num_trips;
1342 memcpy(tz->trips, trips, num_trips * sizeof(*trips));
1344 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
1345 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);
1349 result = thermal_zone_create_device_groups(tz);
1354 atomic_set(&tz->need_update, 1);
1356 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id);
1358 thermal_zone_destroy_device_groups(tz);
1361 result = device_register(&tz->device);
1368 if (tz->tzp)
1369 governor = __find_governor(tz->tzp->governor_name);
1373 result = thermal_set_governor(tz, governor);
1381 if (!tz->tzp || !tz->tzp->no_hwmon) {
1382 result = thermal_add_hwmon_sysfs(tz);
1388 mutex_lock(&tz->lock);
1389 list_add_tail(&tz->node, &thermal_tz_list);
1390 mutex_unlock(&tz->lock);
1394 bind_tz(tz);
1396 thermal_zone_device_init(tz);
1398 if (atomic_cmpxchg(&tz->need_update, 1, 0))
1399 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
1401 thermal_notify_tz_create(tz);
1403 thermal_debug_tz_add(tz);
1405 return tz;
1408 device_del(&tz->device);
1410 put_device(&tz->device);
1414 kfree(tz->tzp);
1416 kfree(tz);
1458 * @tz: the thermal zone device to remove
1460 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1465 if (!tz)
1468 thermal_debug_tz_remove(tz);
1472 if (pos == tz)
1474 if (pos != tz) {
1480 mutex_lock(&tz->lock);
1481 list_del(&tz->node);
1482 mutex_unlock(&tz->lock);
1486 if (tz->ops.unbind)
1487 tz->ops.unbind(tz, cdev);
1491 cancel_delayed_work_sync(&tz->poll_queue);
1493 thermal_set_governor(tz, NULL);
1495 thermal_remove_hwmon_sysfs(tz);
1496 ida_free(&thermal_tz_ida, tz->id);
1497 ida_destroy(&tz->ida);
1499 device_del(&tz->device);
1501 kfree(tz->tzp);
1503 put_device(&tz->device);
1505 thermal_notify_tz_delete(tz);
1507 wait_for_completion(&tz->removal);
1508 kfree(tz);
1552 struct thermal_zone_device *tz;
1554 tz = container_of(work, struct thermal_zone_device, poll_queue.work);
1556 mutex_lock(&tz->lock);
1558 tz->suspended = false;
1560 thermal_zone_device_init(tz);
1561 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
1563 mutex_unlock(&tz->lock);
1569 struct thermal_zone_device *tz;
1577 list_for_each_entry(tz, &thermal_tz_list, node) {
1578 mutex_lock(&tz->lock);
1580 tz->suspended = true;
1582 mutex_unlock(&tz->lock);
1592 list_for_each_entry(tz, &thermal_tz_list, node) {
1593 mutex_lock(&tz->lock);
1595 cancel_delayed_work(&tz->poll_queue);
1602 INIT_DELAYED_WORK(&tz->poll_queue,
1606 &tz->poll_queue, 0);
1608 mutex_unlock(&tz->lock);