diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-10-19 10:53:50 -0400 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2009-12-17 05:27:23 -0500 |
commit | e79055d62ea6ca3c36962209f4c819614972c95a (patch) | |
tree | 2065914f45c00b6b94f346f9374d77748581a215 /drivers | |
parent | 5b307627738f1f6cbc31fad9e28a299b5fe55602 (diff) |
regulator: Factor out voltage constraint setup
This allows constraints to take effect on regulators that support
voltage setting but for which the board does not specify a voltage
range (for example, because it is fixed correctly at system startup).
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/regulator/core.c | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 9b43dab16387..c1a49917af24 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -672,31 +672,11 @@ static void print_constraints(struct regulator_dev *rdev) | |||
672 | printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); | 672 | printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); |
673 | } | 673 | } |
674 | 674 | ||
675 | /** | 675 | static int machine_constraints_voltage(struct regulator_dev *rdev, |
676 | * set_machine_constraints - sets regulator constraints | 676 | const char *name, struct regulation_constraints *constraints) |
677 | * @rdev: regulator source | ||
678 | * @constraints: constraints to apply | ||
679 | * | ||
680 | * Allows platform initialisation code to define and constrain | ||
681 | * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: | ||
682 | * Constraints *must* be set by platform code in order for some | ||
683 | * regulator operations to proceed i.e. set_voltage, set_current_limit, | ||
684 | * set_mode. | ||
685 | */ | ||
686 | static int set_machine_constraints(struct regulator_dev *rdev, | ||
687 | struct regulation_constraints *constraints) | ||
688 | { | 677 | { |
689 | int ret = 0; | ||
690 | const char *name; | ||
691 | struct regulator_ops *ops = rdev->desc->ops; | 678 | struct regulator_ops *ops = rdev->desc->ops; |
692 | 679 | ||
693 | if (constraints->name) | ||
694 | name = constraints->name; | ||
695 | else if (rdev->desc->name) | ||
696 | name = rdev->desc->name; | ||
697 | else | ||
698 | name = "regulator"; | ||
699 | |||
700 | /* constrain machine-level voltage specs to fit | 680 | /* constrain machine-level voltage specs to fit |
701 | * the actual range supported by this regulator. | 681 | * the actual range supported by this regulator. |
702 | */ | 682 | */ |
@@ -719,14 +699,13 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
719 | 699 | ||
720 | /* voltage constraints are optional */ | 700 | /* voltage constraints are optional */ |
721 | if ((cmin == 0) && (cmax == 0)) | 701 | if ((cmin == 0) && (cmax == 0)) |
722 | goto out; | 702 | return 0; |
723 | 703 | ||
724 | /* else require explicit machine-level constraints */ | 704 | /* else require explicit machine-level constraints */ |
725 | if (cmin <= 0 || cmax <= 0 || cmax < cmin) { | 705 | if (cmin <= 0 || cmax <= 0 || cmax < cmin) { |
726 | pr_err("%s: %s '%s' voltage constraints\n", | 706 | pr_err("%s: %s '%s' voltage constraints\n", |
727 | __func__, "invalid", name); | 707 | __func__, "invalid", name); |
728 | ret = -EINVAL; | 708 | return -EINVAL; |
729 | goto out; | ||
730 | } | 709 | } |
731 | 710 | ||
732 | /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ | 711 | /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ |
@@ -748,8 +727,7 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
748 | if (max_uV < min_uV) { | 727 | if (max_uV < min_uV) { |
749 | pr_err("%s: %s '%s' voltage constraints\n", | 728 | pr_err("%s: %s '%s' voltage constraints\n", |
750 | __func__, "unsupportable", name); | 729 | __func__, "unsupportable", name); |
751 | ret = -EINVAL; | 730 | return -EINVAL; |
752 | goto out; | ||
753 | } | 731 | } |
754 | 732 | ||
755 | /* use regulator's subset of machine constraints */ | 733 | /* use regulator's subset of machine constraints */ |
@@ -767,6 +745,38 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
767 | } | 745 | } |
768 | } | 746 | } |
769 | 747 | ||
748 | return 0; | ||
749 | } | ||
750 | |||
751 | /** | ||
752 | * set_machine_constraints - sets regulator constraints | ||
753 | * @rdev: regulator source | ||
754 | * @constraints: constraints to apply | ||
755 | * | ||
756 | * Allows platform initialisation code to define and constrain | ||
757 | * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: | ||
758 | * Constraints *must* be set by platform code in order for some | ||
759 | * regulator operations to proceed i.e. set_voltage, set_current_limit, | ||
760 | * set_mode. | ||
761 | */ | ||
762 | static int set_machine_constraints(struct regulator_dev *rdev, | ||
763 | struct regulation_constraints *constraints) | ||
764 | { | ||
765 | int ret = 0; | ||
766 | const char *name; | ||
767 | struct regulator_ops *ops = rdev->desc->ops; | ||
768 | |||
769 | if (constraints->name) | ||
770 | name = constraints->name; | ||
771 | else if (rdev->desc->name) | ||
772 | name = rdev->desc->name; | ||
773 | else | ||
774 | name = "regulator"; | ||
775 | |||
776 | ret = machine_constraints_voltage(rdev, name, constraints); | ||
777 | if (ret != 0) | ||
778 | goto out; | ||
779 | |||
770 | rdev->constraints = constraints; | 780 | rdev->constraints = constraints; |
771 | 781 | ||
772 | /* do we need to apply the constraint voltage */ | 782 | /* do we need to apply the constraint voltage */ |