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,10 +1476,50 @@ void devm_regulator_put(struct regulator *regulator) ...@@ -1476,10 +1476,50 @@ void devm_regulator_put(struct regulator *regulator)
} }
EXPORT_SYMBOL_GPL(devm_regulator_put); EXPORT_SYMBOL_GPL(devm_regulator_put);
static int _regulator_do_enable(struct regulator_dev *rdev)
{
int ret, delay;
/* Query before enabling in case configuration dependent. */
ret = _regulator_get_enable_time(rdev);
if (ret >= 0) {
delay = ret;
} else {
rdev_warn(rdev, "enable_time() failed: %d\n", ret);
delay = 0;
}
trace_regulator_enable(rdev_get_name(rdev));
if (rdev->desc->ops->enable) {
ret = rdev->desc->ops->enable(rdev);
if (ret < 0)
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));
if (delay >= 1000) {
mdelay(delay / 1000);
udelay(delay % 1000);
} else if (delay) {
udelay(delay);
}
trace_regulator_enable_complete(rdev_get_name(rdev));
return 0;
}
/* locks held by regulator_enable() */ /* locks held by regulator_enable() */
static int _regulator_enable(struct regulator_dev *rdev) static int _regulator_enable(struct regulator_dev *rdev)
{ {
int ret, delay; int ret;
/* check voltage and requested load before enabling */ /* check voltage and requested load before enabling */
if (rdev->constraints && if (rdev->constraints &&
...@@ -1493,40 +1533,10 @@ static int _regulator_enable(struct regulator_dev *rdev) ...@@ -1493,40 +1533,10 @@ static int _regulator_enable(struct regulator_dev *rdev)
if (!_regulator_can_change_status(rdev)) if (!_regulator_can_change_status(rdev))
return -EPERM; return -EPERM;
if (!rdev->desc->ops->enable) ret = _regulator_do_enable(rdev);
return -EINVAL;
/* Query before enabling in case configuration
* dependent. */
ret = _regulator_get_enable_time(rdev);
if (ret >= 0) {
delay = ret;
} else {
rdev_warn(rdev, "enable_time() failed: %d\n",
ret);
delay = 0;
}
trace_regulator_enable(rdev_get_name(rdev));
/* Allow the regulator to ramp; it would be useful
* to extend this for bulk operations so that the
* regulators can ramp together. */
ret = rdev->desc->ops->enable(rdev);
if (ret < 0) if (ret < 0)
return ret; return ret;
trace_regulator_enable_delay(rdev_get_name(rdev));
if (delay >= 1000) {
mdelay(delay / 1000);
udelay(delay % 1000);
} else if (delay) {
udelay(delay);
}
trace_regulator_enable_complete(rdev_get_name(rdev));
} 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