diff mbox

regulator: core: if voltage scaling fails, restore original voltage values

Message ID 1355312753-16514-2-git-send-email-paolo.pisati@canonical.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paolo Pisati Dec. 12, 2012, 11:45 a.m. UTC
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
---
 drivers/regulator/core.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Robert Nelson Dec. 12, 2012, 6:13 p.m. UTC | #1
On Wed, Dec 12, 2012 at 5:45 AM, Paolo Pisati
<paolo.pisati@canonical.com> wrote:
> Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
> ---
>  drivers/regulator/core.c |   16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index e872c8b..c347fd0 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -2250,6 +2250,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
>  {
>         struct regulator_dev *rdev = regulator->rdev;
>         int ret = 0;
> +       int old_min_uV, old_max_uV;
>
>         mutex_lock(&rdev->mutex);
>
> @@ -2271,18 +2272,29 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
>         ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
>         if (ret < 0)
>                 goto out;
> +
> +       /* restore original values in case of error */
> +       old_min_uV = regulator->min_uV;
> +       old_max_uV = regulator->max_uV;
>         regulator->min_uV = min_uV;
>         regulator->max_uV = max_uV;
>
>         ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
>         if (ret < 0)
> -               goto out;
> +               goto out2;
>
>         ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
> -
> +       if (ret < 0)
> +               goto out2;
> +
>  out:
>         mutex_unlock(&rdev->mutex);
>         return ret;
> +out2:
> +       regulator->min_uV = old_min_uV;
> +       regulator->max_uV = old_max_uV;
> +       mutex_unlock(&rdev->mutex);
> +       return ret;
>  }
>  EXPORT_SYMBOL_GPL(regulator_set_voltage);
>
> --
> 1.7.10.4

Nice! This fixes the 800Mhz lockup on bootup after a software reset we
were seeing on the Beagle xM's with v3.7.x/v3.6.x...

Tested-by: Robert Nelson <robertcnelson@gmail.com>

Regards,
Felipe Balbi Dec. 12, 2012, 7 p.m. UTC | #2
Hi,

On Wed, Dec 12, 2012 at 12:13:35PM -0600, Robert Nelson wrote:
> On Wed, Dec 12, 2012 at 5:45 AM, Paolo Pisati
> <paolo.pisati@canonical.com> wrote:
> > Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
> > ---
> >  drivers/regulator/core.c |   16 ++++++++++++++--
> >  1 file changed, 14 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> > index e872c8b..c347fd0 100644
> > --- a/drivers/regulator/core.c
> > +++ b/drivers/regulator/core.c
> > @@ -2250,6 +2250,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
> >  {
> >         struct regulator_dev *rdev = regulator->rdev;
> >         int ret = 0;
> > +       int old_min_uV, old_max_uV;
> >
> >         mutex_lock(&rdev->mutex);
> >
> > @@ -2271,18 +2272,29 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
> >         ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
> >         if (ret < 0)
> >                 goto out;
> > +
> > +       /* restore original values in case of error */
> > +       old_min_uV = regulator->min_uV;
> > +       old_max_uV = regulator->max_uV;
> >         regulator->min_uV = min_uV;
> >         regulator->max_uV = max_uV;
> >
> >         ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
> >         if (ret < 0)
> > -               goto out;
> > +               goto out2;
> >
> >         ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
> > -
> > +       if (ret < 0)
> > +               goto out2;
> > +
> >  out:
> >         mutex_unlock(&rdev->mutex);
> >         return ret;
> > +out2:
> > +       regulator->min_uV = old_min_uV;
> > +       regulator->max_uV = old_max_uV;
> > +       mutex_unlock(&rdev->mutex);
> > +       return ret;
> >  }
> >  EXPORT_SYMBOL_GPL(regulator_set_voltage);
> >
> > --
> > 1.7.10.4
> 
> Nice! This fixes the 800Mhz lockup on bootup after a software reset we
> were seeing on the Beagle xM's with v3.7.x/v3.6.x...
> 
> Tested-by: Robert Nelson <robertcnelson@gmail.com>

if this fixes a boot lockup with older kernel, I believe this deserves a
Cc: stable@vger.kernel.org.
diff mbox

Patch

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index e872c8b..c347fd0 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2250,6 +2250,7 @@  int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
 {
 	struct regulator_dev *rdev = regulator->rdev;
 	int ret = 0;
+	int old_min_uV, old_max_uV;
 
 	mutex_lock(&rdev->mutex);
 
@@ -2271,18 +2272,29 @@  int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
 	ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
 	if (ret < 0)
 		goto out;
+	
+	/* restore original values in case of error */
+	old_min_uV = regulator->min_uV;
+	old_max_uV = regulator->max_uV;
 	regulator->min_uV = min_uV;
 	regulator->max_uV = max_uV;
 
 	ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
 	if (ret < 0)
-		goto out;
+		goto out2;
 
 	ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
-
+	if (ret < 0)
+		goto out2;
+	
 out:
 	mutex_unlock(&rdev->mutex);
 	return ret;
+out2:
+	regulator->min_uV = old_min_uV;
+	regulator->max_uV = old_max_uV;
+	mutex_unlock(&rdev->mutex);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(regulator_set_voltage);