diff options
author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2011-10-31 17:25:40 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2011-12-12 04:48:26 -0500 |
commit | 3140e8cbfec18ecb9c9ef856933fdb98c09af1e8 (patch) | |
tree | c4aad9489eabb168e4bf3eaa5006194286a2a158 /drivers/usb | |
parent | c2da2ff00606ae008f0e233bd29c3307d0c3ce85 (diff) |
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')
-rw-r--r-- | drivers/usb/dwc3/core.c | 13 | ||||
-rw-r--r-- | drivers/usb/dwc3/core.h | 2 | ||||
-rw-r--r-- | drivers/usb/dwc3/debugfs.c | 21 | ||||
-rw-r--r-- | 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 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) | |||
103 | } | 103 | } |
104 | EXPORT_SYMBOL_GPL(dwc3_put_device_id); | 104 | EXPORT_SYMBOL_GPL(dwc3_put_device_id); |
105 | 105 | ||
106 | /* -------------------------------------------------------------------------- */ | 106 | void dwc3_set_mode(struct dwc3 *dwc, u32 mode) |
107 | { | ||
108 | u32 reg; | ||
109 | |||
110 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | ||
111 | reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG)); | ||
112 | reg |= DWC3_GCTL_PRTCAPDIR(mode); | ||
113 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); | ||
114 | } | ||
107 | 115 | ||
108 | /** | 116 | /** |
109 | * dwc3_core_soft_reset - Issues core soft reset and PHY reset | 117 | * dwc3_core_soft_reset - Issues core soft reset and PHY reset |
@@ -452,6 +460,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev) | |||
452 | 460 | ||
453 | switch (mode) { | 461 | switch (mode) { |
454 | case DWC3_MODE_DEVICE: | 462 | case DWC3_MODE_DEVICE: |
463 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); | ||
455 | ret = dwc3_gadget_init(dwc); | 464 | ret = dwc3_gadget_init(dwc); |
456 | if (ret) { | 465 | if (ret) { |
457 | dev_err(&pdev->dev, "failed to initialize gadget\n"); | 466 | dev_err(&pdev->dev, "failed to initialize gadget\n"); |
@@ -459,6 +468,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev) | |||
459 | } | 468 | } |
460 | break; | 469 | break; |
461 | case DWC3_MODE_HOST: | 470 | case DWC3_MODE_HOST: |
471 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); | ||
462 | ret = dwc3_host_init(dwc); | 472 | ret = dwc3_host_init(dwc); |
463 | if (ret) { | 473 | if (ret) { |
464 | dev_err(&pdev->dev, "failed to initialize host\n"); | 474 | dev_err(&pdev->dev, "failed to initialize host\n"); |
@@ -466,6 +476,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev) | |||
466 | } | 476 | } |
467 | break; | 477 | break; |
468 | case DWC3_MODE_DRD: | 478 | case DWC3_MODE_DRD: |
479 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); | ||
469 | ret = dwc3_host_init(dwc); | 480 | ret = dwc3_host_init(dwc); |
470 | if (ret) { | 481 | if (ret) { |
471 | dev_err(&pdev->dev, "failed to initialize host\n"); | 482 | dev_err(&pdev->dev, "failed to initialize host\n"); |
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index d6f1b793cd04..cecff5624af3 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h | |||
@@ -786,6 +786,8 @@ union dwc3_event { | |||
786 | #define DWC3_HAS_OTG BIT(3) | 786 | #define DWC3_HAS_OTG BIT(3) |
787 | 787 | ||
788 | /* prototypes */ | 788 | /* prototypes */ |
789 | void dwc3_set_mode(struct dwc3 *dwc, u32 mode); | ||
790 | |||
789 | int dwc3_host_init(struct dwc3 *dwc); | 791 | int dwc3_host_init(struct dwc3 *dwc); |
790 | void dwc3_host_exit(struct dwc3 *dwc); | 792 | void dwc3_host_exit(struct dwc3 *dwc); |
791 | 793 | ||
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index b5370e781500..ca4be0afc33d 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, | |||
443 | struct seq_file *s = file->private_data; | 443 | struct seq_file *s = file->private_data; |
444 | struct dwc3 *dwc = s->private; | 444 | struct dwc3 *dwc = s->private; |
445 | unsigned long flags; | 445 | unsigned long flags; |
446 | u32 reg; | 446 | u32 mode = 0; |
447 | char buf[32]; | 447 | char buf[32]; |
448 | 448 | ||
449 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) | 449 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
450 | return -EFAULT; | 450 | return -EFAULT; |
451 | 451 | ||
452 | spin_lock_irqsave(&dwc->lock, flags); | ||
453 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | ||
454 | |||
455 | reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG)); | ||
456 | |||
457 | if (!strncmp(buf, "host", 4)) | 452 | if (!strncmp(buf, "host", 4)) |
458 | reg |= DWC3_GCTL_PRTCAP(DWC3_GCTL_PRTCAP_HOST); | 453 | mode |= DWC3_GCTL_PRTCAP_HOST; |
459 | 454 | ||
460 | if (!strncmp(buf, "device", 6)) | 455 | if (!strncmp(buf, "device", 6)) |
461 | reg |= DWC3_GCTL_PRTCAP(DWC3_GCTL_PRTCAP_DEVICE); | 456 | mode |= DWC3_GCTL_PRTCAP_DEVICE; |
462 | 457 | ||
463 | if (!strncmp(buf, "otg", 3)) | 458 | if (!strncmp(buf, "otg", 3)) |
464 | reg |= DWC3_GCTL_PRTCAP(DWC3_GCTL_PRTCAP_OTG); | 459 | mode |= DWC3_GCTL_PRTCAP_OTG; |
465 | |||
466 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); | ||
467 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
468 | 460 | ||
461 | if (mode) { | ||
462 | spin_lock_irqsave(&dwc->lock, flags); | ||
463 | dwc3_set_mode(dwc, mode); | ||
464 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
465 | } | ||
469 | return count; | 466 | return count; |
470 | } | 467 | } |
471 | 468 | ||
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index b84418e88774..fab4ee0082e2 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, | |||
1158 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | 1158 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
1159 | 1159 | ||
1160 | reg &= ~DWC3_GCTL_SCALEDOWN(3); | 1160 | reg &= ~DWC3_GCTL_SCALEDOWN(3); |
1161 | reg &= ~DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG); | ||
1162 | reg &= ~DWC3_GCTL_DISSCRAMBLE; | 1161 | reg &= ~DWC3_GCTL_DISSCRAMBLE; |
1163 | reg |= DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_DEVICE); | ||
1164 | 1162 | ||
1165 | switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams0)) { | 1163 | switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams0)) { |
1166 | case DWC3_GHWPARAMS1_EN_PWROPT_CLK: | 1164 | case DWC3_GHWPARAMS1_EN_PWROPT_CLK: |