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

Commit e7f29456 authored by Nicholas Troast's avatar Nicholas Troast
Browse files

power: smb-lib: prevent unnecessary APSD re-runs



When APSD_START_ON_CC_BIT is set both VBUS and CC must be attached
before APSD runs. This eliminates all issues related to slow plugin.

Unfortunately this means that if CC is re-asserted anytime after APSD
finishes, then it will rerun again.

Fix this by disabling APSD_START_ON_CC_BIT right after CC is asserted,
and enable it after USB removal.

Change-Id: I27d3727647635b78392b925f0881dc3a4ef41623
Signed-off-by: default avatarNicholas Troast <ntroast@codeaurora.org>
parent c3e73c5a
Loading
Loading
Loading
Loading
+15 −28
Original line number Diff line number Diff line
@@ -1098,16 +1098,6 @@ static int smblib_apsd_disable_vote_callback(struct votable *votable,
	int rc;

	if (apsd_disable) {
		/* Don't run APSD on CC debounce when APSD is disabled */
		rc = smblib_masked_write(chg, TYPE_C_CFG_REG,
							APSD_START_ON_CC_BIT,
							0);
		if (rc < 0) {
			smblib_err(chg, "Couldn't disable APSD_START_ON_CC rc=%d\n",
									rc);
			return rc;
		}

		rc = smblib_masked_write(chg, USBIN_OPTIONS_1_CFG_REG,
							AUTO_SRC_DETECT_BIT,
							0);
@@ -1123,15 +1113,6 @@ static int smblib_apsd_disable_vote_callback(struct votable *votable,
			smblib_err(chg, "Couldn't enable APSD rc=%d\n", rc);
			return rc;
		}

		rc = smblib_masked_write(chg, TYPE_C_CFG_REG,
							APSD_START_ON_CC_BIT,
							APSD_START_ON_CC_BIT);
		if (rc < 0) {
			smblib_err(chg, "Couldn't enable APSD_START_ON_CC rc=%d\n",
									rc);
			return rc;
		}
	}

	return 0;
@@ -2684,12 +2665,6 @@ int smblib_reg_block_restore(struct smb_charger *chg,
}

static struct reg_info cc2_detach_settings[] = {
	{
		.reg	= TYPE_C_CFG_REG,
		.mask	= APSD_START_ON_CC_BIT,
		.val	= 0,
		.desc	= "TYPE_C_CFG_REG",
	},
	{
		.reg	= TYPE_C_CFG_2_REG,
		.mask	= TYPE_C_UFP_MODE_BIT | EN_TRY_SOURCE_MODE_BIT,
@@ -3568,6 +3543,8 @@ static void typec_sink_removal(struct smb_charger *chg)

static void smblib_handle_typec_removal(struct smb_charger *chg)
{
	int rc;

	vote(chg->pd_disallowed_votable_indirect, CC_DETACHED_VOTER, true, 0);
	vote(chg->pd_disallowed_votable_indirect, HVDCP_TIMEOUT_VOTER, true, 0);
	vote(chg->pd_disallowed_votable_indirect, LEGACY_CABLE_VOTER, true, 0);
@@ -3589,11 +3566,15 @@ static void smblib_handle_typec_removal(struct smb_charger *chg)
	chg->otg_attempts = 0;
	chg->pulse_cnt = 0;
	chg->usb_icl_delta_ua = 0;

	chg->usb_ever_removed = true;

	smblib_update_usb_type(chg);
	/* enable APSD CC trigger for next insertion */
	rc = smblib_masked_write(chg, TYPE_C_CFG_REG,
				APSD_START_ON_CC_BIT, APSD_START_ON_CC_BIT);
	if (rc < 0)
		smblib_err(chg, "Couldn't enable APSD_START_ON_CC rc=%d\n", rc);

	smblib_update_usb_type(chg);
	typec_source_removal(chg);
	typec_sink_removal(chg);
}
@@ -3601,12 +3582,18 @@ static void smblib_handle_typec_removal(struct smb_charger *chg)
static void smblib_handle_typec_insertion(struct smb_charger *chg,
		bool sink_attached, bool legacy_cable)
{
	int rp;
	int rp, rc;
	bool vbus_cc_short = false;
	bool valid_legacy_cable;

	vote(chg->pd_disallowed_votable_indirect, CC_DETACHED_VOTER, false, 0);

	/* disable APSD CC trigger since CC is attached */
	rc = smblib_masked_write(chg, TYPE_C_CFG_REG, APSD_START_ON_CC_BIT, 0);
	if (rc < 0)
		smblib_err(chg, "Couldn't disable APSD_START_ON_CC rc=%d\n",
									rc);

	if (sink_attached) {
		typec_source_removal(chg);
		typec_sink_insertion(chg);