summaryrefslogtreecommitdiff
path: root/drivers/regulator
diff options
context:
space:
mode:
authorAdam Ward <Adam.Ward.opensource@diasemi.com>2020-11-30 16:59:11 +0000
committerMark Brown <broonie@kernel.org>2020-12-01 12:18:01 +0000
commit9929900d1878565a90a70bf25baa7d3e4187ae99 (patch)
tree4c466a835644132887b5d8b4a863c7794a543f63 /drivers/regulator
parent46c413d5bb239769e6f1de706adf422c807c7a5f (diff)
regulator: da9121: Update registration to support multiple buck variants
Add function which iterates the regulator descriptors for the confirmed variant ID and registers each buck. Signed-off-by: Adam Ward <Adam.Ward.opensource@diasemi.com> Link: https://lore.kernel.org/r/1fd53c3ab032ef3c8a92f80a2247381db1c09ced.1606755367.git.Adam.Ward.opensource@diasemi.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/da9121-regulator.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/drivers/regulator/da9121-regulator.c b/drivers/regulator/da9121-regulator.c
index 1f74371eebad..6c82441dda57 100644
--- a/drivers/regulator/da9121-regulator.c
+++ b/drivers/regulator/da9121-regulator.c
@@ -31,6 +31,7 @@ struct da9121 {
struct device *dev;
struct da9121_pdata *pdata;
struct regmap *regmap;
+ struct regulator_dev *rdev[DA9121_IDX_MAX];
int variant_id;
};
@@ -291,6 +292,35 @@ static const struct regulator_desc *local_da9121_regulators[][DA9121_IDX_MAX] =
[DA9121_TYPE_DA9217] = { &da9217_reg, NULL },
};
+static int da9121_set_regulator_config(struct da9121 *chip)
+{
+ struct regulator_config config = { };
+ unsigned int max_matches = variant_parameters[chip->variant_id].num_bucks;
+ int ret = 0;
+ int i;
+
+ for (i = 0; i < max_matches; i++) {
+ const struct regulator_desc *regl_desc =
+ local_da9121_regulators[chip->variant_id][i];
+
+ config.dev = chip->dev;
+ config.driver_data = chip;
+ config.regmap = chip->regmap;
+
+ chip->rdev[i] = devm_regulator_register(chip->dev,
+ regl_desc, &config);
+ if (IS_ERR(chip->rdev[i])) {
+ dev_err(chip->dev, "Failed to register regulator %s, %d/%d\n",
+ regl_desc->name, (i+1), max_matches);
+ ret = PTR_ERR(chip->rdev[i]);
+ goto error;
+ }
+ }
+
+error:
+ return ret;
+}
+
/* DA9121 chip register model */
static const struct regmap_range da9121_1ch_readable_ranges[] = {
regmap_reg_range(DA9121_REG_SYS_STATUS_0, DA9121_REG_SYS_MASK_3),
@@ -522,9 +552,6 @@ static int da9121_i2c_probe(struct i2c_client *i2c,
{
struct da9121 *chip;
int ret = 0;
- struct device *dev = &i2c->dev;
- struct regulator_config config = {};
- struct regulator_dev *rdev;
chip = devm_kzalloc(&i2c->dev, sizeof(struct da9121), GFP_KERNEL);
if (!chip) {
@@ -539,16 +566,7 @@ static int da9121_i2c_probe(struct i2c_client *i2c,
if (ret < 0)
goto error;
- config.dev = &i2c->dev;
- config.driver_data = chip;
- config.of_node = dev->of_node;
- config.regmap = chip->regmap;
-
- rdev = devm_regulator_register(&i2c->dev, &da9121_reg, &config);
- if (IS_ERR(rdev)) {
- dev_err(&i2c->dev, "Failed to register da9121 regulator\n");
- return PTR_ERR(rdev);
- }
+ ret = da9121_set_regulator_config(chip);
error:
return ret;