aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Shiyan <shc_work@mail.ru>2013-04-27 02:29:25 -0400
committerMark Brown <broonie@sirena.org.uk>2013-04-27 21:10:00 -0400
commit86b139f0f3441dfcb32a095cdc2ffe88c13c8ed0 (patch)
tree1060257663ec0bf1f1a3f19c812b765ae9236af9
parenteb0d8e7a14041e30f74f63dca12e0f49ee0bec39 (diff)
regulator: mc13783: Add device tree probe support
Patch adds device tree probe support for mc13783-regulator driver. Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Mark Brown <broonie@sirena.org.uk>
-rw-r--r--Documentation/devicetree/bindings/mfd/mc13xxx.txt36
-rw-r--r--drivers/regulator/mc13783-regulator.c44
2 files changed, 62 insertions, 18 deletions
diff --git a/Documentation/devicetree/bindings/mfd/mc13xxx.txt b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
index baf07987ae68..abd9e3cb2db7 100644
--- a/Documentation/devicetree/bindings/mfd/mc13xxx.txt
+++ b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
@@ -10,10 +10,40 @@ Optional properties:
10- fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used 10- fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used
11 11
12Sub-nodes: 12Sub-nodes:
13- regulators : Contain the regulator nodes. The MC13892 regulators are 13- regulators : Contain the regulator nodes. The regulators are bound using
14 bound using their names as listed below with their registers and bits 14 their names as listed below with their registers and bits for enabling.
15 for enabling.
16 15
16MC13783 regulators:
17 sw1a : regulator SW1A (register 24, bit 0)
18 sw1b : regulator SW1B (register 25, bit 0)
19 sw2a : regulator SW2A (register 26, bit 0)
20 sw2b : regulator SW2B (register 27, bit 0)
21 sw3 : regulator SW3 (register 29, bit 20)
22 vaudio : regulator VAUDIO (register 32, bit 0)
23 viohi : regulator VIOHI (register 32, bit 3)
24 violo : regulator VIOLO (register 32, bit 6)
25 vdig : regulator VDIG (register 32, bit 9)
26 vgen : regulator VGEN (register 32, bit 12)
27 vrfdig : regulator VRFDIG (register 32, bit 15)
28 vrfref : regulator VRFREF (register 32, bit 18)
29 vrfcp : regulator VRFCP (register 32, bit 21)
30 vsim : regulator VSIM (register 33, bit 0)
31 vesim : regulator VESIM (register 33, bit 3)
32 vcam : regulator VCAM (register 33, bit 6)
33 vrfbg : regulator VRFBG (register 33, bit 9)
34 vvib : regulator VVIB (register 33, bit 11)
35 vrf1 : regulator VRF1 (register 33, bit 12)
36 vrf2 : regulator VRF2 (register 33, bit 15)
37 vmmc1 : regulator VMMC1 (register 33, bit 18)
38 vmmc2 : regulator VMMC2 (register 33, bit 21)
39 gpo1 : regulator GPO1 (register 34, bit 6)
40 gpo2 : regulator GPO2 (register 34, bit 8)
41 gpo3 : regulator GPO3 (register 34, bit 10)
42 gpo4 : regulator GPO4 (register 34, bit 12)
43 pwgt1spi : regulator PWGT1SPI (register 34, bit 15)
44 pwgt2spi : regulator PWGT2SPI (register 34, bit 16)
45
46MC13892 regulators:
17 vcoincell : regulator VCOINCELL (register 13, bit 23) 47 vcoincell : regulator VCOINCELL (register 13, bit 23)
18 sw1 : regulator SW1 (register 24, bit 0) 48 sw1 : regulator SW1 (register 24, bit 0)
19 sw2 : regulator SW2 (register 25, bit 0) 49 sw2 : regulator SW2 (register 25, bit 0)
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index c46c6705cd74..fdf7f0a09090 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -398,33 +398,51 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
398 struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent); 398 struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
399 struct mc13xxx_regulator_platform_data *pdata = 399 struct mc13xxx_regulator_platform_data *pdata =
400 dev_get_platdata(&pdev->dev); 400 dev_get_platdata(&pdev->dev);
401 struct mc13xxx_regulator_init_data *init_data; 401 struct mc13xxx_regulator_init_data *mc13xxx_data;
402 struct regulator_config config = { }; 402 struct regulator_config config = { };
403 int i, ret; 403 int i, ret, num_regulators;
404 404
405 dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id); 405 num_regulators = mc13xxx_get_num_regulators_dt(pdev);
406 406
407 if (!pdata) 407 if (num_regulators <= 0 && pdata)
408 num_regulators = pdata->num_regulators;
409 if (num_regulators <= 0)
408 return -EINVAL; 410 return -EINVAL;
409 411
410 priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + 412 priv = devm_kzalloc(&pdev->dev, sizeof(*priv) +
411 pdata->num_regulators * sizeof(priv->regulators[0]), 413 num_regulators * sizeof(priv->regulators[0]),
412 GFP_KERNEL); 414 GFP_KERNEL);
413 if (!priv) 415 if (!priv)
414 return -ENOMEM; 416 return -ENOMEM;
415 417
418 priv->num_regulators = num_regulators;
416 priv->mc13xxx_regulators = mc13783_regulators; 419 priv->mc13xxx_regulators = mc13783_regulators;
417 priv->mc13xxx = mc13783; 420 priv->mc13xxx = mc13783;
421 platform_set_drvdata(pdev, priv);
418 422
419 for (i = 0; i < pdata->num_regulators; i++) { 423 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13783_regulators,
420 struct regulator_desc *desc; 424 ARRAY_SIZE(mc13783_regulators));
421 425
422 init_data = &pdata->regulators[i]; 426 for (i = 0; i < priv->num_regulators; i++) {
423 desc = &mc13783_regulators[init_data->id].desc; 427 struct regulator_init_data *init_data;
428 struct regulator_desc *desc;
429 struct device_node *node = NULL;
430 int id;
431
432 if (mc13xxx_data) {
433 id = mc13xxx_data[i].id;
434 init_data = mc13xxx_data[i].init_data;
435 node = mc13xxx_data[i].node;
436 } else {
437 id = pdata->regulators[i].id;
438 init_data = pdata->regulators[i].init_data;
439 }
440 desc = &mc13783_regulators[id].desc;
424 441
425 config.dev = &pdev->dev; 442 config.dev = &pdev->dev;
426 config.init_data = init_data->init_data; 443 config.init_data = init_data;
427 config.driver_data = priv; 444 config.driver_data = priv;
445 config.of_node = node;
428 446
429 priv->regulators[i] = regulator_register(desc, &config); 447 priv->regulators[i] = regulator_register(desc, &config);
430 if (IS_ERR(priv->regulators[i])) { 448 if (IS_ERR(priv->regulators[i])) {
@@ -435,8 +453,6 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
435 } 453 }
436 } 454 }
437 455
438 platform_set_drvdata(pdev, priv);
439
440 return 0; 456 return 0;
441err: 457err:
442 while (--i >= 0) 458 while (--i >= 0)
@@ -448,13 +464,11 @@ err:
448static int mc13783_regulator_remove(struct platform_device *pdev) 464static int mc13783_regulator_remove(struct platform_device *pdev)
449{ 465{
450 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev); 466 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
451 struct mc13xxx_regulator_platform_data *pdata =
452 dev_get_platdata(&pdev->dev);
453 int i; 467 int i;
454 468
455 platform_set_drvdata(pdev, NULL); 469 platform_set_drvdata(pdev, NULL);
456 470
457 for (i = 0; i < pdata->num_regulators; i++) 471 for (i = 0; i < priv->num_regulators; i++)
458 regulator_unregister(priv->regulators[i]); 472 regulator_unregister(priv->regulators[i]);
459 473
460 return 0; 474 return 0;