usb: dwc3: switch to peripheral mode when exiting
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Wed, 11 Sep 2019 09:33:45 +0000 (11:33 +0200)
committerMarek Vasut <marek.vasut+renesas@gmail.com>
Thu, 24 Oct 2019 09:28:16 +0000 (11:28 +0200)
This allow the phy to enter idle and then suspend.
the K2 platforms require the PHY to be suspended before the USB domain
clock can be turned off.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
drivers/usb/dwc3/core.c

index 2498f0efb1a488aee4854e51072852fde5ad8a4f..1bd41f8bc771da6a324d6b5e4547ce721bf0da24 100644 (file)
@@ -581,6 +581,12 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
        return 0;
 }
 
+static void dwc3_gadget_run(struct dwc3 *dwc)
+{
+       dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_RUN_STOP);
+       mdelay(100);
+}
+
 static void dwc3_core_exit_mode(struct dwc3 *dwc)
 {
        switch (dwc->dr_mode) {
@@ -598,6 +604,13 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
                /* do nothing */
                break;
        }
+
+       /*
+        * switch back to peripheral mode
+        * This enables the phy to enter idle and then, if enabled, suspend.
+        */
+       dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
+       dwc3_gadget_run(dwc);
 }
 
 #define DWC3_ALIGN_MASK                (16 - 1)