2012-10-16 05:27:55

by Yadwinder Singh Brar

[permalink] [raw]
Subject: [PATCH 1/2] regulator: core: Check before enabling regulator while setting constraints.

This patch adds check, whether regulator is already enabled before enabling it
while setting machine constraints. Since some PMICs have same register bits
for setting opmode and enabling/disabling the regulator, so it will overwrite
the settings (if any)done by set_mode/set_suspend_mode callbacks when it
enables regulator without checking previous status.

Signed-off-by: Yadwinder Singh Brar <[email protected]>
---
drivers/regulator/core.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index f7c74db..9e3a0c7 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -958,6 +958,9 @@ static int set_machine_constraints(struct regulator_dev *rdev,
*/
if ((rdev->constraints->always_on || rdev->constraints->boot_on) &&
ops->enable) {
+ if (ops->is_enabled && ops->is_enabled(rdev))
+ goto enabled;
+
ret = ops->enable(rdev);
if (ret < 0) {
rdev_err(rdev, "failed to enable\n");
@@ -965,6 +968,7 @@ static int set_machine_constraints(struct regulator_dev *rdev,
}
}

+enabled:
if (rdev->constraints->ramp_delay && ops->set_ramp_delay) {
ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay);
if (ret < 0) {
--
1.7.0.4


2012-10-16 05:35:12

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 1/2] regulator: core: Check before enabling regulator while setting constraints.

On Tue, Oct 16, 2012 at 10:54:19AM +0530, Yadwinder Singh Brar wrote:
> This patch adds check, whether regulator is already enabled before enabling it
> while setting machine constraints. Since some PMICs have same register bits
> for setting opmode and enabling/disabling the regulator, so it will overwrite
> the settings (if any)done by set_mode/set_suspend_mode callbacks when it
> enables regulator without checking previous status.

This sounds like a bug in the driver, these ops are supposed to be
repeatable at will. The driver needs to remember the mode setting when
doing enable or disable, and setting the mode should not change the
enable status.