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 
308da65e367SBjorn Andersson struct rpm_regulator_data {
309da65e367SBjorn Andersson 	const char *name;
310da65e367SBjorn Andersson 	u32 type;
311da65e367SBjorn Andersson 	u32 id;
312da65e367SBjorn Andersson 	const struct regulator_desc *desc;
313da65e367SBjorn Andersson 	const char *supply;
314da65e367SBjorn Andersson };
315da65e367SBjorn Andersson 
316da65e367SBjorn Andersson static const struct rpm_regulator_data rpm_pm8841_regulators[] = {
317da65e367SBjorn Andersson 	{ "s1", QCOM_SMD_RPM_SMPB, 1, &pm8x41_hfsmps, "vdd_s1" },
318da65e367SBjorn Andersson 	{ "s2", QCOM_SMD_RPM_SMPB, 2, &pm8841_ftsmps, "vdd_s2" },
319da65e367SBjorn Andersson 	{ "s3", QCOM_SMD_RPM_SMPB, 3, &pm8x41_hfsmps, "vdd_s3" },
320da65e367SBjorn Andersson 	{ "s4", QCOM_SMD_RPM_SMPB, 4, &pm8841_ftsmps, "vdd_s4" },
321da65e367SBjorn Andersson 	{ "s5", QCOM_SMD_RPM_SMPB, 5, &pm8841_ftsmps, "vdd_s5" },
322da65e367SBjorn Andersson 	{ "s6", QCOM_SMD_RPM_SMPB, 6, &pm8841_ftsmps, "vdd_s6" },
323da65e367SBjorn Andersson 	{ "s7", QCOM_SMD_RPM_SMPB, 7, &pm8841_ftsmps, "vdd_s7" },
324da65e367SBjorn Andersson 	{ "s8", QCOM_SMD_RPM_SMPB, 8, &pm8841_ftsmps, "vdd_s8" },
325da65e367SBjorn Andersson 	{}
326da65e367SBjorn Andersson };
327da65e367SBjorn Andersson 
32857d65676SAndy Gross static const struct rpm_regulator_data rpm_pm8916_regulators[] = {
32957d65676SAndy Gross 	{ "s1", QCOM_SMD_RPM_SMPA, 1, &pm8916_buck_lvo_smps, "vdd_s1" },
33057d65676SAndy Gross 	{ "s2", QCOM_SMD_RPM_SMPA, 2, &pm8916_buck_lvo_smps, "vdd_s2" },
33157d65676SAndy Gross 	{ "s3", QCOM_SMD_RPM_SMPA, 3, &pm8916_buck_lvo_smps, "vdd_s3" },
33257d65676SAndy Gross 	{ "s4", QCOM_SMD_RPM_SMPA, 4, &pm8916_buck_hvo_smps, "vdd_s4" },
33357d65676SAndy Gross 	{ "l1", QCOM_SMD_RPM_LDOA, 1, &pm8916_nldo, "vdd_l1_l2_l3" },
33457d65676SAndy Gross 	{ "l2", QCOM_SMD_RPM_LDOA, 2, &pm8916_nldo, "vdd_l1_l2_l3" },
33557d65676SAndy Gross 	{ "l3", QCOM_SMD_RPM_LDOA, 3, &pm8916_nldo, "vdd_l1_l2_l3" },
33657d65676SAndy Gross 	{ "l4", QCOM_SMD_RPM_LDOA, 4, &pm8916_pldo, "vdd_l4_l5_l6" },
33757d65676SAndy Gross 	{ "l5", QCOM_SMD_RPM_LDOA, 5, &pm8916_pldo, "vdd_l4_l5_l6" },
33857d65676SAndy Gross 	{ "l6", QCOM_SMD_RPM_LDOA, 6, &pm8916_pldo, "vdd_l4_l5_l6" },
33957d65676SAndy Gross 	{ "l7", QCOM_SMD_RPM_LDOA, 7, &pm8916_pldo, "vdd_l7" },
34057d65676SAndy Gross 	{ "l8", QCOM_SMD_RPM_LDOA, 8, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18" },
34157d65676SAndy Gross 	{ "l9", QCOM_SMD_RPM_LDOA, 9, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18" },
34257d65676SAndy Gross 	{ "l10", QCOM_SMD_RPM_LDOA, 10, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
34357d65676SAndy Gross 	{ "l11", QCOM_SMD_RPM_LDOA, 11, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
34457d65676SAndy Gross 	{ "l12", QCOM_SMD_RPM_LDOA, 12, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
34557d65676SAndy Gross 	{ "l13", QCOM_SMD_RPM_LDOA, 13, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
34657d65676SAndy Gross 	{ "l14", QCOM_SMD_RPM_LDOA, 14, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
34757d65676SAndy Gross 	{ "l15", QCOM_SMD_RPM_LDOA, 15, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
34857d65676SAndy Gross 	{ "l16", QCOM_SMD_RPM_LDOA, 16, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
34957d65676SAndy Gross 	{ "l17", QCOM_SMD_RPM_LDOA, 17, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
35057d65676SAndy Gross 	{ "l18", QCOM_SMD_RPM_LDOA, 18, &pm8916_pldo, "vdd_l8_l9_l10_l11_l12_l13_l14_l15_l16_l17_l18"},
35157d65676SAndy Gross 	{}
35257d65676SAndy Gross };
35357d65676SAndy Gross 
354da65e367SBjorn Andersson static const struct rpm_regulator_data rpm_pm8941_regulators[] = {
355da65e367SBjorn Andersson 	{ "s1", QCOM_SMD_RPM_SMPA, 1, &pm8x41_hfsmps, "vdd_s1" },
356da65e367SBjorn Andersson 	{ "s2", QCOM_SMD_RPM_SMPA, 2, &pm8x41_hfsmps, "vdd_s2" },
357da65e367SBjorn Andersson 	{ "s3", QCOM_SMD_RPM_SMPA, 3, &pm8x41_hfsmps, "vdd_s3" },
358da65e367SBjorn Andersson 	{ "s4", QCOM_SMD_RPM_BOOST, 1, &pm8941_boost },
359da65e367SBjorn Andersson 
360da65e367SBjorn Andersson 	{ "l1", QCOM_SMD_RPM_LDOA, 1, &pm8941_nldo, "vdd_l1_l3" },
361da65e367SBjorn Andersson 	{ "l2", QCOM_SMD_RPM_LDOA, 2, &pm8941_nldo, "vdd_l2_lvs1_2_3" },
362da65e367SBjorn Andersson 	{ "l3", QCOM_SMD_RPM_LDOA, 3, &pm8941_nldo, "vdd_l1_l3" },
363da65e367SBjorn Andersson 	{ "l4", QCOM_SMD_RPM_LDOA, 4, &pm8941_nldo, "vdd_l4_l11" },
364da65e367SBjorn Andersson 	{ "l5", QCOM_SMD_RPM_LDOA, 5, &pm8941_lnldo, "vdd_l5_l7" },
365da65e367SBjorn Andersson 	{ "l6", QCOM_SMD_RPM_LDOA, 6, &pm8941_pldo, "vdd_l6_l12_l14_l15" },
366da65e367SBjorn Andersson 	{ "l7", QCOM_SMD_RPM_LDOA, 7, &pm8941_lnldo, "vdd_l5_l7" },
367da65e367SBjorn Andersson 	{ "l8", QCOM_SMD_RPM_LDOA, 8, &pm8941_pldo, "vdd_l8_l16_l18_l19" },
368da65e367SBjorn Andersson 	{ "l9", QCOM_SMD_RPM_LDOA, 9, &pm8941_pldo, "vdd_l9_l10_l17_l22" },
369da65e367SBjorn Andersson 	{ "l10", QCOM_SMD_RPM_LDOA, 10, &pm8941_pldo, "vdd_l9_l10_l17_l22" },
370da65e367SBjorn Andersson 	{ "l11", QCOM_SMD_RPM_LDOA, 11, &pm8941_nldo, "vdd_l4_l11" },
371da65e367SBjorn Andersson 	{ "l12", QCOM_SMD_RPM_LDOA, 12, &pm8941_pldo, "vdd_l6_l12_l14_l15" },
372da65e367SBjorn Andersson 	{ "l13", QCOM_SMD_RPM_LDOA, 13, &pm8941_pldo, "vdd_l13_l20_l23_l24" },
373da65e367SBjorn Andersson 	{ "l14", QCOM_SMD_RPM_LDOA, 14, &pm8941_pldo, "vdd_l6_l12_l14_l15" },
374da65e367SBjorn Andersson 	{ "l15", QCOM_SMD_RPM_LDOA, 15, &pm8941_pldo, "vdd_l6_l12_l14_l15" },
375da65e367SBjorn Andersson 	{ "l16", QCOM_SMD_RPM_LDOA, 16, &pm8941_pldo, "vdd_l8_l16_l18_l19" },
376da65e367SBjorn Andersson 	{ "l17", QCOM_SMD_RPM_LDOA, 17, &pm8941_pldo, "vdd_l9_l10_l17_l22" },
377da65e367SBjorn Andersson 	{ "l18", QCOM_SMD_RPM_LDOA, 18, &pm8941_pldo, "vdd_l8_l16_l18_l19" },
378da65e367SBjorn Andersson 	{ "l19", QCOM_SMD_RPM_LDOA, 19, &pm8941_pldo, "vdd_l8_l16_l18_l19" },
379da65e367SBjorn Andersson 	{ "l20", QCOM_SMD_RPM_LDOA, 20, &pm8941_pldo, "vdd_l13_l20_l23_l24" },
380da65e367SBjorn Andersson 	{ "l21", QCOM_SMD_RPM_LDOA, 21, &pm8941_pldo, "vdd_l21" },
381da65e367SBjorn Andersson 	{ "l22", QCOM_SMD_RPM_LDOA, 22, &pm8941_pldo, "vdd_l9_l10_l17_l22" },
382da65e367SBjorn Andersson 	{ "l23", QCOM_SMD_RPM_LDOA, 23, &pm8941_pldo, "vdd_l13_l20_l23_l24" },
383da65e367SBjorn Andersson 	{ "l24", QCOM_SMD_RPM_LDOA, 24, &pm8941_pldo, "vdd_l13_l20_l23_l24" },
384da65e367SBjorn Andersson 
385da65e367SBjorn Andersson 	{ "lvs1", QCOM_SMD_RPM_VSA, 1, &pm8941_switch, "vdd_l2_lvs1_2_3" },
386da65e367SBjorn Andersson 	{ "lvs2", QCOM_SMD_RPM_VSA, 2, &pm8941_switch, "vdd_l2_lvs1_2_3" },
387da65e367SBjorn Andersson 	{ "lvs3", QCOM_SMD_RPM_VSA, 3, &pm8941_switch, "vdd_l2_lvs1_2_3" },
388da65e367SBjorn Andersson 
389da65e367SBjorn Andersson 	{ "5vs1", QCOM_SMD_RPM_VSA, 4, &pm8941_switch, "vin_5vs" },
390da65e367SBjorn Andersson 	{ "5vs2", QCOM_SMD_RPM_VSA, 5, &pm8941_switch, "vin_5vs" },
391da65e367SBjorn Andersson 
392da65e367SBjorn Andersson 	{}
393da65e367SBjorn Andersson };
394da65e367SBjorn Andersson 
395ee01d0c9SAndy Gross static const struct rpm_regulator_data rpm_pma8084_regulators[] = {
396ee01d0c9SAndy Gross 	{ "s1", QCOM_SMD_RPM_SMPA, 1, &pma8084_ftsmps, "vdd_s1" },
397ee01d0c9SAndy Gross 	{ "s2", QCOM_SMD_RPM_SMPA, 2, &pma8084_ftsmps, "vdd_s2" },
398ee01d0c9SAndy Gross 	{ "s3", QCOM_SMD_RPM_SMPA, 3, &pma8084_hfsmps, "vdd_s3" },
399ee01d0c9SAndy Gross 	{ "s4", QCOM_SMD_RPM_SMPA, 4, &pma8084_hfsmps, "vdd_s4" },
400ee01d0c9SAndy Gross 	{ "s5", QCOM_SMD_RPM_SMPA, 5, &pma8084_hfsmps, "vdd_s5" },
401ee01d0c9SAndy Gross 	{ "s6", QCOM_SMD_RPM_SMPA, 6, &pma8084_ftsmps, "vdd_s6" },
402ee01d0c9SAndy Gross 	{ "s7", QCOM_SMD_RPM_SMPA, 7, &pma8084_ftsmps, "vdd_s7" },
403ee01d0c9SAndy Gross 	{ "s8", QCOM_SMD_RPM_SMPA, 8, &pma8084_ftsmps, "vdd_s8" },
404ee01d0c9SAndy Gross 	{ "s9", QCOM_SMD_RPM_SMPA, 9, &pma8084_ftsmps, "vdd_s9" },
405ee01d0c9SAndy Gross 	{ "s10", QCOM_SMD_RPM_SMPA, 10, &pma8084_ftsmps, "vdd_s10" },
406ee01d0c9SAndy Gross 	{ "s11", QCOM_SMD_RPM_SMPA, 11, &pma8084_ftsmps, "vdd_s11" },
407ee01d0c9SAndy Gross 	{ "s12", QCOM_SMD_RPM_SMPA, 12, &pma8084_ftsmps, "vdd_s12" },
408ee01d0c9SAndy Gross 
409ee01d0c9SAndy Gross 	{ "l1", QCOM_SMD_RPM_LDOA, 1, &pma8084_nldo, "vdd_l1_l11" },
410ee01d0c9SAndy Gross 	{ "l2", QCOM_SMD_RPM_LDOA, 2, &pma8084_nldo, "vdd_l2_l3_l4_l27" },
411ee01d0c9SAndy Gross 	{ "l3", QCOM_SMD_RPM_LDOA, 3, &pma8084_nldo, "vdd_l2_l3_l4_l27" },
412ee01d0c9SAndy Gross 	{ "l4", QCOM_SMD_RPM_LDOA, 4, &pma8084_nldo, "vdd_l2_l3_l4_l27" },
413ee01d0c9SAndy Gross 	{ "l5", QCOM_SMD_RPM_LDOA, 5, &pma8084_pldo, "vdd_l5_l7" },
414ee01d0c9SAndy Gross 	{ "l6", QCOM_SMD_RPM_LDOA, 6, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
415ee01d0c9SAndy Gross 	{ "l7", QCOM_SMD_RPM_LDOA, 7, &pma8084_pldo, "vdd_l5_l7" },
416ee01d0c9SAndy Gross 	{ "l8", QCOM_SMD_RPM_LDOA, 8, &pma8084_pldo, "vdd_l8" },
417ee01d0c9SAndy Gross 	{ "l9", QCOM_SMD_RPM_LDOA, 9, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
418ee01d0c9SAndy Gross 	{ "l10", QCOM_SMD_RPM_LDOA, 10, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
419ee01d0c9SAndy Gross 	{ "l11", QCOM_SMD_RPM_LDOA, 11, &pma8084_nldo, "vdd_l1_l11" },
420ee01d0c9SAndy Gross 	{ "l12", QCOM_SMD_RPM_LDOA, 12, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
421ee01d0c9SAndy Gross 	{ "l13", QCOM_SMD_RPM_LDOA, 13, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
422ee01d0c9SAndy Gross 	{ "l14", QCOM_SMD_RPM_LDOA, 14, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
423ee01d0c9SAndy Gross 	{ "l15", QCOM_SMD_RPM_LDOA, 15, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
424ee01d0c9SAndy Gross 	{ "l16", QCOM_SMD_RPM_LDOA, 16, &pma8084_pldo, "vdd_l16_l25" },
425ee01d0c9SAndy Gross 	{ "l17", QCOM_SMD_RPM_LDOA, 17, &pma8084_pldo, "vdd_l17" },
426ee01d0c9SAndy Gross 	{ "l18", QCOM_SMD_RPM_LDOA, 18, &pma8084_pldo, "vdd_l18" },
427ee01d0c9SAndy Gross 	{ "l19", QCOM_SMD_RPM_LDOA, 19, &pma8084_pldo, "vdd_l19" },
428ee01d0c9SAndy Gross 	{ "l20", QCOM_SMD_RPM_LDOA, 20, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
429ee01d0c9SAndy Gross 	{ "l21", QCOM_SMD_RPM_LDOA, 21, &pma8084_pldo, "vdd_l21" },
430ee01d0c9SAndy Gross 	{ "l22", QCOM_SMD_RPM_LDOA, 22, &pma8084_pldo, "vdd_l22" },
431ee01d0c9SAndy Gross 	{ "l23", QCOM_SMD_RPM_LDOA, 23, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
432ee01d0c9SAndy Gross 	{ "l24", QCOM_SMD_RPM_LDOA, 24, &pma8084_pldo, "vdd_l9_l10_l13_l20_l23_l24" },
433ee01d0c9SAndy Gross 	{ "l25", QCOM_SMD_RPM_LDOA, 25, &pma8084_pldo, "vdd_l16_l25" },
434ee01d0c9SAndy Gross 	{ "l26", QCOM_SMD_RPM_LDOA, 26, &pma8084_pldo, "vdd_l6_l12_l14_l15_l26" },
435ee01d0c9SAndy Gross 	{ "l27", QCOM_SMD_RPM_LDOA, 27, &pma8084_nldo, "vdd_l2_l3_l4_l27" },
436ee01d0c9SAndy Gross 
437ee01d0c9SAndy Gross 	{ "lvs1", QCOM_SMD_RPM_VSA, 1, &pma8084_switch },
438ee01d0c9SAndy Gross 	{ "lvs2", QCOM_SMD_RPM_VSA, 2, &pma8084_switch },
439ee01d0c9SAndy Gross 	{ "lvs3", QCOM_SMD_RPM_VSA, 3, &pma8084_switch },
440ee01d0c9SAndy Gross 	{ "lvs4", QCOM_SMD_RPM_VSA, 4, &pma8084_switch },
441ee01d0c9SAndy Gross 	{ "5vs1", QCOM_SMD_RPM_VSA, 5, &pma8084_switch },
442ee01d0c9SAndy Gross 
443ee01d0c9SAndy Gross 	{}
444ee01d0c9SAndy Gross };
445ee01d0c9SAndy Gross 
446da65e367SBjorn Andersson static const struct of_device_id rpm_of_match[] = {
447da65e367SBjorn Andersson 	{ .compatible = "qcom,rpm-pm8841-regulators", .data = &rpm_pm8841_regulators },
44857d65676SAndy Gross 	{ .compatible = "qcom,rpm-pm8916-regulators", .data = &rpm_pm8916_regulators },
449da65e367SBjorn Andersson 	{ .compatible = "qcom,rpm-pm8941-regulators", .data = &rpm_pm8941_regulators },
450ee01d0c9SAndy Gross 	{ .compatible = "qcom,rpm-pma8084-regulators", .data = &rpm_pma8084_regulators },
451da65e367SBjorn Andersson 	{}
452da65e367SBjorn Andersson };
453da65e367SBjorn Andersson MODULE_DEVICE_TABLE(of, rpm_of_match);
454da65e367SBjorn Andersson 
455da65e367SBjorn Andersson static int rpm_reg_probe(struct platform_device *pdev)
456da65e367SBjorn Andersson {
457da65e367SBjorn Andersson 	const struct rpm_regulator_data *reg;
458da65e367SBjorn Andersson 	const struct of_device_id *match;
459da65e367SBjorn Andersson 	struct regulator_config config = { };
460da65e367SBjorn Andersson 	struct regulator_dev *rdev;
461da65e367SBjorn Andersson 	struct qcom_rpm_reg *vreg;
462da65e367SBjorn Andersson 	struct qcom_smd_rpm *rpm;
463da65e367SBjorn Andersson 
464da65e367SBjorn Andersson 	rpm = dev_get_drvdata(pdev->dev.parent);
465da65e367SBjorn Andersson 	if (!rpm) {
466da65e367SBjorn Andersson 		dev_err(&pdev->dev, "unable to retrieve handle to rpm\n");
467da65e367SBjorn Andersson 		return -ENODEV;
468da65e367SBjorn Andersson 	}
469da65e367SBjorn Andersson 
470da65e367SBjorn Andersson 	match = of_match_device(rpm_of_match, &pdev->dev);
471da65e367SBjorn Andersson 	for (reg = match->data; reg->name; reg++) {
472da65e367SBjorn Andersson 		vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL);
473da65e367SBjorn Andersson 		if (!vreg)
474da65e367SBjorn Andersson 			return -ENOMEM;
475da65e367SBjorn Andersson 
476da65e367SBjorn Andersson 		vreg->dev = &pdev->dev;
477da65e367SBjorn Andersson 		vreg->type = reg->type;
478da65e367SBjorn Andersson 		vreg->id = reg->id;
479da65e367SBjorn Andersson 		vreg->rpm = rpm;
480da65e367SBjorn Andersson 
481da65e367SBjorn Andersson 		memcpy(&vreg->desc, reg->desc, sizeof(vreg->desc));
482da65e367SBjorn Andersson 
483da65e367SBjorn Andersson 		vreg->desc.id = -1;
484da65e367SBjorn Andersson 		vreg->desc.owner = THIS_MODULE;
485da65e367SBjorn Andersson 		vreg->desc.type = REGULATOR_VOLTAGE;
486da65e367SBjorn Andersson 		vreg->desc.name = reg->name;
487da65e367SBjorn Andersson 		vreg->desc.supply_name = reg->supply;
488da65e367SBjorn Andersson 		vreg->desc.of_match = reg->name;
489da65e367SBjorn Andersson 
490da65e367SBjorn Andersson 		config.dev = &pdev->dev;
491da65e367SBjorn Andersson 		config.driver_data = vreg;
492da65e367SBjorn Andersson 		rdev = devm_regulator_register(&pdev->dev, &vreg->desc, &config);
493da65e367SBjorn Andersson 		if (IS_ERR(rdev)) {
494da65e367SBjorn Andersson 			dev_err(&pdev->dev, "failed to register %s\n", reg->name);
495da65e367SBjorn Andersson 			return PTR_ERR(rdev);
496da65e367SBjorn Andersson 		}
497da65e367SBjorn Andersson 	}
498da65e367SBjorn Andersson 
499da65e367SBjorn Andersson 	return 0;
500da65e367SBjorn Andersson }
501da65e367SBjorn Andersson 
502da65e367SBjorn Andersson static struct platform_driver rpm_reg_driver = {
503da65e367SBjorn Andersson 	.probe = rpm_reg_probe,
504da65e367SBjorn Andersson 	.driver = {
505da65e367SBjorn Andersson 		.name  = "qcom_rpm_smd_regulator",
506da65e367SBjorn Andersson 		.of_match_table = rpm_of_match,
507da65e367SBjorn Andersson 	},
508da65e367SBjorn Andersson };
509da65e367SBjorn Andersson 
510da65e367SBjorn Andersson static int __init rpm_reg_init(void)
511da65e367SBjorn Andersson {
512da65e367SBjorn Andersson 	return platform_driver_register(&rpm_reg_driver);
513da65e367SBjorn Andersson }
514da65e367SBjorn Andersson subsys_initcall(rpm_reg_init);
515da65e367SBjorn Andersson 
516da65e367SBjorn Andersson static void __exit rpm_reg_exit(void)
517da65e367SBjorn Andersson {
518da65e367SBjorn Andersson 	platform_driver_unregister(&rpm_reg_driver);
519da65e367SBjorn Andersson }
520da65e367SBjorn Andersson module_exit(rpm_reg_exit)
521da65e367SBjorn Andersson 
522da65e367SBjorn Andersson MODULE_DESCRIPTION("Qualcomm RPM regulator driver");
523da65e367SBjorn Andersson MODULE_LICENSE("GPL v2");
524