Lines Matching full:tz
65 * @tz: a valid pointer to a struct thermal_zone_device
71 static void bind_previous_governor(struct thermal_zone_device *tz, in bind_previous_governor() argument
74 if (tz->governor && tz->governor->bind_to_tz) { in bind_previous_governor()
75 if (tz->governor->bind_to_tz(tz)) { in bind_previous_governor()
76 dev_err(&tz->device, in bind_previous_governor()
78 failed_gov_name, tz->governor->name, tz->type); in bind_previous_governor()
79 tz->governor = NULL; in bind_previous_governor()
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, in thermal_set_governor() argument
98 if (tz->governor && tz->governor->unbind_from_tz) in thermal_set_governor()
99 tz->governor->unbind_from_tz(tz); in thermal_set_governor()
102 ret = new_gov->bind_to_tz(tz); in thermal_set_governor()
104 bind_previous_governor(tz, new_gov->name); in thermal_set_governor()
110 tz->governor = new_gov; in thermal_set_governor()
144 * only thermal zones with specified tz->tzp->governor_name in thermal_register_governor()
145 * may run with tz->govenor unset in thermal_register_governor()
195 int thermal_zone_device_set_policy(struct thermal_zone_device *tz, in thermal_zone_device_set_policy() argument
202 mutex_lock(&tz->lock); in thermal_zone_device_set_policy()
208 ret = thermal_set_governor(tz, gov); in thermal_zone_device_set_policy()
211 mutex_unlock(&tz->lock); in thermal_zone_device_set_policy()
214 thermal_notify_tz_gov_change(tz, policy); in thermal_zone_device_set_policy()
285 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, in thermal_zone_device_set_polling() argument
290 &tz->poll_queue, delay); in thermal_zone_device_set_polling()
292 cancel_delayed_work(&tz->poll_queue); in thermal_zone_device_set_polling()
295 static void monitor_thermal_zone(struct thermal_zone_device *tz) in monitor_thermal_zone() argument
297 if (tz->mode != THERMAL_DEVICE_ENABLED) in monitor_thermal_zone()
298 thermal_zone_device_set_polling(tz, 0); in monitor_thermal_zone()
299 else if (tz->passive) in monitor_thermal_zone()
300 thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies); in monitor_thermal_zone()
301 else if (tz->polling_delay_jiffies) in monitor_thermal_zone()
302 thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); in monitor_thermal_zone()
305 static void handle_non_critical_trips(struct thermal_zone_device *tz, in handle_non_critical_trips() argument
308 tz->governor ? tz->governor->throttle(tz, trip) : in handle_non_critical_trips()
309 def_governor->throttle(tz, trip); in handle_non_critical_trips()
312 void thermal_governor_update_tz(struct thermal_zone_device *tz, in thermal_governor_update_tz() argument
315 if (!tz->governor || !tz->governor->update_tz) in thermal_governor_update_tz()
318 tz->governor->update_tz(tz, reason); in thermal_governor_update_tz()
321 static void thermal_zone_device_halt(struct thermal_zone_device *tz, bool shutdown) in thermal_zone_device_halt() argument
330 dev_emerg(&tz->device, "%s: critical temperature reached\n", tz->type); in thermal_zone_device_halt()
338 void thermal_zone_device_critical(struct thermal_zone_device *tz) in thermal_zone_device_critical() argument
340 thermal_zone_device_halt(tz, true); in thermal_zone_device_critical()
344 void thermal_zone_device_critical_reboot(struct thermal_zone_device *tz) in thermal_zone_device_critical_reboot() argument
346 thermal_zone_device_halt(tz, false); in thermal_zone_device_critical_reboot()
349 static void handle_critical_trips(struct thermal_zone_device *tz, in handle_critical_trips() argument
353 if (trip->temperature <= 0 || tz->temperature < trip->temperature) in handle_critical_trips()
356 trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type); in handle_critical_trips()
359 tz->ops->critical(tz); in handle_critical_trips()
360 else if (tz->ops->hot) in handle_critical_trips()
361 tz->ops->hot(tz); in handle_critical_trips()
364 static void handle_thermal_trip(struct thermal_zone_device *tz, in handle_thermal_trip() argument
370 if (tz->last_temperature == THERMAL_TEMP_INVALID) { in handle_thermal_trip()
373 if (tz->temperature >= trip->threshold) in handle_thermal_trip()
375 } else if (tz->last_temperature < trip->threshold) { in handle_thermal_trip()
383 if (tz->temperature >= trip->temperature) { in handle_thermal_trip()
384 thermal_notify_tz_trip_up(tz, trip); in handle_thermal_trip()
385 thermal_debug_tz_trip_up(tz, trip); in handle_thermal_trip()
401 if (tz->temperature < trip->temperature - trip->hysteresis) { in handle_thermal_trip()
402 thermal_notify_tz_trip_down(tz, trip); in handle_thermal_trip()
403 thermal_debug_tz_trip_down(tz, trip); in handle_thermal_trip()
411 handle_critical_trips(tz, trip); in handle_thermal_trip()
413 handle_non_critical_trips(tz, trip); in handle_thermal_trip()
416 static void update_temperature(struct thermal_zone_device *tz) in update_temperature() argument
420 ret = __thermal_zone_get_temp(tz, &temp); in update_temperature()
423 dev_warn(&tz->device, in update_temperature()
429 tz->last_temperature = tz->temperature; in update_temperature()
430 tz->temperature = temp; in update_temperature()
432 trace_thermal_temperature(tz); in update_temperature()
434 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
435 thermal_debug_update_temp(tz); in update_temperature()
440 struct thermal_zone_device *tz = container_of(work, struct in thermal_zone_device_check() local
443 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_check()
446 static void thermal_zone_device_init(struct thermal_zone_device *tz) in thermal_zone_device_init() argument
450 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_init()
452 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
453 tz->prev_low_trip = -INT_MAX; in thermal_zone_device_init()
454 tz->prev_high_trip = INT_MAX; in thermal_zone_device_init()
455 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
459 void __thermal_zone_device_update(struct thermal_zone_device *tz, in __thermal_zone_device_update() argument
464 if (tz->suspended) in __thermal_zone_device_update()
467 if (!thermal_zone_device_is_enabled(tz)) in __thermal_zone_device_update()
470 update_temperature(tz); in __thermal_zone_device_update()
472 __thermal_zone_set_trips(tz); in __thermal_zone_device_update()
474 tz->notify_event = event; in __thermal_zone_device_update()
476 for_each_trip(tz, trip) in __thermal_zone_device_update()
477 handle_thermal_trip(tz, trip); in __thermal_zone_device_update()
479 monitor_thermal_zone(tz); in __thermal_zone_device_update()
482 static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, in thermal_zone_device_set_mode() argument
487 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
490 if (mode == tz->mode) { in thermal_zone_device_set_mode()
491 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
496 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
497 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
500 tz->mode = mode; in thermal_zone_device_set_mode()
502 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_set_mode()
504 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
507 thermal_notify_tz_enable(tz); in thermal_zone_device_set_mode()
509 thermal_notify_tz_disable(tz); in thermal_zone_device_set_mode()
514 int thermal_zone_device_enable(struct thermal_zone_device *tz) in thermal_zone_device_enable() argument
516 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); in thermal_zone_device_enable()
520 int thermal_zone_device_disable(struct thermal_zone_device *tz) in thermal_zone_device_disable() argument
522 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); in thermal_zone_device_disable()
526 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) in thermal_zone_device_is_enabled() argument
528 lockdep_assert_held(&tz->lock); in thermal_zone_device_is_enabled()
530 return tz->mode == THERMAL_DEVICE_ENABLED; in thermal_zone_device_is_enabled()
533 static bool thermal_zone_is_present(struct thermal_zone_device *tz) in thermal_zone_is_present() argument
535 return !list_empty(&tz->node); in thermal_zone_is_present()
538 void thermal_zone_device_update(struct thermal_zone_device *tz, in thermal_zone_device_update() argument
541 mutex_lock(&tz->lock); in thermal_zone_device_update()
542 if (thermal_zone_is_present(tz)) in thermal_zone_device_update()
543 __thermal_zone_device_update(tz, event); in thermal_zone_device_update()
544 mutex_unlock(&tz->lock); in thermal_zone_device_update()
585 struct thermal_zone_device *tz; in for_each_thermal_zone() local
589 list_for_each_entry(tz, &thermal_tz_list, node) { in for_each_thermal_zone()
590 ret = cb(tz, data); in for_each_thermal_zone()
601 struct thermal_zone_device *tz, *match = NULL; in thermal_zone_get_by_id() local
604 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_zone_get_by_id()
605 if (tz->id == id) { in thermal_zone_get_by_id()
606 match = tz; in thermal_zone_get_by_id()
627 * @tz: pointer to struct thermal_zone_device
646 int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz, in thermal_bind_cdev_to_trip() argument
660 if (pos1 == tz) in thermal_bind_cdev_to_trip()
668 if (tz != pos1 || cdev != pos2) in thermal_bind_cdev_to_trip()
687 dev->tz = tz; in thermal_bind_cdev_to_trip()
696 result = ida_alloc(&tz->ida, GFP_KERNEL); in thermal_bind_cdev_to_trip()
703 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_bind_cdev_to_trip()
713 result = device_create_file(&tz->device, &dev->attr); in thermal_bind_cdev_to_trip()
724 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_bind_cdev_to_trip()
728 mutex_lock(&tz->lock); in thermal_bind_cdev_to_trip()
730 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_bind_cdev_to_trip()
731 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_bind_cdev_to_trip()
736 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_bind_cdev_to_trip()
738 atomic_set(&tz->need_update, 1); in thermal_bind_cdev_to_trip()
740 thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV); in thermal_bind_cdev_to_trip()
743 mutex_unlock(&tz->lock); in thermal_bind_cdev_to_trip()
748 device_remove_file(&tz->device, &dev->weight_attr); in thermal_bind_cdev_to_trip()
750 device_remove_file(&tz->device, &dev->attr); in thermal_bind_cdev_to_trip()
752 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_bind_cdev_to_trip()
754 ida_free(&tz->ida, dev->id); in thermal_bind_cdev_to_trip()
761 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_bind_cooling_device() argument
767 if (trip_index < 0 || trip_index >= tz->num_trips) in thermal_zone_bind_cooling_device()
770 return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index], cdev, in thermal_zone_bind_cooling_device()
777 * @tz: pointer to a struct thermal_zone_device.
787 int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz, in thermal_unbind_cdev_from_trip() argument
793 mutex_lock(&tz->lock); in thermal_unbind_cdev_from_trip()
795 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_unbind_cdev_from_trip()
796 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_unbind_cdev_from_trip()
800 thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV); in thermal_unbind_cdev_from_trip()
803 mutex_unlock(&tz->lock); in thermal_unbind_cdev_from_trip()
808 mutex_unlock(&tz->lock); in thermal_unbind_cdev_from_trip()
813 device_remove_file(&tz->device, &pos->weight_attr); in thermal_unbind_cdev_from_trip()
814 device_remove_file(&tz->device, &pos->attr); in thermal_unbind_cdev_from_trip()
815 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_unbind_cdev_from_trip()
816 ida_free(&tz->ida, pos->id); in thermal_unbind_cdev_from_trip()
822 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_unbind_cooling_device() argument
826 if (trip_index < 0 || trip_index >= tz->num_trips) in thermal_zone_unbind_cooling_device()
829 return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index], cdev); in thermal_zone_unbind_cooling_device()
835 struct thermal_zone_device *tz; in thermal_release() local
840 tz = to_thermal_zone(dev); in thermal_release()
841 thermal_zone_destroy_device_groups(tz); in thermal_release()
842 mutex_destroy(&tz->lock); in thermal_release()
843 complete(&tz->removal); in thermal_release()
857 void print_bind_err_msg(struct thermal_zone_device *tz, in print_bind_err_msg() argument
860 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
861 tz->type, cdev->type, ret); in print_bind_err_msg()
1169 struct thermal_zone_device *tz; in thermal_cooling_device_unregister() local
1186 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_cooling_device_unregister()
1187 if (tz->ops->unbind) in thermal_cooling_device_unregister()
1188 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1197 static void bind_tz(struct thermal_zone_device *tz) in bind_tz() argument
1202 if (!tz->ops->bind) in bind_tz()
1208 ret = tz->ops->bind(tz, pos); in bind_tz()
1210 print_bind_err_msg(tz, pos, ret); in bind_tz()
1223 int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp) in thermal_zone_get_crit_temp() argument
1227 if (tz->ops->get_crit_temp) in thermal_zone_get_crit_temp()
1228 return tz->ops->get_crit_temp(tz, temp); in thermal_zone_get_crit_temp()
1230 if (!tz->trips) in thermal_zone_get_crit_temp()
1233 mutex_lock(&tz->lock); in thermal_zone_get_crit_temp()
1235 for (i = 0; i < tz->num_trips; i++) { in thermal_zone_get_crit_temp()
1236 if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) { in thermal_zone_get_crit_temp()
1237 *temp = tz->trips[i].temperature; in thermal_zone_get_crit_temp()
1243 mutex_unlock(&tz->lock); in thermal_zone_get_crit_temp()
1280 struct thermal_zone_device *tz; in thermal_zone_device_register_with_trips() local
1325 tz = kzalloc(sizeof(*tz), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1326 if (!tz) in thermal_zone_device_register_with_trips()
1330 tz->tzp = kmemdup(tzp, sizeof(*tzp), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1331 if (!tz->tzp) { in thermal_zone_device_register_with_trips()
1337 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register_with_trips()
1338 INIT_LIST_HEAD(&tz->node); in thermal_zone_device_register_with_trips()
1339 ida_init(&tz->ida); in thermal_zone_device_register_with_trips()
1340 mutex_init(&tz->lock); in thermal_zone_device_register_with_trips()
1341 init_completion(&tz->removal); in thermal_zone_device_register_with_trips()
1348 tz->id = id; in thermal_zone_device_register_with_trips()
1349 strscpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register_with_trips()
1354 tz->ops = ops; in thermal_zone_device_register_with_trips()
1355 tz->device.class = thermal_class; in thermal_zone_device_register_with_trips()
1356 tz->devdata = devdata; in thermal_zone_device_register_with_trips()
1357 tz->trips = trips; in thermal_zone_device_register_with_trips()
1358 tz->num_trips = num_trips; in thermal_zone_device_register_with_trips()
1360 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); in thermal_zone_device_register_with_trips()
1361 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay); in thermal_zone_device_register_with_trips()
1365 result = thermal_zone_create_device_groups(tz, mask); in thermal_zone_device_register_with_trips()
1370 atomic_set(&tz->need_update, 1); in thermal_zone_device_register_with_trips()
1372 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register_with_trips()
1374 thermal_zone_destroy_device_groups(tz); in thermal_zone_device_register_with_trips()
1377 result = device_register(&tz->device); in thermal_zone_device_register_with_trips()
1384 if (tz->tzp) in thermal_zone_device_register_with_trips()
1385 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register_with_trips()
1389 result = thermal_set_governor(tz, governor); in thermal_zone_device_register_with_trips()
1397 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register_with_trips()
1398 result = thermal_add_hwmon_sysfs(tz); in thermal_zone_device_register_with_trips()
1404 mutex_lock(&tz->lock); in thermal_zone_device_register_with_trips()
1405 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register_with_trips()
1406 mutex_unlock(&tz->lock); in thermal_zone_device_register_with_trips()
1410 bind_tz(tz); in thermal_zone_device_register_with_trips()
1412 thermal_zone_device_init(tz); in thermal_zone_device_register_with_trips()
1414 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register_with_trips()
1415 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_register_with_trips()
1417 thermal_notify_tz_create(tz); in thermal_zone_device_register_with_trips()
1419 thermal_debug_tz_add(tz); in thermal_zone_device_register_with_trips()
1421 return tz; in thermal_zone_device_register_with_trips()
1424 device_del(&tz->device); in thermal_zone_device_register_with_trips()
1426 put_device(&tz->device); in thermal_zone_device_register_with_trips()
1430 kfree(tz->tzp); in thermal_zone_device_register_with_trips()
1432 kfree(tz); in thermal_zone_device_register_with_trips()
1474 * @tz: the thermal zone device to remove
1476 void thermal_zone_device_unregister(struct thermal_zone_device *tz) in thermal_zone_device_unregister() argument
1481 if (!tz) in thermal_zone_device_unregister()
1484 thermal_debug_tz_remove(tz); in thermal_zone_device_unregister()
1488 if (pos == tz) in thermal_zone_device_unregister()
1490 if (pos != tz) { in thermal_zone_device_unregister()
1496 mutex_lock(&tz->lock); in thermal_zone_device_unregister()
1497 list_del(&tz->node); in thermal_zone_device_unregister()
1498 mutex_unlock(&tz->lock); in thermal_zone_device_unregister()
1502 if (tz->ops->unbind) in thermal_zone_device_unregister()
1503 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1507 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1509 thermal_set_governor(tz, NULL); in thermal_zone_device_unregister()
1511 thermal_remove_hwmon_sysfs(tz); in thermal_zone_device_unregister()
1512 ida_free(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1513 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1515 device_del(&tz->device); in thermal_zone_device_unregister()
1517 kfree(tz->tzp); in thermal_zone_device_unregister()
1519 put_device(&tz->device); in thermal_zone_device_unregister()
1521 thermal_notify_tz_delete(tz); in thermal_zone_device_unregister()
1523 wait_for_completion(&tz->removal); in thermal_zone_device_unregister()
1524 kfree(tz); in thermal_zone_device_unregister()
1568 struct thermal_zone_device *tz; in thermal_zone_device_resume() local
1570 tz = container_of(work, struct thermal_zone_device, poll_queue.work); in thermal_zone_device_resume()
1572 mutex_lock(&tz->lock); in thermal_zone_device_resume()
1574 tz->suspended = false; in thermal_zone_device_resume()
1576 thermal_zone_device_init(tz); in thermal_zone_device_resume()
1577 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_resume()
1579 mutex_unlock(&tz->lock); in thermal_zone_device_resume()
1585 struct thermal_zone_device *tz; in thermal_pm_notify() local
1593 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1594 mutex_lock(&tz->lock); in thermal_pm_notify()
1596 tz->suspended = true; in thermal_pm_notify()
1598 mutex_unlock(&tz->lock); in thermal_pm_notify()
1608 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1609 mutex_lock(&tz->lock); in thermal_pm_notify()
1611 cancel_delayed_work(&tz->poll_queue); in thermal_pm_notify()
1618 INIT_DELAYED_WORK(&tz->poll_queue, in thermal_pm_notify()
1622 &tz->poll_queue, 0); in thermal_pm_notify()
1624 mutex_unlock(&tz->lock); in thermal_pm_notify()