4 * Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/bug.h>
20 #include <linux/err.h>
21 #include <linux/gpio.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
25 #include <linux/regmap.h>
26 #include <linux/platform_device.h>
27 #include <linux/regulator/driver.h>
28 #include <linux/regulator/machine.h>
29 #include <linux/regulator/of_regulator.h>
30 #include <linux/of_gpio.h>
31 #include <linux/mfd/samsung/core.h>
32 #include <linux/mfd/samsung/s2mps11.h>
33 #include <linux/mfd/samsung/s2mps13.h>
34 #include <linux/mfd/samsung/s2mps14.h>
35 #include <linux/mfd/samsung/s2mpu02.h>
38 unsigned int rdev_num
;
46 enum sec_device_type dev_type
;
49 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
50 * the suspend mode was enabled.
52 unsigned long long s2mps14_suspend_state
:50;
54 /* Array of size rdev_num with GPIO-s for external sleep control */
55 int *ext_control_gpio
;
58 static int get_ramp_delay(int ramp_delay
)
60 unsigned char cnt
= 0;
65 ramp_delay
= ramp_delay
>> 1;
77 static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev
*rdev
,
78 unsigned int old_selector
,
79 unsigned int new_selector
)
81 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
82 unsigned int ramp_delay
= 0;
83 int old_volt
, new_volt
;
85 switch (rdev_get_id(rdev
)) {
87 ramp_delay
= s2mps11
->ramp_delay2
;
91 ramp_delay
= s2mps11
->ramp_delay34
;
94 ramp_delay
= s2mps11
->ramp_delay5
;
98 ramp_delay
= s2mps11
->ramp_delay16
;
103 ramp_delay
= s2mps11
->ramp_delay7810
;
106 ramp_delay
= s2mps11
->ramp_delay9
;
110 ramp_delay
= rdev
->desc
->ramp_delay
;
112 old_volt
= rdev
->desc
->min_uV
+ (rdev
->desc
->uV_step
* old_selector
);
113 new_volt
= rdev
->desc
->min_uV
+ (rdev
->desc
->uV_step
* new_selector
);
115 return DIV_ROUND_UP(abs(new_volt
- old_volt
), ramp_delay
);
118 static int s2mps11_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
120 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
121 unsigned int ramp_val
, ramp_shift
, ramp_reg
= S2MPS11_REG_RAMP_BUCK
;
122 unsigned int ramp_enable
= 1, enable_shift
= 0;
125 switch (rdev_get_id(rdev
)) {
127 if (ramp_delay
> s2mps11
->ramp_delay16
)
128 s2mps11
->ramp_delay16
= ramp_delay
;
130 ramp_delay
= s2mps11
->ramp_delay16
;
132 ramp_shift
= S2MPS11_BUCK16_RAMP_SHIFT
;
135 enable_shift
= S2MPS11_BUCK2_RAMP_EN_SHIFT
;
141 s2mps11
->ramp_delay2
= ramp_delay
;
142 ramp_shift
= S2MPS11_BUCK2_RAMP_SHIFT
;
143 ramp_reg
= S2MPS11_REG_RAMP
;
146 enable_shift
= S2MPS11_BUCK3_RAMP_EN_SHIFT
;
152 if (ramp_delay
> s2mps11
->ramp_delay34
)
153 s2mps11
->ramp_delay34
= ramp_delay
;
155 ramp_delay
= s2mps11
->ramp_delay34
;
157 ramp_shift
= S2MPS11_BUCK34_RAMP_SHIFT
;
158 ramp_reg
= S2MPS11_REG_RAMP
;
161 enable_shift
= S2MPS11_BUCK4_RAMP_EN_SHIFT
;
167 if (ramp_delay
> s2mps11
->ramp_delay34
)
168 s2mps11
->ramp_delay34
= ramp_delay
;
170 ramp_delay
= s2mps11
->ramp_delay34
;
172 ramp_shift
= S2MPS11_BUCK34_RAMP_SHIFT
;
173 ramp_reg
= S2MPS11_REG_RAMP
;
176 s2mps11
->ramp_delay5
= ramp_delay
;
177 ramp_shift
= S2MPS11_BUCK5_RAMP_SHIFT
;
180 enable_shift
= S2MPS11_BUCK6_RAMP_EN_SHIFT
;
186 if (ramp_delay
> s2mps11
->ramp_delay16
)
187 s2mps11
->ramp_delay16
= ramp_delay
;
189 ramp_delay
= s2mps11
->ramp_delay16
;
191 ramp_shift
= S2MPS11_BUCK16_RAMP_SHIFT
;
196 if (ramp_delay
> s2mps11
->ramp_delay7810
)
197 s2mps11
->ramp_delay7810
= ramp_delay
;
199 ramp_delay
= s2mps11
->ramp_delay7810
;
201 ramp_shift
= S2MPS11_BUCK7810_RAMP_SHIFT
;
204 s2mps11
->ramp_delay9
= ramp_delay
;
205 ramp_shift
= S2MPS11_BUCK9_RAMP_SHIFT
;
214 /* Ramp delay can be enabled/disabled only for buck[2346] */
215 if ((rdev_get_id(rdev
) >= S2MPS11_BUCK2
&&
216 rdev_get_id(rdev
) <= S2MPS11_BUCK4
) ||
217 rdev_get_id(rdev
) == S2MPS11_BUCK6
) {
218 ret
= regmap_update_bits(rdev
->regmap
, S2MPS11_REG_RAMP
,
219 1 << enable_shift
, 1 << enable_shift
);
221 dev_err(&rdev
->dev
, "failed to enable ramp rate\n");
226 ramp_val
= get_ramp_delay(ramp_delay
);
228 return regmap_update_bits(rdev
->regmap
, ramp_reg
, 0x3 << ramp_shift
,
229 ramp_val
<< ramp_shift
);
232 return regmap_update_bits(rdev
->regmap
, S2MPS11_REG_RAMP
,
233 1 << enable_shift
, 0);
236 static struct regulator_ops s2mps11_ldo_ops
= {
237 .list_voltage
= regulator_list_voltage_linear
,
238 .map_voltage
= regulator_map_voltage_linear
,
239 .is_enabled
= regulator_is_enabled_regmap
,
240 .enable
= regulator_enable_regmap
,
241 .disable
= regulator_disable_regmap
,
242 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
243 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
244 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
247 static struct regulator_ops s2mps11_buck_ops
= {
248 .list_voltage
= regulator_list_voltage_linear
,
249 .map_voltage
= regulator_map_voltage_linear
,
250 .is_enabled
= regulator_is_enabled_regmap
,
251 .enable
= regulator_enable_regmap
,
252 .disable
= regulator_disable_regmap
,
253 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
254 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
255 .set_voltage_time_sel
= s2mps11_regulator_set_voltage_time_sel
,
256 .set_ramp_delay
= s2mps11_set_ramp_delay
,
259 #define regulator_desc_s2mps11_ldo(num, step) { \
261 .id = S2MPS11_LDO##num, \
262 .ops = &s2mps11_ldo_ops, \
263 .type = REGULATOR_VOLTAGE, \
264 .owner = THIS_MODULE, \
265 .min_uV = MIN_800_MV, \
267 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
268 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
269 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
270 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
271 .enable_mask = S2MPS11_ENABLE_MASK \
274 #define regulator_desc_s2mps11_buck1_4(num) { \
275 .name = "BUCK"#num, \
276 .id = S2MPS11_BUCK##num, \
277 .ops = &s2mps11_buck_ops, \
278 .type = REGULATOR_VOLTAGE, \
279 .owner = THIS_MODULE, \
280 .min_uV = MIN_600_MV, \
281 .uV_step = STEP_6_25_MV, \
282 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
283 .ramp_delay = S2MPS11_RAMP_DELAY, \
284 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
285 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
286 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
287 .enable_mask = S2MPS11_ENABLE_MASK \
290 #define regulator_desc_s2mps11_buck5 { \
292 .id = S2MPS11_BUCK5, \
293 .ops = &s2mps11_buck_ops, \
294 .type = REGULATOR_VOLTAGE, \
295 .owner = THIS_MODULE, \
296 .min_uV = MIN_600_MV, \
297 .uV_step = STEP_6_25_MV, \
298 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
299 .ramp_delay = S2MPS11_RAMP_DELAY, \
300 .vsel_reg = S2MPS11_REG_B5CTRL2, \
301 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
302 .enable_reg = S2MPS11_REG_B5CTRL1, \
303 .enable_mask = S2MPS11_ENABLE_MASK \
306 #define regulator_desc_s2mps11_buck6_10(num, min, step) { \
307 .name = "BUCK"#num, \
308 .id = S2MPS11_BUCK##num, \
309 .ops = &s2mps11_buck_ops, \
310 .type = REGULATOR_VOLTAGE, \
311 .owner = THIS_MODULE, \
314 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
315 .ramp_delay = S2MPS11_RAMP_DELAY, \
316 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
317 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
318 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
319 .enable_mask = S2MPS11_ENABLE_MASK \
322 static const struct regulator_desc s2mps11_regulators
[] = {
323 regulator_desc_s2mps11_ldo(1, STEP_25_MV
),
324 regulator_desc_s2mps11_ldo(2, STEP_50_MV
),
325 regulator_desc_s2mps11_ldo(3, STEP_50_MV
),
326 regulator_desc_s2mps11_ldo(4, STEP_50_MV
),
327 regulator_desc_s2mps11_ldo(5, STEP_50_MV
),
328 regulator_desc_s2mps11_ldo(6, STEP_25_MV
),
329 regulator_desc_s2mps11_ldo(7, STEP_50_MV
),
330 regulator_desc_s2mps11_ldo(8, STEP_50_MV
),
331 regulator_desc_s2mps11_ldo(9, STEP_50_MV
),
332 regulator_desc_s2mps11_ldo(10, STEP_50_MV
),
333 regulator_desc_s2mps11_ldo(11, STEP_25_MV
),
334 regulator_desc_s2mps11_ldo(12, STEP_50_MV
),
335 regulator_desc_s2mps11_ldo(13, STEP_50_MV
),
336 regulator_desc_s2mps11_ldo(14, STEP_50_MV
),
337 regulator_desc_s2mps11_ldo(15, STEP_50_MV
),
338 regulator_desc_s2mps11_ldo(16, STEP_50_MV
),
339 regulator_desc_s2mps11_ldo(17, STEP_50_MV
),
340 regulator_desc_s2mps11_ldo(18, STEP_50_MV
),
341 regulator_desc_s2mps11_ldo(19, STEP_50_MV
),
342 regulator_desc_s2mps11_ldo(20, STEP_50_MV
),
343 regulator_desc_s2mps11_ldo(21, STEP_50_MV
),
344 regulator_desc_s2mps11_ldo(22, STEP_25_MV
),
345 regulator_desc_s2mps11_ldo(23, STEP_25_MV
),
346 regulator_desc_s2mps11_ldo(24, STEP_50_MV
),
347 regulator_desc_s2mps11_ldo(25, STEP_50_MV
),
348 regulator_desc_s2mps11_ldo(26, STEP_50_MV
),
349 regulator_desc_s2mps11_ldo(27, STEP_25_MV
),
350 regulator_desc_s2mps11_ldo(28, STEP_50_MV
),
351 regulator_desc_s2mps11_ldo(29, STEP_50_MV
),
352 regulator_desc_s2mps11_ldo(30, STEP_50_MV
),
353 regulator_desc_s2mps11_ldo(31, STEP_50_MV
),
354 regulator_desc_s2mps11_ldo(32, STEP_50_MV
),
355 regulator_desc_s2mps11_ldo(33, STEP_50_MV
),
356 regulator_desc_s2mps11_ldo(34, STEP_50_MV
),
357 regulator_desc_s2mps11_ldo(35, STEP_50_MV
),
358 regulator_desc_s2mps11_ldo(36, STEP_50_MV
),
359 regulator_desc_s2mps11_ldo(37, STEP_50_MV
),
360 regulator_desc_s2mps11_ldo(38, STEP_50_MV
),
361 regulator_desc_s2mps11_buck1_4(1),
362 regulator_desc_s2mps11_buck1_4(2),
363 regulator_desc_s2mps11_buck1_4(3),
364 regulator_desc_s2mps11_buck1_4(4),
365 regulator_desc_s2mps11_buck5
,
366 regulator_desc_s2mps11_buck6_10(6, MIN_600_MV
, STEP_6_25_MV
),
367 regulator_desc_s2mps11_buck6_10(7, MIN_600_MV
, STEP_6_25_MV
),
368 regulator_desc_s2mps11_buck6_10(8, MIN_600_MV
, STEP_6_25_MV
),
369 regulator_desc_s2mps11_buck6_10(9, MIN_3000_MV
, STEP_25_MV
),
370 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV
, STEP_12_5_MV
),
373 static struct regulator_ops s2mps14_reg_ops
;
375 #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
377 .id = S2MPS13_LDO##num, \
378 .ops = &s2mps14_reg_ops, \
379 .type = REGULATOR_VOLTAGE, \
380 .owner = THIS_MODULE, \
383 .linear_min_sel = min_sel, \
384 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
385 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
386 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
387 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
388 .enable_mask = S2MPS14_ENABLE_MASK \
391 #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
392 .name = "BUCK"#num, \
393 .id = S2MPS13_BUCK##num, \
394 .ops = &s2mps14_reg_ops, \
395 .type = REGULATOR_VOLTAGE, \
396 .owner = THIS_MODULE, \
399 .linear_min_sel = min_sel, \
400 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
401 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
402 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
403 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
404 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
405 .enable_mask = S2MPS14_ENABLE_MASK \
408 #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
409 .name = "BUCK"#num, \
410 .id = S2MPS13_BUCK##num, \
411 .ops = &s2mps14_reg_ops, \
412 .type = REGULATOR_VOLTAGE, \
413 .owner = THIS_MODULE, \
416 .linear_min_sel = min_sel, \
417 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
418 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
419 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
420 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
421 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
422 .enable_mask = S2MPS14_ENABLE_MASK \
425 #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
426 .name = "BUCK"#num, \
427 .id = S2MPS13_BUCK##num, \
428 .ops = &s2mps14_reg_ops, \
429 .type = REGULATOR_VOLTAGE, \
430 .owner = THIS_MODULE, \
433 .linear_min_sel = min_sel, \
434 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
435 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
436 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
437 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
438 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
439 .enable_mask = S2MPS14_ENABLE_MASK \
442 static const struct regulator_desc s2mps13_regulators
[] = {
443 regulator_desc_s2mps13_ldo(1, MIN_800_MV
, STEP_12_5_MV
, 0x00),
444 regulator_desc_s2mps13_ldo(2, MIN_1400_MV
, STEP_50_MV
, 0x0C),
445 regulator_desc_s2mps13_ldo(3, MIN_1000_MV
, STEP_25_MV
, 0x08),
446 regulator_desc_s2mps13_ldo(4, MIN_800_MV
, STEP_12_5_MV
, 0x00),
447 regulator_desc_s2mps13_ldo(5, MIN_800_MV
, STEP_12_5_MV
, 0x00),
448 regulator_desc_s2mps13_ldo(6, MIN_800_MV
, STEP_12_5_MV
, 0x00),
449 regulator_desc_s2mps13_ldo(7, MIN_1000_MV
, STEP_25_MV
, 0x08),
450 regulator_desc_s2mps13_ldo(8, MIN_1000_MV
, STEP_25_MV
, 0x08),
451 regulator_desc_s2mps13_ldo(9, MIN_1000_MV
, STEP_25_MV
, 0x08),
452 regulator_desc_s2mps13_ldo(10, MIN_1400_MV
, STEP_50_MV
, 0x0C),
453 regulator_desc_s2mps13_ldo(11, MIN_800_MV
, STEP_25_MV
, 0x10),
454 regulator_desc_s2mps13_ldo(12, MIN_800_MV
, STEP_25_MV
, 0x10),
455 regulator_desc_s2mps13_ldo(13, MIN_800_MV
, STEP_25_MV
, 0x10),
456 regulator_desc_s2mps13_ldo(14, MIN_800_MV
, STEP_12_5_MV
, 0x00),
457 regulator_desc_s2mps13_ldo(15, MIN_800_MV
, STEP_12_5_MV
, 0x00),
458 regulator_desc_s2mps13_ldo(16, MIN_1400_MV
, STEP_50_MV
, 0x0C),
459 regulator_desc_s2mps13_ldo(17, MIN_1400_MV
, STEP_50_MV
, 0x0C),
460 regulator_desc_s2mps13_ldo(18, MIN_1000_MV
, STEP_25_MV
, 0x08),
461 regulator_desc_s2mps13_ldo(19, MIN_1000_MV
, STEP_25_MV
, 0x08),
462 regulator_desc_s2mps13_ldo(20, MIN_1400_MV
, STEP_50_MV
, 0x0C),
463 regulator_desc_s2mps13_ldo(21, MIN_1000_MV
, STEP_25_MV
, 0x08),
464 regulator_desc_s2mps13_ldo(22, MIN_1000_MV
, STEP_25_MV
, 0x08),
465 regulator_desc_s2mps13_ldo(23, MIN_800_MV
, STEP_12_5_MV
, 0x00),
466 regulator_desc_s2mps13_ldo(24, MIN_800_MV
, STEP_12_5_MV
, 0x00),
467 regulator_desc_s2mps13_ldo(25, MIN_1400_MV
, STEP_50_MV
, 0x0C),
468 regulator_desc_s2mps13_ldo(26, MIN_1400_MV
, STEP_50_MV
, 0x0C),
469 regulator_desc_s2mps13_ldo(27, MIN_1400_MV
, STEP_50_MV
, 0x0C),
470 regulator_desc_s2mps13_ldo(28, MIN_1000_MV
, STEP_25_MV
, 0x08),
471 regulator_desc_s2mps13_ldo(29, MIN_1400_MV
, STEP_50_MV
, 0x0C),
472 regulator_desc_s2mps13_ldo(30, MIN_1400_MV
, STEP_50_MV
, 0x0C),
473 regulator_desc_s2mps13_ldo(31, MIN_1000_MV
, STEP_25_MV
, 0x08),
474 regulator_desc_s2mps13_ldo(32, MIN_1000_MV
, STEP_25_MV
, 0x08),
475 regulator_desc_s2mps13_ldo(33, MIN_1400_MV
, STEP_50_MV
, 0x0C),
476 regulator_desc_s2mps13_ldo(34, MIN_1000_MV
, STEP_25_MV
, 0x08),
477 regulator_desc_s2mps13_ldo(35, MIN_1400_MV
, STEP_50_MV
, 0x0C),
478 regulator_desc_s2mps13_ldo(36, MIN_800_MV
, STEP_12_5_MV
, 0x00),
479 regulator_desc_s2mps13_ldo(37, MIN_1000_MV
, STEP_25_MV
, 0x08),
480 regulator_desc_s2mps13_ldo(38, MIN_1400_MV
, STEP_50_MV
, 0x0C),
481 regulator_desc_s2mps13_ldo(39, MIN_1000_MV
, STEP_25_MV
, 0x08),
482 regulator_desc_s2mps13_ldo(40, MIN_1400_MV
, STEP_50_MV
, 0x0C),
483 regulator_desc_s2mps13_buck(1, MIN_500_MV
, STEP_6_25_MV
, 0x10),
484 regulator_desc_s2mps13_buck(2, MIN_500_MV
, STEP_6_25_MV
, 0x10),
485 regulator_desc_s2mps13_buck(3, MIN_500_MV
, STEP_6_25_MV
, 0x10),
486 regulator_desc_s2mps13_buck(4, MIN_500_MV
, STEP_6_25_MV
, 0x10),
487 regulator_desc_s2mps13_buck(5, MIN_500_MV
, STEP_6_25_MV
, 0x10),
488 regulator_desc_s2mps13_buck(6, MIN_500_MV
, STEP_6_25_MV
, 0x10),
489 regulator_desc_s2mps13_buck7(7, MIN_500_MV
, STEP_6_25_MV
, 0x10),
490 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV
, STEP_12_5_MV
, 0x20),
491 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV
, STEP_12_5_MV
, 0x20),
492 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV
, STEP_6_25_MV
, 0x10),
495 static int s2mps14_regulator_enable(struct regulator_dev
*rdev
)
497 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
500 switch (s2mps11
->dev_type
) {
503 if (s2mps11
->s2mps14_suspend_state
& (1 << rdev_get_id(rdev
)))
504 val
= S2MPS14_ENABLE_SUSPEND
;
505 else if (gpio_is_valid(s2mps11
->ext_control_gpio
[rdev_get_id(rdev
)]))
506 val
= S2MPS14_ENABLE_EXT_CONTROL
;
508 val
= rdev
->desc
->enable_mask
;
511 if (s2mps11
->s2mps14_suspend_state
& (1 << rdev_get_id(rdev
)))
512 val
= S2MPU02_ENABLE_SUSPEND
;
514 val
= rdev
->desc
->enable_mask
;
520 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
521 rdev
->desc
->enable_mask
, val
);
524 static int s2mps14_regulator_set_suspend_disable(struct regulator_dev
*rdev
)
527 unsigned int val
, state
;
528 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
529 int rdev_id
= rdev_get_id(rdev
);
531 /* Below LDO should be always on or does not support suspend mode. */
532 switch (s2mps11
->dev_type
) {
539 state
= S2MPS14_ENABLE_SUSPEND
;
550 state
= S2MPU02_DISABLE_SUSPEND
;
553 state
= S2MPU02_ENABLE_SUSPEND
;
561 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->enable_reg
, &val
);
565 s2mps11
->s2mps14_suspend_state
|= (1 << rdev_get_id(rdev
));
567 * Don't enable suspend mode if regulator is already disabled because
568 * this would effectively for a short time turn on the regulator after
570 * However we still want to toggle the suspend_state bit for regulator
571 * in case if it got enabled before suspending the system.
573 if (!(val
& rdev
->desc
->enable_mask
))
576 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
577 rdev
->desc
->enable_mask
, state
);
580 static struct regulator_ops s2mps14_reg_ops
= {
581 .list_voltage
= regulator_list_voltage_linear
,
582 .map_voltage
= regulator_map_voltage_linear
,
583 .is_enabled
= regulator_is_enabled_regmap
,
584 .enable
= s2mps14_regulator_enable
,
585 .disable
= regulator_disable_regmap
,
586 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
587 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
588 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
589 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
592 #define regulator_desc_s2mps14_ldo(num, min, step) { \
594 .id = S2MPS14_LDO##num, \
595 .ops = &s2mps14_reg_ops, \
596 .type = REGULATOR_VOLTAGE, \
597 .owner = THIS_MODULE, \
600 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
601 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
602 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
603 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
604 .enable_mask = S2MPS14_ENABLE_MASK \
607 #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
608 .name = "BUCK"#num, \
609 .id = S2MPS14_BUCK##num, \
610 .ops = &s2mps14_reg_ops, \
611 .type = REGULATOR_VOLTAGE, \
612 .owner = THIS_MODULE, \
615 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
616 .linear_min_sel = min_sel, \
617 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
618 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
619 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
620 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
621 .enable_mask = S2MPS14_ENABLE_MASK \
624 static const struct regulator_desc s2mps14_regulators
[] = {
625 regulator_desc_s2mps14_ldo(1, MIN_800_MV
, STEP_12_5_MV
),
626 regulator_desc_s2mps14_ldo(2, MIN_800_MV
, STEP_12_5_MV
),
627 regulator_desc_s2mps14_ldo(3, MIN_800_MV
, STEP_25_MV
),
628 regulator_desc_s2mps14_ldo(4, MIN_800_MV
, STEP_25_MV
),
629 regulator_desc_s2mps14_ldo(5, MIN_800_MV
, STEP_12_5_MV
),
630 regulator_desc_s2mps14_ldo(6, MIN_800_MV
, STEP_12_5_MV
),
631 regulator_desc_s2mps14_ldo(7, MIN_800_MV
, STEP_25_MV
),
632 regulator_desc_s2mps14_ldo(8, MIN_1800_MV
, STEP_25_MV
),
633 regulator_desc_s2mps14_ldo(9, MIN_800_MV
, STEP_12_5_MV
),
634 regulator_desc_s2mps14_ldo(10, MIN_800_MV
, STEP_12_5_MV
),
635 regulator_desc_s2mps14_ldo(11, MIN_800_MV
, STEP_25_MV
),
636 regulator_desc_s2mps14_ldo(12, MIN_1800_MV
, STEP_25_MV
),
637 regulator_desc_s2mps14_ldo(13, MIN_1800_MV
, STEP_25_MV
),
638 regulator_desc_s2mps14_ldo(14, MIN_1800_MV
, STEP_25_MV
),
639 regulator_desc_s2mps14_ldo(15, MIN_1800_MV
, STEP_25_MV
),
640 regulator_desc_s2mps14_ldo(16, MIN_1800_MV
, STEP_25_MV
),
641 regulator_desc_s2mps14_ldo(17, MIN_1800_MV
, STEP_25_MV
),
642 regulator_desc_s2mps14_ldo(18, MIN_1800_MV
, STEP_25_MV
),
643 regulator_desc_s2mps14_ldo(19, MIN_800_MV
, STEP_25_MV
),
644 regulator_desc_s2mps14_ldo(20, MIN_800_MV
, STEP_25_MV
),
645 regulator_desc_s2mps14_ldo(21, MIN_800_MV
, STEP_25_MV
),
646 regulator_desc_s2mps14_ldo(22, MIN_800_MV
, STEP_12_5_MV
),
647 regulator_desc_s2mps14_ldo(23, MIN_800_MV
, STEP_25_MV
),
648 regulator_desc_s2mps14_ldo(24, MIN_1800_MV
, STEP_25_MV
),
649 regulator_desc_s2mps14_ldo(25, MIN_1800_MV
, STEP_25_MV
),
650 regulator_desc_s2mps14_buck(1, MIN_600_MV
, STEP_6_25_MV
,
651 S2MPS14_BUCK1235_START_SEL
),
652 regulator_desc_s2mps14_buck(2, MIN_600_MV
, STEP_6_25_MV
,
653 S2MPS14_BUCK1235_START_SEL
),
654 regulator_desc_s2mps14_buck(3, MIN_600_MV
, STEP_6_25_MV
,
655 S2MPS14_BUCK1235_START_SEL
),
656 regulator_desc_s2mps14_buck(4, MIN_1400_MV
, STEP_12_5_MV
,
657 S2MPS14_BUCK4_START_SEL
),
658 regulator_desc_s2mps14_buck(5, MIN_600_MV
, STEP_6_25_MV
,
659 S2MPS14_BUCK1235_START_SEL
),
662 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info
*s2mps11
,
663 struct regulator_dev
*rdev
)
665 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
666 rdev
->desc
->enable_mask
, S2MPS14_ENABLE_EXT_CONTROL
);
669 static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device
*pdev
,
670 struct of_regulator_match
*rdata
, struct s2mps11_info
*s2mps11
)
672 int *gpio
= s2mps11
->ext_control_gpio
;
674 unsigned int valid_regulators
[3] = { S2MPS14_LDO10
, S2MPS14_LDO11
,
677 for (i
= 0; i
< ARRAY_SIZE(valid_regulators
); i
++) {
678 unsigned int reg
= valid_regulators
[i
];
680 if (!rdata
[reg
].init_data
|| !rdata
[reg
].of_node
)
683 gpio
[reg
] = of_get_named_gpio(rdata
[reg
].of_node
,
684 "samsung,ext-control-gpios", 0);
685 if (gpio_is_valid(gpio
[reg
]))
686 dev_dbg(&pdev
->dev
, "Using GPIO %d for ext-control over %d/%s\n",
687 gpio
[reg
], reg
, rdata
[reg
].name
);
691 static int s2mps11_pmic_dt_parse(struct platform_device
*pdev
,
692 struct of_regulator_match
*rdata
, struct s2mps11_info
*s2mps11
)
694 struct device_node
*reg_np
;
696 reg_np
= of_get_child_by_name(pdev
->dev
.parent
->of_node
, "regulators");
698 dev_err(&pdev
->dev
, "could not find regulators sub-node\n");
702 of_regulator_match(&pdev
->dev
, reg_np
, rdata
, s2mps11
->rdev_num
);
703 if (s2mps11
->dev_type
== S2MPS14X
)
704 s2mps14_pmic_dt_parse_ext_control_gpio(pdev
, rdata
, s2mps11
);
711 static int s2mpu02_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
713 unsigned int ramp_val
, ramp_shift
, ramp_reg
;
715 switch (rdev_get_id(rdev
)) {
717 ramp_shift
= S2MPU02_BUCK1_RAMP_SHIFT
;
720 ramp_shift
= S2MPU02_BUCK2_RAMP_SHIFT
;
723 ramp_shift
= S2MPU02_BUCK3_RAMP_SHIFT
;
726 ramp_shift
= S2MPU02_BUCK4_RAMP_SHIFT
;
731 ramp_reg
= S2MPU02_REG_RAMP1
;
732 ramp_val
= get_ramp_delay(ramp_delay
);
734 return regmap_update_bits(rdev
->regmap
, ramp_reg
,
735 S2MPU02_BUCK1234_RAMP_MASK
<< ramp_shift
,
736 ramp_val
<< ramp_shift
);
739 static struct regulator_ops s2mpu02_ldo_ops
= {
740 .list_voltage
= regulator_list_voltage_linear
,
741 .map_voltage
= regulator_map_voltage_linear
,
742 .is_enabled
= regulator_is_enabled_regmap
,
743 .enable
= s2mps14_regulator_enable
,
744 .disable
= regulator_disable_regmap
,
745 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
746 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
747 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
748 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
751 static struct regulator_ops s2mpu02_buck_ops
= {
752 .list_voltage
= regulator_list_voltage_linear
,
753 .map_voltage
= regulator_map_voltage_linear
,
754 .is_enabled
= regulator_is_enabled_regmap
,
755 .enable
= s2mps14_regulator_enable
,
756 .disable
= regulator_disable_regmap
,
757 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
758 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
759 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
760 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
761 .set_ramp_delay
= s2mpu02_set_ramp_delay
,
764 #define regulator_desc_s2mpu02_ldo1(num) { \
766 .id = S2MPU02_LDO##num, \
767 .ops = &s2mpu02_ldo_ops, \
768 .type = REGULATOR_VOLTAGE, \
769 .owner = THIS_MODULE, \
770 .min_uV = S2MPU02_LDO_MIN_900MV, \
771 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
772 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
773 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
774 .vsel_reg = S2MPU02_REG_L1CTRL, \
775 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
776 .enable_reg = S2MPU02_REG_L1CTRL, \
777 .enable_mask = S2MPU02_ENABLE_MASK \
779 #define regulator_desc_s2mpu02_ldo2(num) { \
781 .id = S2MPU02_LDO##num, \
782 .ops = &s2mpu02_ldo_ops, \
783 .type = REGULATOR_VOLTAGE, \
784 .owner = THIS_MODULE, \
785 .min_uV = S2MPU02_LDO_MIN_1050MV, \
786 .uV_step = S2MPU02_LDO_STEP_25MV, \
787 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
788 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
789 .vsel_reg = S2MPU02_REG_L2CTRL1, \
790 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
791 .enable_reg = S2MPU02_REG_L2CTRL1, \
792 .enable_mask = S2MPU02_ENABLE_MASK \
794 #define regulator_desc_s2mpu02_ldo3(num) { \
796 .id = S2MPU02_LDO##num, \
797 .ops = &s2mpu02_ldo_ops, \
798 .type = REGULATOR_VOLTAGE, \
799 .owner = THIS_MODULE, \
800 .min_uV = S2MPU02_LDO_MIN_900MV, \
801 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
802 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
803 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
804 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
805 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
806 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
807 .enable_mask = S2MPU02_ENABLE_MASK \
809 #define regulator_desc_s2mpu02_ldo4(num) { \
811 .id = S2MPU02_LDO##num, \
812 .ops = &s2mpu02_ldo_ops, \
813 .type = REGULATOR_VOLTAGE, \
814 .owner = THIS_MODULE, \
815 .min_uV = S2MPU02_LDO_MIN_1050MV, \
816 .uV_step = S2MPU02_LDO_STEP_25MV, \
817 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
818 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
819 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
820 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
821 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
822 .enable_mask = S2MPU02_ENABLE_MASK \
824 #define regulator_desc_s2mpu02_ldo5(num) { \
826 .id = S2MPU02_LDO##num, \
827 .ops = &s2mpu02_ldo_ops, \
828 .type = REGULATOR_VOLTAGE, \
829 .owner = THIS_MODULE, \
830 .min_uV = S2MPU02_LDO_MIN_1600MV, \
831 .uV_step = S2MPU02_LDO_STEP_50MV, \
832 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
833 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
834 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
835 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
836 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
837 .enable_mask = S2MPU02_ENABLE_MASK \
840 #define regulator_desc_s2mpu02_buck1234(num) { \
841 .name = "BUCK"#num, \
842 .id = S2MPU02_BUCK##num, \
843 .ops = &s2mpu02_buck_ops, \
844 .type = REGULATOR_VOLTAGE, \
845 .owner = THIS_MODULE, \
846 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
847 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
848 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
849 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
850 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
851 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
852 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
853 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
854 .enable_mask = S2MPU02_ENABLE_MASK \
856 #define regulator_desc_s2mpu02_buck5(num) { \
857 .name = "BUCK"#num, \
858 .id = S2MPU02_BUCK##num, \
859 .ops = &s2mpu02_ldo_ops, \
860 .type = REGULATOR_VOLTAGE, \
861 .owner = THIS_MODULE, \
862 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
863 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
864 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
865 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
866 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
867 .vsel_reg = S2MPU02_REG_B5CTRL2, \
868 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
869 .enable_reg = S2MPU02_REG_B5CTRL1, \
870 .enable_mask = S2MPU02_ENABLE_MASK \
872 #define regulator_desc_s2mpu02_buck6(num) { \
873 .name = "BUCK"#num, \
874 .id = S2MPU02_BUCK##num, \
875 .ops = &s2mpu02_ldo_ops, \
876 .type = REGULATOR_VOLTAGE, \
877 .owner = THIS_MODULE, \
878 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
879 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
880 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
881 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
882 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
883 .vsel_reg = S2MPU02_REG_B6CTRL2, \
884 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
885 .enable_reg = S2MPU02_REG_B6CTRL1, \
886 .enable_mask = S2MPU02_ENABLE_MASK \
888 #define regulator_desc_s2mpu02_buck7(num) { \
889 .name = "BUCK"#num, \
890 .id = S2MPU02_BUCK##num, \
891 .ops = &s2mpu02_ldo_ops, \
892 .type = REGULATOR_VOLTAGE, \
893 .owner = THIS_MODULE, \
894 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
895 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
896 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
897 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
898 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
899 .vsel_reg = S2MPU02_REG_B7CTRL2, \
900 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
901 .enable_reg = S2MPU02_REG_B7CTRL1, \
902 .enable_mask = S2MPU02_ENABLE_MASK \
905 static const struct regulator_desc s2mpu02_regulators
[] = {
906 regulator_desc_s2mpu02_ldo1(1),
907 regulator_desc_s2mpu02_ldo2(2),
908 regulator_desc_s2mpu02_ldo4(3),
909 regulator_desc_s2mpu02_ldo5(4),
910 regulator_desc_s2mpu02_ldo4(5),
911 regulator_desc_s2mpu02_ldo3(6),
912 regulator_desc_s2mpu02_ldo3(7),
913 regulator_desc_s2mpu02_ldo4(8),
914 regulator_desc_s2mpu02_ldo5(9),
915 regulator_desc_s2mpu02_ldo3(10),
916 regulator_desc_s2mpu02_ldo4(11),
917 regulator_desc_s2mpu02_ldo5(12),
918 regulator_desc_s2mpu02_ldo5(13),
919 regulator_desc_s2mpu02_ldo5(14),
920 regulator_desc_s2mpu02_ldo5(15),
921 regulator_desc_s2mpu02_ldo5(16),
922 regulator_desc_s2mpu02_ldo4(17),
923 regulator_desc_s2mpu02_ldo5(18),
924 regulator_desc_s2mpu02_ldo3(19),
925 regulator_desc_s2mpu02_ldo4(20),
926 regulator_desc_s2mpu02_ldo5(21),
927 regulator_desc_s2mpu02_ldo5(22),
928 regulator_desc_s2mpu02_ldo5(23),
929 regulator_desc_s2mpu02_ldo4(24),
930 regulator_desc_s2mpu02_ldo5(25),
931 regulator_desc_s2mpu02_ldo4(26),
932 regulator_desc_s2mpu02_ldo5(27),
933 regulator_desc_s2mpu02_ldo5(28),
934 regulator_desc_s2mpu02_buck1234(1),
935 regulator_desc_s2mpu02_buck1234(2),
936 regulator_desc_s2mpu02_buck1234(3),
937 regulator_desc_s2mpu02_buck1234(4),
938 regulator_desc_s2mpu02_buck5(5),
939 regulator_desc_s2mpu02_buck6(6),
940 regulator_desc_s2mpu02_buck7(7),
943 static int s2mps11_pmic_probe(struct platform_device
*pdev
)
945 struct sec_pmic_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
946 struct sec_platform_data
*pdata
= NULL
;
947 struct of_regulator_match
*rdata
= NULL
;
948 struct regulator_config config
= { };
949 struct s2mps11_info
*s2mps11
;
951 const struct regulator_desc
*regulators
;
953 s2mps11
= devm_kzalloc(&pdev
->dev
, sizeof(struct s2mps11_info
),
958 s2mps11
->dev_type
= platform_get_device_id(pdev
)->driver_data
;
959 switch (s2mps11
->dev_type
) {
961 s2mps11
->rdev_num
= ARRAY_SIZE(s2mps11_regulators
);
962 regulators
= s2mps11_regulators
;
965 s2mps11
->rdev_num
= ARRAY_SIZE(s2mps13_regulators
);
966 regulators
= s2mps13_regulators
;
969 s2mps11
->rdev_num
= ARRAY_SIZE(s2mps14_regulators
);
970 regulators
= s2mps14_regulators
;
973 s2mps11
->rdev_num
= ARRAY_SIZE(s2mpu02_regulators
);
974 regulators
= s2mpu02_regulators
;
977 dev_err(&pdev
->dev
, "Invalid device type: %u\n",
982 s2mps11
->ext_control_gpio
= devm_kmalloc(&pdev
->dev
,
983 sizeof(*s2mps11
->ext_control_gpio
) * s2mps11
->rdev_num
,
985 if (!s2mps11
->ext_control_gpio
)
988 * 0 is a valid GPIO so initialize all GPIO-s to negative value
989 * to indicate that external control won't be used for this regulator.
991 for (i
= 0; i
< s2mps11
->rdev_num
; i
++)
992 s2mps11
->ext_control_gpio
[i
] = -EINVAL
;
994 if (!iodev
->dev
->of_node
) {
996 pdata
= iodev
->pdata
;
999 dev_err(pdev
->dev
.parent
,
1000 "Platform data or DT node not supplied\n");
1005 rdata
= kzalloc(sizeof(*rdata
) * s2mps11
->rdev_num
, GFP_KERNEL
);
1009 for (i
= 0; i
< s2mps11
->rdev_num
; i
++)
1010 rdata
[i
].name
= regulators
[i
].name
;
1012 ret
= s2mps11_pmic_dt_parse(pdev
, rdata
, s2mps11
);
1017 platform_set_drvdata(pdev
, s2mps11
);
1019 config
.dev
= &pdev
->dev
;
1020 config
.regmap
= iodev
->regmap_pmic
;
1021 config
.driver_data
= s2mps11
;
1022 config
.ena_gpio_flags
= GPIOF_OUT_INIT_HIGH
;
1023 config
.ena_gpio_initialized
= true;
1024 for (i
= 0; i
< s2mps11
->rdev_num
; i
++) {
1025 struct regulator_dev
*regulator
;
1028 config
.init_data
= pdata
->regulators
[i
].initdata
;
1029 config
.of_node
= pdata
->regulators
[i
].reg_node
;
1031 config
.init_data
= rdata
[i
].init_data
;
1032 config
.of_node
= rdata
[i
].of_node
;
1034 config
.ena_gpio
= s2mps11
->ext_control_gpio
[i
];
1036 regulator
= devm_regulator_register(&pdev
->dev
,
1037 ®ulators
[i
], &config
);
1038 if (IS_ERR(regulator
)) {
1039 ret
= PTR_ERR(regulator
);
1040 dev_err(&pdev
->dev
, "regulator init failed for %d\n",
1045 if (gpio_is_valid(s2mps11
->ext_control_gpio
[i
])) {
1046 ret
= s2mps14_pmic_enable_ext_control(s2mps11
,
1050 "failed to enable GPIO control over %s: %d\n",
1051 regulator
->desc
->name
, ret
);
1063 static const struct platform_device_id s2mps11_pmic_id
[] = {
1064 { "s2mps11-pmic", S2MPS11X
},
1065 { "s2mps13-pmic", S2MPS13X
},
1066 { "s2mps14-pmic", S2MPS14X
},
1067 { "s2mpu02-pmic", S2MPU02
},
1070 MODULE_DEVICE_TABLE(platform
, s2mps11_pmic_id
);
1072 static struct platform_driver s2mps11_pmic_driver
= {
1074 .name
= "s2mps11-pmic",
1076 .probe
= s2mps11_pmic_probe
,
1077 .id_table
= s2mps11_pmic_id
,
1080 static int __init
s2mps11_pmic_init(void)
1082 return platform_driver_register(&s2mps11_pmic_driver
);
1084 subsys_initcall(s2mps11_pmic_init
);
1086 static void __exit
s2mps11_pmic_exit(void)
1088 platform_driver_unregister(&s2mps11_pmic_driver
);
1090 module_exit(s2mps11_pmic_exit
);
1092 /* Module information */
1093 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
1094 MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPU02 Regulator Driver");
1095 MODULE_LICENSE("GPL");