Commit 5c5659d0 authored by Mark Brown's avatar Mark Brown

regulator: core: Factor out enable and disable operations some more

Create new _regulator_do_enable() and _regulator_do_disable() operations
which deal with the mechanics of performing the enable and disable, partly
to cut down on the levels of indentation and partly to support some future
work.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent eefaa3c6
...@@ -1476,46 +1476,32 @@ void devm_regulator_put(struct regulator *regulator) ...@@ -1476,46 +1476,32 @@ void devm_regulator_put(struct regulator *regulator)
} }
EXPORT_SYMBOL_GPL(devm_regulator_put); EXPORT_SYMBOL_GPL(devm_regulator_put);
/* locks held by regulator_enable() */ static int _regulator_do_enable(struct regulator_dev *rdev)
static int _regulator_enable(struct regulator_dev *rdev)
{ {
int ret, delay; int ret, delay;
/* check voltage and requested load before enabling */ /* Query before enabling in case configuration dependent. */
if (rdev->constraints &&
(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
drms_uA_update(rdev);
if (rdev->use_count == 0) {
/* The regulator may on if it's not switchable or left on */
ret = _regulator_is_enabled(rdev);
if (ret == -EINVAL || ret == 0) {
if (!_regulator_can_change_status(rdev))
return -EPERM;
if (!rdev->desc->ops->enable)
return -EINVAL;
/* Query before enabling in case configuration
* dependent. */
ret = _regulator_get_enable_time(rdev); ret = _regulator_get_enable_time(rdev);
if (ret >= 0) { if (ret >= 0) {
delay = ret; delay = ret;
} else { } else {
rdev_warn(rdev, "enable_time() failed: %d\n", rdev_warn(rdev, "enable_time() failed: %d\n", ret);
ret);
delay = 0; delay = 0;
} }
trace_regulator_enable(rdev_get_name(rdev)); trace_regulator_enable(rdev_get_name(rdev));
/* Allow the regulator to ramp; it would be useful if (rdev->desc->ops->enable) {
* to extend this for bulk operations so that the
* regulators can ramp together. */
ret = rdev->desc->ops->enable(rdev); ret = rdev->desc->ops->enable(rdev);
if (ret < 0) if (ret < 0)
return ret; return ret;
} else {
return -EINVAL;
}
/* Allow the regulator to ramp; it would be useful to extend
* this for bulk operations so that the regulators can ramp
* together. */
trace_regulator_enable_delay(rdev_get_name(rdev)); trace_regulator_enable_delay(rdev_get_name(rdev));
if (delay >= 1000) { if (delay >= 1000) {
...@@ -1527,6 +1513,30 @@ static int _regulator_enable(struct regulator_dev *rdev) ...@@ -1527,6 +1513,30 @@ static int _regulator_enable(struct regulator_dev *rdev)
trace_regulator_enable_complete(rdev_get_name(rdev)); trace_regulator_enable_complete(rdev_get_name(rdev));
return 0;
}
/* locks held by regulator_enable() */
static int _regulator_enable(struct regulator_dev *rdev)
{
int ret;
/* check voltage and requested load before enabling */
if (rdev->constraints &&
(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
drms_uA_update(rdev);
if (rdev->use_count == 0) {
/* The regulator may on if it's not switchable or left on */
ret = _regulator_is_enabled(rdev);
if (ret == -EINVAL || ret == 0) {
if (!_regulator_can_change_status(rdev))
return -EPERM;
ret = _regulator_do_enable(rdev);
if (ret < 0)
return ret;
} else if (ret < 0) { } else if (ret < 0) {
rdev_err(rdev, "is_enabled() failed: %d\n", ret); rdev_err(rdev, "is_enabled() failed: %d\n", ret);
return ret; return ret;
...@@ -1575,6 +1585,30 @@ int regulator_enable(struct regulator *regulator) ...@@ -1575,6 +1585,30 @@ int regulator_enable(struct regulator *regulator)
} }
EXPORT_SYMBOL_GPL(regulator_enable); EXPORT_SYMBOL_GPL(regulator_enable);
static int _regulator_do_disable(struct regulator_dev *rdev)
{
int ret;
trace_regulator_disable(rdev_get_name(rdev));
if (rdev->ena_gpio) {
gpio_set_value_cansleep(rdev->ena_gpio,
rdev->ena_gpio_invert);
rdev->ena_gpio_state = 0;
} else if (rdev->desc->ops->disable) {
ret = rdev->desc->ops->disable(rdev);
if (ret != 0)
return ret;
}
trace_regulator_disable_complete(rdev_get_name(rdev));
_notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
NULL);
return 0;
}
/* locks held by regulator_disable() */ /* locks held by regulator_disable() */
static int _regulator_disable(struct regulator_dev *rdev) static int _regulator_disable(struct regulator_dev *rdev)
{ {
...@@ -1589,20 +1623,12 @@ static int _regulator_disable(struct regulator_dev *rdev) ...@@ -1589,20 +1623,12 @@ static int _regulator_disable(struct regulator_dev *rdev)
(rdev->constraints && !rdev->constraints->always_on)) { (rdev->constraints && !rdev->constraints->always_on)) {
/* we are last user */ /* we are last user */
if (_regulator_can_change_status(rdev) && if (_regulator_can_change_status(rdev)) {
rdev->desc->ops->disable) { ret = _regulator_do_disable(rdev);
trace_regulator_disable(rdev_get_name(rdev));
ret = rdev->desc->ops->disable(rdev);
if (ret < 0) { if (ret < 0) {
rdev_err(rdev, "failed to disable\n"); rdev_err(rdev, "failed to disable\n");
return ret; return ret;
} }
trace_regulator_disable_complete(rdev_get_name(rdev));
_notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
NULL);
} }
rdev->use_count = 0; rdev->use_count = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment