Skip to contentSkip to conversation

regulator: rt6160: Convert to use regulator_set_ramp_delay_regmap

PATCH In review Axel Lin 3 participants 12 messages Jun 3, 2021 – Jun 14, 2021 3 messages not in the archive Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: rt6160: Convert to use regulator_set_ramp_delay_regmap

Use regulator_set_ramp_delay_regmap instead of open-coded.

---
 drivers/regulator/rt6160-regulator.c | 35 +++++++---------------------
 1 file changed, 9 insertions(+), 26 deletions(-)
drivers/regulator/rt6160-regulator.c +9 -26
index 4588ae0748a5..69550284083d 100644
@@ -46,6 +46,10 @@ struct rt6160_priv {
 	bool enable_state;
 };
 
+static const unsigned int rt6160_ramp_tables[] = {
+	1000, 2500, 5000, 10000
+};
+
 static int rt6160_enable(struct regulator_dev *rdev)
 {
 	struct rt6160_priv *priv = rdev_get_drvdata(rdev);
@@ -140,31 +144,6 @@ static int rt6160_set_suspend_voltage(struct regulator_dev *rdev, int uV)
 	return regmap_update_bits(regmap, reg, RT6160_VSEL_MASK, vsel);
 }
 
-static int rt6160_set_ramp_delay(struct regulator_dev *rdev, int target)
-{
-	struct regmap *regmap = rdev_get_regmap(rdev);
-	const int ramp_tables[] = { 1000, 2500, 5000, 10000 };
-	unsigned int i, sel;
-
-	/* Find closest larger or equal */
-	for (i = 0; i < ARRAY_SIZE(ramp_tables); i++) {
-		sel = i;
-
-		/* If ramp delay is equal to 0, directly set ramp speed to fastest */
-		if (target == 0) {
-			sel = ARRAY_SIZE(ramp_tables) - 1;
-			break;
-		}
-
-		if (target <= ramp_tables[i])
-			break;
-	}
-
-	sel <<= ffs(RT6160_RAMPRATE_MASK) - 1;
-
-	return regmap_update_bits(regmap, RT6160_REG_CNTL, RT6160_RAMPRATE_MASK, sel);
-}
-
 static int rt6160_get_error_flags(struct regulator_dev *rdev, unsigned int *flags)
 {
 	struct regmap *regmap = rdev_get_regmap(rdev);
@@ -203,7 +182,7 @@ static const struct regulator_ops rt6160_regulator_ops = {
 	.set_mode = rt6160_set_mode,
 	.get_mode = rt6160_get_mode,
 	.set_suspend_voltage = rt6160_set_suspend_voltage,
-	.set_ramp_delay = rt6160_set_ramp_delay,
+	.set_ramp_delay = regulator_set_ramp_delay_regmap,
 	.get_error_flags = rt6160_get_error_flags,
 };
 
@@ -292,6 +271,10 @@ static int rt6160_probe(struct i2c_client *i2c)
 	priv->desc.vsel_reg = RT6160_REG_VSELH;
 	priv->desc.vsel_mask = RT6160_VSEL_MASK;
 	priv->desc.n_voltages = RT6160_N_VOUTS;
+	priv->desc.ramp_reg = RT6160_REG_CNTL;
+	priv->desc.ramp_mask = RT6160_RAMPRATE_MASK;
+	priv->desc.ramp_delay_table = rt6160_ramp_tables;
+	priv->desc.n_ramp_values = ARRAY_SIZE(rt6160_ramp_tables);
 	priv->desc.of_map_mode = rt6160_of_map_mode;
 	priv->desc.ops = &rt6160_regulator_ops;
 	if (priv->vsel_active_low)
Signature · 1 line
2.25.1
#1 lore raw

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

Quoted 1 line

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small. It conflicts with find_closest_bigger value chosen logic.

That's why I need hard-coded for my ramp value selection.

Quoted 67 lines
---
 drivers/regulator/rt6160-regulator.c | 35 +++++++---------------------
 1 file changed, 9 insertions(+), 26 deletions(-)
drivers/regulator/rt6160- renamed from drivers/regulator/rt6160-regulator.c +0 -0

regulator.c
index 4588ae0748a5..69550284083d 100644

drivers/regulator/rt6160-regulator.c +4 -11
@@ -46,6 +46,10 @@ struct rt6160_priv {
 bool enable_state;
 };
 
+static const unsigned int rt6160_ramp_tables[] = {
+1000, 2500, 5000, 10000
+};
+
 static int rt6160_enable(struct regulator_dev *rdev)
 {
 struct rt6160_priv *priv = rdev_get_drvdata(rdev);
@@ -140,31 +144,6 @@ static int rt6160_set_suspend_voltage(struct
 regulator_dev *rdev, int uV)
 return regmap_update_bits(regmap, reg, RT6160_VSEL_MASK, vsel);
 }
 
-static int rt6160_set_ramp_delay(struct regulator_dev *rdev, int target)
-{
-struct regmap *regmap = rdev_get_regmap(rdev);
-const int ramp_tables[] = { 1000, 2500, 5000, 10000 };
-unsigned int i, sel;
-
-/* Find closest larger or equal */
-for (i = 0; i < ARRAY_SIZE(ramp_tables); i++) {
-sel = i;
-
-/* If ramp delay is equal to 0, directly set ramp speed to

fastest */

drivers/regulator/rt6160-regulator.c +0 -12
-if (target == 0) {
-sel = ARRAY_SIZE(ramp_tables) - 1;
-break;
-}
-
-if (target <= ramp_tables[i])
-break;
-}
-
-sel <<= ffs(RT6160_RAMPRATE_MASK) - 1;
-
-return regmap_update_bits(regmap, RT6160_REG_CNTL,

RT6160_RAMPRATE_MASK, sel);

drivers/regulator/rt6160-regulator.c +0 -2
-}
-
 static int rt6160_get_error_flags(struct regulator_dev *rdev, unsigned int

*flags)
{
struct regmap *regmap = rdev_get_regmap(rdev);

drivers/regulator/rt6160-regulator.c +1 -1
@@ -203,7 +182,7 @@ static const struct regulator_ops rt6160_regulator_ops = {
 .set_mode = rt6160_set_mode,
 .get_mode = rt6160_get_mode,
 .set_suspend_voltage = rt6160_set_suspend_voltage,
-.set_ramp_delay = rt6160_set_ramp_delay,
+.set_ramp_delay = regulator_set_ramp_delay_regmap,
 .get_error_flags = rt6160_get_error_flags,
 };
 

drivers/regulator/rt6160-regulator.c static int rt6160_probe(struct i2c_client *i2c) · line 280

Quoted 10 lines
drivers/regulator/rt6160-regulator.c +4 -0
@@ -292,6 +271,10 @@ static int rt6160_probe(struct i2c_client *i2c)
 priv->desc.vsel_reg = RT6160_REG_VSELH;
 priv->desc.vsel_mask = RT6160_VSEL_MASK;
 priv->desc.n_voltages = RT6160_N_VOUTS;
+priv->desc.ramp_reg = RT6160_REG_CNTL;
+priv->desc.ramp_mask = RT6160_RAMPRATE_MASK;
+priv->desc.ramp_delay_table = rt6160_ramp_tables;
+priv->desc.n_ramp_values = ARRAY_SIZE(rt6160_ramp_tables);
 priv->desc.of_map_mode = rt6160_of_map_mode;
 priv->desc.ops = &rt6160_regulator_ops;
 if (priv->vsel_active_low)

************* Email Confidentiality Notice ********************

The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!

author
#2 lore raw

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Quoted 8 lines

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

Quoted 1 line

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small. It conflicts with find_closest_bigger value chosen logic.

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Thanks,
Axel

#3 lore raw
Quoted 9 lines

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Quoted 8 lines

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

Quoted 2 lines

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

Quoted 8 lines
Quoted 3 lines

It's because our ramp value order is from small to large, not large to small.
It conflicts with find_closest_bigger value chosen logic.

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Sure.

Quoted 3 lines

Thanks,
Axel

************* Email Confidentiality Notice ********************

The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!

author
#4 lore raw

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:41寫道:

Quoted 13 lines
Quoted 13 lines

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Quoted 11 lines

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

Quoted 2 lines

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small.
It conflicts with find_closest_bigger value chosen logic.

Quoted 6 lines
Quoted 5 lines

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Sure.

The find_closest_bigger() does not rely on ascending or descending table entries.
Regards,
Axel

#5 lore raw
In reply to cy_huang(黃啟原)

Hi,> >

Quoted 14 lines
Quoted 14 lines

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Quoted 13 lines

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

Quoted 3 lines

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small.
It conflicts with find_closest_bigger value chosen logic.

Quoted 6 lines
Quoted 5 lines

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Sure.

After my test sample code, below's the result.
ascending [1000 2500 5000 10000]

target =  1000 =>sel = 0
target =  2500 =>sel = 1
target =  5000 =>sel = 2
target = 10000 =>sel = 3
target =  1700 =>sel = 1
target =  2750 =>sel = 2
target =  7500 =>sel = 3
target = 15000 =>failed to find best select, sel = 3
target =     0 =>sel = 0
descending [10000 5000 2500 1000]
target =  1000 =>sel = 3
target =  2500 =>sel = 2
target =  5000 =>sel = 1
target = 10000 =>sel = 0
target =  1700 =>sel = 2
target =  2750 =>sel = 1
target =  7500 =>sel = 0

target = 15000 =>failed to find best select, sel = 0
target = 0 =>sel = 3

It means when target is in range or even over, the result are all correct.
But like as the ramp target is equal to 0, the selection will only choose the minimum one. When the ramp target is equal to 0, it means the user want to disable the rammpping function.

As I know, if target is equal to 0, it must find the fastest rampping value as the best selection.

Quoted 4 lines
Quoted 4 lines

Thanks,
Axel

************* Email Confidentiality Notice ********************

The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!

author
#6 lore raw

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午11:18寫道:

Quoted 45 lines

Hi,> >

Quoted 14 lines
Quoted 14 lines

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Quoted 13 lines

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

Quoted 3 lines

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small.
It conflicts with find_closest_bigger value chosen logic.

Quoted 6 lines
Quoted 5 lines

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Sure.

After my test sample code, below's the result.
ascending [1000 2500 5000 10000]

target =  1000 =>sel = 0
target =  2500 =>sel = 1
target =  5000 =>sel = 2
target = 10000 =>sel = 3
target =  1700 =>sel = 1
target =  2750 =>sel = 2
target =  7500 =>sel = 3
target = 15000 =>failed to find best select, sel = 3
target =     0 =>sel = 0
descending [10000 5000 2500 1000]
target =  1000 =>sel = 3
target =  2500 =>sel = 2
target =  5000 =>sel = 1
target = 10000 =>sel = 0
target =  1700 =>sel = 2
target =  2750 =>sel = 1
target =  7500 =>sel = 0

target = 15000 =>failed to find best select, sel = 0
target = 0 =>sel = 3

Quoted 5 lines

It means when target is in range or even over, the result are all correct.
But like as the ramp target is equal to 0, the selection will only choose the minimum one. When the ramp target is equal to 0, it means the user want to disable the rammpping function.

As I know, if target is equal to 0, it must find the fastest rampping value as the best selection.

If your table is [1000 2500 5000 10000], find_closest_bigger() will choose sel=0 when ramp_delay=0.
If your table is [10000 5000 2500 1000], find_closest_bigger() will choose sel=3 when ramp_delay=0.
i.e. In both cases, find_closest_bigger() chooses the fastest ramping value.

This meets your exception.

Actually, even if your table is [10000, 1000, 5000, 2500], find_closest_bigger() still can choose the correct selector. i.e. sel=1 when ramp_delay=0 in this case.

Regards,
Axel

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#8 lore raw

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 上午10:26寫道:

Quoted 73 lines

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午11:18寫道:

Hi,> >

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small.
It conflicts with find_closest_bigger value chosen logic.

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Sure.

After my test sample code, below's the result.
ascending [1000 2500 5000 10000]

target =  1000 =>sel = 0
target =  2500 =>sel = 1
target =  5000 =>sel = 2
target = 10000 =>sel = 3
target =  1700 =>sel = 1
target =  2750 =>sel = 2
target =  7500 =>sel = 3
target = 15000 =>failed to find best select, sel = 3
target =     0 =>sel = 0
descending [10000 5000 2500 1000]
target =  1000 =>sel = 3
target =  2500 =>sel = 2
target =  5000 =>sel = 1
target = 10000 =>sel = 0
target =  1700 =>sel = 2
target =  2750 =>sel = 1
target =  7500 =>sel = 0

target = 15000 =>failed to find best select, sel = 0
target = 0 =>sel = 3

It means when target is in range or even over, the result are all correct.
But like as the ramp target is equal to 0, the selection will only choose the minimum one. When the ramp target is equal to 0, it means the user want to disable the rammpping function.

As I know, if target is equal to 0, it must find the fastest rampping value as the best selection.

If your table is [1000 2500 5000 10000], find_closest_bigger() will choose sel=0 when ramp_delay=0.
If your table is [10000 5000 2500 1000], find_closest_bigger() will choose sel=3 when ramp_delay=0.
i.e. In both cases, find_closest_bigger() chooses the fastest ramping value.

This meets your exception.

Quoted 7 lines

Actually, even if your table is [10000, 1000, 5000, 2500], find_closest_bigger() still can choose the correct selector. i.e. sel=1 when ramp_delay=0 in this case.

This selection may be wrong.
ramp_delay=0 means ramp disabled,
If chip not support rampping disable, this selection must be configured as fastest rampping value, not the minimum one.

0 does not mean ramp disable.
It could be explicitly set to zero or its unintialized (zero by default). see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/regulator/core.c?id=1653ccf4c52df6a4abe8ec2f33f2cb2896d129ea

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#10 lore raw

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 下午1:48寫道:

Quoted 89 lines

於 五,2021-06-04 於 11:30 +0800,Axel Lin 提到:

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 上午10:26寫道:

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午11:18寫道:

Hi,> >

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small.
It conflicts with find_closest_bigger value chosen logic.

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Sure.

After my test sample code, below's the result.
ascending [1000 2500 5000 10000]

target =  1000 =>sel = 0
target =  2500 =>sel = 1
target =  5000 =>sel = 2
target = 10000 =>sel = 3
target =  1700 =>sel = 1
target =  2750 =>sel = 2
target =  7500 =>sel = 3
target = 15000 =>failed to find best select, sel = 3
target =     0 =>sel = 0
descending [10000 5000 2500 1000]
target =  1000 =>sel = 3
target =  2500 =>sel = 2
target =  5000 =>sel = 1
target = 10000 =>sel = 0
target =  1700 =>sel = 2
target =  2750 =>sel = 1
target =  7500 =>sel = 0

target = 15000 =>failed to find best select, sel = 0
target = 0 =>sel = 3

It means when target is in range or even over, the result are all correct.
But like as the ramp target is equal to 0, the selection will only choose the minimum one. When the ramp target is equal to 0, it means the user want to disable the rammpping function.

As I know, if target is equal to 0, it must find the fastest rampping value as the best selection.

If your table is [1000 2500 5000 10000], find_closest_bigger() will choose sel=0 when ramp_delay=0.
If your table is [10000 5000 2500 1000], find_closest_bigger() will choose sel=3 when ramp_delay=0.
i.e. In both cases, find_closest_bigger() chooses the fastest ramping value.

This meets your exception.

Actually, even if your table is [10000, 1000, 5000, 2500], find_closest_bigger() still can choose the correct selector. i.e. sel=1 when ramp_delay=0 in this case.

This selection may be wrong.
ramp_delay=0 means ramp disabled,
If chip not support rampping disable, this selection must be configured as fastest rampping value, not the minimum one.

Quoted 6 lines

0 does not mean ramp disable.
It could be explicitly set to zero or its unintialized (zero by default). see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/regulator/core.c?id=1653ccf4c52df6a4abe8ec2f33f2cb2896d129ea

How about 'ramp_disable' falg is true?

My understanding is:
If the h/w does not support disabling ramp_delay, the regulator core won't call ops->set_ramp_delay when ramp_delay=0.
If the h/w supports disabling ramp, i.e. ramp_disable flag is true, the regulator core will
call ops->set_ramp_delay with ramp_delay=0. in this case, it should have an exactly match and
write the register to disable ramp_delay.

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#12 lore raw

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 下午2:29寫道:

Quoted 113 lines

於 五,2021-06-04 於 13:59 +0800,Axel Lin 提到:

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 下午1:48寫道:

於 五,2021-06-04 於 11:30 +0800,Axel Lin 提到:

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 上午10:26寫道:

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午11:18寫道:

Hi,> >

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small.
It conflicts with find_closest_bigger value chosen logic.

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Sure.

After my test sample code, below's the result.
ascending [1000 2500 5000 10000]

target =  1000 =>sel = 0
target =  2500 =>sel = 1
target =  5000 =>sel = 2
target = 10000 =>sel = 3
target =  1700 =>sel = 1
target =  2750 =>sel = 2
target =  7500 =>sel = 3
target = 15000 =>failed to find best select, sel = 3
target =     0 =>sel = 0
descending [10000 5000 2500 1000]
target =  1000 =>sel = 3
target =  2500 =>sel = 2
target =  5000 =>sel = 1
target = 10000 =>sel = 0
target =  1700 =>sel = 2
target =  2750 =>sel = 1
target =  7500 =>sel = 0

target = 15000 =>failed to find best select, sel = 0
target = 0 =>sel = 3

It means when target is in range or even over, the result are all correct.
But like as the ramp target is equal to 0, the selection will only choose the minimum one. When the ramp target is equal to 0, it means the user want to disable the rammpping function.

As I know, if target is equal to 0, it must find the fastest rampping value as the best selection.

If your table is [1000 2500 5000 10000], find_closest_bigger() will choose sel=0 when ramp_delay=0.
If your table is [10000 5000 2500 1000], find_closest_bigger() will choose sel=3 when ramp_delay=0.
i.e. In both cases, find_closest_bigger() chooses the fastest ramping value.

This meets your exception.

Actually, even if your table is [10000, 1000, 5000, 2500], find_closest_bigger() still can choose the correct selector. i.e. sel=1 when ramp_delay=0 in this case.

This selection may be wrong.
ramp_delay=0 means ramp disabled,
If chip not support rampping disable, this selection must be configured as fastest rampping value, not the minimum one.

0 does not mean ramp disable.
It could be explicitly set to zero or its unintialized (zero by default). see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/regulator/core.c?id=1653ccf4c52df6a4abe8ec2f33f2cb2896d129ea

How about 'ramp_disable' falg is true?

My understanding is:
If the h/w does not support disabling ramp_delay, the regulator core won't call ops->set_ramp_delay when ramp_delay=0.
If the h/w supports disabling ramp, i.e. ramp_disable flag is true, the regulator core will
call ops->set_ramp_delay with ramp_delay=0. in this case, it should have an exactly match and
write the register to disable ramp_delay.

Quoted 1 line

If this can be guaranteed , to use the set_ramp_delay_regmap helper function would be better.

Hi ChiYuan,
Can you add Reviewed-by or Acked-by if this patch works.

Regards,
Axel

#13 lore raw

於 三,2021-06-09 於 11:32 +0800,Axel Lin 提到:

Quoted 117 lines

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 下午2:29寫道:

Quoted 116 lines

於 五,2021-06-04 於 13:59 +0800,Axel Lin 提到:

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 下午1:48寫道:

於 五,2021-06-04 於 11:30 +0800,Axel Lin 提到:

cy_huang(黃啟原) <[email protected]> 於 2021年6月4日 週五 上午10:26寫道:

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午11:18寫道:

Hi,> >

cy_huang(黃啟原) <[email protected]> 於 2021年6月3日 週四 下午6:20寫道:

Hi, Axel:> Use regulator_set_ramp_delay_regmap instead of open-coded.

There's some reason.
You can refer to https://lkml.org/lkml/2021/6/1/1145.

It's because our ramp value order is from small to large, not large to small.
It conflicts with find_closest_bigger value chosen logic.

I have verified the rt6160_set_ramp_delay() behavior exactly the same as regulator_set_ramp_delay_regmap. (both functions get the same selector for a given delay)

Could you check if this patch works?

Sure.

After my test sample code, below's the result.
ascending [1000 2500 5000 10000]

target =  1000 =>sel = 0
target =  2500 =>sel = 1
target =  5000 =>sel = 2
target = 10000 =>sel = 3
target =  1700 =>sel = 1
target =  2750 =>sel = 2
target =  7500 =>sel = 3
target = 15000 =>failed to find best select, sel = 3
target =     0 =>sel = 0
descending [10000 5000 2500 1000]
target =  1000 =>sel = 3
target =  2500 =>sel = 2
target =  5000 =>sel = 1
target = 10000 =>sel = 0
target =  1700 =>sel = 2
target =  2750 =>sel = 1
target =  7500 =>sel = 0

target = 15000 =>failed to find best select, sel = 0
target = 0 =>sel = 3

It means when target is in range or even over, the result are all correct.
But like as the ramp target is equal to 0, the selection will only choose the minimum one. When the ramp target is equal to 0, it means the user want to disable the rammpping function.

As I know, if target is equal to 0, it must find the fastest rampping value as the best selection.

If your table is [1000 2500 5000 10000], find_closest_bigger() will choose sel=0 when ramp_delay=0.
If your table is [10000 5000 2500 1000], find_closest_bigger() will choose sel=3 when ramp_delay=0.
i.e. In both cases, find_closest_bigger() chooses the fastest ramping value.

This meets your exception.

Actually, even if your table is [10000, 1000, 5000, 2500], find_closest_bigger() still can choose the correct selector. i.e. sel=1 when ramp_delay=0 in this case.

This selection may be wrong.
ramp_delay=0 means ramp disabled,
If chip not support rampping disable, this selection must be configured as fastest rampping value, not the minimum one.

0 does not mean ramp disable.
It could be explicitly set to zero or its unintialized (zero by default). see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/regulator/core.c?id=1653ccf4c52df6
a4abe8ec2f33f2cb2896d129ea

How about 'ramp_disable' falg is true?

My understanding is:
If the h/w does not support disabling ramp_delay, the regulator core won't call ops->set_ramp_delay when ramp_delay=0.
If the h/w supports disabling ramp, i.e. ramp_disable flag is true, the regulator core will
call ops->set_ramp_delay with ramp_delay=0. in this case, it should have an exactly match and
write the register to disable ramp_delay.

Quoted 3 lines
Quoted 1 line

If this can be guaranteed , to use the set_ramp_delay_regmap helper function would be better.

Hi ChiYuan,
Can you add Reviewed-by or Acked-by if this patch works.

Sure, already tested.

Quoted 3 lines

Regards,
Axel

************* Email Confidentiality Notice ********************

The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!

maintainer
#14 lore raw
In reply to Axel Lin
Quoted 1 line · Axel Lin

Use regulator_set_ramp_delay_regmap instead of open-coded.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/1] regulator: rt6160: Convert to use regulator_set_ramp_delay_regmap

      commit: b113ec2d8562f5f3e0359c547cba53686ee805e9

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark