1 // SPDX-License-Identifier: GPL-2.0+
3 // max8998.c - Voltage regulator driver for the Maxim 8998
5 // Copyright (C) 2009-2010 Samsung Electronics
6 // Kyungmin Park <kyungmin.park@samsung.com>
7 // Marek Szyprowski <m.szyprowski@samsung.com>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/i2c.h>
12 #include <linux/err.h>
13 #include <linux/gpio.h>
14 #include <linux/slab.h>
15 #include <linux/interrupt.h>
16 #include <linux/mutex.h>
18 #include <linux/of_gpio.h>
19 #include <linux/platform_device.h>
20 #include <linux/regulator/driver.h>
21 #include <linux/regulator/of_regulator.h>
22 #include <linux/mfd/max8998.h>
23 #include <linux/mfd/max8998-private.h>
27 struct max8998_dev
*iodev
;
29 u8 buck1_vol
[4]; /* voltages for selection */
31 unsigned int buck1_idx
; /* index to last changed voltage */
33 unsigned int buck2_idx
;
36 struct voltage_map_desc
{
42 /* Voltage maps in uV*/
43 static const struct voltage_map_desc ldo23_voltage_map_desc
= {
44 .min
= 800000, .step
= 50000, .max
= 1300000,
46 static const struct voltage_map_desc ldo456711_voltage_map_desc
= {
47 .min
= 1600000, .step
= 100000, .max
= 3600000,
49 static const struct voltage_map_desc ldo8_voltage_map_desc
= {
50 .min
= 3000000, .step
= 100000, .max
= 3600000,
52 static const struct voltage_map_desc ldo9_voltage_map_desc
= {
53 .min
= 2800000, .step
= 100000, .max
= 3100000,
55 static const struct voltage_map_desc ldo10_voltage_map_desc
= {
56 .min
= 950000, .step
= 50000, .max
= 1300000,
58 static const struct voltage_map_desc ldo1213_voltage_map_desc
= {
59 .min
= 800000, .step
= 100000, .max
= 3300000,
61 static const struct voltage_map_desc ldo1415_voltage_map_desc
= {
62 .min
= 1200000, .step
= 100000, .max
= 3300000,
64 static const struct voltage_map_desc ldo1617_voltage_map_desc
= {
65 .min
= 1600000, .step
= 100000, .max
= 3600000,
67 static const struct voltage_map_desc buck12_voltage_map_desc
= {
68 .min
= 750000, .step
= 25000, .max
= 1525000,
70 static const struct voltage_map_desc buck3_voltage_map_desc
= {
71 .min
= 1600000, .step
= 100000, .max
= 3600000,
73 static const struct voltage_map_desc buck4_voltage_map_desc
= {
74 .min
= 800000, .step
= 100000, .max
= 2300000,
77 static const struct voltage_map_desc
*ldo_voltage_map
[] = {
80 &ldo23_voltage_map_desc
, /* LDO2 */
81 &ldo23_voltage_map_desc
, /* LDO3 */
82 &ldo456711_voltage_map_desc
, /* LDO4 */
83 &ldo456711_voltage_map_desc
, /* LDO5 */
84 &ldo456711_voltage_map_desc
, /* LDO6 */
85 &ldo456711_voltage_map_desc
, /* LDO7 */
86 &ldo8_voltage_map_desc
, /* LDO8 */
87 &ldo9_voltage_map_desc
, /* LDO9 */
88 &ldo10_voltage_map_desc
, /* LDO10 */
89 &ldo456711_voltage_map_desc
, /* LDO11 */
90 &ldo1213_voltage_map_desc
, /* LDO12 */
91 &ldo1213_voltage_map_desc
, /* LDO13 */
92 &ldo1415_voltage_map_desc
, /* LDO14 */
93 &ldo1415_voltage_map_desc
, /* LDO15 */
94 &ldo1617_voltage_map_desc
, /* LDO16 */
95 &ldo1617_voltage_map_desc
, /* LDO17 */
96 &buck12_voltage_map_desc
, /* BUCK1 */
97 &buck12_voltage_map_desc
, /* BUCK2 */
98 &buck3_voltage_map_desc
, /* BUCK3 */
99 &buck4_voltage_map_desc
, /* BUCK4 */
102 static int max8998_get_enable_register(struct regulator_dev
*rdev
,
103 int *reg
, int *shift
)
105 int ldo
= rdev_get_id(rdev
);
108 case MAX8998_LDO2
... MAX8998_LDO5
:
109 *reg
= MAX8998_REG_ONOFF1
;
110 *shift
= 3 - (ldo
- MAX8998_LDO2
);
112 case MAX8998_LDO6
... MAX8998_LDO13
:
113 *reg
= MAX8998_REG_ONOFF2
;
114 *shift
= 7 - (ldo
- MAX8998_LDO6
);
116 case MAX8998_LDO14
... MAX8998_LDO17
:
117 *reg
= MAX8998_REG_ONOFF3
;
118 *shift
= 7 - (ldo
- MAX8998_LDO14
);
120 case MAX8998_BUCK1
... MAX8998_BUCK4
:
121 *reg
= MAX8998_REG_ONOFF1
;
122 *shift
= 7 - (ldo
- MAX8998_BUCK1
);
124 case MAX8998_EN32KHZ_AP
... MAX8998_ENVICHG
:
125 *reg
= MAX8998_REG_ONOFF4
;
126 *shift
= 7 - (ldo
- MAX8998_EN32KHZ_AP
);
128 case MAX8998_ESAFEOUT1
... MAX8998_ESAFEOUT2
:
129 *reg
= MAX8998_REG_CHGR2
;
130 *shift
= 7 - (ldo
- MAX8998_ESAFEOUT1
);
139 static int max8998_ldo_is_enabled(struct regulator_dev
*rdev
)
141 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
142 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
143 int ret
, reg
, shift
= 8;
146 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
150 ret
= max8998_read_reg(i2c
, reg
, &val
);
154 return val
& (1 << shift
);
157 static int max8998_ldo_enable(struct regulator_dev
*rdev
)
159 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
160 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
161 int reg
, shift
= 8, ret
;
163 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
167 return max8998_update_reg(i2c
, reg
, 1<<shift
, 1<<shift
);
170 static int max8998_ldo_disable(struct regulator_dev
*rdev
)
172 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
173 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
174 int reg
, shift
= 8, ret
;
176 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
180 return max8998_update_reg(i2c
, reg
, 0, 1<<shift
);
183 static int max8998_get_voltage_register(struct regulator_dev
*rdev
,
184 int *_reg
, int *_shift
, int *_mask
)
186 int ldo
= rdev_get_id(rdev
);
187 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
188 int reg
, shift
= 0, mask
= 0xff;
191 case MAX8998_LDO2
... MAX8998_LDO3
:
192 reg
= MAX8998_REG_LDO2_LDO3
;
194 if (ldo
== MAX8998_LDO2
)
199 case MAX8998_LDO4
... MAX8998_LDO7
:
200 reg
= MAX8998_REG_LDO4
+ (ldo
- MAX8998_LDO4
);
202 case MAX8998_LDO8
... MAX8998_LDO9
:
203 reg
= MAX8998_REG_LDO8_LDO9
;
205 if (ldo
== MAX8998_LDO8
)
210 case MAX8998_LDO10
... MAX8998_LDO11
:
211 reg
= MAX8998_REG_LDO10_LDO11
;
212 if (ldo
== MAX8998_LDO10
) {
220 case MAX8998_LDO12
... MAX8998_LDO17
:
221 reg
= MAX8998_REG_LDO12
+ (ldo
- MAX8998_LDO12
);
224 reg
= MAX8998_REG_BUCK1_VOLTAGE1
+ max8998
->buck1_idx
;
227 reg
= MAX8998_REG_BUCK2_VOLTAGE1
+ max8998
->buck2_idx
;
230 reg
= MAX8998_REG_BUCK3
;
233 reg
= MAX8998_REG_BUCK4
;
246 static int max8998_get_voltage_sel(struct regulator_dev
*rdev
)
248 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
249 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
250 int reg
, shift
= 0, mask
, ret
;
253 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
257 ret
= max8998_read_reg(i2c
, reg
, &val
);
267 static int max8998_set_voltage_ldo_sel(struct regulator_dev
*rdev
,
270 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
271 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
272 int reg
, shift
= 0, mask
, ret
;
274 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
278 ret
= max8998_update_reg(i2c
, reg
, selector
<<shift
, mask
<<shift
);
283 static inline void buck1_gpio_set(int gpio1
, int gpio2
, int v
)
285 gpio_set_value(gpio1
, v
& 0x1);
286 gpio_set_value(gpio2
, (v
>> 1) & 0x1);
289 static inline void buck2_gpio_set(int gpio
, int v
)
291 gpio_set_value(gpio
, v
& 0x1);
294 static int max8998_set_voltage_buck_sel(struct regulator_dev
*rdev
,
297 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
298 struct max8998_platform_data
*pdata
= max8998
->iodev
->pdata
;
299 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
300 int buck
= rdev_get_id(rdev
);
301 int reg
, shift
= 0, mask
, ret
, j
;
302 static u8 buck1_last_val
;
304 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
310 dev_dbg(max8998
->dev
,
311 "BUCK1, selector:%d, buck1_vol1:%d, buck1_vol2:%d\n"
312 "buck1_vol3:%d, buck1_vol4:%d\n",
313 selector
, max8998
->buck1_vol
[0], max8998
->buck1_vol
[1],
314 max8998
->buck1_vol
[2], max8998
->buck1_vol
[3]);
316 if (gpio_is_valid(pdata
->buck1_set1
) &&
317 gpio_is_valid(pdata
->buck1_set2
)) {
319 /* check if requested voltage */
320 /* value is already defined */
321 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck1_vol
); j
++) {
322 if (max8998
->buck1_vol
[j
] == selector
) {
323 max8998
->buck1_idx
= j
;
324 buck1_gpio_set(pdata
->buck1_set1
,
325 pdata
->buck1_set2
, j
);
330 if (pdata
->buck_voltage_lock
)
333 /* no predefine regulator found */
334 max8998
->buck1_idx
= (buck1_last_val
% 2) + 2;
335 dev_dbg(max8998
->dev
, "max8998->buck1_idx:%d\n",
337 max8998
->buck1_vol
[max8998
->buck1_idx
] = selector
;
338 ret
= max8998_get_voltage_register(rdev
, ®
,
341 ret
= max8998_write_reg(i2c
, reg
, selector
);
342 buck1_gpio_set(pdata
->buck1_set1
,
343 pdata
->buck1_set2
, max8998
->buck1_idx
);
346 dev_dbg(max8998
->dev
, "%s: SET1:%d, SET2:%d\n",
347 i2c
->name
, gpio_get_value(pdata
->buck1_set1
),
348 gpio_get_value(pdata
->buck1_set2
));
351 ret
= max8998_write_reg(i2c
, reg
, selector
);
356 dev_dbg(max8998
->dev
,
357 "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n",
358 selector
, max8998
->buck2_vol
[0], max8998
->buck2_vol
[1]);
359 if (gpio_is_valid(pdata
->buck2_set3
)) {
361 /* check if requested voltage */
362 /* value is already defined */
363 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck2_vol
); j
++) {
364 if (max8998
->buck2_vol
[j
] == selector
) {
365 max8998
->buck2_idx
= j
;
366 buck2_gpio_set(pdata
->buck2_set3
, j
);
371 if (pdata
->buck_voltage_lock
)
374 max8998_get_voltage_register(rdev
,
375 ®
, &shift
, &mask
);
376 ret
= max8998_write_reg(i2c
, reg
, selector
);
377 max8998
->buck2_vol
[max8998
->buck2_idx
] = selector
;
378 buck2_gpio_set(pdata
->buck2_set3
, max8998
->buck2_idx
);
380 dev_dbg(max8998
->dev
, "%s: SET3:%d\n", i2c
->name
,
381 gpio_get_value(pdata
->buck2_set3
));
383 ret
= max8998_write_reg(i2c
, reg
, selector
);
389 ret
= max8998_update_reg(i2c
, reg
, selector
<<shift
,
397 static int max8998_set_voltage_buck_time_sel(struct regulator_dev
*rdev
,
398 unsigned int old_selector
,
399 unsigned int new_selector
)
401 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
402 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
403 const struct voltage_map_desc
*desc
;
404 int buck
= rdev_get_id(rdev
);
408 if (buck
< MAX8998_BUCK1
|| buck
> MAX8998_BUCK4
)
411 desc
= ldo_voltage_map
[buck
];
413 /* Voltage stabilization */
414 ret
= max8998_read_reg(i2c
, MAX8998_REG_ONOFF4
, &val
);
418 /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */
419 /* MAX8998 has ENRAMP bit implemented, so test it*/
420 if (max8998
->iodev
->type
== TYPE_MAX8998
&& !(val
& MAX8998_ENRAMP
))
423 difference
= (new_selector
- old_selector
) * desc
->step
/ 1000;
425 return DIV_ROUND_UP(difference
, (val
& 0x0f) + 1);
430 static struct regulator_ops max8998_ldo_ops
= {
431 .list_voltage
= regulator_list_voltage_linear
,
432 .map_voltage
= regulator_map_voltage_linear
,
433 .is_enabled
= max8998_ldo_is_enabled
,
434 .enable
= max8998_ldo_enable
,
435 .disable
= max8998_ldo_disable
,
436 .get_voltage_sel
= max8998_get_voltage_sel
,
437 .set_voltage_sel
= max8998_set_voltage_ldo_sel
,
440 static struct regulator_ops max8998_buck_ops
= {
441 .list_voltage
= regulator_list_voltage_linear
,
442 .map_voltage
= regulator_map_voltage_linear
,
443 .is_enabled
= max8998_ldo_is_enabled
,
444 .enable
= max8998_ldo_enable
,
445 .disable
= max8998_ldo_disable
,
446 .get_voltage_sel
= max8998_get_voltage_sel
,
447 .set_voltage_sel
= max8998_set_voltage_buck_sel
,
448 .set_voltage_time_sel
= max8998_set_voltage_buck_time_sel
,
451 static struct regulator_ops max8998_others_ops
= {
452 .is_enabled
= max8998_ldo_is_enabled
,
453 .enable
= max8998_ldo_enable
,
454 .disable
= max8998_ldo_disable
,
457 static struct regulator_desc regulators
[] = {
461 .ops
= &max8998_ldo_ops
,
462 .type
= REGULATOR_VOLTAGE
,
463 .owner
= THIS_MODULE
,
467 .ops
= &max8998_ldo_ops
,
468 .type
= REGULATOR_VOLTAGE
,
469 .owner
= THIS_MODULE
,
473 .ops
= &max8998_ldo_ops
,
474 .type
= REGULATOR_VOLTAGE
,
475 .owner
= THIS_MODULE
,
479 .ops
= &max8998_ldo_ops
,
480 .type
= REGULATOR_VOLTAGE
,
481 .owner
= THIS_MODULE
,
485 .ops
= &max8998_ldo_ops
,
486 .type
= REGULATOR_VOLTAGE
,
487 .owner
= THIS_MODULE
,
491 .ops
= &max8998_ldo_ops
,
492 .type
= REGULATOR_VOLTAGE
,
493 .owner
= THIS_MODULE
,
497 .ops
= &max8998_ldo_ops
,
498 .type
= REGULATOR_VOLTAGE
,
499 .owner
= THIS_MODULE
,
503 .ops
= &max8998_ldo_ops
,
504 .type
= REGULATOR_VOLTAGE
,
505 .owner
= THIS_MODULE
,
509 .ops
= &max8998_ldo_ops
,
510 .type
= REGULATOR_VOLTAGE
,
511 .owner
= THIS_MODULE
,
515 .ops
= &max8998_ldo_ops
,
516 .type
= REGULATOR_VOLTAGE
,
517 .owner
= THIS_MODULE
,
521 .ops
= &max8998_ldo_ops
,
522 .type
= REGULATOR_VOLTAGE
,
523 .owner
= THIS_MODULE
,
527 .ops
= &max8998_ldo_ops
,
528 .type
= REGULATOR_VOLTAGE
,
529 .owner
= THIS_MODULE
,
533 .ops
= &max8998_ldo_ops
,
534 .type
= REGULATOR_VOLTAGE
,
535 .owner
= THIS_MODULE
,
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_buck_ops
,
558 .type
= REGULATOR_VOLTAGE
,
559 .owner
= THIS_MODULE
,
563 .ops
= &max8998_buck_ops
,
564 .type
= REGULATOR_VOLTAGE
,
565 .owner
= THIS_MODULE
,
569 .ops
= &max8998_buck_ops
,
570 .type
= REGULATOR_VOLTAGE
,
571 .owner
= THIS_MODULE
,
575 .ops
= &max8998_buck_ops
,
576 .type
= REGULATOR_VOLTAGE
,
577 .owner
= THIS_MODULE
,
579 .name
= "EN32KHz-AP",
580 .id
= MAX8998_EN32KHZ_AP
,
581 .ops
= &max8998_others_ops
,
582 .type
= REGULATOR_VOLTAGE
,
583 .owner
= THIS_MODULE
,
585 .name
= "EN32KHz-CP",
586 .id
= MAX8998_EN32KHZ_CP
,
587 .ops
= &max8998_others_ops
,
588 .type
= REGULATOR_VOLTAGE
,
589 .owner
= THIS_MODULE
,
592 .id
= MAX8998_ENVICHG
,
593 .ops
= &max8998_others_ops
,
594 .type
= REGULATOR_VOLTAGE
,
595 .owner
= THIS_MODULE
,
598 .id
= MAX8998_ESAFEOUT1
,
599 .ops
= &max8998_others_ops
,
600 .type
= REGULATOR_VOLTAGE
,
601 .owner
= THIS_MODULE
,
604 .id
= MAX8998_ESAFEOUT2
,
605 .ops
= &max8998_others_ops
,
606 .type
= REGULATOR_VOLTAGE
,
607 .owner
= THIS_MODULE
,
611 static int max8998_pmic_dt_parse_dvs_gpio(struct max8998_dev
*iodev
,
612 struct max8998_platform_data
*pdata
,
613 struct device_node
*pmic_np
)
617 gpio
= of_get_named_gpio(pmic_np
, "max8998,pmic-buck1-dvs-gpios", 0);
618 if (!gpio_is_valid(gpio
)) {
619 dev_err(iodev
->dev
, "invalid buck1 gpio[0]: %d\n", gpio
);
622 pdata
->buck1_set1
= gpio
;
624 gpio
= of_get_named_gpio(pmic_np
, "max8998,pmic-buck1-dvs-gpios", 1);
625 if (!gpio_is_valid(gpio
)) {
626 dev_err(iodev
->dev
, "invalid buck1 gpio[1]: %d\n", gpio
);
629 pdata
->buck1_set2
= gpio
;
631 gpio
= of_get_named_gpio(pmic_np
, "max8998,pmic-buck2-dvs-gpio", 0);
632 if (!gpio_is_valid(gpio
)) {
633 dev_err(iodev
->dev
, "invalid buck 2 gpio: %d\n", gpio
);
636 pdata
->buck2_set3
= gpio
;
641 static int max8998_pmic_dt_parse_pdata(struct max8998_dev
*iodev
,
642 struct max8998_platform_data
*pdata
)
644 struct device_node
*pmic_np
= iodev
->dev
->of_node
;
645 struct device_node
*regulators_np
, *reg_np
;
646 struct max8998_regulator_data
*rdata
;
650 regulators_np
= of_get_child_by_name(pmic_np
, "regulators");
651 if (!regulators_np
) {
652 dev_err(iodev
->dev
, "could not find regulators sub-node\n");
656 /* count the number of regulators to be supported in pmic */
657 pdata
->num_regulators
= of_get_child_count(regulators_np
);
659 rdata
= devm_kcalloc(iodev
->dev
,
660 pdata
->num_regulators
, sizeof(*rdata
),
663 of_node_put(regulators_np
);
667 pdata
->regulators
= rdata
;
668 for (i
= 0; i
< ARRAY_SIZE(regulators
); ++i
) {
669 reg_np
= of_get_child_by_name(regulators_np
,
674 rdata
->id
= regulators
[i
].id
;
675 rdata
->initdata
= of_get_regulator_init_data(iodev
->dev
,
678 rdata
->reg_node
= reg_np
;
681 pdata
->num_regulators
= rdata
- pdata
->regulators
;
684 of_node_put(regulators_np
);
686 ret
= max8998_pmic_dt_parse_dvs_gpio(iodev
, pdata
, pmic_np
);
690 if (of_find_property(pmic_np
, "max8998,pmic-buck-voltage-lock", NULL
))
691 pdata
->buck_voltage_lock
= true;
693 ret
= of_property_read_u32(pmic_np
,
694 "max8998,pmic-buck1-default-dvs-idx",
695 &pdata
->buck1_default_idx
);
696 if (!ret
&& pdata
->buck1_default_idx
>= 4) {
697 pdata
->buck1_default_idx
= 0;
698 dev_warn(iodev
->dev
, "invalid value for default dvs index, using 0 instead\n");
701 ret
= of_property_read_u32(pmic_np
,
702 "max8998,pmic-buck2-default-dvs-idx",
703 &pdata
->buck2_default_idx
);
704 if (!ret
&& pdata
->buck2_default_idx
>= 2) {
705 pdata
->buck2_default_idx
= 0;
706 dev_warn(iodev
->dev
, "invalid value for default dvs index, using 0 instead\n");
709 ret
= of_property_read_u32_array(pmic_np
,
710 "max8998,pmic-buck1-dvs-voltage",
711 pdata
->buck1_voltage
,
712 ARRAY_SIZE(pdata
->buck1_voltage
));
714 dev_err(iodev
->dev
, "buck1 voltages not specified\n");
718 ret
= of_property_read_u32_array(pmic_np
,
719 "max8998,pmic-buck2-dvs-voltage",
720 pdata
->buck2_voltage
,
721 ARRAY_SIZE(pdata
->buck2_voltage
));
723 dev_err(iodev
->dev
, "buck2 voltages not specified\n");
730 static int max8998_pmic_probe(struct platform_device
*pdev
)
732 struct max8998_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
733 struct max8998_platform_data
*pdata
= iodev
->pdata
;
734 struct regulator_config config
= { };
735 struct regulator_dev
*rdev
;
736 struct max8998_data
*max8998
;
737 struct i2c_client
*i2c
;
742 dev_err(pdev
->dev
.parent
, "No platform init data supplied\n");
746 if (IS_ENABLED(CONFIG_OF
) && iodev
->dev
->of_node
) {
747 ret
= max8998_pmic_dt_parse_pdata(iodev
, pdata
);
752 max8998
= devm_kzalloc(&pdev
->dev
, sizeof(struct max8998_data
),
757 max8998
->dev
= &pdev
->dev
;
758 max8998
->iodev
= iodev
;
759 max8998
->num_regulators
= pdata
->num_regulators
;
760 platform_set_drvdata(pdev
, max8998
);
761 i2c
= max8998
->iodev
->i2c
;
763 max8998
->buck1_idx
= pdata
->buck1_default_idx
;
764 max8998
->buck2_idx
= pdata
->buck2_default_idx
;
767 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */
768 /* will be displayed */
770 /* Check if MAX8998 voltage selection GPIOs are defined */
771 if (gpio_is_valid(pdata
->buck1_set1
) &&
772 gpio_is_valid(pdata
->buck1_set2
)) {
773 /* Check if SET1 is not equal to 0 */
774 if (!pdata
->buck1_set1
) {
776 "MAX8998 SET1 GPIO defined as 0 !\n");
777 WARN_ON(!pdata
->buck1_set1
);
780 /* Check if SET2 is not equal to 0 */
781 if (!pdata
->buck1_set2
) {
783 "MAX8998 SET2 GPIO defined as 0 !\n");
784 WARN_ON(!pdata
->buck1_set2
);
788 gpio_request(pdata
->buck1_set1
, "MAX8998 BUCK1_SET1");
789 gpio_direction_output(pdata
->buck1_set1
,
790 max8998
->buck1_idx
& 0x1);
793 gpio_request(pdata
->buck1_set2
, "MAX8998 BUCK1_SET2");
794 gpio_direction_output(pdata
->buck1_set2
,
795 (max8998
->buck1_idx
>> 1) & 0x1);
797 /* Set predefined values for BUCK1 registers */
798 for (v
= 0; v
< ARRAY_SIZE(pdata
->buck1_voltage
); ++v
) {
800 while (buck12_voltage_map_desc
.min
+
801 buck12_voltage_map_desc
.step
*i
802 < pdata
->buck1_voltage
[v
])
805 max8998
->buck1_vol
[v
] = i
;
806 ret
= max8998_write_reg(i2c
,
807 MAX8998_REG_BUCK1_VOLTAGE1
+ v
, i
);
813 if (gpio_is_valid(pdata
->buck2_set3
)) {
814 /* Check if SET3 is not equal to 0 */
815 if (!pdata
->buck2_set3
) {
817 "MAX8998 SET3 GPIO defined as 0 !\n");
818 WARN_ON(!pdata
->buck2_set3
);
821 gpio_request(pdata
->buck2_set3
, "MAX8998 BUCK2_SET3");
822 gpio_direction_output(pdata
->buck2_set3
,
823 max8998
->buck2_idx
& 0x1);
825 /* Set predefined values for BUCK2 registers */
826 for (v
= 0; v
< ARRAY_SIZE(pdata
->buck2_voltage
); ++v
) {
828 while (buck12_voltage_map_desc
.min
+
829 buck12_voltage_map_desc
.step
*i
830 < pdata
->buck2_voltage
[v
])
833 max8998
->buck2_vol
[v
] = i
;
834 ret
= max8998_write_reg(i2c
,
835 MAX8998_REG_BUCK2_VOLTAGE1
+ v
, i
);
841 for (i
= 0; i
< pdata
->num_regulators
; i
++) {
842 const struct voltage_map_desc
*desc
;
843 int id
= pdata
->regulators
[i
].id
;
844 int index
= id
- MAX8998_LDO2
;
846 desc
= ldo_voltage_map
[id
];
847 if (desc
&& regulators
[index
].ops
!= &max8998_others_ops
) {
848 int count
= (desc
->max
- desc
->min
) / desc
->step
+ 1;
850 regulators
[index
].n_voltages
= count
;
851 regulators
[index
].min_uV
= desc
->min
;
852 regulators
[index
].uV_step
= desc
->step
;
855 config
.dev
= max8998
->dev
;
856 config
.of_node
= pdata
->regulators
[i
].reg_node
;
857 config
.init_data
= pdata
->regulators
[i
].initdata
;
858 config
.driver_data
= max8998
;
860 rdev
= devm_regulator_register(&pdev
->dev
, ®ulators
[index
],
864 dev_err(max8998
->dev
, "regulator %s init failed (%d)\n",
865 regulators
[index
].name
, ret
);
874 static const struct platform_device_id max8998_pmic_id
[] = {
875 { "max8998-pmic", TYPE_MAX8998
},
876 { "lp3974-pmic", TYPE_LP3974
},
879 MODULE_DEVICE_TABLE(platform
, max8998_pmic_id
);
881 static struct platform_driver max8998_pmic_driver
= {
883 .name
= "max8998-pmic",
885 .probe
= max8998_pmic_probe
,
886 .id_table
= max8998_pmic_id
,
889 static int __init
max8998_pmic_init(void)
891 return platform_driver_register(&max8998_pmic_driver
);
893 subsys_initcall(max8998_pmic_init
);
895 static void __exit
max8998_pmic_cleanup(void)
897 platform_driver_unregister(&max8998_pmic_driver
);
899 module_exit(max8998_pmic_cleanup
);
901 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
902 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
903 MODULE_LICENSE("GPL");