Lines Matching refs:tz
75 static void bind_previous_governor(struct thermal_zone_device *tz, in bind_previous_governor() argument
78 if (tz->governor && tz->governor->bind_to_tz) { in bind_previous_governor()
79 if (tz->governor->bind_to_tz(tz)) { in bind_previous_governor()
80 dev_err(&tz->device, in bind_previous_governor()
82 failed_gov_name, tz->governor->name, tz->type); in bind_previous_governor()
83 tz->governor = NULL; in bind_previous_governor()
97 static int thermal_set_governor(struct thermal_zone_device *tz, in thermal_set_governor() argument
102 if (tz->governor && tz->governor->unbind_from_tz) in thermal_set_governor()
103 tz->governor->unbind_from_tz(tz); in thermal_set_governor()
106 ret = new_gov->bind_to_tz(tz); in thermal_set_governor()
108 bind_previous_governor(tz, new_gov->name); in thermal_set_governor()
114 tz->governor = new_gov; in thermal_set_governor()
199 int thermal_zone_device_set_policy(struct thermal_zone_device *tz, in thermal_zone_device_set_policy() argument
206 mutex_lock(&tz->lock); in thermal_zone_device_set_policy()
212 ret = thermal_set_governor(tz, gov); in thermal_zone_device_set_policy()
215 mutex_unlock(&tz->lock); in thermal_zone_device_set_policy()
218 thermal_notify_tz_gov_change(tz->id, policy); in thermal_zone_device_set_policy()
291 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, in thermal_zone_device_set_polling() argument
296 &tz->poll_queue, in thermal_zone_device_set_polling()
300 &tz->poll_queue, in thermal_zone_device_set_polling()
303 cancel_delayed_work(&tz->poll_queue); in thermal_zone_device_set_polling()
306 static inline bool should_stop_polling(struct thermal_zone_device *tz) in should_stop_polling() argument
308 return !thermal_zone_device_is_enabled(tz); in should_stop_polling()
311 static void monitor_thermal_zone(struct thermal_zone_device *tz) in monitor_thermal_zone() argument
315 stop = should_stop_polling(tz); in monitor_thermal_zone()
317 mutex_lock(&tz->lock); in monitor_thermal_zone()
319 if (!stop && tz->passive) in monitor_thermal_zone()
320 thermal_zone_device_set_polling(tz, tz->passive_delay); in monitor_thermal_zone()
321 else if (!stop && tz->polling_delay) in monitor_thermal_zone()
322 thermal_zone_device_set_polling(tz, tz->polling_delay); in monitor_thermal_zone()
324 thermal_zone_device_set_polling(tz, 0); in monitor_thermal_zone()
326 mutex_unlock(&tz->lock); in monitor_thermal_zone()
329 static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip) in handle_non_critical_trips() argument
331 tz->governor ? tz->governor->throttle(tz, trip) : in handle_non_critical_trips()
332 def_governor->throttle(tz, trip); in handle_non_critical_trips()
383 static void handle_critical_trips(struct thermal_zone_device *tz, in handle_critical_trips() argument
388 tz->ops->get_trip_temp(tz, trip, &trip_temp); in handle_critical_trips()
391 if (trip_temp <= 0 || tz->temperature < trip_temp) in handle_critical_trips()
394 trace_thermal_zone_trip(tz, trip, trip_type); in handle_critical_trips()
396 if (tz->ops->notify) in handle_critical_trips()
397 tz->ops->notify(tz, trip, trip_type); in handle_critical_trips()
400 dev_emerg(&tz->device, in handle_critical_trips()
402 tz->temperature / 1000); in handle_critical_trips()
417 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) in handle_thermal_trip() argument
423 if (test_bit(trip, &tz->trips_disabled)) in handle_thermal_trip()
426 tz->ops->get_trip_temp(tz, trip, &trip_temp); in handle_thermal_trip()
427 tz->ops->get_trip_type(tz, trip, &type); in handle_thermal_trip()
428 if (tz->ops->get_trip_hyst) in handle_thermal_trip()
429 tz->ops->get_trip_hyst(tz, trip, &hyst); in handle_thermal_trip()
431 if (tz->last_temperature != THERMAL_TEMP_INVALID) { in handle_thermal_trip()
432 if (tz->last_temperature < trip_temp && in handle_thermal_trip()
433 tz->temperature >= trip_temp) in handle_thermal_trip()
434 thermal_notify_tz_trip_up(tz->id, trip); in handle_thermal_trip()
435 if (tz->last_temperature >= trip_temp && in handle_thermal_trip()
436 tz->temperature < (trip_temp - hyst)) in handle_thermal_trip()
437 thermal_notify_tz_trip_down(tz->id, trip); in handle_thermal_trip()
441 handle_critical_trips(tz, trip, type); in handle_thermal_trip()
443 handle_non_critical_trips(tz, trip); in handle_thermal_trip()
448 monitor_thermal_zone(tz); in handle_thermal_trip()
451 static void update_temperature(struct thermal_zone_device *tz) in update_temperature() argument
455 ret = thermal_zone_get_temp(tz, &temp); in update_temperature()
458 dev_warn(&tz->device, in update_temperature()
464 mutex_lock(&tz->lock); in update_temperature()
465 tz->last_temperature = tz->temperature; in update_temperature()
466 tz->temperature = temp; in update_temperature()
467 mutex_unlock(&tz->lock); in update_temperature()
469 trace_thermal_temperature(tz); in update_temperature()
471 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
474 static void thermal_zone_device_init(struct thermal_zone_device *tz) in thermal_zone_device_init() argument
477 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
478 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
482 static void thermal_zone_device_reset(struct thermal_zone_device *tz) in thermal_zone_device_reset() argument
484 tz->passive = 0; in thermal_zone_device_reset()
485 thermal_zone_device_init(tz); in thermal_zone_device_reset()
488 static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, in thermal_zone_device_set_mode() argument
493 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
496 if (mode == tz->mode) { in thermal_zone_device_set_mode()
497 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
502 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
503 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
506 tz->mode = mode; in thermal_zone_device_set_mode()
508 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
510 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_set_mode()
513 thermal_notify_tz_enable(tz->id); in thermal_zone_device_set_mode()
515 thermal_notify_tz_disable(tz->id); in thermal_zone_device_set_mode()
520 int thermal_zone_device_enable(struct thermal_zone_device *tz) in thermal_zone_device_enable() argument
522 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); in thermal_zone_device_enable()
526 int thermal_zone_device_disable(struct thermal_zone_device *tz) in thermal_zone_device_disable() argument
528 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); in thermal_zone_device_disable()
532 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) in thermal_zone_device_is_enabled() argument
536 mutex_lock(&tz->lock); in thermal_zone_device_is_enabled()
538 mode = tz->mode; in thermal_zone_device_is_enabled()
540 mutex_unlock(&tz->lock); in thermal_zone_device_is_enabled()
545 void thermal_zone_device_update(struct thermal_zone_device *tz, in thermal_zone_device_update() argument
550 if (should_stop_polling(tz)) in thermal_zone_device_update()
556 if (!tz->ops->get_temp) in thermal_zone_device_update()
559 update_temperature(tz); in thermal_zone_device_update()
561 thermal_zone_set_trips(tz); in thermal_zone_device_update()
563 tz->notify_event = event; in thermal_zone_device_update()
565 for (count = 0; count < tz->trips; count++) in thermal_zone_device_update()
566 handle_thermal_trip(tz, count); in thermal_zone_device_update()
582 void thermal_notify_framework(struct thermal_zone_device *tz, int trip) in thermal_notify_framework() argument
584 handle_thermal_trip(tz, trip); in thermal_notify_framework()
590 struct thermal_zone_device *tz = container_of(work, struct in thermal_zone_device_check() local
593 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_check()
684 void thermal_zone_device_rebind_exception(struct thermal_zone_device *tz, in thermal_zone_device_rebind_exception() argument
696 thermal_zone_bind_cooling_device(tz, THERMAL_TRIPS_NONE, cdev, in thermal_zone_device_rebind_exception()
741 struct thermal_zone_device *tz; in for_each_thermal_zone() local
745 list_for_each_entry(tz, &thermal_tz_list, node) { in for_each_thermal_zone()
746 ret = cb(tz, data); in for_each_thermal_zone()
757 struct thermal_zone_device *tz, *match = NULL; in thermal_zone_get_by_id() local
760 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_zone_get_by_id()
761 if (tz->id == id) { in thermal_zone_get_by_id()
762 match = tz; in thermal_zone_get_by_id()
771 void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz, in thermal_zone_device_unbind_exception() argument
782 thermal_zone_unbind_cooling_device(tz, THERMAL_TRIPS_NONE, in thermal_zone_device_unbind_exception()
820 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_bind_cooling_device() argument
833 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE)) in thermal_zone_bind_cooling_device()
837 if (pos1 == tz) in thermal_zone_bind_cooling_device()
845 if (tz != pos1 || cdev != pos2) in thermal_zone_bind_cooling_device()
862 dev->tz = tz; in thermal_zone_bind_cooling_device()
870 result = ida_simple_get(&tz->ida, 0, 0, GFP_KERNEL); in thermal_zone_bind_cooling_device()
877 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
886 result = device_create_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
896 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
900 mutex_lock(&tz->lock); in thermal_zone_bind_cooling_device()
902 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_bind_cooling_device()
903 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_bind_cooling_device()
908 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_zone_bind_cooling_device()
910 atomic_set(&tz->need_update, 1); in thermal_zone_bind_cooling_device()
913 mutex_unlock(&tz->lock); in thermal_zone_bind_cooling_device()
918 device_remove_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
920 device_remove_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
922 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
924 ida_simple_remove(&tz->ida, dev->id); in thermal_zone_bind_cooling_device()
945 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_unbind_cooling_device() argument
951 mutex_lock(&tz->lock); in thermal_zone_unbind_cooling_device()
953 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_zone_unbind_cooling_device()
954 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_unbind_cooling_device()
958 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
963 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
968 device_remove_file(&tz->device, &pos->weight_attr); in thermal_zone_unbind_cooling_device()
969 device_remove_file(&tz->device, &pos->attr); in thermal_zone_unbind_cooling_device()
970 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_zone_unbind_cooling_device()
971 ida_simple_remove(&tz->ida, pos->id); in thermal_zone_unbind_cooling_device()
979 struct thermal_zone_device *tz; in thermal_release() local
984 tz = to_thermal_zone(dev); in thermal_release()
985 thermal_zone_destroy_device_groups(tz); in thermal_release()
986 kfree(tz); in thermal_release()
1000 void print_bind_err_msg(struct thermal_zone_device *tz, in print_bind_err_msg() argument
1003 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
1004 tz->type, cdev->type, ret); in print_bind_err_msg()
1007 static void __bind(struct thermal_zone_device *tz, int mask, in __bind() argument
1014 for (i = 0; i < tz->trips; i++) { in __bind()
1024 ret = thermal_zone_bind_cooling_device(tz, i, cdev, in __bind()
1028 print_bind_err_msg(tz, cdev, ret); in __bind()
1243 static void __unbind(struct thermal_zone_device *tz, int mask, in __unbind() argument
1248 for (i = 0; i < tz->trips; i++) in __unbind()
1250 thermal_zone_unbind_cooling_device(tz, i, cdev); in __unbind()
1264 struct thermal_zone_device *tz; in thermal_cooling_device_unregister() local
1282 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_cooling_device_unregister()
1283 if (tz->ops->unbind) { in thermal_cooling_device_unregister()
1284 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1288 if (!tz->tzp || !tz->tzp->tbp) in thermal_cooling_device_unregister()
1291 tzp = tz->tzp; in thermal_cooling_device_unregister()
1294 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_cooling_device_unregister()
1309 static void bind_tz(struct thermal_zone_device *tz) in bind_tz() argument
1313 const struct thermal_zone_params *tzp = tz->tzp; in bind_tz()
1315 if (!tzp && !tz->ops->bind) in bind_tz()
1321 if (tz->ops->bind) { in bind_tz()
1323 ret = tz->ops->bind(tz, pos); in bind_tz()
1325 print_bind_err_msg(tz, pos, ret); in bind_tz()
1337 if (tzp->tbp[i].match(tz, pos)) in bind_tz()
1340 __bind(tz, tzp->tbp[i].trip_mask, pos, in bind_tz()
1379 struct thermal_zone_device *tz; in thermal_zone_device_register() local
1411 tz = kzalloc(sizeof(*tz), GFP_KERNEL); in thermal_zone_device_register()
1412 if (!tz) in thermal_zone_device_register()
1415 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register()
1416 ida_init(&tz->ida); in thermal_zone_device_register()
1417 mutex_init(&tz->lock); in thermal_zone_device_register()
1424 tz->id = id; in thermal_zone_device_register()
1425 strlcpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register()
1426 tz->ops = ops; in thermal_zone_device_register()
1427 tz->tzp = tzp; in thermal_zone_device_register()
1428 tz->device.class = &thermal_class; in thermal_zone_device_register()
1429 tz->devdata = devdata; in thermal_zone_device_register()
1430 tz->trips = trips; in thermal_zone_device_register()
1431 tz->passive_delay = passive_delay; in thermal_zone_device_register()
1432 tz->polling_delay = polling_delay; in thermal_zone_device_register()
1436 result = thermal_zone_create_device_groups(tz, mask); in thermal_zone_device_register()
1441 atomic_set(&tz->need_update, 1); in thermal_zone_device_register()
1443 dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register()
1444 result = device_register(&tz->device); in thermal_zone_device_register()
1449 if (tz->ops->get_trip_type(tz, count, &trip_type)) in thermal_zone_device_register()
1450 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1451 if (tz->ops->get_trip_temp(tz, count, &trip_temp)) in thermal_zone_device_register()
1452 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1455 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1461 if (tz->tzp) in thermal_zone_device_register()
1462 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register()
1466 result = thermal_set_governor(tz, governor); in thermal_zone_device_register()
1474 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register()
1475 result = thermal_add_hwmon_sysfs(tz); in thermal_zone_device_register()
1481 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register()
1485 bind_tz(tz); in thermal_zone_device_register()
1487 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_register()
1489 thermal_zone_device_reset(tz); in thermal_zone_device_register()
1491 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register()
1492 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_register()
1494 thermal_notify_tz_create(tz->id, tz->type); in thermal_zone_device_register()
1496 return tz; in thermal_zone_device_register()
1499 device_del(&tz->device); in thermal_zone_device_register()
1501 put_device(&tz->device); in thermal_zone_device_register()
1502 tz = NULL; in thermal_zone_device_register()
1506 kfree(tz); in thermal_zone_device_register()
1515 void thermal_zone_device_unregister(struct thermal_zone_device *tz) in thermal_zone_device_unregister() argument
1522 if (!tz) in thermal_zone_device_unregister()
1525 tzp = tz->tzp; in thermal_zone_device_unregister()
1526 tz_id = tz->id; in thermal_zone_device_unregister()
1530 if (pos == tz) in thermal_zone_device_unregister()
1532 if (pos != tz) { in thermal_zone_device_unregister()
1537 list_del(&tz->node); in thermal_zone_device_unregister()
1541 if (tz->ops->unbind) { in thermal_zone_device_unregister()
1542 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1551 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_zone_device_unregister()
1559 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1561 thermal_set_governor(tz, NULL); in thermal_zone_device_unregister()
1563 thermal_remove_hwmon_sysfs(tz); in thermal_zone_device_unregister()
1564 ida_simple_remove(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1565 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1566 mutex_destroy(&tz->lock); in thermal_zone_device_unregister()
1567 device_unregister(&tz->device); in thermal_zone_device_unregister()
1614 struct thermal_zone_device *tz; in thermal_pm_notify() local
1626 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1627 if (!thermal_zone_device_is_enabled(tz)) in thermal_pm_notify()
1630 thermal_zone_device_init(tz); in thermal_pm_notify()
1631 thermal_zone_device_update(tz, in thermal_pm_notify()