4 * Copyright (c) 2011 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.
14 #include <linux/bug.h>
15 #include <linux/delay.h>
16 #include <linux/err.h>
17 #include <linux/gpio.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/regulator/driver.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/regulator/of_regulator.h>
24 #include <linux/mfd/s5m87xx/s5m-core.h>
25 #include <linux/mfd/s5m87xx/s5m-pmic.h>
27 #define S5M8767_OPMODE_MASK 0x3
31 struct s5m87xx_dev *iodev;
33 struct regulator_dev **rdev;
50 struct s5m_voltage_desc {
56 static const struct s5m_voltage_desc buck_voltage_val1 = {
62 static const struct s5m_voltage_desc buck_voltage_val2 = {
68 static const struct s5m_voltage_desc buck_voltage_val3 = {
74 static const struct s5m_voltage_desc ldo_voltage_val1 = {
80 static const struct s5m_voltage_desc ldo_voltage_val2 = {
86 static const struct s5m_voltage_desc *reg_voltage_map[] = {
87 [S5M8767_LDO1] = &ldo_voltage_val2,
88 [S5M8767_LDO2] = &ldo_voltage_val2,
89 [S5M8767_LDO3] = &ldo_voltage_val1,
90 [S5M8767_LDO4] = &ldo_voltage_val1,
91 [S5M8767_LDO5] = &ldo_voltage_val1,
92 [S5M8767_LDO6] = &ldo_voltage_val2,
93 [S5M8767_LDO7] = &ldo_voltage_val2,
94 [S5M8767_LDO8] = &ldo_voltage_val2,
95 [S5M8767_LDO9] = &ldo_voltage_val1,
96 [S5M8767_LDO10] = &ldo_voltage_val1,
97 [S5M8767_LDO11] = &ldo_voltage_val1,
98 [S5M8767_LDO12] = &ldo_voltage_val1,
99 [S5M8767_LDO13] = &ldo_voltage_val1,
100 [S5M8767_LDO14] = &ldo_voltage_val1,
101 [S5M8767_LDO15] = &ldo_voltage_val2,
102 [S5M8767_LDO16] = &ldo_voltage_val1,
103 [S5M8767_LDO17] = &ldo_voltage_val1,
104 [S5M8767_LDO18] = &ldo_voltage_val1,
105 [S5M8767_LDO19] = &ldo_voltage_val1,
106 [S5M8767_LDO20] = &ldo_voltage_val1,
107 [S5M8767_LDO21] = &ldo_voltage_val1,
108 [S5M8767_LDO22] = &ldo_voltage_val1,
109 [S5M8767_LDO23] = &ldo_voltage_val1,
110 [S5M8767_LDO24] = &ldo_voltage_val1,
111 [S5M8767_LDO25] = &ldo_voltage_val1,
112 [S5M8767_LDO26] = &ldo_voltage_val1,
113 [S5M8767_LDO27] = &ldo_voltage_val1,
114 [S5M8767_LDO28] = &ldo_voltage_val1,
115 [S5M8767_BUCK1] = &buck_voltage_val1,
116 [S5M8767_BUCK2] = &buck_voltage_val2,
117 [S5M8767_BUCK3] = &buck_voltage_val2,
118 [S5M8767_BUCK4] = &buck_voltage_val2,
119 [S5M8767_BUCK5] = &buck_voltage_val1,
120 [S5M8767_BUCK6] = &buck_voltage_val1,
121 [S5M8767_BUCK7] = NULL,
122 [S5M8767_BUCK8] = NULL,
123 [S5M8767_BUCK9] = &buck_voltage_val3,
126 static int s5m8767_list_voltage(struct regulator_dev *rdev,
127 unsigned int selector)
129 const struct s5m_voltage_desc *desc;
130 int reg_id = rdev_get_id(rdev);
133 if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0)
136 desc = reg_voltage_map[reg_id];
140 val = desc->min + desc->step * selector;
147 static int s5m8767_get_register(struct regulator_dev *rdev, int *reg)
149 int reg_id = rdev_get_id(rdev);
152 case S5M8767_LDO1 ... S5M8767_LDO2:
153 *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1);
155 case S5M8767_LDO3 ... S5M8767_LDO28:
156 *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3);
159 *reg = S5M8767_REG_BUCK1CTRL1;
161 case S5M8767_BUCK2 ... S5M8767_BUCK4:
162 *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9;
165 *reg = S5M8767_REG_BUCK5CTRL1;
167 case S5M8767_BUCK6 ... S5M8767_BUCK9:
168 *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2;
177 static int s5m8767_reg_is_enabled(struct regulator_dev *rdev)
179 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
181 int mask = 0xc0, pattern = 0xc0;
184 ret = s5m8767_get_register(rdev, ®);
190 ret = s5m_reg_read(s5m8767->iodev, reg, &val);
194 return (val & mask) == pattern;
197 static int s5m8767_reg_enable(struct regulator_dev *rdev)
199 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
201 int mask = 0xc0, pattern = 0xc0;
203 ret = s5m8767_get_register(rdev, ®);
207 return s5m_reg_update(s5m8767->iodev, reg, pattern, mask);
210 static int s5m8767_reg_disable(struct regulator_dev *rdev)
212 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
214 int mask = 0xc0, pattern = 0xc0;
216 ret = s5m8767_get_register(rdev, ®);
220 return s5m_reg_update(s5m8767->iodev, reg, ~pattern, mask);
223 static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg)
225 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
226 int reg_id = rdev_get_id(rdev);
230 case S5M8767_LDO1 ... S5M8767_LDO2:
231 reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1);
233 case S5M8767_LDO3 ... S5M8767_LDO28:
234 reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3);
237 reg = S5M8767_REG_BUCK1CTRL2;
240 reg = S5M8767_REG_BUCK2DVS1;
241 if (s5m8767->buck2_gpiodvs)
242 reg += s5m8767->buck_gpioindex;
245 reg = S5M8767_REG_BUCK3DVS1;
246 if (s5m8767->buck3_gpiodvs)
247 reg += s5m8767->buck_gpioindex;
250 reg = S5M8767_REG_BUCK4DVS1;
251 if (s5m8767->buck4_gpiodvs)
252 reg += s5m8767->buck_gpioindex;
255 reg = S5M8767_REG_BUCK5CTRL2;
257 case S5M8767_BUCK6 ... S5M8767_BUCK9:
258 reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2;
269 static int s5m8767_get_voltage_sel(struct regulator_dev *rdev)
271 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
273 int reg_id = rdev_get_id(rdev);
276 ret = s5m8767_get_voltage_register(rdev, ®);
280 mask = (reg_id < S5M8767_BUCK1) ? 0x3f : 0xff;
282 ret = s5m_reg_read(s5m8767->iodev, reg, &val);
291 static int s5m8767_convert_voltage_to_sel(
292 const struct s5m_voltage_desc *desc,
293 int min_vol, int max_vol)
300 if (max_vol < desc->min || min_vol > desc->max)
303 selector = (min_vol - desc->min) / desc->step;
305 if (desc->min + desc->step * selector > max_vol)
311 static int s5m8767_set_voltage(struct regulator_dev *rdev,
312 int min_uV, int max_uV, unsigned *selector)
314 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
315 const struct s5m_voltage_desc *desc;
316 int reg_id = rdev_get_id(rdev);
317 int sel, reg, mask, ret;
321 case S5M8767_LDO1 ... S5M8767_LDO28:
324 case S5M8767_BUCK1 ... S5M8767_BUCK6:
327 case S5M8767_BUCK7 ... S5M8767_BUCK8:
336 desc = reg_voltage_map[reg_id];
338 sel = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV);
342 ret = s5m8767_get_voltage_register(rdev, ®);
346 s5m_reg_read(s5m8767->iodev, reg, &val);
350 ret = s5m_reg_write(s5m8767->iodev, reg, val);
356 static inline void s5m8767_set_high(struct s5m8767_info *s5m8767)
358 int temp_index = s5m8767->buck_gpioindex;
360 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
361 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
362 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
365 static inline void s5m8767_set_low(struct s5m8767_info *s5m8767)
367 int temp_index = s5m8767->buck_gpioindex;
369 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
370 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
371 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
374 static int s5m8767_set_voltage_buck(struct regulator_dev *rdev,
375 int min_uV, int max_uV, unsigned *selector)
377 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
378 int reg_id = rdev_get_id(rdev);
379 const struct s5m_voltage_desc *desc;
380 int new_val, old_val, i = 0;
382 if (reg_id < S5M8767_BUCK1 || reg_id > S5M8767_BUCK6)
387 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
388 case S5M8767_BUCK2 ... S5M8767_BUCK4:
390 case S5M8767_BUCK5 ... S5M8767_BUCK6:
391 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
393 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
396 desc = reg_voltage_map[reg_id];
397 new_val = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV);
403 if (s5m8767->buck2_gpiodvs) {
404 while (s5m8767->buck2_vol[i] != new_val)
407 return s5m8767_set_voltage(rdev, min_uV,
411 if (s5m8767->buck3_gpiodvs) {
412 while (s5m8767->buck3_vol[i] != new_val)
415 return s5m8767_set_voltage(rdev, min_uV,
419 if (s5m8767->buck3_gpiodvs) {
420 while (s5m8767->buck4_vol[i] != new_val)
423 return s5m8767_set_voltage(rdev, min_uV,
428 old_val = s5m8767->buck_gpioindex;
429 s5m8767->buck_gpioindex = i;
432 s5m8767_set_high(s5m8767);
434 s5m8767_set_low(s5m8767);
440 static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev,
441 unsigned int old_sel,
442 unsigned int new_sel)
444 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
445 const struct s5m_voltage_desc *desc;
446 int reg_id = rdev_get_id(rdev);
448 desc = reg_voltage_map[reg_id];
450 if (old_sel < new_sel)
451 return DIV_ROUND_UP(desc->step * (new_sel - old_sel),
452 s5m8767->ramp_delay * 1000);
456 static struct regulator_ops s5m8767_ldo_ops = {
457 .list_voltage = s5m8767_list_voltage,
458 .is_enabled = s5m8767_reg_is_enabled,
459 .enable = s5m8767_reg_enable,
460 .disable = s5m8767_reg_disable,
461 .get_voltage_sel = s5m8767_get_voltage_sel,
462 .set_voltage = s5m8767_set_voltage,
463 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
466 static struct regulator_ops s5m8767_buck_ops = {
467 .list_voltage = s5m8767_list_voltage,
468 .is_enabled = s5m8767_reg_is_enabled,
469 .enable = s5m8767_reg_enable,
470 .disable = s5m8767_reg_disable,
471 .get_voltage_sel = s5m8767_get_voltage_sel,
472 .set_voltage = s5m8767_set_voltage_buck,
473 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
476 #define regulator_desc_ldo(num) { \
478 .id = S5M8767_LDO##num, \
479 .ops = &s5m8767_ldo_ops, \
480 .type = REGULATOR_VOLTAGE, \
481 .owner = THIS_MODULE, \
483 #define regulator_desc_buck(num) { \
484 .name = "BUCK"#num, \
485 .id = S5M8767_BUCK##num, \
486 .ops = &s5m8767_buck_ops, \
487 .type = REGULATOR_VOLTAGE, \
488 .owner = THIS_MODULE, \
491 static struct regulator_desc regulators[] = {
492 regulator_desc_ldo(1),
493 regulator_desc_ldo(2),
494 regulator_desc_ldo(3),
495 regulator_desc_ldo(4),
496 regulator_desc_ldo(5),
497 regulator_desc_ldo(6),
498 regulator_desc_ldo(7),
499 regulator_desc_ldo(8),
500 regulator_desc_ldo(9),
501 regulator_desc_ldo(10),
502 regulator_desc_ldo(11),
503 regulator_desc_ldo(12),
504 regulator_desc_ldo(13),
505 regulator_desc_ldo(14),
506 regulator_desc_ldo(15),
507 regulator_desc_ldo(16),
508 regulator_desc_ldo(17),
509 regulator_desc_ldo(18),
510 regulator_desc_ldo(19),
511 regulator_desc_ldo(20),
512 regulator_desc_ldo(21),
513 regulator_desc_ldo(22),
514 regulator_desc_ldo(23),
515 regulator_desc_ldo(24),
516 regulator_desc_ldo(25),
517 regulator_desc_ldo(26),
518 regulator_desc_ldo(27),
519 regulator_desc_ldo(28),
520 regulator_desc_buck(1),
521 regulator_desc_buck(2),
522 regulator_desc_buck(3),
523 regulator_desc_buck(4),
524 regulator_desc_buck(5),
525 regulator_desc_buck(6),
526 regulator_desc_buck(7),
527 regulator_desc_buck(8),
528 regulator_desc_buck(9),
532 static int s5m8767_pmic_dt_parse_pdata(struct s5m87xx_dev *iodev,
533 struct s5m_platform_data *pdata)
535 struct device_node *pmic_np, *regulators_np, *reg_np;
536 struct s5m_regulator_data *rdata;
539 pmic_np = iodev->dev->of_node;
541 dev_err(iodev->dev, "could not find pmic sub-node\n");
545 regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators");
546 if (!regulators_np) {
547 dev_err(iodev->dev, "could not find regulators sub-node\n");
551 /* count the number of regulators to be supported in pmic */
552 pdata->num_regulators = 0;
553 for_each_child_of_node(regulators_np, reg_np)
554 pdata->num_regulators++;
556 rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
557 pdata->num_regulators, GFP_KERNEL);
560 "could not allocate memory for regulator data\n");
564 pdata->regulators = rdata;
565 for_each_child_of_node(regulators_np, reg_np) {
566 for (i = 0; i < ARRAY_SIZE(regulators); i++)
567 if (!of_node_cmp(reg_np->name, regulators[i].name))
570 if (i == ARRAY_SIZE(regulators)) {
572 "No configuration data for regulator %s\n",
578 rdata->initdata = of_get_regulator_init_data(
580 rdata->reg_node = reg_np;
581 if (of_property_read_u32(reg_np, "reg_op_mode",
582 &rdata->reg_op_mode)) {
583 dev_warn(iodev->dev, "no op_mode property property at %s\n",
586 * Set operating mode to NORMAL "ON" as default. The
587 * 32KHz clocks are being turned on and kept on by
588 * default, so the below mode setting does not impact
591 rdata->reg_op_mode = S5M8767_OPMODE_MASK;
596 if (!of_property_read_u32(pmic_np, "s5m8767,buck_ramp_delay", &i))
597 pdata->buck_ramp_delay = i & 0xf;
599 if (of_get_property(pmic_np, "s5m8767,buck2_ramp_enable", NULL))
600 pdata->buck2_ramp_enable = 1;
602 if (of_get_property(pmic_np, "s5m8767,buck3_ramp_enable", NULL))
603 pdata->buck3_ramp_enable = 1;
605 if (of_get_property(pmic_np, "s5m8767,buck4_ramp_enable", NULL))
606 pdata->buck4_ramp_enable = 1;
611 static int s5m8767_pmic_dt_parse_pdata(struct s5m87xx_dev *iodev,
612 struct s5m_platform_data *pdata)
616 #endif /* CONFIG_OF */
618 static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
620 struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent);
621 struct s5m_platform_data *pdata = iodev->pdata;
622 struct regulator_dev **rdev;
623 struct s5m8767_info *s5m8767;
627 dev_err(pdev->dev.parent, "Platform data not supplied\n");
631 if (iodev->dev->of_node) {
632 ret = s5m8767_pmic_dt_parse_pdata(iodev, pdata);
637 if (pdata->buck2_gpiodvs) {
638 if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) {
639 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
644 if (pdata->buck3_gpiodvs) {
645 if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) {
646 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
651 if (pdata->buck4_gpiodvs) {
652 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) {
653 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
658 s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info),
663 if (!pdata->num_regulators)
664 pdata->num_regulators = S5M8767_REG_MAX - 2;
666 size = sizeof(struct regulator_dev *) * pdata->num_regulators;
667 s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
671 rdev = s5m8767->rdev;
672 s5m8767->dev = &pdev->dev;
673 s5m8767->iodev = iodev;
674 s5m8767->num_regulators = pdata->num_regulators;
675 platform_set_drvdata(pdev, s5m8767);
677 s5m8767->buck_gpioindex = pdata->buck_default_idx;
678 s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs;
679 s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs;
680 s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs;
681 s5m8767->buck_gpios[0] = pdata->buck_gpios[0];
682 s5m8767->buck_gpios[1] = pdata->buck_gpios[1];
683 s5m8767->buck_gpios[2] = pdata->buck_gpios[2];
684 s5m8767->ramp_delay = pdata->buck_ramp_delay;
685 s5m8767->buck2_ramp = pdata->buck2_ramp_enable;
686 s5m8767->buck3_ramp = pdata->buck3_ramp_enable;
687 s5m8767->buck4_ramp = pdata->buck4_ramp_enable;
689 for (i = 0; i < 8; i++) {
690 if (s5m8767->buck2_gpiodvs) {
691 s5m8767->buck2_vol[i] =
692 s5m8767_convert_voltage_to_sel(
694 pdata->buck2_voltage[i],
695 pdata->buck2_voltage[i] +
696 buck_voltage_val2.step);
699 if (s5m8767->buck3_gpiodvs) {
700 s5m8767->buck3_vol[i] =
701 s5m8767_convert_voltage_to_sel(
703 pdata->buck3_voltage[i],
704 pdata->buck3_voltage[i] +
705 buck_voltage_val2.step);
708 if (s5m8767->buck4_gpiodvs) {
709 s5m8767->buck4_vol[i] =
710 s5m8767_convert_voltage_to_sel(
712 pdata->buck4_voltage[i],
713 pdata->buck4_voltage[i] +
714 buck_voltage_val2.step);
718 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
719 pdata->buck4_gpiodvs) {
720 if (gpio_is_valid(pdata->buck_gpios[0]) &&
721 gpio_is_valid(pdata->buck_gpios[1]) &&
722 gpio_is_valid(pdata->buck_gpios[2])) {
723 ret = gpio_request(pdata->buck_gpios[0],
726 dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n");
728 ret = gpio_request(pdata->buck_gpios[1],
731 dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n");
733 ret = gpio_request(pdata->buck_gpios[2],
736 dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n");
738 gpio_direction_output(pdata->buck_gpios[0],
739 (s5m8767->buck_gpioindex >> 2) & 0x1);
741 gpio_direction_output(pdata->buck_gpios[1],
742 (s5m8767->buck_gpioindex >> 1) & 0x1);
744 gpio_direction_output(pdata->buck_gpios[2],
745 (s5m8767->buck_gpioindex >> 0) & 0x1);
748 dev_err(&pdev->dev, "GPIO NOT VALID\n");
754 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL,
755 (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
756 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL,
757 (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
758 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL,
759 (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
761 /* Initialize GPIO DVS registers */
762 for (i = 0; i < 8; i++) {
763 if (s5m8767->buck2_gpiodvs) {
764 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i,
765 s5m8767->buck2_vol[i]);
768 if (s5m8767->buck3_gpiodvs) {
769 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i,
770 s5m8767->buck3_vol[i]);
773 if (s5m8767->buck4_gpiodvs) {
774 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i,
775 s5m8767->buck4_vol[i]);
778 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff);
779 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff);
780 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff);
782 if (s5m8767->buck2_ramp)
783 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08);
785 if (s5m8767->buck3_ramp)
786 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04);
788 if (s5m8767->buck4_ramp)
789 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02);
791 if (s5m8767->buck2_ramp || s5m8767->buck3_ramp
792 || s5m8767->buck4_ramp) {
793 switch (s5m8767->ramp_delay) {
795 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
799 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
803 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
807 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
811 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
816 for (i = 0; i < pdata->num_regulators; i++) {
817 const struct s5m_voltage_desc *desc;
818 int id = pdata->regulators[i].id;
820 desc = reg_voltage_map[id];
822 regulators[id].n_voltages =
823 (desc->max - desc->min) / desc->step + 1;
825 rdev[i] = regulator_register(®ulators[id], s5m8767->dev,
826 pdata->regulators[i].initdata,
828 pdata->regulators[i].reg_node);
829 if (IS_ERR(rdev[i])) {
830 ret = PTR_ERR(rdev[i]);
831 dev_err(s5m8767->dev, "regulator init failed for %d\n",
840 for (i = 0; i < s5m8767->num_regulators; i++)
842 regulator_unregister(rdev[i]);
847 static int __devexit s5m8767_pmic_remove(struct platform_device *pdev)
849 struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev);
850 struct regulator_dev **rdev = s5m8767->rdev;
853 for (i = 0; i < s5m8767->num_regulators; i++)
855 regulator_unregister(rdev[i]);
860 static const struct platform_device_id s5m8767_pmic_id[] = {
861 { "s5m8767-pmic", 0},
864 MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id);
866 static struct platform_driver s5m8767_pmic_driver = {
868 .name = "s5m8767-pmic",
869 .owner = THIS_MODULE,
871 .probe = s5m8767_pmic_probe,
872 .remove = __devexit_p(s5m8767_pmic_remove),
873 .id_table = s5m8767_pmic_id,
876 static int __init s5m8767_pmic_init(void)
878 return platform_driver_register(&s5m8767_pmic_driver);
880 subsys_initcall(s5m8767_pmic_init);
882 static void __exit s5m8767_pmic_exit(void)
884 platform_driver_unregister(&s5m8767_pmic_driver);
886 module_exit(s5m8767_pmic_exit);
888 /* Module information */
889 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
890 MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver");
891 MODULE_LICENSE("GPL");