aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-10-22 23:30:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-22 23:30:48 -0400
commit5cc103506289de7ee0a0b526ae0381541990cad4 (patch)
treeae8a4958e70c6d1295030b40e333dcc007b3c074 /drivers/usb/gadget
parent73ecf3a6e3f0206bf56a0fefe3b3eda042fb7034 (diff)
parent92ca0dc5ee022e4c0e488177e1d8865a0778c6c2 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (141 commits) USB: mct_u232: fix broken close USB: gadget: amd5536udc.c: fix error path USB: imx21-hcd - fix off by one resource size calculation usb: gadget: fix Kconfig warning usb: r8a66597-udc: Add processing when USB was removed. mxc_udc: add workaround for ENGcm09152 for i.MX35 USB: ftdi_sio: add device ids for ScienceScope USB: musb: AM35x: Workaround for fifo read issue USB: musb: add musb support for AM35x USB: AM35x: Add musb support usb: Fix linker errors with CONFIG_PM=n USB: ohci-sh - use resource_size instead of defining its own resource_len macro USB: isp1362-hcd - use resource_size instead of defining its own resource_len macro USB: isp116x-hcd - use resource_size instead of defining its own resource_len macro USB: xhci: Fix compile error when CONFIG_PM=n USB: accept some invalid ep0-maxpacket values USB: xHCI: PCI power management implementation USB: xHCI: bus power management implementation USB: xHCI: port remote wakeup implementation USB: xHCI: port power management implementation ... Manually fix up (non-data) conflict: the SCSI merge gad renamed the 'hw_sector_size' member to 'physical_block_size', and the USB tree brought a new use of it.
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/Kconfig22
-rw-r--r--drivers/usb/gadget/Makefile41
-rw-r--r--drivers/usb/gadget/amd5536udc.c15
-rw-r--r--drivers/usb/gadget/at91_udc.c11
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c10
-rw-r--r--drivers/usb/gadget/audio.c10
-rw-r--r--drivers/usb/gadget/cdc2.c10
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c18
-rw-r--r--drivers/usb/gadget/composite.c139
-rw-r--r--drivers/usb/gadget/dbgp.c19
-rw-r--r--drivers/usb/gadget/dummy_hcd.c18
-rw-r--r--drivers/usb/gadget/ether.c16
-rw-r--r--drivers/usb/gadget/f_acm.c2
-rw-r--r--drivers/usb/gadget/f_loopback.c7
-rw-r--r--drivers/usb/gadget/f_mass_storage.c88
-rw-r--r--drivers/usb/gadget/f_sourcesink.c5
-rw-r--r--drivers/usb/gadget/file_storage.c128
-rw-r--r--drivers/usb/gadget/fsl_mxc_udc.c15
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c12
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c10
-rw-r--r--drivers/usb/gadget/g_ffs.c91
-rw-r--r--drivers/usb/gadget/gmidi.c5
-rw-r--r--drivers/usb/gadget/goku_udc.c35
-rw-r--r--drivers/usb/gadget/hid.c10
-rw-r--r--drivers/usb/gadget/imx_udc.c9
-rw-r--r--drivers/usb/gadget/inode.c6
-rw-r--r--drivers/usb/gadget/langwell_udc.c1058
-rw-r--r--drivers/usb/gadget/langwell_udc.h15
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c10
-rw-r--r--drivers/usb/gadget/m66592-udc.c9
-rw-r--r--drivers/usb/gadget/mass_storage.c82
-rw-r--r--drivers/usb/gadget/multi.c36
-rw-r--r--drivers/usb/gadget/net2280.c10
-rw-r--r--drivers/usb/gadget/nokia.c11
-rw-r--r--drivers/usb/gadget/omap_udc.c10
-rw-r--r--drivers/usb/gadget/printer.c7
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c9
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c12
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c14
-rw-r--r--drivers/usb/gadget/r8a66597-udc.h2
-rw-r--r--drivers/usb/gadget/rndis.c492
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c9
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c17
-rw-r--r--drivers/usb/gadget/serial.c11
-rw-r--r--drivers/usb/gadget/storage_common.c49
-rw-r--r--drivers/usb/gadget/webcam.c11
-rw-r--r--drivers/usb/gadget/zero.c5
47 files changed, 1366 insertions, 1265 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index cd27f9bde2c8..b739ca814651 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -158,6 +158,7 @@ config USB_GADGET_FSL_USB2
158 boolean "Freescale Highspeed USB DR Peripheral Controller" 158 boolean "Freescale Highspeed USB DR Peripheral Controller"
159 depends on FSL_SOC || ARCH_MXC 159 depends on FSL_SOC || ARCH_MXC
160 select USB_GADGET_DUALSPEED 160 select USB_GADGET_DUALSPEED
161 select USB_FSL_MPH_DR_OF
161 help 162 help
162 Some of Freescale PowerPC processors have a High Speed 163 Some of Freescale PowerPC processors have a High Speed
163 Dual-Role(DR) USB controller, which supports device mode. 164 Dual-Role(DR) USB controller, which supports device mode.
@@ -209,17 +210,6 @@ config USB_OMAP
209 default USB_GADGET 210 default USB_GADGET
210 select USB_GADGET_SELECTED 211 select USB_GADGET_SELECTED
211 212
212config USB_OTG
213 boolean "OTG Support"
214 depends on USB_GADGET_OMAP && ARCH_OMAP_OTG && USB_OHCI_HCD
215 help
216 The most notable feature of USB OTG is support for a
217 "Dual-Role" device, which can act as either a device
218 or a host. The initial role choice can be changed
219 later, when two dual-role devices talk to each other.
220
221 Select this only if your OMAP board has a Mini-AB connector.
222
223config USB_GADGET_PXA25X 213config USB_GADGET_PXA25X
224 boolean "PXA 25x or IXP 4xx" 214 boolean "PXA 25x or IXP 4xx"
225 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX 215 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
@@ -716,8 +706,8 @@ config USB_FUNCTIONFS
716 depends on EXPERIMENTAL 706 depends on EXPERIMENTAL
717 select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) 707 select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS)
718 help 708 help
719 The Function Filesystem (FunctioFS) lets one create USB 709 The Function Filesystem (FunctionFS) lets one create USB
720 composite functions in user space in the same way as GadgetFS 710 composite functions in user space in the same way GadgetFS
721 lets one create USB gadgets in user space. This allows creation 711 lets one create USB gadgets in user space. This allows creation
722 of composite gadgets such that some of the functions are 712 of composite gadgets such that some of the functions are
723 implemented in kernel space (for instance Ethernet, serial or 713 implemented in kernel space (for instance Ethernet, serial or
@@ -733,14 +723,14 @@ config USB_FUNCTIONFS_ETH
733 bool "Include configuration with CDC ECM (Ethernet)" 723 bool "Include configuration with CDC ECM (Ethernet)"
734 depends on USB_FUNCTIONFS && NET 724 depends on USB_FUNCTIONFS && NET
735 help 725 help
736 Include a configuration with CDC ECM funcion (Ethernet) and the 726 Include a configuration with CDC ECM function (Ethernet) and the
737 Funcion Filesystem. 727 Function Filesystem.
738 728
739config USB_FUNCTIONFS_RNDIS 729config USB_FUNCTIONFS_RNDIS
740 bool "Include configuration with RNDIS (Ethernet)" 730 bool "Include configuration with RNDIS (Ethernet)"
741 depends on USB_FUNCTIONFS && NET 731 depends on USB_FUNCTIONFS && NET
742 help 732 help
743 Include a configuration with RNDIS funcion (Ethernet) and the Filesystem. 733 Include a configuration with RNDIS function (Ethernet) and the Filesystem.
744 734
745config USB_FUNCTIONFS_GENERIC 735config USB_FUNCTIONFS_GENERIC
746 bool "Include 'pure' configuration" 736 bool "Include 'pure' configuration"
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 27283df37d09..5780db42417b 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -1,9 +1,7 @@
1# 1#
2# USB peripheral controller drivers 2# USB peripheral controller drivers
3# 3#
4ifeq ($(CONFIG_USB_GADGET_DEBUG),y) 4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5 EXTRA_CFLAGS += -DDEBUG
6endif
7 5
8obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 6obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
9obj-$(CONFIG_USB_NET2280) += net2280.o 7obj-$(CONFIG_USB_NET2280) += net2280.o
@@ -18,10 +16,8 @@ obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o
18obj-$(CONFIG_USB_AT91) += at91_udc.o 16obj-$(CONFIG_USB_AT91) += at91_udc.o
19obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o 17obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
20obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o 18obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
21fsl_usb2_udc-objs := fsl_udc_core.o 19fsl_usb2_udc-y := fsl_udc_core.o
22ifeq ($(CONFIG_ARCH_MXC),y) 20fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o
23fsl_usb2_udc-objs += fsl_mxc_udc.o
24endif
25obj-$(CONFIG_USB_M66592) += m66592-udc.o 21obj-$(CONFIG_USB_M66592) += m66592-udc.o
26obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o 22obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o
27obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o 23obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o
@@ -32,21 +28,21 @@ obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o
32# 28#
33# USB gadget drivers 29# USB gadget drivers
34# 30#
35g_zero-objs := zero.o 31g_zero-y := zero.o
36g_audio-objs := audio.o 32g_audio-y := audio.o
37g_ether-objs := ether.o 33g_ether-y := ether.o
38g_serial-objs := serial.o 34g_serial-y := serial.o
39g_midi-objs := gmidi.o 35g_midi-y := gmidi.o
40gadgetfs-objs := inode.o 36gadgetfs-y := inode.o
41g_file_storage-objs := file_storage.o 37g_file_storage-y := file_storage.o
42g_mass_storage-objs := mass_storage.o 38g_mass_storage-y := mass_storage.o
43g_printer-objs := printer.o 39g_printer-y := printer.o
44g_cdc-objs := cdc2.o 40g_cdc-y := cdc2.o
45g_multi-objs := multi.o 41g_multi-y := multi.o
46g_hid-objs := hid.o 42g_hid-y := hid.o
47g_dbgp-objs := dbgp.o 43g_dbgp-y := dbgp.o
48g_nokia-objs := nokia.o 44g_nokia-y := nokia.o
49g_webcam-objs := webcam.o 45g_webcam-y := webcam.o
50 46
51obj-$(CONFIG_USB_ZERO) += g_zero.o 47obj-$(CONFIG_USB_ZERO) += g_zero.o
52obj-$(CONFIG_USB_AUDIO) += g_audio.o 48obj-$(CONFIG_USB_AUDIO) += g_audio.o
@@ -64,4 +60,3 @@ obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o
64obj-$(CONFIG_USB_G_MULTI) += g_multi.o 60obj-$(CONFIG_USB_G_MULTI) += g_multi.o
65obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o 61obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o
66obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o 62obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o
67
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 731150d4b1d9..9034e0344723 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -203,7 +203,7 @@ static void print_regs(struct udc *dev)
203 DBG(dev, "DMA mode = PPBNDU (packet per buffer " 203 DBG(dev, "DMA mode = PPBNDU (packet per buffer "
204 "WITHOUT desc. update)\n"); 204 "WITHOUT desc. update)\n");
205 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBNDU"); 205 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBNDU");
206 } else if (use_dma && use_dma_ppb_du && use_dma_ppb_du) { 206 } else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
207 DBG(dev, "DMA mode = PPBDU (packet per buffer " 207 DBG(dev, "DMA mode = PPBDU (packet per buffer "
208 "WITH desc. update)\n"); 208 "WITH desc. update)\n");
209 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBDU"); 209 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBDU");
@@ -1954,13 +1954,14 @@ static int setup_ep0(struct udc *dev)
1954} 1954}
1955 1955
1956/* Called by gadget driver to register itself */ 1956/* Called by gadget driver to register itself */
1957int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1957int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1958 int (*bind)(struct usb_gadget *))
1958{ 1959{
1959 struct udc *dev = udc; 1960 struct udc *dev = udc;
1960 int retval; 1961 int retval;
1961 u32 tmp; 1962 u32 tmp;
1962 1963
1963 if (!driver || !driver->bind || !driver->setup 1964 if (!driver || !bind || !driver->setup
1964 || driver->speed != USB_SPEED_HIGH) 1965 || driver->speed != USB_SPEED_HIGH)
1965 return -EINVAL; 1966 return -EINVAL;
1966 if (!dev) 1967 if (!dev)
@@ -1972,7 +1973,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1972 dev->driver = driver; 1973 dev->driver = driver;
1973 dev->gadget.dev.driver = &driver->driver; 1974 dev->gadget.dev.driver = &driver->driver;
1974 1975
1975 retval = driver->bind(&dev->gadget); 1976 retval = bind(&dev->gadget);
1976 1977
1977 /* Some gadget drivers use both ep0 directions. 1978 /* Some gadget drivers use both ep0 directions.
1978 * NOTE: to gadget driver, ep0 is just one endpoint... 1979 * NOTE: to gadget driver, ep0 is just one endpoint...
@@ -2000,7 +2001,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2000 2001
2001 return 0; 2002 return 0;
2002} 2003}
2003EXPORT_SYMBOL(usb_gadget_register_driver); 2004EXPORT_SYMBOL(usb_gadget_probe_driver);
2004 2005
2005/* shutdown requests and disconnect from gadget */ 2006/* shutdown requests and disconnect from gadget */
2006static void 2007static void
@@ -3382,8 +3383,10 @@ static int udc_probe(struct udc *dev)
3382 udc = dev; 3383 udc = dev;
3383 3384
3384 retval = device_register(&dev->gadget.dev); 3385 retval = device_register(&dev->gadget.dev);
3385 if (retval) 3386 if (retval) {
3387 put_device(&dev->gadget.dev);
3386 goto finished; 3388 goto finished;
3389 }
3387 3390
3388 /* timer init */ 3391 /* timer init */
3389 init_timer(&udc_timer); 3392 init_timer(&udc_timer);
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 93ead19507b6..387e503b9d14 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1628,7 +1628,8 @@ static void at91_vbus_timer(unsigned long data)
1628 schedule_work(&udc->vbus_timer_work); 1628 schedule_work(&udc->vbus_timer_work);
1629} 1629}
1630 1630
1631int usb_gadget_register_driver (struct usb_gadget_driver *driver) 1631int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1632 int (*bind)(struct usb_gadget *))
1632{ 1633{
1633 struct at91_udc *udc = &controller; 1634 struct at91_udc *udc = &controller;
1634 int retval; 1635 int retval;
@@ -1636,7 +1637,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1636 1637
1637 if (!driver 1638 if (!driver
1638 || driver->speed < USB_SPEED_FULL 1639 || driver->speed < USB_SPEED_FULL
1639 || !driver->bind 1640 || !bind
1640 || !driver->setup) { 1641 || !driver->setup) {
1641 DBG("bad parameter.\n"); 1642 DBG("bad parameter.\n");
1642 return -EINVAL; 1643 return -EINVAL;
@@ -1653,9 +1654,9 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1653 udc->enabled = 1; 1654 udc->enabled = 1;
1654 udc->selfpowered = 1; 1655 udc->selfpowered = 1;
1655 1656
1656 retval = driver->bind(&udc->gadget); 1657 retval = bind(&udc->gadget);
1657 if (retval) { 1658 if (retval) {
1658 DBG("driver->bind() returned %d\n", retval); 1659 DBG("bind() returned %d\n", retval);
1659 udc->driver = NULL; 1660 udc->driver = NULL;
1660 udc->gadget.dev.driver = NULL; 1661 udc->gadget.dev.driver = NULL;
1661 dev_set_drvdata(&udc->gadget.dev, NULL); 1662 dev_set_drvdata(&udc->gadget.dev, NULL);
@@ -1671,7 +1672,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1671 DBG("bound to %s\n", driver->driver.name); 1672 DBG("bound to %s\n", driver->driver.name);
1672 return 0; 1673 return 0;
1673} 1674}
1674EXPORT_SYMBOL (usb_gadget_register_driver); 1675EXPORT_SYMBOL(usb_gadget_probe_driver);
1675 1676
1676int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 1677int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1677{ 1678{
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index d623c7bda1f6..b5e20e873cba 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1789,7 +1789,8 @@ out:
1789 return IRQ_HANDLED; 1789 return IRQ_HANDLED;
1790} 1790}
1791 1791
1792int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1792int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1793 int (*bind)(struct usb_gadget *))
1793{ 1794{
1794 struct usba_udc *udc = &the_udc; 1795 struct usba_udc *udc = &the_udc;
1795 unsigned long flags; 1796 unsigned long flags;
@@ -1812,7 +1813,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1812 clk_enable(udc->pclk); 1813 clk_enable(udc->pclk);
1813 clk_enable(udc->hclk); 1814 clk_enable(udc->hclk);
1814 1815
1815 ret = driver->bind(&udc->gadget); 1816 ret = bind(&udc->gadget);
1816 if (ret) { 1817 if (ret) {
1817 DBG(DBG_ERR, "Could not bind to driver %s: error %d\n", 1818 DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
1818 driver->driver.name, ret); 1819 driver->driver.name, ret);
@@ -1841,7 +1842,7 @@ err_driver_bind:
1841 udc->gadget.dev.driver = NULL; 1842 udc->gadget.dev.driver = NULL;
1842 return ret; 1843 return ret;
1843} 1844}
1844EXPORT_SYMBOL(usb_gadget_register_driver); 1845EXPORT_SYMBOL(usb_gadget_probe_driver);
1845 1846
1846int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1847int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1847{ 1848{
@@ -2014,6 +2015,9 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2014 } else { 2015 } else {
2015 disable_irq(gpio_to_irq(udc->vbus_pin)); 2016 disable_irq(gpio_to_irq(udc->vbus_pin));
2016 } 2017 }
2018 } else {
2019 /* gpio_request fail so use -EINVAL for gpio_is_valid */
2020 ubc->vbus_pin = -EINVAL;
2017 } 2021 }
2018 } 2022 }
2019 2023
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index b744ccd0f34d..93b999e49ef3 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -89,7 +89,7 @@ static const struct usb_descriptor_header *otg_desc[] = {
89 89
90/*-------------------------------------------------------------------------*/ 90/*-------------------------------------------------------------------------*/
91 91
92static int __ref audio_do_config(struct usb_configuration *c) 92static int __init audio_do_config(struct usb_configuration *c)
93{ 93{
94 /* FIXME alloc iConfiguration string, set it in c->strings */ 94 /* FIXME alloc iConfiguration string, set it in c->strings */
95 95
@@ -105,7 +105,6 @@ static int __ref audio_do_config(struct usb_configuration *c)
105 105
106static struct usb_configuration audio_config_driver = { 106static struct usb_configuration audio_config_driver = {
107 .label = DRIVER_DESC, 107 .label = DRIVER_DESC,
108 .bind = audio_do_config,
109 .bConfigurationValue = 1, 108 .bConfigurationValue = 1,
110 /* .iConfiguration = DYNAMIC */ 109 /* .iConfiguration = DYNAMIC */
111 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 110 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -113,7 +112,7 @@ static struct usb_configuration audio_config_driver = {
113 112
114/*-------------------------------------------------------------------------*/ 113/*-------------------------------------------------------------------------*/
115 114
116static int __ref audio_bind(struct usb_composite_dev *cdev) 115static int __init audio_bind(struct usb_composite_dev *cdev)
117{ 116{
118 int gcnum; 117 int gcnum;
119 int status; 118 int status;
@@ -145,7 +144,7 @@ static int __ref audio_bind(struct usb_composite_dev *cdev)
145 strings_dev[STRING_PRODUCT_IDX].id = status; 144 strings_dev[STRING_PRODUCT_IDX].id = status;
146 device_desc.iProduct = status; 145 device_desc.iProduct = status;
147 146
148 status = usb_add_config(cdev, &audio_config_driver); 147 status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
149 if (status < 0) 148 if (status < 0)
150 goto fail; 149 goto fail;
151 150
@@ -166,13 +165,12 @@ static struct usb_composite_driver audio_driver = {
166 .name = "g_audio", 165 .name = "g_audio",
167 .dev = &device_desc, 166 .dev = &device_desc,
168 .strings = audio_strings, 167 .strings = audio_strings,
169 .bind = audio_bind,
170 .unbind = __exit_p(audio_unbind), 168 .unbind = __exit_p(audio_unbind),
171}; 169};
172 170
173static int __init init(void) 171static int __init init(void)
174{ 172{
175 return usb_composite_register(&audio_driver); 173 return usb_composite_probe(&audio_driver, audio_bind);
176} 174}
177module_init(init); 175module_init(init);
178 176
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 1f5ba2fd4c1f..2720ab07ef1a 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -129,7 +129,7 @@ static u8 hostaddr[ETH_ALEN];
129/* 129/*
130 * We _always_ have both CDC ECM and CDC ACM functions. 130 * We _always_ have both CDC ECM and CDC ACM functions.
131 */ 131 */
132static int __ref cdc_do_config(struct usb_configuration *c) 132static int __init cdc_do_config(struct usb_configuration *c)
133{ 133{
134 int status; 134 int status;
135 135
@@ -151,7 +151,6 @@ static int __ref cdc_do_config(struct usb_configuration *c)
151 151
152static struct usb_configuration cdc_config_driver = { 152static struct usb_configuration cdc_config_driver = {
153 .label = "CDC Composite (ECM + ACM)", 153 .label = "CDC Composite (ECM + ACM)",
154 .bind = cdc_do_config,
155 .bConfigurationValue = 1, 154 .bConfigurationValue = 1,
156 /* .iConfiguration = DYNAMIC */ 155 /* .iConfiguration = DYNAMIC */
157 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 156 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -159,7 +158,7 @@ static struct usb_configuration cdc_config_driver = {
159 158
160/*-------------------------------------------------------------------------*/ 159/*-------------------------------------------------------------------------*/
161 160
162static int __ref cdc_bind(struct usb_composite_dev *cdev) 161static int __init cdc_bind(struct usb_composite_dev *cdev)
163{ 162{
164 int gcnum; 163 int gcnum;
165 struct usb_gadget *gadget = cdev->gadget; 164 struct usb_gadget *gadget = cdev->gadget;
@@ -218,7 +217,7 @@ static int __ref cdc_bind(struct usb_composite_dev *cdev)
218 device_desc.iProduct = status; 217 device_desc.iProduct = status;
219 218
220 /* register our configuration */ 219 /* register our configuration */
221 status = usb_add_config(cdev, &cdc_config_driver); 220 status = usb_add_config(cdev, &cdc_config_driver, cdc_do_config);
222 if (status < 0) 221 if (status < 0)
223 goto fail1; 222 goto fail1;
224 223
@@ -245,7 +244,6 @@ static struct usb_composite_driver cdc_driver = {
245 .name = "g_cdc", 244 .name = "g_cdc",
246 .dev = &device_desc, 245 .dev = &device_desc,
247 .strings = dev_strings, 246 .strings = dev_strings,
248 .bind = cdc_bind,
249 .unbind = __exit_p(cdc_unbind), 247 .unbind = __exit_p(cdc_unbind),
250}; 248};
251 249
@@ -255,7 +253,7 @@ MODULE_LICENSE("GPL");
255 253
256static int __init init(void) 254static int __init init(void)
257{ 255{
258 return usb_composite_register(&cdc_driver); 256 return usb_composite_probe(&cdc_driver, cdc_bind);
259} 257}
260module_init(init); 258module_init(init);
261 259
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index 699695128e33..98b36fc88c77 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -2340,12 +2340,15 @@ static const struct usb_ep_ops usb_ep_ops = {
2340static const struct usb_gadget_ops usb_gadget_ops; 2340static const struct usb_gadget_ops usb_gadget_ops;
2341 2341
2342/** 2342/**
2343 * usb_gadget_register_driver: register a gadget driver 2343 * usb_gadget_probe_driver: register a gadget driver
2344 * @driver: the driver being registered
2345 * @bind: the driver's bind callback
2344 * 2346 *
2345 * Check usb_gadget_register_driver() at "usb_gadget.h" for details 2347 * Check usb_gadget_probe_driver() at <linux/usb/gadget.h> for details.
2346 * Interrupts are enabled here 2348 * Interrupts are enabled here.
2347 */ 2349 */
2348int usb_gadget_register_driver(struct usb_gadget_driver *driver) 2350int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2351 int (*bind)(struct usb_gadget *))
2349{ 2352{
2350 struct ci13xxx *udc = _udc; 2353 struct ci13xxx *udc = _udc;
2351 unsigned long i, k, flags; 2354 unsigned long i, k, flags;
@@ -2354,7 +2357,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2354 trace("%p", driver); 2357 trace("%p", driver);
2355 2358
2356 if (driver == NULL || 2359 if (driver == NULL ||
2357 driver->bind == NULL || 2360 bind == NULL ||
2358 driver->unbind == NULL || 2361 driver->unbind == NULL ||
2359 driver->setup == NULL || 2362 driver->setup == NULL ||
2360 driver->disconnect == NULL || 2363 driver->disconnect == NULL ||
@@ -2430,7 +2433,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2430 udc->gadget.dev.driver = &driver->driver; 2433 udc->gadget.dev.driver = &driver->driver;
2431 2434
2432 spin_unlock_irqrestore(udc->lock, flags); 2435 spin_unlock_irqrestore(udc->lock, flags);
2433 retval = driver->bind(&udc->gadget); /* MAY SLEEP */ 2436 retval = bind(&udc->gadget); /* MAY SLEEP */
2434 spin_lock_irqsave(udc->lock, flags); 2437 spin_lock_irqsave(udc->lock, flags);
2435 2438
2436 if (retval) { 2439 if (retval) {
@@ -2447,7 +2450,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2447 usb_gadget_unregister_driver(driver); 2450 usb_gadget_unregister_driver(driver);
2448 return retval; 2451 return retval;
2449} 2452}
2450EXPORT_SYMBOL(usb_gadget_register_driver); 2453EXPORT_SYMBOL(usb_gadget_probe_driver);
2451 2454
2452/** 2455/**
2453 * usb_gadget_unregister_driver: unregister a gadget driver 2456 * usb_gadget_unregister_driver: unregister a gadget driver
@@ -2462,7 +2465,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2462 trace("%p", driver); 2465 trace("%p", driver);
2463 2466
2464 if (driver == NULL || 2467 if (driver == NULL ||
2465 driver->bind == NULL ||
2466 driver->unbind == NULL || 2468 driver->unbind == NULL ||
2467 driver->setup == NULL || 2469 driver->setup == NULL ||
2468 driver->disconnect == NULL || 2470 driver->disconnect == NULL ||
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 1160c55de7f2..7b5cc16e4a0b 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -24,6 +24,7 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/utsname.h>
27 28
28#include <linux/usb/composite.h> 29#include <linux/usb/composite.h>
29 30
@@ -39,6 +40,7 @@
39#define USB_BUFSIZ 1024 40#define USB_BUFSIZ 1024
40 41
41static struct usb_composite_driver *composite; 42static struct usb_composite_driver *composite;
43static int (*composite_gadget_bind)(struct usb_composite_dev *cdev);
42 44
43/* Some systems will need runtime overrides for the product identifers 45/* Some systems will need runtime overrides for the product identifers
44 * published in the device descriptor, either numbers or strings or both. 46 * published in the device descriptor, either numbers or strings or both.
@@ -69,6 +71,8 @@ static char *iSerialNumber;
69module_param(iSerialNumber, charp, 0); 71module_param(iSerialNumber, charp, 0);
70MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); 72MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
71 73
74static char composite_manufacturer[50];
75
72/*-------------------------------------------------------------------------*/ 76/*-------------------------------------------------------------------------*/
73 77
74/** 78/**
@@ -470,18 +474,20 @@ done:
470 * usb_add_config() - add a configuration to a device. 474 * usb_add_config() - add a configuration to a device.
471 * @cdev: wraps the USB gadget 475 * @cdev: wraps the USB gadget
472 * @config: the configuration, with bConfigurationValue assigned 476 * @config: the configuration, with bConfigurationValue assigned
477 * @bind: the configuration's bind function
473 * Context: single threaded during gadget setup 478 * Context: single threaded during gadget setup
474 * 479 *
475 * One of the main tasks of a composite driver's bind() routine is to 480 * One of the main tasks of a composite @bind() routine is to
476 * add each of the configurations it supports, using this routine. 481 * add each of the configurations it supports, using this routine.
477 * 482 *
478 * This function returns the value of the configuration's bind(), which 483 * This function returns the value of the configuration's @bind(), which
479 * is zero for success else a negative errno value. Binding configurations 484 * is zero for success else a negative errno value. Binding configurations
480 * assigns global resources including string IDs, and per-configuration 485 * assigns global resources including string IDs, and per-configuration
481 * resources such as interface IDs and endpoints. 486 * resources such as interface IDs and endpoints.
482 */ 487 */
483int usb_add_config(struct usb_composite_dev *cdev, 488int usb_add_config(struct usb_composite_dev *cdev,
484 struct usb_configuration *config) 489 struct usb_configuration *config,
490 int (*bind)(struct usb_configuration *))
485{ 491{
486 int status = -EINVAL; 492 int status = -EINVAL;
487 struct usb_configuration *c; 493 struct usb_configuration *c;
@@ -490,7 +496,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
490 config->bConfigurationValue, 496 config->bConfigurationValue,
491 config->label, config); 497 config->label, config);
492 498
493 if (!config->bConfigurationValue || !config->bind) 499 if (!config->bConfigurationValue || !bind)
494 goto done; 500 goto done;
495 501
496 /* Prevent duplicate configuration identifiers */ 502 /* Prevent duplicate configuration identifiers */
@@ -507,7 +513,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
507 INIT_LIST_HEAD(&config->functions); 513 INIT_LIST_HEAD(&config->functions);
508 config->next_interface_id = 0; 514 config->next_interface_id = 0;
509 515
510 status = config->bind(config); 516 status = bind(config);
511 if (status < 0) { 517 if (status < 0) {
512 list_del(&config->list); 518 list_del(&config->list);
513 config->cdev = NULL; 519 config->cdev = NULL;
@@ -533,7 +539,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
533 } 539 }
534 } 540 }
535 541
536 /* set_alt(), or next config->bind(), sets up 542 /* set_alt(), or next bind(), sets up
537 * ep->driver_data as needed. 543 * ep->driver_data as needed.
538 */ 544 */
539 usb_ep_autoconfig_reset(cdev->gadget); 545 usb_ep_autoconfig_reset(cdev->gadget);
@@ -599,6 +605,7 @@ static int get_string(struct usb_composite_dev *cdev,
599 struct usb_configuration *c; 605 struct usb_configuration *c;
600 struct usb_function *f; 606 struct usb_function *f;
601 int len; 607 int len;
608 const char *str;
602 609
603 /* Yes, not only is USB's I18N support probably more than most 610 /* Yes, not only is USB's I18N support probably more than most
604 * folk will ever care about ... also, it's all supported here. 611 * folk will ever care about ... also, it's all supported here.
@@ -638,9 +645,29 @@ static int get_string(struct usb_composite_dev *cdev,
638 return s->bLength; 645 return s->bLength;
639 } 646 }
640 647
641 /* Otherwise, look up and return a specified string. String IDs 648 /* Otherwise, look up and return a specified string. First
642 * are device-scoped, so we look up each string table we're told 649 * check if the string has not been overridden.
643 * about. These lookups are infrequent; simpler-is-better here. 650 */
651 if (cdev->manufacturer_override == id)
652 str = iManufacturer ?: composite->iManufacturer ?:
653 composite_manufacturer;
654 else if (cdev->product_override == id)
655 str = iProduct ?: composite->iProduct;
656 else if (cdev->serial_override == id)
657 str = iSerialNumber;
658 else
659 str = NULL;
660 if (str) {
661 struct usb_gadget_strings strings = {
662 .language = language,
663 .strings = &(struct usb_string) { 0xff, str }
664 };
665 return usb_gadget_get_string(&strings, 0xff, buf);
666 }
667
668 /* String IDs are device-scoped, so we look up each string
669 * table we're told about. These lookups are infrequent;
670 * simpler-is-better here.
644 */ 671 */
645 if (composite->strings) { 672 if (composite->strings) {
646 len = lookup_string(composite->strings, buf, language, id); 673 len = lookup_string(composite->strings, buf, language, id);
@@ -901,7 +928,8 @@ unknown:
901 */ 928 */
902 switch (ctrl->bRequestType & USB_RECIP_MASK) { 929 switch (ctrl->bRequestType & USB_RECIP_MASK) {
903 case USB_RECIP_INTERFACE: 930 case USB_RECIP_INTERFACE:
904 f = cdev->config->interface[intf]; 931 if (cdev->config)
932 f = cdev->config->interface[intf];
905 break; 933 break;
906 934
907 case USB_RECIP_ENDPOINT: 935 case USB_RECIP_ENDPOINT:
@@ -1025,26 +1053,17 @@ composite_unbind(struct usb_gadget *gadget)
1025 composite = NULL; 1053 composite = NULL;
1026} 1054}
1027 1055
1028static void 1056static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
1029string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
1030{ 1057{
1031 struct usb_string *str = tab->strings; 1058 if (!*desc) {
1032 1059 int ret = usb_string_id(cdev);
1033 for (str = tab->strings; str->s; str++) { 1060 if (unlikely(ret < 0))
1034 if (str->id == id) { 1061 WARNING(cdev, "failed to override string ID\n");
1035 str->s = s; 1062 else
1036 return; 1063 *desc = ret;
1037 }
1038 } 1064 }
1039}
1040 1065
1041static void 1066 return *desc;
1042string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
1043{
1044 while (*tab) {
1045 string_override_one(*tab, id, s);
1046 tab++;
1047 }
1048} 1067}
1049 1068
1050static int composite_bind(struct usb_gadget *gadget) 1069static int composite_bind(struct usb_gadget *gadget)
@@ -1074,7 +1093,13 @@ static int composite_bind(struct usb_gadget *gadget)
1074 cdev->bufsiz = USB_BUFSIZ; 1093 cdev->bufsiz = USB_BUFSIZ;
1075 cdev->driver = composite; 1094 cdev->driver = composite;
1076 1095
1077 usb_gadget_set_selfpowered(gadget); 1096 /*
1097 * As per USB compliance update, a device that is actively drawing
1098 * more than 100mA from USB must report itself as bus-powered in
1099 * the GetStatus(DEVICE) call.
1100 */
1101 if (CONFIG_USB_GADGET_VBUS_DRAW <= USB_SELF_POWER_VBUS_MAX_DRAW)
1102 usb_gadget_set_selfpowered(gadget);
1078 1103
1079 /* interface and string IDs start at zero via kzalloc. 1104 /* interface and string IDs start at zero via kzalloc.
1080 * we force endpoints to start unassigned; few controller 1105 * we force endpoints to start unassigned; few controller
@@ -1094,26 +1119,41 @@ static int composite_bind(struct usb_gadget *gadget)
1094 * serial number), register function drivers, potentially update 1119 * serial number), register function drivers, potentially update
1095 * power state and consumption, etc 1120 * power state and consumption, etc
1096 */ 1121 */
1097 status = composite->bind(cdev); 1122 status = composite_gadget_bind(cdev);
1098 if (status < 0) 1123 if (status < 0)
1099 goto fail; 1124 goto fail;
1100 1125
1101 cdev->desc = *composite->dev; 1126 cdev->desc = *composite->dev;
1102 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket; 1127 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1103 1128
1104 /* strings can't be assigned before bind() allocates the 1129 /* stirng overrides */
1105 * releavnt identifiers 1130 if (iManufacturer || !cdev->desc.iManufacturer) {
1106 */ 1131 if (!iManufacturer && !composite->iManufacturer &&
1107 if (cdev->desc.iManufacturer && iManufacturer) 1132 !*composite_manufacturer)
1108 string_override(composite->strings, 1133 snprintf(composite_manufacturer,
1109 cdev->desc.iManufacturer, iManufacturer); 1134 sizeof composite_manufacturer,
1110 if (cdev->desc.iProduct && iProduct) 1135 "%s %s with %s",
1111 string_override(composite->strings, 1136 init_utsname()->sysname,
1112 cdev->desc.iProduct, iProduct); 1137 init_utsname()->release,
1113 if (cdev->desc.iSerialNumber && iSerialNumber) 1138 gadget->name);
1114 string_override(composite->strings, 1139
1115 cdev->desc.iSerialNumber, iSerialNumber); 1140 cdev->manufacturer_override =
1141 override_id(cdev, &cdev->desc.iManufacturer);
1142 }
1143
1144 if (iProduct || (!cdev->desc.iProduct && composite->iProduct))
1145 cdev->product_override =
1146 override_id(cdev, &cdev->desc.iProduct);
1147
1148 if (iSerialNumber)
1149 cdev->serial_override =
1150 override_id(cdev, &cdev->desc.iSerialNumber);
1151
1152 /* has userspace failed to provide a serial number? */
1153 if (composite->needs_serial && !cdev->desc.iSerialNumber)
1154 WARNING(cdev, "userspace failed to provide iSerialNumber\n");
1116 1155
1156 /* finish up */
1117 status = device_create_file(&gadget->dev, &dev_attr_suspended); 1157 status = device_create_file(&gadget->dev, &dev_attr_suspended);
1118 if (status) 1158 if (status)
1119 goto fail; 1159 goto fail;
@@ -1177,7 +1217,6 @@ composite_resume(struct usb_gadget *gadget)
1177static struct usb_gadget_driver composite_driver = { 1217static struct usb_gadget_driver composite_driver = {
1178 .speed = USB_SPEED_HIGH, 1218 .speed = USB_SPEED_HIGH,
1179 1219
1180 .bind = composite_bind,
1181 .unbind = composite_unbind, 1220 .unbind = composite_unbind,
1182 1221
1183 .setup = composite_setup, 1222 .setup = composite_setup,
@@ -1192,8 +1231,12 @@ static struct usb_gadget_driver composite_driver = {
1192}; 1231};
1193 1232
1194/** 1233/**
1195 * usb_composite_register() - register a composite driver 1234 * usb_composite_probe() - register a composite driver
1196 * @driver: the driver to register 1235 * @driver: the driver to register
1236 * @bind: the callback used to allocate resources that are shared across the
1237 * whole device, such as string IDs, and add its configurations using
1238 * @usb_add_config(). This may fail by returning a negative errno
1239 * value; it should return zero on successful initialization.
1197 * Context: single threaded during gadget setup 1240 * Context: single threaded during gadget setup
1198 * 1241 *
1199 * This function is used to register drivers using the composite driver 1242 * This function is used to register drivers using the composite driver
@@ -1206,18 +1249,22 @@ static struct usb_gadget_driver composite_driver = {
1206 * while it was binding. That would usually be done in order to wait for 1249 * while it was binding. That would usually be done in order to wait for
1207 * some userspace participation. 1250 * some userspace participation.
1208 */ 1251 */
1209int usb_composite_register(struct usb_composite_driver *driver) 1252extern int usb_composite_probe(struct usb_composite_driver *driver,
1253 int (*bind)(struct usb_composite_dev *cdev))
1210{ 1254{
1211 if (!driver || !driver->dev || !driver->bind || composite) 1255 if (!driver || !driver->dev || !bind || composite)
1212 return -EINVAL; 1256 return -EINVAL;
1213 1257
1258 if (!driver->iProduct)
1259 driver->iProduct = driver->name;
1214 if (!driver->name) 1260 if (!driver->name)
1215 driver->name = "composite"; 1261 driver->name = "composite";
1216 composite_driver.function = (char *) driver->name; 1262 composite_driver.function = (char *) driver->name;
1217 composite_driver.driver.name = driver->name; 1263 composite_driver.driver.name = driver->name;
1218 composite = driver; 1264 composite = driver;
1265 composite_gadget_bind = bind;
1219 1266
1220 return usb_gadget_register_driver(&composite_driver); 1267 return usb_gadget_probe_driver(&composite_driver, composite_bind);
1221} 1268}
1222 1269
1223/** 1270/**
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
index 0ed50a2c0a36..e5ac8a316fec 100644
--- a/drivers/usb/gadget/dbgp.c
+++ b/drivers/usb/gadget/dbgp.c
@@ -386,15 +386,13 @@ static int dbgp_setup(struct usb_gadget *gadget,
386 } else 386 } else
387 goto fail; 387 goto fail;
388 388
389 if (len >= 0) { 389 req->length = min(length, len);
390 req->length = min(length, len); 390 req->zero = len < req->length;
391 req->zero = len < req->length; 391 if (data && req->length)
392 if (data && req->length) 392 memcpy(req->buf, data, req->length);
393 memcpy(req->buf, data, req->length); 393
394 394 req->complete = dbgp_setup_complete;
395 req->complete = dbgp_setup_complete; 395 return usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
396 return usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
397 }
398 396
399fail: 397fail:
400 dev_dbg(&dbgp.gadget->dev, 398 dev_dbg(&dbgp.gadget->dev,
@@ -405,7 +403,6 @@ fail:
405static struct usb_gadget_driver dbgp_driver = { 403static struct usb_gadget_driver dbgp_driver = {
406 .function = "dbgp", 404 .function = "dbgp",
407 .speed = USB_SPEED_HIGH, 405 .speed = USB_SPEED_HIGH,
408 .bind = dbgp_bind,
409 .unbind = dbgp_unbind, 406 .unbind = dbgp_unbind,
410 .setup = dbgp_setup, 407 .setup = dbgp_setup,
411 .disconnect = dbgp_disconnect, 408 .disconnect = dbgp_disconnect,
@@ -417,7 +414,7 @@ static struct usb_gadget_driver dbgp_driver = {
417 414
418static int __init dbgp_init(void) 415static int __init dbgp_init(void)
419{ 416{
420 return usb_gadget_register_driver(&dbgp_driver); 417 return usb_gadget_probe_driver(&dbgp_driver, dbgp_bind);
421} 418}
422 419
423static void __exit dbgp_exit(void) 420static void __exit dbgp_exit(void)
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index dc6546248ed9..1d2a2abbfa80 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -748,7 +748,8 @@ static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
748 */ 748 */
749 749
750int 750int
751usb_gadget_register_driver (struct usb_gadget_driver *driver) 751usb_gadget_probe_driver(struct usb_gadget_driver *driver,
752 int (*bind)(struct usb_gadget *))
752{ 753{
753 struct dummy *dum = the_controller; 754 struct dummy *dum = the_controller;
754 int retval, i; 755 int retval, i;
@@ -757,8 +758,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
757 return -EINVAL; 758 return -EINVAL;
758 if (dum->driver) 759 if (dum->driver)
759 return -EBUSY; 760 return -EBUSY;
760 if (!driver->bind || !driver->setup 761 if (!bind || !driver->setup || driver->speed == USB_SPEED_UNKNOWN)
761 || driver->speed == USB_SPEED_UNKNOWN)
762 return -EINVAL; 762 return -EINVAL;
763 763
764 /* 764 /*
@@ -796,7 +796,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
796 dum->gadget.dev.driver = &driver->driver; 796 dum->gadget.dev.driver = &driver->driver;
797 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 797 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
798 driver->driver.name); 798 driver->driver.name);
799 retval = driver->bind(&dum->gadget); 799 retval = bind(&dum->gadget);
800 if (retval) { 800 if (retval) {
801 dum->driver = NULL; 801 dum->driver = NULL;
802 dum->gadget.dev.driver = NULL; 802 dum->gadget.dev.driver = NULL;
@@ -812,7 +812,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
812 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 812 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
813 return 0; 813 return 0;
814} 814}
815EXPORT_SYMBOL (usb_gadget_register_driver); 815EXPORT_SYMBOL(usb_gadget_probe_driver);
816 816
817int 817int
818usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 818usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
@@ -874,6 +874,8 @@ static int dummy_udc_probe (struct platform_device *pdev)
874 struct dummy *dum = the_controller; 874 struct dummy *dum = the_controller;
875 int rc; 875 int rc;
876 876
877 usb_get_hcd(dummy_to_hcd(dum));
878
877 dum->gadget.name = gadget_name; 879 dum->gadget.name = gadget_name;
878 dum->gadget.ops = &dummy_ops; 880 dum->gadget.ops = &dummy_ops;
879 dum->gadget.is_dualspeed = 1; 881 dum->gadget.is_dualspeed = 1;
@@ -885,10 +887,10 @@ static int dummy_udc_probe (struct platform_device *pdev)
885 dum->gadget.dev.parent = &pdev->dev; 887 dum->gadget.dev.parent = &pdev->dev;
886 dum->gadget.dev.release = dummy_gadget_release; 888 dum->gadget.dev.release = dummy_gadget_release;
887 rc = device_register (&dum->gadget.dev); 889 rc = device_register (&dum->gadget.dev);
888 if (rc < 0) 890 if (rc < 0) {
891 put_device(&dum->gadget.dev);
889 return rc; 892 return rc;
890 893 }
891 usb_get_hcd (dummy_to_hcd (dum));
892 894
893 platform_set_drvdata (pdev, dum); 895 platform_set_drvdata (pdev, dum);
894 rc = device_create_file (&dum->gadget.dev, &dev_attr_function); 896 rc = device_create_file (&dum->gadget.dev, &dev_attr_function);
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 114fa024c22c..1690c9d68256 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -237,7 +237,7 @@ static u8 hostaddr[ETH_ALEN];
237 * the first one present. That's to make Microsoft's drivers happy, 237 * the first one present. That's to make Microsoft's drivers happy,
238 * and to follow DOCSIS 1.0 (cable modem standard). 238 * and to follow DOCSIS 1.0 (cable modem standard).
239 */ 239 */
240static int __ref rndis_do_config(struct usb_configuration *c) 240static int __init rndis_do_config(struct usb_configuration *c)
241{ 241{
242 /* FIXME alloc iConfiguration string, set it in c->strings */ 242 /* FIXME alloc iConfiguration string, set it in c->strings */
243 243
@@ -251,7 +251,6 @@ static int __ref rndis_do_config(struct usb_configuration *c)
251 251
252static struct usb_configuration rndis_config_driver = { 252static struct usb_configuration rndis_config_driver = {
253 .label = "RNDIS", 253 .label = "RNDIS",
254 .bind = rndis_do_config,
255 .bConfigurationValue = 2, 254 .bConfigurationValue = 2,
256 /* .iConfiguration = DYNAMIC */ 255 /* .iConfiguration = DYNAMIC */
257 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 256 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -270,7 +269,7 @@ MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
270/* 269/*
271 * We _always_ have an ECM, CDC Subset, or EEM configuration. 270 * We _always_ have an ECM, CDC Subset, or EEM configuration.
272 */ 271 */
273static int __ref eth_do_config(struct usb_configuration *c) 272static int __init eth_do_config(struct usb_configuration *c)
274{ 273{
275 /* FIXME alloc iConfiguration string, set it in c->strings */ 274 /* FIXME alloc iConfiguration string, set it in c->strings */
276 275
@@ -289,7 +288,6 @@ static int __ref eth_do_config(struct usb_configuration *c)
289 288
290static struct usb_configuration eth_config_driver = { 289static struct usb_configuration eth_config_driver = {
291 /* .label = f(hardware) */ 290 /* .label = f(hardware) */
292 .bind = eth_do_config,
293 .bConfigurationValue = 1, 291 .bConfigurationValue = 1,
294 /* .iConfiguration = DYNAMIC */ 292 /* .iConfiguration = DYNAMIC */
295 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 293 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -297,7 +295,7 @@ static struct usb_configuration eth_config_driver = {
297 295
298/*-------------------------------------------------------------------------*/ 296/*-------------------------------------------------------------------------*/
299 297
300static int __ref eth_bind(struct usb_composite_dev *cdev) 298static int __init eth_bind(struct usb_composite_dev *cdev)
301{ 299{
302 int gcnum; 300 int gcnum;
303 struct usb_gadget *gadget = cdev->gadget; 301 struct usb_gadget *gadget = cdev->gadget;
@@ -373,12 +371,13 @@ static int __ref eth_bind(struct usb_composite_dev *cdev)
373 371
374 /* register our configuration(s); RNDIS first, if it's used */ 372 /* register our configuration(s); RNDIS first, if it's used */
375 if (has_rndis()) { 373 if (has_rndis()) {
376 status = usb_add_config(cdev, &rndis_config_driver); 374 status = usb_add_config(cdev, &rndis_config_driver,
375 rndis_do_config);
377 if (status < 0) 376 if (status < 0)
378 goto fail; 377 goto fail;
379 } 378 }
380 379
381 status = usb_add_config(cdev, &eth_config_driver); 380 status = usb_add_config(cdev, &eth_config_driver, eth_do_config);
382 if (status < 0) 381 if (status < 0)
383 goto fail; 382 goto fail;
384 383
@@ -402,7 +401,6 @@ static struct usb_composite_driver eth_driver = {
402 .name = "g_ether", 401 .name = "g_ether",
403 .dev = &device_desc, 402 .dev = &device_desc,
404 .strings = dev_strings, 403 .strings = dev_strings,
405 .bind = eth_bind,
406 .unbind = __exit_p(eth_unbind), 404 .unbind = __exit_p(eth_unbind),
407}; 405};
408 406
@@ -412,7 +410,7 @@ MODULE_LICENSE("GPL");
412 410
413static int __init init(void) 411static int __init init(void)
414{ 412{
415 return usb_composite_register(&eth_driver); 413 return usb_composite_probe(&eth_driver, eth_bind);
416} 414}
417module_init(init); 415module_init(init);
418 416
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index d47a123f15ab..bd6226cbae86 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -111,7 +111,7 @@ acm_iad_descriptor = {
111 .bInterfaceCount = 2, // control + data 111 .bInterfaceCount = 2, // control + data
112 .bFunctionClass = USB_CLASS_COMM, 112 .bFunctionClass = USB_CLASS_COMM,
113 .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, 113 .bFunctionSubClass = USB_CDC_SUBCLASS_ACM,
114 .bFunctionProtocol = USB_CDC_PROTO_NONE, 114 .bFunctionProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
115 /* .iFunction = DYNAMIC */ 115 /* .iFunction = DYNAMIC */
116}; 116};
117 117
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index 43225879c3cd..b37960f9e753 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -324,7 +324,7 @@ static void loopback_disable(struct usb_function *f)
324 324
325/*-------------------------------------------------------------------------*/ 325/*-------------------------------------------------------------------------*/
326 326
327static int __ref loopback_bind_config(struct usb_configuration *c) 327static int __init loopback_bind_config(struct usb_configuration *c)
328{ 328{
329 struct f_loopback *loop; 329 struct f_loopback *loop;
330 int status; 330 int status;
@@ -346,10 +346,9 @@ static int __ref loopback_bind_config(struct usb_configuration *c)
346 return status; 346 return status;
347} 347}
348 348
349static struct usb_configuration loopback_driver = { 349static struct usb_configuration loopback_driver = {
350 .label = "loopback", 350 .label = "loopback",
351 .strings = loopback_strings, 351 .strings = loopback_strings,
352 .bind = loopback_bind_config,
353 .bConfigurationValue = 2, 352 .bConfigurationValue = 2,
354 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 353 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
355 /* .iConfiguration = DYNAMIC */ 354 /* .iConfiguration = DYNAMIC */
@@ -382,5 +381,5 @@ int __init loopback_add(struct usb_composite_dev *cdev, bool autoresume)
382 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 381 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
383 } 382 }
384 383
385 return usb_add_config(cdev, &loopback_driver); 384 return usb_add_config(cdev, &loopback_driver, loopback_bind_config);
386} 385}
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 32cce029f65c..838286b1cd14 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -73,6 +73,8 @@
73 * being removable. 73 * being removable.
74 * ->cdrom Flag specifying that LUN shall be reported as 74 * ->cdrom Flag specifying that LUN shall be reported as
75 * being a CD-ROM. 75 * being a CD-ROM.
76 * ->nofua Flag specifying that FUA flag in SCSI WRITE(10,12)
77 * commands for this LUN shall be ignored.
76 * 78 *
77 * lun_name_format A printf-like format for names of the LUN 79 * lun_name_format A printf-like format for names of the LUN
78 * devices. This determines how the 80 * devices. This determines how the
@@ -127,6 +129,8 @@
127 * Default true, boolean for removable media. 129 * Default true, boolean for removable media.
128 * cdrom=b[,b...] Default false, boolean for whether to emulate 130 * cdrom=b[,b...] Default false, boolean for whether to emulate
129 * a CD-ROM drive. 131 * a CD-ROM drive.
132 * nofua=b[,b...] Default false, booleans for ignore FUA flag
133 * in SCSI WRITE(10,12) commands
130 * luns=N Default N = number of filenames, number of 134 * luns=N Default N = number of filenames, number of
131 * LUNs to support. 135 * LUNs to support.
132 * stall Default determined according to the type of 136 * stall Default determined according to the type of
@@ -409,6 +413,7 @@ struct fsg_config {
409 char ro; 413 char ro;
410 char removable; 414 char removable;
411 char cdrom; 415 char cdrom;
416 char nofua;
412 } luns[FSG_MAX_LUNS]; 417 } luns[FSG_MAX_LUNS];
413 418
414 const char *lun_name_format; 419 const char *lun_name_format;
@@ -736,7 +741,7 @@ static int do_read(struct fsg_common *common)
736 741
737 /* Get the starting Logical Block Address and check that it's 742 /* Get the starting Logical Block Address and check that it's
738 * not too big */ 743 * not too big */
739 if (common->cmnd[0] == SC_READ_6) 744 if (common->cmnd[0] == READ_6)
740 lba = get_unaligned_be24(&common->cmnd[1]); 745 lba = get_unaligned_be24(&common->cmnd[1]);
741 else { 746 else {
742 lba = get_unaligned_be32(&common->cmnd[2]); 747 lba = get_unaligned_be32(&common->cmnd[2]);
@@ -874,7 +879,7 @@ static int do_write(struct fsg_common *common)
874 879
875 /* Get the starting Logical Block Address and check that it's 880 /* Get the starting Logical Block Address and check that it's
876 * not too big */ 881 * not too big */
877 if (common->cmnd[0] == SC_WRITE_6) 882 if (common->cmnd[0] == WRITE_6)
878 lba = get_unaligned_be24(&common->cmnd[1]); 883 lba = get_unaligned_be24(&common->cmnd[1]);
879 else { 884 else {
880 lba = get_unaligned_be32(&common->cmnd[2]); 885 lba = get_unaligned_be32(&common->cmnd[2]);
@@ -887,7 +892,7 @@ static int do_write(struct fsg_common *common)
887 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 892 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
888 return -EINVAL; 893 return -EINVAL;
889 } 894 }
890 if (common->cmnd[1] & 0x08) { /* FUA */ 895 if (!curlun->nofua && (common->cmnd[1] & 0x08)) { /* FUA */
891 spin_lock(&curlun->filp->f_lock); 896 spin_lock(&curlun->filp->f_lock);
892 curlun->filp->f_flags |= O_SYNC; 897 curlun->filp->f_flags |= O_SYNC;
893 spin_unlock(&curlun->filp->f_lock); 898 spin_unlock(&curlun->filp->f_lock);
@@ -1181,7 +1186,7 @@ static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh)
1181 return 36; 1186 return 36;
1182 } 1187 }
1183 1188
1184 buf[0] = curlun->cdrom ? TYPE_CDROM : TYPE_DISK; 1189 buf[0] = curlun->cdrom ? TYPE_ROM : TYPE_DISK;
1185 buf[1] = curlun->removable ? 0x80 : 0; 1190 buf[1] = curlun->removable ? 0x80 : 0;
1186 buf[2] = 2; /* ANSI SCSI level 2 */ 1191 buf[2] = 2; /* ANSI SCSI level 2 */
1187 buf[3] = 2; /* SCSI-2 INQUIRY data format */ 1192 buf[3] = 2; /* SCSI-2 INQUIRY data format */
@@ -1348,11 +1353,11 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1348 * The only variable value is the WriteProtect bit. We will fill in 1353 * The only variable value is the WriteProtect bit. We will fill in
1349 * the mode data length later. */ 1354 * the mode data length later. */
1350 memset(buf, 0, 8); 1355 memset(buf, 0, 8);
1351 if (mscmnd == SC_MODE_SENSE_6) { 1356 if (mscmnd == MODE_SENSE) {
1352 buf[2] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */ 1357 buf[2] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */
1353 buf += 4; 1358 buf += 4;
1354 limit = 255; 1359 limit = 255;
1355 } else { /* SC_MODE_SENSE_10 */ 1360 } else { /* MODE_SENSE_10 */
1356 buf[3] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */ 1361 buf[3] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */
1357 buf += 8; 1362 buf += 8;
1358 limit = 65535; /* Should really be FSG_BUFLEN */ 1363 limit = 65535; /* Should really be FSG_BUFLEN */
@@ -1392,7 +1397,7 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1392 } 1397 }
1393 1398
1394 /* Store the mode data length */ 1399 /* Store the mode data length */
1395 if (mscmnd == SC_MODE_SENSE_6) 1400 if (mscmnd == MODE_SENSE)
1396 buf0[0] = len - 1; 1401 buf0[0] = len - 1;
1397 else 1402 else
1398 put_unaligned_be16(len - 2, buf0); 1403 put_unaligned_be16(len - 2, buf0);
@@ -1881,7 +1886,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1881 if (common->lun >= 0 && common->lun < common->nluns) { 1886 if (common->lun >= 0 && common->lun < common->nluns) {
1882 curlun = &common->luns[common->lun]; 1887 curlun = &common->luns[common->lun];
1883 common->curlun = curlun; 1888 common->curlun = curlun;
1884 if (common->cmnd[0] != SC_REQUEST_SENSE) { 1889 if (common->cmnd[0] != REQUEST_SENSE) {
1885 curlun->sense_data = SS_NO_SENSE; 1890 curlun->sense_data = SS_NO_SENSE;
1886 curlun->sense_data_info = 0; 1891 curlun->sense_data_info = 0;
1887 curlun->info_valid = 0; 1892 curlun->info_valid = 0;
@@ -1893,8 +1898,8 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1893 1898
1894 /* INQUIRY and REQUEST SENSE commands are explicitly allowed 1899 /* INQUIRY and REQUEST SENSE commands are explicitly allowed
1895 * to use unsupported LUNs; all others may not. */ 1900 * to use unsupported LUNs; all others may not. */
1896 if (common->cmnd[0] != SC_INQUIRY && 1901 if (common->cmnd[0] != INQUIRY &&
1897 common->cmnd[0] != SC_REQUEST_SENSE) { 1902 common->cmnd[0] != REQUEST_SENSE) {
1898 DBG(common, "unsupported LUN %d\n", common->lun); 1903 DBG(common, "unsupported LUN %d\n", common->lun);
1899 return -EINVAL; 1904 return -EINVAL;
1900 } 1905 }
@@ -1903,8 +1908,8 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1903 /* If a unit attention condition exists, only INQUIRY and 1908 /* If a unit attention condition exists, only INQUIRY and
1904 * REQUEST SENSE commands are allowed; anything else must fail. */ 1909 * REQUEST SENSE commands are allowed; anything else must fail. */
1905 if (curlun && curlun->unit_attention_data != SS_NO_SENSE && 1910 if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
1906 common->cmnd[0] != SC_INQUIRY && 1911 common->cmnd[0] != INQUIRY &&
1907 common->cmnd[0] != SC_REQUEST_SENSE) { 1912 common->cmnd[0] != REQUEST_SENSE) {
1908 curlun->sense_data = curlun->unit_attention_data; 1913 curlun->sense_data = curlun->unit_attention_data;
1909 curlun->unit_attention_data = SS_NO_SENSE; 1914 curlun->unit_attention_data = SS_NO_SENSE;
1910 return -EINVAL; 1915 return -EINVAL;
@@ -1955,7 +1960,7 @@ static int do_scsi_command(struct fsg_common *common)
1955 down_read(&common->filesem); /* We're using the backing file */ 1960 down_read(&common->filesem); /* We're using the backing file */
1956 switch (common->cmnd[0]) { 1961 switch (common->cmnd[0]) {
1957 1962
1958 case SC_INQUIRY: 1963 case INQUIRY:
1959 common->data_size_from_cmnd = common->cmnd[4]; 1964 common->data_size_from_cmnd = common->cmnd[4];
1960 reply = check_command(common, 6, DATA_DIR_TO_HOST, 1965 reply = check_command(common, 6, DATA_DIR_TO_HOST,
1961 (1<<4), 0, 1966 (1<<4), 0,
@@ -1964,7 +1969,7 @@ static int do_scsi_command(struct fsg_common *common)
1964 reply = do_inquiry(common, bh); 1969 reply = do_inquiry(common, bh);
1965 break; 1970 break;
1966 1971
1967 case SC_MODE_SELECT_6: 1972 case MODE_SELECT:
1968 common->data_size_from_cmnd = common->cmnd[4]; 1973 common->data_size_from_cmnd = common->cmnd[4];
1969 reply = check_command(common, 6, DATA_DIR_FROM_HOST, 1974 reply = check_command(common, 6, DATA_DIR_FROM_HOST,
1970 (1<<1) | (1<<4), 0, 1975 (1<<1) | (1<<4), 0,
@@ -1973,7 +1978,7 @@ static int do_scsi_command(struct fsg_common *common)
1973 reply = do_mode_select(common, bh); 1978 reply = do_mode_select(common, bh);
1974 break; 1979 break;
1975 1980
1976 case SC_MODE_SELECT_10: 1981 case MODE_SELECT_10:
1977 common->data_size_from_cmnd = 1982 common->data_size_from_cmnd =
1978 get_unaligned_be16(&common->cmnd[7]); 1983 get_unaligned_be16(&common->cmnd[7]);
1979 reply = check_command(common, 10, DATA_DIR_FROM_HOST, 1984 reply = check_command(common, 10, DATA_DIR_FROM_HOST,
@@ -1983,7 +1988,7 @@ static int do_scsi_command(struct fsg_common *common)
1983 reply = do_mode_select(common, bh); 1988 reply = do_mode_select(common, bh);
1984 break; 1989 break;
1985 1990
1986 case SC_MODE_SENSE_6: 1991 case MODE_SENSE:
1987 common->data_size_from_cmnd = common->cmnd[4]; 1992 common->data_size_from_cmnd = common->cmnd[4];
1988 reply = check_command(common, 6, DATA_DIR_TO_HOST, 1993 reply = check_command(common, 6, DATA_DIR_TO_HOST,
1989 (1<<1) | (1<<2) | (1<<4), 0, 1994 (1<<1) | (1<<2) | (1<<4), 0,
@@ -1992,7 +1997,7 @@ static int do_scsi_command(struct fsg_common *common)
1992 reply = do_mode_sense(common, bh); 1997 reply = do_mode_sense(common, bh);
1993 break; 1998 break;
1994 1999
1995 case SC_MODE_SENSE_10: 2000 case MODE_SENSE_10:
1996 common->data_size_from_cmnd = 2001 common->data_size_from_cmnd =
1997 get_unaligned_be16(&common->cmnd[7]); 2002 get_unaligned_be16(&common->cmnd[7]);
1998 reply = check_command(common, 10, DATA_DIR_TO_HOST, 2003 reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2002,7 +2007,7 @@ static int do_scsi_command(struct fsg_common *common)
2002 reply = do_mode_sense(common, bh); 2007 reply = do_mode_sense(common, bh);
2003 break; 2008 break;
2004 2009
2005 case SC_PREVENT_ALLOW_MEDIUM_REMOVAL: 2010 case ALLOW_MEDIUM_REMOVAL:
2006 common->data_size_from_cmnd = 0; 2011 common->data_size_from_cmnd = 0;
2007 reply = check_command(common, 6, DATA_DIR_NONE, 2012 reply = check_command(common, 6, DATA_DIR_NONE,
2008 (1<<4), 0, 2013 (1<<4), 0,
@@ -2011,7 +2016,7 @@ static int do_scsi_command(struct fsg_common *common)
2011 reply = do_prevent_allow(common); 2016 reply = do_prevent_allow(common);
2012 break; 2017 break;
2013 2018
2014 case SC_READ_6: 2019 case READ_6:
2015 i = common->cmnd[4]; 2020 i = common->cmnd[4];
2016 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; 2021 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2017 reply = check_command(common, 6, DATA_DIR_TO_HOST, 2022 reply = check_command(common, 6, DATA_DIR_TO_HOST,
@@ -2021,7 +2026,7 @@ static int do_scsi_command(struct fsg_common *common)
2021 reply = do_read(common); 2026 reply = do_read(common);
2022 break; 2027 break;
2023 2028
2024 case SC_READ_10: 2029 case READ_10:
2025 common->data_size_from_cmnd = 2030 common->data_size_from_cmnd =
2026 get_unaligned_be16(&common->cmnd[7]) << 9; 2031 get_unaligned_be16(&common->cmnd[7]) << 9;
2027 reply = check_command(common, 10, DATA_DIR_TO_HOST, 2032 reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2031,7 +2036,7 @@ static int do_scsi_command(struct fsg_common *common)
2031 reply = do_read(common); 2036 reply = do_read(common);
2032 break; 2037 break;
2033 2038
2034 case SC_READ_12: 2039 case READ_12:
2035 common->data_size_from_cmnd = 2040 common->data_size_from_cmnd =
2036 get_unaligned_be32(&common->cmnd[6]) << 9; 2041 get_unaligned_be32(&common->cmnd[6]) << 9;
2037 reply = check_command(common, 12, DATA_DIR_TO_HOST, 2042 reply = check_command(common, 12, DATA_DIR_TO_HOST,
@@ -2041,7 +2046,7 @@ static int do_scsi_command(struct fsg_common *common)
2041 reply = do_read(common); 2046 reply = do_read(common);
2042 break; 2047 break;
2043 2048
2044 case SC_READ_CAPACITY: 2049 case READ_CAPACITY:
2045 common->data_size_from_cmnd = 8; 2050 common->data_size_from_cmnd = 8;
2046 reply = check_command(common, 10, DATA_DIR_TO_HOST, 2051 reply = check_command(common, 10, DATA_DIR_TO_HOST,
2047 (0xf<<2) | (1<<8), 1, 2052 (0xf<<2) | (1<<8), 1,
@@ -2050,7 +2055,7 @@ static int do_scsi_command(struct fsg_common *common)
2050 reply = do_read_capacity(common, bh); 2055 reply = do_read_capacity(common, bh);
2051 break; 2056 break;
2052 2057
2053 case SC_READ_HEADER: 2058 case READ_HEADER:
2054 if (!common->curlun || !common->curlun->cdrom) 2059 if (!common->curlun || !common->curlun->cdrom)
2055 goto unknown_cmnd; 2060 goto unknown_cmnd;
2056 common->data_size_from_cmnd = 2061 common->data_size_from_cmnd =
@@ -2062,7 +2067,7 @@ static int do_scsi_command(struct fsg_common *common)
2062 reply = do_read_header(common, bh); 2067 reply = do_read_header(common, bh);
2063 break; 2068 break;
2064 2069
2065 case SC_READ_TOC: 2070 case READ_TOC:
2066 if (!common->curlun || !common->curlun->cdrom) 2071 if (!common->curlun || !common->curlun->cdrom)
2067 goto unknown_cmnd; 2072 goto unknown_cmnd;
2068 common->data_size_from_cmnd = 2073 common->data_size_from_cmnd =
@@ -2074,7 +2079,7 @@ static int do_scsi_command(struct fsg_common *common)
2074 reply = do_read_toc(common, bh); 2079 reply = do_read_toc(common, bh);
2075 break; 2080 break;
2076 2081
2077 case SC_READ_FORMAT_CAPACITIES: 2082 case READ_FORMAT_CAPACITIES:
2078 common->data_size_from_cmnd = 2083 common->data_size_from_cmnd =
2079 get_unaligned_be16(&common->cmnd[7]); 2084 get_unaligned_be16(&common->cmnd[7]);
2080 reply = check_command(common, 10, DATA_DIR_TO_HOST, 2085 reply = check_command(common, 10, DATA_DIR_TO_HOST,
@@ -2084,7 +2089,7 @@ static int do_scsi_command(struct fsg_common *common)
2084 reply = do_read_format_capacities(common, bh); 2089 reply = do_read_format_capacities(common, bh);
2085 break; 2090 break;
2086 2091
2087 case SC_REQUEST_SENSE: 2092 case REQUEST_SENSE:
2088 common->data_size_from_cmnd = common->cmnd[4]; 2093 common->data_size_from_cmnd = common->cmnd[4];
2089 reply = check_command(common, 6, DATA_DIR_TO_HOST, 2094 reply = check_command(common, 6, DATA_DIR_TO_HOST,
2090 (1<<4), 0, 2095 (1<<4), 0,
@@ -2093,7 +2098,7 @@ static int do_scsi_command(struct fsg_common *common)
2093 reply = do_request_sense(common, bh); 2098 reply = do_request_sense(common, bh);
2094 break; 2099 break;
2095 2100
2096 case SC_START_STOP_UNIT: 2101 case START_STOP:
2097 common->data_size_from_cmnd = 0; 2102 common->data_size_from_cmnd = 0;
2098 reply = check_command(common, 6, DATA_DIR_NONE, 2103 reply = check_command(common, 6, DATA_DIR_NONE,
2099 (1<<1) | (1<<4), 0, 2104 (1<<1) | (1<<4), 0,
@@ -2102,7 +2107,7 @@ static int do_scsi_command(struct fsg_common *common)
2102 reply = do_start_stop(common); 2107 reply = do_start_stop(common);
2103 break; 2108 break;
2104 2109
2105 case SC_SYNCHRONIZE_CACHE: 2110 case SYNCHRONIZE_CACHE:
2106 common->data_size_from_cmnd = 0; 2111 common->data_size_from_cmnd = 0;
2107 reply = check_command(common, 10, DATA_DIR_NONE, 2112 reply = check_command(common, 10, DATA_DIR_NONE,
2108 (0xf<<2) | (3<<7), 1, 2113 (0xf<<2) | (3<<7), 1,
@@ -2111,7 +2116,7 @@ static int do_scsi_command(struct fsg_common *common)
2111 reply = do_synchronize_cache(common); 2116 reply = do_synchronize_cache(common);
2112 break; 2117 break;
2113 2118
2114 case SC_TEST_UNIT_READY: 2119 case TEST_UNIT_READY:
2115 common->data_size_from_cmnd = 0; 2120 common->data_size_from_cmnd = 0;
2116 reply = check_command(common, 6, DATA_DIR_NONE, 2121 reply = check_command(common, 6, DATA_DIR_NONE,
2117 0, 1, 2122 0, 1,
@@ -2120,7 +2125,7 @@ static int do_scsi_command(struct fsg_common *common)
2120 2125
2121 /* Although optional, this command is used by MS-Windows. We 2126 /* Although optional, this command is used by MS-Windows. We
2122 * support a minimal version: BytChk must be 0. */ 2127 * support a minimal version: BytChk must be 0. */
2123 case SC_VERIFY: 2128 case VERIFY:
2124 common->data_size_from_cmnd = 0; 2129 common->data_size_from_cmnd = 0;
2125 reply = check_command(common, 10, DATA_DIR_NONE, 2130 reply = check_command(common, 10, DATA_DIR_NONE,
2126 (1<<1) | (0xf<<2) | (3<<7), 1, 2131 (1<<1) | (0xf<<2) | (3<<7), 1,
@@ -2129,7 +2134,7 @@ static int do_scsi_command(struct fsg_common *common)
2129 reply = do_verify(common); 2134 reply = do_verify(common);
2130 break; 2135 break;
2131 2136
2132 case SC_WRITE_6: 2137 case WRITE_6:
2133 i = common->cmnd[4]; 2138 i = common->cmnd[4];
2134 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; 2139 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2135 reply = check_command(common, 6, DATA_DIR_FROM_HOST, 2140 reply = check_command(common, 6, DATA_DIR_FROM_HOST,
@@ -2139,7 +2144,7 @@ static int do_scsi_command(struct fsg_common *common)
2139 reply = do_write(common); 2144 reply = do_write(common);
2140 break; 2145 break;
2141 2146
2142 case SC_WRITE_10: 2147 case WRITE_10:
2143 common->data_size_from_cmnd = 2148 common->data_size_from_cmnd =
2144 get_unaligned_be16(&common->cmnd[7]) << 9; 2149 get_unaligned_be16(&common->cmnd[7]) << 9;
2145 reply = check_command(common, 10, DATA_DIR_FROM_HOST, 2150 reply = check_command(common, 10, DATA_DIR_FROM_HOST,
@@ -2149,7 +2154,7 @@ static int do_scsi_command(struct fsg_common *common)
2149 reply = do_write(common); 2154 reply = do_write(common);
2150 break; 2155 break;
2151 2156
2152 case SC_WRITE_12: 2157 case WRITE_12:
2153 common->data_size_from_cmnd = 2158 common->data_size_from_cmnd =
2154 get_unaligned_be32(&common->cmnd[6]) << 9; 2159 get_unaligned_be32(&common->cmnd[6]) << 9;
2155 reply = check_command(common, 12, DATA_DIR_FROM_HOST, 2160 reply = check_command(common, 12, DATA_DIR_FROM_HOST,
@@ -2163,10 +2168,10 @@ static int do_scsi_command(struct fsg_common *common)
2163 * They don't mean much in this setting. It's left as an exercise 2168 * They don't mean much in this setting. It's left as an exercise
2164 * for anyone interested to implement RESERVE and RELEASE in terms 2169 * for anyone interested to implement RESERVE and RELEASE in terms
2165 * of Posix locks. */ 2170 * of Posix locks. */
2166 case SC_FORMAT_UNIT: 2171 case FORMAT_UNIT:
2167 case SC_RELEASE: 2172 case RELEASE:
2168 case SC_RESERVE: 2173 case RESERVE:
2169 case SC_SEND_DIAGNOSTIC: 2174 case SEND_DIAGNOSTIC:
2170 /* Fall through */ 2175 /* Fall through */
2171 2176
2172 default: 2177 default:
@@ -2662,6 +2667,7 @@ static int fsg_main_thread(void *common_)
2662 2667
2663/* Write permission is checked per LUN in store_*() functions. */ 2668/* Write permission is checked per LUN in store_*() functions. */
2664static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro); 2669static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
2670static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua);
2665static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file); 2671static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
2666 2672
2667 2673
@@ -2768,6 +2774,9 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2768 rc = device_create_file(&curlun->dev, &dev_attr_file); 2774 rc = device_create_file(&curlun->dev, &dev_attr_file);
2769 if (rc) 2775 if (rc)
2770 goto error_luns; 2776 goto error_luns;
2777 rc = device_create_file(&curlun->dev, &dev_attr_nofua);
2778 if (rc)
2779 goto error_luns;
2771 2780
2772 if (lcfg->filename) { 2781 if (lcfg->filename) {
2773 rc = fsg_lun_open(curlun, lcfg->filename); 2782 rc = fsg_lun_open(curlun, lcfg->filename);
@@ -2911,6 +2920,7 @@ static void fsg_common_release(struct kref *ref)
2911 2920
2912 /* In error recovery common->nluns may be zero. */ 2921 /* In error recovery common->nluns may be zero. */
2913 for (; i; --i, ++lun) { 2922 for (; i; --i, ++lun) {
2923 device_remove_file(&lun->dev, &dev_attr_nofua);
2914 device_remove_file(&lun->dev, &dev_attr_ro); 2924 device_remove_file(&lun->dev, &dev_attr_ro);
2915 device_remove_file(&lun->dev, &dev_attr_file); 2925 device_remove_file(&lun->dev, &dev_attr_file);
2916 fsg_lun_close(lun); 2926 fsg_lun_close(lun);
@@ -3069,8 +3079,10 @@ struct fsg_module_parameters {
3069 int ro[FSG_MAX_LUNS]; 3079 int ro[FSG_MAX_LUNS];
3070 int removable[FSG_MAX_LUNS]; 3080 int removable[FSG_MAX_LUNS];
3071 int cdrom[FSG_MAX_LUNS]; 3081 int cdrom[FSG_MAX_LUNS];
3082 int nofua[FSG_MAX_LUNS];
3072 3083
3073 unsigned int file_count, ro_count, removable_count, cdrom_count; 3084 unsigned int file_count, ro_count, removable_count, cdrom_count;
3085 unsigned int nofua_count;
3074 unsigned int luns; /* nluns */ 3086 unsigned int luns; /* nluns */
3075 int stall; /* can_stall */ 3087 int stall; /* can_stall */
3076}; 3088};
@@ -3096,6 +3108,8 @@ struct fsg_module_parameters {
3096 "true to simulate removable media"); \ 3108 "true to simulate removable media"); \
3097 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \ 3109 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
3098 "true to simulate CD-ROM instead of disk"); \ 3110 "true to simulate CD-ROM instead of disk"); \
3111 _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
3112 "true to ignore SCSI WRITE(10,12) FUA bit"); \
3099 _FSG_MODULE_PARAM(prefix, params, luns, uint, \ 3113 _FSG_MODULE_PARAM(prefix, params, luns, uint, \
3100 "number of LUNs"); \ 3114 "number of LUNs"); \
3101 _FSG_MODULE_PARAM(prefix, params, stall, bool, \ 3115 _FSG_MODULE_PARAM(prefix, params, stall, bool, \
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 685d768f336e..e403a534dd55 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -404,7 +404,7 @@ static void sourcesink_disable(struct usb_function *f)
404 404
405/*-------------------------------------------------------------------------*/ 405/*-------------------------------------------------------------------------*/
406 406
407static int __ref sourcesink_bind_config(struct usb_configuration *c) 407static int __init sourcesink_bind_config(struct usb_configuration *c)
408{ 408{
409 struct f_sourcesink *ss; 409 struct f_sourcesink *ss;
410 int status; 410 int status;
@@ -498,7 +498,6 @@ unknown:
498static struct usb_configuration sourcesink_driver = { 498static struct usb_configuration sourcesink_driver = {
499 .label = "source/sink", 499 .label = "source/sink",
500 .strings = sourcesink_strings, 500 .strings = sourcesink_strings,
501 .bind = sourcesink_bind_config,
502 .setup = sourcesink_setup, 501 .setup = sourcesink_setup,
503 .bConfigurationValue = 3, 502 .bConfigurationValue = 3,
504 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 503 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -532,5 +531,5 @@ int __init sourcesink_add(struct usb_composite_dev *cdev, bool autoresume)
532 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 531 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
533 } 532 }
534 533
535 return usb_add_config(cdev, &sourcesink_driver); 534 return usb_add_config(cdev, &sourcesink_driver, sourcesink_bind_config);
536} 535}
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a857b7ac238c..d4fdf65fb925 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -89,6 +89,7 @@
89 * Required if "removable" is not set, names of 89 * Required if "removable" is not set, names of
90 * the files or block devices used for 90 * the files or block devices used for
91 * backing storage 91 * backing storage
92 * serial=HHHH... Required serial number (string of hex chars)
92 * ro=b[,b...] Default false, booleans for read-only access 93 * ro=b[,b...] Default false, booleans for read-only access
93 * removable Default false, boolean for removable media 94 * removable Default false, boolean for removable media
94 * luns=N Default N = number of filenames, number of 95 * luns=N Default N = number of filenames, number of
@@ -108,12 +109,11 @@
108 * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID 109 * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
109 * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID 110 * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
110 * release=0xRRRR Override the USB release number (bcdDevice) 111 * release=0xRRRR Override the USB release number (bcdDevice)
111 * serial=HHHH... Override serial number (string of hex chars)
112 * buflen=N Default N=16384, buffer size used (will be 112 * buflen=N Default N=16384, buffer size used (will be
113 * rounded down to a multiple of 113 * rounded down to a multiple of
114 * PAGE_CACHE_SIZE) 114 * PAGE_CACHE_SIZE)
115 * 115 *
116 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", 116 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
117 * "removable", "luns", "nofua", "stall", and "cdrom" options are available; 117 * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
118 * default values are used for everything else. 118 * default values are used for everything else.
119 * 119 *
@@ -273,13 +273,10 @@
273 273
274#define DRIVER_DESC "File-backed Storage Gadget" 274#define DRIVER_DESC "File-backed Storage Gadget"
275#define DRIVER_NAME "g_file_storage" 275#define DRIVER_NAME "g_file_storage"
276/* DRIVER_VERSION must be at least 6 characters long, as it is used 276#define DRIVER_VERSION "1 September 2010"
277 * to generate a fallback serial number. */
278#define DRIVER_VERSION "20 November 2008"
279 277
280static char fsg_string_manufacturer[64]; 278static char fsg_string_manufacturer[64];
281static const char fsg_string_product[] = DRIVER_DESC; 279static const char fsg_string_product[] = DRIVER_DESC;
282static char fsg_string_serial[13];
283static const char fsg_string_config[] = "Self-powered"; 280static const char fsg_string_config[] = "Self-powered";
284static const char fsg_string_interface[] = "Mass Storage"; 281static const char fsg_string_interface[] = "Mass Storage";
285 282
@@ -305,6 +302,7 @@ MODULE_LICENSE("Dual BSD/GPL");
305 302
306static struct { 303static struct {
307 char *file[FSG_MAX_LUNS]; 304 char *file[FSG_MAX_LUNS];
305 char *serial;
308 int ro[FSG_MAX_LUNS]; 306 int ro[FSG_MAX_LUNS];
309 int nofua[FSG_MAX_LUNS]; 307 int nofua[FSG_MAX_LUNS];
310 unsigned int num_filenames; 308 unsigned int num_filenames;
@@ -321,7 +319,6 @@ static struct {
321 unsigned short vendor; 319 unsigned short vendor;
322 unsigned short product; 320 unsigned short product;
323 unsigned short release; 321 unsigned short release;
324 char *serial;
325 unsigned int buflen; 322 unsigned int buflen;
326 323
327 int transport_type; 324 int transport_type;
@@ -346,6 +343,9 @@ module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
346 S_IRUGO); 343 S_IRUGO);
347MODULE_PARM_DESC(file, "names of backing files or devices"); 344MODULE_PARM_DESC(file, "names of backing files or devices");
348 345
346module_param_named(serial, mod_data.serial, charp, S_IRUGO);
347MODULE_PARM_DESC(serial, "USB serial number");
348
349module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); 349module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
350MODULE_PARM_DESC(ro, "true to force read-only"); 350MODULE_PARM_DESC(ro, "true to force read-only");
351 351
@@ -365,9 +365,6 @@ MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
365module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); 365module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
366MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); 366MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
367 367
368module_param_named(serial, mod_data.serial, charp, S_IRUGO);
369MODULE_PARM_DESC(serial, "USB serial number");
370
371/* In the non-TEST version, only the module parameters listed above 368/* In the non-TEST version, only the module parameters listed above
372 * are available. */ 369 * are available. */
373#ifdef CONFIG_USB_FILE_STORAGE_TEST 370#ifdef CONFIG_USB_FILE_STORAGE_TEST
@@ -786,7 +783,7 @@ static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
786{ 783{
787 struct usb_request *req = fsg->ep0req; 784 struct usb_request *req = fsg->ep0req;
788 static u8 cbi_reset_cmnd[6] = { 785 static u8 cbi_reset_cmnd[6] = {
789 SC_SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff}; 786 SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
790 787
791 /* Error in command transfer? */ 788 /* Error in command transfer? */
792 if (req->status || req->length != req->actual || 789 if (req->status || req->length != req->actual ||
@@ -1138,7 +1135,7 @@ static int do_read(struct fsg_dev *fsg)
1138 1135
1139 /* Get the starting Logical Block Address and check that it's 1136 /* Get the starting Logical Block Address and check that it's
1140 * not too big */ 1137 * not too big */
1141 if (fsg->cmnd[0] == SC_READ_6) 1138 if (fsg->cmnd[0] == READ_6)
1142 lba = get_unaligned_be24(&fsg->cmnd[1]); 1139 lba = get_unaligned_be24(&fsg->cmnd[1]);
1143 else { 1140 else {
1144 lba = get_unaligned_be32(&fsg->cmnd[2]); 1141 lba = get_unaligned_be32(&fsg->cmnd[2]);
@@ -1273,7 +1270,7 @@ static int do_write(struct fsg_dev *fsg)
1273 1270
1274 /* Get the starting Logical Block Address and check that it's 1271 /* Get the starting Logical Block Address and check that it's
1275 * not too big */ 1272 * not too big */
1276 if (fsg->cmnd[0] == SC_WRITE_6) 1273 if (fsg->cmnd[0] == WRITE_6)
1277 lba = get_unaligned_be24(&fsg->cmnd[1]); 1274 lba = get_unaligned_be24(&fsg->cmnd[1]);
1278 else { 1275 else {
1279 lba = get_unaligned_be32(&fsg->cmnd[2]); 1276 lba = get_unaligned_be32(&fsg->cmnd[2]);
@@ -1581,7 +1578,7 @@ static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1581 } 1578 }
1582 1579
1583 memset(buf, 0, 8); 1580 memset(buf, 0, 8);
1584 buf[0] = (mod_data.cdrom ? TYPE_CDROM : TYPE_DISK); 1581 buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
1585 if (mod_data.removable) 1582 if (mod_data.removable)
1586 buf[1] = 0x80; 1583 buf[1] = 0x80;
1587 buf[2] = 2; // ANSI SCSI level 2 1584 buf[2] = 2; // ANSI SCSI level 2
@@ -1750,11 +1747,11 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1750 * The only variable value is the WriteProtect bit. We will fill in 1747 * The only variable value is the WriteProtect bit. We will fill in
1751 * the mode data length later. */ 1748 * the mode data length later. */
1752 memset(buf, 0, 8); 1749 memset(buf, 0, 8);
1753 if (mscmnd == SC_MODE_SENSE_6) { 1750 if (mscmnd == MODE_SENSE) {
1754 buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA 1751 buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
1755 buf += 4; 1752 buf += 4;
1756 limit = 255; 1753 limit = 255;
1757 } else { // SC_MODE_SENSE_10 1754 } else { // MODE_SENSE_10
1758 buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA 1755 buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
1759 buf += 8; 1756 buf += 8;
1760 limit = 65535; // Should really be mod_data.buflen 1757 limit = 65535; // Should really be mod_data.buflen
@@ -1794,7 +1791,7 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1794 } 1791 }
1795 1792
1796 /* Store the mode data length */ 1793 /* Store the mode data length */
1797 if (mscmnd == SC_MODE_SENSE_6) 1794 if (mscmnd == MODE_SENSE)
1798 buf0[0] = len - 1; 1795 buf0[0] = len - 1;
1799 else 1796 else
1800 put_unaligned_be16(len - 2, buf0); 1797 put_unaligned_be16(len - 2, buf0);
@@ -2319,7 +2316,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2319 /* Check the LUN */ 2316 /* Check the LUN */
2320 if (fsg->lun >= 0 && fsg->lun < fsg->nluns) { 2317 if (fsg->lun >= 0 && fsg->lun < fsg->nluns) {
2321 fsg->curlun = curlun = &fsg->luns[fsg->lun]; 2318 fsg->curlun = curlun = &fsg->luns[fsg->lun];
2322 if (fsg->cmnd[0] != SC_REQUEST_SENSE) { 2319 if (fsg->cmnd[0] != REQUEST_SENSE) {
2323 curlun->sense_data = SS_NO_SENSE; 2320 curlun->sense_data = SS_NO_SENSE;
2324 curlun->sense_data_info = 0; 2321 curlun->sense_data_info = 0;
2325 curlun->info_valid = 0; 2322 curlun->info_valid = 0;
@@ -2330,8 +2327,8 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2330 2327
2331 /* INQUIRY and REQUEST SENSE commands are explicitly allowed 2328 /* INQUIRY and REQUEST SENSE commands are explicitly allowed
2332 * to use unsupported LUNs; all others may not. */ 2329 * to use unsupported LUNs; all others may not. */
2333 if (fsg->cmnd[0] != SC_INQUIRY && 2330 if (fsg->cmnd[0] != INQUIRY &&
2334 fsg->cmnd[0] != SC_REQUEST_SENSE) { 2331 fsg->cmnd[0] != REQUEST_SENSE) {
2335 DBG(fsg, "unsupported LUN %d\n", fsg->lun); 2332 DBG(fsg, "unsupported LUN %d\n", fsg->lun);
2336 return -EINVAL; 2333 return -EINVAL;
2337 } 2334 }
@@ -2340,8 +2337,8 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2340 /* If a unit attention condition exists, only INQUIRY and 2337 /* If a unit attention condition exists, only INQUIRY and
2341 * REQUEST SENSE commands are allowed; anything else must fail. */ 2338 * REQUEST SENSE commands are allowed; anything else must fail. */
2342 if (curlun && curlun->unit_attention_data != SS_NO_SENSE && 2339 if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
2343 fsg->cmnd[0] != SC_INQUIRY && 2340 fsg->cmnd[0] != INQUIRY &&
2344 fsg->cmnd[0] != SC_REQUEST_SENSE) { 2341 fsg->cmnd[0] != REQUEST_SENSE) {
2345 curlun->sense_data = curlun->unit_attention_data; 2342 curlun->sense_data = curlun->unit_attention_data;
2346 curlun->unit_attention_data = SS_NO_SENSE; 2343 curlun->unit_attention_data = SS_NO_SENSE;
2347 return -EINVAL; 2344 return -EINVAL;
@@ -2391,7 +2388,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2391 down_read(&fsg->filesem); // We're using the backing file 2388 down_read(&fsg->filesem); // We're using the backing file
2392 switch (fsg->cmnd[0]) { 2389 switch (fsg->cmnd[0]) {
2393 2390
2394 case SC_INQUIRY: 2391 case INQUIRY:
2395 fsg->data_size_from_cmnd = fsg->cmnd[4]; 2392 fsg->data_size_from_cmnd = fsg->cmnd[4];
2396 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, 2393 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
2397 (1<<4), 0, 2394 (1<<4), 0,
@@ -2399,7 +2396,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2399 reply = do_inquiry(fsg, bh); 2396 reply = do_inquiry(fsg, bh);
2400 break; 2397 break;
2401 2398
2402 case SC_MODE_SELECT_6: 2399 case MODE_SELECT:
2403 fsg->data_size_from_cmnd = fsg->cmnd[4]; 2400 fsg->data_size_from_cmnd = fsg->cmnd[4];
2404 if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST, 2401 if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
2405 (1<<1) | (1<<4), 0, 2402 (1<<1) | (1<<4), 0,
@@ -2407,7 +2404,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2407 reply = do_mode_select(fsg, bh); 2404 reply = do_mode_select(fsg, bh);
2408 break; 2405 break;
2409 2406
2410 case SC_MODE_SELECT_10: 2407 case MODE_SELECT_10:
2411 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2408 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
2412 if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST, 2409 if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
2413 (1<<1) | (3<<7), 0, 2410 (1<<1) | (3<<7), 0,
@@ -2415,7 +2412,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2415 reply = do_mode_select(fsg, bh); 2412 reply = do_mode_select(fsg, bh);
2416 break; 2413 break;
2417 2414
2418 case SC_MODE_SENSE_6: 2415 case MODE_SENSE:
2419 fsg->data_size_from_cmnd = fsg->cmnd[4]; 2416 fsg->data_size_from_cmnd = fsg->cmnd[4];
2420 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, 2417 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
2421 (1<<1) | (1<<2) | (1<<4), 0, 2418 (1<<1) | (1<<2) | (1<<4), 0,
@@ -2423,7 +2420,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2423 reply = do_mode_sense(fsg, bh); 2420 reply = do_mode_sense(fsg, bh);
2424 break; 2421 break;
2425 2422
2426 case SC_MODE_SENSE_10: 2423 case MODE_SENSE_10:
2427 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2424 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
2428 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, 2425 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
2429 (1<<1) | (1<<2) | (3<<7), 0, 2426 (1<<1) | (1<<2) | (3<<7), 0,
@@ -2431,7 +2428,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2431 reply = do_mode_sense(fsg, bh); 2428 reply = do_mode_sense(fsg, bh);
2432 break; 2429 break;
2433 2430
2434 case SC_PREVENT_ALLOW_MEDIUM_REMOVAL: 2431 case ALLOW_MEDIUM_REMOVAL:
2435 fsg->data_size_from_cmnd = 0; 2432 fsg->data_size_from_cmnd = 0;
2436 if ((reply = check_command(fsg, 6, DATA_DIR_NONE, 2433 if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
2437 (1<<4), 0, 2434 (1<<4), 0,
@@ -2439,7 +2436,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2439 reply = do_prevent_allow(fsg); 2436 reply = do_prevent_allow(fsg);
2440 break; 2437 break;
2441 2438
2442 case SC_READ_6: 2439 case READ_6:
2443 i = fsg->cmnd[4]; 2440 i = fsg->cmnd[4];
2444 fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; 2441 fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2445 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, 2442 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
@@ -2448,7 +2445,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2448 reply = do_read(fsg); 2445 reply = do_read(fsg);
2449 break; 2446 break;
2450 2447
2451 case SC_READ_10: 2448 case READ_10:
2452 fsg->data_size_from_cmnd = 2449 fsg->data_size_from_cmnd =
2453 get_unaligned_be16(&fsg->cmnd[7]) << 9; 2450 get_unaligned_be16(&fsg->cmnd[7]) << 9;
2454 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, 2451 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
@@ -2457,7 +2454,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2457 reply = do_read(fsg); 2454 reply = do_read(fsg);
2458 break; 2455 break;
2459 2456
2460 case SC_READ_12: 2457 case READ_12:
2461 fsg->data_size_from_cmnd = 2458 fsg->data_size_from_cmnd =
2462 get_unaligned_be32(&fsg->cmnd[6]) << 9; 2459 get_unaligned_be32(&fsg->cmnd[6]) << 9;
2463 if ((reply = check_command(fsg, 12, DATA_DIR_TO_HOST, 2460 if ((reply = check_command(fsg, 12, DATA_DIR_TO_HOST,
@@ -2466,7 +2463,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2466 reply = do_read(fsg); 2463 reply = do_read(fsg);
2467 break; 2464 break;
2468 2465
2469 case SC_READ_CAPACITY: 2466 case READ_CAPACITY:
2470 fsg->data_size_from_cmnd = 8; 2467 fsg->data_size_from_cmnd = 8;
2471 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, 2468 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
2472 (0xf<<2) | (1<<8), 1, 2469 (0xf<<2) | (1<<8), 1,
@@ -2474,7 +2471,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2474 reply = do_read_capacity(fsg, bh); 2471 reply = do_read_capacity(fsg, bh);
2475 break; 2472 break;
2476 2473
2477 case SC_READ_HEADER: 2474 case READ_HEADER:
2478 if (!mod_data.cdrom) 2475 if (!mod_data.cdrom)
2479 goto unknown_cmnd; 2476 goto unknown_cmnd;
2480 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2477 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
@@ -2484,7 +2481,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2484 reply = do_read_header(fsg, bh); 2481 reply = do_read_header(fsg, bh);
2485 break; 2482 break;
2486 2483
2487 case SC_READ_TOC: 2484 case READ_TOC:
2488 if (!mod_data.cdrom) 2485 if (!mod_data.cdrom)
2489 goto unknown_cmnd; 2486 goto unknown_cmnd;
2490 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2487 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
@@ -2494,7 +2491,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2494 reply = do_read_toc(fsg, bh); 2491 reply = do_read_toc(fsg, bh);
2495 break; 2492 break;
2496 2493
2497 case SC_READ_FORMAT_CAPACITIES: 2494 case READ_FORMAT_CAPACITIES:
2498 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]); 2495 fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
2499 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST, 2496 if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
2500 (3<<7), 1, 2497 (3<<7), 1,
@@ -2502,7 +2499,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2502 reply = do_read_format_capacities(fsg, bh); 2499 reply = do_read_format_capacities(fsg, bh);
2503 break; 2500 break;
2504 2501
2505 case SC_REQUEST_SENSE: 2502 case REQUEST_SENSE:
2506 fsg->data_size_from_cmnd = fsg->cmnd[4]; 2503 fsg->data_size_from_cmnd = fsg->cmnd[4];
2507 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST, 2504 if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
2508 (1<<4), 0, 2505 (1<<4), 0,
@@ -2510,7 +2507,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2510 reply = do_request_sense(fsg, bh); 2507 reply = do_request_sense(fsg, bh);
2511 break; 2508 break;
2512 2509
2513 case SC_START_STOP_UNIT: 2510 case START_STOP:
2514 fsg->data_size_from_cmnd = 0; 2511 fsg->data_size_from_cmnd = 0;
2515 if ((reply = check_command(fsg, 6, DATA_DIR_NONE, 2512 if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
2516 (1<<1) | (1<<4), 0, 2513 (1<<1) | (1<<4), 0,
@@ -2518,7 +2515,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2518 reply = do_start_stop(fsg); 2515 reply = do_start_stop(fsg);
2519 break; 2516 break;
2520 2517
2521 case SC_SYNCHRONIZE_CACHE: 2518 case SYNCHRONIZE_CACHE:
2522 fsg->data_size_from_cmnd = 0; 2519 fsg->data_size_from_cmnd = 0;
2523 if ((reply = check_command(fsg, 10, DATA_DIR_NONE, 2520 if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
2524 (0xf<<2) | (3<<7), 1, 2521 (0xf<<2) | (3<<7), 1,
@@ -2526,7 +2523,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2526 reply = do_synchronize_cache(fsg); 2523 reply = do_synchronize_cache(fsg);
2527 break; 2524 break;
2528 2525
2529 case SC_TEST_UNIT_READY: 2526 case TEST_UNIT_READY:
2530 fsg->data_size_from_cmnd = 0; 2527 fsg->data_size_from_cmnd = 0;
2531 reply = check_command(fsg, 6, DATA_DIR_NONE, 2528 reply = check_command(fsg, 6, DATA_DIR_NONE,
2532 0, 1, 2529 0, 1,
@@ -2535,7 +2532,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2535 2532
2536 /* Although optional, this command is used by MS-Windows. We 2533 /* Although optional, this command is used by MS-Windows. We
2537 * support a minimal version: BytChk must be 0. */ 2534 * support a minimal version: BytChk must be 0. */
2538 case SC_VERIFY: 2535 case VERIFY:
2539 fsg->data_size_from_cmnd = 0; 2536 fsg->data_size_from_cmnd = 0;
2540 if ((reply = check_command(fsg, 10, DATA_DIR_NONE, 2537 if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
2541 (1<<1) | (0xf<<2) | (3<<7), 1, 2538 (1<<1) | (0xf<<2) | (3<<7), 1,
@@ -2543,7 +2540,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2543 reply = do_verify(fsg); 2540 reply = do_verify(fsg);
2544 break; 2541 break;
2545 2542
2546 case SC_WRITE_6: 2543 case WRITE_6:
2547 i = fsg->cmnd[4]; 2544 i = fsg->cmnd[4];
2548 fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; 2545 fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2549 if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST, 2546 if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
@@ -2552,7 +2549,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2552 reply = do_write(fsg); 2549 reply = do_write(fsg);
2553 break; 2550 break;
2554 2551
2555 case SC_WRITE_10: 2552 case WRITE_10:
2556 fsg->data_size_from_cmnd = 2553 fsg->data_size_from_cmnd =
2557 get_unaligned_be16(&fsg->cmnd[7]) << 9; 2554 get_unaligned_be16(&fsg->cmnd[7]) << 9;
2558 if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST, 2555 if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
@@ -2561,7 +2558,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2561 reply = do_write(fsg); 2558 reply = do_write(fsg);
2562 break; 2559 break;
2563 2560
2564 case SC_WRITE_12: 2561 case WRITE_12:
2565 fsg->data_size_from_cmnd = 2562 fsg->data_size_from_cmnd =
2566 get_unaligned_be32(&fsg->cmnd[6]) << 9; 2563 get_unaligned_be32(&fsg->cmnd[6]) << 9;
2567 if ((reply = check_command(fsg, 12, DATA_DIR_FROM_HOST, 2564 if ((reply = check_command(fsg, 12, DATA_DIR_FROM_HOST,
@@ -2574,10 +2571,10 @@ static int do_scsi_command(struct fsg_dev *fsg)
2574 * They don't mean much in this setting. It's left as an exercise 2571 * They don't mean much in this setting. It's left as an exercise
2575 * for anyone interested to implement RESERVE and RELEASE in terms 2572 * for anyone interested to implement RESERVE and RELEASE in terms
2576 * of Posix locks. */ 2573 * of Posix locks. */
2577 case SC_FORMAT_UNIT: 2574 case FORMAT_UNIT:
2578 case SC_RELEASE: 2575 case RELEASE:
2579 case SC_RESERVE: 2576 case RESERVE:
2580 case SC_SEND_DIAGNOSTIC: 2577 case SEND_DIAGNOSTIC:
2581 // Fall through 2578 // Fall through
2582 2579
2583 default: 2580 default:
@@ -3178,6 +3175,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3178 for (i = 0; i < fsg->nluns; ++i) { 3175 for (i = 0; i < fsg->nluns; ++i) {
3179 curlun = &fsg->luns[i]; 3176 curlun = &fsg->luns[i];
3180 if (curlun->registered) { 3177 if (curlun->registered) {
3178 device_remove_file(&curlun->dev, &dev_attr_nofua);
3181 device_remove_file(&curlun->dev, &dev_attr_ro); 3179 device_remove_file(&curlun->dev, &dev_attr_ro);
3182 device_remove_file(&curlun->dev, &dev_attr_file); 3180 device_remove_file(&curlun->dev, &dev_attr_file);
3183 fsg_lun_close(curlun); 3181 fsg_lun_close(curlun);
@@ -3213,7 +3211,6 @@ static int __init check_parameters(struct fsg_dev *fsg)
3213{ 3211{
3214 int prot; 3212 int prot;
3215 int gcnum; 3213 int gcnum;
3216 int i;
3217 3214
3218 /* Store the default values */ 3215 /* Store the default values */
3219 mod_data.transport_type = USB_PR_BULK; 3216 mod_data.transport_type = USB_PR_BULK;
@@ -3309,45 +3306,29 @@ static int __init check_parameters(struct fsg_dev *fsg)
3309 if ((*ch < '0' || *ch > '9') && 3306 if ((*ch < '0' || *ch > '9') &&
3310 (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */ 3307 (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
3311 WARNING(fsg, 3308 WARNING(fsg,
3312 "Invalid serial string character: %c; " 3309 "Invalid serial string character: %c\n",
3313 "Failing back to default\n",
3314 *ch); 3310 *ch);
3315 goto fill_serial; 3311 goto no_serial;
3316 } 3312 }
3317 } 3313 }
3318 if (len > 126 || 3314 if (len > 126 ||
3319 (mod_data.transport_type == USB_PR_BULK && len < 12) || 3315 (mod_data.transport_type == USB_PR_BULK && len < 12) ||
3320 (mod_data.transport_type != USB_PR_BULK && len > 12)) { 3316 (mod_data.transport_type != USB_PR_BULK && len > 12)) {
3321 WARNING(fsg, 3317 WARNING(fsg, "Invalid serial string length!\n");
3322 "Invalid serial string length; " 3318 goto no_serial;
3323 "Failing back to default\n");
3324 goto fill_serial;
3325 } 3319 }
3326 fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial; 3320 fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
3327 } else { 3321 } else {
3328 WARNING(fsg, 3322 WARNING(fsg, "No serial-number string provided!\n");
3329 "Userspace failed to provide serial number; " 3323 no_serial:
3330 "Failing back to default\n"); 3324 device_desc.iSerialNumber = 0;
3331fill_serial:
3332 /* Serial number not specified or invalid, make our own.
3333 * We just encode it from the driver version string,
3334 * 12 characters to comply with both CB[I] and BBB spec.
3335 * Warning : Two devices running the same kernel will have
3336 * the same fallback serial number. */
3337 for (i = 0; i < 12; i += 2) {
3338 unsigned char c = DRIVER_VERSION[i / 2];
3339
3340 if (!c)
3341 break;
3342 sprintf(&fsg_string_serial[i], "%02X", c);
3343 }
3344 } 3325 }
3345 3326
3346 return 0; 3327 return 0;
3347} 3328}
3348 3329
3349 3330
3350static int __ref fsg_bind(struct usb_gadget *gadget) 3331static int __init fsg_bind(struct usb_gadget *gadget)
3351{ 3332{
3352 struct fsg_dev *fsg = the_fsg; 3333 struct fsg_dev *fsg = the_fsg;
3353 int rc; 3334 int rc;
@@ -3607,7 +3588,6 @@ static struct usb_gadget_driver fsg_driver = {
3607 .speed = USB_SPEED_FULL, 3588 .speed = USB_SPEED_FULL,
3608#endif 3589#endif
3609 .function = (char *) fsg_string_product, 3590 .function = (char *) fsg_string_product,
3610 .bind = fsg_bind,
3611 .unbind = fsg_unbind, 3591 .unbind = fsg_unbind,
3612 .disconnect = fsg_disconnect, 3592 .disconnect = fsg_disconnect,
3613 .setup = fsg_setup, 3593 .setup = fsg_setup,
@@ -3649,7 +3629,7 @@ static int __init fsg_init(void)
3649 if ((rc = fsg_alloc()) != 0) 3629 if ((rc = fsg_alloc()) != 0)
3650 return rc; 3630 return rc;
3651 fsg = the_fsg; 3631 fsg = the_fsg;
3652 if ((rc = usb_gadget_register_driver(&fsg_driver)) != 0) 3632 if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
3653 kref_put(&fsg->ref, fsg_release); 3633 kref_put(&fsg->ref, fsg_release);
3654 return rc; 3634 return rc;
3655} 3635}
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index eafa6d2c5ed7..5bdbfe619853 100644
--- a/drivers/usb/gadget/fsl_mxc_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -22,6 +22,10 @@
22static struct clk *mxc_ahb_clk; 22static struct clk *mxc_ahb_clk;
23static struct clk *mxc_usb_clk; 23static struct clk *mxc_usb_clk;
24 24
25/* workaround ENGcm09152 for i.MX35 */
26#define USBPHYCTRL_OTGBASE_OFFSET 0x608
27#define USBPHYCTRL_EVDO (1 << 23)
28
25int fsl_udc_clk_init(struct platform_device *pdev) 29int fsl_udc_clk_init(struct platform_device *pdev)
26{ 30{
27 struct fsl_usb2_platform_data *pdata; 31 struct fsl_usb2_platform_data *pdata;
@@ -84,6 +88,17 @@ eenahb:
84void fsl_udc_clk_finalize(struct platform_device *pdev) 88void fsl_udc_clk_finalize(struct platform_device *pdev)
85{ 89{
86 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 90 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
91#if defined(CONFIG_ARCH_MX35)
92 unsigned int v;
93
94 /* workaround ENGcm09152 for i.MX35 */
95 if (pdata->workaround & FLS_USB2_WORKAROUND_ENGCM09152) {
96 v = readl(MX35_IO_ADDRESS(MX35_OTG_BASE_ADDR +
97 USBPHYCTRL_OTGBASE_OFFSET));
98 writel(v | USBPHYCTRL_EVDO, MX35_IO_ADDRESS(MX35_OTG_BASE_ADDR +
99 USBPHYCTRL_OTGBASE_OFFSET));
100 }
101#endif
87 102
88 /* ULPI transceivers don't need usbpll */ 103 /* ULPI transceivers don't need usbpll */
89 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) { 104 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index a5ea2c1d8c93..792d5ef40137 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2302,9 +2302,10 @@ static irqreturn_t qe_udc_irq(int irq, void *_udc)
2302} 2302}
2303 2303
2304/*------------------------------------------------------------------------- 2304/*-------------------------------------------------------------------------
2305 Gadget driver register and unregister. 2305 Gadget driver probe and unregister.
2306 --------------------------------------------------------------------------*/ 2306 --------------------------------------------------------------------------*/
2307int usb_gadget_register_driver(struct usb_gadget_driver *driver) 2307int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2308 int (*bind)(struct usb_gadget *))
2308{ 2309{
2309 int retval; 2310 int retval;
2310 unsigned long flags = 0; 2311 unsigned long flags = 0;
@@ -2315,8 +2316,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2315 2316
2316 if (!driver || (driver->speed != USB_SPEED_FULL 2317 if (!driver || (driver->speed != USB_SPEED_FULL
2317 && driver->speed != USB_SPEED_HIGH) 2318 && driver->speed != USB_SPEED_HIGH)
2318 || !driver->bind || !driver->disconnect 2319 || !bind || !driver->disconnect || !driver->setup)
2319 || !driver->setup)
2320 return -EINVAL; 2320 return -EINVAL;
2321 2321
2322 if (udc_controller->driver) 2322 if (udc_controller->driver)
@@ -2332,7 +2332,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2332 udc_controller->gadget.speed = (enum usb_device_speed)(driver->speed); 2332 udc_controller->gadget.speed = (enum usb_device_speed)(driver->speed);
2333 spin_unlock_irqrestore(&udc_controller->lock, flags); 2333 spin_unlock_irqrestore(&udc_controller->lock, flags);
2334 2334
2335 retval = driver->bind(&udc_controller->gadget); 2335 retval = bind(&udc_controller->gadget);
2336 if (retval) { 2336 if (retval) {
2337 dev_err(udc_controller->dev, "bind to %s --> %d", 2337 dev_err(udc_controller->dev, "bind to %s --> %d",
2338 driver->driver.name, retval); 2338 driver->driver.name, retval);
@@ -2353,7 +2353,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2353 udc_controller->gadget.name, driver->driver.name); 2353 udc_controller->gadget.name, driver->driver.name);
2354 return 0; 2354 return 0;
2355} 2355}
2356EXPORT_SYMBOL(usb_gadget_register_driver); 2356EXPORT_SYMBOL(usb_gadget_probe_driver);
2357 2357
2358int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2358int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2359{ 2359{
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 08a9a62a39e3..c16b402a876b 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1765,7 +1765,8 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
1765 * Hook to gadget drivers 1765 * Hook to gadget drivers
1766 * Called by initialization code of gadget drivers 1766 * Called by initialization code of gadget drivers
1767*----------------------------------------------------------------*/ 1767*----------------------------------------------------------------*/
1768int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1768int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1769 int (*bind)(struct usb_gadget *))
1769{ 1770{
1770 int retval = -ENODEV; 1771 int retval = -ENODEV;
1771 unsigned long flags = 0; 1772 unsigned long flags = 0;
@@ -1775,8 +1776,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1775 1776
1776 if (!driver || (driver->speed != USB_SPEED_FULL 1777 if (!driver || (driver->speed != USB_SPEED_FULL
1777 && driver->speed != USB_SPEED_HIGH) 1778 && driver->speed != USB_SPEED_HIGH)
1778 || !driver->bind || !driver->disconnect 1779 || !bind || !driver->disconnect || !driver->setup)
1779 || !driver->setup)
1780 return -EINVAL; 1780 return -EINVAL;
1781 1781
1782 if (udc_controller->driver) 1782 if (udc_controller->driver)
@@ -1792,7 +1792,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1792 spin_unlock_irqrestore(&udc_controller->lock, flags); 1792 spin_unlock_irqrestore(&udc_controller->lock, flags);
1793 1793
1794 /* bind udc driver to gadget driver */ 1794 /* bind udc driver to gadget driver */
1795 retval = driver->bind(&udc_controller->gadget); 1795 retval = bind(&udc_controller->gadget);
1796 if (retval) { 1796 if (retval) {
1797 VDBG("bind to %s --> %d", driver->driver.name, retval); 1797 VDBG("bind to %s --> %d", driver->driver.name, retval);
1798 udc_controller->gadget.dev.driver = NULL; 1798 udc_controller->gadget.dev.driver = NULL;
@@ -1814,7 +1814,7 @@ out:
1814 retval); 1814 retval);
1815 return retval; 1815 return retval;
1816} 1816}
1817EXPORT_SYMBOL(usb_gadget_register_driver); 1817EXPORT_SYMBOL(usb_gadget_probe_driver);
1818 1818
1819/* Disconnect from gadget driver */ 1819/* Disconnect from gadget driver */
1820int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1820int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index a9474f8d5325..af75e3620849 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -52,9 +52,8 @@ MODULE_DESCRIPTION(DRIVER_DESC);
52MODULE_AUTHOR("Michal Nazarewicz"); 52MODULE_AUTHOR("Michal Nazarewicz");
53MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
54 54
55 55#define GFS_VENDOR_ID 0x1d6b /* Linux Foundation */
56static unsigned short gfs_vendor_id = 0x0525; /* XXX NetChip */ 56#define GFS_PRODUCT_ID 0x0105 /* FunctionFS Gadget */
57static unsigned short gfs_product_id = 0xa4ac; /* XXX */
58 57
59static struct usb_device_descriptor gfs_dev_desc = { 58static struct usb_device_descriptor gfs_dev_desc = {
60 .bLength = sizeof gfs_dev_desc, 59 .bLength = sizeof gfs_dev_desc,
@@ -63,29 +62,16 @@ static struct usb_device_descriptor gfs_dev_desc = {
63 .bcdUSB = cpu_to_le16(0x0200), 62 .bcdUSB = cpu_to_le16(0x0200),
64 .bDeviceClass = USB_CLASS_PER_INTERFACE, 63 .bDeviceClass = USB_CLASS_PER_INTERFACE,
65 64
66 /* Vendor and product id can be overridden by module parameters. */ 65 .idVendor = cpu_to_le16(GFS_VENDOR_ID),
67 /* .idVendor = cpu_to_le16(gfs_vendor_id), */ 66 .idProduct = cpu_to_le16(GFS_PRODUCT_ID),
68 /* .idProduct = cpu_to_le16(gfs_product_id), */
69 /* .bcdDevice = f(hardware) */
70 /* .iManufacturer = DYNAMIC */
71 /* .iProduct = DYNAMIC */
72 /* NO SERIAL NUMBER */
73 .bNumConfigurations = 1,
74}; 67};
75 68
76#define GFS_MODULE_PARAM_DESC(name, field) \ 69module_param_named(bDeviceClass, gfs_dev_desc.bDeviceClass, byte, 0644);
77 MODULE_PARM_DESC(name, "Value of the " #field " field of the device descriptor sent to the host. Takes effect only prior to the user-space driver registering to the FunctionFS.") 70MODULE_PARM_DESC(bDeviceClass, "USB Device class");
78 71module_param_named(bDeviceSubClass, gfs_dev_desc.bDeviceSubClass, byte, 0644);
79module_param_named(usb_class, gfs_dev_desc.bDeviceClass, byte, 0644); 72MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass");
80GFS_MODULE_PARAM_DESC(usb_class, bDeviceClass); 73module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
81module_param_named(usb_subclass, gfs_dev_desc.bDeviceSubClass, byte, 0644); 74MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol");
82GFS_MODULE_PARAM_DESC(usb_subclass, bDeviceSubClass);
83module_param_named(usb_protocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
84GFS_MODULE_PARAM_DESC(usb_protocol, bDeviceProtocol);
85module_param_named(usb_vendor, gfs_vendor_id, ushort, 0644);
86GFS_MODULE_PARAM_DESC(usb_vendor, idVendor);
87module_param_named(usb_product, gfs_product_id, ushort, 0644);
88GFS_MODULE_PARAM_DESC(usb_product, idProduct);
89 75
90 76
91 77
@@ -95,8 +81,10 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = {
95 .bLength = sizeof(struct usb_otg_descriptor), 81 .bLength = sizeof(struct usb_otg_descriptor),
96 .bDescriptorType = USB_DT_OTG, 82 .bDescriptorType = USB_DT_OTG,
97 83
98 /* REVISIT SRP-only hardware is possible, although 84 /*
99 * it would not be called "OTG" ... */ 85 * REVISIT SRP-only hardware is possible, although
86 * it would not be called "OTG" ...
87 */
100 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 88 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
101 }, 89 },
102 90
@@ -105,19 +93,7 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = {
105 93
106/* string IDs are assigned dynamically */ 94/* string IDs are assigned dynamically */
107 95
108enum {
109 GFS_STRING_MANUFACTURER_IDX,
110 GFS_STRING_PRODUCT_IDX,
111 GFS_STRING_FIRST_CONFIG_IDX,
112};
113
114static char gfs_manufacturer[50];
115static const char gfs_driver_desc[] = DRIVER_DESC;
116static const char gfs_short_name[] = DRIVER_NAME;
117
118static struct usb_string gfs_strings[] = { 96static struct usb_string gfs_strings[] = {
119 [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer,
120 [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc,
121#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 97#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
122 { .s = "FunctionFS + RNDIS" }, 98 { .s = "FunctionFS + RNDIS" },
123#endif 99#endif
@@ -168,11 +144,11 @@ static int gfs_unbind(struct usb_composite_dev *cdev);
168static int gfs_do_config(struct usb_configuration *c); 144static int gfs_do_config(struct usb_configuration *c);
169 145
170static struct usb_composite_driver gfs_driver = { 146static struct usb_composite_driver gfs_driver = {
171 .name = gfs_short_name, 147 .name = DRIVER_NAME,
172 .dev = &gfs_dev_desc, 148 .dev = &gfs_dev_desc,
173 .strings = gfs_dev_strings, 149 .strings = gfs_dev_strings,
174 .bind = gfs_bind,
175 .unbind = gfs_unbind, 150 .unbind = gfs_unbind,
151 .iProduct = DRIVER_DESC,
176}; 152};
177 153
178 154
@@ -210,7 +186,7 @@ static int functionfs_ready_callback(struct ffs_data *ffs)
210 return -EBUSY; 186 return -EBUSY;
211 187
212 gfs_ffs_data = ffs; 188 gfs_ffs_data = ffs;
213 ret = usb_composite_register(&gfs_driver); 189 ret = usb_composite_probe(&gfs_driver, gfs_bind);
214 if (unlikely(ret < 0)) 190 if (unlikely(ret < 0))
215 clear_bit(0, &gfs_registered); 191 clear_bit(0, &gfs_registered);
216 return ret; 192 return ret;
@@ -245,20 +221,10 @@ static int gfs_bind(struct usb_composite_dev *cdev)
245 if (unlikely(ret < 0)) 221 if (unlikely(ret < 0))
246 goto error_quick; 222 goto error_quick;
247 223
248 gfs_dev_desc.idVendor = cpu_to_le16(gfs_vendor_id);
249 gfs_dev_desc.idProduct = cpu_to_le16(gfs_product_id);
250
251 snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s",
252 init_utsname()->sysname, init_utsname()->release,
253 cdev->gadget->name);
254
255 ret = usb_string_ids_tab(cdev, gfs_strings); 224 ret = usb_string_ids_tab(cdev, gfs_strings);
256 if (unlikely(ret < 0)) 225 if (unlikely(ret < 0))
257 goto error; 226 goto error;
258 227
259 gfs_dev_desc.iManufacturer = gfs_strings[GFS_STRING_MANUFACTURER_IDX].id;
260 gfs_dev_desc.iProduct = gfs_strings[GFS_STRING_PRODUCT_IDX].id;
261
262 ret = functionfs_bind(gfs_ffs_data, cdev); 228 ret = functionfs_bind(gfs_ffs_data, cdev);
263 if (unlikely(ret < 0)) 229 if (unlikely(ret < 0))
264 goto error; 230 goto error;
@@ -266,14 +232,12 @@ static int gfs_bind(struct usb_composite_dev *cdev)
266 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { 232 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) {
267 struct gfs_configuration *c = gfs_configurations + i; 233 struct gfs_configuration *c = gfs_configurations + i;
268 234
269 ret = GFS_STRING_FIRST_CONFIG_IDX + i; 235 c->c.label = gfs_strings[i].s;
270 c->c.label = gfs_strings[ret].s; 236 c->c.iConfiguration = gfs_strings[i].id;
271 c->c.iConfiguration = gfs_strings[ret].id;
272 c->c.bind = gfs_do_config;
273 c->c.bConfigurationValue = 1 + i; 237 c->c.bConfigurationValue = 1 + i;
274 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; 238 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER;
275 239
276 ret = usb_add_config(cdev, &c->c); 240 ret = usb_add_config(cdev, &c->c, gfs_do_config);
277 if (unlikely(ret < 0)) 241 if (unlikely(ret < 0))
278 goto error_unbind; 242 goto error_unbind;
279 } 243 }
@@ -293,13 +257,14 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
293{ 257{
294 ENTER(); 258 ENTER();
295 259
296 /* We may have been called in an error recovery frem 260 /*
261 * We may have been called in an error recovery from
297 * composite_bind() after gfs_unbind() failure so we need to 262 * composite_bind() after gfs_unbind() failure so we need to
298 * check if gfs_ffs_data is not NULL since gfs_bind() handles 263 * check if gfs_ffs_data is not NULL since gfs_bind() handles
299 * all error recovery itself. I'd rather we werent called 264 * all error recovery itself. I'd rather we werent called
300 * from composite on orror recovery, but what you're gonna 265 * from composite on orror recovery, but what you're gonna
301 * do...? */ 266 * do...?
302 267 */
303 if (gfs_ffs_data) { 268 if (gfs_ffs_data) {
304 gether_cleanup(); 269 gether_cleanup();
305 functionfs_unbind(gfs_ffs_data); 270 functionfs_unbind(gfs_ffs_data);
@@ -334,14 +299,16 @@ static int gfs_do_config(struct usb_configuration *c)
334 if (unlikely(ret < 0)) 299 if (unlikely(ret < 0))
335 return ret; 300 return ret;
336 301
337 /* After previous do_configs there may be some invalid 302 /*
303 * After previous do_configs there may be some invalid
338 * pointers in c->interface array. This happens every time 304 * pointers in c->interface array. This happens every time
339 * a user space function with fewer interfaces than a user 305 * a user space function with fewer interfaces than a user
340 * space function that was run before the new one is run. The 306 * space function that was run before the new one is run. The
341 * compasit's set_config() assumes that if there is no more 307 * compasit's set_config() assumes that if there is no more
342 * then MAX_CONFIG_INTERFACES interfaces in a configuration 308 * then MAX_CONFIG_INTERFACES interfaces in a configuration
343 * then there is a NULL pointer after the last interface in 309 * then there is a NULL pointer after the last interface in
344 * c->interface array. We need to make sure this is true. */ 310 * c->interface array. We need to make sure this is true.
311 */
345 if (c->next_interface_id < ARRAY_SIZE(c->interface)) 312 if (c->next_interface_id < ARRAY_SIZE(c->interface))
346 c->interface[c->next_interface_id] = NULL; 313 c->interface[c->next_interface_id] = NULL;
347 314
@@ -350,10 +317,12 @@ static int gfs_do_config(struct usb_configuration *c)
350 317
351 318
352#ifdef CONFIG_USB_FUNCTIONFS_ETH 319#ifdef CONFIG_USB_FUNCTIONFS_ETH
320
353static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 321static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
354{ 322{
355 return can_support_ecm(c->cdev->gadget) 323 return can_support_ecm(c->cdev->gadget)
356 ? ecm_bind_config(c, ethaddr) 324 ? ecm_bind_config(c, ethaddr)
357 : geth_bind_config(c, ethaddr); 325 : geth_bind_config(c, ethaddr);
358} 326}
327
359#endif 328#endif
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 1b413a5cc3f6..0ab7e141d494 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -1157,7 +1157,7 @@ fail:
1157/* 1157/*
1158 * Creates an output endpoint, and initializes output ports. 1158 * Creates an output endpoint, and initializes output ports.
1159 */ 1159 */
1160static int __ref gmidi_bind(struct usb_gadget *gadget) 1160static int __init gmidi_bind(struct usb_gadget *gadget)
1161{ 1161{
1162 struct gmidi_device *dev; 1162 struct gmidi_device *dev;
1163 struct usb_ep *in_ep, *out_ep; 1163 struct usb_ep *in_ep, *out_ep;
@@ -1292,7 +1292,6 @@ static void gmidi_resume(struct usb_gadget *gadget)
1292static struct usb_gadget_driver gmidi_driver = { 1292static struct usb_gadget_driver gmidi_driver = {
1293 .speed = USB_SPEED_FULL, 1293 .speed = USB_SPEED_FULL,
1294 .function = (char *)longname, 1294 .function = (char *)longname,
1295 .bind = gmidi_bind,
1296 .unbind = gmidi_unbind, 1295 .unbind = gmidi_unbind,
1297 1296
1298 .setup = gmidi_setup, 1297 .setup = gmidi_setup,
@@ -1309,7 +1308,7 @@ static struct usb_gadget_driver gmidi_driver = {
1309 1308
1310static int __init gmidi_init(void) 1309static int __init gmidi_init(void)
1311{ 1310{
1312 return usb_gadget_register_driver(&gmidi_driver); 1311 return usb_gadget_probe_driver(&gmidi_driver, gmidi_bind);
1313} 1312}
1314module_init(gmidi_init); 1313module_init(gmidi_init);
1315 1314
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 1088d08c7ed8..48a760220baf 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1343,14 +1343,15 @@ static struct goku_udc *the_controller;
1343 * disconnect is reported. then a host may connect again, or 1343 * disconnect is reported. then a host may connect again, or
1344 * the driver might get unbound. 1344 * the driver might get unbound.
1345 */ 1345 */
1346int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1346int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1347 int (*bind)(struct usb_gadget *))
1347{ 1348{
1348 struct goku_udc *dev = the_controller; 1349 struct goku_udc *dev = the_controller;
1349 int retval; 1350 int retval;
1350 1351
1351 if (!driver 1352 if (!driver
1352 || driver->speed < USB_SPEED_FULL 1353 || driver->speed < USB_SPEED_FULL
1353 || !driver->bind 1354 || !bind
1354 || !driver->disconnect 1355 || !driver->disconnect
1355 || !driver->setup) 1356 || !driver->setup)
1356 return -EINVAL; 1357 return -EINVAL;
@@ -1363,7 +1364,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1363 driver->driver.bus = NULL; 1364 driver->driver.bus = NULL;
1364 dev->driver = driver; 1365 dev->driver = driver;
1365 dev->gadget.dev.driver = &driver->driver; 1366 dev->gadget.dev.driver = &driver->driver;
1366 retval = driver->bind(&dev->gadget); 1367 retval = bind(&dev->gadget);
1367 if (retval) { 1368 if (retval) {
1368 DBG(dev, "bind to driver %s --> error %d\n", 1369 DBG(dev, "bind to driver %s --> error %d\n",
1369 driver->driver.name, retval); 1370 driver->driver.name, retval);
@@ -1380,7 +1381,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1380 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name); 1381 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name);
1381 return 0; 1382 return 0;
1382} 1383}
1383EXPORT_SYMBOL(usb_gadget_register_driver); 1384EXPORT_SYMBOL(usb_gadget_probe_driver);
1384 1385
1385static void 1386static void
1386stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) 1387stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
@@ -1744,7 +1745,8 @@ static void goku_remove(struct pci_dev *pdev)
1744 pci_resource_len (pdev, 0)); 1745 pci_resource_len (pdev, 0));
1745 if (dev->enabled) 1746 if (dev->enabled)
1746 pci_disable_device(pdev); 1747 pci_disable_device(pdev);
1747 device_unregister(&dev->gadget.dev); 1748 if (dev->registered)
1749 device_unregister(&dev->gadget.dev);
1748 1750
1749 pci_set_drvdata(pdev, NULL); 1751 pci_set_drvdata(pdev, NULL);
1750 dev->regs = NULL; 1752 dev->regs = NULL;
@@ -1774,7 +1776,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1774 if (!pdev->irq) { 1776 if (!pdev->irq) {
1775 printk(KERN_ERR "Check PCI %s IRQ setup!\n", pci_name(pdev)); 1777 printk(KERN_ERR "Check PCI %s IRQ setup!\n", pci_name(pdev));
1776 retval = -ENODEV; 1778 retval = -ENODEV;
1777 goto done; 1779 goto err;
1778 } 1780 }
1779 1781
1780 /* alloc, and start init */ 1782 /* alloc, and start init */
@@ -1782,7 +1784,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1782 if (dev == NULL){ 1784 if (dev == NULL){
1783 pr_debug("enomem %s\n", pci_name(pdev)); 1785 pr_debug("enomem %s\n", pci_name(pdev));
1784 retval = -ENOMEM; 1786 retval = -ENOMEM;
1785 goto done; 1787 goto err;
1786 } 1788 }
1787 1789
1788 spin_lock_init(&dev->lock); 1790 spin_lock_init(&dev->lock);
@@ -1800,7 +1802,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1800 retval = pci_enable_device(pdev); 1802 retval = pci_enable_device(pdev);
1801 if (retval < 0) { 1803 if (retval < 0) {
1802 DBG(dev, "can't enable, %d\n", retval); 1804 DBG(dev, "can't enable, %d\n", retval);
1803 goto done; 1805 goto err;
1804 } 1806 }
1805 dev->enabled = 1; 1807 dev->enabled = 1;
1806 1808
@@ -1809,7 +1811,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1809 if (!request_mem_region(resource, len, driver_name)) { 1811 if (!request_mem_region(resource, len, driver_name)) {
1810 DBG(dev, "controller already in use\n"); 1812 DBG(dev, "controller already in use\n");
1811 retval = -EBUSY; 1813 retval = -EBUSY;
1812 goto done; 1814 goto err;
1813 } 1815 }
1814 dev->got_region = 1; 1816 dev->got_region = 1;
1815 1817
@@ -1817,7 +1819,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1817 if (base == NULL) { 1819 if (base == NULL) {
1818 DBG(dev, "can't map memory\n"); 1820 DBG(dev, "can't map memory\n");
1819 retval = -EFAULT; 1821 retval = -EFAULT;
1820 goto done; 1822 goto err;
1821 } 1823 }
1822 dev->regs = (struct goku_udc_regs __iomem *) base; 1824 dev->regs = (struct goku_udc_regs __iomem *) base;
1823 1825
@@ -1833,7 +1835,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1833 driver_name, dev) != 0) { 1835 driver_name, dev) != 0) {
1834 DBG(dev, "request interrupt %d failed\n", pdev->irq); 1836 DBG(dev, "request interrupt %d failed\n", pdev->irq);
1835 retval = -EBUSY; 1837 retval = -EBUSY;
1836 goto done; 1838 goto err;
1837 } 1839 }
1838 dev->got_irq = 1; 1840 dev->got_irq = 1;
1839 if (use_dma) 1841 if (use_dma)
@@ -1844,13 +1846,16 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1844 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev); 1846 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev);
1845#endif 1847#endif
1846 1848
1847 /* done */
1848 the_controller = dev; 1849 the_controller = dev;
1849 retval = device_register(&dev->gadget.dev); 1850 retval = device_register(&dev->gadget.dev);
1850 if (retval == 0) 1851 if (retval) {
1851 return 0; 1852 put_device(&dev->gadget.dev);
1853 goto err;
1854 }
1855 dev->registered = 1;
1856 return 0;
1852 1857
1853done: 1858err:
1854 if (dev) 1859 if (dev)
1855 goku_remove (pdev); 1860 goku_remove (pdev);
1856 return retval; 1861 return retval;
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index 735495bf8411..2523e54097bd 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -127,7 +127,7 @@ static struct usb_gadget_strings *dev_strings[] = {
127 127
128/****************************** Configurations ******************************/ 128/****************************** Configurations ******************************/
129 129
130static int __ref do_config(struct usb_configuration *c) 130static int __init do_config(struct usb_configuration *c)
131{ 131{
132 struct hidg_func_node *e; 132 struct hidg_func_node *e;
133 int func = 0, status = 0; 133 int func = 0, status = 0;
@@ -148,7 +148,6 @@ static int __ref do_config(struct usb_configuration *c)
148 148
149static struct usb_configuration config_driver = { 149static struct usb_configuration config_driver = {
150 .label = "HID Gadget", 150 .label = "HID Gadget",
151 .bind = do_config,
152 .bConfigurationValue = 1, 151 .bConfigurationValue = 1,
153 /* .iConfiguration = DYNAMIC */ 152 /* .iConfiguration = DYNAMIC */
154 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 153 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -156,7 +155,7 @@ static struct usb_configuration config_driver = {
156 155
157/****************************** Gadget Bind ******************************/ 156/****************************** Gadget Bind ******************************/
158 157
159static int __ref hid_bind(struct usb_composite_dev *cdev) 158static int __init hid_bind(struct usb_composite_dev *cdev)
160{ 159{
161 struct usb_gadget *gadget = cdev->gadget; 160 struct usb_gadget *gadget = cdev->gadget;
162 struct list_head *tmp; 161 struct list_head *tmp;
@@ -201,7 +200,7 @@ static int __ref hid_bind(struct usb_composite_dev *cdev)
201 device_desc.iProduct = status; 200 device_desc.iProduct = status;
202 201
203 /* register our configuration */ 202 /* register our configuration */
204 status = usb_add_config(cdev, &config_driver); 203 status = usb_add_config(cdev, &config_driver, do_config);
205 if (status < 0) 204 if (status < 0)
206 return status; 205 return status;
207 206
@@ -256,7 +255,6 @@ static struct usb_composite_driver hidg_driver = {
256 .name = "g_hid", 255 .name = "g_hid",
257 .dev = &device_desc, 256 .dev = &device_desc,
258 .strings = dev_strings, 257 .strings = dev_strings,
259 .bind = hid_bind,
260 .unbind = __exit_p(hid_unbind), 258 .unbind = __exit_p(hid_unbind),
261}; 259};
262 260
@@ -282,7 +280,7 @@ static int __init hidg_init(void)
282 if (status < 0) 280 if (status < 0)
283 return status; 281 return status;
284 282
285 status = usb_composite_register(&hidg_driver); 283 status = usb_composite_probe(&hidg_driver, hid_bind);
286 if (status < 0) 284 if (status < 0)
287 platform_driver_unregister(&hidg_plat_driver); 285 platform_driver_unregister(&hidg_plat_driver);
288 286
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index e743122fcd93..ed0266462c57 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1319,14 +1319,15 @@ static struct imx_udc_struct controller = {
1319 * USB gadged driver functions 1319 * USB gadged driver functions
1320 ******************************************************************************* 1320 *******************************************************************************
1321 */ 1321 */
1322int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1322int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1323 int (*bind)(struct usb_gadget *))
1323{ 1324{
1324 struct imx_udc_struct *imx_usb = &controller; 1325 struct imx_udc_struct *imx_usb = &controller;
1325 int retval; 1326 int retval;
1326 1327
1327 if (!driver 1328 if (!driver
1328 || driver->speed < USB_SPEED_FULL 1329 || driver->speed < USB_SPEED_FULL
1329 || !driver->bind 1330 || !bind
1330 || !driver->disconnect 1331 || !driver->disconnect
1331 || !driver->setup) 1332 || !driver->setup)
1332 return -EINVAL; 1333 return -EINVAL;
@@ -1342,7 +1343,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1342 retval = device_add(&imx_usb->gadget.dev); 1343 retval = device_add(&imx_usb->gadget.dev);
1343 if (retval) 1344 if (retval)
1344 goto fail; 1345 goto fail;
1345 retval = driver->bind(&imx_usb->gadget); 1346 retval = bind(&imx_usb->gadget);
1346 if (retval) { 1347 if (retval) {
1347 D_ERR(imx_usb->dev, "<%s> bind to driver %s --> error %d\n", 1348 D_ERR(imx_usb->dev, "<%s> bind to driver %s --> error %d\n",
1348 __func__, driver->driver.name, retval); 1349 __func__, driver->driver.name, retval);
@@ -1362,7 +1363,7 @@ fail:
1362 imx_usb->gadget.dev.driver = NULL; 1363 imx_usb->gadget.dev.driver = NULL;
1363 return retval; 1364 return retval;
1364} 1365}
1365EXPORT_SYMBOL(usb_gadget_register_driver); 1366EXPORT_SYMBOL(usb_gadget_probe_driver);
1366 1367
1367int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1368int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1368{ 1369{
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 3f1d771c8be5..d1d72d946b04 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1774,7 +1774,6 @@ static struct usb_gadget_driver gadgetfs_driver = {
1774 .speed = USB_SPEED_FULL, 1774 .speed = USB_SPEED_FULL,
1775#endif 1775#endif
1776 .function = (char *) driver_desc, 1776 .function = (char *) driver_desc,
1777 .bind = gadgetfs_bind,
1778 .unbind = gadgetfs_unbind, 1777 .unbind = gadgetfs_unbind,
1779 .setup = gadgetfs_setup, 1778 .setup = gadgetfs_setup,
1780 .disconnect = gadgetfs_disconnect, 1779 .disconnect = gadgetfs_disconnect,
@@ -1797,7 +1796,6 @@ static int gadgetfs_probe (struct usb_gadget *gadget)
1797 1796
1798static struct usb_gadget_driver probe_driver = { 1797static struct usb_gadget_driver probe_driver = {
1799 .speed = USB_SPEED_HIGH, 1798 .speed = USB_SPEED_HIGH,
1800 .bind = gadgetfs_probe,
1801 .unbind = gadgetfs_nop, 1799 .unbind = gadgetfs_nop,
1802 .setup = (void *)gadgetfs_nop, 1800 .setup = (void *)gadgetfs_nop,
1803 .disconnect = gadgetfs_nop, 1801 .disconnect = gadgetfs_nop,
@@ -1907,7 +1905,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1907 1905
1908 /* triggers gadgetfs_bind(); then we can enumerate. */ 1906 /* triggers gadgetfs_bind(); then we can enumerate. */
1909 spin_unlock_irq (&dev->lock); 1907 spin_unlock_irq (&dev->lock);
1910 value = usb_gadget_register_driver (&gadgetfs_driver); 1908 value = usb_gadget_probe_driver(&gadgetfs_driver, gadgetfs_bind);
1911 if (value != 0) { 1909 if (value != 0) {
1912 kfree (dev->buf); 1910 kfree (dev->buf);
1913 dev->buf = NULL; 1911 dev->buf = NULL;
@@ -2046,7 +2044,7 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
2046 return -ESRCH; 2044 return -ESRCH;
2047 2045
2048 /* fake probe to determine $CHIP */ 2046 /* fake probe to determine $CHIP */
2049 (void) usb_gadget_register_driver (&probe_driver); 2047 (void) usb_gadget_probe_driver(&probe_driver, gadgetfs_probe);
2050 if (!CHIP) 2048 if (!CHIP)
2051 return -ENODEV; 2049 return -ENODEV;
2052 2050
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index c2d2a201f84b..b8ec954c0692 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -19,7 +19,7 @@
19 19
20 20
21/* #undef DEBUG */ 21/* #undef DEBUG */
22/* #undef VERBOSE */ 22/* #undef VERBOSE_DEBUG */
23 23
24#if defined(CONFIG_USB_LANGWELL_OTG) 24#if defined(CONFIG_USB_LANGWELL_OTG)
25#define OTG_TRANSCEIVER 25#define OTG_TRANSCEIVER
@@ -77,141 +77,110 @@ langwell_ep0_desc = {
77/*-------------------------------------------------------------------------*/ 77/*-------------------------------------------------------------------------*/
78/* debugging */ 78/* debugging */
79 79
80#ifdef DEBUG 80#ifdef VERBOSE_DEBUG
81#define DBG(dev, fmt, args...) \
82 pr_debug("%s %s: " fmt , driver_name, \
83 pci_name(dev->pdev), ## args)
84#else
85#define DBG(dev, fmt, args...) \
86 do { } while (0)
87#endif /* DEBUG */
88
89
90#ifdef VERBOSE
91#define VDBG DBG
92#else
93#define VDBG(dev, fmt, args...) \
94 do { } while (0)
95#endif /* VERBOSE */
96
97
98#define ERROR(dev, fmt, args...) \
99 pr_err("%s %s: " fmt , driver_name, \
100 pci_name(dev->pdev), ## args)
101
102#define WARNING(dev, fmt, args...) \
103 pr_warning("%s %s: " fmt , driver_name, \
104 pci_name(dev->pdev), ## args)
105
106#define INFO(dev, fmt, args...) \
107 pr_info("%s %s: " fmt , driver_name, \
108 pci_name(dev->pdev), ## args)
109
110
111#ifdef VERBOSE
112static inline void print_all_registers(struct langwell_udc *dev) 81static inline void print_all_registers(struct langwell_udc *dev)
113{ 82{
114 int i; 83 int i;
115 84
116 /* Capability Registers */ 85 /* Capability Registers */
117 printk(KERN_DEBUG "Capability Registers (offset: " 86 dev_dbg(&dev->pdev->dev,
118 "0x%04x, length: 0x%08x)\n", 87 "Capability Registers (offset: 0x%04x, length: 0x%08x)\n",
119 CAP_REG_OFFSET, 88 CAP_REG_OFFSET, (u32)sizeof(struct langwell_cap_regs));
120 (u32)sizeof(struct langwell_cap_regs)); 89 dev_dbg(&dev->pdev->dev, "caplength=0x%02x\n",
121 printk(KERN_DEBUG "caplength=0x%02x\n",
122 readb(&dev->cap_regs->caplength)); 90 readb(&dev->cap_regs->caplength));
123 printk(KERN_DEBUG "hciversion=0x%04x\n", 91 dev_dbg(&dev->pdev->dev, "hciversion=0x%04x\n",
124 readw(&dev->cap_regs->hciversion)); 92 readw(&dev->cap_regs->hciversion));
125 printk(KERN_DEBUG "hcsparams=0x%08x\n", 93 dev_dbg(&dev->pdev->dev, "hcsparams=0x%08x\n",
126 readl(&dev->cap_regs->hcsparams)); 94 readl(&dev->cap_regs->hcsparams));
127 printk(KERN_DEBUG "hccparams=0x%08x\n", 95 dev_dbg(&dev->pdev->dev, "hccparams=0x%08x\n",
128 readl(&dev->cap_regs->hccparams)); 96 readl(&dev->cap_regs->hccparams));
129 printk(KERN_DEBUG "dciversion=0x%04x\n", 97 dev_dbg(&dev->pdev->dev, "dciversion=0x%04x\n",
130 readw(&dev->cap_regs->dciversion)); 98 readw(&dev->cap_regs->dciversion));
131 printk(KERN_DEBUG "dccparams=0x%08x\n", 99 dev_dbg(&dev->pdev->dev, "dccparams=0x%08x\n",
132 readl(&dev->cap_regs->dccparams)); 100 readl(&dev->cap_regs->dccparams));
133 101
134 /* Operational Registers */ 102 /* Operational Registers */
135 printk(KERN_DEBUG "Operational Registers (offset: " 103 dev_dbg(&dev->pdev->dev,
136 "0x%04x, length: 0x%08x)\n", 104 "Operational Registers (offset: 0x%04x, length: 0x%08x)\n",
137 OP_REG_OFFSET, 105 OP_REG_OFFSET, (u32)sizeof(struct langwell_op_regs));
138 (u32)sizeof(struct langwell_op_regs)); 106 dev_dbg(&dev->pdev->dev, "extsts=0x%08x\n",
139 printk(KERN_DEBUG "extsts=0x%08x\n",
140 readl(&dev->op_regs->extsts)); 107 readl(&dev->op_regs->extsts));
141 printk(KERN_DEBUG "extintr=0x%08x\n", 108 dev_dbg(&dev->pdev->dev, "extintr=0x%08x\n",
142 readl(&dev->op_regs->extintr)); 109 readl(&dev->op_regs->extintr));
143 printk(KERN_DEBUG "usbcmd=0x%08x\n", 110 dev_dbg(&dev->pdev->dev, "usbcmd=0x%08x\n",
144 readl(&dev->op_regs->usbcmd)); 111 readl(&dev->op_regs->usbcmd));
145 printk(KERN_DEBUG "usbsts=0x%08x\n", 112 dev_dbg(&dev->pdev->dev, "usbsts=0x%08x\n",
146 readl(&dev->op_regs->usbsts)); 113 readl(&dev->op_regs->usbsts));
147 printk(KERN_DEBUG "usbintr=0x%08x\n", 114 dev_dbg(&dev->pdev->dev, "usbintr=0x%08x\n",
148 readl(&dev->op_regs->usbintr)); 115 readl(&dev->op_regs->usbintr));
149 printk(KERN_DEBUG "frindex=0x%08x\n", 116 dev_dbg(&dev->pdev->dev, "frindex=0x%08x\n",
150 readl(&dev->op_regs->frindex)); 117 readl(&dev->op_regs->frindex));
151 printk(KERN_DEBUG "ctrldssegment=0x%08x\n", 118 dev_dbg(&dev->pdev->dev, "ctrldssegment=0x%08x\n",
152 readl(&dev->op_regs->ctrldssegment)); 119 readl(&dev->op_regs->ctrldssegment));
153 printk(KERN_DEBUG "deviceaddr=0x%08x\n", 120 dev_dbg(&dev->pdev->dev, "deviceaddr=0x%08x\n",
154 readl(&dev->op_regs->deviceaddr)); 121 readl(&dev->op_regs->deviceaddr));
155 printk(KERN_DEBUG "endpointlistaddr=0x%08x\n", 122 dev_dbg(&dev->pdev->dev, "endpointlistaddr=0x%08x\n",
156 readl(&dev->op_regs->endpointlistaddr)); 123 readl(&dev->op_regs->endpointlistaddr));
157 printk(KERN_DEBUG "ttctrl=0x%08x\n", 124 dev_dbg(&dev->pdev->dev, "ttctrl=0x%08x\n",
158 readl(&dev->op_regs->ttctrl)); 125 readl(&dev->op_regs->ttctrl));
159 printk(KERN_DEBUG "burstsize=0x%08x\n", 126 dev_dbg(&dev->pdev->dev, "burstsize=0x%08x\n",
160 readl(&dev->op_regs->burstsize)); 127 readl(&dev->op_regs->burstsize));
161 printk(KERN_DEBUG "txfilltuning=0x%08x\n", 128 dev_dbg(&dev->pdev->dev, "txfilltuning=0x%08x\n",
162 readl(&dev->op_regs->txfilltuning)); 129 readl(&dev->op_regs->txfilltuning));
163 printk(KERN_DEBUG "txttfilltuning=0x%08x\n", 130 dev_dbg(&dev->pdev->dev, "txttfilltuning=0x%08x\n",
164 readl(&dev->op_regs->txttfilltuning)); 131 readl(&dev->op_regs->txttfilltuning));
165 printk(KERN_DEBUG "ic_usb=0x%08x\n", 132 dev_dbg(&dev->pdev->dev, "ic_usb=0x%08x\n",
166 readl(&dev->op_regs->ic_usb)); 133 readl(&dev->op_regs->ic_usb));
167 printk(KERN_DEBUG "ulpi_viewport=0x%08x\n", 134 dev_dbg(&dev->pdev->dev, "ulpi_viewport=0x%08x\n",
168 readl(&dev->op_regs->ulpi_viewport)); 135 readl(&dev->op_regs->ulpi_viewport));
169 printk(KERN_DEBUG "configflag=0x%08x\n", 136 dev_dbg(&dev->pdev->dev, "configflag=0x%08x\n",
170 readl(&dev->op_regs->configflag)); 137 readl(&dev->op_regs->configflag));
171 printk(KERN_DEBUG "portsc1=0x%08x\n", 138 dev_dbg(&dev->pdev->dev, "portsc1=0x%08x\n",
172 readl(&dev->op_regs->portsc1)); 139 readl(&dev->op_regs->portsc1));
173 printk(KERN_DEBUG "devlc=0x%08x\n", 140 dev_dbg(&dev->pdev->dev, "devlc=0x%08x\n",
174 readl(&dev->op_regs->devlc)); 141 readl(&dev->op_regs->devlc));
175 printk(KERN_DEBUG "otgsc=0x%08x\n", 142 dev_dbg(&dev->pdev->dev, "otgsc=0x%08x\n",
176 readl(&dev->op_regs->otgsc)); 143 readl(&dev->op_regs->otgsc));
177 printk(KERN_DEBUG "usbmode=0x%08x\n", 144 dev_dbg(&dev->pdev->dev, "usbmode=0x%08x\n",
178 readl(&dev->op_regs->usbmode)); 145 readl(&dev->op_regs->usbmode));
179 printk(KERN_DEBUG "endptnak=0x%08x\n", 146 dev_dbg(&dev->pdev->dev, "endptnak=0x%08x\n",
180 readl(&dev->op_regs->endptnak)); 147 readl(&dev->op_regs->endptnak));
181 printk(KERN_DEBUG "endptnaken=0x%08x\n", 148 dev_dbg(&dev->pdev->dev, "endptnaken=0x%08x\n",
182 readl(&dev->op_regs->endptnaken)); 149 readl(&dev->op_regs->endptnaken));
183 printk(KERN_DEBUG "endptsetupstat=0x%08x\n", 150 dev_dbg(&dev->pdev->dev, "endptsetupstat=0x%08x\n",
184 readl(&dev->op_regs->endptsetupstat)); 151 readl(&dev->op_regs->endptsetupstat));
185 printk(KERN_DEBUG "endptprime=0x%08x\n", 152 dev_dbg(&dev->pdev->dev, "endptprime=0x%08x\n",
186 readl(&dev->op_regs->endptprime)); 153 readl(&dev->op_regs->endptprime));
187 printk(KERN_DEBUG "endptflush=0x%08x\n", 154 dev_dbg(&dev->pdev->dev, "endptflush=0x%08x\n",
188 readl(&dev->op_regs->endptflush)); 155 readl(&dev->op_regs->endptflush));
189 printk(KERN_DEBUG "endptstat=0x%08x\n", 156 dev_dbg(&dev->pdev->dev, "endptstat=0x%08x\n",
190 readl(&dev->op_regs->endptstat)); 157 readl(&dev->op_regs->endptstat));
191 printk(KERN_DEBUG "endptcomplete=0x%08x\n", 158 dev_dbg(&dev->pdev->dev, "endptcomplete=0x%08x\n",
192 readl(&dev->op_regs->endptcomplete)); 159 readl(&dev->op_regs->endptcomplete));
193 160
194 for (i = 0; i < dev->ep_max / 2; i++) { 161 for (i = 0; i < dev->ep_max / 2; i++) {
195 printk(KERN_DEBUG "endptctrl[%d]=0x%08x\n", 162 dev_dbg(&dev->pdev->dev, "endptctrl[%d]=0x%08x\n",
196 i, readl(&dev->op_regs->endptctrl[i])); 163 i, readl(&dev->op_regs->endptctrl[i]));
197 } 164 }
198} 165}
199#endif /* VERBOSE */ 166#else
167
168#define print_all_registers(dev) do { } while (0)
169
170#endif /* VERBOSE_DEBUG */
200 171
201 172
202/*-------------------------------------------------------------------------*/ 173/*-------------------------------------------------------------------------*/
203 174
204#define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") 175#define is_in(ep) (((ep)->ep_num == 0) ? ((ep)->dev->ep0_dir == \
176 USB_DIR_IN) : (usb_endpoint_dir_in((ep)->desc)))
205 177
206#define is_in(ep) (((ep)->ep_num == 0) ? ((ep)->dev->ep0_dir == \ 178#define DIR_STRING(ep) (is_in(ep) ? "in" : "out")
207 USB_DIR_IN) : ((ep)->desc->bEndpointAddress \
208 & USB_DIR_IN) == USB_DIR_IN)
209 179
210 180
211#ifdef DEBUG 181static char *type_string(const struct usb_endpoint_descriptor *desc)
212static char *type_string(u8 bmAttributes)
213{ 182{
214 switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { 183 switch (usb_endpoint_type(desc)) {
215 case USB_ENDPOINT_XFER_BULK: 184 case USB_ENDPOINT_XFER_BULK:
216 return "bulk"; 185 return "bulk";
217 case USB_ENDPOINT_XFER_ISOC: 186 case USB_ENDPOINT_XFER_ISOC:
@@ -222,7 +191,6 @@ static char *type_string(u8 bmAttributes)
222 191
223 return "control"; 192 return "control";
224} 193}
225#endif
226 194
227 195
228/* configure endpoint control registers */ 196/* configure endpoint control registers */
@@ -233,7 +201,7 @@ static void ep_reset(struct langwell_ep *ep, unsigned char ep_num,
233 u32 endptctrl; 201 u32 endptctrl;
234 202
235 dev = ep->dev; 203 dev = ep->dev;
236 VDBG(dev, "---> %s()\n", __func__); 204 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
237 205
238 endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); 206 endptctrl = readl(&dev->op_regs->endptctrl[ep_num]);
239 if (is_in) { /* TX */ 207 if (is_in) { /* TX */
@@ -250,7 +218,7 @@ static void ep_reset(struct langwell_ep *ep, unsigned char ep_num,
250 218
251 writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); 219 writel(endptctrl, &dev->op_regs->endptctrl[ep_num]);
252 220
253 VDBG(dev, "<--- %s()\n", __func__); 221 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
254} 222}
255 223
256 224
@@ -260,7 +228,7 @@ static void ep0_reset(struct langwell_udc *dev)
260 struct langwell_ep *ep; 228 struct langwell_ep *ep;
261 int i; 229 int i;
262 230
263 VDBG(dev, "---> %s()\n", __func__); 231 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
264 232
265 /* ep0 in and out */ 233 /* ep0 in and out */
266 for (i = 0; i < 2; i++) { 234 for (i = 0; i < 2; i++) {
@@ -274,17 +242,18 @@ static void ep0_reset(struct langwell_udc *dev)
274 ep->dqh->dqh_ios = 1; 242 ep->dqh->dqh_ios = 1;
275 ep->dqh->dqh_mpl = EP0_MAX_PKT_SIZE; 243 ep->dqh->dqh_mpl = EP0_MAX_PKT_SIZE;
276 244
277 /* FIXME: enable ep0-in HW zero length termination select */ 245 /* enable ep0-in HW zero length termination select */
278 if (is_in(ep)) 246 if (is_in(ep))
279 ep->dqh->dqh_zlt = 0; 247 ep->dqh->dqh_zlt = 0;
280 ep->dqh->dqh_mult = 0; 248 ep->dqh->dqh_mult = 0;
281 249
250 ep->dqh->dtd_next = DTD_TERM;
251
282 /* configure ep0 control registers */ 252 /* configure ep0 control registers */
283 ep_reset(&dev->ep[0], 0, i, USB_ENDPOINT_XFER_CONTROL); 253 ep_reset(&dev->ep[0], 0, i, USB_ENDPOINT_XFER_CONTROL);
284 } 254 }
285 255
286 VDBG(dev, "<--- %s()\n", __func__); 256 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
287 return;
288} 257}
289 258
290 259
@@ -300,12 +269,12 @@ static int langwell_ep_enable(struct usb_ep *_ep,
300 struct langwell_ep *ep; 269 struct langwell_ep *ep;
301 u16 max = 0; 270 u16 max = 0;
302 unsigned long flags; 271 unsigned long flags;
303 int retval = 0; 272 int i, retval = 0;
304 unsigned char zlt, ios = 0, mult = 0; 273 unsigned char zlt, ios = 0, mult = 0;
305 274
306 ep = container_of(_ep, struct langwell_ep, ep); 275 ep = container_of(_ep, struct langwell_ep, ep);
307 dev = ep->dev; 276 dev = ep->dev;
308 VDBG(dev, "---> %s()\n", __func__); 277 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
309 278
310 if (!_ep || !desc || ep->desc 279 if (!_ep || !desc || ep->desc
311 || desc->bDescriptorType != USB_DT_ENDPOINT) 280 || desc->bDescriptorType != USB_DT_ENDPOINT)
@@ -326,7 +295,7 @@ static int langwell_ep_enable(struct usb_ep *_ep,
326 * sanity check type, direction, address, and then 295 * sanity check type, direction, address, and then
327 * initialize the endpoint capabilities fields in dQH 296 * initialize the endpoint capabilities fields in dQH
328 */ 297 */
329 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 298 switch (usb_endpoint_type(desc)) {
330 case USB_ENDPOINT_XFER_CONTROL: 299 case USB_ENDPOINT_XFER_CONTROL:
331 ios = 1; 300 ios = 1;
332 break; 301 break;
@@ -386,33 +355,36 @@ static int langwell_ep_enable(struct usb_ep *_ep,
386 355
387 spin_lock_irqsave(&dev->lock, flags); 356 spin_lock_irqsave(&dev->lock, flags);
388 357
389 /* configure endpoint capabilities in dQH */
390 ep->dqh->dqh_ios = ios;
391 ep->dqh->dqh_mpl = cpu_to_le16(max);
392 ep->dqh->dqh_zlt = zlt;
393 ep->dqh->dqh_mult = mult;
394
395 ep->ep.maxpacket = max; 358 ep->ep.maxpacket = max;
396 ep->desc = desc; 359 ep->desc = desc;
397 ep->stopped = 0; 360 ep->stopped = 0;
398 ep->ep_num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 361 ep->ep_num = usb_endpoint_num(desc);
399 362
400 /* ep_type */ 363 /* ep_type */
401 ep->ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 364 ep->ep_type = usb_endpoint_type(desc);
402 365
403 /* configure endpoint control registers */ 366 /* configure endpoint control registers */
404 ep_reset(ep, ep->ep_num, is_in(ep), ep->ep_type); 367 ep_reset(ep, ep->ep_num, is_in(ep), ep->ep_type);
405 368
406 DBG(dev, "enabled %s (ep%d%s-%s), max %04x\n", 369 /* configure endpoint capabilities in dQH */
370 i = ep->ep_num * 2 + is_in(ep);
371 ep->dqh = &dev->ep_dqh[i];
372 ep->dqh->dqh_ios = ios;
373 ep->dqh->dqh_mpl = cpu_to_le16(max);
374 ep->dqh->dqh_zlt = zlt;
375 ep->dqh->dqh_mult = mult;
376 ep->dqh->dtd_next = DTD_TERM;
377
378 dev_dbg(&dev->pdev->dev, "enabled %s (ep%d%s-%s), max %04x\n",
407 _ep->name, 379 _ep->name,
408 ep->ep_num, 380 ep->ep_num,
409 DIR_STRING(desc->bEndpointAddress), 381 DIR_STRING(ep),
410 type_string(desc->bmAttributes), 382 type_string(desc),
411 max); 383 max);
412 384
413 spin_unlock_irqrestore(&dev->lock, flags); 385 spin_unlock_irqrestore(&dev->lock, flags);
414done: 386done:
415 VDBG(dev, "<--- %s()\n", __func__); 387 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
416 return retval; 388 return retval;
417} 389}
418 390
@@ -428,7 +400,7 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
428 struct langwell_dtd *curr_dtd, *next_dtd; 400 struct langwell_dtd *curr_dtd, *next_dtd;
429 int i; 401 int i;
430 402
431 VDBG(dev, "---> %s()\n", __func__); 403 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
432 404
433 /* remove the req from ep->queue */ 405 /* remove the req from ep->queue */
434 list_del_init(&req->queue); 406 list_del_init(&req->queue);
@@ -448,7 +420,8 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
448 } 420 }
449 421
450 if (req->mapped) { 422 if (req->mapped) {
451 dma_unmap_single(&dev->pdev->dev, req->req.dma, req->req.length, 423 dma_unmap_single(&dev->pdev->dev,
424 req->req.dma, req->req.length,
452 is_in(ep) ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); 425 is_in(ep) ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
453 req->req.dma = DMA_ADDR_INVALID; 426 req->req.dma = DMA_ADDR_INVALID;
454 req->mapped = 0; 427 req->mapped = 0;
@@ -458,9 +431,10 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
458 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 431 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
459 432
460 if (status != -ESHUTDOWN) 433 if (status != -ESHUTDOWN)
461 DBG(dev, "complete %s, req %p, stat %d, len %u/%u\n", 434 dev_dbg(&dev->pdev->dev,
462 ep->ep.name, &req->req, status, 435 "complete %s, req %p, stat %d, len %u/%u\n",
463 req->req.actual, req->req.length); 436 ep->ep.name, &req->req, status,
437 req->req.actual, req->req.length);
464 438
465 /* don't modify queue heads during completion callback */ 439 /* don't modify queue heads during completion callback */
466 ep->stopped = 1; 440 ep->stopped = 1;
@@ -473,7 +447,7 @@ static void done(struct langwell_ep *ep, struct langwell_request *req,
473 spin_lock(&dev->lock); 447 spin_lock(&dev->lock);
474 ep->stopped = stopped; 448 ep->stopped = stopped;
475 449
476 VDBG(dev, "<--- %s()\n", __func__); 450 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
477} 451}
478 452
479 453
@@ -511,7 +485,7 @@ static int langwell_ep_disable(struct usb_ep *_ep)
511 485
512 ep = container_of(_ep, struct langwell_ep, ep); 486 ep = container_of(_ep, struct langwell_ep, ep);
513 dev = ep->dev; 487 dev = ep->dev;
514 VDBG(dev, "---> %s()\n", __func__); 488 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
515 489
516 if (!_ep || !ep->desc) 490 if (!_ep || !ep->desc)
517 return -EINVAL; 491 return -EINVAL;
@@ -535,8 +509,8 @@ static int langwell_ep_disable(struct usb_ep *_ep)
535 509
536 spin_unlock_irqrestore(&dev->lock, flags); 510 spin_unlock_irqrestore(&dev->lock, flags);
537 511
538 DBG(dev, "disabled %s\n", _ep->name); 512 dev_dbg(&dev->pdev->dev, "disabled %s\n", _ep->name);
539 VDBG(dev, "<--- %s()\n", __func__); 513 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
540 514
541 return 0; 515 return 0;
542} 516}
@@ -555,7 +529,7 @@ static struct usb_request *langwell_alloc_request(struct usb_ep *_ep,
555 529
556 ep = container_of(_ep, struct langwell_ep, ep); 530 ep = container_of(_ep, struct langwell_ep, ep);
557 dev = ep->dev; 531 dev = ep->dev;
558 VDBG(dev, "---> %s()\n", __func__); 532 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
559 533
560 req = kzalloc(sizeof(*req), gfp_flags); 534 req = kzalloc(sizeof(*req), gfp_flags);
561 if (!req) 535 if (!req)
@@ -564,8 +538,8 @@ static struct usb_request *langwell_alloc_request(struct usb_ep *_ep,
564 req->req.dma = DMA_ADDR_INVALID; 538 req->req.dma = DMA_ADDR_INVALID;
565 INIT_LIST_HEAD(&req->queue); 539 INIT_LIST_HEAD(&req->queue);
566 540
567 VDBG(dev, "alloc request for %s\n", _ep->name); 541 dev_vdbg(&dev->pdev->dev, "alloc request for %s\n", _ep->name);
568 VDBG(dev, "<--- %s()\n", __func__); 542 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
569 return &req->req; 543 return &req->req;
570} 544}
571 545
@@ -580,7 +554,7 @@ static void langwell_free_request(struct usb_ep *_ep,
580 554
581 ep = container_of(_ep, struct langwell_ep, ep); 555 ep = container_of(_ep, struct langwell_ep, ep);
582 dev = ep->dev; 556 dev = ep->dev;
583 VDBG(dev, "---> %s()\n", __func__); 557 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
584 558
585 if (!_ep || !_req) 559 if (!_ep || !_req)
586 return; 560 return;
@@ -591,8 +565,8 @@ static void langwell_free_request(struct usb_ep *_ep,
591 if (_req) 565 if (_req)
592 kfree(req); 566 kfree(req);
593 567
594 VDBG(dev, "free request for %s\n", _ep->name); 568 dev_vdbg(&dev->pdev->dev, "free request for %s\n", _ep->name);
595 VDBG(dev, "<--- %s()\n", __func__); 569 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
596} 570}
597 571
598 572
@@ -608,23 +582,24 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req)
608 struct langwell_udc *dev; 582 struct langwell_udc *dev;
609 583
610 dev = ep->dev; 584 dev = ep->dev;
611 VDBG(dev, "---> %s()\n", __func__); 585 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
612 586
613 i = ep->ep_num * 2 + is_in(ep); 587 i = ep->ep_num * 2 + is_in(ep);
614 dqh = &dev->ep_dqh[i]; 588 dqh = &dev->ep_dqh[i];
615 589
616 if (ep->ep_num) 590 if (ep->ep_num)
617 VDBG(dev, "%s\n", ep->name); 591 dev_vdbg(&dev->pdev->dev, "%s\n", ep->name);
618 else 592 else
619 /* ep0 */ 593 /* ep0 */
620 VDBG(dev, "%s-%s\n", ep->name, is_in(ep) ? "in" : "out"); 594 dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep));
621 595
622 VDBG(dev, "ep_dqh[%d] addr: 0x%08x\n", i, (u32)&(dev->ep_dqh[i])); 596 dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%08x\n",
597 i, (u32)&(dev->ep_dqh[i]));
623 598
624 bit_mask = is_in(ep) ? 599 bit_mask = is_in(ep) ?
625 (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num)); 600 (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num));
626 601
627 VDBG(dev, "bit_mask = 0x%08x\n", bit_mask); 602 dev_vdbg(&dev->pdev->dev, "bit_mask = 0x%08x\n", bit_mask);
628 603
629 /* check if the pipe is empty */ 604 /* check if the pipe is empty */
630 if (!(list_empty(&ep->queue))) { 605 if (!(list_empty(&ep->queue))) {
@@ -665,14 +640,17 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req)
665 /* clear active and halt bit */ 640 /* clear active and halt bit */
666 dtd_status = (u8) ~(DTD_STS_ACTIVE | DTD_STS_HALTED); 641 dtd_status = (u8) ~(DTD_STS_ACTIVE | DTD_STS_HALTED);
667 dqh->dtd_status &= dtd_status; 642 dqh->dtd_status &= dtd_status;
668 VDBG(dev, "dqh->dtd_status = 0x%x\n", dqh->dtd_status); 643 dev_vdbg(&dev->pdev->dev, "dqh->dtd_status = 0x%x\n", dqh->dtd_status);
644
645 /* ensure that updates to the dQH will occure before priming */
646 wmb();
669 647
670 /* write 1 to endptprime register to PRIME endpoint */ 648 /* write 1 to endptprime register to PRIME endpoint */
671 bit_mask = is_in(ep) ? (1 << (ep->ep_num + 16)) : (1 << ep->ep_num); 649 bit_mask = is_in(ep) ? (1 << (ep->ep_num + 16)) : (1 << ep->ep_num);
672 VDBG(dev, "endprime bit_mask = 0x%08x\n", bit_mask); 650 dev_vdbg(&dev->pdev->dev, "endprime bit_mask = 0x%08x\n", bit_mask);
673 writel(bit_mask, &dev->op_regs->endptprime); 651 writel(bit_mask, &dev->op_regs->endptprime);
674out: 652out:
675 VDBG(dev, "<--- %s()\n", __func__); 653 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
676 return 0; 654 return 0;
677} 655}
678 656
@@ -687,7 +665,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req,
687 int i; 665 int i;
688 666
689 dev = req->ep->dev; 667 dev = req->ep->dev;
690 VDBG(dev, "---> %s()\n", __func__); 668 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
691 669
692 /* the maximum transfer length, up to 16k bytes */ 670 /* the maximum transfer length, up to 16k bytes */
693 *length = min(req->req.length - req->req.actual, 671 *length = min(req->req.length - req->req.actual,
@@ -708,7 +686,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req,
708 686
709 /* fill in total bytes with transfer size */ 687 /* fill in total bytes with transfer size */
710 dtd->dtd_total = cpu_to_le16(*length); 688 dtd->dtd_total = cpu_to_le16(*length);
711 VDBG(dev, "dtd->dtd_total = %d\n", dtd->dtd_total); 689 dev_vdbg(&dev->pdev->dev, "dtd->dtd_total = %d\n", dtd->dtd_total);
712 690
713 /* set is_last flag if req->req.zero is set or not */ 691 /* set is_last flag if req->req.zero is set or not */
714 if (req->req.zero) { 692 if (req->req.zero) {
@@ -722,7 +700,7 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req,
722 *is_last = 0; 700 *is_last = 0;
723 701
724 if (*is_last == 0) 702 if (*is_last == 0)
725 VDBG(dev, "multi-dtd request!\n"); 703 dev_vdbg(&dev->pdev->dev, "multi-dtd request!\n");
726 704
727 /* set interrupt on complete bit for the last dTD */ 705 /* set interrupt on complete bit for the last dTD */
728 if (*is_last && !req->req.no_interrupt) 706 if (*is_last && !req->req.no_interrupt)
@@ -733,10 +711,12 @@ static struct langwell_dtd *build_dtd(struct langwell_request *req,
733 711
734 /* set the active bit of status field to 1 */ 712 /* set the active bit of status field to 1 */
735 dtd->dtd_status = DTD_STS_ACTIVE; 713 dtd->dtd_status = DTD_STS_ACTIVE;
736 VDBG(dev, "dtd->dtd_status = 0x%02x\n", dtd->dtd_status); 714 dev_vdbg(&dev->pdev->dev, "dtd->dtd_status = 0x%02x\n",
715 dtd->dtd_status);
737 716
738 VDBG(dev, "length = %d, dma addr= 0x%08x\n", *length, (int)*dma); 717 dev_vdbg(&dev->pdev->dev, "length = %d, dma addr= 0x%08x\n",
739 VDBG(dev, "<--- %s()\n", __func__); 718 *length, (int)*dma);
719 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
740 return dtd; 720 return dtd;
741} 721}
742 722
@@ -751,7 +731,7 @@ static int req_to_dtd(struct langwell_request *req)
751 dma_addr_t dma; 731 dma_addr_t dma;
752 732
753 dev = req->ep->dev; 733 dev = req->ep->dev;
754 VDBG(dev, "---> %s()\n", __func__); 734 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
755 do { 735 do {
756 dtd = build_dtd(req, &count, &dma, &is_last); 736 dtd = build_dtd(req, &count, &dma, &is_last);
757 if (dtd == NULL) 737 if (dtd == NULL)
@@ -773,7 +753,7 @@ static int req_to_dtd(struct langwell_request *req)
773 753
774 req->tail = dtd; 754 req->tail = dtd;
775 755
776 VDBG(dev, "<--- %s()\n", __func__); 756 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
777 return 0; 757 return 0;
778} 758}
779 759
@@ -803,9 +783,9 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
803 783
804 dev = ep->dev; 784 dev = ep->dev;
805 req->ep = ep; 785 req->ep = ep;
806 VDBG(dev, "---> %s()\n", __func__); 786 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
807 787
808 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 788 if (usb_endpoint_xfer_isoc(ep->desc)) {
809 if (req->req.length > ep->ep.maxpacket) 789 if (req->req.length > ep->ep.maxpacket)
810 return -EMSGSIZE; 790 return -EMSGSIZE;
811 is_iso = 1; 791 is_iso = 1;
@@ -818,7 +798,7 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
818 if (_req->dma == DMA_ADDR_INVALID) { 798 if (_req->dma == DMA_ADDR_INVALID) {
819 /* WORKAROUND: WARN_ON(size == 0) */ 799 /* WORKAROUND: WARN_ON(size == 0) */
820 if (_req->length == 0) { 800 if (_req->length == 0) {
821 VDBG(dev, "req->length: 0->1\n"); 801 dev_vdbg(&dev->pdev->dev, "req->length: 0->1\n");
822 zlflag = 1; 802 zlflag = 1;
823 _req->length++; 803 _req->length++;
824 } 804 }
@@ -827,24 +807,25 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
827 _req->buf, _req->length, 807 _req->buf, _req->length,
828 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 808 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
829 if (zlflag && (_req->length == 1)) { 809 if (zlflag && (_req->length == 1)) {
830 VDBG(dev, "req->length: 1->0\n"); 810 dev_vdbg(&dev->pdev->dev, "req->length: 1->0\n");
831 zlflag = 0; 811 zlflag = 0;
832 _req->length = 0; 812 _req->length = 0;
833 } 813 }
834 814
835 req->mapped = 1; 815 req->mapped = 1;
836 VDBG(dev, "req->mapped = 1\n"); 816 dev_vdbg(&dev->pdev->dev, "req->mapped = 1\n");
837 } else { 817 } else {
838 dma_sync_single_for_device(&dev->pdev->dev, 818 dma_sync_single_for_device(&dev->pdev->dev,
839 _req->dma, _req->length, 819 _req->dma, _req->length,
840 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 820 is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
841 req->mapped = 0; 821 req->mapped = 0;
842 VDBG(dev, "req->mapped = 0\n"); 822 dev_vdbg(&dev->pdev->dev, "req->mapped = 0\n");
843 } 823 }
844 824
845 DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08llx\n", 825 dev_dbg(&dev->pdev->dev,
846 _ep->name, 826 "%s queue req %p, len %u, buf %p, dma 0x%08x\n",
847 _req, _req->length, _req->buf, (unsigned long long)_req->dma); 827 _ep->name,
828 _req, _req->length, _req->buf, (int)_req->dma);
848 829
849 _req->status = -EINPROGRESS; 830 _req->status = -EINPROGRESS;
850 _req->actual = 0; 831 _req->actual = 0;
@@ -866,12 +847,12 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
866 847
867 if (likely(req != NULL)) { 848 if (likely(req != NULL)) {
868 list_add_tail(&req->queue, &ep->queue); 849 list_add_tail(&req->queue, &ep->queue);
869 VDBG(dev, "list_add_tail() \n"); 850 dev_vdbg(&dev->pdev->dev, "list_add_tail()\n");
870 } 851 }
871 852
872 spin_unlock_irqrestore(&dev->lock, flags); 853 spin_unlock_irqrestore(&dev->lock, flags);
873 854
874 VDBG(dev, "<--- %s()\n", __func__); 855 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
875 return 0; 856 return 0;
876} 857}
877 858
@@ -888,7 +869,7 @@ static int langwell_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
888 869
889 ep = container_of(_ep, struct langwell_ep, ep); 870 ep = container_of(_ep, struct langwell_ep, ep);
890 dev = ep->dev; 871 dev = ep->dev;
891 VDBG(dev, "---> %s()\n", __func__); 872 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
892 873
893 if (!_ep || !ep->desc || !_req) 874 if (!_ep || !ep->desc || !_req)
894 return -EINVAL; 875 return -EINVAL;
@@ -924,7 +905,7 @@ static int langwell_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
924 905
925 /* queue head may be partially complete. */ 906 /* queue head may be partially complete. */
926 if (ep->queue.next == &req->queue) { 907 if (ep->queue.next == &req->queue) {
927 DBG(dev, "unlink (%s) dma\n", _ep->name); 908 dev_dbg(&dev->pdev->dev, "unlink (%s) dma\n", _ep->name);
928 _req->status = -ECONNRESET; 909 _req->status = -ECONNRESET;
929 langwell_ep_fifo_flush(&ep->ep); 910 langwell_ep_fifo_flush(&ep->ep);
930 911
@@ -963,7 +944,7 @@ done:
963 ep->stopped = stopped; 944 ep->stopped = stopped;
964 spin_unlock_irqrestore(&dev->lock, flags); 945 spin_unlock_irqrestore(&dev->lock, flags);
965 946
966 VDBG(dev, "<--- %s()\n", __func__); 947 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
967 return retval; 948 return retval;
968} 949}
969 950
@@ -976,7 +957,7 @@ static void ep_set_halt(struct langwell_ep *ep, int value)
976 u32 endptctrl = 0; 957 u32 endptctrl = 0;
977 int ep_num; 958 int ep_num;
978 struct langwell_udc *dev = ep->dev; 959 struct langwell_udc *dev = ep->dev;
979 VDBG(dev, "---> %s()\n", __func__); 960 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
980 961
981 ep_num = ep->ep_num; 962 ep_num = ep->ep_num;
982 endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); 963 endptctrl = readl(&dev->op_regs->endptctrl[ep_num]);
@@ -1001,7 +982,7 @@ static void ep_set_halt(struct langwell_ep *ep, int value)
1001 982
1002 writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); 983 writel(endptctrl, &dev->op_regs->endptctrl[ep_num]);
1003 984
1004 VDBG(dev, "<--- %s()\n", __func__); 985 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1005} 986}
1006 987
1007 988
@@ -1016,7 +997,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value)
1016 ep = container_of(_ep, struct langwell_ep, ep); 997 ep = container_of(_ep, struct langwell_ep, ep);
1017 dev = ep->dev; 998 dev = ep->dev;
1018 999
1019 VDBG(dev, "---> %s()\n", __func__); 1000 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1020 1001
1021 if (!_ep || !ep->desc) 1002 if (!_ep || !ep->desc)
1022 return -EINVAL; 1003 return -EINVAL;
@@ -1024,8 +1005,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value)
1024 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) 1005 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
1025 return -ESHUTDOWN; 1006 return -ESHUTDOWN;
1026 1007
1027 if (ep->desc && (ep->desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 1008 if (usb_endpoint_xfer_isoc(ep->desc))
1028 == USB_ENDPOINT_XFER_ISOC)
1029 return -EOPNOTSUPP; 1009 return -EOPNOTSUPP;
1030 1010
1031 spin_lock_irqsave(&dev->lock, flags); 1011 spin_lock_irqsave(&dev->lock, flags);
@@ -1036,7 +1016,7 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value)
1036 */ 1016 */
1037 if (!list_empty(&ep->queue) && is_in(ep) && value) { 1017 if (!list_empty(&ep->queue) && is_in(ep) && value) {
1038 /* IN endpoint FIFO holds bytes */ 1018 /* IN endpoint FIFO holds bytes */
1039 DBG(dev, "%s FIFO holds bytes\n", _ep->name); 1019 dev_dbg(&dev->pdev->dev, "%s FIFO holds bytes\n", _ep->name);
1040 retval = -EAGAIN; 1020 retval = -EAGAIN;
1041 goto done; 1021 goto done;
1042 } 1022 }
@@ -1050,8 +1030,9 @@ static int langwell_ep_set_halt(struct usb_ep *_ep, int value)
1050 } 1030 }
1051done: 1031done:
1052 spin_unlock_irqrestore(&dev->lock, flags); 1032 spin_unlock_irqrestore(&dev->lock, flags);
1053 DBG(dev, "%s %s halt\n", _ep->name, value ? "set" : "clear"); 1033 dev_dbg(&dev->pdev->dev, "%s %s halt\n",
1054 VDBG(dev, "<--- %s()\n", __func__); 1034 _ep->name, value ? "set" : "clear");
1035 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1055 return retval; 1036 return retval;
1056} 1037}
1057 1038
@@ -1065,12 +1046,12 @@ static int langwell_ep_set_wedge(struct usb_ep *_ep)
1065 ep = container_of(_ep, struct langwell_ep, ep); 1046 ep = container_of(_ep, struct langwell_ep, ep);
1066 dev = ep->dev; 1047 dev = ep->dev;
1067 1048
1068 VDBG(dev, "---> %s()\n", __func__); 1049 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1069 1050
1070 if (!_ep || !ep->desc) 1051 if (!_ep || !ep->desc)
1071 return -EINVAL; 1052 return -EINVAL;
1072 1053
1073 VDBG(dev, "<--- %s()\n", __func__); 1054 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1074 return usb_ep_set_halt(_ep); 1055 return usb_ep_set_halt(_ep);
1075} 1056}
1076 1057
@@ -1086,15 +1067,16 @@ static void langwell_ep_fifo_flush(struct usb_ep *_ep)
1086 ep = container_of(_ep, struct langwell_ep, ep); 1067 ep = container_of(_ep, struct langwell_ep, ep);
1087 dev = ep->dev; 1068 dev = ep->dev;
1088 1069
1089 VDBG(dev, "---> %s()\n", __func__); 1070 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1090 1071
1091 if (!_ep || !ep->desc) { 1072 if (!_ep || !ep->desc) {
1092 VDBG(dev, "ep or ep->desc is NULL\n"); 1073 dev_vdbg(&dev->pdev->dev, "ep or ep->desc is NULL\n");
1093 VDBG(dev, "<--- %s()\n", __func__); 1074 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1094 return; 1075 return;
1095 } 1076 }
1096 1077
1097 VDBG(dev, "%s-%s fifo flush\n", _ep->name, is_in(ep) ? "in" : "out"); 1078 dev_vdbg(&dev->pdev->dev, "%s-%s fifo flush\n",
1079 _ep->name, DIR_STRING(ep));
1098 1080
1099 /* flush endpoint buffer */ 1081 /* flush endpoint buffer */
1100 if (ep->ep_num == 0) 1082 if (ep->ep_num == 0)
@@ -1110,14 +1092,14 @@ static void langwell_ep_fifo_flush(struct usb_ep *_ep)
1110 writel(flush_bit, &dev->op_regs->endptflush); 1092 writel(flush_bit, &dev->op_regs->endptflush);
1111 while (readl(&dev->op_regs->endptflush)) { 1093 while (readl(&dev->op_regs->endptflush)) {
1112 if (time_after(jiffies, timeout)) { 1094 if (time_after(jiffies, timeout)) {
1113 ERROR(dev, "ep flush timeout\n"); 1095 dev_err(&dev->pdev->dev, "ep flush timeout\n");
1114 goto done; 1096 goto done;
1115 } 1097 }
1116 cpu_relax(); 1098 cpu_relax();
1117 } 1099 }
1118 } while (readl(&dev->op_regs->endptstat) & flush_bit); 1100 } while (readl(&dev->op_regs->endptstat) & flush_bit);
1119done: 1101done:
1120 VDBG(dev, "<--- %s()\n", __func__); 1102 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1121} 1103}
1122 1104
1123 1105
@@ -1167,31 +1149,59 @@ static int langwell_get_frame(struct usb_gadget *_gadget)
1167 return -ENODEV; 1149 return -ENODEV;
1168 1150
1169 dev = container_of(_gadget, struct langwell_udc, gadget); 1151 dev = container_of(_gadget, struct langwell_udc, gadget);
1170 VDBG(dev, "---> %s()\n", __func__); 1152 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1171 1153
1172 retval = readl(&dev->op_regs->frindex) & FRINDEX_MASK; 1154 retval = readl(&dev->op_regs->frindex) & FRINDEX_MASK;
1173 1155
1174 VDBG(dev, "<--- %s()\n", __func__); 1156 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1175 return retval; 1157 return retval;
1176} 1158}
1177 1159
1178 1160
1161/* enter or exit PHY low power state */
1162static void langwell_phy_low_power(struct langwell_udc *dev, bool flag)
1163{
1164 u32 devlc;
1165 u8 devlc_byte2;
1166 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1167
1168 devlc = readl(&dev->op_regs->devlc);
1169 dev_vdbg(&dev->pdev->dev, "devlc = 0x%08x\n", devlc);
1170
1171 if (flag)
1172 devlc |= LPM_PHCD;
1173 else
1174 devlc &= ~LPM_PHCD;
1175
1176 /* FIXME: workaround for Langwell A1/A2/A3 sighting */
1177 devlc_byte2 = (devlc >> 16) & 0xff;
1178 writeb(devlc_byte2, (u8 *)&dev->op_regs->devlc + 2);
1179
1180 devlc = readl(&dev->op_regs->devlc);
1181 dev_vdbg(&dev->pdev->dev,
1182 "%s PHY low power suspend, devlc = 0x%08x\n",
1183 flag ? "enter" : "exit", devlc);
1184}
1185
1186
1179/* tries to wake up the host connected to this gadget */ 1187/* tries to wake up the host connected to this gadget */
1180static int langwell_wakeup(struct usb_gadget *_gadget) 1188static int langwell_wakeup(struct usb_gadget *_gadget)
1181{ 1189{
1182 struct langwell_udc *dev; 1190 struct langwell_udc *dev;
1183 u32 portsc1, devlc; 1191 u32 portsc1;
1184 unsigned long flags; 1192 unsigned long flags;
1185 1193
1186 if (!_gadget) 1194 if (!_gadget)
1187 return 0; 1195 return 0;
1188 1196
1189 dev = container_of(_gadget, struct langwell_udc, gadget); 1197 dev = container_of(_gadget, struct langwell_udc, gadget);
1190 VDBG(dev, "---> %s()\n", __func__); 1198 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1191 1199
1192 /* Remote Wakeup feature not enabled by host */ 1200 /* remote wakeup feature not enabled by host */
1193 if (!dev->remote_wakeup) 1201 if (!dev->remote_wakeup) {
1202 dev_info(&dev->pdev->dev, "remote wakeup is disabled\n");
1194 return -ENOTSUPP; 1203 return -ENOTSUPP;
1204 }
1195 1205
1196 spin_lock_irqsave(&dev->lock, flags); 1206 spin_lock_irqsave(&dev->lock, flags);
1197 1207
@@ -1201,27 +1211,23 @@ static int langwell_wakeup(struct usb_gadget *_gadget)
1201 return 0; 1211 return 0;
1202 } 1212 }
1203 1213
1204 /* LPM L1 to L0, remote wakeup */ 1214 /* LPM L1 to L0 or legacy remote wakeup */
1205 if (dev->lpm && dev->lpm_state == LPM_L1) { 1215 if (dev->lpm && dev->lpm_state == LPM_L1)
1206 portsc1 |= PORTS_SLP; 1216 dev_info(&dev->pdev->dev, "LPM L1 to L0 remote wakeup\n");
1207 writel(portsc1, &dev->op_regs->portsc1); 1217 else
1208 } 1218 dev_info(&dev->pdev->dev, "device remote wakeup\n");
1209
1210 /* force port resume */
1211 if (dev->usb_state == USB_STATE_SUSPENDED) {
1212 portsc1 |= PORTS_FPR;
1213 writel(portsc1, &dev->op_regs->portsc1);
1214 }
1215 1219
1216 /* exit PHY low power suspend */ 1220 /* exit PHY low power suspend */
1217 devlc = readl(&dev->op_regs->devlc); 1221 if (dev->pdev->device != 0x0829)
1218 VDBG(dev, "devlc = 0x%08x\n", devlc); 1222 langwell_phy_low_power(dev, 0);
1219 devlc &= ~LPM_PHCD; 1223
1220 writel(devlc, &dev->op_regs->devlc); 1224 /* force port resume */
1225 portsc1 |= PORTS_FPR;
1226 writel(portsc1, &dev->op_regs->portsc1);
1221 1227
1222 spin_unlock_irqrestore(&dev->lock, flags); 1228 spin_unlock_irqrestore(&dev->lock, flags);
1223 1229
1224 VDBG(dev, "<--- %s()\n", __func__); 1230 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1225 return 0; 1231 return 0;
1226} 1232}
1227 1233
@@ -1231,16 +1237,17 @@ static int langwell_vbus_session(struct usb_gadget *_gadget, int is_active)
1231{ 1237{
1232 struct langwell_udc *dev; 1238 struct langwell_udc *dev;
1233 unsigned long flags; 1239 unsigned long flags;
1234 u32 usbcmd; 1240 u32 usbcmd;
1235 1241
1236 if (!_gadget) 1242 if (!_gadget)
1237 return -ENODEV; 1243 return -ENODEV;
1238 1244
1239 dev = container_of(_gadget, struct langwell_udc, gadget); 1245 dev = container_of(_gadget, struct langwell_udc, gadget);
1240 VDBG(dev, "---> %s()\n", __func__); 1246 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1241 1247
1242 spin_lock_irqsave(&dev->lock, flags); 1248 spin_lock_irqsave(&dev->lock, flags);
1243 VDBG(dev, "VBUS status: %s\n", is_active ? "on" : "off"); 1249 dev_vdbg(&dev->pdev->dev, "VBUS status: %s\n",
1250 is_active ? "on" : "off");
1244 1251
1245 dev->vbus_active = (is_active != 0); 1252 dev->vbus_active = (is_active != 0);
1246 if (dev->driver && dev->softconnected && dev->vbus_active) { 1253 if (dev->driver && dev->softconnected && dev->vbus_active) {
@@ -1255,7 +1262,7 @@ static int langwell_vbus_session(struct usb_gadget *_gadget, int is_active)
1255 1262
1256 spin_unlock_irqrestore(&dev->lock, flags); 1263 spin_unlock_irqrestore(&dev->lock, flags);
1257 1264
1258 VDBG(dev, "<--- %s()\n", __func__); 1265 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1259 return 0; 1266 return 0;
1260} 1267}
1261 1268
@@ -1269,15 +1276,15 @@ static int langwell_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1269 return -ENODEV; 1276 return -ENODEV;
1270 1277
1271 dev = container_of(_gadget, struct langwell_udc, gadget); 1278 dev = container_of(_gadget, struct langwell_udc, gadget);
1272 VDBG(dev, "---> %s()\n", __func__); 1279 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1273 1280
1274 if (dev->transceiver) { 1281 if (dev->transceiver) {
1275 VDBG(dev, "otg_set_power\n"); 1282 dev_vdbg(&dev->pdev->dev, "otg_set_power\n");
1276 VDBG(dev, "<--- %s()\n", __func__); 1283 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1277 return otg_set_power(dev->transceiver, mA); 1284 return otg_set_power(dev->transceiver, mA);
1278 } 1285 }
1279 1286
1280 VDBG(dev, "<--- %s()\n", __func__); 1287 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1281 return -ENOTSUPP; 1288 return -ENOTSUPP;
1282} 1289}
1283 1290
@@ -1286,15 +1293,15 @@ static int langwell_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1286static int langwell_pullup(struct usb_gadget *_gadget, int is_on) 1293static int langwell_pullup(struct usb_gadget *_gadget, int is_on)
1287{ 1294{
1288 struct langwell_udc *dev; 1295 struct langwell_udc *dev;
1289 u32 usbcmd; 1296 u32 usbcmd;
1290 unsigned long flags; 1297 unsigned long flags;
1291 1298
1292 if (!_gadget) 1299 if (!_gadget)
1293 return -ENODEV; 1300 return -ENODEV;
1294 1301
1295 dev = container_of(_gadget, struct langwell_udc, gadget); 1302 dev = container_of(_gadget, struct langwell_udc, gadget);
1296 1303
1297 VDBG(dev, "---> %s()\n", __func__); 1304 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1298 1305
1299 spin_lock_irqsave(&dev->lock, flags); 1306 spin_lock_irqsave(&dev->lock, flags);
1300 dev->softconnected = (is_on != 0); 1307 dev->softconnected = (is_on != 0);
@@ -1310,7 +1317,7 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on)
1310 } 1317 }
1311 spin_unlock_irqrestore(&dev->lock, flags); 1318 spin_unlock_irqrestore(&dev->lock, flags);
1312 1319
1313 VDBG(dev, "<--- %s()\n", __func__); 1320 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1314 return 0; 1321 return 0;
1315} 1322}
1316 1323
@@ -1346,12 +1353,13 @@ static const struct usb_gadget_ops langwell_ops = {
1346static int langwell_udc_reset(struct langwell_udc *dev) 1353static int langwell_udc_reset(struct langwell_udc *dev)
1347{ 1354{
1348 u32 usbcmd, usbmode, devlc, endpointlistaddr; 1355 u32 usbcmd, usbmode, devlc, endpointlistaddr;
1356 u8 devlc_byte0, devlc_byte2;
1349 unsigned long timeout; 1357 unsigned long timeout;
1350 1358
1351 if (!dev) 1359 if (!dev)
1352 return -EINVAL; 1360 return -EINVAL;
1353 1361
1354 DBG(dev, "---> %s()\n", __func__); 1362 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1355 1363
1356 /* set controller to stop state */ 1364 /* set controller to stop state */
1357 usbcmd = readl(&dev->op_regs->usbcmd); 1365 usbcmd = readl(&dev->op_regs->usbcmd);
@@ -1367,7 +1375,7 @@ static int langwell_udc_reset(struct langwell_udc *dev)
1367 timeout = jiffies + RESET_TIMEOUT; 1375 timeout = jiffies + RESET_TIMEOUT;
1368 while (readl(&dev->op_regs->usbcmd) & CMD_RST) { 1376 while (readl(&dev->op_regs->usbcmd) & CMD_RST) {
1369 if (time_after(jiffies, timeout)) { 1377 if (time_after(jiffies, timeout)) {
1370 ERROR(dev, "device reset timeout\n"); 1378 dev_err(&dev->pdev->dev, "device reset timeout\n");
1371 return -ETIMEDOUT; 1379 return -ETIMEDOUT;
1372 } 1380 }
1373 cpu_relax(); 1381 cpu_relax();
@@ -1382,7 +1390,7 @@ static int langwell_udc_reset(struct langwell_udc *dev)
1382 1390
1383 writel(usbmode, &dev->op_regs->usbmode); 1391 writel(usbmode, &dev->op_regs->usbmode);
1384 usbmode = readl(&dev->op_regs->usbmode); 1392 usbmode = readl(&dev->op_regs->usbmode);
1385 VDBG(dev, "usbmode=0x%08x\n", usbmode); 1393 dev_vdbg(&dev->pdev->dev, "usbmode=0x%08x\n", usbmode);
1386 1394
1387 /* Write-Clear setup status */ 1395 /* Write-Clear setup status */
1388 writel(0, &dev->op_regs->usbsts); 1396 writel(0, &dev->op_regs->usbsts);
@@ -1390,9 +1398,17 @@ static int langwell_udc_reset(struct langwell_udc *dev)
1390 /* if support USB LPM, ACK all LPM token */ 1398 /* if support USB LPM, ACK all LPM token */
1391 if (dev->lpm) { 1399 if (dev->lpm) {
1392 devlc = readl(&dev->op_regs->devlc); 1400 devlc = readl(&dev->op_regs->devlc);
1401 dev_vdbg(&dev->pdev->dev, "devlc = 0x%08x\n", devlc);
1402 /* FIXME: workaround for Langwell A1/A2/A3 sighting */
1393 devlc &= ~LPM_STL; /* don't STALL LPM token */ 1403 devlc &= ~LPM_STL; /* don't STALL LPM token */
1394 devlc &= ~LPM_NYT_ACK; /* ACK LPM token */ 1404 devlc &= ~LPM_NYT_ACK; /* ACK LPM token */
1395 writel(devlc, &dev->op_regs->devlc); 1405 devlc_byte0 = devlc & 0xff;
1406 devlc_byte2 = (devlc >> 16) & 0xff;
1407 writeb(devlc_byte0, (u8 *)&dev->op_regs->devlc);
1408 writeb(devlc_byte2, (u8 *)&dev->op_regs->devlc + 2);
1409 devlc = readl(&dev->op_regs->devlc);
1410 dev_vdbg(&dev->pdev->dev,
1411 "ACK LPM token, devlc = 0x%08x\n", devlc);
1396 } 1412 }
1397 1413
1398 /* fill endpointlistaddr register */ 1414 /* fill endpointlistaddr register */
@@ -1400,10 +1416,11 @@ static int langwell_udc_reset(struct langwell_udc *dev)
1400 endpointlistaddr &= ENDPOINTLISTADDR_MASK; 1416 endpointlistaddr &= ENDPOINTLISTADDR_MASK;
1401 writel(endpointlistaddr, &dev->op_regs->endpointlistaddr); 1417 writel(endpointlistaddr, &dev->op_regs->endpointlistaddr);
1402 1418
1403 VDBG(dev, "dQH base (vir: %p, phy: 0x%08x), endpointlistaddr=0x%08x\n", 1419 dev_vdbg(&dev->pdev->dev,
1404 dev->ep_dqh, endpointlistaddr, 1420 "dQH base (vir: %p, phy: 0x%08x), endpointlistaddr=0x%08x\n",
1405 readl(&dev->op_regs->endpointlistaddr)); 1421 dev->ep_dqh, endpointlistaddr,
1406 DBG(dev, "<--- %s()\n", __func__); 1422 readl(&dev->op_regs->endpointlistaddr));
1423 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1407 return 0; 1424 return 0;
1408} 1425}
1409 1426
@@ -1415,7 +1432,7 @@ static int eps_reinit(struct langwell_udc *dev)
1415 char name[14]; 1432 char name[14];
1416 int i; 1433 int i;
1417 1434
1418 VDBG(dev, "---> %s()\n", __func__); 1435 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1419 1436
1420 /* initialize ep0 */ 1437 /* initialize ep0 */
1421 ep = &dev->ep[0]; 1438 ep = &dev->ep[0];
@@ -1449,11 +1466,9 @@ static int eps_reinit(struct langwell_udc *dev)
1449 1466
1450 INIT_LIST_HEAD(&ep->queue); 1467 INIT_LIST_HEAD(&ep->queue);
1451 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); 1468 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
1452
1453 ep->dqh = &dev->ep_dqh[i];
1454 } 1469 }
1455 1470
1456 VDBG(dev, "<--- %s()\n", __func__); 1471 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1457 return 0; 1472 return 0;
1458} 1473}
1459 1474
@@ -1462,7 +1477,7 @@ static int eps_reinit(struct langwell_udc *dev)
1462static void langwell_udc_start(struct langwell_udc *dev) 1477static void langwell_udc_start(struct langwell_udc *dev)
1463{ 1478{
1464 u32 usbintr, usbcmd; 1479 u32 usbintr, usbcmd;
1465 DBG(dev, "---> %s()\n", __func__); 1480 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1466 1481
1467 /* enable interrupts */ 1482 /* enable interrupts */
1468 usbintr = INTR_ULPIE /* ULPI */ 1483 usbintr = INTR_ULPIE /* ULPI */
@@ -1485,8 +1500,7 @@ static void langwell_udc_start(struct langwell_udc *dev)
1485 usbcmd |= CMD_RUNSTOP; 1500 usbcmd |= CMD_RUNSTOP;
1486 writel(usbcmd, &dev->op_regs->usbcmd); 1501 writel(usbcmd, &dev->op_regs->usbcmd);
1487 1502
1488 DBG(dev, "<--- %s()\n", __func__); 1503 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1489 return;
1490} 1504}
1491 1505
1492 1506
@@ -1495,7 +1509,7 @@ static void langwell_udc_stop(struct langwell_udc *dev)
1495{ 1509{
1496 u32 usbcmd; 1510 u32 usbcmd;
1497 1511
1498 DBG(dev, "---> %s()\n", __func__); 1512 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1499 1513
1500 /* disable all interrupts */ 1514 /* disable all interrupts */
1501 writel(0, &dev->op_regs->usbintr); 1515 writel(0, &dev->op_regs->usbintr);
@@ -1508,8 +1522,7 @@ static void langwell_udc_stop(struct langwell_udc *dev)
1508 usbcmd &= ~CMD_RUNSTOP; 1522 usbcmd &= ~CMD_RUNSTOP;
1509 writel(usbcmd, &dev->op_regs->usbcmd); 1523 writel(usbcmd, &dev->op_regs->usbcmd);
1510 1524
1511 DBG(dev, "<--- %s()\n", __func__); 1525 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1512 return;
1513} 1526}
1514 1527
1515 1528
@@ -1518,7 +1531,7 @@ static void stop_activity(struct langwell_udc *dev,
1518 struct usb_gadget_driver *driver) 1531 struct usb_gadget_driver *driver)
1519{ 1532{
1520 struct langwell_ep *ep; 1533 struct langwell_ep *ep;
1521 DBG(dev, "---> %s()\n", __func__); 1534 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1522 1535
1523 nuke(&dev->ep[0], -ESHUTDOWN); 1536 nuke(&dev->ep[0], -ESHUTDOWN);
1524 1537
@@ -1533,7 +1546,7 @@ static void stop_activity(struct langwell_udc *dev,
1533 spin_lock(&dev->lock); 1546 spin_lock(&dev->lock);
1534 } 1547 }
1535 1548
1536 DBG(dev, "<--- %s()\n", __func__); 1549 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1537} 1550}
1538 1551
1539 1552
@@ -1659,13 +1672,15 @@ static ssize_t show_langwell_udc(struct device *_dev,
1659 "Over-current Change: %s\n" 1672 "Over-current Change: %s\n"
1660 "Port Enable/Disable Change: %s\n" 1673 "Port Enable/Disable Change: %s\n"
1661 "Port Enabled/Disabled: %s\n" 1674 "Port Enabled/Disabled: %s\n"
1662 "Current Connect Status: %s\n\n", 1675 "Current Connect Status: %s\n"
1676 "LPM Suspend Status: %s\n\n",
1663 (tmp_reg & PORTS_PR) ? "Reset" : "Not Reset", 1677 (tmp_reg & PORTS_PR) ? "Reset" : "Not Reset",
1664 (tmp_reg & PORTS_SUSP) ? "Suspend " : "Not Suspend", 1678 (tmp_reg & PORTS_SUSP) ? "Suspend " : "Not Suspend",
1665 (tmp_reg & PORTS_OCC) ? "Detected" : "No", 1679 (tmp_reg & PORTS_OCC) ? "Detected" : "No",
1666 (tmp_reg & PORTS_PEC) ? "Changed" : "Not Changed", 1680 (tmp_reg & PORTS_PEC) ? "Changed" : "Not Changed",
1667 (tmp_reg & PORTS_PE) ? "Enable" : "Not Correct", 1681 (tmp_reg & PORTS_PE) ? "Enable" : "Not Correct",
1668 (tmp_reg & PORTS_CCS) ? "Attached" : "Not Attached"); 1682 (tmp_reg & PORTS_CCS) ? "Attached" : "Not Attached",
1683 (tmp_reg & PORTS_SLP) ? "LPM L1" : "LPM L0");
1669 size -= t; 1684 size -= t;
1670 next += t; 1685 next += t;
1671 1686
@@ -1676,7 +1691,7 @@ static ssize_t show_langwell_udc(struct device *_dev,
1676 "Serial Transceiver : %d\n" 1691 "Serial Transceiver : %d\n"
1677 "Port Speed: %s\n" 1692 "Port Speed: %s\n"
1678 "Port Force Full Speed Connenct: %s\n" 1693 "Port Force Full Speed Connenct: %s\n"
1679 "PHY Low Power Suspend Clock Disable: %s\n" 1694 "PHY Low Power Suspend Clock: %s\n"
1680 "BmAttributes: %d\n\n", 1695 "BmAttributes: %d\n\n",
1681 LPM_PTS(tmp_reg), 1696 LPM_PTS(tmp_reg),
1682 (tmp_reg & LPM_STS) ? 1 : 0, 1697 (tmp_reg & LPM_STS) ? 1 : 0,
@@ -1797,6 +1812,36 @@ static ssize_t show_langwell_udc(struct device *_dev,
1797static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL); 1812static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL);
1798 1813
1799 1814
1815/* device "remote_wakeup" sysfs attribute file */
1816static ssize_t store_remote_wakeup(struct device *_dev,
1817 struct device_attribute *attr, const char *buf, size_t count)
1818{
1819 struct langwell_udc *dev = the_controller;
1820 unsigned long flags;
1821 ssize_t rc = count;
1822
1823 if (count > 2)
1824 return -EINVAL;
1825
1826 if (count > 0 && buf[count-1] == '\n')
1827 ((char *) buf)[count-1] = 0;
1828
1829 if (buf[0] != '1')
1830 return -EINVAL;
1831
1832 /* force remote wakeup enabled in case gadget driver doesn't support */
1833 spin_lock_irqsave(&dev->lock, flags);
1834 dev->remote_wakeup = 1;
1835 dev->dev_status |= (1 << USB_DEVICE_REMOTE_WAKEUP);
1836 spin_unlock_irqrestore(&dev->lock, flags);
1837
1838 langwell_wakeup(&dev->gadget);
1839
1840 return rc;
1841}
1842static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup);
1843
1844
1800/*-------------------------------------------------------------------------*/ 1845/*-------------------------------------------------------------------------*/
1801 1846
1802/* 1847/*
@@ -1807,7 +1852,8 @@ static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL);
1807 * the driver might get unbound. 1852 * the driver might get unbound.
1808 */ 1853 */
1809 1854
1810int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1855int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1856 int (*bind)(struct usb_gadget *))
1811{ 1857{
1812 struct langwell_udc *dev = the_controller; 1858 struct langwell_udc *dev = the_controller;
1813 unsigned long flags; 1859 unsigned long flags;
@@ -1816,7 +1862,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1816 if (!dev) 1862 if (!dev)
1817 return -ENODEV; 1863 return -ENODEV;
1818 1864
1819 DBG(dev, "---> %s()\n", __func__); 1865 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1820 1866
1821 if (dev->driver) 1867 if (dev->driver)
1822 return -EBUSY; 1868 return -EBUSY;
@@ -1830,9 +1876,9 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1830 1876
1831 spin_unlock_irqrestore(&dev->lock, flags); 1877 spin_unlock_irqrestore(&dev->lock, flags);
1832 1878
1833 retval = driver->bind(&dev->gadget); 1879 retval = bind(&dev->gadget);
1834 if (retval) { 1880 if (retval) {
1835 DBG(dev, "bind to driver %s --> %d\n", 1881 dev_dbg(&dev->pdev->dev, "bind to driver %s --> %d\n",
1836 driver->driver.name, retval); 1882 driver->driver.name, retval);
1837 dev->driver = NULL; 1883 dev->driver = NULL;
1838 dev->gadget.dev.driver = NULL; 1884 dev->gadget.dev.driver = NULL;
@@ -1851,13 +1897,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1851 if (dev->got_irq) 1897 if (dev->got_irq)
1852 langwell_udc_start(dev); 1898 langwell_udc_start(dev);
1853 1899
1854 VDBG(dev, "After langwell_udc_start(), print all registers:\n"); 1900 dev_vdbg(&dev->pdev->dev,
1855#ifdef VERBOSE 1901 "After langwell_udc_start(), print all registers:\n");
1856 print_all_registers(dev); 1902 print_all_registers(dev);
1857#endif
1858 1903
1859 INFO(dev, "register driver: %s\n", driver->driver.name); 1904 dev_info(&dev->pdev->dev, "register driver: %s\n",
1860 VDBG(dev, "<--- %s()\n", __func__); 1905 driver->driver.name);
1906 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1861 return 0; 1907 return 0;
1862 1908
1863err_unbind: 1909err_unbind:
@@ -1865,10 +1911,10 @@ err_unbind:
1865 dev->gadget.dev.driver = NULL; 1911 dev->gadget.dev.driver = NULL;
1866 dev->driver = NULL; 1912 dev->driver = NULL;
1867 1913
1868 DBG(dev, "<--- %s()\n", __func__); 1914 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1869 return retval; 1915 return retval;
1870} 1916}
1871EXPORT_SYMBOL(usb_gadget_register_driver); 1917EXPORT_SYMBOL(usb_gadget_probe_driver);
1872 1918
1873 1919
1874/* unregister gadget driver */ 1920/* unregister gadget driver */
@@ -1880,11 +1926,15 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1880 if (!dev) 1926 if (!dev)
1881 return -ENODEV; 1927 return -ENODEV;
1882 1928
1883 DBG(dev, "---> %s()\n", __func__); 1929 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
1884 1930
1885 if (unlikely(!driver || !driver->bind || !driver->unbind)) 1931 if (unlikely(!driver || !driver->unbind))
1886 return -EINVAL; 1932 return -EINVAL;
1887 1933
1934 /* exit PHY low power suspend */
1935 if (dev->pdev->device != 0x0829)
1936 langwell_phy_low_power(dev, 0);
1937
1888 /* unbind OTG transceiver */ 1938 /* unbind OTG transceiver */
1889 if (dev->transceiver) 1939 if (dev->transceiver)
1890 (void)otg_set_peripheral(dev->transceiver, 0); 1940 (void)otg_set_peripheral(dev->transceiver, 0);
@@ -1910,8 +1960,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1910 1960
1911 device_remove_file(&dev->pdev->dev, &dev_attr_function); 1961 device_remove_file(&dev->pdev->dev, &dev_attr_function);
1912 1962
1913 INFO(dev, "unregistered driver '%s'\n", driver->driver.name); 1963 dev_info(&dev->pdev->dev, "unregistered driver '%s'\n",
1914 DBG(dev, "<--- %s()\n", __func__); 1964 driver->driver.name);
1965 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1915 return 0; 1966 return 0;
1916} 1967}
1917EXPORT_SYMBOL(usb_gadget_unregister_driver); 1968EXPORT_SYMBOL(usb_gadget_unregister_driver);
@@ -1930,7 +1981,7 @@ static void setup_tripwire(struct langwell_udc *dev)
1930 unsigned long timeout; 1981 unsigned long timeout;
1931 struct langwell_dqh *dqh; 1982 struct langwell_dqh *dqh;
1932 1983
1933 VDBG(dev, "---> %s()\n", __func__); 1984 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1934 1985
1935 /* ep0 OUT dQH */ 1986 /* ep0 OUT dQH */
1936 dqh = &dev->ep_dqh[EP_DIR_OUT]; 1987 dqh = &dev->ep_dqh[EP_DIR_OUT];
@@ -1943,7 +1994,7 @@ static void setup_tripwire(struct langwell_udc *dev)
1943 timeout = jiffies + SETUPSTAT_TIMEOUT; 1994 timeout = jiffies + SETUPSTAT_TIMEOUT;
1944 while (readl(&dev->op_regs->endptsetupstat)) { 1995 while (readl(&dev->op_regs->endptsetupstat)) {
1945 if (time_after(jiffies, timeout)) { 1996 if (time_after(jiffies, timeout)) {
1946 ERROR(dev, "setup_tripwire timeout\n"); 1997 dev_err(&dev->pdev->dev, "setup_tripwire timeout\n");
1947 break; 1998 break;
1948 } 1999 }
1949 cpu_relax(); 2000 cpu_relax();
@@ -1963,7 +2014,7 @@ static void setup_tripwire(struct langwell_udc *dev)
1963 usbcmd = readl(&dev->op_regs->usbcmd); 2014 usbcmd = readl(&dev->op_regs->usbcmd);
1964 writel(usbcmd & ~CMD_SUTW, &dev->op_regs->usbcmd); 2015 writel(usbcmd & ~CMD_SUTW, &dev->op_regs->usbcmd);
1965 2016
1966 VDBG(dev, "<--- %s()\n", __func__); 2017 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1967} 2018}
1968 2019
1969 2020
@@ -1972,7 +2023,7 @@ static void ep0_stall(struct langwell_udc *dev)
1972{ 2023{
1973 u32 endptctrl; 2024 u32 endptctrl;
1974 2025
1975 VDBG(dev, "---> %s()\n", __func__); 2026 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1976 2027
1977 /* set TX and RX to stall */ 2028 /* set TX and RX to stall */
1978 endptctrl = readl(&dev->op_regs->endptctrl[0]); 2029 endptctrl = readl(&dev->op_regs->endptctrl[0]);
@@ -1983,7 +2034,7 @@ static void ep0_stall(struct langwell_udc *dev)
1983 dev->ep0_state = WAIT_FOR_SETUP; 2034 dev->ep0_state = WAIT_FOR_SETUP;
1984 dev->ep0_dir = USB_DIR_OUT; 2035 dev->ep0_dir = USB_DIR_OUT;
1985 2036
1986 VDBG(dev, "<--- %s()\n", __func__); 2037 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1987} 2038}
1988 2039
1989 2040
@@ -1994,7 +2045,7 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
1994 struct langwell_ep *ep; 2045 struct langwell_ep *ep;
1995 int status = 0; 2046 int status = 0;
1996 2047
1997 VDBG(dev, "---> %s()\n", __func__); 2048 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
1998 2049
1999 if (dir == EP_DIR_IN) 2050 if (dir == EP_DIR_IN)
2000 dev->ep0_dir = USB_DIR_IN; 2051 dev->ep0_dir = USB_DIR_IN;
@@ -2019,11 +2070,11 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
2019 return -ENOMEM; 2070 return -ENOMEM;
2020 2071
2021 if (status) 2072 if (status)
2022 ERROR(dev, "can't queue ep0 status request\n"); 2073 dev_err(&dev->pdev->dev, "can't queue ep0 status request\n");
2023 2074
2024 list_add_tail(&req->queue, &ep->queue); 2075 list_add_tail(&req->queue, &ep->queue);
2025 2076
2026 VDBG(dev, "<--- %s()\n", __func__); 2077 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2027 return status; 2078 return status;
2028} 2079}
2029 2080
@@ -2032,11 +2083,11 @@ static int prime_status_phase(struct langwell_udc *dev, int dir)
2032static void set_address(struct langwell_udc *dev, u16 value, 2083static void set_address(struct langwell_udc *dev, u16 value,
2033 u16 index, u16 length) 2084 u16 index, u16 length)
2034{ 2085{
2035 VDBG(dev, "---> %s()\n", __func__); 2086 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2036 2087
2037 /* save the new address to device struct */ 2088 /* save the new address to device struct */
2038 dev->dev_addr = (u8) value; 2089 dev->dev_addr = (u8) value;
2039 VDBG(dev, "dev->dev_addr = %d\n", dev->dev_addr); 2090 dev_vdbg(&dev->pdev->dev, "dev->dev_addr = %d\n", dev->dev_addr);
2040 2091
2041 /* update usb state */ 2092 /* update usb state */
2042 dev->usb_state = USB_STATE_ADDRESS; 2093 dev->usb_state = USB_STATE_ADDRESS;
@@ -2045,7 +2096,7 @@ static void set_address(struct langwell_udc *dev, u16 value,
2045 if (prime_status_phase(dev, EP_DIR_IN)) 2096 if (prime_status_phase(dev, EP_DIR_IN))
2046 ep0_stall(dev); 2097 ep0_stall(dev);
2047 2098
2048 VDBG(dev, "<--- %s()\n", __func__); 2099 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2049} 2100}
2050 2101
2051 2102
@@ -2054,7 +2105,7 @@ static struct langwell_ep *get_ep_by_windex(struct langwell_udc *dev,
2054 u16 wIndex) 2105 u16 wIndex)
2055{ 2106{
2056 struct langwell_ep *ep; 2107 struct langwell_ep *ep;
2057 VDBG(dev, "---> %s()\n", __func__); 2108 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2058 2109
2059 if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0) 2110 if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
2060 return &dev->ep[0]; 2111 return &dev->ep[0];
@@ -2073,7 +2124,7 @@ static struct langwell_ep *get_ep_by_windex(struct langwell_udc *dev,
2073 return ep; 2124 return ep;
2074 } 2125 }
2075 2126
2076 VDBG(dev, "<--- %s()\n", __func__); 2127 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2077 return NULL; 2128 return NULL;
2078} 2129}
2079 2130
@@ -2085,7 +2136,7 @@ static int ep_is_stall(struct langwell_ep *ep)
2085 u32 endptctrl; 2136 u32 endptctrl;
2086 int retval; 2137 int retval;
2087 2138
2088 VDBG(dev, "---> %s()\n", __func__); 2139 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2089 2140
2090 endptctrl = readl(&dev->op_regs->endptctrl[ep->ep_num]); 2141 endptctrl = readl(&dev->op_regs->endptctrl[ep->ep_num]);
2091 if (is_in(ep)) 2142 if (is_in(ep))
@@ -2093,7 +2144,7 @@ static int ep_is_stall(struct langwell_ep *ep)
2093 else 2144 else
2094 retval = endptctrl & EPCTRL_RXS ? 1 : 0; 2145 retval = endptctrl & EPCTRL_RXS ? 1 : 0;
2095 2146
2096 VDBG(dev, "<--- %s()\n", __func__); 2147 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2097 return retval; 2148 return retval;
2098} 2149}
2099 2150
@@ -2107,14 +2158,13 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
2107 u16 status_data = 0; /* 16 bits cpu view status data */ 2158 u16 status_data = 0; /* 16 bits cpu view status data */
2108 int status = 0; 2159 int status = 0;
2109 2160
2110 VDBG(dev, "---> %s()\n", __func__); 2161 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2111 2162
2112 ep = &dev->ep[0]; 2163 ep = &dev->ep[0];
2113 2164
2114 if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) { 2165 if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
2115 /* get device status */ 2166 /* get device status */
2116 status_data = 1 << USB_DEVICE_SELF_POWERED; 2167 status_data = dev->dev_status;
2117 status_data |= dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP;
2118 } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) { 2168 } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) {
2119 /* get interface status */ 2169 /* get interface status */
2120 status_data = 0; 2170 status_data = 0;
@@ -2129,6 +2179,8 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
2129 status_data = ep_is_stall(epn) << USB_ENDPOINT_HALT; 2179 status_data = ep_is_stall(epn) << USB_ENDPOINT_HALT;
2130 } 2180 }
2131 2181
2182 dev_dbg(&dev->pdev->dev, "get status data: 0x%04x\n", status_data);
2183
2132 dev->ep0_dir = USB_DIR_IN; 2184 dev->ep0_dir = USB_DIR_IN;
2133 2185
2134 /* borrow the per device status_req */ 2186 /* borrow the per device status_req */
@@ -2150,18 +2202,19 @@ static void get_status(struct langwell_udc *dev, u8 request_type, u16 value,
2150 goto stall; 2202 goto stall;
2151 2203
2152 if (status) { 2204 if (status) {
2153 ERROR(dev, "response error on GET_STATUS request\n"); 2205 dev_err(&dev->pdev->dev,
2206 "response error on GET_STATUS request\n");
2154 goto stall; 2207 goto stall;
2155 } 2208 }
2156 2209
2157 list_add_tail(&req->queue, &ep->queue); 2210 list_add_tail(&req->queue, &ep->queue);
2158 dev->ep0_state = DATA_STATE_XMIT; 2211 dev->ep0_state = DATA_STATE_XMIT;
2159 2212
2160 VDBG(dev, "<--- %s()\n", __func__); 2213 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2161 return; 2214 return;
2162stall: 2215stall:
2163 ep0_stall(dev); 2216 ep0_stall(dev);
2164 VDBG(dev, "<--- %s()\n", __func__); 2217 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2165} 2218}
2166 2219
2167 2220
@@ -2173,12 +2226,12 @@ static void handle_setup_packet(struct langwell_udc *dev,
2173 u16 wIndex = le16_to_cpu(setup->wIndex); 2226 u16 wIndex = le16_to_cpu(setup->wIndex);
2174 u16 wLength = le16_to_cpu(setup->wLength); 2227 u16 wLength = le16_to_cpu(setup->wLength);
2175 2228
2176 VDBG(dev, "---> %s()\n", __func__); 2229 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2177 2230
2178 /* ep0 fifo flush */ 2231 /* ep0 fifo flush */
2179 nuke(&dev->ep[0], -ESHUTDOWN); 2232 nuke(&dev->ep[0], -ESHUTDOWN);
2180 2233
2181 DBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", 2234 dev_dbg(&dev->pdev->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
2182 setup->bRequestType, setup->bRequest, 2235 setup->bRequestType, setup->bRequest,
2183 wValue, wIndex, wLength); 2236 wValue, wIndex, wLength);
2184 2237
@@ -2197,7 +2250,7 @@ static void handle_setup_packet(struct langwell_udc *dev,
2197 /* We process some stardard setup requests here */ 2250 /* We process some stardard setup requests here */
2198 switch (setup->bRequest) { 2251 switch (setup->bRequest) {
2199 case USB_REQ_GET_STATUS: 2252 case USB_REQ_GET_STATUS:
2200 DBG(dev, "SETUP: USB_REQ_GET_STATUS\n"); 2253 dev_dbg(&dev->pdev->dev, "SETUP: USB_REQ_GET_STATUS\n");
2201 /* get status, DATA and STATUS phase */ 2254 /* get status, DATA and STATUS phase */
2202 if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) 2255 if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK))
2203 != (USB_DIR_IN | USB_TYPE_STANDARD)) 2256 != (USB_DIR_IN | USB_TYPE_STANDARD))
@@ -2206,7 +2259,7 @@ static void handle_setup_packet(struct langwell_udc *dev,
2206 goto end; 2259 goto end;
2207 2260
2208 case USB_REQ_SET_ADDRESS: 2261 case USB_REQ_SET_ADDRESS:
2209 DBG(dev, "SETUP: USB_REQ_SET_ADDRESS\n"); 2262 dev_dbg(&dev->pdev->dev, "SETUP: USB_REQ_SET_ADDRESS\n");
2210 /* STATUS phase */ 2263 /* STATUS phase */
2211 if (setup->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD 2264 if (setup->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD
2212 | USB_RECIP_DEVICE)) 2265 | USB_RECIP_DEVICE))
@@ -2220,9 +2273,11 @@ static void handle_setup_packet(struct langwell_udc *dev,
2220 { 2273 {
2221 int rc = -EOPNOTSUPP; 2274 int rc = -EOPNOTSUPP;
2222 if (setup->bRequest == USB_REQ_SET_FEATURE) 2275 if (setup->bRequest == USB_REQ_SET_FEATURE)
2223 DBG(dev, "SETUP: USB_REQ_SET_FEATURE\n"); 2276 dev_dbg(&dev->pdev->dev,
2277 "SETUP: USB_REQ_SET_FEATURE\n");
2224 else if (setup->bRequest == USB_REQ_CLEAR_FEATURE) 2278 else if (setup->bRequest == USB_REQ_CLEAR_FEATURE)
2225 DBG(dev, "SETUP: USB_REQ_CLEAR_FEATURE\n"); 2279 dev_dbg(&dev->pdev->dev,
2280 "SETUP: USB_REQ_CLEAR_FEATURE\n");
2226 2281
2227 if ((setup->bRequestType & (USB_RECIP_MASK | USB_TYPE_MASK)) 2282 if ((setup->bRequestType & (USB_RECIP_MASK | USB_TYPE_MASK))
2228 == (USB_RECIP_ENDPOINT | USB_TYPE_STANDARD)) { 2283 == (USB_RECIP_ENDPOINT | USB_TYPE_STANDARD)) {
@@ -2240,13 +2295,29 @@ static void handle_setup_packet(struct langwell_udc *dev,
2240 2295
2241 spin_unlock(&dev->lock); 2296 spin_unlock(&dev->lock);
2242 rc = langwell_ep_set_halt(&epn->ep, 2297 rc = langwell_ep_set_halt(&epn->ep,
2243 (setup->bRequest == USB_REQ_SET_FEATURE) 2298 (setup->bRequest == USB_REQ_SET_FEATURE)
2244 ? 1 : 0); 2299 ? 1 : 0);
2245 spin_lock(&dev->lock); 2300 spin_lock(&dev->lock);
2246 2301
2247 } else if ((setup->bRequestType & (USB_RECIP_MASK 2302 } else if ((setup->bRequestType & (USB_RECIP_MASK
2248 | USB_TYPE_MASK)) == (USB_RECIP_DEVICE 2303 | USB_TYPE_MASK)) == (USB_RECIP_DEVICE
2249 | USB_TYPE_STANDARD)) { 2304 | USB_TYPE_STANDARD)) {
2305 rc = 0;
2306 switch (wValue) {
2307 case USB_DEVICE_REMOTE_WAKEUP:
2308 if (setup->bRequest == USB_REQ_SET_FEATURE) {
2309 dev->remote_wakeup = 1;
2310 dev->dev_status |= (1 << wValue);
2311 } else {
2312 dev->remote_wakeup = 0;
2313 dev->dev_status &= ~(1 << wValue);
2314 }
2315 break;
2316 default:
2317 rc = -EOPNOTSUPP;
2318 break;
2319 }
2320
2250 if (!gadget_is_otg(&dev->gadget)) 2321 if (!gadget_is_otg(&dev->gadget))
2251 break; 2322 break;
2252 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) { 2323 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) {
@@ -2262,7 +2333,6 @@ static void handle_setup_packet(struct langwell_udc *dev,
2262 dev->gadget.a_alt_hnp_support = 1; 2333 dev->gadget.a_alt_hnp_support = 1;
2263 else 2334 else
2264 break; 2335 break;
2265 rc = 0;
2266 } else 2336 } else
2267 break; 2337 break;
2268 2338
@@ -2274,31 +2344,38 @@ static void handle_setup_packet(struct langwell_udc *dev,
2274 } 2344 }
2275 2345
2276 case USB_REQ_GET_DESCRIPTOR: 2346 case USB_REQ_GET_DESCRIPTOR:
2277 DBG(dev, "SETUP: USB_REQ_GET_DESCRIPTOR\n"); 2347 dev_dbg(&dev->pdev->dev,
2348 "SETUP: USB_REQ_GET_DESCRIPTOR\n");
2278 goto delegate; 2349 goto delegate;
2279 2350
2280 case USB_REQ_SET_DESCRIPTOR: 2351 case USB_REQ_SET_DESCRIPTOR:
2281 DBG(dev, "SETUP: USB_REQ_SET_DESCRIPTOR unsupported\n"); 2352 dev_dbg(&dev->pdev->dev,
2353 "SETUP: USB_REQ_SET_DESCRIPTOR unsupported\n");
2282 goto delegate; 2354 goto delegate;
2283 2355
2284 case USB_REQ_GET_CONFIGURATION: 2356 case USB_REQ_GET_CONFIGURATION:
2285 DBG(dev, "SETUP: USB_REQ_GET_CONFIGURATION\n"); 2357 dev_dbg(&dev->pdev->dev,
2358 "SETUP: USB_REQ_GET_CONFIGURATION\n");
2286 goto delegate; 2359 goto delegate;
2287 2360
2288 case USB_REQ_SET_CONFIGURATION: 2361 case USB_REQ_SET_CONFIGURATION:
2289 DBG(dev, "SETUP: USB_REQ_SET_CONFIGURATION\n"); 2362 dev_dbg(&dev->pdev->dev,
2363 "SETUP: USB_REQ_SET_CONFIGURATION\n");
2290 goto delegate; 2364 goto delegate;
2291 2365
2292 case USB_REQ_GET_INTERFACE: 2366 case USB_REQ_GET_INTERFACE:
2293 DBG(dev, "SETUP: USB_REQ_GET_INTERFACE\n"); 2367 dev_dbg(&dev->pdev->dev,
2368 "SETUP: USB_REQ_GET_INTERFACE\n");
2294 goto delegate; 2369 goto delegate;
2295 2370
2296 case USB_REQ_SET_INTERFACE: 2371 case USB_REQ_SET_INTERFACE:
2297 DBG(dev, "SETUP: USB_REQ_SET_INTERFACE\n"); 2372 dev_dbg(&dev->pdev->dev,
2373 "SETUP: USB_REQ_SET_INTERFACE\n");
2298 goto delegate; 2374 goto delegate;
2299 2375
2300 case USB_REQ_SYNCH_FRAME: 2376 case USB_REQ_SYNCH_FRAME:
2301 DBG(dev, "SETUP: USB_REQ_SYNCH_FRAME unsupported\n"); 2377 dev_dbg(&dev->pdev->dev,
2378 "SETUP: USB_REQ_SYNCH_FRAME unsupported\n");
2302 goto delegate; 2379 goto delegate;
2303 2380
2304 default: 2381 default:
@@ -2310,7 +2387,8 @@ delegate:
2310 /* DATA phase from gadget, STATUS phase from udc */ 2387 /* DATA phase from gadget, STATUS phase from udc */
2311 dev->ep0_dir = (setup->bRequestType & USB_DIR_IN) 2388 dev->ep0_dir = (setup->bRequestType & USB_DIR_IN)
2312 ? USB_DIR_IN : USB_DIR_OUT; 2389 ? USB_DIR_IN : USB_DIR_OUT;
2313 VDBG(dev, "dev->ep0_dir = 0x%x, wLength = %d\n", 2390 dev_vdbg(&dev->pdev->dev,
2391 "dev->ep0_dir = 0x%x, wLength = %d\n",
2314 dev->ep0_dir, wLength); 2392 dev->ep0_dir, wLength);
2315 spin_unlock(&dev->lock); 2393 spin_unlock(&dev->lock);
2316 if (dev->driver->setup(&dev->gadget, 2394 if (dev->driver->setup(&dev->gadget,
@@ -2322,7 +2400,8 @@ delegate:
2322 } else { 2400 } else {
2323 /* no DATA phase, IN STATUS phase from gadget */ 2401 /* no DATA phase, IN STATUS phase from gadget */
2324 dev->ep0_dir = USB_DIR_IN; 2402 dev->ep0_dir = USB_DIR_IN;
2325 VDBG(dev, "dev->ep0_dir = 0x%x, wLength = %d\n", 2403 dev_vdbg(&dev->pdev->dev,
2404 "dev->ep0_dir = 0x%x, wLength = %d\n",
2326 dev->ep0_dir, wLength); 2405 dev->ep0_dir, wLength);
2327 spin_unlock(&dev->lock); 2406 spin_unlock(&dev->lock);
2328 if (dev->driver->setup(&dev->gadget, 2407 if (dev->driver->setup(&dev->gadget,
@@ -2334,8 +2413,7 @@ delegate:
2334 break; 2413 break;
2335 } 2414 }
2336end: 2415end:
2337 VDBG(dev, "<--- %s()\n", __func__); 2416 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2338 return;
2339} 2417}
2340 2418
2341 2419
@@ -2359,23 +2437,27 @@ static int process_ep_req(struct langwell_udc *dev, int index,
2359 td_complete = 0; 2437 td_complete = 0;
2360 actual = curr_req->req.length; 2438 actual = curr_req->req.length;
2361 2439
2362 VDBG(dev, "---> %s()\n", __func__); 2440 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2363 2441
2364 for (i = 0; i < curr_req->dtd_count; i++) { 2442 for (i = 0; i < curr_req->dtd_count; i++) {
2365 remaining_length = le16_to_cpu(curr_dtd->dtd_total);
2366 actual -= remaining_length;
2367 2443
2368 /* command execution states by dTD */ 2444 /* command execution states by dTD */
2369 dtd_status = curr_dtd->dtd_status; 2445 dtd_status = curr_dtd->dtd_status;
2370 2446
2447 barrier();
2448 remaining_length = le16_to_cpu(curr_dtd->dtd_total);
2449 actual -= remaining_length;
2450
2371 if (!dtd_status) { 2451 if (!dtd_status) {
2372 /* transfers completed successfully */ 2452 /* transfers completed successfully */
2373 if (!remaining_length) { 2453 if (!remaining_length) {
2374 td_complete++; 2454 td_complete++;
2375 VDBG(dev, "dTD transmitted successfully\n"); 2455 dev_vdbg(&dev->pdev->dev,
2456 "dTD transmitted successfully\n");
2376 } else { 2457 } else {
2377 if (dir) { 2458 if (dir) {
2378 VDBG(dev, "TX dTD remains data\n"); 2459 dev_vdbg(&dev->pdev->dev,
2460 "TX dTD remains data\n");
2379 retval = -EPROTO; 2461 retval = -EPROTO;
2380 break; 2462 break;
2381 2463
@@ -2387,27 +2469,32 @@ static int process_ep_req(struct langwell_udc *dev, int index,
2387 } else { 2469 } else {
2388 /* transfers completed with errors */ 2470 /* transfers completed with errors */
2389 if (dtd_status & DTD_STS_ACTIVE) { 2471 if (dtd_status & DTD_STS_ACTIVE) {
2390 DBG(dev, "request not completed\n"); 2472 dev_dbg(&dev->pdev->dev,
2473 "dTD status ACTIVE dQH[%d]\n", index);
2391 retval = 1; 2474 retval = 1;
2392 return retval; 2475 return retval;
2393 } else if (dtd_status & DTD_STS_HALTED) { 2476 } else if (dtd_status & DTD_STS_HALTED) {
2394 ERROR(dev, "dTD error %08x dQH[%d]\n", 2477 dev_err(&dev->pdev->dev,
2395 dtd_status, index); 2478 "dTD error %08x dQH[%d]\n",
2479 dtd_status, index);
2396 /* clear the errors and halt condition */ 2480 /* clear the errors and halt condition */
2397 curr_dqh->dtd_status = 0; 2481 curr_dqh->dtd_status = 0;
2398 retval = -EPIPE; 2482 retval = -EPIPE;
2399 break; 2483 break;
2400 } else if (dtd_status & DTD_STS_DBE) { 2484 } else if (dtd_status & DTD_STS_DBE) {
2401 DBG(dev, "data buffer (overflow) error\n"); 2485 dev_dbg(&dev->pdev->dev,
2486 "data buffer (overflow) error\n");
2402 retval = -EPROTO; 2487 retval = -EPROTO;
2403 break; 2488 break;
2404 } else if (dtd_status & DTD_STS_TRE) { 2489 } else if (dtd_status & DTD_STS_TRE) {
2405 DBG(dev, "transaction(ISO) error\n"); 2490 dev_dbg(&dev->pdev->dev,
2491 "transaction(ISO) error\n");
2406 retval = -EILSEQ; 2492 retval = -EILSEQ;
2407 break; 2493 break;
2408 } else 2494 } else
2409 ERROR(dev, "unknown error (0x%x)!\n", 2495 dev_err(&dev->pdev->dev,
2410 dtd_status); 2496 "unknown error (0x%x)!\n",
2497 dtd_status);
2411 } 2498 }
2412 2499
2413 if (i != curr_req->dtd_count - 1) 2500 if (i != curr_req->dtd_count - 1)
@@ -2420,7 +2507,7 @@ static int process_ep_req(struct langwell_udc *dev, int index,
2420 2507
2421 curr_req->req.actual = actual; 2508 curr_req->req.actual = actual;
2422 2509
2423 VDBG(dev, "<--- %s()\n", __func__); 2510 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2424 return 0; 2511 return 0;
2425} 2512}
2426 2513
@@ -2430,7 +2517,7 @@ static void ep0_req_complete(struct langwell_udc *dev,
2430 struct langwell_ep *ep0, struct langwell_request *req) 2517 struct langwell_ep *ep0, struct langwell_request *req)
2431{ 2518{
2432 u32 new_addr; 2519 u32 new_addr;
2433 VDBG(dev, "---> %s()\n", __func__); 2520 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2434 2521
2435 if (dev->usb_state == USB_STATE_ADDRESS) { 2522 if (dev->usb_state == USB_STATE_ADDRESS) {
2436 /* set the new address */ 2523 /* set the new address */
@@ -2438,7 +2525,7 @@ static void ep0_req_complete(struct langwell_udc *dev,
2438 writel(new_addr << USBADR_SHIFT, &dev->op_regs->deviceaddr); 2525 writel(new_addr << USBADR_SHIFT, &dev->op_regs->deviceaddr);
2439 2526
2440 new_addr = USBADR(readl(&dev->op_regs->deviceaddr)); 2527 new_addr = USBADR(readl(&dev->op_regs->deviceaddr));
2441 VDBG(dev, "new_addr = %d\n", new_addr); 2528 dev_vdbg(&dev->pdev->dev, "new_addr = %d\n", new_addr);
2442 } 2529 }
2443 2530
2444 done(ep0, req, 0); 2531 done(ep0, req, 0);
@@ -2458,14 +2545,14 @@ static void ep0_req_complete(struct langwell_udc *dev,
2458 dev->ep0_state = WAIT_FOR_SETUP; 2545 dev->ep0_state = WAIT_FOR_SETUP;
2459 break; 2546 break;
2460 case WAIT_FOR_SETUP: 2547 case WAIT_FOR_SETUP:
2461 ERROR(dev, "unexpect ep0 packets\n"); 2548 dev_err(&dev->pdev->dev, "unexpect ep0 packets\n");
2462 break; 2549 break;
2463 default: 2550 default:
2464 ep0_stall(dev); 2551 ep0_stall(dev);
2465 break; 2552 break;
2466 } 2553 }
2467 2554
2468 VDBG(dev, "<--- %s()\n", __func__); 2555 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2469} 2556}
2470 2557
2471 2558
@@ -2477,16 +2564,17 @@ static void handle_trans_complete(struct langwell_udc *dev)
2477 struct langwell_ep *epn; 2564 struct langwell_ep *epn;
2478 struct langwell_request *curr_req, *temp_req; 2565 struct langwell_request *curr_req, *temp_req;
2479 2566
2480 VDBG(dev, "---> %s()\n", __func__); 2567 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2481 2568
2482 complete_bits = readl(&dev->op_regs->endptcomplete); 2569 complete_bits = readl(&dev->op_regs->endptcomplete);
2483 VDBG(dev, "endptcomplete register: 0x%08x\n", complete_bits); 2570 dev_vdbg(&dev->pdev->dev, "endptcomplete register: 0x%08x\n",
2571 complete_bits);
2484 2572
2485 /* Write-Clear the bits in endptcomplete register */ 2573 /* Write-Clear the bits in endptcomplete register */
2486 writel(complete_bits, &dev->op_regs->endptcomplete); 2574 writel(complete_bits, &dev->op_regs->endptcomplete);
2487 2575
2488 if (!complete_bits) { 2576 if (!complete_bits) {
2489 DBG(dev, "complete_bits = 0\n"); 2577 dev_dbg(&dev->pdev->dev, "complete_bits = 0\n");
2490 goto done; 2578 goto done;
2491 } 2579 }
2492 2580
@@ -2506,23 +2594,25 @@ static void handle_trans_complete(struct langwell_udc *dev)
2506 epn = &dev->ep[i]; 2594 epn = &dev->ep[i];
2507 2595
2508 if (epn->name == NULL) { 2596 if (epn->name == NULL) {
2509 WARNING(dev, "invalid endpoint\n"); 2597 dev_warn(&dev->pdev->dev, "invalid endpoint\n");
2510 continue; 2598 continue;
2511 } 2599 }
2512 2600
2513 if (i < 2) 2601 if (i < 2)
2514 /* ep0 in and out */ 2602 /* ep0 in and out */
2515 DBG(dev, "%s-%s transfer completed\n", 2603 dev_dbg(&dev->pdev->dev, "%s-%s transfer completed\n",
2516 epn->name, 2604 epn->name,
2517 is_in(epn) ? "in" : "out"); 2605 is_in(epn) ? "in" : "out");
2518 else 2606 else
2519 DBG(dev, "%s transfer completed\n", epn->name); 2607 dev_dbg(&dev->pdev->dev, "%s transfer completed\n",
2608 epn->name);
2520 2609
2521 /* process the req queue until an uncomplete request */ 2610 /* process the req queue until an uncomplete request */
2522 list_for_each_entry_safe(curr_req, temp_req, 2611 list_for_each_entry_safe(curr_req, temp_req,
2523 &epn->queue, queue) { 2612 &epn->queue, queue) {
2524 status = process_ep_req(dev, i, curr_req); 2613 status = process_ep_req(dev, i, curr_req);
2525 VDBG(dev, "%s req status: %d\n", epn->name, status); 2614 dev_vdbg(&dev->pdev->dev, "%s req status: %d\n",
2615 epn->name, status);
2526 2616
2527 if (status) 2617 if (status)
2528 break; 2618 break;
@@ -2540,8 +2630,7 @@ static void handle_trans_complete(struct langwell_udc *dev)
2540 } 2630 }
2541 } 2631 }
2542done: 2632done:
2543 VDBG(dev, "<--- %s()\n", __func__); 2633 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2544 return;
2545} 2634}
2546 2635
2547 2636
@@ -2551,14 +2640,14 @@ static void handle_port_change(struct langwell_udc *dev)
2551 u32 portsc1, devlc; 2640 u32 portsc1, devlc;
2552 u32 speed; 2641 u32 speed;
2553 2642
2554 VDBG(dev, "---> %s()\n", __func__); 2643 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2555 2644
2556 if (dev->bus_reset) 2645 if (dev->bus_reset)
2557 dev->bus_reset = 0; 2646 dev->bus_reset = 0;
2558 2647
2559 portsc1 = readl(&dev->op_regs->portsc1); 2648 portsc1 = readl(&dev->op_regs->portsc1);
2560 devlc = readl(&dev->op_regs->devlc); 2649 devlc = readl(&dev->op_regs->devlc);
2561 VDBG(dev, "portsc1 = 0x%08x, devlc = 0x%08x\n", 2650 dev_vdbg(&dev->pdev->dev, "portsc1 = 0x%08x, devlc = 0x%08x\n",
2562 portsc1, devlc); 2651 portsc1, devlc);
2563 2652
2564 /* bus reset is finished */ 2653 /* bus reset is finished */
@@ -2579,25 +2668,22 @@ static void handle_port_change(struct langwell_udc *dev)
2579 dev->gadget.speed = USB_SPEED_UNKNOWN; 2668 dev->gadget.speed = USB_SPEED_UNKNOWN;
2580 break; 2669 break;
2581 } 2670 }
2582 VDBG(dev, "speed = %d, dev->gadget.speed = %d\n", 2671 dev_vdbg(&dev->pdev->dev,
2672 "speed = %d, dev->gadget.speed = %d\n",
2583 speed, dev->gadget.speed); 2673 speed, dev->gadget.speed);
2584 } 2674 }
2585 2675
2586 /* LPM L0 to L1 */ 2676 /* LPM L0 to L1 */
2587 if (dev->lpm && dev->lpm_state == LPM_L0) 2677 if (dev->lpm && dev->lpm_state == LPM_L0)
2588 if (portsc1 & PORTS_SUSP && portsc1 & PORTS_SLP) { 2678 if (portsc1 & PORTS_SUSP && portsc1 & PORTS_SLP) {
2589 INFO(dev, "LPM L0 to L1\n"); 2679 dev_info(&dev->pdev->dev, "LPM L0 to L1\n");
2590 dev->lpm_state = LPM_L1; 2680 dev->lpm_state = LPM_L1;
2591 } 2681 }
2592 2682
2593 /* LPM L1 to L0, force resume or remote wakeup finished */ 2683 /* LPM L1 to L0, force resume or remote wakeup finished */
2594 if (dev->lpm && dev->lpm_state == LPM_L1) 2684 if (dev->lpm && dev->lpm_state == LPM_L1)
2595 if (!(portsc1 & PORTS_SUSP)) { 2685 if (!(portsc1 & PORTS_SUSP)) {
2596 if (portsc1 & PORTS_SLP) 2686 dev_info(&dev->pdev->dev, "LPM L1 to L0\n");
2597 INFO(dev, "LPM L1 to L0, force resume\n");
2598 else
2599 INFO(dev, "LPM L1 to L0, remote wakeup\n");
2600
2601 dev->lpm_state = LPM_L0; 2687 dev->lpm_state = LPM_L0;
2602 } 2688 }
2603 2689
@@ -2605,7 +2691,7 @@ static void handle_port_change(struct langwell_udc *dev)
2605 if (!dev->resume_state) 2691 if (!dev->resume_state)
2606 dev->usb_state = USB_STATE_DEFAULT; 2692 dev->usb_state = USB_STATE_DEFAULT;
2607 2693
2608 VDBG(dev, "<--- %s()\n", __func__); 2694 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2609} 2695}
2610 2696
2611 2697
@@ -2617,7 +2703,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
2617 endptcomplete; 2703 endptcomplete;
2618 unsigned long timeout; 2704 unsigned long timeout;
2619 2705
2620 VDBG(dev, "---> %s()\n", __func__); 2706 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2621 2707
2622 /* Write-Clear the device address */ 2708 /* Write-Clear the device address */
2623 deviceaddr = readl(&dev->op_regs->deviceaddr); 2709 deviceaddr = readl(&dev->op_regs->deviceaddr);
@@ -2634,7 +2720,10 @@ static void handle_usb_reset(struct langwell_udc *dev)
2634 2720
2635 dev->ep0_dir = USB_DIR_OUT; 2721 dev->ep0_dir = USB_DIR_OUT;
2636 dev->ep0_state = WAIT_FOR_SETUP; 2722 dev->ep0_state = WAIT_FOR_SETUP;
2637 dev->remote_wakeup = 0; /* default to 0 on reset */ 2723
2724 /* remote wakeup reset to 0 when the device is reset */
2725 dev->remote_wakeup = 0;
2726 dev->dev_status = 1 << USB_DEVICE_SELF_POWERED;
2638 dev->gadget.b_hnp_enable = 0; 2727 dev->gadget.b_hnp_enable = 0;
2639 dev->gadget.a_hnp_support = 0; 2728 dev->gadget.a_hnp_support = 0;
2640 dev->gadget.a_alt_hnp_support = 0; 2729 dev->gadget.a_alt_hnp_support = 0;
@@ -2651,7 +2740,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
2651 timeout = jiffies + PRIME_TIMEOUT; 2740 timeout = jiffies + PRIME_TIMEOUT;
2652 while (readl(&dev->op_regs->endptprime)) { 2741 while (readl(&dev->op_regs->endptprime)) {
2653 if (time_after(jiffies, timeout)) { 2742 if (time_after(jiffies, timeout)) {
2654 ERROR(dev, "USB reset timeout\n"); 2743 dev_err(&dev->pdev->dev, "USB reset timeout\n");
2655 break; 2744 break;
2656 } 2745 }
2657 cpu_relax(); 2746 cpu_relax();
@@ -2661,7 +2750,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
2661 writel((u32) ~0, &dev->op_regs->endptflush); 2750 writel((u32) ~0, &dev->op_regs->endptflush);
2662 2751
2663 if (readl(&dev->op_regs->portsc1) & PORTS_PR) { 2752 if (readl(&dev->op_regs->portsc1) & PORTS_PR) {
2664 VDBG(dev, "USB bus reset\n"); 2753 dev_vdbg(&dev->pdev->dev, "USB bus reset\n");
2665 /* bus is reseting */ 2754 /* bus is reseting */
2666 dev->bus_reset = 1; 2755 dev->bus_reset = 1;
2667 2756
@@ -2669,7 +2758,7 @@ static void handle_usb_reset(struct langwell_udc *dev)
2669 stop_activity(dev, dev->driver); 2758 stop_activity(dev, dev->driver);
2670 dev->usb_state = USB_STATE_DEFAULT; 2759 dev->usb_state = USB_STATE_DEFAULT;
2671 } else { 2760 } else {
2672 VDBG(dev, "device controller reset\n"); 2761 dev_vdbg(&dev->pdev->dev, "device controller reset\n");
2673 /* controller reset */ 2762 /* controller reset */
2674 langwell_udc_reset(dev); 2763 langwell_udc_reset(dev);
2675 2764
@@ -2691,15 +2780,14 @@ static void handle_usb_reset(struct langwell_udc *dev)
2691 dev->lotg->hsm.b_hnp_enable = 0; 2780 dev->lotg->hsm.b_hnp_enable = 0;
2692#endif 2781#endif
2693 2782
2694 VDBG(dev, "<--- %s()\n", __func__); 2783 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2695} 2784}
2696 2785
2697 2786
2698/* USB bus suspend/resume interrupt */ 2787/* USB bus suspend/resume interrupt */
2699static void handle_bus_suspend(struct langwell_udc *dev) 2788static void handle_bus_suspend(struct langwell_udc *dev)
2700{ 2789{
2701 u32 devlc; 2790 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2702 DBG(dev, "---> %s()\n", __func__);
2703 2791
2704 dev->resume_state = dev->usb_state; 2792 dev->resume_state = dev->usb_state;
2705 dev->usb_state = USB_STATE_SUSPENDED; 2793 dev->usb_state = USB_STATE_SUSPENDED;
@@ -2733,33 +2821,29 @@ static void handle_bus_suspend(struct langwell_udc *dev)
2733 spin_unlock(&dev->lock); 2821 spin_unlock(&dev->lock);
2734 dev->driver->suspend(&dev->gadget); 2822 dev->driver->suspend(&dev->gadget);
2735 spin_lock(&dev->lock); 2823 spin_lock(&dev->lock);
2736 DBG(dev, "suspend %s\n", dev->driver->driver.name); 2824 dev_dbg(&dev->pdev->dev, "suspend %s\n",
2825 dev->driver->driver.name);
2737 } 2826 }
2738 } 2827 }
2739 2828
2740 /* enter PHY low power suspend */ 2829 /* enter PHY low power suspend */
2741 devlc = readl(&dev->op_regs->devlc); 2830 if (dev->pdev->device != 0x0829)
2742 VDBG(dev, "devlc = 0x%08x\n", devlc); 2831 langwell_phy_low_power(dev, 0);
2743 devlc |= LPM_PHCD;
2744 writel(devlc, &dev->op_regs->devlc);
2745 2832
2746 DBG(dev, "<--- %s()\n", __func__); 2833 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2747} 2834}
2748 2835
2749 2836
2750static void handle_bus_resume(struct langwell_udc *dev) 2837static void handle_bus_resume(struct langwell_udc *dev)
2751{ 2838{
2752 u32 devlc; 2839 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2753 DBG(dev, "---> %s()\n", __func__);
2754 2840
2755 dev->usb_state = dev->resume_state; 2841 dev->usb_state = dev->resume_state;
2756 dev->resume_state = 0; 2842 dev->resume_state = 0;
2757 2843
2758 /* exit PHY low power suspend */ 2844 /* exit PHY low power suspend */
2759 devlc = readl(&dev->op_regs->devlc); 2845 if (dev->pdev->device != 0x0829)
2760 VDBG(dev, "devlc = 0x%08x\n", devlc); 2846 langwell_phy_low_power(dev, 0);
2761 devlc &= ~LPM_PHCD;
2762 writel(devlc, &dev->op_regs->devlc);
2763 2847
2764#ifdef OTG_TRANSCEIVER 2848#ifdef OTG_TRANSCEIVER
2765 if (dev->lotg->otg.default_a == 0) 2849 if (dev->lotg->otg.default_a == 0)
@@ -2772,11 +2856,12 @@ static void handle_bus_resume(struct langwell_udc *dev)
2772 spin_unlock(&dev->lock); 2856 spin_unlock(&dev->lock);
2773 dev->driver->resume(&dev->gadget); 2857 dev->driver->resume(&dev->gadget);
2774 spin_lock(&dev->lock); 2858 spin_lock(&dev->lock);
2775 DBG(dev, "resume %s\n", dev->driver->driver.name); 2859 dev_dbg(&dev->pdev->dev, "resume %s\n",
2860 dev->driver->driver.name);
2776 } 2861 }
2777 } 2862 }
2778 2863
2779 DBG(dev, "<--- %s()\n", __func__); 2864 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2780} 2865}
2781 2866
2782 2867
@@ -2789,11 +2874,11 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2789 irq_sts, 2874 irq_sts,
2790 portsc1; 2875 portsc1;
2791 2876
2792 VDBG(dev, "---> %s()\n", __func__); 2877 dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__);
2793 2878
2794 if (dev->stopped) { 2879 if (dev->stopped) {
2795 VDBG(dev, "handle IRQ_NONE\n"); 2880 dev_vdbg(&dev->pdev->dev, "handle IRQ_NONE\n");
2796 VDBG(dev, "<--- %s()\n", __func__); 2881 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2797 return IRQ_NONE; 2882 return IRQ_NONE;
2798 } 2883 }
2799 2884
@@ -2806,12 +2891,13 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2806 usbintr = readl(&dev->op_regs->usbintr); 2891 usbintr = readl(&dev->op_regs->usbintr);
2807 2892
2808 irq_sts = usbsts & usbintr; 2893 irq_sts = usbsts & usbintr;
2809 VDBG(dev, "usbsts = 0x%08x, usbintr = 0x%08x, irq_sts = 0x%08x\n", 2894 dev_vdbg(&dev->pdev->dev,
2895 "usbsts = 0x%08x, usbintr = 0x%08x, irq_sts = 0x%08x\n",
2810 usbsts, usbintr, irq_sts); 2896 usbsts, usbintr, irq_sts);
2811 2897
2812 if (!irq_sts) { 2898 if (!irq_sts) {
2813 VDBG(dev, "handle IRQ_NONE\n"); 2899 dev_vdbg(&dev->pdev->dev, "handle IRQ_NONE\n");
2814 VDBG(dev, "<--- %s()\n", __func__); 2900 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2815 spin_unlock(&dev->lock); 2901 spin_unlock(&dev->lock);
2816 return IRQ_NONE; 2902 return IRQ_NONE;
2817 } 2903 }
@@ -2827,12 +2913,13 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2827 2913
2828 /* USB interrupt */ 2914 /* USB interrupt */
2829 if (irq_sts & STS_UI) { 2915 if (irq_sts & STS_UI) {
2830 VDBG(dev, "USB interrupt\n"); 2916 dev_vdbg(&dev->pdev->dev, "USB interrupt\n");
2831 2917
2832 /* setup packet received from ep0 */ 2918 /* setup packet received from ep0 */
2833 if (readl(&dev->op_regs->endptsetupstat) 2919 if (readl(&dev->op_regs->endptsetupstat)
2834 & EP0SETUPSTAT_MASK) { 2920 & EP0SETUPSTAT_MASK) {
2835 VDBG(dev, "USB SETUP packet received interrupt\n"); 2921 dev_vdbg(&dev->pdev->dev,
2922 "USB SETUP packet received interrupt\n");
2836 /* setup tripwire semaphone */ 2923 /* setup tripwire semaphone */
2837 setup_tripwire(dev); 2924 setup_tripwire(dev);
2838 handle_setup_packet(dev, &dev->local_setup_buff); 2925 handle_setup_packet(dev, &dev->local_setup_buff);
@@ -2840,7 +2927,8 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2840 2927
2841 /* USB transfer completion */ 2928 /* USB transfer completion */
2842 if (readl(&dev->op_regs->endptcomplete)) { 2929 if (readl(&dev->op_regs->endptcomplete)) {
2843 VDBG(dev, "USB transfer completion interrupt\n"); 2930 dev_vdbg(&dev->pdev->dev,
2931 "USB transfer completion interrupt\n");
2844 handle_trans_complete(dev); 2932 handle_trans_complete(dev);
2845 } 2933 }
2846 } 2934 }
@@ -2848,36 +2936,36 @@ static irqreturn_t langwell_irq(int irq, void *_dev)
2848 /* SOF received interrupt (for ISO transfer) */ 2936 /* SOF received interrupt (for ISO transfer) */
2849 if (irq_sts & STS_SRI) { 2937 if (irq_sts & STS_SRI) {
2850 /* FIXME */ 2938 /* FIXME */
2851 /* VDBG(dev, "SOF received interrupt\n"); */ 2939 /* dev_vdbg(&dev->pdev->dev, "SOF received interrupt\n"); */
2852 } 2940 }
2853 2941
2854 /* port change detect interrupt */ 2942 /* port change detect interrupt */
2855 if (irq_sts & STS_PCI) { 2943 if (irq_sts & STS_PCI) {
2856 VDBG(dev, "port change detect interrupt\n"); 2944 dev_vdbg(&dev->pdev->dev, "port change detect interrupt\n");
2857 handle_port_change(dev); 2945 handle_port_change(dev);
2858 } 2946 }
2859 2947
2860 /* suspend interrrupt */ 2948 /* suspend interrrupt */
2861 if (irq_sts & STS_SLI) { 2949 if (irq_sts & STS_SLI) {
2862 VDBG(dev, "suspend interrupt\n"); 2950 dev_vdbg(&dev->pdev->dev, "suspend interrupt\n");
2863 handle_bus_suspend(dev); 2951 handle_bus_suspend(dev);
2864 } 2952 }
2865 2953
2866 /* USB reset interrupt */ 2954 /* USB reset interrupt */
2867 if (irq_sts & STS_URI) { 2955 if (irq_sts & STS_URI) {
2868 VDBG(dev, "USB reset interrupt\n"); 2956 dev_vdbg(&dev->pdev->dev, "USB reset interrupt\n");
2869 handle_usb_reset(dev); 2957 handle_usb_reset(dev);
2870 } 2958 }
2871 2959
2872 /* USB error or system error interrupt */ 2960 /* USB error or system error interrupt */
2873 if (irq_sts & (STS_UEI | STS_SEI)) { 2961 if (irq_sts & (STS_UEI | STS_SEI)) {
2874 /* FIXME */ 2962 /* FIXME */
2875 WARNING(dev, "error IRQ, irq_sts: %x\n", irq_sts); 2963 dev_warn(&dev->pdev->dev, "error IRQ, irq_sts: %x\n", irq_sts);
2876 } 2964 }
2877 2965
2878 spin_unlock(&dev->lock); 2966 spin_unlock(&dev->lock);
2879 2967
2880 VDBG(dev, "<--- %s()\n", __func__); 2968 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2881 return IRQ_HANDLED; 2969 return IRQ_HANDLED;
2882} 2970}
2883 2971
@@ -2889,15 +2977,59 @@ static void gadget_release(struct device *_dev)
2889{ 2977{
2890 struct langwell_udc *dev = the_controller; 2978 struct langwell_udc *dev = the_controller;
2891 2979
2892 DBG(dev, "---> %s()\n", __func__); 2980 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2893 2981
2894 complete(dev->done); 2982 complete(dev->done);
2895 2983
2896 DBG(dev, "<--- %s()\n", __func__); 2984 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2897 kfree(dev); 2985 kfree(dev);
2898} 2986}
2899 2987
2900 2988
2989/* enable SRAM caching if SRAM detected */
2990static void sram_init(struct langwell_udc *dev)
2991{
2992 struct pci_dev *pdev = dev->pdev;
2993
2994 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2995
2996 dev->sram_addr = pci_resource_start(pdev, 1);
2997 dev->sram_size = pci_resource_len(pdev, 1);
2998 dev_info(&dev->pdev->dev, "Found private SRAM at %x size:%x\n",
2999 dev->sram_addr, dev->sram_size);
3000 dev->got_sram = 1;
3001
3002 if (pci_request_region(pdev, 1, kobject_name(&pdev->dev.kobj))) {
3003 dev_warn(&dev->pdev->dev, "SRAM request failed\n");
3004 dev->got_sram = 0;
3005 } else if (!dma_declare_coherent_memory(&pdev->dev, dev->sram_addr,
3006 dev->sram_addr, dev->sram_size, DMA_MEMORY_MAP)) {
3007 dev_warn(&dev->pdev->dev, "SRAM DMA declare failed\n");
3008 pci_release_region(pdev, 1);
3009 dev->got_sram = 0;
3010 }
3011
3012 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3013}
3014
3015
3016/* release SRAM caching */
3017static void sram_deinit(struct langwell_udc *dev)
3018{
3019 struct pci_dev *pdev = dev->pdev;
3020
3021 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3022
3023 dma_release_declared_memory(&pdev->dev);
3024 pci_release_region(pdev, 1);
3025
3026 dev->got_sram = 0;
3027
3028 dev_info(&dev->pdev->dev, "release SRAM caching\n");
3029 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3030}
3031
3032
2901/* tear down the binding between this driver and the pci device */ 3033/* tear down the binding between this driver and the pci device */
2902static void langwell_udc_remove(struct pci_dev *pdev) 3034static void langwell_udc_remove(struct pci_dev *pdev)
2903{ 3035{
@@ -2906,23 +3038,29 @@ static void langwell_udc_remove(struct pci_dev *pdev)
2906 DECLARE_COMPLETION(done); 3038 DECLARE_COMPLETION(done);
2907 3039
2908 BUG_ON(dev->driver); 3040 BUG_ON(dev->driver);
2909 DBG(dev, "---> %s()\n", __func__); 3041 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
2910 3042
2911 dev->done = &done; 3043 dev->done = &done;
2912 3044
2913 /* free memory allocated in probe */ 3045#ifndef OTG_TRANSCEIVER
3046 /* free dTD dma_pool and dQH */
2914 if (dev->dtd_pool) 3047 if (dev->dtd_pool)
2915 dma_pool_destroy(dev->dtd_pool); 3048 dma_pool_destroy(dev->dtd_pool);
2916 3049
3050 if (dev->ep_dqh)
3051 dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
3052 dev->ep_dqh, dev->ep_dqh_dma);
3053
3054 /* release SRAM caching */
3055 if (dev->has_sram && dev->got_sram)
3056 sram_deinit(dev);
3057#endif
3058
2917 if (dev->status_req) { 3059 if (dev->status_req) {
2918 kfree(dev->status_req->req.buf); 3060 kfree(dev->status_req->req.buf);
2919 kfree(dev->status_req); 3061 kfree(dev->status_req);
2920 } 3062 }
2921 3063
2922 if (dev->ep_dqh)
2923 dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
2924 dev->ep_dqh, dev->ep_dqh_dma);
2925
2926 kfree(dev->ep); 3064 kfree(dev->ep);
2927 3065
2928 /* diable IRQ handler */ 3066 /* diable IRQ handler */
@@ -2949,11 +3087,12 @@ static void langwell_udc_remove(struct pci_dev *pdev)
2949 3087
2950 dev->cap_regs = NULL; 3088 dev->cap_regs = NULL;
2951 3089
2952 INFO(dev, "unbind\n"); 3090 dev_info(&dev->pdev->dev, "unbind\n");
2953 DBG(dev, "<--- %s()\n", __func__); 3091 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
2954 3092
2955 device_unregister(&dev->gadget.dev); 3093 device_unregister(&dev->gadget.dev);
2956 device_remove_file(&pdev->dev, &dev_attr_langwell_udc); 3094 device_remove_file(&pdev->dev, &dev_attr_langwell_udc);
3095 device_remove_file(&pdev->dev, &dev_attr_remote_wakeup);
2957 3096
2958#ifndef OTG_TRANSCEIVER 3097#ifndef OTG_TRANSCEIVER
2959 pci_set_drvdata(pdev, NULL); 3098 pci_set_drvdata(pdev, NULL);
@@ -2997,7 +3136,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
2997 spin_lock_init(&dev->lock); 3136 spin_lock_init(&dev->lock);
2998 3137
2999 dev->pdev = pdev; 3138 dev->pdev = pdev;
3000 DBG(dev, "---> %s()\n", __func__); 3139 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3001 3140
3002#ifdef OTG_TRANSCEIVER 3141#ifdef OTG_TRANSCEIVER
3003 /* PCI device is already enabled by otg_transceiver driver */ 3142 /* PCI device is already enabled by otg_transceiver driver */
@@ -3022,7 +3161,7 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3022 resource = pci_resource_start(pdev, 0); 3161 resource = pci_resource_start(pdev, 0);
3023 len = pci_resource_len(pdev, 0); 3162 len = pci_resource_len(pdev, 0);
3024 if (!request_mem_region(resource, len, driver_name)) { 3163 if (!request_mem_region(resource, len, driver_name)) {
3025 ERROR(dev, "controller already in use\n"); 3164 dev_err(&dev->pdev->dev, "controller already in use\n");
3026 retval = -EBUSY; 3165 retval = -EBUSY;
3027 goto error; 3166 goto error;
3028 } 3167 }
@@ -3031,33 +3170,43 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3031 base = ioremap_nocache(resource, len); 3170 base = ioremap_nocache(resource, len);
3032#endif 3171#endif
3033 if (base == NULL) { 3172 if (base == NULL) {
3034 ERROR(dev, "can't map memory\n"); 3173 dev_err(&dev->pdev->dev, "can't map memory\n");
3035 retval = -EFAULT; 3174 retval = -EFAULT;
3036 goto error; 3175 goto error;
3037 } 3176 }
3038 3177
3039 dev->cap_regs = (struct langwell_cap_regs __iomem *) base; 3178 dev->cap_regs = (struct langwell_cap_regs __iomem *) base;
3040 VDBG(dev, "dev->cap_regs: %p\n", dev->cap_regs); 3179 dev_vdbg(&dev->pdev->dev, "dev->cap_regs: %p\n", dev->cap_regs);
3041 dev->op_regs = (struct langwell_op_regs __iomem *) 3180 dev->op_regs = (struct langwell_op_regs __iomem *)
3042 (base + OP_REG_OFFSET); 3181 (base + OP_REG_OFFSET);
3043 VDBG(dev, "dev->op_regs: %p\n", dev->op_regs); 3182 dev_vdbg(&dev->pdev->dev, "dev->op_regs: %p\n", dev->op_regs);
3044 3183
3045 /* irq setup after old hardware is cleaned up */ 3184 /* irq setup after old hardware is cleaned up */
3046 if (!pdev->irq) { 3185 if (!pdev->irq) {
3047 ERROR(dev, "No IRQ. Check PCI setup!\n"); 3186 dev_err(&dev->pdev->dev, "No IRQ. Check PCI setup!\n");
3048 retval = -ENODEV; 3187 retval = -ENODEV;
3049 goto error; 3188 goto error;
3050 } 3189 }
3051 3190
3191 dev->has_sram = 1;
3192 dev->got_sram = 0;
3193 dev_vdbg(&dev->pdev->dev, "dev->has_sram: %d\n", dev->has_sram);
3194
3052#ifndef OTG_TRANSCEIVER 3195#ifndef OTG_TRANSCEIVER
3053 INFO(dev, "irq %d, io mem: 0x%08lx, len: 0x%08lx, pci mem 0x%p\n", 3196 /* enable SRAM caching if detected */
3197 if (dev->has_sram && !dev->got_sram)
3198 sram_init(dev);
3199
3200 dev_info(&dev->pdev->dev,
3201 "irq %d, io mem: 0x%08lx, len: 0x%08lx, pci mem 0x%p\n",
3054 pdev->irq, resource, len, base); 3202 pdev->irq, resource, len, base);
3055 /* enables bus-mastering for device dev */ 3203 /* enables bus-mastering for device dev */
3056 pci_set_master(pdev); 3204 pci_set_master(pdev);
3057 3205
3058 if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED, 3206 if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED,
3059 driver_name, dev) != 0) { 3207 driver_name, dev) != 0) {
3060 ERROR(dev, "request interrupt %d failed\n", pdev->irq); 3208 dev_err(&dev->pdev->dev,
3209 "request interrupt %d failed\n", pdev->irq);
3061 retval = -EBUSY; 3210 retval = -EBUSY;
3062 goto error; 3211 goto error;
3063 } 3212 }
@@ -3071,32 +3220,34 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3071 dev->lpm = (readl(&dev->cap_regs->hccparams) & HCC_LEN) ? 1 : 0; 3220 dev->lpm = (readl(&dev->cap_regs->hccparams) & HCC_LEN) ? 1 : 0;
3072 dev->dciversion = readw(&dev->cap_regs->dciversion); 3221 dev->dciversion = readw(&dev->cap_regs->dciversion);
3073 dev->devcap = (readl(&dev->cap_regs->dccparams) & DEVCAP) ? 1 : 0; 3222 dev->devcap = (readl(&dev->cap_regs->dccparams) & DEVCAP) ? 1 : 0;
3074 VDBG(dev, "dev->lpm: %d\n", dev->lpm); 3223 dev_vdbg(&dev->pdev->dev, "dev->lpm: %d\n", dev->lpm);
3075 VDBG(dev, "dev->dciversion: 0x%04x\n", dev->dciversion); 3224 dev_vdbg(&dev->pdev->dev, "dev->dciversion: 0x%04x\n",
3076 VDBG(dev, "dccparams: 0x%08x\n", readl(&dev->cap_regs->dccparams)); 3225 dev->dciversion);
3077 VDBG(dev, "dev->devcap: %d\n", dev->devcap); 3226 dev_vdbg(&dev->pdev->dev, "dccparams: 0x%08x\n",
3227 readl(&dev->cap_regs->dccparams));
3228 dev_vdbg(&dev->pdev->dev, "dev->devcap: %d\n", dev->devcap);
3078 if (!dev->devcap) { 3229 if (!dev->devcap) {
3079 ERROR(dev, "can't support device mode\n"); 3230 dev_err(&dev->pdev->dev, "can't support device mode\n");
3080 retval = -ENODEV; 3231 retval = -ENODEV;
3081 goto error; 3232 goto error;
3082 } 3233 }
3083 3234
3084 /* a pair of endpoints (out/in) for each address */ 3235 /* a pair of endpoints (out/in) for each address */
3085 dev->ep_max = DEN(readl(&dev->cap_regs->dccparams)) * 2; 3236 dev->ep_max = DEN(readl(&dev->cap_regs->dccparams)) * 2;
3086 VDBG(dev, "dev->ep_max: %d\n", dev->ep_max); 3237 dev_vdbg(&dev->pdev->dev, "dev->ep_max: %d\n", dev->ep_max);
3087 3238
3088 /* allocate endpoints memory */ 3239 /* allocate endpoints memory */
3089 dev->ep = kzalloc(sizeof(struct langwell_ep) * dev->ep_max, 3240 dev->ep = kzalloc(sizeof(struct langwell_ep) * dev->ep_max,
3090 GFP_KERNEL); 3241 GFP_KERNEL);
3091 if (!dev->ep) { 3242 if (!dev->ep) {
3092 ERROR(dev, "allocate endpoints memory failed\n"); 3243 dev_err(&dev->pdev->dev, "allocate endpoints memory failed\n");
3093 retval = -ENOMEM; 3244 retval = -ENOMEM;
3094 goto error; 3245 goto error;
3095 } 3246 }
3096 3247
3097 /* allocate device dQH memory */ 3248 /* allocate device dQH memory */
3098 size = dev->ep_max * sizeof(struct langwell_dqh); 3249 size = dev->ep_max * sizeof(struct langwell_dqh);
3099 VDBG(dev, "orig size = %d\n", size); 3250 dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size);
3100 if (size < DQH_ALIGNMENT) 3251 if (size < DQH_ALIGNMENT)
3101 size = DQH_ALIGNMENT; 3252 size = DQH_ALIGNMENT;
3102 else if ((size % DQH_ALIGNMENT) != 0) { 3253 else if ((size % DQH_ALIGNMENT) != 0) {
@@ -3106,17 +3257,18 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3106 dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size, 3257 dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size,
3107 &dev->ep_dqh_dma, GFP_KERNEL); 3258 &dev->ep_dqh_dma, GFP_KERNEL);
3108 if (!dev->ep_dqh) { 3259 if (!dev->ep_dqh) {
3109 ERROR(dev, "allocate dQH memory failed\n"); 3260 dev_err(&dev->pdev->dev, "allocate dQH memory failed\n");
3110 retval = -ENOMEM; 3261 retval = -ENOMEM;
3111 goto error; 3262 goto error;
3112 } 3263 }
3113 dev->ep_dqh_size = size; 3264 dev->ep_dqh_size = size;
3114 VDBG(dev, "ep_dqh_size = %d\n", dev->ep_dqh_size); 3265 dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
3115 3266
3116 /* initialize ep0 status request structure */ 3267 /* initialize ep0 status request structure */
3117 dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL); 3268 dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL);
3118 if (!dev->status_req) { 3269 if (!dev->status_req) {
3119 ERROR(dev, "allocate status_req memory failed\n"); 3270 dev_err(&dev->pdev->dev,
3271 "allocate status_req memory failed\n");
3120 retval = -ENOMEM; 3272 retval = -ENOMEM;
3121 goto error; 3273 goto error;
3122 } 3274 }
@@ -3129,7 +3281,10 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3129 dev->resume_state = USB_STATE_NOTATTACHED; 3281 dev->resume_state = USB_STATE_NOTATTACHED;
3130 dev->usb_state = USB_STATE_POWERED; 3282 dev->usb_state = USB_STATE_POWERED;
3131 dev->ep0_dir = USB_DIR_OUT; 3283 dev->ep0_dir = USB_DIR_OUT;
3132 dev->remote_wakeup = 0; /* default to 0 on reset */ 3284
3285 /* remote wakeup reset to 0 when the device is reset */
3286 dev->remote_wakeup = 0;
3287 dev->dev_status = 1 << USB_DEVICE_SELF_POWERED;
3133 3288
3134#ifndef OTG_TRANSCEIVER 3289#ifndef OTG_TRANSCEIVER
3135 /* reset device controller */ 3290 /* reset device controller */
@@ -3174,18 +3329,20 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3174 } 3329 }
3175 3330
3176 /* done */ 3331 /* done */
3177 INFO(dev, "%s\n", driver_desc); 3332 dev_info(&dev->pdev->dev, "%s\n", driver_desc);
3178 INFO(dev, "irq %d, pci mem %p\n", pdev->irq, base); 3333 dev_info(&dev->pdev->dev, "irq %d, pci mem %p\n", pdev->irq, base);
3179 INFO(dev, "Driver version: " DRIVER_VERSION "\n"); 3334 dev_info(&dev->pdev->dev, "Driver version: " DRIVER_VERSION "\n");
3180 INFO(dev, "Support (max) %d endpoints\n", dev->ep_max); 3335 dev_info(&dev->pdev->dev, "Support (max) %d endpoints\n", dev->ep_max);
3181 INFO(dev, "Device interface version: 0x%04x\n", dev->dciversion); 3336 dev_info(&dev->pdev->dev, "Device interface version: 0x%04x\n",
3182 INFO(dev, "Controller mode: %s\n", dev->devcap ? "Device" : "Host"); 3337 dev->dciversion);
3183 INFO(dev, "Support USB LPM: %s\n", dev->lpm ? "Yes" : "No"); 3338 dev_info(&dev->pdev->dev, "Controller mode: %s\n",
3184 3339 dev->devcap ? "Device" : "Host");
3185 VDBG(dev, "After langwell_udc_probe(), print all registers:\n"); 3340 dev_info(&dev->pdev->dev, "Support USB LPM: %s\n",
3186#ifdef VERBOSE 3341 dev->lpm ? "Yes" : "No");
3342
3343 dev_vdbg(&dev->pdev->dev,
3344 "After langwell_udc_probe(), print all registers:\n");
3187 print_all_registers(dev); 3345 print_all_registers(dev);
3188#endif
3189 3346
3190 the_controller = dev; 3347 the_controller = dev;
3191 3348
@@ -3197,12 +3354,18 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3197 if (retval) 3354 if (retval)
3198 goto error; 3355 goto error;
3199 3356
3200 VDBG(dev, "<--- %s()\n", __func__); 3357 retval = device_create_file(&pdev->dev, &dev_attr_remote_wakeup);
3358 if (retval)
3359 goto error_attr1;
3360
3361 dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3201 return 0; 3362 return 0;
3202 3363
3364error_attr1:
3365 device_remove_file(&pdev->dev, &dev_attr_langwell_udc);
3203error: 3366error:
3204 if (dev) { 3367 if (dev) {
3205 DBG(dev, "<--- %s()\n", __func__); 3368 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3206 langwell_udc_remove(pdev); 3369 langwell_udc_remove(pdev);
3207 } 3370 }
3208 3371
@@ -3214,9 +3377,8 @@ error:
3214static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state) 3377static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
3215{ 3378{
3216 struct langwell_udc *dev = the_controller; 3379 struct langwell_udc *dev = the_controller;
3217 u32 devlc;
3218 3380
3219 DBG(dev, "---> %s()\n", __func__); 3381 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3220 3382
3221 /* disable interrupt and set controller to stop state */ 3383 /* disable interrupt and set controller to stop state */
3222 langwell_udc_stop(dev); 3384 langwell_udc_stop(dev);
@@ -3226,20 +3388,34 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
3226 free_irq(pdev->irq, dev); 3388 free_irq(pdev->irq, dev);
3227 dev->got_irq = 0; 3389 dev->got_irq = 0;
3228 3390
3229
3230 /* save PCI state */ 3391 /* save PCI state */
3231 pci_save_state(pdev); 3392 pci_save_state(pdev);
3232 3393
3394 spin_lock_irq(&dev->lock);
3395 /* stop all usb activities */
3396 stop_activity(dev, dev->driver);
3397 spin_unlock_irq(&dev->lock);
3398
3399 /* free dTD dma_pool and dQH */
3400 if (dev->dtd_pool)
3401 dma_pool_destroy(dev->dtd_pool);
3402
3403 if (dev->ep_dqh)
3404 dma_free_coherent(&pdev->dev, dev->ep_dqh_size,
3405 dev->ep_dqh, dev->ep_dqh_dma);
3406
3407 /* release SRAM caching */
3408 if (dev->has_sram && dev->got_sram)
3409 sram_deinit(dev);
3410
3233 /* set device power state */ 3411 /* set device power state */
3234 pci_set_power_state(pdev, PCI_D3hot); 3412 pci_set_power_state(pdev, PCI_D3hot);
3235 3413
3236 /* enter PHY low power suspend */ 3414 /* enter PHY low power suspend */
3237 devlc = readl(&dev->op_regs->devlc); 3415 if (dev->pdev->device != 0x0829)
3238 VDBG(dev, "devlc = 0x%08x\n", devlc); 3416 langwell_phy_low_power(dev, 1);
3239 devlc |= LPM_PHCD;
3240 writel(devlc, &dev->op_regs->devlc);
3241 3417
3242 DBG(dev, "<--- %s()\n", __func__); 3418 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3243 return 0; 3419 return 0;
3244} 3420}
3245 3421
@@ -3248,27 +3424,58 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
3248static int langwell_udc_resume(struct pci_dev *pdev) 3424static int langwell_udc_resume(struct pci_dev *pdev)
3249{ 3425{
3250 struct langwell_udc *dev = the_controller; 3426 struct langwell_udc *dev = the_controller;
3251 u32 devlc; 3427 size_t size;
3252 3428
3253 DBG(dev, "---> %s()\n", __func__); 3429 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3254 3430
3255 /* exit PHY low power suspend */ 3431 /* exit PHY low power suspend */
3256 devlc = readl(&dev->op_regs->devlc); 3432 if (dev->pdev->device != 0x0829)
3257 VDBG(dev, "devlc = 0x%08x\n", devlc); 3433 langwell_phy_low_power(dev, 0);
3258 devlc &= ~LPM_PHCD;
3259 writel(devlc, &dev->op_regs->devlc);
3260 3434
3261 /* set device D0 power state */ 3435 /* set device D0 power state */
3262 pci_set_power_state(pdev, PCI_D0); 3436 pci_set_power_state(pdev, PCI_D0);
3263 3437
3438 /* enable SRAM caching if detected */
3439 if (dev->has_sram && !dev->got_sram)
3440 sram_init(dev);
3441
3442 /* allocate device dQH memory */
3443 size = dev->ep_max * sizeof(struct langwell_dqh);
3444 dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size);
3445 if (size < DQH_ALIGNMENT)
3446 size = DQH_ALIGNMENT;
3447 else if ((size % DQH_ALIGNMENT) != 0) {
3448 size += DQH_ALIGNMENT + 1;
3449 size &= ~(DQH_ALIGNMENT - 1);
3450 }
3451 dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size,
3452 &dev->ep_dqh_dma, GFP_KERNEL);
3453 if (!dev->ep_dqh) {
3454 dev_err(&dev->pdev->dev, "allocate dQH memory failed\n");
3455 return -ENOMEM;
3456 }
3457 dev->ep_dqh_size = size;
3458 dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size);
3459
3460 /* create dTD dma_pool resource */
3461 dev->dtd_pool = dma_pool_create("langwell_dtd",
3462 &dev->pdev->dev,
3463 sizeof(struct langwell_dtd),
3464 DTD_ALIGNMENT,
3465 DMA_BOUNDARY);
3466
3467 if (!dev->dtd_pool)
3468 return -ENOMEM;
3469
3264 /* restore PCI state */ 3470 /* restore PCI state */
3265 pci_restore_state(pdev); 3471 pci_restore_state(pdev);
3266 3472
3267 /* enable IRQ handler */ 3473 /* enable IRQ handler */
3268 if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED, driver_name, dev) 3474 if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED,
3269 != 0) { 3475 driver_name, dev) != 0) {
3270 ERROR(dev, "request interrupt %d failed\n", pdev->irq); 3476 dev_err(&dev->pdev->dev, "request interrupt %d failed\n",
3271 return -1; 3477 pdev->irq);
3478 return -EBUSY;
3272 } 3479 }
3273 dev->got_irq = 1; 3480 dev->got_irq = 1;
3274 3481
@@ -3290,7 +3497,7 @@ static int langwell_udc_resume(struct pci_dev *pdev)
3290 dev->ep0_state = WAIT_FOR_SETUP; 3497 dev->ep0_state = WAIT_FOR_SETUP;
3291 dev->ep0_dir = USB_DIR_OUT; 3498 dev->ep0_dir = USB_DIR_OUT;
3292 3499
3293 DBG(dev, "<--- %s()\n", __func__); 3500 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3294 return 0; 3501 return 0;
3295} 3502}
3296 3503
@@ -3301,15 +3508,15 @@ static void langwell_udc_shutdown(struct pci_dev *pdev)
3301 struct langwell_udc *dev = the_controller; 3508 struct langwell_udc *dev = the_controller;
3302 u32 usbmode; 3509 u32 usbmode;
3303 3510
3304 DBG(dev, "---> %s()\n", __func__); 3511 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3305 3512
3306 /* reset controller mode to IDLE */ 3513 /* reset controller mode to IDLE */
3307 usbmode = readl(&dev->op_regs->usbmode); 3514 usbmode = readl(&dev->op_regs->usbmode);
3308 DBG(dev, "usbmode = 0x%08x\n", usbmode); 3515 dev_dbg(&dev->pdev->dev, "usbmode = 0x%08x\n", usbmode);
3309 usbmode &= (~3 | MODE_IDLE); 3516 usbmode &= (~3 | MODE_IDLE);
3310 writel(usbmode, &dev->op_regs->usbmode); 3517 writel(usbmode, &dev->op_regs->usbmode);
3311 3518
3312 DBG(dev, "<--- %s()\n", __func__); 3519 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
3313} 3520}
3314 3521
3315/*-------------------------------------------------------------------------*/ 3522/*-------------------------------------------------------------------------*/
@@ -3324,7 +3531,6 @@ static const struct pci_device_id pci_ids[] = { {
3324}, { /* end: all zeroes */ } 3531}, { /* end: all zeroes */ }
3325}; 3532};
3326 3533
3327
3328MODULE_DEVICE_TABLE(pci, pci_ids); 3534MODULE_DEVICE_TABLE(pci, pci_ids);
3329 3535
3330 3536
@@ -3343,12 +3549,6 @@ static struct pci_driver langwell_pci_driver = {
3343}; 3549};
3344 3550
3345 3551
3346MODULE_DESCRIPTION(DRIVER_DESC);
3347MODULE_AUTHOR("Xiaochen Shen <xiaochen.shen@intel.com>");
3348MODULE_VERSION(DRIVER_VERSION);
3349MODULE_LICENSE("GPL");
3350
3351
3352static int __init init(void) 3552static int __init init(void)
3353{ 3553{
3354#ifdef OTG_TRANSCEIVER 3554#ifdef OTG_TRANSCEIVER
@@ -3370,3 +3570,9 @@ static void __exit cleanup(void)
3370} 3570}
3371module_exit(cleanup); 3571module_exit(cleanup);
3372 3572
3573
3574MODULE_DESCRIPTION(DRIVER_DESC);
3575MODULE_AUTHOR("Xiaochen Shen <xiaochen.shen@intel.com>");
3576MODULE_VERSION(DRIVER_VERSION);
3577MODULE_LICENSE("GPL");
3578
diff --git a/drivers/usb/gadget/langwell_udc.h b/drivers/usb/gadget/langwell_udc.h
index 9719934e1c08..f1d9c1bb04f3 100644
--- a/drivers/usb/gadget/langwell_udc.h
+++ b/drivers/usb/gadget/langwell_udc.h
@@ -18,11 +18,7 @@
18 */ 18 */
19 19
20#include <linux/usb/langwell_udc.h> 20#include <linux/usb/langwell_udc.h>
21
22#if defined(CONFIG_USB_LANGWELL_OTG)
23#include <linux/usb/langwell_otg.h> 21#include <linux/usb/langwell_otg.h>
24#endif
25
26 22
27/*-------------------------------------------------------------------------*/ 23/*-------------------------------------------------------------------------*/
28 24
@@ -199,7 +195,9 @@ struct langwell_udc {
199 vbus_active:1, 195 vbus_active:1,
200 suspended:1, 196 suspended:1,
201 stopped:1, 197 stopped:1,
202 lpm:1; /* LPM capability */ 198 lpm:1, /* LPM capability */
199 has_sram:1, /* SRAM caching */
200 got_sram:1;
203 201
204 /* pci state used to access those endpoints */ 202 /* pci state used to access those endpoints */
205 struct pci_dev *pdev; 203 struct pci_dev *pdev;
@@ -224,5 +222,12 @@ struct langwell_udc {
224 222
225 /* make sure release() is done */ 223 /* make sure release() is done */
226 struct completion *done; 224 struct completion *done;
225
226 /* for private SRAM caching */
227 unsigned int sram_addr;
228 unsigned int sram_size;
229
230 /* device status data for get_status request */
231 u16 dev_status;
227}; 232};
228 233
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index fded3fca793b..6b58bd8ce623 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -408,7 +408,8 @@ static void udc_enable(struct lh7a40x_udc *dev)
408/* 408/*
409 Register entry point for the peripheral controller driver. 409 Register entry point for the peripheral controller driver.
410*/ 410*/
411int usb_gadget_register_driver(struct usb_gadget_driver *driver) 411int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
412 int (*bind)(struct usb_gadget *))
412{ 413{
413 struct lh7a40x_udc *dev = the_controller; 414 struct lh7a40x_udc *dev = the_controller;
414 int retval; 415 int retval;
@@ -417,7 +418,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
417 418
418 if (!driver 419 if (!driver
419 || driver->speed != USB_SPEED_FULL 420 || driver->speed != USB_SPEED_FULL
420 || !driver->bind 421 || !bind
421 || !driver->disconnect 422 || !driver->disconnect
422 || !driver->setup) 423 || !driver->setup)
423 return -EINVAL; 424 return -EINVAL;
@@ -431,7 +432,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
431 dev->gadget.dev.driver = &driver->driver; 432 dev->gadget.dev.driver = &driver->driver;
432 433
433 device_add(&dev->gadget.dev); 434 device_add(&dev->gadget.dev);
434 retval = driver->bind(&dev->gadget); 435 retval = bind(&dev->gadget);
435 if (retval) { 436 if (retval) {
436 printk(KERN_WARNING "%s: bind to driver %s --> error %d\n", 437 printk(KERN_WARNING "%s: bind to driver %s --> error %d\n",
437 dev->gadget.name, driver->driver.name, retval); 438 dev->gadget.name, driver->driver.name, retval);
@@ -453,8 +454,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
453 454
454 return 0; 455 return 0;
455} 456}
456 457EXPORT_SYMBOL(usb_gadget_probe_driver);
457EXPORT_SYMBOL(usb_gadget_register_driver);
458 458
459/* 459/*
460 Unregister entry point for the peripheral controller driver. 460 Unregister entry point for the peripheral controller driver.
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index e03058fe23cb..51b19f3027e7 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1454,14 +1454,15 @@ static struct usb_ep_ops m66592_ep_ops = {
1454/*-------------------------------------------------------------------------*/ 1454/*-------------------------------------------------------------------------*/
1455static struct m66592 *the_controller; 1455static struct m66592 *the_controller;
1456 1456
1457int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1457int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1458 int (*bind)(struct usb_gadget *))
1458{ 1459{
1459 struct m66592 *m66592 = the_controller; 1460 struct m66592 *m66592 = the_controller;
1460 int retval; 1461 int retval;
1461 1462
1462 if (!driver 1463 if (!driver
1463 || driver->speed != USB_SPEED_HIGH 1464 || driver->speed != USB_SPEED_HIGH
1464 || !driver->bind 1465 || !bind
1465 || !driver->setup) 1466 || !driver->setup)
1466 return -EINVAL; 1467 return -EINVAL;
1467 if (!m66592) 1468 if (!m66592)
@@ -1480,7 +1481,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1480 goto error; 1481 goto error;
1481 } 1482 }
1482 1483
1483 retval = driver->bind (&m66592->gadget); 1484 retval = bind(&m66592->gadget);
1484 if (retval) { 1485 if (retval) {
1485 pr_err("bind to driver error (%d)\n", retval); 1486 pr_err("bind to driver error (%d)\n", retval);
1486 device_del(&m66592->gadget.dev); 1487 device_del(&m66592->gadget.dev);
@@ -1505,7 +1506,7 @@ error:
1505 1506
1506 return retval; 1507 return retval;
1507} 1508}
1508EXPORT_SYMBOL(usb_gadget_register_driver); 1509EXPORT_SYMBOL(usb_gadget_probe_driver);
1509 1510
1510int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1511int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1511{ 1512{
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index 585f2559484d..0769179dbdb0 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -75,10 +75,6 @@ static struct usb_device_descriptor msg_device_desc = {
75 /* Vendor and product id can be overridden by module parameters. */ 75 /* Vendor and product id can be overridden by module parameters. */
76 .idVendor = cpu_to_le16(FSG_VENDOR_ID), 76 .idVendor = cpu_to_le16(FSG_VENDOR_ID),
77 .idProduct = cpu_to_le16(FSG_PRODUCT_ID), 77 .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
78 /* .bcdDevice = f(hardware) */
79 /* .iManufacturer = DYNAMIC */
80 /* .iProduct = DYNAMIC */
81 /* NO SERIAL NUMBER */
82 .bNumConfigurations = 1, 78 .bNumConfigurations = 1,
83}; 79};
84 80
@@ -86,7 +82,8 @@ static struct usb_otg_descriptor otg_descriptor = {
86 .bLength = sizeof otg_descriptor, 82 .bLength = sizeof otg_descriptor,
87 .bDescriptorType = USB_DT_OTG, 83 .bDescriptorType = USB_DT_OTG,
88 84
89 /* REVISIT SRP-only hardware is possible, although 85 /*
86 * REVISIT SRP-only hardware is possible, although
90 * it would not be called "OTG" ... 87 * it would not be called "OTG" ...
91 */ 88 */
92 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 89 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
@@ -98,33 +95,6 @@ static const struct usb_descriptor_header *otg_desc[] = {
98}; 95};
99 96
100 97
101/* string IDs are assigned dynamically */
102
103#define STRING_MANUFACTURER_IDX 0
104#define STRING_PRODUCT_IDX 1
105#define STRING_CONFIGURATION_IDX 2
106
107static char manufacturer[50];
108
109static struct usb_string strings_dev[] = {
110 [STRING_MANUFACTURER_IDX].s = manufacturer,
111 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
112 [STRING_CONFIGURATION_IDX].s = "Self Powered",
113 { } /* end of list */
114};
115
116static struct usb_gadget_strings stringtab_dev = {
117 .language = 0x0409, /* en-us */
118 .strings = strings_dev,
119};
120
121static struct usb_gadget_strings *dev_strings[] = {
122 &stringtab_dev,
123 NULL,
124};
125
126
127
128/****************************** Configurations ******************************/ 98/****************************** Configurations ******************************/
129 99
130static struct fsg_module_parameters mod_data = { 100static struct fsg_module_parameters mod_data = {
@@ -141,7 +111,7 @@ static int msg_thread_exits(struct fsg_common *common)
141 return 0; 111 return 0;
142} 112}
143 113
144static int __ref msg_do_config(struct usb_configuration *c) 114static int __init msg_do_config(struct usb_configuration *c)
145{ 115{
146 static const struct fsg_operations ops = { 116 static const struct fsg_operations ops = {
147 .thread_exits = msg_thread_exits, 117 .thread_exits = msg_thread_exits,
@@ -171,54 +141,23 @@ static int __ref msg_do_config(struct usb_configuration *c)
171 141
172static struct usb_configuration msg_config_driver = { 142static struct usb_configuration msg_config_driver = {
173 .label = "Linux File-Backed Storage", 143 .label = "Linux File-Backed Storage",
174 .bind = msg_do_config,
175 .bConfigurationValue = 1, 144 .bConfigurationValue = 1,
176 /* .iConfiguration = DYNAMIC */
177 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 145 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
178}; 146};
179 147
180 148
181
182/****************************** Gadget Bind ******************************/ 149/****************************** Gadget Bind ******************************/
183 150
184 151static int __init msg_bind(struct usb_composite_dev *cdev)
185static int __ref msg_bind(struct usb_composite_dev *cdev)
186{ 152{
187 struct usb_gadget *gadget = cdev->gadget;
188 int status; 153 int status;
189 154
190 /* Allocate string descriptor numbers ... note that string 155 status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
191 * contents can be overridden by the composite_dev glue.
192 */
193
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) 156 if (status < 0)
200 return status; 157 return status;
201 strings_dev[STRING_MANUFACTURER_IDX].id = status;
202 msg_device_desc.iManufacturer = status;
203 158
204 status = usb_string_id(cdev); 159 dev_info(&cdev->gadget->dev,
205 if (status < 0) 160 DRIVER_DESC ", version: " DRIVER_VERSION "\n");
206 return status;
207 strings_dev[STRING_PRODUCT_IDX].id = status;
208 msg_device_desc.iProduct = status;
209
210 status = usb_string_id(cdev);
211 if (status < 0)
212 return status;
213 strings_dev[STRING_CONFIGURATION_IDX].id = status;
214 msg_config_driver.iConfiguration = status;
215
216 /* register our second configuration */
217 status = usb_add_config(cdev, &msg_config_driver);
218 if (status < 0)
219 return status;
220
221 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
222 set_bit(0, &msg_registered); 161 set_bit(0, &msg_registered);
223 return 0; 162 return 0;
224} 163}
@@ -226,12 +165,11 @@ static int __ref msg_bind(struct usb_composite_dev *cdev)
226 165
227/****************************** Some noise ******************************/ 166/****************************** Some noise ******************************/
228 167
229
230static struct usb_composite_driver msg_driver = { 168static struct usb_composite_driver msg_driver = {
231 .name = "g_mass_storage", 169 .name = "g_mass_storage",
232 .dev = &msg_device_desc, 170 .dev = &msg_device_desc,
233 .strings = dev_strings, 171 .iProduct = DRIVER_DESC,
234 .bind = msg_bind, 172 .needs_serial = 1,
235}; 173};
236 174
237MODULE_DESCRIPTION(DRIVER_DESC); 175MODULE_DESCRIPTION(DRIVER_DESC);
@@ -240,7 +178,7 @@ MODULE_LICENSE("GPL");
240 178
241static int __init msg_init(void) 179static int __init msg_init(void)
242{ 180{
243 return usb_composite_register(&msg_driver); 181 return usb_composite_probe(&msg_driver, msg_bind);
244} 182}
245module_init(msg_init); 183module_init(msg_init);
246 184
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 795d76232167..d9feced348e3 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -74,8 +74,8 @@ MODULE_LICENSE("GPL");
74 74
75/***************************** Device Descriptor ****************************/ 75/***************************** Device Descriptor ****************************/
76 76
77#define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */ 77#define MULTI_VENDOR_NUM 0x1d6b /* Linux Foundation */
78#define MULTI_PRODUCT_NUM 0xa4ab /* XXX */ 78#define MULTI_PRODUCT_NUM 0x0104 /* Multifunction Composite Gadget */
79 79
80 80
81enum { 81enum {
@@ -121,8 +121,6 @@ static const struct usb_descriptor_header *otg_desc[] = {
121 121
122 122
123enum { 123enum {
124 MULTI_STRING_MANUFACTURER_IDX,
125 MULTI_STRING_PRODUCT_IDX,
126#ifdef CONFIG_USB_G_MULTI_RNDIS 124#ifdef CONFIG_USB_G_MULTI_RNDIS
127 MULTI_STRING_RNDIS_CONFIG_IDX, 125 MULTI_STRING_RNDIS_CONFIG_IDX,
128#endif 126#endif
@@ -131,11 +129,7 @@ enum {
131#endif 129#endif
132}; 130};
133 131
134static char manufacturer[50];
135
136static struct usb_string strings_dev[] = { 132static struct usb_string strings_dev[] = {
137 [MULTI_STRING_MANUFACTURER_IDX].s = manufacturer,
138 [MULTI_STRING_PRODUCT_IDX].s = DRIVER_DESC,
139#ifdef CONFIG_USB_G_MULTI_RNDIS 133#ifdef CONFIG_USB_G_MULTI_RNDIS
140 [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS", 134 [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS",
141#endif 135#endif
@@ -170,7 +164,7 @@ static u8 hostaddr[ETH_ALEN];
170 164
171#ifdef USB_ETH_RNDIS 165#ifdef USB_ETH_RNDIS
172 166
173static __ref int rndis_do_config(struct usb_configuration *c) 167static __init int rndis_do_config(struct usb_configuration *c)
174{ 168{
175 int ret; 169 int ret;
176 170
@@ -197,7 +191,6 @@ static __ref int rndis_do_config(struct usb_configuration *c)
197static int rndis_config_register(struct usb_composite_dev *cdev) 191static int rndis_config_register(struct usb_composite_dev *cdev)
198{ 192{
199 static struct usb_configuration config = { 193 static struct usb_configuration config = {
200 .bind = rndis_do_config,
201 .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM, 194 .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM,
202 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 195 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
203 }; 196 };
@@ -205,7 +198,7 @@ static int rndis_config_register(struct usb_composite_dev *cdev)
205 config.label = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s; 198 config.label = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s;
206 config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id; 199 config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id;
207 200
208 return usb_add_config(cdev, &config); 201 return usb_add_config(cdev, &config, rndis_do_config);
209} 202}
210 203
211#else 204#else
@@ -222,7 +215,7 @@ static int rndis_config_register(struct usb_composite_dev *cdev)
222 215
223#ifdef CONFIG_USB_G_MULTI_CDC 216#ifdef CONFIG_USB_G_MULTI_CDC
224 217
225static __ref int cdc_do_config(struct usb_configuration *c) 218static __init int cdc_do_config(struct usb_configuration *c)
226{ 219{
227 int ret; 220 int ret;
228 221
@@ -249,7 +242,6 @@ static __ref int cdc_do_config(struct usb_configuration *c)
249static int cdc_config_register(struct usb_composite_dev *cdev) 242static int cdc_config_register(struct usb_composite_dev *cdev)
250{ 243{
251 static struct usb_configuration config = { 244 static struct usb_configuration config = {
252 .bind = cdc_do_config,
253 .bConfigurationValue = MULTI_CDC_CONFIG_NUM, 245 .bConfigurationValue = MULTI_CDC_CONFIG_NUM,
254 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 246 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
255 }; 247 };
@@ -257,7 +249,7 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
257 config.label = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s; 249 config.label = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s;
258 config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id; 250 config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id;
259 251
260 return usb_add_config(cdev, &config); 252 return usb_add_config(cdev, &config, cdc_do_config);
261} 253}
262 254
263#else 255#else
@@ -314,20 +306,11 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
314 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099); 306 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
315 } 307 }
316 308
317 /* allocate string descriptor numbers */ 309 /* allocate string IDs */
318 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
319 init_utsname()->sysname, init_utsname()->release,
320 gadget->name);
321
322 status = usb_string_ids_tab(cdev, strings_dev); 310 status = usb_string_ids_tab(cdev, strings_dev);
323 if (unlikely(status < 0)) 311 if (unlikely(status < 0))
324 goto fail2; 312 goto fail2;
325 313
326 device_desc.iManufacturer =
327 strings_dev[MULTI_STRING_MANUFACTURER_IDX].id;
328 device_desc.iProduct =
329 strings_dev[MULTI_STRING_PRODUCT_IDX].id;
330
331 /* register configurations */ 314 /* register configurations */
332 status = rndis_config_register(cdev); 315 status = rndis_config_register(cdev);
333 if (unlikely(status < 0)) 316 if (unlikely(status < 0))
@@ -368,14 +351,15 @@ static struct usb_composite_driver multi_driver = {
368 .name = "g_multi", 351 .name = "g_multi",
369 .dev = &device_desc, 352 .dev = &device_desc,
370 .strings = dev_strings, 353 .strings = dev_strings,
371 .bind = multi_bind,
372 .unbind = __exit_p(multi_unbind), 354 .unbind = __exit_p(multi_unbind),
355 .iProduct = DRIVER_DESC,
356 .needs_serial = 1,
373}; 357};
374 358
375 359
376static int __init multi_init(void) 360static int __init multi_init(void)
377{ 361{
378 return usb_composite_register(&multi_driver); 362 return usb_composite_probe(&multi_driver, multi_bind);
379} 363}
380module_init(multi_init); 364module_init(multi_init);
381 365
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 9498be87a724..d09155b25d73 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -1929,7 +1929,8 @@ static void ep0_start (struct net2280 *dev)
1929 * disconnect is reported. then a host may connect again, or 1929 * disconnect is reported. then a host may connect again, or
1930 * the driver might get unbound. 1930 * the driver might get unbound.
1931 */ 1931 */
1932int usb_gadget_register_driver (struct usb_gadget_driver *driver) 1932int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1933 int (*bind)(struct usb_gadget *))
1933{ 1934{
1934 struct net2280 *dev = the_controller; 1935 struct net2280 *dev = the_controller;
1935 int retval; 1936 int retval;
@@ -1941,8 +1942,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1941 */ 1942 */
1942 if (!driver 1943 if (!driver
1943 || driver->speed != USB_SPEED_HIGH 1944 || driver->speed != USB_SPEED_HIGH
1944 || !driver->bind 1945 || !bind || !driver->setup)
1945 || !driver->setup)
1946 return -EINVAL; 1946 return -EINVAL;
1947 if (!dev) 1947 if (!dev)
1948 return -ENODEV; 1948 return -ENODEV;
@@ -1957,7 +1957,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1957 driver->driver.bus = NULL; 1957 driver->driver.bus = NULL;
1958 dev->driver = driver; 1958 dev->driver = driver;
1959 dev->gadget.dev.driver = &driver->driver; 1959 dev->gadget.dev.driver = &driver->driver;
1960 retval = driver->bind (&dev->gadget); 1960 retval = bind(&dev->gadget);
1961 if (retval) { 1961 if (retval) {
1962 DEBUG (dev, "bind to driver %s --> %d\n", 1962 DEBUG (dev, "bind to driver %s --> %d\n",
1963 driver->driver.name, retval); 1963 driver->driver.name, retval);
@@ -1993,7 +1993,7 @@ err_unbind:
1993 dev->driver = NULL; 1993 dev->driver = NULL;
1994 return retval; 1994 return retval;
1995} 1995}
1996EXPORT_SYMBOL (usb_gadget_register_driver); 1996EXPORT_SYMBOL(usb_gadget_probe_driver);
1997 1997
1998static void 1998static void
1999stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) 1999stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 7d6b66a85724..b5364f9d7cd2 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -135,7 +135,6 @@ static int __init nokia_bind_config(struct usb_configuration *c)
135 135
136static struct usb_configuration nokia_config_500ma_driver = { 136static struct usb_configuration nokia_config_500ma_driver = {
137 .label = "Bus Powered", 137 .label = "Bus Powered",
138 .bind = nokia_bind_config,
139 .bConfigurationValue = 1, 138 .bConfigurationValue = 1,
140 /* .iConfiguration = DYNAMIC */ 139 /* .iConfiguration = DYNAMIC */
141 .bmAttributes = USB_CONFIG_ATT_ONE, 140 .bmAttributes = USB_CONFIG_ATT_ONE,
@@ -144,7 +143,6 @@ static struct usb_configuration nokia_config_500ma_driver = {
144 143
145static struct usb_configuration nokia_config_100ma_driver = { 144static struct usb_configuration nokia_config_100ma_driver = {
146 .label = "Self Powered", 145 .label = "Self Powered",
147 .bind = nokia_bind_config,
148 .bConfigurationValue = 2, 146 .bConfigurationValue = 2,
149 /* .iConfiguration = DYNAMIC */ 147 /* .iConfiguration = DYNAMIC */
150 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, 148 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
@@ -206,11 +204,13 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
206 } 204 }
207 205
208 /* finaly register the configuration */ 206 /* finaly register the configuration */
209 status = usb_add_config(cdev, &nokia_config_500ma_driver); 207 status = usb_add_config(cdev, &nokia_config_500ma_driver,
208 nokia_bind_config);
210 if (status < 0) 209 if (status < 0)
211 goto err_usb; 210 goto err_usb;
212 211
213 status = usb_add_config(cdev, &nokia_config_100ma_driver); 212 status = usb_add_config(cdev, &nokia_config_100ma_driver,
213 nokia_bind_config);
214 if (status < 0) 214 if (status < 0)
215 goto err_usb; 215 goto err_usb;
216 216
@@ -241,13 +241,12 @@ static struct usb_composite_driver nokia_driver = {
241 .name = "g_nokia", 241 .name = "g_nokia",
242 .dev = &device_desc, 242 .dev = &device_desc,
243 .strings = dev_strings, 243 .strings = dev_strings,
244 .bind = nokia_bind,
245 .unbind = __exit_p(nokia_unbind), 244 .unbind = __exit_p(nokia_unbind),
246}; 245};
247 246
248static int __init nokia_init(void) 247static int __init nokia_init(void)
249{ 248{
250 return usb_composite_register(&nokia_driver); 249 return usb_composite_probe(&nokia_driver, nokia_bind);
251} 250}
252module_init(nokia_init); 251module_init(nokia_init);
253 252
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index f81e4f025f23..61d3ca6619bb 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -2102,7 +2102,8 @@ static inline int machine_without_vbus_sense(void)
2102 ); 2102 );
2103} 2103}
2104 2104
2105int usb_gadget_register_driver (struct usb_gadget_driver *driver) 2105int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2106 int (*bind)(struct usb_gadget *))
2106{ 2107{
2107 int status = -ENODEV; 2108 int status = -ENODEV;
2108 struct omap_ep *ep; 2109 struct omap_ep *ep;
@@ -2114,8 +2115,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2114 if (!driver 2115 if (!driver
2115 // FIXME if otg, check: driver->is_otg 2116 // FIXME if otg, check: driver->is_otg
2116 || driver->speed < USB_SPEED_FULL 2117 || driver->speed < USB_SPEED_FULL
2117 || !driver->bind 2118 || !bind || !driver->setup)
2118 || !driver->setup)
2119 return -EINVAL; 2119 return -EINVAL;
2120 2120
2121 spin_lock_irqsave(&udc->lock, flags); 2121 spin_lock_irqsave(&udc->lock, flags);
@@ -2145,7 +2145,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2145 if (udc->dc_clk != NULL) 2145 if (udc->dc_clk != NULL)
2146 omap_udc_enable_clock(1); 2146 omap_udc_enable_clock(1);
2147 2147
2148 status = driver->bind (&udc->gadget); 2148 status = bind(&udc->gadget);
2149 if (status) { 2149 if (status) {
2150 DBG("bind to %s --> %d\n", driver->driver.name, status); 2150 DBG("bind to %s --> %d\n", driver->driver.name, status);
2151 udc->gadget.dev.driver = NULL; 2151 udc->gadget.dev.driver = NULL;
@@ -2186,7 +2186,7 @@ done:
2186 omap_udc_enable_clock(0); 2186 omap_udc_enable_clock(0);
2187 return status; 2187 return status;
2188} 2188}
2189EXPORT_SYMBOL(usb_gadget_register_driver); 2189EXPORT_SYMBOL(usb_gadget_probe_driver);
2190 2190
2191int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 2191int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2192{ 2192{
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 327a92a137b4..2fc8636316c5 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -1348,7 +1348,7 @@ printer_unbind(struct usb_gadget *gadget)
1348 set_gadget_data(gadget, NULL); 1348 set_gadget_data(gadget, NULL);
1349} 1349}
1350 1350
1351static int __ref 1351static int __init
1352printer_bind(struct usb_gadget *gadget) 1352printer_bind(struct usb_gadget *gadget)
1353{ 1353{
1354 struct printer_dev *dev; 1354 struct printer_dev *dev;
@@ -1544,7 +1544,6 @@ static struct usb_gadget_driver printer_driver = {
1544 .speed = DEVSPEED, 1544 .speed = DEVSPEED,
1545 1545
1546 .function = (char *) driver_desc, 1546 .function = (char *) driver_desc,
1547 .bind = printer_bind,
1548 .unbind = printer_unbind, 1547 .unbind = printer_unbind,
1549 1548
1550 .setup = printer_setup, 1549 .setup = printer_setup,
@@ -1580,11 +1579,11 @@ init(void)
1580 return status; 1579 return status;
1581 } 1580 }
1582 1581
1583 status = usb_gadget_register_driver(&printer_driver); 1582 status = usb_gadget_probe_driver(&printer_driver, printer_bind);
1584 if (status) { 1583 if (status) {
1585 class_destroy(usb_gadget_class); 1584 class_destroy(usb_gadget_class);
1586 unregister_chrdev_region(g_printer_devno, 1); 1585 unregister_chrdev_region(g_printer_devno, 1);
1587 DBG(dev, "usb_gadget_register_driver %x\n", status); 1586 DBG(dev, "usb_gadget_probe_driver %x\n", status);
1588 } 1587 }
1589 1588
1590 return status; 1589 return status;
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index be5fb34d9602..b37f92cb71bc 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -1280,14 +1280,15 @@ static void udc_enable (struct pxa25x_udc *dev)
1280 * disconnect is reported. then a host may connect again, or 1280 * disconnect is reported. then a host may connect again, or
1281 * the driver might get unbound. 1281 * the driver might get unbound.
1282 */ 1282 */
1283int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1283int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1284 int (*bind)(struct usb_gadget *))
1284{ 1285{
1285 struct pxa25x_udc *dev = the_controller; 1286 struct pxa25x_udc *dev = the_controller;
1286 int retval; 1287 int retval;
1287 1288
1288 if (!driver 1289 if (!driver
1289 || driver->speed < USB_SPEED_FULL 1290 || driver->speed < USB_SPEED_FULL
1290 || !driver->bind 1291 || !bind
1291 || !driver->disconnect 1292 || !driver->disconnect
1292 || !driver->setup) 1293 || !driver->setup)
1293 return -EINVAL; 1294 return -EINVAL;
@@ -1308,7 +1309,7 @@ fail:
1308 dev->gadget.dev.driver = NULL; 1309 dev->gadget.dev.driver = NULL;
1309 return retval; 1310 return retval;
1310 } 1311 }
1311 retval = driver->bind(&dev->gadget); 1312 retval = bind(&dev->gadget);
1312 if (retval) { 1313 if (retval) {
1313 DMSG("bind to driver %s --> error %d\n", 1314 DMSG("bind to driver %s --> error %d\n",
1314 driver->driver.name, retval); 1315 driver->driver.name, retval);
@@ -1338,7 +1339,7 @@ fail:
1338bind_fail: 1339bind_fail:
1339 return retval; 1340 return retval;
1340} 1341}
1341EXPORT_SYMBOL(usb_gadget_register_driver); 1342EXPORT_SYMBOL(usb_gadget_probe_driver);
1342 1343
1343static void 1344static void
1344stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) 1345stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 980762453a9c..027d66f81620 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -1792,8 +1792,9 @@ static void udc_enable(struct pxa_udc *udc)
1792} 1792}
1793 1793
1794/** 1794/**
1795 * usb_gadget_register_driver - Register gadget driver 1795 * usb_gadget_probe_driver - Register gadget driver
1796 * @driver: gadget driver 1796 * @driver: gadget driver
1797 * @bind: bind function
1797 * 1798 *
1798 * When a driver is successfully registered, it will receive control requests 1799 * When a driver is successfully registered, it will receive control requests
1799 * including set_configuration(), which enables non-control requests. Then 1800 * including set_configuration(), which enables non-control requests. Then
@@ -1805,12 +1806,13 @@ static void udc_enable(struct pxa_udc *udc)
1805 * 1806 *
1806 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1807 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1807 */ 1808 */
1808int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1809int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1810 int (*bind)(struct usb_gadget *))
1809{ 1811{
1810 struct pxa_udc *udc = the_controller; 1812 struct pxa_udc *udc = the_controller;
1811 int retval; 1813 int retval;
1812 1814
1813 if (!driver || driver->speed < USB_SPEED_FULL || !driver->bind 1815 if (!driver || driver->speed < USB_SPEED_FULL || !bind
1814 || !driver->disconnect || !driver->setup) 1816 || !driver->disconnect || !driver->setup)
1815 return -EINVAL; 1817 return -EINVAL;
1816 if (!udc) 1818 if (!udc)
@@ -1828,7 +1830,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1828 dev_err(udc->dev, "device_add error %d\n", retval); 1830 dev_err(udc->dev, "device_add error %d\n", retval);
1829 goto add_fail; 1831 goto add_fail;
1830 } 1832 }
1831 retval = driver->bind(&udc->gadget); 1833 retval = bind(&udc->gadget);
1832 if (retval) { 1834 if (retval) {
1833 dev_err(udc->dev, "bind to driver %s --> error %d\n", 1835 dev_err(udc->dev, "bind to driver %s --> error %d\n",
1834 driver->driver.name, retval); 1836 driver->driver.name, retval);
@@ -1859,7 +1861,7 @@ add_fail:
1859 udc->gadget.dev.driver = NULL; 1861 udc->gadget.dev.driver = NULL;
1860 return retval; 1862 return retval;
1861} 1863}
1862EXPORT_SYMBOL(usb_gadget_register_driver); 1864EXPORT_SYMBOL(usb_gadget_probe_driver);
1863 1865
1864 1866
1865/** 1867/**
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index 2456ccd9965e..20d43da319ae 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -42,6 +42,7 @@ static const char *r8a66597_ep_name[] = {
42 "ep8", "ep9", 42 "ep8", "ep9",
43}; 43};
44 44
45static void init_controller(struct r8a66597 *r8a66597);
45static void disable_controller(struct r8a66597 *r8a66597); 46static void disable_controller(struct r8a66597 *r8a66597);
46static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req); 47static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req);
47static void irq_packet_write(struct r8a66597_ep *ep, 48static void irq_packet_write(struct r8a66597_ep *ep,
@@ -104,6 +105,8 @@ __acquires(r8a66597->lock)
104 spin_lock(&r8a66597->lock); 105 spin_lock(&r8a66597->lock);
105 106
106 disable_controller(r8a66597); 107 disable_controller(r8a66597);
108 init_controller(r8a66597);
109 r8a66597_bset(r8a66597, VBSE, INTENB0);
107 INIT_LIST_HEAD(&r8a66597->ep[0].queue); 110 INIT_LIST_HEAD(&r8a66597->ep[0].queue);
108} 111}
109 112
@@ -274,7 +277,7 @@ static int pipe_buffer_setting(struct r8a66597 *r8a66597,
274 } 277 }
275 278
276 if (buf_bsize && ((bufnum + 16) >= R8A66597_MAX_BUFNUM)) { 279 if (buf_bsize && ((bufnum + 16) >= R8A66597_MAX_BUFNUM)) {
277 pr_err(KERN_ERR "r8a66597 pipe memory is insufficient\n"); 280 pr_err("r8a66597 pipe memory is insufficient\n");
278 return -ENOMEM; 281 return -ENOMEM;
279 } 282 }
280 283
@@ -1405,14 +1408,15 @@ static struct usb_ep_ops r8a66597_ep_ops = {
1405/*-------------------------------------------------------------------------*/ 1408/*-------------------------------------------------------------------------*/
1406static struct r8a66597 *the_controller; 1409static struct r8a66597 *the_controller;
1407 1410
1408int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1411int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1412 int (*bind)(struct usb_gadget *))
1409{ 1413{
1410 struct r8a66597 *r8a66597 = the_controller; 1414 struct r8a66597 *r8a66597 = the_controller;
1411 int retval; 1415 int retval;
1412 1416
1413 if (!driver 1417 if (!driver
1414 || driver->speed != USB_SPEED_HIGH 1418 || driver->speed != USB_SPEED_HIGH
1415 || !driver->bind 1419 || !bind
1416 || !driver->setup) 1420 || !driver->setup)
1417 return -EINVAL; 1421 return -EINVAL;
1418 if (!r8a66597) 1422 if (!r8a66597)
@@ -1431,7 +1435,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1431 goto error; 1435 goto error;
1432 } 1436 }
1433 1437
1434 retval = driver->bind(&r8a66597->gadget); 1438 retval = bind(&r8a66597->gadget);
1435 if (retval) { 1439 if (retval) {
1436 printk(KERN_ERR "bind to driver error (%d)\n", retval); 1440 printk(KERN_ERR "bind to driver error (%d)\n", retval);
1437 device_del(&r8a66597->gadget.dev); 1441 device_del(&r8a66597->gadget.dev);
@@ -1456,7 +1460,7 @@ error:
1456 1460
1457 return retval; 1461 return retval;
1458} 1462}
1459EXPORT_SYMBOL(usb_gadget_register_driver); 1463EXPORT_SYMBOL(usb_gadget_probe_driver);
1460 1464
1461int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1465int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1462{ 1466{
diff --git a/drivers/usb/gadget/r8a66597-udc.h b/drivers/usb/gadget/r8a66597-udc.h
index f763b5190afa..5fc22e09a0f1 100644
--- a/drivers/usb/gadget/r8a66597-udc.h
+++ b/drivers/usb/gadget/r8a66597-udc.h
@@ -136,7 +136,7 @@ static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597,
136 int len) 136 int len)
137{ 137{
138 void __iomem *fifoaddr = r8a66597->reg + offset; 138 void __iomem *fifoaddr = r8a66597->reg + offset;
139 unsigned int data; 139 unsigned int data = 0;
140 int i; 140 int i;
141 141
142 if (r8a66597->pdata->on_chip) { 142 if (r8a66597->pdata->on_chip) {
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 972d5ddd1e18..5b314041dfa9 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -61,17 +61,17 @@ MODULE_PARM_DESC (rndis_debug, "enable debugging");
61#define RNDIS_MAX_CONFIGS 1 61#define RNDIS_MAX_CONFIGS 1
62 62
63 63
64static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS]; 64static rndis_params rndis_per_dev_params[RNDIS_MAX_CONFIGS];
65 65
66/* Driver Version */ 66/* Driver Version */
67static const __le32 rndis_driver_version = cpu_to_le32 (1); 67static const __le32 rndis_driver_version = cpu_to_le32(1);
68 68
69/* Function Prototypes */ 69/* Function Prototypes */
70static rndis_resp_t *rndis_add_response (int configNr, u32 length); 70static rndis_resp_t *rndis_add_response(int configNr, u32 length);
71 71
72 72
73/* supported OIDs */ 73/* supported OIDs */
74static const u32 oid_supported_list [] = 74static const u32 oid_supported_list[] =
75{ 75{
76 /* the general stuff */ 76 /* the general stuff */
77 OID_GEN_SUPPORTED_LIST, 77 OID_GEN_SUPPORTED_LIST,
@@ -161,21 +161,20 @@ static const u32 oid_supported_list [] =
161 161
162 162
163/* NDIS Functions */ 163/* NDIS Functions */
164static int 164static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
165gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, 165 unsigned buf_len, rndis_resp_t *r)
166 rndis_resp_t *r)
167{ 166{
168 int retval = -ENOTSUPP; 167 int retval = -ENOTSUPP;
169 u32 length = 4; /* usually */ 168 u32 length = 4; /* usually */
170 __le32 *outbuf; 169 __le32 *outbuf;
171 int i, count; 170 int i, count;
172 rndis_query_cmplt_type *resp; 171 rndis_query_cmplt_type *resp;
173 struct net_device *net; 172 struct net_device *net;
174 struct rtnl_link_stats64 temp; 173 struct rtnl_link_stats64 temp;
175 const struct rtnl_link_stats64 *stats; 174 const struct rtnl_link_stats64 *stats;
176 175
177 if (!r) return -ENOMEM; 176 if (!r) return -ENOMEM;
178 resp = (rndis_query_cmplt_type *) r->buf; 177 resp = (rndis_query_cmplt_type *)r->buf;
179 178
180 if (!resp) return -ENOMEM; 179 if (!resp) return -ENOMEM;
181 180
@@ -191,8 +190,8 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
191 } 190 }
192 191
193 /* response goes here, right after the header */ 192 /* response goes here, right after the header */
194 outbuf = (__le32 *) &resp[1]; 193 outbuf = (__le32 *)&resp[1];
195 resp->InformationBufferOffset = cpu_to_le32 (16); 194 resp->InformationBufferOffset = cpu_to_le32(16);
196 195
197 net = rndis_per_dev_params[configNr].dev; 196 net = rndis_per_dev_params[configNr].dev;
198 stats = dev_get_stats(net, &temp); 197 stats = dev_get_stats(net, &temp);
@@ -204,10 +203,10 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
204 /* mandatory */ 203 /* mandatory */
205 case OID_GEN_SUPPORTED_LIST: 204 case OID_GEN_SUPPORTED_LIST:
206 pr_debug("%s: OID_GEN_SUPPORTED_LIST\n", __func__); 205 pr_debug("%s: OID_GEN_SUPPORTED_LIST\n", __func__);
207 length = sizeof (oid_supported_list); 206 length = sizeof(oid_supported_list);
208 count = length / sizeof (u32); 207 count = length / sizeof(u32);
209 for (i = 0; i < count; i++) 208 for (i = 0; i < count; i++)
210 outbuf[i] = cpu_to_le32 (oid_supported_list[i]); 209 outbuf[i] = cpu_to_le32(oid_supported_list[i]);
211 retval = 0; 210 retval = 0;
212 break; 211 break;
213 212
@@ -220,14 +219,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
220 * reddite ergo quae sunt Caesaris Caesari 219 * reddite ergo quae sunt Caesaris Caesari
221 * et quae sunt Dei Deo! 220 * et quae sunt Dei Deo!
222 */ 221 */
223 *outbuf = cpu_to_le32 (0); 222 *outbuf = cpu_to_le32(0);
224 retval = 0; 223 retval = 0;
225 break; 224 break;
226 225
227 /* mandatory */ 226 /* mandatory */
228 case OID_GEN_MEDIA_SUPPORTED: 227 case OID_GEN_MEDIA_SUPPORTED:
229 pr_debug("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__); 228 pr_debug("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__);
230 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 229 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium);
231 retval = 0; 230 retval = 0;
232 break; 231 break;
233 232
@@ -235,16 +234,16 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
235 case OID_GEN_MEDIA_IN_USE: 234 case OID_GEN_MEDIA_IN_USE:
236 pr_debug("%s: OID_GEN_MEDIA_IN_USE\n", __func__); 235 pr_debug("%s: OID_GEN_MEDIA_IN_USE\n", __func__);
237 /* one medium, one transport... (maybe you do it better) */ 236 /* one medium, one transport... (maybe you do it better) */
238 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 237 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium);
239 retval = 0; 238 retval = 0;
240 break; 239 break;
241 240
242 /* mandatory */ 241 /* mandatory */
243 case OID_GEN_MAXIMUM_FRAME_SIZE: 242 case OID_GEN_MAXIMUM_FRAME_SIZE:
244 pr_debug("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); 243 pr_debug("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
245 if (rndis_per_dev_params [configNr].dev) { 244 if (rndis_per_dev_params[configNr].dev) {
246 *outbuf = cpu_to_le32 ( 245 *outbuf = cpu_to_le32(
247 rndis_per_dev_params [configNr].dev->mtu); 246 rndis_per_dev_params[configNr].dev->mtu);
248 retval = 0; 247 retval = 0;
249 } 248 }
250 break; 249 break;
@@ -253,21 +252,21 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
253 case OID_GEN_LINK_SPEED: 252 case OID_GEN_LINK_SPEED:
254 if (rndis_debug > 1) 253 if (rndis_debug > 1)
255 pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__); 254 pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__);
256 if (rndis_per_dev_params [configNr].media_state 255 if (rndis_per_dev_params[configNr].media_state
257 == NDIS_MEDIA_STATE_DISCONNECTED) 256 == NDIS_MEDIA_STATE_DISCONNECTED)
258 *outbuf = cpu_to_le32 (0); 257 *outbuf = cpu_to_le32(0);
259 else 258 else
260 *outbuf = cpu_to_le32 ( 259 *outbuf = cpu_to_le32(
261 rndis_per_dev_params [configNr].speed); 260 rndis_per_dev_params[configNr].speed);
262 retval = 0; 261 retval = 0;
263 break; 262 break;
264 263
265 /* mandatory */ 264 /* mandatory */
266 case OID_GEN_TRANSMIT_BLOCK_SIZE: 265 case OID_GEN_TRANSMIT_BLOCK_SIZE:
267 pr_debug("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); 266 pr_debug("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
268 if (rndis_per_dev_params [configNr].dev) { 267 if (rndis_per_dev_params[configNr].dev) {
269 *outbuf = cpu_to_le32 ( 268 *outbuf = cpu_to_le32(
270 rndis_per_dev_params [configNr].dev->mtu); 269 rndis_per_dev_params[configNr].dev->mtu);
271 retval = 0; 270 retval = 0;
272 } 271 }
273 break; 272 break;
@@ -275,9 +274,9 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
275 /* mandatory */ 274 /* mandatory */
276 case OID_GEN_RECEIVE_BLOCK_SIZE: 275 case OID_GEN_RECEIVE_BLOCK_SIZE:
277 pr_debug("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); 276 pr_debug("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
278 if (rndis_per_dev_params [configNr].dev) { 277 if (rndis_per_dev_params[configNr].dev) {
279 *outbuf = cpu_to_le32 ( 278 *outbuf = cpu_to_le32(
280 rndis_per_dev_params [configNr].dev->mtu); 279 rndis_per_dev_params[configNr].dev->mtu);
281 retval = 0; 280 retval = 0;
282 } 281 }
283 break; 282 break;
@@ -285,18 +284,20 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
285 /* mandatory */ 284 /* mandatory */
286 case OID_GEN_VENDOR_ID: 285 case OID_GEN_VENDOR_ID:
287 pr_debug("%s: OID_GEN_VENDOR_ID\n", __func__); 286 pr_debug("%s: OID_GEN_VENDOR_ID\n", __func__);
288 *outbuf = cpu_to_le32 ( 287 *outbuf = cpu_to_le32(
289 rndis_per_dev_params [configNr].vendorID); 288 rndis_per_dev_params[configNr].vendorID);
290 retval = 0; 289 retval = 0;
291 break; 290 break;
292 291
293 /* mandatory */ 292 /* mandatory */
294 case OID_GEN_VENDOR_DESCRIPTION: 293 case OID_GEN_VENDOR_DESCRIPTION:
295 pr_debug("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__); 294 pr_debug("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__);
296 if ( rndis_per_dev_params [configNr].vendorDescr ) { 295 if (rndis_per_dev_params[configNr].vendorDescr) {
297 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 296 length = strlen(rndis_per_dev_params[configNr].
298 memcpy (outbuf, 297 vendorDescr);
299 rndis_per_dev_params [configNr].vendorDescr, length); 298 memcpy(outbuf,
299 rndis_per_dev_params[configNr].vendorDescr,
300 length);
300 } else { 301 } else {
301 outbuf[0] = 0; 302 outbuf[0] = 0;
302 } 303 }
@@ -313,7 +314,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
313 /* mandatory */ 314 /* mandatory */
314 case OID_GEN_CURRENT_PACKET_FILTER: 315 case OID_GEN_CURRENT_PACKET_FILTER:
315 pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__); 316 pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
316 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); 317 *outbuf = cpu_to_le32(*rndis_per_dev_params[configNr].filter);
317 retval = 0; 318 retval = 0;
318 break; 319 break;
319 320
@@ -328,14 +329,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
328 case OID_GEN_MEDIA_CONNECT_STATUS: 329 case OID_GEN_MEDIA_CONNECT_STATUS:
329 if (rndis_debug > 1) 330 if (rndis_debug > 1)
330 pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); 331 pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
331 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 332 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr]
332 .media_state); 333 .media_state);
333 retval = 0; 334 retval = 0;
334 break; 335 break;
335 336
336 case OID_GEN_PHYSICAL_MEDIUM: 337 case OID_GEN_PHYSICAL_MEDIUM:
337 pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__); 338 pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__);
338 *outbuf = cpu_to_le32 (0); 339 *outbuf = cpu_to_le32(0);
339 retval = 0; 340 retval = 0;
340 break; 341 break;
341 342
@@ -409,10 +410,10 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
409 /* mandatory */ 410 /* mandatory */
410 case OID_802_3_PERMANENT_ADDRESS: 411 case OID_802_3_PERMANENT_ADDRESS:
411 pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__); 412 pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__);
412 if (rndis_per_dev_params [configNr].dev) { 413 if (rndis_per_dev_params[configNr].dev) {
413 length = ETH_ALEN; 414 length = ETH_ALEN;
414 memcpy (outbuf, 415 memcpy(outbuf,
415 rndis_per_dev_params [configNr].host_mac, 416 rndis_per_dev_params[configNr].host_mac,
416 length); 417 length);
417 retval = 0; 418 retval = 0;
418 } 419 }
@@ -421,9 +422,9 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
421 /* mandatory */ 422 /* mandatory */
422 case OID_802_3_CURRENT_ADDRESS: 423 case OID_802_3_CURRENT_ADDRESS:
423 pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__); 424 pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__);
424 if (rndis_per_dev_params [configNr].dev) { 425 if (rndis_per_dev_params[configNr].dev) {
425 length = ETH_ALEN; 426 length = ETH_ALEN;
426 memcpy (outbuf, 427 memcpy(outbuf,
427 rndis_per_dev_params [configNr].host_mac, 428 rndis_per_dev_params [configNr].host_mac,
428 length); 429 length);
429 retval = 0; 430 retval = 0;
@@ -434,7 +435,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
434 case OID_802_3_MULTICAST_LIST: 435 case OID_802_3_MULTICAST_LIST:
435 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); 436 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__);
436 /* Multicast base address only */ 437 /* Multicast base address only */
437 *outbuf = cpu_to_le32 (0xE0000000); 438 *outbuf = cpu_to_le32(0xE0000000);
438 retval = 0; 439 retval = 0;
439 break; 440 break;
440 441
@@ -442,7 +443,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
442 case OID_802_3_MAXIMUM_LIST_SIZE: 443 case OID_802_3_MAXIMUM_LIST_SIZE:
443 pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); 444 pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
444 /* Multicast base address only */ 445 /* Multicast base address only */
445 *outbuf = cpu_to_le32 (1); 446 *outbuf = cpu_to_le32(1);
446 retval = 0; 447 retval = 0;
447 break; 448 break;
448 449
@@ -466,14 +467,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
466 /* mandatory */ 467 /* mandatory */
467 case OID_802_3_XMIT_ONE_COLLISION: 468 case OID_802_3_XMIT_ONE_COLLISION:
468 pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__); 469 pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__);
469 *outbuf = cpu_to_le32 (0); 470 *outbuf = cpu_to_le32(0);
470 retval = 0; 471 retval = 0;
471 break; 472 break;
472 473
473 /* mandatory */ 474 /* mandatory */
474 case OID_802_3_XMIT_MORE_COLLISIONS: 475 case OID_802_3_XMIT_MORE_COLLISIONS:
475 pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); 476 pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
476 *outbuf = cpu_to_le32 (0); 477 *outbuf = cpu_to_le32(0);
477 retval = 0; 478 retval = 0;
478 break; 479 break;
479 480
@@ -484,22 +485,22 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
484 if (retval < 0) 485 if (retval < 0)
485 length = 0; 486 length = 0;
486 487
487 resp->InformationBufferLength = cpu_to_le32 (length); 488 resp->InformationBufferLength = cpu_to_le32(length);
488 r->length = length + sizeof *resp; 489 r->length = length + sizeof(*resp);
489 resp->MessageLength = cpu_to_le32 (r->length); 490 resp->MessageLength = cpu_to_le32(r->length);
490 return retval; 491 return retval;
491} 492}
492 493
493static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len, 494static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len,
494 rndis_resp_t *r) 495 rndis_resp_t *r)
495{ 496{
496 rndis_set_cmplt_type *resp; 497 rndis_set_cmplt_type *resp;
497 int i, retval = -ENOTSUPP; 498 int i, retval = -ENOTSUPP;
498 struct rndis_params *params; 499 struct rndis_params *params;
499 500
500 if (!r) 501 if (!r)
501 return -ENOMEM; 502 return -ENOMEM;
502 resp = (rndis_set_cmplt_type *) r->buf; 503 resp = (rndis_set_cmplt_type *)r->buf;
503 if (!resp) 504 if (!resp)
504 return -ENOMEM; 505 return -ENOMEM;
505 506
@@ -514,7 +515,7 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
514 } 515 }
515 } 516 }
516 517
517 params = &rndis_per_dev_params [configNr]; 518 params = &rndis_per_dev_params[configNr];
518 switch (OID) { 519 switch (OID) {
519 case OID_GEN_CURRENT_PACKET_FILTER: 520 case OID_GEN_CURRENT_PACKET_FILTER:
520 521
@@ -537,11 +538,11 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
537 params->state = RNDIS_DATA_INITIALIZED; 538 params->state = RNDIS_DATA_INITIALIZED;
538 netif_carrier_on(params->dev); 539 netif_carrier_on(params->dev);
539 if (netif_running(params->dev)) 540 if (netif_running(params->dev))
540 netif_wake_queue (params->dev); 541 netif_wake_queue(params->dev);
541 } else { 542 } else {
542 params->state = RNDIS_INITIALIZED; 543 params->state = RNDIS_INITIALIZED;
543 netif_carrier_off (params->dev); 544 netif_carrier_off(params->dev);
544 netif_stop_queue (params->dev); 545 netif_stop_queue(params->dev);
545 } 546 }
546 break; 547 break;
547 548
@@ -563,48 +564,47 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
563 * Response Functions 564 * Response Functions
564 */ 565 */
565 566
566static int rndis_init_response (int configNr, rndis_init_msg_type *buf) 567static int rndis_init_response(int configNr, rndis_init_msg_type *buf)
567{ 568{
568 rndis_init_cmplt_type *resp; 569 rndis_init_cmplt_type *resp;
569 rndis_resp_t *r; 570 rndis_resp_t *r;
570 struct rndis_params *params = rndis_per_dev_params + configNr; 571 struct rndis_params *params = rndis_per_dev_params + configNr;
571 572
572 if (!params->dev) 573 if (!params->dev)
573 return -ENOTSUPP; 574 return -ENOTSUPP;
574 575
575 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); 576 r = rndis_add_response(configNr, sizeof(rndis_init_cmplt_type));
576 if (!r) 577 if (!r)
577 return -ENOMEM; 578 return -ENOMEM;
578 resp = (rndis_init_cmplt_type *) r->buf; 579 resp = (rndis_init_cmplt_type *)r->buf;
579 580
580 resp->MessageType = cpu_to_le32 ( 581 resp->MessageType = cpu_to_le32(REMOTE_NDIS_INITIALIZE_CMPLT);
581 REMOTE_NDIS_INITIALIZE_CMPLT); 582 resp->MessageLength = cpu_to_le32(52);
582 resp->MessageLength = cpu_to_le32 (52);
583 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 583 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
584 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 584 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
585 resp->MajorVersion = cpu_to_le32 (RNDIS_MAJOR_VERSION); 585 resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
586 resp->MinorVersion = cpu_to_le32 (RNDIS_MINOR_VERSION); 586 resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
587 resp->DeviceFlags = cpu_to_le32 (RNDIS_DF_CONNECTIONLESS); 587 resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
588 resp->Medium = cpu_to_le32 (RNDIS_MEDIUM_802_3); 588 resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
589 resp->MaxPacketsPerTransfer = cpu_to_le32 (1); 589 resp->MaxPacketsPerTransfer = cpu_to_le32(1);
590 resp->MaxTransferSize = cpu_to_le32 ( 590 resp->MaxTransferSize = cpu_to_le32(
591 params->dev->mtu 591 params->dev->mtu
592 + sizeof (struct ethhdr) 592 + sizeof(struct ethhdr)
593 + sizeof (struct rndis_packet_msg_type) 593 + sizeof(struct rndis_packet_msg_type)
594 + 22); 594 + 22);
595 resp->PacketAlignmentFactor = cpu_to_le32 (0); 595 resp->PacketAlignmentFactor = cpu_to_le32(0);
596 resp->AFListOffset = cpu_to_le32 (0); 596 resp->AFListOffset = cpu_to_le32(0);
597 resp->AFListSize = cpu_to_le32 (0); 597 resp->AFListSize = cpu_to_le32(0);
598 598
599 params->resp_avail(params->v); 599 params->resp_avail(params->v);
600 return 0; 600 return 0;
601} 601}
602 602
603static int rndis_query_response (int configNr, rndis_query_msg_type *buf) 603static int rndis_query_response(int configNr, rndis_query_msg_type *buf)
604{ 604{
605 rndis_query_cmplt_type *resp; 605 rndis_query_cmplt_type *resp;
606 rndis_resp_t *r; 606 rndis_resp_t *r;
607 struct rndis_params *params = rndis_per_dev_params + configNr; 607 struct rndis_params *params = rndis_per_dev_params + configNr;
608 608
609 /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */ 609 /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
610 if (!params->dev) 610 if (!params->dev)
@@ -616,47 +616,46 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
616 * rndis_query_cmplt_type followed by data. 616 * rndis_query_cmplt_type followed by data.
617 * oid_supported_list is the largest data reply 617 * oid_supported_list is the largest data reply
618 */ 618 */
619 r = rndis_add_response (configNr, 619 r = rndis_add_response(configNr,
620 sizeof (oid_supported_list) + sizeof(rndis_query_cmplt_type)); 620 sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type));
621 if (!r) 621 if (!r)
622 return -ENOMEM; 622 return -ENOMEM;
623 resp = (rndis_query_cmplt_type *) r->buf; 623 resp = (rndis_query_cmplt_type *)r->buf;
624 624
625 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); 625 resp->MessageType = cpu_to_le32(REMOTE_NDIS_QUERY_CMPLT);
626 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 626 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
627 627
628 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), 628 if (gen_ndis_query_resp(configNr, le32_to_cpu(buf->OID),
629 le32_to_cpu(buf->InformationBufferOffset) 629 le32_to_cpu(buf->InformationBufferOffset)
630 + 8 + (u8 *) buf, 630 + 8 + (u8 *)buf,
631 le32_to_cpu(buf->InformationBufferLength), 631 le32_to_cpu(buf->InformationBufferLength),
632 r)) { 632 r)) {
633 /* OID not supported */ 633 /* OID not supported */
634 resp->Status = cpu_to_le32 ( 634 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
635 RNDIS_STATUS_NOT_SUPPORTED); 635 resp->MessageLength = cpu_to_le32(sizeof *resp);
636 resp->MessageLength = cpu_to_le32 (sizeof *resp); 636 resp->InformationBufferLength = cpu_to_le32(0);
637 resp->InformationBufferLength = cpu_to_le32 (0); 637 resp->InformationBufferOffset = cpu_to_le32(0);
638 resp->InformationBufferOffset = cpu_to_le32 (0);
639 } else 638 } else
640 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 639 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
641 640
642 params->resp_avail(params->v); 641 params->resp_avail(params->v);
643 return 0; 642 return 0;
644} 643}
645 644
646static int rndis_set_response (int configNr, rndis_set_msg_type *buf) 645static int rndis_set_response(int configNr, rndis_set_msg_type *buf)
647{ 646{
648 u32 BufLength, BufOffset; 647 u32 BufLength, BufOffset;
649 rndis_set_cmplt_type *resp; 648 rndis_set_cmplt_type *resp;
650 rndis_resp_t *r; 649 rndis_resp_t *r;
651 struct rndis_params *params = rndis_per_dev_params + configNr; 650 struct rndis_params *params = rndis_per_dev_params + configNr;
652 651
653 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); 652 r = rndis_add_response(configNr, sizeof(rndis_set_cmplt_type));
654 if (!r) 653 if (!r)
655 return -ENOMEM; 654 return -ENOMEM;
656 resp = (rndis_set_cmplt_type *) r->buf; 655 resp = (rndis_set_cmplt_type *)r->buf;
657 656
658 BufLength = le32_to_cpu (buf->InformationBufferLength); 657 BufLength = le32_to_cpu(buf->InformationBufferLength);
659 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 658 BufOffset = le32_to_cpu(buf->InformationBufferOffset);
660 659
661#ifdef VERBOSE_DEBUG 660#ifdef VERBOSE_DEBUG
662 pr_debug("%s: Length: %d\n", __func__, BufLength); 661 pr_debug("%s: Length: %d\n", __func__, BufLength);
@@ -670,59 +669,59 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
670 pr_debug("\n"); 669 pr_debug("\n");
671#endif 670#endif
672 671
673 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_SET_CMPLT); 672 resp->MessageType = cpu_to_le32(REMOTE_NDIS_SET_CMPLT);
674 resp->MessageLength = cpu_to_le32 (16); 673 resp->MessageLength = cpu_to_le32(16);
675 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 674 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
676 if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID), 675 if (gen_ndis_set_resp(configNr, le32_to_cpu(buf->OID),
677 ((u8 *) buf) + 8 + BufOffset, BufLength, r)) 676 ((u8 *)buf) + 8 + BufOffset, BufLength, r))
678 resp->Status = cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED); 677 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
679 else 678 else
680 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 679 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
681 680
682 params->resp_avail(params->v); 681 params->resp_avail(params->v);
683 return 0; 682 return 0;
684} 683}
685 684
686static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf) 685static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf)
687{ 686{
688 rndis_reset_cmplt_type *resp; 687 rndis_reset_cmplt_type *resp;
689 rndis_resp_t *r; 688 rndis_resp_t *r;
690 struct rndis_params *params = rndis_per_dev_params + configNr; 689 struct rndis_params *params = rndis_per_dev_params + configNr;
691 690
692 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); 691 r = rndis_add_response(configNr, sizeof(rndis_reset_cmplt_type));
693 if (!r) 692 if (!r)
694 return -ENOMEM; 693 return -ENOMEM;
695 resp = (rndis_reset_cmplt_type *) r->buf; 694 resp = (rndis_reset_cmplt_type *)r->buf;
696 695
697 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); 696 resp->MessageType = cpu_to_le32(REMOTE_NDIS_RESET_CMPLT);
698 resp->MessageLength = cpu_to_le32 (16); 697 resp->MessageLength = cpu_to_le32(16);
699 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 698 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
700 /* resent information */ 699 /* resent information */
701 resp->AddressingReset = cpu_to_le32 (1); 700 resp->AddressingReset = cpu_to_le32(1);
702 701
703 params->resp_avail(params->v); 702 params->resp_avail(params->v);
704 return 0; 703 return 0;
705} 704}
706 705
707static int rndis_keepalive_response (int configNr, 706static int rndis_keepalive_response(int configNr,
708 rndis_keepalive_msg_type *buf) 707 rndis_keepalive_msg_type *buf)
709{ 708{
710 rndis_keepalive_cmplt_type *resp; 709 rndis_keepalive_cmplt_type *resp;
711 rndis_resp_t *r; 710 rndis_resp_t *r;
712 struct rndis_params *params = rndis_per_dev_params + configNr; 711 struct rndis_params *params = rndis_per_dev_params + configNr;
713 712
714 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 713 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
715 714
716 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); 715 r = rndis_add_response(configNr, sizeof(rndis_keepalive_cmplt_type));
717 if (!r) 716 if (!r)
718 return -ENOMEM; 717 return -ENOMEM;
719 resp = (rndis_keepalive_cmplt_type *) r->buf; 718 resp = (rndis_keepalive_cmplt_type *)r->buf;
720 719
721 resp->MessageType = cpu_to_le32 ( 720 resp->MessageType = cpu_to_le32(
722 REMOTE_NDIS_KEEPALIVE_CMPLT); 721 REMOTE_NDIS_KEEPALIVE_CMPLT);
723 resp->MessageLength = cpu_to_le32 (16); 722 resp->MessageLength = cpu_to_le32(16);
724 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 723 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
725 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); 724 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
726 725
727 params->resp_avail(params->v); 726 params->resp_avail(params->v);
728 return 0; 727 return 0;
@@ -732,86 +731,85 @@ static int rndis_keepalive_response (int configNr,
732/* 731/*
733 * Device to Host Comunication 732 * Device to Host Comunication
734 */ 733 */
735static int rndis_indicate_status_msg (int configNr, u32 status) 734static int rndis_indicate_status_msg(int configNr, u32 status)
736{ 735{
737 rndis_indicate_status_msg_type *resp; 736 rndis_indicate_status_msg_type *resp;
738 rndis_resp_t *r; 737 rndis_resp_t *r;
739 struct rndis_params *params = rndis_per_dev_params + configNr; 738 struct rndis_params *params = rndis_per_dev_params + configNr;
740 739
741 if (params->state == RNDIS_UNINITIALIZED) 740 if (params->state == RNDIS_UNINITIALIZED)
742 return -ENOTSUPP; 741 return -ENOTSUPP;
743 742
744 r = rndis_add_response (configNr, 743 r = rndis_add_response(configNr,
745 sizeof (rndis_indicate_status_msg_type)); 744 sizeof(rndis_indicate_status_msg_type));
746 if (!r) 745 if (!r)
747 return -ENOMEM; 746 return -ENOMEM;
748 resp = (rndis_indicate_status_msg_type *) r->buf; 747 resp = (rndis_indicate_status_msg_type *)r->buf;
749 748
750 resp->MessageType = cpu_to_le32 ( 749 resp->MessageType = cpu_to_le32(REMOTE_NDIS_INDICATE_STATUS_MSG);
751 REMOTE_NDIS_INDICATE_STATUS_MSG); 750 resp->MessageLength = cpu_to_le32(20);
752 resp->MessageLength = cpu_to_le32 (20); 751 resp->Status = cpu_to_le32(status);
753 resp->Status = cpu_to_le32 (status); 752 resp->StatusBufferLength = cpu_to_le32(0);
754 resp->StatusBufferLength = cpu_to_le32 (0); 753 resp->StatusBufferOffset = cpu_to_le32(0);
755 resp->StatusBufferOffset = cpu_to_le32 (0);
756 754
757 params->resp_avail(params->v); 755 params->resp_avail(params->v);
758 return 0; 756 return 0;
759} 757}
760 758
761int rndis_signal_connect (int configNr) 759int rndis_signal_connect(int configNr)
762{ 760{
763 rndis_per_dev_params [configNr].media_state 761 rndis_per_dev_params[configNr].media_state
764 = NDIS_MEDIA_STATE_CONNECTED; 762 = NDIS_MEDIA_STATE_CONNECTED;
765 return rndis_indicate_status_msg (configNr, 763 return rndis_indicate_status_msg(configNr,
766 RNDIS_STATUS_MEDIA_CONNECT); 764 RNDIS_STATUS_MEDIA_CONNECT);
767} 765}
768 766
769int rndis_signal_disconnect (int configNr) 767int rndis_signal_disconnect(int configNr)
770{ 768{
771 rndis_per_dev_params [configNr].media_state 769 rndis_per_dev_params[configNr].media_state
772 = NDIS_MEDIA_STATE_DISCONNECTED; 770 = NDIS_MEDIA_STATE_DISCONNECTED;
773 return rndis_indicate_status_msg (configNr, 771 return rndis_indicate_status_msg(configNr,
774 RNDIS_STATUS_MEDIA_DISCONNECT); 772 RNDIS_STATUS_MEDIA_DISCONNECT);
775} 773}
776 774
777void rndis_uninit (int configNr) 775void rndis_uninit(int configNr)
778{ 776{
779 u8 *buf; 777 u8 *buf;
780 u32 length; 778 u32 length;
781 779
782 if (configNr >= RNDIS_MAX_CONFIGS) 780 if (configNr >= RNDIS_MAX_CONFIGS)
783 return; 781 return;
784 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED; 782 rndis_per_dev_params[configNr].state = RNDIS_UNINITIALIZED;
785 783
786 /* drain the response queue */ 784 /* drain the response queue */
787 while ((buf = rndis_get_next_response(configNr, &length))) 785 while ((buf = rndis_get_next_response(configNr, &length)))
788 rndis_free_response(configNr, buf); 786 rndis_free_response(configNr, buf);
789} 787}
790 788
791void rndis_set_host_mac (int configNr, const u8 *addr) 789void rndis_set_host_mac(int configNr, const u8 *addr)
792{ 790{
793 rndis_per_dev_params [configNr].host_mac = addr; 791 rndis_per_dev_params[configNr].host_mac = addr;
794} 792}
795 793
796/* 794/*
797 * Message Parser 795 * Message Parser
798 */ 796 */
799int rndis_msg_parser (u8 configNr, u8 *buf) 797int rndis_msg_parser(u8 configNr, u8 *buf)
800{ 798{
801 u32 MsgType, MsgLength; 799 u32 MsgType, MsgLength;
802 __le32 *tmp; 800 __le32 *tmp;
803 struct rndis_params *params; 801 struct rndis_params *params;
804 802
805 if (!buf) 803 if (!buf)
806 return -ENOMEM; 804 return -ENOMEM;
807 805
808 tmp = (__le32 *) buf; 806 tmp = (__le32 *)buf;
809 MsgType = get_unaligned_le32(tmp++); 807 MsgType = get_unaligned_le32(tmp++);
810 MsgLength = get_unaligned_le32(tmp++); 808 MsgLength = get_unaligned_le32(tmp++);
811 809
812 if (configNr >= RNDIS_MAX_CONFIGS) 810 if (configNr >= RNDIS_MAX_CONFIGS)
813 return -ENOTSUPP; 811 return -ENOTSUPP;
814 params = &rndis_per_dev_params [configNr]; 812 params = &rndis_per_dev_params[configNr];
815 813
816 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for 814 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
817 * rx/tx statistics and link status, in addition to KEEPALIVE traffic 815 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
@@ -822,41 +820,41 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
822 switch (MsgType) { 820 switch (MsgType) {
823 case REMOTE_NDIS_INITIALIZE_MSG: 821 case REMOTE_NDIS_INITIALIZE_MSG:
824 pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 822 pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
825 __func__ ); 823 __func__);
826 params->state = RNDIS_INITIALIZED; 824 params->state = RNDIS_INITIALIZED;
827 return rndis_init_response (configNr, 825 return rndis_init_response(configNr,
828 (rndis_init_msg_type *) buf); 826 (rndis_init_msg_type *)buf);
829 827
830 case REMOTE_NDIS_HALT_MSG: 828 case REMOTE_NDIS_HALT_MSG:
831 pr_debug("%s: REMOTE_NDIS_HALT_MSG\n", 829 pr_debug("%s: REMOTE_NDIS_HALT_MSG\n",
832 __func__ ); 830 __func__);
833 params->state = RNDIS_UNINITIALIZED; 831 params->state = RNDIS_UNINITIALIZED;
834 if (params->dev) { 832 if (params->dev) {
835 netif_carrier_off (params->dev); 833 netif_carrier_off(params->dev);
836 netif_stop_queue (params->dev); 834 netif_stop_queue(params->dev);
837 } 835 }
838 return 0; 836 return 0;
839 837
840 case REMOTE_NDIS_QUERY_MSG: 838 case REMOTE_NDIS_QUERY_MSG:
841 return rndis_query_response (configNr, 839 return rndis_query_response(configNr,
842 (rndis_query_msg_type *) buf); 840 (rndis_query_msg_type *)buf);
843 841
844 case REMOTE_NDIS_SET_MSG: 842 case REMOTE_NDIS_SET_MSG:
845 return rndis_set_response (configNr, 843 return rndis_set_response(configNr,
846 (rndis_set_msg_type *) buf); 844 (rndis_set_msg_type *)buf);
847 845
848 case REMOTE_NDIS_RESET_MSG: 846 case REMOTE_NDIS_RESET_MSG:
849 pr_debug("%s: REMOTE_NDIS_RESET_MSG\n", 847 pr_debug("%s: REMOTE_NDIS_RESET_MSG\n",
850 __func__ ); 848 __func__);
851 return rndis_reset_response (configNr, 849 return rndis_reset_response(configNr,
852 (rndis_reset_msg_type *) buf); 850 (rndis_reset_msg_type *)buf);
853 851
854 case REMOTE_NDIS_KEEPALIVE_MSG: 852 case REMOTE_NDIS_KEEPALIVE_MSG:
855 /* For USB: host does this every 5 seconds */ 853 /* For USB: host does this every 5 seconds */
856 if (rndis_debug > 1) 854 if (rndis_debug > 1)
857 pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 855 pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
858 __func__ ); 856 __func__);
859 return rndis_keepalive_response (configNr, 857 return rndis_keepalive_response(configNr,
860 (rndis_keepalive_msg_type *) 858 (rndis_keepalive_msg_type *)
861 buf); 859 buf);
862 860
@@ -866,7 +864,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
866 * suspending itself. 864 * suspending itself.
867 */ 865 */
868 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n", 866 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
869 __func__ , MsgType, MsgLength); 867 __func__, MsgType, MsgLength);
870 { 868 {
871 unsigned i; 869 unsigned i;
872 for (i = 0; i < MsgLength; i += 16) { 870 for (i = 0; i < MsgLength; i += 16) {
@@ -901,10 +899,10 @@ int rndis_register(void (*resp_avail)(void *v), void *v)
901 return -EINVAL; 899 return -EINVAL;
902 900
903 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { 901 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
904 if (!rndis_per_dev_params [i].used) { 902 if (!rndis_per_dev_params[i].used) {
905 rndis_per_dev_params [i].used = 1; 903 rndis_per_dev_params[i].used = 1;
906 rndis_per_dev_params [i].resp_avail = resp_avail; 904 rndis_per_dev_params[i].resp_avail = resp_avail;
907 rndis_per_dev_params [i].v = v; 905 rndis_per_dev_params[i].v = v;
908 pr_debug("%s: configNr = %d\n", __func__, i); 906 pr_debug("%s: configNr = %d\n", __func__, i);
909 return i; 907 return i;
910 } 908 }
@@ -914,12 +912,12 @@ int rndis_register(void (*resp_avail)(void *v), void *v)
914 return -ENODEV; 912 return -ENODEV;
915} 913}
916 914
917void rndis_deregister (int configNr) 915void rndis_deregister(int configNr)
918{ 916{
919 pr_debug("%s: \n", __func__); 917 pr_debug("%s:\n", __func__);
920 918
921 if (configNr >= RNDIS_MAX_CONFIGS) return; 919 if (configNr >= RNDIS_MAX_CONFIGS) return;
922 rndis_per_dev_params [configNr].used = 0; 920 rndis_per_dev_params[configNr].used = 0;
923 921
924 return; 922 return;
925} 923}
@@ -931,76 +929,76 @@ int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
931 return -EINVAL; 929 return -EINVAL;
932 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 930 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
933 931
934 rndis_per_dev_params [configNr].dev = dev; 932 rndis_per_dev_params[configNr].dev = dev;
935 rndis_per_dev_params [configNr].filter = cdc_filter; 933 rndis_per_dev_params[configNr].filter = cdc_filter;
936 934
937 return 0; 935 return 0;
938} 936}
939 937
940int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) 938int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr)
941{ 939{
942 pr_debug("%s:\n", __func__); 940 pr_debug("%s:\n", __func__);
943 if (!vendorDescr) return -1; 941 if (!vendorDescr) return -1;
944 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 942 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
945 943
946 rndis_per_dev_params [configNr].vendorID = vendorID; 944 rndis_per_dev_params[configNr].vendorID = vendorID;
947 rndis_per_dev_params [configNr].vendorDescr = vendorDescr; 945 rndis_per_dev_params[configNr].vendorDescr = vendorDescr;
948 946
949 return 0; 947 return 0;
950} 948}
951 949
952int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 950int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed)
953{ 951{
954 pr_debug("%s: %u %u\n", __func__, medium, speed); 952 pr_debug("%s: %u %u\n", __func__, medium, speed);
955 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 953 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
956 954
957 rndis_per_dev_params [configNr].medium = medium; 955 rndis_per_dev_params[configNr].medium = medium;
958 rndis_per_dev_params [configNr].speed = speed; 956 rndis_per_dev_params[configNr].speed = speed;
959 957
960 return 0; 958 return 0;
961} 959}
962 960
963void rndis_add_hdr (struct sk_buff *skb) 961void rndis_add_hdr(struct sk_buff *skb)
964{ 962{
965 struct rndis_packet_msg_type *header; 963 struct rndis_packet_msg_type *header;
966 964
967 if (!skb) 965 if (!skb)
968 return; 966 return;
969 header = (void *) skb_push (skb, sizeof *header); 967 header = (void *)skb_push(skb, sizeof(*header));
970 memset (header, 0, sizeof *header); 968 memset(header, 0, sizeof *header);
971 header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG); 969 header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG);
972 header->MessageLength = cpu_to_le32(skb->len); 970 header->MessageLength = cpu_to_le32(skb->len);
973 header->DataOffset = cpu_to_le32 (36); 971 header->DataOffset = cpu_to_le32(36);
974 header->DataLength = cpu_to_le32(skb->len - sizeof *header); 972 header->DataLength = cpu_to_le32(skb->len - sizeof(*header));
975} 973}
976 974
977void rndis_free_response (int configNr, u8 *buf) 975void rndis_free_response(int configNr, u8 *buf)
978{ 976{
979 rndis_resp_t *r; 977 rndis_resp_t *r;
980 struct list_head *act, *tmp; 978 struct list_head *act, *tmp;
981 979
982 list_for_each_safe (act, tmp, 980 list_for_each_safe(act, tmp,
983 &(rndis_per_dev_params [configNr].resp_queue)) 981 &(rndis_per_dev_params[configNr].resp_queue))
984 { 982 {
985 r = list_entry (act, rndis_resp_t, list); 983 r = list_entry(act, rndis_resp_t, list);
986 if (r && r->buf == buf) { 984 if (r && r->buf == buf) {
987 list_del (&r->list); 985 list_del(&r->list);
988 kfree (r); 986 kfree(r);
989 } 987 }
990 } 988 }
991} 989}
992 990
993u8 *rndis_get_next_response (int configNr, u32 *length) 991u8 *rndis_get_next_response(int configNr, u32 *length)
994{ 992{
995 rndis_resp_t *r; 993 rndis_resp_t *r;
996 struct list_head *act, *tmp; 994 struct list_head *act, *tmp;
997 995
998 if (!length) return NULL; 996 if (!length) return NULL;
999 997
1000 list_for_each_safe (act, tmp, 998 list_for_each_safe(act, tmp,
1001 &(rndis_per_dev_params [configNr].resp_queue)) 999 &(rndis_per_dev_params[configNr].resp_queue))
1002 { 1000 {
1003 r = list_entry (act, rndis_resp_t, list); 1001 r = list_entry(act, rndis_resp_t, list);
1004 if (!r->send) { 1002 if (!r->send) {
1005 r->send = 1; 1003 r->send = 1;
1006 *length = r->length; 1004 *length = r->length;
@@ -1011,20 +1009,20 @@ u8 *rndis_get_next_response (int configNr, u32 *length)
1011 return NULL; 1009 return NULL;
1012} 1010}
1013 1011
1014static rndis_resp_t *rndis_add_response (int configNr, u32 length) 1012static rndis_resp_t *rndis_add_response(int configNr, u32 length)
1015{ 1013{
1016 rndis_resp_t *r; 1014 rndis_resp_t *r;
1017 1015
1018 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */ 1016 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1019 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); 1017 r = kmalloc(sizeof(rndis_resp_t) + length, GFP_ATOMIC);
1020 if (!r) return NULL; 1018 if (!r) return NULL;
1021 1019
1022 r->buf = (u8 *) (r + 1); 1020 r->buf = (u8 *)(r + 1);
1023 r->length = length; 1021 r->length = length;
1024 r->send = 0; 1022 r->send = 0;
1025 1023
1026 list_add_tail (&r->list, 1024 list_add_tail(&r->list,
1027 &(rndis_per_dev_params [configNr].resp_queue)); 1025 &(rndis_per_dev_params[configNr].resp_queue));
1028 return r; 1026 return r;
1029} 1027}
1030 1028
@@ -1033,7 +1031,7 @@ int rndis_rm_hdr(struct gether *port,
1033 struct sk_buff_head *list) 1031 struct sk_buff_head *list)
1034{ 1032{
1035 /* tmp points to a struct rndis_packet_msg_type */ 1033 /* tmp points to a struct rndis_packet_msg_type */
1036 __le32 *tmp = (void *) skb->data; 1034 __le32 *tmp = (void *)skb->data;
1037 1035
1038 /* MessageType, MessageLength */ 1036 /* MessageType, MessageLength */
1039 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) 1037 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
@@ -1054,7 +1052,7 @@ int rndis_rm_hdr(struct gether *port,
1054 return 0; 1052 return 0;
1055} 1053}
1056 1054
1057#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1055#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1058 1056
1059static int rndis_proc_show(struct seq_file *m, void *v) 1057static int rndis_proc_show(struct seq_file *m, void *v)
1060{ 1058{
@@ -1087,7 +1085,7 @@ static int rndis_proc_show(struct seq_file *m, void *v)
1087} 1085}
1088 1086
1089static ssize_t rndis_proc_write(struct file *file, const char __user *buffer, 1087static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1090 size_t count, loff_t *ppos) 1088 size_t count, loff_t *ppos)
1091{ 1089{
1092 rndis_params *p = PDE(file->f_path.dentry->d_inode)->data; 1090 rndis_params *p = PDE(file->f_path.dentry->d_inode)->data;
1093 u32 speed = 0; 1091 u32 speed = 0;
@@ -1109,11 +1107,11 @@ static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1109 case '8': 1107 case '8':
1110 case '9': 1108 case '9':
1111 fl_speed = 1; 1109 fl_speed = 1;
1112 speed = speed*10 + c - '0'; 1110 speed = speed * 10 + c - '0';
1113 break; 1111 break;
1114 case 'C': 1112 case 'C':
1115 case 'c': 1113 case 'c':
1116 rndis_signal_connect (p->confignr); 1114 rndis_signal_connect(p->confignr);
1117 break; 1115 break;
1118 case 'D': 1116 case 'D':
1119 case 'd': 1117 case 'd':
@@ -1145,11 +1143,11 @@ static const struct file_operations rndis_proc_fops = {
1145 .write = rndis_proc_write, 1143 .write = rndis_proc_write,
1146}; 1144};
1147 1145
1148#define NAME_TEMPLATE "driver/rndis-%03d" 1146#define NAME_TEMPLATE "driver/rndis-%03d"
1149 1147
1150static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS]; 1148static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1151 1149
1152#endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1150#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1153 1151
1154 1152
1155int rndis_init(void) 1153int rndis_init(void)
@@ -1160,42 +1158,40 @@ int rndis_init(void)
1160#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1158#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1161 char name [20]; 1159 char name [20];
1162 1160
1163 sprintf (name, NAME_TEMPLATE, i); 1161 sprintf(name, NAME_TEMPLATE, i);
1164 if (!(rndis_connect_state [i] 1162 rndis_connect_state[i] = proc_create_data(name, 0660, NULL,
1165 = proc_create_data(name, 0660, NULL,
1166 &rndis_proc_fops, 1163 &rndis_proc_fops,
1167 (void *)(rndis_per_dev_params + i)))) 1164 (void *)(rndis_per_dev_params + i));
1168 { 1165 if (!rndis_connect_state[i]) {
1169 pr_debug("%s :remove entries", __func__); 1166 pr_debug("%s: remove entries", __func__);
1170 while (i) { 1167 while (i) {
1171 sprintf (name, NAME_TEMPLATE, --i); 1168 sprintf(name, NAME_TEMPLATE, --i);
1172 remove_proc_entry (name, NULL); 1169 remove_proc_entry(name, NULL);
1173 } 1170 }
1174 pr_debug("\n"); 1171 pr_debug("\n");
1175 return -EIO; 1172 return -EIO;
1176 } 1173 }
1177#endif 1174#endif
1178 rndis_per_dev_params [i].confignr = i; 1175 rndis_per_dev_params[i].confignr = i;
1179 rndis_per_dev_params [i].used = 0; 1176 rndis_per_dev_params[i].used = 0;
1180 rndis_per_dev_params [i].state = RNDIS_UNINITIALIZED; 1177 rndis_per_dev_params[i].state = RNDIS_UNINITIALIZED;
1181 rndis_per_dev_params [i].media_state 1178 rndis_per_dev_params[i].media_state
1182 = NDIS_MEDIA_STATE_DISCONNECTED; 1179 = NDIS_MEDIA_STATE_DISCONNECTED;
1183 INIT_LIST_HEAD (&(rndis_per_dev_params [i].resp_queue)); 1180 INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue));
1184 } 1181 }
1185 1182
1186 return 0; 1183 return 0;
1187} 1184}
1188 1185
1189void rndis_exit (void) 1186void rndis_exit(void)
1190{ 1187{
1191#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1188#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1192 u8 i; 1189 u8 i;
1193 char name [20]; 1190 char name[20];
1194 1191
1195 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { 1192 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1196 sprintf (name, NAME_TEMPLATE, i); 1193 sprintf(name, NAME_TEMPLATE, i);
1197 remove_proc_entry (name, NULL); 1194 remove_proc_entry(name, NULL);
1198 } 1195 }
1199#endif 1196#endif
1200} 1197}
1201
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index a229744a8c7d..ef825c3baed9 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -2523,7 +2523,8 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2523 return 0; 2523 return 0;
2524} 2524}
2525 2525
2526int usb_gadget_register_driver(struct usb_gadget_driver *driver) 2526int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2527 int (*bind)(struct usb_gadget *))
2527{ 2528{
2528 struct s3c_hsotg *hsotg = our_hsotg; 2529 struct s3c_hsotg *hsotg = our_hsotg;
2529 int ret; 2530 int ret;
@@ -2543,7 +2544,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2543 dev_err(hsotg->dev, "%s: bad speed\n", __func__); 2544 dev_err(hsotg->dev, "%s: bad speed\n", __func__);
2544 } 2545 }
2545 2546
2546 if (!driver->bind || !driver->setup) { 2547 if (!bind || !driver->setup) {
2547 dev_err(hsotg->dev, "%s: missing entry points\n", __func__); 2548 dev_err(hsotg->dev, "%s: missing entry points\n", __func__);
2548 return -EINVAL; 2549 return -EINVAL;
2549 } 2550 }
@@ -2562,7 +2563,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2562 goto err; 2563 goto err;
2563 } 2564 }
2564 2565
2565 ret = driver->bind(&hsotg->gadget); 2566 ret = bind(&hsotg->gadget);
2566 if (ret) { 2567 if (ret) {
2567 dev_err(hsotg->dev, "failed bind %s\n", driver->driver.name); 2568 dev_err(hsotg->dev, "failed bind %s\n", driver->driver.name);
2568 2569
@@ -2687,7 +2688,7 @@ err:
2687 hsotg->gadget.dev.driver = NULL; 2688 hsotg->gadget.dev.driver = NULL;
2688 return ret; 2689 return ret;
2689} 2690}
2690EXPORT_SYMBOL(usb_gadget_register_driver); 2691EXPORT_SYMBOL(usb_gadget_probe_driver);
2691 2692
2692int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2693int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2693{ 2694{
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index ea2b3c7ebee5..c2448950a8d8 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1632,15 +1632,15 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev)
1632} 1632}
1633 1633
1634/* 1634/*
1635 * usb_gadget_register_driver 1635 * usb_gadget_probe_driver
1636 */ 1636 */
1637int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1637int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1638 int (*bind)(struct usb_gadget *))
1638{ 1639{
1639 struct s3c2410_udc *udc = the_controller; 1640 struct s3c2410_udc *udc = the_controller;
1640 int retval; 1641 int retval;
1641 1642
1642 dprintk(DEBUG_NORMAL, "usb_gadget_register_driver() '%s'\n", 1643 dprintk(DEBUG_NORMAL, "%s() '%s'\n", __func__, driver->driver.name);
1643 driver->driver.name);
1644 1644
1645 /* Sanity checks */ 1645 /* Sanity checks */
1646 if (!udc) 1646 if (!udc)
@@ -1649,10 +1649,9 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1649 if (udc->driver) 1649 if (udc->driver)
1650 return -EBUSY; 1650 return -EBUSY;
1651 1651
1652 if (!driver->bind || !driver->setup 1652 if (!bind || !driver->setup || driver->speed < USB_SPEED_FULL) {
1653 || driver->speed < USB_SPEED_FULL) {
1654 printk(KERN_ERR "Invalid driver: bind %p setup %p speed %d\n", 1653 printk(KERN_ERR "Invalid driver: bind %p setup %p speed %d\n",
1655 driver->bind, driver->setup, driver->speed); 1654 bind, driver->setup, driver->speed);
1656 return -EINVAL; 1655 return -EINVAL;
1657 } 1656 }
1658#if defined(MODULE) 1657#if defined(MODULE)
@@ -1675,7 +1674,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1675 dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n", 1674 dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n",
1676 driver->driver.name); 1675 driver->driver.name);
1677 1676
1678 if ((retval = driver->bind (&udc->gadget)) != 0) { 1677 if ((retval = bind(&udc->gadget)) != 0) {
1679 device_del(&udc->gadget.dev); 1678 device_del(&udc->gadget.dev);
1680 goto register_error; 1679 goto register_error;
1681 } 1680 }
@@ -1690,6 +1689,7 @@ register_error:
1690 udc->gadget.dev.driver = NULL; 1689 udc->gadget.dev.driver = NULL;
1691 return retval; 1690 return retval;
1692} 1691}
1692EXPORT_SYMBOL(usb_gadget_probe_driver);
1693 1693
1694/* 1694/*
1695 * usb_gadget_unregister_driver 1695 * usb_gadget_unregister_driver
@@ -2049,7 +2049,6 @@ static void __exit udc_exit(void)
2049} 2049}
2050 2050
2051EXPORT_SYMBOL(usb_gadget_unregister_driver); 2051EXPORT_SYMBOL(usb_gadget_unregister_driver);
2052EXPORT_SYMBOL(usb_gadget_register_driver);
2053 2052
2054module_init(udc_init); 2053module_init(udc_init);
2055module_exit(udc_exit); 2054module_exit(udc_exit);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index b22eedbc7dc5..1ac57a973aa9 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -137,7 +137,7 @@ MODULE_PARM_DESC(n_ports, "number of ports to create, default=1");
137 137
138/*-------------------------------------------------------------------------*/ 138/*-------------------------------------------------------------------------*/
139 139
140static int __ref serial_bind_config(struct usb_configuration *c) 140static int __init serial_bind_config(struct usb_configuration *c)
141{ 141{
142 unsigned i; 142 unsigned i;
143 int status = 0; 143 int status = 0;
@@ -155,13 +155,12 @@ static int __ref serial_bind_config(struct usb_configuration *c)
155 155
156static struct usb_configuration serial_config_driver = { 156static struct usb_configuration serial_config_driver = {
157 /* .label = f(use_acm) */ 157 /* .label = f(use_acm) */
158 .bind = serial_bind_config,
159 /* .bConfigurationValue = f(use_acm) */ 158 /* .bConfigurationValue = f(use_acm) */
160 /* .iConfiguration = DYNAMIC */ 159 /* .iConfiguration = DYNAMIC */
161 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 160 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
162}; 161};
163 162
164static int __ref gs_bind(struct usb_composite_dev *cdev) 163static int __init gs_bind(struct usb_composite_dev *cdev)
165{ 164{
166 int gcnum; 165 int gcnum;
167 struct usb_gadget *gadget = cdev->gadget; 166 struct usb_gadget *gadget = cdev->gadget;
@@ -225,7 +224,8 @@ static int __ref gs_bind(struct usb_composite_dev *cdev)
225 } 224 }
226 225
227 /* register our configuration */ 226 /* register our configuration */
228 status = usb_add_config(cdev, &serial_config_driver); 227 status = usb_add_config(cdev, &serial_config_driver,
228 serial_bind_config);
229 if (status < 0) 229 if (status < 0)
230 goto fail; 230 goto fail;
231 231
@@ -242,7 +242,6 @@ static struct usb_composite_driver gserial_driver = {
242 .name = "g_serial", 242 .name = "g_serial",
243 .dev = &device_desc, 243 .dev = &device_desc,
244 .strings = dev_strings, 244 .strings = dev_strings,
245 .bind = gs_bind,
246}; 245};
247 246
248static int __init init(void) 247static int __init init(void)
@@ -271,7 +270,7 @@ static int __init init(void)
271 } 270 }
272 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label; 271 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label;
273 272
274 return usb_composite_register(&gserial_driver); 273 return usb_composite_probe(&gserial_driver, gs_bind);
275} 274}
276module_init(init); 275module_init(init);
277 276
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 484acfb1a7c5..3b513bafaf2a 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -26,7 +26,6 @@
26 * be defined (each of type pointer to char): 26 * be defined (each of type pointer to char):
27 * - fsg_string_manufacturer -- name of the manufacturer 27 * - fsg_string_manufacturer -- name of the manufacturer
28 * - fsg_string_product -- name of the product 28 * - fsg_string_product -- name of the product
29 * - fsg_string_serial -- product's serial
30 * - fsg_string_config -- name of the configuration 29 * - fsg_string_config -- name of the configuration
31 * - fsg_string_interface -- name of the interface 30 * - fsg_string_interface -- name of the interface
32 * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS 31 * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
@@ -54,6 +53,8 @@
54 */ 53 */
55 54
56 55
56#include <linux/usb/storage.h>
57#include <scsi/scsi.h>
57#include <asm/unaligned.h> 58#include <asm/unaligned.h>
58 59
59 60
@@ -153,23 +154,6 @@
153 154
154/*-------------------------------------------------------------------------*/ 155/*-------------------------------------------------------------------------*/
155 156
156/* SCSI device types */
157#define TYPE_DISK 0x00
158#define TYPE_CDROM 0x05
159
160/* USB protocol value = the transport method */
161#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */
162#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */
163#define USB_PR_BULK 0x50 /* Bulk-only */
164
165/* USB subclass value = the protocol encapsulation */
166#define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */
167#define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */
168#define USB_SC_QIC 0x03 /* QIC-157 (tape) */
169#define USB_SC_UFI 0x04 /* UFI (floppy) */
170#define USB_SC_8070 0x05 /* SFF-8070i (removable) */
171#define USB_SC_SCSI 0x06 /* Transparent SCSI */
172
173/* Bulk-only data structures */ 157/* Bulk-only data structures */
174 158
175/* Command Block Wrapper */ 159/* Command Block Wrapper */
@@ -221,33 +205,6 @@ struct interrupt_data {
221/* Length of a SCSI Command Data Block */ 205/* Length of a SCSI Command Data Block */
222#define MAX_COMMAND_SIZE 16 206#define MAX_COMMAND_SIZE 16
223 207
224/* SCSI commands that we recognize */
225#define SC_FORMAT_UNIT 0x04
226#define SC_INQUIRY 0x12
227#define SC_MODE_SELECT_6 0x15
228#define SC_MODE_SELECT_10 0x55
229#define SC_MODE_SENSE_6 0x1a
230#define SC_MODE_SENSE_10 0x5a
231#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
232#define SC_READ_6 0x08
233#define SC_READ_10 0x28
234#define SC_READ_12 0xa8
235#define SC_READ_CAPACITY 0x25
236#define SC_READ_FORMAT_CAPACITIES 0x23
237#define SC_READ_HEADER 0x44
238#define SC_READ_TOC 0x43
239#define SC_RELEASE 0x17
240#define SC_REQUEST_SENSE 0x03
241#define SC_RESERVE 0x16
242#define SC_SEND_DIAGNOSTIC 0x1d
243#define SC_START_STOP_UNIT 0x1b
244#define SC_SYNCHRONIZE_CACHE 0x35
245#define SC_TEST_UNIT_READY 0x00
246#define SC_VERIFY 0x2f
247#define SC_WRITE_6 0x0a
248#define SC_WRITE_10 0x2a
249#define SC_WRITE_12 0xaa
250
251/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ 208/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
252#define SS_NO_SENSE 0 209#define SS_NO_SENSE 0
253#define SS_COMMUNICATION_FAILURE 0x040800 210#define SS_COMMUNICATION_FAILURE 0x040800
@@ -552,7 +509,7 @@ static struct usb_string fsg_strings[] = {
552#ifndef FSG_NO_DEVICE_STRINGS 509#ifndef FSG_NO_DEVICE_STRINGS
553 {FSG_STRING_MANUFACTURER, fsg_string_manufacturer}, 510 {FSG_STRING_MANUFACTURER, fsg_string_manufacturer},
554 {FSG_STRING_PRODUCT, fsg_string_product}, 511 {FSG_STRING_PRODUCT, fsg_string_product},
555 {FSG_STRING_SERIAL, fsg_string_serial}, 512 {FSG_STRING_SERIAL, ""},
556 {FSG_STRING_CONFIG, fsg_string_config}, 513 {FSG_STRING_CONFIG, fsg_string_config},
557#endif 514#endif
558 {FSG_STRING_INTERFACE, fsg_string_interface}, 515 {FSG_STRING_INTERFACE, fsg_string_interface},
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index de1deb7a3c63..a5a0fdb808c7 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -308,7 +308,7 @@ static const struct uvc_descriptor_header * const uvc_hs_streaming_cls[] = {
308 * USB configuration 308 * USB configuration
309 */ 309 */
310 310
311static int __ref 311static int __init
312webcam_config_bind(struct usb_configuration *c) 312webcam_config_bind(struct usb_configuration *c)
313{ 313{
314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls, 314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls,
@@ -317,7 +317,6 @@ webcam_config_bind(struct usb_configuration *c)
317 317
318static struct usb_configuration webcam_config_driver = { 318static struct usb_configuration webcam_config_driver = {
319 .label = webcam_config_label, 319 .label = webcam_config_label,
320 .bind = webcam_config_bind,
321 .bConfigurationValue = 1, 320 .bConfigurationValue = 1,
322 .iConfiguration = 0, /* dynamic */ 321 .iConfiguration = 0, /* dynamic */
323 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 322 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -330,7 +329,7 @@ webcam_unbind(struct usb_composite_dev *cdev)
330 return 0; 329 return 0;
331} 330}
332 331
333static int __ref 332static int __init
334webcam_bind(struct usb_composite_dev *cdev) 333webcam_bind(struct usb_composite_dev *cdev)
335{ 334{
336 int ret; 335 int ret;
@@ -354,7 +353,8 @@ webcam_bind(struct usb_composite_dev *cdev)
354 webcam_config_driver.iConfiguration = ret; 353 webcam_config_driver.iConfiguration = ret;
355 354
356 /* Register our configuration. */ 355 /* Register our configuration. */
357 if ((ret = usb_add_config(cdev, &webcam_config_driver)) < 0) 356 if ((ret = usb_add_config(cdev, &webcam_config_driver,
357 webcam_config_bind)) < 0)
358 goto error; 358 goto error;
359 359
360 INFO(cdev, "Webcam Video Gadget\n"); 360 INFO(cdev, "Webcam Video Gadget\n");
@@ -373,14 +373,13 @@ static struct usb_composite_driver webcam_driver = {
373 .name = "g_webcam", 373 .name = "g_webcam",
374 .dev = &webcam_device_descriptor, 374 .dev = &webcam_device_descriptor,
375 .strings = webcam_device_strings, 375 .strings = webcam_device_strings,
376 .bind = webcam_bind,
377 .unbind = webcam_unbind, 376 .unbind = webcam_unbind,
378}; 377};
379 378
380static int __init 379static int __init
381webcam_init(void) 380webcam_init(void)
382{ 381{
383 return usb_composite_register(&webcam_driver); 382 return usb_composite_probe(&webcam_driver, webcam_bind);
384} 383}
385 384
386static void __exit 385static void __exit
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index cf353920bb1c..6d16db9d9d2d 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -264,7 +264,7 @@ static void zero_resume(struct usb_composite_dev *cdev)
264 264
265/*-------------------------------------------------------------------------*/ 265/*-------------------------------------------------------------------------*/
266 266
267static int __ref zero_bind(struct usb_composite_dev *cdev) 267static int __init zero_bind(struct usb_composite_dev *cdev)
268{ 268{
269 int gcnum; 269 int gcnum;
270 struct usb_gadget *gadget = cdev->gadget; 270 struct usb_gadget *gadget = cdev->gadget;
@@ -340,7 +340,6 @@ static struct usb_composite_driver zero_driver = {
340 .name = "zero", 340 .name = "zero",
341 .dev = &device_desc, 341 .dev = &device_desc,
342 .strings = dev_strings, 342 .strings = dev_strings,
343 .bind = zero_bind,
344 .unbind = zero_unbind, 343 .unbind = zero_unbind,
345 .suspend = zero_suspend, 344 .suspend = zero_suspend,
346 .resume = zero_resume, 345 .resume = zero_resume,
@@ -351,7 +350,7 @@ MODULE_LICENSE("GPL");
351 350
352static int __init init(void) 351static int __init init(void)
353{ 352{
354 return usb_composite_register(&zero_driver); 353 return usb_composite_probe(&zero_driver, zero_bind);
355} 354}
356module_init(init); 355module_init(init);
357 356