diff options
author | Adam Ward <Adam.Ward.opensource@diasemi.com> | 2020-11-30 16:59:07 +0000 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2020-12-01 12:17:57 +0000 |
commit | f3fbd5566f6a8cdb7c48ab29bd1096205b7fbcaf (patch) | |
tree | 6de74d96e83b7e724c64b2ed42d1382ad23bfaee /drivers/regulator/da9121-regulator.c | |
parent | 86f162c91f274e0d8a0c440d7a991230f6ac7725 (diff) |
regulator: da9121: Add device variants
Add basic support for configuration to reference variants of this device,
and track the selected variant within the driver.
Signed-off-by: Adam Ward <Adam.Ward.opensource@diasemi.com>
Link: https://lore.kernel.org/r/aaabd3063593e5172fa6b605884d475df64e6d65.1606755367.git.Adam.Ward.opensource@diasemi.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator/da9121-regulator.c')
-rw-r--r-- | drivers/regulator/da9121-regulator.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/drivers/regulator/da9121-regulator.c b/drivers/regulator/da9121-regulator.c index c11fe046345f..5bebdb2a480d 100644 --- a/drivers/regulator/da9121-regulator.c +++ b/drivers/regulator/da9121-regulator.c @@ -11,6 +11,12 @@ #include <linux/i2c.h> #include "da9121-regulator.h" +/* Chip data */ +struct da9121 { + struct device *dev; + int variant_id; +}; + #define DA9121_MIN_MV 300 #define DA9121_MAX_MV 1900 #define DA9121_STEP_MV 10 @@ -53,19 +59,46 @@ static const struct regulator_desc da9121_reg = { }; static const struct of_device_id da9121_dt_ids[] = { - { .compatible = "dlg,da9121", }, + { .compatible = "dlg,da9121", .data = (void *) DA9121_TYPE_DA9121_DA9130 }, + { .compatible = "dlg,da9130", .data = (void *) DA9121_TYPE_DA9121_DA9130 }, + { .compatible = "dlg,da9217", .data = (void *) DA9121_TYPE_DA9217 }, + { .compatible = "dlg,da9122", .data = (void *) DA9121_TYPE_DA9122_DA9131 }, + { .compatible = "dlg,da9131", .data = (void *) DA9121_TYPE_DA9122_DA9131 }, + { .compatible = "dlg,da9220", .data = (void *) DA9121_TYPE_DA9220_DA9132 }, + { .compatible = "dlg,da9132", .data = (void *) DA9121_TYPE_DA9220_DA9132 }, { } }; MODULE_DEVICE_TABLE(of, da9121_dt_ids); +static inline int da9121_of_get_id(struct device *dev) +{ + const struct of_device_id *id = of_match_device(da9121_dt_ids, dev); + + if (!id) { + dev_err(dev, "%s: Failed\n", __func__); + return -EINVAL; + } + return (uintptr_t)id->data; +} + static int da9121_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { + struct da9121 *chip; + int ret = 0; struct device *dev = &i2c->dev; struct regulator_config config = {}; struct regulator_dev *rdev; struct regmap *regmap; + chip = devm_kzalloc(&i2c->dev, sizeof(struct da9121), GFP_KERNEL); + if (!chip) { + ret = -ENOMEM; + goto error; + } + + chip->variant_id = da9121_of_get_id(&i2c->dev); + regmap = devm_regmap_init_i2c(i2c, &da9121_regmap_config); if (IS_ERR(regmap)) return PTR_ERR(regmap); @@ -80,11 +113,18 @@ static int da9121_i2c_probe(struct i2c_client *i2c, return PTR_ERR(rdev); } - return 0; +error: + return ret; } static const struct i2c_device_id da9121_i2c_id[] = { - { "da9121", 0 }, + {"da9121", DA9121_TYPE_DA9121_DA9130}, + {"da9130", DA9121_TYPE_DA9121_DA9130}, + {"da9217", DA9121_TYPE_DA9217}, + {"da9122", DA9121_TYPE_DA9122_DA9131}, + {"da9131", DA9121_TYPE_DA9122_DA9131}, + {"da9220", DA9121_TYPE_DA9220_DA9132}, + {"da9132", DA9121_TYPE_DA9220_DA9132}, {}, }; MODULE_DEVICE_TABLE(i2c, da9121_i2c_id); |