From: Adam Ward <Adam.Ward.opensource@diasemi.com>
To: Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Vincent Whitchurch <vincent.whitchurch@axis.com>,
<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
Support Opensource <support.opensource@diasemi.com>
Subject: [PATCH V4 07/10] regulator: da9121: Update registration to support multiple buck variants
Date: Tue, 1 Dec 2020 13:52:33 +0000 [thread overview]
Message-ID: <1fd53c3ab032ef3c8a92f80a2247381db1c09ced.1606830377.git.Adam.Ward.opensource@diasemi.com> (raw)
In-Reply-To: <cover.1606830377.git.Adam.Ward.opensource@diasemi.com>
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>
---
drivers/regulator/da9121-regulator.c | 44 +++++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 13 deletions(-)
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 int da9121_of_parse_cb(struct device_node *np,
[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;
--
1.9.1
next prev parent reply other threads:[~2020-12-01 13:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-01 13:52 [PATCH V4 00/10] regulator: da9121: extend support to variants, add features Adam Ward
2020-12-01 13:52 ` [PATCH V4 01/10] regulator: Update DA9121 dt-bindings Adam Ward
2020-12-07 17:58 ` Rob Herring
2020-12-08 10:41 ` Adam Ward
2020-12-01 13:52 ` [PATCH V4 02/10] regulator: da9121: Add header file Adam Ward
2020-12-01 13:52 ` [PATCH V4 03/10] regulator: da9121: Add device variants Adam Ward
2020-12-01 13:52 ` [PATCH V4 04/10] regulator: da9121: Add device variant regmaps Adam Ward
2020-12-01 13:52 ` [PATCH V4 05/10] regulator: da9121: Add device variant descriptors Adam Ward
2020-12-01 13:52 ` [PATCH V4 06/10] regulator: da9121: Add support for device variants via devicetree Adam Ward
2020-12-01 13:52 ` Adam Ward [this message]
2020-12-01 13:52 ` [PATCH V4 08/10] regulator: da9121: add current support Adam Ward
2020-12-01 13:52 ` [PATCH V4 09/10] regulator: da9121: add mode support Adam Ward
2020-12-01 13:52 ` [PATCH V4 10/10] regulator: da9121: add interrupt support Adam Ward
2020-12-01 14:01 ` [PATCH V4 00/10] regulator: da9121: extend support to variants, add features Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1fd53c3ab032ef3c8a92f80a2247381db1c09ced.1606830377.git.Adam.Ward.opensource@diasemi.com \
--to=adam.ward.opensource@diasemi.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=support.opensource@diasemi.com \
--cc=vincent.whitchurch@axis.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).