diff mbox series

[1/2] power: supply: ltc2941: simplify Qlsb calculation

Message ID 680a4c737950f59e787f64887402e3ae247e89dd.1641868274.git.mirq-linux@rere.qmqm.pl (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series [1/2] power: supply: ltc2941: simplify Qlsb calculation | expand

Commit Message

Michał Mirosław Jan. 11, 2022, 2:32 a.m. UTC
Replace two divisions with a subtraction+shift for a small code size
improvement and less brackets.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/power/supply/ltc2941-battery-gauge.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Sebastian Reichel Feb. 11, 2022, 8:18 p.m. UTC | #1
Hi,

On Tue, Jan 11, 2022 at 03:32:40AM +0100, Michał Mirosław wrote:
> Replace two divisions with a subtraction+shift for a small code size
> improvement and less brackets.
> 
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/ltc2941-battery-gauge.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c
> index 09f3e78af4e0..c0cbf4cd59ee 100644
> --- a/drivers/power/supply/ltc2941-battery-gauge.c
> +++ b/drivers/power/supply/ltc2941-battery-gauge.c
> @@ -490,13 +490,13 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
>  	if (info->id == LTC2943_ID) {
>  		if (prescaler_exp > LTC2943_MAX_PRESCALER_EXP)
>  			prescaler_exp = LTC2943_MAX_PRESCALER_EXP;
> -		info->Qlsb = ((340 * 50000) / r_sense) /
> -				(4096 / (1 << (2*prescaler_exp)));
> +		info->Qlsb = ((340 * 50000) / r_sense) >>
> +			     (12 - 2*prescaler_exp);
>  	} else {
>  		if (prescaler_exp > LTC2941_MAX_PRESCALER_EXP)
>  			prescaler_exp = LTC2941_MAX_PRESCALER_EXP;
> -		info->Qlsb = ((85 * 50000) / r_sense) /
> -				(128 / (1 << prescaler_exp));
> +		info->Qlsb = ((85 * 50000) / r_sense) >>
> +			     (7 - prescaler_exp);
>  	}
>  
>  	/* Read status register to check for LTC2942 */
> -- 
> 2.30.2
>
diff mbox series

Patch

diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c
index 09f3e78af4e0..c0cbf4cd59ee 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -490,13 +490,13 @@  static int ltc294x_i2c_probe(struct i2c_client *client,
 	if (info->id == LTC2943_ID) {
 		if (prescaler_exp > LTC2943_MAX_PRESCALER_EXP)
 			prescaler_exp = LTC2943_MAX_PRESCALER_EXP;
-		info->Qlsb = ((340 * 50000) / r_sense) /
-				(4096 / (1 << (2*prescaler_exp)));
+		info->Qlsb = ((340 * 50000) / r_sense) >>
+			     (12 - 2*prescaler_exp);
 	} else {
 		if (prescaler_exp > LTC2941_MAX_PRESCALER_EXP)
 			prescaler_exp = LTC2941_MAX_PRESCALER_EXP;
-		info->Qlsb = ((85 * 50000) / r_sense) /
-				(128 / (1 << prescaler_exp));
+		info->Qlsb = ((85 * 50000) / r_sense) >>
+			     (7 - prescaler_exp);
 	}
 
 	/* Read status register to check for LTC2942 */