linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: Simplify the code to get selector in isl6271a_set_voltage
@ 2012-03-02  1:19 Axel Lin
  2012-03-02 10:13 ` Marek Vasut
  2012-03-02 11:23 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2012-03-02  1:19 UTC (permalink / raw)
  To: linux-kernel; +Cc: Marek Vasut, Liam Girdwood, Mark Brown

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/isl6271a-regulator.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index c1a456c..775f5fd 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -63,23 +63,15 @@ static int isl6271a_set_voltage(struct regulator_dev *dev,
 				unsigned *selector)
 {
 	struct isl_pmic *pmic = rdev_get_drvdata(dev);
-	int vsel, err, data;
+	int err, data;
 
 	if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX)
 		return -EINVAL;
 	if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX)
 		return -EINVAL;
 
-	/* Align to 50000 mV */
-	vsel = minuV - (minuV % ISL6271A_VOLTAGE_STEP);
-
-	/* If the result fell out of [minuV,maxuV] range, put it back */
-	if (vsel < minuV)
-		vsel += ISL6271A_VOLTAGE_STEP;
-
-	/* Convert the microvolts to data for the chip */
-	data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP;
-
+	data = DIV_ROUND_UP(minuV - ISL6271A_VOLTAGE_MIN,
+			    ISL6271A_VOLTAGE_STEP);
 	*selector = data;
 
 	mutex_lock(&pmic->mtx);
-- 
1.7.5.4




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

* Re: [PATCH] regulator: Simplify the code to get selector in isl6271a_set_voltage
  2012-03-02  1:19 [PATCH] regulator: Simplify the code to get selector in isl6271a_set_voltage Axel Lin
@ 2012-03-02 10:13 ` Marek Vasut
  2012-03-02 11:23 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Vasut @ 2012-03-02 10:13 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Liam Girdwood, Mark Brown

> Signed-off-by: Axel Lin <axel.lin@gmail.com>
> ---
>  drivers/regulator/isl6271a-regulator.c |   14 +++-----------
>  1 files changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/regulator/isl6271a-regulator.c
> b/drivers/regulator/isl6271a-regulator.c index c1a456c..775f5fd 100644
> --- a/drivers/regulator/isl6271a-regulator.c
> +++ b/drivers/regulator/isl6271a-regulator.c
> @@ -63,23 +63,15 @@ static int isl6271a_set_voltage(struct regulator_dev
> *dev, unsigned *selector)
>  {
>  	struct isl_pmic *pmic = rdev_get_drvdata(dev);
> -	int vsel, err, data;
> +	int err, data;
> 
>  	if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX)
>  		return -EINVAL;
>  	if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX)
>  		return -EINVAL;
> 
> -	/* Align to 50000 mV */

Heh ... 50000mV ? :-)

> -	vsel = minuV - (minuV % ISL6271A_VOLTAGE_STEP);
> -
> -	/* If the result fell out of [minuV,maxuV] range, put it back */
> -	if (vsel < minuV)
> -		vsel += ISL6271A_VOLTAGE_STEP;
> -
> -	/* Convert the microvolts to data for the chip */
> -	data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP;
> -
> +	data = DIV_ROUND_UP(minuV - ISL6271A_VOLTAGE_MIN,
> +			    ISL6271A_VOLTAGE_STEP);

Ok, this makes sense.

Acked-by: Marek Vasut <marek.vasut@gmail.com>

>  	*selector = data;
> 
>  	mutex_lock(&pmic->mtx);

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

* Re: [PATCH] regulator: Simplify the code to get selector in isl6271a_set_voltage
  2012-03-02  1:19 [PATCH] regulator: Simplify the code to get selector in isl6271a_set_voltage Axel Lin
  2012-03-02 10:13 ` Marek Vasut
@ 2012-03-02 11:23 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2012-03-02 11:23 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Marek Vasut, Liam Girdwood

[-- Attachment #1: Type: text/plain, Size: 123 bytes --]

On Fri, Mar 02, 2012 at 09:19:02AM +0800, Axel Lin wrote:
> Signed-off-by: Axel Lin <axel.lin@gmail.com>

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2012-03-02 11:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-02  1:19 [PATCH] regulator: Simplify the code to get selector in isl6271a_set_voltage Axel Lin
2012-03-02 10:13 ` Marek Vasut
2012-03-02 11:23 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).