power: qpnp-bms: do not clamp SOC based on voltage when charging

The BMS driver currently reports SOC to be at least 1% whenever the
battery voltage is above cutoff voltage. However, this can cause an
issue when charging, where the IR drop across the battery causes the
battery terminal voltages to be higher than the cutoff even when the
battery is effectively dead. This makes the BMS driver always report 1%
when charging, even when it should be reporting 0%.

Fix this by not clamping the SOC when the battery is charging.

CRs-Fixed: 634856
Change-Id: I3d85b5b35973123471dc21eb9651c958219795f9
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
diff --git a/drivers/power/qpnp-bms.c b/drivers/power/qpnp-bms.c
index 56d4a30..ed0279e 100644
--- a/drivers/power/qpnp-bms.c
+++ b/drivers/power/qpnp-bms.c
@@ -2205,6 +2205,11 @@
 		pr_err("adc vbat failed err = %d\n", rc);
 		return soc;
 	}
+
+	/* only clamp when discharging */
+	if (is_battery_charging(chip))
+		return soc;
+
 	if (soc <= 0 && vbat_uv > chip->v_cutoff_uv) {
 		pr_debug("clamping soc to 1, vbat (%d) > cutoff (%d)\n",
 						vbat_uv, chip->v_cutoff_uv);