1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 ROHM Semiconductors
3 // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
4 
5 #include <linux/delay.h>
6 #include <linux/err.h>
7 #include <linux/gpio.h>
8 #include <linux/interrupt.h>
9 #include <linux/kernel.h>
10 #include <linux/mfd/rohm-bd718x7.h>
11 #include <linux/module.h>
12 #include <linux/of.h>
13 #include <linux/platform_device.h>
14 #include <linux/regulator/driver.h>
15 #include <linux/regulator/machine.h>
16 #include <linux/regulator/of_regulator.h>
17 #include <linux/slab.h>
18 
19 /*
20  * BUCK1/2/3/4
21  * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
22  * 00: 10.00mV/usec 10mV 1uS
23  * 01: 5.00mV/usec	10mV 2uS
24  * 10: 2.50mV/usec	10mV 4uS
25  * 11: 1.25mV/usec	10mV 8uS
26  */
27 static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
28 					   int ramp_delay)
29 {
30 	int id = rdev_get_id(rdev);
31 	unsigned int ramp_value;
32 
33 	dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
34 		ramp_delay);
35 	switch (ramp_delay) {
36 	case 1 ... 1250:
37 		ramp_value = BUCK_RAMPRATE_1P25MV;
38 		break;
39 	case 1251 ... 2500:
40 		ramp_value = BUCK_RAMPRATE_2P50MV;
41 		break;
42 	case 2501 ... 5000:
43 		ramp_value = BUCK_RAMPRATE_5P00MV;
44 		break;
45 	case 5001 ... 10000:
46 		ramp_value = BUCK_RAMPRATE_10P00MV;
47 		break;
48 	default:
49 		ramp_value = BUCK_RAMPRATE_10P00MV;
50 		dev_err(&rdev->dev,
51 			"%s: ramp_delay: %d not supported, setting 10000mV//us\n",
52 			rdev->desc->name, ramp_delay);
53 	}
54 
55 	return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
56 				  BUCK_RAMPRATE_MASK, ramp_value << 6);
57 }
58 
59 /* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
60  * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
61  * is changed. Hence we return -EBUSY for these if voltage is changed
62  * when BUCK/LDO is enabled.
63  */
64 static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
65 						    unsigned int sel)
66 {
67 	if (regulator_is_enabled_regmap(rdev))
68 		return -EBUSY;
69 
70 	return regulator_set_voltage_sel_regmap(rdev, sel);
71 }
72 
73 static int bd718xx_set_voltage_sel_pickable_restricted(
74 		struct regulator_dev *rdev, unsigned int sel)
75 {
76 	if (regulator_is_enabled_regmap(rdev))
77 		return -EBUSY;
78 
79 	return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
80 }
81 
82 static const struct regulator_ops bd718xx_pickable_range_ldo_ops = {
83 	.enable = regulator_enable_regmap,
84 	.disable = regulator_disable_regmap,
85 	.is_enabled = regulator_is_enabled_regmap,
86 	.list_voltage = regulator_list_voltage_pickable_linear_range,
87 	.set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
88 	.get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
89 };
90 
91 static const struct regulator_ops bd718xx_pickable_range_buck_ops = {
92 	.enable = regulator_enable_regmap,
93 	.disable = regulator_disable_regmap,
94 	.is_enabled = regulator_is_enabled_regmap,
95 	.list_voltage = regulator_list_voltage_pickable_linear_range,
96 	.set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
97 	.get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
98 	.set_voltage_time_sel = regulator_set_voltage_time_sel,
99 };
100 
101 static const struct regulator_ops bd718xx_ldo_regulator_ops = {
102 	.enable = regulator_enable_regmap,
103 	.disable = regulator_disable_regmap,
104 	.is_enabled = regulator_is_enabled_regmap,
105 	.list_voltage = regulator_list_voltage_linear_range,
106 	.set_voltage_sel = bd718xx_set_voltage_sel_restricted,
107 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
108 };
109 
110 static const struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = {
111 	.enable = regulator_enable_regmap,
112 	.disable = regulator_disable_regmap,
113 	.is_enabled = regulator_is_enabled_regmap,
114 	.list_voltage = regulator_list_voltage_table,
115 	.set_voltage_sel = bd718xx_set_voltage_sel_restricted,
116 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
117 };
118 
119 static const struct regulator_ops bd718xx_buck_regulator_ops = {
120 	.enable = regulator_enable_regmap,
121 	.disable = regulator_disable_regmap,
122 	.is_enabled = regulator_is_enabled_regmap,
123 	.list_voltage = regulator_list_voltage_linear_range,
124 	.set_voltage_sel = bd718xx_set_voltage_sel_restricted,
125 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
126 	.set_voltage_time_sel = regulator_set_voltage_time_sel,
127 };
128 
129 static const struct regulator_ops bd718xx_buck_regulator_nolinear_ops = {
130 	.enable = regulator_enable_regmap,
131 	.disable = regulator_disable_regmap,
132 	.is_enabled = regulator_is_enabled_regmap,
133 	.list_voltage = regulator_list_voltage_table,
134 	.map_voltage = regulator_map_voltage_ascend,
135 	.set_voltage_sel = bd718xx_set_voltage_sel_restricted,
136 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
137 	.set_voltage_time_sel = regulator_set_voltage_time_sel,
138 };
139 
140 static const struct regulator_ops bd718xx_dvs_buck_regulator_ops = {
141 	.enable = regulator_enable_regmap,
142 	.disable = regulator_disable_regmap,
143 	.is_enabled = regulator_is_enabled_regmap,
144 	.list_voltage = regulator_list_voltage_linear_range,
145 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
146 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
147 	.set_voltage_time_sel = regulator_set_voltage_time_sel,
148 	.set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
149 };
150 
151 /*
152  * BD71837 BUCK1/2/3/4
153  * BD71847 BUCK1/2
154  * 0.70 to 1.30V (10mV step)
155  */
156 static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = {
157 	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
158 	REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
159 };
160 
161 /*
162  * BD71837 BUCK5
163  * 0.7V to 1.35V  (range 0)
164  * and
165  * 0.675 to 1.325 (range 1)
166  */
167 static const struct regulator_linear_range bd71837_buck5_volts[] = {
168 	/* Ranges when VOLT_SEL bit is 0 */
169 	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
170 	REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
171 	REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
172 	/* Ranges when VOLT_SEL bit is 1  */
173 	REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
174 	REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
175 	REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
176 };
177 
178 /*
179  * Range selector for first 3 linear ranges is 0x0
180  * and 0x1 for last 3 ranges.
181  */
182 static const unsigned int bd71837_buck5_volt_range_sel[] = {
183 	0x0, 0x0, 0x0, 0x80, 0x80, 0x80
184 };
185 
186 /*
187  * BD71847 BUCK3
188  */
189 static const struct regulator_linear_range bd71847_buck3_volts[] = {
190 	/* Ranges when VOLT_SEL bits are 00 */
191 	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
192 	REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
193 	REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
194 	/* Ranges when VOLT_SEL bits are 01 */
195 	REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
196 	/* Ranges when VOLT_SEL bits are 11 */
197 	REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
198 	REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
199 	REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
200 };
201 
202 static const unsigned int bd71847_buck3_volt_range_sel[] = {
203 	0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
204 };
205 
206 static const struct regulator_linear_range bd71847_buck4_volts[] = {
207 	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
208 	REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
209 };
210 
211 static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
212 
213 /*
214  * BUCK6
215  * 3.0V to 3.3V (step 100mV)
216  */
217 static const struct regulator_linear_range bd71837_buck6_volts[] = {
218 	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
219 };
220 
221 /*
222  * BD71837 BUCK7
223  * BD71847 BUCK5
224  * 000 = 1.605V
225  * 001 = 1.695V
226  * 010 = 1.755V
227  * 011 = 1.8V (Initial)
228  * 100 = 1.845V
229  * 101 = 1.905V
230  * 110 = 1.95V
231  * 111 = 1.995V
232  */
233 static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
234 	1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
235 };
236 
237 /*
238  * BUCK8
239  * 0.8V to 1.40V (step 10mV)
240  */
241 static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = {
242 	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
243 };
244 
245 /*
246  * LDO1
247  * 3.0 to 3.3V (100mV step)
248  */
249 static const struct regulator_linear_range bd718xx_ldo1_volts[] = {
250 	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
251 	REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
252 };
253 
254 static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
255 
256 /*
257  * LDO2
258  * 0.8 or 0.9V
259  */
260 static const unsigned int ldo_2_volts[] = {
261 	900000, 800000
262 };
263 
264 /*
265  * LDO3
266  * 1.8 to 3.3V (100mV step)
267  */
268 static const struct regulator_linear_range bd718xx_ldo3_volts[] = {
269 	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
270 };
271 
272 /*
273  * LDO4
274  * 0.9 to 1.8V (100mV step)
275  */
276 static const struct regulator_linear_range bd718xx_ldo4_volts[] = {
277 	REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
278 };
279 
280 /*
281  * LDO5 for BD71837
282  * 1.8 to 3.3V (100mV step)
283  */
284 static const struct regulator_linear_range bd71837_ldo5_volts[] = {
285 	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
286 };
287 
288 /*
289  * LDO5 for BD71837
290  * 1.8 to 3.3V (100mV step)
291  */
292 static const struct regulator_linear_range bd71847_ldo5_volts[] = {
293 	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
294 	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
295 };
296 
297 static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
298 
299 /*
300  * LDO6
301  * 0.9 to 1.8V (100mV step)
302  */
303 static const struct regulator_linear_range bd718xx_ldo6_volts[] = {
304 	REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
305 };
306 
307 /*
308  * LDO7
309  * 1.8 to 3.3V (100mV step)
310  */
311 static const struct regulator_linear_range bd71837_ldo7_volts[] = {
312 	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
313 };
314 
315 struct reg_init {
316 	unsigned int reg;
317 	unsigned int mask;
318 	unsigned int val;
319 };
320 struct bd718xx_regulator_data {
321 	struct regulator_desc desc;
322 	const struct reg_init init;
323 	const struct reg_init *additional_inits;
324 	int additional_init_amnt;
325 };
326 
327 /*
328  * There is a HW quirk in BD71837. The shutdown sequence timings for
329  * bucks/LDOs which are controlled via register interface are changed.
330  * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
331  * beginning of shut-down sequence. As bucks 6 and 7 are parent
332  * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
333  * monitoring to errorneously detect under voltage and force PMIC to
334  * emergency state instead of poweroff. In order to avoid this we
335  * disable voltage monitoring for LDO5 and LDO6
336  */
337 static const struct reg_init bd71837_ldo5_inits[] = {
338 	{
339 		.reg = BD718XX_REG_MVRFLTMASK2,
340 		.mask = BD718XX_LDO5_VRMON80,
341 		.val = BD718XX_LDO5_VRMON80,
342 	},
343 };
344 
345 static const struct reg_init bd71837_ldo6_inits[] = {
346 	{
347 		.reg = BD718XX_REG_MVRFLTMASK2,
348 		.mask = BD718XX_LDO6_VRMON80,
349 		.val = BD718XX_LDO6_VRMON80,
350 	},
351 };
352 
353 #define NUM_DVS_BUCKS 4
354 
355 struct of_dvs_setting {
356 	const char *prop;
357 	unsigned int reg;
358 };
359 
360 static int set_dvs_levels(const struct of_dvs_setting *dvs,
361 			  struct device_node *np,
362 			  const struct regulator_desc *desc,
363 			  struct regmap *regmap)
364 {
365 	int ret, i;
366 	unsigned int uv;
367 
368 	ret = of_property_read_u32(np, dvs->prop, &uv);
369 	if (ret) {
370 		if (ret != -EINVAL)
371 			return ret;
372 		return 0;
373 	}
374 
375 	for (i = 0; i < desc->n_voltages; i++) {
376 		ret = regulator_desc_list_voltage_linear_range(desc, i);
377 		if (ret < 0)
378 			continue;
379 		if (ret == uv) {
380 			i <<= ffs(desc->vsel_mask) - 1;
381 			ret = regmap_update_bits(regmap, dvs->reg,
382 						 DVS_BUCK_RUN_MASK, i);
383 			break;
384 		}
385 	}
386 	return ret;
387 }
388 
389 static int buck4_set_hw_dvs_levels(struct device_node *np,
390 			    const struct regulator_desc *desc,
391 			    struct regulator_config *cfg)
392 {
393 	int ret, i;
394 	const struct of_dvs_setting dvs[] = {
395 		{
396 			.prop = "rohm,dvs-run-voltage",
397 			.reg = BD71837_REG_BUCK4_VOLT_RUN,
398 		},
399 	};
400 
401 	for (i = 0; i < ARRAY_SIZE(dvs); i++) {
402 		ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
403 		if (ret)
404 			break;
405 	}
406 	return ret;
407 }
408 static int buck3_set_hw_dvs_levels(struct device_node *np,
409 			    const struct regulator_desc *desc,
410 			    struct regulator_config *cfg)
411 {
412 	int ret, i;
413 	const struct of_dvs_setting dvs[] = {
414 		{
415 			.prop = "rohm,dvs-run-voltage",
416 			.reg = BD71837_REG_BUCK3_VOLT_RUN,
417 		},
418 	};
419 
420 	for (i = 0; i < ARRAY_SIZE(dvs); i++) {
421 		ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
422 		if (ret)
423 			break;
424 	}
425 	return ret;
426 }
427 
428 static int buck2_set_hw_dvs_levels(struct device_node *np,
429 			    const struct regulator_desc *desc,
430 			    struct regulator_config *cfg)
431 {
432 	int ret, i;
433 	const struct of_dvs_setting dvs[] = {
434 		{
435 			.prop = "rohm,dvs-run-voltage",
436 			.reg = BD718XX_REG_BUCK2_VOLT_RUN,
437 		},
438 		{
439 			.prop = "rohm,dvs-idle-voltage",
440 			.reg = BD718XX_REG_BUCK2_VOLT_IDLE,
441 		},
442 	};
443 
444 
445 
446 	for (i = 0; i < ARRAY_SIZE(dvs); i++) {
447 		ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
448 		if (ret)
449 			break;
450 	}
451 	return ret;
452 }
453 
454 static int buck1_set_hw_dvs_levels(struct device_node *np,
455 			    const struct regulator_desc *desc,
456 			    struct regulator_config *cfg)
457 {
458 	int ret, i;
459 	const struct of_dvs_setting dvs[] = {
460 		{
461 			.prop = "rohm,dvs-run-voltage",
462 			.reg = BD718XX_REG_BUCK1_VOLT_RUN,
463 		},
464 		{
465 			.prop = "rohm,dvs-idle-voltage",
466 			.reg = BD718XX_REG_BUCK1_VOLT_IDLE,
467 		},
468 		{
469 			.prop = "rohm,dvs-suspend-voltage",
470 			.reg = BD718XX_REG_BUCK1_VOLT_SUSP,
471 		},
472 	};
473 
474 	for (i = 0; i < ARRAY_SIZE(dvs); i++) {
475 		ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
476 		if (ret)
477 			break;
478 	}
479 	return ret;
480 }
481 
482 static const struct bd718xx_regulator_data bd71847_regulators[] = {
483 	{
484 		.desc = {
485 			.name = "buck1",
486 			.of_match = of_match_ptr("BUCK1"),
487 			.regulators_node = of_match_ptr("regulators"),
488 			.id = BD718XX_BUCK1,
489 			.ops = &bd718xx_dvs_buck_regulator_ops,
490 			.type = REGULATOR_VOLTAGE,
491 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
492 			.linear_ranges = bd718xx_dvs_buck_volts,
493 			.n_linear_ranges =
494 				ARRAY_SIZE(bd718xx_dvs_buck_volts),
495 			.vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
496 			.vsel_mask = DVS_BUCK_RUN_MASK,
497 			.enable_reg = BD718XX_REG_BUCK1_CTRL,
498 			.enable_mask = BD718XX_BUCK_EN,
499 			.owner = THIS_MODULE,
500 			.of_parse_cb = buck1_set_hw_dvs_levels,
501 		},
502 		.init = {
503 			.reg = BD718XX_REG_BUCK1_CTRL,
504 			.mask = BD718XX_BUCK_SEL,
505 			.val = BD718XX_BUCK_SEL,
506 		},
507 	},
508 	{
509 		.desc = {
510 			.name = "buck2",
511 			.of_match = of_match_ptr("BUCK2"),
512 			.regulators_node = of_match_ptr("regulators"),
513 			.id = BD718XX_BUCK2,
514 			.ops = &bd718xx_dvs_buck_regulator_ops,
515 			.type = REGULATOR_VOLTAGE,
516 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
517 			.linear_ranges = bd718xx_dvs_buck_volts,
518 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
519 			.vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
520 			.vsel_mask = DVS_BUCK_RUN_MASK,
521 			.enable_reg = BD718XX_REG_BUCK2_CTRL,
522 			.enable_mask = BD718XX_BUCK_EN,
523 			.owner = THIS_MODULE,
524 			.of_parse_cb = buck2_set_hw_dvs_levels,
525 		},
526 		.init = {
527 			.reg = BD718XX_REG_BUCK2_CTRL,
528 			.mask = BD718XX_BUCK_SEL,
529 			.val = BD718XX_BUCK_SEL,
530 		},
531 	},
532 	{
533 		.desc = {
534 			.name = "buck3",
535 			.of_match = of_match_ptr("BUCK3"),
536 			.regulators_node = of_match_ptr("regulators"),
537 			.id = BD718XX_BUCK3,
538 			.ops = &bd718xx_pickable_range_buck_ops,
539 			.type = REGULATOR_VOLTAGE,
540 			.n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
541 			.linear_ranges = bd71847_buck3_volts,
542 			.n_linear_ranges =
543 				ARRAY_SIZE(bd71847_buck3_volts),
544 			.vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
545 			.vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
546 			.vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
547 			.vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
548 			.linear_range_selectors = bd71847_buck3_volt_range_sel,
549 			.enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
550 			.enable_mask = BD718XX_BUCK_EN,
551 			.owner = THIS_MODULE,
552 		},
553 		.init = {
554 			.reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
555 			.mask = BD718XX_BUCK_SEL,
556 			.val = BD718XX_BUCK_SEL,
557 		},
558 	},
559 	{
560 		.desc = {
561 			.name = "buck4",
562 			.of_match = of_match_ptr("BUCK4"),
563 			.regulators_node = of_match_ptr("regulators"),
564 			.id = BD718XX_BUCK4,
565 			.ops = &bd718xx_pickable_range_buck_ops,
566 			.type = REGULATOR_VOLTAGE,
567 			.n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
568 			.linear_ranges = bd71847_buck4_volts,
569 			.n_linear_ranges =
570 				ARRAY_SIZE(bd71847_buck4_volts),
571 			.enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
572 			.vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
573 			.vsel_mask = BD71847_BUCK4_MASK,
574 			.vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
575 			.vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
576 			.linear_range_selectors = bd71847_buck4_volt_range_sel,
577 			.enable_mask = BD718XX_BUCK_EN,
578 			.owner = THIS_MODULE,
579 		},
580 		.init = {
581 			.reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
582 			.mask = BD718XX_BUCK_SEL,
583 			.val = BD718XX_BUCK_SEL,
584 		},
585 	},
586 	{
587 		.desc = {
588 			.name = "buck5",
589 			.of_match = of_match_ptr("BUCK5"),
590 			.regulators_node = of_match_ptr("regulators"),
591 			.id = BD718XX_BUCK5,
592 			.ops = &bd718xx_buck_regulator_nolinear_ops,
593 			.type = REGULATOR_VOLTAGE,
594 			.volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
595 			.n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
596 			.vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
597 			.vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
598 			.enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
599 			.enable_mask = BD718XX_BUCK_EN,
600 			.owner = THIS_MODULE,
601 		},
602 		.init = {
603 			.reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
604 			.mask = BD718XX_BUCK_SEL,
605 			.val = BD718XX_BUCK_SEL,
606 		},
607 	},
608 	{
609 		.desc = {
610 			.name = "buck6",
611 			.of_match = of_match_ptr("BUCK6"),
612 			.regulators_node = of_match_ptr("regulators"),
613 			.id = BD718XX_BUCK6,
614 			.ops = &bd718xx_buck_regulator_ops,
615 			.type = REGULATOR_VOLTAGE,
616 			.n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
617 			.linear_ranges = bd718xx_4th_nodvs_buck_volts,
618 			.n_linear_ranges =
619 				ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
620 			.vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
621 			.vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
622 			.enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
623 			.enable_mask = BD718XX_BUCK_EN,
624 			.owner = THIS_MODULE,
625 		},
626 		.init = {
627 			.reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
628 			.mask = BD718XX_BUCK_SEL,
629 			.val = BD718XX_BUCK_SEL,
630 		},
631 	},
632 	{
633 		.desc = {
634 			.name = "ldo1",
635 			.of_match = of_match_ptr("LDO1"),
636 			.regulators_node = of_match_ptr("regulators"),
637 			.id = BD718XX_LDO1,
638 			.ops = &bd718xx_pickable_range_ldo_ops,
639 			.type = REGULATOR_VOLTAGE,
640 			.n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
641 			.linear_ranges = bd718xx_ldo1_volts,
642 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
643 			.vsel_reg = BD718XX_REG_LDO1_VOLT,
644 			.vsel_mask = BD718XX_LDO1_MASK,
645 			.vsel_range_reg = BD718XX_REG_LDO1_VOLT,
646 			.vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
647 			.linear_range_selectors = bd718xx_ldo1_volt_range_sel,
648 			.enable_reg = BD718XX_REG_LDO1_VOLT,
649 			.enable_mask = BD718XX_LDO_EN,
650 			.owner = THIS_MODULE,
651 		},
652 		.init = {
653 			.reg = BD718XX_REG_LDO1_VOLT,
654 			.mask = BD718XX_LDO_SEL,
655 			.val = BD718XX_LDO_SEL,
656 		},
657 	},
658 	{
659 		.desc = {
660 			.name = "ldo2",
661 			.of_match = of_match_ptr("LDO2"),
662 			.regulators_node = of_match_ptr("regulators"),
663 			.id = BD718XX_LDO2,
664 			.ops = &bd718xx_ldo_regulator_nolinear_ops,
665 			.type = REGULATOR_VOLTAGE,
666 			.volt_table = &ldo_2_volts[0],
667 			.vsel_reg = BD718XX_REG_LDO2_VOLT,
668 			.vsel_mask = BD718XX_LDO2_MASK,
669 			.n_voltages = ARRAY_SIZE(ldo_2_volts),
670 			.enable_reg = BD718XX_REG_LDO2_VOLT,
671 			.enable_mask = BD718XX_LDO_EN,
672 			.owner = THIS_MODULE,
673 		},
674 		.init = {
675 			.reg = BD718XX_REG_LDO2_VOLT,
676 			.mask = BD718XX_LDO_SEL,
677 			.val = BD718XX_LDO_SEL,
678 		},
679 	},
680 	{
681 		.desc = {
682 			.name = "ldo3",
683 			.of_match = of_match_ptr("LDO3"),
684 			.regulators_node = of_match_ptr("regulators"),
685 			.id = BD718XX_LDO3,
686 			.ops = &bd718xx_ldo_regulator_ops,
687 			.type = REGULATOR_VOLTAGE,
688 			.n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
689 			.linear_ranges = bd718xx_ldo3_volts,
690 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
691 			.vsel_reg = BD718XX_REG_LDO3_VOLT,
692 			.vsel_mask = BD718XX_LDO3_MASK,
693 			.enable_reg = BD718XX_REG_LDO3_VOLT,
694 			.enable_mask = BD718XX_LDO_EN,
695 			.owner = THIS_MODULE,
696 		},
697 		.init = {
698 			.reg = BD718XX_REG_LDO3_VOLT,
699 			.mask = BD718XX_LDO_SEL,
700 			.val = BD718XX_LDO_SEL,
701 		},
702 	},
703 	{
704 		.desc = {
705 			.name = "ldo4",
706 			.of_match = of_match_ptr("LDO4"),
707 			.regulators_node = of_match_ptr("regulators"),
708 			.id = BD718XX_LDO4,
709 			.ops = &bd718xx_ldo_regulator_ops,
710 			.type = REGULATOR_VOLTAGE,
711 			.n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
712 			.linear_ranges = bd718xx_ldo4_volts,
713 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
714 			.vsel_reg = BD718XX_REG_LDO4_VOLT,
715 			.vsel_mask = BD718XX_LDO4_MASK,
716 			.enable_reg = BD718XX_REG_LDO4_VOLT,
717 			.enable_mask = BD718XX_LDO_EN,
718 			.owner = THIS_MODULE,
719 		},
720 		.init = {
721 			.reg = BD718XX_REG_LDO4_VOLT,
722 			.mask = BD718XX_LDO_SEL,
723 			.val = BD718XX_LDO_SEL,
724 		},
725 	},
726 	{
727 		.desc = {
728 			.name = "ldo5",
729 			.of_match = of_match_ptr("LDO5"),
730 			.regulators_node = of_match_ptr("regulators"),
731 			.id = BD718XX_LDO5,
732 			.ops = &bd718xx_pickable_range_ldo_ops,
733 			.type = REGULATOR_VOLTAGE,
734 			.n_voltages = BD71847_LDO5_VOLTAGE_NUM,
735 			.linear_ranges = bd71847_ldo5_volts,
736 			.n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
737 			.vsel_reg = BD718XX_REG_LDO5_VOLT,
738 			.vsel_mask = BD71847_LDO5_MASK,
739 			.vsel_range_reg = BD718XX_REG_LDO5_VOLT,
740 			.vsel_range_mask = BD71847_LDO5_RANGE_MASK,
741 			.linear_range_selectors = bd71847_ldo5_volt_range_sel,
742 			.enable_reg = BD718XX_REG_LDO5_VOLT,
743 			.enable_mask = BD718XX_LDO_EN,
744 			.owner = THIS_MODULE,
745 		},
746 		.init = {
747 			.reg = BD718XX_REG_LDO5_VOLT,
748 			.mask = BD718XX_LDO_SEL,
749 			.val = BD718XX_LDO_SEL,
750 		},
751 	},
752 	{
753 		.desc = {
754 			.name = "ldo6",
755 			.of_match = of_match_ptr("LDO6"),
756 			.regulators_node = of_match_ptr("regulators"),
757 			.id = BD718XX_LDO6,
758 			.ops = &bd718xx_ldo_regulator_ops,
759 			.type = REGULATOR_VOLTAGE,
760 			.n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
761 			.linear_ranges = bd718xx_ldo6_volts,
762 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
763 			/* LDO6 is supplied by buck5 */
764 			.supply_name = "buck5",
765 			.vsel_reg = BD718XX_REG_LDO6_VOLT,
766 			.vsel_mask = BD718XX_LDO6_MASK,
767 			.enable_reg = BD718XX_REG_LDO6_VOLT,
768 			.enable_mask = BD718XX_LDO_EN,
769 			.owner = THIS_MODULE,
770 		},
771 		.init = {
772 			.reg = BD718XX_REG_LDO6_VOLT,
773 			.mask = BD718XX_LDO_SEL,
774 			.val = BD718XX_LDO_SEL,
775 		},
776 	},
777 };
778 
779 static const struct bd718xx_regulator_data bd71837_regulators[] = {
780 	{
781 		.desc = {
782 			.name = "buck1",
783 			.of_match = of_match_ptr("BUCK1"),
784 			.regulators_node = of_match_ptr("regulators"),
785 			.id = BD718XX_BUCK1,
786 			.ops = &bd718xx_dvs_buck_regulator_ops,
787 			.type = REGULATOR_VOLTAGE,
788 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
789 			.linear_ranges = bd718xx_dvs_buck_volts,
790 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
791 			.vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
792 			.vsel_mask = DVS_BUCK_RUN_MASK,
793 			.enable_reg = BD718XX_REG_BUCK1_CTRL,
794 			.enable_mask = BD718XX_BUCK_EN,
795 			.owner = THIS_MODULE,
796 			.of_parse_cb = buck1_set_hw_dvs_levels,
797 		},
798 		.init = {
799 			.reg = BD718XX_REG_BUCK1_CTRL,
800 			.mask = BD718XX_BUCK_SEL,
801 			.val = BD718XX_BUCK_SEL,
802 		},
803 	},
804 	{
805 		.desc = {
806 			.name = "buck2",
807 			.of_match = of_match_ptr("BUCK2"),
808 			.regulators_node = of_match_ptr("regulators"),
809 			.id = BD718XX_BUCK2,
810 			.ops = &bd718xx_dvs_buck_regulator_ops,
811 			.type = REGULATOR_VOLTAGE,
812 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
813 			.linear_ranges = bd718xx_dvs_buck_volts,
814 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
815 			.vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
816 			.vsel_mask = DVS_BUCK_RUN_MASK,
817 			.enable_reg = BD718XX_REG_BUCK2_CTRL,
818 			.enable_mask = BD718XX_BUCK_EN,
819 			.owner = THIS_MODULE,
820 			.of_parse_cb = buck2_set_hw_dvs_levels,
821 		},
822 		.init = {
823 			.reg = BD718XX_REG_BUCK2_CTRL,
824 			.mask = BD718XX_BUCK_SEL,
825 			.val = BD718XX_BUCK_SEL,
826 		},
827 	},
828 	{
829 		.desc = {
830 			.name = "buck3",
831 			.of_match = of_match_ptr("BUCK3"),
832 			.regulators_node = of_match_ptr("regulators"),
833 			.id = BD718XX_BUCK3,
834 			.ops = &bd718xx_dvs_buck_regulator_ops,
835 			.type = REGULATOR_VOLTAGE,
836 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
837 			.linear_ranges = bd718xx_dvs_buck_volts,
838 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
839 			.vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
840 			.vsel_mask = DVS_BUCK_RUN_MASK,
841 			.enable_reg = BD71837_REG_BUCK3_CTRL,
842 			.enable_mask = BD718XX_BUCK_EN,
843 			.owner = THIS_MODULE,
844 			.of_parse_cb = buck3_set_hw_dvs_levels,
845 		},
846 		.init = {
847 			.reg = BD71837_REG_BUCK3_CTRL,
848 			.mask = BD718XX_BUCK_SEL,
849 			.val = BD718XX_BUCK_SEL,
850 		},
851 	},
852 	{
853 		.desc = {
854 			.name = "buck4",
855 			.of_match = of_match_ptr("BUCK4"),
856 			.regulators_node = of_match_ptr("regulators"),
857 			.id = BD718XX_BUCK4,
858 			.ops = &bd718xx_dvs_buck_regulator_ops,
859 			.type = REGULATOR_VOLTAGE,
860 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
861 			.linear_ranges = bd718xx_dvs_buck_volts,
862 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
863 			.vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
864 			.vsel_mask = DVS_BUCK_RUN_MASK,
865 			.enable_reg = BD71837_REG_BUCK4_CTRL,
866 			.enable_mask = BD718XX_BUCK_EN,
867 			.owner = THIS_MODULE,
868 			.of_parse_cb = buck4_set_hw_dvs_levels,
869 		},
870 		.init = {
871 			.reg = BD71837_REG_BUCK4_CTRL,
872 			.mask = BD718XX_BUCK_SEL,
873 			.val = BD718XX_BUCK_SEL,
874 		},
875 	},
876 	{
877 		.desc = {
878 			.name = "buck5",
879 			.of_match = of_match_ptr("BUCK5"),
880 			.regulators_node = of_match_ptr("regulators"),
881 			.id = BD718XX_BUCK5,
882 			.ops = &bd718xx_pickable_range_buck_ops,
883 			.type = REGULATOR_VOLTAGE,
884 			.n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
885 			.linear_ranges = bd71837_buck5_volts,
886 			.n_linear_ranges =
887 				ARRAY_SIZE(bd71837_buck5_volts),
888 			.vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
889 			.vsel_mask = BD71837_BUCK5_MASK,
890 			.vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
891 			.vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
892 			.linear_range_selectors = bd71837_buck5_volt_range_sel,
893 			.enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
894 			.enable_mask = BD718XX_BUCK_EN,
895 			.owner = THIS_MODULE,
896 		},
897 		.init = {
898 			.reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
899 			.mask = BD718XX_BUCK_SEL,
900 			.val = BD718XX_BUCK_SEL,
901 		},
902 	},
903 	{
904 		.desc = {
905 			.name = "buck6",
906 			.of_match = of_match_ptr("BUCK6"),
907 			.regulators_node = of_match_ptr("regulators"),
908 			.id = BD718XX_BUCK6,
909 			.ops = &bd718xx_buck_regulator_ops,
910 			.type = REGULATOR_VOLTAGE,
911 			.n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
912 			.linear_ranges = bd71837_buck6_volts,
913 			.n_linear_ranges =
914 				ARRAY_SIZE(bd71837_buck6_volts),
915 			.vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
916 			.vsel_mask = BD71837_BUCK6_MASK,
917 			.enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
918 			.enable_mask = BD718XX_BUCK_EN,
919 			.owner = THIS_MODULE,
920 		},
921 		.init = {
922 			.reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
923 			.mask = BD718XX_BUCK_SEL,
924 			.val = BD718XX_BUCK_SEL,
925 		},
926 	},
927 	{
928 		.desc = {
929 			.name = "buck7",
930 			.of_match = of_match_ptr("BUCK7"),
931 			.regulators_node = of_match_ptr("regulators"),
932 			.id = BD718XX_BUCK7,
933 			.ops = &bd718xx_buck_regulator_nolinear_ops,
934 			.type = REGULATOR_VOLTAGE,
935 			.volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
936 			.n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
937 			.vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
938 			.vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
939 			.enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
940 			.enable_mask = BD718XX_BUCK_EN,
941 			.owner = THIS_MODULE,
942 		},
943 		.init = {
944 			.reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
945 			.mask = BD718XX_BUCK_SEL,
946 			.val = BD718XX_BUCK_SEL,
947 		},
948 	},
949 	{
950 		.desc = {
951 			.name = "buck8",
952 			.of_match = of_match_ptr("BUCK8"),
953 			.regulators_node = of_match_ptr("regulators"),
954 			.id = BD718XX_BUCK8,
955 			.ops = &bd718xx_buck_regulator_ops,
956 			.type = REGULATOR_VOLTAGE,
957 			.n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
958 			.linear_ranges = bd718xx_4th_nodvs_buck_volts,
959 			.n_linear_ranges =
960 				ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
961 			.vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
962 			.vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
963 			.enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
964 			.enable_mask = BD718XX_BUCK_EN,
965 			.owner = THIS_MODULE,
966 		},
967 		.init = {
968 			.reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
969 			.mask = BD718XX_BUCK_SEL,
970 			.val = BD718XX_BUCK_SEL,
971 		},
972 	},
973 	{
974 		.desc = {
975 			.name = "ldo1",
976 			.of_match = of_match_ptr("LDO1"),
977 			.regulators_node = of_match_ptr("regulators"),
978 			.id = BD718XX_LDO1,
979 			.ops = &bd718xx_pickable_range_ldo_ops,
980 			.type = REGULATOR_VOLTAGE,
981 			.n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
982 			.linear_ranges = bd718xx_ldo1_volts,
983 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
984 			.vsel_reg = BD718XX_REG_LDO1_VOLT,
985 			.vsel_mask = BD718XX_LDO1_MASK,
986 			.vsel_range_reg = BD718XX_REG_LDO1_VOLT,
987 			.vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
988 			.linear_range_selectors = bd718xx_ldo1_volt_range_sel,
989 			.enable_reg = BD718XX_REG_LDO1_VOLT,
990 			.enable_mask = BD718XX_LDO_EN,
991 			.owner = THIS_MODULE,
992 		},
993 		.init = {
994 			.reg = BD718XX_REG_LDO1_VOLT,
995 			.mask = BD718XX_LDO_SEL,
996 			.val = BD718XX_LDO_SEL,
997 		},
998 	},
999 	{
1000 		.desc = {
1001 			.name = "ldo2",
1002 			.of_match = of_match_ptr("LDO2"),
1003 			.regulators_node = of_match_ptr("regulators"),
1004 			.id = BD718XX_LDO2,
1005 			.ops = &bd718xx_ldo_regulator_nolinear_ops,
1006 			.type = REGULATOR_VOLTAGE,
1007 			.volt_table = &ldo_2_volts[0],
1008 			.vsel_reg = BD718XX_REG_LDO2_VOLT,
1009 			.vsel_mask = BD718XX_LDO2_MASK,
1010 			.n_voltages = ARRAY_SIZE(ldo_2_volts),
1011 			.enable_reg = BD718XX_REG_LDO2_VOLT,
1012 			.enable_mask = BD718XX_LDO_EN,
1013 			.owner = THIS_MODULE,
1014 		},
1015 		.init = {
1016 			.reg = BD718XX_REG_LDO2_VOLT,
1017 			.mask = BD718XX_LDO_SEL,
1018 			.val = BD718XX_LDO_SEL,
1019 		},
1020 	},
1021 	{
1022 		.desc = {
1023 			.name = "ldo3",
1024 			.of_match = of_match_ptr("LDO3"),
1025 			.regulators_node = of_match_ptr("regulators"),
1026 			.id = BD718XX_LDO3,
1027 			.ops = &bd718xx_ldo_regulator_ops,
1028 			.type = REGULATOR_VOLTAGE,
1029 			.n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
1030 			.linear_ranges = bd718xx_ldo3_volts,
1031 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
1032 			.vsel_reg = BD718XX_REG_LDO3_VOLT,
1033 			.vsel_mask = BD718XX_LDO3_MASK,
1034 			.enable_reg = BD718XX_REG_LDO3_VOLT,
1035 			.enable_mask = BD718XX_LDO_EN,
1036 			.owner = THIS_MODULE,
1037 		},
1038 		.init = {
1039 			.reg = BD718XX_REG_LDO3_VOLT,
1040 			.mask = BD718XX_LDO_SEL,
1041 			.val = BD718XX_LDO_SEL,
1042 		},
1043 	},
1044 	{
1045 		.desc = {
1046 			.name = "ldo4",
1047 			.of_match = of_match_ptr("LDO4"),
1048 			.regulators_node = of_match_ptr("regulators"),
1049 			.id = BD718XX_LDO4,
1050 			.ops = &bd718xx_ldo_regulator_ops,
1051 			.type = REGULATOR_VOLTAGE,
1052 			.n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
1053 			.linear_ranges = bd718xx_ldo4_volts,
1054 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
1055 			.vsel_reg = BD718XX_REG_LDO4_VOLT,
1056 			.vsel_mask = BD718XX_LDO4_MASK,
1057 			.enable_reg = BD718XX_REG_LDO4_VOLT,
1058 			.enable_mask = BD718XX_LDO_EN,
1059 			.owner = THIS_MODULE,
1060 		},
1061 		.init = {
1062 			.reg = BD718XX_REG_LDO4_VOLT,
1063 			.mask = BD718XX_LDO_SEL,
1064 			.val = BD718XX_LDO_SEL,
1065 		},
1066 	},
1067 	{
1068 		.desc = {
1069 			.name = "ldo5",
1070 			.of_match = of_match_ptr("LDO5"),
1071 			.regulators_node = of_match_ptr("regulators"),
1072 			.id = BD718XX_LDO5,
1073 			.ops = &bd718xx_ldo_regulator_ops,
1074 			.type = REGULATOR_VOLTAGE,
1075 			.n_voltages = BD71837_LDO5_VOLTAGE_NUM,
1076 			.linear_ranges = bd71837_ldo5_volts,
1077 			.n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
1078 			/* LDO5 is supplied by buck6 */
1079 			.supply_name = "buck6",
1080 			.vsel_reg = BD718XX_REG_LDO5_VOLT,
1081 			.vsel_mask = BD71837_LDO5_MASK,
1082 			.enable_reg = BD718XX_REG_LDO5_VOLT,
1083 			.enable_mask = BD718XX_LDO_EN,
1084 			.owner = THIS_MODULE,
1085 		},
1086 		.init = {
1087 			.reg = BD718XX_REG_LDO5_VOLT,
1088 			.mask = BD718XX_LDO_SEL,
1089 			.val = BD718XX_LDO_SEL,
1090 		},
1091 		.additional_inits = bd71837_ldo5_inits,
1092 		.additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
1093 	},
1094 	{
1095 		.desc = {
1096 			.name = "ldo6",
1097 			.of_match = of_match_ptr("LDO6"),
1098 			.regulators_node = of_match_ptr("regulators"),
1099 			.id = BD718XX_LDO6,
1100 			.ops = &bd718xx_ldo_regulator_ops,
1101 			.type = REGULATOR_VOLTAGE,
1102 			.n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
1103 			.linear_ranges = bd718xx_ldo6_volts,
1104 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
1105 			/* LDO6 is supplied by buck7 */
1106 			.supply_name = "buck7",
1107 			.vsel_reg = BD718XX_REG_LDO6_VOLT,
1108 			.vsel_mask = BD718XX_LDO6_MASK,
1109 			.enable_reg = BD718XX_REG_LDO6_VOLT,
1110 			.enable_mask = BD718XX_LDO_EN,
1111 			.owner = THIS_MODULE,
1112 		},
1113 		.init = {
1114 			.reg = BD718XX_REG_LDO6_VOLT,
1115 			.mask = BD718XX_LDO_SEL,
1116 			.val = BD718XX_LDO_SEL,
1117 		},
1118 		.additional_inits = bd71837_ldo6_inits,
1119 		.additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
1120 	},
1121 	{
1122 		.desc = {
1123 			.name = "ldo7",
1124 			.of_match = of_match_ptr("LDO7"),
1125 			.regulators_node = of_match_ptr("regulators"),
1126 			.id = BD718XX_LDO7,
1127 			.ops = &bd718xx_ldo_regulator_ops,
1128 			.type = REGULATOR_VOLTAGE,
1129 			.n_voltages = BD71837_LDO7_VOLTAGE_NUM,
1130 			.linear_ranges = bd71837_ldo7_volts,
1131 			.n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
1132 			.vsel_reg = BD71837_REG_LDO7_VOLT,
1133 			.vsel_mask = BD71837_LDO7_MASK,
1134 			.enable_reg = BD71837_REG_LDO7_VOLT,
1135 			.enable_mask = BD718XX_LDO_EN,
1136 			.owner = THIS_MODULE,
1137 		},
1138 		.init = {
1139 			.reg = BD71837_REG_LDO7_VOLT,
1140 			.mask = BD718XX_LDO_SEL,
1141 			.val = BD718XX_LDO_SEL,
1142 		},
1143 	},
1144 };
1145 
1146 struct bd718xx_pmic_inits {
1147 	const struct bd718xx_regulator_data *r_datas;
1148 	unsigned int r_amount;
1149 };
1150 
1151 static int bd718xx_probe(struct platform_device *pdev)
1152 {
1153 	struct bd718xx *mfd;
1154 	struct regulator_config config = { 0 };
1155 	struct bd718xx_pmic_inits pmic_regulators[] = {
1156 		[BD718XX_TYPE_BD71837] = {
1157 			.r_datas = bd71837_regulators,
1158 			.r_amount = ARRAY_SIZE(bd71837_regulators),
1159 		},
1160 		[BD718XX_TYPE_BD71847] = {
1161 			.r_datas = bd71847_regulators,
1162 			.r_amount = ARRAY_SIZE(bd71847_regulators),
1163 		},
1164 	};
1165 
1166 	int i, j, err;
1167 	bool use_snvs;
1168 
1169 	mfd = dev_get_drvdata(pdev->dev.parent);
1170 	if (!mfd) {
1171 		dev_err(&pdev->dev, "No MFD driver data\n");
1172 		err = -EINVAL;
1173 		goto err;
1174 	}
1175 
1176 	if (mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
1177 	    !pmic_regulators[mfd->chip_type].r_datas) {
1178 		dev_err(&pdev->dev, "Unsupported chip type\n");
1179 		err = -EINVAL;
1180 		goto err;
1181 	}
1182 
1183 	/* Register LOCK release */
1184 	err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK,
1185 				 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1186 	if (err) {
1187 		dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
1188 		goto err;
1189 	} else {
1190 		dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
1191 			BD718XX_REG_REGLOCK);
1192 	}
1193 
1194 	use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
1195 					 "rohm,reset-snvs-powered");
1196 
1197 	/*
1198 	 * Change the next stage from poweroff to be READY instead of SNVS
1199 	 * for all reset types because OTP loading at READY will clear SEL
1200 	 * bit allowing HW defaults for power rails to be used
1201 	 */
1202 	if (!use_snvs) {
1203 		err = regmap_update_bits(mfd->regmap, BD718XX_REG_TRANS_COND1,
1204 					 BD718XX_ON_REQ_POWEROFF_MASK |
1205 					 BD718XX_SWRESET_POWEROFF_MASK |
1206 					 BD718XX_WDOG_POWEROFF_MASK |
1207 					 BD718XX_KEY_L_POWEROFF_MASK,
1208 					 BD718XX_POWOFF_TO_RDY);
1209 		if (err) {
1210 			dev_err(&pdev->dev, "Failed to change reset target\n");
1211 			goto err;
1212 		} else {
1213 			dev_dbg(&pdev->dev,
1214 				"Changed all resets from SVNS to READY\n");
1215 		}
1216 	}
1217 
1218 	for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
1219 
1220 		const struct regulator_desc *desc;
1221 		struct regulator_dev *rdev;
1222 		const struct bd718xx_regulator_data *r;
1223 
1224 		r = &pmic_regulators[mfd->chip_type].r_datas[i];
1225 		desc = &r->desc;
1226 
1227 		config.dev = pdev->dev.parent;
1228 		config.regmap = mfd->regmap;
1229 
1230 		rdev = devm_regulator_register(&pdev->dev, desc, &config);
1231 		if (IS_ERR(rdev)) {
1232 			dev_err(&pdev->dev,
1233 				"failed to register %s regulator\n",
1234 				desc->name);
1235 			err = PTR_ERR(rdev);
1236 			goto err;
1237 		}
1238 
1239 		/*
1240 		 * Regulator register gets the regulator constraints and
1241 		 * applies them (set_machine_constraints). This should have
1242 		 * turned the control register(s) to correct values and we
1243 		 * can now switch the control from PMIC state machine to the
1244 		 * register interface
1245 		 *
1246 		 * At poweroff transition PMIC HW disables EN bit for
1247 		 * regulators but leaves SEL bit untouched. So if state
1248 		 * transition from POWEROFF is done to SNVS - then all power
1249 		 * rails controlled by SW (having SEL bit set) stay disabled
1250 		 * as EN is cleared. This will result boot failure if any
1251 		 * crucial systems are powered by these rails. We don't
1252 		 * enable SW control for crucial regulators if snvs state is
1253 		 * used
1254 		 */
1255 		if (!use_snvs || !rdev->constraints->always_on ||
1256 		    !rdev->constraints->boot_on) {
1257 			err = regmap_update_bits(mfd->regmap, r->init.reg,
1258 						 r->init.mask, r->init.val);
1259 			if (err) {
1260 				dev_err(&pdev->dev,
1261 					"Failed to take control for (%s)\n",
1262 					desc->name);
1263 				goto err;
1264 			}
1265 		}
1266 		for (j = 0; j < r->additional_init_amnt; j++) {
1267 			err = regmap_update_bits(mfd->regmap,
1268 						 r->additional_inits[j].reg,
1269 						 r->additional_inits[j].mask,
1270 						 r->additional_inits[j].val);
1271 			if (err) {
1272 				dev_err(&pdev->dev,
1273 					"Buck (%s) initialization failed\n",
1274 					desc->name);
1275 				goto err;
1276 			}
1277 		}
1278 	}
1279 
1280 err:
1281 	return err;
1282 }
1283 
1284 static struct platform_driver bd718xx_regulator = {
1285 	.driver = {
1286 		.name = "bd718xx-pmic",
1287 	},
1288 	.probe = bd718xx_probe,
1289 };
1290 
1291 module_platform_driver(bd718xx_regulator);
1292 
1293 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
1294 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1295 MODULE_LICENSE("GPL");
1296