From patchwork Mon Jun 17 17:49:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 1948771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rjwysocki.net header.i=@rjwysocki.net header.a=rsa-sha256 header.s=dkim header.b=khEwqy1n; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.48.161; helo=sy.mirrors.kernel.org; envelope-from=linux-tegra+bounces-2724-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [147.75.48.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2zBX2TtRz20Wg for ; Tue, 18 Jun 2024 04:37:08 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1BE89B29B63 for ; Mon, 17 Jun 2024 18:13:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC54619AA40; Mon, 17 Jun 2024 18:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="khEwqy1n" X-Original-To: linux-tegra@vger.kernel.org Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEF961991D7; Mon, 17 Jun 2024 18:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718647999; cv=none; b=JQmRPysTRmsHfMOYUBbreKi09N4iFzHrWhNZ3jFfKtzP/BMm90zqhvVTKdMa+/JJ49dbb6zrJmqcxeaoEczC6tkd0YmKfYDbW1IL4BHAOi8bdNTOArbmKuRcYYegcls9kk7KxtZqSiphQ4vei+Tha1uWOxAQdAnjZSkLbN7k3j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718647999; c=relaxed/simple; bh=N4431/dEqcLneJ0L4FqIhI85vfz3NLUuiDXk1AU3+nU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fv2Cv2+8/qRGLL9OhRPrnZzFVXvkT0u54ummcQm59YO+NoavvpDFfZPpegUHvzfHRwofQ3Yk0XPUjD4pEozZxeQ0kunM6v/KawQM+DsNDrm8BldXoTR2hLupMLcYniHGu+aMUx445rARWhuxPueKz9UxJXShxonFjKUbt191cEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=khEwqy1n reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id 77efd14f6b27b710; Mon, 17 Jun 2024 20:13:15 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 70A071661CEB; Mon, 17 Jun 2024 20:13:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1718647995; bh=N4431/dEqcLneJ0L4FqIhI85vfz3NLUuiDXk1AU3+nU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=khEwqy1nEFPglCqAk7bLLJkqxKbyVX0hyvsc4n3Z5I5NmIXpD4wqHFGgIOqEMo+tl SSDuzyjUtm028ZX6ul36c1ntDqEmNZ3vlPe2B8C3DheNPdC/QxXMgPeFC41c6gbwzc 79D4tsJf0aYp/V+IrUGeCdgroGt0LqPmQjaOKLRMy+xFoACYL4wiXalD3GHmE5k/0Z +2Nk29y1xvdGr02xr7ww+6KWrJ0I+hiN+74dpmZsimjxPQxYpIuqI6xBqAHAwrtqaS rsItBLw2QjuMJkPquwl0XZNgLPCylkgeeQ0lAwwQuYQFmqiROKnID8vcFQMQiU/9Lt 6duBRRNKe38wA== From: "Rafael J. Wysocki" To: Linux PM , linux-tegra@vger.kernel.org Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano , Thierry Reding , Jonathan Hunter Subject: [PATCH v1 02/14] thermal: helpers: Introduce thermal_trip_is_bound_to_cdev() Date: Mon, 17 Jun 2024 19:49:03 +0200 Message-ID: <2013201.usQuhbGJ8B@kreacher> In-Reply-To: <8409966.T7Z3S40VBb@kreacher> References: <8409966.T7Z3S40VBb@kreacher> Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrfedvhedguddvvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqthgvghhrrgesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhu khgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 From: Rafael J. Wysocki Introduce a new helper function thermal_trip_is_bound_to_cdev() for checking whether or not a given trip point has been bound to a given cooling device. The primary user of it will be the Tegra thermal driver. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_helpers.c | 47 ++++++++++++++++++++++++++++---------- include/linux/thermal.h | 3 ++ 2 files changed, 38 insertions(+), 12 deletions(-) Index: linux-pm/drivers/thermal/thermal_helpers.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_helpers.c +++ linux-pm/drivers/thermal/thermal_helpers.c @@ -39,30 +39,53 @@ int get_tz_trend(struct thermal_zone_dev return trend; } +static struct thermal_instance *get_instance(struct thermal_zone_device *tz, + struct thermal_cooling_device *cdev, + const struct thermal_trip *trip) +{ + struct thermal_instance *ti; + + list_for_each_entry(ti, &tz->thermal_instances, tz_node) { + if (ti->trip == trip && ti->cdev == cdev) + return ti; + } + + return NULL; +} + +bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz, + const struct thermal_trip *trip, + struct thermal_cooling_device *cdev) +{ + bool ret; + + mutex_lock(&tz->lock); + mutex_lock(&cdev->lock); + + ret = !!get_instance(tz, cdev, trip); + + mutex_unlock(&cdev->lock); + mutex_unlock(&tz->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(thermal_trip_is_bound_to_cdev); + struct thermal_instance * get_thermal_instance(struct thermal_zone_device *tz, struct thermal_cooling_device *cdev, int trip_index) { - struct thermal_instance *pos = NULL; - struct thermal_instance *target_instance = NULL; - const struct thermal_trip *trip; + struct thermal_instance *ti; mutex_lock(&tz->lock); mutex_lock(&cdev->lock); - trip = &tz->trips[trip_index].trip; - - list_for_each_entry(pos, &tz->thermal_instances, tz_node) { - if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { - target_instance = pos; - break; - } - } + ti = get_instance(tz, cdev, &tz->trips[trip_index].trip); mutex_unlock(&cdev->lock); mutex_unlock(&tz->lock); - return target_instance; + return ti; } EXPORT_SYMBOL(get_thermal_instance); Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -269,6 +269,9 @@ struct thermal_zone_device *thermal_zone int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); int thermal_zone_get_slope(struct thermal_zone_device *tz); int thermal_zone_get_offset(struct thermal_zone_device *tz); +bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz, + const struct thermal_trip *trip, + struct thermal_cooling_device *cdev); int thermal_zone_device_enable(struct thermal_zone_device *tz); int thermal_zone_device_disable(struct thermal_zone_device *tz); From patchwork Mon Jun 17 17:56:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 1948749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rjwysocki.net header.i=@rjwysocki.net header.a=rsa-sha256 header.s=dkim header.b=En3zpbUx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-tegra+bounces-2723-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2yg6285Jz20KL for ; Tue, 18 Jun 2024 04:13:22 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 490C2285E31 for ; Mon, 17 Jun 2024 18:13:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93EBB19A297; Mon, 17 Jun 2024 18:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="En3zpbUx" X-Original-To: linux-tegra@vger.kernel.org Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 168BC1990BD; Mon, 17 Jun 2024 18:13:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718647999; cv=none; b=kvOlBm3IA4cmbtcJQy5zDTr2SYUBPdWUJ6QvR034wzZtO5UMUYiq2EgNzAaHBMLiC2LvBJBTwVht1V5Ki3sa8epvlfTmvBy/yHTulPZPtQvKgtvAXN3Ji+VL4I5dpGJ94tL6ZcC7SBPv09iESnk9SeP0AZk3Iom3G9U4Sq0fnB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718647999; c=relaxed/simple; bh=wLE2yVrZmO8clQsdrxpf6sPfMe5xsA3rOLdO/l0VmqU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FA0dsBtZ2ywjIMUSEQtcdph2GyqUxMifXrox4Jolv+6+yiMykhCkeN3HcWyyHPto+sexo9CV/qERcQ1OSoPOgvMjIuBjOLbQUD5u2Jz0n8iYdu1tDcOgtlZZrBkgzjRxms1iL4MyMQU9hjfh40uUA05O0loIkD1KfxkpjrdiDvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=En3zpbUx reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id dae7ff0a8a334dfb; Mon, 17 Jun 2024 20:13:13 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 4E0AC16606FD; Mon, 17 Jun 2024 20:13:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1718647992; bh=wLE2yVrZmO8clQsdrxpf6sPfMe5xsA3rOLdO/l0VmqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=En3zpbUxkmE6M/3wbdZlLhGzjlUIjWAh/9CnFDWz5C4M4lbmhHNtUj4c3lwMVwnWH nPKPRCDLbFXgYEKh1EFm20A3Eq9REdT/ZuvUXdMY6q6/rQnP6Loc+cU0qy3AWOo6KO K0SQYo9jkgREh8bbB8Ggf+k2nZf9cPLyyj328Um5lbkbzho0weyzo1GEnUNnUjg+kM 3oOGC5PgvsARrCJTvtsnpdkQ3CH7s78OzBJI5v+zUvzn4Q/BAbTYpUg5sjZe9HNz+j xuR48ZI67MrHXgbhWzQwP73cyn0qc4eaCaVwW4beVnm/APbubdjU11r5ntUEEaaAR+ TNbmfWjvVQ9dg== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui , Shawn Guo , Pengutronix Kernel Team , Thara Gopinath , Thierry Reding , Jonathan Hunter , linux-wireless@vger.kernel.org, linux-tegra@vger.kernel.org, Miri Korenblit Subject: [PATCH v1 04/14] thermal: trip: Pass trip pointer to .set_trip_temp() thermal zone callback Date: Mon, 17 Jun 2024 19:56:52 +0200 Message-ID: <2174635.OBFZWjSADL@kreacher> In-Reply-To: <8409966.T7Z3S40VBb@kreacher> References: <8409966.T7Z3S40VBb@kreacher> Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrfedvhedguddvfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeduhedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopegurghnihgvlhdrlhgv iigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=15 Fuz1=15 Fuz2=15 From: Rafael J. Wysocki Out of several drivers implementing the .set_trip_temp() thermal zone operation, two don't actually use the trip ID argument passed to it, two call __thermal_zone_get_trip() to get a struct thermal_trip corresponding to the given trip ID, and the other use the trip ID as an index into their own data structures with the assumption that it will always match the ordering of entries in the trips table passed to the core during thermal zone registration, which is fragile and not really guaranteed. Even though the trip IDs used by core are in fact their indices in the trips table passed to it by the thermal zone creator, that is purely a matter of convenience and should not be relied on for correctness. For this reason, modify trip_point_temp_store() to pass a (const) trip pointer to .set_trip_temp() and adjust the drivers implementing it accordingly. This helps to simplify the drivers invoking __thermal_zone_get_trip() from their .set_trip_temp() callback functions because they will not need to do it now and the other drivers can store their internal trip indices in the priv field in struct thermal_trip and their .set_trip_temp() callback functions can get those indices from there. The intel_quark_dts thermal driver can instead use the trip type to determine the requisite trip index. Signed-off-by: Rafael J. Wysocki --- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 2 drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 8 +-- drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c | 3 - drivers/thermal/intel/intel_quark_dts_thermal.c | 26 +++++++--- drivers/thermal/intel/intel_soc_dts_iosf.c | 15 +++-- drivers/thermal/intel/x86_pkg_temp_thermal.c | 9 ++- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 10 +-- drivers/thermal/tegra/soctherm.c | 14 +---- drivers/thermal/thermal_sysfs.c | 2 include/linux/thermal.h | 3 - 10 files changed, 54 insertions(+), 38 deletions(-) Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -113,7 +113,7 @@ trip_point_temp_store(struct device *dev if (temp != trip->temperature) { if (tz->ops.set_trip_temp) { - ret = tz->ops.set_trip_temp(tz, trip_id, temp); + ret = tz->ops.set_trip_temp(tz, trip, temp); if (ret) goto unlock; } Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -93,7 +93,8 @@ struct thermal_zone_device_ops { int (*set_trips) (struct thermal_zone_device *, int, int); int (*change_mode) (struct thermal_zone_device *, enum thermal_device_mode); - int (*set_trip_temp) (struct thermal_zone_device *, int, int); + int (*set_trip_temp) (struct thermal_zone_device *, + const struct thermal_trip *, int); int (*get_crit_temp) (struct thermal_zone_device *, int *); int (*set_emul_temp) (struct thermal_zone_device *, int); int (*get_trend) (struct thermal_zone_device *, Index: linux-pm/drivers/net/wireless/intel/iwlwifi/mvm/tt.c =================================================================== --- linux-pm.orig/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ linux-pm/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -638,7 +638,7 @@ out: } static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device, - int trip, int temp) + const struct thermal_trip *trip, int temp) { struct iwl_mvm *mvm = thermal_zone_device_priv(device); int ret; Index: linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +++ linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c @@ -39,13 +39,14 @@ static int int340x_thermal_get_zone_temp } static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone, - int trip, int temp) + const struct thermal_trip *trip, int temp) { struct int34x_thermal_zone *d = thermal_zone_device_priv(zone); - char name[] = {'P', 'A', 'T', '0' + trip, '\0'}; + unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv); + char name[] = {'P', 'A', 'T', '0' + trip_index, '\0'}; acpi_status status; - if (trip > 9) + if (trip_index > 9) return -EINVAL; status = acpi_execute_simple_method(d->adev->handle, name, @@ -144,6 +145,7 @@ struct int34x_thermal_zone *int340x_ther zone_trips[i].type = THERMAL_TRIP_PASSIVE; zone_trips[i].temperature = THERMAL_TEMP_INVALID; zone_trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP; + zone_trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i); } trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt); Index: linux-pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +++ linux-pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c @@ -193,7 +193,8 @@ static int sys_get_curr_temp(struct ther return 0; } -static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) +static int sys_set_trip_temp(struct thermal_zone_device *tzd, + const struct thermal_trip *trip, int temp) { struct proc_thermal_pci *pci_info = thermal_zone_device_priv(tzd); int tjmax, _temp; Index: linux-pm/drivers/thermal/intel/intel_quark_dts_thermal.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/intel_quark_dts_thermal.c +++ linux-pm/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -195,7 +195,7 @@ static int get_trip_temp(int trip) } static int update_trip_temp(struct soc_sensor_entry *aux_entry, - int trip, int temp) + int trip_index, int temp) { u32 out; u32 temp_out; @@ -230,9 +230,9 @@ static int update_trip_temp(struct soc_s */ temp_out = temp + QRK_DTS_TEMP_BASE; out = (store_ptps & ~(QRK_DTS_MASK_TP_THRES << - (trip * QRK_DTS_SHIFT_TP))); + (trip_index * QRK_DTS_SHIFT_TP))); out |= (temp_out & QRK_DTS_MASK_TP_THRES) << - (trip * QRK_DTS_SHIFT_TP); + (trip_index * QRK_DTS_SHIFT_TP); ret = iosf_mbi_write(QRK_MBI_UNIT_RMU, MBI_REG_WRITE, QRK_DTS_REG_OFFSET_PTPS, out); @@ -242,10 +242,24 @@ failed: return ret; } -static inline int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, - int temp) +static inline int sys_set_trip_temp(struct thermal_zone_device *tzd, + const struct thermal_trip *trip, + int temp) { - return update_trip_temp(thermal_zone_device_priv(tzd), trip, temp); + unsigned int trip_index; + + switch (trip->type) { + case THERMAL_TRIP_HOT: + trip_index = QRK_DTS_ID_TP_HOT; + break; + case THERMAL_TRIP_CRITICAL: + trip_index = QRK_DTS_ID_TP_CRITICAL; + break; + default + return -EINVAL; + } + + return update_trip_temp(thermal_zone_device_priv(tzd), trip_index, temp); } static int sys_get_curr_temp(struct thermal_zone_device *tzd, Index: linux-pm/drivers/thermal/intel/intel_soc_dts_iosf.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/intel_soc_dts_iosf.c +++ linux-pm/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -129,18 +129,20 @@ err_restore_ptps: return status; } -static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, +static int sys_set_trip_temp(struct thermal_zone_device *tzd, + const struct thermal_trip *trip, int temp) { struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_priv(tzd); struct intel_soc_dts_sensors *sensors = dts->sensors; + unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv); int status; if (temp > sensors->tj_max) return -EINVAL; mutex_lock(&sensors->dts_update_lock); - status = update_trip_temp(sensors, trip, temp); + status = update_trip_temp(sensors, trip_index, temp); mutex_unlock(&sensors->dts_update_lock); return status; @@ -293,11 +295,12 @@ static void dts_trips_reset(struct intel } static void set_trip(struct thermal_trip *trip, enum thermal_trip_type type, - u8 flags, int temp) + u8 flags, int temp, unsigned int index) { trip->type = type; trip->flags = flags; trip->temperature = temp; + trip->priv = THERMAL_INT_TO_TRIP_PRIV(index); } struct intel_soc_dts_sensors * @@ -332,7 +335,7 @@ intel_soc_dts_iosf_init(enum intel_soc_d sensors->soc_dts[i].sensors = sensors; set_trip(&trips[i][0], THERMAL_TRIP_PASSIVE, - THERMAL_TRIP_FLAG_RW_TEMP, 0); + THERMAL_TRIP_FLAG_RW_TEMP, 0, 0); ret = update_trip_temp(sensors, 0, 0); if (ret) @@ -340,10 +343,10 @@ intel_soc_dts_iosf_init(enum intel_soc_d if (critical_trip) { temp = sensors->tj_max - crit_offset; - set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp); + set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp, 1); } else { set_trip(&trips[i][1], THERMAL_TRIP_PASSIVE, - THERMAL_TRIP_FLAG_RW_TEMP, 0); + THERMAL_TRIP_FLAG_RW_TEMP, 0, 1); temp = 0; } Index: linux-pm/drivers/thermal/intel/x86_pkg_temp_thermal.c =================================================================== --- linux-pm.orig/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ linux-pm/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -119,9 +119,11 @@ static int sys_get_curr_temp(struct ther } static int -sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) +sys_set_trip_temp(struct thermal_zone_device *tzd, + const struct thermal_trip *trip, int temp) { struct zone_device *zonedev = thermal_zone_device_priv(tzd); + unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv); u32 l, h, mask, shift, intr; int tj_max, val, ret; @@ -132,7 +134,7 @@ sys_set_trip_temp(struct thermal_zone_de val = (tj_max - temp)/1000; - if (trip >= MAX_NUMBER_OF_TRIPS || val < 0 || val > 0x7f) + if (trip_index >= MAX_NUMBER_OF_TRIPS || val < 0 || val > 0x7f) return -EINVAL; ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, @@ -140,7 +142,7 @@ sys_set_trip_temp(struct thermal_zone_de if (ret < 0) return ret; - if (trip) { + if (trip_index) { mask = THERM_MASK_THRESHOLD1; shift = THERM_SHIFT_THRESHOLD1; intr = THERM_INT_THRESHOLD1_ENABLE; @@ -296,6 +298,7 @@ static int pkg_temp_thermal_trips_init(i trips[i].type = THERMAL_TRIP_PASSIVE; trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP; + trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i); pr_debug("%s: cpu=%d, trip=%d, temp=%d\n", __func__, cpu, i, trips[i].temperature); Index: linux-pm/drivers/thermal/qcom/qcom-spmi-temp-alarm.c =================================================================== --- linux-pm.orig/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ linux-pm/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -261,17 +261,13 @@ skip: return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg); } -static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp) +static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, + const struct thermal_trip *trip, int temp) { struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz); - struct thermal_trip trip; int ret; - ret = __thermal_zone_get_trip(chip->tz_dev, trip_id, &trip); - if (ret) - return ret; - - if (trip.type != THERMAL_TRIP_CRITICAL) + if (trip->type != THERMAL_TRIP_CRITICAL) return 0; mutex_lock(&chip->lock); Index: linux-pm/drivers/thermal/tegra/soctherm.c =================================================================== --- linux-pm.orig/drivers/thermal/tegra/soctherm.c +++ linux-pm/drivers/thermal/tegra/soctherm.c @@ -582,11 +582,11 @@ static int tsensor_group_thermtrip_get(s return temp; } -static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp) +static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, + const struct thermal_trip *trip, int temp) { struct tegra_thermctl_zone *zone = thermal_zone_device_priv(tz); struct tegra_soctherm *ts = zone->ts; - struct thermal_trip trip; const struct tegra_tsensor_group *sg = zone->sg; struct device *dev = zone->dev; int ret; @@ -594,11 +594,7 @@ static int tegra_thermctl_set_trip_temp( if (!tz) return -EINVAL; - ret = __thermal_zone_get_trip(tz, trip_id, &trip); - if (ret) - return ret; - - if (trip.type == THERMAL_TRIP_CRITICAL) { + if (trip->type == THERMAL_TRIP_CRITICAL) { /* * If thermtrips property is set in DT, * doesn't need to program critical type trip to HW, @@ -609,7 +605,7 @@ static int tegra_thermctl_set_trip_temp( else return 0; - } else if (trip.type == THERMAL_TRIP_HOT) { + } else if (trip->type == THERMAL_TRIP_HOT) { int i; for (i = 0; i < THROTTLE_SIZE; i++) { @@ -620,7 +616,7 @@ static int tegra_thermctl_set_trip_temp( continue; cdev = ts->throt_cfgs[i].cdev; - if (get_thermal_instance(tz, cdev, trip_id)) + if (thermal_trip_is_bound_to_cdev(tz, trip, cdev)) stc = find_throttle_cfg_by_name(ts, cdev->type); else continue; From patchwork Mon Jun 17 18:02:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 1948751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rjwysocki.net header.i=@rjwysocki.net header.a=rsa-sha256 header.s=dkim header.b=tluoamCu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-tegra+bounces-2722-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2yg83Lsvz20KL for ; Tue, 18 Jun 2024 04:13:24 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 331341C23B0A for ; Mon, 17 Jun 2024 18:13:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FA5C19755E; Mon, 17 Jun 2024 18:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="tluoamCu" X-Original-To: linux-tegra@vger.kernel.org Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B67B71991BA; Mon, 17 Jun 2024 18:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718647999; cv=none; b=XzZDexAOOuknQSUusDE+TyxJz/fFrfLEH9lLyqziIaZhma+Q2Ei/VSrRsUYPzxAZyEeYlYB2FDB9H7bBHDgmSXnY4IEWSnkIKsoe/VvIRk8aFapCbq/Ml5kfrgFFDGj0z3dtISiCn4x26yAYgii73mipPoY21yRzmYM6ljZsl28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718647999; c=relaxed/simple; bh=7mdftKfiva4yGQi7egcP+5WH/goOfxgEbPUdP8Gm38A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t413cva7PBFKcaHMyleRtmqyhCTu5MrRGUiZB/zf/VMXyLM6vibSlWCbTSJ7L+16j4ovivdv6/VwNLsePklGkekGbz1ytzwYSwdE/BxCQmN34PPtqx3xLiI4eq+3J01Rx2vw/Hw/9sJ8vVVyfZcrNqTjzGI+aWVOf6GxWqWO9d8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=tluoamCu reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id 2802260fd3be30fa; Mon, 17 Jun 2024 20:13:08 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 5D93F16606FD; Mon, 17 Jun 2024 20:13:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1718647988; bh=7mdftKfiva4yGQi7egcP+5WH/goOfxgEbPUdP8Gm38A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tluoamCuWUD0K/C0A7uy6JSXNF6o752y8UYiX6jVTIOo9Nl+kvgckzX/dw4VTizVL cuBG4COwRWM9cS1oYnFU+3S1OhboFbzgZd68PDikfT0O1J7sqMOq5tVSuigAbCXMdF JM+fec0o0wZ5iwBsNgeno5qnmZsn721IPnOQhqDObscwCS6Q3L4sDVyWXUr4Z8YURz n33H3M9NsUHxM8XY1FB1QK7EOTKTeO4ojk8Vj8z8WW1J6aaB5lkEP9KXTK9ptd64B+ oU7vg+4F9SxQ3flRtNK4xN9zdqr6kfmePZ8fda/ie9ydcu8/3K0yZyav5DypD2CPwd deNofIc6Uoevg== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano , Thierry Reding , Jonathan Hunter , linux-tegra@vger.kernel.org Subject: [PATCH v1 09/14] thermal: tegra: Introduce struct trip_temps for critical and hot trips Date: Mon, 17 Jun 2024 20:02:50 +0200 Message-ID: <5022394.0VBMTVartN@kreacher> In-Reply-To: <8409966.T7Z3S40VBb@kreacher> References: <8409966.T7Z3S40VBb@kreacher> Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrfedvhedguddvvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgii tggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehthhhivghrrhihrdhrvgguihhnghesghhmrghilhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 From: Rafael J. Wysocki Introduce a helper structure, struct trip_temps, for storing the temperatures of the critical and hot trip points. This helps to make the code in tegra_tsensor_get_hw_channel_trips() somewhat cleaner and will be useful subsequently in eliminating iteration over trip indices from the driver. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/tegra/tegra30-tsensor.c | 34 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) Index: linux-pm/drivers/thermal/tegra/tegra30-tsensor.c =================================================================== --- linux-pm.orig/drivers/thermal/tegra/tegra30-tsensor.c +++ linux-pm/drivers/thermal/tegra/tegra30-tsensor.c @@ -303,8 +303,13 @@ stop_channel: return 0; } +struct trip_temps { + int hot_trip; + int crit_trip; +}; + static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd, - int *hot_trip, int *crit_trip) + struct trip_temps *temps) { unsigned int i; @@ -312,8 +317,8 @@ static void tegra_tsensor_get_hw_channel * 90C is the maximal critical temperature of all Tegra30 SoC variants, * use it for the default trip if unspecified in a device-tree. */ - *hot_trip = 85000; - *crit_trip = 90000; + temps->hot_trip = 85000; + temps->crit_trip = 90000; for (i = 0; i < thermal_zone_get_num_trips(tzd); i++) { @@ -322,14 +327,14 @@ static void tegra_tsensor_get_hw_channel thermal_zone_get_trip(tzd, i, &trip); if (trip.type == THERMAL_TRIP_HOT) - *hot_trip = trip.temperature; + temps->hot_trip = trip.temperature; if (trip.type == THERMAL_TRIP_CRITICAL) - *crit_trip = trip.temperature; + temps->crit_trip = trip.temperature; } /* clamp hardware trips to the calibration limits */ - *hot_trip = clamp(*hot_trip, 25000, 90000); + temps->hot_trip = clamp(temps->hot_trip, 25000, 90000); /* * Kernel will perform a normal system shut down if it will @@ -338,7 +343,7 @@ static void tegra_tsensor_get_hw_channel * shut down gracefully before sending signal to the Power * Management controller. */ - *crit_trip = clamp(*crit_trip + 5000, 25000, 90000); + temps->crit_trip = clamp(temps->crit_trip + 5000, 25000, 90000); } static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts, @@ -346,7 +351,8 @@ static int tegra_tsensor_enable_hw_chann { const struct tegra_tsensor_channel *tsc = &ts->ch[id]; struct thermal_zone_device *tzd = tsc->tzd; - int err, hot_trip = 0, crit_trip = 0; + struct trip_temps temps = { 0 }; + int err; u32 val; if (!tzd) { @@ -357,24 +363,24 @@ static int tegra_tsensor_enable_hw_chann return 0; } - tegra_tsensor_get_hw_channel_trips(tzd, &hot_trip, &crit_trip); + tegra_tsensor_get_hw_channel_trips(tzd, &temps); dev_info_once(ts->dev, "ch%u: PMC emergency shutdown trip set to %dC\n", - id, DIV_ROUND_CLOSEST(crit_trip, 1000)); + id, DIV_ROUND_CLOSEST(temps.crit_trip, 1000)); - hot_trip = tegra_tsensor_temp_to_counter(ts, hot_trip); - crit_trip = tegra_tsensor_temp_to_counter(ts, crit_trip); + temps.hot_trip = tegra_tsensor_temp_to_counter(ts, temps.hot_trip); + temps.crit_trip = tegra_tsensor_temp_to_counter(ts, temps.crit_trip); /* program LEVEL2 counter threshold */ val = readl_relaxed(tsc->regs + TSENSOR_SENSOR0_CONFIG1); val &= ~TSENSOR_SENSOR0_CONFIG1_TH2; - val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG1_TH2, hot_trip); + val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG1_TH2, temps.hot_trip); writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG1); /* program LEVEL3 counter threshold */ val = readl_relaxed(tsc->regs + TSENSOR_SENSOR0_CONFIG2); val &= ~TSENSOR_SENSOR0_CONFIG2_TH3; - val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG2_TH3, crit_trip); + val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG2_TH3, temps.crit_trip); writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG2); /* From patchwork Mon Jun 17 18:03:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 1948750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rjwysocki.net header.i=@rjwysocki.net header.a=rsa-sha256 header.s=dkim header.b=lqe81IbW; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-tegra+bounces-2721-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2yg72NCPz20XJ for ; Tue, 18 Jun 2024 04:13:23 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4AAF41F25417 for ; Mon, 17 Jun 2024 18:13:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1CAE199E96; Mon, 17 Jun 2024 18:13:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="lqe81IbW" X-Original-To: linux-tegra@vger.kernel.org Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB0101990C9; Mon, 17 Jun 2024 18:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718647998; cv=none; b=ECcy8S8daV2s0DKrMdNapTr4oRHh8o2xDHOl1sMZjioJOq8mgsS46EhIg9b2mIIb4cHvajFR6ZUMz+GZcmqpwXoCjOO9sRaLCZqD2vvE+kCqprd0o27Na58+wzEJ6AZ5X0HuLBTwGakBMFa4u759G4XtXRHN4iavni6EtbGqmBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718647998; c=relaxed/simple; bh=0EqbKRr78pKBR/LsZY0Hi8foVnymZgGel7l5EDAak44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WHtVjAAFOlURJtZeWMO4b7ZARq2XWekxcRVXzoVLfdF/Zg0v7PofvRiT1UIV0cHCAdPs3cpv/egkixMNqHAr2zg+fOLAAUZc3aYycUjfnQfR/kWKXUrVI4Ohx2FzAtTremhBNymcqLw0pM5wUGilKhi5d+a5z2VQzzmQbaNW74g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=lqe81IbW reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id d8ebfcda6e69060f; Mon, 17 Jun 2024 20:13:08 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 8F85B16606FD; Mon, 17 Jun 2024 20:13:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1718647988; bh=0EqbKRr78pKBR/LsZY0Hi8foVnymZgGel7l5EDAak44=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lqe81IbWjlzayrmgEhUnh7AE8CfedTq5oO6luYYBVS6QCCDt6lCN44PeOQZbBNxQp gehJefYOuxaLnOY4fXtmoFwcsOR0xz1/rmfqPCuCXZSRodSRnOoG3kWUCiSCnDLRPp tE40JE7lDMiPD4ZGuXXbXj3oZ+bzxG30Be/xxu5LSb+D0Ox0AISw75GzWmy4q/M8RA 6Mpfmtxl0vxS00KcBfhBh9MgFUCkBZBsDopgZFK8nQkY+MXtej2EHp9RaMFcssfX0C A8zwKI33hyfmQUNfqfzue7oC+oscbOMyggXhlcXpZPoZjZHY3bQYeiOl3VQ/C71Z/F 68LNfNjMsTebQ== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano , Thierry Reding , Jonathan Hunter , linux-tegra@vger.kernel.org Subject: [PATCH v1 10/14] thermal: tegra: Use thermal_zone_for_each_trip() for walking trip points Date: Mon, 17 Jun 2024 20:03:59 +0200 Message-ID: <13999070.RDIVbhacDa@kreacher> In-Reply-To: <8409966.T7Z3S40VBb@kreacher> References: <8409966.T7Z3S40VBb@kreacher> Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrfedvhedguddvvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgii tggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehthhhivghrrhihrdhrvgguihhnghesghhmrghilhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 From: Rafael J. Wysocki It is generally inefficient to iterate over trip indices and call thermal_zone_get_trip() every time to get the struct thermal_trip corresponding to the given trip index, so modify the Tegra thermal drivers to use thermal_zone_for_each_trip() for walking trips. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/tegra/soctherm.c | 38 ++++++++++++++++---------------- drivers/thermal/tegra/tegra30-tsensor.c | 25 ++++++++++----------- 2 files changed, 33 insertions(+), 30 deletions(-) Index: linux-pm/drivers/thermal/tegra/soctherm.c =================================================================== --- linux-pm.orig/drivers/thermal/tegra/soctherm.c +++ linux-pm/drivers/thermal/tegra/soctherm.c @@ -683,24 +683,25 @@ static const struct thermal_zone_device_ .set_trips = tegra_thermctl_set_trips, }; -static int get_hot_temp(struct thermal_zone_device *tz, int *trip_id, int *temp) +static int get_hot_trip_cb(struct thermal_trip *trip, void *arg) { - int i, ret; - struct thermal_trip trip; + const struct thermal_trip **trip_ret = arg; - for (i = 0; i < thermal_zone_get_num_trips(tz); i++) { + if (trip->type != THERMAL_TRIP_HOT) + return 0; - ret = thermal_zone_get_trip(tz, i, &trip); - if (ret) - return -EINVAL; - - if (trip.type == THERMAL_TRIP_HOT) { - *trip_id = i; - return 0; - } - } + *trip_ret = trip; + /* Return nonzero to terminate the search. */ + return 1; +} - return -EINVAL; +static const struct thermal_trip *get_hot_trip(struct thermal_zone_device *tz) +{ + const struct thermal_trip *trip = NULL; + + thermal_zone_for_each_trip(tz, get_hot_trip_cb, &trip); + + return trip; } /** @@ -732,8 +733,9 @@ static int tegra_soctherm_set_hwtrips(st struct thermal_zone_device *tz) { struct tegra_soctherm *ts = dev_get_drvdata(dev); + const struct thermal_trip *hot_trip; struct soctherm_throt_cfg *stc; - int i, trip, temperature, ret; + int i, temperature, ret; /* Get thermtrips. If missing, try to get critical trips. */ temperature = tsensor_group_thermtrip_get(ts, sg->id); @@ -750,8 +752,8 @@ static int tegra_soctherm_set_hwtrips(st dev_info(dev, "thermtrip: will shut down when %s reaches %d mC\n", sg->name, temperature); - ret = get_hot_temp(tz, &trip, &temperature); - if (ret) { + hot_trip = get_hot_trip(tz); + if (!hot_trip) { dev_info(dev, "throttrip: %s: missing hot temperature\n", sg->name); return 0; @@ -764,7 +766,7 @@ static int tegra_soctherm_set_hwtrips(st continue; cdev = ts->throt_cfgs[i].cdev; - if (get_thermal_instance(tz, cdev, trip)) + if (thermal_trip_is_bound_to_cdev(tz, hot_trip, cdev)) stc = find_throttle_cfg_by_name(ts, cdev->type); else continue; Index: linux-pm/drivers/thermal/tegra/tegra30-tsensor.c =================================================================== --- linux-pm.orig/drivers/thermal/tegra/tegra30-tsensor.c +++ linux-pm/drivers/thermal/tegra/tegra30-tsensor.c @@ -308,6 +308,18 @@ struct trip_temps { int crit_trip; }; +static int tegra_tsensor_get_trips_cb(struct thermal_trip *trip, void *arg) +{ + struct trip_temps *temps = arg; + + if (trip->type == THERMAL_TRIP_HOT) + temps->hot_trip = trip->temperature; + else if (trip->type == THERMAL_TRIP_CRITICAL) + temps->crit_trip = trip->temperature; + + return 0; +} + static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd, struct trip_temps *temps) { @@ -320,18 +332,7 @@ static void tegra_tsensor_get_hw_channel temps->hot_trip = 85000; temps->crit_trip = 90000; - for (i = 0; i < thermal_zone_get_num_trips(tzd); i++) { - - struct thermal_trip trip; - - thermal_zone_get_trip(tzd, i, &trip); - - if (trip.type == THERMAL_TRIP_HOT) - temps->hot_trip = trip.temperature; - - if (trip.type == THERMAL_TRIP_CRITICAL) - temps->crit_trip = trip.temperature; - } + thermal_zone_for_each_trip(tzd, tegra_tsensor_get_trips_cb, temps); /* clamp hardware trips to the calibration limits */ temps->hot_trip = clamp(temps->hot_trip, 25000, 90000);