Lines Matching +full:thermal +full:- +full:zone

1 // SPDX-License-Identifier: GPL-2.0
3 * thermal_helpers.c - helper functions to handle thermal devices
22 #include <trace/events/thermal.h>
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 list_for_each_entry(pos, &tz->thermal_instances, tz_node) { in get_thermal_instance()
55 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { in get_thermal_instance()
61 mutex_unlock(&cdev->lock); in get_thermal_instance()
62 mutex_unlock(&tz->lock); in get_thermal_instance()
69 * thermal_zone_get_temp() - returns the temperature of a thermal zone
73 * When a valid thermal zone reference is passed, it will fetch its
80 int ret = -EINVAL; in thermal_zone_get_temp()
85 if (!tz || IS_ERR(tz) || !tz->ops->get_temp) in thermal_zone_get_temp()
88 mutex_lock(&tz->lock); in thermal_zone_get_temp()
90 ret = tz->ops->get_temp(tz, temp); in thermal_zone_get_temp()
92 if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) { in thermal_zone_get_temp()
93 for (count = 0; count < tz->trips; count++) { in thermal_zone_get_temp()
94 ret = tz->ops->get_trip_type(tz, count, &type); in thermal_zone_get_temp()
96 ret = tz->ops->get_trip_temp(tz, count, in thermal_zone_get_temp()
108 *temp = tz->emul_temperature; in thermal_zone_get_temp()
111 mutex_unlock(&tz->lock); in thermal_zone_get_temp()
118 * thermal_zone_set_trips - Computes the next trip points for the driver
119 * @tz: a pointer to a thermal zone device structure
131 int low = -INT_MAX; in thermal_zone_set_trips()
136 mutex_lock(&tz->lock); in thermal_zone_set_trips()
138 if (!tz->ops->set_trips || !tz->ops->get_trip_hyst) in thermal_zone_set_trips()
141 for (i = 0; i < tz->trips; i++) { in thermal_zone_set_trips()
144 tz->ops->get_trip_temp(tz, i, &trip_temp); in thermal_zone_set_trips()
145 tz->ops->get_trip_hyst(tz, i, &hysteresis); in thermal_zone_set_trips()
147 trip_low = trip_temp - hysteresis; in thermal_zone_set_trips()
149 if (trip_low < tz->temperature && trip_low > low) in thermal_zone_set_trips()
152 if (trip_temp > tz->temperature && trip_temp < high) in thermal_zone_set_trips()
157 if (tz->prev_low_trip == low && tz->prev_high_trip == high) in thermal_zone_set_trips()
160 tz->prev_low_trip = low; in thermal_zone_set_trips()
161 tz->prev_high_trip = high; in thermal_zone_set_trips()
163 dev_dbg(&tz->device, in thermal_zone_set_trips()
168 * must inform the thermal core via thermal_zone_device_update. in thermal_zone_set_trips()
170 ret = tz->ops->set_trips(tz, low, high); in thermal_zone_set_trips()
172 dev_err(&tz->device, "Failed to set trips: %d\n", ret); in thermal_zone_set_trips()
175 mutex_unlock(&tz->lock); in thermal_zone_set_trips()
181 if (cdev->ops->set_cur_state(cdev, target)) in thermal_cdev_set_cur_state()
184 thermal_notify_cdev_state_update(cdev->id, target); in thermal_cdev_set_cur_state()
193 mutex_lock(&cdev->lock); in thermal_cdev_update()
195 if (cdev->updated) { in thermal_cdev_update()
196 mutex_unlock(&cdev->lock); in thermal_cdev_update()
201 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { in thermal_cdev_update()
202 dev_dbg(&cdev->device, "zone%d->target=%lu\n", in thermal_cdev_update()
203 instance->tz->id, instance->target); in thermal_cdev_update()
204 if (instance->target == THERMAL_NO_TARGET) in thermal_cdev_update()
206 if (instance->target > target) in thermal_cdev_update()
207 target = instance->target; in thermal_cdev_update()
212 cdev->updated = true; in thermal_cdev_update()
213 mutex_unlock(&cdev->lock); in thermal_cdev_update()
215 dev_dbg(&cdev->device, "set to state %lu\n", target); in thermal_cdev_update()
220 * thermal_zone_get_slope - return the slope attribute of the thermal zone
221 * @tz: thermal zone device with the slope attribute
223 * Return: If the thermal zone device has a slope attribute, return it, else
228 if (tz && tz->tzp) in thermal_zone_get_slope()
229 return tz->tzp->slope; in thermal_zone_get_slope()
235 * thermal_zone_get_offset - return the offset attribute of the thermal zone
236 * @tz: thermal zone device with the offset attribute
238 * Return: If the thermal zone device has a offset attribute, return it, else
243 if (tz && tz->tzp) in thermal_zone_get_offset()
244 return tz->tzp->offset; in thermal_zone_get_offset()