Skip to content

Commit 606a256

Browse files
broonieLiam Girdwood
authored andcommitted
regulator: Add API to re-apply voltage to hardware
When cooperating with an external control source the regulator setup may be changed underneath the API. Currently consumers can just redo the regulator_set_voltage() to restore a previously set configuration but provide an explicit API for doing this as optimsations in the regulator_set_voltage() implementation will shortly prevent that. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
1 parent 27315cf commit 606a256

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎drivers/regulator/core.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,53 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
17271727
}
17281728
EXPORT_SYMBOL_GPL(regulator_set_voltage);
17291729

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+
*/
1738+
int 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+
1771+
out:
1772+
mutex_unlock(&rdev->mutex);
1773+
return ret;
1774+
}
1775+
EXPORT_SYMBOL_GPL(regulator_sync_voltage);
1776+
17301777
static int _regulator_get_voltage(struct regulator_dev *rdev)
17311778
{
17321779
int sel;

‎include/linux/regulator/consumer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ int regulator_is_supported_voltage(struct regulator *regulator,
154154
int min_uV, int max_uV);
155155
int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
156156
int regulator_get_voltage(struct regulator *regulator);
157+
int regulator_sync_voltage(struct regulator *regulator);
157158
int regulator_set_current_limit(struct regulator *regulator,
158159
int min_uA, int max_uA);
159160
int regulator_get_current_limit(struct regulator *regulator);

0 commit comments

Comments
 (0)