Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / remoteproc / qcom_wcnss_iris.c
blob0e0ae1e764ea3e9f5a86f76d16aa5b0defae1694
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Qualcomm Wireless Connectivity Subsystem Iris driver
5 * Copyright (C) 2016 Linaro Ltd
6 * Copyright (C) 2014 Sony Mobile Communications AB
7 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
8 */
10 #include <linux/clk.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/of_device.h>
14 #include <linux/platform_device.h>
15 #include <linux/regulator/consumer.h>
17 #include "qcom_wcnss.h"
19 struct qcom_iris {
20 struct device *dev;
22 struct clk *xo_clk;
24 struct regulator_bulk_data *vregs;
25 size_t num_vregs;
28 struct iris_data {
29 const struct wcnss_vreg_info *vregs;
30 size_t num_vregs;
32 bool use_48mhz_xo;
35 static const struct iris_data wcn3620_data = {
36 .vregs = (struct wcnss_vreg_info[]) {
37 { "vddxo", 1800000, 1800000, 10000 },
38 { "vddrfa", 1300000, 1300000, 100000 },
39 { "vddpa", 3300000, 3300000, 515000 },
40 { "vdddig", 1800000, 1800000, 10000 },
42 .num_vregs = 4,
43 .use_48mhz_xo = false,
46 static const struct iris_data wcn3660_data = {
47 .vregs = (struct wcnss_vreg_info[]) {
48 { "vddxo", 1800000, 1800000, 10000 },
49 { "vddrfa", 1300000, 1300000, 100000 },
50 { "vddpa", 2900000, 3000000, 515000 },
51 { "vdddig", 1200000, 1225000, 10000 },
53 .num_vregs = 4,
54 .use_48mhz_xo = true,
57 static const struct iris_data wcn3680_data = {
58 .vregs = (struct wcnss_vreg_info[]) {
59 { "vddxo", 1800000, 1800000, 10000 },
60 { "vddrfa", 1300000, 1300000, 100000 },
61 { "vddpa", 3300000, 3300000, 515000 },
62 { "vdddig", 1800000, 1800000, 10000 },
64 .num_vregs = 4,
65 .use_48mhz_xo = true,
68 int qcom_iris_enable(struct qcom_iris *iris)
70 int ret;
72 ret = regulator_bulk_enable(iris->num_vregs, iris->vregs);
73 if (ret)
74 return ret;
76 ret = clk_prepare_enable(iris->xo_clk);
77 if (ret) {
78 dev_err(iris->dev, "failed to enable xo clk\n");
79 goto disable_regulators;
82 return 0;
84 disable_regulators:
85 regulator_bulk_disable(iris->num_vregs, iris->vregs);
87 return ret;
90 void qcom_iris_disable(struct qcom_iris *iris)
92 clk_disable_unprepare(iris->xo_clk);
93 regulator_bulk_disable(iris->num_vregs, iris->vregs);
96 static int qcom_iris_probe(struct platform_device *pdev)
98 const struct iris_data *data;
99 struct qcom_wcnss *wcnss;
100 struct qcom_iris *iris;
101 int ret;
102 int i;
104 iris = devm_kzalloc(&pdev->dev, sizeof(struct qcom_iris), GFP_KERNEL);
105 if (!iris)
106 return -ENOMEM;
108 data = of_device_get_match_data(&pdev->dev);
109 wcnss = dev_get_drvdata(pdev->dev.parent);
111 iris->xo_clk = devm_clk_get(&pdev->dev, "xo");
112 if (IS_ERR(iris->xo_clk)) {
113 if (PTR_ERR(iris->xo_clk) != -EPROBE_DEFER)
114 dev_err(&pdev->dev, "failed to acquire xo clk\n");
115 return PTR_ERR(iris->xo_clk);
118 iris->num_vregs = data->num_vregs;
119 iris->vregs = devm_kcalloc(&pdev->dev,
120 iris->num_vregs,
121 sizeof(struct regulator_bulk_data),
122 GFP_KERNEL);
123 if (!iris->vregs)
124 return -ENOMEM;
126 for (i = 0; i < iris->num_vregs; i++)
127 iris->vregs[i].supply = data->vregs[i].name;
129 ret = devm_regulator_bulk_get(&pdev->dev, iris->num_vregs, iris->vregs);
130 if (ret) {
131 dev_err(&pdev->dev, "failed to get regulators\n");
132 return ret;
135 for (i = 0; i < iris->num_vregs; i++) {
136 if (data->vregs[i].max_voltage)
137 regulator_set_voltage(iris->vregs[i].consumer,
138 data->vregs[i].min_voltage,
139 data->vregs[i].max_voltage);
141 if (data->vregs[i].load_uA)
142 regulator_set_load(iris->vregs[i].consumer,
143 data->vregs[i].load_uA);
146 qcom_wcnss_assign_iris(wcnss, iris, data->use_48mhz_xo);
148 return 0;
151 static int qcom_iris_remove(struct platform_device *pdev)
153 struct qcom_wcnss *wcnss = dev_get_drvdata(pdev->dev.parent);
155 qcom_wcnss_assign_iris(wcnss, NULL, false);
157 return 0;
160 static const struct of_device_id iris_of_match[] = {
161 { .compatible = "qcom,wcn3620", .data = &wcn3620_data },
162 { .compatible = "qcom,wcn3660", .data = &wcn3660_data },
163 { .compatible = "qcom,wcn3680", .data = &wcn3680_data },
166 MODULE_DEVICE_TABLE(of, iris_of_match);
168 struct platform_driver qcom_iris_driver = {
169 .probe = qcom_iris_probe,
170 .remove = qcom_iris_remove,
171 .driver = {
172 .name = "qcom-iris",
173 .of_match_table = iris_of_match,