From: Minas Harutyunyan <hminas@xxxxxxxxxxxx> Before flushing fifos required to check AHB master state and flush when AHB master is in IDLE state. Signed-off-by: Minas Harutyunyan <hminas@xxxxxxxxxxxx> Signed-off-by: Grigor Tovmasyan <tovmasya@xxxxxxxxxxxx> --- drivers/usb/dwc2/core.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 2e02556013af..916c4bfdb2f9 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -870,10 +870,26 @@ void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num) 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) { @@ -902,9 +918,23 @@ void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg) dev_vdbg(hsotg->dev, "%s()\n", __func__); - greset = GRSTCTL_RXFFLSH; - dwc2_writel(greset, hsotg->regs + GRSTCTL); + /* 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); + } + + /* 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