[PATCH v3 39/49] usb: dwc2: Change TxFIFO and RxFIFO flushing flow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Minas Harutyunyan <hminas@xxxxxxxxxxxx>

Before flushing fifos required to check AHB master state and
flush when AHB master is in IDLE state.

Added default value for greset in dwc2_flush_tx_fifo() and
dwc2_flush_rx_fifo() functions.

Signed-off-by: Minas Harutyunyan <hminas@xxxxxxxxxxxx>
Signed-off-by: Grigor Tovmasyan <tovmasya@xxxxxxxxxxxx>
---
 drivers/usb/dwc2/core.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 2e02556013af..97463bbc46f0 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -865,15 +865,31 @@ void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg)
  */
 void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num)
 {
-	u32 greset;
+	u32 greset = 0;
 	int count = 0;
 
 	dev_vdbg(hsotg->dev, "Flush Tx FIFO %d\n", num);
 
+	/* Wait for AHB master IDLE state */
+	while (1) {
+		greset = dwc2_readl(hsotg->regs + GRSTCTL);
+		if (greset & GRSTCTL_AHBIDLE)
+			break;
+
+		if (++count > 10000) {
+			dev_warn(hsotg->dev,
+				 "%s() HANG! AHB Idle GRSTCTL=%0x\n",
+				__func__, greset);
+			return;
+		}
+		udelay(1);
+	}
+
 	greset = GRSTCTL_TXFFLSH;
 	greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK;
 	dwc2_writel(greset, hsotg->regs + GRSTCTL);
 
+	count = 0;
 	do {
 		greset = dwc2_readl(hsotg->regs + GRSTCTL);
 		if (++count > 10000) {
@@ -897,14 +913,31 @@ void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num)
  */
 void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg)
 {
-	u32 greset;
+	u32 greseti = 0;
 	int count = 0;
 
 	dev_vdbg(hsotg->dev, "%s()\n", __func__);
 
+	/* Wait for AHB master IDLE state */
+	while (1) {
+		greset = dwc2_readl(hsotg->regs + GRSTCTL);
+		if (greset & GRSTCTL_AHBIDLE)
+			break;
+
+		if (++count > 10000) {
+			dev_warn(hsotg->dev,
+				 "%s() HANG! AHB Idle GRSTCTL=%0x\n",
+				__func__, greset);
+			return;
+		}
+		udelay(1);
+	}
+
 	greset = GRSTCTL_RXFFLSH;
 	dwc2_writel(greset, hsotg->regs + GRSTCTL);
 
+	/* Wait for RxFIFO flush done */
+	count = 0;
 	do {
 		greset = dwc2_readl(hsotg->regs + GRSTCTL);
 		if (++count > 10000) {
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux