aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-07-26 02:08:32 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-07-26 02:08:32 -0400
commitf549953c15deab4c54708b39af86d4edecc6cddc (patch)
treef0412f989b77cdceab34c18aa85a8a25d5942a1f
parentf0deb97ab13ad1f89cd0993f7339655d59788405 (diff)
parente04f5f7e423018bcec84c11af2058cdce87816f3 (diff)
Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (115 commits) EHCI: fix direction handling for interrupt data toggles USB: serial: add IDs for WinChipHead USB->RS232 adapter USB: OHCI: fix another regression for NVIDIA controllers usb: gadget: m66592-udc: add pullup function usb: gadget: m66592-udc: add function for external controller usb: gadget: r8a66597-udc: add pullup function usb: renesas_usbhs: support multi driver usb: renesas_usbhs: inaccessible pipe is not an error usb: renesas_usbhs: care buff alignment when dma handler USB: PL2303: correctly handle baudrates above 115200 usb: r8a66597-hcd: fixup USB_PORT_STAT_C_SUSPEND shift usb: renesas_usbhs: compile/config are rescued usb: renesas_usbhs: fixup comment-out usb: update email address in ohci-sh and r8a66597-hcd usb: r8a66597-hcd: add function for external controller EHCI: only power off port if over-current is active USB: mon: Allow to use usbmon without debugfs USB: EHCI: go back to using the system clock for QH unlinks ehci: add pci quirk for Ordissimo and RM Slate 100 too ehci: refactor pci quirk to use standard dmi_check_system method ... Fix up trivial conflicts in Documentation/feature-removal-schedule.txt
-rw-r--r--Documentation/ABI/testing/sysfs-module23
-rw-r--r--Documentation/feature-removal-schedule.txt7
-rw-r--r--Documentation/kernel-parameters.txt5
-rw-r--r--Documentation/usb/ehci.txt2
-rw-r--r--Documentation/usb/gadget_hid.txt6
-rw-r--r--arch/arm/mach-omap2/usb-musb.c10
-rw-r--r--drivers/usb/atm/ueagle-atm.c38
-rw-r--r--drivers/usb/atm/usbatm.c4
-rw-r--r--drivers/usb/class/usblp.c7
-rw-r--r--drivers/usb/core/hcd.c17
-rw-r--r--drivers/usb/gadget/Kconfig313
-rw-r--r--drivers/usb/gadget/Makefile2
-rw-r--r--drivers/usb/gadget/amd5536udc.c18
-rw-r--r--drivers/usb/gadget/at91_udc.c20
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c26
-rw-r--r--drivers/usb/gadget/audio.c1
-rw-r--r--drivers/usb/gadget/cdc2.c1
-rw-r--r--drivers/usb/gadget/ci13xxx_msm.c1
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c62
-rw-r--r--drivers/usb/gadget/composite.c363
-rw-r--r--drivers/usb/gadget/config.c25
-rw-r--r--drivers/usb/gadget/dbgp.c10
-rw-r--r--drivers/usb/gadget/dummy_hcd.c1162
-rw-r--r--drivers/usb/gadget/epautoconf.c132
-rw-r--r--drivers/usb/gadget/ether.c1
-rw-r--r--drivers/usb/gadget/f_acm.c50
-rw-r--r--drivers/usb/gadget/f_audio.c5
-rw-r--r--drivers/usb/gadget/f_ecm.c152
-rw-r--r--drivers/usb/gadget/f_eem.c90
-rw-r--r--drivers/usb/gadget/f_fs.c3
-rw-r--r--drivers/usb/gadget/f_hid.c22
-rw-r--r--drivers/usb/gadget/f_loopback.c72
-rw-r--r--drivers/usb/gadget/f_mass_storage.c33
-rw-r--r--drivers/usb/gadget/f_ncm.c58
-rw-r--r--drivers/usb/gadget/f_obex.c32
-rw-r--r--drivers/usb/gadget/f_phonet.c17
-rw-r--r--drivers/usb/gadget/f_rndis.c151
-rw-r--r--drivers/usb/gadget/f_serial.c32
-rw-r--r--drivers/usb/gadget/f_sourcesink.c71
-rw-r--r--drivers/usb/gadget/f_subset.c95
-rw-r--r--drivers/usb/gadget/f_uvc.c8
-rw-r--r--drivers/usb/gadget/file_storage.c15
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c20
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c20
-rw-r--r--drivers/usb/gadget/fusb300_udc.c111
-rw-r--r--drivers/usb/gadget/g_ffs.c1
-rw-r--r--drivers/usb/gadget/gadget_chips.h178
-rw-r--r--drivers/usb/gadget/gmidi.c9
-rw-r--r--drivers/usb/gadget/goku_udc.c19
-rw-r--r--drivers/usb/gadget/hid.c1
-rw-r--r--drivers/usb/gadget/imx_udc.c20
-rw-r--r--drivers/usb/gadget/inode.c11
-rw-r--r--drivers/usb/gadget/langwell_udc.c32
-rw-r--r--drivers/usb/gadget/m66592-udc.c62
-rw-r--r--drivers/usb/gadget/m66592-udc.h40
-rw-r--r--drivers/usb/gadget/mass_storage.c1
-rw-r--r--drivers/usb/gadget/multi.c1
-rw-r--r--drivers/usb/gadget/mv_udc_core.c21
-rw-r--r--drivers/usb/gadget/ncm.c1
-rw-r--r--drivers/usb/gadget/net2272.c2752
-rw-r--r--drivers/usb/gadget/net2272.h601
-rw-r--r--drivers/usb/gadget/net2280.c74
-rw-r--r--drivers/usb/gadget/nokia.c1
-rw-r--r--drivers/usb/gadget/omap_udc.c22
-rw-r--r--drivers/usb/gadget/pch_udc.c16
-rw-r--r--drivers/usb/gadget/printer.c40
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c19
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c23
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c71
-rw-r--r--drivers/usb/gadget/r8a66597-udc.h2
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c19
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c17
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c60
-rw-r--r--drivers/usb/gadget/serial.c1
-rw-r--r--drivers/usb/gadget/storage_common.c2
-rw-r--r--drivers/usb/gadget/u_ether.c24
-rw-r--r--drivers/usb/gadget/u_ether.h4
-rw-r--r--drivers/usb/gadget/u_serial.c4
-rw-r--r--drivers/usb/gadget/u_serial.h2
-rw-r--r--drivers/usb/gadget/udc-core.c484
-rw-r--r--drivers/usb/gadget/webcam.c1
-rw-r--r--drivers/usb/gadget/zero.c1
-rw-r--r--drivers/usb/host/ehci-hcd.c21
-rw-r--r--drivers/usb/host/ehci-hub.c78
-rw-r--r--drivers/usb/host/ehci-msm.c20
-rw-r--r--drivers/usb/host/ehci-q.c85
-rw-r--r--drivers/usb/host/ehci-s5p.c95
-rw-r--r--drivers/usb/host/ehci-sched.c17
-rw-r--r--drivers/usb/host/ehci-sysfs.c190
-rw-r--r--drivers/usb/host/ehci.h6
-rw-r--r--drivers/usb/host/ohci-sh.c2
-rw-r--r--drivers/usb/host/pci-quirks.c56
-rw-r--r--drivers/usb/host/r8a66597-hcd.c6
-rw-r--r--drivers/usb/host/r8a66597.h38
-rw-r--r--drivers/usb/host/xhci-dbg.c22
-rw-r--r--drivers/usb/host/xhci-mem.c26
-rw-r--r--drivers/usb/host/xhci-ring.c42
-rw-r--r--drivers/usb/host/xhci.c10
-rw-r--r--drivers/usb/host/xhci.h7
-rw-r--r--drivers/usb/mon/mon_text.c9
-rw-r--r--drivers/usb/musb/Kconfig75
-rw-r--r--drivers/usb/musb/Makefile4
-rw-r--r--drivers/usb/musb/am35x.c4
-rw-r--r--drivers/usb/musb/blackfin.h2
-rw-r--r--drivers/usb/musb/da8xx.c12
-rw-r--r--drivers/usb/musb/davinci.c5
-rw-r--r--drivers/usb/musb/musb_core.c133
-rw-r--r--drivers/usb/musb/musb_core.h70
-rw-r--r--drivers/usb/musb/musb_gadget.c102
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c4
-rw-r--r--drivers/usb/musb/musb_host.h4
-rw-r--r--drivers/usb/musb/musb_virthub.c6
-rw-r--r--drivers/usb/musb/omap2430.c15
-rw-r--r--drivers/usb/musb/tusb6010.c26
-rw-r--r--drivers/usb/otg/twl6030-usb.c30
-rw-r--r--drivers/usb/renesas_usbhs/Kconfig13
-rw-r--r--drivers/usb/renesas_usbhs/Makefile2
-rw-r--r--drivers/usb/renesas_usbhs/common.c34
-rw-r--r--drivers/usb/renesas_usbhs/common.h44
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c1015
-rw-r--r--drivers/usb/renesas_usbhs/fifo.h104
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c840
-rw-r--r--drivers/usb/renesas_usbhs/pipe.c298
-rw-r--r--drivers/usb/renesas_usbhs/pipe.h47
-rw-r--r--drivers/usb/serial/pl2303.c27
-rw-r--r--drivers/usb/serial/pl2303.h4
-rw-r--r--drivers/usb/storage/Kconfig4
-rw-r--r--drivers/usb/storage/realtek_cr.c490
-rw-r--r--drivers/usb/wusbcore/cbaf.c4
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c7
-rw-r--r--include/linux/usb/composite.h32
-rw-r--r--include/linux/usb/gadget.h88
-rw-r--r--include/linux/usb/m66592.h2
-rw-r--r--include/linux/usb/r8a66597.h8
-rw-r--r--include/linux/usb/renesas_usbhs.h17
135 files changed, 9085 insertions, 3167 deletions
diff --git a/Documentation/ABI/testing/sysfs-module b/Documentation/ABI/testing/sysfs-module
index cfcec3bffc0a..9489ea8e294c 100644
--- a/Documentation/ABI/testing/sysfs-module
+++ b/Documentation/ABI/testing/sysfs-module
@@ -10,3 +10,26 @@ KernelVersion: 2.6.35
10Contact: masa-korg@dsn.okisemi.com 10Contact: masa-korg@dsn.okisemi.com
11Description: Write/read Option ROM data. 11Description: Write/read Option ROM data.
12 12
13
14What: /sys/module/ehci_hcd/drivers/.../uframe_periodic_max
15Date: July 2011
16KernelVersion: 3.1
17Contact: Kirill Smelkov <kirr@mns.spb.ru>
18Description: Maximum time allowed for periodic transfers per microframe (μs)
19
20 [ USB 2.0 sets maximum allowed time for periodic transfers per
21 microframe to be 80%, that is 100 microseconds out of 125
22 microseconds (full microframe).
23
24 However there are cases, when 80% max isochronous bandwidth is
25 too limiting. For example two video streams could require 110
26 microseconds of isochronous bandwidth per microframe to work
27 together. ]
28
29 Through this setting it is possible to raise the limit so that
30 the host controller would allow allocating more than 100
31 microseconds of periodic bandwidth per microframe.
32
33 Beware, non-standard modes are usually not thoroughly tested by
34 hardware designers, and the hardware can malfunction when this
35 setting differ from default 100.
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index aca4f8235969..9becc5eff794 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -569,3 +569,10 @@ Why: Just opening a V4L device should not change the state of the hardware
569Who: Hans Verkuil <hans.verkuil@cisco.com> 569Who: Hans Verkuil <hans.verkuil@cisco.com>
570 570
571---------------------------- 571----------------------------
572
573What: g_file_storage driver
574When: 3.8
575Why: This driver has been superseded by g_mass_storage.
576Who: Alan Stern <stern@rowland.harvard.edu>
577
578----------------------------
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 2d1e14ca35fd..a70e43edcb65 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2545,6 +2545,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
2545 unknown_nmi_panic 2545 unknown_nmi_panic
2546 [X86] Cause panic on unknown NMI. 2546 [X86] Cause panic on unknown NMI.
2547 2547
2548 usbcore.authorized_default=
2549 [USB] Default USB device authorization:
2550 (default -1 = authorized except for wireless USB,
2551 0 = not authorized, 1 = authorized)
2552
2548 usbcore.autosuspend= 2553 usbcore.autosuspend=
2549 [USB] The autosuspend time delay (in seconds) used 2554 [USB] The autosuspend time delay (in seconds) used
2550 for newly-detected USB devices (default 2). This 2555 for newly-detected USB devices (default 2). This
diff --git a/Documentation/usb/ehci.txt b/Documentation/usb/ehci.txt
index 9dcafa7d930d..160bd6c3ab7b 100644
--- a/Documentation/usb/ehci.txt
+++ b/Documentation/usb/ehci.txt
@@ -210,3 +210,5 @@ TBD: Interrupt and ISO transfer performance issues. Those periodic
210transfers are fully scheduled, so the main issue is likely to be how 210transfers are fully scheduled, so the main issue is likely to be how
211to trigger "high bandwidth" modes. 211to trigger "high bandwidth" modes.
212 212
213TBD: More than standard 80% periodic bandwidth allocation is possible
214through sysfs uframe_periodic_max parameter. Describe that.
diff --git a/Documentation/usb/gadget_hid.txt b/Documentation/usb/gadget_hid.txt
index f4a51f567427..12696c2e43fb 100644
--- a/Documentation/usb/gadget_hid.txt
+++ b/Documentation/usb/gadget_hid.txt
@@ -81,8 +81,8 @@ Send and receive HID reports
81 to do this. 81 to do this.
82 82
83 hid_gadget_test is a small interactive program to test the HID 83 hid_gadget_test is a small interactive program to test the HID
84 gadget driver. To use, point it at a hidg device and set the 84 gadget driver. To use, point it at a hidg device and set the
85 device type (keyboard / mouse / joystick) - E.G.: 85 device type (keyboard / mouse / joystick) - E.G.:
86 86
87 # hid_gadget_test /dev/hidg0 keyboard 87 # hid_gadget_test /dev/hidg0 keyboard
88 88
@@ -97,7 +97,7 @@ Send and receive HID reports
97 HID gadget. 97 HID gadget.
98 98
99 Another interesting example is the caps lock test. Type 99 Another interesting example is the caps lock test. Type
100 -–caps-lock and hit return. A report is then sent by the 100 --caps-lock and hit return. A report is then sent by the
101 gadget and you should receive the host answer, corresponding 101 gadget and you should receive the host answer, corresponding
102 to the caps lock LED status. 102 to the caps lock LED status.
103 103
diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
index c7ed540d868d..a65145b02a55 100644
--- a/arch/arm/mach-omap2/usb-musb.c
+++ b/arch/arm/mach-omap2/usb-musb.c
@@ -33,8 +33,6 @@
33#include <plat/omap_device.h> 33#include <plat/omap_device.h>
34#include "mux.h" 34#include "mux.h"
35 35
36#if defined(CONFIG_USB_MUSB_OMAP2PLUS) || defined (CONFIG_USB_MUSB_AM35X)
37
38static struct musb_hdrc_config musb_config = { 36static struct musb_hdrc_config musb_config = {
39 .multipoint = 1, 37 .multipoint = 1,
40 .dyn_fifo = 1, 38 .dyn_fifo = 1,
@@ -175,11 +173,3 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data)
175 if (cpu_is_omap44xx()) 173 if (cpu_is_omap44xx())
176 omap4430_phy_init(dev); 174 omap4430_phy_init(dev);
177} 175}
178
179#else
180void __init usb_musb_init(struct omap_musb_board_data *board_data)
181{
182 if (cpu_is_omap44xx())
183 omap4430_phy_init(NULL);
184}
185#endif /* CONFIG_USB_MUSB_SOC */
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index e71521ce3010..428f36801e06 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -116,14 +116,14 @@ struct uea_cmvs_v1 {
116 u32 address; 116 u32 address;
117 u16 offset; 117 u16 offset;
118 u32 data; 118 u32 data;
119} __attribute__ ((packed)); 119} __packed;
120 120
121struct uea_cmvs_v2 { 121struct uea_cmvs_v2 {
122 u32 group; 122 u32 group;
123 u32 address; 123 u32 address;
124 u32 offset; 124 u32 offset;
125 u32 data; 125 u32 data;
126} __attribute__ ((packed)); 126} __packed;
127 127
128/* information about currently processed cmv */ 128/* information about currently processed cmv */
129struct cmv_dsc_e1 { 129struct cmv_dsc_e1 {
@@ -352,7 +352,7 @@ struct block_index {
352 __le32 PageAddress; 352 __le32 PageAddress;
353 __le16 dummy1; 353 __le16 dummy1;
354 __le16 PageNumber; 354 __le16 PageNumber;
355} __attribute__ ((packed)); 355} __packed;
356 356
357#define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000) 357#define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
358#define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4) 358#define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
@@ -367,7 +367,7 @@ struct l1_code {
367 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER]; 367 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
368 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS]; 368 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
369 u8 code[0]; 369 u8 code[0];
370} __attribute__ ((packed)); 370} __packed;
371 371
372/* structures describing a block within a DSP page */ 372/* structures describing a block within a DSP page */
373struct block_info_e1 { 373struct block_info_e1 {
@@ -377,7 +377,7 @@ struct block_info_e1 {
377 __le16 wOvlOffset; 377 __le16 wOvlOffset;
378 __le16 wOvl; /* overlay */ 378 __le16 wOvl; /* overlay */
379 __le16 wLast; 379 __le16 wLast;
380} __attribute__ ((packed)); 380} __packed;
381#define E1_BLOCK_INFO_SIZE 12 381#define E1_BLOCK_INFO_SIZE 12
382 382
383struct block_info_e4 { 383struct block_info_e4 {
@@ -387,7 +387,7 @@ struct block_info_e4 {
387 __be32 dwSize; 387 __be32 dwSize;
388 __be32 dwAddress; 388 __be32 dwAddress;
389 __be16 wReserved; 389 __be16 wReserved;
390} __attribute__ ((packed)); 390} __packed;
391#define E4_BLOCK_INFO_SIZE 14 391#define E4_BLOCK_INFO_SIZE 14
392 392
393#define UEA_BIHDR 0xabcd 393#define UEA_BIHDR 0xabcd
@@ -467,7 +467,7 @@ struct cmv_e1 {
467 __le32 dwSymbolicAddress; 467 __le32 dwSymbolicAddress;
468 __le16 wOffsetAddress; 468 __le16 wOffsetAddress;
469 __le32 dwData; 469 __le32 dwData;
470} __attribute__ ((packed)); 470} __packed;
471 471
472struct cmv_e4 { 472struct cmv_e4 {
473 __be16 wGroup; 473 __be16 wGroup;
@@ -475,17 +475,17 @@ struct cmv_e4 {
475 __be16 wOffset; 475 __be16 wOffset;
476 __be16 wAddress; 476 __be16 wAddress;
477 __be32 dwData[6]; 477 __be32 dwData[6];
478} __attribute__ ((packed)); 478} __packed;
479 479
480/* structures representing swap information */ 480/* structures representing swap information */
481struct swap_info_e1 { 481struct swap_info_e1 {
482 __u8 bSwapPageNo; 482 __u8 bSwapPageNo;
483 __u8 bOvl; /* overlay */ 483 __u8 bOvl; /* overlay */
484} __attribute__ ((packed)); 484} __packed;
485 485
486struct swap_info_e4 { 486struct swap_info_e4 {
487 __u8 bSwapPageNo; 487 __u8 bSwapPageNo;
488} __attribute__ ((packed)); 488} __packed;
489 489
490/* structures representing interrupt data */ 490/* structures representing interrupt data */
491#define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo 491#define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
@@ -499,23 +499,23 @@ union intr_data_e1 {
499 struct { 499 struct {
500 struct swap_info_e1 swapinfo; 500 struct swap_info_e1 swapinfo;
501 __le16 wDataSize; 501 __le16 wDataSize;
502 } __attribute__ ((packed)) s1; 502 } __packed s1;
503 struct { 503 struct {
504 struct cmv_e1 cmv; 504 struct cmv_e1 cmv;
505 __le16 wDataSize; 505 __le16 wDataSize;
506 } __attribute__ ((packed)) s2; 506 } __packed s2;
507} __attribute__ ((packed)); 507} __packed;
508 508
509union intr_data_e4 { 509union intr_data_e4 {
510 struct { 510 struct {
511 struct swap_info_e4 swapinfo; 511 struct swap_info_e4 swapinfo;
512 __le16 wDataSize; 512 __le16 wDataSize;
513 } __attribute__ ((packed)) s1; 513 } __packed s1;
514 struct { 514 struct {
515 struct cmv_e4 cmv; 515 struct cmv_e4 cmv;
516 __le16 wDataSize; 516 __le16 wDataSize;
517 } __attribute__ ((packed)) s2; 517 } __packed s2;
518} __attribute__ ((packed)); 518} __packed;
519 519
520struct intr_pkt { 520struct intr_pkt {
521 __u8 bType; 521 __u8 bType;
@@ -528,15 +528,15 @@ struct intr_pkt {
528 union intr_data_e1 e1; 528 union intr_data_e1 e1;
529 union intr_data_e4 e4; 529 union intr_data_e4 e4;
530 } u; 530 } u;
531} __attribute__ ((packed)); 531} __packed;
532 532
533#define E1_INTR_PKT_SIZE 28 533#define E1_INTR_PKT_SIZE 28
534#define E4_INTR_PKT_SIZE 64 534#define E4_INTR_PKT_SIZE 64
535 535
536static struct usb_driver uea_driver; 536static struct usb_driver uea_driver;
537static DEFINE_MUTEX(uea_mutex); 537static DEFINE_MUTEX(uea_mutex);
538static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III", 538static const char * const chip_name[] = {
539 "Eagle IV"}; 539 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
540 540
541static int modem_index; 541static int modem_index;
542static unsigned int debug; 542static unsigned int debug;
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 989e16e4ab5c..d3448ca110ce 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -81,6 +81,7 @@
81#include <linux/timer.h> 81#include <linux/timer.h>
82#include <linux/wait.h> 82#include <linux/wait.h>
83#include <linux/kthread.h> 83#include <linux/kthread.h>
84#include <linux/ratelimit.h>
84 85
85#ifdef VERBOSE_DEBUG 86#ifdef VERBOSE_DEBUG
86static int usbatm_print_packet(const unsigned char *data, int len); 87static int usbatm_print_packet(const unsigned char *data, int len);
@@ -668,8 +669,7 @@ static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
668 /* racy disconnection check - fine */ 669 /* racy disconnection check - fine */
669 if (!instance || instance->disconnected) { 670 if (!instance || instance->disconnected) {
670#ifdef DEBUG 671#ifdef DEBUG
671 if (printk_ratelimit()) 672 printk_ratelimited(KERN_DEBUG "%s: %s!\n", __func__, instance ? "disconnected" : "NULL instance");
672 printk(KERN_DEBUG "%s: %s!\n", __func__, instance ? "disconnected" : "NULL instance");
673#endif 673#endif
674 err = -ENODEV; 674 err = -ENODEV;
675 goto fail; 675 goto fail;
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 9eca4053312e..cb3a93243a05 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -58,6 +58,7 @@
58#include <linux/mutex.h> 58#include <linux/mutex.h>
59#undef DEBUG 59#undef DEBUG
60#include <linux/usb.h> 60#include <linux/usb.h>
61#include <linux/ratelimit.h>
61 62
62/* 63/*
63 * Version Information 64 * Version Information
@@ -348,8 +349,7 @@ static int usblp_check_status(struct usblp *usblp, int err)
348 mutex_lock(&usblp->mut); 349 mutex_lock(&usblp->mut);
349 if ((error = usblp_read_status(usblp, usblp->statusbuf)) < 0) { 350 if ((error = usblp_read_status(usblp, usblp->statusbuf)) < 0) {
350 mutex_unlock(&usblp->mut); 351 mutex_unlock(&usblp->mut);
351 if (printk_ratelimit()) 352 printk_ratelimited(KERN_ERR
352 printk(KERN_ERR
353 "usblp%d: error %d reading printer status\n", 353 "usblp%d: error %d reading printer status\n",
354 usblp->minor, error); 354 usblp->minor, error);
355 return 0; 355 return 0;
@@ -653,8 +653,7 @@ static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
653 653
654 case LPGETSTATUS: 654 case LPGETSTATUS:
655 if ((retval = usblp_read_status(usblp, usblp->statusbuf))) { 655 if ((retval = usblp_read_status(usblp, usblp->statusbuf))) {
656 if (printk_ratelimit()) 656 printk_ratelimited(KERN_ERR "usblp%d:"
657 printk(KERN_ERR "usblp%d:"
658 "failed reading printer status (%d)\n", 657 "failed reading printer status (%d)\n",
659 usblp->minor, retval); 658 usblp->minor, retval);
660 retval = -EIO; 659 retval = -EIO;
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index ace9f8442e5d..8669ba3fe794 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -337,6 +337,17 @@ static const u8 ss_rh_config_descriptor[] = {
337 0x02, 0x00 /* __le16 ss_wBytesPerInterval; 15 bits for max 15 ports */ 337 0x02, 0x00 /* __le16 ss_wBytesPerInterval; 15 bits for max 15 ports */
338}; 338};
339 339
340/* authorized_default behaviour:
341 * -1 is authorized for all devices except wireless (old behaviour)
342 * 0 is unauthorized for all devices
343 * 1 is authorized for all devices
344 */
345static int authorized_default = -1;
346module_param(authorized_default, int, S_IRUGO|S_IWUSR);
347MODULE_PARM_DESC(authorized_default,
348 "Default USB device authorization: 0 is not authorized, 1 is "
349 "authorized, -1 is authorized except for wireless USB (default, "
350 "old behaviour");
340/*-------------------------------------------------------------------------*/ 351/*-------------------------------------------------------------------------*/
341 352
342/** 353/**
@@ -2371,7 +2382,11 @@ int usb_add_hcd(struct usb_hcd *hcd,
2371 2382
2372 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); 2383 dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
2373 2384
2374 hcd->authorized_default = hcd->wireless? 0 : 1; 2385 /* Keep old behaviour if authorized_default is not in [0, 1]. */
2386 if (authorized_default < 0 || authorized_default > 1)
2387 hcd->authorized_default = hcd->wireless? 0 : 1;
2388 else
2389 hcd->authorized_default = authorized_default;
2375 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 2390 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
2376 2391
2377 /* HC is in reset state, but accessible. Now do the one-time init, 2392 /* HC is in reset state, but accessible. Now do the one-time init,
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 029e288805b6..44b6b40aafb4 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -96,9 +96,6 @@ config USB_GADGET_VBUS_DRAW
96 This value will be used except for system-specific gadget 96 This value will be used except for system-specific gadget
97 drivers that have more specific information. 97 drivers that have more specific information.
98 98
99config USB_GADGET_SELECTED
100 boolean
101
102# 99#
103# USB Peripheral Controller Support 100# USB Peripheral Controller Support
104# 101#
@@ -122,10 +119,9 @@ choice
122# Integrated controllers 119# Integrated controllers
123# 120#
124 121
125config USB_GADGET_AT91 122config USB_AT91
126 boolean "Atmel AT91 USB Device Port" 123 tristate "Atmel AT91 USB Device Port"
127 depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 && !ARCH_AT91SAM9G45 124 depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 && !ARCH_AT91SAM9G45
128 select USB_GADGET_SELECTED
129 help 125 help
130 Many Atmel AT91 processors (such as the AT91RM2000) have a 126 Many Atmel AT91 processors (such as the AT91RM2000) have a
131 full speed USB Device Port with support for five configurable 127 full speed USB Device Port with support for five configurable
@@ -135,27 +131,16 @@ config USB_GADGET_AT91
135 dynamically linked module called "at91_udc" and force all 131 dynamically linked module called "at91_udc" and force all
136 gadget drivers to also be dynamically linked. 132 gadget drivers to also be dynamically linked.
137 133
138config USB_AT91 134config USB_ATMEL_USBA
139 tristate 135 tristate "Atmel USBA"
140 depends on USB_GADGET_AT91
141 default USB_GADGET
142
143config USB_GADGET_ATMEL_USBA
144 boolean "Atmel USBA"
145 select USB_GADGET_DUALSPEED 136 select USB_GADGET_DUALSPEED
146 depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 137 depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45
147 help 138 help
148 USBA is the integrated high-speed USB Device controller on 139 USBA is the integrated high-speed USB Device controller on
149 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. 140 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
150 141
151config USB_ATMEL_USBA 142config USB_FSL_USB2
152 tristate 143 tristate "Freescale Highspeed USB DR Peripheral Controller"
153 depends on USB_GADGET_ATMEL_USBA
154 default USB_GADGET
155 select USB_GADGET_SELECTED
156
157config USB_GADGET_FSL_USB2
158 boolean "Freescale Highspeed USB DR Peripheral Controller"
159 depends on FSL_SOC || ARCH_MXC 144 depends on FSL_SOC || ARCH_MXC
160 select USB_GADGET_DUALSPEED 145 select USB_GADGET_DUALSPEED
161 select USB_FSL_MPH_DR_OF if OF 146 select USB_FSL_MPH_DR_OF if OF
@@ -170,26 +155,15 @@ config USB_GADGET_FSL_USB2
170 dynamically linked module called "fsl_usb2_udc" and force 155 dynamically linked module called "fsl_usb2_udc" and force
171 all gadget drivers to also be dynamically linked. 156 all gadget drivers to also be dynamically linked.
172 157
173config USB_FSL_USB2 158config USB_FUSB300
174 tristate 159 tristate "Faraday FUSB300 USB Peripheral Controller"
175 depends on USB_GADGET_FSL_USB2 160 depends on !PHYS_ADDR_T_64BIT
176 default USB_GADGET
177 select USB_GADGET_SELECTED
178
179config USB_GADGET_FUSB300
180 boolean "Faraday FUSB300 USB Peripheral Controller"
181 select USB_GADGET_DUALSPEED 161 select USB_GADGET_DUALSPEED
182 help 162 help
183 Faraday usb device controller FUSB300 driver 163 Faraday usb device controller FUSB300 driver
184 164
185config USB_FUSB300 165config USB_OMAP
186 tristate 166 tristate "OMAP USB Device Controller"
187 depends on USB_GADGET_FUSB300
188 default USB_GADGET
189 select USB_GADGET_SELECTED
190
191config USB_GADGET_OMAP
192 boolean "OMAP USB Device Controller"
193 depends on ARCH_OMAP 167 depends on ARCH_OMAP
194 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG 168 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG
195 select USB_OTG_UTILS if ARCH_OMAP 169 select USB_OTG_UTILS if ARCH_OMAP
@@ -204,14 +178,8 @@ config USB_GADGET_OMAP
204 dynamically linked module called "omap_udc" and force all 178 dynamically linked module called "omap_udc" and force all
205 gadget drivers to also be dynamically linked. 179 gadget drivers to also be dynamically linked.
206 180
207config USB_OMAP 181config USB_PXA25X
208 tristate 182 tristate "PXA 25x or IXP 4xx"
209 depends on USB_GADGET_OMAP
210 default USB_GADGET
211 select USB_GADGET_SELECTED
212
213config USB_GADGET_PXA25X
214 boolean "PXA 25x or IXP 4xx"
215 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX 183 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
216 select USB_OTG_UTILS 184 select USB_OTG_UTILS
217 help 185 help
@@ -226,24 +194,18 @@ config USB_GADGET_PXA25X
226 dynamically linked module called "pxa25x_udc" and force all 194 dynamically linked module called "pxa25x_udc" and force all
227 gadget drivers to also be dynamically linked. 195 gadget drivers to also be dynamically linked.
228 196
229config USB_PXA25X
230 tristate
231 depends on USB_GADGET_PXA25X
232 default USB_GADGET
233 select USB_GADGET_SELECTED
234
235# if there's only one gadget driver, using only two bulk endpoints, 197# if there's only one gadget driver, using only two bulk endpoints,
236# don't waste memory for the other endpoints 198# don't waste memory for the other endpoints
237config USB_PXA25X_SMALL 199config USB_PXA25X_SMALL
238 depends on USB_GADGET_PXA25X 200 depends on USB_PXA25X
239 bool 201 bool
240 default n if USB_ETH_RNDIS 202 default n if USB_ETH_RNDIS
241 default y if USB_ZERO 203 default y if USB_ZERO
242 default y if USB_ETH 204 default y if USB_ETH
243 default y if USB_G_SERIAL 205 default y if USB_G_SERIAL
244 206
245config USB_GADGET_R8A66597 207config USB_R8A66597
246 boolean "Renesas R8A66597 USB Peripheral Controller" 208 tristate "Renesas R8A66597 USB Peripheral Controller"
247 select USB_GADGET_DUALSPEED 209 select USB_GADGET_DUALSPEED
248 help 210 help
249 R8A66597 is a discrete USB host and peripheral controller chip that 211 R8A66597 is a discrete USB host and peripheral controller chip that
@@ -254,32 +216,22 @@ config USB_GADGET_R8A66597
254 dynamically linked module called "r8a66597_udc" and force all 216 dynamically linked module called "r8a66597_udc" and force all
255 gadget drivers to also be dynamically linked. 217 gadget drivers to also be dynamically linked.
256 218
257config USB_R8A66597 219config USB_RENESAS_USBHS_UDC
258 tristate 220 tristate 'Renesas USBHS controller'
259 depends on USB_GADGET_R8A66597 221 depends on SUPERH || ARCH_SHMOBILE
260 default USB_GADGET
261 select USB_GADGET_SELECTED
262
263config USB_GADGET_RENESAS_USBHS
264 boolean "Renesas USBHS"
265 depends on USB_RENESAS_USBHS 222 depends on USB_RENESAS_USBHS
266 select USB_GADGET_DUALSPEED 223 select USB_GADGET_DUALSPEED
267 help 224 help
268 Renesas USBHS is a discrete USB host and peripheral controller 225 Renesas USBHS is a discrete USB host and peripheral controller chip
269 chip that supports both full and high speed USB 2.0 data transfers. 226 that supports both full and high speed USB 2.0 data transfers.
270 platform is able to configure endpoint (pipe) style 227 It has nine or more configurable endpoints, and endpoint zero.
271 228
272 Say "y" to enable the gadget specific portion of the USBHS driver. 229 Say "y" to link the driver statically, or "m" to build a
273 230 dynamically linked module called "renesas_usbhs" and force all
274 231 gadget drivers to also be dynamically linked.
275config USB_RENESAS_USBHS_UDC
276 tristate
277 depends on USB_GADGET_RENESAS_USBHS
278 default USB_GADGET
279 select USB_GADGET_SELECTED
280 232
281config USB_GADGET_PXA27X 233config USB_PXA27X
282 boolean "PXA 27x" 234 tristate "PXA 27x"
283 depends on ARCH_PXA && (PXA27x || PXA3xx) 235 depends on ARCH_PXA && (PXA27x || PXA3xx)
284 select USB_OTG_UTILS 236 select USB_OTG_UTILS
285 help 237 help
@@ -293,14 +245,8 @@ config USB_GADGET_PXA27X
293 dynamically linked module called "pxa27x_udc" and force all 245 dynamically linked module called "pxa27x_udc" and force all
294 gadget drivers to also be dynamically linked. 246 gadget drivers to also be dynamically linked.
295 247
296config USB_PXA27X 248config USB_S3C_HSOTG
297 tristate 249 tristate "S3C HS/OtG USB Device controller"
298 depends on USB_GADGET_PXA27X
299 default USB_GADGET
300 select USB_GADGET_SELECTED
301
302config USB_GADGET_S3C_HSOTG
303 boolean "S3C HS/OtG USB Device controller"
304 depends on S3C_DEV_USB_HSOTG 250 depends on S3C_DEV_USB_HSOTG
305 select USB_GADGET_S3C_HSOTG_PIO 251 select USB_GADGET_S3C_HSOTG_PIO
306 select USB_GADGET_DUALSPEED 252 select USB_GADGET_DUALSPEED
@@ -308,14 +254,8 @@ config USB_GADGET_S3C_HSOTG
308 The Samsung S3C64XX USB2.0 high-speed gadget controller 254 The Samsung S3C64XX USB2.0 high-speed gadget controller
309 integrated into the S3C64XX series SoC. 255 integrated into the S3C64XX series SoC.
310 256
311config USB_S3C_HSOTG 257config USB_IMX
312 tristate 258 tristate "Freescale IMX USB Peripheral Controller"
313 depends on USB_GADGET_S3C_HSOTG
314 default USB_GADGET
315 select USB_GADGET_SELECTED
316
317config USB_GADGET_IMX
318 boolean "Freescale IMX USB Peripheral Controller"
319 depends on ARCH_MX1 259 depends on ARCH_MX1
320 help 260 help
321 Freescale's IMX series include an integrated full speed 261 Freescale's IMX series include an integrated full speed
@@ -329,14 +269,8 @@ config USB_GADGET_IMX
329 dynamically linked module called "imx_udc" and force all 269 dynamically linked module called "imx_udc" and force all
330 gadget drivers to also be dynamically linked. 270 gadget drivers to also be dynamically linked.
331 271
332config USB_IMX 272config USB_S3C2410
333 tristate 273 tristate "S3C2410 USB Device Controller"
334 depends on USB_GADGET_IMX
335 default USB_GADGET
336 select USB_GADGET_SELECTED
337
338config USB_GADGET_S3C2410
339 boolean "S3C2410 USB Device Controller"
340 depends on ARCH_S3C2410 274 depends on ARCH_S3C2410
341 help 275 help
342 Samsung's S3C2410 is an ARM-4 processor with an integrated 276 Samsung's S3C2410 is an ARM-4 processor with an integrated
@@ -346,18 +280,12 @@ config USB_GADGET_S3C2410
346 This driver has been tested on the S3C2410, S3C2412, and 280 This driver has been tested on the S3C2410, S3C2412, and
347 S3C2440 processors. 281 S3C2440 processors.
348 282
349config USB_S3C2410
350 tristate
351 depends on USB_GADGET_S3C2410
352 default USB_GADGET
353 select USB_GADGET_SELECTED
354
355config USB_S3C2410_DEBUG 283config USB_S3C2410_DEBUG
356 boolean "S3C2410 udc debug messages" 284 boolean "S3C2410 udc debug messages"
357 depends on USB_GADGET_S3C2410 285 depends on USB_S3C2410
358 286
359config USB_GADGET_S3C_HSUDC 287config USB_S3C_HSUDC
360 boolean "S3C2416, S3C2443 and S3C2450 USB Device Controller" 288 tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller"
361 depends on ARCH_S3C2410 289 depends on ARCH_S3C2410
362 select USB_GADGET_DUALSPEED 290 select USB_GADGET_DUALSPEED
363 help 291 help
@@ -367,41 +295,29 @@ config USB_GADGET_S3C_HSUDC
367 295
368 This driver has been tested on S3C2416 and S3C2450 processors. 296 This driver has been tested on S3C2416 and S3C2450 processors.
369 297
370config USB_S3C_HSUDC 298config USB_PXA_U2O
371 tristate 299 tristate "PXA9xx Processor USB2.0 controller"
372 depends on USB_GADGET_S3C_HSUDC 300 depends on ARCH_MMP
373 default USB_GADGET
374 select USB_GADGET_SELECTED
375
376config USB_GADGET_PXA_U2O
377 boolean "PXA9xx Processor USB2.0 controller"
378 select USB_GADGET_DUALSPEED 301 select USB_GADGET_DUALSPEED
379 help 302 help
380 PXA9xx Processor series include a high speed USB2.0 device 303 PXA9xx Processor series include a high speed USB2.0 device
381 controller, which support high speed and full speed USB peripheral. 304 controller, which support high speed and full speed USB peripheral.
382 305
383config USB_PXA_U2O
384 tristate
385 depends on USB_GADGET_PXA_U2O
386 default USB_GADGET
387 select USB_GADGET_SELECTED
388
389# 306#
390# Controllers available in both integrated and discrete versions 307# Controllers available in both integrated and discrete versions
391# 308#
392 309
393# musb builds in ../musb along with host support 310# musb builds in ../musb along with host support
394config USB_GADGET_MUSB_HDRC 311config USB_GADGET_MUSB_HDRC
395 boolean "Inventra HDRC USB Peripheral (TI, ADI, ...)" 312 tristate "Inventra HDRC USB Peripheral (TI, ADI, ...)"
396 depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG) 313 depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG)
397 select USB_GADGET_DUALSPEED 314 select USB_GADGET_DUALSPEED
398 select USB_GADGET_SELECTED
399 help 315 help
400 This OTG-capable silicon IP is used in dual designs including 316 This OTG-capable silicon IP is used in dual designs including
401 the TI DaVinci, OMAP 243x, OMAP 343x, TUSB 6010, and ADI Blackfin 317 the TI DaVinci, OMAP 243x, OMAP 343x, TUSB 6010, and ADI Blackfin
402 318
403config USB_GADGET_M66592 319config USB_M66592
404 boolean "Renesas M66592 USB Peripheral Controller" 320 tristate "Renesas M66592 USB Peripheral Controller"
405 select USB_GADGET_DUALSPEED 321 select USB_GADGET_DUALSPEED
406 help 322 help
407 M66592 is a discrete USB peripheral controller chip that 323 M66592 is a discrete USB peripheral controller chip that
@@ -412,18 +328,12 @@ config USB_GADGET_M66592
412 dynamically linked module called "m66592_udc" and force all 328 dynamically linked module called "m66592_udc" and force all
413 gadget drivers to also be dynamically linked. 329 gadget drivers to also be dynamically linked.
414 330
415config USB_M66592
416 tristate
417 depends on USB_GADGET_M66592
418 default USB_GADGET
419 select USB_GADGET_SELECTED
420
421# 331#
422# Controllers available only in discrete form (and all PCI controllers) 332# Controllers available only in discrete form (and all PCI controllers)
423# 333#
424 334
425config USB_GADGET_AMD5536UDC 335config USB_AMD5536UDC
426 boolean "AMD5536 UDC" 336 tristate "AMD5536 UDC"
427 depends on PCI 337 depends on PCI
428 select USB_GADGET_DUALSPEED 338 select USB_GADGET_DUALSPEED
429 help 339 help
@@ -437,14 +347,8 @@ config USB_GADGET_AMD5536UDC
437 dynamically linked module called "amd5536udc" and force all 347 dynamically linked module called "amd5536udc" and force all
438 gadget drivers to also be dynamically linked. 348 gadget drivers to also be dynamically linked.
439 349
440config USB_AMD5536UDC 350config USB_FSL_QE
441 tristate 351 tristate "Freescale QE/CPM USB Device Controller"
442 depends on USB_GADGET_AMD5536UDC
443 default USB_GADGET
444 select USB_GADGET_SELECTED
445
446config USB_GADGET_FSL_QE
447 boolean "Freescale QE/CPM USB Device Controller"
448 depends on FSL_SOC && (QUICC_ENGINE || CPM) 352 depends on FSL_SOC && (QUICC_ENGINE || CPM)
449 help 353 help
450 Some of Freescale PowerPC processors have a Full Speed 354 Some of Freescale PowerPC processors have a Full Speed
@@ -456,14 +360,8 @@ config USB_GADGET_FSL_QE
456 Set CONFIG_USB_GADGET to "m" to build this driver as a 360 Set CONFIG_USB_GADGET to "m" to build this driver as a
457 dynamically linked module called "fsl_qe_udc". 361 dynamically linked module called "fsl_qe_udc".
458 362
459config USB_FSL_QE 363config USB_CI13XXX_PCI
460 tristate 364 tristate "MIPS USB CI13xxx PCI UDC"
461 depends on USB_GADGET_FSL_QE
462 default USB_GADGET
463 select USB_GADGET_SELECTED
464
465config USB_GADGET_CI13XXX_PCI
466 boolean "MIPS USB CI13xxx PCI UDC"
467 depends on PCI 365 depends on PCI
468 select USB_GADGET_DUALSPEED 366 select USB_GADGET_DUALSPEED
469 help 367 help
@@ -474,14 +372,31 @@ config USB_GADGET_CI13XXX_PCI
474 dynamically linked module called "ci13xxx_udc" and force all 372 dynamically linked module called "ci13xxx_udc" and force all
475 gadget drivers to also be dynamically linked. 373 gadget drivers to also be dynamically linked.
476 374
477config USB_CI13XXX_PCI 375config USB_NET2272
478 tristate 376 tristate "PLX NET2272"
479 depends on USB_GADGET_CI13XXX_PCI 377 select USB_GADGET_DUALSPEED
480 default USB_GADGET 378 help
481 select USB_GADGET_SELECTED 379 PLX NET2272 is a USB peripheral controller which supports
380 both full and high speed USB 2.0 data transfers.
381
382 It has three configurable endpoints, as well as endpoint zero
383 (for control transfer).
384 Say "y" to link the driver statically, or "m" to build a
385 dynamically linked module called "net2272" and force all
386 gadget drivers to also be dynamically linked.
387
388config USB_NET2272_DMA
389 boolean "Support external DMA controller"
390 depends on USB_NET2272
391 help
392 The NET2272 part can optionally support an external DMA
393 controller, but your board has to have support in the
394 driver itself.
482 395
483config USB_GADGET_NET2280 396 If unsure, say "N" here. The driver works fine in PIO mode.
484 boolean "NetChip 228x" 397
398config USB_NET2280
399 tristate "NetChip 228x"
485 depends on PCI 400 depends on PCI
486 select USB_GADGET_DUALSPEED 401 select USB_GADGET_DUALSPEED
487 help 402 help
@@ -496,14 +411,8 @@ config USB_GADGET_NET2280
496 dynamically linked module called "net2280" and force all 411 dynamically linked module called "net2280" and force all
497 gadget drivers to also be dynamically linked. 412 gadget drivers to also be dynamically linked.
498 413
499config USB_NET2280 414config USB_GOKU
500 tristate 415 tristate "Toshiba TC86C001 'Goku-S'"
501 depends on USB_GADGET_NET2280
502 default USB_GADGET
503 select USB_GADGET_SELECTED
504
505config USB_GADGET_GOKU
506 boolean "Toshiba TC86C001 'Goku-S'"
507 depends on PCI 416 depends on PCI
508 help 417 help
509 The Toshiba TC86C001 is a PCI device which includes controllers 418 The Toshiba TC86C001 is a PCI device which includes controllers
@@ -516,15 +425,10 @@ config USB_GADGET_GOKU
516 dynamically linked module called "goku_udc" and to force all 425 dynamically linked module called "goku_udc" and to force all
517 gadget drivers to also be dynamically linked. 426 gadget drivers to also be dynamically linked.
518 427
519config USB_GOKU 428config USB_LANGWELL
520 tristate 429 tristate "Intel Langwell USB Device Controller"
521 depends on USB_GADGET_GOKU
522 default USB_GADGET
523 select USB_GADGET_SELECTED
524
525config USB_GADGET_LANGWELL
526 boolean "Intel Langwell USB Device Controller"
527 depends on PCI 430 depends on PCI
431 depends on !PHYS_ADDR_T_64BIT
528 select USB_GADGET_DUALSPEED 432 select USB_GADGET_DUALSPEED
529 help 433 help
530 Intel Langwell USB Device Controller is a High-Speed USB 434 Intel Langwell USB Device Controller is a High-Speed USB
@@ -537,14 +441,8 @@ config USB_GADGET_LANGWELL
537 dynamically linked module called "langwell_udc" and force all 441 dynamically linked module called "langwell_udc" and force all
538 gadget drivers to also be dynamically linked. 442 gadget drivers to also be dynamically linked.
539 443
540config USB_LANGWELL 444config USB_EG20T
541 tristate 445 tristate "Intel EG20T PCH/OKI SEMICONDUCTOR ML7213 IOH UDC"
542 depends on USB_GADGET_LANGWELL
543 default USB_GADGET
544 select USB_GADGET_SELECTED
545
546config USB_GADGET_EG20T
547 boolean "Intel EG20T PCH/OKI SEMICONDUCTOR ML7213 IOH UDC"
548 depends on PCI 446 depends on PCI
549 select USB_GADGET_DUALSPEED 447 select USB_GADGET_DUALSPEED
550 help 448 help
@@ -565,14 +463,8 @@ config USB_GADGET_EG20T
565 ML7213 is companion chip for Intel Atom E6xx series. 463 ML7213 is companion chip for Intel Atom E6xx series.
566 ML7213 is completely compatible for Intel EG20T PCH. 464 ML7213 is completely compatible for Intel EG20T PCH.
567 465
568config USB_EG20T 466config USB_CI13XXX_MSM
569 tristate 467 tristate "MIPS USB CI13xxx for MSM"
570 depends on USB_GADGET_EG20T
571 default USB_GADGET
572 select USB_GADGET_SELECTED
573
574config USB_GADGET_CI13XXX_MSM
575 boolean "MIPS USB CI13xxx for MSM"
576 depends on ARCH_MSM 468 depends on ARCH_MSM
577 select USB_GADGET_DUALSPEED 469 select USB_GADGET_DUALSPEED
578 select USB_MSM_OTG 470 select USB_MSM_OTG
@@ -588,31 +480,26 @@ config USB_GADGET_CI13XXX_MSM
588 dynamically linked module called "ci13xxx_msm" and force all 480 dynamically linked module called "ci13xxx_msm" and force all
589 gadget drivers to also be dynamically linked. 481 gadget drivers to also be dynamically linked.
590 482
591config USB_CI13XXX_MSM
592 tristate
593 depends on USB_GADGET_CI13XXX_MSM
594 default USB_GADGET
595 select USB_GADGET_SELECTED
596
597# 483#
598# LAST -- dummy/emulated controller 484# LAST -- dummy/emulated controller
599# 485#
600 486
601config USB_GADGET_DUMMY_HCD 487config USB_DUMMY_HCD
602 boolean "Dummy HCD (DEVELOPMENT)" 488 tristate "Dummy HCD (DEVELOPMENT)"
603 depends on USB=y || (USB=m && USB_GADGET=m) 489 depends on USB=y || (USB=m && USB_GADGET=m)
604 select USB_GADGET_DUALSPEED 490 select USB_GADGET_DUALSPEED
491 select USB_GADGET_SUPERSPEED
605 help 492 help
606 This host controller driver emulates USB, looping all data transfer 493 This host controller driver emulates USB, looping all data transfer
607 requests back to a USB "gadget driver" in the same host. The host 494 requests back to a USB "gadget driver" in the same host. The host
608 side is the master; the gadget side is the slave. Gadget drivers 495 side is the master; the gadget side is the slave. Gadget drivers
609 can be high, full, or low speed; and they have access to endpoints 496 can be high, full, or low speed; and they have access to endpoints
610 like those from NET2280, PXA2xx, or SA1100 hardware. 497 like those from NET2280, PXA2xx, or SA1100 hardware.
611 498
612 This may help in some stages of creating a driver to embed in a 499 This may help in some stages of creating a driver to embed in a
613 Linux device, since it lets you debug several parts of the gadget 500 Linux device, since it lets you debug several parts of the gadget
614 driver without its hardware or drivers being involved. 501 driver without its hardware or drivers being involved.
615 502
616 Since such a gadget side driver needs to interoperate with a host 503 Since such a gadget side driver needs to interoperate with a host
617 side Linux-USB device driver, this may help to debug both sides 504 side Linux-USB device driver, this may help to debug both sides
618 of a USB protocol stack. 505 of a USB protocol stack.
@@ -621,12 +508,6 @@ config USB_GADGET_DUMMY_HCD
621 dynamically linked module called "dummy_hcd" and force all 508 dynamically linked module called "dummy_hcd" and force all
622 gadget drivers to also be dynamically linked. 509 gadget drivers to also be dynamically linked.
623 510
624config USB_DUMMY_HCD
625 tristate
626 depends on USB_GADGET_DUMMY_HCD
627 default USB_GADGET
628 select USB_GADGET_SELECTED
629
630# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears 511# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears
631# first and will be selected by default. 512# first and will be selected by default.
632 513
@@ -637,12 +518,18 @@ config USB_GADGET_DUALSPEED
637 bool 518 bool
638 depends on USB_GADGET 519 depends on USB_GADGET
639 520
521# Selected by UDC drivers that support super-speed opperation
522config USB_GADGET_SUPERSPEED
523 bool
524 depends on USB_GADGET
525 depends on USB_GADGET_DUALSPEED
526
640# 527#
641# USB Gadget Drivers 528# USB Gadget Drivers
642# 529#
643choice 530choice
644 tristate "USB Gadget Drivers" 531 tristate "USB Gadget Drivers"
645 depends on USB_GADGET && USB_GADGET_SELECTED 532 depends on USB_GADGET
646 default USB_ETH 533 default USB_ETH
647 help 534 help
648 A Linux "Gadget Driver" talks to the USB Peripheral Controller 535 A Linux "Gadget Driver" talks to the USB Peripheral Controller
@@ -848,7 +735,7 @@ config USB_FUNCTIONFS_GENERIC
848 no Ethernet interface. 735 no Ethernet interface.
849 736
850config USB_FILE_STORAGE 737config USB_FILE_STORAGE
851 tristate "File-backed Storage Gadget" 738 tristate "File-backed Storage Gadget (DEPRECATED)"
852 depends on BLOCK 739 depends on BLOCK
853 help 740 help
854 The File-backed Storage Gadget acts as a USB Mass Storage 741 The File-backed Storage Gadget acts as a USB Mass Storage
@@ -859,6 +746,9 @@ config USB_FILE_STORAGE
859 Say "y" to link the driver statically, or "m" to build a 746 Say "y" to link the driver statically, or "m" to build a
860 dynamically linked module called "g_file_storage". 747 dynamically linked module called "g_file_storage".
861 748
749 NOTE: This driver is deprecated. Its replacement is the
750 Mass Storage Gadget.
751
862config USB_FILE_STORAGE_TEST 752config USB_FILE_STORAGE_TEST
863 bool "File-backed Storage Gadget testing version" 753 bool "File-backed Storage Gadget testing version"
864 depends on USB_FILE_STORAGE 754 depends on USB_FILE_STORAGE
@@ -878,14 +768,11 @@ config USB_MASS_STORAGE
878 device (in much the same way as the "loop" device driver), 768 device (in much the same way as the "loop" device driver),
879 specified as a module parameter or sysfs option. 769 specified as a module parameter or sysfs option.
880 770
881 This is heavily based on File-backed Storage Gadget and in most 771 This driver is an updated replacement for the deprecated
882 cases you will want to use FSG instead. This gadget is mostly 772 File-backed Storage Gadget (g_file_storage).
883 here to test the functionality of the Mass Storage Function
884 which may be used with composite framework.
885 773
886 Say "y" to link the driver statically, or "m" to build 774 Say "y" to link the driver statically, or "m" to build
887 a dynamically linked module called "g_mass_storage". If unsure, 775 a dynamically linked module called "g_mass_storage".
888 consider File-backed Storage Gadget.
889 776
890config USB_G_SERIAL 777config USB_G_SERIAL
891 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" 778 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)"
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 4fe92b18a055..9ba725af4a08 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -3,7 +3,9 @@
3# 3#
4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5 5
6obj-$(CONFIG_USB_GADGET) += udc-core.o
6obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 7obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
8obj-$(CONFIG_USB_NET2272) += net2272.o
7obj-$(CONFIG_USB_NET2280) += net2280.o 9obj-$(CONFIG_USB_NET2280) += net2280.o
8obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o 10obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o
9obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o 11obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 95e8138cd48f..70f2b376c86d 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1438,10 +1438,15 @@ static int udc_wakeup(struct usb_gadget *gadget)
1438 return 0; 1438 return 0;
1439} 1439}
1440 1440
1441static int amd5536_start(struct usb_gadget_driver *driver,
1442 int (*bind)(struct usb_gadget *));
1443static int amd5536_stop(struct usb_gadget_driver *driver);
1441/* gadget operations */ 1444/* gadget operations */
1442static const struct usb_gadget_ops udc_ops = { 1445static const struct usb_gadget_ops udc_ops = {
1443 .wakeup = udc_wakeup, 1446 .wakeup = udc_wakeup,
1444 .get_frame = udc_get_frame, 1447 .get_frame = udc_get_frame,
1448 .start = amd5536_start,
1449 .stop = amd5536_stop,
1445}; 1450};
1446 1451
1447/* Setups endpoint parameters, adds endpoints to linked list */ 1452/* Setups endpoint parameters, adds endpoints to linked list */
@@ -1955,7 +1960,7 @@ static int setup_ep0(struct udc *dev)
1955} 1960}
1956 1961
1957/* Called by gadget driver to register itself */ 1962/* Called by gadget driver to register itself */
1958int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1963static int amd5536_start(struct usb_gadget_driver *driver,
1959 int (*bind)(struct usb_gadget *)) 1964 int (*bind)(struct usb_gadget *))
1960{ 1965{
1961 struct udc *dev = udc; 1966 struct udc *dev = udc;
@@ -2002,7 +2007,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2002 2007
2003 return 0; 2008 return 0;
2004} 2009}
2005EXPORT_SYMBOL(usb_gadget_probe_driver);
2006 2010
2007/* shutdown requests and disconnect from gadget */ 2011/* shutdown requests and disconnect from gadget */
2008static void 2012static void
@@ -2027,7 +2031,7 @@ __acquires(dev->lock)
2027} 2031}
2028 2032
2029/* Called by gadget driver to unregister itself */ 2033/* Called by gadget driver to unregister itself */
2030int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2034static int amd5536_stop(struct usb_gadget_driver *driver)
2031{ 2035{
2032 struct udc *dev = udc; 2036 struct udc *dev = udc;
2033 unsigned long flags; 2037 unsigned long flags;
@@ -2057,8 +2061,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2057 2061
2058 return 0; 2062 return 0;
2059} 2063}
2060EXPORT_SYMBOL(usb_gadget_unregister_driver);
2061
2062 2064
2063/* Clear pending NAK bits */ 2065/* Clear pending NAK bits */
2064static void udc_process_cnak_queue(struct udc *dev) 2066static void udc_process_cnak_queue(struct udc *dev)
@@ -3134,6 +3136,7 @@ static void udc_pci_remove(struct pci_dev *pdev)
3134 3136
3135 dev = pci_get_drvdata(pdev); 3137 dev = pci_get_drvdata(pdev);
3136 3138
3139 usb_del_gadget_udc(&udc->gadget);
3137 /* gadget driver must not be registered */ 3140 /* gadget driver must not be registered */
3138 BUG_ON(dev->driver != NULL); 3141 BUG_ON(dev->driver != NULL);
3139 3142
@@ -3382,8 +3385,13 @@ static int udc_probe(struct udc *dev)
3382 "driver version: %s(for Geode5536 B1)\n", tmp); 3385 "driver version: %s(for Geode5536 B1)\n", tmp);
3383 udc = dev; 3386 udc = dev;
3384 3387
3388 retval = usb_add_gadget_udc(&udc->pdev->dev, &dev->gadget);
3389 if (retval)
3390 goto finished;
3391
3385 retval = device_register(&dev->gadget.dev); 3392 retval = device_register(&dev->gadget.dev);
3386 if (retval) { 3393 if (retval) {
3394 usb_del_gadget_udc(&dev->gadget);
3387 put_device(&dev->gadget.dev); 3395 put_device(&dev->gadget.dev);
3388 goto finished; 3396 goto finished;
3389 } 3397 }
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index f4690ffcb489..98cbc06c30fd 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -985,12 +985,18 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on)
985 return 0; 985 return 0;
986} 986}
987 987
988static int at91_start(struct usb_gadget_driver *driver,
989 int (*bind)(struct usb_gadget *));
990static int at91_stop(struct usb_gadget_driver *driver);
991
988static const struct usb_gadget_ops at91_udc_ops = { 992static const struct usb_gadget_ops at91_udc_ops = {
989 .get_frame = at91_get_frame, 993 .get_frame = at91_get_frame,
990 .wakeup = at91_wakeup, 994 .wakeup = at91_wakeup,
991 .set_selfpowered = at91_set_selfpowered, 995 .set_selfpowered = at91_set_selfpowered,
992 .vbus_session = at91_vbus_session, 996 .vbus_session = at91_vbus_session,
993 .pullup = at91_pullup, 997 .pullup = at91_pullup,
998 .start = at91_start,
999 .stop = at91_stop,
994 1000
995 /* 1001 /*
996 * VBUS-powered devices may also also want to support bigger 1002 * VBUS-powered devices may also also want to support bigger
@@ -1628,7 +1634,7 @@ static void at91_vbus_timer(unsigned long data)
1628 schedule_work(&udc->vbus_timer_work); 1634 schedule_work(&udc->vbus_timer_work);
1629} 1635}
1630 1636
1631int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1637static int at91_start(struct usb_gadget_driver *driver,
1632 int (*bind)(struct usb_gadget *)) 1638 int (*bind)(struct usb_gadget *))
1633{ 1639{
1634 struct at91_udc *udc = &controller; 1640 struct at91_udc *udc = &controller;
@@ -1672,9 +1678,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1672 DBG("bound to %s\n", driver->driver.name); 1678 DBG("bound to %s\n", driver->driver.name);
1673 return 0; 1679 return 0;
1674} 1680}
1675EXPORT_SYMBOL(usb_gadget_probe_driver);
1676 1681
1677int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 1682static int at91_stop(struct usb_gadget_driver *driver)
1678{ 1683{
1679 struct at91_udc *udc = &controller; 1684 struct at91_udc *udc = &controller;
1680 unsigned long flags; 1685 unsigned long flags;
@@ -1696,7 +1701,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1696 DBG("unbound from %s\n", driver->driver.name); 1701 DBG("unbound from %s\n", driver->driver.name);
1697 return 0; 1702 return 0;
1698} 1703}
1699EXPORT_SYMBOL (usb_gadget_unregister_driver);
1700 1704
1701/*-------------------------------------------------------------------------*/ 1705/*-------------------------------------------------------------------------*/
1702 1706
@@ -1854,13 +1858,18 @@ static int __init at91udc_probe(struct platform_device *pdev)
1854 DBG("no VBUS detection, assuming always-on\n"); 1858 DBG("no VBUS detection, assuming always-on\n");
1855 udc->vbus = 1; 1859 udc->vbus = 1;
1856 } 1860 }
1861 retval = usb_add_gadget_udc(dev, &udc->gadget);
1862 if (retval)
1863 goto fail4;
1857 dev_set_drvdata(dev, udc); 1864 dev_set_drvdata(dev, udc);
1858 device_init_wakeup(dev, 1); 1865 device_init_wakeup(dev, 1);
1859 create_debug_file(udc); 1866 create_debug_file(udc);
1860 1867
1861 INFO("%s version %s\n", driver_name, DRIVER_VERSION); 1868 INFO("%s version %s\n", driver_name, DRIVER_VERSION);
1862 return 0; 1869 return 0;
1863 1870fail4:
1871 if (udc->board.vbus_pin > 0 && !udc->board.vbus_polled)
1872 free_irq(udc->board.vbus_pin, udc);
1864fail3: 1873fail3:
1865 if (udc->board.vbus_pin > 0) 1874 if (udc->board.vbus_pin > 0)
1866 gpio_free(udc->board.vbus_pin); 1875 gpio_free(udc->board.vbus_pin);
@@ -1887,6 +1896,7 @@ static int __exit at91udc_remove(struct platform_device *pdev)
1887 1896
1888 DBG("remove\n"); 1897 DBG("remove\n");
1889 1898
1899 usb_del_gadget_udc(&udc->gadget);
1890 if (udc->driver) 1900 if (udc->driver)
1891 return -EBUSY; 1901 return -EBUSY;
1892 1902
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index f045c8968a6e..5b1665eb1bef 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1007,10 +1007,16 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
1007 return 0; 1007 return 0;
1008} 1008}
1009 1009
1010static int atmel_usba_start(struct usb_gadget_driver *driver,
1011 int (*bind)(struct usb_gadget *));
1012static int atmel_usba_stop(struct usb_gadget_driver *driver);
1013
1010static const struct usb_gadget_ops usba_udc_ops = { 1014static const struct usb_gadget_ops usba_udc_ops = {
1011 .get_frame = usba_udc_get_frame, 1015 .get_frame = usba_udc_get_frame,
1012 .wakeup = usba_udc_wakeup, 1016 .wakeup = usba_udc_wakeup,
1013 .set_selfpowered = usba_udc_set_selfpowered, 1017 .set_selfpowered = usba_udc_set_selfpowered,
1018 .start = atmel_usba_start,
1019 .stop = atmel_usba_stop,
1014}; 1020};
1015 1021
1016static struct usb_endpoint_descriptor usba_ep0_desc = { 1022static struct usb_endpoint_descriptor usba_ep0_desc = {
@@ -1789,7 +1795,7 @@ out:
1789 return IRQ_HANDLED; 1795 return IRQ_HANDLED;
1790} 1796}
1791 1797
1792int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1798static int atmel_usba_start(struct usb_gadget_driver *driver,
1793 int (*bind)(struct usb_gadget *)) 1799 int (*bind)(struct usb_gadget *))
1794{ 1800{
1795 struct usba_udc *udc = &the_udc; 1801 struct usba_udc *udc = &the_udc;
@@ -1842,9 +1848,8 @@ err_driver_bind:
1842 udc->gadget.dev.driver = NULL; 1848 udc->gadget.dev.driver = NULL;
1843 return ret; 1849 return ret;
1844} 1850}
1845EXPORT_SYMBOL(usb_gadget_probe_driver);
1846 1851
1847int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1852static int atmel_usba_stop(struct usb_gadget_driver *driver)
1848{ 1853{
1849 struct usba_udc *udc = &the_udc; 1854 struct usba_udc *udc = &the_udc;
1850 unsigned long flags; 1855 unsigned long flags;
@@ -1880,7 +1885,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1880 1885
1881 return 0; 1886 return 0;
1882} 1887}
1883EXPORT_SYMBOL(usb_gadget_unregister_driver);
1884 1888
1885static int __init usba_udc_probe(struct platform_device *pdev) 1889static int __init usba_udc_probe(struct platform_device *pdev)
1886{ 1890{
@@ -2021,12 +2025,24 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2021 } 2025 }
2022 } 2026 }
2023 2027
2028 ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2029 if (ret)
2030 goto err_add_udc;
2031
2024 usba_init_debugfs(udc); 2032 usba_init_debugfs(udc);
2025 for (i = 1; i < pdata->num_ep; i++) 2033 for (i = 1; i < pdata->num_ep; i++)
2026 usba_ep_init_debugfs(udc, &usba_ep[i]); 2034 usba_ep_init_debugfs(udc, &usba_ep[i]);
2027 2035
2028 return 0; 2036 return 0;
2029 2037
2038err_add_udc:
2039 if (gpio_is_valid(pdata->vbus_pin)) {
2040 free_irq(gpio_to_irq(udc->vbus_pin), udc);
2041 gpio_free(udc->vbus_pin);
2042 }
2043
2044 device_unregister(&udc->gadget.dev);
2045
2030err_device_add: 2046err_device_add:
2031 free_irq(irq, udc); 2047 free_irq(irq, udc);
2032err_request_irq: 2048err_request_irq:
@@ -2053,6 +2069,8 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
2053 2069
2054 udc = platform_get_drvdata(pdev); 2070 udc = platform_get_drvdata(pdev);
2055 2071
2072 usb_del_gadget_udc(&udc->gadget);
2073
2056 for (i = 1; i < pdata->num_ep; i++) 2074 for (i = 1; i < pdata->num_ep; i++)
2057 usba_ep_cleanup_debugfs(&usba_ep[i]); 2075 usba_ep_cleanup_debugfs(&usba_ep[i]);
2058 usba_cleanup_debugfs(udc); 2076 usba_cleanup_debugfs(udc);
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index 93b999e49ef3..9d89ae4765a9 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -165,6 +165,7 @@ static struct usb_composite_driver audio_driver = {
165 .name = "g_audio", 165 .name = "g_audio",
166 .dev = &device_desc, 166 .dev = &device_desc,
167 .strings = audio_strings, 167 .strings = audio_strings,
168 .max_speed = USB_SPEED_HIGH,
168 .unbind = __exit_p(audio_unbind), 169 .unbind = __exit_p(audio_unbind),
169}; 170};
170 171
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 2720ab07ef1a..b1c1afbb8750 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -244,6 +244,7 @@ static struct usb_composite_driver cdc_driver = {
244 .name = "g_cdc", 244 .name = "g_cdc",
245 .dev = &device_desc, 245 .dev = &device_desc,
246 .strings = dev_strings, 246 .strings = dev_strings,
247 .max_speed = USB_SPEED_HIGH,
247 .unbind = __exit_p(cdc_unbind), 248 .unbind = __exit_p(cdc_unbind),
248}; 249};
249 250
diff --git a/drivers/usb/gadget/ci13xxx_msm.c b/drivers/usb/gadget/ci13xxx_msm.c
index 139ac9419597..470981ad6f77 100644
--- a/drivers/usb/gadget/ci13xxx_msm.c
+++ b/drivers/usb/gadget/ci13xxx_msm.c
@@ -126,6 +126,7 @@ static struct platform_driver ci13xxx_msm_driver = {
126 .probe = ci13xxx_msm_probe, 126 .probe = ci13xxx_msm_probe,
127 .driver = { .name = "msm_hsusb", }, 127 .driver = { .name = "msm_hsusb", },
128}; 128};
129MODULE_ALIAS("platform:msm_hsusb");
129 130
130static int __init ci13xxx_msm_init(void) 131static int __init ci13xxx_msm_init(void)
131{ 132{
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index baaf87ed7685..1265a8502ea0 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -857,7 +857,7 @@ static void dbg_print(u8 addr, const char *name, int status, const char *extra)
857 stamp = stamp * 1000000 + tval.tv_usec; 857 stamp = stamp * 1000000 + tval.tv_usec;
858 858
859 scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG, 859 scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG,
860 "%04X\t» %02X %-7.7s %4i «\t%s\n", 860 "%04X\t? %02X %-7.7s %4i ?\t%s\n",
861 stamp, addr, name, status, extra); 861 stamp, addr, name, status, extra);
862 862
863 dbg_inc(&dbg_data.idx); 863 dbg_inc(&dbg_data.idx);
@@ -865,7 +865,7 @@ static void dbg_print(u8 addr, const char *name, int status, const char *extra)
865 write_unlock_irqrestore(&dbg_data.lck, flags); 865 write_unlock_irqrestore(&dbg_data.lck, flags);
866 866
867 if (dbg_data.tty != 0) 867 if (dbg_data.tty != 0)
868 pr_notice("%04X\t» %02X %-7.7s %4i «\t%s\n", 868 pr_notice("%04X\t? %02X %-7.7s %4i ?\t%s\n",
869 stamp, addr, name, status, extra); 869 stamp, addr, name, status, extra);
870} 870}
871 871
@@ -1025,15 +1025,15 @@ static ssize_t show_inters(struct device *dev, struct device_attribute *attr,
1025 1025
1026 n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n", 1026 n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n",
1027 isr_statistics.test); 1027 isr_statistics.test);
1028 n += scnprintf(buf + n, PAGE_SIZE - n, "» ui = %d\n", 1028 n += scnprintf(buf + n, PAGE_SIZE - n, "? ui = %d\n",
1029 isr_statistics.ui); 1029 isr_statistics.ui);
1030 n += scnprintf(buf + n, PAGE_SIZE - n, "» uei = %d\n", 1030 n += scnprintf(buf + n, PAGE_SIZE - n, "? uei = %d\n",
1031 isr_statistics.uei); 1031 isr_statistics.uei);
1032 n += scnprintf(buf + n, PAGE_SIZE - n, "» pci = %d\n", 1032 n += scnprintf(buf + n, PAGE_SIZE - n, "? pci = %d\n",
1033 isr_statistics.pci); 1033 isr_statistics.pci);
1034 n += scnprintf(buf + n, PAGE_SIZE - n, "» uri = %d\n", 1034 n += scnprintf(buf + n, PAGE_SIZE - n, "? uri = %d\n",
1035 isr_statistics.uri); 1035 isr_statistics.uri);
1036 n += scnprintf(buf + n, PAGE_SIZE - n, "» sli = %d\n", 1036 n += scnprintf(buf + n, PAGE_SIZE - n, "? sli = %d\n",
1037 isr_statistics.sli); 1037 isr_statistics.sli);
1038 n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n", 1038 n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n",
1039 isr_statistics.none); 1039 isr_statistics.none);
@@ -1214,12 +1214,13 @@ static DEVICE_ATTR(qheads, S_IRUSR, show_qheads, NULL);
1214 * 1214 *
1215 * Check "device.h" for details 1215 * Check "device.h" for details
1216 */ 1216 */
1217#define DUMP_ENTRIES 512
1217static ssize_t show_registers(struct device *dev, 1218static ssize_t show_registers(struct device *dev,
1218 struct device_attribute *attr, char *buf) 1219 struct device_attribute *attr, char *buf)
1219{ 1220{
1220 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); 1221 struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev);
1221 unsigned long flags; 1222 unsigned long flags;
1222 u32 dump[512]; 1223 u32 *dump;
1223 unsigned i, k, n = 0; 1224 unsigned i, k, n = 0;
1224 1225
1225 dbg_trace("[%s] %p\n", __func__, buf); 1226 dbg_trace("[%s] %p\n", __func__, buf);
@@ -1228,8 +1229,14 @@ static ssize_t show_registers(struct device *dev,
1228 return 0; 1229 return 0;
1229 } 1230 }
1230 1231
1232 dump = kmalloc(sizeof(u32) * DUMP_ENTRIES, GFP_KERNEL);
1233 if (!dump) {
1234 dev_err(dev, "%s: out of memory\n", __func__);
1235 return 0;
1236 }
1237
1231 spin_lock_irqsave(udc->lock, flags); 1238 spin_lock_irqsave(udc->lock, flags);
1232 k = hw_register_read(dump, sizeof(dump)/sizeof(u32)); 1239 k = hw_register_read(dump, DUMP_ENTRIES);
1233 spin_unlock_irqrestore(udc->lock, flags); 1240 spin_unlock_irqrestore(udc->lock, flags);
1234 1241
1235 for (i = 0; i < k; i++) { 1242 for (i = 0; i < k; i++) {
@@ -1237,6 +1244,7 @@ static ssize_t show_registers(struct device *dev,
1237 "reg[0x%04X] = 0x%08X\n", 1244 "reg[0x%04X] = 0x%08X\n",
1238 i * (unsigned)sizeof(u32), dump[i]); 1245 i * (unsigned)sizeof(u32), dump[i]);
1239 } 1246 }
1247 kfree(dump);
1240 1248
1241 return n; 1249 return n;
1242} 1250}
@@ -2515,6 +2523,9 @@ static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
2515 return -ENOTSUPP; 2523 return -ENOTSUPP;
2516} 2524}
2517 2525
2526static int ci13xxx_start(struct usb_gadget_driver *driver,
2527 int (*bind)(struct usb_gadget *));
2528static int ci13xxx_stop(struct usb_gadget_driver *driver);
2518/** 2529/**
2519 * Device operations part of the API to the USB controller hardware, 2530 * Device operations part of the API to the USB controller hardware,
2520 * which don't involve endpoints (or i/o) 2531 * which don't involve endpoints (or i/o)
@@ -2524,17 +2535,19 @@ static const struct usb_gadget_ops usb_gadget_ops = {
2524 .vbus_session = ci13xxx_vbus_session, 2535 .vbus_session = ci13xxx_vbus_session,
2525 .wakeup = ci13xxx_wakeup, 2536 .wakeup = ci13xxx_wakeup,
2526 .vbus_draw = ci13xxx_vbus_draw, 2537 .vbus_draw = ci13xxx_vbus_draw,
2538 .start = ci13xxx_start,
2539 .stop = ci13xxx_stop,
2527}; 2540};
2528 2541
2529/** 2542/**
2530 * usb_gadget_probe_driver: register a gadget driver 2543 * ci13xxx_start: register a gadget driver
2531 * @driver: the driver being registered 2544 * @driver: the driver being registered
2532 * @bind: the driver's bind callback 2545 * @bind: the driver's bind callback
2533 * 2546 *
2534 * Check usb_gadget_probe_driver() at <linux/usb/gadget.h> for details. 2547 * Check ci13xxx_start() at <linux/usb/gadget.h> for details.
2535 * Interrupts are enabled here. 2548 * Interrupts are enabled here.
2536 */ 2549 */
2537int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2550static int ci13xxx_start(struct usb_gadget_driver *driver,
2538 int (*bind)(struct usb_gadget *)) 2551 int (*bind)(struct usb_gadget *))
2539{ 2552{
2540 struct ci13xxx *udc = _udc; 2553 struct ci13xxx *udc = _udc;
@@ -2615,10 +2628,13 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2615 if (retval) 2628 if (retval)
2616 goto done; 2629 goto done;
2617 spin_unlock_irqrestore(udc->lock, flags); 2630 spin_unlock_irqrestore(udc->lock, flags);
2618 retval = usb_ep_enable(&udc->ep0out.ep, &ctrl_endpt_out_desc); 2631 udc->ep0out.ep.desc = &ctrl_endpt_out_desc;
2632 retval = usb_ep_enable(&udc->ep0out.ep);
2619 if (retval) 2633 if (retval)
2620 return retval; 2634 return retval;
2621 retval = usb_ep_enable(&udc->ep0in.ep, &ctrl_endpt_in_desc); 2635
2636 udc->ep0in.ep.desc = &ctrl_endpt_in_desc;
2637 retval = usb_ep_enable(&udc->ep0in.ep);
2622 if (retval) 2638 if (retval)
2623 return retval; 2639 return retval;
2624 spin_lock_irqsave(udc->lock, flags); 2640 spin_lock_irqsave(udc->lock, flags);
@@ -2657,14 +2673,13 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2657 spin_unlock_irqrestore(udc->lock, flags); 2673 spin_unlock_irqrestore(udc->lock, flags);
2658 return retval; 2674 return retval;
2659} 2675}
2660EXPORT_SYMBOL(usb_gadget_probe_driver);
2661 2676
2662/** 2677/**
2663 * usb_gadget_unregister_driver: unregister a gadget driver 2678 * ci13xxx_stop: unregister a gadget driver
2664 * 2679 *
2665 * Check usb_gadget_unregister_driver() at "usb_gadget.h" for details 2680 * Check usb_gadget_unregister_driver() at "usb_gadget.h" for details
2666 */ 2681 */
2667int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2682static int ci13xxx_stop(struct usb_gadget_driver *driver)
2668{ 2683{
2669 struct ci13xxx *udc = _udc; 2684 struct ci13xxx *udc = _udc;
2670 unsigned long i, flags; 2685 unsigned long i, flags;
@@ -2726,7 +2741,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2726 2741
2727 return 0; 2742 return 0;
2728} 2743}
2729EXPORT_SYMBOL(usb_gadget_unregister_driver);
2730 2744
2731/****************************************************************************** 2745/******************************************************************************
2732 * BUS block 2746 * BUS block
@@ -2901,12 +2915,23 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
2901 if (retval) 2915 if (retval)
2902 goto remove_dbg; 2916 goto remove_dbg;
2903 } 2917 }
2918
2919 retval = usb_add_gadget_udc(dev, &udc->gadget);
2920 if (retval)
2921 goto remove_trans;
2922
2904 pm_runtime_no_callbacks(&udc->gadget.dev); 2923 pm_runtime_no_callbacks(&udc->gadget.dev);
2905 pm_runtime_enable(&udc->gadget.dev); 2924 pm_runtime_enable(&udc->gadget.dev);
2906 2925
2907 _udc = udc; 2926 _udc = udc;
2908 return retval; 2927 return retval;
2909 2928
2929remove_trans:
2930 if (udc->transceiver) {
2931 otg_set_peripheral(udc->transceiver, &udc->gadget);
2932 otg_put_transceiver(udc->transceiver);
2933 }
2934
2910 err("error = %i", retval); 2935 err("error = %i", retval);
2911remove_dbg: 2936remove_dbg:
2912#ifdef CONFIG_USB_GADGET_DEBUG_FILES 2937#ifdef CONFIG_USB_GADGET_DEBUG_FILES
@@ -2936,6 +2961,7 @@ static void udc_remove(void)
2936 err("EINVAL"); 2961 err("EINVAL");
2937 return; 2962 return;
2938 } 2963 }
2964 usb_del_gadget_udc(&udc->gadget);
2939 2965
2940 if (udc->transceiver) { 2966 if (udc->transceiver) {
2941 otg_set_peripheral(udc->transceiver, &udc->gadget); 2967 otg_set_peripheral(udc->transceiver, &udc->gadget);
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 5cbb1a41c223..5ef87794fd32 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -27,7 +27,7 @@
27#include <linux/utsname.h> 27#include <linux/utsname.h>
28 28
29#include <linux/usb/composite.h> 29#include <linux/usb/composite.h>
30 30#include <asm/unaligned.h>
31 31
32/* 32/*
33 * The code in this file is utility code, used to build a gadget driver 33 * The code in this file is utility code, used to build a gadget driver
@@ -74,6 +74,130 @@ MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
74static char composite_manufacturer[50]; 74static char composite_manufacturer[50];
75 75
76/*-------------------------------------------------------------------------*/ 76/*-------------------------------------------------------------------------*/
77/**
78 * next_ep_desc() - advance to the next EP descriptor
79 * @t: currect pointer within descriptor array
80 *
81 * Return: next EP descriptor or NULL
82 *
83 * Iterate over @t until either EP descriptor found or
84 * NULL (that indicates end of list) encountered
85 */
86static struct usb_descriptor_header**
87next_ep_desc(struct usb_descriptor_header **t)
88{
89 for (; *t; t++) {
90 if ((*t)->bDescriptorType == USB_DT_ENDPOINT)
91 return t;
92 }
93 return NULL;
94}
95
96/*
97 * for_each_ep_desc()- iterate over endpoint descriptors in the
98 * descriptors list
99 * @start: pointer within descriptor array.
100 * @ep_desc: endpoint descriptor to use as the loop cursor
101 */
102#define for_each_ep_desc(start, ep_desc) \
103 for (ep_desc = next_ep_desc(start); \
104 ep_desc; ep_desc = next_ep_desc(ep_desc+1))
105
106/**
107 * config_ep_by_speed() - configures the given endpoint
108 * according to gadget speed.
109 * @g: pointer to the gadget
110 * @f: usb function
111 * @_ep: the endpoint to configure
112 *
113 * Return: error code, 0 on success
114 *
115 * This function chooses the right descriptors for a given
116 * endpoint according to gadget speed and saves it in the
117 * endpoint desc field. If the endpoint already has a descriptor
118 * assigned to it - overwrites it with currently corresponding
119 * descriptor. The endpoint maxpacket field is updated according
120 * to the chosen descriptor.
121 * Note: the supplied function should hold all the descriptors
122 * for supported speeds
123 */
124int config_ep_by_speed(struct usb_gadget *g,
125 struct usb_function *f,
126 struct usb_ep *_ep)
127{
128 struct usb_endpoint_descriptor *chosen_desc = NULL;
129 struct usb_descriptor_header **speed_desc = NULL;
130
131 struct usb_ss_ep_comp_descriptor *comp_desc = NULL;
132 int want_comp_desc = 0;
133
134 struct usb_descriptor_header **d_spd; /* cursor for speed desc */
135
136 if (!g || !f || !_ep)
137 return -EIO;
138
139 /* select desired speed */
140 switch (g->speed) {
141 case USB_SPEED_SUPER:
142 if (gadget_is_superspeed(g)) {
143 speed_desc = f->ss_descriptors;
144 want_comp_desc = 1;
145 break;
146 }
147 /* else: Fall trough */
148 case USB_SPEED_HIGH:
149 if (gadget_is_dualspeed(g)) {
150 speed_desc = f->hs_descriptors;
151 break;
152 }
153 /* else: fall through */
154 default:
155 speed_desc = f->descriptors;
156 }
157 /* find descriptors */
158 for_each_ep_desc(speed_desc, d_spd) {
159 chosen_desc = (struct usb_endpoint_descriptor *)*d_spd;
160 if (chosen_desc->bEndpointAddress == _ep->address)
161 goto ep_found;
162 }
163 return -EIO;
164
165ep_found:
166 /* commit results */
167 _ep->maxpacket = le16_to_cpu(chosen_desc->wMaxPacketSize);
168 _ep->desc = chosen_desc;
169 _ep->comp_desc = NULL;
170 _ep->maxburst = 0;
171 _ep->mult = 0;
172 if (!want_comp_desc)
173 return 0;
174
175 /*
176 * Companion descriptor should follow EP descriptor
177 * USB 3.0 spec, #9.6.7
178 */
179 comp_desc = (struct usb_ss_ep_comp_descriptor *)*(++d_spd);
180 if (!comp_desc ||
181 (comp_desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP))
182 return -EIO;
183 _ep->comp_desc = comp_desc;
184 if (g->speed == USB_SPEED_SUPER) {
185 switch (usb_endpoint_type(_ep->desc)) {
186 case USB_ENDPOINT_XFER_BULK:
187 case USB_ENDPOINT_XFER_INT:
188 _ep->maxburst = comp_desc->bMaxBurst;
189 break;
190 case USB_ENDPOINT_XFER_ISOC:
191 /* mult: bits 1:0 of bmAttributes */
192 _ep->mult = comp_desc->bmAttributes & 0x3;
193 break;
194 default:
195 /* Do nothing for control endpoints */
196 break;
197 }
198 }
199 return 0;
200}
77 201
78/** 202/**
79 * usb_add_function() - add a function to a configuration 203 * usb_add_function() - add a function to a configuration
@@ -123,6 +247,8 @@ int usb_add_function(struct usb_configuration *config,
123 config->fullspeed = true; 247 config->fullspeed = true;
124 if (!config->highspeed && function->hs_descriptors) 248 if (!config->highspeed && function->hs_descriptors)
125 config->highspeed = true; 249 config->highspeed = true;
250 if (!config->superspeed && function->ss_descriptors)
251 config->superspeed = true;
126 252
127done: 253done:
128 if (value) 254 if (value)
@@ -266,10 +392,17 @@ static int config_buf(struct usb_configuration *config,
266 list_for_each_entry(f, &config->functions, list) { 392 list_for_each_entry(f, &config->functions, list) {
267 struct usb_descriptor_header **descriptors; 393 struct usb_descriptor_header **descriptors;
268 394
269 if (speed == USB_SPEED_HIGH) 395 switch (speed) {
396 case USB_SPEED_SUPER:
397 descriptors = f->ss_descriptors;
398 break;
399 case USB_SPEED_HIGH:
270 descriptors = f->hs_descriptors; 400 descriptors = f->hs_descriptors;
271 else 401 break;
402 default:
272 descriptors = f->descriptors; 403 descriptors = f->descriptors;
404 }
405
273 if (!descriptors) 406 if (!descriptors)
274 continue; 407 continue;
275 status = usb_descriptor_fillbuf(next, len, 408 status = usb_descriptor_fillbuf(next, len,
@@ -292,9 +425,10 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value)
292 u8 type = w_value >> 8; 425 u8 type = w_value >> 8;
293 enum usb_device_speed speed = USB_SPEED_UNKNOWN; 426 enum usb_device_speed speed = USB_SPEED_UNKNOWN;
294 427
295 if (gadget_is_dualspeed(gadget)) { 428 if (gadget->speed == USB_SPEED_SUPER)
296 int hs = 0; 429 speed = gadget->speed;
297 430 else if (gadget_is_dualspeed(gadget)) {
431 int hs = 0;
298 if (gadget->speed == USB_SPEED_HIGH) 432 if (gadget->speed == USB_SPEED_HIGH)
299 hs = 1; 433 hs = 1;
300 if (type == USB_DT_OTHER_SPEED_CONFIG) 434 if (type == USB_DT_OTHER_SPEED_CONFIG)
@@ -308,13 +442,20 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value)
308 w_value &= 0xff; 442 w_value &= 0xff;
309 list_for_each_entry(c, &cdev->configs, list) { 443 list_for_each_entry(c, &cdev->configs, list) {
310 /* ignore configs that won't work at this speed */ 444 /* ignore configs that won't work at this speed */
311 if (speed == USB_SPEED_HIGH) { 445 switch (speed) {
446 case USB_SPEED_SUPER:
447 if (!c->superspeed)
448 continue;
449 break;
450 case USB_SPEED_HIGH:
312 if (!c->highspeed) 451 if (!c->highspeed)
313 continue; 452 continue;
314 } else { 453 break;
454 default:
315 if (!c->fullspeed) 455 if (!c->fullspeed)
316 continue; 456 continue;
317 } 457 }
458
318 if (w_value == 0) 459 if (w_value == 0)
319 return config_buf(c, speed, cdev->req->buf, type); 460 return config_buf(c, speed, cdev->req->buf, type);
320 w_value--; 461 w_value--;
@@ -328,16 +469,22 @@ static int count_configs(struct usb_composite_dev *cdev, unsigned type)
328 struct usb_configuration *c; 469 struct usb_configuration *c;
329 unsigned count = 0; 470 unsigned count = 0;
330 int hs = 0; 471 int hs = 0;
472 int ss = 0;
331 473
332 if (gadget_is_dualspeed(gadget)) { 474 if (gadget_is_dualspeed(gadget)) {
333 if (gadget->speed == USB_SPEED_HIGH) 475 if (gadget->speed == USB_SPEED_HIGH)
334 hs = 1; 476 hs = 1;
477 if (gadget->speed == USB_SPEED_SUPER)
478 ss = 1;
335 if (type == USB_DT_DEVICE_QUALIFIER) 479 if (type == USB_DT_DEVICE_QUALIFIER)
336 hs = !hs; 480 hs = !hs;
337 } 481 }
338 list_for_each_entry(c, &cdev->configs, list) { 482 list_for_each_entry(c, &cdev->configs, list) {
339 /* ignore configs that won't work at this speed */ 483 /* ignore configs that won't work at this speed */
340 if (hs) { 484 if (ss) {
485 if (!c->superspeed)
486 continue;
487 } else if (hs) {
341 if (!c->highspeed) 488 if (!c->highspeed)
342 continue; 489 continue;
343 } else { 490 } else {
@@ -349,6 +496,71 @@ static int count_configs(struct usb_composite_dev *cdev, unsigned type)
349 return count; 496 return count;
350} 497}
351 498
499/**
500 * bos_desc() - prepares the BOS descriptor.
501 * @cdev: pointer to usb_composite device to generate the bos
502 * descriptor for
503 *
504 * This function generates the BOS (Binary Device Object)
505 * descriptor and its device capabilities descriptors. The BOS
506 * descriptor should be supported by a SuperSpeed device.
507 */
508static int bos_desc(struct usb_composite_dev *cdev)
509{
510 struct usb_ext_cap_descriptor *usb_ext;
511 struct usb_ss_cap_descriptor *ss_cap;
512 struct usb_dcd_config_params dcd_config_params;
513 struct usb_bos_descriptor *bos = cdev->req->buf;
514
515 bos->bLength = USB_DT_BOS_SIZE;
516 bos->bDescriptorType = USB_DT_BOS;
517
518 bos->wTotalLength = cpu_to_le16(USB_DT_BOS_SIZE);
519 bos->bNumDeviceCaps = 0;
520
521 /*
522 * A SuperSpeed device shall include the USB2.0 extension descriptor
523 * and shall support LPM when operating in USB2.0 HS mode.
524 */
525 usb_ext = cdev->req->buf + le16_to_cpu(bos->wTotalLength);
526 bos->bNumDeviceCaps++;
527 le16_add_cpu(&bos->wTotalLength, USB_DT_USB_EXT_CAP_SIZE);
528 usb_ext->bLength = USB_DT_USB_EXT_CAP_SIZE;
529 usb_ext->bDescriptorType = USB_DT_DEVICE_CAPABILITY;
530 usb_ext->bDevCapabilityType = USB_CAP_TYPE_EXT;
531 usb_ext->bmAttributes = cpu_to_le32(USB_LPM_SUPPORT);
532
533 /*
534 * The Superspeed USB Capability descriptor shall be implemented by all
535 * SuperSpeed devices.
536 */
537 ss_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength);
538 bos->bNumDeviceCaps++;
539 le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SS_CAP_SIZE);
540 ss_cap->bLength = USB_DT_USB_SS_CAP_SIZE;
541 ss_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY;
542 ss_cap->bDevCapabilityType = USB_SS_CAP_TYPE;
543 ss_cap->bmAttributes = 0; /* LTM is not supported yet */
544 ss_cap->wSpeedSupported = cpu_to_le16(USB_LOW_SPEED_OPERATION |
545 USB_FULL_SPEED_OPERATION |
546 USB_HIGH_SPEED_OPERATION |
547 USB_5GBPS_OPERATION);
548 ss_cap->bFunctionalitySupport = USB_LOW_SPEED_OPERATION;
549
550 /* Get Controller configuration */
551 if (cdev->gadget->ops->get_config_params)
552 cdev->gadget->ops->get_config_params(&dcd_config_params);
553 else {
554 dcd_config_params.bU1devExitLat = USB_DEFULT_U1_DEV_EXIT_LAT;
555 dcd_config_params.bU2DevExitLat =
556 cpu_to_le16(USB_DEFULT_U2_DEV_EXIT_LAT);
557 }
558 ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat;
559 ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat;
560
561 return le16_to_cpu(bos->wTotalLength);
562}
563
352static void device_qual(struct usb_composite_dev *cdev) 564static void device_qual(struct usb_composite_dev *cdev)
353{ 565{
354 struct usb_qualifier_descriptor *qual = cdev->req->buf; 566 struct usb_qualifier_descriptor *qual = cdev->req->buf;
@@ -361,7 +573,7 @@ static void device_qual(struct usb_composite_dev *cdev)
361 qual->bDeviceSubClass = cdev->desc.bDeviceSubClass; 573 qual->bDeviceSubClass = cdev->desc.bDeviceSubClass;
362 qual->bDeviceProtocol = cdev->desc.bDeviceProtocol; 574 qual->bDeviceProtocol = cdev->desc.bDeviceProtocol;
363 /* ASSUME same EP0 fifo size at both speeds */ 575 /* ASSUME same EP0 fifo size at both speeds */
364 qual->bMaxPacketSize0 = cdev->desc.bMaxPacketSize0; 576 qual->bMaxPacketSize0 = cdev->gadget->ep0->maxpacket;
365 qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER); 577 qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER);
366 qual->bRESERVED = 0; 578 qual->bRESERVED = 0;
367} 579}
@@ -392,28 +604,46 @@ static int set_config(struct usb_composite_dev *cdev,
392 unsigned power = gadget_is_otg(gadget) ? 8 : 100; 604 unsigned power = gadget_is_otg(gadget) ? 8 : 100;
393 int tmp; 605 int tmp;
394 606
395 if (cdev->config)
396 reset_config(cdev);
397
398 if (number) { 607 if (number) {
399 list_for_each_entry(c, &cdev->configs, list) { 608 list_for_each_entry(c, &cdev->configs, list) {
400 if (c->bConfigurationValue == number) { 609 if (c->bConfigurationValue == number) {
610 /*
611 * We disable the FDs of the previous
612 * configuration only if the new configuration
613 * is a valid one
614 */
615 if (cdev->config)
616 reset_config(cdev);
401 result = 0; 617 result = 0;
402 break; 618 break;
403 } 619 }
404 } 620 }
405 if (result < 0) 621 if (result < 0)
406 goto done; 622 goto done;
407 } else 623 } else { /* Zero configuration value - need to reset the config */
624 if (cdev->config)
625 reset_config(cdev);
408 result = 0; 626 result = 0;
627 }
409 628
410 INFO(cdev, "%s speed config #%d: %s\n", 629 INFO(cdev, "%s speed config #%d: %s\n",
411 ({ char *speed; 630 ({ char *speed;
412 switch (gadget->speed) { 631 switch (gadget->speed) {
413 case USB_SPEED_LOW: speed = "low"; break; 632 case USB_SPEED_LOW:
414 case USB_SPEED_FULL: speed = "full"; break; 633 speed = "low";
415 case USB_SPEED_HIGH: speed = "high"; break; 634 break;
416 default: speed = "?"; break; 635 case USB_SPEED_FULL:
636 speed = "full";
637 break;
638 case USB_SPEED_HIGH:
639 speed = "high";
640 break;
641 case USB_SPEED_SUPER:
642 speed = "super";
643 break;
644 default:
645 speed = "?";
646 break;
417 } ; speed; }), number, c ? c->label : "unconfigured"); 647 } ; speed; }), number, c ? c->label : "unconfigured");
418 648
419 if (!c) 649 if (!c)
@@ -435,10 +665,16 @@ static int set_config(struct usb_composite_dev *cdev,
435 * function's setup callback instead of the current 665 * function's setup callback instead of the current
436 * configuration's setup callback. 666 * configuration's setup callback.
437 */ 667 */
438 if (gadget->speed == USB_SPEED_HIGH) 668 switch (gadget->speed) {
669 case USB_SPEED_SUPER:
670 descriptors = f->ss_descriptors;
671 break;
672 case USB_SPEED_HIGH:
439 descriptors = f->hs_descriptors; 673 descriptors = f->hs_descriptors;
440 else 674 break;
675 default:
441 descriptors = f->descriptors; 676 descriptors = f->descriptors;
677 }
442 678
443 for (; *descriptors; ++descriptors) { 679 for (; *descriptors; ++descriptors) {
444 struct usb_endpoint_descriptor *ep; 680 struct usb_endpoint_descriptor *ep;
@@ -531,8 +767,9 @@ int usb_add_config(struct usb_composite_dev *cdev,
531 } else { 767 } else {
532 unsigned i; 768 unsigned i;
533 769
534 DBG(cdev, "cfg %d/%p speeds:%s%s\n", 770 DBG(cdev, "cfg %d/%p speeds:%s%s%s\n",
535 config->bConfigurationValue, config, 771 config->bConfigurationValue, config,
772 config->superspeed ? " super" : "",
536 config->highspeed ? " high" : "", 773 config->highspeed ? " high" : "",
537 config->fullspeed 774 config->fullspeed
538 ? (gadget_is_dualspeed(cdev->gadget) 775 ? (gadget_is_dualspeed(cdev->gadget)
@@ -811,6 +1048,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
811 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1048 struct usb_composite_dev *cdev = get_gadget_data(gadget);
812 struct usb_request *req = cdev->req; 1049 struct usb_request *req = cdev->req;
813 int value = -EOPNOTSUPP; 1050 int value = -EOPNOTSUPP;
1051 int status = 0;
814 u16 w_index = le16_to_cpu(ctrl->wIndex); 1052 u16 w_index = le16_to_cpu(ctrl->wIndex);
815 u8 intf = w_index & 0xFF; 1053 u8 intf = w_index & 0xFF;
816 u16 w_value = le16_to_cpu(ctrl->wValue); 1054 u16 w_value = le16_to_cpu(ctrl->wValue);
@@ -838,18 +1076,29 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
838 case USB_DT_DEVICE: 1076 case USB_DT_DEVICE:
839 cdev->desc.bNumConfigurations = 1077 cdev->desc.bNumConfigurations =
840 count_configs(cdev, USB_DT_DEVICE); 1078 count_configs(cdev, USB_DT_DEVICE);
1079 cdev->desc.bMaxPacketSize0 =
1080 cdev->gadget->ep0->maxpacket;
1081 if (gadget_is_superspeed(gadget)) {
1082 if (gadget->speed >= USB_SPEED_SUPER)
1083 cdev->desc.bcdUSB = cpu_to_le16(0x0300);
1084 else
1085 cdev->desc.bcdUSB = cpu_to_le16(0x0210);
1086 }
1087
841 value = min(w_length, (u16) sizeof cdev->desc); 1088 value = min(w_length, (u16) sizeof cdev->desc);
842 memcpy(req->buf, &cdev->desc, value); 1089 memcpy(req->buf, &cdev->desc, value);
843 break; 1090 break;
844 case USB_DT_DEVICE_QUALIFIER: 1091 case USB_DT_DEVICE_QUALIFIER:
845 if (!gadget_is_dualspeed(gadget)) 1092 if (!gadget_is_dualspeed(gadget) ||
1093 gadget->speed >= USB_SPEED_SUPER)
846 break; 1094 break;
847 device_qual(cdev); 1095 device_qual(cdev);
848 value = min_t(int, w_length, 1096 value = min_t(int, w_length,
849 sizeof(struct usb_qualifier_descriptor)); 1097 sizeof(struct usb_qualifier_descriptor));
850 break; 1098 break;
851 case USB_DT_OTHER_SPEED_CONFIG: 1099 case USB_DT_OTHER_SPEED_CONFIG:
852 if (!gadget_is_dualspeed(gadget)) 1100 if (!gadget_is_dualspeed(gadget) ||
1101 gadget->speed >= USB_SPEED_SUPER)
853 break; 1102 break;
854 /* FALLTHROUGH */ 1103 /* FALLTHROUGH */
855 case USB_DT_CONFIG: 1104 case USB_DT_CONFIG:
@@ -863,6 +1112,12 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
863 if (value >= 0) 1112 if (value >= 0)
864 value = min(w_length, (u16) value); 1113 value = min(w_length, (u16) value);
865 break; 1114 break;
1115 case USB_DT_BOS:
1116 if (gadget_is_superspeed(gadget)) {
1117 value = bos_desc(cdev);
1118 value = min(w_length, (u16) value);
1119 }
1120 break;
866 } 1121 }
867 break; 1122 break;
868 1123
@@ -930,6 +1185,61 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
930 *((u8 *)req->buf) = value; 1185 *((u8 *)req->buf) = value;
931 value = min(w_length, (u16) 1); 1186 value = min(w_length, (u16) 1);
932 break; 1187 break;
1188
1189 /*
1190 * USB 3.0 additions:
1191 * Function driver should handle get_status request. If such cb
1192 * wasn't supplied we respond with default value = 0
1193 * Note: function driver should supply such cb only for the first
1194 * interface of the function
1195 */
1196 case USB_REQ_GET_STATUS:
1197 if (!gadget_is_superspeed(gadget))
1198 goto unknown;
1199 if (ctrl->bRequestType != (USB_DIR_IN | USB_RECIP_INTERFACE))
1200 goto unknown;
1201 value = 2; /* This is the length of the get_status reply */
1202 put_unaligned_le16(0, req->buf);
1203 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
1204 break;
1205 f = cdev->config->interface[intf];
1206 if (!f)
1207 break;
1208 status = f->get_status ? f->get_status(f) : 0;
1209 if (status < 0)
1210 break;
1211 put_unaligned_le16(status & 0x0000ffff, req->buf);
1212 break;
1213 /*
1214 * Function drivers should handle SetFeature/ClearFeature
1215 * (FUNCTION_SUSPEND) request. function_suspend cb should be supplied
1216 * only for the first interface of the function
1217 */
1218 case USB_REQ_CLEAR_FEATURE:
1219 case USB_REQ_SET_FEATURE:
1220 if (!gadget_is_superspeed(gadget))
1221 goto unknown;
1222 if (ctrl->bRequestType != (USB_DIR_OUT | USB_RECIP_INTERFACE))
1223 goto unknown;
1224 switch (w_value) {
1225 case USB_INTRF_FUNC_SUSPEND:
1226 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
1227 break;
1228 f = cdev->config->interface[intf];
1229 if (!f)
1230 break;
1231 value = 0;
1232 if (f->func_suspend)
1233 value = f->func_suspend(f, w_index >> 8);
1234 if (value < 0) {
1235 ERROR(cdev,
1236 "func_suspend() returned error %d\n",
1237 value);
1238 value = 0;
1239 }
1240 break;
1241 }
1242 break;
933 default: 1243 default:
934unknown: 1244unknown:
935 VDBG(cdev, 1245 VDBG(cdev,
@@ -1140,7 +1450,6 @@ static int composite_bind(struct usb_gadget *gadget)
1140 goto fail; 1450 goto fail;
1141 1451
1142 cdev->desc = *composite->dev; 1452 cdev->desc = *composite->dev;
1143 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1144 1453
1145 /* standardized runtime overrides for device ID data */ 1454 /* standardized runtime overrides for device ID data */
1146 if (idVendor) 1455 if (idVendor)
@@ -1247,7 +1556,11 @@ composite_resume(struct usb_gadget *gadget)
1247/*-------------------------------------------------------------------------*/ 1556/*-------------------------------------------------------------------------*/
1248 1557
1249static struct usb_gadget_driver composite_driver = { 1558static struct usb_gadget_driver composite_driver = {
1559#ifdef CONFIG_USB_GADGET_SUPERSPEED
1560 .speed = USB_SPEED_SUPER,
1561#else
1250 .speed = USB_SPEED_HIGH, 1562 .speed = USB_SPEED_HIGH,
1563#endif
1251 1564
1252 .unbind = composite_unbind, 1565 .unbind = composite_unbind,
1253 1566
@@ -1293,6 +1606,8 @@ int usb_composite_probe(struct usb_composite_driver *driver,
1293 driver->iProduct = driver->name; 1606 driver->iProduct = driver->name;
1294 composite_driver.function = (char *) driver->name; 1607 composite_driver.function = (char *) driver->name;
1295 composite_driver.driver.name = driver->name; 1608 composite_driver.driver.name = driver->name;
1609 composite_driver.speed = min((u8)composite_driver.speed,
1610 (u8)driver->max_speed);
1296 composite = driver; 1611 composite = driver;
1297 composite_gadget_bind = bind; 1612 composite_gadget_bind = bind;
1298 1613
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index 09084fd646ab..b2c001334876 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -165,28 +165,3 @@ usb_copy_descriptors(struct usb_descriptor_header **src)
165 return ret; 165 return ret;
166} 166}
167 167
168/**
169 * usb_find_endpoint - find a copy of an endpoint descriptor
170 * @src: original vector of descriptors
171 * @copy: copy of @src
172 * @match: endpoint descriptor found in @src
173 *
174 * This returns the copy of the @match descriptor made for @copy. Its
175 * intended use is to help remembering the endpoint descriptor to use
176 * when enabling a given endpoint.
177 */
178struct usb_endpoint_descriptor *
179usb_find_endpoint(
180 struct usb_descriptor_header **src,
181 struct usb_descriptor_header **copy,
182 struct usb_endpoint_descriptor *match
183)
184{
185 while (*src) {
186 if (*src == (void *) match)
187 return (void *)*copy;
188 src++;
189 copy++;
190 }
191 return NULL;
192}
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
index dbe92ee88477..8beefdd36787 100644
--- a/drivers/usb/gadget/dbgp.c
+++ b/drivers/usb/gadget/dbgp.c
@@ -173,7 +173,9 @@ fail_1:
173 173
174static int __enable_ep(struct usb_ep *ep, struct usb_endpoint_descriptor *desc) 174static int __enable_ep(struct usb_ep *ep, struct usb_endpoint_descriptor *desc)
175{ 175{
176 int err = usb_ep_enable(ep, desc); 176 int err;
177 ep->desc = desc;
178 err = usb_ep_enable(ep);
177 ep->driver_data = dbgp.gadget; 179 ep->driver_data = dbgp.gadget;
178 return err; 180 return err;
179} 181}
@@ -268,8 +270,8 @@ static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
268 dbgp.serial->in = dbgp.i_ep; 270 dbgp.serial->in = dbgp.i_ep;
269 dbgp.serial->out = dbgp.o_ep; 271 dbgp.serial->out = dbgp.o_ep;
270 272
271 dbgp.serial->in_desc = &i_desc; 273 dbgp.serial->in->desc = &i_desc;
272 dbgp.serial->out_desc = &o_desc; 274 dbgp.serial->out->desc = &o_desc;
273 275
274 if (gserial_setup(gadget, 1) < 0) { 276 if (gserial_setup(gadget, 1) < 0) {
275 stp = 3; 277 stp = 3;
@@ -312,7 +314,6 @@ static int __init dbgp_bind(struct usb_gadget *gadget)
312 314
313 dbgp.req->length = DBGP_REQ_EP0_LEN; 315 dbgp.req->length = DBGP_REQ_EP0_LEN;
314 gadget->ep0->driver_data = gadget; 316 gadget->ep0->driver_data = gadget;
315 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
316 317
317#ifdef CONFIG_USB_G_DBGP_SERIAL 318#ifdef CONFIG_USB_G_DBGP_SERIAL
318 dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL); 319 dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL);
@@ -363,6 +364,7 @@ static int dbgp_setup(struct usb_gadget *gadget,
363 dev_dbg(&dbgp.gadget->dev, "setup: desc device\n"); 364 dev_dbg(&dbgp.gadget->dev, "setup: desc device\n");
364 len = sizeof device_desc; 365 len = sizeof device_desc;
365 data = &device_desc; 366 data = &device_desc;
367 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
366 break; 368 break;
367 case USB_DT_DEBUG: 369 case USB_DT_DEBUG:
368 dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n"); 370 dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n");
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index d3dcabc1a5fc..e755a9d267fc 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -70,6 +70,19 @@ MODULE_DESCRIPTION (DRIVER_DESC);
70MODULE_AUTHOR ("David Brownell"); 70MODULE_AUTHOR ("David Brownell");
71MODULE_LICENSE ("GPL"); 71MODULE_LICENSE ("GPL");
72 72
73struct dummy_hcd_module_parameters {
74 bool is_super_speed;
75 bool is_high_speed;
76};
77
78static struct dummy_hcd_module_parameters mod_data = {
79 .is_super_speed = false,
80 .is_high_speed = true,
81};
82module_param_named(is_super_speed, mod_data.is_super_speed, bool, S_IRUGO);
83MODULE_PARM_DESC(is_super_speed, "true to simulate SuperSpeed connection");
84module_param_named(is_high_speed, mod_data.is_high_speed, bool, S_IRUGO);
85MODULE_PARM_DESC(is_high_speed, "true to simulate HighSpeed connection");
73/*-------------------------------------------------------------------------*/ 86/*-------------------------------------------------------------------------*/
74 87
75/* gadget side driver data structres */ 88/* gadget side driver data structres */
@@ -152,6 +165,22 @@ enum dummy_rh_state {
152 DUMMY_RH_RUNNING 165 DUMMY_RH_RUNNING
153}; 166};
154 167
168struct dummy_hcd {
169 struct dummy *dum;
170 enum dummy_rh_state rh_state;
171 struct timer_list timer;
172 u32 port_status;
173 u32 old_status;
174 unsigned long re_timeout;
175
176 struct usb_device *udev;
177 struct list_head urbp_list;
178
179 unsigned active:1;
180 unsigned old_active:1;
181 unsigned resuming:1;
182};
183
155struct dummy { 184struct dummy {
156 spinlock_t lock; 185 spinlock_t lock;
157 186
@@ -167,36 +196,27 @@ struct dummy {
167 u16 devstatus; 196 u16 devstatus;
168 unsigned udc_suspended:1; 197 unsigned udc_suspended:1;
169 unsigned pullup:1; 198 unsigned pullup:1;
170 unsigned active:1;
171 unsigned old_active:1;
172 199
173 /* 200 /*
174 * MASTER/HOST side support 201 * MASTER/HOST side support
175 */ 202 */
176 enum dummy_rh_state rh_state; 203 struct dummy_hcd *hs_hcd;
177 struct timer_list timer; 204 struct dummy_hcd *ss_hcd;
178 u32 port_status;
179 u32 old_status;
180 unsigned resuming:1;
181 unsigned long re_timeout;
182
183 struct usb_device *udev;
184 struct list_head urbp_list;
185}; 205};
186 206
187static inline struct dummy *hcd_to_dummy (struct usb_hcd *hcd) 207static inline struct dummy_hcd *hcd_to_dummy_hcd(struct usb_hcd *hcd)
188{ 208{
189 return (struct dummy *) (hcd->hcd_priv); 209 return (struct dummy_hcd *) (hcd->hcd_priv);
190} 210}
191 211
192static inline struct usb_hcd *dummy_to_hcd (struct dummy *dum) 212static inline struct usb_hcd *dummy_hcd_to_hcd(struct dummy_hcd *dum)
193{ 213{
194 return container_of((void *) dum, struct usb_hcd, hcd_priv); 214 return container_of((void *) dum, struct usb_hcd, hcd_priv);
195} 215}
196 216
197static inline struct device *dummy_dev (struct dummy *dum) 217static inline struct device *dummy_dev(struct dummy_hcd *dum)
198{ 218{
199 return dummy_to_hcd(dum)->self.controller; 219 return dummy_hcd_to_hcd(dum)->self.controller;
200} 220}
201 221
202static inline struct device *udc_dev (struct dummy *dum) 222static inline struct device *udc_dev (struct dummy *dum)
@@ -209,9 +229,13 @@ static inline struct dummy *ep_to_dummy (struct dummy_ep *ep)
209 return container_of (ep->gadget, struct dummy, gadget); 229 return container_of (ep->gadget, struct dummy, gadget);
210} 230}
211 231
212static inline struct dummy *gadget_to_dummy (struct usb_gadget *gadget) 232static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget)
213{ 233{
214 return container_of (gadget, struct dummy, gadget); 234 struct dummy *dum = container_of(gadget, struct dummy, gadget);
235 if (dum->gadget.speed == USB_SPEED_SUPER)
236 return dum->ss_hcd;
237 else
238 return dum->hs_hcd;
215} 239}
216 240
217static inline struct dummy *gadget_dev_to_dummy (struct device *dev) 241static inline struct dummy *gadget_dev_to_dummy (struct device *dev)
@@ -219,7 +243,7 @@ static inline struct dummy *gadget_dev_to_dummy (struct device *dev)
219 return container_of (dev, struct dummy, gadget.dev); 243 return container_of (dev, struct dummy, gadget.dev);
220} 244}
221 245
222static struct dummy *the_controller; 246static struct dummy the_controller;
223 247
224/*-------------------------------------------------------------------------*/ 248/*-------------------------------------------------------------------------*/
225 249
@@ -259,61 +283,122 @@ stop_activity (struct dummy *dum)
259 /* driver now does any non-usb quiescing necessary */ 283 /* driver now does any non-usb quiescing necessary */
260} 284}
261 285
262/* caller must hold lock */ 286/**
263static void 287 * set_link_state_by_speed() - Sets the current state of the link according to
264set_link_state (struct dummy *dum) 288 * the hcd speed
265{ 289 * @dum_hcd: pointer to the dummy_hcd structure to update the link state for
266 dum->active = 0; 290 *
267 if ((dum->port_status & USB_PORT_STAT_POWER) == 0) 291 * This function updates the port_status according to the link state and the
268 dum->port_status = 0; 292 * speed of the hcd.
269 293 */
270 /* UDC suspend must cause a disconnect */ 294static void set_link_state_by_speed(struct dummy_hcd *dum_hcd)
271 else if (!dum->pullup || dum->udc_suspended) { 295{
272 dum->port_status &= ~(USB_PORT_STAT_CONNECTION | 296 struct dummy *dum = dum_hcd->dum;
273 USB_PORT_STAT_ENABLE | 297
274 USB_PORT_STAT_LOW_SPEED | 298 if (dummy_hcd_to_hcd(dum_hcd)->speed == HCD_USB3) {
275 USB_PORT_STAT_HIGH_SPEED | 299 if ((dum_hcd->port_status & USB_SS_PORT_STAT_POWER) == 0) {
276 USB_PORT_STAT_SUSPEND); 300 dum_hcd->port_status = 0;
277 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0) 301 } else if (!dum->pullup || dum->udc_suspended) {
278 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); 302 /* UDC suspend must cause a disconnect */
303 dum_hcd->port_status &= ~(USB_PORT_STAT_CONNECTION |
304 USB_PORT_STAT_ENABLE);
305 if ((dum_hcd->old_status &
306 USB_PORT_STAT_CONNECTION) != 0)
307 dum_hcd->port_status |=
308 (USB_PORT_STAT_C_CONNECTION << 16);
309 } else {
310 /* device is connected and not suspended */
311 dum_hcd->port_status |= (USB_PORT_STAT_CONNECTION |
312 USB_PORT_STAT_SPEED_5GBPS) ;
313 if ((dum_hcd->old_status &
314 USB_PORT_STAT_CONNECTION) == 0)
315 dum_hcd->port_status |=
316 (USB_PORT_STAT_C_CONNECTION << 16);
317 if ((dum_hcd->port_status &
318 USB_PORT_STAT_ENABLE) == 1 &&
319 (dum_hcd->port_status &
320 USB_SS_PORT_LS_U0) == 1 &&
321 dum_hcd->rh_state != DUMMY_RH_SUSPENDED)
322 dum_hcd->active = 1;
323 }
279 } else { 324 } else {
280 dum->port_status |= USB_PORT_STAT_CONNECTION; 325 if ((dum_hcd->port_status & USB_PORT_STAT_POWER) == 0) {
281 if ((dum->old_status & USB_PORT_STAT_CONNECTION) == 0) 326 dum_hcd->port_status = 0;
282 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); 327 } else if (!dum->pullup || dum->udc_suspended) {
283 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0) 328 /* UDC suspend must cause a disconnect */
284 dum->port_status &= ~USB_PORT_STAT_SUSPEND; 329 dum_hcd->port_status &= ~(USB_PORT_STAT_CONNECTION |
285 else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 && 330 USB_PORT_STAT_ENABLE |
286 dum->rh_state != DUMMY_RH_SUSPENDED) 331 USB_PORT_STAT_LOW_SPEED |
287 dum->active = 1; 332 USB_PORT_STAT_HIGH_SPEED |
333 USB_PORT_STAT_SUSPEND);
334 if ((dum_hcd->old_status &
335 USB_PORT_STAT_CONNECTION) != 0)
336 dum_hcd->port_status |=
337 (USB_PORT_STAT_C_CONNECTION << 16);
338 } else {
339 dum_hcd->port_status |= USB_PORT_STAT_CONNECTION;
340 if ((dum_hcd->old_status &
341 USB_PORT_STAT_CONNECTION) == 0)
342 dum_hcd->port_status |=
343 (USB_PORT_STAT_C_CONNECTION << 16);
344 if ((dum_hcd->port_status & USB_PORT_STAT_ENABLE) == 0)
345 dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND;
346 else if ((dum_hcd->port_status &
347 USB_PORT_STAT_SUSPEND) == 0 &&
348 dum_hcd->rh_state != DUMMY_RH_SUSPENDED)
349 dum_hcd->active = 1;
350 }
288 } 351 }
352}
353
354/* caller must hold lock */
355static void set_link_state(struct dummy_hcd *dum_hcd)
356{
357 struct dummy *dum = dum_hcd->dum;
289 358
290 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0 || dum->active) 359 dum_hcd->active = 0;
291 dum->resuming = 0; 360 if (dum->pullup)
361 if ((dummy_hcd_to_hcd(dum_hcd)->speed == HCD_USB3 &&
362 dum->gadget.speed != USB_SPEED_SUPER) ||
363 (dummy_hcd_to_hcd(dum_hcd)->speed != HCD_USB3 &&
364 dum->gadget.speed == USB_SPEED_SUPER))
365 return;
292 366
293 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0 || 367 set_link_state_by_speed(dum_hcd);
294 (dum->port_status & USB_PORT_STAT_RESET) != 0) { 368
295 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 && 369 if ((dum_hcd->port_status & USB_PORT_STAT_ENABLE) == 0 ||
296 (dum->old_status & USB_PORT_STAT_RESET) == 0 && 370 dum_hcd->active)
297 dum->driver) { 371 dum_hcd->resuming = 0;
298 stop_activity (dum); 372
299 spin_unlock (&dum->lock); 373 /* if !connected or reset */
300 dum->driver->disconnect (&dum->gadget); 374 if ((dum_hcd->port_status & USB_PORT_STAT_CONNECTION) == 0 ||
301 spin_lock (&dum->lock); 375 (dum_hcd->port_status & USB_PORT_STAT_RESET) != 0) {
376 /*
377 * We're connected and not reset (reset occurred now),
378 * and driver attached - disconnect!
379 */
380 if ((dum_hcd->old_status & USB_PORT_STAT_CONNECTION) != 0 &&
381 (dum_hcd->old_status & USB_PORT_STAT_RESET) == 0 &&
382 dum->driver) {
383 stop_activity(dum);
384 spin_unlock(&dum->lock);
385 dum->driver->disconnect(&dum->gadget);
386 spin_lock(&dum->lock);
302 } 387 }
303 } else if (dum->active != dum->old_active) { 388 } else if (dum_hcd->active != dum_hcd->old_active) {
304 if (dum->old_active && dum->driver->suspend) { 389 if (dum_hcd->old_active && dum->driver->suspend) {
305 spin_unlock (&dum->lock); 390 spin_unlock(&dum->lock);
306 dum->driver->suspend (&dum->gadget); 391 dum->driver->suspend(&dum->gadget);
307 spin_lock (&dum->lock); 392 spin_lock(&dum->lock);
308 } else if (!dum->old_active && dum->driver->resume) { 393 } else if (!dum_hcd->old_active && dum->driver->resume) {
309 spin_unlock (&dum->lock); 394 spin_unlock(&dum->lock);
310 dum->driver->resume (&dum->gadget); 395 dum->driver->resume(&dum->gadget);
311 spin_lock (&dum->lock); 396 spin_lock(&dum->lock);
312 } 397 }
313 } 398 }
314 399
315 dum->old_status = dum->port_status; 400 dum_hcd->old_status = dum_hcd->port_status;
316 dum->old_active = dum->active; 401 dum_hcd->old_active = dum_hcd->active;
317} 402}
318 403
319/*-------------------------------------------------------------------------*/ 404/*-------------------------------------------------------------------------*/
@@ -332,6 +417,7 @@ static int
332dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) 417dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
333{ 418{
334 struct dummy *dum; 419 struct dummy *dum;
420 struct dummy_hcd *dum_hcd;
335 struct dummy_ep *ep; 421 struct dummy_ep *ep;
336 unsigned max; 422 unsigned max;
337 int retval; 423 int retval;
@@ -341,9 +427,19 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
341 || desc->bDescriptorType != USB_DT_ENDPOINT) 427 || desc->bDescriptorType != USB_DT_ENDPOINT)
342 return -EINVAL; 428 return -EINVAL;
343 dum = ep_to_dummy (ep); 429 dum = ep_to_dummy (ep);
344 if (!dum->driver || !is_enabled (dum)) 430 if (!dum->driver)
431 return -ESHUTDOWN;
432
433 dum_hcd = gadget_to_dummy_hcd(&dum->gadget);
434 if (!is_enabled(dum_hcd))
345 return -ESHUTDOWN; 435 return -ESHUTDOWN;
346 max = le16_to_cpu(desc->wMaxPacketSize) & 0x3ff; 436
437 /*
438 * For HS/FS devices only bits 0..10 of the wMaxPacketSize represent the
439 * maximum packet size.
440 * For SS devices the wMaxPacketSize is limited by 1024.
441 */
442 max = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff;
347 443
348 /* drivers must not request bad settings, since lower levels 444 /* drivers must not request bad settings, since lower levels
349 * (hardware or its drivers) may not check. some endpoints 445 * (hardware or its drivers) may not check. some endpoints
@@ -361,6 +457,10 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
361 goto done; 457 goto done;
362 } 458 }
363 switch (dum->gadget.speed) { 459 switch (dum->gadget.speed) {
460 case USB_SPEED_SUPER:
461 if (max == 1024)
462 break;
463 goto done;
364 case USB_SPEED_HIGH: 464 case USB_SPEED_HIGH:
365 if (max == 512) 465 if (max == 512)
366 break; 466 break;
@@ -379,6 +479,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
379 goto done; 479 goto done;
380 /* real hardware might not handle all packet sizes */ 480 /* real hardware might not handle all packet sizes */
381 switch (dum->gadget.speed) { 481 switch (dum->gadget.speed) {
482 case USB_SPEED_SUPER:
382 case USB_SPEED_HIGH: 483 case USB_SPEED_HIGH:
383 if (max <= 1024) 484 if (max <= 1024)
384 break; 485 break;
@@ -399,6 +500,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
399 goto done; 500 goto done;
400 /* real hardware might not handle all packet sizes */ 501 /* real hardware might not handle all packet sizes */
401 switch (dum->gadget.speed) { 502 switch (dum->gadget.speed) {
503 case USB_SPEED_SUPER:
402 case USB_SPEED_HIGH: 504 case USB_SPEED_HIGH:
403 if (max <= 1024) 505 if (max <= 1024)
404 break; 506 break;
@@ -425,10 +527,18 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
425 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 527 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
426 ({ char *val; 528 ({ char *val;
427 switch (desc->bmAttributes & 0x03) { 529 switch (desc->bmAttributes & 0x03) {
428 case USB_ENDPOINT_XFER_BULK: val = "bulk"; break; 530 case USB_ENDPOINT_XFER_BULK:
429 case USB_ENDPOINT_XFER_ISOC: val = "iso"; break; 531 val = "bulk";
430 case USB_ENDPOINT_XFER_INT: val = "intr"; break; 532 break;
431 default: val = "ctrl"; break; 533 case USB_ENDPOINT_XFER_ISOC:
534 val = "iso";
535 break;
536 case USB_ENDPOINT_XFER_INT:
537 val = "intr";
538 break;
539 default:
540 val = "ctrl";
541 break;
432 }; val; }), 542 }; val; }),
433 max); 543 max);
434 544
@@ -507,6 +617,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
507 struct dummy_ep *ep; 617 struct dummy_ep *ep;
508 struct dummy_request *req; 618 struct dummy_request *req;
509 struct dummy *dum; 619 struct dummy *dum;
620 struct dummy_hcd *dum_hcd;
510 unsigned long flags; 621 unsigned long flags;
511 622
512 req = usb_request_to_dummy_request (_req); 623 req = usb_request_to_dummy_request (_req);
@@ -518,7 +629,8 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
518 return -EINVAL; 629 return -EINVAL;
519 630
520 dum = ep_to_dummy (ep); 631 dum = ep_to_dummy (ep);
521 if (!dum->driver || !is_enabled (dum)) 632 dum_hcd = gadget_to_dummy_hcd(&dum->gadget);
633 if (!dum->driver || !is_enabled(dum_hcd))
522 return -ESHUTDOWN; 634 return -ESHUTDOWN;
523 635
524#if 0 636#if 0
@@ -662,24 +774,24 @@ static int dummy_g_get_frame (struct usb_gadget *_gadget)
662 774
663static int dummy_wakeup (struct usb_gadget *_gadget) 775static int dummy_wakeup (struct usb_gadget *_gadget)
664{ 776{
665 struct dummy *dum; 777 struct dummy_hcd *dum_hcd;
666 778
667 dum = gadget_to_dummy (_gadget); 779 dum_hcd = gadget_to_dummy_hcd(_gadget);
668 if (!(dum->devstatus & ( (1 << USB_DEVICE_B_HNP_ENABLE) 780 if (!(dum_hcd->dum->devstatus & ((1 << USB_DEVICE_B_HNP_ENABLE)
669 | (1 << USB_DEVICE_REMOTE_WAKEUP)))) 781 | (1 << USB_DEVICE_REMOTE_WAKEUP))))
670 return -EINVAL; 782 return -EINVAL;
671 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0) 783 if ((dum_hcd->port_status & USB_PORT_STAT_CONNECTION) == 0)
672 return -ENOLINK; 784 return -ENOLINK;
673 if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 && 785 if ((dum_hcd->port_status & USB_PORT_STAT_SUSPEND) == 0 &&
674 dum->rh_state != DUMMY_RH_SUSPENDED) 786 dum_hcd->rh_state != DUMMY_RH_SUSPENDED)
675 return -EIO; 787 return -EIO;
676 788
677 /* FIXME: What if the root hub is suspended but the port isn't? */ 789 /* FIXME: What if the root hub is suspended but the port isn't? */
678 790
679 /* hub notices our request, issues downstream resume, etc */ 791 /* hub notices our request, issues downstream resume, etc */
680 dum->resuming = 1; 792 dum_hcd->resuming = 1;
681 dum->re_timeout = jiffies + msecs_to_jiffies(20); 793 dum_hcd->re_timeout = jiffies + msecs_to_jiffies(20);
682 mod_timer (&dummy_to_hcd (dum)->rh_timer, dum->re_timeout); 794 mod_timer(&dummy_hcd_to_hcd(dum_hcd)->rh_timer, dum_hcd->re_timeout);
683 return 0; 795 return 0;
684} 796}
685 797
@@ -687,7 +799,7 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value)
687{ 799{
688 struct dummy *dum; 800 struct dummy *dum;
689 801
690 dum = gadget_to_dummy (_gadget); 802 dum = (gadget_to_dummy_hcd(_gadget))->dum;
691 if (value) 803 if (value)
692 dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED); 804 dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED);
693 else 805 else
@@ -695,26 +807,68 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value)
695 return 0; 807 return 0;
696} 808}
697 809
810static void dummy_udc_udpate_ep0(struct dummy *dum)
811{
812 u32 i;
813
814 if (dum->gadget.speed == USB_SPEED_SUPER) {
815 for (i = 0; i < DUMMY_ENDPOINTS; i++)
816 dum->ep[i].ep.max_streams = 0x10;
817 dum->ep[0].ep.maxpacket = 9;
818 } else {
819 for (i = 0; i < DUMMY_ENDPOINTS; i++)
820 dum->ep[i].ep.max_streams = 0;
821 dum->ep[0].ep.maxpacket = 64;
822 }
823}
824
698static int dummy_pullup (struct usb_gadget *_gadget, int value) 825static int dummy_pullup (struct usb_gadget *_gadget, int value)
699{ 826{
827 struct dummy_hcd *dum_hcd;
700 struct dummy *dum; 828 struct dummy *dum;
701 unsigned long flags; 829 unsigned long flags;
702 830
703 dum = gadget_to_dummy (_gadget); 831 dum = gadget_dev_to_dummy(&_gadget->dev);
832
833 if (value && dum->driver) {
834 if (mod_data.is_super_speed)
835 dum->gadget.speed = dum->driver->speed;
836 else if (mod_data.is_high_speed)
837 dum->gadget.speed = min_t(u8, USB_SPEED_HIGH,
838 dum->driver->speed);
839 else
840 dum->gadget.speed = USB_SPEED_FULL;
841 dummy_udc_udpate_ep0(dum);
842
843 if (dum->gadget.speed < dum->driver->speed)
844 dev_dbg(udc_dev(dum), "This device can perform faster"
845 " if you connect it to a %s port...\n",
846 (dum->driver->speed == USB_SPEED_SUPER ?
847 "SuperSpeed" : "HighSpeed"));
848 }
849 dum_hcd = gadget_to_dummy_hcd(_gadget);
850
704 spin_lock_irqsave (&dum->lock, flags); 851 spin_lock_irqsave (&dum->lock, flags);
705 dum->pullup = (value != 0); 852 dum->pullup = (value != 0);
706 set_link_state (dum); 853 set_link_state(dum_hcd);
707 spin_unlock_irqrestore (&dum->lock, flags); 854 spin_unlock_irqrestore (&dum->lock, flags);
708 855
709 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 856 usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd));
710 return 0; 857 return 0;
711} 858}
712 859
860static int dummy_udc_start(struct usb_gadget *g,
861 struct usb_gadget_driver *driver);
862static int dummy_udc_stop(struct usb_gadget *g,
863 struct usb_gadget_driver *driver);
864
713static const struct usb_gadget_ops dummy_ops = { 865static const struct usb_gadget_ops dummy_ops = {
714 .get_frame = dummy_g_get_frame, 866 .get_frame = dummy_g_get_frame,
715 .wakeup = dummy_wakeup, 867 .wakeup = dummy_wakeup,
716 .set_selfpowered = dummy_set_selfpowered, 868 .set_selfpowered = dummy_set_selfpowered,
717 .pullup = dummy_pullup, 869 .pullup = dummy_pullup,
870 .udc_start = dummy_udc_start,
871 .udc_stop = dummy_udc_stop,
718}; 872};
719 873
720/*-------------------------------------------------------------------------*/ 874/*-------------------------------------------------------------------------*/
@@ -747,18 +901,13 @@ static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
747 * for each driver that registers: just add to a big root hub. 901 * for each driver that registers: just add to a big root hub.
748 */ 902 */
749 903
750int 904static int dummy_udc_start(struct usb_gadget *g,
751usb_gadget_probe_driver(struct usb_gadget_driver *driver, 905 struct usb_gadget_driver *driver)
752 int (*bind)(struct usb_gadget *))
753{ 906{
754 struct dummy *dum = the_controller; 907 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
755 int retval, i; 908 struct dummy *dum = dum_hcd->dum;
756 909
757 if (!dum) 910 if (driver->speed == USB_SPEED_UNKNOWN)
758 return -EINVAL;
759 if (dum->driver)
760 return -EBUSY;
761 if (!bind || !driver->setup || driver->speed == USB_SPEED_UNKNOWN)
762 return -EINVAL; 911 return -EINVAL;
763 912
764 /* 913 /*
@@ -768,121 +917,77 @@ usb_gadget_probe_driver(struct usb_gadget_driver *driver,
768 917
769 dum->devstatus = 0; 918 dum->devstatus = 0;
770 919
771 INIT_LIST_HEAD (&dum->gadget.ep_list);
772 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
773 struct dummy_ep *ep = &dum->ep [i];
774
775 if (!ep_name [i])
776 break;
777 ep->ep.name = ep_name [i];
778 ep->ep.ops = &dummy_ep_ops;
779 list_add_tail (&ep->ep.ep_list, &dum->gadget.ep_list);
780 ep->halted = ep->wedged = ep->already_seen =
781 ep->setup_stage = 0;
782 ep->ep.maxpacket = ~0;
783 ep->last_io = jiffies;
784 ep->gadget = &dum->gadget;
785 ep->desc = NULL;
786 INIT_LIST_HEAD (&ep->queue);
787 }
788
789 dum->gadget.ep0 = &dum->ep [0].ep;
790 dum->ep [0].ep.maxpacket = 64;
791 list_del_init (&dum->ep [0].ep.ep_list);
792 INIT_LIST_HEAD(&dum->fifo_req.queue);
793
794 driver->driver.bus = NULL;
795 dum->driver = driver; 920 dum->driver = driver;
796 dum->gadget.dev.driver = &driver->driver;
797 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 921 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
798 driver->driver.name); 922 driver->driver.name);
799 retval = bind(&dum->gadget);
800 if (retval) {
801 dum->driver = NULL;
802 dum->gadget.dev.driver = NULL;
803 return retval;
804 }
805
806 /* khubd will enumerate this in a while */
807 spin_lock_irq (&dum->lock);
808 dum->pullup = 1;
809 set_link_state (dum);
810 spin_unlock_irq (&dum->lock);
811
812 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
813 return 0; 923 return 0;
814} 924}
815EXPORT_SYMBOL(usb_gadget_probe_driver);
816 925
817int 926static int dummy_udc_stop(struct usb_gadget *g,
818usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 927 struct usb_gadget_driver *driver)
819{ 928{
820 struct dummy *dum = the_controller; 929 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
821 unsigned long flags; 930 struct dummy *dum = dum_hcd->dum;
822
823 if (!dum)
824 return -ENODEV;
825 if (!driver || driver != dum->driver || !driver->unbind)
826 return -EINVAL;
827 931
828 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", 932 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
829 driver->driver.name); 933 driver->driver.name);
830 934
831 spin_lock_irqsave (&dum->lock, flags);
832 dum->pullup = 0;
833 set_link_state (dum);
834 spin_unlock_irqrestore (&dum->lock, flags);
835
836 driver->unbind (&dum->gadget);
837 dum->gadget.dev.driver = NULL;
838 dum->driver = NULL; 935 dum->driver = NULL;
839 936
840 spin_lock_irqsave (&dum->lock, flags); 937 dummy_pullup(&dum->gadget, 0);
841 dum->pullup = 0;
842 set_link_state (dum);
843 spin_unlock_irqrestore (&dum->lock, flags);
844
845 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
846 return 0; 938 return 0;
847} 939}
848EXPORT_SYMBOL (usb_gadget_unregister_driver);
849 940
850#undef is_enabled 941#undef is_enabled
851 942
852/* just declare this in any driver that really need it */
853extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
854
855int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode)
856{
857 return -ENOSYS;
858}
859EXPORT_SYMBOL (net2280_set_fifo_mode);
860
861
862/* The gadget structure is stored inside the hcd structure and will be 943/* The gadget structure is stored inside the hcd structure and will be
863 * released along with it. */ 944 * released along with it. */
864static void 945static void
865dummy_gadget_release (struct device *dev) 946dummy_gadget_release (struct device *dev)
866{ 947{
867 struct dummy *dum = gadget_dev_to_dummy (dev); 948 return;
949}
950
951static void init_dummy_udc_hw(struct dummy *dum)
952{
953 int i;
954
955 INIT_LIST_HEAD(&dum->gadget.ep_list);
956 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
957 struct dummy_ep *ep = &dum->ep[i];
958
959 if (!ep_name[i])
960 break;
961 ep->ep.name = ep_name[i];
962 ep->ep.ops = &dummy_ep_ops;
963 list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list);
964 ep->halted = ep->wedged = ep->already_seen =
965 ep->setup_stage = 0;
966 ep->ep.maxpacket = ~0;
967 ep->last_io = jiffies;
968 ep->gadget = &dum->gadget;
969 ep->desc = NULL;
970 INIT_LIST_HEAD(&ep->queue);
971 }
972
973 dum->gadget.ep0 = &dum->ep[0].ep;
974 list_del_init(&dum->ep[0].ep.ep_list);
975 INIT_LIST_HEAD(&dum->fifo_req.queue);
868 976
869 usb_put_hcd (dummy_to_hcd (dum)); 977#ifdef CONFIG_USB_OTG
978 dum->gadget.is_otg = 1;
979#endif
870} 980}
871 981
872static int dummy_udc_probe (struct platform_device *pdev) 982static int dummy_udc_probe (struct platform_device *pdev)
873{ 983{
874 struct dummy *dum = the_controller; 984 struct dummy *dum = &the_controller;
875 int rc; 985 int rc;
876 986
877 usb_get_hcd(dummy_to_hcd(dum));
878
879 dum->gadget.name = gadget_name; 987 dum->gadget.name = gadget_name;
880 dum->gadget.ops = &dummy_ops; 988 dum->gadget.ops = &dummy_ops;
881 dum->gadget.is_dualspeed = 1; 989 dum->gadget.is_dualspeed = 1;
882 990
883 /* maybe claim OTG support, though we won't complete HNP */
884 dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0);
885
886 dev_set_name(&dum->gadget.dev, "gadget"); 991 dev_set_name(&dum->gadget.dev, "gadget");
887 dum->gadget.dev.parent = &pdev->dev; 992 dum->gadget.dev.parent = &pdev->dev;
888 dum->gadget.dev.release = dummy_gadget_release; 993 dum->gadget.dev.release = dummy_gadget_release;
@@ -892,11 +997,22 @@ static int dummy_udc_probe (struct platform_device *pdev)
892 return rc; 997 return rc;
893 } 998 }
894 999
1000 init_dummy_udc_hw(dum);
1001
1002 rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget);
1003 if (rc < 0)
1004 goto err_udc;
1005
895 rc = device_create_file (&dum->gadget.dev, &dev_attr_function); 1006 rc = device_create_file (&dum->gadget.dev, &dev_attr_function);
896 if (rc < 0) 1007 if (rc < 0)
897 device_unregister (&dum->gadget.dev); 1008 goto err_dev;
898 else 1009 platform_set_drvdata(pdev, dum);
899 platform_set_drvdata(pdev, dum); 1010 return rc;
1011
1012err_dev:
1013 usb_del_gadget_udc(&dum->gadget);
1014err_udc:
1015 device_unregister(&dum->gadget.dev);
900 return rc; 1016 return rc;
901} 1017}
902 1018
@@ -904,37 +1020,41 @@ static int dummy_udc_remove (struct platform_device *pdev)
904{ 1020{
905 struct dummy *dum = platform_get_drvdata (pdev); 1021 struct dummy *dum = platform_get_drvdata (pdev);
906 1022
1023 usb_del_gadget_udc(&dum->gadget);
907 platform_set_drvdata (pdev, NULL); 1024 platform_set_drvdata (pdev, NULL);
908 device_remove_file (&dum->gadget.dev, &dev_attr_function); 1025 device_remove_file (&dum->gadget.dev, &dev_attr_function);
909 device_unregister (&dum->gadget.dev); 1026 device_unregister (&dum->gadget.dev);
910 return 0; 1027 return 0;
911} 1028}
912 1029
913static int dummy_udc_suspend (struct platform_device *pdev, pm_message_t state) 1030static void dummy_udc_pm(struct dummy *dum, struct dummy_hcd *dum_hcd,
1031 int suspend)
914{ 1032{
915 struct dummy *dum = platform_get_drvdata(pdev); 1033 spin_lock_irq(&dum->lock);
1034 dum->udc_suspended = suspend;
1035 set_link_state(dum_hcd);
1036 spin_unlock_irq(&dum->lock);
1037}
916 1038
917 dev_dbg (&pdev->dev, "%s\n", __func__); 1039static int dummy_udc_suspend(struct platform_device *pdev, pm_message_t state)
918 spin_lock_irq (&dum->lock); 1040{
919 dum->udc_suspended = 1; 1041 struct dummy *dum = platform_get_drvdata(pdev);
920 set_link_state (dum); 1042 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(&dum->gadget);
921 spin_unlock_irq (&dum->lock);
922 1043
923 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 1044 dev_dbg(&pdev->dev, "%s\n", __func__);
1045 dummy_udc_pm(dum, dum_hcd, 1);
1046 usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd));
924 return 0; 1047 return 0;
925} 1048}
926 1049
927static int dummy_udc_resume (struct platform_device *pdev) 1050static int dummy_udc_resume(struct platform_device *pdev)
928{ 1051{
929 struct dummy *dum = platform_get_drvdata(pdev); 1052 struct dummy *dum = platform_get_drvdata(pdev);
1053 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(&dum->gadget);
930 1054
931 dev_dbg (&pdev->dev, "%s\n", __func__); 1055 dev_dbg(&pdev->dev, "%s\n", __func__);
932 spin_lock_irq (&dum->lock); 1056 dummy_udc_pm(dum, dum_hcd, 0);
933 dum->udc_suspended = 0; 1057 usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd));
934 set_link_state (dum);
935 spin_unlock_irq (&dum->lock);
936
937 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
938 return 0; 1058 return 0;
939} 1059}
940 1060
@@ -968,7 +1088,7 @@ static int dummy_urb_enqueue (
968 struct urb *urb, 1088 struct urb *urb,
969 gfp_t mem_flags 1089 gfp_t mem_flags
970) { 1090) {
971 struct dummy *dum; 1091 struct dummy_hcd *dum_hcd;
972 struct urbp *urbp; 1092 struct urbp *urbp;
973 unsigned long flags; 1093 unsigned long flags;
974 int rc; 1094 int rc;
@@ -981,51 +1101,51 @@ static int dummy_urb_enqueue (
981 return -ENOMEM; 1101 return -ENOMEM;
982 urbp->urb = urb; 1102 urbp->urb = urb;
983 1103
984 dum = hcd_to_dummy (hcd); 1104 dum_hcd = hcd_to_dummy_hcd(hcd);
985 spin_lock_irqsave (&dum->lock, flags); 1105 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
986 rc = usb_hcd_link_urb_to_ep(hcd, urb); 1106 rc = usb_hcd_link_urb_to_ep(hcd, urb);
987 if (rc) { 1107 if (rc) {
988 kfree(urbp); 1108 kfree(urbp);
989 goto done; 1109 goto done;
990 } 1110 }
991 1111
992 if (!dum->udev) { 1112 if (!dum_hcd->udev) {
993 dum->udev = urb->dev; 1113 dum_hcd->udev = urb->dev;
994 usb_get_dev (dum->udev); 1114 usb_get_dev(dum_hcd->udev);
995 } else if (unlikely (dum->udev != urb->dev)) 1115 } else if (unlikely(dum_hcd->udev != urb->dev))
996 dev_err (dummy_dev(dum), "usb_device address has changed!\n"); 1116 dev_err(dummy_dev(dum_hcd), "usb_device address has changed!\n");
997 1117
998 list_add_tail (&urbp->urbp_list, &dum->urbp_list); 1118 list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list);
999 urb->hcpriv = urbp; 1119 urb->hcpriv = urbp;
1000 if (usb_pipetype (urb->pipe) == PIPE_CONTROL) 1120 if (usb_pipetype (urb->pipe) == PIPE_CONTROL)
1001 urb->error_count = 1; /* mark as a new urb */ 1121 urb->error_count = 1; /* mark as a new urb */
1002 1122
1003 /* kick the scheduler, it'll do the rest */ 1123 /* kick the scheduler, it'll do the rest */
1004 if (!timer_pending (&dum->timer)) 1124 if (!timer_pending(&dum_hcd->timer))
1005 mod_timer (&dum->timer, jiffies + 1); 1125 mod_timer(&dum_hcd->timer, jiffies + 1);
1006 1126
1007 done: 1127 done:
1008 spin_unlock_irqrestore(&dum->lock, flags); 1128 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1009 return rc; 1129 return rc;
1010} 1130}
1011 1131
1012static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 1132static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1013{ 1133{
1014 struct dummy *dum; 1134 struct dummy_hcd *dum_hcd;
1015 unsigned long flags; 1135 unsigned long flags;
1016 int rc; 1136 int rc;
1017 1137
1018 /* giveback happens automatically in timer callback, 1138 /* giveback happens automatically in timer callback,
1019 * so make sure the callback happens */ 1139 * so make sure the callback happens */
1020 dum = hcd_to_dummy (hcd); 1140 dum_hcd = hcd_to_dummy_hcd(hcd);
1021 spin_lock_irqsave (&dum->lock, flags); 1141 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1022 1142
1023 rc = usb_hcd_check_unlink_urb(hcd, urb, status); 1143 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1024 if (!rc && dum->rh_state != DUMMY_RH_RUNNING && 1144 if (!rc && dum_hcd->rh_state != DUMMY_RH_RUNNING &&
1025 !list_empty(&dum->urbp_list)) 1145 !list_empty(&dum_hcd->urbp_list))
1026 mod_timer (&dum->timer, jiffies); 1146 mod_timer(&dum_hcd->timer, jiffies);
1027 1147
1028 spin_unlock_irqrestore (&dum->lock, flags); 1148 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1029 return rc; 1149 return rc;
1030} 1150}
1031 1151
@@ -1162,10 +1282,25 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1162 tmp *= 8 /* applies to entire frame */; 1282 tmp *= 8 /* applies to entire frame */;
1163 limit += limit * tmp; 1283 limit += limit * tmp;
1164 } 1284 }
1285 if (dum->gadget.speed == USB_SPEED_SUPER) {
1286 switch (ep->desc->bmAttributes & 0x03) {
1287 case USB_ENDPOINT_XFER_ISOC:
1288 /* Sec. 4.4.8.2 USB3.0 Spec */
1289 limit = 3 * 16 * 1024 * 8;
1290 break;
1291 case USB_ENDPOINT_XFER_INT:
1292 /* Sec. 4.4.7.2 USB3.0 Spec */
1293 limit = 3 * 1024 * 8;
1294 break;
1295 case USB_ENDPOINT_XFER_BULK:
1296 default:
1297 break;
1298 }
1299 }
1165 return limit; 1300 return limit;
1166} 1301}
1167 1302
1168#define is_active(dum) ((dum->port_status & \ 1303#define is_active(dum_hcd) ((dum_hcd->port_status & \
1169 (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | \ 1304 (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | \
1170 USB_PORT_STAT_SUSPEND)) \ 1305 USB_PORT_STAT_SUSPEND)) \
1171 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE)) 1306 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE))
@@ -1174,7 +1309,8 @@ static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address)
1174{ 1309{
1175 int i; 1310 int i;
1176 1311
1177 if (!is_active (dum)) 1312 if (!is_active((dum->gadget.speed == USB_SPEED_SUPER ?
1313 dum->ss_hcd : dum->hs_hcd)))
1178 return NULL; 1314 return NULL;
1179 if ((address & ~USB_DIR_IN) == 0) 1315 if ((address & ~USB_DIR_IN) == 0)
1180 return &dum->ep [0]; 1316 return &dum->ep [0];
@@ -1211,11 +1347,12 @@ static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address)
1211 * 1 - if the request wasn't handles 1347 * 1 - if the request wasn't handles
1212 * error code on error 1348 * error code on error
1213 */ 1349 */
1214static int handle_control_request(struct dummy *dum, struct urb *urb, 1350static int handle_control_request(struct dummy_hcd *dum_hcd, struct urb *urb,
1215 struct usb_ctrlrequest *setup, 1351 struct usb_ctrlrequest *setup,
1216 int *status) 1352 int *status)
1217{ 1353{
1218 struct dummy_ep *ep2; 1354 struct dummy_ep *ep2;
1355 struct dummy *dum = dum_hcd->dum;
1219 int ret_val = 1; 1356 int ret_val = 1;
1220 unsigned w_index; 1357 unsigned w_index;
1221 unsigned w_value; 1358 unsigned w_value;
@@ -1247,6 +1384,27 @@ static int handle_control_request(struct dummy *dum, struct urb *urb,
1247 case USB_DEVICE_A_ALT_HNP_SUPPORT: 1384 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1248 dum->gadget.a_alt_hnp_support = 1; 1385 dum->gadget.a_alt_hnp_support = 1;
1249 break; 1386 break;
1387 case USB_DEVICE_U1_ENABLE:
1388 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1389 HCD_USB3)
1390 w_value = USB_DEV_STAT_U1_ENABLED;
1391 else
1392 ret_val = -EOPNOTSUPP;
1393 break;
1394 case USB_DEVICE_U2_ENABLE:
1395 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1396 HCD_USB3)
1397 w_value = USB_DEV_STAT_U2_ENABLED;
1398 else
1399 ret_val = -EOPNOTSUPP;
1400 break;
1401 case USB_DEVICE_LTM_ENABLE:
1402 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1403 HCD_USB3)
1404 w_value = USB_DEV_STAT_LTM_ENABLED;
1405 else
1406 ret_val = -EOPNOTSUPP;
1407 break;
1250 default: 1408 default:
1251 ret_val = -EOPNOTSUPP; 1409 ret_val = -EOPNOTSUPP;
1252 } 1410 }
@@ -1273,6 +1431,27 @@ static int handle_control_request(struct dummy *dum, struct urb *urb,
1273 case USB_DEVICE_REMOTE_WAKEUP: 1431 case USB_DEVICE_REMOTE_WAKEUP:
1274 w_value = USB_DEVICE_REMOTE_WAKEUP; 1432 w_value = USB_DEVICE_REMOTE_WAKEUP;
1275 break; 1433 break;
1434 case USB_DEVICE_U1_ENABLE:
1435 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1436 HCD_USB3)
1437 w_value = USB_DEV_STAT_U1_ENABLED;
1438 else
1439 ret_val = -EOPNOTSUPP;
1440 break;
1441 case USB_DEVICE_U2_ENABLE:
1442 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1443 HCD_USB3)
1444 w_value = USB_DEV_STAT_U2_ENABLED;
1445 else
1446 ret_val = -EOPNOTSUPP;
1447 break;
1448 case USB_DEVICE_LTM_ENABLE:
1449 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1450 HCD_USB3)
1451 w_value = USB_DEV_STAT_LTM_ENABLED;
1452 else
1453 ret_val = -EOPNOTSUPP;
1454 break;
1276 default: 1455 default:
1277 ret_val = -EOPNOTSUPP; 1456 ret_val = -EOPNOTSUPP;
1278 break; 1457 break;
@@ -1334,9 +1513,10 @@ static int handle_control_request(struct dummy *dum, struct urb *urb,
1334/* drive both sides of the transfers; looks like irq handlers to 1513/* drive both sides of the transfers; looks like irq handlers to
1335 * both drivers except the callbacks aren't in_irq(). 1514 * both drivers except the callbacks aren't in_irq().
1336 */ 1515 */
1337static void dummy_timer (unsigned long _dum) 1516static void dummy_timer(unsigned long _dum_hcd)
1338{ 1517{
1339 struct dummy *dum = (struct dummy *) _dum; 1518 struct dummy_hcd *dum_hcd = (struct dummy_hcd *) _dum_hcd;
1519 struct dummy *dum = dum_hcd->dum;
1340 struct urbp *urbp, *tmp; 1520 struct urbp *urbp, *tmp;
1341 unsigned long flags; 1521 unsigned long flags;
1342 int limit, total; 1522 int limit, total;
@@ -1353,8 +1533,12 @@ static void dummy_timer (unsigned long _dum)
1353 case USB_SPEED_HIGH: 1533 case USB_SPEED_HIGH:
1354 total = 512/*bytes*/ * 13/*packets*/ * 8/*uframes*/; 1534 total = 512/*bytes*/ * 13/*packets*/ * 8/*uframes*/;
1355 break; 1535 break;
1536 case USB_SPEED_SUPER:
1537 /* Bus speed is 500000 bytes/ms, so use a little less */
1538 total = 490000;
1539 break;
1356 default: 1540 default:
1357 dev_err (dummy_dev(dum), "bogus device speed\n"); 1541 dev_err(dummy_dev(dum_hcd), "bogus device speed\n");
1358 return; 1542 return;
1359 } 1543 }
1360 1544
@@ -1363,8 +1547,8 @@ static void dummy_timer (unsigned long _dum)
1363 /* look at each urb queued by the host side driver */ 1547 /* look at each urb queued by the host side driver */
1364 spin_lock_irqsave (&dum->lock, flags); 1548 spin_lock_irqsave (&dum->lock, flags);
1365 1549
1366 if (!dum->udev) { 1550 if (!dum_hcd->udev) {
1367 dev_err (dummy_dev(dum), 1551 dev_err(dummy_dev(dum_hcd),
1368 "timer fired with no URBs pending?\n"); 1552 "timer fired with no URBs pending?\n");
1369 spin_unlock_irqrestore (&dum->lock, flags); 1553 spin_unlock_irqrestore (&dum->lock, flags);
1370 return; 1554 return;
@@ -1377,7 +1561,7 @@ static void dummy_timer (unsigned long _dum)
1377 } 1561 }
1378 1562
1379restart: 1563restart:
1380 list_for_each_entry_safe (urbp, tmp, &dum->urbp_list, urbp_list) { 1564 list_for_each_entry_safe(urbp, tmp, &dum_hcd->urbp_list, urbp_list) {
1381 struct urb *urb; 1565 struct urb *urb;
1382 struct dummy_request *req; 1566 struct dummy_request *req;
1383 u8 address; 1567 u8 address;
@@ -1388,7 +1572,7 @@ restart:
1388 urb = urbp->urb; 1572 urb = urbp->urb;
1389 if (urb->unlinked) 1573 if (urb->unlinked)
1390 goto return_urb; 1574 goto return_urb;
1391 else if (dum->rh_state != DUMMY_RH_RUNNING) 1575 else if (dum_hcd->rh_state != DUMMY_RH_RUNNING)
1392 continue; 1576 continue;
1393 type = usb_pipetype (urb->pipe); 1577 type = usb_pipetype (urb->pipe);
1394 1578
@@ -1406,7 +1590,7 @@ restart:
1406 ep = find_endpoint(dum, address); 1590 ep = find_endpoint(dum, address);
1407 if (!ep) { 1591 if (!ep) {
1408 /* set_configuration() disagreement */ 1592 /* set_configuration() disagreement */
1409 dev_dbg (dummy_dev(dum), 1593 dev_dbg(dummy_dev(dum_hcd),
1410 "no ep configured for urb %p\n", 1594 "no ep configured for urb %p\n",
1411 urb); 1595 urb);
1412 status = -EPROTO; 1596 status = -EPROTO;
@@ -1422,7 +1606,7 @@ restart:
1422 } 1606 }
1423 if (ep->halted && !ep->setup_stage) { 1607 if (ep->halted && !ep->setup_stage) {
1424 /* NOTE: must not be iso! */ 1608 /* NOTE: must not be iso! */
1425 dev_dbg (dummy_dev(dum), "ep %s halted, urb %p\n", 1609 dev_dbg(dummy_dev(dum_hcd), "ep %s halted, urb %p\n",
1426 ep->ep.name, urb); 1610 ep->ep.name, urb);
1427 status = -EPIPE; 1611 status = -EPIPE;
1428 goto return_urb; 1612 goto return_urb;
@@ -1457,7 +1641,7 @@ restart:
1457 ep->setup_stage = 0; 1641 ep->setup_stage = 0;
1458 ep->halted = 0; 1642 ep->halted = 0;
1459 1643
1460 value = handle_control_request(dum, urb, &setup, 1644 value = handle_control_request(dum_hcd, urb, &setup,
1461 &status); 1645 &status);
1462 1646
1463 /* gadget driver handles all other requests. block 1647 /* gadget driver handles all other requests. block
@@ -1527,20 +1711,20 @@ return_urb:
1527 if (ep) 1711 if (ep)
1528 ep->already_seen = ep->setup_stage = 0; 1712 ep->already_seen = ep->setup_stage = 0;
1529 1713
1530 usb_hcd_unlink_urb_from_ep(dummy_to_hcd(dum), urb); 1714 usb_hcd_unlink_urb_from_ep(dummy_hcd_to_hcd(dum_hcd), urb);
1531 spin_unlock (&dum->lock); 1715 spin_unlock (&dum->lock);
1532 usb_hcd_giveback_urb(dummy_to_hcd(dum), urb, status); 1716 usb_hcd_giveback_urb(dummy_hcd_to_hcd(dum_hcd), urb, status);
1533 spin_lock (&dum->lock); 1717 spin_lock (&dum->lock);
1534 1718
1535 goto restart; 1719 goto restart;
1536 } 1720 }
1537 1721
1538 if (list_empty (&dum->urbp_list)) { 1722 if (list_empty(&dum_hcd->urbp_list)) {
1539 usb_put_dev (dum->udev); 1723 usb_put_dev(dum_hcd->udev);
1540 dum->udev = NULL; 1724 dum_hcd->udev = NULL;
1541 } else if (dum->rh_state == DUMMY_RH_RUNNING) { 1725 } else if (dum_hcd->rh_state == DUMMY_RH_RUNNING) {
1542 /* want a 1 msec delay here */ 1726 /* want a 1 msec delay here */
1543 mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1)); 1727 mod_timer(&dum_hcd->timer, jiffies + msecs_to_jiffies(1));
1544 } 1728 }
1545 1729
1546 spin_unlock_irqrestore (&dum->lock, flags); 1730 spin_unlock_irqrestore (&dum->lock, flags);
@@ -1557,36 +1741,48 @@ return_urb:
1557 1741
1558static int dummy_hub_status (struct usb_hcd *hcd, char *buf) 1742static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1559{ 1743{
1560 struct dummy *dum; 1744 struct dummy_hcd *dum_hcd;
1561 unsigned long flags; 1745 unsigned long flags;
1562 int retval = 0; 1746 int retval = 0;
1563 1747
1564 dum = hcd_to_dummy (hcd); 1748 dum_hcd = hcd_to_dummy_hcd(hcd);
1565 1749
1566 spin_lock_irqsave (&dum->lock, flags); 1750 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1567 if (!HCD_HW_ACCESSIBLE(hcd)) 1751 if (!HCD_HW_ACCESSIBLE(hcd))
1568 goto done; 1752 goto done;
1569 1753
1570 if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { 1754 if (dum_hcd->resuming && time_after_eq(jiffies, dum_hcd->re_timeout)) {
1571 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); 1755 dum_hcd->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1572 dum->port_status &= ~USB_PORT_STAT_SUSPEND; 1756 dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND;
1573 set_link_state (dum); 1757 set_link_state(dum_hcd);
1574 } 1758 }
1575 1759
1576 if ((dum->port_status & PORT_C_MASK) != 0) { 1760 if ((dum_hcd->port_status & PORT_C_MASK) != 0) {
1577 *buf = (1 << 1); 1761 *buf = (1 << 1);
1578 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n", 1762 dev_dbg(dummy_dev(dum_hcd), "port status 0x%08x has changes\n",
1579 dum->port_status); 1763 dum_hcd->port_status);
1580 retval = 1; 1764 retval = 1;
1581 if (dum->rh_state == DUMMY_RH_SUSPENDED) 1765 if (dum_hcd->rh_state == DUMMY_RH_SUSPENDED)
1582 usb_hcd_resume_root_hub (hcd); 1766 usb_hcd_resume_root_hub (hcd);
1583 } 1767 }
1584done: 1768done:
1585 spin_unlock_irqrestore (&dum->lock, flags); 1769 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1586 return retval; 1770 return retval;
1587} 1771}
1588 1772
1589static inline void 1773static inline void
1774ss_hub_descriptor(struct usb_hub_descriptor *desc)
1775{
1776 memset(desc, 0, sizeof *desc);
1777 desc->bDescriptorType = 0x2a;
1778 desc->bDescLength = 12;
1779 desc->wHubCharacteristics = cpu_to_le16(0x0001);
1780 desc->bNbrPorts = 1;
1781 desc->u.ss.bHubHdrDecLat = 0x04; /* Worst case: 0.4 micro sec*/
1782 desc->u.ss.DeviceRemovable = 0xffff;
1783}
1784
1785static inline void
1590hub_descriptor (struct usb_hub_descriptor *desc) 1786hub_descriptor (struct usb_hub_descriptor *desc)
1591{ 1787{
1592 memset (desc, 0, sizeof *desc); 1788 memset (desc, 0, sizeof *desc);
@@ -1606,39 +1802,64 @@ static int dummy_hub_control (
1606 char *buf, 1802 char *buf,
1607 u16 wLength 1803 u16 wLength
1608) { 1804) {
1609 struct dummy *dum; 1805 struct dummy_hcd *dum_hcd;
1610 int retval = 0; 1806 int retval = 0;
1611 unsigned long flags; 1807 unsigned long flags;
1612 1808
1613 if (!HCD_HW_ACCESSIBLE(hcd)) 1809 if (!HCD_HW_ACCESSIBLE(hcd))
1614 return -ETIMEDOUT; 1810 return -ETIMEDOUT;
1615 1811
1616 dum = hcd_to_dummy (hcd); 1812 dum_hcd = hcd_to_dummy_hcd(hcd);
1617 spin_lock_irqsave (&dum->lock, flags); 1813
1814 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1618 switch (typeReq) { 1815 switch (typeReq) {
1619 case ClearHubFeature: 1816 case ClearHubFeature:
1620 break; 1817 break;
1621 case ClearPortFeature: 1818 case ClearPortFeature:
1622 switch (wValue) { 1819 switch (wValue) {
1623 case USB_PORT_FEAT_SUSPEND: 1820 case USB_PORT_FEAT_SUSPEND:
1624 if (dum->port_status & USB_PORT_STAT_SUSPEND) { 1821 if (hcd->speed == HCD_USB3) {
1822 dev_dbg(dummy_dev(dum_hcd),
1823 "USB_PORT_FEAT_SUSPEND req not "
1824 "supported for USB 3.0 roothub\n");
1825 goto error;
1826 }
1827 if (dum_hcd->port_status & USB_PORT_STAT_SUSPEND) {
1625 /* 20msec resume signaling */ 1828 /* 20msec resume signaling */
1626 dum->resuming = 1; 1829 dum_hcd->resuming = 1;
1627 dum->re_timeout = jiffies + 1830 dum_hcd->re_timeout = jiffies +
1628 msecs_to_jiffies(20); 1831 msecs_to_jiffies(20);
1629 } 1832 }
1630 break; 1833 break;
1631 case USB_PORT_FEAT_POWER: 1834 case USB_PORT_FEAT_POWER:
1632 if (dum->port_status & USB_PORT_STAT_POWER) 1835 if (hcd->speed == HCD_USB3) {
1633 dev_dbg (dummy_dev(dum), "power-off\n"); 1836 if (dum_hcd->port_status & USB_PORT_STAT_POWER)
1837 dev_dbg(dummy_dev(dum_hcd),
1838 "power-off\n");
1839 } else
1840 if (dum_hcd->port_status &
1841 USB_SS_PORT_STAT_POWER)
1842 dev_dbg(dummy_dev(dum_hcd),
1843 "power-off\n");
1634 /* FALLS THROUGH */ 1844 /* FALLS THROUGH */
1635 default: 1845 default:
1636 dum->port_status &= ~(1 << wValue); 1846 dum_hcd->port_status &= ~(1 << wValue);
1637 set_link_state (dum); 1847 set_link_state(dum_hcd);
1638 } 1848 }
1639 break; 1849 break;
1640 case GetHubDescriptor: 1850 case GetHubDescriptor:
1641 hub_descriptor ((struct usb_hub_descriptor *) buf); 1851 if (hcd->speed == HCD_USB3 &&
1852 (wLength < USB_DT_SS_HUB_SIZE ||
1853 wValue != (USB_DT_SS_HUB << 8))) {
1854 dev_dbg(dummy_dev(dum_hcd),
1855 "Wrong hub descriptor type for "
1856 "USB 3.0 roothub.\n");
1857 goto error;
1858 }
1859 if (hcd->speed == HCD_USB3)
1860 ss_hub_descriptor((struct usb_hub_descriptor *) buf);
1861 else
1862 hub_descriptor((struct usb_hub_descriptor *) buf);
1642 break; 1863 break;
1643 case GetHubStatus: 1864 case GetHubStatus:
1644 *(__le32 *) buf = cpu_to_le32 (0); 1865 *(__le32 *) buf = cpu_to_le32 (0);
@@ -1650,127 +1871,210 @@ static int dummy_hub_control (
1650 /* whoever resets or resumes must GetPortStatus to 1871 /* whoever resets or resumes must GetPortStatus to
1651 * complete it!! 1872 * complete it!!
1652 */ 1873 */
1653 if (dum->resuming && 1874 if (dum_hcd->resuming &&
1654 time_after_eq (jiffies, dum->re_timeout)) { 1875 time_after_eq(jiffies, dum_hcd->re_timeout)) {
1655 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); 1876 dum_hcd->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1656 dum->port_status &= ~USB_PORT_STAT_SUSPEND; 1877 dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND;
1657 } 1878 }
1658 if ((dum->port_status & USB_PORT_STAT_RESET) != 0 && 1879 if ((dum_hcd->port_status & USB_PORT_STAT_RESET) != 0 &&
1659 time_after_eq (jiffies, dum->re_timeout)) { 1880 time_after_eq(jiffies, dum_hcd->re_timeout)) {
1660 dum->port_status |= (USB_PORT_STAT_C_RESET << 16); 1881 dum_hcd->port_status |= (USB_PORT_STAT_C_RESET << 16);
1661 dum->port_status &= ~USB_PORT_STAT_RESET; 1882 dum_hcd->port_status &= ~USB_PORT_STAT_RESET;
1662 if (dum->pullup) { 1883 if (dum_hcd->dum->pullup) {
1663 dum->port_status |= USB_PORT_STAT_ENABLE; 1884 dum_hcd->port_status |= USB_PORT_STAT_ENABLE;
1664 /* give it the best speed we agree on */ 1885
1665 dum->gadget.speed = dum->driver->speed; 1886 if (hcd->speed < HCD_USB3) {
1666 dum->gadget.ep0->maxpacket = 64; 1887 switch (dum_hcd->dum->gadget.speed) {
1667 switch (dum->gadget.speed) { 1888 case USB_SPEED_HIGH:
1668 case USB_SPEED_HIGH: 1889 dum_hcd->port_status |=
1669 dum->port_status |= 1890 USB_PORT_STAT_HIGH_SPEED;
1670 USB_PORT_STAT_HIGH_SPEED; 1891 break;
1671 break; 1892 case USB_SPEED_LOW:
1672 case USB_SPEED_LOW: 1893 dum_hcd->dum->gadget.ep0->
1673 dum->gadget.ep0->maxpacket = 8; 1894 maxpacket = 8;
1674 dum->port_status |= 1895 dum_hcd->port_status |=
1675 USB_PORT_STAT_LOW_SPEED; 1896 USB_PORT_STAT_LOW_SPEED;
1676 break; 1897 break;
1677 default: 1898 default:
1678 dum->gadget.speed = USB_SPEED_FULL; 1899 dum_hcd->dum->gadget.speed =
1679 break; 1900 USB_SPEED_FULL;
1901 break;
1902 }
1680 } 1903 }
1681 } 1904 }
1682 } 1905 }
1683 set_link_state (dum); 1906 set_link_state(dum_hcd);
1684 ((__le16 *) buf)[0] = cpu_to_le16 (dum->port_status); 1907 ((__le16 *) buf)[0] = cpu_to_le16 (dum_hcd->port_status);
1685 ((__le16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); 1908 ((__le16 *) buf)[1] = cpu_to_le16 (dum_hcd->port_status >> 16);
1686 break; 1909 break;
1687 case SetHubFeature: 1910 case SetHubFeature:
1688 retval = -EPIPE; 1911 retval = -EPIPE;
1689 break; 1912 break;
1690 case SetPortFeature: 1913 case SetPortFeature:
1691 switch (wValue) { 1914 switch (wValue) {
1915 case USB_PORT_FEAT_LINK_STATE:
1916 if (hcd->speed != HCD_USB3) {
1917 dev_dbg(dummy_dev(dum_hcd),
1918 "USB_PORT_FEAT_LINK_STATE req not "
1919 "supported for USB 2.0 roothub\n");
1920 goto error;
1921 }
1922 /*
1923 * Since this is dummy we don't have an actual link so
1924 * there is nothing to do for the SET_LINK_STATE cmd
1925 */
1926 break;
1927 case USB_PORT_FEAT_U1_TIMEOUT:
1928 case USB_PORT_FEAT_U2_TIMEOUT:
1929 /* TODO: add suspend/resume support! */
1930 if (hcd->speed != HCD_USB3) {
1931 dev_dbg(dummy_dev(dum_hcd),
1932 "USB_PORT_FEAT_U1/2_TIMEOUT req not "
1933 "supported for USB 2.0 roothub\n");
1934 goto error;
1935 }
1936 break;
1692 case USB_PORT_FEAT_SUSPEND: 1937 case USB_PORT_FEAT_SUSPEND:
1693 if (dum->active) { 1938 /* Applicable only for USB2.0 hub */
1694 dum->port_status |= USB_PORT_STAT_SUSPEND; 1939 if (hcd->speed == HCD_USB3) {
1940 dev_dbg(dummy_dev(dum_hcd),
1941 "USB_PORT_FEAT_SUSPEND req not "
1942 "supported for USB 3.0 roothub\n");
1943 goto error;
1944 }
1945 if (dum_hcd->active) {
1946 dum_hcd->port_status |= USB_PORT_STAT_SUSPEND;
1695 1947
1696 /* HNP would happen here; for now we 1948 /* HNP would happen here; for now we
1697 * assume b_bus_req is always true. 1949 * assume b_bus_req is always true.
1698 */ 1950 */
1699 set_link_state (dum); 1951 set_link_state(dum_hcd);
1700 if (((1 << USB_DEVICE_B_HNP_ENABLE) 1952 if (((1 << USB_DEVICE_B_HNP_ENABLE)
1701 & dum->devstatus) != 0) 1953 & dum_hcd->dum->devstatus) != 0)
1702 dev_dbg (dummy_dev(dum), 1954 dev_dbg(dummy_dev(dum_hcd),
1703 "no HNP yet!\n"); 1955 "no HNP yet!\n");
1704 } 1956 }
1705 break; 1957 break;
1706 case USB_PORT_FEAT_POWER: 1958 case USB_PORT_FEAT_POWER:
1707 dum->port_status |= USB_PORT_STAT_POWER; 1959 if (hcd->speed == HCD_USB3)
1708 set_link_state (dum); 1960 dum_hcd->port_status |= USB_SS_PORT_STAT_POWER;
1961 else
1962 dum_hcd->port_status |= USB_PORT_STAT_POWER;
1963 set_link_state(dum_hcd);
1709 break; 1964 break;
1965 case USB_PORT_FEAT_BH_PORT_RESET:
1966 /* Applicable only for USB3.0 hub */
1967 if (hcd->speed != HCD_USB3) {
1968 dev_dbg(dummy_dev(dum_hcd),
1969 "USB_PORT_FEAT_BH_PORT_RESET req not "
1970 "supported for USB 2.0 roothub\n");
1971 goto error;
1972 }
1973 /* FALLS THROUGH */
1710 case USB_PORT_FEAT_RESET: 1974 case USB_PORT_FEAT_RESET:
1711 /* if it's already enabled, disable */ 1975 /* if it's already enabled, disable */
1712 dum->port_status &= ~(USB_PORT_STAT_ENABLE 1976 if (hcd->speed == HCD_USB3) {
1977 dum_hcd->port_status = 0;
1978 dum_hcd->port_status =
1979 (USB_SS_PORT_STAT_POWER |
1980 USB_PORT_STAT_CONNECTION |
1981 USB_PORT_STAT_RESET);
1982 } else
1983 dum_hcd->port_status &= ~(USB_PORT_STAT_ENABLE
1713 | USB_PORT_STAT_LOW_SPEED 1984 | USB_PORT_STAT_LOW_SPEED
1714 | USB_PORT_STAT_HIGH_SPEED); 1985 | USB_PORT_STAT_HIGH_SPEED);
1715 dum->devstatus = 0; 1986 /*
1716 /* 50msec reset signaling */ 1987 * We want to reset device status. All but the
1717 dum->re_timeout = jiffies + msecs_to_jiffies(50); 1988 * Self powered feature
1989 */
1990 dum_hcd->dum->devstatus &=
1991 (1 << USB_DEVICE_SELF_POWERED);
1992 /*
1993 * FIXME USB3.0: what is the correct reset signaling
1994 * interval? Is it still 50msec as for HS?
1995 */
1996 dum_hcd->re_timeout = jiffies + msecs_to_jiffies(50);
1718 /* FALLS THROUGH */ 1997 /* FALLS THROUGH */
1719 default: 1998 default:
1720 if ((dum->port_status & USB_PORT_STAT_POWER) != 0) { 1999 if (hcd->speed == HCD_USB3) {
1721 dum->port_status |= (1 << wValue); 2000 if ((dum_hcd->port_status &
1722 set_link_state (dum); 2001 USB_SS_PORT_STAT_POWER) != 0) {
1723 } 2002 dum_hcd->port_status |= (1 << wValue);
2003 set_link_state(dum_hcd);
2004 }
2005 } else
2006 if ((dum_hcd->port_status &
2007 USB_PORT_STAT_POWER) != 0) {
2008 dum_hcd->port_status |= (1 << wValue);
2009 set_link_state(dum_hcd);
2010 }
2011 }
2012 break;
2013 case GetPortErrorCount:
2014 if (hcd->speed != HCD_USB3) {
2015 dev_dbg(dummy_dev(dum_hcd),
2016 "GetPortErrorCount req not "
2017 "supported for USB 2.0 roothub\n");
2018 goto error;
2019 }
2020 /* We'll always return 0 since this is a dummy hub */
2021 *(__le32 *) buf = cpu_to_le32(0);
2022 break;
2023 case SetHubDepth:
2024 if (hcd->speed != HCD_USB3) {
2025 dev_dbg(dummy_dev(dum_hcd),
2026 "SetHubDepth req not supported for "
2027 "USB 2.0 roothub\n");
2028 goto error;
1724 } 2029 }
1725 break; 2030 break;
1726
1727 default: 2031 default:
1728 dev_dbg (dummy_dev(dum), 2032 dev_dbg(dummy_dev(dum_hcd),
1729 "hub control req%04x v%04x i%04x l%d\n", 2033 "hub control req%04x v%04x i%04x l%d\n",
1730 typeReq, wValue, wIndex, wLength); 2034 typeReq, wValue, wIndex, wLength);
1731 2035error:
1732 /* "protocol stall" on error */ 2036 /* "protocol stall" on error */
1733 retval = -EPIPE; 2037 retval = -EPIPE;
1734 } 2038 }
1735 spin_unlock_irqrestore (&dum->lock, flags); 2039 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1736 2040
1737 if ((dum->port_status & PORT_C_MASK) != 0) 2041 if ((dum_hcd->port_status & PORT_C_MASK) != 0)
1738 usb_hcd_poll_rh_status (hcd); 2042 usb_hcd_poll_rh_status (hcd);
1739 return retval; 2043 return retval;
1740} 2044}
1741 2045
1742static int dummy_bus_suspend (struct usb_hcd *hcd) 2046static int dummy_bus_suspend (struct usb_hcd *hcd)
1743{ 2047{
1744 struct dummy *dum = hcd_to_dummy (hcd); 2048 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
1745 2049
1746 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); 2050 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
1747 2051
1748 spin_lock_irq (&dum->lock); 2052 spin_lock_irq(&dum_hcd->dum->lock);
1749 dum->rh_state = DUMMY_RH_SUSPENDED; 2053 dum_hcd->rh_state = DUMMY_RH_SUSPENDED;
1750 set_link_state (dum); 2054 set_link_state(dum_hcd);
1751 hcd->state = HC_STATE_SUSPENDED; 2055 hcd->state = HC_STATE_SUSPENDED;
1752 spin_unlock_irq (&dum->lock); 2056 spin_unlock_irq(&dum_hcd->dum->lock);
1753 return 0; 2057 return 0;
1754} 2058}
1755 2059
1756static int dummy_bus_resume (struct usb_hcd *hcd) 2060static int dummy_bus_resume (struct usb_hcd *hcd)
1757{ 2061{
1758 struct dummy *dum = hcd_to_dummy (hcd); 2062 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
1759 int rc = 0; 2063 int rc = 0;
1760 2064
1761 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); 2065 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
1762 2066
1763 spin_lock_irq (&dum->lock); 2067 spin_lock_irq(&dum_hcd->dum->lock);
1764 if (!HCD_HW_ACCESSIBLE(hcd)) { 2068 if (!HCD_HW_ACCESSIBLE(hcd)) {
1765 rc = -ESHUTDOWN; 2069 rc = -ESHUTDOWN;
1766 } else { 2070 } else {
1767 dum->rh_state = DUMMY_RH_RUNNING; 2071 dum_hcd->rh_state = DUMMY_RH_RUNNING;
1768 set_link_state (dum); 2072 set_link_state(dum_hcd);
1769 if (!list_empty(&dum->urbp_list)) 2073 if (!list_empty(&dum_hcd->urbp_list))
1770 mod_timer (&dum->timer, jiffies); 2074 mod_timer(&dum_hcd->timer, jiffies);
1771 hcd->state = HC_STATE_RUNNING; 2075 hcd->state = HC_STATE_RUNNING;
1772 } 2076 }
1773 spin_unlock_irq (&dum->lock); 2077 spin_unlock_irq(&dum_hcd->dum->lock);
1774 return rc; 2078 return rc;
1775} 2079}
1776 2080
@@ -1786,18 +2090,37 @@ show_urb (char *buf, size_t size, struct urb *urb)
1786 urb, 2090 urb,
1787 ({ char *s; 2091 ({ char *s;
1788 switch (urb->dev->speed) { 2092 switch (urb->dev->speed) {
1789 case USB_SPEED_LOW: s = "ls"; break; 2093 case USB_SPEED_LOW:
1790 case USB_SPEED_FULL: s = "fs"; break; 2094 s = "ls";
1791 case USB_SPEED_HIGH: s = "hs"; break; 2095 break;
1792 default: s = "?"; break; 2096 case USB_SPEED_FULL:
2097 s = "fs";
2098 break;
2099 case USB_SPEED_HIGH:
2100 s = "hs";
2101 break;
2102 case USB_SPEED_SUPER:
2103 s = "ss";
2104 break;
2105 default:
2106 s = "?";
2107 break;
1793 }; s; }), 2108 }; s; }),
1794 ep, ep ? (usb_pipein (urb->pipe) ? "in" : "out") : "", 2109 ep, ep ? (usb_pipein (urb->pipe) ? "in" : "out") : "",
1795 ({ char *s; \ 2110 ({ char *s; \
1796 switch (usb_pipetype (urb->pipe)) { \ 2111 switch (usb_pipetype (urb->pipe)) { \
1797 case PIPE_CONTROL: s = ""; break; \ 2112 case PIPE_CONTROL: \
1798 case PIPE_BULK: s = "-bulk"; break; \ 2113 s = ""; \
1799 case PIPE_INTERRUPT: s = "-int"; break; \ 2114 break; \
1800 default: s = "-iso"; break; \ 2115 case PIPE_BULK: \
2116 s = "-bulk"; \
2117 break; \
2118 case PIPE_INTERRUPT: \
2119 s = "-int"; \
2120 break; \
2121 default: \
2122 s = "-iso"; \
2123 break; \
1801 }; s;}), 2124 }; s;}),
1802 urb->actual_length, urb->transfer_buffer_length); 2125 urb->actual_length, urb->transfer_buffer_length);
1803} 2126}
@@ -1806,43 +2129,63 @@ static ssize_t
1806show_urbs (struct device *dev, struct device_attribute *attr, char *buf) 2129show_urbs (struct device *dev, struct device_attribute *attr, char *buf)
1807{ 2130{
1808 struct usb_hcd *hcd = dev_get_drvdata (dev); 2131 struct usb_hcd *hcd = dev_get_drvdata (dev);
1809 struct dummy *dum = hcd_to_dummy (hcd); 2132 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
1810 struct urbp *urbp; 2133 struct urbp *urbp;
1811 size_t size = 0; 2134 size_t size = 0;
1812 unsigned long flags; 2135 unsigned long flags;
1813 2136
1814 spin_lock_irqsave (&dum->lock, flags); 2137 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1815 list_for_each_entry (urbp, &dum->urbp_list, urbp_list) { 2138 list_for_each_entry(urbp, &dum_hcd->urbp_list, urbp_list) {
1816 size_t temp; 2139 size_t temp;
1817 2140
1818 temp = show_urb (buf, PAGE_SIZE - size, urbp->urb); 2141 temp = show_urb (buf, PAGE_SIZE - size, urbp->urb);
1819 buf += temp; 2142 buf += temp;
1820 size += temp; 2143 size += temp;
1821 } 2144 }
1822 spin_unlock_irqrestore (&dum->lock, flags); 2145 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1823 2146
1824 return size; 2147 return size;
1825} 2148}
1826static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL); 2149static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL);
1827 2150
1828static int dummy_start (struct usb_hcd *hcd) 2151static int dummy_start_ss(struct dummy_hcd *dum_hcd)
1829{ 2152{
1830 struct dummy *dum; 2153 init_timer(&dum_hcd->timer);
2154 dum_hcd->timer.function = dummy_timer;
2155 dum_hcd->timer.data = (unsigned long)dum_hcd;
2156 dum_hcd->rh_state = DUMMY_RH_RUNNING;
2157 INIT_LIST_HEAD(&dum_hcd->urbp_list);
2158 dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET;
2159 dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING;
2160 dummy_hcd_to_hcd(dum_hcd)->uses_new_polling = 1;
2161#ifdef CONFIG_USB_OTG
2162 dummy_hcd_to_hcd(dum_hcd)->self.otg_port = 1;
2163#endif
2164 return 0;
2165
2166 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
2167 return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs);
2168}
1831 2169
1832 dum = hcd_to_dummy (hcd); 2170static int dummy_start(struct usb_hcd *hcd)
2171{
2172 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
1833 2173
1834 /* 2174 /*
1835 * MASTER side init ... we emulate a root hub that'll only ever 2175 * MASTER side init ... we emulate a root hub that'll only ever
1836 * talk to one device (the slave side). Also appears in sysfs, 2176 * talk to one device (the slave side). Also appears in sysfs,
1837 * just like more familiar pci-based HCDs. 2177 * just like more familiar pci-based HCDs.
1838 */ 2178 */
1839 spin_lock_init (&dum->lock); 2179 if (!usb_hcd_is_primary_hcd(hcd))
1840 init_timer (&dum->timer); 2180 return dummy_start_ss(dum_hcd);
1841 dum->timer.function = dummy_timer;
1842 dum->timer.data = (unsigned long) dum;
1843 dum->rh_state = DUMMY_RH_RUNNING;
1844 2181
1845 INIT_LIST_HEAD (&dum->urbp_list); 2182 spin_lock_init(&dum_hcd->dum->lock);
2183 init_timer(&dum_hcd->timer);
2184 dum_hcd->timer.function = dummy_timer;
2185 dum_hcd->timer.data = (unsigned long)dum_hcd;
2186 dum_hcd->rh_state = DUMMY_RH_RUNNING;
2187
2188 INIT_LIST_HEAD(&dum_hcd->urbp_list);
1846 2189
1847 hcd->power_budget = POWER_BUDGET; 2190 hcd->power_budget = POWER_BUDGET;
1848 hcd->state = HC_STATE_RUNNING; 2191 hcd->state = HC_STATE_RUNNING;
@@ -1853,18 +2196,17 @@ static int dummy_start (struct usb_hcd *hcd)
1853#endif 2196#endif
1854 2197
1855 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ 2198 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
1856 return device_create_file (dummy_dev(dum), &dev_attr_urbs); 2199 return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs);
1857} 2200}
1858 2201
1859static void dummy_stop (struct usb_hcd *hcd) 2202static void dummy_stop (struct usb_hcd *hcd)
1860{ 2203{
1861 struct dummy *dum; 2204 struct dummy *dum;
1862 2205
1863 dum = hcd_to_dummy (hcd); 2206 dum = (hcd_to_dummy_hcd(hcd))->dum;
1864 2207 device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs);
1865 device_remove_file (dummy_dev(dum), &dev_attr_urbs); 2208 usb_gadget_unregister_driver(dum->driver);
1866 usb_gadget_unregister_driver (dum->driver); 2209 dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n");
1867 dev_info (dummy_dev(dum), "stopped\n");
1868} 2210}
1869 2211
1870/*-------------------------------------------------------------------------*/ 2212/*-------------------------------------------------------------------------*/
@@ -1874,13 +2216,59 @@ static int dummy_h_get_frame (struct usb_hcd *hcd)
1874 return dummy_g_get_frame (NULL); 2216 return dummy_g_get_frame (NULL);
1875} 2217}
1876 2218
1877static const struct hc_driver dummy_hcd = { 2219static int dummy_setup(struct usb_hcd *hcd)
2220{
2221 if (usb_hcd_is_primary_hcd(hcd)) {
2222 the_controller.hs_hcd = hcd_to_dummy_hcd(hcd);
2223 the_controller.hs_hcd->dum = &the_controller;
2224 /*
2225 * Mark the first roothub as being USB 2.0.
2226 * The USB 3.0 roothub will be registered later by
2227 * dummy_hcd_probe()
2228 */
2229 hcd->speed = HCD_USB2;
2230 hcd->self.root_hub->speed = USB_SPEED_HIGH;
2231 } else {
2232 the_controller.ss_hcd = hcd_to_dummy_hcd(hcd);
2233 the_controller.ss_hcd->dum = &the_controller;
2234 hcd->speed = HCD_USB3;
2235 hcd->self.root_hub->speed = USB_SPEED_SUPER;
2236 }
2237 return 0;
2238}
2239
2240/* Change a group of bulk endpoints to support multiple stream IDs */
2241int dummy_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
2242 struct usb_host_endpoint **eps, unsigned int num_eps,
2243 unsigned int num_streams, gfp_t mem_flags)
2244{
2245 if (hcd->speed != HCD_USB3)
2246 dev_dbg(dummy_dev(hcd_to_dummy_hcd(hcd)),
2247 "%s() - ERROR! Not supported for USB2.0 roothub\n",
2248 __func__);
2249 return 0;
2250}
2251
2252/* Reverts a group of bulk endpoints back to not using stream IDs. */
2253int dummy_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
2254 struct usb_host_endpoint **eps, unsigned int num_eps,
2255 gfp_t mem_flags)
2256{
2257 if (hcd->speed != HCD_USB3)
2258 dev_dbg(dummy_dev(hcd_to_dummy_hcd(hcd)),
2259 "%s() - ERROR! Not supported for USB2.0 roothub\n",
2260 __func__);
2261 return 0;
2262}
2263
2264static struct hc_driver dummy_hcd = {
1878 .description = (char *) driver_name, 2265 .description = (char *) driver_name,
1879 .product_desc = "Dummy host controller", 2266 .product_desc = "Dummy host controller",
1880 .hcd_priv_size = sizeof(struct dummy), 2267 .hcd_priv_size = sizeof(struct dummy_hcd),
1881 2268
1882 .flags = HCD_USB2, 2269 .flags = HCD_USB3 | HCD_SHARED,
1883 2270
2271 .reset = dummy_setup,
1884 .start = dummy_start, 2272 .start = dummy_start,
1885 .stop = dummy_stop, 2273 .stop = dummy_stop,
1886 2274
@@ -1893,51 +2281,85 @@ static const struct hc_driver dummy_hcd = {
1893 .hub_control = dummy_hub_control, 2281 .hub_control = dummy_hub_control,
1894 .bus_suspend = dummy_bus_suspend, 2282 .bus_suspend = dummy_bus_suspend,
1895 .bus_resume = dummy_bus_resume, 2283 .bus_resume = dummy_bus_resume,
2284
2285 .alloc_streams = dummy_alloc_streams,
2286 .free_streams = dummy_free_streams,
1896}; 2287};
1897 2288
1898static int dummy_hcd_probe(struct platform_device *pdev) 2289static int dummy_hcd_probe(struct platform_device *pdev)
1899{ 2290{
1900 struct usb_hcd *hcd; 2291 struct usb_hcd *hs_hcd;
2292 struct usb_hcd *ss_hcd;
1901 int retval; 2293 int retval;
1902 2294
1903 dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc); 2295 dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc);
1904 2296
1905 hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, dev_name(&pdev->dev)); 2297 if (!mod_data.is_super_speed)
1906 if (!hcd) 2298 dummy_hcd.flags = HCD_USB2;
2299 hs_hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, dev_name(&pdev->dev));
2300 if (!hs_hcd)
1907 return -ENOMEM; 2301 return -ENOMEM;
1908 the_controller = hcd_to_dummy (hcd); 2302 hs_hcd->has_tt = 1;
1909 hcd->has_tt = 1;
1910 2303
1911 retval = usb_add_hcd(hcd, 0, 0); 2304 retval = usb_add_hcd(hs_hcd, 0, 0);
1912 if (retval != 0) { 2305 if (retval != 0) {
1913 usb_put_hcd (hcd); 2306 usb_put_hcd(hs_hcd);
1914 the_controller = NULL; 2307 return retval;
2308 }
2309
2310 if (mod_data.is_super_speed) {
2311 ss_hcd = usb_create_shared_hcd(&dummy_hcd, &pdev->dev,
2312 dev_name(&pdev->dev), hs_hcd);
2313 if (!ss_hcd) {
2314 retval = -ENOMEM;
2315 goto dealloc_usb2_hcd;
2316 }
2317
2318 retval = usb_add_hcd(ss_hcd, 0, 0);
2319 if (retval)
2320 goto put_usb3_hcd;
1915 } 2321 }
2322 return 0;
2323
2324put_usb3_hcd:
2325 usb_put_hcd(ss_hcd);
2326dealloc_usb2_hcd:
2327 usb_put_hcd(hs_hcd);
2328 the_controller.hs_hcd = the_controller.ss_hcd = NULL;
1916 return retval; 2329 return retval;
1917} 2330}
1918 2331
1919static int dummy_hcd_remove (struct platform_device *pdev) 2332static int dummy_hcd_remove(struct platform_device *pdev)
1920{ 2333{
1921 struct usb_hcd *hcd; 2334 struct dummy *dum;
2335
2336 dum = (hcd_to_dummy_hcd(platform_get_drvdata(pdev)))->dum;
2337
2338 if (dum->ss_hcd) {
2339 usb_remove_hcd(dummy_hcd_to_hcd(dum->ss_hcd));
2340 usb_put_hcd(dummy_hcd_to_hcd(dum->ss_hcd));
2341 }
2342
2343 usb_remove_hcd(dummy_hcd_to_hcd(dum->hs_hcd));
2344 usb_put_hcd(dummy_hcd_to_hcd(dum->hs_hcd));
2345
2346 the_controller.hs_hcd = NULL;
2347 the_controller.ss_hcd = NULL;
1922 2348
1923 hcd = platform_get_drvdata (pdev);
1924 usb_remove_hcd (hcd);
1925 usb_put_hcd (hcd);
1926 the_controller = NULL;
1927 return 0; 2349 return 0;
1928} 2350}
1929 2351
1930static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state) 2352static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state)
1931{ 2353{
1932 struct usb_hcd *hcd; 2354 struct usb_hcd *hcd;
1933 struct dummy *dum; 2355 struct dummy_hcd *dum_hcd;
1934 int rc = 0; 2356 int rc = 0;
1935 2357
1936 dev_dbg (&pdev->dev, "%s\n", __func__); 2358 dev_dbg (&pdev->dev, "%s\n", __func__);
1937 2359
1938 hcd = platform_get_drvdata (pdev); 2360 hcd = platform_get_drvdata (pdev);
1939 dum = hcd_to_dummy (hcd); 2361 dum_hcd = hcd_to_dummy_hcd(hcd);
1940 if (dum->rh_state == DUMMY_RH_RUNNING) { 2362 if (dum_hcd->rh_state == DUMMY_RH_RUNNING) {
1941 dev_warn(&pdev->dev, "Root hub isn't suspended!\n"); 2363 dev_warn(&pdev->dev, "Root hub isn't suspended!\n");
1942 rc = -EBUSY; 2364 rc = -EBUSY;
1943 } else 2365 } else
@@ -1980,6 +2402,9 @@ static int __init init (void)
1980 if (usb_disabled ()) 2402 if (usb_disabled ())
1981 return -ENODEV; 2403 return -ENODEV;
1982 2404
2405 if (!mod_data.is_high_speed && mod_data.is_super_speed)
2406 return -EINVAL;
2407
1983 the_hcd_pdev = platform_device_alloc(driver_name, -1); 2408 the_hcd_pdev = platform_device_alloc(driver_name, -1);
1984 if (!the_hcd_pdev) 2409 if (!the_hcd_pdev)
1985 return retval; 2410 return retval;
@@ -1997,7 +2422,8 @@ static int __init init (void)
1997 retval = platform_device_add(the_hcd_pdev); 2422 retval = platform_device_add(the_hcd_pdev);
1998 if (retval < 0) 2423 if (retval < 0)
1999 goto err_add_hcd; 2424 goto err_add_hcd;
2000 if (!the_controller) { 2425 if (!the_controller.hs_hcd ||
2426 (!the_controller.ss_hcd && mod_data.is_super_speed)) {
2001 /* 2427 /*
2002 * The hcd was added successfully but its probe function failed 2428 * The hcd was added successfully but its probe function failed
2003 * for some reason. 2429 * for some reason.
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 9b7360ff5aa7..7a7e6b7e1fd6 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -63,13 +63,16 @@ static int
63ep_matches ( 63ep_matches (
64 struct usb_gadget *gadget, 64 struct usb_gadget *gadget,
65 struct usb_ep *ep, 65 struct usb_ep *ep,
66 struct usb_endpoint_descriptor *desc 66 struct usb_endpoint_descriptor *desc,
67 struct usb_ss_ep_comp_descriptor *ep_comp
67) 68)
68{ 69{
69 u8 type; 70 u8 type;
70 const char *tmp; 71 const char *tmp;
71 u16 max; 72 u16 max;
72 73
74 int num_req_streams = 0;
75
73 /* endpoint already claimed? */ 76 /* endpoint already claimed? */
74 if (NULL != ep->driver_data) 77 if (NULL != ep->driver_data)
75 return 0; 78 return 0;
@@ -129,6 +132,22 @@ ep_matches (
129 } 132 }
130 133
131 /* 134 /*
135 * Get the number of required streams from the EP companion
136 * descriptor and see if the EP matches it
137 */
138 if (usb_endpoint_xfer_bulk(desc)) {
139 if (ep_comp) {
140 num_req_streams = ep_comp->bmAttributes & 0x1f;
141 if (num_req_streams > ep->max_streams)
142 return 0;
143 /* Update the ep_comp descriptor if needed */
144 if (num_req_streams != ep->max_streams)
145 ep_comp->bmAttributes = ep->max_streams;
146 }
147
148 }
149
150 /*
132 * If the protocol driver hasn't yet decided on wMaxPacketSize 151 * If the protocol driver hasn't yet decided on wMaxPacketSize
133 * and wants to know the maximum possible, provide the info. 152 * and wants to know the maximum possible, provide the info.
134 */ 153 */
@@ -142,13 +161,13 @@ ep_matches (
142 max = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); 161 max = 0x7ff & le16_to_cpu(desc->wMaxPacketSize);
143 switch (type) { 162 switch (type) {
144 case USB_ENDPOINT_XFER_INT: 163 case USB_ENDPOINT_XFER_INT:
145 /* INT: limit 64 bytes full speed, 1024 high speed */ 164 /* INT: limit 64 bytes full speed, 1024 high/super speed */
146 if (!gadget->is_dualspeed && max > 64) 165 if (!gadget->is_dualspeed && max > 64)
147 return 0; 166 return 0;
148 /* FALLTHROUGH */ 167 /* FALLTHROUGH */
149 168
150 case USB_ENDPOINT_XFER_ISOC: 169 case USB_ENDPOINT_XFER_ISOC:
151 /* ISO: limit 1023 bytes full speed, 1024 high speed */ 170 /* ISO: limit 1023 bytes full speed, 1024 high/super speed */
152 if (ep->maxpacket < max) 171 if (ep->maxpacket < max)
153 return 0; 172 return 0;
154 if (!gadget->is_dualspeed && max > 1023) 173 if (!gadget->is_dualspeed && max > 1023)
@@ -183,7 +202,7 @@ ep_matches (
183 } 202 }
184 203
185 /* report (variable) full speed bulk maxpacket */ 204 /* report (variable) full speed bulk maxpacket */
186 if (USB_ENDPOINT_XFER_BULK == type) { 205 if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) {
187 int size = ep->maxpacket; 206 int size = ep->maxpacket;
188 207
189 /* min() doesn't work on bitfields with gcc-3.5 */ 208 /* min() doesn't work on bitfields with gcc-3.5 */
@@ -191,6 +210,7 @@ ep_matches (
191 size = 64; 210 size = 64;
192 desc->wMaxPacketSize = cpu_to_le16(size); 211 desc->wMaxPacketSize = cpu_to_le16(size);
193 } 212 }
213 ep->address = desc->bEndpointAddress;
194 return 1; 214 return 1;
195} 215}
196 216
@@ -207,38 +227,53 @@ find_ep (struct usb_gadget *gadget, const char *name)
207} 227}
208 228
209/** 229/**
210 * usb_ep_autoconfig - choose an endpoint matching the descriptor 230 * usb_ep_autoconfig_ss() - choose an endpoint matching the ep
231 * descriptor and ep companion descriptor
211 * @gadget: The device to which the endpoint must belong. 232 * @gadget: The device to which the endpoint must belong.
212 * @desc: Endpoint descriptor, with endpoint direction and transfer mode 233 * @desc: Endpoint descriptor, with endpoint direction and transfer mode
213 * initialized. For periodic transfers, the maximum packet 234 * initialized. For periodic transfers, the maximum packet
214 * size must also be initialized. This is modified on success. 235 * size must also be initialized. This is modified on
236 * success.
237 * @ep_comp: Endpoint companion descriptor, with the required
238 * number of streams. Will be modified when the chosen EP
239 * supports a different number of streams.
215 * 240 *
216 * By choosing an endpoint to use with the specified descriptor, this 241 * This routine replaces the usb_ep_autoconfig when needed
217 * routine simplifies writing gadget drivers that work with multiple 242 * superspeed enhancments. If such enhancemnets are required,
218 * USB device controllers. The endpoint would be passed later to 243 * the FD should call usb_ep_autoconfig_ss directly and provide
219 * usb_ep_enable(), along with some descriptor. 244 * the additional ep_comp parameter.
245 *
246 * By choosing an endpoint to use with the specified descriptor,
247 * this routine simplifies writing gadget drivers that work with
248 * multiple USB device controllers. The endpoint would be
249 * passed later to usb_ep_enable(), along with some descriptor.
220 * 250 *
221 * That second descriptor won't always be the same as the first one. 251 * That second descriptor won't always be the same as the first one.
222 * For example, isochronous endpoints can be autoconfigured for high 252 * For example, isochronous endpoints can be autoconfigured for high
223 * bandwidth, and then used in several lower bandwidth altsettings. 253 * bandwidth, and then used in several lower bandwidth altsettings.
224 * Also, high and full speed descriptors will be different. 254 * Also, high and full speed descriptors will be different.
225 * 255 *
226 * Be sure to examine and test the results of autoconfiguration on your 256 * Be sure to examine and test the results of autoconfiguration
227 * hardware. This code may not make the best choices about how to use the 257 * on your hardware. This code may not make the best choices
228 * USB controller, and it can't know all the restrictions that may apply. 258 * about how to use the USB controller, and it can't know all
229 * Some combinations of driver and hardware won't be able to autoconfigure. 259 * the restrictions that may apply. Some combinations of driver
260 * and hardware won't be able to autoconfigure.
230 * 261 *
231 * On success, this returns an un-claimed usb_ep, and modifies the endpoint 262 * On success, this returns an un-claimed usb_ep, and modifies the endpoint
232 * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value 263 * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value
233 * is initialized as if the endpoint were used at full speed. To prevent 264 * is initialized as if the endpoint were used at full speed and
234 * the endpoint from being returned by a later autoconfig call, claim it 265 * the bmAttribute field in the ep companion descriptor is
235 * by assigning ep->driver_data to some non-null value. 266 * updated with the assigned number of streams if it is
267 * different from the original value. To prevent the endpoint
268 * from being returned by a later autoconfig call, claim it by
269 * assigning ep->driver_data to some non-null value.
236 * 270 *
237 * On failure, this returns a null endpoint descriptor. 271 * On failure, this returns a null endpoint descriptor.
238 */ 272 */
239struct usb_ep *usb_ep_autoconfig ( 273struct usb_ep *usb_ep_autoconfig_ss(
240 struct usb_gadget *gadget, 274 struct usb_gadget *gadget,
241 struct usb_endpoint_descriptor *desc 275 struct usb_endpoint_descriptor *desc,
276 struct usb_ss_ep_comp_descriptor *ep_comp
242) 277)
243{ 278{
244 struct usb_ep *ep; 279 struct usb_ep *ep;
@@ -252,23 +287,24 @@ struct usb_ep *usb_ep_autoconfig (
252 if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) { 287 if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) {
253 /* ep-e, ep-f are PIO with only 64 byte fifos */ 288 /* ep-e, ep-f are PIO with only 64 byte fifos */
254 ep = find_ep (gadget, "ep-e"); 289 ep = find_ep (gadget, "ep-e");
255 if (ep && ep_matches (gadget, ep, desc)) 290 if (ep && ep_matches(gadget, ep, desc, ep_comp))
256 return ep; 291 return ep;
257 ep = find_ep (gadget, "ep-f"); 292 ep = find_ep (gadget, "ep-f");
258 if (ep && ep_matches (gadget, ep, desc)) 293 if (ep && ep_matches(gadget, ep, desc, ep_comp))
259 return ep; 294 return ep;
260 295
261 } else if (gadget_is_goku (gadget)) { 296 } else if (gadget_is_goku (gadget)) {
262 if (USB_ENDPOINT_XFER_INT == type) { 297 if (USB_ENDPOINT_XFER_INT == type) {
263 /* single buffering is enough */ 298 /* single buffering is enough */
264 ep = find_ep (gadget, "ep3-bulk"); 299 ep = find_ep(gadget, "ep3-bulk");
265 if (ep && ep_matches (gadget, ep, desc)) 300 if (ep && ep_matches(gadget, ep, desc, ep_comp))
266 return ep; 301 return ep;
267 } else if (USB_ENDPOINT_XFER_BULK == type 302 } else if (USB_ENDPOINT_XFER_BULK == type
268 && (USB_DIR_IN & desc->bEndpointAddress)) { 303 && (USB_DIR_IN & desc->bEndpointAddress)) {
269 /* DMA may be available */ 304 /* DMA may be available */
270 ep = find_ep (gadget, "ep2-bulk"); 305 ep = find_ep(gadget, "ep2-bulk");
271 if (ep && ep_matches (gadget, ep, desc)) 306 if (ep && ep_matches(gadget, ep, desc,
307 ep_comp))
272 return ep; 308 return ep;
273 } 309 }
274 310
@@ -287,14 +323,14 @@ struct usb_ep *usb_ep_autoconfig (
287 ep = find_ep(gadget, "ep2out"); 323 ep = find_ep(gadget, "ep2out");
288 } else 324 } else
289 ep = NULL; 325 ep = NULL;
290 if (ep && ep_matches (gadget, ep, desc)) 326 if (ep && ep_matches(gadget, ep, desc, ep_comp))
291 return ep; 327 return ep;
292#endif 328#endif
293 } 329 }
294 330
295 /* Second, look at endpoints until an unclaimed one looks usable */ 331 /* Second, look at endpoints until an unclaimed one looks usable */
296 list_for_each_entry (ep, &gadget->ep_list, ep_list) { 332 list_for_each_entry (ep, &gadget->ep_list, ep_list) {
297 if (ep_matches (gadget, ep, desc)) 333 if (ep_matches(gadget, ep, desc, ep_comp))
298 return ep; 334 return ep;
299 } 335 }
300 336
@@ -303,6 +339,46 @@ struct usb_ep *usb_ep_autoconfig (
303} 339}
304 340
305/** 341/**
342 * usb_ep_autoconfig() - choose an endpoint matching the
343 * descriptor
344 * @gadget: The device to which the endpoint must belong.
345 * @desc: Endpoint descriptor, with endpoint direction and transfer mode
346 * initialized. For periodic transfers, the maximum packet
347 * size must also be initialized. This is modified on success.
348 *
349 * By choosing an endpoint to use with the specified descriptor, this
350 * routine simplifies writing gadget drivers that work with multiple
351 * USB device controllers. The endpoint would be passed later to
352 * usb_ep_enable(), along with some descriptor.
353 *
354 * That second descriptor won't always be the same as the first one.
355 * For example, isochronous endpoints can be autoconfigured for high
356 * bandwidth, and then used in several lower bandwidth altsettings.
357 * Also, high and full speed descriptors will be different.
358 *
359 * Be sure to examine and test the results of autoconfiguration on your
360 * hardware. This code may not make the best choices about how to use the
361 * USB controller, and it can't know all the restrictions that may apply.
362 * Some combinations of driver and hardware won't be able to autoconfigure.
363 *
364 * On success, this returns an un-claimed usb_ep, and modifies the endpoint
365 * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value
366 * is initialized as if the endpoint were used at full speed. To prevent
367 * the endpoint from being returned by a later autoconfig call, claim it
368 * by assigning ep->driver_data to some non-null value.
369 *
370 * On failure, this returns a null endpoint descriptor.
371 */
372struct usb_ep *usb_ep_autoconfig(
373 struct usb_gadget *gadget,
374 struct usb_endpoint_descriptor *desc
375)
376{
377 return usb_ep_autoconfig_ss(gadget, desc, NULL);
378}
379
380
381/**
306 * usb_ep_autoconfig_reset - reset endpoint autoconfig state 382 * usb_ep_autoconfig_reset - reset endpoint autoconfig state
307 * @gadget: device for which autoconfig state will be reset 383 * @gadget: device for which autoconfig state will be reset
308 * 384 *
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 1690c9d68256..aafc84f33e26 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -401,6 +401,7 @@ static struct usb_composite_driver eth_driver = {
401 .name = "g_ether", 401 .name = "g_ether",
402 .dev = &device_desc, 402 .dev = &device_desc,
403 .strings = dev_strings, 403 .strings = dev_strings,
404 .max_speed = USB_SPEED_SUPER,
404 .unbind = __exit_p(eth_unbind), 405 .unbind = __exit_p(eth_unbind),
405}; 406};
406 407
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index bd6226cbae86..3f8849339ade 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -39,12 +39,6 @@
39 * descriptors (roughly equivalent to CDC Unions) may sometimes help. 39 * descriptors (roughly equivalent to CDC Unions) may sometimes help.
40 */ 40 */
41 41
42struct acm_ep_descs {
43 struct usb_endpoint_descriptor *in;
44 struct usb_endpoint_descriptor *out;
45 struct usb_endpoint_descriptor *notify;
46};
47
48struct f_acm { 42struct f_acm {
49 struct gserial port; 43 struct gserial port;
50 u8 ctrl_id, data_id; 44 u8 ctrl_id, data_id;
@@ -58,11 +52,7 @@ struct f_acm {
58 */ 52 */
59 spinlock_t lock; 53 spinlock_t lock;
60 54
61 struct acm_ep_descs fs;
62 struct acm_ep_descs hs;
63
64 struct usb_ep *notify; 55 struct usb_ep *notify;
65 struct usb_endpoint_descriptor *notify_desc;
66 struct usb_request *notify_req; 56 struct usb_request *notify_req;
67 57
68 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ 58 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
@@ -405,23 +395,27 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
405 usb_ep_disable(acm->notify); 395 usb_ep_disable(acm->notify);
406 } else { 396 } else {
407 VDBG(cdev, "init acm ctrl interface %d\n", intf); 397 VDBG(cdev, "init acm ctrl interface %d\n", intf);
408 acm->notify_desc = ep_choose(cdev->gadget, 398 if (config_ep_by_speed(cdev->gadget, f, acm->notify))
409 acm->hs.notify, 399 return -EINVAL;
410 acm->fs.notify);
411 } 400 }
412 usb_ep_enable(acm->notify, acm->notify_desc); 401 usb_ep_enable(acm->notify);
413 acm->notify->driver_data = acm; 402 acm->notify->driver_data = acm;
414 403
415 } else if (intf == acm->data_id) { 404 } else if (intf == acm->data_id) {
416 if (acm->port.in->driver_data) { 405 if (acm->port.in->driver_data) {
417 DBG(cdev, "reset acm ttyGS%d\n", acm->port_num); 406 DBG(cdev, "reset acm ttyGS%d\n", acm->port_num);
418 gserial_disconnect(&acm->port); 407 gserial_disconnect(&acm->port);
419 } else { 408 }
409 if (!acm->port.in->desc || !acm->port.out->desc) {
420 DBG(cdev, "activate acm ttyGS%d\n", acm->port_num); 410 DBG(cdev, "activate acm ttyGS%d\n", acm->port_num);
421 acm->port.in_desc = ep_choose(cdev->gadget, 411 if (config_ep_by_speed(cdev->gadget, f,
422 acm->hs.in, acm->fs.in); 412 acm->port.in) ||
423 acm->port.out_desc = ep_choose(cdev->gadget, 413 config_ep_by_speed(cdev->gadget, f,
424 acm->hs.out, acm->fs.out); 414 acm->port.out)) {
415 acm->port.in->desc = NULL;
416 acm->port.out->desc = NULL;
417 return -EINVAL;
418 }
425 } 419 }
426 gserial_connect(&acm->port, acm->port_num); 420 gserial_connect(&acm->port, acm->port_num);
427 421
@@ -629,18 +623,11 @@ acm_bind(struct usb_configuration *c, struct usb_function *f)
629 acm->notify_req->complete = acm_cdc_notify_complete; 623 acm->notify_req->complete = acm_cdc_notify_complete;
630 acm->notify_req->context = acm; 624 acm->notify_req->context = acm;
631 625
632 /* copy descriptors, and track endpoint copies */ 626 /* copy descriptors */
633 f->descriptors = usb_copy_descriptors(acm_fs_function); 627 f->descriptors = usb_copy_descriptors(acm_fs_function);
634 if (!f->descriptors) 628 if (!f->descriptors)
635 goto fail; 629 goto fail;
636 630
637 acm->fs.in = usb_find_endpoint(acm_fs_function,
638 f->descriptors, &acm_fs_in_desc);
639 acm->fs.out = usb_find_endpoint(acm_fs_function,
640 f->descriptors, &acm_fs_out_desc);
641 acm->fs.notify = usb_find_endpoint(acm_fs_function,
642 f->descriptors, &acm_fs_notify_desc);
643
644 /* support all relevant hardware speeds... we expect that when 631 /* support all relevant hardware speeds... we expect that when
645 * hardware is dual speed, all bulk-capable endpoints work at 632 * hardware is dual speed, all bulk-capable endpoints work at
646 * both speeds 633 * both speeds
@@ -653,15 +640,8 @@ acm_bind(struct usb_configuration *c, struct usb_function *f)
653 acm_hs_notify_desc.bEndpointAddress = 640 acm_hs_notify_desc.bEndpointAddress =
654 acm_fs_notify_desc.bEndpointAddress; 641 acm_fs_notify_desc.bEndpointAddress;
655 642
656 /* copy descriptors, and track endpoint copies */ 643 /* copy descriptors */
657 f->hs_descriptors = usb_copy_descriptors(acm_hs_function); 644 f->hs_descriptors = usb_copy_descriptors(acm_hs_function);
658
659 acm->hs.in = usb_find_endpoint(acm_hs_function,
660 f->hs_descriptors, &acm_hs_in_desc);
661 acm->hs.out = usb_find_endpoint(acm_hs_function,
662 f->hs_descriptors, &acm_hs_out_desc);
663 acm->hs.notify = usb_find_endpoint(acm_hs_function,
664 f->hs_descriptors, &acm_hs_notify_desc);
665 } 645 }
666 646
667 DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", 647 DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n",
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c
index 8ee330a2ab58..02a02700b51d 100644
--- a/drivers/usb/gadget/f_audio.c
+++ b/drivers/usb/gadget/f_audio.c
@@ -279,7 +279,6 @@ struct f_audio {
279 279
280 /* endpoints handle full and/or high speeds */ 280 /* endpoints handle full and/or high speeds */
281 struct usb_ep *out_ep; 281 struct usb_ep *out_ep;
282 struct usb_endpoint_descriptor *out_desc;
283 282
284 spinlock_t lock; 283 spinlock_t lock;
285 struct f_audio_buf *copy_buf; 284 struct f_audio_buf *copy_buf;
@@ -575,7 +574,7 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
575 574
576 if (intf == 1) { 575 if (intf == 1) {
577 if (alt == 1) { 576 if (alt == 1) {
578 usb_ep_enable(out_ep, audio->out_desc); 577 usb_ep_enable(out_ep);
579 out_ep->driver_data = audio; 578 out_ep->driver_data = audio;
580 audio->copy_buf = f_audio_buffer_alloc(audio_buf_size); 579 audio->copy_buf = f_audio_buffer_alloc(audio_buf_size);
581 if (IS_ERR(audio->copy_buf)) 580 if (IS_ERR(audio->copy_buf))
@@ -677,6 +676,7 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f)
677 if (!ep) 676 if (!ep)
678 goto fail; 677 goto fail;
679 audio->out_ep = ep; 678 audio->out_ep = ep;
679 audio->out_ep->desc = &as_out_ep_desc;
680 ep->driver_data = cdev; /* claim */ 680 ep->driver_data = cdev; /* claim */
681 681
682 status = -ENOMEM; 682 status = -ENOMEM;
@@ -776,7 +776,6 @@ int __init audio_bind_config(struct usb_configuration *c)
776 audio->card.func.set_alt = f_audio_set_alt; 776 audio->card.func.set_alt = f_audio_set_alt;
777 audio->card.func.setup = f_audio_setup; 777 audio->card.func.setup = f_audio_setup;
778 audio->card.func.disable = f_audio_disable; 778 audio->card.func.disable = f_audio_disable;
779 audio->out_desc = &as_out_ep_desc;
780 779
781 control_selector_init(audio); 780 control_selector_init(audio);
782 781
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index 544257a89ed2..3691a0cb9465 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -46,11 +46,6 @@
46 * and also means that a get_alt() method is required. 46 * and also means that a get_alt() method is required.
47 */ 47 */
48 48
49struct ecm_ep_descs {
50 struct usb_endpoint_descriptor *in;
51 struct usb_endpoint_descriptor *out;
52 struct usb_endpoint_descriptor *notify;
53};
54 49
55enum ecm_notify_state { 50enum ecm_notify_state {
56 ECM_NOTIFY_NONE, /* don't notify */ 51 ECM_NOTIFY_NONE, /* don't notify */
@@ -64,11 +59,7 @@ struct f_ecm {
64 59
65 char ethaddr[14]; 60 char ethaddr[14];
66 61
67 struct ecm_ep_descs fs;
68 struct ecm_ep_descs hs;
69
70 struct usb_ep *notify; 62 struct usb_ep *notify;
71 struct usb_endpoint_descriptor *notify_desc;
72 struct usb_request *notify_req; 63 struct usb_request *notify_req;
73 u8 notify_state; 64 u8 notify_state;
74 bool is_open; 65 bool is_open;
@@ -86,10 +77,12 @@ static inline struct f_ecm *func_to_ecm(struct usb_function *f)
86/* peak (theoretical) bulk transfer rate in bits-per-second */ 77/* peak (theoretical) bulk transfer rate in bits-per-second */
87static inline unsigned ecm_bitrate(struct usb_gadget *g) 78static inline unsigned ecm_bitrate(struct usb_gadget *g)
88{ 79{
89 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 80 if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
81 return 13 * 1024 * 8 * 1000 * 8;
82 else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
90 return 13 * 512 * 8 * 1000 * 8; 83 return 13 * 512 * 8 * 1000 * 8;
91 else 84 else
92 return 19 * 64 * 1 * 1000 * 8; 85 return 19 * 64 * 1 * 1000 * 8;
93} 86}
94 87
95/*-------------------------------------------------------------------------*/ 88/*-------------------------------------------------------------------------*/
@@ -219,8 +212,10 @@ static struct usb_descriptor_header *ecm_fs_function[] = {
219 (struct usb_descriptor_header *) &ecm_header_desc, 212 (struct usb_descriptor_header *) &ecm_header_desc,
220 (struct usb_descriptor_header *) &ecm_union_desc, 213 (struct usb_descriptor_header *) &ecm_union_desc,
221 (struct usb_descriptor_header *) &ecm_desc, 214 (struct usb_descriptor_header *) &ecm_desc,
215
222 /* NOTE: status endpoint might need to be removed */ 216 /* NOTE: status endpoint might need to be removed */
223 (struct usb_descriptor_header *) &fs_ecm_notify_desc, 217 (struct usb_descriptor_header *) &fs_ecm_notify_desc,
218
224 /* data interface, altsettings 0 and 1 */ 219 /* data interface, altsettings 0 and 1 */
225 (struct usb_descriptor_header *) &ecm_data_nop_intf, 220 (struct usb_descriptor_header *) &ecm_data_nop_intf,
226 (struct usb_descriptor_header *) &ecm_data_intf, 221 (struct usb_descriptor_header *) &ecm_data_intf,
@@ -240,6 +235,7 @@ static struct usb_endpoint_descriptor hs_ecm_notify_desc = {
240 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT), 235 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
241 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 236 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
242}; 237};
238
243static struct usb_endpoint_descriptor hs_ecm_in_desc = { 239static struct usb_endpoint_descriptor hs_ecm_in_desc = {
244 .bLength = USB_DT_ENDPOINT_SIZE, 240 .bLength = USB_DT_ENDPOINT_SIZE,
245 .bDescriptorType = USB_DT_ENDPOINT, 241 .bDescriptorType = USB_DT_ENDPOINT,
@@ -264,8 +260,10 @@ static struct usb_descriptor_header *ecm_hs_function[] = {
264 (struct usb_descriptor_header *) &ecm_header_desc, 260 (struct usb_descriptor_header *) &ecm_header_desc,
265 (struct usb_descriptor_header *) &ecm_union_desc, 261 (struct usb_descriptor_header *) &ecm_union_desc,
266 (struct usb_descriptor_header *) &ecm_desc, 262 (struct usb_descriptor_header *) &ecm_desc,
263
267 /* NOTE: status endpoint might need to be removed */ 264 /* NOTE: status endpoint might need to be removed */
268 (struct usb_descriptor_header *) &hs_ecm_notify_desc, 265 (struct usb_descriptor_header *) &hs_ecm_notify_desc,
266
269 /* data interface, altsettings 0 and 1 */ 267 /* data interface, altsettings 0 and 1 */
270 (struct usb_descriptor_header *) &ecm_data_nop_intf, 268 (struct usb_descriptor_header *) &ecm_data_nop_intf,
271 (struct usb_descriptor_header *) &ecm_data_intf, 269 (struct usb_descriptor_header *) &ecm_data_intf,
@@ -274,6 +272,76 @@ static struct usb_descriptor_header *ecm_hs_function[] = {
274 NULL, 272 NULL,
275}; 273};
276 274
275/* super speed support: */
276
277static struct usb_endpoint_descriptor ss_ecm_notify_desc = {
278 .bLength = USB_DT_ENDPOINT_SIZE,
279 .bDescriptorType = USB_DT_ENDPOINT,
280
281 .bEndpointAddress = USB_DIR_IN,
282 .bmAttributes = USB_ENDPOINT_XFER_INT,
283 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
284 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
285};
286
287static struct usb_ss_ep_comp_descriptor ss_ecm_intr_comp_desc = {
288 .bLength = sizeof ss_ecm_intr_comp_desc,
289 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
290
291 /* the following 3 values can be tweaked if necessary */
292 /* .bMaxBurst = 0, */
293 /* .bmAttributes = 0, */
294 .wBytesPerInterval = cpu_to_le16(ECM_STATUS_BYTECOUNT),
295};
296
297static struct usb_endpoint_descriptor ss_ecm_in_desc = {
298 .bLength = USB_DT_ENDPOINT_SIZE,
299 .bDescriptorType = USB_DT_ENDPOINT,
300
301 .bEndpointAddress = USB_DIR_IN,
302 .bmAttributes = USB_ENDPOINT_XFER_BULK,
303 .wMaxPacketSize = cpu_to_le16(1024),
304};
305
306static struct usb_endpoint_descriptor ss_ecm_out_desc = {
307 .bLength = USB_DT_ENDPOINT_SIZE,
308 .bDescriptorType = USB_DT_ENDPOINT,
309
310 .bEndpointAddress = USB_DIR_OUT,
311 .bmAttributes = USB_ENDPOINT_XFER_BULK,
312 .wMaxPacketSize = cpu_to_le16(1024),
313};
314
315static struct usb_ss_ep_comp_descriptor ss_ecm_bulk_comp_desc = {
316 .bLength = sizeof ss_ecm_bulk_comp_desc,
317 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
318
319 /* the following 2 values can be tweaked if necessary */
320 /* .bMaxBurst = 0, */
321 /* .bmAttributes = 0, */
322};
323
324static struct usb_descriptor_header *ecm_ss_function[] = {
325 /* CDC ECM control descriptors */
326 (struct usb_descriptor_header *) &ecm_control_intf,
327 (struct usb_descriptor_header *) &ecm_header_desc,
328 (struct usb_descriptor_header *) &ecm_union_desc,
329 (struct usb_descriptor_header *) &ecm_desc,
330
331 /* NOTE: status endpoint might need to be removed */
332 (struct usb_descriptor_header *) &ss_ecm_notify_desc,
333 (struct usb_descriptor_header *) &ss_ecm_intr_comp_desc,
334
335 /* data interface, altsettings 0 and 1 */
336 (struct usb_descriptor_header *) &ecm_data_nop_intf,
337 (struct usb_descriptor_header *) &ecm_data_intf,
338 (struct usb_descriptor_header *) &ss_ecm_in_desc,
339 (struct usb_descriptor_header *) &ss_ecm_bulk_comp_desc,
340 (struct usb_descriptor_header *) &ss_ecm_out_desc,
341 (struct usb_descriptor_header *) &ss_ecm_bulk_comp_desc,
342 NULL,
343};
344
277/* string descriptors: */ 345/* string descriptors: */
278 346
279static struct usb_string ecm_string_defs[] = { 347static struct usb_string ecm_string_defs[] = {
@@ -464,13 +532,13 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
464 if (ecm->notify->driver_data) { 532 if (ecm->notify->driver_data) {
465 VDBG(cdev, "reset ecm control %d\n", intf); 533 VDBG(cdev, "reset ecm control %d\n", intf);
466 usb_ep_disable(ecm->notify); 534 usb_ep_disable(ecm->notify);
467 } else { 535 }
536 if (!(ecm->notify->desc)) {
468 VDBG(cdev, "init ecm ctrl %d\n", intf); 537 VDBG(cdev, "init ecm ctrl %d\n", intf);
469 ecm->notify_desc = ep_choose(cdev->gadget, 538 if (config_ep_by_speed(cdev->gadget, f, ecm->notify))
470 ecm->hs.notify, 539 goto fail;
471 ecm->fs.notify);
472 } 540 }
473 usb_ep_enable(ecm->notify, ecm->notify_desc); 541 usb_ep_enable(ecm->notify);
474 ecm->notify->driver_data = ecm; 542 ecm->notify->driver_data = ecm;
475 543
476 /* Data interface has two altsettings, 0 and 1 */ 544 /* Data interface has two altsettings, 0 and 1 */
@@ -483,12 +551,17 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
483 gether_disconnect(&ecm->port); 551 gether_disconnect(&ecm->port);
484 } 552 }
485 553
486 if (!ecm->port.in) { 554 if (!ecm->port.in_ep->desc ||
555 !ecm->port.out_ep->desc) {
487 DBG(cdev, "init ecm\n"); 556 DBG(cdev, "init ecm\n");
488 ecm->port.in = ep_choose(cdev->gadget, 557 if (config_ep_by_speed(cdev->gadget, f,
489 ecm->hs.in, ecm->fs.in); 558 ecm->port.in_ep) ||
490 ecm->port.out = ep_choose(cdev->gadget, 559 config_ep_by_speed(cdev->gadget, f,
491 ecm->hs.out, ecm->fs.out); 560 ecm->port.out_ep)) {
561 ecm->port.in_ep->desc = NULL;
562 ecm->port.out_ep->desc = NULL;
563 goto fail;
564 }
492 } 565 }
493 566
494 /* CDC Ethernet only sends data in non-default altsettings. 567 /* CDC Ethernet only sends data in non-default altsettings.
@@ -549,7 +622,7 @@ static void ecm_disable(struct usb_function *f)
549 if (ecm->notify->driver_data) { 622 if (ecm->notify->driver_data) {
550 usb_ep_disable(ecm->notify); 623 usb_ep_disable(ecm->notify);
551 ecm->notify->driver_data = NULL; 624 ecm->notify->driver_data = NULL;
552 ecm->notify_desc = NULL; 625 ecm->notify->desc = NULL;
553 } 626 }
554} 627}
555 628
@@ -665,13 +738,6 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
665 if (!f->descriptors) 738 if (!f->descriptors)
666 goto fail; 739 goto fail;
667 740
668 ecm->fs.in = usb_find_endpoint(ecm_fs_function,
669 f->descriptors, &fs_ecm_in_desc);
670 ecm->fs.out = usb_find_endpoint(ecm_fs_function,
671 f->descriptors, &fs_ecm_out_desc);
672 ecm->fs.notify = usb_find_endpoint(ecm_fs_function,
673 f->descriptors, &fs_ecm_notify_desc);
674
675 /* support all relevant hardware speeds... we expect that when 741 /* support all relevant hardware speeds... we expect that when
676 * hardware is dual speed, all bulk-capable endpoints work at 742 * hardware is dual speed, all bulk-capable endpoints work at
677 * both speeds 743 * both speeds
@@ -688,13 +754,20 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
688 f->hs_descriptors = usb_copy_descriptors(ecm_hs_function); 754 f->hs_descriptors = usb_copy_descriptors(ecm_hs_function);
689 if (!f->hs_descriptors) 755 if (!f->hs_descriptors)
690 goto fail; 756 goto fail;
757 }
691 758
692 ecm->hs.in = usb_find_endpoint(ecm_hs_function, 759 if (gadget_is_superspeed(c->cdev->gadget)) {
693 f->hs_descriptors, &hs_ecm_in_desc); 760 ss_ecm_in_desc.bEndpointAddress =
694 ecm->hs.out = usb_find_endpoint(ecm_hs_function, 761 fs_ecm_in_desc.bEndpointAddress;
695 f->hs_descriptors, &hs_ecm_out_desc); 762 ss_ecm_out_desc.bEndpointAddress =
696 ecm->hs.notify = usb_find_endpoint(ecm_hs_function, 763 fs_ecm_out_desc.bEndpointAddress;
697 f->hs_descriptors, &hs_ecm_notify_desc); 764 ss_ecm_notify_desc.bEndpointAddress =
765 fs_ecm_notify_desc.bEndpointAddress;
766
767 /* copy descriptors, and track endpoint copies */
768 f->ss_descriptors = usb_copy_descriptors(ecm_ss_function);
769 if (!f->ss_descriptors)
770 goto fail;
698 } 771 }
699 772
700 /* NOTE: all that is done without knowing or caring about 773 /* NOTE: all that is done without knowing or caring about
@@ -706,6 +779,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
706 ecm->port.close = ecm_close; 779 ecm->port.close = ecm_close;
707 780
708 DBG(cdev, "CDC Ethernet: %s speed IN/%s OUT/%s NOTIFY/%s\n", 781 DBG(cdev, "CDC Ethernet: %s speed IN/%s OUT/%s NOTIFY/%s\n",
782 gadget_is_superspeed(c->cdev->gadget) ? "super" :
709 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 783 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
710 ecm->port.in_ep->name, ecm->port.out_ep->name, 784 ecm->port.in_ep->name, ecm->port.out_ep->name,
711 ecm->notify->name); 785 ecm->notify->name);
@@ -714,6 +788,8 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
714fail: 788fail:
715 if (f->descriptors) 789 if (f->descriptors)
716 usb_free_descriptors(f->descriptors); 790 usb_free_descriptors(f->descriptors);
791 if (f->hs_descriptors)
792 usb_free_descriptors(f->hs_descriptors);
717 793
718 if (ecm->notify_req) { 794 if (ecm->notify_req) {
719 kfree(ecm->notify_req->buf); 795 kfree(ecm->notify_req->buf);
@@ -723,9 +799,9 @@ fail:
723 /* we might as well release our claims on endpoints */ 799 /* we might as well release our claims on endpoints */
724 if (ecm->notify) 800 if (ecm->notify)
725 ecm->notify->driver_data = NULL; 801 ecm->notify->driver_data = NULL;
726 if (ecm->port.out) 802 if (ecm->port.out_ep->desc)
727 ecm->port.out_ep->driver_data = NULL; 803 ecm->port.out_ep->driver_data = NULL;
728 if (ecm->port.in) 804 if (ecm->port.in_ep->desc)
729 ecm->port.in_ep->driver_data = NULL; 805 ecm->port.in_ep->driver_data = NULL;
730 806
731 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 807 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
@@ -740,6 +816,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f)
740 816
741 DBG(c->cdev, "ecm unbind\n"); 817 DBG(c->cdev, "ecm unbind\n");
742 818
819 if (gadget_is_superspeed(c->cdev->gadget))
820 usb_free_descriptors(f->ss_descriptors);
743 if (gadget_is_dualspeed(c->cdev->gadget)) 821 if (gadget_is_dualspeed(c->cdev->gadget))
744 usb_free_descriptors(f->hs_descriptors); 822 usb_free_descriptors(f->hs_descriptors);
745 usb_free_descriptors(f->descriptors); 823 usb_free_descriptors(f->descriptors);
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index b3c304290150..046c6d0e6960 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -35,17 +35,9 @@
35 * Ethernet link. 35 * Ethernet link.
36 */ 36 */
37 37
38struct eem_ep_descs {
39 struct usb_endpoint_descriptor *in;
40 struct usb_endpoint_descriptor *out;
41};
42
43struct f_eem { 38struct f_eem {
44 struct gether port; 39 struct gether port;
45 u8 ctrl_id; 40 u8 ctrl_id;
46
47 struct eem_ep_descs fs;
48 struct eem_ep_descs hs;
49}; 41};
50 42
51static inline struct f_eem *func_to_eem(struct usb_function *f) 43static inline struct f_eem *func_to_eem(struct usb_function *f)
@@ -123,6 +115,45 @@ static struct usb_descriptor_header *eem_hs_function[] __initdata = {
123 NULL, 115 NULL,
124}; 116};
125 117
118/* super speed support: */
119
120static struct usb_endpoint_descriptor eem_ss_in_desc __initdata = {
121 .bLength = USB_DT_ENDPOINT_SIZE,
122 .bDescriptorType = USB_DT_ENDPOINT,
123
124 .bEndpointAddress = USB_DIR_IN,
125 .bmAttributes = USB_ENDPOINT_XFER_BULK,
126 .wMaxPacketSize = cpu_to_le16(1024),
127};
128
129static struct usb_endpoint_descriptor eem_ss_out_desc __initdata = {
130 .bLength = USB_DT_ENDPOINT_SIZE,
131 .bDescriptorType = USB_DT_ENDPOINT,
132
133 .bEndpointAddress = USB_DIR_OUT,
134 .bmAttributes = USB_ENDPOINT_XFER_BULK,
135 .wMaxPacketSize = cpu_to_le16(1024),
136};
137
138static struct usb_ss_ep_comp_descriptor eem_ss_bulk_comp_desc __initdata = {
139 .bLength = sizeof eem_ss_bulk_comp_desc,
140 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
141
142 /* the following 2 values can be tweaked if necessary */
143 /* .bMaxBurst = 0, */
144 /* .bmAttributes = 0, */
145};
146
147static struct usb_descriptor_header *eem_ss_function[] __initdata = {
148 /* CDC EEM control descriptors */
149 (struct usb_descriptor_header *) &eem_intf,
150 (struct usb_descriptor_header *) &eem_ss_in_desc,
151 (struct usb_descriptor_header *) &eem_ss_bulk_comp_desc,
152 (struct usb_descriptor_header *) &eem_ss_out_desc,
153 (struct usb_descriptor_header *) &eem_ss_bulk_comp_desc,
154 NULL,
155};
156
126/* string descriptors: */ 157/* string descriptors: */
127 158
128static struct usb_string eem_string_defs[] = { 159static struct usb_string eem_string_defs[] = {
@@ -176,12 +207,16 @@ static int eem_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
176 gether_disconnect(&eem->port); 207 gether_disconnect(&eem->port);
177 } 208 }
178 209
179 if (!eem->port.in) { 210 if (!eem->port.in_ep->desc || !eem->port.out_ep->desc) {
180 DBG(cdev, "init eem\n"); 211 DBG(cdev, "init eem\n");
181 eem->port.in = ep_choose(cdev->gadget, 212 if (config_ep_by_speed(cdev->gadget, f,
182 eem->hs.in, eem->fs.in); 213 eem->port.in_ep) ||
183 eem->port.out = ep_choose(cdev->gadget, 214 config_ep_by_speed(cdev->gadget, f,
184 eem->hs.out, eem->fs.out); 215 eem->port.out_ep)) {
216 eem->port.in_ep->desc = NULL;
217 eem->port.out_ep->desc = NULL;
218 goto fail;
219 }
185 } 220 }
186 221
187 /* zlps should not occur because zero-length EEM packets 222 /* zlps should not occur because zero-length EEM packets
@@ -253,11 +288,6 @@ eem_bind(struct usb_configuration *c, struct usb_function *f)
253 if (!f->descriptors) 288 if (!f->descriptors)
254 goto fail; 289 goto fail;
255 290
256 eem->fs.in = usb_find_endpoint(eem_fs_function,
257 f->descriptors, &eem_fs_in_desc);
258 eem->fs.out = usb_find_endpoint(eem_fs_function,
259 f->descriptors, &eem_fs_out_desc);
260
261 /* support all relevant hardware speeds... we expect that when 291 /* support all relevant hardware speeds... we expect that when
262 * hardware is dual speed, all bulk-capable endpoints work at 292 * hardware is dual speed, all bulk-capable endpoints work at
263 * both speeds 293 * both speeds
@@ -272,14 +302,22 @@ eem_bind(struct usb_configuration *c, struct usb_function *f)
272 f->hs_descriptors = usb_copy_descriptors(eem_hs_function); 302 f->hs_descriptors = usb_copy_descriptors(eem_hs_function);
273 if (!f->hs_descriptors) 303 if (!f->hs_descriptors)
274 goto fail; 304 goto fail;
305 }
306
307 if (gadget_is_superspeed(c->cdev->gadget)) {
308 eem_ss_in_desc.bEndpointAddress =
309 eem_fs_in_desc.bEndpointAddress;
310 eem_ss_out_desc.bEndpointAddress =
311 eem_fs_out_desc.bEndpointAddress;
275 312
276 eem->hs.in = usb_find_endpoint(eem_hs_function, 313 /* copy descriptors, and track endpoint copies */
277 f->hs_descriptors, &eem_hs_in_desc); 314 f->ss_descriptors = usb_copy_descriptors(eem_ss_function);
278 eem->hs.out = usb_find_endpoint(eem_hs_function, 315 if (!f->ss_descriptors)
279 f->hs_descriptors, &eem_hs_out_desc); 316 goto fail;
280 } 317 }
281 318
282 DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n", 319 DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n",
320 gadget_is_superspeed(c->cdev->gadget) ? "super" :
283 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 321 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
284 eem->port.in_ep->name, eem->port.out_ep->name); 322 eem->port.in_ep->name, eem->port.out_ep->name);
285 return 0; 323 return 0;
@@ -287,11 +325,13 @@ eem_bind(struct usb_configuration *c, struct usb_function *f)
287fail: 325fail:
288 if (f->descriptors) 326 if (f->descriptors)
289 usb_free_descriptors(f->descriptors); 327 usb_free_descriptors(f->descriptors);
328 if (f->hs_descriptors)
329 usb_free_descriptors(f->hs_descriptors);
290 330
291 /* we might as well release our claims on endpoints */ 331 /* we might as well release our claims on endpoints */
292 if (eem->port.out) 332 if (eem->port.out_ep->desc)
293 eem->port.out_ep->driver_data = NULL; 333 eem->port.out_ep->driver_data = NULL;
294 if (eem->port.in) 334 if (eem->port.in_ep->desc)
295 eem->port.in_ep->driver_data = NULL; 335 eem->port.in_ep->driver_data = NULL;
296 336
297 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 337 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
@@ -306,6 +346,8 @@ eem_unbind(struct usb_configuration *c, struct usb_function *f)
306 346
307 DBG(c->cdev, "eem unbind\n"); 347 DBG(c->cdev, "eem unbind\n");
308 348
349 if (gadget_is_superspeed(c->cdev->gadget))
350 usb_free_descriptors(f->ss_descriptors);
309 if (gadget_is_dualspeed(c->cdev->gadget)) 351 if (gadget_is_dualspeed(c->cdev->gadget))
310 usb_free_descriptors(f->hs_descriptors); 352 usb_free_descriptors(f->hs_descriptors);
311 usb_free_descriptors(f->descriptors); 353 usb_free_descriptors(f->descriptors);
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 19fffccc370d..c161a9aaeb7e 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -1544,7 +1544,8 @@ static int ffs_func_eps_enable(struct ffs_function *func)
1544 ds = ep->descs[ep->descs[1] ? 1 : 0]; 1544 ds = ep->descs[ep->descs[1] ? 1 : 0];
1545 1545
1546 ep->ep->driver_data = ep; 1546 ep->ep->driver_data = ep;
1547 ret = usb_ep_enable(ep->ep, ds); 1547 ep->ep->desc = ds;
1548 ret = usb_ep_enable(ep->ep);
1548 if (likely(!ret)) { 1549 if (likely(!ret)) {
1549 epfile->ep = ep; 1550 epfile->ep = ep;
1550 epfile->in = usb_endpoint_dir_in(ds); 1551 epfile->in = usb_endpoint_dir_in(ds);
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c
index 598e7e2ab80c..403a48bcf560 100644
--- a/drivers/usb/gadget/f_hid.c
+++ b/drivers/usb/gadget/f_hid.c
@@ -59,8 +59,6 @@ struct f_hidg {
59 struct cdev cdev; 59 struct cdev cdev;
60 struct usb_function func; 60 struct usb_function func;
61 struct usb_ep *in_ep; 61 struct usb_ep *in_ep;
62 struct usb_endpoint_descriptor *fs_in_ep_desc;
63 struct usb_endpoint_descriptor *hs_in_ep_desc;
64}; 62};
65 63
66static inline struct f_hidg *func_to_hidg(struct usb_function *f) 64static inline struct f_hidg *func_to_hidg(struct usb_function *f)
@@ -416,7 +414,6 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
416{ 414{
417 struct usb_composite_dev *cdev = f->config->cdev; 415 struct usb_composite_dev *cdev = f->config->cdev;
418 struct f_hidg *hidg = func_to_hidg(f); 416 struct f_hidg *hidg = func_to_hidg(f);
419 const struct usb_endpoint_descriptor *ep_desc;
420 int status = 0; 417 int status = 0;
421 418
422 VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt); 419 VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt);
@@ -426,9 +423,13 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
426 if (hidg->in_ep->driver_data != NULL) 423 if (hidg->in_ep->driver_data != NULL)
427 usb_ep_disable(hidg->in_ep); 424 usb_ep_disable(hidg->in_ep);
428 425
429 ep_desc = ep_choose(f->config->cdev->gadget, 426 status = config_ep_by_speed(f->config->cdev->gadget, f,
430 hidg->hs_in_ep_desc, hidg->fs_in_ep_desc); 427 hidg->in_ep);
431 status = usb_ep_enable(hidg->in_ep, ep_desc); 428 if (status) {
429 ERROR(cdev, "config_ep_by_speed FAILED!\n");
430 goto fail;
431 }
432 status = usb_ep_enable(hidg->in_ep);
432 if (status < 0) { 433 if (status < 0) {
433 ERROR(cdev, "Enable endpoint FAILED!\n"); 434 ERROR(cdev, "Enable endpoint FAILED!\n");
434 goto fail; 435 goto fail;
@@ -498,21 +499,12 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
498 if (!f->descriptors) 499 if (!f->descriptors)
499 goto fail; 500 goto fail;
500 501
501 hidg->fs_in_ep_desc = usb_find_endpoint(hidg_fs_descriptors,
502 f->descriptors,
503 &hidg_fs_in_ep_desc);
504
505 if (gadget_is_dualspeed(c->cdev->gadget)) { 502 if (gadget_is_dualspeed(c->cdev->gadget)) {
506 hidg_hs_in_ep_desc.bEndpointAddress = 503 hidg_hs_in_ep_desc.bEndpointAddress =
507 hidg_fs_in_ep_desc.bEndpointAddress; 504 hidg_fs_in_ep_desc.bEndpointAddress;
508 f->hs_descriptors = usb_copy_descriptors(hidg_hs_descriptors); 505 f->hs_descriptors = usb_copy_descriptors(hidg_hs_descriptors);
509 if (!f->hs_descriptors) 506 if (!f->hs_descriptors)
510 goto fail; 507 goto fail;
511 hidg->hs_in_ep_desc = usb_find_endpoint(hidg_hs_descriptors,
512 f->hs_descriptors,
513 &hidg_hs_in_ep_desc);
514 } else {
515 hidg->hs_in_ep_desc = NULL;
516 } 508 }
517 509
518 mutex_init(&hidg->lock); 510 mutex_init(&hidg->lock);
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index b37960f9e753..ca660d40b11a 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -118,6 +118,49 @@ static struct usb_descriptor_header *hs_loopback_descs[] = {
118 NULL, 118 NULL,
119}; 119};
120 120
121/* super speed support: */
122
123static struct usb_endpoint_descriptor ss_loop_source_desc = {
124 .bLength = USB_DT_ENDPOINT_SIZE,
125 .bDescriptorType = USB_DT_ENDPOINT,
126
127 .bmAttributes = USB_ENDPOINT_XFER_BULK,
128 .wMaxPacketSize = cpu_to_le16(1024),
129};
130
131struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = {
132 .bLength = USB_DT_SS_EP_COMP_SIZE,
133 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
134 .bMaxBurst = 0,
135 .bmAttributes = 0,
136 .wBytesPerInterval = 0,
137};
138
139static struct usb_endpoint_descriptor ss_loop_sink_desc = {
140 .bLength = USB_DT_ENDPOINT_SIZE,
141 .bDescriptorType = USB_DT_ENDPOINT,
142
143 .bmAttributes = USB_ENDPOINT_XFER_BULK,
144 .wMaxPacketSize = cpu_to_le16(1024),
145};
146
147struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = {
148 .bLength = USB_DT_SS_EP_COMP_SIZE,
149 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
150 .bMaxBurst = 0,
151 .bmAttributes = 0,
152 .wBytesPerInterval = 0,
153};
154
155static struct usb_descriptor_header *ss_loopback_descs[] = {
156 (struct usb_descriptor_header *) &loopback_intf,
157 (struct usb_descriptor_header *) &ss_loop_source_desc,
158 (struct usb_descriptor_header *) &ss_loop_source_comp_desc,
159 (struct usb_descriptor_header *) &ss_loop_sink_desc,
160 (struct usb_descriptor_header *) &ss_loop_sink_comp_desc,
161 NULL,
162};
163
121/* function-specific strings: */ 164/* function-specific strings: */
122 165
123static struct usb_string strings_loopback[] = { 166static struct usb_string strings_loopback[] = {
@@ -175,8 +218,18 @@ autoconf_fail:
175 f->hs_descriptors = hs_loopback_descs; 218 f->hs_descriptors = hs_loopback_descs;
176 } 219 }
177 220
221 /* support super speed hardware */
222 if (gadget_is_superspeed(c->cdev->gadget)) {
223 ss_loop_source_desc.bEndpointAddress =
224 fs_loop_source_desc.bEndpointAddress;
225 ss_loop_sink_desc.bEndpointAddress =
226 fs_loop_sink_desc.bEndpointAddress;
227 f->ss_descriptors = ss_loopback_descs;
228 }
229
178 DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", 230 DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n",
179 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 231 (gadget_is_superspeed(c->cdev->gadget) ? "super" :
232 (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")),
180 f->name, loop->in_ep->name, loop->out_ep->name); 233 f->name, loop->in_ep->name, loop->out_ep->name);
181 return 0; 234 return 0;
182} 235}
@@ -250,26 +303,27 @@ static int
250enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) 303enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop)
251{ 304{
252 int result = 0; 305 int result = 0;
253 const struct usb_endpoint_descriptor *src, *sink;
254 struct usb_ep *ep; 306 struct usb_ep *ep;
255 struct usb_request *req; 307 struct usb_request *req;
256 unsigned i; 308 unsigned i;
257 309
258 src = ep_choose(cdev->gadget,
259 &hs_loop_source_desc, &fs_loop_source_desc);
260 sink = ep_choose(cdev->gadget,
261 &hs_loop_sink_desc, &fs_loop_sink_desc);
262
263 /* one endpoint writes data back IN to the host */ 310 /* one endpoint writes data back IN to the host */
264 ep = loop->in_ep; 311 ep = loop->in_ep;
265 result = usb_ep_enable(ep, src); 312 result = config_ep_by_speed(cdev->gadget, &(loop->function), ep);
313 if (result)
314 return result;
315 result = usb_ep_enable(ep);
266 if (result < 0) 316 if (result < 0)
267 return result; 317 return result;
268 ep->driver_data = loop; 318 ep->driver_data = loop;
269 319
270 /* one endpoint just reads OUT packets */ 320 /* one endpoint just reads OUT packets */
271 ep = loop->out_ep; 321 ep = loop->out_ep;
272 result = usb_ep_enable(ep, sink); 322 result = config_ep_by_speed(cdev->gadget, &(loop->function), ep);
323 if (result)
324 goto fail0;
325
326 result = usb_ep_enable(ep);
273 if (result < 0) { 327 if (result < 0) {
274fail0: 328fail0:
275 ep = loop->in_ep; 329 ep = loop->in_ep;
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index efb58f9f5aa9..5b9339582007 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2324,18 +2324,6 @@ static int get_next_command(struct fsg_common *common)
2324 2324
2325/*-------------------------------------------------------------------------*/ 2325/*-------------------------------------------------------------------------*/
2326 2326
2327static int enable_endpoint(struct fsg_common *common, struct usb_ep *ep,
2328 const struct usb_endpoint_descriptor *d)
2329{
2330 int rc;
2331
2332 ep->driver_data = common;
2333 rc = usb_ep_enable(ep, d);
2334 if (rc)
2335 ERROR(common, "can't enable %s, result %d\n", ep->name, rc);
2336 return rc;
2337}
2338
2339static int alloc_request(struct fsg_common *common, struct usb_ep *ep, 2327static int alloc_request(struct fsg_common *common, struct usb_ep *ep,
2340 struct usb_request **preq) 2328 struct usb_request **preq)
2341{ 2329{
@@ -2349,7 +2337,6 @@ static int alloc_request(struct fsg_common *common, struct usb_ep *ep,
2349/* Reset interface setting and re-init endpoint state (toggle etc). */ 2337/* Reset interface setting and re-init endpoint state (toggle etc). */
2350static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg) 2338static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg)
2351{ 2339{
2352 const struct usb_endpoint_descriptor *d;
2353 struct fsg_dev *fsg; 2340 struct fsg_dev *fsg;
2354 int i, rc = 0; 2341 int i, rc = 0;
2355 2342
@@ -2396,20 +2383,26 @@ reset:
2396 fsg = common->fsg; 2383 fsg = common->fsg;
2397 2384
2398 /* Enable the endpoints */ 2385 /* Enable the endpoints */
2399 d = fsg_ep_desc(common->gadget, 2386 rc = config_ep_by_speed(common->gadget, &(fsg->function), fsg->bulk_in);
2400 &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc); 2387 if (rc)
2401 rc = enable_endpoint(common, fsg->bulk_in, d); 2388 goto reset;
2389 rc = usb_ep_enable(fsg->bulk_in);
2402 if (rc) 2390 if (rc)
2403 goto reset; 2391 goto reset;
2392 fsg->bulk_in->driver_data = common;
2404 fsg->bulk_in_enabled = 1; 2393 fsg->bulk_in_enabled = 1;
2405 2394
2406 d = fsg_ep_desc(common->gadget, 2395 rc = config_ep_by_speed(common->gadget, &(fsg->function),
2407 &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc); 2396 fsg->bulk_out);
2408 rc = enable_endpoint(common, fsg->bulk_out, d); 2397 if (rc)
2398 goto reset;
2399 rc = usb_ep_enable(fsg->bulk_out);
2409 if (rc) 2400 if (rc)
2410 goto reset; 2401 goto reset;
2402 fsg->bulk_out->driver_data = common;
2411 fsg->bulk_out_enabled = 1; 2403 fsg->bulk_out_enabled = 1;
2412 common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); 2404 common->bulk_out_maxpacket =
2405 le16_to_cpu(fsg->bulk_out->desc->wMaxPacketSize);
2413 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2406 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2414 2407
2415 /* Allocate the requests */ 2408 /* Allocate the requests */
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c
index 86902a60bcdb..ae69ed7e6b99 100644
--- a/drivers/usb/gadget/f_ncm.c
+++ b/drivers/usb/gadget/f_ncm.c
@@ -48,12 +48,6 @@
48#define NCM_NDP_HDR_CRC 0x01000000 48#define NCM_NDP_HDR_CRC 0x01000000
49#define NCM_NDP_HDR_NOCRC 0x00000000 49#define NCM_NDP_HDR_NOCRC 0x00000000
50 50
51struct ncm_ep_descs {
52 struct usb_endpoint_descriptor *in;
53 struct usb_endpoint_descriptor *out;
54 struct usb_endpoint_descriptor *notify;
55};
56
57enum ncm_notify_state { 51enum ncm_notify_state {
58 NCM_NOTIFY_NONE, /* don't notify */ 52 NCM_NOTIFY_NONE, /* don't notify */
59 NCM_NOTIFY_CONNECT, /* issue CONNECT next */ 53 NCM_NOTIFY_CONNECT, /* issue CONNECT next */
@@ -66,11 +60,7 @@ struct f_ncm {
66 60
67 char ethaddr[14]; 61 char ethaddr[14];
68 62
69 struct ncm_ep_descs fs;
70 struct ncm_ep_descs hs;
71
72 struct usb_ep *notify; 63 struct usb_ep *notify;
73 struct usb_endpoint_descriptor *notify_desc;
74 struct usb_request *notify_req; 64 struct usb_request *notify_req;
75 u8 notify_state; 65 u8 notify_state;
76 bool is_open; 66 bool is_open;
@@ -802,13 +792,14 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
802 if (ncm->notify->driver_data) { 792 if (ncm->notify->driver_data) {
803 DBG(cdev, "reset ncm control %d\n", intf); 793 DBG(cdev, "reset ncm control %d\n", intf);
804 usb_ep_disable(ncm->notify); 794 usb_ep_disable(ncm->notify);
805 } else { 795 }
796
797 if (!(ncm->notify->desc)) {
806 DBG(cdev, "init ncm ctrl %d\n", intf); 798 DBG(cdev, "init ncm ctrl %d\n", intf);
807 ncm->notify_desc = ep_choose(cdev->gadget, 799 if (config_ep_by_speed(cdev->gadget, f, ncm->notify))
808 ncm->hs.notify, 800 goto fail;
809 ncm->fs.notify);
810 } 801 }
811 usb_ep_enable(ncm->notify, ncm->notify_desc); 802 usb_ep_enable(ncm->notify);
812 ncm->notify->driver_data = ncm; 803 ncm->notify->driver_data = ncm;
813 804
814 /* Data interface has two altsettings, 0 and 1 */ 805 /* Data interface has two altsettings, 0 and 1 */
@@ -829,14 +820,17 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
829 if (alt == 1) { 820 if (alt == 1) {
830 struct net_device *net; 821 struct net_device *net;
831 822
832 if (!ncm->port.in) { 823 if (!ncm->port.in_ep->desc ||
824 !ncm->port.out_ep->desc) {
833 DBG(cdev, "init ncm\n"); 825 DBG(cdev, "init ncm\n");
834 ncm->port.in = ep_choose(cdev->gadget, 826 if (config_ep_by_speed(cdev->gadget, f,
835 ncm->hs.in, 827 ncm->port.in_ep) ||
836 ncm->fs.in); 828 config_ep_by_speed(cdev->gadget, f,
837 ncm->port.out = ep_choose(cdev->gadget, 829 ncm->port.out_ep)) {
838 ncm->hs.out, 830 ncm->port.in_ep->desc = NULL;
839 ncm->fs.out); 831 ncm->port.out_ep->desc = NULL;
832 goto fail;
833 }
840 } 834 }
841 835
842 /* TODO */ 836 /* TODO */
@@ -1111,7 +1105,7 @@ static void ncm_disable(struct usb_function *f)
1111 if (ncm->notify->driver_data) { 1105 if (ncm->notify->driver_data) {
1112 usb_ep_disable(ncm->notify); 1106 usb_ep_disable(ncm->notify);
1113 ncm->notify->driver_data = NULL; 1107 ncm->notify->driver_data = NULL;
1114 ncm->notify_desc = NULL; 1108 ncm->notify->desc = NULL;
1115 } 1109 }
1116} 1110}
1117 1111
@@ -1228,13 +1222,6 @@ ncm_bind(struct usb_configuration *c, struct usb_function *f)
1228 if (!f->descriptors) 1222 if (!f->descriptors)
1229 goto fail; 1223 goto fail;
1230 1224
1231 ncm->fs.in = usb_find_endpoint(ncm_fs_function,
1232 f->descriptors, &fs_ncm_in_desc);
1233 ncm->fs.out = usb_find_endpoint(ncm_fs_function,
1234 f->descriptors, &fs_ncm_out_desc);
1235 ncm->fs.notify = usb_find_endpoint(ncm_fs_function,
1236 f->descriptors, &fs_ncm_notify_desc);
1237
1238 /* 1225 /*
1239 * support all relevant hardware speeds... we expect that when 1226 * support all relevant hardware speeds... we expect that when
1240 * hardware is dual speed, all bulk-capable endpoints work at 1227 * hardware is dual speed, all bulk-capable endpoints work at
@@ -1252,13 +1239,6 @@ ncm_bind(struct usb_configuration *c, struct usb_function *f)
1252 f->hs_descriptors = usb_copy_descriptors(ncm_hs_function); 1239 f->hs_descriptors = usb_copy_descriptors(ncm_hs_function);
1253 if (!f->hs_descriptors) 1240 if (!f->hs_descriptors)
1254 goto fail; 1241 goto fail;
1255
1256 ncm->hs.in = usb_find_endpoint(ncm_hs_function,
1257 f->hs_descriptors, &hs_ncm_in_desc);
1258 ncm->hs.out = usb_find_endpoint(ncm_hs_function,
1259 f->hs_descriptors, &hs_ncm_out_desc);
1260 ncm->hs.notify = usb_find_endpoint(ncm_hs_function,
1261 f->hs_descriptors, &hs_ncm_notify_desc);
1262 } 1242 }
1263 1243
1264 /* 1244 /*
@@ -1288,9 +1268,9 @@ fail:
1288 /* we might as well release our claims on endpoints */ 1268 /* we might as well release our claims on endpoints */
1289 if (ncm->notify) 1269 if (ncm->notify)
1290 ncm->notify->driver_data = NULL; 1270 ncm->notify->driver_data = NULL;
1291 if (ncm->port.out) 1271 if (ncm->port.out_ep->desc)
1292 ncm->port.out_ep->driver_data = NULL; 1272 ncm->port.out_ep->driver_data = NULL;
1293 if (ncm->port.in) 1273 if (ncm->port.in_ep->desc)
1294 ncm->port.in_ep->driver_data = NULL; 1274 ncm->port.in_ep->driver_data = NULL;
1295 1275
1296 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 1276 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index 8f8c64371475..394502abeb96 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -39,20 +39,12 @@
39 * ready to handle the commands. 39 * ready to handle the commands.
40 */ 40 */
41 41
42struct obex_ep_descs {
43 struct usb_endpoint_descriptor *obex_in;
44 struct usb_endpoint_descriptor *obex_out;
45};
46
47struct f_obex { 42struct f_obex {
48 struct gserial port; 43 struct gserial port;
49 u8 ctrl_id; 44 u8 ctrl_id;
50 u8 data_id; 45 u8 data_id;
51 u8 port_num; 46 u8 port_num;
52 u8 can_activate; 47 u8 can_activate;
53
54 struct obex_ep_descs fs;
55 struct obex_ep_descs hs;
56}; 48};
57 49
58static inline struct f_obex *func_to_obex(struct usb_function *f) 50static inline struct f_obex *func_to_obex(struct usb_function *f)
@@ -227,12 +219,16 @@ static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
227 gserial_disconnect(&obex->port); 219 gserial_disconnect(&obex->port);
228 } 220 }
229 221
230 if (!obex->port.in_desc) { 222 if (!obex->port.in->desc || !obex->port.out->desc) {
231 DBG(cdev, "init obex ttyGS%d\n", obex->port_num); 223 DBG(cdev, "init obex ttyGS%d\n", obex->port_num);
232 obex->port.in_desc = ep_choose(cdev->gadget, 224 if (config_ep_by_speed(cdev->gadget, f,
233 obex->hs.obex_in, obex->fs.obex_in); 225 obex->port.in) ||
234 obex->port.out_desc = ep_choose(cdev->gadget, 226 config_ep_by_speed(cdev->gadget, f,
235 obex->hs.obex_out, obex->fs.obex_out); 227 obex->port.out)) {
228 obex->port.out->desc = NULL;
229 obex->port.in->desc = NULL;
230 goto fail;
231 }
236 } 232 }
237 233
238 if (alt == 1) { 234 if (alt == 1) {
@@ -346,11 +342,6 @@ obex_bind(struct usb_configuration *c, struct usb_function *f)
346 /* copy descriptors, and track endpoint copies */ 342 /* copy descriptors, and track endpoint copies */
347 f->descriptors = usb_copy_descriptors(fs_function); 343 f->descriptors = usb_copy_descriptors(fs_function);
348 344
349 obex->fs.obex_in = usb_find_endpoint(fs_function,
350 f->descriptors, &obex_fs_ep_in_desc);
351 obex->fs.obex_out = usb_find_endpoint(fs_function,
352 f->descriptors, &obex_fs_ep_out_desc);
353
354 /* support all relevant hardware speeds... we expect that when 345 /* support all relevant hardware speeds... we expect that when
355 * hardware is dual speed, all bulk-capable endpoints work at 346 * hardware is dual speed, all bulk-capable endpoints work at
356 * both speeds 347 * both speeds
@@ -364,11 +355,6 @@ obex_bind(struct usb_configuration *c, struct usb_function *f)
364 355
365 /* copy descriptors, and track endpoint copies */ 356 /* copy descriptors, and track endpoint copies */
366 f->hs_descriptors = usb_copy_descriptors(hs_function); 357 f->hs_descriptors = usb_copy_descriptors(hs_function);
367
368 obex->hs.obex_in = usb_find_endpoint(hs_function,
369 f->hs_descriptors, &obex_hs_ep_in_desc);
370 obex->hs.obex_out = usb_find_endpoint(hs_function,
371 f->hs_descriptors, &obex_hs_ep_out_desc);
372 } 358 }
373 359
374 /* Avoid letting this gadget enumerate until the userspace 360 /* Avoid letting this gadget enumerate until the userspace
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index f22fc685ddfd..8f8d3f6cd89e 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -428,17 +428,16 @@ static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
428 spin_lock(&port->lock); 428 spin_lock(&port->lock);
429 __pn_reset(f); 429 __pn_reset(f);
430 if (alt == 1) { 430 if (alt == 1) {
431 struct usb_endpoint_descriptor *out, *in;
432 int i; 431 int i;
433 432
434 out = ep_choose(gadget, 433 if (config_ep_by_speed(gadget, f, fp->in_ep) ||
435 &pn_hs_sink_desc, 434 config_ep_by_speed(gadget, f, fp->out_ep)) {
436 &pn_fs_sink_desc); 435 fp->in_ep->desc = NULL;
437 in = ep_choose(gadget, 436 fp->out_ep->desc = NULL;
438 &pn_hs_source_desc, 437 return -EINVAL;
439 &pn_fs_source_desc); 438 }
440 usb_ep_enable(fp->out_ep, out); 439 usb_ep_enable(fp->out_ep);
441 usb_ep_enable(fp->in_ep, in); 440 usb_ep_enable(fp->in_ep);
442 441
443 port->usb = fp; 442 port->usb = fp;
444 fp->out_ep->driver_data = fp; 443 fp->out_ep->driver_data = fp;
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index fa12ec8364ef..8f3eae90919f 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -76,23 +76,13 @@
76 * - MS-Windows drivers sometimes emit undocumented requests. 76 * - MS-Windows drivers sometimes emit undocumented requests.
77 */ 77 */
78 78
79struct rndis_ep_descs {
80 struct usb_endpoint_descriptor *in;
81 struct usb_endpoint_descriptor *out;
82 struct usb_endpoint_descriptor *notify;
83};
84
85struct f_rndis { 79struct f_rndis {
86 struct gether port; 80 struct gether port;
87 u8 ctrl_id, data_id; 81 u8 ctrl_id, data_id;
88 u8 ethaddr[ETH_ALEN]; 82 u8 ethaddr[ETH_ALEN];
89 int config; 83 int config;
90 84
91 struct rndis_ep_descs fs;
92 struct rndis_ep_descs hs;
93
94 struct usb_ep *notify; 85 struct usb_ep *notify;
95 struct usb_endpoint_descriptor *notify_desc;
96 struct usb_request *notify_req; 86 struct usb_request *notify_req;
97 atomic_t notify_count; 87 atomic_t notify_count;
98}; 88};
@@ -105,10 +95,12 @@ static inline struct f_rndis *func_to_rndis(struct usb_function *f)
105/* peak (theoretical) bulk transfer rate in bits-per-second */ 95/* peak (theoretical) bulk transfer rate in bits-per-second */
106static unsigned int bitrate(struct usb_gadget *g) 96static unsigned int bitrate(struct usb_gadget *g)
107{ 97{
108 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 98 if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
99 return 13 * 1024 * 8 * 1000 * 8;
100 else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
109 return 13 * 512 * 8 * 1000 * 8; 101 return 13 * 512 * 8 * 1000 * 8;
110 else 102 else
111 return 19 * 64 * 1 * 1000 * 8; 103 return 19 * 64 * 1 * 1000 * 8;
112} 104}
113 105
114/*-------------------------------------------------------------------------*/ 106/*-------------------------------------------------------------------------*/
@@ -226,6 +218,7 @@ static struct usb_endpoint_descriptor fs_out_desc = {
226 218
227static struct usb_descriptor_header *eth_fs_function[] = { 219static struct usb_descriptor_header *eth_fs_function[] = {
228 (struct usb_descriptor_header *) &rndis_iad_descriptor, 220 (struct usb_descriptor_header *) &rndis_iad_descriptor,
221
229 /* control interface matches ACM, not Ethernet */ 222 /* control interface matches ACM, not Ethernet */
230 (struct usb_descriptor_header *) &rndis_control_intf, 223 (struct usb_descriptor_header *) &rndis_control_intf,
231 (struct usb_descriptor_header *) &header_desc, 224 (struct usb_descriptor_header *) &header_desc,
@@ -233,6 +226,7 @@ static struct usb_descriptor_header *eth_fs_function[] = {
233 (struct usb_descriptor_header *) &rndis_acm_descriptor, 226 (struct usb_descriptor_header *) &rndis_acm_descriptor,
234 (struct usb_descriptor_header *) &rndis_union_desc, 227 (struct usb_descriptor_header *) &rndis_union_desc,
235 (struct usb_descriptor_header *) &fs_notify_desc, 228 (struct usb_descriptor_header *) &fs_notify_desc,
229
236 /* data interface has no altsetting */ 230 /* data interface has no altsetting */
237 (struct usb_descriptor_header *) &rndis_data_intf, 231 (struct usb_descriptor_header *) &rndis_data_intf,
238 (struct usb_descriptor_header *) &fs_in_desc, 232 (struct usb_descriptor_header *) &fs_in_desc,
@@ -251,6 +245,7 @@ static struct usb_endpoint_descriptor hs_notify_desc = {
251 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), 245 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
252 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 246 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
253}; 247};
248
254static struct usb_endpoint_descriptor hs_in_desc = { 249static struct usb_endpoint_descriptor hs_in_desc = {
255 .bLength = USB_DT_ENDPOINT_SIZE, 250 .bLength = USB_DT_ENDPOINT_SIZE,
256 .bDescriptorType = USB_DT_ENDPOINT, 251 .bDescriptorType = USB_DT_ENDPOINT,
@@ -271,6 +266,7 @@ static struct usb_endpoint_descriptor hs_out_desc = {
271 266
272static struct usb_descriptor_header *eth_hs_function[] = { 267static struct usb_descriptor_header *eth_hs_function[] = {
273 (struct usb_descriptor_header *) &rndis_iad_descriptor, 268 (struct usb_descriptor_header *) &rndis_iad_descriptor,
269
274 /* control interface matches ACM, not Ethernet */ 270 /* control interface matches ACM, not Ethernet */
275 (struct usb_descriptor_header *) &rndis_control_intf, 271 (struct usb_descriptor_header *) &rndis_control_intf,
276 (struct usb_descriptor_header *) &header_desc, 272 (struct usb_descriptor_header *) &header_desc,
@@ -278,6 +274,7 @@ static struct usb_descriptor_header *eth_hs_function[] = {
278 (struct usb_descriptor_header *) &rndis_acm_descriptor, 274 (struct usb_descriptor_header *) &rndis_acm_descriptor,
279 (struct usb_descriptor_header *) &rndis_union_desc, 275 (struct usb_descriptor_header *) &rndis_union_desc,
280 (struct usb_descriptor_header *) &hs_notify_desc, 276 (struct usb_descriptor_header *) &hs_notify_desc,
277
281 /* data interface has no altsetting */ 278 /* data interface has no altsetting */
282 (struct usb_descriptor_header *) &rndis_data_intf, 279 (struct usb_descriptor_header *) &rndis_data_intf,
283 (struct usb_descriptor_header *) &hs_in_desc, 280 (struct usb_descriptor_header *) &hs_in_desc,
@@ -285,6 +282,76 @@ static struct usb_descriptor_header *eth_hs_function[] = {
285 NULL, 282 NULL,
286}; 283};
287 284
285/* super speed support: */
286
287static struct usb_endpoint_descriptor ss_notify_desc = {
288 .bLength = USB_DT_ENDPOINT_SIZE,
289 .bDescriptorType = USB_DT_ENDPOINT,
290
291 .bEndpointAddress = USB_DIR_IN,
292 .bmAttributes = USB_ENDPOINT_XFER_INT,
293 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
294 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
295};
296
297static struct usb_ss_ep_comp_descriptor ss_intr_comp_desc = {
298 .bLength = sizeof ss_intr_comp_desc,
299 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
300
301 /* the following 3 values can be tweaked if necessary */
302 /* .bMaxBurst = 0, */
303 /* .bmAttributes = 0, */
304 .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT),
305};
306
307static struct usb_endpoint_descriptor ss_in_desc = {
308 .bLength = USB_DT_ENDPOINT_SIZE,
309 .bDescriptorType = USB_DT_ENDPOINT,
310
311 .bEndpointAddress = USB_DIR_IN,
312 .bmAttributes = USB_ENDPOINT_XFER_BULK,
313 .wMaxPacketSize = cpu_to_le16(1024),
314};
315
316static struct usb_endpoint_descriptor ss_out_desc = {
317 .bLength = USB_DT_ENDPOINT_SIZE,
318 .bDescriptorType = USB_DT_ENDPOINT,
319
320 .bEndpointAddress = USB_DIR_OUT,
321 .bmAttributes = USB_ENDPOINT_XFER_BULK,
322 .wMaxPacketSize = cpu_to_le16(1024),
323};
324
325static struct usb_ss_ep_comp_descriptor ss_bulk_comp_desc = {
326 .bLength = sizeof ss_bulk_comp_desc,
327 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
328
329 /* the following 2 values can be tweaked if necessary */
330 /* .bMaxBurst = 0, */
331 /* .bmAttributes = 0, */
332};
333
334static struct usb_descriptor_header *eth_ss_function[] = {
335 (struct usb_descriptor_header *) &rndis_iad_descriptor,
336
337 /* control interface matches ACM, not Ethernet */
338 (struct usb_descriptor_header *) &rndis_control_intf,
339 (struct usb_descriptor_header *) &header_desc,
340 (struct usb_descriptor_header *) &call_mgmt_descriptor,
341 (struct usb_descriptor_header *) &rndis_acm_descriptor,
342 (struct usb_descriptor_header *) &rndis_union_desc,
343 (struct usb_descriptor_header *) &ss_notify_desc,
344 (struct usb_descriptor_header *) &ss_intr_comp_desc,
345
346 /* data interface has no altsetting */
347 (struct usb_descriptor_header *) &rndis_data_intf,
348 (struct usb_descriptor_header *) &ss_in_desc,
349 (struct usb_descriptor_header *) &ss_bulk_comp_desc,
350 (struct usb_descriptor_header *) &ss_out_desc,
351 (struct usb_descriptor_header *) &ss_bulk_comp_desc,
352 NULL,
353};
354
288/* string descriptors: */ 355/* string descriptors: */
289 356
290static struct usb_string rndis_string_defs[] = { 357static struct usb_string rndis_string_defs[] = {
@@ -484,13 +551,13 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
484 if (rndis->notify->driver_data) { 551 if (rndis->notify->driver_data) {
485 VDBG(cdev, "reset rndis control %d\n", intf); 552 VDBG(cdev, "reset rndis control %d\n", intf);
486 usb_ep_disable(rndis->notify); 553 usb_ep_disable(rndis->notify);
487 } else { 554 }
555 if (!rndis->notify->desc) {
488 VDBG(cdev, "init rndis ctrl %d\n", intf); 556 VDBG(cdev, "init rndis ctrl %d\n", intf);
489 rndis->notify_desc = ep_choose(cdev->gadget, 557 if (config_ep_by_speed(cdev->gadget, f, rndis->notify))
490 rndis->hs.notify, 558 goto fail;
491 rndis->fs.notify);
492 } 559 }
493 usb_ep_enable(rndis->notify, rndis->notify_desc); 560 usb_ep_enable(rndis->notify);
494 rndis->notify->driver_data = rndis; 561 rndis->notify->driver_data = rndis;
495 562
496 } else if (intf == rndis->data_id) { 563 } else if (intf == rndis->data_id) {
@@ -501,12 +568,16 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
501 gether_disconnect(&rndis->port); 568 gether_disconnect(&rndis->port);
502 } 569 }
503 570
504 if (!rndis->port.in) { 571 if (!rndis->port.in_ep->desc || !rndis->port.out_ep->desc) {
505 DBG(cdev, "init rndis\n"); 572 DBG(cdev, "init rndis\n");
506 rndis->port.in = ep_choose(cdev->gadget, 573 if (config_ep_by_speed(cdev->gadget, f,
507 rndis->hs.in, rndis->fs.in); 574 rndis->port.in_ep) ||
508 rndis->port.out = ep_choose(cdev->gadget, 575 config_ep_by_speed(cdev->gadget, f,
509 rndis->hs.out, rndis->fs.out); 576 rndis->port.out_ep)) {
577 rndis->port.in_ep->desc = NULL;
578 rndis->port.out_ep->desc = NULL;
579 goto fail;
580 }
510 } 581 }
511 582
512 /* Avoid ZLPs; they can be troublesome. */ 583 /* Avoid ZLPs; they can be troublesome. */
@@ -662,13 +733,6 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
662 if (!f->descriptors) 733 if (!f->descriptors)
663 goto fail; 734 goto fail;
664 735
665 rndis->fs.in = usb_find_endpoint(eth_fs_function,
666 f->descriptors, &fs_in_desc);
667 rndis->fs.out = usb_find_endpoint(eth_fs_function,
668 f->descriptors, &fs_out_desc);
669 rndis->fs.notify = usb_find_endpoint(eth_fs_function,
670 f->descriptors, &fs_notify_desc);
671
672 /* support all relevant hardware speeds... we expect that when 736 /* support all relevant hardware speeds... we expect that when
673 * hardware is dual speed, all bulk-capable endpoints work at 737 * hardware is dual speed, all bulk-capable endpoints work at
674 * both speeds 738 * both speeds
@@ -683,16 +747,22 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
683 747
684 /* copy descriptors, and track endpoint copies */ 748 /* copy descriptors, and track endpoint copies */
685 f->hs_descriptors = usb_copy_descriptors(eth_hs_function); 749 f->hs_descriptors = usb_copy_descriptors(eth_hs_function);
686
687 if (!f->hs_descriptors) 750 if (!f->hs_descriptors)
688 goto fail; 751 goto fail;
752 }
689 753
690 rndis->hs.in = usb_find_endpoint(eth_hs_function, 754 if (gadget_is_superspeed(c->cdev->gadget)) {
691 f->hs_descriptors, &hs_in_desc); 755 ss_in_desc.bEndpointAddress =
692 rndis->hs.out = usb_find_endpoint(eth_hs_function, 756 fs_in_desc.bEndpointAddress;
693 f->hs_descriptors, &hs_out_desc); 757 ss_out_desc.bEndpointAddress =
694 rndis->hs.notify = usb_find_endpoint(eth_hs_function, 758 fs_out_desc.bEndpointAddress;
695 f->hs_descriptors, &hs_notify_desc); 759 ss_notify_desc.bEndpointAddress =
760 fs_notify_desc.bEndpointAddress;
761
762 /* copy descriptors, and track endpoint copies */
763 f->ss_descriptors = usb_copy_descriptors(eth_ss_function);
764 if (!f->ss_descriptors)
765 goto fail;
696 } 766 }
697 767
698 rndis->port.open = rndis_open; 768 rndis->port.open = rndis_open;
@@ -719,12 +789,15 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
719 */ 789 */
720 790
721 DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n", 791 DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n",
792 gadget_is_superspeed(c->cdev->gadget) ? "super" :
722 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 793 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
723 rndis->port.in_ep->name, rndis->port.out_ep->name, 794 rndis->port.in_ep->name, rndis->port.out_ep->name,
724 rndis->notify->name); 795 rndis->notify->name);
725 return 0; 796 return 0;
726 797
727fail: 798fail:
799 if (gadget_is_superspeed(c->cdev->gadget) && f->ss_descriptors)
800 usb_free_descriptors(f->ss_descriptors);
728 if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors) 801 if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors)
729 usb_free_descriptors(f->hs_descriptors); 802 usb_free_descriptors(f->hs_descriptors);
730 if (f->descriptors) 803 if (f->descriptors)
@@ -738,9 +811,9 @@ fail:
738 /* we might as well release our claims on endpoints */ 811 /* we might as well release our claims on endpoints */
739 if (rndis->notify) 812 if (rndis->notify)
740 rndis->notify->driver_data = NULL; 813 rndis->notify->driver_data = NULL;
741 if (rndis->port.out) 814 if (rndis->port.out_ep->desc)
742 rndis->port.out_ep->driver_data = NULL; 815 rndis->port.out_ep->driver_data = NULL;
743 if (rndis->port.in) 816 if (rndis->port.in_ep->desc)
744 rndis->port.in_ep->driver_data = NULL; 817 rndis->port.in_ep->driver_data = NULL;
745 818
746 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 819 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
@@ -756,6 +829,8 @@ rndis_unbind(struct usb_configuration *c, struct usb_function *f)
756 rndis_deregister(rndis->config); 829 rndis_deregister(rndis->config);
757 rndis_exit(); 830 rndis_exit();
758 831
832 if (gadget_is_superspeed(c->cdev->gadget))
833 usb_free_descriptors(f->ss_descriptors);
759 if (gadget_is_dualspeed(c->cdev->gadget)) 834 if (gadget_is_dualspeed(c->cdev->gadget))
760 usb_free_descriptors(f->hs_descriptors); 835 usb_free_descriptors(f->hs_descriptors);
761 usb_free_descriptors(f->descriptors); 836 usb_free_descriptors(f->descriptors);
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index 490b00b01a7d..91fdf790ed20 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -27,18 +27,10 @@
27 * if you can arrange appropriate host side drivers. 27 * if you can arrange appropriate host side drivers.
28 */ 28 */
29 29
30struct gser_descs {
31 struct usb_endpoint_descriptor *in;
32 struct usb_endpoint_descriptor *out;
33};
34
35struct f_gser { 30struct f_gser {
36 struct gserial port; 31 struct gserial port;
37 u8 data_id; 32 u8 data_id;
38 u8 port_num; 33 u8 port_num;
39
40 struct gser_descs fs;
41 struct gser_descs hs;
42}; 34};
43 35
44static inline struct f_gser *func_to_gser(struct usb_function *f) 36static inline struct f_gser *func_to_gser(struct usb_function *f)
@@ -136,12 +128,15 @@ static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
136 if (gser->port.in->driver_data) { 128 if (gser->port.in->driver_data) {
137 DBG(cdev, "reset generic ttyGS%d\n", gser->port_num); 129 DBG(cdev, "reset generic ttyGS%d\n", gser->port_num);
138 gserial_disconnect(&gser->port); 130 gserial_disconnect(&gser->port);
139 } else { 131 }
132 if (!gser->port.in->desc || !gser->port.out->desc) {
140 DBG(cdev, "activate generic ttyGS%d\n", gser->port_num); 133 DBG(cdev, "activate generic ttyGS%d\n", gser->port_num);
141 gser->port.in_desc = ep_choose(cdev->gadget, 134 if (!config_ep_by_speed(cdev->gadget, f, gser->port.in) ||
142 gser->hs.in, gser->fs.in); 135 !config_ep_by_speed(cdev->gadget, f, gser->port.out)) {
143 gser->port.out_desc = ep_choose(cdev->gadget, 136 gser->port.in->desc = NULL;
144 gser->hs.out, gser->fs.out); 137 gser->port.out->desc = NULL;
138 return -EINVAL;
139 }
145 } 140 }
146 gserial_connect(&gser->port, gser->port_num); 141 gserial_connect(&gser->port, gser->port_num);
147 return 0; 142 return 0;
@@ -193,12 +188,6 @@ gser_bind(struct usb_configuration *c, struct usb_function *f)
193 /* copy descriptors, and track endpoint copies */ 188 /* copy descriptors, and track endpoint copies */
194 f->descriptors = usb_copy_descriptors(gser_fs_function); 189 f->descriptors = usb_copy_descriptors(gser_fs_function);
195 190
196 gser->fs.in = usb_find_endpoint(gser_fs_function,
197 f->descriptors, &gser_fs_in_desc);
198 gser->fs.out = usb_find_endpoint(gser_fs_function,
199 f->descriptors, &gser_fs_out_desc);
200
201
202 /* support all relevant hardware speeds... we expect that when 191 /* support all relevant hardware speeds... we expect that when
203 * hardware is dual speed, all bulk-capable endpoints work at 192 * hardware is dual speed, all bulk-capable endpoints work at
204 * both speeds 193 * both speeds
@@ -211,11 +200,6 @@ gser_bind(struct usb_configuration *c, struct usb_function *f)
211 200
212 /* copy descriptors, and track endpoint copies */ 201 /* copy descriptors, and track endpoint copies */
213 f->hs_descriptors = usb_copy_descriptors(gser_hs_function); 202 f->hs_descriptors = usb_copy_descriptors(gser_hs_function);
214
215 gser->hs.in = usb_find_endpoint(gser_hs_function,
216 f->hs_descriptors, &gser_hs_in_desc);
217 gser->hs.out = usb_find_endpoint(gser_hs_function,
218 f->hs_descriptors, &gser_hs_out_desc);
219 } 203 }
220 204
221 DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", 205 DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n",
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index e403a534dd55..e18b4f520951 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -131,6 +131,49 @@ static struct usb_descriptor_header *hs_source_sink_descs[] = {
131 NULL, 131 NULL,
132}; 132};
133 133
134/* super speed support: */
135
136static struct usb_endpoint_descriptor ss_source_desc = {
137 .bLength = USB_DT_ENDPOINT_SIZE,
138 .bDescriptorType = USB_DT_ENDPOINT,
139
140 .bmAttributes = USB_ENDPOINT_XFER_BULK,
141 .wMaxPacketSize = cpu_to_le16(1024),
142};
143
144struct usb_ss_ep_comp_descriptor ss_source_comp_desc = {
145 .bLength = USB_DT_SS_EP_COMP_SIZE,
146 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
147 .bMaxBurst = 0,
148 .bmAttributes = 0,
149 .wBytesPerInterval = 0,
150};
151
152static struct usb_endpoint_descriptor ss_sink_desc = {
153 .bLength = USB_DT_ENDPOINT_SIZE,
154 .bDescriptorType = USB_DT_ENDPOINT,
155
156 .bmAttributes = USB_ENDPOINT_XFER_BULK,
157 .wMaxPacketSize = cpu_to_le16(1024),
158};
159
160struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = {
161 .bLength = USB_DT_SS_EP_COMP_SIZE,
162 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
163 .bMaxBurst = 0,
164 .bmAttributes = 0,
165 .wBytesPerInterval = 0,
166};
167
168static struct usb_descriptor_header *ss_source_sink_descs[] = {
169 (struct usb_descriptor_header *) &source_sink_intf,
170 (struct usb_descriptor_header *) &ss_source_desc,
171 (struct usb_descriptor_header *) &ss_source_comp_desc,
172 (struct usb_descriptor_header *) &ss_sink_desc,
173 (struct usb_descriptor_header *) &ss_sink_comp_desc,
174 NULL,
175};
176
134/* function-specific strings: */ 177/* function-specific strings: */
135 178
136static struct usb_string strings_sourcesink[] = { 179static struct usb_string strings_sourcesink[] = {
@@ -187,8 +230,18 @@ autoconf_fail:
187 f->hs_descriptors = hs_source_sink_descs; 230 f->hs_descriptors = hs_source_sink_descs;
188 } 231 }
189 232
233 /* support super speed hardware */
234 if (gadget_is_superspeed(c->cdev->gadget)) {
235 ss_source_desc.bEndpointAddress =
236 fs_source_desc.bEndpointAddress;
237 ss_sink_desc.bEndpointAddress =
238 fs_sink_desc.bEndpointAddress;
239 f->ss_descriptors = ss_source_sink_descs;
240 }
241
190 DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", 242 DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n",
191 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 243 (gadget_is_superspeed(c->cdev->gadget) ? "super" :
244 (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")),
192 f->name, ss->in_ep->name, ss->out_ep->name); 245 f->name, ss->in_ep->name, ss->out_ep->name);
193 return 0; 246 return 0;
194} 247}
@@ -343,15 +396,14 @@ static int
343enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss) 396enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss)
344{ 397{
345 int result = 0; 398 int result = 0;
346 const struct usb_endpoint_descriptor *src, *sink;
347 struct usb_ep *ep; 399 struct usb_ep *ep;
348 400
349 src = ep_choose(cdev->gadget, &hs_source_desc, &fs_source_desc);
350 sink = ep_choose(cdev->gadget, &hs_sink_desc, &fs_sink_desc);
351
352 /* one endpoint writes (sources) zeroes IN (to the host) */ 401 /* one endpoint writes (sources) zeroes IN (to the host) */
353 ep = ss->in_ep; 402 ep = ss->in_ep;
354 result = usb_ep_enable(ep, src); 403 result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
404 if (result)
405 return result;
406 result = usb_ep_enable(ep);
355 if (result < 0) 407 if (result < 0)
356 return result; 408 return result;
357 ep->driver_data = ss; 409 ep->driver_data = ss;
@@ -367,7 +419,10 @@ fail:
367 419
368 /* one endpoint reads (sinks) anything OUT (from the host) */ 420 /* one endpoint reads (sinks) anything OUT (from the host) */
369 ep = ss->out_ep; 421 ep = ss->out_ep;
370 result = usb_ep_enable(ep, sink); 422 result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
423 if (result)
424 goto fail;
425 result = usb_ep_enable(ep);
371 if (result < 0) 426 if (result < 0)
372 goto fail; 427 goto fail;
373 ep->driver_data = ss; 428 ep->driver_data = ss;
@@ -435,6 +490,8 @@ static int sourcesink_setup(struct usb_configuration *c,
435 u16 w_value = le16_to_cpu(ctrl->wValue); 490 u16 w_value = le16_to_cpu(ctrl->wValue);
436 u16 w_length = le16_to_cpu(ctrl->wLength); 491 u16 w_length = le16_to_cpu(ctrl->wLength);
437 492
493 req->length = USB_BUFSIZ;
494
438 /* composite driver infrastructure handles everything except 495 /* composite driver infrastructure handles everything except
439 * the two control test requests. 496 * the two control test requests.
440 */ 497 */
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index 8675ca415329..3dc53754ab60 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -57,18 +57,10 @@
57 * caring about specific product and vendor IDs. 57 * caring about specific product and vendor IDs.
58 */ 58 */
59 59
60struct geth_descs {
61 struct usb_endpoint_descriptor *in;
62 struct usb_endpoint_descriptor *out;
63};
64
65struct f_gether { 60struct f_gether {
66 struct gether port; 61 struct gether port;
67 62
68 char ethaddr[14]; 63 char ethaddr[14];
69
70 struct geth_descs fs;
71 struct geth_descs hs;
72}; 64};
73 65
74static inline struct f_gether *func_to_geth(struct usb_function *f) 66static inline struct f_gether *func_to_geth(struct usb_function *f)
@@ -209,6 +201,46 @@ static struct usb_descriptor_header *hs_eth_function[] __initdata = {
209 NULL, 201 NULL,
210}; 202};
211 203
204/* super speed support: */
205
206static struct usb_endpoint_descriptor ss_subset_in_desc __initdata = {
207 .bLength = USB_DT_ENDPOINT_SIZE,
208 .bDescriptorType = USB_DT_ENDPOINT,
209
210 .bmAttributes = USB_ENDPOINT_XFER_BULK,
211 .wMaxPacketSize = cpu_to_le16(1024),
212};
213
214static struct usb_endpoint_descriptor ss_subset_out_desc __initdata = {
215 .bLength = USB_DT_ENDPOINT_SIZE,
216 .bDescriptorType = USB_DT_ENDPOINT,
217
218 .bmAttributes = USB_ENDPOINT_XFER_BULK,
219 .wMaxPacketSize = cpu_to_le16(1024),
220};
221
222static struct usb_ss_ep_comp_descriptor ss_subset_bulk_comp_desc __initdata = {
223 .bLength = sizeof ss_subset_bulk_comp_desc,
224 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
225
226 /* the following 2 values can be tweaked if necessary */
227 /* .bMaxBurst = 0, */
228 /* .bmAttributes = 0, */
229};
230
231static struct usb_descriptor_header *ss_eth_function[] __initdata = {
232 (struct usb_descriptor_header *) &subset_data_intf,
233 (struct usb_descriptor_header *) &mdlm_header_desc,
234 (struct usb_descriptor_header *) &mdlm_desc,
235 (struct usb_descriptor_header *) &mdlm_detail_desc,
236 (struct usb_descriptor_header *) &ether_desc,
237 (struct usb_descriptor_header *) &ss_subset_in_desc,
238 (struct usb_descriptor_header *) &ss_subset_bulk_comp_desc,
239 (struct usb_descriptor_header *) &ss_subset_out_desc,
240 (struct usb_descriptor_header *) &ss_subset_bulk_comp_desc,
241 NULL,
242};
243
212/* string descriptors: */ 244/* string descriptors: */
213 245
214static struct usb_string geth_string_defs[] = { 246static struct usb_string geth_string_defs[] = {
@@ -243,10 +275,12 @@ static int geth_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
243 } 275 }
244 276
245 DBG(cdev, "init + activate cdc subset\n"); 277 DBG(cdev, "init + activate cdc subset\n");
246 geth->port.in = ep_choose(cdev->gadget, 278 if (config_ep_by_speed(cdev->gadget, f, geth->port.in_ep) ||
247 geth->hs.in, geth->fs.in); 279 config_ep_by_speed(cdev->gadget, f, geth->port.out_ep)) {
248 geth->port.out = ep_choose(cdev->gadget, 280 geth->port.in_ep->desc = NULL;
249 geth->hs.out, geth->fs.out); 281 geth->port.out_ep->desc = NULL;
282 return -EINVAL;
283 }
250 284
251 net = gether_connect(&geth->port); 285 net = gether_connect(&geth->port);
252 return IS_ERR(net) ? PTR_ERR(net) : 0; 286 return IS_ERR(net) ? PTR_ERR(net) : 0;
@@ -296,12 +330,8 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)
296 330
297 /* copy descriptors, and track endpoint copies */ 331 /* copy descriptors, and track endpoint copies */
298 f->descriptors = usb_copy_descriptors(fs_eth_function); 332 f->descriptors = usb_copy_descriptors(fs_eth_function);
299 333 if (!f->descriptors)
300 geth->fs.in = usb_find_endpoint(fs_eth_function, 334 goto fail;
301 f->descriptors, &fs_subset_in_desc);
302 geth->fs.out = usb_find_endpoint(fs_eth_function,
303 f->descriptors, &fs_subset_out_desc);
304
305 335
306 /* support all relevant hardware speeds... we expect that when 336 /* support all relevant hardware speeds... we expect that when
307 * hardware is dual speed, all bulk-capable endpoints work at 337 * hardware is dual speed, all bulk-capable endpoints work at
@@ -315,11 +345,20 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)
315 345
316 /* copy descriptors, and track endpoint copies */ 346 /* copy descriptors, and track endpoint copies */
317 f->hs_descriptors = usb_copy_descriptors(hs_eth_function); 347 f->hs_descriptors = usb_copy_descriptors(hs_eth_function);
348 if (!f->hs_descriptors)
349 goto fail;
350 }
318 351
319 geth->hs.in = usb_find_endpoint(hs_eth_function, 352 if (gadget_is_superspeed(c->cdev->gadget)) {
320 f->hs_descriptors, &hs_subset_in_desc); 353 ss_subset_in_desc.bEndpointAddress =
321 geth->hs.out = usb_find_endpoint(hs_eth_function, 354 fs_subset_in_desc.bEndpointAddress;
322 f->hs_descriptors, &hs_subset_out_desc); 355 ss_subset_out_desc.bEndpointAddress =
356 fs_subset_out_desc.bEndpointAddress;
357
358 /* copy descriptors, and track endpoint copies */
359 f->ss_descriptors = usb_copy_descriptors(ss_eth_function);
360 if (!f->ss_descriptors)
361 goto fail;
323 } 362 }
324 363
325 /* NOTE: all that is done without knowing or caring about 364 /* NOTE: all that is done without knowing or caring about
@@ -328,15 +367,21 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)
328 */ 367 */
329 368
330 DBG(cdev, "CDC Subset: %s speed IN/%s OUT/%s\n", 369 DBG(cdev, "CDC Subset: %s speed IN/%s OUT/%s\n",
370 gadget_is_superspeed(c->cdev->gadget) ? "super" :
331 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 371 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
332 geth->port.in_ep->name, geth->port.out_ep->name); 372 geth->port.in_ep->name, geth->port.out_ep->name);
333 return 0; 373 return 0;
334 374
335fail: 375fail:
376 if (f->descriptors)
377 usb_free_descriptors(f->descriptors);
378 if (f->hs_descriptors)
379 usb_free_descriptors(f->hs_descriptors);
380
336 /* we might as well release our claims on endpoints */ 381 /* we might as well release our claims on endpoints */
337 if (geth->port.out) 382 if (geth->port.out_ep->desc)
338 geth->port.out_ep->driver_data = NULL; 383 geth->port.out_ep->driver_data = NULL;
339 if (geth->port.in) 384 if (geth->port.in_ep->desc)
340 geth->port.in_ep->driver_data = NULL; 385 geth->port.in_ep->driver_data = NULL;
341 386
342 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 387 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
@@ -347,6 +392,8 @@ fail:
347static void 392static void
348geth_unbind(struct usb_configuration *c, struct usb_function *f) 393geth_unbind(struct usb_configuration *c, struct usb_function *f)
349{ 394{
395 if (gadget_is_superspeed(c->cdev->gadget))
396 usb_free_descriptors(f->ss_descriptors);
350 if (gadget_is_dualspeed(c->cdev->gadget)) 397 if (gadget_is_dualspeed(c->cdev->gadget))
351 usb_free_descriptors(f->hs_descriptors); 398 usb_free_descriptors(f->hs_descriptors);
352 usb_free_descriptors(f->descriptors); 399 usb_free_descriptors(f->descriptors);
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index be446b7e7eaa..7a8b9aa4aea5 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -262,8 +262,10 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
262 if (uvc->state != UVC_STATE_CONNECTED) 262 if (uvc->state != UVC_STATE_CONNECTED)
263 return 0; 263 return 0;
264 264
265 if (uvc->video.ep) 265 if (uvc->video.ep) {
266 usb_ep_enable(uvc->video.ep, &uvc_streaming_ep); 266 uvc->video.ep->desc = &uvc_streaming_ep;
267 usb_ep_enable(uvc->video.ep);
268 }
267 269
268 memset(&v4l2_event, 0, sizeof(v4l2_event)); 270 memset(&v4l2_event, 0, sizeof(v4l2_event));
269 v4l2_event.type = UVC_EVENT_STREAMON; 271 v4l2_event.type = UVC_EVENT_STREAMON;
@@ -649,7 +651,7 @@ uvc_bind_config(struct usb_configuration *c,
649 if (ret) 651 if (ret)
650 kfree(uvc); 652 kfree(uvc);
651 653
652 return 0; 654 return ret;
653 655
654error: 656error:
655 kfree(uvc); 657 kfree(uvc);
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 0360f56221ea..639e14a2fd15 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -929,6 +929,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
929 929
930 case USB_DT_DEVICE: 930 case USB_DT_DEVICE:
931 VDBG(fsg, "get device descriptor\n"); 931 VDBG(fsg, "get device descriptor\n");
932 device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
932 value = sizeof device_desc; 933 value = sizeof device_desc;
933 memcpy(req->buf, &device_desc, value); 934 memcpy(req->buf, &device_desc, value);
934 break; 935 break;
@@ -936,6 +937,11 @@ static int standard_setup_req(struct fsg_dev *fsg,
936 VDBG(fsg, "get device qualifier\n"); 937 VDBG(fsg, "get device qualifier\n");
937 if (!gadget_is_dualspeed(fsg->gadget)) 938 if (!gadget_is_dualspeed(fsg->gadget))
938 break; 939 break;
940 /*
941 * Assume ep0 uses the same maxpacket value for both
942 * speeds
943 */
944 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
939 value = sizeof dev_qualifier; 945 value = sizeof dev_qualifier;
940 memcpy(req->buf, &dev_qualifier, value); 946 memcpy(req->buf, &dev_qualifier, value);
941 break; 947 break;
@@ -2713,7 +2719,8 @@ static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
2713 int rc; 2719 int rc;
2714 2720
2715 ep->driver_data = fsg; 2721 ep->driver_data = fsg;
2716 rc = usb_ep_enable(ep, d); 2722 ep->desc = d;
2723 rc = usb_ep_enable(ep);
2717 if (rc) 2724 if (rc)
2718 ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc); 2725 ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
2719 return rc; 2726 return rc;
@@ -3416,7 +3423,6 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3416 } 3423 }
3417 3424
3418 /* Fix up the descriptors */ 3425 /* Fix up the descriptors */
3419 device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
3420 device_desc.idVendor = cpu_to_le16(mod_data.vendor); 3426 device_desc.idVendor = cpu_to_le16(mod_data.vendor);
3421 device_desc.idProduct = cpu_to_le16(mod_data.product); 3427 device_desc.idProduct = cpu_to_le16(mod_data.product);
3422 device_desc.bcdDevice = cpu_to_le16(mod_data.release); 3428 device_desc.bcdDevice = cpu_to_le16(mod_data.release);
@@ -3430,9 +3436,6 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3430 if (gadget_is_dualspeed(gadget)) { 3436 if (gadget_is_dualspeed(gadget)) {
3431 fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3437 fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3432 3438
3433 /* Assume ep0 uses the same maxpacket value for both speeds */
3434 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
3435
3436 /* Assume endpoint addresses are the same for both speeds */ 3439 /* Assume endpoint addresses are the same for both speeds */
3437 fsg_hs_bulk_in_desc.bEndpointAddress = 3440 fsg_hs_bulk_in_desc.bEndpointAddress =
3438 fsg_fs_bulk_in_desc.bEndpointAddress; 3441 fsg_fs_bulk_in_desc.bEndpointAddress;
@@ -3486,6 +3489,8 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3486 } 3489 }
3487 3490
3488 INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 3491 INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
3492 INFO(fsg, "NOTE: This driver is deprecated. "
3493 "Consider using g_mass_storage instead.\n");
3489 INFO(fsg, "Number of LUNs=%d\n", fsg->nluns); 3494 INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
3490 3495
3491 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); 3496 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 3a68e09309f7..3bf872e1ad39 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -1927,6 +1927,10 @@ static int qe_pullup(struct usb_gadget *gadget, int is_on)
1927 return -ENOTSUPP; 1927 return -ENOTSUPP;
1928} 1928}
1929 1929
1930static int fsl_qe_start(struct usb_gadget_driver *driver,
1931 int (*bind)(struct usb_gadget *));
1932static int fsl_qe_stop(struct usb_gadget_driver *driver);
1933
1930/* defined in usb_gadget.h */ 1934/* defined in usb_gadget.h */
1931static struct usb_gadget_ops qe_gadget_ops = { 1935static struct usb_gadget_ops qe_gadget_ops = {
1932 .get_frame = qe_get_frame, 1936 .get_frame = qe_get_frame,
@@ -1935,6 +1939,8 @@ static struct usb_gadget_ops qe_gadget_ops = {
1935 .vbus_session = qe_vbus_session, 1939 .vbus_session = qe_vbus_session,
1936 .vbus_draw = qe_vbus_draw, 1940 .vbus_draw = qe_vbus_draw,
1937 .pullup = qe_pullup, 1941 .pullup = qe_pullup,
1942 .start = fsl_qe_start,
1943 .stop = fsl_qe_stop,
1938}; 1944};
1939 1945
1940/*------------------------------------------------------------------------- 1946/*-------------------------------------------------------------------------
@@ -2320,7 +2326,7 @@ static irqreturn_t qe_udc_irq(int irq, void *_udc)
2320/*------------------------------------------------------------------------- 2326/*-------------------------------------------------------------------------
2321 Gadget driver probe and unregister. 2327 Gadget driver probe and unregister.
2322 --------------------------------------------------------------------------*/ 2328 --------------------------------------------------------------------------*/
2323int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2329static int fsl_qe_start(struct usb_gadget_driver *driver,
2324 int (*bind)(struct usb_gadget *)) 2330 int (*bind)(struct usb_gadget *))
2325{ 2331{
2326 int retval; 2332 int retval;
@@ -2369,9 +2375,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2369 udc_controller->gadget.name, driver->driver.name); 2375 udc_controller->gadget.name, driver->driver.name);
2370 return 0; 2376 return 0;
2371} 2377}
2372EXPORT_SYMBOL(usb_gadget_probe_driver);
2373 2378
2374int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2379static int fsl_qe_stop(struct usb_gadget_driver *driver)
2375{ 2380{
2376 struct qe_ep *loop_ep; 2381 struct qe_ep *loop_ep;
2377 unsigned long flags; 2382 unsigned long flags;
@@ -2411,7 +2416,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2411 driver->driver.name); 2416 driver->driver.name);
2412 return 0; 2417 return 0;
2413} 2418}
2414EXPORT_SYMBOL(usb_gadget_unregister_driver);
2415 2419
2416/* udc structure's alloc and setup, include ep-param alloc */ 2420/* udc structure's alloc and setup, include ep-param alloc */
2417static struct qe_udc __devinit *qe_udc_config(struct platform_device *ofdev) 2421static struct qe_udc __devinit *qe_udc_config(struct platform_device *ofdev)
@@ -2662,11 +2666,17 @@ static int __devinit qe_udc_probe(struct platform_device *ofdev)
2662 if (ret) 2666 if (ret)
2663 goto err6; 2667 goto err6;
2664 2668
2669 ret = usb_add_gadget_udc(&ofdev->dev, &udc_controller->gadget);
2670 if (ret)
2671 goto err7;
2672
2665 dev_info(udc_controller->dev, 2673 dev_info(udc_controller->dev,
2666 "%s USB controller initialized as device\n", 2674 "%s USB controller initialized as device\n",
2667 (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM"); 2675 (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM");
2668 return 0; 2676 return 0;
2669 2677
2678err7:
2679 device_unregister(&udc_controller->gadget.dev);
2670err6: 2680err6:
2671 free_irq(udc_controller->usb_irq, udc_controller); 2681 free_irq(udc_controller->usb_irq, udc_controller);
2672err5: 2682err5:
@@ -2721,6 +2731,8 @@ static int __devexit qe_udc_remove(struct platform_device *ofdev)
2721 if (!udc_controller) 2731 if (!udc_controller)
2722 return -ENODEV; 2732 return -ENODEV;
2723 2733
2734 usb_del_gadget_udc(&udc_controller->gadget);
2735
2724 udc_controller->done = &done; 2736 udc_controller->done = &done;
2725 tasklet_disable(&udc_controller->rx_tasklet); 2737 tasklet_disable(&udc_controller->rx_tasklet);
2726 2738
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 3e59035e6de8..de24a4233c25 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1244,6 +1244,9 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
1244 return 0; 1244 return 0;
1245} 1245}
1246 1246
1247static int fsl_start(struct usb_gadget_driver *driver,
1248 int (*bind)(struct usb_gadget *));
1249static int fsl_stop(struct usb_gadget_driver *driver);
1247/* defined in gadget.h */ 1250/* defined in gadget.h */
1248static struct usb_gadget_ops fsl_gadget_ops = { 1251static struct usb_gadget_ops fsl_gadget_ops = {
1249 .get_frame = fsl_get_frame, 1252 .get_frame = fsl_get_frame,
@@ -1252,6 +1255,8 @@ static struct usb_gadget_ops fsl_gadget_ops = {
1252 .vbus_session = fsl_vbus_session, 1255 .vbus_session = fsl_vbus_session,
1253 .vbus_draw = fsl_vbus_draw, 1256 .vbus_draw = fsl_vbus_draw,
1254 .pullup = fsl_pullup, 1257 .pullup = fsl_pullup,
1258 .start = fsl_start,
1259 .stop = fsl_stop,
1255}; 1260};
1256 1261
1257/* Set protocol stall on ep0, protocol stall will automatically be cleared 1262/* Set protocol stall on ep0, protocol stall will automatically be cleared
@@ -1927,7 +1932,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
1927 * Hook to gadget drivers 1932 * Hook to gadget drivers
1928 * Called by initialization code of gadget drivers 1933 * Called by initialization code of gadget drivers
1929*----------------------------------------------------------------*/ 1934*----------------------------------------------------------------*/
1930int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1935static int fsl_start(struct usb_gadget_driver *driver,
1931 int (*bind)(struct usb_gadget *)) 1936 int (*bind)(struct usb_gadget *))
1932{ 1937{
1933 int retval = -ENODEV; 1938 int retval = -ENODEV;
@@ -1995,10 +2000,9 @@ out:
1995 retval); 2000 retval);
1996 return retval; 2001 return retval;
1997} 2002}
1998EXPORT_SYMBOL(usb_gadget_probe_driver);
1999 2003
2000/* Disconnect from gadget driver */ 2004/* Disconnect from gadget driver */
2001int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2005static int fsl_stop(struct usb_gadget_driver *driver)
2002{ 2006{
2003 struct fsl_ep *loop_ep; 2007 struct fsl_ep *loop_ep;
2004 unsigned long flags; 2008 unsigned long flags;
@@ -2041,7 +2045,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2041 driver->driver.name); 2045 driver->driver.name);
2042 return 0; 2046 return 0;
2043} 2047}
2044EXPORT_SYMBOL(usb_gadget_unregister_driver);
2045 2048
2046/*------------------------------------------------------------------------- 2049/*-------------------------------------------------------------------------
2047 PROC File System Support 2050 PROC File System Support
@@ -2590,9 +2593,16 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2590 ret = -ENOMEM; 2593 ret = -ENOMEM;
2591 goto err_unregister; 2594 goto err_unregister;
2592 } 2595 }
2596
2597 ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget);
2598 if (ret)
2599 goto err_del_udc;
2600
2593 create_proc_file(); 2601 create_proc_file();
2594 return 0; 2602 return 0;
2595 2603
2604err_del_udc:
2605 dma_pool_destroy(udc_controller->td_pool);
2596err_unregister: 2606err_unregister:
2597 device_unregister(&udc_controller->gadget.dev); 2607 device_unregister(&udc_controller->gadget.dev);
2598err_free_irq: 2608err_free_irq:
@@ -2624,6 +2634,8 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
2624 2634
2625 if (!udc_controller) 2635 if (!udc_controller)
2626 return -ENODEV; 2636 return -ENODEV;
2637
2638 usb_del_gadget_udc(&udc_controller->gadget);
2627 udc_controller->done = &done; 2639 udc_controller->done = &done;
2628 2640
2629 fsl_udc_clk_release(); 2641 fsl_udc_clk_release();
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index 763d462454b9..24a924330c81 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -767,56 +767,6 @@ static void fusb300_rdfifo(struct fusb300_ep *ep,
767 } while (!reg); 767 } while (!reg);
768} 768}
769 769
770/* write data to fifo */
771static void fusb300_wrfifo(struct fusb300_ep *ep,
772 struct fusb300_request *req)
773{
774 int i = 0;
775 u8 *tmp;
776 u32 data, reg;
777 struct fusb300 *fusb300 = ep->fusb300;
778
779 tmp = req->req.buf;
780 req->req.actual = req->req.length;
781
782 for (i = (req->req.length >> 2); i > 0; i--) {
783 data = *tmp | *(tmp + 1) << 8 |
784 *(tmp + 2) << 16 | *(tmp + 3) << 24;
785
786 iowrite32(data, fusb300->reg +
787 FUSB300_OFFSET_EPPORT(ep->epnum));
788 tmp += 4;
789 }
790
791 switch (req->req.length % 4) {
792 case 1:
793 data = *tmp;
794 iowrite32(data, fusb300->reg +
795 FUSB300_OFFSET_EPPORT(ep->epnum));
796 break;
797 case 2:
798 data = *tmp | *(tmp + 1) << 8;
799 iowrite32(data, fusb300->reg +
800 FUSB300_OFFSET_EPPORT(ep->epnum));
801 break;
802 case 3:
803 data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16;
804 iowrite32(data, fusb300->reg +
805 FUSB300_OFFSET_EPPORT(ep->epnum));
806 break;
807 default:
808 break;
809 }
810
811 do {
812 reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1);
813 reg &= FUSB300_IGR1_SYNF0_EMPTY_INT;
814 if (i)
815 printk(KERN_INFO"sync fifo is not empty!\n");
816 i++;
817 } while (!reg);
818}
819
820static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep) 770static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep)
821{ 771{
822 u8 value; 772 u8 value;
@@ -980,11 +930,6 @@ static void set_address(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
980 } \ 930 } \
981 } while (0) 931 } while (0)
982 932
983static void fusb300_ep0_complete(struct usb_ep *ep,
984 struct usb_request *req)
985{
986}
987
988static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) 933static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
989{ 934{
990 u8 *p = (u8 *)ctrl; 935 u8 *p = (u8 *)ctrl;
@@ -1029,17 +974,6 @@ static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl)
1029 return ret; 974 return ret;
1030} 975}
1031 976
1032static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt)
1033{
1034 struct fusb300 *fusb300 = ep->fusb300;
1035 u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
1036
1037 reg &= ~FUSB300_FFR_BYCNT;
1038 reg |= bycnt & FUSB300_FFR_BYCNT;
1039
1040 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum));
1041}
1042
1043static void done(struct fusb300_ep *ep, struct fusb300_request *req, 977static void done(struct fusb300_ep *ep, struct fusb300_request *req,
1044 int status) 978 int status)
1045{ 979{
@@ -1063,8 +997,8 @@ static void done(struct fusb300_ep *ep, struct fusb300_request *req,
1063 fusb300_set_cxdone(ep->fusb300); 997 fusb300_set_cxdone(ep->fusb300);
1064} 998}
1065 999
1066void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep, 1000static void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep, dma_addr_t d,
1067 struct fusb300_request *req) 1001 u32 len)
1068{ 1002{
1069 u32 value; 1003 u32 value;
1070 u32 reg; 1004 u32 reg;
@@ -1076,10 +1010,9 @@ void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep,
1076 reg &= FUSB300_EPPRD0_H; 1010 reg &= FUSB300_EPPRD0_H;
1077 } while (reg); 1011 } while (reg);
1078 1012
1079 iowrite32((u32) req->req.buf, ep->fusb300->reg + 1013 iowrite32(d, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W1(ep->epnum));
1080 FUSB300_OFFSET_EPPRD_W1(ep->epnum));
1081 1014
1082 value = FUSB300_EPPRD0_BTC(req->req.length) | FUSB300_EPPRD0_H | 1015 value = FUSB300_EPPRD0_BTC(len) | FUSB300_EPPRD0_H |
1083 FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I; 1016 FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I;
1084 iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum)); 1017 iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum));
1085 1018
@@ -1116,13 +1049,12 @@ static void fusb300_set_idma(struct fusb300_ep *ep,
1116 struct fusb300_request *req) 1049 struct fusb300_request *req)
1117{ 1050{
1118 dma_addr_t d; 1051 dma_addr_t d;
1119 u8 *tmp = NULL;
1120 1052
1121 d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE); 1053 d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE);
1122 1054
1123 if (dma_mapping_error(NULL, d)) { 1055 if (dma_mapping_error(NULL, d)) {
1124 kfree(req->req.buf);
1125 printk(KERN_DEBUG "dma_mapping_error\n"); 1056 printk(KERN_DEBUG "dma_mapping_error\n");
1057 return;
1126 } 1058 }
1127 1059
1128 dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE); 1060 dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE);
@@ -1130,17 +1062,11 @@ static void fusb300_set_idma(struct fusb300_ep *ep,
1130 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0, 1062 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0,
1131 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); 1063 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
1132 1064
1133 tmp = req->req.buf; 1065 fusb300_fill_idma_prdtbl(ep, d, req->req.length);
1134 req->req.buf = (u8 *)d;
1135
1136 fusb300_fill_idma_prdtbl(ep, req);
1137 /* check idma is done */ 1066 /* check idma is done */
1138 fusb300_wait_idma_finished(ep); 1067 fusb300_wait_idma_finished(ep);
1139 1068
1140 req->req.buf = tmp; 1069 dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE);
1141
1142 if (d)
1143 dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE);
1144} 1070}
1145 1071
1146static void in_ep_fifo_handler(struct fusb300_ep *ep) 1072static void in_ep_fifo_handler(struct fusb300_ep *ep)
@@ -1148,14 +1074,8 @@ static void in_ep_fifo_handler(struct fusb300_ep *ep)
1148 struct fusb300_request *req = list_entry(ep->queue.next, 1074 struct fusb300_request *req = list_entry(ep->queue.next,
1149 struct fusb300_request, queue); 1075 struct fusb300_request, queue);
1150 1076
1151 if (req->req.length) { 1077 if (req->req.length)
1152#if 0
1153 fusb300_set_ep_bycnt(ep, req->req.length);
1154 fusb300_wrfifo(ep, req);
1155#else
1156 fusb300_set_idma(ep, req); 1078 fusb300_set_idma(ep, req);
1157#endif
1158 }
1159 done(ep, req, 0); 1079 done(ep, req, 0);
1160} 1080}
1161 1081
@@ -1500,7 +1420,7 @@ static void init_controller(struct fusb300 *fusb300)
1500/*------------------------------------------------------------------------*/ 1420/*------------------------------------------------------------------------*/
1501static struct fusb300 *the_controller; 1421static struct fusb300 *the_controller;
1502 1422
1503int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1423static int fusb300_udc_start(struct usb_gadget_driver *driver,
1504 int (*bind)(struct usb_gadget *)) 1424 int (*bind)(struct usb_gadget *))
1505{ 1425{
1506 struct fusb300 *fusb300 = the_controller; 1426 struct fusb300 *fusb300 = the_controller;
@@ -1544,9 +1464,8 @@ error:
1544 1464
1545 return retval; 1465 return retval;
1546} 1466}
1547EXPORT_SYMBOL(usb_gadget_probe_driver);
1548 1467
1549int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1468static int fusb300_udc_stop(struct usb_gadget_driver *driver)
1550{ 1469{
1551 struct fusb300 *fusb300 = the_controller; 1470 struct fusb300 *fusb300 = the_controller;
1552 1471
@@ -1562,7 +1481,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1562 1481
1563 return 0; 1482 return 0;
1564} 1483}
1565EXPORT_SYMBOL(usb_gadget_unregister_driver);
1566/*--------------------------------------------------------------------------*/ 1484/*--------------------------------------------------------------------------*/
1567 1485
1568static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active) 1486static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
@@ -1572,12 +1490,15 @@ static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
1572 1490
1573static struct usb_gadget_ops fusb300_gadget_ops = { 1491static struct usb_gadget_ops fusb300_gadget_ops = {
1574 .pullup = fusb300_udc_pullup, 1492 .pullup = fusb300_udc_pullup,
1493 .start = fusb300_udc_start,
1494 .stop = fusb300_udc_stop,
1575}; 1495};
1576 1496
1577static int __exit fusb300_remove(struct platform_device *pdev) 1497static int __exit fusb300_remove(struct platform_device *pdev)
1578{ 1498{
1579 struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev); 1499 struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev);
1580 1500
1501 usb_del_gadget_udc(&fusb300->gadget);
1581 iounmap(fusb300->reg); 1502 iounmap(fusb300->reg);
1582 free_irq(platform_get_irq(pdev, 0), fusb300); 1503 free_irq(platform_get_irq(pdev, 0), fusb300);
1583 1504
@@ -1702,9 +1623,15 @@ static int __init fusb300_probe(struct platform_device *pdev)
1702 goto clean_up3; 1623 goto clean_up3;
1703 1624
1704 init_controller(fusb300); 1625 init_controller(fusb300);
1626 ret = usb_add_gadget_udc(&pdev->dev, &fusb300->gadget);
1627 if (ret)
1628 goto err_add_udc;
1629
1705 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1630 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1706 1631
1707 return 0; 1632 return 0;
1633err_add_udc:
1634 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
1708 1635
1709clean_up3: 1636clean_up3:
1710 free_irq(ires->start, fusb300); 1637 free_irq(ires->start, fusb300);
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index ebf6970a10bf..704c2800ac00 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -162,6 +162,7 @@ static struct usb_composite_driver gfs_driver = {
162 .name = DRIVER_NAME, 162 .name = DRIVER_NAME,
163 .dev = &gfs_dev_desc, 163 .dev = &gfs_dev_desc,
164 .strings = gfs_dev_strings, 164 .strings = gfs_dev_strings,
165 .max_speed = USB_SPEED_HIGH,
165 .unbind = gfs_unbind, 166 .unbind = gfs_unbind,
166 .iProduct = DRIVER_DESC, 167 .iProduct = DRIVER_DESC,
167}; 168};
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index bcdac7c73e89..f3a83cd0ef50 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -15,150 +15,40 @@
15#ifndef __GADGET_CHIPS_H 15#ifndef __GADGET_CHIPS_H
16#define __GADGET_CHIPS_H 16#define __GADGET_CHIPS_H
17 17
18#ifdef CONFIG_USB_GADGET_NET2280 18/*
19#define gadget_is_net2280(g) !strcmp("net2280", (g)->name) 19 * NOTICE: the entries below are alphabetical and should be kept
20#else 20 * that way.
21#define gadget_is_net2280(g) 0 21 *
22#endif 22 * Always be sure to add new entries to the correct position or
23 23 * accept the bashing later.
24#ifdef CONFIG_USB_GADGET_AMD5536UDC 24 *
25#define gadget_is_amd5536udc(g) !strcmp("amd5536udc", (g)->name) 25 * If you have forgotten the alphabetical order let VIM/EMACS
26#else 26 * do that for you.
27#define gadget_is_amd5536udc(g) 0 27 */
28#endif 28#define gadget_is_amd5536udc(g) (!strcmp("amd5536udc", (g)->name))
29 29#define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name))
30#ifdef CONFIG_USB_GADGET_DUMMY_HCD 30#define gadget_is_atmel_usba(g) (!strcmp("atmel_usba_udc", (g)->name))
31#define gadget_is_dummy(g) !strcmp("dummy_udc", (g)->name)
32#else
33#define gadget_is_dummy(g) 0
34#endif
35
36#ifdef CONFIG_USB_GADGET_PXA25X
37#define gadget_is_pxa(g) !strcmp("pxa25x_udc", (g)->name)
38#else
39#define gadget_is_pxa(g) 0
40#endif
41
42#ifdef CONFIG_USB_GADGET_GOKU
43#define gadget_is_goku(g) !strcmp("goku_udc", (g)->name)
44#else
45#define gadget_is_goku(g) 0
46#endif
47
48#ifdef CONFIG_USB_GADGET_OMAP
49#define gadget_is_omap(g) !strcmp("omap_udc", (g)->name)
50#else
51#define gadget_is_omap(g) 0
52#endif
53
54/* various unstable versions available */
55#ifdef CONFIG_USB_GADGET_PXA27X
56#define gadget_is_pxa27x(g) !strcmp("pxa27x_udc", (g)->name)
57#else
58#define gadget_is_pxa27x(g) 0
59#endif
60
61#ifdef CONFIG_USB_GADGET_ATMEL_USBA
62#define gadget_is_atmel_usba(g) !strcmp("atmel_usba_udc", (g)->name)
63#else
64#define gadget_is_atmel_usba(g) 0
65#endif
66
67#ifdef CONFIG_USB_GADGET_S3C2410
68#define gadget_is_s3c2410(g) !strcmp("s3c2410_udc", (g)->name)
69#else
70#define gadget_is_s3c2410(g) 0
71#endif
72
73#ifdef CONFIG_USB_GADGET_AT91
74#define gadget_is_at91(g) !strcmp("at91_udc", (g)->name)
75#else
76#define gadget_is_at91(g) 0
77#endif
78
79#ifdef CONFIG_USB_GADGET_IMX
80#define gadget_is_imx(g) !strcmp("imx_udc", (g)->name)
81#else
82#define gadget_is_imx(g) 0
83#endif
84
85#ifdef CONFIG_USB_GADGET_FSL_USB2
86#define gadget_is_fsl_usb2(g) !strcmp("fsl-usb2-udc", (g)->name)
87#else
88#define gadget_is_fsl_usb2(g) 0
89#endif
90
91/* Mentor high speed "dual role" controller, in peripheral role */
92#ifdef CONFIG_USB_GADGET_MUSB_HDRC
93#define gadget_is_musbhdrc(g) !strcmp("musb-hdrc", (g)->name)
94#else
95#define gadget_is_musbhdrc(g) 0
96#endif
97
98#ifdef CONFIG_USB_GADGET_LANGWELL
99#define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name))
100#else
101#define gadget_is_langwell(g) 0
102#endif
103
104#ifdef CONFIG_USB_GADGET_M66592
105#define gadget_is_m66592(g) !strcmp("m66592_udc", (g)->name)
106#else
107#define gadget_is_m66592(g) 0
108#endif
109
110/* Freescale CPM/QE UDC SUPPORT */
111#ifdef CONFIG_USB_GADGET_FSL_QE
112#define gadget_is_fsl_qe(g) !strcmp("fsl_qe_udc", (g)->name)
113#else
114#define gadget_is_fsl_qe(g) 0
115#endif
116
117#ifdef CONFIG_USB_GADGET_CI13XXX_PCI
118#define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name))
119#else
120#define gadget_is_ci13xxx_pci(g) 0
121#endif
122
123// CONFIG_USB_GADGET_SX2
124// CONFIG_USB_GADGET_AU1X00
125// ...
126
127#ifdef CONFIG_USB_GADGET_R8A66597
128#define gadget_is_r8a66597(g) !strcmp("r8a66597_udc", (g)->name)
129#else
130#define gadget_is_r8a66597(g) 0
131#endif
132
133#ifdef CONFIG_USB_S3C_HSOTG
134#define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name))
135#else
136#define gadget_is_s3c_hsotg(g) 0
137#endif
138
139#ifdef CONFIG_USB_S3C_HSUDC
140#define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name))
141#else
142#define gadget_is_s3c_hsudc(g) 0
143#endif
144
145#ifdef CONFIG_USB_GADGET_EG20T
146#define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name))
147#else
148#define gadget_is_pch(g) 0
149#endif
150
151#ifdef CONFIG_USB_GADGET_CI13XXX_MSM
152#define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name)) 31#define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name))
153#else 32#define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name))
154#define gadget_is_ci13xxx_msm(g) 0 33#define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name))
155#endif 34#define gadget_is_fsl_qe(g) (!strcmp("fsl_qe_udc", (g)->name))
156 35#define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name))
157#ifdef CONFIG_USB_GADGET_RENESAS_USBHS 36#define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name))
158#define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name)) 37#define gadget_is_imx(g) (!strcmp("imx_udc", (g)->name))
159#else 38#define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name))
160#define gadget_is_renesas_usbhs(g) 0 39#define gadget_is_m66592(g) (!strcmp("m66592_udc", (g)->name))
161#endif 40#define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name))
41#define gadget_is_net2272(g) (!strcmp("net2272", (g)->name))
42#define gadget_is_net2280(g) (!strcmp("net2280", (g)->name))
43#define gadget_is_omap(g) (!strcmp("omap_udc", (g)->name))
44#define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name))
45#define gadget_is_pxa(g) (!strcmp("pxa25x_udc", (g)->name))
46#define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name))
47#define gadget_is_r8a66597(g) (!strcmp("r8a66597_udc", (g)->name))
48#define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name))
49#define gadget_is_s3c2410(g) (!strcmp("s3c2410_udc", (g)->name))
50#define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name))
51#define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name))
162 52
163/** 53/**
164 * usb_gadget_controller_number - support bcdDevice id convention 54 * usb_gadget_controller_number - support bcdDevice id convention
@@ -223,6 +113,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
223 return 0x29; 113 return 0x29;
224 else if (gadget_is_s3c_hsudc(gadget)) 114 else if (gadget_is_s3c_hsudc(gadget))
225 return 0x30; 115 return 0x30;
116 else if (gadget_is_net2272(gadget))
117 return 0x31;
226 118
227 return -ENOENT; 119 return -ENOENT;
228} 120}
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 47b86b99d449..8b9220e128a7 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -537,14 +537,16 @@ static int set_gmidi_config(struct gmidi_device *dev, gfp_t gfp_flags)
537 struct usb_ep *ep; 537 struct usb_ep *ep;
538 unsigned i; 538 unsigned i;
539 539
540 err = usb_ep_enable(dev->in_ep, &bulk_in_desc); 540 dev->in_ep->desc = &bulk_in_desc;
541 err = usb_ep_enable(dev->in_ep);
541 if (err) { 542 if (err) {
542 ERROR(dev, "can't start %s: %d\n", dev->in_ep->name, err); 543 ERROR(dev, "can't start %s: %d\n", dev->in_ep->name, err);
543 goto fail; 544 goto fail;
544 } 545 }
545 dev->in_ep->driver_data = dev; 546 dev->in_ep->driver_data = dev;
546 547
547 err = usb_ep_enable(dev->out_ep, &bulk_out_desc); 548 dev->out_ep->desc = &bulk_out_desc;
549 err = usb_ep_enable(dev->out_ep);
548 if (err) { 550 if (err) {
549 ERROR(dev, "can't start %s: %d\n", dev->out_ep->name, err); 551 ERROR(dev, "can't start %s: %d\n", dev->out_ep->name, err);
550 goto fail; 552 goto fail;
@@ -693,6 +695,7 @@ static int gmidi_setup(struct usb_gadget *gadget,
693 switch (w_value >> 8) { 695 switch (w_value >> 8) {
694 696
695 case USB_DT_DEVICE: 697 case USB_DT_DEVICE:
698 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
696 value = min(w_length, (u16) sizeof(device_desc)); 699 value = min(w_length, (u16) sizeof(device_desc));
697 memcpy(req->buf, &device_desc, value); 700 memcpy(req->buf, &device_desc, value);
698 break; 701 break;
@@ -1247,8 +1250,6 @@ autoconf_fail:
1247 1250
1248 dev->req->complete = gmidi_setup_complete; 1251 dev->req->complete = gmidi_setup_complete;
1249 1252
1250 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1251
1252 gadget->ep0->driver_data = dev; 1253 gadget->ep0->driver_data = dev;
1253 1254
1254 INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname); 1255 INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index bf6e11c758d5..7f87805cddc4 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -996,8 +996,14 @@ static int goku_get_frame(struct usb_gadget *_gadget)
996 return -EOPNOTSUPP; 996 return -EOPNOTSUPP;
997} 997}
998 998
999static int goku_start(struct usb_gadget_driver *driver,
1000 int (*bind)(struct usb_gadget *));
1001static int goku_stop(struct usb_gadget_driver *driver);
1002
999static const struct usb_gadget_ops goku_ops = { 1003static const struct usb_gadget_ops goku_ops = {
1000 .get_frame = goku_get_frame, 1004 .get_frame = goku_get_frame,
1005 .start = goku_start,
1006 .stop = goku_stop,
1001 // no remote wakeup 1007 // no remote wakeup
1002 // not selfpowered 1008 // not selfpowered
1003}; 1009};
@@ -1344,7 +1350,7 @@ static struct goku_udc *the_controller;
1344 * disconnect is reported. then a host may connect again, or 1350 * disconnect is reported. then a host may connect again, or
1345 * the driver might get unbound. 1351 * the driver might get unbound.
1346 */ 1352 */
1347int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1353static int goku_start(struct usb_gadget_driver *driver,
1348 int (*bind)(struct usb_gadget *)) 1354 int (*bind)(struct usb_gadget *))
1349{ 1355{
1350 struct goku_udc *dev = the_controller; 1356 struct goku_udc *dev = the_controller;
@@ -1382,7 +1388,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1382 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name); 1388 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name);
1383 return 0; 1389 return 0;
1384} 1390}
1385EXPORT_SYMBOL(usb_gadget_probe_driver);
1386 1391
1387static void 1392static void
1388stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) 1393stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
@@ -1408,7 +1413,7 @@ stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
1408 udc_enable(dev); 1413 udc_enable(dev);
1409} 1414}
1410 1415
1411int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1416static int goku_stop(struct usb_gadget_driver *driver)
1412{ 1417{
1413 struct goku_udc *dev = the_controller; 1418 struct goku_udc *dev = the_controller;
1414 unsigned long flags; 1419 unsigned long flags;
@@ -1429,8 +1434,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1429 DBG(dev, "unregistered driver '%s'\n", driver->driver.name); 1434 DBG(dev, "unregistered driver '%s'\n", driver->driver.name);
1430 return 0; 1435 return 0;
1431} 1436}
1432EXPORT_SYMBOL(usb_gadget_unregister_driver);
1433
1434 1437
1435/*-------------------------------------------------------------------------*/ 1438/*-------------------------------------------------------------------------*/
1436 1439
@@ -1730,6 +1733,8 @@ static void goku_remove(struct pci_dev *pdev)
1730 1733
1731 DBG(dev, "%s\n", __func__); 1734 DBG(dev, "%s\n", __func__);
1732 1735
1736 usb_del_gadget_udc(&dev->gadget);
1737
1733 BUG_ON(dev->driver); 1738 BUG_ON(dev->driver);
1734 1739
1735#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1740#ifdef CONFIG_USB_GADGET_DEBUG_FILES
@@ -1854,6 +1859,10 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1854 goto err; 1859 goto err;
1855 } 1860 }
1856 dev->registered = 1; 1861 dev->registered = 1;
1862 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
1863 if (retval)
1864 goto err;
1865
1857 return 0; 1866 return 0;
1858 1867
1859err: 1868err:
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index 2523e54097bd..9fb575034a0e 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -255,6 +255,7 @@ static struct usb_composite_driver hidg_driver = {
255 .name = "g_hid", 255 .name = "g_hid",
256 .dev = &device_desc, 256 .dev = &device_desc,
257 .strings = dev_strings, 257 .strings = dev_strings,
258 .max_speed = USB_SPEED_HIGH,
258 .unbind = __exit_p(hid_unbind), 259 .unbind = __exit_p(hid_unbind),
259}; 260};
260 261
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index ade40066decf..692fd9b2248b 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1237,9 +1237,14 @@ irq_handler_t intr_handler(int i)
1237 ******************************************************************************* 1237 *******************************************************************************
1238 */ 1238 */
1239 1239
1240static int imx_udc_start(struct usb_gadget_driver *driver,
1241 int (*bind)(struct usb_gadget *));
1242static int imx_udc_stop(struct usb_gadget_driver *driver);
1240static const struct usb_gadget_ops imx_udc_ops = { 1243static const struct usb_gadget_ops imx_udc_ops = {
1241 .get_frame = imx_udc_get_frame, 1244 .get_frame = imx_udc_get_frame,
1242 .wakeup = imx_udc_wakeup, 1245 .wakeup = imx_udc_wakeup,
1246 .start = imx_udc_start,
1247 .stop = imx_udc_stop,
1243}; 1248};
1244 1249
1245static struct imx_udc_struct controller = { 1250static struct imx_udc_struct controller = {
@@ -1324,7 +1329,7 @@ static struct imx_udc_struct controller = {
1324 * USB gadget driver functions 1329 * USB gadget driver functions
1325 ******************************************************************************* 1330 *******************************************************************************
1326 */ 1331 */
1327int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1332static int imx_udc_start(struct usb_gadget_driver *driver,
1328 int (*bind)(struct usb_gadget *)) 1333 int (*bind)(struct usb_gadget *))
1329{ 1334{
1330 struct imx_udc_struct *imx_usb = &controller; 1335 struct imx_udc_struct *imx_usb = &controller;
@@ -1368,9 +1373,8 @@ fail:
1368 imx_usb->gadget.dev.driver = NULL; 1373 imx_usb->gadget.dev.driver = NULL;
1369 return retval; 1374 return retval;
1370} 1375}
1371EXPORT_SYMBOL(usb_gadget_probe_driver);
1372 1376
1373int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1377static int imx_udc_stop(struct usb_gadget_driver *driver)
1374{ 1378{
1375 struct imx_udc_struct *imx_usb = &controller; 1379 struct imx_udc_struct *imx_usb = &controller;
1376 1380
@@ -1394,7 +1398,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1394 1398
1395 return 0; 1399 return 0;
1396} 1400}
1397EXPORT_SYMBOL(usb_gadget_unregister_driver);
1398 1401
1399/******************************************************************************* 1402/*******************************************************************************
1400 * Module functions 1403 * Module functions
@@ -1504,8 +1507,14 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1504 imx_usb->timer.function = handle_config; 1507 imx_usb->timer.function = handle_config;
1505 imx_usb->timer.data = (unsigned long)imx_usb; 1508 imx_usb->timer.data = (unsigned long)imx_usb;
1506 1509
1507 return 0; 1510 ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget);
1511 if (ret)
1512 goto fail4;
1508 1513
1514 return 0;
1515fail4:
1516 for (i = 0; i < IMX_USB_NB_EP + 1; i++)
1517 free_irq(imx_usb->usbd_int[i], imx_usb);
1509fail3: 1518fail3:
1510 clk_put(clk); 1519 clk_put(clk);
1511 clk_disable(clk); 1520 clk_disable(clk);
@@ -1525,6 +1534,7 @@ static int __exit imx_udc_remove(struct platform_device *pdev)
1525 struct imxusb_platform_data *pdata = pdev->dev.platform_data; 1534 struct imxusb_platform_data *pdata = pdev->dev.platform_data;
1526 int i; 1535 int i;
1527 1536
1537 usb_del_gadget_udc(&imx_usb->gadget);
1528 imx_udc_disable(imx_usb); 1538 imx_udc_disable(imx_usb);
1529 del_timer(&imx_usb->timer); 1539 del_timer(&imx_usb->timer);
1530 1540
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index a56876aaf76c..1b240990448f 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -832,14 +832,16 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
832 switch (data->dev->gadget->speed) { 832 switch (data->dev->gadget->speed) {
833 case USB_SPEED_LOW: 833 case USB_SPEED_LOW:
834 case USB_SPEED_FULL: 834 case USB_SPEED_FULL:
835 value = usb_ep_enable (ep, &data->desc); 835 ep->desc = &data->desc;
836 value = usb_ep_enable(ep);
836 if (value == 0) 837 if (value == 0)
837 data->state = STATE_EP_ENABLED; 838 data->state = STATE_EP_ENABLED;
838 break; 839 break;
839#ifdef CONFIG_USB_GADGET_DUALSPEED 840#ifdef CONFIG_USB_GADGET_DUALSPEED
840 case USB_SPEED_HIGH: 841 case USB_SPEED_HIGH:
841 /* fails if caller didn't provide that descriptor... */ 842 /* fails if caller didn't provide that descriptor... */
842 value = usb_ep_enable (ep, &data->hs_desc); 843 ep->desc = &data->hs_desc;
844 value = usb_ep_enable(ep);
843 if (value == 0) 845 if (value == 0)
844 data->state = STATE_EP_ENABLED; 846 data->state = STATE_EP_ENABLED;
845 break; 847 break;
@@ -1345,7 +1347,7 @@ static void make_qualifier (struct dev_data *dev)
1345 qual.bDeviceProtocol = desc->bDeviceProtocol; 1347 qual.bDeviceProtocol = desc->bDeviceProtocol;
1346 1348
1347 /* assumes ep0 uses the same value for both speeds ... */ 1349 /* assumes ep0 uses the same value for both speeds ... */
1348 qual.bMaxPacketSize0 = desc->bMaxPacketSize0; 1350 qual.bMaxPacketSize0 = dev->gadget->ep0->maxpacket;
1349 1351
1350 qual.bNumConfigurations = 1; 1352 qual.bNumConfigurations = 1;
1351 qual.bRESERVED = 0; 1353 qual.bRESERVED = 0;
@@ -1402,7 +1404,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1402 } 1404 }
1403 1405
1404 dev->state = STATE_DEV_CONNECTED; 1406 dev->state = STATE_DEV_CONNECTED;
1405 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
1406 1407
1407 INFO (dev, "connected\n"); 1408 INFO (dev, "connected\n");
1408 event = next_event (dev, GADGETFS_CONNECT); 1409 event = next_event (dev, GADGETFS_CONNECT);
@@ -1430,6 +1431,7 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1430 1431
1431 case USB_DT_DEVICE: 1432 case USB_DT_DEVICE:
1432 value = min (w_length, (u16) sizeof *dev->dev); 1433 value = min (w_length, (u16) sizeof *dev->dev);
1434 dev->dev->bMaxPacketSize0 = dev->gadget->ep0->maxpacket;
1433 req->buf = dev->dev; 1435 req->buf = dev->dev;
1434 break; 1436 break;
1435#ifdef CONFIG_USB_GADGET_DUALSPEED 1437#ifdef CONFIG_USB_GADGET_DUALSPEED
@@ -1710,7 +1712,6 @@ gadgetfs_bind (struct usb_gadget *gadget)
1710 set_gadget_data (gadget, dev); 1712 set_gadget_data (gadget, dev);
1711 dev->gadget = gadget; 1713 dev->gadget = gadget;
1712 gadget->ep0->driver_data = dev; 1714 gadget->ep0->driver_data = dev;
1713 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
1714 1715
1715 /* preallocate control response and buffer */ 1716 /* preallocate control response and buffer */
1716 dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); 1717 dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index 9cee88a43a73..a06e2c27b435 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -593,8 +593,8 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req)
593 /* ep0 */ 593 /* ep0 */
594 dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep)); 594 dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep));
595 595
596 dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%08x\n", 596 dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%p\n",
597 i, (u32)&(dev->ep_dqh[i])); 597 i, &(dev->ep_dqh[i]));
598 598
599 bit_mask = is_in(ep) ? 599 bit_mask = is_in(ep) ?
600 (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num)); 600 (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num));
@@ -1321,7 +1321,9 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on)
1321 return 0; 1321 return 0;
1322} 1322}
1323 1323
1324 1324static int langwell_start(struct usb_gadget_driver *driver,
1325 int (*bind)(struct usb_gadget *));
1326static int langwell_stop(struct usb_gadget_driver *driver);
1325/* device controller usb_gadget_ops structure */ 1327/* device controller usb_gadget_ops structure */
1326static const struct usb_gadget_ops langwell_ops = { 1328static const struct usb_gadget_ops langwell_ops = {
1327 1329
@@ -1342,6 +1344,9 @@ static const struct usb_gadget_ops langwell_ops = {
1342 1344
1343 /* D+ pullup, software-controlled connect/disconnect to USB host */ 1345 /* D+ pullup, software-controlled connect/disconnect to USB host */
1344 .pullup = langwell_pullup, 1346 .pullup = langwell_pullup,
1347
1348 .start = langwell_start,
1349 .stop = langwell_stop,
1345}; 1350};
1346 1351
1347 1352
@@ -1852,7 +1857,7 @@ static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup);
1852 * the driver might get unbound. 1857 * the driver might get unbound.
1853 */ 1858 */
1854 1859
1855int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1860static int langwell_start(struct usb_gadget_driver *driver,
1856 int (*bind)(struct usb_gadget *)) 1861 int (*bind)(struct usb_gadget *))
1857{ 1862{
1858 struct langwell_udc *dev = the_controller; 1863 struct langwell_udc *dev = the_controller;
@@ -1914,11 +1919,9 @@ err_unbind:
1914 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); 1919 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1915 return retval; 1920 return retval;
1916} 1921}
1917EXPORT_SYMBOL(usb_gadget_probe_driver);
1918
1919 1922
1920/* unregister gadget driver */ 1923/* unregister gadget driver */
1921int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1924static int langwell_stop(struct usb_gadget_driver *driver)
1922{ 1925{
1923 struct langwell_udc *dev = the_controller; 1926 struct langwell_udc *dev = the_controller;
1924 unsigned long flags; 1927 unsigned long flags;
@@ -1965,8 +1968,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1965 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); 1968 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1966 return 0; 1969 return 0;
1967} 1970}
1968EXPORT_SYMBOL(usb_gadget_unregister_driver);
1969
1970 1971
1971/*-------------------------------------------------------------------------*/ 1972/*-------------------------------------------------------------------------*/
1972 1973
@@ -3270,7 +3271,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3270 3271
3271 /* allocate device dQH memory */ 3272 /* allocate device dQH memory */
3272 size = dev->ep_max * sizeof(struct langwell_dqh); 3273 size = dev->ep_max * sizeof(struct langwell_dqh);
3273 dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size); 3274 dev_vdbg(&dev->pdev->dev, "orig size = %zd\n", size);
3274 if (size < DQH_ALIGNMENT) 3275 if (size < DQH_ALIGNMENT)
3275 size = DQH_ALIGNMENT; 3276 size = DQH_ALIGNMENT;
3276 else if ((size % DQH_ALIGNMENT) != 0) { 3277 else if ((size % DQH_ALIGNMENT) != 0) {
@@ -3285,7 +3286,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3285 goto error; 3286 goto error;
3286 } 3287 }
3287 dev->ep_dqh_size = size; 3288 dev->ep_dqh_size = size;
3288 dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size); 3289 dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %zd\n", dev->ep_dqh_size);
3289 3290
3290 /* initialize ep0 status request structure */ 3291 /* initialize ep0 status request structure */
3291 dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL); 3292 dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL);
@@ -3373,6 +3374,10 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3373 if (retval) 3374 if (retval)
3374 goto error; 3375 goto error;
3375 3376
3377 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
3378 if (retval)
3379 goto error;
3380
3376 retval = device_create_file(&pdev->dev, &dev_attr_langwell_udc); 3381 retval = device_create_file(&pdev->dev, &dev_attr_langwell_udc);
3377 if (retval) 3382 if (retval)
3378 goto error; 3383 goto error;
@@ -3403,6 +3408,7 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
3403 3408
3404 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); 3409 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3405 3410
3411 usb_del_gadget_udc(&dev->gadget);
3406 /* disable interrupt and set controller to stop state */ 3412 /* disable interrupt and set controller to stop state */
3407 langwell_udc_stop(dev); 3413 langwell_udc_stop(dev);
3408 3414
@@ -3464,7 +3470,7 @@ static int langwell_udc_resume(struct pci_dev *pdev)
3464 3470
3465 /* allocate device dQH memory */ 3471 /* allocate device dQH memory */
3466 size = dev->ep_max * sizeof(struct langwell_dqh); 3472 size = dev->ep_max * sizeof(struct langwell_dqh);
3467 dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size); 3473 dev_vdbg(&dev->pdev->dev, "orig size = %zd\n", size);
3468 if (size < DQH_ALIGNMENT) 3474 if (size < DQH_ALIGNMENT)
3469 size = DQH_ALIGNMENT; 3475 size = DQH_ALIGNMENT;
3470 else if ((size % DQH_ALIGNMENT) != 0) { 3476 else if ((size % DQH_ALIGNMENT) != 0) {
@@ -3478,7 +3484,7 @@ static int langwell_udc_resume(struct pci_dev *pdev)
3478 return -ENOMEM; 3484 return -ENOMEM;
3479 } 3485 }
3480 dev->ep_dqh_size = size; 3486 dev->ep_dqh_size = size;
3481 dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size); 3487 dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %zd\n", dev->ep_dqh_size);
3482 3488
3483 /* create dTD dma_pool resource */ 3489 /* create dTD dma_pool resource */
3484 dev->dtd_pool = dma_pool_create("langwell_dtd", 3490 dev->dtd_pool = dma_pool_create("langwell_dtd",
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 084aa080a2d5..491f825ed5c9 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2006-2007 Renesas Solutions Corp. 4 * Copyright (C) 2006-2007 Renesas Solutions Corp.
5 * 5 *
6 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> 6 * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.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
@@ -691,6 +691,7 @@ static void init_controller(struct m66592 *m66592)
691 691
692static void disable_controller(struct m66592 *m66592) 692static void disable_controller(struct m66592 *m66592)
693{ 693{
694 m66592_bclr(m66592, M66592_UTST, M66592_TESTMODE);
694 if (!m66592->pdata->on_chip) { 695 if (!m66592->pdata->on_chip) {
695 m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); 696 m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG);
696 udelay(1); 697 udelay(1);
@@ -780,7 +781,7 @@ static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req)
780 /* write fifo */ 781 /* write fifo */
781 if (req->req.buf) { 782 if (req->req.buf) {
782 if (size > 0) 783 if (size > 0)
783 m66592_write_fifo(m66592, ep->fifoaddr, buf, size); 784 m66592_write_fifo(m66592, ep, buf, size);
784 if ((size == 0) || ((size % ep->ep.maxpacket) != 0)) 785 if ((size == 0) || ((size % ep->ep.maxpacket) != 0))
785 m66592_bset(m66592, M66592_BVAL, ep->fifoctr); 786 m66592_bset(m66592, M66592_BVAL, ep->fifoctr);
786 } 787 }
@@ -826,7 +827,7 @@ static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req)
826 827
827 /* write fifo */ 828 /* write fifo */
828 if (req->req.buf) { 829 if (req->req.buf) {
829 m66592_write_fifo(m66592, ep->fifoaddr, buf, size); 830 m66592_write_fifo(m66592, ep, buf, size);
830 if ((size == 0) 831 if ((size == 0)
831 || ((size % ep->ep.maxpacket) != 0) 832 || ((size % ep->ep.maxpacket) != 0)
832 || ((bufsize != ep->ep.maxpacket) 833 || ((bufsize != ep->ep.maxpacket)
@@ -1048,10 +1049,30 @@ static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
1048 1049
1049static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) 1050static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
1050{ 1051{
1052 u16 tmp;
1053 int timeout = 3000;
1051 1054
1052 switch (ctrl->bRequestType & USB_RECIP_MASK) { 1055 switch (ctrl->bRequestType & USB_RECIP_MASK) {
1053 case USB_RECIP_DEVICE: 1056 case USB_RECIP_DEVICE:
1054 control_end(m66592, 1); 1057 switch (le16_to_cpu(ctrl->wValue)) {
1058 case USB_DEVICE_TEST_MODE:
1059 control_end(m66592, 1);
1060 /* Wait for the completion of status stage */
1061 do {
1062 tmp = m66592_read(m66592, M66592_INTSTS0) &
1063 M66592_CTSQ;
1064 udelay(1);
1065 } while (tmp != M66592_CS_IDST || timeout-- > 0);
1066
1067 if (tmp == M66592_CS_IDST)
1068 m66592_bset(m66592,
1069 le16_to_cpu(ctrl->wIndex >> 8),
1070 M66592_TESTMODE);
1071 break;
1072 default:
1073 pipe_stall(m66592, 0);
1074 break;
1075 }
1055 break; 1076 break;
1056 case USB_RECIP_INTERFACE: 1077 case USB_RECIP_INTERFACE:
1057 control_end(m66592, 1); 1078 control_end(m66592, 1);
@@ -1454,7 +1475,7 @@ static struct usb_ep_ops m66592_ep_ops = {
1454/*-------------------------------------------------------------------------*/ 1475/*-------------------------------------------------------------------------*/
1455static struct m66592 *the_controller; 1476static struct m66592 *the_controller;
1456 1477
1457int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1478static int m66592_start(struct usb_gadget_driver *driver,
1458 int (*bind)(struct usb_gadget *)) 1479 int (*bind)(struct usb_gadget *))
1459{ 1480{
1460 struct m66592 *m66592 = the_controller; 1481 struct m66592 *m66592 = the_controller;
@@ -1506,9 +1527,8 @@ error:
1506 1527
1507 return retval; 1528 return retval;
1508} 1529}
1509EXPORT_SYMBOL(usb_gadget_probe_driver);
1510 1530
1511int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1531static int m66592_stop(struct usb_gadget_driver *driver)
1512{ 1532{
1513 struct m66592 *m66592 = the_controller; 1533 struct m66592 *m66592 = the_controller;
1514 unsigned long flags; 1534 unsigned long flags;
@@ -1533,7 +1553,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1533 m66592->driver = NULL; 1553 m66592->driver = NULL;
1534 return 0; 1554 return 0;
1535} 1555}
1536EXPORT_SYMBOL(usb_gadget_unregister_driver);
1537 1556
1538/*-------------------------------------------------------------------------*/ 1557/*-------------------------------------------------------------------------*/
1539static int m66592_get_frame(struct usb_gadget *_gadget) 1558static int m66592_get_frame(struct usb_gadget *_gadget)
@@ -1542,14 +1561,34 @@ static int m66592_get_frame(struct usb_gadget *_gadget)
1542 return m66592_read(m66592, M66592_FRMNUM) & 0x03FF; 1561 return m66592_read(m66592, M66592_FRMNUM) & 0x03FF;
1543} 1562}
1544 1563
1564static int m66592_pullup(struct usb_gadget *gadget, int is_on)
1565{
1566 struct m66592 *m66592 = gadget_to_m66592(gadget);
1567 unsigned long flags;
1568
1569 spin_lock_irqsave(&m66592->lock, flags);
1570 if (is_on)
1571 m66592_bset(m66592, M66592_DPRPU, M66592_SYSCFG);
1572 else
1573 m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG);
1574 spin_unlock_irqrestore(&m66592->lock, flags);
1575
1576 return 0;
1577}
1578
1545static struct usb_gadget_ops m66592_gadget_ops = { 1579static struct usb_gadget_ops m66592_gadget_ops = {
1546 .get_frame = m66592_get_frame, 1580 .get_frame = m66592_get_frame,
1581 .start = m66592_start,
1582 .stop = m66592_stop,
1583 .pullup = m66592_pullup,
1547}; 1584};
1548 1585
1549static int __exit m66592_remove(struct platform_device *pdev) 1586static int __exit m66592_remove(struct platform_device *pdev)
1550{ 1587{
1551 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); 1588 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev);
1552 1589
1590 usb_del_gadget_udc(&m66592->gadget);
1591
1553 del_timer_sync(&m66592->timer); 1592 del_timer_sync(&m66592->timer);
1554 iounmap(m66592->reg); 1593 iounmap(m66592->reg);
1555 free_irq(platform_get_irq(pdev, 0), m66592); 1594 free_irq(platform_get_irq(pdev, 0), m66592);
@@ -1691,9 +1730,16 @@ static int __init m66592_probe(struct platform_device *pdev)
1691 1730
1692 init_controller(m66592); 1731 init_controller(m66592);
1693 1732
1733 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget);
1734 if (ret)
1735 goto err_add_udc;
1736
1694 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1737 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1695 return 0; 1738 return 0;
1696 1739
1740err_add_udc:
1741 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1742
1697clean_up3: 1743clean_up3:
1698#ifdef CONFIG_HAVE_CLK 1744#ifdef CONFIG_HAVE_CLK
1699 if (m66592->pdata->on_chip) { 1745 if (m66592->pdata->on_chip) {
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h
index c3caf1ac73ce..7b93d579af37 100644
--- a/drivers/usb/gadget/m66592-udc.h
+++ b/drivers/usb/gadget/m66592-udc.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2006-2007 Renesas Solutions Corp. 4 * Copyright (C) 2006-2007 Renesas Solutions Corp.
5 * 5 *
6 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> 6 * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.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
@@ -561,11 +561,26 @@ static inline void m66592_write(struct m66592 *m66592, u16 val,
561 iowrite16(val, m66592->reg + offset); 561 iowrite16(val, m66592->reg + offset);
562} 562}
563 563
564static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat,
565 unsigned long offset)
566{
567 u16 tmp;
568 tmp = m66592_read(m66592, offset);
569 tmp = tmp & (~pat);
570 tmp = tmp | val;
571 m66592_write(m66592, tmp, offset);
572}
573
574#define m66592_bclr(m66592, val, offset) \
575 m66592_mdfy(m66592, 0, val, offset)
576#define m66592_bset(m66592, val, offset) \
577 m66592_mdfy(m66592, val, 0, offset)
578
564static inline void m66592_write_fifo(struct m66592 *m66592, 579static inline void m66592_write_fifo(struct m66592 *m66592,
565 unsigned long offset, 580 struct m66592_ep *ep,
566 void *buf, unsigned long len) 581 void *buf, unsigned long len)
567{ 582{
568 void __iomem *fifoaddr = m66592->reg + offset; 583 void __iomem *fifoaddr = m66592->reg + ep->fifoaddr;
569 584
570 if (m66592->pdata->on_chip) { 585 if (m66592->pdata->on_chip) {
571 unsigned long count; 586 unsigned long count;
@@ -591,26 +606,15 @@ static inline void m66592_write_fifo(struct m66592 *m66592,
591 iowrite16_rep(fifoaddr, buf, len); 606 iowrite16_rep(fifoaddr, buf, len);
592 if (odd) { 607 if (odd) {
593 unsigned char *p = buf + len*2; 608 unsigned char *p = buf + len*2;
609 if (m66592->pdata->wr0_shorted_to_wr1)
610 m66592_bclr(m66592, M66592_MBW_16, ep->fifosel);
594 iowrite8(*p, fifoaddr); 611 iowrite8(*p, fifoaddr);
612 if (m66592->pdata->wr0_shorted_to_wr1)
613 m66592_bset(m66592, M66592_MBW_16, ep->fifosel);
595 } 614 }
596 } 615 }
597} 616}
598 617
599static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat,
600 unsigned long offset)
601{
602 u16 tmp;
603 tmp = m66592_read(m66592, offset);
604 tmp = tmp & (~pat);
605 tmp = tmp | val;
606 m66592_write(m66592, tmp, offset);
607}
608
609#define m66592_bclr(m66592, val, offset) \
610 m66592_mdfy(m66592, 0, val, offset)
611#define m66592_bset(m66592, val, offset) \
612 m66592_mdfy(m66592, val, 0, offset)
613
614#endif /* ifndef __M66592_UDC_H__ */ 618#endif /* ifndef __M66592_UDC_H__ */
615 619
616 620
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index 01822422c3e8..d3eb27427c58 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -169,6 +169,7 @@ static struct usb_composite_driver msg_driver = {
169 .name = "g_mass_storage", 169 .name = "g_mass_storage",
170 .dev = &msg_device_desc, 170 .dev = &msg_device_desc,
171 .iProduct = DRIVER_DESC, 171 .iProduct = DRIVER_DESC,
172 .max_speed = USB_SPEED_HIGH,
172 .needs_serial = 1, 173 .needs_serial = 1,
173}; 174};
174 175
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index d9feced348e3..8c7b74717d85 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -351,6 +351,7 @@ static struct usb_composite_driver multi_driver = {
351 .name = "g_multi", 351 .name = "g_multi",
352 .dev = &device_desc, 352 .dev = &device_desc,
353 .strings = dev_strings, 353 .strings = dev_strings,
354 .max_speed = USB_SPEED_HIGH,
354 .unbind = __exit_p(multi_unbind), 355 .unbind = __exit_p(multi_unbind),
355 .iProduct = DRIVER_DESC, 356 .iProduct = DRIVER_DESC,
356 .needs_serial = 1, 357 .needs_serial = 1,
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index b1a8146b9d50..ce1ac2bcb314 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -1128,6 +1128,9 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on)
1128 return 0; 1128 return 0;
1129} 1129}
1130 1130
1131static int mv_udc_start(struct usb_gadget_driver *driver,
1132 int (*bind)(struct usb_gadget *));
1133static int mv_udc_stop(struct usb_gadget_driver *driver);
1131/* device controller usb_gadget_ops structure */ 1134/* device controller usb_gadget_ops structure */
1132static const struct usb_gadget_ops mv_ops = { 1135static const struct usb_gadget_ops mv_ops = {
1133 1136
@@ -1139,6 +1142,8 @@ static const struct usb_gadget_ops mv_ops = {
1139 1142
1140 /* D+ pullup, software-controlled connect/disconnect to USB host */ 1143 /* D+ pullup, software-controlled connect/disconnect to USB host */
1141 .pullup = mv_udc_pullup, 1144 .pullup = mv_udc_pullup,
1145 .start = mv_udc_start,
1146 .stop = mv_udc_stop,
1142}; 1147};
1143 1148
1144static void mv_udc_testmode(struct mv_udc *udc, u16 index, bool enter) 1149static void mv_udc_testmode(struct mv_udc *udc, u16 index, bool enter)
@@ -1230,7 +1235,7 @@ static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver)
1230 } 1235 }
1231} 1236}
1232 1237
1233int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1238static int mv_udc_start(struct usb_gadget_driver *driver,
1234 int (*bind)(struct usb_gadget *)) 1239 int (*bind)(struct usb_gadget *))
1235{ 1240{
1236 struct mv_udc *udc = the_controller; 1241 struct mv_udc *udc = the_controller;
@@ -1270,9 +1275,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1270 1275
1271 return 0; 1276 return 0;
1272} 1277}
1273EXPORT_SYMBOL(usb_gadget_probe_driver);
1274 1278
1275int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1279static int mv_udc_stop(struct usb_gadget_driver *driver)
1276{ 1280{
1277 struct mv_udc *udc = the_controller; 1281 struct mv_udc *udc = the_controller;
1278 unsigned long flags; 1282 unsigned long flags;
@@ -1296,7 +1300,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1296 1300
1297 return 0; 1301 return 0;
1298} 1302}
1299EXPORT_SYMBOL(usb_gadget_unregister_driver);
1300 1303
1301static int 1304static int
1302udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) 1305udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty)
@@ -1880,9 +1883,10 @@ static void gadget_release(struct device *_dev)
1880static int mv_udc_remove(struct platform_device *dev) 1883static int mv_udc_remove(struct platform_device *dev)
1881{ 1884{
1882 struct mv_udc *udc = the_controller; 1885 struct mv_udc *udc = the_controller;
1883
1884 DECLARE_COMPLETION(done); 1886 DECLARE_COMPLETION(done);
1885 1887
1888 usb_del_gadget_udc(&udc->gadget);
1889
1886 udc->done = &done; 1890 udc->done = &done;
1887 1891
1888 /* free memory allocated in probe */ 1892 /* free memory allocated in probe */
@@ -2074,11 +2078,12 @@ int mv_udc_probe(struct platform_device *dev)
2074 2078
2075 the_controller = udc; 2079 the_controller = udc;
2076 2080
2077 goto out; 2081 retval = usb_add_gadget_udc(&dev->dev, &udc->gadget);
2082 if (!retval)
2083 return retval;
2078error: 2084error:
2079 if (udc) 2085 if (udc)
2080 mv_udc_remove(udc->dev); 2086 mv_udc_remove(udc->dev);
2081out:
2082 return retval; 2087 return retval;
2083} 2088}
2084 2089
@@ -2126,7 +2131,7 @@ static struct platform_driver udc_driver = {
2126#endif 2131#endif
2127 }, 2132 },
2128}; 2133};
2129 2134MODULE_ALIAS("platform:pxa-u2o");
2130 2135
2131MODULE_DESCRIPTION(DRIVER_DESC); 2136MODULE_DESCRIPTION(DRIVER_DESC);
2132MODULE_AUTHOR("Chao Xie <chao.xie@marvell.com>"); 2137MODULE_AUTHOR("Chao Xie <chao.xie@marvell.com>");
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
index 99c179ad729d..62ee5087dcac 100644
--- a/drivers/usb/gadget/ncm.c
+++ b/drivers/usb/gadget/ncm.c
@@ -228,6 +228,7 @@ static struct usb_composite_driver ncm_driver = {
228 .name = "g_ncm", 228 .name = "g_ncm",
229 .dev = &device_desc, 229 .dev = &device_desc,
230 .strings = dev_strings, 230 .strings = dev_strings,
231 .max_speed = USB_SPEED_HIGH,
231 .unbind = __exit_p(gncm_unbind), 232 .unbind = __exit_p(gncm_unbind),
232}; 233};
233 234
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c
new file mode 100644
index 000000000000..7c7b0e120d88
--- /dev/null
+++ b/drivers/usb/gadget/net2272.c
@@ -0,0 +1,2752 @@
1/*
2 * Driver for PLX NET2272 USB device controller
3 *
4 * Copyright (C) 2005-2006 PLX Technology, Inc.
5 * Copyright (C) 2006-2011 Analog Devices, Inc.
6 *
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
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/delay.h>
23#include <linux/device.h>
24#include <linux/errno.h>
25#include <linux/gpio.h>
26#include <linux/init.h>
27#include <linux/interrupt.h>
28#include <linux/io.h>
29#include <linux/ioport.h>
30#include <linux/irq.h>
31#include <linux/kernel.h>
32#include <linux/list.h>
33#include <linux/module.h>
34#include <linux/moduleparam.h>
35#include <linux/pci.h>
36#include <linux/platform_device.h>
37#include <linux/sched.h>
38#include <linux/slab.h>
39#include <linux/timer.h>
40#include <linux/usb.h>
41#include <linux/usb/ch9.h>
42#include <linux/usb/gadget.h>
43
44#include <asm/byteorder.h>
45#include <asm/system.h>
46#include <asm/unaligned.h>
47
48#include "net2272.h"
49
50#define DRIVER_DESC "PLX NET2272 USB Peripheral Controller"
51
52static const char driver_name[] = "net2272";
53static const char driver_vers[] = "2006 October 17/mainline";
54static const char driver_desc[] = DRIVER_DESC;
55
56static const char ep0name[] = "ep0";
57static const char * const ep_name[] = {
58 ep0name,
59 "ep-a", "ep-b", "ep-c",
60};
61
62#define DMA_ADDR_INVALID (~(dma_addr_t)0)
63#ifdef CONFIG_USB_GADGET_NET2272_DMA
64/*
65 * use_dma: the NET2272 can use an external DMA controller.
66 * Note that since there is no generic DMA api, some functions,
67 * notably request_dma, start_dma, and cancel_dma will need to be
68 * modified for your platform's particular dma controller.
69 *
70 * If use_dma is disabled, pio will be used instead.
71 */
72static int use_dma = 0;
73module_param(use_dma, bool, 0644);
74
75/*
76 * dma_ep: selects the endpoint for use with dma (1=ep-a, 2=ep-b)
77 * The NET2272 can only use dma for a single endpoint at a time.
78 * At some point this could be modified to allow either endpoint
79 * to take control of dma as it becomes available.
80 *
81 * Note that DMA should not be used on OUT endpoints unless it can
82 * be guaranteed that no short packets will arrive on an IN endpoint
83 * while the DMA operation is pending. Otherwise the OUT DMA will
84 * terminate prematurely (See NET2272 Errata 630-0213-0101)
85 */
86static ushort dma_ep = 1;
87module_param(dma_ep, ushort, 0644);
88
89/*
90 * dma_mode: net2272 dma mode setting (see LOCCTL1 definiton):
91 * mode 0 == Slow DREQ mode
92 * mode 1 == Fast DREQ mode
93 * mode 2 == Burst mode
94 */
95static ushort dma_mode = 2;
96module_param(dma_mode, ushort, 0644);
97#else
98#define use_dma 0
99#define dma_ep 1
100#define dma_mode 2
101#endif
102
103/*
104 * fifo_mode: net2272 buffer configuration:
105 * mode 0 == ep-{a,b,c} 512db each
106 * mode 1 == ep-a 1k, ep-{b,c} 512db
107 * mode 2 == ep-a 1k, ep-b 1k, ep-c 512db
108 * mode 3 == ep-a 1k, ep-b disabled, ep-c 512db
109 */
110static ushort fifo_mode = 0;
111module_param(fifo_mode, ushort, 0644);
112
113/*
114 * enable_suspend: When enabled, the driver will respond to
115 * USB suspend requests by powering down the NET2272. Otherwise,
116 * USB suspend requests will be ignored. This is acceptible for
117 * self-powered devices. For bus powered devices set this to 1.
118 */
119static ushort enable_suspend = 0;
120module_param(enable_suspend, ushort, 0644);
121
122static void assert_out_naking(struct net2272_ep *ep, const char *where)
123{
124 u8 tmp;
125
126#ifndef DEBUG
127 return;
128#endif
129
130 tmp = net2272_ep_read(ep, EP_STAT0);
131 if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
132 dev_dbg(ep->dev->dev, "%s %s %02x !NAK\n",
133 ep->ep.name, where, tmp);
134 net2272_ep_write(ep, EP_RSPSET, 1 << ALT_NAK_OUT_PACKETS);
135 }
136}
137#define ASSERT_OUT_NAKING(ep) assert_out_naking(ep, __func__)
138
139static void stop_out_naking(struct net2272_ep *ep)
140{
141 u8 tmp = net2272_ep_read(ep, EP_STAT0);
142
143 if ((tmp & (1 << NAK_OUT_PACKETS)) != 0)
144 net2272_ep_write(ep, EP_RSPCLR, 1 << ALT_NAK_OUT_PACKETS);
145}
146
147#define PIPEDIR(bAddress) (usb_pipein(bAddress) ? "in" : "out")
148
149static char *type_string(u8 bmAttributes)
150{
151 switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) {
152 case USB_ENDPOINT_XFER_BULK: return "bulk";
153 case USB_ENDPOINT_XFER_ISOC: return "iso";
154 case USB_ENDPOINT_XFER_INT: return "intr";
155 default: return "control";
156 }
157}
158
159static char *buf_state_string(unsigned state)
160{
161 switch (state) {
162 case BUFF_FREE: return "free";
163 case BUFF_VALID: return "valid";
164 case BUFF_LCL: return "local";
165 case BUFF_USB: return "usb";
166 default: return "unknown";
167 }
168}
169
170static char *dma_mode_string(void)
171{
172 if (!use_dma)
173 return "PIO";
174 switch (dma_mode) {
175 case 0: return "SLOW DREQ";
176 case 1: return "FAST DREQ";
177 case 2: return "BURST";
178 default: return "invalid";
179 }
180}
181
182static void net2272_dequeue_all(struct net2272_ep *);
183static int net2272_kick_dma(struct net2272_ep *, struct net2272_request *);
184static int net2272_fifo_status(struct usb_ep *);
185
186static struct usb_ep_ops net2272_ep_ops;
187
188/*---------------------------------------------------------------------------*/
189
190static int
191net2272_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
192{
193 struct net2272 *dev;
194 struct net2272_ep *ep;
195 u32 max;
196 u8 tmp;
197 unsigned long flags;
198
199 ep = container_of(_ep, struct net2272_ep, ep);
200 if (!_ep || !desc || ep->desc || _ep->name == ep0name
201 || desc->bDescriptorType != USB_DT_ENDPOINT)
202 return -EINVAL;
203 dev = ep->dev;
204 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
205 return -ESHUTDOWN;
206
207 max = le16_to_cpu(desc->wMaxPacketSize) & 0x1fff;
208
209 spin_lock_irqsave(&dev->lock, flags);
210 _ep->maxpacket = max & 0x7fff;
211 ep->desc = desc;
212
213 /* net2272_ep_reset() has already been called */
214 ep->stopped = 0;
215 ep->wedged = 0;
216
217 /* set speed-dependent max packet */
218 net2272_ep_write(ep, EP_MAXPKT0, max & 0xff);
219 net2272_ep_write(ep, EP_MAXPKT1, (max & 0xff00) >> 8);
220
221 /* set type, direction, address; reset fifo counters */
222 net2272_ep_write(ep, EP_STAT1, 1 << BUFFER_FLUSH);
223 tmp = usb_endpoint_type(desc);
224 if (usb_endpoint_xfer_bulk(desc)) {
225 /* catch some particularly blatant driver bugs */
226 if ((dev->gadget.speed == USB_SPEED_HIGH && max != 512) ||
227 (dev->gadget.speed == USB_SPEED_FULL && max > 64)) {
228 spin_unlock_irqrestore(&dev->lock, flags);
229 return -ERANGE;
230 }
231 }
232 ep->is_iso = usb_endpoint_xfer_isoc(desc) ? 1 : 0;
233 tmp <<= ENDPOINT_TYPE;
234 tmp |= ((desc->bEndpointAddress & 0x0f) << ENDPOINT_NUMBER);
235 tmp |= usb_endpoint_dir_in(desc) << ENDPOINT_DIRECTION;
236 tmp |= (1 << ENDPOINT_ENABLE);
237
238 /* for OUT transfers, block the rx fifo until a read is posted */
239 ep->is_in = usb_endpoint_dir_in(desc);
240 if (!ep->is_in)
241 net2272_ep_write(ep, EP_RSPSET, 1 << ALT_NAK_OUT_PACKETS);
242
243 net2272_ep_write(ep, EP_CFG, tmp);
244
245 /* enable irqs */
246 tmp = (1 << ep->num) | net2272_read(dev, IRQENB0);
247 net2272_write(dev, IRQENB0, tmp);
248
249 tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE)
250 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE)
251 | net2272_ep_read(ep, EP_IRQENB);
252 net2272_ep_write(ep, EP_IRQENB, tmp);
253
254 tmp = desc->bEndpointAddress;
255 dev_dbg(dev->dev, "enabled %s (ep%d%s-%s) max %04x cfg %02x\n",
256 _ep->name, tmp & 0x0f, PIPEDIR(tmp),
257 type_string(desc->bmAttributes), max,
258 net2272_ep_read(ep, EP_CFG));
259
260 spin_unlock_irqrestore(&dev->lock, flags);
261 return 0;
262}
263
264static void net2272_ep_reset(struct net2272_ep *ep)
265{
266 u8 tmp;
267
268 ep->desc = NULL;
269 INIT_LIST_HEAD(&ep->queue);
270
271 ep->ep.maxpacket = ~0;
272 ep->ep.ops = &net2272_ep_ops;
273
274 /* disable irqs, endpoint */
275 net2272_ep_write(ep, EP_IRQENB, 0);
276
277 /* init to our chosen defaults, notably so that we NAK OUT
278 * packets until the driver queues a read.
279 */
280 tmp = (1 << NAK_OUT_PACKETS_MODE) | (1 << ALT_NAK_OUT_PACKETS);
281 net2272_ep_write(ep, EP_RSPSET, tmp);
282
283 tmp = (1 << INTERRUPT_MODE) | (1 << HIDE_STATUS_PHASE);
284 if (ep->num != 0)
285 tmp |= (1 << ENDPOINT_TOGGLE) | (1 << ENDPOINT_HALT);
286
287 net2272_ep_write(ep, EP_RSPCLR, tmp);
288
289 /* scrub most status bits, and flush any fifo state */
290 net2272_ep_write(ep, EP_STAT0,
291 (1 << DATA_IN_TOKEN_INTERRUPT)
292 | (1 << DATA_OUT_TOKEN_INTERRUPT)
293 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)
294 | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
295 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT));
296
297 net2272_ep_write(ep, EP_STAT1,
298 (1 << TIMEOUT)
299 | (1 << USB_OUT_ACK_SENT)
300 | (1 << USB_OUT_NAK_SENT)
301 | (1 << USB_IN_ACK_RCVD)
302 | (1 << USB_IN_NAK_SENT)
303 | (1 << USB_STALL_SENT)
304 | (1 << LOCAL_OUT_ZLP)
305 | (1 << BUFFER_FLUSH));
306
307 /* fifo size is handled seperately */
308}
309
310static int net2272_disable(struct usb_ep *_ep)
311{
312 struct net2272_ep *ep;
313 unsigned long flags;
314
315 ep = container_of(_ep, struct net2272_ep, ep);
316 if (!_ep || !ep->desc || _ep->name == ep0name)
317 return -EINVAL;
318
319 spin_lock_irqsave(&ep->dev->lock, flags);
320 net2272_dequeue_all(ep);
321 net2272_ep_reset(ep);
322
323 dev_vdbg(ep->dev->dev, "disabled %s\n", _ep->name);
324
325 spin_unlock_irqrestore(&ep->dev->lock, flags);
326 return 0;
327}
328
329/*---------------------------------------------------------------------------*/
330
331static struct usb_request *
332net2272_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
333{
334 struct net2272_ep *ep;
335 struct net2272_request *req;
336
337 if (!_ep)
338 return NULL;
339 ep = container_of(_ep, struct net2272_ep, ep);
340
341 req = kzalloc(sizeof(*req), gfp_flags);
342 if (!req)
343 return NULL;
344
345 req->req.dma = DMA_ADDR_INVALID;
346 INIT_LIST_HEAD(&req->queue);
347
348 return &req->req;
349}
350
351static void
352net2272_free_request(struct usb_ep *_ep, struct usb_request *_req)
353{
354 struct net2272_ep *ep;
355 struct net2272_request *req;
356
357 ep = container_of(_ep, struct net2272_ep, ep);
358 if (!_ep || !_req)
359 return;
360
361 req = container_of(_req, struct net2272_request, req);
362 WARN_ON(!list_empty(&req->queue));
363 kfree(req);
364}
365
366static void
367net2272_done(struct net2272_ep *ep, struct net2272_request *req, int status)
368{
369 struct net2272 *dev;
370 unsigned stopped = ep->stopped;
371
372 if (ep->num == 0) {
373 if (ep->dev->protocol_stall) {
374 ep->stopped = 1;
375 set_halt(ep);
376 }
377 allow_status(ep);
378 }
379
380 list_del_init(&req->queue);
381
382 if (req->req.status == -EINPROGRESS)
383 req->req.status = status;
384 else
385 status = req->req.status;
386
387 dev = ep->dev;
388 if (use_dma && req->mapped) {
389 dma_unmap_single(dev->dev, req->req.dma, req->req.length,
390 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
391 req->req.dma = DMA_ADDR_INVALID;
392 req->mapped = 0;
393 }
394
395 if (status && status != -ESHUTDOWN)
396 dev_vdbg(dev->dev, "complete %s req %p stat %d len %u/%u buf %p\n",
397 ep->ep.name, &req->req, status,
398 req->req.actual, req->req.length, req->req.buf);
399
400 /* don't modify queue heads during completion callback */
401 ep->stopped = 1;
402 spin_unlock(&dev->lock);
403 req->req.complete(&ep->ep, &req->req);
404 spin_lock(&dev->lock);
405 ep->stopped = stopped;
406}
407
408static int
409net2272_write_packet(struct net2272_ep *ep, u8 *buf,
410 struct net2272_request *req, unsigned max)
411{
412 u16 __iomem *ep_data = net2272_reg_addr(ep->dev, EP_DATA);
413 u16 *bufp;
414 unsigned length, count;
415 u8 tmp;
416
417 length = min(req->req.length - req->req.actual, max);
418 req->req.actual += length;
419
420 dev_vdbg(ep->dev->dev, "write packet %s req %p max %u len %u avail %u\n",
421 ep->ep.name, req, max, length,
422 (net2272_ep_read(ep, EP_AVAIL1) << 8) | net2272_ep_read(ep, EP_AVAIL0));
423
424 count = length;
425 bufp = (u16 *)buf;
426
427 while (likely(count >= 2)) {
428 /* no byte-swap required; chip endian set during init */
429 writew(*bufp++, ep_data);
430 count -= 2;
431 }
432 buf = (u8 *)bufp;
433
434 /* write final byte by placing the NET2272 into 8-bit mode */
435 if (unlikely(count)) {
436 tmp = net2272_read(ep->dev, LOCCTL);
437 net2272_write(ep->dev, LOCCTL, tmp & ~(1 << DATA_WIDTH));
438 writeb(*buf, ep_data);
439 net2272_write(ep->dev, LOCCTL, tmp);
440 }
441 return length;
442}
443
444/* returns: 0: still running, 1: completed, negative: errno */
445static int
446net2272_write_fifo(struct net2272_ep *ep, struct net2272_request *req)
447{
448 u8 *buf;
449 unsigned count, max;
450 int status;
451
452 dev_vdbg(ep->dev->dev, "write_fifo %s actual %d len %d\n",
453 ep->ep.name, req->req.actual, req->req.length);
454
455 /*
456 * Keep loading the endpoint until the final packet is loaded,
457 * or the endpoint buffer is full.
458 */
459 top:
460 /*
461 * Clear interrupt status
462 * - Packet Transmitted interrupt will become set again when the
463 * host successfully takes another packet
464 */
465 net2272_ep_write(ep, EP_STAT0, (1 << DATA_PACKET_TRANSMITTED_INTERRUPT));
466 while (!(net2272_ep_read(ep, EP_STAT0) & (1 << BUFFER_FULL))) {
467 buf = req->req.buf + req->req.actual;
468 prefetch(buf);
469
470 /* force pagesel */
471 net2272_ep_read(ep, EP_STAT0);
472
473 max = (net2272_ep_read(ep, EP_AVAIL1) << 8) |
474 (net2272_ep_read(ep, EP_AVAIL0));
475
476 if (max < ep->ep.maxpacket)
477 max = (net2272_ep_read(ep, EP_AVAIL1) << 8)
478 | (net2272_ep_read(ep, EP_AVAIL0));
479
480 count = net2272_write_packet(ep, buf, req, max);
481 /* see if we are done */
482 if (req->req.length == req->req.actual) {
483 /* validate short or zlp packet */
484 if (count < ep->ep.maxpacket)
485 set_fifo_bytecount(ep, 0);
486 net2272_done(ep, req, 0);
487
488 if (!list_empty(&ep->queue)) {
489 req = list_entry(ep->queue.next,
490 struct net2272_request,
491 queue);
492 status = net2272_kick_dma(ep, req);
493
494 if (status < 0)
495 if ((net2272_ep_read(ep, EP_STAT0)
496 & (1 << BUFFER_EMPTY)))
497 goto top;
498 }
499 return 1;
500 }
501 net2272_ep_write(ep, EP_STAT0, (1 << DATA_PACKET_TRANSMITTED_INTERRUPT));
502 }
503 return 0;
504}
505
506static void
507net2272_out_flush(struct net2272_ep *ep)
508{
509 ASSERT_OUT_NAKING(ep);
510
511 net2272_ep_write(ep, EP_STAT0, (1 << DATA_OUT_TOKEN_INTERRUPT)
512 | (1 << DATA_PACKET_RECEIVED_INTERRUPT));
513 net2272_ep_write(ep, EP_STAT1, 1 << BUFFER_FLUSH);
514}
515
516static int
517net2272_read_packet(struct net2272_ep *ep, u8 *buf,
518 struct net2272_request *req, unsigned avail)
519{
520 u16 __iomem *ep_data = net2272_reg_addr(ep->dev, EP_DATA);
521 unsigned is_short;
522 u16 *bufp;
523
524 req->req.actual += avail;
525
526 dev_vdbg(ep->dev->dev, "read packet %s req %p len %u avail %u\n",
527 ep->ep.name, req, avail,
528 (net2272_ep_read(ep, EP_AVAIL1) << 8) | net2272_ep_read(ep, EP_AVAIL0));
529
530 is_short = (avail < ep->ep.maxpacket);
531
532 if (unlikely(avail == 0)) {
533 /* remove any zlp from the buffer */
534 (void)readw(ep_data);
535 return is_short;
536 }
537
538 /* Ensure we get the final byte */
539 if (unlikely(avail % 2))
540 avail++;
541 bufp = (u16 *)buf;
542
543 do {
544 *bufp++ = readw(ep_data);
545 avail -= 2;
546 } while (avail);
547
548 /*
549 * To avoid false endpoint available race condition must read
550 * ep stat0 twice in the case of a short transfer
551 */
552 if (net2272_ep_read(ep, EP_STAT0) & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT))
553 net2272_ep_read(ep, EP_STAT0);
554
555 return is_short;
556}
557
558static int
559net2272_read_fifo(struct net2272_ep *ep, struct net2272_request *req)
560{
561 u8 *buf;
562 unsigned is_short;
563 int count;
564 int tmp;
565 int cleanup = 0;
566 int status = -1;
567
568 dev_vdbg(ep->dev->dev, "read_fifo %s actual %d len %d\n",
569 ep->ep.name, req->req.actual, req->req.length);
570
571 top:
572 do {
573 buf = req->req.buf + req->req.actual;
574 prefetchw(buf);
575
576 count = (net2272_ep_read(ep, EP_AVAIL1) << 8)
577 | net2272_ep_read(ep, EP_AVAIL0);
578
579 net2272_ep_write(ep, EP_STAT0,
580 (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) |
581 (1 << DATA_PACKET_RECEIVED_INTERRUPT));
582
583 tmp = req->req.length - req->req.actual;
584
585 if (count > tmp) {
586 if ((tmp % ep->ep.maxpacket) != 0) {
587 dev_err(ep->dev->dev,
588 "%s out fifo %d bytes, expected %d\n",
589 ep->ep.name, count, tmp);
590 cleanup = 1;
591 }
592 count = (tmp > 0) ? tmp : 0;
593 }
594
595 is_short = net2272_read_packet(ep, buf, req, count);
596
597 /* completion */
598 if (unlikely(cleanup || is_short ||
599 ((req->req.actual == req->req.length)
600 && !req->req.zero))) {
601
602 if (cleanup) {
603 net2272_out_flush(ep);
604 net2272_done(ep, req, -EOVERFLOW);
605 } else
606 net2272_done(ep, req, 0);
607
608 /* re-initialize endpoint transfer registers
609 * otherwise they may result in erroneous pre-validation
610 * for subsequent control reads
611 */
612 if (unlikely(ep->num == 0)) {
613 net2272_ep_write(ep, EP_TRANSFER2, 0);
614 net2272_ep_write(ep, EP_TRANSFER1, 0);
615 net2272_ep_write(ep, EP_TRANSFER0, 0);
616 }
617
618 if (!list_empty(&ep->queue)) {
619 req = list_entry(ep->queue.next,
620 struct net2272_request, queue);
621 status = net2272_kick_dma(ep, req);
622 if ((status < 0) &&
623 !(net2272_ep_read(ep, EP_STAT0) & (1 << BUFFER_EMPTY)))
624 goto top;
625 }
626 return 1;
627 }
628 } while (!(net2272_ep_read(ep, EP_STAT0) & (1 << BUFFER_EMPTY)));
629
630 return 0;
631}
632
633static void
634net2272_pio_advance(struct net2272_ep *ep)
635{
636 struct net2272_request *req;
637
638 if (unlikely(list_empty(&ep->queue)))
639 return;
640
641 req = list_entry(ep->queue.next, struct net2272_request, queue);
642 (ep->is_in ? net2272_write_fifo : net2272_read_fifo)(ep, req);
643}
644
645/* returns 0 on success, else negative errno */
646static int
647net2272_request_dma(struct net2272 *dev, unsigned ep, u32 buf,
648 unsigned len, unsigned dir)
649{
650 dev_vdbg(dev->dev, "request_dma ep %d buf %08x len %d dir %d\n",
651 ep, buf, len, dir);
652
653 /* The NET2272 only supports a single dma channel */
654 if (dev->dma_busy)
655 return -EBUSY;
656 /*
657 * EP_TRANSFER (used to determine the number of bytes received
658 * in an OUT transfer) is 24 bits wide; don't ask for more than that.
659 */
660 if ((dir == 1) && (len > 0x1000000))
661 return -EINVAL;
662
663 dev->dma_busy = 1;
664
665 /* initialize platform's dma */
666#ifdef CONFIG_PCI
667 /* NET2272 addr, buffer addr, length, etc. */
668 switch (dev->dev_id) {
669 case PCI_DEVICE_ID_RDK1:
670 /* Setup PLX 9054 DMA mode */
671 writel((1 << LOCAL_BUS_WIDTH) |
672 (1 << TA_READY_INPUT_ENABLE) |
673 (0 << LOCAL_BURST_ENABLE) |
674 (1 << DONE_INTERRUPT_ENABLE) |
675 (1 << LOCAL_ADDRESSING_MODE) |
676 (1 << DEMAND_MODE) |
677 (1 << DMA_EOT_ENABLE) |
678 (1 << FAST_SLOW_TERMINATE_MODE_SELECT) |
679 (1 << DMA_CHANNEL_INTERRUPT_SELECT),
680 dev->rdk1.plx9054_base_addr + DMAMODE0);
681
682 writel(0x100000, dev->rdk1.plx9054_base_addr + DMALADR0);
683 writel(buf, dev->rdk1.plx9054_base_addr + DMAPADR0);
684 writel(len, dev->rdk1.plx9054_base_addr + DMASIZ0);
685 writel((dir << DIRECTION_OF_TRANSFER) |
686 (1 << INTERRUPT_AFTER_TERMINAL_COUNT),
687 dev->rdk1.plx9054_base_addr + DMADPR0);
688 writel((1 << LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE) |
689 readl(dev->rdk1.plx9054_base_addr + INTCSR),
690 dev->rdk1.plx9054_base_addr + INTCSR);
691
692 break;
693 }
694#endif
695
696 net2272_write(dev, DMAREQ,
697 (0 << DMA_BUFFER_VALID) |
698 (1 << DMA_REQUEST_ENABLE) |
699 (1 << DMA_CONTROL_DACK) |
700 (dev->dma_eot_polarity << EOT_POLARITY) |
701 (dev->dma_dack_polarity << DACK_POLARITY) |
702 (dev->dma_dreq_polarity << DREQ_POLARITY) |
703 ((ep >> 1) << DMA_ENDPOINT_SELECT));
704
705 (void) net2272_read(dev, SCRATCH);
706
707 return 0;
708}
709
710static void
711net2272_start_dma(struct net2272 *dev)
712{
713 /* start platform's dma controller */
714#ifdef CONFIG_PCI
715 switch (dev->dev_id) {
716 case PCI_DEVICE_ID_RDK1:
717 writeb((1 << CHANNEL_ENABLE) | (1 << CHANNEL_START),
718 dev->rdk1.plx9054_base_addr + DMACSR0);
719 break;
720 }
721#endif
722}
723
724/* returns 0 on success, else negative errno */
725static int
726net2272_kick_dma(struct net2272_ep *ep, struct net2272_request *req)
727{
728 unsigned size;
729 u8 tmp;
730
731 if (!use_dma || (ep->num < 1) || (ep->num > 2) || !ep->dma)
732 return -EINVAL;
733
734 /* don't use dma for odd-length transfers
735 * otherwise, we'd need to deal with the last byte with pio
736 */
737 if (req->req.length & 1)
738 return -EINVAL;
739
740 dev_vdbg(ep->dev->dev, "kick_dma %s req %p dma %08llx\n",
741 ep->ep.name, req, (unsigned long long) req->req.dma);
742
743 net2272_ep_write(ep, EP_RSPSET, 1 << ALT_NAK_OUT_PACKETS);
744
745 /* The NET2272 can only use DMA on one endpoint at a time */
746 if (ep->dev->dma_busy)
747 return -EBUSY;
748
749 /* Make sure we only DMA an even number of bytes (we'll use
750 * pio to complete the transfer)
751 */
752 size = req->req.length;
753 size &= ~1;
754
755 /* device-to-host transfer */
756 if (ep->is_in) {
757 /* initialize platform's dma controller */
758 if (net2272_request_dma(ep->dev, ep->num, req->req.dma, size, 0))
759 /* unable to obtain DMA channel; return error and use pio mode */
760 return -EBUSY;
761 req->req.actual += size;
762
763 /* host-to-device transfer */
764 } else {
765 tmp = net2272_ep_read(ep, EP_STAT0);
766
767 /* initialize platform's dma controller */
768 if (net2272_request_dma(ep->dev, ep->num, req->req.dma, size, 1))
769 /* unable to obtain DMA channel; return error and use pio mode */
770 return -EBUSY;
771
772 if (!(tmp & (1 << BUFFER_EMPTY)))
773 ep->not_empty = 1;
774 else
775 ep->not_empty = 0;
776
777
778 /* allow the endpoint's buffer to fill */
779 net2272_ep_write(ep, EP_RSPCLR, 1 << ALT_NAK_OUT_PACKETS);
780
781 /* this transfer completed and data's already in the fifo
782 * return error so pio gets used.
783 */
784 if (tmp & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) {
785
786 /* deassert dreq */
787 net2272_write(ep->dev, DMAREQ,
788 (0 << DMA_BUFFER_VALID) |
789 (0 << DMA_REQUEST_ENABLE) |
790 (1 << DMA_CONTROL_DACK) |
791 (ep->dev->dma_eot_polarity << EOT_POLARITY) |
792 (ep->dev->dma_dack_polarity << DACK_POLARITY) |
793 (ep->dev->dma_dreq_polarity << DREQ_POLARITY) |
794 ((ep->num >> 1) << DMA_ENDPOINT_SELECT));
795
796 return -EBUSY;
797 }
798 }
799
800 /* Don't use per-packet interrupts: use dma interrupts only */
801 net2272_ep_write(ep, EP_IRQENB, 0);
802
803 net2272_start_dma(ep->dev);
804
805 return 0;
806}
807
808static void net2272_cancel_dma(struct net2272 *dev)
809{
810#ifdef CONFIG_PCI
811 switch (dev->dev_id) {
812 case PCI_DEVICE_ID_RDK1:
813 writeb(0, dev->rdk1.plx9054_base_addr + DMACSR0);
814 writeb(1 << CHANNEL_ABORT, dev->rdk1.plx9054_base_addr + DMACSR0);
815 while (!(readb(dev->rdk1.plx9054_base_addr + DMACSR0) &
816 (1 << CHANNEL_DONE)))
817 continue; /* wait for dma to stabalize */
818
819 /* dma abort generates an interrupt */
820 writeb(1 << CHANNEL_CLEAR_INTERRUPT,
821 dev->rdk1.plx9054_base_addr + DMACSR0);
822 break;
823 }
824#endif
825
826 dev->dma_busy = 0;
827}
828
829/*---------------------------------------------------------------------------*/
830
831static int
832net2272_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
833{
834 struct net2272_request *req;
835 struct net2272_ep *ep;
836 struct net2272 *dev;
837 unsigned long flags;
838 int status = -1;
839 u8 s;
840
841 req = container_of(_req, struct net2272_request, req);
842 if (!_req || !_req->complete || !_req->buf
843 || !list_empty(&req->queue))
844 return -EINVAL;
845 ep = container_of(_ep, struct net2272_ep, ep);
846 if (!_ep || (!ep->desc && ep->num != 0))
847 return -EINVAL;
848 dev = ep->dev;
849 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
850 return -ESHUTDOWN;
851
852 /* set up dma mapping in case the caller didn't */
853 if (use_dma && ep->dma && _req->dma == DMA_ADDR_INVALID) {
854 _req->dma = dma_map_single(dev->dev, _req->buf, _req->length,
855 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
856 req->mapped = 1;
857 }
858
859 dev_vdbg(dev->dev, "%s queue req %p, len %d buf %p dma %08llx %s\n",
860 _ep->name, _req, _req->length, _req->buf,
861 (unsigned long long) _req->dma, _req->zero ? "zero" : "!zero");
862
863 spin_lock_irqsave(&dev->lock, flags);
864
865 _req->status = -EINPROGRESS;
866 _req->actual = 0;
867
868 /* kickstart this i/o queue? */
869 if (list_empty(&ep->queue) && !ep->stopped) {
870 /* maybe there's no control data, just status ack */
871 if (ep->num == 0 && _req->length == 0) {
872 net2272_done(ep, req, 0);
873 dev_vdbg(dev->dev, "%s status ack\n", ep->ep.name);
874 goto done;
875 }
876
877 /* Return zlp, don't let it block subsequent packets */
878 s = net2272_ep_read(ep, EP_STAT0);
879 if (s & (1 << BUFFER_EMPTY)) {
880 /* Buffer is empty check for a blocking zlp, handle it */
881 if ((s & (1 << NAK_OUT_PACKETS)) &&
882 net2272_ep_read(ep, EP_STAT1) & (1 << LOCAL_OUT_ZLP)) {
883 dev_dbg(dev->dev, "WARNING: returning ZLP short packet termination!\n");
884 /*
885 * Request is going to terminate with a short packet ...
886 * hope the client is ready for it!
887 */
888 status = net2272_read_fifo(ep, req);
889 /* clear short packet naking */
890 net2272_ep_write(ep, EP_STAT0, (1 << NAK_OUT_PACKETS));
891 goto done;
892 }
893 }
894
895 /* try dma first */
896 status = net2272_kick_dma(ep, req);
897
898 if (status < 0) {
899 /* dma failed (most likely in use by another endpoint)
900 * fallback to pio
901 */
902 status = 0;
903
904 if (ep->is_in)
905 status = net2272_write_fifo(ep, req);
906 else {
907 s = net2272_ep_read(ep, EP_STAT0);
908 if ((s & (1 << BUFFER_EMPTY)) == 0)
909 status = net2272_read_fifo(ep, req);
910 }
911
912 if (unlikely(status != 0)) {
913 if (status > 0)
914 status = 0;
915 req = NULL;
916 }
917 }
918 }
919 if (likely(req != 0))
920 list_add_tail(&req->queue, &ep->queue);
921
922 if (likely(!list_empty(&ep->queue)))
923 net2272_ep_write(ep, EP_RSPCLR, 1 << ALT_NAK_OUT_PACKETS);
924 done:
925 spin_unlock_irqrestore(&dev->lock, flags);
926
927 return 0;
928}
929
930/* dequeue ALL requests */
931static void
932net2272_dequeue_all(struct net2272_ep *ep)
933{
934 struct net2272_request *req;
935
936 /* called with spinlock held */
937 ep->stopped = 1;
938
939 while (!list_empty(&ep->queue)) {
940 req = list_entry(ep->queue.next,
941 struct net2272_request,
942 queue);
943 net2272_done(ep, req, -ESHUTDOWN);
944 }
945}
946
947/* dequeue JUST ONE request */
948static int
949net2272_dequeue(struct usb_ep *_ep, struct usb_request *_req)
950{
951 struct net2272_ep *ep;
952 struct net2272_request *req;
953 unsigned long flags;
954 int stopped;
955
956 ep = container_of(_ep, struct net2272_ep, ep);
957 if (!_ep || (!ep->desc && ep->num != 0) || !_req)
958 return -EINVAL;
959
960 spin_lock_irqsave(&ep->dev->lock, flags);
961 stopped = ep->stopped;
962 ep->stopped = 1;
963
964 /* make sure it's still queued on this endpoint */
965 list_for_each_entry(req, &ep->queue, queue) {
966 if (&req->req == _req)
967 break;
968 }
969 if (&req->req != _req) {
970 spin_unlock_irqrestore(&ep->dev->lock, flags);
971 return -EINVAL;
972 }
973
974 /* queue head may be partially complete */
975 if (ep->queue.next == &req->queue) {
976 dev_dbg(ep->dev->dev, "unlink (%s) pio\n", _ep->name);
977 net2272_done(ep, req, -ECONNRESET);
978 }
979 req = NULL;
980 ep->stopped = stopped;
981
982 spin_unlock_irqrestore(&ep->dev->lock, flags);
983 return 0;
984}
985
986/*---------------------------------------------------------------------------*/
987
988static int
989net2272_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
990{
991 struct net2272_ep *ep;
992 unsigned long flags;
993 int ret = 0;
994
995 ep = container_of(_ep, struct net2272_ep, ep);
996 if (!_ep || (!ep->desc && ep->num != 0))
997 return -EINVAL;
998 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
999 return -ESHUTDOWN;
1000 if (ep->desc /* not ep0 */ && usb_endpoint_xfer_isoc(ep->desc))
1001 return -EINVAL;
1002
1003 spin_lock_irqsave(&ep->dev->lock, flags);
1004 if (!list_empty(&ep->queue))
1005 ret = -EAGAIN;
1006 else if (ep->is_in && value && net2272_fifo_status(_ep) != 0)
1007 ret = -EAGAIN;
1008 else {
1009 dev_vdbg(ep->dev->dev, "%s %s %s\n", _ep->name,
1010 value ? "set" : "clear",
1011 wedged ? "wedge" : "halt");
1012 /* set/clear */
1013 if (value) {
1014 if (ep->num == 0)
1015 ep->dev->protocol_stall = 1;
1016 else
1017 set_halt(ep);
1018 if (wedged)
1019 ep->wedged = 1;
1020 } else {
1021 clear_halt(ep);
1022 ep->wedged = 0;
1023 }
1024 }
1025 spin_unlock_irqrestore(&ep->dev->lock, flags);
1026
1027 return ret;
1028}
1029
1030static int
1031net2272_set_halt(struct usb_ep *_ep, int value)
1032{
1033 return net2272_set_halt_and_wedge(_ep, value, 0);
1034}
1035
1036static int
1037net2272_set_wedge(struct usb_ep *_ep)
1038{
1039 if (!_ep || _ep->name == ep0name)
1040 return -EINVAL;
1041 return net2272_set_halt_and_wedge(_ep, 1, 1);
1042}
1043
1044static int
1045net2272_fifo_status(struct usb_ep *_ep)
1046{
1047 struct net2272_ep *ep;
1048 u16 avail;
1049
1050 ep = container_of(_ep, struct net2272_ep, ep);
1051 if (!_ep || (!ep->desc && ep->num != 0))
1052 return -ENODEV;
1053 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1054 return -ESHUTDOWN;
1055
1056 avail = net2272_ep_read(ep, EP_AVAIL1) << 8;
1057 avail |= net2272_ep_read(ep, EP_AVAIL0);
1058 if (avail > ep->fifo_size)
1059 return -EOVERFLOW;
1060 if (ep->is_in)
1061 avail = ep->fifo_size - avail;
1062 return avail;
1063}
1064
1065static void
1066net2272_fifo_flush(struct usb_ep *_ep)
1067{
1068 struct net2272_ep *ep;
1069
1070 ep = container_of(_ep, struct net2272_ep, ep);
1071 if (!_ep || (!ep->desc && ep->num != 0))
1072 return;
1073 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1074 return;
1075
1076 net2272_ep_write(ep, EP_STAT1, 1 << BUFFER_FLUSH);
1077}
1078
1079static struct usb_ep_ops net2272_ep_ops = {
1080 .enable = net2272_enable,
1081 .disable = net2272_disable,
1082
1083 .alloc_request = net2272_alloc_request,
1084 .free_request = net2272_free_request,
1085
1086 .queue = net2272_queue,
1087 .dequeue = net2272_dequeue,
1088
1089 .set_halt = net2272_set_halt,
1090 .set_wedge = net2272_set_wedge,
1091 .fifo_status = net2272_fifo_status,
1092 .fifo_flush = net2272_fifo_flush,
1093};
1094
1095/*---------------------------------------------------------------------------*/
1096
1097static int
1098net2272_get_frame(struct usb_gadget *_gadget)
1099{
1100 struct net2272 *dev;
1101 unsigned long flags;
1102 u16 ret;
1103
1104 if (!_gadget)
1105 return -ENODEV;
1106 dev = container_of(_gadget, struct net2272, gadget);
1107 spin_lock_irqsave(&dev->lock, flags);
1108
1109 ret = net2272_read(dev, FRAME1) << 8;
1110 ret |= net2272_read(dev, FRAME0);
1111
1112 spin_unlock_irqrestore(&dev->lock, flags);
1113 return ret;
1114}
1115
1116static int
1117net2272_wakeup(struct usb_gadget *_gadget)
1118{
1119 struct net2272 *dev;
1120 u8 tmp;
1121 unsigned long flags;
1122
1123 if (!_gadget)
1124 return 0;
1125 dev = container_of(_gadget, struct net2272, gadget);
1126
1127 spin_lock_irqsave(&dev->lock, flags);
1128 tmp = net2272_read(dev, USBCTL0);
1129 if (tmp & (1 << IO_WAKEUP_ENABLE))
1130 net2272_write(dev, USBCTL1, (1 << GENERATE_RESUME));
1131
1132 spin_unlock_irqrestore(&dev->lock, flags);
1133
1134 return 0;
1135}
1136
1137static int
1138net2272_set_selfpowered(struct usb_gadget *_gadget, int value)
1139{
1140 struct net2272 *dev;
1141
1142 if (!_gadget)
1143 return -ENODEV;
1144 dev = container_of(_gadget, struct net2272, gadget);
1145
1146 dev->is_selfpowered = value;
1147
1148 return 0;
1149}
1150
1151static int
1152net2272_pullup(struct usb_gadget *_gadget, int is_on)
1153{
1154 struct net2272 *dev;
1155 u8 tmp;
1156 unsigned long flags;
1157
1158 if (!_gadget)
1159 return -ENODEV;
1160 dev = container_of(_gadget, struct net2272, gadget);
1161
1162 spin_lock_irqsave(&dev->lock, flags);
1163 tmp = net2272_read(dev, USBCTL0);
1164 dev->softconnect = (is_on != 0);
1165 if (is_on)
1166 tmp |= (1 << USB_DETECT_ENABLE);
1167 else
1168 tmp &= ~(1 << USB_DETECT_ENABLE);
1169 net2272_write(dev, USBCTL0, tmp);
1170 spin_unlock_irqrestore(&dev->lock, flags);
1171
1172 return 0;
1173}
1174
1175static int net2272_start(struct usb_gadget_driver *driver,
1176 int (*bind)(struct usb_gadget *));
1177static int net2272_stop(struct usb_gadget_driver *driver);
1178
1179static const struct usb_gadget_ops net2272_ops = {
1180 .get_frame = net2272_get_frame,
1181 .wakeup = net2272_wakeup,
1182 .set_selfpowered = net2272_set_selfpowered,
1183 .pullup = net2272_pullup,
1184 .start = net2272_start,
1185 .stop = net2272_stop,
1186};
1187
1188/*---------------------------------------------------------------------------*/
1189
1190static ssize_t
1191net2272_show_registers(struct device *_dev, struct device_attribute *attr, char *buf)
1192{
1193 struct net2272 *dev;
1194 char *next;
1195 unsigned size, t;
1196 unsigned long flags;
1197 u8 t1, t2;
1198 int i;
1199 const char *s;
1200
1201 dev = dev_get_drvdata(_dev);
1202 next = buf;
1203 size = PAGE_SIZE;
1204 spin_lock_irqsave(&dev->lock, flags);
1205
1206 if (dev->driver)
1207 s = dev->driver->driver.name;
1208 else
1209 s = "(none)";
1210
1211 /* Main Control Registers */
1212 t = scnprintf(next, size, "%s version %s,"
1213 "chiprev %02x, locctl %02x\n"
1214 "irqenb0 %02x irqenb1 %02x "
1215 "irqstat0 %02x irqstat1 %02x\n",
1216 driver_name, driver_vers, dev->chiprev,
1217 net2272_read(dev, LOCCTL),
1218 net2272_read(dev, IRQENB0),
1219 net2272_read(dev, IRQENB1),
1220 net2272_read(dev, IRQSTAT0),
1221 net2272_read(dev, IRQSTAT1));
1222 size -= t;
1223 next += t;
1224
1225 /* DMA */
1226 t1 = net2272_read(dev, DMAREQ);
1227 t = scnprintf(next, size, "\ndmareq %02x: %s %s%s%s%s\n",
1228 t1, ep_name[(t1 & 0x01) + 1],
1229 t1 & (1 << DMA_CONTROL_DACK) ? "dack " : "",
1230 t1 & (1 << DMA_REQUEST_ENABLE) ? "reqenb " : "",
1231 t1 & (1 << DMA_REQUEST) ? "req " : "",
1232 t1 & (1 << DMA_BUFFER_VALID) ? "valid " : "");
1233 size -= t;
1234 next += t;
1235
1236 /* USB Control Registers */
1237 t1 = net2272_read(dev, USBCTL1);
1238 if (t1 & (1 << VBUS_PIN)) {
1239 if (t1 & (1 << USB_HIGH_SPEED))
1240 s = "high speed";
1241 else if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1242 s = "powered";
1243 else
1244 s = "full speed";
1245 } else
1246 s = "not attached";
1247 t = scnprintf(next, size,
1248 "usbctl0 %02x usbctl1 %02x addr 0x%02x (%s)\n",
1249 net2272_read(dev, USBCTL0), t1,
1250 net2272_read(dev, OURADDR), s);
1251 size -= t;
1252 next += t;
1253
1254 /* Endpoint Registers */
1255 for (i = 0; i < 4; ++i) {
1256 struct net2272_ep *ep;
1257
1258 ep = &dev->ep[i];
1259 if (i && !ep->desc)
1260 continue;
1261
1262 t1 = net2272_ep_read(ep, EP_CFG);
1263 t2 = net2272_ep_read(ep, EP_RSPSET);
1264 t = scnprintf(next, size,
1265 "\n%s\tcfg %02x rsp (%02x) %s%s%s%s%s%s%s%s"
1266 "irqenb %02x\n",
1267 ep->ep.name, t1, t2,
1268 (t2 & (1 << ALT_NAK_OUT_PACKETS)) ? "NAK " : "",
1269 (t2 & (1 << HIDE_STATUS_PHASE)) ? "hide " : "",
1270 (t2 & (1 << AUTOVALIDATE)) ? "auto " : "",
1271 (t2 & (1 << INTERRUPT_MODE)) ? "interrupt " : "",
1272 (t2 & (1 << CONTROL_STATUS_PHASE_HANDSHAKE)) ? "status " : "",
1273 (t2 & (1 << NAK_OUT_PACKETS_MODE)) ? "NAKmode " : "",
1274 (t2 & (1 << ENDPOINT_TOGGLE)) ? "DATA1 " : "DATA0 ",
1275 (t2 & (1 << ENDPOINT_HALT)) ? "HALT " : "",
1276 net2272_ep_read(ep, EP_IRQENB));
1277 size -= t;
1278 next += t;
1279
1280 t = scnprintf(next, size,
1281 "\tstat0 %02x stat1 %02x avail %04x "
1282 "(ep%d%s-%s)%s\n",
1283 net2272_ep_read(ep, EP_STAT0),
1284 net2272_ep_read(ep, EP_STAT1),
1285 (net2272_ep_read(ep, EP_AVAIL1) << 8) | net2272_ep_read(ep, EP_AVAIL0),
1286 t1 & 0x0f,
1287 ep->is_in ? "in" : "out",
1288 type_string(t1 >> 5),
1289 ep->stopped ? "*" : "");
1290 size -= t;
1291 next += t;
1292
1293 t = scnprintf(next, size,
1294 "\tep_transfer %06x\n",
1295 ((net2272_ep_read(ep, EP_TRANSFER2) & 0xff) << 16) |
1296 ((net2272_ep_read(ep, EP_TRANSFER1) & 0xff) << 8) |
1297 ((net2272_ep_read(ep, EP_TRANSFER0) & 0xff)));
1298 size -= t;
1299 next += t;
1300
1301 t1 = net2272_ep_read(ep, EP_BUFF_STATES) & 0x03;
1302 t2 = (net2272_ep_read(ep, EP_BUFF_STATES) >> 2) & 0x03;
1303 t = scnprintf(next, size,
1304 "\tbuf-a %s buf-b %s\n",
1305 buf_state_string(t1),
1306 buf_state_string(t2));
1307 size -= t;
1308 next += t;
1309 }
1310
1311 spin_unlock_irqrestore(&dev->lock, flags);
1312
1313 return PAGE_SIZE - size;
1314}
1315static DEVICE_ATTR(registers, S_IRUGO, net2272_show_registers, NULL);
1316
1317/*---------------------------------------------------------------------------*/
1318
1319static void
1320net2272_set_fifo_mode(struct net2272 *dev, int mode)
1321{
1322 u8 tmp;
1323
1324 tmp = net2272_read(dev, LOCCTL) & 0x3f;
1325 tmp |= (mode << 6);
1326 net2272_write(dev, LOCCTL, tmp);
1327
1328 INIT_LIST_HEAD(&dev->gadget.ep_list);
1329
1330 /* always ep-a, ep-c ... maybe not ep-b */
1331 list_add_tail(&dev->ep[1].ep.ep_list, &dev->gadget.ep_list);
1332
1333 switch (mode) {
1334 case 0:
1335 list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list);
1336 dev->ep[1].fifo_size = dev->ep[2].fifo_size = 512;
1337 break;
1338 case 1:
1339 list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list);
1340 dev->ep[1].fifo_size = 1024;
1341 dev->ep[2].fifo_size = 512;
1342 break;
1343 case 2:
1344 list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list);
1345 dev->ep[1].fifo_size = dev->ep[2].fifo_size = 1024;
1346 break;
1347 case 3:
1348 dev->ep[1].fifo_size = 1024;
1349 break;
1350 }
1351
1352 /* ep-c is always 2 512 byte buffers */
1353 list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list);
1354 dev->ep[3].fifo_size = 512;
1355}
1356
1357/*---------------------------------------------------------------------------*/
1358
1359static struct net2272 *the_controller;
1360
1361static void
1362net2272_usb_reset(struct net2272 *dev)
1363{
1364 dev->gadget.speed = USB_SPEED_UNKNOWN;
1365
1366 net2272_cancel_dma(dev);
1367
1368 net2272_write(dev, IRQENB0, 0);
1369 net2272_write(dev, IRQENB1, 0);
1370
1371 /* clear irq state */
1372 net2272_write(dev, IRQSTAT0, 0xff);
1373 net2272_write(dev, IRQSTAT1, ~(1 << SUSPEND_REQUEST_INTERRUPT));
1374
1375 net2272_write(dev, DMAREQ,
1376 (0 << DMA_BUFFER_VALID) |
1377 (0 << DMA_REQUEST_ENABLE) |
1378 (1 << DMA_CONTROL_DACK) |
1379 (dev->dma_eot_polarity << EOT_POLARITY) |
1380 (dev->dma_dack_polarity << DACK_POLARITY) |
1381 (dev->dma_dreq_polarity << DREQ_POLARITY) |
1382 ((dma_ep >> 1) << DMA_ENDPOINT_SELECT));
1383
1384 net2272_cancel_dma(dev);
1385 net2272_set_fifo_mode(dev, (fifo_mode <= 3) ? fifo_mode : 0);
1386
1387 /* Set the NET2272 ep fifo data width to 16-bit mode and for correct byte swapping
1388 * note that the higher level gadget drivers are expected to convert data to little endian.
1389 * Enable byte swap for your local bus/cpu if needed by setting BYTE_SWAP in LOCCTL here
1390 */
1391 net2272_write(dev, LOCCTL, net2272_read(dev, LOCCTL) | (1 << DATA_WIDTH));
1392 net2272_write(dev, LOCCTL1, (dma_mode << DMA_MODE));
1393}
1394
1395static void
1396net2272_usb_reinit(struct net2272 *dev)
1397{
1398 int i;
1399
1400 /* basic endpoint init */
1401 for (i = 0; i < 4; ++i) {
1402 struct net2272_ep *ep = &dev->ep[i];
1403
1404 ep->ep.name = ep_name[i];
1405 ep->dev = dev;
1406 ep->num = i;
1407 ep->not_empty = 0;
1408
1409 if (use_dma && ep->num == dma_ep)
1410 ep->dma = 1;
1411
1412 if (i > 0 && i <= 3)
1413 ep->fifo_size = 512;
1414 else
1415 ep->fifo_size = 64;
1416 net2272_ep_reset(ep);
1417 }
1418 dev->ep[0].ep.maxpacket = 64;
1419
1420 dev->gadget.ep0 = &dev->ep[0].ep;
1421 dev->ep[0].stopped = 0;
1422 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
1423}
1424
1425static void
1426net2272_ep0_start(struct net2272 *dev)
1427{
1428 struct net2272_ep *ep0 = &dev->ep[0];
1429
1430 net2272_ep_write(ep0, EP_RSPSET,
1431 (1 << NAK_OUT_PACKETS_MODE) |
1432 (1 << ALT_NAK_OUT_PACKETS));
1433 net2272_ep_write(ep0, EP_RSPCLR,
1434 (1 << HIDE_STATUS_PHASE) |
1435 (1 << CONTROL_STATUS_PHASE_HANDSHAKE));
1436 net2272_write(dev, USBCTL0,
1437 (dev->softconnect << USB_DETECT_ENABLE) |
1438 (1 << USB_ROOT_PORT_WAKEUP_ENABLE) |
1439 (1 << IO_WAKEUP_ENABLE));
1440 net2272_write(dev, IRQENB0,
1441 (1 << SETUP_PACKET_INTERRUPT_ENABLE) |
1442 (1 << ENDPOINT_0_INTERRUPT_ENABLE) |
1443 (1 << DMA_DONE_INTERRUPT_ENABLE));
1444 net2272_write(dev, IRQENB1,
1445 (1 << VBUS_INTERRUPT_ENABLE) |
1446 (1 << ROOT_PORT_RESET_INTERRUPT_ENABLE) |
1447 (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE));
1448}
1449
1450/* when a driver is successfully registered, it will receive
1451 * control requests including set_configuration(), which enables
1452 * non-control requests. then usb traffic follows until a
1453 * disconnect is reported. then a host may connect again, or
1454 * the driver might get unbound.
1455 */
1456static int net2272_start(struct usb_gadget_driver *driver,
1457 int (*bind)(struct usb_gadget *))
1458{
1459 struct net2272 *dev = the_controller;
1460 int ret;
1461 unsigned i;
1462
1463 if (!driver || !bind || !driver->unbind || !driver->setup ||
1464 driver->speed != USB_SPEED_HIGH)
1465 return -EINVAL;
1466 if (!dev)
1467 return -ENODEV;
1468 if (dev->driver)
1469 return -EBUSY;
1470
1471 for (i = 0; i < 4; ++i)
1472 dev->ep[i].irqs = 0;
1473 /* hook up the driver ... */
1474 dev->softconnect = 1;
1475 driver->driver.bus = NULL;
1476 dev->driver = driver;
1477 dev->gadget.dev.driver = &driver->driver;
1478 ret = bind(&dev->gadget);
1479 if (ret) {
1480 dev_dbg(dev->dev, "bind to driver %s --> %d\n",
1481 driver->driver.name, ret);
1482 dev->driver = NULL;
1483 dev->gadget.dev.driver = NULL;
1484 return ret;
1485 }
1486
1487 /* ... then enable host detection and ep0; and we're ready
1488 * for set_configuration as well as eventual disconnect.
1489 */
1490 net2272_ep0_start(dev);
1491
1492 dev_dbg(dev->dev, "%s ready\n", driver->driver.name);
1493
1494 return 0;
1495}
1496
1497static void
1498stop_activity(struct net2272 *dev, struct usb_gadget_driver *driver)
1499{
1500 int i;
1501
1502 /* don't disconnect if it's not connected */
1503 if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1504 driver = NULL;
1505
1506 /* stop hardware; prevent new request submissions;
1507 * and kill any outstanding requests.
1508 */
1509 net2272_usb_reset(dev);
1510 for (i = 0; i < 4; ++i)
1511 net2272_dequeue_all(&dev->ep[i]);
1512
1513 /* report disconnect; the driver is already quiesced */
1514 if (driver) {
1515 spin_unlock(&dev->lock);
1516 driver->disconnect(&dev->gadget);
1517 spin_lock(&dev->lock);
1518
1519 }
1520 net2272_usb_reinit(dev);
1521}
1522
1523static int net2272_stop(struct usb_gadget_driver *driver)
1524{
1525 struct net2272 *dev = the_controller;
1526 unsigned long flags;
1527
1528 if (!dev)
1529 return -ENODEV;
1530 if (!driver || driver != dev->driver)
1531 return -EINVAL;
1532
1533 spin_lock_irqsave(&dev->lock, flags);
1534 stop_activity(dev, driver);
1535 spin_unlock_irqrestore(&dev->lock, flags);
1536
1537 net2272_pullup(&dev->gadget, 0);
1538
1539 driver->unbind(&dev->gadget);
1540 dev->gadget.dev.driver = NULL;
1541 dev->driver = NULL;
1542
1543 dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name);
1544 return 0;
1545}
1546
1547/*---------------------------------------------------------------------------*/
1548/* handle ep-a/ep-b dma completions */
1549static void
1550net2272_handle_dma(struct net2272_ep *ep)
1551{
1552 struct net2272_request *req;
1553 unsigned len;
1554 int status;
1555
1556 if (!list_empty(&ep->queue))
1557 req = list_entry(ep->queue.next,
1558 struct net2272_request, queue);
1559 else
1560 req = NULL;
1561
1562 dev_vdbg(ep->dev->dev, "handle_dma %s req %p\n", ep->ep.name, req);
1563
1564 /* Ensure DREQ is de-asserted */
1565 net2272_write(ep->dev, DMAREQ,
1566 (0 << DMA_BUFFER_VALID)
1567 | (0 << DMA_REQUEST_ENABLE)
1568 | (1 << DMA_CONTROL_DACK)
1569 | (ep->dev->dma_eot_polarity << EOT_POLARITY)
1570 | (ep->dev->dma_dack_polarity << DACK_POLARITY)
1571 | (ep->dev->dma_dreq_polarity << DREQ_POLARITY)
1572 | ((ep->dma >> 1) << DMA_ENDPOINT_SELECT));
1573
1574 ep->dev->dma_busy = 0;
1575
1576 net2272_ep_write(ep, EP_IRQENB,
1577 (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE)
1578 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE)
1579 | net2272_ep_read(ep, EP_IRQENB));
1580
1581 /* device-to-host transfer completed */
1582 if (ep->is_in) {
1583 /* validate a short packet or zlp if necessary */
1584 if ((req->req.length % ep->ep.maxpacket != 0) ||
1585 req->req.zero)
1586 set_fifo_bytecount(ep, 0);
1587
1588 net2272_done(ep, req, 0);
1589 if (!list_empty(&ep->queue)) {
1590 req = list_entry(ep->queue.next,
1591 struct net2272_request, queue);
1592 status = net2272_kick_dma(ep, req);
1593 if (status < 0)
1594 net2272_pio_advance(ep);
1595 }
1596
1597 /* host-to-device transfer completed */
1598 } else {
1599 /* terminated with a short packet? */
1600 if (net2272_read(ep->dev, IRQSTAT0) &
1601 (1 << DMA_DONE_INTERRUPT)) {
1602 /* abort system dma */
1603 net2272_cancel_dma(ep->dev);
1604 }
1605
1606 /* EP_TRANSFER will contain the number of bytes
1607 * actually received.
1608 * NOTE: There is no overflow detection on EP_TRANSFER:
1609 * We can't deal with transfers larger than 2^24 bytes!
1610 */
1611 len = (net2272_ep_read(ep, EP_TRANSFER2) << 16)
1612 | (net2272_ep_read(ep, EP_TRANSFER1) << 8)
1613 | (net2272_ep_read(ep, EP_TRANSFER0));
1614
1615 if (ep->not_empty)
1616 len += 4;
1617
1618 req->req.actual += len;
1619
1620 /* get any remaining data */
1621 net2272_pio_advance(ep);
1622 }
1623}
1624
1625/*---------------------------------------------------------------------------*/
1626
1627static void
1628net2272_handle_ep(struct net2272_ep *ep)
1629{
1630 struct net2272_request *req;
1631 u8 stat0, stat1;
1632
1633 if (!list_empty(&ep->queue))
1634 req = list_entry(ep->queue.next,
1635 struct net2272_request, queue);
1636 else
1637 req = NULL;
1638
1639 /* ack all, and handle what we care about */
1640 stat0 = net2272_ep_read(ep, EP_STAT0);
1641 stat1 = net2272_ep_read(ep, EP_STAT1);
1642 ep->irqs++;
1643
1644 dev_vdbg(ep->dev->dev, "%s ack ep_stat0 %02x, ep_stat1 %02x, req %p\n",
1645 ep->ep.name, stat0, stat1, req ? &req->req : 0);
1646
1647 net2272_ep_write(ep, EP_STAT0, stat0 &
1648 ~((1 << NAK_OUT_PACKETS)
1649 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)));
1650 net2272_ep_write(ep, EP_STAT1, stat1);
1651
1652 /* data packet(s) received (in the fifo, OUT)
1653 * direction must be validated, otherwise control read status phase
1654 * could be interpreted as a valid packet
1655 */
1656 if (!ep->is_in && (stat0 & (1 << DATA_PACKET_RECEIVED_INTERRUPT)))
1657 net2272_pio_advance(ep);
1658 /* data packet(s) transmitted (IN) */
1659 else if (stat0 & (1 << DATA_PACKET_TRANSMITTED_INTERRUPT))
1660 net2272_pio_advance(ep);
1661}
1662
1663static struct net2272_ep *
1664net2272_get_ep_by_addr(struct net2272 *dev, u16 wIndex)
1665{
1666 struct net2272_ep *ep;
1667
1668 if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
1669 return &dev->ep[0];
1670
1671 list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) {
1672 u8 bEndpointAddress;
1673
1674 if (!ep->desc)
1675 continue;
1676 bEndpointAddress = ep->desc->bEndpointAddress;
1677 if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
1678 continue;
1679 if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f))
1680 return ep;
1681 }
1682 return NULL;
1683}
1684
1685/*
1686 * USB Test Packet:
1687 * JKJKJKJK * 9
1688 * JJKKJJKK * 8
1689 * JJJJKKKK * 8
1690 * JJJJJJJKKKKKKK * 8
1691 * JJJJJJJK * 8
1692 * {JKKKKKKK * 10}, JK
1693 */
1694static const u8 net2272_test_packet[] = {
1695 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1696 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
1697 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
1698 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1699 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD,
1700 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFD, 0x7E
1701};
1702
1703static void
1704net2272_set_test_mode(struct net2272 *dev, int mode)
1705{
1706 int i;
1707
1708 /* Disable all net2272 interrupts:
1709 * Nothing but a power cycle should stop the test.
1710 */
1711 net2272_write(dev, IRQENB0, 0x00);
1712 net2272_write(dev, IRQENB1, 0x00);
1713
1714 /* Force tranceiver to high-speed */
1715 net2272_write(dev, XCVRDIAG, 1 << FORCE_HIGH_SPEED);
1716
1717 net2272_write(dev, PAGESEL, 0);
1718 net2272_write(dev, EP_STAT0, 1 << DATA_PACKET_TRANSMITTED_INTERRUPT);
1719 net2272_write(dev, EP_RSPCLR,
1720 (1 << CONTROL_STATUS_PHASE_HANDSHAKE)
1721 | (1 << HIDE_STATUS_PHASE));
1722 net2272_write(dev, EP_CFG, 1 << ENDPOINT_DIRECTION);
1723 net2272_write(dev, EP_STAT1, 1 << BUFFER_FLUSH);
1724
1725 /* wait for status phase to complete */
1726 while (!(net2272_read(dev, EP_STAT0) &
1727 (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)))
1728 ;
1729
1730 /* Enable test mode */
1731 net2272_write(dev, USBTEST, mode);
1732
1733 /* load test packet */
1734 if (mode == TEST_PACKET) {
1735 /* switch to 8 bit mode */
1736 net2272_write(dev, LOCCTL, net2272_read(dev, LOCCTL) &
1737 ~(1 << DATA_WIDTH));
1738
1739 for (i = 0; i < sizeof(net2272_test_packet); ++i)
1740 net2272_write(dev, EP_DATA, net2272_test_packet[i]);
1741
1742 /* Validate test packet */
1743 net2272_write(dev, EP_TRANSFER0, 0);
1744 }
1745}
1746
1747static void
1748net2272_handle_stat0_irqs(struct net2272 *dev, u8 stat)
1749{
1750 struct net2272_ep *ep;
1751 u8 num, scratch;
1752
1753 /* starting a control request? */
1754 if (unlikely(stat & (1 << SETUP_PACKET_INTERRUPT))) {
1755 union {
1756 u8 raw[8];
1757 struct usb_ctrlrequest r;
1758 } u;
1759 int tmp = 0;
1760 struct net2272_request *req;
1761
1762 if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
1763 if (net2272_read(dev, USBCTL1) & (1 << USB_HIGH_SPEED))
1764 dev->gadget.speed = USB_SPEED_HIGH;
1765 else
1766 dev->gadget.speed = USB_SPEED_FULL;
1767 dev_dbg(dev->dev, "%s speed\n",
1768 (dev->gadget.speed == USB_SPEED_HIGH) ? "high" : "full");
1769 }
1770
1771 ep = &dev->ep[0];
1772 ep->irqs++;
1773
1774 /* make sure any leftover interrupt state is cleared */
1775 stat &= ~(1 << ENDPOINT_0_INTERRUPT);
1776 while (!list_empty(&ep->queue)) {
1777 req = list_entry(ep->queue.next,
1778 struct net2272_request, queue);
1779 net2272_done(ep, req,
1780 (req->req.actual == req->req.length) ? 0 : -EPROTO);
1781 }
1782 ep->stopped = 0;
1783 dev->protocol_stall = 0;
1784 net2272_ep_write(ep, EP_STAT0,
1785 (1 << DATA_IN_TOKEN_INTERRUPT)
1786 | (1 << DATA_OUT_TOKEN_INTERRUPT)
1787 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)
1788 | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
1789 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT));
1790 net2272_ep_write(ep, EP_STAT1,
1791 (1 << TIMEOUT)
1792 | (1 << USB_OUT_ACK_SENT)
1793 | (1 << USB_OUT_NAK_SENT)
1794 | (1 << USB_IN_ACK_RCVD)
1795 | (1 << USB_IN_NAK_SENT)
1796 | (1 << USB_STALL_SENT)
1797 | (1 << LOCAL_OUT_ZLP));
1798
1799 /*
1800 * Ensure Control Read pre-validation setting is beyond maximum size
1801 * - Control Writes can leave non-zero values in EP_TRANSFER. If
1802 * an EP0 transfer following the Control Write is a Control Read,
1803 * the NET2272 sees the non-zero EP_TRANSFER as an unexpected
1804 * pre-validation count.
1805 * - Setting EP_TRANSFER beyond the maximum EP0 transfer size ensures
1806 * the pre-validation count cannot cause an unexpected validatation
1807 */
1808 net2272_write(dev, PAGESEL, 0);
1809 net2272_write(dev, EP_TRANSFER2, 0xff);
1810 net2272_write(dev, EP_TRANSFER1, 0xff);
1811 net2272_write(dev, EP_TRANSFER0, 0xff);
1812
1813 u.raw[0] = net2272_read(dev, SETUP0);
1814 u.raw[1] = net2272_read(dev, SETUP1);
1815 u.raw[2] = net2272_read(dev, SETUP2);
1816 u.raw[3] = net2272_read(dev, SETUP3);
1817 u.raw[4] = net2272_read(dev, SETUP4);
1818 u.raw[5] = net2272_read(dev, SETUP5);
1819 u.raw[6] = net2272_read(dev, SETUP6);
1820 u.raw[7] = net2272_read(dev, SETUP7);
1821 /*
1822 * If you have a big endian cpu make sure le16_to_cpus
1823 * performs the proper byte swapping here...
1824 */
1825 le16_to_cpus(&u.r.wValue);
1826 le16_to_cpus(&u.r.wIndex);
1827 le16_to_cpus(&u.r.wLength);
1828
1829 /* ack the irq */
1830 net2272_write(dev, IRQSTAT0, 1 << SETUP_PACKET_INTERRUPT);
1831 stat ^= (1 << SETUP_PACKET_INTERRUPT);
1832
1833 /* watch control traffic at the token level, and force
1834 * synchronization before letting the status phase happen.
1835 */
1836 ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0;
1837 if (ep->is_in) {
1838 scratch = (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE)
1839 | (1 << DATA_OUT_TOKEN_INTERRUPT_ENABLE)
1840 | (1 << DATA_IN_TOKEN_INTERRUPT_ENABLE);
1841 stop_out_naking(ep);
1842 } else
1843 scratch = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE)
1844 | (1 << DATA_OUT_TOKEN_INTERRUPT_ENABLE)
1845 | (1 << DATA_IN_TOKEN_INTERRUPT_ENABLE);
1846 net2272_ep_write(ep, EP_IRQENB, scratch);
1847
1848 if ((u.r.bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD)
1849 goto delegate;
1850 switch (u.r.bRequest) {
1851 case USB_REQ_GET_STATUS: {
1852 struct net2272_ep *e;
1853 u16 status = 0;
1854
1855 switch (u.r.bRequestType & USB_RECIP_MASK) {
1856 case USB_RECIP_ENDPOINT:
1857 e = net2272_get_ep_by_addr(dev, u.r.wIndex);
1858 if (!e || u.r.wLength > 2)
1859 goto do_stall;
1860 if (net2272_ep_read(e, EP_RSPSET) & (1 << ENDPOINT_HALT))
1861 status = __constant_cpu_to_le16(1);
1862 else
1863 status = __constant_cpu_to_le16(0);
1864
1865 /* don't bother with a request object! */
1866 net2272_ep_write(&dev->ep[0], EP_IRQENB, 0);
1867 writew(status, net2272_reg_addr(dev, EP_DATA));
1868 set_fifo_bytecount(&dev->ep[0], 0);
1869 allow_status(ep);
1870 dev_vdbg(dev->dev, "%s stat %02x\n",
1871 ep->ep.name, status);
1872 goto next_endpoints;
1873 case USB_RECIP_DEVICE:
1874 if (u.r.wLength > 2)
1875 goto do_stall;
1876 if (dev->is_selfpowered)
1877 status = (1 << USB_DEVICE_SELF_POWERED);
1878
1879 /* don't bother with a request object! */
1880 net2272_ep_write(&dev->ep[0], EP_IRQENB, 0);
1881 writew(status, net2272_reg_addr(dev, EP_DATA));
1882 set_fifo_bytecount(&dev->ep[0], 0);
1883 allow_status(ep);
1884 dev_vdbg(dev->dev, "device stat %02x\n", status);
1885 goto next_endpoints;
1886 case USB_RECIP_INTERFACE:
1887 if (u.r.wLength > 2)
1888 goto do_stall;
1889
1890 /* don't bother with a request object! */
1891 net2272_ep_write(&dev->ep[0], EP_IRQENB, 0);
1892 writew(status, net2272_reg_addr(dev, EP_DATA));
1893 set_fifo_bytecount(&dev->ep[0], 0);
1894 allow_status(ep);
1895 dev_vdbg(dev->dev, "interface status %02x\n", status);
1896 goto next_endpoints;
1897 }
1898
1899 break;
1900 }
1901 case USB_REQ_CLEAR_FEATURE: {
1902 struct net2272_ep *e;
1903
1904 if (u.r.bRequestType != USB_RECIP_ENDPOINT)
1905 goto delegate;
1906 if (u.r.wValue != USB_ENDPOINT_HALT ||
1907 u.r.wLength != 0)
1908 goto do_stall;
1909 e = net2272_get_ep_by_addr(dev, u.r.wIndex);
1910 if (!e)
1911 goto do_stall;
1912 if (e->wedged) {
1913 dev_vdbg(dev->dev, "%s wedged, halt not cleared\n",
1914 ep->ep.name);
1915 } else {
1916 dev_vdbg(dev->dev, "%s clear halt\n", ep->ep.name);
1917 clear_halt(e);
1918 }
1919 allow_status(ep);
1920 goto next_endpoints;
1921 }
1922 case USB_REQ_SET_FEATURE: {
1923 struct net2272_ep *e;
1924
1925 if (u.r.bRequestType == USB_RECIP_DEVICE) {
1926 if (u.r.wIndex != NORMAL_OPERATION)
1927 net2272_set_test_mode(dev, (u.r.wIndex >> 8));
1928 allow_status(ep);
1929 dev_vdbg(dev->dev, "test mode: %d\n", u.r.wIndex);
1930 goto next_endpoints;
1931 } else if (u.r.bRequestType != USB_RECIP_ENDPOINT)
1932 goto delegate;
1933 if (u.r.wValue != USB_ENDPOINT_HALT ||
1934 u.r.wLength != 0)
1935 goto do_stall;
1936 e = net2272_get_ep_by_addr(dev, u.r.wIndex);
1937 if (!e)
1938 goto do_stall;
1939 set_halt(e);
1940 allow_status(ep);
1941 dev_vdbg(dev->dev, "%s set halt\n", ep->ep.name);
1942 goto next_endpoints;
1943 }
1944 case USB_REQ_SET_ADDRESS: {
1945 net2272_write(dev, OURADDR, u.r.wValue & 0xff);
1946 allow_status(ep);
1947 break;
1948 }
1949 default:
1950 delegate:
1951 dev_vdbg(dev->dev, "setup %02x.%02x v%04x i%04x "
1952 "ep_cfg %08x\n",
1953 u.r.bRequestType, u.r.bRequest,
1954 u.r.wValue, u.r.wIndex,
1955 net2272_ep_read(ep, EP_CFG));
1956 spin_unlock(&dev->lock);
1957 tmp = dev->driver->setup(&dev->gadget, &u.r);
1958 spin_lock(&dev->lock);
1959 }
1960
1961 /* stall ep0 on error */
1962 if (tmp < 0) {
1963 do_stall:
1964 dev_vdbg(dev->dev, "req %02x.%02x protocol STALL; stat %d\n",
1965 u.r.bRequestType, u.r.bRequest, tmp);
1966 dev->protocol_stall = 1;
1967 }
1968 /* endpoint dma irq? */
1969 } else if (stat & (1 << DMA_DONE_INTERRUPT)) {
1970 net2272_cancel_dma(dev);
1971 net2272_write(dev, IRQSTAT0, 1 << DMA_DONE_INTERRUPT);
1972 stat &= ~(1 << DMA_DONE_INTERRUPT);
1973 num = (net2272_read(dev, DMAREQ) & (1 << DMA_ENDPOINT_SELECT))
1974 ? 2 : 1;
1975
1976 ep = &dev->ep[num];
1977 net2272_handle_dma(ep);
1978 }
1979
1980 next_endpoints:
1981 /* endpoint data irq? */
1982 scratch = stat & 0x0f;
1983 stat &= ~0x0f;
1984 for (num = 0; scratch; num++) {
1985 u8 t;
1986
1987 /* does this endpoint's FIFO and queue need tending? */
1988 t = 1 << num;
1989 if ((scratch & t) == 0)
1990 continue;
1991 scratch ^= t;
1992
1993 ep = &dev->ep[num];
1994 net2272_handle_ep(ep);
1995 }
1996
1997 /* some interrupts we can just ignore */
1998 stat &= ~(1 << SOF_INTERRUPT);
1999
2000 if (stat)
2001 dev_dbg(dev->dev, "unhandled irqstat0 %02x\n", stat);
2002}
2003
2004static void
2005net2272_handle_stat1_irqs(struct net2272 *dev, u8 stat)
2006{
2007 u8 tmp, mask;
2008
2009 /* after disconnect there's nothing else to do! */
2010 tmp = (1 << VBUS_INTERRUPT) | (1 << ROOT_PORT_RESET_INTERRUPT);
2011 mask = (1 << USB_HIGH_SPEED) | (1 << USB_FULL_SPEED);
2012
2013 if (stat & tmp) {
2014 net2272_write(dev, IRQSTAT1, tmp);
2015 if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT)) &&
2016 ((net2272_read(dev, USBCTL1) & mask) == 0))
2017 || ((net2272_read(dev, USBCTL1) & (1 << VBUS_PIN))
2018 == 0))
2019 && (dev->gadget.speed != USB_SPEED_UNKNOWN)) {
2020 dev_dbg(dev->dev, "disconnect %s\n",
2021 dev->driver->driver.name);
2022 stop_activity(dev, dev->driver);
2023 net2272_ep0_start(dev);
2024 return;
2025 }
2026 stat &= ~tmp;
2027
2028 if (!stat)
2029 return;
2030 }
2031
2032 tmp = (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT);
2033 if (stat & tmp) {
2034 net2272_write(dev, IRQSTAT1, tmp);
2035 if (stat & (1 << SUSPEND_REQUEST_INTERRUPT)) {
2036 if (dev->driver->suspend)
2037 dev->driver->suspend(&dev->gadget);
2038 if (!enable_suspend) {
2039 stat &= ~(1 << SUSPEND_REQUEST_INTERRUPT);
2040 dev_dbg(dev->dev, "Suspend disabled, ignoring\n");
2041 }
2042 } else {
2043 if (dev->driver->resume)
2044 dev->driver->resume(&dev->gadget);
2045 }
2046 stat &= ~tmp;
2047 }
2048
2049 /* clear any other status/irqs */
2050 if (stat)
2051 net2272_write(dev, IRQSTAT1, stat);
2052
2053 /* some status we can just ignore */
2054 stat &= ~((1 << CONTROL_STATUS_INTERRUPT)
2055 | (1 << SUSPEND_REQUEST_INTERRUPT)
2056 | (1 << RESUME_INTERRUPT));
2057 if (!stat)
2058 return;
2059 else
2060 dev_dbg(dev->dev, "unhandled irqstat1 %02x\n", stat);
2061}
2062
2063static irqreturn_t net2272_irq(int irq, void *_dev)
2064{
2065 struct net2272 *dev = _dev;
2066#if defined(PLX_PCI_RDK) || defined(PLX_PCI_RDK2)
2067 u32 intcsr;
2068#endif
2069#if defined(PLX_PCI_RDK)
2070 u8 dmareq;
2071#endif
2072 spin_lock(&dev->lock);
2073#if defined(PLX_PCI_RDK)
2074 intcsr = readl(dev->rdk1.plx9054_base_addr + INTCSR);
2075
2076 if ((intcsr & LOCAL_INTERRUPT_TEST) == LOCAL_INTERRUPT_TEST) {
2077 writel(intcsr & ~(1 << PCI_INTERRUPT_ENABLE),
2078 dev->rdk1.plx9054_base_addr + INTCSR);
2079 net2272_handle_stat1_irqs(dev, net2272_read(dev, IRQSTAT1));
2080 net2272_handle_stat0_irqs(dev, net2272_read(dev, IRQSTAT0));
2081 intcsr = readl(dev->rdk1.plx9054_base_addr + INTCSR);
2082 writel(intcsr | (1 << PCI_INTERRUPT_ENABLE),
2083 dev->rdk1.plx9054_base_addr + INTCSR);
2084 }
2085 if ((intcsr & DMA_CHANNEL_0_TEST) == DMA_CHANNEL_0_TEST) {
2086 writeb((1 << CHANNEL_CLEAR_INTERRUPT | (0 << CHANNEL_ENABLE)),
2087 dev->rdk1.plx9054_base_addr + DMACSR0);
2088
2089 dmareq = net2272_read(dev, DMAREQ);
2090 if (dmareq & 0x01)
2091 net2272_handle_dma(&dev->ep[2]);
2092 else
2093 net2272_handle_dma(&dev->ep[1]);
2094 }
2095#endif
2096#if defined(PLX_PCI_RDK2)
2097 /* see if PCI int for us by checking irqstat */
2098 intcsr = readl(dev->rdk2.fpga_base_addr + RDK2_IRQSTAT);
2099 if (!intcsr & (1 << NET2272_PCI_IRQ))
2100 return IRQ_NONE;
2101 /* check dma interrupts */
2102#endif
2103 /* Platform/devcice interrupt handler */
2104#if !defined(PLX_PCI_RDK)
2105 net2272_handle_stat1_irqs(dev, net2272_read(dev, IRQSTAT1));
2106 net2272_handle_stat0_irqs(dev, net2272_read(dev, IRQSTAT0));
2107#endif
2108 spin_unlock(&dev->lock);
2109
2110 return IRQ_HANDLED;
2111}
2112
2113static int net2272_present(struct net2272 *dev)
2114{
2115 /*
2116 * Quick test to see if CPU can communicate properly with the NET2272.
2117 * Verifies connection using writes and reads to write/read and
2118 * read-only registers.
2119 *
2120 * This routine is strongly recommended especially during early bring-up
2121 * of new hardware, however for designs that do not apply Power On System
2122 * Tests (POST) it may discarded (or perhaps minimized).
2123 */
2124 unsigned int ii;
2125 u8 val, refval;
2126
2127 /* Verify NET2272 write/read SCRATCH register can write and read */
2128 refval = net2272_read(dev, SCRATCH);
2129 for (ii = 0; ii < 0x100; ii += 7) {
2130 net2272_write(dev, SCRATCH, ii);
2131 val = net2272_read(dev, SCRATCH);
2132 if (val != ii) {
2133 dev_dbg(dev->dev,
2134 "%s: write/read SCRATCH register test failed: "
2135 "wrote:0x%2.2x, read:0x%2.2x\n",
2136 __func__, ii, val);
2137 return -EINVAL;
2138 }
2139 }
2140 /* To be nice, we write the original SCRATCH value back: */
2141 net2272_write(dev, SCRATCH, refval);
2142
2143 /* Verify NET2272 CHIPREV register is read-only: */
2144 refval = net2272_read(dev, CHIPREV_2272);
2145 for (ii = 0; ii < 0x100; ii += 7) {
2146 net2272_write(dev, CHIPREV_2272, ii);
2147 val = net2272_read(dev, CHIPREV_2272);
2148 if (val != refval) {
2149 dev_dbg(dev->dev,
2150 "%s: write/read CHIPREV register test failed: "
2151 "wrote 0x%2.2x, read:0x%2.2x expected:0x%2.2x\n",
2152 __func__, ii, val, refval);
2153 return -EINVAL;
2154 }
2155 }
2156
2157 /*
2158 * Verify NET2272's "NET2270 legacy revision" register
2159 * - NET2272 has two revision registers. The NET2270 legacy revision
2160 * register should read the same value, regardless of the NET2272
2161 * silicon revision. The legacy register applies to NET2270
2162 * firmware being applied to the NET2272.
2163 */
2164 val = net2272_read(dev, CHIPREV_LEGACY);
2165 if (val != NET2270_LEGACY_REV) {
2166 /*
2167 * Unexpected legacy revision value
2168 * - Perhaps the chip is a NET2270?
2169 */
2170 dev_dbg(dev->dev,
2171 "%s: WARNING: UNEXPECTED NET2272 LEGACY REGISTER VALUE:\n"
2172 " - CHIPREV_LEGACY: expected 0x%2.2x, got:0x%2.2x. (Not NET2272?)\n",
2173 __func__, NET2270_LEGACY_REV, val);
2174 return -EINVAL;
2175 }
2176
2177 /*
2178 * Verify NET2272 silicon revision
2179 * - This revision register is appropriate for the silicon version
2180 * of the NET2272
2181 */
2182 val = net2272_read(dev, CHIPREV_2272);
2183 switch (val) {
2184 case CHIPREV_NET2272_R1:
2185 /*
2186 * NET2272 Rev 1 has DMA related errata:
2187 * - Newer silicon (Rev 1A or better) required
2188 */
2189 dev_dbg(dev->dev,
2190 "%s: Rev 1 detected: newer silicon recommended for DMA support\n",
2191 __func__);
2192 break;
2193 case CHIPREV_NET2272_R1A:
2194 break;
2195 default:
2196 /* NET2272 silicon version *may* not work with this firmware */
2197 dev_dbg(dev->dev,
2198 "%s: unexpected silicon revision register value: "
2199 " CHIPREV_2272: 0x%2.2x\n",
2200 __func__, val);
2201 /*
2202 * Return Success, even though the chip rev is not an expected value
2203 * - Older, pre-built firmware can attempt to operate on newer silicon
2204 * - Often, new silicon is perfectly compatible
2205 */
2206 }
2207
2208 /* Success: NET2272 checks out OK */
2209 return 0;
2210}
2211
2212static void
2213net2272_gadget_release(struct device *_dev)
2214{
2215 struct net2272 *dev = dev_get_drvdata(_dev);
2216 kfree(dev);
2217}
2218
2219/*---------------------------------------------------------------------------*/
2220
2221static void __devexit
2222net2272_remove(struct net2272 *dev)
2223{
2224 usb_del_gadget_udc(&dev->gadget);
2225
2226 /* start with the driver above us */
2227 if (dev->driver) {
2228 /* should have been done already by driver model core */
2229 dev_warn(dev->dev, "pci remove, driver '%s' is still registered\n",
2230 dev->driver->driver.name);
2231 usb_gadget_unregister_driver(dev->driver);
2232 }
2233
2234 free_irq(dev->irq, dev);
2235 iounmap(dev->base_addr);
2236
2237 device_unregister(&dev->gadget.dev);
2238 device_remove_file(dev->dev, &dev_attr_registers);
2239
2240 dev_info(dev->dev, "unbind\n");
2241 the_controller = NULL;
2242}
2243
2244static struct net2272 * __devinit
2245net2272_probe_init(struct device *dev, unsigned int irq)
2246{
2247 struct net2272 *ret;
2248
2249 if (the_controller) {
2250 dev_warn(dev, "ignoring\n");
2251 return ERR_PTR(-EBUSY);
2252 }
2253
2254 if (!irq) {
2255 dev_dbg(dev, "No IRQ!\n");
2256 return ERR_PTR(-ENODEV);
2257 }
2258
2259 /* alloc, and start init */
2260 ret = kzalloc(sizeof(*ret), GFP_KERNEL);
2261 if (!ret)
2262 return ERR_PTR(-ENOMEM);
2263
2264 spin_lock_init(&ret->lock);
2265 ret->irq = irq;
2266 ret->dev = dev;
2267 ret->gadget.ops = &net2272_ops;
2268 ret->gadget.is_dualspeed = 1;
2269
2270 /* the "gadget" abstracts/virtualizes the controller */
2271 dev_set_name(&ret->gadget.dev, "gadget");
2272 ret->gadget.dev.parent = dev;
2273 ret->gadget.dev.dma_mask = dev->dma_mask;
2274 ret->gadget.dev.release = net2272_gadget_release;
2275 ret->gadget.name = driver_name;
2276
2277 return ret;
2278}
2279
2280static int __devinit
2281net2272_probe_fin(struct net2272 *dev, unsigned int irqflags)
2282{
2283 int ret;
2284
2285 /* See if there... */
2286 if (net2272_present(dev)) {
2287 dev_warn(dev->dev, "2272 not found!\n");
2288 ret = -ENODEV;
2289 goto err;
2290 }
2291
2292 net2272_usb_reset(dev);
2293 net2272_usb_reinit(dev);
2294
2295 ret = request_irq(dev->irq, net2272_irq, irqflags, driver_name, dev);
2296 if (ret) {
2297 dev_err(dev->dev, "request interrupt %i failed\n", dev->irq);
2298 goto err;
2299 }
2300
2301 dev->chiprev = net2272_read(dev, CHIPREV_2272);
2302
2303 /* done */
2304 dev_info(dev->dev, "%s\n", driver_desc);
2305 dev_info(dev->dev, "irq %i, mem %p, chip rev %04x, dma %s\n",
2306 dev->irq, dev->base_addr, dev->chiprev,
2307 dma_mode_string());
2308 dev_info(dev->dev, "version: %s\n", driver_vers);
2309
2310 the_controller = dev;
2311
2312 ret = device_register(&dev->gadget.dev);
2313 if (ret)
2314 goto err_irq;
2315 ret = device_create_file(dev->dev, &dev_attr_registers);
2316 if (ret)
2317 goto err_dev_reg;
2318
2319 ret = usb_add_gadget_udc(dev->dev, &dev->gadget);
2320 if (ret)
2321 goto err_add_udc;
2322
2323 return 0;
2324
2325err_add_udc:
2326 device_remove_file(dev->dev, &dev_attr_registers);
2327 err_dev_reg:
2328 device_unregister(&dev->gadget.dev);
2329 err_irq:
2330 free_irq(dev->irq, dev);
2331 err:
2332 return ret;
2333}
2334
2335#ifdef CONFIG_PCI
2336
2337/*
2338 * wrap this driver around the specified device, but
2339 * don't respond over USB until a gadget driver binds to us
2340 */
2341
2342static int __devinit
2343net2272_rdk1_probe(struct pci_dev *pdev, struct net2272 *dev)
2344{
2345 unsigned long resource, len, tmp;
2346 void __iomem *mem_mapped_addr[4];
2347 int ret, i;
2348
2349 /*
2350 * BAR 0 holds PLX 9054 config registers
2351 * BAR 1 is i/o memory; unused here
2352 * BAR 2 holds EPLD config registers
2353 * BAR 3 holds NET2272 registers
2354 */
2355
2356 /* Find and map all address spaces */
2357 for (i = 0; i < 4; ++i) {
2358 if (i == 1)
2359 continue; /* BAR1 unused */
2360
2361 resource = pci_resource_start(pdev, i);
2362 len = pci_resource_len(pdev, i);
2363
2364 if (!request_mem_region(resource, len, driver_name)) {
2365 dev_dbg(dev->dev, "controller already in use\n");
2366 ret = -EBUSY;
2367 goto err;
2368 }
2369
2370 mem_mapped_addr[i] = ioremap_nocache(resource, len);
2371 if (mem_mapped_addr[i] == NULL) {
2372 release_mem_region(resource, len);
2373 dev_dbg(dev->dev, "can't map memory\n");
2374 ret = -EFAULT;
2375 goto err;
2376 }
2377 }
2378
2379 dev->rdk1.plx9054_base_addr = mem_mapped_addr[0];
2380 dev->rdk1.epld_base_addr = mem_mapped_addr[2];
2381 dev->base_addr = mem_mapped_addr[3];
2382
2383 /* Set PLX 9054 bus width (16 bits) */
2384 tmp = readl(dev->rdk1.plx9054_base_addr + LBRD1);
2385 writel((tmp & ~(3 << MEMORY_SPACE_LOCAL_BUS_WIDTH)) | W16_BIT,
2386 dev->rdk1.plx9054_base_addr + LBRD1);
2387
2388 /* Enable PLX 9054 Interrupts */
2389 writel(readl(dev->rdk1.plx9054_base_addr + INTCSR) |
2390 (1 << PCI_INTERRUPT_ENABLE) |
2391 (1 << LOCAL_INTERRUPT_INPUT_ENABLE),
2392 dev->rdk1.plx9054_base_addr + INTCSR);
2393
2394 writeb((1 << CHANNEL_CLEAR_INTERRUPT | (0 << CHANNEL_ENABLE)),
2395 dev->rdk1.plx9054_base_addr + DMACSR0);
2396
2397 /* reset */
2398 writeb((1 << EPLD_DMA_ENABLE) |
2399 (1 << DMA_CTL_DACK) |
2400 (1 << DMA_TIMEOUT_ENABLE) |
2401 (1 << USER) |
2402 (0 << MPX_MODE) |
2403 (1 << BUSWIDTH) |
2404 (1 << NET2272_RESET),
2405 dev->base_addr + EPLD_IO_CONTROL_REGISTER);
2406
2407 mb();
2408 writeb(readb(dev->base_addr + EPLD_IO_CONTROL_REGISTER) &
2409 ~(1 << NET2272_RESET),
2410 dev->base_addr + EPLD_IO_CONTROL_REGISTER);
2411 udelay(200);
2412
2413 return 0;
2414
2415 err:
2416 while (--i >= 0) {
2417 iounmap(mem_mapped_addr[i]);
2418 release_mem_region(pci_resource_start(pdev, i),
2419 pci_resource_len(pdev, i));
2420 }
2421
2422 return ret;
2423}
2424
2425static int __devinit
2426net2272_rdk2_probe(struct pci_dev *pdev, struct net2272 *dev)
2427{
2428 unsigned long resource, len;
2429 void __iomem *mem_mapped_addr[2];
2430 int ret, i;
2431
2432 /*
2433 * BAR 0 holds FGPA config registers
2434 * BAR 1 holds NET2272 registers
2435 */
2436
2437 /* Find and map all address spaces, bar2-3 unused in rdk 2 */
2438 for (i = 0; i < 2; ++i) {
2439 resource = pci_resource_start(pdev, i);
2440 len = pci_resource_len(pdev, i);
2441
2442 if (!request_mem_region(resource, len, driver_name)) {
2443 dev_dbg(dev->dev, "controller already in use\n");
2444 ret = -EBUSY;
2445 goto err;
2446 }
2447
2448 mem_mapped_addr[i] = ioremap_nocache(resource, len);
2449 if (mem_mapped_addr[i] == NULL) {
2450 release_mem_region(resource, len);
2451 dev_dbg(dev->dev, "can't map memory\n");
2452 ret = -EFAULT;
2453 goto err;
2454 }
2455 }
2456
2457 dev->rdk2.fpga_base_addr = mem_mapped_addr[0];
2458 dev->base_addr = mem_mapped_addr[1];
2459
2460 mb();
2461 /* Set 2272 bus width (16 bits) and reset */
2462 writel((1 << CHIP_RESET), dev->rdk2.fpga_base_addr + RDK2_LOCCTLRDK);
2463 udelay(200);
2464 writel((1 << BUS_WIDTH), dev->rdk2.fpga_base_addr + RDK2_LOCCTLRDK);
2465 /* Print fpga version number */
2466 dev_info(dev->dev, "RDK2 FPGA version %08x\n",
2467 readl(dev->rdk2.fpga_base_addr + RDK2_FPGAREV));
2468 /* Enable FPGA Interrupts */
2469 writel((1 << NET2272_PCI_IRQ), dev->rdk2.fpga_base_addr + RDK2_IRQENB);
2470
2471 return 0;
2472
2473 err:
2474 while (--i >= 0) {
2475 iounmap(mem_mapped_addr[i]);
2476 release_mem_region(pci_resource_start(pdev, i),
2477 pci_resource_len(pdev, i));
2478 }
2479
2480 return ret;
2481}
2482
2483static int __devinit
2484net2272_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2485{
2486 struct net2272 *dev;
2487 int ret;
2488
2489 dev = net2272_probe_init(&pdev->dev, pdev->irq);
2490 if (IS_ERR(dev))
2491 return PTR_ERR(dev);
2492 dev->dev_id = pdev->device;
2493
2494 if (pci_enable_device(pdev) < 0) {
2495 ret = -ENODEV;
2496 goto err_free;
2497 }
2498
2499 pci_set_master(pdev);
2500
2501 switch (pdev->device) {
2502 case PCI_DEVICE_ID_RDK1: ret = net2272_rdk1_probe(pdev, dev); break;
2503 case PCI_DEVICE_ID_RDK2: ret = net2272_rdk2_probe(pdev, dev); break;
2504 default: BUG();
2505 }
2506 if (ret)
2507 goto err_pci;
2508
2509 ret = net2272_probe_fin(dev, 0);
2510 if (ret)
2511 goto err_pci;
2512
2513 pci_set_drvdata(pdev, dev);
2514
2515 return 0;
2516
2517 err_pci:
2518 pci_disable_device(pdev);
2519 err_free:
2520 kfree(dev);
2521
2522 return ret;
2523}
2524
2525static void __devexit
2526net2272_rdk1_remove(struct pci_dev *pdev, struct net2272 *dev)
2527{
2528 int i;
2529
2530 /* disable PLX 9054 interrupts */
2531 writel(readl(dev->rdk1.plx9054_base_addr + INTCSR) &
2532 ~(1 << PCI_INTERRUPT_ENABLE),
2533 dev->rdk1.plx9054_base_addr + INTCSR);
2534
2535 /* clean up resources allocated during probe() */
2536 iounmap(dev->rdk1.plx9054_base_addr);
2537 iounmap(dev->rdk1.epld_base_addr);
2538
2539 for (i = 0; i < 4; ++i) {
2540 if (i == 1)
2541 continue; /* BAR1 unused */
2542 release_mem_region(pci_resource_start(pdev, i),
2543 pci_resource_len(pdev, i));
2544 }
2545}
2546
2547static void __devexit
2548net2272_rdk2_remove(struct pci_dev *pdev, struct net2272 *dev)
2549{
2550 int i;
2551
2552 /* disable fpga interrupts
2553 writel(readl(dev->rdk1.plx9054_base_addr + INTCSR) &
2554 ~(1 << PCI_INTERRUPT_ENABLE),
2555 dev->rdk1.plx9054_base_addr + INTCSR);
2556 */
2557
2558 /* clean up resources allocated during probe() */
2559 iounmap(dev->rdk2.fpga_base_addr);
2560
2561 for (i = 0; i < 2; ++i)
2562 release_mem_region(pci_resource_start(pdev, i),
2563 pci_resource_len(pdev, i));
2564}
2565
2566static void __devexit
2567net2272_pci_remove(struct pci_dev *pdev)
2568{
2569 struct net2272 *dev = pci_get_drvdata(pdev);
2570
2571 net2272_remove(dev);
2572
2573 switch (pdev->device) {
2574 case PCI_DEVICE_ID_RDK1: net2272_rdk1_remove(pdev, dev); break;
2575 case PCI_DEVICE_ID_RDK2: net2272_rdk2_remove(pdev, dev); break;
2576 default: BUG();
2577 }
2578
2579 pci_disable_device(pdev);
2580
2581 kfree(dev);
2582}
2583
2584/* Table of matching PCI IDs */
2585static struct pci_device_id __devinitdata pci_ids[] = {
2586 { /* RDK 1 card */
2587 .class = ((PCI_CLASS_BRIDGE_OTHER << 8) | 0xfe),
2588 .class_mask = 0,
2589 .vendor = PCI_VENDOR_ID_PLX,
2590 .device = PCI_DEVICE_ID_RDK1,
2591 .subvendor = PCI_ANY_ID,
2592 .subdevice = PCI_ANY_ID,
2593 },
2594 { /* RDK 2 card */
2595 .class = ((PCI_CLASS_BRIDGE_OTHER << 8) | 0xfe),
2596 .class_mask = 0,
2597 .vendor = PCI_VENDOR_ID_PLX,
2598 .device = PCI_DEVICE_ID_RDK2,
2599 .subvendor = PCI_ANY_ID,
2600 .subdevice = PCI_ANY_ID,
2601 },
2602 { }
2603};
2604MODULE_DEVICE_TABLE(pci, pci_ids);
2605
2606static struct pci_driver net2272_pci_driver = {
2607 .name = driver_name,
2608 .id_table = pci_ids,
2609
2610 .probe = net2272_pci_probe,
2611 .remove = __devexit_p(net2272_pci_remove),
2612};
2613
2614static int net2272_pci_register(void)
2615{
2616 return pci_register_driver(&net2272_pci_driver);
2617}
2618
2619static void net2272_pci_unregister(void)
2620{
2621 pci_unregister_driver(&net2272_pci_driver);
2622}
2623
2624#else
2625static inline int net2272_pci_register(void) { return 0; }
2626static inline void net2272_pci_unregister(void) { }
2627#endif
2628
2629/*---------------------------------------------------------------------------*/
2630
2631static int __devinit
2632net2272_plat_probe(struct platform_device *pdev)
2633{
2634 struct net2272 *dev;
2635 int ret;
2636 unsigned int irqflags;
2637 resource_size_t base, len;
2638 struct resource *iomem, *iomem_bus, *irq_res;
2639
2640 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
2641 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2642 iomem_bus = platform_get_resource(pdev, IORESOURCE_BUS, 0);
2643 if (!irq_res || !iomem) {
2644 dev_err(&pdev->dev, "must provide irq/base addr");
2645 return -EINVAL;
2646 }
2647
2648 dev = net2272_probe_init(&pdev->dev, irq_res->start);
2649 if (IS_ERR(dev))
2650 return PTR_ERR(dev);
2651
2652 irqflags = 0;
2653 if (irq_res->flags & IORESOURCE_IRQ_HIGHEDGE)
2654 irqflags |= IRQF_TRIGGER_RISING;
2655 if (irq_res->flags & IORESOURCE_IRQ_LOWEDGE)
2656 irqflags |= IRQF_TRIGGER_FALLING;
2657 if (irq_res->flags & IORESOURCE_IRQ_HIGHLEVEL)
2658 irqflags |= IRQF_TRIGGER_HIGH;
2659 if (irq_res->flags & IORESOURCE_IRQ_LOWLEVEL)
2660 irqflags |= IRQF_TRIGGER_LOW;
2661
2662 base = iomem->start;
2663 len = resource_size(iomem);
2664 if (iomem_bus)
2665 dev->base_shift = iomem_bus->start;
2666
2667 if (!request_mem_region(base, len, driver_name)) {
2668 dev_dbg(dev->dev, "get request memory region!\n");
2669 ret = -EBUSY;
2670 goto err;
2671 }
2672 dev->base_addr = ioremap_nocache(base, len);
2673 if (!dev->base_addr) {
2674 dev_dbg(dev->dev, "can't map memory\n");
2675 ret = -EFAULT;
2676 goto err_req;
2677 }
2678
2679 ret = net2272_probe_fin(dev, IRQF_TRIGGER_LOW);
2680 if (ret)
2681 goto err_io;
2682
2683 platform_set_drvdata(pdev, dev);
2684 dev_info(&pdev->dev, "running in 16-bit, %sbyte swap local bus mode\n",
2685 (net2272_read(dev, LOCCTL) & (1 << BYTE_SWAP)) ? "" : "no ");
2686
2687 the_controller = dev;
2688
2689 return 0;
2690
2691 err_io:
2692 iounmap(dev->base_addr);
2693 err_req:
2694 release_mem_region(base, len);
2695 err:
2696 return ret;
2697}
2698
2699static int __devexit
2700net2272_plat_remove(struct platform_device *pdev)
2701{
2702 struct net2272 *dev = platform_get_drvdata(pdev);
2703
2704 net2272_remove(dev);
2705
2706 release_mem_region(pdev->resource[0].start,
2707 resource_size(&pdev->resource[0]));
2708
2709 kfree(dev);
2710
2711 return 0;
2712}
2713
2714static struct platform_driver net2272_plat_driver = {
2715 .probe = net2272_plat_probe,
2716 .remove = __devexit_p(net2272_plat_remove),
2717 .driver = {
2718 .name = driver_name,
2719 .owner = THIS_MODULE,
2720 },
2721 /* FIXME .suspend, .resume */
2722};
2723MODULE_ALIAS("platform:net2272");
2724
2725static int __init net2272_init(void)
2726{
2727 int ret;
2728
2729 ret = net2272_pci_register();
2730 if (ret)
2731 return ret;
2732 ret = platform_driver_register(&net2272_plat_driver);
2733 if (ret)
2734 goto err_pci;
2735 return ret;
2736
2737err_pci:
2738 net2272_pci_unregister();
2739 return ret;
2740}
2741module_init(net2272_init);
2742
2743static void __exit net2272_cleanup(void)
2744{
2745 net2272_pci_unregister();
2746 platform_driver_unregister(&net2272_plat_driver);
2747}
2748module_exit(net2272_cleanup);
2749
2750MODULE_DESCRIPTION(DRIVER_DESC);
2751MODULE_AUTHOR("PLX Technology, Inc.");
2752MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/net2272.h b/drivers/usb/gadget/net2272.h
new file mode 100644
index 000000000000..e59505789359
--- /dev/null
+++ b/drivers/usb/gadget/net2272.h
@@ -0,0 +1,601 @@
1/*
2 * PLX NET2272 high/full speed USB device controller
3 *
4 * Copyright (C) 2005-2006 PLX Technology, Inc.
5 * Copyright (C) 2006-2011 Analog Devices, Inc.
6 *
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
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef __NET2272_H__
23#define __NET2272_H__
24
25/* Main Registers */
26#define REGADDRPTR 0x00
27#define REGDATA 0x01
28#define IRQSTAT0 0x02
29#define ENDPOINT_0_INTERRUPT 0
30#define ENDPOINT_A_INTERRUPT 1
31#define ENDPOINT_B_INTERRUPT 2
32#define ENDPOINT_C_INTERRUPT 3
33#define VIRTUALIZED_ENDPOINT_INTERRUPT 4
34#define SETUP_PACKET_INTERRUPT 5
35#define DMA_DONE_INTERRUPT 6
36#define SOF_INTERRUPT 7
37#define IRQSTAT1 0x03
38#define CONTROL_STATUS_INTERRUPT 1
39#define VBUS_INTERRUPT 2
40#define SUSPEND_REQUEST_INTERRUPT 3
41#define SUSPEND_REQUEST_CHANGE_INTERRUPT 4
42#define RESUME_INTERRUPT 5
43#define ROOT_PORT_RESET_INTERRUPT 6
44#define RESET_STATUS 7
45#define PAGESEL 0x04
46#define DMAREQ 0x1c
47#define DMA_ENDPOINT_SELECT 0
48#define DREQ_POLARITY 1
49#define DACK_POLARITY 2
50#define EOT_POLARITY 3
51#define DMA_CONTROL_DACK 4
52#define DMA_REQUEST_ENABLE 5
53#define DMA_REQUEST 6
54#define DMA_BUFFER_VALID 7
55#define SCRATCH 0x1d
56#define IRQENB0 0x20
57#define ENDPOINT_0_INTERRUPT_ENABLE 0
58#define ENDPOINT_A_INTERRUPT_ENABLE 1
59#define ENDPOINT_B_INTERRUPT_ENABLE 2
60#define ENDPOINT_C_INTERRUPT_ENABLE 3
61#define VIRTUALIZED_ENDPOINT_INTERRUPT_ENABLE 4
62#define SETUP_PACKET_INTERRUPT_ENABLE 5
63#define DMA_DONE_INTERRUPT_ENABLE 6
64#define SOF_INTERRUPT_ENABLE 7
65#define IRQENB1 0x21
66#define VBUS_INTERRUPT_ENABLE 2
67#define SUSPEND_REQUEST_INTERRUPT_ENABLE 3
68#define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 4
69#define RESUME_INTERRUPT_ENABLE 5
70#define ROOT_PORT_RESET_INTERRUPT_ENABLE 6
71#define LOCCTL 0x22
72#define DATA_WIDTH 0
73#define LOCAL_CLOCK_OUTPUT 1
74#define LOCAL_CLOCK_OUTPUT_OFF 0
75#define LOCAL_CLOCK_OUTPUT_3_75MHZ 1
76#define LOCAL_CLOCK_OUTPUT_7_5MHZ 2
77#define LOCAL_CLOCK_OUTPUT_15MHZ 3
78#define LOCAL_CLOCK_OUTPUT_30MHZ 4
79#define LOCAL_CLOCK_OUTPUT_60MHZ 5
80#define DMA_SPLIT_BUS_MODE 4
81#define BYTE_SWAP 5
82#define BUFFER_CONFIGURATION 6
83#define BUFFER_CONFIGURATION_EPA512_EPB512 0
84#define BUFFER_CONFIGURATION_EPA1024_EPB512 1
85#define BUFFER_CONFIGURATION_EPA1024_EPB1024 2
86#define BUFFER_CONFIGURATION_EPA1024DB 3
87#define CHIPREV_LEGACY 0x23
88#define NET2270_LEGACY_REV 0x40
89#define LOCCTL1 0x24
90#define DMA_MODE 0
91#define SLOW_DREQ 0
92#define FAST_DREQ 1
93#define BURST_MODE 2
94#define DMA_DACK_ENABLE 2
95#define CHIPREV_2272 0x25
96#define CHIPREV_NET2272_R1 0x10
97#define CHIPREV_NET2272_R1A 0x11
98/* USB Registers */
99#define USBCTL0 0x18
100#define IO_WAKEUP_ENABLE 1
101#define USB_DETECT_ENABLE 3
102#define USB_ROOT_PORT_WAKEUP_ENABLE 5
103#define USBCTL1 0x19
104#define VBUS_PIN 0
105#define USB_FULL_SPEED 1
106#define USB_HIGH_SPEED 2
107#define GENERATE_RESUME 3
108#define VIRTUAL_ENDPOINT_ENABLE 4
109#define FRAME0 0x1a
110#define FRAME1 0x1b
111#define OURADDR 0x30
112#define FORCE_IMMEDIATE 7
113#define USBDIAG 0x31
114#define FORCE_TRANSMIT_CRC_ERROR 0
115#define PREVENT_TRANSMIT_BIT_STUFF 1
116#define FORCE_RECEIVE_ERROR 2
117#define FAST_TIMES 4
118#define USBTEST 0x32
119#define TEST_MODE_SELECT 0
120#define NORMAL_OPERATION 0
121#define TEST_J 1
122#define TEST_K 2
123#define TEST_SE0_NAK 3
124#define TEST_PACKET 4
125#define TEST_FORCE_ENABLE 5
126#define XCVRDIAG 0x33
127#define FORCE_FULL_SPEED 2
128#define FORCE_HIGH_SPEED 3
129#define OPMODE 4
130#define NORMAL_OPERATION 0
131#define NON_DRIVING 1
132#define DISABLE_BITSTUFF_AND_NRZI_ENCODE 2
133#define LINESTATE 6
134#define SE0_STATE 0
135#define J_STATE 1
136#define K_STATE 2
137#define SE1_STATE 3
138#define VIRTOUT0 0x34
139#define VIRTOUT1 0x35
140#define VIRTIN0 0x36
141#define VIRTIN1 0x37
142#define SETUP0 0x40
143#define SETUP1 0x41
144#define SETUP2 0x42
145#define SETUP3 0x43
146#define SETUP4 0x44
147#define SETUP5 0x45
148#define SETUP6 0x46
149#define SETUP7 0x47
150/* Endpoint Registers (Paged via PAGESEL) */
151#define EP_DATA 0x05
152#define EP_STAT0 0x06
153#define DATA_IN_TOKEN_INTERRUPT 0
154#define DATA_OUT_TOKEN_INTERRUPT 1
155#define DATA_PACKET_TRANSMITTED_INTERRUPT 2
156#define DATA_PACKET_RECEIVED_INTERRUPT 3
157#define SHORT_PACKET_TRANSFERRED_INTERRUPT 4
158#define NAK_OUT_PACKETS 5
159#define BUFFER_EMPTY 6
160#define BUFFER_FULL 7
161#define EP_STAT1 0x07
162#define TIMEOUT 0
163#define USB_OUT_ACK_SENT 1
164#define USB_OUT_NAK_SENT 2
165#define USB_IN_ACK_RCVD 3
166#define USB_IN_NAK_SENT 4
167#define USB_STALL_SENT 5
168#define LOCAL_OUT_ZLP 6
169#define BUFFER_FLUSH 7
170#define EP_TRANSFER0 0x08
171#define EP_TRANSFER1 0x09
172#define EP_TRANSFER2 0x0a
173#define EP_IRQENB 0x0b
174#define DATA_IN_TOKEN_INTERRUPT_ENABLE 0
175#define DATA_OUT_TOKEN_INTERRUPT_ENABLE 1
176#define DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE 2
177#define DATA_PACKET_RECEIVED_INTERRUPT_ENABLE 3
178#define SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE 4
179#define EP_AVAIL0 0x0c
180#define EP_AVAIL1 0x0d
181#define EP_RSPCLR 0x0e
182#define EP_RSPSET 0x0f
183#define ENDPOINT_HALT 0
184#define ENDPOINT_TOGGLE 1
185#define NAK_OUT_PACKETS_MODE 2
186#define CONTROL_STATUS_PHASE_HANDSHAKE 3
187#define INTERRUPT_MODE 4
188#define AUTOVALIDATE 5
189#define HIDE_STATUS_PHASE 6
190#define ALT_NAK_OUT_PACKETS 7
191#define EP_MAXPKT0 0x28
192#define EP_MAXPKT1 0x29
193#define ADDITIONAL_TRANSACTION_OPPORTUNITIES 3
194#define NONE_ADDITIONAL_TRANSACTION 0
195#define ONE_ADDITIONAL_TRANSACTION 1
196#define TWO_ADDITIONAL_TRANSACTION 2
197#define EP_CFG 0x2a
198#define ENDPOINT_NUMBER 0
199#define ENDPOINT_DIRECTION 4
200#define ENDPOINT_TYPE 5
201#define ENDPOINT_ENABLE 7
202#define EP_HBW 0x2b
203#define HIGH_BANDWIDTH_OUT_TRANSACTION_PID 0
204#define DATA0_PID 0
205#define DATA1_PID 1
206#define DATA2_PID 2
207#define MDATA_PID 3
208#define EP_BUFF_STATES 0x2c
209#define BUFFER_A_STATE 0
210#define BUFFER_B_STATE 2
211#define BUFF_FREE 0
212#define BUFF_VALID 1
213#define BUFF_LCL 2
214#define BUFF_USB 3
215
216/*---------------------------------------------------------------------------*/
217
218#define PCI_DEVICE_ID_RDK1 0x9054
219
220/* PCI-RDK EPLD Registers */
221#define RDK_EPLD_IO_REGISTER1 0x00000000
222#define RDK_EPLD_USB_RESET 0
223#define RDK_EPLD_USB_POWERDOWN 1
224#define RDK_EPLD_USB_WAKEUP 2
225#define RDK_EPLD_USB_EOT 3
226#define RDK_EPLD_DPPULL 4
227#define RDK_EPLD_IO_REGISTER2 0x00000004
228#define RDK_EPLD_BUSWIDTH 0
229#define RDK_EPLD_USER 2
230#define RDK_EPLD_RESET_INTERRUPT_ENABLE 3
231#define RDK_EPLD_DMA_TIMEOUT_ENABLE 4
232#define RDK_EPLD_STATUS_REGISTER 0x00000008
233#define RDK_EPLD_USB_LRESET 0
234#define RDK_EPLD_REVISION_REGISTER 0x0000000c
235
236/* PCI-RDK PLX 9054 Registers */
237#define INTCSR 0x68
238#define PCI_INTERRUPT_ENABLE 8
239#define LOCAL_INTERRUPT_INPUT_ENABLE 11
240#define LOCAL_INPUT_INTERRUPT_ACTIVE 15
241#define LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE 18
242#define LOCAL_DMA_CHANNEL_1_INTERRUPT_ENABLE 19
243#define DMA_CHANNEL_0_INTERRUPT_ACTIVE 21
244#define DMA_CHANNEL_1_INTERRUPT_ACTIVE 22
245#define CNTRL 0x6C
246#define RELOAD_CONFIGURATION_REGISTERS 29
247#define PCI_ADAPTER_SOFTWARE_RESET 30
248#define DMAMODE0 0x80
249#define LOCAL_BUS_WIDTH 0
250#define INTERNAL_WAIT_STATES 2
251#define TA_READY_INPUT_ENABLE 6
252#define LOCAL_BURST_ENABLE 8
253#define SCATTER_GATHER_MODE 9
254#define DONE_INTERRUPT_ENABLE 10
255#define LOCAL_ADDRESSING_MODE 11
256#define DEMAND_MODE 12
257#define DMA_EOT_ENABLE 14
258#define FAST_SLOW_TERMINATE_MODE_SELECT 15
259#define DMA_CHANNEL_INTERRUPT_SELECT 17
260#define DMAPADR0 0x84
261#define DMALADR0 0x88
262#define DMASIZ0 0x8c
263#define DMADPR0 0x90
264#define DESCRIPTOR_LOCATION 0
265#define END_OF_CHAIN 1
266#define INTERRUPT_AFTER_TERMINAL_COUNT 2
267#define DIRECTION_OF_TRANSFER 3
268#define DMACSR0 0xa8
269#define CHANNEL_ENABLE 0
270#define CHANNEL_START 1
271#define CHANNEL_ABORT 2
272#define CHANNEL_CLEAR_INTERRUPT 3
273#define CHANNEL_DONE 4
274#define DMATHR 0xb0
275#define LBRD1 0xf8
276#define MEMORY_SPACE_LOCAL_BUS_WIDTH 0
277#define W8_BIT 0
278#define W16_BIT 1
279
280/* Special OR'ing of INTCSR bits */
281#define LOCAL_INTERRUPT_TEST \
282 ((1 << LOCAL_INPUT_INTERRUPT_ACTIVE) | \
283 (1 << LOCAL_INTERRUPT_INPUT_ENABLE))
284
285#define DMA_CHANNEL_0_TEST \
286 ((1 << DMA_CHANNEL_0_INTERRUPT_ACTIVE) | \
287 (1 << LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE))
288
289#define DMA_CHANNEL_1_TEST \
290 ((1 << DMA_CHANNEL_1_INTERRUPT_ACTIVE) | \
291 (1 << LOCAL_DMA_CHANNEL_1_INTERRUPT_ENABLE))
292
293/* EPLD Registers */
294#define RDK_EPLD_IO_REGISTER1 0x00000000
295#define RDK_EPLD_USB_RESET 0
296#define RDK_EPLD_USB_POWERDOWN 1
297#define RDK_EPLD_USB_WAKEUP 2
298#define RDK_EPLD_USB_EOT 3
299#define RDK_EPLD_DPPULL 4
300#define RDK_EPLD_IO_REGISTER2 0x00000004
301#define RDK_EPLD_BUSWIDTH 0
302#define RDK_EPLD_USER 2
303#define RDK_EPLD_RESET_INTERRUPT_ENABLE 3
304#define RDK_EPLD_DMA_TIMEOUT_ENABLE 4
305#define RDK_EPLD_STATUS_REGISTER 0x00000008
306#define RDK_EPLD_USB_LRESET 0
307#define RDK_EPLD_REVISION_REGISTER 0x0000000c
308
309#define EPLD_IO_CONTROL_REGISTER 0x400
310#define NET2272_RESET 0
311#define BUSWIDTH 1
312#define MPX_MODE 3
313#define USER 4
314#define DMA_TIMEOUT_ENABLE 5
315#define DMA_CTL_DACK 6
316#define EPLD_DMA_ENABLE 7
317#define EPLD_DMA_CONTROL_REGISTER 0x800
318#define SPLIT_DMA_MODE 0
319#define SPLIT_DMA_DIRECTION 1
320#define SPLIT_DMA_ENABLE 2
321#define SPLIT_DMA_INTERRUPT_ENABLE 3
322#define SPLIT_DMA_INTERRUPT 4
323#define EPLD_DMA_MODE 5
324#define EPLD_DMA_CONTROLLER_ENABLE 7
325#define SPLIT_DMA_ADDRESS_LOW 0xc00
326#define SPLIT_DMA_ADDRESS_HIGH 0x1000
327#define SPLIT_DMA_BYTE_COUNT_LOW 0x1400
328#define SPLIT_DMA_BYTE_COUNT_HIGH 0x1800
329#define EPLD_REVISION_REGISTER 0x1c00
330#define SPLIT_DMA_RAM 0x4000
331#define DMA_RAM_SIZE 0x1000
332
333/*---------------------------------------------------------------------------*/
334
335#define PCI_DEVICE_ID_RDK2 0x3272
336
337/* PCI-RDK version 2 registers */
338
339/* Main Control Registers */
340
341#define RDK2_IRQENB 0x00
342#define RDK2_IRQSTAT 0x04
343#define PB7 23
344#define PB6 22
345#define PB5 21
346#define PB4 20
347#define PB3 19
348#define PB2 18
349#define PB1 17
350#define PB0 16
351#define GP3 23
352#define GP2 23
353#define GP1 23
354#define GP0 23
355#define DMA_RETRY_ABORT 6
356#define DMA_PAUSE_DONE 5
357#define DMA_ABORT_DONE 4
358#define DMA_OUT_FIFO_TRANSFER_DONE 3
359#define DMA_LOCAL_DONE 2
360#define DMA_PCI_DONE 1
361#define NET2272_PCI_IRQ 0
362
363#define RDK2_LOCCTLRDK 0x08
364#define CHIP_RESET 3
365#define SPLIT_DMA 2
366#define MULTIPLEX_MODE 1
367#define BUS_WIDTH 0
368
369#define RDK2_GPIOCTL 0x10
370#define GP3_OUT_ENABLE 7
371#define GP2_OUT_ENABLE 6
372#define GP1_OUT_ENABLE 5
373#define GP0_OUT_ENABLE 4
374#define GP3_DATA 3
375#define GP2_DATA 2
376#define GP1_DATA 1
377#define GP0_DATA 0
378
379#define RDK2_LEDSW 0x14
380#define LED3 27
381#define LED2 26
382#define LED1 25
383#define LED0 24
384#define PBUTTON 16
385#define DIPSW 0
386
387#define RDK2_DIAG 0x18
388#define RDK2_FAST_TIMES 2
389#define FORCE_PCI_SERR 1
390#define FORCE_PCI_INT 0
391#define RDK2_FPGAREV 0x1C
392
393/* Dma Control registers */
394#define RDK2_DMACTL 0x80
395#define ADDR_HOLD 24
396#define RETRY_COUNT 16 /* 23:16 */
397#define FIFO_THRESHOLD 11 /* 15:11 */
398#define MEM_WRITE_INVALIDATE 10
399#define READ_MULTIPLE 9
400#define READ_LINE 8
401#define RDK2_DMA_MODE 6 /* 7:6 */
402#define CONTROL_DACK 5
403#define EOT_ENABLE 4
404#define EOT_POLARITY 3
405#define DACK_POLARITY 2
406#define DREQ_POLARITY 1
407#define DMA_ENABLE 0
408
409#define RDK2_DMASTAT 0x84
410#define GATHER_COUNT 12 /* 14:12 */
411#define FIFO_COUNT 6 /* 11:6 */
412#define FIFO_FLUSH 5
413#define FIFO_TRANSFER 4
414#define PAUSE_DONE 3
415#define ABORT_DONE 2
416#define DMA_ABORT 1
417#define DMA_START 0
418
419#define RDK2_DMAPCICOUNT 0x88
420#define DMA_DIRECTION 31
421#define DMA_PCI_BYTE_COUNT 0 /* 0:23 */
422
423#define RDK2_DMALOCCOUNT 0x8C /* 0:23 dma local byte count */
424
425#define RDK2_DMAADDR 0x90 /* 2:31 PCI bus starting address */
426
427/*---------------------------------------------------------------------------*/
428
429#define REG_INDEXED_THRESHOLD (1 << 5)
430
431/* DRIVER DATA STRUCTURES and UTILITIES */
432struct net2272_ep {
433 struct usb_ep ep;
434 struct net2272 *dev;
435 unsigned long irqs;
436
437 /* analogous to a host-side qh */
438 struct list_head queue;
439 const struct usb_endpoint_descriptor *desc;
440 unsigned num:8,
441 fifo_size:12,
442 stopped:1,
443 wedged:1,
444 is_in:1,
445 is_iso:1,
446 dma:1,
447 not_empty:1;
448};
449
450struct net2272 {
451 /* each device provides one gadget, several endpoints */
452 struct usb_gadget gadget;
453 struct device *dev;
454 unsigned short dev_id;
455
456 spinlock_t lock;
457 struct net2272_ep ep[4];
458 struct usb_gadget_driver *driver;
459 unsigned protocol_stall:1,
460 softconnect:1,
461 is_selfpowered:1,
462 wakeup:1,
463 dma_eot_polarity:1,
464 dma_dack_polarity:1,
465 dma_dreq_polarity:1,
466 dma_busy:1;
467 u16 chiprev;
468 u8 pagesel;
469
470 unsigned int irq;
471 unsigned short fifo_mode;
472
473 unsigned int base_shift;
474 u16 __iomem *base_addr;
475 union {
476#ifdef CONFIG_PCI
477 struct {
478 void __iomem *plx9054_base_addr;
479 void __iomem *epld_base_addr;
480 } rdk1;
481 struct {
482 /* Bar0, Bar1 is base_addr both mem-mapped */
483 void __iomem *fpga_base_addr;
484 } rdk2;
485#endif
486 };
487};
488
489static void __iomem *
490net2272_reg_addr(struct net2272 *dev, unsigned int reg)
491{
492 return dev->base_addr + (reg << dev->base_shift);
493}
494
495static void
496net2272_write(struct net2272 *dev, unsigned int reg, u8 value)
497{
498 if (reg >= REG_INDEXED_THRESHOLD) {
499 /*
500 * Indexed register; use REGADDRPTR/REGDATA
501 * - Save and restore REGADDRPTR. This prevents REGADDRPTR from
502 * changes between other code sections, but it is time consuming.
503 * - Performance tips: either do not save and restore REGADDRPTR (if it
504 * is safe) or do save/restore operations only in critical sections.
505 u8 tmp = readb(dev->base_addr + REGADDRPTR);
506 */
507 writeb((u8)reg, net2272_reg_addr(dev, REGADDRPTR));
508 writeb(value, net2272_reg_addr(dev, REGDATA));
509 /* writeb(tmp, net2272_reg_addr(dev, REGADDRPTR)); */
510 } else
511 writeb(value, net2272_reg_addr(dev, reg));
512}
513
514static u8
515net2272_read(struct net2272 *dev, unsigned int reg)
516{
517 u8 ret;
518
519 if (reg >= REG_INDEXED_THRESHOLD) {
520 /*
521 * Indexed register; use REGADDRPTR/REGDATA
522 * - Save and restore REGADDRPTR. This prevents REGADDRPTR from
523 * changes between other code sections, but it is time consuming.
524 * - Performance tips: either do not save and restore REGADDRPTR (if it
525 * is safe) or do save/restore operations only in critical sections.
526 u8 tmp = readb(dev->base_addr + REGADDRPTR);
527 */
528 writeb((u8)reg, net2272_reg_addr(dev, REGADDRPTR));
529 ret = readb(net2272_reg_addr(dev, REGDATA));
530 /* writeb(tmp, net2272_reg_addr(dev, REGADDRPTR)); */
531 } else
532 ret = readb(net2272_reg_addr(dev, reg));
533
534 return ret;
535}
536
537static void
538net2272_ep_write(struct net2272_ep *ep, unsigned int reg, u8 value)
539{
540 struct net2272 *dev = ep->dev;
541
542 if (dev->pagesel != ep->num) {
543 net2272_write(dev, PAGESEL, ep->num);
544 dev->pagesel = ep->num;
545 }
546 net2272_write(dev, reg, value);
547}
548
549static u8
550net2272_ep_read(struct net2272_ep *ep, unsigned int reg)
551{
552 struct net2272 *dev = ep->dev;
553
554 if (dev->pagesel != ep->num) {
555 net2272_write(dev, PAGESEL, ep->num);
556 dev->pagesel = ep->num;
557 }
558 return net2272_read(dev, reg);
559}
560
561static void allow_status(struct net2272_ep *ep)
562{
563 /* ep0 only */
564 net2272_ep_write(ep, EP_RSPCLR,
565 (1 << CONTROL_STATUS_PHASE_HANDSHAKE) |
566 (1 << ALT_NAK_OUT_PACKETS) |
567 (1 << NAK_OUT_PACKETS_MODE));
568 ep->stopped = 1;
569}
570
571static void set_halt(struct net2272_ep *ep)
572{
573 /* ep0 and bulk/intr endpoints */
574 net2272_ep_write(ep, EP_RSPCLR, 1 << CONTROL_STATUS_PHASE_HANDSHAKE);
575 net2272_ep_write(ep, EP_RSPSET, 1 << ENDPOINT_HALT);
576}
577
578static void clear_halt(struct net2272_ep *ep)
579{
580 /* ep0 and bulk/intr endpoints */
581 net2272_ep_write(ep, EP_RSPCLR,
582 (1 << ENDPOINT_HALT) | (1 << ENDPOINT_TOGGLE));
583}
584
585/* count (<= 4) bytes in the next fifo write will be valid */
586static void set_fifo_bytecount(struct net2272_ep *ep, unsigned count)
587{
588 /* net2272_ep_write will truncate to u8 for us */
589 net2272_ep_write(ep, EP_TRANSFER2, count >> 16);
590 net2272_ep_write(ep, EP_TRANSFER1, count >> 8);
591 net2272_ep_write(ep, EP_TRANSFER0, count);
592}
593
594struct net2272_request {
595 struct usb_request req;
596 struct list_head queue;
597 unsigned mapped:1,
598 valid:1;
599};
600
601#endif
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 476d88e1ae97..3dd40b4e675c 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -1410,11 +1410,17 @@ static int net2280_pullup(struct usb_gadget *_gadget, int is_on)
1410 return 0; 1410 return 0;
1411} 1411}
1412 1412
1413static int net2280_start(struct usb_gadget_driver *driver,
1414 int (*bind)(struct usb_gadget *));
1415static int net2280_stop(struct usb_gadget_driver *driver);
1416
1413static const struct usb_gadget_ops net2280_ops = { 1417static const struct usb_gadget_ops net2280_ops = {
1414 .get_frame = net2280_get_frame, 1418 .get_frame = net2280_get_frame,
1415 .wakeup = net2280_wakeup, 1419 .wakeup = net2280_wakeup,
1416 .set_selfpowered = net2280_set_selfpowered, 1420 .set_selfpowered = net2280_set_selfpowered,
1417 .pullup = net2280_pullup, 1421 .pullup = net2280_pullup,
1422 .start = net2280_start,
1423 .stop = net2280_stop,
1418}; 1424};
1419 1425
1420/*-------------------------------------------------------------------------*/ 1426/*-------------------------------------------------------------------------*/
@@ -1738,62 +1744,6 @@ static void set_fifo_mode (struct net2280 *dev, int mode)
1738 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); 1744 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list);
1739} 1745}
1740 1746
1741/* just declare this in any driver that really need it */
1742extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
1743
1744/**
1745 * net2280_set_fifo_mode - change allocation of fifo buffers
1746 * @gadget: access to the net2280 device that will be updated
1747 * @mode: 0 for default, four 1kB buffers (ep-a through ep-d);
1748 * 1 for two 2kB buffers (ep-a and ep-b only);
1749 * 2 for one 2kB buffer (ep-a) and two 1kB ones (ep-b, ep-c).
1750 *
1751 * returns zero on success, else negative errno. when this succeeds,
1752 * the contents of gadget->ep_list may have changed.
1753 *
1754 * you may only call this function when endpoints a-d are all disabled.
1755 * use it whenever extra hardware buffering can help performance, such
1756 * as before enabling "high bandwidth" interrupt endpoints that use
1757 * maxpacket bigger than 512 (when double buffering would otherwise
1758 * be unavailable).
1759 */
1760int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode)
1761{
1762 int i;
1763 struct net2280 *dev;
1764 int status = 0;
1765 unsigned long flags;
1766
1767 if (!gadget)
1768 return -ENODEV;
1769 dev = container_of (gadget, struct net2280, gadget);
1770
1771 spin_lock_irqsave (&dev->lock, flags);
1772
1773 for (i = 1; i <= 4; i++)
1774 if (dev->ep [i].desc) {
1775 status = -EINVAL;
1776 break;
1777 }
1778 if (mode < 0 || mode > 2)
1779 status = -EINVAL;
1780 if (status == 0)
1781 set_fifo_mode (dev, mode);
1782 spin_unlock_irqrestore (&dev->lock, flags);
1783
1784 if (status == 0) {
1785 if (mode == 1)
1786 DEBUG (dev, "fifo: ep-a 2K, ep-b 2K\n");
1787 else if (mode == 2)
1788 DEBUG (dev, "fifo: ep-a 2K, ep-b 1K, ep-c 1K\n");
1789 /* else all are 1K */
1790 }
1791 return status;
1792}
1793EXPORT_SYMBOL (net2280_set_fifo_mode);
1794
1795/*-------------------------------------------------------------------------*/
1796
1797/* keeping it simple: 1747/* keeping it simple:
1798 * - one bus driver, initted first; 1748 * - one bus driver, initted first;
1799 * - one function driver, initted second 1749 * - one function driver, initted second
@@ -1930,7 +1880,7 @@ static void ep0_start (struct net2280 *dev)
1930 * disconnect is reported. then a host may connect again, or 1880 * disconnect is reported. then a host may connect again, or
1931 * the driver might get unbound. 1881 * the driver might get unbound.
1932 */ 1882 */
1933int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1883static int net2280_start(struct usb_gadget_driver *driver,
1934 int (*bind)(struct usb_gadget *)) 1884 int (*bind)(struct usb_gadget *))
1935{ 1885{
1936 struct net2280 *dev = the_controller; 1886 struct net2280 *dev = the_controller;
@@ -1994,7 +1944,6 @@ err_unbind:
1994 dev->driver = NULL; 1944 dev->driver = NULL;
1995 return retval; 1945 return retval;
1996} 1946}
1997EXPORT_SYMBOL(usb_gadget_probe_driver);
1998 1947
1999static void 1948static void
2000stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) 1949stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
@@ -2022,7 +1971,7 @@ stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
2022 usb_reinit (dev); 1971 usb_reinit (dev);
2023} 1972}
2024 1973
2025int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 1974static int net2280_stop(struct usb_gadget_driver *driver)
2026{ 1975{
2027 struct net2280 *dev = the_controller; 1976 struct net2280 *dev = the_controller;
2028 unsigned long flags; 1977 unsigned long flags;
@@ -2049,8 +1998,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2049 DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name); 1998 DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name);
2050 return 0; 1999 return 0;
2051} 2000}
2052EXPORT_SYMBOL (usb_gadget_unregister_driver);
2053
2054 2001
2055/*-------------------------------------------------------------------------*/ 2002/*-------------------------------------------------------------------------*/
2056 2003
@@ -2732,6 +2679,8 @@ static void net2280_remove (struct pci_dev *pdev)
2732{ 2679{
2733 struct net2280 *dev = pci_get_drvdata (pdev); 2680 struct net2280 *dev = pci_get_drvdata (pdev);
2734 2681
2682 usb_del_gadget_udc(&dev->gadget);
2683
2735 BUG_ON(dev->driver); 2684 BUG_ON(dev->driver);
2736 2685
2737 /* then clean up the resources we allocated during probe() */ 2686 /* then clean up the resources we allocated during probe() */
@@ -2916,6 +2865,9 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2916 retval = device_create_file (&pdev->dev, &dev_attr_registers); 2865 retval = device_create_file (&pdev->dev, &dev_attr_registers);
2917 if (retval) goto done; 2866 if (retval) goto done;
2918 2867
2868 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
2869 if (retval)
2870 goto done;
2919 return 0; 2871 return 0;
2920 2872
2921done: 2873done:
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 55ca63ad3506..c7fb7723c014 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -241,6 +241,7 @@ static struct usb_composite_driver nokia_driver = {
241 .name = "g_nokia", 241 .name = "g_nokia",
242 .dev = &device_desc, 242 .dev = &device_desc,
243 .strings = dev_strings, 243 .strings = dev_strings,
244 .max_speed = USB_SPEED_HIGH,
244 .unbind = __exit_p(nokia_unbind), 245 .unbind = __exit_p(nokia_unbind),
245}; 246};
246 247
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 82fd24935332..740c7daed279 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -1375,6 +1375,10 @@ static int omap_pullup(struct usb_gadget *gadget, int is_on)
1375 return 0; 1375 return 0;
1376} 1376}
1377 1377
1378static int omap_udc_start(struct usb_gadget_driver *driver,
1379 int (*bind)(struct usb_gadget *));
1380static int omap_udc_stop(struct usb_gadget_driver *driver);
1381
1378static struct usb_gadget_ops omap_gadget_ops = { 1382static struct usb_gadget_ops omap_gadget_ops = {
1379 .get_frame = omap_get_frame, 1383 .get_frame = omap_get_frame,
1380 .wakeup = omap_wakeup, 1384 .wakeup = omap_wakeup,
@@ -1382,6 +1386,8 @@ static struct usb_gadget_ops omap_gadget_ops = {
1382 .vbus_session = omap_vbus_session, 1386 .vbus_session = omap_vbus_session,
1383 .vbus_draw = omap_vbus_draw, 1387 .vbus_draw = omap_vbus_draw,
1384 .pullup = omap_pullup, 1388 .pullup = omap_pullup,
1389 .start = omap_udc_start,
1390 .stop = omap_udc_stop,
1385}; 1391};
1386 1392
1387/*-------------------------------------------------------------------------*/ 1393/*-------------------------------------------------------------------------*/
@@ -2102,7 +2108,7 @@ static inline int machine_without_vbus_sense(void)
2102 ); 2108 );
2103} 2109}
2104 2110
2105int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2111static int omap_udc_start(struct usb_gadget_driver *driver,
2106 int (*bind)(struct usb_gadget *)) 2112 int (*bind)(struct usb_gadget *))
2107{ 2113{
2108 int status = -ENODEV; 2114 int status = -ENODEV;
@@ -2186,9 +2192,8 @@ done:
2186 omap_udc_enable_clock(0); 2192 omap_udc_enable_clock(0);
2187 return status; 2193 return status;
2188} 2194}
2189EXPORT_SYMBOL(usb_gadget_probe_driver);
2190 2195
2191int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 2196static int omap_udc_stop(struct usb_gadget_driver *driver)
2192{ 2197{
2193 unsigned long flags; 2198 unsigned long flags;
2194 int status = -ENODEV; 2199 int status = -ENODEV;
@@ -2222,8 +2227,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2222 DBG("unregistered driver '%s'\n", driver->driver.name); 2227 DBG("unregistered driver '%s'\n", driver->driver.name);
2223 return status; 2228 return status;
2224} 2229}
2225EXPORT_SYMBOL(usb_gadget_unregister_driver);
2226
2227 2230
2228/*-------------------------------------------------------------------------*/ 2231/*-------------------------------------------------------------------------*/
2229 2232
@@ -2991,9 +2994,16 @@ known:
2991 2994
2992 create_proc_file(); 2995 create_proc_file();
2993 status = device_add(&udc->gadget.dev); 2996 status = device_add(&udc->gadget.dev);
2997 if (status)
2998 goto cleanup4;
2999
3000 status = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2994 if (!status) 3001 if (!status)
2995 return status; 3002 return status;
2996 /* If fail, fall through */ 3003 /* If fail, fall through */
3004cleanup4:
3005 remove_proc_file();
3006
2997#ifdef USE_ISO 3007#ifdef USE_ISO
2998cleanup3: 3008cleanup3:
2999 free_irq(pdev->resource[2].start, udc); 3009 free_irq(pdev->resource[2].start, udc);
@@ -3029,6 +3039,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
3029 3039
3030 if (!udc) 3040 if (!udc)
3031 return -ENODEV; 3041 return -ENODEV;
3042
3043 usb_del_gadget_udc(&udc->gadget);
3032 if (udc->driver) 3044 if (udc->driver)
3033 return -EBUSY; 3045 return -EBUSY;
3034 3046
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index 68dbcc3e4cc2..f96615ab6b77 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -1176,6 +1176,9 @@ static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
1176 return -EOPNOTSUPP; 1176 return -EOPNOTSUPP;
1177} 1177}
1178 1178
1179static int pch_udc_start(struct usb_gadget_driver *driver,
1180 int (*bind)(struct usb_gadget *));
1181static int pch_udc_stop(struct usb_gadget_driver *driver);
1179static const struct usb_gadget_ops pch_udc_ops = { 1182static const struct usb_gadget_ops pch_udc_ops = {
1180 .get_frame = pch_udc_pcd_get_frame, 1183 .get_frame = pch_udc_pcd_get_frame,
1181 .wakeup = pch_udc_pcd_wakeup, 1184 .wakeup = pch_udc_pcd_wakeup,
@@ -1183,6 +1186,8 @@ static const struct usb_gadget_ops pch_udc_ops = {
1183 .pullup = pch_udc_pcd_pullup, 1186 .pullup = pch_udc_pcd_pullup,
1184 .vbus_session = pch_udc_pcd_vbus_session, 1187 .vbus_session = pch_udc_pcd_vbus_session,
1185 .vbus_draw = pch_udc_pcd_vbus_draw, 1188 .vbus_draw = pch_udc_pcd_vbus_draw,
1189 .start = pch_udc_start,
1190 .stop = pch_udc_stop,
1186}; 1191};
1187 1192
1188/** 1193/**
@@ -2690,7 +2695,7 @@ static int init_dma_pools(struct pch_udc_dev *dev)
2690 return 0; 2695 return 0;
2691} 2696}
2692 2697
2693int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2698static int pch_udc_start(struct usb_gadget_driver *driver,
2694 int (*bind)(struct usb_gadget *)) 2699 int (*bind)(struct usb_gadget *))
2695{ 2700{
2696 struct pch_udc_dev *dev = pch_udc; 2701 struct pch_udc_dev *dev = pch_udc;
@@ -2733,9 +2738,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2733 dev->connected = 1; 2738 dev->connected = 1;
2734 return 0; 2739 return 0;
2735} 2740}
2736EXPORT_SYMBOL(usb_gadget_probe_driver);
2737 2741
2738int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2742static int pch_udc_stop(struct usb_gadget_driver *driver)
2739{ 2743{
2740 struct pch_udc_dev *dev = pch_udc; 2744 struct pch_udc_dev *dev = pch_udc;
2741 2745
@@ -2761,7 +2765,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2761 pch_udc_set_disconnect(dev); 2765 pch_udc_set_disconnect(dev);
2762 return 0; 2766 return 0;
2763} 2767}
2764EXPORT_SYMBOL(usb_gadget_unregister_driver);
2765 2768
2766static void pch_udc_shutdown(struct pci_dev *pdev) 2769static void pch_udc_shutdown(struct pci_dev *pdev)
2767{ 2770{
@@ -2778,6 +2781,8 @@ static void pch_udc_remove(struct pci_dev *pdev)
2778{ 2781{
2779 struct pch_udc_dev *dev = pci_get_drvdata(pdev); 2782 struct pch_udc_dev *dev = pci_get_drvdata(pdev);
2780 2783
2784 usb_del_gadget_udc(&dev->gadget);
2785
2781 /* gadget driver must not be registered */ 2786 /* gadget driver must not be registered */
2782 if (dev->driver) 2787 if (dev->driver)
2783 dev_err(&pdev->dev, 2788 dev_err(&pdev->dev,
@@ -2953,6 +2958,9 @@ static int pch_udc_probe(struct pci_dev *pdev,
2953 2958
2954 /* Put the device in disconnected state till a driver is bound */ 2959 /* Put the device in disconnected state till a driver is bound */
2955 pch_udc_set_disconnect(dev); 2960 pch_udc_set_disconnect(dev);
2961 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
2962 if (retval)
2963 goto finished;
2956 return 0; 2964 return 0;
2957 2965
2958finished: 2966finished:
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 978e6a101bf2..a341dde6f9c3 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -89,8 +89,7 @@ struct printer_dev {
89 u8 config; 89 u8 config;
90 s8 interface; 90 s8 interface;
91 struct usb_ep *in_ep, *out_ep; 91 struct usb_ep *in_ep, *out_ep;
92 const struct usb_endpoint_descriptor 92
93 *in, *out;
94 struct list_head rx_reqs; /* List of free RX structs */ 93 struct list_head rx_reqs; /* List of free RX structs */
95 struct list_head rx_reqs_active; /* List of Active RX xfers */ 94 struct list_head rx_reqs_active; /* List of Active RX xfers */
96 struct list_head rx_buffers; /* List of completed xfers */ 95 struct list_head rx_buffers; /* List of completed xfers */
@@ -898,19 +897,20 @@ set_printer_interface(struct printer_dev *dev)
898{ 897{
899 int result = 0; 898 int result = 0;
900 899
901 dev->in = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc); 900 dev->in_ep->desc = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc);
902 dev->in_ep->driver_data = dev; 901 dev->in_ep->driver_data = dev;
903 902
904 dev->out = ep_desc(dev->gadget, &hs_ep_out_desc, &fs_ep_out_desc); 903 dev->out_ep->desc = ep_desc(dev->gadget, &hs_ep_out_desc,
904 &fs_ep_out_desc);
905 dev->out_ep->driver_data = dev; 905 dev->out_ep->driver_data = dev;
906 906
907 result = usb_ep_enable(dev->in_ep, dev->in); 907 result = usb_ep_enable(dev->in_ep);
908 if (result != 0) { 908 if (result != 0) {
909 DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); 909 DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result);
910 goto done; 910 goto done;
911 } 911 }
912 912
913 result = usb_ep_enable(dev->out_ep, dev->out); 913 result = usb_ep_enable(dev->out_ep);
914 if (result != 0) { 914 if (result != 0) {
915 DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); 915 DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result);
916 goto done; 916 goto done;
@@ -921,8 +921,8 @@ done:
921 if (result != 0) { 921 if (result != 0) {
922 (void) usb_ep_disable(dev->in_ep); 922 (void) usb_ep_disable(dev->in_ep);
923 (void) usb_ep_disable(dev->out_ep); 923 (void) usb_ep_disable(dev->out_ep);
924 dev->in = NULL; 924 dev->in_ep->desc = NULL;
925 dev->out = NULL; 925 dev->out_ep->desc = NULL;
926 } 926 }
927 927
928 /* caller is responsible for cleanup on error */ 928 /* caller is responsible for cleanup on error */
@@ -936,12 +936,14 @@ static void printer_reset_interface(struct printer_dev *dev)
936 936
937 DBG(dev, "%s\n", __func__); 937 DBG(dev, "%s\n", __func__);
938 938
939 if (dev->in) 939 if (dev->in_ep->desc)
940 usb_ep_disable(dev->in_ep); 940 usb_ep_disable(dev->in_ep);
941 941
942 if (dev->out) 942 if (dev->out_ep->desc)
943 usb_ep_disable(dev->out_ep); 943 usb_ep_disable(dev->out_ep);
944 944
945 dev->in_ep->desc = NULL;
946 dev->out_ep->desc = NULL;
945 dev->interface = -1; 947 dev->interface = -1;
946} 948}
947 949
@@ -1107,9 +1109,9 @@ static void printer_soft_reset(struct printer_dev *dev)
1107 list_add(&req->list, &dev->tx_reqs); 1109 list_add(&req->list, &dev->tx_reqs);
1108 } 1110 }
1109 1111
1110 if (usb_ep_enable(dev->in_ep, dev->in)) 1112 if (usb_ep_enable(dev->in_ep))
1111 DBG(dev, "Failed to enable USB in_ep\n"); 1113 DBG(dev, "Failed to enable USB in_ep\n");
1112 if (usb_ep_enable(dev->out_ep, dev->out)) 1114 if (usb_ep_enable(dev->out_ep))
1113 DBG(dev, "Failed to enable USB out_ep\n"); 1115 DBG(dev, "Failed to enable USB out_ep\n");
1114 1116
1115 wake_up_interruptible(&dev->rx_wait); 1117 wake_up_interruptible(&dev->rx_wait);
@@ -1149,6 +1151,8 @@ printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1149 switch (wValue >> 8) { 1151 switch (wValue >> 8) {
1150 1152
1151 case USB_DT_DEVICE: 1153 case USB_DT_DEVICE:
1154 device_desc.bMaxPacketSize0 =
1155 gadget->ep0->maxpacket;
1152 value = min(wLength, (u16) sizeof device_desc); 1156 value = min(wLength, (u16) sizeof device_desc);
1153 memcpy(req->buf, &device_desc, value); 1157 memcpy(req->buf, &device_desc, value);
1154 break; 1158 break;
@@ -1156,6 +1160,12 @@ printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1156 case USB_DT_DEVICE_QUALIFIER: 1160 case USB_DT_DEVICE_QUALIFIER:
1157 if (!gadget->is_dualspeed) 1161 if (!gadget->is_dualspeed)
1158 break; 1162 break;
1163 /*
1164 * assumes ep0 uses the same value for both
1165 * speeds
1166 */
1167 dev_qualifier.bMaxPacketSize0 =
1168 gadget->ep0->maxpacket;
1159 value = min(wLength, 1169 value = min(wLength,
1160 (u16) sizeof dev_qualifier); 1170 (u16) sizeof dev_qualifier);
1161 memcpy(req->buf, &dev_qualifier, value); 1171 memcpy(req->buf, &dev_qualifier, value);
@@ -1451,15 +1461,11 @@ autoconf_fail:
1451 out_ep->driver_data = out_ep; /* claim */ 1461 out_ep->driver_data = out_ep; /* claim */
1452 1462
1453#ifdef CONFIG_USB_GADGET_DUALSPEED 1463#ifdef CONFIG_USB_GADGET_DUALSPEED
1454 /* assumes ep0 uses the same value for both speeds ... */ 1464 /* assumes that all endpoints are dual-speed */
1455 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
1456
1457 /* and that all endpoints are dual-speed */
1458 hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; 1465 hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
1459 hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; 1466 hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
1460#endif /* DUALSPEED */ 1467#endif /* DUALSPEED */
1461 1468
1462 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1463 usb_gadget_set_selfpowered(gadget); 1469 usb_gadget_set_selfpowered(gadget);
1464 1470
1465 if (gadget->is_otg) { 1471 if (gadget->is_otg) {
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index 774545494cf2..e4e59b4de25d 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -1011,12 +1011,18 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1011 return -EOPNOTSUPP; 1011 return -EOPNOTSUPP;
1012} 1012}
1013 1013
1014static int pxa25x_start(struct usb_gadget_driver *driver,
1015 int (*bind)(struct usb_gadget *));
1016static int pxa25x_stop(struct usb_gadget_driver *driver);
1017
1014static const struct usb_gadget_ops pxa25x_udc_ops = { 1018static const struct usb_gadget_ops pxa25x_udc_ops = {
1015 .get_frame = pxa25x_udc_get_frame, 1019 .get_frame = pxa25x_udc_get_frame,
1016 .wakeup = pxa25x_udc_wakeup, 1020 .wakeup = pxa25x_udc_wakeup,
1017 .vbus_session = pxa25x_udc_vbus_session, 1021 .vbus_session = pxa25x_udc_vbus_session,
1018 .pullup = pxa25x_udc_pullup, 1022 .pullup = pxa25x_udc_pullup,
1019 .vbus_draw = pxa25x_udc_vbus_draw, 1023 .vbus_draw = pxa25x_udc_vbus_draw,
1024 .start = pxa25x_start,
1025 .stop = pxa25x_stop,
1020}; 1026};
1021 1027
1022/*-------------------------------------------------------------------------*/ 1028/*-------------------------------------------------------------------------*/
@@ -1263,7 +1269,7 @@ static void udc_enable (struct pxa25x_udc *dev)
1263 * disconnect is reported. then a host may connect again, or 1269 * disconnect is reported. then a host may connect again, or
1264 * the driver might get unbound. 1270 * the driver might get unbound.
1265 */ 1271 */
1266int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1272static int pxa25x_start(struct usb_gadget_driver *driver,
1267 int (*bind)(struct usb_gadget *)) 1273 int (*bind)(struct usb_gadget *))
1268{ 1274{
1269 struct pxa25x_udc *dev = the_controller; 1275 struct pxa25x_udc *dev = the_controller;
@@ -1322,7 +1328,6 @@ fail:
1322bind_fail: 1328bind_fail:
1323 return retval; 1329 return retval;
1324} 1330}
1325EXPORT_SYMBOL(usb_gadget_probe_driver);
1326 1331
1327static void 1332static void
1328stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) 1333stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
@@ -1351,7 +1356,7 @@ stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
1351 udc_reinit(dev); 1356 udc_reinit(dev);
1352} 1357}
1353 1358
1354int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1359static int pxa25x_stop(struct usb_gadget_driver *driver)
1355{ 1360{
1356 struct pxa25x_udc *dev = the_controller; 1361 struct pxa25x_udc *dev = the_controller;
1357 1362
@@ -1379,8 +1384,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1379 dump_state(dev); 1384 dump_state(dev);
1380 return 0; 1385 return 0;
1381} 1386}
1382EXPORT_SYMBOL(usb_gadget_unregister_driver);
1383
1384 1387
1385/*-------------------------------------------------------------------------*/ 1388/*-------------------------------------------------------------------------*/
1386 1389
@@ -2231,8 +2234,11 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2231#endif 2234#endif
2232 create_debug_files(dev); 2235 create_debug_files(dev);
2233 2236
2234 return 0; 2237 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
2238 if (!retval)
2239 return retval;
2235 2240
2241 remove_debug_files(dev);
2236#ifdef CONFIG_ARCH_LUBBOCK 2242#ifdef CONFIG_ARCH_LUBBOCK
2237lubbock_fail0: 2243lubbock_fail0:
2238 free_irq(LUBBOCK_USB_DISC_IRQ, dev); 2244 free_irq(LUBBOCK_USB_DISC_IRQ, dev);
@@ -2261,6 +2267,7 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2261{ 2267{
2262 struct pxa25x_udc *dev = platform_get_drvdata(pdev); 2268 struct pxa25x_udc *dev = platform_get_drvdata(pdev);
2263 2269
2270 usb_del_gadget_udc(&dev->gadget);
2264 if (dev->driver) 2271 if (dev->driver)
2265 return -EBUSY; 2272 return -EBUSY;
2266 2273
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 57607696735c..85b68c75dc9d 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -1680,12 +1680,18 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1680 return -EOPNOTSUPP; 1680 return -EOPNOTSUPP;
1681} 1681}
1682 1682
1683static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1684 int (*bind)(struct usb_gadget *));
1685static int pxa27x_udc_stop(struct usb_gadget_driver *driver);
1686
1683static const struct usb_gadget_ops pxa_udc_ops = { 1687static const struct usb_gadget_ops pxa_udc_ops = {
1684 .get_frame = pxa_udc_get_frame, 1688 .get_frame = pxa_udc_get_frame,
1685 .wakeup = pxa_udc_wakeup, 1689 .wakeup = pxa_udc_wakeup,
1686 .pullup = pxa_udc_pullup, 1690 .pullup = pxa_udc_pullup,
1687 .vbus_session = pxa_udc_vbus_session, 1691 .vbus_session = pxa_udc_vbus_session,
1688 .vbus_draw = pxa_udc_vbus_draw, 1692 .vbus_draw = pxa_udc_vbus_draw,
1693 .start = pxa27x_udc_start,
1694 .stop = pxa27x_udc_stop,
1689}; 1695};
1690 1696
1691/** 1697/**
@@ -1791,7 +1797,7 @@ static void udc_enable(struct pxa_udc *udc)
1791} 1797}
1792 1798
1793/** 1799/**
1794 * usb_gadget_probe_driver - Register gadget driver 1800 * pxa27x_start - Register gadget driver
1795 * @driver: gadget driver 1801 * @driver: gadget driver
1796 * @bind: bind function 1802 * @bind: bind function
1797 * 1803 *
@@ -1805,7 +1811,7 @@ static void udc_enable(struct pxa_udc *udc)
1805 * 1811 *
1806 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1812 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1807 */ 1813 */
1808int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1814static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1809 int (*bind)(struct usb_gadget *)) 1815 int (*bind)(struct usb_gadget *))
1810{ 1816{
1811 struct pxa_udc *udc = the_controller; 1817 struct pxa_udc *udc = the_controller;
@@ -1860,8 +1866,6 @@ add_fail:
1860 udc->gadget.dev.driver = NULL; 1866 udc->gadget.dev.driver = NULL;
1861 return retval; 1867 return retval;
1862} 1868}
1863EXPORT_SYMBOL(usb_gadget_probe_driver);
1864
1865 1869
1866/** 1870/**
1867 * stop_activity - Stops udc endpoints 1871 * stop_activity - Stops udc endpoints
@@ -1888,12 +1892,12 @@ static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver)
1888} 1892}
1889 1893
1890/** 1894/**
1891 * usb_gadget_unregister_driver - Unregister the gadget driver 1895 * pxa27x_udc_stop - Unregister the gadget driver
1892 * @driver: gadget driver 1896 * @driver: gadget driver
1893 * 1897 *
1894 * Returns 0 if no error, -ENODEV, -EINVAL otherwise 1898 * Returns 0 if no error, -ENODEV, -EINVAL otherwise
1895 */ 1899 */
1896int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1900static int pxa27x_udc_stop(struct usb_gadget_driver *driver)
1897{ 1901{
1898 struct pxa_udc *udc = the_controller; 1902 struct pxa_udc *udc = the_controller;
1899 1903
@@ -1917,7 +1921,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1917 return otg_set_peripheral(udc->transceiver, NULL); 1921 return otg_set_peripheral(udc->transceiver, NULL);
1918 return 0; 1922 return 0;
1919} 1923}
1920EXPORT_SYMBOL(usb_gadget_unregister_driver);
1921 1924
1922/** 1925/**
1923 * handle_ep0_ctrl_req - handle control endpoint control request 1926 * handle_ep0_ctrl_req - handle control endpoint control request
@@ -2516,9 +2519,14 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2516 driver_name, IRQ_USB, retval); 2519 driver_name, IRQ_USB, retval);
2517 goto err_irq; 2520 goto err_irq;
2518 } 2521 }
2522 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2523 if (retval)
2524 goto err_add_udc;
2519 2525
2520 pxa_init_debugfs(udc); 2526 pxa_init_debugfs(udc);
2521 return 0; 2527 return 0;
2528err_add_udc:
2529 free_irq(udc->irq, udc);
2522err_irq: 2530err_irq:
2523 iounmap(udc->regs); 2531 iounmap(udc->regs);
2524err_map: 2532err_map:
@@ -2537,6 +2545,7 @@ static int __exit pxa_udc_remove(struct platform_device *_dev)
2537 struct pxa_udc *udc = platform_get_drvdata(_dev); 2545 struct pxa_udc *udc = platform_get_drvdata(_dev);
2538 int gpio = udc->mach->gpio_pullup; 2546 int gpio = udc->mach->gpio_pullup;
2539 2547
2548 usb_del_gadget_udc(&udc->gadget);
2540 usb_gadget_unregister_driver(udc->driver); 2549 usb_gadget_unregister_driver(udc->driver);
2541 free_irq(udc->irq, udc); 2550 free_irq(udc->irq, udc);
2542 pxa_cleanup_debugfs(udc); 2551 pxa_cleanup_debugfs(udc);
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index 6dcc1f68fa60..50991e5bd5e8 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2006-2009 Renesas Solutions Corp. 4 * Copyright (C) 2006-2009 Renesas Solutions Corp.
5 * 5 *
6 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> 6 * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.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
@@ -576,7 +576,11 @@ static void init_controller(struct r8a66597 *r8a66597)
576 u16 endian = r8a66597->pdata->endian ? BIGEND : 0; 576 u16 endian = r8a66597->pdata->endian ? BIGEND : 0;
577 577
578 if (r8a66597->pdata->on_chip) { 578 if (r8a66597->pdata->on_chip) {
579 r8a66597_bset(r8a66597, 0x04, SYSCFG1); 579 if (r8a66597->pdata->buswait)
580 r8a66597_write(r8a66597, r8a66597->pdata->buswait,
581 SYSCFG1);
582 else
583 r8a66597_write(r8a66597, 0x0f, SYSCFG1);
580 r8a66597_bset(r8a66597, HSE, SYSCFG0); 584 r8a66597_bset(r8a66597, HSE, SYSCFG0);
581 585
582 r8a66597_bclr(r8a66597, USBE, SYSCFG0); 586 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
@@ -618,6 +622,7 @@ static void disable_controller(struct r8a66597 *r8a66597)
618{ 622{
619 if (r8a66597->pdata->on_chip) { 623 if (r8a66597->pdata->on_chip) {
620 r8a66597_bset(r8a66597, SCKE, SYSCFG0); 624 r8a66597_bset(r8a66597, SCKE, SYSCFG0);
625 r8a66597_bclr(r8a66597, UTST, TESTMODE);
621 626
622 /* disable interrupts */ 627 /* disable interrupts */
623 r8a66597_write(r8a66597, 0, INTENB0); 628 r8a66597_write(r8a66597, 0, INTENB0);
@@ -635,6 +640,7 @@ static void disable_controller(struct r8a66597 *r8a66597)
635 r8a66597_bclr(r8a66597, SCKE, SYSCFG0); 640 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
636 641
637 } else { 642 } else {
643 r8a66597_bclr(r8a66597, UTST, TESTMODE);
638 r8a66597_bclr(r8a66597, SCKE, SYSCFG0); 644 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
639 udelay(1); 645 udelay(1);
640 r8a66597_bclr(r8a66597, PLLC, SYSCFG0); 646 r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
@@ -999,10 +1005,29 @@ static void clear_feature(struct r8a66597 *r8a66597,
999 1005
1000static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) 1006static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
1001{ 1007{
1008 u16 tmp;
1009 int timeout = 3000;
1002 1010
1003 switch (ctrl->bRequestType & USB_RECIP_MASK) { 1011 switch (ctrl->bRequestType & USB_RECIP_MASK) {
1004 case USB_RECIP_DEVICE: 1012 case USB_RECIP_DEVICE:
1005 control_end(r8a66597, 1); 1013 switch (le16_to_cpu(ctrl->wValue)) {
1014 case USB_DEVICE_TEST_MODE:
1015 control_end(r8a66597, 1);
1016 /* Wait for the completion of status stage */
1017 do {
1018 tmp = r8a66597_read(r8a66597, INTSTS0) & CTSQ;
1019 udelay(1);
1020 } while (tmp != CS_IDST || timeout-- > 0);
1021
1022 if (tmp == CS_IDST)
1023 r8a66597_bset(r8a66597,
1024 le16_to_cpu(ctrl->wIndex >> 8),
1025 TESTMODE);
1026 break;
1027 default:
1028 pipe_stall(r8a66597, 0);
1029 break;
1030 }
1006 break; 1031 break;
1007 case USB_RECIP_INTERFACE: 1032 case USB_RECIP_INTERFACE:
1008 control_end(r8a66597, 1); 1033 control_end(r8a66597, 1);
@@ -1410,7 +1435,7 @@ static struct usb_ep_ops r8a66597_ep_ops = {
1410/*-------------------------------------------------------------------------*/ 1435/*-------------------------------------------------------------------------*/
1411static struct r8a66597 *the_controller; 1436static struct r8a66597 *the_controller;
1412 1437
1413int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1438static int r8a66597_start(struct usb_gadget_driver *driver,
1414 int (*bind)(struct usb_gadget *)) 1439 int (*bind)(struct usb_gadget *))
1415{ 1440{
1416 struct r8a66597 *r8a66597 = the_controller; 1441 struct r8a66597 *r8a66597 = the_controller;
@@ -1444,6 +1469,7 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1444 goto error; 1469 goto error;
1445 } 1470 }
1446 1471
1472 init_controller(r8a66597);
1447 r8a66597_bset(r8a66597, VBSE, INTENB0); 1473 r8a66597_bset(r8a66597, VBSE, INTENB0);
1448 if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) { 1474 if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) {
1449 r8a66597_start_xclock(r8a66597); 1475 r8a66597_start_xclock(r8a66597);
@@ -1462,9 +1488,8 @@ error:
1462 1488
1463 return retval; 1489 return retval;
1464} 1490}
1465EXPORT_SYMBOL(usb_gadget_probe_driver);
1466 1491
1467int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1492static int r8a66597_stop(struct usb_gadget_driver *driver)
1468{ 1493{
1469 struct r8a66597 *r8a66597 = the_controller; 1494 struct r8a66597 *r8a66597 = the_controller;
1470 unsigned long flags; 1495 unsigned long flags;
@@ -1475,20 +1500,16 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1475 spin_lock_irqsave(&r8a66597->lock, flags); 1500 spin_lock_irqsave(&r8a66597->lock, flags);
1476 if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN) 1501 if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN)
1477 r8a66597_usb_disconnect(r8a66597); 1502 r8a66597_usb_disconnect(r8a66597);
1478 spin_unlock_irqrestore(&r8a66597->lock, flags);
1479
1480 r8a66597_bclr(r8a66597, VBSE, INTENB0); 1503 r8a66597_bclr(r8a66597, VBSE, INTENB0);
1504 disable_controller(r8a66597);
1505 spin_unlock_irqrestore(&r8a66597->lock, flags);
1481 1506
1482 driver->unbind(&r8a66597->gadget); 1507 driver->unbind(&r8a66597->gadget);
1483 1508
1484 init_controller(r8a66597);
1485 disable_controller(r8a66597);
1486
1487 device_del(&r8a66597->gadget.dev); 1509 device_del(&r8a66597->gadget.dev);
1488 r8a66597->driver = NULL; 1510 r8a66597->driver = NULL;
1489 return 0; 1511 return 0;
1490} 1512}
1491EXPORT_SYMBOL(usb_gadget_unregister_driver);
1492 1513
1493/*-------------------------------------------------------------------------*/ 1514/*-------------------------------------------------------------------------*/
1494static int r8a66597_get_frame(struct usb_gadget *_gadget) 1515static int r8a66597_get_frame(struct usb_gadget *_gadget)
@@ -1497,14 +1518,33 @@ static int r8a66597_get_frame(struct usb_gadget *_gadget)
1497 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF; 1518 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
1498} 1519}
1499 1520
1521static int r8a66597_pullup(struct usb_gadget *gadget, int is_on)
1522{
1523 struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget);
1524 unsigned long flags;
1525
1526 spin_lock_irqsave(&r8a66597->lock, flags);
1527 if (is_on)
1528 r8a66597_bset(r8a66597, DPRPU, SYSCFG0);
1529 else
1530 r8a66597_bclr(r8a66597, DPRPU, SYSCFG0);
1531 spin_unlock_irqrestore(&r8a66597->lock, flags);
1532
1533 return 0;
1534}
1535
1500static struct usb_gadget_ops r8a66597_gadget_ops = { 1536static struct usb_gadget_ops r8a66597_gadget_ops = {
1501 .get_frame = r8a66597_get_frame, 1537 .get_frame = r8a66597_get_frame,
1538 .start = r8a66597_start,
1539 .stop = r8a66597_stop,
1540 .pullup = r8a66597_pullup,
1502}; 1541};
1503 1542
1504static int __exit r8a66597_remove(struct platform_device *pdev) 1543static int __exit r8a66597_remove(struct platform_device *pdev)
1505{ 1544{
1506 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); 1545 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
1507 1546
1547 usb_del_gadget_udc(&r8a66597->gadget);
1508 del_timer_sync(&r8a66597->timer); 1548 del_timer_sync(&r8a66597->timer);
1509 iounmap(r8a66597->reg); 1549 iounmap(r8a66597->reg);
1510 free_irq(platform_get_irq(pdev, 0), r8a66597); 1550 free_irq(platform_get_irq(pdev, 0), r8a66597);
@@ -1645,11 +1685,15 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1645 goto clean_up3; 1685 goto clean_up3;
1646 r8a66597->ep0_req->complete = nop_completion; 1686 r8a66597->ep0_req->complete = nop_completion;
1647 1687
1648 init_controller(r8a66597); 1688 ret = usb_add_gadget_udc(&pdev->dev, &r8a66597->gadget);
1689 if (ret)
1690 goto err_add_udc;
1649 1691
1650 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1692 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1651 return 0; 1693 return 0;
1652 1694
1695err_add_udc:
1696 r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
1653clean_up3: 1697clean_up3:
1654 free_irq(irq, r8a66597); 1698 free_irq(irq, r8a66597);
1655clean_up2: 1699clean_up2:
@@ -1679,6 +1723,7 @@ static struct platform_driver r8a66597_driver = {
1679 .name = (char *) udc_name, 1723 .name = (char *) udc_name,
1680 }, 1724 },
1681}; 1725};
1726MODULE_ALIAS("platform:r8a66597_udc");
1682 1727
1683static int __init r8a66597_udc_init(void) 1728static int __init r8a66597_udc_init(void)
1684{ 1729{
diff --git a/drivers/usb/gadget/r8a66597-udc.h b/drivers/usb/gadget/r8a66597-udc.h
index 5fc22e09a0f1..503f766c23a7 100644
--- a/drivers/usb/gadget/r8a66597-udc.h
+++ b/drivers/usb/gadget/r8a66597-udc.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2007-2009 Renesas Solutions Corp. 4 * Copyright (C) 2007-2009 Renesas Solutions Corp.
5 * 5 *
6 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> 6 * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.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
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 0dfee282878a..8bdee67ce09a 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -2574,7 +2574,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2574 return 0; 2574 return 0;
2575} 2575}
2576 2576
2577int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2577static int s3c_hsotg_start(struct usb_gadget_driver *driver,
2578 int (*bind)(struct usb_gadget *)) 2578 int (*bind)(struct usb_gadget *))
2579{ 2579{
2580 struct s3c_hsotg *hsotg = our_hsotg; 2580 struct s3c_hsotg *hsotg = our_hsotg;
@@ -2745,9 +2745,8 @@ err:
2745 hsotg->gadget.dev.driver = NULL; 2745 hsotg->gadget.dev.driver = NULL;
2746 return ret; 2746 return ret;
2747} 2747}
2748EXPORT_SYMBOL(usb_gadget_probe_driver);
2749 2748
2750int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2749static int s3c_hsotg_stop(struct usb_gadget_driver *driver)
2751{ 2750{
2752 struct s3c_hsotg *hsotg = our_hsotg; 2751 struct s3c_hsotg *hsotg = our_hsotg;
2753 int ep; 2752 int ep;
@@ -2775,7 +2774,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2775 2774
2776 return 0; 2775 return 0;
2777} 2776}
2778EXPORT_SYMBOL(usb_gadget_unregister_driver);
2779 2777
2780static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) 2778static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget)
2781{ 2779{
@@ -2784,6 +2782,8 @@ static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget)
2784 2782
2785static struct usb_gadget_ops s3c_hsotg_gadget_ops = { 2783static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
2786 .get_frame = s3c_hsotg_gadget_getframe, 2784 .get_frame = s3c_hsotg_gadget_getframe,
2785 .start = s3c_hsotg_start,
2786 .stop = s3c_hsotg_stop,
2787}; 2787};
2788 2788
2789/** 2789/**
@@ -3403,6 +3403,10 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3403 for (epnum = 0; epnum < S3C_HSOTG_EPS; epnum++) 3403 for (epnum = 0; epnum < S3C_HSOTG_EPS; epnum++)
3404 s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); 3404 s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum);
3405 3405
3406 ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget);
3407 if (ret)
3408 goto err_add_udc;
3409
3406 s3c_hsotg_create_debug(hsotg); 3410 s3c_hsotg_create_debug(hsotg);
3407 3411
3408 s3c_hsotg_dump(hsotg); 3412 s3c_hsotg_dump(hsotg);
@@ -3410,6 +3414,11 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3410 our_hsotg = hsotg; 3414 our_hsotg = hsotg;
3411 return 0; 3415 return 0;
3412 3416
3417err_add_udc:
3418 s3c_hsotg_gate(pdev, false);
3419 clk_disable(hsotg->clk);
3420 clk_put(hsotg->clk);
3421
3413err_regs: 3422err_regs:
3414 iounmap(hsotg->regs); 3423 iounmap(hsotg->regs);
3415 3424
@@ -3427,6 +3436,8 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev)
3427{ 3436{
3428 struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); 3437 struct s3c_hsotg *hsotg = platform_get_drvdata(pdev);
3429 3438
3439 usb_del_gadget_udc(&hsotg->gadget);
3440
3430 s3c_hsotg_delete_debug(hsotg); 3441 s3c_hsotg_delete_debug(hsotg);
3431 3442
3432 usb_gadget_unregister_driver(hsotg->driver); 3443 usb_gadget_unregister_driver(hsotg->driver);
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index d5e3e1e58626..3fa717c5f4bc 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -1133,7 +1133,7 @@ static irqreturn_t s3c_hsudc_irq(int irq, void *_dev)
1133 return IRQ_HANDLED; 1133 return IRQ_HANDLED;
1134} 1134}
1135 1135
1136int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1136static int s3c_hsudc_start(struct usb_gadget_driver *driver,
1137 int (*bind)(struct usb_gadget *)) 1137 int (*bind)(struct usb_gadget *))
1138{ 1138{
1139 struct s3c_hsudc *hsudc = the_controller; 1139 struct s3c_hsudc *hsudc = the_controller;
@@ -1181,9 +1181,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1181 1181
1182 return 0; 1182 return 0;
1183} 1183}
1184EXPORT_SYMBOL(usb_gadget_probe_driver);
1185 1184
1186int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1185static int s3c_hsudc_stop(struct usb_gadget_driver *driver)
1187{ 1186{
1188 struct s3c_hsudc *hsudc = the_controller; 1187 struct s3c_hsudc *hsudc = the_controller;
1189 unsigned long flags; 1188 unsigned long flags;
@@ -1210,7 +1209,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1210 driver->driver.name); 1209 driver->driver.name);
1211 return 0; 1210 return 0;
1212} 1211}
1213EXPORT_SYMBOL(usb_gadget_unregister_driver);
1214 1212
1215static inline u32 s3c_hsudc_read_frameno(struct s3c_hsudc *hsudc) 1213static inline u32 s3c_hsudc_read_frameno(struct s3c_hsudc *hsudc)
1216{ 1214{
@@ -1224,6 +1222,8 @@ static int s3c_hsudc_gadget_getframe(struct usb_gadget *gadget)
1224 1222
1225static struct usb_gadget_ops s3c_hsudc_gadget_ops = { 1223static struct usb_gadget_ops s3c_hsudc_gadget_ops = {
1226 .get_frame = s3c_hsudc_gadget_getframe, 1224 .get_frame = s3c_hsudc_gadget_getframe,
1225 .start = s3c_hsudc_start,
1226 .stop = s3c_hsudc_stop,
1227}; 1227};
1228 1228
1229static int s3c_hsudc_probe(struct platform_device *pdev) 1229static int s3c_hsudc_probe(struct platform_device *pdev)
@@ -1311,7 +1311,15 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1311 1311
1312 disable_irq(hsudc->irq); 1312 disable_irq(hsudc->irq);
1313 local_irq_enable(); 1313 local_irq_enable();
1314
1315 ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget);
1316 if (ret)
1317 goto err_add_udc;
1318
1314 return 0; 1319 return 0;
1320err_add_udc:
1321 clk_disable(hsudc->uclk);
1322 clk_put(hsudc->uclk);
1315err_clk: 1323err_clk:
1316 free_irq(hsudc->irq, hsudc); 1324 free_irq(hsudc->irq, hsudc);
1317err_irq: 1325err_irq:
@@ -1333,6 +1341,7 @@ static struct platform_driver s3c_hsudc_driver = {
1333 }, 1341 },
1334 .probe = s3c_hsudc_probe, 1342 .probe = s3c_hsudc_probe,
1335}; 1343};
1344MODULE_ALIAS("platform:s3c-hsudc");
1336 1345
1337static int __init s3c_hsudc_modinit(void) 1346static int __init s3c_hsudc_modinit(void)
1338{ 1347{
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index 100f2635cf0a..85c1b0d66293 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1552,6 +1552,10 @@ static int s3c2410_vbus_draw(struct usb_gadget *_gadget, unsigned ma)
1552 return -ENOTSUPP; 1552 return -ENOTSUPP;
1553} 1553}
1554 1554
1555static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1556 int (*bind)(struct usb_gadget *));
1557static int s3c2410_udc_stop(struct usb_gadget_driver *driver);
1558
1555static const struct usb_gadget_ops s3c2410_ops = { 1559static const struct usb_gadget_ops s3c2410_ops = {
1556 .get_frame = s3c2410_udc_get_frame, 1560 .get_frame = s3c2410_udc_get_frame,
1557 .wakeup = s3c2410_udc_wakeup, 1561 .wakeup = s3c2410_udc_wakeup,
@@ -1559,6 +1563,8 @@ static const struct usb_gadget_ops s3c2410_ops = {
1559 .pullup = s3c2410_udc_pullup, 1563 .pullup = s3c2410_udc_pullup,
1560 .vbus_session = s3c2410_udc_vbus_session, 1564 .vbus_session = s3c2410_udc_vbus_session,
1561 .vbus_draw = s3c2410_vbus_draw, 1565 .vbus_draw = s3c2410_vbus_draw,
1566 .start = s3c2410_udc_start,
1567 .stop = s3c2410_udc_stop,
1562}; 1568};
1563 1569
1564static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) 1570static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd)
@@ -1567,7 +1573,7 @@ static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd)
1567 return; 1573 return;
1568 1574
1569 if (udc_info->udc_command) { 1575 if (udc_info->udc_command) {
1570 udc_info->udc_command(S3C2410_UDC_P_DISABLE); 1576 udc_info->udc_command(cmd);
1571 } else if (gpio_is_valid(udc_info->pullup_pin)) { 1577 } else if (gpio_is_valid(udc_info->pullup_pin)) {
1572 int value; 1578 int value;
1573 1579
@@ -1672,10 +1678,7 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev)
1672 s3c2410_udc_command(S3C2410_UDC_P_ENABLE); 1678 s3c2410_udc_command(S3C2410_UDC_P_ENABLE);
1673} 1679}
1674 1680
1675/* 1681static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1676 * usb_gadget_probe_driver
1677 */
1678int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1679 int (*bind)(struct usb_gadget *)) 1682 int (*bind)(struct usb_gadget *))
1680{ 1683{
1681 struct s3c2410_udc *udc = the_controller; 1684 struct s3c2410_udc *udc = the_controller;
@@ -1730,12 +1733,8 @@ register_error:
1730 udc->gadget.dev.driver = NULL; 1733 udc->gadget.dev.driver = NULL;
1731 return retval; 1734 return retval;
1732} 1735}
1733EXPORT_SYMBOL(usb_gadget_probe_driver);
1734 1736
1735/* 1737static int s3c2410_udc_stop(struct usb_gadget_driver *driver)
1736 * usb_gadget_unregister_driver
1737 */
1738int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1739{ 1738{
1740 struct s3c2410_udc *udc = the_controller; 1739 struct s3c2410_udc *udc = the_controller;
1741 1740
@@ -1955,6 +1954,10 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1955 goto err_vbus_irq; 1954 goto err_vbus_irq;
1956 } 1955 }
1957 1956
1957 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
1958 if (retval)
1959 goto err_add_udc;
1960
1958 if (s3c2410_udc_debugfs_root) { 1961 if (s3c2410_udc_debugfs_root) {
1959 udc->regs_info = debugfs_create_file("registers", S_IRUGO, 1962 udc->regs_info = debugfs_create_file("registers", S_IRUGO,
1960 s3c2410_udc_debugfs_root, 1963 s3c2410_udc_debugfs_root,
@@ -1967,6 +1970,10 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1967 1970
1968 return 0; 1971 return 0;
1969 1972
1973err_add_udc:
1974 if (udc_info && !udc_info->udc_command &&
1975 gpio_is_valid(udc_info->pullup_pin))
1976 gpio_free(udc_info->pullup_pin);
1970err_vbus_irq: 1977err_vbus_irq:
1971 if (udc_info && udc_info->vbus_pin > 0) 1978 if (udc_info && udc_info->vbus_pin > 0)
1972 free_irq(gpio_to_irq(udc_info->vbus_pin), udc); 1979 free_irq(gpio_to_irq(udc_info->vbus_pin), udc);
@@ -1992,6 +1999,8 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
1992 unsigned int irq; 1999 unsigned int irq;
1993 2000
1994 dev_dbg(&pdev->dev, "%s()\n", __func__); 2001 dev_dbg(&pdev->dev, "%s()\n", __func__);
2002
2003 usb_del_gadget_udc(&udc->gadget);
1995 if (udc->driver) 2004 if (udc->driver)
1996 return -EBUSY; 2005 return -EBUSY;
1997 2006
@@ -2048,26 +2057,22 @@ static int s3c2410_udc_resume(struct platform_device *pdev)
2048#define s3c2410_udc_resume NULL 2057#define s3c2410_udc_resume NULL
2049#endif 2058#endif
2050 2059
2051static struct platform_driver udc_driver_2410 = { 2060static const struct platform_device_id s3c_udc_ids[] = {
2052 .driver = { 2061 { "s3c2410-usbgadget", },
2053 .name = "s3c2410-usbgadget", 2062 { "s3c2440-usbgadget", },
2054 .owner = THIS_MODULE,
2055 },
2056 .probe = s3c2410_udc_probe,
2057 .remove = s3c2410_udc_remove,
2058 .suspend = s3c2410_udc_suspend,
2059 .resume = s3c2410_udc_resume,
2060}; 2063};
2064MODULE_DEVICE_TABLE(platform, s3c_udc_ids);
2061 2065
2062static struct platform_driver udc_driver_2440 = { 2066static struct platform_driver udc_driver_24x0 = {
2063 .driver = { 2067 .driver = {
2064 .name = "s3c2440-usbgadget", 2068 .name = "s3c24x0-usbgadget",
2065 .owner = THIS_MODULE, 2069 .owner = THIS_MODULE,
2066 }, 2070 },
2067 .probe = s3c2410_udc_probe, 2071 .probe = s3c2410_udc_probe,
2068 .remove = s3c2410_udc_remove, 2072 .remove = s3c2410_udc_remove,
2069 .suspend = s3c2410_udc_suspend, 2073 .suspend = s3c2410_udc_suspend,
2070 .resume = s3c2410_udc_resume, 2074 .resume = s3c2410_udc_resume,
2075 .id_table = s3c_udc_ids,
2071}; 2076};
2072 2077
2073static int __init udc_init(void) 2078static int __init udc_init(void)
@@ -2083,11 +2088,7 @@ static int __init udc_init(void)
2083 s3c2410_udc_debugfs_root = NULL; 2088 s3c2410_udc_debugfs_root = NULL;
2084 } 2089 }
2085 2090
2086 retval = platform_driver_register(&udc_driver_2410); 2091 retval = platform_driver_register(&udc_driver_24x0);
2087 if (retval)
2088 goto err;
2089
2090 retval = platform_driver_register(&udc_driver_2440);
2091 if (retval) 2092 if (retval)
2092 goto err; 2093 goto err;
2093 2094
@@ -2100,13 +2101,10 @@ err:
2100 2101
2101static void __exit udc_exit(void) 2102static void __exit udc_exit(void)
2102{ 2103{
2103 platform_driver_unregister(&udc_driver_2410); 2104 platform_driver_unregister(&udc_driver_24x0);
2104 platform_driver_unregister(&udc_driver_2440);
2105 debugfs_remove(s3c2410_udc_debugfs_root); 2105 debugfs_remove(s3c2410_udc_debugfs_root);
2106} 2106}
2107 2107
2108EXPORT_SYMBOL(usb_gadget_unregister_driver);
2109
2110module_init(udc_init); 2108module_init(udc_init);
2111module_exit(udc_exit); 2109module_exit(udc_exit);
2112 2110
@@ -2114,5 +2112,3 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
2114MODULE_DESCRIPTION(DRIVER_DESC); 2112MODULE_DESCRIPTION(DRIVER_DESC);
2115MODULE_VERSION(DRIVER_VERSION); 2113MODULE_VERSION(DRIVER_VERSION);
2116MODULE_LICENSE("GPL"); 2114MODULE_LICENSE("GPL");
2117MODULE_ALIAS("platform:s3c2410-usbgadget");
2118MODULE_ALIAS("platform:s3c2440-usbgadget");
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 1ac57a973aa9..ed1b816e58d8 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -242,6 +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}; 246};
246 247
247static 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 1fa4f705b0b4..d3dd227a2bfc 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -494,7 +494,7 @@ static struct usb_descriptor_header *fsg_hs_function[] = {
494}; 494};
495 495
496/* Maxpacket and other transfer characteristics vary by speed. */ 496/* Maxpacket and other transfer characteristics vary by speed. */
497static struct usb_endpoint_descriptor * 497static __maybe_unused struct usb_endpoint_descriptor *
498fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, 498fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
499 struct usb_endpoint_descriptor *hs) 499 struct usb_endpoint_descriptor *hs)
500{ 500{
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 2ac1d2147325..dfed4c1d96c0 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -97,16 +97,17 @@ struct eth_dev {
97 97
98static unsigned qmult = 5; 98static unsigned qmult = 5;
99module_param(qmult, uint, S_IRUGO|S_IWUSR); 99module_param(qmult, uint, S_IRUGO|S_IWUSR);
100MODULE_PARM_DESC(qmult, "queue length multiplier at high speed"); 100MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
101 101
102#else /* full speed (low speed doesn't do bulk) */ 102#else /* full speed (low speed doesn't do bulk) */
103#define qmult 1 103#define qmult 1
104#endif 104#endif
105 105
106/* for dual-speed hardware, use deeper queues at highspeed */ 106/* for dual-speed hardware, use deeper queues at high/super speed */
107static inline int qlen(struct usb_gadget *gadget) 107static inline int qlen(struct usb_gadget *gadget)
108{ 108{
109 if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH) 109 if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH ||
110 gadget->speed == USB_SPEED_SUPER))
110 return qmult * DEFAULT_QLEN; 111 return qmult * DEFAULT_QLEN;
111 else 112 else
112 return DEFAULT_QLEN; 113 return DEFAULT_QLEN;
@@ -598,9 +599,10 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
598 599
599 req->length = length; 600 req->length = length;
600 601
601 /* throttle highspeed IRQ rate back slightly */ 602 /* throttle high/super speed IRQ rate back slightly */
602 if (gadget_is_dualspeed(dev->gadget)) 603 if (gadget_is_dualspeed(dev->gadget))
603 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH) 604 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH ||
605 dev->gadget->speed == USB_SPEED_SUPER)
604 ? ((atomic_read(&dev->tx_qlen) % qmult) != 0) 606 ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
605 : 0; 607 : 0;
606 608
@@ -693,8 +695,8 @@ static int eth_stop(struct net_device *net)
693 usb_ep_disable(link->out_ep); 695 usb_ep_disable(link->out_ep);
694 if (netif_carrier_ok(net)) { 696 if (netif_carrier_ok(net)) {
695 DBG(dev, "host still using in/out endpoints\n"); 697 DBG(dev, "host still using in/out endpoints\n");
696 usb_ep_enable(link->in_ep, link->in); 698 usb_ep_enable(link->in_ep);
697 usb_ep_enable(link->out_ep, link->out); 699 usb_ep_enable(link->out_ep);
698 } 700 }
699 } 701 }
700 spin_unlock_irqrestore(&dev->lock, flags); 702 spin_unlock_irqrestore(&dev->lock, flags);
@@ -871,7 +873,7 @@ struct net_device *gether_connect(struct gether *link)
871 return ERR_PTR(-EINVAL); 873 return ERR_PTR(-EINVAL);
872 874
873 link->in_ep->driver_data = dev; 875 link->in_ep->driver_data = dev;
874 result = usb_ep_enable(link->in_ep, link->in); 876 result = usb_ep_enable(link->in_ep);
875 if (result != 0) { 877 if (result != 0) {
876 DBG(dev, "enable %s --> %d\n", 878 DBG(dev, "enable %s --> %d\n",
877 link->in_ep->name, result); 879 link->in_ep->name, result);
@@ -879,7 +881,7 @@ struct net_device *gether_connect(struct gether *link)
879 } 881 }
880 882
881 link->out_ep->driver_data = dev; 883 link->out_ep->driver_data = dev;
882 result = usb_ep_enable(link->out_ep, link->out); 884 result = usb_ep_enable(link->out_ep);
883 if (result != 0) { 885 if (result != 0) {
884 DBG(dev, "enable %s --> %d\n", 886 DBG(dev, "enable %s --> %d\n",
885 link->out_ep->name, result); 887 link->out_ep->name, result);
@@ -969,7 +971,7 @@ void gether_disconnect(struct gether *link)
969 } 971 }
970 spin_unlock(&dev->req_lock); 972 spin_unlock(&dev->req_lock);
971 link->in_ep->driver_data = NULL; 973 link->in_ep->driver_data = NULL;
972 link->in = NULL; 974 link->in_ep->desc = NULL;
973 975
974 usb_ep_disable(link->out_ep); 976 usb_ep_disable(link->out_ep);
975 spin_lock(&dev->req_lock); 977 spin_lock(&dev->req_lock);
@@ -984,7 +986,7 @@ void gether_disconnect(struct gether *link)
984 } 986 }
985 spin_unlock(&dev->req_lock); 987 spin_unlock(&dev->req_lock);
986 link->out_ep->driver_data = NULL; 988 link->out_ep->driver_data = NULL;
987 link->out = NULL; 989 link->out_ep->desc = NULL;
988 990
989 /* finish forgetting about this USB link episode */ 991 /* finish forgetting about this USB link episode */
990 dev->header_len = 0; 992 dev->header_len = 0;
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index b56e1e7d423c..c966440ddd70 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -52,10 +52,6 @@ struct gether {
52 struct usb_ep *in_ep; 52 struct usb_ep *in_ep;
53 struct usb_ep *out_ep; 53 struct usb_ep *out_ep;
54 54
55 /* descriptors match device speed at gether_connect() time */
56 struct usb_endpoint_descriptor *in;
57 struct usb_endpoint_descriptor *out;
58
59 bool is_zlp_ok; 55 bool is_zlp_ok;
60 56
61 u16 cdc_filter; 57 u16 cdc_filter;
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 40f7716b31fc..a8aa46962d81 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -1247,12 +1247,12 @@ int gserial_connect(struct gserial *gser, u8 port_num)
1247 port = ports[port_num].port; 1247 port = ports[port_num].port;
1248 1248
1249 /* activate the endpoints */ 1249 /* activate the endpoints */
1250 status = usb_ep_enable(gser->in, gser->in_desc); 1250 status = usb_ep_enable(gser->in);
1251 if (status < 0) 1251 if (status < 0)
1252 return status; 1252 return status;
1253 gser->in->driver_data = port; 1253 gser->in->driver_data = port;
1254 1254
1255 status = usb_ep_enable(gser->out, gser->out_desc); 1255 status = usb_ep_enable(gser->out);
1256 if (status < 0) 1256 if (status < 0)
1257 goto fail_out; 1257 goto fail_out;
1258 gser->out->driver_data = port; 1258 gser->out->driver_data = port;
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h
index 300f0ed9475d..9b0fe6450fbf 100644
--- a/drivers/usb/gadget/u_serial.h
+++ b/drivers/usb/gadget/u_serial.h
@@ -35,8 +35,6 @@ struct gserial {
35 35
36 struct usb_ep *in; 36 struct usb_ep *in;
37 struct usb_ep *out; 37 struct usb_ep *out;
38 struct usb_endpoint_descriptor *in_desc;
39 struct usb_endpoint_descriptor *out_desc;
40 38
41 /* REVISIT avoid this CDC-ACM support harder ... */ 39 /* REVISIT avoid this CDC-ACM support harder ... */
42 struct usb_cdc_line_coding port_line_coding; /* 9600-8-N-1 etc */ 40 struct usb_cdc_line_coding port_line_coding; /* 9600-8-N-1 etc */
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
new file mode 100644
index 000000000000..05ba47214361
--- /dev/null
+++ b/drivers/usb/gadget/udc-core.c
@@ -0,0 +1,484 @@
1/**
2 * udc.c - Core UDC Framework
3 *
4 * Copyright (C) 2010 Texas Instruments
5 * Author: Felipe Balbi <balbi@ti.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 of
9 * the License as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/device.h>
23#include <linux/list.h>
24#include <linux/err.h>
25
26#include <linux/usb/ch9.h>
27#include <linux/usb/gadget.h>
28
29/**
30 * struct usb_udc - describes one usb device controller
31 * @driver - the gadget driver pointer. For use by the class code
32 * @dev - the child device to the actual controller
33 * @gadget - the gadget. For use by the class code
34 * @list - for use by the udc class driver
35 *
36 * This represents the internal data structure which is used by the UDC-class
37 * to hold information about udc driver and gadget together.
38 */
39struct usb_udc {
40 struct usb_gadget_driver *driver;
41 struct usb_gadget *gadget;
42 struct device dev;
43 struct list_head list;
44};
45
46static struct class *udc_class;
47static LIST_HEAD(udc_list);
48static DEFINE_MUTEX(udc_lock);
49
50/* ------------------------------------------------------------------------- */
51
52/**
53 * usb_gadget_start - tells usb device controller to start up
54 * @gadget: The gadget we want to get started
55 * @driver: The driver we want to bind to @gadget
56 * @bind: The bind function for @driver
57 *
58 * This call is issued by the UDC Class driver when it's about
59 * to register a gadget driver to the device controller, before
60 * calling gadget driver's bind() method.
61 *
62 * It allows the controller to be powered off until strictly
63 * necessary to have it powered on.
64 *
65 * Returns zero on success, else negative errno.
66 */
67static inline int usb_gadget_start(struct usb_gadget *gadget,
68 struct usb_gadget_driver *driver,
69 int (*bind)(struct usb_gadget *))
70{
71 return gadget->ops->start(driver, bind);
72}
73
74/**
75 * usb_gadget_udc_start - tells usb device controller to start up
76 * @gadget: The gadget we want to get started
77 * @driver: The driver we want to bind to @gadget
78 *
79 * This call is issued by the UDC Class driver when it's about
80 * to register a gadget driver to the device controller, before
81 * calling gadget driver's bind() method.
82 *
83 * It allows the controller to be powered off until strictly
84 * necessary to have it powered on.
85 *
86 * Returns zero on success, else negative errno.
87 */
88static inline int usb_gadget_udc_start(struct usb_gadget *gadget,
89 struct usb_gadget_driver *driver)
90{
91 return gadget->ops->udc_start(gadget, driver);
92}
93
94/**
95 * usb_gadget_stop - tells usb device controller we don't need it anymore
96 * @gadget: The device we want to stop activity
97 * @driver: The driver to unbind from @gadget
98 *
99 * This call is issued by the UDC Class driver after calling
100 * gadget driver's unbind() method.
101 *
102 * The details are implementation specific, but it can go as
103 * far as powering off UDC completely and disable its data
104 * line pullups.
105 */
106static inline void usb_gadget_stop(struct usb_gadget *gadget,
107 struct usb_gadget_driver *driver)
108{
109 gadget->ops->stop(driver);
110}
111
112/**
113 * usb_gadget_udc_stop - tells usb device controller we don't need it anymore
114 * @gadget: The device we want to stop activity
115 * @driver: The driver to unbind from @gadget
116 *
117 * This call is issued by the UDC Class driver after calling
118 * gadget driver's unbind() method.
119 *
120 * The details are implementation specific, but it can go as
121 * far as powering off UDC completely and disable its data
122 * line pullups.
123 */
124static inline void usb_gadget_udc_stop(struct usb_gadget *gadget,
125 struct usb_gadget_driver *driver)
126{
127 gadget->ops->udc_stop(gadget, driver);
128}
129
130/**
131 * usb_udc_release - release the usb_udc struct
132 * @dev: the dev member within usb_udc
133 *
134 * This is called by driver's core in order to free memory once the last
135 * reference is released.
136 */
137static void usb_udc_release(struct device *dev)
138{
139 struct usb_udc *udc;
140
141 udc = container_of(dev, struct usb_udc, dev);
142 dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
143 kfree(udc);
144}
145
146static const struct attribute_group *usb_udc_attr_groups[];
147/**
148 * usb_add_gadget_udc - adds a new gadget to the udc class driver list
149 * @parent: the parent device to this udc. Usually the controller
150 * driver's device.
151 * @gadget: the gadget to be added to the list
152 *
153 * Returns zero on success, negative errno otherwise.
154 */
155int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
156{
157 struct usb_udc *udc;
158 int ret = -ENOMEM;
159
160 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
161 if (!udc)
162 goto err1;
163
164 device_initialize(&udc->dev);
165 udc->dev.release = usb_udc_release;
166 udc->dev.class = udc_class;
167 udc->dev.groups = usb_udc_attr_groups;
168 udc->dev.parent = parent;
169 ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
170 if (ret)
171 goto err2;
172
173 udc->gadget = gadget;
174
175 mutex_lock(&udc_lock);
176 list_add_tail(&udc->list, &udc_list);
177
178 ret = device_add(&udc->dev);
179 if (ret)
180 goto err3;
181
182 mutex_unlock(&udc_lock);
183
184 return 0;
185err3:
186 list_del(&udc->list);
187 mutex_unlock(&udc_lock);
188
189err2:
190 put_device(&udc->dev);
191
192err1:
193 return ret;
194}
195EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
196
197static int udc_is_newstyle(struct usb_udc *udc)
198{
199 if (udc->gadget->ops->udc_start && udc->gadget->ops->udc_stop)
200 return 1;
201 return 0;
202}
203
204
205static void usb_gadget_remove_driver(struct usb_udc *udc)
206{
207 dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
208 udc->gadget->name);
209
210 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
211
212 if (udc_is_newstyle(udc)) {
213 usb_gadget_disconnect(udc->gadget);
214 udc->driver->unbind(udc->gadget);
215 usb_gadget_udc_stop(udc->gadget, udc->driver);
216
217 } else {
218 usb_gadget_stop(udc->gadget, udc->driver);
219 }
220
221 udc->driver = NULL;
222 udc->dev.driver = NULL;
223}
224
225/**
226 * usb_del_gadget_udc - deletes @udc from udc_list
227 * @gadget: the gadget to be removed.
228 *
229 * This, will call usb_gadget_unregister_driver() if
230 * the @udc is still busy.
231 */
232void usb_del_gadget_udc(struct usb_gadget *gadget)
233{
234 struct usb_udc *udc = NULL;
235
236 mutex_lock(&udc_lock);
237 list_for_each_entry(udc, &udc_list, list)
238 if (udc->gadget == gadget)
239 goto found;
240
241 dev_err(gadget->dev.parent, "gadget not registered.\n");
242 mutex_unlock(&udc_lock);
243
244 return;
245
246found:
247 dev_vdbg(gadget->dev.parent, "unregistering gadget\n");
248
249 list_del(&udc->list);
250 mutex_unlock(&udc_lock);
251
252 if (udc->driver)
253 usb_gadget_remove_driver(udc);
254
255 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
256 device_unregister(&udc->dev);
257}
258EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
259
260/* ------------------------------------------------------------------------- */
261
262int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
263 int (*bind)(struct usb_gadget *))
264{
265 struct usb_udc *udc = NULL;
266 int ret;
267
268 if (!driver || !bind || !driver->setup)
269 return -EINVAL;
270
271 mutex_lock(&udc_lock);
272 list_for_each_entry(udc, &udc_list, list) {
273 /* For now we take the first one */
274 if (!udc->driver)
275 goto found;
276 }
277
278 pr_debug("couldn't find an available UDC\n");
279 mutex_unlock(&udc_lock);
280 return -ENODEV;
281
282found:
283 dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
284 driver->function);
285
286 udc->driver = driver;
287 udc->dev.driver = &driver->driver;
288
289 if (udc_is_newstyle(udc)) {
290 ret = bind(udc->gadget);
291 if (ret)
292 goto err1;
293 ret = usb_gadget_udc_start(udc->gadget, driver);
294 if (ret) {
295 driver->unbind(udc->gadget);
296 goto err1;
297 }
298 usb_gadget_connect(udc->gadget);
299 } else {
300
301 ret = usb_gadget_start(udc->gadget, driver, bind);
302 if (ret)
303 goto err1;
304
305 }
306
307 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
308 mutex_unlock(&udc_lock);
309 return 0;
310
311err1:
312 dev_err(&udc->dev, "failed to start %s: %d\n",
313 udc->driver->function, ret);
314 udc->driver = NULL;
315 udc->dev.driver = NULL;
316 mutex_unlock(&udc_lock);
317 return ret;
318}
319EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
320
321int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
322{
323 struct usb_udc *udc = NULL;
324 int ret = -ENODEV;
325
326 if (!driver || !driver->unbind)
327 return -EINVAL;
328
329 mutex_lock(&udc_lock);
330 list_for_each_entry(udc, &udc_list, list)
331 if (udc->driver == driver) {
332 usb_gadget_remove_driver(udc);
333 ret = 0;
334 break;
335 }
336
337 mutex_unlock(&udc_lock);
338 return ret;
339}
340EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
341
342/* ------------------------------------------------------------------------- */
343
344static ssize_t usb_udc_srp_store(struct device *dev,
345 struct device_attribute *attr, const char *buf, size_t n)
346{
347 struct usb_udc *udc = dev_get_drvdata(dev);
348
349 if (sysfs_streq(buf, "1"))
350 usb_gadget_wakeup(udc->gadget);
351
352 return n;
353}
354static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store);
355
356static ssize_t usb_udc_softconn_store(struct device *dev,
357 struct device_attribute *attr, const char *buf, size_t n)
358{
359 struct usb_udc *udc = dev_get_drvdata(dev);
360
361 if (sysfs_streq(buf, "connect")) {
362 usb_gadget_connect(udc->gadget);
363 } else if (sysfs_streq(buf, "disconnect")) {
364 usb_gadget_disconnect(udc->gadget);
365 } else {
366 dev_err(dev, "unsupported command '%s'\n", buf);
367 return -EINVAL;
368 }
369
370 return n;
371}
372static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
373
374static ssize_t usb_udc_speed_show(struct device *dev,
375 struct device_attribute *attr, char *buf)
376{
377 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
378 struct usb_gadget *gadget = udc->gadget;
379
380 switch (gadget->speed) {
381 case USB_SPEED_LOW:
382 return snprintf(buf, PAGE_SIZE, "low-speed\n");
383 case USB_SPEED_FULL:
384 return snprintf(buf, PAGE_SIZE, "full-speed\n");
385 case USB_SPEED_HIGH:
386 return snprintf(buf, PAGE_SIZE, "high-speed\n");
387 case USB_SPEED_WIRELESS:
388 return snprintf(buf, PAGE_SIZE, "wireless\n");
389 case USB_SPEED_SUPER:
390 return snprintf(buf, PAGE_SIZE, "super-speed\n");
391 case USB_SPEED_UNKNOWN: /* FALLTHROUGH */
392 default:
393 return snprintf(buf, PAGE_SIZE, "UNKNOWN\n");
394 }
395}
396static DEVICE_ATTR(speed, S_IRUSR, usb_udc_speed_show, NULL);
397
398#define USB_UDC_ATTR(name) \
399ssize_t usb_udc_##name##_show(struct device *dev, \
400 struct device_attribute *attr, char *buf) \
401{ \
402 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
403 struct usb_gadget *gadget = udc->gadget; \
404 \
405 return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \
406} \
407static DEVICE_ATTR(name, S_IRUSR, usb_udc_##name##_show, NULL)
408
409static USB_UDC_ATTR(is_dualspeed);
410static USB_UDC_ATTR(is_otg);
411static USB_UDC_ATTR(is_a_peripheral);
412static USB_UDC_ATTR(b_hnp_enable);
413static USB_UDC_ATTR(a_hnp_support);
414static USB_UDC_ATTR(a_alt_hnp_support);
415
416static struct attribute *usb_udc_attrs[] = {
417 &dev_attr_srp.attr,
418 &dev_attr_soft_connect.attr,
419 &dev_attr_speed.attr,
420
421 &dev_attr_is_dualspeed.attr,
422 &dev_attr_is_otg.attr,
423 &dev_attr_is_a_peripheral.attr,
424 &dev_attr_b_hnp_enable.attr,
425 &dev_attr_a_hnp_support.attr,
426 &dev_attr_a_alt_hnp_support.attr,
427 NULL,
428};
429
430static const struct attribute_group usb_udc_attr_group = {
431 .attrs = usb_udc_attrs,
432};
433
434static const struct attribute_group *usb_udc_attr_groups[] = {
435 &usb_udc_attr_group,
436 NULL,
437};
438
439static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env)
440{
441 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
442 int ret;
443
444 ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name);
445 if (ret) {
446 dev_err(dev, "failed to add uevent USB_UDC_NAME\n");
447 return ret;
448 }
449
450 if (udc->driver) {
451 ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
452 udc->driver->function);
453 if (ret) {
454 dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n");
455 return ret;
456 }
457 }
458
459 return 0;
460}
461
462static int __init usb_udc_init(void)
463{
464 udc_class = class_create(THIS_MODULE, "udc");
465 if (IS_ERR(udc_class)) {
466 pr_err("failed to create udc class --> %ld\n",
467 PTR_ERR(udc_class));
468 return PTR_ERR(udc_class);
469 }
470
471 udc_class->dev_uevent = usb_udc_uevent;
472 return 0;
473}
474subsys_initcall(usb_udc_init);
475
476static void __exit usb_udc_exit(void)
477{
478 class_destroy(udc_class);
479}
480module_exit(usb_udc_exit);
481
482MODULE_DESCRIPTION("UDC Framework");
483MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
484MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index a5a0fdb808c7..df6882de50bf 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -373,6 +373,7 @@ static struct usb_composite_driver webcam_driver = {
373 .name = "g_webcam", 373 .name = "g_webcam",
374 .dev = &webcam_device_descriptor, 374 .dev = &webcam_device_descriptor,
375 .strings = webcam_device_strings, 375 .strings = webcam_device_strings,
376 .max_speed = USB_SPEED_HIGH,
376 .unbind = webcam_unbind, 377 .unbind = webcam_unbind,
377}; 378};
378 379
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 6d16db9d9d2d..00e2fd2d4791 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -340,6 +340,7 @@ static struct usb_composite_driver zero_driver = {
340 .name = "zero", 340 .name = "zero",
341 .dev = &device_desc, 341 .dev = &device_desc,
342 .strings = dev_strings, 342 .strings = dev_strings,
343 .max_speed = USB_SPEED_SUPER,
343 .unbind = zero_unbind, 344 .unbind = zero_unbind,
344 .suspend = zero_suspend, 345 .suspend = zero_suspend,
345 .resume = zero_resume, 346 .resume = zero_resume,
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index f8030ee928e8..f72ae0b6ee7f 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -94,7 +94,8 @@ static const char hcd_name [] = "ehci_hcd";
94#define EHCI_IAA_MSECS 10 /* arbitrary */ 94#define EHCI_IAA_MSECS 10 /* arbitrary */
95#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ 95#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
96#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ 96#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
97#define EHCI_SHRINK_FRAMES 5 /* async qh unlink delay */ 97#define EHCI_SHRINK_JIFFIES (DIV_ROUND_UP(HZ, 200) + 1)
98 /* 200-ms async qh unlink delay */
98 99
99/* Initial IRQ latency: faster than hw default */ 100/* Initial IRQ latency: faster than hw default */
100static int log2_irq_thresh = 0; // 0 to 6 101static int log2_irq_thresh = 0; // 0 to 6
@@ -114,7 +115,7 @@ MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
114/* for link power management(LPM) feature */ 115/* for link power management(LPM) feature */
115static unsigned int hird; 116static unsigned int hird;
116module_param(hird, int, S_IRUGO); 117module_param(hird, int, S_IRUGO);
117MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n"); 118MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us");
118 119
119#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 120#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
120 121
@@ -152,10 +153,7 @@ timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action)
152 break; 153 break;
153 /* case TIMER_ASYNC_SHRINK: */ 154 /* case TIMER_ASYNC_SHRINK: */
154 default: 155 default:
155 /* add a jiffie since we synch against the 156 t = EHCI_SHRINK_JIFFIES;
156 * 8 KHz uframe counter.
157 */
158 t = DIV_ROUND_UP(EHCI_SHRINK_FRAMES * HZ, 1000) + 1;
159 break; 157 break;
160 } 158 }
161 mod_timer(&ehci->watchdog, t + jiffies); 159 mod_timer(&ehci->watchdog, t + jiffies);
@@ -340,6 +338,7 @@ static void ehci_work(struct ehci_hcd *ehci);
340#include "ehci-mem.c" 338#include "ehci-mem.c"
341#include "ehci-q.c" 339#include "ehci-q.c"
342#include "ehci-sched.c" 340#include "ehci-sched.c"
341#include "ehci-sysfs.c"
343 342
344/*-------------------------------------------------------------------------*/ 343/*-------------------------------------------------------------------------*/
345 344
@@ -524,7 +523,7 @@ static void ehci_stop (struct usb_hcd *hcd)
524 ehci_reset (ehci); 523 ehci_reset (ehci);
525 spin_unlock_irq(&ehci->lock); 524 spin_unlock_irq(&ehci->lock);
526 525
527 remove_companion_file(ehci); 526 remove_sysfs_files(ehci);
528 remove_debug_files (ehci); 527 remove_debug_files (ehci);
529 528
530 /* root hub is shut down separately (first, when possible) */ 529 /* root hub is shut down separately (first, when possible) */
@@ -575,6 +574,12 @@ static int ehci_init(struct usb_hcd *hcd)
575 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); 574 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
576 575
577 /* 576 /*
577 * by default set standard 80% (== 100 usec/uframe) max periodic
578 * bandwidth as required by USB 2.0
579 */
580 ehci->uframe_periodic_max = 100;
581
582 /*
578 * hw default: 1K periodic list heads, one per frame. 583 * hw default: 1K periodic list heads, one per frame.
579 * periodic_size can shrink by USBCMD update if hcc_params allows. 584 * periodic_size can shrink by USBCMD update if hcc_params allows.
580 */ 585 */
@@ -758,7 +763,7 @@ static int ehci_run (struct usb_hcd *hcd)
758 * since the class device isn't created that early. 763 * since the class device isn't created that early.
759 */ 764 */
760 create_debug_files(ehci); 765 create_debug_files(ehci);
761 create_companion_file(ehci); 766 create_sysfs_files(ehci);
762 767
763 return 0; 768 return 0;
764} 769}
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index ea6184bf48d0..bf2c8f65e1ae 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -471,29 +471,6 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
471 471
472/*-------------------------------------------------------------------------*/ 472/*-------------------------------------------------------------------------*/
473 473
474/* Display the ports dedicated to the companion controller */
475static ssize_t show_companion(struct device *dev,
476 struct device_attribute *attr,
477 char *buf)
478{
479 struct ehci_hcd *ehci;
480 int nports, index, n;
481 int count = PAGE_SIZE;
482 char *ptr = buf;
483
484 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
485 nports = HCS_N_PORTS(ehci->hcs_params);
486
487 for (index = 0; index < nports; ++index) {
488 if (test_bit(index, &ehci->companion_ports)) {
489 n = scnprintf(ptr, count, "%d\n", index + 1);
490 ptr += n;
491 count -= n;
492 }
493 }
494 return ptr - buf;
495}
496
497/* 474/*
498 * Sets the owner of a port 475 * Sets the owner of a port
499 */ 476 */
@@ -528,58 +505,6 @@ static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
528 } 505 }
529} 506}
530 507
531/*
532 * Dedicate or undedicate a port to the companion controller.
533 * Syntax is "[-]portnum", where a leading '-' sign means
534 * return control of the port to the EHCI controller.
535 */
536static ssize_t store_companion(struct device *dev,
537 struct device_attribute *attr,
538 const char *buf, size_t count)
539{
540 struct ehci_hcd *ehci;
541 int portnum, new_owner;
542
543 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
544 new_owner = PORT_OWNER; /* Owned by companion */
545 if (sscanf(buf, "%d", &portnum) != 1)
546 return -EINVAL;
547 if (portnum < 0) {
548 portnum = - portnum;
549 new_owner = 0; /* Owned by EHCI */
550 }
551 if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
552 return -ENOENT;
553 portnum--;
554 if (new_owner)
555 set_bit(portnum, &ehci->companion_ports);
556 else
557 clear_bit(portnum, &ehci->companion_ports);
558 set_owner(ehci, portnum, new_owner);
559 return count;
560}
561static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
562
563static inline int create_companion_file(struct ehci_hcd *ehci)
564{
565 int i = 0;
566
567 /* with integrated TT there is no companion! */
568 if (!ehci_is_TDI(ehci))
569 i = device_create_file(ehci_to_hcd(ehci)->self.controller,
570 &dev_attr_companion);
571 return i;
572}
573
574static inline void remove_companion_file(struct ehci_hcd *ehci)
575{
576 /* with integrated TT there is no companion! */
577 if (!ehci_is_TDI(ehci))
578 device_remove_file(ehci_to_hcd(ehci)->self.controller,
579 &dev_attr_companion);
580}
581
582
583/*-------------------------------------------------------------------------*/ 508/*-------------------------------------------------------------------------*/
584 509
585static int check_reset_complete ( 510static int check_reset_complete (
@@ -891,10 +816,11 @@ static int ehci_hub_control (
891 * power switching; they're allowed to just limit the 816 * power switching; they're allowed to just limit the
892 * current. khubd will turn the power back on. 817 * current. khubd will turn the power back on.
893 */ 818 */
894 if (HCS_PPC (ehci->hcs_params)){ 819 if ((temp & PORT_OC) && HCS_PPC(ehci->hcs_params)) {
895 ehci_writel(ehci, 820 ehci_writel(ehci,
896 temp & ~(PORT_RWC_BITS | PORT_POWER), 821 temp & ~(PORT_RWC_BITS | PORT_POWER),
897 status_reg); 822 status_reg);
823 temp = ehci_readl(ehci, status_reg);
898 } 824 }
899 } 825 }
900 826
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index b5a0bf649c95..592d5f76803e 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -40,27 +40,9 @@ static int ehci_msm_reset(struct usb_hcd *hcd)
40 int retval; 40 int retval;
41 41
42 ehci->caps = USB_CAPLENGTH; 42 ehci->caps = USB_CAPLENGTH;
43 ehci->regs = USB_CAPLENGTH +
44 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
45 dbg_hcs_params(ehci, "reset");
46 dbg_hcc_params(ehci, "reset");
47
48 /* cache the data to minimize the chip reads*/
49 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
50
51 hcd->has_tt = 1; 43 hcd->has_tt = 1;
52 ehci->sbrn = HCD_USB2;
53
54 retval = ehci_halt(ehci);
55 if (retval)
56 return retval;
57
58 /* data structure init */
59 retval = ehci_init(hcd);
60 if (retval)
61 return retval;
62 44
63 retval = ehci_reset(ehci); 45 retval = ehci_setup(hcd);
64 if (retval) 46 if (retval)
65 return retval; 47 return retval;
66 48
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 5d6bc624c961..0917e3a32465 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -103,7 +103,7 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
103 if (!(hw->hw_info1 & cpu_to_hc32(ehci, 1 << 14))) { 103 if (!(hw->hw_info1 & cpu_to_hc32(ehci, 1 << 14))) {
104 unsigned is_out, epnum; 104 unsigned is_out, epnum;
105 105
106 is_out = !(qtd->hw_token & cpu_to_hc32(ehci, 1 << 8)); 106 is_out = qh->is_out;
107 epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f; 107 epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f;
108 if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { 108 if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) {
109 hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); 109 hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE);
@@ -946,6 +946,7 @@ done:
946 hw = qh->hw; 946 hw = qh->hw;
947 hw->hw_info1 = cpu_to_hc32(ehci, info1); 947 hw->hw_info1 = cpu_to_hc32(ehci, info1);
948 hw->hw_info2 = cpu_to_hc32(ehci, info2); 948 hw->hw_info2 = cpu_to_hc32(ehci, info2);
949 qh->is_out = !is_input;
949 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1); 950 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1);
950 qh_refresh (ehci, qh); 951 qh_refresh (ehci, qh);
951 return qh; 952 return qh;
@@ -1231,6 +1232,8 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1231 1232
1232 prev->hw->hw_next = qh->hw->hw_next; 1233 prev->hw->hw_next = qh->hw->hw_next;
1233 prev->qh_next = qh->qh_next; 1234 prev->qh_next = qh->qh_next;
1235 if (ehci->qh_scan_next == qh)
1236 ehci->qh_scan_next = qh->qh_next.qh;
1234 wmb (); 1237 wmb ();
1235 1238
1236 /* If the controller isn't running, we don't have to wait for it */ 1239 /* If the controller isn't running, we don't have to wait for it */
@@ -1256,53 +1259,49 @@ static void scan_async (struct ehci_hcd *ehci)
1256 struct ehci_qh *qh; 1259 struct ehci_qh *qh;
1257 enum ehci_timer_action action = TIMER_IO_WATCHDOG; 1260 enum ehci_timer_action action = TIMER_IO_WATCHDOG;
1258 1261
1259 ehci->stamp = ehci_readl(ehci, &ehci->regs->frame_index);
1260 timer_action_done (ehci, TIMER_ASYNC_SHRINK); 1262 timer_action_done (ehci, TIMER_ASYNC_SHRINK);
1261rescan:
1262 stopped = !HC_IS_RUNNING(ehci_to_hcd(ehci)->state); 1263 stopped = !HC_IS_RUNNING(ehci_to_hcd(ehci)->state);
1263 qh = ehci->async->qh_next.qh;
1264 if (likely (qh != NULL)) {
1265 do {
1266 /* clean any finished work for this qh */
1267 if (!list_empty(&qh->qtd_list) && (stopped ||
1268 qh->stamp != ehci->stamp)) {
1269 int temp;
1270
1271 /* unlinks could happen here; completion
1272 * reporting drops the lock. rescan using
1273 * the latest schedule, but don't rescan
1274 * qhs we already finished (no looping)
1275 * unless the controller is stopped.
1276 */
1277 qh = qh_get (qh);
1278 qh->stamp = ehci->stamp;
1279 temp = qh_completions (ehci, qh);
1280 if (qh->needs_rescan)
1281 unlink_async(ehci, qh);
1282 qh_put (qh);
1283 if (temp != 0) {
1284 goto rescan;
1285 }
1286 }
1287 1264
1288 /* unlink idle entries, reducing DMA usage as well 1265 ehci->qh_scan_next = ehci->async->qh_next.qh;
1289 * as HCD schedule-scanning costs. delay for any qh 1266 while (ehci->qh_scan_next) {
1290 * we just scanned, there's a not-unusual case that it 1267 qh = ehci->qh_scan_next;
1291 * doesn't stay idle for long. 1268 ehci->qh_scan_next = qh->qh_next.qh;
1292 * (plus, avoids some kind of re-activation race.) 1269 rescan:
1270 /* clean any finished work for this qh */
1271 if (!list_empty(&qh->qtd_list)) {
1272 int temp;
1273
1274 /*
1275 * Unlinks could happen here; completion reporting
1276 * drops the lock. That's why ehci->qh_scan_next
1277 * always holds the next qh to scan; if the next qh
1278 * gets unlinked then ehci->qh_scan_next is adjusted
1279 * in start_unlink_async().
1293 */ 1280 */
1294 if (list_empty(&qh->qtd_list) 1281 qh = qh_get(qh);
1295 && qh->qh_state == QH_STATE_LINKED) { 1282 temp = qh_completions(ehci, qh);
1296 if (!ehci->reclaim && (stopped || 1283 if (qh->needs_rescan)
1297 ((ehci->stamp - qh->stamp) & 0x1fff) 1284 unlink_async(ehci, qh);
1298 >= EHCI_SHRINK_FRAMES * 8)) 1285 qh->unlink_time = jiffies + EHCI_SHRINK_JIFFIES;
1299 start_unlink_async(ehci, qh); 1286 qh_put(qh);
1300 else 1287 if (temp != 0)
1301 action = TIMER_ASYNC_SHRINK; 1288 goto rescan;
1302 } 1289 }
1303 1290
1304 qh = qh->qh_next.qh; 1291 /* unlink idle entries, reducing DMA usage as well
1305 } while (qh); 1292 * as HCD schedule-scanning costs. delay for any qh
1293 * we just scanned, there's a not-unusual case that it
1294 * doesn't stay idle for long.
1295 * (plus, avoids some kind of re-activation race.)
1296 */
1297 if (list_empty(&qh->qtd_list)
1298 && qh->qh_state == QH_STATE_LINKED) {
1299 if (!ehci->reclaim && (stopped ||
1300 time_after_eq(jiffies, qh->unlink_time)))
1301 start_unlink_async(ehci, qh);
1302 else
1303 action = TIMER_ASYNC_SHRINK;
1304 }
1306 } 1305 }
1307 if (action == TIMER_ASYNC_SHRINK) 1306 if (action == TIMER_ASYNC_SHRINK)
1308 timer_action (ehci, TIMER_ASYNC_SHRINK); 1307 timer_action (ehci, TIMER_ASYNC_SHRINK);
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
index e3374c8f7b3f..b3958b3d3163 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-s5p.c
@@ -189,6 +189,100 @@ static void s5p_ehci_shutdown(struct platform_device *pdev)
189 hcd->driver->shutdown(hcd); 189 hcd->driver->shutdown(hcd);
190} 190}
191 191
192#ifdef CONFIG_PM
193static int s5p_ehci_suspend(struct device *dev)
194{
195 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
196 struct usb_hcd *hcd = s5p_ehci->hcd;
197 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
198 struct platform_device *pdev = to_platform_device(dev);
199 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
200 unsigned long flags;
201 int rc = 0;
202
203 if (time_before(jiffies, ehci->next_statechange))
204 msleep(20);
205
206 /*
207 * Root hub was already suspended. Disable irq emission and
208 * mark HW unaccessible. The PM and USB cores make sure that
209 * the root hub is either suspended or stopped.
210 */
211 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
212 spin_lock_irqsave(&ehci->lock, flags);
213 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
214 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
215
216 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
217 spin_unlock_irqrestore(&ehci->lock, flags);
218
219 if (pdata && pdata->phy_exit)
220 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
221
222 return rc;
223}
224
225static int s5p_ehci_resume(struct device *dev)
226{
227 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
228 struct usb_hcd *hcd = s5p_ehci->hcd;
229 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
230 struct platform_device *pdev = to_platform_device(dev);
231 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
232
233 if (pdata && pdata->phy_init)
234 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
235
236 if (time_before(jiffies, ehci->next_statechange))
237 msleep(100);
238
239 /* Mark hardware accessible again as we are out of D3 state by now */
240 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
241
242 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
243 int mask = INTR_MASK;
244
245 ehci_prepare_ports_for_controller_resume(ehci);
246 if (!hcd->self.root_hub->do_remote_wakeup)
247 mask &= ~STS_PCD;
248 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
249 ehci_readl(ehci, &ehci->regs->intr_enable);
250 return 0;
251 }
252
253 usb_root_hub_lost_power(hcd->self.root_hub);
254
255 (void) ehci_halt(ehci);
256 (void) ehci_reset(ehci);
257
258 /* emptying the schedule aborts any urbs */
259 spin_lock_irq(&ehci->lock);
260 if (ehci->reclaim)
261 end_unlink_async(ehci);
262 ehci_work(ehci);
263 spin_unlock_irq(&ehci->lock);
264
265 ehci_writel(ehci, ehci->command, &ehci->regs->command);
266 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
267 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
268
269 /* here we "know" root ports should always stay powered */
270 ehci_port_power(ehci, 1);
271
272 hcd->state = HC_STATE_SUSPENDED;
273
274 return 0;
275}
276#else
277#define s5p_ehci_suspend NULL
278#define s5p_ehci_resume NULL
279#endif
280
281static const struct dev_pm_ops s5p_ehci_pm_ops = {
282 .suspend = s5p_ehci_suspend,
283 .resume = s5p_ehci_resume,
284};
285
192static struct platform_driver s5p_ehci_driver = { 286static struct platform_driver s5p_ehci_driver = {
193 .probe = s5p_ehci_probe, 287 .probe = s5p_ehci_probe,
194 .remove = __devexit_p(s5p_ehci_remove), 288 .remove = __devexit_p(s5p_ehci_remove),
@@ -196,6 +290,7 @@ static struct platform_driver s5p_ehci_driver = {
196 .driver = { 290 .driver = {
197 .name = "s5p-ehci", 291 .name = "s5p-ehci",
198 .owner = THIS_MODULE, 292 .owner = THIS_MODULE,
293 .pm = &s5p_ehci_pm_ops,
199 } 294 }
200}; 295};
201 296
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 6c9fbe352f73..2abf8543f083 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -172,7 +172,7 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe)
172 } 172 }
173 } 173 }
174#ifdef DEBUG 174#ifdef DEBUG
175 if (usecs > 100) 175 if (usecs > ehci->uframe_periodic_max)
176 ehci_err (ehci, "uframe %d sched overrun: %d usecs\n", 176 ehci_err (ehci, "uframe %d sched overrun: %d usecs\n",
177 frame * 8 + uframe, usecs); 177 frame * 8 + uframe, usecs);
178#endif 178#endif
@@ -709,11 +709,8 @@ static int check_period (
709 if (uframe >= 8) 709 if (uframe >= 8)
710 return 0; 710 return 0;
711 711
712 /* 712 /* convert "usecs we need" to "max already claimed" */
713 * 80% periodic == 100 usec/uframe available 713 usecs = ehci->uframe_periodic_max - usecs;
714 * convert "usecs we need" to "max already claimed"
715 */
716 usecs = 100 - usecs;
717 714
718 /* we "know" 2 and 4 uframe intervals were rejected; so 715 /* we "know" 2 and 4 uframe intervals were rejected; so
719 * for period 0, check _every_ microframe in the schedule. 716 * for period 0, check _every_ microframe in the schedule.
@@ -1286,9 +1283,9 @@ itd_slot_ok (
1286{ 1283{
1287 uframe %= period; 1284 uframe %= period;
1288 do { 1285 do {
1289 /* can't commit more than 80% periodic == 100 usec */ 1286 /* can't commit more than uframe_periodic_max usec */
1290 if (periodic_usecs (ehci, uframe >> 3, uframe & 0x7) 1287 if (periodic_usecs (ehci, uframe >> 3, uframe & 0x7)
1291 > (100 - usecs)) 1288 > (ehci->uframe_periodic_max - usecs))
1292 return 0; 1289 return 0;
1293 1290
1294 /* we know urb->interval is 2^N uframes */ 1291 /* we know urb->interval is 2^N uframes */
@@ -1345,7 +1342,7 @@ sitd_slot_ok (
1345#endif 1342#endif
1346 1343
1347 /* check starts (OUT uses more than one) */ 1344 /* check starts (OUT uses more than one) */
1348 max_used = 100 - stream->usecs; 1345 max_used = ehci->uframe_periodic_max - stream->usecs;
1349 for (tmp = stream->raw_mask & 0xff; tmp; tmp >>= 1, uf++) { 1346 for (tmp = stream->raw_mask & 0xff; tmp; tmp >>= 1, uf++) {
1350 if (periodic_usecs (ehci, frame, uf) > max_used) 1347 if (periodic_usecs (ehci, frame, uf) > max_used)
1351 return 0; 1348 return 0;
@@ -1354,7 +1351,7 @@ sitd_slot_ok (
1354 /* for IN, check CSPLIT */ 1351 /* for IN, check CSPLIT */
1355 if (stream->c_usecs) { 1352 if (stream->c_usecs) {
1356 uf = uframe & 7; 1353 uf = uframe & 7;
1357 max_used = 100 - stream->c_usecs; 1354 max_used = ehci->uframe_periodic_max - stream->c_usecs;
1358 do { 1355 do {
1359 tmp = 1 << uf; 1356 tmp = 1 << uf;
1360 tmp <<= 8; 1357 tmp <<= 8;
diff --git a/drivers/usb/host/ehci-sysfs.c b/drivers/usb/host/ehci-sysfs.c
new file mode 100644
index 000000000000..14ced00ba220
--- /dev/null
+++ b/drivers/usb/host/ehci-sysfs.c
@@ -0,0 +1,190 @@
1/*
2 * Copyright (C) 2007 by Alan Stern
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* this file is part of ehci-hcd.c */
20
21
22/* Display the ports dedicated to the companion controller */
23static ssize_t show_companion(struct device *dev,
24 struct device_attribute *attr,
25 char *buf)
26{
27 struct ehci_hcd *ehci;
28 int nports, index, n;
29 int count = PAGE_SIZE;
30 char *ptr = buf;
31
32 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
33 nports = HCS_N_PORTS(ehci->hcs_params);
34
35 for (index = 0; index < nports; ++index) {
36 if (test_bit(index, &ehci->companion_ports)) {
37 n = scnprintf(ptr, count, "%d\n", index + 1);
38 ptr += n;
39 count -= n;
40 }
41 }
42 return ptr - buf;
43}
44
45/*
46 * Dedicate or undedicate a port to the companion controller.
47 * Syntax is "[-]portnum", where a leading '-' sign means
48 * return control of the port to the EHCI controller.
49 */
50static ssize_t store_companion(struct device *dev,
51 struct device_attribute *attr,
52 const char *buf, size_t count)
53{
54 struct ehci_hcd *ehci;
55 int portnum, new_owner;
56
57 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
58 new_owner = PORT_OWNER; /* Owned by companion */
59 if (sscanf(buf, "%d", &portnum) != 1)
60 return -EINVAL;
61 if (portnum < 0) {
62 portnum = - portnum;
63 new_owner = 0; /* Owned by EHCI */
64 }
65 if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
66 return -ENOENT;
67 portnum--;
68 if (new_owner)
69 set_bit(portnum, &ehci->companion_ports);
70 else
71 clear_bit(portnum, &ehci->companion_ports);
72 set_owner(ehci, portnum, new_owner);
73 return count;
74}
75static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
76
77
78/*
79 * Display / Set uframe_periodic_max
80 */
81static ssize_t show_uframe_periodic_max(struct device *dev,
82 struct device_attribute *attr,
83 char *buf)
84{
85 struct ehci_hcd *ehci;
86 int n;
87
88 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
89 n = scnprintf(buf, PAGE_SIZE, "%d\n", ehci->uframe_periodic_max);
90 return n;
91}
92
93
94static ssize_t store_uframe_periodic_max(struct device *dev,
95 struct device_attribute *attr,
96 const char *buf, size_t count)
97{
98 struct ehci_hcd *ehci;
99 unsigned uframe_periodic_max;
100 unsigned frame, uframe;
101 unsigned short allocated_max;
102 unsigned long flags;
103 ssize_t ret;
104
105 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
106 if (kstrtouint(buf, 0, &uframe_periodic_max) < 0)
107 return -EINVAL;
108
109 if (uframe_periodic_max < 100 || uframe_periodic_max >= 125) {
110 ehci_info(ehci, "rejecting invalid request for "
111 "uframe_periodic_max=%u\n", uframe_periodic_max);
112 return -EINVAL;
113 }
114
115 ret = -EINVAL;
116
117 /*
118 * lock, so that our checking does not race with possible periodic
119 * bandwidth allocation through submitting new urbs.
120 */
121 spin_lock_irqsave (&ehci->lock, flags);
122
123 /*
124 * for request to decrease max periodic bandwidth, we have to check
125 * every microframe in the schedule to see whether the decrease is
126 * possible.
127 */
128 if (uframe_periodic_max < ehci->uframe_periodic_max) {
129 allocated_max = 0;
130
131 for (frame = 0; frame < ehci->periodic_size; ++frame)
132 for (uframe = 0; uframe < 7; ++uframe)
133 allocated_max = max(allocated_max,
134 periodic_usecs (ehci, frame, uframe));
135
136 if (allocated_max > uframe_periodic_max) {
137 ehci_info(ehci,
138 "cannot decrease uframe_periodic_max becase "
139 "periodic bandwidth is already allocated "
140 "(%u > %u)\n",
141 allocated_max, uframe_periodic_max);
142 goto out_unlock;
143 }
144 }
145
146 /* increasing is always ok */
147
148 ehci_info(ehci, "setting max periodic bandwidth to %u%% "
149 "(== %u usec/uframe)\n",
150 100*uframe_periodic_max/125, uframe_periodic_max);
151
152 if (uframe_periodic_max != 100)
153 ehci_warn(ehci, "max periodic bandwidth set is non-standard\n");
154
155 ehci->uframe_periodic_max = uframe_periodic_max;
156 ret = count;
157
158out_unlock:
159 spin_unlock_irqrestore (&ehci->lock, flags);
160 return ret;
161}
162static DEVICE_ATTR(uframe_periodic_max, 0644, show_uframe_periodic_max, store_uframe_periodic_max);
163
164
165static inline int create_sysfs_files(struct ehci_hcd *ehci)
166{
167 struct device *controller = ehci_to_hcd(ehci)->self.controller;
168 int i = 0;
169
170 /* with integrated TT there is no companion! */
171 if (!ehci_is_TDI(ehci))
172 i = device_create_file(controller, &dev_attr_companion);
173 if (i)
174 goto out;
175
176 i = device_create_file(controller, &dev_attr_uframe_periodic_max);
177out:
178 return i;
179}
180
181static inline void remove_sysfs_files(struct ehci_hcd *ehci)
182{
183 struct device *controller = ehci_to_hcd(ehci)->self.controller;
184
185 /* with integrated TT there is no companion! */
186 if (!ehci_is_TDI(ehci))
187 device_remove_file(controller, &dev_attr_companion);
188
189 device_remove_file(controller, &dev_attr_uframe_periodic_max);
190}
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index bd6ff489baf9..cc7d337ec355 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -75,6 +75,7 @@ struct ehci_hcd { /* one per controller */
75 struct ehci_qh *async; 75 struct ehci_qh *async;
76 struct ehci_qh *dummy; /* For AMD quirk use */ 76 struct ehci_qh *dummy; /* For AMD quirk use */
77 struct ehci_qh *reclaim; 77 struct ehci_qh *reclaim;
78 struct ehci_qh *qh_scan_next;
78 unsigned scanning : 1; 79 unsigned scanning : 1;
79 80
80 /* periodic schedule support */ 81 /* periodic schedule support */
@@ -87,6 +88,8 @@ struct ehci_hcd { /* one per controller */
87 union ehci_shadow *pshadow; /* mirror hw periodic table */ 88 union ehci_shadow *pshadow; /* mirror hw periodic table */
88 int next_uframe; /* scan periodic, start here */ 89 int next_uframe; /* scan periodic, start here */
89 unsigned periodic_sched; /* periodic activity count */ 90 unsigned periodic_sched; /* periodic activity count */
91 unsigned uframe_periodic_max; /* max periodic time per uframe */
92
90 93
91 /* list of itds & sitds completed while clock_frame was still active */ 94 /* list of itds & sitds completed while clock_frame was still active */
92 struct list_head cached_itd_list; 95 struct list_head cached_itd_list;
@@ -117,7 +120,6 @@ struct ehci_hcd { /* one per controller */
117 struct timer_list iaa_watchdog; 120 struct timer_list iaa_watchdog;
118 struct timer_list watchdog; 121 struct timer_list watchdog;
119 unsigned long actions; 122 unsigned long actions;
120 unsigned stamp;
121 unsigned periodic_stamp; 123 unsigned periodic_stamp;
122 unsigned random_frame; 124 unsigned random_frame;
123 unsigned long next_statechange; 125 unsigned long next_statechange;
@@ -343,6 +345,7 @@ struct ehci_qh {
343 struct ehci_qh *reclaim; /* next to reclaim */ 345 struct ehci_qh *reclaim; /* next to reclaim */
344 346
345 struct ehci_hcd *ehci; 347 struct ehci_hcd *ehci;
348 unsigned long unlink_time;
346 349
347 /* 350 /*
348 * Do NOT use atomic operations for QH refcounting. On some CPUs 351 * Do NOT use atomic operations for QH refcounting. On some CPUs
@@ -374,6 +377,7 @@ struct ehci_qh {
374#define NO_FRAME ((unsigned short)~0) /* pick new start */ 377#define NO_FRAME ((unsigned short)~0) /* pick new start */
375 378
376 struct usb_device *dev; /* access to TT */ 379 struct usb_device *dev; /* access to TT */
380 unsigned is_out:1; /* bulk or intr OUT */
377 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ 381 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
378}; 382};
379 383
diff --git a/drivers/usb/host/ohci-sh.c b/drivers/usb/host/ohci-sh.c
index f47867ff78c7..14cecb52a9fe 100644
--- a/drivers/usb/host/ohci-sh.c
+++ b/drivers/usb/host/ohci-sh.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2008 Renesas Solutions Corp. 4 * Copyright (C) 2008 Renesas Solutions Corp.
5 * 5 *
6 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> 6 * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.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
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index fd930618c28f..a9d315906e3d 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -35,6 +35,8 @@
35#define OHCI_INTRSTATUS 0x0c 35#define OHCI_INTRSTATUS 0x0c
36#define OHCI_INTRENABLE 0x10 36#define OHCI_INTRENABLE 0x10
37#define OHCI_INTRDISABLE 0x14 37#define OHCI_INTRDISABLE 0x14
38#define OHCI_FMINTERVAL 0x34
39#define OHCI_HCR (1 << 0) /* host controller reset */
38#define OHCI_OCR (1 << 3) /* ownership change request */ 40#define OHCI_OCR (1 << 3) /* ownership change request */
39#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */ 41#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
40#define OHCI_CTRL_IR (1 << 8) /* interrupt routing */ 42#define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
@@ -497,6 +499,32 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
497 499
498 /* reset controller, preserving RWC (and possibly IR) */ 500 /* reset controller, preserving RWC (and possibly IR) */
499 writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL); 501 writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL);
502 readl(base + OHCI_CONTROL);
503
504 /* Some NVIDIA controllers stop working if kept in RESET for too long */
505 if (pdev->vendor == PCI_VENDOR_ID_NVIDIA) {
506 u32 fminterval;
507 int cnt;
508
509 /* drive reset for at least 50 ms (7.1.7.5) */
510 msleep(50);
511
512 /* software reset of the controller, preserving HcFmInterval */
513 fminterval = readl(base + OHCI_FMINTERVAL);
514 writel(OHCI_HCR, base + OHCI_CMDSTATUS);
515
516 /* reset requires max 10 us delay */
517 for (cnt = 30; cnt > 0; --cnt) { /* ... allow extra time */
518 if ((readl(base + OHCI_CMDSTATUS) & OHCI_HCR) == 0)
519 break;
520 udelay(1);
521 }
522 writel(fminterval, base + OHCI_FMINTERVAL);
523
524 /* Now we're in the SUSPEND state with all devices reset
525 * and wakeups and interrupts disabled
526 */
527 }
500 528
501 /* 529 /*
502 * disable interrupts 530 * disable interrupts
@@ -507,20 +535,34 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
507 iounmap(base); 535 iounmap(base);
508} 536}
509 537
538static const struct dmi_system_id __initconst ehci_dmi_nohandoff_table[] = {
539 {
540 /* Pegatron Lucid (ExoPC) */
541 .matches = {
542 DMI_MATCH(DMI_BOARD_NAME, "EXOPG06411"),
543 DMI_MATCH(DMI_BIOS_VERSION, "Lucid-CE-133"),
544 },
545 },
546 {
547 /* Pegatron Lucid (Ordissimo AIRIS) */
548 .matches = {
549 DMI_MATCH(DMI_BOARD_NAME, "M11JB"),
550 DMI_MATCH(DMI_BIOS_VERSION, "Lucid-GE-133"),
551 },
552 },
553 { }
554};
555
510static void __devinit ehci_bios_handoff(struct pci_dev *pdev, 556static void __devinit ehci_bios_handoff(struct pci_dev *pdev,
511 void __iomem *op_reg_base, 557 void __iomem *op_reg_base,
512 u32 cap, u8 offset) 558 u32 cap, u8 offset)
513{ 559{
514 int try_handoff = 1, tried_handoff = 0; 560 int try_handoff = 1, tried_handoff = 0;
515 561
516 /* The Pegatron Lucid (ExoPC) tablet sporadically waits for 90 562 /* The Pegatron Lucid tablet sporadically waits for 98 seconds trying
517 * seconds trying the handoff on its unused controller. Skip 563 * the handoff on its unused controller. Skip it. */
518 * it. */
519 if (pdev->vendor == 0x8086 && pdev->device == 0x283a) { 564 if (pdev->vendor == 0x8086 && pdev->device == 0x283a) {
520 const char *dmi_bn = dmi_get_system_info(DMI_BOARD_NAME); 565 if (dmi_check_system(ehci_dmi_nohandoff_table))
521 const char *dmi_bv = dmi_get_system_info(DMI_BIOS_VERSION);
522 if (dmi_bn && !strcmp(dmi_bn, "EXOPG06411") &&
523 dmi_bv && !strcmp(dmi_bv, "Lucid-CE-133"))
524 try_handoff = 0; 566 try_handoff = 0;
525 } 567 }
526 568
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 4586369dda00..40a0d8b03ad7 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -6,7 +6,7 @@
6 * Portions Copyright (C) 2004-2005 David Brownell 6 * Portions Copyright (C) 2004-2005 David Brownell
7 * Portions Copyright (C) 1999 Roman Weissgaerber 7 * Portions Copyright (C) 1999 Roman Weissgaerber
8 * 8 *
9 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> 9 * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
@@ -1438,7 +1438,7 @@ static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
1438 if (pipenum > 0) 1438 if (pipenum > 0)
1439 r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS); 1439 r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS);
1440 if (urb->transfer_buffer) { 1440 if (urb->transfer_buffer) {
1441 r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size); 1441 r8a66597_write_fifo(r8a66597, td->pipe, buf, size);
1442 if (!usb_pipebulk(urb->pipe) || td->maxpacket != size) 1442 if (!usb_pipebulk(urb->pipe) || td->maxpacket != size)
1443 r8a66597_write(r8a66597, BVAL, td->pipe->fifoctr); 1443 r8a66597_write(r8a66597, BVAL, td->pipe->fifoctr);
1444 } 1444 }
@@ -2306,7 +2306,7 @@ static int r8a66597_bus_resume(struct usb_hcd *hcd)
2306 2306
2307 dbg("resume port = %d", port); 2307 dbg("resume port = %d", port);
2308 rh->port &= ~USB_PORT_STAT_SUSPEND; 2308 rh->port &= ~USB_PORT_STAT_SUSPEND;
2309 rh->port |= USB_PORT_STAT_C_SUSPEND < 16; 2309 rh->port |= USB_PORT_STAT_C_SUSPEND << 16;
2310 r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg); 2310 r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg);
2311 msleep(50); 2311 msleep(50);
2312 r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg); 2312 r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg);
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h
index 25563e9a90bc..f28782d20eef 100644
--- a/drivers/usb/host/r8a66597.h
+++ b/drivers/usb/host/r8a66597.h
@@ -201,11 +201,26 @@ static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val,
201 iowrite16(val, r8a66597->reg + offset); 201 iowrite16(val, r8a66597->reg + offset);
202} 202}
203 203
204static inline void r8a66597_mdfy(struct r8a66597 *r8a66597,
205 u16 val, u16 pat, unsigned long offset)
206{
207 u16 tmp;
208 tmp = r8a66597_read(r8a66597, offset);
209 tmp = tmp & (~pat);
210 tmp = tmp | val;
211 r8a66597_write(r8a66597, tmp, offset);
212}
213
214#define r8a66597_bclr(r8a66597, val, offset) \
215 r8a66597_mdfy(r8a66597, 0, val, offset)
216#define r8a66597_bset(r8a66597, val, offset) \
217 r8a66597_mdfy(r8a66597, val, 0, offset)
218
204static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597, 219static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
205 unsigned long offset, u16 *buf, 220 struct r8a66597_pipe *pipe, u16 *buf,
206 int len) 221 int len)
207{ 222{
208 void __iomem *fifoaddr = r8a66597->reg + offset; 223 void __iomem *fifoaddr = r8a66597->reg + pipe->fifoaddr;
209 unsigned long count; 224 unsigned long count;
210 unsigned char *pb; 225 unsigned char *pb;
211 int i; 226 int i;
@@ -230,26 +245,15 @@ static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
230 iowrite16_rep(fifoaddr, buf, len); 245 iowrite16_rep(fifoaddr, buf, len);
231 if (unlikely(odd)) { 246 if (unlikely(odd)) {
232 buf = &buf[len]; 247 buf = &buf[len];
248 if (r8a66597->pdata->wr0_shorted_to_wr1)
249 r8a66597_bclr(r8a66597, MBW_16, pipe->fifosel);
233 iowrite8((unsigned char)*buf, fifoaddr); 250 iowrite8((unsigned char)*buf, fifoaddr);
251 if (r8a66597->pdata->wr0_shorted_to_wr1)
252 r8a66597_bset(r8a66597, MBW_16, pipe->fifosel);
234 } 253 }
235 } 254 }
236} 255}
237 256
238static inline void r8a66597_mdfy(struct r8a66597 *r8a66597,
239 u16 val, u16 pat, unsigned long offset)
240{
241 u16 tmp;
242 tmp = r8a66597_read(r8a66597, offset);
243 tmp = tmp & (~pat);
244 tmp = tmp | val;
245 r8a66597_write(r8a66597, tmp, offset);
246}
247
248#define r8a66597_bclr(r8a66597, val, offset) \
249 r8a66597_mdfy(r8a66597, 0, val, offset)
250#define r8a66597_bset(r8a66597, val, offset) \
251 r8a66597_mdfy(r8a66597, val, 0, offset)
252
253static inline unsigned long get_syscfg_reg(int port) 257static inline unsigned long get_syscfg_reg(int port)
254{ 258{
255 return port == 0 ? SYSCFG0 : SYSCFG1; 259 return port == 0 ? SYSCFG0 : SYSCFG1;
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index 1f50b4468e87..e9b0f043455d 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -266,11 +266,11 @@ void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
266 xhci_dbg(xhci, "Interrupter target = 0x%x\n", 266 xhci_dbg(xhci, "Interrupter target = 0x%x\n",
267 GET_INTR_TARGET(le32_to_cpu(trb->link.intr_target))); 267 GET_INTR_TARGET(le32_to_cpu(trb->link.intr_target)));
268 xhci_dbg(xhci, "Cycle bit = %u\n", 268 xhci_dbg(xhci, "Cycle bit = %u\n",
269 (unsigned int) (le32_to_cpu(trb->link.control) & TRB_CYCLE)); 269 le32_to_cpu(trb->link.control) & TRB_CYCLE);
270 xhci_dbg(xhci, "Toggle cycle bit = %u\n", 270 xhci_dbg(xhci, "Toggle cycle bit = %u\n",
271 (unsigned int) (le32_to_cpu(trb->link.control) & LINK_TOGGLE)); 271 le32_to_cpu(trb->link.control) & LINK_TOGGLE);
272 xhci_dbg(xhci, "No Snoop bit = %u\n", 272 xhci_dbg(xhci, "No Snoop bit = %u\n",
273 (unsigned int) (le32_to_cpu(trb->link.control) & TRB_NO_SNOOP)); 273 le32_to_cpu(trb->link.control) & TRB_NO_SNOOP);
274 break; 274 break;
275 case TRB_TYPE(TRB_TRANSFER): 275 case TRB_TYPE(TRB_TRANSFER):
276 address = le64_to_cpu(trb->trans_event.buffer); 276 address = le64_to_cpu(trb->trans_event.buffer);
@@ -284,9 +284,9 @@ void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
284 address = le64_to_cpu(trb->event_cmd.cmd_trb); 284 address = le64_to_cpu(trb->event_cmd.cmd_trb);
285 xhci_dbg(xhci, "Command TRB pointer = %llu\n", address); 285 xhci_dbg(xhci, "Command TRB pointer = %llu\n", address);
286 xhci_dbg(xhci, "Completion status = %u\n", 286 xhci_dbg(xhci, "Completion status = %u\n",
287 (unsigned int) GET_COMP_CODE(le32_to_cpu(trb->event_cmd.status))); 287 GET_COMP_CODE(le32_to_cpu(trb->event_cmd.status)));
288 xhci_dbg(xhci, "Flags = 0x%x\n", 288 xhci_dbg(xhci, "Flags = 0x%x\n",
289 (unsigned int) le32_to_cpu(trb->event_cmd.flags)); 289 le32_to_cpu(trb->event_cmd.flags));
290 break; 290 break;
291 default: 291 default:
292 xhci_dbg(xhci, "Unknown TRB with TRB type ID %u\n", 292 xhci_dbg(xhci, "Unknown TRB with TRB type ID %u\n",
@@ -318,10 +318,10 @@ void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg)
318 for (i = 0; i < TRBS_PER_SEGMENT; ++i) { 318 for (i = 0; i < TRBS_PER_SEGMENT; ++i) {
319 trb = &seg->trbs[i]; 319 trb = &seg->trbs[i];
320 xhci_dbg(xhci, "@%016llx %08x %08x %08x %08x\n", addr, 320 xhci_dbg(xhci, "@%016llx %08x %08x %08x %08x\n", addr,
321 (u32)lower_32_bits(le64_to_cpu(trb->link.segment_ptr)), 321 lower_32_bits(le64_to_cpu(trb->link.segment_ptr)),
322 (u32)upper_32_bits(le64_to_cpu(trb->link.segment_ptr)), 322 upper_32_bits(le64_to_cpu(trb->link.segment_ptr)),
323 (unsigned int) le32_to_cpu(trb->link.intr_target), 323 le32_to_cpu(trb->link.intr_target),
324 (unsigned int) le32_to_cpu(trb->link.control)); 324 le32_to_cpu(trb->link.control));
325 addr += sizeof(*trb); 325 addr += sizeof(*trb);
326 } 326 }
327} 327}
@@ -402,8 +402,8 @@ void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
402 addr, 402 addr,
403 lower_32_bits(le64_to_cpu(entry->seg_addr)), 403 lower_32_bits(le64_to_cpu(entry->seg_addr)),
404 upper_32_bits(le64_to_cpu(entry->seg_addr)), 404 upper_32_bits(le64_to_cpu(entry->seg_addr)),
405 (unsigned int) le32_to_cpu(entry->seg_size), 405 le32_to_cpu(entry->seg_size),
406 (unsigned int) le32_to_cpu(entry->rsvd)); 406 le32_to_cpu(entry->rsvd));
407 addr += sizeof(*entry); 407 addr += sizeof(*entry);
408 } 408 }
409} 409}
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index fcb7f7efc86d..d446886b22b0 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -89,8 +89,8 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev,
89 return; 89 return;
90 prev->next = next; 90 prev->next = next;
91 if (link_trbs) { 91 if (link_trbs) {
92 prev->trbs[TRBS_PER_SEGMENT-1].link. 92 prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr =
93 segment_ptr = cpu_to_le64(next->dma); 93 cpu_to_le64(next->dma);
94 94
95 /* Set the last TRB in the segment to have a TRB type ID of Link TRB */ 95 /* Set the last TRB in the segment to have a TRB type ID of Link TRB */
96 val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control); 96 val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control);
@@ -187,8 +187,8 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
187 187
188 if (link_trbs) { 188 if (link_trbs) {
189 /* See section 4.9.2.1 and 6.4.4.1 */ 189 /* See section 4.9.2.1 and 6.4.4.1 */
190 prev->trbs[TRBS_PER_SEGMENT-1].link. 190 prev->trbs[TRBS_PER_SEGMENT-1].link.control |=
191 control |= cpu_to_le32(LINK_TOGGLE); 191 cpu_to_le32(LINK_TOGGLE);
192 xhci_dbg(xhci, "Wrote link toggle flag to" 192 xhci_dbg(xhci, "Wrote link toggle flag to"
193 " segment %p (virtual), 0x%llx (DMA)\n", 193 " segment %p (virtual), 0x%llx (DMA)\n",
194 prev, (unsigned long long)prev->dma); 194 prev, (unsigned long long)prev->dma);
@@ -549,8 +549,8 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
549 addr = cur_ring->first_seg->dma | 549 addr = cur_ring->first_seg->dma |
550 SCT_FOR_CTX(SCT_PRI_TR) | 550 SCT_FOR_CTX(SCT_PRI_TR) |
551 cur_ring->cycle_state; 551 cur_ring->cycle_state;
552 stream_info->stream_ctx_array[cur_stream]. 552 stream_info->stream_ctx_array[cur_stream].stream_ring =
553 stream_ring = cpu_to_le64(addr); 553 cpu_to_le64(addr);
554 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", 554 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n",
555 cur_stream, (unsigned long long) addr); 555 cur_stream, (unsigned long long) addr);
556 556
@@ -786,7 +786,7 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
786 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n", 786 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n",
787 slot_id, 787 slot_id,
788 &xhci->dcbaa->dev_context_ptrs[slot_id], 788 &xhci->dcbaa->dev_context_ptrs[slot_id],
789 (unsigned long long) le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id])); 789 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id]));
790 790
791 return 1; 791 return 1;
792fail: 792fail:
@@ -890,19 +890,19 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
890 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); 890 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG);
891 891
892 /* 3) Only the control endpoint is valid - one endpoint context */ 892 /* 3) Only the control endpoint is valid - one endpoint context */
893 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | (u32) udev->route); 893 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route);
894 switch (udev->speed) { 894 switch (udev->speed) {
895 case USB_SPEED_SUPER: 895 case USB_SPEED_SUPER:
896 slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_SS); 896 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS);
897 break; 897 break;
898 case USB_SPEED_HIGH: 898 case USB_SPEED_HIGH:
899 slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_HS); 899 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS);
900 break; 900 break;
901 case USB_SPEED_FULL: 901 case USB_SPEED_FULL:
902 slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_FS); 902 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS);
903 break; 903 break;
904 case USB_SPEED_LOW: 904 case USB_SPEED_LOW:
905 slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_LS); 905 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS);
906 break; 906 break;
907 case USB_SPEED_WIRELESS: 907 case USB_SPEED_WIRELESS:
908 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); 908 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
@@ -916,7 +916,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
916 port_num = xhci_find_real_port_number(xhci, udev); 916 port_num = xhci_find_real_port_number(xhci, udev);
917 if (!port_num) 917 if (!port_num)
918 return -EINVAL; 918 return -EINVAL;
919 slot_ctx->dev_info2 |= cpu_to_le32((u32) ROOT_HUB_PORT(port_num)); 919 slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(port_num));
920 /* Set the port number in the virtual_device to the faked port number */ 920 /* Set the port number in the virtual_device to the faked port number */
921 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; 921 for (top_dev = udev; top_dev->parent && top_dev->parent->parent;
922 top_dev = top_dev->parent) 922 top_dev = top_dev->parent)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 70cacbbe7fb9..7113d16e2d3a 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -113,15 +113,13 @@ static int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
113 if (ring == xhci->event_ring) 113 if (ring == xhci->event_ring)
114 return trb == &seg->trbs[TRBS_PER_SEGMENT]; 114 return trb == &seg->trbs[TRBS_PER_SEGMENT];
115 else 115 else
116 return (le32_to_cpu(trb->link.control) & TRB_TYPE_BITMASK) 116 return TRB_TYPE_LINK_LE32(trb->link.control);
117 == TRB_TYPE(TRB_LINK);
118} 117}
119 118
120static int enqueue_is_link_trb(struct xhci_ring *ring) 119static int enqueue_is_link_trb(struct xhci_ring *ring)
121{ 120{
122 struct xhci_link_trb *link = &ring->enqueue->link; 121 struct xhci_link_trb *link = &ring->enqueue->link;
123 return ((le32_to_cpu(link->control) & TRB_TYPE_BITMASK) == 122 return TRB_TYPE_LINK_LE32(link->control);
124 TRB_TYPE(TRB_LINK));
125} 123}
126 124
127/* Updates trb to point to the next TRB in the ring, and updates seg if the next 125/* Updates trb to point to the next TRB in the ring, and updates seg if the next
@@ -372,7 +370,7 @@ static struct xhci_segment *find_trb_seg(
372 while (cur_seg->trbs > trb || 370 while (cur_seg->trbs > trb ||
373 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) { 371 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
374 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic; 372 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic;
375 if (le32_to_cpu(generic_trb->field[3]) & LINK_TOGGLE) 373 if (generic_trb->field[3] & cpu_to_le32(LINK_TOGGLE))
376 *cycle_state ^= 0x1; 374 *cycle_state ^= 0x1;
377 cur_seg = cur_seg->next; 375 cur_seg = cur_seg->next;
378 if (cur_seg == start_seg) 376 if (cur_seg == start_seg)
@@ -489,8 +487,8 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
489 } 487 }
490 488
491 trb = &state->new_deq_ptr->generic; 489 trb = &state->new_deq_ptr->generic;
492 if ((le32_to_cpu(trb->field[3]) & TRB_TYPE_BITMASK) == 490 if (TRB_TYPE_LINK_LE32(trb->field[3]) &&
493 TRB_TYPE(TRB_LINK) && (le32_to_cpu(trb->field[3]) & LINK_TOGGLE)) 491 (trb->field[3] & cpu_to_le32(LINK_TOGGLE)))
494 state->new_cycle_state ^= 0x1; 492 state->new_cycle_state ^= 0x1;
495 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); 493 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr);
496 494
@@ -525,8 +523,7 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
525 for (cur_seg = cur_td->start_seg, cur_trb = cur_td->first_trb; 523 for (cur_seg = cur_td->start_seg, cur_trb = cur_td->first_trb;
526 true; 524 true;
527 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 525 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
528 if ((le32_to_cpu(cur_trb->generic.field[3]) & TRB_TYPE_BITMASK) 526 if (TRB_TYPE_LINK_LE32(cur_trb->generic.field[3])) {
529 == TRB_TYPE(TRB_LINK)) {
530 /* Unchain any chained Link TRBs, but 527 /* Unchain any chained Link TRBs, but
531 * leave the pointers intact. 528 * leave the pointers intact.
532 */ 529 */
@@ -1000,7 +997,7 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
1000 * but we don't care. 997 * but we don't care.
1001 */ 998 */
1002 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n", 999 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n",
1003 (unsigned int) GET_COMP_CODE(le32_to_cpu(event->status))); 1000 GET_COMP_CODE(le32_to_cpu(event->status)));
1004 1001
1005 /* HW with the reset endpoint quirk needs to have a configure endpoint 1002 /* HW with the reset endpoint quirk needs to have a configure endpoint
1006 * command complete before the endpoint can be used. Queue that here 1003 * command complete before the endpoint can be used. Queue that here
@@ -1458,7 +1455,8 @@ static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci,
1458 * endpoint anyway. Check if a babble halted the 1455 * endpoint anyway. Check if a babble halted the
1459 * endpoint. 1456 * endpoint.
1460 */ 1457 */
1461 if ((le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) == EP_STATE_HALTED) 1458 if ((ep_ctx->ep_info & cpu_to_le32(EP_STATE_MASK)) ==
1459 cpu_to_le32(EP_STATE_HALTED))
1462 return 1; 1460 return 1;
1463 1461
1464 return 0; 1462 return 0;
@@ -1753,10 +1751,8 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1753 for (cur_trb = ep_ring->dequeue, 1751 for (cur_trb = ep_ring->dequeue,
1754 cur_seg = ep_ring->deq_seg; cur_trb != event_trb; 1752 cur_seg = ep_ring->deq_seg; cur_trb != event_trb;
1755 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1753 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1756 if ((le32_to_cpu(cur_trb->generic.field[3]) & 1754 if (!TRB_TYPE_NOOP_LE32(cur_trb->generic.field[3]) &&
1757 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1755 !TRB_TYPE_LINK_LE32(cur_trb->generic.field[3]))
1758 (le32_to_cpu(cur_trb->generic.field[3]) &
1759 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1760 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])); 1756 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2]));
1761 } 1757 }
1762 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) - 1758 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) -
@@ -1885,10 +1881,8 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1885 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg; 1881 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg;
1886 cur_trb != event_trb; 1882 cur_trb != event_trb;
1887 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1883 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1888 if ((le32_to_cpu(cur_trb->generic.field[3]) & 1884 if (!TRB_TYPE_NOOP_LE32(cur_trb->generic.field[3]) &&
1889 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1885 !TRB_TYPE_LINK_LE32(cur_trb->generic.field[3]))
1890 (le32_to_cpu(cur_trb->generic.field[3]) &
1891 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1892 td->urb->actual_length += 1886 td->urb->actual_length +=
1893 TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])); 1887 TRB_LEN(le32_to_cpu(cur_trb->generic.field[2]));
1894 } 1888 }
@@ -2047,8 +2041,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
2047 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)), 2041 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)),
2048 ep_index); 2042 ep_index);
2049 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n", 2043 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
2050 (unsigned int) (le32_to_cpu(event->flags) 2044 (le32_to_cpu(event->flags) &
2051 & TRB_TYPE_BITMASK)>>10); 2045 TRB_TYPE_BITMASK)>>10);
2052 xhci_print_trb_offsets(xhci, (union xhci_trb *) event); 2046 xhci_print_trb_offsets(xhci, (union xhci_trb *) event);
2053 if (ep->skip) { 2047 if (ep->skip) {
2054 ep->skip = false; 2048 ep->skip = false;
@@ -2119,9 +2113,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
2119 * corresponding TD has been cancelled. Just ignore 2113 * corresponding TD has been cancelled. Just ignore
2120 * the TD. 2114 * the TD.
2121 */ 2115 */
2122 if ((le32_to_cpu(event_trb->generic.field[3]) 2116 if (TRB_TYPE_NOOP_LE32(event_trb->generic.field[3])) {
2123 & TRB_TYPE_BITMASK)
2124 == TRB_TYPE(TRB_TR_NOOP)) {
2125 xhci_dbg(xhci, 2117 xhci_dbg(xhci,
2126 "event_trb is a no-op TRB. Skip it\n"); 2118 "event_trb is a no-op TRB. Skip it\n");
2127 goto cleanup; 2119 goto cleanup;
@@ -2452,7 +2444,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
2452 next->link.control |= cpu_to_le32(TRB_CHAIN); 2444 next->link.control |= cpu_to_le32(TRB_CHAIN);
2453 2445
2454 wmb(); 2446 wmb();
2455 next->link.control ^= cpu_to_le32((u32) TRB_CYCLE); 2447 next->link.control ^= cpu_to_le32(TRB_CYCLE);
2456 2448
2457 /* Toggle the cycle bit after the last ring segment. */ 2449 /* Toggle the cycle bit after the last ring segment. */
2458 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) { 2450 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) {
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index f5fe1ac301ab..763f484bc092 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1342,8 +1342,8 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1342 /* If the HC already knows the endpoint is disabled, 1342 /* If the HC already knows the endpoint is disabled,
1343 * or the HCD has noted it is disabled, ignore this request 1343 * or the HCD has noted it is disabled, ignore this request
1344 */ 1344 */
1345 if ((le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) == 1345 if (((ep_ctx->ep_info & cpu_to_le32(EP_STATE_MASK)) ==
1346 EP_STATE_DISABLED || 1346 cpu_to_le32(EP_STATE_DISABLED)) ||
1347 le32_to_cpu(ctrl_ctx->drop_flags) & 1347 le32_to_cpu(ctrl_ctx->drop_flags) &
1348 xhci_get_endpoint_flag(&ep->desc)) { 1348 xhci_get_endpoint_flag(&ep->desc)) {
1349 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", 1349 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n",
@@ -1758,8 +1758,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1758 /* Enqueue pointer can be left pointing to the link TRB, 1758 /* Enqueue pointer can be left pointing to the link TRB,
1759 * we must handle that 1759 * we must handle that
1760 */ 1760 */
1761 if ((le32_to_cpu(command->command_trb->link.control) 1761 if (TRB_TYPE_LINK_LE32(command->command_trb->link.control))
1762 & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
1763 command->command_trb = 1762 command->command_trb =
1764 xhci->cmd_ring->enq_seg->next->trbs; 1763 xhci->cmd_ring->enq_seg->next->trbs;
1765 1764
@@ -2559,8 +2558,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
2559 /* Enqueue pointer can be left pointing to the link TRB, 2558 /* Enqueue pointer can be left pointing to the link TRB,
2560 * we must handle that 2559 * we must handle that
2561 */ 2560 */
2562 if ((le32_to_cpu(reset_device_cmd->command_trb->link.control) 2561 if (TRB_TYPE_LINK_LE32(reset_device_cmd->command_trb->link.control))
2563 & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
2564 reset_device_cmd->command_trb = 2562 reset_device_cmd->command_trb =
2565 xhci->cmd_ring->enq_seg->next->trbs; 2563 xhci->cmd_ring->enq_seg->next->trbs;
2566 2564
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index d8bbf5ccb10d..cae8e23308bf 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1072,6 +1072,13 @@ union xhci_trb {
1072/* Get NEC firmware revision. */ 1072/* Get NEC firmware revision. */
1073#define TRB_NEC_GET_FW 49 1073#define TRB_NEC_GET_FW 49
1074 1074
1075#define TRB_TYPE_LINK(x) (((x) & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
1076/* Above, but for __le32 types -- can avoid work by swapping constants: */
1077#define TRB_TYPE_LINK_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
1078 cpu_to_le32(TRB_TYPE(TRB_LINK)))
1079#define TRB_TYPE_NOOP_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
1080 cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)))
1081
1075#define NEC_FW_MINOR(p) (((p) >> 0) & 0xff) 1082#define NEC_FW_MINOR(p) (((p) >> 0) & 0xff)
1076#define NEC_FW_MAJOR(p) (((p) >> 8) & 0xff) 1083#define NEC_FW_MAJOR(p) (((p) >> 8) & 0xff)
1077 1084
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index c302e1983c70..1c3afcc11bd9 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -670,6 +670,9 @@ int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus)
670 int busnum = ubus? ubus->busnum: 0; 670 int busnum = ubus? ubus->busnum: 0;
671 int rc; 671 int rc;
672 672
673 if (mon_dir == NULL)
674 return 0;
675
673 if (ubus != NULL) { 676 if (ubus != NULL) {
674 rc = snprintf(name, NAMESZ, "%dt", busnum); 677 rc = snprintf(name, NAMESZ, "%dt", busnum);
675 if (rc <= 0 || rc >= NAMESZ) 678 if (rc <= 0 || rc >= NAMESZ)
@@ -740,12 +743,12 @@ int __init mon_text_init(void)
740 743
741 mondir = debugfs_create_dir("usbmon", usb_debug_root); 744 mondir = debugfs_create_dir("usbmon", usb_debug_root);
742 if (IS_ERR(mondir)) { 745 if (IS_ERR(mondir)) {
743 printk(KERN_NOTICE TAG ": debugfs is not available\n"); 746 /* debugfs not available, but we can use usbmon without it */
744 return -ENODEV; 747 return 0;
745 } 748 }
746 if (mondir == NULL) { 749 if (mondir == NULL) {
747 printk(KERN_NOTICE TAG ": unable to create usbmon directory\n"); 750 printk(KERN_NOTICE TAG ": unable to create usbmon directory\n");
748 return -ENODEV; 751 return -ENOMEM;
749 } 752 }
750 mon_dir = mondir; 753 mon_dir = mondir;
751 return 0; 754 return 0;
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 13093481f918..6192b45959f4 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -8,7 +8,7 @@ comment "Enable Host or Gadget support to see Inventra options"
8 8
9# (M)HDRC = (Multipoint) Highspeed Dual-Role Controller 9# (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
10config USB_MUSB_HDRC 10config USB_MUSB_HDRC
11 depends on (USB || USB_GADGET) 11 depends on USB && USB_GADGET
12 depends on (ARM || (BF54x && !BF544) || (BF52x && !BF522 && !BF523)) 12 depends on (ARM || (BF54x && !BF544) || (BF52x && !BF522 && !BF523))
13 select NOP_USB_XCEIV if (ARCH_DAVINCI || MACH_OMAP3EVM || BLACKFIN) 13 select NOP_USB_XCEIV if (ARCH_DAVINCI || MACH_OMAP3EVM || BLACKFIN)
14 select TWL4030_USB if MACH_OMAP_3430SDP 14 select TWL4030_USB if MACH_OMAP_3430SDP
@@ -67,79 +67,6 @@ config USB_MUSB_UX500
67 67
68endchoice 68endchoice
69 69
70choice
71 prompt "Driver Mode"
72 depends on USB_MUSB_HDRC
73 help
74 Dual-Role devices can support both host and peripheral roles,
75 as well as a the special "OTG Device" role which can switch
76 between both roles as needed.
77
78# use USB_MUSB_HDRC_HCD not USB_MUSB_HOST to #ifdef host side support;
79# OTG needs both roles, not just USB_MUSB_HOST.
80config USB_MUSB_HOST
81 depends on USB
82 bool "USB Host"
83 help
84 Say Y here if your system supports the USB host role.
85 If it has a USB "A" (rectangular), "Mini-A" (uncommon),
86 or "Mini-AB" connector, it supports the host role.
87 (With a "Mini-AB" connector, you should enable USB OTG.)
88
89# use USB_GADGET_MUSB_HDRC not USB_MUSB_PERIPHERAL to #ifdef peripheral
90# side support ... OTG needs both roles
91config USB_MUSB_PERIPHERAL
92 depends on USB_GADGET
93 bool "USB Peripheral (gadget stack)"
94 select USB_GADGET_MUSB_HDRC
95 help
96 Say Y here if your system supports the USB peripheral role.
97 If it has a USB "B" (squarish), "Mini-B", or "Mini-AB"
98 connector, it supports the peripheral role.
99 (With a "Mini-AB" connector, you should enable USB OTG.)
100
101config USB_MUSB_OTG
102 depends on USB && USB_GADGET && PM && EXPERIMENTAL
103 bool "Both host and peripheral: USB OTG (On The Go) Device"
104 select USB_GADGET_MUSB_HDRC
105 select USB_OTG
106 help
107 The most notable feature of USB OTG is support for a
108 "Dual-Role" device, which can act as either a device
109 or a host. The initial role choice can be changed
110 later, when two dual-role devices talk to each other.
111
112 At this writing, the OTG support in this driver is incomplete,
113 omitting the mandatory HNP or SRP protocols. However, some
114 of the cable based role switching works. (That is, grounding
115 the ID pin switches the controller to host mode, while leaving
116 it floating leaves it in peripheral mode.)
117
118 Select this if your system has a Mini-AB connector, or
119 to simplify certain kinds of configuration.
120
121 To implement your OTG Targeted Peripherals List (TPL), enable
122 USB_OTG_WHITELIST and update "drivers/usb/core/otg_whitelist.h"
123 to match your requirements.
124
125endchoice
126
127# enable peripheral support (including with OTG)
128config USB_GADGET_MUSB_HDRC
129 bool
130 depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG)
131# default y
132# select USB_GADGET_DUALSPEED
133# select USB_GADGET_SELECTED
134
135# enables host support (including with OTG)
136config USB_MUSB_HDRC_HCD
137 bool
138 depends on USB_MUSB_HDRC && (USB_MUSB_HOST || USB_MUSB_OTG)
139 select USB_OTG if USB_GADGET_MUSB_HDRC
140 default y
141
142
143config MUSB_PIO_ONLY 70config MUSB_PIO_ONLY
144 bool 'Disable DMA (always use PIO)' 71 bool 'Disable DMA (always use PIO)'
145 depends on USB_MUSB_HDRC 72 depends on USB_MUSB_HDRC
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index c4d228b6ef8a..d8fd9d092dec 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -6,8 +6,8 @@ obj-$(CONFIG_USB_MUSB_HDRC) += musb_hdrc.o
6 6
7musb_hdrc-y := musb_core.o 7musb_hdrc-y := musb_core.o
8 8
9musb_hdrc-$(CONFIG_USB_GADGET_MUSB_HDRC) += musb_gadget_ep0.o musb_gadget.o 9musb_hdrc-y += musb_gadget_ep0.o musb_gadget.o
10musb_hdrc-$(CONFIG_USB_MUSB_HDRC_HCD) += musb_virthub.o musb_host.o 10musb_hdrc-y += musb_virthub.o musb_host.o
11musb_hdrc-$(CONFIG_DEBUG_FS) += musb_debugfs.o 11musb_hdrc-$(CONFIG_DEBUG_FS) += musb_debugfs.o
12 12
13# Hardware Glue Layer 13# Hardware Glue Layer
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 23ac28f98d91..08f1d0b662a3 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -124,11 +124,7 @@ static void am35x_musb_disable(struct musb *musb)
124 musb_writel(reg_base, USB_END_OF_INTR_REG, 0); 124 musb_writel(reg_base, USB_END_OF_INTR_REG, 0);
125} 125}
126 126
127#ifdef CONFIG_USB_MUSB_HDRC_HCD
128#define portstate(stmt) stmt 127#define portstate(stmt) stmt
129#else
130#define portstate(stmt)
131#endif
132 128
133static void am35x_musb_set_vbus(struct musb *musb, int is_on) 129static void am35x_musb_set_vbus(struct musb *musb, int is_on)
134{ 130{
diff --git a/drivers/usb/musb/blackfin.h b/drivers/usb/musb/blackfin.h
index bd9352a2ef2a..c84dae546dc6 100644
--- a/drivers/usb/musb/blackfin.h
+++ b/drivers/usb/musb/blackfin.h
@@ -47,7 +47,7 @@
47 * So, need to either use silicon v0.2+ or disable DMA mode in MUSB. 47 * So, need to either use silicon v0.2+ or disable DMA mode in MUSB.
48 */ 48 */
49#if ANOMALY_05000380 && defined(CONFIG_BF52x) && \ 49#if ANOMALY_05000380 && defined(CONFIG_BF52x) && \
50 defined(CONFIG_USB_MUSB_HDRC) && !defined(CONFIG_MUSB_PIO_ONLY) 50 !defined(CONFIG_MUSB_PIO_ONLY)
51# error "Please use PIO mode in MUSB driver on bf52x chip v0.0 and v0.1" 51# error "Please use PIO mode in MUSB driver on bf52x chip v0.0 and v0.1"
52#endif 52#endif
53 53
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 662ed34980bd..4da7492ddbdb 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -172,11 +172,7 @@ static void da8xx_musb_disable(struct musb *musb)
172 musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); 172 musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
173} 173}
174 174
175#ifdef CONFIG_USB_MUSB_HDRC_HCD 175#define portstate(stmt) stmt
176#define portstate(stmt) stmt
177#else
178#define portstate(stmt)
179#endif
180 176
181static void da8xx_musb_set_vbus(struct musb *musb, int is_on) 177static void da8xx_musb_set_vbus(struct musb *musb, int is_on)
182{ 178{
@@ -397,21 +393,15 @@ static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)
397 393
398 cfgchip2 &= ~CFGCHIP2_OTGMODE; 394 cfgchip2 &= ~CFGCHIP2_OTGMODE;
399 switch (musb_mode) { 395 switch (musb_mode) {
400#ifdef CONFIG_USB_MUSB_HDRC_HCD
401 case MUSB_HOST: /* Force VBUS valid, ID = 0 */ 396 case MUSB_HOST: /* Force VBUS valid, ID = 0 */
402 cfgchip2 |= CFGCHIP2_FORCE_HOST; 397 cfgchip2 |= CFGCHIP2_FORCE_HOST;
403 break; 398 break;
404#endif
405#ifdef CONFIG_USB_GADGET_MUSB_HDRC
406 case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */ 399 case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
407 cfgchip2 |= CFGCHIP2_FORCE_DEVICE; 400 cfgchip2 |= CFGCHIP2_FORCE_DEVICE;
408 break; 401 break;
409#endif
410#ifdef CONFIG_USB_MUSB_OTG
411 case MUSB_OTG: /* Don't override the VBUS/ID comparators */ 402 case MUSB_OTG: /* Don't override the VBUS/ID comparators */
412 cfgchip2 |= CFGCHIP2_NO_OVERRIDE; 403 cfgchip2 |= CFGCHIP2_NO_OVERRIDE;
413 break; 404 break;
414#endif
415 default: 405 default:
416 dev_dbg(musb->controller, "Trying to set unsupported mode %u\n", musb_mode); 406 dev_dbg(musb->controller, "Trying to set unsupported mode %u\n", musb_mode);
417 } 407 }
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 2a2adf6492cd..8bdf25a8b023 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -143,12 +143,7 @@ static void davinci_musb_disable(struct musb *musb)
143} 143}
144 144
145 145
146#ifdef CONFIG_USB_MUSB_HDRC_HCD
147#define portstate(stmt) stmt 146#define portstate(stmt) stmt
148#else
149#define portstate(stmt)
150#endif
151
152 147
153/* 148/*
154 * VBUS SWITCHING IS BOARD-SPECIFIC ... at least for the DM6446 EVM, 149 * VBUS SWITCHING IS BOARD-SPECIFIC ... at least for the DM6446 EVM,
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index bcbd1aba961a..20a28731c338 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -328,8 +328,6 @@ void musb_load_testpacket(struct musb *musb)
328 328
329/*-------------------------------------------------------------------------*/ 329/*-------------------------------------------------------------------------*/
330 330
331#ifdef CONFIG_USB_MUSB_OTG
332
333/* 331/*
334 * Handles OTG hnp timeouts, such as b_ase0_brst 332 * Handles OTG hnp timeouts, such as b_ase0_brst
335 */ 333 */
@@ -401,8 +399,6 @@ void musb_hnp_stop(struct musb *musb)
401 musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); 399 musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16);
402} 400}
403 401
404#endif
405
406/* 402/*
407 * Interrupt Service Routine to record USB "global" interrupts. 403 * Interrupt Service Routine to record USB "global" interrupts.
408 * Since these do not happen often and signify things of 404 * Since these do not happen often and signify things of
@@ -432,7 +428,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
432 dev_dbg(musb->controller, "RESUME (%s)\n", otg_state_string(musb->xceiv->state)); 428 dev_dbg(musb->controller, "RESUME (%s)\n", otg_state_string(musb->xceiv->state));
433 429
434 if (devctl & MUSB_DEVCTL_HM) { 430 if (devctl & MUSB_DEVCTL_HM) {
435#ifdef CONFIG_USB_MUSB_HDRC_HCD
436 void __iomem *mbase = musb->mregs; 431 void __iomem *mbase = musb->mregs;
437 432
438 switch (musb->xceiv->state) { 433 switch (musb->xceiv->state) {
@@ -472,17 +467,13 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
472 "host", 467 "host",
473 otg_state_string(musb->xceiv->state)); 468 otg_state_string(musb->xceiv->state));
474 } 469 }
475#endif
476 } else { 470 } else {
477 switch (musb->xceiv->state) { 471 switch (musb->xceiv->state) {
478#ifdef CONFIG_USB_MUSB_HDRC_HCD
479 case OTG_STATE_A_SUSPEND: 472 case OTG_STATE_A_SUSPEND:
480 /* possibly DISCONNECT is upcoming */ 473 /* possibly DISCONNECT is upcoming */
481 musb->xceiv->state = OTG_STATE_A_HOST; 474 musb->xceiv->state = OTG_STATE_A_HOST;
482 usb_hcd_resume_root_hub(musb_to_hcd(musb)); 475 usb_hcd_resume_root_hub(musb_to_hcd(musb));
483 break; 476 break;
484#endif
485#ifdef CONFIG_USB_GADGET_MUSB_HDRC
486 case OTG_STATE_B_WAIT_ACON: 477 case OTG_STATE_B_WAIT_ACON:
487 case OTG_STATE_B_PERIPHERAL: 478 case OTG_STATE_B_PERIPHERAL:
488 /* disconnect while suspended? we may 479 /* disconnect while suspended? we may
@@ -500,7 +491,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
500 case OTG_STATE_B_IDLE: 491 case OTG_STATE_B_IDLE:
501 musb->int_usb &= ~MUSB_INTR_SUSPEND; 492 musb->int_usb &= ~MUSB_INTR_SUSPEND;
502 break; 493 break;
503#endif
504 default: 494 default:
505 WARNING("bogus %s RESUME (%s)\n", 495 WARNING("bogus %s RESUME (%s)\n",
506 "peripheral", 496 "peripheral",
@@ -509,7 +499,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
509 } 499 }
510 } 500 }
511 501
512#ifdef CONFIG_USB_MUSB_HDRC_HCD
513 /* see manual for the order of the tests */ 502 /* see manual for the order of the tests */
514 if (int_usb & MUSB_INTR_SESSREQ) { 503 if (int_usb & MUSB_INTR_SESSREQ) {
515 void __iomem *mbase = musb->mregs; 504 void __iomem *mbase = musb->mregs;
@@ -609,14 +598,12 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
609 handled = IRQ_HANDLED; 598 handled = IRQ_HANDLED;
610 } 599 }
611 600
612#endif
613 if (int_usb & MUSB_INTR_SUSPEND) { 601 if (int_usb & MUSB_INTR_SUSPEND) {
614 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x power %02x\n", 602 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x power %02x\n",
615 otg_state_string(musb->xceiv->state), devctl, power); 603 otg_state_string(musb->xceiv->state), devctl, power);
616 handled = IRQ_HANDLED; 604 handled = IRQ_HANDLED;
617 605
618 switch (musb->xceiv->state) { 606 switch (musb->xceiv->state) {
619#ifdef CONFIG_USB_MUSB_OTG
620 case OTG_STATE_A_PERIPHERAL: 607 case OTG_STATE_A_PERIPHERAL:
621 /* We also come here if the cable is removed, since 608 /* We also come here if the cable is removed, since
622 * this silicon doesn't report ID-no-longer-grounded. 609 * this silicon doesn't report ID-no-longer-grounded.
@@ -633,7 +620,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
633 ? : OTG_TIME_A_WAIT_BCON)); 620 ? : OTG_TIME_A_WAIT_BCON));
634 621
635 break; 622 break;
636#endif
637 case OTG_STATE_B_IDLE: 623 case OTG_STATE_B_IDLE:
638 if (!musb->is_active) 624 if (!musb->is_active)
639 break; 625 break;
@@ -642,13 +628,11 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
642 musb->is_active = is_otg_enabled(musb) 628 musb->is_active = is_otg_enabled(musb)
643 && musb->xceiv->gadget->b_hnp_enable; 629 && musb->xceiv->gadget->b_hnp_enable;
644 if (musb->is_active) { 630 if (musb->is_active) {
645#ifdef CONFIG_USB_MUSB_OTG
646 musb->xceiv->state = OTG_STATE_B_WAIT_ACON; 631 musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
647 dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n"); 632 dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n");
648 mod_timer(&musb->otg_timer, jiffies 633 mod_timer(&musb->otg_timer, jiffies
649 + msecs_to_jiffies( 634 + msecs_to_jiffies(
650 OTG_TIME_B_ASE0_BRST)); 635 OTG_TIME_B_ASE0_BRST));
651#endif
652 } 636 }
653 break; 637 break;
654 case OTG_STATE_A_WAIT_BCON: 638 case OTG_STATE_A_WAIT_BCON:
@@ -672,7 +656,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
672 } 656 }
673 } 657 }
674 658
675#ifdef CONFIG_USB_MUSB_HDRC_HCD
676 if (int_usb & MUSB_INTR_CONNECT) { 659 if (int_usb & MUSB_INTR_CONNECT) {
677 struct usb_hcd *hcd = musb_to_hcd(musb); 660 struct usb_hcd *hcd = musb_to_hcd(musb);
678 661
@@ -682,7 +665,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
682 665
683 musb->ep0_stage = MUSB_EP0_START; 666 musb->ep0_stage = MUSB_EP0_START;
684 667
685#ifdef CONFIG_USB_MUSB_OTG
686 /* flush endpoints when transitioning from Device Mode */ 668 /* flush endpoints when transitioning from Device Mode */
687 if (is_peripheral_active(musb)) { 669 if (is_peripheral_active(musb)) {
688 /* REVISIT HNP; just force disconnect */ 670 /* REVISIT HNP; just force disconnect */
@@ -690,7 +672,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
690 musb_writew(musb->mregs, MUSB_INTRTXE, musb->epmask); 672 musb_writew(musb->mregs, MUSB_INTRTXE, musb->epmask);
691 musb_writew(musb->mregs, MUSB_INTRRXE, musb->epmask & 0xfffe); 673 musb_writew(musb->mregs, MUSB_INTRRXE, musb->epmask & 0xfffe);
692 musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7); 674 musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7);
693#endif
694 musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED 675 musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED
695 |USB_PORT_STAT_HIGH_SPEED 676 |USB_PORT_STAT_HIGH_SPEED
696 |USB_PORT_STAT_ENABLE 677 |USB_PORT_STAT_ENABLE
@@ -739,7 +720,6 @@ b_host:
739 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", 720 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n",
740 otg_state_string(musb->xceiv->state), devctl); 721 otg_state_string(musb->xceiv->state), devctl);
741 } 722 }
742#endif /* CONFIG_USB_MUSB_HDRC_HCD */
743 723
744 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { 724 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
745 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", 725 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n",
@@ -748,7 +728,6 @@ b_host:
748 handled = IRQ_HANDLED; 728 handled = IRQ_HANDLED;
749 729
750 switch (musb->xceiv->state) { 730 switch (musb->xceiv->state) {
751#ifdef CONFIG_USB_MUSB_HDRC_HCD
752 case OTG_STATE_A_HOST: 731 case OTG_STATE_A_HOST:
753 case OTG_STATE_A_SUSPEND: 732 case OTG_STATE_A_SUSPEND:
754 usb_hcd_resume_root_hub(musb_to_hcd(musb)); 733 usb_hcd_resume_root_hub(musb_to_hcd(musb));
@@ -757,8 +736,6 @@ b_host:
757 musb_platform_try_idle(musb, jiffies 736 musb_platform_try_idle(musb, jiffies
758 + msecs_to_jiffies(musb->a_wait_bcon)); 737 + msecs_to_jiffies(musb->a_wait_bcon));
759 break; 738 break;
760#endif /* HOST */
761#ifdef CONFIG_USB_MUSB_OTG
762 case OTG_STATE_B_HOST: 739 case OTG_STATE_B_HOST:
763 /* REVISIT this behaves for "real disconnect" 740 /* REVISIT this behaves for "real disconnect"
764 * cases; make sure the other transitions from 741 * cases; make sure the other transitions from
@@ -777,13 +754,10 @@ b_host:
777 /* FALLTHROUGH */ 754 /* FALLTHROUGH */
778 case OTG_STATE_B_WAIT_ACON: 755 case OTG_STATE_B_WAIT_ACON:
779 /* FALLTHROUGH */ 756 /* FALLTHROUGH */
780#endif /* OTG */
781#ifdef CONFIG_USB_GADGET_MUSB_HDRC
782 case OTG_STATE_B_PERIPHERAL: 757 case OTG_STATE_B_PERIPHERAL:
783 case OTG_STATE_B_IDLE: 758 case OTG_STATE_B_IDLE:
784 musb_g_disconnect(musb); 759 musb_g_disconnect(musb);
785 break; 760 break;
786#endif /* GADGET */
787 default: 761 default:
788 WARNING("unhandled DISCONNECT transition (%s)\n", 762 WARNING("unhandled DISCONNECT transition (%s)\n",
789 otg_state_string(musb->xceiv->state)); 763 otg_state_string(musb->xceiv->state));
@@ -814,7 +788,6 @@ b_host:
814 dev_dbg(musb->controller, "BUS RESET as %s\n", 788 dev_dbg(musb->controller, "BUS RESET as %s\n",
815 otg_state_string(musb->xceiv->state)); 789 otg_state_string(musb->xceiv->state));
816 switch (musb->xceiv->state) { 790 switch (musb->xceiv->state) {
817#ifdef CONFIG_USB_OTG
818 case OTG_STATE_A_SUSPEND: 791 case OTG_STATE_A_SUSPEND:
819 /* We need to ignore disconnect on suspend 792 /* We need to ignore disconnect on suspend
820 * otherwise tusb 2.0 won't reconnect after a 793 * otherwise tusb 2.0 won't reconnect after a
@@ -842,7 +815,6 @@ b_host:
842 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 815 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
843 musb_g_reset(musb); 816 musb_g_reset(musb);
844 break; 817 break;
845#endif
846 case OTG_STATE_B_IDLE: 818 case OTG_STATE_B_IDLE:
847 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 819 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
848 /* FALLTHROUGH */ 820 /* FALLTHROUGH */
@@ -927,7 +899,6 @@ void musb_start(struct musb *musb)
927 899
928 /* put into basic highspeed mode and start session */ 900 /* put into basic highspeed mode and start session */
929 musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE 901 musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
930 | MUSB_POWER_SOFTCONN
931 | MUSB_POWER_HSENAB 902 | MUSB_POWER_HSENAB
932 /* ENSUSPEND wedges tusb */ 903 /* ENSUSPEND wedges tusb */
933 /* | MUSB_POWER_ENSUSPEND */ 904 /* | MUSB_POWER_ENSUSPEND */
@@ -1038,10 +1009,15 @@ static void musb_shutdown(struct platform_device *pdev)
1038 * We don't currently use dynamic fifo setup capability to do anything 1009 * We don't currently use dynamic fifo setup capability to do anything
1039 * more than selecting one of a bunch of predefined configurations. 1010 * more than selecting one of a bunch of predefined configurations.
1040 */ 1011 */
1041#if defined(CONFIG_USB_MUSB_TUSB6010) || defined(CONFIG_USB_MUSB_OMAP2PLUS) \ 1012#if defined(CONFIG_USB_MUSB_TUSB6010) \
1042 || defined(CONFIG_USB_MUSB_AM35X) 1013 || defined(CONFIG_USB_MUSB_TUSB6010_MODULE) \
1014 || defined(CONFIG_USB_MUSB_OMAP2PLUS) \
1015 || defined(CONFIG_USB_MUSB_OMAP2PLUS_MODULE) \
1016 || defined(CONFIG_USB_MUSB_AM35X) \
1017 || defined(CONFIG_USB_MUSB_AM35X_MODULE)
1043static ushort __initdata fifo_mode = 4; 1018static ushort __initdata fifo_mode = 4;
1044#elif defined(CONFIG_USB_MUSB_UX500) 1019#elif defined(CONFIG_USB_MUSB_UX500) \
1020 || defined(CONFIG_USB_MUSB_UX500_MODULE)
1045static ushort __initdata fifo_mode = 5; 1021static ushort __initdata fifo_mode = 5;
1046#else 1022#else
1047static ushort __initdata fifo_mode = 2; 1023static ushort __initdata fifo_mode = 2;
@@ -1191,14 +1167,12 @@ fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
1191 /* configure the FIFO */ 1167 /* configure the FIFO */
1192 musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum); 1168 musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum);
1193 1169
1194#ifdef CONFIG_USB_MUSB_HDRC_HCD
1195 /* EP0 reserved endpoint for control, bidirectional; 1170 /* EP0 reserved endpoint for control, bidirectional;
1196 * EP1 reserved for bulk, two unidirection halves. 1171 * EP1 reserved for bulk, two unidirection halves.
1197 */ 1172 */
1198 if (hw_ep->epnum == 1) 1173 if (hw_ep->epnum == 1)
1199 musb->bulk_ep = hw_ep; 1174 musb->bulk_ep = hw_ep;
1200 /* REVISIT error check: be sure ep0 can both rx and tx ... */ 1175 /* REVISIT error check: be sure ep0 can both rx and tx ... */
1201#endif
1202 switch (cfg->style) { 1176 switch (cfg->style) {
1203 case FIFO_TX: 1177 case FIFO_TX:
1204 musb_write_txfifosz(mbase, c_size); 1178 musb_write_txfifosz(mbase, c_size);
@@ -1317,12 +1291,10 @@ done:
1317 n + 1, musb->config->num_eps * 2 - 1, 1291 n + 1, musb->config->num_eps * 2 - 1,
1318 offset, (1 << (musb->config->ram_bits + 2))); 1292 offset, (1 << (musb->config->ram_bits + 2)));
1319 1293
1320#ifdef CONFIG_USB_MUSB_HDRC_HCD
1321 if (!musb->bulk_ep) { 1294 if (!musb->bulk_ep) {
1322 pr_debug("%s: missing bulk\n", musb_driver_name); 1295 pr_debug("%s: missing bulk\n", musb_driver_name);
1323 return -EINVAL; 1296 return -EINVAL;
1324 } 1297 }
1325#endif
1326 1298
1327 return 0; 1299 return 0;
1328} 1300}
@@ -1353,7 +1325,6 @@ static int __init ep_config_from_hw(struct musb *musb)
1353 1325
1354 /* FIXME set up hw_ep->{rx,tx}_double_buffered */ 1326 /* FIXME set up hw_ep->{rx,tx}_double_buffered */
1355 1327
1356#ifdef CONFIG_USB_MUSB_HDRC_HCD
1357 /* pick an RX/TX endpoint for bulk */ 1328 /* pick an RX/TX endpoint for bulk */
1358 if (hw_ep->max_packet_sz_tx < 512 1329 if (hw_ep->max_packet_sz_tx < 512
1359 || hw_ep->max_packet_sz_rx < 512) 1330 || hw_ep->max_packet_sz_rx < 512)
@@ -1365,15 +1336,12 @@ static int __init ep_config_from_hw(struct musb *musb)
1365 if (musb->bulk_ep) 1336 if (musb->bulk_ep)
1366 continue; 1337 continue;
1367 musb->bulk_ep = hw_ep; 1338 musb->bulk_ep = hw_ep;
1368#endif
1369 } 1339 }
1370 1340
1371#ifdef CONFIG_USB_MUSB_HDRC_HCD
1372 if (!musb->bulk_ep) { 1341 if (!musb->bulk_ep) {
1373 pr_debug("%s: missing bulk\n", musb_driver_name); 1342 pr_debug("%s: missing bulk\n", musb_driver_name);
1374 return -EINVAL; 1343 return -EINVAL;
1375 } 1344 }
1376#endif
1377 1345
1378 return 0; 1346 return 0;
1379} 1347}
@@ -1429,13 +1397,11 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1429 } else { 1397 } else {
1430 musb->is_multipoint = 0; 1398 musb->is_multipoint = 0;
1431 type = ""; 1399 type = "";
1432#ifdef CONFIG_USB_MUSB_HDRC_HCD
1433#ifndef CONFIG_USB_OTG_BLACKLIST_HUB 1400#ifndef CONFIG_USB_OTG_BLACKLIST_HUB
1434 printk(KERN_ERR 1401 printk(KERN_ERR
1435 "%s: kernel must blacklist external hubs\n", 1402 "%s: kernel must blacklist external hubs\n",
1436 musb_driver_name); 1403 musb_driver_name);
1437#endif 1404#endif
1438#endif
1439 } 1405 }
1440 1406
1441 /* log release info */ 1407 /* log release info */
@@ -1479,11 +1445,9 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1479#endif 1445#endif
1480 1446
1481 hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase; 1447 hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase;
1482#ifdef CONFIG_USB_MUSB_HDRC_HCD
1483 hw_ep->target_regs = musb_read_target_reg_base(i, mbase); 1448 hw_ep->target_regs = musb_read_target_reg_base(i, mbase);
1484 hw_ep->rx_reinit = 1; 1449 hw_ep->rx_reinit = 1;
1485 hw_ep->tx_reinit = 1; 1450 hw_ep->tx_reinit = 1;
1486#endif
1487 1451
1488 if (hw_ep->max_packet_sz_tx) { 1452 if (hw_ep->max_packet_sz_tx) {
1489 dev_dbg(musb->controller, 1453 dev_dbg(musb->controller,
@@ -1561,14 +1525,6 @@ irqreturn_t musb_interrupt(struct musb *musb)
1561 (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral", 1525 (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
1562 musb->int_usb, musb->int_tx, musb->int_rx); 1526 musb->int_usb, musb->int_tx, musb->int_rx);
1563 1527
1564#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1565 if (is_otg_enabled(musb) || is_peripheral_enabled(musb))
1566 if (!musb->gadget_driver) {
1567 dev_dbg(musb->controller, "No gadget driver loaded\n");
1568 return IRQ_HANDLED;
1569 }
1570#endif
1571
1572 /* the core can interrupt us for multiple reasons; docs have 1528 /* the core can interrupt us for multiple reasons; docs have
1573 * a generic interrupt flowchart to follow 1529 * a generic interrupt flowchart to follow
1574 */ 1530 */
@@ -1767,8 +1723,6 @@ musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
1767} 1723}
1768static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store); 1724static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store);
1769 1725
1770#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1771
1772/* Gadget drivers can't know that a host is connected so they might want 1726/* Gadget drivers can't know that a host is connected so they might want
1773 * to start SRP, but users can. This allows userspace to trigger SRP. 1727 * to start SRP, but users can. This allows userspace to trigger SRP.
1774 */ 1728 */
@@ -1792,14 +1746,10 @@ musb_srp_store(struct device *dev, struct device_attribute *attr,
1792} 1746}
1793static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store); 1747static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
1794 1748
1795#endif /* CONFIG_USB_GADGET_MUSB_HDRC */
1796
1797static struct attribute *musb_attributes[] = { 1749static struct attribute *musb_attributes[] = {
1798 &dev_attr_mode.attr, 1750 &dev_attr_mode.attr,
1799 &dev_attr_vbus.attr, 1751 &dev_attr_vbus.attr,
1800#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1801 &dev_attr_srp.attr, 1752 &dev_attr_srp.attr,
1802#endif
1803 NULL 1753 NULL
1804}; 1754};
1805 1755
@@ -1832,7 +1782,6 @@ allocate_instance(struct device *dev,
1832 struct musb *musb; 1782 struct musb *musb;
1833 struct musb_hw_ep *ep; 1783 struct musb_hw_ep *ep;
1834 int epnum; 1784 int epnum;
1835#ifdef CONFIG_USB_MUSB_HDRC_HCD
1836 struct usb_hcd *hcd; 1785 struct usb_hcd *hcd;
1837 1786
1838 hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev)); 1787 hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev));
@@ -1850,12 +1799,6 @@ allocate_instance(struct device *dev,
1850 1799
1851 musb->vbuserr_retry = VBUSERR_RETRY_COUNT; 1800 musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
1852 musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON; 1801 musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON;
1853#else
1854 musb = kzalloc(sizeof *musb, GFP_KERNEL);
1855 if (!musb)
1856 return NULL;
1857
1858#endif
1859 dev_set_drvdata(dev, musb); 1802 dev_set_drvdata(dev, musb);
1860 musb->mregs = mbase; 1803 musb->mregs = mbase;
1861 musb->ctrl_base = mbase; 1804 musb->ctrl_base = mbase;
@@ -1885,9 +1828,7 @@ static void musb_free(struct musb *musb)
1885 sysfs_remove_group(&musb->controller->kobj, &musb_attr_group); 1828 sysfs_remove_group(&musb->controller->kobj, &musb_attr_group);
1886#endif 1829#endif
1887 1830
1888#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1889 musb_gadget_cleanup(musb); 1831 musb_gadget_cleanup(musb);
1890#endif
1891 1832
1892 if (musb->nIrq >= 0) { 1833 if (musb->nIrq >= 0) {
1893 if (musb->irq_wake) 1834 if (musb->irq_wake)
@@ -1901,11 +1842,7 @@ static void musb_free(struct musb *musb)
1901 dma_controller_destroy(c); 1842 dma_controller_destroy(c);
1902 } 1843 }
1903 1844
1904#ifdef CONFIG_USB_MUSB_HDRC_HCD
1905 usb_put_hcd(musb_to_hcd(musb));
1906#else
1907 kfree(musb); 1845 kfree(musb);
1908#endif
1909} 1846}
1910 1847
1911/* 1848/*
@@ -2000,9 +1937,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
2000 if (status < 0) 1937 if (status < 0)
2001 goto fail3; 1938 goto fail3;
2002 1939
2003#ifdef CONFIG_USB_MUSB_OTG
2004 setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb); 1940 setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb);
2005#endif
2006 1941
2007 /* Init IRQ workqueue before request_irq */ 1942 /* Init IRQ workqueue before request_irq */
2008 INIT_WORK(&musb->irq_work, musb_irq_work); 1943 INIT_WORK(&musb->irq_work, musb_irq_work);
@@ -2214,7 +2149,16 @@ static void musb_save_context(struct musb *musb)
2214 musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL); 2149 musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL);
2215 2150
2216 for (i = 0; i < musb->config->num_eps; ++i) { 2151 for (i = 0; i < musb->config->num_eps; ++i) {
2217 epio = musb->endpoints[i].regs; 2152 struct musb_hw_ep *hw_ep;
2153
2154 hw_ep = &musb->endpoints[i];
2155 if (!hw_ep)
2156 continue;
2157
2158 epio = hw_ep->regs;
2159 if (!epio)
2160 continue;
2161
2218 musb->context.index_regs[i].txmaxp = 2162 musb->context.index_regs[i].txmaxp =
2219 musb_readw(epio, MUSB_TXMAXP); 2163 musb_readw(epio, MUSB_TXMAXP);
2220 musb->context.index_regs[i].txcsr = 2164 musb->context.index_regs[i].txcsr =
@@ -2280,7 +2224,16 @@ static void musb_restore_context(struct musb *musb)
2280 musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl); 2224 musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl);
2281 2225
2282 for (i = 0; i < musb->config->num_eps; ++i) { 2226 for (i = 0; i < musb->config->num_eps; ++i) {
2283 epio = musb->endpoints[i].regs; 2227 struct musb_hw_ep *hw_ep;
2228
2229 hw_ep = &musb->endpoints[i];
2230 if (!hw_ep)
2231 continue;
2232
2233 epio = hw_ep->regs;
2234 if (!epio)
2235 continue;
2236
2284 musb_writew(epio, MUSB_TXMAXP, 2237 musb_writew(epio, MUSB_TXMAXP,
2285 musb->context.index_regs[i].txmaxp); 2238 musb->context.index_regs[i].txmaxp);
2286 musb_writew(epio, MUSB_TXCSR, 2239 musb_writew(epio, MUSB_TXCSR,
@@ -2329,13 +2282,13 @@ static void musb_restore_context(struct musb *musb)
2329 musb->context.index_regs[i].rxhubport); 2282 musb->context.index_regs[i].rxhubport);
2330 } 2283 }
2331 } 2284 }
2285 musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
2332} 2286}
2333 2287
2334static int musb_suspend(struct device *dev) 2288static int musb_suspend(struct device *dev)
2335{ 2289{
2336 struct platform_device *pdev = to_platform_device(dev); 2290 struct musb *musb = dev_to_musb(dev);
2337 unsigned long flags; 2291 unsigned long flags;
2338 struct musb *musb = dev_to_musb(&pdev->dev);
2339 2292
2340 spin_lock_irqsave(&musb->lock, flags); 2293 spin_lock_irqsave(&musb->lock, flags);
2341 2294
@@ -2357,8 +2310,7 @@ static int musb_suspend(struct device *dev)
2357 2310
2358static int musb_resume_noirq(struct device *dev) 2311static int musb_resume_noirq(struct device *dev)
2359{ 2312{
2360 struct platform_device *pdev = to_platform_device(dev); 2313 struct musb *musb = dev_to_musb(dev);
2361 struct musb *musb = dev_to_musb(&pdev->dev);
2362 2314
2363 musb_restore_context(musb); 2315 musb_restore_context(musb);
2364 2316
@@ -2426,34 +2378,13 @@ static struct platform_driver musb_driver = {
2426 2378
2427static int __init musb_init(void) 2379static int __init musb_init(void)
2428{ 2380{
2429#ifdef CONFIG_USB_MUSB_HDRC_HCD
2430 if (usb_disabled()) 2381 if (usb_disabled())
2431 return 0; 2382 return 0;
2432#endif
2433 2383
2434 pr_info("%s: version " MUSB_VERSION ", " 2384 pr_info("%s: version " MUSB_VERSION ", "
2435#ifdef CONFIG_MUSB_PIO_ONLY
2436 "pio"
2437#elif defined(CONFIG_USB_TI_CPPI_DMA)
2438 "cppi-dma"
2439#elif defined(CONFIG_USB_INVENTRA_DMA)
2440 "musb-dma"
2441#elif defined(CONFIG_USB_TUSB_OMAP_DMA)
2442 "tusb-omap-dma"
2443#elif defined(CONFIG_USB_UX500_DMA)
2444 "ux500-dma"
2445#else
2446 "?dma?" 2385 "?dma?"
2447#endif
2448 ", " 2386 ", "
2449#ifdef CONFIG_USB_MUSB_OTG 2387 "otg (peripheral+host)",
2450 "otg (peripheral+host)"
2451#elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
2452 "peripheral"
2453#elif defined(CONFIG_USB_MUSB_HDRC_HCD)
2454 "host"
2455#endif
2456 ,
2457 musb_driver_name); 2388 musb_driver_name);
2458 return platform_driver_probe(&musb_driver, musb_probe); 2389 return platform_driver_probe(&musb_driver, musb_probe);
2459} 2390}
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 0e053b587960..668eeef601ae 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -72,10 +72,6 @@ struct musb_ep;
72#include <linux/usb/hcd.h> 72#include <linux/usb/hcd.h>
73#include "musb_host.h" 73#include "musb_host.h"
74 74
75
76
77#ifdef CONFIG_USB_MUSB_OTG
78
79#define is_peripheral_enabled(musb) ((musb)->board_mode != MUSB_HOST) 75#define is_peripheral_enabled(musb) ((musb)->board_mode != MUSB_HOST)
80#define is_host_enabled(musb) ((musb)->board_mode != MUSB_PERIPHERAL) 76#define is_host_enabled(musb) ((musb)->board_mode != MUSB_PERIPHERAL)
81#define is_otg_enabled(musb) ((musb)->board_mode == MUSB_OTG) 77#define is_otg_enabled(musb) ((musb)->board_mode == MUSB_OTG)
@@ -86,24 +82,6 @@ struct musb_ep;
86#define is_peripheral_active(m) (!(m)->is_host) 82#define is_peripheral_active(m) (!(m)->is_host)
87#define is_host_active(m) ((m)->is_host) 83#define is_host_active(m) ((m)->is_host)
88 84
89#else
90#define is_peripheral_enabled(musb) is_peripheral_capable()
91#define is_host_enabled(musb) is_host_capable()
92#define is_otg_enabled(musb) 0
93
94#define is_peripheral_active(musb) is_peripheral_capable()
95#define is_host_active(musb) is_host_capable()
96#endif
97
98#if defined(CONFIG_USB_MUSB_OTG) || defined(CONFIG_USB_MUSB_PERIPHERAL)
99/* for some reason, the "select USB_GADGET_MUSB_HDRC" doesn't always
100 * override that choice selection (often USB_GADGET_DUMMY_HCD).
101 */
102#ifndef CONFIG_USB_GADGET_MUSB_HDRC
103#error bogus Kconfig output ... select CONFIG_USB_GADGET_MUSB_HDRC
104#endif
105#endif /* need MUSB gadget selection */
106
107#ifndef CONFIG_HAVE_CLK 85#ifndef CONFIG_HAVE_CLK
108/* Dummy stub for clk framework */ 86/* Dummy stub for clk framework */
109#define clk_get(dev, id) NULL 87#define clk_get(dev, id) NULL
@@ -119,8 +97,6 @@ struct musb_ep;
119 97
120/****************************** PERIPHERAL ROLE *****************************/ 98/****************************** PERIPHERAL ROLE *****************************/
121 99
122#ifdef CONFIG_USB_GADGET_MUSB_HDRC
123
124#define is_peripheral_capable() (1) 100#define is_peripheral_capable() (1)
125 101
126extern irqreturn_t musb_g_ep0_irq(struct musb *); 102extern irqreturn_t musb_g_ep0_irq(struct musb *);
@@ -132,40 +108,14 @@ extern void musb_g_resume(struct musb *);
132extern void musb_g_wakeup(struct musb *); 108extern void musb_g_wakeup(struct musb *);
133extern void musb_g_disconnect(struct musb *); 109extern void musb_g_disconnect(struct musb *);
134 110
135#else
136
137#define is_peripheral_capable() (0)
138
139static inline irqreturn_t musb_g_ep0_irq(struct musb *m) { return IRQ_NONE; }
140static inline void musb_g_reset(struct musb *m) {}
141static inline void musb_g_suspend(struct musb *m) {}
142static inline void musb_g_resume(struct musb *m) {}
143static inline void musb_g_wakeup(struct musb *m) {}
144static inline void musb_g_disconnect(struct musb *m) {}
145
146#endif
147
148/****************************** HOST ROLE ***********************************/ 111/****************************** HOST ROLE ***********************************/
149 112
150#ifdef CONFIG_USB_MUSB_HDRC_HCD
151
152#define is_host_capable() (1) 113#define is_host_capable() (1)
153 114
154extern irqreturn_t musb_h_ep0_irq(struct musb *); 115extern irqreturn_t musb_h_ep0_irq(struct musb *);
155extern void musb_host_tx(struct musb *, u8); 116extern void musb_host_tx(struct musb *, u8);
156extern void musb_host_rx(struct musb *, u8); 117extern void musb_host_rx(struct musb *, u8);
157 118
158#else
159
160#define is_host_capable() (0)
161
162static inline irqreturn_t musb_h_ep0_irq(struct musb *m) { return IRQ_NONE; }
163static inline void musb_host_tx(struct musb *m, u8 e) {}
164static inline void musb_host_rx(struct musb *m, u8 e) {}
165
166#endif
167
168
169/****************************** CONSTANTS ********************************/ 119/****************************** CONSTANTS ********************************/
170 120
171#ifndef MUSB_C_NUM_EPS 121#ifndef MUSB_C_NUM_EPS
@@ -261,7 +211,7 @@ enum musb_g_ep0_state {
261 * @try_ilde: tries to idle the IP 211 * @try_ilde: tries to idle the IP
262 * @vbus_status: returns vbus status if possible 212 * @vbus_status: returns vbus status if possible
263 * @set_vbus: forces vbus status 213 * @set_vbus: forces vbus status
264 * @channel_program: pre check for standard dma channel_program func 214 * @adjust_channel_params: pre check for standard dma channel_program func
265 */ 215 */
266struct musb_platform_ops { 216struct musb_platform_ops {
267 int (*init)(struct musb *musb); 217 int (*init)(struct musb *musb);
@@ -315,7 +265,6 @@ struct musb_hw_ep {
315 void __iomem *fifo_sync_va; 265 void __iomem *fifo_sync_va;
316#endif 266#endif
317 267
318#ifdef CONFIG_USB_MUSB_HDRC_HCD
319 void __iomem *target_regs; 268 void __iomem *target_regs;
320 269
321 /* currently scheduled peripheral endpoint */ 270 /* currently scheduled peripheral endpoint */
@@ -324,31 +273,20 @@ struct musb_hw_ep {
324 273
325 u8 rx_reinit; 274 u8 rx_reinit;
326 u8 tx_reinit; 275 u8 tx_reinit;
327#endif
328 276
329#ifdef CONFIG_USB_GADGET_MUSB_HDRC
330 /* peripheral side */ 277 /* peripheral side */
331 struct musb_ep ep_in; /* TX */ 278 struct musb_ep ep_in; /* TX */
332 struct musb_ep ep_out; /* RX */ 279 struct musb_ep ep_out; /* RX */
333#endif
334}; 280};
335 281
336static inline struct musb_request *next_in_request(struct musb_hw_ep *hw_ep) 282static inline struct musb_request *next_in_request(struct musb_hw_ep *hw_ep)
337{ 283{
338#ifdef CONFIG_USB_GADGET_MUSB_HDRC
339 return next_request(&hw_ep->ep_in); 284 return next_request(&hw_ep->ep_in);
340#else
341 return NULL;
342#endif
343} 285}
344 286
345static inline struct musb_request *next_out_request(struct musb_hw_ep *hw_ep) 287static inline struct musb_request *next_out_request(struct musb_hw_ep *hw_ep)
346{ 288{
347#ifdef CONFIG_USB_GADGET_MUSB_HDRC
348 return next_request(&hw_ep->ep_out); 289 return next_request(&hw_ep->ep_out);
349#else
350 return NULL;
351#endif
352} 290}
353 291
354struct musb_csr_regs { 292struct musb_csr_regs {
@@ -393,7 +331,6 @@ struct musb {
393 331
394 u32 port1_status; 332 u32 port1_status;
395 333
396#ifdef CONFIG_USB_MUSB_HDRC_HCD
397 unsigned long rh_timer; 334 unsigned long rh_timer;
398 335
399 enum musb_h_ep0_state ep0_stage; 336 enum musb_h_ep0_state ep0_stage;
@@ -411,7 +348,6 @@ struct musb {
411 struct list_head out_bulk; /* of musb_qh */ 348 struct list_head out_bulk; /* of musb_qh */
412 349
413 struct timer_list otg_timer; 350 struct timer_list otg_timer;
414#endif
415 struct notifier_block nb; 351 struct notifier_block nb;
416 352
417 struct dma_controller *dma_controller; 353 struct dma_controller *dma_controller;
@@ -472,7 +408,6 @@ struct musb {
472#define can_bulk_combine(musb,type) \ 408#define can_bulk_combine(musb,type) \
473 (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_combine) 409 (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_combine)
474 410
475#ifdef CONFIG_USB_GADGET_MUSB_HDRC
476 /* is_suspended means USB B_PERIPHERAL suspend */ 411 /* is_suspended means USB B_PERIPHERAL suspend */
477 unsigned is_suspended:1; 412 unsigned is_suspended:1;
478 413
@@ -496,7 +431,6 @@ struct musb {
496 enum musb_g_ep0_state ep0_state; 431 enum musb_g_ep0_state ep0_state;
497 struct usb_gadget g; /* the gadget */ 432 struct usb_gadget g; /* the gadget */
498 struct usb_gadget_driver *gadget_driver; /* its driver */ 433 struct usb_gadget_driver *gadget_driver; /* its driver */
499#endif
500 434
501 /* 435 /*
502 * FIXME: Remove this flag. 436 * FIXME: Remove this flag.
@@ -518,12 +452,10 @@ struct musb {
518#endif 452#endif
519}; 453};
520 454
521#ifdef CONFIG_USB_GADGET_MUSB_HDRC
522static inline struct musb *gadget_to_musb(struct usb_gadget *g) 455static inline struct musb *gadget_to_musb(struct usb_gadget *g)
523{ 456{
524 return container_of(g, struct musb, g); 457 return container_of(g, struct musb, g);
525} 458}
526#endif
527 459
528#ifdef CONFIG_BLACKFIN 460#ifdef CONFIG_BLACKFIN
529static inline int musb_read_fifosize(struct musb *musb, 461static inline int musb_read_fifosize(struct musb *musb,
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 6aeb363e63e7..b67a062f556b 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1663,8 +1663,8 @@ static void musb_pullup(struct musb *musb, int is_on)
1663 1663
1664 /* FIXME if on, HdrcStart; if off, HdrcStop */ 1664 /* FIXME if on, HdrcStart; if off, HdrcStop */
1665 1665
1666 dev_dbg(musb->controller, "gadget %s D+ pullup %s\n", 1666 dev_dbg(musb->controller, "gadget D+ pullup %s\n",
1667 musb->gadget_driver->function, is_on ? "on" : "off"); 1667 is_on ? "on" : "off");
1668 musb_writeb(musb->mregs, MUSB_POWER, power); 1668 musb_writeb(musb->mregs, MUSB_POWER, power);
1669} 1669}
1670 1670
@@ -1710,6 +1710,11 @@ static int musb_gadget_pullup(struct usb_gadget *gadget, int is_on)
1710 return 0; 1710 return 0;
1711} 1711}
1712 1712
1713static int musb_gadget_start(struct usb_gadget *g,
1714 struct usb_gadget_driver *driver);
1715static int musb_gadget_stop(struct usb_gadget *g,
1716 struct usb_gadget_driver *driver);
1717
1713static const struct usb_gadget_ops musb_gadget_operations = { 1718static const struct usb_gadget_ops musb_gadget_operations = {
1714 .get_frame = musb_gadget_get_frame, 1719 .get_frame = musb_gadget_get_frame,
1715 .wakeup = musb_gadget_wakeup, 1720 .wakeup = musb_gadget_wakeup,
@@ -1717,6 +1722,8 @@ static const struct usb_gadget_ops musb_gadget_operations = {
1717 /* .vbus_session = musb_gadget_vbus_session, */ 1722 /* .vbus_session = musb_gadget_vbus_session, */
1718 .vbus_draw = musb_gadget_vbus_draw, 1723 .vbus_draw = musb_gadget_vbus_draw,
1719 .pullup = musb_gadget_pullup, 1724 .pullup = musb_gadget_pullup,
1725 .udc_start = musb_gadget_start,
1726 .udc_stop = musb_gadget_stop,
1720}; 1727};
1721 1728
1722/* ----------------------------------------------------------------------- */ 1729/* ----------------------------------------------------------------------- */
@@ -1727,7 +1734,6 @@ static const struct usb_gadget_ops musb_gadget_operations = {
1727 * about there being only one external upstream port. It assumes 1734 * about there being only one external upstream port. It assumes
1728 * all peripheral ports are external... 1735 * all peripheral ports are external...
1729 */ 1736 */
1730static struct musb *the_gadget;
1731 1737
1732static void musb_gadget_release(struct device *dev) 1738static void musb_gadget_release(struct device *dev)
1733{ 1739{
@@ -1814,9 +1820,6 @@ int __init musb_gadget_setup(struct musb *musb)
1814 * musb peripherals at the same time, only the bus lock 1820 * musb peripherals at the same time, only the bus lock
1815 * is probably held. 1821 * is probably held.
1816 */ 1822 */
1817 if (the_gadget)
1818 return -EBUSY;
1819 the_gadget = musb;
1820 1823
1821 musb->g.ops = &musb_gadget_operations; 1824 musb->g.ops = &musb_gadget_operations;
1822 musb->g.is_dualspeed = 1; 1825 musb->g.is_dualspeed = 1;
@@ -1840,18 +1843,22 @@ int __init musb_gadget_setup(struct musb *musb)
1840 status = device_register(&musb->g.dev); 1843 status = device_register(&musb->g.dev);
1841 if (status != 0) { 1844 if (status != 0) {
1842 put_device(&musb->g.dev); 1845 put_device(&musb->g.dev);
1843 the_gadget = NULL; 1846 return status;
1844 } 1847 }
1848 status = usb_add_gadget_udc(musb->controller, &musb->g);
1849 if (status)
1850 goto err;
1851
1852 return 0;
1853err:
1854 device_unregister(&musb->g.dev);
1845 return status; 1855 return status;
1846} 1856}
1847 1857
1848void musb_gadget_cleanup(struct musb *musb) 1858void musb_gadget_cleanup(struct musb *musb)
1849{ 1859{
1850 if (musb != the_gadget) 1860 usb_del_gadget_udc(&musb->g);
1851 return;
1852
1853 device_unregister(&musb->g.dev); 1861 device_unregister(&musb->g.dev);
1854 the_gadget = NULL;
1855} 1862}
1856 1863
1857/* 1864/*
@@ -1863,59 +1870,30 @@ void musb_gadget_cleanup(struct musb *musb)
1863 * -ENOMEM no memory to perform the operation 1870 * -ENOMEM no memory to perform the operation
1864 * 1871 *
1865 * @param driver the gadget driver 1872 * @param driver the gadget driver
1866 * @param bind the driver's bind function
1867 * @return <0 if error, 0 if everything is fine 1873 * @return <0 if error, 0 if everything is fine
1868 */ 1874 */
1869int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1875static int musb_gadget_start(struct usb_gadget *g,
1870 int (*bind)(struct usb_gadget *)) 1876 struct usb_gadget_driver *driver)
1871{ 1877{
1872 struct musb *musb = the_gadget; 1878 struct musb *musb = gadget_to_musb(g);
1873 unsigned long flags; 1879 unsigned long flags;
1874 int retval = -EINVAL; 1880 int retval = -EINVAL;
1875 1881
1876 if (!driver 1882 if (driver->speed != USB_SPEED_HIGH)
1877 || driver->speed != USB_SPEED_HIGH
1878 || !bind || !driver->setup)
1879 goto err0;
1880
1881 /* driver must be initialized to support peripheral mode */
1882 if (!musb) {
1883 dev_dbg(musb->controller, "no dev??\n");
1884 retval = -ENODEV;
1885 goto err0; 1883 goto err0;
1886 }
1887 1884
1888 pm_runtime_get_sync(musb->controller); 1885 pm_runtime_get_sync(musb->controller);
1889 1886
1890 dev_dbg(musb->controller, "registering driver %s\n", driver->function); 1887 dev_dbg(musb->controller, "registering driver %s\n", driver->function);
1891 1888
1892 if (musb->gadget_driver) { 1889 musb->softconnect = 0;
1893 dev_dbg(musb->controller, "%s is already bound to %s\n",
1894 musb_driver_name,
1895 musb->gadget_driver->driver.name);
1896 retval = -EBUSY;
1897 goto err0;
1898 }
1899
1900 spin_lock_irqsave(&musb->lock, flags);
1901 musb->gadget_driver = driver; 1890 musb->gadget_driver = driver;
1902 musb->g.dev.driver = &driver->driver;
1903 driver->driver.bus = NULL;
1904 musb->softconnect = 1;
1905 spin_unlock_irqrestore(&musb->lock, flags);
1906
1907 retval = bind(&musb->g);
1908 if (retval) {
1909 dev_dbg(musb->controller, "bind to driver %s failed --> %d\n",
1910 driver->driver.name, retval);
1911 goto err1;
1912 }
1913 1891
1914 spin_lock_irqsave(&musb->lock, flags); 1892 spin_lock_irqsave(&musb->lock, flags);
1893 musb->is_active = 1;
1915 1894
1916 otg_set_peripheral(musb->xceiv, &musb->g); 1895 otg_set_peripheral(musb->xceiv, &musb->g);
1917 musb->xceiv->state = OTG_STATE_B_IDLE; 1896 musb->xceiv->state = OTG_STATE_B_IDLE;
1918 musb->is_active = 1;
1919 1897
1920 /* 1898 /*
1921 * FIXME this ignores the softconnect flag. Drivers are 1899 * FIXME this ignores the softconnect flag. Drivers are
@@ -1927,8 +1905,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1927 if (!is_otg_enabled(musb)) 1905 if (!is_otg_enabled(musb))
1928 musb_start(musb); 1906 musb_start(musb);
1929 1907
1930 otg_set_peripheral(musb->xceiv, &musb->g);
1931
1932 spin_unlock_irqrestore(&musb->lock, flags); 1908 spin_unlock_irqrestore(&musb->lock, flags);
1933 1909
1934 if (is_otg_enabled(musb)) { 1910 if (is_otg_enabled(musb)) {
@@ -1960,15 +1936,9 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1960err2: 1936err2:
1961 if (!is_otg_enabled(musb)) 1937 if (!is_otg_enabled(musb))
1962 musb_stop(musb); 1938 musb_stop(musb);
1963
1964err1:
1965 musb->gadget_driver = NULL;
1966 musb->g.dev.driver = NULL;
1967
1968err0: 1939err0:
1969 return retval; 1940 return retval;
1970} 1941}
1971EXPORT_SYMBOL(usb_gadget_probe_driver);
1972 1942
1973static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver) 1943static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
1974{ 1944{
@@ -2018,17 +1988,12 @@ static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
2018 * 1988 *
2019 * @param driver the gadget driver to unregister 1989 * @param driver the gadget driver to unregister
2020 */ 1990 */
2021int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1991static int musb_gadget_stop(struct usb_gadget *g,
1992 struct usb_gadget_driver *driver)
2022{ 1993{
2023 struct musb *musb = the_gadget; 1994 struct musb *musb = gadget_to_musb(g);
2024 unsigned long flags; 1995 unsigned long flags;
2025 1996
2026 if (!driver || !driver->unbind || !musb)
2027 return -EINVAL;
2028
2029 if (!musb->gadget_driver)
2030 return -EINVAL;
2031
2032 if (musb->xceiv->last_event == USB_EVENT_NONE) 1997 if (musb->xceiv->last_event == USB_EVENT_NONE)
2033 pm_runtime_get_sync(musb->controller); 1998 pm_runtime_get_sync(musb->controller);
2034 1999
@@ -2039,9 +2004,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2039 2004
2040 spin_lock_irqsave(&musb->lock, flags); 2005 spin_lock_irqsave(&musb->lock, flags);
2041 2006
2042#ifdef CONFIG_USB_MUSB_OTG
2043 musb_hnp_stop(musb); 2007 musb_hnp_stop(musb);
2044#endif
2045 2008
2046 (void) musb_gadget_vbus_draw(&musb->g, 0); 2009 (void) musb_gadget_vbus_draw(&musb->g, 0);
2047 2010
@@ -2051,13 +2014,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2051 2014
2052 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function); 2015 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function);
2053 2016
2054 spin_unlock_irqrestore(&musb->lock, flags);
2055 driver->unbind(&musb->g);
2056 spin_lock_irqsave(&musb->lock, flags);
2057
2058 musb->gadget_driver = NULL;
2059 musb->g.dev.driver = NULL;
2060
2061 musb->is_active = 0; 2017 musb->is_active = 0;
2062 musb_platform_try_idle(musb, 0); 2018 musb_platform_try_idle(musb, 0);
2063 spin_unlock_irqrestore(&musb->lock, flags); 2019 spin_unlock_irqrestore(&musb->lock, flags);
@@ -2077,8 +2033,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2077 2033
2078 return 0; 2034 return 0;
2079} 2035}
2080EXPORT_SYMBOL(usb_gadget_unregister_driver);
2081
2082 2036
2083/* ----------------------------------------------------------------------- */ 2037/* ----------------------------------------------------------------------- */
2084 2038
@@ -2164,7 +2118,6 @@ void musb_g_disconnect(struct musb *musb)
2164 2118
2165 switch (musb->xceiv->state) { 2119 switch (musb->xceiv->state) {
2166 default: 2120 default:
2167#ifdef CONFIG_USB_MUSB_OTG
2168 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n", 2121 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n",
2169 otg_state_string(musb->xceiv->state)); 2122 otg_state_string(musb->xceiv->state));
2170 musb->xceiv->state = OTG_STATE_A_IDLE; 2123 musb->xceiv->state = OTG_STATE_A_IDLE;
@@ -2176,7 +2129,6 @@ void musb_g_disconnect(struct musb *musb)
2176 break; 2129 break;
2177 case OTG_STATE_B_WAIT_ACON: 2130 case OTG_STATE_B_WAIT_ACON:
2178 case OTG_STATE_B_HOST: 2131 case OTG_STATE_B_HOST:
2179#endif
2180 case OTG_STATE_B_PERIPHERAL: 2132 case OTG_STATE_B_PERIPHERAL:
2181 case OTG_STATE_B_IDLE: 2133 case OTG_STATE_B_IDLE:
2182 musb->xceiv->state = OTG_STATE_B_IDLE; 2134 musb->xceiv->state = OTG_STATE_B_IDLE;
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index b2faff235507..9378b359c1f0 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -88,7 +88,6 @@ static int service_tx_status_request(
88 case USB_RECIP_DEVICE: 88 case USB_RECIP_DEVICE:
89 result[0] = musb->is_self_powered << USB_DEVICE_SELF_POWERED; 89 result[0] = musb->is_self_powered << USB_DEVICE_SELF_POWERED;
90 result[0] |= musb->may_wakeup << USB_DEVICE_REMOTE_WAKEUP; 90 result[0] |= musb->may_wakeup << USB_DEVICE_REMOTE_WAKEUP;
91#ifdef CONFIG_USB_MUSB_OTG
92 if (musb->g.is_otg) { 91 if (musb->g.is_otg) {
93 result[0] |= musb->g.b_hnp_enable 92 result[0] |= musb->g.b_hnp_enable
94 << USB_DEVICE_B_HNP_ENABLE; 93 << USB_DEVICE_B_HNP_ENABLE;
@@ -97,7 +96,6 @@ static int service_tx_status_request(
97 result[0] |= musb->g.a_hnp_support 96 result[0] |= musb->g.a_hnp_support
98 << USB_DEVICE_A_HNP_SUPPORT; 97 << USB_DEVICE_A_HNP_SUPPORT;
99 } 98 }
100#endif
101 break; 99 break;
102 100
103 case USB_RECIP_INTERFACE: 101 case USB_RECIP_INTERFACE:
@@ -392,7 +390,6 @@ __acquires(musb->lock)
392 if (handled > 0) 390 if (handled > 0)
393 musb->test_mode = true; 391 musb->test_mode = true;
394 break; 392 break;
395#ifdef CONFIG_USB_MUSB_OTG
396 case USB_DEVICE_B_HNP_ENABLE: 393 case USB_DEVICE_B_HNP_ENABLE:
397 if (!musb->g.is_otg) 394 if (!musb->g.is_otg)
398 goto stall; 395 goto stall;
@@ -409,7 +406,6 @@ __acquires(musb->lock)
409 goto stall; 406 goto stall;
410 musb->g.a_alt_hnp_support = 1; 407 musb->g.a_alt_hnp_support = 1;
411 break; 408 break;
412#endif
413 case USB_DEVICE_DEBUG_MODE: 409 case USB_DEVICE_DEBUG_MODE:
414 handled = 0; 410 handled = 0;
415 break; 411 break;
diff --git a/drivers/usb/musb/musb_host.h b/drivers/usb/musb/musb_host.h
index 14b00776638d..622d09fb9aba 100644
--- a/drivers/usb/musb/musb_host.h
+++ b/drivers/usb/musb/musb_host.h
@@ -95,7 +95,6 @@ extern const struct hc_driver musb_hc_driver;
95 95
96static inline struct urb *next_urb(struct musb_qh *qh) 96static inline struct urb *next_urb(struct musb_qh *qh)
97{ 97{
98#ifdef CONFIG_USB_MUSB_HDRC_HCD
99 struct list_head *queue; 98 struct list_head *queue;
100 99
101 if (!qh) 100 if (!qh)
@@ -104,9 +103,6 @@ static inline struct urb *next_urb(struct musb_qh *qh)
104 if (list_empty(queue)) 103 if (list_empty(queue))
105 return NULL; 104 return NULL;
106 return list_entry(queue->next, struct urb, urb_list); 105 return list_entry(queue->next, struct urb, urb_list);
107#else
108 return NULL;
109#endif
110} 106}
111 107
112#endif /* _MUSB_HOST_H */ 108#endif /* _MUSB_HOST_H */
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index 2d80a5758838..e9f80adc45a4 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -88,14 +88,12 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
88 OTG_TIME_A_AIDL_BDIS)); 88 OTG_TIME_A_AIDL_BDIS));
89 musb_platform_try_idle(musb, 0); 89 musb_platform_try_idle(musb, 0);
90 break; 90 break;
91#ifdef CONFIG_USB_MUSB_OTG
92 case OTG_STATE_B_HOST: 91 case OTG_STATE_B_HOST:
93 musb->xceiv->state = OTG_STATE_B_WAIT_ACON; 92 musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
94 musb->is_active = is_otg_enabled(musb) 93 musb->is_active = is_otg_enabled(musb)
95 && musb->xceiv->host->b_hnp_enable; 94 && musb->xceiv->host->b_hnp_enable;
96 musb_platform_try_idle(musb, 0); 95 musb_platform_try_idle(musb, 0);
97 break; 96 break;
98#endif
99 default: 97 default:
100 dev_dbg(musb->controller, "bogus rh suspend? %s\n", 98 dev_dbg(musb->controller, "bogus rh suspend? %s\n",
101 otg_state_string(musb->xceiv->state)); 99 otg_state_string(musb->xceiv->state));
@@ -118,13 +116,11 @@ static void musb_port_reset(struct musb *musb, bool do_reset)
118 u8 power; 116 u8 power;
119 void __iomem *mbase = musb->mregs; 117 void __iomem *mbase = musb->mregs;
120 118
121#ifdef CONFIG_USB_MUSB_OTG
122 if (musb->xceiv->state == OTG_STATE_B_IDLE) { 119 if (musb->xceiv->state == OTG_STATE_B_IDLE) {
123 dev_dbg(musb->controller, "HNP: Returning from HNP; no hub reset from b_idle\n"); 120 dev_dbg(musb->controller, "HNP: Returning from HNP; no hub reset from b_idle\n");
124 musb->port1_status &= ~USB_PORT_STAT_RESET; 121 musb->port1_status &= ~USB_PORT_STAT_RESET;
125 return; 122 return;
126 } 123 }
127#endif
128 124
129 if (!is_host_active(musb)) 125 if (!is_host_active(musb))
130 return; 126 return;
@@ -191,14 +187,12 @@ void musb_root_disconnect(struct musb *musb)
191 187
192 switch (musb->xceiv->state) { 188 switch (musb->xceiv->state) {
193 case OTG_STATE_A_SUSPEND: 189 case OTG_STATE_A_SUSPEND:
194#ifdef CONFIG_USB_MUSB_OTG
195 if (is_otg_enabled(musb) 190 if (is_otg_enabled(musb)
196 && musb->xceiv->host->b_hnp_enable) { 191 && musb->xceiv->host->b_hnp_enable) {
197 musb->xceiv->state = OTG_STATE_A_PERIPHERAL; 192 musb->xceiv->state = OTG_STATE_A_PERIPHERAL;
198 musb->g.is_a_peripheral = 1; 193 musb->g.is_a_peripheral = 1;
199 break; 194 break;
200 } 195 }
201#endif
202 /* FALLTHROUGH */ 196 /* FALLTHROUGH */
203 case OTG_STATE_A_HOST: 197 case OTG_STATE_A_HOST:
204 musb->xceiv->state = OTG_STATE_A_WAIT_BCON; 198 musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index c5d4c44d0ffa..ba85f273e487 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -51,9 +51,7 @@ static void musb_do_idle(unsigned long _musb)
51{ 51{
52 struct musb *musb = (void *)_musb; 52 struct musb *musb = (void *)_musb;
53 unsigned long flags; 53 unsigned long flags;
54#ifdef CONFIG_USB_MUSB_HDRC_HCD
55 u8 power; 54 u8 power;
56#endif
57 u8 devctl; 55 u8 devctl;
58 56
59 spin_lock_irqsave(&musb->lock, flags); 57 spin_lock_irqsave(&musb->lock, flags);
@@ -70,7 +68,6 @@ static void musb_do_idle(unsigned long _musb)
70 MUSB_HST_MODE(musb); 68 MUSB_HST_MODE(musb);
71 } 69 }
72 break; 70 break;
73#ifdef CONFIG_USB_MUSB_HDRC_HCD
74 case OTG_STATE_A_SUSPEND: 71 case OTG_STATE_A_SUSPEND:
75 /* finish RESUME signaling? */ 72 /* finish RESUME signaling? */
76 if (musb->port1_status & MUSB_PORT_STAT_RESUME) { 73 if (musb->port1_status & MUSB_PORT_STAT_RESUME) {
@@ -87,15 +84,12 @@ static void musb_do_idle(unsigned long _musb)
87 musb->xceiv->state = OTG_STATE_A_HOST; 84 musb->xceiv->state = OTG_STATE_A_HOST;
88 } 85 }
89 break; 86 break;
90#endif
91#ifdef CONFIG_USB_MUSB_HDRC_HCD
92 case OTG_STATE_A_HOST: 87 case OTG_STATE_A_HOST:
93 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 88 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
94 if (devctl & MUSB_DEVCTL_BDEVICE) 89 if (devctl & MUSB_DEVCTL_BDEVICE)
95 musb->xceiv->state = OTG_STATE_B_IDLE; 90 musb->xceiv->state = OTG_STATE_B_IDLE;
96 else 91 else
97 musb->xceiv->state = OTG_STATE_A_WAIT_BCON; 92 musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
98#endif
99 default: 93 default:
100 break; 94 break;
101 } 95 }
@@ -243,13 +237,11 @@ static int musb_otg_notifications(struct notifier_block *nb,
243 dev_dbg(musb->controller, "ID GND\n"); 237 dev_dbg(musb->controller, "ID GND\n");
244 238
245 if (is_otg_enabled(musb)) { 239 if (is_otg_enabled(musb)) {
246#ifdef CONFIG_USB_GADGET_MUSB_HDRC
247 if (musb->gadget_driver) { 240 if (musb->gadget_driver) {
248 pm_runtime_get_sync(musb->controller); 241 pm_runtime_get_sync(musb->controller);
249 otg_init(musb->xceiv); 242 otg_init(musb->xceiv);
250 omap2430_musb_set_vbus(musb, 1); 243 omap2430_musb_set_vbus(musb, 1);
251 } 244 }
252#endif
253 } else { 245 } else {
254 pm_runtime_get_sync(musb->controller); 246 pm_runtime_get_sync(musb->controller);
255 otg_init(musb->xceiv); 247 otg_init(musb->xceiv);
@@ -260,21 +252,16 @@ static int musb_otg_notifications(struct notifier_block *nb,
260 case USB_EVENT_VBUS: 252 case USB_EVENT_VBUS:
261 dev_dbg(musb->controller, "VBUS Connect\n"); 253 dev_dbg(musb->controller, "VBUS Connect\n");
262 254
263#ifdef CONFIG_USB_GADGET_MUSB_HDRC
264 if (musb->gadget_driver) 255 if (musb->gadget_driver)
265 pm_runtime_get_sync(musb->controller); 256 pm_runtime_get_sync(musb->controller);
266#endif
267 otg_init(musb->xceiv); 257 otg_init(musb->xceiv);
268 break; 258 break;
269 259
270 case USB_EVENT_NONE: 260 case USB_EVENT_NONE:
271 dev_dbg(musb->controller, "VBUS Disconnect\n"); 261 dev_dbg(musb->controller, "VBUS Disconnect\n");
272 262
273#ifdef CONFIG_USB_GADGET_MUSB_HDRC
274 if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) 263 if (is_otg_enabled(musb) || is_peripheral_enabled(musb))
275 if (musb->gadget_driver) 264 if (musb->gadget_driver) {
276#endif
277 {
278 pm_runtime_mark_last_busy(musb->controller); 265 pm_runtime_mark_last_busy(musb->controller);
279 pm_runtime_put_autosuspend(musb->controller); 266 pm_runtime_put_autosuspend(musb->controller);
280 } 267 }
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index b410357cf016..9eec41fbf3a4 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -269,8 +269,6 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf)
269 269
270static struct musb *the_musb; 270static struct musb *the_musb;
271 271
272#ifdef CONFIG_USB_GADGET_MUSB_HDRC
273
274/* This is used by gadget drivers, and OTG transceiver logic, allowing 272/* This is used by gadget drivers, and OTG transceiver logic, allowing
275 * at most mA current to be drawn from VBUS during a Default-B session 273 * at most mA current to be drawn from VBUS during a Default-B session
276 * (that is, while VBUS exceeds 4.4V). In Default-A (including pure host 274 * (that is, while VBUS exceeds 4.4V). In Default-A (including pure host
@@ -310,10 +308,6 @@ static int tusb_draw_power(struct otg_transceiver *x, unsigned mA)
310 return 0; 308 return 0;
311} 309}
312 310
313#else
314#define tusb_draw_power NULL
315#endif
316
317/* workaround for issue 13: change clock during chip idle 311/* workaround for issue 13: change clock during chip idle
318 * (to be fixed in rev3 silicon) ... symptoms include disconnect 312 * (to be fixed in rev3 silicon) ... symptoms include disconnect
319 * or looping suspend/resume cycles 313 * or looping suspend/resume cycles
@@ -440,19 +434,15 @@ static void musb_do_idle(unsigned long _musb)
440 if (is_host_active(musb) && (musb->port1_status >> 16)) 434 if (is_host_active(musb) && (musb->port1_status >> 16))
441 goto done; 435 goto done;
442 436
443#ifdef CONFIG_USB_GADGET_MUSB_HDRC 437 if (is_peripheral_enabled(musb) && !musb->gadget_driver) {
444 if (is_peripheral_enabled(musb) && !musb->gadget_driver)
445 wakeups = 0; 438 wakeups = 0;
446 else { 439 } else {
447 wakeups = TUSB_PRCM_WHOSTDISCON 440 wakeups = TUSB_PRCM_WHOSTDISCON
448 | TUSB_PRCM_WBUS 441 | TUSB_PRCM_WBUS
449 | TUSB_PRCM_WVBUS; 442 | TUSB_PRCM_WVBUS;
450 if (is_otg_enabled(musb)) 443 if (is_otg_enabled(musb))
451 wakeups |= TUSB_PRCM_WID; 444 wakeups |= TUSB_PRCM_WID;
452 } 445 }
453#else
454 wakeups = TUSB_PRCM_WHOSTDISCON | TUSB_PRCM_WBUS;
455#endif
456 tusb_allow_idle(musb, wakeups); 446 tusb_allow_idle(musb, wakeups);
457 } 447 }
458done: 448done:
@@ -610,30 +600,22 @@ static int tusb_musb_set_mode(struct musb *musb, u8 musb_mode)
610 600
611 switch (musb_mode) { 601 switch (musb_mode) {
612 602
613#ifdef CONFIG_USB_MUSB_HDRC_HCD
614 case MUSB_HOST: /* Disable PHY ID detect, ground ID */ 603 case MUSB_HOST: /* Disable PHY ID detect, ground ID */
615 phy_otg_ctrl &= ~TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP; 604 phy_otg_ctrl &= ~TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
616 phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP; 605 phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
617 dev_conf |= TUSB_DEV_CONF_ID_SEL; 606 dev_conf |= TUSB_DEV_CONF_ID_SEL;
618 dev_conf &= ~TUSB_DEV_CONF_SOFT_ID; 607 dev_conf &= ~TUSB_DEV_CONF_SOFT_ID;
619 break; 608 break;
620#endif
621
622#ifdef CONFIG_USB_GADGET_MUSB_HDRC
623 case MUSB_PERIPHERAL: /* Disable PHY ID detect, keep ID pull-up on */ 609 case MUSB_PERIPHERAL: /* Disable PHY ID detect, keep ID pull-up on */
624 phy_otg_ctrl |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP; 610 phy_otg_ctrl |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
625 phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP; 611 phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
626 dev_conf |= (TUSB_DEV_CONF_ID_SEL | TUSB_DEV_CONF_SOFT_ID); 612 dev_conf |= (TUSB_DEV_CONF_ID_SEL | TUSB_DEV_CONF_SOFT_ID);
627 break; 613 break;
628#endif
629
630#ifdef CONFIG_USB_MUSB_OTG
631 case MUSB_OTG: /* Use PHY ID detection */ 614 case MUSB_OTG: /* Use PHY ID detection */
632 phy_otg_ctrl |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP; 615 phy_otg_ctrl |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
633 phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP; 616 phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
634 dev_conf &= ~(TUSB_DEV_CONF_ID_SEL | TUSB_DEV_CONF_SOFT_ID); 617 dev_conf &= ~(TUSB_DEV_CONF_ID_SEL | TUSB_DEV_CONF_SOFT_ID);
635 break; 618 break;
636#endif
637 619
638 default: 620 default:
639 dev_dbg(musb->controller, "Trying to set mode %i\n", musb_mode); 621 dev_dbg(musb->controller, "Trying to set mode %i\n", musb_mode);
@@ -684,7 +666,6 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
684 /* B-dev state machine: no vbus ~= disconnect */ 666 /* B-dev state machine: no vbus ~= disconnect */
685 if ((is_otg_enabled(musb) && !musb->xceiv->default_a) 667 if ((is_otg_enabled(musb) && !musb->xceiv->default_a)
686 || !is_host_enabled(musb)) { 668 || !is_host_enabled(musb)) {
687#ifdef CONFIG_USB_MUSB_HDRC_HCD
688 /* ? musb_root_disconnect(musb); */ 669 /* ? musb_root_disconnect(musb); */
689 musb->port1_status &= 670 musb->port1_status &=
690 ~(USB_PORT_STAT_CONNECTION 671 ~(USB_PORT_STAT_CONNECTION
@@ -693,7 +674,6 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
693 | USB_PORT_STAT_HIGH_SPEED 674 | USB_PORT_STAT_HIGH_SPEED
694 | USB_PORT_STAT_TEST 675 | USB_PORT_STAT_TEST
695 ); 676 );
696#endif
697 677
698 if (otg_stat & TUSB_DEV_OTG_STAT_SESS_END) { 678 if (otg_stat & TUSB_DEV_OTG_STAT_SESS_END) {
699 dev_dbg(musb->controller, "Forcing disconnect (no interrupt)\n"); 679 dev_dbg(musb->controller, "Forcing disconnect (no interrupt)\n");
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c
index cfb5aa72b196..b4d2c0972b3d 100644
--- a/drivers/usb/otg/twl6030-usb.c
+++ b/drivers/usb/otg/twl6030-usb.c
@@ -95,11 +95,15 @@ struct twl6030_usb {
95 95
96 struct regulator *usb3v3; 96 struct regulator *usb3v3;
97 97
98 /* used to set vbus, in atomic path */
99 struct work_struct set_vbus_work;
100
98 int irq1; 101 int irq1;
99 int irq2; 102 int irq2;
100 u8 linkstat; 103 u8 linkstat;
101 u8 asleep; 104 u8 asleep;
102 bool irq_enabled; 105 bool irq_enabled;
106 bool vbus_enable;
103 unsigned long features; 107 unsigned long features;
104}; 108};
105 109
@@ -370,20 +374,31 @@ static int twl6030_enable_irq(struct otg_transceiver *x)
370 return 0; 374 return 0;
371} 375}
372 376
373static int twl6030_set_vbus(struct otg_transceiver *x, bool enabled) 377static void otg_set_vbus_work(struct work_struct *data)
374{ 378{
375 struct twl6030_usb *twl = xceiv_to_twl(x); 379 struct twl6030_usb *twl = container_of(data, struct twl6030_usb,
380 set_vbus_work);
376 381
377 /* 382 /*
378 * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1 383 * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1
379 * register. This enables boost mode. 384 * register. This enables boost mode.
380 */ 385 */
381 if (enabled) 386
387 if (twl->vbus_enable)
382 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x40, 388 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x40,
383 CHARGERUSB_CTRL1); 389 CHARGERUSB_CTRL1);
384 else 390 else
385 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x00, 391 twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x00,
386 CHARGERUSB_CTRL1); 392 CHARGERUSB_CTRL1);
393}
394
395static int twl6030_set_vbus(struct otg_transceiver *x, bool enabled)
396{
397 struct twl6030_usb *twl = xceiv_to_twl(x);
398
399 twl->vbus_enable = enabled;
400 schedule_work(&twl->set_vbus_work);
401
387 return 0; 402 return 0;
388} 403}
389 404
@@ -444,6 +459,8 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
444 459
445 ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier); 460 ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier);
446 461
462 INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
463
447 twl->irq_enabled = true; 464 twl->irq_enabled = true;
448 status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq, 465 status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq,
449 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 466 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
@@ -494,6 +511,7 @@ static int __exit twl6030_usb_remove(struct platform_device *pdev)
494 regulator_put(twl->usb3v3); 511 regulator_put(twl->usb3v3);
495 pdata->phy_exit(twl->dev); 512 pdata->phy_exit(twl->dev);
496 device_remove_file(twl->dev, &dev_attr_vbus); 513 device_remove_file(twl->dev, &dev_attr_vbus);
514 cancel_work_sync(&twl->set_vbus_work);
497 kfree(twl); 515 kfree(twl);
498 516
499 return 0; 517 return 0;
diff --git a/drivers/usb/renesas_usbhs/Kconfig b/drivers/usb/renesas_usbhs/Kconfig
index b2e64918884c..286cbf1ca7de 100644
--- a/drivers/usb/renesas_usbhs/Kconfig
+++ b/drivers/usb/renesas_usbhs/Kconfig
@@ -1,5 +1,5 @@
1# 1#
2# Renesas USB Controller Drivers 2# Renesas USBHS Controller Drivers
3# 3#
4 4
5config USB_RENESAS_USBHS 5config USB_RENESAS_USBHS
@@ -7,10 +7,9 @@ config USB_RENESAS_USBHS
7 depends on SUPERH || ARCH_SHMOBILE 7 depends on SUPERH || ARCH_SHMOBILE
8 default n 8 default n
9 help 9 help
10 Renesas USBHS is a discrete USB host and peripheral controller chip 10 Renesas USBHS is a discrete USB host and peripheral controller chip
11 that supports both full and high speed USB 2.0 data transfers. 11 that supports both full and high speed USB 2.0 data transfers.
12 It has nine or more configurable endpoints, and endpoint zero. 12 It has nine or more configurable endpoints, and endpoint zero.
13 13
14 Say "y" to link the driver statically, or "m" to build a 14 Say "y" to link the driver statically, or "m" to build a
15 dynamically linked module called "renesas_usbhs" and force all 15 dynamically linked module called "renesas_usbhs"
16 gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/renesas_usbhs/Makefile b/drivers/usb/renesas_usbhs/Makefile
index b8798ad16278..ce08345fa15a 100644
--- a/drivers/usb/renesas_usbhs/Makefile
+++ b/drivers/usb/renesas_usbhs/Makefile
@@ -4,6 +4,6 @@
4 4
5obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o 5obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o
6 6
7renesas_usbhs-y := common.o mod.o pipe.o 7renesas_usbhs-y := common.o mod.o pipe.o fifo.o
8 8
9renesas_usbhs-$(CONFIG_USB_RENESAS_USBHS_UDC) += mod_gadget.o 9renesas_usbhs-$(CONFIG_USB_RENESAS_USBHS_UDC) += mod_gadget.o
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
index f3664d6af661..d8239e5efa66 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -21,6 +21,29 @@
21#include <linux/sysfs.h> 21#include <linux/sysfs.h>
22#include "./common.h" 22#include "./common.h"
23 23
24/*
25 * image of renesas_usbhs
26 *
27 * ex) gadget case
28
29 * mod.c
30 * mod_gadget.c
31 * mod_host.c pipe.c fifo.c
32 *
33 * +-------+ +-----------+
34 * | pipe0 |------>| fifo pio |
35 * +------------+ +-------+ +-----------+
36 * | mod_gadget |=====> | pipe1 |--+
37 * +------------+ +-------+ | +-----------+
38 * | pipe2 | | +-| fifo dma0 |
39 * +------------+ +-------+ | | +-----------+
40 * | mod_host | | pipe3 |<-|--+
41 * +------------+ +-------+ | +-----------+
42 * | .... | +--->| fifo dma1 |
43 * | .... | +-----------+
44 */
45
46
24#define USBHSF_RUNTIME_PWCTRL (1 << 0) 47#define USBHSF_RUNTIME_PWCTRL (1 << 0)
25 48
26/* status */ 49/* status */
@@ -304,6 +327,8 @@ static int __devinit usbhs_probe(struct platform_device *pdev)
304 priv->dparam->pipe_type = usbhsc_default_pipe_type; 327 priv->dparam->pipe_type = usbhsc_default_pipe_type;
305 priv->dparam->pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type); 328 priv->dparam->pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type);
306 } 329 }
330 if (!priv->dparam->pio_dma_border)
331 priv->dparam->pio_dma_border = 64; /* 64byte */
307 332
308 /* FIXME */ 333 /* FIXME */
309 /* runtime power control ? */ 334 /* runtime power control ? */
@@ -323,10 +348,14 @@ static int __devinit usbhs_probe(struct platform_device *pdev)
323 if (ret < 0) 348 if (ret < 0)
324 goto probe_end_iounmap; 349 goto probe_end_iounmap;
325 350
326 ret = usbhs_mod_probe(priv); 351 ret = usbhs_fifo_probe(priv);
327 if (ret < 0) 352 if (ret < 0)
328 goto probe_end_pipe_exit; 353 goto probe_end_pipe_exit;
329 354
355 ret = usbhs_mod_probe(priv);
356 if (ret < 0)
357 goto probe_end_fifo_exit;
358
330 /* dev_set_drvdata should be called after usbhs_mod_init */ 359 /* dev_set_drvdata should be called after usbhs_mod_init */
331 dev_set_drvdata(&pdev->dev, priv); 360 dev_set_drvdata(&pdev->dev, priv);
332 361
@@ -374,6 +403,8 @@ probe_end_call_remove:
374 usbhs_platform_call(priv, hardware_exit, pdev); 403 usbhs_platform_call(priv, hardware_exit, pdev);
375probe_end_mod_exit: 404probe_end_mod_exit:
376 usbhs_mod_remove(priv); 405 usbhs_mod_remove(priv);
406probe_end_fifo_exit:
407 usbhs_fifo_remove(priv);
377probe_end_pipe_exit: 408probe_end_pipe_exit:
378 usbhs_pipe_remove(priv); 409 usbhs_pipe_remove(priv);
379probe_end_iounmap: 410probe_end_iounmap:
@@ -404,6 +435,7 @@ static int __devexit usbhs_remove(struct platform_device *pdev)
404 435
405 usbhs_platform_call(priv, hardware_exit, pdev); 436 usbhs_platform_call(priv, hardware_exit, pdev);
406 usbhs_mod_remove(priv); 437 usbhs_mod_remove(priv);
438 usbhs_fifo_remove(priv);
407 usbhs_pipe_remove(priv); 439 usbhs_pipe_remove(priv);
408 iounmap(priv->base); 440 iounmap(priv->base);
409 kfree(priv); 441 kfree(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h
index 0aadcb402764..b410463a1212 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -36,6 +36,12 @@ struct usbhs_priv;
36#define CFIFO 0x0014 36#define CFIFO 0x0014
37#define CFIFOSEL 0x0020 37#define CFIFOSEL 0x0020
38#define CFIFOCTR 0x0022 38#define CFIFOCTR 0x0022
39#define D0FIFO 0x0100
40#define D0FIFOSEL 0x0028
41#define D0FIFOCTR 0x002A
42#define D1FIFO 0x0120
43#define D1FIFOSEL 0x002C
44#define D1FIFOCTR 0x002E
39#define INTENB0 0x0030 45#define INTENB0 0x0030
40#define INTENB1 0x0032 46#define INTENB1 0x0032
41#define BRDYENB 0x0036 47#define BRDYENB 0x0036
@@ -60,6 +66,30 @@ struct usbhs_priv;
60#define PIPEMAXP 0x006C 66#define PIPEMAXP 0x006C
61#define PIPEPERI 0x006E 67#define PIPEPERI 0x006E
62#define PIPEnCTR 0x0070 68#define PIPEnCTR 0x0070
69#define PIPE1TRE 0x0090
70#define PIPE1TRN 0x0092
71#define PIPE2TRE 0x0094
72#define PIPE2TRN 0x0096
73#define PIPE3TRE 0x0098
74#define PIPE3TRN 0x009A
75#define PIPE4TRE 0x009C
76#define PIPE4TRN 0x009E
77#define PIPE5TRE 0x00A0
78#define PIPE5TRN 0x00A2
79#define PIPEBTRE 0x00A4
80#define PIPEBTRN 0x00A6
81#define PIPECTRE 0x00A8
82#define PIPECTRN 0x00AA
83#define PIPEDTRE 0x00AC
84#define PIPEDTRN 0x00AE
85#define PIPEETRE 0x00B0
86#define PIPEETRN 0x00B2
87#define PIPEFTRE 0x00B4
88#define PIPEFTRN 0x00B6
89#define PIPE9TRE 0x00B8
90#define PIPE9TRN 0x00BA
91#define PIPEATRE 0x00BC
92#define PIPEATRN 0x00BE
63 93
64/* SYSCFG */ 94/* SYSCFG */
65#define SCKE (1 << 10) /* USB Module Clock Enable */ 95#define SCKE (1 << 10) /* USB Module Clock Enable */
@@ -78,6 +108,7 @@ struct usbhs_priv;
78#define RHST_HIGH_SPEED 3 /* High-speed connection */ 108#define RHST_HIGH_SPEED 3 /* High-speed connection */
79 109
80/* CFIFOSEL */ 110/* CFIFOSEL */
111#define DREQE (1 << 12) /* DMA Transfer Request Enable */
81#define MBW_32 (0x2 << 10) /* CFIFO Port Access Bit Width */ 112#define MBW_32 (0x2 << 10) /* CFIFO Port Access Bit Width */
82 113
83/* CFIFOCTR */ 114/* CFIFOCTR */
@@ -164,6 +195,10 @@ struct usbhs_priv;
164 195
165#define CCPL (1 << 2) /* Control Transfer End Enable */ 196#define CCPL (1 << 2) /* Control Transfer End Enable */
166 197
198/* PIPEnTRE */
199#define TRENB (1 << 9) /* Transaction Counter Enable */
200#define TRCLR (1 << 8) /* Transaction Counter Clear */
201
167/* FRMNUM */ 202/* FRMNUM */
168#define FRNM_MASK (0x7FF) 203#define FRNM_MASK (0x7FF)
169 204
@@ -194,6 +229,11 @@ struct usbhs_priv {
194 * pipe control 229 * pipe control
195 */ 230 */
196 struct usbhs_pipe_info pipe_info; 231 struct usbhs_pipe_info pipe_info;
232
233 /*
234 * fifo control
235 */
236 struct usbhs_fifo_info fifo_info;
197}; 237};
198 238
199/* 239/*
@@ -204,6 +244,10 @@ void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data);
204void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data); 244void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data);
205 245
206int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev); 246int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev);
247
248#define usbhs_lock(p, f) spin_lock_irqsave(usbhs_priv_to_lock(p), f)
249#define usbhs_unlock(p, f) spin_unlock_irqrestore(usbhs_priv_to_lock(p), f)
250
207/* 251/*
208 * sysconfig 252 * sysconfig
209 */ 253 */
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
new file mode 100644
index 000000000000..406893e4422b
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -0,0 +1,1015 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#include <linux/delay.h>
18#include <linux/io.h>
19#include "./common.h"
20#include "./pipe.h"
21
22#define usbhsf_get_cfifo(p) (&((p)->fifo_info.cfifo))
23#define usbhsf_get_d0fifo(p) (&((p)->fifo_info.d0fifo))
24#define usbhsf_get_d1fifo(p) (&((p)->fifo_info.d1fifo))
25
26#define usbhsf_fifo_is_busy(f) ((f)->pipe) /* see usbhs_pipe_select_fifo */
27
28/*
29 * packet initialize
30 */
31void usbhs_pkt_init(struct usbhs_pkt *pkt)
32{
33 pkt->dma = DMA_ADDR_INVALID;
34 INIT_LIST_HEAD(&pkt->node);
35}
36
37/*
38 * packet control function
39 */
40static int usbhsf_null_handle(struct usbhs_pkt *pkt, int *is_done)
41{
42 struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe);
43 struct device *dev = usbhs_priv_to_dev(priv);
44
45 dev_err(dev, "null handler\n");
46
47 return -EINVAL;
48}
49
50static struct usbhs_pkt_handle usbhsf_null_handler = {
51 .prepare = usbhsf_null_handle,
52 .try_run = usbhsf_null_handle,
53};
54
55void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
56 struct usbhs_pkt_handle *handler,
57 void *buf, int len, int zero)
58{
59 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
60 struct device *dev = usbhs_priv_to_dev(priv);
61 unsigned long flags;
62
63 /******************** spin lock ********************/
64 usbhs_lock(priv, flags);
65
66 if (!handler) {
67 dev_err(dev, "no handler function\n");
68 handler = &usbhsf_null_handler;
69 }
70
71 list_del_init(&pkt->node);
72 list_add_tail(&pkt->node, &pipe->list);
73
74 pkt->pipe = pipe;
75 pkt->buf = buf;
76 pkt->handler = handler;
77 pkt->length = len;
78 pkt->zero = zero;
79 pkt->actual = 0;
80
81 usbhs_unlock(priv, flags);
82 /******************** spin unlock ******************/
83
84 usbhs_pkt_start(pipe);
85}
86
87static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
88{
89 list_del_init(&pkt->node);
90}
91
92static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
93{
94 if (list_empty(&pipe->list))
95 return NULL;
96
97 return list_entry(pipe->list.next, struct usbhs_pkt, node);
98}
99
100struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt)
101{
102 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
103 unsigned long flags;
104
105 /******************** spin lock ********************/
106 usbhs_lock(priv, flags);
107
108 if (!pkt)
109 pkt = __usbhsf_pkt_get(pipe);
110
111 if (pkt)
112 __usbhsf_pkt_del(pkt);
113
114 usbhs_unlock(priv, flags);
115 /******************** spin unlock ******************/
116
117 return pkt;
118}
119
120int __usbhs_pkt_handler(struct usbhs_pipe *pipe, int type)
121{
122 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
123 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
124 struct usbhs_pkt *pkt;
125 struct device *dev = usbhs_priv_to_dev(priv);
126 int (*func)(struct usbhs_pkt *pkt, int *is_done);
127 unsigned long flags;
128 int ret = 0;
129 int is_done = 0;
130
131 /******************** spin lock ********************/
132 usbhs_lock(priv, flags);
133
134 pkt = __usbhsf_pkt_get(pipe);
135 if (!pkt)
136 goto __usbhs_pkt_handler_end;
137
138 switch (type) {
139 case USBHSF_PKT_PREPARE:
140 func = pkt->handler->prepare;
141 break;
142 case USBHSF_PKT_TRY_RUN:
143 func = pkt->handler->try_run;
144 break;
145 case USBHSF_PKT_DMA_DONE:
146 func = pkt->handler->dma_done;
147 break;
148 default:
149 dev_err(dev, "unknown pkt hander\n");
150 goto __usbhs_pkt_handler_end;
151 }
152
153 ret = func(pkt, &is_done);
154
155 if (is_done)
156 __usbhsf_pkt_del(pkt);
157
158__usbhs_pkt_handler_end:
159 usbhs_unlock(priv, flags);
160 /******************** spin unlock ******************/
161
162 if (is_done) {
163 info->done(pkt);
164 usbhs_pkt_start(pipe);
165 }
166
167 return ret;
168}
169
170/*
171 * irq enable/disable function
172 */
173#define usbhsf_irq_empty_ctrl(p, e) usbhsf_irq_callback_ctrl(p, bempsts, e)
174#define usbhsf_irq_ready_ctrl(p, e) usbhsf_irq_callback_ctrl(p, brdysts, e)
175#define usbhsf_irq_callback_ctrl(pipe, status, enable) \
176 ({ \
177 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); \
178 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
179 u16 status = (1 << usbhs_pipe_number(pipe)); \
180 if (!mod) \
181 return; \
182 if (enable) \
183 mod->irq_##status |= status; \
184 else \
185 mod->irq_##status &= ~status; \
186 usbhs_irq_callback_update(priv, mod); \
187 })
188
189static void usbhsf_tx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
190{
191 /*
192 * And DCP pipe can NOT use "ready interrupt" for "send"
193 * it should use "empty" interrupt.
194 * see
195 * "Operation" - "Interrupt Function" - "BRDY Interrupt"
196 *
197 * on the other hand, normal pipe can use "ready interrupt" for "send"
198 * even though it is single/double buffer
199 */
200 if (usbhs_pipe_is_dcp(pipe))
201 usbhsf_irq_empty_ctrl(pipe, enable);
202 else
203 usbhsf_irq_ready_ctrl(pipe, enable);
204}
205
206static void usbhsf_rx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
207{
208 usbhsf_irq_ready_ctrl(pipe, enable);
209}
210
211/*
212 * FIFO ctrl
213 */
214static void usbhsf_send_terminator(struct usbhs_pipe *pipe,
215 struct usbhs_fifo *fifo)
216{
217 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
218
219 usbhs_bset(priv, fifo->ctr, BVAL, BVAL);
220}
221
222static int usbhsf_fifo_barrier(struct usbhs_priv *priv,
223 struct usbhs_fifo *fifo)
224{
225 int timeout = 1024;
226
227 do {
228 /* The FIFO port is accessible */
229 if (usbhs_read(priv, fifo->ctr) & FRDY)
230 return 0;
231
232 udelay(10);
233 } while (timeout--);
234
235 return -EBUSY;
236}
237
238static void usbhsf_fifo_clear(struct usbhs_pipe *pipe,
239 struct usbhs_fifo *fifo)
240{
241 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
242
243 if (!usbhs_pipe_is_dcp(pipe))
244 usbhsf_fifo_barrier(priv, fifo);
245
246 usbhs_write(priv, fifo->ctr, BCLR);
247}
248
249static int usbhsf_fifo_rcv_len(struct usbhs_priv *priv,
250 struct usbhs_fifo *fifo)
251{
252 return usbhs_read(priv, fifo->ctr) & DTLN_MASK;
253}
254
255static void usbhsf_fifo_unselect(struct usbhs_pipe *pipe,
256 struct usbhs_fifo *fifo)
257{
258 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
259
260 usbhs_pipe_select_fifo(pipe, NULL);
261 usbhs_write(priv, fifo->sel, 0);
262}
263
264static int usbhsf_fifo_select(struct usbhs_pipe *pipe,
265 struct usbhs_fifo *fifo,
266 int write)
267{
268 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
269 struct device *dev = usbhs_priv_to_dev(priv);
270 int timeout = 1024;
271 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
272 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
273
274 if (usbhs_pipe_is_busy(pipe) ||
275 usbhsf_fifo_is_busy(fifo))
276 return -EBUSY;
277
278 if (usbhs_pipe_is_dcp(pipe))
279 base |= (1 == write) << 5; /* ISEL */
280
281 /* "base" will be used below */
282 usbhs_write(priv, fifo->sel, base | MBW_32);
283
284 /* check ISEL and CURPIPE value */
285 while (timeout--) {
286 if (base == (mask & usbhs_read(priv, fifo->sel))) {
287 usbhs_pipe_select_fifo(pipe, fifo);
288 return 0;
289 }
290 udelay(10);
291 }
292
293 dev_err(dev, "fifo select error\n");
294
295 return -EIO;
296}
297
298/*
299 * PIO push handler
300 */
301static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done)
302{
303 struct usbhs_pipe *pipe = pkt->pipe;
304 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
305 struct device *dev = usbhs_priv_to_dev(priv);
306 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
307 void __iomem *addr = priv->base + fifo->port;
308 u8 *buf;
309 int maxp = usbhs_pipe_get_maxpacket(pipe);
310 int total_len;
311 int i, ret, len;
312 int is_short;
313
314 ret = usbhsf_fifo_select(pipe, fifo, 1);
315 if (ret < 0)
316 return 0;
317
318 ret = usbhs_pipe_is_accessible(pipe);
319 if (ret < 0) {
320 /* inaccessible pipe is not an error */
321 ret = 0;
322 goto usbhs_fifo_write_busy;
323 }
324
325 ret = usbhsf_fifo_barrier(priv, fifo);
326 if (ret < 0)
327 goto usbhs_fifo_write_busy;
328
329 buf = pkt->buf + pkt->actual;
330 len = pkt->length - pkt->actual;
331 len = min(len, maxp);
332 total_len = len;
333 is_short = total_len < maxp;
334
335 /*
336 * FIXME
337 *
338 * 32-bit access only
339 */
340 if (len >= 4 && !((unsigned long)buf & 0x03)) {
341 iowrite32_rep(addr, buf, len / 4);
342 len %= 4;
343 buf += total_len - len;
344 }
345
346 /* the rest operation */
347 for (i = 0; i < len; i++)
348 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
349
350 /*
351 * variable update
352 */
353 pkt->actual += total_len;
354
355 if (pkt->actual < pkt->length)
356 *is_done = 0; /* there are remainder data */
357 else if (is_short)
358 *is_done = 1; /* short packet */
359 else
360 *is_done = !pkt->zero; /* send zero packet ? */
361
362 /*
363 * pipe/irq handling
364 */
365 if (is_short)
366 usbhsf_send_terminator(pipe, fifo);
367
368 usbhsf_tx_irq_ctrl(pipe, !*is_done);
369 usbhs_pipe_enable(pipe);
370
371 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
372 usbhs_pipe_number(pipe),
373 pkt->length, pkt->actual, *is_done, pkt->zero);
374
375 /*
376 * Transmission end
377 */
378 if (*is_done) {
379 if (usbhs_pipe_is_dcp(pipe))
380 usbhs_dcp_control_transfer_done(pipe);
381 }
382
383 usbhsf_fifo_unselect(pipe, fifo);
384
385 return 0;
386
387usbhs_fifo_write_busy:
388 usbhsf_fifo_unselect(pipe, fifo);
389
390 /*
391 * pipe is busy.
392 * retry in interrupt
393 */
394 usbhsf_tx_irq_ctrl(pipe, 1);
395
396 return ret;
397}
398
399struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = {
400 .prepare = usbhsf_pio_try_push,
401 .try_run = usbhsf_pio_try_push,
402};
403
404/*
405 * PIO pop handler
406 */
407static int usbhsf_prepare_pop(struct usbhs_pkt *pkt, int *is_done)
408{
409 struct usbhs_pipe *pipe = pkt->pipe;
410
411 if (usbhs_pipe_is_busy(pipe))
412 return 0;
413
414 /*
415 * pipe enable to prepare packet receive
416 */
417
418 usbhs_pipe_enable(pipe);
419 usbhsf_rx_irq_ctrl(pipe, 1);
420
421 return 0;
422}
423
424static int usbhsf_pio_try_pop(struct usbhs_pkt *pkt, int *is_done)
425{
426 struct usbhs_pipe *pipe = pkt->pipe;
427 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
428 struct device *dev = usbhs_priv_to_dev(priv);
429 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
430 void __iomem *addr = priv->base + fifo->port;
431 u8 *buf;
432 u32 data = 0;
433 int maxp = usbhs_pipe_get_maxpacket(pipe);
434 int rcv_len, len;
435 int i, ret;
436 int total_len = 0;
437
438 ret = usbhsf_fifo_select(pipe, fifo, 0);
439 if (ret < 0)
440 return 0;
441
442 ret = usbhsf_fifo_barrier(priv, fifo);
443 if (ret < 0)
444 goto usbhs_fifo_read_busy;
445
446 rcv_len = usbhsf_fifo_rcv_len(priv, fifo);
447
448 buf = pkt->buf + pkt->actual;
449 len = pkt->length - pkt->actual;
450 len = min(len, rcv_len);
451 total_len = len;
452
453 /*
454 * Buffer clear if Zero-Length packet
455 *
456 * see
457 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
458 */
459 if (0 == rcv_len) {
460 usbhsf_fifo_clear(pipe, fifo);
461 goto usbhs_fifo_read_end;
462 }
463
464 /*
465 * FIXME
466 *
467 * 32-bit access only
468 */
469 if (len >= 4 && !((unsigned long)buf & 0x03)) {
470 ioread32_rep(addr, buf, len / 4);
471 len %= 4;
472 buf += total_len - len;
473 }
474
475 /* the rest operation */
476 for (i = 0; i < len; i++) {
477 if (!(i & 0x03))
478 data = ioread32(addr);
479
480 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
481 }
482
483 pkt->actual += total_len;
484
485usbhs_fifo_read_end:
486 if ((pkt->actual == pkt->length) || /* receive all data */
487 (total_len < maxp)) { /* short packet */
488 *is_done = 1;
489 usbhsf_rx_irq_ctrl(pipe, 0);
490 usbhs_pipe_disable(pipe);
491 }
492
493 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
494 usbhs_pipe_number(pipe),
495 pkt->length, pkt->actual, *is_done, pkt->zero);
496
497usbhs_fifo_read_busy:
498 usbhsf_fifo_unselect(pipe, fifo);
499
500 return ret;
501}
502
503struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler = {
504 .prepare = usbhsf_prepare_pop,
505 .try_run = usbhsf_pio_try_pop,
506};
507
508/*
509 * DCP ctrol statge handler
510 */
511static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt, int *is_done)
512{
513 usbhs_dcp_control_transfer_done(pkt->pipe);
514
515 *is_done = 1;
516
517 return 0;
518}
519
520struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler = {
521 .prepare = usbhsf_ctrl_stage_end,
522 .try_run = usbhsf_ctrl_stage_end,
523};
524
525/*
526 * DMA fifo functions
527 */
528static struct dma_chan *usbhsf_dma_chan_get(struct usbhs_fifo *fifo,
529 struct usbhs_pkt *pkt)
530{
531 if (&usbhs_fifo_dma_push_handler == pkt->handler)
532 return fifo->tx_chan;
533
534 if (&usbhs_fifo_dma_pop_handler == pkt->handler)
535 return fifo->rx_chan;
536
537 return NULL;
538}
539
540static struct usbhs_fifo *usbhsf_get_dma_fifo(struct usbhs_priv *priv,
541 struct usbhs_pkt *pkt)
542{
543 struct usbhs_fifo *fifo;
544
545 /* DMA :: D0FIFO */
546 fifo = usbhsf_get_d0fifo(priv);
547 if (usbhsf_dma_chan_get(fifo, pkt) &&
548 !usbhsf_fifo_is_busy(fifo))
549 return fifo;
550
551 /* DMA :: D1FIFO */
552 fifo = usbhsf_get_d1fifo(priv);
553 if (usbhsf_dma_chan_get(fifo, pkt) &&
554 !usbhsf_fifo_is_busy(fifo))
555 return fifo;
556
557 return NULL;
558}
559
560#define usbhsf_dma_start(p, f) __usbhsf_dma_ctrl(p, f, DREQE)
561#define usbhsf_dma_stop(p, f) __usbhsf_dma_ctrl(p, f, 0)
562static void __usbhsf_dma_ctrl(struct usbhs_pipe *pipe,
563 struct usbhs_fifo *fifo,
564 u16 dreqe)
565{
566 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
567
568 usbhs_bset(priv, fifo->sel, DREQE, dreqe);
569}
570
571#define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1)
572#define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0)
573static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
574{
575 struct usbhs_pipe *pipe = pkt->pipe;
576 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
577 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
578
579 return info->dma_map_ctrl(pkt, map);
580}
581
582static void usbhsf_dma_complete(void *arg);
583static void usbhsf_dma_prepare_tasklet(unsigned long data)
584{
585 struct usbhs_pkt *pkt = (struct usbhs_pkt *)data;
586 struct usbhs_pipe *pipe = pkt->pipe;
587 struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe);
588 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
589 struct scatterlist sg;
590 struct dma_async_tx_descriptor *desc;
591 struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt);
592 struct device *dev = usbhs_priv_to_dev(priv);
593 enum dma_data_direction dir;
594 dma_cookie_t cookie;
595
596 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
597
598 sg_init_table(&sg, 1);
599 sg_set_page(&sg, virt_to_page(pkt->dma),
600 pkt->length, offset_in_page(pkt->dma));
601 sg_dma_address(&sg) = pkt->dma + pkt->actual;
602 sg_dma_len(&sg) = pkt->trans;
603
604 desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir,
605 DMA_PREP_INTERRUPT |
606 DMA_CTRL_ACK);
607 if (!desc)
608 return;
609
610 desc->callback = usbhsf_dma_complete;
611 desc->callback_param = pipe;
612
613 cookie = desc->tx_submit(desc);
614 if (cookie < 0) {
615 dev_err(dev, "Failed to submit dma descriptor\n");
616 return;
617 }
618
619 dev_dbg(dev, " %s %d (%d/ %d)\n",
620 fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero);
621
622 usbhsf_dma_start(pipe, fifo);
623 dma_async_issue_pending(chan);
624}
625
626/*
627 * DMA push handler
628 */
629static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
630{
631 struct usbhs_pipe *pipe = pkt->pipe;
632 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
633 struct usbhs_fifo *fifo;
634 int len = pkt->length - pkt->actual;
635 int ret;
636
637 if (usbhs_pipe_is_busy(pipe))
638 return 0;
639
640 /* use PIO if packet is less than pio_dma_border or pipe is DCP */
641 if ((len < usbhs_get_dparam(priv, pio_dma_border)) ||
642 usbhs_pipe_is_dcp(pipe))
643 goto usbhsf_pio_prepare_push;
644
645 if (len % 4) /* 32bit alignment */
646 goto usbhsf_pio_prepare_push;
647
648 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
649 goto usbhsf_pio_prepare_push;
650
651 /* get enable DMA fifo */
652 fifo = usbhsf_get_dma_fifo(priv, pkt);
653 if (!fifo)
654 goto usbhsf_pio_prepare_push;
655
656 if (usbhsf_dma_map(pkt) < 0)
657 goto usbhsf_pio_prepare_push;
658
659 ret = usbhsf_fifo_select(pipe, fifo, 0);
660 if (ret < 0)
661 goto usbhsf_pio_prepare_push_unmap;
662
663 pkt->trans = len;
664
665 tasklet_init(&fifo->tasklet,
666 usbhsf_dma_prepare_tasklet,
667 (unsigned long)pkt);
668
669 tasklet_schedule(&fifo->tasklet);
670
671 return 0;
672
673usbhsf_pio_prepare_push_unmap:
674 usbhsf_dma_unmap(pkt);
675usbhsf_pio_prepare_push:
676 /*
677 * change handler to PIO
678 */
679 pkt->handler = &usbhs_fifo_pio_push_handler;
680
681 return pkt->handler->prepare(pkt, is_done);
682}
683
684static int usbhsf_dma_push_done(struct usbhs_pkt *pkt, int *is_done)
685{
686 struct usbhs_pipe *pipe = pkt->pipe;
687
688 pkt->actual = pkt->trans;
689
690 *is_done = !pkt->zero; /* send zero packet ? */
691
692 usbhsf_dma_stop(pipe, pipe->fifo);
693 usbhsf_dma_unmap(pkt);
694 usbhsf_fifo_unselect(pipe, pipe->fifo);
695
696 return 0;
697}
698
699struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = {
700 .prepare = usbhsf_dma_prepare_push,
701 .dma_done = usbhsf_dma_push_done,
702};
703
704/*
705 * DMA pop handler
706 */
707static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done)
708{
709 struct usbhs_pipe *pipe = pkt->pipe;
710 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
711 struct usbhs_fifo *fifo;
712 int len, ret;
713
714 if (usbhs_pipe_is_busy(pipe))
715 return 0;
716
717 if (usbhs_pipe_is_dcp(pipe))
718 goto usbhsf_pio_prepare_pop;
719
720 /* get enable DMA fifo */
721 fifo = usbhsf_get_dma_fifo(priv, pkt);
722 if (!fifo)
723 goto usbhsf_pio_prepare_pop;
724
725 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
726 goto usbhsf_pio_prepare_pop;
727
728 ret = usbhsf_fifo_select(pipe, fifo, 0);
729 if (ret < 0)
730 goto usbhsf_pio_prepare_pop;
731
732 /* use PIO if packet is less than pio_dma_border */
733 len = usbhsf_fifo_rcv_len(priv, fifo);
734 len = min(pkt->length - pkt->actual, len);
735 if (len % 4) /* 32bit alignment */
736 goto usbhsf_pio_prepare_pop_unselect;
737
738 if (len < usbhs_get_dparam(priv, pio_dma_border))
739 goto usbhsf_pio_prepare_pop_unselect;
740
741 ret = usbhsf_fifo_barrier(priv, fifo);
742 if (ret < 0)
743 goto usbhsf_pio_prepare_pop_unselect;
744
745 if (usbhsf_dma_map(pkt) < 0)
746 goto usbhsf_pio_prepare_pop_unselect;
747
748 /* DMA */
749
750 /*
751 * usbhs_fifo_dma_pop_handler :: prepare
752 * enabled irq to come here.
753 * but it is no longer needed for DMA. disable it.
754 */
755 usbhsf_rx_irq_ctrl(pipe, 0);
756
757 pkt->trans = len;
758
759 tasklet_init(&fifo->tasklet,
760 usbhsf_dma_prepare_tasklet,
761 (unsigned long)pkt);
762
763 tasklet_schedule(&fifo->tasklet);
764
765 return 0;
766
767usbhsf_pio_prepare_pop_unselect:
768 usbhsf_fifo_unselect(pipe, fifo);
769usbhsf_pio_prepare_pop:
770
771 /*
772 * change handler to PIO
773 */
774 pkt->handler = &usbhs_fifo_pio_pop_handler;
775
776 return pkt->handler->try_run(pkt, is_done);
777}
778
779static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done)
780{
781 struct usbhs_pipe *pipe = pkt->pipe;
782 int maxp = usbhs_pipe_get_maxpacket(pipe);
783
784 usbhsf_dma_stop(pipe, pipe->fifo);
785 usbhsf_dma_unmap(pkt);
786 usbhsf_fifo_unselect(pipe, pipe->fifo);
787
788 pkt->actual += pkt->trans;
789
790 if ((pkt->actual == pkt->length) || /* receive all data */
791 (pkt->trans < maxp)) { /* short packet */
792 *is_done = 1;
793 } else {
794 /* re-enable */
795 usbhsf_prepare_pop(pkt, is_done);
796 }
797
798 return 0;
799}
800
801struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = {
802 .prepare = usbhsf_prepare_pop,
803 .try_run = usbhsf_dma_try_pop,
804 .dma_done = usbhsf_dma_pop_done
805};
806
807/*
808 * DMA setting
809 */
810static bool usbhsf_dma_filter(struct dma_chan *chan, void *param)
811{
812 struct sh_dmae_slave *slave = param;
813
814 /*
815 * FIXME
816 *
817 * usbhs doesn't recognize id = 0 as valid DMA
818 */
819 if (0 == slave->slave_id)
820 return false;
821
822 chan->private = slave;
823
824 return true;
825}
826
827static void usbhsf_dma_quit(struct usbhs_priv *priv, struct usbhs_fifo *fifo)
828{
829 if (fifo->tx_chan)
830 dma_release_channel(fifo->tx_chan);
831 if (fifo->rx_chan)
832 dma_release_channel(fifo->rx_chan);
833
834 fifo->tx_chan = NULL;
835 fifo->rx_chan = NULL;
836}
837
838static void usbhsf_dma_init(struct usbhs_priv *priv,
839 struct usbhs_fifo *fifo)
840{
841 struct device *dev = usbhs_priv_to_dev(priv);
842 dma_cap_mask_t mask;
843
844 dma_cap_zero(mask);
845 dma_cap_set(DMA_SLAVE, mask);
846 fifo->tx_chan = dma_request_channel(mask, usbhsf_dma_filter,
847 &fifo->tx_slave);
848
849 dma_cap_zero(mask);
850 dma_cap_set(DMA_SLAVE, mask);
851 fifo->rx_chan = dma_request_channel(mask, usbhsf_dma_filter,
852 &fifo->rx_slave);
853
854 if (fifo->tx_chan || fifo->rx_chan)
855 dev_dbg(dev, "enable DMAEngine (%s%s%s)\n",
856 fifo->name,
857 fifo->tx_chan ? "[TX]" : " ",
858 fifo->rx_chan ? "[RX]" : " ");
859}
860
861/*
862 * irq functions
863 */
864static int usbhsf_irq_empty(struct usbhs_priv *priv,
865 struct usbhs_irq_state *irq_state)
866{
867 struct usbhs_pipe *pipe;
868 struct device *dev = usbhs_priv_to_dev(priv);
869 int i, ret;
870
871 if (!irq_state->bempsts) {
872 dev_err(dev, "debug %s !!\n", __func__);
873 return -EIO;
874 }
875
876 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
877
878 /*
879 * search interrupted "pipe"
880 * not "uep".
881 */
882 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
883 if (!(irq_state->bempsts & (1 << i)))
884 continue;
885
886 ret = usbhs_pkt_run(pipe);
887 if (ret < 0)
888 dev_err(dev, "irq_empty run_error %d : %d\n", i, ret);
889 }
890
891 return 0;
892}
893
894static int usbhsf_irq_ready(struct usbhs_priv *priv,
895 struct usbhs_irq_state *irq_state)
896{
897 struct usbhs_pipe *pipe;
898 struct device *dev = usbhs_priv_to_dev(priv);
899 int i, ret;
900
901 if (!irq_state->brdysts) {
902 dev_err(dev, "debug %s !!\n", __func__);
903 return -EIO;
904 }
905
906 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
907
908 /*
909 * search interrupted "pipe"
910 * not "uep".
911 */
912 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
913 if (!(irq_state->brdysts & (1 << i)))
914 continue;
915
916 ret = usbhs_pkt_run(pipe);
917 if (ret < 0)
918 dev_err(dev, "irq_ready run_error %d : %d\n", i, ret);
919 }
920
921 return 0;
922}
923
924static void usbhsf_dma_complete(void *arg)
925{
926 struct usbhs_pipe *pipe = arg;
927 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
928 struct device *dev = usbhs_priv_to_dev(priv);
929 int ret;
930
931 ret = usbhs_pkt_dmadone(pipe);
932 if (ret < 0)
933 dev_err(dev, "dma_complete run_error %d : %d\n",
934 usbhs_pipe_number(pipe), ret);
935}
936
937/*
938 * fifo init
939 */
940void usbhs_fifo_init(struct usbhs_priv *priv)
941{
942 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
943 struct usbhs_fifo *cfifo = usbhsf_get_cfifo(priv);
944 struct usbhs_fifo *d0fifo = usbhsf_get_d0fifo(priv);
945 struct usbhs_fifo *d1fifo = usbhsf_get_d1fifo(priv);
946
947 mod->irq_empty = usbhsf_irq_empty;
948 mod->irq_ready = usbhsf_irq_ready;
949 mod->irq_bempsts = 0;
950 mod->irq_brdysts = 0;
951
952 cfifo->pipe = NULL;
953 cfifo->tx_chan = NULL;
954 cfifo->rx_chan = NULL;
955
956 d0fifo->pipe = NULL;
957 d0fifo->tx_chan = NULL;
958 d0fifo->rx_chan = NULL;
959
960 d1fifo->pipe = NULL;
961 d1fifo->tx_chan = NULL;
962 d1fifo->rx_chan = NULL;
963
964 usbhsf_dma_init(priv, usbhsf_get_d0fifo(priv));
965 usbhsf_dma_init(priv, usbhsf_get_d1fifo(priv));
966}
967
968void usbhs_fifo_quit(struct usbhs_priv *priv)
969{
970 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
971
972 mod->irq_empty = NULL;
973 mod->irq_ready = NULL;
974 mod->irq_bempsts = 0;
975 mod->irq_brdysts = 0;
976
977 usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv));
978 usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv));
979}
980
981int usbhs_fifo_probe(struct usbhs_priv *priv)
982{
983 struct usbhs_fifo *fifo;
984
985 /* CFIFO */
986 fifo = usbhsf_get_cfifo(priv);
987 fifo->name = "CFIFO";
988 fifo->port = CFIFO;
989 fifo->sel = CFIFOSEL;
990 fifo->ctr = CFIFOCTR;
991
992 /* D0FIFO */
993 fifo = usbhsf_get_d0fifo(priv);
994 fifo->name = "D0FIFO";
995 fifo->port = D0FIFO;
996 fifo->sel = D0FIFOSEL;
997 fifo->ctr = D0FIFOCTR;
998 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id);
999 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id);
1000
1001 /* D1FIFO */
1002 fifo = usbhsf_get_d1fifo(priv);
1003 fifo->name = "D1FIFO";
1004 fifo->port = D1FIFO;
1005 fifo->sel = D1FIFOSEL;
1006 fifo->ctr = D1FIFOCTR;
1007 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id);
1008 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id);
1009
1010 return 0;
1011}
1012
1013void usbhs_fifo_remove(struct usbhs_priv *priv)
1014{
1015}
diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h
new file mode 100644
index 000000000000..ed6d8e56c13c
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/fifo.h
@@ -0,0 +1,104 @@
1/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#ifndef RENESAS_USB_FIFO_H
18#define RENESAS_USB_FIFO_H
19
20#include <linux/interrupt.h>
21#include <linux/sh_dma.h>
22#include <asm/dma.h>
23#include "pipe.h"
24
25#define DMA_ADDR_INVALID (~(dma_addr_t)0)
26
27struct usbhs_fifo {
28 char *name;
29 u32 port; /* xFIFO */
30 u32 sel; /* xFIFOSEL */
31 u32 ctr; /* xFIFOCTR */
32
33 struct usbhs_pipe *pipe;
34 struct tasklet_struct tasklet;
35
36 struct dma_chan *tx_chan;
37 struct dma_chan *rx_chan;
38
39 struct sh_dmae_slave tx_slave;
40 struct sh_dmae_slave rx_slave;
41};
42
43struct usbhs_fifo_info {
44 struct usbhs_fifo cfifo;
45 struct usbhs_fifo d0fifo;
46 struct usbhs_fifo d1fifo;
47};
48
49struct usbhs_pkt_handle;
50struct usbhs_pkt {
51 struct list_head node;
52 struct usbhs_pipe *pipe;
53 struct usbhs_pkt_handle *handler;
54 dma_addr_t dma;
55 void *buf;
56 int length;
57 int trans;
58 int actual;
59 int zero;
60};
61
62struct usbhs_pkt_handle {
63 int (*prepare)(struct usbhs_pkt *pkt, int *is_done);
64 int (*try_run)(struct usbhs_pkt *pkt, int *is_done);
65 int (*dma_done)(struct usbhs_pkt *pkt, int *is_done);
66};
67
68/*
69 * fifo
70 */
71int usbhs_fifo_probe(struct usbhs_priv *priv);
72void usbhs_fifo_remove(struct usbhs_priv *priv);
73void usbhs_fifo_init(struct usbhs_priv *priv);
74void usbhs_fifo_quit(struct usbhs_priv *priv);
75
76/*
77 * packet info
78 */
79enum {
80 USBHSF_PKT_PREPARE,
81 USBHSF_PKT_TRY_RUN,
82 USBHSF_PKT_DMA_DONE,
83};
84
85extern struct usbhs_pkt_handle usbhs_fifo_pio_push_handler;
86extern struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler;
87extern struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
88
89extern struct usbhs_pkt_handle usbhs_fifo_dma_push_handler;
90extern struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler;
91
92
93void usbhs_pkt_init(struct usbhs_pkt *pkt);
94void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
95 struct usbhs_pkt_handle *handler,
96 void *buf, int len, int zero);
97struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
98int __usbhs_pkt_handler(struct usbhs_pipe *pipe, int type);
99
100#define usbhs_pkt_start(p) __usbhs_pkt_handler(p, USBHSF_PKT_PREPARE)
101#define usbhs_pkt_run(p) __usbhs_pkt_handler(p, USBHSF_PKT_TRY_RUN)
102#define usbhs_pkt_dmadone(p) __usbhs_pkt_handler(p, USBHSF_PKT_DMA_DONE)
103
104#endif /* RENESAS_USB_FIFO_H */
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 547486ccd059..ba79dbf5adbc 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -26,26 +26,25 @@
26 */ 26 */
27struct usbhsg_request { 27struct usbhsg_request {
28 struct usb_request req; 28 struct usb_request req;
29 struct list_head node; 29 struct usbhs_pkt pkt;
30}; 30};
31 31
32#define EP_NAME_SIZE 8 32#define EP_NAME_SIZE 8
33struct usbhsg_gpriv; 33struct usbhsg_gpriv;
34struct usbhsg_pipe_handle;
35struct usbhsg_uep { 34struct usbhsg_uep {
36 struct usb_ep ep; 35 struct usb_ep ep;
37 struct usbhs_pipe *pipe; 36 struct usbhs_pipe *pipe;
38 struct list_head list;
39 37
40 char ep_name[EP_NAME_SIZE]; 38 char ep_name[EP_NAME_SIZE];
41 39
42 struct usbhsg_gpriv *gpriv; 40 struct usbhsg_gpriv *gpriv;
43 struct usbhsg_pipe_handle *handler; 41 struct usbhs_pkt_handle *handler;
44}; 42};
45 43
46struct usbhsg_gpriv { 44struct usbhsg_gpriv {
47 struct usb_gadget gadget; 45 struct usb_gadget gadget;
48 struct usbhs_mod mod; 46 struct usbhs_mod mod;
47 struct list_head link;
49 48
50 struct usbhsg_uep *uep; 49 struct usbhsg_uep *uep;
51 int uep_size; 50 int uep_size;
@@ -58,12 +57,6 @@ struct usbhsg_gpriv {
58#define USBHSG_STATUS_WEDGE (1 << 2) 57#define USBHSG_STATUS_WEDGE (1 << 2)
59}; 58};
60 59
61struct usbhsg_pipe_handle {
62 int (*prepare)(struct usbhsg_uep *uep, struct usbhsg_request *ureq);
63 int (*try_run)(struct usbhsg_uep *uep, struct usbhsg_request *ureq);
64 void (*irq_mask)(struct usbhsg_uep *uep, int enable);
65};
66
67struct usbhsg_recip_handle { 60struct usbhsg_recip_handle {
68 char *name; 61 char *name;
69 int (*device)(struct usbhs_priv *priv, struct usbhsg_uep *uep, 62 int (*device)(struct usbhs_priv *priv, struct usbhsg_uep *uep,
@@ -100,7 +93,6 @@ struct usbhsg_recip_handle {
100 container_of(r, struct usbhsg_request, req) 93 container_of(r, struct usbhsg_request, req)
101 94
102#define usbhsg_ep_to_uep(e) container_of(e, struct usbhsg_uep, ep) 95#define usbhsg_ep_to_uep(e) container_of(e, struct usbhsg_uep, ep)
103#define usbhsg_gpriv_to_lock(gp) usbhs_priv_to_lock((gp)->mod.priv)
104#define usbhsg_gpriv_to_dev(gp) usbhs_priv_to_dev((gp)->mod.priv) 96#define usbhsg_gpriv_to_dev(gp) usbhs_priv_to_dev((gp)->mod.priv)
105#define usbhsg_gpriv_to_priv(gp) ((gp)->mod.priv) 97#define usbhsg_gpriv_to_priv(gp) ((gp)->mod.priv)
106#define usbhsg_gpriv_to_dcp(gp) ((gp)->uep) 98#define usbhsg_gpriv_to_dcp(gp) ((gp)->uep)
@@ -110,6 +102,10 @@ struct usbhsg_recip_handle {
110#define usbhsg_pipe_to_uep(p) ((p)->mod_private) 102#define usbhsg_pipe_to_uep(p) ((p)->mod_private)
111#define usbhsg_is_dcp(u) ((u) == usbhsg_gpriv_to_dcp((u)->gpriv)) 103#define usbhsg_is_dcp(u) ((u) == usbhsg_gpriv_to_dcp((u)->gpriv))
112 104
105#define usbhsg_ureq_to_pkt(u) (&(u)->pkt)
106#define usbhsg_pkt_to_ureq(i) \
107 container_of(i, struct usbhsg_request, pkt)
108
113#define usbhsg_is_not_connected(gp) ((gp)->gadget.speed == USB_SPEED_UNKNOWN) 109#define usbhsg_is_not_connected(gp) ((gp)->gadget.speed == USB_SPEED_UNKNOWN)
114 110
115/* status */ 111/* status */
@@ -118,37 +114,18 @@ struct usbhsg_recip_handle {
118#define usbhsg_status_clr(gp, b) (gp->status &= ~b) 114#define usbhsg_status_clr(gp, b) (gp->status &= ~b)
119#define usbhsg_status_has(gp, b) (gp->status & b) 115#define usbhsg_status_has(gp, b) (gp->status & b)
120 116
121/* 117/* controller */
122 * usbhsg_trylock 118LIST_HEAD(the_controller_link);
123 *
124 * This driver don't use spin_try_lock
125 * to avoid warning of CONFIG_DEBUG_SPINLOCK
126 */
127static spinlock_t *usbhsg_trylock(struct usbhsg_gpriv *gpriv,
128 unsigned long *flags)
129{
130 spinlock_t *lock = usbhsg_gpriv_to_lock(gpriv);
131
132 /* check spin lock status
133 * to avoid deadlock/nest */
134 if (spin_is_locked(lock))
135 return NULL;
136 119
137 spin_lock_irqsave(lock, *flags); 120#define usbhsg_for_each_controller(gpriv)\
138 121 list_for_each_entry(gpriv, &the_controller_link, link)
139 return lock; 122#define usbhsg_controller_register(gpriv)\
140} 123 list_add_tail(&(gpriv)->link, &the_controller_link)
141 124#define usbhsg_controller_unregister(gpriv)\
142static void usbhsg_unlock(spinlock_t *lock, unsigned long *flags) 125 list_del_init(&(gpriv)->link)
143{
144 if (!lock)
145 return;
146
147 spin_unlock_irqrestore(lock, *flags);
148}
149 126
150/* 127/*
151 * list push/pop 128 * queue push/pop
152 */ 129 */
153static void usbhsg_queue_push(struct usbhsg_uep *uep, 130static void usbhsg_queue_push(struct usbhsg_uep *uep,
154 struct usbhsg_request *ureq) 131 struct usbhsg_request *ureq)
@@ -156,79 +133,17 @@ static void usbhsg_queue_push(struct usbhsg_uep *uep,
156 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); 133 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
157 struct device *dev = usbhsg_gpriv_to_dev(gpriv); 134 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
158 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 135 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
136 struct usbhs_pkt *pkt = usbhsg_ureq_to_pkt(ureq);
137 struct usb_request *req = &ureq->req;
159 138
160 /* 139 req->actual = 0;
161 ********* assume under spin lock ********* 140 req->status = -EINPROGRESS;
162 */ 141 usbhs_pkt_push(pipe, pkt, uep->handler,
163 list_del_init(&ureq->node); 142 req->buf, req->length, req->zero);
164 list_add_tail(&ureq->node, &uep->list);
165 ureq->req.actual = 0;
166 ureq->req.status = -EINPROGRESS;
167 143
168 dev_dbg(dev, "pipe %d : queue push (%d)\n", 144 dev_dbg(dev, "pipe %d : queue push (%d)\n",
169 usbhs_pipe_number(pipe), 145 usbhs_pipe_number(pipe),
170 ureq->req.length); 146 req->length);
171}
172
173static struct usbhsg_request *usbhsg_queue_get(struct usbhsg_uep *uep)
174{
175 /*
176 ********* assume under spin lock *********
177 */
178 if (list_empty(&uep->list))
179 return NULL;
180
181 return list_entry(uep->list.next, struct usbhsg_request, node);
182}
183
184#define usbhsg_queue_prepare(uep) __usbhsg_queue_handler(uep, 1);
185#define usbhsg_queue_handle(uep) __usbhsg_queue_handler(uep, 0);
186static int __usbhsg_queue_handler(struct usbhsg_uep *uep, int prepare)
187{
188 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
189 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
190 struct usbhsg_request *ureq;
191 spinlock_t *lock;
192 unsigned long flags;
193 int ret = 0;
194
195 if (!uep->handler) {
196 dev_err(dev, "no handler function\n");
197 return -EIO;
198 }
199
200 /*
201 * CAUTION [*queue handler*]
202 *
203 * This function will be called for start/restart queue operation.
204 * OTOH the most much worry for USB driver is spinlock nest.
205 * Specially it are
206 * - usb_ep_ops :: queue
207 * - usb_request :: complete
208 *
209 * But the caller of this function need not care about spinlock.
210 * This function is using usbhsg_trylock for it.
211 * if "is_locked" is 1, this mean this function lock it.
212 * but if it is 0, this mean it is already under spin lock.
213 * see also
214 * CAUTION [*endpoint queue*]
215 * CAUTION [*request complete*]
216 */
217
218 /****************** spin try lock *******************/
219 lock = usbhsg_trylock(gpriv, &flags);
220
221 ureq = usbhsg_queue_get(uep);
222 if (ureq) {
223 if (prepare)
224 ret = uep->handler->prepare(uep, ureq);
225 else
226 ret = uep->handler->try_run(uep, ureq);
227 }
228 usbhsg_unlock(lock, &flags);
229 /******************** spin unlock ******************/
230
231 return ret;
232} 147}
233 148
234static void usbhsg_queue_pop(struct usbhsg_uep *uep, 149static void usbhsg_queue_pop(struct usbhsg_uep *uep,
@@ -239,289 +154,91 @@ static void usbhsg_queue_pop(struct usbhsg_uep *uep,
239 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 154 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
240 struct device *dev = usbhsg_gpriv_to_dev(gpriv); 155 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
241 156
242 /*
243 ********* assume under spin lock *********
244 */
245
246 /*
247 * CAUTION [*request complete*]
248 *
249 * There is a possibility not to be called in correct order
250 * if "complete" is called without spinlock.
251 *
252 * So, this function assume it is under spinlock,
253 * and call usb_request :: complete.
254 *
255 * But this "complete" will push next usb_request.
256 * It mean "usb_ep_ops :: queue" which is using spinlock is called
257 * under spinlock.
258 *
259 * To avoid dead-lock, this driver is using usbhsg_trylock.
260 * CAUTION [*endpoint queue*]
261 * CAUTION [*queue handler*]
262 */
263
264 dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe)); 157 dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe));
265 158
266 list_del_init(&ureq->node);
267
268 ureq->req.status = status; 159 ureq->req.status = status;
269 ureq->req.complete(&uep->ep, &ureq->req); 160 ureq->req.complete(&uep->ep, &ureq->req);
270
271 /* more request ? */
272 if (0 == status)
273 usbhsg_queue_prepare(uep);
274} 161}
275 162
276/* 163static void usbhsg_queue_done(struct usbhs_pkt *pkt)
277 * irq enable/disable function
278 */
279#define usbhsg_irq_callback_ctrl(uep, status, enable) \
280 ({ \
281 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); \
282 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); \
283 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); \
284 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
285 if (!mod) \
286 return; \
287 if (enable) \
288 mod->irq_##status |= (1 << usbhs_pipe_number(pipe)); \
289 else \
290 mod->irq_##status &= ~(1 << usbhs_pipe_number(pipe)); \
291 usbhs_irq_callback_update(priv, mod); \
292 })
293
294static void usbhsg_irq_empty_ctrl(struct usbhsg_uep *uep, int enable)
295{ 164{
296 usbhsg_irq_callback_ctrl(uep, bempsts, enable); 165 struct usbhs_pipe *pipe = pkt->pipe;
297} 166 struct usbhsg_uep *uep = usbhsg_pipe_to_uep(pipe);
167 struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt);
298 168
299static void usbhsg_irq_ready_ctrl(struct usbhsg_uep *uep, int enable) 169 ureq->req.actual = pkt->actual;
300{
301 usbhsg_irq_callback_ctrl(uep, brdysts, enable);
302}
303
304/*
305 * handler function
306 */
307static int usbhsg_try_run_ctrl_stage_end(struct usbhsg_uep *uep,
308 struct usbhsg_request *ureq)
309{
310 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
311
312 /*
313 ********* assume under spin lock *********
314 */
315 170
316 usbhs_dcp_control_transfer_done(pipe);
317 usbhsg_queue_pop(uep, ureq, 0); 171 usbhsg_queue_pop(uep, ureq, 0);
318
319 return 0;
320} 172}
321 173
322static int usbhsg_try_run_send_packet(struct usbhsg_uep *uep, 174/*
323 struct usbhsg_request *ureq) 175 * dma map/unmap
176 */
177static int usbhsg_dma_map(struct device *dev,
178 struct usbhs_pkt *pkt,
179 enum dma_data_direction dir)
324{ 180{
325 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 181 struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt);
326 struct usb_request *req = &ureq->req; 182 struct usb_request *req = &ureq->req;
327 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
328 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
329 void *buf;
330 int remainder, send;
331 int is_done = 0;
332 int enable;
333 int maxp;
334 183
335 /* 184 if (pkt->dma != DMA_ADDR_INVALID) {
336 ********* assume under spin lock ********* 185 dev_err(dev, "dma is already mapped\n");
337 */ 186 return -EIO;
338
339 maxp = usbhs_pipe_get_maxpacket(pipe);
340 buf = req->buf + req->actual;
341 remainder = req->length - req->actual;
342
343 send = usbhs_fifo_write(pipe, buf, remainder);
344
345 /*
346 * send < 0 : pipe busy
347 * send = 0 : send zero packet
348 * send > 0 : send data
349 *
350 * send <= max_packet
351 */
352 if (send > 0)
353 req->actual += send;
354
355 /* send all packet ? */
356 if (send < remainder)
357 is_done = 0; /* there are remainder data */
358 else if (send < maxp)
359 is_done = 1; /* short packet */
360 else
361 is_done = !req->zero; /* send zero packet ? */
362
363 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
364 usbhs_pipe_number(pipe),
365 remainder, send, is_done, req->zero);
366
367 /*
368 * enable interrupt and send again in irq handler
369 * if it still have remainder data which should be sent.
370 */
371 enable = !is_done;
372 uep->handler->irq_mask(uep, enable);
373
374 /*
375 * usbhs_fifo_enable execute
376 * - after callback_update,
377 * - before queue_pop / stage_end
378 */
379 usbhs_fifo_enable(pipe);
380
381 /*
382 * all data were sent ?
383 */
384 if (is_done) {
385 /* it care below call in
386 "function mode" */
387 if (usbhsg_is_dcp(uep))
388 usbhs_dcp_control_transfer_done(pipe);
389
390 usbhsg_queue_pop(uep, ureq, 0);
391 } 187 }
392 188
393 return 0; 189 if (req->dma == DMA_ADDR_INVALID) {
394} 190 pkt->dma = dma_map_single(dev, pkt->buf, pkt->length, dir);
395 191 } else {
396static int usbhsg_prepare_send_packet(struct usbhsg_uep *uep, 192 dma_sync_single_for_device(dev, req->dma, req->length, dir);
397 struct usbhsg_request *ureq) 193 pkt->dma = req->dma;
398{ 194 }
399 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
400
401 /*
402 ********* assume under spin lock *********
403 */
404 195
405 usbhs_fifo_prepare_write(pipe); 196 if (dma_mapping_error(dev, pkt->dma)) {
406 usbhsg_try_run_send_packet(uep, ureq); 197 dev_err(dev, "dma mapping error %x\n", pkt->dma);
198 return -EIO;
199 }
407 200
408 return 0; 201 return 0;
409} 202}
410 203
411static int usbhsg_try_run_receive_packet(struct usbhsg_uep *uep, 204static int usbhsg_dma_unmap(struct device *dev,
412 struct usbhsg_request *ureq) 205 struct usbhs_pkt *pkt,
206 enum dma_data_direction dir)
413{ 207{
414 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 208 struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt);
415 struct usb_request *req = &ureq->req; 209 struct usb_request *req = &ureq->req;
416 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
417 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
418 void *buf;
419 int maxp;
420 int remainder, recv;
421 int is_done = 0;
422
423 /*
424 ********* assume under spin lock *********
425 */
426
427 maxp = usbhs_pipe_get_maxpacket(pipe);
428 buf = req->buf + req->actual;
429 remainder = req->length - req->actual;
430
431 recv = usbhs_fifo_read(pipe, buf, remainder);
432 /*
433 * recv < 0 : pipe busy
434 * recv >= 0 : receive data
435 *
436 * recv <= max_packet
437 */
438 if (recv < 0)
439 return -EBUSY;
440
441 /* update parameters */
442 req->actual += recv;
443
444 if ((recv == remainder) || /* receive all data */
445 (recv < maxp)) /* short packet */
446 is_done = 1;
447 210
448 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n", 211 if (pkt->dma == DMA_ADDR_INVALID) {
449 usbhs_pipe_number(pipe), 212 dev_err(dev, "dma is not mapped\n");
450 remainder, recv, is_done, req->zero); 213 return -EIO;
214 }
451 215
452 /* read all data ? */ 216 if (req->dma == DMA_ADDR_INVALID)
453 if (is_done) { 217 dma_unmap_single(dev, pkt->dma, pkt->length, dir);
454 int disable = 0; 218 else
219 dma_sync_single_for_cpu(dev, req->dma, req->length, dir);
455 220
456 uep->handler->irq_mask(uep, disable); 221 pkt->dma = DMA_ADDR_INVALID;
457 usbhs_fifo_disable(pipe);
458 usbhsg_queue_pop(uep, ureq, 0);
459 }
460 222
461 return 0; 223 return 0;
462} 224}
463 225
464static int usbhsg_prepare_receive_packet(struct usbhsg_uep *uep, 226static int usbhsg_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
465 struct usbhsg_request *ureq)
466{ 227{
467 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 228 struct usbhs_pipe *pipe = pkt->pipe;
468 int enable = 1; 229 struct usbhsg_uep *uep = usbhsg_pipe_to_uep(pipe);
469 int ret; 230 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
470 231 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
471 /* 232 enum dma_data_direction dir;
472 ********* assume under spin lock *********
473 */
474
475 ret = usbhs_fifo_prepare_read(pipe);
476 if (ret < 0)
477 return ret;
478 233
479 /* 234 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
480 * data will be read in interrupt handler
481 */
482 uep->handler->irq_mask(uep, enable);
483 235
484 return ret; 236 if (map)
237 return usbhsg_dma_map(dev, pkt, dir);
238 else
239 return usbhsg_dma_unmap(dev, pkt, dir);
485} 240}
486 241
487static struct usbhsg_pipe_handle usbhsg_handler_send_by_empty = {
488 .prepare = usbhsg_prepare_send_packet,
489 .try_run = usbhsg_try_run_send_packet,
490 .irq_mask = usbhsg_irq_empty_ctrl,
491};
492
493static struct usbhsg_pipe_handle usbhsg_handler_send_by_ready = {
494 .prepare = usbhsg_prepare_send_packet,
495 .try_run = usbhsg_try_run_send_packet,
496 .irq_mask = usbhsg_irq_ready_ctrl,
497};
498
499static struct usbhsg_pipe_handle usbhsg_handler_recv_by_ready = {
500 .prepare = usbhsg_prepare_receive_packet,
501 .try_run = usbhsg_try_run_receive_packet,
502 .irq_mask = usbhsg_irq_ready_ctrl,
503};
504
505static struct usbhsg_pipe_handle usbhsg_handler_ctrl_stage_end = {
506 .prepare = usbhsg_try_run_ctrl_stage_end,
507 .try_run = usbhsg_try_run_ctrl_stage_end,
508};
509
510/*
511 * DCP pipe can NOT use "ready interrupt" for "send"
512 * it should use "empty" interrupt.
513 * see
514 * "Operation" - "Interrupt Function" - "BRDY Interrupt"
515 *
516 * on the other hand, normal pipe can use "ready interrupt" for "send"
517 * even though it is single/double buffer
518 */
519#define usbhsg_handler_send_ctrl usbhsg_handler_send_by_empty
520#define usbhsg_handler_recv_ctrl usbhsg_handler_recv_by_ready
521
522#define usbhsg_handler_send_packet usbhsg_handler_send_by_ready
523#define usbhsg_handler_recv_packet usbhsg_handler_recv_by_ready
524
525/* 242/*
526 * USB_TYPE_STANDARD / clear feature functions 243 * USB_TYPE_STANDARD / clear feature functions
527 */ 244 */
@@ -546,15 +263,13 @@ static int usbhsg_recip_handler_std_clear_endpoint(struct usbhs_priv *priv,
546 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 263 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
547 264
548 if (!usbhsg_status_has(gpriv, USBHSG_STATUS_WEDGE)) { 265 if (!usbhsg_status_has(gpriv, USBHSG_STATUS_WEDGE)) {
549 usbhs_fifo_disable(pipe); 266 usbhs_pipe_disable(pipe);
550 usbhs_pipe_clear_sequence(pipe); 267 usbhs_pipe_clear_sequence(pipe);
551 usbhs_fifo_enable(pipe); 268 usbhs_pipe_enable(pipe);
552 } 269 }
553 270
554 usbhsg_recip_handler_std_control_done(priv, uep, ctrl); 271 usbhsg_recip_handler_std_control_done(priv, uep, ctrl);
555 272
556 usbhsg_queue_prepare(uep);
557
558 return 0; 273 return 0;
559} 274}
560 275
@@ -575,6 +290,7 @@ static int usbhsg_recip_run_handle(struct usbhs_priv *priv,
575 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); 290 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
576 struct device *dev = usbhsg_gpriv_to_dev(gpriv); 291 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
577 struct usbhsg_uep *uep; 292 struct usbhsg_uep *uep;
293 struct usbhs_pipe *pipe;
578 int recip = ctrl->bRequestType & USB_RECIP_MASK; 294 int recip = ctrl->bRequestType & USB_RECIP_MASK;
579 int nth = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; 295 int nth = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK;
580 int ret; 296 int ret;
@@ -583,9 +299,11 @@ static int usbhsg_recip_run_handle(struct usbhs_priv *priv,
583 char *msg; 299 char *msg;
584 300
585 uep = usbhsg_gpriv_to_nth_uep(gpriv, nth); 301 uep = usbhsg_gpriv_to_nth_uep(gpriv, nth);
586 if (!usbhsg_uep_to_pipe(uep)) { 302 pipe = usbhsg_uep_to_pipe(uep);
303 if (!pipe) {
587 dev_err(dev, "wrong recip request\n"); 304 dev_err(dev, "wrong recip request\n");
588 return -EINVAL; 305 ret = -EINVAL;
306 goto usbhsg_recip_run_handle_end;
589 } 307 }
590 308
591 switch (recip) { 309 switch (recip) {
@@ -608,10 +326,20 @@ static int usbhsg_recip_run_handle(struct usbhs_priv *priv,
608 } 326 }
609 327
610 if (func) { 328 if (func) {
329 unsigned long flags;
330
611 dev_dbg(dev, "%s (pipe %d :%s)\n", handler->name, nth, msg); 331 dev_dbg(dev, "%s (pipe %d :%s)\n", handler->name, nth, msg);
332
333 /******************** spin lock ********************/
334 usbhs_lock(priv, flags);
612 ret = func(priv, uep, ctrl); 335 ret = func(priv, uep, ctrl);
336 usbhs_unlock(priv, flags);
337 /******************** spin unlock ******************/
613 } 338 }
614 339
340usbhsg_recip_run_handle_end:
341 usbhs_pkt_start(pipe);
342
615 return ret; 343 return ret;
616} 344}
617 345
@@ -660,13 +388,13 @@ static int usbhsg_irq_ctrl_stage(struct usbhs_priv *priv,
660 388
661 switch (stage) { 389 switch (stage) {
662 case READ_DATA_STAGE: 390 case READ_DATA_STAGE:
663 dcp->handler = &usbhsg_handler_send_ctrl; 391 dcp->handler = &usbhs_fifo_pio_push_handler;
664 break; 392 break;
665 case WRITE_DATA_STAGE: 393 case WRITE_DATA_STAGE:
666 dcp->handler = &usbhsg_handler_recv_ctrl; 394 dcp->handler = &usbhs_fifo_pio_pop_handler;
667 break; 395 break;
668 case NODATA_STATUS_STAGE: 396 case NODATA_STATUS_STAGE:
669 dcp->handler = &usbhsg_handler_ctrl_stage_end; 397 dcp->handler = &usbhs_ctrl_stage_end_handler;
670 break; 398 break;
671 default: 399 default:
672 return ret; 400 return ret;
@@ -695,128 +423,27 @@ static int usbhsg_irq_ctrl_stage(struct usbhs_priv *priv,
695 ret = gpriv->driver->setup(&gpriv->gadget, &ctrl); 423 ret = gpriv->driver->setup(&gpriv->gadget, &ctrl);
696 424
697 if (ret < 0) 425 if (ret < 0)
698 usbhs_fifo_stall(pipe); 426 usbhs_pipe_stall(pipe);
699 427
700 return ret; 428 return ret;
701} 429}
702 430
703static int usbhsg_irq_empty(struct usbhs_priv *priv,
704 struct usbhs_irq_state *irq_state)
705{
706 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
707 struct usbhsg_uep *uep;
708 struct usbhs_pipe *pipe;
709 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
710 int i, ret;
711
712 if (!irq_state->bempsts) {
713 dev_err(dev, "debug %s !!\n", __func__);
714 return -EIO;
715 }
716
717 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
718
719 /*
720 * search interrupted "pipe"
721 * not "uep".
722 */
723 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
724 if (!(irq_state->bempsts & (1 << i)))
725 continue;
726
727 uep = usbhsg_pipe_to_uep(pipe);
728 ret = usbhsg_queue_handle(uep);
729 if (ret < 0)
730 dev_err(dev, "send error %d : %d\n", i, ret);
731 }
732
733 return 0;
734}
735
736static int usbhsg_irq_ready(struct usbhs_priv *priv,
737 struct usbhs_irq_state *irq_state)
738{
739 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
740 struct usbhsg_uep *uep;
741 struct usbhs_pipe *pipe;
742 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
743 int i, ret;
744
745 if (!irq_state->brdysts) {
746 dev_err(dev, "debug %s !!\n", __func__);
747 return -EIO;
748 }
749
750 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
751
752 /*
753 * search interrupted "pipe"
754 * not "uep".
755 */
756 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
757 if (!(irq_state->brdysts & (1 << i)))
758 continue;
759
760 uep = usbhsg_pipe_to_uep(pipe);
761 ret = usbhsg_queue_handle(uep);
762 if (ret < 0)
763 dev_err(dev, "receive error %d : %d\n", i, ret);
764 }
765
766 return 0;
767}
768
769/* 431/*
770 * 432 *
771 * usb_dcp_ops 433 * usb_dcp_ops
772 * 434 *
773 */ 435 */
774static int usbhsg_dcp_enable(struct usbhsg_uep *uep)
775{
776 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
777 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
778 struct usbhs_pipe *pipe;
779
780 /*
781 ********* assume under spin lock *********
782 */
783
784 pipe = usbhs_dcp_malloc(priv);
785 if (!pipe)
786 return -EIO;
787
788 uep->pipe = pipe;
789 uep->pipe->mod_private = uep;
790 INIT_LIST_HEAD(&uep->list);
791
792 return 0;
793}
794
795#define usbhsg_dcp_disable usbhsg_pipe_disable
796static int usbhsg_pipe_disable(struct usbhsg_uep *uep) 436static int usbhsg_pipe_disable(struct usbhsg_uep *uep)
797{ 437{
798 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 438 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
799 struct usbhsg_request *ureq; 439 struct usbhs_pkt *pkt;
800 int disable = 0;
801
802 /*
803 ********* assume under spin lock *********
804 */
805 440
806 usbhs_fifo_disable(pipe); 441 usbhs_pipe_disable(pipe);
807
808 /*
809 * disable pipe irq
810 */
811 usbhsg_irq_empty_ctrl(uep, disable);
812 usbhsg_irq_ready_ctrl(uep, disable);
813 442
814 while (1) { 443 while (1) {
815 ureq = usbhsg_queue_get(uep); 444 pkt = usbhs_pkt_pop(pipe, NULL);
816 if (!ureq) 445 if (!pkt)
817 break; 446 break;
818
819 usbhsg_queue_pop(uep, ureq, -ECONNRESET);
820 } 447 }
821 448
822 return 0; 449 return 0;
@@ -843,57 +470,44 @@ static int usbhsg_ep_enable(struct usb_ep *ep,
843 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); 470 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
844 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); 471 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
845 struct usbhs_pipe *pipe; 472 struct usbhs_pipe *pipe;
846 spinlock_t *lock;
847 unsigned long flags;
848 int ret = -EIO; 473 int ret = -EIO;
849 474
850 /* 475 /*
851 * if it already have pipe, 476 * if it already have pipe,
852 * nothing to do 477 * nothing to do
853 */ 478 */
854 if (uep->pipe) 479 if (uep->pipe) {
480 usbhs_pipe_clear(uep->pipe);
481 usbhs_pipe_clear_sequence(uep->pipe);
855 return 0; 482 return 0;
856 483 }
857 /******************** spin lock ********************/
858 lock = usbhsg_trylock(gpriv, &flags);
859 484
860 pipe = usbhs_pipe_malloc(priv, desc); 485 pipe = usbhs_pipe_malloc(priv, desc);
861 if (pipe) { 486 if (pipe) {
862 uep->pipe = pipe; 487 uep->pipe = pipe;
863 pipe->mod_private = uep; 488 pipe->mod_private = uep;
864 INIT_LIST_HEAD(&uep->list);
865 489
490 /*
491 * usbhs_fifo_dma_push/pop_handler try to
492 * use dmaengine if possible.
493 * It will use pio handler if impossible.
494 */
866 if (usb_endpoint_dir_in(desc)) 495 if (usb_endpoint_dir_in(desc))
867 uep->handler = &usbhsg_handler_send_packet; 496 uep->handler = &usbhs_fifo_dma_push_handler;
868 else 497 else
869 uep->handler = &usbhsg_handler_recv_packet; 498 uep->handler = &usbhs_fifo_dma_pop_handler;
870 499
871 ret = 0; 500 ret = 0;
872 } 501 }
873 502
874 usbhsg_unlock(lock, &flags);
875 /******************** spin unlock ******************/
876
877 return ret; 503 return ret;
878} 504}
879 505
880static int usbhsg_ep_disable(struct usb_ep *ep) 506static int usbhsg_ep_disable(struct usb_ep *ep)
881{ 507{
882 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); 508 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
883 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
884 spinlock_t *lock;
885 unsigned long flags;
886 int ret;
887
888 /******************** spin lock ********************/
889 lock = usbhsg_trylock(gpriv, &flags);
890 509
891 ret = usbhsg_pipe_disable(uep); 510 return usbhsg_pipe_disable(uep);
892
893 usbhsg_unlock(lock, &flags);
894 /******************** spin unlock ******************/
895
896 return ret;
897} 511}
898 512
899static struct usb_request *usbhsg_ep_alloc_request(struct usb_ep *ep, 513static struct usb_request *usbhsg_ep_alloc_request(struct usb_ep *ep,
@@ -905,7 +519,10 @@ static struct usb_request *usbhsg_ep_alloc_request(struct usb_ep *ep,
905 if (!ureq) 519 if (!ureq)
906 return NULL; 520 return NULL;
907 521
908 INIT_LIST_HEAD(&ureq->node); 522 usbhs_pkt_init(usbhsg_ureq_to_pkt(ureq));
523
524 ureq->req.dma = DMA_ADDR_INVALID;
525
909 return &ureq->req; 526 return &ureq->req;
910} 527}
911 528
@@ -914,7 +531,7 @@ static void usbhsg_ep_free_request(struct usb_ep *ep,
914{ 531{
915 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req); 532 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
916 533
917 WARN_ON(!list_empty(&ureq->node)); 534 WARN_ON(!list_empty(&ureq->pkt.node));
918 kfree(ureq); 535 kfree(ureq);
919} 536}
920 537
@@ -925,69 +542,27 @@ static int usbhsg_ep_queue(struct usb_ep *ep, struct usb_request *req,
925 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); 542 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
926 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req); 543 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
927 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 544 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
928 spinlock_t *lock;
929 unsigned long flags;
930 int ret = 0;
931
932 /*
933 * CAUTION [*endpoint queue*]
934 *
935 * This function will be called from usb_request :: complete
936 * or usb driver timing.
937 * If this function is called from usb_request :: complete,
938 * it is already under spinlock on this driver.
939 * but it is called frm usb driver, this function should call spinlock.
940 *
941 * This function is using usbshg_trylock to solve this issue.
942 * if "is_locked" is 1, this mean this function lock it.
943 * but if it is 0, this mean it is already under spin lock.
944 * see also
945 * CAUTION [*queue handler*]
946 * CAUTION [*request complete*]
947 */
948
949 /******************** spin lock ********************/
950 lock = usbhsg_trylock(gpriv, &flags);
951 545
952 /* param check */ 546 /* param check */
953 if (usbhsg_is_not_connected(gpriv) || 547 if (usbhsg_is_not_connected(gpriv) ||
954 unlikely(!gpriv->driver) || 548 unlikely(!gpriv->driver) ||
955 unlikely(!pipe)) 549 unlikely(!pipe))
956 ret = -ESHUTDOWN; 550 return -ESHUTDOWN;
957 else
958 usbhsg_queue_push(uep, ureq);
959
960 usbhsg_unlock(lock, &flags);
961 /******************** spin unlock ******************/
962 551
963 usbhsg_queue_prepare(uep); 552 usbhsg_queue_push(uep, ureq);
964 553
965 return ret; 554 return 0;
966} 555}
967 556
968static int usbhsg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) 557static int usbhsg_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
969{ 558{
970 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); 559 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
971 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req); 560 struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
972 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); 561 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
973 spinlock_t *lock;
974 unsigned long flags;
975
976 /*
977 * see
978 * CAUTION [*queue handler*]
979 * CAUTION [*endpoint queue*]
980 * CAUTION [*request complete*]
981 */
982
983 /******************** spin lock ********************/
984 lock = usbhsg_trylock(gpriv, &flags);
985 562
563 usbhs_pkt_pop(pipe, usbhsg_ureq_to_pkt(ureq));
986 usbhsg_queue_pop(uep, ureq, -ECONNRESET); 564 usbhsg_queue_pop(uep, ureq, -ECONNRESET);
987 565
988 usbhsg_unlock(lock, &flags);
989 /******************** spin unlock ******************/
990
991 return 0; 566 return 0;
992} 567}
993 568
@@ -996,42 +571,32 @@ static int __usbhsg_ep_set_halt_wedge(struct usb_ep *ep, int halt, int wedge)
996 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep); 571 struct usbhsg_uep *uep = usbhsg_ep_to_uep(ep);
997 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); 572 struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);
998 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); 573 struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep);
574 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
999 struct device *dev = usbhsg_gpriv_to_dev(gpriv); 575 struct device *dev = usbhsg_gpriv_to_dev(gpriv);
1000 spinlock_t *lock;
1001 unsigned long flags; 576 unsigned long flags;
1002 int ret = -EAGAIN;
1003 577
1004 /* 578 usbhsg_pipe_disable(uep);
1005 * see
1006 * CAUTION [*queue handler*]
1007 * CAUTION [*endpoint queue*]
1008 * CAUTION [*request complete*]
1009 */
1010 579
1011 /******************** spin lock ********************/ 580 dev_dbg(dev, "set halt %d (pipe %d)\n",
1012 lock = usbhsg_trylock(gpriv, &flags); 581 halt, usbhs_pipe_number(pipe));
1013 if (!usbhsg_queue_get(uep)) {
1014 582
1015 dev_dbg(dev, "set halt %d (pipe %d)\n", 583 /******************** spin lock ********************/
1016 halt, usbhs_pipe_number(pipe)); 584 usbhs_lock(priv, flags);
1017
1018 if (halt)
1019 usbhs_fifo_stall(pipe);
1020 else
1021 usbhs_fifo_disable(pipe);
1022 585
1023 if (halt && wedge) 586 if (halt)
1024 usbhsg_status_set(gpriv, USBHSG_STATUS_WEDGE); 587 usbhs_pipe_stall(pipe);
1025 else 588 else
1026 usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE); 589 usbhs_pipe_disable(pipe);
1027 590
1028 ret = 0; 591 if (halt && wedge)
1029 } 592 usbhsg_status_set(gpriv, USBHSG_STATUS_WEDGE);
593 else
594 usbhsg_status_clr(gpriv, USBHSG_STATUS_WEDGE);
1030 595
1031 usbhsg_unlock(lock, &flags); 596 usbhs_unlock(priv, flags);
1032 /******************** spin unlock ******************/ 597 /******************** spin unlock ******************/
1033 598
1034 return ret; 599 return 0;
1035} 600}
1036 601
1037static int usbhsg_ep_set_halt(struct usb_ep *ep, int value) 602static int usbhsg_ep_set_halt(struct usb_ep *ep, int value)
@@ -1067,28 +632,40 @@ static int usbhsg_try_start(struct usbhs_priv *priv, u32 status)
1067 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv); 632 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
1068 struct usbhs_mod *mod = usbhs_mod_get_current(priv); 633 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1069 struct device *dev = usbhs_priv_to_dev(priv); 634 struct device *dev = usbhs_priv_to_dev(priv);
1070 spinlock_t *lock;
1071 unsigned long flags; 635 unsigned long flags;
636 int ret = 0;
1072 637
1073 /******************** spin lock ********************/ 638 /******************** spin lock ********************/
1074 lock = usbhsg_trylock(gpriv, &flags); 639 usbhs_lock(priv, flags);
1075 640
1076 /*
1077 * enable interrupt and systems if ready
1078 */
1079 usbhsg_status_set(gpriv, status); 641 usbhsg_status_set(gpriv, status);
1080 if (!(usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) && 642 if (!(usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) &&
1081 usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD))) 643 usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD)))
1082 goto usbhsg_try_start_unlock; 644 ret = -1; /* not ready */
645
646 usbhs_unlock(priv, flags);
647 /******************** spin unlock ********************/
648
649 if (ret < 0)
650 return 0; /* not ready is not error */
1083 651
652 /*
653 * enable interrupt and systems if ready
654 */
1084 dev_dbg(dev, "start gadget\n"); 655 dev_dbg(dev, "start gadget\n");
1085 656
1086 /* 657 /*
1087 * pipe initialize and enable DCP 658 * pipe initialize and enable DCP
1088 */ 659 */
1089 usbhs_pipe_init(priv); 660 usbhs_pipe_init(priv,
661 usbhsg_queue_done,
662 usbhsg_dma_map_ctrl);
663 usbhs_fifo_init(priv);
1090 usbhsg_uep_init(gpriv); 664 usbhsg_uep_init(gpriv);
1091 usbhsg_dcp_enable(dcp); 665
666 /* dcp init */
667 dcp->pipe = usbhs_dcp_malloc(priv);
668 dcp->pipe->mod_private = dcp;
1092 669
1093 /* 670 /*
1094 * system config enble 671 * system config enble
@@ -1105,16 +682,8 @@ static int usbhsg_try_start(struct usbhs_priv *priv, u32 status)
1105 */ 682 */
1106 mod->irq_dev_state = usbhsg_irq_dev_state; 683 mod->irq_dev_state = usbhsg_irq_dev_state;
1107 mod->irq_ctrl_stage = usbhsg_irq_ctrl_stage; 684 mod->irq_ctrl_stage = usbhsg_irq_ctrl_stage;
1108 mod->irq_empty = usbhsg_irq_empty;
1109 mod->irq_ready = usbhsg_irq_ready;
1110 mod->irq_bempsts = 0;
1111 mod->irq_brdysts = 0;
1112 usbhs_irq_callback_update(priv, mod); 685 usbhs_irq_callback_update(priv, mod);
1113 686
1114usbhsg_try_start_unlock:
1115 usbhsg_unlock(lock, &flags);
1116 /******************** spin unlock ********************/
1117
1118 return 0; 687 return 0;
1119} 688}
1120 689
@@ -1124,31 +693,33 @@ static int usbhsg_try_stop(struct usbhs_priv *priv, u32 status)
1124 struct usbhs_mod *mod = usbhs_mod_get_current(priv); 693 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1125 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv); 694 struct usbhsg_uep *dcp = usbhsg_gpriv_to_dcp(gpriv);
1126 struct device *dev = usbhs_priv_to_dev(priv); 695 struct device *dev = usbhs_priv_to_dev(priv);
1127 spinlock_t *lock;
1128 unsigned long flags; 696 unsigned long flags;
697 int ret = 0;
1129 698
1130 /******************** spin lock ********************/ 699 /******************** spin lock ********************/
1131 lock = usbhsg_trylock(gpriv, &flags); 700 usbhs_lock(priv, flags);
1132 701
1133 /*
1134 * disable interrupt and systems if 1st try
1135 */
1136 usbhsg_status_clr(gpriv, status); 702 usbhsg_status_clr(gpriv, status);
1137 if (!usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) && 703 if (!usbhsg_status_has(gpriv, USBHSG_STATUS_STARTED) &&
1138 !usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD)) 704 !usbhsg_status_has(gpriv, USBHSG_STATUS_REGISTERD))
1139 goto usbhsg_try_stop_unlock; 705 ret = -1; /* already done */
706
707 usbhs_unlock(priv, flags);
708 /******************** spin unlock ********************/
709
710 if (ret < 0)
711 return 0; /* already done is not error */
712
713 /*
714 * disable interrupt and systems if 1st try
715 */
716 usbhs_fifo_quit(priv);
1140 717
1141 /* disable all irq */ 718 /* disable all irq */
1142 mod->irq_dev_state = NULL; 719 mod->irq_dev_state = NULL;
1143 mod->irq_ctrl_stage = NULL; 720 mod->irq_ctrl_stage = NULL;
1144 mod->irq_empty = NULL;
1145 mod->irq_ready = NULL;
1146 mod->irq_bempsts = 0;
1147 mod->irq_brdysts = 0;
1148 usbhs_irq_callback_update(priv, mod); 721 usbhs_irq_callback_update(priv, mod);
1149 722
1150 usbhsg_dcp_disable(dcp);
1151
1152 gpriv->gadget.speed = USB_SPEED_UNKNOWN; 723 gpriv->gadget.speed = USB_SPEED_UNKNOWN;
1153 724
1154 /* disable sys */ 725 /* disable sys */
@@ -1156,8 +727,7 @@ static int usbhsg_try_stop(struct usbhs_priv *priv, u32 status)
1156 usbhs_sys_function_ctrl(priv, 0); 727 usbhs_sys_function_ctrl(priv, 0);
1157 usbhs_sys_usb_ctrl(priv, 0); 728 usbhs_sys_usb_ctrl(priv, 0);
1158 729
1159 usbhsg_unlock(lock, &flags); 730 usbhsg_pipe_disable(dcp);
1160 /******************** spin unlock ********************/
1161 731
1162 if (gpriv->driver && 732 if (gpriv->driver &&
1163 gpriv->driver->disconnect) 733 gpriv->driver->disconnect)
@@ -1166,11 +736,6 @@ static int usbhsg_try_stop(struct usbhs_priv *priv, u32 status)
1166 dev_dbg(dev, "stop gadget\n"); 736 dev_dbg(dev, "stop gadget\n");
1167 737
1168 return 0; 738 return 0;
1169
1170usbhsg_try_stop_unlock:
1171 usbhsg_unlock(lock, &flags);
1172
1173 return 0;
1174} 739}
1175 740
1176/* 741/*
@@ -1178,11 +743,10 @@ usbhsg_try_stop_unlock:
1178 * linux usb function 743 * linux usb function
1179 * 744 *
1180 */ 745 */
1181struct usbhsg_gpriv *the_controller; 746static int usbhsg_gadget_start(struct usb_gadget_driver *driver,
1182int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1183 int (*bind)(struct usb_gadget *)) 747 int (*bind)(struct usb_gadget *))
1184{ 748{
1185 struct usbhsg_gpriv *gpriv = the_controller; 749 struct usbhsg_gpriv *gpriv;
1186 struct usbhs_priv *priv; 750 struct usbhs_priv *priv;
1187 struct device *dev; 751 struct device *dev;
1188 int ret; 752 int ret;
@@ -1192,10 +756,17 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1192 !driver->setup || 756 !driver->setup ||
1193 driver->speed != USB_SPEED_HIGH) 757 driver->speed != USB_SPEED_HIGH)
1194 return -EINVAL; 758 return -EINVAL;
1195 if (!gpriv) 759
1196 return -ENODEV; 760 /*
1197 if (gpriv->driver) 761 * find unused controller
1198 return -EBUSY; 762 */
763 usbhsg_for_each_controller(gpriv) {
764 if (!gpriv->driver)
765 goto find_unused_controller;
766 }
767 return -ENODEV;
768
769find_unused_controller:
1199 770
1200 dev = usbhsg_gpriv_to_dev(gpriv); 771 dev = usbhsg_gpriv_to_dev(gpriv);
1201 priv = usbhsg_gpriv_to_priv(gpriv); 772 priv = usbhsg_gpriv_to_priv(gpriv);
@@ -1229,22 +800,28 @@ add_fail:
1229 800
1230 return ret; 801 return ret;
1231} 802}
1232EXPORT_SYMBOL(usb_gadget_probe_driver);
1233 803
1234int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 804static int usbhsg_gadget_stop(struct usb_gadget_driver *driver)
1235{ 805{
1236 struct usbhsg_gpriv *gpriv = the_controller; 806 struct usbhsg_gpriv *gpriv;
1237 struct usbhs_priv *priv; 807 struct usbhs_priv *priv;
1238 struct device *dev = usbhsg_gpriv_to_dev(gpriv); 808 struct device *dev;
1239
1240 if (!gpriv)
1241 return -ENODEV;
1242 809
1243 if (!driver || 810 if (!driver ||
1244 !driver->unbind || 811 !driver->unbind)
1245 driver != gpriv->driver)
1246 return -EINVAL; 812 return -EINVAL;
1247 813
814 /*
815 * find controller
816 */
817 usbhsg_for_each_controller(gpriv) {
818 if (gpriv->driver == driver)
819 goto find_matching_controller;
820 }
821 return -ENODEV;
822
823find_matching_controller:
824
1248 dev = usbhsg_gpriv_to_dev(gpriv); 825 dev = usbhsg_gpriv_to_dev(gpriv);
1249 priv = usbhsg_gpriv_to_priv(gpriv); 826 priv = usbhsg_gpriv_to_priv(gpriv);
1250 827
@@ -1260,7 +837,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1260 837
1261 return 0; 838 return 0;
1262} 839}
1263EXPORT_SYMBOL(usb_gadget_unregister_driver);
1264 840
1265/* 841/*
1266 * usb gadget ops 842 * usb gadget ops
@@ -1275,6 +851,8 @@ static int usbhsg_get_frame(struct usb_gadget *gadget)
1275 851
1276static struct usb_gadget_ops usbhsg_gadget_ops = { 852static struct usb_gadget_ops usbhsg_gadget_ops = {
1277 .get_frame = usbhsg_get_frame, 853 .get_frame = usbhsg_get_frame,
854 .start = usbhsg_gadget_start,
855 .stop = usbhsg_gadget_stop,
1278}; 856};
1279 857
1280static int usbhsg_start(struct usbhs_priv *priv) 858static int usbhsg_start(struct usbhs_priv *priv)
@@ -1294,6 +872,7 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1294 struct device *dev = usbhs_priv_to_dev(priv); 872 struct device *dev = usbhs_priv_to_dev(priv);
1295 int pipe_size = usbhs_get_dparam(priv, pipe_size); 873 int pipe_size = usbhs_get_dparam(priv, pipe_size);
1296 int i; 874 int i;
875 int ret;
1297 876
1298 gpriv = kzalloc(sizeof(struct usbhsg_gpriv), GFP_KERNEL); 877 gpriv = kzalloc(sizeof(struct usbhsg_gpriv), GFP_KERNEL);
1299 if (!gpriv) { 878 if (!gpriv) {
@@ -1304,6 +883,7 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1304 uep = kzalloc(sizeof(struct usbhsg_uep) * pipe_size, GFP_KERNEL); 883 uep = kzalloc(sizeof(struct usbhsg_uep) * pipe_size, GFP_KERNEL);
1305 if (!uep) { 884 if (!uep) {
1306 dev_err(dev, "Could not allocate ep\n"); 885 dev_err(dev, "Could not allocate ep\n");
886 ret = -ENOMEM;
1307 goto usbhs_mod_gadget_probe_err_gpriv; 887 goto usbhs_mod_gadget_probe_err_gpriv;
1308 } 888 }
1309 889
@@ -1350,7 +930,6 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1350 uep->ep.name = uep->ep_name; 930 uep->ep.name = uep->ep_name;
1351 uep->ep.ops = &usbhsg_ep_ops; 931 uep->ep.ops = &usbhsg_ep_ops;
1352 INIT_LIST_HEAD(&uep->ep.ep_list); 932 INIT_LIST_HEAD(&uep->ep.ep_list);
1353 INIT_LIST_HEAD(&uep->list);
1354 933
1355 /* init DCP */ 934 /* init DCP */
1356 if (usbhsg_is_dcp(uep)) { 935 if (usbhsg_is_dcp(uep)) {
@@ -1364,22 +943,33 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1364 } 943 }
1365 } 944 }
1366 945
1367 the_controller = gpriv; 946 usbhsg_controller_register(gpriv);
947
948 ret = usb_add_gadget_udc(dev, &gpriv->gadget);
949 if (ret)
950 goto err_add_udc;
951
1368 952
1369 dev_info(dev, "gadget probed\n"); 953 dev_info(dev, "gadget probed\n");
1370 954
1371 return 0; 955 return 0;
956err_add_udc:
957 kfree(gpriv->uep);
1372 958
1373usbhs_mod_gadget_probe_err_gpriv: 959usbhs_mod_gadget_probe_err_gpriv:
1374 kfree(gpriv); 960 kfree(gpriv);
1375 961
1376 return -ENOMEM; 962 return ret;
1377} 963}
1378 964
1379void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv) 965void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv)
1380{ 966{
1381 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); 967 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
1382 968
969 usb_del_gadget_udc(&gpriv->gadget);
970
971 usbhsg_controller_unregister(gpriv);
972
1383 kfree(gpriv->uep); 973 kfree(gpriv->uep);
1384 kfree(gpriv); 974 kfree(gpriv);
1385} 975}
diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c
index bc4521c54261..1b14cae45704 100644
--- a/drivers/usb/renesas_usbhs/pipe.c
+++ b/drivers/usb/renesas_usbhs/pipe.c
@@ -15,7 +15,6 @@
15 * 15 *
16 */ 16 */
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/io.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
20#include "./common.h" 19#include "./common.h"
21#include "./pipe.h" 20#include "./pipe.h"
@@ -23,13 +22,8 @@
23/* 22/*
24 * macros 23 * macros
25 */ 24 */
26#define usbhsp_priv_to_pipeinfo(pr) (&(pr)->pipe_info)
27#define usbhsp_pipe_to_priv(p) ((p)->priv)
28
29#define usbhsp_addr_offset(p) ((usbhs_pipe_number(p) - 1) * 2) 25#define usbhsp_addr_offset(p) ((usbhs_pipe_number(p) - 1) * 2)
30 26
31#define usbhsp_is_dcp(p) ((p)->priv->pipe_info.pipe == (p))
32
33#define usbhsp_flags_set(p, f) ((p)->flags |= USBHS_PIPE_FLAGS_##f) 27#define usbhsp_flags_set(p, f) ((p)->flags |= USBHS_PIPE_FLAGS_##f)
34#define usbhsp_flags_clr(p, f) ((p)->flags &= ~USBHS_PIPE_FLAGS_##f) 28#define usbhsp_flags_clr(p, f) ((p)->flags &= ~USBHS_PIPE_FLAGS_##f)
35#define usbhsp_flags_has(p, f) ((p)->flags & USBHS_PIPE_FLAGS_##f) 29#define usbhsp_flags_has(p, f) ((p)->flags & USBHS_PIPE_FLAGS_##f)
@@ -77,10 +71,10 @@ void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
77 */ 71 */
78static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val) 72static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
79{ 73{
80 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe); 74 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
81 int offset = usbhsp_addr_offset(pipe); 75 int offset = usbhsp_addr_offset(pipe);
82 76
83 if (usbhsp_is_dcp(pipe)) 77 if (usbhs_pipe_is_dcp(pipe))
84 usbhs_bset(priv, DCPCTR, mask, val); 78 usbhs_bset(priv, DCPCTR, mask, val);
85 else 79 else
86 usbhs_bset(priv, PIPEnCTR + offset, mask, val); 80 usbhs_bset(priv, PIPEnCTR + offset, mask, val);
@@ -88,10 +82,10 @@ static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
88 82
89static u16 usbhsp_pipectrl_get(struct usbhs_pipe *pipe) 83static u16 usbhsp_pipectrl_get(struct usbhs_pipe *pipe)
90{ 84{
91 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe); 85 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
92 int offset = usbhsp_addr_offset(pipe); 86 int offset = usbhsp_addr_offset(pipe);
93 87
94 if (usbhsp_is_dcp(pipe)) 88 if (usbhs_pipe_is_dcp(pipe))
95 return usbhs_read(priv, DCPCTR); 89 return usbhs_read(priv, DCPCTR);
96 else 90 else
97 return usbhs_read(priv, PIPEnCTR + offset); 91 return usbhs_read(priv, PIPEnCTR + offset);
@@ -104,9 +98,9 @@ static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe,
104 u16 dcp_reg, u16 pipe_reg, 98 u16 dcp_reg, u16 pipe_reg,
105 u16 mask, u16 val) 99 u16 mask, u16 val)
106{ 100{
107 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe); 101 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
108 102
109 if (usbhsp_is_dcp(pipe)) 103 if (usbhs_pipe_is_dcp(pipe))
110 usbhs_bset(priv, dcp_reg, mask, val); 104 usbhs_bset(priv, dcp_reg, mask, val);
111 else 105 else
112 usbhs_bset(priv, pipe_reg, mask, val); 106 usbhs_bset(priv, pipe_reg, mask, val);
@@ -115,9 +109,9 @@ static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe,
115static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe, 109static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe,
116 u16 dcp_reg, u16 pipe_reg) 110 u16 dcp_reg, u16 pipe_reg)
117{ 111{
118 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe); 112 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
119 113
120 if (usbhsp_is_dcp(pipe)) 114 if (usbhs_pipe_is_dcp(pipe))
121 return usbhs_read(priv, dcp_reg); 115 return usbhs_read(priv, dcp_reg);
122 else 116 else
123 return usbhs_read(priv, pipe_reg); 117 return usbhs_read(priv, pipe_reg);
@@ -136,7 +130,7 @@ static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
136 */ 130 */
137static void usbhsp_pipe_buf_set(struct usbhs_pipe *pipe, u16 mask, u16 val) 131static void usbhsp_pipe_buf_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
138{ 132{
139 if (usbhsp_is_dcp(pipe)) 133 if (usbhs_pipe_is_dcp(pipe))
140 return; 134 return;
141 135
142 __usbhsp_pipe_xxx_set(pipe, 0, PIPEBUF, mask, val); 136 __usbhsp_pipe_xxx_set(pipe, 0, PIPEBUF, mask, val);
@@ -160,7 +154,7 @@ static u16 usbhsp_pipe_maxp_get(struct usbhs_pipe *pipe)
160 */ 154 */
161static void usbhsp_pipe_select(struct usbhs_pipe *pipe) 155static void usbhsp_pipe_select(struct usbhs_pipe *pipe)
162{ 156{
163 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe); 157 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
164 158
165 /* 159 /*
166 * On pipe, this is necessary before 160 * On pipe, this is necessary before
@@ -182,7 +176,7 @@ static void usbhsp_pipe_select(struct usbhs_pipe *pipe)
182 176
183static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe) 177static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
184{ 178{
185 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe); 179 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
186 int timeout = 1024; 180 int timeout = 1024;
187 u16 val; 181 u16 val;
188 182
@@ -205,7 +199,7 @@ static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
205 * - "Pipe Control Registers Switching Procedure" 199 * - "Pipe Control Registers Switching Procedure"
206 */ 200 */
207 usbhs_write(priv, CFIFOSEL, 0); 201 usbhs_write(priv, CFIFOSEL, 0);
208 usbhs_fifo_disable(pipe); 202 usbhs_pipe_disable(pipe);
209 203
210 do { 204 do {
211 val = usbhsp_pipectrl_get(pipe); 205 val = usbhsp_pipectrl_get(pipe);
@@ -220,7 +214,7 @@ static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
220 return -EBUSY; 214 return -EBUSY;
221} 215}
222 216
223static int usbhsp_pipe_is_accessible(struct usbhs_pipe *pipe) 217int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe)
224{ 218{
225 u16 val; 219 u16 val;
226 220
@@ -253,7 +247,7 @@ static void __usbhsp_pid_try_nak_if_stall(struct usbhs_pipe *pipe)
253 } 247 }
254} 248}
255 249
256void usbhs_fifo_disable(struct usbhs_pipe *pipe) 250void usbhs_pipe_disable(struct usbhs_pipe *pipe)
257{ 251{
258 int timeout = 1024; 252 int timeout = 1024;
259 u16 val; 253 u16 val;
@@ -273,7 +267,7 @@ void usbhs_fifo_disable(struct usbhs_pipe *pipe)
273 } while (timeout--); 267 } while (timeout--);
274} 268}
275 269
276void usbhs_fifo_enable(struct usbhs_pipe *pipe) 270void usbhs_pipe_enable(struct usbhs_pipe *pipe)
277{ 271{
278 /* see "Pipe n Control Register" - "PID" */ 272 /* see "Pipe n Control Register" - "PID" */
279 __usbhsp_pid_try_nak_if_stall(pipe); 273 __usbhsp_pid_try_nak_if_stall(pipe);
@@ -281,7 +275,7 @@ void usbhs_fifo_enable(struct usbhs_pipe *pipe)
281 usbhsp_pipectrl_set(pipe, PID_MASK, PID_BUF); 275 usbhsp_pipectrl_set(pipe, PID_MASK, PID_BUF);
282} 276}
283 277
284void usbhs_fifo_stall(struct usbhs_pipe *pipe) 278void usbhs_pipe_stall(struct usbhs_pipe *pipe)
285{ 279{
286 u16 pid = usbhsp_pipectrl_get(pipe); 280 u16 pid = usbhsp_pipectrl_get(pipe);
287 281
@@ -302,191 +296,6 @@ void usbhs_fifo_stall(struct usbhs_pipe *pipe)
302} 296}
303 297
304/* 298/*
305 * CFIFO ctrl
306 */
307void usbhs_fifo_send_terminator(struct usbhs_pipe *pipe)
308{
309 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
310
311 usbhs_bset(priv, CFIFOCTR, BVAL, BVAL);
312}
313
314static void usbhsp_fifo_clear(struct usbhs_pipe *pipe)
315{
316 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
317
318 usbhs_write(priv, CFIFOCTR, BCLR);
319}
320
321static int usbhsp_fifo_barrier(struct usbhs_priv *priv)
322{
323 int timeout = 1024;
324
325 do {
326 /* The FIFO port is accessible */
327 if (usbhs_read(priv, CFIFOCTR) & FRDY)
328 return 0;
329
330 udelay(10);
331 } while (timeout--);
332
333 return -EBUSY;
334}
335
336static int usbhsp_fifo_rcv_len(struct usbhs_priv *priv)
337{
338 return usbhs_read(priv, CFIFOCTR) & DTLN_MASK;
339}
340
341static int usbhsp_fifo_select(struct usbhs_pipe *pipe, int write)
342{
343 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
344 struct device *dev = usbhs_priv_to_dev(priv);
345 int timeout = 1024;
346 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
347 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
348
349 if (usbhsp_is_dcp(pipe))
350 base |= (1 == write) << 5; /* ISEL */
351
352 /* "base" will be used below */
353 usbhs_write(priv, CFIFOSEL, base | MBW_32);
354
355 /* check ISEL and CURPIPE value */
356 while (timeout--) {
357 if (base == (mask & usbhs_read(priv, CFIFOSEL)))
358 return 0;
359 udelay(10);
360 }
361
362 dev_err(dev, "fifo select error\n");
363
364 return -EIO;
365}
366
367int usbhs_fifo_prepare_write(struct usbhs_pipe *pipe)
368{
369 return usbhsp_fifo_select(pipe, 1);
370}
371
372int usbhs_fifo_write(struct usbhs_pipe *pipe, u8 *buf, int len)
373{
374 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
375 void __iomem *addr = priv->base + CFIFO;
376 int maxp = usbhs_pipe_get_maxpacket(pipe);
377 int total_len;
378 int i, ret;
379
380 ret = usbhsp_pipe_is_accessible(pipe);
381 if (ret < 0)
382 return ret;
383
384 ret = usbhsp_fifo_select(pipe, 1);
385 if (ret < 0)
386 return ret;
387
388 ret = usbhsp_fifo_barrier(priv);
389 if (ret < 0)
390 return ret;
391
392 len = min(len, maxp);
393 total_len = len;
394
395 /*
396 * FIXME
397 *
398 * 32-bit access only
399 */
400 if (len >= 4 &&
401 !((unsigned long)buf & 0x03)) {
402 iowrite32_rep(addr, buf, len / 4);
403 len %= 4;
404 buf += total_len - len;
405 }
406
407 /* the rest operation */
408 for (i = 0; i < len; i++)
409 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
410
411 if (total_len < maxp)
412 usbhs_fifo_send_terminator(pipe);
413
414 return total_len;
415}
416
417int usbhs_fifo_prepare_read(struct usbhs_pipe *pipe)
418{
419 int ret;
420
421 /*
422 * select pipe and enable it to prepare packet receive
423 */
424 ret = usbhsp_fifo_select(pipe, 0);
425 if (ret < 0)
426 return ret;
427
428 usbhs_fifo_enable(pipe);
429
430 return ret;
431}
432
433int usbhs_fifo_read(struct usbhs_pipe *pipe, u8 *buf, int len)
434{
435 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
436 void __iomem *addr = priv->base + CFIFO;
437 int rcv_len;
438 int i, ret;
439 int total_len;
440 u32 data = 0;
441
442 ret = usbhsp_fifo_select(pipe, 0);
443 if (ret < 0)
444 return ret;
445
446 ret = usbhsp_fifo_barrier(priv);
447 if (ret < 0)
448 return ret;
449
450 rcv_len = usbhsp_fifo_rcv_len(priv);
451
452 /*
453 * Buffer clear if Zero-Length packet
454 *
455 * see
456 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
457 */
458 if (0 == rcv_len) {
459 usbhsp_fifo_clear(pipe);
460 return 0;
461 }
462
463 len = min(rcv_len, len);
464 total_len = len;
465
466 /*
467 * FIXME
468 *
469 * 32-bit access only
470 */
471 if (len >= 4 &&
472 !((unsigned long)buf & 0x03)) {
473 ioread32_rep(addr, buf, len / 4);
474 len %= 4;
475 buf += rcv_len - len;
476 }
477
478 /* the rest operation */
479 for (i = 0; i < len; i++) {
480 if (!(i & 0x03))
481 data = ioread32(addr);
482
483 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
484 }
485
486 return total_len;
487}
488
489/*
490 * pipe setup 299 * pipe setup
491 */ 300 */
492static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe) 301static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe)
@@ -519,7 +328,7 @@ static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
519 }; 328 };
520 int is_double = usbhsp_possible_double_buffer(pipe); 329 int is_double = usbhsp_possible_double_buffer(pipe);
521 330
522 if (usbhsp_is_dcp(pipe)) 331 if (usbhs_pipe_is_dcp(pipe))
523 return -EINVAL; 332 return -EINVAL;
524 333
525 /* 334 /*
@@ -550,12 +359,15 @@ static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
550 359
551 /* DIR */ 360 /* DIR */
552 if (usb_endpoint_dir_in(desc)) 361 if (usb_endpoint_dir_in(desc))
553 usbhsp_flags_set(pipe, IS_DIR_IN); 362 usbhsp_flags_set(pipe, IS_DIR_HOST);
554 363
555 if ((is_host && usb_endpoint_dir_out(desc)) || 364 if ((is_host && usb_endpoint_dir_out(desc)) ||
556 (!is_host && usb_endpoint_dir_in(desc))) 365 (!is_host && usb_endpoint_dir_in(desc)))
557 dir |= DIR_OUT; 366 dir |= DIR_OUT;
558 367
368 if (!dir)
369 usbhsp_flags_set(pipe, IS_DIR_IN);
370
559 /* SHTNAK */ 371 /* SHTNAK */
560 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK) && 372 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK) &&
561 !dir) 373 !dir)
@@ -587,8 +399,8 @@ static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe,
587 const struct usb_endpoint_descriptor *desc, 399 const struct usb_endpoint_descriptor *desc,
588 int is_host) 400 int is_host)
589{ 401{
590 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe); 402 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
591 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv); 403 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
592 struct device *dev = usbhs_priv_to_dev(priv); 404 struct device *dev = usbhs_priv_to_dev(priv);
593 int pipe_num = usbhs_pipe_number(pipe); 405 int pipe_num = usbhs_pipe_number(pipe);
594 int is_double = usbhsp_possible_double_buffer(pipe); 406 int is_double = usbhsp_possible_double_buffer(pipe);
@@ -666,7 +478,7 @@ static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe,
666 */ 478 */
667int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe) 479int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe)
668{ 480{
669 u16 mask = usbhsp_is_dcp(pipe) ? DCP_MAXP_MASK : PIPE_MAXP_MASK; 481 u16 mask = usbhs_pipe_is_dcp(pipe) ? DCP_MAXP_MASK : PIPE_MAXP_MASK;
670 482
671 usbhsp_pipe_select(pipe); 483 usbhsp_pipe_select(pipe);
672 484
@@ -678,11 +490,22 @@ int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe)
678 return usbhsp_flags_has(pipe, IS_DIR_IN); 490 return usbhsp_flags_has(pipe, IS_DIR_IN);
679} 491}
680 492
493int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe)
494{
495 return usbhsp_flags_has(pipe, IS_DIR_HOST);
496}
497
681void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe) 498void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe)
682{ 499{
683 usbhsp_pipectrl_set(pipe, SQCLR, SQCLR); 500 usbhsp_pipectrl_set(pipe, SQCLR, SQCLR);
684} 501}
685 502
503void usbhs_pipe_clear(struct usbhs_pipe *pipe)
504{
505 usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
506 usbhsp_pipectrl_set(pipe, ACLRM, 0);
507}
508
686static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type) 509static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
687{ 510{
688 struct usbhs_pipe *pos, *pipe; 511 struct usbhs_pipe *pos, *pipe;
@@ -714,12 +537,20 @@ static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
714 return pipe; 537 return pipe;
715} 538}
716 539
717void usbhs_pipe_init(struct usbhs_priv *priv) 540void usbhs_pipe_init(struct usbhs_priv *priv,
541 void (*done)(struct usbhs_pkt *pkt),
542 int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map))
718{ 543{
719 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv); 544 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
545 struct device *dev = usbhs_priv_to_dev(priv);
720 struct usbhs_pipe *pipe; 546 struct usbhs_pipe *pipe;
721 int i; 547 int i;
722 548
549 if (!done) {
550 dev_err(dev, "no done function\n");
551 return;
552 }
553
723 /* 554 /*
724 * FIXME 555 * FIXME
725 * 556 *
@@ -738,10 +569,16 @@ void usbhs_pipe_init(struct usbhs_priv *priv)
738 info->bufnmb_last++; 569 info->bufnmb_last++;
739 570
740 usbhsp_flags_init(pipe); 571 usbhsp_flags_init(pipe);
572 pipe->fifo = NULL;
741 pipe->mod_private = NULL; 573 pipe->mod_private = NULL;
574 INIT_LIST_HEAD(&pipe->list);
742 575
743 usbhsp_fifo_clear(pipe); 576 /* pipe force init */
577 usbhs_pipe_clear(pipe);
744 } 578 }
579
580 info->done = done;
581 info->dma_map_ctrl = dma_map_ctrl;
745} 582}
746 583
747struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv, 584struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
@@ -761,7 +598,9 @@ struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
761 return NULL; 598 return NULL;
762 } 599 }
763 600
764 usbhs_fifo_disable(pipe); 601 INIT_LIST_HEAD(&pipe->list);
602
603 usbhs_pipe_disable(pipe);
765 604
766 /* make sure pipe is not busy */ 605 /* make sure pipe is not busy */
767 ret = usbhsp_pipe_barrier(pipe); 606 ret = usbhsp_pipe_barrier(pipe);
@@ -774,11 +613,6 @@ struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
774 pipebuf = usbhsp_setup_pipebuff(pipe, desc, is_host); 613 pipebuf = usbhsp_setup_pipebuff(pipe, desc, is_host);
775 pipemaxp = usbhsp_setup_pipemaxp(pipe, desc, is_host); 614 pipemaxp = usbhsp_setup_pipemaxp(pipe, desc, is_host);
776 615
777 /* buffer clear
778 * see PIPECFG :: BFRE */
779 usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
780 usbhsp_pipectrl_set(pipe, ACLRM, 0);
781
782 usbhsp_pipe_select(pipe); 616 usbhsp_pipe_select(pipe);
783 usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg); 617 usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
784 usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf); 618 usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
@@ -794,6 +628,18 @@ struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
794 return pipe; 628 return pipe;
795} 629}
796 630
631void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo)
632{
633 if (pipe->fifo)
634 pipe->fifo->pipe = NULL;
635
636 pipe->fifo = fifo;
637
638 if (fifo)
639 fifo->pipe = pipe;
640}
641
642
797/* 643/*
798 * dcp control 644 * dcp control
799 */ 645 */
@@ -813,25 +659,25 @@ struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv)
813 659
814 usbhsp_pipe_select(pipe); 660 usbhsp_pipe_select(pipe);
815 usbhs_pipe_clear_sequence(pipe); 661 usbhs_pipe_clear_sequence(pipe);
662 INIT_LIST_HEAD(&pipe->list);
816 663
817 return pipe; 664 return pipe;
818} 665}
819 666
820void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe) 667void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
821{ 668{
822 WARN_ON(!usbhsp_is_dcp(pipe)); 669 WARN_ON(!usbhs_pipe_is_dcp(pipe));
823 670
824 usbhs_fifo_enable(pipe); 671 usbhs_pipe_enable(pipe);
825 usbhsp_pipectrl_set(pipe, CCPL, CCPL); 672 usbhsp_pipectrl_set(pipe, CCPL, CCPL);
826} 673}
827 674
828
829/* 675/*
830 * pipe module function 676 * pipe module function
831 */ 677 */
832int usbhs_pipe_probe(struct usbhs_priv *priv) 678int usbhs_pipe_probe(struct usbhs_priv *priv)
833{ 679{
834 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv); 680 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
835 struct usbhs_pipe *pipe; 681 struct usbhs_pipe *pipe;
836 struct device *dev = usbhs_priv_to_dev(priv); 682 struct device *dev = usbhs_priv_to_dev(priv);
837 u32 *pipe_type = usbhs_get_dparam(priv, pipe_type); 683 u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
@@ -868,7 +714,7 @@ int usbhs_pipe_probe(struct usbhs_priv *priv)
868 714
869void usbhs_pipe_remove(struct usbhs_priv *priv) 715void usbhs_pipe_remove(struct usbhs_priv *priv)
870{ 716{
871 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv); 717 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
872 718
873 kfree(info->pipe); 719 kfree(info->pipe);
874} 720}
diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h
index 1cca9b7fb266..41534cb0e734 100644
--- a/drivers/usb/renesas_usbhs/pipe.h
+++ b/drivers/usb/renesas_usbhs/pipe.h
@@ -18,6 +18,7 @@
18#define RENESAS_USB_PIPE_H 18#define RENESAS_USB_PIPE_H
19 19
20#include "./common.h" 20#include "./common.h"
21#include "./fifo.h"
21 22
22/* 23/*
23 * struct 24 * struct
@@ -26,10 +27,13 @@ struct usbhs_pipe {
26 u32 pipe_type; /* USB_ENDPOINT_XFER_xxx */ 27 u32 pipe_type; /* USB_ENDPOINT_XFER_xxx */
27 28
28 struct usbhs_priv *priv; 29 struct usbhs_priv *priv;
30 struct usbhs_fifo *fifo;
31 struct list_head list;
29 32
30 u32 flags; 33 u32 flags;
31#define USBHS_PIPE_FLAGS_IS_USED (1 << 0) 34#define USBHS_PIPE_FLAGS_IS_USED (1 << 0)
32#define USBHS_PIPE_FLAGS_IS_DIR_IN (1 << 1) 35#define USBHS_PIPE_FLAGS_IS_DIR_IN (1 << 1)
36#define USBHS_PIPE_FLAGS_IS_DIR_HOST (1 << 2)
33 37
34 void *mod_private; 38 void *mod_private;
35}; 39};
@@ -38,6 +42,9 @@ struct usbhs_pipe_info {
38 struct usbhs_pipe *pipe; 42 struct usbhs_pipe *pipe;
39 int size; /* array size of "pipe" */ 43 int size; /* array size of "pipe" */
40 int bufnmb_last; /* FIXME : driver needs good allocator */ 44 int bufnmb_last; /* FIXME : driver needs good allocator */
45
46 void (*done)(struct usbhs_pkt *pkt);
47 int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map);
41}; 48};
42 49
43/* 50/*
@@ -55,25 +62,9 @@ struct usbhs_pipe_info {
55 __usbhs_for_each_pipe(0, pos, &((priv)->pipe_info), i) 62 __usbhs_for_each_pipe(0, pos, &((priv)->pipe_info), i)
56 63
57/* 64/*
58 * pipe module probe / remove 65 * data
59 */ 66 */
60int usbhs_pipe_probe(struct usbhs_priv *priv); 67#define usbhs_priv_to_pipeinfo(pr) (&(pr)->pipe_info)
61void usbhs_pipe_remove(struct usbhs_priv *priv);
62
63/*
64 * cfifo
65 */
66int usbhs_fifo_write(struct usbhs_pipe *pipe, u8 *buf, int len);
67int usbhs_fifo_read(struct usbhs_pipe *pipe, u8 *buf, int len);
68int usbhs_fifo_prepare_write(struct usbhs_pipe *pipe);
69int usbhs_fifo_prepare_read(struct usbhs_pipe *pipe);
70
71void usbhs_fifo_enable(struct usbhs_pipe *pipe);
72void usbhs_fifo_disable(struct usbhs_pipe *pipe);
73void usbhs_fifo_stall(struct usbhs_pipe *pipe);
74
75void usbhs_fifo_send_terminator(struct usbhs_pipe *pipe);
76
77 68
78/* 69/*
79 * usb request 70 * usb request
@@ -87,13 +78,27 @@ void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req);
87struct usbhs_pipe 78struct usbhs_pipe
88*usbhs_pipe_malloc(struct usbhs_priv *priv, 79*usbhs_pipe_malloc(struct usbhs_priv *priv,
89 const struct usb_endpoint_descriptor *desc); 80 const struct usb_endpoint_descriptor *desc);
90 81int usbhs_pipe_probe(struct usbhs_priv *priv);
82void usbhs_pipe_remove(struct usbhs_priv *priv);
91int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe); 83int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe);
92void usbhs_pipe_init(struct usbhs_priv *priv); 84int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe);
85void usbhs_pipe_init(struct usbhs_priv *priv,
86 void (*done)(struct usbhs_pkt *pkt),
87 int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map));
93int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe); 88int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe);
94void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe); 89void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe);
95 90void usbhs_pipe_clear(struct usbhs_pipe *pipe);
91int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe);
92void usbhs_pipe_enable(struct usbhs_pipe *pipe);
93void usbhs_pipe_disable(struct usbhs_pipe *pipe);
94void usbhs_pipe_stall(struct usbhs_pipe *pipe);
95void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo);
96
97#define usbhs_pipe_to_priv(p) ((p)->priv)
96#define usbhs_pipe_number(p) (int)((p) - (p)->priv->pipe_info.pipe) 98#define usbhs_pipe_number(p) (int)((p) - (p)->priv->pipe_info.pipe)
99#define usbhs_pipe_is_dcp(p) ((p)->priv->pipe_info.pipe == (p))
100#define usbhs_pipe_to_fifo(p) ((p)->fifo)
101#define usbhs_pipe_is_busy(p) usbhs_pipe_to_fifo(p)
97 102
98/* 103/*
99 * dcp control 104 * dcp control
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 30461fcc2206..1d33260de014 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -91,6 +91,7 @@ static const struct usb_device_id id_table[] = {
91 { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) }, 91 { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) },
92 { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) }, 92 { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) },
93 { USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530_PRODUCT_ID) }, 93 { USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530_PRODUCT_ID) },
94 { USB_DEVICE(WINCHIPHEAD_VENDOR_ID, WINCHIPHEAD_USBSER_PRODUCT_ID) },
94 { } /* Terminating entry */ 95 { } /* Terminating entry */
95}; 96};
96 97
@@ -342,10 +343,28 @@ static void pl2303_set_termios(struct tty_struct *tty,
342 baud = 6000000; 343 baud = 6000000;
343 } 344 }
344 dbg("%s - baud set = %d", __func__, baud); 345 dbg("%s - baud set = %d", __func__, baud);
345 buf[0] = baud & 0xff; 346 if (baud <= 115200) {
346 buf[1] = (baud >> 8) & 0xff; 347 buf[0] = baud & 0xff;
347 buf[2] = (baud >> 16) & 0xff; 348 buf[1] = (baud >> 8) & 0xff;
348 buf[3] = (baud >> 24) & 0xff; 349 buf[2] = (baud >> 16) & 0xff;
350 buf[3] = (baud >> 24) & 0xff;
351 } else {
352 /* apparently the formula for higher speeds is:
353 * baudrate = 12M * 32 / (2^buf[1]) / buf[0]
354 */
355 unsigned tmp = 12*1000*1000*32 / baud;
356 buf[3] = 0x80;
357 buf[2] = 0;
358 buf[1] = (tmp >= 256);
359 while (tmp >= 256) {
360 tmp >>= 2;
361 buf[1] <<= 1;
362 }
363 if (tmp > 256) {
364 tmp %= 256;
365 }
366 buf[0] = tmp;
367 }
349 } 368 }
350 369
351 /* For reference buf[4]=0 is 1 stop bits */ 370 /* For reference buf[4]=0 is 1 stop bits */
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 1b025f75dafd..ca0d237683b3 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -144,3 +144,7 @@
144/* ADLINK ND-6530 RS232,RS485 and RS422 adapter */ 144/* ADLINK ND-6530 RS232,RS485 and RS422 adapter */
145#define ADLINK_VENDOR_ID 0x0b63 145#define ADLINK_VENDOR_ID 0x0b63
146#define ADLINK_ND6530_PRODUCT_ID 0x6530 146#define ADLINK_ND6530_PRODUCT_ID 0x6530
147
148/* WinChipHead USB->RS 232 adapter */
149#define WINCHIPHEAD_VENDOR_ID 0x4348
150#define WINCHIPHEAD_USBSER_PRODUCT_ID 0x5523
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index 97987255be75..58aabe679c32 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -40,6 +40,10 @@ config USB_STORAGE_REALTEK
40 40
41 If this driver is compiled as a module, it will be named ums-realtek. 41 If this driver is compiled as a module, it will be named ums-realtek.
42 42
43config REALTEK_AUTOPM
44 bool "Realtek Card Reader autosuspend support"
45 depends on USB_STORAGE_REALTEK && CONFIG_PM_RUNTIME
46 default y
43 47
44config USB_STORAGE_DATAFAB 48config USB_STORAGE_DATAFAB
45 tristate "Datafab Compact Flash Reader support" 49 tristate "Datafab Compact Flash Reader support"
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
index d509a4a7d74f..34adc4b42ceb 100644
--- a/drivers/usb/storage/realtek_cr.c
+++ b/drivers/usb/storage/realtek_cr.c
@@ -24,7 +24,6 @@
24#include <linux/blkdev.h> 24#include <linux/blkdev.h>
25#include <linux/kthread.h> 25#include <linux/kthread.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/workqueue.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/version.h> 28#include <linux/version.h>
30 29
@@ -51,6 +50,35 @@ static int auto_delink_en = 1;
51module_param(auto_delink_en, int, S_IRUGO | S_IWUSR); 50module_param(auto_delink_en, int, S_IRUGO | S_IWUSR);
52MODULE_PARM_DESC(auto_delink_en, "enable auto delink"); 51MODULE_PARM_DESC(auto_delink_en, "enable auto delink");
53 52
53#ifdef CONFIG_REALTEK_AUTOPM
54static int ss_en = 1;
55module_param(ss_en, int, S_IRUGO | S_IWUSR);
56MODULE_PARM_DESC(ss_en, "enable selective suspend");
57
58static int ss_delay = 50;
59module_param(ss_delay, int, S_IRUGO | S_IWUSR);
60MODULE_PARM_DESC(ss_delay,
61 "seconds to delay before entering selective suspend");
62
63enum RTS51X_STAT {
64 RTS51X_STAT_INIT,
65 RTS51X_STAT_IDLE,
66 RTS51X_STAT_RUN,
67 RTS51X_STAT_SS
68};
69
70#define POLLING_INTERVAL 50
71
72#define rts51x_set_stat(chip, stat) \
73 ((chip)->state = (enum RTS51X_STAT)(stat))
74#define rts51x_get_stat(chip) ((chip)->state)
75
76#define SET_LUN_READY(chip, lun) ((chip)->lun_ready |= ((u8)1 << (lun)))
77#define CLR_LUN_READY(chip, lun) ((chip)->lun_ready &= ~((u8)1 << (lun)))
78#define TST_LUN_READY(chip, lun) ((chip)->lun_ready & ((u8)1 << (lun)))
79
80#endif
81
54struct rts51x_status { 82struct rts51x_status {
55 u16 vid; 83 u16 vid;
56 u16 pid; 84 u16 pid;
@@ -70,14 +98,25 @@ struct rts51x_status {
70}; 98};
71 99
72struct rts51x_chip { 100struct rts51x_chip {
73 u16 vendor_id; 101 u16 vendor_id;
74 u16 product_id; 102 u16 product_id;
75 char max_lun; 103 char max_lun;
76 104
77 struct rts51x_status *status; 105 struct rts51x_status *status;
78 int status_len; 106 int status_len;
79 107
80 u32 flag; 108 u32 flag;
109#ifdef CONFIG_REALTEK_AUTOPM
110 struct us_data *us;
111 struct timer_list rts51x_suspend_timer;
112 unsigned long timer_expires;
113 int pwr_state;
114 u8 lun_ready;
115 enum RTS51X_STAT state;
116 int support_auto_delink;
117#endif
118 /* used to back up the protocal choosen in probe1 phase */
119 proto_cmnd proto_handler_backup;
81}; 120};
82 121
83/* flag definition */ 122/* flag definition */
@@ -97,9 +136,14 @@ struct rts51x_chip {
97#define RTS51X_GET_VID(chip) ((chip)->vendor_id) 136#define RTS51X_GET_VID(chip) ((chip)->vendor_id)
98#define RTS51X_GET_PID(chip) ((chip)->product_id) 137#define RTS51X_GET_PID(chip) ((chip)->product_id)
99 138
139#define VENDOR_ID(chip) ((chip)->status[0].vid)
140#define PRODUCT_ID(chip) ((chip)->status[0].pid)
100#define FW_VERSION(chip) ((chip)->status[0].fw_ver) 141#define FW_VERSION(chip) ((chip)->status[0].fw_ver)
101#define STATUS_LEN(chip) ((chip)->status_len) 142#define STATUS_LEN(chip) ((chip)->status_len)
102 143
144#define STATUS_SUCCESS 0
145#define STATUS_FAIL 1
146
103/* Check card reader function */ 147/* Check card reader function */
104#define SUPPORT_DETAILED_TYPE1(chip) \ 148#define SUPPORT_DETAILED_TYPE1(chip) \
105 CHK_BIT((chip)->status[0].function[0], 1) 149 CHK_BIT((chip)->status[0].function[0], 1)
@@ -119,15 +163,6 @@ struct rts51x_chip {
119#define CHECK_ID(chip, pid, fw_ver) \ 163#define CHECK_ID(chip, pid, fw_ver) \
120 (CHECK_PID((chip), (pid)) && CHECK_FW_VER((chip), (fw_ver))) 164 (CHECK_PID((chip), (pid)) && CHECK_FW_VER((chip), (fw_ver)))
121 165
122#define wait_timeout_x(task_state, msecs) \
123do { \
124 set_current_state((task_state)); \
125 schedule_timeout((msecs) * HZ / 1000); \
126} while (0)
127
128#define wait_timeout(msecs) \
129 wait_timeout_x(TASK_INTERRUPTIBLE, (msecs))
130
131static int init_realtek_cr(struct us_data *us); 166static int init_realtek_cr(struct us_data *us);
132 167
133/* 168/*
@@ -143,8 +178,9 @@ static int init_realtek_cr(struct us_data *us);
143 178
144static const struct usb_device_id realtek_cr_ids[] = { 179static const struct usb_device_id realtek_cr_ids[] = {
145# include "unusual_realtek.h" 180# include "unusual_realtek.h"
146 { } /* Terminating entry */ 181 {} /* Terminating entry */
147}; 182};
183
148MODULE_DEVICE_TABLE(usb, realtek_cr_ids); 184MODULE_DEVICE_TABLE(usb, realtek_cr_ids);
149 185
150#undef UNUSUAL_DEV 186#undef UNUSUAL_DEV
@@ -165,7 +201,7 @@ MODULE_DEVICE_TABLE(usb, realtek_cr_ids);
165 201
166static struct us_unusual_dev realtek_cr_unusual_dev_list[] = { 202static struct us_unusual_dev realtek_cr_unusual_dev_list[] = {
167# include "unusual_realtek.h" 203# include "unusual_realtek.h"
168 { } /* Terminating entry */ 204 {} /* Terminating entry */
169}; 205};
170 206
171#undef UNUSUAL_DEV 207#undef UNUSUAL_DEV
@@ -174,8 +210,8 @@ static int rts51x_bulk_transport(struct us_data *us, u8 lun,
174 u8 *cmd, int cmd_len, u8 *buf, int buf_len, 210 u8 *cmd, int cmd_len, u8 *buf, int buf_len,
175 enum dma_data_direction dir, int *act_len) 211 enum dma_data_direction dir, int *act_len)
176{ 212{
177 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 213 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *)us->iobuf;
178 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 214 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *)us->iobuf;
179 int result; 215 int result;
180 unsigned int residue; 216 unsigned int residue;
181 unsigned int cswlen; 217 unsigned int cswlen;
@@ -195,7 +231,7 @@ static int rts51x_bulk_transport(struct us_data *us, u8 lun,
195 231
196 /* send it to out endpoint */ 232 /* send it to out endpoint */
197 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, 233 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
198 bcb, cbwlen, NULL); 234 bcb, cbwlen, NULL);
199 if (result != USB_STOR_XFER_GOOD) 235 if (result != USB_STOR_XFER_GOOD)
200 return USB_STOR_TRANSPORT_ERROR; 236 return USB_STOR_TRANSPORT_ERROR;
201 237
@@ -204,24 +240,23 @@ static int rts51x_bulk_transport(struct us_data *us, u8 lun,
204 240
205 if (buf && buf_len) { 241 if (buf && buf_len) {
206 unsigned int pipe = (dir == DMA_FROM_DEVICE) ? 242 unsigned int pipe = (dir == DMA_FROM_DEVICE) ?
207 us->recv_bulk_pipe : us->send_bulk_pipe; 243 us->recv_bulk_pipe : us->send_bulk_pipe;
208 result = usb_stor_bulk_transfer_buf(us, pipe, 244 result = usb_stor_bulk_transfer_buf(us, pipe,
209 buf, buf_len, NULL); 245 buf, buf_len, NULL);
210 if (result == USB_STOR_XFER_ERROR) 246 if (result == USB_STOR_XFER_ERROR)
211 return USB_STOR_TRANSPORT_ERROR; 247 return USB_STOR_TRANSPORT_ERROR;
212 } 248 }
213 249
214 /* get CSW for device status */ 250 /* get CSW for device status */
215 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 251 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
216 bcs, US_BULK_CS_WRAP_LEN, &cswlen); 252 bcs, US_BULK_CS_WRAP_LEN, &cswlen);
217 if (result != USB_STOR_XFER_GOOD) 253 if (result != USB_STOR_XFER_GOOD)
218 return USB_STOR_TRANSPORT_ERROR; 254 return USB_STOR_TRANSPORT_ERROR;
219 255
220 /* check bulk status */ 256 /* check bulk status */
221 if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN)) { 257 if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN)) {
222 US_DEBUGP("Signature mismatch: got %08X, expecting %08X\n", 258 US_DEBUGP("Signature mismatch: got %08X, expecting %08X\n",
223 le32_to_cpu(bcs->Signature), 259 le32_to_cpu(bcs->Signature), US_BULK_CS_SIGN);
224 US_BULK_CS_SIGN);
225 return USB_STOR_TRANSPORT_ERROR; 260 return USB_STOR_TRANSPORT_ERROR;
226 } 261 }
227 262
@@ -249,8 +284,8 @@ static int rts51x_bulk_transport(struct us_data *us, u8 lun,
249 284
250 case US_BULK_STAT_PHASE: 285 case US_BULK_STAT_PHASE:
251 /* phase error -- note that a transport reset will be 286 /* phase error -- note that a transport reset will be
252 * invoked by the invoke_transport() function 287 * invoked by the invoke_transport() function
253 */ 288 */
254 return USB_STOR_TRANSPORT_ERROR; 289 return USB_STOR_TRANSPORT_ERROR;
255 } 290 }
256 291
@@ -266,10 +301,10 @@ static int rts51x_get_max_lun(struct us_data *us)
266 /* issue the command */ 301 /* issue the command */
267 us->iobuf[0] = 0; 302 us->iobuf[0] = 0;
268 result = usb_stor_control_msg(us, us->recv_ctrl_pipe, 303 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
269 US_BULK_GET_MAX_LUN, 304 US_BULK_GET_MAX_LUN,
270 USB_DIR_IN | USB_TYPE_CLASS | 305 USB_DIR_IN | USB_TYPE_CLASS |
271 USB_RECIP_INTERFACE, 306 USB_RECIP_INTERFACE,
272 0, us->ifnum, us->iobuf, 1, 10*HZ); 307 0, us->ifnum, us->iobuf, 1, 10 * HZ);
273 308
274 US_DEBUGP("GetMaxLUN command result is %d, data is %d\n", 309 US_DEBUGP("GetMaxLUN command result is %d, data is %d\n",
275 result, us->iobuf[0]); 310 result, us->iobuf[0]);
@@ -284,16 +319,16 @@ static int rts51x_get_max_lun(struct us_data *us)
284static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len) 319static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
285{ 320{
286 int retval; 321 int retval;
287 u8 cmnd[12] = {0}; 322 u8 cmnd[12] = { 0 };
288 323
289 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); 324 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
290 325
291 cmnd[0] = 0xF0; 326 cmnd[0] = 0xF0;
292 cmnd[1] = 0x0D; 327 cmnd[1] = 0x0D;
293 cmnd[2] = (u8)(addr >> 8); 328 cmnd[2] = (u8) (addr >> 8);
294 cmnd[3] = (u8)addr; 329 cmnd[3] = (u8) addr;
295 cmnd[4] = (u8)(len >> 8); 330 cmnd[4] = (u8) (len >> 8);
296 cmnd[5] = (u8)len; 331 cmnd[5] = (u8) len;
297 332
298 retval = rts51x_bulk_transport(us, 0, cmnd, 12, 333 retval = rts51x_bulk_transport(us, 0, cmnd, 12,
299 data, len, DMA_FROM_DEVICE, NULL); 334 data, len, DMA_FROM_DEVICE, NULL);
@@ -306,16 +341,16 @@ static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
306static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len) 341static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
307{ 342{
308 int retval; 343 int retval;
309 u8 cmnd[12] = {0}; 344 u8 cmnd[12] = { 0 };
310 345
311 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); 346 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
312 347
313 cmnd[0] = 0xF0; 348 cmnd[0] = 0xF0;
314 cmnd[1] = 0x0E; 349 cmnd[1] = 0x0E;
315 cmnd[2] = (u8)(addr >> 8); 350 cmnd[2] = (u8) (addr >> 8);
316 cmnd[3] = (u8)addr; 351 cmnd[3] = (u8) addr;
317 cmnd[4] = (u8)(len >> 8); 352 cmnd[4] = (u8) (len >> 8);
318 cmnd[5] = (u8)len; 353 cmnd[5] = (u8) len;
319 354
320 retval = rts51x_bulk_transport(us, 0, cmnd, 12, 355 retval = rts51x_bulk_transport(us, 0, cmnd, 12,
321 data, len, DMA_TO_DEVICE, NULL); 356 data, len, DMA_TO_DEVICE, NULL);
@@ -329,7 +364,7 @@ static int rts51x_read_status(struct us_data *us,
329 u8 lun, u8 *status, int len, int *actlen) 364 u8 lun, u8 *status, int len, int *actlen)
330{ 365{
331 int retval; 366 int retval;
332 u8 cmnd[12] = {0}; 367 u8 cmnd[12] = { 0 };
333 368
334 US_DEBUGP("%s, lun = %d\n", __func__, lun); 369 US_DEBUGP("%s, lun = %d\n", __func__, lun);
335 370
@@ -356,12 +391,12 @@ static int rts51x_check_status(struct us_data *us, u8 lun)
356 391
357 US_DEBUGP("chip->status_len = %d\n", chip->status_len); 392 US_DEBUGP("chip->status_len = %d\n", chip->status_len);
358 393
359 chip->status[lun].vid = ((u16)buf[0] << 8) | buf[1]; 394 chip->status[lun].vid = ((u16) buf[0] << 8) | buf[1];
360 chip->status[lun].pid = ((u16)buf[2] << 8) | buf[3]; 395 chip->status[lun].pid = ((u16) buf[2] << 8) | buf[3];
361 chip->status[lun].cur_lun = buf[4]; 396 chip->status[lun].cur_lun = buf[4];
362 chip->status[lun].card_type = buf[5]; 397 chip->status[lun].card_type = buf[5];
363 chip->status[lun].total_lun = buf[6]; 398 chip->status[lun].total_lun = buf[6];
364 chip->status[lun].fw_ver = ((u16)buf[7] << 8) | buf[8]; 399 chip->status[lun].fw_ver = ((u16) buf[7] << 8) | buf[8];
365 chip->status[lun].phy_exist = buf[9]; 400 chip->status[lun].phy_exist = buf[9];
366 chip->status[lun].multi_flag = buf[10]; 401 chip->status[lun].multi_flag = buf[10];
367 chip->status[lun].multi_card = buf[11]; 402 chip->status[lun].multi_card = buf[11];
@@ -432,6 +467,8 @@ static int config_autodelink_after_power_on(struct us_data *us)
432 int retval; 467 int retval;
433 u8 value; 468 u8 value;
434 469
470 US_DEBUGP("%s: <---\n", __func__);
471
435 if (!CHK_AUTO_DELINK(chip)) 472 if (!CHK_AUTO_DELINK(chip))
436 return 0; 473 return 0;
437 474
@@ -465,7 +502,7 @@ static int config_autodelink_after_power_on(struct us_data *us)
465 CLR_BIT(value, 2); 502 CLR_BIT(value, 2);
466 503
467 if (CHECK_ID(chip, 0x0159, 0x5889) || 504 if (CHECK_ID(chip, 0x0159, 0x5889) ||
468 CHECK_ID(chip, 0x0138, 0x3880)) { 505 CHECK_ID(chip, 0x0138, 0x3880)) {
469 CLR_BIT(value, 0); 506 CLR_BIT(value, 0);
470 CLR_BIT(value, 7); 507 CLR_BIT(value, 7);
471 } 508 }
@@ -487,6 +524,8 @@ static int config_autodelink_after_power_on(struct us_data *us)
487 } 524 }
488 } 525 }
489 526
527 US_DEBUGP("%s: --->\n", __func__);
528
490 return 0; 529 return 0;
491} 530}
492 531
@@ -496,6 +535,8 @@ static int config_autodelink_before_power_down(struct us_data *us)
496 int retval; 535 int retval;
497 u8 value; 536 u8 value;
498 537
538 US_DEBUGP("%s: <---\n", __func__);
539
499 if (!CHK_AUTO_DELINK(chip)) 540 if (!CHK_AUTO_DELINK(chip))
500 return 0; 541 return 0;
501 542
@@ -528,14 +569,14 @@ static int config_autodelink_before_power_down(struct us_data *us)
528 return -EIO; 569 return -EIO;
529 } else { 570 } else {
530 if (CHECK_ID(chip, 0x0159, 0x5889) || 571 if (CHECK_ID(chip, 0x0159, 0x5889) ||
531 CHECK_ID(chip, 0x0138, 0x3880) || 572 CHECK_ID(chip, 0x0138, 0x3880) ||
532 CHECK_ID(chip, 0x0138, 0x3882)) { 573 CHECK_ID(chip, 0x0138, 0x3882)) {
533 retval = rts51x_read_mem(us, 0xFE47, &value, 1); 574 retval = rts51x_read_mem(us, 0xFE47, &value, 1);
534 if (retval < 0) 575 if (retval < 0)
535 return -EIO; 576 return -EIO;
536 577
537 if (CHECK_ID(chip, 0x0159, 0x5889) || 578 if (CHECK_ID(chip, 0x0159, 0x5889) ||
538 CHECK_ID(chip, 0x0138, 0x3880)) { 579 CHECK_ID(chip, 0x0138, 0x3880)) {
539 SET_BIT(value, 0); 580 SET_BIT(value, 0);
540 SET_BIT(value, 7); 581 SET_BIT(value, 7);
541 } 582 }
@@ -556,25 +597,323 @@ static int config_autodelink_before_power_down(struct us_data *us)
556 } 597 }
557 } 598 }
558 599
600 US_DEBUGP("%s: --->\n", __func__);
601
602 return 0;
603}
604
605static void fw5895_init(struct us_data *us)
606{
607 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
608 int retval;
609 u8 val;
610
611 US_DEBUGP("%s: <---\n", __func__);
612
613 if ((PRODUCT_ID(chip) != 0x0158) || (FW_VERSION(chip) != 0x5895)) {
614 US_DEBUGP("Not the specified device, return immediately!\n");
615 } else {
616 retval = rts51x_read_mem(us, 0xFD6F, &val, 1);
617 if (retval == STATUS_SUCCESS && (val & 0x1F) == 0) {
618 val = 0x1F;
619 retval = rts51x_write_mem(us, 0xFD70, &val, 1);
620 if (retval != STATUS_SUCCESS)
621 US_DEBUGP("Write memory fail\n");
622 } else {
623 US_DEBUGP("Read memory fail, OR (val & 0x1F) != 0\n");
624 }
625 }
626
627 US_DEBUGP("%s: --->\n", __func__);
628}
629
630#ifdef CONFIG_REALTEK_AUTOPM
631static void fw5895_set_mmc_wp(struct us_data *us)
632{
633 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
634 int retval;
635 u8 buf[13];
636
637 US_DEBUGP("%s: <---\n", __func__);
638
639 if ((PRODUCT_ID(chip) != 0x0158) || (FW_VERSION(chip) != 0x5895)) {
640 US_DEBUGP("Not the specified device, return immediately!\n");
641 } else {
642 retval = rts51x_read_mem(us, 0xFD6F, buf, 1);
643 if (retval == STATUS_SUCCESS && (buf[0] & 0x24) == 0x24) {
644 /* SD Exist and SD WP */
645 retval = rts51x_read_mem(us, 0xD04E, buf, 1);
646 if (retval == STATUS_SUCCESS) {
647 buf[0] |= 0x04;
648 retval = rts51x_write_mem(us, 0xFD70, buf, 1);
649 if (retval != STATUS_SUCCESS)
650 US_DEBUGP("Write memory fail\n");
651 } else {
652 US_DEBUGP("Read memory fail\n");
653 }
654 } else {
655 US_DEBUGP("Read memory fail, OR (buf[0]&0x24)!=0x24\n");
656 }
657 }
658
659 US_DEBUGP("%s: --->\n", __func__);
660}
661
662static void rts51x_modi_suspend_timer(struct rts51x_chip *chip)
663{
664 US_DEBUGP("%s: <---, state:%d\n", __func__, rts51x_get_stat(chip));
665
666 chip->timer_expires = jiffies + msecs_to_jiffies(1000*ss_delay);
667 mod_timer(&chip->rts51x_suspend_timer, chip->timer_expires);
668
669 US_DEBUGP("%s: --->\n", __func__);
670}
671
672static void rts51x_suspend_timer_fn(unsigned long data)
673{
674 struct rts51x_chip *chip = (struct rts51x_chip *)data;
675 struct us_data *us = chip->us;
676
677 US_DEBUGP("%s: <---\n", __func__);
678
679 switch (rts51x_get_stat(chip)) {
680 case RTS51X_STAT_INIT:
681 case RTS51X_STAT_RUN:
682 rts51x_modi_suspend_timer(chip);
683 break;
684 case RTS51X_STAT_IDLE:
685 case RTS51X_STAT_SS:
686 US_DEBUGP("%s: RTS51X_STAT_SS, intf->pm_usage_cnt:%d,"
687 "power.usage:%d\n", __func__,
688 atomic_read(&us->pusb_intf->pm_usage_cnt),
689 atomic_read(&us->pusb_intf->dev.power.usage_count));
690
691 if (atomic_read(&us->pusb_intf->pm_usage_cnt) > 0) {
692 US_DEBUGP("%s: Ready to enter SS state.\n",
693 __func__);
694 rts51x_set_stat(chip, RTS51X_STAT_SS);
695 /* ignore mass storage interface's children */
696 pm_suspend_ignore_children(&us->pusb_intf->dev, true);
697 usb_autopm_put_interface(us->pusb_intf);
698 US_DEBUGP("%s: RTS51X_STAT_SS 01,"
699 "intf->pm_usage_cnt:%d, power.usage:%d\n",
700 __func__,
701 atomic_read(&us->pusb_intf->pm_usage_cnt),
702 atomic_read(
703 &us->pusb_intf->dev.power.usage_count));
704 }
705 break;
706 default:
707 US_DEBUGP("%s: Unknonwn state !!!\n", __func__);
708 break;
709 }
710
711 US_DEBUGP("%s: --->\n", __func__);
712}
713
714static inline int working_scsi(struct scsi_cmnd *srb)
715{
716 if ((srb->cmnd[0] == TEST_UNIT_READY) ||
717 (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL)) {
718 return 0;
719 }
720
721 return 1;
722}
723
724void rts51x_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
725{
726 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
727 static int card_first_show = 1;
728 static u8 media_not_present[] = { 0x70, 0, 0x02, 0, 0, 0, 0,
729 10, 0, 0, 0, 0, 0x3A, 0, 0, 0, 0, 0
730 };
731 static u8 invalid_cmd_field[] = { 0x70, 0, 0x05, 0, 0, 0, 0,
732 10, 0, 0, 0, 0, 0x24, 0, 0, 0, 0, 0
733 };
734 int ret;
735
736 US_DEBUGP("%s: <---\n", __func__);
737
738 if (working_scsi(srb)) {
739 US_DEBUGP("%s: working scsi, intf->pm_usage_cnt:%d,"
740 "power.usage:%d\n", __func__,
741 atomic_read(&us->pusb_intf->pm_usage_cnt),
742 atomic_read(&us->pusb_intf->dev.power.usage_count));
743
744 if (atomic_read(&us->pusb_intf->pm_usage_cnt) <= 0) {
745 ret = usb_autopm_get_interface(us->pusb_intf);
746 US_DEBUGP("%s: working scsi, ret=%d\n", __func__, ret);
747 }
748 if (rts51x_get_stat(chip) != RTS51X_STAT_RUN)
749 rts51x_set_stat(chip, RTS51X_STAT_RUN);
750 chip->proto_handler_backup(srb, us);
751 } else {
752 if (rts51x_get_stat(chip) == RTS51X_STAT_SS) {
753 US_DEBUGP("%s: NOT working scsi\n", __func__);
754 if ((srb->cmnd[0] == TEST_UNIT_READY) &&
755 (chip->pwr_state == US_SUSPEND)) {
756 if (TST_LUN_READY(chip, srb->device->lun)) {
757 srb->result = SAM_STAT_GOOD;
758 } else {
759 srb->result = SAM_STAT_CHECK_CONDITION;
760 memcpy(srb->sense_buffer,
761 media_not_present,
762 US_SENSE_SIZE);
763 }
764 US_DEBUGP("%s: TEST_UNIT_READY--->\n",
765 __func__);
766 goto out;
767 }
768 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
769 int prevent = srb->cmnd[4] & 0x1;
770 if (prevent) {
771 srb->result = SAM_STAT_CHECK_CONDITION;
772 memcpy(srb->sense_buffer,
773 invalid_cmd_field,
774 US_SENSE_SIZE);
775 } else {
776 srb->result = SAM_STAT_GOOD;
777 }
778 US_DEBUGP("%s: ALLOW_MEDIUM_REMOVAL--->\n",
779 __func__);
780 goto out;
781 }
782 } else {
783 US_DEBUGP("%s: NOT working scsi, not SS\n", __func__);
784 chip->proto_handler_backup(srb, us);
785 /* Check wether card is plugged in */
786 if (srb->cmnd[0] == TEST_UNIT_READY) {
787 if (srb->result == SAM_STAT_GOOD) {
788 SET_LUN_READY(chip, srb->device->lun);
789 if (card_first_show) {
790 card_first_show = 0;
791 fw5895_set_mmc_wp(us);
792 }
793 } else {
794 CLR_LUN_READY(chip, srb->device->lun);
795 card_first_show = 1;
796 }
797 }
798 if (rts51x_get_stat(chip) != RTS51X_STAT_IDLE)
799 rts51x_set_stat(chip, RTS51X_STAT_IDLE);
800 }
801 }
802out:
803 US_DEBUGP("%s: state:%d\n", __func__, rts51x_get_stat(chip));
804 if (rts51x_get_stat(chip) == RTS51X_STAT_RUN)
805 rts51x_modi_suspend_timer(chip);
806
807 US_DEBUGP("%s: --->\n", __func__);
808}
809
810static int realtek_cr_autosuspend_setup(struct us_data *us)
811{
812 struct rts51x_chip *chip;
813 struct rts51x_status *status = NULL;
814 u8 buf[16];
815 int retval;
816
817 chip = (struct rts51x_chip *)us->extra;
818 chip->support_auto_delink = 0;
819 chip->pwr_state = US_RESUME;
820 chip->lun_ready = 0;
821 rts51x_set_stat(chip, RTS51X_STAT_INIT);
822
823 retval = rts51x_read_status(us, 0, buf, 16, &(chip->status_len));
824 if (retval != STATUS_SUCCESS) {
825 US_DEBUGP("Read status fail\n");
826 return -EIO;
827 }
828 status = chip->status;
829 status->vid = ((u16) buf[0] << 8) | buf[1];
830 status->pid = ((u16) buf[2] << 8) | buf[3];
831 status->cur_lun = buf[4];
832 status->card_type = buf[5];
833 status->total_lun = buf[6];
834 status->fw_ver = ((u16) buf[7] << 8) | buf[8];
835 status->phy_exist = buf[9];
836 status->multi_flag = buf[10];
837 status->multi_card = buf[11];
838 status->log_exist = buf[12];
839 if (chip->status_len == 16) {
840 status->detailed_type.detailed_type1 = buf[13];
841 status->function[0] = buf[14];
842 status->function[1] = buf[15];
843 }
844
845 /* back up the proto_handler in us->extra */
846 chip = (struct rts51x_chip *)(us->extra);
847 chip->proto_handler_backup = us->proto_handler;
848 /* Set the autosuspend_delay to 0 */
849 pm_runtime_set_autosuspend_delay(&us->pusb_dev->dev, 0);
850 /* override us->proto_handler setted in get_protocol() */
851 us->proto_handler = rts51x_invoke_transport;
852
853 chip->timer_expires = 0;
854 setup_timer(&chip->rts51x_suspend_timer, rts51x_suspend_timer_fn,
855 (unsigned long)chip);
856 fw5895_init(us);
857
858 /* enable autosuspend funciton of the usb device */
859 usb_enable_autosuspend(us->pusb_dev);
860
559 return 0; 861 return 0;
560} 862}
863#endif
561 864
562static void realtek_cr_destructor(void *extra) 865static void realtek_cr_destructor(void *extra)
563{ 866{
564 struct rts51x_chip *chip = (struct rts51x_chip *)extra; 867 struct rts51x_chip *chip = (struct rts51x_chip *)extra;
565 868
869 US_DEBUGP("%s: <---\n", __func__);
870
566 if (!chip) 871 if (!chip)
567 return; 872 return;
568 873#ifdef CONFIG_REALTEK_AUTOPM
874 if (ss_en) {
875 del_timer(&chip->rts51x_suspend_timer);
876 chip->timer_expires = 0;
877 }
878#endif
569 kfree(chip->status); 879 kfree(chip->status);
570} 880}
571 881
572#ifdef CONFIG_PM 882#ifdef CONFIG_PM
573static void realtek_pm_hook(struct us_data *us, int pm_state) 883int realtek_cr_suspend(struct usb_interface *iface, pm_message_t message)
884{
885 struct us_data *us = usb_get_intfdata(iface);
886
887 US_DEBUGP("%s: <---\n", __func__);
888
889 /* wait until no command is running */
890 mutex_lock(&us->dev_mutex);
891
892 config_autodelink_before_power_down(us);
893
894 mutex_unlock(&us->dev_mutex);
895
896 US_DEBUGP("%s: --->\n", __func__);
897
898 return 0;
899}
900
901static int realtek_cr_resume(struct usb_interface *iface)
574{ 902{
575 if (pm_state == US_SUSPEND) 903 struct us_data *us = usb_get_intfdata(iface);
576 (void)config_autodelink_before_power_down(us); 904
905 US_DEBUGP("%s: <---\n", __func__);
906
907 fw5895_init(us);
908 config_autodelink_after_power_on(us);
909
910 US_DEBUGP("%s: --->\n", __func__);
911
912 return 0;
577} 913}
914#else
915#define realtek_cr_suspend NULL
916#define realtek_cr_resume NULL
578#endif 917#endif
579 918
580static int init_realtek_cr(struct us_data *us) 919static int init_realtek_cr(struct us_data *us)
@@ -588,10 +927,6 @@ static int init_realtek_cr(struct us_data *us)
588 927
589 us->extra = chip; 928 us->extra = chip;
590 us->extra_destructor = realtek_cr_destructor; 929 us->extra_destructor = realtek_cr_destructor;
591#ifdef CONFIG_PM
592 us->suspend_resume_hook = realtek_pm_hook;
593#endif
594
595 us->max_lun = chip->max_lun = rts51x_get_max_lun(us); 930 us->max_lun = chip->max_lun = rts51x_get_max_lun(us);
596 931
597 US_DEBUGP("chip->max_lun = %d\n", chip->max_lun); 932 US_DEBUGP("chip->max_lun = %d\n", chip->max_lun);
@@ -602,18 +937,24 @@ static int init_realtek_cr(struct us_data *us)
602 goto INIT_FAIL; 937 goto INIT_FAIL;
603 938
604 for (i = 0; i <= (int)(chip->max_lun); i++) { 939 for (i = 0; i <= (int)(chip->max_lun); i++) {
605 retval = rts51x_check_status(us, (u8)i); 940 retval = rts51x_check_status(us, (u8) i);
606 if (retval < 0) 941 if (retval < 0)
607 goto INIT_FAIL; 942 goto INIT_FAIL;
608 } 943 }
609 944
610 if (CHECK_FW_VER(chip, 0x5888) || CHECK_FW_VER(chip, 0x5889) || 945 if (CHECK_FW_VER(chip, 0x5888) || CHECK_FW_VER(chip, 0x5889) ||
611 CHECK_FW_VER(chip, 0x5901)) 946 CHECK_FW_VER(chip, 0x5901))
612 SET_AUTO_DELINK(chip); 947 SET_AUTO_DELINK(chip);
613 if (STATUS_LEN(chip) == 16) { 948 if (STATUS_LEN(chip) == 16) {
614 if (SUPPORT_AUTO_DELINK(chip)) 949 if (SUPPORT_AUTO_DELINK(chip))
615 SET_AUTO_DELINK(chip); 950 SET_AUTO_DELINK(chip);
616 } 951 }
952#ifdef CONFIG_REALTEK_AUTOPM
953 if (ss_en) {
954 chip->us = us;
955 realtek_cr_autosuspend_setup(us);
956 }
957#endif
617 958
618 US_DEBUGP("chip->flag = 0x%x\n", chip->flag); 959 US_DEBUGP("chip->flag = 0x%x\n", chip->flag);
619 960
@@ -632,7 +973,7 @@ INIT_FAIL:
632} 973}
633 974
634static int realtek_cr_probe(struct usb_interface *intf, 975static int realtek_cr_probe(struct usb_interface *intf,
635 const struct usb_device_id *id) 976 const struct usb_device_id *id)
636{ 977{
637 struct us_data *us; 978 struct us_data *us;
638 int result; 979 int result;
@@ -640,25 +981,30 @@ static int realtek_cr_probe(struct usb_interface *intf,
640 US_DEBUGP("Probe Realtek Card Reader!\n"); 981 US_DEBUGP("Probe Realtek Card Reader!\n");
641 982
642 result = usb_stor_probe1(&us, intf, id, 983 result = usb_stor_probe1(&us, intf, id,
643 (id - realtek_cr_ids) + realtek_cr_unusual_dev_list); 984 (id - realtek_cr_ids) +
985 realtek_cr_unusual_dev_list);
644 if (result) 986 if (result)
645 return result; 987 return result;
646 988
647 result = usb_stor_probe2(us); 989 result = usb_stor_probe2(us);
990
648 return result; 991 return result;
649} 992}
650 993
651static struct usb_driver realtek_cr_driver = { 994static struct usb_driver realtek_cr_driver = {
652 .name = "ums-realtek", 995 .name = "ums-realtek",
653 .probe = realtek_cr_probe, 996 .probe = realtek_cr_probe,
654 .disconnect = usb_stor_disconnect, 997 .disconnect = usb_stor_disconnect,
655 .suspend = usb_stor_suspend, 998 /* .suspend = usb_stor_suspend, */
656 .resume = usb_stor_resume, 999 /* .resume = usb_stor_resume, */
657 .reset_resume = usb_stor_reset_resume, 1000 .reset_resume = usb_stor_reset_resume,
658 .pre_reset = usb_stor_pre_reset, 1001 .suspend = realtek_cr_suspend,
659 .post_reset = usb_stor_post_reset, 1002 .resume = realtek_cr_resume,
660 .id_table = realtek_cr_ids, 1003 .pre_reset = usb_stor_pre_reset,
661 .soft_unbind = 1, 1004 .post_reset = usb_stor_post_reset,
1005 .id_table = realtek_cr_ids,
1006 .soft_unbind = 1,
1007 .supports_autosuspend = 1,
662}; 1008};
663 1009
664static int __init realtek_cr_init(void) 1010static int __init realtek_cr_init(void)
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
index c0c5665e60a9..200fd7c6c7d5 100644
--- a/drivers/usb/wusbcore/cbaf.c
+++ b/drivers/usb/wusbcore/cbaf.c
@@ -298,7 +298,7 @@ static int cbaf_cdid_get(struct cbaf *cbaf)
298 if (result < needed) { 298 if (result < needed) {
299 dev_err(dev, "Not enough data in DEVICE_INFO reply (%zu vs " 299 dev_err(dev, "Not enough data in DEVICE_INFO reply (%zu vs "
300 "%zu bytes needed)\n", (size_t)result, needed); 300 "%zu bytes needed)\n", (size_t)result, needed);
301 return result; 301 return -ENOENT;
302 } 302 }
303 303
304 strlcpy(cbaf->device_name, di->DeviceFriendlyName, CBA_NAME_LEN); 304 strlcpy(cbaf->device_name, di->DeviceFriendlyName, CBA_NAME_LEN);
@@ -350,7 +350,7 @@ static ssize_t cbaf_wusb_chid_store(struct device *dev,
350 return result; 350 return result;
351 result = cbaf_cdid_get(cbaf); 351 result = cbaf_cdid_get(cbaf);
352 if (result < 0) 352 if (result < 0)
353 return -result; 353 return result;
354 return size; 354 return size;
355} 355}
356static DEVICE_ATTR(wusb_chid, 0600, cbaf_wusb_chid_show, cbaf_wusb_chid_store); 356static DEVICE_ATTR(wusb_chid, 0600, cbaf_wusb_chid_show, cbaf_wusb_chid_store);
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 6ccd93a9b909..419334568be6 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -83,6 +83,7 @@
83#include <linux/spinlock.h> 83#include <linux/spinlock.h>
84#include <linux/slab.h> 84#include <linux/slab.h>
85#include <linux/hash.h> 85#include <linux/hash.h>
86#include <linux/ratelimit.h>
86 87
87#include "wa-hc.h" 88#include "wa-hc.h"
88#include "wusbhc.h" 89#include "wusbhc.h"
@@ -1217,16 +1218,14 @@ static int wa_xfer_status_to_errno(u8 status)
1217 if (status == 0) 1218 if (status == 0)
1218 return 0; 1219 return 0;
1219 if (status >= ARRAY_SIZE(xlat)) { 1220 if (status >= ARRAY_SIZE(xlat)) {
1220 if (printk_ratelimit()) 1221 printk_ratelimited(KERN_ERR "%s(): BUG? "
1221 printk(KERN_ERR "%s(): BUG? "
1222 "Unknown WA transfer status 0x%02x\n", 1222 "Unknown WA transfer status 0x%02x\n",
1223 __func__, real_status); 1223 __func__, real_status);
1224 return -EINVAL; 1224 return -EINVAL;
1225 } 1225 }
1226 errno = xlat[status]; 1226 errno = xlat[status];
1227 if (unlikely(errno > 0)) { 1227 if (unlikely(errno > 0)) {
1228 if (printk_ratelimit()) 1228 printk_ratelimited(KERN_ERR "%s(): BUG? "
1229 printk(KERN_ERR "%s(): BUG? "
1230 "Inconsistent WA status: 0x%02x\n", 1229 "Inconsistent WA status: 0x%02x\n",
1231 __func__, real_status); 1230 __func__, real_status);
1232 errno = -errno; 1231 errno = -errno;
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index b78cba466d3d..a316fba73518 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -59,6 +59,10 @@ struct usb_configuration;
59 * @hs_descriptors: Table of high speed descriptors, using interface and 59 * @hs_descriptors: Table of high speed descriptors, using interface and
60 * string identifiers assigned during @bind(). If this pointer is null, 60 * string identifiers assigned during @bind(). If this pointer is null,
61 * the function will not be available at high speed. 61 * the function will not be available at high speed.
62 * @ss_descriptors: Table of super speed descriptors, using interface and
63 * string identifiers assigned during @bind(). If this
64 * pointer is null after initiation, the function will not
65 * be available at super speed.
62 * @config: assigned when @usb_add_function() is called; this is the 66 * @config: assigned when @usb_add_function() is called; this is the
63 * configuration with which this function is associated. 67 * configuration with which this function is associated.
64 * @bind: Before the gadget can register, all of its functions bind() to the 68 * @bind: Before the gadget can register, all of its functions bind() to the
@@ -77,6 +81,10 @@ struct usb_configuration;
77 * @setup: Used for interface-specific control requests. 81 * @setup: Used for interface-specific control requests.
78 * @suspend: Notifies functions when the host stops sending USB traffic. 82 * @suspend: Notifies functions when the host stops sending USB traffic.
79 * @resume: Notifies functions when the host restarts USB traffic. 83 * @resume: Notifies functions when the host restarts USB traffic.
84 * @get_status: Returns function status as a reply to
85 * GetStatus() request when the recepient is Interface.
86 * @func_suspend: callback to be called when
87 * SetFeature(FUNCTION_SUSPEND) is reseived
80 * 88 *
81 * A single USB function uses one or more interfaces, and should in most 89 * A single USB function uses one or more interfaces, and should in most
82 * cases support operation at both full and high speeds. Each function is 90 * cases support operation at both full and high speeds. Each function is
@@ -106,6 +114,7 @@ struct usb_function {
106 struct usb_gadget_strings **strings; 114 struct usb_gadget_strings **strings;
107 struct usb_descriptor_header **descriptors; 115 struct usb_descriptor_header **descriptors;
108 struct usb_descriptor_header **hs_descriptors; 116 struct usb_descriptor_header **hs_descriptors;
117 struct usb_descriptor_header **ss_descriptors;
109 118
110 struct usb_configuration *config; 119 struct usb_configuration *config;
111 120
@@ -132,6 +141,10 @@ struct usb_function {
132 void (*suspend)(struct usb_function *); 141 void (*suspend)(struct usb_function *);
133 void (*resume)(struct usb_function *); 142 void (*resume)(struct usb_function *);
134 143
144 /* USB 3.0 additions */
145 int (*get_status)(struct usb_function *);
146 int (*func_suspend)(struct usb_function *,
147 u8 suspend_opt);
135 /* private: */ 148 /* private: */
136 /* internals */ 149 /* internals */
137 struct list_head list; 150 struct list_head list;
@@ -145,20 +158,8 @@ int usb_function_activate(struct usb_function *);
145 158
146int usb_interface_id(struct usb_configuration *, struct usb_function *); 159int usb_interface_id(struct usb_configuration *, struct usb_function *);
147 160
148/** 161int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f,
149 * ep_choose - select descriptor endpoint at current device speed 162 struct usb_ep *_ep);
150 * @g: gadget, connected and running at some speed
151 * @hs: descriptor to use for high speed operation
152 * @fs: descriptor to use for full or low speed operation
153 */
154static inline struct usb_endpoint_descriptor *
155ep_choose(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
156 struct usb_endpoint_descriptor *fs)
157{
158 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
159 return hs;
160 return fs;
161}
162 163
163#define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */ 164#define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */
164 165
@@ -231,6 +232,7 @@ struct usb_configuration {
231 struct list_head list; 232 struct list_head list;
232 struct list_head functions; 233 struct list_head functions;
233 u8 next_interface_id; 234 u8 next_interface_id;
235 unsigned superspeed:1;
234 unsigned highspeed:1; 236 unsigned highspeed:1;
235 unsigned fullspeed:1; 237 unsigned fullspeed:1;
236 struct usb_function *interface[MAX_CONFIG_INTERFACES]; 238 struct usb_function *interface[MAX_CONFIG_INTERFACES];
@@ -252,6 +254,7 @@ int usb_add_config(struct usb_composite_dev *,
252 * identifiers. 254 * identifiers.
253 * @strings: tables of strings, keyed by identifiers assigned during bind() 255 * @strings: tables of strings, keyed by identifiers assigned during bind()
254 * and language IDs provided in control requests 256 * and language IDs provided in control requests
257 * @max_speed: Highest speed the driver supports.
255 * @needs_serial: set to 1 if the gadget needs userspace to provide 258 * @needs_serial: set to 1 if the gadget needs userspace to provide
256 * a serial number. If one is not provided, warning will be printed. 259 * a serial number. If one is not provided, warning will be printed.
257 * @unbind: Reverses bind; called as a side effect of unregistering 260 * @unbind: Reverses bind; called as a side effect of unregistering
@@ -279,6 +282,7 @@ struct usb_composite_driver {
279 const char *iManufacturer; 282 const char *iManufacturer;
280 const struct usb_device_descriptor *dev; 283 const struct usb_device_descriptor *dev;
281 struct usb_gadget_strings **strings; 284 struct usb_gadget_strings **strings;
285 enum usb_device_speed max_speed;
282 unsigned needs_serial:1; 286 unsigned needs_serial:1;
283 287
284 int (*unbind)(struct usb_composite_dev *); 288 int (*unbind)(struct usb_composite_dev *);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index dd1571db55e7..087f4b931833 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -15,7 +15,13 @@
15#ifndef __LINUX_USB_GADGET_H 15#ifndef __LINUX_USB_GADGET_H
16#define __LINUX_USB_GADGET_H 16#define __LINUX_USB_GADGET_H
17 17
18#include <linux/device.h>
19#include <linux/errno.h>
20#include <linux/init.h>
21#include <linux/list.h>
18#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/types.h>
24#include <linux/usb/ch9.h>
19 25
20struct usb_ep; 26struct usb_ep;
21 27
@@ -27,6 +33,7 @@ struct usb_ep;
27 * field, and the usb controller needs one, it is responsible 33 * field, and the usb controller needs one, it is responsible
28 * for mapping and unmapping the buffer. 34 * for mapping and unmapping the buffer.
29 * @length: Length of that data 35 * @length: Length of that data
36 * @stream_id: The stream id, when USB3.0 bulk streams are being used
30 * @no_interrupt: If true, hints that no completion irq is needed. 37 * @no_interrupt: If true, hints that no completion irq is needed.
31 * Helpful sometimes with deep request queues that are handled 38 * Helpful sometimes with deep request queues that are handled
32 * directly by DMA controllers. 39 * directly by DMA controllers.
@@ -81,6 +88,7 @@ struct usb_request {
81 unsigned length; 88 unsigned length;
82 dma_addr_t dma; 89 dma_addr_t dma;
83 90
91 unsigned stream_id:16;
84 unsigned no_interrupt:1; 92 unsigned no_interrupt:1;
85 unsigned zero:1; 93 unsigned zero:1;
86 unsigned short_not_ok:1; 94 unsigned short_not_ok:1;
@@ -131,8 +139,17 @@ struct usb_ep_ops {
131 * @maxpacket:The maximum packet size used on this endpoint. The initial 139 * @maxpacket:The maximum packet size used on this endpoint. The initial
132 * value can sometimes be reduced (hardware allowing), according to 140 * value can sometimes be reduced (hardware allowing), according to
133 * the endpoint descriptor used to configure the endpoint. 141 * the endpoint descriptor used to configure the endpoint.
134 * @driver_data:for use by the gadget driver. all other fields are 142 * @max_streams: The maximum number of streams supported
135 * read-only to gadget drivers. 143 * by this EP (0 - 16, actual number is 2^n)
144 * @mult: multiplier, 'mult' value for SS Isoc EPs
145 * @maxburst: the maximum number of bursts supported by this EP (for usb3)
146 * @driver_data:for use by the gadget driver.
147 * @address: used to identify the endpoint when finding descriptor that
148 * matches connection speed
149 * @desc: endpoint descriptor. This pointer is set before the endpoint is
150 * enabled and remains valid until the endpoint is disabled.
151 * @comp_desc: In case of SuperSpeed support, this is the endpoint companion
152 * descriptor that is used to configure the endpoint
136 * 153 *
137 * the bus controller driver lists all the general purpose endpoints in 154 * the bus controller driver lists all the general purpose endpoints in
138 * gadget->ep_list. the control endpoint (gadget->ep0) is not in that list, 155 * gadget->ep_list. the control endpoint (gadget->ep0) is not in that list,
@@ -145,6 +162,12 @@ struct usb_ep {
145 const struct usb_ep_ops *ops; 162 const struct usb_ep_ops *ops;
146 struct list_head ep_list; 163 struct list_head ep_list;
147 unsigned maxpacket:16; 164 unsigned maxpacket:16;
165 unsigned max_streams:16;
166 unsigned mult:2;
167 unsigned maxburst:4;
168 u8 address;
169 const struct usb_endpoint_descriptor *desc;
170 const struct usb_ss_ep_comp_descriptor *comp_desc;
148}; 171};
149 172
150/*-------------------------------------------------------------------------*/ 173/*-------------------------------------------------------------------------*/
@@ -153,11 +176,8 @@ struct usb_ep {
153 * usb_ep_enable - configure endpoint, making it usable 176 * usb_ep_enable - configure endpoint, making it usable
154 * @ep:the endpoint being configured. may not be the endpoint named "ep0". 177 * @ep:the endpoint being configured. may not be the endpoint named "ep0".
155 * drivers discover endpoints through the ep_list of a usb_gadget. 178 * drivers discover endpoints through the ep_list of a usb_gadget.
156 * @desc:descriptor for desired behavior. caller guarantees this pointer
157 * remains valid until the endpoint is disabled; the data byte order
158 * is little-endian (usb-standard).
159 * 179 *
160 * when configurations are set, or when interface settings change, the driver 180 * When configurations are set, or when interface settings change, the driver
161 * will enable or disable the relevant endpoints. while it is enabled, an 181 * will enable or disable the relevant endpoints. while it is enabled, an
162 * endpoint may be used for i/o until the driver receives a disconnect() from 182 * endpoint may be used for i/o until the driver receives a disconnect() from
163 * the host or until the endpoint is disabled. 183 * the host or until the endpoint is disabled.
@@ -172,10 +192,9 @@ struct usb_ep {
172 * 192 *
173 * returns zero, or a negative error code. 193 * returns zero, or a negative error code.
174 */ 194 */
175static inline int usb_ep_enable(struct usb_ep *ep, 195static inline int usb_ep_enable(struct usb_ep *ep)
176 const struct usb_endpoint_descriptor *desc)
177{ 196{
178 return ep->ops->enable(ep, desc); 197 return ep->ops->enable(ep, ep->desc);
179} 198}
180 199
181/** 200/**
@@ -416,7 +435,16 @@ static inline void usb_ep_fifo_flush(struct usb_ep *ep)
416 435
417/*-------------------------------------------------------------------------*/ 436/*-------------------------------------------------------------------------*/
418 437
438struct usb_dcd_config_params {
439 __u8 bU1devExitLat; /* U1 Device exit Latency */
440#define USB_DEFULT_U1_DEV_EXIT_LAT 0x01 /* Less then 1 microsec */
441 __le16 bU2DevExitLat; /* U2 Device exit Latency */
442#define USB_DEFULT_U2_DEV_EXIT_LAT 0x1F4 /* Less then 500 microsec */
443};
444
445
419struct usb_gadget; 446struct usb_gadget;
447struct usb_gadget_driver;
420 448
421/* the rest of the api to the controller hardware: device operations, 449/* the rest of the api to the controller hardware: device operations,
422 * which don't involve endpoints (or i/o). 450 * which don't involve endpoints (or i/o).
@@ -430,6 +458,16 @@ struct usb_gadget_ops {
430 int (*pullup) (struct usb_gadget *, int is_on); 458 int (*pullup) (struct usb_gadget *, int is_on);
431 int (*ioctl)(struct usb_gadget *, 459 int (*ioctl)(struct usb_gadget *,
432 unsigned code, unsigned long param); 460 unsigned code, unsigned long param);
461 void (*get_config_params)(struct usb_dcd_config_params *);
462 int (*udc_start)(struct usb_gadget *,
463 struct usb_gadget_driver *);
464 int (*udc_stop)(struct usb_gadget *,
465 struct usb_gadget_driver *);
466
467 /* Those two are deprecated */
468 int (*start)(struct usb_gadget_driver *,
469 int (*bind)(struct usb_gadget *));
470 int (*stop)(struct usb_gadget_driver *);
433}; 471};
434 472
435/** 473/**
@@ -521,6 +559,24 @@ static inline int gadget_is_dualspeed(struct usb_gadget *g)
521} 559}
522 560
523/** 561/**
562 * gadget_is_superspeed() - return true if the hardware handles
563 * supperspeed
564 * @g: controller that might support supper speed
565 */
566static inline int gadget_is_superspeed(struct usb_gadget *g)
567{
568#ifdef CONFIG_USB_GADGET_SUPERSPEED
569 /*
570 * runtime test would check "g->is_superspeed" ... that might be
571 * useful to work around hardware bugs, but is mostly pointless
572 */
573 return 1;
574#else
575 return 0;
576#endif
577}
578
579/**
524 * gadget_is_otg - return true iff the hardware is OTG-ready 580 * gadget_is_otg - return true iff the hardware is OTG-ready
525 * @g: controller that might have a Mini-AB connector 581 * @g: controller that might have a Mini-AB connector
526 * 582 *
@@ -821,6 +877,9 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
821 */ 877 */
822int usb_gadget_unregister_driver(struct usb_gadget_driver *driver); 878int usb_gadget_unregister_driver(struct usb_gadget_driver *driver);
823 879
880extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
881extern void usb_del_gadget_udc(struct usb_gadget *gadget);
882
824/*-------------------------------------------------------------------------*/ 883/*-------------------------------------------------------------------------*/
825 884
826/* utility to simplify dealing with string descriptors */ 885/* utility to simplify dealing with string descriptors */
@@ -870,12 +929,6 @@ int usb_gadget_config_buf(const struct usb_config_descriptor *config,
870struct usb_descriptor_header **usb_copy_descriptors( 929struct usb_descriptor_header **usb_copy_descriptors(
871 struct usb_descriptor_header **); 930 struct usb_descriptor_header **);
872 931
873/* return copy of endpoint descriptor given original descriptor set */
874struct usb_endpoint_descriptor *usb_find_endpoint(
875 struct usb_descriptor_header **src,
876 struct usb_descriptor_header **copy,
877 struct usb_endpoint_descriptor *match);
878
879/** 932/**
880 * usb_free_descriptors - free descriptors returned by usb_copy_descriptors() 933 * usb_free_descriptors - free descriptors returned by usb_copy_descriptors()
881 * @v: vector of descriptors 934 * @v: vector of descriptors
@@ -892,6 +945,11 @@ static inline void usb_free_descriptors(struct usb_descriptor_header **v)
892extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *, 945extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
893 struct usb_endpoint_descriptor *); 946 struct usb_endpoint_descriptor *);
894 947
948
949extern struct usb_ep *usb_ep_autoconfig_ss(struct usb_gadget *,
950 struct usb_endpoint_descriptor *,
951 struct usb_ss_ep_comp_descriptor *);
952
895extern void usb_ep_autoconfig_reset(struct usb_gadget *); 953extern void usb_ep_autoconfig_reset(struct usb_gadget *);
896 954
897#endif /* __LINUX_USB_GADGET_H */ 955#endif /* __LINUX_USB_GADGET_H */
diff --git a/include/linux/usb/m66592.h b/include/linux/usb/m66592.h
index cda9625e7df0..a4ba31ab2fed 100644
--- a/include/linux/usb/m66592.h
+++ b/include/linux/usb/m66592.h
@@ -38,6 +38,8 @@ struct m66592_platdata {
38 /* (external controller only) one = 3.3V, zero = 1.5V */ 38 /* (external controller only) one = 3.3V, zero = 1.5V */
39 unsigned vif:1; 39 unsigned vif:1;
40 40
41 /* (external controller only) set one = WR0_N shorted to WR1_N */
42 unsigned wr0_shorted_to_wr1:1;
41}; 43};
42 44
43#endif /* __LINUX_USB_M66592_H */ 45#endif /* __LINUX_USB_M66592_H */
diff --git a/include/linux/usb/r8a66597.h b/include/linux/usb/r8a66597.h
index 26d216734057..b6b8660d0c68 100644
--- a/include/linux/usb/r8a66597.h
+++ b/include/linux/usb/r8a66597.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2009 Renesas Solutions Corp. 4 * Copyright (C) 2009 Renesas Solutions Corp.
5 * 5 *
6 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> 6 * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.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
@@ -31,6 +31,9 @@ struct r8a66597_platdata {
31 /* This callback can control port power instead of DVSTCTR register. */ 31 /* This callback can control port power instead of DVSTCTR register. */
32 void (*port_power)(int port, int power); 32 void (*port_power)(int port, int power);
33 33
34 /* This parameter is for BUSWAIT */
35 u16 buswait;
36
34 /* set one = on chip controller, set zero = external controller */ 37 /* set one = on chip controller, set zero = external controller */
35 unsigned on_chip:1; 38 unsigned on_chip:1;
36 39
@@ -42,6 +45,9 @@ struct r8a66597_platdata {
42 45
43 /* set one = big endian, set zero = little endian */ 46 /* set one = big endian, set zero = little endian */
44 unsigned endian:1; 47 unsigned endian:1;
48
49 /* (external controller only) set one = WR0_N shorted to WR1_N */
50 unsigned wr0_shorted_to_wr1:1;
45}; 51};
46 52
47/* Register definitions */ 53/* Register definitions */
diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
index 3a7f1d982dd6..8977431259c6 100644
--- a/include/linux/usb/renesas_usbhs.h
+++ b/include/linux/usb/renesas_usbhs.h
@@ -110,6 +110,23 @@ struct renesas_usbhs_driver_param {
110 * delay time from notify_hotplug callback 110 * delay time from notify_hotplug callback
111 */ 111 */
112 int detection_delay; 112 int detection_delay;
113
114 /*
115 * option:
116 *
117 * dma id for dmaengine
118 */
119 int d0_tx_id;
120 int d0_rx_id;
121 int d1_tx_id;
122 int d1_rx_id;
123
124 /*
125 * option:
126 *
127 * pio <--> dma border.
128 */
129 int pio_dma_border; /* default is 64byte */
113}; 130};
114 131
115/* 132/*