power: pm8921-bms: limit the number of tries for ocv calculation
When we want to force a certain percent charge we calculate the
expect percent charge (pc) from the expected RC (remaining charge
same as ocv based charge). We reverse lookup the ocv (open circuit
voltage) based on the pc. We double make sure that a forward lookup
matches the reverse lookup and if it does not within a percent limit
we repeatedly tweak the ocv by 5mV to get it to match.
This tweaking is unbounded and based on the battery profile could
result in a infinite loop. Limit the number of times we tweak the ocv
to prevent a possible watchdog bark.
CRs-Fixed: 406197
Change-Id: Iea874027a9e2f7ce326c8398f255e393fa7e4529
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index 23903df..cfee334 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -1216,6 +1216,7 @@
int pc, new_pc;
int batt_temp_degc = batt_temp / 10;
int ocv;
+ int count = 0;
rc = (s64)shutdown_soc * (fcc_uah - uuc_uah);
rc = div_s64(rc, 100) + cc_uah + uuc_uah;
@@ -1229,7 +1230,8 @@
new_pc = interpolate_pc(chip->pc_temp_ocv_lut, batt_temp_degc, ocv);
pr_debug("test revlookup pc = %d for ocv = %d\n", new_pc, ocv);
- while (abs(new_pc - pc) > 1) {
+ /* try 10 times to get a close enough pc */
+ while (abs(new_pc - pc) > 1 && count++ < 10) {
int delta_mv = 5;
if (new_pc > pc)