From nobody Fri Feb 13 15:03:55 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99E7C12BF3D for ; Fri, 24 May 2024 14:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561120; cv=none; b=bFHSZpLUlymYg0svDE9xGyS5JxTe0rb/iWknrhoE77LpTF8lpt2lv+9a3nkgyw2cL3FFjPDR7zw5oIMve/s6WNPMYVbC/7w3I0lfk8KnDdjbE0xnkIH7VAdDW6xwFuahW+4YbvFluNS6UOuQHGUXa42Irsy0pffqYggb+uU4pF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561120; c=relaxed/simple; bh=rnldv7833XODCkkhE2IoJHX1ijFNhpuCcMgGUEpMC7w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nbdMstk5TNDmJzkv6RYQnGcwnr+WcyR6y8mXYN8fItI1ayZr6X2ykBB1p6NSSTOY8jlJNum092pNQ82U3UJ+eZdeLjXY36IQdwcGz5uwhdgVhkYKKqtJyeEJoJyUGNRpZ5V5bSBDqWzz8PwL7ETxL9pyP4GliZqLDOBR7Iq7Ids= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=rpyKTH5i; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="rpyKTH5i" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4200ee47de7so66155395e9.2 for ; Fri, 24 May 2024 07:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1716561116; x=1717165916; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SJ3mx1HRwERqoH8XmiCBcC2qPne8ED2LI938/bq1eLA=; b=rpyKTH5iQvriVyQD9mnPFPiJuyP0PXkrW+qDjdhDArRSrkNndcJ7XZuSorzwsAspCH ByKOyD+mKqoeQoQYrtQ2ihQQx7pafWGC5pxFHOMJe44JMvj8NdZZ7hRIwpdKGjWUW1gY 6aGICS8m6/gI/5Ige1l9vmHmlfe3cQUZJQelXFtyfcwicuzoHbaTJPJ3Ira35WdHZxGg T1KLm8fE49gRAAG/nysHvEUAkq8eKUXj5IZ8C9KrHnYRND0iWdQocMjmkstwRM0PiVC2 tRC5qbhFL17ap3FlUrg47jHRwsAfwzV670AcseVot1k2ciuIjIWSfQ6BIcoEZedIQtnR Nhrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716561116; x=1717165916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SJ3mx1HRwERqoH8XmiCBcC2qPne8ED2LI938/bq1eLA=; b=j6hbJyZMMB+FprYHyM3DPhFrewAFCcn2CYoTi881AuJiPOdzE7zYVhhLJdWE40dU3D atyi+fD7++CeqbgzemYgtrvoRqZypCADaRfTm0GErha/XvLNfJa8EZxlGZ8rihtNAY7q LxvTR3l2qxbGgcUWwdKTzITwQ8zw4uGvWOGc26qPLen8bv2fu+uAN59eVtDVsws6Fbqx Fw7GbvyAG2FqfD/mCikPPfvCQZf8WhJMc+yKu7Tnxzp9NY4DbXHyogtVmK38uweA5GSn 9fF1zcNiS/Ivl2TWJATtIOAFKisaPt+PGn07Ler5sRBJIgKbehzgDZb6iurSd2I5ytnB XTww== X-Forwarded-Encrypted: i=1; AJvYcCU8NRsflaOKtdmwXO8nXDUrJ8pHfpJmp3+moEYSnjAUuhlxRj76mFqt2g156bZ22BdRHTuzb6n+3twhGygk5ceRknsPfa+JpNHx+OPv X-Gm-Message-State: AOJu0YxwlRBqmrh4RgQMJMrwLVbfVzvGtLG7mfBOxzQDv4VqNuBZrHpn h7DQy4gChXqSGd3+U4wIkht7SMp+RswzNN4OZq5PnzuRBQ29FDSrdUhsL+OV+jM= X-Google-Smtp-Source: AGHT+IHeazyAYbEcDfkZpobbZA+PYRdLXkVlFupJmpkvVRjYWEJntrAScewAKlYFPKugfsjlI9OUkQ== X-Received: by 2002:adf:cd91:0:b0:356:48f5:437b with SMTP id ffacd0b85a97d-35648f546camr1349067f8f.32.1716561116049; Fri, 24 May 2024 07:31:56 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a090c2bsm1719611f8f.59.2024.05.24.07.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 07:31:54 -0700 (PDT) From: Alexandre Bailon 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 , Rob Herring Subject: [PATCH v3 1/6] dt-bindings: thermal: Restore the thermal-sensors property Date: Fri, 24 May 2024 16:31:45 +0200 Message-ID: <20240524143150.610949-2-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240524143150.610949-1-abailon@baylibre.com> References: <20240524143150.610949-1-abailon@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" thermal-sensors was defined in thermal.txt but when the yaml binding has been defined, its definition has changed, dropping support of multi sensors. Since we are adding support of multi sensors, use the original definition for thermal-sensors property. Signed-off-by: Alexandre Bailon Reviewed-by: Rob Herring --- Documentation/devicetree/bindings/thermal/thermal-zones.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/thermal/thermal-zones.yaml b= /Documentation/devicetree/bindings/thermal/thermal-zones.yaml index 68398e7e8655..fa7a72e2ba44 100644 --- a/Documentation/devicetree/bindings/thermal/thermal-zones.yaml +++ b/Documentation/devicetree/bindings/thermal/thermal-zones.yaml @@ -93,10 +93,9 @@ patternProperties: =20 thermal-sensors: $ref: /schemas/types.yaml#/definitions/phandle-array - maxItems: 1 description: - The thermal sensor phandle and sensor specifier used to monitor = this - thermal zone. + A list of thermal sensor phandles and sensor specifier + used while monitoring the thermal zone. =20 coefficients: $ref: /schemas/types.yaml#/definitions/uint32-array --=20 2.44.1 From nobody Fri Feb 13 15:03:55 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EEBF12C555 for ; Fri, 24 May 2024 14:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561121; cv=none; b=NDgqXt3tiwG1wgEM7hrV/st7dPxLGUDm+9FXBacRMD7SS9WbcYmNrDLDcshq0MnfXDQSH4iK4XfSdYoxaVYeXP61NH7g7CqxcbzdBsYbyBPJBzIuZKr0141XlkOSqH6f/ffyGS5VvnOhBPWtGHa6Q8GZjPBGn7++RnIKmP0AdTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561121; c=relaxed/simple; bh=mPXSWVM/lWJTvxx8Sk78MOF9pL+YlUVhGWXRjiz7bfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fedXs2HX0RE6d2RYXLD0iie/2OQctSdKQxzIfShZDSy/r2NRiexiWg9I9U/Knd5SrTbYOJCj1f8LQGQglOg/U0c9oUGvFALapdbJntBcR7jjtdrtkwzdt0zfa4vPQTgPz2JidJoCBAVXpcCtWBNK/B/O0cKp7D7kv0NDczNRAt8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=K5E0dJYk; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="K5E0dJYk" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-354cd8da8b9so3260473f8f.0 for ; Fri, 24 May 2024 07:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1716561118; x=1717165918; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6+j9xOE0tYjxUOHMPpSuPZogtIBOsTQZVZMBTvXII0g=; b=K5E0dJYkZaZjooZzdssubRRRjVemvkEzI3Q4pMLIeZmBJ7RGZYGeQUH2DfJgr5tR3o MraRTaFpOJa5IATWuXiXXPjzSI57cTXHOSpTp6U5Wm5qox/JIbTujcuPRpEEbhO9sqNH dgosnspKTplnwRhfaNdW6WoQpJ6JvgTI3ijSOSSts44zJNBUSJ7iN7cbH77LwkY07jhc Z97SZ/PwntEGhkdclhuYPSbgGXIqmp6+GiGXJLw0MoIClj3i5DIMe+6IybLBEmFdzbUL VZCD5UHbRICMJdB8Fy7VwWVakYT0npPVVUtIfHj4F3FYggcAIj6b57yWyToNr+ipGBra 8xfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716561118; x=1717165918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6+j9xOE0tYjxUOHMPpSuPZogtIBOsTQZVZMBTvXII0g=; b=foIxO9sPikPlHwlyv8GZUmrLrhOzCqKutsJY6AT14bEr8o+yGQxdIKShlHyXkRAzl5 fUwYLrKK47whTcj40uB7X739GrTTRneK7P1ifAGsJEA9G5xaXDAjRWtlkjXFhH1fXS/i T1hEdO5p4b0lGeyFTAXOCfZTdO2HPgekD92syYQmjNFio8afxT6RuZFW2kZFgEKY9PNt g1DxATVoYyebR05IprmT9TcModslJUYDlsWW3jhAZhCgHoX9dZgjJPueFuBnKiwE9HtE t4hdwtb+W8k2BpjymbNmhpkXkqEvn5i9/ESDFR8Fmjv+qWsoK6e4moIk4d83LO1muBWI WTUA== X-Forwarded-Encrypted: i=1; AJvYcCWYgJ6dXKcH//HfYs7GGhKFcd5GS6HmkdX6gvSpl+fKJ9m8Rv8kWqtsNGlFgKWXsp6Y5FqwC9VhqivDcGfAFo5IRp+LKq+6GGMrdBqv X-Gm-Message-State: AOJu0YxFuPhHXUUai6Zc44BZy4VAumE+nXNCESfp9YNfX/I0sR4hmg8v 8Ck958UgmNzv4boIUw/b+AoIDUvU5NRQjvKyuXfpxukc9VNOl+bEr2wHTqGn1C0= X-Google-Smtp-Source: AGHT+IH5y0F3sHdzgvtSPWAAwV1/nrn57MOWODWjtpU2gpn/5+qDWgV6Q2DiZ9JVGquT4dNU8LJy9w== X-Received: by 2002:adf:f746:0:b0:354:eb62:365c with SMTP id ffacd0b85a97d-3552217fd10mr1577173f8f.15.1716561117567; Fri, 24 May 2024 07:31:57 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a090c2bsm1719611f8f.59.2024.05.24.07.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 07:31:56 -0700 (PDT) From: Alexandre Bailon 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 Subject: [PATCH v3 2/6] thermal: Add support of multi sensors to thermal_core Date: Fri, 24 May 2024 16:31:46 +0200 Message-ID: <20240524143150.610949-3-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240524143150.610949-1-abailon@baylibre.com> References: <20240524143150.610949-1-abailon@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This adds support of multi sensors to thermal. Currently, this only support the get_temp operation. This returns an average temperature of all the sensors. If defined, a coefficient is applied to the value read from the sensor before computing the average. Signed-off-by: Alexandre Bailon --- drivers/thermal/Makefile | 1 + drivers/thermal/thermal_core.h | 15 ++ drivers/thermal/thermal_multi.c | 332 ++++++++++++++++++++++++++++++++ include/uapi/linux/thermal.h | 5 + 4 files changed, 353 insertions(+) create mode 100644 drivers/thermal/thermal_multi.c diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 5cdf7d68687f..872190f9062b 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -6,6 +6,7 @@ CFLAGS_thermal_core.o :=3D -I$(src) obj-$(CONFIG_THERMAL) +=3D thermal_sys.o thermal_sys-y +=3D thermal_core.o thermal_sysfs.o thermal_sys-y +=3D thermal_trip.o thermal_helpers.o +thermal_sys-y +=3D thermal_multi.o =20 # netlink interface to manage the thermal framework thermal_sys-$(CONFIG_THERMAL_NETLINK) +=3D thermal_netlink.o diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index 0d8a42bb7ce8..224735b644bc 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -142,6 +142,21 @@ ssize_t weight_show(struct device *, struct device_att= ribute *, char *); ssize_t weight_store(struct device *, struct device_attribute *, const cha= r *, size_t); =20 +/* Multi sensors */ +struct thermal_zone_device *thermal_multi_sensor_find_tz(const char *type); +struct thermal_zone_device_ops *thermal_multi_sensor_alloc_ops(int aggr_ty= pe); +struct thermal_zone_device *thermal_multi_sensor_tz_alloc(const char *type, + struct thermal_trip *trips, + int num_trips, + struct thermal_zone_device_ops *ops, + int passive_delay, int polling_delay); +void thermal_multi_sensor_tz_free(struct thermal_zone_device *tz); +int thermal_multi_sensor_validate_coeff(int *coeff, int count, int offset); +int thermal_multi_sensor_register(struct thermal_zone_device *tz, + struct thermal_zone_device *sensor_tz, int coeff); +void thermal_multi_sensor_unregister(struct thermal_zone_device *sensor_tz= ); + + #ifdef CONFIG_THERMAL_STATISTICS void thermal_cooling_device_stats_update(struct thermal_cooling_device *cd= ev, unsigned long new_state); diff --git a/drivers/thermal/thermal_multi.c b/drivers/thermal/thermal_mult= i.c new file mode 100644 index 000000000000..cee0ded8dc25 --- /dev/null +++ b/drivers/thermal/thermal_multi.c @@ -0,0 +1,332 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include + +#include "thermal_core.h" + +struct sensor_interface { + struct thermal_zone_device *tz; + int coeff; + + struct list_head node; +}; + +struct multi_sensor_thermal_zone { + struct thermal_zone_device *tz; + struct mutex sensors_lock; + struct list_head sensors; + + struct list_head node; +}; + +static DEFINE_MUTEX(multi_tz_mutex); +static LIST_HEAD(multi_tz_list); + +#define TJ_MAX 120000 + +static int multi_sensor_get_temp(struct thermal_zone_device *tz, int *temp) +{ + struct multi_sensor_thermal_zone *multi_tz =3D tz->devdata; + struct sensor_interface *sensor; + int accumulated_temp =3D 0; + u32 accumulated_coeff =3D 0; + int ret; + + mutex_lock(&multi_tz->sensors_lock); + + if (list_empty(&multi_tz->sensors)) { + mutex_unlock(&multi_tz->sensors_lock); + return -ENODEV; + } + + list_for_each_entry(sensor, &multi_tz->sensors, node) { + ret =3D thermal_zone_get_temp(sensor->tz, temp); + if (ret) { + mutex_unlock(&multi_tz->sensors_lock); + return ret; + } + + accumulated_temp +=3D *temp * sensor->coeff; + accumulated_coeff +=3D sensor->coeff; + } + + mutex_unlock(&multi_tz->sensors_lock); + + *temp =3D accumulated_temp / accumulated_coeff; + return ret; +} + +static int multi_sensor_get_temp_max(struct thermal_zone_device *tz, int *= temp) +{ + struct multi_sensor_thermal_zone *multi_tz =3D tz->devdata; + struct sensor_interface *sensor; + int max_temp; + int ret; + + mutex_lock(&multi_tz->sensors_lock); + + if (list_empty(&multi_tz->sensors)) { + mutex_unlock(&multi_tz->sensors_lock); + return -ENODEV; + } + + list_for_each_entry(sensor, &multi_tz->sensors, node) { + ret =3D thermal_zone_get_temp(sensor->tz, temp); + if (ret) { + mutex_unlock(&multi_tz->sensors_lock); + return ret; + } + + max_temp =3D max(max_temp, *temp * sensor->coeff); + } + + mutex_unlock(&multi_tz->sensors_lock); + + *temp =3D max_temp; + return ret; +} + +/** + * Check if the sum of the coefficients multiplied by sensors temperature = plus + * an offset won't overflow during the aggregation. + * @coeff: An array of coefficient + * @count: Number of coefficient + * @offset: The offset + * + * Returns: 0 if the coefficient are safe, -EOVERFLOW otherwise + */ +int thermal_multi_sensor_validate_coeff(int *coeff, int count, int offset) +{ + int max_accumulated_temp =3D 0; + int i; + + for (i =3D 0; i < count; i++) { + max_accumulated_temp +=3D TJ_MAX * coeff[i]; + if (max_accumulated_temp < 0) + return -EOVERFLOW; + } + + max_accumulated_temp +=3D offset; + return max_accumulated_temp < 0 ? -EOVERFLOW : 0; +} + +/** + * Find a multi sensor thermal zone + * @type: The thermal zone type to find + * + * Returns: a pointer to the thermal zone or NULL if not found + */ +struct thermal_zone_device *thermal_multi_sensor_find_tz(const char *type) +{ + struct thermal_zone_device *tz; + + tz =3D thermal_zone_get_zone_by_name(type); + if (IS_ERR(tz)) + return NULL; + return tz; +} + +/** + * Allocate a struct thermal_zone_device_ops for the multi sensor thermal = zoen + * + * This allocates a struct thermal_zone_device_ops with a predifiend get_t= emp + * operation. This allows setting the other function pointers before regis= tering + * the thermal zone. + * + * @aggr_type: The aggregation type to use (THERMAL_AGGR_AVG or THERMAL_AG= GR_MAX) + * + * Returns: a pointer to the created struct thermal_zone_device_ops or an + * in case of error, an ERR_PTR. Caller must check return value with + * IS_ERR*() helpers. + */ +struct thermal_zone_device_ops *thermal_multi_sensor_alloc_ops(int aggr_ty= pe) +{ + struct thermal_zone_device_ops *ops; + + ops =3D kzalloc(sizeof(*ops), GFP_KERNEL); + if (!ops) + return ERR_PTR(-ENOMEM); + + switch (aggr_type) { + case THERMAL_AGGR_AVG: + ops->get_temp =3D multi_sensor_get_temp; + break; + case THERMAL_AGGR_MAX: + ops->get_temp =3D multi_sensor_get_temp_max; + break; + default: + kfree(ops); + return ERR_PTR(-EINVAL); + } + + return ops; +} + +/** + * Register a new thermal zone device that supports multi sensors + * @type: the thermal zone device type + * @trips: a pointer to an array of thermal trips + * @num_trips: the number of trip points the thermal zone support + * @mask: a bit string indicating the writeablility of trip points + * @ops: standard thermal zone device callbacks + * @passive_delay: number of milliseconds to wait between polls when + * performing passive cooling + * @polling_delay: number of milliseconds to wait between polls when check= ing + * whether trip points have been crossed (0 for interrupt + * driven systems) + * + * This function allocates and register a multi sensor thermal zone. + * To register a sensor to this thermal zone, use thermal_multi_sensor_reg= ister(). + * thermal_multi_sensor_unregister() must be called to unregister the sens= ors + * and release this thermal zone when it is not used anymore. + * + * Return: a pointer to the created struct thermal_zone_device or an + * in case of error, an ERR_PTR. Caller must check return value with + * IS_ERR*() helpers. + */ +struct thermal_zone_device *thermal_multi_sensor_tz_alloc(const char *type, + struct thermal_trip *trips, + int num_trips, + struct thermal_zone_device_ops *ops, + int passive_delay, int polling_delay) +{ + struct thermal_zone_device *tz; + struct thermal_zone_params tzp =3D {}; + struct multi_sensor_thermal_zone *multi_tz; + + mutex_lock(&multi_tz_mutex); + + tz =3D thermal_zone_get_zone_by_name(type); + if (!IS_ERR(tz)) + goto unlock; + + multi_tz =3D kzalloc(sizeof(*multi_tz), GFP_KERNEL); + if (!multi_tz) { + tz =3D ERR_PTR(-ENOMEM); + goto unlock; + } + mutex_init(&multi_tz->sensors_lock); + INIT_LIST_HEAD(&multi_tz->sensors); + + tzp.no_hwmon =3D true; + tzp.slope =3D 1; + tzp.offset =3D 0; + + tz =3D thermal_zone_device_register_with_trips(type, trips, num_trips, + multi_tz, ops, &tzp, + passive_delay, polling_delay); + if (IS_ERR(tz)) { + kfree(multi_tz); + } else { + multi_tz->tz =3D tz; + list_add(&multi_tz->node, &multi_tz_list); + } + +unlock: + mutex_unlock(&multi_tz_mutex); + return tz; +} + +/** + * Remove all sensors from multi sensor thermal zone and release it + * + * This function must not be used except on error path to correctly + * release all the allocated resources. + * Use thermal_multi_sensor_unregister() to unregister a sensor and + * release a thermal zone that is not used anymore. + * + * @tz: Pointer to thermal zone to release + */ +void thermal_multi_sensor_tz_free(struct thermal_zone_device *tz) +{ + struct multi_sensor_thermal_zone *multi_tz =3D tz->devdata; + struct thermal_trip *trips =3D tz->trips; + struct thermal_zone_device_ops *ops =3D &tz->ops; + struct sensor_interface *sensor, *tmp; + + list_for_each_entry_safe(sensor, tmp, &multi_tz->sensors, node) { + list_del(&sensor->node); + kfree(sensor); + } + + thermal_zone_device_unregister(tz); + list_del(&multi_tz->node); + kfree(multi_tz); + kfree(trips); + kfree(ops); +} + +/** + * Register a thermal sensor to a multi sensor thermal zone + * @tz: The multi sensor thermal zone + * @sensor_tz: The thermal zone of the zensor to register + * @coeff: The coefficient to apply to the temperature returned by the sen= sor + * + * Returns: On success 0, a negative value in case of error + */ +int thermal_multi_sensor_register(struct thermal_zone_device *tz, + struct thermal_zone_device *sensor_tz, + int coeff) +{ + struct multi_sensor_thermal_zone *multi_tz; + struct sensor_interface *sensor; + + mutex_lock(&multi_tz_mutex); + + multi_tz =3D tz->devdata; + + sensor =3D kzalloc(sizeof(*sensor), GFP_KERNEL); + if (!sensor) { + mutex_unlock(&multi_tz_mutex); + return -ENOMEM; + } + + sensor->tz =3D sensor_tz; + sensor->coeff =3D coeff; + mutex_lock(&multi_tz->sensors_lock); + list_add(&sensor->node, &multi_tz->sensors); + mutex_unlock(&multi_tz->sensors_lock); + + thermal_zone_device_enable(tz); + + mutex_unlock(&multi_tz_mutex); + + return 0; +} + +/** + * Unregister a thermal sensor from a multi sensor thermal zone + * + * This unregister a thermal sensor from a multi sensor thermal zone. + * If all the sensors have been removed then this also release the multi s= ensor + * thermal zone. + * @sensor_tz: The sensor to unregister + */ +void thermal_multi_sensor_unregister(struct thermal_zone_device *sensor_tz) +{ + struct multi_sensor_thermal_zone *multi_tz, *tmp_tz; + struct sensor_interface *sensor, *tmp; + + mutex_lock(&multi_tz_mutex); + list_for_each_entry_safe(multi_tz, tmp_tz, &multi_tz_list, node) { + mutex_lock(&multi_tz->sensors_lock); + list_for_each_entry_safe(sensor, tmp, &multi_tz->sensors, node) { + if (sensor->tz =3D=3D sensor_tz) { + list_del(&sensor->node); + kfree(sensor); + break; + } + } + mutex_unlock(&multi_tz->sensors_lock); + + if (list_empty(&multi_tz->sensors)) + thermal_multi_sensor_tz_free(multi_tz->tz); + } + mutex_unlock(&multi_tz_mutex); +} diff --git a/include/uapi/linux/thermal.h b/include/uapi/linux/thermal.h index fc78bf3aead7..e4f6c4c5e6fd 100644 --- a/include/uapi/linux/thermal.h +++ b/include/uapi/linux/thermal.h @@ -16,6 +16,11 @@ enum thermal_trip_type { THERMAL_TRIP_CRITICAL, }; =20 +enum thermal_aggregation_type { + THERMAL_AGGR_AVG =3D 0, + THERMAL_AGGR_MAX =3D 1, +}; + /* Adding event notification support elements */ #define THERMAL_GENL_FAMILY_NAME "thermal" #define THERMAL_GENL_VERSION 0x01 --=20 2.44.1 From nobody Fri Feb 13 15:03:55 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2228312C805 for ; Fri, 24 May 2024 14:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561122; cv=none; b=t/Wk4DZHZSvszjGsN4xYAnsVdPyzQ0XwdF33UZ2TxR2/hrWIl3/0qyg62+fjgJfNqkaH0AEzsLEfOsXAI7/T7XRvPbPfEmC574d7xHpXU77zaHxmL65pIBnp6jwKckDKtfrOQnRgqpVju72b0xeBDPM9qi7mFSZUqlSfb2U1rXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561122; c=relaxed/simple; bh=XxQPs+CKFd+C8xKkktDLuby2qDkISiDB0yAv0iDwLio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qUe3VDoAwHkEPBe2t/Lx6QQpmkojZwwUPzdmboPN11fynrzem+j1/vb56iuqkk/VyiFkK4pyhZnsBo98PxE1qn69PynAOQfu34xc8+AjSuysuHVFC0cD+y5DJJ6K2On4ScXpNdqmIAiId3aHPBraOoEmfkeV1a3RqzsiCa+20OY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=zmT5rMh9; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="zmT5rMh9" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-42108822e3cso4906235e9.0 for ; Fri, 24 May 2024 07:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1716561118; x=1717165918; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5NZtcu9PAYXkGaMFVFG3nx6sddIRSoZPbItA3KPqh64=; b=zmT5rMh9zaxZCK/RNMgXtQhVH80OwCuawwlsXa+0ZB7wdl+aRghR0MkLu/OXkXUsUI NJczJMjI4C/5P6F7ovB9mW9fHe1YpfGRdkvIQ6XUzoXl72LnoDtPrurNPWPq2cPDCpf3 BYog2sf49jjB75kyRwa8jaPxKLMNNuCqF49024mDZ/dEMoncXM62uxTNHacTq8bNOs1Y y2A/paPNpLtYJOeC8fOmWmkhSslAS64VCxHsASEyaHFsr51MqXosxN/vzb0lctkuWQUI 47MW9NyB1niq62Yo5pGC7o4p+U+L0nLl+JptIvNE7jfbwH+wvYzsLzlofiQlpd34e8W5 uSwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716561118; x=1717165918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5NZtcu9PAYXkGaMFVFG3nx6sddIRSoZPbItA3KPqh64=; b=xLgj1HE+K4kXTQJfcCeJqCLps3+oXMAMIHQNKLBMGl9tUPPAl/0ygFQqeNaucJtYnP a90L/FVoHPGRdTdqLd1fMaKuUI0gZB43ByTUZuLPhrZ2QAB8yir87ihpZFfSX+6bjnGz Jd5UcXNiY6807YV2pLu5bK6Vag8zPRY8RV52lwxii89r36P94++mSfSNeDOoD8PF2JvH coFZL+kbi2B1XdF0aH30FAK6aXUDEeyyRM7bIDQgeS+fKpEt2OQzki8DKagamAsI5xxl KVaKxuxHgD3XHv2+Vz7jlqLYyX1cKLi/Puducm/XnLk2aGeqxohK91uHFNPG4G3NpOgv Akig== X-Forwarded-Encrypted: i=1; AJvYcCWheHL0d7NadGphufdEjOivoni5JiT5MpGWVnmCwsxA3HycUreXq9DxSEM/uC4NVTbiJzYzeH3kbeRkjfGiURo/hp8IzZShL/FXFMO4 X-Gm-Message-State: AOJu0Yy7OBZoKSImfKURvovOpi8WCurYEVOkanykfmfL12DlpeNKsyoi NO7q4qrpMnN6DT8OYrUXvKi3oxTyPnUePF3rRiA1lNKXtnvgetTqiWXwS50X3wY= X-Google-Smtp-Source: AGHT+IFWU8gG+e37pZmxQTBYP+ymcZvgVYFKwYUoy5BLlIk1BxT5PROIa+A09uXjEL4pfbi1jnhA8g== X-Received: by 2002:a05:6000:11cf:b0:351:debf:a39e with SMTP id ffacd0b85a97d-354f757d1a5mr5109406f8f.27.1716561118543; Fri, 24 May 2024 07:31:58 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a090c2bsm1719611f8f.59.2024.05.24.07.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 07:31:58 -0700 (PDT) From: Alexandre Bailon 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 Subject: [PATCH v3 3/6] thermal: Add support of multi sensors to thermal_of Date: Fri, 24 May 2024 16:31:47 +0200 Message-ID: <20240524143150.610949-4-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240524143150.610949-1-abailon@baylibre.com> References: <20240524143150.610949-1-abailon@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This updates thermal_of to support more than one sensor. If during the registration we find another thermal zone referencing this sensors and some other, then we create the multi sensor thermal zone (if it doesn't exist) and register the sensor to it. Signed-off-by: Alexandre Bailon --- drivers/thermal/thermal_of.c | 250 +++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index aa34b6e82e26..75e3cfb8488a 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -18,6 +18,8 @@ =20 #include "thermal_core.h" =20 +#define STRLEN_ID (8) + /*** functions parsing device tree nodes ***/ =20 static int of_find_trip_id(struct device_node *np, struct device_node *tri= p) @@ -222,6 +224,77 @@ static struct device_node *of_thermal_zone_find(struct= device_node *sensor, int return tz; } =20 +static int thermal_of_multi_sensor_get_name(struct device_node *sensor, in= t id, + struct device_node *tz, char *name) +{ + struct of_phandle_args sensor_specs; + int count, i; + + tz =3D of_thermal_zone_find(sensor, id); + if (!tz) { + pr_debug("No thermal zones description\n"); + return -ENODEV; + } + + count =3D of_count_phandle_with_args(tz, "thermal-sensors", + "#thermal-sensor-cells"); + if (count <=3D 0) + return count; + + for (i =3D 0; i < count; i++) { + + int ret; + + ret =3D of_parse_phandle_with_args(tz, "thermal-sensors", + "#thermal-sensor-cells", + i, &sensor_specs); + if (ret < 0) { + pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret); + return ret; + } + + if ((sensor =3D=3D sensor_specs.np) && id =3D=3D (sensor_specs.args_coun= t ? + sensor_specs.args[0] : 0)) { + snprintf(name, THERMAL_NAME_LENGTH, "%s%d", tz->name, id); + return 0; + } + } + + return -ENODEV; +} + +static int thermal_of_multi_sensor_get_id(struct device_node *sensor, + struct device_node *tz, int id) +{ + struct of_phandle_args sensor_specs; + int count, i; + + count =3D of_count_phandle_with_args(tz, "thermal-sensors", + "#thermal-sensor-cells"); + if (count <=3D 0) + return 0; + + for (i =3D 0; i < count; i++) { + + int ret; + + ret =3D of_parse_phandle_with_args(tz, "thermal-sensors", + "#thermal-sensor-cells", + i, &sensor_specs); + if (ret < 0) { + pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret); + return 0; + } + + if ((sensor =3D=3D sensor_specs.np) && id =3D=3D (sensor_specs.args_coun= t ? + sensor_specs.args[0] : 0)) { + return i; + } + } + + return -ENODEV; +} + static int thermal_of_monitor_init(struct device_node *np, int *delay, int= *pdelay) { int ret; @@ -281,6 +354,17 @@ static struct device_node *thermal_of_zone_get_by_name= (struct thermal_zone_devic return ERR_PTR(-ENODEV); =20 tz_np =3D of_get_child_by_name(np, tz->type); + if (!tz_np) { + char tmp[THERMAL_NAME_LENGTH]; + char *ptr; + + ptr =3D strrchr(tz->type, '.'); + if (!ptr) + return ERR_PTR(-ENODEV); + + strscpy(tmp, tz->type, (ptr - tz->type) + 1); + tz_np =3D of_get_child_by_name(np, tmp); + } =20 of_node_put(np); =20 @@ -444,10 +528,140 @@ static int thermal_of_unbind(struct thermal_zone_dev= ice *tz, */ static void thermal_of_zone_unregister(struct thermal_zone_device *tz) { + thermal_multi_sensor_unregister(tz); thermal_zone_device_disable(tz); thermal_zone_device_unregister(tz); } =20 +static int thermal_of_multi_sensor_validate_coeff(struct device_node *sens= or, int id, + struct device_node *tz_np) +{ + u32 *coeff; + int ret; + int i; + + int count; + int index; + int offset; + + index =3D thermal_of_multi_sensor_get_id(sensor, tz_np, id); + if (index < 0) + return -ENODEV; + + + count =3D of_count_phandle_with_args(tz_np, + "thermal-sensors", + "#thermal-sensor-cells"); + if (count < 0) + return count; + + coeff =3D kmalloc_array(count, sizeof(*coeff), GFP_KERNEL); + if (!coeff) + return -ENOMEM; + + for (i =3D 0; i < count; i++) { + ret =3D of_property_read_u32_index(tz_np, + "coefficients", + i, coeff + i); + if (ret) + coeff[i] =3D 1; + } + + ret =3D of_property_read_u32_index(tz_np, "coefficients", + count, &offset); + if (ret) + offset =3D 0; + + /* Make sure the coeff and offset won't cause an overflow */ + ret =3D thermal_multi_sensor_validate_coeff(coeff, count, offset); + + kfree(coeff); + + return ret; +} + +static int thermal_of_mutli_sensor_coeff(struct device_node *sensor, int i= d, + struct device_node *tz_np, + u32 *coeff) +{ + int index; + int ret; + + index =3D thermal_of_multi_sensor_get_id(sensor, tz_np, id); + if (index < 0) + return index; + + ret =3D of_property_read_u32_index(tz_np, "coefficients", index, coeff); + if (ret) + *coeff =3D 1; + + return 0; +} + +static struct thermal_zone_device * +thermal_of_register_multi_tz(struct device_node *sensor, int id, struct de= vice_node *np, + const char *type, struct thermal_trip *trips, int num_trips, + void *devdata, struct thermal_zone_device_ops *ops, + const struct thermal_zone_params *tzp, int passive_delay, + int polling_delay) +{ + struct thermal_zone_device *multi_tz, *tz; + char name[THERMAL_NAME_LENGTH]; + u32 coeff; + int ret; + + multi_tz =3D thermal_multi_sensor_find_tz(type); + if (!multi_tz) { + struct thermal_zone_device_ops *multi_ops; + + ret =3D thermal_of_multi_sensor_validate_coeff(sensor, id, np); + if (ret) + return ERR_PTR(ret); + + multi_ops =3D thermal_multi_sensor_alloc_ops(THERMAL_AGGR_AVG); + if (IS_ERR_OR_NULL(multi_ops)) + return ERR_PTR(PTR_ERR(multi_ops)); + multi_ops->bind =3D thermal_of_bind; + multi_ops->unbind =3D thermal_of_unbind; + + multi_tz =3D thermal_multi_sensor_tz_alloc(type, trips, num_trips, + multi_ops, + passive_delay, polling_delay); + if (IS_ERR_OR_NULL(multi_tz)) { + kfree(multi_ops); + return multi_tz; + } + } + + ret =3D thermal_of_multi_sensor_get_name(sensor, id, np, name); + if (ret) + goto out_release_multi_tz; + + tz =3D thermal_tripless_zone_device_register(name, devdata, ops, tzp); + if (IS_ERR_OR_NULL(tz)) { + ret =3D PTR_ERR(tz); + goto out_release_multi_tz; + } + + ret =3D thermal_of_mutli_sensor_coeff(sensor, id, np, &coeff); + if (ret) + goto out_release_tz; + + ret =3D thermal_multi_sensor_register(multi_tz, tz, coeff); + if (ret) + goto out_release_tz; + + return tz; + +out_release_tz: + thermal_zone_device_unregister(tz); +out_release_multi_tz: + thermal_multi_sensor_tz_free(multi_tz); + + return ERR_PTR(ret); +} + + /** * thermal_of_zone_register - Register a thermal zone with device node * sensor @@ -479,6 +693,7 @@ static struct thermal_zone_device *thermal_of_zone_regi= ster(struct device_node * const char *action; int delay, pdelay; int ntrips; + int count; int ret; =20 np =3D of_thermal_zone_find(sensor, id); @@ -488,10 +703,19 @@ static struct thermal_zone_device *thermal_of_zone_re= gister(struct device_node * return ERR_CAST(np); } =20 - trips =3D thermal_of_trips_init(np, &ntrips); - if (IS_ERR(trips)) { - pr_err("Failed to find trip points for %pOFn id=3D%d\n", sensor, id); - return ERR_CAST(trips); + count =3D of_count_phandle_with_args(np, "thermal-sensors", + "#thermal-sensor-cells"); + if (count <=3D 0) + return ERR_PTR(count); + + /* Only allocate trips if the thermal zone doesn't exist yet */ + if (!thermal_multi_sensor_find_tz(np->name)) { + trips =3D thermal_of_trips_init(np, &ntrips); + if (IS_ERR(trips)) { + pr_err("Failed to find trip points for %pOFn id=3D%d\n", sensor, id); + ret =3D PTR_ERR(trips); + goto out_kfree_trips; + } } =20 ret =3D thermal_of_monitor_init(np, &delay, &pdelay); @@ -502,17 +726,25 @@ static struct thermal_zone_device *thermal_of_zone_re= gister(struct device_node * =20 thermal_of_parameters_init(np, &tzp); =20 - of_ops.bind =3D thermal_of_bind; - of_ops.unbind =3D thermal_of_unbind; + if (count =3D=3D 1) { + of_ops.bind =3D thermal_of_bind; + of_ops.unbind =3D thermal_of_unbind; + } =20 ret =3D of_property_read_string(np, "critical-action", &action); if (!ret) if (!of_ops.critical && !strcasecmp(action, "reboot")) of_ops.critical =3D thermal_zone_device_critical_reboot; =20 - tz =3D thermal_zone_device_register_with_trips(np->name, trips, ntrips, - data, &of_ops, &tzp, - pdelay, delay); + if (count =3D=3D 1) { + tz =3D thermal_zone_device_register_with_trips(np->name, trips, ntrips, + data, &of_ops, &tzp, + pdelay, delay); + } else { + tz =3D thermal_of_register_multi_tz(sensor, id, np, np->name, trips, + ntrips, data, &of_ops, &tzp, + pdelay, delay); + } if (IS_ERR(tz)) { ret =3D PTR_ERR(tz); pr_err("Failed to register thermal zone %pOFn: %d\n", np, ret); --=20 2.44.1 From nobody Fri Feb 13 15:03:55 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B142F12D748 for ; Fri, 24 May 2024 14:32:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561125; cv=none; b=T6qMRv56JqIxudK2slCQY7LF+25DfWcx/BHj2ZR1Oi1fmw+irO0z2aVY66shQqwVafwj/5UYQGc90NA+TXpls4zbFxqQjG91T+yzBGFPkP3rykMy+JynFtcQprM8zqjZo1VaMasPv4m7D2Zm3CQ2LQEr2x6SC8F+SGZZTKpiC80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561125; c=relaxed/simple; bh=mGHJTIEqaOM3rGni2f2k2W0qT+PA8lgJbBpgTIxC7k8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d5L1DQPMftPMBN+y5thCV+DVG8VRfrpCPXD7+oCAvY+y+JcIVtK2yObkPeXIjEZ7TPeuyYkPNLkIaRhyRXXPiKnFICxGSNqu/y378luQvZxMhmQ/pVN2ddn9xNpN36sCpMPZ1QsqQfv43h6b+tKbzEvv5ldj8KSyU26UfC4KLsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=V8XIZtmX; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="V8XIZtmX" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5295f201979so1081552e87.2 for ; Fri, 24 May 2024 07:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1716561121; x=1717165921; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x/1Ee6H1I4b4eaa21f1IZfthFOHfX8TRhLVEevdwWj0=; b=V8XIZtmXCIif/wk8caetPmdFoyx29DqFpr+cwKfx5KMhPHl8ymU/CCkuBbD4OLYqZh Tdxmh9LECY1R66vLE2C67avS54JiwgRQo+ynqnTcWai9sPxLjHtthbYfsLajATvqdqB0 UqOE15EtlNmxhD7Ktq45e6dAF67F4qBDNDtJBsZ/XDA0BiY08P9kSrhm6OJZj1y0lMAw 17z9Qisyylrbt60om8G8ZjH8tmxQMB+NB/NmNG4Yvxw+pt7cP2U/FCMjsx3SJwyOZS9G fzn22bQAbLRiJTHHWPeAlwp1uaUzpjXwv4sseocijwbjFhGYxLOVp+jKCU66pnlNnFLn WtOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716561121; x=1717165921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x/1Ee6H1I4b4eaa21f1IZfthFOHfX8TRhLVEevdwWj0=; b=D5dIOafzgslweGy2KApQHovPR/UdFbpGH8SjSngLhBOAfkfuXSTjSe6jcq5y4VwwKJ yOYKs7V8eN2Bo2DCr/Ne9UpzKb8KC1+A+TZp6+pcVZGAMS6A8wH5It6FYbpFxGfqS7DM qNpQj9yJ4957E/5ihJ8i/lRjHKb2zhEVkzPpZClEmOTCS86lmmlrClwAPUvBOUeMge1d JWZD2EHK9AGoaAK5qhK/NcxHv3Vh7wxJBUG0R2gj8oEvk6F1rEpCE2I9ooETjPwxmHY+ xJhofux+qjjKnxqIglv6ae63abHTukOtHje4XydL6N92XKhnl+TKb8Vo7s8q5xih8iAV 2tsQ== X-Forwarded-Encrypted: i=1; AJvYcCVwRdfTgQg6L7C3WLkCmaHvKvpxaoItZ8XNmGo0ulW/yYEz12p8YpguGUhR2TCFQr2pzAJAk0GNquy8gLf8UkGd/hqPrLUq5TPXS8CX X-Gm-Message-State: AOJu0YwYF+TIBrYNcrEh1JX79pQyG1OO6z0WLpXPnEPHCn0EJczECYBK Bpd3e1Wy5/wIsFmS1metQCTiaho3rCbitFN+Xj+JD3jIipm1nJ2aTRdWzfywDg4= X-Google-Smtp-Source: AGHT+IGae8vz7FD8oFzDfF3fXF9u1uERG6J8NuAfN29z6HqiuN+X4zLPzr4PMF9xpcgrJ0L2NyAUgw== X-Received: by 2002:ac2:4c24:0:b0:521:f000:5d1a with SMTP id 2adb3069b0e04-52966ca837fmr1547324e87.59.1716561120954; Fri, 24 May 2024 07:32:00 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a090c2bsm1719611f8f.59.2024.05.24.07.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 07:31:59 -0700 (PDT) From: Alexandre Bailon 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 Subject: [PATCH v3 4/6] dt-bindings: thermal: Add a property to select the aggregation type Date: Fri, 24 May 2024 16:31:48 +0200 Message-ID: <20240524143150.610949-5-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240524143150.610949-1-abailon@baylibre.com> References: <20240524143150.610949-1-abailon@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This adds a new property named "aggregation" that could be used to select the aggregation type when there are multiple sensors assigned to a thermal zone. Signed-off-by: Alexandre Bailon --- .../devicetree/bindings/thermal/thermal-zones.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/thermal/thermal-zones.yaml b= /Documentation/devicetree/bindings/thermal/thermal-zones.yaml index fa7a72e2ba44..e6e4b46773e3 100644 --- a/Documentation/devicetree/bindings/thermal/thermal-zones.yaml +++ b/Documentation/devicetree/bindings/thermal/thermal-zones.yaml @@ -111,6 +111,14 @@ patternProperties: coefficients are ordered and are matched with sensors by means o= f the sensor ID. Additional coefficients are interpreted as constant o= ffset. =20 + aggregation: + $ref: /schemas/types.yaml#/definitions/string + enum: + - avg + - max + description: + Aggregation type to use compute a temperature from multiple sens= ors. + sustainable-power: $ref: /schemas/types.yaml#/definitions/uint32 description: --=20 2.44.1 From nobody Fri Feb 13 15:03:55 2026 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C9E412D755 for ; Fri, 24 May 2024 14:32:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561126; cv=none; b=pG6cSMWUcSB4bBrInAAkRm9MsNyWjQytO6NAIT3K6Cxte7cptT2wSrt9qPpWILRPM78MRz5Lc9z/0t2BN3HB+0d3HDK6cdyNj0pK6Rep5944fgRbfDxKr9lNLl9DYoXrdYlfHU2YNCBfkftB/JMQhnCAO+cO9YBHezJivMCeeZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561126; c=relaxed/simple; bh=7yX2hQotDIGtiorXI3z/x7bEre3XpPfBoX/iqy4G0gA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nKZOWjRzWkEg5Ty2vO93Pq7i9abuK3sdkNgUge43l1gvfWrriJKy4lqG/FdNdMtgf4zc75gOCJAjkQ1MOyFLqagGbvr5UwThQUpyUproG6hyZX8/NrqKcAABgJToPyyUF4i+P1aLAA6bJt/az6F/FThJHn01OSlRJ5k/rpxj4CU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=ZCKTf9DP; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="ZCKTf9DP" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3550224b745so1127519f8f.0 for ; Fri, 24 May 2024 07:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1716561123; x=1717165923; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QKYQwwXxPgEaUkNb+P0Yo4hvRZxOOz/or0QP5Vm2gcw=; b=ZCKTf9DPabArzgp2W3CYxbiW9NJZMq16CHpE42GV+OM2Ljm5rj+oVjv4IGWz3IwEMN ExV67TxHZ2vRoY0v1kATZ3WRu86eMgkeGK6xRaVXWUvIjqrj86FrvcArfrHDqB1nZA2q kLYXSxNvsRjQL1yUE/TYnWE1uLmCuw8JtmplcskKnz1SHeTVJaBGBz8di0Sm4En2945u 1NesexzN/NRQgSz9lO5lybbP/IeSi98AtVL1tbQOHq9UZSjVoVSw1j0WYTTvV1Es3jWf WgZZOBEtj2ng4P53og3tOXbqKCxnGNbyiFctz41R3d9fqe/xjESyrBkhMjG8pkyGWEPm 08xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716561123; x=1717165923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QKYQwwXxPgEaUkNb+P0Yo4hvRZxOOz/or0QP5Vm2gcw=; b=coZkInh3wcp1ZI9s2FDrQyArWCUA1M6XioodGDRrf7QkpnZKEPI70FGgXBPe0C/MWp TqO5KtlM5tUAVn+Bvuq7l9AXDEKB/bHyMjbJp5esvj2IqsQiiTDVmZRPhFVOl/Hu7LrJ mWbybjgL7VJpuiUPjV8aSumQoE+RhLsrQtvUZD5d+azUPrSCMHxlDhJwtUbISOo4TmM5 NjNy83eMbwcdFn8fzphUQIZT2MYtg5hCG15S3rLD7Tll3QuMmkhZzNe7BxXPGdFEtSfA cnXnElEjuV+3D31LyBiwMgU6buC9fN5LbYk+9TdS1Pji0TSbDkL63QHbSdSR8I+DNf8z KkMA== X-Forwarded-Encrypted: i=1; AJvYcCWprop2YGVlyo+6TOnWpwiFM6SfJAN3rzA+g+sBMXmykaFjmsdiGsQo/PWWaV+X+OYu623ZZEFTdzkKMAnUXa1F3j42JgSZHvJT3zWK X-Gm-Message-State: AOJu0Yy5NuA6LbQJ+kt3xCLq2bioxi6Ky0XFNuVkxyCpLUS9vr6Ym0F2 7Ss9d4n7FHIYYTPrr/L2a+tUUfVecDlmSXxae3VOj/sCHKuSX3TyP8I8o1+14Xc= X-Google-Smtp-Source: AGHT+IFMZIFVZcP6PbiZYFp88cxLXoWz0ATJDVN52IQI0qhWieGFreYqoFMkNFKwtIZqf1dIqdbp3g== X-Received: by 2002:a5d:53d2:0:b0:34d:9d2c:d9e2 with SMTP id ffacd0b85a97d-3552fdf269amr1793217f8f.53.1716561122768; Fri, 24 May 2024 07:32:02 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a090c2bsm1719611f8f.59.2024.05.24.07.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 07:32:01 -0700 (PDT) From: Alexandre Bailon 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 Subject: [PATCH v3 5/6] thermal: of: Parse aggregation property to select the aggegration type Date: Fri, 24 May 2024 16:31:49 +0200 Message-ID: <20240524143150.610949-6-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240524143150.610949-1-abailon@baylibre.com> References: <20240524143150.610949-1-abailon@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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); } =20 +static const char * const aggr_types[] =3D { + [THERMAL_AGGR_AVG] =3D "avg", + [THERMAL_AGGR_MAX] =3D "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 =3D of_property_read_string(np, "aggregation", &t); + if (err < 0) { + *type =3D THERMAL_AGGR_AVG; + return 0; + } + + for (i =3D 0; i < ARRAY_SIZE(aggr_types); i++) { + if (!strcasecmp(t, aggr_types[i])) { + *type =3D i; + return 0; + } + } + + return -EINVAL; +} + static int thermal_of_multi_sensor_validate_coeff(struct device_node *sens= or, 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 *senso= r, int id, struct device_n if (!multi_tz) { struct thermal_zone_device_ops *multi_ops; =20 + ret =3D thermal_of_multi_sensor_get_type(np, &aggr_type); + if (ret) + return ERR_PTR(ret); + ret =3D thermal_of_multi_sensor_validate_coeff(sensor, id, np); if (ret) return ERR_PTR(ret); --=20 2.44.1 From nobody Fri Feb 13 15:03:55 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42D8012DD8A for ; Fri, 24 May 2024 14:32:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561128; cv=none; b=i0+k0b8zSia/BErjwzgWDbn0i0kO0eTIX8UWl9S9UlGLhYqCtcWLBFQ9/tmulixH91la6t1APgxCSHslop5aX8ir8r1gu/dBTQsEhAY9zQbEc7PlLGV0pLos+DoqPI1/QjpJREp8jFFzSbpkxPS9PY7thuBhVkuM58cSXmNnW6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561128; c=relaxed/simple; bh=ihEpBfOoTIzhcY5yCWLCSgakPGdyeqFhOmNtZbrClHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G8g+6eaEdQjQCGDKLfZyaqmSONUPBjJkM7F37LdZ5BHh4UkXzkOHEalcYq4BfdvwQ2UqguFSzBr5SKstUJUMlLbKD6EBVN98Yt2/VpTL8pzPfrbm22kaDmjSDcCgp1boqv9qP1FneLmXgaOrE/uLOn7YBsWA5ChXUzMTqDD5354= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=gpdaIOqf; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="gpdaIOqf" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3504f34a086so6124066f8f.1 for ; Fri, 24 May 2024 07:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1716561125; x=1717165925; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/J4OrAZncZpQuvGizXTDM9c24jSIJESkYwIXxao8DRY=; b=gpdaIOqfeDPXOPjjpojLfbIERjFDk3AzLAw8GuvXFpv/4vv6KCp0MLA6trPVlcLx4y swgXtCQ8xLJjbZ0O6jprO8T8hiPvg4G/hg5OnEcWHdZKcieWPuYtpISckI5Im19+1KHL 0Qi45ybTs0VM9SGfocw4iy5BbG9RtxJcBJyPQ7W7MMB4p0VaadHB5R7fT2jmhgVjhlm1 RoDCSNmj6TwFzOCwIhXzf8Azvl6fy7FdMD52ZpYfTVrLBIeM338Y17eR2Ex94RPKWPb2 gianLWs3o/SZx8CVyd+C62TST0ahlttt1XajQyUoRM7XokZhNVs0p2B3bAPb0wxudpKR 9jkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716561125; x=1717165925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/J4OrAZncZpQuvGizXTDM9c24jSIJESkYwIXxao8DRY=; b=N1IQRoGRfHfYa5oWdze8uKtmkOlRWlMnJkT4VdqVYH4i6yqKcJ2hILYVcjsHa/oQnK TONMlXnJZeUEwlhz3wDTkRphZCUPfox95CaeISCWac7qEQvU2gjADXYQnKiMrfAHPde4 33D3bnao2o6mGfGRkxGXUL05h1vmGwDtC7+qDZbTfvzSRShcPGrmCsW7GXYbCgHIraFl O5EmMLWe021ov6QDhWB9yTXWl6vZWdzv9UN/voR1So0pQeuVgwbyAUOug67OzIcQRhH8 xq6oMo/HUggoXqnHx09VSPKumgPv/rwnsm7ck4HqqMJGH6U3wdiF6JEMlm+bvd3GXXXw YQhg== X-Forwarded-Encrypted: i=1; AJvYcCVeU5f9jnXneyTOsFEVIbDZ6h82anDhqo6VQc77Ahpy4uLQpNqXON4W4dUHDNGME2fX7rMuaqMKrAv70n3sHEdChXfc7MevFBhtWx4Z X-Gm-Message-State: AOJu0YzAlUJzFHUwLQlQvcf5DyMK/f/ghkYEQLNrJtvs39ljiQil2+qY 6/PaNQTBZurwEJFOKgPqSv6xww65K3T3HacTE1kQrLTlzVO2RawUjkcrJMvuXhketDtqXHtiNLh DDzM= X-Google-Smtp-Source: AGHT+IFCKj2pq8XeDS8Y3FzCUKaVouktrLJTGeT9YfniOKJ5yXmCDzg766BhAVtXMdougnVYNmAMyw== X-Received: by 2002:a5d:400a:0:b0:355:21d:ab9d with SMTP id ffacd0b85a97d-3552fdfd70emr1644022f8f.65.1716561124742; Fri, 24 May 2024 07:32:04 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a090c2bsm1719611f8f.59.2024.05.24.07.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 07:32:03 -0700 (PDT) From: Alexandre Bailon 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 Subject: [PATCH v3 6/6] ARM64: mt8195: Use thermal aggregation for big and little cpu Date: Fri, 24 May 2024 16:31:50 +0200 Message-ID: <20240524143150.610949-7-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240524143150.610949-1-abailon@baylibre.com> References: <20240524143150.610949-1-abailon@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This uses the thermal aggregation for the mt8195 to get the maximal temperature of big and little cpu clusters. Signed-off-by: Alexandre Bailon --- arch/arm64/boot/dts/mediatek/mt8195.dtsi | 212 +++-------------------- 1 file changed, 27 insertions(+), 185 deletions(-) diff --git a/arch/arm64/boot/dts/mediatek/mt8195.dtsi b/arch/arm64/boot/dts= /mediatek/mt8195.dtsi index 5d8b68f86ce4..8aa2bf142622 100644 --- a/arch/arm64/boot/dts/mediatek/mt8195.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8195.dtsi @@ -3600,50 +3600,31 @@ dp_tx: dp-tx@1c600000 { }; =20 thermal_zones: thermal-zones { - cpu0-thermal { + cpu-little { polling-delay =3D <1000>; - polling-delay-passive =3D <250>; - thermal-sensors =3D <&lvts_mcu MT8195_MCU_LITTLE_CPU0>; + polling-delay-passive =3D <100>; + thermal-sensors =3D <&lvts_mcu MT8195_MCU_LITTLE_CPU0>, + <&lvts_mcu MT8195_MCU_LITTLE_CPU1>, + <&lvts_mcu MT8195_MCU_LITTLE_CPU2>, + <&lvts_mcu MT8195_MCU_LITTLE_CPU3>; + sustainable-power =3D <1500>; + aggregation =3D "max"; =20 trips { - cpu0_alert: trip-alert { - temperature =3D <85000>; + cpu_little_threshold: trip-point { + temperature =3D <68000>; hysteresis =3D <2000>; type =3D "passive"; }; =20 - cpu0_crit: trip-crit { - temperature =3D <100000>; - hysteresis =3D <2000>; - type =3D "critical"; - }; - }; - - cooling-maps { - map0 { - trip =3D <&cpu0_alert>; - cooling-device =3D <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; - }; - }; - }; - - cpu1-thermal { - polling-delay =3D <1000>; - polling-delay-passive =3D <250>; - thermal-sensors =3D <&lvts_mcu MT8195_MCU_LITTLE_CPU1>; - - trips { - cpu1_alert: trip-alert { + cpu_little_target: target { temperature =3D <85000>; hysteresis =3D <2000>; type =3D "passive"; }; =20 - cpu1_crit: trip-crit { - temperature =3D <100000>; + cpu_little_soc_max_crit: soc-max-crit { + temperature =3D <115000>; hysteresis =3D <2000>; type =3D "critical"; }; @@ -3651,7 +3632,7 @@ cpu1_crit: trip-crit { =20 cooling-maps { map0 { - trip =3D <&cpu1_alert>; + trip =3D <&cpu_little_target>; cooling-device =3D <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, <&cpu1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, <&cpu2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, @@ -3660,170 +3641,31 @@ map0 { }; }; =20 - cpu2-thermal { + cpu-big { polling-delay =3D <1000>; polling-delay-passive =3D <250>; - thermal-sensors =3D <&lvts_mcu MT8195_MCU_LITTLE_CPU2>; + thermal-sensors =3D <&lvts_mcu MT8195_MCU_BIG_CPU0>, + <&lvts_mcu MT8195_MCU_BIG_CPU1>, + <&lvts_mcu MT8195_MCU_BIG_CPU2>, + <&lvts_mcu MT8195_MCU_BIG_CPU3>; + sustainable-power =3D <1500>; + aggregation =3D "max"; =20 trips { - cpu2_alert: trip-alert { - temperature =3D <85000>; + cpu_big_threshold: trip-point { + temperature =3D <68000>; hysteresis =3D <2000>; type =3D "passive"; }; =20 - cpu2_crit: trip-crit { - temperature =3D <100000>; - hysteresis =3D <2000>; - type =3D "critical"; - }; - }; - - cooling-maps { - map0 { - trip =3D <&cpu2_alert>; - cooling-device =3D <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; - }; - }; - }; - - cpu3-thermal { - polling-delay =3D <1000>; - polling-delay-passive =3D <250>; - thermal-sensors =3D <&lvts_mcu MT8195_MCU_LITTLE_CPU3>; - - trips { - cpu3_alert: trip-alert { - temperature =3D <85000>; - hysteresis =3D <2000>; - type =3D "passive"; - }; - - cpu3_crit: trip-crit { - temperature =3D <100000>; - hysteresis =3D <2000>; - type =3D "critical"; - }; - }; - - cooling-maps { - map0 { - trip =3D <&cpu3_alert>; - cooling-device =3D <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; - }; - }; - }; - - cpu4-thermal { - polling-delay =3D <1000>; - polling-delay-passive =3D <250>; - thermal-sensors =3D <&lvts_mcu MT8195_MCU_BIG_CPU0>; - - trips { - cpu4_alert: trip-alert { + cpu_big_target: target { temperature =3D <85000>; hysteresis =3D <2000>; type =3D "passive"; }; =20 - cpu4_crit: trip-crit { - temperature =3D <100000>; - hysteresis =3D <2000>; - type =3D "critical"; - }; - }; - - cooling-maps { - map0 { - trip =3D <&cpu4_alert>; - cooling-device =3D <&cpu4 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu5 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu7 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; - }; - }; - }; - - cpu5-thermal { - polling-delay =3D <1000>; - polling-delay-passive =3D <250>; - thermal-sensors =3D <&lvts_mcu MT8195_MCU_BIG_CPU1>; - - trips { - cpu5_alert: trip-alert { - temperature =3D <85000>; - hysteresis =3D <2000>; - type =3D "passive"; - }; - - cpu5_crit: trip-crit { - temperature =3D <100000>; - hysteresis =3D <2000>; - type =3D "critical"; - }; - }; - - cooling-maps { - map0 { - trip =3D <&cpu5_alert>; - cooling-device =3D <&cpu4 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu5 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu7 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; - }; - }; - }; - - cpu6-thermal { - polling-delay =3D <1000>; - polling-delay-passive =3D <250>; - thermal-sensors =3D <&lvts_mcu MT8195_MCU_BIG_CPU2>; - - trips { - cpu6_alert: trip-alert { - temperature =3D <85000>; - hysteresis =3D <2000>; - type =3D "passive"; - }; - - cpu6_crit: trip-crit { - temperature =3D <100000>; - hysteresis =3D <2000>; - type =3D "critical"; - }; - }; - - cooling-maps { - map0 { - trip =3D <&cpu6_alert>; - cooling-device =3D <&cpu4 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu5 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, - <&cpu7 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; - }; - }; - }; - - cpu7-thermal { - polling-delay =3D <1000>; - polling-delay-passive =3D <250>; - thermal-sensors =3D <&lvts_mcu MT8195_MCU_BIG_CPU3>; - - trips { - cpu7_alert: trip-alert { - temperature =3D <85000>; - hysteresis =3D <2000>; - type =3D "passive"; - }; - - cpu7_crit: trip-crit { - temperature =3D <100000>; + cpu_big_soc_max_crit: soc-max-crit { + temperature =3D <115000>; hysteresis =3D <2000>; type =3D "critical"; }; @@ -3831,7 +3673,7 @@ cpu7_crit: trip-crit { =20 cooling-maps { map0 { - trip =3D <&cpu7_alert>; + trip =3D <&cpu_big_target>; cooling-device =3D <&cpu4 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, <&cpu5 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, --=20 2.44.1