Skip to contentSkip to conversation

regulator: ad5398: Fix min/max current limit boundary checking

PATCH Superseded Axel Lin 2 participants 7 messages Jul 3, 2012

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 regulator: ad5398: Fix min/max current limit boundary checking

It is ok to request current limit with min_uA < chip->min_uA and max_uA > chip->max_uA.

---
 drivers/regulator/ad5398.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/regulator/ad5398.c +1 -3
index 46d05f3..6a357dc 100644
@@ -89,9 +89,7 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int
 	unsigned short data;
 	int ret;
 
-	if (min_uA > chip->max_uA || min_uA < chip->min_uA)
-		return -EINVAL;
-	if (max_uA > chip->max_uA || max_uA < chip->min_uA)
+	if (min_uA > chip->max_uA || max_uA < chip->min_uA)
 		return -EINVAL;
 
 	selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level,
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/2 regulator: tps65217: Fix voltage boundary checking in tps65217_pmic_map_voltage

It is ok to request voltage with min_uV < tps->info[rid]->min_uV and max_uV > tps->info[rid]->max_uV

---
 drivers/regulator/tps65217-regulator.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/regulator/tps65217-regulator.c +1 -4
index 0a3df5b..0947a09 100644
@@ -206,10 +206,7 @@ static int tps65217_pmic_map_voltage(struct regulator_dev *dev,
 	if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
 		return -EINVAL;
 
-	if (min_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV)
-		return -EINVAL;
-
-	if (max_uV < tps->info[rid]->min_uV || max_uV > tps->info[rid]->max_uV)
+	if (max_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV)
 		return -EINVAL;
 
 	ret = tps->info[rid]->uv_to_vsel(min_uV, &sel);
Signature · 1 line
1.7.9.5
#2 lore raw

RE: [PATCH 2/2] regulator: tps65217: Fix voltage boundary checking in tps65217_pmic_map_voltage

Hi Axel,

Quoted 13 lines · Axel Lin

It is ok to request voltage with min_uV < tps->info[rid]->min_uV and max_uV > tps->info[rid]->max_uV

---
 drivers/regulator/tps65217-regulator.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/regulator/tps65217-regulator.c +0 -0
index 0a3df5b..0947a09 100644

drivers/regulator/tps65217-regulator.c static int tps65217_pmic_map_voltage(struct regulator_dev *dev, · line 210

Quoted 9 lines
drivers/regulator/tps65217-regulator.c +1 -4
@@ -206,10 +206,7 @@ static int tps65217_pmic_map_voltage(struct regulator_dev *dev,
 	if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
 		return -EINVAL;
 
-	if (min_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV)
-		return -EINVAL;
-
-	if (max_uV < tps->info[rid]->min_uV || max_uV > tps->info[rid]->max_uV)
+	if (max_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV)
 		return -EINVAL;

Case 1:-
------

tps->info[rid]->min_uV = 600000;
tps->info[rid]->max_uV = 1100000;

If we do regulator_set_voltage(reg, 550000, 1100000);

This results into error condition and how can we handle with this?

Case 2:-
------

I think the current code handles this case as well.

There might be a case where board/DT data is false like

tps->info[rid]->min_uV = 1100000;
tps->info[rid]->max_uV = 600000;

regulator_set_voltage(reg, 650000, 1100000);

Regards
AnilKumar

author
#3 lore raw

RE: [PATCH 2/2] regulator: tps65217: Fix voltage boundary checking in tps65217_pmic_map_voltage

Quoted 10 lines

Case 1:-
------

tps->info[rid]->min_uV = 600000;
tps->info[rid]->max_uV = 1100000;

If we do regulator_set_voltage(reg, 550000, 1100000);

This results into error condition and how can we handle with this?

In original code, it returns error. ( I think which is wrong.)

What we want is to set the smallest voltage within the specified voltage range.
With this patch, calling regulator_set_voltage(reg, 550000, 1100000); is the same as calling regulator_set_voltage(reg, 600000, 1100000); It will set the voltage to 600000 uV.

Quoted 11 lines

Case 2:-
------

I think the current code handles this case as well.

There might be a case where board/DT data is false like

tps->info[rid]->min_uV = 1100000;
tps->info[rid]->max_uV = 600000;

I don't get it.
You mean the case min_uV is greater than max_uV?

My understanding of current implementation is that the tps->info[rid]->min_uV and tps->info[rid]->max_uV are not controlled by board/DT data. They are defined in tps65217_pmic_regs[].

Quoted 4 lines

regulator_set_voltage(reg, 650000, 1100000);

Regards
AnilKumar

#4 lore raw

RE: [PATCH 2/2] regulator: tps65217: Fix voltage boundary checking in tps65217_pmic_map_voltage

Quoted 11 lines · Axel Lin
Quoted 10 lines

Case 1:-
------

tps->info[rid]->min_uV = 600000;
tps->info[rid]->max_uV = 1100000;

If we do regulator_set_voltage(reg, 550000, 1100000);

This results into error condition and how can we handle with this?

Quoted 7 lines

In original code, it returns error. ( I think which is wrong.)

What we want is to set the smallest voltage within the specified voltage range.
With this patch, calling regulator_set_voltage(reg, 550000, 1100000); is the same as calling regulator_set_voltage(reg, 600000, 1100000); It will set the voltage to 600000 uV.

Suppose
rdev->constraints->min_uV = 600000; /* wrong data entered by user as DT/plat

						data */

rdev->constraints->max_uV = 1500000;

And tps limits (little modification from my previous mail "actual values")

tps->info[rid]->min_uV = 900000;
tps->info[rid]->max_uV = 1800000;

regulator_set_voltage(reg, 850000, 1100000);

In side tps65217_pmic_map_voltage() we have

tps->info[rid]->uv_to_vsel(850000, &sel) nothing but tps65217_uv_to_vsel1(850000, &sel);

sel = (((850000 - 900000) + (25000) - 1) / (25000)); sel = ((-25001)/(25000));
sel = -1; /* Which is not expected */

Ideally this would be the change

	if (min_uV < tps->info[rid]->min_uV)
		min_uV = tps->info[rid]->min_uV;

	if (max_uV > tps->info[rid]->max_uV)
		max_uV = tps->info[rid]->max_uV;

	if (max_uV < tps->info[rid]->min_uV ||
			min_uV > tps->info[rid]->max_uV)
		return -EINVAL;

If this is not the case then I am completely in a wrong direction.

Quoted 12 lines
Quoted 5 lines

Case 2:-
------

Quoted 7 lines

I think the current code handles this case as well.

There might be a case where board/DT data is false like

tps->info[rid]->min_uV = 1100000;
tps->info[rid]->max_uV = 600000;

Quoted 6 lines

I don't get it.
You mean the case min_uV is greater than max_uV?

My understanding of current implementation is that the tps->info[rid]->min_uV and tps->info[rid]->max_uV are not controlled by board/DT data. They are defined in tps65217_pmic_regs[].

My point here is rdev->constraints->min_uV and rdev->constraints->max_uV values set from DT/board file. Sorry about the confusion. This case is taken care by regulator core.

Regards
AnilKumar

author
#5 lore raw

RE: [PATCH 2/2] regulator: tps65217: Fix voltage boundary checking in tps65217_pmic_map_voltage

Quoted 6 lines

In side tps65217_pmic_map_voltage() we have

tps->info[rid]->uv_to_vsel(850000, &sel) nothing but tps65217_uv_to_vsel1(850000, &sel);

Quoted 9 lines

sel = (((850000 - 900000) + (25000) - 1) / (25000)); sel = ((-25001)/(25000));
sel = -1; /* Which is not expected */

Ideally this would be the change

	if (min_uV < tps->info[rid]->min_uV)
		min_uV = tps->info[rid]->min_uV;

ok. I got your point now.

So if min_uV < tps->info[rid]->min_uV, we need to set
min_uV = tps->info[rid]->min_uV.
This is because the equation we used in uv_to_vsel() does not allow min_uV < tps->info[rid]->min_uV, otherwise it returns negative selector.

Quoted 2 lines
	if (max_uV > tps->info[rid]->max_uV)
		max_uV = tps->info[rid]->max_uV;

This looks not necessary. the equation in uv_to_vsel() does not use max_uV.

Quoted 6 lines
	if (max_uV < tps->info[rid]->min_uV ||
			min_uV > tps->info[rid]->max_uV)
		return -EINVAL;

If this is not the case then I am completely in a wrong direction.

You are right in this case. I'll send a v2 for review.

Thanks for the review,
Axel

#6 lore raw

RE: [PATCH 2/2] regulator: tps65217: Fix voltage boundary checking in tps65217_pmic_map_voltage

Quoted 23 lines · Axel Lin
Quoted 6 lines

In side tps65217_pmic_map_voltage() we have

tps->info[rid]->uv_to_vsel(850000, &sel) nothing but tps65217_uv_to_vsel1(850000, &sel);

Quoted 9 lines

sel = (((850000 - 900000) + (25000) - 1) / (25000)); sel = ((-25001)/(25000));
sel = -1; /* Which is not expected */

Ideally this would be the change

	if (min_uV < tps->info[rid]->min_uV)
		min_uV = tps->info[rid]->min_uV;

ok. I got your point now.

So if min_uV < tps->info[rid]->min_uV, we need to set
min_uV = tps->info[rid]->min_uV.
This is because the equation we used in uv_to_vsel() does not allow min_uV < tps->info[rid]->min_uV, otherwise it returns negative selector.

Quoted 6 lines
Quoted 2 lines
	if (max_uV > tps->info[rid]->max_uV)
		max_uV = tps->info[rid]->max_uV;

This looks not necessary. the equation in uv_to_vsel() does not use max_uV.

Yes, I agree.

Regards
AnilKumar