Skip to content

Commit 1cb8339

Browse files
Niklas Casselvireshk
Niklas Cassel
authored andcommitted
cpufreq: qcom: Add support for qcs404 on nvmem driver
Add support for qcs404 on nvmem driver. The qcs404 SoC has support for Core Power Reduction (CPR), which is implemented as a power domain provider, therefore add optional support in this driver to attach to a genpd power domain. Co-developed-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org> Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org> Signed-off-by: Niklas Cassel <niklas.cassel@linaro.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 57f2f8b commit 1cb8339

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

drivers/cpufreq/qcom-cpufreq-nvmem.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/of.h>
2525
#include <linux/of_device.h>
2626
#include <linux/platform_device.h>
27+
#include <linux/pm_domain.h>
2728
#include <linux/pm_opp.h>
2829
#include <linux/slab.h>
2930
#include <linux/soc/qcom/smem.h>
@@ -49,10 +50,12 @@ struct qcom_cpufreq_match_data {
4950
int (*get_version)(struct device *cpu_dev,
5051
struct nvmem_cell *speedbin_nvmem,
5152
struct qcom_cpufreq_drv *drv);
53+
const char **genpd_names;
5254
};
5355

5456
struct qcom_cpufreq_drv {
5557
struct opp_table **opp_tables;
58+
struct opp_table **genpd_opp_tables;
5659
u32 versions;
5760
const struct qcom_cpufreq_match_data *data;
5861
};
@@ -126,6 +129,12 @@ static const struct qcom_cpufreq_match_data match_data_kryo = {
126129
.get_version = qcom_cpufreq_kryo_name_version,
127130
};
128131

132+
static const char *qcs404_genpd_names[] = { "cpr", NULL };
133+
134+
static const struct qcom_cpufreq_match_data match_data_qcs404 = {
135+
.genpd_names = qcs404_genpd_names,
136+
};
137+
129138
static int qcom_cpufreq_probe(struct platform_device *pdev)
130139
{
131140
struct qcom_cpufreq_drv *drv;
@@ -188,11 +197,19 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
188197
goto free_drv;
189198
}
190199

200+
drv->genpd_opp_tables = kcalloc(num_possible_cpus(),
201+
sizeof(*drv->genpd_opp_tables),
202+
GFP_KERNEL);
203+
if (!drv->genpd_opp_tables) {
204+
ret = -ENOMEM;
205+
goto free_opp;
206+
}
207+
191208
for_each_possible_cpu(cpu) {
192209
cpu_dev = get_cpu_device(cpu);
193210
if (NULL == cpu_dev) {
194211
ret = -ENODEV;
195-
goto free_opp;
212+
goto free_genpd_opp;
196213
}
197214

198215
if (drv->data->get_version) {
@@ -203,7 +220,22 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
203220
ret = PTR_ERR(drv->opp_tables[cpu]);
204221
dev_err(cpu_dev,
205222
"Failed to set supported hardware\n");
206-
goto free_opp;
223+
goto free_genpd_opp;
224+
}
225+
}
226+
227+
if (drv->data->genpd_names) {
228+
drv->genpd_opp_tables[cpu] =
229+
dev_pm_opp_attach_genpd(cpu_dev,
230+
drv->data->genpd_names,
231+
NULL);
232+
if (IS_ERR(drv->genpd_opp_tables[cpu])) {
233+
ret = PTR_ERR(drv->genpd_opp_tables[cpu]);
234+
if (ret != -EPROBE_DEFER)
235+
dev_err(cpu_dev,
236+
"Could not attach to pm_domain: %d\n",
237+
ret);
238+
goto free_genpd_opp;
207239
}
208240
}
209241
}
@@ -218,6 +250,13 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
218250
ret = PTR_ERR(cpufreq_dt_pdev);
219251
dev_err(cpu_dev, "Failed to register platform device\n");
220252

253+
free_genpd_opp:
254+
for_each_possible_cpu(cpu) {
255+
if (IS_ERR_OR_NULL(drv->genpd_opp_tables[cpu]))
256+
break;
257+
dev_pm_opp_detach_genpd(drv->genpd_opp_tables[cpu]);
258+
}
259+
kfree(drv->genpd_opp_tables);
221260
free_opp:
222261
for_each_possible_cpu(cpu) {
223262
if (IS_ERR_OR_NULL(drv->opp_tables[cpu]))
@@ -238,11 +277,15 @@ static int qcom_cpufreq_remove(struct platform_device *pdev)
238277

239278
platform_device_unregister(cpufreq_dt_pdev);
240279

241-
for_each_possible_cpu(cpu)
280+
for_each_possible_cpu(cpu) {
242281
if (drv->opp_tables[cpu])
243282
dev_pm_opp_put_supported_hw(drv->opp_tables[cpu]);
283+
if (drv->genpd_opp_tables[cpu])
284+
dev_pm_opp_detach_genpd(drv->genpd_opp_tables[cpu]);
285+
}
244286

245287
kfree(drv->opp_tables);
288+
kfree(drv->genpd_opp_tables);
246289
kfree(drv);
247290

248291
return 0;
@@ -259,6 +302,7 @@ static struct platform_driver qcom_cpufreq_driver = {
259302
static const struct of_device_id qcom_cpufreq_match_list[] __initconst = {
260303
{ .compatible = "qcom,apq8096", .data = &match_data_kryo },
261304
{ .compatible = "qcom,msm8996", .data = &match_data_kryo },
305+
{ .compatible = "qcom,qcs404", .data = &match_data_qcs404 },
262306
{},
263307
};
264308

0 commit comments

Comments
 (0)