}
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
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");
}
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");
}
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");
#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);
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;
}
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: