diff options
author | Laxman Dewangan <ldewangan@nvidia.com> | 2012-08-28 12:16:33 +0530 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2013-09-14 01:09:44 -0700 |
commit | e06a8ba57723579b0d028c8aec77f438380daa72 (patch) | |
tree | 9b5eeb72c7781c02b979337bba7a017cef8becb2 /drivers/regulator/max77663-regulator.c | |
parent | b4586e70aa8d987ea6a0c0cf82c526365d67f012 (diff) |
regulator: max77663: register all regulators in single probe
Register the max77663 regulator sub driver as regulator-pmic and
register all regulators in single probe calls.
This will ease the DT porting.
Change-Id: Id50bf52ada4da0e45fabd540c7d9ba5949bbd4f8
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/127515
Rebase-Id: R71523672e6192eac6eae9f7a56099e21a3f93892
Diffstat (limited to 'drivers/regulator/max77663-regulator.c')
-rw-r--r-- | drivers/regulator/max77663-regulator.c | 94 |
1 files changed, 67 insertions, 27 deletions
diff --git a/drivers/regulator/max77663-regulator.c b/drivers/regulator/max77663-regulator.c index d37ad88aebfd..325717ef571d 100644 --- a/drivers/regulator/max77663-regulator.c +++ b/drivers/regulator/max77663-regulator.c @@ -857,54 +857,94 @@ static struct max77663_regulator_info max77663_regs_info[MAX77663_REGULATOR_ID_N static int max77663_regulator_probe(struct platform_device *pdev) { + struct max77663_platform_data *pdata = + dev_get_platdata(pdev->dev.parent); struct regulator_desc *rdesc; struct max77663_regulator *reg; + struct max77663_regulator *max_regs; + struct max77663_regulator_platform_data *reg_pdata; int ret = 0; + int id; + int reg_id; + int reg_count; - if ((pdev->id < 0) || (pdev->id >= MAX77663_REGULATOR_ID_NR)) { - dev_err(&pdev->dev, "Invalid device id %d\n", pdev->id); + if (!pdata) { + dev_err(&pdev->dev, "No Platform data\n"); return -ENODEV; } - reg = devm_kzalloc(&pdev->dev, sizeof(*reg), GFP_KERNEL); - if (!reg) { + reg_count = pdata->num_regulator_pdata; + max_regs = devm_kzalloc(&pdev->dev, + reg_count * sizeof(*max_regs), GFP_KERNEL); + if (!max_regs) { dev_err(&pdev->dev, "mem alloc for reg failed\n"); return -ENOMEM; } - rdesc = &max77663_regs_info[pdev->id].desc; - reg->rinfo = &max77663_regs_info[pdev->id]; - reg->dev = &pdev->dev; - reg->pdata = dev_get_platdata(&pdev->dev); - reg->regulator_mode = REGULATOR_MODE_NORMAL; - reg->power_mode = POWER_MODE_NORMAL; - - dev_dbg(&pdev->dev, "probe: name=%s\n", rdesc->name); + for (id = 0; id < reg_count; ++id) { + reg_pdata = pdata->regulator_pdata[id]; + if (!reg_pdata) { + dev_err(&pdev->dev, + "Regulator pltform data not there\n"); + goto clean_exit; + } - ret = max77663_regulator_preinit(reg); - if (ret) { - dev_err(&pdev->dev, "probe: Failed to preinit regulator %s\n", - rdesc->name); - return ret; - } + reg_id = reg_pdata->id; + reg = &max_regs[id]; + rdesc = &max77663_regs_info[reg_id].desc; + reg->rinfo = &max77663_regs_info[reg_id]; + reg->dev = &pdev->dev; + reg->pdata = reg_pdata; + reg->regulator_mode = REGULATOR_MODE_NORMAL; + reg->power_mode = POWER_MODE_NORMAL; + + dev_dbg(&pdev->dev, "probe: name=%s\n", rdesc->name); + + ret = max77663_regulator_preinit(reg); + if (ret) { + dev_err(&pdev->dev, "Failed to preinit regulator %s\n", + rdesc->name); + goto clean_exit; + } - reg->rdev = regulator_register(rdesc, &pdev->dev, - reg->pdata->reg_init_data, reg, NULL); - if (IS_ERR(reg->rdev)) { - dev_err(&pdev->dev, "probe: Failed to register regulator %s\n", + reg->rdev = regulator_register(rdesc, &pdev->dev, + reg->pdata->reg_init_data, reg, NULL); + if (IS_ERR(reg->rdev)) { + dev_err(&pdev->dev, "Failed to register regulator %s\n", rdesc->name); - return PTR_ERR(reg->rdev); + ret = PTR_ERR(reg->rdev); + goto clean_exit; + } } - platform_set_drvdata(pdev, reg); + platform_set_drvdata(pdev, max_regs); return 0; + +clean_exit: + while (--id >= 0) { + reg = &max_regs[id]; + regulator_unregister(reg->rdev); + } + return ret; } static int max77663_regulator_remove(struct platform_device *pdev) { - struct regulator_dev *rdev = platform_get_drvdata(pdev); + struct max77663_regulator *max_regs = platform_get_drvdata(pdev); + struct max77663_regulator *reg; + struct max77663_platform_data *pdata = + dev_get_platdata(pdev->dev.parent); + int reg_count; + + if (!pdata) + return 0; + + reg_count = pdata->num_regulator_pdata; + while (--reg_count >= 0) { + reg = &max_regs[reg_count]; + regulator_unregister(reg->rdev); + } - regulator_unregister(rdev); return 0; } @@ -912,7 +952,7 @@ static struct platform_driver max77663_regulator_driver = { .probe = max77663_regulator_probe, .remove = max77663_regulator_remove, .driver = { - .name = "max77663-regulator", + .name = "max77663-pmic", .owner = THIS_MODULE, }, }; |