This patch adds OTG initialization in DWC3 core. This finally enables OTG feature if selected operation mode is "otg". It also initializes and deinitialized OTG in suspend/resume functions. After this changes DWC3 core is uninitialized by default in OTG mode. The dwc3_core_init() function is called after relevant cable detection. Signed-off-by: Robert Baldyga <r.baldyga@xxxxxxxxxxx> --- drivers/usb/dwc3/core.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index d519b31..e5af049 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -43,6 +43,7 @@ #include "platform_data.h" #include "core.h" #include "gadget.h" +#include "otg.h" #include "io.h" #include "debug.h" @@ -687,17 +688,37 @@ static int dwc3_core_init_mode(struct dwc3 *dwc) break; case USB_DR_MODE_OTG: dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); + ret = dwc3_otg_init(dwc); + if (ret) { + dev_err(dev, "failed to initialize otg\n"); + return ret; + } + ret = dwc3_host_init(dwc); if (ret) { dev_err(dev, "failed to initialize host\n"); + dwc3_otg_exit(dwc); return ret; } ret = dwc3_gadget_init(dwc); if (ret) { dev_err(dev, "failed to initialize gadget\n"); + dwc3_host_exit(dwc); + dwc3_otg_exit(dwc); return ret; } + + /* Now we are ready to start OTG */ + ret = dwc3_otg_start(dwc); + if (ret) { + dev_err(dev, "failed to start otg\n"); + dwc3_host_exit(dwc); + dwc3_gadget_exit(dwc); + dwc3_otg_exit(dwc); + return ret; + } + break; default: dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); @@ -717,8 +738,10 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc) dwc3_host_exit(dwc); break; case USB_DR_MODE_OTG: + dwc3_otg_stop(dwc); dwc3_host_exit(dwc); dwc3_gadget_exit(dwc); + dwc3_otg_exit(dwc); break; default: /* do nothing */ @@ -932,6 +955,12 @@ static int dwc3_probe(struct platform_device *pdev) if (ret < 0) goto err3; + if (dwc->dotg) { + dwc3_core_exit(dwc); + dwc->needs_reinit = 1; + pm_runtime_put_sync(dev); + } + ret = dwc3_core_init_mode(dwc); if (ret) goto err4; @@ -1009,6 +1038,9 @@ static int dwc3_suspend(struct device *dev) struct dwc3 *dwc = dev_get_drvdata(dev); unsigned long flags; + if (dwc->dotg) + dwc3_otg_stop(dwc); + spin_lock_irqsave(&dwc->lock, flags); switch (dwc->dr_mode) { @@ -1067,6 +1099,9 @@ static int dwc3_resume(struct device *dev) pm_runtime_set_active(dev); pm_runtime_enable(dev); + if (dwc->dotg) + dwc3_otg_start(dwc); + return 0; err_usb2phy_init: -- 1.9.1 -- 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