usb: dwc2: force dr_mode in case of configuration mismatch
authorMian Yousaf Kaukab <yousaf.kaukab@intel.com>
Tue, 29 Sep 2015 10:08:18 +0000 (12:08 +0200)
committerFelipe Balbi <balbi@ti.com>
Thu, 1 Oct 2015 17:40:23 +0000 (12:40 -0500)
If dual role configuration is not selected, check and force dr_mode
based on the selected configuration.

Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@intel.com>
Tested-by: Robert Baldyga <r.baldyga@samsung.com>
Tested-by: Dinh Nguyen <dinguyen@opensource.altera.com>
Tested-by: John Youn <johnyoun@synopsys.com>
Acked-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/dwc2/platform.c

index 28abd1f909000dc91e7b1d3cd13fcdff83057796..a013ea9f2c9c3a413b7f638a38739afce4005cf8 100644 (file)
@@ -221,6 +221,17 @@ static int dwc2_driver_probe(struct platform_device *dev)
                (unsigned long)res->start, hsotg->regs);
 
        hsotg->dr_mode = usb_get_dr_mode(&dev->dev);
+       if (IS_ENABLED(CONFIG_USB_DWC2_HOST) &&
+                       hsotg->dr_mode != USB_DR_MODE_HOST) {
+               hsotg->dr_mode = USB_DR_MODE_HOST;
+               dev_warn(hsotg->dev,
+                       "Configuration mismatch. Forcing host mode\n");
+       } else if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) &&
+                       hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) {
+               hsotg->dr_mode = USB_DR_MODE_PERIPHERAL;
+               dev_warn(hsotg->dev,
+                       "Configuration mismatch. Forcing peripheral mode\n");
+       }
 
        /*
         * Attempt to find a generic PHY, then look for an old style