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
28 #define S5M8767_OPMODE_SHIFT 6
29 #define S5M8767_OPMODE_SM (S5M8767_OPMODE_MASK << S5M8767_OPMODE_SHIFT)
33 struct s5m87xx_dev *iodev;
35 struct regulator_dev **rdev;
52 struct s5m_voltage_desc {
58 static const struct s5m_voltage_desc buck_voltage_val1 = {
64 static const struct s5m_voltage_desc buck_voltage_val2 = {
70 static const struct s5m_voltage_desc buck_voltage_val3 = {
76 static const struct s5m_voltage_desc ldo_voltage_val1 = {
82 static const struct s5m_voltage_desc ldo_voltage_val2 = {
88 static const struct s5m_voltage_desc *reg_voltage_map[] = {
89 [S5M8767_LDO1] = &ldo_voltage_val2,
90 [S5M8767_LDO2] = &ldo_voltage_val2,
91 [S5M8767_LDO3] = &ldo_voltage_val1,
92 [S5M8767_LDO4] = &ldo_voltage_val1,
93 [S5M8767_LDO5] = &ldo_voltage_val1,
94 [S5M8767_LDO6] = &ldo_voltage_val2,
95 [S5M8767_LDO7] = &ldo_voltage_val2,
96 [S5M8767_LDO8] = &ldo_voltage_val2,
97 [S5M8767_LDO9] = &ldo_voltage_val1,
98 [S5M8767_LDO10] = &ldo_voltage_val1,
99 [S5M8767_LDO11] = &ldo_voltage_val1,
100 [S5M8767_LDO12] = &ldo_voltage_val1,
101 [S5M8767_LDO13] = &ldo_voltage_val1,
102 [S5M8767_LDO14] = &ldo_voltage_val1,
103 [S5M8767_LDO15] = &ldo_voltage_val2,
104 [S5M8767_LDO16] = &ldo_voltage_val1,
105 [S5M8767_LDO17] = &ldo_voltage_val1,
106 [S5M8767_LDO18] = &ldo_voltage_val1,
107 [S5M8767_LDO19] = &ldo_voltage_val1,
108 [S5M8767_LDO20] = &ldo_voltage_val1,
109 [S5M8767_LDO21] = &ldo_voltage_val1,
110 [S5M8767_LDO22] = &ldo_voltage_val1,
111 [S5M8767_LDO23] = &ldo_voltage_val1,
112 [S5M8767_LDO24] = &ldo_voltage_val1,
113 [S5M8767_LDO25] = &ldo_voltage_val1,
114 [S5M8767_LDO26] = &ldo_voltage_val1,
115 [S5M8767_LDO27] = &ldo_voltage_val1,
116 [S5M8767_LDO28] = &ldo_voltage_val1,
117 [S5M8767_BUCK1] = &buck_voltage_val1,
118 [S5M8767_BUCK2] = &buck_voltage_val2,
119 [S5M8767_BUCK3] = &buck_voltage_val2,
120 [S5M8767_BUCK4] = &buck_voltage_val2,
121 [S5M8767_BUCK5] = &buck_voltage_val1,
122 [S5M8767_BUCK6] = &buck_voltage_val1,
123 [S5M8767_BUCK7] = NULL,
124 [S5M8767_BUCK8] = NULL,
125 [S5M8767_BUCK9] = &buck_voltage_val3,
126 [S5M8767_EN32KHZ_AP] = NULL,
127 [S5M8767_EN32KHZ_CP] = NULL,
128 [S5M8767_EN32KHZ_BT] = NULL,
131 static int s5m8767_list_voltage(struct regulator_dev *rdev,
132 unsigned int selector)
134 const struct s5m_voltage_desc *desc;
135 int reg_id = rdev_get_id(rdev);
138 if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0)
141 desc = reg_voltage_map[reg_id];
145 val = desc->min + desc->step * selector;
152 static int s5m8767_get_register(struct regulator_dev *rdev,
153 int *reg, int *mask, int *pattern)
155 int reg_id = rdev_get_id(rdev);
156 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
159 for (i = 0; i < s5m8767->iodev->pdata->num_regulators; i++)
160 if (reg_id == s5m8767->iodev->pdata->regulators[i].id)
163 if (i == s5m8767->iodev->pdata->num_regulators) {
164 dev_err(s5m8767->iodev->dev, "No matching regulators\n");
168 op_mode = s5m8767->iodev->pdata->regulators[i].reg_op_mode;
170 *pattern = op_mode << S5M8767_OPMODE_SHIFT;
171 *mask = S5M8767_OPMODE_SM;
174 case S5M8767_LDO1 ... S5M8767_LDO2:
175 *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1);
177 case S5M8767_LDO3 ... S5M8767_LDO28:
178 *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3);
181 *reg = S5M8767_REG_BUCK1CTRL1;
183 case S5M8767_BUCK2 ... S5M8767_BUCK4:
184 *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9;
187 *reg = S5M8767_REG_BUCK5CTRL1;
189 case S5M8767_BUCK6 ... S5M8767_BUCK9:
190 *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2;
192 case S5M8767_EN32KHZ_AP...S5M8767_EN32KHZ_BT:
193 *reg = S5M8767_REG_CTRL1;
194 *pattern = 1 << (reg_id - S5M8767_EN32KHZ_AP);
195 *mask = 1 << (reg_id - S5M8767_EN32KHZ_AP);
204 static int s5m8767_reg_is_enabled(struct regulator_dev *rdev)
206 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
207 int ret, reg, mask, pattern;
210 ret = s5m8767_get_register(rdev, ®, &mask, &pattern);
216 ret = s5m_reg_read(s5m8767->iodev, reg, &val);
220 return (val & mask) == pattern;
223 static int s5m8767_reg_enable(struct regulator_dev *rdev)
225 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
226 int ret, reg, mask, pattern;
228 ret = s5m8767_get_register(rdev, ®, &mask, &pattern);
232 return s5m_reg_update(s5m8767->iodev, reg, pattern, mask);
235 static int s5m8767_reg_disable(struct regulator_dev *rdev)
237 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
238 int ret, reg, mask, pattern;
240 ret = s5m8767_get_register(rdev, ®, &mask, &pattern);
244 return s5m_reg_update(s5m8767->iodev, reg, ~mask, mask);
247 static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg)
249 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
250 int reg_id = rdev_get_id(rdev);
254 case S5M8767_LDO1 ... S5M8767_LDO2:
255 reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1);
257 case S5M8767_LDO3 ... S5M8767_LDO28:
258 reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3);
261 reg = S5M8767_REG_BUCK1CTRL2;
264 reg = S5M8767_REG_BUCK2DVS1;
265 if (s5m8767->buck2_gpiodvs)
266 reg += s5m8767->buck_gpioindex;
269 reg = S5M8767_REG_BUCK3DVS1;
270 if (s5m8767->buck3_gpiodvs)
271 reg += s5m8767->buck_gpioindex;
274 reg = S5M8767_REG_BUCK4DVS1;
275 if (s5m8767->buck4_gpiodvs)
276 reg += s5m8767->buck_gpioindex;
279 reg = S5M8767_REG_BUCK5CTRL2;
281 case S5M8767_BUCK6 ... S5M8767_BUCK9:
282 reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2;
293 static int s5m8767_get_voltage_sel(struct regulator_dev *rdev)
295 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
297 int reg_id = rdev_get_id(rdev);
300 ret = s5m8767_get_voltage_register(rdev, ®);
304 mask = (reg_id < S5M8767_BUCK1) ? 0x3f : 0xff;
306 ret = s5m_reg_read(s5m8767->iodev, reg, &val);
315 static int s5m8767_convert_voltage_to_sel(
316 const struct s5m_voltage_desc *desc,
317 int min_vol, int max_vol)
324 if (max_vol < desc->min || min_vol > desc->max)
327 selector = (min_vol - desc->min) / desc->step;
329 if (desc->min + desc->step * selector > max_vol)
335 static int s5m8767_set_voltage(struct regulator_dev *rdev,
336 int min_uV, int max_uV, unsigned *selector)
338 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
339 const struct s5m_voltage_desc *desc;
340 int reg_id = rdev_get_id(rdev);
341 int sel, reg, mask, ret;
345 case S5M8767_LDO1 ... S5M8767_LDO28:
348 case S5M8767_BUCK1 ... S5M8767_BUCK6:
351 case S5M8767_BUCK7 ... S5M8767_BUCK8:
360 desc = reg_voltage_map[reg_id];
362 sel = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV);
366 ret = s5m8767_get_voltage_register(rdev, ®);
370 s5m_reg_read(s5m8767->iodev, reg, &val);
374 ret = s5m_reg_write(s5m8767->iodev, reg, val);
380 static inline void s5m8767_set_high(struct s5m8767_info *s5m8767)
382 int temp_index = s5m8767->buck_gpioindex;
384 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
385 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
386 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
389 static inline void s5m8767_set_low(struct s5m8767_info *s5m8767)
391 int temp_index = s5m8767->buck_gpioindex;
393 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
394 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
395 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
398 static int s5m8767_set_voltage_buck(struct regulator_dev *rdev,
399 int min_uV, int max_uV, unsigned *selector)
401 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
402 int reg_id = rdev_get_id(rdev);
403 const struct s5m_voltage_desc *desc;
404 int new_val, old_val, i = 0;
406 if (reg_id < S5M8767_BUCK1 || reg_id > S5M8767_BUCK6)
411 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
412 case S5M8767_BUCK2 ... S5M8767_BUCK4:
414 case S5M8767_BUCK5 ... S5M8767_BUCK6:
415 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
417 return s5m8767_set_voltage(rdev, min_uV, max_uV, selector);
420 desc = reg_voltage_map[reg_id];
421 new_val = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV);
427 if (s5m8767->buck2_gpiodvs) {
428 while (s5m8767->buck2_vol[i] != new_val)
431 return s5m8767_set_voltage(rdev, min_uV,
435 if (s5m8767->buck3_gpiodvs) {
436 while (s5m8767->buck3_vol[i] != new_val)
439 return s5m8767_set_voltage(rdev, min_uV,
443 if (s5m8767->buck3_gpiodvs) {
444 while (s5m8767->buck4_vol[i] != new_val)
447 return s5m8767_set_voltage(rdev, min_uV,
452 old_val = s5m8767->buck_gpioindex;
453 s5m8767->buck_gpioindex = i;
456 s5m8767_set_high(s5m8767);
458 s5m8767_set_low(s5m8767);
464 static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev,
465 unsigned int old_sel,
466 unsigned int new_sel)
468 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
469 const struct s5m_voltage_desc *desc;
470 int reg_id = rdev_get_id(rdev);
472 desc = reg_voltage_map[reg_id];
474 if (old_sel < new_sel)
475 return DIV_ROUND_UP(desc->step * (new_sel - old_sel),
476 s5m8767->ramp_delay * 1000);
480 static struct regulator_ops s5m8767_ldo_ops = {
481 .list_voltage = s5m8767_list_voltage,
482 .is_enabled = s5m8767_reg_is_enabled,
483 .enable = s5m8767_reg_enable,
484 .disable = s5m8767_reg_disable,
485 .get_voltage_sel = s5m8767_get_voltage_sel,
486 .set_voltage = s5m8767_set_voltage,
487 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
490 static struct regulator_ops s5m8767_buck_ops = {
491 .list_voltage = s5m8767_list_voltage,
492 .is_enabled = s5m8767_reg_is_enabled,
493 .enable = s5m8767_reg_enable,
494 .disable = s5m8767_reg_disable,
495 .get_voltage_sel = s5m8767_get_voltage_sel,
496 .set_voltage = s5m8767_set_voltage_buck,
497 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
500 static struct regulator_ops s5m8767_32k_ops = {
501 .list_voltage = s5m8767_list_voltage,
502 .is_enabled = s5m8767_reg_is_enabled,
503 .enable = s5m8767_reg_enable,
504 .disable = s5m8767_reg_disable,
507 #define regulator_desc_ldo(num) { \
509 .id = S5M8767_LDO##num, \
510 .ops = &s5m8767_ldo_ops, \
511 .type = REGULATOR_VOLTAGE, \
512 .owner = THIS_MODULE, \
514 #define regulator_desc_buck(num) { \
515 .name = "BUCK"#num, \
516 .id = S5M8767_BUCK##num, \
517 .ops = &s5m8767_buck_ops, \
518 .type = REGULATOR_VOLTAGE, \
519 .owner = THIS_MODULE, \
521 #define regulator_desc_32khz(x) { \
522 .name = "EN32KHZ_" __stringify(x), \
523 .id = S5M8767_EN32KHZ_##x, \
524 .ops = &s5m8767_32k_ops, \
525 .type = REGULATOR_VOLTAGE, \
526 .owner = THIS_MODULE, \
529 static struct regulator_desc regulators[] = {
530 regulator_desc_ldo(1),
531 regulator_desc_ldo(2),
532 regulator_desc_ldo(3),
533 regulator_desc_ldo(4),
534 regulator_desc_ldo(5),
535 regulator_desc_ldo(6),
536 regulator_desc_ldo(7),
537 regulator_desc_ldo(8),
538 regulator_desc_ldo(9),
539 regulator_desc_ldo(10),
540 regulator_desc_ldo(11),
541 regulator_desc_ldo(12),
542 regulator_desc_ldo(13),
543 regulator_desc_ldo(14),
544 regulator_desc_ldo(15),
545 regulator_desc_ldo(16),
546 regulator_desc_ldo(17),
547 regulator_desc_ldo(18),
548 regulator_desc_ldo(19),
549 regulator_desc_ldo(20),
550 regulator_desc_ldo(21),
551 regulator_desc_ldo(22),
552 regulator_desc_ldo(23),
553 regulator_desc_ldo(24),
554 regulator_desc_ldo(25),
555 regulator_desc_ldo(26),
556 regulator_desc_ldo(27),
557 regulator_desc_ldo(28),
558 regulator_desc_buck(1),
559 regulator_desc_buck(2),
560 regulator_desc_buck(3),
561 regulator_desc_buck(4),
562 regulator_desc_buck(5),
563 regulator_desc_buck(6),
564 regulator_desc_buck(7),
565 regulator_desc_buck(8),
566 regulator_desc_buck(9),
567 regulator_desc_32khz(AP),
568 regulator_desc_32khz(CP),
569 regulator_desc_32khz(BT),
573 static int s5m8767_pmic_dt_parse_pdata(struct s5m87xx_dev *iodev,
574 struct s5m_platform_data *pdata)
576 struct device_node *pmic_np, *regulators_np, *reg_np;
577 struct s5m_regulator_data *rdata;
580 pmic_np = iodev->dev->of_node;
582 dev_err(iodev->dev, "could not find pmic sub-node\n");
586 regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators");
587 if (!regulators_np) {
588 dev_err(iodev->dev, "could not find regulators sub-node\n");
592 /* count the number of regulators to be supported in pmic */
593 pdata->num_regulators = 0;
594 for_each_child_of_node(regulators_np, reg_np)
595 pdata->num_regulators++;
597 rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
598 pdata->num_regulators, GFP_KERNEL);
601 "could not allocate memory for regulator data\n");
605 pdata->regulators = rdata;
606 for_each_child_of_node(regulators_np, reg_np) {
607 for (i = 0; i < ARRAY_SIZE(regulators); i++)
608 if (!of_node_cmp(reg_np->name, regulators[i].name))
611 if (i == ARRAY_SIZE(regulators)) {
613 "No configuration data for regulator %s\n",
619 rdata->initdata = of_get_regulator_init_data(
621 rdata->reg_node = reg_np;
622 if (of_property_read_u32(reg_np, "reg_op_mode",
623 &rdata->reg_op_mode)) {
624 dev_warn(iodev->dev, "no op_mode property property at %s\n",
627 * Set operating mode to NORMAL "ON" as default. The
628 * 32KHz clocks are being turned on and kept on by
629 * default, so the below mode setting does not impact
632 rdata->reg_op_mode = S5M8767_OPMODE_MASK;
637 if (!of_property_read_u32(pmic_np, "s5m8767,buck_ramp_delay", &i))
638 pdata->buck_ramp_delay = i & 0xf;
640 if (of_get_property(pmic_np, "s5m8767,buck2_ramp_enable", NULL))
641 pdata->buck2_ramp_enable = 1;
643 if (of_get_property(pmic_np, "s5m8767,buck3_ramp_enable", NULL))
644 pdata->buck3_ramp_enable = 1;
646 if (of_get_property(pmic_np, "s5m8767,buck4_ramp_enable", NULL))
647 pdata->buck4_ramp_enable = 1;
652 static int s5m8767_pmic_dt_parse_pdata(struct s5m87xx_dev *iodev,
653 struct s5m_platform_data *pdata)
657 #endif /* CONFIG_OF */
659 static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
661 struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent);
662 struct s5m_platform_data *pdata = iodev->pdata;
663 struct regulator_dev **rdev;
664 struct s5m8767_info *s5m8767;
668 dev_err(pdev->dev.parent, "Platform data not supplied\n");
672 if (iodev->dev->of_node) {
673 ret = s5m8767_pmic_dt_parse_pdata(iodev, pdata);
678 if (pdata->buck2_gpiodvs) {
679 if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) {
680 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
685 if (pdata->buck3_gpiodvs) {
686 if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) {
687 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
692 if (pdata->buck4_gpiodvs) {
693 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) {
694 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
699 s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info),
704 if (!pdata->num_regulators)
705 pdata->num_regulators = S5M8767_REG_MAX - 2;
707 size = sizeof(struct regulator_dev *) * pdata->num_regulators;
708 s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
712 rdev = s5m8767->rdev;
713 s5m8767->dev = &pdev->dev;
714 s5m8767->iodev = iodev;
715 s5m8767->num_regulators = pdata->num_regulators;
716 platform_set_drvdata(pdev, s5m8767);
718 s5m8767->buck_gpioindex = pdata->buck_default_idx;
719 s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs;
720 s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs;
721 s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs;
722 s5m8767->buck_gpios[0] = pdata->buck_gpios[0];
723 s5m8767->buck_gpios[1] = pdata->buck_gpios[1];
724 s5m8767->buck_gpios[2] = pdata->buck_gpios[2];
725 s5m8767->ramp_delay = pdata->buck_ramp_delay;
726 s5m8767->buck2_ramp = pdata->buck2_ramp_enable;
727 s5m8767->buck3_ramp = pdata->buck3_ramp_enable;
728 s5m8767->buck4_ramp = pdata->buck4_ramp_enable;
730 for (i = 0; i < 8; i++) {
731 if (s5m8767->buck2_gpiodvs) {
732 s5m8767->buck2_vol[i] =
733 s5m8767_convert_voltage_to_sel(
735 pdata->buck2_voltage[i],
736 pdata->buck2_voltage[i] +
737 buck_voltage_val2.step);
740 if (s5m8767->buck3_gpiodvs) {
741 s5m8767->buck3_vol[i] =
742 s5m8767_convert_voltage_to_sel(
744 pdata->buck3_voltage[i],
745 pdata->buck3_voltage[i] +
746 buck_voltage_val2.step);
749 if (s5m8767->buck4_gpiodvs) {
750 s5m8767->buck4_vol[i] =
751 s5m8767_convert_voltage_to_sel(
753 pdata->buck4_voltage[i],
754 pdata->buck4_voltage[i] +
755 buck_voltage_val2.step);
759 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
760 pdata->buck4_gpiodvs) {
761 if (gpio_is_valid(pdata->buck_gpios[0]) &&
762 gpio_is_valid(pdata->buck_gpios[1]) &&
763 gpio_is_valid(pdata->buck_gpios[2])) {
764 ret = gpio_request(pdata->buck_gpios[0],
767 dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n");
769 ret = gpio_request(pdata->buck_gpios[1],
772 dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n");
774 ret = gpio_request(pdata->buck_gpios[2],
777 dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n");
779 gpio_direction_output(pdata->buck_gpios[0],
780 (s5m8767->buck_gpioindex >> 2) & 0x1);
782 gpio_direction_output(pdata->buck_gpios[1],
783 (s5m8767->buck_gpioindex >> 1) & 0x1);
785 gpio_direction_output(pdata->buck_gpios[2],
786 (s5m8767->buck_gpioindex >> 0) & 0x1);
789 dev_err(&pdev->dev, "GPIO NOT VALID\n");
795 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL,
796 (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
797 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL,
798 (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
799 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL,
800 (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
802 /* Initialize GPIO DVS registers */
803 for (i = 0; i < 8; i++) {
804 if (s5m8767->buck2_gpiodvs) {
805 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i,
806 s5m8767->buck2_vol[i]);
809 if (s5m8767->buck3_gpiodvs) {
810 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i,
811 s5m8767->buck3_vol[i]);
814 if (s5m8767->buck4_gpiodvs) {
815 s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i,
816 s5m8767->buck4_vol[i]);
819 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff);
820 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff);
821 s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff);
823 if (s5m8767->buck2_ramp)
824 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08);
826 if (s5m8767->buck3_ramp)
827 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04);
829 if (s5m8767->buck4_ramp)
830 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02);
832 if (s5m8767->buck2_ramp || s5m8767->buck3_ramp
833 || s5m8767->buck4_ramp) {
834 switch (s5m8767->ramp_delay) {
836 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
840 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
844 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
848 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
852 s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
857 for (i = 0; i < pdata->num_regulators; i++) {
858 const struct s5m_voltage_desc *desc;
859 int id = pdata->regulators[i].id;
861 desc = reg_voltage_map[id];
863 regulators[id].n_voltages =
864 (desc->max - desc->min) / desc->step + 1;
866 rdev[i] = regulator_register(®ulators[id], s5m8767->dev,
867 pdata->regulators[i].initdata,
869 pdata->regulators[i].reg_node);
870 if (IS_ERR(rdev[i])) {
871 ret = PTR_ERR(rdev[i]);
872 dev_err(s5m8767->dev, "regulator init failed for %d\n",
881 for (i = 0; i < s5m8767->num_regulators; i++)
883 regulator_unregister(rdev[i]);
888 static int __devexit s5m8767_pmic_remove(struct platform_device *pdev)
890 struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev);
891 struct regulator_dev **rdev = s5m8767->rdev;
894 for (i = 0; i < s5m8767->num_regulators; i++)
896 regulator_unregister(rdev[i]);
901 static const struct platform_device_id s5m8767_pmic_id[] = {
902 { "s5m8767-pmic", 0},
905 MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id);
907 static struct platform_driver s5m8767_pmic_driver = {
909 .name = "s5m8767-pmic",
910 .owner = THIS_MODULE,
912 .probe = s5m8767_pmic_probe,
913 .remove = __devexit_p(s5m8767_pmic_remove),
914 .id_table = s5m8767_pmic_id,
917 static int __init s5m8767_pmic_init(void)
919 return platform_driver_register(&s5m8767_pmic_driver);
921 subsys_initcall(s5m8767_pmic_init);
923 static void __exit s5m8767_pmic_exit(void)
925 platform_driver_unregister(&s5m8767_pmic_driver);
927 module_exit(s5m8767_pmic_exit);
929 /* Module information */
930 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
931 MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver");
932 MODULE_LICENSE("GPL");