xref: /linux/drivers/regulator/mt6357-regulator.c (revision dafc7cde23dca239987d3cd000b11cdccc3728ea)
1*dafc7cdeSFabien Parent // SPDX-License-Identifier: GPL-2.0
2*dafc7cdeSFabien Parent //
3*dafc7cdeSFabien Parent // Copyright (c) 2022 MediaTek Inc.
4*dafc7cdeSFabien Parent // Copyright (c) 2022 BayLibre, SAS.
5*dafc7cdeSFabien Parent // Author: Chen Zhong <chen.zhong@mediatek.com>
6*dafc7cdeSFabien Parent // Author: Fabien Parent <fparent@baylibre.com>
7*dafc7cdeSFabien Parent // Author: Alexandre Mergnat <amergnat@baylibre.com>
8*dafc7cdeSFabien Parent //
9*dafc7cdeSFabien Parent // Based on mt6397-regulator.c
10*dafc7cdeSFabien Parent //
11*dafc7cdeSFabien Parent 
12*dafc7cdeSFabien Parent #include <linux/module.h>
13*dafc7cdeSFabien Parent #include <linux/of.h>
14*dafc7cdeSFabien Parent #include <linux/platform_device.h>
15*dafc7cdeSFabien Parent #include <linux/regmap.h>
16*dafc7cdeSFabien Parent #include <linux/mfd/mt6397/core.h>
17*dafc7cdeSFabien Parent #include <linux/mfd/mt6357/registers.h>
18*dafc7cdeSFabien Parent #include <linux/regulator/driver.h>
19*dafc7cdeSFabien Parent #include <linux/regulator/machine.h>
20*dafc7cdeSFabien Parent #include <linux/regulator/mt6357-regulator.h>
21*dafc7cdeSFabien Parent #include <linux/regulator/of_regulator.h>
22*dafc7cdeSFabien Parent 
23*dafc7cdeSFabien Parent /*
24*dafc7cdeSFabien Parent  * MT6357 regulators' information
25*dafc7cdeSFabien Parent  *
26*dafc7cdeSFabien Parent  * @desc: standard fields of regulator description.
27*dafc7cdeSFabien Parent  * @da_vsel_reg: Monitor register for query buck's voltage.
28*dafc7cdeSFabien Parent  * @da_vsel_mask: Mask for query buck's voltage.
29*dafc7cdeSFabien Parent  */
30*dafc7cdeSFabien Parent struct mt6357_regulator_info {
31*dafc7cdeSFabien Parent 	struct regulator_desc desc;
32*dafc7cdeSFabien Parent 	u32 da_vsel_reg;
33*dafc7cdeSFabien Parent 	u32 da_vsel_mask;
34*dafc7cdeSFabien Parent };
35*dafc7cdeSFabien Parent 
36*dafc7cdeSFabien Parent #define MT6357_BUCK(match, vreg, min, max, step,		\
37*dafc7cdeSFabien Parent 	volt_ranges, vosel_reg, vosel_mask, _da_vsel_mask)	\
38*dafc7cdeSFabien Parent [MT6357_ID_##vreg] = {		\
39*dafc7cdeSFabien Parent 	.desc = {		\
40*dafc7cdeSFabien Parent 		.name = #vreg,	\
41*dafc7cdeSFabien Parent 		.of_match = of_match_ptr(match),		\
42*dafc7cdeSFabien Parent 		.regulators_node = "regulators",		\
43*dafc7cdeSFabien Parent 		.ops = &mt6357_volt_range_ops,	\
44*dafc7cdeSFabien Parent 		.type = REGULATOR_VOLTAGE,	\
45*dafc7cdeSFabien Parent 		.id = MT6357_ID_##vreg,		\
46*dafc7cdeSFabien Parent 		.owner = THIS_MODULE,		\
47*dafc7cdeSFabien Parent 		.n_voltages = ((max) - (min)) / (step) + 1,	\
48*dafc7cdeSFabien Parent 		.linear_ranges = volt_ranges,			\
49*dafc7cdeSFabien Parent 		.n_linear_ranges = ARRAY_SIZE(volt_ranges),	\
50*dafc7cdeSFabien Parent 		.vsel_reg = vosel_reg,		\
51*dafc7cdeSFabien Parent 		.vsel_mask = vosel_mask,	\
52*dafc7cdeSFabien Parent 		.enable_reg = MT6357_BUCK_##vreg##_CON0,	\
53*dafc7cdeSFabien Parent 		.enable_mask = BIT(0),		\
54*dafc7cdeSFabien Parent 	},	\
55*dafc7cdeSFabien Parent 	.da_vsel_reg = MT6357_BUCK_##vreg##_DBG0,		\
56*dafc7cdeSFabien Parent 	.da_vsel_mask = vosel_mask,		\
57*dafc7cdeSFabien Parent }
58*dafc7cdeSFabien Parent 
59*dafc7cdeSFabien Parent #define MT6357_LDO(match, vreg, ldo_volt_table,	\
60*dafc7cdeSFabien Parent 	enreg, vosel, vosel_mask)		\
61*dafc7cdeSFabien Parent [MT6357_ID_##vreg] = {		\
62*dafc7cdeSFabien Parent 	.desc = {		\
63*dafc7cdeSFabien Parent 		.name = #vreg,	\
64*dafc7cdeSFabien Parent 		.of_match = of_match_ptr(match),		\
65*dafc7cdeSFabien Parent 		.regulators_node = "regulators",		\
66*dafc7cdeSFabien Parent 		.ops = &mt6357_volt_table_ops,	\
67*dafc7cdeSFabien Parent 		.type = REGULATOR_VOLTAGE,	\
68*dafc7cdeSFabien Parent 		.id = MT6357_ID_##vreg,		\
69*dafc7cdeSFabien Parent 		.owner = THIS_MODULE,		\
70*dafc7cdeSFabien Parent 		.n_voltages = ARRAY_SIZE(ldo_volt_table),	\
71*dafc7cdeSFabien Parent 		.volt_table = ldo_volt_table,	\
72*dafc7cdeSFabien Parent 		.vsel_reg = vosel,		\
73*dafc7cdeSFabien Parent 		.vsel_mask = vosel_mask,	\
74*dafc7cdeSFabien Parent 		.enable_reg = enreg,		\
75*dafc7cdeSFabien Parent 		.enable_mask = BIT(0),		\
76*dafc7cdeSFabien Parent 	},	\
77*dafc7cdeSFabien Parent }
78*dafc7cdeSFabien Parent 
79*dafc7cdeSFabien Parent #define MT6357_LDO1(match, vreg, min, max, step, volt_ranges,	\
80*dafc7cdeSFabien Parent 	enreg, vosel, vosel_mask)		\
81*dafc7cdeSFabien Parent [MT6357_ID_##vreg] = {		\
82*dafc7cdeSFabien Parent 	.desc = {		\
83*dafc7cdeSFabien Parent 		.name = #vreg,	\
84*dafc7cdeSFabien Parent 		.of_match = of_match_ptr(match),		\
85*dafc7cdeSFabien Parent 		.regulators_node = "regulators",		\
86*dafc7cdeSFabien Parent 		.ops = &mt6357_volt_range_ops,	\
87*dafc7cdeSFabien Parent 		.type = REGULATOR_VOLTAGE,	\
88*dafc7cdeSFabien Parent 		.id = MT6357_ID_##vreg,		\
89*dafc7cdeSFabien Parent 		.owner = THIS_MODULE,		\
90*dafc7cdeSFabien Parent 		.n_voltages = ((max) - (min)) / (step) + 1,	\
91*dafc7cdeSFabien Parent 		.linear_ranges = volt_ranges,	\
92*dafc7cdeSFabien Parent 		.n_linear_ranges = ARRAY_SIZE(volt_ranges),	\
93*dafc7cdeSFabien Parent 		.vsel_reg = vosel,		\
94*dafc7cdeSFabien Parent 		.vsel_mask = vosel_mask,	\
95*dafc7cdeSFabien Parent 		.enable_reg = enreg,		\
96*dafc7cdeSFabien Parent 		.enable_mask = BIT(0),		\
97*dafc7cdeSFabien Parent 	},	\
98*dafc7cdeSFabien Parent 	.da_vsel_reg = MT6357_LDO_##vreg##_DBG0,		\
99*dafc7cdeSFabien Parent 	.da_vsel_mask = 0x7f00,	\
100*dafc7cdeSFabien Parent }
101*dafc7cdeSFabien Parent 
102*dafc7cdeSFabien Parent #define MT6357_REG_FIXED(match, vreg, volt)	\
103*dafc7cdeSFabien Parent [MT6357_ID_##vreg] = {					\
104*dafc7cdeSFabien Parent 	.desc = {					\
105*dafc7cdeSFabien Parent 		.name = #vreg,				\
106*dafc7cdeSFabien Parent 		.of_match = of_match_ptr(match),	\
107*dafc7cdeSFabien Parent 		.regulators_node = "regulators",	\
108*dafc7cdeSFabien Parent 		.ops = &mt6357_volt_fixed_ops,		\
109*dafc7cdeSFabien Parent 		.type = REGULATOR_VOLTAGE,		\
110*dafc7cdeSFabien Parent 		.id = MT6357_ID_##vreg,			\
111*dafc7cdeSFabien Parent 		.owner = THIS_MODULE,			\
112*dafc7cdeSFabien Parent 		.n_voltages = 1,			\
113*dafc7cdeSFabien Parent 		.enable_reg = MT6357_LDO_##vreg##_CON0,	\
114*dafc7cdeSFabien Parent 		.enable_mask = BIT(0),			\
115*dafc7cdeSFabien Parent 		.min_uV = volt,				\
116*dafc7cdeSFabien Parent 	},						\
117*dafc7cdeSFabien Parent }
118*dafc7cdeSFabien Parent 
119*dafc7cdeSFabien Parent /**
120*dafc7cdeSFabien Parent  * mt6357_get_buck_voltage_sel - get_voltage_sel for regmap users
121*dafc7cdeSFabien Parent  *
122*dafc7cdeSFabien Parent  * @rdev: regulator to operate on
123*dafc7cdeSFabien Parent  *
124*dafc7cdeSFabien Parent  * Regulators that use regmap for their register I/O can set the
125*dafc7cdeSFabien Parent  * da_vsel_reg and da_vsel_mask fields in the info structure and
126*dafc7cdeSFabien Parent  * then use this as their get_voltage_vsel operation.
127*dafc7cdeSFabien Parent  */
128*dafc7cdeSFabien Parent static int mt6357_get_buck_voltage_sel(struct regulator_dev *rdev)
129*dafc7cdeSFabien Parent {
130*dafc7cdeSFabien Parent 	int ret, regval;
131*dafc7cdeSFabien Parent 	struct mt6357_regulator_info *info = rdev_get_drvdata(rdev);
132*dafc7cdeSFabien Parent 
133*dafc7cdeSFabien Parent 	ret = regmap_read(rdev->regmap, info->da_vsel_reg, &regval);
134*dafc7cdeSFabien Parent 	if (ret != 0) {
135*dafc7cdeSFabien Parent 		dev_err(&rdev->dev,
136*dafc7cdeSFabien Parent 			"Failed to get mt6357 Buck %s vsel reg: %d\n",
137*dafc7cdeSFabien Parent 			info->desc.name, ret);
138*dafc7cdeSFabien Parent 		return ret;
139*dafc7cdeSFabien Parent 	}
140*dafc7cdeSFabien Parent 
141*dafc7cdeSFabien Parent 	regval &= info->da_vsel_mask;
142*dafc7cdeSFabien Parent 	regval >>= ffs(info->da_vsel_mask) - 1;
143*dafc7cdeSFabien Parent 
144*dafc7cdeSFabien Parent 	return regval;
145*dafc7cdeSFabien Parent }
146*dafc7cdeSFabien Parent 
147*dafc7cdeSFabien Parent static const struct regulator_ops mt6357_volt_range_ops = {
148*dafc7cdeSFabien Parent 	.list_voltage = regulator_list_voltage_linear_range,
149*dafc7cdeSFabien Parent 	.map_voltage = regulator_map_voltage_linear_range,
150*dafc7cdeSFabien Parent 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
151*dafc7cdeSFabien Parent 	.get_voltage_sel = mt6357_get_buck_voltage_sel,
152*dafc7cdeSFabien Parent 	.set_voltage_time_sel = regulator_set_voltage_time_sel,
153*dafc7cdeSFabien Parent 	.enable = regulator_enable_regmap,
154*dafc7cdeSFabien Parent 	.disable = regulator_disable_regmap,
155*dafc7cdeSFabien Parent 	.is_enabled = regulator_is_enabled_regmap,
156*dafc7cdeSFabien Parent };
157*dafc7cdeSFabien Parent 
158*dafc7cdeSFabien Parent static const struct regulator_ops mt6357_volt_table_ops = {
159*dafc7cdeSFabien Parent 	.list_voltage = regulator_list_voltage_table,
160*dafc7cdeSFabien Parent 	.map_voltage = regulator_map_voltage_iterate,
161*dafc7cdeSFabien Parent 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
162*dafc7cdeSFabien Parent 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
163*dafc7cdeSFabien Parent 	.set_voltage_time_sel = regulator_set_voltage_time_sel,
164*dafc7cdeSFabien Parent 	.enable = regulator_enable_regmap,
165*dafc7cdeSFabien Parent 	.disable = regulator_disable_regmap,
166*dafc7cdeSFabien Parent 	.is_enabled = regulator_is_enabled_regmap,
167*dafc7cdeSFabien Parent };
168*dafc7cdeSFabien Parent 
169*dafc7cdeSFabien Parent static const struct regulator_ops mt6357_volt_fixed_ops = {
170*dafc7cdeSFabien Parent 	.list_voltage = regulator_list_voltage_linear,
171*dafc7cdeSFabien Parent 	.enable = regulator_enable_regmap,
172*dafc7cdeSFabien Parent 	.disable = regulator_disable_regmap,
173*dafc7cdeSFabien Parent 	.is_enabled = regulator_is_enabled_regmap,
174*dafc7cdeSFabien Parent };
175*dafc7cdeSFabien Parent 
176*dafc7cdeSFabien Parent static const int vxo22_voltages[] = {
177*dafc7cdeSFabien Parent 	2200000,
178*dafc7cdeSFabien Parent 	0,
179*dafc7cdeSFabien Parent 	2400000,
180*dafc7cdeSFabien Parent };
181*dafc7cdeSFabien Parent 
182*dafc7cdeSFabien Parent static const int vefuse_voltages[] = {
183*dafc7cdeSFabien Parent 	1200000,
184*dafc7cdeSFabien Parent 	1300000,
185*dafc7cdeSFabien Parent 	1500000,
186*dafc7cdeSFabien Parent 	0,
187*dafc7cdeSFabien Parent 	1800000,
188*dafc7cdeSFabien Parent 	0,
189*dafc7cdeSFabien Parent 	0,
190*dafc7cdeSFabien Parent 	0,
191*dafc7cdeSFabien Parent 	0,
192*dafc7cdeSFabien Parent 	2800000,
193*dafc7cdeSFabien Parent 	2900000,
194*dafc7cdeSFabien Parent 	3000000,
195*dafc7cdeSFabien Parent 	0,
196*dafc7cdeSFabien Parent 	3300000,
197*dafc7cdeSFabien Parent };
198*dafc7cdeSFabien Parent 
199*dafc7cdeSFabien Parent static const int vcn33_voltages[] = {
200*dafc7cdeSFabien Parent 	0,
201*dafc7cdeSFabien Parent 	3300000,
202*dafc7cdeSFabien Parent 	3400000,
203*dafc7cdeSFabien Parent 	3500000,
204*dafc7cdeSFabien Parent };
205*dafc7cdeSFabien Parent 
206*dafc7cdeSFabien Parent static const int vcama_voltages[] = {
207*dafc7cdeSFabien Parent 	0,
208*dafc7cdeSFabien Parent 	0,
209*dafc7cdeSFabien Parent 	0,
210*dafc7cdeSFabien Parent 	0,
211*dafc7cdeSFabien Parent 	0,
212*dafc7cdeSFabien Parent 	0,
213*dafc7cdeSFabien Parent 	0,
214*dafc7cdeSFabien Parent 	2500000,
215*dafc7cdeSFabien Parent 	0,
216*dafc7cdeSFabien Parent 	0,
217*dafc7cdeSFabien Parent 	2800000,
218*dafc7cdeSFabien Parent };
219*dafc7cdeSFabien Parent 
220*dafc7cdeSFabien Parent static const int vcamd_voltages[] = {
221*dafc7cdeSFabien Parent 	0,
222*dafc7cdeSFabien Parent 	0,
223*dafc7cdeSFabien Parent 	0,
224*dafc7cdeSFabien Parent 	0,
225*dafc7cdeSFabien Parent 	1000000,
226*dafc7cdeSFabien Parent 	1100000,
227*dafc7cdeSFabien Parent 	1200000,
228*dafc7cdeSFabien Parent 	1300000,
229*dafc7cdeSFabien Parent 	0,
230*dafc7cdeSFabien Parent 	1500000,
231*dafc7cdeSFabien Parent 	0,
232*dafc7cdeSFabien Parent 	0,
233*dafc7cdeSFabien Parent 	1800000,
234*dafc7cdeSFabien Parent };
235*dafc7cdeSFabien Parent 
236*dafc7cdeSFabien Parent static const int vldo28_voltages[] = {
237*dafc7cdeSFabien Parent 	0,
238*dafc7cdeSFabien Parent 	2800000,
239*dafc7cdeSFabien Parent 	0,
240*dafc7cdeSFabien Parent 	3000000,
241*dafc7cdeSFabien Parent };
242*dafc7cdeSFabien Parent 
243*dafc7cdeSFabien Parent static const int vdram_voltages[] = {
244*dafc7cdeSFabien Parent 	0,
245*dafc7cdeSFabien Parent 	1100000,
246*dafc7cdeSFabien Parent 	1200000,
247*dafc7cdeSFabien Parent };
248*dafc7cdeSFabien Parent 
249*dafc7cdeSFabien Parent static const int vsim_voltages[] = {
250*dafc7cdeSFabien Parent 	0,
251*dafc7cdeSFabien Parent 	0,
252*dafc7cdeSFabien Parent 	0,
253*dafc7cdeSFabien Parent 	1700000,
254*dafc7cdeSFabien Parent 	1800000,
255*dafc7cdeSFabien Parent 	0,
256*dafc7cdeSFabien Parent 	0,
257*dafc7cdeSFabien Parent 	0,
258*dafc7cdeSFabien Parent 	2700000,
259*dafc7cdeSFabien Parent 	0,
260*dafc7cdeSFabien Parent 	0,
261*dafc7cdeSFabien Parent 	3000000,
262*dafc7cdeSFabien Parent 	3100000,
263*dafc7cdeSFabien Parent };
264*dafc7cdeSFabien Parent 
265*dafc7cdeSFabien Parent static const int vibr_voltages[] = {
266*dafc7cdeSFabien Parent 	1200000,
267*dafc7cdeSFabien Parent 	1300000,
268*dafc7cdeSFabien Parent 	1500000,
269*dafc7cdeSFabien Parent 	0,
270*dafc7cdeSFabien Parent 	1800000,
271*dafc7cdeSFabien Parent 	2000000,
272*dafc7cdeSFabien Parent 	0,
273*dafc7cdeSFabien Parent 	0,
274*dafc7cdeSFabien Parent 	0,
275*dafc7cdeSFabien Parent 	2800000,
276*dafc7cdeSFabien Parent 	0,
277*dafc7cdeSFabien Parent 	3000000,
278*dafc7cdeSFabien Parent 	0,
279*dafc7cdeSFabien Parent 	3300000,
280*dafc7cdeSFabien Parent };
281*dafc7cdeSFabien Parent 
282*dafc7cdeSFabien Parent static const int vmc_voltages[] = {
283*dafc7cdeSFabien Parent 	0,
284*dafc7cdeSFabien Parent 	0,
285*dafc7cdeSFabien Parent 	0,
286*dafc7cdeSFabien Parent 	0,
287*dafc7cdeSFabien Parent 	1800000,
288*dafc7cdeSFabien Parent 	0,
289*dafc7cdeSFabien Parent 	0,
290*dafc7cdeSFabien Parent 	0,
291*dafc7cdeSFabien Parent 	0,
292*dafc7cdeSFabien Parent 	0,
293*dafc7cdeSFabien Parent 	2900000,
294*dafc7cdeSFabien Parent 	3000000,
295*dafc7cdeSFabien Parent 	0,
296*dafc7cdeSFabien Parent 	3300000,
297*dafc7cdeSFabien Parent };
298*dafc7cdeSFabien Parent 
299*dafc7cdeSFabien Parent static const int vmch_voltages[] = {
300*dafc7cdeSFabien Parent 	0,
301*dafc7cdeSFabien Parent 	0,
302*dafc7cdeSFabien Parent 	2900000,
303*dafc7cdeSFabien Parent 	3000000,
304*dafc7cdeSFabien Parent 	0,
305*dafc7cdeSFabien Parent 	3300000,
306*dafc7cdeSFabien Parent };
307*dafc7cdeSFabien Parent 
308*dafc7cdeSFabien Parent static const int vemc_voltages[] = {
309*dafc7cdeSFabien Parent 	0,
310*dafc7cdeSFabien Parent 	0,
311*dafc7cdeSFabien Parent 	2900000,
312*dafc7cdeSFabien Parent 	3000000,
313*dafc7cdeSFabien Parent 	0,
314*dafc7cdeSFabien Parent 	3300000,
315*dafc7cdeSFabien Parent };
316*dafc7cdeSFabien Parent 
317*dafc7cdeSFabien Parent static const int vusb_voltages[] = {
318*dafc7cdeSFabien Parent 	0,
319*dafc7cdeSFabien Parent 	0,
320*dafc7cdeSFabien Parent 	0,
321*dafc7cdeSFabien Parent 	3000000,
322*dafc7cdeSFabien Parent 	3100000,
323*dafc7cdeSFabien Parent };
324*dafc7cdeSFabien Parent 
325*dafc7cdeSFabien Parent static const struct linear_range buck_volt_range1[] = {
326*dafc7cdeSFabien Parent 	REGULATOR_LINEAR_RANGE(518750, 0, 0x7f, 6250),
327*dafc7cdeSFabien Parent };
328*dafc7cdeSFabien Parent 
329*dafc7cdeSFabien Parent static const struct linear_range buck_volt_range2[] = {
330*dafc7cdeSFabien Parent 	REGULATOR_LINEAR_RANGE(500000, 0, 0x7f, 6250),
331*dafc7cdeSFabien Parent };
332*dafc7cdeSFabien Parent 
333*dafc7cdeSFabien Parent static const struct linear_range buck_volt_range3[] = {
334*dafc7cdeSFabien Parent 	REGULATOR_LINEAR_RANGE(500000, 0, 0x3f, 50000),
335*dafc7cdeSFabien Parent };
336*dafc7cdeSFabien Parent 
337*dafc7cdeSFabien Parent static const struct linear_range buck_volt_range4[] = {
338*dafc7cdeSFabien Parent 	REGULATOR_LINEAR_RANGE(1200000, 0, 0x7f, 12500),
339*dafc7cdeSFabien Parent };
340*dafc7cdeSFabien Parent 
341*dafc7cdeSFabien Parent /* The array is indexed by id(MT6357_ID_XXX) */
342*dafc7cdeSFabien Parent static struct mt6357_regulator_info mt6357_regulators[] = {
343*dafc7cdeSFabien Parent 	/* Bucks */
344*dafc7cdeSFabien Parent 	MT6357_BUCK("buck-vcore", VCORE, 518750, 1312500, 6250,
345*dafc7cdeSFabien Parent 		buck_volt_range1, MT6357_BUCK_VCORE_ELR0, 0x7f, 0x7f),
346*dafc7cdeSFabien Parent 	MT6357_BUCK("buck-vproc", VPROC, 518750, 1312500, 6250,
347*dafc7cdeSFabien Parent 		buck_volt_range1, MT6357_BUCK_VPROC_ELR0, 0x7f, 0x7f),
348*dafc7cdeSFabien Parent 	MT6357_BUCK("buck-vmodem", VMODEM, 500000, 1293750, 6250,
349*dafc7cdeSFabien Parent 		buck_volt_range2, MT6357_BUCK_VMODEM_ELR0, 0x7f, 0x7f),
350*dafc7cdeSFabien Parent 	MT6357_BUCK("buck-vpa", VPA, 500000, 3650000, 50000,
351*dafc7cdeSFabien Parent 		buck_volt_range3, MT6357_BUCK_VPA_CON1, 0x3f, 0x3f),
352*dafc7cdeSFabien Parent 	MT6357_BUCK("buck-vs1", VS1, 1200000, 2787500, 12500,
353*dafc7cdeSFabien Parent 		buck_volt_range4, MT6357_BUCK_VS1_ELR0, 0x7f, 0x7f),
354*dafc7cdeSFabien Parent 
355*dafc7cdeSFabien Parent 	/* LDOs */
356*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vcama", VCAMA, vcama_voltages,
357*dafc7cdeSFabien Parent 		   MT6357_LDO_VCAMA_CON0, MT6357_VCAMA_ANA_CON0, 0xf00),
358*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vcamd", VCAMD, vcamd_voltages,
359*dafc7cdeSFabien Parent 		   MT6357_LDO_VCAMD_CON0, MT6357_VCAMD_ANA_CON0, 0xf00),
360*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vcn33-bt", VCN33_BT, vcn33_voltages,
361*dafc7cdeSFabien Parent 		   MT6357_LDO_VCN33_CON0_0, MT6357_VCN33_ANA_CON0, 0x300),
362*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vcn33-wifi", VCN33_WIFI, vcn33_voltages,
363*dafc7cdeSFabien Parent 		   MT6357_LDO_VCN33_CON0_1, MT6357_VCN33_ANA_CON0, 0x300),
364*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vdram", VDRAM, vdram_voltages,
365*dafc7cdeSFabien Parent 		   MT6357_LDO_VDRAM_CON0, MT6357_VDRAM_ELR_2, 0x300),
366*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vefuse", VEFUSE, vefuse_voltages,
367*dafc7cdeSFabien Parent 		   MT6357_LDO_VEFUSE_CON0, MT6357_VEFUSE_ANA_CON0, 0xf00),
368*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vemc", VEMC, vemc_voltages,
369*dafc7cdeSFabien Parent 		   MT6357_LDO_VEMC_CON0, MT6357_VEMC_ANA_CON0, 0x700),
370*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vibr", VIBR, vibr_voltages,
371*dafc7cdeSFabien Parent 		   MT6357_LDO_VIBR_CON0, MT6357_VIBR_ANA_CON0, 0xf00),
372*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vldo28", VLDO28, vldo28_voltages,
373*dafc7cdeSFabien Parent 		   MT6357_LDO_VLDO28_CON0_0, MT6357_VLDO28_ANA_CON0, 0x300),
374*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vmc", VMC, vmc_voltages,
375*dafc7cdeSFabien Parent 		   MT6357_LDO_VMC_CON0, MT6357_VMC_ANA_CON0, 0xf00),
376*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vmch", VMCH, vmch_voltages,
377*dafc7cdeSFabien Parent 		   MT6357_LDO_VMCH_CON0, MT6357_VMCH_ANA_CON0, 0x700),
378*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vsim1", VSIM1, vsim_voltages,
379*dafc7cdeSFabien Parent 		   MT6357_LDO_VSIM1_CON0, MT6357_VSIM1_ANA_CON0, 0xf00),
380*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vsim2", VSIM2, vsim_voltages,
381*dafc7cdeSFabien Parent 		   MT6357_LDO_VSIM2_CON0, MT6357_VSIM2_ANA_CON0, 0xf00),
382*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vusb33", VUSB33, vusb_voltages,
383*dafc7cdeSFabien Parent 		   MT6357_LDO_VUSB33_CON0_0, MT6357_VUSB33_ANA_CON0, 0x700),
384*dafc7cdeSFabien Parent 	MT6357_LDO("ldo-vxo22", VXO22, vxo22_voltages,
385*dafc7cdeSFabien Parent 		   MT6357_LDO_VXO22_CON0, MT6357_VXO22_ANA_CON0, 0x300),
386*dafc7cdeSFabien Parent 
387*dafc7cdeSFabien Parent 	MT6357_LDO1("ldo-vsram-proc", VSRAM_PROC, 518750, 1312500, 6250,
388*dafc7cdeSFabien Parent 		   buck_volt_range1, MT6357_LDO_VSRAM_PROC_CON0,
389*dafc7cdeSFabien Parent 		   MT6357_LDO_VSRAM_CON0, 0x7f00),
390*dafc7cdeSFabien Parent 	MT6357_LDO1("ldo-vsram-others", VSRAM_OTHERS, 518750, 1312500, 6250,
391*dafc7cdeSFabien Parent 		   buck_volt_range1, MT6357_LDO_VSRAM_OTHERS_CON0,
392*dafc7cdeSFabien Parent 		   MT6357_LDO_VSRAM_CON1, 0x7f00),
393*dafc7cdeSFabien Parent 
394*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vaud28", VAUD28, 2800000),
395*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vaux18", VAUX18, 1800000),
396*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vcamio18", VCAMIO, 1800000),
397*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vcn18", VCN18, 1800000),
398*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vcn28", VCN28, 2800000),
399*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vfe28", VFE28, 2800000),
400*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vio18", VIO18, 1800000),
401*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vio28", VIO28, 2800000),
402*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vrf12", VRF12, 1200000),
403*dafc7cdeSFabien Parent 	MT6357_REG_FIXED("ldo-vrf18", VRF18, 1800000),
404*dafc7cdeSFabien Parent };
405*dafc7cdeSFabien Parent 
406*dafc7cdeSFabien Parent static int mt6357_regulator_probe(struct platform_device *pdev)
407*dafc7cdeSFabien Parent {
408*dafc7cdeSFabien Parent 	struct mt6397_chip *mt6357 = dev_get_drvdata(pdev->dev.parent);
409*dafc7cdeSFabien Parent 	struct regulator_config config = {};
410*dafc7cdeSFabien Parent 	struct regulator_dev *rdev;
411*dafc7cdeSFabien Parent 	int i;
412*dafc7cdeSFabien Parent 
413*dafc7cdeSFabien Parent 	pdev->dev.of_node = pdev->dev.parent->of_node;
414*dafc7cdeSFabien Parent 
415*dafc7cdeSFabien Parent 	for (i = 0; i < MT6357_MAX_REGULATOR; i++) {
416*dafc7cdeSFabien Parent 		config.dev = &pdev->dev;
417*dafc7cdeSFabien Parent 		config.driver_data = &mt6357_regulators[i];
418*dafc7cdeSFabien Parent 		config.regmap = mt6357->regmap;
419*dafc7cdeSFabien Parent 
420*dafc7cdeSFabien Parent 		rdev = devm_regulator_register(&pdev->dev,
421*dafc7cdeSFabien Parent 					       &mt6357_regulators[i].desc,
422*dafc7cdeSFabien Parent 					       &config);
423*dafc7cdeSFabien Parent 		if (IS_ERR(rdev)) {
424*dafc7cdeSFabien Parent 			dev_err(&pdev->dev, "failed to register %s\n",
425*dafc7cdeSFabien Parent 				mt6357_regulators[i].desc.name);
426*dafc7cdeSFabien Parent 			return PTR_ERR(rdev);
427*dafc7cdeSFabien Parent 		}
428*dafc7cdeSFabien Parent 	}
429*dafc7cdeSFabien Parent 
430*dafc7cdeSFabien Parent 	return 0;
431*dafc7cdeSFabien Parent }
432*dafc7cdeSFabien Parent 
433*dafc7cdeSFabien Parent static const struct platform_device_id mt6357_platform_ids[] = {
434*dafc7cdeSFabien Parent 	{ "mt6357-regulator" },
435*dafc7cdeSFabien Parent 	{ /* sentinel */ },
436*dafc7cdeSFabien Parent };
437*dafc7cdeSFabien Parent MODULE_DEVICE_TABLE(platform, mt6357_platform_ids);
438*dafc7cdeSFabien Parent 
439*dafc7cdeSFabien Parent static struct platform_driver mt6357_regulator_driver = {
440*dafc7cdeSFabien Parent 	.driver = {
441*dafc7cdeSFabien Parent 		.name = "mt6357-regulator",
442*dafc7cdeSFabien Parent 	},
443*dafc7cdeSFabien Parent 	.probe = mt6357_regulator_probe,
444*dafc7cdeSFabien Parent 	.id_table = mt6357_platform_ids,
445*dafc7cdeSFabien Parent };
446*dafc7cdeSFabien Parent 
447*dafc7cdeSFabien Parent module_platform_driver(mt6357_regulator_driver);
448*dafc7cdeSFabien Parent 
449*dafc7cdeSFabien Parent MODULE_AUTHOR("Chen Zhong <chen.zhong@mediatek.com>");
450*dafc7cdeSFabien Parent MODULE_AUTHOR("Fabien Parent <fabien.parent@linaro.org>");
451*dafc7cdeSFabien Parent MODULE_AUTHOR("Alexandre Mergnat <amergnat@baylibre.com>");
452*dafc7cdeSFabien Parent MODULE_DESCRIPTION("Regulator Driver for MediaTek MT6357 PMIC");
453*dafc7cdeSFabien Parent MODULE_LICENSE("GPL");
454