aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2011-12-12 18:19:40 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-12-12 18:19:53 -0500
commit007d00d4c11b30b8fd7ff23b9d5aed3743e41f74 (patch)
treed5c307ba2ee0e2f56fbc284db21b8bccf95d8a40 /drivers/usb
parentc91043adaf50ef13609003120f3471783460fb71 (diff)
parent68d3e668d245bb8300c7c6ddbc8508ddfe352e0f (diff)
Merge branch 'for-next/dwc3' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
* 'for-next/dwc3' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb: (392 commits) usb: dwc3: ep0: fix for possible early delayed_status usb: dwc3: gadget: fix stream enable bit usb: dwc3: ep0: fix GetStatus handling (again) usb: dwc3: ep0: use dwc3_request for ep0 requsts instead of usb_request usb: dwc3: use correct hwparam register for power mgm check usb: dwc3: omap: move to module_platform_driver usb: dwc3: workaround: missing disconnect event usb: dwc3: workaround: missing USB3 Reset event usb: dwc3: workaround: U1/U2 -> U0 transiton usb: dwc3: gadget: return early in dwc3_cleanup_done_reqs() usb: dwc3: ep0: handle delayed_status again usb: dwc3: ep0: push ep0state into xfernotready processing usb: dwc3: fix sparse errors usb: dwc3: fix few coding style problems usb: dwc3: move generic dwc3 code from gadget into core usb: dwc3: use a helper function for operation mode setting usb: dwc3: ep0: don't use ep0in for transfers usb: dwc3: ep0: use proper endianess in SetFeature for wIndex usb: dwc3: core: drop DWC3_EVENT_BUFFERS_MAX usb: dwc3: omap: add multiple instances support to OMAP ...
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/dwc3/Kconfig5
-rw-r--r--drivers/usb/dwc3/Makefile6
-rw-r--r--drivers/usb/dwc3/core.c209
-rw-r--r--drivers/usb/dwc3/core.h62
-rw-r--r--drivers/usb/dwc3/debugfs.c83
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c29
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c49
-rw-r--r--drivers/usb/dwc3/ep0.c160
-rw-r--r--drivers/usb/dwc3/gadget.c197
-rw-r--r--drivers/usb/dwc3/gadget.h29
-rw-r--r--drivers/usb/dwc3/host.c102
-rw-r--r--drivers/usb/dwc3/io.h2
-rw-r--r--drivers/usb/gadget/Kconfig12
-rw-r--r--drivers/usb/gadget/amd5536udc.c2
-rw-r--r--drivers/usb/gadget/f_serial.c4
-rw-r--r--drivers/usb/gadget/fsl_mxc_udc.c3
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c3
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c75
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.h10
-rw-r--r--drivers/usb/gadget/m66592-udc.c2
-rw-r--r--drivers/usb/gadget/net2280.c2
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c2
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c4
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c3
-rw-r--r--drivers/usb/host/ehci-sched.c9
-rw-r--r--drivers/usb/host/whci/qset.c2
-rw-r--r--drivers/usb/host/xhci.c5
-rw-r--r--drivers/usb/musb/musb_core.c6
-rw-r--r--drivers/usb/musb/musb_gadget.c2
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c47
-rw-r--r--drivers/usb/serial/ftdi_sio.c1
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h1
-rw-r--r--drivers/usb/serial/option.c4
-rw-r--r--drivers/usb/storage/unusual_devs.h7
34 files changed, 804 insertions, 335 deletions
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 3c1d67d324fd..d8f741f9e56e 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -1,7 +1,10 @@
1config USB_DWC3 1config USB_DWC3
2 tristate "DesignWare USB3 DRD Core Support" 2 tristate "DesignWare USB3 DRD Core Support"
3 depends on (USB || USB_GADGET) 3 depends on (USB && USB_GADGET)
4 select USB_OTG_UTILS 4 select USB_OTG_UTILS
5 select USB_GADGET_DUALSPEED
6 select USB_GADGET_SUPERSPEED
7 select USB_XHCI_PLATFORM
5 help 8 help
6 Say Y or M here if your system has a Dual Role SuperSpeed 9 Say Y or M here if your system has a Dual Role SuperSpeed
7 USB controller based on the DesignWare USB3 IP Core. 10 USB controller based on the DesignWare USB3 IP Core.
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 593d1dbc465b..900ae74357f1 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -4,10 +4,8 @@ ccflags-$(CONFIG_USB_DWC3_VERBOSE) += -DVERBOSE_DEBUG
4obj-$(CONFIG_USB_DWC3) += dwc3.o 4obj-$(CONFIG_USB_DWC3) += dwc3.o
5 5
6dwc3-y := core.o 6dwc3-y := core.o
7 7dwc3-y += host.o
8ifneq ($(CONFIG_USB_GADGET_DWC3),) 8dwc3-y += gadget.o ep0.o
9 dwc3-y += gadget.o ep0.o
10endif
11 9
12ifneq ($(CONFIG_DEBUG_FS),) 10ifneq ($(CONFIG_DEBUG_FS),)
13 dwc3-y += debugfs.o 11 dwc3-y += debugfs.o
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 717ebc9ff941..455bb1e748d7 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -59,6 +59,60 @@
59 59
60#include "debug.h" 60#include "debug.h"
61 61
62static char *maximum_speed = "super";
63module_param(maximum_speed, charp, 0);
64MODULE_PARM_DESC(maximum_speed, "Maximum supported speed.");
65
66/* -------------------------------------------------------------------------- */
67
68#define DWC3_DEVS_POSSIBLE 32
69
70static DECLARE_BITMAP(dwc3_devs, DWC3_DEVS_POSSIBLE);
71
72int dwc3_get_device_id(void)
73{
74 int id;
75
76again:
77 id = find_first_zero_bit(dwc3_devs, DWC3_DEVS_POSSIBLE);
78 if (id < DWC3_DEVS_POSSIBLE) {
79 int old;
80
81 old = test_and_set_bit(id, dwc3_devs);
82 if (old)
83 goto again;
84 } else {
85 pr_err("dwc3: no space for new device\n");
86 id = -ENOMEM;
87 }
88
89 return 0;
90}
91EXPORT_SYMBOL_GPL(dwc3_get_device_id);
92
93void dwc3_put_device_id(int id)
94{
95 int ret;
96
97 if (id < 0)
98 return;
99
100 ret = test_bit(id, dwc3_devs);
101 WARN(!ret, "dwc3: ID %d not in use\n", id);
102 clear_bit(id, dwc3_devs);
103}
104EXPORT_SYMBOL_GPL(dwc3_put_device_id);
105
106void 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}
115
62/** 116/**
63 * dwc3_core_soft_reset - Issues core soft reset and PHY reset 117 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
64 * @dwc: pointer to our context structure 118 * @dwc: pointer to our context structure
@@ -150,7 +204,7 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc)
150 struct dwc3_event_buffer *evt; 204 struct dwc3_event_buffer *evt;
151 int i; 205 int i;
152 206
153 for (i = 0; i < DWC3_EVENT_BUFFERS_NUM; i++) { 207 for (i = 0; i < dwc->num_event_buffers; i++) {
154 evt = dwc->ev_buffs[i]; 208 evt = dwc->ev_buffs[i];
155 if (evt) { 209 if (evt) {
156 dwc3_free_one_event_buffer(dwc, evt); 210 dwc3_free_one_event_buffer(dwc, evt);
@@ -162,17 +216,25 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc)
162/** 216/**
163 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length 217 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
164 * @dwc: Pointer to out controller context structure 218 * @dwc: Pointer to out controller context structure
165 * @num: number of event buffers to allocate
166 * @length: size of event buffer 219 * @length: size of event buffer
167 * 220 *
168 * Returns 0 on success otherwise negative errno. In error the case, dwc 221 * Returns 0 on success otherwise negative errno. In error the case, dwc
169 * may contain some buffers allocated but not all which were requested. 222 * may contain some buffers allocated but not all which were requested.
170 */ 223 */
171static int __devinit dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned num, 224static int __devinit dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
172 unsigned length)
173{ 225{
226 int num;
174 int i; 227 int i;
175 228
229 num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
230 dwc->num_event_buffers = num;
231
232 dwc->ev_buffs = kzalloc(sizeof(*dwc->ev_buffs) * num, GFP_KERNEL);
233 if (!dwc->ev_buffs) {
234 dev_err(dwc->dev, "can't allocate event buffers array\n");
235 return -ENOMEM;
236 }
237
176 for (i = 0; i < num; i++) { 238 for (i = 0; i < num; i++) {
177 struct dwc3_event_buffer *evt; 239 struct dwc3_event_buffer *evt;
178 240
@@ -198,7 +260,7 @@ static int __devinit dwc3_event_buffers_setup(struct dwc3 *dwc)
198 struct dwc3_event_buffer *evt; 260 struct dwc3_event_buffer *evt;
199 int n; 261 int n;
200 262
201 for (n = 0; n < DWC3_EVENT_BUFFERS_NUM; n++) { 263 for (n = 0; n < dwc->num_event_buffers; n++) {
202 evt = dwc->ev_buffs[n]; 264 evt = dwc->ev_buffs[n];
203 dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n", 265 dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n",
204 evt->buf, (unsigned long long) evt->dma, 266 evt->buf, (unsigned long long) evt->dma,
@@ -221,7 +283,7 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
221 struct dwc3_event_buffer *evt; 283 struct dwc3_event_buffer *evt;
222 int n; 284 int n;
223 285
224 for (n = 0; n < DWC3_EVENT_BUFFERS_NUM; n++) { 286 for (n = 0; n < dwc->num_event_buffers; n++) {
225 evt = dwc->ev_buffs[n]; 287 evt = dwc->ev_buffs[n];
226 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0); 288 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
227 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0); 289 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
@@ -285,8 +347,32 @@ static int __devinit dwc3_core_init(struct dwc3 *dwc)
285 cpu_relax(); 347 cpu_relax();
286 } while (true); 348 } while (true);
287 349
288 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_NUM, 350 dwc3_cache_hwparams(dwc);
289 DWC3_EVENT_BUFFERS_SIZE); 351
352 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
353 reg &= ~DWC3_GCTL_SCALEDOWN(3);
354 reg &= ~DWC3_GCTL_DISSCRAMBLE;
355
356 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
357 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
358 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
359 break;
360 default:
361 dev_dbg(dwc->dev, "No power optimization available\n");
362 }
363
364 /*
365 * WORKAROUND: DWC3 revisions <1.90a have a bug
366 * when The device fails to connect at SuperSpeed
367 * and falls back to high-speed mode which causes
368 * the device to enter in a Connect/Disconnect loop
369 */
370 if (dwc->revision < DWC3_REVISION_190A)
371 reg |= DWC3_GCTL_U2RSTECN;
372
373 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
374
375 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
290 if (ret) { 376 if (ret) {
291 dev_err(dwc->dev, "failed to allocate event buffers\n"); 377 dev_err(dwc->dev, "failed to allocate event buffers\n");
292 ret = -ENOMEM; 378 ret = -ENOMEM;
@@ -299,8 +385,6 @@ static int __devinit dwc3_core_init(struct dwc3 *dwc)
299 goto err1; 385 goto err1;
300 } 386 }
301 387
302 dwc3_cache_hwparams(dwc);
303
304 return 0; 388 return 0;
305 389
306err1: 390err1:
@@ -320,15 +404,17 @@ static void dwc3_core_exit(struct dwc3 *dwc)
320 404
321static int __devinit dwc3_probe(struct platform_device *pdev) 405static int __devinit dwc3_probe(struct platform_device *pdev)
322{ 406{
323 const struct platform_device_id *id = platform_get_device_id(pdev);
324 struct resource *res; 407 struct resource *res;
325 struct dwc3 *dwc; 408 struct dwc3 *dwc;
326 void __iomem *regs; 409
327 unsigned int features = id->driver_data;
328 int ret = -ENOMEM; 410 int ret = -ENOMEM;
329 int irq; 411 int irq;
412
413 void __iomem *regs;
330 void *mem; 414 void *mem;
331 415
416 u8 mode;
417
332 mem = kzalloc(sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); 418 mem = kzalloc(sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
333 if (!mem) { 419 if (!mem) {
334 dev_err(&pdev->dev, "not enough memory\n"); 420 dev_err(&pdev->dev, "not enough memory\n");
@@ -343,6 +429,8 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
343 goto err1; 429 goto err1;
344 } 430 }
345 431
432 dwc->res = res;
433
346 res = request_mem_region(res->start, resource_size(res), 434 res = request_mem_region(res->start, resource_size(res),
347 dev_name(&pdev->dev)); 435 dev_name(&pdev->dev));
348 if (!res) { 436 if (!res) {
@@ -370,6 +458,17 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
370 dwc->dev = &pdev->dev; 458 dwc->dev = &pdev->dev;
371 dwc->irq = irq; 459 dwc->irq = irq;
372 460
461 if (!strncmp("super", maximum_speed, 5))
462 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
463 else if (!strncmp("high", maximum_speed, 4))
464 dwc->maximum_speed = DWC3_DCFG_HIGHSPEED;
465 else if (!strncmp("full", maximum_speed, 4))
466 dwc->maximum_speed = DWC3_DCFG_FULLSPEED1;
467 else if (!strncmp("low", maximum_speed, 3))
468 dwc->maximum_speed = DWC3_DCFG_LOWSPEED;
469 else
470 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
471
373 pm_runtime_enable(&pdev->dev); 472 pm_runtime_enable(&pdev->dev);
374 pm_runtime_get_sync(&pdev->dev); 473 pm_runtime_get_sync(&pdev->dev);
375 pm_runtime_forbid(&pdev->dev); 474 pm_runtime_forbid(&pdev->dev);
@@ -380,13 +479,44 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
380 goto err3; 479 goto err3;
381 } 480 }
382 481
383 if (features & DWC3_HAS_PERIPHERAL) { 482 mode = DWC3_MODE(dwc->hwparams.hwparams0);
483
484 switch (mode) {
485 case DWC3_MODE_DEVICE:
486 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
384 ret = dwc3_gadget_init(dwc); 487 ret = dwc3_gadget_init(dwc);
385 if (ret) { 488 if (ret) {
386 dev_err(&pdev->dev, "failed to initialized gadget\n"); 489 dev_err(&pdev->dev, "failed to initialize gadget\n");
387 goto err4; 490 goto err4;
388 } 491 }
492 break;
493 case DWC3_MODE_HOST:
494 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
495 ret = dwc3_host_init(dwc);
496 if (ret) {
497 dev_err(&pdev->dev, "failed to initialize host\n");
498 goto err4;
499 }
500 break;
501 case DWC3_MODE_DRD:
502 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
503 ret = dwc3_host_init(dwc);
504 if (ret) {
505 dev_err(&pdev->dev, "failed to initialize host\n");
506 goto err4;
507 }
508
509 ret = dwc3_gadget_init(dwc);
510 if (ret) {
511 dev_err(&pdev->dev, "failed to initialize gadget\n");
512 goto err4;
513 }
514 break;
515 default:
516 dev_err(&pdev->dev, "Unsupported mode of operation %d\n", mode);
517 goto err4;
389 } 518 }
519 dwc->mode = mode;
390 520
391 ret = dwc3_debugfs_init(dwc); 521 ret = dwc3_debugfs_init(dwc);
392 if (ret) { 522 if (ret) {
@@ -399,8 +529,21 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
399 return 0; 529 return 0;
400 530
401err5: 531err5:
402 if (features & DWC3_HAS_PERIPHERAL) 532 switch (mode) {
533 case DWC3_MODE_DEVICE:
534 dwc3_gadget_exit(dwc);
535 break;
536 case DWC3_MODE_HOST:
537 dwc3_host_exit(dwc);
538 break;
539 case DWC3_MODE_DRD:
540 dwc3_host_exit(dwc);
403 dwc3_gadget_exit(dwc); 541 dwc3_gadget_exit(dwc);
542 break;
543 default:
544 /* do nothing */
545 break;
546 }
404 547
405err4: 548err4:
406 dwc3_core_exit(dwc); 549 dwc3_core_exit(dwc);
@@ -420,10 +563,8 @@ err0:
420 563
421static int __devexit dwc3_remove(struct platform_device *pdev) 564static int __devexit dwc3_remove(struct platform_device *pdev)
422{ 565{
423 const struct platform_device_id *id = platform_get_device_id(pdev);
424 struct dwc3 *dwc = platform_get_drvdata(pdev); 566 struct dwc3 *dwc = platform_get_drvdata(pdev);
425 struct resource *res; 567 struct resource *res;
426 unsigned int features = id->driver_data;
427 568
428 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 569 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
429 570
@@ -432,8 +573,21 @@ static int __devexit dwc3_remove(struct platform_device *pdev)
432 573
433 dwc3_debugfs_exit(dwc); 574 dwc3_debugfs_exit(dwc);
434 575
435 if (features & DWC3_HAS_PERIPHERAL) 576 switch (dwc->mode) {
577 case DWC3_MODE_DEVICE:
578 dwc3_gadget_exit(dwc);
579 break;
580 case DWC3_MODE_HOST:
581 dwc3_host_exit(dwc);
582 break;
583 case DWC3_MODE_DRD:
584 dwc3_host_exit(dwc);
436 dwc3_gadget_exit(dwc); 585 dwc3_gadget_exit(dwc);
586 break;
587 default:
588 /* do nothing */
589 break;
590 }
437 591
438 dwc3_core_exit(dwc); 592 dwc3_core_exit(dwc);
439 release_mem_region(res->start, resource_size(res)); 593 release_mem_region(res->start, resource_size(res));
@@ -443,30 +597,15 @@ static int __devexit dwc3_remove(struct platform_device *pdev)
443 return 0; 597 return 0;
444} 598}
445 599
446static const struct platform_device_id dwc3_id_table[] __devinitconst = {
447 {
448 .name = "dwc3-omap",
449 .driver_data = (DWC3_HAS_PERIPHERAL
450 | DWC3_HAS_XHCI
451 | DWC3_HAS_OTG),
452 },
453 {
454 .name = "dwc3-pci",
455 .driver_data = DWC3_HAS_PERIPHERAL,
456 },
457 { }, /* Terminating Entry */
458};
459MODULE_DEVICE_TABLE(platform, dwc3_id_table);
460
461static struct platform_driver dwc3_driver = { 600static struct platform_driver dwc3_driver = {
462 .probe = dwc3_probe, 601 .probe = dwc3_probe,
463 .remove = __devexit_p(dwc3_remove), 602 .remove = __devexit_p(dwc3_remove),
464 .driver = { 603 .driver = {
465 .name = "dwc3", 604 .name = "dwc3",
466 }, 605 },
467 .id_table = dwc3_id_table,
468}; 606};
469 607
608MODULE_ALIAS("platform:dwc3");
470MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 609MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
471MODULE_LICENSE("Dual BSD/GPL"); 610MODULE_LICENSE("Dual BSD/GPL");
472MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); 611MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 29a8e1679e12..9e57f8e9bf17 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -41,6 +41,7 @@
41 41
42#include <linux/device.h> 42#include <linux/device.h>
43#include <linux/spinlock.h> 43#include <linux/spinlock.h>
44#include <linux/ioport.h>
44#include <linux/list.h> 45#include <linux/list.h>
45#include <linux/dma-mapping.h> 46#include <linux/dma-mapping.h>
46#include <linux/mm.h> 47#include <linux/mm.h>
@@ -52,7 +53,6 @@
52/* Global constants */ 53/* Global constants */
53#define DWC3_ENDPOINTS_NUM 32 54#define DWC3_ENDPOINTS_NUM 32
54 55
55#define DWC3_EVENT_BUFFERS_NUM 2
56#define DWC3_EVENT_BUFFERS_SIZE PAGE_SIZE 56#define DWC3_EVENT_BUFFERS_SIZE PAGE_SIZE
57#define DWC3_EVENT_TYPE_MASK 0xfe 57#define DWC3_EVENT_TYPE_MASK 0xfe
58 58
@@ -153,6 +153,7 @@
153#define DWC3_GCTL_CLK_PIPEHALF (2) 153#define DWC3_GCTL_CLK_PIPEHALF (2)
154#define DWC3_GCTL_CLK_MASK (3) 154#define DWC3_GCTL_CLK_MASK (3)
155 155
156#define DWC3_GCTL_PRTCAP(n) (((n) & (3 << 12)) >> 12)
156#define DWC3_GCTL_PRTCAPDIR(n) (n << 12) 157#define DWC3_GCTL_PRTCAPDIR(n) (n << 12)
157#define DWC3_GCTL_PRTCAP_HOST 1 158#define DWC3_GCTL_PRTCAP_HOST 1
158#define DWC3_GCTL_PRTCAP_DEVICE 2 159#define DWC3_GCTL_PRTCAP_DEVICE 2
@@ -347,6 +348,7 @@ struct dwc3_ep {
347 u32 free_slot; 348 u32 free_slot;
348 u32 busy_slot; 349 u32 busy_slot;
349 const struct usb_endpoint_descriptor *desc; 350 const struct usb_endpoint_descriptor *desc;
351 const struct usb_ss_ep_comp_descriptor *comp_desc;
350 struct dwc3 *dwc; 352 struct dwc3 *dwc;
351 353
352 unsigned flags; 354 unsigned flags;
@@ -536,6 +538,31 @@ struct dwc3_hwparams {
536 u32 hwparams8; 538 u32 hwparams8;
537}; 539};
538 540
541/* HWPARAMS0 */
542#define DWC3_MODE(n) ((n) & 0x7)
543
544#define DWC3_MODE_DEVICE 0
545#define DWC3_MODE_HOST 1
546#define DWC3_MODE_DRD 2
547#define DWC3_MODE_HUB 3
548
549/* HWPARAMS1 */
550#define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15)
551
552struct dwc3_request {
553 struct usb_request request;
554 struct list_head list;
555 struct dwc3_ep *dep;
556
557 u8 epnum;
558 struct dwc3_trb_hw *trb;
559 dma_addr_t trb_dma;
560
561 unsigned direction:1;
562 unsigned mapped:1;
563 unsigned queued:1;
564};
565
539/** 566/**
540 * struct dwc3 - representation of our controller 567 * struct dwc3 - representation of our controller
541 * @ctrl_req: usb control request which is used for ep0 568 * @ctrl_req: usb control request which is used for ep0
@@ -549,19 +576,24 @@ struct dwc3_hwparams {
549 * @ep0_bounce_addr: dma address of ep0_bounce 576 * @ep0_bounce_addr: dma address of ep0_bounce
550 * @lock: for synchronizing 577 * @lock: for synchronizing
551 * @dev: pointer to our struct device 578 * @dev: pointer to our struct device
579 * @xhci: pointer to our xHCI child
552 * @event_buffer_list: a list of event buffers 580 * @event_buffer_list: a list of event buffers
553 * @gadget: device side representation of the peripheral controller 581 * @gadget: device side representation of the peripheral controller
554 * @gadget_driver: pointer to the gadget driver 582 * @gadget_driver: pointer to the gadget driver
555 * @regs: base address for our registers 583 * @regs: base address for our registers
556 * @regs_size: address space size 584 * @regs_size: address space size
557 * @irq: IRQ number 585 * @irq: IRQ number
586 * @num_event_buffers: calculated number of event buffers
587 * @u1u2: only used on revisions <1.83a for workaround
588 * @maximum_speed: maximum speed requested (mainly for testing purposes)
558 * @revision: revision register contents 589 * @revision: revision register contents
590 * @mode: mode of operation
559 * @is_selfpowered: true when we are selfpowered 591 * @is_selfpowered: true when we are selfpowered
560 * @three_stage_setup: set if we perform a three phase setup 592 * @three_stage_setup: set if we perform a three phase setup
561 * @ep0_status_pending: ep0 status response without a req is pending
562 * @ep0_bounced: true when we used bounce buffer 593 * @ep0_bounced: true when we used bounce buffer
563 * @ep0_expect_in: true when we expect a DATA IN transfer 594 * @ep0_expect_in: true when we expect a DATA IN transfer
564 * @start_config_issued: true when StartConfig command has been issued 595 * @start_config_issued: true when StartConfig command has been issued
596 * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
565 * @ep0_next_event: hold the next expected event 597 * @ep0_next_event: hold the next expected event
566 * @ep0state: state of endpoint zero 598 * @ep0state: state of endpoint zero
567 * @link_state: link state 599 * @link_state: link state
@@ -579,12 +611,15 @@ struct dwc3 {
579 dma_addr_t ep0_trb_addr; 611 dma_addr_t ep0_trb_addr;
580 dma_addr_t setup_buf_addr; 612 dma_addr_t setup_buf_addr;
581 dma_addr_t ep0_bounce_addr; 613 dma_addr_t ep0_bounce_addr;
582 struct usb_request ep0_usb_req; 614 struct dwc3_request ep0_usb_req;
583 /* device lock */ 615 /* device lock */
584 spinlock_t lock; 616 spinlock_t lock;
585 struct device *dev; 617 struct device *dev;
586 618
587 struct dwc3_event_buffer *ev_buffs[DWC3_EVENT_BUFFERS_NUM]; 619 struct platform_device *xhci;
620 struct resource *res;
621
622 struct dwc3_event_buffer **ev_buffs;
588 struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; 623 struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM];
589 624
590 struct usb_gadget gadget; 625 struct usb_gadget gadget;
@@ -595,7 +630,11 @@ struct dwc3 {
595 630
596 int irq; 631 int irq;
597 632
633 u32 num_event_buffers;
634 u32 u1u2;
635 u32 maximum_speed;
598 u32 revision; 636 u32 revision;
637 u32 mode;
599 638
600#define DWC3_REVISION_173A 0x5533173a 639#define DWC3_REVISION_173A 0x5533173a
601#define DWC3_REVISION_175A 0x5533175a 640#define DWC3_REVISION_175A 0x5533175a
@@ -607,10 +646,11 @@ struct dwc3 {
607 646
608 unsigned is_selfpowered:1; 647 unsigned is_selfpowered:1;
609 unsigned three_stage_setup:1; 648 unsigned three_stage_setup:1;
610 unsigned ep0_status_pending:1;
611 unsigned ep0_bounced:1; 649 unsigned ep0_bounced:1;
612 unsigned ep0_expect_in:1; 650 unsigned ep0_expect_in:1;
613 unsigned start_config_issued:1; 651 unsigned start_config_issued:1;
652 unsigned setup_packet_pending:1;
653 unsigned delayed_status:1;
614 654
615 enum dwc3_ep0_next ep0_next_event; 655 enum dwc3_ep0_next ep0_next_event;
616 enum dwc3_ep0_state ep0state; 656 enum dwc3_ep0_state ep0state;
@@ -765,4 +805,16 @@ union dwc3_event {
765#define DWC3_HAS_XHCI BIT(1) 805#define DWC3_HAS_XHCI BIT(1)
766#define DWC3_HAS_OTG BIT(3) 806#define DWC3_HAS_OTG BIT(3)
767 807
808/* prototypes */
809void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
810
811int dwc3_host_init(struct dwc3 *dwc);
812void dwc3_host_exit(struct dwc3 *dwc);
813
814int dwc3_gadget_init(struct dwc3 *dwc);
815void dwc3_gadget_exit(struct dwc3 *dwc);
816
817extern int dwc3_get_device_id(void);
818extern void dwc3_put_device_id(int id);
819
768#endif /* __DRIVERS_USB_DWC3_CORE_H */ 820#endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index da1ad77d8d51..87d403df1f3f 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -44,12 +44,12 @@
44#include <linux/debugfs.h> 44#include <linux/debugfs.h>
45#include <linux/seq_file.h> 45#include <linux/seq_file.h>
46#include <linux/delay.h> 46#include <linux/delay.h>
47 47#include <linux/uaccess.h>
48#include <asm/uaccess.h>
49 48
50#include "core.h" 49#include "core.h"
51#include "gadget.h" 50#include "gadget.h"
52#include "io.h" 51#include "io.h"
52#include "debug.h"
53 53
54struct dwc3_register { 54struct dwc3_register {
55 const char *name; 55 const char *name;
@@ -405,6 +405,75 @@ static const struct file_operations dwc3_regdump_fops = {
405 .release = single_release, 405 .release = single_release,
406}; 406};
407 407
408static int dwc3_mode_show(struct seq_file *s, void *unused)
409{
410 struct dwc3 *dwc = s->private;
411 unsigned long flags;
412 u32 reg;
413
414 spin_lock_irqsave(&dwc->lock, flags);
415 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
416 spin_unlock_irqrestore(&dwc->lock, flags);
417
418 switch (DWC3_GCTL_PRTCAP(reg)) {
419 case DWC3_GCTL_PRTCAP_HOST:
420 seq_printf(s, "host\n");
421 break;
422 case DWC3_GCTL_PRTCAP_DEVICE:
423 seq_printf(s, "device\n");
424 break;
425 case DWC3_GCTL_PRTCAP_OTG:
426 seq_printf(s, "OTG\n");
427 break;
428 default:
429 seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
430 }
431
432 return 0;
433}
434
435static int dwc3_mode_open(struct inode *inode, struct file *file)
436{
437 return single_open(file, dwc3_mode_show, inode->i_private);
438}
439
440static ssize_t dwc3_mode_write(struct file *file,
441 const char __user *ubuf, size_t count, loff_t *ppos)
442{
443 struct seq_file *s = file->private_data;
444 struct dwc3 *dwc = s->private;
445 unsigned long flags;
446 u32 mode = 0;
447 char buf[32];
448
449 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
450 return -EFAULT;
451
452 if (!strncmp(buf, "host", 4))
453 mode |= DWC3_GCTL_PRTCAP_HOST;
454
455 if (!strncmp(buf, "device", 6))
456 mode |= DWC3_GCTL_PRTCAP_DEVICE;
457
458 if (!strncmp(buf, "otg", 3))
459 mode |= DWC3_GCTL_PRTCAP_OTG;
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 }
466 return count;
467}
468
469static const struct file_operations dwc3_mode_fops = {
470 .open = dwc3_mode_open,
471 .write = dwc3_mode_write,
472 .read = seq_read,
473 .llseek = seq_lseek,
474 .release = single_release,
475};
476
408int __devinit dwc3_debugfs_init(struct dwc3 *dwc) 477int __devinit dwc3_debugfs_init(struct dwc3 *dwc)
409{ 478{
410 struct dentry *root; 479 struct dentry *root;
@@ -412,7 +481,7 @@ int __devinit dwc3_debugfs_init(struct dwc3 *dwc)
412 int ret; 481 int ret;
413 482
414 root = debugfs_create_dir(dev_name(dwc->dev), NULL); 483 root = debugfs_create_dir(dev_name(dwc->dev), NULL);
415 if (IS_ERR(root)){ 484 if (IS_ERR(root)) {
416 ret = PTR_ERR(root); 485 ret = PTR_ERR(root);
417 goto err0; 486 goto err0;
418 } 487 }
@@ -425,6 +494,14 @@ int __devinit dwc3_debugfs_init(struct dwc3 *dwc)
425 ret = PTR_ERR(file); 494 ret = PTR_ERR(file);
426 goto err1; 495 goto err1;
427 } 496 }
497
498 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
499 dwc, &dwc3_mode_fops);
500 if (IS_ERR(file)) {
501 ret = PTR_ERR(file);
502 goto err1;
503 }
504
428 return 0; 505 return 0;
429 506
430err1: 507err1:
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 4e27d5bf40ad..3274ac8f1200 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -48,6 +48,7 @@
48#include <linux/io.h> 48#include <linux/io.h>
49#include <linux/module.h> 49#include <linux/module.h>
50 50
51#include "core.h"
51#include "io.h" 52#include "io.h"
52 53
53/* 54/*
@@ -200,6 +201,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
200 struct dwc3_omap *omap; 201 struct dwc3_omap *omap;
201 struct resource *res; 202 struct resource *res;
202 203
204 int devid;
203 int ret = -ENOMEM; 205 int ret = -ENOMEM;
204 int irq; 206 int irq;
205 207
@@ -236,16 +238,20 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
236 goto err1; 238 goto err1;
237 } 239 }
238 240
239 dwc3 = platform_device_alloc("dwc3-omap", -1); 241 devid = dwc3_get_device_id();
242 if (devid < 0)
243 goto err2;
244
245 dwc3 = platform_device_alloc("dwc3", devid);
240 if (!dwc3) { 246 if (!dwc3) {
241 dev_err(&pdev->dev, "couldn't allocate dwc3 device\n"); 247 dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
242 goto err2; 248 goto err3;
243 } 249 }
244 250
245 context = kzalloc(resource_size(res), GFP_KERNEL); 251 context = kzalloc(resource_size(res), GFP_KERNEL);
246 if (!context) { 252 if (!context) {
247 dev_err(&pdev->dev, "couldn't allocate dwc3 context memory\n"); 253 dev_err(&pdev->dev, "couldn't allocate dwc3 context memory\n");
248 goto err3; 254 goto err4;
249 } 255 }
250 256
251 spin_lock_init(&omap->lock); 257 spin_lock_init(&omap->lock);
@@ -299,7 +305,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
299 if (ret) { 305 if (ret) {
300 dev_err(&pdev->dev, "failed to request IRQ #%d --> %d\n", 306 dev_err(&pdev->dev, "failed to request IRQ #%d --> %d\n",
301 omap->irq, ret); 307 omap->irq, ret);
302 goto err4; 308 goto err5;
303 } 309 }
304 310
305 /* enable all IRQs */ 311 /* enable all IRQs */
@@ -322,26 +328,29 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev)
322 pdev->num_resources); 328 pdev->num_resources);
323 if (ret) { 329 if (ret) {
324 dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n"); 330 dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n");
325 goto err5; 331 goto err6;
326 } 332 }
327 333
328 ret = platform_device_add(dwc3); 334 ret = platform_device_add(dwc3);
329 if (ret) { 335 if (ret) {
330 dev_err(&pdev->dev, "failed to register dwc3 device\n"); 336 dev_err(&pdev->dev, "failed to register dwc3 device\n");
331 goto err5; 337 goto err6;
332 } 338 }
333 339
334 return 0; 340 return 0;
335 341
336err5: 342err6:
337 free_irq(omap->irq, omap); 343 free_irq(omap->irq, omap);
338 344
339err4: 345err5:
340 kfree(omap->context); 346 kfree(omap->context);
341 347
342err3: 348err4:
343 platform_device_put(dwc3); 349 platform_device_put(dwc3);
344 350
351err3:
352 dwc3_put_device_id(devid);
353
345err2: 354err2:
346 iounmap(base); 355 iounmap(base);
347 356
@@ -358,6 +367,7 @@ static int __devexit dwc3_omap_remove(struct platform_device *pdev)
358 367
359 platform_device_unregister(omap->dwc3); 368 platform_device_unregister(omap->dwc3);
360 369
370 dwc3_put_device_id(omap->dwc3->id);
361 free_irq(omap->irq, omap); 371 free_irq(omap->irq, omap);
362 iounmap(omap->base); 372 iounmap(omap->base);
363 373
@@ -386,6 +396,7 @@ static struct platform_driver dwc3_omap_driver = {
386 396
387module_platform_driver(dwc3_omap_driver); 397module_platform_driver(dwc3_omap_driver);
388 398
399MODULE_ALIAS("platform:omap-dwc3");
389MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 400MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
390MODULE_LICENSE("Dual BSD/GPL"); 401MODULE_LICENSE("Dual BSD/GPL");
391MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer"); 402MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index f77c00042685..cd1429f168c2 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -42,52 +42,17 @@
42#include <linux/pci.h> 42#include <linux/pci.h>
43#include <linux/platform_device.h> 43#include <linux/platform_device.h>
44 44
45#include "core.h"
46
45/* FIXME define these in <linux/pci_ids.h> */ 47/* FIXME define these in <linux/pci_ids.h> */
46#define PCI_VENDOR_ID_SYNOPSYS 0x16c3 48#define PCI_VENDOR_ID_SYNOPSYS 0x16c3
47#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 49#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd
48 50
49#define DWC3_PCI_DEVS_POSSIBLE 32
50
51struct dwc3_pci { 51struct dwc3_pci {
52 struct device *dev; 52 struct device *dev;
53 struct platform_device *dwc3; 53 struct platform_device *dwc3;
54}; 54};
55 55
56static DECLARE_BITMAP(dwc3_pci_devs, DWC3_PCI_DEVS_POSSIBLE);
57
58static int dwc3_pci_get_device_id(struct dwc3_pci *glue)
59{
60 int id;
61
62again:
63 id = find_first_zero_bit(dwc3_pci_devs, DWC3_PCI_DEVS_POSSIBLE);
64 if (id < DWC3_PCI_DEVS_POSSIBLE) {
65 int old;
66
67 old = test_and_set_bit(id, dwc3_pci_devs);
68 if (old)
69 goto again;
70 } else {
71 dev_err(glue->dev, "no space for new device\n");
72 id = -ENOMEM;
73 }
74
75 return 0;
76}
77
78static void dwc3_pci_put_device_id(struct dwc3_pci *glue, int id)
79{
80 int ret;
81
82 if (id < 0)
83 return;
84
85 ret = test_bit(id, dwc3_pci_devs);
86 WARN(!ret, "Device: %s\nID %d not in use\n",
87 dev_driver_string(glue->dev), id);
88 clear_bit(id, dwc3_pci_devs);
89}
90
91static int __devinit dwc3_pci_probe(struct pci_dev *pci, 56static int __devinit dwc3_pci_probe(struct pci_dev *pci,
92 const struct pci_device_id *id) 57 const struct pci_device_id *id)
93{ 58{
@@ -114,11 +79,11 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci,
114 pci_set_power_state(pci, PCI_D0); 79 pci_set_power_state(pci, PCI_D0);
115 pci_set_master(pci); 80 pci_set_master(pci);
116 81
117 devid = dwc3_pci_get_device_id(glue); 82 devid = dwc3_get_device_id();
118 if (devid < 0) 83 if (devid < 0)
119 goto err2; 84 goto err2;
120 85
121 dwc3 = platform_device_alloc("dwc3-pci", devid); 86 dwc3 = platform_device_alloc("dwc3", devid);
122 if (!dwc3) { 87 if (!dwc3) {
123 dev_err(&pci->dev, "couldn't allocate dwc3 device\n"); 88 dev_err(&pci->dev, "couldn't allocate dwc3 device\n");
124 goto err3; 89 goto err3;
@@ -163,7 +128,7 @@ err4:
163 platform_device_put(dwc3); 128 platform_device_put(dwc3);
164 129
165err3: 130err3:
166 dwc3_pci_put_device_id(glue, devid); 131 dwc3_put_device_id(devid);
167 132
168err2: 133err2:
169 pci_disable_device(pci); 134 pci_disable_device(pci);
@@ -179,7 +144,7 @@ static void __devexit dwc3_pci_remove(struct pci_dev *pci)
179{ 144{
180 struct dwc3_pci *glue = pci_get_drvdata(pci); 145 struct dwc3_pci *glue = pci_get_drvdata(pci);
181 146
182 dwc3_pci_put_device_id(glue, glue->dwc3->id); 147 dwc3_put_device_id(glue->dwc3->id);
183 platform_device_unregister(glue->dwc3); 148 platform_device_unregister(glue->dwc3);
184 pci_set_drvdata(pci, NULL); 149 pci_set_drvdata(pci, NULL);
185 pci_disable_device(pci); 150 pci_disable_device(pci);
@@ -196,7 +161,7 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {
196MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); 161MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
197 162
198static struct pci_driver dwc3_pci_driver = { 163static struct pci_driver dwc3_pci_driver = {
199 .name = "pci-dwc3", 164 .name = "dwc3-pci",
200 .id_table = dwc3_pci_id_table, 165 .id_table = dwc3_pci_id_table,
201 .probe = dwc3_pci_probe, 166 .probe = dwc3_pci_probe,
202 .remove = __devexit_p(dwc3_pci_remove), 167 .remove = __devexit_p(dwc3_pci_remove),
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 69a4e43ddf59..2f51de57593a 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -48,13 +48,13 @@
48 48
49#include <linux/usb/ch9.h> 49#include <linux/usb/ch9.h>
50#include <linux/usb/gadget.h> 50#include <linux/usb/gadget.h>
51#include <linux/usb/composite.h>
51 52
52#include "core.h" 53#include "core.h"
53#include "gadget.h" 54#include "gadget.h"
54#include "io.h" 55#include "io.h"
55 56
56static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, 57static void dwc3_ep0_do_control_status(struct dwc3 *dwc, u32 epnum);
57 const struct dwc3_event_depevt *event);
58 58
59static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state) 59static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
60{ 60{
@@ -125,6 +125,8 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
125static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep, 125static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
126 struct dwc3_request *req) 126 struct dwc3_request *req)
127{ 127{
128 struct dwc3 *dwc = dep->dwc;
129 u32 type;
128 int ret = 0; 130 int ret = 0;
129 131
130 req->request.actual = 0; 132 req->request.actual = 0;
@@ -143,9 +145,7 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
143 * IRQ we were waiting for is long gone. 145 * IRQ we were waiting for is long gone.
144 */ 146 */
145 if (dep->flags & DWC3_EP_PENDING_REQUEST) { 147 if (dep->flags & DWC3_EP_PENDING_REQUEST) {
146 struct dwc3 *dwc = dep->dwc;
147 unsigned direction; 148 unsigned direction;
148 u32 type;
149 149
150 direction = !!(dep->flags & DWC3_EP0_DIR_IN); 150 direction = !!(dep->flags & DWC3_EP0_DIR_IN);
151 151
@@ -165,6 +165,13 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
165 req->request.dma, req->request.length, type); 165 req->request.dma, req->request.length, type);
166 dep->flags &= ~(DWC3_EP_PENDING_REQUEST | 166 dep->flags &= ~(DWC3_EP_PENDING_REQUEST |
167 DWC3_EP0_DIR_IN); 167 DWC3_EP0_DIR_IN);
168 } else if (dwc->delayed_status) {
169 dwc->delayed_status = false;
170
171 if (dwc->ep0state == EP0_STATUS_PHASE)
172 dwc3_ep0_do_control_status(dwc, 1);
173 else
174 dev_dbg(dwc->dev, "too early for delayed status\n");
168 } 175 }
169 176
170 return ret; 177 return ret;
@@ -190,9 +197,7 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
190 } 197 }
191 198
192 /* we share one TRB for ep0/1 */ 199 /* we share one TRB for ep0/1 */
193 if (!list_empty(&dwc->eps[0]->request_list) || 200 if (!list_empty(&dep->request_list)) {
194 !list_empty(&dwc->eps[1]->request_list) ||
195 dwc->ep0_status_pending) {
196 ret = -EBUSY; 201 ret = -EBUSY;
197 goto out; 202 goto out;
198 } 203 }
@@ -214,8 +219,9 @@ static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc)
214 struct dwc3_ep *dep = dwc->eps[0]; 219 struct dwc3_ep *dep = dwc->eps[0];
215 220
216 /* stall is always issued on EP0 */ 221 /* stall is always issued on EP0 */
217 __dwc3_gadget_ep_set_halt(dwc->eps[0], 1); 222 __dwc3_gadget_ep_set_halt(dep, 1);
218 dwc->eps[0]->flags = DWC3_EP_ENABLED; 223 dep->flags = DWC3_EP_ENABLED;
224 dwc->delayed_status = false;
219 225
220 if (!list_empty(&dep->request_list)) { 226 if (!list_empty(&dep->request_list)) {
221 struct dwc3_request *req; 227 struct dwc3_request *req;
@@ -254,17 +260,14 @@ static struct dwc3_ep *dwc3_wIndex_to_dep(struct dwc3 *dwc, __le16 wIndex_le)
254 return NULL; 260 return NULL;
255} 261}
256 262
257static void dwc3_ep0_send_status_response(struct dwc3 *dwc) 263static void dwc3_ep0_status_cmpl(struct usb_ep *ep, struct usb_request *req)
258{ 264{
259 dwc3_ep0_start_trans(dwc, 1, dwc->setup_buf_addr,
260 dwc->ep0_usb_req.length,
261 DWC3_TRBCTL_CONTROL_DATA);
262} 265}
263
264/* 266/*
265 * ch 9.4.5 267 * ch 9.4.5
266 */ 268 */
267static int dwc3_ep0_handle_status(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 269static int dwc3_ep0_handle_status(struct dwc3 *dwc,
270 struct usb_ctrlrequest *ctrl)
268{ 271{
269 struct dwc3_ep *dep; 272 struct dwc3_ep *dep;
270 u32 recip; 273 u32 recip;
@@ -291,7 +294,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl
291 case USB_RECIP_ENDPOINT: 294 case USB_RECIP_ENDPOINT:
292 dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); 295 dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex);
293 if (!dep) 296 if (!dep)
294 return -EINVAL; 297 return -EINVAL;
295 298
296 if (dep->flags & DWC3_EP_STALL) 299 if (dep->flags & DWC3_EP_STALL)
297 usb_status = 1 << USB_ENDPOINT_HALT; 300 usb_status = 1 << USB_ENDPOINT_HALT;
@@ -302,10 +305,14 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl
302 305
303 response_pkt = (__le16 *) dwc->setup_buf; 306 response_pkt = (__le16 *) dwc->setup_buf;
304 *response_pkt = cpu_to_le16(usb_status); 307 *response_pkt = cpu_to_le16(usb_status);
305 dwc->ep0_usb_req.length = sizeof(*response_pkt);
306 dwc->ep0_status_pending = 1;
307 308
308 return 0; 309 dep = dwc->eps[0];
310 dwc->ep0_usb_req.dep = dep;
311 dwc->ep0_usb_req.request.length = sizeof(*response_pkt);
312 dwc->ep0_usb_req.request.dma = dwc->setup_buf_addr;
313 dwc->ep0_usb_req.request.complete = dwc3_ep0_status_cmpl;
314
315 return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req);
309} 316}
310 317
311static int dwc3_ep0_handle_feature(struct dwc3 *dwc, 318static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
@@ -396,8 +403,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
396 case USB_RECIP_ENDPOINT: 403 case USB_RECIP_ENDPOINT:
397 switch (wValue) { 404 switch (wValue) {
398 case USB_ENDPOINT_HALT: 405 case USB_ENDPOINT_HALT:
399 406 dep = dwc3_wIndex_to_dep(dwc, wIndex);
400 dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex);
401 if (!dep) 407 if (!dep)
402 return -EINVAL; 408 return -EINVAL;
403 ret = __dwc3_gadget_ep_set_halt(dep, set); 409 ret = __dwc3_gadget_ep_set_halt(dep, set);
@@ -422,8 +428,15 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
422 u32 reg; 428 u32 reg;
423 429
424 addr = le16_to_cpu(ctrl->wValue); 430 addr = le16_to_cpu(ctrl->wValue);
425 if (addr > 127) 431 if (addr > 127) {
432 dev_dbg(dwc->dev, "invalid device address %d\n", addr);
426 return -EINVAL; 433 return -EINVAL;
434 }
435
436 if (dwc->dev_state == DWC3_CONFIGURED_STATE) {
437 dev_dbg(dwc->dev, "trying to set address when configured\n");
438 return -EINVAL;
439 }
427 440
428 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 441 reg = dwc3_readl(dwc->regs, DWC3_DCFG);
429 reg &= ~(DWC3_DCFG_DEVADDR_MASK); 442 reg &= ~(DWC3_DCFG_DEVADDR_MASK);
@@ -473,8 +486,10 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
473 if (!cfg) 486 if (!cfg)
474 dwc->dev_state = DWC3_ADDRESS_STATE; 487 dwc->dev_state = DWC3_ADDRESS_STATE;
475 break; 488 break;
489 default:
490 ret = -EINVAL;
476 } 491 }
477 return 0; 492 return ret;
478} 493}
479 494
480static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 495static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
@@ -537,6 +552,9 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc,
537 else 552 else
538 ret = dwc3_ep0_delegate_req(dwc, ctrl); 553 ret = dwc3_ep0_delegate_req(dwc, ctrl);
539 554
555 if (ret == USB_GADGET_DELAYED_STATUS)
556 dwc->delayed_status = true;
557
540 if (ret >= 0) 558 if (ret >= 0)
541 return; 559 return;
542 560
@@ -550,27 +568,21 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
550 struct dwc3_request *r = NULL; 568 struct dwc3_request *r = NULL;
551 struct usb_request *ur; 569 struct usb_request *ur;
552 struct dwc3_trb trb; 570 struct dwc3_trb trb;
553 struct dwc3_ep *dep; 571 struct dwc3_ep *ep0;
554 u32 transferred; 572 u32 transferred;
555 u8 epnum; 573 u8 epnum;
556 574
557 epnum = event->endpoint_number; 575 epnum = event->endpoint_number;
558 dep = dwc->eps[epnum]; 576 ep0 = dwc->eps[0];
559 577
560 dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; 578 dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS;
561 579
562 if (!dwc->ep0_status_pending) { 580 r = next_request(&ep0->request_list);
563 r = next_request(&dwc->eps[0]->request_list); 581 ur = &r->request;
564 ur = &r->request;
565 } else {
566 ur = &dwc->ep0_usb_req;
567 dwc->ep0_status_pending = 0;
568 }
569 582
570 dwc3_trb_to_nat(dwc->ep0_trb, &trb); 583 dwc3_trb_to_nat(dwc->ep0_trb, &trb);
571 584
572 if (dwc->ep0_bounced) { 585 if (dwc->ep0_bounced) {
573 struct dwc3_ep *ep0 = dwc->eps[0];
574 586
575 transferred = min_t(u32, ur->length, 587 transferred = min_t(u32, ur->length,
576 ep0->endpoint.maxpacket - trb.length); 588 ep0->endpoint.maxpacket - trb.length);
@@ -591,7 +603,7 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
591 * seems to be case when req.length > maxpacket. Could it be? 603 * seems to be case when req.length > maxpacket. Could it be?
592 */ 604 */
593 if (r) 605 if (r)
594 dwc3_gadget_giveback(dep, r, 0); 606 dwc3_gadget_giveback(ep0, r, 0);
595 } 607 }
596} 608}
597 609
@@ -619,6 +631,7 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
619 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; 631 struct dwc3_ep *dep = dwc->eps[event->endpoint_number];
620 632
621 dep->flags &= ~DWC3_EP_BUSY; 633 dep->flags &= ~DWC3_EP_BUSY;
634 dwc->setup_packet_pending = false;
622 635
623 switch (dwc->ep0state) { 636 switch (dwc->ep0state) {
624 case EP0_SETUP_PHASE: 637 case EP0_SETUP_PHASE:
@@ -643,7 +656,6 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
643static void dwc3_ep0_do_control_setup(struct dwc3 *dwc, 656static void dwc3_ep0_do_control_setup(struct dwc3 *dwc,
644 const struct dwc3_event_depevt *event) 657 const struct dwc3_event_depevt *event)
645{ 658{
646 dwc->ep0state = EP0_SETUP_PHASE;
647 dwc3_ep0_out_start(dwc); 659 dwc3_ep0_out_start(dwc);
648} 660}
649 661
@@ -655,12 +667,6 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc,
655 int ret; 667 int ret;
656 668
657 dep = dwc->eps[0]; 669 dep = dwc->eps[0];
658 dwc->ep0state = EP0_DATA_PHASE;
659
660 if (dwc->ep0_status_pending) {
661 dwc3_ep0_send_status_response(dwc);
662 return;
663 }
664 670
665 if (list_empty(&dep->request_list)) { 671 if (list_empty(&dep->request_list)) {
666 dev_vdbg(dwc->dev, "pending request for EP0 Data phase\n"); 672 dev_vdbg(dwc->dev, "pending request for EP0 Data phase\n");
@@ -674,7 +680,6 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc,
674 req = next_request(&dep->request_list); 680 req = next_request(&dep->request_list);
675 req->direction = !!event->endpoint_number; 681 req->direction = !!event->endpoint_number;
676 682
677 dwc->ep0state = EP0_DATA_PHASE;
678 if (req->request.length == 0) { 683 if (req->request.length == 0) {
679 ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, 684 ret = dwc3_ep0_start_trans(dwc, event->endpoint_number,
680 dwc->ctrl_req_addr, 0, 685 dwc->ctrl_req_addr, 0,
@@ -706,35 +711,79 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc,
706 WARN_ON(ret < 0); 711 WARN_ON(ret < 0);
707} 712}
708 713
709static void dwc3_ep0_do_control_status(struct dwc3 *dwc, 714static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
710 const struct dwc3_event_depevt *event)
711{ 715{
716 struct dwc3 *dwc = dep->dwc;
712 u32 type; 717 u32 type;
713 int ret;
714
715 dwc->ep0state = EP0_STATUS_PHASE;
716 718
717 type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3 719 type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3
718 : DWC3_TRBCTL_CONTROL_STATUS2; 720 : DWC3_TRBCTL_CONTROL_STATUS2;
719 721
720 ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, 722 return dwc3_ep0_start_trans(dwc, dep->number,
721 dwc->ctrl_req_addr, 0, type); 723 dwc->ctrl_req_addr, 0, type);
724}
722 725
723 WARN_ON(ret < 0); 726static void dwc3_ep0_do_control_status(struct dwc3 *dwc, u32 epnum)
727{
728 struct dwc3_ep *dep = dwc->eps[epnum];
729
730 WARN_ON(dwc3_ep0_start_control_status(dep));
724} 731}
725 732
726static void dwc3_ep0_xfernotready(struct dwc3 *dwc, 733static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
727 const struct dwc3_event_depevt *event) 734 const struct dwc3_event_depevt *event)
728{ 735{
736 dwc->setup_packet_pending = true;
737
738 /*
739 * This part is very tricky: If we has just handled
740 * XferNotReady(Setup) and we're now expecting a
741 * XferComplete but, instead, we receive another
742 * XferNotReady(Setup), we should STALL and restart
743 * the state machine.
744 *
745 * In all other cases, we just continue waiting
746 * for the XferComplete event.
747 *
748 * We are a little bit unsafe here because we're
749 * not trying to ensure that last event was, indeed,
750 * XferNotReady(Setup).
751 *
752 * Still, we don't expect any condition where that
753 * should happen and, even if it does, it would be
754 * another error condition.
755 */
756 if (dwc->ep0_next_event == DWC3_EP0_COMPLETE) {
757 switch (event->status) {
758 case DEPEVT_STATUS_CONTROL_SETUP:
759 dev_vdbg(dwc->dev, "Unexpected XferNotReady(Setup)\n");
760 dwc3_ep0_stall_and_restart(dwc);
761 break;
762 case DEPEVT_STATUS_CONTROL_DATA:
763 /* FALLTHROUGH */
764 case DEPEVT_STATUS_CONTROL_STATUS:
765 /* FALLTHROUGH */
766 default:
767 dev_vdbg(dwc->dev, "waiting for XferComplete\n");
768 }
769
770 return;
771 }
772
729 switch (event->status) { 773 switch (event->status) {
730 case DEPEVT_STATUS_CONTROL_SETUP: 774 case DEPEVT_STATUS_CONTROL_SETUP:
731 dev_vdbg(dwc->dev, "Control Setup\n"); 775 dev_vdbg(dwc->dev, "Control Setup\n");
776
777 dwc->ep0state = EP0_SETUP_PHASE;
778
732 dwc3_ep0_do_control_setup(dwc, event); 779 dwc3_ep0_do_control_setup(dwc, event);
733 break; 780 break;
734 781
735 case DEPEVT_STATUS_CONTROL_DATA: 782 case DEPEVT_STATUS_CONTROL_DATA:
736 dev_vdbg(dwc->dev, "Control Data\n"); 783 dev_vdbg(dwc->dev, "Control Data\n");
737 784
785 dwc->ep0state = EP0_DATA_PHASE;
786
738 if (dwc->ep0_next_event != DWC3_EP0_NRDY_DATA) { 787 if (dwc->ep0_next_event != DWC3_EP0_NRDY_DATA) {
739 dev_vdbg(dwc->dev, "Expected %d got %d\n", 788 dev_vdbg(dwc->dev, "Expected %d got %d\n",
740 dwc->ep0_next_event, 789 dwc->ep0_next_event,
@@ -764,6 +813,8 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
764 case DEPEVT_STATUS_CONTROL_STATUS: 813 case DEPEVT_STATUS_CONTROL_STATUS:
765 dev_vdbg(dwc->dev, "Control Status\n"); 814 dev_vdbg(dwc->dev, "Control Status\n");
766 815
816 dwc->ep0state = EP0_STATUS_PHASE;
817
767 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) { 818 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) {
768 dev_vdbg(dwc->dev, "Expected %d got %d\n", 819 dev_vdbg(dwc->dev, "Expected %d got %d\n",
769 dwc->ep0_next_event, 820 dwc->ep0_next_event,
@@ -772,12 +823,19 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
772 dwc3_ep0_stall_and_restart(dwc); 823 dwc3_ep0_stall_and_restart(dwc);
773 return; 824 return;
774 } 825 }
775 dwc3_ep0_do_control_status(dwc, event); 826
827 if (dwc->delayed_status) {
828 WARN_ON_ONCE(event->endpoint_number != 1);
829 dev_vdbg(dwc->dev, "Mass Storage delayed status\n");
830 return;
831 }
832
833 dwc3_ep0_do_control_status(dwc, event->endpoint_number);
776 } 834 }
777} 835}
778 836
779void dwc3_ep0_interrupt(struct dwc3 *dwc, 837void dwc3_ep0_interrupt(struct dwc3 *dwc,
780 const const struct dwc3_event_depevt *event) 838 const struct dwc3_event_depevt *event)
781{ 839{
782 u8 epnum = event->endpoint_number; 840 u8 epnum = event->endpoint_number;
783 841
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 25dbd8614e72..026c53cf1645 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -251,7 +251,8 @@ static int dwc3_gadget_start_config(struct dwc3 *dwc, struct dwc3_ep *dep)
251} 251}
252 252
253static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep, 253static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep,
254 const struct usb_endpoint_descriptor *desc) 254 const struct usb_endpoint_descriptor *desc,
255 const struct usb_ss_ep_comp_descriptor *comp_desc)
255{ 256{
256 struct dwc3_gadget_ep_cmd_params params; 257 struct dwc3_gadget_ep_cmd_params params;
257 258
@@ -264,7 +265,8 @@ static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep,
264 params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN 265 params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN
265 | DWC3_DEPCFG_XFER_NOT_READY_EN; 266 | DWC3_DEPCFG_XFER_NOT_READY_EN;
266 267
267 if (usb_endpoint_xfer_bulk(desc) && dep->endpoint.max_streams) { 268 if (comp_desc && USB_SS_MAX_STREAMS(comp_desc->bmAttributes)
269 && usb_endpoint_xfer_bulk(desc)) {
268 params.param1 |= DWC3_DEPCFG_STREAM_CAPABLE 270 params.param1 |= DWC3_DEPCFG_STREAM_CAPABLE
269 | DWC3_DEPCFG_STREAM_EVENT_EN; 271 | DWC3_DEPCFG_STREAM_EVENT_EN;
270 dep->stream_capable = true; 272 dep->stream_capable = true;
@@ -317,7 +319,8 @@ static int dwc3_gadget_set_xfer_resource(struct dwc3 *dwc, struct dwc3_ep *dep)
317 * Caller should take care of locking 319 * Caller should take care of locking
318 */ 320 */
319static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, 321static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
320 const struct usb_endpoint_descriptor *desc) 322 const struct usb_endpoint_descriptor *desc,
323 const struct usb_ss_ep_comp_descriptor *comp_desc)
321{ 324{
322 struct dwc3 *dwc = dep->dwc; 325 struct dwc3 *dwc = dep->dwc;
323 u32 reg; 326 u32 reg;
@@ -329,7 +332,7 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
329 return ret; 332 return ret;
330 } 333 }
331 334
332 ret = dwc3_gadget_set_ep_config(dwc, dep, desc); 335 ret = dwc3_gadget_set_ep_config(dwc, dep, desc, comp_desc);
333 if (ret) 336 if (ret)
334 return ret; 337 return ret;
335 338
@@ -343,6 +346,7 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
343 return ret; 346 return ret;
344 347
345 dep->desc = desc; 348 dep->desc = desc;
349 dep->comp_desc = comp_desc;
346 dep->type = usb_endpoint_type(desc); 350 dep->type = usb_endpoint_type(desc);
347 dep->flags |= DWC3_EP_ENABLED; 351 dep->flags |= DWC3_EP_ENABLED;
348 352
@@ -405,6 +409,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep)
405 409
406 dep->stream_capable = false; 410 dep->stream_capable = false;
407 dep->desc = NULL; 411 dep->desc = NULL;
412 dep->comp_desc = NULL;
408 dep->type = 0; 413 dep->type = 0;
409 dep->flags = 0; 414 dep->flags = 0;
410 415
@@ -473,7 +478,7 @@ static int dwc3_gadget_ep_enable(struct usb_ep *ep,
473 dev_vdbg(dwc->dev, "Enabling %s\n", dep->name); 478 dev_vdbg(dwc->dev, "Enabling %s\n", dep->name);
474 479
475 spin_lock_irqsave(&dwc->lock, flags); 480 spin_lock_irqsave(&dwc->lock, flags);
476 ret = __dwc3_gadget_ep_enable(dep, desc); 481 ret = __dwc3_gadget_ep_enable(dep, desc, ep->comp_desc);
477 spin_unlock_irqrestore(&dwc->lock, flags); 482 spin_unlock_irqrestore(&dwc->lock, flags);
478 483
479 return ret; 484 return ret;
@@ -745,8 +750,9 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param,
745 dep->flags |= DWC3_EP_BUSY; 750 dep->flags |= DWC3_EP_BUSY;
746 dep->res_trans_idx = dwc3_gadget_ep_get_transfer_index(dwc, 751 dep->res_trans_idx = dwc3_gadget_ep_get_transfer_index(dwc,
747 dep->number); 752 dep->number);
748 if (!dep->res_trans_idx) 753
749 printk_once(KERN_ERR "%s() res_trans_idx is invalid\n", __func__); 754 WARN_ON_ONCE(!dep->res_trans_idx);
755
750 return 0; 756 return 0;
751} 757}
752 758
@@ -1155,35 +1161,9 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1155 dwc->gadget_driver = driver; 1161 dwc->gadget_driver = driver;
1156 dwc->gadget.dev.driver = &driver->driver; 1162 dwc->gadget.dev.driver = &driver->driver;
1157 1163
1158 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
1159
1160 reg &= ~DWC3_GCTL_SCALEDOWN(3);
1161 reg &= ~DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG);
1162 reg &= ~DWC3_GCTL_DISSCRAMBLE;
1163 reg |= DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_DEVICE);
1164
1165 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams0)) {
1166 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
1167 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
1168 break;
1169 default:
1170 dev_dbg(dwc->dev, "No power optimization available\n");
1171 }
1172
1173 /*
1174 * WORKAROUND: DWC3 revisions <1.90a have a bug
1175 * when The device fails to connect at SuperSpeed
1176 * and falls back to high-speed mode which causes
1177 * the device to enter in a Connect/Disconnect loop
1178 */
1179 if (dwc->revision < DWC3_REVISION_190A)
1180 reg |= DWC3_GCTL_U2RSTECN;
1181
1182 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
1183
1184 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 1164 reg = dwc3_readl(dwc->regs, DWC3_DCFG);
1185 reg &= ~(DWC3_DCFG_SPEED_MASK); 1165 reg &= ~(DWC3_DCFG_SPEED_MASK);
1186 reg |= DWC3_DCFG_SUPERSPEED; 1166 reg |= dwc->maximum_speed;
1187 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 1167 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
1188 1168
1189 dwc->start_config_issued = false; 1169 dwc->start_config_issued = false;
@@ -1192,14 +1172,14 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1192 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 1172 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
1193 1173
1194 dep = dwc->eps[0]; 1174 dep = dwc->eps[0];
1195 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc); 1175 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL);
1196 if (ret) { 1176 if (ret) {
1197 dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1177 dev_err(dwc->dev, "failed to enable %s\n", dep->name);
1198 goto err0; 1178 goto err0;
1199 } 1179 }
1200 1180
1201 dep = dwc->eps[1]; 1181 dep = dwc->eps[1];
1202 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc); 1182 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL);
1203 if (ret) { 1183 if (ret) {
1204 dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1184 dev_err(dwc->dev, "failed to enable %s\n", dep->name);
1205 goto err1; 1185 goto err1;
@@ -1290,11 +1270,10 @@ static int __devinit dwc3_gadget_init_endpoints(struct dwc3 *dwc)
1290 &dwc->gadget.ep_list); 1270 &dwc->gadget.ep_list);
1291 1271
1292 ret = dwc3_alloc_trb_pool(dep); 1272 ret = dwc3_alloc_trb_pool(dep);
1293 if (ret) { 1273 if (ret)
1294 dev_err(dwc->dev, "%s: failed to allocate TRB pool\n", dep->name);
1295 return ret; 1274 return ret;
1296 }
1297 } 1275 }
1276
1298 INIT_LIST_HEAD(&dep->request_list); 1277 INIT_LIST_HEAD(&dep->request_list);
1299 INIT_LIST_HEAD(&dep->req_queued); 1278 INIT_LIST_HEAD(&dep->req_queued);
1300 } 1279 }
@@ -1334,8 +1313,10 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
1334 1313
1335 do { 1314 do {
1336 req = next_request(&dep->req_queued); 1315 req = next_request(&dep->req_queued);
1337 if (!req) 1316 if (!req) {
1338 break; 1317 WARN_ON_ONCE(1);
1318 return 1;
1319 }
1339 1320
1340 dwc3_trb_to_nat(req->trb, &trb); 1321 dwc3_trb_to_nat(req->trb, &trb);
1341 1322
@@ -1400,6 +1381,31 @@ static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc,
1400 dep->flags &= ~DWC3_EP_BUSY; 1381 dep->flags &= ~DWC3_EP_BUSY;
1401 dep->res_trans_idx = 0; 1382 dep->res_trans_idx = 0;
1402 } 1383 }
1384
1385 /*
1386 * WORKAROUND: This is the 2nd half of U1/U2 -> U0 workaround.
1387 * See dwc3_gadget_linksts_change_interrupt() for 1st half.
1388 */
1389 if (dwc->revision < DWC3_REVISION_183A) {
1390 u32 reg;
1391 int i;
1392
1393 for (i = 0; i < DWC3_ENDPOINTS_NUM; i++) {
1394 struct dwc3_ep *dep = dwc->eps[i];
1395
1396 if (!(dep->flags & DWC3_EP_ENABLED))
1397 continue;
1398
1399 if (!list_empty(&dep->req_queued))
1400 return;
1401 }
1402
1403 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
1404 reg |= dwc->u1u2;
1405 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
1406
1407 dwc->u1u2 = 0;
1408 }
1403} 1409}
1404 1410
1405static void dwc3_gadget_start_isoc(struct dwc3 *dwc, 1411static void dwc3_gadget_start_isoc(struct dwc3 *dwc,
@@ -1639,6 +1645,7 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
1639 dwc->start_config_issued = false; 1645 dwc->start_config_issued = false;
1640 1646
1641 dwc->gadget.speed = USB_SPEED_UNKNOWN; 1647 dwc->gadget.speed = USB_SPEED_UNKNOWN;
1648 dwc->setup_packet_pending = false;
1642} 1649}
1643 1650
1644static void dwc3_gadget_usb3_phy_power(struct dwc3 *dwc, int on) 1651static void dwc3_gadget_usb3_phy_power(struct dwc3 *dwc, int on)
@@ -1675,6 +1682,37 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
1675 1682
1676 dev_vdbg(dwc->dev, "%s\n", __func__); 1683 dev_vdbg(dwc->dev, "%s\n", __func__);
1677 1684
1685 /*
1686 * WORKAROUND: DWC3 revisions <1.88a have an issue which
1687 * would cause a missing Disconnect Event if there's a
1688 * pending Setup Packet in the FIFO.
1689 *
1690 * There's no suggested workaround on the official Bug
1691 * report, which states that "unless the driver/application
1692 * is doing any special handling of a disconnect event,
1693 * there is no functional issue".
1694 *
1695 * Unfortunately, it turns out that we _do_ some special
1696 * handling of a disconnect event, namely complete all
1697 * pending transfers, notify gadget driver of the
1698 * disconnection, and so on.
1699 *
1700 * Our suggested workaround is to follow the Disconnect
1701 * Event steps here, instead, based on a setup_packet_pending
1702 * flag. Such flag gets set whenever we have a XferNotReady
1703 * event on EP0 and gets cleared on XferComplete for the
1704 * same endpoint.
1705 *
1706 * Refers to:
1707 *
1708 * STAR#9000466709: RTL: Device : Disconnect event not
1709 * generated if setup packet pending in FIFO
1710 */
1711 if (dwc->revision < DWC3_REVISION_188A) {
1712 if (dwc->setup_packet_pending)
1713 dwc3_gadget_disconnect_interrupt(dwc);
1714 }
1715
1678 /* Enable PHYs */ 1716 /* Enable PHYs */
1679 dwc3_gadget_usb2_phy_power(dwc, true); 1717 dwc3_gadget_usb2_phy_power(dwc, true);
1680 dwc3_gadget_usb3_phy_power(dwc, true); 1718 dwc3_gadget_usb3_phy_power(dwc, true);
@@ -1755,6 +1793,22 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
1755 1793
1756 switch (speed) { 1794 switch (speed) {
1757 case DWC3_DCFG_SUPERSPEED: 1795 case DWC3_DCFG_SUPERSPEED:
1796 /*
1797 * WORKAROUND: DWC3 revisions <1.90a have an issue which
1798 * would cause a missing USB3 Reset event.
1799 *
1800 * In such situations, we should force a USB3 Reset
1801 * event by calling our dwc3_gadget_reset_interrupt()
1802 * routine.
1803 *
1804 * Refers to:
1805 *
1806 * STAR#9000483510: RTL: SS : USB3 reset event may
1807 * not be generated always when the link enters poll
1808 */
1809 if (dwc->revision < DWC3_REVISION_190A)
1810 dwc3_gadget_reset_interrupt(dwc);
1811
1758 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 1812 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
1759 dwc->gadget.ep0->maxpacket = 512; 1813 dwc->gadget.ep0->maxpacket = 512;
1760 dwc->gadget.speed = USB_SPEED_SUPER; 1814 dwc->gadget.speed = USB_SPEED_SUPER;
@@ -1781,14 +1835,14 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
1781 dwc3_gadget_disable_phy(dwc, dwc->gadget.speed); 1835 dwc3_gadget_disable_phy(dwc, dwc->gadget.speed);
1782 1836
1783 dep = dwc->eps[0]; 1837 dep = dwc->eps[0];
1784 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc); 1838 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL);
1785 if (ret) { 1839 if (ret) {
1786 dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1840 dev_err(dwc->dev, "failed to enable %s\n", dep->name);
1787 return; 1841 return;
1788 } 1842 }
1789 1843
1790 dep = dwc->eps[1]; 1844 dep = dwc->eps[1];
1791 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc); 1845 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL);
1792 if (ret) { 1846 if (ret) {
1793 dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1847 dev_err(dwc->dev, "failed to enable %s\n", dep->name);
1794 return; 1848 return;
@@ -1818,8 +1872,55 @@ static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc)
1818static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, 1872static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
1819 unsigned int evtinfo) 1873 unsigned int evtinfo)
1820{ 1874{
1821 /* The fith bit says SuperSpeed yes or no. */ 1875 enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK;
1822 dwc->link_state = evtinfo & DWC3_LINK_STATE_MASK; 1876
1877 /*
1878 * WORKAROUND: DWC3 Revisions <1.83a have an issue which, depending
1879 * on the link partner, the USB session might do multiple entry/exit
1880 * of low power states before a transfer takes place.
1881 *
1882 * Due to this problem, we might experience lower throughput. The
1883 * suggested workaround is to disable DCTL[12:9] bits if we're
1884 * transitioning from U1/U2 to U0 and enable those bits again
1885 * after a transfer completes and there are no pending transfers
1886 * on any of the enabled endpoints.
1887 *
1888 * This is the first half of that workaround.
1889 *
1890 * Refers to:
1891 *
1892 * STAR#9000446952: RTL: Device SS : if U1/U2 ->U0 takes >128us
1893 * core send LGO_Ux entering U0
1894 */
1895 if (dwc->revision < DWC3_REVISION_183A) {
1896 if (next == DWC3_LINK_STATE_U0) {
1897 u32 u1u2;
1898 u32 reg;
1899
1900 switch (dwc->link_state) {
1901 case DWC3_LINK_STATE_U1:
1902 case DWC3_LINK_STATE_U2:
1903 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
1904 u1u2 = reg & (DWC3_DCTL_INITU2ENA
1905 | DWC3_DCTL_ACCEPTU2ENA
1906 | DWC3_DCTL_INITU1ENA
1907 | DWC3_DCTL_ACCEPTU1ENA);
1908
1909 if (!dwc->u1u2)
1910 dwc->u1u2 = reg & u1u2;
1911
1912 reg &= ~u1u2;
1913
1914 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
1915 break;
1916 default:
1917 /* do nothing */
1918 break;
1919 }
1920 }
1921 }
1922
1923 dwc->link_state = next;
1823 1924
1824 dev_vdbg(dwc->dev, "%s link %d\n", __func__, dwc->link_state); 1925 dev_vdbg(dwc->dev, "%s link %d\n", __func__, dwc->link_state);
1825} 1926}
@@ -1925,7 +2026,7 @@ static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
1925 2026
1926 spin_lock(&dwc->lock); 2027 spin_lock(&dwc->lock);
1927 2028
1928 for (i = 0; i < DWC3_EVENT_BUFFERS_NUM; i++) { 2029 for (i = 0; i < dwc->num_event_buffers; i++) {
1929 irqreturn_t status; 2030 irqreturn_t status;
1930 2031
1931 status = dwc3_process_event_buf(dwc, i); 2032 status = dwc3_process_event_buf(dwc, i);
@@ -2076,7 +2177,6 @@ err0:
2076void dwc3_gadget_exit(struct dwc3 *dwc) 2177void dwc3_gadget_exit(struct dwc3 *dwc)
2077{ 2178{
2078 int irq; 2179 int irq;
2079 int i;
2080 2180
2081 usb_del_gadget_udc(&dwc->gadget); 2181 usb_del_gadget_udc(&dwc->gadget);
2082 irq = platform_get_irq(to_platform_device(dwc->dev), 0); 2182 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
@@ -2084,9 +2184,6 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
2084 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); 2184 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
2085 free_irq(irq, dwc); 2185 free_irq(irq, dwc);
2086 2186
2087 for (i = 0; i < ARRAY_SIZE(dwc->eps); i++)
2088 __dwc3_gadget_ep_disable(dwc->eps[i]);
2089
2090 dwc3_gadget_free_endpoints(dwc); 2187 dwc3_gadget_free_endpoints(dwc);
2091 2188
2092 dma_free_coherent(dwc->dev, 512, dwc->ep0_bounce, 2189 dma_free_coherent(dwc->dev, 512, dwc->ep0_bounce,
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
index 71145a449d99..d97f467d41cc 100644
--- a/drivers/usb/dwc3/gadget.h
+++ b/drivers/usb/dwc3/gadget.h
@@ -79,19 +79,6 @@ struct dwc3_gadget_ep_cmd_params {
79 79
80/* -------------------------------------------------------------------------- */ 80/* -------------------------------------------------------------------------- */
81 81
82struct dwc3_request {
83 struct usb_request request;
84 struct list_head list;
85 struct dwc3_ep *dep;
86
87 u8 epnum;
88 struct dwc3_trb_hw *trb;
89 dma_addr_t trb_dma;
90
91 unsigned direction:1;
92 unsigned mapped:1;
93 unsigned queued:1;
94};
95#define to_dwc3_request(r) (container_of(r, struct dwc3_request, request)) 82#define to_dwc3_request(r) (container_of(r, struct dwc3_request, request))
96 83
97static inline struct dwc3_request *next_request(struct list_head *list) 84static inline struct dwc3_request *next_request(struct list_head *list)
@@ -110,23 +97,11 @@ static inline void dwc3_gadget_move_request_queued(struct dwc3_request *req)
110 list_move_tail(&req->list, &dep->req_queued); 97 list_move_tail(&req->list, &dep->req_queued);
111} 98}
112 99
113#if defined(CONFIG_USB_GADGET_DWC3) || defined(CONFIG_USB_GADGET_DWC3_MODULE)
114int dwc3_gadget_init(struct dwc3 *dwc);
115void dwc3_gadget_exit(struct dwc3 *dwc);
116#else
117static inline int dwc3_gadget_init(struct dwc3 *dwc) { return 0; }
118static inline void dwc3_gadget_exit(struct dwc3 *dwc) { }
119static inline int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
120 unsigned cmd, struct dwc3_gadget_ep_cmd_params *params)
121{
122 return 0;
123}
124#endif
125
126void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, 100void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
127 int status); 101 int status);
128 102
129void dwc3_ep0_interrupt(struct dwc3 *dwc, const struct dwc3_event_depevt *event); 103void dwc3_ep0_interrupt(struct dwc3 *dwc,
104 const struct dwc3_event_depevt *event);
130void dwc3_ep0_out_start(struct dwc3 *dwc); 105void dwc3_ep0_out_start(struct dwc3 *dwc);
131int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, 106int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
132 gfp_t gfp_flags); 107 gfp_t gfp_flags);
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
new file mode 100644
index 000000000000..7cfe211b6c37
--- /dev/null
+++ b/drivers/usb/dwc3/host.c
@@ -0,0 +1,102 @@
1/**
2 * host.c - DesignWare USB3 DRD Controller Host Glue
3 *
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The names of the above-listed copyright holders may not be used
18 * to endorse or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * ALTERNATIVELY, this software may be distributed under the terms of the
22 * GNU General Public License ("GPL") version 2, as published by the Free
23 * Software Foundation.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/platform_device.h>
39
40#include "core.h"
41
42static struct resource generic_resources[] = {
43 {
44 .flags = IORESOURCE_IRQ,
45 },
46 {
47 .flags = IORESOURCE_MEM,
48 },
49};
50
51int dwc3_host_init(struct dwc3 *dwc)
52{
53 struct platform_device *xhci;
54 int ret;
55
56 xhci = platform_device_alloc("xhci", -1);
57 if (!xhci) {
58 dev_err(dwc->dev, "couldn't allocate xHCI device\n");
59 ret = -ENOMEM;
60 goto err0;
61 }
62
63 dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
64
65 xhci->dev.parent = dwc->dev;
66 xhci->dev.dma_mask = dwc->dev->dma_mask;
67 xhci->dev.dma_parms = dwc->dev->dma_parms;
68
69 dwc->xhci = xhci;
70
71 /* setup resources */
72 generic_resources[0].start = dwc->irq;
73
74 generic_resources[1].start = dwc->res->start;
75 generic_resources[1].end = dwc->res->start + 0x7fff;
76
77 ret = platform_device_add_resources(xhci, generic_resources,
78 ARRAY_SIZE(generic_resources));
79 if (ret) {
80 dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
81 goto err1;
82 }
83
84 ret = platform_device_add(xhci);
85 if (ret) {
86 dev_err(dwc->dev, "failed to register xHCI device\n");
87 goto err1;
88 }
89
90 return 0;
91
92err1:
93 platform_device_put(xhci);
94
95err0:
96 return ret;
97}
98
99void dwc3_host_exit(struct dwc3 *dwc)
100{
101 platform_device_unregister(dwc->xhci);
102}
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index bc957db1ea4b..071d561f3e68 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -39,7 +39,7 @@
39#ifndef __DRIVERS_USB_DWC3_IO_H 39#ifndef __DRIVERS_USB_DWC3_IO_H
40#define __DRIVERS_USB_DWC3_IO_H 40#define __DRIVERS_USB_DWC3_IO_H
41 41
42#include <asm/io.h> 42#include <linux/io.h>
43 43
44static inline u32 dwc3_readl(void __iomem *base, u32 offset) 44static inline u32 dwc3_readl(void __iomem *base, u32 offset)
45{ 45{
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 3162a7da8724..71108c26c562 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -319,18 +319,6 @@ config USB_PXA_U2O
319 PXA9xx Processor series include a high speed USB2.0 device 319 PXA9xx Processor series include a high speed USB2.0 device
320 controller, which support high speed and full speed USB peripheral. 320 controller, which support high speed and full speed USB peripheral.
321 321
322config USB_GADGET_DWC3
323 tristate "DesignWare USB3.0 (DRD) Controller"
324 depends on USB_DWC3
325 select USB_GADGET_DUALSPEED
326 select USB_GADGET_SUPERSPEED
327 help
328 DesignWare USB3.0 controller is a SuperSpeed USB3.0 Controller
329 which can be configured for peripheral-only, host-only, hub-only
330 and Dual-Role operation. This Controller was first integrated into
331 the OMAP5 series of processors. More information about the OMAP5
332 version of this controller, refer to http://www.ti.com/omap5.
333
334# 322#
335# Controllers available in both integrated and discrete versions 323# Controllers available in both integrated and discrete versions
336# 324#
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 4730016d7cd4..45f422ac103f 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1959,7 +1959,7 @@ static int amd5536_start(struct usb_gadget_driver *driver,
1959 u32 tmp; 1959 u32 tmp;
1960 1960
1961 if (!driver || !bind || !driver->setup 1961 if (!driver || !bind || !driver->setup
1962 || driver->speed != USB_SPEED_HIGH) 1962 || driver->speed < USB_SPEED_HIGH)
1963 return -EINVAL; 1963 return -EINVAL;
1964 if (!dev) 1964 if (!dev)
1965 return -ENODEV; 1965 return -ENODEV;
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index 91fdf790ed20..cf33a8d0fd5d 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -131,8 +131,8 @@ static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
131 } 131 }
132 if (!gser->port.in->desc || !gser->port.out->desc) { 132 if (!gser->port.in->desc || !gser->port.out->desc) {
133 DBG(cdev, "activate generic ttyGS%d\n", gser->port_num); 133 DBG(cdev, "activate generic ttyGS%d\n", gser->port_num);
134 if (!config_ep_by_speed(cdev->gadget, f, gser->port.in) || 134 if (config_ep_by_speed(cdev->gadget, f, gser->port.in) ||
135 !config_ep_by_speed(cdev->gadget, f, gser->port.out)) { 135 config_ep_by_speed(cdev->gadget, f, gser->port.out)) {
136 gser->port.in->desc = NULL; 136 gser->port.in->desc = NULL;
137 gser->port.out->desc = NULL; 137 gser->port.out->desc = NULL;
138 return -EINVAL; 138 return -EINVAL;
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index 43a49ecc1f36..dcbc0a2e48dd 100644
--- a/drivers/usb/gadget/fsl_mxc_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -16,6 +16,7 @@
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/fsl_devices.h> 17#include <linux/fsl_devices.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/io.h>
19 20
20#include <mach/hardware.h> 21#include <mach/hardware.h>
21 22
@@ -88,7 +89,6 @@ eenahb:
88void fsl_udc_clk_finalize(struct platform_device *pdev) 89void fsl_udc_clk_finalize(struct platform_device *pdev)
89{ 90{
90 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 91 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
91#if defined(CONFIG_SOC_IMX35)
92 if (cpu_is_mx35()) { 92 if (cpu_is_mx35()) {
93 unsigned int v; 93 unsigned int v;
94 94
@@ -101,7 +101,6 @@ void fsl_udc_clk_finalize(struct platform_device *pdev)
101 USBPHYCTRL_OTGBASE_OFFSET)); 101 USBPHYCTRL_OTGBASE_OFFSET));
102 } 102 }
103 } 103 }
104#endif
105 104
106 /* ULPI transceivers don't need usbpll */ 105 /* ULPI transceivers don't need usbpll */
107 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) { 106 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 811ea76ae76e..f75c56a259a9 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2336,8 +2336,7 @@ static int fsl_qe_start(struct usb_gadget_driver *driver,
2336 if (!udc_controller) 2336 if (!udc_controller)
2337 return -ENODEV; 2337 return -ENODEV;
2338 2338
2339 if (!driver || (driver->speed != USB_SPEED_FULL 2339 if (!driver || driver->speed < USB_SPEED_FULL
2340 && driver->speed != USB_SPEED_HIGH)
2341 || !bind || !driver->disconnect || !driver->setup) 2340 || !bind || !driver->disconnect || !driver->setup)
2342 return -EINVAL; 2341 return -EINVAL;
2343 2342
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index b3b3d83b7c33..dd28ef3def71 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -696,12 +696,31 @@ static void fsl_free_request(struct usb_ep *_ep, struct usb_request *_req)
696 kfree(req); 696 kfree(req);
697} 697}
698 698
699/*-------------------------------------------------------------------------*/ 699/* Actually add a dTD chain to an empty dQH and let go */
700static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
701{
702 struct ep_queue_head *qh = get_qh_by_ep(ep);
703
704 /* Write dQH next pointer and terminate bit to 0 */
705 qh->next_dtd_ptr = cpu_to_hc32(td->td_dma
706 & EP_QUEUE_HEAD_NEXT_POINTER_MASK);
707
708 /* Clear active and halt bit */
709 qh->size_ioc_int_sts &= cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
710 | EP_QUEUE_HEAD_STATUS_HALT));
711
712 /* Ensure that updates to the QH will occur before priming. */
713 wmb();
714
715 /* Prime endpoint by writing correct bit to ENDPTPRIME */
716 fsl_writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
717 : (1 << (ep_index(ep))), &dr_regs->endpointprime);
718}
719
720/* Add dTD chain to the dQH of an EP */
700static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req) 721static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
701{ 722{
702 int i = ep_index(ep) * 2 + ep_is_in(ep);
703 u32 temp, bitmask, tmp_stat; 723 u32 temp, bitmask, tmp_stat;
704 struct ep_queue_head *dQH = &ep->udc->ep_qh[i];
705 724
706 /* VDBG("QH addr Register 0x%8x", dr_regs->endpointlistaddr); 725 /* VDBG("QH addr Register 0x%8x", dr_regs->endpointlistaddr);
707 VDBG("ep_qh[%d] addr is 0x%8x", i, (u32)&(ep->udc->ep_qh[i])); */ 726 VDBG("ep_qh[%d] addr is 0x%8x", i, (u32)&(ep->udc->ep_qh[i])); */
@@ -719,7 +738,7 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
719 cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK); 738 cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK);
720 /* Read prime bit, if 1 goto done */ 739 /* Read prime bit, if 1 goto done */
721 if (fsl_readl(&dr_regs->endpointprime) & bitmask) 740 if (fsl_readl(&dr_regs->endpointprime) & bitmask)
722 goto out; 741 return;
723 742
724 do { 743 do {
725 /* Set ATDTW bit in USBCMD */ 744 /* Set ATDTW bit in USBCMD */
@@ -736,28 +755,10 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
736 fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd); 755 fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
737 756
738 if (tmp_stat) 757 if (tmp_stat)
739 goto out; 758 return;
740 } 759 }
741 760
742 /* Write dQH next pointer and terminate bit to 0 */ 761 fsl_prime_ep(ep, req->head);
743 temp = req->head->td_dma & EP_QUEUE_HEAD_NEXT_POINTER_MASK;
744 dQH->next_dtd_ptr = cpu_to_hc32(temp);
745
746 /* Clear active and halt bit */
747 temp = cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
748 | EP_QUEUE_HEAD_STATUS_HALT));
749 dQH->size_ioc_int_sts &= temp;
750
751 /* Ensure that updates to the QH will occur before priming. */
752 wmb();
753
754 /* Prime endpoint by writing 1 to ENDPTPRIME */
755 temp = ep_is_in(ep)
756 ? (1 << (ep_index(ep) + 16))
757 : (1 << (ep_index(ep)));
758 fsl_writel(temp, &dr_regs->endpointprime);
759out:
760 return;
761} 762}
762 763
763/* Fill in the dTD structure 764/* Fill in the dTD structure
@@ -877,7 +878,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
877 VDBG("%s, bad ep", __func__); 878 VDBG("%s, bad ep", __func__);
878 return -EINVAL; 879 return -EINVAL;
879 } 880 }
880 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 881 if (usb_endpoint_xfer_isoc(ep->desc)) {
881 if (req->req.length > ep->ep.maxpacket) 882 if (req->req.length > ep->ep.maxpacket)
882 return -EMSGSIZE; 883 return -EMSGSIZE;
883 } 884 }
@@ -973,25 +974,20 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
973 974
974 /* The request isn't the last request in this ep queue */ 975 /* The request isn't the last request in this ep queue */
975 if (req->queue.next != &ep->queue) { 976 if (req->queue.next != &ep->queue) {
976 struct ep_queue_head *qh;
977 struct fsl_req *next_req; 977 struct fsl_req *next_req;
978 978
979 qh = ep->qh;
980 next_req = list_entry(req->queue.next, struct fsl_req, 979 next_req = list_entry(req->queue.next, struct fsl_req,
981 queue); 980 queue);
982 981
983 /* Point the QH to the first TD of next request */ 982 /* prime with dTD of next request */
984 fsl_writel((u32) next_req->head, &qh->curr_dtd_ptr); 983 fsl_prime_ep(ep, next_req->head);
985 } 984 }
986 985 /* The request hasn't been processed, patch up the TD chain */
987 /* The request hasn't been processed, patch up the TD chain */
988 } else { 986 } else {
989 struct fsl_req *prev_req; 987 struct fsl_req *prev_req;
990 988
991 prev_req = list_entry(req->queue.prev, struct fsl_req, queue); 989 prev_req = list_entry(req->queue.prev, struct fsl_req, queue);
992 fsl_writel(fsl_readl(&req->tail->next_td_ptr), 990 prev_req->tail->next_td_ptr = req->tail->next_td_ptr;
993 &prev_req->tail->next_td_ptr);
994
995 } 991 }
996 992
997 done(ep, req, -ECONNRESET); 993 done(ep, req, -ECONNRESET);
@@ -1032,7 +1028,7 @@ static int fsl_ep_set_halt(struct usb_ep *_ep, int value)
1032 goto out; 1028 goto out;
1033 } 1029 }
1034 1030
1035 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 1031 if (usb_endpoint_xfer_isoc(ep->desc)) {
1036 status = -EOPNOTSUPP; 1032 status = -EOPNOTSUPP;
1037 goto out; 1033 goto out;
1038 } 1034 }
@@ -1068,7 +1064,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
1068 struct fsl_udc *udc; 1064 struct fsl_udc *udc;
1069 int size = 0; 1065 int size = 0;
1070 u32 bitmask; 1066 u32 bitmask;
1071 struct ep_queue_head *d_qh; 1067 struct ep_queue_head *qh;
1072 1068
1073 ep = container_of(_ep, struct fsl_ep, ep); 1069 ep = container_of(_ep, struct fsl_ep, ep);
1074 if (!_ep || (!ep->desc && ep_index(ep) != 0)) 1070 if (!_ep || (!ep->desc && ep_index(ep) != 0))
@@ -1079,13 +1075,13 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
1079 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) 1075 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
1080 return -ESHUTDOWN; 1076 return -ESHUTDOWN;
1081 1077
1082 d_qh = &ep->udc->ep_qh[ep_index(ep) * 2 + ep_is_in(ep)]; 1078 qh = get_qh_by_ep(ep);
1083 1079
1084 bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) : 1080 bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) :
1085 (1 << (ep_index(ep))); 1081 (1 << (ep_index(ep)));
1086 1082
1087 if (fsl_readl(&dr_regs->endptstatus) & bitmask) 1083 if (fsl_readl(&dr_regs->endptstatus) & bitmask)
1088 size = (d_qh->size_ioc_int_sts & DTD_PACKET_SIZE) 1084 size = (qh->size_ioc_int_sts & DTD_PACKET_SIZE)
1089 >> DTD_LENGTH_BIT_POS; 1085 >> DTD_LENGTH_BIT_POS;
1090 1086
1091 pr_debug("%s %u\n", __func__, size); 1087 pr_debug("%s %u\n", __func__, size);
@@ -1938,8 +1934,7 @@ static int fsl_start(struct usb_gadget_driver *driver,
1938 if (!udc_controller) 1934 if (!udc_controller)
1939 return -ENODEV; 1935 return -ENODEV;
1940 1936
1941 if (!driver || (driver->speed != USB_SPEED_FULL 1937 if (!driver || driver->speed < USB_SPEED_FULL
1942 && driver->speed != USB_SPEED_HIGH)
1943 || !bind || !driver->disconnect || !driver->setup) 1938 || !bind || !driver->disconnect || !driver->setup)
1944 return -EINVAL; 1939 return -EINVAL;
1945 1940
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 1d51be83fda8..f781f5dec417 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -569,6 +569,16 @@ static void dump_msg(const char *label, const u8 * buf, unsigned int length)
569 * 2 + ((windex & USB_DIR_IN) ? 1 : 0)) 569 * 2 + ((windex & USB_DIR_IN) ? 1 : 0))
570#define get_pipe_by_ep(EP) (ep_index(EP) * 2 + ep_is_in(EP)) 570#define get_pipe_by_ep(EP) (ep_index(EP) * 2 + ep_is_in(EP))
571 571
572static inline struct ep_queue_head *get_qh_by_ep(struct fsl_ep *ep)
573{
574 /* we only have one ep0 structure but two queue heads */
575 if (ep_index(ep) != 0)
576 return ep->qh;
577 else
578 return &ep->udc->ep_qh[(ep->udc->ep0_dir ==
579 USB_DIR_IN) ? 1 : 0];
580}
581
572struct platform_device; 582struct platform_device;
573#ifdef CONFIG_ARCH_MXC 583#ifdef CONFIG_ARCH_MXC
574int fsl_udc_clk_init(struct platform_device *pdev); 584int fsl_udc_clk_init(struct platform_device *pdev);
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 91d0af2a24a8..9aa1cbbee45b 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1472,7 +1472,7 @@ static int m66592_start(struct usb_gadget_driver *driver,
1472 int retval; 1472 int retval;
1473 1473
1474 if (!driver 1474 if (!driver
1475 || driver->speed != USB_SPEED_HIGH 1475 || driver->speed < USB_SPEED_HIGH
1476 || !bind 1476 || !bind
1477 || !driver->setup) 1477 || !driver->setup)
1478 return -EINVAL; 1478 return -EINVAL;
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 7f1bc9a73cda..da2b9d0be3ca 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -1881,7 +1881,7 @@ static int net2280_start(struct usb_gadget *_gadget,
1881 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) 1881 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
1882 * "must not be used in normal operation" 1882 * "must not be used in normal operation"
1883 */ 1883 */
1884 if (!driver || driver->speed != USB_SPEED_HIGH 1884 if (!driver || driver->speed < USB_SPEED_HIGH
1885 || !driver->setup) 1885 || !driver->setup)
1886 return -EINVAL; 1886 return -EINVAL;
1887 1887
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index 24f84b210ce1..fc719a3f8557 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -1746,7 +1746,7 @@ static int r8a66597_start(struct usb_gadget *gadget,
1746 struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget); 1746 struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget);
1747 1747
1748 if (!driver 1748 if (!driver
1749 || driver->speed != USB_SPEED_HIGH 1749 || driver->speed < USB_SPEED_HIGH
1750 || !driver->setup) 1750 || !driver->setup)
1751 return -EINVAL; 1751 return -EINVAL;
1752 if (!r8a66597) 1752 if (!r8a66597)
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 745a3081fb37..c59156c0061d 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -2586,10 +2586,8 @@ static int s3c_hsotg_start(struct usb_gadget_driver *driver,
2586 return -EINVAL; 2586 return -EINVAL;
2587 } 2587 }
2588 2588
2589 if (driver->speed != USB_SPEED_HIGH && 2589 if (driver->speed < USB_SPEED_FULL)
2590 driver->speed != USB_SPEED_FULL) {
2591 dev_err(hsotg->dev, "%s: bad speed\n", __func__); 2590 dev_err(hsotg->dev, "%s: bad speed\n", __func__);
2592 }
2593 2591
2594 if (!bind || !driver->setup) { 2592 if (!bind || !driver->setup) {
2595 dev_err(hsotg->dev, "%s: missing entry points\n", __func__); 2593 dev_err(hsotg->dev, "%s: missing entry points\n", __func__);
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index baf506a66ded..787ac5baae92 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -1142,8 +1142,7 @@ static int s3c_hsudc_start(struct usb_gadget_driver *driver,
1142 int ret; 1142 int ret;
1143 1143
1144 if (!driver 1144 if (!driver
1145 || (driver->speed != USB_SPEED_FULL && 1145 || driver->speed < USB_SPEED_FULL
1146 driver->speed != USB_SPEED_HIGH)
1147 || !bind 1146 || !bind
1148 || !driver->unbind || !driver->disconnect || !driver->setup) 1147 || !driver->unbind || !driver->disconnect || !driver->setup)
1149 return -EINVAL; 1148 return -EINVAL;
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 56a32033adb3..a60679cbbf85 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1475,6 +1475,7 @@ iso_stream_schedule (
1475 * jump until after the queue is primed. 1475 * jump until after the queue is primed.
1476 */ 1476 */
1477 else { 1477 else {
1478 int done = 0;
1478 start = SCHEDULE_SLOP + (now & ~0x07); 1479 start = SCHEDULE_SLOP + (now & ~0x07);
1479 1480
1480 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ 1481 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */
@@ -1492,18 +1493,18 @@ iso_stream_schedule (
1492 if (stream->highspeed) { 1493 if (stream->highspeed) {
1493 if (itd_slot_ok(ehci, mod, start, 1494 if (itd_slot_ok(ehci, mod, start,
1494 stream->usecs, period)) 1495 stream->usecs, period))
1495 break; 1496 done = 1;
1496 } else { 1497 } else {
1497 if ((start % 8) >= 6) 1498 if ((start % 8) >= 6)
1498 continue; 1499 continue;
1499 if (sitd_slot_ok(ehci, mod, stream, 1500 if (sitd_slot_ok(ehci, mod, stream,
1500 start, sched, period)) 1501 start, sched, period))
1501 break; 1502 done = 1;
1502 } 1503 }
1503 } while (start > next); 1504 } while (start > next && !done);
1504 1505
1505 /* no room in the schedule */ 1506 /* no room in the schedule */
1506 if (start == next) { 1507 if (!done) {
1507 ehci_dbg(ehci, "iso resched full %p (now %d max %d)\n", 1508 ehci_dbg(ehci, "iso resched full %p (now %d max %d)\n",
1508 urb, now, now + mod); 1509 urb, now, now + mod);
1509 status = -ENOSPC; 1510 status = -ENOSPC;
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index a91712c8bff5..76083ae92138 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -124,7 +124,7 @@ void qset_clear(struct whc *whc, struct whc_qset *qset)
124{ 124{
125 qset->td_start = qset->td_end = qset->ntds = 0; 125 qset->td_start = qset->td_end = qset->ntds = 0;
126 126
127 qset->qh.link = cpu_to_le32(QH_LINK_NTDS(8) | QH_LINK_T); 127 qset->qh.link = cpu_to_le64(QH_LINK_NTDS(8) | QH_LINK_T);
128 qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK; 128 qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK;
129 qset->qh.err_count = 0; 129 qset->qh.err_count = 0;
130 qset->qh.scratch[0] = 0; 130 qset->qh.scratch[0] = 0;
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index aa94c0195791..a1afb7c39f7e 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -711,7 +711,10 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
711 ring = xhci->cmd_ring; 711 ring = xhci->cmd_ring;
712 seg = ring->deq_seg; 712 seg = ring->deq_seg;
713 do { 713 do {
714 memset(seg->trbs, 0, SEGMENT_SIZE); 714 memset(seg->trbs, 0,
715 sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1));
716 seg->trbs[TRBS_PER_SEGMENT - 1].link.control &=
717 cpu_to_le32(~TRB_CYCLE);
715 seg = seg->next; 718 seg = seg->next;
716 } while (seg != ring->deq_seg); 719 } while (seg != ring->deq_seg);
717 720
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 549585086798..227c1dfa6bee 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2300,18 +2300,12 @@ static int musb_suspend(struct device *dev)
2300 */ 2300 */
2301 } 2301 }
2302 2302
2303 musb_save_context(musb);
2304
2305 spin_unlock_irqrestore(&musb->lock, flags); 2303 spin_unlock_irqrestore(&musb->lock, flags);
2306 return 0; 2304 return 0;
2307} 2305}
2308 2306
2309static int musb_resume_noirq(struct device *dev) 2307static int musb_resume_noirq(struct device *dev)
2310{ 2308{
2311 struct musb *musb = dev_to_musb(dev);
2312
2313 musb_restore_context(musb);
2314
2315 /* for static cmos like DaVinci, register values were preserved 2309 /* for static cmos like DaVinci, register values were preserved
2316 * unless for some reason the whole soc powered down or the USB 2310 * unless for some reason the whole soc powered down or the USB
2317 * module got reset through the PSC (vs just being disabled). 2311 * module got reset through the PSC (vs just being disabled).
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index d51043acfe1a..922148ff8d29 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1903,7 +1903,7 @@ static int musb_gadget_start(struct usb_gadget *g,
1903 unsigned long flags; 1903 unsigned long flags;
1904 int retval = -EINVAL; 1904 int retval = -EINVAL;
1905 1905
1906 if (driver->speed != USB_SPEED_HIGH) 1906 if (driver->speed < USB_SPEED_HIGH)
1907 goto err0; 1907 goto err0;
1908 1908
1909 pm_runtime_get_sync(musb->controller); 1909 pm_runtime_get_sync(musb->controller);
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index d9717e0bc1ff..7f4e80338570 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -751,53 +751,32 @@ static int usbhsg_gadget_start(struct usb_gadget *gadget,
751 struct usb_gadget_driver *driver) 751 struct usb_gadget_driver *driver)
752{ 752{
753 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); 753 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget);
754 struct usbhs_priv *priv; 754 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
755 struct device *dev;
756 int ret;
757 755
758 if (!driver || 756 if (!driver ||
759 !driver->setup || 757 !driver->setup ||
760 driver->speed != USB_SPEED_HIGH) 758 driver->speed < USB_SPEED_FULL)
761 return -EINVAL; 759 return -EINVAL;
762 760
763 dev = usbhsg_gpriv_to_dev(gpriv);
764 priv = usbhsg_gpriv_to_priv(gpriv);
765
766 /* first hook up the driver ... */ 761 /* first hook up the driver ... */
767 gpriv->driver = driver; 762 gpriv->driver = driver;
768 gpriv->gadget.dev.driver = &driver->driver; 763 gpriv->gadget.dev.driver = &driver->driver;
769 764
770 ret = device_add(&gpriv->gadget.dev);
771 if (ret) {
772 dev_err(dev, "device_add error %d\n", ret);
773 goto add_fail;
774 }
775
776 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); 765 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD);
777
778add_fail:
779 gpriv->driver = NULL;
780 gpriv->gadget.dev.driver = NULL;
781
782 return ret;
783} 766}
784 767
785static int usbhsg_gadget_stop(struct usb_gadget *gadget, 768static int usbhsg_gadget_stop(struct usb_gadget *gadget,
786 struct usb_gadget_driver *driver) 769 struct usb_gadget_driver *driver)
787{ 770{
788 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); 771 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget);
789 struct usbhs_priv *priv; 772 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
790 struct device *dev;
791 773
792 if (!driver || 774 if (!driver ||
793 !driver->unbind) 775 !driver->unbind)
794 return -EINVAL; 776 return -EINVAL;
795 777
796 dev = usbhsg_gpriv_to_dev(gpriv);
797 priv = usbhsg_gpriv_to_priv(gpriv);
798
799 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD); 778 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD);
800 device_del(&gpriv->gadget.dev); 779 gpriv->gadget.dev.driver = NULL;
801 gpriv->driver = NULL; 780 gpriv->driver = NULL;
802 781
803 return 0; 782 return 0;
@@ -827,6 +806,13 @@ static int usbhsg_start(struct usbhs_priv *priv)
827 806
828static int usbhsg_stop(struct usbhs_priv *priv) 807static int usbhsg_stop(struct usbhs_priv *priv)
829{ 808{
809 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
810
811 /* cable disconnect */
812 if (gpriv->driver &&
813 gpriv->driver->disconnect)
814 gpriv->driver->disconnect(&gpriv->gadget);
815
830 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED); 816 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED);
831} 817}
832 818
@@ -876,12 +862,14 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
876 /* 862 /*
877 * init gadget 863 * init gadget
878 */ 864 */
879 device_initialize(&gpriv->gadget.dev);
880 dev_set_name(&gpriv->gadget.dev, "gadget"); 865 dev_set_name(&gpriv->gadget.dev, "gadget");
881 gpriv->gadget.dev.parent = dev; 866 gpriv->gadget.dev.parent = dev;
882 gpriv->gadget.name = "renesas_usbhs_udc"; 867 gpriv->gadget.name = "renesas_usbhs_udc";
883 gpriv->gadget.ops = &usbhsg_gadget_ops; 868 gpriv->gadget.ops = &usbhsg_gadget_ops;
884 gpriv->gadget.is_dualspeed = 1; 869 gpriv->gadget.is_dualspeed = 1;
870 ret = device_register(&gpriv->gadget.dev);
871 if (ret < 0)
872 goto err_add_udc;
885 873
886 INIT_LIST_HEAD(&gpriv->gadget.ep_list); 874 INIT_LIST_HEAD(&gpriv->gadget.ep_list);
887 875
@@ -912,12 +900,15 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
912 900
913 ret = usb_add_gadget_udc(dev, &gpriv->gadget); 901 ret = usb_add_gadget_udc(dev, &gpriv->gadget);
914 if (ret) 902 if (ret)
915 goto err_add_udc; 903 goto err_register;
916 904
917 905
918 dev_info(dev, "gadget probed\n"); 906 dev_info(dev, "gadget probed\n");
919 907
920 return 0; 908 return 0;
909
910err_register:
911 device_unregister(&gpriv->gadget.dev);
921err_add_udc: 912err_add_udc:
922 kfree(gpriv->uep); 913 kfree(gpriv->uep);
923 914
@@ -933,6 +924,8 @@ void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
933 924
934 usb_del_gadget_udc(&gpriv->gadget); 925 usb_del_gadget_udc(&gpriv->gadget);
935 926
927 device_unregister(&gpriv->gadget.dev);
928
936 usbhsg_controller_unregister(gpriv); 929 usbhsg_controller_unregister(gpriv);
937 930
938 kfree(gpriv->uep); 931 kfree(gpriv->uep);
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 13e4ecc6e43d..c290df97108e 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -736,6 +736,7 @@ static struct usb_device_id id_table_combined [] = {
736 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) }, 736 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
737 { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) }, 737 { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) },
738 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) }, 738 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) },
739 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_ISPCABLEIII_PID) },
739 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), 740 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
740 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 741 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
741 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_H_PID), 742 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_H_PID),
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 571fa96b49c7..055b64ef0bba 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -112,6 +112,7 @@
112 112
113/* Propox devices */ 113/* Propox devices */
114#define FTDI_PROPOX_JTAGCABLEII_PID 0xD738 114#define FTDI_PROPOX_JTAGCABLEII_PID 0xD738
115#define FTDI_PROPOX_ISPCABLEIII_PID 0xD739
115 116
116/* Lenz LI-USB Computer Interface. */ 117/* Lenz LI-USB Computer Interface. */
117#define FTDI_LENZ_LIUSB_PID 0xD780 118#define FTDI_LENZ_LIUSB_PID 0xD780
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index d865878c9f97..e3426602dc82 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -661,6 +661,9 @@ static const struct usb_device_id option_ids[] = {
661 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x31) }, 661 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x31) },
662 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x32) }, 662 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x32) },
663 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x01) }, 663 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x01) },
664 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x02) },
665 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x03) },
666 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x08) },
664 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, 667 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) },
665 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, 668 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) },
666 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) }, 669 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) },
@@ -747,6 +750,7 @@ static const struct usb_device_id option_ids[] = {
747 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) }, 750 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) },
748 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */ 751 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */
749 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */ 752 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */
753 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x9000)}, /* SIMCom SIM5218 */
750 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6280) }, /* BP3-USB & BP3-EXT HSDPA */ 754 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6280) }, /* BP3-USB & BP3-EXT HSDPA */
751 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6008) }, 755 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6008) },
752 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) }, 756 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) },
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 3041a974faf3..24caba79d722 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1854,6 +1854,13 @@ UNUSUAL_DEV( 0x1370, 0x6828, 0x0110, 0x0110,
1854 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 1854 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1855 US_FL_IGNORE_RESIDUE ), 1855 US_FL_IGNORE_RESIDUE ),
1856 1856
1857/* Reported by Qinglin Ye <yestyle@gmail.com> */
1858UNUSUAL_DEV( 0x13fe, 0x3600, 0x0100, 0x0100,
1859 "Kingston",
1860 "DT 101 G2",
1861 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1862 US_FL_BULK_IGNORE_TAG ),
1863
1857/* Reported by Francesco Foresti <frafore@tiscali.it> */ 1864/* Reported by Francesco Foresti <frafore@tiscali.it> */
1858UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201, 1865UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201,
1859 "Super Top", 1866 "Super Top",