charger: fix slower charging with NON-PD type-C charger

1. When charger type is detected as NON-PD type-C but usb icl is
   voted as 1500mA, it will cause wrong charging current.
   That is fixed by voting correct current.
2. NON-PD type-C charger with D+/D- open was detected as UNKNOWN charger.
   Fix it.

Bug: 112529920
Change-Id: I8818d632d64fd3ee82adb31043e68d0652c75003
Signed-off-by: Jack Wu <wjack@google.com>
diff --git a/drivers/power/htc_battery.c b/drivers/power/htc_battery.c
index 2b1cd8f..623ee14 100644
--- a/drivers/power/htc_battery.c
+++ b/drivers/power/htc_battery.c
@@ -1381,6 +1381,7 @@
 	unsigned long cur_jiffies;
 	int cc_uah_now;
 	int current_max = 0;
+	int typec_sink = 0;
 	char chg_strbuf[20];
 	/* reference from power_supply.h power_supply_type */
 	char *chr_src[] = {"NONE", "BATTERY", "UPS", "MAINS", "USB",
@@ -1481,16 +1482,21 @@
 		} else {
 			/* WA: QCT  recorgnize D+/D- open charger won't set 500mA. */
 			if ((htc_batt_info.rep.charging_source == POWER_SUPPLY_TYPE_USB)) {
-				user_set_chg_curr = get_property(htc_batt_info.usb_psy, POWER_SUPPLY_PROP_CURRENT_MAX);
-				if (!get_connect2pc() && !g_rerun_apsd_done && !g_is_unknown_charger) {
-					user_set_chg_curr = SLOW_CHARGE_CURR;
-					if (delayed_work_pending(&htc_batt_info.chk_unknown_chg_work))
-						cancel_delayed_work(&htc_batt_info.chk_unknown_chg_work);
-					schedule_delayed_work(&htc_batt_info.chk_unknown_chg_work,
-							msecs_to_jiffies(CHG_UNKNOWN_CHG_PERIOD_MS));
+				typec_sink = get_property(htc_batt_info.batt_psy, POWER_SUPPLY_PROP_TYPEC_SINK_CURRENT);
+				if (typec_sink){
+					//Souce type is USB TYPE_C, Ignore WA.
 				} else {
-					if (user_set_chg_curr < SLOW_CHARGE_CURR)
+					user_set_chg_curr = get_property(htc_batt_info.usb_psy, POWER_SUPPLY_PROP_CURRENT_MAX);
+					if (!get_connect2pc() && !g_rerun_apsd_done && !g_is_unknown_charger) {
 						user_set_chg_curr = SLOW_CHARGE_CURR;
+						if (delayed_work_pending(&htc_batt_info.chk_unknown_chg_work))
+							cancel_delayed_work(&htc_batt_info.chk_unknown_chg_work);
+						schedule_delayed_work(&htc_batt_info.chk_unknown_chg_work,
+								msecs_to_jiffies(CHG_UNKNOWN_CHG_PERIOD_MS));
+					} else {
+						if (user_set_chg_curr < SLOW_CHARGE_CURR)
+							user_set_chg_curr = SLOW_CHARGE_CURR;
+					}
 				}
 			} else if (htc_batt_info.rep.charging_source == POWER_SUPPLY_TYPE_USB_HVDCP){
 				user_set_chg_curr = get_property(htc_batt_info.usb_psy, POWER_SUPPLY_PROP_CURRENT_MAX);
diff --git a/drivers/power/qpnp-smbcharger.c b/drivers/power/qpnp-smbcharger.c
index 857b9d9..9f83661 100644
--- a/drivers/power/qpnp-smbcharger.c
+++ b/drivers/power/qpnp-smbcharger.c
@@ -5084,11 +5084,6 @@
 			current_limit_ma = 3000;
 		power_supply_set_current_limit(chip->usb_psy,
 			current_limit_ma * 1000);
-
-		/* To make sure Type-C charger do have the ability to work at
-		   3A high current mode, need go through 5v2a detect worker
-		   before setting 3A, so set default low current right here */
-		current_limit_ma = DEFAULT_TYPEC_MA;
 	} else
 #endif /* CONFIG_HTC_BATT */
 	if (chip->typec_psy && (type != POWER_SUPPLY_TYPE_USB))