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 inline bool should_stop_polling(struct thermal_zone_device *tz) in should_stop_polling() argument
300 return !thermal_zone_device_is_enabled(tz); in should_stop_polling()
303 static void monitor_thermal_zone(struct thermal_zone_device *tz) in monitor_thermal_zone() argument
307 stop = should_stop_polling(tz); in monitor_thermal_zone()
309 mutex_lock(&tz->lock); in monitor_thermal_zone()
311 if (!stop && tz->passive) in monitor_thermal_zone()
312 thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies); in monitor_thermal_zone()
313 else if (!stop && tz->polling_delay_jiffies) in monitor_thermal_zone()
314 thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); in monitor_thermal_zone()
316 thermal_zone_device_set_polling(tz, 0); in monitor_thermal_zone()
318 mutex_unlock(&tz->lock); in monitor_thermal_zone()
321 static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip) in handle_non_critical_trips() argument
323 tz->governor ? tz->governor->throttle(tz, trip) : in handle_non_critical_trips()
324 def_governor->throttle(tz, trip); in handle_non_critical_trips()
327 void thermal_zone_device_critical(struct thermal_zone_device *tz) in thermal_zone_device_critical() argument
335 dev_emerg(&tz->device, "%s: critical temperature reached, " in thermal_zone_device_critical()
336 "shutting down\n", tz->type); in thermal_zone_device_critical()
342 static void handle_critical_trips(struct thermal_zone_device *tz, in handle_critical_trips() argument
347 tz->ops->get_trip_temp(tz, trip, &trip_temp); in handle_critical_trips()
350 if (trip_temp <= 0 || tz->temperature < trip_temp) in handle_critical_trips()
353 trace_thermal_zone_trip(tz, trip, trip_type); in handle_critical_trips()
355 if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot) in handle_critical_trips()
356 tz->ops->hot(tz); in handle_critical_trips()
358 tz->ops->critical(tz); in handle_critical_trips()
361 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) in handle_thermal_trip() argument
367 if (test_bit(trip, &tz->trips_disabled)) in handle_thermal_trip()
370 tz->ops->get_trip_temp(tz, trip, &trip_temp); in handle_thermal_trip()
371 tz->ops->get_trip_type(tz, trip, &type); in handle_thermal_trip()
372 if (tz->ops->get_trip_hyst) in handle_thermal_trip()
373 tz->ops->get_trip_hyst(tz, trip, &hyst); in handle_thermal_trip()
375 if (tz->last_temperature != THERMAL_TEMP_INVALID) { in handle_thermal_trip()
376 if (tz->last_temperature < trip_temp && in handle_thermal_trip()
377 tz->temperature >= trip_temp) in handle_thermal_trip()
378 thermal_notify_tz_trip_up(tz->id, trip, in handle_thermal_trip()
379 tz->temperature); in handle_thermal_trip()
380 if (tz->last_temperature >= trip_temp && in handle_thermal_trip()
381 tz->temperature < (trip_temp - hyst)) in handle_thermal_trip()
382 thermal_notify_tz_trip_down(tz->id, trip, in handle_thermal_trip()
383 tz->temperature); in handle_thermal_trip()
387 handle_critical_trips(tz, trip, type); in handle_thermal_trip()
389 handle_non_critical_trips(tz, trip); in handle_thermal_trip()
394 monitor_thermal_zone(tz); in handle_thermal_trip()
397 static void update_temperature(struct thermal_zone_device *tz) in update_temperature() argument
401 ret = thermal_zone_get_temp(tz, &temp); in update_temperature()
404 dev_warn(&tz->device, in update_temperature()
410 mutex_lock(&tz->lock); in update_temperature()
411 tz->last_temperature = tz->temperature; in update_temperature()
412 tz->temperature = temp; in update_temperature()
413 mutex_unlock(&tz->lock); in update_temperature()
415 trace_thermal_temperature(tz); in update_temperature()
417 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
420 static void thermal_zone_device_init(struct thermal_zone_device *tz) in thermal_zone_device_init() argument
423 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
424 tz->prev_low_trip = -INT_MAX; in thermal_zone_device_init()
425 tz->prev_high_trip = INT_MAX; in thermal_zone_device_init()
426 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
430 static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, in thermal_zone_device_set_mode() argument
435 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
438 if (mode == tz->mode) { in thermal_zone_device_set_mode()
439 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
444 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
445 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
448 tz->mode = mode; in thermal_zone_device_set_mode()
450 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
452 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_set_mode()
455 thermal_notify_tz_enable(tz->id); in thermal_zone_device_set_mode()
457 thermal_notify_tz_disable(tz->id); in thermal_zone_device_set_mode()
462 int thermal_zone_device_enable(struct thermal_zone_device *tz) in thermal_zone_device_enable() argument
464 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); in thermal_zone_device_enable()
468 int thermal_zone_device_disable(struct thermal_zone_device *tz) in thermal_zone_device_disable() argument
470 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); in thermal_zone_device_disable()
474 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) in thermal_zone_device_is_enabled() argument
478 mutex_lock(&tz->lock); in thermal_zone_device_is_enabled()
480 mode = tz->mode; in thermal_zone_device_is_enabled()
482 mutex_unlock(&tz->lock); in thermal_zone_device_is_enabled()
487 void thermal_zone_device_update(struct thermal_zone_device *tz, in thermal_zone_device_update() argument
492 if (should_stop_polling(tz)) in thermal_zone_device_update()
498 if (WARN_ONCE(!tz->ops->get_temp, "'%s' must not be called without " in thermal_zone_device_update()
502 update_temperature(tz); in thermal_zone_device_update()
504 thermal_zone_set_trips(tz); in thermal_zone_device_update()
506 tz->notify_event = event; in thermal_zone_device_update()
508 for (count = 0; count < tz->trips; count++) in thermal_zone_device_update()
509 handle_thermal_trip(tz, count); in thermal_zone_device_update()
515 struct thermal_zone_device *tz = container_of(work, struct in thermal_zone_device_check() local
518 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_check()
558 struct thermal_zone_device *tz; in for_each_thermal_zone() local
562 list_for_each_entry(tz, &thermal_tz_list, node) { in for_each_thermal_zone()
563 ret = cb(tz, data); in for_each_thermal_zone()
574 struct thermal_zone_device *tz, *match = NULL; in thermal_zone_get_by_id() local
577 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_zone_get_by_id()
578 if (tz->id == id) { in thermal_zone_get_by_id()
579 match = tz; in thermal_zone_get_by_id()
620 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_bind_cooling_device() argument
633 if (trip >= tz->trips || trip < 0) in thermal_zone_bind_cooling_device()
637 if (pos1 == tz) in thermal_zone_bind_cooling_device()
645 if (tz != pos1 || cdev != pos2) in thermal_zone_bind_cooling_device()
662 dev->tz = tz; in thermal_zone_bind_cooling_device()
670 result = ida_simple_get(&tz->ida, 0, 0, GFP_KERNEL); in thermal_zone_bind_cooling_device()
677 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
686 result = device_create_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
696 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
700 mutex_lock(&tz->lock); in thermal_zone_bind_cooling_device()
702 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_bind_cooling_device()
703 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_bind_cooling_device()
708 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_zone_bind_cooling_device()
710 atomic_set(&tz->need_update, 1); in thermal_zone_bind_cooling_device()
713 mutex_unlock(&tz->lock); in thermal_zone_bind_cooling_device()
718 device_remove_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
720 device_remove_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
722 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
724 ida_simple_remove(&tz->ida, dev->id); in thermal_zone_bind_cooling_device()
745 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_unbind_cooling_device() argument
751 mutex_lock(&tz->lock); in thermal_zone_unbind_cooling_device()
753 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_zone_unbind_cooling_device()
754 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_unbind_cooling_device()
758 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
763 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
768 device_remove_file(&tz->device, &pos->weight_attr); in thermal_zone_unbind_cooling_device()
769 device_remove_file(&tz->device, &pos->attr); in thermal_zone_unbind_cooling_device()
770 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_zone_unbind_cooling_device()
771 ida_simple_remove(&tz->ida, pos->id); in thermal_zone_unbind_cooling_device()
779 struct thermal_zone_device *tz; in thermal_release() local
784 tz = to_thermal_zone(dev); in thermal_release()
785 thermal_zone_destroy_device_groups(tz); in thermal_release()
786 kfree(tz); in thermal_release()
800 void print_bind_err_msg(struct thermal_zone_device *tz, in print_bind_err_msg() argument
803 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
804 tz->type, cdev->type, ret); in print_bind_err_msg()
807 static void __bind(struct thermal_zone_device *tz, int mask, in __bind() argument
814 for (i = 0; i < tz->trips; i++) { in __bind()
824 ret = thermal_zone_bind_cooling_device(tz, i, cdev, in __bind()
828 print_bind_err_msg(tz, cdev, ret); in __bind()
1054 static void __unbind(struct thermal_zone_device *tz, int mask, in __unbind() argument
1059 for (i = 0; i < tz->trips; i++) in __unbind()
1061 thermal_zone_unbind_cooling_device(tz, i, cdev); in __unbind()
1075 struct thermal_zone_device *tz; in thermal_cooling_device_unregister() local
1093 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_cooling_device_unregister()
1094 if (tz->ops->unbind) { in thermal_cooling_device_unregister()
1095 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1099 if (!tz->tzp || !tz->tzp->tbp) in thermal_cooling_device_unregister()
1102 tzp = tz->tzp; in thermal_cooling_device_unregister()
1105 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_cooling_device_unregister()
1121 static void bind_tz(struct thermal_zone_device *tz) in bind_tz() argument
1125 const struct thermal_zone_params *tzp = tz->tzp; in bind_tz()
1127 if (!tzp && !tz->ops->bind) in bind_tz()
1133 if (tz->ops->bind) { in bind_tz()
1135 ret = tz->ops->bind(tz, pos); in bind_tz()
1137 print_bind_err_msg(tz, pos, ret); in bind_tz()
1149 if (tzp->tbp[i].match(tz, pos)) in bind_tz()
1152 __bind(tz, tzp->tbp[i].trip_mask, pos, in bind_tz()
1191 struct thermal_zone_device *tz; in thermal_zone_device_register() local
1223 tz = kzalloc(sizeof(*tz), GFP_KERNEL); in thermal_zone_device_register()
1224 if (!tz) in thermal_zone_device_register()
1227 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register()
1228 ida_init(&tz->ida); in thermal_zone_device_register()
1229 mutex_init(&tz->lock); in thermal_zone_device_register()
1236 tz->id = id; in thermal_zone_device_register()
1237 strlcpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register()
1239 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register()
1246 tz->ops = ops; in thermal_zone_device_register()
1247 tz->tzp = tzp; in thermal_zone_device_register()
1248 tz->device.class = &thermal_class; in thermal_zone_device_register()
1249 tz->devdata = devdata; in thermal_zone_device_register()
1250 tz->trips = trips; in thermal_zone_device_register()
1252 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); in thermal_zone_device_register()
1253 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay); in thermal_zone_device_register()
1257 result = thermal_zone_create_device_groups(tz, mask); in thermal_zone_device_register()
1262 atomic_set(&tz->need_update, 1); in thermal_zone_device_register()
1264 result = device_register(&tz->device); in thermal_zone_device_register()
1269 if (tz->ops->get_trip_type(tz, count, &trip_type) || in thermal_zone_device_register()
1270 tz->ops->get_trip_temp(tz, count, &trip_temp) || in thermal_zone_device_register()
1272 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1278 if (tz->tzp) in thermal_zone_device_register()
1279 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register()
1283 result = thermal_set_governor(tz, governor); in thermal_zone_device_register()
1291 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register()
1292 result = thermal_add_hwmon_sysfs(tz); in thermal_zone_device_register()
1298 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register()
1302 bind_tz(tz); in thermal_zone_device_register()
1304 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_register()
1306 thermal_zone_device_init(tz); in thermal_zone_device_register()
1308 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register()
1309 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_register()
1311 thermal_notify_tz_create(tz->id, tz->type); in thermal_zone_device_register()
1313 return tz; in thermal_zone_device_register()
1316 device_del(&tz->device); in thermal_zone_device_register()
1318 put_device(&tz->device); in thermal_zone_device_register()
1319 tz = NULL; in thermal_zone_device_register()
1323 kfree(tz); in thermal_zone_device_register()
1332 void thermal_zone_device_unregister(struct thermal_zone_device *tz) in thermal_zone_device_unregister() argument
1339 if (!tz) in thermal_zone_device_unregister()
1342 tzp = tz->tzp; in thermal_zone_device_unregister()
1343 tz_id = tz->id; in thermal_zone_device_unregister()
1347 if (pos == tz) in thermal_zone_device_unregister()
1349 if (pos != tz) { in thermal_zone_device_unregister()
1354 list_del(&tz->node); in thermal_zone_device_unregister()
1358 if (tz->ops->unbind) { in thermal_zone_device_unregister()
1359 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1368 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_zone_device_unregister()
1376 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1378 thermal_set_governor(tz, NULL); in thermal_zone_device_unregister()
1380 thermal_remove_hwmon_sysfs(tz); in thermal_zone_device_unregister()
1381 ida_simple_remove(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1382 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1383 mutex_destroy(&tz->lock); in thermal_zone_device_unregister()
1384 device_unregister(&tz->device); in thermal_zone_device_unregister()
1431 struct thermal_zone_device *tz; in thermal_pm_notify() local
1443 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1444 if (!thermal_zone_device_is_enabled(tz)) in thermal_pm_notify()
1447 thermal_zone_device_init(tz); in thermal_pm_notify()
1448 thermal_zone_device_update(tz, in thermal_pm_notify()