Lines Matching +full:pmic +full:- +full:buck2 +full:- +full:default +full:- +full:dvs +full:- +full:idx

1 // SPDX-License-Identifier: GPL-2.0+
3 // max8998.c - Voltage regulator driver for the Maxim 8998
5 // Copyright (C) 2009-2010 Samsung Electronics
23 #include <linux/mfd/max8998-private.h>
51 *shift = 3 - (ldo - MAX8998_LDO2); in max8998_get_enable_register()
55 *shift = 7 - (ldo - MAX8998_LDO6); in max8998_get_enable_register()
59 *shift = 7 - (ldo - MAX8998_LDO14); in max8998_get_enable_register()
63 *shift = 7 - (ldo - MAX8998_BUCK1); in max8998_get_enable_register()
67 *shift = 7 - (ldo - MAX8998_EN32KHZ_AP); in max8998_get_enable_register()
71 *shift = 7 - (ldo - MAX8998_ESAFEOUT1); in max8998_get_enable_register()
77 default: in max8998_get_enable_register()
78 return -EINVAL; in max8998_get_enable_register()
87 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_ldo_is_enabled()
110 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_ldo_enable()
123 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_ldo_disable()
150 reg = MAX8998_REG_LDO4 + (ldo - MAX8998_LDO4); in max8998_get_voltage_register()
171 reg = MAX8998_REG_LDO12 + (ldo - MAX8998_LDO12); in max8998_get_voltage_register()
174 reg = MAX8998_REG_BUCK1_VOLTAGE1 + max8998->buck1_idx; in max8998_get_voltage_register()
177 reg = MAX8998_REG_BUCK2_VOLTAGE1 + max8998->buck2_idx; in max8998_get_voltage_register()
185 default: in max8998_get_voltage_register()
186 return -EINVAL; in max8998_get_voltage_register()
199 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_get_voltage_sel()
221 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_set_voltage_ldo_sel()
248 struct max8998_platform_data *pdata = max8998->iodev->pdata; in max8998_set_voltage_buck_sel()
249 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_set_voltage_buck_sel()
260 dev_dbg(max8998->dev, in max8998_set_voltage_buck_sel()
263 selector, max8998->buck1_vol[0], max8998->buck1_vol[1], in max8998_set_voltage_buck_sel()
264 max8998->buck1_vol[2], max8998->buck1_vol[3]); in max8998_set_voltage_buck_sel()
266 if (max8998->buck1_gpio1 && max8998->buck1_gpio2) { in max8998_set_voltage_buck_sel()
270 for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) { in max8998_set_voltage_buck_sel()
271 if (max8998->buck1_vol[j] == selector) { in max8998_set_voltage_buck_sel()
272 max8998->buck1_idx = j; in max8998_set_voltage_buck_sel()
273 buck1_gpio_set(max8998->buck1_gpio1, in max8998_set_voltage_buck_sel()
274 max8998->buck1_gpio2, j); in max8998_set_voltage_buck_sel()
279 if (pdata->buck_voltage_lock) in max8998_set_voltage_buck_sel()
280 return -EINVAL; in max8998_set_voltage_buck_sel()
283 max8998->buck1_idx = (buck1_last_val % 2) + 2; in max8998_set_voltage_buck_sel()
284 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n", in max8998_set_voltage_buck_sel()
285 max8998->buck1_idx); in max8998_set_voltage_buck_sel()
286 max8998->buck1_vol[max8998->buck1_idx] = selector; in max8998_set_voltage_buck_sel()
291 buck1_gpio_set(max8998->buck1_gpio1, in max8998_set_voltage_buck_sel()
292 max8998->buck1_gpio2, max8998->buck1_idx); in max8998_set_voltage_buck_sel()
295 dev_dbg(max8998->dev, "%s: SET1:%d, SET2:%d\n", in max8998_set_voltage_buck_sel()
296 i2c->name, gpiod_get_value(max8998->buck1_gpio1), in max8998_set_voltage_buck_sel()
297 gpiod_get_value(max8998->buck1_gpio2)); in max8998_set_voltage_buck_sel()
305 dev_dbg(max8998->dev, in max8998_set_voltage_buck_sel()
306 "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n", in max8998_set_voltage_buck_sel()
307 selector, max8998->buck2_vol[0], max8998->buck2_vol[1]); in max8998_set_voltage_buck_sel()
308 if (max8998->buck2_gpio) { in max8998_set_voltage_buck_sel()
311 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) { in max8998_set_voltage_buck_sel()
312 if (max8998->buck2_vol[j] == selector) { in max8998_set_voltage_buck_sel()
313 max8998->buck2_idx = j; in max8998_set_voltage_buck_sel()
314 buck2_gpio_set(max8998->buck2_gpio, j); in max8998_set_voltage_buck_sel()
319 if (pdata->buck_voltage_lock) in max8998_set_voltage_buck_sel()
320 return -EINVAL; in max8998_set_voltage_buck_sel()
325 max8998->buck2_vol[max8998->buck2_idx] = selector; in max8998_set_voltage_buck_sel()
326 buck2_gpio_set(max8998->buck2_gpio, max8998->buck2_idx); in max8998_set_voltage_buck_sel()
328 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, in max8998_set_voltage_buck_sel()
329 gpiod_get_value(max8998->buck2_gpio)); in max8998_set_voltage_buck_sel()
350 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_set_voltage_buck_time_sel()
356 return -EINVAL; in max8998_set_voltage_buck_time_sel()
363 /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */ in max8998_set_voltage_buck_time_sel()
365 if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP)) in max8998_set_voltage_buck_time_sel()
368 difference = (new_selector - old_selector) * rdev->desc->uV_step / 1000; in max8998_set_voltage_buck_time_sel()
379 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_set_current_limit()
380 unsigned int n_currents = rdev->desc->n_current_limits; in max8998_set_current_limit()
381 int i, sel = -1; in max8998_set_current_limit()
384 return -EINVAL; in max8998_set_current_limit()
386 if (rdev->desc->curr_table) { in max8998_set_current_limit()
387 const unsigned int *curr_table = rdev->desc->curr_table; in max8998_set_current_limit()
388 bool ascend = curr_table[n_currents - 1] > curr_table[0]; in max8998_set_current_limit()
392 for (i = n_currents - 1; i >= 0; i--) { in max8998_set_current_limit()
411 return -EINVAL; in max8998_set_current_limit()
413 sel <<= ffs(rdev->desc->csel_mask) - 1; in max8998_set_current_limit()
415 return max8998_update_reg(i2c, rdev->desc->csel_reg, in max8998_set_current_limit()
416 sel, rdev->desc->csel_mask); in max8998_set_current_limit()
422 struct i2c_client *i2c = max8998->iodev->i2c; in max8998_get_current_limit()
426 ret = max8998_read_reg(i2c, rdev->desc->csel_reg, &val); in max8998_get_current_limit()
430 val &= rdev->desc->csel_mask; in max8998_get_current_limit()
431 val >>= ffs(rdev->desc->csel_mask) - 1; in max8998_get_current_limit()
433 if (rdev->desc->curr_table) { in max8998_get_current_limit()
434 if (val >= rdev->desc->n_current_limits) in max8998_get_current_limit()
435 return -EINVAL; in max8998_get_current_limit()
437 return rdev->desc->curr_table[val]; in max8998_get_current_limit()
440 return -EINVAL; in max8998_get_current_limit()
486 .n_voltages = ((_max) - (_min)) / (_step) + 1, \
531 MAX8998_LINEAR_REG(BUCK2, &max8998_buck_ops, 750000, 25000, 1525000),
534 MAX8998_OTHERS_REG(EN32KHz-AP, MAX8998_EN32KHZ_AP),
535 MAX8998_OTHERS_REG(EN32KHz-CP, MAX8998_EN32KHZ_CP),
546 struct device_node *pmic_np = iodev->dev->of_node; in max8998_pmic_dt_parse_pdata()
554 dev_err(iodev->dev, "could not find regulators sub-node\n"); in max8998_pmic_dt_parse_pdata()
555 return -EINVAL; in max8998_pmic_dt_parse_pdata()
558 /* count the number of regulators to be supported in pmic */ in max8998_pmic_dt_parse_pdata()
559 pdata->num_regulators = of_get_child_count(regulators_np); in max8998_pmic_dt_parse_pdata()
561 rdata = devm_kcalloc(iodev->dev, in max8998_pmic_dt_parse_pdata()
562 pdata->num_regulators, sizeof(*rdata), in max8998_pmic_dt_parse_pdata()
566 return -ENOMEM; in max8998_pmic_dt_parse_pdata()
569 pdata->regulators = rdata; in max8998_pmic_dt_parse_pdata()
576 rdata->id = regulators[i].id; in max8998_pmic_dt_parse_pdata()
577 rdata->initdata = of_get_regulator_init_data(iodev->dev, in max8998_pmic_dt_parse_pdata()
580 rdata->reg_node = reg_np; in max8998_pmic_dt_parse_pdata()
583 pdata->num_regulators = rdata - pdata->regulators; in max8998_pmic_dt_parse_pdata()
588 pdata->buck_voltage_lock = of_property_read_bool(pmic_np, "max8998,pmic-buck-voltage-lock"); in max8998_pmic_dt_parse_pdata()
591 "max8998,pmic-buck1-default-dvs-idx", in max8998_pmic_dt_parse_pdata()
592 &pdata->buck1_default_idx); in max8998_pmic_dt_parse_pdata()
593 if (!ret && pdata->buck1_default_idx >= 4) { in max8998_pmic_dt_parse_pdata()
594 pdata->buck1_default_idx = 0; in max8998_pmic_dt_parse_pdata()
595 dev_warn(iodev->dev, "invalid value for default dvs index, using 0 instead\n"); in max8998_pmic_dt_parse_pdata()
599 "max8998,pmic-buck2-default-dvs-idx", in max8998_pmic_dt_parse_pdata()
600 &pdata->buck2_default_idx); in max8998_pmic_dt_parse_pdata()
601 if (!ret && pdata->buck2_default_idx >= 2) { in max8998_pmic_dt_parse_pdata()
602 pdata->buck2_default_idx = 0; in max8998_pmic_dt_parse_pdata()
603 dev_warn(iodev->dev, "invalid value for default dvs index, using 0 instead\n"); in max8998_pmic_dt_parse_pdata()
607 "max8998,pmic-buck1-dvs-voltage", in max8998_pmic_dt_parse_pdata()
608 pdata->buck1_voltage, in max8998_pmic_dt_parse_pdata()
609 ARRAY_SIZE(pdata->buck1_voltage)); in max8998_pmic_dt_parse_pdata()
611 dev_err(iodev->dev, "buck1 voltages not specified\n"); in max8998_pmic_dt_parse_pdata()
612 return -EINVAL; in max8998_pmic_dt_parse_pdata()
616 "max8998,pmic-buck2-dvs-voltage", in max8998_pmic_dt_parse_pdata()
617 pdata->buck2_voltage, in max8998_pmic_dt_parse_pdata()
618 ARRAY_SIZE(pdata->buck2_voltage)); in max8998_pmic_dt_parse_pdata()
620 dev_err(iodev->dev, "buck2 voltages not specified\n"); in max8998_pmic_dt_parse_pdata()
621 return -EINVAL; in max8998_pmic_dt_parse_pdata()
629 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); in max8998_pmic_probe()
630 struct max8998_platform_data *pdata = iodev->pdata; in max8998_pmic_probe()
640 dev_err(pdev->dev.parent, "No platform init data supplied\n"); in max8998_pmic_probe()
641 return -ENODEV; in max8998_pmic_probe()
644 if (IS_ENABLED(CONFIG_OF) && iodev->dev->of_node) { in max8998_pmic_probe()
650 max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_data), in max8998_pmic_probe()
653 return -ENOMEM; in max8998_pmic_probe()
655 max8998->dev = &pdev->dev; in max8998_pmic_probe()
656 max8998->iodev = iodev; in max8998_pmic_probe()
657 max8998->num_regulators = pdata->num_regulators; in max8998_pmic_probe()
659 i2c = max8998->iodev->i2c; in max8998_pmic_probe()
661 max8998->buck1_idx = pdata->buck1_default_idx; in max8998_pmic_probe()
662 max8998->buck2_idx = pdata->buck2_default_idx; in max8998_pmic_probe()
665 flags = (max8998->buck1_idx & BIT(0)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; in max8998_pmic_probe()
666 max8998->buck1_gpio1 = devm_gpiod_get_index_optional(iodev->dev, in max8998_pmic_probe()
667 "max8998,pmic-buck1-dvs", in max8998_pmic_probe()
670 if (IS_ERR(max8998->buck1_gpio1)) in max8998_pmic_probe()
671 return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck1_gpio1), in max8998_pmic_probe()
673 gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK1_SET1"); in max8998_pmic_probe()
675 flags = (max8998->buck1_idx & BIT(1)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; in max8998_pmic_probe()
676 max8998->buck1_gpio2 = devm_gpiod_get_index_optional(iodev->dev, in max8998_pmic_probe()
677 "max8998,pmic-buck1-dvs", in max8998_pmic_probe()
680 if (IS_ERR(max8998->buck1_gpio2)) in max8998_pmic_probe()
681 return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck1_gpio2), in max8998_pmic_probe()
683 gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK1_SET2"); in max8998_pmic_probe()
685 flags = (max8998->buck2_idx & BIT(0)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; in max8998_pmic_probe()
686 max8998->buck2_gpio = devm_gpiod_get_index_optional(iodev->dev, in max8998_pmic_probe()
687 "max8998,pmic-buck2-dvs", in max8998_pmic_probe()
690 if (IS_ERR(max8998->buck2_gpio)) in max8998_pmic_probe()
691 return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck2_gpio), in max8998_pmic_probe()
692 "could not get BUCK2 GPIO\n"); in max8998_pmic_probe()
693 gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK2_SET3"); in max8998_pmic_probe()
695 if (max8998->buck1_gpio1 && max8998->buck1_gpio2) { in max8998_pmic_probe()
697 for (v = 0; v < ARRAY_SIZE(pdata->buck1_voltage); ++v) { in max8998_pmic_probe()
698 int index = MAX8998_BUCK1 - MAX8998_LDO2; in max8998_pmic_probe()
703 < pdata->buck1_voltage[v]) in max8998_pmic_probe()
706 max8998->buck1_vol[v] = i; in max8998_pmic_probe()
714 if (max8998->buck2_gpio) { in max8998_pmic_probe()
715 /* Set predefined values for BUCK2 registers */ in max8998_pmic_probe()
716 for (v = 0; v < ARRAY_SIZE(pdata->buck2_voltage); ++v) { in max8998_pmic_probe()
717 int index = MAX8998_BUCK2 - MAX8998_LDO2; in max8998_pmic_probe()
722 < pdata->buck2_voltage[v]) in max8998_pmic_probe()
725 max8998->buck2_vol[v] = i; in max8998_pmic_probe()
733 for (i = 0; i < pdata->num_regulators; i++) { in max8998_pmic_probe()
734 int index = pdata->regulators[i].id - MAX8998_LDO2; in max8998_pmic_probe()
736 config.dev = max8998->dev; in max8998_pmic_probe()
737 config.of_node = pdata->regulators[i].reg_node; in max8998_pmic_probe()
738 config.init_data = pdata->regulators[i].initdata; in max8998_pmic_probe()
741 rdev = devm_regulator_register(&pdev->dev, &regulators[index], in max8998_pmic_probe()
745 dev_err(max8998->dev, "regulator %s init failed (%d)\n", in max8998_pmic_probe()
755 { "max8998-pmic", TYPE_MAX8998 },
756 { "lp3974-pmic", TYPE_LP3974 },
763 .name = "max8998-pmic",