aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYadwinder Singh Brar <yadi.brar@samsung.com>2013-06-29 08:51:17 -0400
committerMark Brown <broonie@linaro.org>2013-07-15 13:56:19 -0400
commita50c6b3255b819c9e18c1cc350ed46698b346c1a (patch)
tree677e705905e22fe8ad35d9ab0a2804e47f643322
parent939c02777a27ea7915764ecca5263dbb60c664f3 (diff)
regulator: s2mps11: Add DT support
This patch adds DT support for parsing regulators constraints for parent(mfd) node and moves some common intialising code out of loop while registering. Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/regulator/s2mps11.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 4b84e7660637..b316d40c8e14 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -16,13 +16,17 @@
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/of.h>
19#include <linux/regmap.h> 20#include <linux/regmap.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/regulator/driver.h> 22#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h> 23#include <linux/regulator/machine.h>
24#include <linux/regulator/of_regulator.h>
23#include <linux/mfd/samsung/core.h> 25#include <linux/mfd/samsung/core.h>
24#include <linux/mfd/samsung/s2mps11.h> 26#include <linux/mfd/samsung/s2mps11.h>
25 27
28#define S2MPS11_REGULATOR_CNT ARRAY_SIZE(regulators)
29
26struct s2mps11_info { 30struct s2mps11_info {
27 struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX]; 31 struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX];
28 32
@@ -407,22 +411,38 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
407{ 411{
408 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); 412 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
409 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); 413 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);
414 struct of_regulator_match rdata[S2MPS11_REGULATOR_MAX];
415 struct device_node *reg_np = NULL;
410 struct regulator_config config = { }; 416 struct regulator_config config = { };
411 struct s2mps11_info *s2mps11; 417 struct s2mps11_info *s2mps11;
412 int i, ret; 418 int i, ret;
413 unsigned char ramp_enable, ramp_reg = 0; 419 unsigned char ramp_enable, ramp_reg = 0;
414 420
415 if (!pdata) {
416 dev_err(pdev->dev.parent, "Platform data not supplied\n");
417 return -ENODEV;
418 }
419
420 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), 421 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
421 GFP_KERNEL); 422 GFP_KERNEL);
422 if (!s2mps11) 423 if (!s2mps11)
423 return -ENOMEM; 424 return -ENOMEM;
424 425
425 platform_set_drvdata(pdev, s2mps11); 426 if (!iodev->dev->of_node)
427 goto p_data;
428
429 for (i = 0; i < S2MPS11_REGULATOR_CNT; i++)
430 rdata[i].name = regulators[i].name;
431
432 reg_np = of_find_node_by_name(iodev->dev->of_node, "regulators");
433 if (!reg_np) {
434 dev_err(&pdev->dev, "could not find regulators sub-node\n");
435 return -EINVAL;
436 }
437
438 of_regulator_match(&pdev->dev, reg_np, rdata, S2MPS11_REGULATOR_MAX);
439
440 goto common_reg;
441p_data:
442 if (!pdata) {
443 dev_err(pdev->dev.parent, "Platform data not supplied\n");
444 return -ENODEV;
445 }
426 446
427 s2mps11->ramp_delay2 = pdata->buck2_ramp_delay; 447 s2mps11->ramp_delay2 = pdata->buck2_ramp_delay;
428 s2mps11->ramp_delay34 = pdata->buck34_ramp_delay; 448 s2mps11->ramp_delay34 = pdata->buck34_ramp_delay;
@@ -454,12 +474,19 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
454 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9); 474 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9);
455 sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg); 475 sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg);
456 476
457 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) { 477common_reg:
478 platform_set_drvdata(pdev, s2mps11);
458 479
459 config.dev = &pdev->dev; 480 config.dev = &pdev->dev;
460 config.regmap = iodev->regmap; 481 config.regmap = iodev->regmap;
461 config.init_data = pdata->regulators[i].initdata; 482 config.driver_data = s2mps11;
462 config.driver_data = s2mps11; 483 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) {
484 if (!reg_np) {
485 config.init_data = pdata->regulators[i].initdata;
486 } else {
487 config.init_data = rdata[i].init_data;
488 config.of_node = rdata[i].of_node;
489 }
463 490
464 s2mps11->rdev[i] = regulator_register(&regulators[i], &config); 491 s2mps11->rdev[i] = regulator_register(&regulators[i], &config);
465 if (IS_ERR(s2mps11->rdev[i])) { 492 if (IS_ERR(s2mps11->rdev[i])) {