regulator: as3722: Fix equation to calculate max_uV in regulator_lin_range macro
PATCH 1/2 regulator: as3722: Fix equation to calculate max_uV in regulator_lin_range macro
Fix off-by-one in the equation to calculate max_uV.
---
Hi,
I don't have the datasheet and h/w.
Just found this issue while reading the code. (Only compile test).
Axel
drivers/regulator/as3722-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/as3722-regulator.c +1 -1
@@ -441,7 +441,7 @@ static struct regulator_ops as3722_ldo3_extcntrl_ops = { .max_sel = _max_sel, \ .uV_step = _step_uV, \ .min_uV = _min_uV, \ - .max_uV = _min_uV + (_max_sel - _min_sel + 1) * _step_uV, \ + .max_uV = _min_uV + (_max_sel - _min_sel) * _step_uV, \ }static const struct regulator_linear_range as3722_ldo_ranges[] = {
Signature · 1 line
1.8.1.2
PATCH 2/2 regulator: as3722: Fix off-by-one n_voltages setting for SDx
AS3722_SDx_VSEL_MAX means the maximum selector, the n_voltages should be AS3722_SDx_VSEL_MAX + 1.
--- drivers/regulator/as3722-regulator.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/regulator/as3722-regulator.c +7 -7
@@ -99,7 +99,7 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD0_EXT_ENABLE_MASK, .control_reg = AS3722_SD0_CONTROL_REG, .mode_mask = AS3722_SD0_MODE_FAST, - .n_voltages = AS3722_SD0_VSEL_MAX, + .n_voltages = AS3722_SD0_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_SD1,
@@ -112,7 +112,7 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD1_EXT_ENABLE_MASK, .control_reg = AS3722_SD1_CONTROL_REG, .mode_mask = AS3722_SD1_MODE_FAST, - .n_voltages = AS3722_SD0_VSEL_MAX, + .n_voltages = AS3722_SD0_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_SD2,
@@ -126,7 +126,7 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD2_EXT_ENABLE_MASK, .control_reg = AS3722_SD23_CONTROL_REG, .mode_mask = AS3722_SD2_MODE_FAST, - .n_voltages = AS3722_SD2_VSEL_MAX, + .n_voltages = AS3722_SD2_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_SD3,
@@ -140,7 +140,7 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD3_EXT_ENABLE_MASK, .control_reg = AS3722_SD23_CONTROL_REG, .mode_mask = AS3722_SD3_MODE_FAST, - .n_voltages = AS3722_SD2_VSEL_MAX, + .n_voltages = AS3722_SD2_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_SD4,
@@ -154,7 +154,7 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD4_EXT_ENABLE_MASK, .control_reg = AS3722_SD4_CONTROL_REG, .mode_mask = AS3722_SD4_MODE_FAST, - .n_voltages = AS3722_SD2_VSEL_MAX, + .n_voltages = AS3722_SD2_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_SD5,
@@ -168,7 +168,7 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD5_EXT_ENABLE_MASK, .control_reg = AS3722_SD5_CONTROL_REG, .mode_mask = AS3722_SD5_MODE_FAST, - .n_voltages = AS3722_SD2_VSEL_MAX, + .n_voltages = AS3722_SD2_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_SD6,
@@ -181,7 +181,7 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD6_EXT_ENABLE_MASK, .control_reg = AS3722_SD6_CONTROL_REG, .mode_mask = AS3722_SD6_MODE_FAST, - .n_voltages = AS3722_SD0_VSEL_MAX, + .n_voltages = AS3722_SD0_VSEL_MAX + 1, }, { .regulator_id = AS3722_REGULATOR_ID_LDO0,
Signature · 1 line
1.8.1.2
Re: [RFT][PATCH 2/2] regulator: as3722: Fix off-by-one n_voltages setting for SDx
Quoted 13 lines · Axel Lin
AS3722_SDx_VSEL_MAXmeans the maximum selector, then_voltagesshould beAS3722_SDx_VSEL_MAX+ 1.Signed-off-by Axel Lin <[email protected]>--- drivers/regulator/as3722-regulator.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/regulator/as3722-regulator.c +0
-0
drivers/regulator/as3722-regulator.c static const struct as3722_register_mapping as3722_reg_lookup[] = { · line 103
Quoted 6 lines
drivers/regulator/as3722-regulator.c +1
-1@@ -99,7 +99,7 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { .sleep_ctrl_mask = AS3722_SD0_EXT_ENABLE_MASK, .control_reg = AS3722_SD0_CONTROL_REG, .mode_mask = AS3722_SD0_MODE_FAST, - .n_voltages = AS3722_SD0_VSEL_MAX, + .n_voltages = AS3722_SD0_VSEL_MAX + 1, },
Agree, to allow the VSEL_MAX as valid value, it need to be +1 in n_voltages.
if (selector >= rdev->desc->n_voltages)
return -EINVAL;Originally, I offset this because of min_sel is 1 as thinking that n_voltages are number of voltages but it become MAX_VSEL. Seems my interpretation issue.
In header, it is defined as
#define AS3722_SD0_VSEL_MIN 0x01 #define AS3722_SD0_VSEL_MAX 0x5A #define AS3722_SD2_VSEL_MIN 0x01 #define AS3722_SD2_VSEL_MAX 0x7F
Quoted 17 lines · Axel Lin
Fix off-by-one in the equation to calculate
max_uV.Signed-off-by Axel Lin <[email protected]>---
Hi,
I don't have the datasheet and h/w.
Just found this issue while reading the code. (Only compile test).Axel
drivers/regulator/as3722-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/regulator/as3722-regulator.c +0
-0
drivers/regulator/as3722-regulator.c static struct regulator_ops as3722_ldo3_extcntrl_ops = { · line 447
Quoted 8 lines
drivers/regulator/as3722-regulator.c +1
-1@@ -441,7 +441,7 @@ static struct regulator_ops as3722_ldo3_extcntrl_ops = { .max_sel = _max_sel, \ .uV_step = _step_uV, \ .min_uV = _min_uV, \ - .max_uV = _min_uV + (_max_sel - _min_sel + 1) * _step_uV, \ + .max_uV = _min_uV + (_max_sel - _min_sel) * _step_uV, \ }static const struct regulator_linear_range as3722_ldo_ranges[] = {
The datasheet says:
The voltage select bits set the LDO output voltage 0.825V...3.3V, 25mV steps
....00h : LDO off
01h-24h : V_LDO4=0.8V+ldo4_vsel*25mV
25h-3Fh : do not use
40h-7Fh : V_LDO4=1.725V+(ldo4_vsel-40h)*25mV
And put the linear range asregulator_lin_range(0x01, 0x24, 800000, 25000),regulator_lin_range(0x40, 0x7F, 1725000, 25000),
So as per datasheet, value 0x24 is equal to 1700mV.
and 0x7F equal to 3300
I created equation based on first entry which is wrong for second entry and your equation is correct for second entry but break first one.
I think your equation is correct with following change:regulator_lin_range(0x01, 0x24, 825000, 25000),
So it need to re-spin this patch.
2013/10/2 Laxman Dewangan <[email protected]>:
Quoted 43 lines · Axel Lin
Quoted 27 lines
Fix off-by-one in the equation to calculate
max_uV.Signed-off-by Axel Lin <[email protected]>---
Hi,
I don't have the datasheet and h/w.
Just found this issue while reading the code. (Only compile test).Axel
drivers/regulator/as3722-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/regulator/as3722-regulator.c +1
-1@@ -441,7 +441,7 @@ static struct regulator_ops as3722_ldo3_extcntrl_ops = { .max_sel = _max_sel, \ .uV_step = _step_uV, \ .min_uV = _min_uV, \ - .max_uV = _min_uV + (_max_sel - _min_sel + 1) * _step_uV, \ + .max_uV = _min_uV + (_max_sel - _min_sel) * _step_uV, \ }Quoted 1 line
static const struct regulator_linear_range as3722_ldo_ranges[] = {The datasheet says:
The voltage select bits set the LDO output voltage 0.825V...3.3V, 25mV steps
....00h : LDO off
01h-24h : V_LDO4=0.8V+ldo4_vsel*25mV
25h-3Fh : do not use
40h-7Fh : V_LDO4=1.725V+(ldo4_vsel-40h)*25mVAnd put the linear range as
regulator_lin_range(0x01, 0x24, 800000, 25000),regulator_lin_range(0x40, 0x7F, 1725000, 25000),
Quoted 8 lines
So as per datasheet, value
0x24is equal to 1700mV.and 0x7F equal to 3300I created equation based on first entry which is wrong for second entry and your equation is correct for second entry but break first one.
I think your equation is correct with following change:
regulator_lin_range(0x01, 0x24, 825000, 25000),
Hi Laxman,
Thanks for the review.
And how about the setting for as3722_sd2345_ranges? How the datasheet says for sd2345?
e.g. Should I changeregulator_lin_range(0x01, 0x40, 600000, 12500),
toregulator_lin_range(0x01, 0x40, 612500, 12500),
Thanks,
Axel.
Quoted 55 lines · Axel Lin
2013/10/2 Laxman Dewangan <[email protected]>:
Quoted 41 lines · Axel Lin
Quoted 26 lines
Fix off-by-one in the equation to calculate
max_uV.Signed-off-by Axel Lin <[email protected]>---
Hi,
I don't have the datasheet and h/w.
Just found this issue while reading the code. (Only compile test).Axel
drivers/regulator/as3722-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/regulator/as3722-regulator.c +1
-1@@ -441,7 +441,7 @@ static struct regulator_ops as3722_ldo3_extcntrl_ops = { .max_sel = _max_sel, \ .uV_step = _step_uV, \ .min_uV = _min_uV, \ - .max_uV = _min_uV + (_max_sel - _min_sel + 1) * _step_uV, \ + .max_uV = _min_uV + (_max_sel - _min_sel) * _step_uV, \ }Quoted 1 line
static const struct regulator_linear_range as3722_ldo_ranges[] = {The datasheet says:
The voltage select bits set the LDO output voltage 0.825V...3.3V, 25mV steps
....00h : LDO off
01h-24h : V_LDO4=0.8V+ldo4_vsel*25mV
25h-3Fh : do not use
40h-7Fh : V_LDO4=1.725V+(ldo4_vsel-40h)*25mVAnd put the linear range as
regulator_lin_range(0x01, 0x24, 800000, 25000),regulator_lin_range(0x40, 0x7F, 1725000, 25000),Quoted 8 lines
So as per datasheet, value
0x24is equal to 1700mV.and 0x7F equal to 3300I created equation based on first entry which is wrong for second entry and your equation is correct for second entry but break first one.
I think your equation is correct with following change:
regulator_lin_range(0x01, 0x24, 825000, 25000),Hi Laxman,
Thanks for the review.
And how about the setting foras3722_sd2345_ranges? How the datasheet says for sd2345?
Quoted 5 lines
e.g. Should I change
regulator_lin_range(0x01, 0x40, 600000, 12500),
toregulator_lin_range(0x01, 0x40, 612500, 12500),
For this, it need to change for all entry:
The voltage select bits set the DC/DC output voltage level and power the DC/DC converter down.
....00h : DC/DC powered down
01h-40h : V_SD2=0.6V+sd2_vsel*12.5mV
41h-70h : V_SD2=1.4V+(sd2_vsel-40h)*25mV
71h-7Fh : V_SD2=2.6V+(sd2_vsel-70h)*50mV
Again second and third entry need to be taken care.
Third entry min_uV is completely wrong here. Did not get caught in my testing as I did not have requirement of the third range in my board.
static const struct regulator_linear_range as3722_sd2345_ranges[] = {
regulator_lin_range(0x01, 0x40, 600000, 12500),
regulator_lin_range(0x41, 0x70, 1400000, 25000),
regulator_lin_range(0x71, 0x7F, 1725000, 50000),
};