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

Commit 197358e5 authored by Harry Yang's avatar Harry Yang
Browse files

power: smb5-lib: update liquid presence detection flow



Currently, in the case where neither device attach nor E-Mark
cable is detected after crude sensor trip, moisture presence is
decided and type-C block is put to sink mode.

However, inserting a legacy cable with the other end floating
can trip the crude sensor which can trigger a false positive
for moisture detection.

Fix this by checking SBU resistance after the crude sensor
trips. Confirm the moisture detection only if the resistance
is low on at least one SBU pin.

Change-Id: Ia43c27eb4026f5ff991cb5073ddb3912e4f4825a
Signed-off-by: default avatarHarry Yang <harryy@codeaurora.org>
parent 4719c01d
Loading
Loading
Loading
Loading
+15 −16
Original line number Diff line number Diff line
@@ -4689,8 +4689,8 @@ static void smblib_lpd_ra_open_work(struct work_struct *work)
	pval.intval = POWER_SUPPLY_TYPEC_PR_SOURCE;
	rc = smblib_set_prop_typec_power_role(chg, &pval);
	if (rc < 0) {
		smblib_err(chg, "Couldn't write 0x%02x to TYPE_C_INTRPT_ENB_SOFTWARE_CTRL rc=%d\n",
			pval.intval, rc);
		smblib_err(chg, "Couldn't set typec source only mode rc=%d\n",
					rc);
		goto out;
	}

@@ -4704,9 +4704,19 @@ static void smblib_lpd_ra_open_work(struct work_struct *work)
		goto out;
	}

	/* Emark cable */
	if ((stat & SRC_RA_OPEN_BIT) &&
			!smblib_rsbux_low(chg, RSBU_K_300K_UV)) {
	if (smblib_rsbux_low(chg, RSBU_K_300K_UV)) {
		/* Moisture detected, enable sink only mode */
		pval.intval = POWER_SUPPLY_TYPEC_PR_SINK;
		rc = smblib_set_prop_typec_power_role(chg, &pval);
		if (rc < 0) {
			smblib_err(chg, "Couldn't set typec sink only rc=%d\n",
				rc);
			goto out;
		}

		chg->lpd_reason = LPD_MOISTURE_DETECTED;

	} else {
		/* Floating cable, disable water detection irq temporarily */
		rc = smblib_masked_write(chg, TYPE_C_INTERRUPT_EN_CFG_2_REG,
					TYPEC_WATER_DETECTION_INT_EN_BIT, 0);
@@ -4726,17 +4736,6 @@ static void smblib_lpd_ra_open_work(struct work_struct *work)
		}

		chg->lpd_reason = LPD_FLOATING_CABLE;
	} else {
		/* Moisture detected, enable sink only mode */
		pval.intval = POWER_SUPPLY_TYPEC_PR_SINK;
		rc = smblib_set_prop_typec_power_role(chg, &pval);
		if (rc < 0) {
			smblib_err(chg, "Couldn't write 0x%02x to TYPE_C_INTRPT_ENB_SOFTWARE_CTRL rc=%d\n",
				pval.intval, rc);
			goto out;
		}

		chg->lpd_reason = LPD_MOISTURE_DETECTED;
	}

	/* recheck in 60 seconds */