power: pm8921-bms: use consistent temperature units
There is bug in the code where interpolate_pc is passed temperature in
DegC at one call site vs deciDegCelcius at other.
Use degC consistently.
Change-Id: I3e5e92e39adf904e62d4c5ffcb6d370c0655f7cf
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index c6cc845..5eff419 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -831,28 +831,26 @@
}
static int interpolate_pc(struct pm8921_bms_chip *chip,
- int batt_temp, int ocv)
+ int batt_temp_degc, int ocv)
{
int i, j, pcj, pcj_minus_one, pc;
int rows = chip->pc_temp_ocv_lut->rows;
int cols = chip->pc_temp_ocv_lut->cols;
- /* batt_temp is in tenths of degC - convert it to degC for lookups */
- batt_temp = batt_temp/10;
- if (batt_temp < chip->pc_temp_ocv_lut->temp[0]) {
- pr_debug("batt_temp %d < known temp range for pc\n", batt_temp);
- batt_temp = chip->pc_temp_ocv_lut->temp[0];
+ if (batt_temp_degc < chip->pc_temp_ocv_lut->temp[0]) {
+ pr_debug("batt_temp %d < known temp range\n", batt_temp_degc);
+ batt_temp_degc = chip->pc_temp_ocv_lut->temp[0];
}
- if (batt_temp > chip->pc_temp_ocv_lut->temp[cols - 1]) {
- pr_debug("batt_temp %d > known temp range for pc\n", batt_temp);
- batt_temp = chip->pc_temp_ocv_lut->temp[cols - 1];
+ if (batt_temp_degc > chip->pc_temp_ocv_lut->temp[cols - 1]) {
+ pr_debug("batt_temp %d > known temp range\n", batt_temp_degc);
+ batt_temp_degc = chip->pc_temp_ocv_lut->temp[cols - 1];
}
for (j = 0; j < cols; j++)
- if (batt_temp <= chip->pc_temp_ocv_lut->temp[j])
+ if (batt_temp_degc <= chip->pc_temp_ocv_lut->temp[j])
break;
- if (batt_temp == chip->pc_temp_ocv_lut->temp[j]) {
+ if (batt_temp_degc == chip->pc_temp_ocv_lut->temp[j]) {
/* found an exact match for temp in the table */
if (ocv >= chip->pc_temp_ocv_lut->ocv[0][j])
return chip->pc_temp_ocv_lut->percent[0];
@@ -875,7 +873,7 @@
}
/*
- * batt_temp is within temperature for
+ * batt_temp_degc is within temperature for
* column j-1 and j
*/
if (ocv >= chip->pc_temp_ocv_lut->ocv[0][j])
@@ -915,7 +913,7 @@
chip->pc_temp_ocv_lut->temp[j-1],
pcj,
chip->pc_temp_ocv_lut->temp[j],
- batt_temp);
+ batt_temp_degc);
return pc;
}
}
@@ -927,7 +925,7 @@
return pcj_minus_one;
pr_debug("%d ocv wasn't found for temp %d in the LUT returning 100%%",
- ocv, batt_temp);
+ ocv, batt_temp_degc);
return 100;
}
@@ -1160,7 +1158,7 @@
{
int pc, scalefactor;
- pc = interpolate_pc(chip, batt_temp, ocv_uv / 1000);
+ pc = interpolate_pc(chip, batt_temp / 10, ocv_uv / 1000);
pr_debug("pc = %u for ocv = %dmicroVolts batt_temp = %d\n",
pc, ocv_uv, batt_temp);