From patchwork Thu Jun 13 13:24:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 804044 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 08EAB145343 for ; Thu, 13 Jun 2024 13:24:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285059; cv=none; b=VPC62Sjr0zQJpgwgqWRWzNkhTXVHS9WHtCmXn7cC/28gVKiJQp0g0QqH46inrtxZGCWuzwEzkP7OF34pxXfUBM4b6tw2n9VbbCODdzfunTkQ7kFOsLn0cxCSMInD7ARyAErzvBQY3X4+I0FkUzEpkigFAMbttKb+/Y+xhbprEU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285059; c=relaxed/simple; bh=rnldv7833XODCkkhE2IoJHX1ijFNhpuCcMgGUEpMC7w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MTXKi4fTnyK0Rhd3q+RkCsEgvnrhlD4toDylGPXqq4hB7Sl4OYK2gY3JxZnCrdMlXGAXprsTdIVKO7tSuEVEttmCEUYWIlSC9NLqbSBlzF2UjWc7PLzVPEWDb2TNGZfyt0G4D+Hbi0Mj0EK8JFwKdWFMz5QUt/bu2dE464I619E= 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=dVtQKdED; arc=none smtp.client-ip=209.85.128.51 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="dVtQKdED" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4230366ad7bso4321805e9.1 for ; Thu, 13 Jun 2024 06:24:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718285056; x=1718889856; 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=dVtQKdEDmWJhRc5J5qjUfL8DaZXdrdqZeBSpMsQcgTx7OhEmPo/A/H3GERSIrzUhf/ NvmUs54kkXt7kLERWqk0cpe1owPb92fIwOzjwe9UmIvo26vaqB5Zb4lzPA7ymOLsW8MF Fku+erMegf/wSDFxSV1YfbHgtvGOlwxVIziNuwNrkyvtfdeh/pPBL3OQLGBpo0ITpOdT 0JBJqfrWrUixz8Yhuj7X22XXxL4PXu2e7PC+pFl/J5Mpk4yLdGdTddFAmDFshUq2iwQm tDvREFDxXWywgDSYN3g716Ty8pdbe3ms24foPqM+bXE17693EmOsBJTShs2T07q1S7Au z2FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718285056; x=1718889856; 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=GKBFDqSvlBoUTyX76bEh7GAFlLrIpkV/n+Nz2QTrOckkljQOVH3/MzQf5pIMynpOpn UGjj+EgdjebBbO9Cdj03QyXzAqVrIif9lcQXN5l0CX4EmKQmVExakDBRA5fgg5JrRwwl Lu7Yg3sEja0d1HUmEMijERLgouveWgi8l5h3dkLNSrxvNXtOINH7j7juAVdOe1WQxql+ 1+J8liEdD+KwZ3QIqhi8HTC7HJ+DuP5ybPFu5QBeA8WMDToXhqg/89Z5PpjjHbaiYAba 0fpZ6r9/r4wNonnDm64tGz7xCjEv4Cs41eNCMnX9bAuHZyvoYfODJwdfsvi3sLAzndrJ 8bfg== X-Forwarded-Encrypted: i=1; AJvYcCW82XeGNrHQa/LK3fr+VEpDY4UgPinGXd9UP+AP60rRbmQhFIBgc5oNZO9rapuvzYhCPQTP7PsK8sr1HdVorUXXkvr3p9QTAWc= X-Gm-Message-State: AOJu0YwjSyxNO0yROnO6RDHjcBfzOY9RuS095CDYrzLqrJQiZHwUqkDA w1Xdef9Wx9KjklD9dZLcNdux2OW78DvZhBijDyPUK6Swu+EIREUW3i6DslbUI8s= X-Google-Smtp-Source: AGHT+IEJg/QKxM4h1Il+pvifbmJ54eJISJ780cLTsOHK41otmROyNxfcRHscGOFu/oRAa2gn49Gm7g== X-Received: by 2002:a05:600c:3d99:b0:421:dd8c:35a3 with SMTP id 5b1f17b1804b1-422866c2561mr59775105e9.26.1718285056346; Thu, 13 Jun 2024 06:24:16 -0700 (PDT) Received: from blaptop.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f5f33c6esm25086225e9.4.2024.06.13.06.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:24:15 -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 v4 1/4] dt-bindings: thermal: Restore the thermal-sensors property Date: Thu, 13 Jun 2024 15:24:07 +0200 Message-ID: <20240613132410.161663-2-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240613132410.161663-1-abailon@baylibre.com> References: <20240613132410.161663-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 Thu Jun 13 13:24:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 804742 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 99A0C144D1F for ; Thu, 13 Jun 2024 13:24:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285062; cv=none; b=WffUR1akKlBQOZlJdbXX++PDJ8i3nD1qV/cL5fO7PS2J+aRGZQWY8M6zPbXULgn+UoG4qP6pIq/TFv3IV7Fd/w8+ZxminJVNusX2k906iX1er2jwR6O1dSbqCA1Y+AVqA7chDHVcoLEmN4QDc942uwBnPTVsmjErxbWLMG/ZpWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285062; c=relaxed/simple; bh=j7f3ZXCinJ1j3RqxyoUU0BtazpbIWYMRhtwdrGF0DRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EPQ2aIEM/Gql91y13E+xQJiYZVeteE3osiOlhPfTQWFBUgVpqG2XEBklU2a7e/qquYufwAKSqzXp3bVkljALDUtmxRWT6WWB/dllUHz9F1hwUEBGswpsvazcrIdcgEMhSJ6xHkNxa13ukFQTaoOw96kyFV3F4PWKSoRy3m+5rAA= 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=vSRp1pYG; arc=none smtp.client-ip=209.85.128.46 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="vSRp1pYG" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4217136a74dso9657805e9.2 for ; Thu, 13 Jun 2024 06:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718285058; x=1718889858; 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=/LyOSi8f/3UaYrbHuOz6VLA6k5tiA3tUA9t+QNNaNjo=; b=vSRp1pYGWLsoWhr1wdptYe1itkN3vVztankJ+tU74HmFgOk2PZc4L8jnm8n3AJV2/p E8U8SjMkKil2uJTXBW13+8Wx9Qc7+NiiILJHEOegb5ptrysM621v6LpLYMo+f5OB57t3 SHJuPr8U4kXOZHACkxaBDHjJknirlUAMsWbvx3A9EROU9nWnAuThNtMKCheOUx+q8kCm hoX8gp2QVDSRitmh2MAfJdyfk8Wk/C0J+vXV4HeB3rLj48rmkzbSqnS9DR9NEjUrHC99 wrotLsl0x6xNFG1nHYQ5dYBshcD816DqAo/GBlUWuXY6C6rmqsZ1/ZQXZNU7B6D6vpwC JzCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718285058; x=1718889858; 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=/LyOSi8f/3UaYrbHuOz6VLA6k5tiA3tUA9t+QNNaNjo=; b=FzrF/NbPA9ICyNQe5rCau54sPq5gELBZ38xwhg6Yz34DNL7jwSsnziDKWARPYEaj0y ygJZ90fS13JavbLjzgBxLLSYqiuuJcI4/srouCLnDZyxe2VVQeqZjr7WBnYTEUv0B/yp e/LWeSl9kVUAEQxxRFZcF7dV49qANXf7nmWfsjuag98gwro5pXUeKoDnrCwqkobX9NcK Mm6oVKESAzdeqmny2Cip4T9HV/3bA1tWk3BmgX7S/6D+bnCmOLfXJ5Ly4cH4A0BeUWmx FLgkVgBQBJLRM3rnUUQdPutjiAGsrCyFGuRUcvcfIUJRzriPQXvDBws3w5yZWmt8O3De pmJA== X-Forwarded-Encrypted: i=1; AJvYcCXGgVlOuLrdPK5G4uMhivZ4NTZJST6Nc777tMdpoNhSoS3ZKoa5fUMZ6a0pz0wue6r7hpwUzShPdtciBhQvUw/AHOfg2PgKTcs= X-Gm-Message-State: AOJu0YwF5mV0Z6pZ0Mbrmy2GJ2b5Ps7WyLI6AXVM41HTLf6koyoQAcI+ YN8koQZz9mj6aYbxedlg/vvqrOeh9yFaRMiDnpaqviB2Ub+Ee/jh2aoX5DFaGeg= X-Google-Smtp-Source: AGHT+IGsOLsgFK7ts6VttFOyzjo0d0li8FyVir5Ilvh/4L2ZA8c+T3S4y7KLtVeT+iKItocG0DgtjA== X-Received: by 2002:a05:600c:3d16:b0:421:8345:7891 with SMTP id 5b1f17b1804b1-422863a8d1amr53462135e9.16.1718285057919; Thu, 13 Jun 2024 06:24:17 -0700 (PDT) Received: from blaptop.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f5f33c6esm25086225e9.4.2024.06.13.06.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:24:16 -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 v4 2/4] thermal: Add support of multi sensors to thermal_core Date: Thu, 13 Jun 2024 15:24:08 +0200 Message-ID: <20240613132410.161663-3-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240613132410.161663-1-abailon@baylibre.com> References: <20240613132410.161663-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 the maximum temperature among all the sensors. Signed-off-by: Alexandre Bailon --- drivers/thermal/Makefile | 1 + drivers/thermal/thermal_core.h | 15 ++ drivers/thermal/thermal_multi.c | 286 ++++++++++++++++++++++++++++++++ include/uapi/linux/thermal.h | 5 + 4 files changed, 307 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 20e7b45673d6..c2cf2c19738a 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -261,6 +261,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(void); +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..4b3f261a7000 --- /dev/null +++ b/drivers/thermal/thermal_multi.c @@ -0,0 +1,286 @@ +// 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_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. + * + * 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(void) +{ + struct thermal_zone_device_ops *ops; + + ops = kzalloc(sizeof(*ops), GFP_KERNEL); + if (!ops) + return ERR_PTR(-ENOMEM); + + ops->get_temp = multi_sensor_get_temp_max; + + 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_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(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 Thu Jun 13 13:24:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 804043 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 35A14145B24 for ; Thu, 13 Jun 2024 13:24:21 +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=1718285063; cv=none; b=cKNttv5HAq/xO3OMHUAPDlw9Johus2YCacXihrKNm9g3fNLUU7eYtV6cDAXSSoC1u89aafn/mT+htq/34uzXVmXL3mOS5bDY+mtaLyyrocLHtt1a6ot9xlc0evoo0TlhT5c8VWSODw1VR4IBCDjjsh3lgdgIjqJPlArxBY7be8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285063; c=relaxed/simple; bh=LpbziCjZRkzrPCbzYtUAQhYRDTw/5cNCLTZgMC5mxrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bG2B01+jfFWhsIa2V8R+eSHQqvgSwWa14rlpuKUkYacqdXICnA2lr0L11KieDAH5wfpoIqJ79hFhgwbcHCBUe1uc5H1CyegQOCPHgld57VyPZ+qlttzDvHK4t4oRqPCZ0tn9UB40ykCG220+7V+B+8jhoP4/JVkUsggRKAbDTEA= 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=v7CYwVN3; 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="v7CYwVN3" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4218008c613so8391165e9.2 for ; Thu, 13 Jun 2024 06:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718285059; x=1718889859; 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=Tya0ITp4z4S3hnZL7iK4UAV9x+Mi7A2TRjTzUlOjL/8=; b=v7CYwVN3TCuTZjXV5IVE04Lu+ji9UjYw3OCp9bxeN2OhWTGDa2imrnOQ5gqlLUmXIX 6CCAXqtuL3Zz7NeomSI4TCXFCgS9ua/6OjkLeJWwEen9/+y1KBikWVEadFxjtV/alJlT Yixy8aOxxjJZoWzKF7D60kQt2zyZ+jYCi3/sv2ck/m3ROfzqQvZyLw9aZA3eSzDSflDJ 8CO9ZGU5LbSjncOAhZzQbr9sF4zERoV7HBPYaohRFpYpNdDNJaYD5nZou1vSbOqg+yq/ uGpUyNYkCJ3oJ01Ej+RKGv1ZlE7gmtyxXAkpEFUJbn4rsISKy78Fqi9+4UawEwlD+hLt ErBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718285059; x=1718889859; 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=Tya0ITp4z4S3hnZL7iK4UAV9x+Mi7A2TRjTzUlOjL/8=; b=oNy7Azyyx/zo//tC4f8tMbwCNzSp9jxR5muo3R/BOvz/Cdjatz6PZFJCPrNrNG1XPz ZTni5e/AKgtfxb+W9PyIKglA39h1/gXh57ICu5r9cRFVNbg7oyZFq03oXKJOClTynywU yzUKm0pX8S3Xd95wuVntJkbqwTIZAEoVUteRUsPcUiGVaIits38TShFXaujJbr291+tC B5H0el+g2FJLpOAcC6kcTr5CObEDB9S3rPsGUC6MIeUK2UBIj0mQt/VyKBmcB+prarwu fBG6Dz6JyMSN9hy/p6Jvi+zUm7T0EKHQhOPRSB3gdBgVXhPcUwTGBe3prxnzdQ61fsjU Uy+g== X-Forwarded-Encrypted: i=1; AJvYcCX2kIazmXX6IVpW0PvhGMSnpYHw2it/neannC7KO6klyl5ZCgwXYAgd7CFJjgQmIzuGLdYGXab89ElZelIu43pkHrShBMBVIc8= X-Gm-Message-State: AOJu0YyhymNph88P8YQcGxz1iRxUPujOBRqZ07lcO585SFJxmTiJJbS/ Yb7A8pX7O7GSAmL9mt4/VDkPclrC8dYTU3JjOtJXnT2mITVttP8PON07G+ql5AY= X-Google-Smtp-Source: AGHT+IGbVJk/idr4DAbfqDBHeVeUSQXIMINdv853E/IV6oCCF2ifS2Cr4eRXr+Mrg1v3ct8+2iM7VQ== X-Received: by 2002:a05:600c:1f1a:b0:421:7407:d778 with SMTP id 5b1f17b1804b1-422862a7251mr36347485e9.14.1718285059563; Thu, 13 Jun 2024 06:24:19 -0700 (PDT) Received: from blaptop.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f5f33c6esm25086225e9.4.2024.06.13.06.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:24:18 -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 v4 3/4] thermal: Add support of multi sensors to thermal_of Date: Thu, 13 Jun 2024 15:24:09 +0200 Message-ID: <20240613132410.161663-4-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240613132410.161663-1-abailon@baylibre.com> References: <20240613132410.161663-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..fef966557b30 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(); + 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 Thu Jun 13 13:24:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 804741 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 CCEB9145FFD for ; Thu, 13 Jun 2024 13:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285064; cv=none; b=P9oA+i8aeSObNaw7JQdYQ5G9ev9wkK2J/OlmIHU9o2FZMetwm0OloL5GLj49wa6rR3CYQZI7AQY3DnpaFKZRMqmS/+wNt0k10vWiwHVaVfxeIwHUUsI4+t+9FVRq7/vJJwCxBucI+uUEb/F7CctTpeg5yWPXoDJQLAFRytDY0aU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718285064; c=relaxed/simple; bh=ei6MygeSgJsE+wcqS+H6XtwKC909xyCYznIa430bejg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aZ+LYcO6NiXW2/aqKZbU9CUIeC4yV/M0yN+d52Vl45uIC3qQsBbgBcOsoP/bbaUCMyMnwQak7ud7A+JbdOF020k53r9O0eWga3Ezq8MH1W1TTokcj+ErcncJV987MAo6uszUw9xUqQ8GkUNRaDQzzEVGPMvPwXXZbDcXe4DvF6c= 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=lVYHjfpX; arc=none smtp.client-ip=209.85.128.49 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="lVYHjfpX" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4218314a6c7so9888955e9.0 for ; Thu, 13 Jun 2024 06:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718285061; x=1718889861; 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=FIdfAng31JZ7AXh+5wJJBwNTBQjKsoPR8mg2mxmZaFA=; b=lVYHjfpXkOBC6G1ZkUaQ+V7WtKaalI0UX/StJ63ftEgS53JTpaDbxmYKC4QhwUaXo4 4JpN2r8r5xJugiOvqOjhJi7aEI3D8Asc5w0GVZ2fbMHj2qyoySpCkubNUr1A1JrKdBir lvyi9fR/C6snMQTOZplZyZGGmJpr8uDpKzHLvoKRbasEhFw6jFrI8M9scovaRQn+3fOu EbSQk2vqlrKn+FTPzNHlkYIQ/GgvUF/LjjDKGojpfPUXU6zvjA7NQTr7GEiZcr/wJbAt tGl+DpllKo39/DFAlJNIkgeMZg9ZQb4a/b1KtmcNCNzRw4BmmFk5DsaY0MnMNEEI/ZAj OMcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718285061; x=1718889861; 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=FIdfAng31JZ7AXh+5wJJBwNTBQjKsoPR8mg2mxmZaFA=; b=XNJObQQV47/dbSn4s1t3oSy4hW0BluJGA09YRCpuvD19OoSInf/LrCTiEQWuWqYTlb mU8IErZFlXSr1ZbEgHQjVSSO9BYpYWfbxXUTMQuQupgcE4rbimb/Nz00IKdYO2WCO49s fl2Te4jBXXD67najypBNw91drVkDLyLAeJnjY+eS7whU/+/ZFaNc/Ybq30re5chsjnyy EkRYyR8muynW10aNxLqJtL6KKqN/3Ag9+pMqN6oyMP+5HzJZLjMp2t3UWcn3YKK8TN8r q0M1+AkUt2jT6NGs7Sv3aOApXOH+829+pbgCfgtG/D+X2FCZcZVUaqvQT+BuGLs6+Udr v2Gw== X-Forwarded-Encrypted: i=1; AJvYcCV/5wchhzOkDhWkxjlKFxDhnWW8YFypE6GxkWOQ5kd/C94JeGNuyw4lg3jLG6OdnIyM2/2UiM3uO9zmmt2NYH+FFIwvezpkeXY= X-Gm-Message-State: AOJu0Yz00SMiUClY1i6ru5J/u3LzsbzNzpvb4PmexgNuWE+EtTlBiv7X JoDs6iKrqUFi1fs+kHOLBrPax36hS9VcWJEfYYEwzS9LEAMojgJL4DQPFUzd3Wg= X-Google-Smtp-Source: AGHT+IEaGyMoVlH5DAEAQTeEGpbxwW1clV0twr/chrl0KmoLh9fV5Vaxzf96/t1WHAqzFEyPkITxdw== X-Received: by 2002:a05:600c:190d:b0:421:82ed:28d1 with SMTP id 5b1f17b1804b1-422867c02f1mr39073585e9.41.1718285061285; Thu, 13 Jun 2024 06:24:21 -0700 (PDT) Received: from blaptop.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f5f33c6esm25086225e9.4.2024.06.13.06.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:24:20 -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 v4 4/4] ARM64: mt8195: Use thermal aggregation for big and little cpu Date: Thu, 13 Jun 2024 15:24:10 +0200 Message-ID: <20240613132410.161663-5-abailon@baylibre.com> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240613132410.161663-1-abailon@baylibre.com> References: <20240613132410.161663-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 | 210 +++-------------------- 1 file changed, 25 insertions(+), 185 deletions(-) diff --git a/arch/arm64/boot/dts/mediatek/mt8195.dtsi b/arch/arm64/boot/dts/mediatek/mt8195.dtsi index 5d8b68f86ce4..90778c609ceb 100644 --- a/arch/arm64/boot/dts/mediatek/mt8195.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8195.dtsi @@ -3600,50 +3600,30 @@ 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>; 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 +3631,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 +3640,30 @@ 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>; 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 +3671,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>,