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/delay.h>
32 #include <linux/platform_device.h>
33 #include <linux/regulator/driver.h>
34 #include <linux/mfd/max8998.h>
35 #include <linux/mfd/max8998-private.h>
39 struct max8998_dev
*iodev
;
41 struct regulator_dev
**rdev
;
42 u8 buck1_vol
[4]; /* voltages for selection */
44 unsigned int buck1_idx
; /* index to last changed voltage */
46 unsigned int buck2_idx
;
49 struct voltage_map_desc
{
56 static const struct voltage_map_desc ldo23_voltage_map_desc
= {
57 .min
= 800, .step
= 50, .max
= 1300,
59 static const struct voltage_map_desc ldo456711_voltage_map_desc
= {
60 .min
= 1600, .step
= 100, .max
= 3600,
62 static const struct voltage_map_desc ldo8_voltage_map_desc
= {
63 .min
= 3000, .step
= 100, .max
= 3600,
65 static const struct voltage_map_desc ldo9_voltage_map_desc
= {
66 .min
= 2800, .step
= 100, .max
= 3100,
68 static const struct voltage_map_desc ldo10_voltage_map_desc
= {
69 .min
= 950, .step
= 50, .max
= 1300,
71 static const struct voltage_map_desc ldo1213_voltage_map_desc
= {
72 .min
= 800, .step
= 100, .max
= 3300,
74 static const struct voltage_map_desc ldo1415_voltage_map_desc
= {
75 .min
= 1200, .step
= 100, .max
= 3300,
77 static const struct voltage_map_desc ldo1617_voltage_map_desc
= {
78 .min
= 1600, .step
= 100, .max
= 3600,
80 static const struct voltage_map_desc buck12_voltage_map_desc
= {
81 .min
= 750, .step
= 25, .max
= 1525,
83 static const struct voltage_map_desc buck3_voltage_map_desc
= {
84 .min
= 1600, .step
= 100, .max
= 3600,
86 static const struct voltage_map_desc buck4_voltage_map_desc
= {
87 .min
= 800, .step
= 100, .max
= 2300,
90 static const struct voltage_map_desc
*ldo_voltage_map
[] = {
93 &ldo23_voltage_map_desc
, /* LDO2 */
94 &ldo23_voltage_map_desc
, /* LDO3 */
95 &ldo456711_voltage_map_desc
, /* LDO4 */
96 &ldo456711_voltage_map_desc
, /* LDO5 */
97 &ldo456711_voltage_map_desc
, /* LDO6 */
98 &ldo456711_voltage_map_desc
, /* LDO7 */
99 &ldo8_voltage_map_desc
, /* LDO8 */
100 &ldo9_voltage_map_desc
, /* LDO9 */
101 &ldo10_voltage_map_desc
, /* LDO10 */
102 &ldo456711_voltage_map_desc
, /* LDO11 */
103 &ldo1213_voltage_map_desc
, /* LDO12 */
104 &ldo1213_voltage_map_desc
, /* LDO13 */
105 &ldo1415_voltage_map_desc
, /* LDO14 */
106 &ldo1415_voltage_map_desc
, /* LDO15 */
107 &ldo1617_voltage_map_desc
, /* LDO16 */
108 &ldo1617_voltage_map_desc
, /* LDO17 */
109 &buck12_voltage_map_desc
, /* BUCK1 */
110 &buck12_voltage_map_desc
, /* BUCK2 */
111 &buck3_voltage_map_desc
, /* BUCK3 */
112 &buck4_voltage_map_desc
, /* BUCK4 */
115 static int max8998_list_voltage(struct regulator_dev
*rdev
,
116 unsigned int selector
)
118 const struct voltage_map_desc
*desc
;
119 int ldo
= rdev_get_id(rdev
);
122 if (ldo
>= ARRAY_SIZE(ldo_voltage_map
))
125 desc
= ldo_voltage_map
[ldo
];
129 val
= desc
->min
+ desc
->step
* selector
;
136 static int max8998_get_enable_register(struct regulator_dev
*rdev
,
137 int *reg
, int *shift
)
139 int ldo
= rdev_get_id(rdev
);
142 case MAX8998_LDO2
... MAX8998_LDO5
:
143 *reg
= MAX8998_REG_ONOFF1
;
144 *shift
= 3 - (ldo
- MAX8998_LDO2
);
146 case MAX8998_LDO6
... MAX8998_LDO13
:
147 *reg
= MAX8998_REG_ONOFF2
;
148 *shift
= 7 - (ldo
- MAX8998_LDO6
);
150 case MAX8998_LDO14
... MAX8998_LDO17
:
151 *reg
= MAX8998_REG_ONOFF3
;
152 *shift
= 7 - (ldo
- MAX8998_LDO14
);
154 case MAX8998_BUCK1
... MAX8998_BUCK4
:
155 *reg
= MAX8998_REG_ONOFF1
;
156 *shift
= 7 - (ldo
- MAX8998_BUCK1
);
158 case MAX8998_EN32KHZ_AP
... MAX8998_ENVICHG
:
159 *reg
= MAX8998_REG_ONOFF4
;
160 *shift
= 7 - (ldo
- MAX8998_EN32KHZ_AP
);
162 case MAX8998_ESAFEOUT1
... MAX8998_ESAFEOUT2
:
163 *reg
= MAX8998_REG_CHGR2
;
164 *shift
= 7 - (ldo
- MAX8998_ESAFEOUT1
);
173 static int max8998_ldo_is_enabled(struct regulator_dev
*rdev
)
175 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
176 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
177 int ret
, reg
, shift
= 8;
180 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
184 ret
= max8998_read_reg(i2c
, reg
, &val
);
188 return val
& (1 << shift
);
191 static int max8998_ldo_enable(struct regulator_dev
*rdev
)
193 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
194 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
195 int reg
, shift
= 8, ret
;
197 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
201 return max8998_update_reg(i2c
, reg
, 1<<shift
, 1<<shift
);
204 static int max8998_ldo_disable(struct regulator_dev
*rdev
)
206 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
207 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
208 int reg
, shift
= 8, ret
;
210 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
214 return max8998_update_reg(i2c
, reg
, 0, 1<<shift
);
217 static int max8998_get_voltage_register(struct regulator_dev
*rdev
,
218 int *_reg
, int *_shift
, int *_mask
)
220 int ldo
= rdev_get_id(rdev
);
221 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
222 int reg
, shift
= 0, mask
= 0xff;
225 case MAX8998_LDO2
... MAX8998_LDO3
:
226 reg
= MAX8998_REG_LDO2_LDO3
;
228 if (ldo
== MAX8998_LDO2
)
233 case MAX8998_LDO4
... MAX8998_LDO7
:
234 reg
= MAX8998_REG_LDO4
+ (ldo
- MAX8998_LDO4
);
236 case MAX8998_LDO8
... MAX8998_LDO9
:
237 reg
= MAX8998_REG_LDO8_LDO9
;
239 if (ldo
== MAX8998_LDO8
)
244 case MAX8998_LDO10
... MAX8998_LDO11
:
245 reg
= MAX8998_REG_LDO10_LDO11
;
246 if (ldo
== MAX8998_LDO10
) {
254 case MAX8998_LDO12
... MAX8998_LDO17
:
255 reg
= MAX8998_REG_LDO12
+ (ldo
- MAX8998_LDO12
);
258 reg
= MAX8998_REG_BUCK1_VOLTAGE1
+ max8998
->buck1_idx
;
261 reg
= MAX8998_REG_BUCK2_VOLTAGE1
+ max8998
->buck2_idx
;
264 reg
= MAX8998_REG_BUCK3
;
267 reg
= MAX8998_REG_BUCK4
;
280 static int max8998_get_voltage(struct regulator_dev
*rdev
)
282 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
283 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
284 int reg
, shift
= 0, mask
, ret
;
287 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
291 ret
= max8998_read_reg(i2c
, reg
, &val
);
298 return max8998_list_voltage(rdev
, val
);
301 static int max8998_set_voltage_ldo(struct regulator_dev
*rdev
,
302 int min_uV
, int max_uV
, unsigned *selector
)
304 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
305 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
306 int min_vol
= min_uV
/ 1000, max_vol
= max_uV
/ 1000;
307 const struct voltage_map_desc
*desc
;
308 int ldo
= rdev_get_id(rdev
);
309 int reg
, shift
= 0, mask
, ret
;
312 if (ldo
>= ARRAY_SIZE(ldo_voltage_map
))
315 desc
= ldo_voltage_map
[ldo
];
319 if (max_vol
< desc
->min
|| min_vol
> desc
->max
)
322 while (desc
->min
+ desc
->step
*i
< min_vol
&&
323 desc
->min
+ desc
->step
*i
< desc
->max
)
326 if (desc
->min
+ desc
->step
*i
> max_vol
)
331 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
335 ret
= max8998_update_reg(i2c
, reg
, i
<<shift
, mask
<<shift
);
340 static inline void buck1_gpio_set(int gpio1
, int gpio2
, int v
)
342 gpio_set_value(gpio1
, v
& 0x1);
343 gpio_set_value(gpio2
, (v
>> 1) & 0x1);
346 static inline void buck2_gpio_set(int gpio
, int v
)
348 gpio_set_value(gpio
, v
& 0x1);
351 static int max8998_set_voltage_buck(struct regulator_dev
*rdev
,
352 int min_uV
, int max_uV
, unsigned *selector
)
354 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
355 struct max8998_platform_data
*pdata
=
356 dev_get_platdata(max8998
->iodev
->dev
);
357 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
358 int min_vol
= min_uV
/ 1000, max_vol
= max_uV
/ 1000;
359 const struct voltage_map_desc
*desc
;
360 int buck
= rdev_get_id(rdev
);
361 int reg
, shift
= 0, mask
, ret
;
362 int difference
= 0, i
= 0, j
= 0, previous_vol
= 0;
364 static u8 buck1_last_val
;
366 if (buck
>= ARRAY_SIZE(ldo_voltage_map
))
369 desc
= ldo_voltage_map
[buck
];
374 if (max_vol
< desc
->min
|| min_vol
> desc
->max
)
377 while (desc
->min
+ desc
->step
*i
< min_vol
&&
378 desc
->min
+ desc
->step
*i
< desc
->max
)
381 if (desc
->min
+ desc
->step
*i
> max_vol
)
386 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
390 previous_vol
= max8998_get_voltage(rdev
);
392 /* Check if voltage needs to be changed */
393 /* if previous_voltage equal new voltage, return */
394 if (previous_vol
== max8998_list_voltage(rdev
, i
)) {
395 dev_dbg(max8998
->dev
, "No voltage change, old:%d, new:%d\n",
396 previous_vol
, max8998_list_voltage(rdev
, i
));
402 dev_dbg(max8998
->dev
,
403 "BUCK1, i:%d, buck1_vol1:%d, buck1_vol2:%d\n"
404 "buck1_vol3:%d, buck1_vol4:%d\n",
405 i
, max8998
->buck1_vol
[0], max8998
->buck1_vol
[1],
406 max8998
->buck1_vol
[2], max8998
->buck1_vol
[3]);
408 if (gpio_is_valid(pdata
->buck1_set1
) &&
409 gpio_is_valid(pdata
->buck1_set2
)) {
411 /* check if requested voltage */
412 /* value is already defined */
413 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck1_vol
); j
++) {
414 if (max8998
->buck1_vol
[j
] == i
) {
415 max8998
->buck1_idx
= j
;
416 buck1_gpio_set(pdata
->buck1_set1
,
417 pdata
->buck1_set2
, j
);
422 if (pdata
->buck_voltage_lock
)
425 /* no predefine regulator found */
426 max8998
->buck1_idx
= (buck1_last_val
% 2) + 2;
427 dev_dbg(max8998
->dev
, "max8998->buck1_idx:%d\n",
429 max8998
->buck1_vol
[max8998
->buck1_idx
] = i
;
430 ret
= max8998_get_voltage_register(rdev
, ®
,
433 ret
= max8998_write_reg(i2c
, reg
, i
);
434 buck1_gpio_set(pdata
->buck1_set1
,
435 pdata
->buck1_set2
, max8998
->buck1_idx
);
438 dev_dbg(max8998
->dev
, "%s: SET1:%d, SET2:%d\n",
439 i2c
->name
, gpio_get_value(pdata
->buck1_set1
),
440 gpio_get_value(pdata
->buck1_set2
));
443 ret
= max8998_write_reg(i2c
, reg
, i
);
448 dev_dbg(max8998
->dev
,
449 "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n"
450 , i
, max8998
->buck2_vol
[0], max8998
->buck2_vol
[1]);
451 if (gpio_is_valid(pdata
->buck2_set3
)) {
453 /* check if requested voltage */
454 /* value is already defined */
455 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck2_vol
); j
++) {
456 if (max8998
->buck2_vol
[j
] == i
) {
457 max8998
->buck2_idx
= j
;
458 buck2_gpio_set(pdata
->buck2_set3
, j
);
463 if (pdata
->buck_voltage_lock
)
466 max8998_get_voltage_register(rdev
,
467 ®
, &shift
, &mask
);
468 ret
= max8998_write_reg(i2c
, reg
, i
);
469 max8998
->buck2_vol
[max8998
->buck2_idx
] = i
;
470 buck2_gpio_set(pdata
->buck2_set3
, max8998
->buck2_idx
);
472 dev_dbg(max8998
->dev
, "%s: SET3:%d\n", i2c
->name
,
473 gpio_get_value(pdata
->buck2_set3
));
475 ret
= max8998_write_reg(i2c
, reg
, i
);
481 ret
= max8998_update_reg(i2c
, reg
, i
<<shift
, mask
<<shift
);
485 /* Voltage stabilization */
486 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
= desc
->min
+ desc
->step
*i
- previous_vol
/1000;
495 udelay(DIV_ROUND_UP(difference
, (val
& 0x0f) + 1));
500 static struct regulator_ops max8998_ldo_ops
= {
501 .list_voltage
= max8998_list_voltage
,
502 .is_enabled
= max8998_ldo_is_enabled
,
503 .enable
= max8998_ldo_enable
,
504 .disable
= max8998_ldo_disable
,
505 .get_voltage
= max8998_get_voltage
,
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
= max8998_list_voltage
,
513 .is_enabled
= max8998_ldo_is_enabled
,
514 .enable
= max8998_ldo_enable
,
515 .disable
= max8998_ldo_disable
,
516 .get_voltage
= max8998_get_voltage
,
517 .set_voltage
= max8998_set_voltage_buck
,
518 .set_suspend_enable
= max8998_ldo_enable
,
519 .set_suspend_disable
= max8998_ldo_disable
,
522 static struct regulator_ops max8998_others_ops
= {
523 .is_enabled
= max8998_ldo_is_enabled
,
524 .enable
= max8998_ldo_enable
,
525 .disable
= max8998_ldo_disable
,
526 .set_suspend_enable
= max8998_ldo_enable
,
527 .set_suspend_disable
= max8998_ldo_disable
,
530 static struct regulator_desc regulators
[] = {
534 .ops
= &max8998_ldo_ops
,
535 .type
= REGULATOR_VOLTAGE
,
536 .owner
= THIS_MODULE
,
540 .ops
= &max8998_ldo_ops
,
541 .type
= REGULATOR_VOLTAGE
,
542 .owner
= THIS_MODULE
,
546 .ops
= &max8998_ldo_ops
,
547 .type
= REGULATOR_VOLTAGE
,
548 .owner
= THIS_MODULE
,
552 .ops
= &max8998_ldo_ops
,
553 .type
= REGULATOR_VOLTAGE
,
554 .owner
= THIS_MODULE
,
558 .ops
= &max8998_ldo_ops
,
559 .type
= REGULATOR_VOLTAGE
,
560 .owner
= THIS_MODULE
,
564 .ops
= &max8998_ldo_ops
,
565 .type
= REGULATOR_VOLTAGE
,
566 .owner
= THIS_MODULE
,
570 .ops
= &max8998_ldo_ops
,
571 .type
= REGULATOR_VOLTAGE
,
572 .owner
= THIS_MODULE
,
576 .ops
= &max8998_ldo_ops
,
577 .type
= REGULATOR_VOLTAGE
,
578 .owner
= THIS_MODULE
,
582 .ops
= &max8998_ldo_ops
,
583 .type
= REGULATOR_VOLTAGE
,
584 .owner
= THIS_MODULE
,
588 .ops
= &max8998_ldo_ops
,
589 .type
= REGULATOR_VOLTAGE
,
590 .owner
= THIS_MODULE
,
594 .ops
= &max8998_ldo_ops
,
595 .type
= REGULATOR_VOLTAGE
,
596 .owner
= THIS_MODULE
,
600 .ops
= &max8998_ldo_ops
,
601 .type
= REGULATOR_VOLTAGE
,
602 .owner
= THIS_MODULE
,
606 .ops
= &max8998_ldo_ops
,
607 .type
= REGULATOR_VOLTAGE
,
608 .owner
= THIS_MODULE
,
612 .ops
= &max8998_ldo_ops
,
613 .type
= REGULATOR_VOLTAGE
,
614 .owner
= THIS_MODULE
,
618 .ops
= &max8998_ldo_ops
,
619 .type
= REGULATOR_VOLTAGE
,
620 .owner
= THIS_MODULE
,
624 .ops
= &max8998_ldo_ops
,
625 .type
= REGULATOR_VOLTAGE
,
626 .owner
= THIS_MODULE
,
630 .ops
= &max8998_buck_ops
,
631 .type
= REGULATOR_VOLTAGE
,
632 .owner
= THIS_MODULE
,
636 .ops
= &max8998_buck_ops
,
637 .type
= REGULATOR_VOLTAGE
,
638 .owner
= THIS_MODULE
,
642 .ops
= &max8998_buck_ops
,
643 .type
= REGULATOR_VOLTAGE
,
644 .owner
= THIS_MODULE
,
648 .ops
= &max8998_buck_ops
,
649 .type
= REGULATOR_VOLTAGE
,
650 .owner
= THIS_MODULE
,
652 .name
= "EN32KHz AP",
653 .id
= MAX8998_EN32KHZ_AP
,
654 .ops
= &max8998_others_ops
,
655 .type
= REGULATOR_VOLTAGE
,
656 .owner
= THIS_MODULE
,
658 .name
= "EN32KHz CP",
659 .id
= MAX8998_EN32KHZ_CP
,
660 .ops
= &max8998_others_ops
,
661 .type
= REGULATOR_VOLTAGE
,
662 .owner
= THIS_MODULE
,
665 .id
= MAX8998_ENVICHG
,
666 .ops
= &max8998_others_ops
,
667 .type
= REGULATOR_VOLTAGE
,
668 .owner
= THIS_MODULE
,
671 .id
= MAX8998_ESAFEOUT1
,
672 .ops
= &max8998_others_ops
,
673 .type
= REGULATOR_VOLTAGE
,
674 .owner
= THIS_MODULE
,
677 .id
= MAX8998_ESAFEOUT2
,
678 .ops
= &max8998_others_ops
,
679 .type
= REGULATOR_VOLTAGE
,
680 .owner
= THIS_MODULE
,
684 static __devinit
int max8998_pmic_probe(struct platform_device
*pdev
)
686 struct max8998_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
687 struct max8998_platform_data
*pdata
= dev_get_platdata(iodev
->dev
);
688 struct regulator_dev
**rdev
;
689 struct max8998_data
*max8998
;
690 struct i2c_client
*i2c
;
694 dev_err(pdev
->dev
.parent
, "No platform init data supplied\n");
698 max8998
= kzalloc(sizeof(struct max8998_data
), GFP_KERNEL
);
702 size
= sizeof(struct regulator_dev
*) * pdata
->num_regulators
;
703 max8998
->rdev
= kzalloc(size
, GFP_KERNEL
);
704 if (!max8998
->rdev
) {
709 rdev
= max8998
->rdev
;
710 max8998
->dev
= &pdev
->dev
;
711 max8998
->iodev
= iodev
;
712 max8998
->num_regulators
= pdata
->num_regulators
;
713 platform_set_drvdata(pdev
, max8998
);
714 i2c
= max8998
->iodev
->i2c
;
716 max8998
->buck1_idx
= pdata
->buck1_default_idx
;
717 max8998
->buck2_idx
= pdata
->buck2_default_idx
;
720 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */
721 /* will be displayed */
723 /* Check if MAX8998 voltage selection GPIOs are defined */
724 if (gpio_is_valid(pdata
->buck1_set1
) &&
725 gpio_is_valid(pdata
->buck1_set2
)) {
726 /* Check if SET1 is not equal to 0 */
727 if (!pdata
->buck1_set1
) {
728 printk(KERN_ERR
"MAX8998 SET1 GPIO defined as 0 !\n");
729 WARN_ON(!pdata
->buck1_set1
);
733 /* Check if SET2 is not equal to 0 */
734 if (!pdata
->buck1_set2
) {
735 printk(KERN_ERR
"MAX8998 SET2 GPIO defined as 0 !\n");
736 WARN_ON(!pdata
->buck1_set2
);
741 gpio_request(pdata
->buck1_set1
, "MAX8998 BUCK1_SET1");
742 gpio_direction_output(pdata
->buck1_set1
,
743 max8998
->buck1_idx
& 0x1);
746 gpio_request(pdata
->buck1_set2
, "MAX8998 BUCK1_SET2");
747 gpio_direction_output(pdata
->buck1_set2
,
748 (max8998
->buck1_idx
>> 1) & 0x1);
749 /* Set predefined value for BUCK1 register 1 */
751 while (buck12_voltage_map_desc
.min
+
752 buck12_voltage_map_desc
.step
*i
753 < (pdata
->buck1_voltage1
/ 1000))
755 max8998
->buck1_vol
[0] = i
;
756 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE1
, i
);
760 /* Set predefined value for BUCK1 register 2 */
762 while (buck12_voltage_map_desc
.min
+
763 buck12_voltage_map_desc
.step
*i
764 < (pdata
->buck1_voltage2
/ 1000))
767 max8998
->buck1_vol
[1] = i
;
768 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE2
, i
);
772 /* Set predefined value for BUCK1 register 3 */
774 while (buck12_voltage_map_desc
.min
+
775 buck12_voltage_map_desc
.step
*i
776 < (pdata
->buck1_voltage3
/ 1000))
779 max8998
->buck1_vol
[2] = i
;
780 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE3
, i
);
784 /* Set predefined value for BUCK1 register 4 */
786 while (buck12_voltage_map_desc
.min
+
787 buck12_voltage_map_desc
.step
*i
788 < (pdata
->buck1_voltage4
/ 1000))
791 max8998
->buck1_vol
[3] = i
;
792 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE4
, i
);
798 if (gpio_is_valid(pdata
->buck2_set3
)) {
799 /* Check if SET3 is not equal to 0 */
800 if (!pdata
->buck2_set3
) {
801 printk(KERN_ERR
"MAX8998 SET3 GPIO defined as 0 !\n");
802 WARN_ON(!pdata
->buck2_set3
);
806 gpio_request(pdata
->buck2_set3
, "MAX8998 BUCK2_SET3");
807 gpio_direction_output(pdata
->buck2_set3
,
808 max8998
->buck2_idx
& 0x1);
810 /* BUCK2 register 1 */
812 while (buck12_voltage_map_desc
.min
+
813 buck12_voltage_map_desc
.step
*i
814 < (pdata
->buck2_voltage1
/ 1000))
816 max8998
->buck2_vol
[0] = i
;
817 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK2_VOLTAGE1
, i
);
821 /* BUCK2 register 2 */
823 while (buck12_voltage_map_desc
.min
+
824 buck12_voltage_map_desc
.step
*i
825 < (pdata
->buck2_voltage2
/ 1000))
827 max8998
->buck2_vol
[1] = i
;
828 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK2_VOLTAGE2
, i
);
833 for (i
= 0; i
< pdata
->num_regulators
; i
++) {
834 const struct voltage_map_desc
*desc
;
835 int id
= pdata
->regulators
[i
].id
;
836 int index
= id
- MAX8998_LDO2
;
838 desc
= ldo_voltage_map
[id
];
839 if (desc
&& regulators
[index
].ops
!= &max8998_others_ops
) {
840 int count
= (desc
->max
- desc
->min
) / desc
->step
+ 1;
841 regulators
[index
].n_voltages
= count
;
843 rdev
[i
] = regulator_register(®ulators
[index
], max8998
->dev
,
844 pdata
->regulators
[i
].initdata
, max8998
, NULL
);
845 if (IS_ERR(rdev
[i
])) {
846 ret
= PTR_ERR(rdev
[i
]);
847 dev_err(max8998
->dev
, "regulator init failed\n");
856 for (i
= 0; i
< max8998
->num_regulators
; i
++)
858 regulator_unregister(rdev
[i
]);
861 kfree(max8998
->rdev
);
867 static int __devexit
max8998_pmic_remove(struct platform_device
*pdev
)
869 struct max8998_data
*max8998
= platform_get_drvdata(pdev
);
870 struct regulator_dev
**rdev
= max8998
->rdev
;
873 for (i
= 0; i
< max8998
->num_regulators
; i
++)
875 regulator_unregister(rdev
[i
]);
877 kfree(max8998
->rdev
);
883 static const struct platform_device_id max8998_pmic_id
[] = {
884 { "max8998-pmic", TYPE_MAX8998
},
885 { "lp3974-pmic", TYPE_LP3974
},
888 MODULE_DEVICE_TABLE(platform
, max8998_pmic_id
);
890 static struct platform_driver max8998_pmic_driver
= {
892 .name
= "max8998-pmic",
893 .owner
= THIS_MODULE
,
895 .probe
= max8998_pmic_probe
,
896 .remove
= __devexit_p(max8998_pmic_remove
),
897 .id_table
= max8998_pmic_id
,
900 static int __init
max8998_pmic_init(void)
902 return platform_driver_register(&max8998_pmic_driver
);
904 subsys_initcall(max8998_pmic_init
);
906 static void __exit
max8998_pmic_cleanup(void)
908 platform_driver_unregister(&max8998_pmic_driver
);
910 module_exit(max8998_pmic_cleanup
);
912 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
913 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
914 MODULE_LICENSE("GPL");