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 inline int max8998_get_ldo(struct regulator_dev
*rdev
)
117 return rdev_get_id(rdev
);
120 static int max8998_list_voltage(struct regulator_dev
*rdev
,
121 unsigned int selector
)
123 const struct voltage_map_desc
*desc
;
124 int ldo
= max8998_get_ldo(rdev
);
127 if (ldo
>= ARRAY_SIZE(ldo_voltage_map
))
130 desc
= ldo_voltage_map
[ldo
];
134 val
= desc
->min
+ desc
->step
* selector
;
141 static int max8998_get_enable_register(struct regulator_dev
*rdev
,
142 int *reg
, int *shift
)
144 int ldo
= max8998_get_ldo(rdev
);
147 case MAX8998_LDO2
... MAX8998_LDO5
:
148 *reg
= MAX8998_REG_ONOFF1
;
149 *shift
= 3 - (ldo
- MAX8998_LDO2
);
151 case MAX8998_LDO6
... MAX8998_LDO13
:
152 *reg
= MAX8998_REG_ONOFF2
;
153 *shift
= 7 - (ldo
- MAX8998_LDO6
);
155 case MAX8998_LDO14
... MAX8998_LDO17
:
156 *reg
= MAX8998_REG_ONOFF3
;
157 *shift
= 7 - (ldo
- MAX8998_LDO14
);
159 case MAX8998_BUCK1
... MAX8998_BUCK4
:
160 *reg
= MAX8998_REG_ONOFF1
;
161 *shift
= 7 - (ldo
- MAX8998_BUCK1
);
163 case MAX8998_EN32KHZ_AP
... MAX8998_ENVICHG
:
164 *reg
= MAX8998_REG_ONOFF4
;
165 *shift
= 7 - (ldo
- MAX8998_EN32KHZ_AP
);
167 case MAX8998_ESAFEOUT1
... MAX8998_ESAFEOUT2
:
168 *reg
= MAX8998_REG_CHGR2
;
169 *shift
= 7 - (ldo
- MAX8998_ESAFEOUT1
);
178 static int max8998_ldo_is_enabled(struct regulator_dev
*rdev
)
180 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
181 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
182 int ret
, reg
, shift
= 8;
185 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
189 ret
= max8998_read_reg(i2c
, reg
, &val
);
193 return val
& (1 << shift
);
196 static int max8998_ldo_enable(struct regulator_dev
*rdev
)
198 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
199 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
200 int reg
, shift
= 8, ret
;
202 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
206 return max8998_update_reg(i2c
, reg
, 1<<shift
, 1<<shift
);
209 static int max8998_ldo_disable(struct regulator_dev
*rdev
)
211 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
212 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
213 int reg
, shift
= 8, ret
;
215 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
219 return max8998_update_reg(i2c
, reg
, 0, 1<<shift
);
222 static int max8998_get_voltage_register(struct regulator_dev
*rdev
,
223 int *_reg
, int *_shift
, int *_mask
)
225 int ldo
= max8998_get_ldo(rdev
);
226 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
227 int reg
, shift
= 0, mask
= 0xff;
230 case MAX8998_LDO2
... MAX8998_LDO3
:
231 reg
= MAX8998_REG_LDO2_LDO3
;
233 if (ldo
== MAX8998_LDO2
)
238 case MAX8998_LDO4
... MAX8998_LDO7
:
239 reg
= MAX8998_REG_LDO4
+ (ldo
- MAX8998_LDO4
);
241 case MAX8998_LDO8
... MAX8998_LDO9
:
242 reg
= MAX8998_REG_LDO8_LDO9
;
244 if (ldo
== MAX8998_LDO8
)
249 case MAX8998_LDO10
... MAX8998_LDO11
:
250 reg
= MAX8998_REG_LDO10_LDO11
;
251 if (ldo
== MAX8998_LDO10
) {
259 case MAX8998_LDO12
... MAX8998_LDO17
:
260 reg
= MAX8998_REG_LDO12
+ (ldo
- MAX8998_LDO12
);
263 reg
= MAX8998_REG_BUCK1_VOLTAGE1
+ max8998
->buck1_idx
;
266 reg
= MAX8998_REG_BUCK2_VOLTAGE1
+ max8998
->buck2_idx
;
269 reg
= MAX8998_REG_BUCK3
;
272 reg
= MAX8998_REG_BUCK4
;
285 static int max8998_get_voltage(struct regulator_dev
*rdev
)
287 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
288 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
289 int reg
, shift
= 0, mask
, ret
;
292 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
296 ret
= max8998_read_reg(i2c
, reg
, &val
);
303 return max8998_list_voltage(rdev
, val
);
306 static int max8998_set_voltage_ldo(struct regulator_dev
*rdev
,
307 int min_uV
, int max_uV
, unsigned *selector
)
309 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
310 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
311 int min_vol
= min_uV
/ 1000, max_vol
= max_uV
/ 1000;
312 const struct voltage_map_desc
*desc
;
313 int ldo
= max8998_get_ldo(rdev
);
314 int reg
, shift
= 0, mask
, ret
;
317 if (ldo
>= ARRAY_SIZE(ldo_voltage_map
))
320 desc
= ldo_voltage_map
[ldo
];
324 if (max_vol
< desc
->min
|| min_vol
> desc
->max
)
327 while (desc
->min
+ desc
->step
*i
< min_vol
&&
328 desc
->min
+ desc
->step
*i
< desc
->max
)
331 if (desc
->min
+ desc
->step
*i
> max_vol
)
336 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
340 ret
= max8998_update_reg(i2c
, reg
, i
<<shift
, mask
<<shift
);
345 static inline void buck1_gpio_set(int gpio1
, int gpio2
, int v
)
347 gpio_set_value(gpio1
, v
& 0x1);
348 gpio_set_value(gpio2
, (v
>> 1) & 0x1);
351 static inline void buck2_gpio_set(int gpio
, int v
)
353 gpio_set_value(gpio
, v
& 0x1);
356 static int max8998_set_voltage_buck(struct regulator_dev
*rdev
,
357 int min_uV
, int max_uV
, unsigned *selector
)
359 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
360 struct max8998_platform_data
*pdata
=
361 dev_get_platdata(max8998
->iodev
->dev
);
362 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
363 int min_vol
= min_uV
/ 1000, max_vol
= max_uV
/ 1000;
364 const struct voltage_map_desc
*desc
;
365 int buck
= max8998_get_ldo(rdev
);
366 int reg
, shift
= 0, mask
, ret
;
367 int difference
= 0, i
= 0, j
= 0, previous_vol
= 0;
369 static u8 buck1_last_val
;
371 if (buck
>= ARRAY_SIZE(ldo_voltage_map
))
374 desc
= ldo_voltage_map
[buck
];
379 if (max_vol
< desc
->min
|| min_vol
> desc
->max
)
382 while (desc
->min
+ desc
->step
*i
< min_vol
&&
383 desc
->min
+ desc
->step
*i
< desc
->max
)
386 if (desc
->min
+ desc
->step
*i
> max_vol
)
391 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
395 previous_vol
= max8998_get_voltage(rdev
);
397 /* Check if voltage needs to be changed */
398 /* if previous_voltage equal new voltage, return */
399 if (previous_vol
== max8998_list_voltage(rdev
, i
)) {
400 dev_dbg(max8998
->dev
, "No voltage change, old:%d, new:%d\n",
401 previous_vol
, max8998_list_voltage(rdev
, i
));
407 dev_dbg(max8998
->dev
,
408 "BUCK1, i:%d, buck1_vol1:%d, buck1_vol2:%d\n\
409 buck1_vol3:%d, buck1_vol4:%d\n",
410 i
, max8998
->buck1_vol
[0], max8998
->buck1_vol
[1],
411 max8998
->buck1_vol
[2], max8998
->buck1_vol
[3]);
413 if (gpio_is_valid(pdata
->buck1_set1
) &&
414 gpio_is_valid(pdata
->buck1_set2
)) {
416 /* check if requested voltage */
417 /* value is already defined */
418 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck1_vol
); j
++) {
419 if (max8998
->buck1_vol
[j
] == i
) {
420 max8998
->buck1_idx
= j
;
421 buck1_gpio_set(pdata
->buck1_set1
,
422 pdata
->buck1_set2
, j
);
427 if (pdata
->buck_voltage_lock
)
430 /* no predefine regulator found */
431 max8998
->buck1_idx
= (buck1_last_val
% 2) + 2;
432 dev_dbg(max8998
->dev
, "max8998->buck1_idx:%d\n",
434 max8998
->buck1_vol
[max8998
->buck1_idx
] = i
;
435 ret
= max8998_get_voltage_register(rdev
, ®
,
438 ret
= max8998_write_reg(i2c
, reg
, i
);
439 buck1_gpio_set(pdata
->buck1_set1
,
440 pdata
->buck1_set2
, max8998
->buck1_idx
);
443 dev_dbg(max8998
->dev
, "%s: SET1:%d, SET2:%d\n",
444 i2c
->name
, gpio_get_value(pdata
->buck1_set1
),
445 gpio_get_value(pdata
->buck1_set2
));
448 ret
= max8998_write_reg(i2c
, reg
, i
);
453 dev_dbg(max8998
->dev
,
454 "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n"
455 , i
, max8998
->buck2_vol
[0], max8998
->buck2_vol
[1]);
456 if (gpio_is_valid(pdata
->buck2_set3
)) {
458 /* check if requested voltage */
459 /* value is already defined */
460 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck2_vol
); j
++) {
461 if (max8998
->buck2_vol
[j
] == i
) {
462 max8998
->buck2_idx
= j
;
463 buck2_gpio_set(pdata
->buck2_set3
, j
);
468 if (pdata
->buck_voltage_lock
)
471 max8998_get_voltage_register(rdev
,
472 ®
, &shift
, &mask
);
473 ret
= max8998_write_reg(i2c
, reg
, i
);
474 max8998
->buck2_vol
[max8998
->buck2_idx
] = i
;
475 buck2_gpio_set(pdata
->buck2_set3
, max8998
->buck2_idx
);
477 dev_dbg(max8998
->dev
, "%s: SET3:%d\n", i2c
->name
,
478 gpio_get_value(pdata
->buck2_set3
));
480 ret
= max8998_write_reg(i2c
, reg
, i
);
486 ret
= max8998_update_reg(i2c
, reg
, i
<<shift
, mask
<<shift
);
490 /* Voltage stabilization */
491 max8998_read_reg(i2c
, MAX8998_REG_ONOFF4
, &val
);
493 /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */
494 /* MAX8998 has ENRAMP bit implemented, so test it*/
495 if (max8998
->iodev
->type
== TYPE_MAX8998
&& !(val
& MAX8998_ENRAMP
))
498 difference
= desc
->min
+ desc
->step
*i
- previous_vol
/1000;
500 udelay(difference
/ ((val
& 0x0f) + 1));
505 static struct regulator_ops max8998_ldo_ops
= {
506 .list_voltage
= max8998_list_voltage
,
507 .is_enabled
= max8998_ldo_is_enabled
,
508 .enable
= max8998_ldo_enable
,
509 .disable
= max8998_ldo_disable
,
510 .get_voltage
= max8998_get_voltage
,
511 .set_voltage
= max8998_set_voltage_ldo
,
512 .set_suspend_enable
= max8998_ldo_enable
,
513 .set_suspend_disable
= max8998_ldo_disable
,
516 static struct regulator_ops max8998_buck_ops
= {
517 .list_voltage
= max8998_list_voltage
,
518 .is_enabled
= max8998_ldo_is_enabled
,
519 .enable
= max8998_ldo_enable
,
520 .disable
= max8998_ldo_disable
,
521 .get_voltage
= max8998_get_voltage
,
522 .set_voltage
= max8998_set_voltage_buck
,
523 .set_suspend_enable
= max8998_ldo_enable
,
524 .set_suspend_disable
= max8998_ldo_disable
,
527 static struct regulator_ops max8998_others_ops
= {
528 .is_enabled
= max8998_ldo_is_enabled
,
529 .enable
= max8998_ldo_enable
,
530 .disable
= max8998_ldo_disable
,
531 .set_suspend_enable
= max8998_ldo_enable
,
532 .set_suspend_disable
= max8998_ldo_disable
,
535 static struct regulator_desc regulators
[] = {
539 .ops
= &max8998_ldo_ops
,
540 .type
= REGULATOR_VOLTAGE
,
541 .owner
= THIS_MODULE
,
545 .ops
= &max8998_ldo_ops
,
546 .type
= REGULATOR_VOLTAGE
,
547 .owner
= THIS_MODULE
,
551 .ops
= &max8998_ldo_ops
,
552 .type
= REGULATOR_VOLTAGE
,
553 .owner
= THIS_MODULE
,
557 .ops
= &max8998_ldo_ops
,
558 .type
= REGULATOR_VOLTAGE
,
559 .owner
= THIS_MODULE
,
563 .ops
= &max8998_ldo_ops
,
564 .type
= REGULATOR_VOLTAGE
,
565 .owner
= THIS_MODULE
,
569 .ops
= &max8998_ldo_ops
,
570 .type
= REGULATOR_VOLTAGE
,
571 .owner
= THIS_MODULE
,
575 .ops
= &max8998_ldo_ops
,
576 .type
= REGULATOR_VOLTAGE
,
577 .owner
= THIS_MODULE
,
581 .ops
= &max8998_ldo_ops
,
582 .type
= REGULATOR_VOLTAGE
,
583 .owner
= THIS_MODULE
,
587 .ops
= &max8998_ldo_ops
,
588 .type
= REGULATOR_VOLTAGE
,
589 .owner
= THIS_MODULE
,
593 .ops
= &max8998_ldo_ops
,
594 .type
= REGULATOR_VOLTAGE
,
595 .owner
= THIS_MODULE
,
599 .ops
= &max8998_ldo_ops
,
600 .type
= REGULATOR_VOLTAGE
,
601 .owner
= THIS_MODULE
,
605 .ops
= &max8998_ldo_ops
,
606 .type
= REGULATOR_VOLTAGE
,
607 .owner
= THIS_MODULE
,
611 .ops
= &max8998_ldo_ops
,
612 .type
= REGULATOR_VOLTAGE
,
613 .owner
= THIS_MODULE
,
617 .ops
= &max8998_ldo_ops
,
618 .type
= REGULATOR_VOLTAGE
,
619 .owner
= THIS_MODULE
,
623 .ops
= &max8998_ldo_ops
,
624 .type
= REGULATOR_VOLTAGE
,
625 .owner
= THIS_MODULE
,
629 .ops
= &max8998_ldo_ops
,
630 .type
= REGULATOR_VOLTAGE
,
631 .owner
= THIS_MODULE
,
635 .ops
= &max8998_buck_ops
,
636 .type
= REGULATOR_VOLTAGE
,
637 .owner
= THIS_MODULE
,
641 .ops
= &max8998_buck_ops
,
642 .type
= REGULATOR_VOLTAGE
,
643 .owner
= THIS_MODULE
,
647 .ops
= &max8998_buck_ops
,
648 .type
= REGULATOR_VOLTAGE
,
649 .owner
= THIS_MODULE
,
653 .ops
= &max8998_buck_ops
,
654 .type
= REGULATOR_VOLTAGE
,
655 .owner
= THIS_MODULE
,
657 .name
= "EN32KHz AP",
658 .id
= MAX8998_EN32KHZ_AP
,
659 .ops
= &max8998_others_ops
,
660 .type
= REGULATOR_VOLTAGE
,
661 .owner
= THIS_MODULE
,
663 .name
= "EN32KHz CP",
664 .id
= MAX8998_EN32KHZ_CP
,
665 .ops
= &max8998_others_ops
,
666 .type
= REGULATOR_VOLTAGE
,
667 .owner
= THIS_MODULE
,
670 .id
= MAX8998_ENVICHG
,
671 .ops
= &max8998_others_ops
,
672 .type
= REGULATOR_VOLTAGE
,
673 .owner
= THIS_MODULE
,
676 .id
= MAX8998_ESAFEOUT1
,
677 .ops
= &max8998_others_ops
,
678 .type
= REGULATOR_VOLTAGE
,
679 .owner
= THIS_MODULE
,
682 .id
= MAX8998_ESAFEOUT2
,
683 .ops
= &max8998_others_ops
,
684 .type
= REGULATOR_VOLTAGE
,
685 .owner
= THIS_MODULE
,
689 static __devinit
int max8998_pmic_probe(struct platform_device
*pdev
)
691 struct max8998_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
692 struct max8998_platform_data
*pdata
= dev_get_platdata(iodev
->dev
);
693 struct regulator_dev
**rdev
;
694 struct max8998_data
*max8998
;
695 struct i2c_client
*i2c
;
699 dev_err(pdev
->dev
.parent
, "No platform init data supplied\n");
703 max8998
= kzalloc(sizeof(struct max8998_data
), GFP_KERNEL
);
707 size
= sizeof(struct regulator_dev
*) * pdata
->num_regulators
;
708 max8998
->rdev
= kzalloc(size
, GFP_KERNEL
);
709 if (!max8998
->rdev
) {
714 rdev
= max8998
->rdev
;
715 max8998
->dev
= &pdev
->dev
;
716 max8998
->iodev
= iodev
;
717 max8998
->num_regulators
= pdata
->num_regulators
;
718 platform_set_drvdata(pdev
, max8998
);
719 i2c
= max8998
->iodev
->i2c
;
721 max8998
->buck1_idx
= pdata
->buck1_default_idx
;
722 max8998
->buck2_idx
= pdata
->buck2_default_idx
;
725 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */
726 /* will be displayed */
728 /* Check if MAX8998 voltage selection GPIOs are defined */
729 if (gpio_is_valid(pdata
->buck1_set1
) &&
730 gpio_is_valid(pdata
->buck1_set2
)) {
731 /* Check if SET1 is not equal to 0 */
732 if (!pdata
->buck1_set1
) {
733 printk(KERN_ERR
"MAX8998 SET1 GPIO defined as 0 !\n");
734 WARN_ON(!pdata
->buck1_set1
);
737 /* Check if SET2 is not equal to 0 */
738 if (!pdata
->buck1_set2
) {
739 printk(KERN_ERR
"MAX8998 SET2 GPIO defined as 0 !\n");
740 WARN_ON(!pdata
->buck1_set2
);
744 gpio_request(pdata
->buck1_set1
, "MAX8998 BUCK1_SET1");
745 gpio_direction_output(pdata
->buck1_set1
,
746 max8998
->buck1_idx
& 0x1);
749 gpio_request(pdata
->buck1_set2
, "MAX8998 BUCK1_SET2");
750 gpio_direction_output(pdata
->buck1_set2
,
751 (max8998
->buck1_idx
>> 1) & 0x1);
752 /* Set predefined value for BUCK1 register 1 */
754 while (buck12_voltage_map_desc
.min
+
755 buck12_voltage_map_desc
.step
*i
756 < (pdata
->buck1_voltage1
/ 1000))
758 max8998
->buck1_vol
[0] = i
;
759 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE1
, i
);
763 /* Set predefined value for BUCK1 register 2 */
765 while (buck12_voltage_map_desc
.min
+
766 buck12_voltage_map_desc
.step
*i
767 < (pdata
->buck1_voltage2
/ 1000))
770 max8998
->buck1_vol
[1] = i
;
771 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE2
, i
);
775 /* Set predefined value for BUCK1 register 3 */
777 while (buck12_voltage_map_desc
.min
+
778 buck12_voltage_map_desc
.step
*i
779 < (pdata
->buck1_voltage3
/ 1000))
782 max8998
->buck1_vol
[2] = i
;
783 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE3
, i
);
787 /* Set predefined value for BUCK1 register 4 */
789 while (buck12_voltage_map_desc
.min
+
790 buck12_voltage_map_desc
.step
*i
791 < (pdata
->buck1_voltage4
/ 1000))
794 max8998
->buck1_vol
[3] = i
;
795 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE4
, i
);
801 if (gpio_is_valid(pdata
->buck2_set3
)) {
802 /* Check if SET3 is not equal to 0 */
803 if (!pdata
->buck2_set3
) {
804 printk(KERN_ERR
"MAX8998 SET3 GPIO defined as 0 !\n");
805 WARN_ON(!pdata
->buck2_set3
);
808 gpio_request(pdata
->buck2_set3
, "MAX8998 BUCK2_SET3");
809 gpio_direction_output(pdata
->buck2_set3
,
810 max8998
->buck2_idx
& 0x1);
812 /* BUCK2 register 1 */
814 while (buck12_voltage_map_desc
.min
+
815 buck12_voltage_map_desc
.step
*i
816 < (pdata
->buck2_voltage1
/ 1000))
818 max8998
->buck2_vol
[0] = i
;
819 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK2_VOLTAGE1
, i
);
823 /* BUCK2 register 2 */
825 while (buck12_voltage_map_desc
.min
+
826 buck12_voltage_map_desc
.step
*i
827 < (pdata
->buck2_voltage2
/ 1000))
829 printk(KERN_ERR
"i2:%d, buck2_idx:%d\n", i
, max8998
->buck2_idx
);
830 max8998
->buck2_vol
[1] = i
;
831 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK2_VOLTAGE2
, i
);
836 for (i
= 0; i
< pdata
->num_regulators
; i
++) {
837 const struct voltage_map_desc
*desc
;
838 int id
= pdata
->regulators
[i
].id
;
839 int index
= id
- MAX8998_LDO2
;
841 desc
= ldo_voltage_map
[id
];
842 if (desc
&& regulators
[index
].ops
!= &max8998_others_ops
) {
843 int count
= (desc
->max
- desc
->min
) / desc
->step
+ 1;
844 regulators
[index
].n_voltages
= count
;
846 rdev
[i
] = regulator_register(®ulators
[index
], max8998
->dev
,
847 pdata
->regulators
[i
].initdata
, max8998
);
848 if (IS_ERR(rdev
[i
])) {
849 ret
= PTR_ERR(rdev
[i
]);
850 dev_err(max8998
->dev
, "regulator init failed\n");
859 for (i
= 0; i
< max8998
->num_regulators
; i
++)
861 regulator_unregister(rdev
[i
]);
863 kfree(max8998
->rdev
);
869 static int __devexit
max8998_pmic_remove(struct platform_device
*pdev
)
871 struct max8998_data
*max8998
= platform_get_drvdata(pdev
);
872 struct regulator_dev
**rdev
= max8998
->rdev
;
875 for (i
= 0; i
< max8998
->num_regulators
; i
++)
877 regulator_unregister(rdev
[i
]);
879 kfree(max8998
->rdev
);
885 static const struct platform_device_id max8998_pmic_id
[] = {
886 { "max8998-pmic", TYPE_MAX8998
},
887 { "lp3974-pmic", TYPE_LP3974
},
891 static struct platform_driver max8998_pmic_driver
= {
893 .name
= "max8998-pmic",
894 .owner
= THIS_MODULE
,
896 .probe
= max8998_pmic_probe
,
897 .remove
= __devexit_p(max8998_pmic_remove
),
898 .id_table
= max8998_pmic_id
,
901 static int __init
max8998_pmic_init(void)
903 return platform_driver_register(&max8998_pmic_driver
);
905 subsys_initcall(max8998_pmic_init
);
907 static void __exit
max8998_pmic_cleanup(void)
909 platform_driver_unregister(&max8998_pmic_driver
);
911 module_exit(max8998_pmic_cleanup
);
913 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
914 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
915 MODULE_LICENSE("GPL");