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
)
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
)
334 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
338 ret
= max8998_update_reg(i2c
, reg
, i
<<shift
, mask
<<shift
);
343 static inline void buck1_gpio_set(int gpio1
, int gpio2
, int v
)
345 gpio_set_value(gpio1
, v
& 0x1);
346 gpio_set_value(gpio2
, (v
>> 1) & 0x1);
349 static inline void buck2_gpio_set(int gpio
, int v
)
351 gpio_set_value(gpio
, v
& 0x1);
354 static int max8998_set_voltage_buck(struct regulator_dev
*rdev
,
355 int min_uV
, int max_uV
)
357 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
358 struct max8998_platform_data
*pdata
=
359 dev_get_platdata(max8998
->iodev
->dev
);
360 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
361 int min_vol
= min_uV
/ 1000, max_vol
= max_uV
/ 1000;
362 const struct voltage_map_desc
*desc
;
363 int buck
= max8998_get_ldo(rdev
);
364 int reg
, shift
= 0, mask
, ret
;
365 int difference
= 0, i
= 0, j
= 0, previous_vol
= 0;
367 static u8 buck1_last_val
;
369 if (buck
>= ARRAY_SIZE(ldo_voltage_map
))
372 desc
= ldo_voltage_map
[buck
];
377 if (max_vol
< desc
->min
|| min_vol
> desc
->max
)
380 while (desc
->min
+ desc
->step
*i
< min_vol
&&
381 desc
->min
+ desc
->step
*i
< desc
->max
)
384 if (desc
->min
+ desc
->step
*i
> max_vol
)
387 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
391 previous_vol
= max8998_get_voltage(rdev
);
393 /* Check if voltage needs to be changed */
394 /* if previous_voltage equal new voltage, return */
395 if (previous_vol
== max8998_list_voltage(rdev
, i
)) {
396 dev_dbg(max8998
->dev
, "No voltage change, old:%d, new:%d\n",
397 previous_vol
, max8998_list_voltage(rdev
, i
));
403 dev_dbg(max8998
->dev
,
404 "BUCK1, i:%d, buck1_vol1:%d, buck1_vol2:%d\n\
405 buck1_vol3:%d, buck1_vol4:%d\n",
406 i
, max8998
->buck1_vol
[0], max8998
->buck1_vol
[1],
407 max8998
->buck1_vol
[2], max8998
->buck1_vol
[3]);
409 if (gpio_is_valid(pdata
->buck1_set1
) &&
410 gpio_is_valid(pdata
->buck1_set2
)) {
412 /* check if requested voltage */
413 /* value is already defined */
414 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck1_vol
); j
++) {
415 if (max8998
->buck1_vol
[j
] == i
) {
416 max8998
->buck1_idx
= j
;
417 buck1_gpio_set(pdata
->buck1_set1
,
418 pdata
->buck1_set2
, j
);
423 /* no predefine regulator found */
424 max8998
->buck1_idx
= (buck1_last_val
% 2) + 2;
425 dev_dbg(max8998
->dev
, "max8998->buck1_idx:%d\n",
427 max8998
->buck1_vol
[max8998
->buck1_idx
] = i
;
428 ret
= max8998_get_voltage_register(rdev
, ®
,
431 ret
= max8998_write_reg(i2c
, reg
, i
);
432 buck1_gpio_set(pdata
->buck1_set1
,
433 pdata
->buck1_set2
, max8998
->buck1_idx
);
436 dev_dbg(max8998
->dev
, "%s: SET1:%d, SET2:%d\n",
437 i2c
->name
, gpio_get_value(pdata
->buck1_set1
),
438 gpio_get_value(pdata
->buck1_set2
));
441 ret
= max8998_write_reg(i2c
, reg
, i
);
446 dev_dbg(max8998
->dev
,
447 "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n"
448 , i
, max8998
->buck2_vol
[0], max8998
->buck2_vol
[1]);
449 if (gpio_is_valid(pdata
->buck2_set3
)) {
450 if (max8998
->buck2_vol
[0] == i
) {
451 max8998
->buck1_idx
= 0;
452 buck2_gpio_set(pdata
->buck2_set3
, 0);
454 max8998
->buck1_idx
= 1;
455 ret
= max8998_get_voltage_register(rdev
, ®
,
458 ret
= max8998_write_reg(i2c
, reg
, i
);
459 max8998
->buck2_vol
[1] = i
;
460 buck2_gpio_set(pdata
->buck2_set3
, 1);
462 dev_dbg(max8998
->dev
, "%s: SET3:%d\n", i2c
->name
,
463 gpio_get_value(pdata
->buck2_set3
));
465 ret
= max8998_write_reg(i2c
, reg
, i
);
471 ret
= max8998_update_reg(i2c
, reg
, i
<<shift
, mask
<<shift
);
475 /* Voltage stabilization */
476 max8998_read_reg(i2c
, MAX8998_REG_ONOFF4
, &val
);
478 /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */
479 /* MAX8998 has ENRAMP bit implemented, so test it*/
480 if (max8998
->iodev
->type
== TYPE_MAX8998
&& !(val
& MAX8998_ENRAMP
))
483 difference
= desc
->min
+ desc
->step
*i
- previous_vol
/1000;
485 udelay(difference
/ ((val
& 0x0f) + 1));
490 static struct regulator_ops max8998_ldo_ops
= {
491 .list_voltage
= max8998_list_voltage
,
492 .is_enabled
= max8998_ldo_is_enabled
,
493 .enable
= max8998_ldo_enable
,
494 .disable
= max8998_ldo_disable
,
495 .get_voltage
= max8998_get_voltage
,
496 .set_voltage
= max8998_set_voltage_ldo
,
497 .set_suspend_enable
= max8998_ldo_enable
,
498 .set_suspend_disable
= max8998_ldo_disable
,
501 static struct regulator_ops max8998_buck_ops
= {
502 .list_voltage
= max8998_list_voltage
,
503 .is_enabled
= max8998_ldo_is_enabled
,
504 .enable
= max8998_ldo_enable
,
505 .disable
= max8998_ldo_disable
,
506 .get_voltage
= max8998_get_voltage
,
507 .set_voltage
= max8998_set_voltage_buck
,
508 .set_suspend_enable
= max8998_ldo_enable
,
509 .set_suspend_disable
= max8998_ldo_disable
,
512 static struct regulator_ops max8998_others_ops
= {
513 .is_enabled
= max8998_ldo_is_enabled
,
514 .enable
= max8998_ldo_enable
,
515 .disable
= max8998_ldo_disable
,
516 .set_suspend_enable
= max8998_ldo_enable
,
517 .set_suspend_disable
= max8998_ldo_disable
,
520 static struct regulator_desc regulators
[] = {
524 .ops
= &max8998_ldo_ops
,
525 .type
= REGULATOR_VOLTAGE
,
526 .owner
= THIS_MODULE
,
530 .ops
= &max8998_ldo_ops
,
531 .type
= REGULATOR_VOLTAGE
,
532 .owner
= THIS_MODULE
,
536 .ops
= &max8998_ldo_ops
,
537 .type
= REGULATOR_VOLTAGE
,
538 .owner
= THIS_MODULE
,
542 .ops
= &max8998_ldo_ops
,
543 .type
= REGULATOR_VOLTAGE
,
544 .owner
= THIS_MODULE
,
548 .ops
= &max8998_ldo_ops
,
549 .type
= REGULATOR_VOLTAGE
,
550 .owner
= THIS_MODULE
,
554 .ops
= &max8998_ldo_ops
,
555 .type
= REGULATOR_VOLTAGE
,
556 .owner
= THIS_MODULE
,
560 .ops
= &max8998_ldo_ops
,
561 .type
= REGULATOR_VOLTAGE
,
562 .owner
= THIS_MODULE
,
566 .ops
= &max8998_ldo_ops
,
567 .type
= REGULATOR_VOLTAGE
,
568 .owner
= THIS_MODULE
,
572 .ops
= &max8998_ldo_ops
,
573 .type
= REGULATOR_VOLTAGE
,
574 .owner
= THIS_MODULE
,
578 .ops
= &max8998_ldo_ops
,
579 .type
= REGULATOR_VOLTAGE
,
580 .owner
= THIS_MODULE
,
584 .ops
= &max8998_ldo_ops
,
585 .type
= REGULATOR_VOLTAGE
,
586 .owner
= THIS_MODULE
,
590 .ops
= &max8998_ldo_ops
,
591 .type
= REGULATOR_VOLTAGE
,
592 .owner
= THIS_MODULE
,
596 .ops
= &max8998_ldo_ops
,
597 .type
= REGULATOR_VOLTAGE
,
598 .owner
= THIS_MODULE
,
602 .ops
= &max8998_ldo_ops
,
603 .type
= REGULATOR_VOLTAGE
,
604 .owner
= THIS_MODULE
,
608 .ops
= &max8998_ldo_ops
,
609 .type
= REGULATOR_VOLTAGE
,
610 .owner
= THIS_MODULE
,
614 .ops
= &max8998_ldo_ops
,
615 .type
= REGULATOR_VOLTAGE
,
616 .owner
= THIS_MODULE
,
620 .ops
= &max8998_buck_ops
,
621 .type
= REGULATOR_VOLTAGE
,
622 .owner
= THIS_MODULE
,
626 .ops
= &max8998_buck_ops
,
627 .type
= REGULATOR_VOLTAGE
,
628 .owner
= THIS_MODULE
,
632 .ops
= &max8998_buck_ops
,
633 .type
= REGULATOR_VOLTAGE
,
634 .owner
= THIS_MODULE
,
638 .ops
= &max8998_buck_ops
,
639 .type
= REGULATOR_VOLTAGE
,
640 .owner
= THIS_MODULE
,
642 .name
= "EN32KHz AP",
643 .id
= MAX8998_EN32KHZ_AP
,
644 .ops
= &max8998_others_ops
,
645 .type
= REGULATOR_VOLTAGE
,
646 .owner
= THIS_MODULE
,
648 .name
= "EN32KHz CP",
649 .id
= MAX8998_EN32KHZ_CP
,
650 .ops
= &max8998_others_ops
,
651 .type
= REGULATOR_VOLTAGE
,
652 .owner
= THIS_MODULE
,
655 .id
= MAX8998_ENVICHG
,
656 .ops
= &max8998_others_ops
,
657 .type
= REGULATOR_VOLTAGE
,
658 .owner
= THIS_MODULE
,
661 .id
= MAX8998_ESAFEOUT1
,
662 .ops
= &max8998_others_ops
,
663 .type
= REGULATOR_VOLTAGE
,
664 .owner
= THIS_MODULE
,
667 .id
= MAX8998_ESAFEOUT2
,
668 .ops
= &max8998_others_ops
,
669 .type
= REGULATOR_VOLTAGE
,
670 .owner
= THIS_MODULE
,
674 static __devinit
int max8998_pmic_probe(struct platform_device
*pdev
)
676 struct max8998_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
677 struct max8998_platform_data
*pdata
= dev_get_platdata(iodev
->dev
);
678 struct regulator_dev
**rdev
;
679 struct max8998_data
*max8998
;
680 struct i2c_client
*i2c
;
684 dev_err(pdev
->dev
.parent
, "No platform init data supplied\n");
688 max8998
= kzalloc(sizeof(struct max8998_data
), GFP_KERNEL
);
692 size
= sizeof(struct regulator_dev
*) * pdata
->num_regulators
;
693 max8998
->rdev
= kzalloc(size
, GFP_KERNEL
);
694 if (!max8998
->rdev
) {
699 rdev
= max8998
->rdev
;
700 max8998
->dev
= &pdev
->dev
;
701 max8998
->iodev
= iodev
;
702 max8998
->num_regulators
= pdata
->num_regulators
;
703 platform_set_drvdata(pdev
, max8998
);
704 i2c
= max8998
->iodev
->i2c
;
707 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */
708 /* will be displayed */
710 /* Check if MAX8998 voltage selection GPIOs are defined */
711 if (gpio_is_valid(pdata
->buck1_set1
) &&
712 gpio_is_valid(pdata
->buck1_set2
)) {
713 /* Check if SET1 is not equal to 0 */
714 if (!pdata
->buck1_set1
) {
715 printk(KERN_ERR
"MAX8998 SET1 GPIO defined as 0 !\n");
716 WARN_ON(!pdata
->buck1_set1
);
719 /* Check if SET2 is not equal to 0 */
720 if (!pdata
->buck1_set2
) {
721 printk(KERN_ERR
"MAX8998 SET2 GPIO defined as 0 !\n");
722 WARN_ON(!pdata
->buck1_set2
);
726 gpio_request(pdata
->buck1_set1
, "MAX8998 BUCK1_SET1");
727 gpio_direction_output(pdata
->buck1_set1
,
728 max8998
->buck1_idx
& 0x1);
731 gpio_request(pdata
->buck1_set2
, "MAX8998 BUCK1_SET2");
732 gpio_direction_output(pdata
->buck1_set2
,
733 (max8998
->buck1_idx
>> 1) & 0x1);
734 /* Set predefined value for BUCK1 register 1 */
736 while (buck12_voltage_map_desc
.min
+
737 buck12_voltage_map_desc
.step
*i
738 != (pdata
->buck1_max_voltage1
/ 1000))
740 printk(KERN_ERR
"i:%d, buck1_idx:%d\n", i
, max8998
->buck1_idx
);
741 max8998
->buck1_vol
[0] = i
;
742 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE1
, i
);
744 /* Set predefined value for BUCK1 register 2 */
746 while (buck12_voltage_map_desc
.min
+
747 buck12_voltage_map_desc
.step
*i
748 != (pdata
->buck1_max_voltage2
/ 1000))
751 max8998
->buck1_vol
[1] = i
;
752 printk(KERN_ERR
"i:%d, buck1_idx:%d\n", i
, max8998
->buck1_idx
);
753 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK1_VOLTAGE2
, i
)
760 if (gpio_is_valid(pdata
->buck2_set3
)) {
761 /* Check if SET3 is not equal to 0 */
762 if (!pdata
->buck2_set3
) {
763 printk(KERN_ERR
"MAX8998 SET3 GPIO defined as 0 !\n");
764 WARN_ON(!pdata
->buck2_set3
);
767 gpio_request(pdata
->buck2_set3
, "MAX8998 BUCK2_SET3");
768 gpio_direction_output(pdata
->buck2_set3
,
769 max8998
->buck2_idx
& 0x1);
771 /* BUCK2 - set preset default voltage value to buck2_vol[0] */
773 while (buck12_voltage_map_desc
.min
+
774 buck12_voltage_map_desc
.step
*i
775 != (pdata
->buck2_max_voltage
/ 1000))
777 printk(KERN_ERR
"i:%d, buck2_idx:%d\n", i
, max8998
->buck2_idx
);
778 max8998
->buck2_vol
[0] = i
;
779 ret
= max8998_write_reg(i2c
, MAX8998_REG_BUCK2_VOLTAGE1
, i
);
785 for (i
= 0; i
< pdata
->num_regulators
; i
++) {
786 const struct voltage_map_desc
*desc
;
787 int id
= pdata
->regulators
[i
].id
;
788 int index
= id
- MAX8998_LDO2
;
790 desc
= ldo_voltage_map
[id
];
791 if (desc
&& regulators
[index
].ops
!= &max8998_others_ops
) {
792 int count
= (desc
->max
- desc
->min
) / desc
->step
+ 1;
793 regulators
[index
].n_voltages
= count
;
795 rdev
[i
] = regulator_register(®ulators
[index
], max8998
->dev
,
796 pdata
->regulators
[i
].initdata
, max8998
);
797 if (IS_ERR(rdev
[i
])) {
798 ret
= PTR_ERR(rdev
[i
]);
799 dev_err(max8998
->dev
, "regulator init failed\n");
808 for (i
= 0; i
< max8998
->num_regulators
; i
++)
810 regulator_unregister(rdev
[i
]);
812 kfree(max8998
->rdev
);
818 static int __devexit
max8998_pmic_remove(struct platform_device
*pdev
)
820 struct max8998_data
*max8998
= platform_get_drvdata(pdev
);
821 struct regulator_dev
**rdev
= max8998
->rdev
;
824 for (i
= 0; i
< max8998
->num_regulators
; i
++)
826 regulator_unregister(rdev
[i
]);
828 kfree(max8998
->rdev
);
834 static struct platform_driver max8998_pmic_driver
= {
836 .name
= "max8998-pmic",
837 .owner
= THIS_MODULE
,
839 .probe
= max8998_pmic_probe
,
840 .remove
= __devexit_p(max8998_pmic_remove
),
843 static int __init
max8998_pmic_init(void)
845 return platform_driver_register(&max8998_pmic_driver
);
847 subsys_initcall(max8998_pmic_init
);
849 static void __exit
max8998_pmic_cleanup(void)
851 platform_driver_unregister(&max8998_pmic_driver
);
853 module_exit(max8998_pmic_cleanup
);
855 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
856 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
857 MODULE_LICENSE("GPL");