All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rajendra Nayak <rnayak@ti.com>
To: Axel Lin <axel.lin@gmail.com>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Liam Girdwood <lrg@ti.com>, LKML <linux-kernel@vger.kernel.org>,
	Graeme Gregory <gg@slimlogic.co.uk>,
	loml <linux-omap@vger.kernel.org>
Subject: Re: [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage()
Date: Mon, 16 Jul 2012 14:55:15 +0530	[thread overview]
Message-ID: <5003DDFB.2090102@ti.com> (raw)
In-Reply-To: <1342244233.4207.1.camel@phoenix>

Copying Graeme and linux-omap list.

On Saturday 14 July 2012 11:07 AM, Axel Lin wrote:
> The voltage selection logic is supposed to find the samllest voltage falls
> within specified range. When using equation to calculate vsel, we need to
> ensure the requested min_uV meet the range of using the equation.
> Otherwise we may select a voltage that is out of specified range.
>
> For example, in the case vsel = 62 means select voltage of 2100000uV.
> What we want is to ensure the requested min_uV<= 2100000 rather than checking
> max_uV>= 2100000. And this also means in the case min_uV>  2100000, vsel = 62
> does not meet the request.
>
> Also calling twl6030smps_list_voltage() for all cases to ensure the selected
> voltage still in bounds.
>
> Signed-off-by: Axel Lin<axel.lin@gmail.com>
> ---
>   drivers/regulator/twl-regulator.c |   36 ++++++++++++++++--------------------
>   1 file changed, 16 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
> index 8f0bd56..03d0bea 100644
> --- a/drivers/regulator/twl-regulator.c
> +++ b/drivers/regulator/twl-regulator.c
> @@ -760,32 +760,28 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
>   			unsigned int *selector)
>   {
>   	struct twlreg_info	*info = rdev_get_drvdata(rdev);
> -	int	vsel = 0;
> +	int vsel = 0, calc_uV;
>
>   	switch (info->flags) {
>   	case 0:
>   		if (min_uV == 0)
>   			vsel = 0;
>   		else if ((min_uV>= 600000)&&  (min_uV<= 1300000)) {
> -			int calc_uV;
>   			vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
>   			vsel++;
> -			calc_uV = twl6030smps_list_voltage(rdev, vsel);
> -			if (calc_uV>  max_uV)
> -				return -EINVAL;
>   		}
>   		/* Values 1..57 for vsel are linear and can be calculated
>   		 * values 58..62 are non linear.
>   		 */
> -		else if ((min_uV>  1900000)&&  (max_uV>= 2100000))
> +		else if ((min_uV>  1900000)&&  (min_uV<= 2100000))
>   			vsel = 62;
> -		else if ((min_uV>  1800000)&&  (max_uV>= 1900000))
> +		else if ((min_uV>  1800000)&&  (min_uV<= 1900000))
>   			vsel = 61;
> -		else if ((min_uV>  1500000)&&  (max_uV>= 1800000))
> +		else if ((min_uV>  1500000)&&  (min_uV<= 1800000))
>   			vsel = 60;
> -		else if ((min_uV>  1350000)&&  (max_uV>= 1500000))
> +		else if ((min_uV>  1350000)&&  (min_uV<= 1500000))
>   			vsel = 59;
> -		else if ((min_uV>  1300000)&&  (max_uV>= 1350000))
> +		else if ((min_uV>  1300000)&&  (min_uV<= 1350000))
>   			vsel = 58;
>   		else
>   			return -EINVAL;
> @@ -794,25 +790,21 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
>   		if (min_uV == 0)
>   			vsel = 0;
>   		else if ((min_uV>= 700000)&&  (min_uV<= 1420000)) {
> -			int calc_uV;
>   			vsel = DIV_ROUND_UP(min_uV - 700000, 12500);
>   			vsel++;
> -			calc_uV = twl6030smps_list_voltage(rdev, vsel);
> -			if (calc_uV>  max_uV)
> -				return -EINVAL;
>   		}
>   		/* Values 1..57 for vsel are linear and can be calculated
>   		 * values 58..62 are non linear.
>   		 */
> -		else if ((min_uV>  1900000)&&  (max_uV>= 2100000))
> +		else if ((min_uV>  1900000)&&  (min_uV<= 2100000))
>   			vsel = 62;
> -		else if ((min_uV>  1800000)&&  (max_uV>= 1900000))
> +		else if ((min_uV>  1800000)&&  (min_uV<= 1900000))
>   			vsel = 61;
> -		else if ((min_uV>  1350000)&&  (max_uV>= 1800000))
> +		else if ((min_uV>  1350000)&&  (min_uV<= 1800000))
>   			vsel = 60;
> -		else if ((min_uV>  1350000)&&  (max_uV>= 1500000))
> +		else if ((min_uV>  1350000)&&  (min_uV<= 1500000))
>   			vsel = 59;
> -		else if ((min_uV>  1300000)&&  (max_uV>= 1350000))
> +		else if ((min_uV>  1300000)&&  (min_uV<= 1350000))
>   			vsel = 58;
>   		else
>   			return -EINVAL;
> @@ -828,13 +820,17 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
>   	case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
>   		if (min_uV == 0) {
>   			vsel = 0;
> -		} else if ((min_uV>= 2161000)&&  (max_uV<= 4321000)) {
> +		} else if ((min_uV>= 2161000)&&  (min_uV<= 4321000)) {
>   			vsel = DIV_ROUND_UP(min_uV - 2161000, 38600);
>   			vsel++;
>   		}
>   		break;
>   	}
>
> +	calc_uV = twl6030smps_list_voltage(rdev, vsel);
> +	if (calc_uV>  max_uV)
> +		return -EINVAL;
> +
>   	*selector = vsel;
>
>   	return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,


  parent reply	other threads:[~2012-07-16  9:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-14  5:37 [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage() Axel Lin
2012-07-14  5:41 ` [PATCH RFT 2/2] regulator: twl: Convert twlsmps_ops to get_voltage_sel and map_voltage Axel Lin
2012-07-16  9:25   ` Rajendra Nayak
2012-07-16  9:25 ` Rajendra Nayak [this message]
2012-08-01 19:57 ` [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage() Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5003DDFB.2090102@ti.com \
    --to=rnayak@ti.com \
    --cc=axel.lin@gmail.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=gg@slimlogic.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=lrg@ti.com \
    --cc=peter.ujfalusi@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.