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>
37 /* The highest number of possible regulators for supported devices. */
38 #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX
40 unsigned int rdev_num
;
48 enum sec_device_type dev_type
;
51 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
52 * the suspend mode was enabled.
54 DECLARE_BITMAP(suspend_state
, S2MPS_REGULATOR_MAX
);
56 /* Array of size rdev_num with GPIO-s for external sleep control */
57 int *ext_control_gpio
;
60 static int get_ramp_delay(int ramp_delay
)
62 unsigned char cnt
= 0;
67 ramp_delay
= ramp_delay
>> 1;
79 static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev
*rdev
,
80 unsigned int old_selector
,
81 unsigned int new_selector
)
83 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
84 unsigned int ramp_delay
= 0;
85 int old_volt
, new_volt
;
87 switch (rdev_get_id(rdev
)) {
89 ramp_delay
= s2mps11
->ramp_delay2
;
93 ramp_delay
= s2mps11
->ramp_delay34
;
96 ramp_delay
= s2mps11
->ramp_delay5
;
100 ramp_delay
= s2mps11
->ramp_delay16
;
105 ramp_delay
= s2mps11
->ramp_delay7810
;
108 ramp_delay
= s2mps11
->ramp_delay9
;
112 ramp_delay
= rdev
->desc
->ramp_delay
;
114 old_volt
= rdev
->desc
->min_uV
+ (rdev
->desc
->uV_step
* old_selector
);
115 new_volt
= rdev
->desc
->min_uV
+ (rdev
->desc
->uV_step
* new_selector
);
117 return DIV_ROUND_UP(abs(new_volt
- old_volt
), ramp_delay
);
120 static int s2mps11_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
122 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
123 unsigned int ramp_val
, ramp_shift
, ramp_reg
= S2MPS11_REG_RAMP_BUCK
;
124 unsigned int ramp_enable
= 1, enable_shift
= 0;
127 switch (rdev_get_id(rdev
)) {
129 if (ramp_delay
> s2mps11
->ramp_delay16
)
130 s2mps11
->ramp_delay16
= ramp_delay
;
132 ramp_delay
= s2mps11
->ramp_delay16
;
134 ramp_shift
= S2MPS11_BUCK16_RAMP_SHIFT
;
137 enable_shift
= S2MPS11_BUCK2_RAMP_EN_SHIFT
;
143 s2mps11
->ramp_delay2
= ramp_delay
;
144 ramp_shift
= S2MPS11_BUCK2_RAMP_SHIFT
;
145 ramp_reg
= S2MPS11_REG_RAMP
;
148 enable_shift
= S2MPS11_BUCK3_RAMP_EN_SHIFT
;
154 if (ramp_delay
> s2mps11
->ramp_delay34
)
155 s2mps11
->ramp_delay34
= ramp_delay
;
157 ramp_delay
= s2mps11
->ramp_delay34
;
159 ramp_shift
= S2MPS11_BUCK34_RAMP_SHIFT
;
160 ramp_reg
= S2MPS11_REG_RAMP
;
163 enable_shift
= S2MPS11_BUCK4_RAMP_EN_SHIFT
;
169 if (ramp_delay
> s2mps11
->ramp_delay34
)
170 s2mps11
->ramp_delay34
= ramp_delay
;
172 ramp_delay
= s2mps11
->ramp_delay34
;
174 ramp_shift
= S2MPS11_BUCK34_RAMP_SHIFT
;
175 ramp_reg
= S2MPS11_REG_RAMP
;
178 s2mps11
->ramp_delay5
= ramp_delay
;
179 ramp_shift
= S2MPS11_BUCK5_RAMP_SHIFT
;
182 enable_shift
= S2MPS11_BUCK6_RAMP_EN_SHIFT
;
188 if (ramp_delay
> s2mps11
->ramp_delay16
)
189 s2mps11
->ramp_delay16
= ramp_delay
;
191 ramp_delay
= s2mps11
->ramp_delay16
;
193 ramp_shift
= S2MPS11_BUCK16_RAMP_SHIFT
;
198 if (ramp_delay
> s2mps11
->ramp_delay7810
)
199 s2mps11
->ramp_delay7810
= ramp_delay
;
201 ramp_delay
= s2mps11
->ramp_delay7810
;
203 ramp_shift
= S2MPS11_BUCK7810_RAMP_SHIFT
;
206 s2mps11
->ramp_delay9
= ramp_delay
;
207 ramp_shift
= S2MPS11_BUCK9_RAMP_SHIFT
;
216 /* Ramp delay can be enabled/disabled only for buck[2346] */
217 if ((rdev_get_id(rdev
) >= S2MPS11_BUCK2
&&
218 rdev_get_id(rdev
) <= S2MPS11_BUCK4
) ||
219 rdev_get_id(rdev
) == S2MPS11_BUCK6
) {
220 ret
= regmap_update_bits(rdev
->regmap
, S2MPS11_REG_RAMP
,
221 1 << enable_shift
, 1 << enable_shift
);
223 dev_err(&rdev
->dev
, "failed to enable ramp rate\n");
228 ramp_val
= get_ramp_delay(ramp_delay
);
230 return regmap_update_bits(rdev
->regmap
, ramp_reg
, 0x3 << ramp_shift
,
231 ramp_val
<< ramp_shift
);
234 return regmap_update_bits(rdev
->regmap
, S2MPS11_REG_RAMP
,
235 1 << enable_shift
, 0);
238 static struct regulator_ops s2mps11_ldo_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
= regulator_set_voltage_time_sel
,
249 static struct regulator_ops s2mps11_buck_ops
= {
250 .list_voltage
= regulator_list_voltage_linear
,
251 .map_voltage
= regulator_map_voltage_linear
,
252 .is_enabled
= regulator_is_enabled_regmap
,
253 .enable
= regulator_enable_regmap
,
254 .disable
= regulator_disable_regmap
,
255 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
256 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
257 .set_voltage_time_sel
= s2mps11_regulator_set_voltage_time_sel
,
258 .set_ramp_delay
= s2mps11_set_ramp_delay
,
261 #define regulator_desc_s2mps11_ldo(num, step) { \
263 .id = S2MPS11_LDO##num, \
264 .ops = &s2mps11_ldo_ops, \
265 .type = REGULATOR_VOLTAGE, \
266 .owner = THIS_MODULE, \
267 .min_uV = MIN_800_MV, \
269 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
270 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
271 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
272 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
273 .enable_mask = S2MPS11_ENABLE_MASK \
276 #define regulator_desc_s2mps11_buck1_4(num) { \
277 .name = "BUCK"#num, \
278 .id = S2MPS11_BUCK##num, \
279 .ops = &s2mps11_buck_ops, \
280 .type = REGULATOR_VOLTAGE, \
281 .owner = THIS_MODULE, \
282 .min_uV = MIN_600_MV, \
283 .uV_step = STEP_6_25_MV, \
284 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
285 .ramp_delay = S2MPS11_RAMP_DELAY, \
286 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
287 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
288 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
289 .enable_mask = S2MPS11_ENABLE_MASK \
292 #define regulator_desc_s2mps11_buck5 { \
294 .id = S2MPS11_BUCK5, \
295 .ops = &s2mps11_buck_ops, \
296 .type = REGULATOR_VOLTAGE, \
297 .owner = THIS_MODULE, \
298 .min_uV = MIN_600_MV, \
299 .uV_step = STEP_6_25_MV, \
300 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
301 .ramp_delay = S2MPS11_RAMP_DELAY, \
302 .vsel_reg = S2MPS11_REG_B5CTRL2, \
303 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
304 .enable_reg = S2MPS11_REG_B5CTRL1, \
305 .enable_mask = S2MPS11_ENABLE_MASK \
308 #define regulator_desc_s2mps11_buck6_10(num, min, step) { \
309 .name = "BUCK"#num, \
310 .id = S2MPS11_BUCK##num, \
311 .ops = &s2mps11_buck_ops, \
312 .type = REGULATOR_VOLTAGE, \
313 .owner = THIS_MODULE, \
316 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
317 .ramp_delay = S2MPS11_RAMP_DELAY, \
318 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
319 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
320 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
321 .enable_mask = S2MPS11_ENABLE_MASK \
324 static const struct regulator_desc s2mps11_regulators
[] = {
325 regulator_desc_s2mps11_ldo(1, STEP_25_MV
),
326 regulator_desc_s2mps11_ldo(2, STEP_50_MV
),
327 regulator_desc_s2mps11_ldo(3, STEP_50_MV
),
328 regulator_desc_s2mps11_ldo(4, STEP_50_MV
),
329 regulator_desc_s2mps11_ldo(5, STEP_50_MV
),
330 regulator_desc_s2mps11_ldo(6, STEP_25_MV
),
331 regulator_desc_s2mps11_ldo(7, STEP_50_MV
),
332 regulator_desc_s2mps11_ldo(8, STEP_50_MV
),
333 regulator_desc_s2mps11_ldo(9, STEP_50_MV
),
334 regulator_desc_s2mps11_ldo(10, STEP_50_MV
),
335 regulator_desc_s2mps11_ldo(11, STEP_25_MV
),
336 regulator_desc_s2mps11_ldo(12, STEP_50_MV
),
337 regulator_desc_s2mps11_ldo(13, STEP_50_MV
),
338 regulator_desc_s2mps11_ldo(14, STEP_50_MV
),
339 regulator_desc_s2mps11_ldo(15, STEP_50_MV
),
340 regulator_desc_s2mps11_ldo(16, STEP_50_MV
),
341 regulator_desc_s2mps11_ldo(17, STEP_50_MV
),
342 regulator_desc_s2mps11_ldo(18, STEP_50_MV
),
343 regulator_desc_s2mps11_ldo(19, STEP_50_MV
),
344 regulator_desc_s2mps11_ldo(20, STEP_50_MV
),
345 regulator_desc_s2mps11_ldo(21, STEP_50_MV
),
346 regulator_desc_s2mps11_ldo(22, STEP_25_MV
),
347 regulator_desc_s2mps11_ldo(23, STEP_25_MV
),
348 regulator_desc_s2mps11_ldo(24, STEP_50_MV
),
349 regulator_desc_s2mps11_ldo(25, STEP_50_MV
),
350 regulator_desc_s2mps11_ldo(26, STEP_50_MV
),
351 regulator_desc_s2mps11_ldo(27, STEP_25_MV
),
352 regulator_desc_s2mps11_ldo(28, STEP_50_MV
),
353 regulator_desc_s2mps11_ldo(29, STEP_50_MV
),
354 regulator_desc_s2mps11_ldo(30, STEP_50_MV
),
355 regulator_desc_s2mps11_ldo(31, STEP_50_MV
),
356 regulator_desc_s2mps11_ldo(32, STEP_50_MV
),
357 regulator_desc_s2mps11_ldo(33, STEP_50_MV
),
358 regulator_desc_s2mps11_ldo(34, STEP_50_MV
),
359 regulator_desc_s2mps11_ldo(35, STEP_50_MV
),
360 regulator_desc_s2mps11_ldo(36, STEP_50_MV
),
361 regulator_desc_s2mps11_ldo(37, STEP_50_MV
),
362 regulator_desc_s2mps11_ldo(38, STEP_50_MV
),
363 regulator_desc_s2mps11_buck1_4(1),
364 regulator_desc_s2mps11_buck1_4(2),
365 regulator_desc_s2mps11_buck1_4(3),
366 regulator_desc_s2mps11_buck1_4(4),
367 regulator_desc_s2mps11_buck5
,
368 regulator_desc_s2mps11_buck6_10(6, MIN_600_MV
, STEP_6_25_MV
),
369 regulator_desc_s2mps11_buck6_10(7, MIN_600_MV
, STEP_6_25_MV
),
370 regulator_desc_s2mps11_buck6_10(8, MIN_600_MV
, STEP_6_25_MV
),
371 regulator_desc_s2mps11_buck6_10(9, MIN_3000_MV
, STEP_25_MV
),
372 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV
, STEP_12_5_MV
),
375 static struct regulator_ops s2mps14_reg_ops
;
377 #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
379 .id = S2MPS13_LDO##num, \
380 .ops = &s2mps14_reg_ops, \
381 .type = REGULATOR_VOLTAGE, \
382 .owner = THIS_MODULE, \
385 .linear_min_sel = min_sel, \
386 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
387 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
388 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
389 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
390 .enable_mask = S2MPS14_ENABLE_MASK \
393 #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
394 .name = "BUCK"#num, \
395 .id = S2MPS13_BUCK##num, \
396 .ops = &s2mps14_reg_ops, \
397 .type = REGULATOR_VOLTAGE, \
398 .owner = THIS_MODULE, \
401 .linear_min_sel = min_sel, \
402 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
403 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
404 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
405 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
406 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
407 .enable_mask = S2MPS14_ENABLE_MASK \
410 #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
411 .name = "BUCK"#num, \
412 .id = S2MPS13_BUCK##num, \
413 .ops = &s2mps14_reg_ops, \
414 .type = REGULATOR_VOLTAGE, \
415 .owner = THIS_MODULE, \
418 .linear_min_sel = min_sel, \
419 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
420 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
421 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
422 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
423 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
424 .enable_mask = S2MPS14_ENABLE_MASK \
427 #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
428 .name = "BUCK"#num, \
429 .id = S2MPS13_BUCK##num, \
430 .ops = &s2mps14_reg_ops, \
431 .type = REGULATOR_VOLTAGE, \
432 .owner = THIS_MODULE, \
435 .linear_min_sel = min_sel, \
436 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
437 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
438 .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
439 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
440 .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
441 .enable_mask = S2MPS14_ENABLE_MASK \
444 static const struct regulator_desc s2mps13_regulators
[] = {
445 regulator_desc_s2mps13_ldo(1, MIN_800_MV
, STEP_12_5_MV
, 0x00),
446 regulator_desc_s2mps13_ldo(2, MIN_1400_MV
, STEP_50_MV
, 0x0C),
447 regulator_desc_s2mps13_ldo(3, MIN_1000_MV
, STEP_25_MV
, 0x08),
448 regulator_desc_s2mps13_ldo(4, MIN_800_MV
, STEP_12_5_MV
, 0x00),
449 regulator_desc_s2mps13_ldo(5, MIN_800_MV
, STEP_12_5_MV
, 0x00),
450 regulator_desc_s2mps13_ldo(6, MIN_800_MV
, STEP_12_5_MV
, 0x00),
451 regulator_desc_s2mps13_ldo(7, MIN_1000_MV
, STEP_25_MV
, 0x08),
452 regulator_desc_s2mps13_ldo(8, MIN_1000_MV
, STEP_25_MV
, 0x08),
453 regulator_desc_s2mps13_ldo(9, MIN_1000_MV
, STEP_25_MV
, 0x08),
454 regulator_desc_s2mps13_ldo(10, MIN_1400_MV
, STEP_50_MV
, 0x0C),
455 regulator_desc_s2mps13_ldo(11, MIN_800_MV
, STEP_25_MV
, 0x10),
456 regulator_desc_s2mps13_ldo(12, MIN_800_MV
, STEP_25_MV
, 0x10),
457 regulator_desc_s2mps13_ldo(13, MIN_800_MV
, STEP_25_MV
, 0x10),
458 regulator_desc_s2mps13_ldo(14, MIN_800_MV
, STEP_12_5_MV
, 0x00),
459 regulator_desc_s2mps13_ldo(15, MIN_800_MV
, STEP_12_5_MV
, 0x00),
460 regulator_desc_s2mps13_ldo(16, MIN_1400_MV
, STEP_50_MV
, 0x0C),
461 regulator_desc_s2mps13_ldo(17, MIN_1400_MV
, STEP_50_MV
, 0x0C),
462 regulator_desc_s2mps13_ldo(18, MIN_1000_MV
, STEP_25_MV
, 0x08),
463 regulator_desc_s2mps13_ldo(19, MIN_1000_MV
, STEP_25_MV
, 0x08),
464 regulator_desc_s2mps13_ldo(20, MIN_1400_MV
, STEP_50_MV
, 0x0C),
465 regulator_desc_s2mps13_ldo(21, MIN_1000_MV
, STEP_25_MV
, 0x08),
466 regulator_desc_s2mps13_ldo(22, MIN_1000_MV
, STEP_25_MV
, 0x08),
467 regulator_desc_s2mps13_ldo(23, MIN_800_MV
, STEP_12_5_MV
, 0x00),
468 regulator_desc_s2mps13_ldo(24, MIN_800_MV
, STEP_12_5_MV
, 0x00),
469 regulator_desc_s2mps13_ldo(25, MIN_1400_MV
, STEP_50_MV
, 0x0C),
470 regulator_desc_s2mps13_ldo(26, MIN_1400_MV
, STEP_50_MV
, 0x0C),
471 regulator_desc_s2mps13_ldo(27, MIN_1400_MV
, STEP_50_MV
, 0x0C),
472 regulator_desc_s2mps13_ldo(28, MIN_1000_MV
, STEP_25_MV
, 0x08),
473 regulator_desc_s2mps13_ldo(29, MIN_1400_MV
, STEP_50_MV
, 0x0C),
474 regulator_desc_s2mps13_ldo(30, MIN_1400_MV
, STEP_50_MV
, 0x0C),
475 regulator_desc_s2mps13_ldo(31, MIN_1000_MV
, STEP_25_MV
, 0x08),
476 regulator_desc_s2mps13_ldo(32, MIN_1000_MV
, STEP_25_MV
, 0x08),
477 regulator_desc_s2mps13_ldo(33, MIN_1400_MV
, STEP_50_MV
, 0x0C),
478 regulator_desc_s2mps13_ldo(34, MIN_1000_MV
, STEP_25_MV
, 0x08),
479 regulator_desc_s2mps13_ldo(35, MIN_1400_MV
, STEP_50_MV
, 0x0C),
480 regulator_desc_s2mps13_ldo(36, MIN_800_MV
, STEP_12_5_MV
, 0x00),
481 regulator_desc_s2mps13_ldo(37, MIN_1000_MV
, STEP_25_MV
, 0x08),
482 regulator_desc_s2mps13_ldo(38, MIN_1400_MV
, STEP_50_MV
, 0x0C),
483 regulator_desc_s2mps13_ldo(39, MIN_1000_MV
, STEP_25_MV
, 0x08),
484 regulator_desc_s2mps13_ldo(40, MIN_1400_MV
, STEP_50_MV
, 0x0C),
485 regulator_desc_s2mps13_buck(1, MIN_500_MV
, STEP_6_25_MV
, 0x10),
486 regulator_desc_s2mps13_buck(2, MIN_500_MV
, STEP_6_25_MV
, 0x10),
487 regulator_desc_s2mps13_buck(3, MIN_500_MV
, STEP_6_25_MV
, 0x10),
488 regulator_desc_s2mps13_buck(4, MIN_500_MV
, STEP_6_25_MV
, 0x10),
489 regulator_desc_s2mps13_buck(5, MIN_500_MV
, STEP_6_25_MV
, 0x10),
490 regulator_desc_s2mps13_buck(6, MIN_500_MV
, STEP_6_25_MV
, 0x10),
491 regulator_desc_s2mps13_buck7(7, MIN_500_MV
, STEP_6_25_MV
, 0x10),
492 regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV
, STEP_12_5_MV
, 0x20),
493 regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV
, STEP_12_5_MV
, 0x20),
494 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV
, STEP_6_25_MV
, 0x10),
497 static int s2mps14_regulator_enable(struct regulator_dev
*rdev
)
499 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
502 switch (s2mps11
->dev_type
) {
505 if (test_bit(rdev_get_id(rdev
), s2mps11
->suspend_state
))
506 val
= S2MPS14_ENABLE_SUSPEND
;
507 else if (gpio_is_valid(s2mps11
->ext_control_gpio
[rdev_get_id(rdev
)]))
508 val
= S2MPS14_ENABLE_EXT_CONTROL
;
510 val
= rdev
->desc
->enable_mask
;
513 if (test_bit(rdev_get_id(rdev
), s2mps11
->suspend_state
))
514 val
= S2MPU02_ENABLE_SUSPEND
;
516 val
= rdev
->desc
->enable_mask
;
522 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
523 rdev
->desc
->enable_mask
, val
);
526 static int s2mps14_regulator_set_suspend_disable(struct regulator_dev
*rdev
)
529 unsigned int val
, state
;
530 struct s2mps11_info
*s2mps11
= rdev_get_drvdata(rdev
);
531 int rdev_id
= rdev_get_id(rdev
);
533 /* Below LDO should be always on or does not support suspend mode. */
534 switch (s2mps11
->dev_type
) {
541 state
= S2MPS14_ENABLE_SUSPEND
;
552 state
= S2MPU02_DISABLE_SUSPEND
;
555 state
= S2MPU02_ENABLE_SUSPEND
;
563 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->enable_reg
, &val
);
567 set_bit(rdev_get_id(rdev
), s2mps11
->suspend_state
);
569 * Don't enable suspend mode if regulator is already disabled because
570 * this would effectively for a short time turn on the regulator after
572 * However we still want to toggle the suspend_state bit for regulator
573 * in case if it got enabled before suspending the system.
575 if (!(val
& rdev
->desc
->enable_mask
))
578 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
579 rdev
->desc
->enable_mask
, state
);
582 static struct regulator_ops s2mps14_reg_ops
= {
583 .list_voltage
= regulator_list_voltage_linear
,
584 .map_voltage
= regulator_map_voltage_linear
,
585 .is_enabled
= regulator_is_enabled_regmap
,
586 .enable
= s2mps14_regulator_enable
,
587 .disable
= regulator_disable_regmap
,
588 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
589 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
590 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
591 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
594 #define regulator_desc_s2mps14_ldo(num, min, step) { \
596 .id = S2MPS14_LDO##num, \
597 .ops = &s2mps14_reg_ops, \
598 .type = REGULATOR_VOLTAGE, \
599 .owner = THIS_MODULE, \
602 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
603 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
604 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
605 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
606 .enable_mask = S2MPS14_ENABLE_MASK \
609 #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
610 .name = "BUCK"#num, \
611 .id = S2MPS14_BUCK##num, \
612 .ops = &s2mps14_reg_ops, \
613 .type = REGULATOR_VOLTAGE, \
614 .owner = THIS_MODULE, \
617 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
618 .linear_min_sel = min_sel, \
619 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
620 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
621 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
622 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
623 .enable_mask = S2MPS14_ENABLE_MASK \
626 static const struct regulator_desc s2mps14_regulators
[] = {
627 regulator_desc_s2mps14_ldo(1, MIN_800_MV
, STEP_12_5_MV
),
628 regulator_desc_s2mps14_ldo(2, MIN_800_MV
, STEP_12_5_MV
),
629 regulator_desc_s2mps14_ldo(3, MIN_800_MV
, STEP_25_MV
),
630 regulator_desc_s2mps14_ldo(4, MIN_800_MV
, STEP_25_MV
),
631 regulator_desc_s2mps14_ldo(5, MIN_800_MV
, STEP_12_5_MV
),
632 regulator_desc_s2mps14_ldo(6, MIN_800_MV
, STEP_12_5_MV
),
633 regulator_desc_s2mps14_ldo(7, MIN_800_MV
, STEP_25_MV
),
634 regulator_desc_s2mps14_ldo(8, MIN_1800_MV
, STEP_25_MV
),
635 regulator_desc_s2mps14_ldo(9, MIN_800_MV
, STEP_12_5_MV
),
636 regulator_desc_s2mps14_ldo(10, MIN_800_MV
, STEP_12_5_MV
),
637 regulator_desc_s2mps14_ldo(11, MIN_800_MV
, STEP_25_MV
),
638 regulator_desc_s2mps14_ldo(12, MIN_1800_MV
, STEP_25_MV
),
639 regulator_desc_s2mps14_ldo(13, MIN_1800_MV
, STEP_25_MV
),
640 regulator_desc_s2mps14_ldo(14, MIN_1800_MV
, STEP_25_MV
),
641 regulator_desc_s2mps14_ldo(15, MIN_1800_MV
, STEP_25_MV
),
642 regulator_desc_s2mps14_ldo(16, MIN_1800_MV
, STEP_25_MV
),
643 regulator_desc_s2mps14_ldo(17, MIN_1800_MV
, STEP_25_MV
),
644 regulator_desc_s2mps14_ldo(18, MIN_1800_MV
, STEP_25_MV
),
645 regulator_desc_s2mps14_ldo(19, MIN_800_MV
, STEP_25_MV
),
646 regulator_desc_s2mps14_ldo(20, MIN_800_MV
, STEP_25_MV
),
647 regulator_desc_s2mps14_ldo(21, MIN_800_MV
, STEP_25_MV
),
648 regulator_desc_s2mps14_ldo(22, MIN_800_MV
, STEP_12_5_MV
),
649 regulator_desc_s2mps14_ldo(23, MIN_800_MV
, STEP_25_MV
),
650 regulator_desc_s2mps14_ldo(24, MIN_1800_MV
, STEP_25_MV
),
651 regulator_desc_s2mps14_ldo(25, MIN_1800_MV
, STEP_25_MV
),
652 regulator_desc_s2mps14_buck(1, MIN_600_MV
, STEP_6_25_MV
,
653 S2MPS14_BUCK1235_START_SEL
),
654 regulator_desc_s2mps14_buck(2, MIN_600_MV
, STEP_6_25_MV
,
655 S2MPS14_BUCK1235_START_SEL
),
656 regulator_desc_s2mps14_buck(3, MIN_600_MV
, STEP_6_25_MV
,
657 S2MPS14_BUCK1235_START_SEL
),
658 regulator_desc_s2mps14_buck(4, MIN_1400_MV
, STEP_12_5_MV
,
659 S2MPS14_BUCK4_START_SEL
),
660 regulator_desc_s2mps14_buck(5, MIN_600_MV
, STEP_6_25_MV
,
661 S2MPS14_BUCK1235_START_SEL
),
664 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info
*s2mps11
,
665 struct regulator_dev
*rdev
)
667 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->enable_reg
,
668 rdev
->desc
->enable_mask
, S2MPS14_ENABLE_EXT_CONTROL
);
671 static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device
*pdev
,
672 struct of_regulator_match
*rdata
, struct s2mps11_info
*s2mps11
)
674 int *gpio
= s2mps11
->ext_control_gpio
;
676 unsigned int valid_regulators
[3] = { S2MPS14_LDO10
, S2MPS14_LDO11
,
679 for (i
= 0; i
< ARRAY_SIZE(valid_regulators
); i
++) {
680 unsigned int reg
= valid_regulators
[i
];
682 if (!rdata
[reg
].init_data
|| !rdata
[reg
].of_node
)
685 gpio
[reg
] = of_get_named_gpio(rdata
[reg
].of_node
,
686 "samsung,ext-control-gpios", 0);
687 if (gpio_is_valid(gpio
[reg
]))
688 dev_dbg(&pdev
->dev
, "Using GPIO %d for ext-control over %d/%s\n",
689 gpio
[reg
], reg
, rdata
[reg
].name
);
693 static int s2mps11_pmic_dt_parse(struct platform_device
*pdev
,
694 struct of_regulator_match
*rdata
, struct s2mps11_info
*s2mps11
)
696 struct device_node
*reg_np
;
698 reg_np
= of_get_child_by_name(pdev
->dev
.parent
->of_node
, "regulators");
700 dev_err(&pdev
->dev
, "could not find regulators sub-node\n");
704 of_regulator_match(&pdev
->dev
, reg_np
, rdata
, s2mps11
->rdev_num
);
705 if (s2mps11
->dev_type
== S2MPS14X
)
706 s2mps14_pmic_dt_parse_ext_control_gpio(pdev
, rdata
, s2mps11
);
713 static int s2mpu02_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
715 unsigned int ramp_val
, ramp_shift
, ramp_reg
;
717 switch (rdev_get_id(rdev
)) {
719 ramp_shift
= S2MPU02_BUCK1_RAMP_SHIFT
;
722 ramp_shift
= S2MPU02_BUCK2_RAMP_SHIFT
;
725 ramp_shift
= S2MPU02_BUCK3_RAMP_SHIFT
;
728 ramp_shift
= S2MPU02_BUCK4_RAMP_SHIFT
;
733 ramp_reg
= S2MPU02_REG_RAMP1
;
734 ramp_val
= get_ramp_delay(ramp_delay
);
736 return regmap_update_bits(rdev
->regmap
, ramp_reg
,
737 S2MPU02_BUCK1234_RAMP_MASK
<< ramp_shift
,
738 ramp_val
<< ramp_shift
);
741 static struct regulator_ops s2mpu02_ldo_ops
= {
742 .list_voltage
= regulator_list_voltage_linear
,
743 .map_voltage
= regulator_map_voltage_linear
,
744 .is_enabled
= regulator_is_enabled_regmap
,
745 .enable
= s2mps14_regulator_enable
,
746 .disable
= regulator_disable_regmap
,
747 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
748 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
749 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
750 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
753 static struct regulator_ops s2mpu02_buck_ops
= {
754 .list_voltage
= regulator_list_voltage_linear
,
755 .map_voltage
= regulator_map_voltage_linear
,
756 .is_enabled
= regulator_is_enabled_regmap
,
757 .enable
= s2mps14_regulator_enable
,
758 .disable
= regulator_disable_regmap
,
759 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
760 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
761 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
762 .set_suspend_disable
= s2mps14_regulator_set_suspend_disable
,
763 .set_ramp_delay
= s2mpu02_set_ramp_delay
,
766 #define regulator_desc_s2mpu02_ldo1(num) { \
768 .id = S2MPU02_LDO##num, \
769 .ops = &s2mpu02_ldo_ops, \
770 .type = REGULATOR_VOLTAGE, \
771 .owner = THIS_MODULE, \
772 .min_uV = S2MPU02_LDO_MIN_900MV, \
773 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
774 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
775 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
776 .vsel_reg = S2MPU02_REG_L1CTRL, \
777 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
778 .enable_reg = S2MPU02_REG_L1CTRL, \
779 .enable_mask = S2MPU02_ENABLE_MASK \
781 #define regulator_desc_s2mpu02_ldo2(num) { \
783 .id = S2MPU02_LDO##num, \
784 .ops = &s2mpu02_ldo_ops, \
785 .type = REGULATOR_VOLTAGE, \
786 .owner = THIS_MODULE, \
787 .min_uV = S2MPU02_LDO_MIN_1050MV, \
788 .uV_step = S2MPU02_LDO_STEP_25MV, \
789 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
790 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
791 .vsel_reg = S2MPU02_REG_L2CTRL1, \
792 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
793 .enable_reg = S2MPU02_REG_L2CTRL1, \
794 .enable_mask = S2MPU02_ENABLE_MASK \
796 #define regulator_desc_s2mpu02_ldo3(num) { \
798 .id = S2MPU02_LDO##num, \
799 .ops = &s2mpu02_ldo_ops, \
800 .type = REGULATOR_VOLTAGE, \
801 .owner = THIS_MODULE, \
802 .min_uV = S2MPU02_LDO_MIN_900MV, \
803 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
804 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
805 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
806 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
807 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
808 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
809 .enable_mask = S2MPU02_ENABLE_MASK \
811 #define regulator_desc_s2mpu02_ldo4(num) { \
813 .id = S2MPU02_LDO##num, \
814 .ops = &s2mpu02_ldo_ops, \
815 .type = REGULATOR_VOLTAGE, \
816 .owner = THIS_MODULE, \
817 .min_uV = S2MPU02_LDO_MIN_1050MV, \
818 .uV_step = S2MPU02_LDO_STEP_25MV, \
819 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
820 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
821 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
822 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
823 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
824 .enable_mask = S2MPU02_ENABLE_MASK \
826 #define regulator_desc_s2mpu02_ldo5(num) { \
828 .id = S2MPU02_LDO##num, \
829 .ops = &s2mpu02_ldo_ops, \
830 .type = REGULATOR_VOLTAGE, \
831 .owner = THIS_MODULE, \
832 .min_uV = S2MPU02_LDO_MIN_1600MV, \
833 .uV_step = S2MPU02_LDO_STEP_50MV, \
834 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
835 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
836 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
837 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
838 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
839 .enable_mask = S2MPU02_ENABLE_MASK \
842 #define regulator_desc_s2mpu02_buck1234(num) { \
843 .name = "BUCK"#num, \
844 .id = S2MPU02_BUCK##num, \
845 .ops = &s2mpu02_buck_ops, \
846 .type = REGULATOR_VOLTAGE, \
847 .owner = THIS_MODULE, \
848 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
849 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
850 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
851 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
852 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
853 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
854 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
855 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
856 .enable_mask = S2MPU02_ENABLE_MASK \
858 #define regulator_desc_s2mpu02_buck5(num) { \
859 .name = "BUCK"#num, \
860 .id = S2MPU02_BUCK##num, \
861 .ops = &s2mpu02_ldo_ops, \
862 .type = REGULATOR_VOLTAGE, \
863 .owner = THIS_MODULE, \
864 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
865 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
866 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
867 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
868 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
869 .vsel_reg = S2MPU02_REG_B5CTRL2, \
870 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
871 .enable_reg = S2MPU02_REG_B5CTRL1, \
872 .enable_mask = S2MPU02_ENABLE_MASK \
874 #define regulator_desc_s2mpu02_buck6(num) { \
875 .name = "BUCK"#num, \
876 .id = S2MPU02_BUCK##num, \
877 .ops = &s2mpu02_ldo_ops, \
878 .type = REGULATOR_VOLTAGE, \
879 .owner = THIS_MODULE, \
880 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
881 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
882 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
883 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
884 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
885 .vsel_reg = S2MPU02_REG_B6CTRL2, \
886 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
887 .enable_reg = S2MPU02_REG_B6CTRL1, \
888 .enable_mask = S2MPU02_ENABLE_MASK \
890 #define regulator_desc_s2mpu02_buck7(num) { \
891 .name = "BUCK"#num, \
892 .id = S2MPU02_BUCK##num, \
893 .ops = &s2mpu02_ldo_ops, \
894 .type = REGULATOR_VOLTAGE, \
895 .owner = THIS_MODULE, \
896 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
897 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
898 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
899 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
900 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
901 .vsel_reg = S2MPU02_REG_B7CTRL2, \
902 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
903 .enable_reg = S2MPU02_REG_B7CTRL1, \
904 .enable_mask = S2MPU02_ENABLE_MASK \
907 static const struct regulator_desc s2mpu02_regulators
[] = {
908 regulator_desc_s2mpu02_ldo1(1),
909 regulator_desc_s2mpu02_ldo2(2),
910 regulator_desc_s2mpu02_ldo4(3),
911 regulator_desc_s2mpu02_ldo5(4),
912 regulator_desc_s2mpu02_ldo4(5),
913 regulator_desc_s2mpu02_ldo3(6),
914 regulator_desc_s2mpu02_ldo3(7),
915 regulator_desc_s2mpu02_ldo4(8),
916 regulator_desc_s2mpu02_ldo5(9),
917 regulator_desc_s2mpu02_ldo3(10),
918 regulator_desc_s2mpu02_ldo4(11),
919 regulator_desc_s2mpu02_ldo5(12),
920 regulator_desc_s2mpu02_ldo5(13),
921 regulator_desc_s2mpu02_ldo5(14),
922 regulator_desc_s2mpu02_ldo5(15),
923 regulator_desc_s2mpu02_ldo5(16),
924 regulator_desc_s2mpu02_ldo4(17),
925 regulator_desc_s2mpu02_ldo5(18),
926 regulator_desc_s2mpu02_ldo3(19),
927 regulator_desc_s2mpu02_ldo4(20),
928 regulator_desc_s2mpu02_ldo5(21),
929 regulator_desc_s2mpu02_ldo5(22),
930 regulator_desc_s2mpu02_ldo5(23),
931 regulator_desc_s2mpu02_ldo4(24),
932 regulator_desc_s2mpu02_ldo5(25),
933 regulator_desc_s2mpu02_ldo4(26),
934 regulator_desc_s2mpu02_ldo5(27),
935 regulator_desc_s2mpu02_ldo5(28),
936 regulator_desc_s2mpu02_buck1234(1),
937 regulator_desc_s2mpu02_buck1234(2),
938 regulator_desc_s2mpu02_buck1234(3),
939 regulator_desc_s2mpu02_buck1234(4),
940 regulator_desc_s2mpu02_buck5(5),
941 regulator_desc_s2mpu02_buck6(6),
942 regulator_desc_s2mpu02_buck7(7),
945 static int s2mps11_pmic_probe(struct platform_device
*pdev
)
947 struct sec_pmic_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
948 struct sec_platform_data
*pdata
= NULL
;
949 struct of_regulator_match
*rdata
= NULL
;
950 struct regulator_config config
= { };
951 struct s2mps11_info
*s2mps11
;
953 const struct regulator_desc
*regulators
;
955 s2mps11
= devm_kzalloc(&pdev
->dev
, sizeof(struct s2mps11_info
),
960 s2mps11
->dev_type
= platform_get_device_id(pdev
)->driver_data
;
961 switch (s2mps11
->dev_type
) {
963 s2mps11
->rdev_num
= ARRAY_SIZE(s2mps11_regulators
);
964 regulators
= s2mps11_regulators
;
965 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< s2mps11
->rdev_num
);
968 s2mps11
->rdev_num
= ARRAY_SIZE(s2mps13_regulators
);
969 regulators
= s2mps13_regulators
;
970 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< s2mps11
->rdev_num
);
973 s2mps11
->rdev_num
= ARRAY_SIZE(s2mps14_regulators
);
974 regulators
= s2mps14_regulators
;
975 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< s2mps11
->rdev_num
);
978 s2mps11
->rdev_num
= ARRAY_SIZE(s2mpu02_regulators
);
979 regulators
= s2mpu02_regulators
;
980 BUILD_BUG_ON(S2MPS_REGULATOR_MAX
< s2mps11
->rdev_num
);
983 dev_err(&pdev
->dev
, "Invalid device type: %u\n",
988 s2mps11
->ext_control_gpio
= devm_kmalloc(&pdev
->dev
,
989 sizeof(*s2mps11
->ext_control_gpio
) * s2mps11
->rdev_num
,
991 if (!s2mps11
->ext_control_gpio
)
994 * 0 is a valid GPIO so initialize all GPIO-s to negative value
995 * to indicate that external control won't be used for this regulator.
997 for (i
= 0; i
< s2mps11
->rdev_num
; i
++)
998 s2mps11
->ext_control_gpio
[i
] = -EINVAL
;
1000 if (!iodev
->dev
->of_node
) {
1002 pdata
= iodev
->pdata
;
1005 dev_err(pdev
->dev
.parent
,
1006 "Platform data or DT node not supplied\n");
1011 rdata
= kzalloc(sizeof(*rdata
) * s2mps11
->rdev_num
, GFP_KERNEL
);
1015 for (i
= 0; i
< s2mps11
->rdev_num
; i
++)
1016 rdata
[i
].name
= regulators
[i
].name
;
1018 ret
= s2mps11_pmic_dt_parse(pdev
, rdata
, s2mps11
);
1023 platform_set_drvdata(pdev
, s2mps11
);
1025 config
.dev
= &pdev
->dev
;
1026 config
.regmap
= iodev
->regmap_pmic
;
1027 config
.driver_data
= s2mps11
;
1028 config
.ena_gpio_flags
= GPIOF_OUT_INIT_HIGH
;
1029 config
.ena_gpio_initialized
= true;
1030 for (i
= 0; i
< s2mps11
->rdev_num
; i
++) {
1031 struct regulator_dev
*regulator
;
1034 config
.init_data
= pdata
->regulators
[i
].initdata
;
1035 config
.of_node
= pdata
->regulators
[i
].reg_node
;
1037 config
.init_data
= rdata
[i
].init_data
;
1038 config
.of_node
= rdata
[i
].of_node
;
1040 config
.ena_gpio
= s2mps11
->ext_control_gpio
[i
];
1042 regulator
= devm_regulator_register(&pdev
->dev
,
1043 ®ulators
[i
], &config
);
1044 if (IS_ERR(regulator
)) {
1045 ret
= PTR_ERR(regulator
);
1046 dev_err(&pdev
->dev
, "regulator init failed for %d\n",
1051 if (gpio_is_valid(s2mps11
->ext_control_gpio
[i
])) {
1052 ret
= s2mps14_pmic_enable_ext_control(s2mps11
,
1056 "failed to enable GPIO control over %s: %d\n",
1057 regulator
->desc
->name
, ret
);
1069 static const struct platform_device_id s2mps11_pmic_id
[] = {
1070 { "s2mps11-pmic", S2MPS11X
},
1071 { "s2mps13-pmic", S2MPS13X
},
1072 { "s2mps14-pmic", S2MPS14X
},
1073 { "s2mpu02-pmic", S2MPU02
},
1076 MODULE_DEVICE_TABLE(platform
, s2mps11_pmic_id
);
1078 static struct platform_driver s2mps11_pmic_driver
= {
1080 .name
= "s2mps11-pmic",
1082 .probe
= s2mps11_pmic_probe
,
1083 .id_table
= s2mps11_pmic_id
,
1086 static int __init
s2mps11_pmic_init(void)
1088 return platform_driver_register(&s2mps11_pmic_driver
);
1090 subsys_initcall(s2mps11_pmic_init
);
1092 static void __exit
s2mps11_pmic_exit(void)
1094 platform_driver_unregister(&s2mps11_pmic_driver
);
1096 module_exit(s2mps11_pmic_exit
);
1098 /* Module information */
1099 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
1100 MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPU02 Regulator Driver");
1101 MODULE_LICENSE("GPL");