Lines Matching refs:tz
73 static void bind_previous_governor(struct thermal_zone_device *tz, in bind_previous_governor() argument
76 if (tz->governor && tz->governor->bind_to_tz) { in bind_previous_governor()
77 if (tz->governor->bind_to_tz(tz)) { in bind_previous_governor()
78 dev_err(&tz->device, in bind_previous_governor()
80 failed_gov_name, tz->governor->name, tz->type); in bind_previous_governor()
81 tz->governor = NULL; in bind_previous_governor()
95 static int thermal_set_governor(struct thermal_zone_device *tz, in thermal_set_governor() argument
100 if (tz->governor && tz->governor->unbind_from_tz) in thermal_set_governor()
101 tz->governor->unbind_from_tz(tz); in thermal_set_governor()
104 ret = new_gov->bind_to_tz(tz); in thermal_set_governor()
106 bind_previous_governor(tz, new_gov->name); in thermal_set_governor()
112 tz->governor = new_gov; in thermal_set_governor()
197 int thermal_zone_device_set_policy(struct thermal_zone_device *tz, in thermal_zone_device_set_policy() argument
204 mutex_lock(&tz->lock); in thermal_zone_device_set_policy()
210 ret = thermal_set_governor(tz, gov); in thermal_zone_device_set_policy()
213 mutex_unlock(&tz->lock); in thermal_zone_device_set_policy()
216 thermal_notify_tz_gov_change(tz->id, policy); in thermal_zone_device_set_policy()
288 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, in thermal_zone_device_set_polling() argument
293 &tz->poll_queue, delay); in thermal_zone_device_set_polling()
295 cancel_delayed_work(&tz->poll_queue); in thermal_zone_device_set_polling()
298 static void monitor_thermal_zone(struct thermal_zone_device *tz) in monitor_thermal_zone() argument
300 if (tz->mode != THERMAL_DEVICE_ENABLED) in monitor_thermal_zone()
301 thermal_zone_device_set_polling(tz, 0); in monitor_thermal_zone()
302 else if (tz->passive) in monitor_thermal_zone()
303 thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies); in monitor_thermal_zone()
304 else if (tz->polling_delay_jiffies) in monitor_thermal_zone()
305 thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); in monitor_thermal_zone()
308 static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip) in handle_non_critical_trips() argument
310 tz->governor ? tz->governor->throttle(tz, trip) : in handle_non_critical_trips()
311 def_governor->throttle(tz, trip); in handle_non_critical_trips()
314 void thermal_zone_device_critical(struct thermal_zone_device *tz) in thermal_zone_device_critical() argument
322 dev_emerg(&tz->device, "%s: critical temperature reached, " in thermal_zone_device_critical()
323 "shutting down\n", tz->type); in thermal_zone_device_critical()
329 static void handle_critical_trips(struct thermal_zone_device *tz, in handle_critical_trips() argument
333 if (trip_temp <= 0 || tz->temperature < trip_temp) in handle_critical_trips()
336 trace_thermal_zone_trip(tz, trip, trip_type); in handle_critical_trips()
338 if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot) in handle_critical_trips()
339 tz->ops->hot(tz); in handle_critical_trips()
341 tz->ops->critical(tz); in handle_critical_trips()
344 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) in handle_thermal_trip() argument
350 if (test_bit(trip, &tz->trips_disabled)) in handle_thermal_trip()
353 tz->ops->get_trip_temp(tz, trip, &trip_temp); in handle_thermal_trip()
354 tz->ops->get_trip_type(tz, trip, &type); in handle_thermal_trip()
355 if (tz->ops->get_trip_hyst) in handle_thermal_trip()
356 tz->ops->get_trip_hyst(tz, trip, &hyst); in handle_thermal_trip()
358 if (tz->last_temperature != THERMAL_TEMP_INVALID) { in handle_thermal_trip()
359 if (tz->last_temperature < trip_temp && in handle_thermal_trip()
360 tz->temperature >= trip_temp) in handle_thermal_trip()
361 thermal_notify_tz_trip_up(tz->id, trip, in handle_thermal_trip()
362 tz->temperature); in handle_thermal_trip()
363 if (tz->last_temperature >= trip_temp && in handle_thermal_trip()
364 tz->temperature < (trip_temp - hyst)) in handle_thermal_trip()
365 thermal_notify_tz_trip_down(tz->id, trip, in handle_thermal_trip()
366 tz->temperature); in handle_thermal_trip()
370 handle_critical_trips(tz, trip, trip_temp, type); in handle_thermal_trip()
372 handle_non_critical_trips(tz, trip); in handle_thermal_trip()
375 static void update_temperature(struct thermal_zone_device *tz) in update_temperature() argument
379 ret = __thermal_zone_get_temp(tz, &temp); in update_temperature()
382 dev_warn(&tz->device, in update_temperature()
388 tz->last_temperature = tz->temperature; in update_temperature()
389 tz->temperature = temp; in update_temperature()
391 trace_thermal_temperature(tz); in update_temperature()
393 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
396 static void thermal_zone_device_init(struct thermal_zone_device *tz) in thermal_zone_device_init() argument
399 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
400 tz->prev_low_trip = -INT_MAX; in thermal_zone_device_init()
401 tz->prev_high_trip = INT_MAX; in thermal_zone_device_init()
402 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
406 static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, in thermal_zone_device_set_mode() argument
411 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
414 if (mode == tz->mode) { in thermal_zone_device_set_mode()
415 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
420 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
421 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
424 tz->mode = mode; in thermal_zone_device_set_mode()
426 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
428 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_set_mode()
431 thermal_notify_tz_enable(tz->id); in thermal_zone_device_set_mode()
433 thermal_notify_tz_disable(tz->id); in thermal_zone_device_set_mode()
438 int thermal_zone_device_enable(struct thermal_zone_device *tz) in thermal_zone_device_enable() argument
440 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); in thermal_zone_device_enable()
444 int thermal_zone_device_disable(struct thermal_zone_device *tz) in thermal_zone_device_disable() argument
446 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); in thermal_zone_device_disable()
450 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) in thermal_zone_device_is_enabled() argument
452 lockdep_assert_held(&tz->lock); in thermal_zone_device_is_enabled()
454 return tz->mode == THERMAL_DEVICE_ENABLED; in thermal_zone_device_is_enabled()
457 void thermal_zone_device_update(struct thermal_zone_device *tz, in thermal_zone_device_update() argument
465 if (WARN_ONCE(!tz->ops->get_temp, "'%s' must not be called without " in thermal_zone_device_update()
469 mutex_lock(&tz->lock); in thermal_zone_device_update()
471 if (!thermal_zone_device_is_enabled(tz)) in thermal_zone_device_update()
474 update_temperature(tz); in thermal_zone_device_update()
476 __thermal_zone_set_trips(tz); in thermal_zone_device_update()
478 tz->notify_event = event; in thermal_zone_device_update()
480 for (count = 0; count < tz->num_trips; count++) in thermal_zone_device_update()
481 handle_thermal_trip(tz, count); in thermal_zone_device_update()
483 monitor_thermal_zone(tz); in thermal_zone_device_update()
485 mutex_unlock(&tz->lock); in thermal_zone_device_update()
491 struct thermal_zone_device *tz = container_of(work, struct in thermal_zone_device_check() local
494 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_check()
534 struct thermal_zone_device *tz; in for_each_thermal_zone() local
538 list_for_each_entry(tz, &thermal_tz_list, node) { in for_each_thermal_zone()
539 ret = cb(tz, data); in for_each_thermal_zone()
550 struct thermal_zone_device *tz, *match = NULL; in thermal_zone_get_by_id() local
553 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_zone_get_by_id()
554 if (tz->id == id) { in thermal_zone_get_by_id()
555 match = tz; in thermal_zone_get_by_id()
596 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_bind_cooling_device() argument
609 if (trip >= tz->num_trips || trip < 0) in thermal_zone_bind_cooling_device()
613 if (pos1 == tz) in thermal_zone_bind_cooling_device()
621 if (tz != pos1 || cdev != pos2) in thermal_zone_bind_cooling_device()
638 dev->tz = tz; in thermal_zone_bind_cooling_device()
646 result = ida_alloc(&tz->ida, GFP_KERNEL); in thermal_zone_bind_cooling_device()
653 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
662 result = device_create_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
672 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
676 mutex_lock(&tz->lock); in thermal_zone_bind_cooling_device()
678 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_bind_cooling_device()
679 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_bind_cooling_device()
684 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_zone_bind_cooling_device()
686 atomic_set(&tz->need_update, 1); in thermal_zone_bind_cooling_device()
689 mutex_unlock(&tz->lock); in thermal_zone_bind_cooling_device()
694 device_remove_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
696 device_remove_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
698 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
700 ida_free(&tz->ida, dev->id); in thermal_zone_bind_cooling_device()
721 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_unbind_cooling_device() argument
727 mutex_lock(&tz->lock); in thermal_zone_unbind_cooling_device()
729 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_zone_unbind_cooling_device()
730 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_unbind_cooling_device()
734 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
739 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
744 device_remove_file(&tz->device, &pos->weight_attr); in thermal_zone_unbind_cooling_device()
745 device_remove_file(&tz->device, &pos->attr); in thermal_zone_unbind_cooling_device()
746 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_zone_unbind_cooling_device()
747 ida_free(&tz->ida, pos->id); in thermal_zone_unbind_cooling_device()
755 struct thermal_zone_device *tz; in thermal_release() local
760 tz = to_thermal_zone(dev); in thermal_release()
761 thermal_zone_destroy_device_groups(tz); in thermal_release()
762 kfree(tz); in thermal_release()
776 void print_bind_err_msg(struct thermal_zone_device *tz, in print_bind_err_msg() argument
779 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
780 tz->type, cdev->type, ret); in print_bind_err_msg()
783 static void __bind(struct thermal_zone_device *tz, int mask, in __bind() argument
790 for (i = 0; i < tz->num_trips; i++) { in __bind()
800 ret = thermal_zone_bind_cooling_device(tz, i, cdev, in __bind()
804 print_bind_err_msg(tz, cdev, ret); in __bind()
1031 static void __unbind(struct thermal_zone_device *tz, int mask, in __unbind() argument
1036 for (i = 0; i < tz->num_trips; i++) in __unbind()
1038 thermal_zone_unbind_cooling_device(tz, i, cdev); in __unbind()
1052 struct thermal_zone_device *tz; in thermal_cooling_device_unregister() local
1070 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_cooling_device_unregister()
1071 if (tz->ops->unbind) { in thermal_cooling_device_unregister()
1072 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1076 if (!tz->tzp || !tz->tzp->tbp) in thermal_cooling_device_unregister()
1079 tzp = tz->tzp; in thermal_cooling_device_unregister()
1082 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_cooling_device_unregister()
1098 static void bind_tz(struct thermal_zone_device *tz) in bind_tz() argument
1102 const struct thermal_zone_params *tzp = tz->tzp; in bind_tz()
1104 if (!tzp && !tz->ops->bind) in bind_tz()
1110 if (tz->ops->bind) { in bind_tz()
1112 ret = tz->ops->bind(tz, pos); in bind_tz()
1114 print_bind_err_msg(tz, pos, ret); in bind_tz()
1126 if (tzp->tbp[i].match(tz, pos)) in bind_tz()
1129 __bind(tz, tzp->tbp[i].trip_mask, pos, in bind_tz()
1176 struct thermal_zone_device *tz; in thermal_zone_device_register_with_trips() local
1221 tz = kzalloc(sizeof(*tz), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1222 if (!tz) in thermal_zone_device_register_with_trips()
1225 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register_with_trips()
1226 ida_init(&tz->ida); in thermal_zone_device_register_with_trips()
1227 mutex_init(&tz->lock); in thermal_zone_device_register_with_trips()
1234 tz->id = id; in thermal_zone_device_register_with_trips()
1235 strscpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register_with_trips()
1237 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register_with_trips()
1244 tz->ops = ops; in thermal_zone_device_register_with_trips()
1245 tz->tzp = tzp; in thermal_zone_device_register_with_trips()
1246 tz->device.class = &thermal_class; in thermal_zone_device_register_with_trips()
1247 tz->devdata = devdata; in thermal_zone_device_register_with_trips()
1248 tz->trips = trips; in thermal_zone_device_register_with_trips()
1249 tz->num_trips = num_trips; in thermal_zone_device_register_with_trips()
1251 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); in thermal_zone_device_register_with_trips()
1252 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay); in thermal_zone_device_register_with_trips()
1256 result = thermal_zone_create_device_groups(tz, mask); in thermal_zone_device_register_with_trips()
1261 atomic_set(&tz->need_update, 1); in thermal_zone_device_register_with_trips()
1263 result = device_register(&tz->device); in thermal_zone_device_register_with_trips()
1268 if (tz->ops->get_trip_type(tz, count, &trip_type) || in thermal_zone_device_register_with_trips()
1269 tz->ops->get_trip_temp(tz, count, &trip_temp) || in thermal_zone_device_register_with_trips()
1271 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register_with_trips()
1277 if (tz->tzp) in thermal_zone_device_register_with_trips()
1278 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register_with_trips()
1282 result = thermal_set_governor(tz, governor); in thermal_zone_device_register_with_trips()
1290 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register_with_trips()
1291 result = thermal_add_hwmon_sysfs(tz); in thermal_zone_device_register_with_trips()
1297 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register_with_trips()
1301 bind_tz(tz); in thermal_zone_device_register_with_trips()
1303 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_register_with_trips()
1305 thermal_zone_device_init(tz); in thermal_zone_device_register_with_trips()
1307 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register_with_trips()
1308 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_register_with_trips()
1310 thermal_notify_tz_create(tz->id, tz->type); in thermal_zone_device_register_with_trips()
1312 return tz; in thermal_zone_device_register_with_trips()
1315 device_del(&tz->device); in thermal_zone_device_register_with_trips()
1317 put_device(&tz->device); in thermal_zone_device_register_with_trips()
1318 tz = NULL; in thermal_zone_device_register_with_trips()
1322 kfree(tz); in thermal_zone_device_register_with_trips()
1342 void thermal_zone_device_unregister(struct thermal_zone_device *tz) in thermal_zone_device_unregister() argument
1349 if (!tz) in thermal_zone_device_unregister()
1352 tzp = tz->tzp; in thermal_zone_device_unregister()
1353 tz_id = tz->id; in thermal_zone_device_unregister()
1357 if (pos == tz) in thermal_zone_device_unregister()
1359 if (pos != tz) { in thermal_zone_device_unregister()
1364 list_del(&tz->node); in thermal_zone_device_unregister()
1368 if (tz->ops->unbind) { in thermal_zone_device_unregister()
1369 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1378 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_zone_device_unregister()
1386 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1388 thermal_set_governor(tz, NULL); in thermal_zone_device_unregister()
1390 thermal_remove_hwmon_sysfs(tz); in thermal_zone_device_unregister()
1391 ida_free(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1392 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1393 mutex_destroy(&tz->lock); in thermal_zone_device_unregister()
1394 device_unregister(&tz->device); in thermal_zone_device_unregister()
1441 struct thermal_zone_device *tz; in thermal_pm_notify() local
1453 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1454 thermal_zone_device_init(tz); in thermal_pm_notify()
1455 thermal_zone_device_update(tz, in thermal_pm_notify()