diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-12-12 09:25:50 -0500 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2011-01-12 09:33:04 -0500 |
commit | 757902513019e6ee469791ff76f954b19ca8d036 (patch) | |
tree | dc808dc3dbe8df8f06c2b9b3fb7f99ac5ab87865 /drivers/regulator | |
parent | d9f0f287179f76ec71a50a96d553dfd1dbb41711 (diff) |
regulator: Factor out voltage set operation into a separate function
Push all the callers of the chip set_voltage() operation out into a single
function to facilitiate future refactoring.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/core.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b362dbde80f7..23c5f7c80bff 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -83,6 +83,8 @@ static int _regulator_get_current_limit(struct regulator_dev *rdev); | |||
83 | static unsigned int _regulator_get_mode(struct regulator_dev *rdev); | 83 | static unsigned int _regulator_get_mode(struct regulator_dev *rdev); |
84 | static void _notifier_call_chain(struct regulator_dev *rdev, | 84 | static void _notifier_call_chain(struct regulator_dev *rdev, |
85 | unsigned long event, void *data); | 85 | unsigned long event, void *data); |
86 | static int _regulator_do_set_voltage(struct regulator_dev *rdev, | ||
87 | int min_uV, int max_uV); | ||
86 | 88 | ||
87 | static const char *rdev_get_name(struct regulator_dev *rdev) | 89 | static const char *rdev_get_name(struct regulator_dev *rdev) |
88 | { | 90 | { |
@@ -745,22 +747,19 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, | |||
745 | { | 747 | { |
746 | struct regulator_ops *ops = rdev->desc->ops; | 748 | struct regulator_ops *ops = rdev->desc->ops; |
747 | int ret; | 749 | int ret; |
748 | unsigned selector; | ||
749 | 750 | ||
750 | /* do we need to apply the constraint voltage */ | 751 | /* do we need to apply the constraint voltage */ |
751 | if (rdev->constraints->apply_uV && | 752 | if (rdev->constraints->apply_uV && |
752 | rdev->constraints->min_uV == rdev->constraints->max_uV && | 753 | rdev->constraints->min_uV == rdev->constraints->max_uV) { |
753 | ops->set_voltage) { | 754 | ret = _regulator_do_set_voltage(rdev, |
754 | ret = ops->set_voltage(rdev, | 755 | rdev->constraints->min_uV, |
755 | rdev->constraints->min_uV, | 756 | rdev->constraints->max_uV); |
756 | rdev->constraints->max_uV, | 757 | if (ret < 0) { |
757 | &selector); | 758 | rdev_err(rdev, "failed to apply %duV constraint\n", |
758 | if (ret < 0) { | 759 | rdev->constraints->min_uV); |
759 | rdev_err(rdev, "failed to apply %duV constraint\n", | 760 | rdev->constraints = NULL; |
760 | rdev->constraints->min_uV); | 761 | return ret; |
761 | rdev->constraints = NULL; | 762 | } |
762 | return ret; | ||
763 | } | ||
764 | } | 763 | } |
765 | 764 | ||
766 | /* constrain machine-level voltage specs to fit | 765 | /* constrain machine-level voltage specs to fit |
@@ -1621,6 +1620,32 @@ int regulator_is_supported_voltage(struct regulator *regulator, | |||
1621 | return 0; | 1620 | return 0; |
1622 | } | 1621 | } |
1623 | 1622 | ||
1623 | static int _regulator_do_set_voltage(struct regulator_dev *rdev, | ||
1624 | int min_uV, int max_uV) | ||
1625 | { | ||
1626 | int ret; | ||
1627 | unsigned int selector; | ||
1628 | |||
1629 | trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); | ||
1630 | |||
1631 | if (rdev->desc->ops->set_voltage) { | ||
1632 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, | ||
1633 | &selector); | ||
1634 | |||
1635 | if (rdev->desc->ops->list_voltage) | ||
1636 | selector = rdev->desc->ops->list_voltage(rdev, | ||
1637 | selector); | ||
1638 | else | ||
1639 | selector = -1; | ||
1640 | } else { | ||
1641 | ret = -EINVAL; | ||
1642 | } | ||
1643 | |||
1644 | trace_regulator_set_voltage_complete(rdev_get_name(rdev), selector); | ||
1645 | |||
1646 | return ret; | ||
1647 | } | ||
1648 | |||
1624 | /** | 1649 | /** |
1625 | * regulator_set_voltage - set regulator output voltage | 1650 | * regulator_set_voltage - set regulator output voltage |
1626 | * @regulator: regulator source | 1651 | * @regulator: regulator source |
@@ -1643,7 +1668,6 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
1643 | { | 1668 | { |
1644 | struct regulator_dev *rdev = regulator->rdev; | 1669 | struct regulator_dev *rdev = regulator->rdev; |
1645 | int ret; | 1670 | int ret; |
1646 | unsigned selector; | ||
1647 | 1671 | ||
1648 | mutex_lock(&rdev->mutex); | 1672 | mutex_lock(&rdev->mutex); |
1649 | 1673 | ||
@@ -1664,16 +1688,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
1664 | if (ret < 0) | 1688 | if (ret < 0) |
1665 | goto out; | 1689 | goto out; |
1666 | 1690 | ||
1667 | trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); | 1691 | ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); |
1668 | |||
1669 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, &selector); | ||
1670 | |||
1671 | if (rdev->desc->ops->list_voltage) | ||
1672 | selector = rdev->desc->ops->list_voltage(rdev, selector); | ||
1673 | else | ||
1674 | selector = -1; | ||
1675 | |||
1676 | trace_regulator_set_voltage_complete(rdev_get_name(rdev), selector); | ||
1677 | 1692 | ||
1678 | out: | 1693 | out: |
1679 | _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL); | 1694 | _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL); |