Setting jeita fv re-charge voltage for warm temp

Jeita fv stop charging when battery temp is warm, but without
use HW re-charge. To fix this, add a dynamic re-charge
function for warm temp's HW re-charge.

Issue: FP3-A11#230
Change-Id: I9343ab687113f03d93cecb8baa5e8ac794cf7f7b
diff --git a/drivers/power/supply/qcom/smb5-lib.c b/drivers/power/supply/qcom/smb5-lib.c
old mode 100644
new mode 100755
index 1fae678..7670e5d
--- a/drivers/power/supply/qcom/smb5-lib.c
+++ b/drivers/power/supply/qcom/smb5-lib.c
@@ -1236,6 +1236,36 @@
 	return 0;
 }
 
+static int smblib_jeita_rechg_voltage_vote_callback(struct votable *votable, void *data,
+			int voltage, const char *client)
+{
+	struct smb_charger *chg = data;
+	int rc = 0;
+	u32 temp = VBAT_TO_VRAW_ADC((voltage/1000));
+
+	temp = ((temp & 0xFF00) >> 8) | ((temp & 0xFF) << 8);
+	rc = smblib_batch_write(chg,
+		CHGR_ADC_RECHARGE_THRESHOLD_MSB_REG, (u8 *)&temp, 2);
+	if (rc < 0) {
+		dev_err(chg->dev, "Couldn't configure ADC_RECHARGE_THRESHOLD REG rc=%d\n",
+			rc);
+		return rc;
+	}
+	/* Program the sample count for VBAT based recharge to 3 */
+	rc = smblib_masked_write(chg, CHGR_NO_SAMPLE_TERM_RCHG_CFG_REG,
+				NO_OF_SAMPLE_FOR_RCHG,
+				2 << NO_OF_SAMPLE_FOR_RCHG_SHIFT);
+	if (rc < 0) {
+		dev_err(chg->dev, "Couldn't configure CHGR_NO_SAMPLE_FOR_TERM_RCHG_CFG rc=%d\n",
+			rc);
+		return rc;
+	}
+
+	dev_err(chg->dev, "jeita_rechg_voltage =%d\n", voltage);
+
+	return rc;
+}
+
 /*******************
  * VCONN REGULATOR *
  * *****************/
@@ -4521,6 +4551,14 @@
 		return rc;
 	}
 
+	chg->rechg_vol_votable = create_votable("RECHG_VOL", VOTE_MIN,
+					smblib_jeita_rechg_voltage_vote_callback,
+					chg);
+	if (IS_ERR(chg->rechg_vol_votable)) {
+		rc = PTR_ERR(chg->rechg_vol_votable);
+		return rc;
+	}
+
 	return rc;
 }
 
diff --git a/drivers/power/supply/qcom/smb5-lib.h b/drivers/power/supply/qcom/smb5-lib.h
old mode 100644
new mode 100755
index 4911047..e7dd8be
--- a/drivers/power/supply/qcom/smb5-lib.h
+++ b/drivers/power/supply/qcom/smb5-lib.h
@@ -347,6 +347,7 @@
 	struct votable		*chg_disable_votable;
 	struct votable		*pl_enable_votable_indirect;
 	struct votable		*usb_irq_enable_votable;
+	struct votable		*rechg_vol_votable;
 
 	/* work */
 	struct work_struct	bms_update_work;
diff --git a/drivers/power/supply/qcom/step-chg-jeita.c b/drivers/power/supply/qcom/step-chg-jeita.c
old mode 100644
new mode 100755
index 3e8b46b..4262d70
--- a/drivers/power/supply/qcom/step-chg-jeita.c
+++ b/drivers/power/supply/qcom/step-chg-jeita.c
@@ -80,6 +80,7 @@
 	struct votable		*fcc_votable;
 	struct votable		*fv_votable;
 	struct votable		*usb_icl_votable;
+	struct votable		*rechg_vol_votable;
 	struct wakeup_source	*step_chg_ws;
 	struct power_supply	*batt_psy;
 	struct power_supply	*bms_psy;
@@ -500,6 +501,8 @@
 }
 
 #define JEITA_SUSPEND_HYST_UV		50000
+#define JEITA_RECHG_HYST_UV		200000//100000
+
 static int handle_jeita(struct step_chg_info *chip)
 {
 	union power_supply_propval pval = {0, };
@@ -561,6 +564,9 @@
 	if (rc < 0)
 		fv_uv = 0;
 
+	if (!chip->rechg_vol_votable)
+		chip->rechg_vol_votable = find_votable("RECHG_VOL");
+
 	chip->fv_votable = find_votable("FV");
 	if (!chip->fv_votable)
 		goto update_time;
@@ -597,6 +603,8 @@
 
 set_jeita_fv:
 	vote(chip->fv_votable, JEITA_VOTER, fv_uv ? true : false, fv_uv);
+	vote(chip->rechg_vol_votable,
+			JEITA_VOTER, true, (fv_uv -JEITA_RECHG_HYST_UV));
 
 update_time:
 	chip->jeita_last_update_time = ktime_get();