regulator: rk8xx: Fix buck get and set enabled state on RK806
PATCH 1/1 regulator: rk8xx: Fix buck get and set enabled state on RK806
Wrong POWER_EN reg is used to get and set enabled state for the RK806 buck 4 and 8 regulators, also wrong POWER_SLP_EN0 bit is used for suspend state for the RK806 buck 1-8 regulators.
Fix this by not adding one to the zero based buck variable.
--- drivers/power/regulator/rk8xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/power/regulator/rk8xx.c +6 -6
@@ -415,7 +415,7 @@ static int _buck_set_enable(struct udevice *pmic, int buck, bool enable)break ;case RK806_ID : value =RK806_POWER_EN_CLRSETBITS (buck %4 , enable); - en_reg =RK806_POWER_EN ((buck +1 ) /4 ); + en_reg =RK806_POWER_EN (buck /4 ); ret =pmic_reg_write (pmic, en_reg, value);break ;case RK808_ID :
@@ -494,7 +494,7 @@ static int _buck_get_enable(struct udevice *pmic, int buck)break ;case RK806_ID : mask =BIT (buck %4 ); - ret =pmic_reg_read (pmic,RK806_POWER_EN ((buck +1 ) /4 )); + ret =pmic_reg_read (pmic,RK806_POWER_EN (buck /4 ));break ;case RK808_ID :case RK818_ID :
@@ -541,10 +541,10 @@ static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable)if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 ); }else { reg =RK806_POWER_SLP_EN0 ; - mask =BIT (buck +1 ); + mask =BIT (buck); } ret =pmic_clrsetbits (pmic, reg, mask, enable ? mask :0 ); }
@@ -592,10 +592,10 @@ static int _buck_get_suspend_enable(struct udevice *pmic, int buck)if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 ); }else { reg =RK806_POWER_SLP_EN0 ; - mask =BIT (buck +1 ); + mask =BIT (buck); } val =pmic_reg_read (pmic, reg); }
Signature · 1 line
2.46.0
Hi Jonas,
Quoted 8 lines · Jonas Karlman
Wrong
POWER_ENreg is used to get and set enabled state for the RK806 buck 4 and 8 regulators, also wrongPOWER_SLP_EN0bit is used for suspend state for the RK806 buck 1-8 regulators.Fix this by not adding one to the zero based buck variable.
Fixes f172575d92cd ("power: rk8xx: add support for RK806")Signed-off-by Jonas Karlman <[email protected]>
Thanks,
- Kever
Quoted 52 lines
--- drivers/power/regulator/rk8xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/power/regulator/rk8xx.c +6
-6@@ -415,7 +415,7 @@ static int _buck_set_enable(struct udevice *pmic, int buck, bool enable)break ;case RK806_ID : value =RK806_POWER_EN_CLRSETBITS (buck %4 , enable); - en_reg =RK806_POWER_EN ((buck +1 ) /4 ); + en_reg =RK806_POWER_EN (buck /4 ); ret =pmic_reg_write (pmic, en_reg, value);break ;case RK808_ID :@@ -494,7 +494,7 @@ static int _buck_get_enable(struct udevice *pmic, int buck)break ;case RK806_ID : mask =BIT (buck %4 ); - ret =pmic_reg_read (pmic,RK806_POWER_EN ((buck +1 ) /4 )); + ret =pmic_reg_read (pmic,RK806_POWER_EN (buck /4 ));break ;case RK808_ID :case RK818_ID :@@ -541,10 +541,10 @@ static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable)if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 ); }else { reg =RK806_POWER_SLP_EN0 ; - mask =BIT (buck +1 ); + mask =BIT (buck); } ret =pmic_clrsetbits (pmic, reg, mask, enable ? mask :0 ); }@@ -592,10 +592,10 @@ static int _buck_get_suspend_enable(struct udevice *pmic, int buck)if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 ); }else { reg =RK806_POWER_SLP_EN0 ; - mask =BIT (buck +1 ); + mask =BIT (buck); } val =pmic_reg_read (pmic, reg); }
Hi Jonas,
Quoted 7 lines · Jonas Karlman
Wrong
POWER_ENreg is used to get and set enabled state for the RK806 buck 4 and 8 regulators, also wrongPOWER_SLP_EN0bit is used for suspend state for the RK806 buck 1-8 regulators.Fix this by not adding one to the zero based buck variable.
Fixes f172575d92cd ("power: rk8xx: add support for RK806")
Shoot, I made a lot of mistakes in that driver :/
Thanks for catching those :)
Quoted 28 lines
Signed-off-by Jonas Karlman <[email protected]>--- drivers/power/regulator/rk8xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/power/regulator/rk8xx.c +2
-2@@ -415,7 +415,7 @@ static int _buck_set_enable(struct udevice *pmic, int buck, bool enable)break ;case RK806_ID : value =RK806_POWER_EN_CLRSETBITS (buck %4 , enable); - en_reg =RK806_POWER_EN ((buck +1 ) /4 ); + en_reg =RK806_POWER_EN (buck /4 ); ret =pmic_reg_write (pmic, en_reg, value);break ;case RK808_ID :@@ -494,7 +494,7 @@ static int _buck_get_enable(struct udevice *pmic, int buck)break ;case RK806_ID : mask =BIT (buck %4 ); - ret =pmic_reg_read (pmic,RK806_POWER_EN ((buck +1 ) /4 )); + ret =pmic_reg_read (pmic,RK806_POWER_EN (buck /4 ));break ;case RK808_ID :case RK818_ID :
drivers/power/regulator/rk8xx.c static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable) · line 544
Quoted 5 lines
drivers/power/regulator/rk8xx.c +1
-1@@ -541,10 +541,10 @@ static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable)if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 );
I like my (+ 1 - 3) here to match buck + 1 above. buck + 1 represents the buck number in the datasheet (index starts at one), so you need to subtract 3 to that index to find the bit index in the register.
drivers/power/regulator/rk8xx.c static int _buck_get_suspend_enable(struct udevice *pmic, int buck) · line 595
Quoted 13 lines
drivers/power/regulator/rk8xx.c +2
-2}else { reg =RK806_POWER_SLP_EN0 ; - mask =BIT (buck +1 ); + mask =BIT (buck); } ret =pmic_clrsetbits (pmic, reg, mask, enable ? mask :0 ); }@@ -592,10 +592,10 @@ static int _buck_get_suspend_enable(struct udevice *pmic, int buck)if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 );
Ditto.
Just a matter of taste though!
@Kever Since it's a bugfix, can we have this in your next MR for v2024.10 please? Thanks!
Thanks!
Quentin
Hi Quentin,
Quoted 44 lines · Quentin Schulz
Hi Jonas,
Quoted 7 lines · Jonas Karlman
Wrong
POWER_ENreg is used to get and set enabled state for the RK806 buck 4 and 8 regulators, also wrongPOWER_SLP_EN0bit is used for suspend state for the RK806 buck 1-8 regulators.Fix this by not adding one to the zero based buck variable.
Fixes f172575d92cd ("power: rk8xx: add support for RK806")Shoot, I made a lot of mistakes in that driver :/
Thanks for catching those :)
Quoted 29 lines
Signed-off-by Jonas Karlman <[email protected]>--- drivers/power/regulator/rk8xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/power/regulator/rk8xx.c +2
-2@@ -415,7 +415,7 @@ static int _buck_set_enable(struct udevice *pmic, int buck, bool enable)break ;case RK806_ID : value =RK806_POWER_EN_CLRSETBITS (buck %4 , enable); - en_reg =RK806_POWER_EN ((buck +1 ) /4 ); + en_reg =RK806_POWER_EN (buck /4 ); ret =pmic_reg_write (pmic, en_reg, value);break ;case RK808_ID :@@ -494,7 +494,7 @@ static int _buck_get_enable(struct udevice *pmic, int buck)break ;case RK806_ID : mask =BIT (buck %4 ); - ret =pmic_reg_read (pmic,RK806_POWER_EN ((buck +1 ) /4 )); + ret =pmic_reg_read (pmic,RK806_POWER_EN (buck /4 ));break ;case RK808_ID :case RK818_ID :@@ -541,10 +541,10 @@ static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable)
Quoted 8 lines
drivers/power/regulator/rk8xx.c static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable) · line 544
Quoted 4 lines
drivers/power/regulator/rk8xx.c +1
-1if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 );I like my (+ 1 - 3) here to match buck + 1 above. buck + 1 represents the buck number in the datasheet (index starts at one), so you need to subtract 3 to that index to find the bit index in the register.
I understand this reasoning and would fully agree if this was the only use of buck in BIT(), however each time I tried to scan over this code, (with buck is 0-based in mind) this buck + 1 - 3 made me stop and re-think if this really was correct.
I have no strong opinion and can revert this change if you like.
Quoted 10 lines
Quoted 10 lines
drivers/power/regulator/rk8xx.c +1
-1}else { reg =RK806_POWER_SLP_EN0 ; - mask =BIT (buck +1 ); + mask =BIT (buck); } ret =pmic_clrsetbits (pmic, reg, mask, enable ? mask :0 ); }@@ -592,10 +592,10 @@ static int _buck_get_suspend_enable(struct udevice *pmic, int buck)
Quoted 8 lines
drivers/power/regulator/rk8xx.c static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable) · line 544
Quoted 4 lines
drivers/power/regulator/rk8xx.c +1
-1if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 );Ditto.
Just a matter of taste though!
Let me know if you want me to send a v2 with this change reverted.
Regards,
Jonas
Quoted 8 lines
Reviewed-by Quentin Schulz <[email protected]>@Kever Since it's a bugfix, can we have this in your next MR for v2024.10 please? Thanks!
Thanks!
Quentin
Hi Jonas,
Quoted 56 lines · Jonas Karlman
Hi Quentin,
Quoted 44 lines · Quentin Schulz
Hi Jonas,
Quoted 7 lines · Jonas Karlman
Wrong
POWER_ENreg is used to get and set enabled state for the RK806 buck 4 and 8 regulators, also wrongPOWER_SLP_EN0bit is used for suspend state for the RK806 buck 1-8 regulators.Fix this by not adding one to the zero based buck variable.
Fixes f172575d92cd ("power: rk8xx: add support for RK806")Shoot, I made a lot of mistakes in that driver :/
Thanks for catching those :)
Quoted 29 lines
Signed-off-by Jonas Karlman <[email protected]>--- drivers/power/regulator/rk8xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/power/regulator/rk8xx.c +2
-2@@ -415,7 +415,7 @@ static int _buck_set_enable(struct udevice *pmic, int buck, bool enable)break ;case RK806_ID : value =RK806_POWER_EN_CLRSETBITS (buck %4 , enable); - en_reg =RK806_POWER_EN ((buck +1 ) /4 ); + en_reg =RK806_POWER_EN (buck /4 ); ret =pmic_reg_write (pmic, en_reg, value);break ;case RK808_ID :@@ -494,7 +494,7 @@ static int _buck_get_enable(struct udevice *pmic, int buck)break ;case RK806_ID : mask =BIT (buck %4 ); - ret =pmic_reg_read (pmic,RK806_POWER_EN ((buck +1 ) /4 )); + ret =pmic_reg_read (pmic,RK806_POWER_EN (buck /4 ));break ;case RK808_ID :case RK818_ID :@@ -541,10 +541,10 @@ static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable)Quoted 8 lines
drivers/power/regulator/rk8xx.c static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable) · line 544
Quoted 4 lines
drivers/power/regulator/rk8xx.c +1
-1if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 );I like my (+ 1 - 3) here to match buck + 1 above. buck + 1 represents the buck number in the datasheet (index starts at one), so you need to subtract 3 to that index to find the bit index in the register.
Quoted 5 lines
I understand this reasoning and would fully agree if this was the only use of buck in
BIT(), however each time I tried to scan over this code, (with buck is 0-based in mind) this buck + 1 - 3 made me stop and re-think if this really was correct.
Fair enough. Should we migrate buck + 1 >= 9 to buck >= 8 with an additional comment explaining this is for BUCK9/BUCK10?
Quoted 19 lines
I have no strong opinion and can revert this change if you like.
Quoted 17 lines
Quoted 9 lines
drivers/power/regulator/rk8xx.c +1
-1}else { reg =RK806_POWER_SLP_EN0 ; - mask =BIT (buck +1 ); + mask =BIT (buck); } ret =pmic_clrsetbits (pmic, reg, mask, enable ? mask :0 ); }drivers/power/regulator/rk8xx.c static int _buck_get_suspend_enable(struct udevice *pmic, int buck) · line 595
Quoted 5 lines
drivers/power/regulator/rk8xx.c +1
-1@@ -592,10 +592,10 @@ static int _buck_get_suspend_enable(struct udevice *pmic, int buck)if (buck +1 >=9 ) { reg =RK806_POWER_SLP_EN1 ; - mask =BIT (buck +1 -3 ); + mask =BIT (buck -2 );Ditto.
Quoted 4 lines
Quoted 1 line
Just a matter of taste though!
Let me know if you want me to send a v2 with this change reverted.
It just creeps in along changes that are actually bugs and I had to do a double take on the diff to make sure it was correct.
I could suggest two separate commits:
1) bug fixes from buck + 1 to buck (basically everything but the buck - 2 changes)
2) change buck + 1 that I added for "readability" to buck by subtracting one elsewhere and maybe adding a comment for better readability?
What do you think?
Cheers,
Quentin