xref: /linux/drivers/regulator/bd718x7-regulator.c (revision 281a94b0f2f0775a2b7825c18bccf7e4c922b7b3)
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/interrupt.h>
8 #include <linux/kernel.h>
9 #include <linux/mfd/rohm-bd718x7.h>
10 #include <linux/module.h>
11 #include <linux/of.h>
12 #include <linux/platform_device.h>
13 #include <linux/regulator/driver.h>
14 #include <linux/regulator/machine.h>
15 #include <linux/regulator/of_regulator.h>
16 #include <linux/slab.h>
17 
18 /*
19  * BD718(37/47/50) have two "enable control modes". ON/OFF can either be
20  * controlled by software - or by PMIC internal HW state machine. Whether
21  * regulator should be under SW or HW control can be defined from device-tree.
22  * Let's provide separate ops for regulators to use depending on the "enable
23  * control mode".
24  */
25 #define BD718XX_HWOPNAME(swopname) swopname##_hwcontrol
26 
27 #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \
28 		   _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay) \
29 static const struct regulator_ops name = {			\
30 	.enable = regulator_enable_regmap,			\
31 	.disable = regulator_disable_regmap,			\
32 	.is_enabled = regulator_is_enabled_regmap,		\
33 	.list_voltage = (_list_voltage),			\
34 	.map_voltage = (_map_voltage),				\
35 	.set_voltage_sel = (_set_voltage_sel),			\
36 	.get_voltage_sel = (_get_voltage_sel),			\
37 	.set_voltage_time_sel = (_set_voltage_time_sel),	\
38 	.set_ramp_delay = (_set_ramp_delay),			\
39 };								\
40 								\
41 static const struct regulator_ops BD718XX_HWOPNAME(name) = {	\
42 	.is_enabled = always_enabled_by_hwstate,		\
43 	.list_voltage = (_list_voltage),			\
44 	.map_voltage = (_map_voltage),				\
45 	.set_voltage_sel = (_set_voltage_sel),			\
46 	.get_voltage_sel = (_get_voltage_sel),			\
47 	.set_voltage_time_sel = (_set_voltage_time_sel),	\
48 	.set_ramp_delay = (_set_ramp_delay),			\
49 }								\
50 
51 /*
52  * BUCK1/2/3/4
53  * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
54  * 00: 10.00mV/usec 10mV 1uS
55  * 01: 5.00mV/usec	10mV 2uS
56  * 10: 2.50mV/usec	10mV 4uS
57  * 11: 1.25mV/usec	10mV 8uS
58  */
59 static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
60 					   int ramp_delay)
61 {
62 	int id = rdev_get_id(rdev);
63 	unsigned int ramp_value;
64 
65 	dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
66 		ramp_delay);
67 	switch (ramp_delay) {
68 	case 1 ... 1250:
69 		ramp_value = BUCK_RAMPRATE_1P25MV;
70 		break;
71 	case 1251 ... 2500:
72 		ramp_value = BUCK_RAMPRATE_2P50MV;
73 		break;
74 	case 2501 ... 5000:
75 		ramp_value = BUCK_RAMPRATE_5P00MV;
76 		break;
77 	case 5001 ... 10000:
78 		ramp_value = BUCK_RAMPRATE_10P00MV;
79 		break;
80 	default:
81 		ramp_value = BUCK_RAMPRATE_10P00MV;
82 		dev_err(&rdev->dev,
83 			"%s: ramp_delay: %d not supported, setting 10000mV//us\n",
84 			rdev->desc->name, ramp_delay);
85 	}
86 
87 	return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
88 				  BUCK_RAMPRATE_MASK, ramp_value << 6);
89 }
90 
91 /* These functions are used when regulators are under HW state machine control.
92  * We assume PMIC is in RUN state because SW running and able to query the
93  * status. Most of the regulators have fixed ON or OFF state at RUN/IDLE so for
94  * them we just return a constant. BD71837 BUCK3 and BUCK4 are exceptions as
95  * they support configuring the ON/OFF state for RUN.
96  *
97  * Note for next hacker - these PMICs have a register where the HW state can be
98  * read. If assuming RUN appears to be false in your use-case - you can
99  * implement state reading (although that is not going to be atomic) before
100  * returning the enable state.
101  */
102 static int always_enabled_by_hwstate(struct regulator_dev *rdev)
103 {
104 	return 1;
105 }
106 
107 static int never_enabled_by_hwstate(struct regulator_dev *rdev)
108 {
109 	return 0;
110 }
111 
112 static int bd71837_get_buck34_enable_hwctrl(struct regulator_dev *rdev)
113 {
114 	int ret;
115 	unsigned int val;
116 
117 	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
118 	if (ret)
119 		return ret;
120 
121 	return !!(BD718XX_BUCK_RUN_ON & val);
122 }
123 /*
124  * On BD71837 (not on BD71847, BD71850, ...)
125  * Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
126  * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
127  * is changed. Hence we return -EBUSY for these if voltage is changed
128  * when BUCK/LDO is enabled.
129  *
130  * On BD71847, BD71850, ... The LDO voltage can be changed when LDO is
131  * enabled. But if voltage is increased the LDO power-good monitoring
132  * must be disabled for the duration of changing + 1mS to ensure voltage
133  * has reached the higher level before HW does next under voltage detection
134  * cycle.
135  */
136 static int bd71837_set_voltage_sel_restricted(struct regulator_dev *rdev,
137 						    unsigned int sel)
138 {
139 	if (rdev->desc->ops->is_enabled(rdev))
140 		return -EBUSY;
141 
142 	return regulator_set_voltage_sel_regmap(rdev, sel);
143 }
144 
145 static void voltage_change_done(struct regulator_dev *rdev, unsigned int sel,
146 				unsigned int *mask)
147 {
148 	int ret;
149 
150 	if (*mask) {
151 		/*
152 		 * Let's allow scheduling as we use I2C anyways. We just need to
153 		 * guarantee minimum of 1ms sleep - it shouldn't matter if we
154 		 * exceed it due to the scheduling.
155 		 */
156 		msleep(1);
157 		/*
158 		 * Note for next hacker. The PWRGOOD should not be masked on
159 		 * BD71847 so we will just unconditionally enable detection
160 		 * when voltage is set.
161 		 * If someone want's to disable PWRGOOD he must implement
162 		 * caching and restoring the old value here. I am not
163 		 * aware of such use-cases so for the sake of the simplicity
164 		 * we just always enable PWRGOOD here.
165 		 */
166 		ret = regmap_update_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
167 					 *mask, 0);
168 		if (ret)
169 			dev_err(&rdev->dev,
170 				"Failed to re-enable voltage monitoring (%d)\n",
171 				ret);
172 	}
173 }
174 
175 static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int sel,
176 				  unsigned int *mask)
177 {
178 	int ret;
179 
180 	*mask = 0;
181 	if (rdev->desc->ops->is_enabled(rdev)) {
182 		int now, new;
183 
184 		now = rdev->desc->ops->get_voltage_sel(rdev);
185 		if (now < 0)
186 			return now;
187 
188 		now = rdev->desc->ops->list_voltage(rdev, now);
189 		if (now < 0)
190 			return now;
191 
192 		new = rdev->desc->ops->list_voltage(rdev, sel);
193 		if (new < 0)
194 			return new;
195 
196 		/*
197 		 * If we increase LDO voltage when LDO is enabled we need to
198 		 * disable the power-good detection until voltage has reached
199 		 * the new level. According to HW colleagues the maximum time
200 		 * it takes is 1000us. I assume that on systems with light load
201 		 * this might be less - and we could probably use DT to give
202 		 * system specific delay value if performance matters.
203 		 *
204 		 * Well, knowing we use I2C here and can add scheduling delays
205 		 * I don't think it is worth the hassle and I just add fixed
206 		 * 1ms sleep here (and allow scheduling). If this turns out to
207 		 * be a problem we can change it to delay and make the delay
208 		 * time configurable.
209 		 */
210 		if (new > now) {
211 			int ldo_offset = rdev->desc->id - BD718XX_LDO1;
212 
213 			*mask = BD718XX_LDO1_VRMON80 << ldo_offset;
214 			ret = regmap_update_bits(rdev->regmap,
215 						 BD718XX_REG_MVRFLTMASK2,
216 						 *mask, *mask);
217 			if (ret) {
218 				dev_err(&rdev->dev,
219 					"Failed to stop voltage monitoring\n");
220 				return ret;
221 			}
222 		}
223 	}
224 
225 	return 0;
226 }
227 
228 static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
229 						    unsigned int sel)
230 {
231 	int ret;
232 	int mask;
233 
234 	ret = voltage_change_prepare(rdev, sel, &mask);
235 	if (ret)
236 		return ret;
237 
238 	ret = regulator_set_voltage_sel_regmap(rdev, sel);
239 	voltage_change_done(rdev, sel, &mask);
240 
241 	return ret;
242 }
243 
244 static int bd718xx_set_voltage_sel_pickable_restricted(
245 		struct regulator_dev *rdev, unsigned int sel)
246 {
247 	int ret;
248 	int mask;
249 
250 	ret = voltage_change_prepare(rdev, sel, &mask);
251 	if (ret)
252 		return ret;
253 
254 	ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel);
255 	voltage_change_done(rdev, sel, &mask);
256 
257 	return ret;
258 }
259 
260 static int bd71837_set_voltage_sel_pickable_restricted(
261 		struct regulator_dev *rdev, unsigned int sel)
262 {
263 	if (rdev->desc->ops->is_enabled(rdev))
264 		return -EBUSY;
265 
266 	return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
267 }
268 
269 /*
270  * OPS common for BD71847 and BD71850
271  */
272 BD718XX_OPS(bd718xx_pickable_range_ldo_ops,
273 	    regulator_list_voltage_pickable_linear_range, NULL,
274 	    bd718xx_set_voltage_sel_pickable_restricted,
275 	    regulator_get_voltage_sel_pickable_regmap, NULL, NULL);
276 
277 /* BD71847 and BD71850 LDO 5 is by default OFF at RUN state */
278 static const struct regulator_ops bd718xx_ldo5_ops_hwstate = {
279 	.is_enabled = never_enabled_by_hwstate,
280 	.list_voltage = regulator_list_voltage_pickable_linear_range,
281 	.set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
282 	.get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
283 };
284 
285 BD718XX_OPS(bd718xx_pickable_range_buck_ops,
286 	    regulator_list_voltage_pickable_linear_range, NULL,
287 	    regulator_set_voltage_sel_pickable_regmap,
288 	    regulator_get_voltage_sel_pickable_regmap,
289 	    regulator_set_voltage_time_sel, NULL);
290 
291 BD718XX_OPS(bd718xx_ldo_regulator_ops, regulator_list_voltage_linear_range,
292 	    NULL, bd718xx_set_voltage_sel_restricted,
293 	    regulator_get_voltage_sel_regmap, NULL, NULL);
294 
295 BD718XX_OPS(bd718xx_ldo_regulator_nolinear_ops, regulator_list_voltage_table,
296 	    NULL, bd718xx_set_voltage_sel_restricted,
297 	    regulator_get_voltage_sel_regmap, NULL, NULL);
298 
299 BD718XX_OPS(bd718xx_buck_regulator_ops, regulator_list_voltage_linear_range,
300 	    NULL, regulator_set_voltage_sel_regmap,
301 	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
302 	    NULL);
303 
304 BD718XX_OPS(bd718xx_buck_regulator_nolinear_ops, regulator_list_voltage_table,
305 	    regulator_map_voltage_ascend, regulator_set_voltage_sel_regmap,
306 	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
307 	    NULL);
308 
309 /*
310  * OPS for BD71837
311  */
312 BD718XX_OPS(bd71837_pickable_range_ldo_ops,
313 	    regulator_list_voltage_pickable_linear_range, NULL,
314 	    bd71837_set_voltage_sel_pickable_restricted,
315 	    regulator_get_voltage_sel_pickable_regmap, NULL, NULL);
316 
317 BD718XX_OPS(bd71837_pickable_range_buck_ops,
318 	    regulator_list_voltage_pickable_linear_range, NULL,
319 	    bd71837_set_voltage_sel_pickable_restricted,
320 	    regulator_get_voltage_sel_pickable_regmap,
321 	    regulator_set_voltage_time_sel, NULL);
322 
323 BD718XX_OPS(bd71837_ldo_regulator_ops, regulator_list_voltage_linear_range,
324 	    NULL, bd71837_set_voltage_sel_restricted,
325 	    regulator_get_voltage_sel_regmap, NULL, NULL);
326 
327 BD718XX_OPS(bd71837_ldo_regulator_nolinear_ops, regulator_list_voltage_table,
328 	    NULL, bd71837_set_voltage_sel_restricted,
329 	    regulator_get_voltage_sel_regmap, NULL, NULL);
330 
331 BD718XX_OPS(bd71837_buck_regulator_ops, regulator_list_voltage_linear_range,
332 	    NULL, bd71837_set_voltage_sel_restricted,
333 	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
334 	    NULL);
335 
336 BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_table,
337 	    regulator_map_voltage_ascend, bd718xx_set_voltage_sel_restricted,
338 	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
339 	    NULL);
340 /*
341  * BD71837 bucks 3 and 4 support defining their enable/disable state also
342  * when buck enable state is under HW state machine control. In that case the
343  * bit [2] in CTRL register is used to indicate if regulator should be ON.
344  */
345 static const struct regulator_ops bd71837_buck34_ops_hwctrl = {
346 	.is_enabled = bd71837_get_buck34_enable_hwctrl,
347 	.list_voltage = regulator_list_voltage_linear_range,
348 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
349 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
350 	.set_voltage_time_sel = regulator_set_voltage_time_sel,
351 	.set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
352 };
353 
354 /*
355  * OPS for all of the ICs - BD718(37/47/50)
356  */
357 BD718XX_OPS(bd718xx_dvs_buck_regulator_ops, regulator_list_voltage_linear_range,
358 	    NULL, regulator_set_voltage_sel_regmap,
359 	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
360 	    bd718xx_buck1234_set_ramp_delay);
361 
362 /*
363  * BD71837 BUCK1/2/3/4
364  * BD71847 BUCK1/2
365  * 0.70 to 1.30V (10mV step)
366  */
367 static const struct linear_range bd718xx_dvs_buck_volts[] = {
368 	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
369 	REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
370 };
371 
372 /*
373  * BD71837 BUCK5
374  * 0.7V to 1.35V  (range 0)
375  * and
376  * 0.675 to 1.325 (range 1)
377  */
378 static const struct linear_range bd71837_buck5_volts[] = {
379 	/* Ranges when VOLT_SEL bit is 0 */
380 	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
381 	REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
382 	REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
383 	/* Ranges when VOLT_SEL bit is 1  */
384 	REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
385 	REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
386 	REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
387 };
388 
389 /*
390  * Range selector for first 3 linear ranges is 0x0
391  * and 0x1 for last 3 ranges.
392  */
393 static const unsigned int bd71837_buck5_volt_range_sel[] = {
394 	0x0, 0x0, 0x0, 0x80, 0x80, 0x80
395 };
396 
397 /*
398  * BD71847 BUCK3
399  */
400 static const struct linear_range bd71847_buck3_volts[] = {
401 	/* Ranges when VOLT_SEL bits are 00 */
402 	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
403 	REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
404 	REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
405 	/* Ranges when VOLT_SEL bits are 01 */
406 	REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
407 	/* Ranges when VOLT_SEL bits are 11 */
408 	REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
409 	REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
410 	REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
411 };
412 
413 static const unsigned int bd71847_buck3_volt_range_sel[] = {
414 	0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
415 };
416 
417 static const struct linear_range bd71847_buck4_volts[] = {
418 	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
419 	REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
420 };
421 
422 static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
423 
424 /*
425  * BUCK6
426  * 3.0V to 3.3V (step 100mV)
427  */
428 static const struct linear_range bd71837_buck6_volts[] = {
429 	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
430 };
431 
432 /*
433  * BD71837 BUCK7
434  * BD71847 BUCK5
435  * 000 = 1.605V
436  * 001 = 1.695V
437  * 010 = 1.755V
438  * 011 = 1.8V (Initial)
439  * 100 = 1.845V
440  * 101 = 1.905V
441  * 110 = 1.95V
442  * 111 = 1.995V
443  */
444 static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
445 	1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
446 };
447 
448 /*
449  * BUCK8
450  * 0.8V to 1.40V (step 10mV)
451  */
452 static const struct linear_range bd718xx_4th_nodvs_buck_volts[] = {
453 	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
454 };
455 
456 /*
457  * LDO1
458  * 3.0 to 3.3V (100mV step)
459  */
460 static const struct linear_range bd718xx_ldo1_volts[] = {
461 	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
462 	REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
463 };
464 
465 static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
466 
467 /*
468  * LDO2
469  * 0.8 or 0.9V
470  */
471 static const unsigned int ldo_2_volts[] = {
472 	900000, 800000
473 };
474 
475 /*
476  * LDO3
477  * 1.8 to 3.3V (100mV step)
478  */
479 static const struct linear_range bd718xx_ldo3_volts[] = {
480 	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
481 };
482 
483 /*
484  * LDO4
485  * 0.9 to 1.8V (100mV step)
486  */
487 static const struct linear_range bd718xx_ldo4_volts[] = {
488 	REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
489 };
490 
491 /*
492  * LDO5 for BD71837
493  * 1.8 to 3.3V (100mV step)
494  */
495 static const struct linear_range bd71837_ldo5_volts[] = {
496 	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
497 };
498 
499 /*
500  * LDO5 for BD71837
501  * 1.8 to 3.3V (100mV step)
502  */
503 static const struct linear_range bd71847_ldo5_volts[] = {
504 	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
505 	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
506 };
507 
508 static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
509 
510 /*
511  * LDO6
512  * 0.9 to 1.8V (100mV step)
513  */
514 static const struct linear_range bd718xx_ldo6_volts[] = {
515 	REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
516 };
517 
518 /*
519  * LDO7
520  * 1.8 to 3.3V (100mV step)
521  */
522 static const struct linear_range bd71837_ldo7_volts[] = {
523 	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
524 };
525 
526 struct reg_init {
527 	unsigned int reg;
528 	unsigned int mask;
529 	unsigned int val;
530 };
531 struct bd718xx_regulator_data {
532 	struct regulator_desc desc;
533 	const struct rohm_dvs_config dvs;
534 	const struct reg_init init;
535 	const struct reg_init *additional_inits;
536 	int additional_init_amnt;
537 };
538 
539 /*
540  * There is a HW quirk in BD71837. The shutdown sequence timings for
541  * bucks/LDOs which are controlled via register interface are changed.
542  * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
543  * beginning of shut-down sequence. As bucks 6 and 7 are parent
544  * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
545  * monitoring to errorneously detect under voltage and force PMIC to
546  * emergency state instead of poweroff. In order to avoid this we
547  * disable voltage monitoring for LDO5 and LDO6
548  */
549 static const struct reg_init bd71837_ldo5_inits[] = {
550 	{
551 		.reg = BD718XX_REG_MVRFLTMASK2,
552 		.mask = BD718XX_LDO5_VRMON80,
553 		.val = BD718XX_LDO5_VRMON80,
554 	},
555 };
556 
557 static const struct reg_init bd71837_ldo6_inits[] = {
558 	{
559 		.reg = BD718XX_REG_MVRFLTMASK2,
560 		.mask = BD718XX_LDO6_VRMON80,
561 		.val = BD718XX_LDO6_VRMON80,
562 	},
563 };
564 
565 static int buck_set_hw_dvs_levels(struct device_node *np,
566 			    const struct regulator_desc *desc,
567 			    struct regulator_config *cfg)
568 {
569 	struct bd718xx_regulator_data *data;
570 
571 	data = container_of(desc, struct bd718xx_regulator_data, desc);
572 
573 	return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
574 }
575 
576 static const struct regulator_ops *bd71847_swcontrol_ops[] = {
577 	&bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
578 	&bd718xx_pickable_range_buck_ops, &bd718xx_pickable_range_buck_ops,
579 	&bd718xx_buck_regulator_nolinear_ops, &bd718xx_buck_regulator_ops,
580 	&bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_nolinear_ops,
581 	&bd718xx_ldo_regulator_ops, &bd718xx_ldo_regulator_ops,
582 	&bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_ops,
583 };
584 
585 static const struct regulator_ops *bd71847_hwcontrol_ops[] = {
586 	&BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
587 	&BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
588 	&BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops),
589 	&BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops),
590 	&BD718XX_HWOPNAME(bd718xx_buck_regulator_nolinear_ops),
591 	&BD718XX_HWOPNAME(bd718xx_buck_regulator_ops),
592 	&BD718XX_HWOPNAME(bd718xx_pickable_range_ldo_ops),
593 	&BD718XX_HWOPNAME(bd718xx_ldo_regulator_nolinear_ops),
594 	&BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
595 	&BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
596 	&bd718xx_ldo5_ops_hwstate,
597 	&BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
598 };
599 
600 static struct bd718xx_regulator_data bd71847_regulators[] = {
601 	{
602 		.desc = {
603 			.name = "buck1",
604 			.of_match = of_match_ptr("BUCK1"),
605 			.regulators_node = of_match_ptr("regulators"),
606 			.id = BD718XX_BUCK1,
607 			.type = REGULATOR_VOLTAGE,
608 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
609 			.linear_ranges = bd718xx_dvs_buck_volts,
610 			.n_linear_ranges =
611 				ARRAY_SIZE(bd718xx_dvs_buck_volts),
612 			.vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
613 			.vsel_mask = DVS_BUCK_RUN_MASK,
614 			.enable_reg = BD718XX_REG_BUCK1_CTRL,
615 			.enable_mask = BD718XX_BUCK_EN,
616 			.owner = THIS_MODULE,
617 			.of_parse_cb = buck_set_hw_dvs_levels,
618 		},
619 		.dvs = {
620 			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
621 				     ROHM_DVS_LEVEL_SUSPEND,
622 			.run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
623 			.run_mask = DVS_BUCK_RUN_MASK,
624 			.idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
625 			.idle_mask = DVS_BUCK_RUN_MASK,
626 			.suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
627 			.suspend_mask = DVS_BUCK_RUN_MASK,
628 		},
629 		.init = {
630 			.reg = BD718XX_REG_BUCK1_CTRL,
631 			.mask = BD718XX_BUCK_SEL,
632 			.val = BD718XX_BUCK_SEL,
633 		},
634 	},
635 	{
636 		.desc = {
637 			.name = "buck2",
638 			.of_match = of_match_ptr("BUCK2"),
639 			.regulators_node = of_match_ptr("regulators"),
640 			.id = BD718XX_BUCK2,
641 			.type = REGULATOR_VOLTAGE,
642 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
643 			.linear_ranges = bd718xx_dvs_buck_volts,
644 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
645 			.vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
646 			.vsel_mask = DVS_BUCK_RUN_MASK,
647 			.enable_reg = BD718XX_REG_BUCK2_CTRL,
648 			.enable_mask = BD718XX_BUCK_EN,
649 			.owner = THIS_MODULE,
650 			.of_parse_cb = buck_set_hw_dvs_levels,
651 		},
652 		.dvs = {
653 			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
654 			.run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
655 			.run_mask = DVS_BUCK_RUN_MASK,
656 			.idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
657 			.idle_mask = DVS_BUCK_RUN_MASK,
658 		},
659 		.init = {
660 			.reg = BD718XX_REG_BUCK2_CTRL,
661 			.mask = BD718XX_BUCK_SEL,
662 			.val = BD718XX_BUCK_SEL,
663 		},
664 	},
665 	{
666 		.desc = {
667 			.name = "buck3",
668 			.of_match = of_match_ptr("BUCK3"),
669 			.regulators_node = of_match_ptr("regulators"),
670 			.id = BD718XX_BUCK3,
671 			.type = REGULATOR_VOLTAGE,
672 			.n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
673 			.linear_ranges = bd71847_buck3_volts,
674 			.n_linear_ranges =
675 				ARRAY_SIZE(bd71847_buck3_volts),
676 			.vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
677 			.vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
678 			.vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
679 			.vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
680 			.linear_range_selectors = bd71847_buck3_volt_range_sel,
681 			.enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
682 			.enable_mask = BD718XX_BUCK_EN,
683 			.owner = THIS_MODULE,
684 		},
685 		.init = {
686 			.reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
687 			.mask = BD718XX_BUCK_SEL,
688 			.val = BD718XX_BUCK_SEL,
689 		},
690 	},
691 	{
692 		.desc = {
693 			.name = "buck4",
694 			.of_match = of_match_ptr("BUCK4"),
695 			.regulators_node = of_match_ptr("regulators"),
696 			.id = BD718XX_BUCK4,
697 			.type = REGULATOR_VOLTAGE,
698 			.n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
699 			.linear_ranges = bd71847_buck4_volts,
700 			.n_linear_ranges =
701 				ARRAY_SIZE(bd71847_buck4_volts),
702 			.enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
703 			.vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
704 			.vsel_mask = BD71847_BUCK4_MASK,
705 			.vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
706 			.vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
707 			.linear_range_selectors = bd71847_buck4_volt_range_sel,
708 			.enable_mask = BD718XX_BUCK_EN,
709 			.owner = THIS_MODULE,
710 		},
711 		.init = {
712 			.reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
713 			.mask = BD718XX_BUCK_SEL,
714 			.val = BD718XX_BUCK_SEL,
715 		},
716 	},
717 	{
718 		.desc = {
719 			.name = "buck5",
720 			.of_match = of_match_ptr("BUCK5"),
721 			.regulators_node = of_match_ptr("regulators"),
722 			.id = BD718XX_BUCK5,
723 			.type = REGULATOR_VOLTAGE,
724 			.volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
725 			.n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
726 			.vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
727 			.vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
728 			.enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
729 			.enable_mask = BD718XX_BUCK_EN,
730 			.owner = THIS_MODULE,
731 		},
732 		.init = {
733 			.reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
734 			.mask = BD718XX_BUCK_SEL,
735 			.val = BD718XX_BUCK_SEL,
736 		},
737 	},
738 	{
739 		.desc = {
740 			.name = "buck6",
741 			.of_match = of_match_ptr("BUCK6"),
742 			.regulators_node = of_match_ptr("regulators"),
743 			.id = BD718XX_BUCK6,
744 			.type = REGULATOR_VOLTAGE,
745 			.n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
746 			.linear_ranges = bd718xx_4th_nodvs_buck_volts,
747 			.n_linear_ranges =
748 				ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
749 			.vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
750 			.vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
751 			.enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
752 			.enable_mask = BD718XX_BUCK_EN,
753 			.owner = THIS_MODULE,
754 		},
755 		.init = {
756 			.reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
757 			.mask = BD718XX_BUCK_SEL,
758 			.val = BD718XX_BUCK_SEL,
759 		},
760 	},
761 	{
762 		.desc = {
763 			.name = "ldo1",
764 			.of_match = of_match_ptr("LDO1"),
765 			.regulators_node = of_match_ptr("regulators"),
766 			.id = BD718XX_LDO1,
767 			.type = REGULATOR_VOLTAGE,
768 			.n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
769 			.linear_ranges = bd718xx_ldo1_volts,
770 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
771 			.vsel_reg = BD718XX_REG_LDO1_VOLT,
772 			.vsel_mask = BD718XX_LDO1_MASK,
773 			.vsel_range_reg = BD718XX_REG_LDO1_VOLT,
774 			.vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
775 			.linear_range_selectors = bd718xx_ldo1_volt_range_sel,
776 			.enable_reg = BD718XX_REG_LDO1_VOLT,
777 			.enable_mask = BD718XX_LDO_EN,
778 			.owner = THIS_MODULE,
779 		},
780 		.init = {
781 			.reg = BD718XX_REG_LDO1_VOLT,
782 			.mask = BD718XX_LDO_SEL,
783 			.val = BD718XX_LDO_SEL,
784 		},
785 	},
786 	{
787 		.desc = {
788 			.name = "ldo2",
789 			.of_match = of_match_ptr("LDO2"),
790 			.regulators_node = of_match_ptr("regulators"),
791 			.id = BD718XX_LDO2,
792 			.type = REGULATOR_VOLTAGE,
793 			.volt_table = &ldo_2_volts[0],
794 			.vsel_reg = BD718XX_REG_LDO2_VOLT,
795 			.vsel_mask = BD718XX_LDO2_MASK,
796 			.n_voltages = ARRAY_SIZE(ldo_2_volts),
797 			.enable_reg = BD718XX_REG_LDO2_VOLT,
798 			.enable_mask = BD718XX_LDO_EN,
799 			.owner = THIS_MODULE,
800 		},
801 		.init = {
802 			.reg = BD718XX_REG_LDO2_VOLT,
803 			.mask = BD718XX_LDO_SEL,
804 			.val = BD718XX_LDO_SEL,
805 		},
806 	},
807 	{
808 		.desc = {
809 			.name = "ldo3",
810 			.of_match = of_match_ptr("LDO3"),
811 			.regulators_node = of_match_ptr("regulators"),
812 			.id = BD718XX_LDO3,
813 			.type = REGULATOR_VOLTAGE,
814 			.n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
815 			.linear_ranges = bd718xx_ldo3_volts,
816 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
817 			.vsel_reg = BD718XX_REG_LDO3_VOLT,
818 			.vsel_mask = BD718XX_LDO3_MASK,
819 			.enable_reg = BD718XX_REG_LDO3_VOLT,
820 			.enable_mask = BD718XX_LDO_EN,
821 			.owner = THIS_MODULE,
822 		},
823 		.init = {
824 			.reg = BD718XX_REG_LDO3_VOLT,
825 			.mask = BD718XX_LDO_SEL,
826 			.val = BD718XX_LDO_SEL,
827 		},
828 	},
829 	{
830 		.desc = {
831 			.name = "ldo4",
832 			.of_match = of_match_ptr("LDO4"),
833 			.regulators_node = of_match_ptr("regulators"),
834 			.id = BD718XX_LDO4,
835 			.type = REGULATOR_VOLTAGE,
836 			.n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
837 			.linear_ranges = bd718xx_ldo4_volts,
838 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
839 			.vsel_reg = BD718XX_REG_LDO4_VOLT,
840 			.vsel_mask = BD718XX_LDO4_MASK,
841 			.enable_reg = BD718XX_REG_LDO4_VOLT,
842 			.enable_mask = BD718XX_LDO_EN,
843 			.owner = THIS_MODULE,
844 		},
845 		.init = {
846 			.reg = BD718XX_REG_LDO4_VOLT,
847 			.mask = BD718XX_LDO_SEL,
848 			.val = BD718XX_LDO_SEL,
849 		},
850 	},
851 	{
852 		.desc = {
853 			.name = "ldo5",
854 			.of_match = of_match_ptr("LDO5"),
855 			.regulators_node = of_match_ptr("regulators"),
856 			.id = BD718XX_LDO5,
857 			.type = REGULATOR_VOLTAGE,
858 			.n_voltages = BD71847_LDO5_VOLTAGE_NUM,
859 			.linear_ranges = bd71847_ldo5_volts,
860 			.n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
861 			.vsel_reg = BD718XX_REG_LDO5_VOLT,
862 			.vsel_mask = BD71847_LDO5_MASK,
863 			.vsel_range_reg = BD718XX_REG_LDO5_VOLT,
864 			.vsel_range_mask = BD71847_LDO5_RANGE_MASK,
865 			.linear_range_selectors = bd71847_ldo5_volt_range_sel,
866 			.enable_reg = BD718XX_REG_LDO5_VOLT,
867 			.enable_mask = BD718XX_LDO_EN,
868 			.owner = THIS_MODULE,
869 		},
870 		.init = {
871 			.reg = BD718XX_REG_LDO5_VOLT,
872 			.mask = BD718XX_LDO_SEL,
873 			.val = BD718XX_LDO_SEL,
874 		},
875 	},
876 	{
877 		.desc = {
878 			.name = "ldo6",
879 			.of_match = of_match_ptr("LDO6"),
880 			.regulators_node = of_match_ptr("regulators"),
881 			.id = BD718XX_LDO6,
882 			.type = REGULATOR_VOLTAGE,
883 			.n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
884 			.linear_ranges = bd718xx_ldo6_volts,
885 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
886 			/* LDO6 is supplied by buck5 */
887 			.supply_name = "buck5",
888 			.vsel_reg = BD718XX_REG_LDO6_VOLT,
889 			.vsel_mask = BD718XX_LDO6_MASK,
890 			.enable_reg = BD718XX_REG_LDO6_VOLT,
891 			.enable_mask = BD718XX_LDO_EN,
892 			.owner = THIS_MODULE,
893 		},
894 		.init = {
895 			.reg = BD718XX_REG_LDO6_VOLT,
896 			.mask = BD718XX_LDO_SEL,
897 			.val = BD718XX_LDO_SEL,
898 		},
899 	},
900 };
901 
902 static const struct regulator_ops *bd71837_swcontrol_ops[] = {
903 	&bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
904 	&bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
905 	&bd71837_pickable_range_buck_ops, &bd71837_buck_regulator_ops,
906 	&bd71837_buck_regulator_nolinear_ops, &bd71837_buck_regulator_ops,
907 	&bd71837_pickable_range_ldo_ops, &bd71837_ldo_regulator_nolinear_ops,
908 	&bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
909 	&bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
910 	&bd71837_ldo_regulator_ops,
911 };
912 
913 static const struct regulator_ops *bd71837_hwcontrol_ops[] = {
914 	&BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
915 	&BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
916 	&bd71837_buck34_ops_hwctrl, &bd71837_buck34_ops_hwctrl,
917 	&BD718XX_HWOPNAME(bd71837_pickable_range_buck_ops),
918 	&BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
919 	&BD718XX_HWOPNAME(bd71837_buck_regulator_nolinear_ops),
920 	&BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
921 	&BD718XX_HWOPNAME(bd71837_pickable_range_ldo_ops),
922 	&BD718XX_HWOPNAME(bd71837_ldo_regulator_nolinear_ops),
923 	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
924 	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
925 	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
926 	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
927 	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
928 };
929 
930 static struct bd718xx_regulator_data bd71837_regulators[] = {
931 	{
932 		.desc = {
933 			.name = "buck1",
934 			.of_match = of_match_ptr("BUCK1"),
935 			.regulators_node = of_match_ptr("regulators"),
936 			.id = BD718XX_BUCK1,
937 			.type = REGULATOR_VOLTAGE,
938 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
939 			.linear_ranges = bd718xx_dvs_buck_volts,
940 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
941 			.vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
942 			.vsel_mask = DVS_BUCK_RUN_MASK,
943 			.enable_reg = BD718XX_REG_BUCK1_CTRL,
944 			.enable_mask = BD718XX_BUCK_EN,
945 			.owner = THIS_MODULE,
946 			.of_parse_cb = buck_set_hw_dvs_levels,
947 		},
948 		.dvs = {
949 			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
950 				     ROHM_DVS_LEVEL_SUSPEND,
951 			.run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
952 			.run_mask = DVS_BUCK_RUN_MASK,
953 			.idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
954 			.idle_mask = DVS_BUCK_RUN_MASK,
955 			.suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
956 			.suspend_mask = DVS_BUCK_RUN_MASK,
957 		},
958 		.init = {
959 			.reg = BD718XX_REG_BUCK1_CTRL,
960 			.mask = BD718XX_BUCK_SEL,
961 			.val = BD718XX_BUCK_SEL,
962 		},
963 	},
964 	{
965 		.desc = {
966 			.name = "buck2",
967 			.of_match = of_match_ptr("BUCK2"),
968 			.regulators_node = of_match_ptr("regulators"),
969 			.id = BD718XX_BUCK2,
970 			.type = REGULATOR_VOLTAGE,
971 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
972 			.linear_ranges = bd718xx_dvs_buck_volts,
973 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
974 			.vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
975 			.vsel_mask = DVS_BUCK_RUN_MASK,
976 			.enable_reg = BD718XX_REG_BUCK2_CTRL,
977 			.enable_mask = BD718XX_BUCK_EN,
978 			.owner = THIS_MODULE,
979 			.of_parse_cb = buck_set_hw_dvs_levels,
980 		},
981 		.dvs = {
982 			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
983 			.run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
984 			.run_mask = DVS_BUCK_RUN_MASK,
985 			.idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
986 			.idle_mask = DVS_BUCK_RUN_MASK,
987 		},
988 		.init = {
989 			.reg = BD718XX_REG_BUCK2_CTRL,
990 			.mask = BD718XX_BUCK_SEL,
991 			.val = BD718XX_BUCK_SEL,
992 		},
993 	},
994 	{
995 		.desc = {
996 			.name = "buck3",
997 			.of_match = of_match_ptr("BUCK3"),
998 			.regulators_node = of_match_ptr("regulators"),
999 			.id = BD718XX_BUCK3,
1000 			.type = REGULATOR_VOLTAGE,
1001 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1002 			.linear_ranges = bd718xx_dvs_buck_volts,
1003 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1004 			.vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
1005 			.vsel_mask = DVS_BUCK_RUN_MASK,
1006 			.enable_reg = BD71837_REG_BUCK3_CTRL,
1007 			.enable_mask = BD718XX_BUCK_EN,
1008 			.owner = THIS_MODULE,
1009 			.of_parse_cb = buck_set_hw_dvs_levels,
1010 		},
1011 		.dvs = {
1012 			.level_map = ROHM_DVS_LEVEL_RUN,
1013 			.run_reg = BD71837_REG_BUCK3_VOLT_RUN,
1014 			.run_mask = DVS_BUCK_RUN_MASK,
1015 		},
1016 		.init = {
1017 			.reg = BD71837_REG_BUCK3_CTRL,
1018 			.mask = BD718XX_BUCK_SEL,
1019 			.val = BD718XX_BUCK_SEL,
1020 		},
1021 	},
1022 	{
1023 		.desc = {
1024 			.name = "buck4",
1025 			.of_match = of_match_ptr("BUCK4"),
1026 			.regulators_node = of_match_ptr("regulators"),
1027 			.id = BD718XX_BUCK4,
1028 			.type = REGULATOR_VOLTAGE,
1029 			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1030 			.linear_ranges = bd718xx_dvs_buck_volts,
1031 			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1032 			.vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
1033 			.vsel_mask = DVS_BUCK_RUN_MASK,
1034 			.enable_reg = BD71837_REG_BUCK4_CTRL,
1035 			.enable_mask = BD718XX_BUCK_EN,
1036 			.owner = THIS_MODULE,
1037 			.of_parse_cb = buck_set_hw_dvs_levels,
1038 		},
1039 		.dvs = {
1040 			.level_map = ROHM_DVS_LEVEL_RUN,
1041 			.run_reg = BD71837_REG_BUCK4_VOLT_RUN,
1042 			.run_mask = DVS_BUCK_RUN_MASK,
1043 		},
1044 		.init = {
1045 			.reg = BD71837_REG_BUCK4_CTRL,
1046 			.mask = BD718XX_BUCK_SEL,
1047 			.val = BD718XX_BUCK_SEL,
1048 		},
1049 	},
1050 	{
1051 		.desc = {
1052 			.name = "buck5",
1053 			.of_match = of_match_ptr("BUCK5"),
1054 			.regulators_node = of_match_ptr("regulators"),
1055 			.id = BD718XX_BUCK5,
1056 			.type = REGULATOR_VOLTAGE,
1057 			.n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
1058 			.linear_ranges = bd71837_buck5_volts,
1059 			.n_linear_ranges =
1060 				ARRAY_SIZE(bd71837_buck5_volts),
1061 			.vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
1062 			.vsel_mask = BD71837_BUCK5_MASK,
1063 			.vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
1064 			.vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
1065 			.linear_range_selectors = bd71837_buck5_volt_range_sel,
1066 			.enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1067 			.enable_mask = BD718XX_BUCK_EN,
1068 			.owner = THIS_MODULE,
1069 		},
1070 		.init = {
1071 			.reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1072 			.mask = BD718XX_BUCK_SEL,
1073 			.val = BD718XX_BUCK_SEL,
1074 		},
1075 	},
1076 	{
1077 		.desc = {
1078 			.name = "buck6",
1079 			.of_match = of_match_ptr("BUCK6"),
1080 			.regulators_node = of_match_ptr("regulators"),
1081 			.id = BD718XX_BUCK6,
1082 			.type = REGULATOR_VOLTAGE,
1083 			.n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
1084 			.linear_ranges = bd71837_buck6_volts,
1085 			.n_linear_ranges =
1086 				ARRAY_SIZE(bd71837_buck6_volts),
1087 			.vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
1088 			.vsel_mask = BD71837_BUCK6_MASK,
1089 			.enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1090 			.enable_mask = BD718XX_BUCK_EN,
1091 			.owner = THIS_MODULE,
1092 		},
1093 		.init = {
1094 			.reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1095 			.mask = BD718XX_BUCK_SEL,
1096 			.val = BD718XX_BUCK_SEL,
1097 		},
1098 	},
1099 	{
1100 		.desc = {
1101 			.name = "buck7",
1102 			.of_match = of_match_ptr("BUCK7"),
1103 			.regulators_node = of_match_ptr("regulators"),
1104 			.id = BD718XX_BUCK7,
1105 			.type = REGULATOR_VOLTAGE,
1106 			.volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
1107 			.n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
1108 			.vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
1109 			.vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
1110 			.enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1111 			.enable_mask = BD718XX_BUCK_EN,
1112 			.owner = THIS_MODULE,
1113 		},
1114 		.init = {
1115 			.reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1116 			.mask = BD718XX_BUCK_SEL,
1117 			.val = BD718XX_BUCK_SEL,
1118 		},
1119 	},
1120 	{
1121 		.desc = {
1122 			.name = "buck8",
1123 			.of_match = of_match_ptr("BUCK8"),
1124 			.regulators_node = of_match_ptr("regulators"),
1125 			.id = BD718XX_BUCK8,
1126 			.type = REGULATOR_VOLTAGE,
1127 			.n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
1128 			.linear_ranges = bd718xx_4th_nodvs_buck_volts,
1129 			.n_linear_ranges =
1130 				ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
1131 			.vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
1132 			.vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
1133 			.enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1134 			.enable_mask = BD718XX_BUCK_EN,
1135 			.owner = THIS_MODULE,
1136 		},
1137 		.init = {
1138 			.reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1139 			.mask = BD718XX_BUCK_SEL,
1140 			.val = BD718XX_BUCK_SEL,
1141 		},
1142 	},
1143 	{
1144 		.desc = {
1145 			.name = "ldo1",
1146 			.of_match = of_match_ptr("LDO1"),
1147 			.regulators_node = of_match_ptr("regulators"),
1148 			.id = BD718XX_LDO1,
1149 			.type = REGULATOR_VOLTAGE,
1150 			.n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
1151 			.linear_ranges = bd718xx_ldo1_volts,
1152 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
1153 			.vsel_reg = BD718XX_REG_LDO1_VOLT,
1154 			.vsel_mask = BD718XX_LDO1_MASK,
1155 			.vsel_range_reg = BD718XX_REG_LDO1_VOLT,
1156 			.vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
1157 			.linear_range_selectors = bd718xx_ldo1_volt_range_sel,
1158 			.enable_reg = BD718XX_REG_LDO1_VOLT,
1159 			.enable_mask = BD718XX_LDO_EN,
1160 			.owner = THIS_MODULE,
1161 		},
1162 		.init = {
1163 			.reg = BD718XX_REG_LDO1_VOLT,
1164 			.mask = BD718XX_LDO_SEL,
1165 			.val = BD718XX_LDO_SEL,
1166 		},
1167 	},
1168 	{
1169 		.desc = {
1170 			.name = "ldo2",
1171 			.of_match = of_match_ptr("LDO2"),
1172 			.regulators_node = of_match_ptr("regulators"),
1173 			.id = BD718XX_LDO2,
1174 			.type = REGULATOR_VOLTAGE,
1175 			.volt_table = &ldo_2_volts[0],
1176 			.vsel_reg = BD718XX_REG_LDO2_VOLT,
1177 			.vsel_mask = BD718XX_LDO2_MASK,
1178 			.n_voltages = ARRAY_SIZE(ldo_2_volts),
1179 			.enable_reg = BD718XX_REG_LDO2_VOLT,
1180 			.enable_mask = BD718XX_LDO_EN,
1181 			.owner = THIS_MODULE,
1182 		},
1183 		.init = {
1184 			.reg = BD718XX_REG_LDO2_VOLT,
1185 			.mask = BD718XX_LDO_SEL,
1186 			.val = BD718XX_LDO_SEL,
1187 		},
1188 	},
1189 	{
1190 		.desc = {
1191 			.name = "ldo3",
1192 			.of_match = of_match_ptr("LDO3"),
1193 			.regulators_node = of_match_ptr("regulators"),
1194 			.id = BD718XX_LDO3,
1195 			.type = REGULATOR_VOLTAGE,
1196 			.n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
1197 			.linear_ranges = bd718xx_ldo3_volts,
1198 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
1199 			.vsel_reg = BD718XX_REG_LDO3_VOLT,
1200 			.vsel_mask = BD718XX_LDO3_MASK,
1201 			.enable_reg = BD718XX_REG_LDO3_VOLT,
1202 			.enable_mask = BD718XX_LDO_EN,
1203 			.owner = THIS_MODULE,
1204 		},
1205 		.init = {
1206 			.reg = BD718XX_REG_LDO3_VOLT,
1207 			.mask = BD718XX_LDO_SEL,
1208 			.val = BD718XX_LDO_SEL,
1209 		},
1210 	},
1211 	{
1212 		.desc = {
1213 			.name = "ldo4",
1214 			.of_match = of_match_ptr("LDO4"),
1215 			.regulators_node = of_match_ptr("regulators"),
1216 			.id = BD718XX_LDO4,
1217 			.type = REGULATOR_VOLTAGE,
1218 			.n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
1219 			.linear_ranges = bd718xx_ldo4_volts,
1220 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
1221 			.vsel_reg = BD718XX_REG_LDO4_VOLT,
1222 			.vsel_mask = BD718XX_LDO4_MASK,
1223 			.enable_reg = BD718XX_REG_LDO4_VOLT,
1224 			.enable_mask = BD718XX_LDO_EN,
1225 			.owner = THIS_MODULE,
1226 		},
1227 		.init = {
1228 			.reg = BD718XX_REG_LDO4_VOLT,
1229 			.mask = BD718XX_LDO_SEL,
1230 			.val = BD718XX_LDO_SEL,
1231 		},
1232 	},
1233 	{
1234 		.desc = {
1235 			.name = "ldo5",
1236 			.of_match = of_match_ptr("LDO5"),
1237 			.regulators_node = of_match_ptr("regulators"),
1238 			.id = BD718XX_LDO5,
1239 			.type = REGULATOR_VOLTAGE,
1240 			.n_voltages = BD71837_LDO5_VOLTAGE_NUM,
1241 			.linear_ranges = bd71837_ldo5_volts,
1242 			.n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
1243 			/* LDO5 is supplied by buck6 */
1244 			.supply_name = "buck6",
1245 			.vsel_reg = BD718XX_REG_LDO5_VOLT,
1246 			.vsel_mask = BD71837_LDO5_MASK,
1247 			.enable_reg = BD718XX_REG_LDO5_VOLT,
1248 			.enable_mask = BD718XX_LDO_EN,
1249 			.owner = THIS_MODULE,
1250 		},
1251 		.init = {
1252 			.reg = BD718XX_REG_LDO5_VOLT,
1253 			.mask = BD718XX_LDO_SEL,
1254 			.val = BD718XX_LDO_SEL,
1255 		},
1256 		.additional_inits = bd71837_ldo5_inits,
1257 		.additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
1258 	},
1259 	{
1260 		.desc = {
1261 			.name = "ldo6",
1262 			.of_match = of_match_ptr("LDO6"),
1263 			.regulators_node = of_match_ptr("regulators"),
1264 			.id = BD718XX_LDO6,
1265 			.type = REGULATOR_VOLTAGE,
1266 			.n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
1267 			.linear_ranges = bd718xx_ldo6_volts,
1268 			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
1269 			/* LDO6 is supplied by buck7 */
1270 			.supply_name = "buck7",
1271 			.vsel_reg = BD718XX_REG_LDO6_VOLT,
1272 			.vsel_mask = BD718XX_LDO6_MASK,
1273 			.enable_reg = BD718XX_REG_LDO6_VOLT,
1274 			.enable_mask = BD718XX_LDO_EN,
1275 			.owner = THIS_MODULE,
1276 		},
1277 		.init = {
1278 			.reg = BD718XX_REG_LDO6_VOLT,
1279 			.mask = BD718XX_LDO_SEL,
1280 			.val = BD718XX_LDO_SEL,
1281 		},
1282 		.additional_inits = bd71837_ldo6_inits,
1283 		.additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
1284 	},
1285 	{
1286 		.desc = {
1287 			.name = "ldo7",
1288 			.of_match = of_match_ptr("LDO7"),
1289 			.regulators_node = of_match_ptr("regulators"),
1290 			.id = BD718XX_LDO7,
1291 			.type = REGULATOR_VOLTAGE,
1292 			.n_voltages = BD71837_LDO7_VOLTAGE_NUM,
1293 			.linear_ranges = bd71837_ldo7_volts,
1294 			.n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
1295 			.vsel_reg = BD71837_REG_LDO7_VOLT,
1296 			.vsel_mask = BD71837_LDO7_MASK,
1297 			.enable_reg = BD71837_REG_LDO7_VOLT,
1298 			.enable_mask = BD718XX_LDO_EN,
1299 			.owner = THIS_MODULE,
1300 		},
1301 		.init = {
1302 			.reg = BD71837_REG_LDO7_VOLT,
1303 			.mask = BD718XX_LDO_SEL,
1304 			.val = BD718XX_LDO_SEL,
1305 		},
1306 	},
1307 };
1308 
1309 static void mark_hw_controlled(struct device *dev, struct device_node *np,
1310 			       struct bd718xx_regulator_data *reg_data,
1311 			       unsigned int num_reg_data, int *info)
1312 {
1313 	int i;
1314 
1315 	for (i = 1; i <= num_reg_data; i++) {
1316 		if (!of_node_name_eq(np, reg_data[i-1].desc.of_match))
1317 			continue;
1318 
1319 		*info |= 1 << (i - 1);
1320 		dev_dbg(dev, "regulator %d runlevel controlled\n", i);
1321 		return;
1322 	}
1323 	dev_warn(dev, "Bad regulator node\n");
1324 }
1325 
1326 /*
1327  * Setups where regulator (especially the buck8) output voltage is scaled
1328  * by adding external connection where some other regulator output is connected
1329  * to feedback-pin (over suitable resistors) is getting popular amongst users
1330  * of BD71837. (This allows for example scaling down the buck8 voltages to suit
1331  * lover GPU voltages for projects where buck8 is (ab)used to supply power
1332  * for GPU. Additionally some setups do allow DVS for buck8 but as this do
1333  * produce voltage spikes the HW must be evaluated to be able to survive this
1334  * - hence I keep the DVS disabled for non DVS bucks by default. I don't want
1335  * to help you burn your proto board)
1336  *
1337  * So we allow describing this external connection from DT and scale the
1338  * voltages accordingly. This is what the connection should look like:
1339  *
1340  * |------------|
1341  * |	buck 8  |-------+----->Vout
1342  * |		|	|
1343  * |------------|	|
1344  *	| FB pin	|
1345  *	|		|
1346  *	+-------+--R2---+
1347  *		|
1348  *		R1
1349  *		|
1350  *	V FB-pull-up
1351  *
1352  *	Here the buck output is sifted according to formula:
1353  *
1354  * Vout_o = Vo - (Vpu - Vo)*R2/R1
1355  * Linear_step = step_orig*(R1+R2)/R1
1356  *
1357  * where:
1358  * Vout_o is adjusted voltage output at vsel reg value 0
1359  * Vo is original voltage output at vsel reg value 0
1360  * Vpu is the pull-up voltage V FB-pull-up in the picture
1361  * R1 and R2 are resistor values.
1362  *
1363  * As a real world example for buck8 and a specific GPU:
1364  * VLDO = 1.6V (used as FB-pull-up)
1365  * R1 = 1000ohms
1366  * R2 = 150ohms
1367  * VSEL 0x0 => 0.8V – (VLDO – 0.8) * R2 / R1 = 0.68V
1368  * Linear Step = 10mV * (R1 + R2) / R1 = 11.5mV
1369  */
1370 static int setup_feedback_loop(struct device *dev, struct device_node *np,
1371 			       struct bd718xx_regulator_data *reg_data,
1372 			       unsigned int num_reg_data, int fb_uv)
1373 {
1374 	int i, r1, r2, ret;
1375 
1376 	/*
1377 	 * We do adjust the values in the global desc based on DT settings.
1378 	 * This may not be best approach as it can cause problems if more than
1379 	 * one PMIC is controlled from same processor. I don't see such use-case
1380 	 * for BD718x7 now - so we spare some bits.
1381 	 *
1382 	 * If this will point out to be a problem - then we can allocate new
1383 	 * bd718xx_regulator_data array at probe and just use the global
1384 	 * array as a template where we copy initial values. Then we can
1385 	 * use allocated descs for regultor registration and do IC specific
1386 	 * modifications to this copy while leaving other PMICs untouched. But
1387 	 * that means allocating new array for each PMIC - and currently I see
1388 	 * no need for that.
1389 	 */
1390 
1391 	for (i = 0; i < num_reg_data; i++) {
1392 		struct regulator_desc *desc = &reg_data[i].desc;
1393 		int j;
1394 
1395 		if (!of_node_name_eq(np, desc->of_match))
1396 			continue;
1397 
1398 		pr_info("Looking at node '%s'\n", desc->of_match);
1399 
1400 		/* The feedback loop connection does not make sense for LDOs */
1401 		if (desc->id >= BD718XX_LDO1)
1402 			return -EINVAL;
1403 
1404 		ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms",
1405 					   &r1);
1406 		if (ret)
1407 			return ret;
1408 
1409 		if (!r1)
1410 			return -EINVAL;
1411 
1412 		ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms",
1413 					   &r2);
1414 		if (ret)
1415 			return ret;
1416 
1417 		if (desc->n_linear_ranges && desc->linear_ranges) {
1418 			struct linear_range *new;
1419 
1420 			new = devm_kzalloc(dev, desc->n_linear_ranges *
1421 					   sizeof(struct linear_range),
1422 					   GFP_KERNEL);
1423 			if (!new)
1424 				return -ENOMEM;
1425 
1426 			for (j = 0; j < desc->n_linear_ranges; j++) {
1427 				int min = desc->linear_ranges[j].min;
1428 				int step = desc->linear_ranges[j].step;
1429 
1430 				min -= (fb_uv - min)*r2/r1;
1431 				step = step * (r1 + r2);
1432 				step /= r1;
1433 
1434 				new[j].min = min;
1435 				new[j].step = step;
1436 
1437 				dev_dbg(dev, "%s: old range min %d, step %d\n",
1438 					desc->name, desc->linear_ranges[j].min,
1439 					desc->linear_ranges[j].step);
1440 				dev_dbg(dev, "new range min %d, step %d\n", min,
1441 					step);
1442 			}
1443 			desc->linear_ranges = new;
1444 		}
1445 		dev_dbg(dev, "regulator '%s' has FB pull-up configured\n",
1446 			desc->name);
1447 
1448 		return 0;
1449 	}
1450 
1451 	return -ENODEV;
1452 }
1453 
1454 static int get_special_regulators(struct device *dev,
1455 				  struct bd718xx_regulator_data *reg_data,
1456 				  unsigned int num_reg_data, int *info)
1457 {
1458 	int ret;
1459 	struct device_node *np;
1460 	struct device_node *nproot = dev->of_node;
1461 	int uv;
1462 
1463 	*info = 0;
1464 
1465 	nproot = of_get_child_by_name(nproot, "regulators");
1466 	if (!nproot) {
1467 		dev_err(dev, "failed to find regulators node\n");
1468 		return -ENODEV;
1469 	}
1470 	for_each_child_of_node(nproot, np) {
1471 		if (of_property_read_bool(np, "rohm,no-regulator-enable-control"))
1472 			mark_hw_controlled(dev, np, reg_data, num_reg_data,
1473 					   info);
1474 		ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt",
1475 					   &uv);
1476 		if (ret) {
1477 			if (ret == -EINVAL)
1478 				continue;
1479 			else
1480 				goto err_out;
1481 		}
1482 
1483 		ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv);
1484 		if (ret)
1485 			goto err_out;
1486 	}
1487 
1488 	of_node_put(nproot);
1489 	return 0;
1490 
1491 err_out:
1492 	of_node_put(np);
1493 	of_node_put(nproot);
1494 
1495 	return ret;
1496 }
1497 
1498 static int bd718xx_probe(struct platform_device *pdev)
1499 {
1500 	struct bd718xx *mfd;
1501 	struct regulator_config config = { 0 };
1502 	int i, j, err, omit_enable;
1503 	bool use_snvs;
1504 	struct bd718xx_regulator_data *reg_data;
1505 	unsigned int num_reg_data;
1506 	enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
1507 	const struct regulator_ops **swops, **hwops;
1508 
1509 	mfd = dev_get_drvdata(pdev->dev.parent);
1510 	if (!mfd) {
1511 		dev_err(&pdev->dev, "No MFD driver data\n");
1512 		err = -EINVAL;
1513 		goto err;
1514 	}
1515 
1516 	switch (chip) {
1517 	case ROHM_CHIP_TYPE_BD71837:
1518 		reg_data = bd71837_regulators;
1519 		num_reg_data = ARRAY_SIZE(bd71837_regulators);
1520 		swops = &bd71837_swcontrol_ops[0];
1521 		hwops = &bd71837_hwcontrol_ops[0];
1522 		break;
1523 	case ROHM_CHIP_TYPE_BD71847:
1524 		reg_data = bd71847_regulators;
1525 		num_reg_data = ARRAY_SIZE(bd71847_regulators);
1526 		swops = &bd71847_swcontrol_ops[0];
1527 		hwops = &bd71847_hwcontrol_ops[0];
1528 		break;
1529 	default:
1530 		dev_err(&pdev->dev, "Unsupported chip type\n");
1531 		err = -EINVAL;
1532 		goto err;
1533 	}
1534 
1535 	/* Register LOCK release */
1536 	err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_REGLOCK,
1537 				 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1538 	if (err) {
1539 		dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
1540 		goto err;
1541 	} else {
1542 		dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
1543 			BD718XX_REG_REGLOCK);
1544 	}
1545 
1546 	use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
1547 					 "rohm,reset-snvs-powered");
1548 
1549 	/*
1550 	 * Change the next stage from poweroff to be READY instead of SNVS
1551 	 * for all reset types because OTP loading at READY will clear SEL
1552 	 * bit allowing HW defaults for power rails to be used
1553 	 */
1554 	if (!use_snvs) {
1555 		err = regmap_update_bits(mfd->chip.regmap,
1556 					 BD718XX_REG_TRANS_COND1,
1557 					 BD718XX_ON_REQ_POWEROFF_MASK |
1558 					 BD718XX_SWRESET_POWEROFF_MASK |
1559 					 BD718XX_WDOG_POWEROFF_MASK |
1560 					 BD718XX_KEY_L_POWEROFF_MASK,
1561 					 BD718XX_POWOFF_TO_RDY);
1562 		if (err) {
1563 			dev_err(&pdev->dev, "Failed to change reset target\n");
1564 			goto err;
1565 		} else {
1566 			dev_dbg(&pdev->dev,
1567 				"Changed all resets from SVNS to READY\n");
1568 		}
1569 	}
1570 
1571 	config.dev = pdev->dev.parent;
1572 	config.regmap = mfd->chip.regmap;
1573 	/*
1574 	 * There are cases when we want to leave the enable-control for
1575 	 * the HW state machine and use this driver only for voltage control.
1576 	 * One special case is when we use PMIC_STBY_REQ line from SoC to PMIC
1577 	 * in order to set the system to SUSPEND state.
1578 	 *
1579 	 * If regulator is taken under SW control the regulator state will not
1580 	 * be affected by PMIC state machine - Eg. regulator is likely to stay
1581 	 * on even in SUSPEND
1582 	 */
1583 	err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data,
1584 				     &omit_enable);
1585 	if (err)
1586 		return err;
1587 
1588 	for (i = 0; i < num_reg_data; i++) {
1589 
1590 		struct regulator_desc *desc;
1591 		struct regulator_dev *rdev;
1592 		struct bd718xx_regulator_data *r;
1593 		int no_enable_control = omit_enable & (1 << i);
1594 
1595 		r = &reg_data[i];
1596 		desc = &r->desc;
1597 
1598 		if (no_enable_control)
1599 			desc->ops = hwops[i];
1600 		else
1601 			desc->ops = swops[i];
1602 
1603 		rdev = devm_regulator_register(&pdev->dev, desc, &config);
1604 		if (IS_ERR(rdev)) {
1605 			dev_err(&pdev->dev,
1606 				"failed to register %s regulator\n",
1607 				desc->name);
1608 			err = PTR_ERR(rdev);
1609 			goto err;
1610 		}
1611 
1612 		/*
1613 		 * Regulator register gets the regulator constraints and
1614 		 * applies them (set_machine_constraints). This should have
1615 		 * turned the control register(s) to correct values and we
1616 		 * can now switch the control from PMIC state machine to the
1617 		 * register interface
1618 		 *
1619 		 * At poweroff transition PMIC HW disables EN bit for
1620 		 * regulators but leaves SEL bit untouched. So if state
1621 		 * transition from POWEROFF is done to SNVS - then all power
1622 		 * rails controlled by SW (having SEL bit set) stay disabled
1623 		 * as EN is cleared. This will result boot failure if any
1624 		 * crucial systems are powered by these rails. We don't
1625 		 * enable SW control for crucial regulators if snvs state is
1626 		 * used
1627 		 */
1628 		if (!no_enable_control && (!use_snvs ||
1629 		    !rdev->constraints->always_on ||
1630 		    !rdev->constraints->boot_on)) {
1631 			err = regmap_update_bits(mfd->chip.regmap, r->init.reg,
1632 						 r->init.mask, r->init.val);
1633 			if (err) {
1634 				dev_err(&pdev->dev,
1635 					"Failed to take control for (%s)\n",
1636 					desc->name);
1637 				goto err;
1638 			}
1639 		}
1640 		for (j = 0; j < r->additional_init_amnt; j++) {
1641 			err = regmap_update_bits(mfd->chip.regmap,
1642 						 r->additional_inits[j].reg,
1643 						 r->additional_inits[j].mask,
1644 						 r->additional_inits[j].val);
1645 			if (err) {
1646 				dev_err(&pdev->dev,
1647 					"Buck (%s) initialization failed\n",
1648 					desc->name);
1649 				goto err;
1650 			}
1651 		}
1652 	}
1653 
1654 err:
1655 	return err;
1656 }
1657 
1658 static const struct platform_device_id bd718x7_pmic_id[] = {
1659 	{ "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
1660 	{ "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
1661 	{ },
1662 };
1663 MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id);
1664 
1665 static struct platform_driver bd718xx_regulator = {
1666 	.driver = {
1667 		.name = "bd718xx-pmic",
1668 	},
1669 	.probe = bd718xx_probe,
1670 	.id_table = bd718x7_pmic_id,
1671 };
1672 
1673 module_platform_driver(bd718xx_regulator);
1674 
1675 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
1676 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1677 MODULE_LICENSE("GPL");
1678 MODULE_ALIAS("platform:bd718xx-pmic");
1679