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/bits.h>
14 #include <linux/gpio/consumer.h>
15 #include <linux/slab.h>
16 #include <linux/interrupt.h>
17 #include <linux/mutex.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
;
34 struct gpio_desc
*buck1_gpio1
;
35 struct gpio_desc
*buck1_gpio2
;
36 struct gpio_desc
*buck2_gpio
;
39 static const unsigned int charger_current_table
[] = {
40 90000, 380000, 475000, 550000, 570000, 600000, 700000, 800000,
43 static int max8998_get_enable_register(struct regulator_dev
*rdev
,
46 int ldo
= rdev_get_id(rdev
);
49 case MAX8998_LDO2
... MAX8998_LDO5
:
50 *reg
= MAX8998_REG_ONOFF1
;
51 *shift
= 3 - (ldo
- MAX8998_LDO2
);
53 case MAX8998_LDO6
... MAX8998_LDO13
:
54 *reg
= MAX8998_REG_ONOFF2
;
55 *shift
= 7 - (ldo
- MAX8998_LDO6
);
57 case MAX8998_LDO14
... MAX8998_LDO17
:
58 *reg
= MAX8998_REG_ONOFF3
;
59 *shift
= 7 - (ldo
- MAX8998_LDO14
);
61 case MAX8998_BUCK1
... MAX8998_BUCK4
:
62 *reg
= MAX8998_REG_ONOFF1
;
63 *shift
= 7 - (ldo
- MAX8998_BUCK1
);
65 case MAX8998_EN32KHZ_AP
... MAX8998_ENVICHG
:
66 *reg
= MAX8998_REG_ONOFF4
;
67 *shift
= 7 - (ldo
- MAX8998_EN32KHZ_AP
);
69 case MAX8998_ESAFEOUT1
... MAX8998_ESAFEOUT2
:
70 *reg
= MAX8998_REG_CHGR2
;
71 *shift
= 7 - (ldo
- MAX8998_ESAFEOUT1
);
74 *reg
= MAX8998_REG_CHGR2
;
84 static int max8998_ldo_is_enabled(struct regulator_dev
*rdev
)
86 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
87 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
88 int ret
, reg
, shift
= 8;
91 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
95 ret
= max8998_read_reg(i2c
, reg
, &val
);
99 return val
& (1 << shift
);
102 static int max8998_ldo_is_enabled_inverted(struct regulator_dev
*rdev
)
104 return (!max8998_ldo_is_enabled(rdev
));
107 static int max8998_ldo_enable(struct regulator_dev
*rdev
)
109 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
110 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
111 int reg
, shift
= 8, ret
;
113 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
117 return max8998_update_reg(i2c
, reg
, 1<<shift
, 1<<shift
);
120 static int max8998_ldo_disable(struct regulator_dev
*rdev
)
122 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
123 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
124 int reg
, shift
= 8, ret
;
126 ret
= max8998_get_enable_register(rdev
, ®
, &shift
);
130 return max8998_update_reg(i2c
, reg
, 0, 1<<shift
);
133 static int max8998_get_voltage_register(struct regulator_dev
*rdev
,
134 int *_reg
, int *_shift
, int *_mask
)
136 int ldo
= rdev_get_id(rdev
);
137 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
138 int reg
, shift
= 0, mask
= 0xff;
141 case MAX8998_LDO2
... MAX8998_LDO3
:
142 reg
= MAX8998_REG_LDO2_LDO3
;
144 if (ldo
== MAX8998_LDO2
)
149 case MAX8998_LDO4
... MAX8998_LDO7
:
150 reg
= MAX8998_REG_LDO4
+ (ldo
- MAX8998_LDO4
);
152 case MAX8998_LDO8
... MAX8998_LDO9
:
153 reg
= MAX8998_REG_LDO8_LDO9
;
155 if (ldo
== MAX8998_LDO8
)
160 case MAX8998_LDO10
... MAX8998_LDO11
:
161 reg
= MAX8998_REG_LDO10_LDO11
;
162 if (ldo
== MAX8998_LDO10
) {
170 case MAX8998_LDO12
... MAX8998_LDO17
:
171 reg
= MAX8998_REG_LDO12
+ (ldo
- MAX8998_LDO12
);
174 reg
= MAX8998_REG_BUCK1_VOLTAGE1
+ max8998
->buck1_idx
;
177 reg
= MAX8998_REG_BUCK2_VOLTAGE1
+ max8998
->buck2_idx
;
180 reg
= MAX8998_REG_BUCK3
;
183 reg
= MAX8998_REG_BUCK4
;
196 static int max8998_get_voltage_sel(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
= 0, mask
, ret
;
203 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
207 ret
= max8998_read_reg(i2c
, reg
, &val
);
217 static int max8998_set_voltage_ldo_sel(struct regulator_dev
*rdev
,
220 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
221 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
222 int reg
, shift
= 0, mask
, ret
;
224 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
228 ret
= max8998_update_reg(i2c
, reg
, selector
<<shift
, mask
<<shift
);
233 static inline void buck1_gpio_set(struct gpio_desc
*gpio1
, struct gpio_desc
*gpio2
, int v
)
235 gpiod_set_value(gpio1
, v
& 0x1);
236 gpiod_set_value(gpio2
, (v
>> 1) & 0x1);
239 static inline void buck2_gpio_set(struct gpio_desc
*gpio
, int v
)
241 gpiod_set_value(gpio
, v
& 0x1);
244 static int max8998_set_voltage_buck_sel(struct regulator_dev
*rdev
,
247 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
248 struct max8998_platform_data
*pdata
= max8998
->iodev
->pdata
;
249 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
250 int buck
= rdev_get_id(rdev
);
251 int reg
, shift
= 0, mask
, ret
, j
;
252 static u8 buck1_last_val
;
254 ret
= max8998_get_voltage_register(rdev
, ®
, &shift
, &mask
);
260 dev_dbg(max8998
->dev
,
261 "BUCK1, selector:%d, buck1_vol1:%d, buck1_vol2:%d\n"
262 "buck1_vol3:%d, buck1_vol4:%d\n",
263 selector
, max8998
->buck1_vol
[0], max8998
->buck1_vol
[1],
264 max8998
->buck1_vol
[2], max8998
->buck1_vol
[3]);
266 if (max8998
->buck1_gpio1
&& max8998
->buck1_gpio2
) {
268 /* check if requested voltage */
269 /* value is already defined */
270 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck1_vol
); j
++) {
271 if (max8998
->buck1_vol
[j
] == selector
) {
272 max8998
->buck1_idx
= j
;
273 buck1_gpio_set(max8998
->buck1_gpio1
,
274 max8998
->buck1_gpio2
, j
);
279 if (pdata
->buck_voltage_lock
)
282 /* no predefine regulator found */
283 max8998
->buck1_idx
= (buck1_last_val
% 2) + 2;
284 dev_dbg(max8998
->dev
, "max8998->buck1_idx:%d\n",
286 max8998
->buck1_vol
[max8998
->buck1_idx
] = selector
;
287 ret
= max8998_get_voltage_register(rdev
, ®
,
290 ret
= max8998_write_reg(i2c
, reg
, selector
);
291 buck1_gpio_set(max8998
->buck1_gpio1
,
292 max8998
->buck1_gpio2
, max8998
->buck1_idx
);
295 dev_dbg(max8998
->dev
, "%s: SET1:%d, SET2:%d\n",
296 i2c
->name
, gpiod_get_value(max8998
->buck1_gpio1
),
297 gpiod_get_value(max8998
->buck1_gpio2
));
300 ret
= max8998_write_reg(i2c
, reg
, selector
);
305 dev_dbg(max8998
->dev
,
306 "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n",
307 selector
, max8998
->buck2_vol
[0], max8998
->buck2_vol
[1]);
308 if (max8998
->buck2_gpio
) {
309 /* check if requested voltage */
310 /* value is already defined */
311 for (j
= 0; j
< ARRAY_SIZE(max8998
->buck2_vol
); j
++) {
312 if (max8998
->buck2_vol
[j
] == selector
) {
313 max8998
->buck2_idx
= j
;
314 buck2_gpio_set(max8998
->buck2_gpio
, j
);
319 if (pdata
->buck_voltage_lock
)
322 max8998_get_voltage_register(rdev
,
323 ®
, &shift
, &mask
);
324 ret
= max8998_write_reg(i2c
, reg
, selector
);
325 max8998
->buck2_vol
[max8998
->buck2_idx
] = selector
;
326 buck2_gpio_set(max8998
->buck2_gpio
, max8998
->buck2_idx
);
328 dev_dbg(max8998
->dev
, "%s: SET3:%d\n", i2c
->name
,
329 gpiod_get_value(max8998
->buck2_gpio
));
331 ret
= max8998_write_reg(i2c
, reg
, selector
);
337 ret
= max8998_update_reg(i2c
, reg
, selector
<<shift
,
345 static int max8998_set_voltage_buck_time_sel(struct regulator_dev
*rdev
,
346 unsigned int old_selector
,
347 unsigned int new_selector
)
349 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
350 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
351 int buck
= rdev_get_id(rdev
);
355 if (buck
< MAX8998_BUCK1
|| buck
> MAX8998_BUCK4
)
358 /* Voltage stabilization */
359 ret
= max8998_read_reg(i2c
, MAX8998_REG_ONOFF4
, &val
);
363 /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */
364 /* MAX8998 has ENRAMP bit implemented, so test it*/
365 if (max8998
->iodev
->type
== TYPE_MAX8998
&& !(val
& MAX8998_ENRAMP
))
368 difference
= (new_selector
- old_selector
) * rdev
->desc
->uV_step
/ 1000;
370 return DIV_ROUND_UP(difference
, (val
& 0x0f) + 1);
375 static int max8998_set_current_limit(struct regulator_dev
*rdev
,
376 int min_uA
, int max_uA
)
378 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
379 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
380 unsigned int n_currents
= rdev
->desc
->n_current_limits
;
386 if (rdev
->desc
->curr_table
) {
387 const unsigned int *curr_table
= rdev
->desc
->curr_table
;
388 bool ascend
= curr_table
[n_currents
- 1] > curr_table
[0];
390 /* search for closest to maximum */
392 for (i
= n_currents
- 1; i
>= 0; i
--) {
393 if (min_uA
<= curr_table
[i
] &&
394 curr_table
[i
] <= max_uA
) {
400 for (i
= 0; i
< n_currents
; i
++) {
401 if (min_uA
<= curr_table
[i
] &&
402 curr_table
[i
] <= max_uA
) {
413 sel
<<= ffs(rdev
->desc
->csel_mask
) - 1;
415 return max8998_update_reg(i2c
, rdev
->desc
->csel_reg
,
416 sel
, rdev
->desc
->csel_mask
);
419 static int max8998_get_current_limit(struct regulator_dev
*rdev
)
421 struct max8998_data
*max8998
= rdev_get_drvdata(rdev
);
422 struct i2c_client
*i2c
= max8998
->iodev
->i2c
;
426 ret
= max8998_read_reg(i2c
, rdev
->desc
->csel_reg
, &val
);
430 val
&= rdev
->desc
->csel_mask
;
431 val
>>= ffs(rdev
->desc
->csel_mask
) - 1;
433 if (rdev
->desc
->curr_table
) {
434 if (val
>= rdev
->desc
->n_current_limits
)
437 return rdev
->desc
->curr_table
[val
];
443 static const struct regulator_ops max8998_ldo_ops
= {
444 .list_voltage
= regulator_list_voltage_linear
,
445 .map_voltage
= regulator_map_voltage_linear
,
446 .is_enabled
= max8998_ldo_is_enabled
,
447 .enable
= max8998_ldo_enable
,
448 .disable
= max8998_ldo_disable
,
449 .get_voltage_sel
= max8998_get_voltage_sel
,
450 .set_voltage_sel
= max8998_set_voltage_ldo_sel
,
453 static const struct regulator_ops max8998_buck_ops
= {
454 .list_voltage
= regulator_list_voltage_linear
,
455 .map_voltage
= regulator_map_voltage_linear
,
456 .is_enabled
= max8998_ldo_is_enabled
,
457 .enable
= max8998_ldo_enable
,
458 .disable
= max8998_ldo_disable
,
459 .get_voltage_sel
= max8998_get_voltage_sel
,
460 .set_voltage_sel
= max8998_set_voltage_buck_sel
,
461 .set_voltage_time_sel
= max8998_set_voltage_buck_time_sel
,
464 static const struct regulator_ops max8998_charger_ops
= {
465 .set_current_limit
= max8998_set_current_limit
,
466 .get_current_limit
= max8998_get_current_limit
,
467 .is_enabled
= max8998_ldo_is_enabled_inverted
,
468 /* Swapped as register is inverted */
469 .enable
= max8998_ldo_disable
,
470 .disable
= max8998_ldo_enable
,
473 static const struct regulator_ops max8998_others_ops
= {
474 .is_enabled
= max8998_ldo_is_enabled
,
475 .enable
= max8998_ldo_enable
,
476 .disable
= max8998_ldo_disable
,
479 #define MAX8998_LINEAR_REG(_name, _ops, _min, _step, _max) \
482 .id = MAX8998_##_name, \
485 .uV_step = (_step), \
486 .n_voltages = ((_max) - (_min)) / (_step) + 1, \
487 .type = REGULATOR_VOLTAGE, \
488 .owner = THIS_MODULE, \
491 #define MAX8998_CURRENT_REG(_name, _ops, _table, _reg, _mask) \
494 .id = MAX8998_##_name, \
496 .curr_table = _table, \
497 .n_current_limits = ARRAY_SIZE(_table), \
499 .csel_mask = _mask, \
500 .type = REGULATOR_CURRENT, \
501 .owner = THIS_MODULE, \
504 #define MAX8998_OTHERS_REG(_name, _id) \
508 .ops = &max8998_others_ops, \
509 .type = REGULATOR_VOLTAGE, \
510 .owner = THIS_MODULE, \
513 static const struct regulator_desc regulators
[] = {
514 MAX8998_LINEAR_REG(LDO2
, &max8998_ldo_ops
, 800000, 50000, 1300000),
515 MAX8998_LINEAR_REG(LDO3
, &max8998_ldo_ops
, 800000, 50000, 1300000),
516 MAX8998_LINEAR_REG(LDO4
, &max8998_ldo_ops
, 1600000, 100000, 3600000),
517 MAX8998_LINEAR_REG(LDO5
, &max8998_ldo_ops
, 1600000, 100000, 3600000),
518 MAX8998_LINEAR_REG(LDO6
, &max8998_ldo_ops
, 1600000, 100000, 3600000),
519 MAX8998_LINEAR_REG(LDO7
, &max8998_ldo_ops
, 1600000, 100000, 3600000),
520 MAX8998_LINEAR_REG(LDO8
, &max8998_ldo_ops
, 3000000, 100000, 3600000),
521 MAX8998_LINEAR_REG(LDO9
, &max8998_ldo_ops
, 2800000, 100000, 3100000),
522 MAX8998_LINEAR_REG(LDO10
, &max8998_ldo_ops
, 950000, 50000, 1300000),
523 MAX8998_LINEAR_REG(LDO11
, &max8998_ldo_ops
, 1600000, 100000, 3600000),
524 MAX8998_LINEAR_REG(LDO12
, &max8998_ldo_ops
, 800000, 100000, 3300000),
525 MAX8998_LINEAR_REG(LDO13
, &max8998_ldo_ops
, 800000, 100000, 3300000),
526 MAX8998_LINEAR_REG(LDO14
, &max8998_ldo_ops
, 1200000, 100000, 3300000),
527 MAX8998_LINEAR_REG(LDO15
, &max8998_ldo_ops
, 1200000, 100000, 3300000),
528 MAX8998_LINEAR_REG(LDO16
, &max8998_ldo_ops
, 1600000, 100000, 3600000),
529 MAX8998_LINEAR_REG(LDO17
, &max8998_ldo_ops
, 1600000, 100000, 3600000),
530 MAX8998_LINEAR_REG(BUCK1
, &max8998_buck_ops
, 750000, 25000, 1525000),
531 MAX8998_LINEAR_REG(BUCK2
, &max8998_buck_ops
, 750000, 25000, 1525000),
532 MAX8998_LINEAR_REG(BUCK3
, &max8998_buck_ops
, 1600000, 100000, 3600000),
533 MAX8998_LINEAR_REG(BUCK4
, &max8998_buck_ops
, 800000, 100000, 2300000),
534 MAX8998_OTHERS_REG(EN32KHz
-AP
, MAX8998_EN32KHZ_AP
),
535 MAX8998_OTHERS_REG(EN32KHz
-CP
, MAX8998_EN32KHZ_CP
),
536 MAX8998_OTHERS_REG(ENVICHG
, MAX8998_ENVICHG
),
537 MAX8998_OTHERS_REG(ESAFEOUT1
, MAX8998_ESAFEOUT1
),
538 MAX8998_OTHERS_REG(ESAFEOUT2
, MAX8998_ESAFEOUT2
),
539 MAX8998_CURRENT_REG(CHARGER
, &max8998_charger_ops
,
540 charger_current_table
, MAX8998_REG_CHGR1
, 0x7),
543 static int max8998_pmic_dt_parse_pdata(struct max8998_dev
*iodev
,
544 struct max8998_platform_data
*pdata
)
546 struct device_node
*pmic_np
= iodev
->dev
->of_node
;
547 struct device_node
*regulators_np
, *reg_np
;
548 struct max8998_regulator_data
*rdata
;
552 regulators_np
= of_get_child_by_name(pmic_np
, "regulators");
553 if (!regulators_np
) {
554 dev_err(iodev
->dev
, "could not find regulators sub-node\n");
558 /* count the number of regulators to be supported in pmic */
559 pdata
->num_regulators
= of_get_child_count(regulators_np
);
561 rdata
= devm_kcalloc(iodev
->dev
,
562 pdata
->num_regulators
, sizeof(*rdata
),
565 of_node_put(regulators_np
);
569 pdata
->regulators
= rdata
;
570 for (i
= 0; i
< ARRAY_SIZE(regulators
); ++i
) {
571 reg_np
= of_get_child_by_name(regulators_np
,
576 rdata
->id
= regulators
[i
].id
;
577 rdata
->initdata
= of_get_regulator_init_data(iodev
->dev
,
580 rdata
->reg_node
= reg_np
;
583 pdata
->num_regulators
= rdata
- pdata
->regulators
;
586 of_node_put(regulators_np
);
588 pdata
->buck_voltage_lock
= of_property_read_bool(pmic_np
, "max8998,pmic-buck-voltage-lock");
590 ret
= of_property_read_u32(pmic_np
,
591 "max8998,pmic-buck1-default-dvs-idx",
592 &pdata
->buck1_default_idx
);
593 if (!ret
&& pdata
->buck1_default_idx
>= 4) {
594 pdata
->buck1_default_idx
= 0;
595 dev_warn(iodev
->dev
, "invalid value for default dvs index, using 0 instead\n");
598 ret
= of_property_read_u32(pmic_np
,
599 "max8998,pmic-buck2-default-dvs-idx",
600 &pdata
->buck2_default_idx
);
601 if (!ret
&& pdata
->buck2_default_idx
>= 2) {
602 pdata
->buck2_default_idx
= 0;
603 dev_warn(iodev
->dev
, "invalid value for default dvs index, using 0 instead\n");
606 ret
= of_property_read_u32_array(pmic_np
,
607 "max8998,pmic-buck1-dvs-voltage",
608 pdata
->buck1_voltage
,
609 ARRAY_SIZE(pdata
->buck1_voltage
));
611 dev_err(iodev
->dev
, "buck1 voltages not specified\n");
615 ret
= of_property_read_u32_array(pmic_np
,
616 "max8998,pmic-buck2-dvs-voltage",
617 pdata
->buck2_voltage
,
618 ARRAY_SIZE(pdata
->buck2_voltage
));
620 dev_err(iodev
->dev
, "buck2 voltages not specified\n");
627 static int max8998_pmic_probe(struct platform_device
*pdev
)
629 struct max8998_dev
*iodev
= dev_get_drvdata(pdev
->dev
.parent
);
630 struct max8998_platform_data
*pdata
= iodev
->pdata
;
631 struct regulator_config config
= { };
632 struct regulator_dev
*rdev
;
633 struct max8998_data
*max8998
;
634 struct i2c_client
*i2c
;
635 enum gpiod_flags flags
;
640 dev_err(pdev
->dev
.parent
, "No platform init data supplied\n");
644 if (IS_ENABLED(CONFIG_OF
) && iodev
->dev
->of_node
) {
645 ret
= max8998_pmic_dt_parse_pdata(iodev
, pdata
);
650 max8998
= devm_kzalloc(&pdev
->dev
, sizeof(struct max8998_data
),
655 max8998
->dev
= &pdev
->dev
;
656 max8998
->iodev
= iodev
;
657 max8998
->num_regulators
= pdata
->num_regulators
;
658 platform_set_drvdata(pdev
, max8998
);
659 i2c
= max8998
->iodev
->i2c
;
661 max8998
->buck1_idx
= pdata
->buck1_default_idx
;
662 max8998
->buck2_idx
= pdata
->buck2_default_idx
;
664 /* Check if MAX8998 voltage selection GPIOs are defined */
665 flags
= (max8998
->buck1_idx
& BIT(0)) ? GPIOD_OUT_HIGH
: GPIOD_OUT_LOW
;
666 max8998
->buck1_gpio1
= devm_gpiod_get_index_optional(iodev
->dev
,
667 "max8998,pmic-buck1-dvs",
670 if (IS_ERR(max8998
->buck1_gpio1
))
671 return dev_err_probe(&pdev
->dev
, PTR_ERR(max8998
->buck1_gpio1
),
672 "could not get BUCK1 GPIO1\n");
673 gpiod_set_consumer_name(max8998
->buck1_gpio1
, "MAX8998 BUCK1_SET1");
675 flags
= (max8998
->buck1_idx
& BIT(1)) ? GPIOD_OUT_HIGH
: GPIOD_OUT_LOW
;
676 max8998
->buck1_gpio2
= devm_gpiod_get_index_optional(iodev
->dev
,
677 "max8998,pmic-buck1-dvs",
680 if (IS_ERR(max8998
->buck1_gpio2
))
681 return dev_err_probe(&pdev
->dev
, PTR_ERR(max8998
->buck1_gpio2
),
682 "could not get BUCK1 GPIO2\n");
683 gpiod_set_consumer_name(max8998
->buck1_gpio1
, "MAX8998 BUCK1_SET2");
685 flags
= (max8998
->buck2_idx
& BIT(0)) ? GPIOD_OUT_HIGH
: GPIOD_OUT_LOW
;
686 max8998
->buck2_gpio
= devm_gpiod_get_index_optional(iodev
->dev
,
687 "max8998,pmic-buck2-dvs",
690 if (IS_ERR(max8998
->buck2_gpio
))
691 return dev_err_probe(&pdev
->dev
, PTR_ERR(max8998
->buck2_gpio
),
692 "could not get BUCK2 GPIO\n");
693 gpiod_set_consumer_name(max8998
->buck1_gpio1
, "MAX8998 BUCK2_SET3");
695 if (max8998
->buck1_gpio1
&& max8998
->buck1_gpio2
) {
696 /* Set predefined values for BUCK1 registers */
697 for (v
= 0; v
< ARRAY_SIZE(pdata
->buck1_voltage
); ++v
) {
698 int index
= MAX8998_BUCK1
- MAX8998_LDO2
;
701 while (regulators
[index
].min_uV
+
702 regulators
[index
].uV_step
* i
703 < pdata
->buck1_voltage
[v
])
706 max8998
->buck1_vol
[v
] = i
;
707 ret
= max8998_write_reg(i2c
,
708 MAX8998_REG_BUCK1_VOLTAGE1
+ v
, i
);
714 if (max8998
->buck2_gpio
) {
715 /* Set predefined values for BUCK2 registers */
716 for (v
= 0; v
< ARRAY_SIZE(pdata
->buck2_voltage
); ++v
) {
717 int index
= MAX8998_BUCK2
- MAX8998_LDO2
;
720 while (regulators
[index
].min_uV
+
721 regulators
[index
].uV_step
* i
722 < pdata
->buck2_voltage
[v
])
725 max8998
->buck2_vol
[v
] = i
;
726 ret
= max8998_write_reg(i2c
,
727 MAX8998_REG_BUCK2_VOLTAGE1
+ v
, i
);
733 for (i
= 0; i
< pdata
->num_regulators
; i
++) {
734 int index
= pdata
->regulators
[i
].id
- MAX8998_LDO2
;
736 config
.dev
= max8998
->dev
;
737 config
.of_node
= pdata
->regulators
[i
].reg_node
;
738 config
.init_data
= pdata
->regulators
[i
].initdata
;
739 config
.driver_data
= max8998
;
741 rdev
= devm_regulator_register(&pdev
->dev
, ®ulators
[index
],
745 dev_err(max8998
->dev
, "regulator %s init failed (%d)\n",
746 regulators
[index
].name
, ret
);
754 static const struct platform_device_id max8998_pmic_id
[] = {
755 { "max8998-pmic", TYPE_MAX8998
},
756 { "lp3974-pmic", TYPE_LP3974
},
759 MODULE_DEVICE_TABLE(platform
, max8998_pmic_id
);
761 static struct platform_driver max8998_pmic_driver
= {
763 .name
= "max8998-pmic",
764 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
766 .probe
= max8998_pmic_probe
,
767 .id_table
= max8998_pmic_id
,
770 static int __init
max8998_pmic_init(void)
772 return platform_driver_register(&max8998_pmic_driver
);
774 subsys_initcall(max8998_pmic_init
);
776 static void __exit
max8998_pmic_cleanup(void)
778 platform_driver_unregister(&max8998_pmic_driver
);
780 module_exit(max8998_pmic_cleanup
);
782 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
783 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
784 MODULE_LICENSE("GPL");