aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/regulator/core.c47
-rw-r--r--include/linux/regulator/consumer.h1
2 files changed, 48 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 3d72cc8e2f3..a12cba32460 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1727,6 +1727,53 @@ out:
1727} 1727}
1728EXPORT_SYMBOL_GPL(regulator_set_voltage); 1728EXPORT_SYMBOL_GPL(regulator_set_voltage);
1729 1729
1730/**
1731 * regulator_sync_voltage - re-apply last regulator output voltage
1732 * @regulator: regulator source
1733 *
1734 * Re-apply the last configured voltage. This is intended to be used
1735 * where some external control source the consumer is cooperating with
1736 * has caused the configured voltage to change.
1737 */
1738int regulator_sync_voltage(struct regulator *regulator)
1739{
1740 struct regulator_dev *rdev = regulator->rdev;
1741 int ret, min_uV, max_uV;
1742
1743 mutex_lock(&rdev->mutex);
1744
1745 if (!rdev->desc->ops->set_voltage &&
1746 !rdev->desc->ops->set_voltage_sel) {
1747 ret = -EINVAL;
1748 goto out;
1749 }
1750
1751 /* This is only going to work if we've had a voltage configured. */
1752 if (!regulator->min_uV && !regulator->max_uV) {
1753 ret = -EINVAL;
1754 goto out;
1755 }
1756
1757 min_uV = regulator->min_uV;
1758 max_uV = regulator->max_uV;
1759
1760 /* This should be a paranoia check... */
1761 ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
1762 if (ret < 0)
1763 goto out;
1764
1765 ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
1766 if (ret < 0)
1767 goto out;
1768
1769 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
1770
1771out:
1772 mutex_unlock(&rdev->mutex);
1773 return ret;
1774}
1775EXPORT_SYMBOL_GPL(regulator_sync_voltage);
1776
1730static int _regulator_get_voltage(struct regulator_dev *rdev) 1777static int _regulator_get_voltage(struct regulator_dev *rdev)
1731{ 1778{
1732 int sel; 1779 int sel;
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index ebd74726529..7954f6bd7ed 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -154,6 +154,7 @@ int regulator_is_supported_voltage(struct regulator *regulator,
154 int min_uV, int max_uV); 154 int min_uV, int max_uV);
155int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); 155int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
156int regulator_get_voltage(struct regulator *regulator); 156int regulator_get_voltage(struct regulator *regulator);
157int regulator_sync_voltage(struct regulator *regulator);
157int regulator_set_current_limit(struct regulator *regulator, 158int regulator_set_current_limit(struct regulator *regulator,
158 int min_uA, int max_uA); 159 int min_uA, int max_uA);
159int regulator_get_current_limit(struct regulator *regulator); 160int regulator_get_current_limit(struct regulator *regulator);