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

Commit d8bc42f4 authored by Ashay Jaiswal's avatar Ashay Jaiswal Committed by Guru Das Srinagesh
Browse files

power: smb5: add legacy-cable detection logic



Charger h/w legacy-cable detection fails if the device is rebooted
with charger connected. Fix this by resetting Type-C state machine
by disabling/enabling TypeC module.

Change-Id: I26e78123f7a60adbeceeaa7acd5dc9b83306b19f
Signed-off-by: default avatarAshay Jaiswal <ashayj@codeaurora.org>
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent 99041e20
Loading
Loading
Loading
Loading
+35 −0
Original line number Original line Diff line number Diff line
@@ -1639,7 +1639,42 @@ static int smb5_init_vconn_regulator(struct smb5 *chip)
 ***************************/
 ***************************/
static int smb5_configure_typec(struct smb_charger *chg)
static int smb5_configure_typec(struct smb_charger *chg)
{
{
	union power_supply_propval pval = {0, };
	int rc;
	int rc;
	u8 val = 0;

	rc = smblib_read(chg, LEGACY_CABLE_STATUS_REG, &val);
	if (rc < 0) {
		dev_err(chg->dev, "Couldn't read Legacy status rc=%d\n", rc);
		return rc;
	}

	/*
	 * Across reboot, standard typeC cables get detected as legacy cables
	 * due to VBUS attachment prior to CC attach/dettach. To handle this,
	 * "early_usb_attach" flag is used, which assumes that across reboot,
	 * the cable connected can be standard typeC. However, its jurisdiction
	 * is limited to PD capable designs only. Hence, for non-PD type designs
	 * reset legacy cable detection by disabling/enabling typeC mode.
	 */
	if (chg->pd_not_supported && (val & TYPEC_LEGACY_CABLE_STATUS_BIT)) {
		pval.intval = POWER_SUPPLY_TYPEC_PR_NONE;
		smblib_set_prop_typec_power_role(chg, &pval);
		if (rc < 0) {
			dev_err(chg->dev, "Couldn't disable TYPEC rc=%d\n", rc);
			return rc;
		}

		/* delay before enabling typeC */
		msleep(50);

		pval.intval = POWER_SUPPLY_TYPEC_PR_DUAL;
		smblib_set_prop_typec_power_role(chg, &pval);
		if (rc < 0) {
			dev_err(chg->dev, "Couldn't enable TYPEC rc=%d\n", rc);
			return rc;
		}
	}


	smblib_apsd_enable(chg, true);
	smblib_apsd_enable(chg, true);
	smblib_hvdcp_detect_enable(chg, false);
	smblib_hvdcp_detect_enable(chg, false);