All of lore.kernel.org
 help / color / mirror / Atom feed
From: Artur Petrosyan <Arthur.Petrosyan@synopsys.com>
To: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Artur Petrosyan <Arthur.Petrosyan@synopsys.com>,
	Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>,
	Vardan Mikayelyan <Vardan.Mikayelyan@synopsys.com>,
	Grigor Tovmasyan <Grigor.Tovmasyan@synopsys.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: John Youn <John.Youn@synopsys.com>,
	Artur Petrosyan <Arthur.Petrosyan@synopsys.com>,
	Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Subject: [PATCH v2 04/15] usb: dwc2: Fix hibernation between host and device modes.
Date: Fri, 16 Apr 2021 16:47:14 +0400	[thread overview]
Message-ID: <20210416124715.75355A005D@mailhost.synopsys.com> (raw)
In-Reply-To: <cover.1618464534.git.Arthur.Petrosyan@synopsys.com>

When core is in hibernation in host mode and a device cable
was connected then driver exited from device hibernation.
However, registers saved for host mode and when exited from
device hibernation register restore would be done for device
register which was wrong because there was no device registers
stored to restore.

- Added dwc_handle_gpwrdn_disc_det() function which handles
  gpwrdn disconnect detect flow and exits hibernation
  without restoring the registers.
- Updated exiting from hibernation in GPWRDN_STS_CHGINT with
  calling dwc_handle_gpwrdn_disc_det() function. Here no register
  is restored which is the solution described above.

Fixes: 65c9c4c6b01f ("usb: dwc2: Add dwc2_handle_gpwrdn_intr() handler")
Signed-off-by: Artur Petrosyan <Arthur.Petrosyan@synopsys.com>
Signed-off-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
---
 drivers/usb/dwc2/core_intr.c | 154 +++++++++++++++++++----------------
 1 file changed, 83 insertions(+), 71 deletions(-)

diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index 550c52c1a0c7..27d729fad227 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -680,6 +680,71 @@ static u32 dwc2_read_common_intr(struct dwc2_hsotg *hsotg)
 		return 0;
 }
 
+/**
+ * dwc_handle_gpwrdn_disc_det() - Handles the gpwrdn disconnect detect.
+ * Exits hibernation without restoring registers.
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @gpwrdn: GPWRDN register
+ */
+static inline void dwc_handle_gpwrdn_disc_det(struct dwc2_hsotg *hsotg,
+					      u32 gpwrdn)
+{
+	u32 gpwrdn_tmp;
+
+	/* Switch-on voltage to the core */
+	gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
+	gpwrdn_tmp &= ~GPWRDN_PWRDNSWTCH;
+	dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
+	udelay(5);
+
+	/* Reset core */
+	gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
+	gpwrdn_tmp &= ~GPWRDN_PWRDNRSTN;
+	dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
+	udelay(5);
+
+	/* Disable Power Down Clamp */
+	gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
+	gpwrdn_tmp &= ~GPWRDN_PWRDNCLMP;
+	dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
+	udelay(5);
+
+	/* Deassert reset core */
+	gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
+	gpwrdn_tmp |= GPWRDN_PWRDNRSTN;
+	dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
+	udelay(5);
+
+	/* Disable PMU interrupt */
+	gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
+	gpwrdn_tmp &= ~GPWRDN_PMUINTSEL;
+	dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
+
+	/* De-assert Wakeup Logic */
+	gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
+	gpwrdn_tmp &= ~GPWRDN_PMUACTV;
+	dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
+
+	hsotg->hibernated = 0;
+	hsotg->bus_suspended = 0;
+
+	if (gpwrdn & GPWRDN_IDSTS) {
+		hsotg->op_state = OTG_STATE_B_PERIPHERAL;
+		dwc2_core_init(hsotg, false);
+		dwc2_enable_global_interrupts(hsotg);
+		dwc2_hsotg_core_init_disconnected(hsotg, false);
+		dwc2_hsotg_core_connect(hsotg);
+	} else {
+		hsotg->op_state = OTG_STATE_A_HOST;
+
+		/* Initialize the Core for Host mode */
+		dwc2_core_init(hsotg, false);
+		dwc2_enable_global_interrupts(hsotg);
+		dwc2_hcd_start(hsotg);
+	}
+}
+
 /*
  * GPWRDN interrupt handler.
  *
@@ -701,64 +766,14 @@ static void dwc2_handle_gpwrdn_intr(struct dwc2_hsotg *hsotg)
 
 	if ((gpwrdn & GPWRDN_DISCONN_DET) &&
 	    (gpwrdn & GPWRDN_DISCONN_DET_MSK) && !linestate) {
-		u32 gpwrdn_tmp;
-
 		dev_dbg(hsotg->dev, "%s: GPWRDN_DISCONN_DET\n", __func__);
-
-		/* Switch-on voltage to the core */
-		gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
-		gpwrdn_tmp &= ~GPWRDN_PWRDNSWTCH;
-		dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
-		udelay(10);
-
-		/* Reset core */
-		gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
-		gpwrdn_tmp &= ~GPWRDN_PWRDNRSTN;
-		dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
-		udelay(10);
-
-		/* Disable Power Down Clamp */
-		gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
-		gpwrdn_tmp &= ~GPWRDN_PWRDNCLMP;
-		dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
-		udelay(10);
-
-		/* Deassert reset core */
-		gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
-		gpwrdn_tmp |= GPWRDN_PWRDNRSTN;
-		dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
-		udelay(10);
-
-		/* Disable PMU interrupt */
-		gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
-		gpwrdn_tmp &= ~GPWRDN_PMUINTSEL;
-		dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
-
-		/* De-assert Wakeup Logic */
-		gpwrdn_tmp = dwc2_readl(hsotg, GPWRDN);
-		gpwrdn_tmp &= ~GPWRDN_PMUACTV;
-		dwc2_writel(hsotg, gpwrdn_tmp, GPWRDN);
-
-		hsotg->hibernated = 0;
-
-		if (gpwrdn & GPWRDN_IDSTS) {
-			hsotg->op_state = OTG_STATE_B_PERIPHERAL;
-			dwc2_core_init(hsotg, false);
-			dwc2_enable_global_interrupts(hsotg);
-			dwc2_hsotg_core_init_disconnected(hsotg, false);
-			dwc2_hsotg_core_connect(hsotg);
-		} else {
-			hsotg->op_state = OTG_STATE_A_HOST;
-
-			/* Initialize the Core for Host mode */
-			dwc2_core_init(hsotg, false);
-			dwc2_enable_global_interrupts(hsotg);
-			dwc2_hcd_start(hsotg);
-		}
-	}
-
-	if ((gpwrdn & GPWRDN_LNSTSCHG) &&
-	    (gpwrdn & GPWRDN_LNSTSCHG_MSK) && linestate) {
+		/*
+		 * Call disconnect detect function to exit from
+		 * hibernation
+		 */
+		dwc_handle_gpwrdn_disc_det(hsotg, gpwrdn);
+	} else if ((gpwrdn & GPWRDN_LNSTSCHG) &&
+		   (gpwrdn & GPWRDN_LNSTSCHG_MSK) && linestate) {
 		dev_dbg(hsotg->dev, "%s: GPWRDN_LNSTSCHG\n", __func__);
 		if (hsotg->hw_params.hibernation &&
 		    hsotg->hibernated) {
@@ -769,24 +784,21 @@ static void dwc2_handle_gpwrdn_intr(struct dwc2_hsotg *hsotg)
 				dwc2_exit_hibernation(hsotg, 1, 0, 1);
 			}
 		}
-	}
-	if ((gpwrdn & GPWRDN_RST_DET) && (gpwrdn & GPWRDN_RST_DET_MSK)) {
+	} else if ((gpwrdn & GPWRDN_RST_DET) &&
+		   (gpwrdn & GPWRDN_RST_DET_MSK)) {
 		dev_dbg(hsotg->dev, "%s: GPWRDN_RST_DET\n", __func__);
 		if (!linestate && (gpwrdn & GPWRDN_BSESSVLD))
 			dwc2_exit_hibernation(hsotg, 0, 1, 0);
-	}
-	if ((gpwrdn & GPWRDN_STS_CHGINT) &&
-	    (gpwrdn & GPWRDN_STS_CHGINT_MSK) && linestate) {
+	} else if ((gpwrdn & GPWRDN_STS_CHGINT) &&
+		   (gpwrdn & GPWRDN_STS_CHGINT_MSK)) {
 		dev_dbg(hsotg->dev, "%s: GPWRDN_STS_CHGINT\n", __func__);
-		if (hsotg->hw_params.hibernation &&
-		    hsotg->hibernated) {
-			if (gpwrdn & GPWRDN_IDSTS) {
-				dwc2_exit_hibernation(hsotg, 0, 0, 0);
-				call_gadget(hsotg, resume);
-			} else {
-				dwc2_exit_hibernation(hsotg, 1, 0, 1);
-			}
-		}
+		/*
+		 * As GPWRDN_STS_CHGINT exit from hibernation flow is
+		 * the same as in GPWRDN_DISCONN_DET flow. Call
+		 * disconnect detect helper function to exit from
+		 * hibernation.
+		 */
+		dwc_handle_gpwrdn_disc_det(hsotg, gpwrdn);
 	}
 }
 
-- 
2.25.1


  parent reply	other threads:[~2021-04-16 12:47 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1618464534.git.Arthur.Petrosyan@synopsys.com>
2021-04-15  5:39 ` [PATCH 01/15] usb: dwc2: Update exit hibernation when port reset is asserted Artur Petrosyan
2021-04-15  5:39 ` [PATCH 02/15] usb: dwc2: Reset DEVADDR after exiting gadget hibernation Artur Petrosyan
2021-04-15  5:39 ` [PATCH 03/15] usb: dwc2: Fix host mode hibernation exit with remote wakeup flow Artur Petrosyan
2021-04-15  5:39 ` [PATCH 04/15] usb: dwc2: Fix hibernation between host and device modes Artur Petrosyan
2021-04-15  5:40 ` [PATCH 05/15] usb: dwc2: Allow exiting hibernation from gpwrdn rst detect Artur Petrosyan
2021-04-15  5:40 ` [PATCH 06/15] usb: dwc2: Clear fifo_map when resetting core Artur Petrosyan
2021-04-15  5:40 ` [PATCH 07/15] usb: dwc2: Clear GINTSTS_RESTOREDONE bit after restore is generated Artur Petrosyan
2021-04-15  5:40 ` [PATCH 08/15] usb: dwc2: Move enter hibernation to dwc2_port_suspend() function Artur Petrosyan
2021-04-15  5:40 ` [PATCH 09/15] usb: dwc2: Move exit hibernation to dwc2_port_resume() function Artur Petrosyan
2021-04-15  5:40 ` [PATCH 10/15] usb: dwc2: Allow exit hibernation in urb enqueue Artur Petrosyan
2021-04-15  9:12   ` Sergei Shtylyov
2021-04-16  5:43     ` Artur Petrosyan
2021-04-16  7:05       ` Artur Petrosyan
2021-04-15  5:40 ` [PATCH 11/15] usb: dwc2: Add hibernation entering flow by system suspend Artur Petrosyan
2021-04-15  5:40 ` [PATCH 12/15] usb: dwc2: Add hibernation exiting flow by system resume Artur Petrosyan
2021-04-15  5:41 ` [PATCH 13/15] usb: dwc2: Add exit hibernation mode before removing drive Artur Petrosyan
2021-04-15  9:24   ` Sergei Shtylyov
2021-04-16  5:46     ` Artur Petrosyan
2021-04-15  9:50   ` kernel test robot
2021-04-15  9:50     ` kernel test robot
2021-04-15 13:40   ` [kbuild] " Dan Carpenter
2021-04-15 13:40     ` Dan Carpenter
2021-04-15 13:40     ` Dan Carpenter
2021-04-15  5:41 ` [PATCH 14/15] usb: dwc2: Update dwc2_handle_usb_suspend_intr function Artur Petrosyan
2021-04-15  5:41 ` [PATCH 15/15] usb: dwc2: Get rid of useless error checks in suspend interrupt Artur Petrosyan
2021-04-16 12:46 ` [PATCH v2 00/15] usb: dwc2: Fix Hibernation issues Artur Petrosyan
2021-04-16 12:46 ` [PATCH v2 01/15] usb: dwc2: Update exit hibernation when port reset is asserted Artur Petrosyan
2021-04-19  7:30   ` Minas Harutyunyan
2021-04-16 12:46 ` [PATCH v2 02/15] usb: dwc2: Reset DEVADDR after exiting gadget hibernation Artur Petrosyan
2021-04-16 12:47 ` [PATCH v2 03/15] usb: dwc2: Fix host mode hibernation exit with remote wakeup flow Artur Petrosyan
2021-04-19  7:30   ` Minas Harutyunyan
2021-04-16 12:47 ` Artur Petrosyan [this message]
2021-04-16 12:47 ` [PATCH v2 05/15] usb: dwc2: Allow exiting hibernation from gpwrdn rst detect Artur Petrosyan
2021-04-16 12:47 ` [PATCH v2 06/15] usb: dwc2: Clear fifo_map when resetting core Artur Petrosyan
2021-04-16 12:47 ` [PATCH v2 07/15] usb: dwc2: Clear GINTSTS_RESTOREDONE bit after restore is generated Artur Petrosyan
2021-04-16 12:47 ` [PATCH v2 08/15] usb: dwc2: Move enter hibernation to dwc2_port_suspend() function Artur Petrosyan
2021-04-19  7:31   ` Minas Harutyunyan
2021-04-16 12:47 ` [PATCH v2 09/15] usb: dwc2: Move exit hibernation to dwc2_port_resume() function Artur Petrosyan
2021-04-19  7:31   ` Minas Harutyunyan
2021-04-16 12:48 ` [PATCH v2 10/15] usb: dwc2: Allow exit hibernation in urb enqueue Artur Petrosyan
2021-04-19  7:31   ` Minas Harutyunyan
2021-04-16 12:48 ` [PATCH v2 11/15] usb: dwc2: Add hibernation entering flow by system suspend Artur Petrosyan
2021-04-19  7:31   ` Minas Harutyunyan
2021-04-16 12:48 ` [PATCH v2 12/15] usb: dwc2: Add hibernation exiting flow by system resume Artur Petrosyan
2021-04-19  7:31   ` Minas Harutyunyan
2021-04-16 12:48 ` [PATCH v2 13/15] usb: dwc2: Add exit hibernation mode before removing drive Artur Petrosyan
2021-04-19  7:32   ` Minas Harutyunyan
2021-04-16 12:48 ` [PATCH v2 14/15] usb: dwc2: Update dwc2_handle_usb_suspend_intr function Artur Petrosyan
2021-04-16 12:48 ` [PATCH v2 15/15] usb: dwc2: Get rid of useless error checks in suspend interrupt Artur Petrosyan
2021-04-19  7:32   ` Minas Harutyunyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416124715.75355A005D@mailhost.synopsys.com \
    --to=arthur.petrosyan@synopsys.com \
    --cc=Grigor.Tovmasyan@synopsys.com \
    --cc=John.Youn@synopsys.com \
    --cc=Minas.Harutyunyan@synopsys.com \
    --cc=Vardan.Mikayelyan@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.