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_list_voltage(struct regulator_dev
*rdev
,
115 unsigned int selector
)
117 const struct voltage_map_desc
*desc
;
118 int ldo
= rdev_get_id(rdev
);
121 if (ldo
>= ARRAY_SIZE(ldo_voltage_map
))
124 desc
= ldo_voltage_map
[ldo
];
128 val
= desc
->min
+ desc
->step
* selector
;
135 static int max8998_get_enable_register(struct regulator_dev
*rdev
,
136 int *reg
, int *shift
)
138 int ldo
= rdev_get_id(rdev
);
141 case MAX8998_LDO2
... MAX8998_LDO5
:
142 *reg
= MAX8998_REG_ONOFF1
;
143 *shift
= 3 - (ldo
- MAX8998_LDO2
);
145 case MAX8998_LDO6
... MAX8998_LDO13
:
146 *reg
= MAX8998_REG_ONOFF2
;
147 *shift
= 7 - (ldo
- MAX8998_LDO6
);
149 case MAX8998_LDO14
... MAX8998_LDO17
:
150 *reg
= MAX8998_REG_ONOFF3
;
151 *shift
= 7 - (ldo
- MAX8998_LDO14
);
153 case MAX8998_BUCK1
... MAX8998_BUCK4
:
154 *reg
= MAX8998_REG_ONOFF1
;
155 *shift
= 7 - (ldo
- MAX8998_BUCK1
);
157 case MAX8998_EN32KHZ_AP
... MAX8998_ENVICHG
:
158 *reg
= MAX8998_REG_ONOFF4
;
159 *shift
= 7 - (ldo
- MAX8998_EN32KHZ_AP
);
161 case MAX8998_ESAFEOUT1
... MAX8998_ESAFEOUT2
:
162 *reg
= MAX8998_REG_CHGR2
;
163 *shift
= 7 - (ldo
- MAX8998_ESAFEOUT1
);
172 static int max8998_ldo_is_enabled(struct regulator_dev
*rdev
)
174 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
175 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
176 int ret
, reg
, shift
= 8;
179 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
183 ret
= max8998_read_reg(i2c
, reg
, &val
);
187 return val
& (1 << shift
);
190 static int max8998_ldo_enable(struct regulator_dev
*rdev
)
192 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
193 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
194 int reg
, shift
= 8, ret
;
196 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
200 return max8998_update_reg(i2c
, reg
, 1<<shift
, 1<<shift
);
203 static int max8998_ldo_disable(struct regulator_dev
*rdev
)
205 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
206 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
207 int reg
, shift
= 8, ret
;
209 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
213 return max8998_update_reg(i2c
, reg
, 0, 1<<shift
);
216 static int max8998_get_voltage_register(struct regulator_dev
*rdev
,
217 int *_reg
, int *_shift
, int *_mask
)
219 int ldo
= rdev_get_id(rdev
);
220 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
221 int reg
, shift
= 0, mask
= 0xff;
224 case MAX8998_LDO2
... MAX8998_LDO3
:
225 reg
= MAX8998_REG_LDO2_LDO3
;
227 if (ldo
== MAX8998_LDO2
)
232 case MAX8998_LDO4
... MAX8998_LDO7
:
233 reg
= MAX8998_REG_LDO4
+ (ldo
- MAX8998_LDO4
);
235 case MAX8998_LDO8
... MAX8998_LDO9
:
236 reg
= MAX8998_REG_LDO8_LDO9
;
238 if (ldo
== MAX8998_LDO8
)
243 case MAX8998_LDO10
... MAX8998_LDO11
:
244 reg
= MAX8998_REG_LDO10_LDO11
;
245 if (ldo
== MAX8998_LDO10
) {
253 case MAX8998_LDO12
... MAX8998_LDO17
:
254 reg
= MAX8998_REG_LDO12
+ (ldo
- MAX8998_LDO12
);
257 reg
= MAX8998_REG_BUCK1_VOLTAGE1
+ max8998
->buck1_idx
;
260 reg
= MAX8998_REG_BUCK2_VOLTAGE1
+ max8998
->buck2_idx
;
263 reg
= MAX8998_REG_BUCK3
;
266 reg
= MAX8998_REG_BUCK4
;
279 static int max8998_get_voltage_sel(struct regulator_dev
*rdev
)
281 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
282 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
283 int reg
, shift
= 0, mask
, ret
;
286 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
290 ret
= max8998_read_reg(i2c
, reg
, &val
);
300 static int max8998_set_voltage_ldo(struct regulator_dev
*rdev
,
301 int min_uV
, int max_uV
, unsigned *selector
)
303 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
304 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
305 int min_vol
= min_uV
/ 1000, max_vol
= max_uV
/ 1000;
306 const struct voltage_map_desc
*desc
;
307 int ldo
= rdev_get_id(rdev
);
308 int reg
, shift
= 0, mask
, ret
, i
;
310 if (ldo
>= ARRAY_SIZE(ldo_voltage_map
))
313 desc
= ldo_voltage_map
[ldo
];
317 if (max_vol
< desc
->min
|| min_vol
> desc
->max
)
320 if (min_vol
< desc
->min
)
323 i
= DIV_ROUND_UP(min_vol
- desc
->min
, desc
->step
);
325 if (desc
->min
+ desc
->step
*i
> max_vol
)
330 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
334 ret
= max8998_update_reg(i2c
, reg
, i
<<shift
, mask
<<shift
);
339 static inline void buck1_gpio_set(int gpio1
, int gpio2
, int v
)
341 gpio_set_value(gpio1
, v
& 0x1);
342 gpio_set_value(gpio2
, (v
>> 1) & 0x1);
345 static inline void buck2_gpio_set(int gpio
, int v
)
347 gpio_set_value(gpio
, v
& 0x1);
350 static int max8998_set_voltage_buck(struct regulator_dev
*rdev
,
351 int min_uV
, int max_uV
, unsigned *selector
)
353 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
354 struct max8998_platform_data
*pdata
=
355 dev_get_platdata(max8998
->iodev
->dev
);
356 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
357 int min_vol
= min_uV
/ 1000, max_vol
= max_uV
/ 1000;
358 const struct voltage_map_desc
*desc
;
359 int buck
= rdev_get_id(rdev
);
360 int reg
, shift
= 0, mask
, ret
;
361 int i
, j
, previous_sel
;
362 static u8 buck1_last_val
;
364 if (buck
>= ARRAY_SIZE(ldo_voltage_map
))
367 desc
= ldo_voltage_map
[buck
];
372 if (max_vol
< desc
->min
|| min_vol
> desc
->max
)
375 if (min_vol
< desc
->min
)
378 i
= DIV_ROUND_UP(min_vol
- desc
->min
, desc
->step
);
380 if (desc
->min
+ desc
->step
*i
> max_vol
)
385 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
389 previous_sel
= max8998_get_voltage_sel(rdev
);
391 /* Check if voltage needs to be changed */
392 /* if previous_voltage equal new voltage, return */
393 if (previous_sel
== i
) {
394 dev_dbg(max8998
->dev
, "No voltage change, old:%d, new:%d\n",
395 max8998_list_voltage(rdev
, previous_sel
),
396 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
);
488 static int max8998_set_voltage_buck_time_sel(struct regulator_dev
*rdev
,
489 unsigned int old_selector
,
490 unsigned int new_selector
)
492 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
493 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
494 const struct voltage_map_desc
*desc
;
495 int buck
= rdev_get_id(rdev
);
499 if (buck
< MAX8998_BUCK1
|| buck
> MAX8998_BUCK4
)
502 desc
= ldo_voltage_map
[buck
];
504 /* Voltage stabilization */
505 ret
= max8998_read_reg(i2c
, MAX8998_REG_ONOFF4
, &val
);
509 /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */
510 /* MAX8998 has ENRAMP bit implemented, so test it*/
511 if (max8998
->iodev
->type
== TYPE_MAX8998
&& !(val
& MAX8998_ENRAMP
))
514 difference
= (new_selector
- old_selector
) * desc
->step
;
516 return difference
/ ((val
& 0x0f) + 1);
521 static struct regulator_ops max8998_ldo_ops
= {
522 .list_voltage
= max8998_list_voltage
,
523 .is_enabled
= max8998_ldo_is_enabled
,
524 .enable
= max8998_ldo_enable
,
525 .disable
= max8998_ldo_disable
,
526 .get_voltage_sel
= max8998_get_voltage_sel
,
527 .set_voltage
= max8998_set_voltage_ldo
,
528 .set_suspend_enable
= max8998_ldo_enable
,
529 .set_suspend_disable
= max8998_ldo_disable
,
532 static struct regulator_ops max8998_buck_ops
= {
533 .list_voltage
= max8998_list_voltage
,
534 .is_enabled
= max8998_ldo_is_enabled
,
535 .enable
= max8998_ldo_enable
,
536 .disable
= max8998_ldo_disable
,
537 .get_voltage_sel
= max8998_get_voltage_sel
,
538 .set_voltage
= max8998_set_voltage_buck
,
539 .set_voltage_time_sel
= max8998_set_voltage_buck_time_sel
,
540 .set_suspend_enable
= max8998_ldo_enable
,
541 .set_suspend_disable
= max8998_ldo_disable
,
544 static struct regulator_ops max8998_others_ops
= {
545 .is_enabled
= max8998_ldo_is_enabled
,
546 .enable
= max8998_ldo_enable
,
547 .disable
= max8998_ldo_disable
,
548 .set_suspend_enable
= max8998_ldo_enable
,
549 .set_suspend_disable
= max8998_ldo_disable
,
552 static struct regulator_desc regulators
[] = {
556 .ops
= &max8998_ldo_ops
,
557 .type
= REGULATOR_VOLTAGE
,
558 .owner
= THIS_MODULE
,
562 .ops
= &max8998_ldo_ops
,
563 .type
= REGULATOR_VOLTAGE
,
564 .owner
= THIS_MODULE
,
568 .ops
= &max8998_ldo_ops
,
569 .type
= REGULATOR_VOLTAGE
,
570 .owner
= THIS_MODULE
,
574 .ops
= &max8998_ldo_ops
,
575 .type
= REGULATOR_VOLTAGE
,
576 .owner
= THIS_MODULE
,
580 .ops
= &max8998_ldo_ops
,
581 .type
= REGULATOR_VOLTAGE
,
582 .owner
= THIS_MODULE
,
586 .ops
= &max8998_ldo_ops
,
587 .type
= REGULATOR_VOLTAGE
,
588 .owner
= THIS_MODULE
,
592 .ops
= &max8998_ldo_ops
,
593 .type
= REGULATOR_VOLTAGE
,
594 .owner
= THIS_MODULE
,
598 .ops
= &max8998_ldo_ops
,
599 .type
= REGULATOR_VOLTAGE
,
600 .owner
= THIS_MODULE
,
604 .ops
= &max8998_ldo_ops
,
605 .type
= REGULATOR_VOLTAGE
,
606 .owner
= THIS_MODULE
,
610 .ops
= &max8998_ldo_ops
,
611 .type
= REGULATOR_VOLTAGE
,
612 .owner
= THIS_MODULE
,
616 .ops
= &max8998_ldo_ops
,
617 .type
= REGULATOR_VOLTAGE
,
618 .owner
= THIS_MODULE
,
622 .ops
= &max8998_ldo_ops
,
623 .type
= REGULATOR_VOLTAGE
,
624 .owner
= THIS_MODULE
,
628 .ops
= &max8998_ldo_ops
,
629 .type
= REGULATOR_VOLTAGE
,
630 .owner
= THIS_MODULE
,
634 .ops
= &max8998_ldo_ops
,
635 .type
= REGULATOR_VOLTAGE
,
636 .owner
= THIS_MODULE
,
640 .ops
= &max8998_ldo_ops
,
641 .type
= REGULATOR_VOLTAGE
,
642 .owner
= THIS_MODULE
,
646 .ops
= &max8998_ldo_ops
,
647 .type
= REGULATOR_VOLTAGE
,
648 .owner
= THIS_MODULE
,
652 .ops
= &max8998_buck_ops
,
653 .type
= REGULATOR_VOLTAGE
,
654 .owner
= THIS_MODULE
,
658 .ops
= &max8998_buck_ops
,
659 .type
= REGULATOR_VOLTAGE
,
660 .owner
= THIS_MODULE
,
664 .ops
= &max8998_buck_ops
,
665 .type
= REGULATOR_VOLTAGE
,
666 .owner
= THIS_MODULE
,
670 .ops
= &max8998_buck_ops
,
671 .type
= REGULATOR_VOLTAGE
,
672 .owner
= THIS_MODULE
,
674 .name
= "EN32KHz AP",
675 .id
= MAX8998_EN32KHZ_AP
,
676 .ops
= &max8998_others_ops
,
677 .type
= REGULATOR_VOLTAGE
,
678 .owner
= THIS_MODULE
,
680 .name
= "EN32KHz CP",
681 .id
= MAX8998_EN32KHZ_CP
,
682 .ops
= &max8998_others_ops
,
683 .type
= REGULATOR_VOLTAGE
,
684 .owner
= THIS_MODULE
,
687 .id
= MAX8998_ENVICHG
,
688 .ops
= &max8998_others_ops
,
689 .type
= REGULATOR_VOLTAGE
,
690 .owner
= THIS_MODULE
,
693 .id
= MAX8998_ESAFEOUT1
,
694 .ops
= &max8998_others_ops
,
695 .type
= REGULATOR_VOLTAGE
,
696 .owner
= THIS_MODULE
,
699 .id
= MAX8998_ESAFEOUT2
,
700 .ops
= &max8998_others_ops
,
701 .type
= REGULATOR_VOLTAGE
,
702 .owner
= THIS_MODULE
,
706 static __devinit
int max8998_pmic_probe(struct platform_device
*pdev
)
708 struct max8998_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
709 struct max8998_platform_data
*pdata
= dev_get_platdata(iodev
->dev
);
710 struct regulator_config config
= { };
711 struct regulator_dev
**rdev
;
712 struct max8998_data
*max8998
;
713 struct i2c_client
*i2c
;
717 dev_err(pdev
->dev
.parent
, "No platform init data supplied\n");
721 max8998
= devm_kzalloc(&pdev
->dev
, sizeof(struct max8998_data
),
726 size
= sizeof(struct regulator_dev
*) * pdata
->num_regulators
;
727 max8998
->rdev
= devm_kzalloc(&pdev
->dev
, size
, GFP_KERNEL
);
731 rdev
= max8998
->rdev
;
732 max8998
->dev
= &pdev
->dev
;
733 max8998
->iodev
= iodev
;
734 max8998
->num_regulators
= pdata
->num_regulators
;
735 platform_set_drvdata(pdev
, max8998
);
736 i2c
= max8998
->iodev
->i2c
;
738 max8998
->buck1_idx
= pdata
->buck1_default_idx
;
739 max8998
->buck2_idx
= pdata
->buck2_default_idx
;
742 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */
743 /* will be displayed */
745 /* Check if MAX8998 voltage selection GPIOs are defined */
746 if (gpio_is_valid(pdata
->buck1_set1
) &&
747 gpio_is_valid(pdata
->buck1_set2
)) {
748 /* Check if SET1 is not equal to 0 */
749 if (!pdata
->buck1_set1
) {
750 printk(KERN_ERR
"MAX8998 SET1 GPIO defined as 0 !\n");
751 WARN_ON(!pdata
->buck1_set1
);
755 /* Check if SET2 is not equal to 0 */
756 if (!pdata
->buck1_set2
) {
757 printk(KERN_ERR
"MAX8998 SET2 GPIO defined as 0 !\n");
758 WARN_ON(!pdata
->buck1_set2
);
763 gpio_request(pdata
->buck1_set1
, "MAX8998 BUCK1_SET1");
764 gpio_direction_output(pdata
->buck1_set1
,
765 max8998
->buck1_idx
& 0x1);
768 gpio_request(pdata
->buck1_set2
, "MAX8998 BUCK1_SET2");
769 gpio_direction_output(pdata
->buck1_set2
,
770 (max8998
->buck1_idx
>> 1) & 0x1);
771 /* Set predefined value for BUCK1 register 1 */
773 while (buck12_voltage_map_desc
.min
+
774 buck12_voltage_map_desc
.step
*i
775 < (pdata
->buck1_voltage1
/ 1000))
777 max8998
->buck1_vol
[0] = i
;
778 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE1
, i
);
782 /* Set predefined value for BUCK1 register 2 */
784 while (buck12_voltage_map_desc
.min
+
785 buck12_voltage_map_desc
.step
*i
786 < (pdata
->buck1_voltage2
/ 1000))
789 max8998
->buck1_vol
[1] = i
;
790 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE2
, i
);
794 /* Set predefined value for BUCK1 register 3 */
796 while (buck12_voltage_map_desc
.min
+
797 buck12_voltage_map_desc
.step
*i
798 < (pdata
->buck1_voltage3
/ 1000))
801 max8998
->buck1_vol
[2] = i
;
802 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE3
, i
);
806 /* Set predefined value for BUCK1 register 4 */
808 while (buck12_voltage_map_desc
.min
+
809 buck12_voltage_map_desc
.step
*i
810 < (pdata
->buck1_voltage4
/ 1000))
813 max8998
->buck1_vol
[3] = i
;
814 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE4
, i
);
820 if (gpio_is_valid(pdata
->buck2_set3
)) {
821 /* Check if SET3 is not equal to 0 */
822 if (!pdata
->buck2_set3
) {
823 printk(KERN_ERR
"MAX8998 SET3 GPIO defined as 0 !\n");
824 WARN_ON(!pdata
->buck2_set3
);
828 gpio_request(pdata
->buck2_set3
, "MAX8998 BUCK2_SET3");
829 gpio_direction_output(pdata
->buck2_set3
,
830 max8998
->buck2_idx
& 0x1);
832 /* BUCK2 register 1 */
834 while (buck12_voltage_map_desc
.min
+
835 buck12_voltage_map_desc
.step
*i
836 < (pdata
->buck2_voltage1
/ 1000))
838 max8998
->buck2_vol
[0] = i
;
839 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK2_VOLTAGE1
, i
);
843 /* BUCK2 register 2 */
845 while (buck12_voltage_map_desc
.min
+
846 buck12_voltage_map_desc
.step
*i
847 < (pdata
->buck2_voltage2
/ 1000))
849 max8998
->buck2_vol
[1] = i
;
850 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK2_VOLTAGE2
, i
);
855 for (i
= 0; i
< pdata
->num_regulators
; i
++) {
856 const struct voltage_map_desc
*desc
;
857 int id
= pdata
->regulators
[i
].id
;
858 int index
= id
- MAX8998_LDO2
;
860 desc
= ldo_voltage_map
[id
];
861 if (desc
&& regulators
[index
].ops
!= &max8998_others_ops
) {
862 int count
= (desc
->max
- desc
->min
) / desc
->step
+ 1;
863 regulators
[index
].n_voltages
= count
;
866 config
.dev
= max8998
->dev
;
867 config
.init_data
= pdata
->regulators
[i
].initdata
;
868 config
.driver_data
= max8998
;
870 rdev
[i
] = regulator_register(®ulators
[index
], &config
);
871 if (IS_ERR(rdev
[i
])) {
872 ret
= PTR_ERR(rdev
[i
]);
873 dev_err(max8998
->dev
, "regulator init failed\n");
883 regulator_unregister(rdev
[i
]);
888 static int __devexit
max8998_pmic_remove(struct platform_device
*pdev
)
890 struct max8998_data
*max8998
= platform_get_drvdata(pdev
);
891 struct regulator_dev
**rdev
= max8998
->rdev
;
894 for (i
= 0; i
< max8998
->num_regulators
; i
++)
895 regulator_unregister(rdev
[i
]);
899 static const struct platform_device_id max8998_pmic_id
[] = {
900 { "max8998-pmic", TYPE_MAX8998
},
901 { "lp3974-pmic", TYPE_LP3974
},
904 MODULE_DEVICE_TABLE(platform
, max8998_pmic_id
);
906 static struct platform_driver max8998_pmic_driver
= {
908 .name
= "max8998-pmic",
909 .owner
= THIS_MODULE
,
911 .probe
= max8998_pmic_probe
,
912 .remove
= __devexit_p(max8998_pmic_remove
),
913 .id_table
= max8998_pmic_id
,
916 static int __init
max8998_pmic_init(void)
918 return platform_driver_register(&max8998_pmic_driver
);
920 subsys_initcall(max8998_pmic_init
);
922 static void __exit
max8998_pmic_cleanup(void)
924 platform_driver_unregister(&max8998_pmic_driver
);
926 module_exit(max8998_pmic_cleanup
);
928 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
929 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
930 MODULE_LICENSE("GPL");