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()
206 if (!device_is_registered(&tz->device)) in thermal_zone_device_set_policy()
213 ret = thermal_set_governor(tz, gov); in thermal_zone_device_set_policy()
216 mutex_unlock(&tz->lock); in thermal_zone_device_set_policy()
219 thermal_notify_tz_gov_change(tz->id, policy); in thermal_zone_device_set_policy()
290 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, in thermal_zone_device_set_polling() argument
295 &tz->poll_queue, delay); in thermal_zone_device_set_polling()
297 cancel_delayed_work(&tz->poll_queue); in thermal_zone_device_set_polling()
300 static void monitor_thermal_zone(struct thermal_zone_device *tz) in monitor_thermal_zone() argument
302 if (tz->mode != THERMAL_DEVICE_ENABLED) in monitor_thermal_zone()
303 thermal_zone_device_set_polling(tz, 0); in monitor_thermal_zone()
304 else if (tz->passive) in monitor_thermal_zone()
305 thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies); in monitor_thermal_zone()
306 else if (tz->polling_delay_jiffies) in monitor_thermal_zone()
307 thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); in monitor_thermal_zone()
310 static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip) in handle_non_critical_trips() argument
312 tz->governor ? tz->governor->throttle(tz, trip) : in handle_non_critical_trips()
313 def_governor->throttle(tz, trip); in handle_non_critical_trips()
316 void thermal_zone_device_critical(struct thermal_zone_device *tz) in thermal_zone_device_critical() argument
324 dev_emerg(&tz->device, "%s: critical temperature reached, " in thermal_zone_device_critical()
325 "shutting down\n", tz->type); in thermal_zone_device_critical()
331 static void handle_critical_trips(struct thermal_zone_device *tz, in handle_critical_trips() argument
335 if (trip_temp <= 0 || tz->temperature < trip_temp) in handle_critical_trips()
338 trace_thermal_zone_trip(tz, trip, trip_type); in handle_critical_trips()
340 if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot) in handle_critical_trips()
341 tz->ops->hot(tz); in handle_critical_trips()
343 tz->ops->critical(tz); in handle_critical_trips()
346 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip_id) in handle_thermal_trip() argument
351 if (test_bit(trip_id, &tz->trips_disabled)) in handle_thermal_trip()
354 __thermal_zone_get_trip(tz, trip_id, &trip); in handle_thermal_trip()
356 if (tz->last_temperature != THERMAL_TEMP_INVALID) { in handle_thermal_trip()
357 if (tz->last_temperature < trip.temperature && in handle_thermal_trip()
358 tz->temperature >= trip.temperature) in handle_thermal_trip()
359 thermal_notify_tz_trip_up(tz->id, trip_id, in handle_thermal_trip()
360 tz->temperature); in handle_thermal_trip()
361 if (tz->last_temperature >= trip.temperature && in handle_thermal_trip()
362 tz->temperature < (trip.temperature - trip.hysteresis)) in handle_thermal_trip()
363 thermal_notify_tz_trip_down(tz->id, trip_id, in handle_thermal_trip()
364 tz->temperature); in handle_thermal_trip()
368 handle_critical_trips(tz, trip_id, trip.temperature, trip.type); in handle_thermal_trip()
370 handle_non_critical_trips(tz, trip_id); in handle_thermal_trip()
373 static void update_temperature(struct thermal_zone_device *tz) in update_temperature() argument
377 ret = __thermal_zone_get_temp(tz, &temp); in update_temperature()
380 dev_warn(&tz->device, in update_temperature()
386 tz->last_temperature = tz->temperature; in update_temperature()
387 tz->temperature = temp; in update_temperature()
389 trace_thermal_temperature(tz); in update_temperature()
391 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
394 static void thermal_zone_device_init(struct thermal_zone_device *tz) in thermal_zone_device_init() argument
397 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
398 tz->prev_low_trip = -INT_MAX; in thermal_zone_device_init()
399 tz->prev_high_trip = INT_MAX; in thermal_zone_device_init()
400 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
404 void __thermal_zone_device_update(struct thermal_zone_device *tz, in __thermal_zone_device_update() argument
412 if (WARN_ONCE(!tz->ops->get_temp, in __thermal_zone_device_update()
417 if (!thermal_zone_device_is_enabled(tz)) in __thermal_zone_device_update()
420 update_temperature(tz); in __thermal_zone_device_update()
422 __thermal_zone_set_trips(tz); in __thermal_zone_device_update()
424 tz->notify_event = event; in __thermal_zone_device_update()
426 for (count = 0; count < tz->num_trips; count++) in __thermal_zone_device_update()
427 handle_thermal_trip(tz, count); in __thermal_zone_device_update()
429 monitor_thermal_zone(tz); in __thermal_zone_device_update()
432 static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, in thermal_zone_device_set_mode() argument
437 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
440 if (mode == tz->mode) { in thermal_zone_device_set_mode()
441 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
446 if (!device_is_registered(&tz->device)) { in thermal_zone_device_set_mode()
447 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
452 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
453 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
456 tz->mode = mode; in thermal_zone_device_set_mode()
458 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_set_mode()
460 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
463 thermal_notify_tz_enable(tz->id); in thermal_zone_device_set_mode()
465 thermal_notify_tz_disable(tz->id); in thermal_zone_device_set_mode()
470 int thermal_zone_device_enable(struct thermal_zone_device *tz) in thermal_zone_device_enable() argument
472 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); in thermal_zone_device_enable()
476 int thermal_zone_device_disable(struct thermal_zone_device *tz) in thermal_zone_device_disable() argument
478 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); in thermal_zone_device_disable()
482 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) in thermal_zone_device_is_enabled() argument
484 lockdep_assert_held(&tz->lock); in thermal_zone_device_is_enabled()
486 return tz->mode == THERMAL_DEVICE_ENABLED; in thermal_zone_device_is_enabled()
489 void thermal_zone_device_update(struct thermal_zone_device *tz, in thermal_zone_device_update() argument
492 mutex_lock(&tz->lock); in thermal_zone_device_update()
493 if (device_is_registered(&tz->device)) in thermal_zone_device_update()
494 __thermal_zone_device_update(tz, event); in thermal_zone_device_update()
495 mutex_unlock(&tz->lock); in thermal_zone_device_update()
501 struct thermal_zone_device *tz = container_of(work, struct in thermal_zone_device_check() local
504 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_check()
544 struct thermal_zone_device *tz; in for_each_thermal_zone() local
548 list_for_each_entry(tz, &thermal_tz_list, node) { in for_each_thermal_zone()
549 ret = cb(tz, data); in for_each_thermal_zone()
560 struct thermal_zone_device *tz, *match = NULL; in thermal_zone_get_by_id() local
563 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_zone_get_by_id()
564 if (tz->id == id) { in thermal_zone_get_by_id()
565 match = tz; in thermal_zone_get_by_id()
606 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_bind_cooling_device() argument
618 if (trip >= tz->num_trips || trip < 0) in thermal_zone_bind_cooling_device()
622 if (pos1 == tz) in thermal_zone_bind_cooling_device()
630 if (tz != pos1 || cdev != pos2) in thermal_zone_bind_cooling_device()
643 dev->tz = tz; in thermal_zone_bind_cooling_device()
651 result = ida_alloc(&tz->ida, GFP_KERNEL); in thermal_zone_bind_cooling_device()
658 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
667 result = device_create_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
677 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
681 mutex_lock(&tz->lock); in thermal_zone_bind_cooling_device()
683 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_bind_cooling_device()
684 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_bind_cooling_device()
689 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_zone_bind_cooling_device()
691 atomic_set(&tz->need_update, 1); in thermal_zone_bind_cooling_device()
694 mutex_unlock(&tz->lock); in thermal_zone_bind_cooling_device()
699 device_remove_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
701 device_remove_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
703 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
705 ida_free(&tz->ida, dev->id); in thermal_zone_bind_cooling_device()
726 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_unbind_cooling_device() argument
732 mutex_lock(&tz->lock); in thermal_zone_unbind_cooling_device()
734 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_zone_unbind_cooling_device()
735 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_unbind_cooling_device()
739 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
744 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
749 device_remove_file(&tz->device, &pos->weight_attr); in thermal_zone_unbind_cooling_device()
750 device_remove_file(&tz->device, &pos->attr); in thermal_zone_unbind_cooling_device()
751 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_zone_unbind_cooling_device()
752 ida_free(&tz->ida, pos->id); in thermal_zone_unbind_cooling_device()
760 struct thermal_zone_device *tz; in thermal_release() local
765 tz = to_thermal_zone(dev); in thermal_release()
766 thermal_zone_destroy_device_groups(tz); in thermal_release()
767 mutex_destroy(&tz->lock); in thermal_release()
768 kfree(tz); in thermal_release()
782 void print_bind_err_msg(struct thermal_zone_device *tz, in print_bind_err_msg() argument
785 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
786 tz->type, cdev->type, ret); in print_bind_err_msg()
789 static void __bind(struct thermal_zone_device *tz, int mask, in __bind() argument
796 for (i = 0; i < tz->num_trips; i++) { in __bind()
806 ret = thermal_zone_bind_cooling_device(tz, i, cdev, in __bind()
810 print_bind_err_msg(tz, cdev, ret); in __bind()
1048 static void __unbind(struct thermal_zone_device *tz, int mask, in __unbind() argument
1053 for (i = 0; i < tz->num_trips; i++) in __unbind()
1055 thermal_zone_unbind_cooling_device(tz, i, cdev); in __unbind()
1069 struct thermal_zone_device *tz; in thermal_cooling_device_unregister() local
1087 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_cooling_device_unregister()
1088 if (tz->ops->unbind) { in thermal_cooling_device_unregister()
1089 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1093 if (!tz->tzp || !tz->tzp->tbp) in thermal_cooling_device_unregister()
1096 tzp = tz->tzp; in thermal_cooling_device_unregister()
1099 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_cooling_device_unregister()
1111 static void bind_tz(struct thermal_zone_device *tz) in bind_tz() argument
1115 const struct thermal_zone_params *tzp = tz->tzp; in bind_tz()
1117 if (!tzp && !tz->ops->bind) in bind_tz()
1123 if (tz->ops->bind) { in bind_tz()
1125 ret = tz->ops->bind(tz, pos); in bind_tz()
1127 print_bind_err_msg(tz, pos, ret); in bind_tz()
1139 if (tzp->tbp[i].match(tz, pos)) in bind_tz()
1142 __bind(tz, tzp->tbp[i].trip_mask, pos, in bind_tz()
1158 int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp) in thermal_zone_get_crit_temp() argument
1162 if (tz->ops->get_crit_temp) in thermal_zone_get_crit_temp()
1163 return tz->ops->get_crit_temp(tz, temp); in thermal_zone_get_crit_temp()
1165 if (!tz->trips) in thermal_zone_get_crit_temp()
1168 mutex_lock(&tz->lock); in thermal_zone_get_crit_temp()
1170 for (i = 0; i < tz->num_trips; i++) { in thermal_zone_get_crit_temp()
1171 if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) { in thermal_zone_get_crit_temp()
1172 *temp = tz->trips[i].temperature; in thermal_zone_get_crit_temp()
1178 mutex_unlock(&tz->lock); in thermal_zone_get_crit_temp()
1215 struct thermal_zone_device *tz; in thermal_zone_device_register_with_trips() local
1261 tz = kzalloc(sizeof(*tz), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1262 if (!tz) in thermal_zone_device_register_with_trips()
1265 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register_with_trips()
1266 ida_init(&tz->ida); in thermal_zone_device_register_with_trips()
1267 mutex_init(&tz->lock); in thermal_zone_device_register_with_trips()
1274 tz->id = id; in thermal_zone_device_register_with_trips()
1275 strscpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register_with_trips()
1280 tz->ops = ops; in thermal_zone_device_register_with_trips()
1281 tz->tzp = tzp; in thermal_zone_device_register_with_trips()
1282 tz->device.class = thermal_class; in thermal_zone_device_register_with_trips()
1283 tz->devdata = devdata; in thermal_zone_device_register_with_trips()
1284 tz->trips = trips; in thermal_zone_device_register_with_trips()
1285 tz->num_trips = num_trips; in thermal_zone_device_register_with_trips()
1287 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); in thermal_zone_device_register_with_trips()
1288 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay); in thermal_zone_device_register_with_trips()
1292 result = thermal_zone_create_device_groups(tz, mask); in thermal_zone_device_register_with_trips()
1297 atomic_set(&tz->need_update, 1); in thermal_zone_device_register_with_trips()
1299 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register_with_trips()
1301 thermal_zone_destroy_device_groups(tz); in thermal_zone_device_register_with_trips()
1304 result = device_register(&tz->device); in thermal_zone_device_register_with_trips()
1311 result = thermal_zone_get_trip(tz, count, &trip); in thermal_zone_device_register_with_trips()
1313 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register_with_trips()
1319 if (tz->tzp) in thermal_zone_device_register_with_trips()
1320 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register_with_trips()
1324 result = thermal_set_governor(tz, governor); in thermal_zone_device_register_with_trips()
1332 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register_with_trips()
1333 result = thermal_add_hwmon_sysfs(tz); in thermal_zone_device_register_with_trips()
1339 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register_with_trips()
1343 bind_tz(tz); in thermal_zone_device_register_with_trips()
1345 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_register_with_trips()
1347 thermal_zone_device_init(tz); in thermal_zone_device_register_with_trips()
1349 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register_with_trips()
1350 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_register_with_trips()
1352 thermal_notify_tz_create(tz->id, tz->type); in thermal_zone_device_register_with_trips()
1354 return tz; in thermal_zone_device_register_with_trips()
1357 device_del(&tz->device); in thermal_zone_device_register_with_trips()
1359 put_device(&tz->device); in thermal_zone_device_register_with_trips()
1360 tz = NULL; in thermal_zone_device_register_with_trips()
1364 kfree(tz); in thermal_zone_device_register_with_trips()
1384 void thermal_zone_device_unregister(struct thermal_zone_device *tz) in thermal_zone_device_unregister() argument
1391 if (!tz) in thermal_zone_device_unregister()
1394 tzp = tz->tzp; in thermal_zone_device_unregister()
1395 tz_id = tz->id; in thermal_zone_device_unregister()
1399 if (pos == tz) in thermal_zone_device_unregister()
1401 if (pos != tz) { in thermal_zone_device_unregister()
1406 list_del(&tz->node); in thermal_zone_device_unregister()
1410 if (tz->ops->unbind) { in thermal_zone_device_unregister()
1411 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1420 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_zone_device_unregister()
1428 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1430 thermal_set_governor(tz, NULL); in thermal_zone_device_unregister()
1432 thermal_remove_hwmon_sysfs(tz); in thermal_zone_device_unregister()
1433 ida_free(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1434 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1436 mutex_lock(&tz->lock); in thermal_zone_device_unregister()
1437 device_del(&tz->device); in thermal_zone_device_unregister()
1438 mutex_unlock(&tz->lock); in thermal_zone_device_unregister()
1440 put_device(&tz->device); in thermal_zone_device_unregister()
1487 struct thermal_zone_device *tz; in thermal_pm_notify() local
1499 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1500 thermal_zone_device_init(tz); in thermal_pm_notify()
1501 thermal_zone_device_update(tz, in thermal_pm_notify()