[PATCH 1/2] power: supply: ltc2941: simplify Qlsb calculation
From: Michał Mirosław
Date: Mon Jan 10 2022 - 21:32:44 EST
Replace two divisions with a subtraction+shift for a small code size
improvement and less brackets.
Signed-off-by: Michał Mirosław <mirq-linux@xxxxxxxxxxxx>
---
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