mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 2/4] regulator-core: manage enable GPIO list
@ 2013-01-15  4:35 Kim, Milo
  2013-01-27  6:06 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Kim, Milo @ 2013-01-15  4:35 UTC (permalink / raw)
  To: Mark Brown; +Cc: Axel Lin, Girdwood, Liam, linux-kernel

 To support shared enable GPIO pin, replace GPIO code with new static functions

 regulator_ena_gpio_ctrl()
   Find a GPIO information in the enable GPIO list and control the pin.

 _do_ena_gpio_ctrl()
   Balance the reference count of each GPIO and actual pin control.
   The count is incremented with enabling GPIO.
   On the other hand, it is decremented on disabling GPIO.
   Actual GPIO pin is enabled at the initial use.(enable_count = 0)
   The pin is disabled if it is not used(shared) any more. (enable_count = 1)
   This concept is derived from the 'use_count' of regulator.
   Regardless of the enable count, update GPIO state of the regulator.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
---
 drivers/regulator/core.c |   54 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 47 insertions(+), 7 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 1273090..dc713c4 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1501,6 +1501,51 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
 	return 0;
 }
 
+/**
+ * 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 is 1)
+ */
+static void _do_ena_gpio_ctrl(struct regulator_enable_gpio *pin,
+			struct regulator_dev *rdev, bool enable)
+{
+	if (enable) {
+		/* Enable GPIO at initial use */
+		if (pin->enable_count == 0)
+			gpio_set_value_cansleep(rdev->ena_gpio,
+						!rdev->ena_gpio_invert);
+
+		rdev->ena_gpio_state = 1;
+		pin->enable_count++;
+
+	} else {
+		rdev->ena_gpio_state = 0;
+		if (pin->enable_count > 1) {
+			pin->enable_count--;
+			return;
+		}
+
+		/* Disable GPIO if not used */
+		if (pin->enable_count == 1) {
+			gpio_set_value_cansleep(rdev->ena_gpio,
+						rdev->ena_gpio_invert);
+			pin->enable_count = 0;
+		}
+	}
+}
+
+static void regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
+{
+	struct regulator_enable_gpio *pin;
+
+	list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
+		if (pin->gpio == rdev->ena_gpio) {
+			_do_ena_gpio_ctrl(pin, rdev, enable);
+			return;
+		}
+	}
+}
+
 static int _regulator_do_enable(struct regulator_dev *rdev)
 {
 	int ret, delay;
@@ -1517,9 +1562,7 @@ 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);
-		rdev->ena_gpio_state = 1;
+		regulator_ena_gpio_ctrl(rdev, true);
 	} else if (rdev->desc->ops->enable) {
 		ret = rdev->desc->ops->enable(rdev);
 		if (ret < 0)
@@ -1621,10 +1664,7 @@ 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);
-		rdev->ena_gpio_state = 0;
-
+		regulator_ena_gpio_ctrl(rdev, false);
 	} else if (rdev->desc->ops->disable) {
 		ret = rdev->desc->ops->disable(rdev);
 		if (ret != 0)
-- 
1.7.9.5


Best Regards,
Milo



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-01-27  6:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-15  4:35 [PATCH v2 2/4] regulator-core: manage enable GPIO list Kim, Milo
2013-01-27  6:06 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome