2 * max8998.c - Voltage regulator driver for the Maxim 8998
4 * Copyright (C) 2009-2010 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Marek Szyprowski <m.szyprowski@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/i2c.h>
26 #include <linux/err.h>
27 #include <linux/gpio.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <linux/mutex.h>
31 #include <linux/platform_device.h>
32 #include <linux/regulator/driver.h>
33 #include <linux/mfd/max8998.h>
34 #include <linux/mfd/max8998-private.h>
38 struct max8998_dev *iodev;
40 struct regulator_dev **rdev;
41 u8 buck1_vol[4]; /* voltages for selection */
43 unsigned int buck1_idx; /* index to last changed voltage */
45 unsigned int buck2_idx;
48 struct voltage_map_desc {
55 static const struct voltage_map_desc ldo23_voltage_map_desc = {
56 .min = 800, .step = 50, .max = 1300,
58 static const struct voltage_map_desc ldo456711_voltage_map_desc = {
59 .min = 1600, .step = 100, .max = 3600,
61 static const struct voltage_map_desc ldo8_voltage_map_desc = {
62 .min = 3000, .step = 100, .max = 3600,
64 static const struct voltage_map_desc ldo9_voltage_map_desc = {
65 .min = 2800, .step = 100, .max = 3100,
67 static const struct voltage_map_desc ldo10_voltage_map_desc = {
68 .min = 950, .step = 50, .max = 1300,
70 static const struct voltage_map_desc ldo1213_voltage_map_desc = {
71 .min = 800, .step = 100, .max = 3300,
73 static const struct voltage_map_desc ldo1415_voltage_map_desc = {
74 .min = 1200, .step = 100, .max = 3300,
76 static const struct voltage_map_desc ldo1617_voltage_map_desc = {
77 .min = 1600, .step = 100, .max = 3600,
79 static const struct voltage_map_desc buck12_voltage_map_desc = {
80 .min = 750, .step = 25, .max = 1525,
82 static const struct voltage_map_desc buck3_voltage_map_desc = {
83 .min = 1600, .step = 100, .max = 3600,
85 static const struct voltage_map_desc buck4_voltage_map_desc = {
86 .min = 800, .step = 100, .max = 2300,
89 static const struct voltage_map_desc *ldo_voltage_map[] = {
92 &ldo23_voltage_map_desc, /* LDO2 */
93 &ldo23_voltage_map_desc, /* LDO3 */
94 &ldo456711_voltage_map_desc, /* LDO4 */
95 &ldo456711_voltage_map_desc, /* LDO5 */
96 &ldo456711_voltage_map_desc, /* LDO6 */
97 &ldo456711_voltage_map_desc, /* LDO7 */
98 &ldo8_voltage_map_desc, /* LDO8 */
99 &ldo9_voltage_map_desc, /* LDO9 */
100 &ldo10_voltage_map_desc, /* LDO10 */
101 &ldo456711_voltage_map_desc, /* LDO11 */
102 &ldo1213_voltage_map_desc, /* LDO12 */
103 &ldo1213_voltage_map_desc, /* LDO13 */
104 &ldo1415_voltage_map_desc, /* LDO14 */
105 &ldo1415_voltage_map_desc, /* LDO15 */
106 &ldo1617_voltage_map_desc, /* LDO16 */
107 &ldo1617_voltage_map_desc, /* LDO17 */
108 &buck12_voltage_map_desc, /* BUCK1 */
109 &buck12_voltage_map_desc, /* BUCK2 */
110 &buck3_voltage_map_desc, /* BUCK3 */
111 &buck4_voltage_map_desc, /* BUCK4 */
114 static int max8998_get_enable_register(struct regulator_dev *rdev,
115 int *reg, int *shift)
117 int ldo = rdev_get_id(rdev);
120 case MAX8998_LDO2 ... MAX8998_LDO5:
121 *reg = MAX8998_REG_ONOFF1;
122 *shift = 3 - (ldo - MAX8998_LDO2);
124 case MAX8998_LDO6 ... MAX8998_LDO13:
125 *reg = MAX8998_REG_ONOFF2;
126 *shift = 7 - (ldo - MAX8998_LDO6);
128 case MAX8998_LDO14 ... MAX8998_LDO17:
129 *reg = MAX8998_REG_ONOFF3;
130 *shift = 7 - (ldo - MAX8998_LDO14);
132 case MAX8998_BUCK1 ... MAX8998_BUCK4:
133 *reg = MAX8998_REG_ONOFF1;
134 *shift = 7 - (ldo - MAX8998_BUCK1);
136 case MAX8998_EN32KHZ_AP ... MAX8998_ENVICHG:
137 *reg = MAX8998_REG_ONOFF4;
138 *shift = 7 - (ldo - MAX8998_EN32KHZ_AP);
140 case MAX8998_ESAFEOUT1 ... MAX8998_ESAFEOUT2:
141 *reg = MAX8998_REG_CHGR2;
142 *shift = 7 - (ldo - MAX8998_ESAFEOUT1);
151 static int max8998_ldo_is_enabled(struct regulator_dev *rdev)
153 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
154 struct i2c_client *i2c = max8998->iodev->i2c;
155 int ret, reg, shift = 8;
158 ret = max8998_get_enable_register(rdev, ®, &shift);
162 ret = max8998_read_reg(i2c, reg, &val);
166 return val & (1 << shift);
169 static int max8998_ldo_enable(struct regulator_dev *rdev)
171 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
172 struct i2c_client *i2c = max8998->iodev->i2c;
173 int reg, shift = 8, ret;
175 ret = max8998_get_enable_register(rdev, ®, &shift);
179 return max8998_update_reg(i2c, reg, 1<<shift, 1<<shift);
182 static int max8998_ldo_disable(struct regulator_dev *rdev)
184 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
185 struct i2c_client *i2c = max8998->iodev->i2c;
186 int reg, shift = 8, ret;
188 ret = max8998_get_enable_register(rdev, ®, &shift);
192 return max8998_update_reg(i2c, reg, 0, 1<<shift);
195 static int max8998_get_voltage_register(struct regulator_dev *rdev,
196 int *_reg, int *_shift, int *_mask)
198 int ldo = rdev_get_id(rdev);
199 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
200 int reg, shift = 0, mask = 0xff;
203 case MAX8998_LDO2 ... MAX8998_LDO3:
204 reg = MAX8998_REG_LDO2_LDO3;
206 if (ldo == MAX8998_LDO2)
211 case MAX8998_LDO4 ... MAX8998_LDO7:
212 reg = MAX8998_REG_LDO4 + (ldo - MAX8998_LDO4);
214 case MAX8998_LDO8 ... MAX8998_LDO9:
215 reg = MAX8998_REG_LDO8_LDO9;
217 if (ldo == MAX8998_LDO8)
222 case MAX8998_LDO10 ... MAX8998_LDO11:
223 reg = MAX8998_REG_LDO10_LDO11;
224 if (ldo == MAX8998_LDO10) {
232 case MAX8998_LDO12 ... MAX8998_LDO17:
233 reg = MAX8998_REG_LDO12 + (ldo - MAX8998_LDO12);
236 reg = MAX8998_REG_BUCK1_VOLTAGE1 + max8998->buck1_idx;
239 reg = MAX8998_REG_BUCK2_VOLTAGE1 + max8998->buck2_idx;
242 reg = MAX8998_REG_BUCK3;
245 reg = MAX8998_REG_BUCK4;
258 static int max8998_get_voltage_sel(struct regulator_dev *rdev)
260 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
261 struct i2c_client *i2c = max8998->iodev->i2c;
262 int reg, shift = 0, mask, ret;
265 ret = max8998_get_voltage_register(rdev, ®, &shift, &mask);
269 ret = max8998_read_reg(i2c, reg, &val);
279 static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
280 int min_uV, int max_uV, unsigned *selector)
282 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
283 struct i2c_client *i2c = max8998->iodev->i2c;
284 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
285 const struct voltage_map_desc *desc;
286 int ldo = rdev_get_id(rdev);
287 int reg, shift = 0, mask, ret, i;
289 if (ldo >= ARRAY_SIZE(ldo_voltage_map))
292 desc = ldo_voltage_map[ldo];
296 if (max_vol < desc->min || min_vol > desc->max)
299 if (min_vol < desc->min)
302 i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
304 if (desc->min + desc->step*i > max_vol)
309 ret = max8998_get_voltage_register(rdev, ®, &shift, &mask);
313 ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift);
318 static inline void buck1_gpio_set(int gpio1, int gpio2, int v)
320 gpio_set_value(gpio1, v & 0x1);
321 gpio_set_value(gpio2, (v >> 1) & 0x1);
324 static inline void buck2_gpio_set(int gpio, int v)
326 gpio_set_value(gpio, v & 0x1);
329 static int max8998_set_voltage_buck(struct regulator_dev *rdev,
330 int min_uV, int max_uV, unsigned *selector)
332 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
333 struct max8998_platform_data *pdata =
334 dev_get_platdata(max8998->iodev->dev);
335 struct i2c_client *i2c = max8998->iodev->i2c;
336 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
337 const struct voltage_map_desc *desc;
338 int buck = rdev_get_id(rdev);
339 int reg, shift = 0, mask, ret;
340 int i, j, previous_sel;
341 static u8 buck1_last_val;
343 if (buck >= ARRAY_SIZE(ldo_voltage_map))
346 desc = ldo_voltage_map[buck];
351 if (max_vol < desc->min || min_vol > desc->max)
354 if (min_vol < desc->min)
357 i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
359 if (desc->min + desc->step*i > max_vol)
364 ret = max8998_get_voltage_register(rdev, ®, &shift, &mask);
368 previous_sel = max8998_get_voltage_sel(rdev);
370 /* Check if voltage needs to be changed */
371 /* if previous_voltage equal new voltage, return */
372 if (previous_sel == i) {
373 dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n",
374 regulator_list_voltage_linear(rdev, previous_sel),
375 regulator_list_voltage_linear(rdev, i));
381 dev_dbg(max8998->dev,
382 "BUCK1, i:%d, buck1_vol1:%d, buck1_vol2:%d\n"
383 "buck1_vol3:%d, buck1_vol4:%d\n",
384 i, max8998->buck1_vol[0], max8998->buck1_vol[1],
385 max8998->buck1_vol[2], max8998->buck1_vol[3]);
387 if (gpio_is_valid(pdata->buck1_set1) &&
388 gpio_is_valid(pdata->buck1_set2)) {
390 /* check if requested voltage */
391 /* value is already defined */
392 for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) {
393 if (max8998->buck1_vol[j] == i) {
394 max8998->buck1_idx = j;
395 buck1_gpio_set(pdata->buck1_set1,
396 pdata->buck1_set2, j);
401 if (pdata->buck_voltage_lock)
404 /* no predefine regulator found */
405 max8998->buck1_idx = (buck1_last_val % 2) + 2;
406 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n",
408 max8998->buck1_vol[max8998->buck1_idx] = i;
409 ret = max8998_get_voltage_register(rdev, ®,
412 ret = max8998_write_reg(i2c, reg, i);
413 buck1_gpio_set(pdata->buck1_set1,
414 pdata->buck1_set2, max8998->buck1_idx);
417 dev_dbg(max8998->dev, "%s: SET1:%d, SET2:%d\n",
418 i2c->name, gpio_get_value(pdata->buck1_set1),
419 gpio_get_value(pdata->buck1_set2));
422 ret = max8998_write_reg(i2c, reg, i);
427 dev_dbg(max8998->dev,
428 "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n"
429 , i, max8998->buck2_vol[0], max8998->buck2_vol[1]);
430 if (gpio_is_valid(pdata->buck2_set3)) {
432 /* check if requested voltage */
433 /* value is already defined */
434 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) {
435 if (max8998->buck2_vol[j] == i) {
436 max8998->buck2_idx = j;
437 buck2_gpio_set(pdata->buck2_set3, j);
442 if (pdata->buck_voltage_lock)
445 max8998_get_voltage_register(rdev,
446 ®, &shift, &mask);
447 ret = max8998_write_reg(i2c, reg, i);
448 max8998->buck2_vol[max8998->buck2_idx] = i;
449 buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx);
451 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name,
452 gpio_get_value(pdata->buck2_set3));
454 ret = max8998_write_reg(i2c, reg, i);
460 ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift);
467 static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev,
468 unsigned int old_selector,
469 unsigned int new_selector)
471 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
472 struct i2c_client *i2c = max8998->iodev->i2c;
473 const struct voltage_map_desc *desc;
474 int buck = rdev_get_id(rdev);
478 if (buck < MAX8998_BUCK1 || buck > MAX8998_BUCK4)
481 desc = ldo_voltage_map[buck];
483 /* Voltage stabilization */
484 ret = max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val);
488 /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */
489 /* MAX8998 has ENRAMP bit implemented, so test it*/
490 if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP))
493 difference = (new_selector - old_selector) * desc->step;
495 return difference / ((val & 0x0f) + 1);
500 static struct regulator_ops max8998_ldo_ops = {
501 .list_voltage = regulator_list_voltage_linear,
502 .is_enabled = max8998_ldo_is_enabled,
503 .enable = max8998_ldo_enable,
504 .disable = max8998_ldo_disable,
505 .get_voltage_sel = max8998_get_voltage_sel,
506 .set_voltage = max8998_set_voltage_ldo,
507 .set_suspend_enable = max8998_ldo_enable,
508 .set_suspend_disable = max8998_ldo_disable,
511 static struct regulator_ops max8998_buck_ops = {
512 .list_voltage = regulator_list_voltage_linear,
513 .is_enabled = max8998_ldo_is_enabled,
514 .enable = max8998_ldo_enable,
515 .disable = max8998_ldo_disable,
516 .get_voltage_sel = max8998_get_voltage_sel,
517 .set_voltage = max8998_set_voltage_buck,
518 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel,
519 .set_suspend_enable = max8998_ldo_enable,
520 .set_suspend_disable = max8998_ldo_disable,
523 static struct regulator_ops max8998_others_ops = {
524 .is_enabled = max8998_ldo_is_enabled,
525 .enable = max8998_ldo_enable,
526 .disable = max8998_ldo_disable,
527 .set_suspend_enable = max8998_ldo_enable,
528 .set_suspend_disable = max8998_ldo_disable,
531 static struct regulator_desc regulators[] = {
535 .ops = &max8998_ldo_ops,
536 .type = REGULATOR_VOLTAGE,
537 .owner = THIS_MODULE,
541 .ops = &max8998_ldo_ops,
542 .type = REGULATOR_VOLTAGE,
543 .owner = THIS_MODULE,
547 .ops = &max8998_ldo_ops,
548 .type = REGULATOR_VOLTAGE,
549 .owner = THIS_MODULE,
553 .ops = &max8998_ldo_ops,
554 .type = REGULATOR_VOLTAGE,
555 .owner = THIS_MODULE,
559 .ops = &max8998_ldo_ops,
560 .type = REGULATOR_VOLTAGE,
561 .owner = THIS_MODULE,
565 .ops = &max8998_ldo_ops,
566 .type = REGULATOR_VOLTAGE,
567 .owner = THIS_MODULE,
571 .ops = &max8998_ldo_ops,
572 .type = REGULATOR_VOLTAGE,
573 .owner = THIS_MODULE,
577 .ops = &max8998_ldo_ops,
578 .type = REGULATOR_VOLTAGE,
579 .owner = THIS_MODULE,
583 .ops = &max8998_ldo_ops,
584 .type = REGULATOR_VOLTAGE,
585 .owner = THIS_MODULE,
589 .ops = &max8998_ldo_ops,
590 .type = REGULATOR_VOLTAGE,
591 .owner = THIS_MODULE,
595 .ops = &max8998_ldo_ops,
596 .type = REGULATOR_VOLTAGE,
597 .owner = THIS_MODULE,
601 .ops = &max8998_ldo_ops,
602 .type = REGULATOR_VOLTAGE,
603 .owner = THIS_MODULE,
607 .ops = &max8998_ldo_ops,
608 .type = REGULATOR_VOLTAGE,
609 .owner = THIS_MODULE,
613 .ops = &max8998_ldo_ops,
614 .type = REGULATOR_VOLTAGE,
615 .owner = THIS_MODULE,
619 .ops = &max8998_ldo_ops,
620 .type = REGULATOR_VOLTAGE,
621 .owner = THIS_MODULE,
625 .ops = &max8998_ldo_ops,
626 .type = REGULATOR_VOLTAGE,
627 .owner = THIS_MODULE,
631 .ops = &max8998_buck_ops,
632 .type = REGULATOR_VOLTAGE,
633 .owner = THIS_MODULE,
637 .ops = &max8998_buck_ops,
638 .type = REGULATOR_VOLTAGE,
639 .owner = THIS_MODULE,
643 .ops = &max8998_buck_ops,
644 .type = REGULATOR_VOLTAGE,
645 .owner = THIS_MODULE,
649 .ops = &max8998_buck_ops,
650 .type = REGULATOR_VOLTAGE,
651 .owner = THIS_MODULE,
653 .name = "EN32KHz AP",
654 .id = MAX8998_EN32KHZ_AP,
655 .ops = &max8998_others_ops,
656 .type = REGULATOR_VOLTAGE,
657 .owner = THIS_MODULE,
659 .name = "EN32KHz CP",
660 .id = MAX8998_EN32KHZ_CP,
661 .ops = &max8998_others_ops,
662 .type = REGULATOR_VOLTAGE,
663 .owner = THIS_MODULE,
666 .id = MAX8998_ENVICHG,
667 .ops = &max8998_others_ops,
668 .type = REGULATOR_VOLTAGE,
669 .owner = THIS_MODULE,
672 .id = MAX8998_ESAFEOUT1,
673 .ops = &max8998_others_ops,
674 .type = REGULATOR_VOLTAGE,
675 .owner = THIS_MODULE,
678 .id = MAX8998_ESAFEOUT2,
679 .ops = &max8998_others_ops,
680 .type = REGULATOR_VOLTAGE,
681 .owner = THIS_MODULE,
685 static __devinit int max8998_pmic_probe(struct platform_device *pdev)
687 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
688 struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev);
689 struct regulator_config config = { };
690 struct regulator_dev **rdev;
691 struct max8998_data *max8998;
692 struct i2c_client *i2c;
696 dev_err(pdev->dev.parent, "No platform init data supplied\n");
700 max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_data),
705 size = sizeof(struct regulator_dev *) * pdata->num_regulators;
706 max8998->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
710 rdev = max8998->rdev;
711 max8998->dev = &pdev->dev;
712 max8998->iodev = iodev;
713 max8998->num_regulators = pdata->num_regulators;
714 platform_set_drvdata(pdev, max8998);
715 i2c = max8998->iodev->i2c;
717 max8998->buck1_idx = pdata->buck1_default_idx;
718 max8998->buck2_idx = pdata->buck2_default_idx;
721 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */
722 /* will be displayed */
724 /* Check if MAX8998 voltage selection GPIOs are defined */
725 if (gpio_is_valid(pdata->buck1_set1) &&
726 gpio_is_valid(pdata->buck1_set2)) {
727 /* Check if SET1 is not equal to 0 */
728 if (!pdata->buck1_set1) {
729 printk(KERN_ERR "MAX8998 SET1 GPIO defined as 0 !\n");
730 WARN_ON(!pdata->buck1_set1);
734 /* Check if SET2 is not equal to 0 */
735 if (!pdata->buck1_set2) {
736 printk(KERN_ERR "MAX8998 SET2 GPIO defined as 0 !\n");
737 WARN_ON(!pdata->buck1_set2);
742 gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1");
743 gpio_direction_output(pdata->buck1_set1,
744 max8998->buck1_idx & 0x1);
747 gpio_request(pdata->buck1_set2, "MAX8998 BUCK1_SET2");
748 gpio_direction_output(pdata->buck1_set2,
749 (max8998->buck1_idx >> 1) & 0x1);
750 /* Set predefined value for BUCK1 register 1 */
752 while (buck12_voltage_map_desc.min +
753 buck12_voltage_map_desc.step*i
754 < (pdata->buck1_voltage1 / 1000))
756 max8998->buck1_vol[0] = i;
757 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i);
761 /* Set predefined value for BUCK1 register 2 */
763 while (buck12_voltage_map_desc.min +
764 buck12_voltage_map_desc.step*i
765 < (pdata->buck1_voltage2 / 1000))
768 max8998->buck1_vol[1] = i;
769 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i);
773 /* Set predefined value for BUCK1 register 3 */
775 while (buck12_voltage_map_desc.min +
776 buck12_voltage_map_desc.step*i
777 < (pdata->buck1_voltage3 / 1000))
780 max8998->buck1_vol[2] = i;
781 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE3, i);
785 /* Set predefined value for BUCK1 register 4 */
787 while (buck12_voltage_map_desc.min +
788 buck12_voltage_map_desc.step*i
789 < (pdata->buck1_voltage4 / 1000))
792 max8998->buck1_vol[3] = i;
793 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE4, i);
799 if (gpio_is_valid(pdata->buck2_set3)) {
800 /* Check if SET3 is not equal to 0 */
801 if (!pdata->buck2_set3) {
802 printk(KERN_ERR "MAX8998 SET3 GPIO defined as 0 !\n");
803 WARN_ON(!pdata->buck2_set3);
807 gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3");
808 gpio_direction_output(pdata->buck2_set3,
809 max8998->buck2_idx & 0x1);
811 /* BUCK2 register 1 */
813 while (buck12_voltage_map_desc.min +
814 buck12_voltage_map_desc.step*i
815 < (pdata->buck2_voltage1 / 1000))
817 max8998->buck2_vol[0] = i;
818 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i);
822 /* BUCK2 register 2 */
824 while (buck12_voltage_map_desc.min +
825 buck12_voltage_map_desc.step*i
826 < (pdata->buck2_voltage2 / 1000))
828 max8998->buck2_vol[1] = i;
829 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i);
834 for (i = 0; i < pdata->num_regulators; i++) {
835 const struct voltage_map_desc *desc;
836 int id = pdata->regulators[i].id;
837 int index = id - MAX8998_LDO2;
839 desc = ldo_voltage_map[id];
840 if (desc && regulators[index].ops != &max8998_others_ops) {
841 int count = (desc->max - desc->min) / desc->step + 1;
843 regulators[index].n_voltages = count;
844 regulators[index].min_uV = desc->min * 1000;
845 regulators[index].uV_step = desc->step * 1000;
848 config.dev = max8998->dev;
849 config.init_data = pdata->regulators[i].initdata;
850 config.driver_data = max8998;
852 rdev[i] = regulator_register(®ulators[index], &config);
853 if (IS_ERR(rdev[i])) {
854 ret = PTR_ERR(rdev[i]);
855 dev_err(max8998->dev, "regulator init failed\n");
865 regulator_unregister(rdev[i]);
870 static int __devexit max8998_pmic_remove(struct platform_device *pdev)
872 struct max8998_data *max8998 = platform_get_drvdata(pdev);
873 struct regulator_dev **rdev = max8998->rdev;
876 for (i = 0; i < max8998->num_regulators; i++)
877 regulator_unregister(rdev[i]);
881 static const struct platform_device_id max8998_pmic_id[] = {
882 { "max8998-pmic", TYPE_MAX8998 },
883 { "lp3974-pmic", TYPE_LP3974 },
886 MODULE_DEVICE_TABLE(platform, max8998_pmic_id);
888 static struct platform_driver max8998_pmic_driver = {
890 .name = "max8998-pmic",
891 .owner = THIS_MODULE,
893 .probe = max8998_pmic_probe,
894 .remove = __devexit_p(max8998_pmic_remove),
895 .id_table = max8998_pmic_id,
898 static int __init max8998_pmic_init(void)
900 return platform_driver_register(&max8998_pmic_driver);
902 subsys_initcall(max8998_pmic_init);
904 static void __exit max8998_pmic_cleanup(void)
906 platform_driver_unregister(&max8998_pmic_driver);
908 module_exit(max8998_pmic_cleanup);
910 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
911 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
912 MODULE_LICENSE("GPL");