* [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps
@ 2012-07-17 3:29 Axel Lin
2012-07-17 8:45 ` Graeme Gregory
2012-07-17 10:08 ` Mark Brown
0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2012-07-17 3:29 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood
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.lin@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 - 500000) / 10000) + 1;
- if (ret < 0)
- return ret;
+ if (min_uV == 0)
+ return 0;
+
+ if (pmic->range[id]) { /* RANGE is x2 */
+ if (min_uV < 1000000)
+ min_uV = 1000000;
+ ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1;
+ } else { /* RANGE is x1 */
+ if (min_uV < 500000)
+ min_uV = 500000;
+ ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1;
+ }
/* Map back into a voltage to verify we're still in bounds */
voltage = palmas_list_voltage_smps(rdev, ret);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps
2012-07-17 3:29 [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps Axel Lin
@ 2012-07-17 8:45 ` Graeme Gregory
2012-07-17 10:08 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Graeme Gregory @ 2012-07-17 8:45 UTC (permalink / raw)
To: Axel Lin; +Cc: Mark Brown, linux-kernel, Liam Girdwood
Good catch, thanks I totally forgot about the range bit in that function.
Acked-by: Graeme Gregory <gg@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.lin@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 - 500000) / 10000) + 1;
> - if (ret < 0)
> - return ret;
> + if (min_uV == 0)
> + return 0;
> +
> + if (pmic->range[id]) { /* RANGE is x2 */
> + if (min_uV < 1000000)
> + min_uV = 1000000;
> + ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1;
> + } else { /* RANGE is x1 */
> + if (min_uV < 500000)
> + min_uV = 500000;
> + ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1;
> + }
>
> /* Map back into a voltage to verify we're still in bounds */
> voltage = palmas_list_voltage_smps(rdev, ret);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps
2012-07-17 3:29 [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps Axel Lin
2012-07-17 8:45 ` Graeme Gregory
@ 2012-07-17 10:08 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2012-07-17 10:08 UTC (permalink / raw)
To: Axel Lin; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 215 bytes --]
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.
[-- 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-07-17 10:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-17 3:29 [PATCH RFT] regulator: palmas: Fix calcuating selector in palmas_map_voltage_smps Axel Lin
2012-07-17 8:45 ` Graeme Gregory
2012-07-17 10:08 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox