diff options
author | Lee Jones <lee.jones@linaro.org> | 2012-05-18 04:39:04 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-05-18 11:36:36 -0400 |
commit | 8986cf8852f16774896fd7b48ec44fa68d29991f (patch) | |
tree | 2206dfe67de5cb359f328fdce458f23e8b0b741a /drivers/regulator/db8500-prcmu.c | |
parent | b13296d0701b90fa8eae5cb6b79c7a2d7a75d3b2 (diff) |
regulator: db8500-prcmu: Separate regulator registration from probe
This will provide us with a convenient way to register regulators when
booting with Device Tree both enabled & disabled and will save us a
great deal of code duplication in time.
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/db8500-prcmu.c')
-rw-r--r-- | drivers/regulator/db8500-prcmu.c | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/drivers/regulator/db8500-prcmu.c b/drivers/regulator/db8500-prcmu.c index 87b2e83be11c..d6b4d4ce1051 100644 --- a/drivers/regulator/db8500-prcmu.c +++ b/drivers/regulator/db8500-prcmu.c | |||
@@ -410,40 +410,58 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { | |||
410 | }, | 410 | }, |
411 | }; | 411 | }; |
412 | 412 | ||
413 | static __devinit int db8500_regulator_register(struct platform_device *pdev, | ||
414 | struct regulator_init_data *init_data, | ||
415 | int id, | ||
416 | struct device_node *np) | ||
417 | { | ||
418 | struct dbx500_regulator_info *info; | ||
419 | struct regulator_config config = { }; | ||
420 | int err; | ||
421 | |||
422 | /* assign per-regulator data */ | ||
423 | info = &dbx500_regulator_info[id]; | ||
424 | info->dev = &pdev->dev; | ||
425 | |||
426 | config.dev = &pdev->dev; | ||
427 | config.init_data = init_data; | ||
428 | config.driver_data = info; | ||
429 | config.of_node = np; | ||
430 | |||
431 | /* register with the regulator framework */ | ||
432 | info->rdev = regulator_register(&info->desc, &config); | ||
433 | if (IS_ERR(info->rdev)) { | ||
434 | err = PTR_ERR(info->rdev); | ||
435 | dev_err(&pdev->dev, "failed to register %s: err %i\n", | ||
436 | info->desc.name, err); | ||
437 | |||
438 | /* if failing, unregister all earlier regulators */ | ||
439 | while (--id >= 0) { | ||
440 | info = &dbx500_regulator_info[id]; | ||
441 | regulator_unregister(info->rdev); | ||
442 | } | ||
443 | return err; | ||
444 | } | ||
445 | |||
446 | dev_dbg(rdev_get_dev(info->rdev), | ||
447 | "regulator-%s-probed\n", info->desc.name); | ||
448 | |||
449 | return 0; | ||
450 | } | ||
451 | |||
413 | static int __devinit db8500_regulator_probe(struct platform_device *pdev) | 452 | static int __devinit db8500_regulator_probe(struct platform_device *pdev) |
414 | { | 453 | { |
415 | struct regulator_init_data *db8500_init_data = | 454 | struct regulator_init_data *db8500_init_data = |
416 | dev_get_platdata(&pdev->dev); | 455 | dev_get_platdata(&pdev->dev); |
417 | struct regulator_config config = { }; | ||
418 | int i, err; | 456 | int i, err; |
419 | 457 | ||
420 | /* register all regulators */ | 458 | /* register all regulators */ |
421 | for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { | 459 | for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { |
422 | struct dbx500_regulator_info *info; | 460 | err = db8500_regulator_register(pdev, |
423 | struct regulator_init_data *init_data = &db8500_init_data[i]; | 461 | &db8500_init_data[i], |
424 | 462 | i, NULL); | |
425 | /* assign per-regulator data */ | 463 | if (err) |
426 | info = &dbx500_regulator_info[i]; | ||
427 | info->dev = &pdev->dev; | ||
428 | |||
429 | config.dev = &pdev->dev; | ||
430 | config.init_data = init_data; | ||
431 | config.driver_data = info; | ||
432 | |||
433 | /* register with the regulator framework */ | ||
434 | info->rdev = regulator_register(&info->desc, &config); | ||
435 | if (IS_ERR(info->rdev)) { | ||
436 | err = PTR_ERR(info->rdev); | ||
437 | dev_err(&pdev->dev, "failed to register %s: err %i\n", | ||
438 | info->desc.name, err); | ||
439 | |||
440 | /* if failing, unregister all earlier regulators */ | ||
441 | while (--i >= 0) { | ||
442 | info = &dbx500_regulator_info[i]; | ||
443 | regulator_unregister(info->rdev); | ||
444 | } | ||
445 | return err; | 464 | return err; |
446 | } | ||
447 | 465 | ||
448 | dev_dbg(rdev_get_dev(info->rdev), | 466 | dev_dbg(rdev_get_dev(info->rdev), |
449 | "regulator-%s-probed\n", info->desc.name); | 467 | "regulator-%s-probed\n", info->desc.name); |
@@ -451,8 +469,7 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev) | |||
451 | err = ux500_regulator_debug_init(pdev, | 469 | err = ux500_regulator_debug_init(pdev, |
452 | dbx500_regulator_info, | 470 | dbx500_regulator_info, |
453 | ARRAY_SIZE(dbx500_regulator_info)); | 471 | ARRAY_SIZE(dbx500_regulator_info)); |
454 | 472 | return 0; | |
455 | return err; | ||
456 | } | 473 | } |
457 | 474 | ||
458 | static int __exit db8500_regulator_remove(struct platform_device *pdev) | 475 | static int __exit db8500_regulator_remove(struct platform_device *pdev) |