public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM <linux-pm@vger.kernel.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	linux-tegra@vger.kernel.org
Subject: [RESEND][PATCH v1 4/8] thermal: tegra: Introduce struct trip_temps for critical and hot trips
Date: Mon, 29 Jul 2024 18:02:22 +0200	[thread overview]
Message-ID: <9333090.CDJkKcVGEf@rjwysocki.net> (raw)
In-Reply-To: <2211925.irdbgypaU6@rjwysocki.net>

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

Introduce a helper structure, struct trip_temps, for storing the
temperatures of the critical and hot trip points.

This helps to make the code in tegra_tsensor_get_hw_channel_trips()
somewhat cleaner and will be useful subsequently in eliminating
iteration over trip indices from the driver.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

This patch does not depend on the previous patch(es) in the series.

---
 drivers/thermal/tegra/tegra30-tsensor.c |   34 ++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

Index: linux-pm/drivers/thermal/tegra/tegra30-tsensor.c
===================================================================
--- linux-pm.orig/drivers/thermal/tegra/tegra30-tsensor.c
+++ linux-pm/drivers/thermal/tegra/tegra30-tsensor.c
@@ -303,8 +303,13 @@ stop_channel:
 	return 0;
 }
 
+struct trip_temps {
+	int hot_trip;
+	int crit_trip;
+};
+
 static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
-					       int *hot_trip, int *crit_trip)
+					       struct trip_temps *temps)
 {
 	unsigned int i;
 
@@ -312,8 +317,8 @@ static void tegra_tsensor_get_hw_channel
 	 * 90C is the maximal critical temperature of all Tegra30 SoC variants,
 	 * use it for the default trip if unspecified in a device-tree.
 	 */
-	*hot_trip  = 85000;
-	*crit_trip = 90000;
+	temps->hot_trip  = 85000;
+	temps->crit_trip = 90000;
 
 	for (i = 0; i < thermal_zone_get_num_trips(tzd); i++) {
 
@@ -322,14 +327,14 @@ static void tegra_tsensor_get_hw_channel
 		thermal_zone_get_trip(tzd, i, &trip);
 
 		if (trip.type == THERMAL_TRIP_HOT)
-			*hot_trip = trip.temperature;
+			temps->hot_trip = trip.temperature;
 
 		if (trip.type == THERMAL_TRIP_CRITICAL)
-			*crit_trip = trip.temperature;
+			temps->crit_trip = trip.temperature;
 	}
 
 	/* clamp hardware trips to the calibration limits */
-	*hot_trip = clamp(*hot_trip, 25000, 90000);
+	temps->hot_trip = clamp(temps->hot_trip, 25000, 90000);
 
 	/*
 	 * Kernel will perform a normal system shut down if it will
@@ -338,7 +343,7 @@ static void tegra_tsensor_get_hw_channel
 	 * shut down gracefully before sending signal to the Power
 	 * Management controller.
 	 */
-	*crit_trip = clamp(*crit_trip + 5000, 25000, 90000);
+	temps->crit_trip = clamp(temps->crit_trip + 5000, 25000, 90000);
 }
 
 static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,
@@ -346,7 +351,8 @@ static int tegra_tsensor_enable_hw_chann
 {
 	const struct tegra_tsensor_channel *tsc = &ts->ch[id];
 	struct thermal_zone_device *tzd = tsc->tzd;
-	int err, hot_trip = 0, crit_trip = 0;
+	struct trip_temps temps = { 0 };
+	int err;
 	u32 val;
 
 	if (!tzd) {
@@ -357,24 +363,24 @@ static int tegra_tsensor_enable_hw_chann
 		return 0;
 	}
 
-	tegra_tsensor_get_hw_channel_trips(tzd, &hot_trip, &crit_trip);
+	tegra_tsensor_get_hw_channel_trips(tzd, &temps);
 
 	dev_info_once(ts->dev, "ch%u: PMC emergency shutdown trip set to %dC\n",
-		      id, DIV_ROUND_CLOSEST(crit_trip, 1000));
+		      id, DIV_ROUND_CLOSEST(temps.crit_trip, 1000));
 
-	hot_trip  = tegra_tsensor_temp_to_counter(ts, hot_trip);
-	crit_trip = tegra_tsensor_temp_to_counter(ts, crit_trip);
+	temps.hot_trip  = tegra_tsensor_temp_to_counter(ts, temps.hot_trip);
+	temps.crit_trip = tegra_tsensor_temp_to_counter(ts, temps.crit_trip);
 
 	/* program LEVEL2 counter threshold */
 	val = readl_relaxed(tsc->regs + TSENSOR_SENSOR0_CONFIG1);
 	val &= ~TSENSOR_SENSOR0_CONFIG1_TH2;
-	val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG1_TH2, hot_trip);
+	val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG1_TH2, temps.hot_trip);
 	writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG1);
 
 	/* program LEVEL3 counter threshold */
 	val = readl_relaxed(tsc->regs + TSENSOR_SENSOR0_CONFIG2);
 	val &= ~TSENSOR_SENSOR0_CONFIG2_TH3;
-	val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG2_TH3, crit_trip);
+	val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG2_TH3, temps.crit_trip);
 	writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG2);
 
 	/*




  parent reply	other threads:[~2024-07-29 17:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-29 15:50 [RESEND][PATCH v1 0/8] thermal: Use trip pointers in thermal driver interface Rafael J. Wysocki
2024-07-29 15:53 ` [RESEND][PATCH v1 1/8] thermal: broadcom: Use thermal_zone_get_crit_temp() in bcm2835_thermal_probe() Rafael J. Wysocki
2024-07-29 21:54   ` Florian Fainelli
2024-08-02  9:36   ` Lukasz Luba
2024-07-29 15:56 ` [RESEND][PATCH v1 2/8] thermal: hisi: Use thermal_zone_for_each_trip() in hisi_thermal_register_sensor() Rafael J. Wysocki
2024-08-02  9:35   ` Lukasz Luba
2024-07-29 15:58 ` [RESEND][PATCH v1 3/8] thermal: qcom: Use thermal_zone_get_crit_temp() in qpnp_tm_init() Rafael J. Wysocki
2024-08-02  9:37   ` Lukasz Luba
2024-08-14  5:09   ` Amit Kucheria
2024-07-29 16:02 ` Rafael J. Wysocki [this message]
2024-08-02  9:40   ` [RESEND][PATCH v1 4/8] thermal: tegra: Introduce struct trip_temps for critical and hot trips Lukasz Luba
2024-07-29 16:05 ` [RESEND][PATCH v1 5/8] thermal: tegra: Use thermal_zone_for_each_trip() for walking trip points Rafael J. Wysocki
2024-08-02  9:47   ` Lukasz Luba
2024-07-29 16:06 ` [RESEND][PATCH v1 6/8] thermal: helpers: Drop get_thermal_instance() Rafael J. Wysocki
2024-08-02  9:53   ` Lukasz Luba
2024-07-29 16:11 ` [PATCH v2 7/8] thermal: trip: Get rid of thermal_zone_get_num_trips() Rafael J. Wysocki
2024-07-30 10:37   ` Niklas Söderlund
2024-08-02  9:55   ` Lukasz Luba
2024-07-29 16:12 ` [RESEND][PATCH v1 8/8] thermal: trip: Drop thermal_zone_get_trip() Rafael J. Wysocki
2024-08-02  9:56   ` Lukasz Luba

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=9333090.CDJkKcVGEf@rjwysocki.net \
    --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=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