Lines Matching +full:dvs +full:- +full:gpio

1 // SPDX-License-Identifier: GPL-2.0+
3 // max8997.c - Regulator driver for the Maxim 8997/8966
13 #include <linux/gpio/consumer.h>
20 #include <linux/mfd/max8997-private.h>
51 int set3 = (max8997->buck125_gpioindex) & 0x1; in max8997_set_gpio()
52 int set2 = ((max8997->buck125_gpioindex) >> 1) & 0x1; in max8997_set_gpio()
53 int set1 = ((max8997->buck125_gpioindex) >> 2) & 0x1; in max8997_set_gpio()
55 gpiod_set_value(max8997->buck125_gpiods[0], set1); in max8997_set_gpio()
56 gpiod_set_value(max8997->buck125_gpiods[1], set2); in max8997_set_gpio()
57 gpiod_set_value(max8997->buck125_gpiods[2], set3); in max8997_set_gpio()
137 return 4000000 + 20000 * (selector - 0x01); in max8997_list_voltage_charger_cv()
141 return -EINVAL; in max8997_list_voltage_charger_cv()
144 return -EINVAL; in max8997_list_voltage_charger_cv()
155 return -EINVAL; in max8997_list_voltage()
159 return -EINVAL; in max8997_list_voltage()
161 val = desc->min + desc->step * selector; in max8997_list_voltage()
162 if (val > desc->max) in max8997_list_voltage()
163 return -EINVAL; in max8997_list_voltage()
175 *reg = MAX8997_REG_LDO1CTRL + (rid - MAX8997_LDO1); in max8997_get_enable_register()
216 *mask = 0x01 << (rid - MAX8997_EN32KHZ_AP); in max8997_get_enable_register()
217 *pattern = 0x01 << (rid - MAX8997_EN32KHZ_AP); in max8997_get_enable_register()
226 *mask = 0x40 << (rid - MAX8997_ESAFEOUT1); in max8997_get_enable_register()
227 *pattern = 0x40 << (rid - MAX8997_ESAFEOUT1); in max8997_get_enable_register()
236 return -EINVAL; in max8997_get_enable_register()
245 struct i2c_client *i2c = max8997->iodev->i2c; in max8997_reg_is_enabled()
263 struct i2c_client *i2c = max8997->iodev->i2c; in max8997_reg_enable()
276 struct i2c_client *i2c = max8997->iodev->i2c; in max8997_reg_disable()
295 reg = MAX8997_REG_LDO1CTRL + (rid - MAX8997_LDO1); in max8997_get_voltage_register()
299 if (max8997->buck1_gpiodvs) in max8997_get_voltage_register()
300 reg += max8997->buck125_gpioindex; in max8997_get_voltage_register()
304 if (max8997->buck2_gpiodvs) in max8997_get_voltage_register()
305 reg += max8997->buck125_gpioindex; in max8997_get_voltage_register()
315 if (max8997->buck5_gpiodvs) in max8997_get_voltage_register()
316 reg += max8997->buck125_gpioindex; in max8997_get_voltage_register()
342 return -EINVAL; in max8997_get_voltage_register()
355 struct i2c_client *i2c = max8997->iodev->i2c; in max8997_get_voltage_sel()
380 return -EINVAL; in max8997_get_voltage_proper_val()
382 if (max_vol < desc->min || min_vol > desc->max) in max8997_get_voltage_proper_val()
383 return -EINVAL; in max8997_get_voltage_proper_val()
385 if (min_vol < desc->min) in max8997_get_voltage_proper_val()
386 min_vol = desc->min; in max8997_get_voltage_proper_val()
388 i = DIV_ROUND_UP(min_vol - desc->min, desc->step); in max8997_get_voltage_proper_val()
390 if (desc->min + desc->step * i > max_vol) in max8997_get_voltage_proper_val()
391 return -EINVAL; in max8997_get_voltage_proper_val()
400 struct i2c_client *i2c = max8997->iodev->i2c; in max8997_set_voltage_charger_cv()
407 return -EINVAL; in max8997_set_voltage_charger_cv()
414 return -EINVAL; in max8997_set_voltage_charger_cv()
421 lb = (min_uV - 4000001) / 20000 + 2; in max8997_set_voltage_charger_cv()
422 ub = (max_uV - 4000000) / 20000 + 1; in max8997_set_voltage_charger_cv()
425 return -EINVAL; in max8997_set_voltage_charger_cv()
433 return -EINVAL; in max8997_set_voltage_charger_cv()
446 * BUCK1, 2, and 5 are available if they are not controlled by gpio
452 struct i2c_client *i2c = max8997->iodev->i2c; in max8997_set_voltage_ldobuck()
463 return -EINVAL; in max8997_set_voltage_ldobuck()
471 return -EINVAL; in max8997_set_voltage_ldobuck()
505 if (max8997->buck1_gpiodvs) in max8997_set_voltage_buck_time_sel()
509 if (max8997->buck2_gpiodvs) in max8997_set_voltage_buck_time_sel()
513 if (max8997->buck5_gpiodvs) in max8997_set_voltage_buck_time_sel()
523 return DIV_ROUND_UP(desc->step * (new_selector - old_selector), in max8997_set_voltage_buck_time_sel()
524 max8997->ramp_delay * 1000); in max8997_set_voltage_buck_time_sel()
533 * When GPIO-DVS mode is used for multiple bucks, changing the voltage value
535 * effect of the change (set_voltage). This function examines the GPIO-DVS
536 * configurations and checks whether such side-effect exists.
549 *best = -1; in max8997_assess_side_effect()
562 return -EINVAL; in max8997_assess_side_effect()
565 buckx_val[0] = max8997->buck1_vol; in max8997_assess_side_effect()
566 buckx_val[1] = max8997->buck2_vol; in max8997_assess_side_effect()
567 buckx_val[2] = max8997->buck5_vol; in max8997_assess_side_effect()
568 buckx_gpiodvs[0] = max8997->buck1_gpiodvs; in max8997_assess_side_effect()
569 buckx_gpiodvs[1] = max8997->buck2_gpiodvs; in max8997_assess_side_effect()
570 buckx_gpiodvs[2] = max8997->buck5_gpiodvs; in max8997_assess_side_effect()
576 side_effect[i] = -1; in max8997_assess_side_effect()
588 diff = (buckx_val[others])[i] - in max8997_assess_side_effect()
589 (buckx_val[others])[max8997->buck125_gpioindex]; in max8997_assess_side_effect()
593 side_effect[i] -= diff; in max8997_assess_side_effect()
605 if (*best == -1) in max8997_assess_side_effect()
606 return -EINVAL; in max8997_assess_side_effect()
612 * For Buck 1 ~ 5 and 7. If it is not controlled by GPIO, this calls
625 return -EINVAL; in max8997_set_voltage_buck()
629 if (max8997->buck1_gpiodvs) in max8997_set_voltage_buck()
633 if (max8997->buck2_gpiodvs) in max8997_set_voltage_buck()
637 if (max8997->buck5_gpiodvs) in max8997_set_voltage_buck()
652 tmp_idx = -1; in max8997_set_voltage_buck()
653 tmp_val = -1; in max8997_set_voltage_buck()
666 } while (desc->min + desc->step * new_val <= desc->max); in max8997_set_voltage_buck()
671 if (max8997->ignore_gpiodvs_side_effect == false) in max8997_set_voltage_buck()
672 return -EINVAL; in max8997_set_voltage_buck()
674 dev_warn(&rdev->dev, in max8997_set_voltage_buck()
675 "MAX8997 GPIO-DVS Side Effect Warning: GPIO SET: %d -> %d\n", in max8997_set_voltage_buck()
676 max8997->buck125_gpioindex, tmp_idx); in max8997_set_voltage_buck()
680 return -EINVAL; in max8997_set_voltage_buck()
682 max8997->buck125_gpioindex = new_idx; in max8997_set_voltage_buck()
694 struct i2c_client *i2c = max8997->iodev->i2c; in max8997_set_voltage_safeout_sel()
699 return -EINVAL; in max8997_set_voltage_safeout_sel()
711 struct i2c_client *i2c = max8997->iodev->i2c; in max8997_reg_disable_suspend()
719 max8997_read_reg(i2c, reg, &max8997->saved_states[rid]); in max8997_reg_disable_suspend()
724 dev_dbg(&rdev->dev, "Conditional Power-Off for %s\n", in max8997_reg_disable_suspend()
725 rdev->desc->name); in max8997_reg_disable_suspend()
729 dev_dbg(&rdev->dev, "Full Power-Off for %s (%xh -> %xh)\n", in max8997_reg_disable_suspend()
730 rdev->desc->name, max8997->saved_states[rid] & mask, in max8997_reg_disable_suspend()
787 return -EINVAL; in max8997_set_current_limit()
798 return -EINVAL; in max8997_get_current_limit()
879 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); in max8997_pmic_dt_parse_pdata()
884 pmic_np = iodev->dev->of_node; in max8997_pmic_dt_parse_pdata()
886 dev_err(&pdev->dev, "could not find pmic sub-node\n"); in max8997_pmic_dt_parse_pdata()
887 return -ENODEV; in max8997_pmic_dt_parse_pdata()
893 dev_err(&pdev->dev, "could not find regulators sub-node\n"); in max8997_pmic_dt_parse_pdata()
894 return -EINVAL; in max8997_pmic_dt_parse_pdata()
898 pdata->num_regulators = of_get_child_count(regulators_np); in max8997_pmic_dt_parse_pdata()
900 rdata = devm_kcalloc(&pdev->dev, in max8997_pmic_dt_parse_pdata()
901 pdata->num_regulators, sizeof(*rdata), in max8997_pmic_dt_parse_pdata()
904 return -ENOMEM; in max8997_pmic_dt_parse_pdata()
906 pdata->regulators = rdata; in max8997_pmic_dt_parse_pdata()
913 dev_warn(&pdev->dev, "don't know how to configure regulator %pOFn\n", in max8997_pmic_dt_parse_pdata()
918 rdata->id = i; in max8997_pmic_dt_parse_pdata()
919 rdata->initdata = of_get_regulator_init_data(&pdev->dev, in max8997_pmic_dt_parse_pdata()
922 rdata->reg_node = reg_np; in max8997_pmic_dt_parse_pdata()
926 pdata->buck1_gpiodvs = of_property_read_bool(pmic_np, "max8997,pmic-buck1-uses-gpio-dvs"); in max8997_pmic_dt_parse_pdata()
927 pdata->buck2_gpiodvs = of_property_read_bool(pmic_np, "max8997,pmic-buck2-uses-gpio-dvs"); in max8997_pmic_dt_parse_pdata()
928 pdata->buck5_gpiodvs = of_property_read_bool(pmic_np, "max8997,pmic-buck5-uses-gpio-dvs"); in max8997_pmic_dt_parse_pdata()
930 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || in max8997_pmic_dt_parse_pdata()
931 pdata->buck5_gpiodvs) { in max8997_pmic_dt_parse_pdata()
933 "max8997,pmic-buck125-default-dvs-idx", in max8997_pmic_dt_parse_pdata()
934 &pdata->buck125_default_idx)) { in max8997_pmic_dt_parse_pdata()
935 pdata->buck125_default_idx = 0; in max8997_pmic_dt_parse_pdata()
937 if (pdata->buck125_default_idx >= 8) { in max8997_pmic_dt_parse_pdata()
938 pdata->buck125_default_idx = 0; in max8997_pmic_dt_parse_pdata()
939 dev_info(&pdev->dev, "invalid value for default dvs index, using 0 instead\n"); in max8997_pmic_dt_parse_pdata()
943 pdata->ignore_gpiodvs_side_effect = of_property_read_bool(pmic_np, in max8997_pmic_dt_parse_pdata()
944 "max8997,pmic-ignore-gpiodvs-side-effect"); in max8997_pmic_dt_parse_pdata()
950 "max8997,pmic-buck1-dvs-voltage", in max8997_pmic_dt_parse_pdata()
951 pdata->buck1_voltage, dvs_voltage_nr)) { in max8997_pmic_dt_parse_pdata()
952 dev_err(&pdev->dev, "buck1 voltages not specified\n"); in max8997_pmic_dt_parse_pdata()
953 return -EINVAL; in max8997_pmic_dt_parse_pdata()
957 "max8997,pmic-buck2-dvs-voltage", in max8997_pmic_dt_parse_pdata()
958 pdata->buck2_voltage, dvs_voltage_nr)) { in max8997_pmic_dt_parse_pdata()
959 dev_err(&pdev->dev, "buck2 voltages not specified\n"); in max8997_pmic_dt_parse_pdata()
960 return -EINVAL; in max8997_pmic_dt_parse_pdata()
964 "max8997,pmic-buck5-dvs-voltage", in max8997_pmic_dt_parse_pdata()
965 pdata->buck5_voltage, dvs_voltage_nr)) { in max8997_pmic_dt_parse_pdata()
966 dev_err(&pdev->dev, "buck5 voltages not specified\n"); in max8997_pmic_dt_parse_pdata()
967 return -EINVAL; in max8997_pmic_dt_parse_pdata()
982 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); in max8997_pmic_probe()
983 struct max8997_platform_data *pdata = iodev->pdata; in max8997_pmic_probe()
992 dev_err(&pdev->dev, "No platform init data supplied.\n"); in max8997_pmic_probe()
993 return -ENODEV; in max8997_pmic_probe()
996 if (iodev->dev->of_node) { in max8997_pmic_probe()
1002 max8997 = devm_kzalloc(&pdev->dev, sizeof(struct max8997_data), in max8997_pmic_probe()
1005 return -ENOMEM; in max8997_pmic_probe()
1007 max8997->dev = &pdev->dev; in max8997_pmic_probe()
1008 max8997->iodev = iodev; in max8997_pmic_probe()
1009 max8997->num_regulators = pdata->num_regulators; in max8997_pmic_probe()
1011 i2c = max8997->iodev->i2c; in max8997_pmic_probe()
1013 max8997->buck125_gpioindex = pdata->buck125_default_idx; in max8997_pmic_probe()
1014 max8997->buck1_gpiodvs = pdata->buck1_gpiodvs; in max8997_pmic_probe()
1015 max8997->buck2_gpiodvs = pdata->buck2_gpiodvs; in max8997_pmic_probe()
1016 max8997->buck5_gpiodvs = pdata->buck5_gpiodvs; in max8997_pmic_probe()
1017 max8997->ignore_gpiodvs_side_effect = pdata->ignore_gpiodvs_side_effect; in max8997_pmic_probe()
1019 nr_dvs = (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || in max8997_pmic_probe()
1020 pdata->buck5_gpiodvs) ? 8 : 1; in max8997_pmic_probe()
1023 max8997->buck1_vol[i] = ret = in max8997_pmic_probe()
1026 pdata->buck1_voltage[i], in max8997_pmic_probe()
1027 pdata->buck1_voltage[i] + in max8997_pmic_probe()
1032 max8997->buck2_vol[i] = ret = in max8997_pmic_probe()
1035 pdata->buck2_voltage[i], in max8997_pmic_probe()
1036 pdata->buck2_voltage[i] + in max8997_pmic_probe()
1041 max8997->buck5_vol[i] = ret = in max8997_pmic_probe()
1044 pdata->buck5_voltage[i], in max8997_pmic_probe()
1045 pdata->buck5_voltage[i] + in max8997_pmic_probe()
1050 if (max_buck1 < max8997->buck1_vol[i]) in max8997_pmic_probe()
1051 max_buck1 = max8997->buck1_vol[i]; in max8997_pmic_probe()
1052 if (max_buck2 < max8997->buck2_vol[i]) in max8997_pmic_probe()
1053 max_buck2 = max8997->buck2_vol[i]; in max8997_pmic_probe()
1054 if (max_buck5 < max8997->buck5_vol[i]) in max8997_pmic_probe()
1055 max_buck5 = max8997->buck5_vol[i]; in max8997_pmic_probe()
1068 /* Initialize all the DVS related BUCK registers */ in max8997_pmic_probe()
1071 max8997->buck1_vol[i], in max8997_pmic_probe()
1074 max8997->buck2_vol[i], in max8997_pmic_probe()
1077 max8997->buck5_vol[i], in max8997_pmic_probe()
1082 * If buck 1, 2, and 5 do not care DVS GPIO settings, ignore them. in max8997_pmic_probe()
1085 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || in max8997_pmic_probe()
1086 pdata->buck5_gpiodvs) { in max8997_pmic_probe()
1092 if (max8997->buck125_gpioindex & BIT(2 - i)) in max8997_pmic_probe()
1097 max8997->buck125_gpiods[i] = devm_gpiod_get_index(iodev->dev, in max8997_pmic_probe()
1098 "max8997,pmic-buck125-dvs", in max8997_pmic_probe()
1101 if (IS_ERR(max8997->buck125_gpiods[i])) { in max8997_pmic_probe()
1102 ret = PTR_ERR(max8997->buck125_gpiods[i]); in max8997_pmic_probe()
1103 return dev_err_probe(iodev->dev, ret, "cant get GPIO %d (%d)\n", in max8997_pmic_probe()
1106 gpiod_set_consumer_name(max8997->buck125_gpiods[i], gpio_names[i]); in max8997_pmic_probe()
1110 /* DVS-GPIO disabled */ in max8997_pmic_probe()
1111 max8997_update_reg(i2c, MAX8997_REG_BUCK1CTRL, (pdata->buck1_gpiodvs) ? in max8997_pmic_probe()
1113 max8997_update_reg(i2c, MAX8997_REG_BUCK2CTRL, (pdata->buck2_gpiodvs) ? in max8997_pmic_probe()
1115 max8997_update_reg(i2c, MAX8997_REG_BUCK5CTRL, (pdata->buck5_gpiodvs) ? in max8997_pmic_probe()
1119 max8997->ramp_delay = 10; /* set 10mV/us, which is the default */ in max8997_pmic_probe()
1122 for (i = 0; i < pdata->num_regulators; i++) { in max8997_pmic_probe()
1124 int id = pdata->regulators[i].id; in max8997_pmic_probe()
1129 (desc->max - desc->min) / desc->step + 1; in max8997_pmic_probe()
1137 config.dev = max8997->dev; in max8997_pmic_probe()
1138 config.init_data = pdata->regulators[i].initdata; in max8997_pmic_probe()
1140 config.of_node = pdata->regulators[i].reg_node; in max8997_pmic_probe()
1142 rdev = devm_regulator_register(&pdev->dev, &regulators[id], in max8997_pmic_probe()
1145 dev_err(max8997->dev, "regulator init failed for %d\n", in max8997_pmic_probe()
1155 { "max8997-pmic", 0},
1162 .name = "max8997-pmic",