1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
4 // http://www.samsung.com
8 #include <linux/gpio/consumer.h>
9 #include <linux/slab.h>
10 #include <linux/module.h>
12 #include <linux/regmap.h>
13 #include <linux/platform_device.h>
14 #include <linux/regulator/driver.h>
15 #include <linux/regulator/machine.h>
16 #include <linux/regulator/of_regulator.h>
17 #include <linux/mfd/samsung/core.h>
18 #include <linux/mfd/samsung/s2mps11.h>
19 #include <linux/mfd/samsung/s2mps13.h>
20 #include <linux/mfd/samsung/s2mps14.h>
21 #include <linux/mfd/samsung/s2mps15.h>
22 #include <linux/mfd/samsung/s2mpu02.h>
24 /* The highest number of possible regulators for supported devices. */
25 #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX
34 enum sec_device_type dev_type
;
37 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
38 * the suspend mode was enabled.
40 DECLARE_BITMAP(suspend_state
, S2MPS_REGULATOR_MAX
);
43 * Array (size: number of regulators) with GPIO-s for external
46 struct gpio_desc
**ext_control_gpiod
;
49 static int get_ramp_delay(int ramp_delay
)
51 unsigned char cnt
= 0;
56 ramp_delay
= ramp_delay
>> 1;
68 static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev
*rdev
,
69 unsigned int old_selector
,
70 unsigned int new_selector
)
72 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
73 unsigned int ramp_delay
= 0;
74 int old_volt
, new_volt
;
76 switch (rdev_get_id(rdev
)) {
78 ramp_delay
= s2mps11
->ramp_delay2
;
82 ramp_delay
= s2mps11
->ramp_delay34
;
85 ramp_delay
= s2mps11
->ramp_delay5
;
89 ramp_delay
= s2mps11
->ramp_delay16
;
94 ramp_delay
= s2mps11
->ramp_delay7810
;
97 ramp_delay
= s2mps11
->ramp_delay9
;
101 ramp_delay
= rdev
->desc
->ramp_delay
;
103 old_volt
= rdev
->desc
->min_uV
+ (rdev
->desc
->uV_step
* old_selector
);
104 new_volt
= rdev
->desc
->min_uV
+ (rdev
->desc
->uV_step
* new_selector
);
106 return DIV_ROUND_UP(abs(new_volt
- old_volt
), ramp_delay
);
109 static int s2mps11_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
111 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
112 unsigned int ramp_val
, ramp_shift
, ramp_reg
= S2MPS11_REG_RAMP_BUCK
;
113 unsigned int ramp_enable
= 1, enable_shift
= 0;
116 switch (rdev_get_id(rdev
)) {
118 if (ramp_delay
> s2mps11
->ramp_delay16
)
119 s2mps11
->ramp_delay16
= ramp_delay
;
121 ramp_delay
= s2mps11
->ramp_delay16
;
123 ramp_shift
= S2MPS11_BUCK16_RAMP_SHIFT
;
126 enable_shift
= S2MPS11_BUCK2_RAMP_EN_SHIFT
;
132 s2mps11
->ramp_delay2
= ramp_delay
;
133 ramp_shift
= S2MPS11_BUCK2_RAMP_SHIFT
;
134 ramp_reg
= S2MPS11_REG_RAMP
;
137 enable_shift
= S2MPS11_BUCK3_RAMP_EN_SHIFT
;
143 if (ramp_delay
> s2mps11
->ramp_delay34
)
144 s2mps11
->ramp_delay34
= ramp_delay
;
146 ramp_delay
= s2mps11
->ramp_delay34
;
148 ramp_shift
= S2MPS11_BUCK34_RAMP_SHIFT
;
149 ramp_reg
= S2MPS11_REG_RAMP
;
152 enable_shift
= S2MPS11_BUCK4_RAMP_EN_SHIFT
;
158 if (ramp_delay
> s2mps11
->ramp_delay34
)
159 s2mps11
->ramp_delay34
= ramp_delay
;
161 ramp_delay
= s2mps11
->ramp_delay34
;
163 ramp_shift
= S2MPS11_BUCK34_RAMP_SHIFT
;
164 ramp_reg
= S2MPS11_REG_RAMP
;
167 s2mps11
->ramp_delay5
= ramp_delay
;
168 ramp_shift
= S2MPS11_BUCK5_RAMP_SHIFT
;
171 enable_shift
= S2MPS11_BUCK6_RAMP_EN_SHIFT
;
177 if (ramp_delay
> s2mps11
->ramp_delay16
)
178 s2mps11
->ramp_delay16
= ramp_delay
;
180 ramp_delay
= s2mps11
->ramp_delay16
;
182 ramp_shift
= S2MPS11_BUCK16_RAMP_SHIFT
;
187 if (ramp_delay
> s2mps11
->ramp_delay7810
)
188 s2mps11
->ramp_delay7810
= ramp_delay
;
190 ramp_delay
= s2mps11
->ramp_delay7810
;
192 ramp_shift
= S2MPS11_BUCK7810_RAMP_SHIFT
;
195 s2mps11
->ramp_delay9
= ramp_delay
;
196 ramp_shift
= S2MPS11_BUCK9_RAMP_SHIFT
;
205 /* Ramp delay can be enabled/disabled only for buck[2346] */
206 if ((rdev_get_id(rdev
) >= S2MPS11_BUCK2
&&
207 rdev_get_id(rdev
) <= S2MPS11_BUCK4
) ||
208 rdev_get_id(rdev
) == S2MPS11_BUCK6
) {
209 ret
= regmap_update_bits(rdev
->regmap
, S2MPS11_REG_RAMP
,
210 1 << enable_shift
, 1 << enable_shift
);
212 dev_err(&rdev
->dev
, "failed to enable ramp rate\n");
217 ramp_val
= get_ramp_delay(ramp_delay
);
219 return regmap_update_bits(rdev
->regmap
, ramp_reg
, 0x3 << ramp_shift
,
220 ramp_val
<< ramp_shift
);
223 return regmap_update_bits(rdev
->regmap
, S2MPS11_REG_RAMP
,
224 1 << enable_shift
, 0);
227 static const struct regulator_ops s2mps11_ldo_ops
= {
228 .list_voltage
= regulator_list_voltage_linear
,
229 .map_voltage
= regulator_map_voltage_linear
,
230 .is_enabled
= regulator_is_enabled_regmap
,
231 .enable
= regulator_enable_regmap
,
232 .disable
= regulator_disable_regmap
,
233 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
234 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
235 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
238 static const struct regulator_ops s2mps11_buck_ops
= {
239 .list_voltage
= regulator_list_voltage_linear
,
240 .map_voltage
= regulator_map_voltage_linear
,
241 .is_enabled
= regulator_is_enabled_regmap
,
242 .enable
= regulator_enable_regmap
,
243 .disable
= regulator_disable_regmap
,
244 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
245 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
246 .set_voltage_time_sel
= s2mps11_regulator_set_voltage_time_sel
,
247 .set_ramp_delay
= s2mps11_set_ramp_delay
,
250 #define regulator_desc_s2mps11_ldo(num, step) { \
252 .id = S2MPS11_LDO##num, \
253 .ops = &s2mps11_ldo_ops, \
254 .type = REGULATOR_VOLTAGE, \
255 .owner = THIS_MODULE, \
256 .ramp_delay = RAMP_DELAY_12_MVUS, \
257 .min_uV = MIN_800_MV, \
259 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
260 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
261 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
262 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
263 .enable_mask = S2MPS11_ENABLE_MASK \
266 #define regulator_desc_s2mps11_buck1_4(num) { \
267 .name = "BUCK"#num, \
268 .id = S2MPS11_BUCK##num, \
269 .ops = &s2mps11_buck_ops, \
270 .type = REGULATOR_VOLTAGE, \
271 .owner = THIS_MODULE, \
272 .min_uV = MIN_600_MV, \
273 .uV_step = STEP_6_25_MV, \
274 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
275 .ramp_delay = S2MPS11_RAMP_DELAY, \
276 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
277 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
278 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
279 .enable_mask = S2MPS11_ENABLE_MASK \
282 #define regulator_desc_s2mps11_buck5 { \
284 .id = S2MPS11_BUCK5, \
285 .ops = &s2mps11_buck_ops, \
286 .type = REGULATOR_VOLTAGE, \
287 .owner = THIS_MODULE, \
288 .min_uV = MIN_600_MV, \
289 .uV_step = STEP_6_25_MV, \
290 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
291 .ramp_delay = S2MPS11_RAMP_DELAY, \
292 .vsel_reg = S2MPS11_REG_B5CTRL2, \
293 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
294 .enable_reg = S2MPS11_REG_B5CTRL1, \
295 .enable_mask = S2MPS11_ENABLE_MASK \
298 #define regulator_desc_s2mps11_buck67810(num, min, step) { \
299 .name = "BUCK"#num, \
300 .id = S2MPS11_BUCK##num, \
301 .ops = &s2mps11_buck_ops, \
302 .type = REGULATOR_VOLTAGE, \
303 .owner = THIS_MODULE, \
306 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
307 .ramp_delay = S2MPS11_RAMP_DELAY, \
308 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
309 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
310 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
311 .enable_mask = S2MPS11_ENABLE_MASK \
314 #define regulator_desc_s2mps11_buck9 { \
316 .id = S2MPS11_BUCK9, \
317 .ops = &s2mps11_buck_ops, \
318 .type = REGULATOR_VOLTAGE, \
319 .owner = THIS_MODULE, \
320 .min_uV = MIN_3000_MV, \
321 .uV_step = STEP_25_MV, \
322 .n_voltages = S2MPS11_BUCK9_N_VOLTAGES, \
323 .ramp_delay = S2MPS11_RAMP_DELAY, \
324 .vsel_reg = S2MPS11_REG_B9CTRL2, \
325 .vsel_mask = S2MPS11_BUCK9_VSEL_MASK, \
326 .enable_reg = S2MPS11_REG_B9CTRL1, \
327 .enable_mask = S2MPS11_ENABLE_MASK \
330 static const struct regulator_desc s2mps11_regulators
[] = {
331 regulator_desc_s2mps11_ldo(1, STEP_25_MV
),
332 regulator_desc_s2mps11_ldo(2, STEP_50_MV
),
333 regulator_desc_s2mps11_ldo(3, STEP_50_MV
),
334 regulator_desc_s2mps11_ldo(4, STEP_50_MV
),
335 regulator_desc_s2mps11_ldo(5, STEP_50_MV
),
336 regulator_desc_s2mps11_ldo(6, STEP_25_MV
),
337 regulator_desc_s2mps11_ldo(7, STEP_50_MV
),
338 regulator_desc_s2mps11_ldo(8, STEP_50_MV
),
339 regulator_desc_s2mps11_ldo(9, STEP_50_MV
),
340 regulator_desc_s2mps11_ldo(10, STEP_50_MV
),
341 regulator_desc_s2mps11_ldo(11, STEP_25_MV
),
342 regulator_desc_s2mps11_ldo(12, STEP_50_MV
),
343 regulator_desc_s2mps11_ldo(13, STEP_50_MV
),
344 regulator_desc_s2mps11_ldo(14, STEP_50_MV
),
345 regulator_desc_s2mps11_ldo(15, STEP_50_MV
),
346 regulator_desc_s2mps11_ldo(16, STEP_50_MV
),
347 regulator_desc_s2mps11_ldo(17, STEP_50_MV
),
348 regulator_desc_s2mps11_ldo(18, STEP_50_MV
),
349 regulator_desc_s2mps11_ldo(19, STEP_50_MV
),
350 regulator_desc_s2mps11_ldo(20, STEP_50_MV
),
351 regulator_desc_s2mps11_ldo(21, STEP_50_MV
),
352 regulator_desc_s2mps11_ldo(22, STEP_25_MV
),
353 regulator_desc_s2mps11_ldo(23, STEP_25_MV
),
354 regulator_desc_s2mps11_ldo(24, STEP_50_MV
),
355 regulator_desc_s2mps11_ldo(25, STEP_50_MV
),
356 regulator_desc_s2mps11_ldo(26, STEP_50_MV
),
357 regulator_desc_s2mps11_ldo(27, STEP_25_MV
),
358 regulator_desc_s2mps11_ldo(28, STEP_50_MV
),
359 regulator_desc_s2mps11_ldo(29, STEP_50_MV
),
360 regulator_desc_s2mps11_ldo(30, STEP_50_MV
),
361 regulator_desc_s2mps11_ldo(31, STEP_50_MV
),
362 regulator_desc_s2mps11_ldo(32, STEP_50_MV
),
363 regulator_desc_s2mps11_ldo(33, STEP_50_MV
),
364 regulator_desc_s2mps11_ldo(34, STEP_50_MV
),
365 regulator_desc_s2mps11_ldo(35, STEP_25_MV
),
366 regulator_desc_s2mps11_ldo(36, STEP_50_MV
),
367 regulator_desc_s2mps11_ldo(37, STEP_50_MV
),
368 regulator_desc_s2mps11_ldo(38, STEP_50_MV
),
369 regulator_desc_s2mps11_buck1_4(1),
370 regulator_desc_s2mps11_buck1_4(2),
371 regulator_desc_s2mps11_buck1_4(3),
372 regulator_desc_s2mps11_buck1_4(4),
373 regulator_desc_s2mps11_buck5
,
374 regulator_desc_s2mps11_buck67810(6, MIN_600_MV
, STEP_6_25_MV
),
375 regulator_desc_s2mps11_buck67810(7, MIN_600_MV
, STEP_12_5_MV
),
376 regulator_desc_s2mps11_buck67810(8, MIN_600_MV
, STEP_12_5_MV
),
377 regulator_desc_s2mps11_buck9
,
378 regulator_desc_s2mps11_buck67810(10, MIN_750_MV
, STEP_12_5_MV
),
381 static const struct regulator_ops s2mps14_reg_ops
;
383 #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
385 .id = S2MPS13_LDO##num, \
386 .ops = &s2mps14_reg_ops, \
387 .type = REGULATOR_VOLTAGE, \
388 .owner = THIS_MODULE, \
391 .linear_min_sel = min_sel, \
392 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
393 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
394 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
395 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
396 .enable_mask = S2MPS14_ENABLE_MASK \
399 #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
400 .name = "BUCK"#num, \
401 .id = S2MPS13_BUCK##num, \
402 .ops = &s2mps14_reg_ops, \
403 .type = REGULATOR_VOLTAGE, \
404 .owner = THIS_MODULE, \
407 .linear_min_sel = min_sel, \
408 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
409 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
410 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
411 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
412 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
413 .enable_mask = S2MPS14_ENABLE_MASK \
416 #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
417 .name = "BUCK"#num, \
418 .id = S2MPS13_BUCK##num, \
419 .ops = &s2mps14_reg_ops, \
420 .type = REGULATOR_VOLTAGE, \
421 .owner = THIS_MODULE, \
424 .linear_min_sel = min_sel, \
425 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
426 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
427 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
428 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
429 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
430 .enable_mask = S2MPS14_ENABLE_MASK \
433 #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
434 .name = "BUCK"#num, \
435 .id = S2MPS13_BUCK##num, \
436 .ops = &s2mps14_reg_ops, \
437 .type = REGULATOR_VOLTAGE, \
438 .owner = THIS_MODULE, \
441 .linear_min_sel = min_sel, \
442 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
443 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
444 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
445 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
446 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
447 .enable_mask = S2MPS14_ENABLE_MASK \
450 static const struct regulator_desc s2mps13_regulators
[] = {
451 regulator_desc_s2mps13_ldo(1, MIN_800_MV
, STEP_12_5_MV
, 0x00),
452 regulator_desc_s2mps13_ldo(2, MIN_1400_MV
, STEP_50_MV
, 0x0C),
453 regulator_desc_s2mps13_ldo(3, MIN_1000_MV
, STEP_25_MV
, 0x08),
454 regulator_desc_s2mps13_ldo(4, MIN_800_MV
, STEP_12_5_MV
, 0x00),
455 regulator_desc_s2mps13_ldo(5, MIN_800_MV
, STEP_12_5_MV
, 0x00),
456 regulator_desc_s2mps13_ldo(6, MIN_800_MV
, STEP_12_5_MV
, 0x00),
457 regulator_desc_s2mps13_ldo(7, MIN_1000_MV
, STEP_25_MV
, 0x08),
458 regulator_desc_s2mps13_ldo(8, MIN_1000_MV
, STEP_25_MV
, 0x08),
459 regulator_desc_s2mps13_ldo(9, MIN_1000_MV
, STEP_25_MV
, 0x08),
460 regulator_desc_s2mps13_ldo(10, MIN_1400_MV
, STEP_50_MV
, 0x0C),
461 regulator_desc_s2mps13_ldo(11, MIN_800_MV
, STEP_25_MV
, 0x10),
462 regulator_desc_s2mps13_ldo(12, MIN_800_MV
, STEP_25_MV
, 0x10),
463 regulator_desc_s2mps13_ldo(13, MIN_800_MV
, STEP_25_MV
, 0x10),
464 regulator_desc_s2mps13_ldo(14, MIN_800_MV
, STEP_12_5_MV
, 0x00),
465 regulator_desc_s2mps13_ldo(15, MIN_800_MV
, STEP_12_5_MV
, 0x00),
466 regulator_desc_s2mps13_ldo(16, MIN_1400_MV
, STEP_50_MV
, 0x0C),
467 regulator_desc_s2mps13_ldo(17, MIN_1400_MV
, STEP_50_MV
, 0x0C),
468 regulator_desc_s2mps13_ldo(18, MIN_1000_MV
, STEP_25_MV
, 0x08),
469 regulator_desc_s2mps13_ldo(19, MIN_1000_MV
, STEP_25_MV
, 0x08),
470 regulator_desc_s2mps13_ldo(20, MIN_1400_MV
, STEP_50_MV
, 0x0C),
471 regulator_desc_s2mps13_ldo(21, MIN_1000_MV
, STEP_25_MV
, 0x08),
472 regulator_desc_s2mps13_ldo(22, MIN_1000_MV
, STEP_25_MV
, 0x08),
473 regulator_desc_s2mps13_ldo(23, MIN_800_MV
, STEP_12_5_MV
, 0x00),
474 regulator_desc_s2mps13_ldo(24, MIN_800_MV
, STEP_12_5_MV
, 0x00),
475 regulator_desc_s2mps13_ldo(25, MIN_1400_MV
, STEP_50_MV
, 0x0C),
476 regulator_desc_s2mps13_ldo(26, MIN_1400_MV
, STEP_50_MV
, 0x0C),
477 regulator_desc_s2mps13_ldo(27, MIN_1400_MV
, STEP_50_MV
, 0x0C),
478 regulator_desc_s2mps13_ldo(28, MIN_1000_MV
, STEP_25_MV
, 0x08),
479 regulator_desc_s2mps13_ldo(29, MIN_1400_MV
, STEP_50_MV
, 0x0C),
480 regulator_desc_s2mps13_ldo(30, MIN_1400_MV
, STEP_50_MV
, 0x0C),
481 regulator_desc_s2mps13_ldo(31, MIN_1000_MV
, STEP_25_MV
, 0x08),
482 regulator_desc_s2mps13_ldo(32, MIN_1000_MV
, STEP_25_MV
, 0x08),
483 regulator_desc_s2mps13_ldo(33, MIN_1400_MV
, STEP_50_MV
, 0x0C),
484 regulator_desc_s2mps13_ldo(34, MIN_1000_MV
, STEP_25_MV
, 0x08),
485 regulator_desc_s2mps13_ldo(35, MIN_1400_MV
, STEP_50_MV
, 0x0C),
486 regulator_desc_s2mps13_ldo(36, MIN_800_MV
, STEP_12_5_MV
, 0x00),
487 regulator_desc_s2mps13_ldo(37, MIN_1000_MV
, STEP_25_MV
, 0x08),
488 regulator_desc_s2mps13_ldo(38, MIN_1400_MV
, STEP_50_MV
, 0x0C),
489 regulator_desc_s2mps13_ldo(39, MIN_1000_MV
, STEP_25_MV
, 0x08),
490 regulator_desc_s2mps13_ldo(40, MIN_1400_MV
, STEP_50_MV
, 0x0C),
491 regulator_desc_s2mps13_buck(1, MIN_500_MV
, STEP_6_25_MV
, 0x10),
492 regulator_desc_s2mps13_buck(2, MIN_500_MV
, STEP_6_25_MV
, 0x10),
493 regulator_desc_s2mps13_buck(3, MIN_500_MV
, STEP_6_25_MV
, 0x10),
494 regulator_desc_s2mps13_buck(4, MIN_500_MV
, STEP_6_25_MV
, 0x10),
495 regulator_desc_s2mps13_buck(5, MIN_500_MV
, STEP_6_25_MV
, 0x10),
496 regulator_desc_s2mps13_buck(6, MIN_500_MV
, STEP_6_25_MV
, 0x10),
497 regulator_desc_s2mps13_buck7(7, MIN_500_MV
, STEP_6_25_MV
, 0x10),
498 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV
, STEP_12_5_MV
, 0x20),
499 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV
, STEP_12_5_MV
, 0x20),
500 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV
, STEP_6_25_MV
, 0x10),
503 static int s2mps14_regulator_enable(struct regulator_dev
*rdev
)
505 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
508 switch (s2mps11
->dev_type
) {
511 if (test_bit(rdev_get_id(rdev
), s2mps11
->suspend_state
))
512 val
= S2MPS14_ENABLE_SUSPEND
;
513 else if (s2mps11
->ext_control_gpiod
[rdev_get_id(rdev
)])
514 val
= S2MPS14_ENABLE_EXT_CONTROL
;
516 val
= rdev
->desc
->enable_mask
;
519 if (test_bit(rdev_get_id(rdev
), s2mps11
->suspend_state
))
520 val
= S2MPU02_ENABLE_SUSPEND
;
522 val
= rdev
->desc
->enable_mask
;
528 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
529 rdev
->desc
->enable_mask
, val
);
532 static int s2mps14_regulator_set_suspend_disable(struct regulator_dev
*rdev
)
535 unsigned int val
, state
;
536 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
537 int rdev_id
= rdev_get_id(rdev
);
539 /* Below LDO should be always on or does not support suspend mode. */
540 switch (s2mps11
->dev_type
) {
547 state
= S2MPS14_ENABLE_SUSPEND
;
558 state
= S2MPU02_DISABLE_SUSPEND
;
561 state
= S2MPU02_ENABLE_SUSPEND
;
569 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->enable_reg
, &val
);
573 set_bit(rdev_get_id(rdev
), s2mps11
->suspend_state
);
575 * Don't enable suspend mode if regulator is already disabled because
576 * this would effectively for a short time turn on the regulator after
578 * However we still want to toggle the suspend_state bit for regulator
579 * in case if it got enabled before suspending the system.
581 if (!(val
& rdev
->desc
->enable_mask
))
584 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
585 rdev
->desc
->enable_mask
, state
);
588 static const struct regulator_ops s2mps14_reg_ops
= {
589 .list_voltage
= regulator_list_voltage_linear
,
590 .map_voltage
= regulator_map_voltage_linear
,
591 .is_enabled
= regulator_is_enabled_regmap
,
592 .enable
= s2mps14_regulator_enable
,
593 .disable
= regulator_disable_regmap
,
594 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
595 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
596 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
597 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
600 #define regulator_desc_s2mps14_ldo(num, min, step) { \
602 .id = S2MPS14_LDO##num, \
603 .ops = &s2mps14_reg_ops, \
604 .type = REGULATOR_VOLTAGE, \
605 .owner = THIS_MODULE, \
608 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
609 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
610 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
611 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
612 .enable_mask = S2MPS14_ENABLE_MASK \
615 #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
616 .name = "BUCK"#num, \
617 .id = S2MPS14_BUCK##num, \
618 .ops = &s2mps14_reg_ops, \
619 .type = REGULATOR_VOLTAGE, \
620 .owner = THIS_MODULE, \
623 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
624 .linear_min_sel = min_sel, \
625 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
626 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
627 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
628 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
629 .enable_mask = S2MPS14_ENABLE_MASK \
632 static const struct regulator_desc s2mps14_regulators
[] = {
633 regulator_desc_s2mps14_ldo(1, MIN_800_MV
, STEP_12_5_MV
),
634 regulator_desc_s2mps14_ldo(2, MIN_800_MV
, STEP_12_5_MV
),
635 regulator_desc_s2mps14_ldo(3, MIN_800_MV
, STEP_25_MV
),
636 regulator_desc_s2mps14_ldo(4, MIN_800_MV
, STEP_25_MV
),
637 regulator_desc_s2mps14_ldo(5, MIN_800_MV
, STEP_12_5_MV
),
638 regulator_desc_s2mps14_ldo(6, MIN_800_MV
, STEP_12_5_MV
),
639 regulator_desc_s2mps14_ldo(7, MIN_800_MV
, STEP_25_MV
),
640 regulator_desc_s2mps14_ldo(8, MIN_1800_MV
, STEP_25_MV
),
641 regulator_desc_s2mps14_ldo(9, MIN_800_MV
, STEP_12_5_MV
),
642 regulator_desc_s2mps14_ldo(10, MIN_800_MV
, STEP_12_5_MV
),
643 regulator_desc_s2mps14_ldo(11, MIN_800_MV
, STEP_25_MV
),
644 regulator_desc_s2mps14_ldo(12, MIN_1800_MV
, STEP_25_MV
),
645 regulator_desc_s2mps14_ldo(13, MIN_1800_MV
, STEP_25_MV
),
646 regulator_desc_s2mps14_ldo(14, MIN_1800_MV
, STEP_25_MV
),
647 regulator_desc_s2mps14_ldo(15, MIN_1800_MV
, STEP_25_MV
),
648 regulator_desc_s2mps14_ldo(16, MIN_1800_MV
, STEP_25_MV
),
649 regulator_desc_s2mps14_ldo(17, MIN_1800_MV
, STEP_25_MV
),
650 regulator_desc_s2mps14_ldo(18, MIN_1800_MV
, STEP_25_MV
),
651 regulator_desc_s2mps14_ldo(19, MIN_800_MV
, STEP_25_MV
),
652 regulator_desc_s2mps14_ldo(20, MIN_800_MV
, STEP_25_MV
),
653 regulator_desc_s2mps14_ldo(21, MIN_800_MV
, STEP_25_MV
),
654 regulator_desc_s2mps14_ldo(22, MIN_800_MV
, STEP_12_5_MV
),
655 regulator_desc_s2mps14_ldo(23, MIN_800_MV
, STEP_25_MV
),
656 regulator_desc_s2mps14_ldo(24, MIN_1800_MV
, STEP_25_MV
),
657 regulator_desc_s2mps14_ldo(25, MIN_1800_MV
, STEP_25_MV
),
658 regulator_desc_s2mps14_buck(1, MIN_600_MV
, STEP_6_25_MV
,
659 S2MPS14_BUCK1235_START_SEL
),
660 regulator_desc_s2mps14_buck(2, MIN_600_MV
, STEP_6_25_MV
,
661 S2MPS14_BUCK1235_START_SEL
),
662 regulator_desc_s2mps14_buck(3, MIN_600_MV
, STEP_6_25_MV
,
663 S2MPS14_BUCK1235_START_SEL
),
664 regulator_desc_s2mps14_buck(4, MIN_1400_MV
, STEP_12_5_MV
,
665 S2MPS14_BUCK4_START_SEL
),
666 regulator_desc_s2mps14_buck(5, MIN_600_MV
, STEP_6_25_MV
,
667 S2MPS14_BUCK1235_START_SEL
),
670 static const struct regulator_ops s2mps15_reg_ldo_ops
= {
671 .list_voltage
= regulator_list_voltage_linear_range
,
672 .map_voltage
= regulator_map_voltage_linear_range
,
673 .is_enabled
= regulator_is_enabled_regmap
,
674 .enable
= regulator_enable_regmap
,
675 .disable
= regulator_disable_regmap
,
676 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
677 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
680 static const struct regulator_ops s2mps15_reg_buck_ops
= {
681 .list_voltage
= regulator_list_voltage_linear_range
,
682 .map_voltage
= regulator_map_voltage_linear_range
,
683 .is_enabled
= regulator_is_enabled_regmap
,
684 .enable
= regulator_enable_regmap
,
685 .disable
= regulator_disable_regmap
,
686 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
687 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
688 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
691 #define regulator_desc_s2mps15_ldo(num, range) { \
693 .id = S2MPS15_LDO##num, \
694 .ops = &s2mps15_reg_ldo_ops, \
695 .type = REGULATOR_VOLTAGE, \
696 .owner = THIS_MODULE, \
697 .linear_ranges = range, \
698 .n_linear_ranges = ARRAY_SIZE(range), \
699 .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
700 .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
701 .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
702 .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
703 .enable_mask = S2MPS15_ENABLE_MASK \
706 #define regulator_desc_s2mps15_buck(num, range) { \
707 .name = "BUCK"#num, \
708 .id = S2MPS15_BUCK##num, \
709 .ops = &s2mps15_reg_buck_ops, \
710 .type = REGULATOR_VOLTAGE, \
711 .owner = THIS_MODULE, \
712 .linear_ranges = range, \
713 .n_linear_ranges = ARRAY_SIZE(range), \
714 .ramp_delay = 12500, \
715 .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
716 .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
717 .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
718 .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
719 .enable_mask = S2MPS15_ENABLE_MASK \
722 /* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
723 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges1
[] = {
724 REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
727 /* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
728 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges2
[] = {
729 REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
732 /* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
733 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges3
[] = {
734 REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
737 /* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
738 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges4
[] = {
739 REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000),
742 /* voltage range for s2mps15 LDO 1 */
743 static const struct regulator_linear_range s2mps15_ldo_voltage_ranges5
[] = {
744 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
747 /* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
748 static const struct regulator_linear_range s2mps15_buck_voltage_ranges1
[] = {
749 REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250),
752 /* voltage range for s2mps15 BUCK 8, 9 and 10 */
753 static const struct regulator_linear_range s2mps15_buck_voltage_ranges2
[] = {
754 REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500),
757 static const struct regulator_desc s2mps15_regulators
[] = {
758 regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5
),
759 regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2
),
760 regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1
),
761 regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3
),
762 regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1
),
763 regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2
),
764 regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4
),
765 regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4
),
766 regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4
),
767 regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4
),
768 regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3
),
769 regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3
),
770 regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3
),
771 regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2
),
772 regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1
),
773 regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1
),
774 regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2
),
775 regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1
),
776 regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2
),
777 regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1
),
778 regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2
),
779 regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3
),
780 regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1
),
781 regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2
),
782 regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2
),
783 regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3
),
784 regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1
),
785 regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1
),
786 regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1
),
787 regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1
),
788 regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1
),
789 regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1
),
790 regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1
),
791 regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1
),
792 regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2
),
793 regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2
),
794 regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2
),
797 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info
*s2mps11
,
798 struct regulator_dev
*rdev
)
800 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
801 rdev
->desc
->enable_mask
, S2MPS14_ENABLE_EXT_CONTROL
);
804 static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device
*pdev
,
805 struct of_regulator_match
*rdata
, struct s2mps11_info
*s2mps11
)
807 struct gpio_desc
**gpio
= s2mps11
->ext_control_gpiod
;
809 unsigned int valid_regulators
[3] = { S2MPS14_LDO10
, S2MPS14_LDO11
,
812 for (i
= 0; i
< ARRAY_SIZE(valid_regulators
); i
++) {
813 unsigned int reg
= valid_regulators
[i
];
815 if (!rdata
[reg
].init_data
|| !rdata
[reg
].of_node
)
818 gpio
[reg
] = devm_gpiod_get_from_of_node(&pdev
->dev
,
820 "samsung,ext-control-gpios",
822 GPIOD_OUT_HIGH
| GPIOD_FLAGS_BIT_NONEXCLUSIVE
,
823 "s2mps11-regulator");
824 if (IS_ERR(gpio
[reg
])) {
825 dev_err(&pdev
->dev
, "Failed to get control GPIO for %d/%s\n",
826 reg
, rdata
[reg
].name
);
830 dev_dbg(&pdev
->dev
, "Using GPIO for ext-control over %d/%s\n",
831 reg
, rdata
[reg
].name
);
835 static int s2mps11_pmic_dt_parse(struct platform_device
*pdev
,
836 struct of_regulator_match
*rdata
, struct s2mps11_info
*s2mps11
,
837 unsigned int rdev_num
)
839 struct device_node
*reg_np
;
841 reg_np
= of_get_child_by_name(pdev
->dev
.parent
->of_node
, "regulators");
843 dev_err(&pdev
->dev
, "could not find regulators sub-node\n");
847 of_regulator_match(&pdev
->dev
, reg_np
, rdata
, rdev_num
);
848 if (s2mps11
->dev_type
== S2MPS14X
)
849 s2mps14_pmic_dt_parse_ext_control_gpio(pdev
, rdata
, s2mps11
);
856 static int s2mpu02_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
858 unsigned int ramp_val
, ramp_shift
, ramp_reg
;
860 switch (rdev_get_id(rdev
)) {
862 ramp_shift
= S2MPU02_BUCK1_RAMP_SHIFT
;
865 ramp_shift
= S2MPU02_BUCK2_RAMP_SHIFT
;
868 ramp_shift
= S2MPU02_BUCK3_RAMP_SHIFT
;
871 ramp_shift
= S2MPU02_BUCK4_RAMP_SHIFT
;
876 ramp_reg
= S2MPU02_REG_RAMP1
;
877 ramp_val
= get_ramp_delay(ramp_delay
);
879 return regmap_update_bits(rdev
->regmap
, ramp_reg
,
880 S2MPU02_BUCK1234_RAMP_MASK
<< ramp_shift
,
881 ramp_val
<< ramp_shift
);
884 static const struct regulator_ops s2mpu02_ldo_ops
= {
885 .list_voltage
= regulator_list_voltage_linear
,
886 .map_voltage
= regulator_map_voltage_linear
,
887 .is_enabled
= regulator_is_enabled_regmap
,
888 .enable
= s2mps14_regulator_enable
,
889 .disable
= regulator_disable_regmap
,
890 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
891 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
892 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
893 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
896 static const struct regulator_ops s2mpu02_buck_ops
= {
897 .list_voltage
= regulator_list_voltage_linear
,
898 .map_voltage
= regulator_map_voltage_linear
,
899 .is_enabled
= regulator_is_enabled_regmap
,
900 .enable
= s2mps14_regulator_enable
,
901 .disable
= regulator_disable_regmap
,
902 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
903 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
904 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
905 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
906 .set_ramp_delay
= s2mpu02_set_ramp_delay
,
909 #define regulator_desc_s2mpu02_ldo1(num) { \
911 .id = S2MPU02_LDO##num, \
912 .ops = &s2mpu02_ldo_ops, \
913 .type = REGULATOR_VOLTAGE, \
914 .owner = THIS_MODULE, \
915 .min_uV = S2MPU02_LDO_MIN_900MV, \
916 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
917 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
918 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
919 .vsel_reg = S2MPU02_REG_L1CTRL, \
920 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
921 .enable_reg = S2MPU02_REG_L1CTRL, \
922 .enable_mask = S2MPU02_ENABLE_MASK \
924 #define regulator_desc_s2mpu02_ldo2(num) { \
926 .id = S2MPU02_LDO##num, \
927 .ops = &s2mpu02_ldo_ops, \
928 .type = REGULATOR_VOLTAGE, \
929 .owner = THIS_MODULE, \
930 .min_uV = S2MPU02_LDO_MIN_1050MV, \
931 .uV_step = S2MPU02_LDO_STEP_25MV, \
932 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
933 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
934 .vsel_reg = S2MPU02_REG_L2CTRL1, \
935 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
936 .enable_reg = S2MPU02_REG_L2CTRL1, \
937 .enable_mask = S2MPU02_ENABLE_MASK \
939 #define regulator_desc_s2mpu02_ldo3(num) { \
941 .id = S2MPU02_LDO##num, \
942 .ops = &s2mpu02_ldo_ops, \
943 .type = REGULATOR_VOLTAGE, \
944 .owner = THIS_MODULE, \
945 .min_uV = S2MPU02_LDO_MIN_900MV, \
946 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
947 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
948 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
949 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
950 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
951 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
952 .enable_mask = S2MPU02_ENABLE_MASK \
954 #define regulator_desc_s2mpu02_ldo4(num) { \
956 .id = S2MPU02_LDO##num, \
957 .ops = &s2mpu02_ldo_ops, \
958 .type = REGULATOR_VOLTAGE, \
959 .owner = THIS_MODULE, \
960 .min_uV = S2MPU02_LDO_MIN_1050MV, \
961 .uV_step = S2MPU02_LDO_STEP_25MV, \
962 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
963 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
964 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
965 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
966 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
967 .enable_mask = S2MPU02_ENABLE_MASK \
969 #define regulator_desc_s2mpu02_ldo5(num) { \
971 .id = S2MPU02_LDO##num, \
972 .ops = &s2mpu02_ldo_ops, \
973 .type = REGULATOR_VOLTAGE, \
974 .owner = THIS_MODULE, \
975 .min_uV = S2MPU02_LDO_MIN_1600MV, \
976 .uV_step = S2MPU02_LDO_STEP_50MV, \
977 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
978 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
979 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
980 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
981 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
982 .enable_mask = S2MPU02_ENABLE_MASK \
985 #define regulator_desc_s2mpu02_buck1234(num) { \
986 .name = "BUCK"#num, \
987 .id = S2MPU02_BUCK##num, \
988 .ops = &s2mpu02_buck_ops, \
989 .type = REGULATOR_VOLTAGE, \
990 .owner = THIS_MODULE, \
991 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
992 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
993 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
994 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
995 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
996 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
997 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
998 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
999 .enable_mask = S2MPU02_ENABLE_MASK \
1001 #define regulator_desc_s2mpu02_buck5(num) { \
1002 .name = "BUCK"#num, \
1003 .id = S2MPU02_BUCK##num, \
1004 .ops = &s2mpu02_ldo_ops, \
1005 .type = REGULATOR_VOLTAGE, \
1006 .owner = THIS_MODULE, \
1007 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
1008 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
1009 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1010 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
1011 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1012 .vsel_reg = S2MPU02_REG_B5CTRL2, \
1013 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1014 .enable_reg = S2MPU02_REG_B5CTRL1, \
1015 .enable_mask = S2MPU02_ENABLE_MASK \
1017 #define regulator_desc_s2mpu02_buck6(num) { \
1018 .name = "BUCK"#num, \
1019 .id = S2MPU02_BUCK##num, \
1020 .ops = &s2mpu02_ldo_ops, \
1021 .type = REGULATOR_VOLTAGE, \
1022 .owner = THIS_MODULE, \
1023 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
1024 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
1025 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1026 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
1027 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1028 .vsel_reg = S2MPU02_REG_B6CTRL2, \
1029 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1030 .enable_reg = S2MPU02_REG_B6CTRL1, \
1031 .enable_mask = S2MPU02_ENABLE_MASK \
1033 #define regulator_desc_s2mpu02_buck7(num) { \
1034 .name = "BUCK"#num, \
1035 .id = S2MPU02_BUCK##num, \
1036 .ops = &s2mpu02_ldo_ops, \
1037 .type = REGULATOR_VOLTAGE, \
1038 .owner = THIS_MODULE, \
1039 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
1040 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
1041 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
1042 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
1043 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
1044 .vsel_reg = S2MPU02_REG_B7CTRL2, \
1045 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
1046 .enable_reg = S2MPU02_REG_B7CTRL1, \
1047 .enable_mask = S2MPU02_ENABLE_MASK \
1050 static const struct regulator_desc s2mpu02_regulators
[] = {
1051 regulator_desc_s2mpu02_ldo1(1),
1052 regulator_desc_s2mpu02_ldo2(2),
1053 regulator_desc_s2mpu02_ldo4(3),
1054 regulator_desc_s2mpu02_ldo5(4),
1055 regulator_desc_s2mpu02_ldo4(5),
1056 regulator_desc_s2mpu02_ldo3(6),
1057 regulator_desc_s2mpu02_ldo3(7),
1058 regulator_desc_s2mpu02_ldo4(8),
1059 regulator_desc_s2mpu02_ldo5(9),
1060 regulator_desc_s2mpu02_ldo3(10),
1061 regulator_desc_s2mpu02_ldo4(11),
1062 regulator_desc_s2mpu02_ldo5(12),
1063 regulator_desc_s2mpu02_ldo5(13),
1064 regulator_desc_s2mpu02_ldo5(14),
1065 regulator_desc_s2mpu02_ldo5(15),
1066 regulator_desc_s2mpu02_ldo5(16),
1067 regulator_desc_s2mpu02_ldo4(17),
1068 regulator_desc_s2mpu02_ldo5(18),
1069 regulator_desc_s2mpu02_ldo3(19),
1070 regulator_desc_s2mpu02_ldo4(20),
1071 regulator_desc_s2mpu02_ldo5(21),
1072 regulator_desc_s2mpu02_ldo5(22),
1073 regulator_desc_s2mpu02_ldo5(23),
1074 regulator_desc_s2mpu02_ldo4(24),
1075 regulator_desc_s2mpu02_ldo5(25),
1076 regulator_desc_s2mpu02_ldo4(26),
1077 regulator_desc_s2mpu02_ldo5(27),
1078 regulator_desc_s2mpu02_ldo5(28),
1079 regulator_desc_s2mpu02_buck1234(1),
1080 regulator_desc_s2mpu02_buck1234(2),
1081 regulator_desc_s2mpu02_buck1234(3),
1082 regulator_desc_s2mpu02_buck1234(4),
1083 regulator_desc_s2mpu02_buck5(5),
1084 regulator_desc_s2mpu02_buck6(6),
1085 regulator_desc_s2mpu02_buck7(7),
1088 static int s2mps11_pmic_probe(struct platform_device
*pdev
)
1090 struct sec_pmic_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
1091 struct sec_platform_data
*pdata
= NULL
;
1092 struct of_regulator_match
*rdata
= NULL
;
1093 struct regulator_config config
= { };
1094 struct s2mps11_info
*s2mps11
;
1095 unsigned int rdev_num
= 0;
1097 const struct regulator_desc
*regulators
;
1099 s2mps11
= devm_kzalloc(&pdev
->dev
, sizeof(struct s2mps11_info
),
1104 s2mps11
->dev_type
= platform_get_device_id(pdev
)->driver_data
;
1105 switch (s2mps11
->dev_type
) {
1107 rdev_num
= ARRAY_SIZE(s2mps11_regulators
);
1108 regulators
= s2mps11_regulators
;
1109 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< ARRAY_SIZE(s2mps11_regulators
));
1112 rdev_num
= ARRAY_SIZE(s2mps13_regulators
);
1113 regulators
= s2mps13_regulators
;
1114 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< ARRAY_SIZE(s2mps13_regulators
));
1117 rdev_num
= ARRAY_SIZE(s2mps14_regulators
);
1118 regulators
= s2mps14_regulators
;
1119 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< ARRAY_SIZE(s2mps14_regulators
));
1122 rdev_num
= ARRAY_SIZE(s2mps15_regulators
);
1123 regulators
= s2mps15_regulators
;
1124 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< ARRAY_SIZE(s2mps15_regulators
));
1127 rdev_num
= ARRAY_SIZE(s2mpu02_regulators
);
1128 regulators
= s2mpu02_regulators
;
1129 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< ARRAY_SIZE(s2mpu02_regulators
));
1132 dev_err(&pdev
->dev
, "Invalid device type: %u\n",
1137 s2mps11
->ext_control_gpiod
= devm_kcalloc(&pdev
->dev
, rdev_num
,
1138 sizeof(*s2mps11
->ext_control_gpiod
), GFP_KERNEL
);
1139 if (!s2mps11
->ext_control_gpiod
)
1142 if (!iodev
->dev
->of_node
) {
1144 pdata
= iodev
->pdata
;
1147 dev_err(pdev
->dev
.parent
,
1148 "Platform data or DT node not supplied\n");
1153 rdata
= kcalloc(rdev_num
, sizeof(*rdata
), GFP_KERNEL
);
1157 for (i
= 0; i
< rdev_num
; i
++)
1158 rdata
[i
].name
= regulators
[i
].name
;
1160 ret
= s2mps11_pmic_dt_parse(pdev
, rdata
, s2mps11
, rdev_num
);
1165 platform_set_drvdata(pdev
, s2mps11
);
1167 config
.dev
= &pdev
->dev
;
1168 config
.regmap
= iodev
->regmap_pmic
;
1169 config
.driver_data
= s2mps11
;
1170 for (i
= 0; i
< rdev_num
; i
++) {
1171 struct regulator_dev
*regulator
;
1174 config
.init_data
= pdata
->regulators
[i
].initdata
;
1175 config
.of_node
= pdata
->regulators
[i
].reg_node
;
1177 config
.init_data
= rdata
[i
].init_data
;
1178 config
.of_node
= rdata
[i
].of_node
;
1180 config
.ena_gpiod
= s2mps11
->ext_control_gpiod
[i
];
1182 * Hand the GPIO descriptor management over to the regulator
1183 * core, remove it from devres management.
1185 if (config
.ena_gpiod
)
1186 devm_gpiod_unhinge(&pdev
->dev
, config
.ena_gpiod
);
1187 regulator
= devm_regulator_register(&pdev
->dev
,
1188 ®ulators
[i
], &config
);
1189 if (IS_ERR(regulator
)) {
1190 ret
= PTR_ERR(regulator
);
1191 dev_err(&pdev
->dev
, "regulator init failed for %d\n",
1196 if (s2mps11
->ext_control_gpiod
[i
]) {
1197 ret
= s2mps14_pmic_enable_ext_control(s2mps11
,
1201 "failed to enable GPIO control over %s: %d\n",
1202 regulator
->desc
->name
, ret
);
1214 static const struct platform_device_id s2mps11_pmic_id
[] = {
1215 { "s2mps11-regulator", S2MPS11X
},
1216 { "s2mps13-regulator", S2MPS13X
},
1217 { "s2mps14-regulator", S2MPS14X
},
1218 { "s2mps15-regulator", S2MPS15X
},
1219 { "s2mpu02-regulator", S2MPU02
},
1222 MODULE_DEVICE_TABLE(platform
, s2mps11_pmic_id
);
1224 static struct platform_driver s2mps11_pmic_driver
= {
1226 .name
= "s2mps11-pmic",
1228 .probe
= s2mps11_pmic_probe
,
1229 .id_table
= s2mps11_pmic_id
,
1232 module_platform_driver(s2mps11_pmic_driver
);
1234 /* Module information */
1235 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
1236 MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
1237 MODULE_LICENSE("GPL");