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/err.h>
16 #include <linux/gpio.h>
17 #include <linux/of_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/mfd/samsung/core.h>
24 #include <linux/mfd/samsung/s5m8767.h>
25 #include <linux/regulator/of_regulator.h>
27 #define S5M8767_OPMODE_NORMAL_MODE 0x1
31 struct sec_pmic_dev *iodev;
33 struct regulator_dev **rdev;
34 struct sec_opmode_data *opmode;
52 struct sec_voltage_desc {
58 static const struct sec_voltage_desc buck_voltage_val1 = {
64 static const struct sec_voltage_desc buck_voltage_val2 = {
70 static const struct sec_voltage_desc buck_voltage_val3 = {
76 static const struct sec_voltage_desc ldo_voltage_val1 = {
82 static const struct sec_voltage_desc ldo_voltage_val2 = {
88 static const struct sec_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,
128 static unsigned int s5m8767_opmode_reg[][4] = {
129 /* {OFF, ON, LOWPOWER, SUSPEND} */
131 {0x0, 0x3, 0x2, 0x1}, /* LDO1 */
132 {0x0, 0x3, 0x2, 0x1},
133 {0x0, 0x3, 0x2, 0x1},
134 {0x0, 0x0, 0x0, 0x0},
135 {0x0, 0x3, 0x2, 0x1}, /* LDO5 */
136 {0x0, 0x3, 0x2, 0x1},
137 {0x0, 0x3, 0x2, 0x1},
138 {0x0, 0x3, 0x2, 0x1},
139 {0x0, 0x3, 0x2, 0x1},
140 {0x0, 0x3, 0x2, 0x1}, /* LDO10 */
141 {0x0, 0x3, 0x2, 0x1},
142 {0x0, 0x3, 0x2, 0x1},
143 {0x0, 0x3, 0x2, 0x1},
144 {0x0, 0x3, 0x2, 0x1},
145 {0x0, 0x3, 0x2, 0x1}, /* LDO15 */
146 {0x0, 0x3, 0x2, 0x1},
147 {0x0, 0x3, 0x2, 0x1},
148 {0x0, 0x0, 0x0, 0x0},
149 {0x0, 0x3, 0x2, 0x1},
150 {0x0, 0x3, 0x2, 0x1}, /* LDO20 */
151 {0x0, 0x3, 0x2, 0x1},
152 {0x0, 0x3, 0x2, 0x1},
153 {0x0, 0x0, 0x0, 0x0},
154 {0x0, 0x3, 0x2, 0x1},
155 {0x0, 0x3, 0x2, 0x1}, /* LDO25 */
156 {0x0, 0x3, 0x2, 0x1},
157 {0x0, 0x3, 0x2, 0x1},
158 {0x0, 0x3, 0x2, 0x1}, /* LDO28 */
160 /* BUCK1 ... BUCK9 */
161 {0x0, 0x3, 0x1, 0x1}, /* BUCK1 */
162 {0x0, 0x3, 0x1, 0x1},
163 {0x0, 0x3, 0x1, 0x1},
164 {0x0, 0x3, 0x1, 0x1},
165 {0x0, 0x3, 0x2, 0x1}, /* BUCK5 */
166 {0x0, 0x3, 0x1, 0x1},
167 {0x0, 0x3, 0x1, 0x1},
168 {0x0, 0x3, 0x1, 0x1},
169 {0x0, 0x3, 0x1, 0x1}, /* BUCK9 */
172 static int s5m8767_get_register(struct regulator_dev *rdev, int *reg,
175 int i, reg_id = rdev_get_id(rdev);
177 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
180 case S5M8767_LDO1 ... S5M8767_LDO2:
181 *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1);
183 case S5M8767_LDO3 ... S5M8767_LDO28:
184 *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3);
187 *reg = S5M8767_REG_BUCK1CTRL1;
189 case S5M8767_BUCK2 ... S5M8767_BUCK4:
190 *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9;
193 *reg = S5M8767_REG_BUCK5CTRL1;
195 case S5M8767_BUCK6 ... S5M8767_BUCK9:
196 *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2;
202 for (i = 0; i < s5m8767->num_regulators; i++) {
203 if (s5m8767->opmode[i].id == reg_id) {
204 mode = s5m8767->opmode[i].mode;
209 if (i < s5m8767->num_regulators)
211 s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT;
216 static int s5m8767_reg_is_enabled(struct regulator_dev *rdev)
218 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
223 ret = s5m8767_get_register(rdev, ®, &enable_ctrl);
229 ret = sec_reg_read(s5m8767->iodev, reg, &val);
233 return (val & S5M8767_ENCTRL_MASK) == enable_ctrl;
236 static int s5m8767_reg_enable(struct regulator_dev *rdev)
238 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
242 ret = s5m8767_get_register(rdev, ®, &enable_ctrl);
246 return sec_reg_update(s5m8767->iodev, reg, enable_ctrl,
247 S5M8767_ENCTRL_MASK);
250 static int s5m8767_reg_disable(struct regulator_dev *rdev)
252 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
254 int mask = S5M8767_ENCTRL_MASK, enable_ctrl;
256 ret = s5m8767_get_register(rdev, ®, &enable_ctrl);
260 return sec_reg_update(s5m8767->iodev, reg, ~mask, mask);
263 static int s5m8767_get_vsel_reg(int reg_id, struct s5m8767_info *s5m8767)
268 case S5M8767_LDO1 ... S5M8767_LDO2:
269 reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1);
271 case S5M8767_LDO3 ... S5M8767_LDO28:
272 reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3);
275 reg = S5M8767_REG_BUCK1CTRL2;
278 reg = S5M8767_REG_BUCK2DVS1;
279 if (s5m8767->buck2_gpiodvs)
280 reg += s5m8767->buck_gpioindex;
283 reg = S5M8767_REG_BUCK3DVS1;
284 if (s5m8767->buck3_gpiodvs)
285 reg += s5m8767->buck_gpioindex;
288 reg = S5M8767_REG_BUCK4DVS1;
289 if (s5m8767->buck4_gpiodvs)
290 reg += s5m8767->buck_gpioindex;
293 reg = S5M8767_REG_BUCK5CTRL2;
295 case S5M8767_BUCK6 ... S5M8767_BUCK9:
296 reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2;
305 static int s5m8767_convert_voltage_to_sel(const struct sec_voltage_desc *desc,
313 if (min_vol > desc->max)
316 if (min_vol < desc->min)
319 selector = DIV_ROUND_UP(min_vol - desc->min, desc->step);
321 if (desc->min + desc->step * selector > desc->max)
327 static inline int s5m8767_set_high(struct s5m8767_info *s5m8767)
329 int temp_index = s5m8767->buck_gpioindex;
331 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
332 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
333 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
338 static inline int s5m8767_set_low(struct s5m8767_info *s5m8767)
340 int temp_index = s5m8767->buck_gpioindex;
342 gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
343 gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
344 gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
349 static int s5m8767_set_voltage_sel(struct regulator_dev *rdev,
352 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
353 int reg_id = rdev_get_id(rdev);
354 int old_index, index = 0;
355 u8 *buck234_vol = NULL;
358 case S5M8767_LDO1 ... S5M8767_LDO28:
360 case S5M8767_BUCK1 ... S5M8767_BUCK6:
361 if (reg_id == S5M8767_BUCK2 && s5m8767->buck2_gpiodvs)
362 buck234_vol = &s5m8767->buck2_vol[0];
363 else if (reg_id == S5M8767_BUCK3 && s5m8767->buck3_gpiodvs)
364 buck234_vol = &s5m8767->buck3_vol[0];
365 else if (reg_id == S5M8767_BUCK4 && s5m8767->buck4_gpiodvs)
366 buck234_vol = &s5m8767->buck4_vol[0];
368 case S5M8767_BUCK7 ... S5M8767_BUCK8:
376 /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */
378 while (*buck234_vol != selector) {
382 old_index = s5m8767->buck_gpioindex;
383 s5m8767->buck_gpioindex = index;
385 if (index > old_index)
386 return s5m8767_set_high(s5m8767);
388 return s5m8767_set_low(s5m8767);
390 return regulator_set_voltage_sel_regmap(rdev, selector);
394 static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev,
395 unsigned int old_sel,
396 unsigned int new_sel)
398 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
399 const struct sec_voltage_desc *desc;
400 int reg_id = rdev_get_id(rdev);
402 desc = reg_voltage_map[reg_id];
404 if ((old_sel < new_sel) && s5m8767->ramp_delay)
405 return DIV_ROUND_UP(desc->step * (new_sel - old_sel),
406 s5m8767->ramp_delay * 1000);
410 static struct regulator_ops s5m8767_ops = {
411 .list_voltage = regulator_list_voltage_linear,
412 .is_enabled = s5m8767_reg_is_enabled,
413 .enable = s5m8767_reg_enable,
414 .disable = s5m8767_reg_disable,
415 .get_voltage_sel = regulator_get_voltage_sel_regmap,
416 .set_voltage_sel = s5m8767_set_voltage_sel,
417 .set_voltage_time_sel = s5m8767_set_voltage_time_sel,
420 static struct regulator_ops s5m8767_buck78_ops = {
421 .is_enabled = s5m8767_reg_is_enabled,
422 .enable = s5m8767_reg_enable,
423 .disable = s5m8767_reg_disable,
426 #define s5m8767_regulator_desc(_name) { \
428 .id = S5M8767_##_name, \
429 .ops = &s5m8767_ops, \
430 .type = REGULATOR_VOLTAGE, \
431 .owner = THIS_MODULE, \
434 #define s5m8767_regulator_buck78_desc(_name) { \
436 .id = S5M8767_##_name, \
437 .ops = &s5m8767_buck78_ops, \
438 .type = REGULATOR_VOLTAGE, \
439 .owner = THIS_MODULE, \
442 static struct regulator_desc regulators[] = {
443 s5m8767_regulator_desc(LDO1),
444 s5m8767_regulator_desc(LDO2),
445 s5m8767_regulator_desc(LDO3),
446 s5m8767_regulator_desc(LDO4),
447 s5m8767_regulator_desc(LDO5),
448 s5m8767_regulator_desc(LDO6),
449 s5m8767_regulator_desc(LDO7),
450 s5m8767_regulator_desc(LDO8),
451 s5m8767_regulator_desc(LDO9),
452 s5m8767_regulator_desc(LDO10),
453 s5m8767_regulator_desc(LDO11),
454 s5m8767_regulator_desc(LDO12),
455 s5m8767_regulator_desc(LDO13),
456 s5m8767_regulator_desc(LDO14),
457 s5m8767_regulator_desc(LDO15),
458 s5m8767_regulator_desc(LDO16),
459 s5m8767_regulator_desc(LDO17),
460 s5m8767_regulator_desc(LDO18),
461 s5m8767_regulator_desc(LDO19),
462 s5m8767_regulator_desc(LDO20),
463 s5m8767_regulator_desc(LDO21),
464 s5m8767_regulator_desc(LDO22),
465 s5m8767_regulator_desc(LDO23),
466 s5m8767_regulator_desc(LDO24),
467 s5m8767_regulator_desc(LDO25),
468 s5m8767_regulator_desc(LDO26),
469 s5m8767_regulator_desc(LDO27),
470 s5m8767_regulator_desc(LDO28),
471 s5m8767_regulator_desc(BUCK1),
472 s5m8767_regulator_desc(BUCK2),
473 s5m8767_regulator_desc(BUCK3),
474 s5m8767_regulator_desc(BUCK4),
475 s5m8767_regulator_desc(BUCK5),
476 s5m8767_regulator_desc(BUCK6),
477 s5m8767_regulator_buck78_desc(BUCK7),
478 s5m8767_regulator_buck78_desc(BUCK8),
479 s5m8767_regulator_desc(BUCK9),
483 static int s5m8767_pmic_dt_parse_dvs_gpio(struct sec_pmic_dev *iodev,
484 struct sec_platform_data *pdata,
485 struct device_node *pmic_np)
489 for (i = 0; i < 3; i++) {
490 gpio = of_get_named_gpio(pmic_np,
491 "s5m8767,pmic-buck-dvs-gpios", i);
492 if (!gpio_is_valid(gpio)) {
493 dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
496 pdata->buck_gpios[i] = gpio;
501 static int s5m8767_pmic_dt_parse_ds_gpio(struct sec_pmic_dev *iodev,
502 struct sec_platform_data *pdata,
503 struct device_node *pmic_np)
507 for (i = 0; i < 3; i++) {
508 gpio = of_get_named_gpio(pmic_np,
509 "s5m8767,pmic-buck-ds-gpios", i);
510 if (!gpio_is_valid(gpio)) {
511 dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
514 pdata->buck_ds[i] = gpio;
519 static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
520 struct sec_platform_data *pdata)
522 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
523 struct device_node *pmic_np, *regulators_np, *reg_np;
524 struct sec_regulator_data *rdata;
525 struct sec_opmode_data *rmode;
526 unsigned int i, dvs_voltage_nr = 8, ret;
528 pmic_np = iodev->dev->of_node;
530 dev_err(iodev->dev, "could not find pmic sub-node\n");
534 regulators_np = of_find_node_by_name(pmic_np, "regulators");
535 if (!regulators_np) {
536 dev_err(iodev->dev, "could not find regulators sub-node\n");
540 /* count the number of regulators to be supported in pmic */
541 pdata->num_regulators = of_get_child_count(regulators_np);
543 rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *
544 pdata->num_regulators, GFP_KERNEL);
547 "could not allocate memory for regulator data\n");
551 rmode = devm_kzalloc(&pdev->dev, sizeof(*rmode) *
552 pdata->num_regulators, GFP_KERNEL);
555 "could not allocate memory for regulator mode\n");
559 pdata->regulators = rdata;
560 pdata->opmode = rmode;
561 for_each_child_of_node(regulators_np, reg_np) {
562 for (i = 0; i < ARRAY_SIZE(regulators); i++)
563 if (!of_node_cmp(reg_np->name, regulators[i].name))
566 if (i == ARRAY_SIZE(regulators)) {
568 "don't know how to configure regulator %s\n",
574 rdata->initdata = of_get_regulator_init_data(
576 rdata->reg_node = reg_np;
579 if (of_property_read_u32(reg_np, "op_mode",
582 "no op_mode property property at %s\n",
585 rmode->mode = S5M8767_OPMODE_NORMAL_MODE;
590 if (of_get_property(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs", NULL)) {
591 pdata->buck2_gpiodvs = true;
593 if (of_property_read_u32_array(pmic_np,
594 "s5m8767,pmic-buck2-dvs-voltage",
595 pdata->buck2_voltage, dvs_voltage_nr)) {
596 dev_err(iodev->dev, "buck2 voltages not specified\n");
601 if (of_get_property(pmic_np, "s5m8767,pmic-buck3-uses-gpio-dvs", NULL)) {
602 pdata->buck3_gpiodvs = true;
604 if (of_property_read_u32_array(pmic_np,
605 "s5m8767,pmic-buck3-dvs-voltage",
606 pdata->buck3_voltage, dvs_voltage_nr)) {
607 dev_err(iodev->dev, "buck3 voltages not specified\n");
612 if (of_get_property(pmic_np, "s5m8767,pmic-buck4-uses-gpio-dvs", NULL)) {
613 pdata->buck4_gpiodvs = true;
615 if (of_property_read_u32_array(pmic_np,
616 "s5m8767,pmic-buck4-dvs-voltage",
617 pdata->buck4_voltage, dvs_voltage_nr)) {
618 dev_err(iodev->dev, "buck4 voltages not specified\n");
623 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
624 pdata->buck4_gpiodvs) {
625 ret = s5m8767_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np);
629 if (of_property_read_u32(pmic_np,
630 "s5m8767,pmic-buck-default-dvs-idx",
631 &pdata->buck_default_idx)) {
632 pdata->buck_default_idx = 0;
634 if (pdata->buck_default_idx >= 8) {
635 pdata->buck_default_idx = 0;
637 "invalid value for default dvs index, use 0\n");
642 ret = s5m8767_pmic_dt_parse_ds_gpio(iodev, pdata, pmic_np);
646 if (of_get_property(pmic_np, "s5m8767,pmic-buck2-ramp-enable", NULL))
647 pdata->buck2_ramp_enable = true;
649 if (of_get_property(pmic_np, "s5m8767,pmic-buck3-ramp-enable", NULL))
650 pdata->buck3_ramp_enable = true;
652 if (of_get_property(pmic_np, "s5m8767,pmic-buck4-ramp-enable", NULL))
653 pdata->buck4_ramp_enable = true;
655 if (pdata->buck2_ramp_enable || pdata->buck3_ramp_enable
656 || pdata->buck4_ramp_enable) {
657 if (of_property_read_u32(pmic_np, "s5m8767,pmic-buck-ramp-delay",
658 &pdata->buck_ramp_delay))
659 pdata->buck_ramp_delay = 0;
665 static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
666 struct sec_platform_data *pdata)
670 #endif /* CONFIG_OF */
672 static int s5m8767_pmic_probe(struct platform_device *pdev)
674 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
675 struct sec_platform_data *pdata = iodev->pdata;
676 struct regulator_config config = { };
677 struct regulator_dev **rdev;
678 struct s5m8767_info *s5m8767;
679 int i, ret, size, buck_init;
682 dev_err(pdev->dev.parent, "Platform data not supplied\n");
686 if (iodev->dev->of_node) {
687 ret = s5m8767_pmic_dt_parse_pdata(pdev, pdata);
692 if (pdata->buck2_gpiodvs) {
693 if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) {
694 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
699 if (pdata->buck3_gpiodvs) {
700 if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) {
701 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
706 if (pdata->buck4_gpiodvs) {
707 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) {
708 dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
713 s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info),
718 size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2);
719 s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
723 rdev = s5m8767->rdev;
724 s5m8767->dev = &pdev->dev;
725 s5m8767->iodev = iodev;
726 s5m8767->num_regulators = pdata->num_regulators;
727 platform_set_drvdata(pdev, s5m8767);
729 s5m8767->buck_gpioindex = pdata->buck_default_idx;
730 s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs;
731 s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs;
732 s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs;
733 s5m8767->buck_gpios[0] = pdata->buck_gpios[0];
734 s5m8767->buck_gpios[1] = pdata->buck_gpios[1];
735 s5m8767->buck_gpios[2] = pdata->buck_gpios[2];
736 s5m8767->buck_ds[0] = pdata->buck_ds[0];
737 s5m8767->buck_ds[1] = pdata->buck_ds[1];
738 s5m8767->buck_ds[2] = pdata->buck_ds[2];
740 s5m8767->ramp_delay = pdata->buck_ramp_delay;
741 s5m8767->buck2_ramp = pdata->buck2_ramp_enable;
742 s5m8767->buck3_ramp = pdata->buck3_ramp_enable;
743 s5m8767->buck4_ramp = pdata->buck4_ramp_enable;
744 s5m8767->opmode = pdata->opmode;
746 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
749 sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS2, buck_init);
751 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
754 sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS2, buck_init);
756 buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2,
759 sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS2, buck_init);
761 for (i = 0; i < 8; i++) {
762 if (s5m8767->buck2_gpiodvs) {
763 s5m8767->buck2_vol[i] =
764 s5m8767_convert_voltage_to_sel(
766 pdata->buck2_voltage[i]);
769 if (s5m8767->buck3_gpiodvs) {
770 s5m8767->buck3_vol[i] =
771 s5m8767_convert_voltage_to_sel(
773 pdata->buck3_voltage[i]);
776 if (s5m8767->buck4_gpiodvs) {
777 s5m8767->buck4_vol[i] =
778 s5m8767_convert_voltage_to_sel(
780 pdata->buck4_voltage[i]);
784 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
785 pdata->buck4_gpiodvs) {
787 if (!gpio_is_valid(pdata->buck_gpios[0]) ||
788 !gpio_is_valid(pdata->buck_gpios[1]) ||
789 !gpio_is_valid(pdata->buck_gpios[2])) {
790 dev_err(&pdev->dev, "GPIO NOT VALID\n");
794 ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0],
799 ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1],
804 ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2],
810 gpio_direction_output(pdata->buck_gpios[0],
811 (s5m8767->buck_gpioindex >> 2) & 0x1);
813 gpio_direction_output(pdata->buck_gpios[1],
814 (s5m8767->buck_gpioindex >> 1) & 0x1);
816 gpio_direction_output(pdata->buck_gpios[2],
817 (s5m8767->buck_gpioindex >> 0) & 0x1);
820 ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2");
824 ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3");
828 ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4");
833 gpio_direction_output(pdata->buck_ds[0], 0x0);
835 gpio_direction_output(pdata->buck_ds[1], 0x0);
837 gpio_direction_output(pdata->buck_ds[2], 0x0);
839 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
840 pdata->buck4_gpiodvs) {
841 sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL,
842 (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1),
844 sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL,
845 (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1),
847 sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL,
848 (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1),
852 /* Initialize GPIO DVS registers */
853 for (i = 0; i < 8; i++) {
854 if (s5m8767->buck2_gpiodvs) {
855 sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i,
856 s5m8767->buck2_vol[i]);
859 if (s5m8767->buck3_gpiodvs) {
860 sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i,
861 s5m8767->buck3_vol[i]);
864 if (s5m8767->buck4_gpiodvs) {
865 sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i,
866 s5m8767->buck4_vol[i]);
870 if (s5m8767->buck2_ramp)
871 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08);
873 if (s5m8767->buck3_ramp)
874 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04);
876 if (s5m8767->buck4_ramp)
877 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02);
879 if (s5m8767->buck2_ramp || s5m8767->buck3_ramp
880 || s5m8767->buck4_ramp) {
881 switch (s5m8767->ramp_delay) {
883 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
887 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
891 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
895 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
899 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
903 sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP,
908 for (i = 0; i < pdata->num_regulators; i++) {
909 const struct sec_voltage_desc *desc;
910 int id = pdata->regulators[i].id;
912 desc = reg_voltage_map[id];
914 regulators[id].n_voltages =
915 (desc->max - desc->min) / desc->step + 1;
916 regulators[id].min_uV = desc->min;
917 regulators[id].uV_step = desc->step;
918 regulators[id].vsel_reg =
919 s5m8767_get_vsel_reg(id, s5m8767);
920 if (id < S5M8767_BUCK1)
921 regulators[id].vsel_mask = 0x3f;
923 regulators[id].vsel_mask = 0xff;
926 config.dev = s5m8767->dev;
927 config.init_data = pdata->regulators[i].initdata;
928 config.driver_data = s5m8767;
929 config.regmap = iodev->regmap;
930 config.of_node = pdata->regulators[i].reg_node;
932 rdev[i] = devm_regulator_register(&pdev->dev, ®ulators[id],
934 if (IS_ERR(rdev[i])) {
935 ret = PTR_ERR(rdev[i]);
936 dev_err(s5m8767->dev, "regulator init failed for %d\n",
945 static const struct platform_device_id s5m8767_pmic_id[] = {
946 { "s5m8767-pmic", 0},
949 MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id);
951 static struct platform_driver s5m8767_pmic_driver = {
953 .name = "s5m8767-pmic",
954 .owner = THIS_MODULE,
956 .probe = s5m8767_pmic_probe,
957 .id_table = s5m8767_pmic_id,
960 static int __init s5m8767_pmic_init(void)
962 return platform_driver_register(&s5m8767_pmic_driver);
964 subsys_initcall(s5m8767_pmic_init);
966 static void __exit s5m8767_pmic_exit(void)
968 platform_driver_unregister(&s5m8767_pmic_driver);
970 module_exit(s5m8767_pmic_exit);
972 /* Module information */
973 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
974 MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver");
975 MODULE_LICENSE("GPL");