summary refs log tree commit diff
path: root/drivers/usb/dwc3/core.c
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2011-10-31 22:25:40 +0100
committerFelipe Balbi <balbi@ti.com>2011-12-12 11:48:26 +0200
commit3140e8cbfec18ecb9c9ef856933fdb98c09af1e8 (patch)
treec4aad9489eabb168e4bf3eaa5006194286a2a158 /drivers/usb/dwc3/core.c
parentc2da2ff00606ae008f0e233bd29c3307d0c3ce85 (diff)
downloadlinux-3140e8cbfec18ecb9c9ef856933fdb98c09af1e8.tar.gz
usb: dwc3: use a helper function for operation mode setting
There are two where need to set operational mode:
- during initialization while we decide to run in host,device or DRD
  mode
- at runtime via the debugfs interface.

This patch provides a new function which sets the operational mode and
moves its initialiation to the mode switch instead in the gadget code
itself.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/dwc3/core.c')
-rw-r--r--drivers/usb/dwc3/core.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index a2db41162575..217547514faa 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -103,7 +103,15 @@ void dwc3_put_device_id(int id)
 }
 EXPORT_SYMBOL_GPL(dwc3_put_device_id);
 
-/* -------------------------------------------------------------------------- */
+void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
+{
+	u32 reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
+	reg |= DWC3_GCTL_PRTCAPDIR(mode);
+	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+}
 
 /**
  * dwc3_core_soft_reset - Issues core soft reset and PHY reset
@@ -452,6 +460,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
 
 	switch (mode) {
 	case DWC3_MODE_DEVICE:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
 		ret = dwc3_gadget_init(dwc);
 		if (ret) {
 			dev_err(&pdev->dev, "failed to initialize gadget\n");
@@ -459,6 +468,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
 		}
 		break;
 	case DWC3_MODE_HOST:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
 		ret = dwc3_host_init(dwc);
 		if (ret) {
 			dev_err(&pdev->dev, "failed to initialize host\n");
@@ -466,6 +476,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
 		}
 		break;
 	case DWC3_MODE_DRD:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
 		ret = dwc3_host_init(dwc);
 		if (ret) {
 			dev_err(&pdev->dev, "failed to initialize host\n");