blob: 032d1632e2ba0c6b5aabcbd103c9246511c84e6d [file] [log] [blame]
developer5d148cb2023-06-02 13:08:11 +08001From 96af4d1381b43bafba252d38c2a344f1011de638 Mon Sep 17 00:00:00 2001
2From: Sam Shih <sam.shih@mediatek.com>
3Date: Fri, 2 Jun 2023 13:06:23 +0800
4Subject: [PATCH]
5 [adv-feature][999-2503-cpufreq-mtk-vbining-add-mt7988-support.patch]
6
7---
8 drivers/cpufreq/mediatek-cpufreq.c | 22 ++++++++++++++++++++++
9 1 file changed, 22 insertions(+)
10
developer2cdaeb12022-10-04 20:25:05 +080011diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
developer5d148cb2023-06-02 13:08:11 +080012index b23b6d2b4..c22945100 100644
developer2cdaeb12022-10-04 20:25:05 +080013--- a/drivers/cpufreq/mediatek-cpufreq.c
14+++ b/drivers/cpufreq/mediatek-cpufreq.c
15@@ -15,6 +15,7 @@
16 #include <linux/regulator/consumer.h>
17 #include <linux/slab.h>
18 #include <linux/thermal.h>
19+#include <linux/nvmem-consumer.h>
20
21 #define MIN_VOLT_SHIFT (100000)
22 #define MAX_VOLT_SHIFT (200000)
23@@ -539,6 +540,11 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
24 struct mtk_cpu_dvfs_info *info;
25 struct cpufreq_frequency_table *freq_table;
26 int ret;
27+ int target_vproc;
developer59515632022-10-15 16:55:26 +080028+ u8 reg_val;
developer2cdaeb12022-10-04 20:25:05 +080029+ struct nvmem_cell *cell;
30+ size_t len;
developer59515632022-10-15 16:55:26 +080031+ u8 *buf;
developer2cdaeb12022-10-04 20:25:05 +080032
33 info = mtk_cpu_dvfs_info_lookup(policy->cpu);
34 if (!info) {
35@@ -547,6 +553,22 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
36 return -EINVAL;
37 }
38
39+ cell = nvmem_cell_get(info->cpu_dev, "calibration-data");
40+ if (!IS_ERR(cell)) {
developer59515632022-10-15 16:55:26 +080041+ buf = (u8 *)nvmem_cell_read(cell, &len);
developer2cdaeb12022-10-04 20:25:05 +080042+ nvmem_cell_put(cell);
43+ if (!IS_ERR(buf)) {
44+ reg_val = buf[0] & 0x1f;
45+ pr_debug("%s: read vbinning value: %d\n", __func__, reg_val);
46+ if (reg_val > 0) {
47+ target_vproc = 850000 + reg_val * 10000;
48+ dev_pm_opp_remove(info->cpu_dev, 1800000000);
49+ dev_pm_opp_add(info->cpu_dev, 1800000000, target_vproc);
50+ }
51+ kfree(buf);
52+ }
53+ }
54+
55 ret = dev_pm_opp_init_cpufreq_table(info->cpu_dev, &freq_table);
56 if (ret) {
57 pr_err("failed to init cpufreq table for cpu%d: %d\n",
developer5d148cb2023-06-02 13:08:11 +080058--
592.34.1
60