linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM <linux-pm@vger.kernel.org>, linux-tegra@vger.kernel.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>
Subject: [PATCH v1 02/14] thermal: helpers: Introduce thermal_trip_is_bound_to_cdev()
Date: Mon, 17 Jun 2024 19:49:03 +0200	[thread overview]
Message-ID: <2013201.usQuhbGJ8B@kreacher> (raw)
In-Reply-To: <8409966.T7Z3S40VBb@kreacher>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Introduce a new helper function thermal_trip_is_bound_to_cdev() for
checking whether or not a given trip point has been bound to a given
cooling device.

The primary user of it will be the Tegra thermal driver.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/thermal_helpers.c |   47 ++++++++++++++++++++++++++++----------
 include/linux/thermal.h           |    3 ++
 2 files changed, 38 insertions(+), 12 deletions(-)

Index: linux-pm/drivers/thermal/thermal_helpers.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_helpers.c
+++ linux-pm/drivers/thermal/thermal_helpers.c
@@ -39,30 +39,53 @@ int get_tz_trend(struct thermal_zone_dev
 	return trend;
 }
 
+static struct thermal_instance *get_instance(struct thermal_zone_device *tz,
+					     struct thermal_cooling_device *cdev,
+					     const struct thermal_trip *trip)
+{
+	struct thermal_instance *ti;
+
+	list_for_each_entry(ti, &tz->thermal_instances, tz_node) {
+		if (ti->trip == trip && ti->cdev == cdev)
+			return ti;
+	}
+
+	return NULL;
+}
+
+bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
+				   const struct thermal_trip *trip,
+				   struct thermal_cooling_device *cdev)
+{
+	bool ret;
+
+	mutex_lock(&tz->lock);
+	mutex_lock(&cdev->lock);
+
+	ret = !!get_instance(tz, cdev, trip);
+
+	mutex_unlock(&cdev->lock);
+	mutex_unlock(&tz->lock);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(thermal_trip_is_bound_to_cdev);
+
 struct thermal_instance *
 get_thermal_instance(struct thermal_zone_device *tz,
 		     struct thermal_cooling_device *cdev, int trip_index)
 {
-	struct thermal_instance *pos = NULL;
-	struct thermal_instance *target_instance = NULL;
-	const struct thermal_trip *trip;
+	struct thermal_instance *ti;
 
 	mutex_lock(&tz->lock);
 	mutex_lock(&cdev->lock);
 
-	trip = &tz->trips[trip_index].trip;
-
-	list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
-		if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
-			target_instance = pos;
-			break;
-		}
-	}
+	ti = get_instance(tz, cdev, &tz->trips[trip_index].trip);
 
 	mutex_unlock(&cdev->lock);
 	mutex_unlock(&tz->lock);
 
-	return target_instance;
+	return ti;
 }
 EXPORT_SYMBOL(get_thermal_instance);
 
Index: linux-pm/include/linux/thermal.h
===================================================================
--- linux-pm.orig/include/linux/thermal.h
+++ linux-pm/include/linux/thermal.h
@@ -269,6 +269,9 @@ struct thermal_zone_device *thermal_zone
 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
 int thermal_zone_get_slope(struct thermal_zone_device *tz);
 int thermal_zone_get_offset(struct thermal_zone_device *tz);
+bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
+				   const struct thermal_trip *trip,
+				   struct thermal_cooling_device *cdev);
 
 int thermal_zone_device_enable(struct thermal_zone_device *tz);
 int thermal_zone_device_disable(struct thermal_zone_device *tz);




  parent reply	other threads:[~2024-06-17 18:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-17 17:41 [PATCH v1 00/14] thermal: Eliminate trip IDs from thermal driver interface Rafael J. Wysocki
2024-06-17 17:48 ` [PATCH v1 01/14] thermal: imx: Drop critical trip check from imx_set_trip_temp() Rafael J. Wysocki
2024-06-17 17:49 ` Rafael J. Wysocki [this message]
2024-06-17 17:56 ` [PATCH v1 03/14] thermal: trip: Add conversion macros for thermal trip priv field Rafael J. Wysocki
2024-06-17 17:56 ` [PATCH v1 04/14] thermal: trip: Pass trip pointer to .set_trip_temp() thermal zone callback Rafael J. Wysocki
2024-06-17 17:56 ` [PATCH v1 05/14] thermal: trip: Fold __thermal_zone_get_trip() into its caller Rafael J. Wysocki
2024-06-17 17:57 ` [PATCH v1 06/14] thermal: broadcom: Use thermal_zone_get_crit_temp() in bcm2835_thermal_probe() Rafael J. Wysocki
2024-06-17 17:58 ` [PATCH v1 07/14] thermal: hisi: Use thermal_zone_for_each_trip() in hisi_thermal_register_sensor() Rafael J. Wysocki
2024-06-17 18:00 ` [PATCH v1 08/14] thermal: qcom: Use thermal_zone_get_crit_temp() in qpnp_tm_init() Rafael J. Wysocki
2024-06-17 18:02 ` [PATCH v1 09/14] thermal: tegra: Introduce struct trip_temps for critical and hot trips Rafael J. Wysocki
2024-06-17 18:03 ` [PATCH v1 10/14] thermal: tegra: Use thermal_zone_for_each_trip() for walking trip points Rafael J. Wysocki
2024-06-17 18:05 ` [PATCH v1 11/14] thermal: helpers: Drop get_thermal_instance() Rafael J. Wysocki
2024-06-17 18:07 ` [PATCH v1 12/14] thermal: uniphier: Use thermal_zone_for_each_trip() for walking trip points Rafael J. Wysocki
2024-06-18  4:03   ` Kunihiko Hayashi
2024-06-18 13:06     ` Rafael J. Wysocki
2024-06-17 18:11 ` [PATCH v1 13/14] thermal: trip: Replace thermal_zone_get_num_trips() Rafael J. Wysocki
2024-06-17 18:39   ` Niklas Söderlund
2024-06-17 18:55     ` Rafael J. Wysocki
2024-06-17 19:02       ` Rafael J. Wysocki
2024-06-17 18:12 ` [PATCH v1 14/14] thermal: trip: Drop thermal_zone_get_trip() Rafael J. Wysocki

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=2013201.usQuhbGJ8B@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=daniel.lezcano@linaro.org \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    --cc=thierry.reding@gmail.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;
as well as URLs for NNTP newsgroup(s).