1da65e367SBjorn Andersson /*
2da65e367SBjorn Andersson  * Copyright (c) 2015, Sony Mobile Communications AB.
3da65e367SBjorn Andersson  * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
4da65e367SBjorn Andersson  *
5da65e367SBjorn Andersson  * This program is free software; you can redistribute it and/or modify
6da65e367SBjorn Andersson  * it under the terms of the GNU General Public License version 2 and
7da65e367SBjorn Andersson  * only version 2 as published by the Free Software Foundation.
8da65e367SBjorn Andersson  *
9da65e367SBjorn Andersson  * This program is distributed in the hope that it will be useful,
10da65e367SBjorn Andersson  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11da65e367SBjorn Andersson  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12da65e367SBjorn Andersson  * GNU General Public License for more details.
13da65e367SBjorn Andersson  */
14da65e367SBjorn Andersson 
15da65e367SBjorn Andersson #include <linux/module.h>
16da65e367SBjorn Andersson #include <linux/of.h>
17da65e367SBjorn Andersson #include <linux/of_device.h>
18da65e367SBjorn Andersson #include <linux/platform_device.h>
19da65e367SBjorn Andersson #include <linux/regulator/driver.h>
20da65e367SBjorn Andersson #include <linux/regulator/machine.h>
21da65e367SBjorn Andersson #include <linux/regulator/of_regulator.h>
22da65e367SBjorn Andersson #include <linux/soc/qcom/smd-rpm.h>
23da65e367SBjorn Andersson 
24da65e367SBjorn Andersson struct qcom_rpm_reg {
25da65e367SBjorn Andersson 	struct device *dev;
26da65e367SBjorn Andersson 
27da65e367SBjorn Andersson 	struct qcom_smd_rpm *rpm;
28da65e367SBjorn Andersson 
29da65e367SBjorn Andersson 	u32 type;
30da65e367SBjorn Andersson 	u32 id;
31da65e367SBjorn Andersson 
32da65e367SBjorn Andersson 	struct regulator_desc desc;
33da65e367SBjorn Andersson 
34da65e367SBjorn Andersson 	int is_enabled;
35da65e367SBjorn Andersson 	int uV;
36da65e367SBjorn Andersson };
37da65e367SBjorn Andersson 
38da65e367SBjorn Andersson struct rpm_regulator_req {
392c652a98SStephen Boyd 	__le32 key;
402c652a98SStephen Boyd 	__le32 nbytes;
412c652a98SStephen Boyd 	__le32 value;
42da65e367SBjorn Andersson };
43da65e367SBjorn Andersson 
44da65e367SBjorn Andersson #define RPM_KEY_SWEN	0x6e657773 /* "swen" */
45da65e367SBjorn Andersson #define RPM_KEY_UV	0x00007675 /* "uv" */
46da65e367SBjorn Andersson #define RPM_KEY_MA	0x0000616d /* "ma" */
47da65e367SBjorn Andersson 
48da65e367SBjorn Andersson static int rpm_reg_write_active(struct qcom_rpm_reg *vreg,
49da65e367SBjorn Andersson 				struct rpm_regulator_req *req,
50da65e367SBjorn Andersson 				size_t size)
51da65e367SBjorn Andersson {
52da65e367SBjorn Andersson 	return qcom_rpm_smd_write(vreg->rpm,
53da65e367SBjorn Andersson 				  QCOM_SMD_RPM_ACTIVE_STATE,
54da65e367SBjorn Andersson 				  vreg->type,
55da65e367SBjorn Andersson 				  vreg->id,
56da65e367SBjorn Andersson 				  req, size);
57da65e367SBjorn Andersson }
58da65e367SBjorn Andersson 
59da65e367SBjorn Andersson static int rpm_reg_enable(struct regulator_dev *rdev)
60da65e367SBjorn Andersson {
61da65e367SBjorn Andersson 	struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
62da65e367SBjorn Andersson 	struct rpm_regulator_req req;
63da65e367SBjorn Andersson 	int ret;
64da65e367SBjorn Andersson 
652c652a98SStephen Boyd 	req.key = cpu_to_le32(RPM_KEY_SWEN);
662c652a98SStephen Boyd 	req.nbytes = cpu_to_le32(sizeof(u32));
672c652a98SStephen Boyd 	req.value = cpu_to_le32(1);
68da65e367SBjorn Andersson 
69da65e367SBjorn Andersson 	ret = rpm_reg_write_active(vreg, &req, sizeof(req));
70da65e367SBjorn Andersson 	if (!ret)
71da65e367SBjorn Andersson 		vreg->is_enabled = 1;
72da65e367SBjorn Andersson 
73da65e367SBjorn Andersson 	return ret;
74da65e367SBjorn Andersson }
75da65e367SBjorn Andersson 
76da65e367SBjorn Andersson static int rpm_reg_is_enabled(struct regulator_dev *rdev)
77da65e367SBjorn Andersson {
78da65e367SBjorn Andersson 	struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
79da65e367SBjorn Andersson 
80da65e367SBjorn Andersson 	return vreg->is_enabled;
81da65e367SBjorn Andersson }
82da65e367SBjorn Andersson 
83da65e367SBjorn Andersson static int rpm_reg_disable(struct regulator_dev *rdev)
84da65e367SBjorn Andersson {
85da65e367SBjorn Andersson 	struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
86da65e367SBjorn Andersson 	struct rpm_regulator_req req;
87da65e367SBjorn Andersson 	int ret;
88da65e367SBjorn Andersson 
892c652a98SStephen Boyd 	req.key = cpu_to_le32(RPM_KEY_SWEN);
902c652a98SStephen Boyd 	req.nbytes = cpu_to_le32(sizeof(u32));
91da65e367SBjorn Andersson 	req.value = 0;
92da65e367SBjorn Andersson 
93da65e367SBjorn Andersson 	ret = rpm_reg_write_active(vreg, &req, sizeof(req));
94da65e367SBjorn Andersson 	if (!ret)
95da65e367SBjorn Andersson 		vreg->is_enabled = 0;
96da65e367SBjorn Andersson 
97da65e367SBjorn Andersson 	return ret;
98da65e367SBjorn Andersson }
99da65e367SBjorn Andersson 
100da65e367SBjorn Andersson static int rpm_reg_get_voltage(struct regulator_dev *rdev)
101da65e367SBjorn Andersson {
102da65e367SBjorn Andersson 	struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
103da65e367SBjorn Andersson 
104da65e367SBjorn Andersson 	return vreg->uV;
105da65e367SBjorn Andersson }
106da65e367SBjorn Andersson 
107da65e367SBjorn Andersson static int rpm_reg_set_voltage(struct regulator_dev *rdev,
108da65e367SBjorn Andersson 			       int min_uV,
109da65e367SBjorn Andersson 			       int max_uV,
110da65e367SBjorn Andersson 			       unsigned *selector)
111da65e367SBjorn Andersson {
112da65e367SBjorn Andersson 	struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
113da65e367SBjorn Andersson 	struct rpm_regulator_req req;
114da65e367SBjorn Andersson 	int ret = 0;
115da65e367SBjorn Andersson 
1162c652a98SStephen Boyd 	req.key = cpu_to_le32(RPM_KEY_UV);
1172c652a98SStephen Boyd 	req.nbytes = cpu_to_le32(sizeof(u32));
1182c652a98SStephen Boyd 	req.value = cpu_to_le32(min_uV);
119da65e367SBjorn Andersson 
120da65e367SBjorn Andersson 	ret = rpm_reg_write_active(vreg, &req, sizeof(req));
121da65e367SBjorn Andersson 	if (!ret)
122da65e367SBjorn Andersson 		vreg->uV = min_uV;
123da65e367SBjorn Andersson 
124da65e367SBjorn Andersson 	return ret;
125da65e367SBjorn Andersson }
126da65e367SBjorn Andersson 
127da65e367SBjorn Andersson static int rpm_reg_set_load(struct regulator_dev *rdev, int load_uA)
128da65e367SBjorn Andersson {
129da65e367SBjorn Andersson 	struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
130da65e367SBjorn Andersson 	struct rpm_regulator_req req;
131da65e367SBjorn Andersson 
1322c652a98SStephen Boyd 	req.key = cpu_to_le32(RPM_KEY_MA);
1332c652a98SStephen Boyd 	req.nbytes = cpu_to_le32(sizeof(u32));
134a3e123c1SBjorn Andersson 	req.value = cpu_to_le32(load_uA / 1000);
135da65e367SBjorn Andersson 
136da65e367SBjorn Andersson 	return rpm_reg_write_active(vreg, &req, sizeof(req));
137da65e367SBjorn Andersson }
138da65e367SBjorn Andersson 
139da65e367SBjorn Andersson static const struct regulator_ops rpm_smps_ldo_ops = {
140da65e367SBjorn Andersson 	.enable = rpm_reg_enable,
141da65e367SBjorn Andersson 	.disable = rpm_reg_disable,
142da65e367SBjorn Andersson 	.is_enabled = rpm_reg_is_enabled,
143a8a47540SSrinivas Kandagatla 	.list_voltage = regulator_list_voltage_linear_range,
144da65e367SBjorn Andersson 
145da65e367SBjorn Andersson 	.get_voltage = rpm_reg_get_voltage,
146da65e367SBjorn Andersson 	.set_voltage = rpm_reg_set_voltage,
147da65e367SBjorn Andersson 
148da65e367SBjorn Andersson 	.set_load = rpm_reg_set_load,
149da65e367SBjorn Andersson };
150da65e367SBjorn Andersson 
151d1e44b6bSSrinivas Kandagatla static const struct regulator_ops rpm_smps_ldo_ops_fixed = {
152d1e44b6bSSrinivas Kandagatla 	.enable = rpm_reg_enable,
153d1e44b6bSSrinivas Kandagatla 	.disable = rpm_reg_disable,
154d1e44b6bSSrinivas Kandagatla 	.is_enabled = rpm_reg_is_enabled,
155d1e44b6bSSrinivas Kandagatla 
156d1e44b6bSSrinivas Kandagatla 	.get_voltage = rpm_reg_get_voltage,
157d1e44b6bSSrinivas Kandagatla 	.set_voltage = rpm_reg_set_voltage,
158d1e44b6bSSrinivas Kandagatla 
159d1e44b6bSSrinivas Kandagatla 	.set_load = rpm_reg_set_load,
160d1e44b6bSSrinivas Kandagatla };
161d1e44b6bSSrinivas Kandagatla 
162da65e367SBjorn Andersson static const struct regulator_ops rpm_switch_ops = {
163da65e367SBjorn Andersson 	.enable = rpm_reg_enable,
164da65e367SBjorn Andersson 	.disable = rpm_reg_disable,
165da65e367SBjorn Andersson 	.is_enabled = rpm_reg_is_enabled,
166da65e367SBjorn Andersson };
167da65e367SBjorn Andersson 
168ee01d0c9SAndy Gross static const struct regulator_desc pma8084_hfsmps = {
169ee01d0c9SAndy Gross 	.linear_ranges = (struct regulator_linear_range[]) {
170ee01d0c9SAndy Gross 		REGULATOR_LINEAR_RANGE(375000,  0,  95, 12500),
171ee01d0c9SAndy Gross 		REGULATOR_LINEAR_RANGE(1550000, 96, 158, 25000),
172ee01d0c9SAndy Gross 	},
173ee01d0c9SAndy Gross 	.n_linear_ranges = 2,
174ee01d0c9SAndy Gross 	.n_voltages = 159,
175ee01d0c9SAndy Gross 	.ops = &rpm_smps_ldo_ops,
176ee01d0c9SAndy Gross };
177ee01d0c9SAndy Gross 
178ee01d0c9SAndy Gross static const struct regulator_desc pma8084_ftsmps = {
179ee01d0c9SAndy Gross 	.linear_ranges = (struct regulator_linear_range[]) {
180ee01d0c9SAndy Gross 		REGULATOR_LINEAR_RANGE(350000,  0, 184, 5000),
181c488f007SStephen Boyd 		REGULATOR_LINEAR_RANGE(1280000, 185, 261, 10000),
182ee01d0c9SAndy Gross 	},
183ee01d0c9SAndy Gross 	.n_linear_ranges = 2,
184c488f007SStephen Boyd 	.n_voltages = 262,
185ee01d0c9SAndy Gross 	.ops = &rpm_smps_ldo_ops,
186ee01d0c9SAndy Gross };
187ee01d0c9SAndy Gross 
188ee01d0c9SAndy Gross static const struct regulator_desc pma8084_pldo = {
189ee01d0c9SAndy Gross 	.linear_ranges = (struct regulator_linear_range[]) {
190c488f007SStephen Boyd 		REGULATOR_LINEAR_RANGE( 750000,  0,  63, 12500),
191c488f007SStephen Boyd 		REGULATOR_LINEAR_RANGE(1550000, 64, 126, 25000),
192c488f007SStephen Boyd 		REGULATOR_LINEAR_RANGE(3100000, 127, 163, 50000),
193ee01d0c9SAndy Gross 	},
194c488f007SStephen Boyd 	.n_linear_ranges = 3,
195c488f007SStephen Boyd 	.n_voltages = 164,
196ee01d0c9SAndy Gross 	.ops = &rpm_smps_ldo_ops,
197ee01d0c9SAndy Gross };
198ee01d0c9SAndy Gross 
199ee01d0c9SAndy Gross static const struct regulator_desc pma8084_nldo = {
200ee01d0c9SAndy Gross 	.linear_ranges = (struct regulator_linear_range[]) {
201ee01d0c9SAndy Gross 		REGULATOR_LINEAR_RANGE(750000, 0, 63, 12500),
202ee01d0c9SAndy Gross 	},
203ee01d0c9SAndy Gross 	.n_linear_ranges = 1,
204ee01d0c9SAndy Gross 	.n_voltages = 64,
205ee01d0c9SAndy Gross 	.ops = &rpm_smps_ldo_ops,
206ee01d0c9SAndy Gross };
207ee01d0c9SAndy Gross 
208ee01d0c9SAndy Gross static const struct regulator_desc pma8084_switch = {
209ee01d0c9SAndy Gross 	.ops = &rpm_switch_ops,
210ee01d0c9SAndy Gross };
211ee01d0c9SAndy Gross 
212da65e367SBjorn Andersson static const struct regulator_desc pm8x41_hfsmps = {
213da65e367SBjorn Andersson 	.linear_ranges = (struct regulator_linear_range[]) {
214da65e367SBjorn Andersson 		REGULATOR_LINEAR_RANGE( 375000,  0,  95, 12500),
215b7a8524cSStephen Boyd 		REGULATOR_LINEAR_RANGE(1575000, 96, 158, 25000),
216da65e367SBjorn Andersson 	},
217da65e367SBjorn Andersson 	.n_linear_ranges = 2,
218da65e367SBjorn Andersson 	.n_voltages = 159,
219da65e367SBjorn Andersson 	.ops = &rpm_smps_ldo_ops,
220da65e367SBjorn Andersson };
221da65e367SBjorn Andersson 
222da65e367SBjorn Andersson static const struct regulator_desc pm8841_ftsmps = {
223da65e367SBjorn Andersson 	.linear_ranges = (struct regulator_linear_range[]) {
224da65e367SBjorn Andersson 		REGULATOR_LINEAR_RANGE(350000,  0, 184, 5000),
22529028477SStephen Boyd 		REGULATOR_LINEAR_RANGE(1280000, 185, 261, 10000),
226da65e367SBjorn Andersson 	},
227da65e367SBjorn Andersson 	.n_linear_ranges = 2,
22829028477SStephen Boyd 	.n_voltages = 262,
229da65e367SBjorn Andersson 	.ops = &rpm_smps_ldo_ops,
230da65e367SBjorn Andersson };
231da65e367SBjorn Andersson 
232da65e367SBjorn Andersson static const struct regulator_desc pm8941_boost = {
233da65e367SBjorn Andersson 	.linear_ranges = (struct regulator_linear_range[]) {
23429028477SStephen Boyd 		REGULATOR_LINEAR_RANGE(4000000, 0, 30, 50000),
235da65e367SBjorn Andersson 	},
236da65e367SBjorn Andersson 	.n_linear_ranges = 1,
23729028477SStephen Boyd 	.n_voltages = 31,
238da65e367SBjorn Andersson 	.ops = &rpm_smps_ldo_ops,
239da65e367SBjorn Andersson };
240da65e367SBjorn Andersson 
241da65e367SBjorn Andersson static const struct regulator_desc pm8941_pldo = {
242da65e367SBjorn Andersson 	.linear_ranges = (struct regulator_linear_range[]) {
24329028477SStephen Boyd 		REGULATOR_LINEAR_RANGE( 750000,  0,  63, 12500),
24429028477SStephen Boyd 		REGULATOR_LINEAR_RANGE(1550000, 64, 126, 25000),
24529028477SStephen Boyd 		REGULATOR_LINEAR_RANGE(3100000, 127, 163, 50000),
246da65e367SBjorn Andersson 	},
24729028477SStephen Boyd 	.n_linear_ranges = 3,
24829028477SStephen Boyd 	.n_voltages = 164,
249da65e367SBjorn Andersson 	.ops = &rpm_smps_ldo_ops,
250da65e367SBjorn Andersson };
251da65e367SBjorn Andersson 
252da65e367SBjorn Andersson static const struct regulator_desc pm8941_nldo = {
253da65e367SBjorn Andersson 	.linear_ranges = (struct regulator_linear_range[]) {
254da65e367SBjorn Andersson 		REGULATOR_LINEAR_RANGE(750000, 0, 63, 12500),
255da65e367SBjorn Andersson 	},
256da65e367SBjorn Andersson 	.n_linear_ranges = 1,
257da65e367SBjorn Andersson 	.n_voltages = 64,
258da65e367SBjorn Andersson 	.ops = &rpm_smps_ldo_ops,
259da65e367SBjorn Andersson };
260da65e367SBjorn Andersson 
261da65e367SBjorn Andersson static const struct regulator_desc pm8941_lnldo = {
262da65e367SBjorn Andersson 	.fixed_uV = 1740000,
2635a286aaeSAxel Lin 	.n_voltages = 1,
264d1e44b6bSSrinivas Kandagatla 	.ops = &rpm_smps_ldo_ops_fixed,
265da65e367SBjorn Andersson };
266da65e367SBjorn Andersson 
267da65e367SBjorn Andersson static const struct regulator_desc pm8941_switch = {
268da65e367SBjorn Andersson 	.ops = &rpm_switch_ops,
269da65e367SBjorn Andersson };
270da65e367SBjorn Andersson 
27157d65676SAndy Gross static const struct regulator_desc pm8916_pldo = {
27257d65676SAndy Gross 	.linear_ranges = (struct regulator_linear_range[]) {
27357d65676SAndy Gross 		REGULATOR_LINEAR_RANGE(750000, 0, 208, 12500),
27457d65676SAndy Gross 	},
27557d65676SAndy Gross 	.n_linear_ranges = 1,
27657d65676SAndy Gross 	.n_voltages = 209,
27757d65676SAndy Gross 	.ops = &rpm_smps_ldo_ops,
27857d65676SAndy Gross };
27957d65676SAndy Gross 
28057d65676SAndy Gross static const struct regulator_desc pm8916_nldo = {
28157d65676SAndy Gross 	.linear_ranges = (struct regulator_linear_range[]) {
28257d65676SAndy Gross 		REGULATOR_LINEAR_RANGE(375000, 0, 93, 12500),
28357d65676SAndy Gross 	},
28457d65676SAndy Gross 	.n_linear_ranges = 1,
28557d65676SAndy Gross 	.n_voltages = 94,
28657d65676SAndy Gross 	.ops = &rpm_smps_ldo_ops,
28757d65676SAndy Gross };
28857d65676SAndy Gross 
28957d65676SAndy Gross static const struct regulator_desc pm8916_buck_lvo_smps = {
29057d65676SAndy Gross 	.linear_ranges = (struct regulator_linear_range[]) {
29157d65676SAndy Gross 		REGULATOR_LINEAR_RANGE(375000, 0, 95, 12500),
29257d65676SAndy Gross 		REGULATOR_LINEAR_RANGE(750000, 96, 127, 25000),
29357d65676SAndy Gross 	},
29457d65676SAndy Gross 	.n_linear_ranges = 2,
29557d65676SAndy Gross 	.n_voltages = 128,
29657d65676SAndy Gross 	.ops = &rpm_smps_ldo_ops,
29757d65676SAndy Gross };
29857d65676SAndy Gross 
29957d65676SAndy Gross static const struct regulator_desc pm8916_buck_hvo_smps = {
30057d65676SAndy Gross 	.linear_ranges = (struct regulator_linear_range[]) {
30157d65676SAndy Gross 		REGULATOR_LINEAR_RANGE(1550000, 0, 31, 25000),
30257d65676SAndy Gross 	},
30357d65676SAndy Gross 	.n_linear_ranges = 1,
30457d65676SAndy Gross 	.n_voltages = 32,
30557d65676SAndy Gross 	.ops = &rpm_smps_ldo_ops,
30657d65676SAndy Gross };
30757d65676SAndy Gross 
30814a16992SRajendra Nayak static const struct regulator_desc pm8994_hfsmps = {
30914a16992SRajendra Nayak 	.linear_ranges = (struct regulator_linear_range[]) {
31014a16992SRajendra Nayak 		REGULATOR_LINEAR_RANGE( 375000,  0,  95, 12500),
31114a16992SRajendra Nayak 		REGULATOR_LINEAR_RANGE(1550000, 96, 158, 25000),
31214a16992SRajendra Nayak 	},
31314a16992SRajendra Nayak 	.n_linear_ranges = 2,
31414a16992SRajendra Nayak 	.n_voltages = 159,
31514a16992SRajendra Nayak 	.ops = &rpm_smps_ldo_ops,
31614a16992SRajendra Nayak };
31714a16992SRajendra Nayak 
31814a16992SRajendra Nayak static const struct regulator_desc pm8994_ftsmps = {
31914a16992SRajendra Nayak 	.linear_ranges = (struct regulator_linear_range[]) {
32014a16992SRajendra Nayak 		REGULATOR_LINEAR_RANGE(350000,  0, 199, 5000),
32114a16992SRajendra Nayak 		REGULATOR_LINEAR_RANGE(700000, 200, 349, 10000),
32214a16992SRajendra Nayak 	},
32314a16992SRajendra Nayak 	.n_linear_ranges = 2,
32414a16992SRajendra Nayak 	.n_voltages = 350,
32514a16992SRajendra Nayak 	.ops = &rpm_smps_ldo_ops,
32614a16992SRajendra Nayak };
32714a16992SRajendra Nayak 
32814a16992SRajendra Nayak static const struct regulator_desc pm8994_nldo = {
32914a16992SRajendra Nayak 	.linear_ranges = (struct regulator_linear_range[]) {
33014a16992SRajendra Nayak 		REGULATOR_LINEAR_RANGE(750000, 0, 63, 12500),
33114a16992SRajendra Nayak 	},
33214a16992SRajendra Nayak 	.n_linear_ranges = 1,
33314a16992SRajendra Nayak 	.n_voltages = 64,
33414a16992SRajendra Nayak 	.ops = &rpm_smps_ldo_ops,
33514a16992SRajendra Nayak };
33614a16992SRajendra Nayak 
33714a16992SRajendra Nayak static const struct regulator_desc pm8994_pldo = {
33814a16992SRajendra Nayak 	.linear_ranges = (struct regulator_linear_range[]) {
33914a16992SRajendra Nayak 		REGULATOR_LINEAR_RANGE( 750000,  0,  63, 12500),
34014a16992SRajendra Nayak 		REGULATOR_LINEAR_RANGE(1550000, 64, 126, 25000),
34114a16992SRajendra Nayak 		REGULATOR_LINEAR_RANGE(3100000, 127, 163, 50000),
34214a16992SRajendra Nayak 	},
34314a16992SRajendra Nayak 	.n_linear_ranges = 3,
34414a16992SRajendra Nayak 	.n_voltages = 164,
34514a16992SRajendra Nayak 	.ops = &rpm_smps_ldo_ops,
34614a16992SRajendra Nayak };
34714a16992SRajendra Nayak 
34814a16992SRajendra Nayak static const struct regulator_desc pm8994_switch = {
34914a16992SRajendra Nayak 	.ops = &rpm_switch_ops,
35014a16992SRajendra Nayak };
35114a16992SRajendra Nayak 
35214a16992SRajendra Nayak static const struct regulator_desc pm8994_lnldo = {
35314a16992SRajendra Nayak 	.fixed_uV = 1740000,
35414a16992SRajendra Nayak 	.n_voltages = 1,
35514a16992SRajendra Nayak 	.ops = &rpm_smps_ldo_ops_fixed,
35614a16992SRajendra Nayak };
35714a16992SRajendra Nayak 
358da65e367SBjorn Andersson struct rpm_regulator_data {
359da65e367SBjorn Andersson 	const char *name;
360da65e367SBjorn Andersson 	u32 type;
361da65e367SBjorn Andersson 	u32 id;
362da65e367SBjorn Andersson 	const struct regulator_desc *desc;
363da65e367SBjorn Andersson 	const char *supply;
364da65e367SBjorn Andersson };
365da65e367SBjorn Andersson 
366da65e367SBjorn Andersson static const struct rpm_regulator_data rpm_pm8841_regulators[] = {
367da65e367SBjorn Andersson 	{ "s1", QCOM_SMD_RPM_SMPB, 1, &pm8x41_hfsmps, "vdd_s1" },
368da65e367SBjorn Andersson 	{ "s2", QCOM_SMD_RPM_SMPB, 2, &pm8841_ftsmps, "vdd_s2" },
369da65e367SBjorn Andersson 	{ "s3", QCOM_SMD_RPM_SMPB, 3, &pm8x41_hfsmps, "vdd_s3" },
370da65e367SBjorn Andersson 	{ "s4", QCOM_SMD_RPM_SMPB, 4, &pm8841_ftsmps, "vdd_s4" },
371da65e367SBjorn Andersson 	{ "s5", QCOM_SMD_RPM_SMPB, 5, &pm8841_ftsmps, "vdd_s5" },
372da65e367SBjorn Andersson 	{ "s6", QCOM_SMD_RPM_SMPB, 6, &pm8841_ftsmps, "vdd_s6" },
373da65e367SBjorn Andersson 	{ "s7", QCOM_SMD_RPM_SMPB, 7, &pm8841_ftsmps, "vdd_s7" },
374da65e367SBjorn Andersson 	{ "s8", QCOM_SMD_RPM_SMPB, 8, &pm8841_ftsmps, "vdd_s8" },
375da65e367SBjorn Andersson 	{}
376da65e367SBjorn Andersson };
377da65e367SBjorn Andersson 
37857d65676SAndy Gross static const struct rpm_regulator_data rpm_pm8916_regulators[] = {
37957d65676SAndy Gross 	{ "s1", QCOM_SMD_RPM_SMPA, 1, &pm8916_buck_lvo_smps, "vdd_s1" },
38057d65676SAndy Gross 	{ "s2", QCOM_SMD_RPM_SMPA, 2, &pm8916_buck_lvo_smps, "vdd_s2" },
38157d65676SAndy Gross 	{ "s3", QCOM_SMD_RPM_SMPA, 3, &pm8916_buck_lvo_smps, "vdd_s3" },
38257d65676SAndy Gross 	{ "s4", QCOM_SMD_RPM_SMPA, 4, &pm8916_buck_hvo_smps, "vdd_s4" },
38357d65676SAndy Gross 	{ "l1", QCOM_SMD_RPM_LDOA, 1, &pm8916_nldo, "vdd_l1_l2_l3" },
38457d65676SAndy Gross 	{ "l2", QCOM_SMD_RPM_LDOA, 2, &pm8916_nldo, "vdd_l1_l2_l3" },
38557d65676SAndy Gross 	{ "l3", QCOM_SMD_RPM_LDOA, 3, &pm8916_nldo, "vdd_l1_l2_l3" },
38657d65676SAndy Gross 	{ "l4", QCOM_SMD_RPM_LDOA, 4, &pm8916_pldo, "vdd_l4_l5_l6" },
38757d65676SAndy Gross 	{ "l5", QCOM_SMD_RPM_LDOA, 5, &pm8916_pldo, "vdd_l4_l5_l6" },
38857d65676SAndy Gross 	{ "l6", QCOM_SMD_RPM_LDOA, 6, &pm8916_pldo, "vdd_l4_l5_l6" },
38957d65676SAndy Gross 	{ "l7", QCOM_SMD_RPM_LDOA, 7, &pm8916_pldo, "vdd_l7" },
39057d65676SAndy Gross 	{ "l8", QCOM_SMD_RPM_LDOA, 8, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18" },
39157d65676SAndy Gross 	{ "l9", QCOM_SMD_RPM_LDOA, 9, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18" },
39257d65676SAndy Gross 	{ "l10", QCOM_SMD_RPM_LDOA, 10, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
39357d65676SAndy Gross 	{ "l11", QCOM_SMD_RPM_LDOA, 11, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
39457d65676SAndy Gross 	{ "l12", QCOM_SMD_RPM_LDOA, 12, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
39557d65676SAndy Gross 	{ "l13", QCOM_SMD_RPM_LDOA, 13, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
39657d65676SAndy Gross 	{ "l14", QCOM_SMD_RPM_LDOA, 14, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
39757d65676SAndy Gross 	{ "l15", QCOM_SMD_RPM_LDOA, 15, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
39857d65676SAndy Gross 	{ "l16", QCOM_SMD_RPM_LDOA, 16, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
39957d65676SAndy Gross 	{ "l17", QCOM_SMD_RPM_LDOA, 17, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
40057d65676SAndy Gross 	{ "l18", QCOM_SMD_RPM_LDOA, 18, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
40157d65676SAndy Gross 	{}
40257d65676SAndy Gross };
40357d65676SAndy Gross 
404da65e367SBjorn Andersson static const struct rpm_regulator_data rpm_pm8941_regulators[] = {
405da65e367SBjorn Andersson 	{ "s1", QCOM_SMD_RPM_SMPA, 1, &pm8x41_hfsmps, "vdd_s1" },
406da65e367SBjorn Andersson 	{ "s2", QCOM_SMD_RPM_SMPA, 2, &pm8x41_hfsmps, "vdd_s2" },
407da65e367SBjorn Andersson 	{ "s3", QCOM_SMD_RPM_SMPA, 3, &pm8x41_hfsmps, "vdd_s3" },
408da65e367SBjorn Andersson 	{ "s4", QCOM_SMD_RPM_BOOST, 1, &pm8941_boost },
409da65e367SBjorn Andersson 
410da65e367SBjorn Andersson 	{ "l1", QCOM_SMD_RPM_LDOA, 1, &pm8941_nldo, "vdd_l1_l3" },
411da65e367SBjorn Andersson 	{ "l2", QCOM_SMD_RPM_LDOA, 2, &pm8941_nldo, "vdd_l2_lvs1_2_3" },
412da65e367SBjorn Andersson 	{ "l3", QCOM_SMD_RPM_LDOA, 3, &pm8941_nldo, "vdd_l1_l3" },
413da65e367SBjorn Andersson 	{ "l4", QCOM_SMD_RPM_LDOA, 4, &pm8941_nldo, "vdd_l4_l11" },
414da65e367SBjorn Andersson 	{ "l5", QCOM_SMD_RPM_LDOA, 5, &pm8941_lnldo, "vdd_l5_l7" },
415da65e367SBjorn Andersson 	{ "l6", QCOM_SMD_RPM_LDOA, 6, &pm8941_pldo, "vdd_l6_l12_l14_l15" },
416da65e367SBjorn Andersson 	{ "l7", QCOM_SMD_RPM_LDOA, 7, &pm8941_lnldo, "vdd_l5_l7" },
417da65e367SBjorn Andersson 	{ "l8", QCOM_SMD_RPM_LDOA, 8, &pm8941_pldo, "vdd_l8_l16_l18_l19" },
418da65e367SBjorn Andersson 	{ "l9", QCOM_SMD_RPM_LDOA, 9, &pm8941_pldo, "vdd_l9_l10_l17_l22" },
419da65e367SBjorn Andersson 	{ "l10", QCOM_SMD_RPM_LDOA, 10, &pm8941_pldo, "vdd_l9_l10_l17_l22" },
420da65e367SBjorn Andersson 	{ "l11", QCOM_SMD_RPM_LDOA, 11, &pm8941_nldo, "vdd_l4_l11" },
421da65e367SBjorn Andersson 	{ "l12", QCOM_SMD_RPM_LDOA, 12, &pm8941_pldo, "vdd_l6_l12_l14_l15" },
422da65e367SBjorn Andersson 	{ "l13", QCOM_SMD_RPM_LDOA, 13, &pm8941_pldo, "vdd_l13_l20_l23_l24" },
423da65e367SBjorn Andersson 	{ "l14", QCOM_SMD_RPM_LDOA, 14, &pm8941_pldo, "vdd_l6_l12_l14_l15" },
424da65e367SBjorn Andersson 	{ "l15", QCOM_SMD_RPM_LDOA, 15, &pm8941_pldo, "vdd_l6_l12_l14_l15" },
425da65e367SBjorn Andersson 	{ "l16", QCOM_SMD_RPM_LDOA, 16, &pm8941_pldo, "vdd_l8_l16_l18_l19" },
426da65e367SBjorn Andersson 	{ "l17", QCOM_SMD_RPM_LDOA, 17, &pm8941_pldo, "vdd_l9_l10_l17_l22" },
427da65e367SBjorn Andersson 	{ "l18", QCOM_SMD_RPM_LDOA, 18, &pm8941_pldo, "vdd_l8_l16_l18_l19" },
428da65e367SBjorn Andersson 	{ "l19", QCOM_SMD_RPM_LDOA, 19, &pm8941_pldo, "vdd_l8_l16_l18_l19" },
429da65e367SBjorn Andersson 	{ "l20", QCOM_SMD_RPM_LDOA, 20, &pm8941_pldo, "vdd_l13_l20_l23_l24" },
430da65e367SBjorn Andersson 	{ "l21", QCOM_SMD_RPM_LDOA, 21, &pm8941_pldo, "vdd_l21" },
431da65e367SBjorn Andersson 	{ "l22", QCOM_SMD_RPM_LDOA, 22, &pm8941_pldo, "vdd_l9_l10_l17_l22" },
432da65e367SBjorn Andersson 	{ "l23", QCOM_SMD_RPM_LDOA, 23, &pm8941_pldo, "vdd_l13_l20_l23_l24" },
433da65e367SBjorn Andersson 	{ "l24", QCOM_SMD_RPM_LDOA, 24, &pm8941_pldo, "vdd_l13_l20_l23_l24" },
434da65e367SBjorn Andersson 
435da65e367SBjorn Andersson 	{ "lvs1", QCOM_SMD_RPM_VSA, 1, &pm8941_switch, "vdd_l2_lvs1_2_3" },
436da65e367SBjorn Andersson 	{ "lvs2", QCOM_SMD_RPM_VSA, 2, &pm8941_switch, "vdd_l2_lvs1_2_3" },
437da65e367SBjorn Andersson 	{ "lvs3", QCOM_SMD_RPM_VSA, 3, &pm8941_switch, "vdd_l2_lvs1_2_3" },
438da65e367SBjorn Andersson 
439da65e367SBjorn Andersson 	{ "5vs1", QCOM_SMD_RPM_VSA, 4, &pm8941_switch, "vin_5vs" },
440da65e367SBjorn Andersson 	{ "5vs2", QCOM_SMD_RPM_VSA, 5, &pm8941_switch, "vin_5vs" },
441da65e367SBjorn Andersson 
442da65e367SBjorn Andersson 	{}
443da65e367SBjorn Andersson };
444da65e367SBjorn Andersson 
445ee01d0c9SAndy Gross static const struct rpm_regulator_data rpm_pma8084_regulators[] = {
446ee01d0c9SAndy Gross 	{ "s1", QCOM_SMD_RPM_SMPA, 1, &pma8084_ftsmps, "vdd_s1" },
447ee01d0c9SAndy Gross 	{ "s2", QCOM_SMD_RPM_SMPA, 2, &pma8084_ftsmps, "vdd_s2" },
448ee01d0c9SAndy Gross 	{ "s3", QCOM_SMD_RPM_SMPA, 3, &pma8084_hfsmps, "vdd_s3" },
449ee01d0c9SAndy Gross 	{ "s4", QCOM_SMD_RPM_SMPA, 4, &pma8084_hfsmps, "vdd_s4" },
450ee01d0c9SAndy Gross 	{ "s5", QCOM_SMD_RPM_SMPA, 5, &pma8084_hfsmps, "vdd_s5" },
451ee01d0c9SAndy Gross 	{ "s6", QCOM_SMD_RPM_SMPA, 6, &pma8084_ftsmps, "vdd_s6" },
452ee01d0c9SAndy Gross 	{ "s7", QCOM_SMD_RPM_SMPA, 7, &pma8084_ftsmps, "vdd_s7" },
453ee01d0c9SAndy Gross 	{ "s8", QCOM_SMD_RPM_SMPA, 8, &pma8084_ftsmps, "vdd_s8" },
454ee01d0c9SAndy Gross 	{ "s9", QCOM_SMD_RPM_SMPA, 9, &pma8084_ftsmps, "vdd_s9" },
455ee01d0c9SAndy Gross 	{ "s10", QCOM_SMD_RPM_SMPA, 10, &pma8084_ftsmps, "vdd_s10" },
456ee01d0c9SAndy Gross 	{ "s11", QCOM_SMD_RPM_SMPA, 11, &pma8084_ftsmps, "vdd_s11" },
457ee01d0c9SAndy Gross 	{ "s12", QCOM_SMD_RPM_SMPA, 12, &pma8084_ftsmps, "vdd_s12" },
458ee01d0c9SAndy Gross 
459ee01d0c9SAndy Gross 	{ "l1", QCOM_SMD_RPM_LDOA, 1, &pma8084_nldo, "vdd_l1_l11" },
460ee01d0c9SAndy Gross 	{ "l2", QCOM_SMD_RPM_LDOA, 2, &pma8084_nldo, "vdd_l2_l3_l4_l27" },
461ee01d0c9SAndy Gross 	{ "l3", QCOM_SMD_RPM_LDOA, 3, &pma8084_nldo, "vdd_l2_l3_l4_l27" },
462ee01d0c9SAndy Gross 	{ "l4", QCOM_SMD_RPM_LDOA, 4, &pma8084_nldo, "vdd_l2_l3_l4_l27" },
463ee01d0c9SAndy Gross 	{ "l5", QCOM_SMD_RPM_LDOA, 5, &pma8084_pldo, "vdd_l5_l7" },
464ee01d0c9SAndy Gross 	{ "l6", QCOM_SMD_RPM_LDOA, 6, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
465ee01d0c9SAndy Gross 	{ "l7", QCOM_SMD_RPM_LDOA, 7, &pma8084_pldo, "vdd_l5_l7" },
466ee01d0c9SAndy Gross 	{ "l8", QCOM_SMD_RPM_LDOA, 8, &pma8084_pldo, "vdd_l8" },
467ee01d0c9SAndy Gross 	{ "l9", QCOM_SMD_RPM_LDOA, 9, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
468ee01d0c9SAndy Gross 	{ "l10", QCOM_SMD_RPM_LDOA, 10, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
469ee01d0c9SAndy Gross 	{ "l11", QCOM_SMD_RPM_LDOA, 11, &pma8084_nldo, "vdd_l1_l11" },
470ee01d0c9SAndy Gross 	{ "l12", QCOM_SMD_RPM_LDOA, 12, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
471ee01d0c9SAndy Gross 	{ "l13", QCOM_SMD_RPM_LDOA, 13, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
472ee01d0c9SAndy Gross 	{ "l14", QCOM_SMD_RPM_LDOA, 14, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
473ee01d0c9SAndy Gross 	{ "l15", QCOM_SMD_RPM_LDOA, 15, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
474ee01d0c9SAndy Gross 	{ "l16", QCOM_SMD_RPM_LDOA, 16, &pma8084_pldo, "vdd_l16_l25" },
475ee01d0c9SAndy Gross 	{ "l17", QCOM_SMD_RPM_LDOA, 17, &pma8084_pldo, "vdd_l17" },
476ee01d0c9SAndy Gross 	{ "l18", QCOM_SMD_RPM_LDOA, 18, &pma8084_pldo, "vdd_l18" },
477ee01d0c9SAndy Gross 	{ "l19", QCOM_SMD_RPM_LDOA, 19, &pma8084_pldo, "vdd_l19" },
478ee01d0c9SAndy Gross 	{ "l20", QCOM_SMD_RPM_LDOA, 20, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
479ee01d0c9SAndy Gross 	{ "l21", QCOM_SMD_RPM_LDOA, 21, &pma8084_pldo, "vdd_l21" },
480ee01d0c9SAndy Gross 	{ "l22", QCOM_SMD_RPM_LDOA, 22, &pma8084_pldo, "vdd_l22" },
481ee01d0c9SAndy Gross 	{ "l23", QCOM_SMD_RPM_LDOA, 23, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
482ee01d0c9SAndy Gross 	{ "l24", QCOM_SMD_RPM_LDOA, 24, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
483ee01d0c9SAndy Gross 	{ "l25", QCOM_SMD_RPM_LDOA, 25, &pma8084_pldo, "vdd_l16_l25" },
484ee01d0c9SAndy Gross 	{ "l26", QCOM_SMD_RPM_LDOA, 26, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
485ee01d0c9SAndy Gross 	{ "l27", QCOM_SMD_RPM_LDOA, 27, &pma8084_nldo, "vdd_l2_l3_l4_l27" },
486ee01d0c9SAndy Gross 
487ee01d0c9SAndy Gross 	{ "lvs1", QCOM_SMD_RPM_VSA, 1, &pma8084_switch },
488ee01d0c9SAndy Gross 	{ "lvs2", QCOM_SMD_RPM_VSA, 2, &pma8084_switch },
489ee01d0c9SAndy Gross 	{ "lvs3", QCOM_SMD_RPM_VSA, 3, &pma8084_switch },
490ee01d0c9SAndy Gross 	{ "lvs4", QCOM_SMD_RPM_VSA, 4, &pma8084_switch },
491ee01d0c9SAndy Gross 	{ "5vs1", QCOM_SMD_RPM_VSA, 5, &pma8084_switch },
492ee01d0c9SAndy Gross 
493ee01d0c9SAndy Gross 	{}
494ee01d0c9SAndy Gross };
495ee01d0c9SAndy Gross 
49614a16992SRajendra Nayak static const struct rpm_regulator_data rpm_pm8994_regulators[] = {
49714a16992SRajendra Nayak 	{ "s1", QCOM_SMD_RPM_SMPA, 1, &pm8994_ftsmps, "vdd_s1" },
49814a16992SRajendra Nayak 	{ "s2", QCOM_SMD_RPM_SMPA, 2, &pm8994_ftsmps, "vdd_s2" },
49914a16992SRajendra Nayak 	{ "s3", QCOM_SMD_RPM_SMPA, 3, &pm8994_hfsmps, "vdd_s3" },
50014a16992SRajendra Nayak 	{ "s4", QCOM_SMD_RPM_SMPA, 4, &pm8994_hfsmps, "vdd_s4" },
50114a16992SRajendra Nayak 	{ "s5", QCOM_SMD_RPM_SMPA, 5, &pm8994_hfsmps, "vdd_s5" },
50214a16992SRajendra Nayak 	{ "s6", QCOM_SMD_RPM_SMPA, 6, &pm8994_ftsmps, "vdd_s6" },
50314a16992SRajendra Nayak 	{ "s7", QCOM_SMD_RPM_SMPA, 7, &pm8994_hfsmps, "vdd_s7" },
50414a16992SRajendra Nayak 	{ "s8", QCOM_SMD_RPM_SMPA, 8, &pm8994_ftsmps, "vdd_s8" },
50514a16992SRajendra Nayak 	{ "s9", QCOM_SMD_RPM_SMPA, 9, &pm8994_ftsmps, "vdd_s9" },
50614a16992SRajendra Nayak 	{ "s10", QCOM_SMD_RPM_SMPA, 10, &pm8994_ftsmps, "vdd_s10" },
50714a16992SRajendra Nayak 	{ "s11", QCOM_SMD_RPM_SMPA, 11, &pm8994_ftsmps, "vdd_s11" },
50814a16992SRajendra Nayak 	{ "s12", QCOM_SMD_RPM_SMPA, 12, &pm8994_ftsmps, "vdd_s12" },
50914a16992SRajendra Nayak 	{ "l1", QCOM_SMD_RPM_LDOA, 1, &pm8994_nldo, "vdd_l1" },
51014a16992SRajendra Nayak 	{ "l2", QCOM_SMD_RPM_LDOA, 2, &pm8994_nldo, "vdd_l2_l26_l28" },
51114a16992SRajendra Nayak 	{ "l3", QCOM_SMD_RPM_LDOA, 3, &pm8994_nldo, "vdd_l3_l11" },
51214a16992SRajendra Nayak 	{ "l4", QCOM_SMD_RPM_LDOA, 4, &pm8994_nldo, "vdd_l4_l27_l31" },
51314a16992SRajendra Nayak 	{ "l5", QCOM_SMD_RPM_LDOA, 5, &pm8994_lnldo, "vdd_l5_l7" },
51414a16992SRajendra Nayak 	{ "l6", QCOM_SMD_RPM_LDOA, 6, &pm8994_pldo, "vdd_l6_l12_l32" },
51514a16992SRajendra Nayak 	{ "l7", QCOM_SMD_RPM_LDOA, 7, &pm8994_lnldo, "vdd_l5_l7" },
51614a16992SRajendra Nayak 	{ "l8", QCOM_SMD_RPM_LDOA, 8, &pm8994_pldo, "vdd_l8_l16_l30" },
51714a16992SRajendra Nayak 	{ "l9", QCOM_SMD_RPM_LDOA, 9, &pm8994_pldo, "vdd_l9_l10_l18_l22" },
51814a16992SRajendra Nayak 	{ "l10", QCOM_SMD_RPM_LDOA, 10, &pm8994_pldo, "vdd_l9_l10_l18_l22" },
51914a16992SRajendra Nayak 	{ "l11", QCOM_SMD_RPM_LDOA, 11, &pm8994_nldo, "vdd_l3_l11" },
52014a16992SRajendra Nayak 	{ "l12", QCOM_SMD_RPM_LDOA, 12, &pm8994_pldo, "vdd_l6_l12_l32" },
52114a16992SRajendra Nayak 	{ "l13", QCOM_SMD_RPM_LDOA, 13, &pm8994_pldo, "vdd_l13_l19_l23_l24" },
52214a16992SRajendra Nayak 	{ "l14", QCOM_SMD_RPM_LDOA, 14, &pm8994_pldo, "vdd_l14_l15" },
52314a16992SRajendra Nayak 	{ "l15", QCOM_SMD_RPM_LDOA, 15, &pm8994_pldo, "vdd_l14_l15" },
52414a16992SRajendra Nayak 	{ "l16", QCOM_SMD_RPM_LDOA, 16, &pm8994_pldo, "vdd_l8_l16_l30" },
52514a16992SRajendra Nayak 	{ "l17", QCOM_SMD_RPM_LDOA, 17, &pm8994_pldo, "vdd_l17_l29" },
52614a16992SRajendra Nayak 	{ "l18", QCOM_SMD_RPM_LDOA, 18, &pm8994_pldo, "vdd_l9_l10_l18_l22" },
52714a16992SRajendra Nayak 	{ "l19", QCOM_SMD_RPM_LDOA, 19, &pm8994_pldo, "vdd_l13_l19_l23_l24" },
52814a16992SRajendra Nayak 	{ "l20", QCOM_SMD_RPM_LDOA, 20, &pm8994_pldo, "vdd_l20_l21" },
52914a16992SRajendra Nayak 	{ "l21", QCOM_SMD_RPM_LDOA, 21, &pm8994_pldo, "vdd_l20_l21" },
53014a16992SRajendra Nayak 	{ "l22", QCOM_SMD_RPM_LDOA, 22, &pm8994_pldo, "vdd_l9_l10_l18_l22" },
53114a16992SRajendra Nayak 	{ "l23", QCOM_SMD_RPM_LDOA, 23, &pm8994_pldo, "vdd_l13_l19_l23_l24" },
53214a16992SRajendra Nayak 	{ "l24", QCOM_SMD_RPM_LDOA, 24, &pm8994_pldo, "vdd_l13_l19_l23_l24" },
53314a16992SRajendra Nayak 	{ "l25", QCOM_SMD_RPM_LDOA, 25, &pm8994_pldo, "vdd_l25" },
53414a16992SRajendra Nayak 	{ "l26", QCOM_SMD_RPM_LDOA, 26, &pm8994_nldo, "vdd_l2_l26_l28" },
53514a16992SRajendra Nayak 	{ "l27", QCOM_SMD_RPM_LDOA, 27, &pm8994_nldo, "vdd_l4_l27_l31" },
53614a16992SRajendra Nayak 	{ "l28", QCOM_SMD_RPM_LDOA, 28, &pm8994_nldo, "vdd_l2_l26_l28" },
53714a16992SRajendra Nayak 	{ "l29", QCOM_SMD_RPM_LDOA, 29, &pm8994_pldo, "vdd_l17_l29" },
53814a16992SRajendra Nayak 	{ "l30", QCOM_SMD_RPM_LDOA, 30, &pm8994_pldo, "vdd_l8_l16_l30" },
53914a16992SRajendra Nayak 	{ "l31", QCOM_SMD_RPM_LDOA, 31, &pm8994_nldo, "vdd_l4_l27_l31" },
54014a16992SRajendra Nayak 	{ "l32", QCOM_SMD_RPM_LDOA, 32, &pm8994_pldo, "vdd_l6_l12_l32" },
54114a16992SRajendra Nayak 	{ "lvs1", QCOM_SMD_RPM_VSA, 1, &pm8994_switch, "vdd_lvs1_2" },
54214a16992SRajendra Nayak 	{ "lvs2", QCOM_SMD_RPM_VSA, 2, &pm8994_switch, "vdd_lvs1_2" },
54314a16992SRajendra Nayak 
54414a16992SRajendra Nayak 	{}
54514a16992SRajendra Nayak };
54614a16992SRajendra Nayak 
547da65e367SBjorn Andersson static const struct of_device_id rpm_of_match[] = {
548da65e367SBjorn Andersson 	{ .compatible = "qcom,rpm-pm8841-regulators", .data = &rpm_pm8841_regulators },
54957d65676SAndy Gross 	{ .compatible = "qcom,rpm-pm8916-regulators", .data = &rpm_pm8916_regulators },
550da65e367SBjorn Andersson 	{ .compatible = "qcom,rpm-pm8941-regulators", .data = &rpm_pm8941_regulators },
55114a16992SRajendra Nayak 	{ .compatible = "qcom,rpm-pm8994-regulators", .data = &rpm_pm8994_regulators },
552ee01d0c9SAndy Gross 	{ .compatible = "qcom,rpm-pma8084-regulators", .data = &rpm_pma8084_regulators },
553da65e367SBjorn Andersson 	{}
554da65e367SBjorn Andersson };
555da65e367SBjorn Andersson MODULE_DEVICE_TABLE(of, rpm_of_match);
556da65e367SBjorn Andersson 
557da65e367SBjorn Andersson static int rpm_reg_probe(struct platform_device *pdev)
558da65e367SBjorn Andersson {
559da65e367SBjorn Andersson 	const struct rpm_regulator_data *reg;
560da65e367SBjorn Andersson 	const struct of_device_id *match;
561da65e367SBjorn Andersson 	struct regulator_config config = { };
562da65e367SBjorn Andersson 	struct regulator_dev *rdev;
563da65e367SBjorn Andersson 	struct qcom_rpm_reg *vreg;
564da65e367SBjorn Andersson 	struct qcom_smd_rpm *rpm;
565da65e367SBjorn Andersson 
566da65e367SBjorn Andersson 	rpm = dev_get_drvdata(pdev->dev.parent);
567da65e367SBjorn Andersson 	if (!rpm) {
568da65e367SBjorn Andersson 		dev_err(&pdev->dev, "unable to retrieve handle to rpm\n");
569da65e367SBjorn Andersson 		return -ENODEV;
570da65e367SBjorn Andersson 	}
571da65e367SBjorn Andersson 
572da65e367SBjorn Andersson 	match = of_match_device(rpm_of_match, &pdev->dev);
573e3b53b8aSGustavo A. R. Silva 	if (!match) {
574e3b53b8aSGustavo A. R. Silva 		dev_err(&pdev->dev, "failed to match device\n");
575e3b53b8aSGustavo A. R. Silva 		return -ENODEV;
576e3b53b8aSGustavo A. R. Silva 	}
577e3b53b8aSGustavo A. R. Silva 
578da65e367SBjorn Andersson 	for (reg = match->data; reg->name; reg++) {
579da65e367SBjorn Andersson 		vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL);
580da65e367SBjorn Andersson 		if (!vreg)
581da65e367SBjorn Andersson 			return -ENOMEM;
582da65e367SBjorn Andersson 
583da65e367SBjorn Andersson 		vreg->dev = &pdev->dev;
584da65e367SBjorn Andersson 		vreg->type = reg->type;
585da65e367SBjorn Andersson 		vreg->id = reg->id;
586da65e367SBjorn Andersson 		vreg->rpm = rpm;
587da65e367SBjorn Andersson 
588da65e367SBjorn Andersson 		memcpy(&vreg->desc, reg->desc, sizeof(vreg->desc));
589da65e367SBjorn Andersson 
590da65e367SBjorn Andersson 		vreg->desc.id = -1;
591da65e367SBjorn Andersson 		vreg->desc.owner = THIS_MODULE;
592da65e367SBjorn Andersson 		vreg->desc.type = REGULATOR_VOLTAGE;
593da65e367SBjorn Andersson 		vreg->desc.name = reg->name;
594da65e367SBjorn Andersson 		vreg->desc.supply_name = reg->supply;
595da65e367SBjorn Andersson 		vreg->desc.of_match = reg->name;
596da65e367SBjorn Andersson 
597da65e367SBjorn Andersson 		config.dev = &pdev->dev;
598da65e367SBjorn Andersson 		config.driver_data = vreg;
599da65e367SBjorn Andersson 		rdev = devm_regulator_register(&pdev->dev, &vreg->desc, &config);
600da65e367SBjorn Andersson 		if (IS_ERR(rdev)) {
601da65e367SBjorn Andersson 			dev_err(&pdev->dev, "failed to register %s\n", reg->name);
602da65e367SBjorn Andersson 			return PTR_ERR(rdev);
603da65e367SBjorn Andersson 		}
604da65e367SBjorn Andersson 	}
605da65e367SBjorn Andersson 
606da65e367SBjorn Andersson 	return 0;
607da65e367SBjorn Andersson }
608da65e367SBjorn Andersson 
609da65e367SBjorn Andersson static struct platform_driver rpm_reg_driver = {
610da65e367SBjorn Andersson 	.probe = rpm_reg_probe,
611da65e367SBjorn Andersson 	.driver = {
612da65e367SBjorn Andersson 		.name  = "qcom_rpm_smd_regulator",
613da65e367SBjorn Andersson 		.of_match_table = rpm_of_match,
614da65e367SBjorn Andersson 	},
615da65e367SBjorn Andersson };
616da65e367SBjorn Andersson 
617da65e367SBjorn Andersson static int __init rpm_reg_init(void)
618da65e367SBjorn Andersson {
619da65e367SBjorn Andersson 	return platform_driver_register(&rpm_reg_driver);
620da65e367SBjorn Andersson }
621da65e367SBjorn Andersson subsys_initcall(rpm_reg_init);
622da65e367SBjorn Andersson 
623da65e367SBjorn Andersson static void __exit rpm_reg_exit(void)
624da65e367SBjorn Andersson {
625da65e367SBjorn Andersson 	platform_driver_unregister(&rpm_reg_driver);
626da65e367SBjorn Andersson }
627da65e367SBjorn Andersson module_exit(rpm_reg_exit)
628da65e367SBjorn Andersson 
629da65e367SBjorn Andersson MODULE_DESCRIPTION("Qualcomm RPM regulator driver");
630da65e367SBjorn Andersson MODULE_LICENSE("GPL v2");
631