aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/ab3100.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2013-04-22 05:57:14 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-04-24 05:53:59 -0400
commit9b31835341004022ea2862116de05fea50b8d1e4 (patch)
tree24ea17657cbd6aca0077653eeb5834eab203128d /drivers/regulator/ab3100.c
parent60d509fa6a9c4653a86ad830e4c4b30360b23f0e (diff)
regulator: ab3100: refactor probe to use IDs
This refactors the AB3100 regulator probe to use regulator IDs and pass this to a separate registration function. This works much smoother when migrating to device tree, as we can use a match table with this regulator ID encoded in the .driver_data. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/ab3100.c')
-rw-r--r--drivers/regulator/ab3100.c90
1 files changed, 55 insertions, 35 deletions
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index 111ec69a3e94..740735d1cca0 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -488,6 +488,58 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
488 }, 488 },
489}; 489};
490 490
491static int ab3100_regulator_register(struct platform_device *pdev,
492 struct ab3100_platform_data *plfdata,
493 int id)
494{
495 struct regulator_desc *desc;
496 struct ab3100_regulator *reg;
497 struct regulator_dev *rdev;
498 struct regulator_config config = { };
499 int err, i;
500
501 for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
502 desc = &ab3100_regulator_desc[i];
503 if (desc->id == id)
504 break;
505 }
506 if (desc->id != id)
507 return -ENODEV;
508
509 /* Same index used for this array */
510 reg = &ab3100_regulators[i];
511
512 /*
513 * Initialize per-regulator struct.
514 * Inherit platform data, this comes down from the
515 * i2c boarddata, from the machine. So if you want to
516 * see what it looks like for a certain machine, go
517 * into the machine I2C setup.
518 */
519 reg->dev = &pdev->dev;
520 if (plfdata) {
521 /* This will be replaced by device tree data */
522 reg->plfdata = plfdata;
523 config.init_data = &plfdata->reg_constraints[i];
524 }
525 config.dev = &pdev->dev;
526 config.driver_data = reg;
527
528 rdev = regulator_register(desc, &config);
529 if (IS_ERR(rdev)) {
530 err = PTR_ERR(rdev);
531 dev_err(&pdev->dev,
532 "%s: failed to register regulator %s err %d\n",
533 __func__, desc->name,
534 err);
535 return err;
536 }
537
538 /* Then set a pointer back to the registered regulator */
539 reg->rdev = rdev;
540 return 0;
541}
542
491/* 543/*
492 * NOTE: the following functions are regulators pluralis - it is the 544 * NOTE: the following functions are regulators pluralis - it is the
493 * binding to the AB3100 core driver and the parent platform device 545 * binding to the AB3100 core driver and the parent platform device
@@ -497,7 +549,6 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
497static int ab3100_regulators_probe(struct platform_device *pdev) 549static int ab3100_regulators_probe(struct platform_device *pdev)
498{ 550{
499 struct ab3100_platform_data *plfdata = pdev->dev.platform_data; 551 struct ab3100_platform_data *plfdata = pdev->dev.platform_data;
500 struct regulator_config config = { };
501 int err = 0; 552 int err = 0;
502 u8 data; 553 u8 data;
503 int i; 554 int i;
@@ -530,42 +581,11 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
530 581
531 /* Register the regulators */ 582 /* Register the regulators */
532 for (i = 0; i < AB3100_NUM_REGULATORS; i++) { 583 for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
533 struct ab3100_regulator *reg = &ab3100_regulators[i]; 584 struct regulator_desc *desc = &ab3100_regulator_desc[i];
534 struct regulator_dev *rdev;
535
536 /*
537 * Initialize per-regulator struct.
538 * Inherit platform data, this comes down from the
539 * i2c boarddata, from the machine. So if you want to
540 * see what it looks like for a certain machine, go
541 * into the machine I2C setup.
542 */
543 reg->dev = &pdev->dev;
544 reg->plfdata = plfdata;
545
546 config.dev = &pdev->dev;
547 config.driver_data = reg;
548 config.init_data = &plfdata->reg_constraints[i];
549 585
550 /* 586 err = ab3100_regulator_register(pdev, plfdata, desc->id);
551 * Register the regulator, pass around 587 if (err)
552 * the ab3100_regulator struct
553 */
554 rdev = regulator_register(&ab3100_regulator_desc[i], &config);
555 if (IS_ERR(rdev)) {
556 err = PTR_ERR(rdev);
557 dev_err(&pdev->dev,
558 "%s: failed to register regulator %s err %d\n",
559 __func__, ab3100_regulator_desc[i].name,
560 err);
561 /* remove the already registered regulators */
562 while (--i >= 0)
563 regulator_unregister(ab3100_regulators[i].rdev);
564 return err; 588 return err;
565 }
566
567 /* Then set a pointer back to the registered regulator */
568 reg->rdev = rdev;
569 } 589 }
570 590
571 return 0; 591 return 0;