aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-11 16:39:31 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-11 16:39:49 -0400
commit7135f08e47de094f8748507806efa8d7ba27a964 (patch)
tree4e0bd28908a35cb3ce3b44a87402641c959775c7 /drivers/usb
parent73d4066055e0e2830533041f4b91df8e6e5976ff (diff)
parent5c4d46eb89fe99011a02048533857345d9e8b506 (diff)
Merge tag 'gadget-for-v3.7' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
usb: gadget: patches for v3.7 merge window This pull request is large but the biggest part is the first part of the cleanup on the gadget framework so we have a saner setup to add configfs support for v3.8. We have also some more conversions to the new udc_start/udc_stop which makes us closer from dropping the old interfaces. USB_GADGET_DUALSPEED and USB_GADGET_SUPERSPEED are finally gone, thanks to Michal for his awesome work. Other than that, we have the usual set of miscellaneous changes and cleanups involving improvements to debug messages, removal of duplicated includes, moving dereference after NULL test, making renesas_hsbhs' irq handler Shared, unused code being dropped, prevention of sleep-inside-spinlock bugs and a race condition fix on udc-core.
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/chipidea/Kconfig1
-rw-r--r--drivers/usb/dwc3/Kconfig2
-rw-r--r--drivers/usb/gadget/Kconfig61
-rw-r--r--drivers/usb/gadget/Makefile4
-rw-r--r--drivers/usb/gadget/acm_ms.c55
-rw-r--r--drivers/usb/gadget/amd5536udc.c6
-rw-r--r--drivers/usb/gadget/at91_udc.c5
-rw-r--r--drivers/usb/gadget/audio.c62
-rw-r--r--drivers/usb/gadget/bcm63xx_udc.c2464
-rw-r--r--drivers/usb/gadget/cdc2.c56
-rw-r--r--drivers/usb/gadget/composite.c290
-rw-r--r--drivers/usb/gadget/config.c6
-rw-r--r--drivers/usb/gadget/dbgp.c11
-rw-r--r--drivers/usb/gadget/dummy_hcd.c2
-rw-r--r--drivers/usb/gadget/epautoconf.c33
-rw-r--r--drivers/usb/gadget/ether.c61
-rw-r--r--drivers/usb/gadget/f_ecm.c5
-rw-r--r--drivers/usb/gadget/f_hid.c2
-rw-r--r--drivers/usb/gadget/f_mass_storage.c16
-rw-r--r--drivers/usb/gadget/f_midi.c1
-rw-r--r--drivers/usb/gadget/f_ncm.c5
-rw-r--r--drivers/usb/gadget/f_sourcesink.c2
-rw-r--r--drivers/usb/gadget/f_subset.c5
-rw-r--r--drivers/usb/gadget/f_uac2.c2
-rw-r--r--drivers/usb/gadget/file_storage.c38
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c6
-rw-r--r--drivers/usb/gadget/fusb300_udc.c4
-rw-r--r--drivers/usb/gadget/g_ffs.c26
-rw-r--r--drivers/usb/gadget/gadget_chips.h96
-rw-r--r--drivers/usb/gadget/gmidi.c61
-rw-r--r--drivers/usb/gadget/goku_udc.c6
-rw-r--r--drivers/usb/gadget/hid.c52
-rw-r--r--drivers/usb/gadget/inode.c29
-rw-r--r--drivers/usb/gadget/lpc32xx_udc.c127
-rw-r--r--drivers/usb/gadget/m66592-udc.c4
-rw-r--r--drivers/usb/gadget/mass_storage.c39
-rw-r--r--drivers/usb/gadget/multi.c42
-rw-r--r--drivers/usb/gadget/mv_udc_core.c91
-rw-r--r--drivers/usb/gadget/ncm.c62
-rw-r--r--drivers/usb/gadget/nokia.c58
-rw-r--r--drivers/usb/gadget/omap_udc.c6
-rw-r--r--drivers/usb/gadget/pch_udc.c6
-rw-r--r--drivers/usb/gadget/printer.c173
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c7
-rw-r--r--drivers/usb/gadget/pxa25x_udc.h2
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c6
-rw-r--r--drivers/usb/gadget/rndis.c22
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c8
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c51
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c148
-rw-r--r--drivers/usb/gadget/serial.c72
-rw-r--r--drivers/usb/gadget/tcm_usb_gadget.c49
-rw-r--r--drivers/usb/gadget/tcm_usb_gadget.h11
-rw-r--r--drivers/usb/gadget/u_ether.c8
-rw-r--r--drivers/usb/gadget/udc-core.c13
-rw-r--r--drivers/usb/gadget/usbstring.c3
-rw-r--r--drivers/usb/gadget/webcam.c42
-rw-r--r--drivers/usb/gadget/zero.c73
-rw-r--r--drivers/usb/musb/Kconfig1
59 files changed, 3256 insertions, 1343 deletions
diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig
index 47e499c9c0b6..1ea932a13685 100644
--- a/drivers/usb/chipidea/Kconfig
+++ b/drivers/usb/chipidea/Kconfig
@@ -13,7 +13,6 @@ if USB_CHIPIDEA
13config USB_CHIPIDEA_UDC 13config USB_CHIPIDEA_UDC
14 bool "ChipIdea device controller" 14 bool "ChipIdea device controller"
15 depends on USB_GADGET=y || USB_GADGET=USB_CHIPIDEA 15 depends on USB_GADGET=y || USB_GADGET=USB_CHIPIDEA
16 select USB_GADGET_DUALSPEED
17 help 16 help
18 Say Y here to enable device controller functionality of the 17 Say Y here to enable device controller functionality of the
19 ChipIdea driver. 18 ChipIdea driver.
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index d13c60f42139..f6a6e070c2ac 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -2,8 +2,6 @@ config USB_DWC3
2 tristate "DesignWare USB3 DRD Core Support" 2 tristate "DesignWare USB3 DRD Core Support"
3 depends on (USB && USB_GADGET) 3 depends on (USB && USB_GADGET)
4 select USB_OTG_UTILS 4 select USB_OTG_UTILS
5 select USB_GADGET_DUALSPEED
6 select USB_GADGET_SUPERSPEED
7 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD 5 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD
8 help 6 help
9 Say Y or M here if your system has a Dual Role SuperSpeed 7 Say Y or M here if your system has a Dual Role SuperSpeed
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 51ab5fd5d468..a53be32c22cf 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -154,16 +154,25 @@ config USB_LPC32XX
154 154
155config USB_ATMEL_USBA 155config USB_ATMEL_USBA
156 tristate "Atmel USBA" 156 tristate "Atmel USBA"
157 select USB_GADGET_DUALSPEED
158 depends on AVR32 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 157 depends on AVR32 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45
159 help 158 help
160 USBA is the integrated high-speed USB Device controller on 159 USBA is the integrated high-speed USB Device controller on
161 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. 160 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
162 161
162config USB_BCM63XX_UDC
163 tristate "Broadcom BCM63xx Peripheral Controller"
164 depends on BCM63XX
165 help
166 Many Broadcom BCM63xx chipsets (such as the BCM6328) have a
167 high speed USB Device Port with support for four fixed endpoints
168 (plus endpoint zero).
169
170 Say "y" to link the driver statically, or "m" to build a
171 dynamically linked module called "bcm63xx_udc".
172
163config USB_FSL_USB2 173config USB_FSL_USB2
164 tristate "Freescale Highspeed USB DR Peripheral Controller" 174 tristate "Freescale Highspeed USB DR Peripheral Controller"
165 depends on FSL_SOC || ARCH_MXC 175 depends on FSL_SOC || ARCH_MXC
166 select USB_GADGET_DUALSPEED
167 select USB_FSL_MPH_DR_OF if OF 176 select USB_FSL_MPH_DR_OF if OF
168 help 177 help
169 Some of Freescale PowerPC and i.MX processors have a High Speed 178 Some of Freescale PowerPC and i.MX processors have a High Speed
@@ -179,7 +188,6 @@ config USB_FSL_USB2
179config USB_FUSB300 188config USB_FUSB300
180 tristate "Faraday FUSB300 USB Peripheral Controller" 189 tristate "Faraday FUSB300 USB Peripheral Controller"
181 depends on !PHYS_ADDR_T_64BIT 190 depends on !PHYS_ADDR_T_64BIT
182 select USB_GADGET_DUALSPEED
183 help 191 help
184 Faraday usb device controller FUSB300 driver 192 Faraday usb device controller FUSB300 driver
185 193
@@ -227,7 +235,6 @@ config USB_PXA25X_SMALL
227 235
228config USB_R8A66597 236config USB_R8A66597
229 tristate "Renesas R8A66597 USB Peripheral Controller" 237 tristate "Renesas R8A66597 USB Peripheral Controller"
230 select USB_GADGET_DUALSPEED
231 help 238 help
232 R8A66597 is a discrete USB host and peripheral controller chip that 239 R8A66597 is a discrete USB host and peripheral controller chip that
233 supports both full and high speed USB 2.0 data transfers. 240 supports both full and high speed USB 2.0 data transfers.
@@ -240,7 +247,6 @@ config USB_R8A66597
240config USB_RENESAS_USBHS_UDC 247config USB_RENESAS_USBHS_UDC
241 tristate 'Renesas USBHS controller' 248 tristate 'Renesas USBHS controller'
242 depends on USB_RENESAS_USBHS 249 depends on USB_RENESAS_USBHS
243 select USB_GADGET_DUALSPEED
244 help 250 help
245 Renesas USBHS is a discrete USB host and peripheral controller chip 251 Renesas USBHS is a discrete USB host and peripheral controller chip
246 that supports both full and high speed USB 2.0 data transfers. 252 that supports both full and high speed USB 2.0 data transfers.
@@ -268,7 +274,6 @@ config USB_PXA27X
268config USB_S3C_HSOTG 274config USB_S3C_HSOTG
269 tristate "S3C HS/OtG USB Device controller" 275 tristate "S3C HS/OtG USB Device controller"
270 depends on S3C_DEV_USB_HSOTG 276 depends on S3C_DEV_USB_HSOTG
271 select USB_GADGET_DUALSPEED
272 help 277 help
273 The Samsung S3C64XX USB2.0 high-speed gadget controller 278 The Samsung S3C64XX USB2.0 high-speed gadget controller
274 integrated into the S3C64XX series SoC. 279 integrated into the S3C64XX series SoC.
@@ -305,7 +310,6 @@ config USB_S3C2410_DEBUG
305config USB_S3C_HSUDC 310config USB_S3C_HSUDC
306 tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller" 311 tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller"
307 depends on ARCH_S3C24XX 312 depends on ARCH_S3C24XX
308 select USB_GADGET_DUALSPEED
309 help 313 help
310 Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC 314 Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC
311 integrated with dual speed USB 2.0 device controller. It has 315 integrated with dual speed USB 2.0 device controller. It has
@@ -315,7 +319,6 @@ config USB_S3C_HSUDC
315 319
316config USB_MV_UDC 320config USB_MV_UDC
317 tristate "Marvell USB2.0 Device Controller" 321 tristate "Marvell USB2.0 Device Controller"
318 select USB_GADGET_DUALSPEED
319 help 322 help
320 Marvell Socs (including PXA and MMP series) include a high speed 323 Marvell Socs (including PXA and MMP series) include a high speed
321 USB2.0 OTG controller, which can be configured as high speed or 324 USB2.0 OTG controller, which can be configured as high speed or
@@ -338,14 +341,12 @@ config USB_MV_U3D
338config USB_GADGET_MUSB_HDRC 341config USB_GADGET_MUSB_HDRC
339 tristate "Inventra HDRC USB Peripheral (TI, ADI, ...)" 342 tristate "Inventra HDRC USB Peripheral (TI, ADI, ...)"
340 depends on USB_MUSB_HDRC 343 depends on USB_MUSB_HDRC
341 select USB_GADGET_DUALSPEED
342 help 344 help
343 This OTG-capable silicon IP is used in dual designs including 345 This OTG-capable silicon IP is used in dual designs including
344 the TI DaVinci, OMAP 243x, OMAP 343x, TUSB 6010, and ADI Blackfin 346 the TI DaVinci, OMAP 243x, OMAP 343x, TUSB 6010, and ADI Blackfin
345 347
346config USB_M66592 348config USB_M66592
347 tristate "Renesas M66592 USB Peripheral Controller" 349 tristate "Renesas M66592 USB Peripheral Controller"
348 select USB_GADGET_DUALSPEED
349 help 350 help
350 M66592 is a discrete USB peripheral controller chip that 351 M66592 is a discrete USB peripheral controller chip that
351 supports both full and high speed USB 2.0 data transfers. 352 supports both full and high speed USB 2.0 data transfers.
@@ -362,7 +363,6 @@ config USB_M66592
362config USB_AMD5536UDC 363config USB_AMD5536UDC
363 tristate "AMD5536 UDC" 364 tristate "AMD5536 UDC"
364 depends on PCI 365 depends on PCI
365 select USB_GADGET_DUALSPEED
366 help 366 help
367 The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge. 367 The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
368 It is a USB Highspeed DMA capable USB device controller. Beside ep0 368 It is a USB Highspeed DMA capable USB device controller. Beside ep0
@@ -389,7 +389,6 @@ config USB_FSL_QE
389 389
390config USB_NET2272 390config USB_NET2272
391 tristate "PLX NET2272" 391 tristate "PLX NET2272"
392 select USB_GADGET_DUALSPEED
393 help 392 help
394 PLX NET2272 is a USB peripheral controller which supports 393 PLX NET2272 is a USB peripheral controller which supports
395 both full and high speed USB 2.0 data transfers. 394 both full and high speed USB 2.0 data transfers.
@@ -413,7 +412,6 @@ config USB_NET2272_DMA
413config USB_NET2280 412config USB_NET2280
414 tristate "NetChip 228x" 413 tristate "NetChip 228x"
415 depends on PCI 414 depends on PCI
416 select USB_GADGET_DUALSPEED
417 help 415 help
418 NetChip 2280 / 2282 is a PCI based USB peripheral controller which 416 NetChip 2280 / 2282 is a PCI based USB peripheral controller which
419 supports both full and high speed USB 2.0 data transfers. 417 supports both full and high speed USB 2.0 data transfers.
@@ -443,7 +441,6 @@ config USB_GOKU
443config USB_EG20T 441config USB_EG20T
444 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC" 442 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC"
445 depends on PCI 443 depends on PCI
446 select USB_GADGET_DUALSPEED
447 help 444 help
448 This is a USB device driver for EG20T PCH. 445 This is a USB device driver for EG20T PCH.
449 EG20T PCH is the platform controller hub that is used in Intel's 446 EG20T PCH is the platform controller hub that is used in Intel's
@@ -470,8 +467,6 @@ config USB_EG20T
470config USB_DUMMY_HCD 467config USB_DUMMY_HCD
471 tristate "Dummy HCD (DEVELOPMENT)" 468 tristate "Dummy HCD (DEVELOPMENT)"
472 depends on USB=y || (USB=m && USB_GADGET=m) 469 depends on USB=y || (USB=m && USB_GADGET=m)
473 select USB_GADGET_DUALSPEED
474 select USB_GADGET_SUPERSPEED
475 help 470 help
476 This host controller driver emulates USB, looping all data transfer 471 This host controller driver emulates USB, looping all data transfer
477 requests back to a USB "gadget driver" in the same host. The host 472 requests back to a USB "gadget driver" in the same host. The host
@@ -496,18 +491,15 @@ config USB_DUMMY_HCD
496 491
497endmenu 492endmenu
498 493
499# Selected by UDC drivers that support high-speed operation.
500config USB_GADGET_DUALSPEED
501 bool
502
503# Selected by UDC drivers that support super-speed opperation
504config USB_GADGET_SUPERSPEED
505 bool
506 depends on USB_GADGET_DUALSPEED
507
508# 494#
509# USB Gadget Drivers 495# USB Gadget Drivers
510# 496#
497
498# composite based drivers
499config USB_LIBCOMPOSITE
500 tristate
501 depends on USB_GADGET
502
511choice 503choice
512 tristate "USB Gadget Drivers" 504 tristate "USB Gadget Drivers"
513 default USB_ETH 505 default USB_ETH
@@ -531,6 +523,7 @@ choice
531 523
532config USB_ZERO 524config USB_ZERO
533 tristate "Gadget Zero (DEVELOPMENT)" 525 tristate "Gadget Zero (DEVELOPMENT)"
526 select USB_LIBCOMPOSITE
534 help 527 help
535 Gadget Zero is a two-configuration device. It either sinks and 528 Gadget Zero is a two-configuration device. It either sinks and
536 sources bulk data; or it loops back a configurable number of 529 sources bulk data; or it loops back a configurable number of
@@ -566,6 +559,7 @@ config USB_ZERO_HNPTEST
566config USB_AUDIO 559config USB_AUDIO
567 tristate "Audio Gadget (EXPERIMENTAL)" 560 tristate "Audio Gadget (EXPERIMENTAL)"
568 depends on SND 561 depends on SND
562 select USB_LIBCOMPOSITE
569 select SND_PCM 563 select SND_PCM
570 help 564 help
571 This Gadget Audio driver is compatible with USB Audio Class 565 This Gadget Audio driver is compatible with USB Audio Class
@@ -594,6 +588,7 @@ config GADGET_UAC1
594config USB_ETH 588config USB_ETH
595 tristate "Ethernet Gadget (with CDC Ethernet support)" 589 tristate "Ethernet Gadget (with CDC Ethernet support)"
596 depends on NET 590 depends on NET
591 select USB_LIBCOMPOSITE
597 select CRC32 592 select CRC32
598 help 593 help
599 This driver implements Ethernet style communication, in one of 594 This driver implements Ethernet style communication, in one of
@@ -629,6 +624,7 @@ config USB_ETH
629config USB_ETH_RNDIS 624config USB_ETH_RNDIS
630 bool "RNDIS support" 625 bool "RNDIS support"
631 depends on USB_ETH 626 depends on USB_ETH
627 select USB_LIBCOMPOSITE
632 default y 628 default y
633 help 629 help
634 Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, 630 Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
@@ -647,6 +643,7 @@ config USB_ETH_RNDIS
647config USB_ETH_EEM 643config USB_ETH_EEM
648 bool "Ethernet Emulation Model (EEM) support" 644 bool "Ethernet Emulation Model (EEM) support"
649 depends on USB_ETH 645 depends on USB_ETH
646 select USB_LIBCOMPOSITE
650 default n 647 default n
651 help 648 help
652 CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM 649 CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM
@@ -663,6 +660,7 @@ config USB_ETH_EEM
663config USB_G_NCM 660config USB_G_NCM
664 tristate "Network Control Model (NCM) support" 661 tristate "Network Control Model (NCM) support"
665 depends on NET 662 depends on NET
663 select USB_LIBCOMPOSITE
666 select CRC32 664 select CRC32
667 help 665 help
668 This driver implements USB CDC NCM subclass standard. NCM is 666 This driver implements USB CDC NCM subclass standard. NCM is
@@ -692,6 +690,7 @@ config USB_GADGETFS
692config USB_FUNCTIONFS 690config USB_FUNCTIONFS
693 tristate "Function Filesystem (EXPERIMENTAL)" 691 tristate "Function Filesystem (EXPERIMENTAL)"
694 depends on EXPERIMENTAL 692 depends on EXPERIMENTAL
693 select USB_LIBCOMPOSITE
695 select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) 694 select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS)
696 help 695 help
697 The Function Filesystem (FunctionFS) lets one create USB 696 The Function Filesystem (FunctionFS) lets one create USB
@@ -755,6 +754,7 @@ config USB_FILE_STORAGE_TEST
755config USB_MASS_STORAGE 754config USB_MASS_STORAGE
756 tristate "Mass Storage Gadget" 755 tristate "Mass Storage Gadget"
757 depends on BLOCK 756 depends on BLOCK
757 select USB_LIBCOMPOSITE
758 help 758 help
759 The Mass Storage Gadget acts as a USB Mass Storage disk drive. 759 The Mass Storage Gadget acts as a USB Mass Storage disk drive.
760 As its storage repository it can use a regular file or a block 760 As its storage repository it can use a regular file or a block
@@ -770,6 +770,7 @@ config USB_MASS_STORAGE
770config USB_GADGET_TARGET 770config USB_GADGET_TARGET
771 tristate "USB Gadget Target Fabric Module" 771 tristate "USB Gadget Target Fabric Module"
772 depends on TARGET_CORE 772 depends on TARGET_CORE
773 select USB_LIBCOMPOSITE
773 help 774 help
774 This fabric is an USB gadget. Two USB protocols are supported that is 775 This fabric is an USB gadget. Two USB protocols are supported that is
775 BBB or BOT (Bulk Only Transport) and UAS (USB Attached SCSI). BOT is 776 BBB or BOT (Bulk Only Transport) and UAS (USB Attached SCSI). BOT is
@@ -779,6 +780,7 @@ config USB_GADGET_TARGET
779 780
780config USB_G_SERIAL 781config USB_G_SERIAL
781 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" 782 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)"
783 select USB_LIBCOMPOSITE
782 help 784 help
783 The Serial Gadget talks to the Linux-USB generic serial driver. 785 The Serial Gadget talks to the Linux-USB generic serial driver.
784 This driver supports a CDC-ACM module option, which can be used 786 This driver supports a CDC-ACM module option, which can be used
@@ -799,6 +801,7 @@ config USB_G_SERIAL
799config USB_MIDI_GADGET 801config USB_MIDI_GADGET
800 tristate "MIDI Gadget (EXPERIMENTAL)" 802 tristate "MIDI Gadget (EXPERIMENTAL)"
801 depends on SND && EXPERIMENTAL 803 depends on SND && EXPERIMENTAL
804 select USB_LIBCOMPOSITE
802 select SND_RAWMIDI 805 select SND_RAWMIDI
803 help 806 help
804 The MIDI Gadget acts as a USB Audio device, with one MIDI 807 The MIDI Gadget acts as a USB Audio device, with one MIDI
@@ -812,6 +815,7 @@ config USB_MIDI_GADGET
812 815
813config USB_G_PRINTER 816config USB_G_PRINTER
814 tristate "Printer Gadget" 817 tristate "Printer Gadget"
818 select USB_LIBCOMPOSITE
815 help 819 help
816 The Printer Gadget channels data between the USB host and a 820 The Printer Gadget channels data between the USB host and a
817 userspace program driving the print engine. The user space 821 userspace program driving the print engine. The user space
@@ -828,6 +832,7 @@ config USB_G_PRINTER
828config USB_CDC_COMPOSITE 832config USB_CDC_COMPOSITE
829 tristate "CDC Composite Device (Ethernet and ACM)" 833 tristate "CDC Composite Device (Ethernet and ACM)"
830 depends on NET 834 depends on NET
835 select USB_LIBCOMPOSITE
831 help 836 help
832 This driver provides two functions in one configuration: 837 This driver provides two functions in one configuration:
833 a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link. 838 a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link.
@@ -842,6 +847,7 @@ config USB_CDC_COMPOSITE
842config USB_G_NOKIA 847config USB_G_NOKIA
843 tristate "Nokia composite gadget" 848 tristate "Nokia composite gadget"
844 depends on PHONET 849 depends on PHONET
850 select USB_LIBCOMPOSITE
845 help 851 help
846 The Nokia composite gadget provides support for acm, obex 852 The Nokia composite gadget provides support for acm, obex
847 and phonet in only one composite gadget driver. 853 and phonet in only one composite gadget driver.
@@ -852,6 +858,7 @@ config USB_G_NOKIA
852config USB_G_ACM_MS 858config USB_G_ACM_MS
853 tristate "CDC Composite Device (ACM and mass storage)" 859 tristate "CDC Composite Device (ACM and mass storage)"
854 depends on BLOCK 860 depends on BLOCK
861 select USB_LIBCOMPOSITE
855 help 862 help
856 This driver provides two functions in one configuration: 863 This driver provides two functions in one configuration:
857 a mass storage, and a CDC ACM (serial port) link. 864 a mass storage, and a CDC ACM (serial port) link.
@@ -863,6 +870,7 @@ config USB_G_MULTI
863 tristate "Multifunction Composite Gadget (EXPERIMENTAL)" 870 tristate "Multifunction Composite Gadget (EXPERIMENTAL)"
864 depends on BLOCK && NET 871 depends on BLOCK && NET
865 select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS 872 select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS
873 select USB_LIBCOMPOSITE
866 help 874 help
867 The Multifunction Composite Gadget provides Ethernet (RNDIS 875 The Multifunction Composite Gadget provides Ethernet (RNDIS
868 and/or CDC Ethernet), mass storage and ACM serial link 876 and/or CDC Ethernet), mass storage and ACM serial link
@@ -903,6 +911,7 @@ config USB_G_MULTI_CDC
903 911
904config USB_G_HID 912config USB_G_HID
905 tristate "HID Gadget" 913 tristate "HID Gadget"
914 select USB_LIBCOMPOSITE
906 help 915 help
907 The HID gadget driver provides generic emulation of USB 916 The HID gadget driver provides generic emulation of USB
908 Human Interface Devices (HID). 917 Human Interface Devices (HID).
@@ -913,8 +922,10 @@ config USB_G_HID
913 Say "y" to link the driver statically, or "m" to build a 922 Say "y" to link the driver statically, or "m" to build a
914 dynamically linked module called "g_hid". 923 dynamically linked module called "g_hid".
915 924
925# Standalone / single function gadgets
916config USB_G_DBGP 926config USB_G_DBGP
917 tristate "EHCI Debug Device Gadget" 927 tristate "EHCI Debug Device Gadget"
928 select USB_LIBCOMPOSITE
918 help 929 help
919 This gadget emulates an EHCI Debug device. This is useful when you want 930 This gadget emulates an EHCI Debug device. This is useful when you want
920 to interact with an EHCI Debug Port. 931 to interact with an EHCI Debug Port.
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 3fd8cd09d2c1..307be5fa824c 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -4,6 +4,9 @@
4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5 5
6obj-$(CONFIG_USB_GADGET) += udc-core.o 6obj-$(CONFIG_USB_GADGET) += udc-core.o
7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
8libcomposite-y := usbstring.o config.o epautoconf.o
9libcomposite-y += composite.o
7obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
8obj-$(CONFIG_USB_NET2272) += net2272.o 11obj-$(CONFIG_USB_NET2272) += net2272.o
9obj-$(CONFIG_USB_NET2280) += net2280.o 12obj-$(CONFIG_USB_NET2280) += net2280.o
@@ -16,6 +19,7 @@ obj-$(CONFIG_USB_OMAP) += omap_udc.o
16obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o 19obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o
17obj-$(CONFIG_USB_AT91) += at91_udc.o 20obj-$(CONFIG_USB_AT91) += at91_udc.o
18obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o 21obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
22obj-$(CONFIG_USB_BCM63XX_UDC) += bcm63xx_udc.o
19obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o 23obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
20fsl_usb2_udc-y := fsl_udc_core.o 24fsl_usb2_udc-y := fsl_udc_core.o
21fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o 25fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 75b8a691fd00..5a7f289805ff 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -15,7 +15,7 @@
15 */ 15 */
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/utsname.h> 18#include <linux/module.h>
19 19
20#include "u_serial.h" 20#include "u_serial.h"
21 21
@@ -41,15 +41,12 @@
41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
42 */ 42 */
43 43
44#include "composite.c"
45#include "usbstring.c"
46#include "config.c"
47#include "epautoconf.c"
48#include "u_serial.c" 44#include "u_serial.c"
49#include "f_acm.c" 45#include "f_acm.c"
50#include "f_mass_storage.c" 46#include "f_mass_storage.c"
51 47
52/*-------------------------------------------------------------------------*/ 48/*-------------------------------------------------------------------------*/
49USB_GADGET_COMPOSITE_OPTIONS();
53 50
54static struct usb_device_descriptor device_desc = { 51static struct usb_device_descriptor device_desc = {
55 .bLength = sizeof device_desc, 52 .bLength = sizeof device_desc,
@@ -89,17 +86,11 @@ static const struct usb_descriptor_header *otg_desc[] = {
89 NULL, 86 NULL,
90}; 87};
91 88
92
93/* string IDs are assigned dynamically */ 89/* string IDs are assigned dynamically */
94
95#define STRING_MANUFACTURER_IDX 0
96#define STRING_PRODUCT_IDX 1
97
98static char manufacturer[50];
99
100static struct usb_string strings_dev[] = { 90static struct usb_string strings_dev[] = {
101 [STRING_MANUFACTURER_IDX].s = manufacturer, 91 [USB_GADGET_MANUFACTURER_IDX].s = "",
102 [STRING_PRODUCT_IDX].s = DRIVER_DESC, 92 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
93 [USB_GADGET_SERIAL_IDX].s = "",
103 { } /* end of list */ 94 { } /* end of list */
104}; 95};
105 96
@@ -157,7 +148,6 @@ static struct usb_configuration acm_ms_config_driver = {
157 148
158static int __init acm_ms_bind(struct usb_composite_dev *cdev) 149static int __init acm_ms_bind(struct usb_composite_dev *cdev)
159{ 150{
160 int gcnum;
161 struct usb_gadget *gadget = cdev->gadget; 151 struct usb_gadget *gadget = cdev->gadget;
162 int status; 152 int status;
163 void *retp; 153 void *retp;
@@ -174,44 +164,22 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
174 goto fail0; 164 goto fail0;
175 } 165 }
176 166
177 /* set bcdDevice */
178 gcnum = usb_gadget_controller_number(gadget);
179 if (gcnum >= 0) {
180 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
181 } else {
182 WARNING(cdev, "controller '%s' not recognized; trying %s\n",
183 gadget->name,
184 acm_ms_config_driver.label);
185 device_desc.bcdDevice =
186 cpu_to_le16(0x0300 | 0x0099);
187 }
188
189 /* 167 /*
190 * Allocate string descriptor numbers ... note that string 168 * Allocate string descriptor numbers ... note that string
191 * contents can be overridden by the composite_dev glue. 169 * contents can be overridden by the composite_dev glue.
192 */ 170 */
193 171 status = usb_string_ids_tab(cdev, strings_dev);
194 /* device descriptor strings: manufacturer, product */
195 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
196 init_utsname()->sysname, init_utsname()->release,
197 gadget->name);
198 status = usb_string_id(cdev);
199 if (status < 0)
200 goto fail1;
201 strings_dev[STRING_MANUFACTURER_IDX].id = status;
202 device_desc.iManufacturer = status;
203
204 status = usb_string_id(cdev);
205 if (status < 0) 172 if (status < 0)
206 goto fail1; 173 goto fail1;
207 strings_dev[STRING_PRODUCT_IDX].id = status; 174 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
208 device_desc.iProduct = status; 175 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
209 176
210 /* register our configuration */ 177 /* register our configuration */
211 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); 178 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
212 if (status < 0) 179 if (status < 0)
213 goto fail1; 180 goto fail1;
214 181
182 usb_composite_overwrite_options(cdev, &coverwrite);
215 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 183 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
216 DRIVER_DESC); 184 DRIVER_DESC);
217 fsg_common_put(&fsg_common); 185 fsg_common_put(&fsg_common);
@@ -232,11 +200,12 @@ static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
232 return 0; 200 return 0;
233} 201}
234 202
235static struct usb_composite_driver acm_ms_driver = { 203static __refdata struct usb_composite_driver acm_ms_driver = {
236 .name = "g_acm_ms", 204 .name = "g_acm_ms",
237 .dev = &device_desc, 205 .dev = &device_desc,
238 .max_speed = USB_SPEED_SUPER, 206 .max_speed = USB_SPEED_SUPER,
239 .strings = dev_strings, 207 .strings = dev_strings,
208 .bind = acm_ms_bind,
240 .unbind = __exit_p(acm_ms_unbind), 209 .unbind = __exit_p(acm_ms_unbind),
241}; 210};
242 211
@@ -246,7 +215,7 @@ MODULE_LICENSE("GPL v2");
246 215
247static int __init init(void) 216static int __init init(void)
248{ 217{
249 return usb_composite_probe(&acm_ms_driver, acm_ms_bind); 218 return usb_composite_probe(&acm_ms_driver);
250} 219}
251module_init(init); 220module_init(init);
252 221
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 187d21181cd5..fc0ec5e0d58e 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1401,7 +1401,7 @@ static int udc_wakeup(struct usb_gadget *gadget)
1401} 1401}
1402 1402
1403static int amd5536_start(struct usb_gadget_driver *driver, 1403static int amd5536_start(struct usb_gadget_driver *driver,
1404 int (*bind)(struct usb_gadget *)); 1404 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
1405static int amd5536_stop(struct usb_gadget_driver *driver); 1405static int amd5536_stop(struct usb_gadget_driver *driver);
1406/* gadget operations */ 1406/* gadget operations */
1407static const struct usb_gadget_ops udc_ops = { 1407static const struct usb_gadget_ops udc_ops = {
@@ -1914,7 +1914,7 @@ static int setup_ep0(struct udc *dev)
1914 1914
1915/* Called by gadget driver to register itself */ 1915/* Called by gadget driver to register itself */
1916static int amd5536_start(struct usb_gadget_driver *driver, 1916static int amd5536_start(struct usb_gadget_driver *driver,
1917 int (*bind)(struct usb_gadget *)) 1917 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1918{ 1918{
1919 struct udc *dev = udc; 1919 struct udc *dev = udc;
1920 int retval; 1920 int retval;
@@ -1932,7 +1932,7 @@ static int amd5536_start(struct usb_gadget_driver *driver,
1932 dev->driver = driver; 1932 dev->driver = driver;
1933 dev->gadget.dev.driver = &driver->driver; 1933 dev->gadget.dev.driver = &driver->driver;
1934 1934
1935 retval = bind(&dev->gadget); 1935 retval = bind(&dev->gadget, driver);
1936 1936
1937 /* Some gadget drivers use both ep0 directions. 1937 /* Some gadget drivers use both ep0 directions.
1938 * NOTE: to gadget driver, ep0 is just one endpoint... 1938 * NOTE: to gadget driver, ep0 is just one endpoint...
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index c9e66dfb02e6..af931282843d 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -469,7 +469,7 @@ static int at91_ep_enable(struct usb_ep *_ep,
469 const struct usb_endpoint_descriptor *desc) 469 const struct usb_endpoint_descriptor *desc)
470{ 470{
471 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); 471 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
472 struct at91_udc *udc = ep->udc; 472 struct at91_udc *udc;
473 u16 maxpacket; 473 u16 maxpacket;
474 u32 tmp; 474 u32 tmp;
475 unsigned long flags; 475 unsigned long flags;
@@ -484,6 +484,7 @@ static int at91_ep_enable(struct usb_ep *_ep,
484 return -EINVAL; 484 return -EINVAL;
485 } 485 }
486 486
487 udc = ep->udc;
487 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { 488 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
488 DBG("bogus device state\n"); 489 DBG("bogus device state\n");
489 return -ESHUTDOWN; 490 return -ESHUTDOWN;
@@ -1703,7 +1704,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1703 int retval; 1704 int retval;
1704 struct resource *res; 1705 struct resource *res;
1705 1706
1706 if (!dev->platform_data) { 1707 if (!dev->platform_data && !pdev->dev.of_node) {
1707 /* small (so we copy it) but critical! */ 1708 /* small (so we copy it) but critical! */
1708 DBG("missing platform_data\n"); 1709 DBG("missing platform_data\n");
1709 return -ENODEV; 1710 return -ENODEV;
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index 98899244860e..231b0efe8fdc 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -12,35 +12,21 @@
12/* #define VERBOSE_DEBUG */ 12/* #define VERBOSE_DEBUG */
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/utsname.h> 15#include <linux/module.h>
16#include <linux/usb/composite.h>
16 17
18#include "gadget_chips.h"
17#define DRIVER_DESC "Linux USB Audio Gadget" 19#define DRIVER_DESC "Linux USB Audio Gadget"
18#define DRIVER_VERSION "Feb 2, 2012" 20#define DRIVER_VERSION "Feb 2, 2012"
19 21
20/*-------------------------------------------------------------------------*/ 22USB_GADGET_COMPOSITE_OPTIONS();
21
22/*
23 * Kbuild is not very cooperative with respect to linking separately
24 * compiled library objects into one module. So for now we won't use
25 * separate compilation ... ensuring init/exit sections work to shrink
26 * the runtime footprint, and giving us at least some parts of what
27 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
28 */
29#include "composite.c"
30#include "usbstring.c"
31#include "config.c"
32#include "epautoconf.c"
33 23
34/* string IDs are assigned dynamically */ 24/* string IDs are assigned dynamically */
35 25
36#define STRING_MANUFACTURER_IDX 0
37#define STRING_PRODUCT_IDX 1
38
39static char manufacturer[50];
40
41static struct usb_string strings_dev[] = { 26static struct usb_string strings_dev[] = {
42 [STRING_MANUFACTURER_IDX].s = manufacturer, 27 [USB_GADGET_MANUFACTURER_IDX].s = "",
43 [STRING_PRODUCT_IDX].s = DRIVER_DESC, 28 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
29 [USB_GADGET_SERIAL_IDX].s = "",
44 { } /* end of list */ 30 { } /* end of list */
45}; 31};
46 32
@@ -149,39 +135,18 @@ static struct usb_configuration audio_config_driver = {
149 135
150static int __init audio_bind(struct usb_composite_dev *cdev) 136static int __init audio_bind(struct usb_composite_dev *cdev)
151{ 137{
152 int gcnum;
153 int status; 138 int status;
154 139
155 gcnum = usb_gadget_controller_number(cdev->gadget); 140 status = usb_string_ids_tab(cdev, strings_dev);
156 if (gcnum >= 0)
157 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
158 else {
159 ERROR(cdev, "controller '%s' not recognized; trying %s\n",
160 cdev->gadget->name,
161 audio_config_driver.label);
162 device_desc.bcdDevice =
163 __constant_cpu_to_le16(0x0300 | 0x0099);
164 }
165
166 /* device descriptor strings: manufacturer, product */
167 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
168 init_utsname()->sysname, init_utsname()->release,
169 cdev->gadget->name);
170 status = usb_string_id(cdev);
171 if (status < 0)
172 goto fail;
173 strings_dev[STRING_MANUFACTURER_IDX].id = status;
174 device_desc.iManufacturer = status;
175
176 status = usb_string_id(cdev);
177 if (status < 0) 141 if (status < 0)
178 goto fail; 142 goto fail;
179 strings_dev[STRING_PRODUCT_IDX].id = status; 143 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
180 device_desc.iProduct = status; 144 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
181 145
182 status = usb_add_config(cdev, &audio_config_driver, audio_do_config); 146 status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
183 if (status < 0) 147 if (status < 0)
184 goto fail; 148 goto fail;
149 usb_composite_overwrite_options(cdev, &coverwrite);
185 150
186 INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION); 151 INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION);
187 return 0; 152 return 0;
@@ -198,17 +163,18 @@ static int __exit audio_unbind(struct usb_composite_dev *cdev)
198 return 0; 163 return 0;
199} 164}
200 165
201static struct usb_composite_driver audio_driver = { 166static __refdata struct usb_composite_driver audio_driver = {
202 .name = "g_audio", 167 .name = "g_audio",
203 .dev = &device_desc, 168 .dev = &device_desc,
204 .strings = audio_strings, 169 .strings = audio_strings,
205 .max_speed = USB_SPEED_HIGH, 170 .max_speed = USB_SPEED_HIGH,
171 .bind = audio_bind,
206 .unbind = __exit_p(audio_unbind), 172 .unbind = __exit_p(audio_unbind),
207}; 173};
208 174
209static int __init init(void) 175static int __init init(void)
210{ 176{
211 return usb_composite_probe(&audio_driver, audio_bind); 177 return usb_composite_probe(&audio_driver);
212} 178}
213module_init(init); 179module_init(init);
214 180
diff --git a/drivers/usb/gadget/bcm63xx_udc.c b/drivers/usb/gadget/bcm63xx_udc.c
new file mode 100644
index 000000000000..9ca792224cd4
--- /dev/null
+++ b/drivers/usb/gadget/bcm63xx_udc.c
@@ -0,0 +1,2464 @@
1/*
2 * bcm63xx_udc.c -- BCM63xx UDC high/full speed USB device controller
3 *
4 * Copyright (C) 2012 Kevin Cernekee <cernekee@gmail.com>
5 * Copyright (C) 2012 Broadcom Corporation
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
13#include <linux/bitops.h>
14#include <linux/bug.h>
15#include <linux/clk.h>
16#include <linux/compiler.h>
17#include <linux/debugfs.h>
18#include <linux/delay.h>
19#include <linux/device.h>
20#include <linux/dma-mapping.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/interrupt.h>
24#include <linux/ioport.h>
25#include <linux/kconfig.h>
26#include <linux/kernel.h>
27#include <linux/list.h>
28#include <linux/module.h>
29#include <linux/moduleparam.h>
30#include <linux/platform_device.h>
31#include <linux/sched.h>
32#include <linux/seq_file.h>
33#include <linux/slab.h>
34#include <linux/timer.h>
35#include <linux/usb/ch9.h>
36#include <linux/usb/gadget.h>
37#include <linux/workqueue.h>
38
39#include <bcm63xx_cpu.h>
40#include <bcm63xx_iudma.h>
41#include <bcm63xx_dev_usb_usbd.h>
42#include <bcm63xx_io.h>
43#include <bcm63xx_regs.h>
44
45#define DRV_MODULE_NAME "bcm63xx_udc"
46
47static const char bcm63xx_ep0name[] = "ep0";
48static const char *const bcm63xx_ep_name[] = {
49 bcm63xx_ep0name,
50 "ep1in-bulk", "ep2out-bulk", "ep3in-int", "ep4out-int",
51};
52
53static bool use_fullspeed;
54module_param(use_fullspeed, bool, S_IRUGO);
55MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
56
57/*
58 * RX IRQ coalescing options:
59 *
60 * false (default) - one IRQ per DATAx packet. Slow but reliable. The
61 * driver is able to pass the "testusb" suite and recover from conditions like:
62 *
63 * 1) Device queues up a 2048-byte RX IUDMA transaction on an OUT bulk ep
64 * 2) Host sends 512 bytes of data
65 * 3) Host decides to reconfigure the device and sends SET_INTERFACE
66 * 4) Device shuts down the endpoint and cancels the RX transaction
67 *
68 * true - one IRQ per transfer, for transfers <= 2048B. Generates
69 * considerably fewer IRQs, but error recovery is less robust. Does not
70 * reliably pass "testusb".
71 *
72 * TX always uses coalescing, because we can cancel partially complete TX
73 * transfers by repeatedly flushing the FIFO. The hardware doesn't allow
74 * this on RX.
75 */
76static bool irq_coalesce;
77module_param(irq_coalesce, bool, S_IRUGO);
78MODULE_PARM_DESC(irq_coalesce, "take one IRQ per RX transfer");
79
80#define BCM63XX_NUM_EP 5
81#define BCM63XX_NUM_IUDMA 6
82#define BCM63XX_NUM_FIFO_PAIRS 3
83
84#define IUDMA_RESET_TIMEOUT_US 10000
85
86#define IUDMA_EP0_RXCHAN 0
87#define IUDMA_EP0_TXCHAN 1
88
89#define IUDMA_MAX_FRAGMENT 2048
90#define BCM63XX_MAX_CTRL_PKT 64
91
92#define BCMEP_CTRL 0x00
93#define BCMEP_ISOC 0x01
94#define BCMEP_BULK 0x02
95#define BCMEP_INTR 0x03
96
97#define BCMEP_OUT 0x00
98#define BCMEP_IN 0x01
99
100#define BCM63XX_SPD_FULL 1
101#define BCM63XX_SPD_HIGH 0
102
103#define IUDMA_DMAC_OFFSET 0x200
104#define IUDMA_DMAS_OFFSET 0x400
105
106enum bcm63xx_ep0_state {
107 EP0_REQUEUE,
108 EP0_IDLE,
109 EP0_IN_DATA_PHASE_SETUP,
110 EP0_IN_DATA_PHASE_COMPLETE,
111 EP0_OUT_DATA_PHASE_SETUP,
112 EP0_OUT_DATA_PHASE_COMPLETE,
113 EP0_OUT_STATUS_PHASE,
114 EP0_IN_FAKE_STATUS_PHASE,
115 EP0_SHUTDOWN,
116};
117
118static const char __maybe_unused bcm63xx_ep0_state_names[][32] = {
119 "REQUEUE",
120 "IDLE",
121 "IN_DATA_PHASE_SETUP",
122 "IN_DATA_PHASE_COMPLETE",
123 "OUT_DATA_PHASE_SETUP",
124 "OUT_DATA_PHASE_COMPLETE",
125 "OUT_STATUS_PHASE",
126 "IN_FAKE_STATUS_PHASE",
127 "SHUTDOWN",
128};
129
130/**
131 * struct iudma_ch_cfg - Static configuration for an IUDMA channel.
132 * @ep_num: USB endpoint number.
133 * @n_bds: Number of buffer descriptors in the ring.
134 * @ep_type: Endpoint type (control, bulk, interrupt).
135 * @dir: Direction (in, out).
136 * @n_fifo_slots: Number of FIFO entries to allocate for this channel.
137 * @max_pkt_hs: Maximum packet size in high speed mode.
138 * @max_pkt_fs: Maximum packet size in full speed mode.
139 */
140struct iudma_ch_cfg {
141 int ep_num;
142 int n_bds;
143 int ep_type;
144 int dir;
145 int n_fifo_slots;
146 int max_pkt_hs;
147 int max_pkt_fs;
148};
149
150static const struct iudma_ch_cfg iudma_defaults[] = {
151
152 /* This controller was designed to support a CDC/RNDIS application.
153 It may be possible to reconfigure some of the endpoints, but
154 the hardware limitations (FIFO sizing and number of DMA channels)
155 may significantly impact flexibility and/or stability. Change
156 these values at your own risk.
157
158 ep_num ep_type n_fifo_slots max_pkt_fs
159 idx | n_bds | dir | max_pkt_hs |
160 | | | | | | | | */
161 [0] = { -1, 4, BCMEP_CTRL, BCMEP_OUT, 32, 64, 64 },
162 [1] = { 0, 4, BCMEP_CTRL, BCMEP_OUT, 32, 64, 64 },
163 [2] = { 2, 16, BCMEP_BULK, BCMEP_OUT, 128, 512, 64 },
164 [3] = { 1, 16, BCMEP_BULK, BCMEP_IN, 128, 512, 64 },
165 [4] = { 4, 4, BCMEP_INTR, BCMEP_OUT, 32, 64, 64 },
166 [5] = { 3, 4, BCMEP_INTR, BCMEP_IN, 32, 64, 64 },
167};
168
169struct bcm63xx_udc;
170
171/**
172 * struct iudma_ch - Represents the current state of a single IUDMA channel.
173 * @ch_idx: IUDMA channel index (0 to BCM63XX_NUM_IUDMA-1).
174 * @ep_num: USB endpoint number. -1 for ep0 RX.
175 * @enabled: Whether bcm63xx_ep_enable() has been called.
176 * @max_pkt: "Chunk size" on the USB interface. Based on interface speed.
177 * @is_tx: true for TX, false for RX.
178 * @bep: Pointer to the associated endpoint. NULL for ep0 RX.
179 * @udc: Reference to the device controller.
180 * @read_bd: Next buffer descriptor to reap from the hardware.
181 * @write_bd: Next BD available for a new packet.
182 * @end_bd: Points to the final BD in the ring.
183 * @n_bds_used: Number of BD entries currently occupied.
184 * @bd_ring: Base pointer to the BD ring.
185 * @bd_ring_dma: Physical (DMA) address of bd_ring.
186 * @n_bds: Total number of BDs in the ring.
187 *
188 * ep0 has two IUDMA channels (IUDMA_EP0_RXCHAN and IUDMA_EP0_TXCHAN), as it is
189 * bidirectional. The "struct usb_ep" associated with ep0 is for TX (IN)
190 * only.
191 *
192 * Each bulk/intr endpoint has a single IUDMA channel and a single
193 * struct usb_ep.
194 */
195struct iudma_ch {
196 unsigned int ch_idx;
197 int ep_num;
198 bool enabled;
199 int max_pkt;
200 bool is_tx;
201 struct bcm63xx_ep *bep;
202 struct bcm63xx_udc *udc;
203
204 struct bcm_enet_desc *read_bd;
205 struct bcm_enet_desc *write_bd;
206 struct bcm_enet_desc *end_bd;
207 int n_bds_used;
208
209 struct bcm_enet_desc *bd_ring;
210 dma_addr_t bd_ring_dma;
211 unsigned int n_bds;
212};
213
214/**
215 * struct bcm63xx_ep - Internal (driver) state of a single endpoint.
216 * @ep_num: USB endpoint number.
217 * @iudma: Pointer to IUDMA channel state.
218 * @ep: USB gadget layer representation of the EP.
219 * @udc: Reference to the device controller.
220 * @queue: Linked list of outstanding requests for this EP.
221 * @halted: 1 if the EP is stalled; 0 otherwise.
222 */
223struct bcm63xx_ep {
224 unsigned int ep_num;
225 struct iudma_ch *iudma;
226 struct usb_ep ep;
227 struct bcm63xx_udc *udc;
228 struct list_head queue;
229 unsigned halted:1;
230};
231
232/**
233 * struct bcm63xx_req - Internal (driver) state of a single request.
234 * @queue: Links back to the EP's request list.
235 * @req: USB gadget layer representation of the request.
236 * @offset: Current byte offset into the data buffer (next byte to queue).
237 * @bd_bytes: Number of data bytes in outstanding BD entries.
238 * @iudma: IUDMA channel used for the request.
239 */
240struct bcm63xx_req {
241 struct list_head queue; /* ep's requests */
242 struct usb_request req;
243 unsigned int offset;
244 unsigned int bd_bytes;
245 struct iudma_ch *iudma;
246};
247
248/**
249 * struct bcm63xx_udc - Driver/hardware private context.
250 * @lock: Spinlock to mediate access to this struct, and (most) HW regs.
251 * @dev: Generic Linux device structure.
252 * @pd: Platform data (board/port info).
253 * @usbd_clk: Clock descriptor for the USB device block.
254 * @usbh_clk: Clock descriptor for the USB host block.
255 * @gadget: USB slave device.
256 * @driver: Driver for USB slave devices.
257 * @usbd_regs: Base address of the USBD/USB20D block.
258 * @iudma_regs: Base address of the USBD's associated IUDMA block.
259 * @bep: Array of endpoints, including ep0.
260 * @iudma: Array of all IUDMA channels used by this controller.
261 * @cfg: USB configuration number, from SET_CONFIGURATION wValue.
262 * @iface: USB interface number, from SET_INTERFACE wIndex.
263 * @alt_iface: USB alt interface number, from SET_INTERFACE wValue.
264 * @ep0_ctrl_req: Request object for bcm63xx_udc-initiated ep0 transactions.
265 * @ep0_ctrl_buf: Data buffer for ep0_ctrl_req.
266 * @ep0state: Current state of the ep0 state machine.
267 * @ep0_wq: Workqueue struct used to wake up the ep0 state machine.
268 * @wedgemap: Bitmap of wedged endpoints.
269 * @ep0_req_reset: USB reset is pending.
270 * @ep0_req_set_cfg: Need to spoof a SET_CONFIGURATION packet.
271 * @ep0_req_set_iface: Need to spoof a SET_INTERFACE packet.
272 * @ep0_req_shutdown: Driver is shutting down; requesting ep0 to halt activity.
273 * @ep0_req_completed: ep0 request has completed; worker has not seen it yet.
274 * @ep0_reply: Pending reply from gadget driver.
275 * @ep0_request: Outstanding ep0 request.
276 * @debugfs_root: debugfs directory: /sys/kernel/debug/<DRV_MODULE_NAME>.
277 * @debugfs_usbd: debugfs file "usbd" for controller state.
278 * @debugfs_iudma: debugfs file "usbd" for IUDMA state.
279 */
280struct bcm63xx_udc {
281 spinlock_t lock;
282
283 struct device *dev;
284 struct bcm63xx_usbd_platform_data *pd;
285 struct clk *usbd_clk;
286 struct clk *usbh_clk;
287
288 struct usb_gadget gadget;
289 struct usb_gadget_driver *driver;
290
291 void __iomem *usbd_regs;
292 void __iomem *iudma_regs;
293
294 struct bcm63xx_ep bep[BCM63XX_NUM_EP];
295 struct iudma_ch iudma[BCM63XX_NUM_IUDMA];
296
297 int cfg;
298 int iface;
299 int alt_iface;
300
301 struct bcm63xx_req ep0_ctrl_req;
302 u8 *ep0_ctrl_buf;
303
304 int ep0state;
305 struct work_struct ep0_wq;
306
307 unsigned long wedgemap;
308
309 unsigned ep0_req_reset:1;
310 unsigned ep0_req_set_cfg:1;
311 unsigned ep0_req_set_iface:1;
312 unsigned ep0_req_shutdown:1;
313
314 unsigned ep0_req_completed:1;
315 struct usb_request *ep0_reply;
316 struct usb_request *ep0_request;
317
318 struct dentry *debugfs_root;
319 struct dentry *debugfs_usbd;
320 struct dentry *debugfs_iudma;
321};
322
323static const struct usb_ep_ops bcm63xx_udc_ep_ops;
324
325/***********************************************************************
326 * Convenience functions
327 ***********************************************************************/
328
329static inline struct bcm63xx_udc *gadget_to_udc(struct usb_gadget *g)
330{
331 return container_of(g, struct bcm63xx_udc, gadget);
332}
333
334static inline struct bcm63xx_ep *our_ep(struct usb_ep *ep)
335{
336 return container_of(ep, struct bcm63xx_ep, ep);
337}
338
339static inline struct bcm63xx_req *our_req(struct usb_request *req)
340{
341 return container_of(req, struct bcm63xx_req, req);
342}
343
344static inline u32 usbd_readl(struct bcm63xx_udc *udc, u32 off)
345{
346 return bcm_readl(udc->usbd_regs + off);
347}
348
349static inline void usbd_writel(struct bcm63xx_udc *udc, u32 val, u32 off)
350{
351 bcm_writel(val, udc->usbd_regs + off);
352}
353
354static inline u32 usb_dma_readl(struct bcm63xx_udc *udc, u32 off)
355{
356 return bcm_readl(udc->iudma_regs + off);
357}
358
359static inline void usb_dma_writel(struct bcm63xx_udc *udc, u32 val, u32 off)
360{
361 bcm_writel(val, udc->iudma_regs + off);
362}
363
364static inline u32 usb_dmac_readl(struct bcm63xx_udc *udc, u32 off)
365{
366 return bcm_readl(udc->iudma_regs + IUDMA_DMAC_OFFSET + off);
367}
368
369static inline void usb_dmac_writel(struct bcm63xx_udc *udc, u32 val, u32 off)
370{
371 bcm_writel(val, udc->iudma_regs + IUDMA_DMAC_OFFSET + off);
372}
373
374static inline u32 usb_dmas_readl(struct bcm63xx_udc *udc, u32 off)
375{
376 return bcm_readl(udc->iudma_regs + IUDMA_DMAS_OFFSET + off);
377}
378
379static inline void usb_dmas_writel(struct bcm63xx_udc *udc, u32 val, u32 off)
380{
381 bcm_writel(val, udc->iudma_regs + IUDMA_DMAS_OFFSET + off);
382}
383
384static inline void set_clocks(struct bcm63xx_udc *udc, bool is_enabled)
385{
386 if (is_enabled) {
387 clk_enable(udc->usbh_clk);
388 clk_enable(udc->usbd_clk);
389 udelay(10);
390 } else {
391 clk_disable(udc->usbd_clk);
392 clk_disable(udc->usbh_clk);
393 }
394}
395
396/***********************************************************************
397 * Low-level IUDMA / FIFO operations
398 ***********************************************************************/
399
400/**
401 * bcm63xx_ep_dma_select - Helper function to set up the init_sel signal.
402 * @udc: Reference to the device controller.
403 * @idx: Desired init_sel value.
404 *
405 * The "init_sel" signal is used as a selection index for both endpoints
406 * and IUDMA channels. Since these do not map 1:1, the use of this signal
407 * depends on the context.
408 */
409static void bcm63xx_ep_dma_select(struct bcm63xx_udc *udc, int idx)
410{
411 u32 val = usbd_readl(udc, USBD_CONTROL_REG);
412
413 val &= ~USBD_CONTROL_INIT_SEL_MASK;
414 val |= idx << USBD_CONTROL_INIT_SEL_SHIFT;
415 usbd_writel(udc, val, USBD_CONTROL_REG);
416}
417
418/**
419 * bcm63xx_set_stall - Enable/disable stall on one endpoint.
420 * @udc: Reference to the device controller.
421 * @bep: Endpoint on which to operate.
422 * @is_stalled: true to enable stall, false to disable.
423 *
424 * See notes in bcm63xx_update_wedge() regarding automatic clearing of
425 * halt/stall conditions.
426 */
427static void bcm63xx_set_stall(struct bcm63xx_udc *udc, struct bcm63xx_ep *bep,
428 bool is_stalled)
429{
430 u32 val;
431
432 val = USBD_STALL_UPDATE_MASK |
433 (is_stalled ? USBD_STALL_ENABLE_MASK : 0) |
434 (bep->ep_num << USBD_STALL_EPNUM_SHIFT);
435 usbd_writel(udc, val, USBD_STALL_REG);
436}
437
438/**
439 * bcm63xx_fifo_setup - (Re)initialize FIFO boundaries and settings.
440 * @udc: Reference to the device controller.
441 *
442 * These parameters depend on the USB link speed. Settings are
443 * per-IUDMA-channel-pair.
444 */
445static void bcm63xx_fifo_setup(struct bcm63xx_udc *udc)
446{
447 int is_hs = udc->gadget.speed == USB_SPEED_HIGH;
448 u32 i, val, rx_fifo_slot, tx_fifo_slot;
449
450 /* set up FIFO boundaries and packet sizes; this is done in pairs */
451 rx_fifo_slot = tx_fifo_slot = 0;
452 for (i = 0; i < BCM63XX_NUM_IUDMA; i += 2) {
453 const struct iudma_ch_cfg *rx_cfg = &iudma_defaults[i];
454 const struct iudma_ch_cfg *tx_cfg = &iudma_defaults[i + 1];
455
456 bcm63xx_ep_dma_select(udc, i >> 1);
457
458 val = (rx_fifo_slot << USBD_RXFIFO_CONFIG_START_SHIFT) |
459 ((rx_fifo_slot + rx_cfg->n_fifo_slots - 1) <<
460 USBD_RXFIFO_CONFIG_END_SHIFT);
461 rx_fifo_slot += rx_cfg->n_fifo_slots;
462 usbd_writel(udc, val, USBD_RXFIFO_CONFIG_REG);
463 usbd_writel(udc,
464 is_hs ? rx_cfg->max_pkt_hs : rx_cfg->max_pkt_fs,
465 USBD_RXFIFO_EPSIZE_REG);
466
467 val = (tx_fifo_slot << USBD_TXFIFO_CONFIG_START_SHIFT) |
468 ((tx_fifo_slot + tx_cfg->n_fifo_slots - 1) <<
469 USBD_TXFIFO_CONFIG_END_SHIFT);
470 tx_fifo_slot += tx_cfg->n_fifo_slots;
471 usbd_writel(udc, val, USBD_TXFIFO_CONFIG_REG);
472 usbd_writel(udc,
473 is_hs ? tx_cfg->max_pkt_hs : tx_cfg->max_pkt_fs,
474 USBD_TXFIFO_EPSIZE_REG);
475
476 usbd_readl(udc, USBD_TXFIFO_EPSIZE_REG);
477 }
478}
479
480/**
481 * bcm63xx_fifo_reset_ep - Flush a single endpoint's FIFO.
482 * @udc: Reference to the device controller.
483 * @ep_num: Endpoint number.
484 */
485static void bcm63xx_fifo_reset_ep(struct bcm63xx_udc *udc, int ep_num)
486{
487 u32 val;
488
489 bcm63xx_ep_dma_select(udc, ep_num);
490
491 val = usbd_readl(udc, USBD_CONTROL_REG);
492 val |= USBD_CONTROL_FIFO_RESET_MASK;
493 usbd_writel(udc, val, USBD_CONTROL_REG);
494 usbd_readl(udc, USBD_CONTROL_REG);
495}
496
497/**
498 * bcm63xx_fifo_reset - Flush all hardware FIFOs.
499 * @udc: Reference to the device controller.
500 */
501static void bcm63xx_fifo_reset(struct bcm63xx_udc *udc)
502{
503 int i;
504
505 for (i = 0; i < BCM63XX_NUM_FIFO_PAIRS; i++)
506 bcm63xx_fifo_reset_ep(udc, i);
507}
508
509/**
510 * bcm63xx_ep_init - Initial (one-time) endpoint initialization.
511 * @udc: Reference to the device controller.
512 */
513static void bcm63xx_ep_init(struct bcm63xx_udc *udc)
514{
515 u32 i, val;
516
517 for (i = 0; i < BCM63XX_NUM_IUDMA; i++) {
518 const struct iudma_ch_cfg *cfg = &iudma_defaults[i];
519
520 if (cfg->ep_num < 0)
521 continue;
522
523 bcm63xx_ep_dma_select(udc, cfg->ep_num);
524 val = (cfg->ep_type << USBD_EPNUM_TYPEMAP_TYPE_SHIFT) |
525 ((i >> 1) << USBD_EPNUM_TYPEMAP_DMA_CH_SHIFT);
526 usbd_writel(udc, val, USBD_EPNUM_TYPEMAP_REG);
527 }
528}
529
530/**
531 * bcm63xx_ep_setup - Configure per-endpoint settings.
532 * @udc: Reference to the device controller.
533 *
534 * This needs to be rerun if the speed/cfg/intf/altintf changes.
535 */
536static void bcm63xx_ep_setup(struct bcm63xx_udc *udc)
537{
538 u32 val, i;
539
540 usbd_writel(udc, USBD_CSR_SETUPADDR_DEF, USBD_CSR_SETUPADDR_REG);
541
542 for (i = 0; i < BCM63XX_NUM_IUDMA; i++) {
543 const struct iudma_ch_cfg *cfg = &iudma_defaults[i];
544 int max_pkt = udc->gadget.speed == USB_SPEED_HIGH ?
545 cfg->max_pkt_hs : cfg->max_pkt_fs;
546 int idx = cfg->ep_num;
547
548 udc->iudma[i].max_pkt = max_pkt;
549
550 if (idx < 0)
551 continue;
552 udc->bep[idx].ep.maxpacket = max_pkt;
553
554 val = (idx << USBD_CSR_EP_LOG_SHIFT) |
555 (cfg->dir << USBD_CSR_EP_DIR_SHIFT) |
556 (cfg->ep_type << USBD_CSR_EP_TYPE_SHIFT) |
557 (udc->cfg << USBD_CSR_EP_CFG_SHIFT) |
558 (udc->iface << USBD_CSR_EP_IFACE_SHIFT) |
559 (udc->alt_iface << USBD_CSR_EP_ALTIFACE_SHIFT) |
560 (max_pkt << USBD_CSR_EP_MAXPKT_SHIFT);
561 usbd_writel(udc, val, USBD_CSR_EP_REG(idx));
562 }
563}
564
565/**
566 * iudma_write - Queue a single IUDMA transaction.
567 * @udc: Reference to the device controller.
568 * @iudma: IUDMA channel to use.
569 * @breq: Request containing the transaction data.
570 *
571 * For RX IUDMA, this will queue a single buffer descriptor, as RX IUDMA
572 * does not honor SOP/EOP so the handling of multiple buffers is ambiguous.
573 * So iudma_write() may be called several times to fulfill a single
574 * usb_request.
575 *
576 * For TX IUDMA, this can queue multiple buffer descriptors if needed.
577 */
578static void iudma_write(struct bcm63xx_udc *udc, struct iudma_ch *iudma,
579 struct bcm63xx_req *breq)
580{
581 int first_bd = 1, last_bd = 0, extra_zero_pkt = 0;
582 unsigned int bytes_left = breq->req.length - breq->offset;
583 const int max_bd_bytes = !irq_coalesce && !iudma->is_tx ?
584 iudma->max_pkt : IUDMA_MAX_FRAGMENT;
585
586 iudma->n_bds_used = 0;
587 breq->bd_bytes = 0;
588 breq->iudma = iudma;
589
590 if ((bytes_left % iudma->max_pkt == 0) && bytes_left && breq->req.zero)
591 extra_zero_pkt = 1;
592
593 do {
594 struct bcm_enet_desc *d = iudma->write_bd;
595 u32 dmaflags = 0;
596 unsigned int n_bytes;
597
598 if (d == iudma->end_bd) {
599 dmaflags |= DMADESC_WRAP_MASK;
600 iudma->write_bd = iudma->bd_ring;
601 } else {
602 iudma->write_bd++;
603 }
604 iudma->n_bds_used++;
605
606 n_bytes = min_t(int, bytes_left, max_bd_bytes);
607 if (n_bytes)
608 dmaflags |= n_bytes << DMADESC_LENGTH_SHIFT;
609 else
610 dmaflags |= (1 << DMADESC_LENGTH_SHIFT) |
611 DMADESC_USB_ZERO_MASK;
612
613 dmaflags |= DMADESC_OWNER_MASK;
614 if (first_bd) {
615 dmaflags |= DMADESC_SOP_MASK;
616 first_bd = 0;
617 }
618
619 /*
620 * extra_zero_pkt forces one more iteration through the loop
621 * after all data is queued up, to send the zero packet
622 */
623 if (extra_zero_pkt && !bytes_left)
624 extra_zero_pkt = 0;
625
626 if (!iudma->is_tx || iudma->n_bds_used == iudma->n_bds ||
627 (n_bytes == bytes_left && !extra_zero_pkt)) {
628 last_bd = 1;
629 dmaflags |= DMADESC_EOP_MASK;
630 }
631
632 d->address = breq->req.dma + breq->offset;
633 mb();
634 d->len_stat = dmaflags;
635
636 breq->offset += n_bytes;
637 breq->bd_bytes += n_bytes;
638 bytes_left -= n_bytes;
639 } while (!last_bd);
640
641 usb_dmac_writel(udc, ENETDMAC_CHANCFG_EN_MASK,
642 ENETDMAC_CHANCFG_REG(iudma->ch_idx));
643}
644
645/**
646 * iudma_read - Check for IUDMA buffer completion.
647 * @udc: Reference to the device controller.
648 * @iudma: IUDMA channel to use.
649 *
650 * This checks to see if ALL of the outstanding BDs on the DMA channel
651 * have been filled. If so, it returns the actual transfer length;
652 * otherwise it returns -EBUSY.
653 */
654static int iudma_read(struct bcm63xx_udc *udc, struct iudma_ch *iudma)
655{
656 int i, actual_len = 0;
657 struct bcm_enet_desc *d = iudma->read_bd;
658
659 if (!iudma->n_bds_used)
660 return -EINVAL;
661
662 for (i = 0; i < iudma->n_bds_used; i++) {
663 u32 dmaflags;
664
665 dmaflags = d->len_stat;
666
667 if (dmaflags & DMADESC_OWNER_MASK)
668 return -EBUSY;
669
670 actual_len += (dmaflags & DMADESC_LENGTH_MASK) >>
671 DMADESC_LENGTH_SHIFT;
672 if (d == iudma->end_bd)
673 d = iudma->bd_ring;
674 else
675 d++;
676 }
677
678 iudma->read_bd = d;
679 iudma->n_bds_used = 0;
680 return actual_len;
681}
682
683/**
684 * iudma_reset_channel - Stop DMA on a single channel.
685 * @udc: Reference to the device controller.
686 * @iudma: IUDMA channel to reset.
687 */
688static void iudma_reset_channel(struct bcm63xx_udc *udc, struct iudma_ch *iudma)
689{
690 int timeout = IUDMA_RESET_TIMEOUT_US;
691 struct bcm_enet_desc *d;
692 int ch_idx = iudma->ch_idx;
693
694 if (!iudma->is_tx)
695 bcm63xx_fifo_reset_ep(udc, max(0, iudma->ep_num));
696
697 /* stop DMA, then wait for the hardware to wrap up */
698 usb_dmac_writel(udc, 0, ENETDMAC_CHANCFG_REG(ch_idx));
699
700 while (usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG(ch_idx)) &
701 ENETDMAC_CHANCFG_EN_MASK) {
702 udelay(1);
703
704 /* repeatedly flush the FIFO data until the BD completes */
705 if (iudma->is_tx && iudma->ep_num >= 0)
706 bcm63xx_fifo_reset_ep(udc, iudma->ep_num);
707
708 if (!timeout--) {
709 dev_err(udc->dev, "can't reset IUDMA channel %d\n",
710 ch_idx);
711 break;
712 }
713 if (timeout == IUDMA_RESET_TIMEOUT_US / 2) {
714 dev_warn(udc->dev, "forcibly halting IUDMA channel %d\n",
715 ch_idx);
716 usb_dmac_writel(udc, ENETDMAC_CHANCFG_BUFHALT_MASK,
717 ENETDMAC_CHANCFG_REG(ch_idx));
718 }
719 }
720 usb_dmac_writel(udc, ~0, ENETDMAC_IR_REG(ch_idx));
721
722 /* don't leave "live" HW-owned entries for the next guy to step on */
723 for (d = iudma->bd_ring; d <= iudma->end_bd; d++)
724 d->len_stat = 0;
725 mb();
726
727 iudma->read_bd = iudma->write_bd = iudma->bd_ring;
728 iudma->n_bds_used = 0;
729
730 /* set up IRQs, UBUS burst size, and BD base for this channel */
731 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK,
732 ENETDMAC_IRMASK_REG(ch_idx));
733 usb_dmac_writel(udc, 8, ENETDMAC_MAXBURST_REG(ch_idx));
734
735 usb_dmas_writel(udc, iudma->bd_ring_dma, ENETDMAS_RSTART_REG(ch_idx));
736 usb_dmas_writel(udc, 0, ENETDMAS_SRAM2_REG(ch_idx));
737}
738
739/**
740 * iudma_init_channel - One-time IUDMA channel initialization.
741 * @udc: Reference to the device controller.
742 * @ch_idx: Channel to initialize.
743 */
744static int iudma_init_channel(struct bcm63xx_udc *udc, unsigned int ch_idx)
745{
746 struct iudma_ch *iudma = &udc->iudma[ch_idx];
747 const struct iudma_ch_cfg *cfg = &iudma_defaults[ch_idx];
748 unsigned int n_bds = cfg->n_bds;
749 struct bcm63xx_ep *bep = NULL;
750
751 iudma->ep_num = cfg->ep_num;
752 iudma->ch_idx = ch_idx;
753 iudma->is_tx = !!(ch_idx & 0x01);
754 if (iudma->ep_num >= 0) {
755 bep = &udc->bep[iudma->ep_num];
756 bep->iudma = iudma;
757 INIT_LIST_HEAD(&bep->queue);
758 }
759
760 iudma->bep = bep;
761 iudma->udc = udc;
762
763 /* ep0 is always active; others are controlled by the gadget driver */
764 if (iudma->ep_num <= 0)
765 iudma->enabled = true;
766
767 iudma->n_bds = n_bds;
768 iudma->bd_ring = dmam_alloc_coherent(udc->dev,
769 n_bds * sizeof(struct bcm_enet_desc),
770 &iudma->bd_ring_dma, GFP_KERNEL);
771 if (!iudma->bd_ring)
772 return -ENOMEM;
773 iudma->end_bd = &iudma->bd_ring[n_bds - 1];
774
775 return 0;
776}
777
778/**
779 * iudma_init - One-time initialization of all IUDMA channels.
780 * @udc: Reference to the device controller.
781 *
782 * Enable DMA, flush channels, and enable global IUDMA IRQs.
783 */
784static int iudma_init(struct bcm63xx_udc *udc)
785{
786 int i, rc;
787
788 usb_dma_writel(udc, ENETDMA_CFG_EN_MASK, ENETDMA_CFG_REG);
789
790 for (i = 0; i < BCM63XX_NUM_IUDMA; i++) {
791 rc = iudma_init_channel(udc, i);
792 if (rc)
793 return rc;
794 iudma_reset_channel(udc, &udc->iudma[i]);
795 }
796
797 usb_dma_writel(udc, BIT(BCM63XX_NUM_IUDMA)-1, ENETDMA_GLB_IRQMASK_REG);
798 return 0;
799}
800
801/**
802 * iudma_uninit - Uninitialize IUDMA channels.
803 * @udc: Reference to the device controller.
804 *
805 * Kill global IUDMA IRQs, flush channels, and kill DMA.
806 */
807static void iudma_uninit(struct bcm63xx_udc *udc)
808{
809 int i;
810
811 usb_dma_writel(udc, 0, ENETDMA_GLB_IRQMASK_REG);
812
813 for (i = 0; i < BCM63XX_NUM_IUDMA; i++)
814 iudma_reset_channel(udc, &udc->iudma[i]);
815
816 usb_dma_writel(udc, 0, ENETDMA_CFG_REG);
817}
818
819/***********************************************************************
820 * Other low-level USBD operations
821 ***********************************************************************/
822
823/**
824 * bcm63xx_set_ctrl_irqs - Mask/unmask control path interrupts.
825 * @udc: Reference to the device controller.
826 * @enable_irqs: true to enable, false to disable.
827 */
828static void bcm63xx_set_ctrl_irqs(struct bcm63xx_udc *udc, bool enable_irqs)
829{
830 u32 val;
831
832 usbd_writel(udc, 0, USBD_STATUS_REG);
833
834 val = BIT(USBD_EVENT_IRQ_USB_RESET) |
835 BIT(USBD_EVENT_IRQ_SETUP) |
836 BIT(USBD_EVENT_IRQ_SETCFG) |
837 BIT(USBD_EVENT_IRQ_SETINTF) |
838 BIT(USBD_EVENT_IRQ_USB_LINK);
839 usbd_writel(udc, enable_irqs ? val : 0, USBD_EVENT_IRQ_MASK_REG);
840 usbd_writel(udc, val, USBD_EVENT_IRQ_STATUS_REG);
841}
842
843/**
844 * bcm63xx_select_phy_mode - Select between USB device and host mode.
845 * @udc: Reference to the device controller.
846 * @is_device: true for device, false for host.
847 *
848 * This should probably be reworked to use the drivers/usb/otg
849 * infrastructure.
850 *
851 * By default, the AFE/pullups are disabled in device mode, until
852 * bcm63xx_select_pullup() is called.
853 */
854static void bcm63xx_select_phy_mode(struct bcm63xx_udc *udc, bool is_device)
855{
856 u32 val, portmask = BIT(udc->pd->port_no);
857
858 if (BCMCPU_IS_6328()) {
859 /* configure pinmux to sense VBUS signal */
860 val = bcm_gpio_readl(GPIO_PINMUX_OTHR_REG);
861 val &= ~GPIO_PINMUX_OTHR_6328_USB_MASK;
862 val |= is_device ? GPIO_PINMUX_OTHR_6328_USB_DEV :
863 GPIO_PINMUX_OTHR_6328_USB_HOST;
864 bcm_gpio_writel(val, GPIO_PINMUX_OTHR_REG);
865 }
866
867 val = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_UTMI_CTL_6368_REG);
868 if (is_device) {
869 val |= (portmask << USBH_PRIV_UTMI_CTL_HOSTB_SHIFT);
870 val |= (portmask << USBH_PRIV_UTMI_CTL_NODRIV_SHIFT);
871 } else {
872 val &= ~(portmask << USBH_PRIV_UTMI_CTL_HOSTB_SHIFT);
873 val &= ~(portmask << USBH_PRIV_UTMI_CTL_NODRIV_SHIFT);
874 }
875 bcm_rset_writel(RSET_USBH_PRIV, val, USBH_PRIV_UTMI_CTL_6368_REG);
876
877 val = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6368_REG);
878 if (is_device)
879 val |= USBH_PRIV_SWAP_USBD_MASK;
880 else
881 val &= ~USBH_PRIV_SWAP_USBD_MASK;
882 bcm_rset_writel(RSET_USBH_PRIV, val, USBH_PRIV_SWAP_6368_REG);
883}
884
885/**
886 * bcm63xx_select_pullup - Enable/disable the pullup on D+
887 * @udc: Reference to the device controller.
888 * @is_on: true to enable the pullup, false to disable.
889 *
890 * If the pullup is active, the host will sense a FS/HS device connected to
891 * the port. If the pullup is inactive, the host will think the USB
892 * device has been disconnected.
893 */
894static void bcm63xx_select_pullup(struct bcm63xx_udc *udc, bool is_on)
895{
896 u32 val, portmask = BIT(udc->pd->port_no);
897
898 val = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_UTMI_CTL_6368_REG);
899 if (is_on)
900 val &= ~(portmask << USBH_PRIV_UTMI_CTL_NODRIV_SHIFT);
901 else
902 val |= (portmask << USBH_PRIV_UTMI_CTL_NODRIV_SHIFT);
903 bcm_rset_writel(RSET_USBH_PRIV, val, USBH_PRIV_UTMI_CTL_6368_REG);
904}
905
906/**
907 * bcm63xx_uninit_udc_hw - Shut down the hardware prior to driver removal.
908 * @udc: Reference to the device controller.
909 *
910 * This just masks the IUDMA IRQs and releases the clocks. It is assumed
911 * that bcm63xx_udc_stop() has already run, and the clocks are stopped.
912 */
913static void bcm63xx_uninit_udc_hw(struct bcm63xx_udc *udc)
914{
915 set_clocks(udc, true);
916 iudma_uninit(udc);
917 set_clocks(udc, false);
918
919 clk_put(udc->usbd_clk);
920 clk_put(udc->usbh_clk);
921}
922
923/**
924 * bcm63xx_init_udc_hw - Initialize the controller hardware and data structures.
925 * @udc: Reference to the device controller.
926 */
927static int bcm63xx_init_udc_hw(struct bcm63xx_udc *udc)
928{
929 int i, rc = 0;
930 u32 val;
931
932 udc->ep0_ctrl_buf = devm_kzalloc(udc->dev, BCM63XX_MAX_CTRL_PKT,
933 GFP_KERNEL);
934 if (!udc->ep0_ctrl_buf)
935 return -ENOMEM;
936
937 INIT_LIST_HEAD(&udc->gadget.ep_list);
938 for (i = 0; i < BCM63XX_NUM_EP; i++) {
939 struct bcm63xx_ep *bep = &udc->bep[i];
940
941 bep->ep.name = bcm63xx_ep_name[i];
942 bep->ep_num = i;
943 bep->ep.ops = &bcm63xx_udc_ep_ops;
944 list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list);
945 bep->halted = 0;
946 bep->ep.maxpacket = BCM63XX_MAX_CTRL_PKT;
947 bep->udc = udc;
948 bep->ep.desc = NULL;
949 INIT_LIST_HEAD(&bep->queue);
950 }
951
952 udc->gadget.ep0 = &udc->bep[0].ep;
953 list_del(&udc->bep[0].ep.ep_list);
954
955 udc->gadget.speed = USB_SPEED_UNKNOWN;
956 udc->ep0state = EP0_SHUTDOWN;
957
958 udc->usbh_clk = clk_get(udc->dev, "usbh");
959 if (IS_ERR(udc->usbh_clk))
960 return -EIO;
961
962 udc->usbd_clk = clk_get(udc->dev, "usbd");
963 if (IS_ERR(udc->usbd_clk)) {
964 clk_put(udc->usbh_clk);
965 return -EIO;
966 }
967
968 set_clocks(udc, true);
969
970 val = USBD_CONTROL_AUTO_CSRS_MASK |
971 USBD_CONTROL_DONE_CSRS_MASK |
972 (irq_coalesce ? USBD_CONTROL_RXZSCFG_MASK : 0);
973 usbd_writel(udc, val, USBD_CONTROL_REG);
974
975 val = USBD_STRAPS_APP_SELF_PWR_MASK |
976 USBD_STRAPS_APP_RAM_IF_MASK |
977 USBD_STRAPS_APP_CSRPRGSUP_MASK |
978 USBD_STRAPS_APP_8BITPHY_MASK |
979 USBD_STRAPS_APP_RMTWKUP_MASK;
980
981 if (udc->gadget.max_speed == USB_SPEED_HIGH)
982 val |= (BCM63XX_SPD_HIGH << USBD_STRAPS_SPEED_SHIFT);
983 else
984 val |= (BCM63XX_SPD_FULL << USBD_STRAPS_SPEED_SHIFT);
985 usbd_writel(udc, val, USBD_STRAPS_REG);
986
987 bcm63xx_set_ctrl_irqs(udc, false);
988
989 usbd_writel(udc, 0, USBD_EVENT_IRQ_CFG_LO_REG);
990
991 val = USBD_EVENT_IRQ_CFG_FALLING(USBD_EVENT_IRQ_ENUM_ON) |
992 USBD_EVENT_IRQ_CFG_FALLING(USBD_EVENT_IRQ_SET_CSRS);
993 usbd_writel(udc, val, USBD_EVENT_IRQ_CFG_HI_REG);
994
995 rc = iudma_init(udc);
996 set_clocks(udc, false);
997 if (rc)
998 bcm63xx_uninit_udc_hw(udc);
999
1000 return 0;
1001}
1002
1003/***********************************************************************
1004 * Standard EP gadget operations
1005 ***********************************************************************/
1006
1007/**
1008 * bcm63xx_ep_enable - Enable one endpoint.
1009 * @ep: Endpoint to enable.
1010 * @desc: Contains max packet, direction, etc.
1011 *
1012 * Most of the endpoint parameters are fixed in this controller, so there
1013 * isn't much for this function to do.
1014 */
1015static int bcm63xx_ep_enable(struct usb_ep *ep,
1016 const struct usb_endpoint_descriptor *desc)
1017{
1018 struct bcm63xx_ep *bep = our_ep(ep);
1019 struct bcm63xx_udc *udc = bep->udc;
1020 struct iudma_ch *iudma = bep->iudma;
1021 unsigned long flags;
1022
1023 if (!ep || !desc || ep->name == bcm63xx_ep0name)
1024 return -EINVAL;
1025
1026 if (!udc->driver)
1027 return -ESHUTDOWN;
1028
1029 spin_lock_irqsave(&udc->lock, flags);
1030 if (iudma->enabled) {
1031 spin_unlock_irqrestore(&udc->lock, flags);
1032 return -EINVAL;
1033 }
1034
1035 iudma->enabled = true;
1036 BUG_ON(!list_empty(&bep->queue));
1037
1038 iudma_reset_channel(udc, iudma);
1039
1040 bep->halted = 0;
1041 bcm63xx_set_stall(udc, bep, false);
1042 clear_bit(bep->ep_num, &udc->wedgemap);
1043
1044 ep->desc = desc;
1045 ep->maxpacket = usb_endpoint_maxp(desc);
1046
1047 spin_unlock_irqrestore(&udc->lock, flags);
1048 return 0;
1049}
1050
1051/**
1052 * bcm63xx_ep_disable - Disable one endpoint.
1053 * @ep: Endpoint to disable.
1054 */
1055static int bcm63xx_ep_disable(struct usb_ep *ep)
1056{
1057 struct bcm63xx_ep *bep = our_ep(ep);
1058 struct bcm63xx_udc *udc = bep->udc;
1059 struct iudma_ch *iudma = bep->iudma;
1060 struct list_head *pos, *n;
1061 unsigned long flags;
1062
1063 if (!ep || !ep->desc)
1064 return -EINVAL;
1065
1066 spin_lock_irqsave(&udc->lock, flags);
1067 if (!iudma->enabled) {
1068 spin_unlock_irqrestore(&udc->lock, flags);
1069 return -EINVAL;
1070 }
1071 iudma->enabled = false;
1072
1073 iudma_reset_channel(udc, iudma);
1074
1075 if (!list_empty(&bep->queue)) {
1076 list_for_each_safe(pos, n, &bep->queue) {
1077 struct bcm63xx_req *breq =
1078 list_entry(pos, struct bcm63xx_req, queue);
1079
1080 usb_gadget_unmap_request(&udc->gadget, &breq->req,
1081 iudma->is_tx);
1082 list_del(&breq->queue);
1083 breq->req.status = -ESHUTDOWN;
1084
1085 spin_unlock_irqrestore(&udc->lock, flags);
1086 breq->req.complete(&iudma->bep->ep, &breq->req);
1087 spin_lock_irqsave(&udc->lock, flags);
1088 }
1089 }
1090 ep->desc = NULL;
1091
1092 spin_unlock_irqrestore(&udc->lock, flags);
1093 return 0;
1094}
1095
1096/**
1097 * bcm63xx_udc_alloc_request - Allocate a new request.
1098 * @ep: Endpoint associated with the request.
1099 * @mem_flags: Flags to pass to kzalloc().
1100 */
1101static struct usb_request *bcm63xx_udc_alloc_request(struct usb_ep *ep,
1102 gfp_t mem_flags)
1103{
1104 struct bcm63xx_req *breq;
1105
1106 breq = kzalloc(sizeof(*breq), mem_flags);
1107 if (!breq)
1108 return NULL;
1109 return &breq->req;
1110}
1111
1112/**
1113 * bcm63xx_udc_free_request - Free a request.
1114 * @ep: Endpoint associated with the request.
1115 * @req: Request to free.
1116 */
1117static void bcm63xx_udc_free_request(struct usb_ep *ep,
1118 struct usb_request *req)
1119{
1120 struct bcm63xx_req *breq = our_req(req);
1121 kfree(breq);
1122}
1123
1124/**
1125 * bcm63xx_udc_queue - Queue up a new request.
1126 * @ep: Endpoint associated with the request.
1127 * @req: Request to add.
1128 * @mem_flags: Unused.
1129 *
1130 * If the queue is empty, start this request immediately. Otherwise, add
1131 * it to the list.
1132 *
1133 * ep0 replies are sent through this function from the gadget driver, but
1134 * they are treated differently because they need to be handled by the ep0
1135 * state machine. (Sometimes they are replies to control requests that
1136 * were spoofed by this driver, and so they shouldn't be transmitted at all.)
1137 */
1138static int bcm63xx_udc_queue(struct usb_ep *ep, struct usb_request *req,
1139 gfp_t mem_flags)
1140{
1141 struct bcm63xx_ep *bep = our_ep(ep);
1142 struct bcm63xx_udc *udc = bep->udc;
1143 struct bcm63xx_req *breq = our_req(req);
1144 unsigned long flags;
1145 int rc = 0;
1146
1147 if (unlikely(!req || !req->complete || !req->buf || !ep))
1148 return -EINVAL;
1149
1150 req->actual = 0;
1151 req->status = 0;
1152 breq->offset = 0;
1153
1154 if (bep == &udc->bep[0]) {
1155 /* only one reply per request, please */
1156 if (udc->ep0_reply)
1157 return -EINVAL;
1158
1159 udc->ep0_reply = req;
1160 schedule_work(&udc->ep0_wq);
1161 return 0;
1162 }
1163
1164 spin_lock_irqsave(&udc->lock, flags);
1165 if (!bep->iudma->enabled) {
1166 rc = -ESHUTDOWN;
1167 goto out;
1168 }
1169
1170 rc = usb_gadget_map_request(&udc->gadget, req, bep->iudma->is_tx);
1171 if (rc == 0) {
1172 list_add_tail(&breq->queue, &bep->queue);
1173 if (list_is_singular(&bep->queue))
1174 iudma_write(udc, bep->iudma, breq);
1175 }
1176
1177out:
1178 spin_unlock_irqrestore(&udc->lock, flags);
1179 return rc;
1180}
1181
1182/**
1183 * bcm63xx_udc_dequeue - Remove a pending request from the queue.
1184 * @ep: Endpoint associated with the request.
1185 * @req: Request to remove.
1186 *
1187 * If the request is not at the head of the queue, this is easy - just nuke
1188 * it. If the request is at the head of the queue, we'll need to stop the
1189 * DMA transaction and then queue up the successor.
1190 */
1191static int bcm63xx_udc_dequeue(struct usb_ep *ep, struct usb_request *req)
1192{
1193 struct bcm63xx_ep *bep = our_ep(ep);
1194 struct bcm63xx_udc *udc = bep->udc;
1195 struct bcm63xx_req *breq = our_req(req), *cur;
1196 unsigned long flags;
1197 int rc = 0;
1198
1199 spin_lock_irqsave(&udc->lock, flags);
1200 if (list_empty(&bep->queue)) {
1201 rc = -EINVAL;
1202 goto out;
1203 }
1204
1205 cur = list_first_entry(&bep->queue, struct bcm63xx_req, queue);
1206 usb_gadget_unmap_request(&udc->gadget, &breq->req, bep->iudma->is_tx);
1207
1208 if (breq == cur) {
1209 iudma_reset_channel(udc, bep->iudma);
1210 list_del(&breq->queue);
1211
1212 if (!list_empty(&bep->queue)) {
1213 struct bcm63xx_req *next;
1214
1215 next = list_first_entry(&bep->queue,
1216 struct bcm63xx_req, queue);
1217 iudma_write(udc, bep->iudma, next);
1218 }
1219 } else {
1220 list_del(&breq->queue);
1221 }
1222
1223out:
1224 spin_unlock_irqrestore(&udc->lock, flags);
1225
1226 req->status = -ESHUTDOWN;
1227 req->complete(ep, req);
1228
1229 return rc;
1230}
1231
1232/**
1233 * bcm63xx_udc_set_halt - Enable/disable STALL flag in the hardware.
1234 * @ep: Endpoint to halt.
1235 * @value: Zero to clear halt; nonzero to set halt.
1236 *
1237 * See comments in bcm63xx_update_wedge().
1238 */
1239static int bcm63xx_udc_set_halt(struct usb_ep *ep, int value)
1240{
1241 struct bcm63xx_ep *bep = our_ep(ep);
1242 struct bcm63xx_udc *udc = bep->udc;
1243 unsigned long flags;
1244
1245 spin_lock_irqsave(&udc->lock, flags);
1246 bcm63xx_set_stall(udc, bep, !!value);
1247 bep->halted = value;
1248 spin_unlock_irqrestore(&udc->lock, flags);
1249
1250 return 0;
1251}
1252
1253/**
1254 * bcm63xx_udc_set_wedge - Stall the endpoint until the next reset.
1255 * @ep: Endpoint to wedge.
1256 *
1257 * See comments in bcm63xx_update_wedge().
1258 */
1259static int bcm63xx_udc_set_wedge(struct usb_ep *ep)
1260{
1261 struct bcm63xx_ep *bep = our_ep(ep);
1262 struct bcm63xx_udc *udc = bep->udc;
1263 unsigned long flags;
1264
1265 spin_lock_irqsave(&udc->lock, flags);
1266 set_bit(bep->ep_num, &udc->wedgemap);
1267 bcm63xx_set_stall(udc, bep, true);
1268 spin_unlock_irqrestore(&udc->lock, flags);
1269
1270 return 0;
1271}
1272
1273static const struct usb_ep_ops bcm63xx_udc_ep_ops = {
1274 .enable = bcm63xx_ep_enable,
1275 .disable = bcm63xx_ep_disable,
1276
1277 .alloc_request = bcm63xx_udc_alloc_request,
1278 .free_request = bcm63xx_udc_free_request,
1279
1280 .queue = bcm63xx_udc_queue,
1281 .dequeue = bcm63xx_udc_dequeue,
1282
1283 .set_halt = bcm63xx_udc_set_halt,
1284 .set_wedge = bcm63xx_udc_set_wedge,
1285};
1286
1287/***********************************************************************
1288 * EP0 handling
1289 ***********************************************************************/
1290
1291/**
1292 * bcm63xx_ep0_setup_callback - Drop spinlock to invoke ->setup callback.
1293 * @udc: Reference to the device controller.
1294 * @ctrl: 8-byte SETUP request.
1295 */
1296static int bcm63xx_ep0_setup_callback(struct bcm63xx_udc *udc,
1297 struct usb_ctrlrequest *ctrl)
1298{
1299 int rc;
1300
1301 spin_unlock_irq(&udc->lock);
1302 rc = udc->driver->setup(&udc->gadget, ctrl);
1303 spin_lock_irq(&udc->lock);
1304 return rc;
1305}
1306
1307/**
1308 * bcm63xx_ep0_spoof_set_cfg - Synthesize a SET_CONFIGURATION request.
1309 * @udc: Reference to the device controller.
1310 *
1311 * Many standard requests are handled automatically in the hardware, but
1312 * we still need to pass them to the gadget driver so that it can
1313 * reconfigure the interfaces/endpoints if necessary.
1314 *
1315 * Unfortunately we are not able to send a STALL response if the host
1316 * requests an invalid configuration. If this happens, we'll have to be
1317 * content with printing a warning.
1318 */
1319static int bcm63xx_ep0_spoof_set_cfg(struct bcm63xx_udc *udc)
1320{
1321 struct usb_ctrlrequest ctrl;
1322 int rc;
1323
1324 ctrl.bRequestType = USB_DIR_OUT | USB_RECIP_DEVICE;
1325 ctrl.bRequest = USB_REQ_SET_CONFIGURATION;
1326 ctrl.wValue = cpu_to_le16(udc->cfg);
1327 ctrl.wIndex = 0;
1328 ctrl.wLength = 0;
1329
1330 rc = bcm63xx_ep0_setup_callback(udc, &ctrl);
1331 if (rc < 0) {
1332 dev_warn_ratelimited(udc->dev,
1333 "hardware auto-acked bad SET_CONFIGURATION(%d) request\n",
1334 udc->cfg);
1335 }
1336 return rc;
1337}
1338
1339/**
1340 * bcm63xx_ep0_spoof_set_iface - Synthesize a SET_INTERFACE request.
1341 * @udc: Reference to the device controller.
1342 */
1343static int bcm63xx_ep0_spoof_set_iface(struct bcm63xx_udc *udc)
1344{
1345 struct usb_ctrlrequest ctrl;
1346 int rc;
1347
1348 ctrl.bRequestType = USB_DIR_OUT | USB_RECIP_INTERFACE;
1349 ctrl.bRequest = USB_REQ_SET_INTERFACE;
1350 ctrl.wValue = cpu_to_le16(udc->alt_iface);
1351 ctrl.wIndex = cpu_to_le16(udc->iface);
1352 ctrl.wLength = 0;
1353
1354 rc = bcm63xx_ep0_setup_callback(udc, &ctrl);
1355 if (rc < 0) {
1356 dev_warn_ratelimited(udc->dev,
1357 "hardware auto-acked bad SET_INTERFACE(%d,%d) request\n",
1358 udc->iface, udc->alt_iface);
1359 }
1360 return rc;
1361}
1362
1363/**
1364 * bcm63xx_ep0_map_write - dma_map and iudma_write a single request.
1365 * @udc: Reference to the device controller.
1366 * @ch_idx: IUDMA channel number.
1367 * @req: USB gadget layer representation of the request.
1368 */
1369static void bcm63xx_ep0_map_write(struct bcm63xx_udc *udc, int ch_idx,
1370 struct usb_request *req)
1371{
1372 struct bcm63xx_req *breq = our_req(req);
1373 struct iudma_ch *iudma = &udc->iudma[ch_idx];
1374
1375 BUG_ON(udc->ep0_request);
1376 udc->ep0_request = req;
1377
1378 req->actual = 0;
1379 breq->offset = 0;
1380 usb_gadget_map_request(&udc->gadget, req, iudma->is_tx);
1381 iudma_write(udc, iudma, breq);
1382}
1383
1384/**
1385 * bcm63xx_ep0_complete - Set completion status and "stage" the callback.
1386 * @udc: Reference to the device controller.
1387 * @req: USB gadget layer representation of the request.
1388 * @status: Status to return to the gadget driver.
1389 */
1390static void bcm63xx_ep0_complete(struct bcm63xx_udc *udc,
1391 struct usb_request *req, int status)
1392{
1393 req->status = status;
1394 if (status)
1395 req->actual = 0;
1396 if (req->complete) {
1397 spin_unlock_irq(&udc->lock);
1398 req->complete(&udc->bep[0].ep, req);
1399 spin_lock_irq(&udc->lock);
1400 }
1401}
1402
1403/**
1404 * bcm63xx_ep0_nuke_reply - Abort request from the gadget driver due to
1405 * reset/shutdown.
1406 * @udc: Reference to the device controller.
1407 * @is_tx: Nonzero for TX (IN), zero for RX (OUT).
1408 */
1409static void bcm63xx_ep0_nuke_reply(struct bcm63xx_udc *udc, int is_tx)
1410{
1411 struct usb_request *req = udc->ep0_reply;
1412
1413 udc->ep0_reply = NULL;
1414 usb_gadget_unmap_request(&udc->gadget, req, is_tx);
1415 if (udc->ep0_request == req) {
1416 udc->ep0_req_completed = 0;
1417 udc->ep0_request = NULL;
1418 }
1419 bcm63xx_ep0_complete(udc, req, -ESHUTDOWN);
1420}
1421
1422/**
1423 * bcm63xx_ep0_read_complete - Close out the pending ep0 request; return
1424 * transfer len.
1425 * @udc: Reference to the device controller.
1426 */
1427static int bcm63xx_ep0_read_complete(struct bcm63xx_udc *udc)
1428{
1429 struct usb_request *req = udc->ep0_request;
1430
1431 udc->ep0_req_completed = 0;
1432 udc->ep0_request = NULL;
1433
1434 return req->actual;
1435}
1436
1437/**
1438 * bcm63xx_ep0_internal_request - Helper function to submit an ep0 request.
1439 * @udc: Reference to the device controller.
1440 * @ch_idx: IUDMA channel number.
1441 * @length: Number of bytes to TX/RX.
1442 *
1443 * Used for simple transfers performed by the ep0 worker. This will always
1444 * use ep0_ctrl_req / ep0_ctrl_buf.
1445 */
1446static void bcm63xx_ep0_internal_request(struct bcm63xx_udc *udc, int ch_idx,
1447 int length)
1448{
1449 struct usb_request *req = &udc->ep0_ctrl_req.req;
1450
1451 req->buf = udc->ep0_ctrl_buf;
1452 req->length = length;
1453 req->complete = NULL;
1454
1455 bcm63xx_ep0_map_write(udc, ch_idx, req);
1456}
1457
1458/**
1459 * bcm63xx_ep0_do_setup - Parse new SETUP packet and decide how to handle it.
1460 * @udc: Reference to the device controller.
1461 *
1462 * EP0_IDLE probably shouldn't ever happen. EP0_REQUEUE means we're ready
1463 * for the next packet. Anything else means the transaction requires multiple
1464 * stages of handling.
1465 */
1466static enum bcm63xx_ep0_state bcm63xx_ep0_do_setup(struct bcm63xx_udc *udc)
1467{
1468 int rc;
1469 struct usb_ctrlrequest *ctrl = (void *)udc->ep0_ctrl_buf;
1470
1471 rc = bcm63xx_ep0_read_complete(udc);
1472
1473 if (rc < 0) {
1474 dev_err(udc->dev, "missing SETUP packet\n");
1475 return EP0_IDLE;
1476 }
1477
1478 /*
1479 * Handle 0-byte IN STATUS acknowledgement. The hardware doesn't
1480 * ALWAYS deliver these 100% of the time, so if we happen to see one,
1481 * just throw it away.
1482 */
1483 if (rc == 0)
1484 return EP0_REQUEUE;
1485
1486 /* Drop malformed SETUP packets */
1487 if (rc != sizeof(*ctrl)) {
1488 dev_warn_ratelimited(udc->dev,
1489 "malformed SETUP packet (%d bytes)\n", rc);
1490 return EP0_REQUEUE;
1491 }
1492
1493 /* Process new SETUP packet arriving on ep0 */
1494 rc = bcm63xx_ep0_setup_callback(udc, ctrl);
1495 if (rc < 0) {
1496 bcm63xx_set_stall(udc, &udc->bep[0], true);
1497 return EP0_REQUEUE;
1498 }
1499
1500 if (!ctrl->wLength)
1501 return EP0_REQUEUE;
1502 else if (ctrl->bRequestType & USB_DIR_IN)
1503 return EP0_IN_DATA_PHASE_SETUP;
1504 else
1505 return EP0_OUT_DATA_PHASE_SETUP;
1506}
1507
1508/**
1509 * bcm63xx_ep0_do_idle - Check for outstanding requests if ep0 is idle.
1510 * @udc: Reference to the device controller.
1511 *
1512 * In state EP0_IDLE, the RX descriptor is either pending, or has been
1513 * filled with a SETUP packet from the host. This function handles new
1514 * SETUP packets, control IRQ events (which can generate fake SETUP packets),
1515 * and reset/shutdown events.
1516 *
1517 * Returns 0 if work was done; -EAGAIN if nothing to do.
1518 */
1519static int bcm63xx_ep0_do_idle(struct bcm63xx_udc *udc)
1520{
1521 if (udc->ep0_req_reset) {
1522 udc->ep0_req_reset = 0;
1523 } else if (udc->ep0_req_set_cfg) {
1524 udc->ep0_req_set_cfg = 0;
1525 if (bcm63xx_ep0_spoof_set_cfg(udc) >= 0)
1526 udc->ep0state = EP0_IN_FAKE_STATUS_PHASE;
1527 } else if (udc->ep0_req_set_iface) {
1528 udc->ep0_req_set_iface = 0;
1529 if (bcm63xx_ep0_spoof_set_iface(udc) >= 0)
1530 udc->ep0state = EP0_IN_FAKE_STATUS_PHASE;
1531 } else if (udc->ep0_req_completed) {
1532 udc->ep0state = bcm63xx_ep0_do_setup(udc);
1533 return udc->ep0state == EP0_IDLE ? -EAGAIN : 0;
1534 } else if (udc->ep0_req_shutdown) {
1535 udc->ep0_req_shutdown = 0;
1536 udc->ep0_req_completed = 0;
1537 udc->ep0_request = NULL;
1538 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_RXCHAN]);
1539 usb_gadget_unmap_request(&udc->gadget,
1540 &udc->ep0_ctrl_req.req, 0);
1541
1542 /* bcm63xx_udc_pullup() is waiting for this */
1543 mb();
1544 udc->ep0state = EP0_SHUTDOWN;
1545 } else if (udc->ep0_reply) {
1546 /*
1547 * This could happen if a USB RESET shows up during an ep0
1548 * transaction (especially if a laggy driver like gadgetfs
1549 * is in use).
1550 */
1551 dev_warn(udc->dev, "nuking unexpected reply\n");
1552 bcm63xx_ep0_nuke_reply(udc, 0);
1553 } else {
1554 return -EAGAIN;
1555 }
1556
1557 return 0;
1558}
1559
1560/**
1561 * bcm63xx_ep0_one_round - Handle the current ep0 state.
1562 * @udc: Reference to the device controller.
1563 *
1564 * Returns 0 if work was done; -EAGAIN if nothing to do.
1565 */
1566static int bcm63xx_ep0_one_round(struct bcm63xx_udc *udc)
1567{
1568 enum bcm63xx_ep0_state ep0state = udc->ep0state;
1569 bool shutdown = udc->ep0_req_reset || udc->ep0_req_shutdown;
1570
1571 switch (udc->ep0state) {
1572 case EP0_REQUEUE:
1573 /* set up descriptor to receive SETUP packet */
1574 bcm63xx_ep0_internal_request(udc, IUDMA_EP0_RXCHAN,
1575 BCM63XX_MAX_CTRL_PKT);
1576 ep0state = EP0_IDLE;
1577 break;
1578 case EP0_IDLE:
1579 return bcm63xx_ep0_do_idle(udc);
1580 case EP0_IN_DATA_PHASE_SETUP:
1581 /*
1582 * Normal case: TX request is in ep0_reply (queued by the
1583 * callback), or will be queued shortly. When it's here,
1584 * send it to the HW and go to EP0_IN_DATA_PHASE_COMPLETE.
1585 *
1586 * Shutdown case: Stop waiting for the reply. Just
1587 * REQUEUE->IDLE. The gadget driver is NOT expected to
1588 * queue anything else now.
1589 */
1590 if (udc->ep0_reply) {
1591 bcm63xx_ep0_map_write(udc, IUDMA_EP0_TXCHAN,
1592 udc->ep0_reply);
1593 ep0state = EP0_IN_DATA_PHASE_COMPLETE;
1594 } else if (shutdown) {
1595 ep0state = EP0_REQUEUE;
1596 }
1597 break;
1598 case EP0_IN_DATA_PHASE_COMPLETE: {
1599 /*
1600 * Normal case: TX packet (ep0_reply) is in flight; wait for
1601 * it to finish, then go back to REQUEUE->IDLE.
1602 *
1603 * Shutdown case: Reset the TX channel, send -ESHUTDOWN
1604 * completion to the gadget driver, then REQUEUE->IDLE.
1605 */
1606 if (udc->ep0_req_completed) {
1607 udc->ep0_reply = NULL;
1608 bcm63xx_ep0_read_complete(udc);
1609 /*
1610 * the "ack" sometimes gets eaten (see
1611 * bcm63xx_ep0_do_idle)
1612 */
1613 ep0state = EP0_REQUEUE;
1614 } else if (shutdown) {
1615 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_TXCHAN]);
1616 bcm63xx_ep0_nuke_reply(udc, 1);
1617 ep0state = EP0_REQUEUE;
1618 }
1619 break;
1620 }
1621 case EP0_OUT_DATA_PHASE_SETUP:
1622 /* Similar behavior to EP0_IN_DATA_PHASE_SETUP */
1623 if (udc->ep0_reply) {
1624 bcm63xx_ep0_map_write(udc, IUDMA_EP0_RXCHAN,
1625 udc->ep0_reply);
1626 ep0state = EP0_OUT_DATA_PHASE_COMPLETE;
1627 } else if (shutdown) {
1628 ep0state = EP0_REQUEUE;
1629 }
1630 break;
1631 case EP0_OUT_DATA_PHASE_COMPLETE: {
1632 /* Similar behavior to EP0_IN_DATA_PHASE_COMPLETE */
1633 if (udc->ep0_req_completed) {
1634 udc->ep0_reply = NULL;
1635 bcm63xx_ep0_read_complete(udc);
1636
1637 /* send 0-byte ack to host */
1638 bcm63xx_ep0_internal_request(udc, IUDMA_EP0_TXCHAN, 0);
1639 ep0state = EP0_OUT_STATUS_PHASE;
1640 } else if (shutdown) {
1641 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_RXCHAN]);
1642 bcm63xx_ep0_nuke_reply(udc, 0);
1643 ep0state = EP0_REQUEUE;
1644 }
1645 break;
1646 }
1647 case EP0_OUT_STATUS_PHASE:
1648 /*
1649 * Normal case: 0-byte OUT ack packet is in flight; wait
1650 * for it to finish, then go back to REQUEUE->IDLE.
1651 *
1652 * Shutdown case: just cancel the transmission. Don't bother
1653 * calling the completion, because it originated from this
1654 * function anyway. Then go back to REQUEUE->IDLE.
1655 */
1656 if (udc->ep0_req_completed) {
1657 bcm63xx_ep0_read_complete(udc);
1658 ep0state = EP0_REQUEUE;
1659 } else if (shutdown) {
1660 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_TXCHAN]);
1661 udc->ep0_request = NULL;
1662 ep0state = EP0_REQUEUE;
1663 }
1664 break;
1665 case EP0_IN_FAKE_STATUS_PHASE: {
1666 /*
1667 * Normal case: we spoofed a SETUP packet and are now
1668 * waiting for the gadget driver to send a 0-byte reply.
1669 * This doesn't actually get sent to the HW because the
1670 * HW has already sent its own reply. Once we get the
1671 * response, return to IDLE.
1672 *
1673 * Shutdown case: return to IDLE immediately.
1674 *
1675 * Note that the ep0 RX descriptor has remained queued
1676 * (and possibly unfilled) during this entire transaction.
1677 * The HW datapath (IUDMA) never even sees SET_CONFIGURATION
1678 * or SET_INTERFACE transactions.
1679 */
1680 struct usb_request *r = udc->ep0_reply;
1681
1682 if (!r) {
1683 if (shutdown)
1684 ep0state = EP0_IDLE;
1685 break;
1686 }
1687
1688 bcm63xx_ep0_complete(udc, r, 0);
1689 udc->ep0_reply = NULL;
1690 ep0state = EP0_IDLE;
1691 break;
1692 }
1693 case EP0_SHUTDOWN:
1694 break;
1695 }
1696
1697 if (udc->ep0state == ep0state)
1698 return -EAGAIN;
1699
1700 udc->ep0state = ep0state;
1701 return 0;
1702}
1703
1704/**
1705 * bcm63xx_ep0_process - ep0 worker thread / state machine.
1706 * @w: Workqueue struct.
1707 *
1708 * bcm63xx_ep0_process is triggered any time an event occurs on ep0. It
1709 * is used to synchronize ep0 events and ensure that both HW and SW events
1710 * occur in a well-defined order. When the ep0 IUDMA queues are idle, it may
1711 * synthesize SET_CONFIGURATION / SET_INTERFACE requests that were consumed
1712 * by the USBD hardware.
1713 *
1714 * The worker function will continue iterating around the state machine
1715 * until there is nothing left to do. Usually "nothing left to do" means
1716 * that we're waiting for a new event from the hardware.
1717 */
1718static void bcm63xx_ep0_process(struct work_struct *w)
1719{
1720 struct bcm63xx_udc *udc = container_of(w, struct bcm63xx_udc, ep0_wq);
1721 spin_lock_irq(&udc->lock);
1722 while (bcm63xx_ep0_one_round(udc) == 0)
1723 ;
1724 spin_unlock_irq(&udc->lock);
1725}
1726
1727/***********************************************************************
1728 * Standard UDC gadget operations
1729 ***********************************************************************/
1730
1731/**
1732 * bcm63xx_udc_get_frame - Read current SOF frame number from the HW.
1733 * @gadget: USB slave device.
1734 */
1735static int bcm63xx_udc_get_frame(struct usb_gadget *gadget)
1736{
1737 struct bcm63xx_udc *udc = gadget_to_udc(gadget);
1738
1739 return (usbd_readl(udc, USBD_STATUS_REG) &
1740 USBD_STATUS_SOF_MASK) >> USBD_STATUS_SOF_SHIFT;
1741}
1742
1743/**
1744 * bcm63xx_udc_pullup - Enable/disable pullup on D+ line.
1745 * @gadget: USB slave device.
1746 * @is_on: 0 to disable pullup, 1 to enable.
1747 *
1748 * See notes in bcm63xx_select_pullup().
1749 */
1750static int bcm63xx_udc_pullup(struct usb_gadget *gadget, int is_on)
1751{
1752 struct bcm63xx_udc *udc = gadget_to_udc(gadget);
1753 unsigned long flags;
1754 int i, rc = -EINVAL;
1755
1756 spin_lock_irqsave(&udc->lock, flags);
1757 if (is_on && udc->ep0state == EP0_SHUTDOWN) {
1758 udc->gadget.speed = USB_SPEED_UNKNOWN;
1759 udc->ep0state = EP0_REQUEUE;
1760 bcm63xx_fifo_setup(udc);
1761 bcm63xx_fifo_reset(udc);
1762 bcm63xx_ep_setup(udc);
1763
1764 bitmap_zero(&udc->wedgemap, BCM63XX_NUM_EP);
1765 for (i = 0; i < BCM63XX_NUM_EP; i++)
1766 bcm63xx_set_stall(udc, &udc->bep[i], false);
1767
1768 bcm63xx_set_ctrl_irqs(udc, true);
1769 bcm63xx_select_pullup(gadget_to_udc(gadget), true);
1770 rc = 0;
1771 } else if (!is_on && udc->ep0state != EP0_SHUTDOWN) {
1772 bcm63xx_select_pullup(gadget_to_udc(gadget), false);
1773
1774 udc->ep0_req_shutdown = 1;
1775 spin_unlock_irqrestore(&udc->lock, flags);
1776
1777 while (1) {
1778 schedule_work(&udc->ep0_wq);
1779 if (udc->ep0state == EP0_SHUTDOWN)
1780 break;
1781 msleep(50);
1782 }
1783 bcm63xx_set_ctrl_irqs(udc, false);
1784 cancel_work_sync(&udc->ep0_wq);
1785 return 0;
1786 }
1787
1788 spin_unlock_irqrestore(&udc->lock, flags);
1789 return rc;
1790}
1791
1792/**
1793 * bcm63xx_udc_start - Start the controller.
1794 * @gadget: USB slave device.
1795 * @driver: Driver for USB slave devices.
1796 */
1797static int bcm63xx_udc_start(struct usb_gadget *gadget,
1798 struct usb_gadget_driver *driver)
1799{
1800 struct bcm63xx_udc *udc = gadget_to_udc(gadget);
1801 unsigned long flags;
1802
1803 if (!driver || driver->max_speed < USB_SPEED_HIGH ||
1804 !driver->setup)
1805 return -EINVAL;
1806 if (!udc)
1807 return -ENODEV;
1808 if (udc->driver)
1809 return -EBUSY;
1810
1811 spin_lock_irqsave(&udc->lock, flags);
1812
1813 set_clocks(udc, true);
1814 bcm63xx_fifo_setup(udc);
1815 bcm63xx_ep_init(udc);
1816 bcm63xx_ep_setup(udc);
1817 bcm63xx_fifo_reset(udc);
1818 bcm63xx_select_phy_mode(udc, true);
1819
1820 udc->driver = driver;
1821 driver->driver.bus = NULL;
1822 udc->gadget.dev.driver = &driver->driver;
1823 udc->gadget.dev.of_node = udc->dev->of_node;
1824
1825 spin_unlock_irqrestore(&udc->lock, flags);
1826
1827 return 0;
1828}
1829
1830/**
1831 * bcm63xx_udc_stop - Shut down the controller.
1832 * @gadget: USB slave device.
1833 * @driver: Driver for USB slave devices.
1834 */
1835static int bcm63xx_udc_stop(struct usb_gadget *gadget,
1836 struct usb_gadget_driver *driver)
1837{
1838 struct bcm63xx_udc *udc = gadget_to_udc(gadget);
1839 unsigned long flags;
1840
1841 spin_lock_irqsave(&udc->lock, flags);
1842
1843 udc->driver = NULL;
1844 udc->gadget.dev.driver = NULL;
1845
1846 /*
1847 * If we switch the PHY too abruptly after dropping D+, the host
1848 * will often complain:
1849 *
1850 * hub 1-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
1851 */
1852 msleep(100);
1853
1854 bcm63xx_select_phy_mode(udc, false);
1855 set_clocks(udc, false);
1856
1857 spin_unlock_irqrestore(&udc->lock, flags);
1858
1859 return 0;
1860}
1861
1862static const struct usb_gadget_ops bcm63xx_udc_ops = {
1863 .get_frame = bcm63xx_udc_get_frame,
1864 .pullup = bcm63xx_udc_pullup,
1865 .udc_start = bcm63xx_udc_start,
1866 .udc_stop = bcm63xx_udc_stop,
1867};
1868
1869/***********************************************************************
1870 * IRQ handling
1871 ***********************************************************************/
1872
1873/**
1874 * bcm63xx_update_cfg_iface - Read current configuration/interface settings.
1875 * @udc: Reference to the device controller.
1876 *
1877 * This controller intercepts SET_CONFIGURATION and SET_INTERFACE messages.
1878 * The driver never sees the raw control packets coming in on the ep0
1879 * IUDMA channel, but at least we get an interrupt event to tell us that
1880 * new values are waiting in the USBD_STATUS register.
1881 */
1882static void bcm63xx_update_cfg_iface(struct bcm63xx_udc *udc)
1883{
1884 u32 reg = usbd_readl(udc, USBD_STATUS_REG);
1885
1886 udc->cfg = (reg & USBD_STATUS_CFG_MASK) >> USBD_STATUS_CFG_SHIFT;
1887 udc->iface = (reg & USBD_STATUS_INTF_MASK) >> USBD_STATUS_INTF_SHIFT;
1888 udc->alt_iface = (reg & USBD_STATUS_ALTINTF_MASK) >>
1889 USBD_STATUS_ALTINTF_SHIFT;
1890 bcm63xx_ep_setup(udc);
1891}
1892
1893/**
1894 * bcm63xx_update_link_speed - Check to see if the link speed has changed.
1895 * @udc: Reference to the device controller.
1896 *
1897 * The link speed update coincides with a SETUP IRQ. Returns 1 if the
1898 * speed has changed, so that the caller can update the endpoint settings.
1899 */
1900static int bcm63xx_update_link_speed(struct bcm63xx_udc *udc)
1901{
1902 u32 reg = usbd_readl(udc, USBD_STATUS_REG);
1903 enum usb_device_speed oldspeed = udc->gadget.speed;
1904
1905 switch ((reg & USBD_STATUS_SPD_MASK) >> USBD_STATUS_SPD_SHIFT) {
1906 case BCM63XX_SPD_HIGH:
1907 udc->gadget.speed = USB_SPEED_HIGH;
1908 break;
1909 case BCM63XX_SPD_FULL:
1910 udc->gadget.speed = USB_SPEED_FULL;
1911 break;
1912 default:
1913 /* this should never happen */
1914 udc->gadget.speed = USB_SPEED_UNKNOWN;
1915 dev_err(udc->dev,
1916 "received SETUP packet with invalid link speed\n");
1917 return 0;
1918 }
1919
1920 if (udc->gadget.speed != oldspeed) {
1921 dev_info(udc->dev, "link up, %s-speed mode\n",
1922 udc->gadget.speed == USB_SPEED_HIGH ? "high" : "full");
1923 return 1;
1924 } else {
1925 return 0;
1926 }
1927}
1928
1929/**
1930 * bcm63xx_update_wedge - Iterate through wedged endpoints.
1931 * @udc: Reference to the device controller.
1932 * @new_status: true to "refresh" wedge status; false to clear it.
1933 *
1934 * On a SETUP interrupt, we need to manually "refresh" the wedge status
1935 * because the controller hardware is designed to automatically clear
1936 * stalls in response to a CLEAR_FEATURE request from the host.
1937 *
1938 * On a RESET interrupt, we do want to restore all wedged endpoints.
1939 */
1940static void bcm63xx_update_wedge(struct bcm63xx_udc *udc, bool new_status)
1941{
1942 int i;
1943
1944 for_each_set_bit(i, &udc->wedgemap, BCM63XX_NUM_EP) {
1945 bcm63xx_set_stall(udc, &udc->bep[i], new_status);
1946 if (!new_status)
1947 clear_bit(i, &udc->wedgemap);
1948 }
1949}
1950
1951/**
1952 * bcm63xx_udc_ctrl_isr - ISR for control path events (USBD).
1953 * @irq: IRQ number (unused).
1954 * @dev_id: Reference to the device controller.
1955 *
1956 * This is where we handle link (VBUS) down, USB reset, speed changes,
1957 * SET_CONFIGURATION, and SET_INTERFACE events.
1958 */
1959static irqreturn_t bcm63xx_udc_ctrl_isr(int irq, void *dev_id)
1960{
1961 struct bcm63xx_udc *udc = dev_id;
1962 u32 stat;
1963 bool disconnected = false;
1964
1965 stat = usbd_readl(udc, USBD_EVENT_IRQ_STATUS_REG) &
1966 usbd_readl(udc, USBD_EVENT_IRQ_MASK_REG);
1967
1968 usbd_writel(udc, stat, USBD_EVENT_IRQ_STATUS_REG);
1969
1970 spin_lock(&udc->lock);
1971 if (stat & BIT(USBD_EVENT_IRQ_USB_LINK)) {
1972 /* VBUS toggled */
1973
1974 if (!(usbd_readl(udc, USBD_EVENTS_REG) &
1975 USBD_EVENTS_USB_LINK_MASK) &&
1976 udc->gadget.speed != USB_SPEED_UNKNOWN)
1977 dev_info(udc->dev, "link down\n");
1978
1979 udc->gadget.speed = USB_SPEED_UNKNOWN;
1980 disconnected = true;
1981 }
1982 if (stat & BIT(USBD_EVENT_IRQ_USB_RESET)) {
1983 bcm63xx_fifo_setup(udc);
1984 bcm63xx_fifo_reset(udc);
1985 bcm63xx_ep_setup(udc);
1986
1987 bcm63xx_update_wedge(udc, false);
1988
1989 udc->ep0_req_reset = 1;
1990 schedule_work(&udc->ep0_wq);
1991 disconnected = true;
1992 }
1993 if (stat & BIT(USBD_EVENT_IRQ_SETUP)) {
1994 if (bcm63xx_update_link_speed(udc)) {
1995 bcm63xx_fifo_setup(udc);
1996 bcm63xx_ep_setup(udc);
1997 }
1998 bcm63xx_update_wedge(udc, true);
1999 }
2000 if (stat & BIT(USBD_EVENT_IRQ_SETCFG)) {
2001 bcm63xx_update_cfg_iface(udc);
2002 udc->ep0_req_set_cfg = 1;
2003 schedule_work(&udc->ep0_wq);
2004 }
2005 if (stat & BIT(USBD_EVENT_IRQ_SETINTF)) {
2006 bcm63xx_update_cfg_iface(udc);
2007 udc->ep0_req_set_iface = 1;
2008 schedule_work(&udc->ep0_wq);
2009 }
2010 spin_unlock(&udc->lock);
2011
2012 if (disconnected && udc->driver)
2013 udc->driver->disconnect(&udc->gadget);
2014
2015 return IRQ_HANDLED;
2016}
2017
2018/**
2019 * bcm63xx_udc_data_isr - ISR for data path events (IUDMA).
2020 * @irq: IRQ number (unused).
2021 * @dev_id: Reference to the IUDMA channel that generated the interrupt.
2022 *
2023 * For the two ep0 channels, we have special handling that triggers the
2024 * ep0 worker thread. For normal bulk/intr channels, either queue up
2025 * the next buffer descriptor for the transaction (incomplete transaction),
2026 * or invoke the completion callback (complete transactions).
2027 */
2028static irqreturn_t bcm63xx_udc_data_isr(int irq, void *dev_id)
2029{
2030 struct iudma_ch *iudma = dev_id;
2031 struct bcm63xx_udc *udc = iudma->udc;
2032 struct bcm63xx_ep *bep;
2033 struct usb_request *req = NULL;
2034 struct bcm63xx_req *breq = NULL;
2035 int rc;
2036 bool is_done = false;
2037
2038 spin_lock(&udc->lock);
2039
2040 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK,
2041 ENETDMAC_IR_REG(iudma->ch_idx));
2042 bep = iudma->bep;
2043 rc = iudma_read(udc, iudma);
2044
2045 /* special handling for EP0 RX (0) and TX (1) */
2046 if (iudma->ch_idx == IUDMA_EP0_RXCHAN ||
2047 iudma->ch_idx == IUDMA_EP0_TXCHAN) {
2048 req = udc->ep0_request;
2049 breq = our_req(req);
2050
2051 /* a single request could require multiple submissions */
2052 if (rc >= 0) {
2053 req->actual += rc;
2054
2055 if (req->actual >= req->length || breq->bd_bytes > rc) {
2056 udc->ep0_req_completed = 1;
2057 is_done = true;
2058 schedule_work(&udc->ep0_wq);
2059
2060 /* "actual" on a ZLP is 1 byte */
2061 req->actual = min(req->actual, req->length);
2062 } else {
2063 /* queue up the next BD (same request) */
2064 iudma_write(udc, iudma, breq);
2065 }
2066 }
2067 } else if (!list_empty(&bep->queue)) {
2068 breq = list_first_entry(&bep->queue, struct bcm63xx_req, queue);
2069 req = &breq->req;
2070
2071 if (rc >= 0) {
2072 req->actual += rc;
2073
2074 if (req->actual >= req->length || breq->bd_bytes > rc) {
2075 is_done = true;
2076 list_del(&breq->queue);
2077
2078 req->actual = min(req->actual, req->length);
2079
2080 if (!list_empty(&bep->queue)) {
2081 struct bcm63xx_req *next;
2082
2083 next = list_first_entry(&bep->queue,
2084 struct bcm63xx_req, queue);
2085 iudma_write(udc, iudma, next);
2086 }
2087 } else {
2088 iudma_write(udc, iudma, breq);
2089 }
2090 }
2091 }
2092 spin_unlock(&udc->lock);
2093
2094 if (is_done) {
2095 usb_gadget_unmap_request(&udc->gadget, req, iudma->is_tx);
2096 if (req->complete)
2097 req->complete(&bep->ep, req);
2098 }
2099
2100 return IRQ_HANDLED;
2101}
2102
2103/***********************************************************************
2104 * Debug filesystem
2105 ***********************************************************************/
2106
2107/*
2108 * bcm63xx_usbd_dbg_show - Show USBD controller state.
2109 * @s: seq_file to which the information will be written.
2110 * @p: Unused.
2111 *
2112 * This file nominally shows up as /sys/kernel/debug/bcm63xx_udc/usbd
2113 */
2114static int bcm63xx_usbd_dbg_show(struct seq_file *s, void *p)
2115{
2116 struct bcm63xx_udc *udc = s->private;
2117
2118 if (!udc->driver)
2119 return -ENODEV;
2120
2121 seq_printf(s, "ep0 state: %s\n",
2122 bcm63xx_ep0_state_names[udc->ep0state]);
2123 seq_printf(s, " pending requests: %s%s%s%s%s%s%s\n",
2124 udc->ep0_req_reset ? "reset " : "",
2125 udc->ep0_req_set_cfg ? "set_cfg " : "",
2126 udc->ep0_req_set_iface ? "set_iface " : "",
2127 udc->ep0_req_shutdown ? "shutdown " : "",
2128 udc->ep0_request ? "pending " : "",
2129 udc->ep0_req_completed ? "completed " : "",
2130 udc->ep0_reply ? "reply " : "");
2131 seq_printf(s, "cfg: %d; iface: %d; alt_iface: %d\n",
2132 udc->cfg, udc->iface, udc->alt_iface);
2133 seq_printf(s, "regs:\n");
2134 seq_printf(s, " control: %08x; straps: %08x; status: %08x\n",
2135 usbd_readl(udc, USBD_CONTROL_REG),
2136 usbd_readl(udc, USBD_STRAPS_REG),
2137 usbd_readl(udc, USBD_STATUS_REG));
2138 seq_printf(s, " events: %08x; stall: %08x\n",
2139 usbd_readl(udc, USBD_EVENTS_REG),
2140 usbd_readl(udc, USBD_STALL_REG));
2141
2142 return 0;
2143}
2144
2145/*
2146 * bcm63xx_iudma_dbg_show - Show IUDMA status and descriptors.
2147 * @s: seq_file to which the information will be written.
2148 * @p: Unused.
2149 *
2150 * This file nominally shows up as /sys/kernel/debug/bcm63xx_udc/iudma
2151 */
2152static int bcm63xx_iudma_dbg_show(struct seq_file *s, void *p)
2153{
2154 struct bcm63xx_udc *udc = s->private;
2155 int ch_idx, i;
2156 u32 sram2, sram3;
2157
2158 if (!udc->driver)
2159 return -ENODEV;
2160
2161 for (ch_idx = 0; ch_idx < BCM63XX_NUM_IUDMA; ch_idx++) {
2162 struct iudma_ch *iudma = &udc->iudma[ch_idx];
2163 struct list_head *pos;
2164
2165 seq_printf(s, "IUDMA channel %d -- ", ch_idx);
2166 switch (iudma_defaults[ch_idx].ep_type) {
2167 case BCMEP_CTRL:
2168 seq_printf(s, "control");
2169 break;
2170 case BCMEP_BULK:
2171 seq_printf(s, "bulk");
2172 break;
2173 case BCMEP_INTR:
2174 seq_printf(s, "interrupt");
2175 break;
2176 }
2177 seq_printf(s, ch_idx & 0x01 ? " tx" : " rx");
2178 seq_printf(s, " [ep%d]:\n",
2179 max_t(int, iudma_defaults[ch_idx].ep_num, 0));
2180 seq_printf(s, " cfg: %08x; irqstat: %08x; irqmask: %08x; maxburst: %08x\n",
2181 usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG(ch_idx)),
2182 usb_dmac_readl(udc, ENETDMAC_IR_REG(ch_idx)),
2183 usb_dmac_readl(udc, ENETDMAC_IRMASK_REG(ch_idx)),
2184 usb_dmac_readl(udc, ENETDMAC_MAXBURST_REG(ch_idx)));
2185
2186 sram2 = usb_dmas_readl(udc, ENETDMAS_SRAM2_REG(ch_idx));
2187 sram3 = usb_dmas_readl(udc, ENETDMAS_SRAM3_REG(ch_idx));
2188 seq_printf(s, " base: %08x; index: %04x_%04x; desc: %04x_%04x %08x\n",
2189 usb_dmas_readl(udc, ENETDMAS_RSTART_REG(ch_idx)),
2190 sram2 >> 16, sram2 & 0xffff,
2191 sram3 >> 16, sram3 & 0xffff,
2192 usb_dmas_readl(udc, ENETDMAS_SRAM4_REG(ch_idx)));
2193 seq_printf(s, " desc: %d/%d used", iudma->n_bds_used,
2194 iudma->n_bds);
2195
2196 if (iudma->bep) {
2197 i = 0;
2198 list_for_each(pos, &iudma->bep->queue)
2199 i++;
2200 seq_printf(s, "; %d queued\n", i);
2201 } else {
2202 seq_printf(s, "\n");
2203 }
2204
2205 for (i = 0; i < iudma->n_bds; i++) {
2206 struct bcm_enet_desc *d = &iudma->bd_ring[i];
2207
2208 seq_printf(s, " %03x (%02x): len_stat: %04x_%04x; pa %08x",
2209 i * sizeof(*d), i,
2210 d->len_stat >> 16, d->len_stat & 0xffff,
2211 d->address);
2212 if (d == iudma->read_bd)
2213 seq_printf(s, " <<RD");
2214 if (d == iudma->write_bd)
2215 seq_printf(s, " <<WR");
2216 seq_printf(s, "\n");
2217 }
2218
2219 seq_printf(s, "\n");
2220 }
2221
2222 return 0;
2223}
2224
2225static int bcm63xx_usbd_dbg_open(struct inode *inode, struct file *file)
2226{
2227 return single_open(file, bcm63xx_usbd_dbg_show, inode->i_private);
2228}
2229
2230static int bcm63xx_iudma_dbg_open(struct inode *inode, struct file *file)
2231{
2232 return single_open(file, bcm63xx_iudma_dbg_show, inode->i_private);
2233}
2234
2235static const struct file_operations usbd_dbg_fops = {
2236 .owner = THIS_MODULE,
2237 .open = bcm63xx_usbd_dbg_open,
2238 .llseek = seq_lseek,
2239 .read = seq_read,
2240 .release = single_release,
2241};
2242
2243static const struct file_operations iudma_dbg_fops = {
2244 .owner = THIS_MODULE,
2245 .open = bcm63xx_iudma_dbg_open,
2246 .llseek = seq_lseek,
2247 .read = seq_read,
2248 .release = single_release,
2249};
2250
2251
2252/**
2253 * bcm63xx_udc_init_debugfs - Create debugfs entries.
2254 * @udc: Reference to the device controller.
2255 */
2256static void bcm63xx_udc_init_debugfs(struct bcm63xx_udc *udc)
2257{
2258 struct dentry *root, *usbd, *iudma;
2259
2260 if (!IS_ENABLED(CONFIG_USB_GADGET_DEBUG_FS))
2261 return;
2262
2263 root = debugfs_create_dir(udc->gadget.name, NULL);
2264 if (IS_ERR(root) || !root)
2265 goto err_root;
2266
2267 usbd = debugfs_create_file("usbd", 0400, root, udc,
2268 &usbd_dbg_fops);
2269 if (!usbd)
2270 goto err_usbd;
2271 iudma = debugfs_create_file("iudma", 0400, root, udc,
2272 &iudma_dbg_fops);
2273 if (!iudma)
2274 goto err_iudma;
2275
2276 udc->debugfs_root = root;
2277 udc->debugfs_usbd = usbd;
2278 udc->debugfs_iudma = iudma;
2279 return;
2280err_iudma:
2281 debugfs_remove(usbd);
2282err_usbd:
2283 debugfs_remove(root);
2284err_root:
2285 dev_err(udc->dev, "debugfs is not available\n");
2286}
2287
2288/**
2289 * bcm63xx_udc_cleanup_debugfs - Remove debugfs entries.
2290 * @udc: Reference to the device controller.
2291 *
2292 * debugfs_remove() is safe to call with a NULL argument.
2293 */
2294static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc)
2295{
2296 debugfs_remove(udc->debugfs_iudma);
2297 debugfs_remove(udc->debugfs_usbd);
2298 debugfs_remove(udc->debugfs_root);
2299 udc->debugfs_iudma = NULL;
2300 udc->debugfs_usbd = NULL;
2301 udc->debugfs_root = NULL;
2302}
2303
2304/***********************************************************************
2305 * Driver init/exit
2306 ***********************************************************************/
2307
2308/**
2309 * bcm63xx_udc_gadget_release - Called from device_release().
2310 * @dev: Unused.
2311 *
2312 * We get a warning if this function doesn't exist, but it's empty because
2313 * we don't have to free any of the memory allocated with the devm_* APIs.
2314 */
2315static void bcm63xx_udc_gadget_release(struct device *dev)
2316{
2317}
2318
2319/**
2320 * bcm63xx_udc_probe - Initialize a new instance of the UDC.
2321 * @pdev: Platform device struct from the bcm63xx BSP code.
2322 *
2323 * Note that platform data is required, because pd.port_no varies from chip
2324 * to chip and is used to switch the correct USB port to device mode.
2325 */
2326static int __devinit bcm63xx_udc_probe(struct platform_device *pdev)
2327{
2328 struct device *dev = &pdev->dev;
2329 struct bcm63xx_usbd_platform_data *pd = dev->platform_data;
2330 struct bcm63xx_udc *udc;
2331 struct resource *res;
2332 int rc = -ENOMEM, i, irq;
2333
2334 udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL);
2335 if (!udc) {
2336 dev_err(dev, "cannot allocate memory\n");
2337 return -ENOMEM;
2338 }
2339
2340 platform_set_drvdata(pdev, udc);
2341 udc->dev = dev;
2342 udc->pd = pd;
2343
2344 if (!pd) {
2345 dev_err(dev, "missing platform data\n");
2346 return -EINVAL;
2347 }
2348
2349 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2350 if (!res) {
2351 dev_err(dev, "error finding USBD resource\n");
2352 return -ENXIO;
2353 }
2354 udc->usbd_regs = devm_request_and_ioremap(dev, res);
2355
2356 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2357 if (!res) {
2358 dev_err(dev, "error finding IUDMA resource\n");
2359 return -ENXIO;
2360 }
2361 udc->iudma_regs = devm_request_and_ioremap(dev, res);
2362
2363 if (!udc->usbd_regs || !udc->iudma_regs) {
2364 dev_err(dev, "error requesting resources\n");
2365 return -ENXIO;
2366 }
2367
2368 spin_lock_init(&udc->lock);
2369 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process);
2370 dev_set_name(&udc->gadget.dev, "gadget");
2371
2372 udc->gadget.ops = &bcm63xx_udc_ops;
2373 udc->gadget.name = dev_name(dev);
2374 udc->gadget.dev.parent = dev;
2375 udc->gadget.dev.release = bcm63xx_udc_gadget_release;
2376 udc->gadget.dev.dma_mask = dev->dma_mask;
2377
2378 if (!pd->use_fullspeed && !use_fullspeed)
2379 udc->gadget.max_speed = USB_SPEED_HIGH;
2380 else
2381 udc->gadget.max_speed = USB_SPEED_FULL;
2382
2383 /* request clocks, allocate buffers, and clear any pending IRQs */
2384 rc = bcm63xx_init_udc_hw(udc);
2385 if (rc)
2386 return rc;
2387
2388 rc = -ENXIO;
2389
2390 /* IRQ resource #0: control interrupt (VBUS, speed, etc.) */
2391 irq = platform_get_irq(pdev, 0);
2392 if (irq < 0) {
2393 dev_err(dev, "missing IRQ resource #0\n");
2394 goto out_uninit;
2395 }
2396 if (devm_request_irq(dev, irq, &bcm63xx_udc_ctrl_isr, 0,
2397 dev_name(dev), udc) < 0) {
2398 dev_err(dev, "error requesting IRQ #%d\n", irq);
2399 goto out_uninit;
2400 }
2401
2402 /* IRQ resources #1-6: data interrupts for IUDMA channels 0-5 */
2403 for (i = 0; i < BCM63XX_NUM_IUDMA; i++) {
2404 irq = platform_get_irq(pdev, i + 1);
2405 if (irq < 0) {
2406 dev_err(dev, "missing IRQ resource #%d\n", i + 1);
2407 goto out_uninit;
2408 }
2409 if (devm_request_irq(dev, irq, &bcm63xx_udc_data_isr, 0,
2410 dev_name(dev), &udc->iudma[i]) < 0) {
2411 dev_err(dev, "error requesting IRQ #%d\n", irq);
2412 goto out_uninit;
2413 }
2414 }
2415
2416 rc = device_register(&udc->gadget.dev);
2417 if (rc)
2418 goto out_uninit;
2419
2420 bcm63xx_udc_init_debugfs(udc);
2421 rc = usb_add_gadget_udc(dev, &udc->gadget);
2422 if (!rc)
2423 return 0;
2424
2425 bcm63xx_udc_cleanup_debugfs(udc);
2426 device_unregister(&udc->gadget.dev);
2427out_uninit:
2428 bcm63xx_uninit_udc_hw(udc);
2429 return rc;
2430}
2431
2432/**
2433 * bcm63xx_udc_remove - Remove the device from the system.
2434 * @pdev: Platform device struct from the bcm63xx BSP code.
2435 */
2436static int __devexit bcm63xx_udc_remove(struct platform_device *pdev)
2437{
2438 struct bcm63xx_udc *udc = platform_get_drvdata(pdev);
2439
2440 bcm63xx_udc_cleanup_debugfs(udc);
2441 usb_del_gadget_udc(&udc->gadget);
2442 device_unregister(&udc->gadget.dev);
2443 BUG_ON(udc->driver);
2444
2445 platform_set_drvdata(pdev, NULL);
2446 bcm63xx_uninit_udc_hw(udc);
2447
2448 return 0;
2449}
2450
2451static struct platform_driver bcm63xx_udc_driver = {
2452 .probe = bcm63xx_udc_probe,
2453 .remove = __devexit_p(bcm63xx_udc_remove),
2454 .driver = {
2455 .name = DRV_MODULE_NAME,
2456 .owner = THIS_MODULE,
2457 },
2458};
2459module_platform_driver(bcm63xx_udc_driver);
2460
2461MODULE_DESCRIPTION("BCM63xx USB Peripheral Controller");
2462MODULE_AUTHOR("Kevin Cernekee <cernekee@gmail.com>");
2463MODULE_LICENSE("GPL");
2464MODULE_ALIAS("platform:" DRV_MODULE_NAME);
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 725550f06fab..1e4bb77f00bb 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -11,7 +11,6 @@
11 */ 11 */
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/utsname.h>
15#include <linux/module.h> 14#include <linux/module.h>
16 15
17#include "u_ether.h" 16#include "u_ether.h"
@@ -34,6 +33,7 @@
34#define CDC_PRODUCT_NUM 0xa4aa /* CDC Composite: ECM + ACM */ 33#define CDC_PRODUCT_NUM 0xa4aa /* CDC Composite: ECM + ACM */
35 34
36/*-------------------------------------------------------------------------*/ 35/*-------------------------------------------------------------------------*/
36USB_GADGET_COMPOSITE_OPTIONS();
37 37
38/* 38/*
39 * Kbuild is not very cooperative with respect to linking separately 39 * Kbuild is not very cooperative with respect to linking separately
@@ -43,10 +43,6 @@
43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
44 */ 44 */
45 45
46#include "composite.c"
47#include "usbstring.c"
48#include "config.c"
49#include "epautoconf.c"
50#include "u_serial.c" 46#include "u_serial.c"
51#include "f_acm.c" 47#include "f_acm.c"
52#include "f_ecm.c" 48#include "f_ecm.c"
@@ -92,15 +88,10 @@ static const struct usb_descriptor_header *otg_desc[] = {
92 88
93 89
94/* string IDs are assigned dynamically */ 90/* string IDs are assigned dynamically */
95
96#define STRING_MANUFACTURER_IDX 0
97#define STRING_PRODUCT_IDX 1
98
99static char manufacturer[50];
100
101static struct usb_string strings_dev[] = { 91static struct usb_string strings_dev[] = {
102 [STRING_MANUFACTURER_IDX].s = manufacturer, 92 [USB_GADGET_MANUFACTURER_IDX].s = "",
103 [STRING_PRODUCT_IDX].s = DRIVER_DESC, 93 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
94 [USB_GADGET_SERIAL_IDX].s = "",
104 { } /* end of list */ 95 { } /* end of list */
105}; 96};
106 97
@@ -152,7 +143,6 @@ static struct usb_configuration cdc_config_driver = {
152 143
153static int __init cdc_bind(struct usb_composite_dev *cdev) 144static int __init cdc_bind(struct usb_composite_dev *cdev)
154{ 145{
155 int gcnum;
156 struct usb_gadget *gadget = cdev->gadget; 146 struct usb_gadget *gadget = cdev->gadget;
157 int status; 147 int status;
158 148
@@ -172,47 +162,22 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
172 if (status < 0) 162 if (status < 0)
173 goto fail0; 163 goto fail0;
174 164
175 gcnum = usb_gadget_controller_number(gadget);
176 if (gcnum >= 0)
177 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
178 else {
179 /* We assume that can_support_ecm() tells the truth;
180 * but if the controller isn't recognized at all then
181 * that assumption is a bit more likely to be wrong.
182 */
183 WARNING(cdev, "controller '%s' not recognized; trying %s\n",
184 gadget->name,
185 cdc_config_driver.label);
186 device_desc.bcdDevice =
187 cpu_to_le16(0x0300 | 0x0099);
188 }
189
190
191 /* Allocate string descriptor numbers ... note that string 165 /* Allocate string descriptor numbers ... note that string
192 * contents can be overridden by the composite_dev glue. 166 * contents can be overridden by the composite_dev glue.
193 */ 167 */
194 168
195 /* device descriptor strings: manufacturer, product */ 169 status = usb_string_ids_tab(cdev, strings_dev);
196 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
197 init_utsname()->sysname, init_utsname()->release,
198 gadget->name);
199 status = usb_string_id(cdev);
200 if (status < 0)
201 goto fail1;
202 strings_dev[STRING_MANUFACTURER_IDX].id = status;
203 device_desc.iManufacturer = status;
204
205 status = usb_string_id(cdev);
206 if (status < 0) 170 if (status < 0)
207 goto fail1; 171 goto fail1;
208 strings_dev[STRING_PRODUCT_IDX].id = status; 172 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
209 device_desc.iProduct = status; 173 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
210 174
211 /* register our configuration */ 175 /* register our configuration */
212 status = usb_add_config(cdev, &cdc_config_driver, cdc_do_config); 176 status = usb_add_config(cdev, &cdc_config_driver, cdc_do_config);
213 if (status < 0) 177 if (status < 0)
214 goto fail1; 178 goto fail1;
215 179
180 usb_composite_overwrite_options(cdev, &coverwrite);
216 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 181 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
217 DRIVER_DESC); 182 DRIVER_DESC);
218 183
@@ -232,11 +197,12 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
232 return 0; 197 return 0;
233} 198}
234 199
235static struct usb_composite_driver cdc_driver = { 200static __refdata struct usb_composite_driver cdc_driver = {
236 .name = "g_cdc", 201 .name = "g_cdc",
237 .dev = &device_desc, 202 .dev = &device_desc,
238 .strings = dev_strings, 203 .strings = dev_strings,
239 .max_speed = USB_SPEED_HIGH, 204 .max_speed = USB_SPEED_HIGH,
205 .bind = cdc_bind,
240 .unbind = __exit_p(cdc_unbind), 206 .unbind = __exit_p(cdc_unbind),
241}; 207};
242 208
@@ -246,7 +212,7 @@ MODULE_LICENSE("GPL");
246 212
247static int __init init(void) 213static int __init init(void)
248{ 214{
249 return usb_composite_probe(&cdc_driver, cdc_bind); 215 return usb_composite_probe(&cdc_driver);
250} 216}
251module_init(init); 217module_init(init);
252 218
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 3f72110da1b0..957f973dd96a 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -28,44 +28,6 @@
28 * with the relevant device-wide data. 28 * with the relevant device-wide data.
29 */ 29 */
30 30
31/* big enough to hold our biggest descriptor */
32#define USB_BUFSIZ 1024
33
34static struct usb_composite_driver *composite;
35static int (*composite_gadget_bind)(struct usb_composite_dev *cdev);
36
37/* Some systems will need runtime overrides for the product identifiers
38 * published in the device descriptor, either numbers or strings or both.
39 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
40 */
41
42static ushort idVendor;
43module_param(idVendor, ushort, 0644);
44MODULE_PARM_DESC(idVendor, "USB Vendor ID");
45
46static ushort idProduct;
47module_param(idProduct, ushort, 0644);
48MODULE_PARM_DESC(idProduct, "USB Product ID");
49
50static ushort bcdDevice;
51module_param(bcdDevice, ushort, 0644);
52MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
53
54static char *iManufacturer;
55module_param(iManufacturer, charp, 0644);
56MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
57
58static char *iProduct;
59module_param(iProduct, charp, 0644);
60MODULE_PARM_DESC(iProduct, "USB Product string");
61
62static char *iSerialNumber;
63module_param(iSerialNumber, charp, 0644);
64MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
65
66static char composite_manufacturer[50];
67
68/*-------------------------------------------------------------------------*/
69/** 31/**
70 * next_ep_desc() - advance to the next EP descriptor 32 * next_ep_desc() - advance to the next EP descriptor
71 * @t: currect pointer within descriptor array 33 * @t: currect pointer within descriptor array
@@ -192,6 +154,7 @@ ep_found:
192 } 154 }
193 return 0; 155 return 0;
194} 156}
157EXPORT_SYMBOL_GPL(config_ep_by_speed);
195 158
196/** 159/**
197 * usb_add_function() - add a function to a configuration 160 * usb_add_function() - add a function to a configuration
@@ -250,6 +213,7 @@ done:
250 function->name, function, value); 213 function->name, function, value);
251 return value; 214 return value;
252} 215}
216EXPORT_SYMBOL_GPL(usb_add_function);
253 217
254/** 218/**
255 * usb_function_deactivate - prevent function and gadget enumeration 219 * usb_function_deactivate - prevent function and gadget enumeration
@@ -286,6 +250,7 @@ int usb_function_deactivate(struct usb_function *function)
286 spin_unlock_irqrestore(&cdev->lock, flags); 250 spin_unlock_irqrestore(&cdev->lock, flags);
287 return status; 251 return status;
288} 252}
253EXPORT_SYMBOL_GPL(usb_function_deactivate);
289 254
290/** 255/**
291 * usb_function_activate - allow function and gadget enumeration 256 * usb_function_activate - allow function and gadget enumeration
@@ -300,9 +265,10 @@ int usb_function_deactivate(struct usb_function *function)
300int usb_function_activate(struct usb_function *function) 265int usb_function_activate(struct usb_function *function)
301{ 266{
302 struct usb_composite_dev *cdev = function->config->cdev; 267 struct usb_composite_dev *cdev = function->config->cdev;
268 unsigned long flags;
303 int status = 0; 269 int status = 0;
304 270
305 spin_lock(&cdev->lock); 271 spin_lock_irqsave(&cdev->lock, flags);
306 272
307 if (WARN_ON(cdev->deactivations == 0)) 273 if (WARN_ON(cdev->deactivations == 0))
308 status = -EINVAL; 274 status = -EINVAL;
@@ -312,9 +278,10 @@ int usb_function_activate(struct usb_function *function)
312 status = usb_gadget_connect(cdev->gadget); 278 status = usb_gadget_connect(cdev->gadget);
313 } 279 }
314 280
315 spin_unlock(&cdev->lock); 281 spin_unlock_irqrestore(&cdev->lock, flags);
316 return status; 282 return status;
317} 283}
284EXPORT_SYMBOL_GPL(usb_function_activate);
318 285
319/** 286/**
320 * usb_interface_id() - allocate an unused interface ID 287 * usb_interface_id() - allocate an unused interface ID
@@ -351,16 +318,18 @@ int usb_interface_id(struct usb_configuration *config,
351 } 318 }
352 return -ENODEV; 319 return -ENODEV;
353} 320}
321EXPORT_SYMBOL_GPL(usb_interface_id);
354 322
355static int config_buf(struct usb_configuration *config, 323static int config_buf(struct usb_configuration *config,
356 enum usb_device_speed speed, void *buf, u8 type) 324 enum usb_device_speed speed, void *buf, u8 type)
357{ 325{
358 struct usb_config_descriptor *c = buf; 326 struct usb_config_descriptor *c = buf;
359 void *next = buf + USB_DT_CONFIG_SIZE; 327 void *next = buf + USB_DT_CONFIG_SIZE;
360 int len = USB_BUFSIZ - USB_DT_CONFIG_SIZE; 328 int len;
361 struct usb_function *f; 329 struct usb_function *f;
362 int status; 330 int status;
363 331
332 len = USB_COMP_EP0_BUFSIZ - USB_DT_CONFIG_SIZE;
364 /* write the config descriptor */ 333 /* write the config descriptor */
365 c = buf; 334 c = buf;
366 c->bLength = USB_DT_CONFIG_SIZE; 335 c->bLength = USB_DT_CONFIG_SIZE;
@@ -790,6 +759,7 @@ done:
790 config->bConfigurationValue, status); 759 config->bConfigurationValue, status);
791 return status; 760 return status;
792} 761}
762EXPORT_SYMBOL_GPL(usb_add_config);
793 763
794static void remove_config(struct usb_composite_dev *cdev, 764static void remove_config(struct usb_composite_dev *cdev,
795 struct usb_configuration *config) 765 struct usb_configuration *config)
@@ -889,10 +859,10 @@ static int lookup_string(
889static int get_string(struct usb_composite_dev *cdev, 859static int get_string(struct usb_composite_dev *cdev,
890 void *buf, u16 language, int id) 860 void *buf, u16 language, int id)
891{ 861{
862 struct usb_composite_driver *composite = cdev->driver;
892 struct usb_configuration *c; 863 struct usb_configuration *c;
893 struct usb_function *f; 864 struct usb_function *f;
894 int len; 865 int len;
895 const char *str;
896 866
897 /* Yes, not only is USB's I18N support probably more than most 867 /* Yes, not only is USB's I18N support probably more than most
898 * folk will ever care about ... also, it's all supported here. 868 * folk will ever care about ... also, it's all supported here.
@@ -932,26 +902,6 @@ static int get_string(struct usb_composite_dev *cdev,
932 return s->bLength; 902 return s->bLength;
933 } 903 }
934 904
935 /* Otherwise, look up and return a specified string. First
936 * check if the string has not been overridden.
937 */
938 if (cdev->manufacturer_override == id)
939 str = iManufacturer ?: composite->iManufacturer ?:
940 composite_manufacturer;
941 else if (cdev->product_override == id)
942 str = iProduct ?: composite->iProduct;
943 else if (cdev->serial_override == id)
944 str = iSerialNumber ?: composite->iSerialNumber;
945 else
946 str = NULL;
947 if (str) {
948 struct usb_gadget_strings strings = {
949 .language = language,
950 .strings = &(struct usb_string) { 0xff, str }
951 };
952 return usb_gadget_get_string(&strings, 0xff, buf);
953 }
954
955 /* String IDs are device-scoped, so we look up each string 905 /* String IDs are device-scoped, so we look up each string
956 * table we're told about. These lookups are infrequent; 906 * table we're told about. These lookups are infrequent;
957 * simpler-is-better here. 907 * simpler-is-better here.
@@ -1003,6 +953,7 @@ int usb_string_id(struct usb_composite_dev *cdev)
1003 } 953 }
1004 return -ENODEV; 954 return -ENODEV;
1005} 955}
956EXPORT_SYMBOL_GPL(usb_string_id);
1006 957
1007/** 958/**
1008 * usb_string_ids() - allocate unused string IDs in batch 959 * usb_string_ids() - allocate unused string IDs in batch
@@ -1034,6 +985,7 @@ int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str)
1034 985
1035 return 0; 986 return 0;
1036} 987}
988EXPORT_SYMBOL_GPL(usb_string_ids_tab);
1037 989
1038/** 990/**
1039 * usb_string_ids_n() - allocate unused string IDs in batch 991 * usb_string_ids_n() - allocate unused string IDs in batch
@@ -1062,7 +1014,7 @@ int usb_string_ids_n(struct usb_composite_dev *c, unsigned n)
1062 c->next_string_id += n; 1014 c->next_string_id += n;
1063 return next + 1; 1015 return next + 1;
1064} 1016}
1065 1017EXPORT_SYMBOL_GPL(usb_string_ids_n);
1066 1018
1067/*-------------------------------------------------------------------------*/ 1019/*-------------------------------------------------------------------------*/
1068 1020
@@ -1359,8 +1311,8 @@ static void composite_disconnect(struct usb_gadget *gadget)
1359 spin_lock_irqsave(&cdev->lock, flags); 1311 spin_lock_irqsave(&cdev->lock, flags);
1360 if (cdev->config) 1312 if (cdev->config)
1361 reset_config(cdev); 1313 reset_config(cdev);
1362 if (composite->disconnect) 1314 if (cdev->driver->disconnect)
1363 composite->disconnect(cdev); 1315 cdev->driver->disconnect(cdev);
1364 spin_unlock_irqrestore(&cdev->lock, flags); 1316 spin_unlock_irqrestore(&cdev->lock, flags);
1365} 1317}
1366 1318
@@ -1396,35 +1348,67 @@ composite_unbind(struct usb_gadget *gadget)
1396 struct usb_configuration, list); 1348 struct usb_configuration, list);
1397 remove_config(cdev, c); 1349 remove_config(cdev, c);
1398 } 1350 }
1399 if (composite->unbind) 1351 if (cdev->driver->unbind)
1400 composite->unbind(cdev); 1352 cdev->driver->unbind(cdev);
1401 1353
1402 if (cdev->req) { 1354 if (cdev->req) {
1403 kfree(cdev->req->buf); 1355 kfree(cdev->req->buf);
1404 usb_ep_free_request(gadget->ep0, cdev->req); 1356 usb_ep_free_request(gadget->ep0, cdev->req);
1405 } 1357 }
1406 device_remove_file(&gadget->dev, &dev_attr_suspended); 1358 device_remove_file(&gadget->dev, &dev_attr_suspended);
1359 kfree(cdev->def_manufacturer);
1407 kfree(cdev); 1360 kfree(cdev);
1408 set_gadget_data(gadget, NULL); 1361 set_gadget_data(gadget, NULL);
1409 composite = NULL;
1410} 1362}
1411 1363
1412static u8 override_id(struct usb_composite_dev *cdev, u8 *desc) 1364static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
1365 const struct usb_device_descriptor *old)
1413{ 1366{
1414 if (!*desc) { 1367 __le16 idVendor;
1415 int ret = usb_string_id(cdev); 1368 __le16 idProduct;
1416 if (unlikely(ret < 0)) 1369 __le16 bcdDevice;
1417 WARNING(cdev, "failed to override string ID\n"); 1370 u8 iSerialNumber;
1418 else 1371 u8 iManufacturer;
1419 *desc = ret; 1372 u8 iProduct;
1420 }
1421 1373
1422 return *desc; 1374 /*
1375 * these variables may have been set in
1376 * usb_composite_overwrite_options()
1377 */
1378 idVendor = new->idVendor;
1379 idProduct = new->idProduct;
1380 bcdDevice = new->bcdDevice;
1381 iSerialNumber = new->iSerialNumber;
1382 iManufacturer = new->iManufacturer;
1383 iProduct = new->iProduct;
1384
1385 *new = *old;
1386 if (idVendor)
1387 new->idVendor = idVendor;
1388 if (idProduct)
1389 new->idProduct = idProduct;
1390 if (bcdDevice)
1391 new->bcdDevice = bcdDevice;
1392 else
1393 new->bcdDevice = cpu_to_le16(get_default_bcdDevice());
1394 if (iSerialNumber)
1395 new->iSerialNumber = iSerialNumber;
1396 if (iManufacturer)
1397 new->iManufacturer = iManufacturer;
1398 if (iProduct)
1399 new->iProduct = iProduct;
1423} 1400}
1424 1401
1425static int composite_bind(struct usb_gadget *gadget) 1402static struct usb_composite_driver *to_cdriver(struct usb_gadget_driver *gdrv)
1403{
1404 return container_of(gdrv, struct usb_composite_driver, gadget_driver);
1405}
1406
1407static int composite_bind(struct usb_gadget *gadget,
1408 struct usb_gadget_driver *gdriver)
1426{ 1409{
1427 struct usb_composite_dev *cdev; 1410 struct usb_composite_dev *cdev;
1411 struct usb_composite_driver *composite = to_cdriver(gdriver);
1428 int status = -ENOMEM; 1412 int status = -ENOMEM;
1429 1413
1430 cdev = kzalloc(sizeof *cdev, GFP_KERNEL); 1414 cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
@@ -1440,13 +1424,12 @@ static int composite_bind(struct usb_gadget *gadget)
1440 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); 1424 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
1441 if (!cdev->req) 1425 if (!cdev->req)
1442 goto fail; 1426 goto fail;
1443 cdev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL); 1427 cdev->req->buf = kmalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL);
1444 if (!cdev->req->buf) 1428 if (!cdev->req->buf)
1445 goto fail; 1429 goto fail;
1446 cdev->req->complete = composite_setup_complete; 1430 cdev->req->complete = composite_setup_complete;
1447 gadget->ep0->driver_data = cdev; 1431 gadget->ep0->driver_data = cdev;
1448 1432
1449 cdev->bufsiz = USB_BUFSIZ;
1450 cdev->driver = composite; 1433 cdev->driver = composite;
1451 1434
1452 /* 1435 /*
@@ -1467,49 +1450,11 @@ static int composite_bind(struct usb_gadget *gadget)
1467 * serial number), register function drivers, potentially update 1450 * serial number), register function drivers, potentially update
1468 * power state and consumption, etc 1451 * power state and consumption, etc
1469 */ 1452 */
1470 status = composite_gadget_bind(cdev); 1453 status = composite->bind(cdev);
1471 if (status < 0) 1454 if (status < 0)
1472 goto fail; 1455 goto fail;
1473 1456
1474 cdev->desc = *composite->dev; 1457 update_unchanged_dev_desc(&cdev->desc, composite->dev);
1475
1476 /* standardized runtime overrides for device ID data */
1477 if (idVendor)
1478 cdev->desc.idVendor = cpu_to_le16(idVendor);
1479 else
1480 idVendor = le16_to_cpu(cdev->desc.idVendor);
1481 if (idProduct)
1482 cdev->desc.idProduct = cpu_to_le16(idProduct);
1483 else
1484 idProduct = le16_to_cpu(cdev->desc.idProduct);
1485 if (bcdDevice)
1486 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1487 else
1488 bcdDevice = le16_to_cpu(cdev->desc.bcdDevice);
1489
1490 /* string overrides */
1491 if (iManufacturer || !cdev->desc.iManufacturer) {
1492 if (!iManufacturer && !composite->iManufacturer &&
1493 !*composite_manufacturer)
1494 snprintf(composite_manufacturer,
1495 sizeof composite_manufacturer,
1496 "%s %s with %s",
1497 init_utsname()->sysname,
1498 init_utsname()->release,
1499 gadget->name);
1500
1501 cdev->manufacturer_override =
1502 override_id(cdev, &cdev->desc.iManufacturer);
1503 }
1504
1505 if (iProduct || (!cdev->desc.iProduct && composite->iProduct))
1506 cdev->product_override =
1507 override_id(cdev, &cdev->desc.iProduct);
1508
1509 if (iSerialNumber ||
1510 (!cdev->desc.iSerialNumber && composite->iSerialNumber))
1511 cdev->serial_override =
1512 override_id(cdev, &cdev->desc.iSerialNumber);
1513 1458
1514 /* has userspace failed to provide a serial number? */ 1459 /* has userspace failed to provide a serial number? */
1515 if (composite->needs_serial && !cdev->desc.iSerialNumber) 1460 if (composite->needs_serial && !cdev->desc.iSerialNumber)
@@ -1546,8 +1491,8 @@ composite_suspend(struct usb_gadget *gadget)
1546 f->suspend(f); 1491 f->suspend(f);
1547 } 1492 }
1548 } 1493 }
1549 if (composite->suspend) 1494 if (cdev->driver->suspend)
1550 composite->suspend(cdev); 1495 cdev->driver->suspend(cdev);
1551 1496
1552 cdev->suspended = 1; 1497 cdev->suspended = 1;
1553 1498
@@ -1565,8 +1510,8 @@ composite_resume(struct usb_gadget *gadget)
1565 * suspend/resume callbacks? 1510 * suspend/resume callbacks?
1566 */ 1511 */
1567 DBG(cdev, "resume\n"); 1512 DBG(cdev, "resume\n");
1568 if (composite->resume) 1513 if (cdev->driver->resume)
1569 composite->resume(cdev); 1514 cdev->driver->resume(cdev);
1570 if (cdev->config) { 1515 if (cdev->config) {
1571 list_for_each_entry(f, &cdev->config->functions, list) { 1516 list_for_each_entry(f, &cdev->config->functions, list) {
1572 if (f->resume) 1517 if (f->resume)
@@ -1584,13 +1529,8 @@ composite_resume(struct usb_gadget *gadget)
1584 1529
1585/*-------------------------------------------------------------------------*/ 1530/*-------------------------------------------------------------------------*/
1586 1531
1587static struct usb_gadget_driver composite_driver = { 1532static const struct usb_gadget_driver composite_driver_template = {
1588#ifdef CONFIG_USB_GADGET_SUPERSPEED 1533 .bind = composite_bind,
1589 .max_speed = USB_SPEED_SUPER,
1590#else
1591 .max_speed = USB_SPEED_HIGH,
1592#endif
1593
1594 .unbind = composite_unbind, 1534 .unbind = composite_unbind,
1595 1535
1596 .setup = composite_setup, 1536 .setup = composite_setup,
@@ -1623,25 +1563,26 @@ static struct usb_gadget_driver composite_driver = {
1623 * while it was binding. That would usually be done in order to wait for 1563 * while it was binding. That would usually be done in order to wait for
1624 * some userspace participation. 1564 * some userspace participation.
1625 */ 1565 */
1626int usb_composite_probe(struct usb_composite_driver *driver, 1566int usb_composite_probe(struct usb_composite_driver *driver)
1627 int (*bind)(struct usb_composite_dev *cdev))
1628{ 1567{
1629 if (!driver || !driver->dev || !bind || composite) 1568 struct usb_gadget_driver *gadget_driver;
1569
1570 if (!driver || !driver->dev || !driver->bind)
1630 return -EINVAL; 1571 return -EINVAL;
1631 1572
1632 if (!driver->name) 1573 if (!driver->name)
1633 driver->name = "composite"; 1574 driver->name = "composite";
1634 if (!driver->iProduct) 1575
1635 driver->iProduct = driver->name; 1576 driver->gadget_driver = composite_driver_template;
1636 composite_driver.function = (char *) driver->name; 1577 gadget_driver = &driver->gadget_driver;
1637 composite_driver.driver.name = driver->name; 1578
1638 composite_driver.max_speed = 1579 gadget_driver->function = (char *) driver->name;
1639 min_t(u8, composite_driver.max_speed, driver->max_speed); 1580 gadget_driver->driver.name = driver->name;
1640 composite = driver; 1581 gadget_driver->max_speed = driver->max_speed;
1641 composite_gadget_bind = bind; 1582
1642 1583 return usb_gadget_probe_driver(gadget_driver);
1643 return usb_gadget_probe_driver(&composite_driver, composite_bind);
1644} 1584}
1585EXPORT_SYMBOL_GPL(usb_composite_probe);
1645 1586
1646/** 1587/**
1647 * usb_composite_unregister() - unregister a composite driver 1588 * usb_composite_unregister() - unregister a composite driver
@@ -1652,10 +1593,9 @@ int usb_composite_probe(struct usb_composite_driver *driver,
1652 */ 1593 */
1653void usb_composite_unregister(struct usb_composite_driver *driver) 1594void usb_composite_unregister(struct usb_composite_driver *driver)
1654{ 1595{
1655 if (composite != driver) 1596 usb_gadget_unregister_driver(&driver->gadget_driver);
1656 return;
1657 usb_gadget_unregister_driver(&composite_driver);
1658} 1597}
1598EXPORT_SYMBOL_GPL(usb_composite_unregister);
1659 1599
1660/** 1600/**
1661 * usb_composite_setup_continue() - Continue with the control transfer 1601 * usb_composite_setup_continue() - Continue with the control transfer
@@ -1692,4 +1632,60 @@ void usb_composite_setup_continue(struct usb_composite_dev *cdev)
1692 1632
1693 spin_unlock_irqrestore(&cdev->lock, flags); 1633 spin_unlock_irqrestore(&cdev->lock, flags);
1694} 1634}
1635EXPORT_SYMBOL_GPL(usb_composite_setup_continue);
1636
1637static char *composite_default_mfr(struct usb_gadget *gadget)
1638{
1639 char *mfr;
1640 int len;
1641
1642 len = snprintf(NULL, 0, "%s %s with %s", init_utsname()->sysname,
1643 init_utsname()->release, gadget->name);
1644 len++;
1645 mfr = kmalloc(len, GFP_KERNEL);
1646 if (!mfr)
1647 return NULL;
1648 snprintf(mfr, len, "%s %s with %s", init_utsname()->sysname,
1649 init_utsname()->release, gadget->name);
1650 return mfr;
1651}
1652
1653void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
1654 struct usb_composite_overwrite *covr)
1655{
1656 struct usb_device_descriptor *desc = &cdev->desc;
1657 struct usb_gadget_strings *gstr = cdev->driver->strings[0];
1658 struct usb_string *dev_str = gstr->strings;
1659
1660 if (covr->idVendor)
1661 desc->idVendor = cpu_to_le16(covr->idVendor);
1662
1663 if (covr->idProduct)
1664 desc->idProduct = cpu_to_le16(covr->idProduct);
1665
1666 if (covr->bcdDevice)
1667 desc->bcdDevice = cpu_to_le16(covr->bcdDevice);
1668
1669 if (covr->serial_number) {
1670 desc->iSerialNumber = dev_str[USB_GADGET_SERIAL_IDX].id;
1671 dev_str[USB_GADGET_SERIAL_IDX].s = covr->serial_number;
1672 }
1673 if (covr->manufacturer) {
1674 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id;
1675 dev_str[USB_GADGET_MANUFACTURER_IDX].s = covr->manufacturer;
1676
1677 } else if (!strlen(dev_str[USB_GADGET_MANUFACTURER_IDX].s)) {
1678 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id;
1679 cdev->def_manufacturer = composite_default_mfr(cdev->gadget);
1680 dev_str[USB_GADGET_MANUFACTURER_IDX].s = cdev->def_manufacturer;
1681 }
1682
1683 if (covr->product) {
1684 desc->iProduct = dev_str[USB_GADGET_PRODUCT_IDX].id;
1685 dev_str[USB_GADGET_PRODUCT_IDX].s = covr->product;
1686 }
1687}
1688EXPORT_SYMBOL_GPL(usb_composite_overwrite_options);
1695 1689
1690MODULE_LICENSE("GPL");
1691MODULE_AUTHOR("David Brownell");
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index 7542a72ce51a..e3a98929d346 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -12,6 +12,7 @@
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h>
15#include <linux/list.h> 16#include <linux/list.h>
16#include <linux/string.h> 17#include <linux/string.h>
17#include <linux/device.h> 18#include <linux/device.h>
@@ -53,7 +54,7 @@ usb_descriptor_fillbuf(void *buf, unsigned buflen,
53 } 54 }
54 return dest - (u8 *)buf; 55 return dest - (u8 *)buf;
55} 56}
56 57EXPORT_SYMBOL_GPL(usb_descriptor_fillbuf);
57 58
58/** 59/**
59 * usb_gadget_config_buf - builts a complete configuration descriptor 60 * usb_gadget_config_buf - builts a complete configuration descriptor
@@ -106,6 +107,7 @@ int usb_gadget_config_buf(
106 cp->bmAttributes |= USB_CONFIG_ATT_ONE; 107 cp->bmAttributes |= USB_CONFIG_ATT_ONE;
107 return len; 108 return len;
108} 109}
110EXPORT_SYMBOL_GPL(usb_gadget_config_buf);
109 111
110/** 112/**
111 * usb_copy_descriptors - copy a vector of USB descriptors 113 * usb_copy_descriptors - copy a vector of USB descriptors
@@ -155,4 +157,4 @@ usb_copy_descriptors(struct usb_descriptor_header **src)
155 157
156 return ret; 158 return ret;
157} 159}
158 160EXPORT_SYMBOL_GPL(usb_copy_descriptors);
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
index 19d7bb0df75a..87d165028162 100644
--- a/drivers/usb/gadget/dbgp.c
+++ b/drivers/usb/gadget/dbgp.c
@@ -13,9 +13,6 @@
13#include <linux/usb/ch9.h> 13#include <linux/usb/ch9.h>
14#include <linux/usb/gadget.h> 14#include <linux/usb/gadget.h>
15 15
16/* See comments in "zero.c" */
17#include "epautoconf.c"
18
19#ifdef CONFIG_USB_G_DBGP_SERIAL 16#ifdef CONFIG_USB_G_DBGP_SERIAL
20#include "u_serial.c" 17#include "u_serial.c"
21#endif 18#endif
@@ -292,7 +289,8 @@ fail_1:
292 return -ENODEV; 289 return -ENODEV;
293} 290}
294 291
295static int __init dbgp_bind(struct usb_gadget *gadget) 292static int __init dbgp_bind(struct usb_gadget *gadget,
293 struct usb_gadget_driver *driver)
296{ 294{
297 int err, stp; 295 int err, stp;
298 296
@@ -402,9 +400,10 @@ fail:
402 return err; 400 return err;
403} 401}
404 402
405static struct usb_gadget_driver dbgp_driver = { 403static __refdata struct usb_gadget_driver dbgp_driver = {
406 .function = "dbgp", 404 .function = "dbgp",
407 .max_speed = USB_SPEED_HIGH, 405 .max_speed = USB_SPEED_HIGH,
406 .bind = dbgp_bind,
408 .unbind = dbgp_unbind, 407 .unbind = dbgp_unbind,
409 .setup = dbgp_setup, 408 .setup = dbgp_setup,
410 .disconnect = dbgp_disconnect, 409 .disconnect = dbgp_disconnect,
@@ -416,7 +415,7 @@ static struct usb_gadget_driver dbgp_driver = {
416 415
417static int __init dbgp_init(void) 416static int __init dbgp_init(void)
418{ 417{
419 return usb_gadget_probe_driver(&dbgp_driver, dbgp_bind); 418 return usb_gadget_probe_driver(&dbgp_driver);
420} 419}
421 420
422static void __exit dbgp_exit(void) 421static void __exit dbgp_exit(void)
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index b799106027ad..91916f693ff7 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -909,6 +909,7 @@ static int dummy_udc_start(struct usb_gadget *g,
909 dum->devstatus = 0; 909 dum->devstatus = 0;
910 910
911 dum->driver = driver; 911 dum->driver = driver;
912 dum->gadget.dev.driver = &driver->driver;
912 dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n", 913 dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n",
913 driver->driver.name); 914 driver->driver.name);
914 return 0; 915 return 0;
@@ -923,6 +924,7 @@ static int dummy_udc_stop(struct usb_gadget *g,
923 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n", 924 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n",
924 driver->driver.name); 925 driver->driver.name);
925 926
927 dum->gadget.dev.driver = NULL;
926 dum->driver = NULL; 928 dum->driver = NULL;
927 929
928 return 0; 930 return 0;
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 51f3d42f5a64..a777f7bd11b4 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/module.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/types.h> 15#include <linux/types.h>
15#include <linux/device.h> 16#include <linux/device.h>
@@ -22,17 +23,6 @@
22 23
23#include "gadget_chips.h" 24#include "gadget_chips.h"
24 25
25
26/* we must assign addresses for configurable endpoints (like net2280) */
27static unsigned epnum;
28
29// #define MANY_ENDPOINTS
30#ifdef MANY_ENDPOINTS
31/* more than 15 configurable endpoints */
32static unsigned in_epnum;
33#endif
34
35
36/* 26/*
37 * This should work with endpoints from controller drivers sharing the 27 * This should work with endpoints from controller drivers sharing the
38 * same endpoint naming convention. By example: 28 * same endpoint naming convention. By example:
@@ -176,16 +166,14 @@ ep_matches (
176 if (isdigit (ep->name [2])) { 166 if (isdigit (ep->name [2])) {
177 u8 num = simple_strtoul (&ep->name [2], NULL, 10); 167 u8 num = simple_strtoul (&ep->name [2], NULL, 10);
178 desc->bEndpointAddress |= num; 168 desc->bEndpointAddress |= num;
179#ifdef MANY_ENDPOINTS
180 } else if (desc->bEndpointAddress & USB_DIR_IN) { 169 } else if (desc->bEndpointAddress & USB_DIR_IN) {
181 if (++in_epnum > 15) 170 if (++gadget->in_epnum > 15)
182 return 0; 171 return 0;
183 desc->bEndpointAddress = USB_DIR_IN | in_epnum; 172 desc->bEndpointAddress = USB_DIR_IN | gadget->in_epnum;
184#endif
185 } else { 173 } else {
186 if (++epnum > 15) 174 if (++gadget->out_epnum > 15)
187 return 0; 175 return 0;
188 desc->bEndpointAddress |= epnum; 176 desc->bEndpointAddress |= gadget->out_epnum;
189 } 177 }
190 178
191 /* report (variable) full speed bulk maxpacket */ 179 /* report (variable) full speed bulk maxpacket */
@@ -328,6 +316,7 @@ found_ep:
328 ep->comp_desc = NULL; 316 ep->comp_desc = NULL;
329 return ep; 317 return ep;
330} 318}
319EXPORT_SYMBOL_GPL(usb_ep_autoconfig_ss);
331 320
332/** 321/**
333 * usb_ep_autoconfig() - choose an endpoint matching the 322 * usb_ep_autoconfig() - choose an endpoint matching the
@@ -367,7 +356,7 @@ struct usb_ep *usb_ep_autoconfig(
367{ 356{
368 return usb_ep_autoconfig_ss(gadget, desc, NULL); 357 return usb_ep_autoconfig_ss(gadget, desc, NULL);
369} 358}
370 359EXPORT_SYMBOL_GPL(usb_ep_autoconfig);
371 360
372/** 361/**
373 * usb_ep_autoconfig_reset - reset endpoint autoconfig state 362 * usb_ep_autoconfig_reset - reset endpoint autoconfig state
@@ -385,9 +374,7 @@ void usb_ep_autoconfig_reset (struct usb_gadget *gadget)
385 list_for_each_entry (ep, &gadget->ep_list, ep_list) { 374 list_for_each_entry (ep, &gadget->ep_list, ep_list) {
386 ep->driver_data = NULL; 375 ep->driver_data = NULL;
387 } 376 }
388#ifdef MANY_ENDPOINTS 377 gadget->in_epnum = 0;
389 in_epnum = 0; 378 gadget->out_epnum = 0;
390#endif
391 epnum = 0;
392} 379}
393 380EXPORT_SYMBOL_GPL(usb_ep_autoconfig_reset);
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index a28f6ffcd0f3..18c3f423706e 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -14,8 +14,6 @@
14/* #define VERBOSE_DEBUG */ 14/* #define VERBOSE_DEBUG */
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/utsname.h>
18
19 17
20#if defined USB_ETH_RNDIS 18#if defined USB_ETH_RNDIS
21# undef USB_ETH_RNDIS 19# undef USB_ETH_RNDIS
@@ -102,11 +100,6 @@ static inline bool has_rndis(void)
102 * the runtime footprint, and giving us at least some parts of what 100 * the runtime footprint, and giving us at least some parts of what
103 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 101 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
104 */ 102 */
105#include "composite.c"
106#include "usbstring.c"
107#include "config.c"
108#include "epautoconf.c"
109
110#include "f_ecm.c" 103#include "f_ecm.c"
111#include "f_subset.c" 104#include "f_subset.c"
112#ifdef USB_ETH_RNDIS 105#ifdef USB_ETH_RNDIS
@@ -117,6 +110,7 @@ static inline bool has_rndis(void)
117#include "u_ether.c" 110#include "u_ether.c"
118 111
119/*-------------------------------------------------------------------------*/ 112/*-------------------------------------------------------------------------*/
113USB_GADGET_COMPOSITE_OPTIONS();
120 114
121/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! 115/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
122 * Instead: allocate your own, using normal USB-IF procedures. 116 * Instead: allocate your own, using normal USB-IF procedures.
@@ -195,17 +189,10 @@ static const struct usb_descriptor_header *otg_desc[] = {
195 NULL, 189 NULL,
196}; 190};
197 191
198
199/* string IDs are assigned dynamically */
200
201#define STRING_MANUFACTURER_IDX 0
202#define STRING_PRODUCT_IDX 1
203
204static char manufacturer[50];
205
206static struct usb_string strings_dev[] = { 192static struct usb_string strings_dev[] = {
207 [STRING_MANUFACTURER_IDX].s = manufacturer, 193 [USB_GADGET_MANUFACTURER_IDX].s = "",
208 [STRING_PRODUCT_IDX].s = PREFIX DRIVER_DESC, 194 [USB_GADGET_PRODUCT_IDX].s = PREFIX DRIVER_DESC,
195 [USB_GADGET_SERIAL_IDX].s = "",
209 { } /* end of list */ 196 { } /* end of list */
210}; 197};
211 198
@@ -288,7 +275,6 @@ static struct usb_configuration eth_config_driver = {
288 275
289static int __init eth_bind(struct usb_composite_dev *cdev) 276static int __init eth_bind(struct usb_composite_dev *cdev)
290{ 277{
291 int gcnum;
292 struct usb_gadget *gadget = cdev->gadget; 278 struct usb_gadget *gadget = cdev->gadget;
293 int status; 279 int status;
294 280
@@ -323,42 +309,15 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
323 device_desc.bNumConfigurations = 2; 309 device_desc.bNumConfigurations = 2;
324 } 310 }
325 311
326 gcnum = usb_gadget_controller_number(gadget);
327 if (gcnum >= 0)
328 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
329 else {
330 /* We assume that can_support_ecm() tells the truth;
331 * but if the controller isn't recognized at all then
332 * that assumption is a bit more likely to be wrong.
333 */
334 dev_warn(&gadget->dev,
335 "controller '%s' not recognized; trying %s\n",
336 gadget->name,
337 eth_config_driver.label);
338 device_desc.bcdDevice =
339 cpu_to_le16(0x0300 | 0x0099);
340 }
341
342
343 /* Allocate string descriptor numbers ... note that string 312 /* Allocate string descriptor numbers ... note that string
344 * contents can be overridden by the composite_dev glue. 313 * contents can be overridden by the composite_dev glue.
345 */ 314 */
346 315
347 /* device descriptor strings: manufacturer, product */ 316 status = usb_string_ids_tab(cdev, strings_dev);
348 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
349 init_utsname()->sysname, init_utsname()->release,
350 gadget->name);
351 status = usb_string_id(cdev);
352 if (status < 0)
353 goto fail;
354 strings_dev[STRING_MANUFACTURER_IDX].id = status;
355 device_desc.iManufacturer = status;
356
357 status = usb_string_id(cdev);
358 if (status < 0) 317 if (status < 0)
359 goto fail; 318 goto fail;
360 strings_dev[STRING_PRODUCT_IDX].id = status; 319 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
361 device_desc.iProduct = status; 320 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
362 321
363 /* register our configuration(s); RNDIS first, if it's used */ 322 /* register our configuration(s); RNDIS first, if it's used */
364 if (has_rndis()) { 323 if (has_rndis()) {
@@ -372,6 +331,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
372 if (status < 0) 331 if (status < 0)
373 goto fail; 332 goto fail;
374 333
334 usb_composite_overwrite_options(cdev, &coverwrite);
375 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 335 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
376 DRIVER_DESC); 336 DRIVER_DESC);
377 337
@@ -388,11 +348,12 @@ static int __exit eth_unbind(struct usb_composite_dev *cdev)
388 return 0; 348 return 0;
389} 349}
390 350
391static struct usb_composite_driver eth_driver = { 351static __refdata struct usb_composite_driver eth_driver = {
392 .name = "g_ether", 352 .name = "g_ether",
393 .dev = &device_desc, 353 .dev = &device_desc,
394 .strings = dev_strings, 354 .strings = dev_strings,
395 .max_speed = USB_SPEED_SUPER, 355 .max_speed = USB_SPEED_SUPER,
356 .bind = eth_bind,
396 .unbind = __exit_p(eth_unbind), 357 .unbind = __exit_p(eth_unbind),
397}; 358};
398 359
@@ -402,7 +363,7 @@ MODULE_LICENSE("GPL");
402 363
403static int __init init(void) 364static int __init init(void)
404{ 365{
405 return usb_composite_probe(&eth_driver, eth_bind); 366 return usb_composite_probe(&eth_driver);
406} 367}
407module_init(init); 368module_init(init);
408 369
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index 30b908f2a53d..95bc94f8e570 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -897,10 +897,7 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
897 return -ENOMEM; 897 return -ENOMEM;
898 898
899 /* export host's Ethernet address in CDC format */ 899 /* export host's Ethernet address in CDC format */
900 snprintf(ecm->ethaddr, sizeof ecm->ethaddr, 900 snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr);
901 "%02X%02X%02X%02X%02X%02X",
902 ethaddr[0], ethaddr[1], ethaddr[2],
903 ethaddr[3], ethaddr[4], ethaddr[5]);
904 ecm_string_defs[1].s = ecm->ethaddr; 901 ecm_string_defs[1].s = ecm->ethaddr;
905 902
906 ecm->port.cdc_filter = DEFAULT_FILTER; 903 ecm->port.cdc_filter = DEFAULT_FILTER;
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c
index 16a8b1c15c62..511e527178e2 100644
--- a/drivers/usb/gadget/f_hid.c
+++ b/drivers/usb/gadget/f_hid.c
@@ -10,7 +10,6 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/utsname.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/hid.h> 14#include <linux/hid.h>
16#include <linux/cdev.h> 15#include <linux/cdev.h>
@@ -18,6 +17,7 @@
18#include <linux/poll.h> 17#include <linux/poll.h>
19#include <linux/uaccess.h> 18#include <linux/uaccess.h>
20#include <linux/wait.h> 19#include <linux/wait.h>
20#include <linux/sched.h>
21#include <linux/usb/g_hid.h> 21#include <linux/usb/g_hid.h>
22 22
23static int major, minors; 23static int major, minors;
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 4f1142efa6d1..3a7668bde3ef 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -213,7 +213,6 @@
213#include <linux/spinlock.h> 213#include <linux/spinlock.h>
214#include <linux/string.h> 214#include <linux/string.h>
215#include <linux/freezer.h> 215#include <linux/freezer.h>
216#include <linux/utsname.h>
217 216
218#include <linux/usb/ch9.h> 217#include <linux/usb/ch9.h>
219#include <linux/usb/gadget.h> 218#include <linux/usb/gadget.h>
@@ -349,7 +348,6 @@ struct fsg_config {
349 348
350 const char *vendor_name; /* 8 characters or less */ 349 const char *vendor_name; /* 8 characters or less */
351 const char *product_name; /* 16 characters or less */ 350 const char *product_name; /* 16 characters or less */
352 u16 release;
353 351
354 char can_stall; 352 char can_stall;
355}; 353};
@@ -2773,18 +2771,7 @@ buffhds_first_it:
2773 bh->next = common->buffhds; 2771 bh->next = common->buffhds;
2774 2772
2775 /* Prepare inquiryString */ 2773 /* Prepare inquiryString */
2776 if (cfg->release != 0xffff) { 2774 i = get_default_bcdDevice();
2777 i = cfg->release;
2778 } else {
2779 i = usb_gadget_controller_number(gadget);
2780 if (i >= 0) {
2781 i = 0x0300 + i;
2782 } else {
2783 WARNING(common, "controller '%s' not recognized\n",
2784 gadget->name);
2785 i = 0x0399;
2786 }
2787 }
2788 snprintf(common->inquiry_string, sizeof common->inquiry_string, 2775 snprintf(common->inquiry_string, sizeof common->inquiry_string,
2789 "%-8s%-16s%04x", cfg->vendor_name ?: "Linux", 2776 "%-8s%-16s%04x", cfg->vendor_name ?: "Linux",
2790 /* Assume product name dependent on the first LUN */ 2777 /* Assume product name dependent on the first LUN */
@@ -3110,7 +3097,6 @@ fsg_config_from_params(struct fsg_config *cfg,
3110 /* Let MSF use defaults */ 3097 /* Let MSF use defaults */
3111 cfg->vendor_name = 0; 3098 cfg->vendor_name = 0;
3112 cfg->product_name = 0; 3099 cfg->product_name = 0;
3113 cfg->release = 0xffff;
3114 3100
3115 cfg->ops = NULL; 3101 cfg->ops = NULL;
3116 cfg->private_data = NULL; 3102 cfg->private_data = NULL;
diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c
index 2f7e8f2930cc..8ed1259fe80d 100644
--- a/drivers/usb/gadget/f_midi.c
+++ b/drivers/usb/gadget/f_midi.c
@@ -21,7 +21,6 @@
21 21
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/utsname.h>
25#include <linux/device.h> 24#include <linux/device.h>
26 25
27#include <sound/core.h> 26#include <sound/core.h>
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c
index aab8eded045b..b651b529c67f 100644
--- a/drivers/usb/gadget/f_ncm.c
+++ b/drivers/usb/gadget/f_ncm.c
@@ -1346,10 +1346,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
1346 return -ENOMEM; 1346 return -ENOMEM;
1347 1347
1348 /* export host's Ethernet address in CDC format */ 1348 /* export host's Ethernet address in CDC format */
1349 snprintf(ncm->ethaddr, sizeof ncm->ethaddr, 1349 snprintf(ncm->ethaddr, sizeof ncm->ethaddr, "%pm", ethaddr);
1350 "%02X%02X%02X%02X%02X%02X",
1351 ethaddr[0], ethaddr[1], ethaddr[2],
1352 ethaddr[3], ethaddr[4], ethaddr[5]);
1353 ncm_string_defs[1].s = ncm->ethaddr; 1350 ncm_string_defs[1].s = ncm->ethaddr;
1354 1351
1355 spin_lock_init(&ncm->lock); 1352 spin_lock_init(&ncm->lock);
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 5c1b68b63c98..3c126fde6e7e 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -795,7 +795,7 @@ static int sourcesink_setup(struct usb_configuration *c,
795 u16 w_value = le16_to_cpu(ctrl->wValue); 795 u16 w_value = le16_to_cpu(ctrl->wValue);
796 u16 w_length = le16_to_cpu(ctrl->wLength); 796 u16 w_length = le16_to_cpu(ctrl->wLength);
797 797
798 req->length = USB_BUFSIZ; 798 req->length = USB_COMP_EP0_BUFSIZ;
799 799
800 /* composite driver infrastructure handles everything except 800 /* composite driver infrastructure handles everything except
801 * the two control test requests. 801 * the two control test requests.
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index 21ab474aca07..4060c0bd9785 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -436,10 +436,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
436 return -ENOMEM; 436 return -ENOMEM;
437 437
438 /* export host's Ethernet address in CDC format */ 438 /* export host's Ethernet address in CDC format */
439 snprintf(geth->ethaddr, sizeof geth->ethaddr, 439 snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr);
440 "%02X%02X%02X%02X%02X%02X",
441 ethaddr[0], ethaddr[1], ethaddr[2],
442 ethaddr[3], ethaddr[4], ethaddr[5]);
443 geth_string_defs[1].s = geth->ethaddr; 440 geth_string_defs[1].s = geth->ethaddr;
444 441
445 geth->port.cdc_filter = DEFAULT_FILTER; 442 geth->port.cdc_filter = DEFAULT_FILTER;
diff --git a/drivers/usb/gadget/f_uac2.c b/drivers/usb/gadget/f_uac2.c
index e7cc4de93e33..d3c6cffccb72 100644
--- a/drivers/usb/gadget/f_uac2.c
+++ b/drivers/usb/gadget/f_uac2.c
@@ -463,7 +463,7 @@ snd_fail:
463 return err; 463 return err;
464} 464}
465 465
466static int __devexit snd_uac2_remove(struct platform_device *pdev) 466static int snd_uac2_remove(struct platform_device *pdev)
467{ 467{
468 struct snd_card *card = platform_get_drvdata(pdev); 468 struct snd_card *card = platform_get_drvdata(pdev);
469 469
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a896d73f7a93..3f7d640b6758 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -251,26 +251,12 @@
251#include <linux/freezer.h> 251#include <linux/freezer.h>
252#include <linux/utsname.h> 252#include <linux/utsname.h>
253 253
254#include <linux/usb/composite.h>
254#include <linux/usb/ch9.h> 255#include <linux/usb/ch9.h>
255#include <linux/usb/gadget.h> 256#include <linux/usb/gadget.h>
256 257
257#include "gadget_chips.h" 258#include "gadget_chips.h"
258 259
259
260
261/*
262 * Kbuild is not very cooperative with respect to linking separately
263 * compiled library objects into one module. So for now we won't use
264 * separate compilation ... ensuring init/exit sections work to shrink
265 * the runtime footprint, and giving us at least some parts of what
266 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
267 */
268#include "usbstring.c"
269#include "config.c"
270#include "epautoconf.c"
271
272/*-------------------------------------------------------------------------*/
273
274#define DRIVER_DESC "File-backed Storage Gadget" 260#define DRIVER_DESC "File-backed Storage Gadget"
275#define DRIVER_NAME "g_file_storage" 261#define DRIVER_NAME "g_file_storage"
276#define DRIVER_VERSION "1 September 2010" 262#define DRIVER_VERSION "1 September 2010"
@@ -3213,7 +3199,6 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3213static int __init check_parameters(struct fsg_dev *fsg) 3199static int __init check_parameters(struct fsg_dev *fsg)
3214{ 3200{
3215 int prot; 3201 int prot;
3216 int gcnum;
3217 3202
3218 /* Store the default values */ 3203 /* Store the default values */
3219 mod_data.transport_type = USB_PR_BULK; 3204 mod_data.transport_type = USB_PR_BULK;
@@ -3228,16 +3213,8 @@ static int __init check_parameters(struct fsg_dev *fsg)
3228 if (gadget_is_at91(fsg->gadget)) 3213 if (gadget_is_at91(fsg->gadget))
3229 mod_data.can_stall = 0; 3214 mod_data.can_stall = 0;
3230 3215
3231 if (mod_data.release == 0xffff) { // Parameter wasn't set 3216 if (mod_data.release == 0xffff)
3232 gcnum = usb_gadget_controller_number(fsg->gadget); 3217 mod_data.release = get_default_bcdDevice();
3233 if (gcnum >= 0)
3234 mod_data.release = 0x0300 + gcnum;
3235 else {
3236 WARNING(fsg, "controller '%s' not recognized\n",
3237 fsg->gadget->name);
3238 mod_data.release = 0x0399;
3239 }
3240 }
3241 3218
3242 prot = simple_strtol(mod_data.protocol_parm, NULL, 0); 3219 prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
3243 3220
@@ -3331,7 +3308,8 @@ static int __init check_parameters(struct fsg_dev *fsg)
3331} 3308}
3332 3309
3333 3310
3334static int __init fsg_bind(struct usb_gadget *gadget) 3311static int __init fsg_bind(struct usb_gadget *gadget,
3312 struct usb_gadget_driver *driver)
3335{ 3313{
3336 struct fsg_dev *fsg = the_fsg; 3314 struct fsg_dev *fsg = the_fsg;
3337 int rc; 3315 int rc;
@@ -3603,9 +3581,10 @@ static void fsg_resume(struct usb_gadget *gadget)
3603 3581
3604/*-------------------------------------------------------------------------*/ 3582/*-------------------------------------------------------------------------*/
3605 3583
3606static struct usb_gadget_driver fsg_driver = { 3584static __refdata struct usb_gadget_driver fsg_driver = {
3607 .max_speed = USB_SPEED_SUPER, 3585 .max_speed = USB_SPEED_SUPER,
3608 .function = (char *) fsg_string_product, 3586 .function = (char *) fsg_string_product,
3587 .bind = fsg_bind,
3609 .unbind = fsg_unbind, 3588 .unbind = fsg_unbind,
3610 .disconnect = fsg_disconnect, 3589 .disconnect = fsg_disconnect,
3611 .setup = fsg_setup, 3590 .setup = fsg_setup,
@@ -3653,7 +3632,8 @@ static int __init fsg_init(void)
3653 if ((rc = fsg_alloc()) != 0) 3632 if ((rc = fsg_alloc()) != 0)
3654 return rc; 3633 return rc;
3655 fsg = the_fsg; 3634 fsg = the_fsg;
3656 if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0) 3635 rc = usb_gadget_probe_driver(&fsg_driver);
3636 if (rc != 0)
3657 kref_put(&fsg->ref, fsg_release); 3637 kref_put(&fsg->ref, fsg_release);
3658 return rc; 3638 return rc;
3659} 3639}
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 3def828f85e7..6ae70cba0c4a 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1255,7 +1255,7 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
1255} 1255}
1256 1256
1257static int fsl_start(struct usb_gadget_driver *driver, 1257static int fsl_start(struct usb_gadget_driver *driver,
1258 int (*bind)(struct usb_gadget *)); 1258 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
1259static int fsl_stop(struct usb_gadget_driver *driver); 1259static int fsl_stop(struct usb_gadget_driver *driver);
1260/* defined in gadget.h */ 1260/* defined in gadget.h */
1261static struct usb_gadget_ops fsl_gadget_ops = { 1261static struct usb_gadget_ops fsl_gadget_ops = {
@@ -1951,7 +1951,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
1951 * Called by initialization code of gadget drivers 1951 * Called by initialization code of gadget drivers
1952*----------------------------------------------------------------*/ 1952*----------------------------------------------------------------*/
1953static int fsl_start(struct usb_gadget_driver *driver, 1953static int fsl_start(struct usb_gadget_driver *driver,
1954 int (*bind)(struct usb_gadget *)) 1954 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1955{ 1955{
1956 int retval = -ENODEV; 1956 int retval = -ENODEV;
1957 unsigned long flags = 0; 1957 unsigned long flags = 0;
@@ -1976,7 +1976,7 @@ static int fsl_start(struct usb_gadget_driver *driver,
1976 spin_unlock_irqrestore(&udc_controller->lock, flags); 1976 spin_unlock_irqrestore(&udc_controller->lock, flags);
1977 1977
1978 /* bind udc driver to gadget driver */ 1978 /* bind udc driver to gadget driver */
1979 retval = bind(&udc_controller->gadget); 1979 retval = bind(&udc_controller->gadget, driver);
1980 if (retval) { 1980 if (retval) {
1981 VDBG("bind to %s --> %d", driver->driver.name, retval); 1981 VDBG("bind to %s --> %d", driver->driver.name, retval);
1982 udc_controller->gadget.dev.driver = NULL; 1982 udc_controller->gadget.dev.driver = NULL;
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index cdd94540e1cd..72cd5e6719db 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -1311,7 +1311,7 @@ static void init_controller(struct fusb300 *fusb300)
1311static struct fusb300 *the_controller; 1311static struct fusb300 *the_controller;
1312 1312
1313static int fusb300_udc_start(struct usb_gadget_driver *driver, 1313static int fusb300_udc_start(struct usb_gadget_driver *driver,
1314 int (*bind)(struct usb_gadget *)) 1314 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1315{ 1315{
1316 struct fusb300 *fusb300 = the_controller; 1316 struct fusb300 *fusb300 = the_controller;
1317 int retval; 1317 int retval;
@@ -1339,7 +1339,7 @@ static int fusb300_udc_start(struct usb_gadget_driver *driver,
1339 goto error; 1339 goto error;
1340 } 1340 }
1341 1341
1342 retval = bind(&fusb300->gadget); 1342 retval = bind(&fusb300->gadget, driver);
1343 if (retval) { 1343 if (retval) {
1344 pr_err("bind to driver error (%d)\n", retval); 1344 pr_err("bind to driver error (%d)\n", retval);
1345 device_del(&fusb300->gadget.dev); 1345 device_del(&fusb300->gadget.dev);
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index d3ace9002a6a..3953dd4d7186 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -13,7 +13,6 @@
13#define pr_fmt(fmt) "g_ffs: " fmt 13#define pr_fmt(fmt) "g_ffs: " fmt
14 14
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/utsname.h>
17 16
18/* 17/*
19 * kbuild is not very cooperative with respect to linking separately 18 * kbuild is not very cooperative with respect to linking separately
@@ -22,12 +21,6 @@
22 * the runtime footprint, and giving us at least some parts of what 21 * the runtime footprint, and giving us at least some parts of what
23 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 22 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
24 */ 23 */
25
26#include "composite.c"
27#include "usbstring.c"
28#include "config.c"
29#include "epautoconf.c"
30
31#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS 24#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
32# if defined USB_ETH_RNDIS 25# if defined USB_ETH_RNDIS
33# undef USB_ETH_RNDIS 26# undef USB_ETH_RNDIS
@@ -76,6 +69,8 @@ struct gfs_ffs_obj {
76 struct ffs_data *ffs_data; 69 struct ffs_data *ffs_data;
77}; 70};
78 71
72USB_GADGET_COMPOSITE_OPTIONS();
73
79static struct usb_device_descriptor gfs_dev_desc = { 74static struct usb_device_descriptor gfs_dev_desc = {
80 .bLength = sizeof gfs_dev_desc, 75 .bLength = sizeof gfs_dev_desc,
81 .bDescriptorType = USB_DT_DEVICE, 76 .bDescriptorType = USB_DT_DEVICE,
@@ -117,6 +112,9 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = {
117 112
118/* String IDs are assigned dynamically */ 113/* String IDs are assigned dynamically */
119static struct usb_string gfs_strings[] = { 114static struct usb_string gfs_strings[] = {
115 [USB_GADGET_MANUFACTURER_IDX].s = "",
116 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
117 [USB_GADGET_SERIAL_IDX].s = "",
120#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 118#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
121 { .s = "FunctionFS + RNDIS" }, 119 { .s = "FunctionFS + RNDIS" },
122#endif 120#endif
@@ -163,13 +161,13 @@ static int gfs_bind(struct usb_composite_dev *cdev);
163static int gfs_unbind(struct usb_composite_dev *cdev); 161static int gfs_unbind(struct usb_composite_dev *cdev);
164static int gfs_do_config(struct usb_configuration *c); 162static int gfs_do_config(struct usb_configuration *c);
165 163
166static struct usb_composite_driver gfs_driver = { 164static __refdata struct usb_composite_driver gfs_driver = {
167 .name = DRIVER_NAME, 165 .name = DRIVER_NAME,
168 .dev = &gfs_dev_desc, 166 .dev = &gfs_dev_desc,
169 .strings = gfs_dev_strings, 167 .strings = gfs_dev_strings,
170 .max_speed = USB_SPEED_HIGH, 168 .max_speed = USB_SPEED_HIGH,
169 .bind = gfs_bind,
171 .unbind = gfs_unbind, 170 .unbind = gfs_unbind,
172 .iProduct = DRIVER_DESC,
173}; 171};
174 172
175static DEFINE_MUTEX(gfs_lock); 173static DEFINE_MUTEX(gfs_lock);
@@ -268,7 +266,7 @@ static int functionfs_ready_callback(struct ffs_data *ffs)
268 } 266 }
269 gfs_registered = true; 267 gfs_registered = true;
270 268
271 ret = usb_composite_probe(&gfs_driver, gfs_bind); 269 ret = usb_composite_probe(&gfs_driver);
272 if (unlikely(ret < 0)) 270 if (unlikely(ret < 0))
273 gfs_registered = false; 271 gfs_registered = false;
274 272
@@ -357,6 +355,7 @@ static int gfs_bind(struct usb_composite_dev *cdev)
357 ret = usb_string_ids_tab(cdev, gfs_strings); 355 ret = usb_string_ids_tab(cdev, gfs_strings);
358 if (unlikely(ret < 0)) 356 if (unlikely(ret < 0))
359 goto error; 357 goto error;
358 gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id;
360 359
361 for (i = func_num; --i; ) { 360 for (i = func_num; --i; ) {
362 ret = functionfs_bind(ffs_tab[i].ffs_data, cdev); 361 ret = functionfs_bind(ffs_tab[i].ffs_data, cdev);
@@ -369,9 +368,10 @@ static int gfs_bind(struct usb_composite_dev *cdev)
369 368
370 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { 369 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) {
371 struct gfs_configuration *c = gfs_configurations + i; 370 struct gfs_configuration *c = gfs_configurations + i;
371 int sid = USB_GADGET_FIRST_AVAIL_IDX + i;
372 372
373 c->c.label = gfs_strings[i].s; 373 c->c.label = gfs_strings[sid].s;
374 c->c.iConfiguration = gfs_strings[i].id; 374 c->c.iConfiguration = gfs_strings[sid].id;
375 c->c.bConfigurationValue = 1 + i; 375 c->c.bConfigurationValue = 1 + i;
376 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; 376 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER;
377 377
@@ -379,7 +379,7 @@ static int gfs_bind(struct usb_composite_dev *cdev)
379 if (unlikely(ret < 0)) 379 if (unlikely(ret < 0))
380 goto error_unbind; 380 goto error_unbind;
381 } 381 }
382 382 usb_composite_overwrite_options(cdev, &coverwrite);
383 return 0; 383 return 0;
384 384
385error_unbind: 385error_unbind:
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index b8b3a3411218..bcd04bc66b98 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -15,6 +15,8 @@
15#ifndef __GADGET_CHIPS_H 15#ifndef __GADGET_CHIPS_H
16#define __GADGET_CHIPS_H 16#define __GADGET_CHIPS_H
17 17
18#include <linux/usb/gadget.h>
19
18/* 20/*
19 * NOTICE: the entries below are alphabetical and should be kept 21 * NOTICE: the entries below are alphabetical and should be kept
20 * that way. 22 * that way.
@@ -25,106 +27,12 @@
25 * If you have forgotten the alphabetical order let VIM/EMACS 27 * If you have forgotten the alphabetical order let VIM/EMACS
26 * do that for you. 28 * do that for you.
27 */ 29 */
28#define gadget_is_amd5536udc(g) (!strcmp("amd5536udc", (g)->name))
29#define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name)) 30#define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name))
30#define gadget_is_atmel_usba(g) (!strcmp("atmel_usba_udc", (g)->name))
31#define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name))
32#define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name))
33#define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name))
34#define gadget_is_dwc3(g) (!strcmp("dwc3-gadget", (g)->name))
35#define gadget_is_fsl_qe(g) (!strcmp("fsl_qe_udc", (g)->name))
36#define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name))
37#define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) 31#define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name))
38#define gadget_is_imx(g) (!strcmp("imx_udc", (g)->name))
39#define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name))
40#define gadget_is_lpc32xx(g) (!strcmp("lpc32xx_udc", (g)->name))
41#define gadget_is_m66592(g) (!strcmp("m66592_udc", (g)->name))
42#define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name)) 32#define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name))
43#define gadget_is_net2272(g) (!strcmp("net2272", (g)->name))
44#define gadget_is_net2280(g) (!strcmp("net2280", (g)->name)) 33#define gadget_is_net2280(g) (!strcmp("net2280", (g)->name))
45#define gadget_is_omap(g) (!strcmp("omap_udc", (g)->name))
46#define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name))
47#define gadget_is_pxa(g) (!strcmp("pxa25x_udc", (g)->name)) 34#define gadget_is_pxa(g) (!strcmp("pxa25x_udc", (g)->name))
48#define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name)) 35#define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name))
49#define gadget_is_r8a66597(g) (!strcmp("r8a66597_udc", (g)->name))
50#define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name))
51#define gadget_is_s3c2410(g) (!strcmp("s3c2410_udc", (g)->name))
52#define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name))
53#define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name))
54
55/**
56 * usb_gadget_controller_number - support bcdDevice id convention
57 * @gadget: the controller being driven
58 *
59 * Return a 2-digit BCD value associated with the peripheral controller,
60 * suitable for use as part of a bcdDevice value, or a negative error code.
61 *
62 * NOTE: this convention is purely optional, and has no meaning in terms of
63 * any USB specification. If you want to use a different convention in your
64 * gadget driver firmware -- maybe a more formal revision ID -- feel free.
65 *
66 * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
67 * to change their behavior accordingly. For example it might help avoiding
68 * some chip bug.
69 */
70static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
71{
72 if (gadget_is_net2280(gadget))
73 return 0x01;
74 else if (gadget_is_dummy(gadget))
75 return 0x02;
76 else if (gadget_is_pxa(gadget))
77 return 0x03;
78 else if (gadget_is_goku(gadget))
79 return 0x06;
80 else if (gadget_is_omap(gadget))
81 return 0x08;
82 else if (gadget_is_pxa27x(gadget))
83 return 0x11;
84 else if (gadget_is_s3c2410(gadget))
85 return 0x12;
86 else if (gadget_is_at91(gadget))
87 return 0x13;
88 else if (gadget_is_imx(gadget))
89 return 0x14;
90 else if (gadget_is_musbhdrc(gadget))
91 return 0x16;
92 else if (gadget_is_atmel_usba(gadget))
93 return 0x18;
94 else if (gadget_is_fsl_usb2(gadget))
95 return 0x19;
96 else if (gadget_is_amd5536udc(gadget))
97 return 0x20;
98 else if (gadget_is_m66592(gadget))
99 return 0x21;
100 else if (gadget_is_fsl_qe(gadget))
101 return 0x22;
102 else if (gadget_is_ci13xxx_pci(gadget))
103 return 0x23;
104 else if (gadget_is_langwell(gadget))
105 return 0x24;
106 else if (gadget_is_r8a66597(gadget))
107 return 0x25;
108 else if (gadget_is_s3c_hsotg(gadget))
109 return 0x26;
110 else if (gadget_is_pch(gadget))
111 return 0x27;
112 else if (gadget_is_ci13xxx_msm(gadget))
113 return 0x28;
114 else if (gadget_is_renesas_usbhs(gadget))
115 return 0x29;
116 else if (gadget_is_s3c_hsudc(gadget))
117 return 0x30;
118 else if (gadget_is_net2272(gadget))
119 return 0x31;
120 else if (gadget_is_dwc3(gadget))
121 return 0x32;
122 else if (gadget_is_lpc32xx(gadget))
123 return 0x33;
124
125 return -ENOENT;
126}
127
128 36
129/** 37/**
130 * gadget_supports_altsettings - return true if altsettings work 38 * gadget_supports_altsettings - return true if altsettings work
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 681bd038b1d8..881aab86ae99 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -22,7 +22,6 @@
22 22
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/utsname.h>
26#include <linux/module.h> 25#include <linux/module.h>
27#include <linux/device.h> 26#include <linux/device.h>
28 27
@@ -31,16 +30,13 @@
31#include <sound/rawmidi.h> 30#include <sound/rawmidi.h>
32 31
33#include <linux/usb/ch9.h> 32#include <linux/usb/ch9.h>
33#include <linux/usb/composite.h>
34#include <linux/usb/gadget.h> 34#include <linux/usb/gadget.h>
35#include <linux/usb/audio.h> 35#include <linux/usb/audio.h>
36#include <linux/usb/midi.h> 36#include <linux/usb/midi.h>
37 37
38#include "gadget_chips.h" 38#include "gadget_chips.h"
39 39
40#include "composite.c"
41#include "usbstring.c"
42#include "config.c"
43#include "epautoconf.c"
44#include "f_midi.c" 40#include "f_midi.c"
45 41
46/*-------------------------------------------------------------------------*/ 42/*-------------------------------------------------------------------------*/
@@ -51,6 +47,8 @@ MODULE_LICENSE("GPL v2");
51static const char shortname[] = "g_midi"; 47static const char shortname[] = "g_midi";
52static const char longname[] = "MIDI Gadget"; 48static const char longname[] = "MIDI Gadget";
53 49
50USB_GADGET_COMPOSITE_OPTIONS();
51
54static int index = SNDRV_DEFAULT_IDX1; 52static int index = SNDRV_DEFAULT_IDX1;
55module_param(index, int, S_IRUGO); 53module_param(index, int, S_IRUGO);
56MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter."); 54MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter.");
@@ -85,9 +83,7 @@ MODULE_PARM_DESC(out_ports, "Number of MIDI output ports");
85 83
86/* string IDs are assigned dynamically */ 84/* string IDs are assigned dynamically */
87 85
88#define STRING_MANUFACTURER_IDX 0 86#define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX
89#define STRING_PRODUCT_IDX 1
90#define STRING_DESCRIPTION_IDX 2
91 87
92static struct usb_device_descriptor device_desc = { 88static struct usb_device_descriptor device_desc = {
93 .bLength = USB_DT_DEVICE_SIZE, 89 .bLength = USB_DT_DEVICE_SIZE,
@@ -102,8 +98,9 @@ static struct usb_device_descriptor device_desc = {
102}; 98};
103 99
104static struct usb_string strings_dev[] = { 100static struct usb_string strings_dev[] = {
105 [STRING_MANUFACTURER_IDX].s = "Grey Innovation", 101 [USB_GADGET_MANUFACTURER_IDX].s = "Grey Innovation",
106 [STRING_PRODUCT_IDX].s = "MIDI Gadget", 102 [USB_GADGET_PRODUCT_IDX].s = "MIDI Gadget",
103 [USB_GADGET_SERIAL_IDX].s = "",
107 [STRING_DESCRIPTION_IDX].s = "MIDI", 104 [STRING_DESCRIPTION_IDX].s = "MIDI",
108 { } /* end of list */ 105 { } /* end of list */
109}; 106};
@@ -140,61 +137,35 @@ static int __init midi_bind_config(struct usb_configuration *c)
140 137
141static int __init midi_bind(struct usb_composite_dev *cdev) 138static int __init midi_bind(struct usb_composite_dev *cdev)
142{ 139{
143 struct usb_gadget *gadget = cdev->gadget; 140 int status;
144 int gcnum, status;
145
146 status = usb_string_id(cdev);
147 if (status < 0)
148 return status;
149 strings_dev[STRING_MANUFACTURER_IDX].id = status;
150 device_desc.iManufacturer = status;
151 141
152 status = usb_string_id(cdev); 142 status = usb_string_ids_tab(cdev, strings_dev);
153 if (status < 0) 143 if (status < 0)
154 return status; 144 return status;
155 strings_dev[STRING_PRODUCT_IDX].id = status; 145 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
156 device_desc.iProduct = status; 146 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
157 147 midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id;
158 /* config description */
159 status = usb_string_id(cdev);
160 if (status < 0)
161 return status;
162 strings_dev[STRING_DESCRIPTION_IDX].id = status;
163
164 midi_config.iConfiguration = status;
165
166 gcnum = usb_gadget_controller_number(gadget);
167 if (gcnum < 0) {
168 /* gmidi is so simple (no altsettings) that
169 * it SHOULD NOT have problems with bulk-capable hardware.
170 * so warn about unrecognized controllers, don't panic.
171 */
172 pr_warning("%s: controller '%s' not recognized\n",
173 __func__, gadget->name);
174 device_desc.bcdDevice = cpu_to_le16(0x9999);
175 } else {
176 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
177 }
178 148
179 status = usb_add_config(cdev, &midi_config, midi_bind_config); 149 status = usb_add_config(cdev, &midi_config, midi_bind_config);
180 if (status < 0) 150 if (status < 0)
181 return status; 151 return status;
182 152 usb_composite_overwrite_options(cdev, &coverwrite);
183 pr_info("%s\n", longname); 153 pr_info("%s\n", longname);
184 return 0; 154 return 0;
185} 155}
186 156
187static struct usb_composite_driver midi_driver = { 157static __refdata struct usb_composite_driver midi_driver = {
188 .name = (char *) longname, 158 .name = (char *) longname,
189 .dev = &device_desc, 159 .dev = &device_desc,
190 .strings = dev_strings, 160 .strings = dev_strings,
191 .max_speed = USB_SPEED_HIGH, 161 .max_speed = USB_SPEED_HIGH,
162 .bind = midi_bind,
192 .unbind = __exit_p(midi_unbind), 163 .unbind = __exit_p(midi_unbind),
193}; 164};
194 165
195static int __init midi_init(void) 166static int __init midi_init(void)
196{ 167{
197 return usb_composite_probe(&midi_driver, midi_bind); 168 return usb_composite_probe(&midi_driver);
198} 169}
199module_init(midi_init); 170module_init(midi_init);
200 171
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 9fd7886cfa9a..51037cb78604 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -994,7 +994,7 @@ static int goku_get_frame(struct usb_gadget *_gadget)
994} 994}
995 995
996static int goku_start(struct usb_gadget_driver *driver, 996static int goku_start(struct usb_gadget_driver *driver,
997 int (*bind)(struct usb_gadget *)); 997 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
998static int goku_stop(struct usb_gadget_driver *driver); 998static int goku_stop(struct usb_gadget_driver *driver);
999 999
1000static const struct usb_gadget_ops goku_ops = { 1000static const struct usb_gadget_ops goku_ops = {
@@ -1348,7 +1348,7 @@ static struct goku_udc *the_controller;
1348 * the driver might get unbound. 1348 * the driver might get unbound.
1349 */ 1349 */
1350static int goku_start(struct usb_gadget_driver *driver, 1350static int goku_start(struct usb_gadget_driver *driver,
1351 int (*bind)(struct usb_gadget *)) 1351 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1352{ 1352{
1353 struct goku_udc *dev = the_controller; 1353 struct goku_udc *dev = the_controller;
1354 int retval; 1354 int retval;
@@ -1368,7 +1368,7 @@ static int goku_start(struct usb_gadget_driver *driver,
1368 driver->driver.bus = NULL; 1368 driver->driver.bus = NULL;
1369 dev->driver = driver; 1369 dev->driver = driver;
1370 dev->gadget.dev.driver = &driver->driver; 1370 dev->gadget.dev.driver = &driver->driver;
1371 retval = bind(&dev->gadget); 1371 retval = bind(&dev->gadget, driver);
1372 if (retval) { 1372 if (retval) {
1373 DBG(dev, "bind to driver %s --> error %d\n", 1373 DBG(dev, "bind to driver %s --> error %d\n",
1374 driver->driver.name, retval); 1374 driver->driver.name, retval);
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index 3493adf064f5..74130f6c12c0 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -15,7 +15,10 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/module.h>
19#include <linux/usb/composite.h>
18 20
21#include "gadget_chips.h"
19#define DRIVER_DESC "HID Gadget" 22#define DRIVER_DESC "HID Gadget"
20#define DRIVER_VERSION "2010/03/16" 23#define DRIVER_VERSION "2010/03/16"
21 24
@@ -33,12 +36,6 @@
33 * the runtime footprint, and giving us at least some parts of what 36 * the runtime footprint, and giving us at least some parts of what
34 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
35 */ 38 */
36
37#include "composite.c"
38#include "usbstring.c"
39#include "config.c"
40#include "epautoconf.c"
41
42#include "f_hid.c" 39#include "f_hid.c"
43 40
44 41
@@ -50,6 +47,7 @@ struct hidg_func_node {
50static LIST_HEAD(hidg_func_list); 47static LIST_HEAD(hidg_func_list);
51 48
52/*-------------------------------------------------------------------------*/ 49/*-------------------------------------------------------------------------*/
50USB_GADGET_COMPOSITE_OPTIONS();
53 51
54static struct usb_device_descriptor device_desc = { 52static struct usb_device_descriptor device_desc = {
55 .bLength = sizeof device_desc, 53 .bLength = sizeof device_desc,
@@ -92,15 +90,10 @@ static const struct usb_descriptor_header *otg_desc[] = {
92 90
93 91
94/* string IDs are assigned dynamically */ 92/* string IDs are assigned dynamically */
95
96#define STRING_MANUFACTURER_IDX 0
97#define STRING_PRODUCT_IDX 1
98
99static char manufacturer[50];
100
101static struct usb_string strings_dev[] = { 93static struct usb_string strings_dev[] = {
102 [STRING_MANUFACTURER_IDX].s = manufacturer, 94 [USB_GADGET_MANUFACTURER_IDX].s = "",
103 [STRING_PRODUCT_IDX].s = DRIVER_DESC, 95 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
96 [USB_GADGET_SERIAL_IDX].s = "",
104 { } /* end of list */ 97 { } /* end of list */
105}; 98};
106 99
@@ -150,7 +143,7 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
150{ 143{
151 struct usb_gadget *gadget = cdev->gadget; 144 struct usb_gadget *gadget = cdev->gadget;
152 struct list_head *tmp; 145 struct list_head *tmp;
153 int status, gcnum, funcs = 0; 146 int status, funcs = 0;
154 147
155 list_for_each(tmp, &hidg_func_list) 148 list_for_each(tmp, &hidg_func_list)
156 funcs++; 149 funcs++;
@@ -163,38 +156,22 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
163 if (status < 0) 156 if (status < 0)
164 return status; 157 return status;
165 158
166 gcnum = usb_gadget_controller_number(gadget);
167 if (gcnum >= 0)
168 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
169 else
170 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
171
172
173 /* Allocate string descriptor numbers ... note that string 159 /* Allocate string descriptor numbers ... note that string
174 * contents can be overridden by the composite_dev glue. 160 * contents can be overridden by the composite_dev glue.
175 */ 161 */
176 162
177 /* device descriptor strings: manufacturer, product */ 163 status = usb_string_ids_tab(cdev, strings_dev);
178 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
179 init_utsname()->sysname, init_utsname()->release,
180 gadget->name);
181 status = usb_string_id(cdev);
182 if (status < 0)
183 return status;
184 strings_dev[STRING_MANUFACTURER_IDX].id = status;
185 device_desc.iManufacturer = status;
186
187 status = usb_string_id(cdev);
188 if (status < 0) 164 if (status < 0)
189 return status; 165 return status;
190 strings_dev[STRING_PRODUCT_IDX].id = status; 166 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
191 device_desc.iProduct = status; 167 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
192 168
193 /* register our configuration */ 169 /* register our configuration */
194 status = usb_add_config(cdev, &config_driver, do_config); 170 status = usb_add_config(cdev, &config_driver, do_config);
195 if (status < 0) 171 if (status < 0)
196 return status; 172 return status;
197 173
174 usb_composite_overwrite_options(cdev, &coverwrite);
198 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 175 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
199 176
200 return 0; 177 return 0;
@@ -242,11 +219,12 @@ static int __devexit hidg_plat_driver_remove(struct platform_device *pdev)
242/****************************** Some noise ******************************/ 219/****************************** Some noise ******************************/
243 220
244 221
245static struct usb_composite_driver hidg_driver = { 222static __refdata struct usb_composite_driver hidg_driver = {
246 .name = "g_hid", 223 .name = "g_hid",
247 .dev = &device_desc, 224 .dev = &device_desc,
248 .strings = dev_strings, 225 .strings = dev_strings,
249 .max_speed = USB_SPEED_HIGH, 226 .max_speed = USB_SPEED_HIGH,
227 .bind = hid_bind,
250 .unbind = __exit_p(hid_unbind), 228 .unbind = __exit_p(hid_unbind),
251}; 229};
252 230
@@ -272,7 +250,7 @@ static int __init hidg_init(void)
272 if (status < 0) 250 if (status < 0)
273 return status; 251 return status;
274 252
275 status = usb_composite_probe(&hidg_driver, hid_bind); 253 status = usb_composite_probe(&hidg_driver);
276 if (status < 0) 254 if (status < 0)
277 platform_driver_unregister(&hidg_plat_driver); 255 platform_driver_unregister(&hidg_plat_driver);
278 256
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index e58b16442971..4bb6d53f2de3 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -828,7 +828,6 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
828 if (value == 0) 828 if (value == 0)
829 data->state = STATE_EP_ENABLED; 829 data->state = STATE_EP_ENABLED;
830 break; 830 break;
831#ifdef CONFIG_USB_GADGET_DUALSPEED
832 case USB_SPEED_HIGH: 831 case USB_SPEED_HIGH:
833 /* fails if caller didn't provide that descriptor... */ 832 /* fails if caller didn't provide that descriptor... */
834 ep->desc = &data->hs_desc; 833 ep->desc = &data->hs_desc;
@@ -836,7 +835,6 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
836 if (value == 0) 835 if (value == 0)
837 data->state = STATE_EP_ENABLED; 836 data->state = STATE_EP_ENABLED;
838 break; 837 break;
839#endif
840 default: 838 default:
841 DBG(data->dev, "unconnected, %s init abandoned\n", 839 DBG(data->dev, "unconnected, %s init abandoned\n",
842 data->name); 840 data->name);
@@ -1324,7 +1322,6 @@ static const struct file_operations ep0_io_operations = {
1324 * Unrecognized ep0 requests may be handled in user space. 1322 * Unrecognized ep0 requests may be handled in user space.
1325 */ 1323 */
1326 1324
1327#ifdef CONFIG_USB_GADGET_DUALSPEED
1328static void make_qualifier (struct dev_data *dev) 1325static void make_qualifier (struct dev_data *dev)
1329{ 1326{
1330 struct usb_qualifier_descriptor qual; 1327 struct usb_qualifier_descriptor qual;
@@ -1347,7 +1344,6 @@ static void make_qualifier (struct dev_data *dev)
1347 1344
1348 memcpy (dev->rbuf, &qual, sizeof qual); 1345 memcpy (dev->rbuf, &qual, sizeof qual);
1349} 1346}
1350#endif
1351 1347
1352static int 1348static int
1353config_buf (struct dev_data *dev, u8 type, unsigned index) 1349config_buf (struct dev_data *dev, u8 type, unsigned index)
@@ -1427,7 +1423,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1427 dev->dev->bMaxPacketSize0 = dev->gadget->ep0->maxpacket; 1423 dev->dev->bMaxPacketSize0 = dev->gadget->ep0->maxpacket;
1428 req->buf = dev->dev; 1424 req->buf = dev->dev;
1429 break; 1425 break;
1430#ifdef CONFIG_USB_GADGET_DUALSPEED
1431 case USB_DT_DEVICE_QUALIFIER: 1426 case USB_DT_DEVICE_QUALIFIER:
1432 if (!dev->hs_config) 1427 if (!dev->hs_config)
1433 break; 1428 break;
@@ -1437,7 +1432,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1437 break; 1432 break;
1438 case USB_DT_OTHER_SPEED_CONFIG: 1433 case USB_DT_OTHER_SPEED_CONFIG:
1439 // FALLTHROUGH 1434 // FALLTHROUGH
1440#endif
1441 case USB_DT_CONFIG: 1435 case USB_DT_CONFIG:
1442 value = config_buf (dev, 1436 value = config_buf (dev,
1443 w_value >> 8, 1437 w_value >> 8,
@@ -1685,8 +1679,8 @@ gadgetfs_unbind (struct usb_gadget *gadget)
1685 1679
1686static struct dev_data *the_device; 1680static struct dev_data *the_device;
1687 1681
1688static int 1682static int gadgetfs_bind(struct usb_gadget *gadget,
1689gadgetfs_bind (struct usb_gadget *gadget) 1683 struct usb_gadget_driver *driver)
1690{ 1684{
1691 struct dev_data *dev = the_device; 1685 struct dev_data *dev = the_device;
1692 1686
@@ -1763,12 +1757,8 @@ gadgetfs_suspend (struct usb_gadget *gadget)
1763} 1757}
1764 1758
1765static struct usb_gadget_driver gadgetfs_driver = { 1759static struct usb_gadget_driver gadgetfs_driver = {
1766#ifdef CONFIG_USB_GADGET_DUALSPEED
1767 .max_speed = USB_SPEED_HIGH,
1768#else
1769 .max_speed = USB_SPEED_FULL,
1770#endif
1771 .function = (char *) driver_desc, 1760 .function = (char *) driver_desc,
1761 .bind = gadgetfs_bind,
1772 .unbind = gadgetfs_unbind, 1762 .unbind = gadgetfs_unbind,
1773 .setup = gadgetfs_setup, 1763 .setup = gadgetfs_setup,
1774 .disconnect = gadgetfs_disconnect, 1764 .disconnect = gadgetfs_disconnect,
@@ -1783,7 +1773,8 @@ static struct usb_gadget_driver gadgetfs_driver = {
1783 1773
1784static void gadgetfs_nop(struct usb_gadget *arg) { } 1774static void gadgetfs_nop(struct usb_gadget *arg) { }
1785 1775
1786static int gadgetfs_probe (struct usb_gadget *gadget) 1776static int gadgetfs_probe(struct usb_gadget *gadget,
1777 struct usb_gadget_driver *driver)
1787{ 1778{
1788 CHIP = gadget->name; 1779 CHIP = gadget->name;
1789 return -EISNAM; 1780 return -EISNAM;
@@ -1791,6 +1782,7 @@ static int gadgetfs_probe (struct usb_gadget *gadget)
1791 1782
1792static struct usb_gadget_driver probe_driver = { 1783static struct usb_gadget_driver probe_driver = {
1793 .max_speed = USB_SPEED_HIGH, 1784 .max_speed = USB_SPEED_HIGH,
1785 .bind = gadgetfs_probe,
1794 .unbind = gadgetfs_nop, 1786 .unbind = gadgetfs_nop,
1795 .setup = (void *)gadgetfs_nop, 1787 .setup = (void *)gadgetfs_nop,
1796 .disconnect = gadgetfs_nop, 1788 .disconnect = gadgetfs_nop,
@@ -1900,7 +1892,12 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1900 1892
1901 /* triggers gadgetfs_bind(); then we can enumerate. */ 1893 /* triggers gadgetfs_bind(); then we can enumerate. */
1902 spin_unlock_irq (&dev->lock); 1894 spin_unlock_irq (&dev->lock);
1903 value = usb_gadget_probe_driver(&gadgetfs_driver, gadgetfs_bind); 1895 if (dev->hs_config)
1896 gadgetfs_driver.max_speed = USB_SPEED_HIGH;
1897 else
1898 gadgetfs_driver.max_speed = USB_SPEED_FULL;
1899
1900 value = usb_gadget_probe_driver(&gadgetfs_driver);
1904 if (value != 0) { 1901 if (value != 0) {
1905 kfree (dev->buf); 1902 kfree (dev->buf);
1906 dev->buf = NULL; 1903 dev->buf = NULL;
@@ -2039,7 +2036,7 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
2039 return -ESRCH; 2036 return -ESRCH;
2040 2037
2041 /* fake probe to determine $CHIP */ 2038 /* fake probe to determine $CHIP */
2042 (void) usb_gadget_probe_driver(&probe_driver, gadgetfs_probe); 2039 usb_gadget_probe_driver(&probe_driver);
2043 if (!CHIP) 2040 if (!CHIP)
2044 return -ENODEV; 2041 return -ENODEV;
2045 2042
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index 3a6cdd0c7c5a..f696fb9b136d 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -141,8 +141,6 @@ struct lpc32xx_ep {
141 u32 totalints; 141 u32 totalints;
142 142
143 bool wedge; 143 bool wedge;
144
145 const struct usb_endpoint_descriptor *desc;
146}; 144};
147 145
148/* 146/*
@@ -556,10 +554,8 @@ static int proc_udc_show(struct seq_file *s, void *unused)
556 554
557 if (udc->enabled && udc->vbus) { 555 if (udc->enabled && udc->vbus) {
558 proc_ep_show(s, &udc->ep[0]); 556 proc_ep_show(s, &udc->ep[0]);
559 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { 557 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list)
560 if (ep->desc) 558 proc_ep_show(s, ep);
561 proc_ep_show(s, ep);
562 }
563 } 559 }
564 560
565 spin_unlock_irqrestore(&udc->lock, flags); 561 spin_unlock_irqrestore(&udc->lock, flags);
@@ -1453,7 +1449,6 @@ static void udc_reinit(struct lpc32xx_udc *udc)
1453 1449
1454 if (i != 0) 1450 if (i != 0)
1455 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); 1451 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
1456 ep->desc = NULL;
1457 ep->ep.maxpacket = ep->maxpacket; 1452 ep->ep.maxpacket = ep->maxpacket;
1458 INIT_LIST_HEAD(&ep->queue); 1453 INIT_LIST_HEAD(&ep->queue);
1459 ep->req_pending = 0; 1454 ep->req_pending = 0;
@@ -1515,7 +1510,7 @@ static void nuke(struct lpc32xx_ep *ep, int status)
1515 done(ep, req, status); 1510 done(ep, req, status);
1516 } 1511 }
1517 1512
1518 if (ep->desc && status == -ESHUTDOWN) { 1513 if (status == -ESHUTDOWN) {
1519 uda_disable_hwepint(ep->udc, ep->hwep_num); 1514 uda_disable_hwepint(ep->udc, ep->hwep_num);
1520 udc_disable_hwep(ep->udc, ep->hwep_num); 1515 udc_disable_hwep(ep->udc, ep->hwep_num);
1521 } 1516 }
@@ -1658,9 +1653,6 @@ static int lpc32xx_ep_disable(struct usb_ep *_ep)
1658 1653
1659 nuke(ep, -ESHUTDOWN); 1654 nuke(ep, -ESHUTDOWN);
1660 1655
1661 /* restore the endpoint's pristine config */
1662 ep->desc = NULL;
1663
1664 /* Clear all DMA statuses for this EP */ 1656 /* Clear all DMA statuses for this EP */
1665 udc_ep_dma_disable(udc, ep->hwep_num); 1657 udc_ep_dma_disable(udc, ep->hwep_num);
1666 writel(1 << ep->hwep_num, USBD_EOTINTCLR(udc->udp_baseaddr)); 1658 writel(1 << ep->hwep_num, USBD_EOTINTCLR(udc->udp_baseaddr));
@@ -1696,7 +1688,7 @@ static int lpc32xx_ep_enable(struct usb_ep *_ep,
1696 unsigned long flags; 1688 unsigned long flags;
1697 1689
1698 /* Verify EP data */ 1690 /* Verify EP data */
1699 if ((!_ep) || (!ep) || (!desc) || (ep->desc) || 1691 if ((!_ep) || (!ep) || (!desc) ||
1700 (desc->bDescriptorType != USB_DT_ENDPOINT)) { 1692 (desc->bDescriptorType != USB_DT_ENDPOINT)) {
1701 dev_dbg(udc->dev, "bad ep or descriptor\n"); 1693 dev_dbg(udc->dev, "bad ep or descriptor\n");
1702 return -EINVAL; 1694 return -EINVAL;
@@ -1754,7 +1746,6 @@ static int lpc32xx_ep_enable(struct usb_ep *_ep,
1754 1746
1755 /* Initialize endpoint to match the selected descriptor */ 1747 /* Initialize endpoint to match the selected descriptor */
1756 ep->is_in = (desc->bEndpointAddress & USB_DIR_IN) != 0; 1748 ep->is_in = (desc->bEndpointAddress & USB_DIR_IN) != 0;
1757 ep->desc = desc;
1758 ep->ep.maxpacket = maxpacket; 1749 ep->ep.maxpacket = maxpacket;
1759 1750
1760 /* Map hardware endpoint from base and direction */ 1751 /* Map hardware endpoint from base and direction */
@@ -1837,7 +1828,7 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep,
1837 1828
1838 udc = ep->udc; 1829 udc = ep->udc;
1839 1830
1840 if (!_ep || (!ep->desc && ep->hwep_num_base != 0)) { 1831 if (!_ep) {
1841 dev_dbg(udc->dev, "invalid ep\n"); 1832 dev_dbg(udc->dev, "invalid ep\n");
1842 return -EINVAL; 1833 return -EINVAL;
1843 } 1834 }
@@ -1976,7 +1967,7 @@ static int lpc32xx_ep_set_halt(struct usb_ep *_ep, int value)
1976 struct lpc32xx_udc *udc = ep->udc; 1967 struct lpc32xx_udc *udc = ep->udc;
1977 unsigned long flags; 1968 unsigned long flags;
1978 1969
1979 if ((!ep) || (ep->desc == NULL) || (ep->hwep_num <= 1)) 1970 if ((!ep) || (ep->hwep_num <= 1))
1980 return -EINVAL; 1971 return -EINVAL;
1981 1972
1982 /* Don't halt an IN EP */ 1973 /* Don't halt an IN EP */
@@ -2262,7 +2253,7 @@ static int udc_get_status(struct lpc32xx_udc *udc, u16 reqtype, u16 wIndex)
2262 case USB_RECIP_ENDPOINT: 2253 case USB_RECIP_ENDPOINT:
2263 tmp = wIndex & USB_ENDPOINT_NUMBER_MASK; 2254 tmp = wIndex & USB_ENDPOINT_NUMBER_MASK;
2264 ep = &udc->ep[tmp]; 2255 ep = &udc->ep[tmp];
2265 if ((tmp == 0) || (tmp >= NUM_ENDPOINTS) || (tmp && !ep->desc)) 2256 if ((tmp == 0) || (tmp >= NUM_ENDPOINTS))
2266 return -EOPNOTSUPP; 2257 return -EOPNOTSUPP;
2267 2258
2268 if (wIndex & USB_DIR_IN) { 2259 if (wIndex & USB_DIR_IN) {
@@ -2599,9 +2590,8 @@ static int lpc32xx_pullup(struct usb_gadget *gadget, int is_on)
2599 return 0; 2590 return 0;
2600} 2591}
2601 2592
2602static int lpc32xx_start(struct usb_gadget_driver *driver, 2593static int lpc32xx_start(struct usb_gadget *, struct usb_gadget_driver *);
2603 int (*bind)(struct usb_gadget *)); 2594static int lpc32xx_stop(struct usb_gadget *, struct usb_gadget_driver *);
2604static int lpc32xx_stop(struct usb_gadget_driver *driver);
2605 2595
2606static const struct usb_gadget_ops lpc32xx_udc_ops = { 2596static const struct usb_gadget_ops lpc32xx_udc_ops = {
2607 .get_frame = lpc32xx_get_frame, 2597 .get_frame = lpc32xx_get_frame,
@@ -2609,8 +2599,8 @@ static const struct usb_gadget_ops lpc32xx_udc_ops = {
2609 .set_selfpowered = lpc32xx_set_selfpowered, 2599 .set_selfpowered = lpc32xx_set_selfpowered,
2610 .vbus_session = lpc32xx_vbus_session, 2600 .vbus_session = lpc32xx_vbus_session,
2611 .pullup = lpc32xx_pullup, 2601 .pullup = lpc32xx_pullup,
2612 .start = lpc32xx_start, 2602 .udc_start = lpc32xx_start,
2613 .stop = lpc32xx_stop, 2603 .udc_stop = lpc32xx_stop,
2614}; 2604};
2615 2605
2616static void nop_release(struct device *dev) 2606static void nop_release(struct device *dev)
@@ -2618,10 +2608,9 @@ static void nop_release(struct device *dev)
2618 /* nothing to free */ 2608 /* nothing to free */
2619} 2609}
2620 2610
2621static struct lpc32xx_udc controller = { 2611static const struct lpc32xx_udc controller_template = {
2622 .gadget = { 2612 .gadget = {
2623 .ops = &lpc32xx_udc_ops, 2613 .ops = &lpc32xx_udc_ops,
2624 .ep0 = &controller.ep[0].ep,
2625 .name = driver_name, 2614 .name = driver_name,
2626 .dev = { 2615 .dev = {
2627 .init_name = "gadget", 2616 .init_name = "gadget",
@@ -2633,7 +2622,6 @@ static struct lpc32xx_udc controller = {
2633 .name = "ep0", 2622 .name = "ep0",
2634 .ops = &lpc32xx_ep_ops, 2623 .ops = &lpc32xx_ep_ops,
2635 }, 2624 },
2636 .udc = &controller,
2637 .maxpacket = 64, 2625 .maxpacket = 64,
2638 .hwep_num_base = 0, 2626 .hwep_num_base = 0,
2639 .hwep_num = 0, /* Can be 0 or 1, has special handling */ 2627 .hwep_num = 0, /* Can be 0 or 1, has special handling */
@@ -2645,7 +2633,6 @@ static struct lpc32xx_udc controller = {
2645 .name = "ep1-int", 2633 .name = "ep1-int",
2646 .ops = &lpc32xx_ep_ops, 2634 .ops = &lpc32xx_ep_ops,
2647 }, 2635 },
2648 .udc = &controller,
2649 .maxpacket = 64, 2636 .maxpacket = 64,
2650 .hwep_num_base = 2, 2637 .hwep_num_base = 2,
2651 .hwep_num = 0, /* 2 or 3, will be set later */ 2638 .hwep_num = 0, /* 2 or 3, will be set later */
@@ -2657,7 +2644,6 @@ static struct lpc32xx_udc controller = {
2657 .name = "ep2-bulk", 2644 .name = "ep2-bulk",
2658 .ops = &lpc32xx_ep_ops, 2645 .ops = &lpc32xx_ep_ops,
2659 }, 2646 },
2660 .udc = &controller,
2661 .maxpacket = 64, 2647 .maxpacket = 64,
2662 .hwep_num_base = 4, 2648 .hwep_num_base = 4,
2663 .hwep_num = 0, /* 4 or 5, will be set later */ 2649 .hwep_num = 0, /* 4 or 5, will be set later */
@@ -2669,7 +2655,6 @@ static struct lpc32xx_udc controller = {
2669 .name = "ep3-iso", 2655 .name = "ep3-iso",
2670 .ops = &lpc32xx_ep_ops, 2656 .ops = &lpc32xx_ep_ops,
2671 }, 2657 },
2672 .udc = &controller,
2673 .maxpacket = 1023, 2658 .maxpacket = 1023,
2674 .hwep_num_base = 6, 2659 .hwep_num_base = 6,
2675 .hwep_num = 0, /* 6 or 7, will be set later */ 2660 .hwep_num = 0, /* 6 or 7, will be set later */
@@ -2681,7 +2666,6 @@ static struct lpc32xx_udc controller = {
2681 .name = "ep4-int", 2666 .name = "ep4-int",
2682 .ops = &lpc32xx_ep_ops, 2667 .ops = &lpc32xx_ep_ops,
2683 }, 2668 },
2684 .udc = &controller,
2685 .maxpacket = 64, 2669 .maxpacket = 64,
2686 .hwep_num_base = 8, 2670 .hwep_num_base = 8,
2687 .hwep_num = 0, /* 8 or 9, will be set later */ 2671 .hwep_num = 0, /* 8 or 9, will be set later */
@@ -2693,7 +2677,6 @@ static struct lpc32xx_udc controller = {
2693 .name = "ep5-bulk", 2677 .name = "ep5-bulk",
2694 .ops = &lpc32xx_ep_ops, 2678 .ops = &lpc32xx_ep_ops,
2695 }, 2679 },
2696 .udc = &controller,
2697 .maxpacket = 64, 2680 .maxpacket = 64,
2698 .hwep_num_base = 10, 2681 .hwep_num_base = 10,
2699 .hwep_num = 0, /* 10 or 11, will be set later */ 2682 .hwep_num = 0, /* 10 or 11, will be set later */
@@ -2705,7 +2688,6 @@ static struct lpc32xx_udc controller = {
2705 .name = "ep6-iso", 2688 .name = "ep6-iso",
2706 .ops = &lpc32xx_ep_ops, 2689 .ops = &lpc32xx_ep_ops,
2707 }, 2690 },
2708 .udc = &controller,
2709 .maxpacket = 1023, 2691 .maxpacket = 1023,
2710 .hwep_num_base = 12, 2692 .hwep_num_base = 12,
2711 .hwep_num = 0, /* 12 or 13, will be set later */ 2693 .hwep_num = 0, /* 12 or 13, will be set later */
@@ -2717,7 +2699,6 @@ static struct lpc32xx_udc controller = {
2717 .name = "ep7-int", 2699 .name = "ep7-int",
2718 .ops = &lpc32xx_ep_ops, 2700 .ops = &lpc32xx_ep_ops,
2719 }, 2701 },
2720 .udc = &controller,
2721 .maxpacket = 64, 2702 .maxpacket = 64,
2722 .hwep_num_base = 14, 2703 .hwep_num_base = 14,
2723 .hwep_num = 0, 2704 .hwep_num = 0,
@@ -2729,7 +2710,6 @@ static struct lpc32xx_udc controller = {
2729 .name = "ep8-bulk", 2710 .name = "ep8-bulk",
2730 .ops = &lpc32xx_ep_ops, 2711 .ops = &lpc32xx_ep_ops,
2731 }, 2712 },
2732 .udc = &controller,
2733 .maxpacket = 64, 2713 .maxpacket = 64,
2734 .hwep_num_base = 16, 2714 .hwep_num_base = 16,
2735 .hwep_num = 0, 2715 .hwep_num = 0,
@@ -2741,7 +2721,6 @@ static struct lpc32xx_udc controller = {
2741 .name = "ep9-iso", 2721 .name = "ep9-iso",
2742 .ops = &lpc32xx_ep_ops, 2722 .ops = &lpc32xx_ep_ops,
2743 }, 2723 },
2744 .udc = &controller,
2745 .maxpacket = 1023, 2724 .maxpacket = 1023,
2746 .hwep_num_base = 18, 2725 .hwep_num_base = 18,
2747 .hwep_num = 0, 2726 .hwep_num = 0,
@@ -2753,7 +2732,6 @@ static struct lpc32xx_udc controller = {
2753 .name = "ep10-int", 2732 .name = "ep10-int",
2754 .ops = &lpc32xx_ep_ops, 2733 .ops = &lpc32xx_ep_ops,
2755 }, 2734 },
2756 .udc = &controller,
2757 .maxpacket = 64, 2735 .maxpacket = 64,
2758 .hwep_num_base = 20, 2736 .hwep_num_base = 20,
2759 .hwep_num = 0, 2737 .hwep_num = 0,
@@ -2765,7 +2743,6 @@ static struct lpc32xx_udc controller = {
2765 .name = "ep11-bulk", 2743 .name = "ep11-bulk",
2766 .ops = &lpc32xx_ep_ops, 2744 .ops = &lpc32xx_ep_ops,
2767 }, 2745 },
2768 .udc = &controller,
2769 .maxpacket = 64, 2746 .maxpacket = 64,
2770 .hwep_num_base = 22, 2747 .hwep_num_base = 22,
2771 .hwep_num = 0, 2748 .hwep_num = 0,
@@ -2777,7 +2754,6 @@ static struct lpc32xx_udc controller = {
2777 .name = "ep12-iso", 2754 .name = "ep12-iso",
2778 .ops = &lpc32xx_ep_ops, 2755 .ops = &lpc32xx_ep_ops,
2779 }, 2756 },
2780 .udc = &controller,
2781 .maxpacket = 1023, 2757 .maxpacket = 1023,
2782 .hwep_num_base = 24, 2758 .hwep_num_base = 24,
2783 .hwep_num = 0, 2759 .hwep_num = 0,
@@ -2789,7 +2765,6 @@ static struct lpc32xx_udc controller = {
2789 .name = "ep13-int", 2765 .name = "ep13-int",
2790 .ops = &lpc32xx_ep_ops, 2766 .ops = &lpc32xx_ep_ops,
2791 }, 2767 },
2792 .udc = &controller,
2793 .maxpacket = 64, 2768 .maxpacket = 64,
2794 .hwep_num_base = 26, 2769 .hwep_num_base = 26,
2795 .hwep_num = 0, 2770 .hwep_num = 0,
@@ -2801,7 +2776,6 @@ static struct lpc32xx_udc controller = {
2801 .name = "ep14-bulk", 2776 .name = "ep14-bulk",
2802 .ops = &lpc32xx_ep_ops, 2777 .ops = &lpc32xx_ep_ops,
2803 }, 2778 },
2804 .udc = &controller,
2805 .maxpacket = 64, 2779 .maxpacket = 64,
2806 .hwep_num_base = 28, 2780 .hwep_num_base = 28,
2807 .hwep_num = 0, 2781 .hwep_num = 0,
@@ -2813,7 +2787,6 @@ static struct lpc32xx_udc controller = {
2813 .name = "ep15-bulk", 2787 .name = "ep15-bulk",
2814 .ops = &lpc32xx_ep_ops, 2788 .ops = &lpc32xx_ep_ops,
2815 }, 2789 },
2816 .udc = &controller,
2817 .maxpacket = 1023, 2790 .maxpacket = 1023,
2818 .hwep_num_base = 30, 2791 .hwep_num_base = 30,
2819 .hwep_num = 0, 2792 .hwep_num = 0,
@@ -2987,14 +2960,13 @@ static irqreturn_t lpc32xx_usb_vbus_irq(int irq, void *_udc)
2987 return IRQ_HANDLED; 2960 return IRQ_HANDLED;
2988} 2961}
2989 2962
2990static int lpc32xx_start(struct usb_gadget_driver *driver, 2963static int lpc32xx_start(struct usb_gadget *gadget,
2991 int (*bind)(struct usb_gadget *)) 2964 struct usb_gadget_driver *driver)
2992{ 2965{
2993 struct lpc32xx_udc *udc = &controller; 2966 struct lpc32xx_udc *udc = to_udc(gadget);
2994 int retval, i; 2967 int i;
2995 2968
2996 if (!driver || driver->max_speed < USB_SPEED_FULL || 2969 if (!driver || driver->max_speed < USB_SPEED_FULL || !driver->setup) {
2997 !bind || !driver->setup) {
2998 dev_err(udc->dev, "bad parameter.\n"); 2970 dev_err(udc->dev, "bad parameter.\n");
2999 return -EINVAL; 2971 return -EINVAL;
3000 } 2972 }
@@ -3011,18 +2983,6 @@ static int lpc32xx_start(struct usb_gadget_driver *driver,
3011 udc->selfpowered = 1; 2983 udc->selfpowered = 1;
3012 udc->vbus = 0; 2984 udc->vbus = 0;
3013 2985
3014 retval = bind(&udc->gadget);
3015 if (retval) {
3016 dev_err(udc->dev, "bind() returned %d\n", retval);
3017 udc->enabled = 0;
3018 udc->selfpowered = 0;
3019 udc->driver = NULL;
3020 udc->gadget.dev.driver = NULL;
3021 return retval;
3022 }
3023
3024 dev_dbg(udc->dev, "bound to %s\n", driver->driver.name);
3025
3026 /* Force VBUS process once to check for cable insertion */ 2986 /* Force VBUS process once to check for cable insertion */
3027 udc->last_vbus = udc->vbus = 0; 2987 udc->last_vbus = udc->vbus = 0;
3028 schedule_work(&udc->vbus_job); 2988 schedule_work(&udc->vbus_job);
@@ -3034,22 +2994,19 @@ static int lpc32xx_start(struct usb_gadget_driver *driver,
3034 return 0; 2994 return 0;
3035} 2995}
3036 2996
3037static int lpc32xx_stop(struct usb_gadget_driver *driver) 2997static int lpc32xx_stop(struct usb_gadget *gadget,
2998 struct usb_gadget_driver *driver)
3038{ 2999{
3039 int i; 3000 int i;
3040 struct lpc32xx_udc *udc = &controller; 3001 struct lpc32xx_udc *udc = to_udc(gadget);
3041 3002
3042 if (!driver || driver != udc->driver || !driver->unbind) 3003 if (!driver || driver != udc->driver)
3043 return -EINVAL; 3004 return -EINVAL;
3044 3005
3045 /* Disable USB pullup */
3046 isp1301_pullup_enable(udc, 0, 1);
3047
3048 for (i = IRQ_USB_LP; i <= IRQ_USB_ATX; i++) 3006 for (i = IRQ_USB_LP; i <= IRQ_USB_ATX; i++)
3049 disable_irq(udc->udp_irq[i]); 3007 disable_irq(udc->udp_irq[i]);
3050 3008
3051 if (udc->clocked) { 3009 if (udc->clocked) {
3052
3053 spin_lock(&udc->lock); 3010 spin_lock(&udc->lock);
3054 stop_activity(udc); 3011 stop_activity(udc);
3055 spin_unlock(&udc->lock); 3012 spin_unlock(&udc->lock);
@@ -3069,20 +3026,16 @@ static int lpc32xx_stop(struct usb_gadget_driver *driver)
3069 } 3026 }
3070 3027
3071 udc->enabled = 0; 3028 udc->enabled = 0;
3072 pullup(udc, 0);
3073
3074 driver->unbind(&udc->gadget);
3075 udc->gadget.dev.driver = NULL; 3029 udc->gadget.dev.driver = NULL;
3076 udc->driver = NULL; 3030 udc->driver = NULL;
3077 3031
3078 dev_dbg(udc->dev, "unbound from %s\n", driver->driver.name);
3079 return 0; 3032 return 0;
3080} 3033}
3081 3034
3082static void lpc32xx_udc_shutdown(struct platform_device *dev) 3035static void lpc32xx_udc_shutdown(struct platform_device *dev)
3083{ 3036{
3084 /* Force disconnect on reboot */ 3037 /* Force disconnect on reboot */
3085 struct lpc32xx_udc *udc = &controller; 3038 struct lpc32xx_udc *udc = platform_get_drvdata(dev);
3086 3039
3087 pullup(udc, 0); 3040 pullup(udc, 0);
3088} 3041}
@@ -3120,12 +3073,21 @@ static u64 lpc32xx_usbd_dmamask = ~(u32) 0x7F;
3120static int __init lpc32xx_udc_probe(struct platform_device *pdev) 3073static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3121{ 3074{
3122 struct device *dev = &pdev->dev; 3075 struct device *dev = &pdev->dev;
3123 struct lpc32xx_udc *udc = &controller; 3076 struct lpc32xx_udc *udc;
3124 int retval, i; 3077 int retval, i;
3125 struct resource *res; 3078 struct resource *res;
3126 dma_addr_t dma_handle; 3079 dma_addr_t dma_handle;
3127 struct device_node *isp1301_node; 3080 struct device_node *isp1301_node;
3128 3081
3082 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
3083 if (!udc)
3084 return -ENOMEM;
3085
3086 memcpy(udc, &controller_template, sizeof(*udc));
3087 for (i = 0; i <= 15; i++)
3088 udc->ep[i].udc = udc;
3089 udc->gadget.ep0 = &udc->ep[0].ep;
3090
3129 /* init software state */ 3091 /* init software state */
3130 udc->gadget.dev.parent = dev; 3092 udc->gadget.dev.parent = dev;
3131 udc->pdev = pdev; 3093 udc->pdev = pdev;
@@ -3140,8 +3102,10 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3140 } 3102 }
3141 3103
3142 udc->isp1301_i2c_client = isp1301_get_client(isp1301_node); 3104 udc->isp1301_i2c_client = isp1301_get_client(isp1301_node);
3143 if (!udc->isp1301_i2c_client) 3105 if (!udc->isp1301_i2c_client) {
3144 return -EPROBE_DEFER; 3106 retval = -EPROBE_DEFER;
3107 goto phy_fail;
3108 }
3145 3109
3146 dev_info(udc->dev, "ISP1301 I2C device at address 0x%x\n", 3110 dev_info(udc->dev, "ISP1301 I2C device at address 0x%x\n",
3147 udc->isp1301_i2c_client->addr); 3111 udc->isp1301_i2c_client->addr);
@@ -3160,8 +3124,10 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3160 * IORESOURCE_IRQ, USB transceiver interrupt number 3124 * IORESOURCE_IRQ, USB transceiver interrupt number
3161 */ 3125 */
3162 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 3126 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3163 if (!res) 3127 if (!res) {
3164 return -ENXIO; 3128 retval = -ENXIO;
3129 goto resource_fail;
3130 }
3165 3131
3166 spin_lock_init(&udc->lock); 3132 spin_lock_init(&udc->lock);
3167 3133
@@ -3171,7 +3137,8 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3171 if (udc->udp_irq[i] < 0) { 3137 if (udc->udp_irq[i] < 0) {
3172 dev_err(udc->dev, 3138 dev_err(udc->dev,
3173 "irq resource %d not available!\n", i); 3139 "irq resource %d not available!\n", i);
3174 return udc->udp_irq[i]; 3140 retval = udc->udp_irq[i];
3141 goto irq_fail;
3175 } 3142 }
3176 } 3143 }
3177 3144
@@ -3179,7 +3146,8 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3179 udc->io_p_size = resource_size(res); 3146 udc->io_p_size = resource_size(res);
3180 if (!request_mem_region(udc->io_p_start, udc->io_p_size, driver_name)) { 3147 if (!request_mem_region(udc->io_p_start, udc->io_p_size, driver_name)) {
3181 dev_err(udc->dev, "someone's using UDC memory\n"); 3148 dev_err(udc->dev, "someone's using UDC memory\n");
3182 return -EBUSY; 3149 retval = -EBUSY;
3150 goto request_mem_region_fail;
3183 } 3151 }
3184 3152
3185 udc->udp_baseaddr = ioremap(udc->io_p_start, udc->io_p_size); 3153 udc->udp_baseaddr = ioremap(udc->io_p_start, udc->io_p_size);
@@ -3376,7 +3344,11 @@ pll_get_fail:
3376io_map_fail: 3344io_map_fail:
3377 release_mem_region(udc->io_p_start, udc->io_p_size); 3345 release_mem_region(udc->io_p_start, udc->io_p_size);
3378 dev_err(udc->dev, "%s probe failed, %d\n", driver_name, retval); 3346 dev_err(udc->dev, "%s probe failed, %d\n", driver_name, retval);
3379 3347request_mem_region_fail:
3348irq_fail:
3349resource_fail:
3350phy_fail:
3351 kfree(udc);
3380 return retval; 3352 return retval;
3381} 3353}
3382 3354
@@ -3414,6 +3386,7 @@ static int __devexit lpc32xx_udc_remove(struct platform_device *pdev)
3414 clk_put(udc->usb_pll_clk); 3386 clk_put(udc->usb_pll_clk);
3415 iounmap(udc->udp_baseaddr); 3387 iounmap(udc->udp_baseaddr);
3416 release_mem_region(udc->io_p_start, udc->io_p_size); 3388 release_mem_region(udc->io_p_start, udc->io_p_size);
3389 kfree(udc);
3417 3390
3418 return 0; 3391 return 0;
3419} 3392}
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index cf6bd626f3fe..b6401f1b56ce 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1466,7 +1466,7 @@ static struct usb_ep_ops m66592_ep_ops = {
1466static struct m66592 *the_controller; 1466static struct m66592 *the_controller;
1467 1467
1468static int m66592_start(struct usb_gadget_driver *driver, 1468static int m66592_start(struct usb_gadget_driver *driver,
1469 int (*bind)(struct usb_gadget *)) 1469 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1470{ 1470{
1471 struct m66592 *m66592 = the_controller; 1471 struct m66592 *m66592 = the_controller;
1472 int retval; 1472 int retval;
@@ -1492,7 +1492,7 @@ static int m66592_start(struct usb_gadget_driver *driver,
1492 goto error; 1492 goto error;
1493 } 1493 }
1494 1494
1495 retval = bind(&m66592->gadget); 1495 retval = bind(&m66592->gadget, driver);
1496 if (retval) { 1496 if (retval) {
1497 pr_err("bind to driver error (%d)\n", retval); 1497 pr_err("bind to driver error (%d)\n", retval);
1498 device_del(&m66592->gadget.dev); 1498 device_del(&m66592->gadget.dev);
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index 1f376eba31f6..080e577773d5 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -29,9 +29,8 @@
29 29
30 30
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/utsname.h>
33#include <linux/usb/ch9.h> 32#include <linux/usb/ch9.h>
34 33#include <linux/module.h>
35 34
36/*-------------------------------------------------------------------------*/ 35/*-------------------------------------------------------------------------*/
37 36
@@ -47,14 +46,10 @@
47 * the runtime footprint, and giving us at least some parts of what 46 * the runtime footprint, and giving us at least some parts of what
48 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 47 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
49 */ 48 */
50
51#include "composite.c"
52#include "usbstring.c"
53#include "config.c"
54#include "epautoconf.c"
55#include "f_mass_storage.c" 49#include "f_mass_storage.c"
56 50
57/*-------------------------------------------------------------------------*/ 51/*-------------------------------------------------------------------------*/
52USB_GADGET_COMPOSITE_OPTIONS();
58 53
59static struct usb_device_descriptor msg_device_desc = { 54static struct usb_device_descriptor msg_device_desc = {
60 .bLength = sizeof msg_device_desc, 55 .bLength = sizeof msg_device_desc,
@@ -85,6 +80,22 @@ static const struct usb_descriptor_header *otg_desc[] = {
85 NULL, 80 NULL,
86}; 81};
87 82
83static struct usb_string strings_dev[] = {
84 [USB_GADGET_MANUFACTURER_IDX].s = "",
85 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
86 [USB_GADGET_SERIAL_IDX].s = "",
87 { } /* end of list */
88};
89
90static struct usb_gadget_strings stringtab_dev = {
91 .language = 0x0409, /* en-us */
92 .strings = strings_dev,
93};
94
95static struct usb_gadget_strings *dev_strings[] = {
96 &stringtab_dev,
97 NULL,
98};
88 99
89/****************************** Configurations ******************************/ 100/****************************** Configurations ******************************/
90 101
@@ -143,10 +154,15 @@ static int __init msg_bind(struct usb_composite_dev *cdev)
143{ 154{
144 int status; 155 int status;
145 156
146 status = usb_add_config(cdev, &msg_config_driver, msg_do_config); 157 status = usb_string_ids_tab(cdev, strings_dev);
147 if (status < 0) 158 if (status < 0)
148 return status; 159 return status;
160 msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
149 161
162 status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
163 if (status < 0)
164 return status;
165 usb_composite_overwrite_options(cdev, &coverwrite);
150 dev_info(&cdev->gadget->dev, 166 dev_info(&cdev->gadget->dev,
151 DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 167 DRIVER_DESC ", version: " DRIVER_VERSION "\n");
152 set_bit(0, &msg_registered); 168 set_bit(0, &msg_registered);
@@ -156,12 +172,13 @@ static int __init msg_bind(struct usb_composite_dev *cdev)
156 172
157/****************************** Some noise ******************************/ 173/****************************** Some noise ******************************/
158 174
159static struct usb_composite_driver msg_driver = { 175static __refdata struct usb_composite_driver msg_driver = {
160 .name = "g_mass_storage", 176 .name = "g_mass_storage",
161 .dev = &msg_device_desc, 177 .dev = &msg_device_desc,
162 .iProduct = DRIVER_DESC,
163 .max_speed = USB_SPEED_SUPER, 178 .max_speed = USB_SPEED_SUPER,
164 .needs_serial = 1, 179 .needs_serial = 1,
180 .strings = dev_strings,
181 .bind = msg_bind,
165}; 182};
166 183
167MODULE_DESCRIPTION(DRIVER_DESC); 184MODULE_DESCRIPTION(DRIVER_DESC);
@@ -170,7 +187,7 @@ MODULE_LICENSE("GPL");
170 187
171static int __init msg_init(void) 188static int __init msg_init(void)
172{ 189{
173 return usb_composite_probe(&msg_driver, msg_bind); 190 return usb_composite_probe(&msg_driver);
174} 191}
175module_init(msg_init); 192module_init(msg_init);
176 193
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index c37fb33a3d1b..88472bf7dbb7 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -14,10 +14,8 @@
14 14
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/utsname.h>
18#include <linux/module.h> 17#include <linux/module.h>
19 18
20
21#if defined USB_ETH_RNDIS 19#if defined USB_ETH_RNDIS
22# undef USB_ETH_RNDIS 20# undef USB_ETH_RNDIS
23#endif 21#endif
@@ -42,12 +40,6 @@ MODULE_LICENSE("GPL");
42 * the runtime footprint, and giving us at least some parts of what 40 * the runtime footprint, and giving us at least some parts of what
43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
44 */ 42 */
45
46#include "composite.c"
47#include "usbstring.c"
48#include "config.c"
49#include "epautoconf.c"
50
51#include "f_mass_storage.c" 43#include "f_mass_storage.c"
52 44
53#include "u_serial.c" 45#include "u_serial.c"
@@ -61,7 +53,7 @@ MODULE_LICENSE("GPL");
61#endif 53#endif
62#include "u_ether.c" 54#include "u_ether.c"
63 55
64 56USB_GADGET_COMPOSITE_OPTIONS();
65 57
66/***************************** Device Descriptor ****************************/ 58/***************************** Device Descriptor ****************************/
67 59
@@ -112,21 +104,16 @@ static const struct usb_descriptor_header *otg_desc[] = {
112 104
113 105
114enum { 106enum {
115#ifdef CONFIG_USB_G_MULTI_RNDIS 107 MULTI_STRING_RNDIS_CONFIG_IDX = USB_GADGET_FIRST_AVAIL_IDX,
116 MULTI_STRING_RNDIS_CONFIG_IDX,
117#endif
118#ifdef CONFIG_USB_G_MULTI_CDC
119 MULTI_STRING_CDC_CONFIG_IDX, 108 MULTI_STRING_CDC_CONFIG_IDX,
120#endif
121}; 109};
122 110
123static struct usb_string strings_dev[] = { 111static struct usb_string strings_dev[] = {
124#ifdef CONFIG_USB_G_MULTI_RNDIS 112 [USB_GADGET_MANUFACTURER_IDX].s = "",
113 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
114 [USB_GADGET_SERIAL_IDX].s = "",
125 [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS", 115 [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS",
126#endif
127#ifdef CONFIG_USB_G_MULTI_CDC
128 [MULTI_STRING_CDC_CONFIG_IDX].s = "Multifunction with CDC ECM", 116 [MULTI_STRING_CDC_CONFIG_IDX].s = "Multifunction with CDC ECM",
129#endif
130 { } /* end of list */ 117 { } /* end of list */
131}; 118};
132 119
@@ -260,7 +247,7 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
260static int __ref multi_bind(struct usb_composite_dev *cdev) 247static int __ref multi_bind(struct usb_composite_dev *cdev)
261{ 248{
262 struct usb_gadget *gadget = cdev->gadget; 249 struct usb_gadget *gadget = cdev->gadget;
263 int status, gcnum; 250 int status;
264 251
265 if (!can_support_ecm(cdev->gadget)) { 252 if (!can_support_ecm(cdev->gadget)) {
266 dev_err(&gadget->dev, "controller '%s' not usable\n", 253 dev_err(&gadget->dev, "controller '%s' not usable\n",
@@ -288,19 +275,11 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
288 } 275 }
289 } 276 }
290 277
291 /* set bcdDevice */
292 gcnum = usb_gadget_controller_number(gadget);
293 if (gcnum >= 0) {
294 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
295 } else {
296 WARNING(cdev, "controller '%s' not recognized\n", gadget->name);
297 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
298 }
299
300 /* allocate string IDs */ 278 /* allocate string IDs */
301 status = usb_string_ids_tab(cdev, strings_dev); 279 status = usb_string_ids_tab(cdev, strings_dev);
302 if (unlikely(status < 0)) 280 if (unlikely(status < 0))
303 goto fail2; 281 goto fail2;
282 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
304 283
305 /* register configurations */ 284 /* register configurations */
306 status = rndis_config_register(cdev); 285 status = rndis_config_register(cdev);
@@ -310,6 +289,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
310 status = cdc_config_register(cdev); 289 status = cdc_config_register(cdev);
311 if (unlikely(status < 0)) 290 if (unlikely(status < 0))
312 goto fail2; 291 goto fail2;
292 usb_composite_overwrite_options(cdev, &coverwrite);
313 293
314 /* we're done */ 294 /* we're done */
315 dev_info(&gadget->dev, DRIVER_DESC "\n"); 295 dev_info(&gadget->dev, DRIVER_DESC "\n");
@@ -338,20 +318,20 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
338/****************************** Some noise ******************************/ 318/****************************** Some noise ******************************/
339 319
340 320
341static struct usb_composite_driver multi_driver = { 321static __refdata struct usb_composite_driver multi_driver = {
342 .name = "g_multi", 322 .name = "g_multi",
343 .dev = &device_desc, 323 .dev = &device_desc,
344 .strings = dev_strings, 324 .strings = dev_strings,
345 .max_speed = USB_SPEED_HIGH, 325 .max_speed = USB_SPEED_HIGH,
326 .bind = multi_bind,
346 .unbind = __exit_p(multi_unbind), 327 .unbind = __exit_p(multi_unbind),
347 .iProduct = DRIVER_DESC,
348 .needs_serial = 1, 328 .needs_serial = 1,
349}; 329};
350 330
351 331
352static int __init multi_init(void) 332static int __init multi_init(void)
353{ 333{
354 return usb_composite_probe(&multi_driver, multi_bind); 334 return usb_composite_probe(&multi_driver);
355} 335}
356module_init(multi_init); 336module_init(multi_init);
357 337
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index 75db2c306cea..ea45224f78c8 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -51,9 +51,8 @@
51#define EPSTATUS_TIMEOUT 10000 51#define EPSTATUS_TIMEOUT 10000
52#define PRIME_TIMEOUT 10000 52#define PRIME_TIMEOUT 10000
53#define READSAFE_TIMEOUT 1000 53#define READSAFE_TIMEOUT 1000
54#define DTD_TIMEOUT 1000
55 54
56#define LOOPS_USEC_SHIFT 4 55#define LOOPS_USEC_SHIFT 1
57#define LOOPS_USEC (1 << LOOPS_USEC_SHIFT) 56#define LOOPS_USEC (1 << LOOPS_USEC_SHIFT)
58#define LOOPS(timeout) ((timeout) >> LOOPS_USEC_SHIFT) 57#define LOOPS(timeout) ((timeout) >> LOOPS_USEC_SHIFT)
59 58
@@ -64,7 +63,6 @@ static const char driver_desc[] = DRIVER_DESC;
64 63
65/* controller device global variable */ 64/* controller device global variable */
66static struct mv_udc *the_controller; 65static struct mv_udc *the_controller;
67int mv_usb_otgsc;
68 66
69static void nuke(struct mv_ep *ep, int status); 67static void nuke(struct mv_ep *ep, int status);
70static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver); 68static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver);
@@ -357,17 +355,24 @@ done:
357 return retval; 355 return retval;
358} 356}
359 357
360
361static struct mv_dtd *build_dtd(struct mv_req *req, unsigned *length, 358static struct mv_dtd *build_dtd(struct mv_req *req, unsigned *length,
362 dma_addr_t *dma, int *is_last) 359 dma_addr_t *dma, int *is_last)
363{ 360{
364 u32 temp;
365 struct mv_dtd *dtd; 361 struct mv_dtd *dtd;
366 struct mv_udc *udc; 362 struct mv_udc *udc;
363 struct mv_dqh *dqh;
364 u32 temp, mult = 0;
367 365
368 /* how big will this transfer be? */ 366 /* how big will this transfer be? */
369 *length = min(req->req.length - req->req.actual, 367 if (usb_endpoint_xfer_isoc(req->ep->ep.desc)) {
370 (unsigned)EP_MAX_LENGTH_TRANSFER); 368 dqh = req->ep->dqh;
369 mult = (dqh->max_packet_length >> EP_QUEUE_HEAD_MULT_POS)
370 & 0x3;
371 *length = min(req->req.length - req->req.actual,
372 (unsigned)(mult * req->ep->ep.maxpacket));
373 } else
374 *length = min(req->req.length - req->req.actual,
375 (unsigned)EP_MAX_LENGTH_TRANSFER);
371 376
372 udc = req->ep->udc; 377 udc = req->ep->udc;
373 378
@@ -375,7 +380,7 @@ static struct mv_dtd *build_dtd(struct mv_req *req, unsigned *length,
375 * Be careful that no _GFP_HIGHMEM is set, 380 * Be careful that no _GFP_HIGHMEM is set,
376 * or we can not use dma_to_virt 381 * or we can not use dma_to_virt
377 */ 382 */
378 dtd = dma_pool_alloc(udc->dtd_pool, GFP_KERNEL, dma); 383 dtd = dma_pool_alloc(udc->dtd_pool, GFP_ATOMIC, dma);
379 if (dtd == NULL) 384 if (dtd == NULL)
380 return dtd; 385 return dtd;
381 386
@@ -409,6 +414,8 @@ static struct mv_dtd *build_dtd(struct mv_req *req, unsigned *length,
409 if (*is_last && !req->req.no_interrupt) 414 if (*is_last && !req->req.no_interrupt)
410 temp |= DTD_IOC; 415 temp |= DTD_IOC;
411 416
417 temp |= mult << 10;
418
412 dtd->size_ioc_sts = temp; 419 dtd->size_ioc_sts = temp;
413 420
414 mb(); 421 mb();
@@ -708,6 +715,7 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
708 struct mv_req *req = container_of(_req, struct mv_req, req); 715 struct mv_req *req = container_of(_req, struct mv_req, req);
709 struct mv_udc *udc = ep->udc; 716 struct mv_udc *udc = ep->udc;
710 unsigned long flags; 717 unsigned long flags;
718 int retval;
711 719
712 /* catch various bogus parameters */ 720 /* catch various bogus parameters */
713 if (!_req || !req->req.complete || !req->req.buf 721 if (!_req || !req->req.complete || !req->req.buf
@@ -719,10 +727,6 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
719 dev_err(&udc->dev->dev, "%s, bad ep", __func__); 727 dev_err(&udc->dev->dev, "%s, bad ep", __func__);
720 return -EINVAL; 728 return -EINVAL;
721 } 729 }
722 if (ep->ep.desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
723 if (req->req.length > ep->ep.maxpacket)
724 return -EMSGSIZE;
725 }
726 730
727 udc = ep->udc; 731 udc = ep->udc;
728 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) 732 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
@@ -755,15 +759,17 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
755 759
756 /* build dtds and push them to device queue */ 760 /* build dtds and push them to device queue */
757 if (!req_to_dtd(req)) { 761 if (!req_to_dtd(req)) {
758 int retval;
759 retval = queue_dtd(ep, req); 762 retval = queue_dtd(ep, req);
760 if (retval) { 763 if (retval) {
761 spin_unlock_irqrestore(&udc->lock, flags); 764 spin_unlock_irqrestore(&udc->lock, flags);
762 return retval; 765 dev_err(&udc->dev->dev, "Failed to queue dtd\n");
766 goto err_unmap_dma;
763 } 767 }
764 } else { 768 } else {
765 spin_unlock_irqrestore(&udc->lock, flags); 769 spin_unlock_irqrestore(&udc->lock, flags);
766 return -ENOMEM; 770 dev_err(&udc->dev->dev, "Failed to dma_pool_alloc\n");
771 retval = -ENOMEM;
772 goto err_unmap_dma;
767 } 773 }
768 774
769 /* Update ep0 state */ 775 /* Update ep0 state */
@@ -775,6 +781,22 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
775 spin_unlock_irqrestore(&udc->lock, flags); 781 spin_unlock_irqrestore(&udc->lock, flags);
776 782
777 return 0; 783 return 0;
784
785err_unmap_dma:
786 if (req->mapped) {
787 dma_unmap_single(ep->udc->gadget.dev.parent,
788 req->req.dma, req->req.length,
789 ((ep_dir(ep) == EP_DIR_IN) ?
790 DMA_TO_DEVICE : DMA_FROM_DEVICE));
791 req->req.dma = DMA_ADDR_INVALID;
792 req->mapped = 0;
793 } else
794 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
795 req->req.dma, req->req.length,
796 ((ep_dir(ep) == EP_DIR_IN) ?
797 DMA_TO_DEVICE : DMA_FROM_DEVICE));
798
799 return retval;
778} 800}
779 801
780static void mv_prime_ep(struct mv_ep *ep, struct mv_req *req) 802static void mv_prime_ep(struct mv_ep *ep, struct mv_req *req)
@@ -1065,7 +1087,7 @@ static int udc_reset(struct mv_udc *udc)
1065 tmp |= USBMODE_CTRL_MODE_DEVICE; 1087 tmp |= USBMODE_CTRL_MODE_DEVICE;
1066 1088
1067 /* turn setup lockout off, require setup tripwire in usbcmd */ 1089 /* turn setup lockout off, require setup tripwire in usbcmd */
1068 tmp |= USBMODE_SETUP_LOCK_OFF | USBMODE_STREAM_DISABLE; 1090 tmp |= USBMODE_SETUP_LOCK_OFF;
1069 1091
1070 writel(tmp, &udc->op_regs->usbmode); 1092 writel(tmp, &udc->op_regs->usbmode);
1071 1093
@@ -1199,12 +1221,16 @@ static int mv_udc_vbus_session(struct usb_gadget *gadget, int is_active)
1199 udc_start(udc); 1221 udc_start(udc);
1200 } 1222 }
1201 } else if (udc->driver && udc->softconnect) { 1223 } else if (udc->driver && udc->softconnect) {
1224 if (!udc->active)
1225 goto out;
1226
1202 /* stop all the transfer in queue*/ 1227 /* stop all the transfer in queue*/
1203 stop_activity(udc, udc->driver); 1228 stop_activity(udc, udc->driver);
1204 udc_stop(udc); 1229 udc_stop(udc);
1205 mv_udc_disable(udc); 1230 mv_udc_disable(udc);
1206 } 1231 }
1207 1232
1233out:
1208 spin_unlock_irqrestore(&udc->lock, flags); 1234 spin_unlock_irqrestore(&udc->lock, flags);
1209 return retval; 1235 return retval;
1210} 1236}
@@ -1243,7 +1269,7 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on)
1243} 1269}
1244 1270
1245static int mv_udc_start(struct usb_gadget_driver *driver, 1271static int mv_udc_start(struct usb_gadget_driver *driver,
1246 int (*bind)(struct usb_gadget *)); 1272 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
1247static int mv_udc_stop(struct usb_gadget_driver *driver); 1273static int mv_udc_stop(struct usb_gadget_driver *driver);
1248/* device controller usb_gadget_ops structure */ 1274/* device controller usb_gadget_ops structure */
1249static const struct usb_gadget_ops mv_ops = { 1275static const struct usb_gadget_ops mv_ops = {
@@ -1348,7 +1374,7 @@ static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver)
1348} 1374}
1349 1375
1350static int mv_udc_start(struct usb_gadget_driver *driver, 1376static int mv_udc_start(struct usb_gadget_driver *driver,
1351 int (*bind)(struct usb_gadget *)) 1377 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1352{ 1378{
1353 struct mv_udc *udc = the_controller; 1379 struct mv_udc *udc = the_controller;
1354 int retval = 0; 1380 int retval = 0;
@@ -1373,7 +1399,7 @@ static int mv_udc_start(struct usb_gadget_driver *driver,
1373 1399
1374 spin_unlock_irqrestore(&udc->lock, flags); 1400 spin_unlock_irqrestore(&udc->lock, flags);
1375 1401
1376 retval = bind(&udc->gadget); 1402 retval = bind(&udc->gadget, driver);
1377 if (retval) { 1403 if (retval) {
1378 dev_err(&udc->dev->dev, "bind to driver %s --> %d\n", 1404 dev_err(&udc->dev->dev, "bind to driver %s --> %d\n",
1379 driver->driver.name, retval); 1405 driver->driver.name, retval);
@@ -1499,15 +1525,17 @@ udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty)
1499 } 1525 }
1500 1526
1501 /* prime the data phase */ 1527 /* prime the data phase */
1502 if (!req_to_dtd(req)) 1528 if (!req_to_dtd(req)) {
1503 retval = queue_dtd(ep, req); 1529 retval = queue_dtd(ep, req);
1504 else{ /* no mem */ 1530 if (retval) {
1531 dev_err(&udc->dev->dev,
1532 "Failed to queue dtd when prime status\n");
1533 goto out;
1534 }
1535 } else{ /* no mem */
1505 retval = -ENOMEM; 1536 retval = -ENOMEM;
1506 goto out; 1537 dev_err(&udc->dev->dev,
1507 } 1538 "Failed to dma_pool_alloc when prime status\n");
1508
1509 if (retval) {
1510 dev_err(&udc->dev->dev, "response error on GET_STATUS request\n");
1511 goto out; 1539 goto out;
1512 } 1540 }
1513 1541
@@ -1515,6 +1543,15 @@ udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty)
1515 1543
1516 return 0; 1544 return 0;
1517out: 1545out:
1546 if (req->mapped) {
1547 dma_unmap_single(ep->udc->gadget.dev.parent,
1548 req->req.dma, req->req.length,
1549 ((ep_dir(ep) == EP_DIR_IN) ?
1550 DMA_TO_DEVICE : DMA_FROM_DEVICE));
1551 req->req.dma = DMA_ADDR_INVALID;
1552 req->mapped = 0;
1553 }
1554
1518 return retval; 1555 return retval;
1519} 1556}
1520 1557
@@ -2468,9 +2505,11 @@ static void mv_udc_shutdown(struct platform_device *dev)
2468 u32 mode; 2505 u32 mode;
2469 2506
2470 /* reset controller mode to IDLE */ 2507 /* reset controller mode to IDLE */
2508 mv_udc_enable(udc);
2471 mode = readl(&udc->op_regs->usbmode); 2509 mode = readl(&udc->op_regs->usbmode);
2472 mode &= ~3; 2510 mode &= ~3;
2473 writel(mode, &udc->op_regs->usbmode); 2511 writel(mode, &udc->op_regs->usbmode);
2512 mv_udc_disable(udc);
2474} 2513}
2475 2514
2476static struct platform_driver udc_driver = { 2515static struct platform_driver udc_driver = {
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
index 89530034dff1..a22ad9af0565 100644
--- a/drivers/usb/gadget/ncm.c
+++ b/drivers/usb/gadget/ncm.c
@@ -20,8 +20,8 @@
20/* #define VERBOSE_DEBUG */ 20/* #define VERBOSE_DEBUG */
21 21
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/utsname.h> 23#include <linux/module.h>
24 24#include <linux/usb/composite.h>
25 25
26#include "u_ether.h" 26#include "u_ether.h"
27 27
@@ -36,11 +36,6 @@
36 * the runtime footprint, and giving us at least some parts of what 36 * the runtime footprint, and giving us at least some parts of what
37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
38 */ 38 */
39#include "composite.c"
40#include "usbstring.c"
41#include "config.c"
42#include "epautoconf.c"
43
44#include "f_ncm.c" 39#include "f_ncm.c"
45#include "u_ether.c" 40#include "u_ether.c"
46 41
@@ -57,6 +52,7 @@
57#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ 52#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
58 53
59/*-------------------------------------------------------------------------*/ 54/*-------------------------------------------------------------------------*/
55USB_GADGET_COMPOSITE_OPTIONS();
60 56
61static struct usb_device_descriptor device_desc = { 57static struct usb_device_descriptor device_desc = {
62 .bLength = sizeof device_desc, 58 .bLength = sizeof device_desc,
@@ -97,17 +93,11 @@ static const struct usb_descriptor_header *otg_desc[] = {
97 NULL, 93 NULL,
98}; 94};
99 95
100
101/* string IDs are assigned dynamically */ 96/* string IDs are assigned dynamically */
102
103#define STRING_MANUFACTURER_IDX 0
104#define STRING_PRODUCT_IDX 1
105
106static char manufacturer[50];
107
108static struct usb_string strings_dev[] = { 97static struct usb_string strings_dev[] = {
109 [STRING_MANUFACTURER_IDX].s = manufacturer, 98 [USB_GADGET_MANUFACTURER_IDX].s = "",
110 [STRING_PRODUCT_IDX].s = DRIVER_DESC, 99 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
100 [USB_GADGET_SERIAL_IDX].s = "",
111 { } /* end of list */ 101 { } /* end of list */
112}; 102};
113 103
@@ -149,7 +139,6 @@ static struct usb_configuration ncm_config_driver = {
149 139
150static int __init gncm_bind(struct usb_composite_dev *cdev) 140static int __init gncm_bind(struct usb_composite_dev *cdev)
151{ 141{
152 int gcnum;
153 struct usb_gadget *gadget = cdev->gadget; 142 struct usb_gadget *gadget = cdev->gadget;
154 int status; 143 int status;
155 144
@@ -158,48 +147,22 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
158 if (status < 0) 147 if (status < 0)
159 return status; 148 return status;
160 149
161 gcnum = usb_gadget_controller_number(gadget);
162 if (gcnum >= 0)
163 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
164 else {
165 /* We assume that can_support_ecm() tells the truth;
166 * but if the controller isn't recognized at all then
167 * that assumption is a bit more likely to be wrong.
168 */
169 dev_warn(&gadget->dev,
170 "controller '%s' not recognized; trying %s\n",
171 gadget->name,
172 ncm_config_driver.label);
173 device_desc.bcdDevice =
174 cpu_to_le16(0x0300 | 0x0099);
175 }
176
177
178 /* Allocate string descriptor numbers ... note that string 150 /* Allocate string descriptor numbers ... note that string
179 * contents can be overridden by the composite_dev glue. 151 * contents can be overridden by the composite_dev glue.
180 */ 152 */
181 153
182 /* device descriptor strings: manufacturer, product */ 154 status = usb_string_ids_tab(cdev, strings_dev);
183 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
184 init_utsname()->sysname, init_utsname()->release,
185 gadget->name);
186 status = usb_string_id(cdev);
187 if (status < 0)
188 goto fail;
189 strings_dev[STRING_MANUFACTURER_IDX].id = status;
190 device_desc.iManufacturer = status;
191
192 status = usb_string_id(cdev);
193 if (status < 0) 155 if (status < 0)
194 goto fail; 156 goto fail;
195 strings_dev[STRING_PRODUCT_IDX].id = status; 157 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
196 device_desc.iProduct = status; 158 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
197 159
198 status = usb_add_config(cdev, &ncm_config_driver, 160 status = usb_add_config(cdev, &ncm_config_driver,
199 ncm_do_config); 161 ncm_do_config);
200 if (status < 0) 162 if (status < 0)
201 goto fail; 163 goto fail;
202 164
165 usb_composite_overwrite_options(cdev, &coverwrite);
203 dev_info(&gadget->dev, "%s\n", DRIVER_DESC); 166 dev_info(&gadget->dev, "%s\n", DRIVER_DESC);
204 167
205 return 0; 168 return 0;
@@ -215,11 +178,12 @@ static int __exit gncm_unbind(struct usb_composite_dev *cdev)
215 return 0; 178 return 0;
216} 179}
217 180
218static struct usb_composite_driver ncm_driver = { 181static __refdata struct usb_composite_driver ncm_driver = {
219 .name = "g_ncm", 182 .name = "g_ncm",
220 .dev = &device_desc, 183 .dev = &device_desc,
221 .strings = dev_strings, 184 .strings = dev_strings,
222 .max_speed = USB_SPEED_HIGH, 185 .max_speed = USB_SPEED_HIGH,
186 .bind = gncm_bind,
223 .unbind = __exit_p(gncm_unbind), 187 .unbind = __exit_p(gncm_unbind),
224}; 188};
225 189
@@ -229,7 +193,7 @@ MODULE_LICENSE("GPL");
229 193
230static int __init init(void) 194static int __init init(void)
231{ 195{
232 return usb_composite_probe(&ncm_driver, gncm_bind); 196 return usb_composite_probe(&ncm_driver);
233} 197}
234module_init(init); 198module_init(init);
235 199
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index c7fb7723c014..661600abace8 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -16,7 +16,6 @@
16 */ 16 */
17 17
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/utsname.h>
20#include <linux/device.h> 19#include <linux/device.h>
21 20
22#include "u_serial.h" 21#include "u_serial.h"
@@ -38,11 +37,6 @@
38 * the runtime footprint, and giving us at least some parts of what 37 * the runtime footprint, and giving us at least some parts of what
39 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
40 */ 39 */
41#include "composite.c"
42#include "usbstring.c"
43#include "config.c"
44#include "epautoconf.c"
45
46#include "u_serial.c" 40#include "u_serial.c"
47#include "f_acm.c" 41#include "f_acm.c"
48#include "f_ecm.c" 42#include "f_ecm.c"
@@ -52,23 +46,23 @@
52#include "u_ether.c" 46#include "u_ether.c"
53 47
54/*-------------------------------------------------------------------------*/ 48/*-------------------------------------------------------------------------*/
49USB_GADGET_COMPOSITE_OPTIONS();
55 50
56#define NOKIA_VENDOR_ID 0x0421 /* Nokia */ 51#define NOKIA_VENDOR_ID 0x0421 /* Nokia */
57#define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */ 52#define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */
58 53
59/* string IDs are assigned dynamically */ 54/* string IDs are assigned dynamically */
60 55
61#define STRING_MANUFACTURER_IDX 0 56#define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX
62#define STRING_PRODUCT_IDX 1
63#define STRING_DESCRIPTION_IDX 2
64 57
65static char manufacturer_nokia[] = "Nokia"; 58static char manufacturer_nokia[] = "Nokia";
66static const char product_nokia[] = NOKIA_LONG_NAME; 59static const char product_nokia[] = NOKIA_LONG_NAME;
67static const char description_nokia[] = "PC-Suite Configuration"; 60static const char description_nokia[] = "PC-Suite Configuration";
68 61
69static struct usb_string strings_dev[] = { 62static struct usb_string strings_dev[] = {
70 [STRING_MANUFACTURER_IDX].s = manufacturer_nokia, 63 [USB_GADGET_MANUFACTURER_IDX].s = manufacturer_nokia,
71 [STRING_PRODUCT_IDX].s = NOKIA_LONG_NAME, 64 [USB_GADGET_PRODUCT_IDX].s = NOKIA_LONG_NAME,
65 [USB_GADGET_SERIAL_IDX].s = "",
72 [STRING_DESCRIPTION_IDX].s = description_nokia, 66 [STRING_DESCRIPTION_IDX].s = description_nokia,
73 { } /* end of list */ 67 { } /* end of list */
74}; 68};
@@ -90,6 +84,7 @@ static struct usb_device_descriptor device_desc = {
90 .bDeviceClass = USB_CLASS_COMM, 84 .bDeviceClass = USB_CLASS_COMM,
91 .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID), 85 .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID),
92 .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID), 86 .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID),
87 .bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM),
93 /* .iManufacturer = DYNAMIC */ 88 /* .iManufacturer = DYNAMIC */
94 /* .iProduct = DYNAMIC */ 89 /* .iProduct = DYNAMIC */
95 .bNumConfigurations = 1, 90 .bNumConfigurations = 1,
@@ -151,7 +146,6 @@ static struct usb_configuration nokia_config_100ma_driver = {
151 146
152static int __init nokia_bind(struct usb_composite_dev *cdev) 147static int __init nokia_bind(struct usb_composite_dev *cdev)
153{ 148{
154 int gcnum;
155 struct usb_gadget *gadget = cdev->gadget; 149 struct usb_gadget *gadget = cdev->gadget;
156 int status; 150 int status;
157 151
@@ -167,41 +161,17 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
167 if (status < 0) 161 if (status < 0)
168 goto err_ether; 162 goto err_ether;
169 163
170 status = usb_string_id(cdev); 164 status = usb_string_ids_tab(cdev, strings_dev);
171 if (status < 0)
172 goto err_usb;
173 strings_dev[STRING_MANUFACTURER_IDX].id = status;
174
175 device_desc.iManufacturer = status;
176
177 status = usb_string_id(cdev);
178 if (status < 0) 165 if (status < 0)
179 goto err_usb; 166 goto err_usb;
180 strings_dev[STRING_PRODUCT_IDX].id = status; 167 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
181 168 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
182 device_desc.iProduct = status; 169 status = strings_dev[STRING_DESCRIPTION_IDX].id;
183
184 /* config description */
185 status = usb_string_id(cdev);
186 if (status < 0)
187 goto err_usb;
188 strings_dev[STRING_DESCRIPTION_IDX].id = status;
189
190 nokia_config_500ma_driver.iConfiguration = status; 170 nokia_config_500ma_driver.iConfiguration = status;
191 nokia_config_100ma_driver.iConfiguration = status; 171 nokia_config_100ma_driver.iConfiguration = status;
192 172
193 /* set up other descriptors */ 173 if (!gadget_supports_altsettings(gadget))
194 gcnum = usb_gadget_controller_number(gadget);
195 if (gcnum >= 0)
196 device_desc.bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM);
197 else {
198 /* this should only work with hw that supports altsettings
199 * and several endpoints, anything else, panic.
200 */
201 pr_err("nokia_bind: controller '%s' not recognized\n",
202 gadget->name);
203 goto err_usb; 174 goto err_usb;
204 }
205 175
206 /* finally register the configuration */ 176 /* finally register the configuration */
207 status = usb_add_config(cdev, &nokia_config_500ma_driver, 177 status = usb_add_config(cdev, &nokia_config_500ma_driver,
@@ -214,6 +184,7 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
214 if (status < 0) 184 if (status < 0)
215 goto err_usb; 185 goto err_usb;
216 186
187 usb_composite_overwrite_options(cdev, &coverwrite);
217 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); 188 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
218 189
219 return 0; 190 return 0;
@@ -237,17 +208,18 @@ static int __exit nokia_unbind(struct usb_composite_dev *cdev)
237 return 0; 208 return 0;
238} 209}
239 210
240static struct usb_composite_driver nokia_driver = { 211static __refdata struct usb_composite_driver nokia_driver = {
241 .name = "g_nokia", 212 .name = "g_nokia",
242 .dev = &device_desc, 213 .dev = &device_desc,
243 .strings = dev_strings, 214 .strings = dev_strings,
244 .max_speed = USB_SPEED_HIGH, 215 .max_speed = USB_SPEED_HIGH,
216 .bind = nokia_bind,
245 .unbind = __exit_p(nokia_unbind), 217 .unbind = __exit_p(nokia_unbind),
246}; 218};
247 219
248static int __init nokia_init(void) 220static int __init nokia_init(void)
249{ 221{
250 return usb_composite_probe(&nokia_driver, nokia_bind); 222 return usb_composite_probe(&nokia_driver);
251} 223}
252module_init(nokia_init); 224module_init(nokia_init);
253 225
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index f9132ada53b5..2a4749c3eb3f 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -1308,7 +1308,7 @@ static int omap_pullup(struct usb_gadget *gadget, int is_on)
1308} 1308}
1309 1309
1310static int omap_udc_start(struct usb_gadget_driver *driver, 1310static int omap_udc_start(struct usb_gadget_driver *driver,
1311 int (*bind)(struct usb_gadget *)); 1311 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
1312static int omap_udc_stop(struct usb_gadget_driver *driver); 1312static int omap_udc_stop(struct usb_gadget_driver *driver);
1313 1313
1314static struct usb_gadget_ops omap_gadget_ops = { 1314static struct usb_gadget_ops omap_gadget_ops = {
@@ -2040,7 +2040,7 @@ static inline int machine_without_vbus_sense(void)
2040} 2040}
2041 2041
2042static int omap_udc_start(struct usb_gadget_driver *driver, 2042static int omap_udc_start(struct usb_gadget_driver *driver,
2043 int (*bind)(struct usb_gadget *)) 2043 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
2044{ 2044{
2045 int status = -ENODEV; 2045 int status = -ENODEV;
2046 struct omap_ep *ep; 2046 struct omap_ep *ep;
@@ -2082,7 +2082,7 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2082 if (udc->dc_clk != NULL) 2082 if (udc->dc_clk != NULL)
2083 omap_udc_enable_clock(1); 2083 omap_udc_enable_clock(1);
2084 2084
2085 status = bind(&udc->gadget); 2085 status = bind(&udc->gadget, driver);
2086 if (status) { 2086 if (status) {
2087 DBG("bind to %s --> %d\n", driver->driver.name, status); 2087 DBG("bind to %s --> %d\n", driver->driver.name, status);
2088 udc->gadget.dev.driver = NULL; 2088 udc->gadget.dev.driver = NULL;
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index f4fb71c9ae08..6490c0040e3a 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -1236,7 +1236,7 @@ static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
1236} 1236}
1237 1237
1238static int pch_udc_start(struct usb_gadget_driver *driver, 1238static int pch_udc_start(struct usb_gadget_driver *driver,
1239 int (*bind)(struct usb_gadget *)); 1239 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
1240static int pch_udc_stop(struct usb_gadget_driver *driver); 1240static int pch_udc_stop(struct usb_gadget_driver *driver);
1241static const struct usb_gadget_ops pch_udc_ops = { 1241static const struct usb_gadget_ops pch_udc_ops = {
1242 .get_frame = pch_udc_pcd_get_frame, 1242 .get_frame = pch_udc_pcd_get_frame,
@@ -2982,7 +2982,7 @@ static int init_dma_pools(struct pch_udc_dev *dev)
2982} 2982}
2983 2983
2984static int pch_udc_start(struct usb_gadget_driver *driver, 2984static int pch_udc_start(struct usb_gadget_driver *driver,
2985 int (*bind)(struct usb_gadget *)) 2985 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
2986{ 2986{
2987 struct pch_udc_dev *dev = pch_udc; 2987 struct pch_udc_dev *dev = pch_udc;
2988 int retval; 2988 int retval;
@@ -3006,7 +3006,7 @@ static int pch_udc_start(struct usb_gadget_driver *driver,
3006 dev->gadget.dev.driver = &driver->driver; 3006 dev->gadget.dev.driver = &driver->driver;
3007 3007
3008 /* Invoke the bind routine of the gadget driver */ 3008 /* Invoke the bind routine of the gadget driver */
3009 retval = bind(&dev->gadget); 3009 retval = bind(&dev->gadget, driver);
3010 3010
3011 if (retval) { 3011 if (retval) {
3012 dev_err(&dev->pdev->dev, "%s: binding to %s returning %d\n", 3012 dev_err(&dev->pdev->dev, "%s: binding to %s returning %d\n",
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index f1f9290a2f47..e156e3f26727 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -22,7 +22,6 @@
22#include <linux/timer.h> 22#include <linux/timer.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/utsname.h>
26#include <linux/device.h> 25#include <linux/device.h>
27#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
28#include <linux/fs.h> 27#include <linux/fs.h>
@@ -38,25 +37,13 @@
38#include <asm/unaligned.h> 37#include <asm/unaligned.h>
39 38
40#include <linux/usb/ch9.h> 39#include <linux/usb/ch9.h>
40#include <linux/usb/composite.h>
41#include <linux/usb/gadget.h> 41#include <linux/usb/gadget.h>
42#include <linux/usb/g_printer.h> 42#include <linux/usb/g_printer.h>
43 43
44#include "gadget_chips.h" 44#include "gadget_chips.h"
45 45
46 46USB_GADGET_COMPOSITE_OPTIONS();
47/*
48 * Kbuild is not very cooperative with respect to linking separately
49 * compiled library objects into one module. So for now we won't use
50 * separate compilation ... ensuring init/exit sections work to shrink
51 * the runtime footprint, and giving us at least some parts of what
52 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
53 */
54#include "composite.c"
55#include "usbstring.c"
56#include "config.c"
57#include "epautoconf.c"
58
59/*-------------------------------------------------------------------------*/
60 47
61#define DRIVER_DESC "Printer Gadget" 48#define DRIVER_DESC "Printer Gadget"
62#define DRIVER_VERSION "2007 OCT 06" 49#define DRIVER_VERSION "2007 OCT 06"
@@ -120,8 +107,7 @@ static struct printer_dev usb_printer_gadget;
120 * parameters are in UTF-8 (superset of ASCII's 7 bit characters). 107 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
121 */ 108 */
122 109
123static char *iSerialNum; 110module_param_named(iSerialNum, coverwrite.serial_number, charp, S_IRUGO);
124module_param(iSerialNum, charp, S_IRUGO);
125MODULE_PARM_DESC(iSerialNum, "1"); 111MODULE_PARM_DESC(iSerialNum, "1");
126 112
127static char *iPNPstring; 113static char *iPNPstring;
@@ -141,18 +127,10 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR);
141 * descriptors are built on demand. 127 * descriptors are built on demand.
142 */ 128 */
143 129
144#define STRING_MANUFACTURER 1
145#define STRING_PRODUCT 2
146#define STRING_SERIALNUM 3
147
148/* holds our biggest descriptor */ 130/* holds our biggest descriptor */
149#define USB_DESC_BUFSIZE 256 131#define USB_DESC_BUFSIZE 256
150#define USB_BUFSIZE 8192 132#define USB_BUFSIZE 8192
151 133
152/* This device advertises one configuration. */
153#define DEV_CONFIG_VALUE 1
154#define PRINTER_INTERFACE 0
155
156static struct usb_device_descriptor device_desc = { 134static struct usb_device_descriptor device_desc = {
157 .bLength = sizeof device_desc, 135 .bLength = sizeof device_desc,
158 .bDescriptorType = USB_DT_DEVICE, 136 .bDescriptorType = USB_DT_DEVICE,
@@ -162,16 +140,12 @@ static struct usb_device_descriptor device_desc = {
162 .bDeviceProtocol = 0, 140 .bDeviceProtocol = 0,
163 .idVendor = cpu_to_le16(PRINTER_VENDOR_NUM), 141 .idVendor = cpu_to_le16(PRINTER_VENDOR_NUM),
164 .idProduct = cpu_to_le16(PRINTER_PRODUCT_NUM), 142 .idProduct = cpu_to_le16(PRINTER_PRODUCT_NUM),
165 .iManufacturer = STRING_MANUFACTURER,
166 .iProduct = STRING_PRODUCT,
167 .iSerialNumber = STRING_SERIALNUM,
168 .bNumConfigurations = 1 143 .bNumConfigurations = 1
169}; 144};
170 145
171static struct usb_interface_descriptor intf_desc = { 146static struct usb_interface_descriptor intf_desc = {
172 .bLength = sizeof intf_desc, 147 .bLength = sizeof intf_desc,
173 .bDescriptorType = USB_DT_INTERFACE, 148 .bDescriptorType = USB_DT_INTERFACE,
174 .bInterfaceNumber = PRINTER_INTERFACE,
175 .bNumEndpoints = 2, 149 .bNumEndpoints = 2,
176 .bInterfaceClass = USB_CLASS_PRINTER, 150 .bInterfaceClass = USB_CLASS_PRINTER,
177 .bInterfaceSubClass = 1, /* Printer Sub-Class */ 151 .bInterfaceSubClass = 1, /* Printer Sub-Class */
@@ -252,7 +226,6 @@ static const struct usb_descriptor_header *otg_desc[] = {
252 226
253/* descriptors that are built on-demand */ 227/* descriptors that are built on-demand */
254 228
255static char manufacturer [50];
256static char product_desc [40] = DRIVER_DESC; 229static char product_desc [40] = DRIVER_DESC;
257static char serial_num [40] = "1"; 230static char serial_num [40] = "1";
258static char pnp_string [1024] = 231static char pnp_string [1024] =
@@ -260,9 +233,9 @@ static char pnp_string [1024] =
260 233
261/* static strings, in UTF-8 */ 234/* static strings, in UTF-8 */
262static struct usb_string strings [] = { 235static struct usb_string strings [] = {
263 { STRING_MANUFACTURER, manufacturer, }, 236 [USB_GADGET_MANUFACTURER_IDX].s = "",
264 { STRING_PRODUCT, product_desc, }, 237 [USB_GADGET_PRODUCT_IDX].s = product_desc,
265 { STRING_SERIALNUM, serial_num, }, 238 [USB_GADGET_SERIAL_IDX].s = serial_num,
266 { } /* end of list */ 239 { } /* end of list */
267}; 240};
268 241
@@ -871,25 +844,13 @@ static int set_interface(struct printer_dev *dev, unsigned number)
871 int result = 0; 844 int result = 0;
872 845
873 /* Free the current interface */ 846 /* Free the current interface */
874 switch (dev->interface) { 847 printer_reset_interface(dev);
875 case PRINTER_INTERFACE:
876 printer_reset_interface(dev);
877 break;
878 }
879 848
880 switch (number) { 849 result = set_printer_interface(dev);
881 case PRINTER_INTERFACE: 850 if (result)
882 result = set_printer_interface(dev); 851 printer_reset_interface(dev);
883 if (result) { 852 else
884 printer_reset_interface(dev); 853 dev->interface = number;
885 } else {
886 dev->interface = PRINTER_INTERFACE;
887 }
888 break;
889 default:
890 result = -EINVAL;
891 /* FALL THROUGH */
892 }
893 854
894 if (!result) 855 if (!result)
895 INFO(dev, "Using interface %x\n", number); 856 INFO(dev, "Using interface %x\n", number);
@@ -972,7 +933,7 @@ static int printer_func_setup(struct usb_function *f,
972 switch (ctrl->bRequest) { 933 switch (ctrl->bRequest) {
973 case 0: /* Get the IEEE-1284 PNP String */ 934 case 0: /* Get the IEEE-1284 PNP String */
974 /* Only one printer interface is supported. */ 935 /* Only one printer interface is supported. */
975 if ((wIndex>>8) != PRINTER_INTERFACE) 936 if ((wIndex>>8) != dev->interface)
976 break; 937 break;
977 938
978 value = (pnp_string[0]<<8)|pnp_string[1]; 939 value = (pnp_string[0]<<8)|pnp_string[1];
@@ -983,7 +944,7 @@ static int printer_func_setup(struct usb_function *f,
983 944
984 case 1: /* Get Port Status */ 945 case 1: /* Get Port Status */
985 /* Only one printer interface is supported. */ 946 /* Only one printer interface is supported. */
986 if (wIndex != PRINTER_INTERFACE) 947 if (wIndex != dev->interface)
987 break; 948 break;
988 949
989 *(u8 *)req->buf = dev->printer_status; 950 *(u8 *)req->buf = dev->printer_status;
@@ -992,7 +953,7 @@ static int printer_func_setup(struct usb_function *f,
992 953
993 case 2: /* Soft Reset */ 954 case 2: /* Soft Reset */
994 /* Only one printer interface is supported. */ 955 /* Only one printer interface is supported. */
995 if (wIndex != PRINTER_INTERFACE) 956 if (wIndex != dev->interface)
996 break; 957 break;
997 958
998 printer_soft_reset(dev); 959 printer_soft_reset(dev);
@@ -1020,6 +981,37 @@ unknown:
1020static int __init printer_func_bind(struct usb_configuration *c, 981static int __init printer_func_bind(struct usb_configuration *c,
1021 struct usb_function *f) 982 struct usb_function *f)
1022{ 983{
984 struct printer_dev *dev = container_of(f, struct printer_dev, function);
985 struct usb_composite_dev *cdev = c->cdev;
986 struct usb_ep *in_ep, *out_ep;
987 int id;
988
989 id = usb_interface_id(c, f);
990 if (id < 0)
991 return id;
992 intf_desc.bInterfaceNumber = id;
993
994 /* all we really need is bulk IN/OUT */
995 in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc);
996 if (!in_ep) {
997autoconf_fail:
998 dev_err(&cdev->gadget->dev, "can't autoconfigure on %s\n",
999 cdev->gadget->name);
1000 return -ENODEV;
1001 }
1002 in_ep->driver_data = in_ep; /* claim */
1003
1004 out_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_out_desc);
1005 if (!out_ep)
1006 goto autoconf_fail;
1007 out_ep->driver_data = out_ep; /* claim */
1008
1009 /* assumes that all endpoints are dual-speed */
1010 hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
1011 hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
1012
1013 dev->in_ep = in_ep;
1014 dev->out_ep = out_ep;
1023 return 0; 1015 return 0;
1024} 1016}
1025 1017
@@ -1035,7 +1027,8 @@ static int printer_func_set_alt(struct usb_function *f,
1035 int ret = -ENOTSUPP; 1027 int ret = -ENOTSUPP;
1036 1028
1037 if (!alt) 1029 if (!alt)
1038 ret = set_interface(dev, PRINTER_INTERFACE); 1030 ret = set_interface(dev, intf);
1031
1039 return ret; 1032 return ret;
1040} 1033}
1041 1034
@@ -1107,13 +1100,13 @@ static int __init printer_bind_config(struct usb_configuration *c)
1107{ 1100{
1108 struct usb_gadget *gadget = c->cdev->gadget; 1101 struct usb_gadget *gadget = c->cdev->gadget;
1109 struct printer_dev *dev; 1102 struct printer_dev *dev;
1110 struct usb_ep *in_ep, *out_ep;
1111 int status = -ENOMEM; 1103 int status = -ENOMEM;
1112 int gcnum;
1113 size_t len; 1104 size_t len;
1114 u32 i; 1105 u32 i;
1115 struct usb_request *req; 1106 struct usb_request *req;
1116 1107
1108 usb_ep_autoconfig_reset(gadget);
1109
1117 dev = &usb_printer_gadget; 1110 dev = &usb_printer_gadget;
1118 1111
1119 dev->function.name = shortname; 1112 dev->function.name = shortname;
@@ -1125,6 +1118,10 @@ static int __init printer_bind_config(struct usb_configuration *c)
1125 dev->function.set_alt = printer_func_set_alt; 1118 dev->function.set_alt = printer_func_set_alt;
1126 dev->function.disable = printer_func_disable; 1119 dev->function.disable = printer_func_disable;
1127 1120
1121 status = usb_add_function(c, &dev->function);
1122 if (status)
1123 return status;
1124
1128 /* Setup the sysfs files for the printer gadget. */ 1125 /* Setup the sysfs files for the printer gadget. */
1129 dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, 1126 dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno,
1130 NULL, "g_printer"); 1127 NULL, "g_printer");
@@ -1145,23 +1142,6 @@ static int __init printer_bind_config(struct usb_configuration *c)
1145 goto fail; 1142 goto fail;
1146 } 1143 }
1147 1144
1148 gcnum = usb_gadget_controller_number(gadget);
1149 if (gcnum >= 0) {
1150 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1151 } else {
1152 dev_warn(&gadget->dev, "controller '%s' not recognized\n",
1153 gadget->name);
1154 /* unrecognized, but safe unless bulk is REALLY quirky */
1155 device_desc.bcdDevice =
1156 cpu_to_le16(0xFFFF);
1157 }
1158 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
1159 init_utsname()->sysname, init_utsname()->release,
1160 gadget->name);
1161
1162 if (iSerialNum)
1163 strlcpy(serial_num, iSerialNum, sizeof serial_num);
1164
1165 if (iPNPstring) 1145 if (iPNPstring)
1166 strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2); 1146 strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2);
1167 1147
@@ -1169,26 +1149,6 @@ static int __init printer_bind_config(struct usb_configuration *c)
1169 pnp_string[0] = (len >> 8) & 0xFF; 1149 pnp_string[0] = (len >> 8) & 0xFF;
1170 pnp_string[1] = len & 0xFF; 1150 pnp_string[1] = len & 0xFF;
1171 1151
1172 /* all we really need is bulk IN/OUT */
1173 usb_ep_autoconfig_reset(gadget);
1174 in_ep = usb_ep_autoconfig(gadget, &fs_ep_in_desc);
1175 if (!in_ep) {
1176autoconf_fail:
1177 dev_err(&gadget->dev, "can't autoconfigure on %s\n",
1178 gadget->name);
1179 return -ENODEV;
1180 }
1181 in_ep->driver_data = in_ep; /* claim */
1182
1183 out_ep = usb_ep_autoconfig(gadget, &fs_ep_out_desc);
1184 if (!out_ep)
1185 goto autoconf_fail;
1186 out_ep->driver_data = out_ep; /* claim */
1187
1188 /* assumes that all endpoints are dual-speed */
1189 hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
1190 hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
1191
1192 usb_gadget_set_selfpowered(gadget); 1152 usb_gadget_set_selfpowered(gadget);
1193 1153
1194 if (gadget->is_otg) { 1154 if (gadget->is_otg) {
@@ -1215,9 +1175,6 @@ autoconf_fail:
1215 dev->current_rx_bytes = 0; 1175 dev->current_rx_bytes = 0;
1216 dev->current_rx_buf = NULL; 1176 dev->current_rx_buf = NULL;
1217 1177
1218 dev->in_ep = in_ep;
1219 dev->out_ep = out_ep;
1220
1221 for (i = 0; i < QLEN; i++) { 1178 for (i = 0; i < QLEN; i++) {
1222 req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); 1179 req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL);
1223 if (!req) { 1180 if (!req) {
@@ -1250,8 +1207,6 @@ autoconf_fail:
1250 dev->gadget = gadget; 1207 dev->gadget = gadget;
1251 1208
1252 INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); 1209 INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc);
1253 INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, out_ep->name,
1254 in_ep->name);
1255 return 0; 1210 return 0;
1256 1211
1257fail: 1212fail:
@@ -1266,14 +1221,28 @@ static int printer_unbind(struct usb_composite_dev *cdev)
1266 1221
1267static int __init printer_bind(struct usb_composite_dev *cdev) 1222static int __init printer_bind(struct usb_composite_dev *cdev)
1268{ 1223{
1269 return usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); 1224 int ret;
1225
1226 ret = usb_string_ids_tab(cdev, strings);
1227 if (ret < 0)
1228 return ret;
1229 device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id;
1230 device_desc.iProduct = strings[USB_GADGET_PRODUCT_IDX].id;
1231 device_desc.iSerialNumber = strings[USB_GADGET_SERIAL_IDX].id;
1232
1233 ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config);
1234 if (ret)
1235 return ret;
1236 usb_composite_overwrite_options(cdev, &coverwrite);
1237 return ret;
1270} 1238}
1271 1239
1272static struct usb_composite_driver printer_driver = { 1240static __refdata struct usb_composite_driver printer_driver = {
1273 .name = shortname, 1241 .name = shortname,
1274 .dev = &device_desc, 1242 .dev = &device_desc,
1275 .strings = dev_strings, 1243 .strings = dev_strings,
1276 .max_speed = USB_SPEED_HIGH, 1244 .max_speed = USB_SPEED_HIGH,
1245 .bind = printer_bind,
1277 .unbind = printer_unbind, 1246 .unbind = printer_unbind,
1278}; 1247};
1279 1248
@@ -1297,7 +1266,7 @@ init(void)
1297 return status; 1266 return status;
1298 } 1267 }
1299 1268
1300 status = usb_composite_probe(&printer_driver, printer_bind); 1269 status = usb_composite_probe(&printer_driver);
1301 if (status) { 1270 if (status) {
1302 class_destroy(usb_gadget_class); 1271 class_destroy(usb_gadget_class);
1303 unregister_chrdev_region(g_printer_devno, 1); 1272 unregister_chrdev_region(g_printer_devno, 1);
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index 907ad3ecb341..8efbf08c3561 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -33,7 +33,6 @@
33#include <linux/dma-mapping.h> 33#include <linux/dma-mapping.h>
34#include <linux/irq.h> 34#include <linux/irq.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/err.h>
37#include <linux/seq_file.h> 36#include <linux/seq_file.h>
38#include <linux/debugfs.h> 37#include <linux/debugfs.h>
39#include <linux/io.h> 38#include <linux/io.h>
@@ -1000,7 +999,7 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1000} 999}
1001 1000
1002static int pxa25x_start(struct usb_gadget_driver *driver, 1001static int pxa25x_start(struct usb_gadget_driver *driver,
1003 int (*bind)(struct usb_gadget *)); 1002 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
1004static int pxa25x_stop(struct usb_gadget_driver *driver); 1003static int pxa25x_stop(struct usb_gadget_driver *driver);
1005 1004
1006static const struct usb_gadget_ops pxa25x_udc_ops = { 1005static const struct usb_gadget_ops pxa25x_udc_ops = {
@@ -1258,7 +1257,7 @@ static void udc_enable (struct pxa25x_udc *dev)
1258 * the driver might get unbound. 1257 * the driver might get unbound.
1259 */ 1258 */
1260static int pxa25x_start(struct usb_gadget_driver *driver, 1259static int pxa25x_start(struct usb_gadget_driver *driver,
1261 int (*bind)(struct usb_gadget *)) 1260 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1262{ 1261{
1263 struct pxa25x_udc *dev = the_controller; 1262 struct pxa25x_udc *dev = the_controller;
1264 int retval; 1263 int retval;
@@ -1286,7 +1285,7 @@ fail:
1286 dev->gadget.dev.driver = NULL; 1285 dev->gadget.dev.driver = NULL;
1287 return retval; 1286 return retval;
1288 } 1287 }
1289 retval = bind(&dev->gadget); 1288 retval = bind(&dev->gadget, driver);
1290 if (retval) { 1289 if (retval) {
1291 DMSG("bind to driver %s --> error %d\n", 1290 DMSG("bind to driver %s --> error %d\n",
1292 driver->driver.name, retval); 1291 driver->driver.name, retval);
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h
index 861f4df6ea22..2eca1e71fecd 100644
--- a/drivers/usb/gadget/pxa25x_udc.h
+++ b/drivers/usb/gadget/pxa25x_udc.h
@@ -225,7 +225,7 @@ dump_state(struct pxa25x_udc *dev)
225 dev->stats.read.bytes, dev->stats.read.ops); 225 dev->stats.read.bytes, dev->stats.read.ops);
226 226
227 for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) { 227 for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) {
228 if (dev->ep [i].desc == NULL) 228 if (dev->ep[i].ep.desc == NULL)
229 continue; 229 continue;
230 DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs); 230 DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs);
231 } 231 }
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 644b4305cb99..979ddaddb0f8 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -1672,7 +1672,7 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1672} 1672}
1673 1673
1674static int pxa27x_udc_start(struct usb_gadget_driver *driver, 1674static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1675 int (*bind)(struct usb_gadget *)); 1675 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
1676static int pxa27x_udc_stop(struct usb_gadget_driver *driver); 1676static int pxa27x_udc_stop(struct usb_gadget_driver *driver);
1677 1677
1678static const struct usb_gadget_ops pxa_udc_ops = { 1678static const struct usb_gadget_ops pxa_udc_ops = {
@@ -1803,7 +1803,7 @@ static void udc_enable(struct pxa_udc *udc)
1803 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1803 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1804 */ 1804 */
1805static int pxa27x_udc_start(struct usb_gadget_driver *driver, 1805static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1806 int (*bind)(struct usb_gadget *)) 1806 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1807{ 1807{
1808 struct pxa_udc *udc = the_controller; 1808 struct pxa_udc *udc = the_controller;
1809 int retval; 1809 int retval;
@@ -1826,7 +1826,7 @@ static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1826 dev_err(udc->dev, "device_add error %d\n", retval); 1826 dev_err(udc->dev, "device_add error %d\n", retval);
1827 goto add_fail; 1827 goto add_fail;
1828 } 1828 }
1829 retval = bind(&udc->gadget); 1829 retval = bind(&udc->gadget, driver);
1830 if (retval) { 1830 if (retval) {
1831 dev_err(udc->dev, "bind to driver %s --> error %d\n", 1831 dev_err(udc->dev, "bind to driver %s --> error %d\n",
1832 driver->driver.name, retval); 1832 driver->driver.name, retval);
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index b35babed6fcb..e4192b887de9 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -863,26 +863,8 @@ int rndis_msg_parser(u8 configNr, u8 *buf)
863 */ 863 */
864 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n", 864 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
865 __func__, MsgType, MsgLength); 865 __func__, MsgType, MsgLength);
866 { 866 print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
867 unsigned i; 867 buf, MsgLength);
868 for (i = 0; i < MsgLength; i += 16) {
869 pr_debug("%03d: "
870 " %02x %02x %02x %02x"
871 " %02x %02x %02x %02x"
872 " %02x %02x %02x %02x"
873 " %02x %02x %02x %02x"
874 "\n",
875 i,
876 buf[i], buf [i+1],
877 buf[i+2], buf[i+3],
878 buf[i+4], buf [i+5],
879 buf[i+6], buf[i+7],
880 buf[i+8], buf [i+9],
881 buf[i+10], buf[i+11],
882 buf[i+12], buf [i+13],
883 buf[i+14], buf[i+15]);
884 }
885 }
886 break; 868 break;
887 } 869 }
888 870
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 0bb617e1dda2..6f696ee8b817 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -2197,7 +2197,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2197 /* issue soft reset */ 2197 /* issue soft reset */
2198 writel(GRSTCTL_CSftRst, hsotg->regs + GRSTCTL); 2198 writel(GRSTCTL_CSftRst, hsotg->regs + GRSTCTL);
2199 2199
2200 timeout = 1000; 2200 timeout = 10000;
2201 do { 2201 do {
2202 grstctl = readl(hsotg->regs + GRSTCTL); 2202 grstctl = readl(hsotg->regs + GRSTCTL);
2203 } while ((grstctl & GRSTCTL_CSftRst) && timeout-- > 0); 2203 } while ((grstctl & GRSTCTL_CSftRst) && timeout-- > 0);
@@ -2207,7 +2207,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2207 return -EINVAL; 2207 return -EINVAL;
2208 } 2208 }
2209 2209
2210 timeout = 1000; 2210 timeout = 10000;
2211 2211
2212 while (1) { 2212 while (1) {
2213 u32 grstctl = readl(hsotg->regs + GRSTCTL); 2213 u32 grstctl = readl(hsotg->regs + GRSTCTL);
@@ -3516,7 +3516,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3516 hsotg->dev = dev; 3516 hsotg->dev = dev;
3517 hsotg->plat = plat; 3517 hsotg->plat = plat;
3518 3518
3519 hsotg->clk = clk_get(&pdev->dev, "otg"); 3519 hsotg->clk = devm_clk_get(&pdev->dev, "otg");
3520 if (IS_ERR(hsotg->clk)) { 3520 if (IS_ERR(hsotg->clk)) {
3521 dev_err(dev, "cannot get otg clock\n"); 3521 dev_err(dev, "cannot get otg clock\n");
3522 return PTR_ERR(hsotg->clk); 3522 return PTR_ERR(hsotg->clk);
@@ -3667,7 +3667,6 @@ err_supplies:
3667 3667
3668err_clk: 3668err_clk:
3669 clk_disable_unprepare(hsotg->clk); 3669 clk_disable_unprepare(hsotg->clk);
3670 clk_put(hsotg->clk);
3671 3670
3672 return ret; 3671 return ret;
3673} 3672}
@@ -3693,7 +3692,6 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev)
3693 regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); 3692 regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
3694 3693
3695 clk_disable_unprepare(hsotg->clk); 3694 clk_disable_unprepare(hsotg->clk);
3696 clk_put(hsotg->clk);
3697 3695
3698 device_unregister(&hsotg->gadget.dev); 3696 device_unregister(&hsotg->gadget.dev);
3699 return 0; 3697 return 0;
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index e26a4e7ed2bf..d8e785d4ad59 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -135,7 +135,6 @@ struct s3c_hsudc_req {
135 * @dev: The device reference used by probe function. 135 * @dev: The device reference used by probe function.
136 * @lock: Lock to synchronize the usage of Endpoints (EP's are indexed). 136 * @lock: Lock to synchronize the usage of Endpoints (EP's are indexed).
137 * @regs: Remapped base address of controller's register space. 137 * @regs: Remapped base address of controller's register space.
138 * @mem_rsrc: Device memory resource used for remapping device register space.
139 * irq: IRQ number used by the controller. 138 * irq: IRQ number used by the controller.
140 * uclk: Reference to the controller clock. 139 * uclk: Reference to the controller clock.
141 * ep0state: Current state of EP0. 140 * ep0state: Current state of EP0.
@@ -150,7 +149,6 @@ struct s3c_hsudc {
150 struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsudc_supply_names)]; 149 struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsudc_supply_names)];
151 spinlock_t lock; 150 spinlock_t lock;
152 void __iomem *regs; 151 void __iomem *regs;
153 struct resource *mem_rsrc;
154 int irq; 152 int irq;
155 struct clk *uclk; 153 struct clk *uclk;
156 int ep0state; 154 int ep0state;
@@ -835,9 +833,9 @@ static struct usb_request *s3c_hsudc_alloc_request(struct usb_ep *_ep,
835{ 833{
836 struct s3c_hsudc_req *hsreq; 834 struct s3c_hsudc_req *hsreq;
837 835
838 hsreq = kzalloc(sizeof *hsreq, gfp_flags); 836 hsreq = kzalloc(sizeof(*hsreq), gfp_flags);
839 if (!hsreq) 837 if (!hsreq)
840 return 0; 838 return NULL;
841 839
842 INIT_LIST_HEAD(&hsreq->queue); 840 INIT_LIST_HEAD(&hsreq->queue);
843 return &hsreq->req; 841 return &hsreq->req;
@@ -906,16 +904,16 @@ static int s3c_hsudc_queue(struct usb_ep *_ep, struct usb_request *_req,
906 csr = readl((u32)hsudc->regs + offset); 904 csr = readl((u32)hsudc->regs + offset);
907 if (!(csr & S3C_ESR_TX_SUCCESS) && 905 if (!(csr & S3C_ESR_TX_SUCCESS) &&
908 (s3c_hsudc_write_fifo(hsep, hsreq) == 1)) 906 (s3c_hsudc_write_fifo(hsep, hsreq) == 1))
909 hsreq = 0; 907 hsreq = NULL;
910 } else { 908 } else {
911 csr = readl((u32)hsudc->regs + offset); 909 csr = readl((u32)hsudc->regs + offset);
912 if ((csr & S3C_ESR_RX_SUCCESS) 910 if ((csr & S3C_ESR_RX_SUCCESS)
913 && (s3c_hsudc_read_fifo(hsep, hsreq) == 1)) 911 && (s3c_hsudc_read_fifo(hsep, hsreq) == 1))
914 hsreq = 0; 912 hsreq = NULL;
915 } 913 }
916 } 914 }
917 915
918 if (hsreq != 0) 916 if (hsreq)
919 list_add_tail(&hsreq->queue, &hsep->queue); 917 list_add_tail(&hsreq->queue, &hsep->queue);
920 918
921 spin_unlock_irqrestore(&hsudc->lock, flags); 919 spin_unlock_irqrestore(&hsudc->lock, flags);
@@ -1271,7 +1269,7 @@ static int __devinit s3c_hsudc_probe(struct platform_device *pdev)
1271 struct s3c24xx_hsudc_platdata *pd = pdev->dev.platform_data; 1269 struct s3c24xx_hsudc_platdata *pd = pdev->dev.platform_data;
1272 int ret, i; 1270 int ret, i;
1273 1271
1274 hsudc = kzalloc(sizeof(struct s3c_hsudc) + 1272 hsudc = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsudc) +
1275 sizeof(struct s3c_hsudc_ep) * pd->epnum, 1273 sizeof(struct s3c_hsudc_ep) * pd->epnum,
1276 GFP_KERNEL); 1274 GFP_KERNEL);
1277 if (!hsudc) { 1275 if (!hsudc) {
@@ -1296,25 +1294,12 @@ static int __devinit s3c_hsudc_probe(struct platform_device *pdev)
1296 } 1294 }
1297 1295
1298 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1296 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1299 if (!res) {
1300 dev_err(dev, "unable to obtain driver resource data\n");
1301 ret = -ENODEV;
1302 goto err_res;
1303 }
1304
1305 hsudc->mem_rsrc = request_mem_region(res->start, resource_size(res),
1306 dev_name(&pdev->dev));
1307 if (!hsudc->mem_rsrc) {
1308 dev_err(dev, "failed to reserve register area\n");
1309 ret = -ENODEV;
1310 goto err_res;
1311 }
1312 1297
1313 hsudc->regs = ioremap(res->start, resource_size(res)); 1298 hsudc->regs = devm_request_and_ioremap(&pdev->dev, res);
1314 if (!hsudc->regs) { 1299 if (!hsudc->regs) {
1315 dev_err(dev, "error mapping device register area\n"); 1300 dev_err(dev, "error mapping device register area\n");
1316 ret = -EBUSY; 1301 ret = -EBUSY;
1317 goto err_remap; 1302 goto err_res;
1318 } 1303 }
1319 1304
1320 spin_lock_init(&hsudc->lock); 1305 spin_lock_init(&hsudc->lock);
@@ -1337,21 +1322,22 @@ static int __devinit s3c_hsudc_probe(struct platform_device *pdev)
1337 ret = platform_get_irq(pdev, 0); 1322 ret = platform_get_irq(pdev, 0);
1338 if (ret < 0) { 1323 if (ret < 0) {
1339 dev_err(dev, "unable to obtain IRQ number\n"); 1324 dev_err(dev, "unable to obtain IRQ number\n");
1340 goto err_irq; 1325 goto err_res;
1341 } 1326 }
1342 hsudc->irq = ret; 1327 hsudc->irq = ret;
1343 1328
1344 ret = request_irq(hsudc->irq, s3c_hsudc_irq, 0, driver_name, hsudc); 1329 ret = devm_request_irq(&pdev->dev, hsudc->irq, s3c_hsudc_irq, 0,
1330 driver_name, hsudc);
1345 if (ret < 0) { 1331 if (ret < 0) {
1346 dev_err(dev, "irq request failed\n"); 1332 dev_err(dev, "irq request failed\n");
1347 goto err_irq; 1333 goto err_res;
1348 } 1334 }
1349 1335
1350 hsudc->uclk = clk_get(&pdev->dev, "usb-device"); 1336 hsudc->uclk = devm_clk_get(&pdev->dev, "usb-device");
1351 if (IS_ERR(hsudc->uclk)) { 1337 if (IS_ERR(hsudc->uclk)) {
1352 dev_err(dev, "failed to find usb-device clock source\n"); 1338 dev_err(dev, "failed to find usb-device clock source\n");
1353 ret = PTR_ERR(hsudc->uclk); 1339 ret = PTR_ERR(hsudc->uclk);
1354 goto err_clk; 1340 goto err_res;
1355 } 1341 }
1356 clk_enable(hsudc->uclk); 1342 clk_enable(hsudc->uclk);
1357 1343
@@ -1377,21 +1363,12 @@ err_add_udc:
1377 device_unregister(&hsudc->gadget.dev); 1363 device_unregister(&hsudc->gadget.dev);
1378err_add_device: 1364err_add_device:
1379 clk_disable(hsudc->uclk); 1365 clk_disable(hsudc->uclk);
1380 clk_put(hsudc->uclk);
1381err_clk:
1382 free_irq(hsudc->irq, hsudc);
1383err_irq:
1384 iounmap(hsudc->regs);
1385
1386err_remap:
1387 release_mem_region(res->start, resource_size(res));
1388err_res: 1366err_res:
1389 if (!IS_ERR_OR_NULL(hsudc->transceiver)) 1367 if (!IS_ERR_OR_NULL(hsudc->transceiver))
1390 usb_put_phy(hsudc->transceiver); 1368 usb_put_phy(hsudc->transceiver);
1391 1369
1392 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1370 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies);
1393err_supplies: 1371err_supplies:
1394 kfree(hsudc);
1395 return ret; 1372 return ret;
1396} 1373}
1397 1374
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index f2e51f50e528..c33e942d119c 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -12,6 +12,8 @@
12 * (at your option) any later version. 12 * (at your option) any later version.
13 */ 13 */
14 14
15#define pr_fmt(fmt) "s3c2410_udc: " fmt
16
15#include <linux/module.h> 17#include <linux/module.h>
16#include <linux/kernel.h> 18#include <linux/kernel.h>
17#include <linux/delay.h> 19#include <linux/delay.h>
@@ -27,6 +29,7 @@
27#include <linux/clk.h> 29#include <linux/clk.h>
28#include <linux/gpio.h> 30#include <linux/gpio.h>
29#include <linux/prefetch.h> 31#include <linux/prefetch.h>
32#include <linux/io.h>
30 33
31#include <linux/debugfs.h> 34#include <linux/debugfs.h>
32#include <linux/seq_file.h> 35#include <linux/seq_file.h>
@@ -35,7 +38,6 @@
35#include <linux/usb/gadget.h> 38#include <linux/usb/gadget.h>
36 39
37#include <asm/byteorder.h> 40#include <asm/byteorder.h>
38#include <asm/io.h>
39#include <asm/irq.h> 41#include <asm/irq.h>
40#include <asm/unaligned.h> 42#include <asm/unaligned.h>
41#include <mach/irqs.h> 43#include <mach/irqs.h>
@@ -115,7 +117,7 @@ static int dprintk(int level, const char *fmt, ...)
115 sizeof(printk_buf)-len, fmt, args); 117 sizeof(printk_buf)-len, fmt, args);
116 va_end(args); 118 va_end(args);
117 119
118 return printk(KERN_DEBUG "%s", printk_buf); 120 return pr_debug("%s", printk_buf);
119} 121}
120#else 122#else
121static int dprintk(int level, const char *fmt, ...) 123static int dprintk(int level, const char *fmt, ...)
@@ -125,10 +127,10 @@ static int dprintk(int level, const char *fmt, ...)
125#endif 127#endif
126static int s3c2410_udc_debugfs_seq_show(struct seq_file *m, void *p) 128static int s3c2410_udc_debugfs_seq_show(struct seq_file *m, void *p)
127{ 129{
128 u32 addr_reg,pwr_reg,ep_int_reg,usb_int_reg; 130 u32 addr_reg, pwr_reg, ep_int_reg, usb_int_reg;
129 u32 ep_int_en_reg, usb_int_en_reg, ep0_csr; 131 u32 ep_int_en_reg, usb_int_en_reg, ep0_csr;
130 u32 ep1_i_csr1,ep1_i_csr2,ep1_o_csr1,ep1_o_csr2; 132 u32 ep1_i_csr1, ep1_i_csr2, ep1_o_csr1, ep1_o_csr2;
131 u32 ep2_i_csr1,ep2_i_csr2,ep2_o_csr1,ep2_o_csr2; 133 u32 ep2_i_csr1, ep2_i_csr2, ep2_o_csr1, ep2_o_csr2;
132 134
133 addr_reg = udc_read(S3C2410_UDC_FUNC_ADDR_REG); 135 addr_reg = udc_read(S3C2410_UDC_FUNC_ADDR_REG);
134 pwr_reg = udc_read(S3C2410_UDC_PWR_REG); 136 pwr_reg = udc_read(S3C2410_UDC_PWR_REG);
@@ -164,10 +166,10 @@ static int s3c2410_udc_debugfs_seq_show(struct seq_file *m, void *p)
164 "EP2_I_CSR2 : 0x%04X\n" 166 "EP2_I_CSR2 : 0x%04X\n"
165 "EP2_O_CSR1 : 0x%04X\n" 167 "EP2_O_CSR1 : 0x%04X\n"
166 "EP2_O_CSR2 : 0x%04X\n", 168 "EP2_O_CSR2 : 0x%04X\n",
167 addr_reg,pwr_reg,ep_int_reg,usb_int_reg, 169 addr_reg, pwr_reg, ep_int_reg, usb_int_reg,
168 ep_int_en_reg, usb_int_en_reg, ep0_csr, 170 ep_int_en_reg, usb_int_en_reg, ep0_csr,
169 ep1_i_csr1,ep1_i_csr2,ep1_o_csr1,ep1_o_csr2, 171 ep1_i_csr1, ep1_i_csr2, ep1_o_csr1, ep1_o_csr2,
170 ep2_i_csr1,ep2_i_csr2,ep2_o_csr1,ep2_o_csr2 172 ep2_i_csr1, ep2_i_csr2, ep2_o_csr1, ep2_o_csr2
171 ); 173 );
172 174
173 return 0; 175 return 0;
@@ -230,7 +232,7 @@ static inline void s3c2410_udc_set_ep0_de_out(void __iomem *base)
230{ 232{
231 udc_writeb(base, S3C2410_UDC_INDEX_EP0, S3C2410_UDC_INDEX_REG); 233 udc_writeb(base, S3C2410_UDC_INDEX_EP0, S3C2410_UDC_INDEX_REG);
232 234
233 udc_writeb(base,(S3C2410_UDC_EP0_CSR_SOPKTRDY 235 udc_writeb(base, (S3C2410_UDC_EP0_CSR_SOPKTRDY
234 | S3C2410_UDC_EP0_CSR_DE), 236 | S3C2410_UDC_EP0_CSR_DE),
235 S3C2410_UDC_EP0_CSR_REG); 237 S3C2410_UDC_EP0_CSR_REG);
236} 238}
@@ -263,7 +265,7 @@ static void s3c2410_udc_done(struct s3c2410_ep *ep,
263 265
264 list_del_init(&req->queue); 266 list_del_init(&req->queue);
265 267
266 if (likely (req->req.status == -EINPROGRESS)) 268 if (likely(req->req.status == -EINPROGRESS))
267 req->req.status = status; 269 req->req.status = status;
268 else 270 else
269 status = req->req.status; 271 status = req->req.status;
@@ -280,9 +282,9 @@ static void s3c2410_udc_nuke(struct s3c2410_udc *udc,
280 if (&ep->queue == NULL) 282 if (&ep->queue == NULL)
281 return; 283 return;
282 284
283 while (!list_empty (&ep->queue)) { 285 while (!list_empty(&ep->queue)) {
284 struct s3c2410_request *req; 286 struct s3c2410_request *req;
285 req = list_entry (ep->queue.next, struct s3c2410_request, 287 req = list_entry(ep->queue.next, struct s3c2410_request,
286 queue); 288 queue);
287 s3c2410_udc_done(ep, req, status); 289 s3c2410_udc_done(ep, req, status);
288 } 290 }
@@ -389,10 +391,10 @@ static int s3c2410_udc_write_fifo(struct s3c2410_ep *ep,
389 391
390 if (idx == 0) { 392 if (idx == 0) {
391 /* Reset signal => no need to say 'data sent' */ 393 /* Reset signal => no need to say 'data sent' */
392 if (! (udc_read(S3C2410_UDC_USB_INT_REG) 394 if (!(udc_read(S3C2410_UDC_USB_INT_REG)
393 & S3C2410_UDC_USBINT_RESET)) 395 & S3C2410_UDC_USBINT_RESET))
394 s3c2410_udc_set_ep0_de_in(base_addr); 396 s3c2410_udc_set_ep0_de_in(base_addr);
395 ep->dev->ep0state=EP0_IDLE; 397 ep->dev->ep0state = EP0_IDLE;
396 } else { 398 } else {
397 udc_write(idx, S3C2410_UDC_INDEX_REG); 399 udc_write(idx, S3C2410_UDC_INDEX_REG);
398 ep_csr = udc_read(S3C2410_UDC_IN_CSR1_REG); 400 ep_csr = udc_read(S3C2410_UDC_IN_CSR1_REG);
@@ -406,7 +408,7 @@ static int s3c2410_udc_write_fifo(struct s3c2410_ep *ep,
406 } else { 408 } else {
407 if (idx == 0) { 409 if (idx == 0) {
408 /* Reset signal => no need to say 'data sent' */ 410 /* Reset signal => no need to say 'data sent' */
409 if (! (udc_read(S3C2410_UDC_USB_INT_REG) 411 if (!(udc_read(S3C2410_UDC_USB_INT_REG)
410 & S3C2410_UDC_USBINT_RESET)) 412 & S3C2410_UDC_USBINT_RESET))
411 s3c2410_udc_set_ep0_ipr(base_addr); 413 s3c2410_udc_set_ep0_ipr(base_addr);
412 } else { 414 } else {
@@ -442,7 +444,7 @@ static int s3c2410_udc_read_fifo(struct s3c2410_ep *ep,
442 u8 *buf; 444 u8 *buf;
443 u32 ep_csr; 445 u32 ep_csr;
444 unsigned bufferspace; 446 unsigned bufferspace;
445 int is_last=1; 447 int is_last = 1;
446 unsigned avail; 448 unsigned avail;
447 int fifo_count = 0; 449 int fifo_count = 0;
448 u32 idx; 450 u32 idx;
@@ -510,7 +512,7 @@ static int s3c2410_udc_read_fifo(struct s3c2410_ep *ep,
510 /* Only ep0 debug messages are interesting */ 512 /* Only ep0 debug messages are interesting */
511 if (idx == 0) 513 if (idx == 0)
512 dprintk(DEBUG_VERBOSE, "%s fifo count : %d [last %d]\n", 514 dprintk(DEBUG_VERBOSE, "%s fifo count : %d [last %d]\n",
513 __func__, fifo_count,is_last); 515 __func__, fifo_count, is_last);
514 516
515 if (is_last) { 517 if (is_last) {
516 if (idx == 0) { 518 if (idx == 0) {
@@ -542,7 +544,7 @@ static int s3c2410_udc_read_fifo(struct s3c2410_ep *ep,
542 544
543static int s3c2410_udc_read_fifo_crq(struct usb_ctrlrequest *crq) 545static int s3c2410_udc_read_fifo_crq(struct usb_ctrlrequest *crq)
544{ 546{
545 unsigned char *outbuf = (unsigned char*)crq; 547 unsigned char *outbuf = (unsigned char *)crq;
546 int bytes_read = 0; 548 int bytes_read = 0;
547 549
548 udc_write(0, S3C2410_UDC_INDEX_REG); 550 udc_write(0, S3C2410_UDC_INDEX_REG);
@@ -648,7 +650,7 @@ static void s3c2410_udc_handle_ep0_idle(struct s3c2410_udc *dev,
648 650
649 switch (crq->bRequest) { 651 switch (crq->bRequest) {
650 case USB_REQ_SET_CONFIGURATION: 652 case USB_REQ_SET_CONFIGURATION:
651 dprintk(DEBUG_NORMAL, "USB_REQ_SET_CONFIGURATION ... \n"); 653 dprintk(DEBUG_NORMAL, "USB_REQ_SET_CONFIGURATION ...\n");
652 654
653 if (crq->bRequestType == USB_RECIP_DEVICE) { 655 if (crq->bRequestType == USB_RECIP_DEVICE) {
654 dev->req_config = 1; 656 dev->req_config = 1;
@@ -657,7 +659,7 @@ static void s3c2410_udc_handle_ep0_idle(struct s3c2410_udc *dev,
657 break; 659 break;
658 660
659 case USB_REQ_SET_INTERFACE: 661 case USB_REQ_SET_INTERFACE:
660 dprintk(DEBUG_NORMAL, "USB_REQ_SET_INTERFACE ... \n"); 662 dprintk(DEBUG_NORMAL, "USB_REQ_SET_INTERFACE ...\n");
661 663
662 if (crq->bRequestType == USB_RECIP_INTERFACE) { 664 if (crq->bRequestType == USB_RECIP_INTERFACE) {
663 dev->req_config = 1; 665 dev->req_config = 1;
@@ -666,7 +668,7 @@ static void s3c2410_udc_handle_ep0_idle(struct s3c2410_udc *dev,
666 break; 668 break;
667 669
668 case USB_REQ_SET_ADDRESS: 670 case USB_REQ_SET_ADDRESS:
669 dprintk(DEBUG_NORMAL, "USB_REQ_SET_ADDRESS ... \n"); 671 dprintk(DEBUG_NORMAL, "USB_REQ_SET_ADDRESS ...\n");
670 672
671 if (crq->bRequestType == USB_RECIP_DEVICE) { 673 if (crq->bRequestType == USB_RECIP_DEVICE) {
672 tmp = crq->wValue & 0x7F; 674 tmp = crq->wValue & 0x7F;
@@ -679,13 +681,12 @@ static void s3c2410_udc_handle_ep0_idle(struct s3c2410_udc *dev,
679 break; 681 break;
680 682
681 case USB_REQ_GET_STATUS: 683 case USB_REQ_GET_STATUS:
682 dprintk(DEBUG_NORMAL, "USB_REQ_GET_STATUS ... \n"); 684 dprintk(DEBUG_NORMAL, "USB_REQ_GET_STATUS ...\n");
683 s3c2410_udc_clear_ep0_opr(base_addr); 685 s3c2410_udc_clear_ep0_opr(base_addr);
684 686
685 if (dev->req_std) { 687 if (dev->req_std) {
686 if (!s3c2410_udc_get_status(dev, crq)) { 688 if (!s3c2410_udc_get_status(dev, crq))
687 return; 689 return;
688 }
689 } 690 }
690 break; 691 break;
691 692
@@ -750,7 +751,7 @@ static void s3c2410_udc_handle_ep0_idle(struct s3c2410_udc *dev,
750 /* deferred i/o == no response yet */ 751 /* deferred i/o == no response yet */
751 } else if (dev->req_pending) { 752 } else if (dev->req_pending) {
752 dprintk(DEBUG_VERBOSE, "dev->req_pending... what now?\n"); 753 dprintk(DEBUG_VERBOSE, "dev->req_pending... what now?\n");
753 dev->req_pending=0; 754 dev->req_pending = 0;
754 } 755 }
755 756
756 dprintk(DEBUG_VERBOSE, "ep0state %s\n", ep0states[dev->ep0state]); 757 dprintk(DEBUG_VERBOSE, "ep0state %s\n", ep0states[dev->ep0state]);
@@ -801,16 +802,14 @@ static void s3c2410_udc_handle_ep0(struct s3c2410_udc *dev)
801 802
802 case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR etc */ 803 case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR etc */
803 dprintk(DEBUG_NORMAL, "EP0_IN_DATA_PHASE ... what now?\n"); 804 dprintk(DEBUG_NORMAL, "EP0_IN_DATA_PHASE ... what now?\n");
804 if (!(ep0csr & S3C2410_UDC_EP0_CSR_IPKRDY) && req) { 805 if (!(ep0csr & S3C2410_UDC_EP0_CSR_IPKRDY) && req)
805 s3c2410_udc_write_fifo(ep, req); 806 s3c2410_udc_write_fifo(ep, req);
806 }
807 break; 807 break;
808 808
809 case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR etc */ 809 case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR etc */
810 dprintk(DEBUG_NORMAL, "EP0_OUT_DATA_PHASE ... what now?\n"); 810 dprintk(DEBUG_NORMAL, "EP0_OUT_DATA_PHASE ... what now?\n");
811 if ((ep0csr & S3C2410_UDC_EP0_CSR_OPKRDY) && req ) { 811 if ((ep0csr & S3C2410_UDC_EP0_CSR_OPKRDY) && req)
812 s3c2410_udc_read_fifo(ep,req); 812 s3c2410_udc_read_fifo(ep, req);
813 }
814 break; 813 break;
815 814
816 case EP0_END_XFER: 815 case EP0_END_XFER:
@@ -836,7 +835,7 @@ static void s3c2410_udc_handle_ep(struct s3c2410_ep *ep)
836 u32 ep_csr1; 835 u32 ep_csr1;
837 u32 idx; 836 u32 idx;
838 837
839 if (likely (!list_empty(&ep->queue))) 838 if (likely(!list_empty(&ep->queue)))
840 req = list_entry(ep->queue.next, 839 req = list_entry(ep->queue.next,
841 struct s3c2410_request, queue); 840 struct s3c2410_request, queue);
842 else 841 else
@@ -858,9 +857,8 @@ static void s3c2410_udc_handle_ep(struct s3c2410_ep *ep)
858 return; 857 return;
859 } 858 }
860 859
861 if (!(ep_csr1 & S3C2410_UDC_ICSR1_PKTRDY) && req) { 860 if (!(ep_csr1 & S3C2410_UDC_ICSR1_PKTRDY) && req)
862 s3c2410_udc_write_fifo(ep,req); 861 s3c2410_udc_write_fifo(ep, req);
863 }
864 } else { 862 } else {
865 udc_write(idx, S3C2410_UDC_INDEX_REG); 863 udc_write(idx, S3C2410_UDC_INDEX_REG);
866 ep_csr1 = udc_read(S3C2410_UDC_OUT_CSR1_REG); 864 ep_csr1 = udc_read(S3C2410_UDC_OUT_CSR1_REG);
@@ -873,9 +871,8 @@ static void s3c2410_udc_handle_ep(struct s3c2410_ep *ep)
873 return; 871 return;
874 } 872 }
875 873
876 if ((ep_csr1 & S3C2410_UDC_OCSR1_PKTRDY) && req) { 874 if ((ep_csr1 & S3C2410_UDC_OCSR1_PKTRDY) && req)
877 s3c2410_udc_read_fifo(ep,req); 875 s3c2410_udc_read_fifo(ep, req);
878 }
879 } 876 }
880} 877}
881 878
@@ -1057,7 +1054,7 @@ static int s3c2410_udc_ep_enable(struct usb_ep *_ep,
1057 struct s3c2410_ep *ep; 1054 struct s3c2410_ep *ep;
1058 u32 max, tmp; 1055 u32 max, tmp;
1059 unsigned long flags; 1056 unsigned long flags;
1060 u32 csr1,csr2; 1057 u32 csr1, csr2;
1061 u32 int_en_reg; 1058 u32 int_en_reg;
1062 1059
1063 ep = to_s3c2410_ep(_ep); 1060 ep = to_s3c2410_ep(_ep);
@@ -1073,7 +1070,7 @@ static int s3c2410_udc_ep_enable(struct usb_ep *_ep,
1073 1070
1074 max = usb_endpoint_maxp(desc) & 0x1fff; 1071 max = usb_endpoint_maxp(desc) & 0x1fff;
1075 1072
1076 local_irq_save (flags); 1073 local_irq_save(flags);
1077 _ep->maxpacket = max & 0x7ff; 1074 _ep->maxpacket = max & 0x7ff;
1078 ep->ep.desc = desc; 1075 ep->ep.desc = desc;
1079 ep->halted = 0; 1076 ep->halted = 0;
@@ -1117,11 +1114,11 @@ static int s3c2410_udc_ep_enable(struct usb_ep *_ep,
1117 1114
1118 /* print some debug message */ 1115 /* print some debug message */
1119 tmp = desc->bEndpointAddress; 1116 tmp = desc->bEndpointAddress;
1120 dprintk (DEBUG_NORMAL, "enable %s(%d) ep%x%s-blk max %02x\n", 1117 dprintk(DEBUG_NORMAL, "enable %s(%d) ep%x%s-blk max %02x\n",
1121 _ep->name,ep->num, tmp, 1118 _ep->name, ep->num, tmp,
1122 desc->bEndpointAddress & USB_DIR_IN ? "in" : "out", max); 1119 desc->bEndpointAddress & USB_DIR_IN ? "in" : "out", max);
1123 1120
1124 local_irq_restore (flags); 1121 local_irq_restore(flags);
1125 s3c2410_udc_set_halt(_ep, 0); 1122 s3c2410_udc_set_halt(_ep, 0);
1126 1123
1127 return 0; 1124 return 0;
@@ -1149,7 +1146,7 @@ static int s3c2410_udc_ep_disable(struct usb_ep *_ep)
1149 ep->ep.desc = NULL; 1146 ep->ep.desc = NULL;
1150 ep->halted = 1; 1147 ep->halted = 1;
1151 1148
1152 s3c2410_udc_nuke (ep->dev, ep, -ESHUTDOWN); 1149 s3c2410_udc_nuke(ep->dev, ep, -ESHUTDOWN);
1153 1150
1154 /* disable irqs */ 1151 /* disable irqs */
1155 int_en_reg = udc_read(S3C2410_UDC_EP_INT_EN_REG); 1152 int_en_reg = udc_read(S3C2410_UDC_EP_INT_EN_REG);
@@ -1170,16 +1167,16 @@ s3c2410_udc_alloc_request(struct usb_ep *_ep, gfp_t mem_flags)
1170{ 1167{
1171 struct s3c2410_request *req; 1168 struct s3c2410_request *req;
1172 1169
1173 dprintk(DEBUG_VERBOSE,"%s(%p,%d)\n", __func__, _ep, mem_flags); 1170 dprintk(DEBUG_VERBOSE, "%s(%p,%d)\n", __func__, _ep, mem_flags);
1174 1171
1175 if (!_ep) 1172 if (!_ep)
1176 return NULL; 1173 return NULL;
1177 1174
1178 req = kzalloc (sizeof(struct s3c2410_request), mem_flags); 1175 req = kzalloc(sizeof(struct s3c2410_request), mem_flags);
1179 if (!req) 1176 if (!req)
1180 return NULL; 1177 return NULL;
1181 1178
1182 INIT_LIST_HEAD (&req->queue); 1179 INIT_LIST_HEAD(&req->queue);
1183 return &req->req; 1180 return &req->req;
1184} 1181}
1185 1182
@@ -1197,7 +1194,7 @@ s3c2410_udc_free_request(struct usb_ep *_ep, struct usb_request *_req)
1197 if (!ep || !_req || (!ep->ep.desc && _ep->name != ep0name)) 1194 if (!ep || !_req || (!ep->ep.desc && _ep->name != ep0name))
1198 return; 1195 return;
1199 1196
1200 WARN_ON (!list_empty (&req->queue)); 1197 WARN_ON(!list_empty(&req->queue));
1201 kfree(req); 1198 kfree(req);
1202} 1199}
1203 1200
@@ -1220,12 +1217,12 @@ static int s3c2410_udc_queue(struct usb_ep *_ep, struct usb_request *_req,
1220 } 1217 }
1221 1218
1222 dev = ep->dev; 1219 dev = ep->dev;
1223 if (unlikely (!dev->driver 1220 if (unlikely(!dev->driver
1224 || dev->gadget.speed == USB_SPEED_UNKNOWN)) { 1221 || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
1225 return -ESHUTDOWN; 1222 return -ESHUTDOWN;
1226 } 1223 }
1227 1224
1228 local_irq_save (flags); 1225 local_irq_save(flags);
1229 1226
1230 if (unlikely(!_req || !_req->complete 1227 if (unlikely(!_req || !_req->complete
1231 || !_req->buf || !list_empty(&req->queue))) { 1228 || !_req->buf || !list_empty(&req->queue))) {
@@ -1233,7 +1230,7 @@ static int s3c2410_udc_queue(struct usb_ep *_ep, struct usb_request *_req,
1233 dprintk(DEBUG_NORMAL, "%s: 1 X X X\n", __func__); 1230 dprintk(DEBUG_NORMAL, "%s: 1 X X X\n", __func__);
1234 else { 1231 else {
1235 dprintk(DEBUG_NORMAL, "%s: 0 %01d %01d %01d\n", 1232 dprintk(DEBUG_NORMAL, "%s: 0 %01d %01d %01d\n",
1236 __func__, !_req->complete,!_req->buf, 1233 __func__, !_req->complete, !_req->buf,
1237 !list_empty(&req->queue)); 1234 !list_empty(&req->queue));
1238 } 1235 }
1239 1236
@@ -1299,7 +1296,7 @@ static int s3c2410_udc_queue(struct usb_ep *_ep, struct usb_request *_req,
1299 } 1296 }
1300 1297
1301 /* pio or dma irq handler advances the queue. */ 1298 /* pio or dma irq handler advances the queue. */
1302 if (likely (req != 0)) 1299 if (likely(req))
1303 list_add_tail(&req->queue, &ep->queue); 1300 list_add_tail(&req->queue, &ep->queue);
1304 1301
1305 local_irq_restore(flags); 1302 local_irq_restore(flags);
@@ -1329,11 +1326,11 @@ static int s3c2410_udc_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1329 1326
1330 udc = to_s3c2410_udc(ep->gadget); 1327 udc = to_s3c2410_udc(ep->gadget);
1331 1328
1332 local_irq_save (flags); 1329 local_irq_save(flags);
1333 1330
1334 list_for_each_entry (req, &ep->queue, queue) { 1331 list_for_each_entry(req, &ep->queue, queue) {
1335 if (&req->req == _req) { 1332 if (&req->req == _req) {
1336 list_del_init (&req->queue); 1333 list_del_init(&req->queue);
1337 _req->status = -ECONNRESET; 1334 _req->status = -ECONNRESET;
1338 retval = 0; 1335 retval = 0;
1339 break; 1336 break;
@@ -1348,7 +1345,7 @@ static int s3c2410_udc_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1348 s3c2410_udc_done(ep, req, -ECONNRESET); 1345 s3c2410_udc_done(ep, req, -ECONNRESET);
1349 } 1346 }
1350 1347
1351 local_irq_restore (flags); 1348 local_irq_restore(flags);
1352 return retval; 1349 return retval;
1353} 1350}
1354 1351
@@ -1367,7 +1364,7 @@ static int s3c2410_udc_set_halt(struct usb_ep *_ep, int value)
1367 return -EINVAL; 1364 return -EINVAL;
1368 } 1365 }
1369 1366
1370 local_irq_save (flags); 1367 local_irq_save(flags);
1371 1368
1372 idx = ep->bEndpointAddress & 0x7F; 1369 idx = ep->bEndpointAddress & 0x7F;
1373 1370
@@ -1376,7 +1373,7 @@ static int s3c2410_udc_set_halt(struct usb_ep *_ep, int value)
1376 s3c2410_udc_set_ep0_de_out(base_addr); 1373 s3c2410_udc_set_ep0_de_out(base_addr);
1377 } else { 1374 } else {
1378 udc_write(idx, S3C2410_UDC_INDEX_REG); 1375 udc_write(idx, S3C2410_UDC_INDEX_REG);
1379 ep_csr = udc_read((ep->bEndpointAddress &USB_DIR_IN) 1376 ep_csr = udc_read((ep->bEndpointAddress & USB_DIR_IN)
1380 ? S3C2410_UDC_IN_CSR1_REG 1377 ? S3C2410_UDC_IN_CSR1_REG
1381 : S3C2410_UDC_OUT_CSR1_REG); 1378 : S3C2410_UDC_OUT_CSR1_REG);
1382 1379
@@ -1404,7 +1401,7 @@ static int s3c2410_udc_set_halt(struct usb_ep *_ep, int value)
1404 } 1401 }
1405 1402
1406 ep->halted = value ? 1 : 0; 1403 ep->halted = value ? 1 : 0;
1407 local_irq_restore (flags); 1404 local_irq_restore(flags);
1408 1405
1409 return 0; 1406 return 0;
1410} 1407}
@@ -1484,9 +1481,9 @@ static int s3c2410_udc_set_pullup(struct s3c2410_udc *udc, int is_on)
1484 } 1481 }
1485 s3c2410_udc_disable(udc); 1482 s3c2410_udc_disable(udc);
1486 } 1483 }
1487 } 1484 } else {
1488 else
1489 return -EOPNOTSUPP; 1485 return -EOPNOTSUPP;
1486 }
1490 1487
1491 return 0; 1488 return 0;
1492} 1489}
@@ -1542,7 +1539,7 @@ static int s3c2410_vbus_draw(struct usb_gadget *_gadget, unsigned ma)
1542} 1539}
1543 1540
1544static int s3c2410_udc_start(struct usb_gadget_driver *driver, 1541static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1545 int (*bind)(struct usb_gadget *)); 1542 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
1546static int s3c2410_udc_stop(struct usb_gadget_driver *driver); 1543static int s3c2410_udc_stop(struct usb_gadget_driver *driver);
1547 1544
1548static const struct usb_gadget_ops s3c2410_ops = { 1545static const struct usb_gadget_ops s3c2410_ops = {
@@ -1617,20 +1614,20 @@ static void s3c2410_udc_reinit(struct s3c2410_udc *dev)
1617 u32 i; 1614 u32 i;
1618 1615
1619 /* device/ep0 records init */ 1616 /* device/ep0 records init */
1620 INIT_LIST_HEAD (&dev->gadget.ep_list); 1617 INIT_LIST_HEAD(&dev->gadget.ep_list);
1621 INIT_LIST_HEAD (&dev->gadget.ep0->ep_list); 1618 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
1622 dev->ep0state = EP0_IDLE; 1619 dev->ep0state = EP0_IDLE;
1623 1620
1624 for (i = 0; i < S3C2410_ENDPOINTS; i++) { 1621 for (i = 0; i < S3C2410_ENDPOINTS; i++) {
1625 struct s3c2410_ep *ep = &dev->ep[i]; 1622 struct s3c2410_ep *ep = &dev->ep[i];
1626 1623
1627 if (i != 0) 1624 if (i != 0)
1628 list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list); 1625 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
1629 1626
1630 ep->dev = dev; 1627 ep->dev = dev;
1631 ep->ep.desc = NULL; 1628 ep->ep.desc = NULL;
1632 ep->halted = 0; 1629 ep->halted = 0;
1633 INIT_LIST_HEAD (&ep->queue); 1630 INIT_LIST_HEAD(&ep->queue);
1634 } 1631 }
1635} 1632}
1636 1633
@@ -1668,7 +1665,7 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev)
1668} 1665}
1669 1666
1670static int s3c2410_udc_start(struct usb_gadget_driver *driver, 1667static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1671 int (*bind)(struct usb_gadget *)) 1668 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1672{ 1669{
1673 struct s3c2410_udc *udc = the_controller; 1670 struct s3c2410_udc *udc = the_controller;
1674 int retval; 1671 int retval;
@@ -1683,13 +1680,13 @@ static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1683 return -EBUSY; 1680 return -EBUSY;
1684 1681
1685 if (!bind || !driver->setup || driver->max_speed < USB_SPEED_FULL) { 1682 if (!bind || !driver->setup || driver->max_speed < USB_SPEED_FULL) {
1686 printk(KERN_ERR "Invalid driver: bind %p setup %p speed %d\n", 1683 dev_err(&udc->gadget.dev, "Invalid driver: bind %p setup %p speed %d\n",
1687 bind, driver->setup, driver->max_speed); 1684 bind, driver->setup, driver->max_speed);
1688 return -EINVAL; 1685 return -EINVAL;
1689 } 1686 }
1690#if defined(MODULE) 1687#if defined(MODULE)
1691 if (!driver->unbind) { 1688 if (!driver->unbind) {
1692 printk(KERN_ERR "Invalid driver: no unbind method\n"); 1689 dev_err(&udc->gadget.dev, "Invalid driver: no unbind method\n");
1693 return -EINVAL; 1690 return -EINVAL;
1694 } 1691 }
1695#endif 1692#endif
@@ -1699,15 +1696,17 @@ static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1699 udc->gadget.dev.driver = &driver->driver; 1696 udc->gadget.dev.driver = &driver->driver;
1700 1697
1701 /* Bind the driver */ 1698 /* Bind the driver */
1702 if ((retval = device_add(&udc->gadget.dev)) != 0) { 1699 retval = device_add(&udc->gadget.dev);
1703 printk(KERN_ERR "Error in device_add() : %d\n",retval); 1700 if (retval) {
1701 dev_err(&udc->gadget.dev, "Error in device_add() : %d\n", retval);
1704 goto register_error; 1702 goto register_error;
1705 } 1703 }
1706 1704
1707 dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n", 1705 dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n",
1708 driver->driver.name); 1706 driver->driver.name);
1709 1707
1710 if ((retval = bind(&udc->gadget)) != 0) { 1708 retval = bind(&udc->gadget, driver);
1709 if (retval) {
1711 device_del(&udc->gadget.dev); 1710 device_del(&udc->gadget.dev);
1712 goto register_error; 1711 goto register_error;
1713 } 1712 }
@@ -1865,7 +1864,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1865 memory.ep[4].fifo_size = S3C2440_EP_FIFO_SIZE; 1864 memory.ep[4].fifo_size = S3C2440_EP_FIFO_SIZE;
1866 } 1865 }
1867 1866
1868 spin_lock_init (&udc->lock); 1867 spin_lock_init(&udc->lock);
1869 udc_info = pdev->dev.platform_data; 1868 udc_info = pdev->dev.platform_data;
1870 1869
1871 rsrc_start = S3C2410_PA_USBDEV; 1870 rsrc_start = S3C2410_PA_USBDEV;
@@ -2028,7 +2027,8 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
2028} 2027}
2029 2028
2030#ifdef CONFIG_PM 2029#ifdef CONFIG_PM
2031static int s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message) 2030static int
2031s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message)
2032{ 2032{
2033 s3c2410_udc_command(S3C2410_UDC_P_DISABLE); 2033 s3c2410_udc_command(S3C2410_UDC_P_DISABLE);
2034 2034
@@ -2073,7 +2073,7 @@ static int __init udc_init(void)
2073 2073
2074 s3c2410_udc_debugfs_root = debugfs_create_dir(gadget_name, NULL); 2074 s3c2410_udc_debugfs_root = debugfs_create_dir(gadget_name, NULL);
2075 if (IS_ERR(s3c2410_udc_debugfs_root)) { 2075 if (IS_ERR(s3c2410_udc_debugfs_root)) {
2076 printk(KERN_ERR "%s: debugfs dir creation failed %ld\n", 2076 pr_err("%s: debugfs dir creation failed %ld\n",
2077 gadget_name, PTR_ERR(s3c2410_udc_debugfs_root)); 2077 gadget_name, PTR_ERR(s3c2410_udc_debugfs_root));
2078 s3c2410_udc_debugfs_root = NULL; 2078 s3c2410_udc_debugfs_root = NULL;
2079 } 2079 }
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 665c07422c26..44752f531e85 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -11,7 +11,6 @@
11 */ 11 */
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/utsname.h>
15#include <linux/device.h> 14#include <linux/device.h>
16#include <linux/tty.h> 15#include <linux/tty.h>
17#include <linux/tty_flip.h> 16#include <linux/tty_flip.h>
@@ -37,17 +36,13 @@
37 * the runtime footprint, and giving us at least some parts of what 36 * the runtime footprint, and giving us at least some parts of what
38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
39 */ 38 */
40#include "composite.c"
41#include "usbstring.c"
42#include "config.c"
43#include "epautoconf.c"
44
45#include "f_acm.c" 39#include "f_acm.c"
46#include "f_obex.c" 40#include "f_obex.c"
47#include "f_serial.c" 41#include "f_serial.c"
48#include "u_serial.c" 42#include "u_serial.c"
49 43
50/*-------------------------------------------------------------------------*/ 44/*-------------------------------------------------------------------------*/
45USB_GADGET_COMPOSITE_OPTIONS();
51 46
52/* Thanks to NetChip Technologies for donating this product ID. 47/* Thanks to NetChip Technologies for donating this product ID.
53* 48*
@@ -61,15 +56,12 @@
61 56
62/* string IDs are assigned dynamically */ 57/* string IDs are assigned dynamically */
63 58
64#define STRING_MANUFACTURER_IDX 0 59#define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX
65#define STRING_PRODUCT_IDX 1
66#define STRING_DESCRIPTION_IDX 2
67
68static char manufacturer[50];
69 60
70static struct usb_string strings_dev[] = { 61static struct usb_string strings_dev[] = {
71 [STRING_MANUFACTURER_IDX].s = manufacturer, 62 [USB_GADGET_MANUFACTURER_IDX].s = "",
72 [STRING_PRODUCT_IDX].s = GS_VERSION_NAME, 63 [USB_GADGET_PRODUCT_IDX].s = GS_VERSION_NAME,
64 [USB_GADGET_SERIAL_IDX].s = "",
73 [STRING_DESCRIPTION_IDX].s = NULL /* updated; f(use_acm) */, 65 [STRING_DESCRIPTION_IDX].s = NULL /* updated; f(use_acm) */,
74 { } /* end of list */ 66 { } /* end of list */
75}; 67};
@@ -94,7 +86,7 @@ static struct usb_device_descriptor device_desc = {
94 /* .bMaxPacketSize0 = f(hardware) */ 86 /* .bMaxPacketSize0 = f(hardware) */
95 .idVendor = cpu_to_le16(GS_VENDOR_ID), 87 .idVendor = cpu_to_le16(GS_VENDOR_ID),
96 /* .idProduct = f(use_acm) */ 88 /* .idProduct = f(use_acm) */
97 /* .bcdDevice = f(hardware) */ 89 .bcdDevice = cpu_to_le16(GS_VERSION_NUM),
98 /* .iManufacturer = DYNAMIC */ 90 /* .iManufacturer = DYNAMIC */
99 /* .iProduct = DYNAMIC */ 91 /* .iProduct = DYNAMIC */
100 .bNumConfigurations = 1, 92 .bNumConfigurations = 1,
@@ -162,8 +154,6 @@ static struct usb_configuration serial_config_driver = {
162 154
163static int __init gs_bind(struct usb_composite_dev *cdev) 155static int __init gs_bind(struct usb_composite_dev *cdev)
164{ 156{
165 int gcnum;
166 struct usb_gadget *gadget = cdev->gadget;
167 int status; 157 int status;
168 158
169 status = gserial_setup(cdev->gadget, n_ports); 159 status = gserial_setup(cdev->gadget, n_ports);
@@ -174,50 +164,14 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
174 * contents can be overridden by the composite_dev glue. 164 * contents can be overridden by the composite_dev glue.
175 */ 165 */
176 166
177 /* device description: manufacturer, product */ 167 status = usb_string_ids_tab(cdev, strings_dev);
178 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
179 init_utsname()->sysname, init_utsname()->release,
180 gadget->name);
181 status = usb_string_id(cdev);
182 if (status < 0) 168 if (status < 0)
183 goto fail; 169 goto fail;
184 strings_dev[STRING_MANUFACTURER_IDX].id = status; 170 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
185 171 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
186 device_desc.iManufacturer = status; 172 status = strings_dev[STRING_DESCRIPTION_IDX].id;
187
188 status = usb_string_id(cdev);
189 if (status < 0)
190 goto fail;
191 strings_dev[STRING_PRODUCT_IDX].id = status;
192
193 device_desc.iProduct = status;
194
195 /* config description */
196 status = usb_string_id(cdev);
197 if (status < 0)
198 goto fail;
199 strings_dev[STRING_DESCRIPTION_IDX].id = status;
200
201 serial_config_driver.iConfiguration = status; 173 serial_config_driver.iConfiguration = status;
202 174
203 /* set up other descriptors */
204 gcnum = usb_gadget_controller_number(gadget);
205 if (gcnum >= 0)
206 device_desc.bcdDevice = cpu_to_le16(GS_VERSION_NUM | gcnum);
207 else {
208 /* this is so simple (for now, no altsettings) that it
209 * SHOULD NOT have problems with bulk-capable hardware.
210 * so warn about unrcognized controllers -- don't panic.
211 *
212 * things like configuration and altsetting numbering
213 * can need hardware-specific attention though.
214 */
215 pr_warning("gs_bind: controller '%s' not recognized\n",
216 gadget->name);
217 device_desc.bcdDevice =
218 cpu_to_le16(GS_VERSION_NUM | 0x0099);
219 }
220
221 if (gadget_is_otg(cdev->gadget)) { 175 if (gadget_is_otg(cdev->gadget)) {
222 serial_config_driver.descriptors = otg_desc; 176 serial_config_driver.descriptors = otg_desc;
223 serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 177 serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
@@ -229,6 +183,7 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
229 if (status < 0) 183 if (status < 0)
230 goto fail; 184 goto fail;
231 185
186 usb_composite_overwrite_options(cdev, &coverwrite);
232 INFO(cdev, "%s\n", GS_VERSION_NAME); 187 INFO(cdev, "%s\n", GS_VERSION_NAME);
233 188
234 return 0; 189 return 0;
@@ -238,11 +193,12 @@ fail:
238 return status; 193 return status;
239} 194}
240 195
241static struct usb_composite_driver gserial_driver = { 196static __refdata struct usb_composite_driver gserial_driver = {
242 .name = "g_serial", 197 .name = "g_serial",
243 .dev = &device_desc, 198 .dev = &device_desc,
244 .strings = dev_strings, 199 .strings = dev_strings,
245 .max_speed = USB_SPEED_SUPER, 200 .max_speed = USB_SPEED_SUPER,
201 .bind = gs_bind,
246}; 202};
247 203
248static int __init init(void) 204static int __init init(void)
@@ -271,7 +227,7 @@ static int __init init(void)
271 } 227 }
272 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label; 228 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label;
273 229
274 return usb_composite_probe(&gserial_driver, gs_bind); 230 return usb_composite_probe(&gserial_driver);
275} 231}
276module_init(init); 232module_init(init);
277 233
diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c
index 5444866e13ef..eaa1005377fc 100644
--- a/drivers/usb/gadget/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/tcm_usb_gadget.c
@@ -25,13 +25,10 @@
25#include <target/configfs_macros.h> 25#include <target/configfs_macros.h>
26#include <asm/unaligned.h> 26#include <asm/unaligned.h>
27 27
28#include "usbstring.c"
29#include "epautoconf.c"
30#include "config.c"
31#include "composite.c"
32
33#include "tcm_usb_gadget.h" 28#include "tcm_usb_gadget.h"
34 29
30USB_GADGET_COMPOSITE_OPTIONS();
31
35static struct target_fabric_configfs *usbg_fabric_configfs; 32static struct target_fabric_configfs *usbg_fabric_configfs;
36 33
37static inline struct f_uas *to_f_uas(struct usb_function *f) 34static inline struct f_uas *to_f_uas(struct usb_function *f)
@@ -1977,7 +1974,6 @@ static struct usb_interface_descriptor bot_intf_desc = {
1977 .bInterfaceClass = USB_CLASS_MASS_STORAGE, 1974 .bInterfaceClass = USB_CLASS_MASS_STORAGE,
1978 .bInterfaceSubClass = USB_SC_SCSI, 1975 .bInterfaceSubClass = USB_SC_SCSI,
1979 .bInterfaceProtocol = USB_PR_BULK, 1976 .bInterfaceProtocol = USB_PR_BULK,
1980 .iInterface = USB_G_STR_INT_UAS,
1981}; 1977};
1982 1978
1983static struct usb_interface_descriptor uasp_intf_desc = { 1979static struct usb_interface_descriptor uasp_intf_desc = {
@@ -1988,7 +1984,6 @@ static struct usb_interface_descriptor uasp_intf_desc = {
1988 .bInterfaceClass = USB_CLASS_MASS_STORAGE, 1984 .bInterfaceClass = USB_CLASS_MASS_STORAGE,
1989 .bInterfaceSubClass = USB_SC_SCSI, 1985 .bInterfaceSubClass = USB_SC_SCSI,
1990 .bInterfaceProtocol = USB_PR_UAS, 1986 .bInterfaceProtocol = USB_PR_UAS,
1991 .iInterface = USB_G_STR_INT_BBB,
1992}; 1987};
1993 1988
1994static struct usb_endpoint_descriptor uasp_bi_desc = { 1989static struct usb_endpoint_descriptor uasp_bi_desc = {
@@ -2209,20 +2204,16 @@ static struct usb_device_descriptor usbg_device_desc = {
2209 .bDeviceClass = USB_CLASS_PER_INTERFACE, 2204 .bDeviceClass = USB_CLASS_PER_INTERFACE,
2210 .idVendor = cpu_to_le16(UAS_VENDOR_ID), 2205 .idVendor = cpu_to_le16(UAS_VENDOR_ID),
2211 .idProduct = cpu_to_le16(UAS_PRODUCT_ID), 2206 .idProduct = cpu_to_le16(UAS_PRODUCT_ID),
2212 .iManufacturer = USB_G_STR_MANUFACTOR,
2213 .iProduct = USB_G_STR_PRODUCT,
2214 .iSerialNumber = USB_G_STR_SERIAL,
2215
2216 .bNumConfigurations = 1, 2207 .bNumConfigurations = 1,
2217}; 2208};
2218 2209
2219static struct usb_string usbg_us_strings[] = { 2210static struct usb_string usbg_us_strings[] = {
2220 { USB_G_STR_MANUFACTOR, "Target Manufactor"}, 2211 [USB_GADGET_MANUFACTURER_IDX].s = "Target Manufactor",
2221 { USB_G_STR_PRODUCT, "Target Product"}, 2212 [USB_GADGET_PRODUCT_IDX].s = "Target Product",
2222 { USB_G_STR_SERIAL, "000000000001"}, 2213 [USB_GADGET_SERIAL_IDX].s = "000000000001",
2223 { USB_G_STR_CONFIG, "default config"}, 2214 [USB_G_STR_CONFIG].s = "default config",
2224 { USB_G_STR_INT_UAS, "USB Attached SCSI"}, 2215 [USB_G_STR_INT_UAS].s = "USB Attached SCSI",
2225 { USB_G_STR_INT_BBB, "Bulk Only Transport"}, 2216 [USB_G_STR_INT_BBB].s = "Bulk Only Transport",
2226 { }, 2217 { },
2227}; 2218};
2228 2219
@@ -2244,7 +2235,6 @@ static int guas_unbind(struct usb_composite_dev *cdev)
2244static struct usb_configuration usbg_config_driver = { 2235static struct usb_configuration usbg_config_driver = {
2245 .label = "Linux Target", 2236 .label = "Linux Target",
2246 .bConfigurationValue = 1, 2237 .bConfigurationValue = 1,
2247 .iConfiguration = USB_G_STR_CONFIG,
2248 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 2238 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
2249}; 2239};
2250 2240
@@ -2417,6 +2407,9 @@ static int usbg_cfg_bind(struct usb_configuration *c)
2417 fu->function.disable = usbg_disable; 2407 fu->function.disable = usbg_disable;
2418 fu->tpg = the_only_tpg_I_currently_have; 2408 fu->tpg = the_only_tpg_I_currently_have;
2419 2409
2410 bot_intf_desc.iInterface = usbg_us_strings[USB_G_STR_INT_BBB].id;
2411 uasp_intf_desc.iInterface = usbg_us_strings[USB_G_STR_INT_UAS].id;
2412
2420 ret = usb_add_function(c, &fu->function); 2413 ret = usb_add_function(c, &fu->function);
2421 if (ret) 2414 if (ret)
2422 goto err; 2415 goto err;
@@ -2431,22 +2424,38 @@ static int usb_target_bind(struct usb_composite_dev *cdev)
2431{ 2424{
2432 int ret; 2425 int ret;
2433 2426
2427 ret = usb_string_ids_tab(cdev, usbg_us_strings);
2428 if (ret)
2429 return ret;
2430
2431 usbg_device_desc.iManufacturer =
2432 usbg_us_strings[USB_GADGET_MANUFACTURER_IDX].id;
2433 usbg_device_desc.iProduct = usbg_us_strings[USB_GADGET_PRODUCT_IDX].id;
2434 usbg_device_desc.iSerialNumber =
2435 usbg_us_strings[USB_GADGET_SERIAL_IDX].id;
2436 usbg_config_driver.iConfiguration =
2437 usbg_us_strings[USB_G_STR_CONFIG].id;
2438
2434 ret = usb_add_config(cdev, &usbg_config_driver, 2439 ret = usb_add_config(cdev, &usbg_config_driver,
2435 usbg_cfg_bind); 2440 usbg_cfg_bind);
2441 if (ret)
2442 return ret;
2443 usb_composite_overwrite_options(cdev, &coverwrite);
2436 return 0; 2444 return 0;
2437} 2445}
2438 2446
2439static struct usb_composite_driver usbg_driver = { 2447static __refdata struct usb_composite_driver usbg_driver = {
2440 .name = "g_target", 2448 .name = "g_target",
2441 .dev = &usbg_device_desc, 2449 .dev = &usbg_device_desc,
2442 .strings = usbg_strings, 2450 .strings = usbg_strings,
2443 .max_speed = USB_SPEED_SUPER, 2451 .max_speed = USB_SPEED_SUPER,
2452 .bind = usb_target_bind,
2444 .unbind = guas_unbind, 2453 .unbind = guas_unbind,
2445}; 2454};
2446 2455
2447static int usbg_attach(struct usbg_tpg *tpg) 2456static int usbg_attach(struct usbg_tpg *tpg)
2448{ 2457{
2449 return usb_composite_probe(&usbg_driver, usb_target_bind); 2458 return usb_composite_probe(&usbg_driver);
2450} 2459}
2451 2460
2452static void usbg_detach(struct usbg_tpg *tpg) 2461static void usbg_detach(struct usbg_tpg *tpg)
diff --git a/drivers/usb/gadget/tcm_usb_gadget.h b/drivers/usb/gadget/tcm_usb_gadget.h
index bb18999a9a8d..8289219925b8 100644
--- a/drivers/usb/gadget/tcm_usb_gadget.h
+++ b/drivers/usb/gadget/tcm_usb_gadget.h
@@ -16,12 +16,11 @@
16#define UASP_SS_EP_COMP_LOG_STREAMS 4 16#define UASP_SS_EP_COMP_LOG_STREAMS 4
17#define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS) 17#define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS)
18 18
19#define USB_G_STR_MANUFACTOR 1 19enum {
20#define USB_G_STR_PRODUCT 2 20 USB_G_STR_CONFIG = USB_GADGET_FIRST_AVAIL_IDX,
21#define USB_G_STR_SERIAL 3 21 USB_G_STR_INT_UAS,
22#define USB_G_STR_CONFIG 4 22 USB_G_STR_INT_BBB,
23#define USB_G_STR_INT_UAS 5 23};
24#define USB_G_STR_INT_BBB 6
25 24
26#define USB_G_ALT_INT_BBB 0 25#define USB_G_ALT_INT_BBB 0
27#define USB_G_ALT_INT_UAS 1 26#define USB_G_ALT_INT_UAS 1
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 0e5230926154..b9c46900c2c1 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -14,6 +14,7 @@
14/* #define VERBOSE_DEBUG */ 14/* #define VERBOSE_DEBUG */
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h>
17#include <linux/gfp.h> 18#include <linux/gfp.h>
18#include <linux/device.h> 19#include <linux/device.h>
19#include <linux/ctype.h> 20#include <linux/ctype.h>
@@ -83,17 +84,10 @@ struct eth_dev {
83 84
84#define DEFAULT_QLEN 2 /* double buffering by default */ 85#define DEFAULT_QLEN 2 /* double buffering by default */
85 86
86
87#ifdef CONFIG_USB_GADGET_DUALSPEED
88
89static unsigned qmult = 5; 87static unsigned qmult = 5;
90module_param(qmult, uint, S_IRUGO|S_IWUSR); 88module_param(qmult, uint, S_IRUGO|S_IWUSR);
91MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed"); 89MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
92 90
93#else /* full speed (low speed doesn't do bulk) */
94#define qmult 1
95#endif
96
97/* for dual-speed hardware, use deeper queues at high/super speed */ 91/* for dual-speed hardware, use deeper queues at high/super speed */
98static inline int qlen(struct usb_gadget *gadget) 92static inline int qlen(struct usb_gadget *gadget)
99{ 93{
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index e5e44f8cde9a..f3cd9690b101 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -118,7 +118,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
118 */ 118 */
119static inline int usb_gadget_start(struct usb_gadget *gadget, 119static inline int usb_gadget_start(struct usb_gadget *gadget,
120 struct usb_gadget_driver *driver, 120 struct usb_gadget_driver *driver,
121 int (*bind)(struct usb_gadget *)) 121 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
122{ 122{
123 return gadget->ops->start(driver, bind); 123 return gadget->ops->start(driver, bind);
124} 124}
@@ -262,8 +262,8 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
262 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 262 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
263 263
264 if (udc_is_newstyle(udc)) { 264 if (udc_is_newstyle(udc)) {
265 udc->driver->disconnect(udc->gadget);
266 usb_gadget_disconnect(udc->gadget); 265 usb_gadget_disconnect(udc->gadget);
266 udc->driver->disconnect(udc->gadget);
267 udc->driver->unbind(udc->gadget); 267 udc->driver->unbind(udc->gadget);
268 usb_gadget_udc_stop(udc->gadget, udc->driver); 268 usb_gadget_udc_stop(udc->gadget, udc->driver);
269 } else { 269 } else {
@@ -311,13 +311,12 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
311 311
312/* ------------------------------------------------------------------------- */ 312/* ------------------------------------------------------------------------- */
313 313
314int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 314int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
315 int (*bind)(struct usb_gadget *))
316{ 315{
317 struct usb_udc *udc = NULL; 316 struct usb_udc *udc = NULL;
318 int ret; 317 int ret;
319 318
320 if (!driver || !bind || !driver->setup) 319 if (!driver || !driver->bind || !driver->setup)
321 return -EINVAL; 320 return -EINVAL;
322 321
323 mutex_lock(&udc_lock); 322 mutex_lock(&udc_lock);
@@ -339,7 +338,7 @@ found:
339 udc->dev.driver = &driver->driver; 338 udc->dev.driver = &driver->driver;
340 339
341 if (udc_is_newstyle(udc)) { 340 if (udc_is_newstyle(udc)) {
342 ret = bind(udc->gadget); 341 ret = driver->bind(udc->gadget, driver);
343 if (ret) 342 if (ret)
344 goto err1; 343 goto err1;
345 ret = usb_gadget_udc_start(udc->gadget, driver); 344 ret = usb_gadget_udc_start(udc->gadget, driver);
@@ -350,7 +349,7 @@ found:
350 usb_gadget_connect(udc->gadget); 349 usb_gadget_connect(udc->gadget);
351 } else { 350 } else {
352 351
353 ret = usb_gadget_start(udc->gadget, driver, bind); 352 ret = usb_gadget_start(udc->gadget, driver, driver->bind);
354 if (ret) 353 if (ret)
355 goto err1; 354 goto err1;
356 355
diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c
index 4d25b9009edf..1f49fce0f0b7 100644
--- a/drivers/usb/gadget/usbstring.c
+++ b/drivers/usb/gadget/usbstring.c
@@ -9,6 +9,7 @@
9 9
10#include <linux/errno.h> 10#include <linux/errno.h>
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h>
12#include <linux/list.h> 13#include <linux/list.h>
13#include <linux/string.h> 14#include <linux/string.h>
14#include <linux/device.h> 15#include <linux/device.h>
@@ -68,4 +69,4 @@ usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
68 buf [1] = USB_DT_STRING; 69 buf [1] = USB_DT_STRING;
69 return buf [0]; 70 return buf [0];
70} 71}
71 72EXPORT_SYMBOL_GPL(usb_gadget_get_string);
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index 120e134e805e..69cf5c2cd335 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -23,16 +23,12 @@
23 * the runtime footprint, and giving us at least some parts of what 23 * the runtime footprint, and giving us at least some parts of what
24 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 24 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
25 */ 25 */
26#include "composite.c"
27#include "usbstring.c"
28#include "config.c"
29#include "epautoconf.c"
30
31#include "uvc_queue.c" 26#include "uvc_queue.c"
32#include "uvc_video.c" 27#include "uvc_video.c"
33#include "uvc_v4l2.c" 28#include "uvc_v4l2.c"
34#include "f_uvc.c" 29#include "f_uvc.c"
35 30
31USB_GADGET_COMPOSITE_OPTIONS();
36/* -------------------------------------------------------------------------- 32/* --------------------------------------------------------------------------
37 * Device descriptor 33 * Device descriptor
38 */ 34 */
@@ -47,13 +43,12 @@ static char webcam_config_label[] = "Video";
47 43
48/* string IDs are assigned dynamically */ 44/* string IDs are assigned dynamically */
49 45
50#define STRING_MANUFACTURER_IDX 0 46#define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX
51#define STRING_PRODUCT_IDX 1
52#define STRING_DESCRIPTION_IDX 2
53 47
54static struct usb_string webcam_strings[] = { 48static struct usb_string webcam_strings[] = {
55 [STRING_MANUFACTURER_IDX].s = webcam_vendor_label, 49 [USB_GADGET_MANUFACTURER_IDX].s = webcam_vendor_label,
56 [STRING_PRODUCT_IDX].s = webcam_product_label, 50 [USB_GADGET_PRODUCT_IDX].s = webcam_product_label,
51 [USB_GADGET_SERIAL_IDX].s = "",
57 [STRING_DESCRIPTION_IDX].s = webcam_config_label, 52 [STRING_DESCRIPTION_IDX].s = webcam_config_label,
58 { } 53 { }
59}; 54};
@@ -358,26 +353,22 @@ webcam_bind(struct usb_composite_dev *cdev)
358 /* Allocate string descriptor numbers ... note that string contents 353 /* Allocate string descriptor numbers ... note that string contents
359 * can be overridden by the composite_dev glue. 354 * can be overridden by the composite_dev glue.
360 */ 355 */
361 if ((ret = usb_string_id(cdev)) < 0) 356 ret = usb_string_ids_tab(cdev, webcam_strings);
362 goto error; 357 if (ret < 0)
363 webcam_strings[STRING_MANUFACTURER_IDX].id = ret;
364 webcam_device_descriptor.iManufacturer = ret;
365
366 if ((ret = usb_string_id(cdev)) < 0)
367 goto error;
368 webcam_strings[STRING_PRODUCT_IDX].id = ret;
369 webcam_device_descriptor.iProduct = ret;
370
371 if ((ret = usb_string_id(cdev)) < 0)
372 goto error; 358 goto error;
373 webcam_strings[STRING_DESCRIPTION_IDX].id = ret; 359 webcam_device_descriptor.iManufacturer =
374 webcam_config_driver.iConfiguration = ret; 360 webcam_strings[USB_GADGET_MANUFACTURER_IDX].id;
361 webcam_device_descriptor.iProduct =
362 webcam_strings[USB_GADGET_PRODUCT_IDX].id;
363 webcam_config_driver.iConfiguration =
364 webcam_strings[STRING_DESCRIPTION_IDX].id;
375 365
376 /* Register our configuration. */ 366 /* Register our configuration. */
377 if ((ret = usb_add_config(cdev, &webcam_config_driver, 367 if ((ret = usb_add_config(cdev, &webcam_config_driver,
378 webcam_config_bind)) < 0) 368 webcam_config_bind)) < 0)
379 goto error; 369 goto error;
380 370
371 usb_composite_overwrite_options(cdev, &coverwrite);
381 INFO(cdev, "Webcam Video Gadget\n"); 372 INFO(cdev, "Webcam Video Gadget\n");
382 return 0; 373 return 0;
383 374
@@ -390,18 +381,19 @@ error:
390 * Driver 381 * Driver
391 */ 382 */
392 383
393static struct usb_composite_driver webcam_driver = { 384static __refdata struct usb_composite_driver webcam_driver = {
394 .name = "g_webcam", 385 .name = "g_webcam",
395 .dev = &webcam_device_descriptor, 386 .dev = &webcam_device_descriptor,
396 .strings = webcam_device_strings, 387 .strings = webcam_device_strings,
397 .max_speed = USB_SPEED_SUPER, 388 .max_speed = USB_SPEED_SUPER,
389 .bind = webcam_bind,
398 .unbind = webcam_unbind, 390 .unbind = webcam_unbind,
399}; 391};
400 392
401static int __init 393static int __init
402webcam_init(void) 394webcam_init(void)
403{ 395{
404 return usb_composite_probe(&webcam_driver, webcam_bind); 396 return usb_composite_probe(&webcam_driver);
405} 397}
406 398
407static void __exit 399static void __exit
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 12ad516ada77..6bf4c0611365 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -42,7 +42,6 @@
42 42
43#include <linux/kernel.h> 43#include <linux/kernel.h>
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/utsname.h>
46#include <linux/device.h> 45#include <linux/device.h>
47 46
48#include "g_zero.h" 47#include "g_zero.h"
@@ -58,15 +57,11 @@
58 * the runtime footprint, and giving us at least some parts of what 57 * the runtime footprint, and giving us at least some parts of what
59 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 58 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
60 */ 59 */
61#include "composite.c"
62#include "usbstring.c"
63#include "config.c"
64#include "epautoconf.c"
65
66#include "f_sourcesink.c" 60#include "f_sourcesink.c"
67#include "f_loopback.c" 61#include "f_loopback.c"
68 62
69/*-------------------------------------------------------------------------*/ 63/*-------------------------------------------------------------------------*/
64USB_GADGET_COMPOSITE_OPTIONS();
70 65
71#define DRIVER_VERSION "Cinco de Mayo 2008" 66#define DRIVER_VERSION "Cinco de Mayo 2008"
72 67
@@ -141,20 +136,13 @@ const struct usb_descriptor_header *otg_desc[] = {
141#endif 136#endif
142 137
143/* string IDs are assigned dynamically */ 138/* string IDs are assigned dynamically */
144
145#define STRING_MANUFACTURER_IDX 0
146#define STRING_PRODUCT_IDX 1
147#define STRING_SERIAL_IDX 2
148
149static char manufacturer[50];
150
151/* default serial number takes at least two packets */ 139/* default serial number takes at least two packets */
152static char serial[] = "0123456789.0123456789.0123456789"; 140static char serial[] = "0123456789.0123456789.0123456789";
153 141
154static struct usb_string strings_dev[] = { 142static struct usb_string strings_dev[] = {
155 [STRING_MANUFACTURER_IDX].s = manufacturer, 143 [USB_GADGET_MANUFACTURER_IDX].s = "",
156 [STRING_PRODUCT_IDX].s = longname, 144 [USB_GADGET_PRODUCT_IDX].s = longname,
157 [STRING_SERIAL_IDX].s = serial, 145 [USB_GADGET_SERIAL_IDX].s = serial,
158 { } /* end of list */ 146 { } /* end of list */
159}; 147};
160 148
@@ -265,30 +253,18 @@ static void zero_resume(struct usb_composite_dev *cdev)
265 253
266static int __init zero_bind(struct usb_composite_dev *cdev) 254static int __init zero_bind(struct usb_composite_dev *cdev)
267{ 255{
268 int gcnum; 256 int status;
269 struct usb_gadget *gadget = cdev->gadget;
270 int id;
271 257
272 /* Allocate string descriptor numbers ... note that string 258 /* Allocate string descriptor numbers ... note that string
273 * contents can be overridden by the composite_dev glue. 259 * contents can be overridden by the composite_dev glue.
274 */ 260 */
275 id = usb_string_id(cdev); 261 status = usb_string_ids_tab(cdev, strings_dev);
276 if (id < 0) 262 if (status < 0)
277 return id; 263 return status;
278 strings_dev[STRING_MANUFACTURER_IDX].id = id; 264
279 device_desc.iManufacturer = id; 265 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
280 266 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
281 id = usb_string_id(cdev); 267 device_desc.iSerialNumber = strings_dev[USB_GADGET_SERIAL_IDX].id;
282 if (id < 0)
283 return id;
284 strings_dev[STRING_PRODUCT_IDX].id = id;
285 device_desc.iProduct = id;
286
287 id = usb_string_id(cdev);
288 if (id < 0)
289 return id;
290 strings_dev[STRING_SERIAL_IDX].id = id;
291 device_desc.iSerialNumber = id;
292 268
293 setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev); 269 setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
294 270
@@ -303,28 +279,10 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
303 loopback_add(cdev, autoresume != 0); 279 loopback_add(cdev, autoresume != 0);
304 } 280 }
305 281
306 gcnum = usb_gadget_controller_number(gadget); 282 usb_composite_overwrite_options(cdev, &coverwrite);
307 if (gcnum >= 0)
308 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
309 else {
310 /* gadget zero is so simple (for now, no altsettings) that
311 * it SHOULD NOT have problems with bulk-capable hardware.
312 * so just warn about unrcognized controllers -- don't panic.
313 *
314 * things like configuration and altsetting numbering
315 * can need hardware-specific attention though.
316 */
317 pr_warning("%s: controller '%s' not recognized\n",
318 longname, gadget->name);
319 device_desc.bcdDevice = cpu_to_le16(0x9999);
320 }
321 283
322 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); 284 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
323 285
324 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
325 init_utsname()->sysname, init_utsname()->release,
326 gadget->name);
327
328 return 0; 286 return 0;
329} 287}
330 288
@@ -334,11 +292,12 @@ static int zero_unbind(struct usb_composite_dev *cdev)
334 return 0; 292 return 0;
335} 293}
336 294
337static struct usb_composite_driver zero_driver = { 295static __refdata struct usb_composite_driver zero_driver = {
338 .name = "zero", 296 .name = "zero",
339 .dev = &device_desc, 297 .dev = &device_desc,
340 .strings = dev_strings, 298 .strings = dev_strings,
341 .max_speed = USB_SPEED_SUPER, 299 .max_speed = USB_SPEED_SUPER,
300 .bind = zero_bind,
342 .unbind = zero_unbind, 301 .unbind = zero_unbind,
343 .suspend = zero_suspend, 302 .suspend = zero_suspend,
344 .resume = zero_resume, 303 .resume = zero_resume,
@@ -349,7 +308,7 @@ MODULE_LICENSE("GPL");
349 308
350static int __init init(void) 309static int __init init(void)
351{ 310{
352 return usb_composite_probe(&zero_driver, zero_bind); 311 return usb_composite_probe(&zero_driver);
353} 312}
354module_init(init); 313module_init(init);
355 314
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 6259f0d99324..09f685686500 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -12,7 +12,6 @@ config USB_MUSB_HDRC
12 select TWL4030_USB if MACH_OMAP_3430SDP 12 select TWL4030_USB if MACH_OMAP_3430SDP
13 select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA 13 select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
14 select USB_OTG_UTILS 14 select USB_OTG_UTILS
15 select USB_GADGET_DUALSPEED
16 help 15 help
17 Say Y here if your system has a dual role high speed USB 16 Say Y here if your system has a dual role high speed USB
18 controller based on the Mentor Graphics silicon IP. Then 17 controller based on the Mentor Graphics silicon IP. Then