devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Bailon <abailon@baylibre.com>
To: rafael@kernel.org, daniel.lezcano@linaro.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org
Cc: rui.zhang@intel.com, lukasz.luba@arm.com,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Alexandre Bailon <abailon@baylibre.com>
Subject: [PATCH v3 5/6] thermal: of: Parse aggregation property to select the aggegration type
Date: Fri, 24 May 2024 16:31:49 +0200	[thread overview]
Message-ID: <20240524143150.610949-6-abailon@baylibre.com> (raw)
In-Reply-To: <20240524143150.610949-1-abailon@baylibre.com>

This updates the driver to parse the aggegration property in DT.
This allows selecting the aggregation function to apply for multi
sensors thermal zone.

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
---
 drivers/thermal/thermal_of.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 75e3cfb8488a..21c81dc91a41 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -533,6 +533,33 @@ static void thermal_of_zone_unregister(struct thermal_zone_device *tz)
 	thermal_zone_device_unregister(tz);
 }
 
+static const char * const aggr_types[] = {
+	[THERMAL_AGGR_AVG]	= "avg",
+	[THERMAL_AGGR_MAX]	= "max",
+};
+
+static int thermal_of_multi_sensor_get_type(struct device_node *np,
+					    enum thermal_aggregation_type *type)
+{
+	const char *t;
+	int err, i;
+
+	err = of_property_read_string(np, "aggregation", &t);
+	if (err < 0) {
+		*type = THERMAL_AGGR_AVG;
+		return 0;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(aggr_types); i++) {
+		if (!strcasecmp(t, aggr_types[i])) {
+			*type = i;
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
 static int thermal_of_multi_sensor_validate_coeff(struct device_node *sensor, int id,
 						  struct device_node *tz_np)
 {
@@ -606,6 +633,7 @@ thermal_of_register_multi_tz(struct device_node *sensor, int id, struct device_n
 			     int polling_delay)
 {
 	struct thermal_zone_device *multi_tz, *tz;
+	enum thermal_aggregation_type aggr_type;
 	char name[THERMAL_NAME_LENGTH];
 	u32 coeff;
 	int ret;
@@ -614,6 +642,10 @@ thermal_of_register_multi_tz(struct device_node *sensor, int id, struct device_n
 	if (!multi_tz) {
 		struct thermal_zone_device_ops *multi_ops;
 
+		ret = thermal_of_multi_sensor_get_type(np, &aggr_type);
+		if (ret)
+			return ERR_PTR(ret);
+
 		ret = thermal_of_multi_sensor_validate_coeff(sensor, id, np);
 		if (ret)
 			return ERR_PTR(ret);
-- 
2.44.1


  parent reply	other threads:[~2024-05-24 14:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-24 14:31 [PATCH v3 0/6] thermal: Add support of multiple sensors Alexandre Bailon
2024-05-24 14:31 ` [PATCH v3 1/6] dt-bindings: thermal: Restore the thermal-sensors property Alexandre Bailon
2024-05-24 14:31 ` [PATCH v3 2/6] thermal: Add support of multi sensors to thermal_core Alexandre Bailon
2024-05-27  7:00   ` Krzysztof Kozlowski
2024-05-27  7:02     ` Krzysztof Kozlowski
2024-05-29  8:23     ` Alexandre Bailon
2024-05-24 14:31 ` [PATCH v3 3/6] thermal: Add support of multi sensors to thermal_of Alexandre Bailon
2024-05-24 14:31 ` [PATCH v3 4/6] dt-bindings: thermal: Add a property to select the aggregation type Alexandre Bailon
2024-05-27  6:55   ` Krzysztof Kozlowski
2024-05-29  8:06     ` Alexandre Bailon
2024-05-28 17:00   ` Rob Herring
2024-05-24 14:31 ` Alexandre Bailon [this message]
2024-05-24 14:31 ` [PATCH v3 6/6] ARM64: mt8195: Use thermal aggregation for big and little cpu Alexandre Bailon
2024-05-27  6:56   ` Krzysztof Kozlowski
2024-05-29  8:19     ` Alexandre Bailon
2024-05-29 12:39       ` Krzysztof Kozlowski

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=20240524143150.610949-6-abailon@baylibre.com \
    --to=abailon@baylibre.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).