Lines Matching +full:thermal +full:- +full:zone
1 // SPDX-License-Identifier: GPL-2.0
3 * thermal_helpers.c - helper functions to handle thermal devices
27 struct thermal_trip *trip = tz->trips ? &tz->trips[trip_index] : NULL; in get_tz_trend()
30 if (tz->emul_temperature || !tz->ops->get_trend || in get_tz_trend()
31 tz->ops->get_trend(tz, trip, &trend)) { in get_tz_trend()
32 if (tz->temperature > tz->last_temperature) in get_tz_trend()
34 else if (tz->temperature < tz->last_temperature) in get_tz_trend()
51 mutex_lock(&tz->lock); in get_thermal_instance()
52 mutex_lock(&cdev->lock); in get_thermal_instance()
54 trip = &tz->trips[trip_index]; in get_thermal_instance()
56 list_for_each_entry(pos, &tz->thermal_instances, tz_node) { in get_thermal_instance()
57 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in get_thermal_instance()
63 mutex_unlock(&cdev->lock); in get_thermal_instance()
64 mutex_unlock(&tz->lock); in get_thermal_instance()
71 * __thermal_zone_get_temp() - returns the temperature of a thermal zone
75 * When a valid thermal zone reference is passed, it will fetch its
78 * Both tz and tz->ops must be valid pointers when calling this function,
79 * and the tz->ops->get_temp callback must be provided.
80 * The function must be called under tz->lock.
86 int ret = -EINVAL; in __thermal_zone_get_temp()
91 lockdep_assert_held(&tz->lock); in __thermal_zone_get_temp()
93 ret = tz->ops->get_temp(tz, temp); in __thermal_zone_get_temp()
95 if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) { in __thermal_zone_get_temp()
96 for (count = 0; count < tz->num_trips; count++) { in __thermal_zone_get_temp()
110 *temp = tz->emul_temperature; in __thermal_zone_get_temp()
114 dev_dbg(&tz->device, "Failed to get temperature: %d\n", ret); in __thermal_zone_get_temp()
120 * thermal_zone_get_temp() - returns the temperature of a thermal zone
124 * When a valid thermal zone reference is passed, it will fetch its
134 return -EINVAL; in thermal_zone_get_temp()
136 mutex_lock(&tz->lock); in thermal_zone_get_temp()
138 if (!tz->ops->get_temp) { in thermal_zone_get_temp()
139 ret = -EINVAL; in thermal_zone_get_temp()
143 if (device_is_registered(&tz->device)) in thermal_zone_get_temp()
146 ret = -ENODEV; in thermal_zone_get_temp()
149 mutex_unlock(&tz->lock); in thermal_zone_get_temp()
158 if (cdev->ops->set_cur_state(cdev, target)) in thermal_cdev_set_cur_state()
161 thermal_notify_cdev_state_update(cdev->id, target); in thermal_cdev_set_cur_state()
171 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { in __thermal_cdev_update()
172 dev_dbg(&cdev->device, "zone%d->target=%lu\n", in __thermal_cdev_update()
173 instance->tz->id, instance->target); in __thermal_cdev_update()
174 if (instance->target == THERMAL_NO_TARGET) in __thermal_cdev_update()
176 if (instance->target > target) in __thermal_cdev_update()
177 target = instance->target; in __thermal_cdev_update()
183 dev_dbg(&cdev->device, "set to state %lu\n", target); in __thermal_cdev_update()
187 * thermal_cdev_update - update cooling device state if needed
194 mutex_lock(&cdev->lock); in thermal_cdev_update()
195 if (!cdev->updated) { in thermal_cdev_update()
197 cdev->updated = true; in thermal_cdev_update()
199 mutex_unlock(&cdev->lock); in thermal_cdev_update()
203 * thermal_zone_get_slope - return the slope attribute of the thermal zone
204 * @tz: thermal zone device with the slope attribute
206 * Return: If the thermal zone device has a slope attribute, return it, else
211 if (tz && tz->tzp) in thermal_zone_get_slope()
212 return tz->tzp->slope; in thermal_zone_get_slope()
218 * thermal_zone_get_offset - return the offset attribute of the thermal zone
219 * @tz: thermal zone device with the offset attribute
221 * Return: If the thermal zone device has a offset attribute, return it, else
226 if (tz && tz->tzp) in thermal_zone_get_offset()
227 return tz->tzp->offset; in thermal_zone_get_offset()