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

Commit 7af26138 authored by Ashay Jaiswal's avatar Ashay Jaiswal Committed by Vamshi Krishna B V
Browse files

power: qpnp-smbcharger: re-arrange parallel charger detection check



In scenarios where fast-charge/taper interrupt fires even before
src_detect_handler detects the parallel charger, parallel charging
will remain disabled. Fix this by adding a parallel charger detection
check in fastcharge and taper handler.
Also Force input current limit to 300mA during QC3.0 DP/DM pulsing
for PMI8950.

CRs-Fixed: 984187
Change-Id: I082cad6cf1bc3e8d9a5c327222f72d046190f9ca
Signed-off-by: default avatarAshay Jaiswal <ashayj@codeaurora.org>
Signed-off-by: default avatarVamshi Krishna B V <vbv@codeaurora.org>
parent 23765c48
Loading
Loading
Loading
Loading
+41 −24
Original line number Diff line number Diff line
@@ -1883,6 +1883,22 @@ static bool smbchg_is_usbin_active_pwr_src(struct smbchg_chip *chip)
		&& (reg & USBIN_ACTIVE_PWR_SRC_BIT);
}

static void smbchg_detect_parallel_charger(struct smbchg_chip *chip)
{
	int rc;
	struct power_supply *parallel_psy = get_parallel_psy(chip);
	union power_supply_propval pval = {0, };

	if (parallel_psy) {
		pval.intval = true;
		rc = power_supply_set_property(parallel_psy,
				POWER_SUPPLY_PROP_PRESENT, &pval);
		chip->parallel_charger_detected = rc ? false : true;
		if (rc)
			pr_debug("parallel-charger absent rc=%d\n", rc);
	}
}

static int smbchg_parallel_usb_charging_en(struct smbchg_chip *chip, bool en)
{
	struct power_supply *parallel_psy = get_parallel_psy(chip);
@@ -2020,7 +2036,8 @@ static void smbchg_parallel_usb_taper(struct smbchg_chip *chip)
	int parallel_fcc_ma, tries = 0;
	u8 reg = 0;

	if (!parallel_psy || !chip->parallel_charger_detected)
	smbchg_detect_parallel_charger(chip);
	if (!chip->parallel_charger_detected)
		return;

	smbchg_stay_awake(chip, PM_PARALLEL_TAPER);
@@ -4588,11 +4605,6 @@ static void restore_from_hvdcp_detection(struct smbchg_chip *chip)
{
	int rc;

	pr_smb(PR_MISC, "Retracting HVDCP vote for ICL\n");
	rc = vote(chip->usb_icl_votable, HVDCP_ICL_VOTER, false, 0);
	if (rc < 0)
		pr_err("Couldn't retract HVDCP ICL vote rc=%d\n", rc);

	/* switch to 9V HVDCP */
	rc = smbchg_sec_masked_write(chip, chip->usb_chgpth_base + CHGPTH_CFG,
				HVDCP_ADAPTER_SEL_MASK, HVDCP_9V);
@@ -4625,6 +4637,19 @@ static void restore_from_hvdcp_detection(struct smbchg_chip *chip)

	chip->hvdcp_3_det_ignore_uv = false;
	chip->pulse_cnt = 0;

	if ((chip->schg_version == QPNP_SCHG_LITE)
				&& is_hvdcp_present(chip)) {
		pr_smb(PR_MISC, "Forcing 9V HVDCP 2.0\n");
		rc = force_9v_hvdcp(chip);
		if (rc)
			pr_err("Failed to force 9V HVDCP=%d\n",	rc);
	}

	pr_smb(PR_MISC, "Retracting HVDCP vote for ICL\n");
	rc = vote(chip->usb_icl_votable, HVDCP_ICL_VOTER, false, 0);
	if (rc < 0)
		pr_err("Couldn't retract HVDCP ICL vote rc=%d\n", rc);
}

#define RESTRICTED_CHG_FCC_PERCENT	50
@@ -4721,8 +4746,6 @@ static bool is_usbin_uv_high(struct smbchg_chip *chip)
#define HVDCP_NOTIFY_MS		2500
static void handle_usb_insertion(struct smbchg_chip *chip)
{
	struct power_supply *parallel_psy = get_parallel_psy(chip);
	union power_supply_propval pval = {0, };
	enum power_supply_type usb_supply_type;
	int rc;
	char *usb_type_name = "null";
@@ -4769,14 +4792,7 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
					msecs_to_jiffies(HVDCP_NOTIFY_MS));
	}

	if (parallel_psy) {
		pval.intval = true;
		rc = power_supply_set_property(parallel_psy,
				POWER_SUPPLY_PROP_PRESENT, &pval);
		chip->parallel_charger_detected = rc ? false : true;
		if (rc)
			pr_debug("parallel-charger absent rc=%d\n", rc);
	}
	smbchg_detect_parallel_charger(chip);

	if (chip->parallel.avail && chip->aicl_done_irq
			&& !chip->enable_aicl_wake) {
@@ -5436,6 +5452,12 @@ static int smbchg_prepare_for_pulsing_lite(struct smbchg_chip *chip)
{
	int rc = 0;

	pr_smb(PR_MISC, "HVDCP voting for 300mA ICL\n");
	rc = vote(chip->usb_icl_votable, HVDCP_ICL_VOTER, true, 300);
	if (rc < 0) {
		pr_err("Couldn't vote for 300mA HVDCP ICL rc=%d\n", rc);
		return rc;
	}
	/* check if HVDCP is already in 5V continuous mode */
	if (is_hvdcp_5v_cont_mode(chip)) {
		pr_smb(PR_MISC, "HVDCP by default is in 5V continuous mode\n");
@@ -5462,13 +5484,6 @@ static int smbchg_prepare_for_pulsing_lite(struct smbchg_chip *chip)
		goto out;
	}

	pr_smb(PR_MISC, "HVDCP voting for 300mA ICL\n");
	rc = vote(chip->usb_icl_votable, HVDCP_ICL_VOTER, true, 300);
	if (rc < 0) {
		pr_err("Couldn't vote for 300mA HVDCP ICL rc=%d\n", rc);
		goto out;
	}

	pr_smb(PR_MISC, "Disable AICL\n");
	smbchg_sec_masked_write(chip, chip->usb_chgpth_base + USB_AICL_CFG,
			AICL_EN_BIT, 0);
@@ -6269,8 +6284,10 @@ static irqreturn_t fastchg_handler(int irq, void *_chip)
	struct smbchg_chip *chip = _chip;

	pr_smb(PR_INTERRUPT, "p2f triggered\n");
	if (is_usb_present(chip) || is_dc_present(chip))
	if (is_usb_present(chip) || is_dc_present(chip)) {
		smbchg_detect_parallel_charger(chip);
		smbchg_parallel_usb_check_ok(chip);
	}
	if (chip->batt_psy)
		power_supply_changed(chip->batt_psy);
	smbchg_charging_status_change(chip);