Re: [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps

2012-07-17 Thread Mark Brown
On Tue, Jul 17, 2012 at 11:29:03AM +0800, Axel Lin wrote:
> The logic of calculating selector in palmas_map_voltage_smps() does not match
> the logic to list voltage in palmas_list_voltage_smps().

Applied, thanks.


signature.asc
Description: Digital signature


Re: [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps

2012-07-17 Thread Graeme Gregory
Good catch, thanks I totally forgot about the range bit in that function.

Acked-by: Graeme Gregory 

On 17/07/12 04:29, Axel Lin wrote:
> The logic of calculating selector in palmas_map_voltage_smps() does not match
> the logic to list voltage in palmas_list_voltage_smps().
>
> We use below equation to calculate voltage when selector > 0:
> voltage = (0.49V + (selector * 0.01V)) * RANGE
> RANGE is either x1 or x2
>
> So we need to take into account with the multiplier set in VSEL register when
> calculating selector in palmas_map_voltage_smps()
>
> Signed-off-by: Axel Lin 
> ---
>  drivers/regulator/palmas-regulator.c |   17 ++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/regulator/palmas-regulator.c 
> b/drivers/regulator/palmas-regulator.c
> index 7540c95..17d19fb 100644
> --- a/drivers/regulator/palmas-regulator.c
> +++ b/drivers/regulator/palmas-regulator.c
> @@ -373,11 +373,22 @@ static int palmas_set_voltage_smps_sel(struct 
> regulator_dev *dev,
>  static int palmas_map_voltage_smps(struct regulator_dev *rdev,
>   int min_uV, int max_uV)
>  {
> + struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
> + int id = rdev_get_id(rdev);
>   int ret, voltage;
>  
> - ret = ((min_uV - 50) / 1) + 1;
> - if (ret < 0)
> - return ret;
> + if (min_uV == 0)
> + return 0;
> +
> + if (pmic->range[id]) { /* RANGE is x2 */
> + if (min_uV < 100)
> + min_uV = 100;
> + ret = DIV_ROUND_UP(min_uV - 100, 2) + 1;
> + } else {/* RANGE is x1 */
> + if (min_uV < 50)
> + min_uV = 50;
> + ret = DIV_ROUND_UP(min_uV - 50, 1) + 1;
> + }
>  
>   /* Map back into a voltage to verify we're still in bounds */
>   voltage = palmas_list_voltage_smps(rdev, ret);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps

2012-07-17 Thread Graeme Gregory
Good catch, thanks I totally forgot about the range bit in that function.

Acked-by: Graeme Gregory g...@slimlogic.co.uk

On 17/07/12 04:29, Axel Lin wrote:
 The logic of calculating selector in palmas_map_voltage_smps() does not match
 the logic to list voltage in palmas_list_voltage_smps().

 We use below equation to calculate voltage when selector  0:
 voltage = (0.49V + (selector * 0.01V)) * RANGE
 RANGE is either x1 or x2

 So we need to take into account with the multiplier set in VSEL register when
 calculating selector in palmas_map_voltage_smps()

 Signed-off-by: Axel Lin axel@gmail.com
 ---
  drivers/regulator/palmas-regulator.c |   17 ++---
  1 file changed, 14 insertions(+), 3 deletions(-)

 diff --git a/drivers/regulator/palmas-regulator.c 
 b/drivers/regulator/palmas-regulator.c
 index 7540c95..17d19fb 100644
 --- a/drivers/regulator/palmas-regulator.c
 +++ b/drivers/regulator/palmas-regulator.c
 @@ -373,11 +373,22 @@ static int palmas_set_voltage_smps_sel(struct 
 regulator_dev *dev,
  static int palmas_map_voltage_smps(struct regulator_dev *rdev,
   int min_uV, int max_uV)
  {
 + struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
 + int id = rdev_get_id(rdev);
   int ret, voltage;
  
 - ret = ((min_uV - 50) / 1) + 1;
 - if (ret  0)
 - return ret;
 + if (min_uV == 0)
 + return 0;
 +
 + if (pmic-range[id]) { /* RANGE is x2 */
 + if (min_uV  100)
 + min_uV = 100;
 + ret = DIV_ROUND_UP(min_uV - 100, 2) + 1;
 + } else {/* RANGE is x1 */
 + if (min_uV  50)
 + min_uV = 50;
 + ret = DIV_ROUND_UP(min_uV - 50, 1) + 1;
 + }
  
   /* Map back into a voltage to verify we're still in bounds */
   voltage = palmas_list_voltage_smps(rdev, ret);


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps

2012-07-17 Thread Mark Brown
On Tue, Jul 17, 2012 at 11:29:03AM +0800, Axel Lin wrote:
 The logic of calculating selector in palmas_map_voltage_smps() does not match
 the logic to list voltage in palmas_list_voltage_smps().

Applied, thanks.


signature.asc
Description: Digital signature


[PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps

2012-07-16 Thread Axel Lin
The logic of calculating selector in palmas_map_voltage_smps() does not match
the logic to list voltage in palmas_list_voltage_smps().

We use below equation to calculate voltage when selector > 0:
voltage = (0.49V + (selector * 0.01V)) * RANGE
RANGE is either x1 or x2

So we need to take into account with the multiplier set in VSEL register when
calculating selector in palmas_map_voltage_smps()

Signed-off-by: Axel Lin 
---
 drivers/regulator/palmas-regulator.c |   17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c 
b/drivers/regulator/palmas-regulator.c
index 7540c95..17d19fb 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -373,11 +373,22 @@ static int palmas_set_voltage_smps_sel(struct 
regulator_dev *dev,
 static int palmas_map_voltage_smps(struct regulator_dev *rdev,
int min_uV, int max_uV)
 {
+   struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
+   int id = rdev_get_id(rdev);
int ret, voltage;
 
-   ret = ((min_uV - 50) / 1) + 1;
-   if (ret < 0)
-   return ret;
+   if (min_uV == 0)
+   return 0;
+
+   if (pmic->range[id]) { /* RANGE is x2 */
+   if (min_uV < 100)
+   min_uV = 100;
+   ret = DIV_ROUND_UP(min_uV - 100, 2) + 1;
+   } else {/* RANGE is x1 */
+   if (min_uV < 50)
+   min_uV = 50;
+   ret = DIV_ROUND_UP(min_uV - 50, 1) + 1;
+   }
 
/* Map back into a voltage to verify we're still in bounds */
voltage = palmas_list_voltage_smps(rdev, ret);
-- 
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps

2012-07-16 Thread Axel Lin
The logic of calculating selector in palmas_map_voltage_smps() does not match
the logic to list voltage in palmas_list_voltage_smps().

We use below equation to calculate voltage when selector  0:
voltage = (0.49V + (selector * 0.01V)) * RANGE
RANGE is either x1 or x2

So we need to take into account with the multiplier set in VSEL register when
calculating selector in palmas_map_voltage_smps()

Signed-off-by: Axel Lin axel@gmail.com
---
 drivers/regulator/palmas-regulator.c |   17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c 
b/drivers/regulator/palmas-regulator.c
index 7540c95..17d19fb 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -373,11 +373,22 @@ static int palmas_set_voltage_smps_sel(struct 
regulator_dev *dev,
 static int palmas_map_voltage_smps(struct regulator_dev *rdev,
int min_uV, int max_uV)
 {
+   struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
+   int id = rdev_get_id(rdev);
int ret, voltage;
 
-   ret = ((min_uV - 50) / 1) + 1;
-   if (ret  0)
-   return ret;
+   if (min_uV == 0)
+   return 0;
+
+   if (pmic-range[id]) { /* RANGE is x2 */
+   if (min_uV  100)
+   min_uV = 100;
+   ret = DIV_ROUND_UP(min_uV - 100, 2) + 1;
+   } else {/* RANGE is x1 */
+   if (min_uV  50)
+   min_uV = 50;
+   ret = DIV_ROUND_UP(min_uV - 50, 1) + 1;
+   }
 
/* Map back into a voltage to verify we're still in bounds */
voltage = palmas_list_voltage_smps(rdev, ret);
-- 
1.7.9.5



--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/