summaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2012-04-08 15:48:52 -0400
committerJiri Kosina <jkosina@suse.cz>2012-04-08 15:48:52 -0400
commite75d660672ddd11704b7f0fdb8ff21968587b266 (patch)
treeccb9c107744c10b553c0373e450bee3971d16c00 /drivers/usb/gadget
parent61282f37927143e45b03153f3e7b48d6b702147a (diff)
parent0034102808e0dbbf3a2394b82b1bb40b5778de9e (diff)
Merge branch 'master' into for-next
Merge with latest Linus' tree, as I have incoming patches that fix code that is newer than current HEAD of for-next. Conflicts: drivers/net/ethernet/realtek/r8169.c
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/Kconfig33
-rw-r--r--drivers/usb/gadget/amd5536udc.c148
-rw-r--r--drivers/usb/gadget/at91_udc.c52
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c7
-rw-r--r--drivers/usb/gadget/audio.c47
-rw-r--r--drivers/usb/gadget/ci13xxx_msm.c4
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c18
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.h2
-rw-r--r--drivers/usb/gadget/dummy_hcd.c756
-rw-r--r--drivers/usb/gadget/epautoconf.c16
-rw-r--r--drivers/usb/gadget/f_acm.c52
-rw-r--r--drivers/usb/gadget/f_ecm.c25
-rw-r--r--drivers/usb/gadget/f_fs.c14
-rw-r--r--drivers/usb/gadget/f_loopback.c2
-rw-r--r--drivers/usb/gadget/f_mass_storage.c29
-rw-r--r--drivers/usb/gadget/f_midi.c2
-rw-r--r--drivers/usb/gadget/f_phonet.c2
-rw-r--r--drivers/usb/gadget/f_rndis.c2
-rw-r--r--drivers/usb/gadget/f_serial.c42
-rw-r--r--drivers/usb/gadget/f_subset.c34
-rw-r--r--drivers/usb/gadget/f_uac1.c (renamed from drivers/usb/gadget/f_audio.c)25
-rw-r--r--drivers/usb/gadget/f_uac2.c1449
-rw-r--r--drivers/usb/gadget/file_storage.c26
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c1
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c29
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.h2
-rw-r--r--drivers/usb/gadget/g_ffs.c2
-rw-r--r--drivers/usb/gadget/goku_udc.c20
-rw-r--r--drivers/usb/gadget/hid.c6
-rw-r--r--drivers/usb/gadget/inode.c15
-rw-r--r--drivers/usb/gadget/langwell_udc.c53
-rw-r--r--drivers/usb/gadget/langwell_udc.h2
-rw-r--r--drivers/usb/gadget/mass_storage.c2
-rw-r--r--drivers/usb/gadget/multi.c2
-rw-r--r--drivers/usb/gadget/mv_udc.h2
-rw-r--r--drivers/usb/gadget/mv_udc_core.c10
-rw-r--r--drivers/usb/gadget/net2272.c19
-rw-r--r--drivers/usb/gadget/net2280.c20
-rw-r--r--drivers/usb/gadget/omap_udc.c27
-rw-r--r--drivers/usb/gadget/omap_udc.h2
-rw-r--r--drivers/usb/gadget/pch_udc.c323
-rw-r--r--drivers/usb/gadget/printer.c1
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c16
-rw-r--r--drivers/usb/gadget/pxa25x_udc.h2
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c11
-rw-r--r--drivers/usb/gadget/pxa27x_udc.h2
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c10
-rw-r--r--drivers/usb/gadget/rndis.c1
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c34
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c3
-rw-r--r--drivers/usb/gadget/serial.c2
-rw-r--r--drivers/usb/gadget/storage_common.c42
-rw-r--r--drivers/usb/gadget/u_serial.c4
-rw-r--r--drivers/usb/gadget/u_uac1.c (renamed from drivers/usb/gadget/u_audio.c)4
-rw-r--r--drivers/usb/gadget/u_uac1.h (renamed from drivers/usb/gadget/u_audio.h)2
-rw-r--r--drivers/usb/gadget/udc-core.c52
56 files changed, 2795 insertions, 715 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index b5972e0f949e..2633f7595116 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -137,7 +137,7 @@ choice
137 137
138config USB_AT91 138config USB_AT91
139 tristate "Atmel AT91 USB Device Port" 139 tristate "Atmel AT91 USB Device Port"
140 depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 && !ARCH_AT91SAM9G45 140 depends on ARCH_AT91
141 help 141 help
142 Many Atmel AT91 processors (such as the AT91RM2000) have a 142 Many Atmel AT91 processors (such as the AT91RM2000) have a
143 full speed USB Device Port with support for five configurable 143 full speed USB Device Port with support for five configurable
@@ -150,7 +150,7 @@ config USB_AT91
150config USB_ATMEL_USBA 150config USB_ATMEL_USBA
151 tristate "Atmel USBA" 151 tristate "Atmel USBA"
152 select USB_GADGET_DUALSPEED 152 select USB_GADGET_DUALSPEED
153 depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 153 depends on AVR32 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45
154 help 154 help
155 USBA is the integrated high-speed USB Device controller on 155 USBA is the integrated high-speed USB Device controller on
156 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. 156 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
@@ -284,7 +284,7 @@ config USB_IMX
284 284
285config USB_S3C2410 285config USB_S3C2410
286 tristate "S3C2410 USB Device Controller" 286 tristate "S3C2410 USB Device Controller"
287 depends on ARCH_S3C2410 287 depends on ARCH_S3C24XX
288 help 288 help
289 Samsung's S3C2410 is an ARM-4 processor with an integrated 289 Samsung's S3C2410 is an ARM-4 processor with an integrated
290 full speed USB 1.1 device controller. It has 4 configurable 290 full speed USB 1.1 device controller. It has 4 configurable
@@ -299,7 +299,7 @@ config USB_S3C2410_DEBUG
299 299
300config USB_S3C_HSUDC 300config USB_S3C_HSUDC
301 tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller" 301 tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller"
302 depends on ARCH_S3C2410 302 depends on ARCH_S3C24XX
303 select USB_GADGET_DUALSPEED 303 select USB_GADGET_DUALSPEED
304 help 304 help
305 Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC 305 Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC
@@ -599,16 +599,29 @@ config USB_AUDIO
599 depends on SND 599 depends on SND
600 select SND_PCM 600 select SND_PCM
601 help 601 help
602 Gadget Audio is compatible with USB Audio Class specification 1.0. 602 This Gadget Audio driver is compatible with USB Audio Class
603 It will include at least one AudioControl interface, zero or more 603 specification 2.0. It implements 1 AudioControl interface,
604 AudioStream interface and zero or more MIDIStream interface. 604 1 AudioStreaming Interface each for USB-OUT and USB-IN.
605 605 Number of channels, sample rate and sample size can be
606 Gadget Audio will use on-board ALSA (CONFIG_SND) audio card to 606 specified as module parameters.
607 playback or capture audio stream. 607 This driver doesn't expect any real Audio codec to be present
608 on the device - the audio streams are simply sinked to and
609 sourced from a virtual ALSA sound card created. The user-space
610 application may choose to do whatever it wants with the data
611 received from the USB Host and choose to provide whatever it
612 wants as audio data to the USB Host.
608 613
609 Say "y" to link the driver statically, or "m" to build a 614 Say "y" to link the driver statically, or "m" to build a
610 dynamically linked module called "g_audio". 615 dynamically linked module called "g_audio".
611 616
617config GADGET_UAC1
618 bool "UAC 1.0 (Legacy)"
619 depends on USB_AUDIO
620 help
621 If you instead want older UAC Spec-1.0 driver that also has audio
622 paths hardwired to the Audio codec chip on-board and doesn't work
623 without one.
624
612config USB_ETH 625config USB_ETH
613 tristate "Ethernet Gadget (with CDC Ethernet support)" 626 tristate "Ethernet Gadget (with CDC Ethernet support)"
614 depends on NET 627 depends on NET
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index c16ff55a74e8..77779271f487 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -29,7 +29,7 @@
29 29
30/* Driver strings */ 30/* Driver strings */
31#define UDC_MOD_DESCRIPTION "AMD 5536 UDC - USB Device Controller" 31#define UDC_MOD_DESCRIPTION "AMD 5536 UDC - USB Device Controller"
32#define UDC_DRIVER_VERSION_STRING "01.00.0206 - $Revision: #3 $" 32#define UDC_DRIVER_VERSION_STRING "01.00.0206"
33 33
34/* system */ 34/* system */
35#include <linux/module.h> 35#include <linux/module.h>
@@ -54,7 +54,6 @@
54#include <linux/prefetch.h> 54#include <linux/prefetch.h>
55 55
56#include <asm/byteorder.h> 56#include <asm/byteorder.h>
57#include <asm/system.h>
58#include <asm/unaligned.h> 57#include <asm/unaligned.h>
59 58
60/* gadget stack */ 59/* gadget stack */
@@ -140,7 +139,7 @@ static DECLARE_TASKLET(disconnect_tasklet, udc_tasklet_disconnect,
140 139
141/* endpoint names used for print */ 140/* endpoint names used for print */
142static const char ep0_string[] = "ep0in"; 141static const char ep0_string[] = "ep0in";
143static const char *ep_string[] = { 142static const char *const ep_string[] = {
144 ep0_string, 143 ep0_string,
145 "ep1in-int", "ep2in-bulk", "ep3in-bulk", "ep4in-bulk", "ep5in-bulk", 144 "ep1in-int", "ep2in-bulk", "ep3in-bulk", "ep4in-bulk", "ep5in-bulk",
146 "ep6in-bulk", "ep7in-bulk", "ep8in-bulk", "ep9in-bulk", "ep10in-bulk", 145 "ep6in-bulk", "ep7in-bulk", "ep8in-bulk", "ep9in-bulk", "ep10in-bulk",
@@ -204,9 +203,8 @@ static void print_regs(struct udc *dev)
204 DBG(dev, "DMA mode = BF (buffer fill mode)\n"); 203 DBG(dev, "DMA mode = BF (buffer fill mode)\n");
205 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "BF"); 204 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "BF");
206 } 205 }
207 if (!use_dma) { 206 if (!use_dma)
208 dev_info(&dev->pdev->dev, "FIFO mode\n"); 207 dev_info(&dev->pdev->dev, "FIFO mode\n");
209 }
210 DBG(dev, "-------------------------------------------------------\n"); 208 DBG(dev, "-------------------------------------------------------\n");
211} 209}
212 210
@@ -445,6 +443,7 @@ static void ep_init(struct udc_regs __iomem *regs, struct udc_ep *ep)
445 443
446 VDBG(ep->dev, "ep-%d reset\n", ep->num); 444 VDBG(ep->dev, "ep-%d reset\n", ep->num);
447 ep->desc = NULL; 445 ep->desc = NULL;
446 ep->ep.desc = NULL;
448 ep->ep.ops = &udc_ep_ops; 447 ep->ep.ops = &udc_ep_ops;
449 INIT_LIST_HEAD(&ep->queue); 448 INIT_LIST_HEAD(&ep->queue);
450 449
@@ -569,9 +568,8 @@ udc_free_request(struct usb_ep *usbep, struct usb_request *usbreq)
569 VDBG(ep->dev, "req->td_data=%p\n", req->td_data); 568 VDBG(ep->dev, "req->td_data=%p\n", req->td_data);
570 569
571 /* free dma chain if created */ 570 /* free dma chain if created */
572 if (req->chain_len > 1) { 571 if (req->chain_len > 1)
573 udc_free_dma_chain(ep->dev, req); 572 udc_free_dma_chain(ep->dev, req);
574 }
575 573
576 pci_pool_free(ep->dev->data_requests, req->td_data, 574 pci_pool_free(ep->dev->data_requests, req->td_data,
577 req->td_phys); 575 req->td_phys);
@@ -639,9 +637,8 @@ udc_txfifo_write(struct udc_ep *ep, struct usb_request *req)
639 bytes = remaining; 637 bytes = remaining;
640 638
641 /* dwords first */ 639 /* dwords first */
642 for (i = 0; i < bytes / UDC_DWORD_BYTES; i++) { 640 for (i = 0; i < bytes / UDC_DWORD_BYTES; i++)
643 writel(*(buf + i), ep->txfifo); 641 writel(*(buf + i), ep->txfifo);
644 }
645 642
646 /* remaining bytes must be written by byte access */ 643 /* remaining bytes must be written by byte access */
647 for (j = 0; j < bytes % UDC_DWORD_BYTES; j++) { 644 for (j = 0; j < bytes % UDC_DWORD_BYTES; j++) {
@@ -660,9 +657,8 @@ static int udc_rxfifo_read_dwords(struct udc *dev, u32 *buf, int dwords)
660 657
661 VDBG(dev, "udc_read_dwords(): %d dwords\n", dwords); 658 VDBG(dev, "udc_read_dwords(): %d dwords\n", dwords);
662 659
663 for (i = 0; i < dwords; i++) { 660 for (i = 0; i < dwords; i++)
664 *(buf + i) = readl(dev->rxfifo); 661 *(buf + i) = readl(dev->rxfifo);
665 }
666 return 0; 662 return 0;
667} 663}
668 664
@@ -675,9 +671,8 @@ static int udc_rxfifo_read_bytes(struct udc *dev, u8 *buf, int bytes)
675 VDBG(dev, "udc_read_bytes(): %d bytes\n", bytes); 671 VDBG(dev, "udc_read_bytes(): %d bytes\n", bytes);
676 672
677 /* dwords first */ 673 /* dwords first */
678 for (i = 0; i < bytes / UDC_DWORD_BYTES; i++) { 674 for (i = 0; i < bytes / UDC_DWORD_BYTES; i++)
679 *((u32 *)(buf + (i<<2))) = readl(dev->rxfifo); 675 *((u32 *)(buf + (i<<2))) = readl(dev->rxfifo);
680 }
681 676
682 /* remaining bytes must be read by byte access */ 677 /* remaining bytes must be read by byte access */
683 if (bytes % UDC_DWORD_BYTES) { 678 if (bytes % UDC_DWORD_BYTES) {
@@ -831,20 +826,8 @@ __acquires(ep->dev->lock)
831 826
832 dev = ep->dev; 827 dev = ep->dev;
833 /* unmap DMA */ 828 /* unmap DMA */
834 if (req->dma_mapping) { 829 if (ep->dma)
835 if (ep->in) 830 usb_gadget_unmap_request(&dev->gadget, &req->req, ep->in);
836 pci_unmap_single(dev->pdev,
837 req->req.dma,
838 req->req.length,
839 PCI_DMA_TODEVICE);
840 else
841 pci_unmap_single(dev->pdev,
842 req->req.dma,
843 req->req.length,
844 PCI_DMA_FROMDEVICE);
845 req->dma_mapping = 0;
846 req->req.dma = DMA_DONT_USE;
847 }
848 831
849 halted = ep->halted; 832 halted = ep->halted;
850 ep->halted = 1; 833 ep->halted = 1;
@@ -897,9 +880,8 @@ static struct udc_data_dma *udc_get_last_dma_desc(struct udc_request *req)
897 struct udc_data_dma *td; 880 struct udc_data_dma *td;
898 881
899 td = req->td_data; 882 td = req->td_data;
900 while (td && !(td->status & AMD_BIT(UDC_DMA_IN_STS_L))) { 883 while (td && !(td->status & AMD_BIT(UDC_DMA_IN_STS_L)))
901 td = phys_to_virt(td->next); 884 td = phys_to_virt(td->next);
902 }
903 885
904 return td; 886 return td;
905 887
@@ -949,21 +931,18 @@ static int udc_create_dma_chain(
949 dma_addr = DMA_DONT_USE; 931 dma_addr = DMA_DONT_USE;
950 932
951 /* unset L bit in first desc for OUT */ 933 /* unset L bit in first desc for OUT */
952 if (!ep->in) { 934 if (!ep->in)
953 req->td_data->status &= AMD_CLEAR_BIT(UDC_DMA_IN_STS_L); 935 req->td_data->status &= AMD_CLEAR_BIT(UDC_DMA_IN_STS_L);
954 }
955 936
956 /* alloc only new desc's if not already available */ 937 /* alloc only new desc's if not already available */
957 len = req->req.length / ep->ep.maxpacket; 938 len = req->req.length / ep->ep.maxpacket;
958 if (req->req.length % ep->ep.maxpacket) { 939 if (req->req.length % ep->ep.maxpacket)
959 len++; 940 len++;
960 }
961 941
962 if (len > req->chain_len) { 942 if (len > req->chain_len) {
963 /* shorter chain already allocated before */ 943 /* shorter chain already allocated before */
964 if (req->chain_len > 1) { 944 if (req->chain_len > 1)
965 udc_free_dma_chain(ep->dev, req); 945 udc_free_dma_chain(ep->dev, req);
966 }
967 req->chain_len = len; 946 req->chain_len = len;
968 create_new_chain = 1; 947 create_new_chain = 1;
969 } 948 }
@@ -1006,11 +985,12 @@ static int udc_create_dma_chain(
1006 985
1007 /* link td and assign tx bytes */ 986 /* link td and assign tx bytes */
1008 if (i == buf_len) { 987 if (i == buf_len) {
1009 if (create_new_chain) { 988 if (create_new_chain)
1010 req->td_data->next = dma_addr; 989 req->td_data->next = dma_addr;
1011 } else { 990 /*
1012 /* req->td_data->next = virt_to_phys(td); */ 991 else
1013 } 992 req->td_data->next = virt_to_phys(td);
993 */
1014 /* write tx bytes */ 994 /* write tx bytes */
1015 if (ep->in) { 995 if (ep->in) {
1016 /* first desc */ 996 /* first desc */
@@ -1024,11 +1004,12 @@ static int udc_create_dma_chain(
1024 UDC_DMA_IN_STS_TXBYTES); 1004 UDC_DMA_IN_STS_TXBYTES);
1025 } 1005 }
1026 } else { 1006 } else {
1027 if (create_new_chain) { 1007 if (create_new_chain)
1028 last->next = dma_addr; 1008 last->next = dma_addr;
1029 } else { 1009 /*
1030 /* last->next = virt_to_phys(td); */ 1010 else
1031 } 1011 last->next = virt_to_phys(td);
1012 */
1032 if (ep->in) { 1013 if (ep->in) {
1033 /* write tx bytes */ 1014 /* write tx bytes */
1034 td->status = AMD_ADDBITS(td->status, 1015 td->status = AMD_ADDBITS(td->status,
@@ -1095,20 +1076,11 @@ udc_queue(struct usb_ep *usbep, struct usb_request *usbreq, gfp_t gfp)
1095 return -ESHUTDOWN; 1076 return -ESHUTDOWN;
1096 1077
1097 /* map dma (usually done before) */ 1078 /* map dma (usually done before) */
1098 if (ep->dma && usbreq->length != 0 1079 if (ep->dma) {
1099 && (usbreq->dma == DMA_DONT_USE || usbreq->dma == 0)) {
1100 VDBG(dev, "DMA map req %p\n", req); 1080 VDBG(dev, "DMA map req %p\n", req);
1101 if (ep->in) 1081 retval = usb_gadget_map_request(&udc->gadget, usbreq, ep->in);
1102 usbreq->dma = pci_map_single(dev->pdev, 1082 if (retval)
1103 usbreq->buf, 1083 return retval;
1104 usbreq->length,
1105 PCI_DMA_TODEVICE);
1106 else
1107 usbreq->dma = pci_map_single(dev->pdev,
1108 usbreq->buf,
1109 usbreq->length,
1110 PCI_DMA_FROMDEVICE);
1111 req->dma_mapping = 1;
1112 } 1084 }
1113 1085
1114 VDBG(dev, "%s queue req %p, len %d req->td_data=%p buf %p\n", 1086 VDBG(dev, "%s queue req %p, len %d req->td_data=%p buf %p\n",
@@ -1479,11 +1451,10 @@ static int startup_registers(struct udc *dev)
1479 1451
1480 /* program speed */ 1452 /* program speed */
1481 tmp = readl(&dev->regs->cfg); 1453 tmp = readl(&dev->regs->cfg);
1482 if (use_fullspeed) { 1454 if (use_fullspeed)
1483 tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_FS, UDC_DEVCFG_SPD); 1455 tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_FS, UDC_DEVCFG_SPD);
1484 } else { 1456 else
1485 tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_HS, UDC_DEVCFG_SPD); 1457 tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_HS, UDC_DEVCFG_SPD);
1486 }
1487 writel(tmp, &dev->regs->cfg); 1458 writel(tmp, &dev->regs->cfg);
1488 1459
1489 return 0; 1460 return 0;
@@ -1504,9 +1475,8 @@ static void udc_basic_init(struct udc *dev)
1504 mod_timer(&udc_timer, jiffies - 1); 1475 mod_timer(&udc_timer, jiffies - 1);
1505 } 1476 }
1506 /* stop poll stall timer */ 1477 /* stop poll stall timer */
1507 if (timer_pending(&udc_pollstall_timer)) { 1478 if (timer_pending(&udc_pollstall_timer))
1508 mod_timer(&udc_pollstall_timer, jiffies - 1); 1479 mod_timer(&udc_pollstall_timer, jiffies - 1);
1509 }
1510 /* disable DMA */ 1480 /* disable DMA */
1511 tmp = readl(&dev->regs->ctl); 1481 tmp = readl(&dev->regs->ctl);
1512 tmp &= AMD_UNMASK_BIT(UDC_DEVCTL_RDE); 1482 tmp &= AMD_UNMASK_BIT(UDC_DEVCTL_RDE);
@@ -1540,11 +1510,10 @@ static void udc_setup_endpoints(struct udc *dev)
1540 /* read enum speed */ 1510 /* read enum speed */
1541 tmp = readl(&dev->regs->sts); 1511 tmp = readl(&dev->regs->sts);
1542 tmp = AMD_GETBITS(tmp, UDC_DEVSTS_ENUM_SPEED); 1512 tmp = AMD_GETBITS(tmp, UDC_DEVSTS_ENUM_SPEED);
1543 if (tmp == UDC_DEVSTS_ENUM_SPEED_HIGH) { 1513 if (tmp == UDC_DEVSTS_ENUM_SPEED_HIGH)
1544 dev->gadget.speed = USB_SPEED_HIGH; 1514 dev->gadget.speed = USB_SPEED_HIGH;
1545 } else if (tmp == UDC_DEVSTS_ENUM_SPEED_FULL) { 1515 else if (tmp == UDC_DEVSTS_ENUM_SPEED_FULL)
1546 dev->gadget.speed = USB_SPEED_FULL; 1516 dev->gadget.speed = USB_SPEED_FULL;
1547 }
1548 1517
1549 /* set basic ep parameters */ 1518 /* set basic ep parameters */
1550 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) { 1519 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) {
@@ -1570,9 +1539,8 @@ static void udc_setup_endpoints(struct udc *dev)
1570 * disabling ep interrupts when ENUM interrupt occurs but ep is 1539 * disabling ep interrupts when ENUM interrupt occurs but ep is
1571 * not enabled by gadget driver 1540 * not enabled by gadget driver
1572 */ 1541 */
1573 if (!ep->desc) { 1542 if (!ep->desc)
1574 ep_init(dev->regs, ep); 1543 ep_init(dev->regs, ep);
1575 }
1576 1544
1577 if (use_dma) { 1545 if (use_dma) {
1578 /* 1546 /*
@@ -1670,9 +1638,8 @@ static void udc_tasklet_disconnect(unsigned long par)
1670 spin_lock(&dev->lock); 1638 spin_lock(&dev->lock);
1671 1639
1672 /* empty queues */ 1640 /* empty queues */
1673 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) { 1641 for (tmp = 0; tmp < UDC_EP_NUM; tmp++)
1674 empty_req_queue(&dev->ep[tmp]); 1642 empty_req_queue(&dev->ep[tmp]);
1675 }
1676 1643
1677 } 1644 }
1678 1645
@@ -1746,9 +1713,8 @@ static void udc_timer_function(unsigned long v)
1746 * open the fifo 1713 * open the fifo
1747 */ 1714 */
1748 udc_timer.expires = jiffies + HZ/UDC_RDE_TIMER_DIV; 1715 udc_timer.expires = jiffies + HZ/UDC_RDE_TIMER_DIV;
1749 if (!stop_timer) { 1716 if (!stop_timer)
1750 add_timer(&udc_timer); 1717 add_timer(&udc_timer);
1751 }
1752 } else { 1718 } else {
1753 /* 1719 /*
1754 * fifo contains data now, setup timer for opening 1720 * fifo contains data now, setup timer for opening
@@ -1760,9 +1726,8 @@ static void udc_timer_function(unsigned long v)
1760 set_rde++; 1726 set_rde++;
1761 /* debug: lhadmot_timer_start = 221070 */ 1727 /* debug: lhadmot_timer_start = 221070 */
1762 udc_timer.expires = jiffies + HZ*UDC_RDE_TIMER_SECONDS; 1728 udc_timer.expires = jiffies + HZ*UDC_RDE_TIMER_SECONDS;
1763 if (!stop_timer) { 1729 if (!stop_timer)
1764 add_timer(&udc_timer); 1730 add_timer(&udc_timer);
1765 }
1766 } 1731 }
1767 1732
1768 } else 1733 } else
@@ -1907,19 +1872,17 @@ static void activate_control_endpoints(struct udc *dev)
1907 mod_timer(&udc_timer, jiffies - 1); 1872 mod_timer(&udc_timer, jiffies - 1);
1908 } 1873 }
1909 /* stop pollstall timer */ 1874 /* stop pollstall timer */
1910 if (timer_pending(&udc_pollstall_timer)) { 1875 if (timer_pending(&udc_pollstall_timer))
1911 mod_timer(&udc_pollstall_timer, jiffies - 1); 1876 mod_timer(&udc_pollstall_timer, jiffies - 1);
1912 }
1913 /* enable DMA */ 1877 /* enable DMA */
1914 tmp = readl(&dev->regs->ctl); 1878 tmp = readl(&dev->regs->ctl);
1915 tmp |= AMD_BIT(UDC_DEVCTL_MODE) 1879 tmp |= AMD_BIT(UDC_DEVCTL_MODE)
1916 | AMD_BIT(UDC_DEVCTL_RDE) 1880 | AMD_BIT(UDC_DEVCTL_RDE)
1917 | AMD_BIT(UDC_DEVCTL_TDE); 1881 | AMD_BIT(UDC_DEVCTL_TDE);
1918 if (use_dma_bufferfill_mode) { 1882 if (use_dma_bufferfill_mode)
1919 tmp |= AMD_BIT(UDC_DEVCTL_BF); 1883 tmp |= AMD_BIT(UDC_DEVCTL_BF);
1920 } else if (use_dma_ppb_du) { 1884 else if (use_dma_ppb_du)
1921 tmp |= AMD_BIT(UDC_DEVCTL_DU); 1885 tmp |= AMD_BIT(UDC_DEVCTL_DU);
1922 }
1923 writel(tmp, &dev->regs->ctl); 1886 writel(tmp, &dev->regs->ctl);
1924 } 1887 }
1925 1888
@@ -2104,9 +2067,8 @@ static void udc_ep0_set_rde(struct udc *dev)
2104 udc_timer.expires = 2067 udc_timer.expires =
2105 jiffies + HZ/UDC_RDE_TIMER_DIV; 2068 jiffies + HZ/UDC_RDE_TIMER_DIV;
2106 set_rde = 1; 2069 set_rde = 1;
2107 if (!stop_timer) { 2070 if (!stop_timer)
2108 add_timer(&udc_timer); 2071 add_timer(&udc_timer);
2109 }
2110 } 2072 }
2111 } 2073 }
2112 } 2074 }
@@ -2131,7 +2093,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int ep_ix)
2131 if (use_dma) { 2093 if (use_dma) {
2132 /* BNA event ? */ 2094 /* BNA event ? */
2133 if (tmp & AMD_BIT(UDC_EPSTS_BNA)) { 2095 if (tmp & AMD_BIT(UDC_EPSTS_BNA)) {
2134 DBG(dev, "BNA ep%dout occurred - DESPTR = %x \n", 2096 DBG(dev, "BNA ep%dout occurred - DESPTR = %x\n",
2135 ep->num, readl(&ep->regs->desptr)); 2097 ep->num, readl(&ep->regs->desptr));
2136 /* clear BNA */ 2098 /* clear BNA */
2137 writel(tmp | AMD_BIT(UDC_EPSTS_BNA), &ep->regs->sts); 2099 writel(tmp | AMD_BIT(UDC_EPSTS_BNA), &ep->regs->sts);
@@ -2294,9 +2256,8 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int ep_ix)
2294 jiffies 2256 jiffies
2295 + HZ*UDC_RDE_TIMER_SECONDS; 2257 + HZ*UDC_RDE_TIMER_SECONDS;
2296 set_rde = 1; 2258 set_rde = 1;
2297 if (!stop_timer) { 2259 if (!stop_timer)
2298 add_timer(&udc_timer); 2260 add_timer(&udc_timer);
2299 }
2300 } 2261 }
2301 if (ep->num != UDC_EP0OUT_IX) 2262 if (ep->num != UDC_EP0OUT_IX)
2302 dev->data_ep_queued = 0; 2263 dev->data_ep_queued = 0;
@@ -2318,9 +2279,8 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int ep_ix)
2318 /* check pending CNAKS */ 2279 /* check pending CNAKS */
2319 if (cnak_pending) { 2280 if (cnak_pending) {
2320 /* CNAk processing when rxfifo empty only */ 2281 /* CNAk processing when rxfifo empty only */
2321 if (readl(&dev->regs->sts) & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) { 2282 if (readl(&dev->regs->sts) & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY))
2322 udc_process_cnak_queue(dev); 2283 udc_process_cnak_queue(dev);
2323 }
2324 } 2284 }
2325 2285
2326 /* clear OUT bits in ep status */ 2286 /* clear OUT bits in ep status */
@@ -2348,7 +2308,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix)
2348 /* BNA ? */ 2308 /* BNA ? */
2349 if (epsts & AMD_BIT(UDC_EPSTS_BNA)) { 2309 if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
2350 dev_err(&dev->pdev->dev, 2310 dev_err(&dev->pdev->dev,
2351 "BNA ep%din occurred - DESPTR = %08lx \n", 2311 "BNA ep%din occurred - DESPTR = %08lx\n",
2352 ep->num, 2312 ep->num,
2353 (unsigned long) readl(&ep->regs->desptr)); 2313 (unsigned long) readl(&ep->regs->desptr));
2354 2314
@@ -2361,7 +2321,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix)
2361 /* HE event ? */ 2321 /* HE event ? */
2362 if (epsts & AMD_BIT(UDC_EPSTS_HE)) { 2322 if (epsts & AMD_BIT(UDC_EPSTS_HE)) {
2363 dev_err(&dev->pdev->dev, 2323 dev_err(&dev->pdev->dev,
2364 "HE ep%dn occurred - DESPTR = %08lx \n", 2324 "HE ep%dn occurred - DESPTR = %08lx\n",
2365 ep->num, (unsigned long) readl(&ep->regs->desptr)); 2325 ep->num, (unsigned long) readl(&ep->regs->desptr));
2366 2326
2367 /* clear HE */ 2327 /* clear HE */
@@ -2427,9 +2387,9 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix)
2427 /* write fifo */ 2387 /* write fifo */
2428 udc_txfifo_write(ep, &req->req); 2388 udc_txfifo_write(ep, &req->req);
2429 len = req->req.length - req->req.actual; 2389 len = req->req.length - req->req.actual;
2430 if (len > ep->ep.maxpacket) 2390 if (len > ep->ep.maxpacket)
2431 len = ep->ep.maxpacket; 2391 len = ep->ep.maxpacket;
2432 req->req.actual += len; 2392 req->req.actual += len;
2433 if (req->req.actual == req->req.length 2393 if (req->req.actual == req->req.length
2434 || (len != ep->ep.maxpacket)) { 2394 || (len != ep->ep.maxpacket)) {
2435 /* complete req */ 2395 /* complete req */
@@ -2581,9 +2541,8 @@ __acquires(dev->lock)
2581 if (!timer_pending(&udc_timer)) { 2541 if (!timer_pending(&udc_timer)) {
2582 udc_timer.expires = jiffies + 2542 udc_timer.expires = jiffies +
2583 HZ/UDC_RDE_TIMER_DIV; 2543 HZ/UDC_RDE_TIMER_DIV;
2584 if (!stop_timer) { 2544 if (!stop_timer)
2585 add_timer(&udc_timer); 2545 add_timer(&udc_timer);
2586 }
2587 } 2546 }
2588 } 2547 }
2589 2548
@@ -2697,9 +2656,8 @@ __acquires(dev->lock)
2697 /* check pending CNAKS */ 2656 /* check pending CNAKS */
2698 if (cnak_pending) { 2657 if (cnak_pending) {
2699 /* CNAk processing when rxfifo empty only */ 2658 /* CNAk processing when rxfifo empty only */
2700 if (readl(&dev->regs->sts) & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) { 2659 if (readl(&dev->regs->sts) & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY))
2701 udc_process_cnak_queue(dev); 2660 udc_process_cnak_queue(dev);
2702 }
2703 } 2661 }
2704 2662
2705finished: 2663finished:
@@ -2723,7 +2681,7 @@ static irqreturn_t udc_control_in_isr(struct udc *dev)
2723 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->sts); 2681 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->sts);
2724 /* DMA completion */ 2682 /* DMA completion */
2725 if (tmp & AMD_BIT(UDC_EPSTS_TDC)) { 2683 if (tmp & AMD_BIT(UDC_EPSTS_TDC)) {
2726 VDBG(dev, "isr: TDC clear \n"); 2684 VDBG(dev, "isr: TDC clear\n");
2727 ret_val = IRQ_HANDLED; 2685 ret_val = IRQ_HANDLED;
2728 2686
2729 /* clear TDC bit */ 2687 /* clear TDC bit */
@@ -3426,7 +3384,7 @@ static int udc_remote_wakeup(struct udc *dev)
3426} 3384}
3427 3385
3428/* PCI device parameters */ 3386/* PCI device parameters */
3429static const struct pci_device_id pci_id[] = { 3387static DEFINE_PCI_DEVICE_TABLE(pci_id) = {
3430 { 3388 {
3431 PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096), 3389 PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096),
3432 .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, 3390 .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe,
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 143a7256b598..0c935d7c65bd 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -29,18 +29,19 @@
29#include <linux/clk.h> 29#include <linux/clk.h>
30#include <linux/usb/ch9.h> 30#include <linux/usb/ch9.h>
31#include <linux/usb/gadget.h> 31#include <linux/usb/gadget.h>
32#include <linux/prefetch.h> 32#include <linux/of.h>
33#include <linux/of_gpio.h>
33 34
34#include <asm/byteorder.h> 35#include <asm/byteorder.h>
35#include <mach/hardware.h> 36#include <mach/hardware.h>
36#include <asm/io.h> 37#include <asm/io.h>
37#include <asm/irq.h> 38#include <asm/irq.h>
38#include <asm/system.h>
39#include <asm/gpio.h> 39#include <asm/gpio.h>
40 40
41#include <mach/board.h> 41#include <mach/board.h>
42#include <mach/cpu.h> 42#include <mach/cpu.h>
43#include <mach/at91sam9261_matrix.h> 43#include <mach/at91sam9261_matrix.h>
44#include <mach/at91_matrix.h>
44 45
45#include "at91_udc.h" 46#include "at91_udc.h"
46 47
@@ -558,6 +559,7 @@ static int at91_ep_disable (struct usb_ep * _ep)
558 559
559 /* restore the endpoint's pristine config */ 560 /* restore the endpoint's pristine config */
560 ep->desc = NULL; 561 ep->desc = NULL;
562 ep->ep.desc = NULL;
561 ep->ep.maxpacket = ep->maxpacket; 563 ep->ep.maxpacket = ep->maxpacket;
562 564
563 /* reset fifos and endpoint */ 565 /* reset fifos and endpoint */
@@ -910,9 +912,9 @@ static void pullup(struct at91_udc *udc, int is_on)
910 } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { 912 } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
911 u32 usbpucr; 913 u32 usbpucr;
912 914
913 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR); 915 usbpucr = at91_matrix_read(AT91_MATRIX_USBPUCR);
914 usbpucr |= AT91_MATRIX_USBPUCR_PUON; 916 usbpucr |= AT91_MATRIX_USBPUCR_PUON;
915 at91_sys_write(AT91_MATRIX_USBPUCR, usbpucr); 917 at91_matrix_write(AT91_MATRIX_USBPUCR, usbpucr);
916 } 918 }
917 } else { 919 } else {
918 stop_activity(udc); 920 stop_activity(udc);
@@ -928,9 +930,9 @@ static void pullup(struct at91_udc *udc, int is_on)
928 } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { 930 } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
929 u32 usbpucr; 931 u32 usbpucr;
930 932
931 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR); 933 usbpucr = at91_matrix_read(AT91_MATRIX_USBPUCR);
932 usbpucr &= ~AT91_MATRIX_USBPUCR_PUON; 934 usbpucr &= ~AT91_MATRIX_USBPUCR_PUON;
933 at91_sys_write(AT91_MATRIX_USBPUCR, usbpucr); 935 at91_matrix_write(AT91_MATRIX_USBPUCR, usbpucr);
934 } 936 }
935 clk_off(udc); 937 clk_off(udc);
936 } 938 }
@@ -1706,7 +1708,27 @@ static void at91udc_shutdown(struct platform_device *dev)
1706 spin_unlock_irqrestore(&udc->lock, flags); 1708 spin_unlock_irqrestore(&udc->lock, flags);
1707} 1709}
1708 1710
1709static int __init at91udc_probe(struct platform_device *pdev) 1711static void __devinit at91udc_of_init(struct at91_udc *udc,
1712 struct device_node *np)
1713{
1714 struct at91_udc_data *board = &udc->board;
1715 u32 val;
1716 enum of_gpio_flags flags;
1717
1718 if (of_property_read_u32(np, "atmel,vbus-polled", &val) == 0)
1719 board->vbus_polled = 1;
1720
1721 board->vbus_pin = of_get_named_gpio_flags(np, "atmel,vbus-gpio", 0,
1722 &flags);
1723 board->vbus_active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0;
1724
1725 board->pullup_pin = of_get_named_gpio_flags(np, "atmel,pullup-gpio", 0,
1726 &flags);
1727
1728 board->pullup_active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0;
1729}
1730
1731static int __devinit at91udc_probe(struct platform_device *pdev)
1710{ 1732{
1711 struct device *dev = &pdev->dev; 1733 struct device *dev = &pdev->dev;
1712 struct at91_udc *udc; 1734 struct at91_udc *udc;
@@ -1741,7 +1763,11 @@ static int __init at91udc_probe(struct platform_device *pdev)
1741 /* init software state */ 1763 /* init software state */
1742 udc = &controller; 1764 udc = &controller;
1743 udc->gadget.dev.parent = dev; 1765 udc->gadget.dev.parent = dev;
1744 udc->board = *(struct at91_udc_data *) dev->platform_data; 1766 if (pdev->dev.of_node)
1767 at91udc_of_init(udc, pdev->dev.of_node);
1768 else
1769 memcpy(&udc->board, dev->platform_data,
1770 sizeof(struct at91_udc_data));
1745 udc->pdev = pdev; 1771 udc->pdev = pdev;
1746 udc->enabled = 0; 1772 udc->enabled = 0;
1747 spin_lock_init(&udc->lock); 1773 spin_lock_init(&udc->lock);
@@ -1970,6 +1996,15 @@ static int at91udc_resume(struct platform_device *pdev)
1970#define at91udc_resume NULL 1996#define at91udc_resume NULL
1971#endif 1997#endif
1972 1998
1999#if defined(CONFIG_OF)
2000static const struct of_device_id at91_udc_dt_ids[] = {
2001 { .compatible = "atmel,at91rm9200-udc" },
2002 { /* sentinel */ }
2003};
2004
2005MODULE_DEVICE_TABLE(of, at91_udc_dt_ids);
2006#endif
2007
1973static struct platform_driver at91_udc_driver = { 2008static struct platform_driver at91_udc_driver = {
1974 .remove = __exit_p(at91udc_remove), 2009 .remove = __exit_p(at91udc_remove),
1975 .shutdown = at91udc_shutdown, 2010 .shutdown = at91udc_shutdown,
@@ -1978,6 +2013,7 @@ static struct platform_driver at91_udc_driver = {
1978 .driver = { 2013 .driver = {
1979 .name = (char *) driver_name, 2014 .name = (char *) driver_name,
1980 .owner = THIS_MODULE, 2015 .owner = THIS_MODULE,
2016 .of_match_table = of_match_ptr(at91_udc_dt_ids),
1981 }, 2017 },
1982}; 2018};
1983 2019
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index e2fb6d583bd9..9f98508966d1 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -332,12 +332,12 @@ static int vbus_is_present(struct usba_udc *udc)
332 332
333static void toggle_bias(int is_on) 333static void toggle_bias(int is_on)
334{ 334{
335 unsigned int uckr = at91_sys_read(AT91_CKGR_UCKR); 335 unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
336 336
337 if (is_on) 337 if (is_on)
338 at91_sys_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN); 338 at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
339 else 339 else
340 at91_sys_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN)); 340 at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
341} 341}
342 342
343#else 343#else
@@ -659,6 +659,7 @@ static int usba_ep_disable(struct usb_ep *_ep)
659 return -EINVAL; 659 return -EINVAL;
660 } 660 }
661 ep->desc = NULL; 661 ep->desc = NULL;
662 ep->ep.desc = NULL;
662 663
663 list_splice_init(&ep->queue, &req_list); 664 list_splice_init(&ep->queue, &req_list);
664 if (ep->can_dma) { 665 if (ep->can_dma) {
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index 9d89ae4765a9..98899244860e 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -14,10 +14,8 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/utsname.h> 15#include <linux/utsname.h>
16 16
17#include "u_audio.h"
18
19#define DRIVER_DESC "Linux USB Audio Gadget" 17#define DRIVER_DESC "Linux USB Audio Gadget"
20#define DRIVER_VERSION "Dec 18, 2008" 18#define DRIVER_VERSION "Feb 2, 2012"
21 19
22/*-------------------------------------------------------------------------*/ 20/*-------------------------------------------------------------------------*/
23 21
@@ -33,8 +31,36 @@
33#include "config.c" 31#include "config.c"
34#include "epautoconf.c" 32#include "epautoconf.c"
35 33
36#include "u_audio.c" 34/* string IDs are assigned dynamically */
37#include "f_audio.c" 35
36#define STRING_MANUFACTURER_IDX 0
37#define STRING_PRODUCT_IDX 1
38
39static char manufacturer[50];
40
41static struct usb_string strings_dev[] = {
42 [STRING_MANUFACTURER_IDX].s = manufacturer,
43 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
44 { } /* end of list */
45};
46
47static struct usb_gadget_strings stringtab_dev = {
48 .language = 0x0409, /* en-us */
49 .strings = strings_dev,
50};
51
52static struct usb_gadget_strings *audio_strings[] = {
53 &stringtab_dev,
54 NULL,
55};
56
57#ifdef CONFIG_GADGET_UAC1
58#include "u_uac1.h"
59#include "u_uac1.c"
60#include "f_uac1.c"
61#else
62#include "f_uac2.c"
63#endif
38 64
39/*-------------------------------------------------------------------------*/ 65/*-------------------------------------------------------------------------*/
40 66
@@ -54,9 +80,15 @@ static struct usb_device_descriptor device_desc = {
54 80
55 .bcdUSB = __constant_cpu_to_le16(0x200), 81 .bcdUSB = __constant_cpu_to_le16(0x200),
56 82
83#ifdef CONFIG_GADGET_UAC1
57 .bDeviceClass = USB_CLASS_PER_INTERFACE, 84 .bDeviceClass = USB_CLASS_PER_INTERFACE,
58 .bDeviceSubClass = 0, 85 .bDeviceSubClass = 0,
59 .bDeviceProtocol = 0, 86 .bDeviceProtocol = 0,
87#else
88 .bDeviceClass = USB_CLASS_MISC,
89 .bDeviceSubClass = 0x02,
90 .bDeviceProtocol = 0x01,
91#endif
60 /* .bMaxPacketSize0 = f(hardware) */ 92 /* .bMaxPacketSize0 = f(hardware) */
61 93
62 /* Vendor and product id defaults change according to what configs 94 /* Vendor and product id defaults change according to what configs
@@ -108,6 +140,9 @@ static struct usb_configuration audio_config_driver = {
108 .bConfigurationValue = 1, 140 .bConfigurationValue = 1,
109 /* .iConfiguration = DYNAMIC */ 141 /* .iConfiguration = DYNAMIC */
110 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 142 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
143#ifndef CONFIG_GADGET_UAC1
144 .unbind = uac2_unbind_config,
145#endif
111}; 146};
112 147
113/*-------------------------------------------------------------------------*/ 148/*-------------------------------------------------------------------------*/
@@ -157,7 +192,9 @@ fail:
157 192
158static int __exit audio_unbind(struct usb_composite_dev *cdev) 193static int __exit audio_unbind(struct usb_composite_dev *cdev)
159{ 194{
195#ifdef CONFIG_GADGET_UAC1
160 gaudio_cleanup(); 196 gaudio_cleanup();
197#endif
161 return 0; 198 return 0;
162} 199}
163 200
diff --git a/drivers/usb/gadget/ci13xxx_msm.c b/drivers/usb/gadget/ci13xxx_msm.c
index 1fc612914c52..d07e44c05e9b 100644
--- a/drivers/usb/gadget/ci13xxx_msm.c
+++ b/drivers/usb/gadget/ci13xxx_msm.c
@@ -37,10 +37,10 @@ static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
37 * Put the transceiver in non-driving mode. Otherwise host 37 * Put the transceiver in non-driving mode. Otherwise host
38 * may not detect soft-disconnection. 38 * may not detect soft-disconnection.
39 */ 39 */
40 val = otg_io_read(udc->transceiver, ULPI_FUNC_CTRL); 40 val = usb_phy_io_read(udc->transceiver, ULPI_FUNC_CTRL);
41 val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; 41 val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
42 val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; 42 val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
43 otg_io_write(udc->transceiver, val, ULPI_FUNC_CTRL); 43 usb_phy_io_write(udc->transceiver, val, ULPI_FUNC_CTRL);
44 break; 44 break;
45 default: 45 default:
46 dev_dbg(dev, "unknown ci13xxx_udc event\n"); 46 dev_dbg(dev, "unknown ci13xxx_udc event\n");
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index 27e313718422..243ef1adf969 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -2181,6 +2181,7 @@ static int ep_disable(struct usb_ep *ep)
2181 } while (mEp->dir != direction); 2181 } while (mEp->dir != direction);
2182 2182
2183 mEp->desc = NULL; 2183 mEp->desc = NULL;
2184 mEp->ep.desc = NULL;
2184 2185
2185 spin_unlock_irqrestore(mEp->lock, flags); 2186 spin_unlock_irqrestore(mEp->lock, flags);
2186 return retval; 2187 return retval;
@@ -2537,7 +2538,7 @@ static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
2537 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); 2538 struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget);
2538 2539
2539 if (udc->transceiver) 2540 if (udc->transceiver)
2540 return otg_set_power(udc->transceiver, mA); 2541 return usb_phy_set_power(udc->transceiver, mA);
2541 return -ENOTSUPP; 2542 return -ENOTSUPP;
2542} 2543}
2543 2544
@@ -2900,7 +2901,7 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
2900 if (retval < 0) 2901 if (retval < 0)
2901 goto free_udc; 2902 goto free_udc;
2902 2903
2903 udc->transceiver = otg_get_transceiver(); 2904 udc->transceiver = usb_get_transceiver();
2904 2905
2905 if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) { 2906 if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) {
2906 if (udc->transceiver == NULL) { 2907 if (udc->transceiver == NULL) {
@@ -2928,7 +2929,8 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
2928 goto unreg_device; 2929 goto unreg_device;
2929 2930
2930 if (udc->transceiver) { 2931 if (udc->transceiver) {
2931 retval = otg_set_peripheral(udc->transceiver, &udc->gadget); 2932 retval = otg_set_peripheral(udc->transceiver->otg,
2933 &udc->gadget);
2932 if (retval) 2934 if (retval)
2933 goto remove_dbg; 2935 goto remove_dbg;
2934 } 2936 }
@@ -2945,8 +2947,8 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
2945 2947
2946remove_trans: 2948remove_trans:
2947 if (udc->transceiver) { 2949 if (udc->transceiver) {
2948 otg_set_peripheral(udc->transceiver, &udc->gadget); 2950 otg_set_peripheral(udc->transceiver->otg, &udc->gadget);
2949 otg_put_transceiver(udc->transceiver); 2951 usb_put_transceiver(udc->transceiver);
2950 } 2952 }
2951 2953
2952 err("error = %i", retval); 2954 err("error = %i", retval);
@@ -2958,7 +2960,7 @@ unreg_device:
2958 device_unregister(&udc->gadget.dev); 2960 device_unregister(&udc->gadget.dev);
2959put_transceiver: 2961put_transceiver:
2960 if (udc->transceiver) 2962 if (udc->transceiver)
2961 otg_put_transceiver(udc->transceiver); 2963 usb_put_transceiver(udc->transceiver);
2962free_udc: 2964free_udc:
2963 kfree(udc); 2965 kfree(udc);
2964 _udc = NULL; 2966 _udc = NULL;
@@ -2981,8 +2983,8 @@ static void udc_remove(void)
2981 usb_del_gadget_udc(&udc->gadget); 2983 usb_del_gadget_udc(&udc->gadget);
2982 2984
2983 if (udc->transceiver) { 2985 if (udc->transceiver) {
2984 otg_set_peripheral(udc->transceiver, &udc->gadget); 2986 otg_set_peripheral(udc->transceiver->otg, &udc->gadget);
2985 otg_put_transceiver(udc->transceiver); 2987 usb_put_transceiver(udc->transceiver);
2986 } 2988 }
2987#ifdef CONFIG_USB_GADGET_DEBUG_FILES 2989#ifdef CONFIG_USB_GADGET_DEBUG_FILES
2988 dbg_remove_files(&udc->gadget.dev); 2990 dbg_remove_files(&udc->gadget.dev);
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h
index f4871e1fac59..0d31af56c989 100644
--- a/drivers/usb/gadget/ci13xxx_udc.h
+++ b/drivers/usb/gadget/ci13xxx_udc.h
@@ -136,7 +136,7 @@ struct ci13xxx {
136 struct usb_gadget_driver *driver; /* 3rd party gadget driver */ 136 struct usb_gadget_driver *driver; /* 3rd party gadget driver */
137 struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ 137 struct ci13xxx_udc_driver *udc_driver; /* device controller driver */
138 int vbus_active; /* is VBUS active */ 138 int vbus_active; /* is VBUS active */
139 struct otg_transceiver *transceiver; /* Transceiver struct */ 139 struct usb_phy *transceiver; /* Transceiver struct */
140}; 140};
141 141
142/****************************************************************************** 142/******************************************************************************
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index db815c2da7ed..a6dfd2164166 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -39,27 +39,26 @@
39#include <linux/usb.h> 39#include <linux/usb.h>
40#include <linux/usb/gadget.h> 40#include <linux/usb/gadget.h>
41#include <linux/usb/hcd.h> 41#include <linux/usb/hcd.h>
42#include <linux/scatterlist.h>
42 43
43#include <asm/byteorder.h> 44#include <asm/byteorder.h>
44#include <asm/io.h> 45#include <linux/io.h>
45#include <asm/irq.h> 46#include <asm/irq.h>
46#include <asm/system.h>
47#include <asm/unaligned.h> 47#include <asm/unaligned.h>
48 48
49
50#define DRIVER_DESC "USB Host+Gadget Emulator" 49#define DRIVER_DESC "USB Host+Gadget Emulator"
51#define DRIVER_VERSION "02 May 2005" 50#define DRIVER_VERSION "02 May 2005"
52 51
53#define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */ 52#define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
54 53
55static const char driver_name [] = "dummy_hcd"; 54static const char driver_name[] = "dummy_hcd";
56static const char driver_desc [] = "USB Host+Gadget Emulator"; 55static const char driver_desc[] = "USB Host+Gadget Emulator";
57 56
58static const char gadget_name [] = "dummy_udc"; 57static const char gadget_name[] = "dummy_udc";
59 58
60MODULE_DESCRIPTION (DRIVER_DESC); 59MODULE_DESCRIPTION(DRIVER_DESC);
61MODULE_AUTHOR ("David Brownell"); 60MODULE_AUTHOR("David Brownell");
62MODULE_LICENSE ("GPL"); 61MODULE_LICENSE("GPL");
63 62
64struct dummy_hcd_module_parameters { 63struct dummy_hcd_module_parameters {
65 bool is_super_speed; 64 bool is_super_speed;
@@ -83,10 +82,11 @@ struct dummy_ep {
83 struct usb_gadget *gadget; 82 struct usb_gadget *gadget;
84 const struct usb_endpoint_descriptor *desc; 83 const struct usb_endpoint_descriptor *desc;
85 struct usb_ep ep; 84 struct usb_ep ep;
86 unsigned halted : 1; 85 unsigned halted:1;
87 unsigned wedged : 1; 86 unsigned wedged:1;
88 unsigned already_seen : 1; 87 unsigned already_seen:1;
89 unsigned setup_stage : 1; 88 unsigned setup_stage:1;
89 unsigned stream_en:1;
90}; 90};
91 91
92struct dummy_request { 92struct dummy_request {
@@ -94,15 +94,15 @@ struct dummy_request {
94 struct usb_request req; 94 struct usb_request req;
95}; 95};
96 96
97static inline struct dummy_ep *usb_ep_to_dummy_ep (struct usb_ep *_ep) 97static inline struct dummy_ep *usb_ep_to_dummy_ep(struct usb_ep *_ep)
98{ 98{
99 return container_of (_ep, struct dummy_ep, ep); 99 return container_of(_ep, struct dummy_ep, ep);
100} 100}
101 101
102static inline struct dummy_request *usb_request_to_dummy_request 102static inline struct dummy_request *usb_request_to_dummy_request
103 (struct usb_request *_req) 103 (struct usb_request *_req)
104{ 104{
105 return container_of (_req, struct dummy_request, req); 105 return container_of(_req, struct dummy_request, req);
106} 106}
107 107
108/*-------------------------------------------------------------------------*/ 108/*-------------------------------------------------------------------------*/
@@ -121,9 +121,9 @@ static inline struct dummy_request *usb_request_to_dummy_request
121 * configurations, illegal or unsupported packet lengths, and so on. 121 * configurations, illegal or unsupported packet lengths, and so on.
122 */ 122 */
123 123
124static const char ep0name [] = "ep0"; 124static const char ep0name[] = "ep0";
125 125
126static const char *const ep_name [] = { 126static const char *const ep_name[] = {
127 ep0name, /* everyone has ep0 */ 127 ep0name, /* everyone has ep0 */
128 128
129 /* act like a net2280: high speed, six configurable endpoints */ 129 /* act like a net2280: high speed, six configurable endpoints */
@@ -147,6 +147,8 @@ static const char *const ep_name [] = {
147struct urbp { 147struct urbp {
148 struct urb *urb; 148 struct urb *urb;
149 struct list_head urbp_list; 149 struct list_head urbp_list;
150 struct sg_mapping_iter miter;
151 u32 miter_started;
150}; 152};
151 153
152 154
@@ -166,6 +168,8 @@ struct dummy_hcd {
166 168
167 struct usb_device *udev; 169 struct usb_device *udev;
168 struct list_head urbp_list; 170 struct list_head urbp_list;
171 u32 stream_en_ep;
172 u8 num_stream[30 / 2];
169 173
170 unsigned active:1; 174 unsigned active:1;
171 unsigned old_active:1; 175 unsigned old_active:1;
@@ -178,12 +182,12 @@ struct dummy {
178 /* 182 /*
179 * SLAVE/GADGET side support 183 * SLAVE/GADGET side support
180 */ 184 */
181 struct dummy_ep ep [DUMMY_ENDPOINTS]; 185 struct dummy_ep ep[DUMMY_ENDPOINTS];
182 int address; 186 int address;
183 struct usb_gadget gadget; 187 struct usb_gadget gadget;
184 struct usb_gadget_driver *driver; 188 struct usb_gadget_driver *driver;
185 struct dummy_request fifo_req; 189 struct dummy_request fifo_req;
186 u8 fifo_buf [FIFO_SIZE]; 190 u8 fifo_buf[FIFO_SIZE];
187 u16 devstatus; 191 u16 devstatus;
188 unsigned udc_suspended:1; 192 unsigned udc_suspended:1;
189 unsigned pullup:1; 193 unsigned pullup:1;
@@ -210,14 +214,14 @@ static inline struct device *dummy_dev(struct dummy_hcd *dum)
210 return dummy_hcd_to_hcd(dum)->self.controller; 214 return dummy_hcd_to_hcd(dum)->self.controller;
211} 215}
212 216
213static inline struct device *udc_dev (struct dummy *dum) 217static inline struct device *udc_dev(struct dummy *dum)
214{ 218{
215 return dum->gadget.dev.parent; 219 return dum->gadget.dev.parent;
216} 220}
217 221
218static inline struct dummy *ep_to_dummy (struct dummy_ep *ep) 222static inline struct dummy *ep_to_dummy(struct dummy_ep *ep)
219{ 223{
220 return container_of (ep->gadget, struct dummy, gadget); 224 return container_of(ep->gadget, struct dummy, gadget);
221} 225}
222 226
223static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget) 227static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget)
@@ -229,9 +233,9 @@ static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget)
229 return dum->hs_hcd; 233 return dum->hs_hcd;
230} 234}
231 235
232static inline struct dummy *gadget_dev_to_dummy (struct device *dev) 236static inline struct dummy *gadget_dev_to_dummy(struct device *dev)
233{ 237{
234 return container_of (dev, struct dummy, gadget.dev); 238 return container_of(dev, struct dummy, gadget.dev);
235} 239}
236 240
237static struct dummy the_controller; 241static struct dummy the_controller;
@@ -241,24 +245,23 @@ static struct dummy the_controller;
241/* SLAVE/GADGET SIDE UTILITY ROUTINES */ 245/* SLAVE/GADGET SIDE UTILITY ROUTINES */
242 246
243/* called with spinlock held */ 247/* called with spinlock held */
244static void nuke (struct dummy *dum, struct dummy_ep *ep) 248static void nuke(struct dummy *dum, struct dummy_ep *ep)
245{ 249{
246 while (!list_empty (&ep->queue)) { 250 while (!list_empty(&ep->queue)) {
247 struct dummy_request *req; 251 struct dummy_request *req;
248 252
249 req = list_entry (ep->queue.next, struct dummy_request, queue); 253 req = list_entry(ep->queue.next, struct dummy_request, queue);
250 list_del_init (&req->queue); 254 list_del_init(&req->queue);
251 req->req.status = -ESHUTDOWN; 255 req->req.status = -ESHUTDOWN;
252 256
253 spin_unlock (&dum->lock); 257 spin_unlock(&dum->lock);
254 req->req.complete (&ep->ep, &req->req); 258 req->req.complete(&ep->ep, &req->req);
255 spin_lock (&dum->lock); 259 spin_lock(&dum->lock);
256 } 260 }
257} 261}
258 262
259/* caller must hold lock */ 263/* caller must hold lock */
260static void 264static void stop_activity(struct dummy *dum)
261stop_activity (struct dummy *dum)
262{ 265{
263 struct dummy_ep *ep; 266 struct dummy_ep *ep;
264 267
@@ -268,8 +271,8 @@ stop_activity (struct dummy *dum)
268 /* The timer is left running so that outstanding URBs can fail */ 271 /* The timer is left running so that outstanding URBs can fail */
269 272
270 /* nuke any pending requests first, so driver i/o is quiesced */ 273 /* nuke any pending requests first, so driver i/o is quiesced */
271 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list) 274 list_for_each_entry(ep, &dum->gadget.ep_list, ep.ep_list)
272 nuke (dum, ep); 275 nuke(dum, ep);
273 276
274 /* driver now does any non-usb quiescing necessary */ 277 /* driver now does any non-usb quiescing necessary */
275} 278}
@@ -404,8 +407,8 @@ static void set_link_state(struct dummy_hcd *dum_hcd)
404#define is_enabled(dum) \ 407#define is_enabled(dum) \
405 (dum->port_status & USB_PORT_STAT_ENABLE) 408 (dum->port_status & USB_PORT_STAT_ENABLE)
406 409
407static int 410static int dummy_enable(struct usb_ep *_ep,
408dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) 411 const struct usb_endpoint_descriptor *desc)
409{ 412{
410 struct dummy *dum; 413 struct dummy *dum;
411 struct dummy_hcd *dum_hcd; 414 struct dummy_hcd *dum_hcd;
@@ -413,11 +416,11 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
413 unsigned max; 416 unsigned max;
414 int retval; 417 int retval;
415 418
416 ep = usb_ep_to_dummy_ep (_ep); 419 ep = usb_ep_to_dummy_ep(_ep);
417 if (!_ep || !desc || ep->desc || _ep->name == ep0name 420 if (!_ep || !desc || ep->desc || _ep->name == ep0name
418 || desc->bDescriptorType != USB_DT_ENDPOINT) 421 || desc->bDescriptorType != USB_DT_ENDPOINT)
419 return -EINVAL; 422 return -EINVAL;
420 dum = ep_to_dummy (ep); 423 dum = ep_to_dummy(ep);
421 if (!dum->driver) 424 if (!dum->driver)
422 return -ESHUTDOWN; 425 return -ESHUTDOWN;
423 426
@@ -441,10 +444,10 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
441 * especially for "ep9out" style fixed function ones.) 444 * especially for "ep9out" style fixed function ones.)
442 */ 445 */
443 retval = -EINVAL; 446 retval = -EINVAL;
444 switch (desc->bmAttributes & 0x03) { 447 switch (usb_endpoint_type(desc)) {
445 case USB_ENDPOINT_XFER_BULK: 448 case USB_ENDPOINT_XFER_BULK:
446 if (strstr (ep->ep.name, "-iso") 449 if (strstr(ep->ep.name, "-iso")
447 || strstr (ep->ep.name, "-int")) { 450 || strstr(ep->ep.name, "-int")) {
448 goto done; 451 goto done;
449 } 452 }
450 switch (dum->gadget.speed) { 453 switch (dum->gadget.speed) {
@@ -466,7 +469,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
466 } 469 }
467 break; 470 break;
468 case USB_ENDPOINT_XFER_INT: 471 case USB_ENDPOINT_XFER_INT:
469 if (strstr (ep->ep.name, "-iso")) /* bulk is ok */ 472 if (strstr(ep->ep.name, "-iso")) /* bulk is ok */
470 goto done; 473 goto done;
471 /* real hardware might not handle all packet sizes */ 474 /* real hardware might not handle all packet sizes */
472 switch (dum->gadget.speed) { 475 switch (dum->gadget.speed) {
@@ -486,8 +489,8 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
486 } 489 }
487 break; 490 break;
488 case USB_ENDPOINT_XFER_ISOC: 491 case USB_ENDPOINT_XFER_ISOC:
489 if (strstr (ep->ep.name, "-bulk") 492 if (strstr(ep->ep.name, "-bulk")
490 || strstr (ep->ep.name, "-int")) 493 || strstr(ep->ep.name, "-int"))
491 goto done; 494 goto done;
492 /* real hardware might not handle all packet sizes */ 495 /* real hardware might not handle all packet sizes */
493 switch (dum->gadget.speed) { 496 switch (dum->gadget.speed) {
@@ -510,14 +513,22 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
510 } 513 }
511 514
512 _ep->maxpacket = max; 515 _ep->maxpacket = max;
516 if (usb_ss_max_streams(_ep->comp_desc)) {
517 if (!usb_endpoint_xfer_bulk(desc)) {
518 dev_err(udc_dev(dum), "Can't enable stream support on "
519 "non-bulk ep %s\n", _ep->name);
520 return -EINVAL;
521 }
522 ep->stream_en = 1;
523 }
513 ep->desc = desc; 524 ep->desc = desc;
514 525
515 dev_dbg (udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n", 526 dev_dbg(udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d stream %s\n",
516 _ep->name, 527 _ep->name,
517 desc->bEndpointAddress & 0x0f, 528 desc->bEndpointAddress & 0x0f,
518 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 529 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
519 ({ char *val; 530 ({ char *val;
520 switch (desc->bmAttributes & 0x03) { 531 switch (usb_endpoint_type(desc)) {
521 case USB_ENDPOINT_XFER_BULK: 532 case USB_ENDPOINT_XFER_BULK:
522 val = "bulk"; 533 val = "bulk";
523 break; 534 break;
@@ -531,7 +542,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
531 val = "ctrl"; 542 val = "ctrl";
532 break; 543 break;
533 }; val; }), 544 }; val; }),
534 max); 545 max, ep->stream_en ? "enabled" : "disabled");
535 546
536 /* at this point real hardware should be NAKing transfers 547 /* at this point real hardware should be NAKing transfers
537 * to that endpoint, until a buffer is queued to it. 548 * to that endpoint, until a buffer is queued to it.
@@ -542,67 +553,67 @@ done:
542 return retval; 553 return retval;
543} 554}
544 555
545static int dummy_disable (struct usb_ep *_ep) 556static int dummy_disable(struct usb_ep *_ep)
546{ 557{
547 struct dummy_ep *ep; 558 struct dummy_ep *ep;
548 struct dummy *dum; 559 struct dummy *dum;
549 unsigned long flags; 560 unsigned long flags;
550 int retval; 561 int retval;
551 562
552 ep = usb_ep_to_dummy_ep (_ep); 563 ep = usb_ep_to_dummy_ep(_ep);
553 if (!_ep || !ep->desc || _ep->name == ep0name) 564 if (!_ep || !ep->desc || _ep->name == ep0name)
554 return -EINVAL; 565 return -EINVAL;
555 dum = ep_to_dummy (ep); 566 dum = ep_to_dummy(ep);
556 567
557 spin_lock_irqsave (&dum->lock, flags); 568 spin_lock_irqsave(&dum->lock, flags);
558 ep->desc = NULL; 569 ep->desc = NULL;
570 ep->stream_en = 0;
559 retval = 0; 571 retval = 0;
560 nuke (dum, ep); 572 nuke(dum, ep);
561 spin_unlock_irqrestore (&dum->lock, flags); 573 spin_unlock_irqrestore(&dum->lock, flags);
562 574
563 dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name); 575 dev_dbg(udc_dev(dum), "disabled %s\n", _ep->name);
564 return retval; 576 return retval;
565} 577}
566 578
567static struct usb_request * 579static struct usb_request *dummy_alloc_request(struct usb_ep *_ep,
568dummy_alloc_request (struct usb_ep *_ep, gfp_t mem_flags) 580 gfp_t mem_flags)
569{ 581{
570 struct dummy_ep *ep; 582 struct dummy_ep *ep;
571 struct dummy_request *req; 583 struct dummy_request *req;
572 584
573 if (!_ep) 585 if (!_ep)
574 return NULL; 586 return NULL;
575 ep = usb_ep_to_dummy_ep (_ep); 587 ep = usb_ep_to_dummy_ep(_ep);
576 588
577 req = kzalloc(sizeof(*req), mem_flags); 589 req = kzalloc(sizeof(*req), mem_flags);
578 if (!req) 590 if (!req)
579 return NULL; 591 return NULL;
580 INIT_LIST_HEAD (&req->queue); 592 INIT_LIST_HEAD(&req->queue);
581 return &req->req; 593 return &req->req;
582} 594}
583 595
584static void 596static void dummy_free_request(struct usb_ep *_ep, struct usb_request *_req)
585dummy_free_request (struct usb_ep *_ep, struct usb_request *_req)
586{ 597{
587 struct dummy_ep *ep; 598 struct dummy_ep *ep;
588 struct dummy_request *req; 599 struct dummy_request *req;
589 600
590 ep = usb_ep_to_dummy_ep (_ep); 601 if (!_ep || !_req)
591 if (!ep || !_req || (!ep->desc && _ep->name != ep0name)) 602 return;
603 ep = usb_ep_to_dummy_ep(_ep);
604 if (!ep->desc && _ep->name != ep0name)
592 return; 605 return;
593 606
594 req = usb_request_to_dummy_request (_req); 607 req = usb_request_to_dummy_request(_req);
595 WARN_ON (!list_empty (&req->queue)); 608 WARN_ON(!list_empty(&req->queue));
596 kfree (req); 609 kfree(req);
597} 610}
598 611
599static void 612static void fifo_complete(struct usb_ep *ep, struct usb_request *req)
600fifo_complete (struct usb_ep *ep, struct usb_request *req)
601{ 613{
602} 614}
603 615
604static int 616static int dummy_queue(struct usb_ep *_ep, struct usb_request *_req,
605dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
606 gfp_t mem_flags) 617 gfp_t mem_flags)
607{ 618{
608 struct dummy_ep *ep; 619 struct dummy_ep *ep;
@@ -611,49 +622,48 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
611 struct dummy_hcd *dum_hcd; 622 struct dummy_hcd *dum_hcd;
612 unsigned long flags; 623 unsigned long flags;
613 624
614 req = usb_request_to_dummy_request (_req); 625 req = usb_request_to_dummy_request(_req);
615 if (!_req || !list_empty (&req->queue) || !_req->complete) 626 if (!_req || !list_empty(&req->queue) || !_req->complete)
616 return -EINVAL; 627 return -EINVAL;
617 628
618 ep = usb_ep_to_dummy_ep (_ep); 629 ep = usb_ep_to_dummy_ep(_ep);
619 if (!_ep || (!ep->desc && _ep->name != ep0name)) 630 if (!_ep || (!ep->desc && _ep->name != ep0name))
620 return -EINVAL; 631 return -EINVAL;
621 632
622 dum = ep_to_dummy (ep); 633 dum = ep_to_dummy(ep);
623 dum_hcd = gadget_to_dummy_hcd(&dum->gadget); 634 dum_hcd = gadget_to_dummy_hcd(&dum->gadget);
624 if (!dum->driver || !is_enabled(dum_hcd)) 635 if (!dum->driver || !is_enabled(dum_hcd))
625 return -ESHUTDOWN; 636 return -ESHUTDOWN;
626 637
627#if 0 638#if 0
628 dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", 639 dev_dbg(udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n",
629 ep, _req, _ep->name, _req->length, _req->buf); 640 ep, _req, _ep->name, _req->length, _req->buf);
630#endif 641#endif
631
632 _req->status = -EINPROGRESS; 642 _req->status = -EINPROGRESS;
633 _req->actual = 0; 643 _req->actual = 0;
634 spin_lock_irqsave (&dum->lock, flags); 644 spin_lock_irqsave(&dum->lock, flags);
635 645
636 /* implement an emulated single-request FIFO */ 646 /* implement an emulated single-request FIFO */
637 if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) && 647 if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) &&
638 list_empty (&dum->fifo_req.queue) && 648 list_empty(&dum->fifo_req.queue) &&
639 list_empty (&ep->queue) && 649 list_empty(&ep->queue) &&
640 _req->length <= FIFO_SIZE) { 650 _req->length <= FIFO_SIZE) {
641 req = &dum->fifo_req; 651 req = &dum->fifo_req;
642 req->req = *_req; 652 req->req = *_req;
643 req->req.buf = dum->fifo_buf; 653 req->req.buf = dum->fifo_buf;
644 memcpy (dum->fifo_buf, _req->buf, _req->length); 654 memcpy(dum->fifo_buf, _req->buf, _req->length);
645 req->req.context = dum; 655 req->req.context = dum;
646 req->req.complete = fifo_complete; 656 req->req.complete = fifo_complete;
647 657
648 list_add_tail(&req->queue, &ep->queue); 658 list_add_tail(&req->queue, &ep->queue);
649 spin_unlock (&dum->lock); 659 spin_unlock(&dum->lock);
650 _req->actual = _req->length; 660 _req->actual = _req->length;
651 _req->status = 0; 661 _req->status = 0;
652 _req->complete (_ep, _req); 662 _req->complete(_ep, _req);
653 spin_lock (&dum->lock); 663 spin_lock(&dum->lock);
654 } else 664 } else
655 list_add_tail(&req->queue, &ep->queue); 665 list_add_tail(&req->queue, &ep->queue);
656 spin_unlock_irqrestore (&dum->lock, flags); 666 spin_unlock_irqrestore(&dum->lock, flags);
657 667
658 /* real hardware would likely enable transfers here, in case 668 /* real hardware would likely enable transfers here, in case
659 * it'd been left NAKing. 669 * it'd been left NAKing.
@@ -661,7 +671,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
661 return 0; 671 return 0;
662} 672}
663 673
664static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req) 674static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req)
665{ 675{
666 struct dummy_ep *ep; 676 struct dummy_ep *ep;
667 struct dummy *dum; 677 struct dummy *dum;
@@ -671,31 +681,31 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
671 681
672 if (!_ep || !_req) 682 if (!_ep || !_req)
673 return retval; 683 return retval;
674 ep = usb_ep_to_dummy_ep (_ep); 684 ep = usb_ep_to_dummy_ep(_ep);
675 dum = ep_to_dummy (ep); 685 dum = ep_to_dummy(ep);
676 686
677 if (!dum->driver) 687 if (!dum->driver)
678 return -ESHUTDOWN; 688 return -ESHUTDOWN;
679 689
680 local_irq_save (flags); 690 local_irq_save(flags);
681 spin_lock (&dum->lock); 691 spin_lock(&dum->lock);
682 list_for_each_entry (req, &ep->queue, queue) { 692 list_for_each_entry(req, &ep->queue, queue) {
683 if (&req->req == _req) { 693 if (&req->req == _req) {
684 list_del_init (&req->queue); 694 list_del_init(&req->queue);
685 _req->status = -ECONNRESET; 695 _req->status = -ECONNRESET;
686 retval = 0; 696 retval = 0;
687 break; 697 break;
688 } 698 }
689 } 699 }
690 spin_unlock (&dum->lock); 700 spin_unlock(&dum->lock);
691 701
692 if (retval == 0) { 702 if (retval == 0) {
693 dev_dbg (udc_dev(dum), 703 dev_dbg(udc_dev(dum),
694 "dequeued req %p from %s, len %d buf %p\n", 704 "dequeued req %p from %s, len %d buf %p\n",
695 req, _ep->name, _req->length, _req->buf); 705 req, _ep->name, _req->length, _req->buf);
696 _req->complete (_ep, _req); 706 _req->complete(_ep, _req);
697 } 707 }
698 local_irq_restore (flags); 708 local_irq_restore(flags);
699 return retval; 709 return retval;
700} 710}
701 711
@@ -707,14 +717,14 @@ dummy_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
707 717
708 if (!_ep) 718 if (!_ep)
709 return -EINVAL; 719 return -EINVAL;
710 ep = usb_ep_to_dummy_ep (_ep); 720 ep = usb_ep_to_dummy_ep(_ep);
711 dum = ep_to_dummy (ep); 721 dum = ep_to_dummy(ep);
712 if (!dum->driver) 722 if (!dum->driver)
713 return -ESHUTDOWN; 723 return -ESHUTDOWN;
714 if (!value) 724 if (!value)
715 ep->halted = ep->wedged = 0; 725 ep->halted = ep->wedged = 0;
716 else if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) && 726 else if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) &&
717 !list_empty (&ep->queue)) 727 !list_empty(&ep->queue))
718 return -EAGAIN; 728 return -EAGAIN;
719 else { 729 else {
720 ep->halted = 1; 730 ep->halted = 1;
@@ -755,15 +765,15 @@ static const struct usb_ep_ops dummy_ep_ops = {
755/*-------------------------------------------------------------------------*/ 765/*-------------------------------------------------------------------------*/
756 766
757/* there are both host and device side versions of this call ... */ 767/* there are both host and device side versions of this call ... */
758static int dummy_g_get_frame (struct usb_gadget *_gadget) 768static int dummy_g_get_frame(struct usb_gadget *_gadget)
759{ 769{
760 struct timeval tv; 770 struct timeval tv;
761 771
762 do_gettimeofday (&tv); 772 do_gettimeofday(&tv);
763 return tv.tv_usec / 1000; 773 return tv.tv_usec / 1000;
764} 774}
765 775
766static int dummy_wakeup (struct usb_gadget *_gadget) 776static int dummy_wakeup(struct usb_gadget *_gadget)
767{ 777{
768 struct dummy_hcd *dum_hcd; 778 struct dummy_hcd *dum_hcd;
769 779
@@ -786,11 +796,11 @@ static int dummy_wakeup (struct usb_gadget *_gadget)
786 return 0; 796 return 0;
787} 797}
788 798
789static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value) 799static int dummy_set_selfpowered(struct usb_gadget *_gadget, int value)
790{ 800{
791 struct dummy *dum; 801 struct dummy *dum;
792 802
793 dum = (gadget_to_dummy_hcd(_gadget))->dum; 803 dum = gadget_to_dummy_hcd(_gadget)->dum;
794 if (value) 804 if (value)
795 dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED); 805 dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED);
796 else 806 else
@@ -798,22 +808,15 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value)
798 return 0; 808 return 0;
799} 809}
800 810
801static void dummy_udc_udpate_ep0(struct dummy *dum) 811static void dummy_udc_update_ep0(struct dummy *dum)
802{ 812{
803 u32 i; 813 if (dum->gadget.speed == USB_SPEED_SUPER)
804
805 if (dum->gadget.speed == USB_SPEED_SUPER) {
806 for (i = 0; i < DUMMY_ENDPOINTS; i++)
807 dum->ep[i].ep.max_streams = 0x10;
808 dum->ep[0].ep.maxpacket = 9; 814 dum->ep[0].ep.maxpacket = 9;
809 } else { 815 else
810 for (i = 0; i < DUMMY_ENDPOINTS; i++)
811 dum->ep[i].ep.max_streams = 0;
812 dum->ep[0].ep.maxpacket = 64; 816 dum->ep[0].ep.maxpacket = 64;
813 }
814} 817}
815 818
816static int dummy_pullup (struct usb_gadget *_gadget, int value) 819static int dummy_pullup(struct usb_gadget *_gadget, int value)
817{ 820{
818 struct dummy_hcd *dum_hcd; 821 struct dummy_hcd *dum_hcd;
819 struct dummy *dum; 822 struct dummy *dum;
@@ -829,7 +832,7 @@ static int dummy_pullup (struct usb_gadget *_gadget, int value)
829 dum->driver->max_speed); 832 dum->driver->max_speed);
830 else 833 else
831 dum->gadget.speed = USB_SPEED_FULL; 834 dum->gadget.speed = USB_SPEED_FULL;
832 dummy_udc_udpate_ep0(dum); 835 dummy_udc_update_ep0(dum);
833 836
834 if (dum->gadget.speed < dum->driver->max_speed) 837 if (dum->gadget.speed < dum->driver->max_speed)
835 dev_dbg(udc_dev(dum), "This device can perform faster" 838 dev_dbg(udc_dev(dum), "This device can perform faster"
@@ -838,10 +841,10 @@ static int dummy_pullup (struct usb_gadget *_gadget, int value)
838 } 841 }
839 dum_hcd = gadget_to_dummy_hcd(_gadget); 842 dum_hcd = gadget_to_dummy_hcd(_gadget);
840 843
841 spin_lock_irqsave (&dum->lock, flags); 844 spin_lock_irqsave(&dum->lock, flags);
842 dum->pullup = (value != 0); 845 dum->pullup = (value != 0);
843 set_link_state(dum_hcd); 846 set_link_state(dum_hcd);
844 spin_unlock_irqrestore (&dum->lock, flags); 847 spin_unlock_irqrestore(&dum->lock, flags);
845 848
846 usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd)); 849 usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd));
847 return 0; 850 return 0;
@@ -864,16 +867,16 @@ static const struct usb_gadget_ops dummy_ops = {
864/*-------------------------------------------------------------------------*/ 867/*-------------------------------------------------------------------------*/
865 868
866/* "function" sysfs attribute */ 869/* "function" sysfs attribute */
867static ssize_t 870static ssize_t show_function(struct device *dev, struct device_attribute *attr,
868show_function (struct device *dev, struct device_attribute *attr, char *buf) 871 char *buf)
869{ 872{
870 struct dummy *dum = gadget_dev_to_dummy (dev); 873 struct dummy *dum = gadget_dev_to_dummy(dev);
871 874
872 if (!dum->driver || !dum->driver->function) 875 if (!dum->driver || !dum->driver->function)
873 return 0; 876 return 0;
874 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function); 877 return scnprintf(buf, PAGE_SIZE, "%s\n", dum->driver->function);
875} 878}
876static DEVICE_ATTR (function, S_IRUGO, show_function, NULL); 879static DEVICE_ATTR(function, S_IRUGO, show_function, NULL);
877 880
878/*-------------------------------------------------------------------------*/ 881/*-------------------------------------------------------------------------*/
879 882
@@ -908,7 +911,7 @@ static int dummy_udc_start(struct usb_gadget *g,
908 dum->devstatus = 0; 911 dum->devstatus = 0;
909 912
910 dum->driver = driver; 913 dum->driver = driver;
911 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 914 dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n",
912 driver->driver.name); 915 driver->driver.name);
913 return 0; 916 return 0;
914} 917}
@@ -919,7 +922,7 @@ static int dummy_udc_stop(struct usb_gadget *g,
919 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g); 922 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
920 struct dummy *dum = dum_hcd->dum; 923 struct dummy *dum = dum_hcd->dum;
921 924
922 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", 925 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n",
923 driver->driver.name); 926 driver->driver.name);
924 927
925 dum->driver = NULL; 928 dum->driver = NULL;
@@ -932,8 +935,7 @@ static int dummy_udc_stop(struct usb_gadget *g,
932 935
933/* The gadget structure is stored inside the hcd structure and will be 936/* The gadget structure is stored inside the hcd structure and will be
934 * released along with it. */ 937 * released along with it. */
935static void 938static void dummy_gadget_release(struct device *dev)
936dummy_gadget_release (struct device *dev)
937{ 939{
938 return; 940 return;
939} 941}
@@ -954,6 +956,7 @@ static void init_dummy_udc_hw(struct dummy *dum)
954 ep->halted = ep->wedged = ep->already_seen = 956 ep->halted = ep->wedged = ep->already_seen =
955 ep->setup_stage = 0; 957 ep->setup_stage = 0;
956 ep->ep.maxpacket = ~0; 958 ep->ep.maxpacket = ~0;
959 ep->ep.max_streams = 16;
957 ep->last_io = jiffies; 960 ep->last_io = jiffies;
958 ep->gadget = &dum->gadget; 961 ep->gadget = &dum->gadget;
959 ep->desc = NULL; 962 ep->desc = NULL;
@@ -969,7 +972,7 @@ static void init_dummy_udc_hw(struct dummy *dum)
969#endif 972#endif
970} 973}
971 974
972static int dummy_udc_probe (struct platform_device *pdev) 975static int dummy_udc_probe(struct platform_device *pdev)
973{ 976{
974 struct dummy *dum = &the_controller; 977 struct dummy *dum = &the_controller;
975 int rc; 978 int rc;
@@ -981,7 +984,7 @@ static int dummy_udc_probe (struct platform_device *pdev)
981 dev_set_name(&dum->gadget.dev, "gadget"); 984 dev_set_name(&dum->gadget.dev, "gadget");
982 dum->gadget.dev.parent = &pdev->dev; 985 dum->gadget.dev.parent = &pdev->dev;
983 dum->gadget.dev.release = dummy_gadget_release; 986 dum->gadget.dev.release = dummy_gadget_release;
984 rc = device_register (&dum->gadget.dev); 987 rc = device_register(&dum->gadget.dev);
985 if (rc < 0) { 988 if (rc < 0) {
986 put_device(&dum->gadget.dev); 989 put_device(&dum->gadget.dev);
987 return rc; 990 return rc;
@@ -993,7 +996,7 @@ static int dummy_udc_probe (struct platform_device *pdev)
993 if (rc < 0) 996 if (rc < 0)
994 goto err_udc; 997 goto err_udc;
995 998
996 rc = device_create_file (&dum->gadget.dev, &dev_attr_function); 999 rc = device_create_file(&dum->gadget.dev, &dev_attr_function);
997 if (rc < 0) 1000 if (rc < 0)
998 goto err_dev; 1001 goto err_dev;
999 platform_set_drvdata(pdev, dum); 1002 platform_set_drvdata(pdev, dum);
@@ -1006,14 +1009,14 @@ err_udc:
1006 return rc; 1009 return rc;
1007} 1010}
1008 1011
1009static int dummy_udc_remove (struct platform_device *pdev) 1012static int dummy_udc_remove(struct platform_device *pdev)
1010{ 1013{
1011 struct dummy *dum = platform_get_drvdata (pdev); 1014 struct dummy *dum = platform_get_drvdata(pdev);
1012 1015
1013 usb_del_gadget_udc(&dum->gadget); 1016 usb_del_gadget_udc(&dum->gadget);
1014 platform_set_drvdata (pdev, NULL); 1017 platform_set_drvdata(pdev, NULL);
1015 device_remove_file (&dum->gadget.dev, &dev_attr_function); 1018 device_remove_file(&dum->gadget.dev, &dev_attr_function);
1016 device_unregister (&dum->gadget.dev); 1019 device_unregister(&dum->gadget.dev);
1017 return 0; 1020 return 0;
1018} 1021}
1019 1022
@@ -1061,6 +1064,16 @@ static struct platform_driver dummy_udc_driver = {
1061 1064
1062/*-------------------------------------------------------------------------*/ 1065/*-------------------------------------------------------------------------*/
1063 1066
1067static unsigned int dummy_get_ep_idx(const struct usb_endpoint_descriptor *desc)
1068{
1069 unsigned int index;
1070
1071 index = usb_endpoint_num(desc) << 1;
1072 if (usb_endpoint_dir_in(desc))
1073 index |= 1;
1074 return index;
1075}
1076
1064/* MASTER/HOST SIDE DRIVER 1077/* MASTER/HOST SIDE DRIVER
1065 * 1078 *
1066 * this uses the hcd framework to hook up to host side drivers. 1079 * this uses the hcd framework to hook up to host side drivers.
@@ -1073,7 +1086,82 @@ static struct platform_driver dummy_udc_driver = {
1073 * usb 2.0 rules. 1086 * usb 2.0 rules.
1074 */ 1087 */
1075 1088
1076static int dummy_urb_enqueue ( 1089static int dummy_ep_stream_en(struct dummy_hcd *dum_hcd, struct urb *urb)
1090{
1091 const struct usb_endpoint_descriptor *desc = &urb->ep->desc;
1092 u32 index;
1093
1094 if (!usb_endpoint_xfer_bulk(desc))
1095 return 0;
1096
1097 index = dummy_get_ep_idx(desc);
1098 return (1 << index) & dum_hcd->stream_en_ep;
1099}
1100
1101/*
1102 * The max stream number is saved as a nibble so for the 30 possible endpoints
1103 * we only 15 bytes of memory. Therefore we are limited to max 16 streams (0
1104 * means we use only 1 stream). The maximum according to the spec is 16bit so
1105 * if the 16 stream limit is about to go, the array size should be incremented
1106 * to 30 elements of type u16.
1107 */
1108static int get_max_streams_for_pipe(struct dummy_hcd *dum_hcd,
1109 unsigned int pipe)
1110{
1111 int max_streams;
1112
1113 max_streams = dum_hcd->num_stream[usb_pipeendpoint(pipe)];
1114 if (usb_pipeout(pipe))
1115 max_streams >>= 4;
1116 else
1117 max_streams &= 0xf;
1118 max_streams++;
1119 return max_streams;
1120}
1121
1122static void set_max_streams_for_pipe(struct dummy_hcd *dum_hcd,
1123 unsigned int pipe, unsigned int streams)
1124{
1125 int max_streams;
1126
1127 streams--;
1128 max_streams = dum_hcd->num_stream[usb_pipeendpoint(pipe)];
1129 if (usb_pipeout(pipe)) {
1130 streams <<= 4;
1131 max_streams &= 0xf;
1132 } else {
1133 max_streams &= 0xf0;
1134 }
1135 max_streams |= streams;
1136 dum_hcd->num_stream[usb_pipeendpoint(pipe)] = max_streams;
1137}
1138
1139static int dummy_validate_stream(struct dummy_hcd *dum_hcd, struct urb *urb)
1140{
1141 unsigned int max_streams;
1142 int enabled;
1143
1144 enabled = dummy_ep_stream_en(dum_hcd, urb);
1145 if (!urb->stream_id) {
1146 if (enabled)
1147 return -EINVAL;
1148 return 0;
1149 }
1150 if (!enabled)
1151 return -EINVAL;
1152
1153 max_streams = get_max_streams_for_pipe(dum_hcd,
1154 usb_pipeendpoint(urb->pipe));
1155 if (urb->stream_id > max_streams) {
1156 dev_err(dummy_dev(dum_hcd), "Stream id %d is out of range.\n",
1157 urb->stream_id);
1158 BUG();
1159 return -EINVAL;
1160 }
1161 return 0;
1162}
1163
1164static int dummy_urb_enqueue(
1077 struct usb_hcd *hcd, 1165 struct usb_hcd *hcd,
1078 struct urb *urb, 1166 struct urb *urb,
1079 gfp_t mem_flags 1167 gfp_t mem_flags
@@ -1083,16 +1171,21 @@ static int dummy_urb_enqueue (
1083 unsigned long flags; 1171 unsigned long flags;
1084 int rc; 1172 int rc;
1085 1173
1086 if (!urb->transfer_buffer && urb->transfer_buffer_length) 1174 urbp = kmalloc(sizeof *urbp, mem_flags);
1087 return -EINVAL;
1088
1089 urbp = kmalloc (sizeof *urbp, mem_flags);
1090 if (!urbp) 1175 if (!urbp)
1091 return -ENOMEM; 1176 return -ENOMEM;
1092 urbp->urb = urb; 1177 urbp->urb = urb;
1178 urbp->miter_started = 0;
1093 1179
1094 dum_hcd = hcd_to_dummy_hcd(hcd); 1180 dum_hcd = hcd_to_dummy_hcd(hcd);
1095 spin_lock_irqsave(&dum_hcd->dum->lock, flags); 1181 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1182
1183 rc = dummy_validate_stream(dum_hcd, urb);
1184 if (rc) {
1185 kfree(urbp);
1186 goto done;
1187 }
1188
1096 rc = usb_hcd_link_urb_to_ep(hcd, urb); 1189 rc = usb_hcd_link_urb_to_ep(hcd, urb);
1097 if (rc) { 1190 if (rc) {
1098 kfree(urbp); 1191 kfree(urbp);
@@ -1107,7 +1200,7 @@ static int dummy_urb_enqueue (
1107 1200
1108 list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list); 1201 list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list);
1109 urb->hcpriv = urbp; 1202 urb->hcpriv = urbp;
1110 if (usb_pipetype (urb->pipe) == PIPE_CONTROL) 1203 if (usb_pipetype(urb->pipe) == PIPE_CONTROL)
1111 urb->error_count = 1; /* mark as a new urb */ 1204 urb->error_count = 1; /* mark as a new urb */
1112 1205
1113 /* kick the scheduler, it'll do the rest */ 1206 /* kick the scheduler, it'll do the rest */
@@ -1139,20 +1232,91 @@ static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1139 return rc; 1232 return rc;
1140} 1233}
1141 1234
1235static int dummy_perform_transfer(struct urb *urb, struct dummy_request *req,
1236 u32 len)
1237{
1238 void *ubuf, *rbuf;
1239 struct urbp *urbp = urb->hcpriv;
1240 int to_host;
1241 struct sg_mapping_iter *miter = &urbp->miter;
1242 u32 trans = 0;
1243 u32 this_sg;
1244 bool next_sg;
1245
1246 to_host = usb_pipein(urb->pipe);
1247 rbuf = req->req.buf + req->req.actual;
1248
1249 if (!urb->num_sgs) {
1250 ubuf = urb->transfer_buffer + urb->actual_length;
1251 if (to_host)
1252 memcpy(ubuf, rbuf, len);
1253 else
1254 memcpy(rbuf, ubuf, len);
1255 return len;
1256 }
1257
1258 if (!urbp->miter_started) {
1259 u32 flags = SG_MITER_ATOMIC;
1260
1261 if (to_host)
1262 flags |= SG_MITER_TO_SG;
1263 else
1264 flags |= SG_MITER_FROM_SG;
1265
1266 sg_miter_start(miter, urb->sg, urb->num_sgs, flags);
1267 urbp->miter_started = 1;
1268 }
1269 next_sg = sg_miter_next(miter);
1270 if (next_sg == false) {
1271 WARN_ON_ONCE(1);
1272 return -EINVAL;
1273 }
1274 do {
1275 ubuf = miter->addr;
1276 this_sg = min_t(u32, len, miter->length);
1277 miter->consumed = this_sg;
1278 trans += this_sg;
1279
1280 if (to_host)
1281 memcpy(ubuf, rbuf, this_sg);
1282 else
1283 memcpy(rbuf, ubuf, this_sg);
1284 len -= this_sg;
1285
1286 if (!len)
1287 break;
1288 next_sg = sg_miter_next(miter);
1289 if (next_sg == false) {
1290 WARN_ON_ONCE(1);
1291 return -EINVAL;
1292 }
1293
1294 rbuf += this_sg;
1295 } while (1);
1296
1297 sg_miter_stop(miter);
1298 return trans;
1299}
1300
1142/* transfer up to a frame's worth; caller must own lock */ 1301/* transfer up to a frame's worth; caller must own lock */
1143static int 1302static int transfer(struct dummy_hcd *dum_hcd, struct urb *urb,
1144transfer(struct dummy *dum, struct urb *urb, struct dummy_ep *ep, int limit, 1303 struct dummy_ep *ep, int limit, int *status)
1145 int *status)
1146{ 1304{
1305 struct dummy *dum = dum_hcd->dum;
1147 struct dummy_request *req; 1306 struct dummy_request *req;
1148 1307
1149top: 1308top:
1150 /* if there's no request queued, the device is NAKing; return */ 1309 /* if there's no request queued, the device is NAKing; return */
1151 list_for_each_entry (req, &ep->queue, queue) { 1310 list_for_each_entry(req, &ep->queue, queue) {
1152 unsigned host_len, dev_len, len; 1311 unsigned host_len, dev_len, len;
1153 int is_short, to_host; 1312 int is_short, to_host;
1154 int rescan = 0; 1313 int rescan = 0;
1155 1314
1315 if (dummy_ep_stream_en(dum_hcd, urb)) {
1316 if ((urb->stream_id != req->req.stream_id))
1317 continue;
1318 }
1319
1156 /* 1..N packets of ep->ep.maxpacket each ... the last one 1320 /* 1..N packets of ep->ep.maxpacket each ... the last one
1157 * may be short (including zero length). 1321 * may be short (including zero length).
1158 * 1322 *
@@ -1162,20 +1326,18 @@ top:
1162 */ 1326 */
1163 host_len = urb->transfer_buffer_length - urb->actual_length; 1327 host_len = urb->transfer_buffer_length - urb->actual_length;
1164 dev_len = req->req.length - req->req.actual; 1328 dev_len = req->req.length - req->req.actual;
1165 len = min (host_len, dev_len); 1329 len = min(host_len, dev_len);
1166 1330
1167 /* FIXME update emulated data toggle too */ 1331 /* FIXME update emulated data toggle too */
1168 1332
1169 to_host = usb_pipein (urb->pipe); 1333 to_host = usb_pipein(urb->pipe);
1170 if (unlikely (len == 0)) 1334 if (unlikely(len == 0))
1171 is_short = 1; 1335 is_short = 1;
1172 else { 1336 else {
1173 char *ubuf, *rbuf;
1174
1175 /* not enough bandwidth left? */ 1337 /* not enough bandwidth left? */
1176 if (limit < ep->ep.maxpacket && limit < len) 1338 if (limit < ep->ep.maxpacket && limit < len)
1177 break; 1339 break;
1178 len = min (len, (unsigned) limit); 1340 len = min_t(unsigned, len, limit);
1179 if (len == 0) 1341 if (len == 0)
1180 break; 1342 break;
1181 1343
@@ -1186,18 +1348,16 @@ top:
1186 } 1348 }
1187 is_short = (len % ep->ep.maxpacket) != 0; 1349 is_short = (len % ep->ep.maxpacket) != 0;
1188 1350
1189 /* else transfer packet(s) */ 1351 len = dummy_perform_transfer(urb, req, len);
1190 ubuf = urb->transfer_buffer + urb->actual_length;
1191 rbuf = req->req.buf + req->req.actual;
1192 if (to_host)
1193 memcpy (ubuf, rbuf, len);
1194 else
1195 memcpy (rbuf, ubuf, len);
1196 ep->last_io = jiffies;
1197 1352
1198 limit -= len; 1353 ep->last_io = jiffies;
1199 urb->actual_length += len; 1354 if ((int)len < 0) {
1200 req->req.actual += len; 1355 req->req.status = len;
1356 } else {
1357 limit -= len;
1358 urb->actual_length += len;
1359 req->req.actual += len;
1360 }
1201 } 1361 }
1202 1362
1203 /* short packets terminate, maybe with overflow/underflow. 1363 /* short packets terminate, maybe with overflow/underflow.
@@ -1238,11 +1398,11 @@ top:
1238 1398
1239 /* device side completion --> continuable */ 1399 /* device side completion --> continuable */
1240 if (req->req.status != -EINPROGRESS) { 1400 if (req->req.status != -EINPROGRESS) {
1241 list_del_init (&req->queue); 1401 list_del_init(&req->queue);
1242 1402
1243 spin_unlock (&dum->lock); 1403 spin_unlock(&dum->lock);
1244 req->req.complete (&ep->ep, &req->req); 1404 req->req.complete(&ep->ep, &req->req);
1245 spin_lock (&dum->lock); 1405 spin_lock(&dum->lock);
1246 1406
1247 /* requests might have been unlinked... */ 1407 /* requests might have been unlinked... */
1248 rescan = 1; 1408 rescan = 1;
@@ -1259,7 +1419,7 @@ top:
1259 return limit; 1419 return limit;
1260} 1420}
1261 1421
1262static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep) 1422static int periodic_bytes(struct dummy *dum, struct dummy_ep *ep)
1263{ 1423{
1264 int limit = ep->ep.maxpacket; 1424 int limit = ep->ep.maxpacket;
1265 1425
@@ -1273,7 +1433,7 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1273 limit += limit * tmp; 1433 limit += limit * tmp;
1274 } 1434 }
1275 if (dum->gadget.speed == USB_SPEED_SUPER) { 1435 if (dum->gadget.speed == USB_SPEED_SUPER) {
1276 switch (ep->desc->bmAttributes & 0x03) { 1436 switch (usb_endpoint_type(ep->desc)) {
1277 case USB_ENDPOINT_XFER_ISOC: 1437 case USB_ENDPOINT_XFER_ISOC:
1278 /* Sec. 4.4.8.2 USB3.0 Spec */ 1438 /* Sec. 4.4.8.2 USB3.0 Spec */
1279 limit = 3 * 16 * 1024 * 8; 1439 limit = 3 * 16 * 1024 * 8;
@@ -1295,7 +1455,7 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1295 USB_PORT_STAT_SUSPEND)) \ 1455 USB_PORT_STAT_SUSPEND)) \
1296 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE)) 1456 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE))
1297 1457
1298static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address) 1458static struct dummy_ep *find_endpoint(struct dummy *dum, u8 address)
1299{ 1459{
1300 int i; 1460 int i;
1301 1461
@@ -1303,9 +1463,9 @@ static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address)
1303 dum->ss_hcd : dum->hs_hcd))) 1463 dum->ss_hcd : dum->hs_hcd)))
1304 return NULL; 1464 return NULL;
1305 if ((address & ~USB_DIR_IN) == 0) 1465 if ((address & ~USB_DIR_IN) == 0)
1306 return &dum->ep [0]; 1466 return &dum->ep[0];
1307 for (i = 1; i < DUMMY_ENDPOINTS; i++) { 1467 for (i = 1; i < DUMMY_ENDPOINTS; i++) {
1308 struct dummy_ep *ep = &dum->ep [i]; 1468 struct dummy_ep *ep = &dum->ep[i];
1309 1469
1310 if (!ep->desc) 1470 if (!ep->desc)
1311 continue; 1471 continue;
@@ -1535,19 +1695,19 @@ static void dummy_timer(unsigned long _dum_hcd)
1535 /* FIXME if HZ != 1000 this will probably misbehave ... */ 1695 /* FIXME if HZ != 1000 this will probably misbehave ... */
1536 1696
1537 /* look at each urb queued by the host side driver */ 1697 /* look at each urb queued by the host side driver */
1538 spin_lock_irqsave (&dum->lock, flags); 1698 spin_lock_irqsave(&dum->lock, flags);
1539 1699
1540 if (!dum_hcd->udev) { 1700 if (!dum_hcd->udev) {
1541 dev_err(dummy_dev(dum_hcd), 1701 dev_err(dummy_dev(dum_hcd),
1542 "timer fired with no URBs pending?\n"); 1702 "timer fired with no URBs pending?\n");
1543 spin_unlock_irqrestore (&dum->lock, flags); 1703 spin_unlock_irqrestore(&dum->lock, flags);
1544 return; 1704 return;
1545 } 1705 }
1546 1706
1547 for (i = 0; i < DUMMY_ENDPOINTS; i++) { 1707 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
1548 if (!ep_name [i]) 1708 if (!ep_name[i])
1549 break; 1709 break;
1550 dum->ep [i].already_seen = 0; 1710 dum->ep[i].already_seen = 0;
1551 } 1711 }
1552 1712
1553restart: 1713restart:
@@ -1564,7 +1724,7 @@ restart:
1564 goto return_urb; 1724 goto return_urb;
1565 else if (dum_hcd->rh_state != DUMMY_RH_RUNNING) 1725 else if (dum_hcd->rh_state != DUMMY_RH_RUNNING)
1566 continue; 1726 continue;
1567 type = usb_pipetype (urb->pipe); 1727 type = usb_pipetype(urb->pipe);
1568 1728
1569 /* used up this frame's non-periodic bandwidth? 1729 /* used up this frame's non-periodic bandwidth?
1570 * FIXME there's infinite bandwidth for control and 1730 * FIXME there's infinite bandwidth for control and
@@ -1575,7 +1735,7 @@ restart:
1575 1735
1576 /* find the gadget's ep for this request (if configured) */ 1736 /* find the gadget's ep for this request (if configured) */
1577 address = usb_pipeendpoint (urb->pipe); 1737 address = usb_pipeendpoint (urb->pipe);
1578 if (usb_pipein (urb->pipe)) 1738 if (usb_pipein(urb->pipe))
1579 address |= USB_DIR_IN; 1739 address |= USB_DIR_IN;
1580 ep = find_endpoint(dum, address); 1740 ep = find_endpoint(dum, address);
1581 if (!ep) { 1741 if (!ep) {
@@ -1590,7 +1750,7 @@ restart:
1590 if (ep->already_seen) 1750 if (ep->already_seen)
1591 continue; 1751 continue;
1592 ep->already_seen = 1; 1752 ep->already_seen = 1;
1593 if (ep == &dum->ep [0] && urb->error_count) { 1753 if (ep == &dum->ep[0] && urb->error_count) {
1594 ep->setup_stage = 1; /* a new urb */ 1754 ep->setup_stage = 1; /* a new urb */
1595 urb->error_count = 0; 1755 urb->error_count = 0;
1596 } 1756 }
@@ -1604,21 +1764,21 @@ restart:
1604 /* FIXME make sure both ends agree on maxpacket */ 1764 /* FIXME make sure both ends agree on maxpacket */
1605 1765
1606 /* handle control requests */ 1766 /* handle control requests */
1607 if (ep == &dum->ep [0] && ep->setup_stage) { 1767 if (ep == &dum->ep[0] && ep->setup_stage) {
1608 struct usb_ctrlrequest setup; 1768 struct usb_ctrlrequest setup;
1609 int value = 1; 1769 int value = 1;
1610 1770
1611 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1771 setup = *(struct usb_ctrlrequest *) urb->setup_packet;
1612 /* paranoia, in case of stale queued data */ 1772 /* paranoia, in case of stale queued data */
1613 list_for_each_entry (req, &ep->queue, queue) { 1773 list_for_each_entry(req, &ep->queue, queue) {
1614 list_del_init (&req->queue); 1774 list_del_init(&req->queue);
1615 req->req.status = -EOVERFLOW; 1775 req->req.status = -EOVERFLOW;
1616 dev_dbg (udc_dev(dum), "stale req = %p\n", 1776 dev_dbg(udc_dev(dum), "stale req = %p\n",
1617 req); 1777 req);
1618 1778
1619 spin_unlock (&dum->lock); 1779 spin_unlock(&dum->lock);
1620 req->req.complete (&ep->ep, &req->req); 1780 req->req.complete(&ep->ep, &req->req);
1621 spin_lock (&dum->lock); 1781 spin_lock(&dum->lock);
1622 ep->already_seen = 0; 1782 ep->already_seen = 0;
1623 goto restart; 1783 goto restart;
1624 } 1784 }
@@ -1638,10 +1798,10 @@ restart:
1638 * until setup() returns; no reentrancy issues etc. 1798 * until setup() returns; no reentrancy issues etc.
1639 */ 1799 */
1640 if (value > 0) { 1800 if (value > 0) {
1641 spin_unlock (&dum->lock); 1801 spin_unlock(&dum->lock);
1642 value = dum->driver->setup (&dum->gadget, 1802 value = dum->driver->setup(&dum->gadget,
1643 &setup); 1803 &setup);
1644 spin_lock (&dum->lock); 1804 spin_lock(&dum->lock);
1645 1805
1646 if (value >= 0) { 1806 if (value >= 0) {
1647 /* no delays (max 64KB data stage) */ 1807 /* no delays (max 64KB data stage) */
@@ -1653,7 +1813,7 @@ restart:
1653 1813
1654 if (value < 0) { 1814 if (value < 0) {
1655 if (value != -EOPNOTSUPP) 1815 if (value != -EOPNOTSUPP)
1656 dev_dbg (udc_dev(dum), 1816 dev_dbg(udc_dev(dum),
1657 "setup --> %d\n", 1817 "setup --> %d\n",
1658 value); 1818 value);
1659 status = -EPIPE; 1819 status = -EPIPE;
@@ -1665,14 +1825,14 @@ restart:
1665 1825
1666 /* non-control requests */ 1826 /* non-control requests */
1667 limit = total; 1827 limit = total;
1668 switch (usb_pipetype (urb->pipe)) { 1828 switch (usb_pipetype(urb->pipe)) {
1669 case PIPE_ISOCHRONOUS: 1829 case PIPE_ISOCHRONOUS:
1670 /* FIXME is it urb->interval since the last xfer? 1830 /* FIXME is it urb->interval since the last xfer?
1671 * use urb->iso_frame_desc[i]. 1831 * use urb->iso_frame_desc[i].
1672 * complete whether or not ep has requests queued. 1832 * complete whether or not ep has requests queued.
1673 * report random errors, to debug drivers. 1833 * report random errors, to debug drivers.
1674 */ 1834 */
1675 limit = max (limit, periodic_bytes (dum, ep)); 1835 limit = max(limit, periodic_bytes(dum, ep));
1676 status = -ENOSYS; 1836 status = -ENOSYS;
1677 break; 1837 break;
1678 1838
@@ -1680,14 +1840,13 @@ restart:
1680 /* FIXME is it urb->interval since the last xfer? 1840 /* FIXME is it urb->interval since the last xfer?
1681 * this almost certainly polls too fast. 1841 * this almost certainly polls too fast.
1682 */ 1842 */
1683 limit = max (limit, periodic_bytes (dum, ep)); 1843 limit = max(limit, periodic_bytes(dum, ep));
1684 /* FALLTHROUGH */ 1844 /* FALLTHROUGH */
1685 1845
1686 // case PIPE_BULK: case PIPE_CONTROL:
1687 default: 1846 default:
1688 treat_control_like_bulk: 1847treat_control_like_bulk:
1689 ep->last_io = jiffies; 1848 ep->last_io = jiffies;
1690 total = transfer(dum, urb, ep, limit, &status); 1849 total = transfer(dum_hcd, urb, ep, limit, &status);
1691 break; 1850 break;
1692 } 1851 }
1693 1852
@@ -1696,15 +1855,15 @@ restart:
1696 continue; 1855 continue;
1697 1856
1698return_urb: 1857return_urb:
1699 list_del (&urbp->urbp_list); 1858 list_del(&urbp->urbp_list);
1700 kfree (urbp); 1859 kfree(urbp);
1701 if (ep) 1860 if (ep)
1702 ep->already_seen = ep->setup_stage = 0; 1861 ep->already_seen = ep->setup_stage = 0;
1703 1862
1704 usb_hcd_unlink_urb_from_ep(dummy_hcd_to_hcd(dum_hcd), urb); 1863 usb_hcd_unlink_urb_from_ep(dummy_hcd_to_hcd(dum_hcd), urb);
1705 spin_unlock (&dum->lock); 1864 spin_unlock(&dum->lock);
1706 usb_hcd_giveback_urb(dummy_hcd_to_hcd(dum_hcd), urb, status); 1865 usb_hcd_giveback_urb(dummy_hcd_to_hcd(dum_hcd), urb, status);
1707 spin_lock (&dum->lock); 1866 spin_lock(&dum->lock);
1708 1867
1709 goto restart; 1868 goto restart;
1710 } 1869 }
@@ -1717,7 +1876,7 @@ return_urb:
1717 mod_timer(&dum_hcd->timer, jiffies + msecs_to_jiffies(1)); 1876 mod_timer(&dum_hcd->timer, jiffies + msecs_to_jiffies(1));
1718 } 1877 }
1719 1878
1720 spin_unlock_irqrestore (&dum->lock, flags); 1879 spin_unlock_irqrestore(&dum->lock, flags);
1721} 1880}
1722 1881
1723/*-------------------------------------------------------------------------*/ 1882/*-------------------------------------------------------------------------*/
@@ -1729,7 +1888,7 @@ return_urb:
1729 | USB_PORT_STAT_C_OVERCURRENT \ 1888 | USB_PORT_STAT_C_OVERCURRENT \
1730 | USB_PORT_STAT_C_RESET) << 16) 1889 | USB_PORT_STAT_C_RESET) << 16)
1731 1890
1732static int dummy_hub_status (struct usb_hcd *hcd, char *buf) 1891static int dummy_hub_status(struct usb_hcd *hcd, char *buf)
1733{ 1892{
1734 struct dummy_hcd *dum_hcd; 1893 struct dummy_hcd *dum_hcd;
1735 unsigned long flags; 1894 unsigned long flags;
@@ -1753,7 +1912,7 @@ static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1753 dum_hcd->port_status); 1912 dum_hcd->port_status);
1754 retval = 1; 1913 retval = 1;
1755 if (dum_hcd->rh_state == DUMMY_RH_SUSPENDED) 1914 if (dum_hcd->rh_state == DUMMY_RH_SUSPENDED)
1756 usb_hcd_resume_root_hub (hcd); 1915 usb_hcd_resume_root_hub(hcd);
1757 } 1916 }
1758done: 1917done:
1759 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); 1918 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
@@ -1772,10 +1931,9 @@ ss_hub_descriptor(struct usb_hub_descriptor *desc)
1772 desc->u.ss.DeviceRemovable = 0xffff; 1931 desc->u.ss.DeviceRemovable = 0xffff;
1773} 1932}
1774 1933
1775static inline void 1934static inline void hub_descriptor(struct usb_hub_descriptor *desc)
1776hub_descriptor (struct usb_hub_descriptor *desc)
1777{ 1935{
1778 memset (desc, 0, sizeof *desc); 1936 memset(desc, 0, sizeof *desc);
1779 desc->bDescriptorType = 0x29; 1937 desc->bDescriptorType = 0x29;
1780 desc->bDescLength = 9; 1938 desc->bDescLength = 9;
1781 desc->wHubCharacteristics = cpu_to_le16(0x0001); 1939 desc->wHubCharacteristics = cpu_to_le16(0x0001);
@@ -1784,7 +1942,7 @@ hub_descriptor (struct usb_hub_descriptor *desc)
1784 desc->u.hs.DeviceRemovable[1] = 0xff; 1942 desc->u.hs.DeviceRemovable[1] = 0xff;
1785} 1943}
1786 1944
1787static int dummy_hub_control ( 1945static int dummy_hub_control(
1788 struct usb_hcd *hcd, 1946 struct usb_hcd *hcd,
1789 u16 typeReq, 1947 u16 typeReq,
1790 u16 wValue, 1948 u16 wValue,
@@ -1852,7 +2010,7 @@ static int dummy_hub_control (
1852 hub_descriptor((struct usb_hub_descriptor *) buf); 2010 hub_descriptor((struct usb_hub_descriptor *) buf);
1853 break; 2011 break;
1854 case GetHubStatus: 2012 case GetHubStatus:
1855 *(__le32 *) buf = cpu_to_le32 (0); 2013 *(__le32 *) buf = cpu_to_le32(0);
1856 break; 2014 break;
1857 case GetPortStatus: 2015 case GetPortStatus:
1858 if (wIndex != 1) 2016 if (wIndex != 1)
@@ -1894,8 +2052,8 @@ static int dummy_hub_control (
1894 } 2052 }
1895 } 2053 }
1896 set_link_state(dum_hcd); 2054 set_link_state(dum_hcd);
1897 ((__le16 *) buf)[0] = cpu_to_le16 (dum_hcd->port_status); 2055 ((__le16 *) buf)[0] = cpu_to_le16(dum_hcd->port_status);
1898 ((__le16 *) buf)[1] = cpu_to_le16 (dum_hcd->port_status >> 16); 2056 ((__le16 *) buf)[1] = cpu_to_le16(dum_hcd->port_status >> 16);
1899 break; 2057 break;
1900 case SetHubFeature: 2058 case SetHubFeature:
1901 retval = -EPIPE; 2059 retval = -EPIPE;
@@ -2029,15 +2187,15 @@ error:
2029 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); 2187 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
2030 2188
2031 if ((dum_hcd->port_status & PORT_C_MASK) != 0) 2189 if ((dum_hcd->port_status & PORT_C_MASK) != 0)
2032 usb_hcd_poll_rh_status (hcd); 2190 usb_hcd_poll_rh_status(hcd);
2033 return retval; 2191 return retval;
2034} 2192}
2035 2193
2036static int dummy_bus_suspend (struct usb_hcd *hcd) 2194static int dummy_bus_suspend(struct usb_hcd *hcd)
2037{ 2195{
2038 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); 2196 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2039 2197
2040 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); 2198 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
2041 2199
2042 spin_lock_irq(&dum_hcd->dum->lock); 2200 spin_lock_irq(&dum_hcd->dum->lock);
2043 dum_hcd->rh_state = DUMMY_RH_SUSPENDED; 2201 dum_hcd->rh_state = DUMMY_RH_SUSPENDED;
@@ -2047,12 +2205,12 @@ static int dummy_bus_suspend (struct usb_hcd *hcd)
2047 return 0; 2205 return 0;
2048} 2206}
2049 2207
2050static int dummy_bus_resume (struct usb_hcd *hcd) 2208static int dummy_bus_resume(struct usb_hcd *hcd)
2051{ 2209{
2052 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); 2210 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2053 int rc = 0; 2211 int rc = 0;
2054 2212
2055 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); 2213 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
2056 2214
2057 spin_lock_irq(&dum_hcd->dum->lock); 2215 spin_lock_irq(&dum_hcd->dum->lock);
2058 if (!HCD_HW_ACCESSIBLE(hcd)) { 2216 if (!HCD_HW_ACCESSIBLE(hcd)) {
@@ -2070,55 +2228,54 @@ static int dummy_bus_resume (struct usb_hcd *hcd)
2070 2228
2071/*-------------------------------------------------------------------------*/ 2229/*-------------------------------------------------------------------------*/
2072 2230
2073static inline ssize_t 2231static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb)
2074show_urb (char *buf, size_t size, struct urb *urb)
2075{ 2232{
2076 int ep = usb_pipeendpoint (urb->pipe); 2233 int ep = usb_pipeendpoint(urb->pipe);
2077 2234
2078 return snprintf (buf, size, 2235 return snprintf(buf, size,
2079 "urb/%p %s ep%d%s%s len %d/%d\n", 2236 "urb/%p %s ep%d%s%s len %d/%d\n",
2080 urb, 2237 urb,
2081 ({ char *s; 2238 ({ char *s;
2082 switch (urb->dev->speed) { 2239 switch (urb->dev->speed) {
2083 case USB_SPEED_LOW: 2240 case USB_SPEED_LOW:
2084 s = "ls"; 2241 s = "ls";
2085 break; 2242 break;
2086 case USB_SPEED_FULL: 2243 case USB_SPEED_FULL:
2087 s = "fs"; 2244 s = "fs";
2088 break; 2245 break;
2089 case USB_SPEED_HIGH: 2246 case USB_SPEED_HIGH:
2090 s = "hs"; 2247 s = "hs";
2091 break; 2248 break;
2092 case USB_SPEED_SUPER: 2249 case USB_SPEED_SUPER:
2093 s = "ss"; 2250 s = "ss";
2094 break; 2251 break;
2095 default: 2252 default:
2096 s = "?"; 2253 s = "?";
2097 break; 2254 break;
2098 }; s; }), 2255 }; s; }),
2099 ep, ep ? (usb_pipein (urb->pipe) ? "in" : "out") : "", 2256 ep, ep ? (usb_pipein(urb->pipe) ? "in" : "out") : "",
2100 ({ char *s; \ 2257 ({ char *s; \
2101 switch (usb_pipetype (urb->pipe)) { \ 2258 switch (usb_pipetype(urb->pipe)) { \
2102 case PIPE_CONTROL: \ 2259 case PIPE_CONTROL: \
2103 s = ""; \ 2260 s = ""; \
2104 break; \ 2261 break; \
2105 case PIPE_BULK: \ 2262 case PIPE_BULK: \
2106 s = "-bulk"; \ 2263 s = "-bulk"; \
2107 break; \ 2264 break; \
2108 case PIPE_INTERRUPT: \ 2265 case PIPE_INTERRUPT: \
2109 s = "-int"; \ 2266 s = "-int"; \
2110 break; \ 2267 break; \
2111 default: \ 2268 default: \
2112 s = "-iso"; \ 2269 s = "-iso"; \
2113 break; \ 2270 break; \
2114 }; s;}), 2271 }; s; }),
2115 urb->actual_length, urb->transfer_buffer_length); 2272 urb->actual_length, urb->transfer_buffer_length);
2116} 2273}
2117 2274
2118static ssize_t 2275static ssize_t show_urbs(struct device *dev, struct device_attribute *attr,
2119show_urbs (struct device *dev, struct device_attribute *attr, char *buf) 2276 char *buf)
2120{ 2277{
2121 struct usb_hcd *hcd = dev_get_drvdata (dev); 2278 struct usb_hcd *hcd = dev_get_drvdata(dev);
2122 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); 2279 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2123 struct urbp *urbp; 2280 struct urbp *urbp;
2124 size_t size = 0; 2281 size_t size = 0;
@@ -2128,7 +2285,7 @@ show_urbs (struct device *dev, struct device_attribute *attr, char *buf)
2128 list_for_each_entry(urbp, &dum_hcd->urbp_list, urbp_list) { 2285 list_for_each_entry(urbp, &dum_hcd->urbp_list, urbp_list) {
2129 size_t temp; 2286 size_t temp;
2130 2287
2131 temp = show_urb (buf, PAGE_SIZE - size, urbp->urb); 2288 temp = show_urb(buf, PAGE_SIZE - size, urbp->urb);
2132 buf += temp; 2289 buf += temp;
2133 size += temp; 2290 size += temp;
2134 } 2291 }
@@ -2136,7 +2293,7 @@ show_urbs (struct device *dev, struct device_attribute *attr, char *buf)
2136 2293
2137 return size; 2294 return size;
2138} 2295}
2139static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL); 2296static DEVICE_ATTR(urbs, S_IRUGO, show_urbs, NULL);
2140 2297
2141static int dummy_start_ss(struct dummy_hcd *dum_hcd) 2298static int dummy_start_ss(struct dummy_hcd *dum_hcd)
2142{ 2299{
@@ -2144,6 +2301,7 @@ static int dummy_start_ss(struct dummy_hcd *dum_hcd)
2144 dum_hcd->timer.function = dummy_timer; 2301 dum_hcd->timer.function = dummy_timer;
2145 dum_hcd->timer.data = (unsigned long)dum_hcd; 2302 dum_hcd->timer.data = (unsigned long)dum_hcd;
2146 dum_hcd->rh_state = DUMMY_RH_RUNNING; 2303 dum_hcd->rh_state = DUMMY_RH_RUNNING;
2304 dum_hcd->stream_en_ep = 0;
2147 INIT_LIST_HEAD(&dum_hcd->urbp_list); 2305 INIT_LIST_HEAD(&dum_hcd->urbp_list);
2148 dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET; 2306 dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET;
2149 dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING; 2307 dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING;
@@ -2189,11 +2347,11 @@ static int dummy_start(struct usb_hcd *hcd)
2189 return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs); 2347 return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs);
2190} 2348}
2191 2349
2192static void dummy_stop (struct usb_hcd *hcd) 2350static void dummy_stop(struct usb_hcd *hcd)
2193{ 2351{
2194 struct dummy *dum; 2352 struct dummy *dum;
2195 2353
2196 dum = (hcd_to_dummy_hcd(hcd))->dum; 2354 dum = hcd_to_dummy_hcd(hcd)->dum;
2197 device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs); 2355 device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs);
2198 usb_gadget_unregister_driver(dum->driver); 2356 usb_gadget_unregister_driver(dum->driver);
2199 dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n"); 2357 dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n");
@@ -2201,13 +2359,14 @@ static void dummy_stop (struct usb_hcd *hcd)
2201 2359
2202/*-------------------------------------------------------------------------*/ 2360/*-------------------------------------------------------------------------*/
2203 2361
2204static int dummy_h_get_frame (struct usb_hcd *hcd) 2362static int dummy_h_get_frame(struct usb_hcd *hcd)
2205{ 2363{
2206 return dummy_g_get_frame (NULL); 2364 return dummy_g_get_frame(NULL);
2207} 2365}
2208 2366
2209static int dummy_setup(struct usb_hcd *hcd) 2367static int dummy_setup(struct usb_hcd *hcd)
2210{ 2368{
2369 hcd->self.sg_tablesize = ~0;
2211 if (usb_hcd_is_primary_hcd(hcd)) { 2370 if (usb_hcd_is_primary_hcd(hcd)) {
2212 the_controller.hs_hcd = hcd_to_dummy_hcd(hcd); 2371 the_controller.hs_hcd = hcd_to_dummy_hcd(hcd);
2213 the_controller.hs_hcd->dum = &the_controller; 2372 the_controller.hs_hcd->dum = &the_controller;
@@ -2228,27 +2387,82 @@ static int dummy_setup(struct usb_hcd *hcd)
2228} 2387}
2229 2388
2230/* Change a group of bulk endpoints to support multiple stream IDs */ 2389/* Change a group of bulk endpoints to support multiple stream IDs */
2231int dummy_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, 2390static int dummy_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
2232 struct usb_host_endpoint **eps, unsigned int num_eps, 2391 struct usb_host_endpoint **eps, unsigned int num_eps,
2233 unsigned int num_streams, gfp_t mem_flags) 2392 unsigned int num_streams, gfp_t mem_flags)
2234{ 2393{
2235 if (hcd->speed != HCD_USB3) 2394 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2236 dev_dbg(dummy_dev(hcd_to_dummy_hcd(hcd)), 2395 unsigned long flags;
2237 "%s() - ERROR! Not supported for USB2.0 roothub\n", 2396 int max_stream;
2238 __func__); 2397 int ret_streams = num_streams;
2239 return 0; 2398 unsigned int index;
2399 unsigned int i;
2400
2401 if (!num_eps)
2402 return -EINVAL;
2403
2404 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
2405 for (i = 0; i < num_eps; i++) {
2406 index = dummy_get_ep_idx(&eps[i]->desc);
2407 if ((1 << index) & dum_hcd->stream_en_ep) {
2408 ret_streams = -EINVAL;
2409 goto out;
2410 }
2411 max_stream = usb_ss_max_streams(&eps[i]->ss_ep_comp);
2412 if (!max_stream) {
2413 ret_streams = -EINVAL;
2414 goto out;
2415 }
2416 if (max_stream < ret_streams) {
2417 dev_dbg(dummy_dev(dum_hcd), "Ep 0x%x only supports %u "
2418 "stream IDs.\n",
2419 eps[i]->desc.bEndpointAddress,
2420 max_stream);
2421 ret_streams = max_stream;
2422 }
2423 }
2424
2425 for (i = 0; i < num_eps; i++) {
2426 index = dummy_get_ep_idx(&eps[i]->desc);
2427 dum_hcd->stream_en_ep |= 1 << index;
2428 set_max_streams_for_pipe(dum_hcd,
2429 usb_endpoint_num(&eps[i]->desc), ret_streams);
2430 }
2431out:
2432 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
2433 return ret_streams;
2240} 2434}
2241 2435
2242/* Reverts a group of bulk endpoints back to not using stream IDs. */ 2436/* Reverts a group of bulk endpoints back to not using stream IDs. */
2243int dummy_free_streams(struct usb_hcd *hcd, struct usb_device *udev, 2437static int dummy_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
2244 struct usb_host_endpoint **eps, unsigned int num_eps, 2438 struct usb_host_endpoint **eps, unsigned int num_eps,
2245 gfp_t mem_flags) 2439 gfp_t mem_flags)
2246{ 2440{
2247 if (hcd->speed != HCD_USB3) 2441 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2248 dev_dbg(dummy_dev(hcd_to_dummy_hcd(hcd)), 2442 unsigned long flags;
2249 "%s() - ERROR! Not supported for USB2.0 roothub\n", 2443 int ret;
2250 __func__); 2444 unsigned int index;
2251 return 0; 2445 unsigned int i;
2446
2447 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
2448 for (i = 0; i < num_eps; i++) {
2449 index = dummy_get_ep_idx(&eps[i]->desc);
2450 if (!((1 << index) & dum_hcd->stream_en_ep)) {
2451 ret = -EINVAL;
2452 goto out;
2453 }
2454 }
2455
2456 for (i = 0; i < num_eps; i++) {
2457 index = dummy_get_ep_idx(&eps[i]->desc);
2458 dum_hcd->stream_en_ep &= ~(1 << index);
2459 set_max_streams_for_pipe(dum_hcd,
2460 usb_endpoint_num(&eps[i]->desc), 0);
2461 }
2462 ret = 0;
2463out:
2464 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
2465 return ret;
2252} 2466}
2253 2467
2254static struct hc_driver dummy_hcd = { 2468static struct hc_driver dummy_hcd = {
@@ -2262,13 +2476,13 @@ static struct hc_driver dummy_hcd = {
2262 .start = dummy_start, 2476 .start = dummy_start,
2263 .stop = dummy_stop, 2477 .stop = dummy_stop,
2264 2478
2265 .urb_enqueue = dummy_urb_enqueue, 2479 .urb_enqueue = dummy_urb_enqueue,
2266 .urb_dequeue = dummy_urb_dequeue, 2480 .urb_dequeue = dummy_urb_dequeue,
2267 2481
2268 .get_frame_number = dummy_h_get_frame, 2482 .get_frame_number = dummy_h_get_frame,
2269 2483
2270 .hub_status_data = dummy_hub_status, 2484 .hub_status_data = dummy_hub_status,
2271 .hub_control = dummy_hub_control, 2485 .hub_control = dummy_hub_control,
2272 .bus_suspend = dummy_bus_suspend, 2486 .bus_suspend = dummy_bus_suspend,
2273 .bus_resume = dummy_bus_resume, 2487 .bus_resume = dummy_bus_resume,
2274 2488
@@ -2323,7 +2537,7 @@ static int dummy_hcd_remove(struct platform_device *pdev)
2323{ 2537{
2324 struct dummy *dum; 2538 struct dummy *dum;
2325 2539
2326 dum = (hcd_to_dummy_hcd(platform_get_drvdata(pdev)))->dum; 2540 dum = hcd_to_dummy_hcd(platform_get_drvdata(pdev))->dum;
2327 2541
2328 if (dum->ss_hcd) { 2542 if (dum->ss_hcd) {
2329 usb_remove_hcd(dummy_hcd_to_hcd(dum->ss_hcd)); 2543 usb_remove_hcd(dummy_hcd_to_hcd(dum->ss_hcd));
@@ -2339,15 +2553,15 @@ static int dummy_hcd_remove(struct platform_device *pdev)
2339 return 0; 2553 return 0;
2340} 2554}
2341 2555
2342static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state) 2556static int dummy_hcd_suspend(struct platform_device *pdev, pm_message_t state)
2343{ 2557{
2344 struct usb_hcd *hcd; 2558 struct usb_hcd *hcd;
2345 struct dummy_hcd *dum_hcd; 2559 struct dummy_hcd *dum_hcd;
2346 int rc = 0; 2560 int rc = 0;
2347 2561
2348 dev_dbg (&pdev->dev, "%s\n", __func__); 2562 dev_dbg(&pdev->dev, "%s\n", __func__);
2349 2563
2350 hcd = platform_get_drvdata (pdev); 2564 hcd = platform_get_drvdata(pdev);
2351 dum_hcd = hcd_to_dummy_hcd(hcd); 2565 dum_hcd = hcd_to_dummy_hcd(hcd);
2352 if (dum_hcd->rh_state == DUMMY_RH_RUNNING) { 2566 if (dum_hcd->rh_state == DUMMY_RH_RUNNING) {
2353 dev_warn(&pdev->dev, "Root hub isn't suspended!\n"); 2567 dev_warn(&pdev->dev, "Root hub isn't suspended!\n");
@@ -2357,15 +2571,15 @@ static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state)
2357 return rc; 2571 return rc;
2358} 2572}
2359 2573
2360static int dummy_hcd_resume (struct platform_device *pdev) 2574static int dummy_hcd_resume(struct platform_device *pdev)
2361{ 2575{
2362 struct usb_hcd *hcd; 2576 struct usb_hcd *hcd;
2363 2577
2364 dev_dbg (&pdev->dev, "%s\n", __func__); 2578 dev_dbg(&pdev->dev, "%s\n", __func__);
2365 2579
2366 hcd = platform_get_drvdata (pdev); 2580 hcd = platform_get_drvdata(pdev);
2367 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 2581 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
2368 usb_hcd_poll_rh_status (hcd); 2582 usb_hcd_poll_rh_status(hcd);
2369 return 0; 2583 return 0;
2370} 2584}
2371 2585
@@ -2385,11 +2599,11 @@ static struct platform_driver dummy_hcd_driver = {
2385static struct platform_device *the_udc_pdev; 2599static struct platform_device *the_udc_pdev;
2386static struct platform_device *the_hcd_pdev; 2600static struct platform_device *the_hcd_pdev;
2387 2601
2388static int __init init (void) 2602static int __init init(void)
2389{ 2603{
2390 int retval = -ENOMEM; 2604 int retval = -ENOMEM;
2391 2605
2392 if (usb_disabled ()) 2606 if (usb_disabled())
2393 return -ENODEV; 2607 return -ENODEV;
2394 2608
2395 if (!mod_data.is_high_speed && mod_data.is_super_speed) 2609 if (!mod_data.is_high_speed && mod_data.is_super_speed)
@@ -2448,13 +2662,13 @@ err_alloc_udc:
2448 platform_device_put(the_hcd_pdev); 2662 platform_device_put(the_hcd_pdev);
2449 return retval; 2663 return retval;
2450} 2664}
2451module_init (init); 2665module_init(init);
2452 2666
2453static void __exit cleanup (void) 2667static void __exit cleanup(void)
2454{ 2668{
2455 platform_device_unregister(the_udc_pdev); 2669 platform_device_unregister(the_udc_pdev);
2456 platform_device_unregister(the_hcd_pdev); 2670 platform_device_unregister(the_hcd_pdev);
2457 platform_driver_unregister(&dummy_udc_driver); 2671 platform_driver_unregister(&dummy_udc_driver);
2458 platform_driver_unregister(&dummy_hcd_driver); 2672 platform_driver_unregister(&dummy_hcd_driver);
2459} 2673}
2460module_exit (cleanup); 2674module_exit(cleanup);
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index e0e6375ef5dd..51f3d42f5a64 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -275,24 +275,24 @@ struct usb_ep *usb_ep_autoconfig_ss(
275 /* ep-e, ep-f are PIO with only 64 byte fifos */ 275 /* ep-e, ep-f are PIO with only 64 byte fifos */
276 ep = find_ep (gadget, "ep-e"); 276 ep = find_ep (gadget, "ep-e");
277 if (ep && ep_matches(gadget, ep, desc, ep_comp)) 277 if (ep && ep_matches(gadget, ep, desc, ep_comp))
278 return ep; 278 goto found_ep;
279 ep = find_ep (gadget, "ep-f"); 279 ep = find_ep (gadget, "ep-f");
280 if (ep && ep_matches(gadget, ep, desc, ep_comp)) 280 if (ep && ep_matches(gadget, ep, desc, ep_comp))
281 return ep; 281 goto found_ep;
282 282
283 } else if (gadget_is_goku (gadget)) { 283 } else if (gadget_is_goku (gadget)) {
284 if (USB_ENDPOINT_XFER_INT == type) { 284 if (USB_ENDPOINT_XFER_INT == type) {
285 /* single buffering is enough */ 285 /* single buffering is enough */
286 ep = find_ep(gadget, "ep3-bulk"); 286 ep = find_ep(gadget, "ep3-bulk");
287 if (ep && ep_matches(gadget, ep, desc, ep_comp)) 287 if (ep && ep_matches(gadget, ep, desc, ep_comp))
288 return ep; 288 goto found_ep;
289 } else if (USB_ENDPOINT_XFER_BULK == type 289 } else if (USB_ENDPOINT_XFER_BULK == type
290 && (USB_DIR_IN & desc->bEndpointAddress)) { 290 && (USB_DIR_IN & desc->bEndpointAddress)) {
291 /* DMA may be available */ 291 /* DMA may be available */
292 ep = find_ep(gadget, "ep2-bulk"); 292 ep = find_ep(gadget, "ep2-bulk");
293 if (ep && ep_matches(gadget, ep, desc, 293 if (ep && ep_matches(gadget, ep, desc,
294 ep_comp)) 294 ep_comp))
295 return ep; 295 goto found_ep;
296 } 296 }
297 297
298#ifdef CONFIG_BLACKFIN 298#ifdef CONFIG_BLACKFIN
@@ -311,18 +311,22 @@ struct usb_ep *usb_ep_autoconfig_ss(
311 } else 311 } else
312 ep = NULL; 312 ep = NULL;
313 if (ep && ep_matches(gadget, ep, desc, ep_comp)) 313 if (ep && ep_matches(gadget, ep, desc, ep_comp))
314 return ep; 314 goto found_ep;
315#endif 315#endif
316 } 316 }
317 317
318 /* Second, look at endpoints until an unclaimed one looks usable */ 318 /* Second, look at endpoints until an unclaimed one looks usable */
319 list_for_each_entry (ep, &gadget->ep_list, ep_list) { 319 list_for_each_entry (ep, &gadget->ep_list, ep_list) {
320 if (ep_matches(gadget, ep, desc, ep_comp)) 320 if (ep_matches(gadget, ep, desc, ep_comp))
321 return ep; 321 goto found_ep;
322 } 322 }
323 323
324 /* Fail */ 324 /* Fail */
325 return NULL; 325 return NULL;
326found_ep:
327 ep->desc = NULL;
328 ep->comp_desc = NULL;
329 return ep;
326} 330}
327 331
328/** 332/**
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 3f8849339ade..d672250a61fa 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -5,7 +5,7 @@
5 * Copyright (C) 2008 by David Brownell 5 * Copyright (C) 2008 by David Brownell
6 * Copyright (C) 2008 by Nokia Corporation 6 * Copyright (C) 2008 by Nokia Corporation
7 * Copyright (C) 2009 by Samsung Electronics 7 * Copyright (C) 2009 by Samsung Electronics
8 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com) 8 * Author: Michal Nazarewicz (mina86@mina86.com)
9 * 9 *
10 * This software is distributed under the terms of the GNU General 10 * This software is distributed under the terms of the GNU General
11 * Public License ("GPL") as published by the Free Software Foundation, 11 * Public License ("GPL") as published by the Free Software Foundation,
@@ -237,6 +237,42 @@ static struct usb_descriptor_header *acm_hs_function[] = {
237 NULL, 237 NULL,
238}; 238};
239 239
240static struct usb_endpoint_descriptor acm_ss_in_desc = {
241 .bLength = USB_DT_ENDPOINT_SIZE,
242 .bDescriptorType = USB_DT_ENDPOINT,
243 .bmAttributes = USB_ENDPOINT_XFER_BULK,
244 .wMaxPacketSize = cpu_to_le16(1024),
245};
246
247static struct usb_endpoint_descriptor acm_ss_out_desc = {
248 .bLength = USB_DT_ENDPOINT_SIZE,
249 .bDescriptorType = USB_DT_ENDPOINT,
250 .bmAttributes = USB_ENDPOINT_XFER_BULK,
251 .wMaxPacketSize = cpu_to_le16(1024),
252};
253
254static struct usb_ss_ep_comp_descriptor acm_ss_bulk_comp_desc = {
255 .bLength = sizeof acm_ss_bulk_comp_desc,
256 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
257};
258
259static struct usb_descriptor_header *acm_ss_function[] = {
260 (struct usb_descriptor_header *) &acm_iad_descriptor,
261 (struct usb_descriptor_header *) &acm_control_interface_desc,
262 (struct usb_descriptor_header *) &acm_header_desc,
263 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
264 (struct usb_descriptor_header *) &acm_descriptor,
265 (struct usb_descriptor_header *) &acm_union_desc,
266 (struct usb_descriptor_header *) &acm_hs_notify_desc,
267 (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
268 (struct usb_descriptor_header *) &acm_data_interface_desc,
269 (struct usb_descriptor_header *) &acm_ss_in_desc,
270 (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
271 (struct usb_descriptor_header *) &acm_ss_out_desc,
272 (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
273 NULL,
274};
275
240/* string descriptors: */ 276/* string descriptors: */
241 277
242#define ACM_CTRL_IDX 0 278#define ACM_CTRL_IDX 0
@@ -643,9 +679,21 @@ acm_bind(struct usb_configuration *c, struct usb_function *f)
643 /* copy descriptors */ 679 /* copy descriptors */
644 f->hs_descriptors = usb_copy_descriptors(acm_hs_function); 680 f->hs_descriptors = usb_copy_descriptors(acm_hs_function);
645 } 681 }
682 if (gadget_is_superspeed(c->cdev->gadget)) {
683 acm_ss_in_desc.bEndpointAddress =
684 acm_fs_in_desc.bEndpointAddress;
685 acm_ss_out_desc.bEndpointAddress =
686 acm_fs_out_desc.bEndpointAddress;
687
688 /* copy descriptors, and track endpoint copies */
689 f->ss_descriptors = usb_copy_descriptors(acm_ss_function);
690 if (!f->ss_descriptors)
691 goto fail;
692 }
646 693
647 DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", 694 DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n",
648 acm->port_num, 695 acm->port_num,
696 gadget_is_superspeed(c->cdev->gadget) ? "super" :
649 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 697 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
650 acm->port.in->name, acm->port.out->name, 698 acm->port.in->name, acm->port.out->name,
651 acm->notify->name); 699 acm->notify->name);
@@ -675,6 +723,8 @@ acm_unbind(struct usb_configuration *c, struct usb_function *f)
675 723
676 if (gadget_is_dualspeed(c->cdev->gadget)) 724 if (gadget_is_dualspeed(c->cdev->gadget))
677 usb_free_descriptors(f->hs_descriptors); 725 usb_free_descriptors(f->hs_descriptors);
726 if (gadget_is_superspeed(c->cdev->gadget))
727 usb_free_descriptors(f->ss_descriptors);
678 usb_free_descriptors(f->descriptors); 728 usb_free_descriptors(f->descriptors);
679 gs_free_req(acm->notify, acm->notify_req); 729 gs_free_req(acm->notify, acm->notify_req);
680 kfree(acm); 730 kfree(acm);
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index 11c07cb7d337..30b908f2a53d 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -97,6 +97,20 @@ static inline unsigned ecm_bitrate(struct usb_gadget *g)
97 97
98/* interface descriptor: */ 98/* interface descriptor: */
99 99
100static struct usb_interface_assoc_descriptor
101ecm_iad_descriptor = {
102 .bLength = sizeof ecm_iad_descriptor,
103 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
104
105 /* .bFirstInterface = DYNAMIC, */
106 .bInterfaceCount = 2, /* control + data */
107 .bFunctionClass = USB_CLASS_COMM,
108 .bFunctionSubClass = USB_CDC_SUBCLASS_ETHERNET,
109 .bFunctionProtocol = USB_CDC_PROTO_NONE,
110 /* .iFunction = DYNAMIC */
111};
112
113
100static struct usb_interface_descriptor ecm_control_intf = { 114static struct usb_interface_descriptor ecm_control_intf = {
101 .bLength = sizeof ecm_control_intf, 115 .bLength = sizeof ecm_control_intf,
102 .bDescriptorType = USB_DT_INTERFACE, 116 .bDescriptorType = USB_DT_INTERFACE,
@@ -199,6 +213,7 @@ static struct usb_endpoint_descriptor fs_ecm_out_desc = {
199 213
200static struct usb_descriptor_header *ecm_fs_function[] = { 214static struct usb_descriptor_header *ecm_fs_function[] = {
201 /* CDC ECM control descriptors */ 215 /* CDC ECM control descriptors */
216 (struct usb_descriptor_header *) &ecm_iad_descriptor,
202 (struct usb_descriptor_header *) &ecm_control_intf, 217 (struct usb_descriptor_header *) &ecm_control_intf,
203 (struct usb_descriptor_header *) &ecm_header_desc, 218 (struct usb_descriptor_header *) &ecm_header_desc,
204 (struct usb_descriptor_header *) &ecm_union_desc, 219 (struct usb_descriptor_header *) &ecm_union_desc,
@@ -247,6 +262,7 @@ static struct usb_endpoint_descriptor hs_ecm_out_desc = {
247 262
248static struct usb_descriptor_header *ecm_hs_function[] = { 263static struct usb_descriptor_header *ecm_hs_function[] = {
249 /* CDC ECM control descriptors */ 264 /* CDC ECM control descriptors */
265 (struct usb_descriptor_header *) &ecm_iad_descriptor,
250 (struct usb_descriptor_header *) &ecm_control_intf, 266 (struct usb_descriptor_header *) &ecm_control_intf,
251 (struct usb_descriptor_header *) &ecm_header_desc, 267 (struct usb_descriptor_header *) &ecm_header_desc,
252 (struct usb_descriptor_header *) &ecm_union_desc, 268 (struct usb_descriptor_header *) &ecm_union_desc,
@@ -339,6 +355,7 @@ static struct usb_string ecm_string_defs[] = {
339 [0].s = "CDC Ethernet Control Model (ECM)", 355 [0].s = "CDC Ethernet Control Model (ECM)",
340 [1].s = NULL /* DYNAMIC */, 356 [1].s = NULL /* DYNAMIC */,
341 [2].s = "CDC Ethernet Data", 357 [2].s = "CDC Ethernet Data",
358 [3].s = "CDC ECM",
342 { } /* end of list */ 359 { } /* end of list */
343}; 360};
344 361
@@ -674,6 +691,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
674 if (status < 0) 691 if (status < 0)
675 goto fail; 692 goto fail;
676 ecm->ctrl_id = status; 693 ecm->ctrl_id = status;
694 ecm_iad_descriptor.bFirstInterface = status;
677 695
678 ecm_control_intf.bInterfaceNumber = status; 696 ecm_control_intf.bInterfaceNumber = status;
679 ecm_union_desc.bMasterInterface0 = status; 697 ecm_union_desc.bMasterInterface0 = status;
@@ -864,6 +882,13 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
864 return status; 882 return status;
865 ecm_string_defs[1].id = status; 883 ecm_string_defs[1].id = status;
866 ecm_desc.iMACAddress = status; 884 ecm_desc.iMACAddress = status;
885
886 /* IAD label */
887 status = usb_string_id(c->cdev);
888 if (status < 0)
889 return status;
890 ecm_string_defs[3].id = status;
891 ecm_iad_descriptor.iFunction = status;
867 } 892 }
868 893
869 /* allocate and initialize one new instance */ 894 /* allocate and initialize one new instance */
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index f63dc6c150d2..1cbba70836bc 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -2,7 +2,7 @@
2 * f_fs.c -- user mode file system API for USB composite function controllers 2 * f_fs.c -- user mode file system API for USB composite function controllers
3 * 3 *
4 * Copyright (C) 2010 Samsung Electronics 4 * Copyright (C) 2010 Samsung Electronics
5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com> 5 * Author: Michal Nazarewicz <mina86@mina86.com>
6 * 6 *
7 * Based on inode.c (GadgetFS) which was: 7 * Based on inode.c (GadgetFS) which was:
8 * Copyright (C) 2003-2004 David Brownell 8 * Copyright (C) 2003-2004 David Brownell
@@ -1063,13 +1063,9 @@ static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1063 &simple_dir_operations, 1063 &simple_dir_operations,
1064 &simple_dir_inode_operations, 1064 &simple_dir_inode_operations,
1065 &data->perms); 1065 &data->perms);
1066 if (unlikely(!inode)) 1066 sb->s_root = d_make_root(inode);
1067 if (unlikely(!sb->s_root))
1067 goto Enomem; 1068 goto Enomem;
1068 sb->s_root = d_alloc_root(inode);
1069 if (unlikely(!sb->s_root)) {
1070 iput(inode);
1071 goto Enomem;
1072 }
1073 1069
1074 /* EP0 file */ 1070 /* EP0 file */
1075 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs, 1071 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs,
@@ -1258,9 +1254,7 @@ static void ffs_data_put(struct ffs_data *ffs)
1258 if (unlikely(atomic_dec_and_test(&ffs->ref))) { 1254 if (unlikely(atomic_dec_and_test(&ffs->ref))) {
1259 pr_info("%s(): freeing\n", __func__); 1255 pr_info("%s(): freeing\n", __func__);
1260 ffs_data_clear(ffs); 1256 ffs_data_clear(ffs);
1261 BUG_ON(mutex_is_locked(&ffs->mutex) || 1257 BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
1262 spin_is_locked(&ffs->ev.waitq.lock) ||
1263 waitqueue_active(&ffs->ev.waitq) ||
1264 waitqueue_active(&ffs->ep0req_completion.wait)); 1258 waitqueue_active(&ffs->ep0req_completion.wait));
1265 kfree(ffs); 1259 kfree(ffs);
1266 } 1260 }
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index 6d87f288df4e..2c0cd824c667 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -418,7 +418,7 @@ int __init loopback_add(struct usb_composite_dev *cdev, bool autoresume)
418 418
419 /* support autoresume for remote wakeup testing */ 419 /* support autoresume for remote wakeup testing */
420 if (autoresume) 420 if (autoresume)
421 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 421 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
422 422
423 /* support OTG systems */ 423 /* support OTG systems */
424 if (gadget_is_otg(cdev->gadget)) { 424 if (gadget_is_otg(cdev->gadget)) {
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index ee8ceec01560..a371e966425f 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2003-2008 Alan Stern 4 * Copyright (C) 2003-2008 Alan Stern
5 * Copyright (C) 2009 Samsung Electronics 5 * Copyright (C) 2009 Samsung Electronics
6 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com> 6 * Author: Michal Nazarewicz <mina86@mina86.com>
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
@@ -304,7 +304,6 @@
304 304
305static const char fsg_string_interface[] = "Mass Storage"; 305static const char fsg_string_interface[] = "Mass Storage";
306 306
307#define FSG_NO_INTR_EP 1
308#define FSG_NO_DEVICE_STRINGS 1 307#define FSG_NO_DEVICE_STRINGS 1
309#define FSG_NO_OTG 1 308#define FSG_NO_OTG 1
310#define FSG_NO_INTR_EP 1 309#define FSG_NO_INTR_EP 1
@@ -620,7 +619,7 @@ static int fsg_setup(struct usb_function *f,
620 619
621 switch (ctrl->bRequest) { 620 switch (ctrl->bRequest) {
622 621
623 case USB_BULK_RESET_REQUEST: 622 case US_BULK_RESET_REQUEST:
624 if (ctrl->bRequestType != 623 if (ctrl->bRequestType !=
625 (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 624 (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
626 break; 625 break;
@@ -636,7 +635,7 @@ static int fsg_setup(struct usb_function *f,
636 raise_exception(fsg->common, FSG_STATE_RESET); 635 raise_exception(fsg->common, FSG_STATE_RESET);
637 return DELAYED_STATUS; 636 return DELAYED_STATUS;
638 637
639 case USB_BULK_GET_MAX_LUN_REQUEST: 638 case US_BULK_GET_MAX_LUN:
640 if (ctrl->bRequestType != 639 if (ctrl->bRequestType !=
641 (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 640 (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
642 break; 641 break;
@@ -1742,7 +1741,7 @@ static int send_status(struct fsg_common *common)
1742 struct fsg_buffhd *bh; 1741 struct fsg_buffhd *bh;
1743 struct bulk_cs_wrap *csw; 1742 struct bulk_cs_wrap *csw;
1744 int rc; 1743 int rc;
1745 u8 status = USB_STATUS_PASS; 1744 u8 status = US_BULK_STAT_OK;
1746 u32 sd, sdinfo = 0; 1745 u32 sd, sdinfo = 0;
1747 1746
1748 /* Wait for the next buffer to become available */ 1747 /* Wait for the next buffer to become available */
@@ -1763,11 +1762,11 @@ static int send_status(struct fsg_common *common)
1763 1762
1764 if (common->phase_error) { 1763 if (common->phase_error) {
1765 DBG(common, "sending phase-error status\n"); 1764 DBG(common, "sending phase-error status\n");
1766 status = USB_STATUS_PHASE_ERROR; 1765 status = US_BULK_STAT_PHASE;
1767 sd = SS_INVALID_COMMAND; 1766 sd = SS_INVALID_COMMAND;
1768 } else if (sd != SS_NO_SENSE) { 1767 } else if (sd != SS_NO_SENSE) {
1769 DBG(common, "sending command-failure status\n"); 1768 DBG(common, "sending command-failure status\n");
1770 status = USB_STATUS_FAIL; 1769 status = US_BULK_STAT_FAIL;
1771 VDBG(common, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;" 1770 VDBG(common, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
1772 " info x%x\n", 1771 " info x%x\n",
1773 SK(sd), ASC(sd), ASCQ(sd), sdinfo); 1772 SK(sd), ASC(sd), ASCQ(sd), sdinfo);
@@ -1776,12 +1775,12 @@ static int send_status(struct fsg_common *common)
1776 /* Store and send the Bulk-only CSW */ 1775 /* Store and send the Bulk-only CSW */
1777 csw = (void *)bh->buf; 1776 csw = (void *)bh->buf;
1778 1777
1779 csw->Signature = cpu_to_le32(USB_BULK_CS_SIG); 1778 csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
1780 csw->Tag = common->tag; 1779 csw->Tag = common->tag;
1781 csw->Residue = cpu_to_le32(common->residue); 1780 csw->Residue = cpu_to_le32(common->residue);
1782 csw->Status = status; 1781 csw->Status = status;
1783 1782
1784 bh->inreq->length = USB_BULK_CS_WRAP_LEN; 1783 bh->inreq->length = US_BULK_CS_WRAP_LEN;
1785 bh->inreq->zero = 0; 1784 bh->inreq->zero = 0;
1786 if (!start_in_transfer(common, bh)) 1785 if (!start_in_transfer(common, bh))
1787 /* Don't know what to do if common->fsg is NULL */ 1786 /* Don't know what to do if common->fsg is NULL */
@@ -2221,7 +2220,7 @@ unknown_cmnd:
2221static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) 2220static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2222{ 2221{
2223 struct usb_request *req = bh->outreq; 2222 struct usb_request *req = bh->outreq;
2224 struct fsg_bulk_cb_wrap *cbw = req->buf; 2223 struct bulk_cb_wrap *cbw = req->buf;
2225 struct fsg_common *common = fsg->common; 2224 struct fsg_common *common = fsg->common;
2226 2225
2227 /* Was this a real packet? Should it be ignored? */ 2226 /* Was this a real packet? Should it be ignored? */
@@ -2229,9 +2228,9 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2229 return -EINVAL; 2228 return -EINVAL;
2230 2229
2231 /* Is the CBW valid? */ 2230 /* Is the CBW valid? */
2232 if (req->actual != USB_BULK_CB_WRAP_LEN || 2231 if (req->actual != US_BULK_CB_WRAP_LEN ||
2233 cbw->Signature != cpu_to_le32( 2232 cbw->Signature != cpu_to_le32(
2234 USB_BULK_CB_SIG)) { 2233 US_BULK_CB_SIGN)) {
2235 DBG(fsg, "invalid CBW: len %u sig 0x%x\n", 2234 DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
2236 req->actual, 2235 req->actual,
2237 le32_to_cpu(cbw->Signature)); 2236 le32_to_cpu(cbw->Signature));
@@ -2253,7 +2252,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2253 } 2252 }
2254 2253
2255 /* Is the CBW meaningful? */ 2254 /* Is the CBW meaningful? */
2256 if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG || 2255 if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
2257 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) { 2256 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
2258 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, " 2257 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
2259 "cmdlen %u\n", 2258 "cmdlen %u\n",
@@ -2273,7 +2272,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2273 /* Save the command for later */ 2272 /* Save the command for later */
2274 common->cmnd_size = cbw->Length; 2273 common->cmnd_size = cbw->Length;
2275 memcpy(common->cmnd, cbw->CDB, common->cmnd_size); 2274 memcpy(common->cmnd, cbw->CDB, common->cmnd_size);
2276 if (cbw->Flags & USB_BULK_IN_FLAG) 2275 if (cbw->Flags & US_BULK_FLAG_IN)
2277 common->data_dir = DATA_DIR_TO_HOST; 2276 common->data_dir = DATA_DIR_TO_HOST;
2278 else 2277 else
2279 common->data_dir = DATA_DIR_FROM_HOST; 2278 common->data_dir = DATA_DIR_FROM_HOST;
@@ -2303,7 +2302,7 @@ static int get_next_command(struct fsg_common *common)
2303 } 2302 }
2304 2303
2305 /* Queue a request to read a Bulk-only CBW */ 2304 /* Queue a request to read a Bulk-only CBW */
2306 set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN); 2305 set_bulk_out_req_length(common, bh, US_BULK_CB_WRAP_LEN);
2307 if (!start_out_transfer(common, bh)) 2306 if (!start_out_transfer(common, bh))
2308 /* Don't know what to do if common->fsg is NULL */ 2307 /* Don't know what to do if common->fsg is NULL */
2309 return -EIO; 2308 return -EIO;
diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c
index 3797b3d6c622..2f7e8f2930cc 100644
--- a/drivers/usb/gadget/f_midi.c
+++ b/drivers/usb/gadget/f_midi.c
@@ -780,7 +780,7 @@ f_midi_bind(struct usb_configuration *c, struct usb_function *f)
780 midi->out_ep->driver_data = cdev; /* claim */ 780 midi->out_ep->driver_data = cdev; /* claim */
781 781
782 /* allocate temporary function list */ 782 /* allocate temporary function list */
783 midi_function = kcalloc((MAX_PORTS * 4) + 9, sizeof(midi_function), 783 midi_function = kcalloc((MAX_PORTS * 4) + 9, sizeof(*midi_function),
784 GFP_KERNEL); 784 GFP_KERNEL);
785 if (!midi_function) { 785 if (!midi_function) {
786 status = -ENOMEM; 786 status = -ENOMEM;
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index 7cdcb63b21ff..965a6293206a 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -345,7 +345,7 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req)
345 } 345 }
346 346
347 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, 347 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
348 skb->len <= 1, req->actual); 348 skb->len <= 1, req->actual, PAGE_SIZE);
349 page = NULL; 349 page = NULL;
350 350
351 if (req->actual < req->length) { /* Last fragment */ 351 if (req->actual < req->length) { /* Last fragment */
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 704d1d94f72a..7b1cf18df5e3 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -5,7 +5,7 @@
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger 5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation 6 * Copyright (C) 2008 Nokia Corporation
7 * Copyright (C) 2009 Samsung Electronics 7 * Copyright (C) 2009 Samsung Electronics
8 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com) 8 * Author: Michal Nazarewicz (mina86@mina86.com)
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index cf33a8d0fd5d..07197d63d9b1 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -99,6 +99,34 @@ static struct usb_descriptor_header *gser_hs_function[] __initdata = {
99 NULL, 99 NULL,
100}; 100};
101 101
102static struct usb_endpoint_descriptor gser_ss_in_desc __initdata = {
103 .bLength = USB_DT_ENDPOINT_SIZE,
104 .bDescriptorType = USB_DT_ENDPOINT,
105 .bmAttributes = USB_ENDPOINT_XFER_BULK,
106 .wMaxPacketSize = cpu_to_le16(1024),
107};
108
109static struct usb_endpoint_descriptor gser_ss_out_desc __initdata = {
110 .bLength = USB_DT_ENDPOINT_SIZE,
111 .bDescriptorType = USB_DT_ENDPOINT,
112 .bmAttributes = USB_ENDPOINT_XFER_BULK,
113 .wMaxPacketSize = cpu_to_le16(1024),
114};
115
116static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc __initdata = {
117 .bLength = sizeof gser_ss_bulk_comp_desc,
118 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
119};
120
121static struct usb_descriptor_header *gser_ss_function[] __initdata = {
122 (struct usb_descriptor_header *) &gser_interface_desc,
123 (struct usb_descriptor_header *) &gser_ss_in_desc,
124 (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc,
125 (struct usb_descriptor_header *) &gser_ss_out_desc,
126 (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc,
127 NULL,
128};
129
102/* string descriptors: */ 130/* string descriptors: */
103 131
104static struct usb_string gser_string_defs[] = { 132static struct usb_string gser_string_defs[] = {
@@ -201,9 +229,21 @@ gser_bind(struct usb_configuration *c, struct usb_function *f)
201 /* copy descriptors, and track endpoint copies */ 229 /* copy descriptors, and track endpoint copies */
202 f->hs_descriptors = usb_copy_descriptors(gser_hs_function); 230 f->hs_descriptors = usb_copy_descriptors(gser_hs_function);
203 } 231 }
232 if (gadget_is_superspeed(c->cdev->gadget)) {
233 gser_ss_in_desc.bEndpointAddress =
234 gser_fs_in_desc.bEndpointAddress;
235 gser_ss_out_desc.bEndpointAddress =
236 gser_fs_out_desc.bEndpointAddress;
237
238 /* copy descriptors, and track endpoint copies */
239 f->ss_descriptors = usb_copy_descriptors(gser_ss_function);
240 if (!f->ss_descriptors)
241 goto fail;
242 }
204 243
205 DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", 244 DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n",
206 gser->port_num, 245 gser->port_num,
246 gadget_is_superspeed(c->cdev->gadget) ? "super" :
207 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 247 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
208 gser->port.in->name, gser->port.out->name); 248 gser->port.in->name, gser->port.out->name);
209 return 0; 249 return 0;
@@ -225,6 +265,8 @@ gser_unbind(struct usb_configuration *c, struct usb_function *f)
225{ 265{
226 if (gadget_is_dualspeed(c->cdev->gadget)) 266 if (gadget_is_dualspeed(c->cdev->gadget))
227 usb_free_descriptors(f->hs_descriptors); 267 usb_free_descriptors(f->hs_descriptors);
268 if (gadget_is_superspeed(c->cdev->gadget))
269 usb_free_descriptors(f->ss_descriptors);
228 usb_free_descriptors(f->descriptors); 270 usb_free_descriptors(f->descriptors);
229 kfree(func_to_gser(f)); 271 kfree(func_to_gser(f));
230} 272}
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index c1540648125a..21ab474aca07 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -74,7 +74,7 @@ static inline struct f_gether *func_to_geth(struct usb_function *f)
74 74
75/* interface descriptor: */ 75/* interface descriptor: */
76 76
77static struct usb_interface_descriptor subset_data_intf __initdata = { 77static struct usb_interface_descriptor subset_data_intf = {
78 .bLength = sizeof subset_data_intf, 78 .bLength = sizeof subset_data_intf,
79 .bDescriptorType = USB_DT_INTERFACE, 79 .bDescriptorType = USB_DT_INTERFACE,
80 80
@@ -87,7 +87,7 @@ static struct usb_interface_descriptor subset_data_intf __initdata = {
87 /* .iInterface = DYNAMIC */ 87 /* .iInterface = DYNAMIC */
88}; 88};
89 89
90static struct usb_cdc_header_desc mdlm_header_desc __initdata = { 90static struct usb_cdc_header_desc mdlm_header_desc = {
91 .bLength = sizeof mdlm_header_desc, 91 .bLength = sizeof mdlm_header_desc,
92 .bDescriptorType = USB_DT_CS_INTERFACE, 92 .bDescriptorType = USB_DT_CS_INTERFACE,
93 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 93 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
@@ -95,7 +95,7 @@ static struct usb_cdc_header_desc mdlm_header_desc __initdata = {
95 .bcdCDC = cpu_to_le16(0x0110), 95 .bcdCDC = cpu_to_le16(0x0110),
96}; 96};
97 97
98static struct usb_cdc_mdlm_desc mdlm_desc __initdata = { 98static struct usb_cdc_mdlm_desc mdlm_desc = {
99 .bLength = sizeof mdlm_desc, 99 .bLength = sizeof mdlm_desc,
100 .bDescriptorType = USB_DT_CS_INTERFACE, 100 .bDescriptorType = USB_DT_CS_INTERFACE,
101 .bDescriptorSubType = USB_CDC_MDLM_TYPE, 101 .bDescriptorSubType = USB_CDC_MDLM_TYPE,
@@ -111,7 +111,7 @@ static struct usb_cdc_mdlm_desc mdlm_desc __initdata = {
111 * can't really use its struct. All we do here is say that we're using 111 * can't really use its struct. All we do here is say that we're using
112 * the submode of "SAFE" which directly matches the CDC Subset. 112 * the submode of "SAFE" which directly matches the CDC Subset.
113 */ 113 */
114static u8 mdlm_detail_desc[] __initdata = { 114static u8 mdlm_detail_desc[] = {
115 6, 115 6,
116 USB_DT_CS_INTERFACE, 116 USB_DT_CS_INTERFACE,
117 USB_CDC_MDLM_DETAIL_TYPE, 117 USB_CDC_MDLM_DETAIL_TYPE,
@@ -121,7 +121,7 @@ static u8 mdlm_detail_desc[] __initdata = {
121 0, /* network data capabilities ("raw" encapsulation) */ 121 0, /* network data capabilities ("raw" encapsulation) */
122}; 122};
123 123
124static struct usb_cdc_ether_desc ether_desc __initdata = { 124static struct usb_cdc_ether_desc ether_desc = {
125 .bLength = sizeof ether_desc, 125 .bLength = sizeof ether_desc,
126 .bDescriptorType = USB_DT_CS_INTERFACE, 126 .bDescriptorType = USB_DT_CS_INTERFACE,
127 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, 127 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
@@ -136,7 +136,7 @@ static struct usb_cdc_ether_desc ether_desc __initdata = {
136 136
137/* full speed support: */ 137/* full speed support: */
138 138
139static struct usb_endpoint_descriptor fs_subset_in_desc __initdata = { 139static struct usb_endpoint_descriptor fs_subset_in_desc = {
140 .bLength = USB_DT_ENDPOINT_SIZE, 140 .bLength = USB_DT_ENDPOINT_SIZE,
141 .bDescriptorType = USB_DT_ENDPOINT, 141 .bDescriptorType = USB_DT_ENDPOINT,
142 142
@@ -144,7 +144,7 @@ static struct usb_endpoint_descriptor fs_subset_in_desc __initdata = {
144 .bmAttributes = USB_ENDPOINT_XFER_BULK, 144 .bmAttributes = USB_ENDPOINT_XFER_BULK,
145}; 145};
146 146
147static struct usb_endpoint_descriptor fs_subset_out_desc __initdata = { 147static struct usb_endpoint_descriptor fs_subset_out_desc = {
148 .bLength = USB_DT_ENDPOINT_SIZE, 148 .bLength = USB_DT_ENDPOINT_SIZE,
149 .bDescriptorType = USB_DT_ENDPOINT, 149 .bDescriptorType = USB_DT_ENDPOINT,
150 150
@@ -152,7 +152,7 @@ static struct usb_endpoint_descriptor fs_subset_out_desc __initdata = {
152 .bmAttributes = USB_ENDPOINT_XFER_BULK, 152 .bmAttributes = USB_ENDPOINT_XFER_BULK,
153}; 153};
154 154
155static struct usb_descriptor_header *fs_eth_function[] __initdata = { 155static struct usb_descriptor_header *fs_eth_function[] = {
156 (struct usb_descriptor_header *) &subset_data_intf, 156 (struct usb_descriptor_header *) &subset_data_intf,
157 (struct usb_descriptor_header *) &mdlm_header_desc, 157 (struct usb_descriptor_header *) &mdlm_header_desc,
158 (struct usb_descriptor_header *) &mdlm_desc, 158 (struct usb_descriptor_header *) &mdlm_desc,
@@ -165,7 +165,7 @@ static struct usb_descriptor_header *fs_eth_function[] __initdata = {
165 165
166/* high speed support: */ 166/* high speed support: */
167 167
168static struct usb_endpoint_descriptor hs_subset_in_desc __initdata = { 168static struct usb_endpoint_descriptor hs_subset_in_desc = {
169 .bLength = USB_DT_ENDPOINT_SIZE, 169 .bLength = USB_DT_ENDPOINT_SIZE,
170 .bDescriptorType = USB_DT_ENDPOINT, 170 .bDescriptorType = USB_DT_ENDPOINT,
171 171
@@ -173,7 +173,7 @@ static struct usb_endpoint_descriptor hs_subset_in_desc __initdata = {
173 .wMaxPacketSize = cpu_to_le16(512), 173 .wMaxPacketSize = cpu_to_le16(512),
174}; 174};
175 175
176static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = { 176static struct usb_endpoint_descriptor hs_subset_out_desc = {
177 .bLength = USB_DT_ENDPOINT_SIZE, 177 .bLength = USB_DT_ENDPOINT_SIZE,
178 .bDescriptorType = USB_DT_ENDPOINT, 178 .bDescriptorType = USB_DT_ENDPOINT,
179 179
@@ -181,7 +181,7 @@ static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = {
181 .wMaxPacketSize = cpu_to_le16(512), 181 .wMaxPacketSize = cpu_to_le16(512),
182}; 182};
183 183
184static struct usb_descriptor_header *hs_eth_function[] __initdata = { 184static struct usb_descriptor_header *hs_eth_function[] = {
185 (struct usb_descriptor_header *) &subset_data_intf, 185 (struct usb_descriptor_header *) &subset_data_intf,
186 (struct usb_descriptor_header *) &mdlm_header_desc, 186 (struct usb_descriptor_header *) &mdlm_header_desc,
187 (struct usb_descriptor_header *) &mdlm_desc, 187 (struct usb_descriptor_header *) &mdlm_desc,
@@ -194,7 +194,7 @@ static struct usb_descriptor_header *hs_eth_function[] __initdata = {
194 194
195/* super speed support: */ 195/* super speed support: */
196 196
197static struct usb_endpoint_descriptor ss_subset_in_desc __initdata = { 197static struct usb_endpoint_descriptor ss_subset_in_desc = {
198 .bLength = USB_DT_ENDPOINT_SIZE, 198 .bLength = USB_DT_ENDPOINT_SIZE,
199 .bDescriptorType = USB_DT_ENDPOINT, 199 .bDescriptorType = USB_DT_ENDPOINT,
200 200
@@ -202,7 +202,7 @@ static struct usb_endpoint_descriptor ss_subset_in_desc __initdata = {
202 .wMaxPacketSize = cpu_to_le16(1024), 202 .wMaxPacketSize = cpu_to_le16(1024),
203}; 203};
204 204
205static struct usb_endpoint_descriptor ss_subset_out_desc __initdata = { 205static struct usb_endpoint_descriptor ss_subset_out_desc = {
206 .bLength = USB_DT_ENDPOINT_SIZE, 206 .bLength = USB_DT_ENDPOINT_SIZE,
207 .bDescriptorType = USB_DT_ENDPOINT, 207 .bDescriptorType = USB_DT_ENDPOINT,
208 208
@@ -210,7 +210,7 @@ static struct usb_endpoint_descriptor ss_subset_out_desc __initdata = {
210 .wMaxPacketSize = cpu_to_le16(1024), 210 .wMaxPacketSize = cpu_to_le16(1024),
211}; 211};
212 212
213static struct usb_ss_ep_comp_descriptor ss_subset_bulk_comp_desc __initdata = { 213static struct usb_ss_ep_comp_descriptor ss_subset_bulk_comp_desc = {
214 .bLength = sizeof ss_subset_bulk_comp_desc, 214 .bLength = sizeof ss_subset_bulk_comp_desc,
215 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 215 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
216 216
@@ -219,7 +219,7 @@ static struct usb_ss_ep_comp_descriptor ss_subset_bulk_comp_desc __initdata = {
219 /* .bmAttributes = 0, */ 219 /* .bmAttributes = 0, */
220}; 220};
221 221
222static struct usb_descriptor_header *ss_eth_function[] __initdata = { 222static struct usb_descriptor_header *ss_eth_function[] = {
223 (struct usb_descriptor_header *) &subset_data_intf, 223 (struct usb_descriptor_header *) &subset_data_intf,
224 (struct usb_descriptor_header *) &mdlm_header_desc, 224 (struct usb_descriptor_header *) &mdlm_header_desc,
225 (struct usb_descriptor_header *) &mdlm_desc, 225 (struct usb_descriptor_header *) &mdlm_desc,
@@ -290,7 +290,7 @@ static void geth_disable(struct usb_function *f)
290 290
291/* serial function driver setup/binding */ 291/* serial function driver setup/binding */
292 292
293static int __init 293static int
294geth_bind(struct usb_configuration *c, struct usb_function *f) 294geth_bind(struct usb_configuration *c, struct usb_function *f)
295{ 295{
296 struct usb_composite_dev *cdev = c->cdev; 296 struct usb_composite_dev *cdev = c->cdev;
@@ -404,7 +404,7 @@ geth_unbind(struct usb_configuration *c, struct usb_function *f)
404 * Caller must have called @gether_setup(). Caller is also responsible 404 * Caller must have called @gether_setup(). Caller is also responsible
405 * for calling @gether_cleanup() before module unload. 405 * for calling @gether_cleanup() before module unload.
406 */ 406 */
407int __init geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 407int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
408{ 408{
409 struct f_gether *geth; 409 struct f_gether *geth;
410 int status; 410 int status;
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_uac1.c
index ec7ffcd0d0cd..1a5dcd5565e3 100644
--- a/drivers/usb/gadget/f_audio.c
+++ b/drivers/usb/gadget/f_uac1.c
@@ -14,7 +14,7 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/atomic.h> 15#include <linux/atomic.h>
16 16
17#include "u_audio.h" 17#include "u_uac1.h"
18 18
19#define OUT_EP_MAX_PACKET_SIZE 200 19#define OUT_EP_MAX_PACKET_SIZE 200
20static int req_buf_size = OUT_EP_MAX_PACKET_SIZE; 20static int req_buf_size = OUT_EP_MAX_PACKET_SIZE;
@@ -216,29 +216,6 @@ static struct usb_descriptor_header *f_audio_desc[] __initdata = {
216 NULL, 216 NULL,
217}; 217};
218 218
219/* string IDs are assigned dynamically */
220
221#define STRING_MANUFACTURER_IDX 0
222#define STRING_PRODUCT_IDX 1
223
224static char manufacturer[50];
225
226static struct usb_string strings_dev[] = {
227 [STRING_MANUFACTURER_IDX].s = manufacturer,
228 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
229 { } /* end of list */
230};
231
232static struct usb_gadget_strings stringtab_dev = {
233 .language = 0x0409, /* en-us */
234 .strings = strings_dev,
235};
236
237static struct usb_gadget_strings *audio_strings[] = {
238 &stringtab_dev,
239 NULL,
240};
241
242/* 219/*
243 * This function is an ALSA sound card following USB Audio Class Spec 1.0. 220 * This function is an ALSA sound card following USB Audio Class Spec 1.0.
244 */ 221 */
diff --git a/drivers/usb/gadget/f_uac2.c b/drivers/usb/gadget/f_uac2.c
new file mode 100644
index 000000000000..e7cc4de93e33
--- /dev/null
+++ b/drivers/usb/gadget/f_uac2.c
@@ -0,0 +1,1449 @@
1/*
2 * f_uac2.c -- USB Audio Class 2.0 Function
3 *
4 * Copyright (C) 2011
5 * Yadwinder Singh (yadi.brar01@gmail.com)
6 * Jaswinder Singh (jaswinder.singh@linaro.org)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/usb/audio.h>
15#include <linux/usb/audio-v2.h>
16#include <linux/platform_device.h>
17#include <linux/module.h>
18
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22
23/* Playback(USB-IN) Default Stereo - Fl/Fr */
24static int p_chmask = 0x3;
25module_param(p_chmask, uint, S_IRUGO);
26MODULE_PARM_DESC(p_chmask, "Playback Channel Mask");
27
28/* Playback Default 48 KHz */
29static int p_srate = 48000;
30module_param(p_srate, uint, S_IRUGO);
31MODULE_PARM_DESC(p_srate, "Playback Sampling Rate");
32
33/* Playback Default 16bits/sample */
34static int p_ssize = 2;
35module_param(p_ssize, uint, S_IRUGO);
36MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)");
37
38/* Capture(USB-OUT) Default Stereo - Fl/Fr */
39static int c_chmask = 0x3;
40module_param(c_chmask, uint, S_IRUGO);
41MODULE_PARM_DESC(c_chmask, "Capture Channel Mask");
42
43/* Capture Default 64 KHz */
44static int c_srate = 64000;
45module_param(c_srate, uint, S_IRUGO);
46MODULE_PARM_DESC(c_srate, "Capture Sampling Rate");
47
48/* Capture Default 16bits/sample */
49static int c_ssize = 2;
50module_param(c_ssize, uint, S_IRUGO);
51MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)");
52
53#define DMA_ADDR_INVALID (~(dma_addr_t)0)
54
55#define ALT_SET(x, a) do {(x) &= ~0xff; (x) |= (a); } while (0)
56#define ALT_GET(x) ((x) & 0xff)
57#define INTF_SET(x, i) do {(x) &= 0xff; (x) |= ((i) << 8); } while (0)
58#define INTF_GET(x) ((x >> 8) & 0xff)
59
60/* Keep everyone on toes */
61#define USB_XFERS 2
62
63/*
64 * The driver implements a simple UAC_2 topology.
65 * USB-OUT -> IT_1 -> OT_3 -> ALSA_Capture
66 * ALSA_Playback -> IT_2 -> OT_4 -> USB-IN
67 * Capture and Playback sampling rates are independently
68 * controlled by two clock sources :
69 * CLK_5 := c_srate, and CLK_6 := p_srate
70 */
71#define USB_OUT_IT_ID 1
72#define IO_IN_IT_ID 2
73#define IO_OUT_OT_ID 3
74#define USB_IN_OT_ID 4
75#define USB_OUT_CLK_ID 5
76#define USB_IN_CLK_ID 6
77
78#define CONTROL_ABSENT 0
79#define CONTROL_RDONLY 1
80#define CONTROL_RDWR 3
81
82#define CLK_FREQ_CTRL 0
83#define CLK_VLD_CTRL 2
84
85#define COPY_CTRL 0
86#define CONN_CTRL 2
87#define OVRLD_CTRL 4
88#define CLSTR_CTRL 6
89#define UNFLW_CTRL 8
90#define OVFLW_CTRL 10
91
92const char *uac2_name = "snd_uac2";
93
94struct uac2_req {
95 struct uac2_rtd_params *pp; /* parent param */
96 struct usb_request *req;
97};
98
99struct uac2_rtd_params {
100 bool ep_enabled; /* if the ep is enabled */
101 /* Size of the ring buffer */
102 size_t dma_bytes;
103 unsigned char *dma_area;
104
105 struct snd_pcm_substream *ss;
106
107 /* Ring buffer */
108 ssize_t hw_ptr;
109
110 void *rbuf;
111
112 size_t period_size;
113
114 unsigned max_psize;
115 struct uac2_req ureq[USB_XFERS];
116
117 spinlock_t lock;
118};
119
120struct snd_uac2_chip {
121 struct platform_device pdev;
122 struct platform_driver pdrv;
123
124 struct uac2_rtd_params p_prm;
125 struct uac2_rtd_params c_prm;
126
127 struct snd_card *card;
128 struct snd_pcm *pcm;
129};
130
131#define BUFF_SIZE_MAX (PAGE_SIZE * 16)
132#define PRD_SIZE_MAX PAGE_SIZE
133#define MIN_PERIODS 4
134
135static struct snd_pcm_hardware uac2_pcm_hardware = {
136 .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER
137 | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID
138 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
139 .rates = SNDRV_PCM_RATE_CONTINUOUS,
140 .periods_max = BUFF_SIZE_MAX / PRD_SIZE_MAX,
141 .buffer_bytes_max = BUFF_SIZE_MAX,
142 .period_bytes_max = PRD_SIZE_MAX,
143 .periods_min = MIN_PERIODS,
144};
145
146struct audio_dev {
147 /* Currently active {Interface[15:8] | AltSettings[7:0]} */
148 __u16 ac_alt, as_out_alt, as_in_alt;
149
150 struct usb_ep *in_ep, *out_ep;
151 struct usb_function func;
152
153 /* The ALSA Sound Card it represents on the USB-Client side */
154 struct snd_uac2_chip uac2;
155};
156
157static struct audio_dev *agdev_g;
158
159static inline
160struct audio_dev *func_to_agdev(struct usb_function *f)
161{
162 return container_of(f, struct audio_dev, func);
163}
164
165static inline
166struct audio_dev *uac2_to_agdev(struct snd_uac2_chip *u)
167{
168 return container_of(u, struct audio_dev, uac2);
169}
170
171static inline
172struct snd_uac2_chip *pdev_to_uac2(struct platform_device *p)
173{
174 return container_of(p, struct snd_uac2_chip, pdev);
175}
176
177static inline
178struct snd_uac2_chip *prm_to_uac2(struct uac2_rtd_params *r)
179{
180 struct snd_uac2_chip *uac2 = container_of(r,
181 struct snd_uac2_chip, c_prm);
182
183 if (&uac2->c_prm != r)
184 uac2 = container_of(r, struct snd_uac2_chip, p_prm);
185
186 return uac2;
187}
188
189static inline
190uint num_channels(uint chanmask)
191{
192 uint num = 0;
193
194 while (chanmask) {
195 num += (chanmask & 1);
196 chanmask >>= 1;
197 }
198
199 return num;
200}
201
202static void
203agdev_iso_complete(struct usb_ep *ep, struct usb_request *req)
204{
205 unsigned pending;
206 unsigned long flags;
207 bool update_alsa = false;
208 unsigned char *src, *dst;
209 int status = req->status;
210 struct uac2_req *ur = req->context;
211 struct snd_pcm_substream *substream;
212 struct uac2_rtd_params *prm = ur->pp;
213 struct snd_uac2_chip *uac2 = prm_to_uac2(prm);
214
215 /* i/f shutting down */
216 if (!prm->ep_enabled)
217 return;
218
219 /*
220 * We can't really do much about bad xfers.
221 * Afterall, the ISOCH xfers could fail legitimately.
222 */
223 if (status)
224 pr_debug("%s: iso_complete status(%d) %d/%d\n",
225 __func__, status, req->actual, req->length);
226
227 substream = prm->ss;
228
229 /* Do nothing if ALSA isn't active */
230 if (!substream)
231 goto exit;
232
233 spin_lock_irqsave(&prm->lock, flags);
234
235 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
236 src = prm->dma_area + prm->hw_ptr;
237 req->actual = req->length;
238 dst = req->buf;
239 } else {
240 dst = prm->dma_area + prm->hw_ptr;
241 src = req->buf;
242 }
243
244 pending = prm->hw_ptr % prm->period_size;
245 pending += req->actual;
246 if (pending >= prm->period_size)
247 update_alsa = true;
248
249 prm->hw_ptr = (prm->hw_ptr + req->actual) % prm->dma_bytes;
250
251 spin_unlock_irqrestore(&prm->lock, flags);
252
253 /* Pack USB load in ALSA ring buffer */
254 memcpy(dst, src, req->actual);
255exit:
256 if (usb_ep_queue(ep, req, GFP_ATOMIC))
257 dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__);
258
259 if (update_alsa)
260 snd_pcm_period_elapsed(substream);
261
262 return;
263}
264
265static int
266uac2_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
267{
268 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream);
269 struct audio_dev *agdev = uac2_to_agdev(uac2);
270 struct uac2_rtd_params *prm;
271 unsigned long flags;
272 struct usb_ep *ep;
273 int err = 0;
274
275 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
276 ep = agdev->in_ep;
277 prm = &uac2->p_prm;
278 } else {
279 ep = agdev->out_ep;
280 prm = &uac2->c_prm;
281 }
282
283 spin_lock_irqsave(&prm->lock, flags);
284
285 /* Reset */
286 prm->hw_ptr = 0;
287
288 switch (cmd) {
289 case SNDRV_PCM_TRIGGER_START:
290 case SNDRV_PCM_TRIGGER_RESUME:
291 prm->ss = substream;
292 break;
293 case SNDRV_PCM_TRIGGER_STOP:
294 case SNDRV_PCM_TRIGGER_SUSPEND:
295 prm->ss = NULL;
296 break;
297 default:
298 err = -EINVAL;
299 }
300
301 spin_unlock_irqrestore(&prm->lock, flags);
302
303 /* Clear buffer after Play stops */
304 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !prm->ss)
305 memset(prm->rbuf, 0, prm->max_psize * USB_XFERS);
306
307 return err;
308}
309
310static snd_pcm_uframes_t uac2_pcm_pointer(struct snd_pcm_substream *substream)
311{
312 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream);
313 struct uac2_rtd_params *prm;
314
315 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
316 prm = &uac2->p_prm;
317 else
318 prm = &uac2->c_prm;
319
320 return bytes_to_frames(substream->runtime, prm->hw_ptr);
321}
322
323static int uac2_pcm_hw_params(struct snd_pcm_substream *substream,
324 struct snd_pcm_hw_params *hw_params)
325{
326 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream);
327 struct uac2_rtd_params *prm;
328 int err;
329
330 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
331 prm = &uac2->p_prm;
332 else
333 prm = &uac2->c_prm;
334
335 err = snd_pcm_lib_malloc_pages(substream,
336 params_buffer_bytes(hw_params));
337 if (err >= 0) {
338 prm->dma_bytes = substream->runtime->dma_bytes;
339 prm->dma_area = substream->runtime->dma_area;
340 prm->period_size = params_period_bytes(hw_params);
341 }
342
343 return err;
344}
345
346static int uac2_pcm_hw_free(struct snd_pcm_substream *substream)
347{
348 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream);
349 struct uac2_rtd_params *prm;
350
351 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
352 prm = &uac2->p_prm;
353 else
354 prm = &uac2->c_prm;
355
356 prm->dma_area = NULL;
357 prm->dma_bytes = 0;
358 prm->period_size = 0;
359
360 return snd_pcm_lib_free_pages(substream);
361}
362
363static int uac2_pcm_open(struct snd_pcm_substream *substream)
364{
365 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream);
366 struct snd_pcm_runtime *runtime = substream->runtime;
367
368 runtime->hw = uac2_pcm_hardware;
369
370 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
371 spin_lock_init(&uac2->p_prm.lock);
372 runtime->hw.rate_min = p_srate;
373 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; /* ! p_ssize ! */
374 runtime->hw.channels_min = num_channels(p_chmask);
375 runtime->hw.period_bytes_min = 2 * uac2->p_prm.max_psize
376 / runtime->hw.periods_min;
377 } else {
378 spin_lock_init(&uac2->c_prm.lock);
379 runtime->hw.rate_min = c_srate;
380 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; /* ! c_ssize ! */
381 runtime->hw.channels_min = num_channels(c_chmask);
382 runtime->hw.period_bytes_min = 2 * uac2->c_prm.max_psize
383 / runtime->hw.periods_min;
384 }
385
386 runtime->hw.rate_max = runtime->hw.rate_min;
387 runtime->hw.channels_max = runtime->hw.channels_min;
388
389 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
390
391 return 0;
392}
393
394/* ALSA cries without these function pointers */
395static int uac2_pcm_null(struct snd_pcm_substream *substream)
396{
397 return 0;
398}
399
400static struct snd_pcm_ops uac2_pcm_ops = {
401 .open = uac2_pcm_open,
402 .close = uac2_pcm_null,
403 .ioctl = snd_pcm_lib_ioctl,
404 .hw_params = uac2_pcm_hw_params,
405 .hw_free = uac2_pcm_hw_free,
406 .trigger = uac2_pcm_trigger,
407 .pointer = uac2_pcm_pointer,
408 .prepare = uac2_pcm_null,
409};
410
411static int __devinit snd_uac2_probe(struct platform_device *pdev)
412{
413 struct snd_uac2_chip *uac2 = pdev_to_uac2(pdev);
414 struct snd_card *card;
415 struct snd_pcm *pcm;
416 int err;
417
418 /* Choose any slot, with no id */
419 err = snd_card_create(-1, NULL, THIS_MODULE, 0, &card);
420 if (err < 0)
421 return err;
422
423 uac2->card = card;
424
425 /*
426 * Create first PCM device
427 * Create a substream only for non-zero channel streams
428 */
429 err = snd_pcm_new(uac2->card, "UAC2 PCM", 0,
430 p_chmask ? 1 : 0, c_chmask ? 1 : 0, &pcm);
431 if (err < 0)
432 goto snd_fail;
433
434 strcpy(pcm->name, "UAC2 PCM");
435 pcm->private_data = uac2;
436
437 uac2->pcm = pcm;
438
439 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &uac2_pcm_ops);
440 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &uac2_pcm_ops);
441
442 strcpy(card->driver, "UAC2_Gadget");
443 strcpy(card->shortname, "UAC2_Gadget");
444 sprintf(card->longname, "UAC2_Gadget %i", pdev->id);
445
446 snd_card_set_dev(card, &pdev->dev);
447
448 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
449 snd_dma_continuous_data(GFP_KERNEL), 0, BUFF_SIZE_MAX);
450
451 err = snd_card_register(card);
452 if (!err) {
453 platform_set_drvdata(pdev, card);
454 return 0;
455 }
456
457snd_fail:
458 snd_card_free(card);
459
460 uac2->pcm = NULL;
461 uac2->card = NULL;
462
463 return err;
464}
465
466static int __devexit snd_uac2_remove(struct platform_device *pdev)
467{
468 struct snd_card *card = platform_get_drvdata(pdev);
469
470 platform_set_drvdata(pdev, NULL);
471
472 if (card)
473 return snd_card_free(card);
474
475 return 0;
476}
477
478static int alsa_uac2_init(struct audio_dev *agdev)
479{
480 struct snd_uac2_chip *uac2 = &agdev->uac2;
481 int err;
482
483 uac2->pdrv.probe = snd_uac2_probe;
484 uac2->pdrv.remove = snd_uac2_remove;
485 uac2->pdrv.driver.name = uac2_name;
486
487 uac2->pdev.id = 0;
488 uac2->pdev.name = uac2_name;
489
490 /* Register snd_uac2 driver */
491 err = platform_driver_register(&uac2->pdrv);
492 if (err)
493 return err;
494
495 /* Register snd_uac2 device */
496 err = platform_device_register(&uac2->pdev);
497 if (err)
498 platform_driver_unregister(&uac2->pdrv);
499
500 return err;
501}
502
503static void alsa_uac2_exit(struct audio_dev *agdev)
504{
505 struct snd_uac2_chip *uac2 = &agdev->uac2;
506
507 platform_driver_unregister(&uac2->pdrv);
508 platform_device_unregister(&uac2->pdev);
509}
510
511
512/* --------- USB Function Interface ------------- */
513
514enum {
515 STR_ASSOC,
516 STR_IF_CTRL,
517 STR_CLKSRC_IN,
518 STR_CLKSRC_OUT,
519 STR_USB_IT,
520 STR_IO_IT,
521 STR_USB_OT,
522 STR_IO_OT,
523 STR_AS_OUT_ALT0,
524 STR_AS_OUT_ALT1,
525 STR_AS_IN_ALT0,
526 STR_AS_IN_ALT1,
527};
528
529static const char ifassoc[] = "Source/Sink";
530static const char ifctrl[] = "Topology Control";
531static char clksrc_in[8];
532static char clksrc_out[8];
533static const char usb_it[] = "USBH Out";
534static const char io_it[] = "USBD Out";
535static const char usb_ot[] = "USBH In";
536static const char io_ot[] = "USBD In";
537static const char out_alt0[] = "Playback Inactive";
538static const char out_alt1[] = "Playback Active";
539static const char in_alt0[] = "Capture Inactive";
540static const char in_alt1[] = "Capture Active";
541
542static struct usb_string strings_fn[] = {
543 [STR_ASSOC].s = ifassoc,
544 [STR_IF_CTRL].s = ifctrl,
545 [STR_CLKSRC_IN].s = clksrc_in,
546 [STR_CLKSRC_OUT].s = clksrc_out,
547 [STR_USB_IT].s = usb_it,
548 [STR_IO_IT].s = io_it,
549 [STR_USB_OT].s = usb_ot,
550 [STR_IO_OT].s = io_ot,
551 [STR_AS_OUT_ALT0].s = out_alt0,
552 [STR_AS_OUT_ALT1].s = out_alt1,
553 [STR_AS_IN_ALT0].s = in_alt0,
554 [STR_AS_IN_ALT1].s = in_alt1,
555 { },
556};
557
558static struct usb_gadget_strings str_fn = {
559 .language = 0x0409, /* en-us */
560 .strings = strings_fn,
561};
562
563static struct usb_gadget_strings *fn_strings[] = {
564 &str_fn,
565 NULL,
566};
567
568static struct usb_qualifier_descriptor devqual_desc = {
569 .bLength = sizeof devqual_desc,
570 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
571
572 .bcdUSB = cpu_to_le16(0x200),
573 .bDeviceClass = USB_CLASS_MISC,
574 .bDeviceSubClass = 0x02,
575 .bDeviceProtocol = 0x01,
576 .bNumConfigurations = 1,
577 .bRESERVED = 0,
578};
579
580static struct usb_interface_assoc_descriptor iad_desc = {
581 .bLength = sizeof iad_desc,
582 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
583
584 .bFirstInterface = 0,
585 .bInterfaceCount = 3,
586 .bFunctionClass = USB_CLASS_AUDIO,
587 .bFunctionSubClass = UAC2_FUNCTION_SUBCLASS_UNDEFINED,
588 .bFunctionProtocol = UAC_VERSION_2,
589};
590
591/* Audio Control Interface */
592static struct usb_interface_descriptor std_ac_if_desc = {
593 .bLength = sizeof std_ac_if_desc,
594 .bDescriptorType = USB_DT_INTERFACE,
595
596 .bAlternateSetting = 0,
597 .bNumEndpoints = 0,
598 .bInterfaceClass = USB_CLASS_AUDIO,
599 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
600 .bInterfaceProtocol = UAC_VERSION_2,
601};
602
603/* Clock source for IN traffic */
604struct uac_clock_source_descriptor in_clk_src_desc = {
605 .bLength = sizeof in_clk_src_desc,
606 .bDescriptorType = USB_DT_CS_INTERFACE,
607
608 .bDescriptorSubtype = UAC2_CLOCK_SOURCE,
609 .bClockID = USB_IN_CLK_ID,
610 .bmAttributes = UAC_CLOCK_SOURCE_TYPE_INT_FIXED,
611 .bmControls = (CONTROL_RDONLY << CLK_FREQ_CTRL),
612 .bAssocTerminal = 0,
613};
614
615/* Clock source for OUT traffic */
616struct uac_clock_source_descriptor out_clk_src_desc = {
617 .bLength = sizeof out_clk_src_desc,
618 .bDescriptorType = USB_DT_CS_INTERFACE,
619
620 .bDescriptorSubtype = UAC2_CLOCK_SOURCE,
621 .bClockID = USB_OUT_CLK_ID,
622 .bmAttributes = UAC_CLOCK_SOURCE_TYPE_INT_FIXED,
623 .bmControls = (CONTROL_RDONLY << CLK_FREQ_CTRL),
624 .bAssocTerminal = 0,
625};
626
627/* Input Terminal for USB_OUT */
628struct uac2_input_terminal_descriptor usb_out_it_desc = {
629 .bLength = sizeof usb_out_it_desc,
630 .bDescriptorType = USB_DT_CS_INTERFACE,
631
632 .bDescriptorSubtype = UAC_INPUT_TERMINAL,
633 .bTerminalID = USB_OUT_IT_ID,
634 .wTerminalType = cpu_to_le16(UAC_TERMINAL_STREAMING),
635 .bAssocTerminal = 0,
636 .bCSourceID = USB_OUT_CLK_ID,
637 .iChannelNames = 0,
638 .bmControls = (CONTROL_RDWR << COPY_CTRL),
639};
640
641/* Input Terminal for I/O-In */
642struct uac2_input_terminal_descriptor io_in_it_desc = {
643 .bLength = sizeof io_in_it_desc,
644 .bDescriptorType = USB_DT_CS_INTERFACE,
645
646 .bDescriptorSubtype = UAC_INPUT_TERMINAL,
647 .bTerminalID = IO_IN_IT_ID,
648 .wTerminalType = cpu_to_le16(UAC_INPUT_TERMINAL_UNDEFINED),
649 .bAssocTerminal = 0,
650 .bCSourceID = USB_IN_CLK_ID,
651 .iChannelNames = 0,
652 .bmControls = (CONTROL_RDWR << COPY_CTRL),
653};
654
655/* Ouput Terminal for USB_IN */
656struct uac2_output_terminal_descriptor usb_in_ot_desc = {
657 .bLength = sizeof usb_in_ot_desc,
658 .bDescriptorType = USB_DT_CS_INTERFACE,
659
660 .bDescriptorSubtype = UAC_OUTPUT_TERMINAL,
661 .bTerminalID = USB_IN_OT_ID,
662 .wTerminalType = cpu_to_le16(UAC_TERMINAL_STREAMING),
663 .bAssocTerminal = 0,
664 .bSourceID = IO_IN_IT_ID,
665 .bCSourceID = USB_IN_CLK_ID,
666 .bmControls = (CONTROL_RDWR << COPY_CTRL),
667};
668
669/* Ouput Terminal for I/O-Out */
670struct uac2_output_terminal_descriptor io_out_ot_desc = {
671 .bLength = sizeof io_out_ot_desc,
672 .bDescriptorType = USB_DT_CS_INTERFACE,
673
674 .bDescriptorSubtype = UAC_OUTPUT_TERMINAL,
675 .bTerminalID = IO_OUT_OT_ID,
676 .wTerminalType = cpu_to_le16(UAC_OUTPUT_TERMINAL_UNDEFINED),
677 .bAssocTerminal = 0,
678 .bSourceID = USB_OUT_IT_ID,
679 .bCSourceID = USB_OUT_CLK_ID,
680 .bmControls = (CONTROL_RDWR << COPY_CTRL),
681};
682
683struct uac2_ac_header_descriptor ac_hdr_desc = {
684 .bLength = sizeof ac_hdr_desc,
685 .bDescriptorType = USB_DT_CS_INTERFACE,
686
687 .bDescriptorSubtype = UAC_MS_HEADER,
688 .bcdADC = cpu_to_le16(0x200),
689 .bCategory = UAC2_FUNCTION_IO_BOX,
690 .wTotalLength = sizeof in_clk_src_desc + sizeof out_clk_src_desc
691 + sizeof usb_out_it_desc + sizeof io_in_it_desc
692 + sizeof usb_in_ot_desc + sizeof io_out_ot_desc,
693 .bmControls = 0,
694};
695
696/* Audio Streaming OUT Interface - Alt0 */
697static struct usb_interface_descriptor std_as_out_if0_desc = {
698 .bLength = sizeof std_as_out_if0_desc,
699 .bDescriptorType = USB_DT_INTERFACE,
700
701 .bAlternateSetting = 0,
702 .bNumEndpoints = 0,
703 .bInterfaceClass = USB_CLASS_AUDIO,
704 .bInterfaceSubClass = USB_SUBCLASS_AUDIOSTREAMING,
705 .bInterfaceProtocol = UAC_VERSION_2,
706};
707
708/* Audio Streaming OUT Interface - Alt1 */
709static struct usb_interface_descriptor std_as_out_if1_desc = {
710 .bLength = sizeof std_as_out_if1_desc,
711 .bDescriptorType = USB_DT_INTERFACE,
712
713 .bAlternateSetting = 1,
714 .bNumEndpoints = 1,
715 .bInterfaceClass = USB_CLASS_AUDIO,
716 .bInterfaceSubClass = USB_SUBCLASS_AUDIOSTREAMING,
717 .bInterfaceProtocol = UAC_VERSION_2,
718};
719
720/* Audio Stream OUT Intface Desc */
721struct uac2_as_header_descriptor as_out_hdr_desc = {
722 .bLength = sizeof as_out_hdr_desc,
723 .bDescriptorType = USB_DT_CS_INTERFACE,
724
725 .bDescriptorSubtype = UAC_AS_GENERAL,
726 .bTerminalLink = USB_OUT_IT_ID,
727 .bmControls = 0,
728 .bFormatType = UAC_FORMAT_TYPE_I,
729 .bmFormats = cpu_to_le32(UAC_FORMAT_TYPE_I_PCM),
730 .iChannelNames = 0,
731};
732
733/* Audio USB_OUT Format */
734struct uac2_format_type_i_descriptor as_out_fmt1_desc = {
735 .bLength = sizeof as_out_fmt1_desc,
736 .bDescriptorType = USB_DT_CS_INTERFACE,
737 .bDescriptorSubtype = UAC_FORMAT_TYPE,
738 .bFormatType = UAC_FORMAT_TYPE_I,
739};
740
741/* STD AS ISO OUT Endpoint */
742struct usb_endpoint_descriptor fs_epout_desc = {
743 .bLength = USB_DT_ENDPOINT_SIZE,
744 .bDescriptorType = USB_DT_ENDPOINT,
745
746 .bEndpointAddress = USB_DIR_OUT,
747 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
748 .bInterval = 1,
749};
750
751struct usb_endpoint_descriptor hs_epout_desc = {
752 .bLength = USB_DT_ENDPOINT_SIZE,
753 .bDescriptorType = USB_DT_ENDPOINT,
754
755 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
756 .bInterval = 4,
757};
758
759/* CS AS ISO OUT Endpoint */
760static struct uac2_iso_endpoint_descriptor as_iso_out_desc = {
761 .bLength = sizeof as_iso_out_desc,
762 .bDescriptorType = USB_DT_CS_ENDPOINT,
763
764 .bDescriptorSubtype = UAC_EP_GENERAL,
765 .bmAttributes = 0,
766 .bmControls = 0,
767 .bLockDelayUnits = 0,
768 .wLockDelay = 0,
769};
770
771/* Audio Streaming IN Interface - Alt0 */
772static struct usb_interface_descriptor std_as_in_if0_desc = {
773 .bLength = sizeof std_as_in_if0_desc,
774 .bDescriptorType = USB_DT_INTERFACE,
775
776 .bAlternateSetting = 0,
777 .bNumEndpoints = 0,
778 .bInterfaceClass = USB_CLASS_AUDIO,
779 .bInterfaceSubClass = USB_SUBCLASS_AUDIOSTREAMING,
780 .bInterfaceProtocol = UAC_VERSION_2,
781};
782
783/* Audio Streaming IN Interface - Alt1 */
784static struct usb_interface_descriptor std_as_in_if1_desc = {
785 .bLength = sizeof std_as_in_if1_desc,
786 .bDescriptorType = USB_DT_INTERFACE,
787
788 .bAlternateSetting = 1,
789 .bNumEndpoints = 1,
790 .bInterfaceClass = USB_CLASS_AUDIO,
791 .bInterfaceSubClass = USB_SUBCLASS_AUDIOSTREAMING,
792 .bInterfaceProtocol = UAC_VERSION_2,
793};
794
795/* Audio Stream IN Intface Desc */
796struct uac2_as_header_descriptor as_in_hdr_desc = {
797 .bLength = sizeof as_in_hdr_desc,
798 .bDescriptorType = USB_DT_CS_INTERFACE,
799
800 .bDescriptorSubtype = UAC_AS_GENERAL,
801 .bTerminalLink = USB_IN_OT_ID,
802 .bmControls = 0,
803 .bFormatType = UAC_FORMAT_TYPE_I,
804 .bmFormats = cpu_to_le32(UAC_FORMAT_TYPE_I_PCM),
805 .iChannelNames = 0,
806};
807
808/* Audio USB_IN Format */
809struct uac2_format_type_i_descriptor as_in_fmt1_desc = {
810 .bLength = sizeof as_in_fmt1_desc,
811 .bDescriptorType = USB_DT_CS_INTERFACE,
812 .bDescriptorSubtype = UAC_FORMAT_TYPE,
813 .bFormatType = UAC_FORMAT_TYPE_I,
814};
815
816/* STD AS ISO IN Endpoint */
817struct usb_endpoint_descriptor fs_epin_desc = {
818 .bLength = USB_DT_ENDPOINT_SIZE,
819 .bDescriptorType = USB_DT_ENDPOINT,
820
821 .bEndpointAddress = USB_DIR_IN,
822 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
823 .bInterval = 1,
824};
825
826struct usb_endpoint_descriptor hs_epin_desc = {
827 .bLength = USB_DT_ENDPOINT_SIZE,
828 .bDescriptorType = USB_DT_ENDPOINT,
829
830 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
831 .bInterval = 4,
832};
833
834/* CS AS ISO IN Endpoint */
835static struct uac2_iso_endpoint_descriptor as_iso_in_desc = {
836 .bLength = sizeof as_iso_in_desc,
837 .bDescriptorType = USB_DT_CS_ENDPOINT,
838
839 .bDescriptorSubtype = UAC_EP_GENERAL,
840 .bmAttributes = 0,
841 .bmControls = 0,
842 .bLockDelayUnits = 0,
843 .wLockDelay = 0,
844};
845
846static struct usb_descriptor_header *fs_audio_desc[] = {
847 (struct usb_descriptor_header *)&iad_desc,
848 (struct usb_descriptor_header *)&std_ac_if_desc,
849
850 (struct usb_descriptor_header *)&ac_hdr_desc,
851 (struct usb_descriptor_header *)&in_clk_src_desc,
852 (struct usb_descriptor_header *)&out_clk_src_desc,
853 (struct usb_descriptor_header *)&usb_out_it_desc,
854 (struct usb_descriptor_header *)&io_in_it_desc,
855 (struct usb_descriptor_header *)&usb_in_ot_desc,
856 (struct usb_descriptor_header *)&io_out_ot_desc,
857
858 (struct usb_descriptor_header *)&std_as_out_if0_desc,
859 (struct usb_descriptor_header *)&std_as_out_if1_desc,
860
861 (struct usb_descriptor_header *)&as_out_hdr_desc,
862 (struct usb_descriptor_header *)&as_out_fmt1_desc,
863 (struct usb_descriptor_header *)&fs_epout_desc,
864 (struct usb_descriptor_header *)&as_iso_out_desc,
865
866 (struct usb_descriptor_header *)&std_as_in_if0_desc,
867 (struct usb_descriptor_header *)&std_as_in_if1_desc,
868
869 (struct usb_descriptor_header *)&as_in_hdr_desc,
870 (struct usb_descriptor_header *)&as_in_fmt1_desc,
871 (struct usb_descriptor_header *)&fs_epin_desc,
872 (struct usb_descriptor_header *)&as_iso_in_desc,
873 NULL,
874};
875
876static struct usb_descriptor_header *hs_audio_desc[] = {
877 (struct usb_descriptor_header *)&iad_desc,
878 (struct usb_descriptor_header *)&std_ac_if_desc,
879
880 (struct usb_descriptor_header *)&ac_hdr_desc,
881 (struct usb_descriptor_header *)&in_clk_src_desc,
882 (struct usb_descriptor_header *)&out_clk_src_desc,
883 (struct usb_descriptor_header *)&usb_out_it_desc,
884 (struct usb_descriptor_header *)&io_in_it_desc,
885 (struct usb_descriptor_header *)&usb_in_ot_desc,
886 (struct usb_descriptor_header *)&io_out_ot_desc,
887
888 (struct usb_descriptor_header *)&std_as_out_if0_desc,
889 (struct usb_descriptor_header *)&std_as_out_if1_desc,
890
891 (struct usb_descriptor_header *)&as_out_hdr_desc,
892 (struct usb_descriptor_header *)&as_out_fmt1_desc,
893 (struct usb_descriptor_header *)&hs_epout_desc,
894 (struct usb_descriptor_header *)&as_iso_out_desc,
895
896 (struct usb_descriptor_header *)&std_as_in_if0_desc,
897 (struct usb_descriptor_header *)&std_as_in_if1_desc,
898
899 (struct usb_descriptor_header *)&as_in_hdr_desc,
900 (struct usb_descriptor_header *)&as_in_fmt1_desc,
901 (struct usb_descriptor_header *)&hs_epin_desc,
902 (struct usb_descriptor_header *)&as_iso_in_desc,
903 NULL,
904};
905
906struct cntrl_cur_lay3 {
907 __u32 dCUR;
908};
909
910struct cntrl_range_lay3 {
911 __u16 wNumSubRanges;
912 __u32 dMIN;
913 __u32 dMAX;
914 __u32 dRES;
915} __packed;
916
917static inline void
918free_ep(struct uac2_rtd_params *prm, struct usb_ep *ep)
919{
920 struct snd_uac2_chip *uac2 = prm_to_uac2(prm);
921 int i;
922
923 prm->ep_enabled = false;
924
925 for (i = 0; i < USB_XFERS; i++) {
926 if (prm->ureq[i].req) {
927 usb_ep_dequeue(ep, prm->ureq[i].req);
928 usb_ep_free_request(ep, prm->ureq[i].req);
929 prm->ureq[i].req = NULL;
930 }
931 }
932
933 if (usb_ep_disable(ep))
934 dev_err(&uac2->pdev.dev,
935 "%s:%d Error!\n", __func__, __LINE__);
936}
937
938static int __init
939afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
940{
941 struct audio_dev *agdev = func_to_agdev(fn);
942 struct snd_uac2_chip *uac2 = &agdev->uac2;
943 struct usb_composite_dev *cdev = cfg->cdev;
944 struct usb_gadget *gadget = cdev->gadget;
945 struct uac2_rtd_params *prm;
946 int ret;
947
948 ret = usb_interface_id(cfg, fn);
949 if (ret < 0) {
950 dev_err(&uac2->pdev.dev,
951 "%s:%d Error!\n", __func__, __LINE__);
952 return ret;
953 }
954 std_ac_if_desc.bInterfaceNumber = ret;
955 ALT_SET(agdev->ac_alt, 0);
956 INTF_SET(agdev->ac_alt, ret);
957
958 ret = usb_interface_id(cfg, fn);
959 if (ret < 0) {
960 dev_err(&uac2->pdev.dev,
961 "%s:%d Error!\n", __func__, __LINE__);
962 return ret;
963 }
964 std_as_out_if0_desc.bInterfaceNumber = ret;
965 std_as_out_if1_desc.bInterfaceNumber = ret;
966 ALT_SET(agdev->as_out_alt, 0);
967 INTF_SET(agdev->as_out_alt, ret);
968
969 ret = usb_interface_id(cfg, fn);
970 if (ret < 0) {
971 dev_err(&uac2->pdev.dev,
972 "%s:%d Error!\n", __func__, __LINE__);
973 return ret;
974 }
975 std_as_in_if0_desc.bInterfaceNumber = ret;
976 std_as_in_if1_desc.bInterfaceNumber = ret;
977 ALT_SET(agdev->as_in_alt, 0);
978 INTF_SET(agdev->as_in_alt, ret);
979
980 agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc);
981 if (!agdev->out_ep)
982 dev_err(&uac2->pdev.dev,
983 "%s:%d Error!\n", __func__, __LINE__);
984 agdev->out_ep->driver_data = agdev;
985
986 agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc);
987 if (!agdev->in_ep)
988 dev_err(&uac2->pdev.dev,
989 "%s:%d Error!\n", __func__, __LINE__);
990 agdev->in_ep->driver_data = agdev;
991
992 hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
993 hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;
994 hs_epin_desc.bEndpointAddress = fs_epin_desc.bEndpointAddress;
995 hs_epin_desc.wMaxPacketSize = fs_epin_desc.wMaxPacketSize;
996
997 fn->descriptors = usb_copy_descriptors(fs_audio_desc);
998 if (gadget_is_dualspeed(gadget))
999 fn->hs_descriptors = usb_copy_descriptors(hs_audio_desc);
1000
1001 prm = &agdev->uac2.c_prm;
1002 prm->max_psize = hs_epout_desc.wMaxPacketSize;
1003 prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL);
1004 if (!prm->rbuf) {
1005 prm->max_psize = 0;
1006 dev_err(&uac2->pdev.dev,
1007 "%s:%d Error!\n", __func__, __LINE__);
1008 }
1009
1010 prm = &agdev->uac2.p_prm;
1011 prm->max_psize = hs_epin_desc.wMaxPacketSize;
1012 prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL);
1013 if (!prm->rbuf) {
1014 prm->max_psize = 0;
1015 dev_err(&uac2->pdev.dev,
1016 "%s:%d Error!\n", __func__, __LINE__);
1017 }
1018
1019 return alsa_uac2_init(agdev);
1020}
1021
1022static void
1023afunc_unbind(struct usb_configuration *cfg, struct usb_function *fn)
1024{
1025 struct audio_dev *agdev = func_to_agdev(fn);
1026 struct usb_composite_dev *cdev = cfg->cdev;
1027 struct usb_gadget *gadget = cdev->gadget;
1028 struct uac2_rtd_params *prm;
1029
1030 alsa_uac2_exit(agdev);
1031
1032 prm = &agdev->uac2.p_prm;
1033 kfree(prm->rbuf);
1034
1035 prm = &agdev->uac2.c_prm;
1036 kfree(prm->rbuf);
1037
1038 if (gadget_is_dualspeed(gadget))
1039 usb_free_descriptors(fn->hs_descriptors);
1040 usb_free_descriptors(fn->descriptors);
1041
1042 if (agdev->in_ep)
1043 agdev->in_ep->driver_data = NULL;
1044 if (agdev->out_ep)
1045 agdev->out_ep->driver_data = NULL;
1046}
1047
1048static int
1049afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt)
1050{
1051 struct usb_composite_dev *cdev = fn->config->cdev;
1052 struct audio_dev *agdev = func_to_agdev(fn);
1053 struct snd_uac2_chip *uac2 = &agdev->uac2;
1054 struct usb_gadget *gadget = cdev->gadget;
1055 struct usb_request *req;
1056 struct usb_ep *ep;
1057 struct uac2_rtd_params *prm;
1058 int i;
1059
1060 /* No i/f has more than 2 alt settings */
1061 if (alt > 1) {
1062 dev_err(&uac2->pdev.dev,
1063 "%s:%d Error!\n", __func__, __LINE__);
1064 return -EINVAL;
1065 }
1066
1067 if (intf == INTF_GET(agdev->ac_alt)) {
1068 /* Control I/f has only 1 AltSetting - 0 */
1069 if (alt) {
1070 dev_err(&uac2->pdev.dev,
1071 "%s:%d Error!\n", __func__, __LINE__);
1072 return -EINVAL;
1073 }
1074 return 0;
1075 }
1076
1077 if (intf == INTF_GET(agdev->as_out_alt)) {
1078 ep = agdev->out_ep;
1079 prm = &uac2->c_prm;
1080 config_ep_by_speed(gadget, fn, ep);
1081 ALT_SET(agdev->as_out_alt, alt);
1082 } else if (intf == INTF_GET(agdev->as_in_alt)) {
1083 ep = agdev->in_ep;
1084 prm = &uac2->p_prm;
1085 config_ep_by_speed(gadget, fn, ep);
1086 ALT_SET(agdev->as_in_alt, alt);
1087 } else {
1088 dev_err(&uac2->pdev.dev,
1089 "%s:%d Error!\n", __func__, __LINE__);
1090 return -EINVAL;
1091 }
1092
1093 if (alt == 0) {
1094 free_ep(prm, ep);
1095 return 0;
1096 }
1097
1098 prm->ep_enabled = true;
1099 usb_ep_enable(ep);
1100
1101 for (i = 0; i < USB_XFERS; i++) {
1102 if (prm->ureq[i].req) {
1103 if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC))
1104 dev_err(&uac2->pdev.dev, "%d Error!\n",
1105 __LINE__);
1106 continue;
1107 }
1108
1109 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
1110 if (req == NULL) {
1111 dev_err(&uac2->pdev.dev,
1112 "%s:%d Error!\n", __func__, __LINE__);
1113 return -EINVAL;
1114 }
1115
1116 prm->ureq[i].req = req;
1117 prm->ureq[i].pp = prm;
1118
1119 req->zero = 0;
1120 req->dma = DMA_ADDR_INVALID;
1121 req->context = &prm->ureq[i];
1122 req->length = prm->max_psize;
1123 req->complete = agdev_iso_complete;
1124 req->buf = prm->rbuf + i * req->length;
1125
1126 if (usb_ep_queue(ep, req, GFP_ATOMIC))
1127 dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__);
1128 }
1129
1130 return 0;
1131}
1132
1133static int
1134afunc_get_alt(struct usb_function *fn, unsigned intf)
1135{
1136 struct audio_dev *agdev = func_to_agdev(fn);
1137 struct snd_uac2_chip *uac2 = &agdev->uac2;
1138
1139 if (intf == INTF_GET(agdev->ac_alt))
1140 return ALT_GET(agdev->ac_alt);
1141 else if (intf == INTF_GET(agdev->as_out_alt))
1142 return ALT_GET(agdev->as_out_alt);
1143 else if (intf == INTF_GET(agdev->as_in_alt))
1144 return ALT_GET(agdev->as_in_alt);
1145 else
1146 dev_err(&uac2->pdev.dev,
1147 "%s:%d Invalid Interface %d!\n",
1148 __func__, __LINE__, intf);
1149
1150 return -EINVAL;
1151}
1152
1153static void
1154afunc_disable(struct usb_function *fn)
1155{
1156 struct audio_dev *agdev = func_to_agdev(fn);
1157 struct snd_uac2_chip *uac2 = &agdev->uac2;
1158
1159 free_ep(&uac2->p_prm, agdev->in_ep);
1160 ALT_SET(agdev->as_in_alt, 0);
1161
1162 free_ep(&uac2->c_prm, agdev->out_ep);
1163 ALT_SET(agdev->as_out_alt, 0);
1164}
1165
1166static int
1167in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1168{
1169 struct usb_request *req = fn->config->cdev->req;
1170 struct audio_dev *agdev = func_to_agdev(fn);
1171 struct snd_uac2_chip *uac2 = &agdev->uac2;
1172 u16 w_length = le16_to_cpu(cr->wLength);
1173 u16 w_index = le16_to_cpu(cr->wIndex);
1174 u16 w_value = le16_to_cpu(cr->wValue);
1175 u8 entity_id = (w_index >> 8) & 0xff;
1176 u8 control_selector = w_value >> 8;
1177 int value = -EOPNOTSUPP;
1178
1179 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) {
1180 struct cntrl_cur_lay3 c;
1181
1182 if (entity_id == USB_IN_CLK_ID)
1183 c.dCUR = p_srate;
1184 else if (entity_id == USB_OUT_CLK_ID)
1185 c.dCUR = c_srate;
1186
1187 value = min_t(unsigned, w_length, sizeof c);
1188 memcpy(req->buf, &c, value);
1189 } else if (control_selector == UAC2_CS_CONTROL_CLOCK_VALID) {
1190 *(u8 *)req->buf = 1;
1191 value = min_t(unsigned, w_length, 1);
1192 } else {
1193 dev_err(&uac2->pdev.dev,
1194 "%s:%d control_selector=%d TODO!\n",
1195 __func__, __LINE__, control_selector);
1196 }
1197
1198 return value;
1199}
1200
1201static int
1202in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1203{
1204 struct usb_request *req = fn->config->cdev->req;
1205 struct audio_dev *agdev = func_to_agdev(fn);
1206 struct snd_uac2_chip *uac2 = &agdev->uac2;
1207 u16 w_length = le16_to_cpu(cr->wLength);
1208 u16 w_index = le16_to_cpu(cr->wIndex);
1209 u16 w_value = le16_to_cpu(cr->wValue);
1210 u8 entity_id = (w_index >> 8) & 0xff;
1211 u8 control_selector = w_value >> 8;
1212 struct cntrl_range_lay3 r;
1213 int value = -EOPNOTSUPP;
1214
1215 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) {
1216 if (entity_id == USB_IN_CLK_ID)
1217 r.dMIN = p_srate;
1218 else if (entity_id == USB_OUT_CLK_ID)
1219 r.dMIN = c_srate;
1220 else
1221 return -EOPNOTSUPP;
1222
1223 r.dMAX = r.dMIN;
1224 r.dRES = 0;
1225 r.wNumSubRanges = 1;
1226
1227 value = min_t(unsigned, w_length, sizeof r);
1228 memcpy(req->buf, &r, value);
1229 } else {
1230 dev_err(&uac2->pdev.dev,
1231 "%s:%d control_selector=%d TODO!\n",
1232 __func__, __LINE__, control_selector);
1233 }
1234
1235 return value;
1236}
1237
1238static int
1239ac_rq_in(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1240{
1241 if (cr->bRequest == UAC2_CS_CUR)
1242 return in_rq_cur(fn, cr);
1243 else if (cr->bRequest == UAC2_CS_RANGE)
1244 return in_rq_range(fn, cr);
1245 else
1246 return -EOPNOTSUPP;
1247}
1248
1249static int
1250out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1251{
1252 u16 w_length = le16_to_cpu(cr->wLength);
1253 u16 w_value = le16_to_cpu(cr->wValue);
1254 u8 control_selector = w_value >> 8;
1255
1256 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ)
1257 return w_length;
1258
1259 return -EOPNOTSUPP;
1260}
1261
1262static int
1263setup_rq_inf(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1264{
1265 struct audio_dev *agdev = func_to_agdev(fn);
1266 struct snd_uac2_chip *uac2 = &agdev->uac2;
1267 u16 w_index = le16_to_cpu(cr->wIndex);
1268 u8 intf = w_index & 0xff;
1269
1270 if (intf != INTF_GET(agdev->ac_alt)) {
1271 dev_err(&uac2->pdev.dev,
1272 "%s:%d Error!\n", __func__, __LINE__);
1273 return -EOPNOTSUPP;
1274 }
1275
1276 if (cr->bRequestType & USB_DIR_IN)
1277 return ac_rq_in(fn, cr);
1278 else if (cr->bRequest == UAC2_CS_CUR)
1279 return out_rq_cur(fn, cr);
1280
1281 return -EOPNOTSUPP;
1282}
1283
1284static int
1285afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1286{
1287 struct usb_composite_dev *cdev = fn->config->cdev;
1288 struct audio_dev *agdev = func_to_agdev(fn);
1289 struct snd_uac2_chip *uac2 = &agdev->uac2;
1290 struct usb_request *req = cdev->req;
1291 u16 w_length = le16_to_cpu(cr->wLength);
1292 int value = -EOPNOTSUPP;
1293
1294 /* Only Class specific requests are supposed to reach here */
1295 if ((cr->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS)
1296 return -EOPNOTSUPP;
1297
1298 if ((cr->bRequestType & USB_RECIP_MASK) == USB_RECIP_INTERFACE)
1299 value = setup_rq_inf(fn, cr);
1300 else
1301 dev_err(&uac2->pdev.dev, "%s:%d Error!\n", __func__, __LINE__);
1302
1303 if (value >= 0) {
1304 req->length = value;
1305 req->zero = value < w_length;
1306 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
1307 if (value < 0) {
1308 dev_err(&uac2->pdev.dev,
1309 "%s:%d Error!\n", __func__, __LINE__);
1310 req->status = 0;
1311 }
1312 }
1313
1314 return value;
1315}
1316
1317static int audio_bind_config(struct usb_configuration *cfg)
1318{
1319 int id, res;
1320
1321 agdev_g = kzalloc(sizeof *agdev_g, GFP_KERNEL);
1322 if (agdev_g == NULL) {
1323 printk(KERN_ERR "Unable to allocate audio gadget\n");
1324 return -ENOMEM;
1325 }
1326
1327 id = usb_string_id(cfg->cdev);
1328 if (id < 0)
1329 return id;
1330
1331 strings_fn[STR_ASSOC].id = id;
1332 iad_desc.iFunction = id,
1333
1334 id = usb_string_id(cfg->cdev);
1335 if (id < 0)
1336 return id;
1337
1338 strings_fn[STR_IF_CTRL].id = id;
1339 std_ac_if_desc.iInterface = id,
1340
1341 id = usb_string_id(cfg->cdev);
1342 if (id < 0)
1343 return id;
1344
1345 strings_fn[STR_CLKSRC_IN].id = id;
1346 in_clk_src_desc.iClockSource = id,
1347
1348 id = usb_string_id(cfg->cdev);
1349 if (id < 0)
1350 return id;
1351
1352 strings_fn[STR_CLKSRC_OUT].id = id;
1353 out_clk_src_desc.iClockSource = id,
1354
1355 id = usb_string_id(cfg->cdev);
1356 if (id < 0)
1357 return id;
1358
1359 strings_fn[STR_USB_IT].id = id;
1360 usb_out_it_desc.iTerminal = id,
1361
1362 id = usb_string_id(cfg->cdev);
1363 if (id < 0)
1364 return id;
1365
1366 strings_fn[STR_IO_IT].id = id;
1367 io_in_it_desc.iTerminal = id;
1368
1369 id = usb_string_id(cfg->cdev);
1370 if (id < 0)
1371 return id;
1372
1373 strings_fn[STR_USB_OT].id = id;
1374 usb_in_ot_desc.iTerminal = id;
1375
1376 id = usb_string_id(cfg->cdev);
1377 if (id < 0)
1378 return id;
1379
1380 strings_fn[STR_IO_OT].id = id;
1381 io_out_ot_desc.iTerminal = id;
1382
1383 id = usb_string_id(cfg->cdev);
1384 if (id < 0)
1385 return id;
1386
1387 strings_fn[STR_AS_OUT_ALT0].id = id;
1388 std_as_out_if0_desc.iInterface = id;
1389
1390 id = usb_string_id(cfg->cdev);
1391 if (id < 0)
1392 return id;
1393
1394 strings_fn[STR_AS_OUT_ALT1].id = id;
1395 std_as_out_if1_desc.iInterface = id;
1396
1397 id = usb_string_id(cfg->cdev);
1398 if (id < 0)
1399 return id;
1400
1401 strings_fn[STR_AS_IN_ALT0].id = id;
1402 std_as_in_if0_desc.iInterface = id;
1403
1404 id = usb_string_id(cfg->cdev);
1405 if (id < 0)
1406 return id;
1407
1408 strings_fn[STR_AS_IN_ALT1].id = id;
1409 std_as_in_if1_desc.iInterface = id;
1410
1411 agdev_g->func.name = "uac2_func";
1412 agdev_g->func.strings = fn_strings;
1413 agdev_g->func.bind = afunc_bind;
1414 agdev_g->func.unbind = afunc_unbind;
1415 agdev_g->func.set_alt = afunc_set_alt;
1416 agdev_g->func.get_alt = afunc_get_alt;
1417 agdev_g->func.disable = afunc_disable;
1418 agdev_g->func.setup = afunc_setup;
1419
1420 /* Initialize the configurable parameters */
1421 usb_out_it_desc.bNrChannels = num_channels(c_chmask);
1422 usb_out_it_desc.bmChannelConfig = cpu_to_le32(c_chmask);
1423 io_in_it_desc.bNrChannels = num_channels(p_chmask);
1424 io_in_it_desc.bmChannelConfig = cpu_to_le32(p_chmask);
1425 as_out_hdr_desc.bNrChannels = num_channels(c_chmask);
1426 as_out_hdr_desc.bmChannelConfig = cpu_to_le32(c_chmask);
1427 as_in_hdr_desc.bNrChannels = num_channels(p_chmask);
1428 as_in_hdr_desc.bmChannelConfig = cpu_to_le32(p_chmask);
1429 as_out_fmt1_desc.bSubslotSize = c_ssize;
1430 as_out_fmt1_desc.bBitResolution = c_ssize * 8;
1431 as_in_fmt1_desc.bSubslotSize = p_ssize;
1432 as_in_fmt1_desc.bBitResolution = p_ssize * 8;
1433
1434 snprintf(clksrc_in, sizeof(clksrc_in), "%uHz", p_srate);
1435 snprintf(clksrc_out, sizeof(clksrc_out), "%uHz", c_srate);
1436
1437 res = usb_add_function(cfg, &agdev_g->func);
1438 if (res < 0)
1439 kfree(agdev_g);
1440
1441 return res;
1442}
1443
1444static void
1445uac2_unbind_config(struct usb_configuration *cfg)
1446{
1447 kfree(agdev_g);
1448 agdev_g = NULL;
1449}
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 47766f0e7caa..4fac56927741 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -855,7 +855,7 @@ static int class_setup_req(struct fsg_dev *fsg,
855 if (transport_is_bbb()) { 855 if (transport_is_bbb()) {
856 switch (ctrl->bRequest) { 856 switch (ctrl->bRequest) {
857 857
858 case USB_BULK_RESET_REQUEST: 858 case US_BULK_RESET_REQUEST:
859 if (ctrl->bRequestType != (USB_DIR_OUT | 859 if (ctrl->bRequestType != (USB_DIR_OUT |
860 USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 860 USB_TYPE_CLASS | USB_RECIP_INTERFACE))
861 break; 861 break;
@@ -871,7 +871,7 @@ static int class_setup_req(struct fsg_dev *fsg,
871 value = DELAYED_STATUS; 871 value = DELAYED_STATUS;
872 break; 872 break;
873 873
874 case USB_BULK_GET_MAX_LUN_REQUEST: 874 case US_BULK_GET_MAX_LUN:
875 if (ctrl->bRequestType != (USB_DIR_IN | 875 if (ctrl->bRequestType != (USB_DIR_IN |
876 USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 876 USB_TYPE_CLASS | USB_RECIP_INTERFACE))
877 break; 877 break;
@@ -2125,7 +2125,7 @@ static int send_status(struct fsg_dev *fsg)
2125 struct fsg_lun *curlun = fsg->curlun; 2125 struct fsg_lun *curlun = fsg->curlun;
2126 struct fsg_buffhd *bh; 2126 struct fsg_buffhd *bh;
2127 int rc; 2127 int rc;
2128 u8 status = USB_STATUS_PASS; 2128 u8 status = US_BULK_STAT_OK;
2129 u32 sd, sdinfo = 0; 2129 u32 sd, sdinfo = 0;
2130 2130
2131 /* Wait for the next buffer to become available */ 2131 /* Wait for the next buffer to become available */
@@ -2146,11 +2146,11 @@ static int send_status(struct fsg_dev *fsg)
2146 2146
2147 if (fsg->phase_error) { 2147 if (fsg->phase_error) {
2148 DBG(fsg, "sending phase-error status\n"); 2148 DBG(fsg, "sending phase-error status\n");
2149 status = USB_STATUS_PHASE_ERROR; 2149 status = US_BULK_STAT_PHASE;
2150 sd = SS_INVALID_COMMAND; 2150 sd = SS_INVALID_COMMAND;
2151 } else if (sd != SS_NO_SENSE) { 2151 } else if (sd != SS_NO_SENSE) {
2152 DBG(fsg, "sending command-failure status\n"); 2152 DBG(fsg, "sending command-failure status\n");
2153 status = USB_STATUS_FAIL; 2153 status = US_BULK_STAT_FAIL;
2154 VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;" 2154 VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
2155 " info x%x\n", 2155 " info x%x\n",
2156 SK(sd), ASC(sd), ASCQ(sd), sdinfo); 2156 SK(sd), ASC(sd), ASCQ(sd), sdinfo);
@@ -2160,12 +2160,12 @@ static int send_status(struct fsg_dev *fsg)
2160 struct bulk_cs_wrap *csw = bh->buf; 2160 struct bulk_cs_wrap *csw = bh->buf;
2161 2161
2162 /* Store and send the Bulk-only CSW */ 2162 /* Store and send the Bulk-only CSW */
2163 csw->Signature = cpu_to_le32(USB_BULK_CS_SIG); 2163 csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
2164 csw->Tag = fsg->tag; 2164 csw->Tag = fsg->tag;
2165 csw->Residue = cpu_to_le32(fsg->residue); 2165 csw->Residue = cpu_to_le32(fsg->residue);
2166 csw->Status = status; 2166 csw->Status = status;
2167 2167
2168 bh->inreq->length = USB_BULK_CS_WRAP_LEN; 2168 bh->inreq->length = US_BULK_CS_WRAP_LEN;
2169 bh->inreq->zero = 0; 2169 bh->inreq->zero = 0;
2170 start_transfer(fsg, fsg->bulk_in, bh->inreq, 2170 start_transfer(fsg, fsg->bulk_in, bh->inreq,
2171 &bh->inreq_busy, &bh->state); 2171 &bh->inreq_busy, &bh->state);
@@ -2609,16 +2609,16 @@ static int do_scsi_command(struct fsg_dev *fsg)
2609static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) 2609static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2610{ 2610{
2611 struct usb_request *req = bh->outreq; 2611 struct usb_request *req = bh->outreq;
2612 struct fsg_bulk_cb_wrap *cbw = req->buf; 2612 struct bulk_cb_wrap *cbw = req->buf;
2613 2613
2614 /* Was this a real packet? Should it be ignored? */ 2614 /* Was this a real packet? Should it be ignored? */
2615 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags)) 2615 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
2616 return -EINVAL; 2616 return -EINVAL;
2617 2617
2618 /* Is the CBW valid? */ 2618 /* Is the CBW valid? */
2619 if (req->actual != USB_BULK_CB_WRAP_LEN || 2619 if (req->actual != US_BULK_CB_WRAP_LEN ||
2620 cbw->Signature != cpu_to_le32( 2620 cbw->Signature != cpu_to_le32(
2621 USB_BULK_CB_SIG)) { 2621 US_BULK_CB_SIGN)) {
2622 DBG(fsg, "invalid CBW: len %u sig 0x%x\n", 2622 DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
2623 req->actual, 2623 req->actual,
2624 le32_to_cpu(cbw->Signature)); 2624 le32_to_cpu(cbw->Signature));
@@ -2638,7 +2638,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2638 } 2638 }
2639 2639
2640 /* Is the CBW meaningful? */ 2640 /* Is the CBW meaningful? */
2641 if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG || 2641 if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
2642 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) { 2642 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
2643 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, " 2643 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
2644 "cmdlen %u\n", 2644 "cmdlen %u\n",
@@ -2656,7 +2656,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2656 /* Save the command for later */ 2656 /* Save the command for later */
2657 fsg->cmnd_size = cbw->Length; 2657 fsg->cmnd_size = cbw->Length;
2658 memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size); 2658 memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
2659 if (cbw->Flags & USB_BULK_IN_FLAG) 2659 if (cbw->Flags & US_BULK_FLAG_IN)
2660 fsg->data_dir = DATA_DIR_TO_HOST; 2660 fsg->data_dir = DATA_DIR_TO_HOST;
2661 else 2661 else
2662 fsg->data_dir = DATA_DIR_FROM_HOST; 2662 fsg->data_dir = DATA_DIR_FROM_HOST;
@@ -2685,7 +2685,7 @@ static int get_next_command(struct fsg_dev *fsg)
2685 } 2685 }
2686 2686
2687 /* Queue a request to read a Bulk-only CBW */ 2687 /* Queue a request to read a Bulk-only CBW */
2688 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN); 2688 set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
2689 start_transfer(fsg, fsg->bulk_out, bh->outreq, 2689 start_transfer(fsg, fsg->bulk_out, bh->outreq,
2690 &bh->outreq_busy, &bh->state); 2690 &bh->outreq_busy, &bh->state);
2691 2691
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index b95697c03d07..877a2c46672b 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -1638,6 +1638,7 @@ static int qe_ep_disable(struct usb_ep *_ep)
1638 /* Nuke all pending requests (does flush) */ 1638 /* Nuke all pending requests (does flush) */
1639 nuke(ep, -ESHUTDOWN); 1639 nuke(ep, -ESHUTDOWN);
1640 ep->desc = NULL; 1640 ep->desc = NULL;
1641 ep->ep.desc = NULL;
1641 ep->stopped = 1; 1642 ep->stopped = 1;
1642 ep->tx_req = NULL; 1643 ep->tx_req = NULL;
1643 qe_ep_reset(udc, ep->epnum); 1644 qe_ep_reset(udc, ep->epnum);
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index b04712f19f1e..5f94e79cd6b9 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -43,7 +43,6 @@
43 43
44#include <asm/byteorder.h> 44#include <asm/byteorder.h>
45#include <asm/io.h> 45#include <asm/io.h>
46#include <asm/system.h>
47#include <asm/unaligned.h> 46#include <asm/unaligned.h>
48#include <asm/dma.h> 47#include <asm/dma.h>
49 48
@@ -659,6 +658,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
659 nuke(ep, -ESHUTDOWN); 658 nuke(ep, -ESHUTDOWN);
660 659
661 ep->desc = NULL; 660 ep->desc = NULL;
661 ep->ep.desc = NULL;
662 ep->stopped = 1; 662 ep->stopped = 1;
663 spin_unlock_irqrestore(&udc->lock, flags); 663 spin_unlock_irqrestore(&udc->lock, flags);
664 664
@@ -768,7 +768,7 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
768 * @is_last: return flag if it is the last dTD of the request 768 * @is_last: return flag if it is the last dTD of the request
769 * return: pointer to the built dTD */ 769 * return: pointer to the built dTD */
770static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length, 770static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
771 dma_addr_t *dma, int *is_last) 771 dma_addr_t *dma, int *is_last, gfp_t gfp_flags)
772{ 772{
773 u32 swap_temp; 773 u32 swap_temp;
774 struct ep_td_struct *dtd; 774 struct ep_td_struct *dtd;
@@ -777,7 +777,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
777 *length = min(req->req.length - req->req.actual, 777 *length = min(req->req.length - req->req.actual,
778 (unsigned)EP_MAX_LENGTH_TRANSFER); 778 (unsigned)EP_MAX_LENGTH_TRANSFER);
779 779
780 dtd = dma_pool_alloc(udc_controller->td_pool, GFP_KERNEL, dma); 780 dtd = dma_pool_alloc(udc_controller->td_pool, gfp_flags, dma);
781 if (dtd == NULL) 781 if (dtd == NULL)
782 return dtd; 782 return dtd;
783 783
@@ -827,7 +827,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
827} 827}
828 828
829/* Generate dtd chain for a request */ 829/* Generate dtd chain for a request */
830static int fsl_req_to_dtd(struct fsl_req *req) 830static int fsl_req_to_dtd(struct fsl_req *req, gfp_t gfp_flags)
831{ 831{
832 unsigned count; 832 unsigned count;
833 int is_last; 833 int is_last;
@@ -836,7 +836,7 @@ static int fsl_req_to_dtd(struct fsl_req *req)
836 dma_addr_t dma; 836 dma_addr_t dma;
837 837
838 do { 838 do {
839 dtd = fsl_build_dtd(req, &count, &dma, &is_last); 839 dtd = fsl_build_dtd(req, &count, &dma, &is_last, gfp_flags);
840 if (dtd == NULL) 840 if (dtd == NULL)
841 return -ENOMEM; 841 return -ENOMEM;
842 842
@@ -910,13 +910,11 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
910 req->req.actual = 0; 910 req->req.actual = 0;
911 req->dtd_count = 0; 911 req->dtd_count = 0;
912 912
913 spin_lock_irqsave(&udc->lock, flags);
914
915 /* build dtds and push them to device queue */ 913 /* build dtds and push them to device queue */
916 if (!fsl_req_to_dtd(req)) { 914 if (!fsl_req_to_dtd(req, gfp_flags)) {
915 spin_lock_irqsave(&udc->lock, flags);
917 fsl_queue_td(ep, req); 916 fsl_queue_td(ep, req);
918 } else { 917 } else {
919 spin_unlock_irqrestore(&udc->lock, flags);
920 return -ENOMEM; 918 return -ENOMEM;
921 } 919 }
922 920
@@ -1217,7 +1215,7 @@ static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1217 1215
1218 udc = container_of(gadget, struct fsl_udc, gadget); 1216 udc = container_of(gadget, struct fsl_udc, gadget);
1219 if (udc->transceiver) 1217 if (udc->transceiver)
1220 return otg_set_power(udc->transceiver, mA); 1218 return usb_phy_set_power(udc->transceiver, mA);
1221 return -ENOTSUPP; 1219 return -ENOTSUPP;
1222} 1220}
1223 1221
@@ -1295,7 +1293,7 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
1295 ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 1293 ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
1296 req->mapped = 1; 1294 req->mapped = 1;
1297 1295
1298 if (fsl_req_to_dtd(req) == 0) 1296 if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0)
1299 fsl_queue_td(ep, req); 1297 fsl_queue_td(ep, req);
1300 else 1298 else
1301 return -ENOMEM; 1299 return -ENOMEM;
@@ -1379,7 +1377,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
1379 req->mapped = 1; 1377 req->mapped = 1;
1380 1378
1381 /* prime the data phase */ 1379 /* prime the data phase */
1382 if ((fsl_req_to_dtd(req) == 0)) 1380 if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0))
1383 fsl_queue_td(ep, req); 1381 fsl_queue_td(ep, req);
1384 else /* no mem */ 1382 else /* no mem */
1385 goto stall; 1383 goto stall;
@@ -1966,7 +1964,8 @@ static int fsl_start(struct usb_gadget_driver *driver,
1966 1964
1967 /* connect to bus through transceiver */ 1965 /* connect to bus through transceiver */
1968 if (udc_controller->transceiver) { 1966 if (udc_controller->transceiver) {
1969 retval = otg_set_peripheral(udc_controller->transceiver, 1967 retval = otg_set_peripheral(
1968 udc_controller->transceiver->otg,
1970 &udc_controller->gadget); 1969 &udc_controller->gadget);
1971 if (retval < 0) { 1970 if (retval < 0) {
1972 ERR("can't bind to transceiver\n"); 1971 ERR("can't bind to transceiver\n");
@@ -2006,7 +2005,7 @@ static int fsl_stop(struct usb_gadget_driver *driver)
2006 return -EINVAL; 2005 return -EINVAL;
2007 2006
2008 if (udc_controller->transceiver) 2007 if (udc_controller->transceiver)
2009 otg_set_peripheral(udc_controller->transceiver, NULL); 2008 otg_set_peripheral(udc_controller->transceiver->otg, NULL);
2010 2009
2011 /* stop DR, disable intr */ 2010 /* stop DR, disable intr */
2012 dr_controller_stop(udc_controller); 2011 dr_controller_stop(udc_controller);
@@ -2430,7 +2429,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2430 2429
2431#ifdef CONFIG_USB_OTG 2430#ifdef CONFIG_USB_OTG
2432 if (pdata->operating_mode == FSL_USB2_DR_OTG) { 2431 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
2433 udc_controller->transceiver = otg_get_transceiver(); 2432 udc_controller->transceiver = usb_get_transceiver();
2434 if (!udc_controller->transceiver) { 2433 if (!udc_controller->transceiver) {
2435 ERR("Can't find OTG driver!\n"); 2434 ERR("Can't find OTG driver!\n");
2436 ret = -ENODEV; 2435 ret = -ENODEV;
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index f781f5dec417..e651469fd39b 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -471,7 +471,7 @@ struct fsl_udc {
471 471
472 struct usb_ctrlrequest local_setup_buff; 472 struct usb_ctrlrequest local_setup_buff;
473 spinlock_t lock; 473 spinlock_t lock;
474 struct otg_transceiver *transceiver; 474 struct usb_phy *transceiver;
475 unsigned softconnect:1; 475 unsigned softconnect:1;
476 unsigned vbus_active:1; 476 unsigned vbus_active:1;
477 unsigned stopped:1; 477 unsigned stopped:1;
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 0519d77915ec..331cd6729d3c 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -2,7 +2,7 @@
2 * g_ffs.c -- user mode file system API for USB composite function controllers 2 * g_ffs.c -- user mode file system API for USB composite function controllers
3 * 3 *
4 * Copyright (C) 2010 Samsung Electronics 4 * Copyright (C) 2010 Samsung Electronics
5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com> 5 * Author: Michal Nazarewicz <mina86@mina86.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 5af70fcce139..e151d6b87dee 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -43,7 +43,6 @@
43#include <asm/byteorder.h> 43#include <asm/byteorder.h>
44#include <asm/io.h> 44#include <asm/io.h>
45#include <asm/irq.h> 45#include <asm/irq.h>
46#include <asm/system.h>
47#include <asm/unaligned.h> 46#include <asm/unaligned.h>
48 47
49 48
@@ -235,6 +234,7 @@ static void ep_reset(struct goku_udc_regs __iomem *regs, struct goku_ep *ep)
235 234
236 ep->ep.maxpacket = MAX_FIFO_SIZE; 235 ep->ep.maxpacket = MAX_FIFO_SIZE;
237 ep->desc = NULL; 236 ep->desc = NULL;
237 ep->ep.desc = NULL;
238 ep->stopped = 1; 238 ep->stopped = 1;
239 ep->irqs = 0; 239 ep->irqs = 0;
240 ep->dma = 0; 240 ep->dma = 0;
@@ -310,12 +310,9 @@ done(struct goku_ep *ep, struct goku_request *req, int status)
310 status = req->req.status; 310 status = req->req.status;
311 311
312 dev = ep->dev; 312 dev = ep->dev;
313 if (req->mapped) { 313
314 pci_unmap_single(dev->pdev, req->req.dma, req->req.length, 314 if (ep->dma)
315 ep->is_in ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); 315 usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in);
316 req->req.dma = DMA_ADDR_INVALID;
317 req->mapped = 0;
318 }
319 316
320#ifndef USB_TRACE 317#ifndef USB_TRACE
321 if (status && status != -ESHUTDOWN) 318 if (status && status != -ESHUTDOWN)
@@ -736,10 +733,11 @@ goku_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
736 return -EBUSY; 733 return -EBUSY;
737 734
738 /* set up dma mapping in case the caller didn't */ 735 /* set up dma mapping in case the caller didn't */
739 if (ep->dma && _req->dma == DMA_ADDR_INVALID) { 736 if (ep->dma) {
740 _req->dma = pci_map_single(dev->pdev, _req->buf, _req->length, 737 status = usb_gadget_map_request(&dev->gadget, &req->req,
741 ep->is_in ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); 738 ep->is_in);
742 req->mapped = 1; 739 if (status)
740 return status;
743 } 741 }
744 742
745#ifdef USB_TRACE 743#ifdef USB_TRACE
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index f888c3ede860..3493adf064f5 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -60,9 +60,9 @@ static struct usb_device_descriptor device_desc = {
60 /* .bDeviceClass = USB_CLASS_COMM, */ 60 /* .bDeviceClass = USB_CLASS_COMM, */
61 /* .bDeviceSubClass = 0, */ 61 /* .bDeviceSubClass = 0, */
62 /* .bDeviceProtocol = 0, */ 62 /* .bDeviceProtocol = 0, */
63 .bDeviceClass = 0xEF, 63 .bDeviceClass = USB_CLASS_PER_INTERFACE,
64 .bDeviceSubClass = 2, 64 .bDeviceSubClass = 0,
65 .bDeviceProtocol = 1, 65 .bDeviceProtocol = 0,
66 /* .bMaxPacketSize0 = f(hardware) */ 66 /* .bMaxPacketSize0 = f(hardware) */
67 67
68 /* Vendor and product id can be overridden by module parameters. */ 68 /* Vendor and product id can be overridden by module parameters. */
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index ae04266dba1b..8793f32bab11 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1043,6 +1043,8 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
1043// FIXME don't call this with the spinlock held ... 1043// FIXME don't call this with the spinlock held ...
1044 if (copy_to_user (buf, dev->req->buf, len)) 1044 if (copy_to_user (buf, dev->req->buf, len))
1045 retval = -EFAULT; 1045 retval = -EFAULT;
1046 else
1047 retval = len;
1046 clean_req (dev->gadget->ep0, dev->req); 1048 clean_req (dev->gadget->ep0, dev->req);
1047 /* NOTE userspace can't yet choose to stall */ 1049 /* NOTE userspace can't yet choose to stall */
1048 } 1050 }
@@ -1569,20 +1571,18 @@ delegate:
1569 1571
1570static void destroy_ep_files (struct dev_data *dev) 1572static void destroy_ep_files (struct dev_data *dev)
1571{ 1573{
1572 struct list_head *entry, *tmp;
1573
1574 DBG (dev, "%s %d\n", __func__, dev->state); 1574 DBG (dev, "%s %d\n", __func__, dev->state);
1575 1575
1576 /* dev->state must prevent interference */ 1576 /* dev->state must prevent interference */
1577restart: 1577restart:
1578 spin_lock_irq (&dev->lock); 1578 spin_lock_irq (&dev->lock);
1579 list_for_each_safe (entry, tmp, &dev->epfiles) { 1579 while (!list_empty(&dev->epfiles)) {
1580 struct ep_data *ep; 1580 struct ep_data *ep;
1581 struct inode *parent; 1581 struct inode *parent;
1582 struct dentry *dentry; 1582 struct dentry *dentry;
1583 1583
1584 /* break link to FS */ 1584 /* break link to FS */
1585 ep = list_entry (entry, struct ep_data, epfiles); 1585 ep = list_first_entry (&dev->epfiles, struct ep_data, epfiles);
1586 list_del_init (&ep->epfiles); 1586 list_del_init (&ep->epfiles);
1587 dentry = ep->dentry; 1587 dentry = ep->dentry;
1588 ep->dentry = NULL; 1588 ep->dentry = NULL;
@@ -1605,8 +1605,7 @@ restart:
1605 dput (dentry); 1605 dput (dentry);
1606 mutex_unlock (&parent->i_mutex); 1606 mutex_unlock (&parent->i_mutex);
1607 1607
1608 /* fds may still be open */ 1608 spin_lock_irq (&dev->lock);
1609 goto restart;
1610 } 1609 }
1611 spin_unlock_irq (&dev->lock); 1610 spin_unlock_irq (&dev->lock);
1612} 1611}
@@ -2059,10 +2058,8 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
2059 if (!inode) 2058 if (!inode)
2060 goto Enomem; 2059 goto Enomem;
2061 inode->i_op = &simple_dir_inode_operations; 2060 inode->i_op = &simple_dir_inode_operations;
2062 if (!(sb->s_root = d_alloc_root (inode))) { 2061 if (!(sb->s_root = d_make_root (inode)))
2063 iput(inode);
2064 goto Enomem; 2062 goto Enomem;
2065 }
2066 2063
2067 /* the ep0 file is named after the controller we expect; 2064 /* the ep0 file is named after the controller we expect;
2068 * user mode code can use it for sanity checks, like we do. 2065 * user mode code can use it for sanity checks, like we do.
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index e2293c1588ee..f9cedd52cf20 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -32,7 +32,6 @@
32#include <linux/pm.h> 32#include <linux/pm.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/irq.h> 34#include <linux/irq.h>
35#include <asm/system.h>
36#include <asm/unaligned.h> 35#include <asm/unaligned.h>
37 36
38#include "langwell_udc.h" 37#include "langwell_udc.h"
@@ -401,16 +400,7 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
401 dma_pool_free(dev->dtd_pool, curr_dtd, curr_dtd->dtd_dma); 400 dma_pool_free(dev->dtd_pool, curr_dtd, curr_dtd->dtd_dma);
402 } 401 }
403 402
404 if (req->mapped) { 403 usb_gadget_unmap_request(&dev->gadget, &req->req, is_in(ep));
405 dma_unmap_single(&dev->pdev->dev,
406 req->req.dma, req->req.length,
407 is_in(ep) ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
408 req->req.dma = DMA_ADDR_INVALID;
409 req->mapped = 0;
410 } else
411 dma_sync_single_for_cpu(&dev->pdev->dev, req->req.dma,
412 req->req.length,
413 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
414 404
415 if (status != -ESHUTDOWN) 405 if (status != -ESHUTDOWN)
416 dev_dbg(&dev->pdev->dev, 406 dev_dbg(&dev->pdev->dev,
@@ -487,6 +477,7 @@ static int langwell_ep_disable(struct usb_ep *_ep)
487 nuke(ep, -ESHUTDOWN); 477 nuke(ep, -ESHUTDOWN);
488 478
489 ep->desc = NULL; 479 ep->desc = NULL;
480 ep->ep.desc = NULL;
490 ep->stopped = 1; 481 ep->stopped = 1;
491 482
492 spin_unlock_irqrestore(&dev->lock, flags); 483 spin_unlock_irqrestore(&dev->lock, flags);
@@ -749,7 +740,8 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
749 struct langwell_ep *ep; 740 struct langwell_ep *ep;
750 struct langwell_udc *dev; 741 struct langwell_udc *dev;
751 unsigned long flags; 742 unsigned long flags;
752 int is_iso = 0, zlflag = 0; 743 int is_iso = 0;
744 int ret;
753 745
754 /* always require a cpu-view buffer */ 746 /* always require a cpu-view buffer */
755 req = container_of(_req, struct langwell_request, req); 747 req = container_of(_req, struct langwell_request, req);
@@ -776,33 +768,10 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
776 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) 768 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN))
777 return -ESHUTDOWN; 769 return -ESHUTDOWN;
778 770
779 /* set up dma mapping in case the caller didn't */ 771 /* set up dma mapping */
780 if (_req->dma == DMA_ADDR_INVALID) { 772 ret = usb_gadget_map_request(&dev->gadget, &req->req, is_in(ep));
781 /* WORKAROUND: WARN_ON(size == 0) */ 773 if (ret)
782 if (_req->length == 0) { 774 return ret;
783 dev_vdbg(&dev->pdev->dev, "req->length: 0->1\n");
784 zlflag = 1;
785 _req->length++;
786 }
787
788 _req->dma = dma_map_single(&dev->pdev->dev,
789 _req->buf, _req->length,
790 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
791 if (zlflag && (_req->length == 1)) {
792 dev_vdbg(&dev->pdev->dev, "req->length: 1->0\n");
793 zlflag = 0;
794 _req->length = 0;
795 }
796
797 req->mapped = 1;
798 dev_vdbg(&dev->pdev->dev, "req->mapped = 1\n");
799 } else {
800 dma_sync_single_for_device(&dev->pdev->dev,
801 _req->dma, _req->length,
802 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
803 req->mapped = 0;
804 dev_vdbg(&dev->pdev->dev, "req->mapped = 0\n");
805 }
806 775
807 dev_dbg(&dev->pdev->dev, 776 dev_dbg(&dev->pdev->dev,
808 "%s queue req %p, len %u, buf %p, dma 0x%08x\n", 777 "%s queue req %p, len %u, buf %p, dma 0x%08x\n",
@@ -1261,9 +1230,9 @@ static int langwell_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1261 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); 1230 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1262 1231
1263 if (dev->transceiver) { 1232 if (dev->transceiver) {
1264 dev_vdbg(&dev->pdev->dev, "otg_set_power\n"); 1233 dev_vdbg(&dev->pdev->dev, "usb_phy_set_power\n");
1265 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); 1234 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1266 return otg_set_power(dev->transceiver, mA); 1235 return usb_phy_set_power(dev->transceiver, mA);
1267 } 1236 }
1268 1237
1269 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); 1238 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
@@ -1906,7 +1875,7 @@ static int langwell_stop(struct usb_gadget *g,
1906 1875
1907 /* unbind OTG transceiver */ 1876 /* unbind OTG transceiver */
1908 if (dev->transceiver) 1877 if (dev->transceiver)
1909 (void)otg_set_peripheral(dev->transceiver, 0); 1878 (void)otg_set_peripheral(dev->transceiver->otg, 0);
1910 1879
1911 /* disable interrupt and set controller to stop state */ 1880 /* disable interrupt and set controller to stop state */
1912 langwell_udc_stop(dev); 1881 langwell_udc_stop(dev);
diff --git a/drivers/usb/gadget/langwell_udc.h b/drivers/usb/gadget/langwell_udc.h
index d6e78accaffe..8c8087abb481 100644
--- a/drivers/usb/gadget/langwell_udc.h
+++ b/drivers/usb/gadget/langwell_udc.h
@@ -162,7 +162,7 @@ struct langwell_udc {
162 spinlock_t lock; /* device lock */ 162 spinlock_t lock; /* device lock */
163 struct langwell_ep *ep; 163 struct langwell_ep *ep;
164 struct usb_gadget_driver *driver; 164 struct usb_gadget_driver *driver;
165 struct otg_transceiver *transceiver; 165 struct usb_phy *transceiver;
166 u8 dev_addr; 166 u8 dev_addr;
167 u32 usb_state; 167 u32 usb_state;
168 u32 resume_state; 168 u32 resume_state;
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index e24f72f82a47..1f376eba31f6 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2003-2008 Alan Stern 4 * Copyright (C) 2003-2008 Alan Stern
5 * Copyright (C) 2009 Samsung Electronics 5 * Copyright (C) 2009 Samsung Electronics
6 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com> 6 * Author: Michal Nazarewicz <mina86@mina86.com>
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 7e7f515b8b19..c37fb33a3d1b 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -4,7 +4,7 @@
4 * Copyright (C) 2008 David Brownell 4 * Copyright (C) 2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
6 * Copyright (C) 2009 Samsung Electronics 6 * Copyright (C) 2009 Samsung Electronics
7 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com) 7 * Author: Michal Nazarewicz (mina86@mina86.com)
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/usb/gadget/mv_udc.h b/drivers/usb/gadget/mv_udc.h
index 34aadfae723d..e2be9519abbe 100644
--- a/drivers/usb/gadget/mv_udc.h
+++ b/drivers/usb/gadget/mv_udc.h
@@ -217,7 +217,7 @@ struct mv_udc {
217 struct work_struct vbus_work; 217 struct work_struct vbus_work;
218 struct workqueue_struct *qwork; 218 struct workqueue_struct *qwork;
219 219
220 struct otg_transceiver *transceiver; 220 struct usb_phy *transceiver;
221 221
222 struct mv_usb_platform_data *pdata; 222 struct mv_usb_platform_data *pdata;
223 223
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index f97e737d26f7..a73cf406e2a4 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -34,7 +34,6 @@
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/platform_data/mv_usb.h> 36#include <linux/platform_data/mv_usb.h>
37#include <asm/system.h>
38#include <asm/unaligned.h> 37#include <asm/unaligned.h>
39 38
40#include "mv_udc.h" 39#include "mv_udc.h"
@@ -608,6 +607,7 @@ static int mv_ep_disable(struct usb_ep *_ep)
608 nuke(ep, -ESHUTDOWN); 607 nuke(ep, -ESHUTDOWN);
609 608
610 ep->desc = NULL; 609 ep->desc = NULL;
610 ep->ep.desc = NULL;
611 ep->stopped = 1; 611 ep->stopped = 1;
612 612
613 spin_unlock_irqrestore(&udc->lock, flags); 613 spin_unlock_irqrestore(&udc->lock, flags);
@@ -771,8 +771,7 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
771 udc->ep0_state = DATA_STATE_XMIT; 771 udc->ep0_state = DATA_STATE_XMIT;
772 772
773 /* irq handler advances the queue */ 773 /* irq handler advances the queue */
774 if (req != NULL) 774 list_add_tail(&req->queue, &ep->queue);
775 list_add_tail(&req->queue, &ep->queue);
776 spin_unlock_irqrestore(&udc->lock, flags); 775 spin_unlock_irqrestore(&udc->lock, flags);
777 776
778 return 0; 777 return 0;
@@ -1384,7 +1383,8 @@ static int mv_udc_start(struct usb_gadget_driver *driver,
1384 } 1383 }
1385 1384
1386 if (udc->transceiver) { 1385 if (udc->transceiver) {
1387 retval = otg_set_peripheral(udc->transceiver, &udc->gadget); 1386 retval = otg_set_peripheral(udc->transceiver->otg,
1387 &udc->gadget);
1388 if (retval) { 1388 if (retval) {
1389 dev_err(&udc->dev->dev, 1389 dev_err(&udc->dev->dev,
1390 "unable to register peripheral to otg\n"); 1390 "unable to register peripheral to otg\n");
@@ -2181,7 +2181,7 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
2181 2181
2182#ifdef CONFIG_USB_OTG_UTILS 2182#ifdef CONFIG_USB_OTG_UTILS
2183 if (pdata->mode == MV_USB_MODE_OTG) 2183 if (pdata->mode == MV_USB_MODE_OTG)
2184 udc->transceiver = otg_get_transceiver(); 2184 udc->transceiver = usb_get_transceiver();
2185#endif 2185#endif
2186 2186
2187 udc->clknum = pdata->clknum; 2187 udc->clknum = pdata->clknum;
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c
index 7322d293213e..43ac7482fa91 100644
--- a/drivers/usb/gadget/net2272.c
+++ b/drivers/usb/gadget/net2272.c
@@ -42,7 +42,6 @@
42#include <linux/usb/gadget.h> 42#include <linux/usb/gadget.h>
43 43
44#include <asm/byteorder.h> 44#include <asm/byteorder.h>
45#include <asm/system.h>
46#include <asm/unaligned.h> 45#include <asm/unaligned.h>
47 46
48#include "net2272.h" 47#include "net2272.h"
@@ -385,12 +384,9 @@ net2272_done(struct net2272_ep *ep, struct net2272_request *req, int status)
385 status = req->req.status; 384 status = req->req.status;
386 385
387 dev = ep->dev; 386 dev = ep->dev;
388 if (use_dma && req->mapped) { 387 if (use_dma && ep->dma)
389 dma_unmap_single(dev->dev, req->req.dma, req->req.length, 388 usb_gadget_unmap_request(&dev->gadget, &req->req,
390 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 389 ep->is_in);
391 req->req.dma = DMA_ADDR_INVALID;
392 req->mapped = 0;
393 }
394 390
395 if (status && status != -ESHUTDOWN) 391 if (status && status != -ESHUTDOWN)
396 dev_vdbg(dev->dev, "complete %s req %p stat %d len %u/%u buf %p\n", 392 dev_vdbg(dev->dev, "complete %s req %p stat %d len %u/%u buf %p\n",
@@ -850,10 +846,11 @@ net2272_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
850 return -ESHUTDOWN; 846 return -ESHUTDOWN;
851 847
852 /* set up dma mapping in case the caller didn't */ 848 /* set up dma mapping in case the caller didn't */
853 if (use_dma && ep->dma && _req->dma == DMA_ADDR_INVALID) { 849 if (use_dma && ep->dma) {
854 _req->dma = dma_map_single(dev->dev, _req->buf, _req->length, 850 status = usb_gadget_map_request(&dev->gadget, _req,
855 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 851 ep->is_in);
856 req->mapped = 1; 852 if (status)
853 return status;
857 } 854 }
858 855
859 dev_vdbg(dev->dev, "%s queue req %p, len %d buf %p dma %08llx %s\n", 856 dev_vdbg(dev->dev, "%s queue req %p, len %d buf %p dma %08llx %s\n",
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index cdedd1336745..ac335af154ba 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -59,7 +59,6 @@
59#include <asm/byteorder.h> 59#include <asm/byteorder.h>
60#include <asm/io.h> 60#include <asm/io.h>
61#include <asm/irq.h> 61#include <asm/irq.h>
62#include <asm/system.h>
63#include <asm/unaligned.h> 62#include <asm/unaligned.h>
64 63
65 64
@@ -806,12 +805,8 @@ done (struct net2280_ep *ep, struct net2280_request *req, int status)
806 status = req->req.status; 805 status = req->req.status;
807 806
808 dev = ep->dev; 807 dev = ep->dev;
809 if (req->mapped) { 808 if (ep->dma)
810 pci_unmap_single (dev->pdev, req->req.dma, req->req.length, 809 usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in);
811 ep->is_in ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
812 req->req.dma = DMA_ADDR_INVALID;
813 req->mapped = 0;
814 }
815 810
816 if (status && status != -ESHUTDOWN) 811 if (status && status != -ESHUTDOWN)
817 VDEBUG (dev, "complete %s req %p stat %d len %u/%u\n", 812 VDEBUG (dev, "complete %s req %p stat %d len %u/%u\n",
@@ -857,10 +852,13 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
857 return -EOPNOTSUPP; 852 return -EOPNOTSUPP;
858 853
859 /* set up dma mapping in case the caller didn't */ 854 /* set up dma mapping in case the caller didn't */
860 if (ep->dma && _req->dma == DMA_ADDR_INVALID) { 855 if (ep->dma) {
861 _req->dma = pci_map_single (dev->pdev, _req->buf, _req->length, 856 int ret;
862 ep->is_in ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); 857
863 req->mapped = 1; 858 ret = usb_gadget_map_request(&dev->gadget, _req,
859 ep->is_in);
860 if (ret)
861 return ret;
864 } 862 }
865 863
866#if 0 864#if 0
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 576cd8578b45..3b4b6dd0f95a 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -40,7 +40,6 @@
40#include <asm/byteorder.h> 40#include <asm/byteorder.h>
41#include <asm/io.h> 41#include <asm/io.h>
42#include <asm/irq.h> 42#include <asm/irq.h>
43#include <asm/system.h>
44#include <asm/unaligned.h> 43#include <asm/unaligned.h>
45#include <asm/mach-types.h> 44#include <asm/mach-types.h>
46 45
@@ -251,6 +250,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
251 250
252 spin_lock_irqsave(&ep->udc->lock, flags); 251 spin_lock_irqsave(&ep->udc->lock, flags);
253 ep->desc = NULL; 252 ep->desc = NULL;
253 ep->ep.desc = NULL;
254 nuke (ep, -ESHUTDOWN); 254 nuke (ep, -ESHUTDOWN);
255 ep->ep.maxpacket = ep->maxpacket; 255 ep->ep.maxpacket = ep->maxpacket;
256 ep->has_dma = 0; 256 ep->has_dma = 0;
@@ -1213,7 +1213,7 @@ static int omap_wakeup(struct usb_gadget *gadget)
1213 /* NOTE: non-OTG systems may use SRP TOO... */ 1213 /* NOTE: non-OTG systems may use SRP TOO... */
1214 } else if (!(udc->devstat & UDC_ATT)) { 1214 } else if (!(udc->devstat & UDC_ATT)) {
1215 if (udc->transceiver) 1215 if (udc->transceiver)
1216 retval = otg_start_srp(udc->transceiver); 1216 retval = otg_start_srp(udc->transceiver->otg);
1217 } 1217 }
1218 spin_unlock_irqrestore(&udc->lock, flags); 1218 spin_unlock_irqrestore(&udc->lock, flags);
1219 1219
@@ -1345,7 +1345,7 @@ static int omap_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1345 1345
1346 udc = container_of(gadget, struct omap_udc, gadget); 1346 udc = container_of(gadget, struct omap_udc, gadget);
1347 if (udc->transceiver) 1347 if (udc->transceiver)
1348 return otg_set_power(udc->transceiver, mA); 1348 return usb_phy_set_power(udc->transceiver, mA);
1349 return -EOPNOTSUPP; 1349 return -EOPNOTSUPP;
1350} 1350}
1351 1351
@@ -1839,11 +1839,13 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1839 spin_lock(&udc->lock); 1839 spin_lock(&udc->lock);
1840 } 1840 }
1841 if (udc->transceiver) 1841 if (udc->transceiver)
1842 otg_set_suspend(udc->transceiver, 1); 1842 usb_phy_set_suspend(
1843 udc->transceiver, 1);
1843 } else { 1844 } else {
1844 VDBG("resume\n"); 1845 VDBG("resume\n");
1845 if (udc->transceiver) 1846 if (udc->transceiver)
1846 otg_set_suspend(udc->transceiver, 0); 1847 usb_phy_set_suspend(
1848 udc->transceiver, 0);
1847 if (udc->gadget.speed == USB_SPEED_FULL 1849 if (udc->gadget.speed == USB_SPEED_FULL
1848 && udc->driver->resume) { 1850 && udc->driver->resume) {
1849 spin_unlock(&udc->lock); 1851 spin_unlock(&udc->lock);
@@ -2154,7 +2156,8 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2154 2156
2155 /* connect to bus through transceiver */ 2157 /* connect to bus through transceiver */
2156 if (udc->transceiver) { 2158 if (udc->transceiver) {
2157 status = otg_set_peripheral(udc->transceiver, &udc->gadget); 2159 status = otg_set_peripheral(udc->transceiver->otg,
2160 &udc->gadget);
2158 if (status < 0) { 2161 if (status < 0) {
2159 ERR("can't bind to transceiver\n"); 2162 ERR("can't bind to transceiver\n");
2160 if (driver->unbind) { 2163 if (driver->unbind) {
@@ -2200,7 +2203,7 @@ static int omap_udc_stop(struct usb_gadget_driver *driver)
2200 omap_vbus_session(&udc->gadget, 0); 2203 omap_vbus_session(&udc->gadget, 0);
2201 2204
2202 if (udc->transceiver) 2205 if (udc->transceiver)
2203 (void) otg_set_peripheral(udc->transceiver, NULL); 2206 (void) otg_set_peripheral(udc->transceiver->otg, NULL);
2204 else 2207 else
2205 pullup_disable(udc); 2208 pullup_disable(udc);
2206 2209
@@ -2650,7 +2653,7 @@ static void omap_udc_release(struct device *dev)
2650} 2653}
2651 2654
2652static int __init 2655static int __init
2653omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv) 2656omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2654{ 2657{
2655 unsigned tmp, buf; 2658 unsigned tmp, buf;
2656 2659
@@ -2790,7 +2793,7 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2790{ 2793{
2791 int status = -ENODEV; 2794 int status = -ENODEV;
2792 int hmc; 2795 int hmc;
2793 struct otg_transceiver *xceiv = NULL; 2796 struct usb_phy *xceiv = NULL;
2794 const char *type = NULL; 2797 const char *type = NULL;
2795 struct omap_usb_config *config = pdev->dev.platform_data; 2798 struct omap_usb_config *config = pdev->dev.platform_data;
2796 struct clk *dc_clk; 2799 struct clk *dc_clk;
@@ -2863,7 +2866,7 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2863 * use it. Except for OTG, we don't _need_ to talk to one; 2866 * use it. Except for OTG, we don't _need_ to talk to one;
2864 * but not having one probably means no VBUS detection. 2867 * but not having one probably means no VBUS detection.
2865 */ 2868 */
2866 xceiv = otg_get_transceiver(); 2869 xceiv = usb_get_transceiver();
2867 if (xceiv) 2870 if (xceiv)
2868 type = xceiv->label; 2871 type = xceiv->label;
2869 else if (config->otg) { 2872 else if (config->otg) {
@@ -3009,7 +3012,7 @@ cleanup1:
3009 3012
3010cleanup0: 3013cleanup0:
3011 if (xceiv) 3014 if (xceiv)
3012 otg_put_transceiver(xceiv); 3015 usb_put_transceiver(xceiv);
3013 3016
3014 if (cpu_is_omap16xx() || cpu_is_omap24xx() || cpu_is_omap7xx()) { 3017 if (cpu_is_omap16xx() || cpu_is_omap24xx() || cpu_is_omap7xx()) {
3015 clk_disable(hhc_clk); 3018 clk_disable(hhc_clk);
@@ -3039,7 +3042,7 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
3039 3042
3040 pullup_disable(udc); 3043 pullup_disable(udc);
3041 if (udc->transceiver) { 3044 if (udc->transceiver) {
3042 otg_put_transceiver(udc->transceiver); 3045 usb_put_transceiver(udc->transceiver);
3043 udc->transceiver = NULL; 3046 udc->transceiver = NULL;
3044 } 3047 }
3045 omap_writew(0, UDC_SYSCON1); 3048 omap_writew(0, UDC_SYSCON1);
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h
index 29edc51b6b22..59d3b2213cb1 100644
--- a/drivers/usb/gadget/omap_udc.h
+++ b/drivers/usb/gadget/omap_udc.h
@@ -164,7 +164,7 @@ struct omap_udc {
164 struct omap_ep ep[32]; 164 struct omap_ep ep[32];
165 u16 devstat; 165 u16 devstat;
166 u16 clr_halt; 166 u16 clr_halt;
167 struct otg_transceiver *transceiver; 167 struct usb_phy *transceiver;
168 struct list_head iso; 168 struct list_head iso;
169 unsigned softconnect:1; 169 unsigned softconnect:1;
170 unsigned vbus_active:1; 170 unsigned vbus_active:1;
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index a3fcaae4bc2a..65307064a6fd 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -15,6 +15,14 @@
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/usb/ch9.h> 16#include <linux/usb/ch9.h>
17#include <linux/usb/gadget.h> 17#include <linux/usb/gadget.h>
18#include <linux/gpio.h>
19#include <linux/irq.h>
20
21/* GPIO port for VBUS detecting */
22static int vbus_gpio_port = -1; /* GPIO port number (-1:Not used) */
23
24#define PCH_VBUS_PERIOD 3000 /* VBUS polling period (msec) */
25#define PCH_VBUS_INTERVAL 10 /* VBUS polling interval (msec) */
18 26
19/* Address offset of Registers */ 27/* Address offset of Registers */
20#define UDC_EP_REG_SHIFT 0x20 /* Offset to next EP */ 28#define UDC_EP_REG_SHIFT 0x20 /* Offset to next EP */
@@ -296,6 +304,21 @@ struct pch_udc_ep {
296}; 304};
297 305
298/** 306/**
307 * struct pch_vbus_gpio_data - Structure holding GPIO informaton
308 * for detecting VBUS
309 * @port: gpio port number
310 * @intr: gpio interrupt number
311 * @irq_work_fall Structure for WorkQueue
312 * @irq_work_rise Structure for WorkQueue
313 */
314struct pch_vbus_gpio_data {
315 int port;
316 int intr;
317 struct work_struct irq_work_fall;
318 struct work_struct irq_work_rise;
319};
320
321/**
299 * struct pch_udc_dev - Structure holding complete information 322 * struct pch_udc_dev - Structure holding complete information
300 * of the PCH USB device 323 * of the PCH USB device
301 * @gadget: gadget driver data 324 * @gadget: gadget driver data
@@ -311,6 +334,7 @@ struct pch_udc_ep {
311 * @registered: driver regsitered with system 334 * @registered: driver regsitered with system
312 * @suspended: driver in suspended state 335 * @suspended: driver in suspended state
313 * @connected: gadget driver associated 336 * @connected: gadget driver associated
337 * @vbus_session: required vbus_session state
314 * @set_cfg_not_acked: pending acknowledgement 4 setup 338 * @set_cfg_not_acked: pending acknowledgement 4 setup
315 * @waiting_zlp_ack: pending acknowledgement 4 ZLP 339 * @waiting_zlp_ack: pending acknowledgement 4 ZLP
316 * @data_requests: DMA pool for data requests 340 * @data_requests: DMA pool for data requests
@@ -322,6 +346,7 @@ struct pch_udc_ep {
322 * @base_addr: for mapped device memory 346 * @base_addr: for mapped device memory
323 * @irq: IRQ line for the device 347 * @irq: IRQ line for the device
324 * @cfg_data: current cfg, intf, and alt in use 348 * @cfg_data: current cfg, intf, and alt in use
349 * @vbus_gpio: GPIO informaton for detecting VBUS
325 */ 350 */
326struct pch_udc_dev { 351struct pch_udc_dev {
327 struct usb_gadget gadget; 352 struct usb_gadget gadget;
@@ -337,6 +362,7 @@ struct pch_udc_dev {
337 registered:1, 362 registered:1,
338 suspended:1, 363 suspended:1,
339 connected:1, 364 connected:1,
365 vbus_session:1,
340 set_cfg_not_acked:1, 366 set_cfg_not_acked:1,
341 waiting_zlp_ack:1; 367 waiting_zlp_ack:1;
342 struct pci_pool *data_requests; 368 struct pci_pool *data_requests;
@@ -347,7 +373,8 @@ struct pch_udc_dev {
347 unsigned long phys_addr; 373 unsigned long phys_addr;
348 void __iomem *base_addr; 374 void __iomem *base_addr;
349 unsigned irq; 375 unsigned irq;
350 struct pch_udc_cfg_data cfg_data; 376 struct pch_udc_cfg_data cfg_data;
377 struct pch_vbus_gpio_data vbus_gpio;
351}; 378};
352 379
353#define PCH_UDC_PCI_BAR 1 380#define PCH_UDC_PCI_BAR 1
@@ -554,6 +581,29 @@ static void pch_udc_clear_disconnect(struct pch_udc_dev *dev)
554} 581}
555 582
556/** 583/**
584 * pch_udc_reconnect() - This API initializes usb device controller,
585 * and clear the disconnect status.
586 * @dev: Reference to pch_udc_regs structure
587 */
588static void pch_udc_init(struct pch_udc_dev *dev);
589static void pch_udc_reconnect(struct pch_udc_dev *dev)
590{
591 pch_udc_init(dev);
592
593 /* enable device interrupts */
594 /* pch_udc_enable_interrupts() */
595 pch_udc_bit_clr(dev, UDC_DEVIRQMSK_ADDR,
596 UDC_DEVINT_UR | UDC_DEVINT_ENUM);
597
598 /* Clear the disconnect */
599 pch_udc_bit_set(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_RES);
600 pch_udc_bit_clr(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_SD);
601 mdelay(1);
602 /* Resume USB signalling */
603 pch_udc_bit_clr(dev, UDC_DEVCTL_ADDR, UDC_DEVCTL_RES);
604}
605
606/**
557 * pch_udc_vbus_session() - set or clearr the disconnect status. 607 * pch_udc_vbus_session() - set or clearr the disconnect status.
558 * @dev: Reference to pch_udc_regs structure 608 * @dev: Reference to pch_udc_regs structure
559 * @is_active: Parameter specifying the action 609 * @is_active: Parameter specifying the action
@@ -563,10 +613,18 @@ static void pch_udc_clear_disconnect(struct pch_udc_dev *dev)
563static inline void pch_udc_vbus_session(struct pch_udc_dev *dev, 613static inline void pch_udc_vbus_session(struct pch_udc_dev *dev,
564 int is_active) 614 int is_active)
565{ 615{
566 if (is_active) 616 if (is_active) {
567 pch_udc_clear_disconnect(dev); 617 pch_udc_reconnect(dev);
568 else 618 dev->vbus_session = 1;
619 } else {
620 if (dev->driver && dev->driver->disconnect) {
621 spin_unlock(&dev->lock);
622 dev->driver->disconnect(&dev->gadget);
623 spin_lock(&dev->lock);
624 }
569 pch_udc_set_disconnect(dev); 625 pch_udc_set_disconnect(dev);
626 dev->vbus_session = 0;
627 }
570} 628}
571 629
572/** 630/**
@@ -1126,7 +1184,17 @@ static int pch_udc_pcd_pullup(struct usb_gadget *gadget, int is_on)
1126 if (!gadget) 1184 if (!gadget)
1127 return -EINVAL; 1185 return -EINVAL;
1128 dev = container_of(gadget, struct pch_udc_dev, gadget); 1186 dev = container_of(gadget, struct pch_udc_dev, gadget);
1129 pch_udc_vbus_session(dev, is_on); 1187 if (is_on) {
1188 pch_udc_reconnect(dev);
1189 } else {
1190 if (dev->driver && dev->driver->disconnect) {
1191 spin_unlock(&dev->lock);
1192 dev->driver->disconnect(&dev->gadget);
1193 spin_lock(&dev->lock);
1194 }
1195 pch_udc_set_disconnect(dev);
1196 }
1197
1130 return 0; 1198 return 0;
1131} 1199}
1132 1200
@@ -1183,6 +1251,188 @@ static const struct usb_gadget_ops pch_udc_ops = {
1183}; 1251};
1184 1252
1185/** 1253/**
1254 * pch_vbus_gpio_get_value() - This API gets value of GPIO port as VBUS status.
1255 * @dev: Reference to the driver structure
1256 *
1257 * Return value:
1258 * 1: VBUS is high
1259 * 0: VBUS is low
1260 * -1: It is not enable to detect VBUS using GPIO
1261 */
1262static int pch_vbus_gpio_get_value(struct pch_udc_dev *dev)
1263{
1264 int vbus = 0;
1265
1266 if (dev->vbus_gpio.port)
1267 vbus = gpio_get_value(dev->vbus_gpio.port) ? 1 : 0;
1268 else
1269 vbus = -1;
1270
1271 return vbus;
1272}
1273
1274/**
1275 * pch_vbus_gpio_work_fall() - This API keeps watch on VBUS becoming Low.
1276 * If VBUS is Low, disconnect is processed
1277 * @irq_work: Structure for WorkQueue
1278 *
1279 */
1280static void pch_vbus_gpio_work_fall(struct work_struct *irq_work)
1281{
1282 struct pch_vbus_gpio_data *vbus_gpio = container_of(irq_work,
1283 struct pch_vbus_gpio_data, irq_work_fall);
1284 struct pch_udc_dev *dev =
1285 container_of(vbus_gpio, struct pch_udc_dev, vbus_gpio);
1286 int vbus_saved = -1;
1287 int vbus;
1288 int count;
1289
1290 if (!dev->vbus_gpio.port)
1291 return;
1292
1293 for (count = 0; count < (PCH_VBUS_PERIOD / PCH_VBUS_INTERVAL);
1294 count++) {
1295 vbus = pch_vbus_gpio_get_value(dev);
1296
1297 if ((vbus_saved == vbus) && (vbus == 0)) {
1298 dev_dbg(&dev->pdev->dev, "VBUS fell");
1299 if (dev->driver
1300 && dev->driver->disconnect) {
1301 dev->driver->disconnect(
1302 &dev->gadget);
1303 }
1304 if (dev->vbus_gpio.intr)
1305 pch_udc_init(dev);
1306 else
1307 pch_udc_reconnect(dev);
1308 return;
1309 }
1310 vbus_saved = vbus;
1311 mdelay(PCH_VBUS_INTERVAL);
1312 }
1313}
1314
1315/**
1316 * pch_vbus_gpio_work_rise() - This API checks VBUS is High.
1317 * If VBUS is High, connect is processed
1318 * @irq_work: Structure for WorkQueue
1319 *
1320 */
1321static void pch_vbus_gpio_work_rise(struct work_struct *irq_work)
1322{
1323 struct pch_vbus_gpio_data *vbus_gpio = container_of(irq_work,
1324 struct pch_vbus_gpio_data, irq_work_rise);
1325 struct pch_udc_dev *dev =
1326 container_of(vbus_gpio, struct pch_udc_dev, vbus_gpio);
1327 int vbus;
1328
1329 if (!dev->vbus_gpio.port)
1330 return;
1331
1332 mdelay(PCH_VBUS_INTERVAL);
1333 vbus = pch_vbus_gpio_get_value(dev);
1334
1335 if (vbus == 1) {
1336 dev_dbg(&dev->pdev->dev, "VBUS rose");
1337 pch_udc_reconnect(dev);
1338 return;
1339 }
1340}
1341
1342/**
1343 * pch_vbus_gpio_irq() - IRQ handler for GPIO intrerrupt for changing VBUS
1344 * @irq: Interrupt request number
1345 * @dev: Reference to the device structure
1346 *
1347 * Return codes:
1348 * 0: Success
1349 * -EINVAL: GPIO port is invalid or can't be initialized.
1350 */
1351static irqreturn_t pch_vbus_gpio_irq(int irq, void *data)
1352{
1353 struct pch_udc_dev *dev = (struct pch_udc_dev *)data;
1354
1355 if (!dev->vbus_gpio.port || !dev->vbus_gpio.intr)
1356 return IRQ_NONE;
1357
1358 if (pch_vbus_gpio_get_value(dev))
1359 schedule_work(&dev->vbus_gpio.irq_work_rise);
1360 else
1361 schedule_work(&dev->vbus_gpio.irq_work_fall);
1362
1363 return IRQ_HANDLED;
1364}
1365
1366/**
1367 * pch_vbus_gpio_init() - This API initializes GPIO port detecting VBUS.
1368 * @dev: Reference to the driver structure
1369 * @vbus_gpio Number of GPIO port to detect gpio
1370 *
1371 * Return codes:
1372 * 0: Success
1373 * -EINVAL: GPIO port is invalid or can't be initialized.
1374 */
1375static int pch_vbus_gpio_init(struct pch_udc_dev *dev, int vbus_gpio_port)
1376{
1377 int err;
1378 int irq_num = 0;
1379
1380 dev->vbus_gpio.port = 0;
1381 dev->vbus_gpio.intr = 0;
1382
1383 if (vbus_gpio_port <= -1)
1384 return -EINVAL;
1385
1386 err = gpio_is_valid(vbus_gpio_port);
1387 if (!err) {
1388 pr_err("%s: gpio port %d is invalid\n",
1389 __func__, vbus_gpio_port);
1390 return -EINVAL;
1391 }
1392
1393 err = gpio_request(vbus_gpio_port, "pch_vbus");
1394 if (err) {
1395 pr_err("%s: can't request gpio port %d, err: %d\n",
1396 __func__, vbus_gpio_port, err);
1397 return -EINVAL;
1398 }
1399
1400 dev->vbus_gpio.port = vbus_gpio_port;
1401 gpio_direction_input(vbus_gpio_port);
1402 INIT_WORK(&dev->vbus_gpio.irq_work_fall, pch_vbus_gpio_work_fall);
1403
1404 irq_num = gpio_to_irq(vbus_gpio_port);
1405 if (irq_num > 0) {
1406 irq_set_irq_type(irq_num, IRQ_TYPE_EDGE_BOTH);
1407 err = request_irq(irq_num, pch_vbus_gpio_irq, 0,
1408 "vbus_detect", dev);
1409 if (!err) {
1410 dev->vbus_gpio.intr = irq_num;
1411 INIT_WORK(&dev->vbus_gpio.irq_work_rise,
1412 pch_vbus_gpio_work_rise);
1413 } else {
1414 pr_err("%s: can't request irq %d, err: %d\n",
1415 __func__, irq_num, err);
1416 }
1417 }
1418
1419 return 0;
1420}
1421
1422/**
1423 * pch_vbus_gpio_free() - This API frees resources of GPIO port
1424 * @dev: Reference to the driver structure
1425 */
1426static void pch_vbus_gpio_free(struct pch_udc_dev *dev)
1427{
1428 if (dev->vbus_gpio.intr)
1429 free_irq(dev->vbus_gpio.intr, dev);
1430
1431 if (dev->vbus_gpio.port)
1432 gpio_free(dev->vbus_gpio.port);
1433}
1434
1435/**
1186 * complete_req() - This API is invoked from the driver when processing 1436 * complete_req() - This API is invoked from the driver when processing
1187 * of a request is complete 1437 * of a request is complete
1188 * @ep: Reference to the endpoint structure 1438 * @ep: Reference to the endpoint structure
@@ -1493,6 +1743,7 @@ static int pch_udc_pcd_ep_disable(struct usb_ep *usbep)
1493 pch_udc_ep_disable(ep); 1743 pch_udc_ep_disable(ep);
1494 pch_udc_disable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); 1744 pch_udc_disable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num));
1495 ep->desc = NULL; 1745 ep->desc = NULL;
1746 ep->ep.desc = NULL;
1496 INIT_LIST_HEAD(&ep->queue); 1747 INIT_LIST_HEAD(&ep->queue);
1497 spin_unlock_irqrestore(&ep->dev->lock, iflags); 1748 spin_unlock_irqrestore(&ep->dev->lock, iflags);
1498 return 0; 1749 return 0;
@@ -2335,8 +2586,11 @@ static void pch_udc_svc_ur_interrupt(struct pch_udc_dev *dev)
2335 /* Complete request queue */ 2586 /* Complete request queue */
2336 empty_req_queue(ep); 2587 empty_req_queue(ep);
2337 } 2588 }
2338 if (dev->driver && dev->driver->disconnect) 2589 if (dev->driver && dev->driver->disconnect) {
2590 spin_unlock(&dev->lock);
2339 dev->driver->disconnect(&dev->gadget); 2591 dev->driver->disconnect(&dev->gadget);
2592 spin_lock(&dev->lock);
2593 }
2340} 2594}
2341 2595
2342/** 2596/**
@@ -2371,6 +2625,11 @@ static void pch_udc_svc_enum_interrupt(struct pch_udc_dev *dev)
2371 pch_udc_set_dma(dev, DMA_DIR_TX); 2625 pch_udc_set_dma(dev, DMA_DIR_TX);
2372 pch_udc_set_dma(dev, DMA_DIR_RX); 2626 pch_udc_set_dma(dev, DMA_DIR_RX);
2373 pch_udc_ep_set_rrdy(&(dev->ep[UDC_EP0OUT_IDX])); 2627 pch_udc_ep_set_rrdy(&(dev->ep[UDC_EP0OUT_IDX]));
2628
2629 /* enable device interrupts */
2630 pch_udc_enable_interrupts(dev, UDC_DEVINT_UR | UDC_DEVINT_US |
2631 UDC_DEVINT_ES | UDC_DEVINT_ENUM |
2632 UDC_DEVINT_SI | UDC_DEVINT_SC);
2374} 2633}
2375 2634
2376/** 2635/**
@@ -2459,12 +2718,18 @@ static void pch_udc_svc_cfg_interrupt(struct pch_udc_dev *dev)
2459 */ 2718 */
2460static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr) 2719static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr)
2461{ 2720{
2721 int vbus;
2722
2462 /* USB Reset Interrupt */ 2723 /* USB Reset Interrupt */
2463 if (dev_intr & UDC_DEVINT_UR) 2724 if (dev_intr & UDC_DEVINT_UR) {
2464 pch_udc_svc_ur_interrupt(dev); 2725 pch_udc_svc_ur_interrupt(dev);
2726 dev_dbg(&dev->pdev->dev, "USB_RESET\n");
2727 }
2465 /* Enumeration Done Interrupt */ 2728 /* Enumeration Done Interrupt */
2466 if (dev_intr & UDC_DEVINT_ENUM) 2729 if (dev_intr & UDC_DEVINT_ENUM) {
2467 pch_udc_svc_enum_interrupt(dev); 2730 pch_udc_svc_enum_interrupt(dev);
2731 dev_dbg(&dev->pdev->dev, "USB_ENUM\n");
2732 }
2468 /* Set Interface Interrupt */ 2733 /* Set Interface Interrupt */
2469 if (dev_intr & UDC_DEVINT_SI) 2734 if (dev_intr & UDC_DEVINT_SI)
2470 pch_udc_svc_intf_interrupt(dev); 2735 pch_udc_svc_intf_interrupt(dev);
@@ -2472,8 +2737,30 @@ static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr)
2472 if (dev_intr & UDC_DEVINT_SC) 2737 if (dev_intr & UDC_DEVINT_SC)
2473 pch_udc_svc_cfg_interrupt(dev); 2738 pch_udc_svc_cfg_interrupt(dev);
2474 /* USB Suspend interrupt */ 2739 /* USB Suspend interrupt */
2475 if (dev_intr & UDC_DEVINT_US) 2740 if (dev_intr & UDC_DEVINT_US) {
2741 if (dev->driver
2742 && dev->driver->suspend) {
2743 spin_unlock(&dev->lock);
2744 dev->driver->suspend(&dev->gadget);
2745 spin_lock(&dev->lock);
2746 }
2747
2748 vbus = pch_vbus_gpio_get_value(dev);
2749 if ((dev->vbus_session == 0)
2750 && (vbus != 1)) {
2751 if (dev->driver && dev->driver->disconnect) {
2752 spin_unlock(&dev->lock);
2753 dev->driver->disconnect(&dev->gadget);
2754 spin_lock(&dev->lock);
2755 }
2756 pch_udc_reconnect(dev);
2757 } else if ((dev->vbus_session == 0)
2758 && (vbus == 1)
2759 && !dev->vbus_gpio.intr)
2760 schedule_work(&dev->vbus_gpio.irq_work_fall);
2761
2476 dev_dbg(&dev->pdev->dev, "USB_SUSPEND\n"); 2762 dev_dbg(&dev->pdev->dev, "USB_SUSPEND\n");
2763 }
2477 /* Clear the SOF interrupt, if enabled */ 2764 /* Clear the SOF interrupt, if enabled */
2478 if (dev_intr & UDC_DEVINT_SOF) 2765 if (dev_intr & UDC_DEVINT_SOF)
2479 dev_dbg(&dev->pdev->dev, "SOF\n"); 2766 dev_dbg(&dev->pdev->dev, "SOF\n");
@@ -2499,6 +2786,14 @@ static irqreturn_t pch_udc_isr(int irq, void *pdev)
2499 dev_intr = pch_udc_read_device_interrupts(dev); 2786 dev_intr = pch_udc_read_device_interrupts(dev);
2500 ep_intr = pch_udc_read_ep_interrupts(dev); 2787 ep_intr = pch_udc_read_ep_interrupts(dev);
2501 2788
2789 /* For a hot plug, this find that the controller is hung up. */
2790 if (dev_intr == ep_intr)
2791 if (dev_intr == pch_udc_readl(dev, UDC_DEVCFG_ADDR)) {
2792 dev_dbg(&dev->pdev->dev, "UDC: Hung up\n");
2793 /* The controller is reset */
2794 pch_udc_writel(dev, UDC_SRST, UDC_SRST_ADDR);
2795 return IRQ_HANDLED;
2796 }
2502 if (dev_intr) 2797 if (dev_intr)
2503 /* Clear device interrupts */ 2798 /* Clear device interrupts */
2504 pch_udc_write_device_interrupts(dev, dev_intr); 2799 pch_udc_write_device_interrupts(dev, dev_intr);
@@ -2625,6 +2920,7 @@ static int pch_udc_pcd_init(struct pch_udc_dev *dev)
2625{ 2920{
2626 pch_udc_init(dev); 2921 pch_udc_init(dev);
2627 pch_udc_pcd_reinit(dev); 2922 pch_udc_pcd_reinit(dev);
2923 pch_vbus_gpio_init(dev, vbus_gpio_port);
2628 return 0; 2924 return 0;
2629} 2925}
2630 2926
@@ -2725,7 +3021,8 @@ static int pch_udc_start(struct usb_gadget_driver *driver,
2725 pch_udc_setup_ep0(dev); 3021 pch_udc_setup_ep0(dev);
2726 3022
2727 /* clear SD */ 3023 /* clear SD */
2728 pch_udc_clear_disconnect(dev); 3024 if ((pch_vbus_gpio_get_value(dev) != 0) || !dev->vbus_gpio.intr)
3025 pch_udc_clear_disconnect(dev);
2729 3026
2730 dev->connected = 1; 3027 dev->connected = 1;
2731 return 0; 3028 return 0;
@@ -2803,6 +3100,8 @@ static void pch_udc_remove(struct pci_dev *pdev)
2803 UDC_EP0OUT_BUFF_SIZE * 4, DMA_FROM_DEVICE); 3100 UDC_EP0OUT_BUFF_SIZE * 4, DMA_FROM_DEVICE);
2804 kfree(dev->ep0out_buf); 3101 kfree(dev->ep0out_buf);
2805 3102
3103 pch_vbus_gpio_free(dev);
3104
2806 pch_udc_exit(dev); 3105 pch_udc_exit(dev);
2807 3106
2808 if (dev->irq_registered) 3107 if (dev->irq_registered)
@@ -2912,8 +3211,10 @@ static int pch_udc_probe(struct pci_dev *pdev,
2912 } 3211 }
2913 pch_udc = dev; 3212 pch_udc = dev;
2914 /* initialize the hardware */ 3213 /* initialize the hardware */
2915 if (pch_udc_pcd_init(dev)) 3214 if (pch_udc_pcd_init(dev)) {
3215 retval = -ENODEV;
2916 goto finished; 3216 goto finished;
3217 }
2917 if (request_irq(pdev->irq, pch_udc_isr, IRQF_SHARED, KBUILD_MODNAME, 3218 if (request_irq(pdev->irq, pch_udc_isr, IRQF_SHARED, KBUILD_MODNAME,
2918 dev)) { 3219 dev)) {
2919 dev_err(&pdev->dev, "%s: request_irq(%d) fail\n", __func__, 3220 dev_err(&pdev->dev, "%s: request_irq(%d) fail\n", __func__,
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index d83134b0f78a..4e4dc1f5f388 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -34,7 +34,6 @@
34#include <asm/byteorder.h> 34#include <asm/byteorder.h>
35#include <linux/io.h> 35#include <linux/io.h>
36#include <linux/irq.h> 36#include <linux/irq.h>
37#include <asm/system.h>
38#include <linux/uaccess.h> 37#include <linux/uaccess.h>
39#include <asm/unaligned.h> 38#include <asm/unaligned.h>
40 39
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index dd470635f4f7..41ed69c96d8c 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -41,7 +41,6 @@
41#include <asm/byteorder.h> 41#include <asm/byteorder.h>
42#include <asm/dma.h> 42#include <asm/dma.h>
43#include <asm/gpio.h> 43#include <asm/gpio.h>
44#include <asm/system.h>
45#include <asm/mach-types.h> 44#include <asm/mach-types.h>
46#include <asm/unaligned.h> 45#include <asm/unaligned.h>
47 46
@@ -283,6 +282,7 @@ static int pxa25x_ep_disable (struct usb_ep *_ep)
283 pxa25x_ep_fifo_flush (_ep); 282 pxa25x_ep_fifo_flush (_ep);
284 283
285 ep->desc = NULL; 284 ep->desc = NULL;
285 ep->ep.desc = NULL;
286 ep->stopped = 1; 286 ep->stopped = 1;
287 287
288 local_irq_restore(flags); 288 local_irq_restore(flags);
@@ -995,7 +995,7 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
995 udc = container_of(_gadget, struct pxa25x_udc, gadget); 995 udc = container_of(_gadget, struct pxa25x_udc, gadget);
996 996
997 if (udc->transceiver) 997 if (udc->transceiver)
998 return otg_set_power(udc->transceiver, mA); 998 return usb_phy_set_power(udc->transceiver, mA);
999 return -EOPNOTSUPP; 999 return -EOPNOTSUPP;
1000} 1000}
1001 1001
@@ -1192,6 +1192,7 @@ static void udc_reinit(struct pxa25x_udc *dev)
1192 list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list); 1192 list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list);
1193 1193
1194 ep->desc = NULL; 1194 ep->desc = NULL;
1195 ep->ep.desc = NULL;
1195 ep->stopped = 0; 1196 ep->stopped = 0;
1196 INIT_LIST_HEAD (&ep->queue); 1197 INIT_LIST_HEAD (&ep->queue);
1197 ep->pio_irqs = 0; 1198 ep->pio_irqs = 0;
@@ -1301,7 +1302,8 @@ fail:
1301 1302
1302 /* connect to bus through transceiver */ 1303 /* connect to bus through transceiver */
1303 if (dev->transceiver) { 1304 if (dev->transceiver) {
1304 retval = otg_set_peripheral(dev->transceiver, &dev->gadget); 1305 retval = otg_set_peripheral(dev->transceiver->otg,
1306 &dev->gadget);
1305 if (retval) { 1307 if (retval) {
1306 DMSG("can't bind to transceiver\n"); 1308 DMSG("can't bind to transceiver\n");
1307 if (driver->unbind) 1309 if (driver->unbind)
@@ -1360,7 +1362,7 @@ static int pxa25x_stop(struct usb_gadget_driver *driver)
1360 local_irq_enable(); 1362 local_irq_enable();
1361 1363
1362 if (dev->transceiver) 1364 if (dev->transceiver)
1363 (void) otg_set_peripheral(dev->transceiver, NULL); 1365 (void) otg_set_peripheral(dev->transceiver->otg, NULL);
1364 1366
1365 driver->unbind(&dev->gadget); 1367 driver->unbind(&dev->gadget);
1366 dev->gadget.dev.driver = NULL; 1368 dev->gadget.dev.driver = NULL;
@@ -2159,7 +2161,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2159 dev->dev = &pdev->dev; 2161 dev->dev = &pdev->dev;
2160 dev->mach = pdev->dev.platform_data; 2162 dev->mach = pdev->dev.platform_data;
2161 2163
2162 dev->transceiver = otg_get_transceiver(); 2164 dev->transceiver = usb_get_transceiver();
2163 2165
2164 if (gpio_is_valid(dev->mach->gpio_pullup)) { 2166 if (gpio_is_valid(dev->mach->gpio_pullup)) {
2165 if ((retval = gpio_request(dev->mach->gpio_pullup, 2167 if ((retval = gpio_request(dev->mach->gpio_pullup,
@@ -2238,7 +2240,7 @@ lubbock_fail0:
2238 gpio_free(dev->mach->gpio_pullup); 2240 gpio_free(dev->mach->gpio_pullup);
2239 err_gpio_pullup: 2241 err_gpio_pullup:
2240 if (dev->transceiver) { 2242 if (dev->transceiver) {
2241 otg_put_transceiver(dev->transceiver); 2243 usb_put_transceiver(dev->transceiver);
2242 dev->transceiver = NULL; 2244 dev->transceiver = NULL;
2243 } 2245 }
2244 clk_put(dev->clk); 2246 clk_put(dev->clk);
@@ -2280,7 +2282,7 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2280 clk_put(dev->clk); 2282 clk_put(dev->clk);
2281 2283
2282 if (dev->transceiver) { 2284 if (dev->transceiver) {
2283 otg_put_transceiver(dev->transceiver); 2285 usb_put_transceiver(dev->transceiver);
2284 dev->transceiver = NULL; 2286 dev->transceiver = NULL;
2285 } 2287 }
2286 2288
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h
index 8eaf4e43726b..893e917f048e 100644
--- a/drivers/usb/gadget/pxa25x_udc.h
+++ b/drivers/usb/gadget/pxa25x_udc.h
@@ -119,7 +119,7 @@ struct pxa25x_udc {
119 struct device *dev; 119 struct device *dev;
120 struct clk *clk; 120 struct clk *clk;
121 struct pxa2xx_udc_mach_info *mach; 121 struct pxa2xx_udc_mach_info *mach;
122 struct otg_transceiver *transceiver; 122 struct usb_phy *transceiver;
123 u64 dma_mask; 123 u64 dma_mask;
124 struct pxa25x_ep ep [PXA_UDC_NUM_ENDPOINTS]; 124 struct pxa25x_ep ep [PXA_UDC_NUM_ENDPOINTS];
125 125
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index f4c44eb806c3..98acb3ab9e17 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -1666,7 +1666,7 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1666 1666
1667 udc = to_gadget_udc(_gadget); 1667 udc = to_gadget_udc(_gadget);
1668 if (udc->transceiver) 1668 if (udc->transceiver)
1669 return otg_set_power(udc->transceiver, mA); 1669 return usb_phy_set_power(udc->transceiver, mA);
1670 return -EOPNOTSUPP; 1670 return -EOPNOTSUPP;
1671} 1671}
1672 1672
@@ -1835,7 +1835,8 @@ static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1835 driver->driver.name); 1835 driver->driver.name);
1836 1836
1837 if (udc->transceiver) { 1837 if (udc->transceiver) {
1838 retval = otg_set_peripheral(udc->transceiver, &udc->gadget); 1838 retval = otg_set_peripheral(udc->transceiver->otg,
1839 &udc->gadget);
1839 if (retval) { 1840 if (retval) {
1840 dev_err(udc->dev, "can't bind to transceiver\n"); 1841 dev_err(udc->dev, "can't bind to transceiver\n");
1841 goto transceiver_fail; 1842 goto transceiver_fail;
@@ -1908,7 +1909,7 @@ static int pxa27x_udc_stop(struct usb_gadget_driver *driver)
1908 driver->driver.name); 1909 driver->driver.name);
1909 1910
1910 if (udc->transceiver) 1911 if (udc->transceiver)
1911 return otg_set_peripheral(udc->transceiver, NULL); 1912 return otg_set_peripheral(udc->transceiver->otg, NULL);
1912 return 0; 1913 return 0;
1913} 1914}
1914 1915
@@ -2463,7 +2464,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2463 2464
2464 udc->dev = &pdev->dev; 2465 udc->dev = &pdev->dev;
2465 udc->mach = pdev->dev.platform_data; 2466 udc->mach = pdev->dev.platform_data;
2466 udc->transceiver = otg_get_transceiver(); 2467 udc->transceiver = usb_get_transceiver();
2467 2468
2468 gpio = udc->mach->gpio_pullup; 2469 gpio = udc->mach->gpio_pullup;
2469 if (gpio_is_valid(gpio)) { 2470 if (gpio_is_valid(gpio)) {
@@ -2542,7 +2543,7 @@ static int __exit pxa_udc_remove(struct platform_device *_dev)
2542 if (gpio_is_valid(gpio)) 2543 if (gpio_is_valid(gpio))
2543 gpio_free(gpio); 2544 gpio_free(gpio);
2544 2545
2545 otg_put_transceiver(udc->transceiver); 2546 usb_put_transceiver(udc->transceiver);
2546 2547
2547 udc->transceiver = NULL; 2548 udc->transceiver = NULL;
2548 platform_set_drvdata(_dev, NULL); 2549 platform_set_drvdata(_dev, NULL);
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
index 7f4e8f424e80..a1d268c6f2cc 100644
--- a/drivers/usb/gadget/pxa27x_udc.h
+++ b/drivers/usb/gadget/pxa27x_udc.h
@@ -447,7 +447,7 @@ struct pxa_udc {
447 struct usb_gadget_driver *driver; 447 struct usb_gadget_driver *driver;
448 struct device *dev; 448 struct device *dev;
449 struct pxa2xx_udc_mach_info *mach; 449 struct pxa2xx_udc_mach_info *mach;
450 struct otg_transceiver *transceiver; 450 struct usb_phy *transceiver;
451 451
452 enum ep0_state ep0state; 452 enum ep0_state ep0state;
453 struct udc_stats stats; 453 struct udc_stats stats;
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index f5b8d215e1d5..c4401e7dd3a6 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -663,11 +663,7 @@ static int sudmac_alloc_channel(struct r8a66597 *r8a66597,
663 ep->fifoctr = D0FIFOCTR; 663 ep->fifoctr = D0FIFOCTR;
664 664
665 /* dma mapping */ 665 /* dma mapping */
666 req->req.dma = dma_map_single(r8a66597_to_dev(ep->r8a66597), 666 return usb_gadget_map_request(&r8a66597->gadget, &req->req, dma->dir);
667 req->req.buf, req->req.length,
668 dma->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
669
670 return 0;
671} 667}
672 668
673static void sudmac_free_channel(struct r8a66597 *r8a66597, 669static void sudmac_free_channel(struct r8a66597 *r8a66597,
@@ -677,9 +673,7 @@ static void sudmac_free_channel(struct r8a66597 *r8a66597,
677 if (!r8a66597_is_sudmac(r8a66597)) 673 if (!r8a66597_is_sudmac(r8a66597))
678 return; 674 return;
679 675
680 dma_unmap_single(r8a66597_to_dev(ep->r8a66597), 676 usb_gadget_unmap_request(&r8a66597->gadget, &req->req, ep->dma->dir);
681 req->req.dma, req->req.length,
682 ep->dma->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
683 677
684 r8a66597_bclr(r8a66597, DREQE, ep->fifosel); 678 r8a66597_bclr(r8a66597, DREQE, ep->fifosel);
685 r8a66597_change_curpipe(r8a66597, 0, 0, ep->fifosel); 679 r8a66597_change_curpipe(r8a66597, 0, 0, ep->fifosel);
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index d3cdffea9c8a..73a934a170d1 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -34,7 +34,6 @@
34 34
35#include <asm/io.h> 35#include <asm/io.h>
36#include <asm/byteorder.h> 36#include <asm/byteorder.h>
37#include <asm/system.h>
38#include <asm/unaligned.h> 37#include <asm/unaligned.h>
39 38
40 39
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index df8661d266cb..cef9b82ff911 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -30,6 +30,7 @@
30#include <linux/prefetch.h> 30#include <linux/prefetch.h>
31#include <linux/platform_data/s3c-hsudc.h> 31#include <linux/platform_data/s3c-hsudc.h>
32#include <linux/regulator/consumer.h> 32#include <linux/regulator/consumer.h>
33#include <linux/pm_runtime.h>
33 34
34#include <mach/regs-s3c2443-clock.h> 35#include <mach/regs-s3c2443-clock.h>
35 36
@@ -145,7 +146,7 @@ struct s3c_hsudc {
145 struct usb_gadget_driver *driver; 146 struct usb_gadget_driver *driver;
146 struct device *dev; 147 struct device *dev;
147 struct s3c24xx_hsudc_platdata *pd; 148 struct s3c24xx_hsudc_platdata *pd;
148 struct otg_transceiver *transceiver; 149 struct usb_phy *transceiver;
149 struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsudc_supply_names)]; 150 struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsudc_supply_names)];
150 spinlock_t lock; 151 spinlock_t lock;
151 void __iomem *regs; 152 void __iomem *regs;
@@ -759,7 +760,7 @@ static int s3c_hsudc_ep_enable(struct usb_ep *_ep,
759 unsigned long flags; 760 unsigned long flags;
760 u32 ecr = 0; 761 u32 ecr = 0;
761 762
762 hsep = container_of(_ep, struct s3c_hsudc_ep, ep); 763 hsep = our_ep(_ep);
763 if (!_ep || !desc || hsep->desc || _ep->name == ep0name 764 if (!_ep || !desc || hsep->desc || _ep->name == ep0name
764 || desc->bDescriptorType != USB_DT_ENDPOINT 765 || desc->bDescriptorType != USB_DT_ENDPOINT
765 || hsep->bEndpointAddress != desc->bEndpointAddress 766 || hsep->bEndpointAddress != desc->bEndpointAddress
@@ -816,6 +817,7 @@ static int s3c_hsudc_ep_disable(struct usb_ep *_ep)
816 s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN); 817 s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN);
817 818
818 hsep->desc = 0; 819 hsep->desc = 0;
820 hsep->ep.desc = NULL;
819 hsep->stopped = 1; 821 hsep->stopped = 1;
820 822
821 spin_unlock_irqrestore(&hsudc->lock, flags); 823 spin_unlock_irqrestore(&hsudc->lock, flags);
@@ -853,7 +855,7 @@ static void s3c_hsudc_free_request(struct usb_ep *ep, struct usb_request *_req)
853{ 855{
854 struct s3c_hsudc_req *hsreq; 856 struct s3c_hsudc_req *hsreq;
855 857
856 hsreq = container_of(_req, struct s3c_hsudc_req, req); 858 hsreq = our_req(_req);
857 WARN_ON(!list_empty(&hsreq->queue)); 859 WARN_ON(!list_empty(&hsreq->queue));
858 kfree(hsreq); 860 kfree(hsreq);
859} 861}
@@ -876,12 +878,12 @@ static int s3c_hsudc_queue(struct usb_ep *_ep, struct usb_request *_req,
876 u32 offset; 878 u32 offset;
877 u32 csr; 879 u32 csr;
878 880
879 hsreq = container_of(_req, struct s3c_hsudc_req, req); 881 hsreq = our_req(_req);
880 if ((!_req || !_req->complete || !_req->buf || 882 if ((!_req || !_req->complete || !_req->buf ||
881 !list_empty(&hsreq->queue))) 883 !list_empty(&hsreq->queue)))
882 return -EINVAL; 884 return -EINVAL;
883 885
884 hsep = container_of(_ep, struct s3c_hsudc_ep, ep); 886 hsep = our_ep(_ep);
885 hsudc = hsep->dev; 887 hsudc = hsep->dev;
886 if (!hsudc->driver || hsudc->gadget.speed == USB_SPEED_UNKNOWN) 888 if (!hsudc->driver || hsudc->gadget.speed == USB_SPEED_UNKNOWN)
887 return -ESHUTDOWN; 889 return -ESHUTDOWN;
@@ -935,7 +937,7 @@ static int s3c_hsudc_dequeue(struct usb_ep *_ep, struct usb_request *_req)
935 struct s3c_hsudc_req *hsreq; 937 struct s3c_hsudc_req *hsreq;
936 unsigned long flags; 938 unsigned long flags;
937 939
938 hsep = container_of(_ep, struct s3c_hsudc_ep, ep); 940 hsep = our_ep(_ep);
939 if (!_ep || hsep->ep.name == ep0name) 941 if (!_ep || hsep->ep.name == ep0name)
940 return -EINVAL; 942 return -EINVAL;
941 943
@@ -1005,6 +1007,7 @@ static void s3c_hsudc_initep(struct s3c_hsudc *hsudc,
1005 hsep->ep.ops = &s3c_hsudc_ep_ops; 1007 hsep->ep.ops = &s3c_hsudc_ep_ops;
1006 hsep->fifo = hsudc->regs + S3C_BR(epnum); 1008 hsep->fifo = hsudc->regs + S3C_BR(epnum);
1007 hsep->desc = 0; 1009 hsep->desc = 0;
1010 hsep->ep.desc = NULL;
1008 hsep->stopped = 0; 1011 hsep->stopped = 0;
1009 hsep->wedge = 0; 1012 hsep->wedge = 0;
1010 1013
@@ -1166,7 +1169,8 @@ static int s3c_hsudc_start(struct usb_gadget *gadget,
1166 1169
1167 /* connect to bus through transceiver */ 1170 /* connect to bus through transceiver */
1168 if (hsudc->transceiver) { 1171 if (hsudc->transceiver) {
1169 ret = otg_set_peripheral(hsudc->transceiver, &hsudc->gadget); 1172 ret = otg_set_peripheral(hsudc->transceiver->otg,
1173 &hsudc->gadget);
1170 if (ret) { 1174 if (ret) {
1171 dev_err(hsudc->dev, "%s: can't bind to transceiver\n", 1175 dev_err(hsudc->dev, "%s: can't bind to transceiver\n",
1172 hsudc->gadget.name); 1176 hsudc->gadget.name);
@@ -1178,6 +1182,9 @@ static int s3c_hsudc_start(struct usb_gadget *gadget,
1178 dev_info(hsudc->dev, "bound driver %s\n", driver->driver.name); 1182 dev_info(hsudc->dev, "bound driver %s\n", driver->driver.name);
1179 1183
1180 s3c_hsudc_reconfig(hsudc); 1184 s3c_hsudc_reconfig(hsudc);
1185
1186 pm_runtime_get_sync(hsudc->dev);
1187
1181 s3c_hsudc_init_phy(); 1188 s3c_hsudc_init_phy();
1182 if (hsudc->pd->gpio_init) 1189 if (hsudc->pd->gpio_init)
1183 hsudc->pd->gpio_init(); 1190 hsudc->pd->gpio_init();
@@ -1208,13 +1215,16 @@ static int s3c_hsudc_stop(struct usb_gadget *gadget,
1208 hsudc->gadget.dev.driver = NULL; 1215 hsudc->gadget.dev.driver = NULL;
1209 hsudc->gadget.speed = USB_SPEED_UNKNOWN; 1216 hsudc->gadget.speed = USB_SPEED_UNKNOWN;
1210 s3c_hsudc_uninit_phy(); 1217 s3c_hsudc_uninit_phy();
1218
1219 pm_runtime_put(hsudc->dev);
1220
1211 if (hsudc->pd->gpio_uninit) 1221 if (hsudc->pd->gpio_uninit)
1212 hsudc->pd->gpio_uninit(); 1222 hsudc->pd->gpio_uninit();
1213 s3c_hsudc_stop_activity(hsudc); 1223 s3c_hsudc_stop_activity(hsudc);
1214 spin_unlock_irqrestore(&hsudc->lock, flags); 1224 spin_unlock_irqrestore(&hsudc->lock, flags);
1215 1225
1216 if (hsudc->transceiver) 1226 if (hsudc->transceiver)
1217 (void) otg_set_peripheral(hsudc->transceiver, NULL); 1227 (void) otg_set_peripheral(hsudc->transceiver->otg, NULL);
1218 1228
1219 disable_irq(hsudc->irq); 1229 disable_irq(hsudc->irq);
1220 1230
@@ -1243,7 +1253,7 @@ static int s3c_hsudc_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1243 return -ENODEV; 1253 return -ENODEV;
1244 1254
1245 if (hsudc->transceiver) 1255 if (hsudc->transceiver)
1246 return otg_set_power(hsudc->transceiver, mA); 1256 return usb_phy_set_power(hsudc->transceiver, mA);
1247 1257
1248 return -EOPNOTSUPP; 1258 return -EOPNOTSUPP;
1249} 1259}
@@ -1275,7 +1285,7 @@ static int __devinit s3c_hsudc_probe(struct platform_device *pdev)
1275 hsudc->dev = dev; 1285 hsudc->dev = dev;
1276 hsudc->pd = pdev->dev.platform_data; 1286 hsudc->pd = pdev->dev.platform_data;
1277 1287
1278 hsudc->transceiver = otg_get_transceiver(); 1288 hsudc->transceiver = usb_get_transceiver();
1279 1289
1280 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++) 1290 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++)
1281 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i]; 1291 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i];
@@ -1362,6 +1372,8 @@ static int __devinit s3c_hsudc_probe(struct platform_device *pdev)
1362 if (ret) 1372 if (ret)
1363 goto err_add_udc; 1373 goto err_add_udc;
1364 1374
1375 pm_runtime_enable(dev);
1376
1365 return 0; 1377 return 0;
1366err_add_udc: 1378err_add_udc:
1367 device_unregister(&hsudc->gadget.dev); 1379 device_unregister(&hsudc->gadget.dev);
@@ -1377,7 +1389,7 @@ err_remap:
1377 release_mem_region(res->start, resource_size(res)); 1389 release_mem_region(res->start, resource_size(res));
1378err_res: 1390err_res:
1379 if (hsudc->transceiver) 1391 if (hsudc->transceiver)
1380 otg_put_transceiver(hsudc->transceiver); 1392 usb_put_transceiver(hsudc->transceiver);
1381 1393
1382 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1394 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies);
1383err_supplies: 1395err_supplies:
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index 3f87cb9344bb..195524cde6c3 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -37,7 +37,6 @@
37#include <asm/byteorder.h> 37#include <asm/byteorder.h>
38#include <asm/io.h> 38#include <asm/io.h>
39#include <asm/irq.h> 39#include <asm/irq.h>
40#include <asm/system.h>
41#include <asm/unaligned.h> 40#include <asm/unaligned.h>
42#include <mach/irqs.h> 41#include <mach/irqs.h>
43 42
@@ -1148,6 +1147,7 @@ static int s3c2410_udc_ep_disable(struct usb_ep *_ep)
1148 dprintk(DEBUG_NORMAL, "ep_disable: %s\n", _ep->name); 1147 dprintk(DEBUG_NORMAL, "ep_disable: %s\n", _ep->name);
1149 1148
1150 ep->desc = NULL; 1149 ep->desc = NULL;
1150 ep->ep.desc = NULL;
1151 ep->halted = 1; 1151 ep->halted = 1;
1152 1152
1153 s3c2410_udc_nuke (ep->dev, ep, -ESHUTDOWN); 1153 s3c2410_udc_nuke (ep->dev, ep, -ESHUTDOWN);
@@ -1630,6 +1630,7 @@ static void s3c2410_udc_reinit(struct s3c2410_udc *dev)
1630 1630
1631 ep->dev = dev; 1631 ep->dev = dev;
1632 ep->desc = NULL; 1632 ep->desc = NULL;
1633 ep->ep.desc = NULL;
1633 ep->halted = 0; 1634 ep->halted = 0;
1634 INIT_LIST_HEAD (&ep->queue); 1635 INIT_LIST_HEAD (&ep->queue);
1635 } 1636 }
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index ad9e5b2df642..665c07422c26 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -242,7 +242,7 @@ static struct usb_composite_driver gserial_driver = {
242 .name = "g_serial", 242 .name = "g_serial",
243 .dev = &device_desc, 243 .dev = &device_desc,
244 .strings = dev_strings, 244 .strings = dev_strings,
245 .max_speed = USB_SPEED_HIGH, 245 .max_speed = USB_SPEED_SUPER,
246}; 246};
247 247
248static int __init init(void) 248static int __init init(void)
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 85ea14e2545e..8081ca3a70a2 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2003-2008 Alan Stern 4 * Copyright (C) 2003-2008 Alan Stern
5 * Copyeight (C) 2009 Samsung Electronics 5 * Copyeight (C) 2009 Samsung Electronics
6 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com) 6 * Author: Michal Nazarewicz (mina86@mina86.com)
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -145,48 +145,8 @@
145 145
146#endif /* DUMP_MSGS */ 146#endif /* DUMP_MSGS */
147 147
148
149
150
151
152/*-------------------------------------------------------------------------*/ 148/*-------------------------------------------------------------------------*/
153 149
154/* Bulk-only data structures */
155
156/* Command Block Wrapper */
157struct fsg_bulk_cb_wrap {
158 __le32 Signature; /* Contains 'USBC' */
159 u32 Tag; /* Unique per command id */
160 __le32 DataTransferLength; /* Size of the data */
161 u8 Flags; /* Direction in bit 7 */
162 u8 Lun; /* LUN (normally 0) */
163 u8 Length; /* Of the CDB, <= MAX_COMMAND_SIZE */
164 u8 CDB[16]; /* Command Data Block */
165};
166
167#define USB_BULK_CB_WRAP_LEN 31
168#define USB_BULK_CB_SIG 0x43425355 /* Spells out USBC */
169#define USB_BULK_IN_FLAG 0x80
170
171/* Command Status Wrapper */
172struct bulk_cs_wrap {
173 __le32 Signature; /* Should = 'USBS' */
174 u32 Tag; /* Same as original command */
175 __le32 Residue; /* Amount not transferred */
176 u8 Status; /* See below */
177};
178
179#define USB_BULK_CS_WRAP_LEN 13
180#define USB_BULK_CS_SIG 0x53425355 /* Spells out 'USBS' */
181#define USB_STATUS_PASS 0
182#define USB_STATUS_FAIL 1
183#define USB_STATUS_PHASE_ERROR 2
184
185/* Bulk-only class specific requests */
186#define USB_BULK_RESET_REQUEST 0xff
187#define USB_BULK_GET_MAX_LUN_REQUEST 0xfe
188
189
190/* CBI Interrupt data structure */ 150/* CBI Interrupt data structure */
191struct interrupt_data { 151struct interrupt_data {
192 u8 bType; 152 u8 bType;
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index a553beeb86d5..09aa92064277 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -725,9 +725,6 @@ static int gs_open(struct tty_struct *tty, struct file *file)
725 struct gs_port *port; 725 struct gs_port *port;
726 int status; 726 int status;
727 727
728 if (port_num < 0 || port_num >= n_ports)
729 return -ENXIO;
730
731 do { 728 do {
732 mutex_lock(&ports[port_num].lock); 729 mutex_lock(&ports[port_num].lock);
733 port = ports[port_num].port; 730 port = ports[port_num].port;
@@ -1087,7 +1084,6 @@ int __init gserial_setup(struct usb_gadget *g, unsigned count)
1087 if (!gs_tty_driver) 1084 if (!gs_tty_driver)
1088 return -ENOMEM; 1085 return -ENOMEM;
1089 1086
1090 gs_tty_driver->owner = THIS_MODULE;
1091 gs_tty_driver->driver_name = "g_serial"; 1087 gs_tty_driver->driver_name = "g_serial";
1092 gs_tty_driver->name = PREFIX; 1088 gs_tty_driver->name = PREFIX;
1093 /* uses dynamically assigned dev_t values */ 1089 /* uses dynamically assigned dev_t values */
diff --git a/drivers/usb/gadget/u_audio.c b/drivers/usb/gadget/u_uac1.c
index 59ffe1ecf1c9..af9898982059 100644
--- a/drivers/usb/gadget/u_audio.c
+++ b/drivers/usb/gadget/u_uac1.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * u_audio.c -- ALSA audio utilities for Gadget stack 2 * u_uac1.c -- ALSA audio utilities for Gadget stack
3 * 3 *
4 * Copyright (C) 2008 Bryan Wu <cooloney@kernel.org> 4 * Copyright (C) 2008 Bryan Wu <cooloney@kernel.org>
5 * Copyright (C) 2008 Analog Devices, Inc 5 * Copyright (C) 2008 Analog Devices, Inc
@@ -17,7 +17,7 @@
17#include <linux/random.h> 17#include <linux/random.h>
18#include <linux/syscalls.h> 18#include <linux/syscalls.h>
19 19
20#include "u_audio.h" 20#include "u_uac1.h"
21 21
22/* 22/*
23 * This component encapsulates the ALSA devices for USB audio gadget 23 * This component encapsulates the ALSA devices for USB audio gadget
diff --git a/drivers/usb/gadget/u_audio.h b/drivers/usb/gadget/u_uac1.h
index 08ffce3298e6..18c2e729faf6 100644
--- a/drivers/usb/gadget/u_audio.h
+++ b/drivers/usb/gadget/u_uac1.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * u_audio.h -- interface to USB gadget "ALSA AUDIO" utilities 2 * u_uac1.h -- interface to USB gadget "ALSA AUDIO" utilities
3 * 3 *
4 * Copyright (C) 2008 Bryan Wu <cooloney@kernel.org> 4 * Copyright (C) 2008 Bryan Wu <cooloney@kernel.org>
5 * Copyright (C) 2008 Analog Devices, Inc 5 * Copyright (C) 2008 Analog Devices, Inc
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 0b0d12ccc487..56da49f31d6c 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -22,6 +22,7 @@
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/dma-mapping.h>
25 26
26#include <linux/usb/ch9.h> 27#include <linux/usb/ch9.h>
27#include <linux/usb/gadget.h> 28#include <linux/usb/gadget.h>
@@ -49,6 +50,57 @@ static DEFINE_MUTEX(udc_lock);
49 50
50/* ------------------------------------------------------------------------- */ 51/* ------------------------------------------------------------------------- */
51 52
53int usb_gadget_map_request(struct usb_gadget *gadget,
54 struct usb_request *req, int is_in)
55{
56 if (req->length == 0)
57 return 0;
58
59 if (req->num_sgs) {
60 int mapped;
61
62 mapped = dma_map_sg(&gadget->dev, req->sg, req->num_sgs,
63 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
64 if (mapped == 0) {
65 dev_err(&gadget->dev, "failed to map SGs\n");
66 return -EFAULT;
67 }
68
69 req->num_mapped_sgs = mapped;
70 } else {
71 req->dma = dma_map_single(&gadget->dev, req->buf, req->length,
72 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
73
74 if (dma_mapping_error(&gadget->dev, req->dma)) {
75 dev_err(&gadget->dev, "failed to map buffer\n");
76 return -EFAULT;
77 }
78 }
79
80 return 0;
81}
82EXPORT_SYMBOL_GPL(usb_gadget_map_request);
83
84void usb_gadget_unmap_request(struct usb_gadget *gadget,
85 struct usb_request *req, int is_in)
86{
87 if (req->length == 0)
88 return;
89
90 if (req->num_mapped_sgs) {
91 dma_unmap_sg(&gadget->dev, req->sg, req->num_mapped_sgs,
92 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
93
94 req->num_mapped_sgs = 0;
95 } else {
96 dma_unmap_single(&gadget->dev, req->dma, req->length,
97 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
98 }
99}
100EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
101
102/* ------------------------------------------------------------------------- */
103
52/** 104/**
53 * usb_gadget_start - tells usb device controller to start up 105 * usb_gadget_start - tells usb device controller to start up
54 * @gadget: The gadget we want to get started 106 * @gadget: The gadget we want to get started