public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lina Iyer <ilina@codeaurora.org>
To: edubezval@gmail.com, rui.zhang@intel.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, daniel.lezcano@linaro.org,
	amit.kucheria@linaro.org, Lina Iyer <ilina@codeaurora.org>
Subject: [PATCH RFC 3/4] drivers: of-thermal: aggregate sensor trips across thermal zones
Date: Tue,  8 May 2018 11:48:58 -0600	[thread overview]
Message-ID: <20180508174859.26539-4-ilina@codeaurora.org> (raw)
In-Reply-To: <20180508174859.26539-1-ilina@codeaurora.org>

Aggregate thermal trip based on the trip points of the thermal zones
that use this sensor as the source.

Signed-off-by: Lina Iyer <ilina@codeaurora.org>
---
 drivers/thermal/of-thermal.c      | 28 ++++++++++++++++++++++-
 drivers/thermal/thermal_helpers.c | 37 ++++++++++++++++++-------------
 include/linux/thermal.h           |  4 ++++
 3 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index 06e581a37c67..6fb2eeb5b6cf 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -96,16 +96,42 @@ static int of_thermal_get_temp(struct thermal_zone_device *tz,
 	return sensor->ops->get_temp(sensor->sensor_data, temp);
 }
 
+static void __of_thermal_agg_trip(struct thermal_sensor *sensor,
+				 int *floor, int *ceil)
+{
+	int low, high;
+	int max_lo = INT_MIN;
+	int min_hi = INT_MAX;
+	struct thermal_zone_device *tz;
+
+	list_for_each_entry(tz, &sensor->tz_list, sensor_tzd) {
+		thermal_zone_get_trip(tz, &low, &high);
+		if (low > max_lo)
+			max_lo = low;
+		if (high < min_hi)
+			min_hi = high;
+	}
+
+	*floor = max_lo;
+	*ceil = min_hi;
+}
+
 static int of_thermal_set_trips(struct thermal_zone_device *tz,
 				int low, int high)
 {
 	struct __thermal_zone *data = tz->devdata;
 	struct thermal_sensor *sensor = data->sensor;
+	int ret;
 
 	if (!sensor || !sensor->ops->set_trips)
 		return -EINVAL;
 
-	return sensor->ops->set_trips(sensor->sensor_data, low, high);
+	mutex_lock(&sensor->lock);
+	__of_thermal_agg_trip(sensor, &low, &high);
+	ret = sensor->ops->set_trips(sensor->sensor_data, low, high);
+	mutex_unlock(&sensor->lock);
+
+	return ret;
 }
 
 /**
diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index f550fdee0f9b..d4fa125f8799 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -113,32 +113,39 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
 }
 EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
 
-void thermal_zone_set_trips(struct thermal_zone_device *tz)
+
+void thermal_zone_get_trip(struct thermal_zone_device *tz, int *low, int *high)
 {
-	int low = -INT_MAX;
-	int high = INT_MAX;
-	int trip_temp, hysteresis;
-	int i, ret;
+	int i, trip_low, trip_temp, hysteresis;
 
-	mutex_lock(&tz->lock);
-
-	if (!tz->ops->set_trips || !tz->ops->get_trip_hyst)
-		goto exit;
+	*low = -INT_MAX;
+	*high = INT_MAX;
 
 	for (i = 0; i < tz->trips; i++) {
-		int trip_low;
-
 		tz->ops->get_trip_temp(tz, i, &trip_temp);
 		tz->ops->get_trip_hyst(tz, i, &hysteresis);
 
 		trip_low = trip_temp - hysteresis;
 
-		if (trip_low < tz->temperature && trip_low > low)
-			low = trip_low;
+		if (trip_low < tz->temperature && trip_low > *low)
+			*low = trip_low;
 
-		if (trip_temp > tz->temperature && trip_temp < high)
-			high = trip_temp;
+		if (trip_temp > tz->temperature && trip_temp < *high)
+			*high = trip_temp;
 	}
+}
+
+void thermal_zone_set_trips(struct thermal_zone_device *tz)
+{
+	int low, high;
+	int ret;
+
+	mutex_lock(&tz->lock);
+
+	if (!tz->ops->set_trips || !tz->ops->get_trip_hyst)
+		goto exit;
+
+	thermal_zone_get_trip(tz, &low, &high);
 
 	/* No need to change trip points */
 	if (tz->prev_low_trip == low && tz->prev_high_trip == high)
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 09e1669a4919..000ae6a97678 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -443,6 +443,7 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
 				       struct thermal_cooling_device *);
 void thermal_zone_device_update(struct thermal_zone_device *,
 				enum thermal_notify_event);
+void thermal_zone_get_trip(struct thermal_zone_device *tz, int *low, int *high);
 void thermal_zone_set_trips(struct thermal_zone_device *);
 
 struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
@@ -496,6 +497,9 @@ static inline int thermal_zone_unbind_cooling_device(
 static inline void thermal_zone_device_update(struct thermal_zone_device *tz,
 					      enum thermal_notify_event event)
 { }
+static inline void thermal_zone_get_trip(struct thermal_zone_device *tz,
+					 int *low, int *high)
+{ }
 static inline void thermal_zone_set_trips(struct thermal_zone_device *tz)
 { }
 static inline struct thermal_cooling_device *
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

  parent reply	other threads:[~2018-05-08 17:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-08 17:48 [PATCH RFC 0/4] drivers/thermal: support for multiple TZ for sensor Lina Iyer
2018-05-08 17:48 ` [PATCH RFC 1/4] drivers: of-thermal: abstract sensor related information Lina Iyer
2018-05-08 17:48 ` [PATCH RFC 2/4] drivers: of-thermal: allow multiple thermal zones for a sensor Lina Iyer
2018-05-08 17:48 ` Lina Iyer [this message]
2018-05-08 17:48 ` [PATCH RFC 4/4] drivers: of-thermal: notify framework when sensor is tripped Lina Iyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180508174859.26539-4-ilina@codeaurora.org \
    --to=ilina@codeaurora.org \
    --cc=amit.kucheria@linaro.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=edubezval@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox