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 static const unsigned int charger_current_table[] = {
37 90000, 380000, 475000, 550000, 570000, 600000, 700000, 800000,
40 static int max8998_get_enable_register(struct regulator_dev *rdev,
43 int ldo = rdev_get_id(rdev);
46 case MAX8998_LDO2 ... MAX8998_LDO5:
47 *reg = MAX8998_REG_ONOFF1;
48 *shift = 3 - (ldo - MAX8998_LDO2);
50 case MAX8998_LDO6 ... MAX8998_LDO13:
51 *reg = MAX8998_REG_ONOFF2;
52 *shift = 7 - (ldo - MAX8998_LDO6);
54 case MAX8998_LDO14 ... MAX8998_LDO17:
55 *reg = MAX8998_REG_ONOFF3;
56 *shift = 7 - (ldo - MAX8998_LDO14);
58 case MAX8998_BUCK1 ... MAX8998_BUCK4:
59 *reg = MAX8998_REG_ONOFF1;
60 *shift = 7 - (ldo - MAX8998_BUCK1);
62 case MAX8998_EN32KHZ_AP ... MAX8998_ENVICHG:
63 *reg = MAX8998_REG_ONOFF4;
64 *shift = 7 - (ldo - MAX8998_EN32KHZ_AP);
66 case MAX8998_ESAFEOUT1 ... MAX8998_ESAFEOUT2:
67 *reg = MAX8998_REG_CHGR2;
68 *shift = 7 - (ldo - MAX8998_ESAFEOUT1);
71 *reg = MAX8998_REG_CHGR2;
81 static int max8998_ldo_is_enabled(struct regulator_dev *rdev)
83 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
84 struct i2c_client *i2c = max8998->iodev->i2c;
85 int ret, reg, shift = 8;
88 ret = max8998_get_enable_register(rdev, ®, &shift);
92 ret = max8998_read_reg(i2c, reg, &val);
96 return val & (1 << shift);
99 static int max8998_ldo_is_enabled_inverted(struct regulator_dev *rdev)
101 return (!max8998_ldo_is_enabled(rdev));
104 static int max8998_ldo_enable(struct regulator_dev *rdev)
106 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
107 struct i2c_client *i2c = max8998->iodev->i2c;
108 int reg, shift = 8, ret;
110 ret = max8998_get_enable_register(rdev, ®, &shift);
114 return max8998_update_reg(i2c, reg, 1<<shift, 1<<shift);
117 static int max8998_ldo_disable(struct regulator_dev *rdev)
119 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
120 struct i2c_client *i2c = max8998->iodev->i2c;
121 int reg, shift = 8, ret;
123 ret = max8998_get_enable_register(rdev, ®, &shift);
127 return max8998_update_reg(i2c, reg, 0, 1<<shift);
130 static int max8998_get_voltage_register(struct regulator_dev *rdev,
131 int *_reg, int *_shift, int *_mask)
133 int ldo = rdev_get_id(rdev);
134 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
135 int reg, shift = 0, mask = 0xff;
138 case MAX8998_LDO2 ... MAX8998_LDO3:
139 reg = MAX8998_REG_LDO2_LDO3;
141 if (ldo == MAX8998_LDO2)
146 case MAX8998_LDO4 ... MAX8998_LDO7:
147 reg = MAX8998_REG_LDO4 + (ldo - MAX8998_LDO4);
149 case MAX8998_LDO8 ... MAX8998_LDO9:
150 reg = MAX8998_REG_LDO8_LDO9;
152 if (ldo == MAX8998_LDO8)
157 case MAX8998_LDO10 ... MAX8998_LDO11:
158 reg = MAX8998_REG_LDO10_LDO11;
159 if (ldo == MAX8998_LDO10) {
167 case MAX8998_LDO12 ... MAX8998_LDO17:
168 reg = MAX8998_REG_LDO12 + (ldo - MAX8998_LDO12);
171 reg = MAX8998_REG_BUCK1_VOLTAGE1 + max8998->buck1_idx;
174 reg = MAX8998_REG_BUCK2_VOLTAGE1 + max8998->buck2_idx;
177 reg = MAX8998_REG_BUCK3;
180 reg = MAX8998_REG_BUCK4;
193 static int max8998_get_voltage_sel(struct regulator_dev *rdev)
195 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
196 struct i2c_client *i2c = max8998->iodev->i2c;
197 int reg, shift = 0, mask, ret;
200 ret = max8998_get_voltage_register(rdev, ®, &shift, &mask);
204 ret = max8998_read_reg(i2c, reg, &val);
214 static int max8998_set_voltage_ldo_sel(struct regulator_dev *rdev,
217 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
218 struct i2c_client *i2c = max8998->iodev->i2c;
219 int reg, shift = 0, mask, ret;
221 ret = max8998_get_voltage_register(rdev, ®, &shift, &mask);
225 ret = max8998_update_reg(i2c, reg, selector<<shift, mask<<shift);
230 static inline void buck1_gpio_set(int gpio1, int gpio2, int v)
232 gpio_set_value(gpio1, v & 0x1);
233 gpio_set_value(gpio2, (v >> 1) & 0x1);
236 static inline void buck2_gpio_set(int gpio, int v)
238 gpio_set_value(gpio, v & 0x1);
241 static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev,
244 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
245 struct max8998_platform_data *pdata = max8998->iodev->pdata;
246 struct i2c_client *i2c = max8998->iodev->i2c;
247 int buck = rdev_get_id(rdev);
248 int reg, shift = 0, mask, ret, j;
249 static u8 buck1_last_val;
251 ret = max8998_get_voltage_register(rdev, ®, &shift, &mask);
257 dev_dbg(max8998->dev,
258 "BUCK1, selector:%d, buck1_vol1:%d, buck1_vol2:%d\n"
259 "buck1_vol3:%d, buck1_vol4:%d\n",
260 selector, max8998->buck1_vol[0], max8998->buck1_vol[1],
261 max8998->buck1_vol[2], max8998->buck1_vol[3]);
263 if (gpio_is_valid(pdata->buck1_set1) &&
264 gpio_is_valid(pdata->buck1_set2)) {
266 /* check if requested voltage */
267 /* value is already defined */
268 for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) {
269 if (max8998->buck1_vol[j] == selector) {
270 max8998->buck1_idx = j;
271 buck1_gpio_set(pdata->buck1_set1,
272 pdata->buck1_set2, j);
277 if (pdata->buck_voltage_lock)
280 /* no predefine regulator found */
281 max8998->buck1_idx = (buck1_last_val % 2) + 2;
282 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n",
284 max8998->buck1_vol[max8998->buck1_idx] = selector;
285 ret = max8998_get_voltage_register(rdev, ®,
288 ret = max8998_write_reg(i2c, reg, selector);
289 buck1_gpio_set(pdata->buck1_set1,
290 pdata->buck1_set2, max8998->buck1_idx);
293 dev_dbg(max8998->dev, "%s: SET1:%d, SET2:%d\n",
294 i2c->name, gpio_get_value(pdata->buck1_set1),
295 gpio_get_value(pdata->buck1_set2));
298 ret = max8998_write_reg(i2c, reg, selector);
303 dev_dbg(max8998->dev,
304 "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n",
305 selector, max8998->buck2_vol[0], max8998->buck2_vol[1]);
306 if (gpio_is_valid(pdata->buck2_set3)) {
308 /* check if requested voltage */
309 /* value is already defined */
310 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) {
311 if (max8998->buck2_vol[j] == selector) {
312 max8998->buck2_idx = j;
313 buck2_gpio_set(pdata->buck2_set3, j);
318 if (pdata->buck_voltage_lock)
321 max8998_get_voltage_register(rdev,
322 ®, &shift, &mask);
323 ret = max8998_write_reg(i2c, reg, selector);
324 max8998->buck2_vol[max8998->buck2_idx] = selector;
325 buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx);
327 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name,
328 gpio_get_value(pdata->buck2_set3));
330 ret = max8998_write_reg(i2c, reg, selector);
336 ret = max8998_update_reg(i2c, reg, selector<<shift,
344 static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev,
345 unsigned int old_selector,
346 unsigned int new_selector)
348 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
349 struct i2c_client *i2c = max8998->iodev->i2c;
350 int buck = rdev_get_id(rdev);
354 if (buck < MAX8998_BUCK1 || buck > MAX8998_BUCK4)
357 /* Voltage stabilization */
358 ret = max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val);
362 /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */
363 /* MAX8998 has ENRAMP bit implemented, so test it*/
364 if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP))
367 difference = (new_selector - old_selector) * rdev->desc->uV_step / 1000;
369 return DIV_ROUND_UP(difference, (val & 0x0f) + 1);
374 static int max8998_set_current_limit(struct regulator_dev *rdev,
375 int min_uA, int max_uA)
377 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
378 struct i2c_client *i2c = max8998->iodev->i2c;
379 unsigned int n_currents = rdev->desc->n_current_limits;
385 if (rdev->desc->curr_table) {
386 const unsigned int *curr_table = rdev->desc->curr_table;
387 bool ascend = curr_table[n_currents - 1] > curr_table[0];
389 /* search for closest to maximum */
391 for (i = n_currents - 1; i >= 0; i--) {
392 if (min_uA <= curr_table[i] &&
393 curr_table[i] <= max_uA) {
399 for (i = 0; i < n_currents; i++) {
400 if (min_uA <= curr_table[i] &&
401 curr_table[i] <= max_uA) {
412 sel <<= ffs(rdev->desc->csel_mask) - 1;
414 return max8998_update_reg(i2c, rdev->desc->csel_reg,
415 sel, rdev->desc->csel_mask);
418 static int max8998_get_current_limit(struct regulator_dev *rdev)
420 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
421 struct i2c_client *i2c = max8998->iodev->i2c;
425 ret = max8998_read_reg(i2c, rdev->desc->csel_reg, &val);
429 val &= rdev->desc->csel_mask;
430 val >>= ffs(rdev->desc->csel_mask) - 1;
432 if (rdev->desc->curr_table) {
433 if (val >= rdev->desc->n_current_limits)
436 return rdev->desc->curr_table[val];
442 static const struct regulator_ops max8998_ldo_ops = {
443 .list_voltage = regulator_list_voltage_linear,
444 .map_voltage = regulator_map_voltage_linear,
445 .is_enabled = max8998_ldo_is_enabled,
446 .enable = max8998_ldo_enable,
447 .disable = max8998_ldo_disable,
448 .get_voltage_sel = max8998_get_voltage_sel,
449 .set_voltage_sel = max8998_set_voltage_ldo_sel,
452 static const struct regulator_ops max8998_buck_ops = {
453 .list_voltage = regulator_list_voltage_linear,
454 .map_voltage = regulator_map_voltage_linear,
455 .is_enabled = max8998_ldo_is_enabled,
456 .enable = max8998_ldo_enable,
457 .disable = max8998_ldo_disable,
458 .get_voltage_sel = max8998_get_voltage_sel,
459 .set_voltage_sel = max8998_set_voltage_buck_sel,
460 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel,
463 static const struct regulator_ops max8998_charger_ops = {
464 .set_current_limit = max8998_set_current_limit,
465 .get_current_limit = max8998_get_current_limit,
466 .is_enabled = max8998_ldo_is_enabled_inverted,
467 /* Swapped as register is inverted */
468 .enable = max8998_ldo_disable,
469 .disable = max8998_ldo_enable,
472 static const struct regulator_ops max8998_others_ops = {
473 .is_enabled = max8998_ldo_is_enabled,
474 .enable = max8998_ldo_enable,
475 .disable = max8998_ldo_disable,
478 #define MAX8998_LINEAR_REG(_name, _ops, _min, _step, _max) \
481 .id = MAX8998_##_name, \
484 .uV_step = (_step), \
485 .n_voltages = ((_max) - (_min)) / (_step) + 1, \
486 .type = REGULATOR_VOLTAGE, \
487 .owner = THIS_MODULE, \
490 #define MAX8998_CURRENT_REG(_name, _ops, _table, _reg, _mask) \
493 .id = MAX8998_##_name, \
495 .curr_table = _table, \
496 .n_current_limits = ARRAY_SIZE(_table), \
498 .csel_mask = _mask, \
499 .type = REGULATOR_CURRENT, \
500 .owner = THIS_MODULE, \
503 #define MAX8998_OTHERS_REG(_name, _id) \
507 .ops = &max8998_others_ops, \
508 .type = REGULATOR_VOLTAGE, \
509 .owner = THIS_MODULE, \
512 static const struct regulator_desc regulators[] = {
513 MAX8998_LINEAR_REG(LDO2, &max8998_ldo_ops, 800000, 50000, 1300000),
514 MAX8998_LINEAR_REG(LDO3, &max8998_ldo_ops, 800000, 50000, 1300000),
515 MAX8998_LINEAR_REG(LDO4, &max8998_ldo_ops, 1600000, 100000, 3600000),
516 MAX8998_LINEAR_REG(LDO5, &max8998_ldo_ops, 1600000, 100000, 3600000),
517 MAX8998_LINEAR_REG(LDO6, &max8998_ldo_ops, 1600000, 100000, 3600000),
518 MAX8998_LINEAR_REG(LDO7, &max8998_ldo_ops, 1600000, 100000, 3600000),
519 MAX8998_LINEAR_REG(LDO8, &max8998_ldo_ops, 3000000, 100000, 3600000),
520 MAX8998_LINEAR_REG(LDO9, &max8998_ldo_ops, 2800000, 100000, 3100000),
521 MAX8998_LINEAR_REG(LDO10, &max8998_ldo_ops, 950000, 50000, 1300000),
522 MAX8998_LINEAR_REG(LDO11, &max8998_ldo_ops, 1600000, 100000, 3600000),
523 MAX8998_LINEAR_REG(LDO12, &max8998_ldo_ops, 800000, 100000, 3300000),
524 MAX8998_LINEAR_REG(LDO13, &max8998_ldo_ops, 800000, 100000, 3300000),
525 MAX8998_LINEAR_REG(LDO14, &max8998_ldo_ops, 1200000, 100000, 3300000),
526 MAX8998_LINEAR_REG(LDO15, &max8998_ldo_ops, 1200000, 100000, 3300000),
527 MAX8998_LINEAR_REG(LDO16, &max8998_ldo_ops, 1600000, 100000, 3600000),
528 MAX8998_LINEAR_REG(LDO17, &max8998_ldo_ops, 1600000, 100000, 3600000),
529 MAX8998_LINEAR_REG(BUCK1, &max8998_buck_ops, 750000, 25000, 1525000),
530 MAX8998_LINEAR_REG(BUCK2, &max8998_buck_ops, 750000, 25000, 1525000),
531 MAX8998_LINEAR_REG(BUCK3, &max8998_buck_ops, 1600000, 100000, 3600000),
532 MAX8998_LINEAR_REG(BUCK4, &max8998_buck_ops, 800000, 100000, 2300000),
533 MAX8998_OTHERS_REG(EN32KHz-AP, MAX8998_EN32KHZ_AP),
534 MAX8998_OTHERS_REG(EN32KHz-CP, MAX8998_EN32KHZ_CP),
535 MAX8998_OTHERS_REG(ENVICHG, MAX8998_ENVICHG),
536 MAX8998_OTHERS_REG(ESAFEOUT1, MAX8998_ESAFEOUT1),
537 MAX8998_OTHERS_REG(ESAFEOUT2, MAX8998_ESAFEOUT2),
538 MAX8998_CURRENT_REG(CHARGER, &max8998_charger_ops,
539 charger_current_table, MAX8998_REG_CHGR1, 0x7),
542 static int max8998_pmic_dt_parse_dvs_gpio(struct max8998_dev *iodev,
543 struct max8998_platform_data *pdata,
544 struct device_node *pmic_np)
548 gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck1-dvs-gpios", 0);
549 if (!gpio_is_valid(gpio)) {
550 dev_err(iodev->dev, "invalid buck1 gpio[0]: %d\n", gpio);
553 pdata->buck1_set1 = gpio;
555 gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck1-dvs-gpios", 1);
556 if (!gpio_is_valid(gpio)) {
557 dev_err(iodev->dev, "invalid buck1 gpio[1]: %d\n", gpio);
560 pdata->buck1_set2 = gpio;
562 gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck2-dvs-gpio", 0);
563 if (!gpio_is_valid(gpio)) {
564 dev_err(iodev->dev, "invalid buck 2 gpio: %d\n", gpio);
567 pdata->buck2_set3 = gpio;
572 static int max8998_pmic_dt_parse_pdata(struct max8998_dev *iodev,
573 struct max8998_platform_data *pdata)
575 struct device_node *pmic_np = iodev->dev->of_node;
576 struct device_node *regulators_np, *reg_np;
577 struct max8998_regulator_data *rdata;
581 regulators_np = of_get_child_by_name(pmic_np, "regulators");
582 if (!regulators_np) {
583 dev_err(iodev->dev, "could not find regulators sub-node\n");
587 /* count the number of regulators to be supported in pmic */
588 pdata->num_regulators = of_get_child_count(regulators_np);
590 rdata = devm_kcalloc(iodev->dev,
591 pdata->num_regulators, sizeof(*rdata),
594 of_node_put(regulators_np);
598 pdata->regulators = rdata;
599 for (i = 0; i < ARRAY_SIZE(regulators); ++i) {
600 reg_np = of_get_child_by_name(regulators_np,
605 rdata->id = regulators[i].id;
606 rdata->initdata = of_get_regulator_init_data(iodev->dev,
609 rdata->reg_node = reg_np;
612 pdata->num_regulators = rdata - pdata->regulators;
615 of_node_put(regulators_np);
617 ret = max8998_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np);
621 if (of_find_property(pmic_np, "max8998,pmic-buck-voltage-lock", NULL))
622 pdata->buck_voltage_lock = true;
624 ret = of_property_read_u32(pmic_np,
625 "max8998,pmic-buck1-default-dvs-idx",
626 &pdata->buck1_default_idx);
627 if (!ret && pdata->buck1_default_idx >= 4) {
628 pdata->buck1_default_idx = 0;
629 dev_warn(iodev->dev, "invalid value for default dvs index, using 0 instead\n");
632 ret = of_property_read_u32(pmic_np,
633 "max8998,pmic-buck2-default-dvs-idx",
634 &pdata->buck2_default_idx);
635 if (!ret && pdata->buck2_default_idx >= 2) {
636 pdata->buck2_default_idx = 0;
637 dev_warn(iodev->dev, "invalid value for default dvs index, using 0 instead\n");
640 ret = of_property_read_u32_array(pmic_np,
641 "max8998,pmic-buck1-dvs-voltage",
642 pdata->buck1_voltage,
643 ARRAY_SIZE(pdata->buck1_voltage));
645 dev_err(iodev->dev, "buck1 voltages not specified\n");
649 ret = of_property_read_u32_array(pmic_np,
650 "max8998,pmic-buck2-dvs-voltage",
651 pdata->buck2_voltage,
652 ARRAY_SIZE(pdata->buck2_voltage));
654 dev_err(iodev->dev, "buck2 voltages not specified\n");
661 static int max8998_pmic_probe(struct platform_device *pdev)
663 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
664 struct max8998_platform_data *pdata = iodev->pdata;
665 struct regulator_config config = { };
666 struct regulator_dev *rdev;
667 struct max8998_data *max8998;
668 struct i2c_client *i2c;
673 dev_err(pdev->dev.parent, "No platform init data supplied\n");
677 if (IS_ENABLED(CONFIG_OF) && iodev->dev->of_node) {
678 ret = max8998_pmic_dt_parse_pdata(iodev, pdata);
683 max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_data),
688 max8998->dev = &pdev->dev;
689 max8998->iodev = iodev;
690 max8998->num_regulators = pdata->num_regulators;
691 platform_set_drvdata(pdev, max8998);
692 i2c = max8998->iodev->i2c;
694 max8998->buck1_idx = pdata->buck1_default_idx;
695 max8998->buck2_idx = pdata->buck2_default_idx;
698 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */
699 /* will be displayed */
701 /* Check if MAX8998 voltage selection GPIOs are defined */
702 if (gpio_is_valid(pdata->buck1_set1) &&
703 gpio_is_valid(pdata->buck1_set2)) {
704 /* Check if SET1 is not equal to 0 */
705 if (!pdata->buck1_set1) {
707 "MAX8998 SET1 GPIO defined as 0 !\n");
708 WARN_ON(!pdata->buck1_set1);
711 /* Check if SET2 is not equal to 0 */
712 if (!pdata->buck1_set2) {
714 "MAX8998 SET2 GPIO defined as 0 !\n");
715 WARN_ON(!pdata->buck1_set2);
719 gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1");
720 gpio_direction_output(pdata->buck1_set1,
721 max8998->buck1_idx & 0x1);
724 gpio_request(pdata->buck1_set2, "MAX8998 BUCK1_SET2");
725 gpio_direction_output(pdata->buck1_set2,
726 (max8998->buck1_idx >> 1) & 0x1);
728 /* Set predefined values for BUCK1 registers */
729 for (v = 0; v < ARRAY_SIZE(pdata->buck1_voltage); ++v) {
730 int index = MAX8998_BUCK1 - MAX8998_LDO2;
733 while (regulators[index].min_uV +
734 regulators[index].uV_step * i
735 < pdata->buck1_voltage[v])
738 max8998->buck1_vol[v] = i;
739 ret = max8998_write_reg(i2c,
740 MAX8998_REG_BUCK1_VOLTAGE1 + v, i);
746 if (gpio_is_valid(pdata->buck2_set3)) {
747 /* Check if SET3 is not equal to 0 */
748 if (!pdata->buck2_set3) {
750 "MAX8998 SET3 GPIO defined as 0 !\n");
751 WARN_ON(!pdata->buck2_set3);
754 gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3");
755 gpio_direction_output(pdata->buck2_set3,
756 max8998->buck2_idx & 0x1);
758 /* Set predefined values for BUCK2 registers */
759 for (v = 0; v < ARRAY_SIZE(pdata->buck2_voltage); ++v) {
760 int index = MAX8998_BUCK2 - MAX8998_LDO2;
763 while (regulators[index].min_uV +
764 regulators[index].uV_step * i
765 < pdata->buck2_voltage[v])
768 max8998->buck2_vol[v] = i;
769 ret = max8998_write_reg(i2c,
770 MAX8998_REG_BUCK2_VOLTAGE1 + v, i);
776 for (i = 0; i < pdata->num_regulators; i++) {
777 int index = pdata->regulators[i].id - MAX8998_LDO2;
779 config.dev = max8998->dev;
780 config.of_node = pdata->regulators[i].reg_node;
781 config.init_data = pdata->regulators[i].initdata;
782 config.driver_data = max8998;
784 rdev = devm_regulator_register(&pdev->dev, ®ulators[index],
788 dev_err(max8998->dev, "regulator %s init failed (%d)\n",
789 regulators[index].name, ret);
797 static const struct platform_device_id max8998_pmic_id[] = {
798 { "max8998-pmic", TYPE_MAX8998 },
799 { "lp3974-pmic", TYPE_LP3974 },
802 MODULE_DEVICE_TABLE(platform, max8998_pmic_id);
804 static struct platform_driver max8998_pmic_driver = {
806 .name = "max8998-pmic",
808 .probe = max8998_pmic_probe,
809 .id_table = max8998_pmic_id,
812 static int __init max8998_pmic_init(void)
814 return platform_driver_register(&max8998_pmic_driver);
816 subsys_initcall(max8998_pmic_init);
818 static void __exit max8998_pmic_cleanup(void)
820 platform_driver_unregister(&max8998_pmic_driver);
822 module_exit(max8998_pmic_cleanup);
824 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
825 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
826 MODULE_LICENSE("GPL");