From nobody Wed Sep 10 01:59:43 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 EDEA92DF712; Fri, 5 Sep 2025 10:24:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757067895; cv=pass; b=uXIAoLdvtnm5Qja9tWIOMY1WE3PCnsYIQs1Ni5I+8tAVn4igbRwSAMczEZygn35COvOqu55CfG41LMMcwRy0wTT2WLDviWcYu+fIG65EIuQWkggf/XyIeELkiW1ayCISRB2gqbldTxUXePMQ0ynLrADSD6VX3nvJov78KfJp68I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757067895; c=relaxed/simple; bh=Fq1f6lzd+1IG9LLJlRe8vPIe5S775FvALUuZ0HhKmKY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KlKOOTK2PGU/Um0/PG4tvMDhDr0q7rR+kLK58ZxhyW5k4ncDMWIuOM+r7kvjRp1ZCk3+eG5L/CMruLbOR2ZU6+5Uv21VxCXpm6V0MYBekMXfxt7eFV5J4b9CpBXFgnGnmjVH2nWfpGS9snBf08OEtZvlFrfi4QXUig+kFdXNKVA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=clVEnI9j; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="clVEnI9j" ARC-Seal: i=1; a=rsa-sha256; t=1757067868; cv=none; d=zohomail.com; s=zohoarc; b=L4EPZidN+OdnJX59KwXFztNlAoo2Zv6EB9UwfwXFrIP7QWQ2NVx7hZ5dALXX4axIEelf+J4bNFVjG2cnW8EwEGtV5hf+GuF9ME3TguNeiHXsY8ONeRGcnzHDshfVg4Qxe7eS5/wwbHuqs3iHPtfh0qQ80yWWTYFuFJVYfv5ZSOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757067868; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=BgcAwBs9k0Tva6LWKXeX4UCp/51+JkoYADUR446m4EA=; b=eyBSv5Tg5Mdnl7+mhbBZaG8N+3yQ36IxdWWwZRF/kWXg6F+PzCLmiLhE9FiO0rF2h5GF/L5Y06Wqp5vxnmP646ha44FhUjTln02YWJrnnkvwbmM+Ip8ZocD64FD135r8+Kh0Gl0sZtospkLFbcBNYcu05QUlhMyqsHpKa2OwVK4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1757067868; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=BgcAwBs9k0Tva6LWKXeX4UCp/51+JkoYADUR446m4EA=; b=clVEnI9jKVRfUoVuADf20X59xEZcoOU9i0kBY2vC0PhuzrTiKkH08qLOhhMMihac PAhk0O/X9oP4FGNQ3MsC+D2nvLuulV7RDbj57V2Vs5uUAhsO8rKlphGSXjCHRgdPX/2 treq9HdTYn+jztxCatpObAkfPyQiSYDfvmFJSpwc= Received: by mx.zohomail.com with SMTPS id 1757067868062527.7136886020036; Fri, 5 Sep 2025 03:24:28 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 05 Sep 2025 12:23:05 +0200 Subject: [PATCH RFC 09/10] drm/panthor: devfreq: add pluggable devfreq providers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250905-mt8196-gpufreq-v1-9-7b6c2d6be221@collabora.com> References: <20250905-mt8196-gpufreq-v1-0-7b6c2d6be221@collabora.com> In-Reply-To: <20250905-mt8196-gpufreq-v1-0-7b6c2d6be221@collabora.com> To: AngeloGioacchino Del Regno , Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Jassi Brar , Kees Cook , "Gustavo A. R. Silva" Cc: Chia-I Wu , Chen-Yu Tsai , kernel@collabora.com, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org, linux-hardening@vger.kernel.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 On some devices, devfreq is not controlled directly by DT OPPs and the common clock framework, but through an external devfreq driver. To permit this type of usage, add the concept of devfreq providers. Devfreq providers for panthor register themselves with panthor as a provider. panthor then gets whatever driver is suckling on its performance-node property, finds the registered devfreq provider init function for it, and calls it. Should the probe order work out such that panthor probes before the devfreq provider is finished probing and registering itself, then we just defer the probe after adding a device link. Signed-off-by: Nicolas Frattaroli --- drivers/gpu/drm/panthor/panthor_devfreq.c | 74 +++++++++++++++++++++++++++= +++- drivers/gpu/drm/panthor/panthor_devfreq.h | 16 +++++++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.c b/drivers/gpu/drm/pa= nthor/panthor_devfreq.c index d495dd856299826c4bddc205087d8914d01d7fc4..1b0c21f6f069b059b8b0e412a79= 556c602c5f1e7 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.c +++ b/drivers/gpu/drm/panthor/panthor_devfreq.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include =20 @@ -12,6 +13,34 @@ #include "panthor_devfreq.h" #include "panthor_device.h" =20 +static LIST_HEAD(panthor_devfreq_providers); +static DEFINE_MUTEX(panthor_devfreq_providers_lock); + +int panthor_devfreq_register_provider(struct panthor_devfreq_provider *pro= v) +{ + guard(mutex)(&panthor_devfreq_providers_lock); + + list_add(&prov->node, &panthor_devfreq_providers); + + return 0; +} +EXPORT_SYMBOL(panthor_devfreq_register_provider); + +static int panthor_devfreq_init_provider(struct panthor_device *ptdev, + struct device *provider_dev) +{ + struct panthor_devfreq_provider *prov; + + guard(mutex)(&panthor_devfreq_providers_lock); + + list_for_each_entry(prov, &panthor_devfreq_providers, node) { + if (prov->dev =3D=3D provider_dev) + return prov->init(ptdev, provider_dev); + } + + return -EPROBE_DEFER; +} + static void panthor_devfreq_update_utilization(struct panthor_devfreq *pde= vfreq) { ktime_t now, last; @@ -102,7 +131,7 @@ static struct devfreq_dev_profile panthor_devfreq_profi= le =3D { .get_cur_freq =3D panthor_devfreq_get_cur_freq, }; =20 -int panthor_devfreq_init(struct panthor_device *ptdev) +static int panthor_devfreq_init_of(struct panthor_device *ptdev) { /* There's actually 2 regulators (mali and sram), but the OPP core only * supports one. @@ -222,6 +251,49 @@ int panthor_devfreq_init(struct panthor_device *ptdev) return 0; } =20 +static int panthor_devfreq_init_platform(struct panthor_device *ptdev) +{ + struct device_node *pcnode; + struct platform_device *pdev; + struct device_link *link; + int ret; + + pcnode =3D of_parse_phandle(ptdev->base.dev->of_node, + "performance-controller", 0); + if (!pcnode) + return -EINVAL; + + pdev =3D of_find_device_by_node(pcnode); + of_node_put(pcnode); + if (!pdev) + return -ENODEV; + + link =3D device_link_add(ptdev->base.dev, &pdev->dev, + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); + if (!link) { + dev_err(ptdev->base.dev, "failed to add device link\n"); + return -ENODEV; + } + + ret =3D panthor_devfreq_init_provider(ptdev, &pdev->dev); + if (ret) + return dev_err_probe(ptdev->base.dev, ret, + "failed to initialize devfreq provider\n"); + + DRM_DEV_INFO(ptdev->base.dev, "initialized devfreq provider %s\n", + dev_name(&pdev->dev)); + + return 0; +} + +int panthor_devfreq_init(struct panthor_device *ptdev) +{ + if (!of_property_present(ptdev->base.dev->of_node, "performance-controlle= r")) + return panthor_devfreq_init_of(ptdev); + + return panthor_devfreq_init_platform(ptdev); +} + void panthor_devfreq_resume(struct panthor_device *ptdev) { struct panthor_devfreq *pdevfreq =3D ptdev->devfreq; diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.h b/drivers/gpu/drm/pa= nthor/panthor_devfreq.h index a891cb5fdc34636444f141e10f5d45828fc35b51..94c9768d5d038c4ba8516929edb= 565a1f13443fb 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.h +++ b/drivers/gpu/drm/panthor/panthor_devfreq.h @@ -8,6 +8,7 @@ =20 struct devfreq; struct thermal_cooling_device; +struct platform_device; =20 struct panthor_device; =20 @@ -43,6 +44,19 @@ struct panthor_devfreq { spinlock_t lock; }; =20 +struct panthor_devfreq_provider { + /** @dev: device pointer to the provider device */ + struct device *dev; + /** + * @init: the provider's init callback that allocates a + * &struct panthor_devfreq, adds it to panthor, and adds a devfreq + * device to panthor. Will be called during panthor's probe. + */ + int (*init)(struct panthor_device *ptdev, struct device *dev); + + struct list_head node; +}; + =20 int panthor_devfreq_init(struct panthor_device *ptdev); =20 @@ -57,4 +71,6 @@ int panthor_devfreq_get_dev_status(struct device *dev, =20 unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev); =20 +int panthor_devfreq_register_provider(struct panthor_devfreq_provider *pro= v); + #endif /* __PANTHOR_DEVFREQ_H__ */ --=20 2.51.0