From nobody Thu Oct 2 18:19:34 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 695F0322DA1; Fri, 12 Sep 2025 18:38:08 +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=1757702290; cv=pass; b=cIiFnMAQ5mNTkYiCD+9+3O7uVVtrNj7xoV7Vv+FPzu1SIiIp/v1FRpEZ4mH2eTL+YLfXHbHq12jBjxrUMLybhfpUq9jNp0XrtxJOXj6s5/rABdmqRM/cDXlCtyagTOWCAjO8B/FB40BU7ljAcnvTNywSEnIfQro9V1Aj65y5nBs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702290; c=relaxed/simple; bh=F453NAbKHQxKALRGtrMTD9hbrreE2rO6rqwharzVOo0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Dcv/5G0By1us4Qqpa+hKrueWc7GYMwqqxGjZD8AgKeAePgZpwghwxK+tfhHwWNAEZwg8uLPVfD5eqsOrrd9cO+SzEsrnctvGoHEuenrgpZWljPvp1XXqWL4pMl59ndtbONd6iBLEgPMn25eOwgZjVPjbL1rvuVia4/krYVoNSBM= 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=IuzaXCrb; 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="IuzaXCrb" ARC-Seal: i=1; a=rsa-sha256; t=1757702254; cv=none; d=zohomail.com; s=zohoarc; b=nMlPsYpy2O8sEcroQQZEZB2sKLF7HSiNy8bY58RoZ1PGORvnrM+Q4n+80vKG6cj2AtW6WMAyLT0yDU/mPwrSW1Fww0kbNL3bevFRdcBKcnS3WutXjspb0OROZ1qsQpgHvnOsgsHTRTkvQUxLNT5l7zu7QXD8o1bLAmSpJFEiONo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702254; 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=O8WVt9Ctmn2q0vEpVu4PvAu7OrnSPQKmq2jz3bFRmnY=; b=feGg57ILtO1r890uqwsMAFPu7FWpIIBgqs2qrm7uRNzvdkjDuN3g2102FETPss5Zz1vZ4b3IsY8GBJKUOrXGl398hsaAnmsm5+rkW4GH2leQwV+Usidh3/IJ1+tMWoR6BzK0+OsKwFlhy3dImyADMDFWSTxGfSD5XvTTvMKmhEo= 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=1757702254; 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=O8WVt9Ctmn2q0vEpVu4PvAu7OrnSPQKmq2jz3bFRmnY=; b=IuzaXCrbeixNucRXQlr1GWvGgkjWhmvEIGSFxjrTvwfbEde7Yrg8lpjswtQ5ifuM kf2gYL/EIjY6rkh5WLbij9F1pctgZvCwYqowX1q23sKAGwv3nJTGdAH9XkPJHdFat90 QEEy0Ekcjfe9MHOKdrZFpeJjRpt51CW0Tgrll0dk= Received: by mx.zohomail.com with SMTPS id 1757702252894215.80562166132404; Fri, 12 Sep 2025 11:37:32 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:00 +0200 Subject: [PATCH v2 01/10] dt-bindings: gpu: mali-valhall-csf: add mediatek,mt8196-mali variant 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: <20250912-mt8196-gpufreq-v2-1-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 The Mali-based GPU on the MediaTek MT8196 SoC uses a separate MCU to control the power and frequency of the GPU. It lets us omit the OPP tables from the device tree, as those can now be enumerated at runtime from the MCU. Add the mediatek,mt8196-mali compatible, and a performance-domains property which points to the MCU's device tree node in this case. It's required on mt8196 devices. Signed-off-by: Nicolas Frattaroli --- .../bindings/gpu/arm,mali-valhall-csf.yaml | 32 ++++++++++++++++++= +++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/gpu/arm,mali-valhall-csf.yam= l b/Documentation/devicetree/bindings/gpu/arm,mali-valhall-csf.yaml index a5b4e00217587c5d1f889094e2fff7b76e6148eb..163b4457f7f25dcdd509c558558= a73694521c96d 100644 --- a/Documentation/devicetree/bindings/gpu/arm,mali-valhall-csf.yaml +++ b/Documentation/devicetree/bindings/gpu/arm,mali-valhall-csf.yaml @@ -19,6 +19,7 @@ properties: - items: - enum: - rockchip,rk3588-mali + - mediatek,mt8196-mali - const: arm,mali-valhall-csf # Mali Valhall GPU model/revisio= n is fully discoverable =20 reg: @@ -53,6 +54,9 @@ properties: opp-table: type: object =20 + performance-domains: + maxItems: 1 + power-domains: minItems: 1 maxItems: 5 @@ -91,7 +95,6 @@ required: - interrupts - interrupt-names - clocks - - mali-supply =20 additionalProperties: false =20 @@ -105,9 +108,24 @@ allOf: properties: clocks: minItems: 3 + performance-domains: false power-domains: maxItems: 1 power-domain-names: false + required: + - mali-supply + - if: + properties: + compatible: + contains: + const: mediatek,mt8196-mali + then: + properties: + mali-supply: false + sram-supply: false + operating-points-v2: false + required: + - performance-domains =20 examples: - | @@ -143,5 +161,17 @@ examples: }; }; }; + - | + gpu@48000000 { + compatible =3D "mediatek,mt8196-mali", "arm,mali-valhall-csf"; + reg =3D <0x48000000 0x480000>; + clocks =3D <&mfgpll 0>; + clock-names =3D "core"; + interrupts =3D , + , + ; + interrupt-names =3D "job", "mmu", "gpu"; + performance-domains =3D <&gpufreq>; + }; =20 ... --=20 2.51.0 From nobody Thu Oct 2 18:19:34 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 0924432F768; Fri, 12 Sep 2025 18:38:13 +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=1757702295; cv=pass; b=I7sjq5jEBORM3hr7KpQLQzP3uJUueeJ0ZdtBnlUlVgj8Rj9njTI+LlYKH8Qp7gjnrcBWvChPZQxhGnzgOT3h98ACA98+Rlvxx2AlYrWXteePxLsEFJ9pF6BoCpFC3U83duLrAYoigtdrMMVucyWIG/83D0TpC/YbFTUHxiM5Q94= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702295; c=relaxed/simple; bh=xpX6nc0zR9r9FFaiUroEPgMJYTBdN/zREbiJIaG5aQo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QyN3hnHDKqn5jGepYouIsVh1FjxaDFSspib/MgzGK2lA4Wj1a30iuRdWkyj2Sz9qUWVZ4vcM14QAz3gw9c4LO0p/KSOIF2nqoMmbCyUakfKcyFfZQeWN4c2SCOdUvwyEOaYbmnZY7o8cmpaA+P13q1GNF2eit5NNYpgu7R6x0G8= 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=PFDyDR20; 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="PFDyDR20" ARC-Seal: i=1; a=rsa-sha256; t=1757702262; cv=none; d=zohomail.com; s=zohoarc; b=byJeH/qvrKSq0hRdY3YAxb4YuVStbP8Q8VjieV/qNRDppLSnEK62wmkr53+MnMm4UxAvZtcGVL7utDj44rhO3ZR9+Di5/tb7FKkxb2zjqo8Jj5wn1ojzQEVIvW97jmdJL4L2t9CDl7UYbFnJq98yWy9VEEjWxr/zmbIkOilQX1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702262; 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=RM1CPtpcM7iofFgJi6EoZwd3D3Y67w7Up4uLm6O8Je4=; b=khTz1fGFOTVAy89miF0ilU82wfp3RnCPCikZlA+QkbOukt/skJOOXsObFcpolr1Nnlmj7pS7PZe0MGoHnbnmB7HZUNrWqq8sjZfpm2iTAnehdNVJ2Vi/2pVl40+E1qVHdoWFy0ujnopjNLJD6WLzJRpb2bFLv6aaaE6SU8q3zJ4= 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=1757702262; 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=RM1CPtpcM7iofFgJi6EoZwd3D3Y67w7Up4uLm6O8Je4=; b=PFDyDR206u30J3avNJ3Hwa4+fmfWyq6mBbycW/ult5ii31XcdDrpgc1d5sLYAe5A ED0AJv7KMjsSXpoQ4NkWawG/A+LoMKdMbz2pHmrniKUy0aNtzywn50ZHAw4AgYCHFh6 1gR5r1dMQvBXNifWNlzscfG5lTrdFW5nlGjfjpj0= Received: by mx.zohomail.com with SMTPS id 1757702259914663.1005178250432; Fri, 12 Sep 2025 11:37:39 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:01 +0200 Subject: [PATCH v2 02/10] dt-bindings: devfreq: add mt8196-gpufreq binding 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: <20250912-mt8196-gpufreq-v2-2-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 the MediaTek MT8196 SoC, the GPU has its power and frequency dynamically controlled by an embedded special-purpose MCU. This MCU is in charge of powering up the GPU silicon. It also provides us with a list of available OPPs at runtime, and is fully in control of all the regulator and clock fiddling it takes to reach a certain level of performance. It's also in charge of enforcing limits on power draw or temperature. Add a binding for this device in the devfreq subdirectory, where it seems to fit in best considering its tasks. Signed-off-by: Nicolas Frattaroli --- .../bindings/devfreq/mediatek,mt8196-gpufreq.yaml | 113 +++++++++++++++++= ++++ 1 file changed, 113 insertions(+) diff --git a/Documentation/devicetree/bindings/devfreq/mediatek,mt8196-gpuf= req.yaml b/Documentation/devicetree/bindings/devfreq/mediatek,mt8196-gpufre= q.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9d9efd4e70f1ef7ae446c833c15= 144beb9641b16 --- /dev/null +++ b/Documentation/devicetree/bindings/devfreq/mediatek,mt8196-gpufreq.yaml @@ -0,0 +1,113 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/devfreq/mediatek,mt8196-gpufreq.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek MFlexGraphics Performance Controller + +maintainers: + - Nicolas Frattaroli + +description: | + A special-purpose embedded MCU to control power and frequency of GPU dev= ices + using MediaTek Flexible Graphics integration hardware. + +properties: + $nodename: + pattern: '^performance-controller@[a-f0-9]+$' + + compatible: + enum: + - mediatek,mt8196-gpufreq + + reg: + items: + - description: GPR memory area + - description: RPC memory area + - description: SoC variant ID register + + reg-names: + items: + - const: gpr + - const: rpc + - const: hw_revision + + clocks: + items: + - description: main clock of the embedded controller (EB) + - description: core PLL + - description: stack 0 PLL + - description: stack 1 PLL + + clock-names: + items: + - const: eb + - const: mfgpll + - const: mfgpll_sc0 + - const: mfgpll_sc1 + + mboxes: + items: + - description: FastDVFS events + - description: frequency control + - description: sleep control + - description: timer control + - description: frequency hopping control + - description: hardware voter control + - description: FastDVFS control + + mbox-names: + items: + - const: fast-dvfs-event + - const: gpufreq + - const: sleep + - const: timer + - const: fhctl + - const: ccf + - const: fast-dvfs + + shmem: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the shared memory region of the GPUEB MCU + + "#performance-domain-cells": + const: 0 + +required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - mboxes + - mbox-names + - shmem + - "#performance-domain-cells" + +additionalProperties: false + +examples: + - | + #include + + gpufreq: performance-controller@4b09fd00 { + compatible =3D "mediatek,mt8196-gpufreq"; + reg =3D <0x4b09fd00 0x80>, + <0x4b800000 0x1000>, + <0x4b860128 0x4>; + reg-names =3D "gpr", "rpc", "hw_revision"; + clocks =3D <&topckgen CLK_TOP_MFG_EB>, + <&mfgpll CLK_MFG_AO_MFGPLL>, + <&mfgpll_sc0 CLK_MFGSC0_AO_MFGPLL_SC0>, + <&mfgpll_sc1 CLK_MFGSC1_AO_MFGPLL_SC1>; + clock-names =3D "eb", "mfgpll", "mfgpll_sc0", + "mfgpll_sc1"; + mboxes =3D <&gpueb_mbox 0>, <&gpueb_mbox 1>, <&gpueb_mbox 2>, + <&gpueb_mbox 3>, <&gpueb_mbox 4>, <&gpueb_mbox 5>, + <&gpueb_mbox 7>; + mbox-names =3D "fast-dvfs-event", "gpufreq", "sleep", "timer", "fh= ctl", + "ccf", "fast-dvfs"; + shmem =3D <&gpufreq_shmem>; + #performance-domain-cells =3D <0>; + }; --=20 2.51.0 From nobody Thu Oct 2 18:19:34 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 8255E33471C; Fri, 12 Sep 2025 18:38:12 +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=1757702294; cv=pass; b=JQhtTIeN8r1a86IlCkxG9OGpGKyZaJxplnEdW7zorJnQ8Q5pjMDYcnSN5vyWhkgLw5GosV2tGH8kSVbvk6fyEFTGUhazUzSbEhzmVH0N+fR3dluxc4KDRKW0wGj2w25qEEVt27sSRx8aE8bCBhTAoyddJhI3C47qiAWMCHiCRYQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702294; c=relaxed/simple; bh=421VgOvXlFdib7pr2C3QvpqejdW2jnU9weK0/zlHcCo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fvGZY6Phmg/zeqSl+lP+S8LoEGUTTe0irfzqkB1SeyAdn7THNcbJ7fM+VvPy42ETJolf57W/7ZMTsl6dt1VVH+sQe/pKt97nMnRFoq9Kridc5haoUMju8lPiiE4YuqFu36YD9lop75aQDf85cV5CbyRb+Z6vKC4SYhxj8AYJnWM= 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=dRLmfSxX; 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="dRLmfSxX" ARC-Seal: i=1; a=rsa-sha256; t=1757702268; cv=none; d=zohomail.com; s=zohoarc; b=Jp3Yjg5LkIuQKesNw6/utyRuTv0nybYZ5coe0YBXK71r24f7rdxKMI682bA6vr3KvXX+dQThuadURLrH+aj8rCRnjgvSiQoRp6FWojTRpYsllyEj5AeK8XZtdlb0cBU1LUnNQH6uQlVv+K4wfnJoXnvVdFAb6/qRXHTys8hqQOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702268; 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=5o2cb+RS3e9vM6xcSLE475S0MGwfkgp0FUKoEaEDRlU=; b=BLDOvsVzVwwie42bi+SVmvubUZzQ7r4CGAALrVL8n59qjbN2tDUifPqEDmUDsdkV0Ey0u0tHpVLP75AGZXnsJdJyS/Ewc2jGN1k3gNr18OsUEN459NPetRMVCzl2QIgEAg5u5vyKonO34Z3JDFFc0jKv9j61lJcF0goaDXGXSEY= 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=1757702268; 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=5o2cb+RS3e9vM6xcSLE475S0MGwfkgp0FUKoEaEDRlU=; b=dRLmfSxXaRzFWG65htj2aEJIZWuCyvok2GtdATgyx7cMuVqUsXZA1++mspb72y9B gu2jp+Y3e98c6JtQliKmEnrHXojq7dDdFyNLZyX7ZBXAZztzCp5Y3vI4dJXitD6SLa8 4knxxAeunr03KcCpmsyLb5u0RWC1PZIysGXo1MmI= Received: by mx.zohomail.com with SMTPS id 1757702266927437.838415080814; Fri, 12 Sep 2025 11:37:46 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:02 +0200 Subject: [PATCH v2 03/10] dt-bindings: sram: Add compatible for mediatek,mt8196-gpufreq-sram 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: <20250912-mt8196-gpufreq-v2-3-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 This compatible is used for an SRAM section that's shared between the MT8196's application processor cores and the embedded GPUEB MCU that controls the GPU frequency. Through this SRAM section, things about the GPU frequency controller like the OPP table can be read. Acked-by: Rob Herring (Arm) Signed-off-by: Nicolas Frattaroli --- Documentation/devicetree/bindings/sram/sram.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/sram/sram.yaml b/Documentati= on/devicetree/bindings/sram/sram.yaml index 7c1337e159f2371401ae99313375656fff014ed4..6ba0dd6a66def11f56a1d5276d7= 397b655bff11e 100644 --- a/Documentation/devicetree/bindings/sram/sram.yaml +++ b/Documentation/devicetree/bindings/sram/sram.yaml @@ -89,6 +89,7 @@ patternProperties: - arm,juno-scp-shmem - arm,scmi-shmem - arm,scp-shmem + - mediatek,mt8196-gpufreq-sram - renesas,smp-sram - rockchip,rk3066-smp-sram - samsung,exynos4210-sysram --=20 2.51.0 From nobody Thu Oct 2 18:19:34 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 F1D2733A004; Fri, 12 Sep 2025 18:38:17 +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=1757702299; cv=pass; b=Kvaz2eyjlcvpgULqCmShoLFwfTZsGdS4WdKcbARMYW1CdZtb/am9p7TIlSXttbkLI2eEPwaAtWurpPe4sNbgw+xaF9Xb+DZNNbR5Ga49gNd9bA/A7m6eJeVcLRPlCvQ+PlSr9FBsPmEeBswLjAblPVi6k1erqoWGOvP8DgwMkuQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702299; c=relaxed/simple; bh=drrwRIWbT/6jTbyDuHbWwnUu/ItZ1Sdr3GaC8JKkbaM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tPxxUcnN1P0/wUiejhrTrmjVt0AijpfXfovyRCM531d0Iwt9HRLyr6bmZOn+hXDo7ojROcUxJSIz3/FihT1dsvGJ6wMLG+xSIAkwOqMBpDTCowgLKz3PhC0J5i+4m5UYFukeGQzo6Pq83MBUjWJopuw5sSk4VnQKGkjrVSi984k= 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=UmNxMtxo; 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="UmNxMtxo" ARC-Seal: i=1; a=rsa-sha256; t=1757702274; cv=none; d=zohomail.com; s=zohoarc; b=G5NKDoUWA7fUF6oU8rPcNYu1AON7niiwV0XRbLDfvWv39oQmjol/MEgnDxzCbLF3rLpjubQ0wdGFouwFIKxbnzxpBEo/yAYFJCPYoiwdMIBIQa7+7POL2gCNxqdBS/X+0BdZXSh4E804/8eIoQamDJumfRxcSWJdPO5y6VmM488= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702274; 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=SYOU/8VrDAp+vsF12aSnGJc7uo89fJ6a5IP9fscM8+4=; b=Mhn2Iz3Pwacrnc73OySUCJ3IcbZV/iwS6tcIkrVH3XXhToBnbPcm0VBKhArr2rqeVXXiyvGbalfAkiYlncqjhJRQyQ8oyVJae1JmJBGc1Xp9E1/aQtgW/gJPaQJKh7ATmN5VWesf3cGrpeJHGvz2cuwqcvPI8Zhcv5sJSzj3hM4= 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=1757702274; 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=SYOU/8VrDAp+vsF12aSnGJc7uo89fJ6a5IP9fscM8+4=; b=UmNxMtxocGD6PV00JP1QPGSyhPJ08T0XNONQcW7XeB9I/zcWsuP6q+ZQTPyGjuSj R9Bz0dCHNHYisE4k/Zm+8DCnakmDvUjuB9HIDX9McEhDPtcFuUtzFJLYG5ALvWKZlZz y1qTNZPe9gcyCVB7dfk4Ffa6XcuPF5XLLV6AO8Bc= Received: by mx.zohomail.com with SMTPS id 1757702273859380.4056309139387; Fri, 12 Sep 2025 11:37:53 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:03 +0200 Subject: [PATCH v2 04/10] dt-bindings: mailbox: Add MT8196 GPUEB Mailbox 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: <20250912-mt8196-gpufreq-v2-4-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 The MediaTek MT8196 SoC includes an embedded MCU referred to as "GPUEB", acting as glue logic to control power and frequency of the Mali GPU. This MCU runs special-purpose firmware for this use, and the main application processor communicates with it through a mailbox. Add a binding that describes this mailbox. Signed-off-by: Nicolas Frattaroli Acked-by: Conor Dooley --- .../mailbox/mediatek,mt8196-gpueb-mbox.yaml | 64 ++++++++++++++++++= ++++ 1 file changed, 64 insertions(+) diff --git a/Documentation/devicetree/bindings/mailbox/mediatek,mt8196-gpue= b-mbox.yaml b/Documentation/devicetree/bindings/mailbox/mediatek,mt8196-gpu= eb-mbox.yaml new file mode 100644 index 0000000000000000000000000000000000000000..56508f406fce88c7c1699aa67b5= 7394fc7b1c357 --- /dev/null +++ b/Documentation/devicetree/bindings/mailbox/mediatek,mt8196-gpueb-mbox.= yaml @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mailbox/mediatek,mt8196-gpueb-mbox.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek MFlexGraphics GPUEB Mailbox Controller + +maintainers: + - Nicolas Frattaroli + +properties: + compatible: + enum: + - mediatek,mt8196-gpueb-mbox + + reg: + items: + - description: mailbox data registers + - description: mailbox control registers + + reg-names: + items: + - const: data + - const: ctl + + clocks: + items: + - description: main clock of the GPUEB MCU + + interrupts: + items: + - description: fires when a new message is received + + "#mbox-cells": + const: 1 + description: + The number of the mailbox channel. + +required: + - compatible + - reg + - reg-names + - clocks + - interrupts + - "#mbox-cells" + +additionalProperties: false + +examples: + - | + #include + #include + #include + + gpueb_mbox: mailbox@4b09fd80 { + compatible =3D "mediatek,mt8196-gpueb-mbox"; + reg =3D <0x4b09fd80 0x280>, + <0x4b170000 0x7c>; + reg-names =3D "data", "ctl"; + clocks =3D <&topckgen CLK_TOP_MFG_EB>; + interrupts =3D ; + #mbox-cells =3D <1>; + }; --=20 2.51.0 From nobody Thu Oct 2 18:19:34 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 001ED32ED43; Fri, 12 Sep 2025 18:38:40 +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=1757702323; cv=pass; b=YAtbYwNS72T/7Mx6OJDmIwhegAb3ypLYeO/Q8vDF3V5iOn1D9k/39yyZG6nK+v8Xe7Fk1/a5BcZfV3McDyq71r/+wIdgOraOicCEfTd1ITYGY5/o1yJ3hTMM+EvibnzZs809Hl8WJkBuZQITcF5aPHVxcim3HslJnZRQAqxRVK4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702323; c=relaxed/simple; bh=igGTGp728VczWM6DDdn3B+hSXNy1+Zd2bHNcoYFZYZw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=appPIJOTWvDlxJYbByArPog8XbZceHj1vzbr/IXMr5B4RxAlN8i+FJvA0Z1vMm5qh3+/5PmvMI8xzFBNSsH3gOx9RQVnwhUbO/k5FXMfidl3HMa9jfoqLTMBBMZ4Uzp8aW01ZLxcqd4RJRHkPp9ZT4aJkhxDdqU3jXhnDctn8o4= 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=DHnEXedC; 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="DHnEXedC" ARC-Seal: i=1; a=rsa-sha256; t=1757702282; cv=none; d=zohomail.com; s=zohoarc; b=CTK4IlOZfrx5lkLZiPBtQfD/IFk3xvh5kq1hq8wW9Kb3MXa0tHf/pmZS4VyH7jmHh6k1bjeWy2tCFOtJu0GT4ocGjWV4JNHDdFKWkAo4Q6cpVoAc4ICoY5MDsrdP7O7841ydEskNyfTneNR+/6FqUyXEppWfCgiDv2LcWAH15sM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702282; 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=KRoz3AX/4l3gWWUh8JeDx86LKRzfv5ckDkbWkGw7YwU=; b=jKzTLZx6BcwMTwZEzslRlF1vqYnaWia+RsNvd+8y0LwYlelgt11n0caEubruPzJE/bFGo6+l6r7vnrQASotkJsDwmlbu8XVX/YaBnBdalpJMdYYNTjKgIhKC1gWfHBUXY/PuIJj2TVBMEaHIs1r3yDtf8aefrqRi5hoj6Q+iu5g= 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=1757702282; 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=KRoz3AX/4l3gWWUh8JeDx86LKRzfv5ckDkbWkGw7YwU=; b=DHnEXedCTtfVglePlmUcurWs0h/SY6P/r2VTOsAdP7YpuhEJW6GlUdnoZbRp4JMj qmwFZ6FdCyEd770OBpz7qgZieawR5lDp6W5nRFVb8Ru0EUIzA+0bJAhwQH0bHyG/t5F peZWZ9ak5CH6FKAiFyezny/OSFhzRav1lYlU5Gps= Received: by mx.zohomail.com with SMTPS id 1757702281064219.21425668198083; Fri, 12 Sep 2025 11:38:01 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:04 +0200 Subject: [PATCH v2 05/10] mailbox: add MediaTek GPUEB IPI mailbox 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: <20250912-mt8196-gpufreq-v2-5-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 The MT8196 SoC uses an embedded MCU to control frequencies and power of the GPU. This controller is referred to as "GPUEB". It communicates to the application processor, among other ways, through a mailbox. The mailbox exposes one interrupt, which appears to only be fired when a response is received, rather than a transaction is completed. For us, this means we unfortunately need to poll for txdone. The mailbox also requires the EB clock to be on when touching any of the mailbox registers. Add a simple driver for it based on the common mailbox framework. Signed-off-by: Nicolas Frattaroli --- drivers/mailbox/Kconfig | 10 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/mtk-gpueb-mailbox.c | 337 ++++++++++++++++++++++++++++++++= ++++ 3 files changed, 349 insertions(+) diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 02432d4a5ccd46a16156a09c7f277fb03e4013f5..2016defda1fabb5c0fcc8078f84= a52d4e4e00167 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -294,6 +294,16 @@ config MTK_CMDQ_MBOX critical time limitation, such as updating display configuration during the vblank. =20 +config MTK_GPUEB_MBOX + tristate "MediaTek GPUEB Mailbox Support" + depends on ARCH_MEDIATEK || COMPILE_TEST + help + The MediaTek GPUEB mailbox is used to communicate with the embedded + controller in charge of GPU frequency and power management on some + MediaTek SoCs, such as the MT8196. + Say Y or m here if you want to support the MT8196 SoC in your kernel + build. + config ZYNQMP_IPI_MBOX tristate "Xilinx ZynqMP IPI Mailbox" depends on ARCH_ZYNQMP && OF diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index 98a68f838486eed117d24296138bf59fda3f92e4..564d06e71313e6d1972e4a6036e= 1e78c8c7ec450 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -63,6 +63,8 @@ obj-$(CONFIG_MTK_ADSP_MBOX) +=3D mtk-adsp-mailbox.o =20 obj-$(CONFIG_MTK_CMDQ_MBOX) +=3D mtk-cmdq-mailbox.o =20 +obj-$(CONFIG_MTK_GPUEB_MBOX) +=3D mtk-gpueb-mailbox.o + obj-$(CONFIG_ZYNQMP_IPI_MBOX) +=3D zynqmp-ipi-mailbox.o =20 obj-$(CONFIG_SUN6I_MSGBOX) +=3D sun6i-msgbox.o diff --git a/drivers/mailbox/mtk-gpueb-mailbox.c b/drivers/mailbox/mtk-gpue= b-mailbox.c new file mode 100644 index 0000000000000000000000000000000000000000..ac7530c6e71b3a3b39f956d6976= c02eabdd4bb71 --- /dev/null +++ b/drivers/mailbox/mtk-gpueb-mailbox.c @@ -0,0 +1,337 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * MediaTek GPUEB mailbox driver for SoCs such as the MT8196 + * + * Copyright (C) 2025, Collabora Ltd. + * + * Developers harmed in the making of this driver: + * - Nicolas Frattaroli + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MBOX_CTL_TX_STS 0x0000 +#define MBOX_CTL_IRQ_SET 0x0004 +#define MBOX_CTL_IRQ_CLR 0x0074 +#define MBOX_CTL_RX_STS 0x0078 + +#define MBOX_FULL BIT(0) /* i.e. we've received data */ +#define MBOX_CLOGGED BIT(1) /* i.e. the channel is shutdown */ + +struct mtk_gpueb_mbox { + struct device *dev; + struct clk *clk; + void __iomem *mbox_mmio; + void __iomem *mbox_ctl; + struct mbox_controller mbox; + struct mtk_gpueb_mbox_chan *ch; + int irq; + const struct mtk_gpueb_mbox_variant *v; +}; + +/** + * struct mtk_gpueb_mbox_chan - per-channel runtime data + * @ebm: pointer to the parent &struct mtk_gpueb_mbox mailbox + * @full_name: descriptive name of channel for IRQ subsystem + * @num: channel number, starting at 0 + * @rx_buf: pointer to memory where received data is copied from MMIO + * @rx_status: signifies whether channel reception is turned off, or full + * @c: pointer to the constant &struct mtk_gpueb_mbox_chan_desc channel da= ta + */ +struct mtk_gpueb_mbox_chan { + struct mtk_gpueb_mbox *ebm; + char *full_name; + u8 num; + void *rx_buf; + atomic_t rx_status; + const struct mtk_gpueb_mbox_chan_desc *c; +}; + +/** + * struct mtk_gpueb_mbox_chan_desc - per-channel constant data + * @name: name of this channel + * @num: index of this channel, starting at 0 + * @tx_offset: byte offset measured from mmio base for outgoing data + * @tx_len: size, in bytes, of the outgoing data on this channel + * @rx_offset: bytes offset measured from mmio base for incoming data + * @rx_len: size, in bytes, of the incoming data on this channel + */ +struct mtk_gpueb_mbox_chan_desc { + const char *name; + const u8 num; + const u16 tx_offset; + const u8 tx_len; + const u16 rx_offset; + const u8 rx_len; +}; + +struct mtk_gpueb_mbox_variant { + const u8 num_channels; + const struct mtk_gpueb_mbox_chan_desc channels[] __counted_by(num_channel= s); +}; + +/** + * mtk_gpueb_mbox_read_rx - read RX buffer from MMIO into channel's RX buf= fer + * @chan: pointer to the channel to read + */ +static void mtk_gpueb_mbox_read_rx(struct mtk_gpueb_mbox_chan *chan) +{ + memcpy_fromio(chan->rx_buf, chan->ebm->mbox_mmio + chan->c->rx_offset, + chan->c->rx_len); +} + +static irqreturn_t mtk_gpueb_mbox_isr(int irq, void *data) +{ + struct mtk_gpueb_mbox_chan *ch =3D data; + u32 rx_sts; + + rx_sts =3D readl(ch->ebm->mbox_ctl + MBOX_CTL_RX_STS); + + if (rx_sts & BIT(ch->num)) { + if (!atomic_cmpxchg(&ch->rx_status, 0, MBOX_FULL | MBOX_CLOGGED)) + return IRQ_WAKE_THREAD; + } + + return IRQ_NONE; +} + +static irqreturn_t mtk_gpueb_mbox_thread(int irq, void *data) +{ + struct mtk_gpueb_mbox_chan *ch =3D data; + int status; + + status =3D atomic_cmpxchg(&ch->rx_status, + MBOX_FULL | MBOX_CLOGGED, MBOX_FULL); + if (status =3D=3D (MBOX_FULL | MBOX_CLOGGED)) { + mtk_gpueb_mbox_read_rx(ch); + writel(BIT(ch->num), ch->ebm->mbox_ctl + MBOX_CTL_IRQ_CLR); + mbox_chan_received_data(&ch->ebm->mbox.chans[ch->num], + ch->rx_buf); + atomic_set(&ch->rx_status, 0); + return IRQ_HANDLED; + } + + return IRQ_NONE; +} + +static int mtk_gpueb_mbox_send_data(struct mbox_chan *chan, void *data) +{ + struct mtk_gpueb_mbox_chan *ch =3D chan->con_priv; + int i; + u32 *values =3D data; + + if (atomic_read(&ch->rx_status)) + return -EBUSY; + + /* + * We don't want any fancy nonsense, just write the 32-bit values in + * order. memcpy_toio/__iowrite32_copy don't work here, because fancy. + */ + for (i =3D 0; i < ch->c->tx_len; i +=3D 4) + writel(values[i / 4], ch->ebm->mbox_mmio + ch->c->tx_offset + i); + + writel(BIT(ch->num), ch->ebm->mbox_ctl + MBOX_CTL_IRQ_SET); + + return 0; +} + +static int mtk_gpueb_mbox_startup(struct mbox_chan *chan) +{ + struct mtk_gpueb_mbox_chan *ch =3D chan->con_priv; + int ret; + + atomic_set(&ch->rx_status, 0); + + ret =3D clk_enable(ch->ebm->clk); + if (ret) { + dev_err(ch->ebm->dev, "Failed to enable EB clock: %pe\n", + ERR_PTR(ret)); + goto err_clog; + } + + writel(BIT(ch->num), ch->ebm->mbox_ctl + MBOX_CTL_IRQ_CLR); + + ret =3D devm_request_threaded_irq(ch->ebm->dev, ch->ebm->irq, mtk_gpueb_m= box_isr, + mtk_gpueb_mbox_thread, IRQF_SHARED | IRQF_ONESHOT, + ch->full_name, ch); + if (ret) { + dev_err(ch->ebm->dev, "Failed to request IRQ: %pe\n", + ERR_PTR(ret)); + goto err_unclk; + } + + return 0; + +err_unclk: + clk_disable(ch->ebm->clk); +err_clog: + atomic_set(&ch->rx_status, MBOX_CLOGGED); + + return ret; +} + +static void mtk_gpueb_mbox_shutdown(struct mbox_chan *chan) +{ + struct mtk_gpueb_mbox_chan *ch =3D chan->con_priv; + + atomic_set(&ch->rx_status, MBOX_CLOGGED); + + devm_free_irq(ch->ebm->dev, ch->ebm->irq, ch); + + clk_disable(ch->ebm->clk); +} + +static bool mtk_gpueb_mbox_last_tx_done(struct mbox_chan *chan) +{ + struct mtk_gpueb_mbox_chan *ch =3D chan->con_priv; + + return !(readl(ch->ebm->mbox_ctl + MBOX_CTL_TX_STS) & BIT(ch->num)); +} + +const struct mbox_chan_ops mtk_gpueb_mbox_ops =3D { + .send_data =3D mtk_gpueb_mbox_send_data, + .startup =3D mtk_gpueb_mbox_startup, + .shutdown =3D mtk_gpueb_mbox_shutdown, + .last_tx_done =3D mtk_gpueb_mbox_last_tx_done, +}; + +static struct mbox_chan * +mtk_gpueb_mbox_of_xlate(struct mbox_controller *mbox, + const struct of_phandle_args *sp) +{ + struct mtk_gpueb_mbox *ebm =3D dev_get_drvdata(mbox->dev); + + if (!sp->args_count) + return ERR_PTR(-EINVAL); + + if (sp->args[0] >=3D ebm->v->num_channels) + return ERR_PTR(-ECHRNG); + + return &mbox->chans[sp->args[0]]; +} + +static int mtk_gpueb_mbox_probe(struct platform_device *pdev) +{ + struct mtk_gpueb_mbox *ebm; + unsigned int rx_buf_sz; + void *buf; + unsigned int i; + + ebm =3D devm_kzalloc(&pdev->dev, sizeof(*ebm), GFP_KERNEL); + if (!ebm) + return -ENOMEM; + + ebm->dev =3D &pdev->dev; + ebm->v =3D of_device_get_match_data(ebm->dev); + + ebm->irq =3D platform_get_irq(pdev, 0); + if (ebm->irq < 0) + return ebm->irq; + + ebm->clk =3D devm_clk_get_prepared(ebm->dev, NULL); + if (IS_ERR(ebm->clk)) + return dev_err_probe(ebm->dev, PTR_ERR(ebm->clk), + "Failed to get 'eb' clock\n"); + + ebm->mbox_mmio =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(ebm->mbox_mmio)) + return dev_err_probe(ebm->dev, PTR_ERR(ebm->mbox_mmio), + "Couldn't map mailbox data registers\n"); + + ebm->mbox_ctl =3D devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(ebm->mbox_ctl)) + return dev_err_probe( + ebm->dev, PTR_ERR(ebm->mbox_ctl), + "Couldn't map mailbox control registers\n"); + + rx_buf_sz =3D (ebm->v->channels[ebm->v->num_channels - 1].rx_offset + + ebm->v->channels[ebm->v->num_channels - 1].rx_len - + ebm->v->channels[0].rx_offset); + + buf =3D devm_kzalloc(ebm->dev, rx_buf_sz, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ebm->ch =3D devm_kmalloc_array(ebm->dev, ebm->v->num_channels, + sizeof(*ebm->ch), GFP_KERNEL); + if (!ebm->ch) + return -ENOMEM; + + ebm->mbox.chans =3D devm_kcalloc(ebm->dev, ebm->v->num_channels, + sizeof(struct mbox_chan), GFP_KERNEL); + if (!ebm->mbox.chans) + return -ENOMEM; + + for (i =3D 0; i < ebm->v->num_channels; i++) { + ebm->ch[i].c =3D &ebm->v->channels[i]; + ebm->ch[i].full_name =3D devm_kasprintf(ebm->dev, GFP_KERNEL, "%s:%s", + dev_name(ebm->dev), ebm->ch[i].c->name); + if (!ebm->ch[i].full_name) + return -ENOMEM; + + ebm->ch[i].ebm =3D ebm; + ebm->ch[i].num =3D i; + ebm->ch[i].rx_buf =3D buf + ebm->ch[i].c->rx_offset - + ebm->v->channels[0].rx_offset; + spin_lock_init(&ebm->mbox.chans[i].lock); + ebm->mbox.chans[i].con_priv =3D &ebm->ch[i]; + atomic_set(&ebm->ch[i].rx_status, MBOX_CLOGGED); + } + + ebm->mbox.dev =3D ebm->dev; + ebm->mbox.num_chans =3D ebm->v->num_channels; + ebm->mbox.txdone_poll =3D true; + ebm->mbox.txpoll_period =3D 0; /* minimum hrtimer interval */ + ebm->mbox.of_xlate =3D mtk_gpueb_mbox_of_xlate; + ebm->mbox.ops =3D &mtk_gpueb_mbox_ops; + + dev_set_drvdata(ebm->dev, ebm); + + return devm_mbox_controller_register(ebm->dev, &ebm->mbox); +} + +static const struct mtk_gpueb_mbox_variant mtk_gpueb_mbox_mt8196 =3D { + .num_channels =3D 12, + .channels =3D { + { "fast-dvfs-event", 0, 0x0000, 16, 0x00e0, 16 }, + { "gpufreq", 1, 0x0010, 32, 0x00f0, 32 }, + { "sleep", 2, 0x0030, 12, 0x0110, 4 }, + { "timer", 3, 0x003c, 24, 0x0114, 4 }, + { "fhctl", 4, 0x0054, 36, 0x0118, 4 }, + { "ccf", 5, 0x0078, 16, 0x011c, 16 }, + { "gpumpu", 6, 0x0088, 24, 0x012c, 4 }, + { "fast-dvfs", 7, 0x00a0, 24, 0x0130, 24 }, + { "ipir-c-met", 8, 0x00b8, 4, 0x0148, 16 }, + { "ipis-c-met", 9, 0x00bc, 16, 0x0158, 4 }, + { "brisket", 10, 0x00cc, 16, 0x015c, 16 }, + { "ppb", 11, 0x00dc, 4, 0x016c, 4 }, + }, +}; + +static const struct of_device_id mtk_gpueb_mbox_of_ids[] =3D { + { .compatible =3D "mediatek,mt8196-gpueb-mbox", .data =3D &mtk_gpueb_mbox= _mt8196 }, + { /* Sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mtk_gpueb_mbox_of_ids); + +static struct platform_driver mtk_gpueb_mbox_drv =3D { + .probe =3D mtk_gpueb_mbox_probe, + .driver =3D { + .name =3D "mtk-gpueb-mbox", + .of_match_table =3D mtk_gpueb_mbox_of_ids, + } +}; +module_platform_driver(mtk_gpueb_mbox_drv); + +MODULE_AUTHOR("Nicolas Frattaroli "); +MODULE_DESCRIPTION("MediaTek GPUEB mailbox driver"); +MODULE_LICENSE("GPL"); --=20 2.51.0 From nobody Thu Oct 2 18:19:34 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 7CAEA32ED43; Fri, 12 Sep 2025 18:38:34 +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=1757702316; cv=pass; b=qfXWy8mXXCasI0F9FtVgk8l2U8p7XgIwjgRuPZFJDAOzuk3XV5qNuK8DUqE3APJP/AXVDorobi+PyrF0f04WmzFIkNWXpRQVhaJX9dNvuv8Zp0eMUcyxiDkLMlqE40UImff7lgA/dOhDmFWHiPys+vHX1zOZobS8VvSEV2hi5ck= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702316; c=relaxed/simple; bh=NqnCKZzhovV7MWMGHtwmCJSKL4qTTHBmssMpVHz5pDo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nlW3TMe8QZx2CjYfLm9/vTM1ITBF0a5k7+ZMqBT1jZj+jdYiBCfe/NsNu6RG80Dvqh3sRYxsqhKvlJeoUU+rS3T9hXI21rE3/BX+anbRlFGTy0sPzE6wEmR9MU5DhTzTkGdOtDkfCIovV50NlgZ9zRXcdhCAJ3RXuspk9kWYK6U= 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=SHF4Lx+3; 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="SHF4Lx+3" ARC-Seal: i=1; a=rsa-sha256; t=1757702290; cv=none; d=zohomail.com; s=zohoarc; b=jCcx5kupcGMQ6qEdeF0fPg45uIPns1+aZza0tsmRTDE6dqGN0tzKR5otE2E7aHxZnWtAhLdTlOZzZJxo4DDPmGP2UlpoRDyyUWp3DkPb0g74IyaeoOAUjyidOhhNrPy6bnSAHkh3GonLWjOeGbj6ngsBZheMc/07x+AE646V578= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702290; 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=t8qb0CjF4TYRjzxh3bLQCf9aGJQh8+bsgUjROmryPOo=; b=JT8+qLfy3Acfr5s9tDKDme3QkuPKKfJOMIiN2+Q1Pd0u5xIfNo420QOgYvoa1/JGe4WEeXqBOE45UGlmXFuZmZVwu3UnL/5Oz+XOqQVsn+YyDCEdKBf8TYvKBu9Bbit/Nk9qE/XsowPBc+d1ijdQz49/B6yiWSAnOTkdEQbif18= 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=1757702290; 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=t8qb0CjF4TYRjzxh3bLQCf9aGJQh8+bsgUjROmryPOo=; b=SHF4Lx+3Zq34d4SGkn2CKwtYjVKUWPGD/Sup1TkvqMk0Q8jwWLCJMvCG887iWArd Uuo6kRpdU1lHPFR0ah7NiGgai1FTDo9dC0v6BxZp/Hnqab8ynCJUAlqGP8f/OUUQ4k5 1ExGo3JwY3ufUj25Bz8DxActLkJ5rwh3BUJDfCtE= Received: by mx.zohomail.com with SMTPS id 1757702288056856.071305666723; Fri, 12 Sep 2025 11:38:08 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:05 +0200 Subject: [PATCH v2 06/10] drm/panthor: call into devfreq for current frequency 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: <20250912-mt8196-gpufreq-v2-6-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 As it stands, panthor keeps a cached current frequency value for when it wants to retrieve it. This doesn't work well for when things might switch frequency without panthor's knowledge. Instead, implement the get_cur_freq operation, and expose it through a helper function to the rest of panthor. Reviewed-by: Steven Price Signed-off-by: Nicolas Frattaroli Reviewed-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/panthor/panthor_devfreq.c | 33 +++++++++++++++++++++++++++= ---- drivers/gpu/drm/panthor/panthor_devfreq.h | 2 ++ drivers/gpu/drm/panthor/panthor_device.h | 3 --- drivers/gpu/drm/panthor/panthor_drv.c | 4 +++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.c b/drivers/gpu/drm/pa= nthor/panthor_devfreq.c index 3686515d368db5bb329f4858d4a7247a4957cc24..8903f60c0a3f06313ac2008791c= 210ff32b6bd52 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.c +++ b/drivers/gpu/drm/panthor/panthor_devfreq.c @@ -62,7 +62,6 @@ static void panthor_devfreq_update_utilization(struct pan= thor_devfreq *pdevfreq) static int panthor_devfreq_target(struct device *dev, unsigned long *freq, u32 flags) { - struct panthor_device *ptdev =3D dev_get_drvdata(dev); struct dev_pm_opp *opp; int err; =20 @@ -72,8 +71,6 @@ static int panthor_devfreq_target(struct device *dev, uns= igned long *freq, dev_pm_opp_put(opp); =20 err =3D dev_pm_opp_set_rate(dev, *freq); - if (!err) - ptdev->current_frequency =3D *freq; =20 return err; } @@ -115,11 +112,21 @@ static int panthor_devfreq_get_dev_status(struct devi= ce *dev, return 0; } =20 +static int panthor_devfreq_get_cur_freq(struct device *dev, unsigned long = *freq) +{ + struct panthor_device *ptdev =3D dev_get_drvdata(dev); + + *freq =3D clk_get_rate(ptdev->clks.core); + + return 0; +} + static struct devfreq_dev_profile panthor_devfreq_profile =3D { .timer =3D DEVFREQ_TIMER_DELAYED, .polling_ms =3D 50, /* ~3 frames */ .target =3D panthor_devfreq_target, .get_dev_status =3D panthor_devfreq_get_dev_status, + .get_cur_freq =3D panthor_devfreq_get_cur_freq, }; =20 int panthor_devfreq_init(struct panthor_device *ptdev) @@ -198,7 +205,6 @@ int panthor_devfreq_init(struct panthor_device *ptdev) return PTR_ERR(opp); =20 panthor_devfreq_profile.initial_freq =3D cur_freq; - ptdev->current_frequency =3D cur_freq; =20 /* * Set the recommend OPP this will enable and configure the regulator @@ -296,3 +302,22 @@ void panthor_devfreq_record_idle(struct panthor_device= *ptdev) =20 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); } + +unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev) +{ + struct panthor_devfreq *pdevfreq =3D ptdev->devfreq; + unsigned long freq =3D 0; + int ret; + + if (!pdevfreq || !pdevfreq->devfreq) + return 0; + + if (pdevfreq->devfreq->profile->get_cur_freq) { + ret =3D pdevfreq->devfreq->profile->get_cur_freq(ptdev->base.dev, + &freq); + if (ret) + return 0; + } + + return freq; +} diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.h b/drivers/gpu/drm/pa= nthor/panthor_devfreq.h index b7631de695f7d79456478c87e8af5dc47673cd1d..f8e29e02f66cb3281ed4bb4c75c= da9bd4df82b92 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.h +++ b/drivers/gpu/drm/panthor/panthor_devfreq.h @@ -18,4 +18,6 @@ void panthor_devfreq_suspend(struct panthor_device *ptdev= ); void panthor_devfreq_record_busy(struct panthor_device *ptdev); void panthor_devfreq_record_idle(struct panthor_device *ptdev); =20 +unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev); + #endif /* __PANTHOR_DEVFREQ_H__ */ diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/pan= thor/panthor_device.h index 4fc7cf2aeed577f623aac73ed287d6327645ecaa..a14239c8f9ca9229d8d6d36d327= e6fd6d05f8f2f 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -200,9 +200,6 @@ struct panthor_device { /** @profile_mask: User-set profiling flags for job accounting. */ u32 profile_mask; =20 - /** @current_frequency: Device clock frequency at present. Set by DVFS*/ - unsigned long current_frequency; - /** @fast_rate: Maximum device clock frequency. Set by DVFS */ unsigned long fast_rate; =20 diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/pantho= r/panthor_drv.c index fdbe89ef7f43c54d705b90275917dfdee16a0152..ba871466d7e05a95b51b3e5bb67= 23c587410f3d8 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -25,6 +25,7 @@ #include #include =20 +#include "panthor_devfreq.h" #include "panthor_device.h" #include "panthor_fw.h" #include "panthor_gem.h" @@ -1519,7 +1520,8 @@ static void panthor_gpu_show_fdinfo(struct panthor_de= vice *ptdev, drm_printf(p, "drm-cycles-panthor:\t%llu\n", pfile->stats.cycles); =20 drm_printf(p, "drm-maxfreq-panthor:\t%lu Hz\n", ptdev->fast_rate); - drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", ptdev->current_frequency); + drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", + panthor_devfreq_get_freq(ptdev)); } =20 static void panthor_show_internal_memory_stats(struct drm_printer *p, stru= ct drm_file *file) --=20 2.51.0 From nobody Thu Oct 2 18:19:34 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 701CE340D9B; Fri, 12 Sep 2025 18:38:44 +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=1757702326; cv=pass; b=KC2K3571X+ZrASRwCKZud3pknh1N5Q3ae5fL5TCr+KeqknpJgf6ttiPyiobCOAp4V8Jke9dtcq/ksTCLa1CnZxRE5e767lGGP/I23Gq3qWC3xlaaKMRmK1U+nN0vk4wK838rLrS3j1v04aIScFuUfEXWzxTVwUPtJ2AXsjQk910= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702326; c=relaxed/simple; bh=V618wGRJg/grXU1p4MD/yIGNYrNlm6vOBXPJBBWzmBQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tq2EhyMZ/nUIutgyMsC9/Sfhla+cyQDW0/9Wghc+QsfxVT9In29bO4x/uo/Yba9Ea1Zp9c5jNadfyhnFRPZqoYrMsa0THngAqYCpGJzxn4SNLtvAVZGnyAb+DUO+EBA7NACp1cn3tUTEWn5te+11DdAXgcozqVXRX6iCLYu/5po= 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=e/+Mq0lr; 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="e/+Mq0lr" ARC-Seal: i=1; a=rsa-sha256; t=1757702297; cv=none; d=zohomail.com; s=zohoarc; b=jYhju4p2xqEoKJTllo2yZ8ezc39M9zpj2Xqu/SFzebFUFnh2hHQcDybEkwpmJFNmOw2lNARHLKbxr9pokaxeMf7+gvlI5sPweHT/VbTlo86CUR96QUzZp+BqL+9Wrrg8XsLDWRw92MeTdUGAQKgpZz42fky5S5fcxiwlEwj4Cv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702297; 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=esTzJAps+Q9ohTe0smajF9MVNFiYXLuAoXALxngs7YA=; b=WcooTMWQVaZyIQf92UQ+g4GRnK2nuXy2EVr9xOLco9ijmvKH00vLhi7NIRA7OUeG1hp0Sf3WccLxrQfjoTelrG5IYvfgFaIQajQiGHRjIAQPlmGzGctl7swiXwbkcJ5MuFo7xntBLNN6L0wVfktOucYFo0N6RflE6f5y/xPPnmg= 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=1757702296; 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=esTzJAps+Q9ohTe0smajF9MVNFiYXLuAoXALxngs7YA=; b=e/+Mq0lrdf4I9fFWBSoBwTEBFQvysct6QKYHYTBa8a/U9AUHkhm/+MHoFRiRehV2 9MuxLF5eKdBav3TV4+Nu6aXYJc07t6uB7JVt1WNhFa6jn5Xz4SQYkHPyX2kW0k2FK48 k5SB/WgzK+tTTRo6wiBRVyzQM41yaptoFWZAmJdU= Received: by mx.zohomail.com with SMTPS id 1757702295104374.16826602133335; Fri, 12 Sep 2025 11:38:15 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:06 +0200 Subject: [PATCH v2 07/10] drm/panthor: move panthor_devfreq struct to header 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: <20250912-mt8196-gpufreq-v2-7-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 In order to make files other than panthor_devfreq.c be able to touch the members of a panthor_devfreq instance, it needs to live somewhere other than the .c file. Move it into the panthor_devfreq.h header, so that the upcoming MediaTek MFG devfreq can use it as well. Reviewed-by: Steven Price Signed-off-by: Nicolas Frattaroli Reviewed-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/panthor/panthor_devfreq.c | 32 --------------------------- drivers/gpu/drm/panthor/panthor_devfreq.h | 36 +++++++++++++++++++++++++++= +++- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.c b/drivers/gpu/drm/pa= nthor/panthor_devfreq.c index 8903f60c0a3f06313ac2008791c210ff32b6bd52..02eb3ca15d1874e1cbafc6b614b= 196c5cc75b6a1 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.c +++ b/drivers/gpu/drm/panthor/panthor_devfreq.c @@ -12,38 +12,6 @@ #include "panthor_devfreq.h" #include "panthor_device.h" =20 -/** - * struct panthor_devfreq - Device frequency management - */ -struct panthor_devfreq { - /** @devfreq: devfreq device. */ - struct devfreq *devfreq; - - /** @gov_data: Governor data. */ - struct devfreq_simple_ondemand_data gov_data; - - /** @busy_time: Busy time. */ - ktime_t busy_time; - - /** @idle_time: Idle time. */ - ktime_t idle_time; - - /** @time_last_update: Last update time. */ - ktime_t time_last_update; - - /** @last_busy_state: True if the GPU was busy last time we updated the s= tate. */ - bool last_busy_state; - - /** - * @lock: Lock used to protect busy_time, idle_time, time_last_update and - * last_busy_state. - * - * These fields can be accessed concurrently by panthor_devfreq_get_dev_s= tatus() - * and panthor_devfreq_record_{busy,idle}(). - */ - spinlock_t lock; -}; - static void panthor_devfreq_update_utilization(struct panthor_devfreq *pde= vfreq) { ktime_t now, last; diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.h b/drivers/gpu/drm/pa= nthor/panthor_devfreq.h index f8e29e02f66cb3281ed4bb4c75cda9bd4df82b92..e8b5ccddd45c52ee3215e9c84c6= ebd9109640282 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.h +++ b/drivers/gpu/drm/panthor/panthor_devfreq.h @@ -4,11 +4,45 @@ #ifndef __PANTHOR_DEVFREQ_H__ #define __PANTHOR_DEVFREQ_H__ =20 +#include + struct devfreq; struct thermal_cooling_device; =20 struct panthor_device; -struct panthor_devfreq; + +/** + * struct panthor_devfreq - Device frequency management + */ +struct panthor_devfreq { + /** @devfreq: devfreq device. */ + struct devfreq *devfreq; + + /** @gov_data: Governor data. */ + struct devfreq_simple_ondemand_data gov_data; + + /** @busy_time: Busy time. */ + ktime_t busy_time; + + /** @idle_time: Idle time. */ + ktime_t idle_time; + + /** @time_last_update: Last update time. */ + ktime_t time_last_update; + + /** @last_busy_state: True if the GPU was busy last time we updated the s= tate. */ + bool last_busy_state; + + /** + * @lock: Lock used to protect busy_time, idle_time, time_last_update and + * last_busy_state. + * + * These fields can be accessed concurrently by panthor_devfreq_get_dev_s= tatus() + * and panthor_devfreq_record_{busy,idle}(). + */ + spinlock_t lock; +}; + =20 int panthor_devfreq_init(struct panthor_device *ptdev); =20 --=20 2.51.0 From nobody Thu Oct 2 18:19:34 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 687A4340DAB; Fri, 12 Sep 2025 18:38:46 +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=1757702328; cv=pass; b=p5/PtXGl5azMHoDb3dW0VzmEu++ZswMH90wXGUhBitcwJLa8wj9nzj4vvERVsZ5hKi9YsrEOs+ShVfbAV4qcqU9Gtr6W0o4c7q1hOEq0Dy8R1COEuu7GwhgHUQCkjJ8lMRS4qV+lkmGv4M1JkoxiwQLQvwoGJors+tkPDgtffBQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702328; c=relaxed/simple; bh=C09om0hSevmo3F26EgHRDJXZTSL3ol4BTavYaJtNduo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cJWlZAGkLBW9XffK4H/cYdP3248BUPdjkv9ry3zEXAT1PHWOVOEXGQcW5lIV7eB5ntuNxUByhr/U/04qQnVki0h3PccgPEcY5rhxazApG5Rp6knPq9RfgOAeDivN4+i9f9TbEHM84zxwT73w35tRyIZ/zHhZAO1GWeQBGHYgnJE= 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=OpQH0mzJ; 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="OpQH0mzJ" ARC-Seal: i=1; a=rsa-sha256; t=1757702303; cv=none; d=zohomail.com; s=zohoarc; b=a4tRqvqtJl9R9hCDCmWgA92dpDyvjYyxf5bZaBZnzumlk0K88olDl3cj8sv/AQN9MiDYQfW0cDu+xcB5YOR1fcYGMTLCMw2m6842DX09giz3fTARjh3/LHZTuiFKzt8ZZ+xTMINw5l8v819T1To1eG9OIq48c+o4MQIwWW/s6T8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702303; 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=C8sOpy/rAktuTLkSbEosXeREaQf1wLgvwiE0AeRcq3g=; b=Vxv4qnF4/hRnA6gggJC60iOILrka4iiIG5PRNxo4Rkbhbf9YYw4y3pp+VS0NzRGELT6sHnSjWZKLHDyAoCXdWKibFNk7+TIvIt/UzHJiAVNAB4Pu9tl1/f0A6J6AXooiI2dISM9mnJ/Rf6E+Es5kxLIMbKPBEeklHfZRKjIzF/I= 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=1757702302; 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=C8sOpy/rAktuTLkSbEosXeREaQf1wLgvwiE0AeRcq3g=; b=OpQH0mzJjlgF2SVIxCZOAbCy5K9FFiQZ+cLHOXqHG0zoq/rJbknktGNta9M0deEi noAbDTS8LSGEusGxWsg/XWY/o8DcTBrGs/af3v5pU1KytBZrfKFle3YvCIMZAj2o3ly lFik1GOirgeAWXVfZIID3uWgK0Ruj4ZUQI6qx58U= Received: by mx.zohomail.com with SMTPS id 1757702302096356.60938068660244; Fri, 12 Sep 2025 11:38:22 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:07 +0200 Subject: [PATCH v2 08/10] drm/panthor: devfreq: expose get_dev_status and make it more generic 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: <20250912-mt8196-gpufreq-v2-8-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 The only device-specific part of panthor's get_dev_status devfreq callback is getting the clock frequency. All the other logic surrounding what it does may be useful for other devfreq implementations however. Expose it in the panthor_devfreq.h header file, and make it call back into get_cur_freq instead of poking the common clock framework directly. Signed-off-by: Nicolas Frattaroli --- drivers/gpu/drm/panthor/panthor_devfreq.c | 11 ++++++++--- drivers/gpu/drm/panthor/panthor_devfreq.h | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.c b/drivers/gpu/drm/pa= nthor/panthor_devfreq.c index 02eb3ca15d1874e1cbafc6b614b196c5cc75b6a1..34b621b155f1324ba4f0a07c981= da669d945a545 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.c +++ b/drivers/gpu/drm/panthor/panthor_devfreq.c @@ -50,14 +50,18 @@ static void panthor_devfreq_reset(struct panthor_devfre= q *pdevfreq) pdevfreq->time_last_update =3D ktime_get(); } =20 -static int panthor_devfreq_get_dev_status(struct device *dev, - struct devfreq_dev_status *status) +int panthor_devfreq_get_dev_status(struct device *dev, + struct devfreq_dev_status *status) { struct panthor_device *ptdev =3D dev_get_drvdata(dev); struct panthor_devfreq *pdevfreq =3D ptdev->devfreq; + struct devfreq_dev_profile *p =3D pdevfreq->devfreq->profile; unsigned long irqflags; + int ret; =20 - status->current_frequency =3D clk_get_rate(ptdev->clks.core); + ret =3D p->get_cur_freq(dev, &status->current_frequency); + if (ret) + return ret; =20 spin_lock_irqsave(&pdevfreq->lock, irqflags); =20 @@ -79,6 +83,7 @@ static int panthor_devfreq_get_dev_status(struct device *= dev, =20 return 0; } +EXPORT_SYMBOL(panthor_devfreq_get_dev_status); =20 static int panthor_devfreq_get_cur_freq(struct device *dev, unsigned long = *freq) { diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.h b/drivers/gpu/drm/pa= nthor/panthor_devfreq.h index e8b5ccddd45c52ee3215e9c84c6ebd9109640282..a891cb5fdc34636444f141e10f5= d45828fc35b51 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.h +++ b/drivers/gpu/drm/panthor/panthor_devfreq.h @@ -52,6 +52,9 @@ void panthor_devfreq_suspend(struct panthor_device *ptdev= ); void panthor_devfreq_record_busy(struct panthor_device *ptdev); void panthor_devfreq_record_idle(struct panthor_device *ptdev); =20 +int panthor_devfreq_get_dev_status(struct device *dev, + struct devfreq_dev_status *status); + unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev); =20 #endif /* __PANTHOR_DEVFREQ_H__ */ --=20 2.51.0 From nobody Thu Oct 2 18:19:34 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 9B3FC18E25; Fri, 12 Sep 2025 18:38:59 +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=1757702341; cv=pass; b=usz5HUkAHAfPuQG+T9U2iNdNMeSf+FciBVcZ/S3HMmyTYMY5J6lO7LF19ziBeZtiTl8axJ25icT5u3c8I7YwpCNU4MZBbAMKvuCfluC8ufW+d+/UAdG3DrP7UTM9+Vmw/E1edTiaK/IxT/zgte2RstZyRS8GGx8hfW1AKOpKiRE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702341; c=relaxed/simple; bh=mfL1HzcwVpkb+79fo+AyJr0DAelm3Tm1QmTIFL8jzGU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SLSHPM/2djrnAExEdNAmYpca47K67GC7/rnjsl0Q3Cu2gL/6DBDZwL7N7tvVgLUseI3QGnEX1SUFsfWhdjT812aYGd5PoM9+yMFleZGIYSBu25Q5/81+k97AV++L6Elym5aZBfE2fBSOo+nmwqLBRJBvTq3O5FaRmwbGcRzKYb0= 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=YH+cFnNW; 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="YH+cFnNW" ARC-Seal: i=1; a=rsa-sha256; t=1757702311; cv=none; d=zohomail.com; s=zohoarc; b=R3DvJYaoj1BUnHbfe6uM3o2Ogobavoh4l1FaRO4FIeGRKImX1aSPgN1ZXOUgALqTKziT9TiN0WylkUKECT1zHaqs24PjcyPBCl//vVvWIh/zfoxtzsrFiKp68ra3CsQQ1DYEhc7EjPitSdrSTbXtlBjooKAvqv9X5euZjNSkAB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702311; 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=AptuEM6eGjHvUS3aWo1FiH8jUU8Yeeux1DBWCw1eemo=; b=PmQdd57aGiE34GNnRETM80hEfkg7rgTgEJ6ACZvPuSH3E6EMu9VUpkQq0BNtY0JLnny3DvNeOOuvuYyCWVsGeg6c+SZqCONJb21owAyaST6q/x7Q6IFj+Y0KGSmPvNbnCUnGnCY+hgWBubTYk4yTLvhHmiGmr3KVya74pN+wKrU= 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=1757702311; 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=AptuEM6eGjHvUS3aWo1FiH8jUU8Yeeux1DBWCw1eemo=; b=YH+cFnNWZugtBZCChnD9/4NvJrYtEZhzu8s36nm0iUOuFtj7XYJxypYwfM2IzE+n P08riJAcQGJ+JDzgj+1Hq2BsCyLHHccR/t2/Lv9lQBvNDH7Aj+1au1KrOld20dwCEi1 Ebb5+vk7QuiYH5JJy3MFqEIU/CEENZ6Hth7Uu/NE= Received: by mx.zohomail.com with SMTPS id 1757702309074253.43093313248596; Fri, 12 Sep 2025 11:38:29 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:08 +0200 Subject: [PATCH v2 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: <20250912-mt8196-gpufreq-v2-9-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 device is pointed at on its performance-domains 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 34b621b155f1324ba4f0a07c981da669d945a545..84157916350cf506d315603a47b= fc99436a787f8 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-domains", 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-domains")) + 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 From nobody Thu Oct 2 18:19:34 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 307B1346A05; Fri, 12 Sep 2025 18:39:05 +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=1757702347; cv=pass; b=S01buAXKAFyVzZSWpQOnmo/pM8rKIyDnkHpi0HMZ00/gpnFChlIjVY2h7OvO4orR3GApbDoJTM2xNSi4Xo9akPiyvYmM59nerBzqi3gwo8WgBl0Te1kKdq9mvoNjXUER05g3AVRJaCYbddXHZhUgyrzXyocZfTxlJ5gX/Hs/mRM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757702347; c=relaxed/simple; bh=BqmOXGp7www3DV2rwc5p+4QdPomeMhnEfLSSRH3XSrU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WSYjQMwGy7bL4W1aUcQdAb0mqri5XENxDdJFYmnpmdW9R//T0zIWABaM9xoVP1uJnrejbiimXx8T9xf52lUB+l4isVuL0Rz0HrCFyye212pMf78ai0LXlwFZNc6hzLWxV++VNmjoEAtw/A0gzzcjA3g65/JMFSPySw0RJmTFHG8= 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=Ob2yGKNJ; 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="Ob2yGKNJ" ARC-Seal: i=1; a=rsa-sha256; t=1757702317; cv=none; d=zohomail.com; s=zohoarc; b=QlnDmwDqn3lpjs1d0KLFKazvGnWfj/57ovvfm3cEDeDWuaztN4xdJdp7xffH3Xq1w3fmmWxRIPAex3Ayo8K77q/P9Zr9QJd02apV2+lj7c9toSMJ9FX5LTGGY13+Uuv0B/ePuLQ4LG341k/DFW35JWBjINwxmNLZiPtEa5fXH4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757702317; 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=jRT2XR7H2WVcQDpIAsRYqGeSLq0Nk+UW+lHe4NwRGrs=; b=Q3sZNrgxredsLur6WRzJiZduzigQGu145NdI6Po4ZWF7Ea3rZ7fFO10Dimf6ROPLnS4xXi/6OeTPEWDroF5jYnOTsRlCDwRvMw7BjzMMiNQWsCZnSjQwKupLaVwbdKNs3YT21hGjnTPC6uIbxM2BSn1tp5LXGuT/7i6xKCfBs9o= 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=1757702317; 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=jRT2XR7H2WVcQDpIAsRYqGeSLq0Nk+UW+lHe4NwRGrs=; b=Ob2yGKNJY+l23tmQvBTsHisZq4FzFfOR+gF0zywRqzLwLdQkKaYrfDuUa4Nf8nga 0bRYmplwwd4Q5JIfSqMXoCDpSmsx2YhS947NY1hDWR1/3wNblcetFMINhZ3b5Q51smS 08rpKdF/ApSoKyReb3s1ZG3VOc78AcagX6gAT8cI= Received: by mx.zohomail.com with SMTPS id 1757702316168732.2914162423385; Fri, 12 Sep 2025 11:38:36 -0700 (PDT) From: Nicolas Frattaroli Date: Fri, 12 Sep 2025 20:37:09 +0200 Subject: [PATCH v2 10/10] drm/panthor: add support for MediaTek MFlexGraphics 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: <20250912-mt8196-gpufreq-v2-10-779a8a3729d9@collabora.com> References: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@collabora.com> In-Reply-To: <20250912-mt8196-gpufreq-v2-0-779a8a3729d9@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" , Chia-I Wu , Chen-Yu Tsai Cc: 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 MediaTek uses some glue logic to control frequency and power on some of their GPUs. This is best exposed as a devfreq driver, as it saves us from having to hardcode OPPs into the device tree, and can be extended with additional devfreq-y logic like more clever governors that use the hardware's GPUEB MCU to set frame time targets and power limits. Add this driver to the panthor subdirectory. It needs to live here as it needs to call into panthor's devfreq layer, and panthor for its part also needs to call into this driver during probe to get a devfreq device registered. Solving the cyclical dependency by having mediatek_mfg live without knowledge of what a panthor is would require moving the devfreq provider stuff into a generic devfreq subsystem solution, which I didn't want to do. Signed-off-by: Nicolas Frattaroli --- drivers/gpu/drm/panthor/Kconfig | 13 + drivers/gpu/drm/panthor/Makefile | 2 + drivers/gpu/drm/panthor/mediatek_mfg.c | 1053 ++++++++++++++++++++++++++++= ++++ 3 files changed, 1068 insertions(+) diff --git a/drivers/gpu/drm/panthor/Kconfig b/drivers/gpu/drm/panthor/Kcon= fig index 55b40ad07f3b0779e0c434469ddc874ff74fde27..c4d2599c05df9e0e009b8e99b3d= 29c220269ca0d 100644 --- a/drivers/gpu/drm/panthor/Kconfig +++ b/drivers/gpu/drm/panthor/Kconfig @@ -21,3 +21,16 @@ config DRM_PANTHOR =20 Note that the Mali-G68 and Mali-G78, while Valhall architecture, will be supported with the panfrost driver as they are not CSF GPUs. + +config DRM_PANTHOR_MEDIATEK_MFG + tristate "MediaTek MFlexGraphics Extensions for Panthor" + depends on (DRM_PANTHOR && ARCH_MEDIATEK) || COMPILE_TEST + select DEVFREQ_GOV_SIMPLE_ONDEMAND + select PM_DEVFREQ + select MTK_GPUEB_MBOX + help + Support for power and clock control in Panthor for MediaTek + MFlexGraphics devices, such as the GPU on the MT8196 or MT6991 SoCs. + + These extensions are required for the GPU to work on these platforms, + as they control the glue logic that powers on the GPU. diff --git a/drivers/gpu/drm/panthor/Makefile b/drivers/gpu/drm/panthor/Mak= efile index 02db21748c125688d2ef20ed254b5ebd7ff642e4..e0ebfdfb20bd78e0003c860c86c= 040746248fb89 100644 --- a/drivers/gpu/drm/panthor/Makefile +++ b/drivers/gpu/drm/panthor/Makefile @@ -12,4 +12,6 @@ panthor-y :=3D \ panthor_mmu.o \ panthor_sched.o =20 +obj-$(CONFIG_DRM_PANTHOR_MEDIATEK_MFG) +=3D mediatek_mfg.o + obj-$(CONFIG_DRM_PANTHOR) +=3D panthor.o diff --git a/drivers/gpu/drm/panthor/mediatek_mfg.c b/drivers/gpu/drm/panth= or/mediatek_mfg.c new file mode 100644 index 0000000000000000000000000000000000000000..e06a1d5d8cbf81ac276b521df4b= 04c81b4c75f0b --- /dev/null +++ b/drivers/gpu/drm/panthor/mediatek_mfg.c @@ -0,0 +1,1053 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for MediaTek MFlexGraphics Devices + * + * Copyright (C) 2025, Collabora Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "panthor_devfreq.h" +#include "panthor_device.h" + +#define GPR_LP_STATE 0x0028 +#define EB_ON_SUSPEND 0x0 +#define EB_ON_RESUME 0x1 +#define GPR_IPI_MAGIC 0x34 + +#define RPC_PWR_CON 0x0504 +#define PWR_ACK_M GENMASK(31, 30) +#define RPC_DUMMY_REG_2 0x0658 +#define RPC_GHPM_CFG0_CON 0x0800 +#define GHPM_ENABLE_M BIT(0) +#define GHPM_ON_SEQ_M BIT(2) +#define RPC_GHPM_RO0_CON 0x09A4 +#define GHPM_STATE_M GENMASK(7, 0) +#define GHPM_PWR_STATE_M BIT(16) + +#define GF_REG_MAGIC 0x0000 +#define GF_REG_GPU_OPP_IDX 0x0004 +#define GF_REG_STK_OPP_IDX 0x0008 +#define GF_REG_GPU_OPP_NUM 0x000c +#define GF_REG_STK_OPP_NUM 0x0010 +#define GF_REG_GPU_OPP_SNUM 0x0014 +#define GF_REG_STK_OPP_SNUM 0x0018 +#define GF_REG_POWER_COUNT 0x001c +#define GF_REG_BUCK_COUNT 0x0020 +#define GF_REG_MTCMOS_COUNT 0x0024 +#define GF_REG_CG_COUNT 0x0028 /* CG =3D Clock Gate? */ +#define GF_REG_ACTIVE_COUNT 0x002C +#define GF_REG_TEMP_RAW 0x0030 +#define GF_REG_TEMP_NORM_GPU 0x0034 +#define GF_REG_TEMP_HIGH_GPU 0x0038 +#define GF_REG_TEMP_NORM_STK 0x003C +#define GF_REG_TEMP_HIGH_STK 0x0040 +#define GF_REG_FREQ_CUR_GPU 0x0044 +#define GF_REG_FREQ_CUR_STK 0x0048 +#define GF_REG_FREQ_OUT_GPU 0x004C /* Guess: actual achieved freq */ +#define GF_REG_FREQ_OUT_STK 0x0050 /* Guess: actual achieved freq */ +#define GF_REG_FREQ_METER_GPU 0x0054 /* Seems unused, always 0 */ +#define GF_REG_FREQ_METER_STK 0x0058 /* Seems unused, always 0 */ +#define GF_REG_VOLT_CUR_GPU 0x005C /* in tens of microvolts */ +#define GF_REG_VOLT_CUR_STK 0x0060 /* in tens of microvolts */ +#define GF_REG_VOLT_CUR_GPU_SRAM 0x0064 +#define GF_REG_VOLT_CUR_STK_SRAM 0x0068 +#define GF_REG_VOLT_CUR_GPU_REG 0x006C /* Seems unused, always 0 */ +#define GF_REG_VOLT_CUR_STK_REG 0x0070 /* Seems unused, always 0 */ +#define GF_REG_VOLT_CUR_GPU_REG_SRAM 0x0074 +#define GF_REG_VOLT_CUR_STK_REG_SRAM 0x0078 +#define GF_REG_PWR_CUR_GPU 0x007C /* in milliwatts */ +#define GF_REG_PWR_CUR_STK 0x0080 /* in milliwatts */ +#define GF_REG_PWR_MAX_GPU 0x0084 /* in milliwatts */ +#define GF_REG_PWR_MAX_STK 0x0088 /* in milliwatts */ +#define GF_REG_PWR_MIN_GPU 0x008C /* in milliwatts */ +#define GF_REG_PWR_MIN_STK 0x0090 /* in milliwatts */ +#define GF_REG_LEAKAGE_RT_GPU 0x0094 /* Unknown */ +#define GF_REG_LEAKAGE_RT_STK 0x0098 /* Unknown */ +#define GF_REG_LEAKAGE_RT_SRAM 0x009C /* Unknown */ +#define GF_REG_LEAKAGE_HT_GPU 0x00A0 /* Unknown */ +#define GF_REG_LEAKAGE_HT_STK 0x00A4 /* Unknown */ +#define GF_REG_LEAKAGE_HT_SRAM 0x00A8 /* Unknown */ +#define GF_REG_VOLT_DAC_LOW_GPU 0x00AC /* Seems unused, always 0 */ +#define GF_REG_VOLT_DAC_LOW_STK 0x00B0 /* Seems unused, always 0 */ +#define GF_REG_OPP_CUR_CEIL 0x00B4 +#define GF_REG_OPP_CUR_FLOOR 0x00B8 +#define GF_REG_OPP_CUR_LIMITER_CEIL 0x00BC +#define GF_REG_OPP_CUR_LIMITER_FLOOR 0x00C0 +#define GF_REG_OPP_PRIORITY_CEIL 0x00C4 +#define GF_REG_OPP_PRIORITY_FLOOR 0x00C8 +#define GF_REG_PWR_CTL 0x00CC +#define GF_REG_ACTIVE_SLEEP_CTL 0x00D0 +#define GF_REG_DVFS_STATE 0x00D4 +#define GF_REG_SHADER_PRESENT 0x00D8 +#define GF_REG_ASENSOR_ENABLE 0x00DC +#define GF_REG_AGING_LOAD 0x00E0 +#define GF_REG_AGING_MARGIN 0x00E4 +#define GF_REG_AVS_ENABLE 0x00E8 +#define GF_REG_AVS_MARGIN 0x00EC +#define GF_REG_CHIP_TYPE 0x00F0 +#define GF_REG_SB_VERSION 0x00F4 +#define GF_REG_PTP_VERSION 0x00F8 +#define GF_REG_DBG_VERSION 0x00FC +#define GF_REG_KDBG_VERSION 0x0100 +#define GF_REG_GPM1_MODE 0x0104 +#define GF_REG_GPM3_MODE 0x0108 +#define GF_REG_DFD_MODE 0x010C +#define GF_REG_DUAL_BUCK 0x0110 +#define GF_REG_SEGMENT_ID 0x0114 +#define GF_REG_POWER_TIME_H 0x0118 +#define GF_REG_POWER_TIME_L 0x011C +#define GF_REG_PWR_STATUS 0x0120 +#define GF_REG_STRESS_TEST 0x0124 +#define GF_REG_TEST_MODE 0x0128 +#define GF_REG_IPS_MODE 0x012C +#define GF_REG_TEMP_COMP_MODE 0x0130 +#define GF_REG_HT_TEMP_COMP_MODE 0x0134 +#define GF_REG_PWR_TRACKER_MODE 0x0138 +#define GF_REG_OPP_TABLE_GPU 0x0314 +#define GF_REG_OPP_TABLE_STK 0x09A4 +#define GF_REG_OPP_TABLE_GPU_S 0x1034 +#define GF_REG_OPP_TABLE_STK_S 0x16c4 +#define GF_REG_LIMIT_TABLE 0x1d54 +#define GF_REG_GPM3_TABLE 0x223C + +#define MFG_MT8196_E2_ID 0x101 +#define GPUEB_SLEEP_MAGIC 0x55667788UL + +#define GPUEB_TIMEOUT_US 10000UL +#define GPUEB_POLL_US 50 + +#define MAX_OPP_NUM 70 + +/* + * This enum is part of the ABI of the GPUEB firmware. Don't change the + * numbering, as you would wreak havoc. + */ +enum mtk_mfg_ipi_cmd { + CMD_INIT_SHARED_MEM =3D 0, + CMD_GET_FREQ_BY_IDX =3D 1, + CMD_GET_POWER_BY_IDX =3D 2, + CMD_GET_OPPIDX_BY_FREQ =3D 3, + CMD_GET_LEAKAGE_POWER =3D 4, + CMD_SET_LIMIT =3D 5, + CMD_POWER_CONTROL =3D 6, + CMD_ACTIVE_SLEEP_CONTROL =3D 7, + CMD_COMMIT =3D 8, + CMD_DUAL_COMMIT =3D 9, + CMD_PDCA_CONFIG =3D 10, + CMD_UPDATE_DEBUG_OPP_INFO =3D 11, + CMD_SWITCH_LIMIT =3D 12, + CMD_FIX_TARGET_OPPIDX =3D 13, + CMD_FIX_DUAL_TARGET_OPPIDX =3D 14, + CMD_FIX_CUSTOM_FREQ_VOLT =3D 15, + CMD_FIX_DUAL_CUSTOM_FREQ_VOLT =3D 16, + CMD_SET_MFGSYS_CONFIG =3D 17, + CMD_MSSV_COMMIT =3D 18, + CMD_NUM =3D 19, +}; + +/* + * This struct is part of the ABI of the GPUEB firmware. Changing it, or + * reordering fields in it, will break things, so don't do it. Thank you. + */ +struct __packed mtk_mfg_ipi_msg { + __le32 magic; + __le32 cmd; + __le32 target; + /* + * Downstream relies on the compiler to implicitly add the following + * padding, as it declares the struct as non-packed. + */ + __le32 padding_lol; + union { + s32 __bitwise oppidx; + s32 __bitwise return_value; + __le32 freq; + __le32 volt; + __le32 power; + __le32 power_state; + __le32 mode; + __le32 value; + struct { + __le64 base; + __le32 size; + } shared_mem; + struct { + __le32 freq; + __le32 volt; + } custom; + struct { + __le32 limiter; + s32 __bitwise ceiling_info; + s32 __bitwise floor_info; + } set_limit; + struct { + __le32 target; + __le32 val; + } mfg_cfg; + struct { + __le32 target; + __le32 val; + } mssv; + struct { + s32 __bitwise gpu_oppidx; + s32 __bitwise stack_oppidx; + } dual_commit; + struct { + __le32 fgpu; + __le32 vgpu; + __le32 fstack; + __le32 vstack; + } dual_custom; + } u; +}; + +struct __packed mtk_mfg_ipi_sleep_msg { + __le32 event; + __le32 state; + __le32 magic; +}; + +/** + * struct mtk_mfg_opp_entry - OPP table entry from firmware + * @freq_khz: The operating point's frequency in kilohertz + * @voltage_core: The operating point's core voltage in tens of microvolts + * @voltage_sram: The operating point's SRAM voltage in tens of microvolts + * @posdiv: exponent of base 2 for PLL frequency divisor used for this OPP + * @voltage_margin: Number of tens of microvolts the voltage can be unders= hot + * @power_mw: estimate of power usage at this operating point, in milliwat= ts + * + * This struct is part of the ABI with the EB firmware. Do not change it. + */ +struct __packed mtk_mfg_opp_entry { + __le32 freq_khz; + __le32 voltage_core; + __le32 voltage_sram; + __le32 posdiv; + __le32 voltage_margin; + __le32 power_mw; +}; + +struct mtk_mfg_mbox { + struct mbox_client cl; + struct completion rx_done; + struct mtk_mfg *mfg; + struct mbox_chan *ch; + void *rx_data; +}; + +struct mtk_mfg { + struct platform_device *pdev; + struct panthor_device *ptdev; + struct clk *clk_eb; + struct clk_bulk_data *gpu_clks; + struct regulator_bulk_data *gpu_regs; + void __iomem *rpc; + void __iomem *gpr; + void __iomem *sram; + phys_addr_t sram_phys; + unsigned int sram_size; + unsigned int ghpm_en_reg; + u32 ipi_magic; + unsigned int num_opps; + unsigned int num_unique_gpu_opps; + struct dev_pm_opp_data *gpu_opps; + struct dev_pm_opp_data *stack_opps; + struct mtk_mfg_mbox *gf_mbox; + struct mtk_mfg_mbox *slp_mbox; + int last_opp; + const struct mtk_mfg_variant *variant; +}; + +struct mtk_mfg_variant { + const char *const *clk_names; + unsigned int num_clks; + const char *const *regulator_names; + unsigned int num_regulators; + int (*init)(struct mtk_mfg *mfg); +}; + +static inline void mtk_mfg_update_reg_bits(void __iomem *addr, u32 mask, u= 32 val) +{ + writel((readl(addr) & ~mask) | (val & mask), addr); +} + +static inline unsigned long mtk_mfg_read_gpu_freq(struct mtk_mfg *mfg) +{ + return readl(mfg->sram + GF_REG_FREQ_CUR_GPU) * 1000UL; +} + +static int mtk_mfg_eb_on(struct mtk_mfg *mfg) +{ + struct device *dev =3D &mfg->pdev->dev; + u32 val; + int ret; + + /* + * If MFG is already on from e.g. the bootloader, we should skip doing + * the power-on sequence, as it wouldn't work without powering it off + * first. + */ + if ((readl(mfg->rpc + RPC_PWR_CON) & PWR_ACK_M) =3D=3D PWR_ACK_M) + return 0; + + ret =3D readl_poll_timeout(mfg->rpc + RPC_GHPM_RO0_CON, val, + !(val & (GHPM_PWR_STATE_M | GHPM_STATE_M)), + GPUEB_POLL_US, GPUEB_TIMEOUT_US); + if (ret) { + dev_err(dev, "timed out waiting for EB to power on\n"); + return ret; + } + + mtk_mfg_update_reg_bits(mfg->rpc + mfg->ghpm_en_reg, GHPM_ENABLE_M, + GHPM_ENABLE_M); + + mtk_mfg_update_reg_bits(mfg->rpc + RPC_GHPM_CFG0_CON, GHPM_ON_SEQ_M, 0); + mtk_mfg_update_reg_bits(mfg->rpc + RPC_GHPM_CFG0_CON, GHPM_ON_SEQ_M, + GHPM_ON_SEQ_M); + + mtk_mfg_update_reg_bits(mfg->rpc + mfg->ghpm_en_reg, GHPM_ENABLE_M, 0); + + + ret =3D readl_poll_timeout(mfg->rpc + RPC_PWR_CON, val, + (val & PWR_ACK_M) =3D=3D PWR_ACK_M, + GPUEB_POLL_US, GPUEB_TIMEOUT_US); + if (ret) { + dev_err(dev, "timed out waiting for EB power ack, val =3D 0x%X\n", + val); + return ret; + } + + ret =3D readl_poll_timeout(mfg->gpr + GPR_LP_STATE, val, + (val =3D=3D EB_ON_RESUME), + GPUEB_POLL_US, GPUEB_TIMEOUT_US); + if (ret) { + dev_err(dev, "timed out waiting for EB to resume, status =3D 0x%X\n", va= l); + return ret; + } + + return 0; +} + +static int mtk_mfg_eb_off(struct mtk_mfg *mfg) +{ + struct mtk_mfg_ipi_sleep_msg msg =3D { + .event =3D 0, + .state =3D 0, + .magic =3D GPUEB_SLEEP_MAGIC + }; + u32 val; + int ret; + + ret =3D mbox_send_message(mfg->slp_mbox->ch, &msg); + if (ret < 0) { + dev_err(&mfg->pdev->dev, "failure in mbox comms: %pe\n", + ERR_PTR(ret)); + return ret; + } + + ret =3D readl_poll_timeout(mfg->rpc + RPC_PWR_CON, val, + !(val & PWR_ACK_M), GPUEB_POLL_US, + GPUEB_TIMEOUT_US); + + if (ret) { + dev_err(&mfg->pdev->dev, + "timed out waiting for EB to power off, val=3D0x%08X\n", + val); + } + + return ret; +} + +static int mtk_mfg_send_ipi(struct mtk_mfg *mfg, struct mtk_mfg_ipi_msg *m= sg) +{ + int ret; + + msg->magic =3D mfg->ipi_magic; + + ret =3D mbox_send_message(mfg->gf_mbox->ch, msg); + if (ret < 0) { + dev_err(&mfg->pdev->dev, "error from mailbox subsystem: %pe\n", + ERR_PTR(ret)); + return ret; + } + + wait_for_completion(&mfg->gf_mbox->rx_done); + + memcpy(msg, mfg->gf_mbox->rx_data, sizeof(*msg)); + + if (msg->u.return_value < 0) { + dev_err(&mfg->pdev->dev, "IPI return: %d\n", + msg->u.return_value); + return -EPROTO; + } + + return 0; +} + +static int mtk_mfg_init_shared_mem(struct mtk_mfg *mfg) +{ + struct device *dev =3D &mfg->pdev->dev; + struct mtk_mfg_ipi_msg msg =3D {}; + int ret; + + dev_info(dev, "clearing GPUEB sram, 0x%X bytes\n", mfg->sram_size); + memset_io(mfg->sram, 0, mfg->sram_size); + + msg.cmd =3D CMD_INIT_SHARED_MEM; + msg.u.shared_mem.base =3D mfg->sram_phys; + msg.u.shared_mem.size =3D mfg->sram_size; + + ret =3D mtk_mfg_send_ipi(mfg, &msg); + if (ret) + return ret; + + if (readl(mfg->sram) !=3D 0xBABADADA) { + dev_err(dev, "EB did not initialise SRAM correctly\n"); + return -EIO; + } + + dev_info(dev, "initialised mem at phys 0x%016llX\n", mfg->sram_phys); + + return 0; +} + +static int mtk_mfg_power_control(struct mtk_mfg *mfg, bool enabled) +{ + struct mtk_mfg_ipi_msg msg =3D {}; + + msg.cmd =3D CMD_POWER_CONTROL; + msg.u.power_state =3D enabled ? 1 : 0; + + return mtk_mfg_send_ipi(mfg, &msg); +} + +static int mtk_mfg_set_oppidx(struct mtk_mfg *mfg, int opp_idx) +{ + struct mtk_mfg_ipi_msg msg =3D {}; + int ret; + + if (!mfg->gpu_opps || !mfg->stack_opps) + return 0; + + if (opp_idx >=3D mfg->num_opps) + return -EINVAL; + + if (mfg->last_opp =3D=3D opp_idx) + return 0; + + msg.cmd =3D CMD_FIX_TARGET_OPPIDX; + msg.u.oppidx =3D opp_idx; + + ret =3D mtk_mfg_send_ipi(mfg, &msg); + if (ret) + return ret; + + mfg->last_opp =3D opp_idx; + + return 0; +} + +static int mtk_mfg_read_opp_tables(struct mtk_mfg *mfg) +{ + struct device *dev =3D &mfg->pdev->dev; + struct mtk_mfg_opp_entry e =3D {}; + unsigned int i; + unsigned long long last_freq; + + mfg->num_opps =3D readl(mfg->sram + GF_REG_GPU_OPP_NUM); + if (mfg->num_opps !=3D readl(mfg->sram + GF_REG_STK_OPP_NUM)) { + dev_err(dev, "OPP count of GPU and Stack differ, %u vs. %u\n", + mfg->num_opps, readl(mfg->sram + GF_REG_STK_OPP_NUM)); + return -EINVAL; + } + + if (mfg->num_opps > MAX_OPP_NUM || mfg->num_opps =3D=3D 0) { + dev_err(dev, "OPP count (%u) out of range %u >=3D count > 0\n", + mfg->num_opps, MAX_OPP_NUM); + return -EINVAL; + } + + mfg->gpu_opps =3D devm_kcalloc(dev, mfg->num_opps, + sizeof(struct dev_pm_opp_data), GFP_KERNEL); + if (!mfg->gpu_opps) + return -ENOMEM; + + mfg->stack_opps =3D devm_kcalloc(dev, mfg->num_opps, + sizeof(struct dev_pm_opp_data), GFP_KERNEL); + if (!mfg->stack_opps) + return -ENOMEM; + + for (i =3D 0; i < mfg->num_opps; i++) { + memcpy_fromio(&e, mfg->sram + GF_REG_OPP_TABLE_GPU + i * sizeof(e), + sizeof(e)); + if (mem_is_zero(&e, sizeof(e))) { + dev_err(dev, "ran into an empty GPU OPP at index %u\n", + i); + return -EINVAL; + } + mfg->gpu_opps[i].freq =3D e.freq_khz * 1000ULL; + mfg->gpu_opps[i].u_volt =3D e.voltage_core * 10; + + if (!last_freq || mfg->gpu_opps[i].freq !=3D last_freq) + mfg->num_unique_gpu_opps++; + + last_freq =3D mfg->gpu_opps[i].freq; + } + + /* Why do I even bother? */ + for (i =3D 0; i < mfg->num_opps; i++) { + memcpy_fromio(&e, mfg->sram + GF_REG_OPP_TABLE_STK + i * sizeof(e), + sizeof(e)); + if (mem_is_zero(&e, sizeof(e))) { + dev_err(dev, "ran into an empty GPU OPP at index %u\n", + i); + return -EINVAL; + } + mfg->stack_opps[i].freq =3D e.freq_khz * 1000ULL; + mfg->stack_opps[i].u_volt =3D e.voltage_core * 10; + } + + return 0; +} + +static inline bool mtk_mfg_opp_idx_match(struct mtk_mfg *mfg, int idx, + unsigned long rate) +{ + if ((idx =3D=3D mfg->num_opps - 1) && mfg->gpu_opps[idx].freq >=3D rate) + return true; + + if (mfg->gpu_opps[idx].freq >=3D rate && mfg->gpu_opps[idx + 1].freq < ra= te) + return true; + + return false; +} + +/** + * mtk_mfg_get_closest_opp_idx - find OPP index for desired GPU frequency + * @mfg: pointer to a &struct mtk_mfg driver instance + * @gpu_rate: desired rate of the GPU core in Hz + * + * Given a desired target frequency for the GPU core, find the index of a + * matching OPP, or the next higher OPP if no exact match is found, or the + * maximum OPP for frequencies exceeding the maximum OPP's frequency. + * + * For duplicate OPP entries, chooses the highest OPP index, as in, the one + * closest to the next lower frequency OPP. + * + * Returns -EINVAL on error, or the OPP index on success. + */ +static int mtk_mfg_get_closest_opp_idx(struct mtk_mfg *mfg, unsigned long = gpu_rate) +{ + int l =3D 0; + int r =3D mfg->num_opps - 1; + int m; + + if (!mfg->gpu_opps) + return -EINVAL; + + if (mfg->gpu_opps[0].freq <=3D gpu_rate) + return 0; + + while (l <=3D r) { + m =3D l + (r - l) / 2; + if (mtk_mfg_opp_idx_match(mfg, m, gpu_rate)) { + return m; + } else if (mfg->gpu_opps[m].freq >=3D gpu_rate) /* >=3D for dupes */ + l =3D m + 1; + else + r =3D m - 1; + } + + return -EINVAL; +} + +static int mtk_mfg_devfreq_target(struct device *dev, unsigned long *freq, + u32 flags) +{ + struct panthor_device *ptdev =3D dev_get_drvdata(dev); + struct panthor_devfreq *pdevfreq =3D ptdev->devfreq; + struct mtk_mfg *mfg =3D dev_get_drvdata(&pdevfreq->devfreq->dev); + int ret, opp; + + opp =3D mtk_mfg_get_closest_opp_idx(mfg, *freq); + if (opp < 0) { + dev_err(dev, "Couldn't get closest OPP: %pe\n", ERR_PTR(opp)); + return opp; + } + + ret =3D pm_runtime_resume_and_get(&mfg->pdev->dev); + if (ret) + return ret; + + ret =3D mtk_mfg_set_oppidx(mfg, opp); + if (!ret) + *freq =3D mtk_mfg_read_gpu_freq(mfg); + else + dev_err(dev, "Couldn't set OPP: %pe\n", ERR_PTR(ret)); + + pm_runtime_put(&mfg->pdev->dev); + + return ret; +} + +static int mtk_mfg_devfreq_get_cur_freq(struct device *dev, unsigned long = *freq) +{ + struct panthor_device *ptdev =3D dev_get_drvdata(dev); + struct panthor_devfreq *pdevfreq =3D ptdev->devfreq; + struct mtk_mfg *mfg; + int ret; + + if (IS_ERR_OR_NULL(pdevfreq->devfreq)) + return -ENODEV; + + mfg =3D dev_get_drvdata(&pdevfreq->devfreq->dev); + if (IS_ERR_OR_NULL(mfg)) { + *freq =3D pdevfreq->devfreq->profile->initial_freq; + return 0; + } + + ret =3D pm_runtime_resume_and_get(&mfg->pdev->dev); + if (ret) + return ret; + + *freq =3D mtk_mfg_read_gpu_freq(mfg); + + pm_runtime_put(&mfg->pdev->dev); + + return 0; +} + +static const struct devfreq_dev_profile mtk_mfg_devfreq_profile =3D { + .timer =3D DEVFREQ_TIMER_DELAYED, + .polling_ms =3D 50, /* ~3 frames */ + .target =3D mtk_mfg_devfreq_target, + .get_dev_status =3D panthor_devfreq_get_dev_status, + .get_cur_freq =3D mtk_mfg_devfreq_get_cur_freq, +}; + +static const char *const mtk_mfg_mt8196_clk_names[] =3D { + "mfgpll", + "mfgpll_sc0", + "mfgpll_sc1", +}; + +static const char *const mtk_mfg_mt8196_regulators[] =3D { + "core", + "stack", + "sram", +}; + +static int mtk_mfg_mt8196_init(struct mtk_mfg *mfg) +{ + void __iomem *e2_base; + + e2_base =3D devm_platform_ioremap_resource_byname(mfg->pdev, "hw_revision= "); + if (IS_ERR(e2_base)) + return dev_err_probe(&mfg->pdev->dev, PTR_ERR(e2_base), + "Couldn't get hw_revision register\n"); + + if (readl(e2_base) =3D=3D MFG_MT8196_E2_ID) + mfg->ghpm_en_reg =3D RPC_DUMMY_REG_2; + else + mfg->ghpm_en_reg =3D RPC_GHPM_CFG0_CON; + + return 0; +}; + +static const struct mtk_mfg_variant mtk_mfg_mt8196_variant =3D { + .clk_names =3D mtk_mfg_mt8196_clk_names, + .num_clks =3D ARRAY_SIZE(mtk_mfg_mt8196_clk_names), + .regulator_names =3D mtk_mfg_mt8196_regulators, + .num_regulators =3D ARRAY_SIZE(mtk_mfg_mt8196_regulators), + .init =3D mtk_mfg_mt8196_init, +}; + +static int mtk_mfg_init_devfreq(struct panthor_device *ptdev, + struct device *gpufreq_dev) +{ + struct device *gpu =3D ptdev->base.dev; + struct panthor_devfreq *pdevfreq; + struct mtk_mfg *mfg; + struct devfreq_dev_profile *profile; + struct dev_pm_opp *opp; + int j =3D 0; + int i, ret; + + mfg =3D dev_get_drvdata(gpufreq_dev); + + if (!mfg) + return -EPROBE_DEFER; + + if (!mfg->gpu_opps) + return -EPROBE_DEFER; + + pdevfreq =3D drmm_kzalloc(&ptdev->base, sizeof(*ptdev->devfreq), GFP_KERN= EL); + if (!pdevfreq) + return -ENOMEM; + + ptdev->devfreq =3D pdevfreq; + mfg->ptdev =3D ptdev; + + spin_lock_init(&pdevfreq->lock); + + profile =3D devm_kmemdup(gpu, &mtk_mfg_devfreq_profile, sizeof(*profile), + GFP_KERNEL); + + if (!profile) + return -ENOMEM; + + ret =3D pm_runtime_resume_and_get(&mfg->pdev->dev); + if (ret) { + dev_err(gpufreq_dev, "could not resume runtime pm: %pe\n", + ERR_PTR(ret)); + return ret; + } + profile->initial_freq =3D mtk_mfg_read_gpu_freq(mfg); + pm_runtime_put(&mfg->pdev->dev); + + profile->freq_table =3D devm_kcalloc(gpu, mfg->num_unique_gpu_opps, + sizeof(*profile->freq_table), + GFP_KERNEL); + if (!profile->freq_table) + return -ENOMEM; + + profile->max_state =3D mfg->num_unique_gpu_opps; + + for (i =3D mfg->num_opps - 1; i >=3D 0 && j < profile->max_state; i--) { + if ((j =3D=3D 0) || (mfg->gpu_opps[i].freq !=3D profile->freq_table[j - = 1])) { + profile->freq_table[j] =3D mfg->gpu_opps[i].freq; + ret =3D dev_pm_opp_add_dynamic(gpu, &mfg->gpu_opps[i]); + if (ret) { + dev_err(gpu, "couldn't add OPP %d: %pe\n", + i, ERR_PTR(ret)); + return ret; + } + j++; + } + } + + opp =3D devfreq_recommended_opp(gpu, &profile->initial_freq, 0); + if (IS_ERR(opp)) { + dev_err(gpufreq_dev, "failed getting OPP recommendation: %pe\n", + opp); + return PTR_ERR(opp); + } + + ret =3D dev_pm_opp_set_opp(gpu, opp); + dev_pm_opp_put(opp); + if (ret) { + dev_err(gpu, "Couldn't set recommended OPP\n"); + return ret; + } + + ptdev->fast_rate =3D profile->freq_table[profile->max_state - 1]; + + pdevfreq->time_last_update =3D ktime_get(); + pdevfreq->gov_data.upthreshold =3D 45; + pdevfreq->gov_data.downdifferential =3D 5; + + pdevfreq->devfreq =3D devm_devfreq_add_device(ptdev->base.dev, profile, + DEVFREQ_GOV_SIMPLE_ONDEMAND, + &pdevfreq->gov_data); + if (IS_ERR(pdevfreq->devfreq)) { + dev_err(gpu, "Failed to register devfreq device: %pe\n", + pdevfreq->devfreq); + return PTR_ERR(pdevfreq->devfreq); + } + + /* + * There are some ways devfreq_add_device can fail without setting an + * error pointer, but setting a NULL pointer instead. We really don't + * want to return 0 in the above check, so return -EINVAL here. + */ + if (!pdevfreq->devfreq) { + dev_err(gpu, "Failed to register devfreq device\n"); + return -EINVAL; + } + + dev_set_drvdata(&pdevfreq->devfreq->dev, mfg); + + return 0; +} + +static void mtk_mfg_mbox_rx_callback(struct mbox_client *cl, void *mssg) +{ + struct mtk_mfg_mbox *mb =3D container_of(cl, struct mtk_mfg_mbox, cl); + + mb->rx_data =3D mssg; + complete(&mb->rx_done); +} + +static int mtk_mfg_init_mbox(struct mtk_mfg *mfg) +{ + struct device *dev =3D &mfg->pdev->dev; + struct mtk_mfg_mbox *gf; + struct mtk_mfg_mbox *slp; + + gf =3D devm_kzalloc(dev, sizeof(*gf), GFP_KERNEL); + if (!gf) + return -ENOMEM; + + slp =3D devm_kzalloc(dev, sizeof(*slp), GFP_KERNEL); + if (!slp) + return -ENOMEM; + + gf->mfg =3D mfg; + init_completion(&gf->rx_done); + gf->cl.dev =3D dev; + gf->cl.rx_callback =3D mtk_mfg_mbox_rx_callback; + gf->cl.tx_tout =3D GPUEB_TIMEOUT_US / USEC_PER_MSEC; + gf->ch =3D mbox_request_channel_byname(&gf->cl, "gpufreq"); + if (IS_ERR(gf->ch)) + return PTR_ERR(gf->ch); + + mfg->gf_mbox =3D gf; + + slp->mfg =3D mfg; + init_completion(&slp->rx_done); + slp->cl.dev =3D dev; + slp->cl.tx_tout =3D GPUEB_TIMEOUT_US / USEC_PER_MSEC; + slp->cl.tx_block =3D true; + slp->ch =3D mbox_request_channel_byname(&slp->cl, "sleep"); + if (IS_ERR(slp->ch)) + return PTR_ERR(slp->ch); + + mfg->slp_mbox =3D slp; + + return 0; +} + +static const struct of_device_id mtk_mfg_of_match[] =3D { + { .compatible =3D "mediatek,mt8196-gpufreq", .data =3D &mtk_mfg_mt8196_va= riant }, + {} +}; +MODULE_DEVICE_TABLE(of, mtk_mfg_of_match); + +static int mtk_mfg_probe(struct platform_device *pdev) +{ + struct device_node *shmem __free(device_node); + struct panthor_devfreq_provider *prov; + struct mtk_mfg *mfg; + struct device *dev =3D &pdev->dev; + const struct mtk_mfg_variant *data =3D of_device_get_match_data(dev); + struct resource res; + int ret; + int i; + + mfg =3D devm_kzalloc(dev, sizeof(*mfg), GFP_KERNEL); + if (!mfg) + return -ENOMEM; + + prov =3D devm_kzalloc(dev, sizeof(*prov), GFP_KERNEL); + if (!prov) + return -ENOMEM; + + prov->dev =3D dev; + prov->init =3D mtk_mfg_init_devfreq; + + mfg->pdev =3D pdev; + mfg->variant =3D data; + + dev_set_drvdata(dev, mfg); + + mfg->gpr =3D devm_platform_ioremap_resource_byname(pdev, "gpr"); + if (IS_ERR(mfg->gpr)) + return dev_err_probe(dev, PTR_ERR(mfg->gpr), + "Could not retrieve GPR MMIO registers\n"); + + mfg->rpc =3D devm_platform_ioremap_resource_byname(pdev, "rpc"); + if (IS_ERR(mfg->rpc)) + return dev_err_probe(dev, PTR_ERR(mfg->rpc), + "Could not retrieve RPC MMIO registers\n"); + + mfg->clk_eb =3D devm_clk_get(dev, "eb"); + if (IS_ERR(mfg->clk_eb)) + return dev_err_probe(dev, PTR_ERR(mfg->clk_eb), + "Could not get 'eb' clock\n"); + + mfg->gpu_clks =3D devm_kcalloc(dev, data->num_clks, sizeof(*mfg->gpu_clks= ), + GFP_KERNEL); + if (!mfg->gpu_clks) + return -ENOMEM; + + for (i =3D 0; i < data->num_clks; i++) + mfg->gpu_clks[i].id =3D data->clk_names[i]; + + ret =3D devm_clk_bulk_get(dev, data->num_clks, mfg->gpu_clks); + if (ret) + return dev_err_probe(dev, ret, "couldn't get GPU clocks\n"); + + mfg->gpu_regs =3D devm_kcalloc(dev, data->num_regulators, + sizeof(*mfg->gpu_regs), GFP_KERNEL); + if (!mfg->gpu_regs) + return -ENOMEM; + + for (i =3D 0; i < data->num_regulators; i++) + mfg->gpu_regs[i].supply =3D data->regulator_names[i]; + + ret =3D devm_regulator_bulk_get(dev, data->num_regulators, mfg->gpu_regs); + if (ret) + return dev_err_probe(dev, ret, "couldn't get GPU regulators\n"); + + shmem =3D of_parse_phandle(dev->of_node, "shmem", 0); + if (!shmem) + return dev_err_probe(dev, -ENODEV, "Could not get 'shmem'\n"); + + ret =3D of_address_to_resource(shmem, 0, &res); + if (ret) + return dev_err_probe(dev, ret, + "failed to get GPUEB shared memory\n"); + + mfg->sram =3D devm_ioremap(dev, res.start, resource_size(&res)); + if (!mfg->sram) + return dev_err_probe(dev, -EADDRNOTAVAIL, + "failed to ioremap GPUEB sram\n"); + mfg->sram_size =3D resource_size(&res); + mfg->sram_phys =3D res.start; + + if (data->init) { + ret =3D data->init(mfg); + if (ret) + return dev_err_probe(dev, ret, "Variant init failed\n"); + } + + ret =3D clk_prepare_enable(mfg->clk_eb); + if (ret) + return dev_err_probe(dev, ret, "failed to turn on EB clock\n"); + mfg->ipi_magic =3D readl(mfg->gpr + GPR_IPI_MAGIC); + writel(0x0, mfg->gpr + GPR_IPI_MAGIC); /* why. */ + + ret =3D mtk_mfg_init_mbox(mfg); + if (ret) { + ret =3D dev_err_probe(dev, ret, "Couldn't initialise mailbox\n"); + goto out; + } + + clk_disable_unprepare(mfg->clk_eb); + + mfg->last_opp =3D -1; + + devm_pm_runtime_enable(dev); + + ret =3D pm_runtime_resume_and_get(dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to power on MFG\n"); + + ret =3D mtk_mfg_init_shared_mem(mfg); + if (ret) { + dev_err(dev, "Couldn't initialize EB SRAM: %pe\n", ERR_PTR(ret)); + goto out; + } + + ret =3D mtk_mfg_read_opp_tables(mfg); + if (ret) { + dev_err(dev, "Error reading OPP tables from EB: %pe\n", + ERR_PTR(ret)); + goto out; + } + + panthor_devfreq_register_provider(prov); + +out: + pm_runtime_put(dev); + return ret; +} + +static int mtk_mfg_suspend(struct device *dev) +{ + struct mtk_mfg *mfg =3D dev_get_drvdata(dev); + int ret; + + ret =3D mtk_mfg_power_control(mfg, false); + if (ret) { + dev_err(dev, "power_control failed: %pe\n", ERR_PTR(ret)); + return ret; + } + ret =3D mtk_mfg_eb_off(mfg); + if (ret) { + dev_err(dev, "eb_off failed: %pe\n", ERR_PTR(ret)); + return ret; + } + clk_bulk_disable_unprepare(mfg->variant->num_clks, mfg->gpu_clks); + clk_disable_unprepare(mfg->clk_eb); + ret =3D regulator_bulk_disable(mfg->variant->num_regulators, mfg->gpu_reg= s); + + return ret; +} + +static int mtk_mfg_resume(struct device *dev) +{ + struct mtk_mfg *mfg =3D dev_get_drvdata(dev); + int ret; + + ret =3D regulator_bulk_enable(mfg->variant->num_regulators, + mfg->gpu_regs); + if (ret) + return ret; + + ret =3D clk_prepare_enable(mfg->clk_eb); + if (ret) + goto err_disable_regulators; + + ret =3D clk_bulk_prepare_enable(mfg->variant->num_clks, mfg->gpu_clks); + if (ret) + goto err_disable_eb_clk; + + ret =3D mtk_mfg_eb_on(mfg); + if (ret) + goto err_disable_clks; + + ret =3D mtk_mfg_power_control(mfg, true); + if (ret) + goto err_eb_off; + + return 0; + +err_eb_off: + mtk_mfg_eb_off(mfg); +err_disable_clks: + clk_bulk_disable_unprepare(mfg->variant->num_clks, mfg->gpu_clks); +err_disable_eb_clk: + clk_disable_unprepare(mfg->clk_eb); +err_disable_regulators: + regulator_bulk_disable(mfg->variant->num_regulators, mfg->gpu_regs); + + return ret; +} + + +static DEFINE_RUNTIME_DEV_PM_OPS(mtk_mfg_pm_ops, + mtk_mfg_suspend, + mtk_mfg_resume, + NULL); + +static struct platform_driver mtk_mfg_driver =3D { + .driver =3D { + .name =3D "panthor-mtk-mfg", + .of_match_table =3D mtk_mfg_of_match, + .pm =3D pm_ptr(&mtk_mfg_pm_ops), + }, + .probe =3D mtk_mfg_probe, +}; +module_platform_driver(mtk_mfg_driver); + +MODULE_SOFTDEP("pre: panthor"); +MODULE_AUTHOR("Nicolas Frattaroli "); +MODULE_DESCRIPTION("MediaTek MFlexGraphics Extension for Panthor"); +MODULE_LICENSE("GPL"); --=20 2.51.0