From 7ecb69d8afb2338acc6abd6da3cf92cb7fe22b1a Mon Sep 17 00:00:00 2001 From: Feng Mingli Date: Fri, 16 Nov 2018 11:39:51 +0800 Subject: [PATCH] usb: dwc2: keep phy power on if current mode is host during probe The commit e6f2f6d63e3b ("usb: dwc2: power on/off phy for otg mode") aimed to control phy power for otg mode, but it also introduced a new problem, so we fix it. This patch keep phy power on for otg if current mode is host during dwc2 probe, otherwise the enumeration will fail with the following error log: Cannot enable. Maybe the USB cable is bad? Cannot enable. Maybe the USB cable is bad? attempt power cycle Cannot enable. Maybe the USB cable is bad? Cannot enable. Maybe the USB cable is bad? unable to enumerate USB device Fixes: e6f2f6d63e3b ("usb: dwc2: power on/off phy for otg mode") Change-Id: I17a4cab6f0337fdc0923989aea8613bfbe1a9e9b Signed-off-by: Feng Mingli --- drivers/usb/dwc2/gadget.c | 4 ++-- drivers/usb/dwc2/platform.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 4bb73a06d8e5..cf988d8b83e0 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -3469,7 +3469,7 @@ static int dwc2_hsotg_udc_start(struct usb_gadget *gadget, goto err; } - if (hsotg->dr_mode == USB_DR_MODE_OTG) { + if (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg)) { struct platform_device *pdev = to_platform_device(hsotg->dev); if (hsotg->uphy) { @@ -3546,7 +3546,7 @@ static int dwc2_hsotg_udc_stop(struct usb_gadget *gadget) if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) dwc2_lowlevel_hw_disable(hsotg); - if (hsotg->dr_mode == USB_DR_MODE_OTG) { + if (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg)) { struct platform_device *pdev = to_platform_device(hsotg->dev); if (hsotg->uphy) { diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 0805f39ecf85..a56267141873 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -662,7 +662,7 @@ static int dwc2_driver_probe(struct platform_device *dev) if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) dwc2_lowlevel_hw_disable(hsotg); - if (hsotg->dr_mode == USB_DR_MODE_OTG) { + if (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg)) { struct platform_device *pdev = to_platform_device(hsotg->dev); if (hsotg->uphy) {