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

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>

authored by

Alexander Shiyan and committed by
Mark Brown
86b139f0 eb0d8e7a

+61 -17
+33 -3
Documentation/devicetree/bindings/mfd/mc13xxx.txt
··· 10 10 - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used 11 11 12 12 Sub-nodes: 13 - - regulators : Contain the regulator nodes. The MC13892 regulators are 14 - bound using their names as listed below with their registers and bits 15 - for enabling. 13 + - regulators : Contain the regulator nodes. The regulators are bound using 14 + their names as listed below with their registers and bits for enabling. 16 15 16 + MC13783 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 + 46 + MC13892 regulators: 17 47 vcoincell : regulator VCOINCELL (register 13, bit 23) 18 48 sw1 : regulator SW1 (register 24, bit 0) 19 49 sw2 : regulator SW2 (register 25, bit 0)
+28 -14
drivers/regulator/mc13783-regulator.c
··· 398 398 struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent); 399 399 struct mc13xxx_regulator_platform_data *pdata = 400 400 dev_get_platdata(&pdev->dev); 401 - struct mc13xxx_regulator_init_data *init_data; 401 + struct mc13xxx_regulator_init_data *mc13xxx_data; 402 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 410 return -EINVAL; 409 411 410 412 priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + 411 - pdata->num_regulators * sizeof(priv->regulators[0]), 413 + num_regulators * sizeof(priv->regulators[0]), 412 414 GFP_KERNEL); 413 415 if (!priv) 414 416 return -ENOMEM; 415 417 418 + priv->num_regulators = num_regulators; 416 419 priv->mc13xxx_regulators = mc13783_regulators; 417 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, 424 + ARRAY_SIZE(mc13783_regulators)); 425 + 426 + for (i = 0; i < priv->num_regulators; i++) { 427 + struct regulator_init_data *init_data; 420 428 struct regulator_desc *desc; 429 + struct device_node *node = NULL; 430 + int id; 421 431 422 - init_data = &pdata->regulators[i]; 423 - desc = &mc13783_regulators[init_data->id].desc; 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 442 config.dev = &pdev->dev; 426 - config.init_data = init_data->init_data; 443 + config.init_data = init_data; 427 444 config.driver_data = priv; 445 + config.of_node = node; 428 446 429 447 priv->regulators[i] = regulator_register(desc, &config); 430 448 if (IS_ERR(priv->regulators[i])) { ··· 452 434 goto err; 453 435 } 454 436 } 455 - 456 - platform_set_drvdata(pdev, priv); 457 437 458 438 return 0; 459 439 err: ··· 464 448 static int mc13783_regulator_remove(struct platform_device *pdev) 465 449 { 466 450 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev); 467 - struct mc13xxx_regulator_platform_data *pdata = 468 - dev_get_platdata(&pdev->dev); 469 451 int i; 470 452 471 453 platform_set_drvdata(pdev, NULL); 472 454 473 - for (i = 0; i < pdata->num_regulators; i++) 455 + for (i = 0; i < priv->num_regulators; i++) 474 456 regulator_unregister(priv->regulators[i]); 475 457 476 458 return 0;