Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'regulator-fix-v6.14-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator

Pull regulator fixes from Mark Brown:
"A couple of fixes that have come in during the merge window: one that
operates the TPS6287x devices more within the design spec and can
prevent current surges when changing voltages and another more trivial
one for error message formatting"

* tag 'regulator-fix-v6.14-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator:
regulator: core: Add missing newline character
regulator: TPS6287X: Use min/max uV to get VRANGE

+58 -1
+1 -1
drivers/regulator/core.c
··· 5033 5033 consumers[i].supply, get_type); 5034 5034 if (IS_ERR(consumers[i].consumer)) { 5035 5035 ret = dev_err_probe(dev, PTR_ERR(consumers[i].consumer), 5036 - "Failed to get supply '%s'", 5036 + "Failed to get supply '%s'\n", 5037 5037 consumers[i].supply); 5038 5038 consumers[i].consumer = NULL; 5039 5039 goto err;
+57
drivers/regulator/tps6287x-regulator.c
··· 44 44 0x0, 0x1, 0x2, 0x3 45 45 }; 46 46 47 + static const unsigned int tps6287x_voltage_range_prefix[] = { 48 + 0x000, 0x100, 0x200, 0x300 49 + }; 50 + 47 51 static const unsigned int tps6287x_ramp_table[] = { 48 52 10000, 5000, 1250, 500 49 53 }; 54 + 55 + struct tps6287x_reg_data { 56 + int range; 57 + }; 58 + 59 + static int tps6287x_best_range(struct regulator_config *config, const struct regulator_desc *desc) 60 + { 61 + const struct linear_range *r; 62 + int i; 63 + 64 + if (!config->init_data->constraints.apply_uV) 65 + return -1; 66 + 67 + for (i = 0; i < desc->n_linear_ranges; i++) { 68 + r = &desc->linear_ranges[i]; 69 + if (r->min <= config->init_data->constraints.min_uV && 70 + config->init_data->constraints.max_uV <= linear_range_get_max_value(r)) 71 + return i; 72 + } 73 + return -1; 74 + } 50 75 51 76 static int tps6287x_set_mode(struct regulator_dev *rdev, unsigned int mode) 52 77 { ··· 116 91 } 117 92 } 118 93 94 + static int tps6287x_map_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 95 + { 96 + struct tps6287x_reg_data *data = (struct tps6287x_reg_data *)rdev->reg_data; 97 + struct linear_range selected_range; 98 + int selector, voltage; 99 + 100 + if (!data || data->range == -1) 101 + return regulator_map_voltage_pickable_linear_range(rdev, min_uV, max_uV); 102 + 103 + selected_range = rdev->desc->linear_ranges[data->range]; 104 + selector = DIV_ROUND_UP(min_uV - selected_range.min, selected_range.step); 105 + if (selector < selected_range.min_sel || selector > selected_range.max_sel) 106 + return -EINVAL; 107 + 108 + selector |= tps6287x_voltage_range_prefix[data->range]; 109 + voltage = rdev->desc->ops->list_voltage(rdev, selector); 110 + if (voltage < min_uV || voltage > max_uV) 111 + return -EINVAL; 112 + 113 + return selector; 114 + } 115 + 119 116 static const struct regulator_ops tps6287x_regulator_ops = { 120 117 .enable = regulator_enable_regmap, 121 118 .disable = regulator_disable_regmap, ··· 147 100 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, 148 101 .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap, 149 102 .list_voltage = regulator_list_voltage_pickable_linear_range, 103 + .map_voltage = tps6287x_map_voltage, 150 104 .set_ramp_delay = regulator_set_ramp_delay_regmap, 151 105 }; 152 106 ··· 178 130 { 179 131 struct device *dev = &i2c->dev; 180 132 struct regulator_config config = {}; 133 + struct tps6287x_reg_data *reg_data; 181 134 struct regulator_dev *rdev; 135 + 136 + reg_data = devm_kzalloc(dev, sizeof(struct tps6287x_reg_data), GFP_KERNEL); 137 + 138 + if (!reg_data) 139 + return -ENOMEM; 182 140 183 141 config.regmap = devm_regmap_init_i2c(i2c, &tps6287x_regmap_config); 184 142 if (IS_ERR(config.regmap)) { ··· 197 143 config.init_data = of_get_regulator_init_data(dev, dev->of_node, 198 144 &tps6287x_reg); 199 145 146 + reg_data->range = tps6287x_best_range(&config, &tps6287x_reg); 147 + 200 148 rdev = devm_regulator_register(dev, &tps6287x_reg, &config); 201 149 if (IS_ERR(rdev)) { 202 150 dev_err(dev, "Failed to register regulator\n"); 203 151 return PTR_ERR(rdev); 204 152 } 205 153 154 + rdev->reg_data = (void *)reg_data; 206 155 dev_dbg(dev, "Probed regulator\n"); 207 156 208 157 return 0;