From: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
Date: Wed, 10 Nov 2010 10:06:22 +0000 (+0100)
Subject: regulator: enable supply regulator only when use count is zero
X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f3c18a87f3ddcfd31b16f689d01eb6adcc99de74;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git

regulator: enable supply regulator only when use count is zero

Supply regulators are disabled only when the last
reference count is removed on the child regulator
(the use count goes from 1 to 0). This patch changes
the behaviour of enable so the supply regulator is
enabled only when the use count of the child
regulator goes from 0 to 1.

Signed-off-by: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
---

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 27d062e1395..c577c6d344a 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1267,15 +1267,17 @@ static int _regulator_enable(struct regulator_dev *rdev)
 {
 	int ret, delay;
 
-	/* do we need to enable the supply regulator first */
-	if (rdev->supply) {
-		mutex_lock(&rdev->supply->mutex);
-		ret = _regulator_enable(rdev->supply);
-		mutex_unlock(&rdev->supply->mutex);
-		if (ret < 0) {
-			printk(KERN_ERR "%s: failed to enable %s: %d\n",
-			       __func__, rdev_get_name(rdev), ret);
-			return ret;
+	if (rdev->use_count == 0) {
+		/* do we need to enable the supply regulator first */
+		if (rdev->supply) {
+			mutex_lock(&rdev->supply->mutex);
+			ret = _regulator_enable(rdev->supply);
+			mutex_unlock(&rdev->supply->mutex);
+			if (ret < 0) {
+				printk(KERN_ERR "%s: failed to enable %s: %d\n",
+				       __func__, rdev_get_name(rdev), ret);
+				return ret;
+			}
 		}
 	}