From nobody Mon Oct 6 20:59:23 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 5371E27F006; Wed, 16 Jul 2025 17:51:48 +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=1752688309; cv=pass; b=h/etU8UIoZdC8PAWRjTsFtuMvthOD72i3JYH2NFIY8h17vZMcGVlCN2aHZe1FGWnq6YRwImQsQot9Uqea61CeS8BsgviSOf+IeZNBjzKmaXbcfyYabhmG4u0Nbdlv862WZqumD1GDD7BMgGT1CHcraP4ohB8DPmjWQ7Cjh1kEOc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752688309; c=relaxed/simple; bh=n8eTmJHFPK+87Ro15/PECQdlwAnPjm6LOtCx/hHBK1s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O9q8bDEfvO1X25dZqOrSWykVrWasHxMV8s/nfZh3S4OPE4zchZMfj4ZMm4y6uifUg08jwVtuq/HrA8vlFTMNKR4NcSXEnsBnVyLFusSwaQ+xySmHg3yAEZczhfRV2OojEbrq2nR8dQ0SPJqBZ1T6PdURgBdSczkwDUtutf4WsQY= 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=Rjqul+t8; 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="Rjqul+t8" ARC-Seal: i=1; a=rsa-sha256; t=1752688291; cv=none; d=zohomail.com; s=zohoarc; b=bPRBQxPfnwzs1gjZA3GgAFdfwbegJ17WohAHpaWx7n5firjUOwZjudlgjU/kganPPPpTd3Oojxsk5Us5XvEaWs0pScWv2mzGJHvuq2ilKkSrH0FwWjGwvchbWUFKQ3yivyrSbX7hU/hlSaRHCXvYtUmFK0tDdaIE1UQPHk1EKNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752688291; 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=3+1vi8bZzQ07I9vWMHC48+ZnxZElk7NeHkY4J8vrkhM=; b=Yr3GeeYhK+9QsDs+MitvcYMFj4OBBiW27xK9Tjc9wxMJM4Uf5pDh8EkTr46UHuHyCM2Rf300y5SKY9CVFGxupbzSVYVsZyX1Jo0RQw5FSfO/8uNTMRilWoGalqoHbBLuPZVN7wKOO+sGra/c/f+v5+nfCl5sNZBLAD3AIlfmuVM= 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=1752688291; 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=3+1vi8bZzQ07I9vWMHC48+ZnxZElk7NeHkY4J8vrkhM=; b=Rjqul+t8exoR/AN8FvRtQnmIckb7djHzQdpCNdZfetUdtV92ecDRruyBxC1pYJ89 PDthIhpOz1bTDcH7sSwUls7roS4NK9CPZPSoFT3X10s6jmuK4phUVGwm7ofnPRrSawZ ryw+EqAwn8Pv/IHYHYhUMVJE4sOiL1nblSma5EBY= Received: by mx.zohomail.com with SMTPS id 1752688289851648.2288655206119; Wed, 16 Jul 2025 10:51:29 -0700 (PDT) From: Nicolas Frattaroli Date: Wed, 16 Jul 2025 19:51:22 +0200 Subject: [PATCH v3 1/4] dt-bindings: cpufreq: Add mediatek,mt8196-cpufreq-hw 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: <20250716-mt8196-cpufreq-v3-1-d440fb810d7e@collabora.com> References: <20250716-mt8196-cpufreq-v3-0-d440fb810d7e@collabora.com> In-Reply-To: <20250716-mt8196-cpufreq-v3-0-d440fb810d7e@collabora.com> To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: kernel@collabora.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 The MediaTek MT8196 SoC has new cpufreq hardware, with added memory register ranges to control Dynamic-Voltage-Frequency-Scaling. The DVFS hardware is controlled through a set of registers referred to as "FDVFS". They set the target frequency the DVFS hardware should aim for for each performance domain. Instead of working around the old binding and its already established meanings for the reg items, add a new binding. The FDVFS register memory region is at the beginning, which allows us to easily expand this binding for future SoCs which may have more than 3 performance domains. Signed-off-by: Nicolas Frattaroli Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Rob Herring (Arm) --- .../cpufreq/mediatek,mt8196-cpufreq-hw.yaml | 82 ++++++++++++++++++= ++++ 1 file changed, 82 insertions(+) diff --git a/Documentation/devicetree/bindings/cpufreq/mediatek,mt8196-cpuf= req-hw.yaml b/Documentation/devicetree/bindings/cpufreq/mediatek,mt8196-cpu= freq-hw.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5f3c7db3f3aa0abf90061b2d735= f975135cb35eb --- /dev/null +++ b/Documentation/devicetree/bindings/cpufreq/mediatek,mt8196-cpufreq-hw.= yaml @@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/cpufreq/mediatek,mt8196-cpufreq-hw.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek Hybrid CPUFreq for MT8196/MT6991 series SoCs + +maintainers: + - Nicolas Frattaroli + +description: + MT8196 uses CPUFreq management hardware that supports dynamic voltage + frequency scaling (dvfs), and can support several performance domains. + +properties: + compatible: + const: mediatek,mt8196-cpufreq-hw + + reg: + items: + - description: FDVFS control register region + - description: OPP tables and control for performance domain 0 + - description: OPP tables and control for performance domain 1 + - description: OPP tables and control for performance domain 2 + + "#performance-domain-cells": + const: 1 + +required: + - compatible + - reg + - "#performance-domain-cells" + +additionalProperties: false + +examples: + - | + cpus { + #address-cells =3D <1>; + #size-cells =3D <0>; + + cpu0: cpu@0 { + device_type =3D "cpu"; + compatible =3D "arm,cortex-a720"; + enable-method =3D "psci"; + performance-domains =3D <&performance 0>; + reg =3D <0x000>; + }; + + /* ... */ + + cpu6: cpu@600 { + device_type =3D "cpu"; + compatible =3D "arm,cortex-x4"; + enable-method =3D "psci"; + performance-domains =3D <&performance 1>; + reg =3D <0x600>; + }; + + cpu7: cpu@700 { + device_type =3D "cpu"; + compatible =3D "arm,cortex-x925"; + enable-method =3D "psci"; + performance-domains =3D <&performance 2>; + reg =3D <0x700>; + }; + }; + + /* ... */ + + soc { + #address-cells =3D <2>; + #size-cells =3D <2>; + + performance: performance-controller@c2c2034 { + compatible =3D "mediatek,mt8196-cpufreq-hw"; + reg =3D <0 0xc220400 0 0x20>, <0 0xc2c0f20 0 0x120>, + <0 0xc2c1040 0 0x120>, <0 0xc2c1160 0 0x120>; + #performance-domain-cells =3D <1>; + }; + }; --=20 2.50.1 From nobody Mon Oct 6 20:59:23 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 5BA53286D79; Wed, 16 Jul 2025 17:51:52 +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=1752688313; cv=pass; b=iLP/lx8TPmZToKRhrb/aTw533Cd/ZNYRUJDPiYimCqmuXBHwB8pZSLPMMoLzaf4nk92ZuyDbFQRvrWtJtDEcEJyBPO8EVavjgBGbdJ2GYhGtqRu0mkSkkqJeFoqxXxhyrkPWAxlNlP+yyt9UuzKhaX++I9mf0Ph66UNpGjSvSKo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752688313; c=relaxed/simple; bh=G3Pq16KWHuxCbAF/LJJ13waONyJ/abmpxN6LFPOa1FU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X5dcMetMjQlnUY2v/Tfd1TVFKTyVHBsXl2s2DZYTQf7+6D8RAGi1xvvVxFeWACOD5VsaWGi8QcSWY7p0BoiOryMywlPfkU8ZsEOUMESRRbxq2fcE6tglisID/AGhMmit6nDh6SbuqqDakKJRRdcdWUQ9eERNf660yMUlHcOOVl0= 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=IMgcm7ZO; 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="IMgcm7ZO" ARC-Seal: i=1; a=rsa-sha256; t=1752688295; cv=none; d=zohomail.com; s=zohoarc; b=MeXqvEeEGB8Xf2pj+MTOTQQcWskKvwobxhUK6KHJwVg72M3EtBc9fsLbxpthwr0B+L+3Ker2zkGRx8sH5r24PNd9vrgZH0uho/WHFlszFemsstGI8Fmx5VEU8Q4iPob9x3SHUrQq57smfaTZHTvyOWNEGgWheCWPUkADwZZwWPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752688295; 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=CFeYngD4ucIt7AO/MWX4ZQHUevaFxkhqhnDYFChGYVQ=; b=mRMFHo7UxlZfPPBKFgsYWW59IzoMgOKLC4jaHqVlL7OyGq7jeMcUrrXY+CcXluIbfGSh5VxyiSezKoW63rqIyCNJKoS9O8uo68zjYqN4B1QRFWnJmm4aoxnEZJyVkfQ8sk/OeAPhQuSlcwbvp8YlZbsRYmFvbF0GhDokL8vkAAQ= 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=1752688295; 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=CFeYngD4ucIt7AO/MWX4ZQHUevaFxkhqhnDYFChGYVQ=; b=IMgcm7ZOsOXScxrQ6/9XkrD74GRW1FQUOTR7mRTC1YlsEQnYeOaGyJ2CC7k3d8Sh 25K7l4+8jjxcluEq736lz++Jhvhxfkzsoko9j0pAAXb3Mlc14kg5WZhLZ738v7x+Y24 7hV0TlyK5KMwnARLmgE6BXrNQqxrl3S4plA/ApPw= Received: by mx.zohomail.com with SMTPS id 1752688292890516.4771910859703; Wed, 16 Jul 2025 10:51:32 -0700 (PDT) From: Nicolas Frattaroli Date: Wed, 16 Jul 2025 19:51:23 +0200 Subject: [PATCH v3 2/4] cpufreq: mediatek-hw: Refactor match data into struct 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: <20250716-mt8196-cpufreq-v3-2-d440fb810d7e@collabora.com> References: <20250716-mt8196-cpufreq-v3-0-d440fb810d7e@collabora.com> In-Reply-To: <20250716-mt8196-cpufreq-v3-0-d440fb810d7e@collabora.com> To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: kernel@collabora.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 While the driver could get away with having the per-compatible match data just be an array of the reg offsets, the only thing it used it for right now, this doesn't really allow it to be extended in any meaningful way if some other per-variant information needs to be communicated. In preparation of adding support for hybrid "FDVFS" for MT8196, refactor the code to make the DT match data a struct, which currently only contains a single member: the reg offsets. This will allow this struct to be extended with other members for other hardware variants. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Nicolas Frattaroli --- drivers/cpufreq/mediatek-cpufreq-hw.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediat= ek-cpufreq-hw.c index 74f1b4c796e4cc9ebccf50dd4e165a1eba03136a..b2aba1842226c7d24a8b9599ea6= 2408cac9f803c 100644 --- a/drivers/cpufreq/mediatek-cpufreq-hw.c +++ b/drivers/cpufreq/mediatek-cpufreq-hw.c @@ -41,15 +41,22 @@ struct mtk_cpufreq_data { struct resource *res; void __iomem *base; int nr_opp; + const struct mtk_cpufreq_variant *variant; }; =20 -static const u16 cpufreq_mtk_offsets[REG_ARRAY_SIZE] =3D { - [REG_FREQ_LUT_TABLE] =3D 0x0, - [REG_FREQ_ENABLE] =3D 0x84, - [REG_FREQ_PERF_STATE] =3D 0x88, - [REG_FREQ_HW_STATE] =3D 0x8c, - [REG_EM_POWER_TBL] =3D 0x90, - [REG_FREQ_LATENCY] =3D 0x110, +struct mtk_cpufreq_variant { + const u16 reg_offsets[REG_ARRAY_SIZE]; +}; + +static const struct mtk_cpufreq_variant cpufreq_mtk_base_variant =3D { + .reg_offsets =3D { + [REG_FREQ_LUT_TABLE] =3D 0x0, + [REG_FREQ_ENABLE] =3D 0x84, + [REG_FREQ_PERF_STATE] =3D 0x88, + [REG_FREQ_HW_STATE] =3D 0x8c, + [REG_EM_POWER_TBL] =3D 0x90, + [REG_FREQ_LATENCY] =3D 0x110, + }, }; =20 static int __maybe_unused @@ -157,7 +164,7 @@ static int mtk_cpu_create_freq_table(struct platform_de= vice *pdev, =20 static int mtk_cpu_resources_init(struct platform_device *pdev, struct cpufreq_policy *policy, - const u16 *offsets) + const struct mtk_cpufreq_variant *variant) { struct mtk_cpufreq_data *data; struct device *dev =3D &pdev->dev; @@ -200,9 +207,10 @@ static int mtk_cpu_resources_init(struct platform_devi= ce *pdev, =20 data->base =3D base; data->res =3D res; + data->variant =3D variant; =20 for (i =3D REG_FREQ_LUT_TABLE; i < REG_ARRAY_SIZE; i++) - data->reg_bases[i] =3D base + offsets[i]; + data->reg_bases[i] =3D base + variant->reg_offsets[i]; =20 ret =3D mtk_cpu_create_freq_table(pdev, data); if (ret) { @@ -336,7 +344,7 @@ static void mtk_cpufreq_hw_driver_remove(struct platfor= m_device *pdev) } =20 static const struct of_device_id mtk_cpufreq_hw_match[] =3D { - { .compatible =3D "mediatek,cpufreq-hw", .data =3D &cpufreq_mtk_offsets }, + { .compatible =3D "mediatek,cpufreq-hw", .data =3D &cpufreq_mtk_base_vari= ant }, {} }; MODULE_DEVICE_TABLE(of, mtk_cpufreq_hw_match); --=20 2.50.1 From nobody Mon Oct 6 20:59:23 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 B0B072877C6; Wed, 16 Jul 2025 17:51:54 +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=1752688316; cv=pass; b=c5xroicEQTjEjMzeAaP2fyOjnxrTipdKgx8WdP1O9FJfKEVgNvFpiAOKuCqJp8Bp9qMtIT0ce46ABmBzIvpAdHJ/POvowQYlmwRqgaV6KwE7nmUbet/ltt67bTe/Gbo4qunNQCmQPXoHwoDrTrF5YD3P/LkzTXH/el8APvws3qA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752688316; c=relaxed/simple; bh=5OQkitAGg+k7nSDDrqr03IxG5f7jNWoM9K1kF964i7k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=osONIEu1AC5Tn+ZYFgJX+xYx/tH/+XPEY5qEg0/di6UBlOt0Q/GHRr4Wzc39t8k7xVPzQthVvkqsXMu5+6NPKKyLZuaIz8TfATmZGtpV6K3IBZVP9aNyC4Je5eScZG6zvzPXObTZDpohJmAlBvlgBjQIcid7fCutOg8A9D7rFKo= 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=lbMiQh6M; 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="lbMiQh6M" ARC-Seal: i=1; a=rsa-sha256; t=1752688297; cv=none; d=zohomail.com; s=zohoarc; b=G0ZVQLmEjkD6RWaQuiZkSKkAb2oK6LuRwgmw1OkyBpjBYMbQXylayjUrybvwSF22//ADr9L6xHGUfkAbDaxDiZhnthQojWufbcUSHfAgGvQG4klY/5dMfo30w9zj2nId4FWR4HOf7ljinlMCYoLwgnVQ+XdXJd14toxJQxr2MtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752688297; 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=9RbBMJlOK/zToyiZFpQ4ckPXM32zr8GURxpNMWtjxWY=; b=hczvp1EvUIT/OJbJxeXap1mi0BfQp9c+PqEQWuSAHLd3mbsdxCWmkOP+ypmuLPBuNhv3Rdsn1CgRVm+SCNhJYpoX+8UNVKU2poKG/mBFNrKdM6TKkbajJcOaktxX71Hfp5/9qFUl8O89cy5FRVk/txPXmclnVIvpXxqdgw12fQM= 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=1752688297; 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=9RbBMJlOK/zToyiZFpQ4ckPXM32zr8GURxpNMWtjxWY=; b=lbMiQh6M6ZM8czBvvyne3yg9vXkXEzhahxJvzbJvovdoOWr/ENjbwiqNSPH3MAjU dZF6g9nfg/yv1cCSillA6KeIscRvp6uol/EhlJMvsPOVYSYrfmcULR0NCAlHuEmwS+C k1vdKXMvacQJJRDNCzpQ3HV9/Arnv3SNk9USfyxQ= Received: by mx.zohomail.com with SMTPS id 1752688295860303.6109821929474; Wed, 16 Jul 2025 10:51:35 -0700 (PDT) From: Nicolas Frattaroli Date: Wed, 16 Jul 2025 19:51:24 +0200 Subject: [PATCH v3 3/4] cpufreq: mediatek-hw: Separate per-domain and per-instance data 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: <20250716-mt8196-cpufreq-v3-3-d440fb810d7e@collabora.com> References: <20250716-mt8196-cpufreq-v3-0-d440fb810d7e@collabora.com> In-Reply-To: <20250716-mt8196-cpufreq-v3-0-d440fb810d7e@collabora.com> To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: kernel@collabora.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 As it stood, the mediatek cpufreq driver could get away with never really having a private driver instance struct. This is because all data was stored in the per-domain structs. However, this complicates matters when actual per-instance data like the variant struct is introduced. Instead of having a pointer to it for every domain, have a pointer to a global "priv" struct that can be extended over time, and rename the "data" struct to "domain" to distinguish its purpose better. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Nicolas Frattaroli --- drivers/cpufreq/mediatek-cpufreq-hw.c | 42 ++++++++++++++++++++++---------= ---- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediat= ek-cpufreq-hw.c index b2aba1842226c7d24a8b9599ea62408cac9f803c..53611077d0d9a2d9865cf771568= ab71abc0e6fbd 100644 --- a/drivers/cpufreq/mediatek-cpufreq-hw.c +++ b/drivers/cpufreq/mediatek-cpufreq-hw.c @@ -35,13 +35,17 @@ enum { REG_ARRAY_SIZE, }; =20 -struct mtk_cpufreq_data { +struct mtk_cpufreq_priv { + const struct mtk_cpufreq_variant *variant; +}; + +struct mtk_cpufreq_domain { + struct mtk_cpufreq_priv *parent; struct cpufreq_frequency_table *table; void __iomem *reg_bases[REG_ARRAY_SIZE]; struct resource *res; void __iomem *base; int nr_opp; - const struct mtk_cpufreq_variant *variant; }; =20 struct mtk_cpufreq_variant { @@ -63,7 +67,7 @@ static int __maybe_unused mtk_cpufreq_get_cpu_power(struct device *cpu_dev, unsigned long *uW, unsigned long *KHz) { - struct mtk_cpufreq_data *data; + struct mtk_cpufreq_domain *data; struct cpufreq_policy *policy; int i; =20 @@ -90,7 +94,7 @@ mtk_cpufreq_get_cpu_power(struct device *cpu_dev, unsigne= d long *uW, static int mtk_cpufreq_hw_target_index(struct cpufreq_policy *policy, unsigned int index) { - struct mtk_cpufreq_data *data =3D policy->driver_data; + struct mtk_cpufreq_domain *data =3D policy->driver_data; =20 writel_relaxed(index, data->reg_bases[REG_FREQ_PERF_STATE]); =20 @@ -99,7 +103,7 @@ static int mtk_cpufreq_hw_target_index(struct cpufreq_po= licy *policy, =20 static unsigned int mtk_cpufreq_hw_get(unsigned int cpu) { - struct mtk_cpufreq_data *data; + struct mtk_cpufreq_domain *data; struct cpufreq_policy *policy; unsigned int index; =20 @@ -118,7 +122,7 @@ static unsigned int mtk_cpufreq_hw_get(unsigned int cpu) static unsigned int mtk_cpufreq_hw_fast_switch(struct cpufreq_policy *poli= cy, unsigned int target_freq) { - struct mtk_cpufreq_data *data =3D policy->driver_data; + struct mtk_cpufreq_domain *data =3D policy->driver_data; unsigned int index; =20 index =3D cpufreq_table_find_index_dl(policy, target_freq, false); @@ -129,7 +133,7 @@ static unsigned int mtk_cpufreq_hw_fast_switch(struct c= pufreq_policy *policy, } =20 static int mtk_cpu_create_freq_table(struct platform_device *pdev, - struct mtk_cpufreq_data *data) + struct mtk_cpufreq_domain *data) { struct device *dev =3D &pdev->dev; u32 temp, i, freq, prev_freq =3D 0; @@ -164,9 +168,9 @@ static int mtk_cpu_create_freq_table(struct platform_de= vice *pdev, =20 static int mtk_cpu_resources_init(struct platform_device *pdev, struct cpufreq_policy *policy, - const struct mtk_cpufreq_variant *variant) + struct mtk_cpufreq_priv *priv) { - struct mtk_cpufreq_data *data; + struct mtk_cpufreq_domain *data; struct device *dev =3D &pdev->dev; struct resource *res; struct of_phandle_args args; @@ -187,6 +191,8 @@ static int mtk_cpu_resources_init(struct platform_devic= e *pdev, index =3D args.args[0]; of_node_put(args.np); =20 + data->parent =3D priv; + res =3D platform_get_resource(pdev, IORESOURCE_MEM, index); if (!res) { dev_err(dev, "failed to get mem resource %d\n", index); @@ -207,10 +213,9 @@ static int mtk_cpu_resources_init(struct platform_devi= ce *pdev, =20 data->base =3D base; data->res =3D res; - data->variant =3D variant; =20 for (i =3D REG_FREQ_LUT_TABLE; i < REG_ARRAY_SIZE; i++) - data->reg_bases[i] =3D base + variant->reg_offsets[i]; + data->reg_bases[i] =3D base + priv->variant->reg_offsets[i]; =20 ret =3D mtk_cpu_create_freq_table(pdev, data); if (ret) { @@ -231,7 +236,7 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_polic= y *policy) { struct platform_device *pdev =3D cpufreq_get_driver_data(); int sig, pwr_hw =3D CPUFREQ_HW_STATUS | SVS_HW_STATUS; - struct mtk_cpufreq_data *data; + struct mtk_cpufreq_domain *data; unsigned int latency; int ret; =20 @@ -270,7 +275,7 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_polic= y *policy) =20 static void mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) { - struct mtk_cpufreq_data *data =3D policy->driver_data; + struct mtk_cpufreq_domain *data =3D policy->driver_data; struct resource *res =3D data->res; void __iomem *base =3D data->base; =20 @@ -283,7 +288,7 @@ static void mtk_cpufreq_hw_cpu_exit(struct cpufreq_poli= cy *policy) static void mtk_cpufreq_register_em(struct cpufreq_policy *policy) { struct em_data_callback em_cb =3D EM_DATA_CB(mtk_cpufreq_get_cpu_power); - struct mtk_cpufreq_data *data =3D policy->driver_data; + struct mtk_cpufreq_domain *data =3D policy->driver_data; =20 em_dev_register_perf_domain(get_cpu_device(policy->cpu), data->nr_opp, &em_cb, policy->cpus, true); @@ -305,6 +310,7 @@ static struct cpufreq_driver cpufreq_mtk_hw_driver =3D { =20 static int mtk_cpufreq_hw_driver_probe(struct platform_device *pdev) { + struct mtk_cpufreq_priv *priv; const void *data; int ret, cpu; struct device *cpu_dev; @@ -328,7 +334,13 @@ static int mtk_cpufreq_hw_driver_probe(struct platform= _device *pdev) if (!data) return -EINVAL; =20 - platform_set_drvdata(pdev, (void *) data); + priv =3D devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->variant =3D data; + + platform_set_drvdata(pdev, priv); cpufreq_mtk_hw_driver.driver_data =3D pdev; =20 ret =3D cpufreq_register_driver(&cpufreq_mtk_hw_driver); --=20 2.50.1 From nobody Mon Oct 6 20:59:23 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 767C428852E; Wed, 16 Jul 2025 17:51:57 +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=1752688319; cv=pass; b=fWLPaW1caR9rsRcbSf/23r/5lLZC65jN4TPWbf9N2b/TIWIO8Pgonvn0kUQrz4AZL7fiNPRvC240hLPZrFs+1iF0NbNLDZJB/X2zEun6cP/fxYNkAGO2ut0c30TIxRo85KGlWUQz/NgeFJrwyexVkWUvh8X1rcnOxolCCalTih4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752688319; c=relaxed/simple; bh=2v3neK4iFC1rT0Q8CInwOC6/+wtUhMCpMwGN7hpoG2E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qBXJTubVvQaaemLjUVe877io09wvtLqnOWDAW2I09oN2D8FGxTAgkPWFXWZB0tKjl4SMPmTIQQYqIL1bN+toZcu0YSgpQ9vhcs0l7nKiOi78nuRfmVGR2EKs3EH0h9EsPqUfM8JChBr8WuzvxIIJ1wYtHyTOVNCmeE6x6d1OEjU= 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=gWiklzTT; 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="gWiklzTT" ARC-Seal: i=1; a=rsa-sha256; t=1752688301; cv=none; d=zohomail.com; s=zohoarc; b=CtcKNsRyUYAYob24gMiwY9gbf6Yw6RRUQE8Znuw7AkeW8muiVXufnUKBU85GhuC/oX25AQ1oievNFc/0nA4ALDmWraISgGEH+uEyIlXezGaewsLKWgMXXqxrxbs6wyA2T47I7HIRGQI8EMr8t9ahlO8zxj5Si0hKwqOZ/ddeMvE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752688301; 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=FdTJy+hTnMMhv0ByE1VmAHdLgDhK3u720le2ZYwEYBw=; b=IhziMyv7PyefgE9/vnV5QMwXqNr0mPA6JpzJCVd1zTKan8YkJX7lmsQuFNTV0rkBZuJXWvncY2SrRLlUuuBRiYpCoFFKF5L0uLI04qvMW7r6j9mgDKKzUtmtXG7FmTUypEKHbdLhykvoQtuo27h89SE2mTrORPZgiJFSivDoKk4= 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=1752688301; 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=FdTJy+hTnMMhv0ByE1VmAHdLgDhK3u720le2ZYwEYBw=; b=gWiklzTT/L2buszEqg82HEr2Tvq4XxrfahjOjVz6RnRdVlAyHwqDj8nuK2KOOhEa pb2js1DyKcjkCm2PDx+nAG4uulqwMHhcvoLf/H2m0T9xL2z3il+sYqTC7xn3URJPZcZ rOYhK+xLU3rn9Zkx5VeAjIfF2zouGFJltEpSACpw= Received: by mx.zohomail.com with SMTPS id 175268829909280.288096823606; Wed, 16 Jul 2025 10:51:39 -0700 (PDT) From: Nicolas Frattaroli Date: Wed, 16 Jul 2025 19:51:25 +0200 Subject: [PATCH v3 4/4] cpufreq: mediatek-hw: Add support for MT8196 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: <20250716-mt8196-cpufreq-v3-4-d440fb810d7e@collabora.com> References: <20250716-mt8196-cpufreq-v3-0-d440fb810d7e@collabora.com> In-Reply-To: <20250716-mt8196-cpufreq-v3-0-d440fb810d7e@collabora.com> To: "Rafael J. Wysocki" , Viresh Kumar , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: kernel@collabora.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 The MT8196 SoC uses DVFS to set a desired target frequency for each CPU core. It also uses slightly different register offsets. Add support for it, which necessitates reworking how the mmio regs are acquired, as mt8196 has the fdvfs register before the performance domain registers. I've verified with both `sysbench cpu run` and `head -c 10G \ /dev/urandom | pigz -p 8 -c - | pv -ba > /dev/null` that we don't just get a higher reported clock frequency, but that the observed performance also increases, by a factor of 2.64 in an 8 thread sysbench test. Signed-off-by: Nicolas Frattaroli Reviewed-by: AngeloGioacchino Del Regno --- drivers/cpufreq/mediatek-cpufreq-hw.c | 70 +++++++++++++++++++++++++++++++= +++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediat= ek-cpufreq-hw.c index 53611077d0d9a2d9865cf771568ab71abc0e6fbd..e4eadce6f937ceff51b34d22da8= 3c51b4e9aa813 100644 --- a/drivers/cpufreq/mediatek-cpufreq-hw.c +++ b/drivers/cpufreq/mediatek-cpufreq-hw.c @@ -24,6 +24,8 @@ #define POLL_USEC 1000 #define TIMEOUT_USEC 300000 =20 +#define FDVFS_FDIV_HZ (26 * 1000) + enum { REG_FREQ_LUT_TABLE, REG_FREQ_ENABLE, @@ -36,7 +38,9 @@ enum { }; =20 struct mtk_cpufreq_priv { + struct device *dev; const struct mtk_cpufreq_variant *variant; + void __iomem *fdvfs; }; =20 struct mtk_cpufreq_domain { @@ -49,7 +53,9 @@ struct mtk_cpufreq_domain { }; =20 struct mtk_cpufreq_variant { + int (*init)(struct mtk_cpufreq_priv *priv); const u16 reg_offsets[REG_ARRAY_SIZE]; + const bool is_hybrid_dvfs; }; =20 static const struct mtk_cpufreq_variant cpufreq_mtk_base_variant =3D { @@ -63,6 +69,29 @@ static const struct mtk_cpufreq_variant cpufreq_mtk_base= _variant =3D { }, }; =20 +static int mtk_cpufreq_hw_mt8196_init(struct mtk_cpufreq_priv *priv) +{ + priv->fdvfs =3D devm_of_iomap(priv->dev, priv->dev->of_node, 0, NULL); + if (IS_ERR_OR_NULL(priv->fdvfs)) + return dev_err_probe(priv->dev, PTR_ERR(priv->fdvfs), + "failed to get fdvfs iomem\n"); + + return 0; +} + +static const struct mtk_cpufreq_variant cpufreq_mtk_mt8196_variant =3D { + .init =3D mtk_cpufreq_hw_mt8196_init, + .reg_offsets =3D { + [REG_FREQ_LUT_TABLE] =3D 0x0, + [REG_FREQ_ENABLE] =3D 0x84, + [REG_FREQ_PERF_STATE] =3D 0x88, + [REG_FREQ_HW_STATE] =3D 0x8c, + [REG_EM_POWER_TBL] =3D 0x90, + [REG_FREQ_LATENCY] =3D 0x114, + }, + .is_hybrid_dvfs =3D true, +}; + static int __maybe_unused mtk_cpufreq_get_cpu_power(struct device *cpu_dev, unsigned long *uW, unsigned long *KHz) @@ -91,12 +120,31 @@ mtk_cpufreq_get_cpu_power(struct device *cpu_dev, unsi= gned long *uW, return 0; } =20 +static void mtk_cpufreq_hw_fdvfs_switch(unsigned int target_freq, + struct cpufreq_policy *policy) +{ + struct mtk_cpufreq_domain *data =3D policy->driver_data; + struct mtk_cpufreq_priv *priv =3D data->parent; + unsigned int cpu; + + target_freq =3D DIV_ROUND_UP(target_freq, FDVFS_FDIV_HZ); + for_each_cpu(cpu, policy->real_cpus) { + writel_relaxed(target_freq, priv->fdvfs + cpu * 4); + } +} + static int mtk_cpufreq_hw_target_index(struct cpufreq_policy *policy, unsigned int index) { struct mtk_cpufreq_domain *data =3D policy->driver_data; + unsigned int target_freq; =20 - writel_relaxed(index, data->reg_bases[REG_FREQ_PERF_STATE]); + if (data->parent->fdvfs) { + target_freq =3D policy->freq_table[index].frequency; + mtk_cpufreq_hw_fdvfs_switch(target_freq, policy); + } else { + writel_relaxed(index, data->reg_bases[REG_FREQ_PERF_STATE]); + } =20 return 0; } @@ -127,7 +175,10 @@ static unsigned int mtk_cpufreq_hw_fast_switch(struct = cpufreq_policy *policy, =20 index =3D cpufreq_table_find_index_dl(policy, target_freq, false); =20 - writel_relaxed(index, data->reg_bases[REG_FREQ_PERF_STATE]); + if (data->parent->fdvfs) + mtk_cpufreq_hw_fdvfs_switch(target_freq, policy); + else + writel_relaxed(index, data->reg_bases[REG_FREQ_PERF_STATE]); =20 return policy->freq_table[index].frequency; } @@ -191,6 +242,13 @@ static int mtk_cpu_resources_init(struct platform_devi= ce *pdev, index =3D args.args[0]; of_node_put(args.np); =20 + /* + * In a cpufreq with hybrid DVFS, such as the MT8196, the first declared + * register range is for FDVFS, followed by the frequency domain MMIOs. + */ + if (priv->variant->is_hybrid_dvfs) + index++; + data->parent =3D priv; =20 res =3D platform_get_resource(pdev, IORESOURCE_MEM, index); @@ -339,6 +397,13 @@ static int mtk_cpufreq_hw_driver_probe(struct platform= _device *pdev) return -ENOMEM; =20 priv->variant =3D data; + priv->dev =3D &pdev->dev; + + if (priv->variant->init) { + ret =3D priv->variant->init(priv); + if (ret) + return ret; + } =20 platform_set_drvdata(pdev, priv); cpufreq_mtk_hw_driver.driver_data =3D pdev; @@ -357,6 +422,7 @@ static void mtk_cpufreq_hw_driver_remove(struct platfor= m_device *pdev) =20 static const struct of_device_id mtk_cpufreq_hw_match[] =3D { { .compatible =3D "mediatek,cpufreq-hw", .data =3D &cpufreq_mtk_base_vari= ant }, + { .compatible =3D "mediatek,mt8196-cpufreq-hw", .data =3D &cpufreq_mtk_mt= 8196_variant }, {} }; MODULE_DEVICE_TABLE(of, mtk_cpufreq_hw_match); --=20 2.50.1