From patchwork Fri Aug 23 15:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 13775452 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 80117188A22 for ; Fri, 23 Aug 2024 15:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427800; cv=none; b=ZMDkQVUS051DlrW/HgfWWtNWltcMPc/aitwQWR9z+wV5a2MwnW6u6mtkFQsCgEKGNY3vXKEx5CzjuX4I6o9F/QVBxwMwe5OHSJOKrTeFzhoGVsIYQYfpeMk96jOrZeQ5JvRPC7vJfmdUAc8W2yozWHpjMB5Sb5vXyt7E+DKrRGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427800; c=relaxed/simple; bh=bmF/l1LbHdLeJhEhwamKHcjNbTSX7NoZJ8UiMeN7k2E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=o0jJZKbaD4LVamYxmBtcE7wE0qwwiLrrcJYppicR+YpX3vNWMi10hE82FSGKnfbg20GdZbLrZ9TnzoazyInq6cdc1Gp5jDk/liHNlSaBH61Of+yPXxhSru30hiq6n3/wWVIShMPnWLq+jiXz212eJibkdN5Gt72BDaS0lEMrZAY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=SUkCJBXu; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="SUkCJBXu" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-371b97cfd6fso1272456f8f.2 for ; Fri, 23 Aug 2024 08:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724427796; x=1725032596; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hBhWwm4oydvRBZ98sd3zd4gjG27RDsuzgB7f2d5Wo+0=; b=SUkCJBXuD2vzhMyFuuuJYkF2hiPDX69yMTOF6y7oVlrPa+QdXIXadtWOMPDeWgUFFB h53AWiDUblp2yZBB2qAzhwQCGjEtE1yns4x5R/e4xWaa1oyR6VLVJxQHjEwyxU92oy5N W0mrd022AsHMMu23PD35ZdJeuu46alnMrBBx6bFeUDfPk57XRYU1iBlm1RhggnLZduWM DIykJsOxhydAL0y5FCWqhBdsWyy9U/09VUwXzyYyMcJ9kVQrcZYKiGBfKclL9XcD8sJ6 EdSLDRlLjo1OpzCRzy1YmUKIYWwtX6jB2UtuC1yZrA3dBVcsc74fF8kC7sg3FA/dG8Fq jFjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724427796; x=1725032596; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hBhWwm4oydvRBZ98sd3zd4gjG27RDsuzgB7f2d5Wo+0=; b=FWrNvBUk5XNoqR+su0gFahvalx7mUg0af3GtHE0ZD4xHJGuhWJHCg+PBYunX2PrQMN S0v3TGtbsS8L/VAi1rJHYCgboaJE1zKOYCXwTsplxM0zhQnAO09/OVn1BesNPF7as4+g sQbjnMO9VPBv6g7c8fI5oUztStF+hH5VDfcg2rHN2uaT85oqcaFfVaLiirXc+OYDc65J Iji9y71boeajjbYsZ83W3e/ekmy2DMDC+a2hPPJVQpqwlhHvvIQN91RdDVLb+283bsn2 PiwZqVNt05308yoADedmjAzojKNdqVS/Qg6IxP6ZSTrgnIJemGvMB8lqqkCG64Ych+iN GrBQ== X-Gm-Message-State: AOJu0YxFapGhH//2tmysoyS1s1Mx0Hc8FDuIy6N3558Dji8NjiG3rN8C tEvpozeOGlo9qr1lYT/IhxlFVki0mb77zTG5ZBeCvi1GE+Cz1m79f8Kfi9RGFQ0= X-Google-Smtp-Source: AGHT+IGz70GF2Iu66e2l7biNRmD2tbKn60KoDEtcX1G/RoEp/vFk39D56AkjZrEkceT8P0IZPwgJ4Q== X-Received: by 2002:a05:6000:18c3:b0:371:a8a3:f97c with SMTP id ffacd0b85a97d-3731185234cmr1517567f8f.6.1724427795530; Fri, 23 Aug 2024 08:43:15 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-373081ff5b8sm4395891f8f.85.2024.08.23.08.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 08:43:15 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, =?utf-8?q?J=C3=A9r=C3=A9mie_Garcia?= , Alexandre Bailon , Zhang Rui , Lukasz Luba , linux-kernel@vger.kernel.org (open list) Subject: [RFC PATCH 1/2] thermal/core: Use thermal_zone_device_param Date: Fri, 23 Aug 2024 17:42:43 +0200 Message-ID: <20240823154245.1553458-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function thermal_zone_device_register_*() have now a significant number of parameters. Simplify the parameters by extending the thermal_zone_device_param structure with the parameters usually used when registering the thermal zone. With that change we have a simpler function: thermal_zone_device_register() which can be reused in the different drivers and replace the duplicate thermal_zone_device_register_with_trips() and thermal_zone_device_register_tripless() functions. Cc: Jérémie Garcia Cc: Alexandre Bailon Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal_core.c | 9 +++++++ include/linux/thermal.h | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index e6669aeda1ff..5869562caf9e 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1390,6 +1390,15 @@ int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp) } EXPORT_SYMBOL_GPL(thermal_zone_get_crit_temp); +struct thermal_zone_device *thermal_zone_device_register(const char *type, + const struct thermal_zone_params *tzp) +{ + return thermal_zone_device_register_with_trips(type, tzp->trips, tzp->num_trips, + tzp->devdata, tzp->ops, + tzp, tzp->passive_delay, + tzp->polling_delay); +} + /** * thermal_zone_device_register_with_trips() - register a new thermal zone device * @type: the thermal zone device type diff --git a/include/linux/thermal.h b/include/linux/thermal.h index b86ddca46b9e..1681b9ddd890 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -174,11 +174,45 @@ struct thermal_zone_params { * Used by thermal zone drivers. */ int slope; + /* * @offset: offset of a linear temperature adjustment curve. * Used by thermal zone drivers (default 0). */ int offset; + + /* + * @trips: a pointer to an array of thermal trips + */ + const struct thermal_trip *trips; + + /* + * @num_trips: the number of trip points the thermal zone support + */ + int num_trips; + + /* + * @devdata: private device data + */ + void *devdata; + + /* + * @ops: standard thermal zone device callbacks + */ + const struct thermal_zone_device_ops *ops; + + /* + * @passive_delay: number of milliseconds to wait between polls when + * performing passive cooling + */ + unsigned int passive_delay; + + /* + * @polling_delay: number of milliseconds to wait between polls when checking + * whether trip points have been crossed (0 for interrupt + * driven systems) + */ + unsigned int polling_delay; }; /* Function declarations */ @@ -218,6 +252,10 @@ void thermal_zone_set_trip_temp(struct thermal_zone_device *tz, int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp); #ifdef CONFIG_THERMAL + +struct thermal_zone_device *thermal_zone_device_register(const char *type, + const struct thermal_zone_params *tzp); + struct thermal_zone_device *thermal_zone_device_register_with_trips( const char *type, const struct thermal_trip *trips, @@ -281,6 +319,11 @@ int thermal_zone_device_enable(struct thermal_zone_device *tz); int thermal_zone_device_disable(struct thermal_zone_device *tz); void thermal_zone_device_critical(struct thermal_zone_device *tz); #else +static inline struct thermal_zone_device *thermal_zone_device_register( + const char *type, + const struct thermal_zone_params *tzp) +{ return ERR_PTR(-ENODEV); } + static inline struct thermal_zone_device *thermal_zone_device_register_with_trips( const char *type, const struct thermal_trip *trips, From patchwork Fri Aug 23 15:42:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 13775453 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 725051885AF for ; Fri, 23 Aug 2024 15:43:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427800; cv=none; b=b0S84JfAnQqJI3WEVL3WNsd0OSkiu4xPFp8fhbRMJsaROEh+OJDKyh2gYTMQPKMZmX0D7q+N3ZzTjTtaxdfTNb9fINrZgXSv2g4330nLhp1nXpVstrwG7W73bMPEi0oLXihe/RzopL/TYg6vwi68UmGOPxZe2zplQ7W5lXmOosA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724427800; c=relaxed/simple; bh=UAAKsIvCmNiVqRTFLcLoUi86VSU3tPObaOIJAs0+nhA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RR7Itb3qG32mLtdWh6EHyZ88M22RWqYBqZFeuGUPM97ZN85/hWPU8LzwQf/sbTD4q/OJavsW4An18mttI03eX62PkWJQgFfshUa/5wJMIxPlLFn4pbQadO5y5XMD35Re9e/CT6pVk450foDu4Bgt2cCdfLgCTae/gtDnxuuu4ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=j6JXTcaM; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="j6JXTcaM" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4281faefea9so16149795e9.2 for ; Fri, 23 Aug 2024 08:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724427797; x=1725032597; 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=WtnMpPUERM2pDdBMnHXsV0NgdHCRPYPmkwqv5dMYPzQ=; b=j6JXTcaMvgKn5W8iLbZSxd/KiNkvIXjagBaCFCH0AmkafB75u79rJ1/bfmI2svJ0q1 3KECHqtSVgrLjKE8aXuDgrcgtEJ5wgT9SGxKGnET8iT85j96/QXBJVATQbYS9HuIicGo HCwlOCH8IJ8sxHwnRlfQ6VkB9apBKaxvbt0mjlTU8oEm2jRxszXX4CXVL8YOC0V6CJZJ CozDTSmB6q0BW1qxSJs/x++PPSRgVASqz+pvPilliMlYpvZN3Y6M0EbIecdg3XYGyXJJ DnJ/n9CxiF7kXGLglZmEajvJY+9AEQ9pvFPMM14HITJyFbsN4k8ymB+AX/S8UhvKa+PY lgPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724427797; x=1725032597; 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=WtnMpPUERM2pDdBMnHXsV0NgdHCRPYPmkwqv5dMYPzQ=; b=YMxaBpux6dN9dMtXYbLhowKUYfVipeEhnUCxpf9OAxeNnLIQXEkmPDzEWB7GrelNaN UTRCDkbYjGozXb/EThhuSsgJWWjQcQEPgnl0oIIQS9UKp2WXbD7du0jsZM50fSKZ3XKo bScjoJpUnPBS2QtT+6vk5f4ZCXYGOlxyfFRf7cAYhoBg02iDr+vd9ndyw0bK/ubbEmbN ouVH8EU/LmXS3uVK3ZO2v3sObk0Tvk3G5jYB69IihSBFlpSpxPwkl/CbhyN8P9lqdLqF 38nFDqjU6DGP7+Rum3Ntt11b/ij/IBuR3DrGjThs5Azynf5Z//AMuwV0taf2BWTW4fmB bwCg== X-Gm-Message-State: AOJu0YwkNsfFmWuGkmAJaTr3QiP5MLLpPj0lDZ1Jrxq4E4Z0ir+Ma79e 72Bk+qlk9KZMvwkve/6W3PfFgLbHMTGZ557ts7e8aQx7EM2M97op8w05k7OL4MY= X-Google-Smtp-Source: AGHT+IH/51VXtSOjuCnDyuonQwj6xZRhLMvkaTQ3d7h/0AoF41O+/4rayP6IPnGDhi6+Curs1LtZsg== X-Received: by 2002:a05:600c:4a9d:b0:427:ac40:d4b1 with SMTP id 5b1f17b1804b1-42b89bf4d11mr6601865e9.27.1724427796647; Fri, 23 Aug 2024 08:43:16 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-373081ff5b8sm4395891f8f.85.2024.08.23.08.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 08:43:16 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, =?utf-8?q?J=C3=A9r=C3=A9mie_Garcia?= , Alexandre Bailon , Zhang Rui , Lukasz Luba , linux-kernel@vger.kernel.org (open list) Subject: [RFC PATCH 2/2] thermal/of: Use thermal_zone_device_param Date: Fri, 23 Aug 2024 17:42:44 +0200 Message-ID: <20240823154245.1553458-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240823154245.1553458-1-daniel.lezcano@linaro.org> References: <20240823154245.1553458-1-daniel.lezcano@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As we can use the thermal_zone_device_param structure to pass the thermal zone parameters, let's use it in thermal-of code. Cc: Jérémie Garcia Cc: Alexandre Bailon Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal_of.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 1f252692815a..3e494ff88648 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -474,12 +474,9 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * { struct thermal_zone_device_ops of_ops = *ops; struct thermal_zone_device *tz; - struct thermal_trip *trips; - struct thermal_zone_params tzp = {}; + struct thermal_zone_params tzp = { .devdata = data, .ops = &of_ops }; struct device_node *np; const char *action; - int delay, pdelay; - int ntrips; int ret; np = of_thermal_zone_find(sensor, id); @@ -489,14 +486,14 @@ 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)) { + tzp.trips = thermal_of_trips_init(np, &tzp.num_trips); + if (IS_ERR(tzp.trips)) { pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); ret = PTR_ERR(trips); goto out_of_node_put; } - ret = thermal_of_monitor_init(np, &delay, &pdelay); + ret = thermal_of_monitor_init(np, &tzp.polling_delay, &tzp.passive_delay); if (ret) { pr_err("Failed to initialize monitoring delays from %pOFn\n", np); goto out_kfree_trips; @@ -512,9 +509,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * 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); + tz = thermal_zone_device_register(np->name, &tzp); if (IS_ERR(tz)) { ret = PTR_ERR(tz); pr_err("Failed to register thermal zone %pOFn: %d\n", np, ret); @@ -522,7 +517,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * } of_node_put(np); - kfree(trips); + kfree(tzp.trips); ret = thermal_zone_device_enable(tz); if (ret) { @@ -535,7 +530,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * return tz; out_kfree_trips: - kfree(trips); + kfree(tzp.trips); out_of_node_put: of_node_put(np);