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

Commit 11a54fcf authored by Nicholas Troast's avatar Nicholas Troast
Browse files

power: smb-lib: always assume legacy cable to prevent CC OV



While in DRP the legacy cable detection may fail. Legacy cable
detection is essential to preventing CC OV damage.

Always assume a legacy cable since the legacy cable detection will fail
in some cases. As a side effect, non-legacy HVDCP adapters will stay at
5V if they have a 10k ohm Rp.

To realize this:
- Remove disallowing PD based on the legacy bit being set. That bit set
  or unset is not reliable and it is safe to try PD.
- Remove the workaround which tries to fix legacy cable being set
  incorrectly at boot. That bit set or unset is not reliable.

Change-Id: I37879866592f63906a7c688f51c309b4e2fee48d
Signed-off-by: default avatarNicholas Troast <ntroast@codeaurora.org>
parent fa12cb53
Loading
Loading
Loading
Loading
+11 −38
Original line number Diff line number Diff line
@@ -702,21 +702,6 @@ static void smblib_uusb_removal(struct smb_charger *chg)
			rc);
}

static bool smblib_sysok_reason_usbin(struct smb_charger *chg)
{
	int rc;
	u8 stat;

	rc = smblib_read(chg, SYSOK_REASON_STATUS_REG, &stat);
	if (rc < 0) {
		smblib_err(chg, "Couldn't get SYSOK_REASON_STATUS rc=%d\n", rc);
		/* assuming 'not usbin' in case of read failure */
		return false;
	}

	return stat & SYSOK_REASON_USBIN_BIT;
}

void smblib_suspend_on_debug_battery(struct smb_charger *chg)
{
	int rc;
@@ -3518,8 +3503,6 @@ static void smblib_handle_typec_removal(struct smb_charger *chg)

	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);
	vote(chg->pd_disallowed_votable_indirect, VBUS_CC_SHORT_VOTER, true, 0);
	vote(chg->pl_disable_votable, PL_DELAY_HVDCP_VOTER, true, 0);

	/* reset votes from vbus_cc_short */
@@ -3537,7 +3520,6 @@ 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;

	/* enable APSD CC trigger for next insertion */
	rc = smblib_masked_write(chg, TYPE_C_CFG_REG,
@@ -3554,8 +3536,6 @@ static void smblib_handle_typec_insertion(struct smb_charger *chg,
		bool sink_attached, bool legacy_cable)
{
	int rp, rc;
	bool vbus_cc_short = false;
	bool valid_legacy_cable;

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

@@ -3573,25 +3553,18 @@ static void smblib_handle_typec_insertion(struct smb_charger *chg,
		typec_sink_removal(chg);
	}

	valid_legacy_cable = legacy_cable &&
		(chg->usb_ever_removed || !smblib_sysok_reason_usbin(chg));
	vote(chg->pd_disallowed_votable_indirect, LEGACY_CABLE_VOTER,
			valid_legacy_cable, 0);

	if (valid_legacy_cable) {
	rp = smblib_get_prop_ufp_mode(chg);
	if (rp == POWER_SUPPLY_TYPEC_SOURCE_HIGH
			|| rp == POWER_SUPPLY_TYPEC_NON_COMPLIANT) {
			vbus_cc_short = true;
			smblib_err(chg, "Disabling PD and HVDCP, VBUS-CC shorted, rp = %d found\n",
					rp);
		}
	}

		smblib_dbg(chg, PR_MISC, "VBUS & CC could be shorted; keeping HVDCP disabled\n");
		/* HVDCP is not going to be enabled; enable parallel */
		vote(chg->pl_disable_votable, PL_DELAY_HVDCP_VOTER, false, 0);
		vote(chg->hvdcp_disable_votable_indirect, VBUS_CC_SHORT_VOTER,
			vbus_cc_short, 0);
	vote(chg->pd_disallowed_votable_indirect, VBUS_CC_SHORT_VOTER,
			vbus_cc_short, 0);
								true, 0);
	} else {
		vote(chg->hvdcp_disable_votable_indirect, VBUS_CC_SHORT_VOTER,
								false, 0);
	}
}

static void smblib_handle_typec_debounce_done(struct smb_charger *chg,
+0 −2
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ enum print_reason {
#define PD_DISALLOWED_INDIRECT_VOTER	"PD_DISALLOWED_INDIRECT_VOTER"
#define PD_HARD_RESET_VOTER		"PD_HARD_RESET_VOTER"
#define VBUS_CC_SHORT_VOTER		"VBUS_CC_SHORT_VOTER"
#define LEGACY_CABLE_VOTER		"LEGACY_CABLE_VOTER"
#define PD_INACTIVE_VOTER		"PD_INACTIVE_VOTER"
#define BOOST_BACK_VOTER		"BOOST_BACK_VOTER"
#define HVDCP_INDIRECT_VOTER		"HVDCP_INDIRECT_VOTER"
@@ -316,7 +315,6 @@ struct smb_charger {

	/* extcon for VBUS / ID notification to USB for uUSB */
	struct extcon_dev	*extcon;
	bool			usb_ever_removed;

	int			icl_reduction_ua;