power: qpnp-smbcharger: update iusb only at beginning of charging

Since AICL result cannot be larger than maximum input current
setting, do not update maximum input current again when it is
already determined. If not, maximum input current could be
lower by a short input voltage drop and the AICL result never
goes back to the higher value.

Bug: 24372404

Change-Id: I20ef13f621d6b8cb95729f9d582639f7f6ab4b35
Signed-off-by: choongryeol.lee <choongryeol.lee@lge.com>
diff --git a/drivers/power/qpnp-smbcharger.c b/drivers/power/qpnp-smbcharger.c
index 571493e..0df90cc 100644
--- a/drivers/power/qpnp-smbcharger.c
+++ b/drivers/power/qpnp-smbcharger.c
@@ -245,6 +245,7 @@
 	int				parallel_ibat_ma;
 	struct completion		aicl_rerun_done;
 	bool				disable_parallel_check;
+	bool				iusb_update_done;
 };
 
 enum print_reason {
@@ -1663,6 +1664,7 @@
 	taper_irq_en(chip, false);
 	chip->parallel.initial_aicl_ma = 0;
 	chip->parallel.current_max_ma = 0;
+	chip->iusb_update_done = true;
 	power_supply_set_current_limit(parallel_psy,
 				SUSPEND_CURRENT_MA * 1000);
 	power_supply_set_present(parallel_psy, false);
@@ -1917,6 +1919,7 @@
 		pr_smb(PR_STATUS, "parallel charging unavailable\n");
 		smbchg_parallel_usb_disable(chip);
 	}
+	chip->iusb_update_done = true;
 	mutex_unlock(&chip->parallel.lock);
 }
 
@@ -1937,6 +1940,8 @@
 	} else if (chip->parallel.current_max_ma != 0) {
 		pr_smb(PR_STATUS, "parallel charging unavailable\n");
 		smbchg_parallel_usb_disable(chip);
+	} else {
+		chip->iusb_update_done = true;
 	}
 	mutex_unlock(&chip->parallel.lock);
 }
@@ -3178,8 +3183,10 @@
 		if (rc < 0)
 			dev_err(chip->dev,
 				"Couldn't set usb current rc = %d\n", rc);
-		if (chip->usb_cc_controller && current_limit > 0)
+		if (chip->usb_cc_controller && current_limit > 0) {
+			chip->iusb_update_done = false;
 			smbchg_wait_first_aicl_done(chip);
+		}
 		smbchg_parallel_usb_check_ok(chip);
 	}
 	mutex_unlock(&chip->current_change_lock);
@@ -4787,7 +4794,8 @@
 	if (chip->aicl_complete)
 		complete_all(&chip->aicl_rerun_done);
 
-	if (chip->usb_cc_controller && !chip->parallel.initial_aicl_ma)
+	if (chip->usb_cc_controller && !chip->parallel.initial_aicl_ma
+					&& !chip->iusb_update_done)
 		smbchg_update_input_max(chip);
 
 	if (usb_present)