diff options
| author | James Ban <james.ban.opensource@diasemi.com> | 2014-08-26 22:47:07 -0400 |
|---|---|---|
| committer | Mark Brown <broonie@linaro.org> | 2014-08-27 05:27:56 -0400 |
| commit | bf3baca6c54ce8a2f51687296f868dfe20d33f13 (patch) | |
| tree | ca07588b6f8ede9628abd2c3f7bcc35befa59be6 | |
| parent | 1d3e6a6985c14f0510ebbd81fb9e8c02b24f8791 (diff) | |
regulator: da9211: support device tree
This is a patch for supporting device tree of DA9211/DA9213.
Signed-off-by: James Ban <james.ban.opensource@diasemi.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
| -rw-r--r-- | Documentation/devicetree/bindings/regulator/da9211.txt | 63 | ||||
| -rw-r--r-- | drivers/regulator/da9211-regulator.c | 85 | ||||
| -rw-r--r-- | include/linux/regulator/da9211.h | 2 |
3 files changed, 142 insertions, 8 deletions
diff --git a/Documentation/devicetree/bindings/regulator/da9211.txt b/Documentation/devicetree/bindings/regulator/da9211.txt new file mode 100644 index 000000000000..240019a82f9a --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/da9211.txt | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | * Dialog Semiconductor DA9211/DA9213 Voltage Regulator | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible: "dlg,da9211" or "dlg,da9213". | ||
| 5 | - reg: I2C slave address, usually 0x68. | ||
| 6 | - interrupts: the interrupt outputs of the controller | ||
| 7 | - regulators: A node that houses a sub-node for each regulator within the | ||
| 8 | device. Each sub-node is identified using the node's name, with valid | ||
| 9 | values listed below. The content of each sub-node is defined by the | ||
| 10 | standard binding for regulators; see regulator.txt. | ||
| 11 | BUCKA and BUCKB. | ||
| 12 | |||
| 13 | Optional properties: | ||
| 14 | - Any optional property defined in regulator.txt | ||
| 15 | |||
| 16 | Example 1) DA9211 | ||
| 17 | |||
| 18 | pmic: da9211@68 { | ||
| 19 | compatible = "dlg,da9211"; | ||
| 20 | reg = <0x68>; | ||
| 21 | interrupts = <3 27>; | ||
| 22 | |||
| 23 | regulators { | ||
| 24 | BUCKA { | ||
| 25 | regulator-name = "VBUCKA"; | ||
| 26 | regulator-min-microvolt = < 300000>; | ||
| 27 | regulator-max-microvolt = <1570000>; | ||
| 28 | regulator-min-microamp = <2000000>; | ||
| 29 | regulator-max-microamp = <5000000>; | ||
| 30 | }; | ||
| 31 | BUCKB { | ||
| 32 | regulator-name = "VBUCKB"; | ||
| 33 | regulator-min-microvolt = < 300000>; | ||
| 34 | regulator-max-microvolt = <1570000>; | ||
| 35 | regulator-min-microamp = <2000000>; | ||
| 36 | regulator-max-microamp = <5000000>; | ||
| 37 | }; | ||
| 38 | }; | ||
| 39 | }; | ||
| 40 | |||
| 41 | Example 2) DA92113 | ||
| 42 | pmic: da9213@68 { | ||
| 43 | compatible = "dlg,da9213"; | ||
| 44 | reg = <0x68>; | ||
| 45 | interrupts = <3 27>; | ||
| 46 | |||
| 47 | regulators { | ||
| 48 | BUCKA { | ||
| 49 | regulator-name = "VBUCKA"; | ||
| 50 | regulator-min-microvolt = < 300000>; | ||
| 51 | regulator-max-microvolt = <1570000>; | ||
| 52 | regulator-min-microamp = <3000000>; | ||
| 53 | regulator-max-microamp = <6000000>; | ||
| 54 | }; | ||
| 55 | BUCKB { | ||
| 56 | regulator-name = "VBUCKB"; | ||
| 57 | regulator-min-microvolt = < 300000>; | ||
| 58 | regulator-max-microvolt = <1570000>; | ||
| 59 | regulator-min-microamp = <3000000>; | ||
| 60 | regulator-max-microamp = <6000000>; | ||
| 61 | }; | ||
| 62 | }; | ||
| 63 | }; | ||
diff --git a/drivers/regulator/da9211-regulator.c b/drivers/regulator/da9211-regulator.c index a26f1d283c57..5aabbac1b524 100644 --- a/drivers/regulator/da9211-regulator.c +++ b/drivers/regulator/da9211-regulator.c | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include <linux/regmap.h> | 24 | #include <linux/regmap.h> |
| 25 | #include <linux/irq.h> | 25 | #include <linux/irq.h> |
| 26 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/regulator/of_regulator.h> | ||
| 27 | #include <linux/regulator/da9211.h> | 28 | #include <linux/regulator/da9211.h> |
| 28 | #include "da9211-regulator.h" | 29 | #include "da9211-regulator.h" |
| 29 | 30 | ||
| @@ -236,6 +237,59 @@ static struct regulator_desc da9211_regulators[] = { | |||
| 236 | DA9211_BUCK(BUCKB), | 237 | DA9211_BUCK(BUCKB), |
| 237 | }; | 238 | }; |
| 238 | 239 | ||
| 240 | #ifdef CONFIG_OF | ||
| 241 | static struct of_regulator_match da9211_matches[] = { | ||
| 242 | [DA9211_ID_BUCKA] = { .name = "BUCKA" }, | ||
| 243 | [DA9211_ID_BUCKB] = { .name = "BUCKB" }, | ||
| 244 | }; | ||
| 245 | |||
| 246 | static struct da9211_pdata *da9211_parse_regulators_dt( | ||
| 247 | struct device *dev) | ||
| 248 | { | ||
| 249 | struct da9211_pdata *pdata; | ||
| 250 | struct device_node *node; | ||
| 251 | int i, num, n; | ||
| 252 | |||
| 253 | node = of_get_child_by_name(dev->of_node, "regulators"); | ||
| 254 | if (!node) { | ||
| 255 | dev_err(dev, "regulators node not found\n"); | ||
| 256 | return ERR_PTR(-ENODEV); | ||
| 257 | } | ||
| 258 | |||
| 259 | num = of_regulator_match(dev, node, da9211_matches, | ||
| 260 | ARRAY_SIZE(da9211_matches)); | ||
| 261 | of_node_put(node); | ||
| 262 | if (num < 0) { | ||
| 263 | dev_err(dev, "Failed to match regulators\n"); | ||
| 264 | return ERR_PTR(-EINVAL); | ||
| 265 | } | ||
| 266 | |||
| 267 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
| 268 | if (!pdata) | ||
| 269 | return ERR_PTR(-ENOMEM); | ||
| 270 | |||
| 271 | pdata->num_buck = num; | ||
| 272 | |||
| 273 | n = 0; | ||
| 274 | for (i = 0; i < ARRAY_SIZE(da9211_matches); i++) { | ||
| 275 | if (!da9211_matches[i].init_data) | ||
| 276 | continue; | ||
| 277 | |||
| 278 | pdata->init_data[n] = da9211_matches[i].init_data; | ||
| 279 | |||
| 280 | n++; | ||
| 281 | }; | ||
| 282 | |||
| 283 | return pdata; | ||
| 284 | } | ||
| 285 | #else | ||
| 286 | static struct da9211_pdata *da9211_parse_regulators_dt( | ||
| 287 | struct device *dev) | ||
| 288 | { | ||
| 289 | return ERR_PTR(-ENODEV); | ||
| 290 | } | ||
| 291 | #endif | ||
| 292 | |||
| 239 | static irqreturn_t da9211_irq_handler(int irq, void *data) | 293 | static irqreturn_t da9211_irq_handler(int irq, void *data) |
| 240 | { | 294 | { |
| 241 | struct da9211 *chip = data; | 295 | struct da9211 *chip = data; |
| @@ -306,7 +360,7 @@ static int da9211_regulator_init(struct da9211 *chip) | |||
| 306 | } | 360 | } |
| 307 | 361 | ||
| 308 | for (i = 0; i < chip->num_regulator; i++) { | 362 | for (i = 0; i < chip->num_regulator; i++) { |
| 309 | config.init_data = &(chip->pdata->init_data[i]); | 363 | config.init_data = chip->pdata->init_data[i]; |
| 310 | config.dev = chip->dev; | 364 | config.dev = chip->dev; |
| 311 | config.driver_data = chip; | 365 | config.driver_data = chip; |
| 312 | config.regmap = chip->regmap; | 366 | config.regmap = chip->regmap; |
| @@ -332,6 +386,21 @@ static int da9211_regulator_init(struct da9211 *chip) | |||
| 332 | 386 | ||
| 333 | return 0; | 387 | return 0; |
| 334 | } | 388 | } |
| 389 | |||
| 390 | static const struct i2c_device_id da9211_i2c_id[] = { | ||
| 391 | {"da9211", DA9211}, | ||
| 392 | {"da9213", DA9213}, | ||
| 393 | {}, | ||
| 394 | }; | ||
| 395 | |||
| 396 | #ifdef CONFIG_OF | ||
| 397 | static const struct of_device_id da9211_dt_ids[] = { | ||
| 398 | { .compatible = "dlg,da9211", .data = &da9211_i2c_id[0] }, | ||
| 399 | { .compatible = "dlg,da9213", .data = &da9211_i2c_id[1] }, | ||
| 400 | {}, | ||
| 401 | }; | ||
| 402 | #endif | ||
| 403 | |||
| 335 | /* | 404 | /* |
| 336 | * I2C driver interface functions | 405 | * I2C driver interface functions |
| 337 | */ | 406 | */ |
| @@ -377,6 +446,14 @@ static int da9211_i2c_probe(struct i2c_client *i2c, | |||
| 377 | return -ENODEV; | 446 | return -ENODEV; |
| 378 | } | 447 | } |
| 379 | 448 | ||
| 449 | if (!chip->pdata) | ||
| 450 | chip->pdata = da9211_parse_regulators_dt(chip->dev); | ||
| 451 | |||
| 452 | if (IS_ERR(chip->pdata)) { | ||
