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

Commit 81404d4d authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar Committed by Anirudh Ghayal
Browse files

smb-lib: allow hvdcp if pd is disabled



Currently when pd is disabled, we do not allow hvdcp. To fix that
once hvdcp timeout happens and if pd is disabled, force a pd_active
= 0. This will cause us to run legacy workaround and rerun apsd if
the charger was detected as hvdcp.

Importantly, once legacy bit workaround is run, wait 400mS for
typeC to debounce. Currently we wait for 100mS only and that
causes a removal detection since the CC lines are not settled within
100mS.

Also it may take up to 650mS for the vbus to drop once CC lines are
floated during the workaround. The current wait is just 500mS,
bump it up to a 1 second.

Change-Id: I17a7341e96d6efccde6270bc69d79c3f215b83e4
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent 15f77b01
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
@@ -2654,17 +2654,13 @@ int smblib_set_prop_usb_voltage_max(struct smb_charger *chg,
	return rc;
}

int smblib_set_prop_pd_active(struct smb_charger *chg,
			      const union power_supply_propval *val)
static int __smblib_set_prop_pd_active(struct smb_charger *chg, bool pd_active)
{
	int rc;
	bool orientation, sink_attached, hvdcp;
	u8 stat;

	if (!get_effective_result(chg->pd_allowed_votable))
		return -EINVAL;

	chg->pd_active = val->intval;
	chg->pd_active = pd_active;
	if (chg->pd_active) {
		vote(chg->apsd_disable_votable, PD_VOTER, true, 0);
		vote(chg->pd_allowed_votable, PD_VOTER, true, 0);
@@ -2752,6 +2748,15 @@ int smblib_set_prop_pd_active(struct smb_charger *chg,
	return rc;
}

int smblib_set_prop_pd_active(struct smb_charger *chg,
			      const union power_supply_propval *val)
{
	if (!get_effective_result(chg->pd_allowed_votable))
		return -EINVAL;

	return __smblib_set_prop_pd_active(chg, val->intval);
}

int smblib_set_prop_ship_mode(struct smb_charger *chg,
				const union power_supply_propval *val)
{
@@ -3496,6 +3501,13 @@ static void smblib_handle_hvdcp_check_timeout(struct smb_charger *chg,
			/* enforce DCP ICL if specified */
			vote(chg->usb_icl_votable, DCP_VOTER,
				chg->dcp_icl_ua != -EINVAL, chg->dcp_icl_ua);

		/*
		 * if pd is not allowed, then set pd_active = false right here,
		 * so that it starts the hvdcp engine
		 */
		if (!get_effective_result(chg->pd_allowed_votable))
			__smblib_set_prop_pd_active(chg, 0);
	}

	smblib_dbg(chg, PR_INTERRUPT, "IRQ: smblib_handle_hvdcp_check_timeout %s\n",
@@ -4469,7 +4481,9 @@ static void smblib_legacy_detection_work(struct work_struct *work)
		smblib_err(chg, "Couldn't disable type-c rc=%d\n", rc);

	/* wait for the adapter to turn off VBUS */
	msleep(500);
	msleep(1000);

	smblib_dbg(chg, PR_MISC, "legacy workaround enabling typec\n");

	rc = smblib_masked_write(chg,
				TYPE_C_INTRPT_ENB_SOFTWARE_CTRL_REG,
@@ -4478,7 +4492,7 @@ static void smblib_legacy_detection_work(struct work_struct *work)
		smblib_err(chg, "Couldn't enable type-c rc=%d\n", rc);

	/* wait for type-c detection to complete */
	msleep(100);
	msleep(400);

	rc = smblib_read(chg, TYPE_C_STATUS_5_REG, &stat);
	if (rc < 0) {
@@ -4490,6 +4504,8 @@ static void smblib_legacy_detection_work(struct work_struct *work)
	vote(chg->usb_icl_votable, LEGACY_UNKNOWN_VOTER, false, 0);
	legacy = stat & TYPEC_LEGACY_CABLE_STATUS_BIT;
	rp_high = chg->typec_mode == POWER_SUPPLY_TYPEC_SOURCE_HIGH;
	smblib_dbg(chg, PR_MISC, "legacy workaround done legacy = %d rp_high = %d\n",
			legacy, rp_high);
	if (!legacy || !rp_high)
		vote(chg->hvdcp_disable_votable_indirect, VBUS_CC_SHORT_VOTER,
								false, 0);