Lines Matching refs:tz
71 static void bind_previous_governor(struct thermal_zone_device *tz, in bind_previous_governor() argument
74 if (tz->governor && tz->governor->bind_to_tz) { in bind_previous_governor()
75 if (tz->governor->bind_to_tz(tz)) { in bind_previous_governor()
76 dev_err(&tz->device, in bind_previous_governor()
78 failed_gov_name, tz->governor->name, tz->type); in bind_previous_governor()
79 tz->governor = NULL; in bind_previous_governor()
93 static int thermal_set_governor(struct thermal_zone_device *tz, in thermal_set_governor() argument
98 if (tz->governor && tz->governor->unbind_from_tz) in thermal_set_governor()
99 tz->governor->unbind_from_tz(tz); in thermal_set_governor()
102 ret = new_gov->bind_to_tz(tz); in thermal_set_governor()
104 bind_previous_governor(tz, new_gov->name); in thermal_set_governor()
110 tz->governor = new_gov; in thermal_set_governor()
195 int thermal_zone_device_set_policy(struct thermal_zone_device *tz, in thermal_zone_device_set_policy() argument
202 mutex_lock(&tz->lock); in thermal_zone_device_set_policy()
204 if (!device_is_registered(&tz->device)) in thermal_zone_device_set_policy()
211 ret = thermal_set_governor(tz, gov); in thermal_zone_device_set_policy()
214 mutex_unlock(&tz->lock); in thermal_zone_device_set_policy()
217 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_id) in handle_thermal_trip() argument
349 if (test_bit(trip_id, &tz->trips_disabled)) in handle_thermal_trip()
352 __thermal_zone_get_trip(tz, trip_id, &trip); in handle_thermal_trip()
357 if (tz->last_temperature != THERMAL_TEMP_INVALID) { in handle_thermal_trip()
358 if (tz->last_temperature < trip.temperature && in handle_thermal_trip()
359 tz->temperature >= trip.temperature) in handle_thermal_trip()
360 thermal_notify_tz_trip_up(tz->id, trip_id, in handle_thermal_trip()
361 tz->temperature); in handle_thermal_trip()
362 if (tz->last_temperature >= trip.temperature && in handle_thermal_trip()
363 tz->temperature < (trip.temperature - trip.hysteresis)) in handle_thermal_trip()
364 thermal_notify_tz_trip_down(tz->id, trip_id, in handle_thermal_trip()
365 tz->temperature); in handle_thermal_trip()
369 handle_critical_trips(tz, trip_id, trip.temperature, trip.type); in handle_thermal_trip()
371 handle_non_critical_trips(tz, trip_id); in handle_thermal_trip()
374 static void update_temperature(struct thermal_zone_device *tz) in update_temperature() argument
378 ret = __thermal_zone_get_temp(tz, &temp); in update_temperature()
381 dev_warn(&tz->device, in update_temperature()
387 tz->last_temperature = tz->temperature; in update_temperature()
388 tz->temperature = temp; in update_temperature()
390 trace_thermal_temperature(tz); in update_temperature()
392 thermal_genl_sampling_temp(tz->id, temp); in update_temperature()
395 static void thermal_zone_device_init(struct thermal_zone_device *tz) in thermal_zone_device_init() argument
398 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
399 tz->prev_low_trip = -INT_MAX; in thermal_zone_device_init()
400 tz->prev_high_trip = INT_MAX; in thermal_zone_device_init()
401 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
405 void __thermal_zone_device_update(struct thermal_zone_device *tz, in __thermal_zone_device_update() argument
410 if (tz->suspended) in __thermal_zone_device_update()
413 if (WARN_ONCE(!tz->ops->get_temp, in __thermal_zone_device_update()
418 if (!thermal_zone_device_is_enabled(tz)) in __thermal_zone_device_update()
421 update_temperature(tz); in __thermal_zone_device_update()
423 __thermal_zone_set_trips(tz); in __thermal_zone_device_update()
425 tz->notify_event = event; in __thermal_zone_device_update()
427 for (count = 0; count < tz->num_trips; count++) in __thermal_zone_device_update()
428 handle_thermal_trip(tz, count); in __thermal_zone_device_update()
430 monitor_thermal_zone(tz); in __thermal_zone_device_update()
433 static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, in thermal_zone_device_set_mode() argument
438 mutex_lock(&tz->lock); in thermal_zone_device_set_mode()
441 if (mode == tz->mode) { in thermal_zone_device_set_mode()
442 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
447 if (!device_is_registered(&tz->device)) { in thermal_zone_device_set_mode()
448 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
453 if (tz->ops->change_mode) in thermal_zone_device_set_mode()
454 ret = tz->ops->change_mode(tz, mode); in thermal_zone_device_set_mode()
457 tz->mode = mode; in thermal_zone_device_set_mode()
459 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_set_mode()
461 mutex_unlock(&tz->lock); in thermal_zone_device_set_mode()
464 thermal_notify_tz_enable(tz->id); in thermal_zone_device_set_mode()
466 thermal_notify_tz_disable(tz->id); in thermal_zone_device_set_mode()
471 int thermal_zone_device_enable(struct thermal_zone_device *tz) in thermal_zone_device_enable() argument
473 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED); in thermal_zone_device_enable()
477 int thermal_zone_device_disable(struct thermal_zone_device *tz) in thermal_zone_device_disable() argument
479 return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); in thermal_zone_device_disable()
483 int thermal_zone_device_is_enabled(struct thermal_zone_device *tz) in thermal_zone_device_is_enabled() argument
485 lockdep_assert_held(&tz->lock); in thermal_zone_device_is_enabled()
487 return tz->mode == THERMAL_DEVICE_ENABLED; in thermal_zone_device_is_enabled()
490 void thermal_zone_device_update(struct thermal_zone_device *tz, in thermal_zone_device_update() argument
493 mutex_lock(&tz->lock); in thermal_zone_device_update()
494 if (device_is_registered(&tz->device)) in thermal_zone_device_update()
495 __thermal_zone_device_update(tz, event); in thermal_zone_device_update()
496 mutex_unlock(&tz->lock); in thermal_zone_device_update()
506 void thermal_zone_device_exec(struct thermal_zone_device *tz, in thermal_zone_device_exec() argument
511 mutex_lock(&tz->lock); in thermal_zone_device_exec()
513 cb(tz, data); in thermal_zone_device_exec()
515 mutex_unlock(&tz->lock); in thermal_zone_device_exec()
521 struct thermal_zone_device *tz = container_of(work, struct in thermal_zone_device_check() local
524 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_check()
564 struct thermal_zone_device *tz; in for_each_thermal_zone() local
568 list_for_each_entry(tz, &thermal_tz_list, node) { in for_each_thermal_zone()
569 ret = cb(tz, data); in for_each_thermal_zone()
580 struct thermal_zone_device *tz, *match = NULL; in thermal_zone_get_by_id() local
583 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_zone_get_by_id()
584 if (tz->id == id) { in thermal_zone_get_by_id()
585 match = tz; in thermal_zone_get_by_id()
626 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_bind_cooling_device() argument
640 if (trip_index >= tz->num_trips || trip_index < 0) in thermal_zone_bind_cooling_device()
643 trip = &tz->trips[trip_index]; in thermal_zone_bind_cooling_device()
646 if (pos1 == tz) in thermal_zone_bind_cooling_device()
654 if (tz != pos1 || cdev != pos2) in thermal_zone_bind_cooling_device()
673 dev->tz = tz; in thermal_zone_bind_cooling_device()
682 result = ida_alloc(&tz->ida, GFP_KERNEL); in thermal_zone_bind_cooling_device()
689 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
699 result = device_create_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
710 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
714 mutex_lock(&tz->lock); in thermal_zone_bind_cooling_device()
716 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_bind_cooling_device()
717 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_bind_cooling_device()
722 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_zone_bind_cooling_device()
724 atomic_set(&tz->need_update, 1); in thermal_zone_bind_cooling_device()
727 mutex_unlock(&tz->lock); in thermal_zone_bind_cooling_device()
732 device_remove_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
734 device_remove_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
736 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
738 ida_free(&tz->ida, dev->id); in thermal_zone_bind_cooling_device()
759 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_unbind_cooling_device() argument
766 mutex_lock(&tz->lock); in thermal_zone_unbind_cooling_device()
768 trip = &tz->trips[trip_index]; in thermal_zone_unbind_cooling_device()
769 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_zone_unbind_cooling_device()
770 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_unbind_cooling_device()
774 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
779 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
784 device_remove_file(&tz->device, &pos->weight_attr); in thermal_zone_unbind_cooling_device()
785 device_remove_file(&tz->device, &pos->attr); in thermal_zone_unbind_cooling_device()
786 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_zone_unbind_cooling_device()
787 ida_free(&tz->ida, pos->id); in thermal_zone_unbind_cooling_device()
795 struct thermal_zone_device *tz; in thermal_release() local
800 tz = to_thermal_zone(dev); in thermal_release()
801 thermal_zone_destroy_device_groups(tz); in thermal_release()
802 mutex_destroy(&tz->lock); in thermal_release()
803 kfree(tz); in thermal_release()
817 void print_bind_err_msg(struct thermal_zone_device *tz, in print_bind_err_msg() argument
820 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
821 tz->type, cdev->type, ret); in print_bind_err_msg()
1127 struct thermal_zone_device *tz; in thermal_cooling_device_unregister() local
1142 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_cooling_device_unregister()
1143 if (tz->ops->unbind) in thermal_cooling_device_unregister()
1144 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1153 static void bind_tz(struct thermal_zone_device *tz) in bind_tz() argument
1158 if (!tz->ops->bind) in bind_tz()
1164 ret = tz->ops->bind(tz, pos); in bind_tz()
1166 print_bind_err_msg(tz, pos, ret); in bind_tz()
1179 int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp) in thermal_zone_get_crit_temp() argument
1183 if (tz->ops->get_crit_temp) in thermal_zone_get_crit_temp()
1184 return tz->ops->get_crit_temp(tz, temp); in thermal_zone_get_crit_temp()
1186 if (!tz->trips) in thermal_zone_get_crit_temp()
1189 mutex_lock(&tz->lock); in thermal_zone_get_crit_temp()
1191 for (i = 0; i < tz->num_trips; i++) { in thermal_zone_get_crit_temp()
1192 if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) { in thermal_zone_get_crit_temp()
1193 *temp = tz->trips[i].temperature; in thermal_zone_get_crit_temp()
1199 mutex_unlock(&tz->lock); in thermal_zone_get_crit_temp()
1236 struct thermal_zone_device *tz; in thermal_zone_device_register_with_trips() local
1282 tz = kzalloc(sizeof(*tz), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1283 if (!tz) in thermal_zone_device_register_with_trips()
1287 tz->tzp = kmemdup(tzp, sizeof(*tzp), GFP_KERNEL); in thermal_zone_device_register_with_trips()
1288 if (!tz->tzp) { in thermal_zone_device_register_with_trips()
1294 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register_with_trips()
1295 ida_init(&tz->ida); in thermal_zone_device_register_with_trips()
1296 mutex_init(&tz->lock); in thermal_zone_device_register_with_trips()
1303 tz->id = id; in thermal_zone_device_register_with_trips()
1304 strscpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register_with_trips()
1309 tz->ops = ops; in thermal_zone_device_register_with_trips()
1310 tz->device.class = thermal_class; in thermal_zone_device_register_with_trips()
1311 tz->devdata = devdata; in thermal_zone_device_register_with_trips()
1312 tz->trips = trips; in thermal_zone_device_register_with_trips()
1313 tz->num_trips = num_trips; in thermal_zone_device_register_with_trips()
1315 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); in thermal_zone_device_register_with_trips()
1316 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay); in thermal_zone_device_register_with_trips()
1320 result = thermal_zone_create_device_groups(tz, mask); in thermal_zone_device_register_with_trips()
1325 atomic_set(&tz->need_update, 1); in thermal_zone_device_register_with_trips()
1327 result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register_with_trips()
1329 thermal_zone_destroy_device_groups(tz); in thermal_zone_device_register_with_trips()
1332 result = device_register(&tz->device); in thermal_zone_device_register_with_trips()
1339 result = thermal_zone_get_trip(tz, count, &trip); in thermal_zone_device_register_with_trips()
1341 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register_with_trips()
1347 if (tz->tzp) in thermal_zone_device_register_with_trips()
1348 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register_with_trips()
1352 result = thermal_set_governor(tz, governor); in thermal_zone_device_register_with_trips()
1360 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register_with_trips()
1361 result = thermal_add_hwmon_sysfs(tz); in thermal_zone_device_register_with_trips()
1367 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register_with_trips()
1371 bind_tz(tz); in thermal_zone_device_register_with_trips()
1373 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_register_with_trips()
1375 thermal_zone_device_init(tz); in thermal_zone_device_register_with_trips()
1377 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register_with_trips()
1378 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_register_with_trips()
1380 thermal_notify_tz_create(tz->id, tz->type); in thermal_zone_device_register_with_trips()
1382 return tz; in thermal_zone_device_register_with_trips()
1385 device_del(&tz->device); in thermal_zone_device_register_with_trips()
1387 put_device(&tz->device); in thermal_zone_device_register_with_trips()
1391 kfree(tz->tzp); in thermal_zone_device_register_with_trips()
1393 kfree(tz); in thermal_zone_device_register_with_trips()
1437 void thermal_zone_device_unregister(struct thermal_zone_device *tz) in thermal_zone_device_unregister() argument
1443 if (!tz) in thermal_zone_device_unregister()
1446 tz_id = tz->id; in thermal_zone_device_unregister()
1450 if (pos == tz) in thermal_zone_device_unregister()
1452 if (pos != tz) { in thermal_zone_device_unregister()
1457 list_del(&tz->node); in thermal_zone_device_unregister()
1461 if (tz->ops->unbind) in thermal_zone_device_unregister()
1462 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1466 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_unregister()
1468 thermal_set_governor(tz, NULL); in thermal_zone_device_unregister()
1470 thermal_remove_hwmon_sysfs(tz); in thermal_zone_device_unregister()
1471 ida_free(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1472 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1474 mutex_lock(&tz->lock); in thermal_zone_device_unregister()
1475 device_del(&tz->device); in thermal_zone_device_unregister()
1476 mutex_unlock(&tz->lock); in thermal_zone_device_unregister()
1478 kfree(tz->tzp); in thermal_zone_device_unregister()
1480 put_device(&tz->device); in thermal_zone_device_unregister()
1527 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 mutex_lock(&tz->lock); in thermal_pm_notify()
1538 tz->suspended = true; in thermal_pm_notify()
1540 mutex_unlock(&tz->lock); in thermal_pm_notify()
1550 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1551 mutex_lock(&tz->lock); in thermal_pm_notify()
1553 tz->suspended = false; in thermal_pm_notify()
1555 thermal_zone_device_init(tz); in thermal_pm_notify()
1556 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_pm_notify()
1558 mutex_unlock(&tz->lock); in thermal_pm_notify()