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

Commit eda06a9d authored by Jack Pham's avatar Jack Pham
Browse files

usb: dwc3-msm: Fix check for device suspend



The check in dwc3_msm_suspend() for whether the controller is
in peripheral mode only looks at the charger type being either
SDP or CDP. However, that does not accommodate if the charger
type is unknown, or if SDP/CDP are erroneously detected during
host mode, in which case the device LPM sequence would wrongly
get performed. Instead, check if the OTG state is B_PERIPHERAL.
Also move the checks for pending gadget interrupts and BAM LPM
status under this condition since they're unneeded for host mode.

Change-Id: I7f7be50f3392f6e6b0ccbefc83cd59b3f85a01e2
Signed-off-by: default avatarJack Pham <jackp@codeaurora.org>
parent 86c28639
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -1579,7 +1579,7 @@ static int dwc3_msm_suspend(struct dwc3_msm *mdwc)
	bool host_bus_suspend;
	bool host_ss_active;
	bool can_suspend_ssphy;
	bool device_bus_suspend;
	bool device_bus_suspend = false;
	struct dwc3 *dwc = platform_get_drvdata(mdwc->dwc3);

	dev_dbg(mdwc->dev, "%s: entering lpm. usb_lpm_override:%d\n",
@@ -1596,9 +1596,11 @@ static int dwc3_msm_suspend(struct dwc3_msm *mdwc)
		return 0;
	}

	/* pending device events need to be handled by dwc3_thread_interrupt */
	if (mdwc->dwc3) {
		struct dwc3 *dwc = platform_get_drvdata(mdwc->dwc3);
	if (mdwc->otg_xceiv && mdwc->otg_xceiv->state == OTG_STATE_B_PERIPHERAL)
		device_bus_suspend = true;

	if (device_bus_suspend) {
		/* pending device events unprocessed */
		for (i = 0; i < dwc->num_event_buffers; i++) {
			struct dwc3_event_buffer *evt = dwc->ev_buffs[i];
			if ((evt->flags & DWC3_EVENT_PENDING)) {
@@ -1609,14 +1611,13 @@ static int dwc3_msm_suspend(struct dwc3_msm *mdwc)
				return -EBUSY;
			}
		}
	}

		if (!msm_bam_usb_lpm_ok(DWC3_CTRL)) {
		dev_dbg(mdwc->dev,
			"%s: IPA handshake not finished, will suspend when done\n",
			dev_dbg(mdwc->dev, "%s: IPA handshake not finished, will suspend when done\n",
					__func__);
			return -EBUSY;
		}
	}

	if (!mdwc->vbus_active && mdwc->otg_xceiv &&
		mdwc->otg_xceiv->state == OTG_STATE_B_PERIPHERAL) {
@@ -1660,8 +1661,6 @@ static int dwc3_msm_suspend(struct dwc3_msm *mdwc)

	host_bus_suspend = (mdwc->scope == POWER_SUPPLY_SCOPE_SYSTEM);
	can_suspend_ssphy = !(host_bus_suspend && host_ss_active);
	device_bus_suspend = ((mdwc->charger.chg_type == DWC3_SDP_CHARGER) ||
				 (mdwc->charger.chg_type == DWC3_CDP_CHARGER));

	if (host_bus_suspend || device_bus_suspend) {