Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1df95494 authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar
Browse files

power: qpnp-smbcharger: skip usb psy input current unless SDP



Since the charger can detect the USB type it need not wait on usb power
supply (usb psy) to inform how much current to draw from the charger.

Set the charge current to 1.8A if DCP or HVDCP and 1.5A if CDP. For SDP
draw just 100mA and wait for usb driver to negotiate with the host to draw
more current.

Note that APSD is expected to be disabled only when HVDCP detection is
in progress. In such a case the type of the charger reported will be
NONE. The code treats this situation correctly by setting the limit
defined for a wall charger.

Change-Id: I9d2a927450929546aee09ab6e530251cf59d6521
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent 59a77e7c
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -1495,8 +1495,8 @@ static int smbchg_set_usb_current_max(struct smbchg_chip *chip,
	}

out:
	pr_smb(PR_STATUS, "usb current set to %d mA\n",
			chip->usb_max_current_ma);
	pr_smb(PR_STATUS, "usb type = %s current set to %d mA\n",
			usb_type_name, chip->usb_max_current_ma);
	return rc;
}

@@ -3091,6 +3091,8 @@ static void smbchg_external_power_changed(struct power_supply *psy)
				struct smbchg_chip, batt_psy);
	union power_supply_propval prop = {0,};
	int rc, current_limit = 0, soc;
	enum power_supply_type usb_supply_type;
	char *usb_type_name = "null";

	if (chip->bms_psy_name)
		chip->bms_psy =
@@ -3122,7 +3124,12 @@ static void smbchg_external_power_changed(struct power_supply *psy)
	if (rc != 0)
		current_limit = prop.intval / 1000;

	pr_smb(PR_MISC, "current_limit = %d\n", current_limit);
	read_usb_type(chip, &usb_type_name, &usb_supply_type);
	if (usb_supply_type != POWER_SUPPLY_TYPE_USB)
		goto  skip_current_for_non_sdp;

	pr_smb(PR_MISC, "usb type = %s current_limit = %d\n",
			usb_type_name, current_limit);
	mutex_lock(&chip->current_change_lock);
	if (current_limit != chip->usb_target_current_ma) {
		pr_smb(PR_STATUS, "changed current_limit = %d\n",
@@ -3136,6 +3143,7 @@ static void smbchg_external_power_changed(struct power_supply *psy)
	}
	mutex_unlock(&chip->current_change_lock);

skip_current_for_non_sdp:
	smbchg_vfloat_adjust_check(chip);

	power_supply_changed(&chip->batt_psy);
@@ -3882,6 +3890,9 @@ static bool is_src_detect_high(struct smbchg_chip *chip)
}

#define HVDCP_NOTIFY_MS		2500
#define DEFAULT_WALL_CHG_MA	1800
#define DEFAULT_SDP_MA		100
#define DEFAULT_CDP_MA		1500
static void handle_usb_insertion(struct smbchg_chip *chip)
{
	struct power_supply *parallel_psy = get_parallel_psy(chip);
@@ -3928,6 +3939,21 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
	if (usb_supply_type == POWER_SUPPLY_TYPE_USB_DCP)
		schedule_delayed_work(&chip->hvdcp_det_work,
					msecs_to_jiffies(HVDCP_NOTIFY_MS));

	mutex_lock(&chip->current_change_lock);
	if (usb_supply_type == POWER_SUPPLY_TYPE_USB)
		chip->usb_target_current_ma = DEFAULT_SDP_MA;
	else if (usb_supply_type == POWER_SUPPLY_TYPE_USB_CDP)
		chip->usb_target_current_ma = DEFAULT_CDP_MA;
	else
		chip->usb_target_current_ma = DEFAULT_WALL_CHG_MA;

	pr_smb(PR_STATUS, "%s detected setting mA = %d\n",
		usb_type_name, chip->usb_target_current_ma);
	rc = smbchg_set_thermal_limited_usb_current_max(chip,
				chip->usb_target_current_ma);
	mutex_unlock(&chip->current_change_lock);

	if (parallel_psy) {
		rc = power_supply_set_present(parallel_psy, true);
		chip->parallel_charger_detected = rc ? false : true;