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()
359 if (tz->last_temperature != THERMAL_TEMP_INVALID) { in handle_thermal_trip()
360 if (tz->last_temperature < trip.temperature && in handle_thermal_trip()
361 tz->temperature >= trip.temperature) in handle_thermal_trip()
362 thermal_notify_tz_trip_up(tz->id, trip_id, in handle_thermal_trip()
363 tz->temperature); in handle_thermal_trip()
364 if (tz->last_temperature >= trip.temperature && in handle_thermal_trip()
365 tz->temperature < (trip.temperature - trip.hysteresis)) in handle_thermal_trip()
366 thermal_notify_tz_trip_down(tz->id, trip_id, in handle_thermal_trip()
367 tz->temperature); in handle_thermal_trip()
371 handle_critical_trips(tz, trip_id, trip.temperature, trip.type); in handle_thermal_trip()
373 handle_non_critical_trips(tz, trip_id); in handle_thermal_trip()
376 static void update_temperature(struct thermal_zone_device *tz) in update_temperature() argument
380 ret = __thermal_zone_get_temp(tz, &temp); in update_temperature()
383 dev_warn(&tz->device, in update_temperature()
389 tz->last_temperature = tz->temperature; in update_temperature()
390 tz->temperature = temp; in update_temperature()
392 trace_thermal_temperature(tz); in update_temperature()
394 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
397 static void thermal_zone_device_init(struct thermal_zone_device *tz) in thermal_zone_device_init() argument
400 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
401 tz->prev_low_trip = -INT_MAX; in thermal_zone_device_init()
402 tz->prev_high_trip = INT_MAX; in thermal_zone_device_init()
403 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
407 void __thermal_zone_device_update(struct thermal_zone_device *tz, in __thermal_zone_device_update() argument
415 if (WARN_ONCE(!tz->ops->get_temp, in __thermal_zone_device_update()
420 if (!thermal_zone_device_is_enabled(tz)) in __thermal_zone_device_update()
423 update_temperature(tz); in __thermal_zone_device_update()
425 __thermal_zone_set_trips(tz); in __thermal_zone_device_update()
427 tz->notify_event = event; in __thermal_zone_device_update()
429 for (count = 0; count < tz->num_trips; count++) in __thermal_zone_device_update()
430 handle_thermal_trip(tz, count); in __thermal_zone_device_update()
432 monitor_thermal_zone(tz); in __thermal_zone_device_update()
435 static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, in thermal_zone_device_set_mode() argument
440 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
443 if (mode == tz->mode) { in thermal_zone_device_set_mode()
444 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
449 if (!device_is_registered(&tz->device)) { in thermal_zone_device_set_mode()
450 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
455 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
456 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
459 tz->mode = mode; in thermal_zone_device_set_mode()
461 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_set_mode()
463 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
466 thermal_notify_tz_enable(tz->id); in thermal_zone_device_set_mode()
468 thermal_notify_tz_disable(tz->id); in thermal_zone_device_set_mode()
473 int thermal_zone_device_enable(struct thermal_zone_device *tz) in thermal_zone_device_enable() argument
475 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); in thermal_zone_device_enable()
479 int thermal_zone_device_disable(struct thermal_zone_device *tz) in thermal_zone_device_disable() argument
481 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); in thermal_zone_device_disable()
485 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) in thermal_zone_device_is_enabled() argument
487 lockdep_assert_held(&tz->lock); in thermal_zone_device_is_enabled()
489 return tz->mode == THERMAL_DEVICE_ENABLED; in thermal_zone_device_is_enabled()
492 void thermal_zone_device_update(struct thermal_zone_device *tz, in thermal_zone_device_update() argument
495 mutex_lock(&tz->lock); in thermal_zone_device_update()
496 if (device_is_registered(&tz->device)) in thermal_zone_device_update()
497 __thermal_zone_device_update(tz, event); in thermal_zone_device_update()
498 mutex_unlock(&tz->lock); in thermal_zone_device_update()
508 void thermal_zone_device_exec(struct thermal_zone_device *tz, in thermal_zone_device_exec() argument
513 mutex_lock(&tz->lock); in thermal_zone_device_exec()
515 cb(tz, data); in thermal_zone_device_exec()
517 mutex_unlock(&tz->lock); in thermal_zone_device_exec()
523 struct thermal_zone_device *tz = container_of(work, struct in thermal_zone_device_check() local
526 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_check()
566 struct thermal_zone_device *tz; in for_each_thermal_zone() local
570 list_for_each_entry(tz, &thermal_tz_list, node) { in for_each_thermal_zone()
571 ret = cb(tz, data); in for_each_thermal_zone()
582 struct thermal_zone_device *tz, *match = NULL; in thermal_zone_get_by_id() local
585 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_zone_get_by_id()
586 if (tz->id == id) { in thermal_zone_get_by_id()
587 match = tz; in thermal_zone_get_by_id()
628 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_bind_cooling_device() argument
641 if (trip >= tz->num_trips || trip < 0) in thermal_zone_bind_cooling_device()
645 if (pos1 == tz) in thermal_zone_bind_cooling_device()
653 if (tz != pos1 || cdev != pos2) in thermal_zone_bind_cooling_device()
672 dev->tz = tz; in thermal_zone_bind_cooling_device()
681 result = ida_alloc(&tz->ida, GFP_KERNEL); in thermal_zone_bind_cooling_device()
688 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
697 result = device_create_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
707 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
711 mutex_lock(&tz->lock); in thermal_zone_bind_cooling_device()
713 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_bind_cooling_device()
714 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_bind_cooling_device()
719 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_zone_bind_cooling_device()
721 atomic_set(&tz->need_update, 1); in thermal_zone_bind_cooling_device()
724 mutex_unlock(&tz->lock); in thermal_zone_bind_cooling_device()
729 device_remove_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
731 device_remove_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
733 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
735 ida_free(&tz->ida, dev->id); in thermal_zone_bind_cooling_device()
756 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_unbind_cooling_device() argument
762 mutex_lock(&tz->lock); in thermal_zone_unbind_cooling_device()
764 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_zone_unbind_cooling_device()
765 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_unbind_cooling_device()
769 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
774 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
779 device_remove_file(&tz->device, &pos->weight_attr); in thermal_zone_unbind_cooling_device()
780 device_remove_file(&tz->device, &pos->attr); in thermal_zone_unbind_cooling_device()
781 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_zone_unbind_cooling_device()
782 ida_free(&tz->ida, pos->id); in thermal_zone_unbind_cooling_device()
790 struct thermal_zone_device *tz; in thermal_release() local
795 tz = to_thermal_zone(dev); in thermal_release()
796 thermal_zone_destroy_device_groups(tz); in thermal_release()
797 mutex_destroy(&tz->lock); in thermal_release()
798 kfree(tz); in thermal_release()
812 void print_bind_err_msg(struct thermal_zone_device *tz, in print_bind_err_msg() argument
815 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
816 tz->type, cdev->type, ret); in print_bind_err_msg()
1122 struct thermal_zone_device *tz; in thermal_cooling_device_unregister() local
1137 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_cooling_device_unregister()
1138 if (tz->ops->unbind) in thermal_cooling_device_unregister()
1139 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1148 static void bind_tz(struct thermal_zone_device *tz) in bind_tz() argument
1153 if (!tz->ops->bind) in bind_tz()
1159 ret = tz->ops->bind(tz, pos); in bind_tz()
1161 print_bind_err_msg(tz, pos, ret); in bind_tz()
1174 int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp) in thermal_zone_get_crit_temp() argument
1178 if (tz->ops->get_crit_temp) in thermal_zone_get_crit_temp()
1179 return tz->ops->get_crit_temp(tz, temp); in thermal_zone_get_crit_temp()
1181 if (!tz->trips) in thermal_zone_get_crit_temp()
1184 mutex_lock(&tz->lock); in thermal_zone_get_crit_temp()
1186 for (i = 0; i < tz->num_trips; i++) { in thermal_zone_get_crit_temp()
1187 if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) { in thermal_zone_get_crit_temp()
1188 *temp = tz->trips[i].temperature; in thermal_zone_get_crit_temp()
1194 mutex_unlock(&tz->lock); in thermal_zone_get_crit_temp()
1231 struct thermal_zone_device *tz; in thermal_zone_device_register_with_trips() local
1277 tz = kzalloc(sizeof(*tz), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1278 if (!tz) in thermal_zone_device_register_with_trips()
1282 tz->tzp = kmemdup(tzp, sizeof(*tzp), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1283 if (!tz->tzp) { in thermal_zone_device_register_with_trips()
1289 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register_with_trips()
1290 ida_init(&tz->ida); in thermal_zone_device_register_with_trips()
1291 mutex_init(&tz->lock); in thermal_zone_device_register_with_trips()
1298 tz->id = id; in thermal_zone_device_register_with_trips()
1299 strscpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register_with_trips()
1304 tz->ops = ops; in thermal_zone_device_register_with_trips()
1305 tz->device.class = thermal_class; in thermal_zone_device_register_with_trips()
1306 tz->devdata = devdata; in thermal_zone_device_register_with_trips()
1307 tz->trips = trips; in thermal_zone_device_register_with_trips()
1308 tz->num_trips = num_trips; in thermal_zone_device_register_with_trips()
1310 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); in thermal_zone_device_register_with_trips()
1311 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay); in thermal_zone_device_register_with_trips()
1315 result = thermal_zone_create_device_groups(tz, mask); in thermal_zone_device_register_with_trips()
1320 atomic_set(&tz->need_update, 1); in thermal_zone_device_register_with_trips()
1322 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register_with_trips()
1324 thermal_zone_destroy_device_groups(tz); in thermal_zone_device_register_with_trips()
1327 result = device_register(&tz->device); in thermal_zone_device_register_with_trips()
1334 result = thermal_zone_get_trip(tz, count, &trip); in thermal_zone_device_register_with_trips()
1336 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register_with_trips()
1342 if (tz->tzp) in thermal_zone_device_register_with_trips()
1343 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register_with_trips()
1347 result = thermal_set_governor(tz, governor); in thermal_zone_device_register_with_trips()
1355 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register_with_trips()
1356 result = thermal_add_hwmon_sysfs(tz); in thermal_zone_device_register_with_trips()
1362 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register_with_trips()
1366 bind_tz(tz); in thermal_zone_device_register_with_trips()
1368 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_register_with_trips()
1370 thermal_zone_device_init(tz); in thermal_zone_device_register_with_trips()
1372 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register_with_trips()
1373 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_register_with_trips()
1375 thermal_notify_tz_create(tz->id, tz->type); in thermal_zone_device_register_with_trips()
1377 return tz; in thermal_zone_device_register_with_trips()
1380 device_del(&tz->device); in thermal_zone_device_register_with_trips()
1382 put_device(&tz->device); in thermal_zone_device_register_with_trips()
1383 tz = NULL; in thermal_zone_device_register_with_trips()
1387 kfree(tz->tzp); in thermal_zone_device_register_with_trips()
1389 kfree(tz); in thermal_zone_device_register_with_trips()
1433 void thermal_zone_device_unregister(struct thermal_zone_device *tz) in thermal_zone_device_unregister() argument
1439 if (!tz) in thermal_zone_device_unregister()
1442 tz_id = tz->id; in thermal_zone_device_unregister()
1446 if (pos == tz) in thermal_zone_device_unregister()
1448 if (pos != tz) { in thermal_zone_device_unregister()
1453 list_del(&tz->node); in thermal_zone_device_unregister()
1457 if (tz->ops->unbind) in thermal_zone_device_unregister()
1458 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1462 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1464 thermal_set_governor(tz, NULL); in thermal_zone_device_unregister()
1466 thermal_remove_hwmon_sysfs(tz); in thermal_zone_device_unregister()
1467 ida_free(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1468 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1470 mutex_lock(&tz->lock); in thermal_zone_device_unregister()
1471 device_del(&tz->device); in thermal_zone_device_unregister()
1472 mutex_unlock(&tz->lock); in thermal_zone_device_unregister()
1474 kfree(tz->tzp); in thermal_zone_device_unregister()
1476 put_device(&tz->device); in thermal_zone_device_unregister()
1523 struct thermal_zone_device *tz; in thermal_pm_notify() local
1535 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1536 thermal_zone_device_init(tz); in thermal_pm_notify()
1537 thermal_zone_device_update(tz, in thermal_pm_notify()