17d127095SSricharan R // SPDX-License-Identifier: GPL-2.0
27d127095SSricharan R /*
37d127095SSricharan R * Copyright (c) 2018, The Linux Foundation. All rights reserved.
47d127095SSricharan R */
57d127095SSricharan R
67d127095SSricharan R /*
77d127095SSricharan R * In Certain QCOM SoCs like apq8096 and msm8996 that have KRYO processors,
87d127095SSricharan R * the CPU frequency subset and voltage value of each OPP varies
97d127095SSricharan R * based on the silicon variant in use. Qualcomm Process Voltage Scaling Tables
107d127095SSricharan R * defines the voltage and frequency value based on the msm-id in SMEM
117d127095SSricharan R * and speedbin blown in the efuse combination.
127d127095SSricharan R * The qcom-cpufreq-nvmem driver reads the msm-id and efuse value from the SoC
137d127095SSricharan R * to provide the OPP framework with required information.
147d127095SSricharan R * This is used to determine the voltage and frequency value for each OPP of
157d127095SSricharan R * operating-points-v2 table when it is parsed by the OPP framework.
167d127095SSricharan R */
177d127095SSricharan R
187d127095SSricharan R #include <linux/cpu.h>
197d127095SSricharan R #include <linux/err.h>
207d127095SSricharan R #include <linux/init.h>
217d127095SSricharan R #include <linux/kernel.h>
227d127095SSricharan R #include <linux/module.h>
237d127095SSricharan R #include <linux/nvmem-consumer.h>
247d127095SSricharan R #include <linux/of.h>
257d127095SSricharan R #include <linux/platform_device.h>
261cb8339cSNiklas Cassel #include <linux/pm_domain.h>
277d127095SSricharan R #include <linux/pm_opp.h>
287d127095SSricharan R #include <linux/slab.h>
297d127095SSricharan R #include <linux/soc/qcom/smem.h>
307d127095SSricharan R
31865d7e71SRobert Marko #include <dt-bindings/arm/qcom,ids.h>
327d127095SSricharan R
3357f2f8b4SNiklas Cassel struct qcom_cpufreq_drv;
3457f2f8b4SNiklas Cassel
3557f2f8b4SNiklas Cassel struct qcom_cpufreq_match_data {
3657f2f8b4SNiklas Cassel int (*get_version)(struct device *cpu_dev,
3757f2f8b4SNiklas Cassel struct nvmem_cell *speedbin_nvmem,
38a8811ec7SAnsuel Smith char **pvs_name,
3957f2f8b4SNiklas Cassel struct qcom_cpufreq_drv *drv);
401cb8339cSNiklas Cassel const char **genpd_names;
4157f2f8b4SNiklas Cassel };
4257f2f8b4SNiklas Cassel
4351a45209SStephan Gerhold struct qcom_cpufreq_drv_cpu {
4451a45209SStephan Gerhold int opp_token;
4551a45209SStephan Gerhold };
4651a45209SStephan Gerhold
4757f2f8b4SNiklas Cassel struct qcom_cpufreq_drv {
4857f2f8b4SNiklas Cassel u32 versions;
4957f2f8b4SNiklas Cassel const struct qcom_cpufreq_match_data *data;
5051a45209SStephan Gerhold struct qcom_cpufreq_drv_cpu cpus[];
5157f2f8b4SNiklas Cassel };
5257f2f8b4SNiklas Cassel
537d127095SSricharan R static struct platform_device *cpufreq_dt_pdev, *cpufreq_pdev;
547d127095SSricharan R
get_krait_bin_format_a(struct device * cpu_dev,int * speed,int * pvs,int * pvs_ver,u8 * buf)55a8811ec7SAnsuel Smith static void get_krait_bin_format_a(struct device *cpu_dev,
56a8811ec7SAnsuel Smith int *speed, int *pvs, int *pvs_ver,
57a05887f0SFabien Parent u8 *buf)
58a8811ec7SAnsuel Smith {
59a8811ec7SAnsuel Smith u32 pte_efuse;
60a8811ec7SAnsuel Smith
61a8811ec7SAnsuel Smith pte_efuse = *((u32 *)buf);
62a8811ec7SAnsuel Smith
63a8811ec7SAnsuel Smith *speed = pte_efuse & 0xf;
64a8811ec7SAnsuel Smith if (*speed == 0xf)
65a8811ec7SAnsuel Smith *speed = (pte_efuse >> 4) & 0xf;
66a8811ec7SAnsuel Smith
67a8811ec7SAnsuel Smith if (*speed == 0xf) {
68a8811ec7SAnsuel Smith *speed = 0;
69a8811ec7SAnsuel Smith dev_warn(cpu_dev, "Speed bin: Defaulting to %d\n", *speed);
70a8811ec7SAnsuel Smith } else {
71a8811ec7SAnsuel Smith dev_dbg(cpu_dev, "Speed bin: %d\n", *speed);
72a8811ec7SAnsuel Smith }
73a8811ec7SAnsuel Smith
74a8811ec7SAnsuel Smith *pvs = (pte_efuse >> 10) & 0x7;
75a8811ec7SAnsuel Smith if (*pvs == 0x7)
76a8811ec7SAnsuel Smith *pvs = (pte_efuse >> 13) & 0x7;
77a8811ec7SAnsuel Smith
78a8811ec7SAnsuel Smith if (*pvs == 0x7) {
79a8811ec7SAnsuel Smith *pvs = 0;
80a8811ec7SAnsuel Smith dev_warn(cpu_dev, "PVS bin: Defaulting to %d\n", *pvs);
81a8811ec7SAnsuel Smith } else {
82a8811ec7SAnsuel Smith dev_dbg(cpu_dev, "PVS bin: %d\n", *pvs);
83a8811ec7SAnsuel Smith }
84a8811ec7SAnsuel Smith }
85a8811ec7SAnsuel Smith
get_krait_bin_format_b(struct device * cpu_dev,int * speed,int * pvs,int * pvs_ver,u8 * buf)86a8811ec7SAnsuel Smith static void get_krait_bin_format_b(struct device *cpu_dev,
87a8811ec7SAnsuel Smith int *speed, int *pvs, int *pvs_ver,
88a05887f0SFabien Parent u8 *buf)
89a8811ec7SAnsuel Smith {
90a8811ec7SAnsuel Smith u32 pte_efuse, redundant_sel;
91a8811ec7SAnsuel Smith
92a8811ec7SAnsuel Smith pte_efuse = *((u32 *)buf);
93a8811ec7SAnsuel Smith redundant_sel = (pte_efuse >> 24) & 0x7;
94a8811ec7SAnsuel Smith
95a8811ec7SAnsuel Smith *pvs_ver = (pte_efuse >> 4) & 0x3;
96a8811ec7SAnsuel Smith
97a8811ec7SAnsuel Smith switch (redundant_sel) {
98a8811ec7SAnsuel Smith case 1:
99a8811ec7SAnsuel Smith *pvs = ((pte_efuse >> 28) & 0x8) | ((pte_efuse >> 6) & 0x7);
100a8811ec7SAnsuel Smith *speed = (pte_efuse >> 27) & 0xf;
101a8811ec7SAnsuel Smith break;
102a8811ec7SAnsuel Smith case 2:
103a8811ec7SAnsuel Smith *pvs = (pte_efuse >> 27) & 0xf;
104a8811ec7SAnsuel Smith *speed = pte_efuse & 0x7;
105a8811ec7SAnsuel Smith break;
106a8811ec7SAnsuel Smith default:
107a8811ec7SAnsuel Smith /* 4 bits of PVS are in efuse register bits 31, 8-6. */
108a8811ec7SAnsuel Smith *pvs = ((pte_efuse >> 28) & 0x8) | ((pte_efuse >> 6) & 0x7);
109a8811ec7SAnsuel Smith *speed = pte_efuse & 0x7;
110a8811ec7SAnsuel Smith }
111a8811ec7SAnsuel Smith
112a8811ec7SAnsuel Smith /* Check SPEED_BIN_BLOW_STATUS */
113a8811ec7SAnsuel Smith if (pte_efuse & BIT(3)) {
114a8811ec7SAnsuel Smith dev_dbg(cpu_dev, "Speed bin: %d\n", *speed);
115a8811ec7SAnsuel Smith } else {
116a8811ec7SAnsuel Smith dev_warn(cpu_dev, "Speed bin not set. Defaulting to 0!\n");
117a8811ec7SAnsuel Smith *speed = 0;
118a8811ec7SAnsuel Smith }
119a8811ec7SAnsuel Smith
120a8811ec7SAnsuel Smith /* Check PVS_BLOW_STATUS */
1214a8a77abSLuca Weiss pte_efuse = *(((u32 *)buf) + 1);
122a8811ec7SAnsuel Smith pte_efuse &= BIT(21);
123a8811ec7SAnsuel Smith if (pte_efuse) {
124a8811ec7SAnsuel Smith dev_dbg(cpu_dev, "PVS bin: %d\n", *pvs);
125a8811ec7SAnsuel Smith } else {
126a8811ec7SAnsuel Smith dev_warn(cpu_dev, "PVS bin not set. Defaulting to 0!\n");
127a8811ec7SAnsuel Smith *pvs = 0;
128a8811ec7SAnsuel Smith }
129a8811ec7SAnsuel Smith
130a8811ec7SAnsuel Smith dev_dbg(cpu_dev, "PVS version: %d\n", *pvs_ver);
131a8811ec7SAnsuel Smith }
132a8811ec7SAnsuel Smith
qcom_cpufreq_kryo_name_version(struct device * cpu_dev,struct nvmem_cell * speedbin_nvmem,char ** pvs_name,struct qcom_cpufreq_drv * drv)1337d127095SSricharan R static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev,
1347d127095SSricharan R struct nvmem_cell *speedbin_nvmem,
135a8811ec7SAnsuel Smith char **pvs_name,
13657f2f8b4SNiklas Cassel struct qcom_cpufreq_drv *drv)
1377d127095SSricharan R {
1387d127095SSricharan R size_t len;
1397d0f03d1SRobert Marko u32 msm_id;
1407d127095SSricharan R u8 *speedbin;
1417d0f03d1SRobert Marko int ret;
142a8811ec7SAnsuel Smith *pvs_name = NULL;
1437d127095SSricharan R
1447d0f03d1SRobert Marko ret = qcom_smem_get_soc_id(&msm_id);
1457d0f03d1SRobert Marko if (ret)
1467d0f03d1SRobert Marko return ret;
1477d127095SSricharan R
1487d127095SSricharan R speedbin = nvmem_cell_read(speedbin_nvmem, &len);
1497d127095SSricharan R if (IS_ERR(speedbin))
1507d127095SSricharan R return PTR_ERR(speedbin);
1517d127095SSricharan R
1527d0f03d1SRobert Marko switch (msm_id) {
1537d0f03d1SRobert Marko case QCOM_ID_MSM8996:
1547d0f03d1SRobert Marko case QCOM_ID_APQ8096:
15557f2f8b4SNiklas Cassel drv->versions = 1 << (unsigned int)(*speedbin);
1567d127095SSricharan R break;
1577d0f03d1SRobert Marko case QCOM_ID_MSM8996SG:
1587d0f03d1SRobert Marko case QCOM_ID_APQ8096SG:
15957f2f8b4SNiklas Cassel drv->versions = 1 << ((unsigned int)(*speedbin) + 4);
1607d127095SSricharan R break;
1617d127095SSricharan R default:
1627d127095SSricharan R BUG();
1637d127095SSricharan R break;
1647d127095SSricharan R }
1657d127095SSricharan R
1667d127095SSricharan R kfree(speedbin);
1677d127095SSricharan R return 0;
1687d127095SSricharan R }
1697d127095SSricharan R
qcom_cpufreq_krait_name_version(struct device * cpu_dev,struct nvmem_cell * speedbin_nvmem,char ** pvs_name,struct qcom_cpufreq_drv * drv)170a8811ec7SAnsuel Smith static int qcom_cpufreq_krait_name_version(struct device *cpu_dev,
171a8811ec7SAnsuel Smith struct nvmem_cell *speedbin_nvmem,
172a8811ec7SAnsuel Smith char **pvs_name,
173a8811ec7SAnsuel Smith struct qcom_cpufreq_drv *drv)
174a8811ec7SAnsuel Smith {
175a8811ec7SAnsuel Smith int speed = 0, pvs = 0, pvs_ver = 0;
176a8811ec7SAnsuel Smith u8 *speedbin;
177a8811ec7SAnsuel Smith size_t len;
1789f42cf54SFabien Parent int ret = 0;
179a8811ec7SAnsuel Smith
180a8811ec7SAnsuel Smith speedbin = nvmem_cell_read(speedbin_nvmem, &len);
181a8811ec7SAnsuel Smith
182a8811ec7SAnsuel Smith if (IS_ERR(speedbin))
183a8811ec7SAnsuel Smith return PTR_ERR(speedbin);
184a8811ec7SAnsuel Smith
185a8811ec7SAnsuel Smith switch (len) {
186a8811ec7SAnsuel Smith case 4:
187a8811ec7SAnsuel Smith get_krait_bin_format_a(cpu_dev, &speed, &pvs, &pvs_ver,
188a05887f0SFabien Parent speedbin);
189a8811ec7SAnsuel Smith break;
190a8811ec7SAnsuel Smith case 8:
191a8811ec7SAnsuel Smith get_krait_bin_format_b(cpu_dev, &speed, &pvs, &pvs_ver,
192a05887f0SFabien Parent speedbin);
193a8811ec7SAnsuel Smith break;
194a8811ec7SAnsuel Smith default:
195a8811ec7SAnsuel Smith dev_err(cpu_dev, "Unable to read nvmem data. Defaulting to 0!\n");
1969f42cf54SFabien Parent ret = -ENODEV;
1979f42cf54SFabien Parent goto len_error;
198a8811ec7SAnsuel Smith }
199a8811ec7SAnsuel Smith
200a8811ec7SAnsuel Smith snprintf(*pvs_name, sizeof("speedXX-pvsXX-vXX"), "speed%d-pvs%d-v%d",
201a8811ec7SAnsuel Smith speed, pvs, pvs_ver);
202a8811ec7SAnsuel Smith
203a8811ec7SAnsuel Smith drv->versions = (1 << speed);
204a8811ec7SAnsuel Smith
2059f42cf54SFabien Parent len_error:
206a8811ec7SAnsuel Smith kfree(speedbin);
2079f42cf54SFabien Parent return ret;
208a8811ec7SAnsuel Smith }
209a8811ec7SAnsuel Smith
21057f2f8b4SNiklas Cassel static const struct qcom_cpufreq_match_data match_data_kryo = {
21157f2f8b4SNiklas Cassel .get_version = qcom_cpufreq_kryo_name_version,
21257f2f8b4SNiklas Cassel };
21357f2f8b4SNiklas Cassel
214a8811ec7SAnsuel Smith static const struct qcom_cpufreq_match_data match_data_krait = {
215a8811ec7SAnsuel Smith .get_version = qcom_cpufreq_krait_name_version,
216a8811ec7SAnsuel Smith };
217a8811ec7SAnsuel Smith
2181cb8339cSNiklas Cassel static const char *qcs404_genpd_names[] = { "cpr", NULL };
2191cb8339cSNiklas Cassel
2201cb8339cSNiklas Cassel static const struct qcom_cpufreq_match_data match_data_qcs404 = {
2211cb8339cSNiklas Cassel .genpd_names = qcs404_genpd_names,
2221cb8339cSNiklas Cassel };
2231cb8339cSNiklas Cassel
qcom_cpufreq_probe(struct platform_device * pdev)2247d127095SSricharan R static int qcom_cpufreq_probe(struct platform_device *pdev)
2257d127095SSricharan R {
22657f2f8b4SNiklas Cassel struct qcom_cpufreq_drv *drv;
2277d127095SSricharan R struct nvmem_cell *speedbin_nvmem;
2287d127095SSricharan R struct device_node *np;
2297d127095SSricharan R struct device *cpu_dev;
23001039fb8SFabien Parent char pvs_name_buffer[] = "speedXX-pvsXX-vXX";
23101039fb8SFabien Parent char *pvs_name = pvs_name_buffer;
2327d127095SSricharan R unsigned cpu;
2337d127095SSricharan R const struct of_device_id *match;
2347d127095SSricharan R int ret;
2357d127095SSricharan R
2367d127095SSricharan R cpu_dev = get_cpu_device(0);
2377d127095SSricharan R if (!cpu_dev)
2387d127095SSricharan R return -ENODEV;
2397d127095SSricharan R
2407d127095SSricharan R np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
2417d127095SSricharan R if (!np)
2427d127095SSricharan R return -ENOENT;
2437d127095SSricharan R
2442dea6516SAnsuel Smith ret = of_device_is_compatible(np, "operating-points-v2-kryo-cpu");
2457d127095SSricharan R if (!ret) {
2467d127095SSricharan R of_node_put(np);
2477d127095SSricharan R return -ENOENT;
2487d127095SSricharan R }
2497d127095SSricharan R
25051a45209SStephan Gerhold drv = devm_kzalloc(&pdev->dev, struct_size(drv, cpus, num_possible_cpus()),
25151a45209SStephan Gerhold GFP_KERNEL);
252*e3fd01a8SJavier Carrasco if (!drv) {
253*e3fd01a8SJavier Carrasco of_node_put(np);
25457f2f8b4SNiklas Cassel return -ENOMEM;
255*e3fd01a8SJavier Carrasco }
25657f2f8b4SNiklas Cassel
25757f2f8b4SNiklas Cassel match = pdev->dev.platform_data;
25857f2f8b4SNiklas Cassel drv->data = match->data;
259*e3fd01a8SJavier Carrasco if (!drv->data) {
260*e3fd01a8SJavier Carrasco of_node_put(np);
26151a45209SStephan Gerhold return -ENODEV;
262*e3fd01a8SJavier Carrasco }
2637d127095SSricharan R
26457f2f8b4SNiklas Cassel if (drv->data->get_version) {
26557f2f8b4SNiklas Cassel speedbin_nvmem = of_nvmem_cell_get(np, NULL);
266*e3fd01a8SJavier Carrasco if (IS_ERR(speedbin_nvmem)) {
267*e3fd01a8SJavier Carrasco of_node_put(np);
26851a45209SStephan Gerhold return dev_err_probe(cpu_dev, PTR_ERR(speedbin_nvmem),
269d78be404SYang Yingliang "Could not get nvmem cell\n");
270*e3fd01a8SJavier Carrasco }
2717d127095SSricharan R
272a8811ec7SAnsuel Smith ret = drv->data->get_version(cpu_dev,
273a8811ec7SAnsuel Smith speedbin_nvmem, &pvs_name, drv);
27457f2f8b4SNiklas Cassel if (ret) {
275*e3fd01a8SJavier Carrasco of_node_put(np);
27657f2f8b4SNiklas Cassel nvmem_cell_put(speedbin_nvmem);
27751a45209SStephan Gerhold return ret;
27857f2f8b4SNiklas Cassel }
27957f2f8b4SNiklas Cassel nvmem_cell_put(speedbin_nvmem);
28057f2f8b4SNiklas Cassel }
28157f2f8b4SNiklas Cassel of_node_put(np);
28257f2f8b4SNiklas Cassel
2837d127095SSricharan R for_each_possible_cpu(cpu) {
28449cd000dSViresh Kumar struct dev_pm_opp_config config = {
28549cd000dSViresh Kumar .supported_hw = NULL,
28649cd000dSViresh Kumar };
28749cd000dSViresh Kumar
2887d127095SSricharan R cpu_dev = get_cpu_device(cpu);
2897d127095SSricharan R if (NULL == cpu_dev) {
2907d127095SSricharan R ret = -ENODEV;
29149cd000dSViresh Kumar goto free_opp;
2927d127095SSricharan R }
2937d127095SSricharan R
29457f2f8b4SNiklas Cassel if (drv->data->get_version) {
29549cd000dSViresh Kumar config.supported_hw = &drv->versions;
29649cd000dSViresh Kumar config.supported_hw_count = 1;
297a8811ec7SAnsuel Smith
29849cd000dSViresh Kumar if (pvs_name)
29949cd000dSViresh Kumar config.prop_name = pvs_name;
3001cb8339cSNiklas Cassel }
3011cb8339cSNiklas Cassel
3021cb8339cSNiklas Cassel if (drv->data->genpd_names) {
30349cd000dSViresh Kumar config.genpd_names = drv->data->genpd_names;
30449cd000dSViresh Kumar config.virt_devs = NULL;
30549cd000dSViresh Kumar }
30649cd000dSViresh Kumar
30749cd000dSViresh Kumar if (config.supported_hw || config.genpd_names) {
30851a45209SStephan Gerhold drv->cpus[cpu].opp_token = dev_pm_opp_set_config(cpu_dev, &config);
30951a45209SStephan Gerhold if (drv->cpus[cpu].opp_token < 0) {
31051a45209SStephan Gerhold ret = drv->cpus[cpu].opp_token;
31149cd000dSViresh Kumar dev_err(cpu_dev, "Failed to set OPP config\n");
31249cd000dSViresh Kumar goto free_opp;
3137d127095SSricharan R }
3147d127095SSricharan R }
31557f2f8b4SNiklas Cassel }
3167d127095SSricharan R
3177d127095SSricharan R cpufreq_dt_pdev = platform_device_register_simple("cpufreq-dt", -1,
3187d127095SSricharan R NULL, 0);
3197d127095SSricharan R if (!IS_ERR(cpufreq_dt_pdev)) {
32057f2f8b4SNiklas Cassel platform_set_drvdata(pdev, drv);
3217d127095SSricharan R return 0;
3227d127095SSricharan R }
3237d127095SSricharan R
3247d127095SSricharan R ret = PTR_ERR(cpufreq_dt_pdev);
3257d127095SSricharan R dev_err(cpu_dev, "Failed to register platform device\n");
3267d127095SSricharan R
3277d127095SSricharan R free_opp:
32849cd000dSViresh Kumar for_each_possible_cpu(cpu)
32951a45209SStephan Gerhold dev_pm_opp_clear_config(drv->cpus[cpu].opp_token);
3307d127095SSricharan R return ret;
3317d127095SSricharan R }
3327d127095SSricharan R
qcom_cpufreq_remove(struct platform_device * pdev)33340273232SYangtao Li static void qcom_cpufreq_remove(struct platform_device *pdev)
3347d127095SSricharan R {
33557f2f8b4SNiklas Cassel struct qcom_cpufreq_drv *drv = platform_get_drvdata(pdev);
3367d127095SSricharan R unsigned int cpu;
3377d127095SSricharan R
3387d127095SSricharan R platform_device_unregister(cpufreq_dt_pdev);
3397d127095SSricharan R
34049cd000dSViresh Kumar for_each_possible_cpu(cpu)
34151a45209SStephan Gerhold dev_pm_opp_clear_config(drv->cpus[cpu].opp_token);
3427d127095SSricharan R }
3437d127095SSricharan R
3447d127095SSricharan R static struct platform_driver qcom_cpufreq_driver = {
3457d127095SSricharan R .probe = qcom_cpufreq_probe,
34640273232SYangtao Li .remove_new = qcom_cpufreq_remove,
3477d127095SSricharan R .driver = {
3487d127095SSricharan R .name = "qcom-cpufreq-nvmem",
3497d127095SSricharan R },
3507d127095SSricharan R };
3517d127095SSricharan R
3527d127095SSricharan R static const struct of_device_id qcom_cpufreq_match_list[] __initconst = {
35357f2f8b4SNiklas Cassel { .compatible = "qcom,apq8096", .data = &match_data_kryo },
35457f2f8b4SNiklas Cassel { .compatible = "qcom,msm8996", .data = &match_data_kryo },
3551cb8339cSNiklas Cassel { .compatible = "qcom,qcs404", .data = &match_data_qcs404 },
356a8811ec7SAnsuel Smith { .compatible = "qcom,ipq8064", .data = &match_data_krait },
357a8811ec7SAnsuel Smith { .compatible = "qcom,apq8064", .data = &match_data_krait },
358a8811ec7SAnsuel Smith { .compatible = "qcom,msm8974", .data = &match_data_krait },
359a8811ec7SAnsuel Smith { .compatible = "qcom,msm8960", .data = &match_data_krait },
3607d127095SSricharan R {},
3617d127095SSricharan R };
362a5a60316SPali Rohár MODULE_DEVICE_TABLE(of, qcom_cpufreq_match_list);
3637d127095SSricharan R
3647d127095SSricharan R /*
3657d127095SSricharan R * Since the driver depends on smem and nvmem drivers, which may
3667d127095SSricharan R * return EPROBE_DEFER, all the real activity is done in the probe,
3677d127095SSricharan R * which may be defered as well. The init here is only registering
3687d127095SSricharan R * the driver and the platform device.
3697d127095SSricharan R */
qcom_cpufreq_init(void)3707d127095SSricharan R static int __init qcom_cpufreq_init(void)
3717d127095SSricharan R {
3727d127095SSricharan R struct device_node *np = of_find_node_by_path("/");
3737d127095SSricharan R const struct of_device_id *match;
3747d127095SSricharan R int ret;
3757d127095SSricharan R
3767d127095SSricharan R if (!np)
3777d127095SSricharan R return -ENODEV;
3787d127095SSricharan R
3797d127095SSricharan R match = of_match_node(qcom_cpufreq_match_list, np);
3807d127095SSricharan R of_node_put(np);
3817d127095SSricharan R if (!match)
3827d127095SSricharan R return -ENODEV;
3837d127095SSricharan R
3847d127095SSricharan R ret = platform_driver_register(&qcom_cpufreq_driver);
3857d127095SSricharan R if (unlikely(ret < 0))
3867d127095SSricharan R return ret;
3877d127095SSricharan R
3887d127095SSricharan R cpufreq_pdev = platform_device_register_data(NULL, "qcom-cpufreq-nvmem",
3897d127095SSricharan R -1, match, sizeof(*match));
3907d127095SSricharan R ret = PTR_ERR_OR_ZERO(cpufreq_pdev);
3917d127095SSricharan R if (0 == ret)
3927d127095SSricharan R return 0;
3937d127095SSricharan R
3947d127095SSricharan R platform_driver_unregister(&qcom_cpufreq_driver);
3957d127095SSricharan R return ret;
3967d127095SSricharan R }
3977d127095SSricharan R module_init(qcom_cpufreq_init);
3987d127095SSricharan R
qcom_cpufreq_exit(void)3997d127095SSricharan R static void __exit qcom_cpufreq_exit(void)
4007d127095SSricharan R {
4017d127095SSricharan R platform_device_unregister(cpufreq_pdev);
4027d127095SSricharan R platform_driver_unregister(&qcom_cpufreq_driver);
4037d127095SSricharan R }
4047d127095SSricharan R module_exit(qcom_cpufreq_exit);
4057d127095SSricharan R
4067d127095SSricharan R MODULE_DESCRIPTION("Qualcomm Technologies, Inc. CPUfreq driver");
4077d127095SSricharan R MODULE_LICENSE("GPL v2");
408