From: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxx> Signed-off-by: Felipe Balbi <balbi@xxxxxx> --- drivers/usb/dwc3/core.c | 13 ++++++++++++- drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/debugfs.c | 21 +++++++++------------ drivers/usb/dwc3/gadget.c | 2 -- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 12309c0..46785a8 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"); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index d6f1b79..cecff56 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -786,6 +786,8 @@ union dwc3_event { #define DWC3_HAS_OTG BIT(3) /* prototypes */ +void dwc3_set_mode(struct dwc3 *dwc, u32 mode); + int dwc3_host_init(struct dwc3 *dwc); void dwc3_host_exit(struct dwc3 *dwc); diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index b5370e7..ca4be0a 100644 --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c @@ -443,29 +443,26 @@ static ssize_t dwc3_mode_write(struct file *file, struct seq_file *s = file->private_data; struct dwc3 *dwc = s->private; unsigned long flags; - u32 reg; + u32 mode = 0; char buf[32]; if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) return -EFAULT; - spin_lock_irqsave(&dwc->lock, flags); - reg = dwc3_readl(dwc->regs, DWC3_GCTL); - - reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG)); - if (!strncmp(buf, "host", 4)) - reg |= DWC3_GCTL_PRTCAP(DWC3_GCTL_PRTCAP_HOST); + mode |= DWC3_GCTL_PRTCAP_HOST; if (!strncmp(buf, "device", 6)) - reg |= DWC3_GCTL_PRTCAP(DWC3_GCTL_PRTCAP_DEVICE); + mode |= DWC3_GCTL_PRTCAP_DEVICE; if (!strncmp(buf, "otg", 3)) - reg |= DWC3_GCTL_PRTCAP(DWC3_GCTL_PRTCAP_OTG); - - dwc3_writel(dwc->regs, DWC3_GCTL, reg); - spin_unlock_irqrestore(&dwc->lock, flags); + mode |= DWC3_GCTL_PRTCAP_OTG; + if (mode) { + spin_lock_irqsave(&dwc->lock, flags); + dwc3_set_mode(dwc, mode); + spin_unlock_irqrestore(&dwc->lock, flags); + } return count; } diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index b84418e..fab4ee0 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1158,9 +1158,7 @@ static int dwc3_gadget_start(struct usb_gadget *g, reg = dwc3_readl(dwc->regs, DWC3_GCTL); reg &= ~DWC3_GCTL_SCALEDOWN(3); - reg &= ~DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG); reg &= ~DWC3_GCTL_DISSCRAMBLE; - reg |= DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_DEVICE); switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams0)) { case DWC3_GHWPARAMS1_EN_PWROPT_CLK: -- 1.7.8.rc3 -- 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