From: Adam Ward Date: Mon, 30 Nov 2020 16:59:11 +0000 (+0000) Subject: regulator: da9121: Update registration to support multiple buck variants X-Git-Tag: accepted/tizen/unified/20230118.172025~8008^2~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9929900d1878565a90a70bf25baa7d3e4187ae99;p=platform%2Fkernel%2Flinux-rpi.git 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 Link: https://lore.kernel.org/r/1fd53c3ab032ef3c8a92f80a2247381db1c09ced.1606755367.git.Adam.Ward.opensource@diasemi.com Signed-off-by: Mark Brown --- diff --git a/drivers/regulator/da9121-regulator.c b/drivers/regulator/da9121-regulator.c index 1f74371..6c82441 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;