qpnp-fg-gen3: expose a fake battery SOC for debug board

When a debug board is present, battery ID will be something like
7 Kohms. Expose a fake battery SOC when this is detected. This
will help avoiding the device shutdown if a low battery voltage
is seen by FG and state of charge goes to 0.

Change-Id: I750b2adfb00f12960f74bd552a5896f66ecaece6
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
diff --git a/drivers/power/qcom-charger/fg-core.h b/drivers/power/qcom-charger/fg-core.h
index a703b20..cb58801 100644
--- a/drivers/power/qcom-charger/fg-core.h
+++ b/drivers/power/qcom-charger/fg-core.h
@@ -222,7 +222,6 @@
 	int		float_volt_uv;
 	int		vbatt_full_mv;
 	int		fastchg_curr_ma;
-	int		batt_id_kohm;
 };
 
 struct fg_cyc_ctr_data {
@@ -278,7 +277,7 @@
 	u32			batt_soc_base;
 	u32			batt_info_base;
 	u32			mem_if_base;
-	int			batt_id;
+	int			batt_id_kohms;
 	int			status;
 	int			charge_done;
 	int			last_soc;
diff --git a/drivers/power/qcom-charger/qpnp-fg-gen3.c b/drivers/power/qcom-charger/qpnp-fg-gen3.c
index a07cb81..759d5eb 100644
--- a/drivers/power/qcom-charger/qpnp-fg-gen3.c
+++ b/drivers/power/qcom-charger/qpnp-fg-gen3.c
@@ -655,12 +655,36 @@
 	return 0;
 }
 
+#define DEBUG_BATT_ID_KOHMS	7
+static bool is_debug_batt_id(struct fg_chip *chip)
+{
+	int batt_id_delta = 0;
+
+	if (!chip->batt_id_kohms)
+		return false;
+
+	batt_id_delta = abs(chip->batt_id_kohms - DEBUG_BATT_ID_KOHMS);
+	if (batt_id_delta <= 1) {
+		fg_dbg(chip, FG_POWER_SUPPLY, "Debug battery id: %dKohms\n",
+			chip->batt_id_kohms);
+		return true;
+	}
+
+	return false;
+}
+
 #define FULL_CAPACITY	100
 #define FULL_SOC_RAW	255
+#define DEBUG_BATT_SOC	67
 static int fg_get_prop_capacity(struct fg_chip *chip, int *val)
 {
 	int rc, msoc;
 
+	if (is_debug_batt_id(chip)) {
+		*val = DEBUG_BATT_SOC;
+		return 0;
+	}
+
 	if (chip->charge_full) {
 		*val = FULL_CAPACITY;
 		return 0;
@@ -725,7 +749,7 @@
 	}
 
 	batt_id /= 1000;
-	chip->batt_id = batt_id;
+	chip->batt_id_kohms = batt_id;
 	batt_node = of_find_node_by_name(node, "qcom,battery-data");
 	if (!batt_node) {
 		pr_err("Batterydata not available\n");
@@ -2612,7 +2636,7 @@
 	rc = fg_get_batt_profile(chip);
 	if (rc < 0)
 		pr_warn("profile for batt_id=%dKOhms not found..using OTP, rc:%d\n",
-			chip->batt_id, rc);
+			chip->batt_id_kohms, rc);
 
 	/* Read all the optional properties below */
 	rc = of_property_read_u32(node, "qcom,fg-cutoff-voltage", &temp);