Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 365137
b: refs/heads/master
c: 967cfb1
h: refs/heads/master
i:
  365135: 31537d5
v: v3
  • Loading branch information
Kim, Milo authored and Mark Brown committed Mar 4, 2013
1 parent de6b19b commit d6cb1fc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f19b00da8ed37db4e3891fe534fcf3a605a0e562
refs/heads/master: 967cfb18c0e331b43a29ae7f60ec1ef0dcb02f6b
50 changes: 44 additions & 6 deletions trunk/drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,42 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev)
}
}

/**
* Balance enable_count of each GPIO and actual GPIO pin control.
* GPIO is enabled in case of initial use. (enable_count is 0)
* GPIO is disabled when it is not shared any more. (enable_count <= 1)
*/
static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
{
struct regulator_enable_gpio *pin = rdev->ena_pin;

if (!pin)
return -EINVAL;

if (enable) {
/* Enable GPIO at initial use */
if (pin->enable_count == 0)
gpio_set_value_cansleep(pin->gpio,
!pin->ena_gpio_invert);

pin->enable_count++;
} else {
if (pin->enable_count > 1) {
pin->enable_count--;
return 0;
}

/* Disable GPIO if not used */
if (pin->enable_count <= 1) {
gpio_set_value_cansleep(pin->gpio,
pin->ena_gpio_invert);
pin->enable_count = 0;
}
}

return 0;
}

static int _regulator_do_enable(struct regulator_dev *rdev)
{
int ret, delay;
Expand All @@ -1544,9 +1580,10 @@ static int _regulator_do_enable(struct regulator_dev *rdev)

trace_regulator_enable(rdev_get_name(rdev));

if (rdev->ena_gpio) {
gpio_set_value_cansleep(rdev->ena_gpio,
!rdev->ena_gpio_invert);
if (rdev->ena_pin) {
ret = regulator_ena_gpio_ctrl(rdev, true);
if (ret < 0)
return ret;
rdev->ena_gpio_state = 1;
} else if (rdev->desc->ops->enable) {
ret = rdev->desc->ops->enable(rdev);
Expand Down Expand Up @@ -1648,9 +1685,10 @@ static int _regulator_do_disable(struct regulator_dev *rdev)

trace_regulator_disable(rdev_get_name(rdev));

if (rdev->ena_gpio) {
gpio_set_value_cansleep(rdev->ena_gpio,
rdev->ena_gpio_invert);
if (rdev->ena_pin) {
ret = regulator_ena_gpio_ctrl(rdev, false);
if (ret < 0)
return ret;
rdev->ena_gpio_state = 0;

} else if (rdev->desc->ops->disable) {
Expand Down

0 comments on commit d6cb1fc

Please sign in to comment.