[PATCH 2/3] regulator-core: update all enable GPIO state in_enable/disable

From: Kim, Milo
Date: Thu Jan 10 2013 - 04:46:11 EST


When a regulator is enabled or disabled, enable GPIO state is changed if it is
used.
If multiple regulators are controlled by one shared GPIO, pin states of other
GPIOs should be updated also.

Look up the list of regulators and change the enable pin state if same GPIO
is used. It guarantees exact value of regulator_is_enabled().

Signed-off-by: Milo(Woogyom) Kim <milo.kim@xxxxxx>
---
drivers/regulator/core.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 21b4247..44b2d61 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1473,6 +1473,17 @@ static int regulator_enable_gpio_request(struct regulator_dev *rdev,
rdev_get_name(rdev));
}

+static void update_enable_gpio_state(int gpio, bool enable)
+{
+ struct regulator_dev *r;
+
+ /* Update shared enable pin state */
+ list_for_each_entry(r, &regulator_list, list) {
+ if (r->ena_gpio == gpio)
+ r->ena_gpio_state = enable ? 1 : 0;
+ }
+}
+
static int _regulator_do_enable(struct regulator_dev *rdev)
{
int ret, delay;
@@ -1491,7 +1502,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
if (rdev->ena_gpio) {
gpio_set_value_cansleep(rdev->ena_gpio,
!rdev->ena_gpio_invert);
- rdev->ena_gpio_state = 1;
+ update_enable_gpio_state(rdev->ena_gpio, true);
} else if (rdev->desc->ops->enable) {
ret = rdev->desc->ops->enable(rdev);
if (ret < 0)
@@ -1595,8 +1606,7 @@ static int _regulator_do_disable(struct regulator_dev *rdev)
if (rdev->ena_gpio) {
gpio_set_value_cansleep(rdev->ena_gpio,
rdev->ena_gpio_invert);
- rdev->ena_gpio_state = 0;
-
+ update_enable_gpio_state(rdev->ena_gpio, false);
} else if (rdev->desc->ops->disable) {
ret = rdev->desc->ops->disable(rdev);
if (ret != 0)
--
1.7.9.5


Best Regards,
Milo


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/