Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a3ce6e1c authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "drivers: thermal: Notify only thermal zones whose trips are violated"

parents 1dcf74bf ca0bb24b
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -569,6 +569,46 @@ static int of_thermal_aggregate_trip_types(struct thermal_zone_device *tz,
	return 0;
}

static bool of_thermal_is_trips_triggered(struct thermal_zone_device *tz,
		int temp)
{
	int tt, th, trip, last_temp;
	struct __thermal_zone *data = tz->devdata;
	bool triggered = false;

	mutex_lock(&tz->lock);
	last_temp = tz->last_temperature;
	for (trip = 0; trip < data->ntrips; trip++) {

		if (!tz->tzp->tracks_low) {
			tt = data->trips[trip].temperature;
			if (temp >= tt && last_temp < tt) {
				triggered = true;
				break;
			}
			th = tt - data->trips[trip].hysteresis;
			if (temp <= th && last_temp > th) {
				triggered = true;
				break;
			}
		} else {
			tt = data->trips[trip].temperature;
			if (temp <= tt && last_temp > tt) {
				triggered = true;
				break;
			}
			th = tt + data->trips[trip].hysteresis;
			if (temp >= th && last_temp < th) {
				triggered = true;
				break;
			}
		}
	}
	mutex_unlock(&tz->lock);

	return triggered;
}

/*
 * of_thermal_aggregate_trip - aggregate trip temperatures across sibling
 *				thermal zones.
@@ -605,6 +645,8 @@ static void handle_thermal_trip(struct thermal_zone_device *tz,
			thermal_zone_device_update(zone,
				THERMAL_EVENT_UNSPECIFIED);
		} else {
			if (!of_thermal_is_trips_triggered(zone, trip_temp))
				continue;
			thermal_zone_device_update_temp(zone,
				THERMAL_EVENT_UNSPECIFIED, trip_temp);
		}