xref: /linux/drivers/regulator/s2mps11.c (revision 169cd52fd9445b30379ea6deafa28a260d489699)
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
4 //              http://www.samsung.com
5 
6 #include <linux/bug.h>
7 #include <linux/cleanup.h>
8 #include <linux/err.h>
9 #include <linux/gpio/consumer.h>
10 #include <linux/slab.h>
11 #include <linux/module.h>
12 #include <linux/of.h>
13 #include <linux/regmap.h>
14 #include <linux/platform_device.h>
15 #include <linux/regulator/driver.h>
16 #include <linux/regulator/machine.h>
17 #include <linux/regulator/of_regulator.h>
18 #include <linux/mfd/samsung/core.h>
19 #include <linux/mfd/samsung/s2mps11.h>
20 #include <linux/mfd/samsung/s2mps13.h>
21 #include <linux/mfd/samsung/s2mps14.h>
22 #include <linux/mfd/samsung/s2mps15.h>
23 #include <linux/mfd/samsung/s2mpu02.h>
24 #include <linux/mfd/samsung/s2mpu05.h>
25 
26 /* The highest number of possible regulators for supported devices. */
27 #define S2MPS_REGULATOR_MAX		S2MPS13_REGULATOR_MAX
28 struct s2mps11_info {
29 	int ramp_delay2;
30 	int ramp_delay34;
31 	int ramp_delay5;
32 	int ramp_delay16;
33 	int ramp_delay7810;
34 	int ramp_delay9;
35 
36 	enum sec_device_type dev_type;
37 
38 	/*
39 	 * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
40 	 * the suspend mode was enabled.
41 	 */
42 	DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
43 
44 	/*
45 	 * Array (size: number of regulators) with GPIO-s for external
46 	 * sleep control.
47 	 */
48 	struct gpio_desc **ext_control_gpiod;
49 };
50 
51 static int get_ramp_delay(int ramp_delay)
52 {
53 	unsigned char cnt = 0;
54 
55 	ramp_delay /= 6250;
56 
57 	while (true) {
58 		ramp_delay = ramp_delay >> 1;
59 		if (ramp_delay == 0)
60 			break;
61 		cnt++;
62 	}
63 
64 	if (cnt > 3)
65 		cnt = 3;
66 
67 	return cnt;
68 }
69 
70 static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
71 				   unsigned int old_selector,
72 				   unsigned int new_selector)
73 {
74 	struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
75 	int rdev_id = rdev_get_id(rdev);
76 	unsigned int ramp_delay = 0;
77 	int old_volt, new_volt;
78 
79 	switch (rdev_id) {
80 	case S2MPS11_BUCK2:
81 		ramp_delay = s2mps11->ramp_delay2;
82 		break;
83 	case S2MPS11_BUCK3:
84 	case S2MPS11_BUCK4:
85 		ramp_delay = s2mps11->ramp_delay34;
86 		break;
87 	case S2MPS11_BUCK5:
88 		ramp_delay = s2mps11->ramp_delay5;
89 		break;
90 	case S2MPS11_BUCK6:
91 	case S2MPS11_BUCK1:
92 		ramp_delay = s2mps11->ramp_delay16;
93 		break;
94 	case S2MPS11_BUCK7:
95 	case S2MPS11_BUCK8:
96 	case S2MPS11_BUCK10:
97 		ramp_delay = s2mps11->ramp_delay7810;
98 		break;
99 	case S2MPS11_BUCK9:
100 		ramp_delay = s2mps11->ramp_delay9;
101 	}
102 
103 	if (ramp_delay == 0)
104 		ramp_delay = rdev->desc->ramp_delay;
105 
106 	old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
107 	new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
108 
109 	return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
110 }
111 
112 static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
113 {
114 	struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
115 	unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
116 	unsigned int ramp_enable = 1, enable_shift = 0;
117 	int rdev_id = rdev_get_id(rdev);
118 	int ret;
119 
120 	switch (rdev_id) {
121 	case S2MPS11_BUCK1:
122 		if (ramp_delay > s2mps11->ramp_delay16)
123 			s2mps11->ramp_delay16 = ramp_delay;
124 		else
125 			ramp_delay = s2mps11->ramp_delay16;
126 
127 		ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
128 		break;
129 	case S2MPS11_BUCK2:
130 		enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
131 		if (!ramp_delay) {
132 			ramp_enable = 0;
133 			break;
134 		}
135 
136 		s2mps11->ramp_delay2 = ramp_delay;
137 		ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
138 		ramp_reg = S2MPS11_REG_RAMP;
139 		break;
140 	case S2MPS11_BUCK3:
141 		enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
142 		if (!ramp_delay) {
143 			ramp_enable = 0;
144 			break;
145 		}
146 
147 		if (ramp_delay > s2mps11->ramp_delay34)
148 			s2mps11->ramp_delay34 = ramp_delay;
149 		else
150 			ramp_delay = s2mps11->ramp_delay34;
151 
152 		ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
153 		ramp_reg = S2MPS11_REG_RAMP;
154 		break;
155 	case S2MPS11_BUCK4:
156 		enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
157 		if (!ramp_delay) {
158 			ramp_enable = 0;
159 			break;
160 		}
161 
162 		if (ramp_delay > s2mps11->ramp_delay34)
163 			s2mps11->ramp_delay34 = ramp_delay;
164 		else
165 			ramp_delay = s2mps11->ramp_delay34;
166 
167 		ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
168 		ramp_reg = S2MPS11_REG_RAMP;
169 		break;
170 	case S2MPS11_BUCK5:
171 		s2mps11->ramp_delay5 = ramp_delay;
172 		ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
173 		break;
174 	case S2MPS11_BUCK6:
175 		enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
176 		if (!ramp_delay) {
177 			ramp_enable = 0;
178 			break;
179 		}
180 
181 		if (ramp_delay > s2mps11->ramp_delay16)
182 			s2mps11->ramp_delay16 = ramp_delay;
183 		else
184 			ramp_delay = s2mps11->ramp_delay16;
185 
186 		ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
187 		break;
188 	case S2MPS11_BUCK7:
189 	case S2MPS11_BUCK8:
190 	case S2MPS11_BUCK10:
191 		if (ramp_delay > s2mps11->ramp_delay7810)
192 			s2mps11->ramp_delay7810 = ramp_delay;
193 		else
194 			ramp_delay = s2mps11->ramp_delay7810;
195 
196 		ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
197 		break;
198 	case S2MPS11_BUCK9:
199 		s2mps11->ramp_delay9 = ramp_delay;
200 		ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
201 		break;
202 	default:
203 		return 0;
204 	}
205 
206 	if (!ramp_enable)
207 		goto ramp_disable;
208 
209 	/* Ramp delay can be enabled/disabled only for buck[2346] */
210 	if ((rdev_id >= S2MPS11_BUCK2 && rdev_id <= S2MPS11_BUCK4) ||
211 	    rdev_id == S2MPS11_BUCK6)  {
212 		ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
213 					 1 << enable_shift, 1 << enable_shift);
214 		if (ret) {
215 			dev_err(&rdev->dev, "failed to enable ramp rate\n");
216 			return ret;
217 		}
218 	}
219 
220 	ramp_val = get_ramp_delay(ramp_delay);
221 
222 	return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
223 				  ramp_val << ramp_shift);
224 
225 ramp_disable:
226 	return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
227 				  1 << enable_shift, 0);
228 }
229 
230 static int s2mps11_regulator_enable(struct regulator_dev *rdev)
231 {
232 	struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
233 	int rdev_id = rdev_get_id(rdev);
234 	unsigned int val;
235 
236 	switch (s2mps11->dev_type) {
237 	case S2MPS11X:
238 		if (test_bit(rdev_id, s2mps11->suspend_state))
239 			val = S2MPS14_ENABLE_SUSPEND;
240 		else
241 			val = rdev->desc->enable_mask;
242 		break;
243 	case S2MPS13X:
244 	case S2MPS14X:
245 		if (test_bit(rdev_id, s2mps11->suspend_state))
246 			val = S2MPS14_ENABLE_SUSPEND;
247 		else if (s2mps11->ext_control_gpiod[rdev_id])
248 			val = S2MPS14_ENABLE_EXT_CONTROL;
249 		else
250 			val = rdev->desc->enable_mask;
251 		break;
252 	case S2MPU02:
253 		if (test_bit(rdev_id, s2mps11->suspend_state))
254 			val = S2MPU02_ENABLE_SUSPEND;
255 		else
256 			val = rdev->desc->enable_mask;
257 		break;
258 	case S2MPU05:
259 		val = rdev->desc->enable_mask;
260 		break;
261 	default:
262 		return -EINVAL;
263 	}
264 
265 	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
266 			rdev->desc->enable_mask, val);
267 }
268 
269 static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev)
270 {
271 	int ret;
272 	unsigned int val, state;
273 	struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
274 	int rdev_id = rdev_get_id(rdev);
275 
276 	/* Below LDO should be always on or does not support suspend mode. */
277 	switch (s2mps11->dev_type) {
278 	case S2MPS11X:
279 		switch (rdev_id) {
280 		case S2MPS11_LDO2:
281 		case S2MPS11_LDO36:
282 		case S2MPS11_LDO37:
283 		case S2MPS11_LDO38:
284 			return 0;
285 		default:
286 			state = S2MPS14_ENABLE_SUSPEND;
287 			break;
288 		}
289 		break;
290 	case S2MPS13X:
291 	case S2MPS14X:
292 		switch (rdev_id) {
293 		case S2MPS14_LDO3:
294 			return 0;
295 		default:
296 			state = S2MPS14_ENABLE_SUSPEND;
297 			break;
298 		}
299 		break;
300 	case S2MPU02:
301 		switch (rdev_id) {
302 		case S2MPU02_LDO13:
303 		case S2MPU02_LDO14:
304 		case S2MPU02_LDO15:
305 		case S2MPU02_LDO17:
306 		case S2MPU02_BUCK7:
307 			state = S2MPU02_DISABLE_SUSPEND;
308 			break;
309 		default:
310 			state = S2MPU02_ENABLE_SUSPEND;
311 			break;
312 		}
313 		break;
314 	default:
315 		return -EINVAL;
316 	}
317 
318 	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
319 	if (ret < 0)
320 		return ret;
321 
322 	set_bit(rdev_id, s2mps11->suspend_state);
323 	/*
324 	 * Don't enable suspend mode if regulator is already disabled because
325 	 * this would effectively for a short time turn on the regulator after
326 	 * resuming.
327 	 * However we still want to toggle the suspend_state bit for regulator
328 	 * in case if it got enabled before suspending the system.
329 	 */
330 	if (!(val & rdev->desc->enable_mask))
331 		return 0;
332 
333 	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
334 				  rdev->desc->enable_mask, state);
335 }
336 
337 static const struct regulator_ops s2mps11_ldo_ops = {
338 	.list_voltage		= regulator_list_voltage_linear,
339 	.map_voltage		= regulator_map_voltage_linear,
340 	.is_enabled		= regulator_is_enabled_regmap,
341 	.enable			= s2mps11_regulator_enable,
342 	.disable		= regulator_disable_regmap,
343 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
344 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
345 	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
346 	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
347 };
348 
349 static const struct regulator_ops s2mps11_buck_ops = {
350 	.list_voltage		= regulator_list_voltage_linear,
351 	.map_voltage		= regulator_map_voltage_linear,
352 	.is_enabled		= regulator_is_enabled_regmap,
353 	.enable			= s2mps11_regulator_enable,
354 	.disable		= regulator_disable_regmap,
355 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
356 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
357 	.set_voltage_time_sel	= s2mps11_regulator_set_voltage_time_sel,
358 	.set_ramp_delay		= s2mps11_set_ramp_delay,
359 	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
360 };
361 
362 #define regulator_desc_s2mps11_ldo(num, step) {		\
363 	.name		= "LDO"#num,			\
364 	.id		= S2MPS11_LDO##num,		\
365 	.ops		= &s2mps11_ldo_ops,		\
366 	.type		= REGULATOR_VOLTAGE,		\
367 	.owner		= THIS_MODULE,			\
368 	.ramp_delay	= RAMP_DELAY_12_MVUS,		\
369 	.min_uV		= MIN_800_MV,			\
370 	.uV_step	= step,				\
371 	.n_voltages	= S2MPS11_LDO_N_VOLTAGES,	\
372 	.vsel_reg	= S2MPS11_REG_L1CTRL + num - 1,	\
373 	.vsel_mask	= S2MPS11_LDO_VSEL_MASK,	\
374 	.enable_reg	= S2MPS11_REG_L1CTRL + num - 1,	\
375 	.enable_mask	= S2MPS11_ENABLE_MASK		\
376 }
377 
378 #define regulator_desc_s2mps11_buck1_4(num) {			\
379 	.name		= "BUCK"#num,				\
380 	.id		= S2MPS11_BUCK##num,			\
381 	.ops		= &s2mps11_buck_ops,			\
382 	.type		= REGULATOR_VOLTAGE,			\
383 	.owner		= THIS_MODULE,				\
384 	.min_uV		= MIN_650_MV,				\
385 	.uV_step	= STEP_6_25_MV,				\
386 	.linear_min_sel	= 8,					\
387 	.n_voltages	= S2MPS11_BUCK12346_N_VOLTAGES,		\
388 	.ramp_delay	= S2MPS11_RAMP_DELAY,			\
389 	.vsel_reg	= S2MPS11_REG_B1CTRL2 + (num - 1) * 2,	\
390 	.vsel_mask	= S2MPS11_BUCK_VSEL_MASK,		\
391 	.enable_reg	= S2MPS11_REG_B1CTRL1 + (num - 1) * 2,	\
392 	.enable_mask	= S2MPS11_ENABLE_MASK			\
393 }
394 
395 #define regulator_desc_s2mps11_buck5 {				\
396 	.name		= "BUCK5",				\
397 	.id		= S2MPS11_BUCK5,			\
398 	.ops		= &s2mps11_buck_ops,			\
399 	.type		= REGULATOR_VOLTAGE,			\
400 	.owner		= THIS_MODULE,				\
401 	.min_uV		= MIN_650_MV,				\
402 	.uV_step	= STEP_6_25_MV,				\
403 	.linear_min_sel	= 8,					\
404 	.n_voltages	= S2MPS11_BUCK5_N_VOLTAGES,		\
405 	.ramp_delay	= S2MPS11_RAMP_DELAY,			\
406 	.vsel_reg	= S2MPS11_REG_B5CTRL2,			\
407 	.vsel_mask	= S2MPS11_BUCK_VSEL_MASK,		\
408 	.enable_reg	= S2MPS11_REG_B5CTRL1,			\
409 	.enable_mask	= S2MPS11_ENABLE_MASK			\
410 }
411 
412 #define regulator_desc_s2mps11_buck67810(num, min, step, min_sel, voltages) {	\
413 	.name		= "BUCK"#num,				\
414 	.id		= S2MPS11_BUCK##num,			\
415 	.ops		= &s2mps11_buck_ops,			\
416 	.type		= REGULATOR_VOLTAGE,			\
417 	.owner		= THIS_MODULE,				\
418 	.min_uV		= min,					\
419 	.uV_step	= step,					\
420 	.linear_min_sel	= min_sel,				\
421 	.n_voltages	= voltages,				\
422 	.ramp_delay	= S2MPS11_RAMP_DELAY,			\
423 	.vsel_reg	= S2MPS11_REG_B6CTRL2 + (num - 6) * 2,	\
424 	.vsel_mask	= S2MPS11_BUCK_VSEL_MASK,		\
425 	.enable_reg	= S2MPS11_REG_B6CTRL1 + (num - 6) * 2,	\
426 	.enable_mask	= S2MPS11_ENABLE_MASK			\
427 }
428 
429 #define regulator_desc_s2mps11_buck9 {				\
430 	.name		= "BUCK9",				\
431 	.id		= S2MPS11_BUCK9,			\
432 	.ops		= &s2mps11_buck_ops,			\
433 	.type		= REGULATOR_VOLTAGE,			\
434 	.owner		= THIS_MODULE,				\
435 	.min_uV		= MIN_3000_MV,				\
436 	.uV_step	= STEP_25_MV,				\
437 	.n_voltages	= S2MPS11_BUCK9_N_VOLTAGES,		\
438 	.ramp_delay	= S2MPS11_RAMP_DELAY,			\
439 	.vsel_reg	= S2MPS11_REG_B9CTRL2,			\
440 	.vsel_mask	= S2MPS11_BUCK9_VSEL_MASK,		\
441 	.enable_reg	= S2MPS11_REG_B9CTRL1,			\
442 	.enable_mask	= S2MPS11_ENABLE_MASK			\
443 }
444 
445 static const struct regulator_desc s2mps11_regulators[] = {
446 	regulator_desc_s2mps11_ldo(1, STEP_25_MV),
447 	regulator_desc_s2mps11_ldo(2, STEP_50_MV),
448 	regulator_desc_s2mps11_ldo(3, STEP_50_MV),
449 	regulator_desc_s2mps11_ldo(4, STEP_50_MV),
450 	regulator_desc_s2mps11_ldo(5, STEP_50_MV),
451 	regulator_desc_s2mps11_ldo(6, STEP_25_MV),
452 	regulator_desc_s2mps11_ldo(7, STEP_50_MV),
453 	regulator_desc_s2mps11_ldo(8, STEP_50_MV),
454 	regulator_desc_s2mps11_ldo(9, STEP_50_MV),
455 	regulator_desc_s2mps11_ldo(10, STEP_50_MV),
456 	regulator_desc_s2mps11_ldo(11, STEP_25_MV),
457 	regulator_desc_s2mps11_ldo(12, STEP_50_MV),
458 	regulator_desc_s2mps11_ldo(13, STEP_50_MV),
459 	regulator_desc_s2mps11_ldo(14, STEP_50_MV),
460 	regulator_desc_s2mps11_ldo(15, STEP_50_MV),
461 	regulator_desc_s2mps11_ldo(16, STEP_50_MV),
462 	regulator_desc_s2mps11_ldo(17, STEP_50_MV),
463 	regulator_desc_s2mps11_ldo(18, STEP_50_MV),
464 	regulator_desc_s2mps11_ldo(19, STEP_50_MV),
465 	regulator_desc_s2mps11_ldo(20, STEP_50_MV),
466 	regulator_desc_s2mps11_ldo(21, STEP_50_MV),
467 	regulator_desc_s2mps11_ldo(22, STEP_25_MV),
468 	regulator_desc_s2mps11_ldo(23, STEP_25_MV),
469 	regulator_desc_s2mps11_ldo(24, STEP_50_MV),
470 	regulator_desc_s2mps11_ldo(25, STEP_50_MV),
471 	regulator_desc_s2mps11_ldo(26, STEP_50_MV),
472 	regulator_desc_s2mps11_ldo(27, STEP_25_MV),
473 	regulator_desc_s2mps11_ldo(28, STEP_50_MV),
474 	regulator_desc_s2mps11_ldo(29, STEP_50_MV),
475 	regulator_desc_s2mps11_ldo(30, STEP_50_MV),
476 	regulator_desc_s2mps11_ldo(31, STEP_50_MV),
477 	regulator_desc_s2mps11_ldo(32, STEP_50_MV),
478 	regulator_desc_s2mps11_ldo(33, STEP_50_MV),
479 	regulator_desc_s2mps11_ldo(34, STEP_50_MV),
480 	regulator_desc_s2mps11_ldo(35, STEP_25_MV),
481 	regulator_desc_s2mps11_ldo(36, STEP_50_MV),
482 	regulator_desc_s2mps11_ldo(37, STEP_50_MV),
483 	regulator_desc_s2mps11_ldo(38, STEP_50_MV),
484 	regulator_desc_s2mps11_buck1_4(1),
485 	regulator_desc_s2mps11_buck1_4(2),
486 	regulator_desc_s2mps11_buck1_4(3),
487 	regulator_desc_s2mps11_buck1_4(4),
488 	regulator_desc_s2mps11_buck5,
489 	regulator_desc_s2mps11_buck67810(6, MIN_650_MV, STEP_6_25_MV, 8,
490 					 S2MPS11_BUCK12346_N_VOLTAGES),
491 	regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV, 0,
492 					 S2MPS11_BUCK7810_N_VOLTAGES),
493 	regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV, 0,
494 					 S2MPS11_BUCK7810_N_VOLTAGES),
495 	regulator_desc_s2mps11_buck9,
496 	regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV, 0,
497 					 S2MPS11_BUCK7810_N_VOLTAGES),
498 };
499 
500 static const struct regulator_ops s2mps14_reg_ops;
501 
502 #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) {	\
503 	.name		= "LDO"#num,				\
504 	.id		= S2MPS13_LDO##num,			\
505 	.ops		= &s2mps14_reg_ops,			\
506 	.type		= REGULATOR_VOLTAGE,			\
507 	.owner		= THIS_MODULE,				\
508 	.min_uV		= min,					\
509 	.uV_step	= step,					\
510 	.linear_min_sel	= min_sel,				\
511 	.n_voltages	= S2MPS14_LDO_N_VOLTAGES,		\
512 	.vsel_reg	= S2MPS13_REG_L1CTRL + num - 1,		\
513 	.vsel_mask	= S2MPS14_LDO_VSEL_MASK,		\
514 	.enable_reg	= S2MPS13_REG_L1CTRL + num - 1,		\
515 	.enable_mask	= S2MPS14_ENABLE_MASK			\
516 }
517 
518 #define regulator_desc_s2mps13_buck(num, min, step, min_sel) {	\
519 	.name		= "BUCK"#num,				\
520 	.id		= S2MPS13_BUCK##num,			\
521 	.ops		= &s2mps14_reg_ops,			\
522 	.type		= REGULATOR_VOLTAGE,			\
523 	.owner		= THIS_MODULE,				\
524 	.min_uV		= min,					\
525 	.uV_step	= step,					\
526 	.linear_min_sel	= min_sel,				\
527 	.n_voltages	= S2MPS14_BUCK_N_VOLTAGES,		\
528 	.ramp_delay	= S2MPS13_BUCK_RAMP_DELAY,		\
529 	.vsel_reg	= S2MPS13_REG_B1OUT + (num - 1) * 2,	\
530 	.vsel_mask	= S2MPS14_BUCK_VSEL_MASK,		\
531 	.enable_reg	= S2MPS13_REG_B1CTRL + (num - 1) * 2,	\
532 	.enable_mask	= S2MPS14_ENABLE_MASK			\
533 }
534 
535 #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) {	\
536 	.name		= "BUCK"#num,				\
537 	.id		= S2MPS13_BUCK##num,			\
538 	.ops		= &s2mps14_reg_ops,			\
539 	.type		= REGULATOR_VOLTAGE,			\
540 	.owner		= THIS_MODULE,				\
541 	.min_uV		= min,					\
542 	.uV_step	= step,					\
543 	.linear_min_sel	= min_sel,				\
544 	.n_voltages	= S2MPS14_BUCK_N_VOLTAGES,		\
545 	.ramp_delay	= S2MPS13_BUCK_RAMP_DELAY,		\
546 	.vsel_reg	= S2MPS13_REG_B1OUT + (num) * 2 - 1,	\
547 	.vsel_mask	= S2MPS14_BUCK_VSEL_MASK,		\
548 	.enable_reg	= S2MPS13_REG_B1CTRL + (num - 1) * 2,	\
549 	.enable_mask	= S2MPS14_ENABLE_MASK			\
550 }
551 
552 #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) {	\
553 	.name		= "BUCK"#num,				\
554 	.id		= S2MPS13_BUCK##num,			\
555 	.ops		= &s2mps14_reg_ops,			\
556 	.type		= REGULATOR_VOLTAGE,			\
557 	.owner		= THIS_MODULE,				\
558 	.min_uV		= min,					\
559 	.uV_step	= step,					\
560 	.linear_min_sel	= min_sel,				\
561 	.n_voltages	= S2MPS14_BUCK_N_VOLTAGES,		\
562 	.ramp_delay	= S2MPS13_BUCK_RAMP_DELAY,		\
563 	.vsel_reg	= S2MPS13_REG_B1OUT + (num) * 2 - 1,	\
564 	.vsel_mask	= S2MPS14_BUCK_VSEL_MASK,		\
565 	.enable_reg	= S2MPS13_REG_B1CTRL + (num) * 2 - 1,	\
566 	.enable_mask	= S2MPS14_ENABLE_MASK			\
567 }
568 
569 static const struct regulator_desc s2mps13_regulators[] = {
570 	regulator_desc_s2mps13_ldo(1,  MIN_800_MV,  STEP_12_5_MV, 0x00),
571 	regulator_desc_s2mps13_ldo(2,  MIN_1400_MV, STEP_50_MV,   0x0C),
572 	regulator_desc_s2mps13_ldo(3,  MIN_1000_MV, STEP_25_MV,   0x08),
573 	regulator_desc_s2mps13_ldo(4,  MIN_800_MV,  STEP_12_5_MV, 0x00),
574 	regulator_desc_s2mps13_ldo(5,  MIN_800_MV,  STEP_12_5_MV, 0x00),
575 	regulator_desc_s2mps13_ldo(6,  MIN_800_MV,  STEP_12_5_MV, 0x00),
576 	regulator_desc_s2mps13_ldo(7,  MIN_1000_MV, STEP_25_MV,   0x08),
577 	regulator_desc_s2mps13_ldo(8,  MIN_1000_MV, STEP_25_MV,   0x08),
578 	regulator_desc_s2mps13_ldo(9,  MIN_1000_MV, STEP_25_MV,   0x08),
579 	regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV,   0x0C),
580 	regulator_desc_s2mps13_ldo(11, MIN_800_MV,  STEP_25_MV,   0x10),
581 	regulator_desc_s2mps13_ldo(12, MIN_800_MV,  STEP_25_MV,   0x10),
582 	regulator_desc_s2mps13_ldo(13, MIN_800_MV,  STEP_25_MV,   0x10),
583 	regulator_desc_s2mps13_ldo(14, MIN_800_MV,  STEP_12_5_MV, 0x00),
584 	regulator_desc_s2mps13_ldo(15, MIN_800_MV,  STEP_12_5_MV, 0x00),
585 	regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV,   0x0C),
586 	regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV,   0x0C),
587 	regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV,   0x08),
588 	regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV,   0x08),
589 	regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV,   0x0C),
590 	regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV,   0x08),
591 	regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV,   0x08),
592 	regulator_desc_s2mps13_ldo(23, MIN_800_MV,  STEP_12_5_MV, 0x00),
593 	regulator_desc_s2mps13_ldo(24, MIN_800_MV,  STEP_12_5_MV, 0x00),
594 	regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV,   0x0C),
595 	regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV,   0x0C),
596 	regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV,   0x0C),
597 	regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV,   0x08),
598 	regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV,   0x0C),
599 	regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV,   0x0C),
600 	regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV,   0x08),
601 	regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV,   0x08),
602 	regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV,   0x0C),
603 	regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV,   0x08),
604 	regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV,   0x0C),
605 	regulator_desc_s2mps13_ldo(36, MIN_800_MV,  STEP_12_5_MV, 0x00),
606 	regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV,   0x08),
607 	regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV,   0x0C),
608 	regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV,   0x08),
609 	regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV,   0x0C),
610 	regulator_desc_s2mps13_buck(1,  MIN_500_MV,  STEP_6_25_MV, 0x10),
611 	regulator_desc_s2mps13_buck(2,  MIN_500_MV,  STEP_6_25_MV, 0x10),
612 	regulator_desc_s2mps13_buck(3,  MIN_500_MV,  STEP_6_25_MV, 0x10),
613 	regulator_desc_s2mps13_buck(4,  MIN_500_MV,  STEP_6_25_MV, 0x10),
614 	regulator_desc_s2mps13_buck(5,  MIN_500_MV,  STEP_6_25_MV, 0x10),
615 	regulator_desc_s2mps13_buck(6,  MIN_500_MV,  STEP_6_25_MV, 0x10),
616 	regulator_desc_s2mps13_buck7(7,  MIN_500_MV,  STEP_6_25_MV, 0x10),
617 	regulator_desc_s2mps13_buck8_10(8,  MIN_1000_MV, STEP_12_5_MV, 0x20),
618 	regulator_desc_s2mps13_buck8_10(9,  MIN_1000_MV, STEP_12_5_MV, 0x20),
619 	regulator_desc_s2mps13_buck8_10(10, MIN_500_MV,  STEP_6_25_MV, 0x10),
620 };
621 
622 static const struct regulator_ops s2mps14_reg_ops = {
623 	.list_voltage		= regulator_list_voltage_linear,
624 	.map_voltage		= regulator_map_voltage_linear,
625 	.is_enabled		= regulator_is_enabled_regmap,
626 	.enable			= s2mps11_regulator_enable,
627 	.disable		= regulator_disable_regmap,
628 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
629 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
630 	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
631 	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
632 };
633 
634 #define regulator_desc_s2mps14_ldo(num, min, step) {	\
635 	.name		= "LDO"#num,			\
636 	.id		= S2MPS14_LDO##num,		\
637 	.ops		= &s2mps14_reg_ops,		\
638 	.type		= REGULATOR_VOLTAGE,		\
639 	.owner		= THIS_MODULE,			\
640 	.min_uV		= min,				\
641 	.uV_step	= step,				\
642 	.n_voltages	= S2MPS14_LDO_N_VOLTAGES,	\
643 	.vsel_reg	= S2MPS14_REG_L1CTRL + num - 1,	\
644 	.vsel_mask	= S2MPS14_LDO_VSEL_MASK,	\
645 	.enable_reg	= S2MPS14_REG_L1CTRL + num - 1,	\
646 	.enable_mask	= S2MPS14_ENABLE_MASK		\
647 }
648 
649 #define regulator_desc_s2mps14_buck(num, min, step, min_sel) {	\
650 	.name		= "BUCK"#num,				\
651 	.id		= S2MPS14_BUCK##num,			\
652 	.ops		= &s2mps14_reg_ops,			\
653 	.type		= REGULATOR_VOLTAGE,			\
654 	.owner		= THIS_MODULE,				\
655 	.min_uV		= min,					\
656 	.uV_step	= step,					\
657 	.n_voltages	= S2MPS14_BUCK_N_VOLTAGES,		\
658 	.linear_min_sel = min_sel,				\
659 	.ramp_delay	= S2MPS14_BUCK_RAMP_DELAY,		\
660 	.vsel_reg	= S2MPS14_REG_B1CTRL2 + (num - 1) * 2,	\
661 	.vsel_mask	= S2MPS14_BUCK_VSEL_MASK,		\
662 	.enable_reg	= S2MPS14_REG_B1CTRL1 + (num - 1) * 2,	\
663 	.enable_mask	= S2MPS14_ENABLE_MASK			\
664 }
665 
666 static const struct regulator_desc s2mps14_regulators[] = {
667 	regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
668 	regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
669 	regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
670 	regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
671 	regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
672 	regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
673 	regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
674 	regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
675 	regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
676 	regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
677 	regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
678 	regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
679 	regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
680 	regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
681 	regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
682 	regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
683 	regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
684 	regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
685 	regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
686 	regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
687 	regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
688 	regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
689 	regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
690 	regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
691 	regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
692 	regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
693 				    S2MPS14_BUCK1235_START_SEL),
694 	regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
695 				    S2MPS14_BUCK1235_START_SEL),
696 	regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
697 				    S2MPS14_BUCK1235_START_SEL),
698 	regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
699 				    S2MPS14_BUCK4_START_SEL),
700 	regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
701 				    S2MPS14_BUCK1235_START_SEL),
702 };
703 
704 static const struct regulator_ops s2mps15_reg_ldo_ops = {
705 	.list_voltage		= regulator_list_voltage_linear_range,
706 	.map_voltage		= regulator_map_voltage_linear_range,
707 	.is_enabled		= regulator_is_enabled_regmap,
708 	.enable			= regulator_enable_regmap,
709 	.disable		= regulator_disable_regmap,
710 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
711 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
712 };
713 
714 static const struct regulator_ops s2mps15_reg_buck_ops = {
715 	.list_voltage		= regulator_list_voltage_linear_range,
716 	.map_voltage		= regulator_map_voltage_linear_range,
717 	.is_enabled		= regulator_is_enabled_regmap,
718 	.enable			= regulator_enable_regmap,
719 	.disable		= regulator_disable_regmap,
720 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
721 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
722 	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
723 };
724 
725 #define regulator_desc_s2mps15_ldo(num, range) {	\
726 	.name		= "LDO"#num,			\
727 	.id		= S2MPS15_LDO##num,		\
728 	.ops		= &s2mps15_reg_ldo_ops,		\
729 	.type		= REGULATOR_VOLTAGE,		\
730 	.owner		= THIS_MODULE,			\
731 	.linear_ranges	= range,			\
732 	.n_linear_ranges = ARRAY_SIZE(range),		\
733 	.n_voltages	= S2MPS15_LDO_N_VOLTAGES,	\
734 	.vsel_reg	= S2MPS15_REG_L1CTRL + num - 1,	\
735 	.vsel_mask	= S2MPS15_LDO_VSEL_MASK,	\
736 	.enable_reg	= S2MPS15_REG_L1CTRL + num - 1,	\
737 	.enable_mask	= S2MPS15_ENABLE_MASK		\
738 }
739 
740 #define regulator_desc_s2mps15_buck(num, range) {			\
741 	.name		= "BUCK"#num,					\
742 	.id		= S2MPS15_BUCK##num,				\
743 	.ops		= &s2mps15_reg_buck_ops,			\
744 	.type		= REGULATOR_VOLTAGE,				\
745 	.owner		= THIS_MODULE,					\
746 	.linear_ranges	= range,					\
747 	.n_linear_ranges = ARRAY_SIZE(range),				\
748 	.ramp_delay	= 12500,					\
749 	.n_voltages	= S2MPS15_BUCK_N_VOLTAGES,			\
750 	.vsel_reg	= S2MPS15_REG_B1CTRL2 + ((num - 1) * 2),	\
751 	.vsel_mask	= S2MPS15_BUCK_VSEL_MASK,			\
752 	.enable_reg	= S2MPS15_REG_B1CTRL1 + ((num - 1) * 2),	\
753 	.enable_mask	= S2MPS15_ENABLE_MASK				\
754 }
755 
756 /* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
757 static const struct linear_range s2mps15_ldo_voltage_ranges1[] = {
758 	REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
759 };
760 
761 /* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
762 static const struct linear_range s2mps15_ldo_voltage_ranges2[] = {
763 	REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
764 };
765 
766 /* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
767 static const struct linear_range s2mps15_ldo_voltage_ranges3[] = {
768 	REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
769 };
770 
771 /* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
772 static const struct linear_range s2mps15_ldo_voltage_ranges4[] = {
773 	REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000),
774 };
775 
776 /* voltage range for s2mps15 LDO 1 */
777 static const struct linear_range s2mps15_ldo_voltage_ranges5[] = {
778 	REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
779 };
780 
781 /* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
782 static const struct linear_range s2mps15_buck_voltage_ranges1[] = {
783 	REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250),
784 };
785 
786 /* voltage range for s2mps15 BUCK 8, 9 and 10 */
787 static const struct linear_range s2mps15_buck_voltage_ranges2[] = {
788 	REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500),
789 };
790 
791 static const struct regulator_desc s2mps15_regulators[] = {
792 	regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
793 	regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
794 	regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
795 	regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
796 	regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
797 	regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
798 	regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
799 	regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
800 	regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
801 	regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
802 	regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
803 	regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
804 	regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
805 	regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
806 	regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
807 	regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
808 	regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
809 	regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
810 	regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
811 	regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
812 	regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
813 	regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
814 	regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
815 	regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
816 	regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
817 	regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
818 	regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
819 	regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
820 	regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
821 	regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
822 	regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
823 	regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
824 	regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
825 	regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
826 	regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
827 	regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
828 	regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
829 };
830 
831 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
832 		struct regulator_dev *rdev)
833 {
834 	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
835 			rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
836 }
837 
838 static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
839 		struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
840 {
841 	struct gpio_desc **gpio = s2mps11->ext_control_gpiod;
842 	unsigned int i;
843 	unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
844 		S2MPS14_LDO12 };
845 
846 	for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
847 		unsigned int reg = valid_regulators[i];
848 
849 		if (!rdata[reg].init_data || !rdata[reg].of_node)
850 			continue;
851 
852 		gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev,
853 				of_fwnode_handle(rdata[reg].of_node),
854 				"samsung,ext-control",
855 				GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
856 				"s2mps11-regulator");
857 		if (PTR_ERR(gpio[reg]) == -ENOENT)
858 			gpio[reg] = NULL;
859 		else if (IS_ERR(gpio[reg])) {
860 			dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
861 				reg, rdata[reg].name);
862 			gpio[reg] = NULL;
863 			continue;
864 		}
865 		if (gpio[reg])
866 			dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n",
867 				reg, rdata[reg].name);
868 	}
869 }
870 
871 static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
872 		struct of_regulator_match *rdata, struct s2mps11_info *s2mps11,
873 		unsigned int rdev_num)
874 {
875 	struct device_node *reg_np;
876 
877 	reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
878 	if (!reg_np) {
879 		dev_err(&pdev->dev, "could not find regulators sub-node\n");
880 		return -EINVAL;
881 	}
882 
883 	of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num);
884 	if (s2mps11->dev_type == S2MPS14X)
885 		s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
886 
887 	of_node_put(reg_np);
888 
889 	return 0;
890 }
891 
892 static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
893 {
894 	unsigned int ramp_val, ramp_shift, ramp_reg;
895 	int rdev_id = rdev_get_id(rdev);
896 
897 	switch (rdev_id) {
898 	case S2MPU02_BUCK1:
899 		ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
900 		break;
901 	case S2MPU02_BUCK2:
902 		ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
903 		break;
904 	case S2MPU02_BUCK3:
905 		ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
906 		break;
907 	case S2MPU02_BUCK4:
908 		ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
909 		break;
910 	default:
911 		return 0;
912 	}
913 	ramp_reg = S2MPU02_REG_RAMP1;
914 	ramp_val = get_ramp_delay(ramp_delay);
915 
916 	return regmap_update_bits(rdev->regmap, ramp_reg,
917 				  S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
918 				  ramp_val << ramp_shift);
919 }
920 
921 static const struct regulator_ops s2mpu02_ldo_ops = {
922 	.list_voltage		= regulator_list_voltage_linear,
923 	.map_voltage		= regulator_map_voltage_linear,
924 	.is_enabled		= regulator_is_enabled_regmap,
925 	.enable			= s2mps11_regulator_enable,
926 	.disable		= regulator_disable_regmap,
927 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
928 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
929 	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
930 	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
931 };
932 
933 static const struct regulator_ops s2mpu02_buck_ops = {
934 	.list_voltage		= regulator_list_voltage_linear,
935 	.map_voltage		= regulator_map_voltage_linear,
936 	.is_enabled		= regulator_is_enabled_regmap,
937 	.enable			= s2mps11_regulator_enable,
938 	.disable		= regulator_disable_regmap,
939 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
940 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
941 	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
942 	.set_suspend_disable	= s2mps11_regulator_set_suspend_disable,
943 	.set_ramp_delay		= s2mpu02_set_ramp_delay,
944 };
945 
946 #define regulator_desc_s2mpu02_ldo1(num) {		\
947 	.name		= "LDO"#num,			\
948 	.id		= S2MPU02_LDO##num,		\
949 	.ops		= &s2mpu02_ldo_ops,		\
950 	.type		= REGULATOR_VOLTAGE,		\
951 	.owner		= THIS_MODULE,			\
952 	.min_uV		= S2MPU02_LDO_MIN_900MV,	\
953 	.uV_step	= S2MPU02_LDO_STEP_12_5MV,	\
954 	.linear_min_sel	= S2MPU02_LDO_GROUP1_START_SEL,	\
955 	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
956 	.vsel_reg	= S2MPU02_REG_L1CTRL,		\
957 	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
958 	.enable_reg	= S2MPU02_REG_L1CTRL,		\
959 	.enable_mask	= S2MPU02_ENABLE_MASK		\
960 }
961 #define regulator_desc_s2mpu02_ldo2(num) {		\
962 	.name		= "LDO"#num,			\
963 	.id		= S2MPU02_LDO##num,		\
964 	.ops		= &s2mpu02_ldo_ops,		\
965 	.type		= REGULATOR_VOLTAGE,		\
966 	.owner		= THIS_MODULE,			\
967 	.min_uV		= S2MPU02_LDO_MIN_1050MV,	\
968 	.uV_step	= S2MPU02_LDO_STEP_25MV,	\
969 	.linear_min_sel	= S2MPU02_LDO_GROUP2_START_SEL,	\
970 	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
971 	.vsel_reg	= S2MPU02_REG_L2CTRL1,		\
972 	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
973 	.enable_reg	= S2MPU02_REG_L2CTRL1,		\
974 	.enable_mask	= S2MPU02_ENABLE_MASK		\
975 }
976 #define regulator_desc_s2mpu02_ldo3(num) {		\
977 	.name		= "LDO"#num,			\
978 	.id		= S2MPU02_LDO##num,		\
979 	.ops		= &s2mpu02_ldo_ops,		\
980 	.type		= REGULATOR_VOLTAGE,		\
981 	.owner		= THIS_MODULE,			\
982 	.min_uV		= S2MPU02_LDO_MIN_900MV,	\
983 	.uV_step	= S2MPU02_LDO_STEP_12_5MV,	\
984 	.linear_min_sel	= S2MPU02_LDO_GROUP1_START_SEL,	\
985 	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
986 	.vsel_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
987 	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
988 	.enable_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
989 	.enable_mask	= S2MPU02_ENABLE_MASK		\
990 }
991 #define regulator_desc_s2mpu02_ldo4(num) {		\
992 	.name		= "LDO"#num,			\
993 	.id		= S2MPU02_LDO##num,		\
994 	.ops		= &s2mpu02_ldo_ops,		\
995 	.type		= REGULATOR_VOLTAGE,		\
996 	.owner		= THIS_MODULE,			\
997 	.min_uV		= S2MPU02_LDO_MIN_1050MV,	\
998 	.uV_step	= S2MPU02_LDO_STEP_25MV,	\
999 	.linear_min_sel	= S2MPU02_LDO_GROUP2_START_SEL,	\
1000 	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
1001 	.vsel_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
1002 	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
1003 	.enable_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
1004 	.enable_mask	= S2MPU02_ENABLE_MASK		\
1005 }
1006 #define regulator_desc_s2mpu02_ldo5(num) {		\
1007 	.name		= "LDO"#num,			\
1008 	.id		= S2MPU02_LDO##num,		\
1009 	.ops		= &s2mpu02_ldo_ops,		\
1010 	.type		= REGULATOR_VOLTAGE,		\
1011 	.owner		= THIS_MODULE,			\
1012 	.min_uV		= S2MPU02_LDO_MIN_1600MV,	\
1013 	.uV_step	= S2MPU02_LDO_STEP_50MV,	\
1014 	.linear_min_sel	= S2MPU02_LDO_GROUP3_START_SEL,	\
1015 	.n_voltages	= S2MPU02_LDO_N_VOLTAGES,	\
1016 	.vsel_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
1017 	.vsel_mask	= S2MPU02_LDO_VSEL_MASK,	\
1018 	.enable_reg	= S2MPU02_REG_L3CTRL + num - 3,	\
1019 	.enable_mask	= S2MPU02_ENABLE_MASK		\
1020 }
1021 
1022 #define regulator_desc_s2mpu02_buck1234(num) {			\
1023 	.name		= "BUCK"#num,				\
1024 	.id		= S2MPU02_BUCK##num,			\
1025 	.ops		= &s2mpu02_buck_ops,			\
1026 	.type		= REGULATOR_VOLTAGE,			\
1027 	.owner		= THIS_MODULE,				\
1028 	.min_uV		= S2MPU02_BUCK1234_MIN_600MV,		\
1029 	.uV_step	= S2MPU02_BUCK1234_STEP_6_25MV,		\
1030 	.n_voltages	= S2MPU02_BUCK_N_VOLTAGES,		\
1031 	.linear_min_sel = S2MPU02_BUCK1234_START_SEL,		\
1032 	.ramp_delay	= S2MPU02_BUCK_RAMP_DELAY,		\
1033 	.vsel_reg	= S2MPU02_REG_B1CTRL2 + (num - 1) * 2,	\
1034 	.vsel_mask	= S2MPU02_BUCK_VSEL_MASK,		\
1035 	.enable_reg	= S2MPU02_REG_B1CTRL1 + (num - 1) * 2,	\
1036 	.enable_mask	= S2MPU02_ENABLE_MASK			\
1037 }
1038 #define regulator_desc_s2mpu02_buck5(num) {			\
1039 	.name		= "BUCK"#num,				\
1040 	.id		= S2MPU02_BUCK##num,			\
1041 	.ops		= &s2mpu02_ldo_ops,			\
1042 	.type		= REGULATOR_VOLTAGE,			\
1043 	.owner		= THIS_MODULE,				\
1044 	.min_uV		= S2MPU02_BUCK5_MIN_1081_25MV,		\
1045 	.uV_step	= S2MPU02_BUCK5_STEP_6_25MV,		\
1046 	.n_voltages	= S2MPU02_BUCK_N_VOLTAGES,		\
1047 	.linear_min_sel = S2MPU02_BUCK5_START_SEL,		\
1048 	.ramp_delay	= S2MPU02_BUCK_RAMP_DELAY,		\
1049 	.vsel_reg	= S2MPU02_REG_B5CTRL2,			\
1050 	.vsel_mask	= S2MPU02_BUCK_VSEL_MASK,		\
1051 	.enable_reg	= S2MPU02_REG_B5CTRL1,			\
1052 	.enable_mask	= S2MPU02_ENABLE_MASK			\
1053 }
1054 #define regulator_desc_s2mpu02_buck6(num) {			\
1055 	.name		= "BUCK"#num,				\
1056 	.id		= S2MPU02_BUCK##num,			\
1057 	.ops		= &s2mpu02_ldo_ops,			\
1058 	.type		= REGULATOR_VOLTAGE,			\
1059 	.owner		= THIS_MODULE,				\
1060 	.min_uV		= S2MPU02_BUCK6_MIN_1700MV,		\
1061 	.uV_step	= S2MPU02_BUCK6_STEP_2_50MV,		\
1062 	.n_voltages	= S2MPU02_BUCK_N_VOLTAGES,		\
1063 	.linear_min_sel = S2MPU02_BUCK6_START_SEL,		\
1064 	.ramp_delay	= S2MPU02_BUCK_RAMP_DELAY,		\
1065 	.vsel_reg	= S2MPU02_REG_B6CTRL2,			\
1066 	.vsel_mask	= S2MPU02_BUCK_VSEL_MASK,		\
1067 	.enable_reg	= S2MPU02_REG_B6CTRL1,			\
1068 	.enable_mask	= S2MPU02_ENABLE_MASK			\
1069 }
1070 #define regulator_desc_s2mpu02_buck7(num) {			\
1071 	.name		= "BUCK"#num,				\
1072 	.id		= S2MPU02_BUCK##num,			\
1073 	.ops		= &s2mpu02_ldo_ops,			\
1074 	.type		= REGULATOR_VOLTAGE,			\
1075 	.owner		= THIS_MODULE,				\
1076 	.min_uV		= S2MPU02_BUCK7_MIN_900MV,		\
1077 	.uV_step	= S2MPU02_BUCK7_STEP_6_25MV,		\
1078 	.n_voltages	= S2MPU02_BUCK_N_VOLTAGES,		\
1079 	.linear_min_sel = S2MPU02_BUCK7_START_SEL,		\
1080 	.ramp_delay	= S2MPU02_BUCK_RAMP_DELAY,		\
1081 	.vsel_reg	= S2MPU02_REG_B7CTRL2,			\
1082 	.vsel_mask	= S2MPU02_BUCK_VSEL_MASK,		\
1083 	.enable_reg	= S2MPU02_REG_B7CTRL1,			\
1084 	.enable_mask	= S2MPU02_ENABLE_MASK			\
1085 }
1086 
1087 static const struct regulator_desc s2mpu02_regulators[] = {
1088 	regulator_desc_s2mpu02_ldo1(1),
1089 	regulator_desc_s2mpu02_ldo2(2),
1090 	regulator_desc_s2mpu02_ldo4(3),
1091 	regulator_desc_s2mpu02_ldo5(4),
1092 	regulator_desc_s2mpu02_ldo4(5),
1093 	regulator_desc_s2mpu02_ldo3(6),
1094 	regulator_desc_s2mpu02_ldo3(7),
1095 	regulator_desc_s2mpu02_ldo4(8),
1096 	regulator_desc_s2mpu02_ldo5(9),
1097 	regulator_desc_s2mpu02_ldo3(10),
1098 	regulator_desc_s2mpu02_ldo4(11),
1099 	regulator_desc_s2mpu02_ldo5(12),
1100 	regulator_desc_s2mpu02_ldo5(13),
1101 	regulator_desc_s2mpu02_ldo5(14),
1102 	regulator_desc_s2mpu02_ldo5(15),
1103 	regulator_desc_s2mpu02_ldo5(16),
1104 	regulator_desc_s2mpu02_ldo4(17),
1105 	regulator_desc_s2mpu02_ldo5(18),
1106 	regulator_desc_s2mpu02_ldo3(19),
1107 	regulator_desc_s2mpu02_ldo4(20),
1108 	regulator_desc_s2mpu02_ldo5(21),
1109 	regulator_desc_s2mpu02_ldo5(22),
1110 	regulator_desc_s2mpu02_ldo5(23),
1111 	regulator_desc_s2mpu02_ldo4(24),
1112 	regulator_desc_s2mpu02_ldo5(25),
1113 	regulator_desc_s2mpu02_ldo4(26),
1114 	regulator_desc_s2mpu02_ldo5(27),
1115 	regulator_desc_s2mpu02_ldo5(28),
1116 	regulator_desc_s2mpu02_buck1234(1),
1117 	regulator_desc_s2mpu02_buck1234(2),
1118 	regulator_desc_s2mpu02_buck1234(3),
1119 	regulator_desc_s2mpu02_buck1234(4),
1120 	regulator_desc_s2mpu02_buck5(5),
1121 	regulator_desc_s2mpu02_buck6(6),
1122 	regulator_desc_s2mpu02_buck7(7),
1123 };
1124 
1125 #define regulator_desc_s2mpu05_ldo_reg(num, min, step, reg) {	\
1126 	.name		= "ldo"#num,				\
1127 	.id		= S2MPU05_LDO##num,			\
1128 	.ops		= &s2mpu02_ldo_ops,			\
1129 	.type		= REGULATOR_VOLTAGE,			\
1130 	.owner		= THIS_MODULE,				\
1131 	.min_uV		= min,					\
1132 	.uV_step	= step,					\
1133 	.n_voltages	= S2MPU05_LDO_N_VOLTAGES,		\
1134 	.vsel_reg	= reg,					\
1135 	.vsel_mask	= S2MPU05_LDO_VSEL_MASK,		\
1136 	.enable_reg	= reg,					\
1137 	.enable_mask	= S2MPU05_ENABLE_MASK,			\
1138 	.enable_time	= S2MPU05_ENABLE_TIME_LDO		\
1139 }
1140 
1141 #define regulator_desc_s2mpu05_ldo(num, reg, min, step) \
1142 	regulator_desc_s2mpu05_ldo_reg(num, min, step, S2MPU05_REG_L##num##reg)
1143 
1144 #define regulator_desc_s2mpu05_ldo1(num, reg) \
1145 	regulator_desc_s2mpu05_ldo(num, reg, S2MPU05_LDO_MIN1, S2MPU05_LDO_STEP1)
1146 
1147 #define regulator_desc_s2mpu05_ldo2(num, reg) \
1148 	regulator_desc_s2mpu05_ldo(num, reg, S2MPU05_LDO_MIN1, S2MPU05_LDO_STEP2)
1149 
1150 #define regulator_desc_s2mpu05_ldo3(num, reg) \
1151 	regulator_desc_s2mpu05_ldo(num, reg, S2MPU05_LDO_MIN2, S2MPU05_LDO_STEP2)
1152 
1153 #define regulator_desc_s2mpu05_ldo4(num, reg) \
1154 	regulator_desc_s2mpu05_ldo(num, reg, S2MPU05_LDO_MIN3, S2MPU05_LDO_STEP2)
1155 
1156 #define regulator_desc_s2mpu05_buck(num, which) {	\
1157 	.name		= "buck"#num,			\
1158 	.id		= S2MPU05_BUCK##num,		\
1159 	.ops		= &s2mpu02_buck_ops,		\
1160 	.type		= REGULATOR_VOLTAGE,		\
1161 	.owner		= THIS_MODULE,			\
1162 	.min_uV		= S2MPU05_BUCK_MIN##which,	\
1163 	.uV_step	= S2MPU05_BUCK_STEP##which,	\
1164 	.n_voltages	= S2MPU05_BUCK_N_VOLTAGES,	\
1165 	.vsel_reg	= S2MPU05_REG_B##num##CTRL2,	\
1166 	.vsel_mask	= S2MPU05_BUCK_VSEL_MASK,	\
1167 	.enable_reg	= S2MPU05_REG_B##num##CTRL1,	\
1168 	.enable_mask	= S2MPU05_ENABLE_MASK,		\
1169 	.enable_time	= S2MPU05_ENABLE_TIME_BUCK##num	\
1170 }
1171 
1172 #define regulator_desc_s2mpu05_buck123(num) regulator_desc_s2mpu05_buck(num, 1)
1173 #define regulator_desc_s2mpu05_buck45(num) regulator_desc_s2mpu05_buck(num, 2)
1174 
1175 static const struct regulator_desc s2mpu05_regulators[] = {
1176 	regulator_desc_s2mpu05_ldo4(1, CTRL),
1177 	regulator_desc_s2mpu05_ldo3(2, CTRL),
1178 	regulator_desc_s2mpu05_ldo2(3, CTRL),
1179 	regulator_desc_s2mpu05_ldo1(4, CTRL),
1180 	regulator_desc_s2mpu05_ldo1(5, CTRL),
1181 	regulator_desc_s2mpu05_ldo1(6, CTRL),
1182 	regulator_desc_s2mpu05_ldo2(7, CTRL),
1183 	regulator_desc_s2mpu05_ldo3(8, CTRL),
1184 	regulator_desc_s2mpu05_ldo4(9, CTRL1),
1185 	regulator_desc_s2mpu05_ldo4(10, CTRL),
1186 	/* LDOs 11-24 are used for CP. They aren't documented. */
1187 	regulator_desc_s2mpu05_ldo2(25, CTRL),
1188 	regulator_desc_s2mpu05_ldo3(26, CTRL),
1189 	regulator_desc_s2mpu05_ldo2(27, CTRL),
1190 	regulator_desc_s2mpu05_ldo3(28, CTRL),
1191 	regulator_desc_s2mpu05_ldo3(29, CTRL),
1192 	regulator_desc_s2mpu05_ldo2(30, CTRL),
1193 	regulator_desc_s2mpu05_ldo3(31, CTRL),
1194 	regulator_desc_s2mpu05_ldo3(32, CTRL),
1195 	regulator_desc_s2mpu05_ldo3(33, CTRL),
1196 	regulator_desc_s2mpu05_ldo3(34, CTRL),
1197 	regulator_desc_s2mpu05_ldo3(35, CTRL),
1198 	regulator_desc_s2mpu05_buck123(1),
1199 	regulator_desc_s2mpu05_buck123(2),
1200 	regulator_desc_s2mpu05_buck123(3),
1201 	regulator_desc_s2mpu05_buck45(4),
1202 	regulator_desc_s2mpu05_buck45(5),
1203 };
1204 
1205 static int s2mps11_pmic_probe(struct platform_device *pdev)
1206 {
1207 	struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
1208 	struct regulator_config config = { };
1209 	struct s2mps11_info *s2mps11;
1210 	unsigned int rdev_num = 0;
1211 	int i, ret = 0;
1212 	const struct regulator_desc *regulators;
1213 
1214 	s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
1215 				GFP_KERNEL);
1216 	if (!s2mps11)
1217 		return -ENOMEM;
1218 
1219 	s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
1220 	switch (s2mps11->dev_type) {
1221 	case S2MPS11X:
1222 		rdev_num = ARRAY_SIZE(s2mps11_regulators);
1223 		regulators = s2mps11_regulators;
1224 		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
1225 		break;
1226 	case S2MPS13X:
1227 		rdev_num = ARRAY_SIZE(s2mps13_regulators);
1228 		regulators = s2mps13_regulators;
1229 		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
1230 		break;
1231 	case S2MPS14X:
1232 		rdev_num = ARRAY_SIZE(s2mps14_regulators);
1233 		regulators = s2mps14_regulators;
1234 		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
1235 		break;
1236 	case S2MPS15X:
1237 		rdev_num = ARRAY_SIZE(s2mps15_regulators);
1238 		regulators = s2mps15_regulators;
1239 		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
1240 		break;
1241 	case S2MPU02:
1242 		rdev_num = ARRAY_SIZE(s2mpu02_regulators);
1243 		regulators = s2mpu02_regulators;
1244 		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
1245 		break;
1246 	case S2MPU05:
1247 		rdev_num = ARRAY_SIZE(s2mpu05_regulators);
1248 		regulators = s2mpu05_regulators;
1249 		BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu05_regulators));
1250 		break;
1251 	default:
1252 		dev_err(&pdev->dev, "Invalid device type: %u\n",
1253 				    s2mps11->dev_type);
1254 		return -EINVAL;
1255 	}
1256 
1257 	s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num,
1258 			       sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL);
1259 	if (!s2mps11->ext_control_gpiod)
1260 		return -ENOMEM;
1261 
1262 	struct of_regulator_match *rdata __free(kfree) =
1263 		kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL);
1264 	if (!rdata)
1265 		return -ENOMEM;
1266 
1267 	for (i = 0; i < rdev_num; i++)
1268 		rdata[i].name = regulators[i].name;
1269 
1270 	ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num);
1271 	if (ret)
1272 		return ret;
1273 
1274 	platform_set_drvdata(pdev, s2mps11);
1275 
1276 	config.dev = &pdev->dev;
1277 	config.regmap = iodev->regmap_pmic;
1278 	config.driver_data = s2mps11;
1279 	for (i = 0; i < rdev_num; i++) {
1280 		struct regulator_dev *regulator;
1281 
1282 		config.init_data = rdata[i].init_data;
1283 		config.of_node = rdata[i].of_node;
1284 		config.ena_gpiod = s2mps11->ext_control_gpiod[i];
1285 		/*
1286 		 * Hand the GPIO descriptor management over to the regulator
1287 		 * core, remove it from devres management.
1288 		 */
1289 		if (config.ena_gpiod)
1290 			devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod);
1291 		regulator = devm_regulator_register(&pdev->dev,
1292 						&regulators[i], &config);
1293 		if (IS_ERR(regulator)) {
1294 			dev_err(&pdev->dev, "regulator init failed for %d\n",
1295 				i);
1296 			return PTR_ERR(regulator);
1297 		}
1298 
1299 		if (config.ena_gpiod) {
1300 			ret = s2mps14_pmic_enable_ext_control(s2mps11,
1301 					regulator);
1302 			if (ret < 0) {
1303 				dev_err(&pdev->dev,
1304 						"failed to enable GPIO control over %s: %d\n",
1305 						regulator->desc->name, ret);
1306 				return ret;
1307 			}
1308 		}
1309 	}
1310 
1311 	return 0;
1312 }
1313 
1314 static const struct platform_device_id s2mps11_pmic_id[] = {
1315 	{ "s2mps11-regulator", S2MPS11X},
1316 	{ "s2mps13-regulator", S2MPS13X},
1317 	{ "s2mps14-regulator", S2MPS14X},
1318 	{ "s2mps15-regulator", S2MPS15X},
1319 	{ "s2mpu02-regulator", S2MPU02},
1320 	{ "s2mpu05-regulator", S2MPU05},
1321 	{ },
1322 };
1323 MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1324 
1325 static struct platform_driver s2mps11_pmic_driver = {
1326 	.driver = {
1327 		.name = "s2mps11-pmic",
1328 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
1329 	},
1330 	.probe = s2mps11_pmic_probe,
1331 	.id_table = s2mps11_pmic_id,
1332 };
1333 
1334 module_platform_driver(s2mps11_pmic_driver);
1335 
1336 /* Module information */
1337 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
1338 MODULE_DESCRIPTION("Samsung S2MPS11/14/15/S2MPU02/05 Regulator Driver");
1339 MODULE_LICENSE("GPL");
1340