From: Roman Vivchar via B4 Relay <devnull+rva333.protonmail.com@kernel.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
Roman Vivchar <rva333@protonmail.com>
Subject: [PATCH 1/3] cpufreq: mediatek: add support for CPU speedbin
Date: Wed, 23 Sep 2026 10:23:34 +0300 [thread overview]
Message-ID: <20260923-6572-cpufreq-v1-1-41f7af6d6d1a@protonmail.com> (raw)
In-Reply-To: <20260923-6572-cpufreq-v1-0-41f7af6d6d1a@protonmail.com>
From: Roman Vivchar <rva333@protonmail.com>
MediaTek SoCs are often released under the same marketing name, but with
different suffix for the speedbin. For example, mt6572m has 1 GHz limit,
mt6572a - 1.2 GHz, mt6572w - 1.4 GHz.
Add code to support per-cluster 'opp-supported-hw' property. The DT is
expected to pass a CPU speedbin using standard 'nvmem-cells' property
under the CPU node.
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
drivers/cpufreq/mediatek-cpufreq.c | 50 ++++++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 052ca7cd2f4f..f15135b2898b 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -10,6 +10,7 @@
#include <linux/cpumask.h>
#include <linux/minmax.h>
#include <linux/module.h>
+#include <linux/nvmem-consumer.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
@@ -57,6 +58,7 @@ struct mtk_cpu_dvfs_info {
const struct mtk_cpufreq_platform_data *soc_data;
int vtrack_max;
bool ccifreq_bound;
+ int opp_token;
};
static struct platform_device *cpufreq_pdev;
@@ -381,6 +383,38 @@ static struct device *of_get_cci(struct device *cpu_dev)
return &pdev->dev;
}
+static int mtk_cpu_parse_speedbin(struct mtk_cpu_dvfs_info *info, int cpu)
+{
+ struct device *cpu_dev = get_cpu_device(cpu);
+ struct dev_pm_opp_config config = {};
+ u32 val, opp_hw_ver;
+ int ret;
+
+ ret = nvmem_cell_read_variable_le_u32(cpu_dev, "speed_grade", &val);
+ if (ret) {
+ if (ret == -ENOENT)
+ /* speedbin is optional */
+ return 0;
+ return dev_err_probe(cpu_dev, ret, "cpu%d: failed to read speedbin\n", cpu);
+ }
+
+ /* Convert the raw value to a bitmask */
+ if (val >= 32)
+ return dev_err_probe(cpu_dev, -EINVAL,
+ "cpu%d: invalid speedbin value %u\n", cpu, val);
+ opp_hw_ver = BIT(val);
+
+ config.supported_hw = &opp_hw_ver;
+ config.supported_hw_count = 1;
+
+ info->opp_token = dev_pm_opp_set_config(cpu_dev, &config);
+ if (info->opp_token < 0)
+ return dev_err_probe(cpu_dev, info->opp_token,
+ "cpu%d: failed to set OPP config\n", cpu);
+
+ return 0;
+}
+
static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
{
struct device *cpu_dev;
@@ -450,18 +484,22 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
}
}
+ ret = mtk_cpu_parse_speedbin(info, cpu);
+ if (ret)
+ goto out_disable_sram_reg;
+
/* Get OPP-sharing information from "operating-points-v2" bindings */
ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, &info->cpus);
if (ret) {
dev_err_probe(cpu_dev, ret,
"cpu%d: failed to get OPP-sharing information\n", cpu);
- goto out_disable_sram_reg;
+ goto out_free_speedbin;
}
ret = dev_pm_opp_of_cpumask_add_table(&info->cpus);
if (ret) {
dev_err_probe(cpu_dev, ret, "cpu%d: no OPP table\n", cpu);
- goto out_disable_sram_reg;
+ goto out_free_speedbin;
}
ret = clk_prepare_enable(info->cpu_clk);
@@ -533,6 +571,10 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
out_free_opp_table:
dev_pm_opp_of_cpumask_remove_table(&info->cpus);
+out_free_speedbin:
+ if (info->opp_token > 0)
+ dev_pm_opp_clear_config(info->opp_token);
+
out_disable_sram_reg:
if (info->sram_reg)
regulator_disable(info->sram_reg);
@@ -573,6 +615,10 @@ static void mtk_cpu_dvfs_info_release(struct mtk_cpu_dvfs_info *info)
clk_disable_unprepare(info->inter_clk);
clk_put(info->inter_clk);
dev_pm_opp_of_cpumask_remove_table(&info->cpus);
+
+ if (info->opp_token > 0)
+ dev_pm_opp_clear_config(info->opp_token);
+
dev_pm_opp_unregister_notifier(info->cpu_dev, &info->opp_nb);
if (info->soc_data->ccifreq_supported)
put_device(info->cci_dev);
--
2.55.0
next prev parent reply other threads:[~2026-09-23 7:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 7:23 [PATCH 0/3] cpufreq: mediatek: add mt6572 support Roman Vivchar via B4 Relay
2026-09-23 7:23 ` Roman Vivchar via B4 Relay [this message]
2026-09-23 8:31 ` [PATCH 1/3] cpufreq: mediatek: add support for CPU speedbin AngeloGioacchino Del Regno
2026-09-23 8:55 ` Roman Vivchar
2026-09-23 7:23 ` [PATCH 2/3] cpufreq: mediatek: add mt6572 support Roman Vivchar via B4 Relay
2026-09-23 8:36 ` AngeloGioacchino Del Regno
2026-09-23 8:58 ` Roman Vivchar
2026-09-23 7:23 ` [PATCH 3/3] cpufreq: dt-platdev: block the driver from probing on MediaTek mt6572 Roman Vivchar via B4 Relay
2026-09-23 8:36 ` AngeloGioacchino Del Regno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260923-6572-cpufreq-v1-1-41f7af6d6d1a@protonmail.com \
--to=devnull+rva333.protonmail.com@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=rafael@kernel.org \
--cc=rva333@protonmail.com \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox