From patchwork Fri May 24 14:31:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 798836 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 8F10612BF30 for ; Fri, 24 May 2024 14:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561119; cv=none; b=SpKnCzclWHtJuso2JYMAvU0R05ffnx2e8l9y9L2WXIaN0fcSQ8PhTCH5MKgu+fTZN+zg7tk+ZDlbNXAqDqaz3dmWsfg5/6+3xa1O/5PeGYVjtjWeMtdUx0+SiuE/6ahATKjVoKuwzlzMezNd1JwLIJBXaABVcqUozWrS4/Y65LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561119; c=relaxed/simple; bh=rnldv7833XODCkkhE2IoJHX1ijFNhpuCcMgGUEpMC7w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FNmrPHf27dlo0VcriVDLxRXf2gtlp39n3HtPpNyy+Dok7HmjiErhLSo328kNg3gw4nn25Zfrj5vlLT904TugBIDNuYsO8NGSbwY7tL1zX+ZXr1hHFHqb3K0GjS+lxcgiku4OeZCi0yF0Fz72/FP7FjNIojKEsUIKVlioA+oPckE= 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.53 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-f53.google.com with SMTP id 5b1f17b1804b1-42017f8de7aso66198255e9.1 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=gyw68vzNt9l+KMgElApTXvckc8wC/NT9ZCiEQeYTTKw5E8o4UrNRoMpXXSPTmWRK+8 J+ER1740J7wI5djXrvw5W+BRh+C+0dnZZ87/aEVwr8Frd6GcYysqDc+FwWDms3+vV3EL 7IFcuXMuPAEdslc8pQsMtXWE0m8LyEP2/4yw2PZwoUAvpcPZW8IYxUEVJQDq+FrBKHFb xmhHvS9hPLIvvVasAewDUOavIg3KC8k94HcgxABnF9C05gR9G/tRe7sYjqeahk1eH7Ou H2AiDRMT1r5jhX0t7zGIgds2UoptXejB+LY5U1oV2P7WqfNdU3KUOnhfvfkmfHutrOpY uAxg== X-Forwarded-Encrypted: i=1; AJvYcCXIqbVOxfrOyVhybEgtAoe9N1ZdJndMZ52DNvNYPj8IvB0ZYKSv3SVXv0B6Q5eSYMRcjoXuFJUXVkuDxIYJZM72pcYGHlbEgAc= X-Gm-Message-State: AOJu0YxIrzanX5MnCSU/RfSoU1WcD20yQF+tulXs4oel9Pfr9TENgqPy LXOJ+drm4PgUg654m5SOYoo/2bRn+SMX12AAjM5FDZnIp1d7zgDLNpMC/G5R1F4= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 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. coefficients: $ref: /schemas/types.yaml#/definitions/uint32-array From patchwork Fri May 24 14:31:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 798835 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 5470E12C54A for ; Fri, 24 May 2024 14:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561121; cv=none; b=EYlgEa/xPCRx7OmCgug6yv2LGpgp7VEZjQ5Zso6Www30dUFpjJH2p4J0hSWJJiq46ynlUE7LWHGPPJrxM6Y7Q/rBwrh75HQiMc6f+0b2ExU2BND2nc2g8aQaXDTa+tsrQyeBHRKOWNr9IJxCEgz/LLpyrT3Xyh2+AGgJrpNh7y4= 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.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="K5E0dJYk" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-354f8a0cd08so2290681f8f.2 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=Ju7M6ZRCiwjvG0MBAKzsBz9SAqc8/mWoEcpyWTJHOj7iPF6yOQdFE7ilzMgPikoYUN iwnScVM4Qyv6x5WuDQ0gxxA1UT/3PIk1baoLIsxsWNQ/yBSSJaqt6USP8q4XjpCIQAwe cXoArsJmwPdCIcytLNs+pWHnVo1B9FsmxW5P5Hf6c5YK8khsQXi29S/fu2MCwjkPNny2 pcx4aaLGZPk68cEGsAcT8gb6j8I/NiDPUtN7p3WprT7gF7lIC7+ZTEzyWQSqKoy2zn4o VK7RECMEcpCqKqymEFgWJ7qV4IsX7dq8QjDWGHofbrx3QkzEUieYap3vkg1RSF6OxGLB pVMQ== X-Forwarded-Encrypted: i=1; AJvYcCWOSBecffqAEE/UiAaA2eGkOw/lIzayLVYipmozZHrXhZbjS350KCB9P+DI9p0u5+0NnjJC8JZX0yQ+fc974J/2lJz7Cb5OLdU= X-Gm-Message-State: AOJu0YyJR9YMhA1aVHjxW6keHxbgyu3oFm62hHhKXauR5as4XKMH63mQ oZfaYCfnX1u6KKSzQjrG3/2vN61glV30SG7PDjM4a/Xb+9dC98Q3cDhI5XYpCW0= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 := -I$(src) obj-$(CONFIG_THERMAL) += thermal_sys.o thermal_sys-y += thermal_core.o thermal_sysfs.o thermal_sys-y += thermal_trip.o thermal_helpers.o +thermal_sys-y += thermal_multi.o # netlink interface to manage the thermal framework thermal_sys-$(CONFIG_THERMAL_NETLINK) += 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_attribute *, char *); ssize_t weight_store(struct device *, struct device_attribute *, const char *, size_t); +/* 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_type); +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 *cdev, unsigned long new_state); diff --git a/drivers/thermal/thermal_multi.c b/drivers/thermal/thermal_multi.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 = tz->devdata; + struct sensor_interface *sensor; + int accumulated_temp = 0; + u32 accumulated_coeff = 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 = thermal_zone_get_temp(sensor->tz, temp); + if (ret) { + mutex_unlock(&multi_tz->sensors_lock); + return ret; + } + + accumulated_temp += *temp * sensor->coeff; + accumulated_coeff += sensor->coeff; + } + + mutex_unlock(&multi_tz->sensors_lock); + + *temp = 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 = 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 = thermal_zone_get_temp(sensor->tz, temp); + if (ret) { + mutex_unlock(&multi_tz->sensors_lock); + return ret; + } + + max_temp = max(max_temp, *temp * sensor->coeff); + } + + mutex_unlock(&multi_tz->sensors_lock); + + *temp = 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 = 0; + int i; + + for (i = 0; i < count; i++) { + max_accumulated_temp += TJ_MAX * coeff[i]; + if (max_accumulated_temp < 0) + return -EOVERFLOW; + } + + max_accumulated_temp += 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 = 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_temp + * operation. This allows setting the other function pointers before registering + * the thermal zone. + * + * @aggr_type: The aggregation type to use (THERMAL_AGGR_AVG or THERMAL_AGGR_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_type) +{ + struct thermal_zone_device_ops *ops; + + ops = kzalloc(sizeof(*ops), GFP_KERNEL); + if (!ops) + return ERR_PTR(-ENOMEM); + + switch (aggr_type) { + case THERMAL_AGGR_AVG: + ops->get_temp = multi_sensor_get_temp; + break; + case THERMAL_AGGR_MAX: + ops->get_temp = 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 checking + * 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_register(). + * thermal_multi_sensor_unregister() must be called to unregister the sensors + * 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 = {}; + struct multi_sensor_thermal_zone *multi_tz; + + mutex_lock(&multi_tz_mutex); + + tz = thermal_zone_get_zone_by_name(type); + if (!IS_ERR(tz)) + goto unlock; + + multi_tz = kzalloc(sizeof(*multi_tz), GFP_KERNEL); + if (!multi_tz) { + tz = ERR_PTR(-ENOMEM); + goto unlock; + } + mutex_init(&multi_tz->sensors_lock); + INIT_LIST_HEAD(&multi_tz->sensors); + + tzp.no_hwmon = true; + tzp.slope = 1; + tzp.offset = 0; + + tz = 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 = 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 = tz->devdata; + struct thermal_trip *trips = tz->trips; + struct thermal_zone_device_ops *ops = &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 sensor + * + * 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 = tz->devdata; + + sensor = kzalloc(sizeof(*sensor), GFP_KERNEL); + if (!sensor) { + mutex_unlock(&multi_tz_mutex); + return -ENOMEM; + } + + sensor->tz = sensor_tz; + sensor->coeff = 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 sensor + * 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 == 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, }; +enum thermal_aggregation_type { + THERMAL_AGGR_AVG = 0, + THERMAL_AGGR_MAX = 1, +}; + /* Adding event notification support elements */ #define THERMAL_GENL_FAMILY_NAME "thermal" #define THERMAL_GENL_VERSION 0x01 From patchwork Fri May 24 14:31:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 799148 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 1BED812C7FF for ; Fri, 24 May 2024 14:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561121; cv=none; b=pcjzTLPpS5yA+TOlfwtnNv7bogNFP65nBpGxmwBhUs5NpLXybzHRV8SyDhWwVFy1+FC8l3aSe1MCIwhYmDrC7KU470JoyeSALGdhHBP64oWkjrJdyrbC3f6pI8sq7gPRij7DWCqwMwO9eYxk0iIN8DuDpMStgi47j89scesWcqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561121; c=relaxed/simple; bh=XxQPs+CKFd+C8xKkktDLuby2qDkISiDB0yAv0iDwLio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LyTQeLZZy78+al+CG6riypfhFI1FsS1Ld0RFbQJwWNA8wSbSDqtLN3PvYKF/kRxyvNlznv50kNaWU7SR6wbtxiVtcBC+5ylJiH3gmCjqQx9rN+WUOlF7bIzhBbvpWJ65j6aKJ0/4rVqsdJhhVks85E7XE/EAl76RXjh0Y9GZEno= 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.221.42 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-wr1-f42.google.com with SMTP id ffacd0b85a97d-35507de9853so532209f8f.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=fTyBhNPeHOm+eKhooeU580vwg/9E6MYOYYiTVIdlHkQ59VYvZrbcewHSptQ2Pp6D3v A0d12WHTZOLarLH6z65QWZWMxeeHrdGmp4ns8wWCMbo9EbFI3HxTWGrKaBtJXwJyx6df yGXNZBNh0Q4rUb5RV7x3yramtuADV+HcMbkZX4Q1eJYnFzaTbd8MkHQrsTKuxT+RyV6X 8Eqi/kEdK1Znfy2rrPnQFiNUXeIfI1oxT6kp7sw2SyQo+i325WguloSa6LlLO84u5OTW OXXZLTVFyvgM1Zwc7evFyqDjk7cZ5wj09ic4Mp9OUbF6iNUn2pkmW1I1GlIsTy3SUCUa J1eA== X-Forwarded-Encrypted: i=1; AJvYcCWs9CogP/atU/7zPtSaDj58pJGzE30t/0kKPGN2nF1yNlLx3b3IG+ha5L+Z7/jdeLTQzTP4gbbirRvsWjS0tw994jspEssXNUk= X-Gm-Message-State: AOJu0YwjUzXUZ+wNGExj8ORP4sbyfWyXpgX2QCf9NIewggSE7tYyIyCt 6pWm5gndCQYzqQJHV1hx4rVY4pODhKYsNiIbbx1PWUXvEkLPRYdj8lzEdWW+D38= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 @@ #include "thermal_core.h" +#define STRLEN_ID (8) + /*** functions parsing device tree nodes ***/ static int of_find_trip_id(struct device_node *np, struct device_node *trip) @@ -222,6 +224,77 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int return tz; } +static int thermal_of_multi_sensor_get_name(struct device_node *sensor, int id, + struct device_node *tz, char *name) +{ + struct of_phandle_args sensor_specs; + int count, i; + + tz = of_thermal_zone_find(sensor, id); + if (!tz) { + pr_debug("No thermal zones description\n"); + return -ENODEV; + } + + count = of_count_phandle_with_args(tz, "thermal-sensors", + "#thermal-sensor-cells"); + if (count <= 0) + return count; + + for (i = 0; i < count; i++) { + + int ret; + + ret = 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 == sensor_specs.np) && id == (sensor_specs.args_count ? + 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 = of_count_phandle_with_args(tz, "thermal-sensors", + "#thermal-sensor-cells"); + if (count <= 0) + return 0; + + for (i = 0; i < count; i++) { + + int ret; + + ret = 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 == sensor_specs.np) && id == (sensor_specs.args_count ? + 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); tz_np = of_get_child_by_name(np, tz->type); + if (!tz_np) { + char tmp[THERMAL_NAME_LENGTH]; + char *ptr; + + ptr = strrchr(tz->type, '.'); + if (!ptr) + return ERR_PTR(-ENODEV); + + strscpy(tmp, tz->type, (ptr - tz->type) + 1); + tz_np = of_get_child_by_name(np, tmp); + } of_node_put(np); @@ -444,10 +528,140 @@ static int thermal_of_unbind(struct thermal_zone_device *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); } +static int thermal_of_multi_sensor_validate_coeff(struct device_node *sensor, int id, + struct device_node *tz_np) +{ + u32 *coeff; + int ret; + int i; + + int count; + int index; + int offset; + + index = thermal_of_multi_sensor_get_id(sensor, tz_np, id); + if (index < 0) + return -ENODEV; + + + count = of_count_phandle_with_args(tz_np, + "thermal-sensors", + "#thermal-sensor-cells"); + if (count < 0) + return count; + + coeff = kmalloc_array(count, sizeof(*coeff), GFP_KERNEL); + if (!coeff) + return -ENOMEM; + + for (i = 0; i < count; i++) { + ret = of_property_read_u32_index(tz_np, + "coefficients", + i, coeff + i); + if (ret) + coeff[i] = 1; + } + + ret = of_property_read_u32_index(tz_np, "coefficients", + count, &offset); + if (ret) + offset = 0; + + /* Make sure the coeff and offset won't cause an overflow */ + ret = thermal_multi_sensor_validate_coeff(coeff, count, offset); + + kfree(coeff); + + return ret; +} + +static int thermal_of_mutli_sensor_coeff(struct device_node *sensor, int id, + struct device_node *tz_np, + u32 *coeff) +{ + int index; + int ret; + + index = thermal_of_multi_sensor_get_id(sensor, tz_np, id); + if (index < 0) + return index; + + ret = of_property_read_u32_index(tz_np, "coefficients", index, coeff); + if (ret) + *coeff = 1; + + return 0; +} + +static struct thermal_zone_device * +thermal_of_register_multi_tz(struct device_node *sensor, int id, struct device_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 = thermal_multi_sensor_find_tz(type); + if (!multi_tz) { + struct thermal_zone_device_ops *multi_ops; + + ret = thermal_of_multi_sensor_validate_coeff(sensor, id, np); + if (ret) + return ERR_PTR(ret); + + multi_ops = 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 = thermal_of_bind; + multi_ops->unbind = thermal_of_unbind; + + multi_tz = 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 = thermal_of_multi_sensor_get_name(sensor, id, np, name); + if (ret) + goto out_release_multi_tz; + + tz = thermal_tripless_zone_device_register(name, devdata, ops, tzp); + if (IS_ERR_OR_NULL(tz)) { + ret = PTR_ERR(tz); + goto out_release_multi_tz; + } + + ret = thermal_of_mutli_sensor_coeff(sensor, id, np, &coeff); + if (ret) + goto out_release_tz; + + ret = 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_register(struct device_node * const char *action; int delay, pdelay; int ntrips; + int count; int ret; np = of_thermal_zone_find(sensor, id); @@ -488,10 +703,19 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * return ERR_CAST(np); } - trips = thermal_of_trips_init(np, &ntrips); - if (IS_ERR(trips)) { - pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); - return ERR_CAST(trips); + count = of_count_phandle_with_args(np, "thermal-sensors", + "#thermal-sensor-cells"); + if (count <= 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 = thermal_of_trips_init(np, &ntrips); + if (IS_ERR(trips)) { + pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); + ret = PTR_ERR(trips); + goto out_kfree_trips; + } } ret = thermal_of_monitor_init(np, &delay, &pdelay); @@ -502,17 +726,25 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * thermal_of_parameters_init(np, &tzp); - of_ops.bind = thermal_of_bind; - of_ops.unbind = thermal_of_unbind; + if (count == 1) { + of_ops.bind = thermal_of_bind; + of_ops.unbind = thermal_of_unbind; + } ret = of_property_read_string(np, "critical-action", &action); if (!ret) if (!of_ops.critical && !strcasecmp(action, "reboot")) of_ops.critical = thermal_zone_device_critical_reboot; - tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips, - data, &of_ops, &tzp, - pdelay, delay); + if (count == 1) { + tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips, + data, &of_ops, &tzp, + pdelay, delay); + } else { + tz = thermal_of_register_multi_tz(sensor, id, np, np->name, trips, + ntrips, data, &of_ops, &tzp, + pdelay, delay); + } if (IS_ERR(tz)) { ret = PTR_ERR(tz); pr_err("Failed to register thermal zone %pOFn: %d\n", np, ret); From patchwork Fri May 24 14:31:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 798834 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 B739812D1FE for ; Fri, 24 May 2024 14:32:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561124; cv=none; b=Nit1tuJLlBAFR4upEzqtC8M5d02sznO5h0gl9ynwRtQ0aTFrht6LPfRA3SxXHW48APXXzUpZlWlWFngDgEf0brRT64NUz6V2cFI2jpbCPyLyNw1CoMVLshNKsYlef7mA0w9sdVCWrJR3xOqFr4HFw+kn38wYQ2ZM/xLCemQ1UhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561124; c=relaxed/simple; bh=mGHJTIEqaOM3rGni2f2k2W0qT+PA8lgJbBpgTIxC7k8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=et5zfrpFNkriBRMxX4ZqISETQx1TcfamUyGG19/XBwbluBQm3Na60Ur6Qi9kkdZl/9I1JSYzVUuujCoQVd6o1kJ7fOT1flMgi7rzsz28d63R0WPKQlA8tyowNxNsbO36qlBXzYvQx9yG+APqIYrI+buuCuM7aHkkyU+wve5ZPaY= 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.208.172 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-lj1-f172.google.com with SMTP id 38308e7fff4ca-2e724bc46bfso71453091fa.3 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=FyaHSm5sCDEl+L6xr1hMpsF6vzGQ2bmVpjGqln655CDVtlgenLKcwG7zJYUwrjrbsk jXNA2+acaa9q1PCJajjHdJzWbV95FTIxL3eJUKNG7Qc/DLyqHLdyyatkcUDN3xx18cMP ifg6YAtC6Tzdd1UFXFG8SIt8jcfXTRXAUUjpLP/0k6tQTDNltELg5pv1qpiJ4CSe0QOC /LipbYL9l5zvxRg5Od1p7cp+mif2vIE8RfM/RKPbXWsk6fAEBJhWKsrSEKdhwAyhRmlq sv2CykAAfvgfhnNOMi8GOnckrIQ+lC/o6BCev9x837OLNbkGfh7dw353EfLRmYzbE4zb bcTA== X-Forwarded-Encrypted: i=1; AJvYcCXfOsFV3pZbriZy3R+I1ARUvFeY76jB8bnGVFiQ7qolDiRSMjkSFHK+RWRPGibe/aXGsTBezpW4bWAinON7QU9cTK0mykEvJHY= X-Gm-Message-State: AOJu0YxIJ4tFXYqqqDk98hGFVLW6mjW2NSHuVmBXtFMTUrNMaoxcX+kc eY0M4S+VVwnVueHrxNIkF2bBA96E74xrUrKMhE8S6ZMT7LMXdV5wPKZFPKbL20w= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 of the sensor ID. Additional coefficients are interpreted as constant offset. + aggregation: + $ref: /schemas/types.yaml#/definitions/string + enum: + - avg + - max + description: + Aggregation type to use compute a temperature from multiple sensors. + sustainable-power: $ref: /schemas/types.yaml#/definitions/uint32 description: From patchwork Fri May 24 14:31:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 799147 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 7879212D759 for ; Fri, 24 May 2024 14:32:04 +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=1716561126; cv=none; b=N6Gu0BoQLqOaziexAi/GU6xguMuVdDW2Pmd6kOvYcilBm3ld8Z/Qp2NSTRGNJv32d0OgxI5BA9bT/0k1s1Z3o5n6T9Jc+XkRW2fQA95b/0aZradGM0/hHExBWML8MSVQSL24B7aL+JVJ01XKXU4OO+3csPwi9ynUPhBZ0IfrhQU= 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.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="ZCKTf9DP" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-351b683f2d8so2717924f8f.3 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=S5la5Yx6eHG1j9cHB/dvAXgzeutbsfCd45zrzpqNqcSIV7C9ojIu3lu34fkxGFasRw qvqrW65bE/yF3Qe/B35B9aipgXnNIe31FSKXFPRWdWq0k+xngogPn4QD9NYcsAQD/eQz PSpjZXvSXjtfUafF0LnP7ng0PL1YOt948/aByVsJbCYyjpHxoFa/e5Bis+JWWr1y7T6P HMqgnU5LAb3VPbuk/F3dWSmyHxZ7JSF10X5I6M90XRTV9aBfZbScpSkIVnCNMX36bekg M7ha/ff8S9iMwNMfzpdkkO74MfWfMmQR6/5BbkcYOaciu2IjeIeFmHo5T0AzjTogwMbM Ls7w== X-Forwarded-Encrypted: i=1; AJvYcCWxpeI/aYy67kBpVSYvnBwzxDl4uzALHWZEcQp3wCm2WFhG1yQhbOj6mh2o/TokK1DkwkCmg0KXmVr+bC5zgxbR9xN5n86Ajq4= X-Gm-Message-State: AOJu0YyVxYWqLFC+FwLbabq0tBX+S4ImV/UVH+Pg1BwNsRa3UeVqEDSM ovujaLtlQpcVHmP8s1BBm3804SBO9FQkcRd+uBGDzhstk6wFL3+s9sFbv9IJZhI= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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); } +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); From patchwork Fri May 24 14:31:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 798833 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 3F89F12DD85 for ; Fri, 24 May 2024 14:32:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716561128; cv=none; b=QEPwo/OVNzf0/eKNeYf4+15PFVAe87WSE+K16NyaipAW4HcBcDI3JuB5KltJepHPDvlDbHtInBz7FX4m+dx76wWj87odU0OMjxskpodrtAUO013+VVVdUd+KRHBQIdTE+ma2+Kjx+Ti98U8GrxLKARXJnzUBQq5mrqrgkMo/T74= 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.128.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="gpdaIOqf" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-420180b58c5so30154505e9.3 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=Va18eDhI+Qz4+J1s/CsMQtuZdF86w9xhT1WBQR2NlNLhK/At3sli0waWQNqg+eJbJd roYoFPG0RuT4mmoNs5u2XHRyhXYj0alH/9YjZqxEje/Zi4ZlstA9S5gNjgMnJKWfc/42 AJltatFBVsdbgYCHMHL6Xf+G6XwJ0X3i2yApbc0RuX05E6cW6NYS0HGh+AC/BuYj6Ufm AgN1XMqW+x1BMW3i40Sy9LG5HoRT2pYAMY60tXjR7sgRsbwGPlmSWD+0T5Fx92T+FkH1 MGLoj6sc3XzcIwxhfOlK8WkBCclJig9MmQGULCXsqfxUsHDpcfZNYYEnWjHXVD0PESCV Yvvg== X-Forwarded-Encrypted: i=1; AJvYcCUKk/+RbCEI43LmQIRnMCxv3FeSylHpdqfb8ALKeckU3zq6v2SsXK2oJFvJl6DlsB6CFEC7/AK8PDFb93qubu30axssHChI+7E= X-Gm-Message-State: AOJu0Yz5XuCB4F6ZdFHheSWLUoIKlppS3Baup4VfNaU/LjeOEa/+K2IS 34rzGZhVCU75/I80DyR2j216GmUAE5EOesF1Trp5wWpVbKOecrRGew2IQvgE/FE= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 { }; thermal_zones: thermal-zones { - cpu0-thermal { + cpu-little { polling-delay = <1000>; - polling-delay-passive = <250>; - thermal-sensors = <&lvts_mcu MT8195_MCU_LITTLE_CPU0>; + polling-delay-passive = <100>; + thermal-sensors = <&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 = <1500>; + aggregation = "max"; trips { - cpu0_alert: trip-alert { - temperature = <85000>; + cpu_little_threshold: trip-point { + temperature = <68000>; hysteresis = <2000>; type = "passive"; }; - cpu0_crit: trip-crit { - temperature = <100000>; - hysteresis = <2000>; - type = "critical"; - }; - }; - - cooling-maps { - map0 { - trip = <&cpu0_alert>; - cooling-device = <&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 = <1000>; - polling-delay-passive = <250>; - thermal-sensors = <&lvts_mcu MT8195_MCU_LITTLE_CPU1>; - - trips { - cpu1_alert: trip-alert { + cpu_little_target: target { temperature = <85000>; hysteresis = <2000>; type = "passive"; }; - cpu1_crit: trip-crit { - temperature = <100000>; + cpu_little_soc_max_crit: soc-max-crit { + temperature = <115000>; hysteresis = <2000>; type = "critical"; }; @@ -3651,7 +3632,7 @@ cpu1_crit: trip-crit { cooling-maps { map0 { - trip = <&cpu1_alert>; + trip = <&cpu_little_target>; cooling-device = <&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 { }; }; - cpu2-thermal { + cpu-big { polling-delay = <1000>; polling-delay-passive = <250>; - thermal-sensors = <&lvts_mcu MT8195_MCU_LITTLE_CPU2>; + thermal-sensors = <&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 = <1500>; + aggregation = "max"; trips { - cpu2_alert: trip-alert { - temperature = <85000>; + cpu_big_threshold: trip-point { + temperature = <68000>; hysteresis = <2000>; type = "passive"; }; - cpu2_crit: trip-crit { - temperature = <100000>; - hysteresis = <2000>; - type = "critical"; - }; - }; - - cooling-maps { - map0 { - trip = <&cpu2_alert>; - cooling-device = <&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 = <1000>; - polling-delay-passive = <250>; - thermal-sensors = <&lvts_mcu MT8195_MCU_LITTLE_CPU3>; - - trips { - cpu3_alert: trip-alert { - temperature = <85000>; - hysteresis = <2000>; - type = "passive"; - }; - - cpu3_crit: trip-crit { - temperature = <100000>; - hysteresis = <2000>; - type = "critical"; - }; - }; - - cooling-maps { - map0 { - trip = <&cpu3_alert>; - cooling-device = <&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 = <1000>; - polling-delay-passive = <250>; - thermal-sensors = <&lvts_mcu MT8195_MCU_BIG_CPU0>; - - trips { - cpu4_alert: trip-alert { + cpu_big_target: target { temperature = <85000>; hysteresis = <2000>; type = "passive"; }; - cpu4_crit: trip-crit { - temperature = <100000>; - hysteresis = <2000>; - type = "critical"; - }; - }; - - cooling-maps { - map0 { - trip = <&cpu4_alert>; - cooling-device = <&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 = <1000>; - polling-delay-passive = <250>; - thermal-sensors = <&lvts_mcu MT8195_MCU_BIG_CPU1>; - - trips { - cpu5_alert: trip-alert { - temperature = <85000>; - hysteresis = <2000>; - type = "passive"; - }; - - cpu5_crit: trip-crit { - temperature = <100000>; - hysteresis = <2000>; - type = "critical"; - }; - }; - - cooling-maps { - map0 { - trip = <&cpu5_alert>; - cooling-device = <&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 = <1000>; - polling-delay-passive = <250>; - thermal-sensors = <&lvts_mcu MT8195_MCU_BIG_CPU2>; - - trips { - cpu6_alert: trip-alert { - temperature = <85000>; - hysteresis = <2000>; - type = "passive"; - }; - - cpu6_crit: trip-crit { - temperature = <100000>; - hysteresis = <2000>; - type = "critical"; - }; - }; - - cooling-maps { - map0 { - trip = <&cpu6_alert>; - cooling-device = <&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 = <1000>; - polling-delay-passive = <250>; - thermal-sensors = <&lvts_mcu MT8195_MCU_BIG_CPU3>; - - trips { - cpu7_alert: trip-alert { - temperature = <85000>; - hysteresis = <2000>; - type = "passive"; - }; - - cpu7_crit: trip-crit { - temperature = <100000>; + cpu_big_soc_max_crit: soc-max-crit { + temperature = <115000>; hysteresis = <2000>; type = "critical"; }; @@ -3831,7 +3673,7 @@ cpu7_crit: trip-crit { cooling-maps { map0 { - trip = <&cpu7_alert>; + trip = <&cpu_big_target>; cooling-device = <&cpu4 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, <&cpu5 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,