Skip to content

Commit

Permalink
regulator: core: Factor out enable and disable operations some more
Browse files Browse the repository at this point in the history
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: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Mark Brown committed Jul 3, 2012
1 parent eefaa3c commit 5c5659d
Showing 1 changed file with 68 additions and 42 deletions.
110 changes: 68 additions & 42 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,10 +1476,50 @@ void devm_regulator_put(struct regulator *regulator)
}
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() */
static int _regulator_enable(struct regulator_dev *rdev)
{
int ret, delay;
int ret;

/* check voltage and requested load before enabling */
if (rdev->constraints &&
Expand All @@ -1493,40 +1533,10 @@ static int _regulator_enable(struct regulator_dev *rdev)
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);
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);
ret = _regulator_do_enable(rdev);
if (ret < 0)
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) {
rdev_err(rdev, "is_enabled() failed: %d\n", ret);
return ret;
Expand Down Expand Up @@ -1575,6 +1585,30 @@ int regulator_enable(struct regulator *regulator)
}
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() */
static int _regulator_disable(struct regulator_dev *rdev)
{
Expand All @@ -1589,20 +1623,12 @@ static int _regulator_disable(struct regulator_dev *rdev)
(rdev->constraints && !rdev->constraints->always_on)) {

/* we are last user */
if (_regulator_can_change_status(rdev) &&
rdev->desc->ops->disable) {
trace_regulator_disable(rdev_get_name(rdev));

ret = rdev->desc->ops->disable(rdev);
if (_regulator_can_change_status(rdev)) {
ret = _regulator_do_disable(rdev);
if (ret < 0) {
rdev_err(rdev, "failed to disable\n");
return ret;
}

trace_regulator_disable_complete(rdev_get_name(rdev));

_notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
NULL);
}

rdev->use_count = 0;
Expand Down

0 comments on commit 5c5659d

Please sign in to comment.