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/s2mps14.h>
34 #include <linux/mfd/samsung/s2mpu02.h>
37 unsigned int rdev_num;
45 enum sec_device_type dev_type;
48 * One bit for each S2MPS14/S2MPU02 regulator whether the suspend mode
51 unsigned long long s2mps14_suspend_state:35;
53 /* Array of size rdev_num with GPIO-s for external sleep control */
54 int *ext_control_gpio;
57 static int get_ramp_delay(int ramp_delay)
59 unsigned char cnt = 0;
64 ramp_delay = ramp_delay >> 1;
76 static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
77 unsigned int old_selector,
78 unsigned int new_selector)
80 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
81 unsigned int ramp_delay = 0;
82 int old_volt, new_volt;
84 switch (rdev_get_id(rdev)) {
86 ramp_delay = s2mps11->ramp_delay2;
90 ramp_delay = s2mps11->ramp_delay34;
93 ramp_delay = s2mps11->ramp_delay5;
97 ramp_delay = s2mps11->ramp_delay16;
102 ramp_delay = s2mps11->ramp_delay7810;
105 ramp_delay = s2mps11->ramp_delay9;
109 ramp_delay = rdev->desc->ramp_delay;
111 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
112 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
114 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
117 static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
119 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
120 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
121 unsigned int ramp_enable = 1, enable_shift = 0;
124 switch (rdev_get_id(rdev)) {
126 if (ramp_delay > s2mps11->ramp_delay16)
127 s2mps11->ramp_delay16 = ramp_delay;
129 ramp_delay = s2mps11->ramp_delay16;
131 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
134 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
140 s2mps11->ramp_delay2 = ramp_delay;
141 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
142 ramp_reg = S2MPS11_REG_RAMP;
145 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
151 if (ramp_delay > s2mps11->ramp_delay34)
152 s2mps11->ramp_delay34 = ramp_delay;
154 ramp_delay = s2mps11->ramp_delay34;
156 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
157 ramp_reg = S2MPS11_REG_RAMP;
160 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
166 if (ramp_delay > s2mps11->ramp_delay34)
167 s2mps11->ramp_delay34 = ramp_delay;
169 ramp_delay = s2mps11->ramp_delay34;
171 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
172 ramp_reg = S2MPS11_REG_RAMP;
175 s2mps11->ramp_delay5 = ramp_delay;
176 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
179 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
185 if (ramp_delay > s2mps11->ramp_delay16)
186 s2mps11->ramp_delay16 = ramp_delay;
188 ramp_delay = s2mps11->ramp_delay16;
190 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
195 if (ramp_delay > s2mps11->ramp_delay7810)
196 s2mps11->ramp_delay7810 = ramp_delay;
198 ramp_delay = s2mps11->ramp_delay7810;
200 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
203 s2mps11->ramp_delay9 = ramp_delay;
204 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
213 /* Ramp delay can be enabled/disabled only for buck[2346] */
214 if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 &&
215 rdev_get_id(rdev) <= S2MPS11_BUCK4) ||
216 rdev_get_id(rdev) == S2MPS11_BUCK6) {
217 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
218 1 << enable_shift, 1 << enable_shift);
220 dev_err(&rdev->dev, "failed to enable ramp rate\n");
225 ramp_val = get_ramp_delay(ramp_delay);
227 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
228 ramp_val << ramp_shift);
231 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
232 1 << enable_shift, 0);
235 static struct regulator_ops s2mps11_ldo_ops = {
236 .list_voltage = regulator_list_voltage_linear,
237 .map_voltage = regulator_map_voltage_linear,
238 .is_enabled = regulator_is_enabled_regmap,
239 .enable = regulator_enable_regmap,
240 .disable = regulator_disable_regmap,
241 .get_voltage_sel = regulator_get_voltage_sel_regmap,
242 .set_voltage_sel = regulator_set_voltage_sel_regmap,
243 .set_voltage_time_sel = regulator_set_voltage_time_sel,
246 static struct regulator_ops s2mps11_buck_ops = {
247 .list_voltage = regulator_list_voltage_linear,
248 .map_voltage = regulator_map_voltage_linear,
249 .is_enabled = regulator_is_enabled_regmap,
250 .enable = regulator_enable_regmap,
251 .disable = regulator_disable_regmap,
252 .get_voltage_sel = regulator_get_voltage_sel_regmap,
253 .set_voltage_sel = regulator_set_voltage_sel_regmap,
254 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
255 .set_ramp_delay = s2mps11_set_ramp_delay,
258 #define regulator_desc_s2mps11_ldo(num, step) { \
260 .id = S2MPS11_LDO##num, \
261 .ops = &s2mps11_ldo_ops, \
262 .type = REGULATOR_VOLTAGE, \
263 .owner = THIS_MODULE, \
264 .min_uV = MIN_800_MV, \
266 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
267 .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
268 .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
269 .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
270 .enable_mask = S2MPS11_ENABLE_MASK \
273 #define regulator_desc_s2mps11_buck1_4(num) { \
274 .name = "BUCK"#num, \
275 .id = S2MPS11_BUCK##num, \
276 .ops = &s2mps11_buck_ops, \
277 .type = REGULATOR_VOLTAGE, \
278 .owner = THIS_MODULE, \
279 .min_uV = MIN_600_MV, \
280 .uV_step = STEP_6_25_MV, \
281 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
282 .ramp_delay = S2MPS11_RAMP_DELAY, \
283 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
284 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
285 .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
286 .enable_mask = S2MPS11_ENABLE_MASK \
289 #define regulator_desc_s2mps11_buck5 { \
291 .id = S2MPS11_BUCK5, \
292 .ops = &s2mps11_buck_ops, \
293 .type = REGULATOR_VOLTAGE, \
294 .owner = THIS_MODULE, \
295 .min_uV = MIN_600_MV, \
296 .uV_step = STEP_6_25_MV, \
297 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
298 .ramp_delay = S2MPS11_RAMP_DELAY, \
299 .vsel_reg = S2MPS11_REG_B5CTRL2, \
300 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
301 .enable_reg = S2MPS11_REG_B5CTRL1, \
302 .enable_mask = S2MPS11_ENABLE_MASK \
305 #define regulator_desc_s2mps11_buck6_10(num, min, step) { \
306 .name = "BUCK"#num, \
307 .id = S2MPS11_BUCK##num, \
308 .ops = &s2mps11_buck_ops, \
309 .type = REGULATOR_VOLTAGE, \
310 .owner = THIS_MODULE, \
313 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
314 .ramp_delay = S2MPS11_RAMP_DELAY, \
315 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
316 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
317 .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
318 .enable_mask = S2MPS11_ENABLE_MASK \
321 static const struct regulator_desc s2mps11_regulators[] = {
322 regulator_desc_s2mps11_ldo(1, STEP_25_MV),
323 regulator_desc_s2mps11_ldo(2, STEP_50_MV),
324 regulator_desc_s2mps11_ldo(3, STEP_50_MV),
325 regulator_desc_s2mps11_ldo(4, STEP_50_MV),
326 regulator_desc_s2mps11_ldo(5, STEP_50_MV),
327 regulator_desc_s2mps11_ldo(6, STEP_25_MV),
328 regulator_desc_s2mps11_ldo(7, STEP_50_MV),
329 regulator_desc_s2mps11_ldo(8, STEP_50_MV),
330 regulator_desc_s2mps11_ldo(9, STEP_50_MV),
331 regulator_desc_s2mps11_ldo(10, STEP_50_MV),
332 regulator_desc_s2mps11_ldo(11, STEP_25_MV),
333 regulator_desc_s2mps11_ldo(12, STEP_50_MV),
334 regulator_desc_s2mps11_ldo(13, STEP_50_MV),
335 regulator_desc_s2mps11_ldo(14, STEP_50_MV),
336 regulator_desc_s2mps11_ldo(15, STEP_50_MV),
337 regulator_desc_s2mps11_ldo(16, STEP_50_MV),
338 regulator_desc_s2mps11_ldo(17, STEP_50_MV),
339 regulator_desc_s2mps11_ldo(18, STEP_50_MV),
340 regulator_desc_s2mps11_ldo(19, STEP_50_MV),
341 regulator_desc_s2mps11_ldo(20, STEP_50_MV),
342 regulator_desc_s2mps11_ldo(21, STEP_50_MV),
343 regulator_desc_s2mps11_ldo(22, STEP_25_MV),
344 regulator_desc_s2mps11_ldo(23, STEP_25_MV),
345 regulator_desc_s2mps11_ldo(24, STEP_50_MV),
346 regulator_desc_s2mps11_ldo(25, STEP_50_MV),
347 regulator_desc_s2mps11_ldo(26, STEP_50_MV),
348 regulator_desc_s2mps11_ldo(27, STEP_25_MV),
349 regulator_desc_s2mps11_ldo(28, STEP_50_MV),
350 regulator_desc_s2mps11_ldo(29, STEP_50_MV),
351 regulator_desc_s2mps11_ldo(30, STEP_50_MV),
352 regulator_desc_s2mps11_ldo(31, STEP_50_MV),
353 regulator_desc_s2mps11_ldo(32, STEP_50_MV),
354 regulator_desc_s2mps11_ldo(33, STEP_50_MV),
355 regulator_desc_s2mps11_ldo(34, STEP_50_MV),
356 regulator_desc_s2mps11_ldo(35, STEP_50_MV),
357 regulator_desc_s2mps11_ldo(36, STEP_50_MV),
358 regulator_desc_s2mps11_ldo(37, STEP_50_MV),
359 regulator_desc_s2mps11_ldo(38, STEP_50_MV),
360 regulator_desc_s2mps11_buck1_4(1),
361 regulator_desc_s2mps11_buck1_4(2),
362 regulator_desc_s2mps11_buck1_4(3),
363 regulator_desc_s2mps11_buck1_4(4),
364 regulator_desc_s2mps11_buck5,
365 regulator_desc_s2mps11_buck6_10(6, MIN_600_MV, STEP_6_25_MV),
366 regulator_desc_s2mps11_buck6_10(7, MIN_600_MV, STEP_6_25_MV),
367 regulator_desc_s2mps11_buck6_10(8, MIN_600_MV, STEP_6_25_MV),
368 regulator_desc_s2mps11_buck6_10(9, MIN_3000_MV, STEP_25_MV),
369 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV, STEP_12_5_MV),
372 static int s2mps14_regulator_enable(struct regulator_dev *rdev)
374 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
377 switch (s2mps11->dev_type) {
379 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
380 val = S2MPS14_ENABLE_SUSPEND;
381 else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
382 val = S2MPS14_ENABLE_EXT_CONTROL;
384 val = rdev->desc->enable_mask;
387 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
388 val = S2MPU02_ENABLE_SUSPEND;
390 val = rdev->desc->enable_mask;
396 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
397 rdev->desc->enable_mask, val);
400 static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
403 unsigned int val, state;
404 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
405 int rdev_id = rdev_get_id(rdev);
407 /* Below LDO should be always on or does not support suspend mode. */
408 switch (s2mps11->dev_type) {
414 state = S2MPS14_ENABLE_SUSPEND;
425 state = S2MPU02_DISABLE_SUSPEND;
428 state = S2MPU02_ENABLE_SUSPEND;
436 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
440 s2mps11->s2mps14_suspend_state |= (1 << rdev_get_id(rdev));
442 * Don't enable suspend mode if regulator is already disabled because
443 * this would effectively for a short time turn on the regulator after
445 * However we still want to toggle the suspend_state bit for regulator
446 * in case if it got enabled before suspending the system.
448 if (!(val & rdev->desc->enable_mask))
451 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
452 rdev->desc->enable_mask, state);
455 static struct regulator_ops s2mps14_reg_ops = {
456 .list_voltage = regulator_list_voltage_linear,
457 .map_voltage = regulator_map_voltage_linear,
458 .is_enabled = regulator_is_enabled_regmap,
459 .enable = s2mps14_regulator_enable,
460 .disable = regulator_disable_regmap,
461 .get_voltage_sel = regulator_get_voltage_sel_regmap,
462 .set_voltage_sel = regulator_set_voltage_sel_regmap,
463 .set_voltage_time_sel = regulator_set_voltage_time_sel,
464 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
467 #define regulator_desc_s2mps14_ldo(num, min, step) { \
469 .id = S2MPS14_LDO##num, \
470 .ops = &s2mps14_reg_ops, \
471 .type = REGULATOR_VOLTAGE, \
472 .owner = THIS_MODULE, \
475 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
476 .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
477 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
478 .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
479 .enable_mask = S2MPS14_ENABLE_MASK \
482 #define regulator_desc_s2mps14_buck(num, min, step) { \
483 .name = "BUCK"#num, \
484 .id = S2MPS14_BUCK##num, \
485 .ops = &s2mps14_reg_ops, \
486 .type = REGULATOR_VOLTAGE, \
487 .owner = THIS_MODULE, \
490 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
491 .linear_min_sel = S2MPS14_BUCK1235_START_SEL, \
492 .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
493 .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
494 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
495 .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
496 .enable_mask = S2MPS14_ENABLE_MASK \
499 static const struct regulator_desc s2mps14_regulators[] = {
500 regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
501 regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
502 regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
503 regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
504 regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
505 regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
506 regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
507 regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
508 regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
509 regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
510 regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
511 regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
512 regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
513 regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
514 regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
515 regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
516 regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
517 regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
518 regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
519 regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
520 regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
521 regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
522 regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
523 regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
524 regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
525 regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV),
526 regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV),
527 regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV),
528 regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV),
529 regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV),
532 static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
533 struct regulator_dev *rdev)
535 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
536 rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
539 static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
540 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
542 int *gpio = s2mps11->ext_control_gpio;
544 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
547 for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
548 unsigned int reg = valid_regulators[i];
550 if (!rdata[reg].init_data || !rdata[reg].of_node)
553 gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
554 "samsung,ext-control-gpios", 0);
555 if (gpio_is_valid(gpio[reg]))
556 dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
557 gpio[reg], reg, rdata[reg].name);
561 static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
562 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
564 struct device_node *reg_np;
566 reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
568 dev_err(&pdev->dev, "could not find regulators sub-node\n");
572 of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num);
573 if (s2mps11->dev_type == S2MPS14X)
574 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
581 static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
583 unsigned int ramp_val, ramp_shift, ramp_reg;
585 switch (rdev_get_id(rdev)) {
587 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
590 ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
593 ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
596 ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
601 ramp_reg = S2MPU02_REG_RAMP1;
602 ramp_val = get_ramp_delay(ramp_delay);
604 return regmap_update_bits(rdev->regmap, ramp_reg,
605 S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
606 ramp_val << ramp_shift);
609 static struct regulator_ops s2mpu02_ldo_ops = {
610 .list_voltage = regulator_list_voltage_linear,
611 .map_voltage = regulator_map_voltage_linear,
612 .is_enabled = regulator_is_enabled_regmap,
613 .enable = s2mps14_regulator_enable,
614 .disable = regulator_disable_regmap,
615 .get_voltage_sel = regulator_get_voltage_sel_regmap,
616 .set_voltage_sel = regulator_set_voltage_sel_regmap,
617 .set_voltage_time_sel = regulator_set_voltage_time_sel,
618 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
621 static struct regulator_ops s2mpu02_buck_ops = {
622 .list_voltage = regulator_list_voltage_linear,
623 .map_voltage = regulator_map_voltage_linear,
624 .is_enabled = regulator_is_enabled_regmap,
625 .enable = s2mps14_regulator_enable,
626 .disable = regulator_disable_regmap,
627 .get_voltage_sel = regulator_get_voltage_sel_regmap,
628 .set_voltage_sel = regulator_set_voltage_sel_regmap,
629 .set_voltage_time_sel = regulator_set_voltage_time_sel,
630 .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
631 .set_ramp_delay = s2mpu02_set_ramp_delay,
634 #define regulator_desc_s2mpu02_ldo1(num) { \
636 .id = S2MPU02_LDO##num, \
637 .ops = &s2mpu02_ldo_ops, \
638 .type = REGULATOR_VOLTAGE, \
639 .owner = THIS_MODULE, \
640 .min_uV = S2MPU02_LDO_MIN_900MV, \
641 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
642 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
643 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
644 .vsel_reg = S2MPU02_REG_L1CTRL, \
645 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
646 .enable_reg = S2MPU02_REG_L1CTRL, \
647 .enable_mask = S2MPU02_ENABLE_MASK \
649 #define regulator_desc_s2mpu02_ldo2(num) { \
651 .id = S2MPU02_LDO##num, \
652 .ops = &s2mpu02_ldo_ops, \
653 .type = REGULATOR_VOLTAGE, \
654 .owner = THIS_MODULE, \
655 .min_uV = S2MPU02_LDO_MIN_1050MV, \
656 .uV_step = S2MPU02_LDO_STEP_25MV, \
657 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
658 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
659 .vsel_reg = S2MPU02_REG_L2CTRL1, \
660 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
661 .enable_reg = S2MPU02_REG_L2CTRL1, \
662 .enable_mask = S2MPU02_ENABLE_MASK \
664 #define regulator_desc_s2mpu02_ldo3(num) { \
666 .id = S2MPU02_LDO##num, \
667 .ops = &s2mpu02_ldo_ops, \
668 .type = REGULATOR_VOLTAGE, \
669 .owner = THIS_MODULE, \
670 .min_uV = S2MPU02_LDO_MIN_900MV, \
671 .uV_step = S2MPU02_LDO_STEP_12_5MV, \
672 .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
673 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
674 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
675 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
676 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
677 .enable_mask = S2MPU02_ENABLE_MASK \
679 #define regulator_desc_s2mpu02_ldo4(num) { \
681 .id = S2MPU02_LDO##num, \
682 .ops = &s2mpu02_ldo_ops, \
683 .type = REGULATOR_VOLTAGE, \
684 .owner = THIS_MODULE, \
685 .min_uV = S2MPU02_LDO_MIN_1050MV, \
686 .uV_step = S2MPU02_LDO_STEP_25MV, \
687 .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
688 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
689 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
690 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
691 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
692 .enable_mask = S2MPU02_ENABLE_MASK \
694 #define regulator_desc_s2mpu02_ldo5(num) { \
696 .id = S2MPU02_LDO##num, \
697 .ops = &s2mpu02_ldo_ops, \
698 .type = REGULATOR_VOLTAGE, \
699 .owner = THIS_MODULE, \
700 .min_uV = S2MPU02_LDO_MIN_1600MV, \
701 .uV_step = S2MPU02_LDO_STEP_50MV, \
702 .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
703 .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
704 .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
705 .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
706 .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
707 .enable_mask = S2MPU02_ENABLE_MASK \
710 #define regulator_desc_s2mpu02_buck1234(num) { \
711 .name = "BUCK"#num, \
712 .id = S2MPU02_BUCK##num, \
713 .ops = &s2mpu02_buck_ops, \
714 .type = REGULATOR_VOLTAGE, \
715 .owner = THIS_MODULE, \
716 .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
717 .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
718 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
719 .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
720 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
721 .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
722 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
723 .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
724 .enable_mask = S2MPU02_ENABLE_MASK \
726 #define regulator_desc_s2mpu02_buck5(num) { \
727 .name = "BUCK"#num, \
728 .id = S2MPU02_BUCK##num, \
729 .ops = &s2mpu02_ldo_ops, \
730 .type = REGULATOR_VOLTAGE, \
731 .owner = THIS_MODULE, \
732 .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
733 .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
734 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
735 .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
736 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
737 .vsel_reg = S2MPU02_REG_B5CTRL2, \
738 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
739 .enable_reg = S2MPU02_REG_B5CTRL1, \
740 .enable_mask = S2MPU02_ENABLE_MASK \
742 #define regulator_desc_s2mpu02_buck6(num) { \
743 .name = "BUCK"#num, \
744 .id = S2MPU02_BUCK##num, \
745 .ops = &s2mpu02_ldo_ops, \
746 .type = REGULATOR_VOLTAGE, \
747 .owner = THIS_MODULE, \
748 .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
749 .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
750 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
751 .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
752 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
753 .vsel_reg = S2MPU02_REG_B6CTRL2, \
754 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
755 .enable_reg = S2MPU02_REG_B6CTRL1, \
756 .enable_mask = S2MPU02_ENABLE_MASK \
758 #define regulator_desc_s2mpu02_buck7(num) { \
759 .name = "BUCK"#num, \
760 .id = S2MPU02_BUCK##num, \
761 .ops = &s2mpu02_ldo_ops, \
762 .type = REGULATOR_VOLTAGE, \
763 .owner = THIS_MODULE, \
764 .min_uV = S2MPU02_BUCK7_MIN_900MV, \
765 .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
766 .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
767 .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
768 .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
769 .vsel_reg = S2MPU02_REG_B7CTRL2, \
770 .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
771 .enable_reg = S2MPU02_REG_B7CTRL1, \
772 .enable_mask = S2MPU02_ENABLE_MASK \
775 static const struct regulator_desc s2mpu02_regulators[] = {
776 regulator_desc_s2mpu02_ldo1(1),
777 regulator_desc_s2mpu02_ldo2(2),
778 regulator_desc_s2mpu02_ldo4(3),
779 regulator_desc_s2mpu02_ldo5(4),
780 regulator_desc_s2mpu02_ldo4(5),
781 regulator_desc_s2mpu02_ldo3(6),
782 regulator_desc_s2mpu02_ldo3(7),
783 regulator_desc_s2mpu02_ldo4(8),
784 regulator_desc_s2mpu02_ldo5(9),
785 regulator_desc_s2mpu02_ldo3(10),
786 regulator_desc_s2mpu02_ldo4(11),
787 regulator_desc_s2mpu02_ldo5(12),
788 regulator_desc_s2mpu02_ldo5(13),
789 regulator_desc_s2mpu02_ldo5(14),
790 regulator_desc_s2mpu02_ldo5(15),
791 regulator_desc_s2mpu02_ldo5(16),
792 regulator_desc_s2mpu02_ldo4(17),
793 regulator_desc_s2mpu02_ldo5(18),
794 regulator_desc_s2mpu02_ldo3(19),
795 regulator_desc_s2mpu02_ldo4(20),
796 regulator_desc_s2mpu02_ldo5(21),
797 regulator_desc_s2mpu02_ldo5(22),
798 regulator_desc_s2mpu02_ldo5(23),
799 regulator_desc_s2mpu02_ldo4(24),
800 regulator_desc_s2mpu02_ldo5(25),
801 regulator_desc_s2mpu02_ldo4(26),
802 regulator_desc_s2mpu02_ldo5(27),
803 regulator_desc_s2mpu02_ldo5(28),
804 regulator_desc_s2mpu02_buck1234(1),
805 regulator_desc_s2mpu02_buck1234(2),
806 regulator_desc_s2mpu02_buck1234(3),
807 regulator_desc_s2mpu02_buck1234(4),
808 regulator_desc_s2mpu02_buck5(5),
809 regulator_desc_s2mpu02_buck6(6),
810 regulator_desc_s2mpu02_buck7(7),
813 static int s2mps11_pmic_probe(struct platform_device *pdev)
815 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
816 struct sec_platform_data *pdata = NULL;
817 struct of_regulator_match *rdata = NULL;
818 struct regulator_config config = { };
819 struct s2mps11_info *s2mps11;
821 const struct regulator_desc *regulators;
823 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
828 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
829 switch (s2mps11->dev_type) {
831 s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
832 regulators = s2mps11_regulators;
835 s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
836 regulators = s2mps14_regulators;
839 s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators);
840 regulators = s2mpu02_regulators;
843 dev_err(&pdev->dev, "Invalid device type: %u\n",
848 s2mps11->ext_control_gpio = devm_kzalloc(&pdev->dev,
849 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num,
851 if (!s2mps11->ext_control_gpio)
854 * 0 is a valid GPIO so initialize all GPIO-s to negative value
855 * to indicate that external control won't be used for this regulator.
857 for (i = 0; i < s2mps11->rdev_num; i++)
858 s2mps11->ext_control_gpio[i] = -EINVAL;
860 if (!iodev->dev->of_node) {
862 pdata = iodev->pdata;
865 dev_err(pdev->dev.parent,
866 "Platform data or DT node not supplied\n");
871 rdata = kzalloc(sizeof(*rdata) * s2mps11->rdev_num, GFP_KERNEL);
875 for (i = 0; i < s2mps11->rdev_num; i++)
876 rdata[i].name = regulators[i].name;
878 ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11);
883 platform_set_drvdata(pdev, s2mps11);
885 config.dev = &pdev->dev;
886 config.regmap = iodev->regmap_pmic;
887 config.driver_data = s2mps11;
888 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
889 for (i = 0; i < s2mps11->rdev_num; i++) {
890 struct regulator_dev *regulator;
893 config.init_data = pdata->regulators[i].initdata;
894 config.of_node = pdata->regulators[i].reg_node;
896 config.init_data = rdata[i].init_data;
897 config.of_node = rdata[i].of_node;
899 config.ena_gpio = s2mps11->ext_control_gpio[i];
901 regulator = devm_regulator_register(&pdev->dev,
902 ®ulators[i], &config);
903 if (IS_ERR(regulator)) {
904 ret = PTR_ERR(regulator);
905 dev_err(&pdev->dev, "regulator init failed for %d\n",
910 if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
911 ret = s2mps14_pmic_enable_ext_control(s2mps11,
915 "failed to enable GPIO control over %s: %d\n",
916 regulator->desc->name, ret);
928 static const struct platform_device_id s2mps11_pmic_id[] = {
929 { "s2mps11-pmic", S2MPS11X},
930 { "s2mps14-pmic", S2MPS14X},
931 { "s2mpu02-pmic", S2MPU02},
934 MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
936 static struct platform_driver s2mps11_pmic_driver = {
938 .name = "s2mps11-pmic",
939 .owner = THIS_MODULE,
941 .probe = s2mps11_pmic_probe,
942 .id_table = s2mps11_pmic_id,
945 static int __init s2mps11_pmic_init(void)
947 return platform_driver_register(&s2mps11_pmic_driver);
949 subsys_initcall(s2mps11_pmic_init);
951 static void __exit s2mps11_pmic_exit(void)
953 platform_driver_unregister(&s2mps11_pmic_driver);
955 module_exit(s2mps11_pmic_exit);
957 /* Module information */
958 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
959 MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPU02 Regulator Driver");
960 MODULE_LICENSE("GPL");