Lines Matching refs:tz
81 static void bind_previous_governor(struct thermal_zone_device *tz, in bind_previous_governor() argument
84 if (tz->governor && tz->governor->bind_to_tz) { in bind_previous_governor()
85 if (tz->governor->bind_to_tz(tz)) { in bind_previous_governor()
86 dev_err(&tz->device, in bind_previous_governor()
88 failed_gov_name, tz->governor->name, tz->type); in bind_previous_governor()
89 tz->governor = NULL; in bind_previous_governor()
103 static int thermal_set_governor(struct thermal_zone_device *tz, in thermal_set_governor() argument
108 if (tz->governor && tz->governor->unbind_from_tz) in thermal_set_governor()
109 tz->governor->unbind_from_tz(tz); in thermal_set_governor()
112 ret = new_gov->bind_to_tz(tz); in thermal_set_governor()
114 bind_previous_governor(tz, new_gov->name); in thermal_set_governor()
120 tz->governor = new_gov; in thermal_set_governor()
205 int thermal_zone_device_set_policy(struct thermal_zone_device *tz, in thermal_zone_device_set_policy() argument
212 mutex_lock(&tz->lock); in thermal_zone_device_set_policy()
218 ret = thermal_set_governor(tz, gov); in thermal_zone_device_set_policy()
221 mutex_unlock(&tz->lock); in thermal_zone_device_set_policy()
295 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, in thermal_zone_device_set_polling() argument
300 &tz->poll_queue, in thermal_zone_device_set_polling()
304 &tz->poll_queue, in thermal_zone_device_set_polling()
307 cancel_delayed_work_sync(&tz->poll_queue); in thermal_zone_device_set_polling()
310 static void monitor_thermal_zone(struct thermal_zone_device *tz) in monitor_thermal_zone() argument
312 mutex_lock(&tz->lock); in monitor_thermal_zone()
314 if (tz->passive) in monitor_thermal_zone()
315 thermal_zone_device_set_polling(tz, tz->passive_delay); in monitor_thermal_zone()
316 else if (tz->polling_delay) in monitor_thermal_zone()
317 thermal_zone_device_set_polling(tz, tz->polling_delay); in monitor_thermal_zone()
319 thermal_zone_device_set_polling(tz, 0); in monitor_thermal_zone()
321 mutex_unlock(&tz->lock); in monitor_thermal_zone()
324 static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip) in handle_non_critical_trips() argument
326 tz->governor ? tz->governor->throttle(tz, trip) : in handle_non_critical_trips()
327 def_governor->throttle(tz, trip); in handle_non_critical_trips()
378 static void handle_critical_trips(struct thermal_zone_device *tz, in handle_critical_trips() argument
383 tz->ops->get_trip_temp(tz, trip, &trip_temp); in handle_critical_trips()
386 if (trip_temp <= 0 || tz->temperature < trip_temp) in handle_critical_trips()
389 trace_thermal_zone_trip(tz, trip, trip_type); in handle_critical_trips()
391 if (tz->ops->notify) in handle_critical_trips()
392 tz->ops->notify(tz, trip, trip_type); in handle_critical_trips()
395 dev_emerg(&tz->device, in handle_critical_trips()
397 tz->temperature / 1000); in handle_critical_trips()
412 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) in handle_thermal_trip() argument
417 if (test_bit(trip, &tz->trips_disabled)) in handle_thermal_trip()
420 tz->ops->get_trip_type(tz, trip, &type); in handle_thermal_trip()
423 handle_critical_trips(tz, trip, type); in handle_thermal_trip()
425 handle_non_critical_trips(tz, trip); in handle_thermal_trip()
430 monitor_thermal_zone(tz); in handle_thermal_trip()
433 static void update_temperature(struct thermal_zone_device *tz) in update_temperature() argument
437 ret = thermal_zone_get_temp(tz, &temp); in update_temperature()
440 dev_warn(&tz->device, in update_temperature()
446 mutex_lock(&tz->lock); in update_temperature()
447 tz->last_temperature = tz->temperature; in update_temperature()
448 tz->temperature = temp; in update_temperature()
449 mutex_unlock(&tz->lock); in update_temperature()
451 trace_thermal_temperature(tz); in update_temperature()
452 if (tz->last_temperature == THERMAL_TEMP_INVALID) in update_temperature()
453 dev_dbg(&tz->device, "last_temperature N/A, current_temperature=%d\n", in update_temperature()
454 tz->temperature); in update_temperature()
456 dev_dbg(&tz->device, "last_temperature=%d, current_temperature=%d\n", in update_temperature()
457 tz->last_temperature, tz->temperature); in update_temperature()
460 static void thermal_zone_device_init(struct thermal_zone_device *tz) in thermal_zone_device_init() argument
463 tz->temperature = THERMAL_TEMP_INVALID; in thermal_zone_device_init()
464 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_device_init()
468 static void thermal_zone_device_reset(struct thermal_zone_device *tz) in thermal_zone_device_reset() argument
470 tz->passive = 0; in thermal_zone_device_reset()
471 thermal_zone_device_init(tz); in thermal_zone_device_reset()
474 void thermal_zone_device_update(struct thermal_zone_device *tz, in thermal_zone_device_update() argument
482 if (!tz->ops->get_temp) in thermal_zone_device_update()
485 update_temperature(tz); in thermal_zone_device_update()
487 thermal_zone_set_trips(tz); in thermal_zone_device_update()
489 tz->notify_event = event; in thermal_zone_device_update()
491 for (count = 0; count < tz->trips; count++) in thermal_zone_device_update()
492 handle_thermal_trip(tz, count); in thermal_zone_device_update()
508 void thermal_notify_framework(struct thermal_zone_device *tz, int trip) in thermal_notify_framework() argument
510 handle_thermal_trip(tz, trip); in thermal_notify_framework()
516 struct thermal_zone_device *tz = container_of(work, struct in thermal_zone_device_check() local
519 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_check()
542 struct thermal_zone_device *tz, u32 *max_power) in power_actor_get_max_power() argument
547 return cdev->ops->state2power(cdev, tz, 0, max_power); in power_actor_get_max_power()
563 struct thermal_zone_device *tz, u32 *min_power) in power_actor_get_min_power() argument
575 return cdev->ops->state2power(cdev, tz, max_state, min_power); in power_actor_get_min_power()
599 ret = cdev->ops->power2state(cdev, instance->tz, power, &state); in power_actor_set_power()
612 void thermal_zone_device_rebind_exception(struct thermal_zone_device *tz, in thermal_zone_device_rebind_exception() argument
624 thermal_zone_bind_cooling_device(tz, THERMAL_TRIPS_NONE, cdev, in thermal_zone_device_rebind_exception()
632 void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz, in thermal_zone_device_unbind_exception() argument
643 thermal_zone_unbind_cooling_device(tz, THERMAL_TRIPS_NONE, in thermal_zone_device_unbind_exception()
681 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_bind_cooling_device() argument
694 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE)) in thermal_zone_bind_cooling_device()
698 if (pos1 == tz) in thermal_zone_bind_cooling_device()
706 if (tz != pos1 || cdev != pos2) in thermal_zone_bind_cooling_device()
723 dev->tz = tz; in thermal_zone_bind_cooling_device()
731 result = ida_simple_get(&tz->ida, 0, 0, GFP_KERNEL); in thermal_zone_bind_cooling_device()
738 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
747 result = device_create_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
757 result = device_create_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
761 mutex_lock(&tz->lock); in thermal_zone_bind_cooling_device()
763 list_for_each_entry(pos, &tz->thermal_instances, tz_node) in thermal_zone_bind_cooling_device()
764 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_bind_cooling_device()
769 list_add_tail(&dev->tz_node, &tz->thermal_instances); in thermal_zone_bind_cooling_device()
771 atomic_set(&tz->need_update, 1); in thermal_zone_bind_cooling_device()
774 mutex_unlock(&tz->lock); in thermal_zone_bind_cooling_device()
779 device_remove_file(&tz->device, &dev->weight_attr); in thermal_zone_bind_cooling_device()
781 device_remove_file(&tz->device, &dev->attr); in thermal_zone_bind_cooling_device()
783 sysfs_remove_link(&tz->device.kobj, dev->name); in thermal_zone_bind_cooling_device()
785 ida_simple_remove(&tz->ida, dev->id); in thermal_zone_bind_cooling_device()
806 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, in thermal_zone_unbind_cooling_device() argument
812 mutex_lock(&tz->lock); in thermal_zone_unbind_cooling_device()
814 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { in thermal_zone_unbind_cooling_device()
815 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in thermal_zone_unbind_cooling_device()
819 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
824 mutex_unlock(&tz->lock); in thermal_zone_unbind_cooling_device()
829 device_remove_file(&tz->device, &pos->weight_attr); in thermal_zone_unbind_cooling_device()
830 device_remove_file(&tz->device, &pos->attr); in thermal_zone_unbind_cooling_device()
831 sysfs_remove_link(&tz->device.kobj, pos->name); in thermal_zone_unbind_cooling_device()
832 ida_simple_remove(&tz->ida, pos->id); in thermal_zone_unbind_cooling_device()
840 struct thermal_zone_device *tz; in thermal_release() local
845 tz = to_thermal_zone(dev); in thermal_release()
846 thermal_zone_destroy_device_groups(tz); in thermal_release()
847 kfree(tz); in thermal_release()
861 void print_bind_err_msg(struct thermal_zone_device *tz, in print_bind_err_msg() argument
864 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", in print_bind_err_msg()
865 tz->type, cdev->type, ret); in print_bind_err_msg()
868 static void __bind(struct thermal_zone_device *tz, int mask, in __bind() argument
875 for (i = 0; i < tz->trips; i++) { in __bind()
885 ret = thermal_zone_bind_cooling_device(tz, i, cdev, in __bind()
889 print_bind_err_msg(tz, cdev, ret); in __bind()
1104 static void __unbind(struct thermal_zone_device *tz, int mask, in __unbind() argument
1109 for (i = 0; i < tz->trips; i++) in __unbind()
1111 thermal_zone_unbind_cooling_device(tz, i, cdev); in __unbind()
1125 struct thermal_zone_device *tz; in thermal_cooling_device_unregister() local
1143 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_cooling_device_unregister()
1144 if (tz->ops->unbind) { in thermal_cooling_device_unregister()
1145 tz->ops->unbind(tz, cdev); in thermal_cooling_device_unregister()
1149 if (!tz->tzp || !tz->tzp->tbp) in thermal_cooling_device_unregister()
1152 tzp = tz->tzp; in thermal_cooling_device_unregister()
1155 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_cooling_device_unregister()
1170 static void bind_tz(struct thermal_zone_device *tz) in bind_tz() argument
1174 const struct thermal_zone_params *tzp = tz->tzp; in bind_tz()
1176 if (!tzp && !tz->ops->bind) in bind_tz()
1182 if (tz->ops->bind) { in bind_tz()
1184 ret = tz->ops->bind(tz, pos); in bind_tz()
1186 print_bind_err_msg(tz, pos, ret); in bind_tz()
1198 if (tzp->tbp[i].match(tz, pos)) in bind_tz()
1201 __bind(tz, tzp->tbp[i].trip_mask, pos, in bind_tz()
1240 struct thermal_zone_device *tz; in thermal_zone_device_register() local
1272 tz = kzalloc(sizeof(*tz), GFP_KERNEL); in thermal_zone_device_register()
1273 if (!tz) in thermal_zone_device_register()
1276 INIT_LIST_HEAD(&tz->thermal_instances); in thermal_zone_device_register()
1277 ida_init(&tz->ida); in thermal_zone_device_register()
1278 mutex_init(&tz->lock); in thermal_zone_device_register()
1285 tz->id = id; in thermal_zone_device_register()
1286 strlcpy(tz->type, type, sizeof(tz->type)); in thermal_zone_device_register()
1287 tz->ops = ops; in thermal_zone_device_register()
1288 tz->tzp = tzp; in thermal_zone_device_register()
1289 tz->device.class = &thermal_class; in thermal_zone_device_register()
1290 tz->devdata = devdata; in thermal_zone_device_register()
1291 tz->trips = trips; in thermal_zone_device_register()
1292 tz->passive_delay = passive_delay; in thermal_zone_device_register()
1293 tz->polling_delay = polling_delay; in thermal_zone_device_register()
1297 result = thermal_zone_create_device_groups(tz, mask); in thermal_zone_device_register()
1302 atomic_set(&tz->need_update, 1); in thermal_zone_device_register()
1304 dev_set_name(&tz->device, "thermal_zone%d", tz->id); in thermal_zone_device_register()
1305 result = device_register(&tz->device); in thermal_zone_device_register()
1310 if (tz->ops->get_trip_type(tz, count, &trip_type)) in thermal_zone_device_register()
1311 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1312 if (tz->ops->get_trip_temp(tz, count, &trip_temp)) in thermal_zone_device_register()
1313 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1316 set_bit(count, &tz->trips_disabled); in thermal_zone_device_register()
1322 if (tz->tzp) in thermal_zone_device_register()
1323 governor = __find_governor(tz->tzp->governor_name); in thermal_zone_device_register()
1327 result = thermal_set_governor(tz, governor); in thermal_zone_device_register()
1335 if (!tz->tzp || !tz->tzp->no_hwmon) { in thermal_zone_device_register()
1336 result = thermal_add_hwmon_sysfs(tz); in thermal_zone_device_register()
1342 list_add_tail(&tz->node, &thermal_tz_list); in thermal_zone_device_register()
1346 bind_tz(tz); in thermal_zone_device_register()
1348 INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); in thermal_zone_device_register()
1350 thermal_zone_device_reset(tz); in thermal_zone_device_register()
1352 if (atomic_cmpxchg(&tz->need_update, 1, 0)) in thermal_zone_device_register()
1353 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); in thermal_zone_device_register()
1355 return tz; in thermal_zone_device_register()
1358 device_del(&tz->device); in thermal_zone_device_register()
1360 put_device(&tz->device); in thermal_zone_device_register()
1361 tz = NULL; in thermal_zone_device_register()
1365 kfree(tz); in thermal_zone_device_register()
1374 void thermal_zone_device_unregister(struct thermal_zone_device *tz) in thermal_zone_device_unregister() argument
1381 if (!tz) in thermal_zone_device_unregister()
1384 tzp = tz->tzp; in thermal_zone_device_unregister()
1388 if (pos == tz) in thermal_zone_device_unregister()
1390 if (pos != tz) { in thermal_zone_device_unregister()
1395 list_del(&tz->node); in thermal_zone_device_unregister()
1399 if (tz->ops->unbind) { in thermal_zone_device_unregister()
1400 tz->ops->unbind(tz, cdev); in thermal_zone_device_unregister()
1409 __unbind(tz, tzp->tbp[i].trip_mask, cdev); in thermal_zone_device_unregister()
1417 thermal_zone_device_set_polling(tz, 0); in thermal_zone_device_unregister()
1419 thermal_set_governor(tz, NULL); in thermal_zone_device_unregister()
1421 thermal_remove_hwmon_sysfs(tz); in thermal_zone_device_unregister()
1422 ida_simple_remove(&thermal_tz_ida, tz->id); in thermal_zone_device_unregister()
1423 ida_destroy(&tz->ida); in thermal_zone_device_unregister()
1424 mutex_destroy(&tz->lock); in thermal_zone_device_unregister()
1425 device_unregister(&tz->device); in thermal_zone_device_unregister()
1481 int thermal_generate_netlink_event(struct thermal_zone_device *tz, in thermal_generate_netlink_event() argument
1492 if (!tz) in thermal_generate_netlink_event()
1529 thermal_event->orig = tz->id; in thermal_generate_netlink_event()
1538 dev_err(&tz->device, "Failed to send netlink event:%d", result); in thermal_generate_netlink_event()
1561 struct thermal_zone_device *tz; in thermal_pm_notify() local
1574 list_for_each_entry(tz, &thermal_tz_list, node) { in thermal_pm_notify()
1576 if (tz->ops->get_mode) in thermal_pm_notify()
1577 tz->ops->get_mode(tz, &tz_mode); in thermal_pm_notify()
1582 thermal_zone_device_init(tz); in thermal_pm_notify()
1583 thermal_zone_device_update(tz, in thermal_pm_notify()