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

Commit 9c83a371 authored by Harry Yang's avatar Harry Yang
Browse files

power: smb5-lib: Check Type-C attached status in moisture detection



Currently, lpd_ra_open_work is used for liquid presence detection and
to mitigate interrupt TYPEC_OR_RID_DETECTION_CHANGE_IRQ storm on
floating cable. This is applicable only for Type-C non-attached state
and hence it should be cancelled for other states.

Check TYPEC_TCCDEBOUNCE_DONE_STATUS_BIT to determine Type-C
attached status to fix this.

Also remove checking for TYPEC_WATER_DETECTION_STATUS_BIT
in typec_or_rid_detection_change interrupt handler as it is always set
when that interrupt fires.

Change-Id: I4477e0684f823335eda8cc7b471c3de50bee7b78
Signed-off-by: default avatarHarry Yang <harryy@codeaurora.org>
parent 4719c01d
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -4080,8 +4080,7 @@ irqreturn_t typec_or_rid_detection_change_irq_handler(int irq, void *data)
		goto out;
	}

	/* liquid presence detected, to check further */
	if ((stat & TYPEC_WATER_DETECTION_STATUS_BIT)
	if (!(stat & TYPEC_TCCDEBOUNCE_DONE_STATUS_BIT)
			&& chg->lpd_stage == LPD_STAGE_NONE) {
		chg->lpd_stage = LPD_STAGE_FLOAT;
		cancel_delayed_work_sync(&chg->lpd_ra_open_work);
@@ -4141,7 +4140,7 @@ irqreturn_t typec_attach_detach_irq_handler(int irq, void *data)
	}

	if (stat & TYPEC_ATTACH_DETACH_STATE_BIT) {
		chg->lpd_stage = LPD_STAGE_ATTACHED;
		chg->lpd_stage = LPD_STAGE_FLOAT_CANCEL;
		cancel_delayed_work_sync(&chg->lpd_ra_open_work);
		vote(chg->awake_votable, LPD_VOTER, false, 0);

@@ -4180,7 +4179,7 @@ irqreturn_t typec_attach_detach_irq_handler(int irq, void *data)
			chg->early_usb_attach = false;
		}

		chg->lpd_stage = LPD_STAGE_DETACHED;
		if (chg->lpd_stage == LPD_STAGE_FLOAT_CANCEL)
			schedule_delayed_work(&chg->lpd_detach_work,
					msecs_to_jiffies(100));
	}
@@ -4677,8 +4676,9 @@ static void smblib_lpd_ra_open_work(struct work_struct *work)
		goto out;
	}

	/* double check water detection status bit */
	if (!(stat & TYPEC_WATER_DETECTION_STATUS_BIT)) {
	/* quit if moisture status is gone or in attached state */
	if (!(stat & TYPEC_WATER_DETECTION_STATUS_BIT)
			|| (stat & TYPEC_TCCDEBOUNCE_DONE_STATUS_BIT)) {
		chg->lpd_stage = LPD_STAGE_NONE;
		goto out;
	}
@@ -4750,7 +4750,7 @@ static void smblib_lpd_detach_work(struct work_struct *work)
	struct smb_charger *chg = container_of(work, struct smb_charger,
							lpd_detach_work.work);

	if (chg->lpd_stage == LPD_STAGE_DETACHED)
	if (chg->lpd_stage == LPD_STAGE_FLOAT_CANCEL)
		chg->lpd_stage = LPD_STAGE_NONE;
}

+6 −2
Original line number Diff line number Diff line
@@ -204,11 +204,15 @@ enum lpd_reason {
	LPD_FLOATING_CABLE,
};

/* Following states are applicable only for floating cable during LPD */
enum lpd_stage {
	/* initial stage */
	LPD_STAGE_NONE,
	/* started and ongoing */
	LPD_STAGE_FLOAT,
	LPD_STAGE_ATTACHED,
	LPD_STAGE_DETACHED,
	/* cancel if started,  or don't start */
	LPD_STAGE_FLOAT_CANCEL,
	/* confirmed and mitigation measures taken for 60 s */
	LPD_STAGE_COMMIT,
};

+1 −0
Original line number Diff line number Diff line
@@ -328,6 +328,7 @@ enum {
#define TYPEC_WATER_DETECTION_STATUS_BIT	BIT(7)
#define SNK_SRC_MODE_BIT			BIT(6)
#define TYPEC_VBUS_ERROR_STATUS_BIT		BIT(4)
#define TYPEC_TCCDEBOUNCE_DONE_STATUS_BIT	BIT(3)
#define CC_ORIENTATION_BIT			BIT(1)
#define CC_ATTACHED_BIT				BIT(0)