All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v11 0/5] USB DWC3 host wake up support from system suspend
@ 2022-03-22  7:07 Sandeep Maheswaram
  2022-03-22  7:07 ` [PATCH v11 1/5] usb: dwc3: core: Add HS phy mode variable and phy poweroff flag Sandeep Maheswaram
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Sandeep Maheswaram @ 2022-03-22  7:07 UTC (permalink / raw)
  To: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman
  Cc: linux-arm-msm, linux-usb, linux-kernel, quic_pkondeti,
	quic_ppratap, Sandeep Maheswaram

Avoiding phy powerdown in host mode when wakeup capable devices are 
connected, so that it can be wake up by devices.
Set GENPD_FLAG_ALWAYS_ON flag to keep usb30_prim gdsc active to retain
controller status during suspend/resume.

Changes in v11:
Moving back to v8 version
https://patchwork.kernel.org/project/linux-arm-msm/cover/1624882097-23265-1-git-send-email-sanm@codeaurora.org
as we are getting interrupts during suspend
when enabling both DP hs phy irq and DM hs phy irq.
Moved the set phy mode function to dwc3/core.c from xhci-plat.c
We didn't find any other option other than accessing xhci from dwc.

Changes in v10:
PATCH 1/6: Change device_set_wakeup_capable to device_set_wakeup_enable
PATCH 2/6: Remove redundant else part in dwc3_resume_common
PATCH 4/6: Change the irg flags
PATCH 5/6: Set flag GENPD_FLAG_ALWAYS_ON
PATCH 6/6: Remove remove disable interrupts function and enable
interrupts in probe.


Changes in v9:
Checking with device_may_makeup property instead of phy_power_off flag.
Changed the IRQ flags and removed hs_phy_mode variable.

Changes in v8:
Moved the dwc3 suspend quirk code in dwc3/host.c to xhci-plat.c
Checking phy_power_off flag instead of usb_wakeup_enabled_descendants 
to keep gdsc active.

Changes in v7:
Change in commit text and message in PATCH 1/5 and PATCH 5/5
as per Matthias suggestion.
Added curly braces for if and else if sections in PATCH 4/5.

Changes in v6:
Addressed comments in host.c and core.c
Separated the patches in dwc3-qcom.c to make it simple.
Dropped wakeup-source change as it is not related to this series.

Changes in v5:
Added phy_power_off flag to check presence of wakeup capable devices.
Dropped patch[v4,4/5] as it is present linux-next.
Addressed comments in host.c and dwc3-qcom.c.

Changes in v4:
Addressed Matthias comments raised in v3.

Changes in v3:
Removed need_phy_for_wakeup flag and by default avoiding phy powerdown.
Addressed Matthias comments and added entry for DEV_SUPERSPEED.
Added suspend_quirk in dwc3 host and moved the dwc3_set_phy_speed_flags.
Added wakeup-source dt entry and reading in dwc-qcom.c glue driver.

Changes in v2:
Dropped the patch in clock to set GENPD_FLAG_ACTIVE_WAKEUP flag and 
setting in usb dwc3 driver.
Separated the core patch and glue driver patch.
Made need_phy_for_wakeup flag part of dwc structure and 
hs_phy_flags as unsgined int.
Adrressed the comment on device_init_wakeup call.
Corrected offset for reading portsc register.
Added pacth to support wakeup in xo shutdown case.

Sandeep Maheswaram (5):
  usb: dwc3: core: Add HS phy mode variable and phy poweroff flag
  usb: dwc3: core: Host wake up support from system suspend
  usb: dwc3: qcom: Add helper functions to enable,disable wake irqs
  usb: dwc3: qcom: Configure wakeup interrupts during suspend
  usb: dwc3: qcom: Keep power domain on to retain controller status

 drivers/usb/dwc3/core.c      | 54 ++++++++++++++++++++++++++------
 drivers/usb/dwc3/core.h      |  3 ++
 drivers/usb/dwc3/dwc3-qcom.c | 74 ++++++++++++++++++++++++++------------------
 3 files changed, 92 insertions(+), 39 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v11 1/5] usb: dwc3: core: Add HS phy mode variable and phy poweroff flag
  2022-03-22  7:07 [PATCH v11 0/5] USB DWC3 host wake up support from system suspend Sandeep Maheswaram
@ 2022-03-22  7:07 ` Sandeep Maheswaram
  2022-03-22  8:09   ` Pavan Kondeti
  2022-03-22  7:07 ` [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend Sandeep Maheswaram
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 20+ messages in thread
From: Sandeep Maheswaram @ 2022-03-22  7:07 UTC (permalink / raw)
  To: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman
  Cc: linux-arm-msm, linux-usb, linux-kernel, quic_pkondeti,
	quic_ppratap, Sandeep Maheswaram

Add variables in dwc3 structure to check HS phy mode which is
used to configure interrupts and phy poweroff flag to check
the phy status during system resume.

Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
---
 drivers/usb/dwc3/core.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 5c9d467..f11a60c 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1154,6 +1154,9 @@ struct dwc3 {
 
 	bool			phys_ready;
 
+	unsigned int            hs_phy_mode;
+	bool			phy_power_off;
+
 	struct ulpi		*ulpi;
 	bool			ulpi_ready;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-22  7:07 [PATCH v11 0/5] USB DWC3 host wake up support from system suspend Sandeep Maheswaram
  2022-03-22  7:07 ` [PATCH v11 1/5] usb: dwc3: core: Add HS phy mode variable and phy poweroff flag Sandeep Maheswaram
@ 2022-03-22  7:07 ` Sandeep Maheswaram
  2022-03-22  8:32   ` Pavan Kondeti
  2022-03-23 18:07   ` Matthias Kaehlcke
  2022-03-22  7:07 ` [PATCH v11 3/5] usb: dwc3: qcom: Add helper functions to enable,disable wake irqs Sandeep Maheswaram
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 20+ messages in thread
From: Sandeep Maheswaram @ 2022-03-22  7:07 UTC (permalink / raw)
  To: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman
  Cc: linux-arm-msm, linux-usb, linux-kernel, quic_pkondeti,
	quic_ppratap, Sandeep Maheswaram

During suspend read the status of all port and make sure the PHYs
are in the correct mode based on current speed.
Phy interrupt masks are set based on this mode. Keep track of the mode
of the HS PHY to be able to configure wakeup properly.

Also check during suspend if any wakeup capable devices are
connected to the controller (directly or through hubs), if there
are none set a flag to indicate that the PHY is powered
down during suspend.

Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
---
 drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 45 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 1170b80..232a734 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -32,12 +32,14 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/of.h>
 #include <linux/usb/otg.h>
+#include <linux/usb/hcd.h>
 
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
 
 #include "debug.h"
+#include "../host/xhci.h"
 
 #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
 
@@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
 	return ret;
 }
 
+static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
+{
+
+	int i, num_ports;
+	u32 reg;
+	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
+	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
+
+	dwc->hs_phy_mode = 0;
+
+	reg = readl(&xhci_hcd->cap_regs->hcs_params1);
+
+	num_ports = HCS_MAX_PORTS(reg);
+	for (i = 0; i < num_ports; i++) {
+		reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04);
+		if (reg & PORT_PE) {
+			if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg))
+				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_HS;
+			else if (DEV_LOWSPEED(reg))
+				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_LS;
+		}
+	}
+	phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_mode);
+}
+
 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 {
 	unsigned long	flags;
 	u32 reg;
+	struct usb_hcd  *hcd = platform_get_drvdata(dwc->xhci);
 
 	switch (dwc->current_dr_role) {
 	case DWC3_GCTL_PRTCAP_DEVICE:
@@ -1877,10 +1905,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 		dwc3_core_exit(dwc);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg)) {
-			dwc3_core_exit(dwc);
-			break;
-		}
+		dwc3_set_phy_speed_mode(dwc);
 
 		/* Let controller to suspend HSPHY before PHY driver suspends */
 		if (dwc->dis_u2_susphy_quirk ||
@@ -1896,6 +1921,16 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 
 		phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
 		phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
+
+		if (!PMSG_IS_AUTO(msg)) {
+			if (device_may_wakeup(&dwc->xhci->dev) &&
+			    usb_wakeup_enabled_descendants(hcd->self.root_hub)) {
+				dwc->phy_power_off = false;
+			} else {
+				dwc->phy_power_off = true;
+				dwc3_core_exit(dwc);
+			}
+		}
 		break;
 	case DWC3_GCTL_PRTCAP_OTG:
 		/* do nothing during runtime_suspend */
@@ -1939,11 +1974,12 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
 		if (!PMSG_IS_AUTO(msg)) {
-			ret = dwc3_core_init_for_resume(dwc);
-			if (ret)
-				return ret;
-			dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
-			break;
+			if (dwc->phy_power_off) {
+				ret = dwc3_core_init_for_resume(dwc);
+				if (ret)
+					return ret;
+				dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
+			}
 		}
 		/* Restore GUSB2PHYCFG bits that were modified in suspend */
 		reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v11 3/5] usb: dwc3: qcom: Add helper functions to enable,disable wake irqs
  2022-03-22  7:07 [PATCH v11 0/5] USB DWC3 host wake up support from system suspend Sandeep Maheswaram
  2022-03-22  7:07 ` [PATCH v11 1/5] usb: dwc3: core: Add HS phy mode variable and phy poweroff flag Sandeep Maheswaram
  2022-03-22  7:07 ` [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend Sandeep Maheswaram
@ 2022-03-22  7:07 ` Sandeep Maheswaram
  2022-03-22  8:33   ` Pavan Kondeti
  2022-03-22  7:07 ` [PATCH v11 4/5] usb: dwc3: qcom: Configure wakeup interrupts during suspend Sandeep Maheswaram
  2022-03-22  7:07 ` [PATCH v11 5/5] usb: dwc3: qcom: Keep power domain on to retain controller status Sandeep Maheswaram
  4 siblings, 1 reply; 20+ messages in thread
From: Sandeep Maheswaram @ 2022-03-22  7:07 UTC (permalink / raw)
  To: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman
  Cc: linux-arm-msm, linux-usb, linux-kernel, quic_pkondeti,
	quic_ppratap, Sandeep Maheswaram

Adding helper functions to enable,disable wake irqs to make
the code simple and readable.

Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
---
 drivers/usb/dwc3/dwc3-qcom.c | 58 ++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 6cba990..7352124 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -296,50 +296,44 @@ static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom)
 	icc_put(qcom->icc_path_apps);
 }
 
+static void dwc3_qcom_enable_wakeup_irq(int irq)
+{
+	if (!irq)
+		return;
+
+	enable_irq(irq);
+	enable_irq_wake(irq);
+}
+
+static void dwc3_qcom_disable_wakeup_irq(int irq)
+{
+	if (!irq)
+		return;
+
+	disable_irq_wake(irq);
+	disable_irq_nosync(irq);
+}
+
 static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
 {
-	if (qcom->hs_phy_irq) {
-		disable_irq_wake(qcom->hs_phy_irq);
-		disable_irq_nosync(qcom->hs_phy_irq);
-	}
+	dwc3_qcom_disable_wakeup_irq(qcom->hs_phy_irq);
 
-	if (qcom->dp_hs_phy_irq) {
-		disable_irq_wake(qcom->dp_hs_phy_irq);
-		disable_irq_nosync(qcom->dp_hs_phy_irq);
-	}
+	dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq);
 
-	if (qcom->dm_hs_phy_irq) {
-		disable_irq_wake(qcom->dm_hs_phy_irq);
-		disable_irq_nosync(qcom->dm_hs_phy_irq);
-	}
+	dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq);
 
-	if (qcom->ss_phy_irq) {
-		disable_irq_wake(qcom->ss_phy_irq);
-		disable_irq_nosync(qcom->ss_phy_irq);
-	}
+	dwc3_qcom_disable_wakeup_irq(qcom->ss_phy_irq);
 }
 
 static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
 {
-	if (qcom->hs_phy_irq) {
-		enable_irq(qcom->hs_phy_irq);
-		enable_irq_wake(qcom->hs_phy_irq);
-	}
+	dwc3_qcom_enable_wakeup_irq(qcom->hs_phy_irq);
 
-	if (qcom->dp_hs_phy_irq) {
-		enable_irq(qcom->dp_hs_phy_irq);
-		enable_irq_wake(qcom->dp_hs_phy_irq);
-	}
+	dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq);
 
-	if (qcom->dm_hs_phy_irq) {
-		enable_irq(qcom->dm_hs_phy_irq);
-		enable_irq_wake(qcom->dm_hs_phy_irq);
-	}
+	dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq);
 
-	if (qcom->ss_phy_irq) {
-		enable_irq(qcom->ss_phy_irq);
-		enable_irq_wake(qcom->ss_phy_irq);
-	}
+	dwc3_qcom_enable_wakeup_irq(qcom->ss_phy_irq);
 }
 
 static int dwc3_qcom_suspend(struct dwc3_qcom *qcom)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v11 4/5] usb: dwc3: qcom: Configure wakeup interrupts during suspend
  2022-03-22  7:07 [PATCH v11 0/5] USB DWC3 host wake up support from system suspend Sandeep Maheswaram
                   ` (2 preceding siblings ...)
  2022-03-22  7:07 ` [PATCH v11 3/5] usb: dwc3: qcom: Add helper functions to enable,disable wake irqs Sandeep Maheswaram
@ 2022-03-22  7:07 ` Sandeep Maheswaram
  2022-03-22  8:36   ` Pavan Kondeti
  2022-03-22  7:07 ` [PATCH v11 5/5] usb: dwc3: qcom: Keep power domain on to retain controller status Sandeep Maheswaram
  4 siblings, 1 reply; 20+ messages in thread
From: Sandeep Maheswaram @ 2022-03-22  7:07 UTC (permalink / raw)
  To: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman
  Cc: linux-arm-msm, linux-usb, linux-kernel, quic_pkondeti,
	quic_ppratap, Sandeep Maheswaram

Configure interrupts based on hs_phy_mode to avoid triggering of
interrupts during system suspend and suspend the device successfully.

Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
---
 drivers/usb/dwc3/dwc3-qcom.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 7352124..9804a19 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -316,22 +316,36 @@ static void dwc3_qcom_disable_wakeup_irq(int irq)
 
 static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
 {
-	dwc3_qcom_disable_wakeup_irq(qcom->hs_phy_irq);
+	struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
 
-	dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq);
+	dwc3_qcom_disable_wakeup_irq(qcom->hs_phy_irq);
 
-	dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq);
+	if (dwc->hs_phy_mode & PHY_MODE_USB_HOST_LS) {
+		dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq);
+	} else if (dwc->hs_phy_mode & PHY_MODE_USB_HOST_HS) {
+		dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq);
+	} else {
+		dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq);
+		dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq);
+	}
 
 	dwc3_qcom_disable_wakeup_irq(qcom->ss_phy_irq);
 }
 
 static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
 {
-	dwc3_qcom_enable_wakeup_irq(qcom->hs_phy_irq);
+	struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
 
-	dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq);
+	dwc3_qcom_enable_wakeup_irq(qcom->hs_phy_irq);
 
-	dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq);
+	if (dwc->hs_phy_mode & PHY_MODE_USB_HOST_LS) {
+		dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq);
+	} else if (dwc->hs_phy_mode & PHY_MODE_USB_HOST_HS) {
+		dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq);
+	} else {
+		dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq);
+		dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq);
+	}
 
 	dwc3_qcom_enable_wakeup_irq(qcom->ss_phy_irq);
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v11 5/5] usb: dwc3: qcom: Keep power domain on to retain controller status
  2022-03-22  7:07 [PATCH v11 0/5] USB DWC3 host wake up support from system suspend Sandeep Maheswaram
                   ` (3 preceding siblings ...)
  2022-03-22  7:07 ` [PATCH v11 4/5] usb: dwc3: qcom: Configure wakeup interrupts during suspend Sandeep Maheswaram
@ 2022-03-22  7:07 ` Sandeep Maheswaram
  2022-03-22  8:37   ` Pavan Kondeti
  4 siblings, 1 reply; 20+ messages in thread
From: Sandeep Maheswaram @ 2022-03-22  7:07 UTC (permalink / raw)
  To: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman
  Cc: linux-arm-msm, linux-usb, linux-kernel, quic_pkondeti,
	quic_ppratap, Sandeep Maheswaram

Keep the power domain on in order to retail controller status and
to support wakeup from devices.

Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 9804a19..35087cf 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -17,6 +17,7 @@
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
+#include <linux/pm_domain.h>
 #include <linux/usb/of.h>
 #include <linux/reset.h>
 #include <linux/iopoll.h>
@@ -724,6 +725,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	struct resource		*res, *parent_res = NULL;
 	int			ret, i;
 	bool			ignore_pipe_clk;
+	struct generic_pm_domain *genpd;
 
 	qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL);
 	if (!qcom)
@@ -732,6 +734,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, qcom);
 	qcom->dev = &pdev->dev;
 
+	genpd = pd_to_genpd(qcom->dev->pm_domain);
+
 	if (has_acpi_companion(dev)) {
 		qcom->acpi_pdata = acpi_device_get_match_data(dev);
 		if (!qcom->acpi_pdata) {
@@ -839,6 +843,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	if (ret)
 		goto interconnect_exit;
 
+	genpd->flags |= GENPD_FLAG_ALWAYS_ON;
+
 	device_init_wakeup(&pdev->dev, 1);
 	qcom->is_suspended = false;
 	pm_runtime_set_active(dev);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 1/5] usb: dwc3: core: Add HS phy mode variable and phy poweroff flag
  2022-03-22  7:07 ` [PATCH v11 1/5] usb: dwc3: core: Add HS phy mode variable and phy poweroff flag Sandeep Maheswaram
@ 2022-03-22  8:09   ` Pavan Kondeti
  2022-03-22  8:42     ` Sandeep Maheswaram (Temp)
  0 siblings, 1 reply; 20+ messages in thread
From: Pavan Kondeti @ 2022-03-22  8:09 UTC (permalink / raw)
  To: Sandeep Maheswaram
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman, linux-arm-msm,
	linux-usb, linux-kernel, quic_pkondeti, quic_ppratap,
	quic_kriskura

Hi Sandeep,

On Tue, Mar 22, 2022 at 12:37:52PM +0530, Sandeep Maheswaram wrote:
> Add variables in dwc3 structure to check HS phy mode which is
> used to configure interrupts and phy poweroff flag to check
> the phy status during system resume.
> 
> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> ---
>  drivers/usb/dwc3/core.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 5c9d467..f11a60c 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1154,6 +1154,9 @@ struct dwc3 {
>  
>  	bool			phys_ready;
>  
> +	unsigned int            hs_phy_mode;
> +	bool			phy_power_off;
> +
>  	struct ulpi		*ulpi;
>  	bool			ulpi_ready;
>  
Why adding members in a separate patch? This needs to be squashed with
2/5 patch in the series where these members are used in taking host
mode PM decisions. Please fix this.

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-22  7:07 ` [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend Sandeep Maheswaram
@ 2022-03-22  8:32   ` Pavan Kondeti
  2022-03-22  8:40     ` Pavan Kondeti
  2022-04-05  9:25     ` Pavan Kondeti
  2022-03-23 18:07   ` Matthias Kaehlcke
  1 sibling, 2 replies; 20+ messages in thread
From: Pavan Kondeti @ 2022-03-22  8:32 UTC (permalink / raw)
  To: Sandeep Maheswaram
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman, linux-arm-msm,
	linux-usb, linux-kernel, quic_pkondeti, quic_ppratap,
	quic_kriskura

Hi Sandeep,

On Tue, Mar 22, 2022 at 12:37:53PM +0530, Sandeep Maheswaram wrote:
> During suspend read the status of all port and make sure the PHYs
> are in the correct mode based on current speed.
> Phy interrupt masks are set based on this mode. Keep track of the mode
> of the HS PHY to be able to configure wakeup properly.
> 
> Also check during suspend if any wakeup capable devices are
> connected to the controller (directly or through hubs), if there
> are none set a flag to indicate that the PHY is powered
> down during suspend.
> 
> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> ---
>  drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 45 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 1170b80..232a734 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -32,12 +32,14 @@
>  #include <linux/usb/gadget.h>
>  #include <linux/usb/of.h>
>  #include <linux/usb/otg.h>
> +#include <linux/usb/hcd.h>
>  
>  #include "core.h"
>  #include "gadget.h"
>  #include "io.h"
>  
>  #include "debug.h"
> +#include "../host/xhci.h"
>  
>  #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
>  
> @@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
>  	return ret;
>  }
>  
> +static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
> +{
> +
> +	int i, num_ports;
> +	u32 reg;
> +	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
> +	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
> +
> +	dwc->hs_phy_mode = 0;
> +
> +	reg = readl(&xhci_hcd->cap_regs->hcs_params1);
> +
> +	num_ports = HCS_MAX_PORTS(reg);
> +	for (i = 0; i < num_ports; i++) {
> +		reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04);
> +		if (reg & PORT_PE) {
> +			if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg))
> +				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_HS;
> +			else if (DEV_LOWSPEED(reg))
> +				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_LS;
> +		}
> +	}
> +	phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_mode);
> +}

Are these flags cleared somewhere? Also qcom-snps-hs phy driver checks
for (hsphy->mode == PHY_MODE_USB_HOST) condition in qcom_snps_hsphy_suspend
to enable auto-resume. PHY_MODE_USB_HOST_HS/PHY_MODE_USB_HOST_LS flags
are different from PHY_MODE_USB_HOST. Currently this flag is set from
__dwc3_set_mode() when entering host mode. Can you clarify your intention
in calling phy_set_mode() here.

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 3/5] usb: dwc3: qcom: Add helper functions to enable,disable wake irqs
  2022-03-22  7:07 ` [PATCH v11 3/5] usb: dwc3: qcom: Add helper functions to enable,disable wake irqs Sandeep Maheswaram
@ 2022-03-22  8:33   ` Pavan Kondeti
  0 siblings, 0 replies; 20+ messages in thread
From: Pavan Kondeti @ 2022-03-22  8:33 UTC (permalink / raw)
  To: Sandeep Maheswaram
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman, linux-arm-msm,
	linux-usb, linux-kernel, quic_pkondeti, quic_ppratap

On Tue, Mar 22, 2022 at 12:37:54PM +0530, Sandeep Maheswaram wrote:
> Adding helper functions to enable,disable wake irqs to make
> the code simple and readable.
> 
> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 58 ++++++++++++++++++++------------------------
>  1 file changed, 26 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 6cba990..7352124 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -296,50 +296,44 @@ static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom)
>  	icc_put(qcom->icc_path_apps);
>  }
>  
> +static void dwc3_qcom_enable_wakeup_irq(int irq)
> +{
> +	if (!irq)
> +		return;
> +
> +	enable_irq(irq);
> +	enable_irq_wake(irq);
> +}
> +
> +static void dwc3_qcom_disable_wakeup_irq(int irq)
> +{
> +	if (!irq)
> +		return;
> +
> +	disable_irq_wake(irq);
> +	disable_irq_nosync(irq);
> +}
> +
>  static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
>  {
> -	if (qcom->hs_phy_irq) {
> -		disable_irq_wake(qcom->hs_phy_irq);
> -		disable_irq_nosync(qcom->hs_phy_irq);
> -	}
> +	dwc3_qcom_disable_wakeup_irq(qcom->hs_phy_irq);
>  
> -	if (qcom->dp_hs_phy_irq) {
> -		disable_irq_wake(qcom->dp_hs_phy_irq);
> -		disable_irq_nosync(qcom->dp_hs_phy_irq);
> -	}
> +	dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq);
>  
> -	if (qcom->dm_hs_phy_irq) {
> -		disable_irq_wake(qcom->dm_hs_phy_irq);
> -		disable_irq_nosync(qcom->dm_hs_phy_irq);
> -	}
> +	dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq);
>  
> -	if (qcom->ss_phy_irq) {
> -		disable_irq_wake(qcom->ss_phy_irq);
> -		disable_irq_nosync(qcom->ss_phy_irq);
> -	}
> +	dwc3_qcom_disable_wakeup_irq(qcom->ss_phy_irq);
>  }
>  
>  static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
>  {
> -	if (qcom->hs_phy_irq) {
> -		enable_irq(qcom->hs_phy_irq);
> -		enable_irq_wake(qcom->hs_phy_irq);
> -	}
> +	dwc3_qcom_enable_wakeup_irq(qcom->hs_phy_irq);
>  
> -	if (qcom->dp_hs_phy_irq) {
> -		enable_irq(qcom->dp_hs_phy_irq);
> -		enable_irq_wake(qcom->dp_hs_phy_irq);
> -	}
> +	dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq);
>  
> -	if (qcom->dm_hs_phy_irq) {
> -		enable_irq(qcom->dm_hs_phy_irq);
> -		enable_irq_wake(qcom->dm_hs_phy_irq);
> -	}
> +	dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq);
>  
> -	if (qcom->ss_phy_irq) {
> -		enable_irq(qcom->ss_phy_irq);
> -		enable_irq_wake(qcom->ss_phy_irq);
> -	}
> +	dwc3_qcom_enable_wakeup_irq(qcom->ss_phy_irq);
>  }
>  
>  static int dwc3_qcom_suspend(struct dwc3_qcom *qcom)

Looks good to me.

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 4/5] usb: dwc3: qcom: Configure wakeup interrupts during suspend
  2022-03-22  7:07 ` [PATCH v11 4/5] usb: dwc3: qcom: Configure wakeup interrupts during suspend Sandeep Maheswaram
@ 2022-03-22  8:36   ` Pavan Kondeti
  0 siblings, 0 replies; 20+ messages in thread
From: Pavan Kondeti @ 2022-03-22  8:36 UTC (permalink / raw)
  To: Sandeep Maheswaram
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman, linux-arm-msm,
	linux-usb, linux-kernel, quic_pkondeti, quic_ppratap

Hi Sandeep,

On Tue, Mar 22, 2022 at 12:37:55PM +0530, Sandeep Maheswaram wrote:
> Configure interrupts based on hs_phy_mode to avoid triggering of
> interrupts during system suspend and suspend the device successfully.
> 
The changelog is not clear and confusing. Can you elaborate please?

> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 26 ++++++++++++++++++++------
>  1 file changed, 20 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 7352124..9804a19 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -316,22 +316,36 @@ static void dwc3_qcom_disable_wakeup_irq(int irq)
>  
>  static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
>  {
> -	dwc3_qcom_disable_wakeup_irq(qcom->hs_phy_irq);
> +	struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
>  
> -	dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq);
> +	dwc3_qcom_disable_wakeup_irq(qcom->hs_phy_irq);
>  
> -	dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq);
> +	if (dwc->hs_phy_mode & PHY_MODE_USB_HOST_LS) {
> +		dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq);
> +	} else if (dwc->hs_phy_mode & PHY_MODE_USB_HOST_HS) {
> +		dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq);
> +	} else {
> +		dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq);
> +		dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq);
> +	}

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 5/5] usb: dwc3: qcom: Keep power domain on to retain controller status
  2022-03-22  7:07 ` [PATCH v11 5/5] usb: dwc3: qcom: Keep power domain on to retain controller status Sandeep Maheswaram
@ 2022-03-22  8:37   ` Pavan Kondeti
  2022-03-22  9:18     ` Sandeep Maheswaram (Temp)
  0 siblings, 1 reply; 20+ messages in thread
From: Pavan Kondeti @ 2022-03-22  8:37 UTC (permalink / raw)
  To: Sandeep Maheswaram
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman, linux-arm-msm,
	linux-usb, linux-kernel, quic_pkondeti, quic_ppratap

Hi Sandeep,

On Tue, Mar 22, 2022 at 12:37:56PM +0530, Sandeep Maheswaram wrote:
> Keep the power domain on in order to retail controller status and
> to support wakeup from devices.
> 

%s/retail/retain

retain the controller status so that remote wakeup / device connect /
device disconnect events can be detected during suspend.

> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 9804a19..35087cf 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -17,6 +17,7 @@
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
>  #include <linux/phy/phy.h>
> +#include <linux/pm_domain.h>
>  #include <linux/usb/of.h>
>  #include <linux/reset.h>
>  #include <linux/iopoll.h>
> @@ -724,6 +725,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	struct resource		*res, *parent_res = NULL;
>  	int			ret, i;
>  	bool			ignore_pipe_clk;
> +	struct generic_pm_domain *genpd;
>  
>  	qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL);
>  	if (!qcom)
> @@ -732,6 +734,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, qcom);
>  	qcom->dev = &pdev->dev;
>  
> +	genpd = pd_to_genpd(qcom->dev->pm_domain);
> +
>  	if (has_acpi_companion(dev)) {
>  		qcom->acpi_pdata = acpi_device_get_match_data(dev);
>  		if (!qcom->acpi_pdata) {
> @@ -839,6 +843,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto interconnect_exit;
>  
> +	genpd->flags |= GENPD_FLAG_ALWAYS_ON;
> +
>  	device_init_wakeup(&pdev->dev, 1);
>  	qcom->is_suspended = false;
>  	pm_runtime_set_active(dev);
> -- 
> 2.7.4
> 

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-22  8:32   ` Pavan Kondeti
@ 2022-03-22  8:40     ` Pavan Kondeti
  2022-04-05  9:25     ` Pavan Kondeti
  1 sibling, 0 replies; 20+ messages in thread
From: Pavan Kondeti @ 2022-03-22  8:40 UTC (permalink / raw)
  To: Pavan Kondeti
  Cc: Sandeep Maheswaram, Bjorn Andersson, Greg Kroah-Hartman,
	Felipe Balbi, Stephen Boyd, Doug Anderson, Matthias Kaehlcke,
	Mathias Nyman, linux-arm-msm, linux-usb, linux-kernel,
	quic_ppratap, quic_kriskura

Hi Sandeep,

On Tue, Mar 22, 2022 at 02:02:21PM +0530, Pavan Kondeti wrote:
> Hi Sandeep,
> 
> On Tue, Mar 22, 2022 at 12:37:53PM +0530, Sandeep Maheswaram wrote:
> > During suspend read the status of all port and make sure the PHYs
> > are in the correct mode based on current speed.
> > Phy interrupt masks are set based on this mode. Keep track of the mode
> > of the HS PHY to be able to configure wakeup properly.
> > 
> > Also check during suspend if any wakeup capable devices are
> > connected to the controller (directly or through hubs), if there
> > are none set a flag to indicate that the PHY is powered
> > down during suspend.
> > 
> > Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> > ---
> >  drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
> >  1 file changed, 45 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > index 1170b80..232a734 100644
> > --- a/drivers/usb/dwc3/core.c
> > +++ b/drivers/usb/dwc3/core.c
> > @@ -32,12 +32,14 @@
> >  #include <linux/usb/gadget.h>
> >  #include <linux/usb/of.h>
> >  #include <linux/usb/otg.h>
> > +#include <linux/usb/hcd.h>
> >  
> >  #include "core.h"
> >  #include "gadget.h"
> >  #include "io.h"
> >  
> >  #include "debug.h"
> > +#include "../host/xhci.h"
> >  
> >  #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
> >  
> > @@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
> >  	return ret;
> >  }
> >  
> > +static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
> > +{
> > +
> > +	int i, num_ports;
> > +	u32 reg;
> > +	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
> > +	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
> > +
> > +	dwc->hs_phy_mode = 0;
> > +
Sorry, My bad. I did not notice that the flags are cleared here.

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 1/5] usb: dwc3: core: Add HS phy mode variable and phy poweroff flag
  2022-03-22  8:09   ` Pavan Kondeti
@ 2022-03-22  8:42     ` Sandeep Maheswaram (Temp)
  0 siblings, 0 replies; 20+ messages in thread
From: Sandeep Maheswaram (Temp) @ 2022-03-22  8:42 UTC (permalink / raw)
  To: Pavan Kondeti
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman, linux-arm-msm,
	linux-usb, linux-kernel, quic_ppratap, quic_kriskura

On 3/22/2022 1:39 PM, Pavan Kondeti wrote:
> Hi Sandeep,
>
> On Tue, Mar 22, 2022 at 12:37:52PM +0530, Sandeep Maheswaram wrote:
>> Add variables in dwc3 structure to check HS phy mode which is
>> used to configure interrupts and phy poweroff flag to check
>> the phy status during system resume.
>>
>> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
>> ---
>>   drivers/usb/dwc3/core.h | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
>> index 5c9d467..f11a60c 100644
>> --- a/drivers/usb/dwc3/core.h
>> +++ b/drivers/usb/dwc3/core.h
>> @@ -1154,6 +1154,9 @@ struct dwc3 {
>>   
>>   	bool			phys_ready;
>>   
>> +	unsigned int            hs_phy_mode;
>> +	bool			phy_power_off;
>> +
>>   	struct ulpi		*ulpi;
>>   	bool			ulpi_ready;
>>   
> Why adding members in a separate patch? This needs to be squashed with
> 2/5 patch in the series where these members are used in taking host
> mode PM decisions. Please fix this.
>
> Thanks,
> Pavan

Sure . Will do in next version.

Regards

Sandeep


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 5/5] usb: dwc3: qcom: Keep power domain on to retain controller status
  2022-03-22  8:37   ` Pavan Kondeti
@ 2022-03-22  9:18     ` Sandeep Maheswaram (Temp)
  0 siblings, 0 replies; 20+ messages in thread
From: Sandeep Maheswaram (Temp) @ 2022-03-22  9:18 UTC (permalink / raw)
  To: Pavan Kondeti
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Matthias Kaehlcke, Mathias Nyman, linux-arm-msm,
	linux-usb, linux-kernel, quic_ppratap

Hi Pavan,

On 3/22/2022 2:07 PM, Pavan Kondeti wrote:
> Hi Sandeep,
>
> On Tue, Mar 22, 2022 at 12:37:56PM +0530, Sandeep Maheswaram wrote:
>> Keep the power domain on in order to retail controller status and
>> to support wakeup from devices.
>>
> %s/retail/retain
>
> retain the controller status so that remote wakeup / device connect /
> device disconnect events can be detected during suspend.
Will correct in next version.
>
>> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
>> ---
>>   drivers/usb/dwc3/dwc3-qcom.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
>> index 9804a19..35087cf 100644
>> --- a/drivers/usb/dwc3/dwc3-qcom.c
>> +++ b/drivers/usb/dwc3/dwc3-qcom.c
>> @@ -17,6 +17,7 @@
>>   #include <linux/of_platform.h>
>>   #include <linux/platform_device.h>
>>   #include <linux/phy/phy.h>
>> +#include <linux/pm_domain.h>
>>   #include <linux/usb/of.h>
>>   #include <linux/reset.h>
>>   #include <linux/iopoll.h>
>> @@ -724,6 +725,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>>   	struct resource		*res, *parent_res = NULL;
>>   	int			ret, i;
>>   	bool			ignore_pipe_clk;
>> +	struct generic_pm_domain *genpd;
>>   
>>   	qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL);
>>   	if (!qcom)
>> @@ -732,6 +734,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>>   	platform_set_drvdata(pdev, qcom);
>>   	qcom->dev = &pdev->dev;
>>   
>> +	genpd = pd_to_genpd(qcom->dev->pm_domain);
>> +
>>   	if (has_acpi_companion(dev)) {
>>   		qcom->acpi_pdata = acpi_device_get_match_data(dev);
>>   		if (!qcom->acpi_pdata) {
>> @@ -839,6 +843,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>>   	if (ret)
>>   		goto interconnect_exit;
>>   
>> +	genpd->flags |= GENPD_FLAG_ALWAYS_ON;
>> +
>>   	device_init_wakeup(&pdev->dev, 1);
>>   	qcom->is_suspended = false;
>>   	pm_runtime_set_active(dev);
>> -- 
>> 2.7.4
>>
> Thanks,
> Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-22  7:07 ` [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend Sandeep Maheswaram
  2022-03-22  8:32   ` Pavan Kondeti
@ 2022-03-23 18:07   ` Matthias Kaehlcke
  2022-03-24  4:54     ` Sandeep Maheswaram (Temp)
  1 sibling, 1 reply; 20+ messages in thread
From: Matthias Kaehlcke @ 2022-03-23 18:07 UTC (permalink / raw)
  To: Sandeep Maheswaram
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Mathias Nyman, linux-arm-msm, linux-usb,
	linux-kernel, quic_pkondeti, quic_ppratap

On Tue, Mar 22, 2022 at 12:37:53PM +0530, Sandeep Maheswaram wrote:
> During suspend read the status of all port and make sure the PHYs
> are in the correct mode based on current speed.
> Phy interrupt masks are set based on this mode. Keep track of the mode
> of the HS PHY to be able to configure wakeup properly.
> 
> Also check during suspend if any wakeup capable devices are
> connected to the controller (directly or through hubs), if there
> are none set a flag to indicate that the PHY is powered
> down during suspend.
> 
> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> ---
>  drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 45 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 1170b80..232a734 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -32,12 +32,14 @@
>  #include <linux/usb/gadget.h>
>  #include <linux/usb/of.h>
>  #include <linux/usb/otg.h>
> +#include <linux/usb/hcd.h>
>  
>  #include "core.h"
>  #include "gadget.h"
>  #include "io.h"
>  
>  #include "debug.h"
> +#include "../host/xhci.h"
>  
>  #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
>  
> @@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
>  	return ret;
>  }
>  
> +static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
> +{
> +
> +	int i, num_ports;
> +	u32 reg;
> +	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
> +	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
> +
> +	dwc->hs_phy_mode = 0;
> +
> +	reg = readl(&xhci_hcd->cap_regs->hcs_params1);
> +
> +	num_ports = HCS_MAX_PORTS(reg);
> +	for (i = 0; i < num_ports; i++) {
> +		reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04);

s/0x04/NUM_PORT_REGS/

> +		if (reg & PORT_PE) {
> +			if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg))
> +				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_HS;
> +			else if (DEV_LOWSPEED(reg))
> +				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_LS;
> +		}
> +	}
> +	phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_mode);
> +}
> +
>  static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
>  {
>  	unsigned long	flags;
>  	u32 reg;
> +	struct usb_hcd  *hcd = platform_get_drvdata(dwc->xhci);
>  
>  	switch (dwc->current_dr_role) {
>  	case DWC3_GCTL_PRTCAP_DEVICE:
> @@ -1877,10 +1905,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
>  		dwc3_core_exit(dwc);
>  		break;
>  	case DWC3_GCTL_PRTCAP_HOST:
> -		if (!PMSG_IS_AUTO(msg)) {
> -			dwc3_core_exit(dwc);
> -			break;
> -		}
> +		dwc3_set_phy_speed_mode(dwc);
>  
>  		/* Let controller to suspend HSPHY before PHY driver suspends */
>  		if (dwc->dis_u2_susphy_quirk ||
> @@ -1896,6 +1921,16 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
>  
>  		phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
>  		phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
> +
> +		if (!PMSG_IS_AUTO(msg)) {
> +			if (device_may_wakeup(&dwc->xhci->dev) &&

Does the xHCI actually provide the correct information? I think Brian brought
up earlier that xhci-plat always marks the xHCI as wakeup capable, regardless
of whether the specific implementation actually supports wakeup. So a dwc3
without wakeup support would keep the PHY and the dwc3 active during suspend
if wakeup capable devices are connected (unless the admin disabled wakeup),
even though wakeup it doesn't support wakeup.

Using the wakeup capability/policy of the xHCI to make decisions in the dwc3
driver might still be the best we can do with the weird driver split over 3
drivers for dwc3. Maybe the dwc3 could pass the actual capability to wake up
to the xHCI through a property_entry? Then again, it's actually the 'glue'
driver (dwc3-qcom) who knows about the actual wakeup capability, and not the
dwc3 core/host ...

> +			    usb_wakeup_enabled_descendants(hcd->self.root_hub)) {
> +				dwc->phy_power_off = false;
> +			} else {
> +				dwc->phy_power_off = true;
> +				dwc3_core_exit(dwc);
> +			}
> +		}
>  		break;
>  	case DWC3_GCTL_PRTCAP_OTG:
>  		/* do nothing during runtime_suspend */
> @@ -1939,11 +1974,12 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
>  		break;
>  	case DWC3_GCTL_PRTCAP_HOST:
>  		if (!PMSG_IS_AUTO(msg)) {
> -			ret = dwc3_core_init_for_resume(dwc);
> -			if (ret)
> -				return ret;
> -			dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
> -			break;
> +			if (dwc->phy_power_off) {

nit: you could merge this with the outer if condition:

     	       	if (!PMSG_IS_AUTO(msg) && dwc->phy_power_off) {

it's also fine to leave as is.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-23 18:07   ` Matthias Kaehlcke
@ 2022-03-24  4:54     ` Sandeep Maheswaram (Temp)
  2022-03-30  4:03       ` Pavan Kondeti
  0 siblings, 1 reply; 20+ messages in thread
From: Sandeep Maheswaram (Temp) @ 2022-03-24  4:54 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Mathias Nyman, linux-arm-msm, linux-usb,
	linux-kernel, quic_pkondeti, quic_ppratap


On 3/23/2022 11:37 PM, Matthias Kaehlcke wrote:
> On Tue, Mar 22, 2022 at 12:37:53PM +0530, Sandeep Maheswaram wrote:
>> During suspend read the status of all port and make sure the PHYs
>> are in the correct mode based on current speed.
>> Phy interrupt masks are set based on this mode. Keep track of the mode
>> of the HS PHY to be able to configure wakeup properly.
>>
>> Also check during suspend if any wakeup capable devices are
>> connected to the controller (directly or through hubs), if there
>> are none set a flag to indicate that the PHY is powered
>> down during suspend.
>>
>> Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
>> ---
>>   drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
>>   1 file changed, 45 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>> index 1170b80..232a734 100644
>> --- a/drivers/usb/dwc3/core.c
>> +++ b/drivers/usb/dwc3/core.c
>> @@ -32,12 +32,14 @@
>>   #include <linux/usb/gadget.h>
>>   #include <linux/usb/of.h>
>>   #include <linux/usb/otg.h>
>> +#include <linux/usb/hcd.h>
>>   
>>   #include "core.h"
>>   #include "gadget.h"
>>   #include "io.h"
>>   
>>   #include "debug.h"
>> +#include "../host/xhci.h"
>>   
>>   #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
>>   
>> @@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
>>   	return ret;
>>   }
>>   
>> +static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
>> +{
>> +
>> +	int i, num_ports;
>> +	u32 reg;
>> +	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
>> +	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
>> +
>> +	dwc->hs_phy_mode = 0;
>> +
>> +	reg = readl(&xhci_hcd->cap_regs->hcs_params1);
>> +
>> +	num_ports = HCS_MAX_PORTS(reg);
>> +	for (i = 0; i < num_ports; i++) {
>> +		reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04);
> s/0x04/NUM_PORT_REGS/
Okay. Will update in next version.
>
>> +		if (reg & PORT_PE) {
>> +			if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg))
>> +				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_HS;
>> +			else if (DEV_LOWSPEED(reg))
>> +				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_LS;
>> +		}
>> +	}
>> +	phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_mode);
>> +}
>> +
>>   static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
>>   {
>>   	unsigned long	flags;
>>   	u32 reg;
>> +	struct usb_hcd  *hcd = platform_get_drvdata(dwc->xhci);
>>   
>>   	switch (dwc->current_dr_role) {
>>   	case DWC3_GCTL_PRTCAP_DEVICE:
>> @@ -1877,10 +1905,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
>>   		dwc3_core_exit(dwc);
>>   		break;
>>   	case DWC3_GCTL_PRTCAP_HOST:
>> -		if (!PMSG_IS_AUTO(msg)) {
>> -			dwc3_core_exit(dwc);
>> -			break;
>> -		}
>> +		dwc3_set_phy_speed_mode(dwc);
>>   
>>   		/* Let controller to suspend HSPHY before PHY driver suspends */
>>   		if (dwc->dis_u2_susphy_quirk ||
>> @@ -1896,6 +1921,16 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
>>   
>>   		phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
>>   		phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
>> +
>> +		if (!PMSG_IS_AUTO(msg)) {
>> +			if (device_may_wakeup(&dwc->xhci->dev) &&
> Does the xHCI actually provide the correct information? I think Brian brought
> up earlier that xhci-plat always marks the xHCI as wakeup capable, regardless
> of whether the specific implementation actually supports wakeup. So a dwc3
> without wakeup support would keep the PHY and the dwc3 active during suspend
> if wakeup capable devices are connected (unless the admin disabled wakeup),
> even though wakeup it doesn't support wakeup.
>
> Using the wakeup capability/policy of the xHCI to make decisions in the dwc3
> driver might still be the best we can do with the weird driver split over 3
> drivers for dwc3. Maybe the dwc3 could pass the actual capability to wake up
> to the xHCI through a property_entry? Then again, it's actually the 'glue'
> driver (dwc3-qcom) who knows about the actual wakeup capability, and not the
> dwc3 core/host ...
Will check if we can do something regarding this.
>
>> +			    usb_wakeup_enabled_descendants(hcd->self.root_hub)) {
>> +				dwc->phy_power_off = false;
>> +			} else {
>> +				dwc->phy_power_off = true;
>> +				dwc3_core_exit(dwc);
>> +			}
>> +		}
>>   		break;
>>   	case DWC3_GCTL_PRTCAP_OTG:
>>   		/* do nothing during runtime_suspend */
>> @@ -1939,11 +1974,12 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
>>   		break;
>>   	case DWC3_GCTL_PRTCAP_HOST:
>>   		if (!PMSG_IS_AUTO(msg)) {
>> -			ret = dwc3_core_init_for_resume(dwc);
>> -			if (ret)
>> -				return ret;
>> -			dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
>> -			break;
>> +			if (dwc->phy_power_off) {
> nit: you could merge this with the outer if condition:
>
>       	       	if (!PMSG_IS_AUTO(msg) && dwc->phy_power_off) {
>
> it's also fine to leave as is.

Okay. Will update in next version.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-24  4:54     ` Sandeep Maheswaram (Temp)
@ 2022-03-30  4:03       ` Pavan Kondeti
  2022-03-30 16:46         ` Matthias Kaehlcke
  0 siblings, 1 reply; 20+ messages in thread
From: Pavan Kondeti @ 2022-03-30  4:03 UTC (permalink / raw)
  To: Sandeep Maheswaram (Temp)
  Cc: Matthias Kaehlcke, Bjorn Andersson, Greg Kroah-Hartman,
	Felipe Balbi, Stephen Boyd, Doug Anderson, Mathias Nyman,
	linux-arm-msm, linux-usb, linux-kernel, quic_pkondeti,
	quic_ppratap

Hi Sandeep/Matthias,

On Thu, Mar 24, 2022 at 10:24:55AM +0530, Sandeep Maheswaram (Temp) wrote:
> 
> On 3/23/2022 11:37 PM, Matthias Kaehlcke wrote:
> >On Tue, Mar 22, 2022 at 12:37:53PM +0530, Sandeep Maheswaram wrote:
> >>During suspend read the status of all port and make sure the PHYs
> >>are in the correct mode based on current speed.
> >>Phy interrupt masks are set based on this mode. Keep track of the mode
> >>of the HS PHY to be able to configure wakeup properly.
> >>
> >>Also check during suspend if any wakeup capable devices are
> >>connected to the controller (directly or through hubs), if there
> >>are none set a flag to indicate that the PHY is powered
> >>down during suspend.
> >>
> >>Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> >>---
> >>  drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
> >>  1 file changed, 45 insertions(+), 9 deletions(-)
> >>
> >>diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> >>index 1170b80..232a734 100644
> >>--- a/drivers/usb/dwc3/core.c
> >>+++ b/drivers/usb/dwc3/core.c
> >>@@ -32,12 +32,14 @@
> >>  #include <linux/usb/gadget.h>
> >>  #include <linux/usb/of.h>
> >>  #include <linux/usb/otg.h>
> >>+#include <linux/usb/hcd.h>
> >>  #include "core.h"
> >>  #include "gadget.h"
> >>  #include "io.h"
> >>  #include "debug.h"
> >>+#include "../host/xhci.h"
> >>  #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
> >>@@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
> >>  	return ret;
> >>  }
> >>+static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
> >>+{
> >>+
> >>+	int i, num_ports;
> >>+	u32 reg;
> >>+	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
> >>+	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
> >>+
> >>+	dwc->hs_phy_mode = 0;
> >>+
> >>+	reg = readl(&xhci_hcd->cap_regs->hcs_params1);
> >>+
> >>+	num_ports = HCS_MAX_PORTS(reg);
> >>+	for (i = 0; i < num_ports; i++) {
> >>+		reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04);
> >s/0x04/NUM_PORT_REGS/
> Okay. Will update in next version.
> >
> >>+		if (reg & PORT_PE) {
> >>+			if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg))
> >>+				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_HS;
> >>+			else if (DEV_LOWSPEED(reg))
> >>+				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_LS;
> >>+		}
> >>+	}
> >>+	phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_mode);
> >>+}
> >>+
> >>  static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> >>  {
> >>  	unsigned long	flags;
> >>  	u32 reg;
> >>+	struct usb_hcd  *hcd = platform_get_drvdata(dwc->xhci);
> >>  	switch (dwc->current_dr_role) {
> >>  	case DWC3_GCTL_PRTCAP_DEVICE:
> >>@@ -1877,10 +1905,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> >>  		dwc3_core_exit(dwc);
> >>  		break;
> >>  	case DWC3_GCTL_PRTCAP_HOST:
> >>-		if (!PMSG_IS_AUTO(msg)) {
> >>-			dwc3_core_exit(dwc);
> >>-			break;
> >>-		}
> >>+		dwc3_set_phy_speed_mode(dwc);
> >>  		/* Let controller to suspend HSPHY before PHY driver suspends */
> >>  		if (dwc->dis_u2_susphy_quirk ||
> >>@@ -1896,6 +1921,16 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> >>  		phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
> >>  		phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
> >>+
> >>+		if (!PMSG_IS_AUTO(msg)) {
> >>+			if (device_may_wakeup(&dwc->xhci->dev) &&
> >Does the xHCI actually provide the correct information? I think Brian brought
> >up earlier that xhci-plat always marks the xHCI as wakeup capable, regardless
> >of whether the specific implementation actually supports wakeup. So a dwc3
> >without wakeup support would keep the PHY and the dwc3 active during suspend
> >if wakeup capable devices are connected (unless the admin disabled wakeup),
> >even though wakeup it doesn't support wakeup.
> >
> >Using the wakeup capability/policy of the xHCI to make decisions in the dwc3
> >driver might still be the best we can do with the weird driver split over 3
> >drivers for dwc3. Maybe the dwc3 could pass the actual capability to wake up
> >to the xHCI through a property_entry? Then again, it's actually the 'glue'
> >driver (dwc3-qcom) who knows about the actual wakeup capability, and not the
> >dwc3 core/host ...
> Will check if we can do something regarding this.

Can we introduce a device tree param to xhci-plat to specify if the underlying
device is wakeup capable or not. Based on this xhci-plat can call
device_set_wakeup_capable() with correct argument.

One immediate problem is that current code unconditionally calls
device_set_wakeup_capable(&pdev->dev, true). So we may break existing use
cases also.

Given that xHC assumes that the undelying device is wakeup capable but dwc3
tearing the stack during PM suspend does not make any sense. can we atleast
create a device tree param for dwc3 not to do this? 

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-30  4:03       ` Pavan Kondeti
@ 2022-03-30 16:46         ` Matthias Kaehlcke
  2022-03-31  3:14           ` Pavan Kondeti
  0 siblings, 1 reply; 20+ messages in thread
From: Matthias Kaehlcke @ 2022-03-30 16:46 UTC (permalink / raw)
  To: Pavan Kondeti
  Cc: Sandeep Maheswaram (Temp),
	Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Mathias Nyman, linux-arm-msm, linux-usb,
	linux-kernel, quic_ppratap

On Wed, Mar 30, 2022 at 09:33:18AM +0530, Pavan Kondeti wrote:
> Hi Sandeep/Matthias,
> 
> On Thu, Mar 24, 2022 at 10:24:55AM +0530, Sandeep Maheswaram (Temp) wrote:
> > 
> > On 3/23/2022 11:37 PM, Matthias Kaehlcke wrote:
> > >On Tue, Mar 22, 2022 at 12:37:53PM +0530, Sandeep Maheswaram wrote:
> > >>During suspend read the status of all port and make sure the PHYs
> > >>are in the correct mode based on current speed.
> > >>Phy interrupt masks are set based on this mode. Keep track of the mode
> > >>of the HS PHY to be able to configure wakeup properly.
> > >>
> > >>Also check during suspend if any wakeup capable devices are
> > >>connected to the controller (directly or through hubs), if there
> > >>are none set a flag to indicate that the PHY is powered
> > >>down during suspend.
> > >>
> > >>Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> > >>---
> > >>  drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
> > >>  1 file changed, 45 insertions(+), 9 deletions(-)
> > >>
> > >>diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > >>index 1170b80..232a734 100644
> > >>--- a/drivers/usb/dwc3/core.c
> > >>+++ b/drivers/usb/dwc3/core.c
> > >>@@ -32,12 +32,14 @@
> > >>  #include <linux/usb/gadget.h>
> > >>  #include <linux/usb/of.h>
> > >>  #include <linux/usb/otg.h>
> > >>+#include <linux/usb/hcd.h>
> > >>  #include "core.h"
> > >>  #include "gadget.h"
> > >>  #include "io.h"
> > >>  #include "debug.h"
> > >>+#include "../host/xhci.h"
> > >>  #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
> > >>@@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
> > >>  	return ret;
> > >>  }
> > >>+static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
> > >>+{
> > >>+
> > >>+	int i, num_ports;
> > >>+	u32 reg;
> > >>+	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
> > >>+	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
> > >>+
> > >>+	dwc->hs_phy_mode = 0;
> > >>+
> > >>+	reg = readl(&xhci_hcd->cap_regs->hcs_params1);
> > >>+
> > >>+	num_ports = HCS_MAX_PORTS(reg);
> > >>+	for (i = 0; i < num_ports; i++) {
> > >>+		reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04);
> > >s/0x04/NUM_PORT_REGS/
> > Okay. Will update in next version.
> > >
> > >>+		if (reg & PORT_PE) {
> > >>+			if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg))
> > >>+				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_HS;
> > >>+			else if (DEV_LOWSPEED(reg))
> > >>+				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_LS;
> > >>+		}
> > >>+	}
> > >>+	phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_mode);
> > >>+}
> > >>+
> > >>  static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> > >>  {
> > >>  	unsigned long	flags;
> > >>  	u32 reg;
> > >>+	struct usb_hcd  *hcd = platform_get_drvdata(dwc->xhci);
> > >>  	switch (dwc->current_dr_role) {
> > >>  	case DWC3_GCTL_PRTCAP_DEVICE:
> > >>@@ -1877,10 +1905,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> > >>  		dwc3_core_exit(dwc);
> > >>  		break;
> > >>  	case DWC3_GCTL_PRTCAP_HOST:
> > >>-		if (!PMSG_IS_AUTO(msg)) {
> > >>-			dwc3_core_exit(dwc);
> > >>-			break;
> > >>-		}
> > >>+		dwc3_set_phy_speed_mode(dwc);
> > >>  		/* Let controller to suspend HSPHY before PHY driver suspends */
> > >>  		if (dwc->dis_u2_susphy_quirk ||
> > >>@@ -1896,6 +1921,16 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> > >>  		phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
> > >>  		phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
> > >>+
> > >>+		if (!PMSG_IS_AUTO(msg)) {
> > >>+			if (device_may_wakeup(&dwc->xhci->dev) &&
> > >Does the xHCI actually provide the correct information? I think Brian brought
> > >up earlier that xhci-plat always marks the xHCI as wakeup capable, regardless
> > >of whether the specific implementation actually supports wakeup. So a dwc3
> > >without wakeup support would keep the PHY and the dwc3 active during suspend
> > >if wakeup capable devices are connected (unless the admin disabled wakeup),
> > >even though wakeup it doesn't support wakeup.
> > >
> > >Using the wakeup capability/policy of the xHCI to make decisions in the dwc3
> > >driver might still be the best we can do with the weird driver split over 3
> > >drivers for dwc3. Maybe the dwc3 could pass the actual capability to wake up
> > >to the xHCI through a property_entry? Then again, it's actually the 'glue'
> > >driver (dwc3-qcom) who knows about the actual wakeup capability, and not the
> > >dwc3 core/host ...
> > Will check if we can do something regarding this.
> 
> Can we introduce a device tree param to xhci-plat to specify if the underlying
> device is wakeup capable or not. Based on this xhci-plat can call
> device_set_wakeup_capable() with correct argument.

This also came to my mind, the existing 'wakeup-source' property could be an
option, I share your concern about breaking existing use cases though ...

> One immediate problem is that current code unconditionally calls
> device_set_wakeup_capable(&pdev->dev, true). So we may break existing use
> cases also.

> Given that xHC assumes that the undelying device is wakeup capable but dwc3
> tearing the stack during PM suspend does not make any sense. can we atleast
> create a device tree param for dwc3 not to do this?

I'm not sure I fully understand what you have in mind. Are you thinking about
a parameter/property to indicate whether wakeup should be enabled for the dwc3?
'wakeup_source' could serve that purpose, it is also used by xhci-mtk.c and
mtu3_host.c.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-30 16:46         ` Matthias Kaehlcke
@ 2022-03-31  3:14           ` Pavan Kondeti
  0 siblings, 0 replies; 20+ messages in thread
From: Pavan Kondeti @ 2022-03-31  3:14 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Pavan Kondeti, Sandeep Maheswaram (Temp),
	Bjorn Andersson, Greg Kroah-Hartman, Felipe Balbi, Stephen Boyd,
	Doug Anderson, Mathias Nyman, linux-arm-msm, linux-usb,
	linux-kernel, quic_ppratap

Hi Matthias,

On Wed, Mar 30, 2022 at 09:46:36AM -0700, Matthias Kaehlcke wrote:
> On Wed, Mar 30, 2022 at 09:33:18AM +0530, Pavan Kondeti wrote:
> > Hi Sandeep/Matthias,
> > 
> > On Thu, Mar 24, 2022 at 10:24:55AM +0530, Sandeep Maheswaram (Temp) wrote:
> > > 
> > > On 3/23/2022 11:37 PM, Matthias Kaehlcke wrote:
> > > >On Tue, Mar 22, 2022 at 12:37:53PM +0530, Sandeep Maheswaram wrote:
> > > >>During suspend read the status of all port and make sure the PHYs
> > > >>are in the correct mode based on current speed.
> > > >>Phy interrupt masks are set based on this mode. Keep track of the mode
> > > >>of the HS PHY to be able to configure wakeup properly.
> > > >>
> > > >>Also check during suspend if any wakeup capable devices are
> > > >>connected to the controller (directly or through hubs), if there
> > > >>are none set a flag to indicate that the PHY is powered
> > > >>down during suspend.
> > > >>
> > > >>Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> > > >>---
> > > >>  drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
> > > >>  1 file changed, 45 insertions(+), 9 deletions(-)
> > > >>
> > > >>diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > > >>index 1170b80..232a734 100644
> > > >>--- a/drivers/usb/dwc3/core.c
> > > >>+++ b/drivers/usb/dwc3/core.c
> > > >>@@ -32,12 +32,14 @@
> > > >>  #include <linux/usb/gadget.h>
> > > >>  #include <linux/usb/of.h>
> > > >>  #include <linux/usb/otg.h>
> > > >>+#include <linux/usb/hcd.h>
> > > >>  #include "core.h"
> > > >>  #include "gadget.h"
> > > >>  #include "io.h"
> > > >>  #include "debug.h"
> > > >>+#include "../host/xhci.h"
> > > >>  #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
> > > >>@@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
> > > >>  	return ret;
> > > >>  }
> > > >>+static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
> > > >>+{
> > > >>+
> > > >>+	int i, num_ports;
> > > >>+	u32 reg;
> > > >>+	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
> > > >>+	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
> > > >>+
> > > >>+	dwc->hs_phy_mode = 0;
> > > >>+
> > > >>+	reg = readl(&xhci_hcd->cap_regs->hcs_params1);
> > > >>+
> > > >>+	num_ports = HCS_MAX_PORTS(reg);
> > > >>+	for (i = 0; i < num_ports; i++) {
> > > >>+		reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04);
> > > >s/0x04/NUM_PORT_REGS/
> > > Okay. Will update in next version.
> > > >
> > > >>+		if (reg & PORT_PE) {
> > > >>+			if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg))
> > > >>+				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_HS;
> > > >>+			else if (DEV_LOWSPEED(reg))
> > > >>+				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_LS;
> > > >>+		}
> > > >>+	}
> > > >>+	phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_mode);
> > > >>+}
> > > >>+
> > > >>  static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> > > >>  {
> > > >>  	unsigned long	flags;
> > > >>  	u32 reg;
> > > >>+	struct usb_hcd  *hcd = platform_get_drvdata(dwc->xhci);
> > > >>  	switch (dwc->current_dr_role) {
> > > >>  	case DWC3_GCTL_PRTCAP_DEVICE:
> > > >>@@ -1877,10 +1905,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> > > >>  		dwc3_core_exit(dwc);
> > > >>  		break;
> > > >>  	case DWC3_GCTL_PRTCAP_HOST:
> > > >>-		if (!PMSG_IS_AUTO(msg)) {
> > > >>-			dwc3_core_exit(dwc);
> > > >>-			break;
> > > >>-		}
> > > >>+		dwc3_set_phy_speed_mode(dwc);
> > > >>  		/* Let controller to suspend HSPHY before PHY driver suspends */
> > > >>  		if (dwc->dis_u2_susphy_quirk ||
> > > >>@@ -1896,6 +1921,16 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
> > > >>  		phy_pm_runtime_put_sync(dwc->usb2_generic_phy);
> > > >>  		phy_pm_runtime_put_sync(dwc->usb3_generic_phy);
> > > >>+
> > > >>+		if (!PMSG_IS_AUTO(msg)) {
> > > >>+			if (device_may_wakeup(&dwc->xhci->dev) &&
> > > >Does the xHCI actually provide the correct information? I think Brian brought
> > > >up earlier that xhci-plat always marks the xHCI as wakeup capable, regardless
> > > >of whether the specific implementation actually supports wakeup. So a dwc3
> > > >without wakeup support would keep the PHY and the dwc3 active during suspend
> > > >if wakeup capable devices are connected (unless the admin disabled wakeup),
> > > >even though wakeup it doesn't support wakeup.
> > > >
> > > >Using the wakeup capability/policy of the xHCI to make decisions in the dwc3
> > > >driver might still be the best we can do with the weird driver split over 3
> > > >drivers for dwc3. Maybe the dwc3 could pass the actual capability to wake up
> > > >to the xHCI through a property_entry? Then again, it's actually the 'glue'
> > > >driver (dwc3-qcom) who knows about the actual wakeup capability, and not the
> > > >dwc3 core/host ...
> > > Will check if we can do something regarding this.
> > 
> > Can we introduce a device tree param to xhci-plat to specify if the underlying
> > device is wakeup capable or not. Based on this xhci-plat can call
> > device_set_wakeup_capable() with correct argument.
> 
> This also came to my mind, the existing 'wakeup-source' property could be an
> option, I share your concern about breaking existing use cases though ...
> 
> > One immediate problem is that current code unconditionally calls
> > device_set_wakeup_capable(&pdev->dev, true). So we may break existing use
> > cases also.
> 
> > Given that xHC assumes that the undelying device is wakeup capable but dwc3
> > tearing the stack during PM suspend does not make any sense. can we atleast
> > create a device tree param for dwc3 not to do this?
> 
> I'm not sure I fully understand what you have in mind. Are you thinking about
> a parameter/property to indicate whether wakeup should be enabled for the dwc3?
> 'wakeup_source' could serve that purpose, it is also used by xhci-mtk.c and
> mtu3_host.c.

Yes, I was suggesting we can have a device tree param for dwc3 node to decide
instead of relying on device_may_wakeup() checks in this patch. 

Thanks for pointing out wakeup-source property. That sounds perfect here to
me.

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend
  2022-03-22  8:32   ` Pavan Kondeti
  2022-03-22  8:40     ` Pavan Kondeti
@ 2022-04-05  9:25     ` Pavan Kondeti
  1 sibling, 0 replies; 20+ messages in thread
From: Pavan Kondeti @ 2022-04-05  9:25 UTC (permalink / raw)
  To: Pavan Kondeti
  Cc: Sandeep Maheswaram, Bjorn Andersson, Greg Kroah-Hartman,
	Felipe Balbi, Stephen Boyd, Doug Anderson, Matthias Kaehlcke,
	Mathias Nyman, linux-arm-msm, linux-usb, linux-kernel,
	quic_ppratap, quic_kriskura

Hi Sandeep,

On Tue, Mar 22, 2022 at 02:02:21PM +0530, Pavan Kondeti wrote:
> Hi Sandeep,
> 
> On Tue, Mar 22, 2022 at 12:37:53PM +0530, Sandeep Maheswaram wrote:
> > During suspend read the status of all port and make sure the PHYs
> > are in the correct mode based on current speed.
> > Phy interrupt masks are set based on this mode. Keep track of the mode
> > of the HS PHY to be able to configure wakeup properly.
> > 
> > Also check during suspend if any wakeup capable devices are
> > connected to the controller (directly or through hubs), if there
> > are none set a flag to indicate that the PHY is powered
> > down during suspend.
> > 
> > Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
> > ---
> >  drivers/usb/dwc3/core.c | 54 ++++++++++++++++++++++++++++++++++++++++---------
> >  1 file changed, 45 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > index 1170b80..232a734 100644
> > --- a/drivers/usb/dwc3/core.c
> > +++ b/drivers/usb/dwc3/core.c
> > @@ -32,12 +32,14 @@
> >  #include <linux/usb/gadget.h>
> >  #include <linux/usb/of.h>
> >  #include <linux/usb/otg.h>
> > +#include <linux/usb/hcd.h>
> >  
> >  #include "core.h"
> >  #include "gadget.h"
> >  #include "io.h"
> >  
> >  #include "debug.h"
> > +#include "../host/xhci.h"
> >  
> >  #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
> >  
> > @@ -1861,10 +1863,36 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
> >  	return ret;
> >  }
> >  
> > +static void dwc3_set_phy_speed_mode(struct dwc3 *dwc)
> > +{
> > +
> > +	int i, num_ports;
> > +	u32 reg;
> > +	struct usb_hcd	*hcd = platform_get_drvdata(dwc->xhci);
> > +	struct xhci_hcd	*xhci_hcd = hcd_to_xhci(hcd);
> > +
> > +	dwc->hs_phy_mode = 0;
> > +
> > +	reg = readl(&xhci_hcd->cap_regs->hcs_params1);
> > +
> > +	num_ports = HCS_MAX_PORTS(reg);
> > +	for (i = 0; i < num_ports; i++) {
> > +		reg = readl(&xhci_hcd->op_regs->port_status_base + i * 0x04);
> > +		if (reg & PORT_PE) {
> > +			if (DEV_HIGHSPEED(reg) || DEV_FULLSPEED(reg))
> > +				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_HS;
> > +			else if (DEV_LOWSPEED(reg))
> > +				dwc->hs_phy_mode |= PHY_MODE_USB_HOST_LS;
> > +		}
> > +	}
> > +	phy_set_mode(dwc->usb2_generic_phy, dwc->hs_phy_mode);
> > +}
> 
> Are these flags cleared somewhere? Also qcom-snps-hs phy driver checks
> for (hsphy->mode == PHY_MODE_USB_HOST) condition in qcom_snps_hsphy_suspend
> to enable auto-resume. PHY_MODE_USB_HOST_HS/PHY_MODE_USB_HOST_LS flags
> are different from PHY_MODE_USB_HOST. Currently this flag is set from
> __dwc3_set_mode() when entering host mode. Can you clarify your intention
> in calling phy_set_mode() here.

I think re-purposing phy_set_mode() to override PHY_MODE_USB_HOST with
PHY_MODE_USB_HOST_HS/PHY_MODE_USB_HOST_LS might break other drivers. All
most all the phy drivers are checking against PHY_MODE_USB_HOST.

Why do we need to set phy_set_mode() here? The next patch in this series
only uses dwc->hs_phy_mode. can we drop phy_set_mode() call here?

Thanks,
Pavan

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-04-05 10:52 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-22  7:07 [PATCH v11 0/5] USB DWC3 host wake up support from system suspend Sandeep Maheswaram
2022-03-22  7:07 ` [PATCH v11 1/5] usb: dwc3: core: Add HS phy mode variable and phy poweroff flag Sandeep Maheswaram
2022-03-22  8:09   ` Pavan Kondeti
2022-03-22  8:42     ` Sandeep Maheswaram (Temp)
2022-03-22  7:07 ` [PATCH v11 2/5] usb: dwc3: core: Host wake up support from system suspend Sandeep Maheswaram
2022-03-22  8:32   ` Pavan Kondeti
2022-03-22  8:40     ` Pavan Kondeti
2022-04-05  9:25     ` Pavan Kondeti
2022-03-23 18:07   ` Matthias Kaehlcke
2022-03-24  4:54     ` Sandeep Maheswaram (Temp)
2022-03-30  4:03       ` Pavan Kondeti
2022-03-30 16:46         ` Matthias Kaehlcke
2022-03-31  3:14           ` Pavan Kondeti
2022-03-22  7:07 ` [PATCH v11 3/5] usb: dwc3: qcom: Add helper functions to enable,disable wake irqs Sandeep Maheswaram
2022-03-22  8:33   ` Pavan Kondeti
2022-03-22  7:07 ` [PATCH v11 4/5] usb: dwc3: qcom: Configure wakeup interrupts during suspend Sandeep Maheswaram
2022-03-22  8:36   ` Pavan Kondeti
2022-03-22  7:07 ` [PATCH v11 5/5] usb: dwc3: qcom: Keep power domain on to retain controller status Sandeep Maheswaram
2022-03-22  8:37   ` Pavan Kondeti
2022-03-22  9:18     ` Sandeep Maheswaram (Temp)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.