1 From be2354b064e6bafbbad599ae2e10569ba4f7d5a6 Mon Sep 17 00:00:00 2001
2 From: Rex-BC Chen <rex-bc.chen@mediatek.com>
3 Date: Thu, 5 May 2022 19:52:19 +0800
4 Subject: [PATCH 09/21] cpufreq: mediatek: Move voltage limits to platform data
6 Voltages and shifts are defined as macros originally.
7 There are different requirements of these values for each MediaTek SoCs.
8 Therefore, we add the platform data and move these values into it.
10 Signed-off-by: Jia-Wei Chang <jia-wei.chang@mediatek.com>
11 Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com>
12 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
13 Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
15 drivers/cpufreq/mediatek-cpufreq.c | 84 +++++++++++++++++++++---------
16 1 file changed, 58 insertions(+), 26 deletions(-)
18 --- a/drivers/cpufreq/mediatek-cpufreq.c
19 +++ b/drivers/cpufreq/mediatek-cpufreq.c
21 #include <linux/cpumask.h>
22 #include <linux/module.h>
24 +#include <linux/of_platform.h>
25 #include <linux/platform_device.h>
26 #include <linux/pm_opp.h>
27 #include <linux/regulator/consumer.h>
29 -#define MIN_VOLT_SHIFT (100000)
30 -#define MAX_VOLT_SHIFT (200000)
31 -#define MAX_VOLT_LIMIT (1150000)
32 #define VOLT_TOL (10000)
34 +struct mtk_cpufreq_platform_data {
43 * The struct mtk_cpu_dvfs_info holds necessary information for doing CPU DVFS
44 * on each CPU power/clock domain of Mediatek SoCs. Each CPU cluster in
45 @@ -41,6 +47,7 @@ struct mtk_cpu_dvfs_info {
46 int intermediate_voltage;
47 bool need_voltage_tracking;
49 + const struct mtk_cpufreq_platform_data *soc_data;
52 static struct platform_device *cpufreq_pdev;
53 @@ -62,6 +69,7 @@ static struct mtk_cpu_dvfs_info *mtk_cpu
54 static int mtk_cpufreq_voltage_tracking(struct mtk_cpu_dvfs_info *info,
57 + const struct mtk_cpufreq_platform_data *soc_data = info->soc_data;
58 struct regulator *proc_reg = info->proc_reg;
59 struct regulator *sram_reg = info->sram_reg;
60 int pre_vproc, pre_vsram, new_vsram, vsram, vproc, ret;
61 @@ -73,7 +81,8 @@ static int mtk_cpufreq_voltage_tracking(
64 /* Vsram should not exceed the maximum allowed voltage of SoC. */
65 - new_vsram = min(new_vproc + MIN_VOLT_SHIFT, MAX_VOLT_LIMIT);
66 + new_vsram = min(new_vproc + soc_data->min_volt_shift,
67 + soc_data->sram_max_volt);
69 if (pre_vproc < new_vproc) {
71 @@ -96,10 +105,11 @@ static int mtk_cpufreq_voltage_tracking(
75 - vsram = min(new_vsram, pre_vproc + MAX_VOLT_SHIFT);
76 + vsram = min(new_vsram,
77 + pre_vproc + soc_data->min_volt_shift);
79 - if (vsram + VOLT_TOL >= MAX_VOLT_LIMIT) {
80 - vsram = MAX_VOLT_LIMIT;
81 + if (vsram + VOLT_TOL >= soc_data->sram_max_volt) {
82 + vsram = soc_data->sram_max_volt;
85 * If the target Vsram hits the maximum voltage,
86 @@ -117,7 +127,7 @@ static int mtk_cpufreq_voltage_tracking(
87 ret = regulator_set_voltage(sram_reg, vsram,
90 - vproc = vsram - MIN_VOLT_SHIFT;
91 + vproc = vsram - soc_data->min_volt_shift;
95 @@ -151,7 +161,8 @@ static int mtk_cpufreq_voltage_tracking(
99 - vproc = max(new_vproc, pre_vsram - MAX_VOLT_SHIFT);
100 + vproc = max(new_vproc,
101 + pre_vsram - soc_data->max_volt_shift);
102 ret = regulator_set_voltage(proc_reg, vproc,
105 @@ -160,10 +171,11 @@ static int mtk_cpufreq_voltage_tracking(
106 if (vproc == new_vproc)
109 - vsram = max(new_vsram, vproc + MIN_VOLT_SHIFT);
110 + vsram = max(new_vsram,
111 + vproc + soc_data->min_volt_shift);
113 - if (vsram + VOLT_TOL >= MAX_VOLT_LIMIT) {
114 - vsram = MAX_VOLT_LIMIT;
115 + if (vsram + VOLT_TOL >= soc_data->sram_max_volt) {
116 + vsram = soc_data->sram_max_volt;
119 * If the target Vsram hits the maximum voltage,
120 @@ -194,13 +206,14 @@ static int mtk_cpufreq_voltage_tracking(
122 static int mtk_cpufreq_set_voltage(struct mtk_cpu_dvfs_info *info, int vproc)
124 + const struct mtk_cpufreq_platform_data *soc_data = info->soc_data;
127 if (info->need_voltage_tracking)
128 ret = mtk_cpufreq_voltage_tracking(info, vproc);
130 ret = regulator_set_voltage(info->proc_reg, vproc,
132 + soc_data->proc_max_volt);
134 info->pre_vproc = vproc;
136 @@ -509,9 +522,17 @@ static struct cpufreq_driver mtk_cpufreq
138 static int mtk_cpufreq_probe(struct platform_device *pdev)
140 + const struct mtk_cpufreq_platform_data *data;
141 struct mtk_cpu_dvfs_info *info, *tmp;
144 + data = dev_get_platdata(&pdev->dev);
146 + dev_err(&pdev->dev,
147 + "failed to get mtk cpufreq platform data\n");
151 for_each_possible_cpu(cpu) {
152 info = mtk_cpu_dvfs_info_lookup(cpu);
154 @@ -523,6 +544,7 @@ static int mtk_cpufreq_probe(struct plat
155 goto release_dvfs_info_list;
158 + info->soc_data = data;
159 ret = mtk_cpu_dvfs_info_init(info, cpu);
162 @@ -558,20 +580,27 @@ static struct platform_driver mtk_cpufre
163 .probe = mtk_cpufreq_probe,
166 +static const struct mtk_cpufreq_platform_data mt2701_platform_data = {
167 + .min_volt_shift = 100000,
168 + .max_volt_shift = 200000,
169 + .proc_max_volt = 1150000,
170 + .sram_min_volt = 0,
171 + .sram_max_volt = 1150000,
174 /* List of machines supported by this driver */
175 static const struct of_device_id mtk_cpufreq_machines[] __initconst = {
176 - { .compatible = "mediatek,mt2701", },
177 - { .compatible = "mediatek,mt2712", },
178 - { .compatible = "mediatek,mt7622", },
179 - { .compatible = "mediatek,mt7623", },
180 - { .compatible = "mediatek,mt8167", },
181 - { .compatible = "mediatek,mt817x", },
182 - { .compatible = "mediatek,mt8173", },
183 - { .compatible = "mediatek,mt8176", },
184 - { .compatible = "mediatek,mt8183", },
185 - { .compatible = "mediatek,mt8365", },
186 - { .compatible = "mediatek,mt8516", },
188 + { .compatible = "mediatek,mt2701", .data = &mt2701_platform_data },
189 + { .compatible = "mediatek,mt2712", .data = &mt2701_platform_data },
190 + { .compatible = "mediatek,mt7622", .data = &mt2701_platform_data },
191 + { .compatible = "mediatek,mt7623", .data = &mt2701_platform_data },
192 + { .compatible = "mediatek,mt8167", .data = &mt2701_platform_data },
193 + { .compatible = "mediatek,mt817x", .data = &mt2701_platform_data },
194 + { .compatible = "mediatek,mt8173", .data = &mt2701_platform_data },
195 + { .compatible = "mediatek,mt8176", .data = &mt2701_platform_data },
196 + { .compatible = "mediatek,mt8183", .data = &mt2701_platform_data },
197 + { .compatible = "mediatek,mt8365", .data = &mt2701_platform_data },
198 + { .compatible = "mediatek,mt8516", .data = &mt2701_platform_data },
201 MODULE_DEVICE_TABLE(of, mtk_cpufreq_machines);
202 @@ -580,6 +609,7 @@ static int __init mtk_cpufreq_driver_ini
204 struct device_node *np;
205 const struct of_device_id *match;
206 + const struct mtk_cpufreq_platform_data *data;
209 np = of_find_node_by_path("/");
210 @@ -592,6 +622,7 @@ static int __init mtk_cpufreq_driver_ini
211 pr_debug("Machine is not compatible with mtk-cpufreq\n");
214 + data = match->data;
216 err = platform_driver_register(&mtk_cpufreq_platdrv);
218 @@ -603,7 +634,8 @@ static int __init mtk_cpufreq_driver_ini
219 * and the device registration codes are put here to handle defer
222 - cpufreq_pdev = platform_device_register_simple("mtk-cpufreq", -1, NULL, 0);
223 + cpufreq_pdev = platform_device_register_data(NULL, "mtk-cpufreq", -1,
224 + data, sizeof(*data));
225 if (IS_ERR(cpufreq_pdev)) {
226 pr_err("failed to register mtk-cpufreq platform device\n");
227 platform_driver_unregister(&mtk_cpufreq_platdrv);