Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulators: max8660: add DT bindings

This patch adds devicetree bindings for max8660, along with some
documentation.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Signed-off-by: Mark Brown <broonie@linaro.org>

authored by

Daniel Mack and committed by
Mark Brown
abe4c51a de492e8d

+129 -2
+47
Documentation/devicetree/bindings/regulator/max8660.txt
··· 1 + Maxim MAX8660 voltage regulator 2 + 3 + Required properties: 4 + - compatible: must be one of "maxim,max8660", "maxim,max8661" 5 + - reg: I2C slave address, usually 0x34 6 + - any required generic properties defined in regulator.txt 7 + 8 + Example: 9 + 10 + i2c_master { 11 + max8660@34 { 12 + compatible = "maxim,max8660"; 13 + reg = <0x34>; 14 + 15 + regulators { 16 + regulator@0 { 17 + regulator-compatible= "V3(DCDC)"; 18 + regulator-min-microvolt = <725000>; 19 + regulator-max-microvolt = <1800000>; 20 + }; 21 + 22 + regulator@1 { 23 + regulator-compatible= "V4(DCDC)"; 24 + regulator-min-microvolt = <725000>; 25 + regulator-max-microvolt = <1800000>; 26 + }; 27 + 28 + regulator@2 { 29 + regulator-compatible= "V5(LDO)"; 30 + regulator-min-microvolt = <1700000>; 31 + regulator-max-microvolt = <2000000>; 32 + }; 33 + 34 + regulator@3 { 35 + regulator-compatible= "V6(LDO)"; 36 + regulator-min-microvolt = <1800000>; 37 + regulator-max-microvolt = <3300000>; 38 + }; 39 + 40 + regulator@4 { 41 + regulator-compatible= "V7(LDO)"; 42 + regulator-min-microvolt = <1800000>; 43 + regulator-max-microvolt = <3300000>; 44 + }; 45 + }; 46 + }; 47 + };
+81 -1
drivers/regulator/max8660.c
··· 44 44 #include <linux/regulator/driver.h> 45 45 #include <linux/slab.h> 46 46 #include <linux/regulator/max8660.h> 47 + #include <linux/of.h> 48 + #include <linux/of_device.h> 49 + #include <linux/regulator/of_regulator.h> 47 50 48 51 #define MAX8660_DCDC_MIN_UV 725000 49 52 #define MAX8660_DCDC_MAX_UV 1800000 ··· 313 310 MAX8661 = 1, 314 311 }; 315 312 313 + #ifdef CONFIG_OF 314 + static const struct of_device_id max8660_dt_ids[] = { 315 + { .compatible = "maxim,max8660", .data = (void *) MAX8660 }, 316 + { .compatible = "maxim,max8661", .data = (void *) MAX8661 }, 317 + { } 318 + }; 319 + MODULE_DEVICE_TABLE(of, max8660_dt_ids); 320 + 321 + static int max8660_pdata_from_dt(struct device *dev, 322 + struct device_node **of_node, 323 + struct max8660_platform_data *pdata) 324 + { 325 + int matched, i; 326 + struct device_node *np; 327 + struct max8660_subdev_data *sub; 328 + struct of_regulator_match rmatch[ARRAY_SIZE(max8660_reg)]; 329 + 330 + np = of_find_node_by_name(dev->of_node, "regulators"); 331 + if (!np) { 332 + dev_err(dev, "missing 'regulators' subnode in DT\n"); 333 + return -EINVAL; 334 + } 335 + 336 + for (i = 0; i < ARRAY_SIZE(rmatch); i++) 337 + rmatch[i].name = max8660_reg[i].name; 338 + 339 + matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(rmatch)); 340 + if (matched <= 0) 341 + return matched; 342 + 343 + pdata->subdevs = devm_kzalloc(dev, sizeof(struct max8660_subdev_data) * 344 + matched, GFP_KERNEL); 345 + if (!pdata->subdevs) 346 + return -ENOMEM; 347 + 348 + pdata->num_subdevs = matched; 349 + sub = pdata->subdevs; 350 + 351 + for (i = 0; i < matched; i++) { 352 + sub->id = i; 353 + sub->name = rmatch[i].name; 354 + sub->platform_data = rmatch[i].init_data; 355 + of_node[i] = rmatch[i].of_node; 356 + sub++; 357 + } 358 + 359 + return 0; 360 + } 361 + #else 362 + static inline int max8660_pdata_from_dt(struct device *dev, 363 + struct device_node **of_node, 364 + struct max8660_platform_data **pdata) 365 + { 366 + return 0; 367 + } 368 + #endif 369 + 316 370 static int max8660_probe(struct i2c_client *client, 317 371 const struct i2c_device_id *i2c_id) 318 372 { ··· 379 319 struct regulator_config config = { }; 380 320 struct max8660 *max8660; 381 321 int boot_on, i, id, ret = -EINVAL; 322 + struct device_node *of_node[MAX8660_V_END]; 382 323 unsigned int type; 324 + 325 + if (dev->of_node && !pdata) { 326 + const struct of_device_id *id; 327 + struct max8660_platform_data pdata_of; 328 + 329 + id = of_match_device(of_match_ptr(max8660_dt_ids), dev); 330 + if (!id) 331 + return -ENODEV; 332 + 333 + ret = max8660_pdata_from_dt(dev, of_node, &pdata_of); 334 + if (ret < 0) 335 + return ret; 336 + 337 + pdata = &pdata_of; 338 + type = (unsigned int) id->data; 339 + } else { 340 + type = i2c_id->driver_data; 341 + memset(of_node, 0, sizeof(of_node)); 342 + } 383 343 384 344 if (pdata->num_subdevs > MAX8660_V_END) { 385 345 dev_err(dev, "Too many regulators found!\n"); ··· 414 334 415 335 max8660->client = client; 416 336 rdev = max8660->rdev; 417 - type = i2c_id->driver_data; 418 337 419 338 if (pdata->en34_is_high) { 420 339 /* Simulate always on */ ··· 486 407 487 408 config.dev = dev; 488 409 config.init_data = pdata->subdevs[i].platform_data; 410 + config.of_node = of_node[i]; 489 411 config.driver_data = max8660; 490 412 491 413 rdev[i] = regulator_register(&max8660_reg[id], &config);
+1 -1
include/linux/regulator/max8660.h
··· 39 39 */ 40 40 struct max8660_subdev_data { 41 41 int id; 42 - char *name; 42 + const char *name; 43 43 struct regulator_init_data *platform_data; 44 44 }; 45 45