power: qpnp-smbcharger: reduce USB ICL to 500mA while shutting down

In the shutdown path the driver resets PMI's USB ICL to HVDCP limits while
disabling parallel charger and right after that the driver reruns AICL
by momentarily disabling it. Some HVDCP chargers collapse during this
time because the PMI attempts to draw the HVDCP limit current (default
2.7A).

To avoid this situation, reduce ICL to 500mA. The system is going to
shutdown and even though this register is dVdd backed, the CSIR
initialization will reset the ICL back to a higher value.

CRs-Fixed: 991066
Change-Id: I690b604435b03779cef40314bba262d4c684a7c0
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Signed-off-by: Vamshi Krishna B V <vbv@codeaurora.org>
diff --git a/drivers/power/supply/qcom/qpnp-smbcharger.c b/drivers/power/supply/qcom/qpnp-smbcharger.c
index 868e918..944de9d 100644
--- a/drivers/power/supply/qcom/qpnp-smbcharger.c
+++ b/drivers/power/supply/qcom/qpnp-smbcharger.c
@@ -352,6 +352,7 @@
 #define WEAK_CHARGER_ICL_VOTER	"WEAK_CHARGER_ICL_VOTER"
 #define SW_AICL_ICL_VOTER	"SW_AICL_ICL_VOTER"
 #define CHG_SUSPEND_WORKAROUND_ICL_VOTER "CHG_SUSPEND_WORKAROUND_ICL_VOTER"
+#define SHUTDOWN_WORKAROUND_ICL_VOTER "SHUTDOWN_WORKAROUND_ICL_VOTER"
 
 /* USB SUSPEND VOTERS */
 /* userspace has suspended charging altogether */
@@ -8413,6 +8414,12 @@
 	if (!is_hvdcp_present(chip))
 		return;
 
+	pr_smb(PR_MISC, "Reducing to 500mA\n");
+	rc = vote(chip->usb_icl_votable, SHUTDOWN_WORKAROUND_ICL_VOTER, true,
+			500);
+	if (rc < 0)
+		pr_err("Couldn't vote 500mA ICL\n");
+
 	pr_smb(PR_MISC, "Disable Parallel\n");
 	mutex_lock(&chip->parallel.lock);
 	smbchg_parallel_en = 0;