Skip to content

Commit dcd1fd7

Browse files
Mani-Sadhasivamvireshk
authored andcommitted
cpufreq: qcom-hw: Use of_device_get_match_data for offsets and row size
For preparing the driver to handle further SoC revisions, let's use the of_device_get_match_data() API for getting the device specific offsets and row size instead of defining them globally. Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent f17b3e4 commit dcd1fd7

1 file changed

Lines changed: 59 additions & 30 deletions

File tree

drivers/cpufreq/qcom-cpufreq-hw.c

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@
1919
#define LUT_L_VAL GENMASK(7, 0)
2020
#define LUT_CORE_COUNT GENMASK(18, 16)
2121
#define LUT_VOLT GENMASK(11, 0)
22-
#define LUT_ROW_SIZE 32
2322
#define CLK_HW_DIV 2
2423
#define LUT_TURBO_IND 1
2524

26-
/* Register offsets */
27-
#define REG_ENABLE 0x0
28-
#define REG_FREQ_LUT 0x110
29-
#define REG_VOLT_LUT 0x114
30-
#define REG_PERF_STATE 0x920
25+
struct qcom_cpufreq_soc_data {
26+
u32 reg_enable;
27+
u32 reg_freq_lut;
28+
u32 reg_volt_lut;
29+
u32 reg_perf_state;
30+
u8 lut_row_size;
31+
};
32+
33+
struct qcom_cpufreq_data {
34+
void __iomem *base;
35+
const struct qcom_cpufreq_soc_data *soc_data;
36+
};
3137

3238
static unsigned long cpu_hw_rate, xo_rate;
3339
static bool icc_scaling_enabled;
@@ -76,10 +82,11 @@ static int qcom_cpufreq_update_opp(struct device *cpu_dev,
7682
static int qcom_cpufreq_hw_target_index(struct cpufreq_policy *policy,
7783
unsigned int index)
7884
{
79-
void __iomem *perf_state_reg = policy->driver_data;
85+
struct qcom_cpufreq_data *data = policy->driver_data;
86+
const struct qcom_cpufreq_soc_data *soc_data = data->soc_data;
8087
unsigned long freq = policy->freq_table[index].frequency;
8188

82-
writel_relaxed(index, perf_state_reg);
89+
writel_relaxed(index, data->base + soc_data->reg_perf_state);
8390

8491
if (icc_scaling_enabled)
8592
qcom_cpufreq_set_bw(policy, freq);
@@ -91,17 +98,19 @@ static int qcom_cpufreq_hw_target_index(struct cpufreq_policy *policy,
9198

9299
static unsigned int qcom_cpufreq_hw_get(unsigned int cpu)
93100
{
94-
void __iomem *perf_state_reg;
101+
struct qcom_cpufreq_data *data;
102+
const struct qcom_cpufreq_soc_data *soc_data;
95103
struct cpufreq_policy *policy;
96104
unsigned int index;
97105

98106
policy = cpufreq_cpu_get_raw(cpu);
99107
if (!policy)
100108
return 0;
101109

102-
perf_state_reg = policy->driver_data;
110+
data = policy->driver_data;
111+
soc_data = data->soc_data;
103112

104-
index = readl_relaxed(perf_state_reg);
113+
index = readl_relaxed(data->base + soc_data->reg_perf_state);
105114
index = min(index, LUT_MAX_ENTRIES - 1);
106115

107116
return policy->freq_table[index].frequency;
@@ -110,12 +119,13 @@ static unsigned int qcom_cpufreq_hw_get(unsigned int cpu)
110119
static unsigned int qcom_cpufreq_hw_fast_switch(struct cpufreq_policy *policy,
111120
unsigned int target_freq)
112121
{
113-
void __iomem *perf_state_reg = policy->driver_data;
122+
struct qcom_cpufreq_data *data = policy->driver_data;
123+
const struct qcom_cpufreq_soc_data *soc_data = data->soc_data;
114124
unsigned int index;
115125
unsigned long freq;
116126

117127
index = policy->cached_resolved_idx;
118-
writel_relaxed(index, perf_state_reg);
128+
writel_relaxed(index, data->base + soc_data->reg_perf_state);
119129

120130
freq = policy->freq_table[index].frequency;
121131
arch_set_freq_scale(policy->related_cpus, freq,
@@ -125,15 +135,16 @@ static unsigned int qcom_cpufreq_hw_fast_switch(struct cpufreq_policy *policy,
125135
}
126136

127137
static int qcom_cpufreq_hw_read_lut(struct device *cpu_dev,
128-
struct cpufreq_policy *policy,
129-
void __iomem *base)
138+
struct cpufreq_policy *policy)
130139
{
131140
u32 data, src, lval, i, core_count, prev_freq = 0, freq;
132141
u32 volt;
133142
struct cpufreq_frequency_table *table;
134143
struct dev_pm_opp *opp;
135144
unsigned long rate;
136145
int ret;
146+
struct qcom_cpufreq_data *drv_data = policy->driver_data;
147+
const struct qcom_cpufreq_soc_data *soc_data = drv_data->soc_data;
137148

138149
table = kcalloc(LUT_MAX_ENTRIES + 1, sizeof(*table), GFP_KERNEL);
139150
if (!table)
@@ -160,14 +171,14 @@ static int qcom_cpufreq_hw_read_lut(struct device *cpu_dev,
160171
}
161172

162173
for (i = 0; i < LUT_MAX_ENTRIES; i++) {
163-
data = readl_relaxed(base + REG_FREQ_LUT +
164-
i * LUT_ROW_SIZE);
174+
data = readl_relaxed(drv_data->base + soc_data->reg_freq_lut +
175+
i * soc_data->lut_row_size);
165176
src = FIELD_GET(LUT_SRC, data);
166177
lval = FIELD_GET(LUT_L_VAL, data);
167178
core_count = FIELD_GET(LUT_CORE_COUNT, data);
168179

169-
data = readl_relaxed(base + REG_VOLT_LUT +
170-
i * LUT_ROW_SIZE);
180+
data = readl_relaxed(drv_data->base + soc_data->reg_volt_lut +
181+
i * soc_data->lut_row_size);
171182
volt = FIELD_GET(LUT_VOLT, data) * 1000;
172183

173184
if (src)
@@ -237,6 +248,20 @@ static void qcom_get_related_cpus(int index, struct cpumask *m)
237248
}
238249
}
239250

251+
static const struct qcom_cpufreq_soc_data qcom_soc_data = {
252+
.reg_enable = 0x0,
253+
.reg_freq_lut = 0x110,
254+
.reg_volt_lut = 0x114,
255+
.reg_perf_state = 0x920,
256+
.lut_row_size = 32,
257+
};
258+
259+
static const struct of_device_id qcom_cpufreq_hw_match[] = {
260+
{ .compatible = "qcom,cpufreq-hw", .data = &qcom_soc_data },
261+
{}
262+
};
263+
MODULE_DEVICE_TABLE(of, qcom_cpufreq_hw_match);
264+
240265
static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
241266
{
242267
struct platform_device *pdev = cpufreq_get_driver_data();
@@ -245,6 +270,7 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
245270
struct device_node *cpu_np;
246271
struct device *cpu_dev;
247272
void __iomem *base;
273+
struct qcom_cpufreq_data *data;
248274
int ret, index;
249275

250276
cpu_dev = get_cpu_device(policy->cpu);
@@ -270,8 +296,17 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
270296
if (IS_ERR(base))
271297
return PTR_ERR(base);
272298

299+
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
300+
if (!data) {
301+
ret = -ENOMEM;
302+
goto error;
303+
}
304+
305+
data->soc_data = of_device_get_match_data(&pdev->dev);
306+
data->base = base;
307+
273308
/* HW should be in enabled state to proceed */
274-
if (!(readl_relaxed(base + REG_ENABLE) & 0x1)) {
309+
if (!(readl_relaxed(base + data->soc_data->reg_enable) & 0x1)) {
275310
dev_err(dev, "Domain-%d cpufreq hardware not enabled\n", index);
276311
ret = -ENODEV;
277312
goto error;
@@ -284,9 +319,9 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
284319
goto error;
285320
}
286321

287-
policy->driver_data = base + REG_PERF_STATE;
322+
policy->driver_data = data;
288323

289-
ret = qcom_cpufreq_hw_read_lut(cpu_dev, policy, base);
324+
ret = qcom_cpufreq_hw_read_lut(cpu_dev, policy);
290325
if (ret) {
291326
dev_err(dev, "Domain-%d failed to read LUT\n", index);
292327
goto error;
@@ -310,13 +345,13 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
310345
static int qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy)
311346
{
312347
struct device *cpu_dev = get_cpu_device(policy->cpu);
313-
void __iomem *base = policy->driver_data - REG_PERF_STATE;
348+
struct qcom_cpufreq_data *data = policy->driver_data;
314349
struct platform_device *pdev = cpufreq_get_driver_data();
315350

316351
dev_pm_opp_remove_all_dynamic(cpu_dev);
317352
dev_pm_opp_of_cpumask_remove_table(policy->related_cpus);
318353
kfree(policy->freq_table);
319-
devm_iounmap(&pdev->dev, base);
354+
devm_iounmap(&pdev->dev, data->base);
320355

321356
return 0;
322357
}
@@ -386,12 +421,6 @@ static int qcom_cpufreq_hw_driver_remove(struct platform_device *pdev)
386421
return cpufreq_unregister_driver(&cpufreq_qcom_hw_driver);
387422
}
388423

389-
static const struct of_device_id qcom_cpufreq_hw_match[] = {
390-
{ .compatible = "qcom,cpufreq-hw" },
391-
{}
392-
};
393-
MODULE_DEVICE_TABLE(of, qcom_cpufreq_hw_match);
394-
395424
static struct platform_driver qcom_cpufreq_hw_driver = {
396425
.probe = qcom_cpufreq_hw_driver_probe,
397426
.remove = qcom_cpufreq_hw_driver_remove,

0 commit comments

Comments
 (0)