All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage()
@ 2012-07-14  5:37 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
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Axel Lin @ 2012-07-14  5:37 UTC (permalink / raw)
  To: Mark Brown; +Cc: Rajendra Nayak, Peter Ujfalusi, Liam Girdwood, linux-kernel

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,
-- 
1.7.9.5




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

* [PATCH RFT 2/2] regulator: twl: Convert twlsmps_ops to get_voltage_sel and map_voltage
  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 ` Axel Lin
  2012-07-16  9:25   ` Rajendra Nayak
  2012-07-16  9:25 ` [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage() Rajendra Nayak
  2012-08-01 19:57 ` Mark Brown
  2 siblings, 1 reply; 5+ messages in thread
From: Axel Lin @ 2012-07-14  5:41 UTC (permalink / raw)
  To: Mark Brown; +Cc: Rajendra Nayak, Peter Ujfalusi, Liam Girdwood, linux-kernel

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/twl-regulator.c |   24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 03d0bea..8dae1e3 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -755,12 +755,11 @@ static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
 	return voltage;
 }
 
-static int
-twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
-			unsigned int *selector)
+static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV,
+				   int max_uV)
 {
-	struct twlreg_info	*info = rdev_get_drvdata(rdev);
-	int vsel = 0, calc_uV;
+	struct twlreg_info *info = rdev_get_drvdata(rdev);
+	int vsel = 0;
 
 	switch (info->flags) {
 	case 0:
@@ -827,14 +826,16 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
 		break;
 	}
 
-	calc_uV = twl6030smps_list_voltage(rdev, vsel);
-	if (calc_uV > max_uV)
-		return -EINVAL;
+	return vsel;
+}
 
-	*selector = vsel;
+static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev,
+				       unsigned int selector)
+{
+	struct twlreg_info *info = rdev_get_drvdata(rdev);
 
 	return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
-							vsel);
+			    selector);
 }
 
 static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
@@ -846,8 +847,9 @@ static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
 
 static struct regulator_ops twlsmps_ops = {
 	.list_voltage		= twl6030smps_list_voltage,
+	.map_voltage		= twl6030smps_map_voltage,
 
-	.set_voltage		= twl6030smps_set_voltage,
+	.set_voltage_sel	= twl6030smps_set_voltage_sel,
 	.get_voltage_sel	= twl6030smps_get_voltage_sel,
 
 	.enable			= twl6030reg_enable,
-- 
1.7.9.5




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

* Re: [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage()
  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-08-01 19:57 ` Mark Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Rajendra Nayak @ 2012-07-16  9:25 UTC (permalink / raw)
  To: Axel Lin
  Cc: Mark Brown, Peter Ujfalusi, Liam Girdwood, LKML, Graeme Gregory, loml

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,


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

* Re: [PATCH RFT 2/2] regulator: twl: Convert twlsmps_ops to get_voltage_sel and map_voltage
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Rajendra Nayak @ 2012-07-16  9:25 UTC (permalink / raw)
  To: Axel Lin
  Cc: Mark Brown, Peter Ujfalusi, Liam Girdwood, linux-kernel,
	Graeme Gregory, loml

Copying Graeme and linux-omap list.

On Saturday 14 July 2012 11:11 AM, Axel Lin wrote:
> Signed-off-by: Axel Lin<axel.lin@gmail.com>
> ---
>   drivers/regulator/twl-regulator.c |   24 +++++++++++++-----------
>   1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
> index 03d0bea..8dae1e3 100644
> --- a/drivers/regulator/twl-regulator.c
> +++ b/drivers/regulator/twl-regulator.c
> @@ -755,12 +755,11 @@ static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
>   	return voltage;
>   }
>
> -static int
> -twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
> -			unsigned int *selector)
> +static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV,
> +				   int max_uV)
>   {
> -	struct twlreg_info	*info = rdev_get_drvdata(rdev);
> -	int vsel = 0, calc_uV;
> +	struct twlreg_info *info = rdev_get_drvdata(rdev);
> +	int vsel = 0;
>
>   	switch (info->flags) {
>   	case 0:
> @@ -827,14 +826,16 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
>   		break;
>   	}
>
> -	calc_uV = twl6030smps_list_voltage(rdev, vsel);
> -	if (calc_uV>  max_uV)
> -		return -EINVAL;
> +	return vsel;
> +}
>
> -	*selector = vsel;
> +static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev,
> +				       unsigned int selector)
> +{
> +	struct twlreg_info *info = rdev_get_drvdata(rdev);
>
>   	return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
> -							vsel);
> +			    selector);
>   }
>
>   static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
> @@ -846,8 +847,9 @@ static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
>
>   static struct regulator_ops twlsmps_ops = {
>   	.list_voltage		= twl6030smps_list_voltage,
> +	.map_voltage		= twl6030smps_map_voltage,
>
> -	.set_voltage		= twl6030smps_set_voltage,
> +	.set_voltage_sel	= twl6030smps_set_voltage_sel,
>   	.get_voltage_sel	= twl6030smps_get_voltage_sel,
>
>   	.enable			= twl6030reg_enable,


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

* Re: [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage()
  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 ` [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage() Rajendra Nayak
@ 2012-08-01 19:57 ` Mark Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2012-08-01 19:57 UTC (permalink / raw)
  To: Axel Lin; +Cc: Rajendra Nayak, Peter Ujfalusi, Liam Girdwood, linux-kernel

On Sat, Jul 14, 2012 at 01:37:13PM +0800, 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.

Applied both, thanks.

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

end of thread, other threads:[~2012-08-01 19:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH RFT 1/2] regulator: twl: Fix checking voltage range in twl6030smps_set_voltage() Rajendra Nayak
2012-08-01 19:57 ` Mark Brown

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.