aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/Kconfig20
-rw-r--r--drivers/usb/gadget/Makefile8
-rw-r--r--drivers/usb/gadget/acm_ms.c42
-rw-r--r--drivers/usb/gadget/amd5536udc.c59
-rw-r--r--drivers/usb/gadget/amd5536udc.h2
-rw-r--r--drivers/usb/gadget/at91_udc.c5
-rw-r--r--drivers/usb/gadget/cdc2.c36
-rw-r--r--drivers/usb/gadget/composite.c326
-rw-r--r--drivers/usb/gadget/dbgp.c14
-rw-r--r--drivers/usb/gadget/f_acm.c153
-rw-r--r--drivers/usb/gadget/f_fs.c5
-rw-r--r--drivers/usb/gadget/f_loopback.c103
-rw-r--r--drivers/usb/gadget/f_mass_storage.c37
-rw-r--r--drivers/usb/gadget/f_ncm.c18
-rw-r--r--drivers/usb/gadget/f_obex.c4
-rw-r--r--drivers/usb/gadget/f_serial.c4
-rw-r--r--drivers/usb/gadget/f_sourcesink.c200
-rw-r--r--drivers/usb/gadget/f_uac2.c9
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c2
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c60
-rw-r--r--drivers/usb/gadget/functions.c116
-rw-r--r--drivers/usb/gadget/fusb300_udc.c67
-rw-r--r--drivers/usb/gadget/fusb300_udc.h2
-rw-r--r--drivers/usb/gadget/g_zero.h35
-rw-r--r--drivers/usb/gadget/gmidi.c2
-rw-r--r--drivers/usb/gadget/goku_udc.c70
-rw-r--r--drivers/usb/gadget/goku_udc.h1
-rw-r--r--drivers/usb/gadget/m66592-udc.c72
-rw-r--r--drivers/usb/gadget/m66592-udc.h1
-rw-r--r--drivers/usb/gadget/multi.c71
-rw-r--r--drivers/usb/gadget/mv_udc_core.c246
-rw-r--r--drivers/usb/gadget/nokia.c43
-rw-r--r--drivers/usb/gadget/omap_udc.c51
-rw-r--r--drivers/usb/gadget/pch_udc.c67
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c62
-rw-r--r--drivers/usb/gadget/pxa25x_udc.h1
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c61
-rw-r--r--drivers/usb/gadget/pxa27x_udc.h1
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c2
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c7
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c13
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c65
-rw-r--r--drivers/usb/gadget/s3c2410_udc.h1
-rw-r--r--drivers/usb/gadget/serial.c118
-rw-r--r--drivers/usb/gadget/storage_common.c61
-rw-r--r--drivers/usb/gadget/u_serial.c313
-rw-r--r--drivers/usb/gadget/u_serial.h13
-rw-r--r--drivers/usb/gadget/udc-core.c157
-rw-r--r--drivers/usb/gadget/webcam.c2
-rw-r--r--drivers/usb/gadget/zero.c233
-rw-r--r--drivers/usb/host/ehci-mv.c1
-rw-r--r--drivers/usb/otg/mv_otg.c82
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c2
53 files changed, 1671 insertions, 1475 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 14625fd2cecd..6665d255d32a 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -500,6 +500,15 @@ config USB_LIBCOMPOSITE
500 tristate 500 tristate
501 depends on USB_GADGET 501 depends on USB_GADGET
502 502
503config USB_F_ACM
504 tristate
505
506config USB_F_SS_LB
507 tristate
508
509config USB_U_SERIAL
510 tristate
511
503choice 512choice
504 tristate "USB Gadget Drivers" 513 tristate "USB Gadget Drivers"
505 default USB_ETH 514 default USB_ETH
@@ -524,6 +533,7 @@ choice
524config USB_ZERO 533config USB_ZERO
525 tristate "Gadget Zero (DEVELOPMENT)" 534 tristate "Gadget Zero (DEVELOPMENT)"
526 select USB_LIBCOMPOSITE 535 select USB_LIBCOMPOSITE
536 select USB_F_SS_LB
527 help 537 help
528 Gadget Zero is a two-configuration device. It either sinks and 538 Gadget Zero is a two-configuration device. It either sinks and
529 sources bulk data; or it loops back a configurable number of 539 sources bulk data; or it loops back a configurable number of
@@ -750,6 +760,8 @@ config USB_GADGET_TARGET
750 760
751config USB_G_SERIAL 761config USB_G_SERIAL
752 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" 762 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)"
763 select USB_U_SERIAL
764 select USB_F_ACM
753 select USB_LIBCOMPOSITE 765 select USB_LIBCOMPOSITE
754 help 766 help
755 The Serial Gadget talks to the Linux-USB generic serial driver. 767 The Serial Gadget talks to the Linux-USB generic serial driver.
@@ -803,6 +815,8 @@ config USB_CDC_COMPOSITE
803 tristate "CDC Composite Device (Ethernet and ACM)" 815 tristate "CDC Composite Device (Ethernet and ACM)"
804 depends on NET 816 depends on NET
805 select USB_LIBCOMPOSITE 817 select USB_LIBCOMPOSITE
818 select USB_U_SERIAL
819 select USB_F_ACM
806 help 820 help
807 This driver provides two functions in one configuration: 821 This driver provides two functions in one configuration:
808 a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link. 822 a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link.
@@ -818,6 +832,7 @@ config USB_G_NOKIA
818 tristate "Nokia composite gadget" 832 tristate "Nokia composite gadget"
819 depends on PHONET 833 depends on PHONET
820 select USB_LIBCOMPOSITE 834 select USB_LIBCOMPOSITE
835 select USB_U_SERIAL
821 help 836 help
822 The Nokia composite gadget provides support for acm, obex 837 The Nokia composite gadget provides support for acm, obex
823 and phonet in only one composite gadget driver. 838 and phonet in only one composite gadget driver.
@@ -829,6 +844,8 @@ config USB_G_ACM_MS
829 tristate "CDC Composite Device (ACM and mass storage)" 844 tristate "CDC Composite Device (ACM and mass storage)"
830 depends on BLOCK 845 depends on BLOCK
831 select USB_LIBCOMPOSITE 846 select USB_LIBCOMPOSITE
847 select USB_U_SERIAL
848 select USB_F_ACM
832 help 849 help
833 This driver provides two functions in one configuration: 850 This driver provides two functions in one configuration:
834 a mass storage, and a CDC ACM (serial port) link. 851 a mass storage, and a CDC ACM (serial port) link.
@@ -841,6 +858,8 @@ config USB_G_MULTI
841 depends on BLOCK && NET 858 depends on BLOCK && NET
842 select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS 859 select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS
843 select USB_LIBCOMPOSITE 860 select USB_LIBCOMPOSITE
861 select USB_U_SERIAL
862 select USB_F_ACM
844 help 863 help
845 The Multifunction Composite Gadget provides Ethernet (RNDIS 864 The Multifunction Composite Gadget provides Ethernet (RNDIS
846 and/or CDC Ethernet), mass storage and ACM serial link 865 and/or CDC Ethernet), mass storage and ACM serial link
@@ -916,6 +935,7 @@ config USB_G_DBGP_PRINTK
916 935
917config USB_G_DBGP_SERIAL 936config USB_G_DBGP_SERIAL
918 depends on USB_G_DBGP 937 depends on USB_G_DBGP
938 select USB_U_SERIAL
919 bool "serial" 939 bool "serial"
920 help 940 help
921 Userland can interact using /dev/ttyGSxxx. 941 Userland can interact using /dev/ttyGSxxx.
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 8b4acfd92aa3..97a13c349cc5 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -6,7 +6,7 @@ ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
6obj-$(CONFIG_USB_GADGET) += udc-core.o 6obj-$(CONFIG_USB_GADGET) += udc-core.o
7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
8libcomposite-y := usbstring.o config.o epautoconf.o 8libcomposite-y := usbstring.o config.o epautoconf.o
9libcomposite-y += composite.o 9libcomposite-y += composite.o functions.o
10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
11obj-$(CONFIG_USB_NET2272) += net2272.o 11obj-$(CONFIG_USB_NET2272) += net2272.o
12obj-$(CONFIG_USB_NET2280) += net2280.o 12obj-$(CONFIG_USB_NET2280) += net2280.o
@@ -74,3 +74,9 @@ obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o
74obj-$(CONFIG_USB_G_NCM) += g_ncm.o 74obj-$(CONFIG_USB_G_NCM) += g_ncm.o
75obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o 75obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o
76obj-$(CONFIG_USB_GADGET_TARGET) += tcm_usb_gadget.o 76obj-$(CONFIG_USB_GADGET_TARGET) += tcm_usb_gadget.o
77
78# USB Functions
79obj-$(CONFIG_USB_F_ACM) += f_acm.o
80f_ss_lb-y := f_loopback.o f_sourcesink.o
81obj-$(CONFIG_USB_F_SS_LB) += f_ss_lb.o
82obj-$(CONFIG_USB_U_SERIAL) += u_serial.o
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 5a7f289805ff..8f2b0e391534 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -40,9 +40,6 @@
40 * the runtime footprint, and giving us at least some parts of what 40 * the runtime footprint, and giving us at least some parts of what
41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
42 */ 42 */
43
44#include "u_serial.c"
45#include "f_acm.c"
46#include "f_mass_storage.c" 43#include "f_mass_storage.c"
47 44
48/*-------------------------------------------------------------------------*/ 45/*-------------------------------------------------------------------------*/
@@ -112,12 +109,15 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
112static struct fsg_common fsg_common; 109static struct fsg_common fsg_common;
113 110
114/*-------------------------------------------------------------------------*/ 111/*-------------------------------------------------------------------------*/
115 112static unsigned char tty_line;
113static struct usb_function *f_acm;
114static struct usb_function_instance *f_acm_inst;
116/* 115/*
117 * We _always_ have both ACM and mass storage functions. 116 * We _always_ have both ACM and mass storage functions.
118 */ 117 */
119static int __init acm_ms_do_config(struct usb_configuration *c) 118static int __init acm_ms_do_config(struct usb_configuration *c)
120{ 119{
120 struct f_serial_opts *opts;
121 int status; 121 int status;
122 122
123 if (gadget_is_otg(c->cdev->gadget)) { 123 if (gadget_is_otg(c->cdev->gadget)) {
@@ -125,16 +125,35 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
125 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 125 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
126 } 126 }
127 127
128 f_acm_inst = usb_get_function_instance("acm");
129 if (IS_ERR(f_acm_inst))
130 return PTR_ERR(f_acm_inst);
131
132 opts = container_of(f_acm_inst, struct f_serial_opts, func_inst);
133 opts->port_num = tty_line;
134
135 f_acm = usb_get_function(f_acm_inst);
136 if (IS_ERR(f_acm)) {
137 status = PTR_ERR(f_acm);
138 goto err_func;
139 }
128 140
129 status = acm_bind_config(c, 0); 141 status = usb_add_function(c, f_acm);
130 if (status < 0) 142 if (status < 0)
131 return status; 143 goto err_conf;
132 144
133 status = fsg_bind_config(c->cdev, c, &fsg_common); 145 status = fsg_bind_config(c->cdev, c, &fsg_common);
134 if (status < 0) 146 if (status < 0)
135 return status; 147 goto err_fsg;
136 148
137 return 0; 149 return 0;
150err_fsg:
151 usb_remove_function(c, f_acm);
152err_conf:
153 usb_put_function(f_acm);
154err_func:
155 usb_put_function_instance(f_acm_inst);
156 return status;
138} 157}
139 158
140static struct usb_configuration acm_ms_config_driver = { 159static struct usb_configuration acm_ms_config_driver = {
@@ -153,7 +172,7 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
153 void *retp; 172 void *retp;
154 173
155 /* set up serial link layer */ 174 /* set up serial link layer */
156 status = gserial_setup(cdev->gadget, 1); 175 status = gserial_alloc_line(&tty_line);
157 if (status < 0) 176 if (status < 0)
158 return status; 177 return status;
159 178
@@ -189,14 +208,15 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
189fail1: 208fail1:
190 fsg_common_put(&fsg_common); 209 fsg_common_put(&fsg_common);
191fail0: 210fail0:
192 gserial_cleanup(); 211 gserial_free_line(tty_line);
193 return status; 212 return status;
194} 213}
195 214
196static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) 215static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
197{ 216{
198 gserial_cleanup(); 217 usb_put_function(f_acm);
199 218 usb_put_function_instance(f_acm_inst);
219 gserial_free_line(tty_line);
200 return 0; 220 return 0;
201} 221}
202 222
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index d9f6b9372491..75973f33a4c8 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1400,15 +1400,16 @@ static int udc_wakeup(struct usb_gadget *gadget)
1400 return 0; 1400 return 0;
1401} 1401}
1402 1402
1403static int amd5536_start(struct usb_gadget_driver *driver, 1403static int amd5536_udc_start(struct usb_gadget *g,
1404 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1404 struct usb_gadget_driver *driver);
1405static int amd5536_stop(struct usb_gadget_driver *driver); 1405static int amd5536_udc_stop(struct usb_gadget *g,
1406 struct usb_gadget_driver *driver);
1406/* gadget operations */ 1407/* gadget operations */
1407static const struct usb_gadget_ops udc_ops = { 1408static const struct usb_gadget_ops udc_ops = {
1408 .wakeup = udc_wakeup, 1409 .wakeup = udc_wakeup,
1409 .get_frame = udc_get_frame, 1410 .get_frame = udc_get_frame,
1410 .start = amd5536_start, 1411 .udc_start = amd5536_udc_start,
1411 .stop = amd5536_stop, 1412 .udc_stop = amd5536_udc_stop,
1412}; 1413};
1413 1414
1414/* Setups endpoint parameters, adds endpoints to linked list */ 1415/* Setups endpoint parameters, adds endpoints to linked list */
@@ -1913,41 +1914,22 @@ static int setup_ep0(struct udc *dev)
1913} 1914}
1914 1915
1915/* Called by gadget driver to register itself */ 1916/* Called by gadget driver to register itself */
1916static int amd5536_start(struct usb_gadget_driver *driver, 1917static int amd5536_udc_start(struct usb_gadget *g,
1917 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1918 struct usb_gadget_driver *driver)
1918{ 1919{
1919 struct udc *dev = udc; 1920 struct udc *dev = to_amd5536_udc(g);
1920 int retval;
1921 u32 tmp; 1921 u32 tmp;
1922 1922
1923 if (!driver || !bind || !driver->setup
1924 || driver->max_speed < USB_SPEED_HIGH)
1925 return -EINVAL;
1926 if (!dev)
1927 return -ENODEV;
1928 if (dev->driver)
1929 return -EBUSY;
1930
1931 driver->driver.bus = NULL; 1923 driver->driver.bus = NULL;
1932 dev->driver = driver; 1924 dev->driver = driver;
1933 dev->gadget.dev.driver = &driver->driver; 1925 dev->gadget.dev.driver = &driver->driver;
1934 1926
1935 retval = bind(&dev->gadget, driver);
1936
1937 /* Some gadget drivers use both ep0 directions. 1927 /* Some gadget drivers use both ep0 directions.
1938 * NOTE: to gadget driver, ep0 is just one endpoint... 1928 * NOTE: to gadget driver, ep0 is just one endpoint...
1939 */ 1929 */
1940 dev->ep[UDC_EP0OUT_IX].ep.driver_data = 1930 dev->ep[UDC_EP0OUT_IX].ep.driver_data =
1941 dev->ep[UDC_EP0IN_IX].ep.driver_data; 1931 dev->ep[UDC_EP0IN_IX].ep.driver_data;
1942 1932
1943 if (retval) {
1944 DBG(dev, "binding to %s returning %d\n",
1945 driver->driver.name, retval);
1946 dev->driver = NULL;
1947 dev->gadget.dev.driver = NULL;
1948 return retval;
1949 }
1950
1951 /* get ready for ep0 traffic */ 1933 /* get ready for ep0 traffic */
1952 setup_ep0(dev); 1934 setup_ep0(dev);
1953 1935
@@ -1969,14 +1951,9 @@ __acquires(dev->lock)
1969{ 1951{
1970 int tmp; 1952 int tmp;
1971 1953
1972 if (dev->gadget.speed != USB_SPEED_UNKNOWN) {
1973 spin_unlock(&dev->lock);
1974 driver->disconnect(&dev->gadget);
1975 spin_lock(&dev->lock);
1976 }
1977
1978 /* empty queues and init hardware */ 1954 /* empty queues and init hardware */
1979 udc_basic_init(dev); 1955 udc_basic_init(dev);
1956
1980 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) 1957 for (tmp = 0; tmp < UDC_EP_NUM; tmp++)
1981 empty_req_queue(&dev->ep[tmp]); 1958 empty_req_queue(&dev->ep[tmp]);
1982 1959
@@ -1984,23 +1961,18 @@ __acquires(dev->lock)
1984} 1961}
1985 1962
1986/* Called by gadget driver to unregister itself */ 1963/* Called by gadget driver to unregister itself */
1987static int amd5536_stop(struct usb_gadget_driver *driver) 1964static int amd5536_udc_stop(struct usb_gadget *g,
1965 struct usb_gadget_driver *driver)
1988{ 1966{
1989 struct udc *dev = udc; 1967 struct udc *dev = to_amd5536_udc(g);
1990 unsigned long flags; 1968 unsigned long flags;
1991 u32 tmp; 1969 u32 tmp;
1992 1970
1993 if (!dev)
1994 return -ENODEV;
1995 if (!driver || driver != dev->driver || !driver->unbind)
1996 return -EINVAL;
1997
1998 spin_lock_irqsave(&dev->lock, flags); 1971 spin_lock_irqsave(&dev->lock, flags);
1999 udc_mask_unused_interrupts(dev); 1972 udc_mask_unused_interrupts(dev);
2000 shutdown(dev, driver); 1973 shutdown(dev, driver);
2001 spin_unlock_irqrestore(&dev->lock, flags); 1974 spin_unlock_irqrestore(&dev->lock, flags);
2002 1975
2003 driver->unbind(&dev->gadget);
2004 dev->gadget.dev.driver = NULL; 1976 dev->gadget.dev.driver = NULL;
2005 dev->driver = NULL; 1977 dev->driver = NULL;
2006 1978
@@ -2009,9 +1981,6 @@ static int amd5536_stop(struct usb_gadget_driver *driver)
2009 tmp |= AMD_BIT(UDC_DEVCTL_SD); 1981 tmp |= AMD_BIT(UDC_DEVCTL_SD);
2010 writel(tmp, &dev->regs->ctl); 1982 writel(tmp, &dev->regs->ctl);
2011 1983
2012
2013 DBG(dev, "%s: unregistered\n", driver->driver.name);
2014
2015 return 0; 1984 return 0;
2016} 1985}
2017 1986
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h
index 14af87d65caa..f1bf32e6b8d8 100644
--- a/drivers/usb/gadget/amd5536udc.h
+++ b/drivers/usb/gadget/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
563 u16 cur_alt; 563 u16 cur_alt;
564}; 564};
565 565
566#define to_amd5536_udc(g) (container_of((g), struct udc, gadget))
567
566/* setup request data */ 568/* setup request data */
567union udc_setup_data { 569union udc_setup_data {
568 u32 data[2]; 570 u32 data[2];
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index f4a21f6f081f..10f45fa01abd 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1621,8 +1621,7 @@ static void at91_vbus_timer(unsigned long data)
1621 * bus such as i2c or spi which may sleep, so schedule some work 1621 * bus such as i2c or spi which may sleep, so schedule some work
1622 * to read the vbus gpio 1622 * to read the vbus gpio
1623 */ 1623 */
1624 if (!work_pending(&udc->vbus_timer_work)) 1624 schedule_work(&udc->vbus_timer_work);
1625 schedule_work(&udc->vbus_timer_work);
1626} 1625}
1627 1626
1628static int at91_start(struct usb_gadget *gadget, 1627static int at91_start(struct usb_gadget *gadget,
@@ -1739,7 +1738,7 @@ static int at91udc_probe(struct platform_device *pdev)
1739 1738
1740 /* rm9200 needs manual D+ pullup; off by default */ 1739 /* rm9200 needs manual D+ pullup; off by default */
1741 if (cpu_is_at91rm9200()) { 1740 if (cpu_is_at91rm9200()) {
1742 if (gpio_is_valid(udc->board.pullup_pin)) { 1741 if (!gpio_is_valid(udc->board.pullup_pin)) {
1743 DBG("no D+ pullup?\n"); 1742 DBG("no D+ pullup?\n");
1744 retval = -ENODEV; 1743 retval = -ENODEV;
1745 goto fail0; 1744 goto fail0;
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 1e4bb77f00bb..a7d6f7026757 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -42,9 +42,6 @@ USB_GADGET_COMPOSITE_OPTIONS();
42 * the runtime footprint, and giving us at least some parts of what 42 * the runtime footprint, and giving us at least some parts of what
43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
44 */ 44 */
45
46#include "u_serial.c"
47#include "f_acm.c"
48#include "f_ecm.c" 45#include "f_ecm.c"
49#include "u_ether.c" 46#include "u_ether.c"
50 47
@@ -108,12 +105,16 @@ static struct usb_gadget_strings *dev_strings[] = {
108static u8 hostaddr[ETH_ALEN]; 105static u8 hostaddr[ETH_ALEN];
109 106
110/*-------------------------------------------------------------------------*/ 107/*-------------------------------------------------------------------------*/
108static struct usb_function *f_acm;
109static struct usb_function_instance *fi_serial;
111 110
111static unsigned char tty_line;
112/* 112/*
113 * We _always_ have both CDC ECM and CDC ACM functions. 113 * We _always_ have both CDC ECM and CDC ACM functions.
114 */ 114 */
115static int __init cdc_do_config(struct usb_configuration *c) 115static int __init cdc_do_config(struct usb_configuration *c)
116{ 116{
117 struct f_serial_opts *opts;
117 int status; 118 int status;
118 119
119 if (gadget_is_otg(c->cdev->gadget)) { 120 if (gadget_is_otg(c->cdev->gadget)) {
@@ -125,11 +126,26 @@ static int __init cdc_do_config(struct usb_configuration *c)
125 if (status < 0) 126 if (status < 0)
126 return status; 127 return status;
127 128
128 status = acm_bind_config(c, 0); 129 fi_serial = usb_get_function_instance("acm");
129 if (status < 0) 130 if (IS_ERR(fi_serial))
130 return status; 131 return PTR_ERR(fi_serial);
131 132
133 opts = container_of(fi_serial, struct f_serial_opts, func_inst);
134 opts->port_num = tty_line;
135
136 f_acm = usb_get_function(fi_serial);
137 if (IS_ERR(f_acm))
138 goto err_func_acm;
139
140 status = usb_add_function(c, f_acm);
141 if (status)
142 goto err_conf;
132 return 0; 143 return 0;
144err_conf:
145 usb_put_function(f_acm);
146err_func_acm:
147 usb_put_function_instance(fi_serial);
148 return status;
133} 149}
134 150
135static struct usb_configuration cdc_config_driver = { 151static struct usb_configuration cdc_config_driver = {
@@ -158,7 +174,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
158 return status; 174 return status;
159 175
160 /* set up serial link layer */ 176 /* set up serial link layer */
161 status = gserial_setup(cdev->gadget, 1); 177 status = gserial_alloc_line(&tty_line);
162 if (status < 0) 178 if (status < 0)
163 goto fail0; 179 goto fail0;
164 180
@@ -184,7 +200,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
184 return 0; 200 return 0;
185 201
186fail1: 202fail1:
187 gserial_cleanup(); 203 gserial_free_line(tty_line);
188fail0: 204fail0:
189 gether_cleanup(); 205 gether_cleanup();
190 return status; 206 return status;
@@ -192,7 +208,9 @@ fail0:
192 208
193static int __exit cdc_unbind(struct usb_composite_dev *cdev) 209static int __exit cdc_unbind(struct usb_composite_dev *cdev)
194{ 210{
195 gserial_cleanup(); 211 usb_put_function(f_acm);
212 usb_put_function_instance(fi_serial);
213 gserial_free_line(tty_line);
196 gether_cleanup(); 214 gether_cleanup();
197 return 0; 215 return 0;
198} 216}
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 2a6bfe759c29..7c821de8ce3d 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -28,6 +28,12 @@
28 * with the relevant device-wide data. 28 * with the relevant device-wide data.
29 */ 29 */
30 30
31static struct usb_gadget_strings **get_containers_gs(
32 struct usb_gadget_string_container *uc)
33{
34 return (struct usb_gadget_strings **)uc->stash;
35}
36
31/** 37/**
32 * next_ep_desc() - advance to the next EP descriptor 38 * next_ep_desc() - advance to the next EP descriptor
33 * @t: currect pointer within descriptor array 39 * @t: currect pointer within descriptor array
@@ -215,6 +221,18 @@ done:
215} 221}
216EXPORT_SYMBOL_GPL(usb_add_function); 222EXPORT_SYMBOL_GPL(usb_add_function);
217 223
224void usb_remove_function(struct usb_configuration *c, struct usb_function *f)
225{
226 if (f->disable)
227 f->disable(f);
228
229 bitmap_zero(f->endpoints, 32);
230 list_del(&f->list);
231 if (f->unbind)
232 f->unbind(c, f);
233}
234EXPORT_SYMBOL_GPL(usb_remove_function);
235
218/** 236/**
219 * usb_function_deactivate - prevent function and gadget enumeration 237 * usb_function_deactivate - prevent function and gadget enumeration
220 * @function: the function that isn't yet ready to respond 238 * @function: the function that isn't yet ready to respond
@@ -320,6 +338,25 @@ int usb_interface_id(struct usb_configuration *config,
320} 338}
321EXPORT_SYMBOL_GPL(usb_interface_id); 339EXPORT_SYMBOL_GPL(usb_interface_id);
322 340
341static u8 encode_bMaxPower(enum usb_device_speed speed,
342 struct usb_configuration *c)
343{
344 unsigned val;
345
346 if (c->MaxPower)
347 val = c->MaxPower;
348 else
349 val = CONFIG_USB_GADGET_VBUS_DRAW;
350 if (!val)
351 return 0;
352 switch (speed) {
353 case USB_SPEED_SUPER:
354 return DIV_ROUND_UP(val, 8);
355 default:
356 return DIV_ROUND_UP(val, 2);
357 };
358}
359
323static int config_buf(struct usb_configuration *config, 360static int config_buf(struct usb_configuration *config,
324 enum usb_device_speed speed, void *buf, u8 type) 361 enum usb_device_speed speed, void *buf, u8 type)
325{ 362{
@@ -339,7 +376,7 @@ static int config_buf(struct usb_configuration *config,
339 c->bConfigurationValue = config->bConfigurationValue; 376 c->bConfigurationValue = config->bConfigurationValue;
340 c->iConfiguration = config->iConfiguration; 377 c->iConfiguration = config->iConfiguration;
341 c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes; 378 c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes;
342 c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2); 379 c->bMaxPower = encode_bMaxPower(speed, config);
343 380
344 /* There may be e.g. OTG descriptors */ 381 /* There may be e.g. OTG descriptors */
345 if (config->descriptors) { 382 if (config->descriptors) {
@@ -656,7 +693,7 @@ static int set_config(struct usb_composite_dev *cdev,
656 } 693 }
657 694
658 /* when we return, be sure our power usage is valid */ 695 /* when we return, be sure our power usage is valid */
659 power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW; 696 power = c->MaxPower ? c->MaxPower : CONFIG_USB_GADGET_VBUS_DRAW;
660done: 697done:
661 usb_gadget_vbus_draw(gadget, power); 698 usb_gadget_vbus_draw(gadget, power);
662 if (result >= 0 && cdev->delayed_status) 699 if (result >= 0 && cdev->delayed_status)
@@ -664,6 +701,31 @@ done:
664 return result; 701 return result;
665} 702}
666 703
704int usb_add_config_only(struct usb_composite_dev *cdev,
705 struct usb_configuration *config)
706{
707 struct usb_configuration *c;
708
709 if (!config->bConfigurationValue)
710 return -EINVAL;
711
712 /* Prevent duplicate configuration identifiers */
713 list_for_each_entry(c, &cdev->configs, list) {
714 if (c->bConfigurationValue == config->bConfigurationValue)
715 return -EBUSY;
716 }
717
718 config->cdev = cdev;
719 list_add_tail(&config->list, &cdev->configs);
720
721 INIT_LIST_HEAD(&config->functions);
722 config->next_interface_id = 0;
723 memset(config->interface, 0, sizeof(config->interface));
724
725 return 0;
726}
727EXPORT_SYMBOL_GPL(usb_add_config_only);
728
667/** 729/**
668 * usb_add_config() - add a configuration to a device. 730 * usb_add_config() - add a configuration to a device.
669 * @cdev: wraps the USB gadget 731 * @cdev: wraps the USB gadget
@@ -684,30 +746,18 @@ int usb_add_config(struct usb_composite_dev *cdev,
684 int (*bind)(struct usb_configuration *)) 746 int (*bind)(struct usb_configuration *))
685{ 747{
686 int status = -EINVAL; 748 int status = -EINVAL;
687 struct usb_configuration *c; 749
750 if (!bind)
751 goto done;
688 752
689 DBG(cdev, "adding config #%u '%s'/%p\n", 753 DBG(cdev, "adding config #%u '%s'/%p\n",
690 config->bConfigurationValue, 754 config->bConfigurationValue,
691 config->label, config); 755 config->label, config);
692 756
693 if (!config->bConfigurationValue || !bind) 757 status = usb_add_config_only(cdev, config);
758 if (status)
694 goto done; 759 goto done;
695 760
696 /* Prevent duplicate configuration identifiers */
697 list_for_each_entry(c, &cdev->configs, list) {
698 if (c->bConfigurationValue == config->bConfigurationValue) {
699 status = -EBUSY;
700 goto done;
701 }
702 }
703
704 config->cdev = cdev;
705 list_add_tail(&config->list, &cdev->configs);
706
707 INIT_LIST_HEAD(&config->functions);
708 config->next_interface_id = 0;
709 memset(config->interface, 0, sizeof(config->interface));
710
711 status = bind(config); 761 status = bind(config);
712 if (status < 0) { 762 if (status < 0) {
713 while (!list_empty(&config->functions)) { 763 while (!list_empty(&config->functions)) {
@@ -860,6 +910,7 @@ static int get_string(struct usb_composite_dev *cdev,
860 void *buf, u16 language, int id) 910 void *buf, u16 language, int id)
861{ 911{
862 struct usb_composite_driver *composite = cdev->driver; 912 struct usb_composite_driver *composite = cdev->driver;
913 struct usb_gadget_string_container *uc;
863 struct usb_configuration *c; 914 struct usb_configuration *c;
864 struct usb_function *f; 915 struct usb_function *f;
865 int len; 916 int len;
@@ -892,6 +943,12 @@ static int get_string(struct usb_composite_dev *cdev,
892 collect_langs(sp, s->wData); 943 collect_langs(sp, s->wData);
893 } 944 }
894 } 945 }
946 list_for_each_entry(uc, &cdev->gstrings, list) {
947 struct usb_gadget_strings **sp;
948
949 sp = get_containers_gs(uc);
950 collect_langs(sp, s->wData);
951 }
895 952
896 for (len = 0; len <= 126 && s->wData[len]; len++) 953 for (len = 0; len <= 126 && s->wData[len]; len++)
897 continue; 954 continue;
@@ -902,6 +959,15 @@ static int get_string(struct usb_composite_dev *cdev,
902 return s->bLength; 959 return s->bLength;
903 } 960 }
904 961
962 list_for_each_entry(uc, &cdev->gstrings, list) {
963 struct usb_gadget_strings **sp;
964
965 sp = get_containers_gs(uc);
966 len = lookup_string(sp, buf, language, id);
967 if (len > 0)
968 return len;
969 }
970
905 /* String IDs are device-scoped, so we look up each string 971 /* String IDs are device-scoped, so we look up each string
906 * table we're told about. These lookups are infrequent; 972 * table we're told about. These lookups are infrequent;
907 * simpler-is-better here. 973 * simpler-is-better here.
@@ -987,6 +1053,119 @@ int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str)
987} 1053}
988EXPORT_SYMBOL_GPL(usb_string_ids_tab); 1054EXPORT_SYMBOL_GPL(usb_string_ids_tab);
989 1055
1056static struct usb_gadget_string_container *copy_gadget_strings(
1057 struct usb_gadget_strings **sp, unsigned n_gstrings,
1058 unsigned n_strings)
1059{
1060 struct usb_gadget_string_container *uc;
1061 struct usb_gadget_strings **gs_array;
1062 struct usb_gadget_strings *gs;
1063 struct usb_string *s;
1064 unsigned mem;
1065 unsigned n_gs;
1066 unsigned n_s;
1067 void *stash;
1068
1069 mem = sizeof(*uc);
1070 mem += sizeof(void *) * (n_gstrings + 1);
1071 mem += sizeof(struct usb_gadget_strings) * n_gstrings;
1072 mem += sizeof(struct usb_string) * (n_strings + 1) * (n_gstrings);
1073 uc = kmalloc(mem, GFP_KERNEL);
1074 if (!uc)
1075 return ERR_PTR(-ENOMEM);
1076 gs_array = get_containers_gs(uc);
1077 stash = uc->stash;
1078 stash += sizeof(void *) * (n_gstrings + 1);
1079 for (n_gs = 0; n_gs < n_gstrings; n_gs++) {
1080 struct usb_string *org_s;
1081
1082 gs_array[n_gs] = stash;
1083 gs = gs_array[n_gs];
1084 stash += sizeof(struct usb_gadget_strings);
1085 gs->language = sp[n_gs]->language;
1086 gs->strings = stash;
1087 org_s = sp[n_gs]->strings;
1088
1089 for (n_s = 0; n_s < n_strings; n_s++) {
1090 s = stash;
1091 stash += sizeof(struct usb_string);
1092 if (org_s->s)
1093 s->s = org_s->s;
1094 else
1095 s->s = "";
1096 org_s++;
1097 }
1098 s = stash;
1099 s->s = NULL;
1100 stash += sizeof(struct usb_string);
1101
1102 }
1103 gs_array[n_gs] = NULL;
1104 return uc;
1105}
1106
1107/**
1108 * usb_gstrings_attach() - attach gadget strings to a cdev and assign ids
1109 * @cdev: the device whose string descriptor IDs are being allocated
1110 * and attached.
1111 * @sp: an array of usb_gadget_strings to attach.
1112 * @n_strings: number of entries in each usb_strings array (sp[]->strings)
1113 *
1114 * This function will create a deep copy of usb_gadget_strings and usb_string
1115 * and attach it to the cdev. The actual string (usb_string.s) will not be
1116 * copied but only a referenced will be made. The struct usb_gadget_strings
1117 * array may contain multiple languges and should be NULL terminated.
1118 * The ->language pointer of each struct usb_gadget_strings has to contain the
1119 * same amount of entries.
1120 * For instance: sp[0] is en-US, sp[1] is es-ES. It is expected that the first
1121 * usb_string entry of es-ES containts the translation of the first usb_string
1122 * entry of en-US. Therefore both entries become the same id assign.
1123 */
1124struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev,
1125 struct usb_gadget_strings **sp, unsigned n_strings)
1126{
1127 struct usb_gadget_string_container *uc;
1128 struct usb_gadget_strings **n_gs;
1129 unsigned n_gstrings = 0;
1130 unsigned i;
1131 int ret;
1132
1133 for (i = 0; sp[i]; i++)
1134 n_gstrings++;
1135
1136 if (!n_gstrings)
1137 return ERR_PTR(-EINVAL);
1138
1139 uc = copy_gadget_strings(sp, n_gstrings, n_strings);
1140 if (IS_ERR(uc))
1141 return ERR_PTR(PTR_ERR(uc));
1142
1143 n_gs = get_containers_gs(uc);
1144 ret = usb_string_ids_tab(cdev, n_gs[0]->strings);
1145 if (ret)
1146 goto err;
1147
1148 for (i = 1; i < n_gstrings; i++) {
1149 struct usb_string *m_s;
1150 struct usb_string *s;
1151 unsigned n;
1152
1153 m_s = n_gs[0]->strings;
1154 s = n_gs[i]->strings;
1155 for (n = 0; n < n_strings; n++) {
1156 s->id = m_s->id;
1157 s++;
1158 m_s++;
1159 }
1160 }
1161 list_add_tail(&uc->list, &cdev->gstrings);
1162 return n_gs[0]->strings;
1163err:
1164 kfree(uc);
1165 return ERR_PTR(ret);
1166}
1167EXPORT_SYMBOL_GPL(usb_gstrings_attach);
1168
990/** 1169/**
991 * usb_string_ids_n() - allocate unused string IDs in batch 1170 * usb_string_ids_n() - allocate unused string IDs in batch
992 * @c: the device whose string descriptor IDs are being allocated 1171 * @c: the device whose string descriptor IDs are being allocated
@@ -1033,7 +1212,7 @@ static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
1033 * housekeeping for the gadget function we're implementing. Most of 1212 * housekeeping for the gadget function we're implementing. Most of
1034 * the work is in config and function specific setup. 1213 * the work is in config and function specific setup.
1035 */ 1214 */
1036static int 1215int
1037composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) 1216composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1038{ 1217{
1039 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1218 struct usb_composite_dev *cdev = get_gadget_data(gadget);
@@ -1300,7 +1479,7 @@ done:
1300 return value; 1479 return value;
1301} 1480}
1302 1481
1303static void composite_disconnect(struct usb_gadget *gadget) 1482void composite_disconnect(struct usb_gadget *gadget)
1304{ 1483{
1305 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1484 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1306 unsigned long flags; 1485 unsigned long flags;
@@ -1330,8 +1509,7 @@ static ssize_t composite_show_suspended(struct device *dev,
1330 1509
1331static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL); 1510static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);
1332 1511
1333static void 1512static void __composite_unbind(struct usb_gadget *gadget, bool unbind_driver)
1334composite_unbind(struct usb_gadget *gadget)
1335{ 1513{
1336 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1514 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1337 1515
@@ -1348,19 +1526,21 @@ composite_unbind(struct usb_gadget *gadget)
1348 struct usb_configuration, list); 1526 struct usb_configuration, list);
1349 remove_config(cdev, c); 1527 remove_config(cdev, c);
1350 } 1528 }
1351 if (cdev->driver->unbind) 1529 if (cdev->driver->unbind && unbind_driver)
1352 cdev->driver->unbind(cdev); 1530 cdev->driver->unbind(cdev);
1353 1531
1354 if (cdev->req) { 1532 composite_dev_cleanup(cdev);
1355 kfree(cdev->req->buf); 1533
1356 usb_ep_free_request(gadget->ep0, cdev->req);
1357 }
1358 device_remove_file(&gadget->dev, &dev_attr_suspended);
1359 kfree(cdev->def_manufacturer); 1534 kfree(cdev->def_manufacturer);
1360 kfree(cdev); 1535 kfree(cdev);
1361 set_gadget_data(gadget, NULL); 1536 set_gadget_data(gadget, NULL);
1362} 1537}
1363 1538
1539static void composite_unbind(struct usb_gadget *gadget)
1540{
1541 __composite_unbind(gadget, true);
1542}
1543
1364static void update_unchanged_dev_desc(struct usb_device_descriptor *new, 1544static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
1365 const struct usb_device_descriptor *old) 1545 const struct usb_device_descriptor *old)
1366{ 1546{
@@ -1399,34 +1579,25 @@ static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
1399 new->iProduct = iProduct; 1579 new->iProduct = iProduct;
1400} 1580}
1401 1581
1402static struct usb_composite_driver *to_cdriver(struct usb_gadget_driver *gdrv) 1582int composite_dev_prepare(struct usb_composite_driver *composite,
1403{ 1583 struct usb_composite_dev *cdev)
1404 return container_of(gdrv, struct usb_composite_driver, gadget_driver);
1405}
1406
1407static int composite_bind(struct usb_gadget *gadget,
1408 struct usb_gadget_driver *gdriver)
1409{ 1584{
1410 struct usb_composite_dev *cdev; 1585 struct usb_gadget *gadget = cdev->gadget;
1411 struct usb_composite_driver *composite = to_cdriver(gdriver); 1586 int ret = -ENOMEM;
1412 int status = -ENOMEM;
1413
1414 cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
1415 if (!cdev)
1416 return status;
1417
1418 spin_lock_init(&cdev->lock);
1419 cdev->gadget = gadget;
1420 set_gadget_data(gadget, cdev);
1421 INIT_LIST_HEAD(&cdev->configs);
1422 1587
1423 /* preallocate control response and buffer */ 1588 /* preallocate control response and buffer */
1424 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); 1589 cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
1425 if (!cdev->req) 1590 if (!cdev->req)
1426 goto fail; 1591 return -ENOMEM;
1592
1427 cdev->req->buf = kmalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL); 1593 cdev->req->buf = kmalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL);
1428 if (!cdev->req->buf) 1594 if (!cdev->req->buf)
1429 goto fail; 1595 goto fail;
1596
1597 ret = device_create_file(&gadget->dev, &dev_attr_suspended);
1598 if (ret)
1599 goto fail_dev;
1600
1430 cdev->req->complete = composite_setup_complete; 1601 cdev->req->complete = composite_setup_complete;
1431 gadget->ep0->driver_data = cdev; 1602 gadget->ep0->driver_data = cdev;
1432 1603
@@ -1444,7 +1615,51 @@ static int composite_bind(struct usb_gadget *gadget,
1444 * we force endpoints to start unassigned; few controller 1615 * we force endpoints to start unassigned; few controller
1445 * drivers will zero ep->driver_data. 1616 * drivers will zero ep->driver_data.
1446 */ 1617 */
1447 usb_ep_autoconfig_reset(cdev->gadget); 1618 usb_ep_autoconfig_reset(gadget);
1619 return 0;
1620fail_dev:
1621 kfree(cdev->req->buf);
1622fail:
1623 usb_ep_free_request(gadget->ep0, cdev->req);
1624 cdev->req = NULL;
1625 return ret;
1626}
1627
1628void composite_dev_cleanup(struct usb_composite_dev *cdev)
1629{
1630 struct usb_gadget_string_container *uc, *tmp;
1631
1632 list_for_each_entry_safe(uc, tmp, &cdev->gstrings, list) {
1633 list_del(&uc->list);
1634 kfree(uc);
1635 }
1636 if (cdev->req) {
1637 kfree(cdev->req->buf);
1638 usb_ep_free_request(cdev->gadget->ep0, cdev->req);
1639 }
1640 device_remove_file(&cdev->gadget->dev, &dev_attr_suspended);
1641}
1642
1643static int composite_bind(struct usb_gadget *gadget,
1644 struct usb_gadget_driver *gdriver)
1645{
1646 struct usb_composite_dev *cdev;
1647 struct usb_composite_driver *composite = to_cdriver(gdriver);
1648 int status = -ENOMEM;
1649
1650 cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
1651 if (!cdev)
1652 return status;
1653
1654 spin_lock_init(&cdev->lock);
1655 cdev->gadget = gadget;
1656 set_gadget_data(gadget, cdev);
1657 INIT_LIST_HEAD(&cdev->configs);
1658 INIT_LIST_HEAD(&cdev->gstrings);
1659
1660 status = composite_dev_prepare(composite, cdev);
1661 if (status)
1662 goto fail;
1448 1663
1449 /* composite gadget needs to assign strings for whole device (like 1664 /* composite gadget needs to assign strings for whole device (like
1450 * serial number), register function drivers, potentially update 1665 * serial number), register function drivers, potentially update
@@ -1460,16 +1675,11 @@ static int composite_bind(struct usb_gadget *gadget,
1460 if (composite->needs_serial && !cdev->desc.iSerialNumber) 1675 if (composite->needs_serial && !cdev->desc.iSerialNumber)
1461 WARNING(cdev, "userspace failed to provide iSerialNumber\n"); 1676 WARNING(cdev, "userspace failed to provide iSerialNumber\n");
1462 1677
1463 /* finish up */
1464 status = device_create_file(&gadget->dev, &dev_attr_suspended);
1465 if (status)
1466 goto fail;
1467
1468 INFO(cdev, "%s ready\n", composite->name); 1678 INFO(cdev, "%s ready\n", composite->name);
1469 return 0; 1679 return 0;
1470 1680
1471fail: 1681fail:
1472 composite_unbind(gadget); 1682 __composite_unbind(gadget, false);
1473 return status; 1683 return status;
1474} 1684}
1475 1685
@@ -1518,10 +1728,10 @@ composite_resume(struct usb_gadget *gadget)
1518 f->resume(f); 1728 f->resume(f);
1519 } 1729 }
1520 1730
1521 maxpower = cdev->config->bMaxPower; 1731 maxpower = cdev->config->MaxPower;
1522 1732
1523 usb_gadget_vbus_draw(gadget, maxpower ? 1733 usb_gadget_vbus_draw(gadget, maxpower ?
1524 (2 * maxpower) : CONFIG_USB_GADGET_VBUS_DRAW); 1734 maxpower : CONFIG_USB_GADGET_VBUS_DRAW);
1525 } 1735 }
1526 1736
1527 cdev->suspended = 0; 1737 cdev->suspended = 0;
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
index 87d165028162..986fc511a2ed 100644
--- a/drivers/usb/gadget/dbgp.c
+++ b/drivers/usb/gadget/dbgp.c
@@ -13,9 +13,7 @@
13#include <linux/usb/ch9.h> 13#include <linux/usb/ch9.h>
14#include <linux/usb/gadget.h> 14#include <linux/usb/gadget.h>
15 15
16#ifdef CONFIG_USB_G_DBGP_SERIAL 16#include "u_serial.h"
17#include "u_serial.c"
18#endif
19 17
20#define DRIVER_VENDOR_ID 0x0525 /* NetChip */ 18#define DRIVER_VENDOR_ID 0x0525 /* NetChip */
21#define DRIVER_PRODUCT_ID 0xc0de /* undefined */ 19#define DRIVER_PRODUCT_ID 0xc0de /* undefined */
@@ -233,6 +231,10 @@ static void dbgp_unbind(struct usb_gadget *gadget)
233 gadget->ep0->driver_data = NULL; 231 gadget->ep0->driver_data = NULL;
234} 232}
235 233
234#ifdef CONFIG_USB_G_DBGP_SERIAL
235static unsigned char tty_line;
236#endif
237
236static int __init dbgp_configure_endpoints(struct usb_gadget *gadget) 238static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
237{ 239{
238 int stp; 240 int stp;
@@ -270,7 +272,7 @@ static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
270 dbgp.serial->in->desc = &i_desc; 272 dbgp.serial->in->desc = &i_desc;
271 dbgp.serial->out->desc = &o_desc; 273 dbgp.serial->out->desc = &o_desc;
272 274
273 if (gserial_setup(gadget, 1) < 0) { 275 if (gserial_alloc_line(&tty_line)) {
274 stp = 3; 276 stp = 3;
275 goto fail_3; 277 goto fail_3;
276 } 278 }
@@ -379,7 +381,7 @@ static int dbgp_setup(struct usb_gadget *gadget,
379#ifdef CONFIG_USB_G_DBGP_PRINTK 381#ifdef CONFIG_USB_G_DBGP_PRINTK
380 err = dbgp_enable_ep(); 382 err = dbgp_enable_ep();
381#else 383#else
382 err = gserial_connect(dbgp.serial, 0); 384 err = gserial_connect(dbgp.serial, tty_line);
383#endif 385#endif
384 if (err < 0) 386 if (err < 0)
385 goto fail; 387 goto fail;
@@ -422,7 +424,7 @@ static void __exit dbgp_exit(void)
422{ 424{
423 usb_gadget_unregister_driver(&dbgp_driver); 425 usb_gadget_unregister_driver(&dbgp_driver);
424#ifdef CONFIG_USB_G_DBGP_SERIAL 426#ifdef CONFIG_USB_G_DBGP_SERIAL
425 gserial_cleanup(); 427 gserial_free_line(tty_line);
426#endif 428#endif
427} 429}
428 430
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 549174466c21..1ae180baa597 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -16,7 +16,9 @@
16 16
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/module.h>
19#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/err.h>
20 22
21#include "u_serial.h" 23#include "u_serial.h"
22#include "gadget_chips.h" 24#include "gadget_chips.h"
@@ -283,7 +285,6 @@ static struct usb_string acm_string_defs[] = {
283 [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)", 285 [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)",
284 [ACM_DATA_IDX].s = "CDC ACM Data", 286 [ACM_DATA_IDX].s = "CDC ACM Data",
285 [ACM_IAD_IDX ].s = "CDC Serial", 287 [ACM_IAD_IDX ].s = "CDC Serial",
286 { /* ZEROES END LIST */ },
287}; 288};
288 289
289static struct usb_gadget_strings acm_string_table = { 290static struct usb_gadget_strings acm_string_table = {
@@ -605,9 +606,23 @@ acm_bind(struct usb_configuration *c, struct usb_function *f)
605{ 606{
606 struct usb_composite_dev *cdev = c->cdev; 607 struct usb_composite_dev *cdev = c->cdev;
607 struct f_acm *acm = func_to_acm(f); 608 struct f_acm *acm = func_to_acm(f);
609 struct usb_string *us;
608 int status; 610 int status;
609 struct usb_ep *ep; 611 struct usb_ep *ep;
610 612
613 /* REVISIT might want instance-specific strings to help
614 * distinguish instances ...
615 */
616
617 /* maybe allocate device-global string IDs, and patch descriptors */
618 us = usb_gstrings_attach(cdev, acm_strings,
619 ARRAY_SIZE(acm_string_defs));
620 if (IS_ERR(us))
621 return PTR_ERR(us);
622 acm_control_interface_desc.iInterface = us[ACM_CTRL_IDX].id;
623 acm_data_interface_desc.iInterface = us[ACM_DATA_IDX].id;
624 acm_iad_descriptor.iFunction = us[ACM_IAD_IDX].id;
625
611 /* allocate instance-specific interface IDs, and patch descriptors */ 626 /* allocate instance-specific interface IDs, and patch descriptors */
612 status = usb_interface_id(c, f); 627 status = usb_interface_id(c, f);
613 if (status < 0) 628 if (status < 0)
@@ -700,24 +715,42 @@ fail:
700 return status; 715 return status;
701} 716}
702 717
718static struct f_acm *acm_alloc_basic_func(void)
719{
720 struct f_acm *acm;
721
722 acm = kzalloc(sizeof(*acm), GFP_KERNEL);
723 if (!acm)
724 return NULL;
725
726 spin_lock_init(&acm->lock);
727
728 acm->port.connect = acm_connect;
729 acm->port.disconnect = acm_disconnect;
730 acm->port.send_break = acm_send_break;
731
732 acm->port.func.name = "acm";
733 /* descriptors are per-instance copies */
734 acm->port.func.bind = acm_bind;
735 acm->port.func.set_alt = acm_set_alt;
736 acm->port.func.setup = acm_setup;
737 acm->port.func.disable = acm_disable;
738
739 return acm;
740}
741
742#ifdef USB_FACM_INCLUDED
703static void 743static void
704acm_unbind(struct usb_configuration *c, struct usb_function *f) 744acm_old_unbind(struct usb_configuration *c, struct usb_function *f)
705{ 745{
706 struct f_acm *acm = func_to_acm(f); 746 struct f_acm *acm = func_to_acm(f);
707 747
708 acm_string_defs[0].id = 0;
709 usb_free_all_descriptors(f); 748 usb_free_all_descriptors(f);
710 gs_free_req(acm->notify, acm->notify_req); 749 if (acm->notify_req)
750 gs_free_req(acm->notify, acm->notify_req);
711 kfree(acm); 751 kfree(acm);
712} 752}
713 753
714/* Some controllers can't support CDC ACM ... */
715static inline bool can_support_cdc(struct usb_configuration *c)
716{
717 /* everything else is *probably* fine ... */
718 return true;
719}
720
721/** 754/**
722 * acm_bind_config - add a CDC ACM function to a configuration 755 * acm_bind_config - add a CDC ACM function to a configuration
723 * @c: the configuration to support the CDC ACM instance 756 * @c: the configuration to support the CDC ACM instance
@@ -726,58 +759,80 @@ static inline bool can_support_cdc(struct usb_configuration *c)
726 * 759 *
727 * Returns zero on success, else negative errno. 760 * Returns zero on success, else negative errno.
728 * 761 *
729 * Caller must have called @gserial_setup() with enough ports to
730 * handle all the ones it binds. Caller is also responsible
731 * for calling @gserial_cleanup() before module unload.
732 */ 762 */
733int acm_bind_config(struct usb_configuration *c, u8 port_num) 763int acm_bind_config(struct usb_configuration *c, u8 port_num)
734{ 764{
735 struct f_acm *acm; 765 struct f_acm *acm;
736 int status; 766 int status;
737 767
738 if (!can_support_cdc(c))
739 return -EINVAL;
740
741 /* REVISIT might want instance-specific strings to help
742 * distinguish instances ...
743 */
744
745 /* maybe allocate device-global string IDs, and patch descriptors */
746 if (acm_string_defs[0].id == 0) {
747 status = usb_string_ids_tab(c->cdev, acm_string_defs);
748 if (status < 0)
749 return status;
750 acm_control_interface_desc.iInterface =
751 acm_string_defs[ACM_CTRL_IDX].id;
752 acm_data_interface_desc.iInterface =
753 acm_string_defs[ACM_DATA_IDX].id;
754 acm_iad_descriptor.iFunction = acm_string_defs[ACM_IAD_IDX].id;
755 }
756
757 /* allocate and initialize one new instance */ 768 /* allocate and initialize one new instance */
758 acm = kzalloc(sizeof *acm, GFP_KERNEL); 769 acm = acm_alloc_basic_func();
759 if (!acm) 770 if (!acm)
760 return -ENOMEM; 771 return -ENOMEM;
761 772
762 spin_lock_init(&acm->lock);
763
764 acm->port_num = port_num; 773 acm->port_num = port_num;
765 774 acm->port.func.unbind = acm_old_unbind;
766 acm->port.connect = acm_connect;
767 acm->port.disconnect = acm_disconnect;
768 acm->port.send_break = acm_send_break;
769
770 acm->port.func.name = "acm";
771 acm->port.func.strings = acm_strings;
772 /* descriptors are per-instance copies */
773 acm->port.func.bind = acm_bind;
774 acm->port.func.unbind = acm_unbind;
775 acm->port.func.set_alt = acm_set_alt;
776 acm->port.func.setup = acm_setup;
777 acm->port.func.disable = acm_disable;
778 775
779 status = usb_add_function(c, &acm->port.func); 776 status = usb_add_function(c, &acm->port.func);
780 if (status) 777 if (status)
781 kfree(acm); 778 kfree(acm);
782 return status; 779 return status;
783} 780}
781
782#else
783
784static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
785{
786 struct f_acm *acm = func_to_acm(f);
787
788 acm_string_defs[0].id = 0;
789 usb_free_all_descriptors(f);
790 if (acm->notify_req)
791 gs_free_req(acm->notify, acm->notify_req);
792}
793
794static void acm_free_func(struct usb_function *f)
795{
796 struct f_acm *acm = func_to_acm(f);
797
798 kfree(acm);
799}
800
801static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
802{
803 struct f_serial_opts *opts;
804 struct f_acm *acm;
805
806 acm = acm_alloc_basic_func();
807 if (!acm)
808 return ERR_PTR(-ENOMEM);
809
810 opts = container_of(fi, struct f_serial_opts, func_inst);
811 acm->port_num = opts->port_num;
812 acm->port.func.unbind = acm_unbind;
813 acm->port.func.free_func = acm_free_func;
814
815 return &acm->port.func;
816}
817
818static void acm_free_instance(struct usb_function_instance *fi)
819{
820 struct f_serial_opts *opts;
821
822 opts = container_of(fi, struct f_serial_opts, func_inst);
823 kfree(opts);
824}
825
826static struct usb_function_instance *acm_alloc_instance(void)
827{
828 struct f_serial_opts *opts;
829
830 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
831 if (!opts)
832 return ERR_PTR(-ENOMEM);
833 opts->func_inst.free_func_inst = acm_free_instance;
834 return &opts->func_inst;
835}
836DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func);
837MODULE_LICENSE("GPL");
838#endif
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 4a6961c517f2..449186c9fd6c 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -1103,8 +1103,8 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1103 return 0; 1103 return 0;
1104 1104
1105 for (;;) { 1105 for (;;) {
1106 char *end, *eq, *comma;
1107 unsigned long value; 1106 unsigned long value;
1107 char *eq, *comma;
1108 1108
1109 /* Option limit */ 1109 /* Option limit */
1110 comma = strchr(opts, ','); 1110 comma = strchr(opts, ',');
@@ -1120,8 +1120,7 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1120 *eq = 0; 1120 *eq = 0;
1121 1121
1122 /* Parse value */ 1122 /* Parse value */
1123 value = simple_strtoul(eq + 1, &end, 0); 1123 if (kstrtoul(eq + 1, 0, &value)) {
1124 if (unlikely(*end != ',' && *end != 0)) {
1125 pr_err("%s: invalid value: %s\n", opts, eq + 1); 1124 pr_err("%s: invalid value: %s\n", opts, eq + 1);
1126 return -EINVAL; 1125 return -EINVAL;
1127 } 1126 }
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index bb39cb2bb3a3..4a3873a0f2d0 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -15,10 +15,11 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/module.h>
19#include <linux/err.h>
20#include <linux/usb/composite.h>
18 21
19#include "g_zero.h" 22#include "g_zero.h"
20#include "gadget_chips.h"
21
22 23
23/* 24/*
24 * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, 25 * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals,
@@ -44,9 +45,8 @@ static inline struct f_loopback *func_to_loop(struct usb_function *f)
44 return container_of(f, struct f_loopback, function); 45 return container_of(f, struct f_loopback, function);
45} 46}
46 47
47static unsigned qlen = 32; 48static unsigned qlen;
48module_param(qlen, uint, 0); 49static unsigned buflen;
49MODULE_PARM_DESC(qlenn, "depth of loopback queue");
50 50
51/*-------------------------------------------------------------------------*/ 51/*-------------------------------------------------------------------------*/
52 52
@@ -171,8 +171,7 @@ static struct usb_gadget_strings *loopback_strings[] = {
171 171
172/*-------------------------------------------------------------------------*/ 172/*-------------------------------------------------------------------------*/
173 173
174static int __init 174static int loopback_bind(struct usb_configuration *c, struct usb_function *f)
175loopback_bind(struct usb_configuration *c, struct usb_function *f)
176{ 175{
177 struct usb_composite_dev *cdev = c->cdev; 176 struct usb_composite_dev *cdev = c->cdev;
178 struct f_loopback *loop = func_to_loop(f); 177 struct f_loopback *loop = func_to_loop(f);
@@ -185,6 +184,12 @@ loopback_bind(struct usb_configuration *c, struct usb_function *f)
185 return id; 184 return id;
186 loopback_intf.bInterfaceNumber = id; 185 loopback_intf.bInterfaceNumber = id;
187 186
187 id = usb_string_id(cdev);
188 if (id < 0)
189 return id;
190 strings_loopback[0].id = id;
191 loopback_intf.iInterface = id;
192
188 /* allocate endpoints */ 193 /* allocate endpoints */
189 194
190 loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_source_desc); 195 loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_source_desc);
@@ -223,8 +228,7 @@ autoconf_fail:
223 return 0; 228 return 0;
224} 229}
225 230
226static void 231static void lb_free_func(struct usb_function *f)
227loopback_unbind(struct usb_configuration *c, struct usb_function *f)
228{ 232{
229 usb_free_all_descriptors(f); 233 usb_free_all_descriptors(f);
230 kfree(func_to_loop(f)); 234 kfree(func_to_loop(f));
@@ -366,63 +370,64 @@ static void loopback_disable(struct usb_function *f)
366 disable_loopback(loop); 370 disable_loopback(loop);
367} 371}
368 372
369/*-------------------------------------------------------------------------*/ 373static struct usb_function *loopback_alloc(struct usb_function_instance *fi)
370
371static int __init loopback_bind_config(struct usb_configuration *c)
372{ 374{
373 struct f_loopback *loop; 375 struct f_loopback *loop;
374 int status; 376 struct f_lb_opts *lb_opts;
375 377
376 loop = kzalloc(sizeof *loop, GFP_KERNEL); 378 loop = kzalloc(sizeof *loop, GFP_KERNEL);
377 if (!loop) 379 if (!loop)
378 return -ENOMEM; 380 return ERR_PTR(-ENOMEM);
381
382 lb_opts = container_of(fi, struct f_lb_opts, func_inst);
383 buflen = lb_opts->bulk_buflen;
384 qlen = lb_opts->qlen;
385 if (!qlen)
386 qlen = 32;
379 387
380 loop->function.name = "loopback"; 388 loop->function.name = "loopback";
381 loop->function.bind = loopback_bind; 389 loop->function.bind = loopback_bind;
382 loop->function.unbind = loopback_unbind;
383 loop->function.set_alt = loopback_set_alt; 390 loop->function.set_alt = loopback_set_alt;
384 loop->function.disable = loopback_disable; 391 loop->function.disable = loopback_disable;
392 loop->function.strings = loopback_strings;
385 393
386 status = usb_add_function(c, &loop->function); 394 loop->function.free_func = lb_free_func;
387 if (status)
388 kfree(loop);
389 return status;
390}
391 395
392static struct usb_configuration loopback_driver = { 396 return &loop->function;
393 .label = "loopback", 397}
394 .strings = loopback_strings,
395 .bConfigurationValue = 2,
396 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
397 /* .iConfiguration = DYNAMIC */
398};
399 398
400/** 399static void lb_free_instance(struct usb_function_instance *fi)
401 * loopback_add - add a loopback testing configuration to a device
402 * @cdev: the device to support the loopback configuration
403 */
404int __init loopback_add(struct usb_composite_dev *cdev, bool autoresume)
405{ 400{
406 int id; 401 struct f_lb_opts *lb_opts;
407 402
408 /* allocate string ID(s) */ 403 lb_opts = container_of(fi, struct f_lb_opts, func_inst);
409 id = usb_string_id(cdev); 404 kfree(lb_opts);
410 if (id < 0) 405}
411 return id;
412 strings_loopback[0].id = id;
413 406
414 loopback_intf.iInterface = id; 407static struct usb_function_instance *loopback_alloc_instance(void)
415 loopback_driver.iConfiguration = id; 408{
409 struct f_lb_opts *lb_opts;
416 410
417 /* support autoresume for remote wakeup testing */ 411 lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL);
418 if (autoresume) 412 if (!lb_opts)
419 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 413 return ERR_PTR(-ENOMEM);
414 lb_opts->func_inst.free_func_inst = lb_free_instance;
415 return &lb_opts->func_inst;
416}
417DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc);
420 418
421 /* support OTG systems */ 419int __init lb_modinit(void)
422 if (gadget_is_otg(cdev->gadget)) { 420{
423 loopback_driver.descriptors = otg_desc; 421 int ret;
424 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
425 }
426 422
427 return usb_add_config(cdev, &loopback_driver, loopback_bind_config); 423 ret = usb_function_register(&Loopbackusb_func);
424 if (ret)
425 return ret;
426 return ret;
428} 427}
428void __exit lb_modexit(void)
429{
430 usb_function_unregister(&Loopbackusb_func);
431}
432
433MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 5d027b3e1ef0..fc5c16ca5e0a 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -246,20 +246,6 @@ struct fsg_operations {
246 * set). 246 * set).
247 */ 247 */
248 int (*thread_exits)(struct fsg_common *common); 248 int (*thread_exits)(struct fsg_common *common);
249
250 /*
251 * Called prior to ejection. Negative return means error,
252 * zero means to continue with ejection, positive means not to
253 * eject.
254 */
255 int (*pre_eject)(struct fsg_common *common,
256 struct fsg_lun *lun, int num);
257 /*
258 * Called after ejection. Negative return means error, zero
259 * or positive is just a success.
260 */
261 int (*post_eject)(struct fsg_common *common,
262 struct fsg_lun *lun, int num);
263}; 249};
264 250
265/* Data shared by all the FSG instances. */ 251/* Data shared by all the FSG instances. */
@@ -1374,26 +1360,13 @@ static int do_start_stop(struct fsg_common *common)
1374 if (!loej) 1360 if (!loej)
1375 return 0; 1361 return 0;
1376 1362
1377 /* Simulate an unload/eject */
1378 if (common->ops && common->ops->pre_eject) {
1379 int r = common->ops->pre_eject(common, curlun,
1380 curlun - common->luns);
1381 if (unlikely(r < 0))
1382 return r;
1383 else if (r)
1384 return 0;
1385 }
1386
1387 up_read(&common->filesem); 1363 up_read(&common->filesem);
1388 down_write(&common->filesem); 1364 down_write(&common->filesem);
1389 fsg_lun_close(curlun); 1365 fsg_lun_close(curlun);
1390 up_write(&common->filesem); 1366 up_write(&common->filesem);
1391 down_read(&common->filesem); 1367 down_read(&common->filesem);
1392 1368
1393 return common->ops && common->ops->post_eject 1369 return 0;
1394 ? min(0, common->ops->post_eject(common, curlun,
1395 curlun - common->luns))
1396 : 0;
1397} 1370}
1398 1371
1399static int do_prevent_allow(struct fsg_common *common) 1372static int do_prevent_allow(struct fsg_common *common)
@@ -1718,7 +1691,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1718 int needs_medium, const char *name) 1691 int needs_medium, const char *name)
1719{ 1692{
1720 int i; 1693 int i;
1721 int lun = common->cmnd[1] >> 5; 1694 unsigned int lun = common->cmnd[1] >> 5;
1722 static const char dirletter[4] = {'u', 'o', 'i', 'n'}; 1695 static const char dirletter[4] = {'u', 'o', 'i', 'n'};
1723 char hdlen[20]; 1696 char hdlen[20];
1724 struct fsg_lun *curlun; 1697 struct fsg_lun *curlun;
@@ -1784,7 +1757,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1784 1757
1785 /* Check that the LUN values are consistent */ 1758 /* Check that the LUN values are consistent */
1786 if (common->lun != lun) 1759 if (common->lun != lun)
1787 DBG(common, "using LUN %d from CBW, not LUN %d from CDB\n", 1760 DBG(common, "using LUN %u from CBW, not LUN %u from CDB\n",
1788 common->lun, lun); 1761 common->lun, lun);
1789 1762
1790 /* Check the LUN */ 1763 /* Check the LUN */
@@ -1804,7 +1777,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,
1804 */ 1777 */
1805 if (common->cmnd[0] != INQUIRY && 1778 if (common->cmnd[0] != INQUIRY &&
1806 common->cmnd[0] != REQUEST_SENSE) { 1779 common->cmnd[0] != REQUEST_SENSE) {
1807 DBG(common, "unsupported LUN %d\n", common->lun); 1780 DBG(common, "unsupported LUN %u\n", common->lun);
1808 return -EINVAL; 1781 return -EINVAL;
1809 } 1782 }
1810 } 1783 }
@@ -2196,7 +2169,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2196 if (common->data_size == 0) 2169 if (common->data_size == 0)
2197 common->data_dir = DATA_DIR_NONE; 2170 common->data_dir = DATA_DIR_NONE;
2198 common->lun = cbw->Lun; 2171 common->lun = cbw->Lun;
2199 if (common->lun >= 0 && common->lun < common->nluns) 2172 if (common->lun < common->nluns)
2200 common->curlun = &common->luns[common->lun]; 2173 common->curlun = &common->luns[common->lun];
2201 else 2174 else
2202 common->curlun = NULL; 2175 common->curlun = NULL;
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c
index 6c8362f937be..5e7557e23ecc 100644
--- a/drivers/usb/gadget/f_ncm.c
+++ b/drivers/usb/gadget/f_ncm.c
@@ -56,8 +56,9 @@ struct f_ncm {
56 u8 notify_state; 56 u8 notify_state;
57 bool is_open; 57 bool is_open;
58 58
59 struct ndp_parser_opts *parser_opts; 59 const struct ndp_parser_opts *parser_opts;
60 bool is_crc; 60 bool is_crc;
61 u32 ndp_sign;
61 62
62 /* 63 /*
63 * for notification, it is accessed from both 64 * for notification, it is accessed from both
@@ -390,8 +391,8 @@ struct ndp_parser_opts {
390 .next_fp_index = 2, \ 391 .next_fp_index = 2, \
391 } 392 }
392 393
393static struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS; 394static const struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS;
394static struct ndp_parser_opts ndp32_opts = INIT_NDP32_OPTS; 395static const struct ndp_parser_opts ndp32_opts = INIT_NDP32_OPTS;
395 396
396static inline void put_ncm(__le16 **p, unsigned size, unsigned val) 397static inline void put_ncm(__le16 **p, unsigned size, unsigned val)
397{ 398{
@@ -732,8 +733,7 @@ static int ncm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
732 default: 733 default:
733 goto invalid; 734 goto invalid;
734 } 735 }
735 ncm->parser_opts->ndp_sign &= ~NCM_NDP_HDR_CRC_MASK; 736 ncm->ndp_sign = ncm->parser_opts->ndp_sign | ndp_hdr_crc;
736 ncm->parser_opts->ndp_sign |= ndp_hdr_crc;
737 value = 0; 737 value = 0;
738 break; 738 break;
739 } 739 }
@@ -875,7 +875,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
875 int ndp_align; 875 int ndp_align;
876 int ndp_pad; 876 int ndp_pad;
877 unsigned max_size = ncm->port.fixed_in_len; 877 unsigned max_size = ncm->port.fixed_in_len;
878 struct ndp_parser_opts *opts = ncm->parser_opts; 878 const struct ndp_parser_opts *opts = ncm->parser_opts;
879 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; 879 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
880 880
881 div = le16_to_cpu(ntb_parameters.wNdpInDivisor); 881 div = le16_to_cpu(ntb_parameters.wNdpInDivisor);
@@ -921,7 +921,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
921 tmp = (void *)tmp + ndp_pad; 921 tmp = (void *)tmp + ndp_pad;
922 922
923 /* NDP */ 923 /* NDP */
924 put_unaligned_le32(opts->ndp_sign, tmp); /* dwSignature */ 924 put_unaligned_le32(ncm->ndp_sign, tmp); /* dwSignature */
925 tmp += 2; 925 tmp += 2;
926 /* wLength */ 926 /* wLength */
927 put_unaligned_le16(ncb_len - opts->nth_size - pad, tmp++); 927 put_unaligned_le16(ncb_len - opts->nth_size - pad, tmp++);
@@ -965,7 +965,7 @@ static int ncm_unwrap_ntb(struct gether *port,
965 struct sk_buff *skb2; 965 struct sk_buff *skb2;
966 int ret = -EINVAL; 966 int ret = -EINVAL;
967 unsigned max_size = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); 967 unsigned max_size = le32_to_cpu(ntb_parameters.dwNtbOutMaxSize);
968 struct ndp_parser_opts *opts = ncm->parser_opts; 968 const struct ndp_parser_opts *opts = ncm->parser_opts;
969 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; 969 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
970 int dgram_counter; 970 int dgram_counter;
971 971
@@ -1002,7 +1002,7 @@ static int ncm_unwrap_ntb(struct gether *port,
1002 1002
1003 /* walk through NDP */ 1003 /* walk through NDP */
1004 tmp = ((void *)skb->data) + index; 1004 tmp = ((void *)skb->data) + index;
1005 if (get_unaligned_le32(tmp) != opts->ndp_sign) { 1005 if (get_unaligned_le32(tmp) != ncm->ndp_sign) {
1006 INFO(port->func.config->cdev, "Wrong NDP SIGN\n"); 1006 INFO(port->func.config->cdev, "Wrong NDP SIGN\n");
1007 goto err; 1007 goto err;
1008 } 1008 }
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index d8dd8782768c..36a004563b82 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -406,10 +406,6 @@ static inline bool can_support_obex(struct usb_configuration *c)
406 * Context: single threaded during gadget setup 406 * Context: single threaded during gadget setup
407 * 407 *
408 * Returns zero on success, else negative errno. 408 * Returns zero on success, else negative errno.
409 *
410 * Caller must have called @gserial_setup() with enough ports to
411 * handle all the ones it binds. Caller is also responsible
412 * for calling @gserial_cleanup() before module unload.
413 */ 409 */
414int __init obex_bind_config(struct usb_configuration *c, u8 port_num) 410int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
415{ 411{
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index 98fa7795df5f..da33cfb3031d 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -260,10 +260,6 @@ gser_unbind(struct usb_configuration *c, struct usb_function *f)
260 * Context: single threaded during gadget setup 260 * Context: single threaded during gadget setup
261 * 261 *
262 * Returns zero on success, else negative errno. 262 * Returns zero on success, else negative errno.
263 *
264 * Caller must have called @gserial_setup() with enough ports to
265 * handle all the ones it binds. Caller is also responsible
266 * for calling @gserial_cleanup() before module unload.
267 */ 263 */
268int __init gser_bind_config(struct usb_configuration *c, u8 port_num) 264int __init gser_bind_config(struct usb_configuration *c, u8 port_num)
269{ 265{
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 102d49beb9df..41adf3ef96c2 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -16,11 +16,12 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/usb/composite.h>
20#include <linux/err.h>
19 21
20#include "g_zero.h" 22#include "g_zero.h"
21#include "gadget_chips.h" 23#include "gadget_chips.h"
22 24
23
24/* 25/*
25 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral 26 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral
26 * controller drivers. 27 * controller drivers.
@@ -62,24 +63,11 @@ static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
62} 63}
63 64
64static unsigned pattern; 65static unsigned pattern;
65module_param(pattern, uint, S_IRUGO|S_IWUSR); 66static unsigned isoc_interval;
66MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63, 2 = none"); 67static unsigned isoc_maxpacket;
67
68static unsigned isoc_interval = 4;
69module_param(isoc_interval, uint, S_IRUGO|S_IWUSR);
70MODULE_PARM_DESC(isoc_interval, "1 - 16");
71
72static unsigned isoc_maxpacket = 1024;
73module_param(isoc_maxpacket, uint, S_IRUGO|S_IWUSR);
74MODULE_PARM_DESC(isoc_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)");
75
76static unsigned isoc_mult; 68static unsigned isoc_mult;
77module_param(isoc_mult, uint, S_IRUGO|S_IWUSR);
78MODULE_PARM_DESC(isoc_mult, "0 - 2 (hs/ss only)");
79
80static unsigned isoc_maxburst; 69static unsigned isoc_maxburst;
81module_param(isoc_maxburst, uint, S_IRUGO|S_IWUSR); 70static unsigned buflen;
82MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)");
83 71
84/*-------------------------------------------------------------------------*/ 72/*-------------------------------------------------------------------------*/
85 73
@@ -313,7 +301,57 @@ static struct usb_gadget_strings *sourcesink_strings[] = {
313 301
314/*-------------------------------------------------------------------------*/ 302/*-------------------------------------------------------------------------*/
315 303
316static int __init 304struct usb_request *alloc_ep_req(struct usb_ep *ep, int len)
305{
306 struct usb_request *req;
307
308 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
309 if (req) {
310 if (len)
311 req->length = len;
312 else
313 req->length = buflen;
314 req->buf = kmalloc(req->length, GFP_ATOMIC);
315 if (!req->buf) {
316 usb_ep_free_request(ep, req);
317 req = NULL;
318 }
319 }
320 return req;
321}
322
323void free_ep_req(struct usb_ep *ep, struct usb_request *req)
324{
325 kfree(req->buf);
326 usb_ep_free_request(ep, req);
327}
328
329static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
330{
331 int value;
332
333 if (ep->driver_data) {
334 value = usb_ep_disable(ep);
335 if (value < 0)
336 DBG(cdev, "disable %s --> %d\n",
337 ep->name, value);
338 ep->driver_data = NULL;
339 }
340}
341
342void disable_endpoints(struct usb_composite_dev *cdev,
343 struct usb_ep *in, struct usb_ep *out,
344 struct usb_ep *iso_in, struct usb_ep *iso_out)
345{
346 disable_ep(cdev, in);
347 disable_ep(cdev, out);
348 if (iso_in)
349 disable_ep(cdev, iso_in);
350 if (iso_out)
351 disable_ep(cdev, iso_out);
352}
353
354static int
317sourcesink_bind(struct usb_configuration *c, struct usb_function *f) 355sourcesink_bind(struct usb_configuration *c, struct usb_function *f)
318{ 356{
319 struct usb_composite_dev *cdev = c->cdev; 357 struct usb_composite_dev *cdev = c->cdev;
@@ -450,7 +488,7 @@ no_iso:
450} 488}
451 489
452static void 490static void
453sourcesink_unbind(struct usb_configuration *c, struct usb_function *f) 491sourcesink_free_func(struct usb_function *f)
454{ 492{
455 usb_free_all_descriptors(f); 493 usb_free_all_descriptors(f);
456 kfree(func_to_ss(f)); 494 kfree(func_to_ss(f));
@@ -531,8 +569,7 @@ static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
531 check_read_data(ss, req); 569 check_read_data(ss, req);
532 if (pattern != 2) 570 if (pattern != 2)
533 memset(req->buf, 0x55, req->length); 571 memset(req->buf, 0x55, req->length);
534 } else 572 }
535 reinit_write_data(ep, req);
536 break; 573 break;
537 574
538 /* this endpoint is normally active while we're configured */ 575 /* this endpoint is normally active while we're configured */
@@ -758,31 +795,10 @@ static void sourcesink_disable(struct usb_function *f)
758 795
759/*-------------------------------------------------------------------------*/ 796/*-------------------------------------------------------------------------*/
760 797
761static int __init sourcesink_bind_config(struct usb_configuration *c) 798static int sourcesink_setup(struct usb_function *f,
762{
763 struct f_sourcesink *ss;
764 int status;
765
766 ss = kzalloc(sizeof *ss, GFP_KERNEL);
767 if (!ss)
768 return -ENOMEM;
769
770 ss->function.name = "source/sink";
771 ss->function.bind = sourcesink_bind;
772 ss->function.unbind = sourcesink_unbind;
773 ss->function.set_alt = sourcesink_set_alt;
774 ss->function.get_alt = sourcesink_get_alt;
775 ss->function.disable = sourcesink_disable;
776
777 status = usb_add_function(c, &ss->function);
778 if (status)
779 kfree(ss);
780 return status;
781}
782
783static int sourcesink_setup(struct usb_configuration *c,
784 const struct usb_ctrlrequest *ctrl) 799 const struct usb_ctrlrequest *ctrl)
785{ 800{
801 struct usb_configuration *c = f->config;
786 struct usb_request *req = c->cdev->req; 802 struct usb_request *req = c->cdev->req;
787 int value = -EOPNOTSUPP; 803 int value = -EOPNOTSUPP;
788 u16 w_index = le16_to_cpu(ctrl->wIndex); 804 u16 w_index = le16_to_cpu(ctrl->wIndex);
@@ -851,42 +867,76 @@ unknown:
851 return value; 867 return value;
852} 868}
853 869
854static struct usb_configuration sourcesink_driver = { 870static struct usb_function *source_sink_alloc_func(
855 .label = "source/sink", 871 struct usb_function_instance *fi)
856 .strings = sourcesink_strings, 872{
857 .setup = sourcesink_setup, 873 struct f_sourcesink *ss;
858 .bConfigurationValue = 3, 874 struct f_ss_opts *ss_opts;
859 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
860 /* .iConfiguration = DYNAMIC */
861};
862 875
863/** 876 ss = kzalloc(sizeof(*ss), GFP_KERNEL);
864 * sourcesink_add - add a source/sink testing configuration to a device 877 if (!ss)
865 * @cdev: the device to support the configuration 878 return NULL;
866 */ 879
867int __init sourcesink_add(struct usb_composite_dev *cdev, bool autoresume) 880 ss_opts = container_of(fi, struct f_ss_opts, func_inst);
881 pattern = ss_opts->pattern;
882 isoc_interval = ss_opts->isoc_interval;
883 isoc_maxpacket = ss_opts->isoc_maxpacket;
884 isoc_mult = ss_opts->isoc_mult;
885 isoc_maxburst = ss_opts->isoc_maxburst;
886 buflen = ss_opts->bulk_buflen;
887
888 ss->function.name = "source/sink";
889 ss->function.bind = sourcesink_bind;
890 ss->function.set_alt = sourcesink_set_alt;
891 ss->function.get_alt = sourcesink_get_alt;
892 ss->function.disable = sourcesink_disable;
893 ss->function.setup = sourcesink_setup;
894 ss->function.strings = sourcesink_strings;
895
896 ss->function.free_func = sourcesink_free_func;
897
898 return &ss->function;
899}
900
901static void acm_free_instance(struct usb_function_instance *fi)
868{ 902{
869 int id; 903 struct f_ss_opts *ss_opts;
870 904
871 /* allocate string ID(s) */ 905 ss_opts = container_of(fi, struct f_ss_opts, func_inst);
872 id = usb_string_id(cdev); 906 kfree(ss_opts);
873 if (id < 0) 907}
874 return id;
875 strings_sourcesink[0].id = id;
876 908
877 source_sink_intf_alt0.iInterface = id; 909static struct usb_function_instance *source_sink_alloc_inst(void)
878 source_sink_intf_alt1.iInterface = id; 910{
879 sourcesink_driver.iConfiguration = id; 911 struct f_ss_opts *ss_opts;
880 912
881 /* support autoresume for remote wakeup testing */ 913 ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL);
882 if (autoresume) 914 if (!ss_opts)
883 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 915 return ERR_PTR(-ENOMEM);
916 ss_opts->func_inst.free_func_inst = acm_free_instance;
917 return &ss_opts->func_inst;
918}
919DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst,
920 source_sink_alloc_func);
884 921
885 /* support OTG systems */ 922static int __init sslb_modinit(void)
886 if (gadget_is_otg(cdev->gadget)) { 923{
887 sourcesink_driver.descriptors = otg_desc; 924 int ret;
888 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
889 }
890 925
891 return usb_add_config(cdev, &sourcesink_driver, sourcesink_bind_config); 926 ret = usb_function_register(&SourceSinkusb_func);
927 if (ret)
928 return ret;
929 ret = lb_modinit();
930 if (ret)
931 usb_function_unregister(&SourceSinkusb_func);
932 return ret;
933}
934static void __exit sslb_modexit(void)
935{
936 usb_function_unregister(&SourceSinkusb_func);
937 lb_modexit();
892} 938}
939module_init(sslb_modinit);
940module_exit(sslb_modexit);
941
942MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/f_uac2.c b/drivers/usb/gadget/f_uac2.c
index d7da258fa3f6..c7468b6c07b0 100644
--- a/drivers/usb/gadget/f_uac2.c
+++ b/drivers/usb/gadget/f_uac2.c
@@ -260,19 +260,14 @@ static int
260uac2_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 260uac2_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
261{ 261{
262 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream); 262 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream);
263 struct audio_dev *agdev = uac2_to_agdev(uac2);
264 struct uac2_rtd_params *prm; 263 struct uac2_rtd_params *prm;
265 unsigned long flags; 264 unsigned long flags;
266 struct usb_ep *ep;
267 int err = 0; 265 int err = 0;
268 266
269 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 267 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
270 ep = agdev->in_ep;
271 prm = &uac2->p_prm; 268 prm = &uac2->p_prm;
272 } else { 269 else
273 ep = agdev->out_ep;
274 prm = &uac2->c_prm; 270 prm = &uac2->c_prm;
275 }
276 271
277 spin_lock_irqsave(&prm->lock, flags); 272 spin_lock_irqsave(&prm->lock, flags);
278 273
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index ec50f18c8890..034477ce77c6 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -1894,7 +1894,7 @@ static int fsl_qe_stop(struct usb_gadget *gadget,
1894 struct usb_gadget_driver *driver); 1894 struct usb_gadget_driver *driver);
1895 1895
1896/* defined in usb_gadget.h */ 1896/* defined in usb_gadget.h */
1897static struct usb_gadget_ops qe_gadget_ops = { 1897static const struct usb_gadget_ops qe_gadget_ops = {
1898 .get_frame = qe_get_frame, 1898 .get_frame = qe_get_frame,
1899 .udc_start = fsl_qe_start, 1899 .udc_start = fsl_qe_start,
1900 .udc_stop = fsl_qe_stop, 1900 .udc_stop = fsl_qe_stop,
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index c19f7f13790b..38939561cff3 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1254,19 +1254,20 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
1254 return 0; 1254 return 0;
1255} 1255}
1256 1256
1257static int fsl_start(struct usb_gadget_driver *driver, 1257static int fsl_udc_start(struct usb_gadget *g,
1258 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1258 struct usb_gadget_driver *driver);
1259static int fsl_stop(struct usb_gadget_driver *driver); 1259static int fsl_udc_stop(struct usb_gadget *g,
1260 struct usb_gadget_driver *driver);
1260/* defined in gadget.h */ 1261/* defined in gadget.h */
1261static struct usb_gadget_ops fsl_gadget_ops = { 1262static const struct usb_gadget_ops fsl_gadget_ops = {
1262 .get_frame = fsl_get_frame, 1263 .get_frame = fsl_get_frame,
1263 .wakeup = fsl_wakeup, 1264 .wakeup = fsl_wakeup,
1264/* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */ 1265/* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */
1265 .vbus_session = fsl_vbus_session, 1266 .vbus_session = fsl_vbus_session,
1266 .vbus_draw = fsl_vbus_draw, 1267 .vbus_draw = fsl_vbus_draw,
1267 .pullup = fsl_pullup, 1268 .pullup = fsl_pullup,
1268 .start = fsl_start, 1269 .udc_start = fsl_udc_start,
1269 .stop = fsl_stop, 1270 .udc_stop = fsl_udc_stop,
1270}; 1271};
1271 1272
1272/* Set protocol stall on ep0, protocol stall will automatically be cleared 1273/* Set protocol stall on ep0, protocol stall will automatically be cleared
@@ -1950,22 +1951,12 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
1950 * Hook to gadget drivers 1951 * Hook to gadget drivers
1951 * Called by initialization code of gadget drivers 1952 * Called by initialization code of gadget drivers
1952*----------------------------------------------------------------*/ 1953*----------------------------------------------------------------*/
1953static int fsl_start(struct usb_gadget_driver *driver, 1954static int fsl_udc_start(struct usb_gadget *g,
1954 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1955 struct usb_gadget_driver *driver)
1955{ 1956{
1956 int retval = -ENODEV; 1957 int retval = 0;
1957 unsigned long flags = 0; 1958 unsigned long flags = 0;
1958 1959
1959 if (!udc_controller)
1960 return -ENODEV;
1961
1962 if (!driver || driver->max_speed < USB_SPEED_FULL
1963 || !bind || !driver->disconnect || !driver->setup)
1964 return -EINVAL;
1965
1966 if (udc_controller->driver)
1967 return -EBUSY;
1968
1969 /* lock is needed but whether should use this lock or another */ 1960 /* lock is needed but whether should use this lock or another */
1970 spin_lock_irqsave(&udc_controller->lock, flags); 1961 spin_lock_irqsave(&udc_controller->lock, flags);
1971 1962
@@ -1975,15 +1966,6 @@ static int fsl_start(struct usb_gadget_driver *driver,
1975 udc_controller->gadget.dev.driver = &driver->driver; 1966 udc_controller->gadget.dev.driver = &driver->driver;
1976 spin_unlock_irqrestore(&udc_controller->lock, flags); 1967 spin_unlock_irqrestore(&udc_controller->lock, flags);
1977 1968
1978 /* bind udc driver to gadget driver */
1979 retval = bind(&udc_controller->gadget, driver);
1980 if (retval) {
1981 VDBG("bind to %s --> %d", driver->driver.name, retval);
1982 udc_controller->gadget.dev.driver = NULL;
1983 udc_controller->driver = NULL;
1984 goto out;
1985 }
1986
1987 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) { 1969 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
1988 /* Suspend the controller until OTG enable it */ 1970 /* Suspend the controller until OTG enable it */
1989 udc_controller->stopped = 1; 1971 udc_controller->stopped = 1;
@@ -2009,28 +1991,17 @@ static int fsl_start(struct usb_gadget_driver *driver,
2009 udc_controller->ep0_state = WAIT_FOR_SETUP; 1991 udc_controller->ep0_state = WAIT_FOR_SETUP;
2010 udc_controller->ep0_dir = 0; 1992 udc_controller->ep0_dir = 0;
2011 } 1993 }
2012 printk(KERN_INFO "%s: bind to driver %s\n",
2013 udc_controller->gadget.name, driver->driver.name);
2014 1994
2015out:
2016 if (retval)
2017 printk(KERN_WARNING "gadget driver register failed %d\n",
2018 retval);
2019 return retval; 1995 return retval;
2020} 1996}
2021 1997
2022/* Disconnect from gadget driver */ 1998/* Disconnect from gadget driver */
2023static int fsl_stop(struct usb_gadget_driver *driver) 1999static int fsl_udc_stop(struct usb_gadget *g,
2000 struct usb_gadget_driver *driver)
2024{ 2001{
2025 struct fsl_ep *loop_ep; 2002 struct fsl_ep *loop_ep;
2026 unsigned long flags; 2003 unsigned long flags;
2027 2004
2028 if (!udc_controller)
2029 return -ENODEV;
2030
2031 if (!driver || driver != udc_controller->driver || !driver->unbind)
2032 return -EINVAL;
2033
2034 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) 2005 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
2035 otg_set_peripheral(udc_controller->transceiver->otg, NULL); 2006 otg_set_peripheral(udc_controller->transceiver->otg, NULL);
2036 2007
@@ -2051,16 +2022,9 @@ static int fsl_stop(struct usb_gadget_driver *driver)
2051 nuke(loop_ep, -ESHUTDOWN); 2022 nuke(loop_ep, -ESHUTDOWN);
2052 spin_unlock_irqrestore(&udc_controller->lock, flags); 2023 spin_unlock_irqrestore(&udc_controller->lock, flags);
2053 2024
2054 /* report disconnect; the controller is already quiesced */
2055 driver->disconnect(&udc_controller->gadget);
2056
2057 /* unbind gadget and unhook driver. */
2058 driver->unbind(&udc_controller->gadget);
2059 udc_controller->gadget.dev.driver = NULL; 2025 udc_controller->gadget.dev.driver = NULL;
2060 udc_controller->driver = NULL; 2026 udc_controller->driver = NULL;
2061 2027
2062 printk(KERN_WARNING "unregistered gadget driver '%s'\n",
2063 driver->driver.name);
2064 return 0; 2028 return 0;
2065} 2029}
2066 2030
diff --git a/drivers/usb/gadget/functions.c b/drivers/usb/gadget/functions.c
new file mode 100644
index 000000000000..b13f839e7368
--- /dev/null
+++ b/drivers/usb/gadget/functions.c
@@ -0,0 +1,116 @@
1#include <linux/kernel.h>
2#include <linux/slab.h>
3#include <linux/module.h>
4#include <linux/err.h>
5
6#include <linux/usb/composite.h>
7
8static LIST_HEAD(func_list);
9static DEFINE_MUTEX(func_lock);
10
11static struct usb_function_instance *try_get_usb_function_instance(const char *name)
12{
13 struct usb_function_driver *fd;
14 struct usb_function_instance *fi;
15
16 fi = ERR_PTR(-ENOENT);
17 mutex_lock(&func_lock);
18 list_for_each_entry(fd, &func_list, list) {
19
20 if (strcmp(name, fd->name))
21 continue;
22
23 if (!try_module_get(fd->mod)) {
24 fi = ERR_PTR(-EBUSY);
25 break;
26 }
27 fi = fd->alloc_inst();
28 if (IS_ERR(fi))
29 module_put(fd->mod);
30 else
31 fi->fd = fd;
32 break;
33 }
34 mutex_unlock(&func_lock);
35 return fi;
36}
37
38struct usb_function_instance *usb_get_function_instance(const char *name)
39{
40 struct usb_function_instance *fi;
41 int ret;
42
43 fi = try_get_usb_function_instance(name);
44 if (!IS_ERR(fi))
45 return fi;
46 ret = PTR_ERR(fi);
47 if (ret != -ENOENT)
48 return fi;
49 ret = request_module("usbfunc:%s", name);
50 if (ret < 0)
51 return ERR_PTR(ret);
52 return try_get_usb_function_instance(name);
53}
54EXPORT_SYMBOL_GPL(usb_get_function_instance);
55
56struct usb_function *usb_get_function(struct usb_function_instance *fi)
57{
58 struct usb_function *f;
59
60 f = fi->fd->alloc_func(fi);
61 if (IS_ERR(f))
62 return f;
63 f->fi = fi;
64 return f;
65}
66EXPORT_SYMBOL_GPL(usb_get_function);
67
68void usb_put_function_instance(struct usb_function_instance *fi)
69{
70 struct module *mod;
71
72 if (!fi)
73 return;
74
75 mod = fi->fd->mod;
76 fi->free_func_inst(fi);
77 module_put(mod);
78}
79EXPORT_SYMBOL_GPL(usb_put_function_instance);
80
81void usb_put_function(struct usb_function *f)
82{
83 if (!f)
84 return;
85
86 f->free_func(f);
87}
88EXPORT_SYMBOL_GPL(usb_put_function);
89
90int usb_function_register(struct usb_function_driver *newf)
91{
92 struct usb_function_driver *fd;
93 int ret;
94
95 ret = -EEXIST;
96
97 mutex_lock(&func_lock);
98 list_for_each_entry(fd, &func_list, list) {
99 if (!strcmp(fd->name, newf->name))
100 goto out;
101 }
102 ret = 0;
103 list_add_tail(&newf->list, &func_list);
104out:
105 mutex_unlock(&func_lock);
106 return ret;
107}
108EXPORT_SYMBOL_GPL(usb_function_register);
109
110void usb_function_unregister(struct usb_function_driver *fd)
111{
112 mutex_lock(&func_lock);
113 list_del(&fd->list);
114 mutex_unlock(&func_lock);
115}
116EXPORT_SYMBOL_GPL(usb_function_unregister);
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index 72cd5e6719db..9fafb00d3c7a 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -1308,65 +1308,28 @@ static void init_controller(struct fusb300 *fusb300)
1308 iowrite32(0xcfffff9f, fusb300->reg + FUSB300_OFFSET_IGER1); 1308 iowrite32(0xcfffff9f, fusb300->reg + FUSB300_OFFSET_IGER1);
1309} 1309}
1310/*------------------------------------------------------------------------*/ 1310/*------------------------------------------------------------------------*/
1311static struct fusb300 *the_controller; 1311static int fusb300_udc_start(struct usb_gadget *g,
1312 1312 struct usb_gadget_driver *driver)
1313static int fusb300_udc_start(struct usb_gadget_driver *driver,
1314 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1315{ 1313{
1316 struct fusb300 *fusb300 = the_controller; 1314 struct fusb300 *fusb300 = to_fusb300(g);
1317 int retval;
1318
1319 if (!driver
1320 || driver->max_speed < USB_SPEED_FULL
1321 || !bind
1322 || !driver->setup)
1323 return -EINVAL;
1324
1325 if (!fusb300)
1326 return -ENODEV;
1327
1328 if (fusb300->driver)
1329 return -EBUSY;
1330 1315
1331 /* hook up the driver */ 1316 /* hook up the driver */
1332 driver->driver.bus = NULL; 1317 driver->driver.bus = NULL;
1333 fusb300->driver = driver; 1318 fusb300->driver = driver;
1334 fusb300->gadget.dev.driver = &driver->driver; 1319 fusb300->gadget.dev.driver = &driver->driver;
1335 1320
1336 retval = device_add(&fusb300->gadget.dev);
1337 if (retval) {
1338 pr_err("device_add error (%d)\n", retval);
1339 goto error;
1340 }
1341
1342 retval = bind(&fusb300->gadget, driver);
1343 if (retval) {
1344 pr_err("bind to driver error (%d)\n", retval);
1345 device_del(&fusb300->gadget.dev);
1346 goto error;
1347 }
1348
1349 return 0; 1321 return 0;
1350
1351error:
1352 fusb300->driver = NULL;
1353 fusb300->gadget.dev.driver = NULL;
1354
1355 return retval;
1356} 1322}
1357 1323
1358static int fusb300_udc_stop(struct usb_gadget_driver *driver) 1324static int fusb300_udc_stop(struct usb_gadget *g,
1325 struct usb_gadget_driver *driver)
1359{ 1326{
1360 struct fusb300 *fusb300 = the_controller; 1327 struct fusb300 *fusb300 = to_fusb300(g);
1361
1362 if (driver != fusb300->driver || !driver->unbind)
1363 return -EINVAL;
1364 1328
1365 driver->unbind(&fusb300->gadget); 1329 driver->unbind(&fusb300->gadget);
1366 fusb300->gadget.dev.driver = NULL; 1330 fusb300->gadget.dev.driver = NULL;
1367 1331
1368 init_controller(fusb300); 1332 init_controller(fusb300);
1369 device_del(&fusb300->gadget.dev);
1370 fusb300->driver = NULL; 1333 fusb300->driver = NULL;
1371 1334
1372 return 0; 1335 return 0;
@@ -1378,10 +1341,10 @@ static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
1378 return 0; 1341 return 0;
1379} 1342}
1380 1343
1381static struct usb_gadget_ops fusb300_gadget_ops = { 1344static const struct usb_gadget_ops fusb300_gadget_ops = {
1382 .pullup = fusb300_udc_pullup, 1345 .pullup = fusb300_udc_pullup,
1383 .start = fusb300_udc_start, 1346 .udc_start = fusb300_udc_start,
1384 .stop = fusb300_udc_stop, 1347 .udc_stop = fusb300_udc_stop,
1385}; 1348};
1386 1349
1387static int __exit fusb300_remove(struct platform_device *pdev) 1350static int __exit fusb300_remove(struct platform_device *pdev)
@@ -1505,8 +1468,6 @@ static int __init fusb300_probe(struct platform_device *pdev)
1505 fusb300->gadget.ep0 = &fusb300->ep[0]->ep; 1468 fusb300->gadget.ep0 = &fusb300->ep[0]->ep;
1506 INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list); 1469 INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list);
1507 1470
1508 the_controller = fusb300;
1509
1510 fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep, 1471 fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep,
1511 GFP_KERNEL); 1472 GFP_KERNEL);
1512 if (fusb300->ep0_req == NULL) 1473 if (fusb300->ep0_req == NULL)
@@ -1517,9 +1478,19 @@ static int __init fusb300_probe(struct platform_device *pdev)
1517 if (ret) 1478 if (ret)
1518 goto err_add_udc; 1479 goto err_add_udc;
1519 1480
1481 ret = device_add(&fusb300->gadget.dev);
1482 if (ret) {
1483 pr_err("device_add error (%d)\n", ret);
1484 goto err_add_device;
1485 }
1486
1520 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1487 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1521 1488
1522 return 0; 1489 return 0;
1490
1491err_add_device:
1492 usb_del_gadget_udc(&fusb300->gadget);
1493
1523err_add_udc: 1494err_add_udc:
1524 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); 1495 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
1525 1496
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h
index 542cd83cc806..6ba444ae8dd5 100644
--- a/drivers/usb/gadget/fusb300_udc.h
+++ b/drivers/usb/gadget/fusb300_udc.h
@@ -673,4 +673,6 @@ struct fusb300 {
673 u8 reenum; /* if re-enumeration */ 673 u8 reenum; /* if re-enumeration */
674}; 674};
675 675
676#define to_fusb300(g) (container_of((g), struct fusb300, gadget))
677
676#endif 678#endif
diff --git a/drivers/usb/gadget/g_zero.h b/drivers/usb/gadget/g_zero.h
index 71ca193358b8..ef3e8515272b 100644
--- a/drivers/usb/gadget/g_zero.h
+++ b/drivers/usb/gadget/g_zero.h
@@ -6,11 +6,34 @@
6#ifndef __G_ZERO_H 6#ifndef __G_ZERO_H
7#define __G_ZERO_H 7#define __G_ZERO_H
8 8
9#include <linux/usb/composite.h> 9struct usb_zero_options {
10 unsigned pattern;
11 unsigned isoc_interval;
12 unsigned isoc_maxpacket;
13 unsigned isoc_mult;
14 unsigned isoc_maxburst;
15 unsigned bulk_buflen;
16 unsigned qlen;
17};
10 18
11/* global state */ 19struct f_ss_opts {
12extern unsigned buflen; 20 struct usb_function_instance func_inst;
13extern const struct usb_descriptor_header *otg_desc[]; 21 unsigned pattern;
22 unsigned isoc_interval;
23 unsigned isoc_maxpacket;
24 unsigned isoc_mult;
25 unsigned isoc_maxburst;
26 unsigned bulk_buflen;
27};
28
29struct f_lb_opts {
30 struct usb_function_instance func_inst;
31 unsigned bulk_buflen;
32 unsigned qlen;
33};
34
35void lb_modexit(void);
36int lb_modinit(void);
14 37
15/* common utilities */ 38/* common utilities */
16struct usb_request *alloc_ep_req(struct usb_ep *ep, int len); 39struct usb_request *alloc_ep_req(struct usb_ep *ep, int len);
@@ -19,8 +42,4 @@ void disable_endpoints(struct usb_composite_dev *cdev,
19 struct usb_ep *in, struct usb_ep *out, 42 struct usb_ep *in, struct usb_ep *out,
20 struct usb_ep *iso_in, struct usb_ep *iso_out); 43 struct usb_ep *iso_in, struct usb_ep *iso_out);
21 44
22/* configuration-specific linkup */
23int sourcesink_add(struct usb_composite_dev *cdev, bool autoresume);
24int loopback_add(struct usb_composite_dev *cdev, bool autoresume);
25
26#endif /* __G_ZERO_H */ 45#endif /* __G_ZERO_H */
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 881aab86ae99..e879e2c9f461 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -125,7 +125,7 @@ static struct usb_configuration midi_config = {
125 .bConfigurationValue = 1, 125 .bConfigurationValue = 1,
126 /* .iConfiguration = DYNAMIC */ 126 /* .iConfiguration = DYNAMIC */
127 .bmAttributes = USB_CONFIG_ATT_ONE, 127 .bmAttributes = USB_CONFIG_ATT_ONE,
128 .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, 128 .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW,
129}; 129};
130 130
131static int __init midi_bind_config(struct usb_configuration *c) 131static int __init midi_bind_config(struct usb_configuration *c)
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 51037cb78604..85742d4c67df 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -993,14 +993,15 @@ static int goku_get_frame(struct usb_gadget *_gadget)
993 return -EOPNOTSUPP; 993 return -EOPNOTSUPP;
994} 994}
995 995
996static int goku_start(struct usb_gadget_driver *driver, 996static int goku_udc_start(struct usb_gadget *g,
997 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 997 struct usb_gadget_driver *driver);
998static int goku_stop(struct usb_gadget_driver *driver); 998static int goku_udc_stop(struct usb_gadget *g,
999 struct usb_gadget_driver *driver);
999 1000
1000static const struct usb_gadget_ops goku_ops = { 1001static const struct usb_gadget_ops goku_ops = {
1001 .get_frame = goku_get_frame, 1002 .get_frame = goku_get_frame,
1002 .start = goku_start, 1003 .udc_start = goku_udc_start,
1003 .stop = goku_stop, 1004 .udc_stop = goku_udc_stop,
1004 // no remote wakeup 1005 // no remote wakeup
1005 // not selfpowered 1006 // not selfpowered
1006}; 1007};
@@ -1339,50 +1340,28 @@ static void udc_enable(struct goku_udc *dev)
1339 * - one function driver, initted second 1340 * - one function driver, initted second
1340 */ 1341 */
1341 1342
1342static struct goku_udc *the_controller;
1343
1344/* when a driver is successfully registered, it will receive 1343/* when a driver is successfully registered, it will receive
1345 * control requests including set_configuration(), which enables 1344 * control requests including set_configuration(), which enables
1346 * non-control requests. then usb traffic follows until a 1345 * non-control requests. then usb traffic follows until a
1347 * disconnect is reported. then a host may connect again, or 1346 * disconnect is reported. then a host may connect again, or
1348 * the driver might get unbound. 1347 * the driver might get unbound.
1349 */ 1348 */
1350static int goku_start(struct usb_gadget_driver *driver, 1349static int goku_udc_start(struct usb_gadget *g,
1351 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1350 struct usb_gadget_driver *driver)
1352{ 1351{
1353 struct goku_udc *dev = the_controller; 1352 struct goku_udc *dev = to_goku_udc(g);
1354 int retval;
1355
1356 if (!driver
1357 || driver->max_speed < USB_SPEED_FULL
1358 || !bind
1359 || !driver->disconnect
1360 || !driver->setup)
1361 return -EINVAL;
1362 if (!dev)
1363 return -ENODEV;
1364 if (dev->driver)
1365 return -EBUSY;
1366 1353
1367 /* hook up the driver */ 1354 /* hook up the driver */
1368 driver->driver.bus = NULL; 1355 driver->driver.bus = NULL;
1369 dev->driver = driver; 1356 dev->driver = driver;
1370 dev->gadget.dev.driver = &driver->driver; 1357 dev->gadget.dev.driver = &driver->driver;
1371 retval = bind(&dev->gadget, driver);
1372 if (retval) {
1373 DBG(dev, "bind to driver %s --> error %d\n",
1374 driver->driver.name, retval);
1375 dev->driver = NULL;
1376 dev->gadget.dev.driver = NULL;
1377 return retval;
1378 }
1379 1358
1380 /* then enable host detection and ep0; and we're ready 1359 /*
1360 * then enable host detection and ep0; and we're ready
1381 * for set_configuration as well as eventual disconnect. 1361 * for set_configuration as well as eventual disconnect.
1382 */ 1362 */
1383 udc_enable(dev); 1363 udc_enable(dev);
1384 1364
1385 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name);
1386 return 0; 1365 return 0;
1387} 1366}
1388 1367
@@ -1400,35 +1379,23 @@ stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
1400 udc_reset (dev); 1379 udc_reset (dev);
1401 for (i = 0; i < 4; i++) 1380 for (i = 0; i < 4; i++)
1402 nuke(&dev->ep [i], -ESHUTDOWN); 1381 nuke(&dev->ep [i], -ESHUTDOWN);
1403 if (driver) {
1404 spin_unlock(&dev->lock);
1405 driver->disconnect(&dev->gadget);
1406 spin_lock(&dev->lock);
1407 }
1408 1382
1409 if (dev->driver) 1383 if (dev->driver)
1410 udc_enable(dev); 1384 udc_enable(dev);
1411} 1385}
1412 1386
1413static int goku_stop(struct usb_gadget_driver *driver) 1387static int goku_udc_stop(struct usb_gadget *g,
1388 struct usb_gadget_driver *driver)
1414{ 1389{
1415 struct goku_udc *dev = the_controller; 1390 struct goku_udc *dev = to_goku_udc(g);
1416 unsigned long flags; 1391 unsigned long flags;
1417 1392
1418 if (!dev)
1419 return -ENODEV;
1420 if (!driver || driver != dev->driver || !driver->unbind)
1421 return -EINVAL;
1422
1423 spin_lock_irqsave(&dev->lock, flags); 1393 spin_lock_irqsave(&dev->lock, flags);
1424 dev->driver = NULL; 1394 dev->driver = NULL;
1425 stop_activity(dev, driver); 1395 stop_activity(dev, driver);
1426 spin_unlock_irqrestore(&dev->lock, flags); 1396 spin_unlock_irqrestore(&dev->lock, flags);
1427
1428 driver->unbind(&dev->gadget);
1429 dev->gadget.dev.driver = NULL; 1397 dev->gadget.dev.driver = NULL;
1430 1398
1431 DBG(dev, "unregistered driver '%s'\n", driver->driver.name);
1432 return 0; 1399 return 0;
1433} 1400}
1434 1401
@@ -1754,7 +1721,6 @@ static void goku_remove(struct pci_dev *pdev)
1754 1721
1755 pci_set_drvdata(pdev, NULL); 1722 pci_set_drvdata(pdev, NULL);
1756 dev->regs = NULL; 1723 dev->regs = NULL;
1757 the_controller = NULL;
1758 1724
1759 INFO(dev, "unbind\n"); 1725 INFO(dev, "unbind\n");
1760} 1726}
@@ -1770,13 +1736,6 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1770 void __iomem *base = NULL; 1736 void __iomem *base = NULL;
1771 int retval; 1737 int retval;
1772 1738
1773 /* if you want to support more than one controller in a system,
1774 * usb_gadget_driver_{register,unregister}() must change.
1775 */
1776 if (the_controller) {
1777 pr_warning("ignoring %s\n", pci_name(pdev));
1778 return -EBUSY;
1779 }
1780 if (!pdev->irq) { 1739 if (!pdev->irq) {
1781 printk(KERN_ERR "Check PCI %s IRQ setup!\n", pci_name(pdev)); 1740 printk(KERN_ERR "Check PCI %s IRQ setup!\n", pci_name(pdev));
1782 retval = -ENODEV; 1741 retval = -ENODEV;
@@ -1851,7 +1810,6 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1851 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev); 1810 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev);
1852#endif 1811#endif
1853 1812
1854 the_controller = dev;
1855 retval = device_register(&dev->gadget.dev); 1813 retval = device_register(&dev->gadget.dev);
1856 if (retval) { 1814 if (retval) {
1857 put_device(&dev->gadget.dev); 1815 put_device(&dev->gadget.dev);
diff --git a/drivers/usb/gadget/goku_udc.h b/drivers/usb/gadget/goku_udc.h
index 85cdce0d1901..b4470d2b1d86 100644
--- a/drivers/usb/gadget/goku_udc.h
+++ b/drivers/usb/gadget/goku_udc.h
@@ -261,6 +261,7 @@ struct goku_udc {
261 /* statistics... */ 261 /* statistics... */
262 unsigned long irqs; 262 unsigned long irqs;
263}; 263};
264#define to_goku_udc(g) (container_of((g), struct goku_udc, gadget))
264 265
265/*-------------------------------------------------------------------------*/ 266/*-------------------------------------------------------------------------*/
266 267
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index b6401f1b56ce..34a0cb9382dc 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1463,42 +1463,16 @@ static struct usb_ep_ops m66592_ep_ops = {
1463}; 1463};
1464 1464
1465/*-------------------------------------------------------------------------*/ 1465/*-------------------------------------------------------------------------*/
1466static struct m66592 *the_controller; 1466static int m66592_udc_start(struct usb_gadget *g,
1467 1467 struct usb_gadget_driver *driver)
1468static int m66592_start(struct usb_gadget_driver *driver,
1469 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
1470{ 1468{
1471 struct m66592 *m66592 = the_controller; 1469 struct m66592 *m66592 = to_m66592(g);
1472 int retval;
1473
1474 if (!driver
1475 || driver->max_speed < USB_SPEED_HIGH
1476 || !bind
1477 || !driver->setup)
1478 return -EINVAL;
1479 if (!m66592)
1480 return -ENODEV;
1481 if (m66592->driver)
1482 return -EBUSY;
1483 1470
1484 /* hook up the driver */ 1471 /* hook up the driver */
1485 driver->driver.bus = NULL; 1472 driver->driver.bus = NULL;
1486 m66592->driver = driver; 1473 m66592->driver = driver;
1487 m66592->gadget.dev.driver = &driver->driver; 1474 m66592->gadget.dev.driver = &driver->driver;
1488 1475
1489 retval = device_add(&m66592->gadget.dev);
1490 if (retval) {
1491 pr_err("device_add error (%d)\n", retval);
1492 goto error;
1493 }
1494
1495 retval = bind(&m66592->gadget, driver);
1496 if (retval) {
1497 pr_err("bind to driver error (%d)\n", retval);
1498 device_del(&m66592->gadget.dev);
1499 goto error;
1500 }
1501
1502 m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1476 m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1503 if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) { 1477 if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) {
1504 m66592_start_xclock(m66592); 1478 m66592_start_xclock(m66592);
@@ -1510,26 +1484,12 @@ static int m66592_start(struct usb_gadget_driver *driver,
1510 } 1484 }
1511 1485
1512 return 0; 1486 return 0;
1513
1514error:
1515 m66592->driver = NULL;
1516 m66592->gadget.dev.driver = NULL;
1517
1518 return retval;
1519} 1487}
1520 1488
1521static int m66592_stop(struct usb_gadget_driver *driver) 1489static int m66592_udc_stop(struct usb_gadget *g,
1490 struct usb_gadget_driver *driver)
1522{ 1491{
1523 struct m66592 *m66592 = the_controller; 1492 struct m66592 *m66592 = to_m66592(g);
1524 unsigned long flags;
1525
1526 if (driver != m66592->driver || !driver->unbind)
1527 return -EINVAL;
1528
1529 spin_lock_irqsave(&m66592->lock, flags);
1530 if (m66592->gadget.speed != USB_SPEED_UNKNOWN)
1531 m66592_usb_disconnect(m66592);
1532 spin_unlock_irqrestore(&m66592->lock, flags);
1533 1493
1534 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1494 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1535 1495
@@ -1539,8 +1499,8 @@ static int m66592_stop(struct usb_gadget_driver *driver)
1539 init_controller(m66592); 1499 init_controller(m66592);
1540 disable_controller(m66592); 1500 disable_controller(m66592);
1541 1501
1542 device_del(&m66592->gadget.dev);
1543 m66592->driver = NULL; 1502 m66592->driver = NULL;
1503
1544 return 0; 1504 return 0;
1545} 1505}
1546 1506
@@ -1566,10 +1526,10 @@ static int m66592_pullup(struct usb_gadget *gadget, int is_on)
1566 return 0; 1526 return 0;
1567} 1527}
1568 1528
1569static struct usb_gadget_ops m66592_gadget_ops = { 1529static const struct usb_gadget_ops m66592_gadget_ops = {
1570 .get_frame = m66592_get_frame, 1530 .get_frame = m66592_get_frame,
1571 .start = m66592_start, 1531 .udc_start = m66592_udc_start,
1572 .stop = m66592_stop, 1532 .udc_stop = m66592_udc_stop,
1573 .pullup = m66592_pullup, 1533 .pullup = m66592_pullup,
1574}; 1534};
1575 1535
@@ -1578,6 +1538,7 @@ static int __exit m66592_remove(struct platform_device *pdev)
1578 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); 1538 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev);
1579 1539
1580 usb_del_gadget_udc(&m66592->gadget); 1540 usb_del_gadget_udc(&m66592->gadget);
1541 device_del(&m66592->gadget.dev);
1581 1542
1582 del_timer_sync(&m66592->timer); 1543 del_timer_sync(&m66592->timer);
1583 iounmap(m66592->reg); 1544 iounmap(m66592->reg);
@@ -1706,8 +1667,6 @@ static int __init m66592_probe(struct platform_device *pdev)
1706 m66592->pipenum2ep[0] = &m66592->ep[0]; 1667 m66592->pipenum2ep[0] = &m66592->ep[0];
1707 m66592->epaddr2ep[0] = &m66592->ep[0]; 1668 m66592->epaddr2ep[0] = &m66592->ep[0];
1708 1669
1709 the_controller = m66592;
1710
1711 m66592->ep0_req = m66592_alloc_request(&m66592->ep[0].ep, GFP_KERNEL); 1670 m66592->ep0_req = m66592_alloc_request(&m66592->ep[0].ep, GFP_KERNEL);
1712 if (m66592->ep0_req == NULL) 1671 if (m66592->ep0_req == NULL)
1713 goto clean_up3; 1672 goto clean_up3;
@@ -1715,6 +1674,12 @@ static int __init m66592_probe(struct platform_device *pdev)
1715 1674
1716 init_controller(m66592); 1675 init_controller(m66592);
1717 1676
1677 ret = device_add(&m66592->gadget.dev);
1678 if (ret) {
1679 pr_err("device_add error (%d)\n", ret);
1680 goto err_device_add;
1681 }
1682
1718 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget); 1683 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget);
1719 if (ret) 1684 if (ret)
1720 goto err_add_udc; 1685 goto err_add_udc;
@@ -1723,6 +1688,9 @@ static int __init m66592_probe(struct platform_device *pdev)
1723 return 0; 1688 return 0;
1724 1689
1725err_add_udc: 1690err_add_udc:
1691 device_del(&m66592->gadget.dev);
1692
1693err_device_add:
1726 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); 1694 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1727 1695
1728clean_up3: 1696clean_up3:
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h
index 16c7e14678b8..96d49d7bfb6b 100644
--- a/drivers/usb/gadget/m66592-udc.h
+++ b/drivers/usb/gadget/m66592-udc.h
@@ -492,6 +492,7 @@ struct m66592 {
492 int isochronous; 492 int isochronous;
493 int num_dma; 493 int num_dma;
494}; 494};
495#define to_m66592(g) (container_of((g), struct m66592, gadget))
495 496
496#define gadget_to_m66592(_gadget) container_of(_gadget, struct m66592, gadget) 497#define gadget_to_m66592(_gadget) container_of(_gadget, struct m66592, gadget)
497#define m66592_to_gadget(m66592) (&m66592->gadget) 498#define m66592_to_gadget(m66592) (&m66592->gadget)
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 88472bf7dbb7..20bbbf917fc2 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -16,6 +16,7 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "u_serial.h"
19#if defined USB_ETH_RNDIS 20#if defined USB_ETH_RNDIS
20# undef USB_ETH_RNDIS 21# undef USB_ETH_RNDIS
21#endif 22#endif
@@ -42,9 +43,6 @@ MODULE_LICENSE("GPL");
42 */ 43 */
43#include "f_mass_storage.c" 44#include "f_mass_storage.c"
44 45
45#include "u_serial.c"
46#include "f_acm.c"
47
48#include "f_ecm.c" 46#include "f_ecm.c"
49#include "f_subset.c" 47#include "f_subset.c"
50#ifdef USB_ETH_RNDIS 48#ifdef USB_ETH_RNDIS
@@ -137,10 +135,13 @@ static struct fsg_common fsg_common;
137 135
138static u8 hostaddr[ETH_ALEN]; 136static u8 hostaddr[ETH_ALEN];
139 137
138static unsigned char tty_line;
139static struct usb_function_instance *fi_acm;
140 140
141/********** RNDIS **********/ 141/********** RNDIS **********/
142 142
143#ifdef USB_ETH_RNDIS 143#ifdef USB_ETH_RNDIS
144static struct usb_function *f_acm_rndis;
144 145
145static __init int rndis_do_config(struct usb_configuration *c) 146static __init int rndis_do_config(struct usb_configuration *c)
146{ 147{
@@ -155,15 +156,25 @@ static __init int rndis_do_config(struct usb_configuration *c)
155 if (ret < 0) 156 if (ret < 0)
156 return ret; 157 return ret;
157 158
158 ret = acm_bind_config(c, 0); 159 f_acm_rndis = usb_get_function(fi_acm);
159 if (ret < 0) 160 if (IS_ERR(f_acm_rndis))
160 return ret; 161 goto err_func_acm;
162
163 ret = usb_add_function(c, f_acm_rndis);
164 if (ret)
165 goto err_conf;
161 166
162 ret = fsg_bind_config(c->cdev, c, &fsg_common); 167 ret = fsg_bind_config(c->cdev, c, &fsg_common);
163 if (ret < 0) 168 if (ret < 0)
164 return ret; 169 goto err_fsg;
165 170
166 return 0; 171 return 0;
172err_fsg:
173 usb_remove_function(c, f_acm_rndis);
174err_conf:
175 usb_put_function(f_acm_rndis);
176err_func_acm:
177 return ret;
167} 178}
168 179
169static int rndis_config_register(struct usb_composite_dev *cdev) 180static int rndis_config_register(struct usb_composite_dev *cdev)
@@ -192,6 +203,7 @@ static int rndis_config_register(struct usb_composite_dev *cdev)
192/********** CDC ECM **********/ 203/********** CDC ECM **********/
193 204
194#ifdef CONFIG_USB_G_MULTI_CDC 205#ifdef CONFIG_USB_G_MULTI_CDC
206static struct usb_function *f_acm_multi;
195 207
196static __init int cdc_do_config(struct usb_configuration *c) 208static __init int cdc_do_config(struct usb_configuration *c)
197{ 209{
@@ -206,15 +218,26 @@ static __init int cdc_do_config(struct usb_configuration *c)
206 if (ret < 0) 218 if (ret < 0)
207 return ret; 219 return ret;
208 220
209 ret = acm_bind_config(c, 0); 221 /* implicit port_num is zero */
210 if (ret < 0) 222 f_acm_multi = usb_get_function(fi_acm);
211 return ret; 223 if (IS_ERR(f_acm_multi))
224 goto err_func_acm;
225
226 ret = usb_add_function(c, f_acm_multi);
227 if (ret)
228 goto err_conf;
212 229
213 ret = fsg_bind_config(c->cdev, c, &fsg_common); 230 ret = fsg_bind_config(c->cdev, c, &fsg_common);
214 if (ret < 0) 231 if (ret < 0)
215 return ret; 232 goto err_fsg;
216 233
217 return 0; 234 return 0;
235err_fsg:
236 usb_remove_function(c, f_acm_multi);
237err_conf:
238 usb_put_function(f_acm_multi);
239err_func_acm:
240 return ret;
218} 241}
219 242
220static int cdc_config_register(struct usb_composite_dev *cdev) 243static int cdc_config_register(struct usb_composite_dev *cdev)
@@ -243,10 +266,10 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
243 266
244/****************************** Gadget Bind ******************************/ 267/****************************** Gadget Bind ******************************/
245 268
246
247static int __ref multi_bind(struct usb_composite_dev *cdev) 269static int __ref multi_bind(struct usb_composite_dev *cdev)
248{ 270{
249 struct usb_gadget *gadget = cdev->gadget; 271 struct usb_gadget *gadget = cdev->gadget;
272 struct f_serial_opts *opts;
250 int status; 273 int status;
251 274
252 if (!can_support_ecm(cdev->gadget)) { 275 if (!can_support_ecm(cdev->gadget)) {
@@ -261,10 +284,19 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
261 return status; 284 return status;
262 285
263 /* set up serial link layer */ 286 /* set up serial link layer */
264 status = gserial_setup(cdev->gadget, 1); 287 status = gserial_alloc_line(&tty_line);
265 if (status < 0) 288 if (status < 0)
266 goto fail0; 289 goto fail0;
267 290
291 fi_acm = usb_get_function_instance("acm");
292 if (IS_ERR(fi_acm)) {
293 status = PTR_ERR(fi_acm);
294 goto fail0dot5;
295 }
296
297 opts = container_of(fi_acm, struct f_serial_opts, func_inst);
298 opts->port_num = tty_line;
299
268 /* set up mass storage function */ 300 /* set up mass storage function */
269 { 301 {
270 void *retp; 302 void *retp;
@@ -301,7 +333,9 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
301fail2: 333fail2:
302 fsg_common_put(&fsg_common); 334 fsg_common_put(&fsg_common);
303fail1: 335fail1:
304 gserial_cleanup(); 336 usb_put_function_instance(fi_acm);
337fail0dot5:
338 gserial_free_line(tty_line);
305fail0: 339fail0:
306 gether_cleanup(); 340 gether_cleanup();
307 return status; 341 return status;
@@ -309,7 +343,14 @@ fail0:
309 343
310static int __exit multi_unbind(struct usb_composite_dev *cdev) 344static int __exit multi_unbind(struct usb_composite_dev *cdev)
311{ 345{
312 gserial_cleanup(); 346#ifdef CONFIG_USB_G_MULTI_CDC
347 usb_put_function(f_acm_multi);
348#endif
349#ifdef USB_ETH_RNDIS
350 usb_put_function(f_acm_rndis);
351#endif
352 usb_put_function_instance(fi_acm);
353 gserial_free_line(tty_line);
313 gether_cleanup(); 354 gether_cleanup();
314 return 0; 355 return 0;
315} 356}
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index 6e8b1272ebce..c8cf959057fe 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -61,9 +61,6 @@ static DECLARE_COMPLETION(release_done);
61static const char driver_name[] = "mv_udc"; 61static const char driver_name[] = "mv_udc";
62static const char driver_desc[] = DRIVER_DESC; 62static const char driver_desc[] = DRIVER_DESC;
63 63
64/* controller device global variable */
65static struct mv_udc *the_controller;
66
67static void nuke(struct mv_ep *ep, int status); 64static void nuke(struct mv_ep *ep, int status);
68static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver); 65static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver);
69 66
@@ -1268,9 +1265,8 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on)
1268 return retval; 1265 return retval;
1269} 1266}
1270 1267
1271static int mv_udc_start(struct usb_gadget_driver *driver, 1268static int mv_udc_start(struct usb_gadget *, struct usb_gadget_driver *);
1272 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1269static int mv_udc_stop(struct usb_gadget *, struct usb_gadget_driver *);
1273static int mv_udc_stop(struct usb_gadget_driver *driver);
1274/* device controller usb_gadget_ops structure */ 1270/* device controller usb_gadget_ops structure */
1275static const struct usb_gadget_ops mv_ops = { 1271static const struct usb_gadget_ops mv_ops = {
1276 1272
@@ -1285,8 +1281,8 @@ static const struct usb_gadget_ops mv_ops = {
1285 1281
1286 /* D+ pullup, software-controlled connect/disconnect to USB host */ 1282 /* D+ pullup, software-controlled connect/disconnect to USB host */
1287 .pullup = mv_udc_pullup, 1283 .pullup = mv_udc_pullup,
1288 .start = mv_udc_start, 1284 .udc_start = mv_udc_start,
1289 .stop = mv_udc_stop, 1285 .udc_stop = mv_udc_stop,
1290}; 1286};
1291 1287
1292static int eps_init(struct mv_udc *udc) 1288static int eps_init(struct mv_udc *udc)
@@ -1373,15 +1369,14 @@ static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver)
1373 } 1369 }
1374} 1370}
1375 1371
1376static int mv_udc_start(struct usb_gadget_driver *driver, 1372static int mv_udc_start(struct usb_gadget *gadget,
1377 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1373 struct usb_gadget_driver *driver)
1378{ 1374{
1379 struct mv_udc *udc = the_controller; 1375 struct mv_udc *udc;
1380 int retval = 0; 1376 int retval = 0;
1381 unsigned long flags; 1377 unsigned long flags;
1382 1378
1383 if (!udc) 1379 udc = container_of(gadget, struct mv_udc, gadget);
1384 return -ENODEV;
1385 1380
1386 if (udc->driver) 1381 if (udc->driver)
1387 return -EBUSY; 1382 return -EBUSY;
@@ -1399,26 +1394,14 @@ static int mv_udc_start(struct usb_gadget_driver *driver,
1399 1394
1400 spin_unlock_irqrestore(&udc->lock, flags); 1395 spin_unlock_irqrestore(&udc->lock, flags);
1401 1396
1402 retval = bind(&udc->gadget, driver); 1397 if (udc->transceiver) {
1403 if (retval) {
1404 dev_err(&udc->dev->dev, "bind to driver %s --> %d\n",
1405 driver->driver.name, retval);
1406 udc->driver = NULL;
1407 udc->gadget.dev.driver = NULL;
1408 return retval;
1409 }
1410
1411 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1412 retval = otg_set_peripheral(udc->transceiver->otg, 1398 retval = otg_set_peripheral(udc->transceiver->otg,
1413 &udc->gadget); 1399 &udc->gadget);
1414 if (retval) { 1400 if (retval) {
1415 dev_err(&udc->dev->dev, 1401 dev_err(&udc->dev->dev,
1416 "unable to register peripheral to otg\n"); 1402 "unable to register peripheral to otg\n");
1417 if (driver->unbind) { 1403 udc->driver = NULL;
1418 driver->unbind(&udc->gadget); 1404 udc->gadget.dev.driver = NULL;
1419 udc->gadget.dev.driver = NULL;
1420 udc->driver = NULL;
1421 }
1422 return retval; 1405 return retval;
1423 } 1406 }
1424 } 1407 }
@@ -1433,13 +1416,13 @@ static int mv_udc_start(struct usb_gadget_driver *driver,
1433 return 0; 1416 return 0;
1434} 1417}
1435 1418
1436static int mv_udc_stop(struct usb_gadget_driver *driver) 1419static int mv_udc_stop(struct usb_gadget *gadget,
1420 struct usb_gadget_driver *driver)
1437{ 1421{
1438 struct mv_udc *udc = the_controller; 1422 struct mv_udc *udc;
1439 unsigned long flags; 1423 unsigned long flags;
1440 1424
1441 if (!udc) 1425 udc = container_of(gadget, struct mv_udc, gadget);
1442 return -ENODEV;
1443 1426
1444 spin_lock_irqsave(&udc->lock, flags); 1427 spin_lock_irqsave(&udc->lock, flags);
1445 1428
@@ -1454,7 +1437,6 @@ static int mv_udc_stop(struct usb_gadget_driver *driver)
1454 spin_unlock_irqrestore(&udc->lock, flags); 1437 spin_unlock_irqrestore(&udc->lock, flags);
1455 1438
1456 /* unbind gadget driver */ 1439 /* unbind gadget driver */
1457 driver->unbind(&udc->gadget);
1458 udc->gadget.dev.driver = NULL; 1440 udc->gadget.dev.driver = NULL;
1459 udc->driver = NULL; 1441 udc->driver = NULL;
1460 1442
@@ -1472,10 +1454,13 @@ static void mv_set_ptc(struct mv_udc *udc, u32 mode)
1472 1454
1473static void prime_status_complete(struct usb_ep *ep, struct usb_request *_req) 1455static void prime_status_complete(struct usb_ep *ep, struct usb_request *_req)
1474{ 1456{
1475 struct mv_udc *udc = the_controller; 1457 struct mv_ep *mvep = container_of(ep, struct mv_ep, ep);
1476 struct mv_req *req = container_of(_req, struct mv_req, req); 1458 struct mv_req *req = container_of(_req, struct mv_req, req);
1459 struct mv_udc *udc;
1477 unsigned long flags; 1460 unsigned long flags;
1478 1461
1462 udc = mvep->udc;
1463
1479 dev_info(&udc->dev->dev, "switch to test mode %d\n", req->test_mode); 1464 dev_info(&udc->dev->dev, "switch to test mode %d\n", req->test_mode);
1480 1465
1481 spin_lock_irqsave(&udc->lock, flags); 1466 spin_lock_irqsave(&udc->lock, flags);
@@ -2123,15 +2108,18 @@ static void mv_udc_vbus_work(struct work_struct *work)
2123/* release device structure */ 2108/* release device structure */
2124static void gadget_release(struct device *_dev) 2109static void gadget_release(struct device *_dev)
2125{ 2110{
2126 struct mv_udc *udc = the_controller; 2111 struct mv_udc *udc;
2112
2113 udc = dev_get_drvdata(_dev);
2127 2114
2128 complete(udc->done); 2115 complete(udc->done);
2129} 2116}
2130 2117
2131static int mv_udc_remove(struct platform_device *dev) 2118static int mv_udc_remove(struct platform_device *pdev)
2132{ 2119{
2133 struct mv_udc *udc = the_controller; 2120 struct mv_udc *udc;
2134 int clk_i; 2121
2122 udc = platform_get_drvdata(pdev);
2135 2123
2136 usb_del_gadget_udc(&udc->gadget); 2124 usb_del_gadget_udc(&udc->gadget);
2137 2125
@@ -2140,57 +2128,27 @@ static int mv_udc_remove(struct platform_device *dev)
2140 destroy_workqueue(udc->qwork); 2128 destroy_workqueue(udc->qwork);
2141 } 2129 }
2142 2130
2143 /*
2144 * If we have transceiver inited,
2145 * then vbus irq will not be requested in udc driver.
2146 */
2147 if (udc->pdata && udc->pdata->vbus
2148 && udc->clock_gating && IS_ERR_OR_NULL(udc->transceiver))
2149 free_irq(udc->pdata->vbus->irq, &dev->dev);
2150
2151 /* free memory allocated in probe */ 2131 /* free memory allocated in probe */
2152 if (udc->dtd_pool) 2132 if (udc->dtd_pool)
2153 dma_pool_destroy(udc->dtd_pool); 2133 dma_pool_destroy(udc->dtd_pool);
2154 2134
2155 if (udc->ep_dqh) 2135 if (udc->ep_dqh)
2156 dma_free_coherent(&dev->dev, udc->ep_dqh_size, 2136 dma_free_coherent(&pdev->dev, udc->ep_dqh_size,
2157 udc->ep_dqh, udc->ep_dqh_dma); 2137 udc->ep_dqh, udc->ep_dqh_dma);
2158 2138
2159 kfree(udc->eps);
2160
2161 if (udc->irq)
2162 free_irq(udc->irq, &dev->dev);
2163
2164 mv_udc_disable(udc); 2139 mv_udc_disable(udc);
2165 2140
2166 if (udc->cap_regs)
2167 iounmap(udc->cap_regs);
2168
2169 if (udc->phy_regs)
2170 iounmap(udc->phy_regs);
2171
2172 if (udc->status_req) {
2173 kfree(udc->status_req->req.buf);
2174 kfree(udc->status_req);
2175 }
2176
2177 for (clk_i = 0; clk_i <= udc->clknum; clk_i++)
2178 clk_put(udc->clk[clk_i]);
2179
2180 device_unregister(&udc->gadget.dev); 2141 device_unregister(&udc->gadget.dev);
2181 2142
2182 /* free dev, wait for the release() finished */ 2143 /* free dev, wait for the release() finished */
2183 wait_for_completion(udc->done); 2144 wait_for_completion(udc->done);
2184 kfree(udc);
2185
2186 the_controller = NULL;
2187 2145
2188 return 0; 2146 return 0;
2189} 2147}
2190 2148
2191static int mv_udc_probe(struct platform_device *dev) 2149static int mv_udc_probe(struct platform_device *pdev)
2192{ 2150{
2193 struct mv_usb_platform_data *pdata = dev->dev.platform_data; 2151 struct mv_usb_platform_data *pdata = pdev->dev.platform_data;
2194 struct mv_udc *udc; 2152 struct mv_udc *udc;
2195 int retval = 0; 2153 int retval = 0;
2196 int clk_i = 0; 2154 int clk_i = 0;
@@ -2198,71 +2156,73 @@ static int mv_udc_probe(struct platform_device *dev)
2198 size_t size; 2156 size_t size;
2199 2157
2200 if (pdata == NULL) { 2158 if (pdata == NULL) {
2201 dev_err(&dev->dev, "missing platform_data\n"); 2159 dev_err(&pdev->dev, "missing platform_data\n");
2202 return -ENODEV; 2160 return -ENODEV;
2203 } 2161 }
2204 2162
2205 size = sizeof(*udc) + sizeof(struct clk *) * pdata->clknum; 2163 size = sizeof(*udc) + sizeof(struct clk *) * pdata->clknum;
2206 udc = kzalloc(size, GFP_KERNEL); 2164 udc = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
2207 if (udc == NULL) { 2165 if (udc == NULL) {
2208 dev_err(&dev->dev, "failed to allocate memory for udc\n"); 2166 dev_err(&pdev->dev, "failed to allocate memory for udc\n");
2209 return -ENOMEM; 2167 return -ENOMEM;
2210 } 2168 }
2211 2169
2212 the_controller = udc;
2213 udc->done = &release_done; 2170 udc->done = &release_done;
2214 udc->pdata = dev->dev.platform_data; 2171 udc->pdata = pdev->dev.platform_data;
2215 spin_lock_init(&udc->lock); 2172 spin_lock_init(&udc->lock);
2216 2173
2217 udc->dev = dev; 2174 udc->dev = pdev;
2218 2175
2219#ifdef CONFIG_USB_OTG_UTILS 2176#ifdef CONFIG_USB_OTG_UTILS
2220 if (pdata->mode == MV_USB_MODE_OTG) 2177 if (pdata->mode == MV_USB_MODE_OTG) {
2221 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 2178 udc->transceiver = devm_usb_get_phy(&pdev->dev,
2179 USB_PHY_TYPE_USB2);
2180 if (IS_ERR_OR_NULL(udc->transceiver)) {
2181 udc->transceiver = NULL;
2182 return -ENODEV;
2183 }
2184 }
2222#endif 2185#endif
2223 2186
2224 udc->clknum = pdata->clknum; 2187 udc->clknum = pdata->clknum;
2225 for (clk_i = 0; clk_i < udc->clknum; clk_i++) { 2188 for (clk_i = 0; clk_i < udc->clknum; clk_i++) {
2226 udc->clk[clk_i] = clk_get(&dev->dev, pdata->clkname[clk_i]); 2189 udc->clk[clk_i] = devm_clk_get(&pdev->dev,
2190 pdata->clkname[clk_i]);
2227 if (IS_ERR(udc->clk[clk_i])) { 2191 if (IS_ERR(udc->clk[clk_i])) {
2228 retval = PTR_ERR(udc->clk[clk_i]); 2192 retval = PTR_ERR(udc->clk[clk_i]);
2229 goto err_put_clk; 2193 return retval;
2230 } 2194 }
2231 } 2195 }
2232 2196
2233 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs"); 2197 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs");
2234 if (r == NULL) { 2198 if (r == NULL) {
2235 dev_err(&dev->dev, "no I/O memory resource defined\n"); 2199 dev_err(&pdev->dev, "no I/O memory resource defined\n");
2236 retval = -ENODEV; 2200 return -ENODEV;
2237 goto err_put_clk;
2238 } 2201 }
2239 2202
2240 udc->cap_regs = (struct mv_cap_regs __iomem *) 2203 udc->cap_regs = (struct mv_cap_regs __iomem *)
2241 ioremap(r->start, resource_size(r)); 2204 devm_ioremap(&pdev->dev, r->start, resource_size(r));
2242 if (udc->cap_regs == NULL) { 2205 if (udc->cap_regs == NULL) {
2243 dev_err(&dev->dev, "failed to map I/O memory\n"); 2206 dev_err(&pdev->dev, "failed to map I/O memory\n");
2244 retval = -EBUSY; 2207 return -EBUSY;
2245 goto err_put_clk;
2246 } 2208 }
2247 2209
2248 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "phyregs"); 2210 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "phyregs");
2249 if (r == NULL) { 2211 if (r == NULL) {
2250 dev_err(&dev->dev, "no phy I/O memory resource defined\n"); 2212 dev_err(&pdev->dev, "no phy I/O memory resource defined\n");
2251 retval = -ENODEV; 2213 return -ENODEV;
2252 goto err_iounmap_capreg;
2253 } 2214 }
2254 2215
2255 udc->phy_regs = ioremap(r->start, resource_size(r)); 2216 udc->phy_regs = ioremap(r->start, resource_size(r));
2256 if (udc->phy_regs == NULL) { 2217 if (udc->phy_regs == NULL) {
2257 dev_err(&dev->dev, "failed to map phy I/O memory\n"); 2218 dev_err(&pdev->dev, "failed to map phy I/O memory\n");
2258 retval = -EBUSY; 2219 return -EBUSY;
2259 goto err_iounmap_capreg;
2260 } 2220 }
2261 2221
2262 /* we will acces controller register, so enable the clk */ 2222 /* we will acces controller register, so enable the clk */
2263 retval = mv_udc_enable_internal(udc); 2223 retval = mv_udc_enable_internal(udc);
2264 if (retval) 2224 if (retval)
2265 goto err_iounmap_phyreg; 2225 return retval;
2266 2226
2267 udc->op_regs = 2227 udc->op_regs =
2268 (struct mv_op_regs __iomem *)((unsigned long)udc->cap_regs 2228 (struct mv_op_regs __iomem *)((unsigned long)udc->cap_regs
@@ -2279,11 +2239,11 @@ static int mv_udc_probe(struct platform_device *dev)
2279 2239
2280 size = udc->max_eps * sizeof(struct mv_dqh) *2; 2240 size = udc->max_eps * sizeof(struct mv_dqh) *2;
2281 size = (size + DQH_ALIGNMENT - 1) & ~(DQH_ALIGNMENT - 1); 2241 size = (size + DQH_ALIGNMENT - 1) & ~(DQH_ALIGNMENT - 1);
2282 udc->ep_dqh = dma_alloc_coherent(&dev->dev, size, 2242 udc->ep_dqh = dma_alloc_coherent(&pdev->dev, size,
2283 &udc->ep_dqh_dma, GFP_KERNEL); 2243 &udc->ep_dqh_dma, GFP_KERNEL);
2284 2244
2285 if (udc->ep_dqh == NULL) { 2245 if (udc->ep_dqh == NULL) {
2286 dev_err(&dev->dev, "allocate dQH memory failed\n"); 2246 dev_err(&pdev->dev, "allocate dQH memory failed\n");
2287 retval = -ENOMEM; 2247 retval = -ENOMEM;
2288 goto err_disable_clock; 2248 goto err_disable_clock;
2289 } 2249 }
@@ -2291,7 +2251,7 @@ static int mv_udc_probe(struct platform_device *dev)
2291 2251
2292 /* create dTD dma_pool resource */ 2252 /* create dTD dma_pool resource */
2293 udc->dtd_pool = dma_pool_create("mv_dtd", 2253 udc->dtd_pool = dma_pool_create("mv_dtd",
2294 &dev->dev, 2254 &pdev->dev,
2295 sizeof(struct mv_dtd), 2255 sizeof(struct mv_dtd),
2296 DTD_ALIGNMENT, 2256 DTD_ALIGNMENT,
2297 DMA_BOUNDARY); 2257 DMA_BOUNDARY);
@@ -2302,19 +2262,20 @@ static int mv_udc_probe(struct platform_device *dev)
2302 } 2262 }
2303 2263
2304 size = udc->max_eps * sizeof(struct mv_ep) *2; 2264 size = udc->max_eps * sizeof(struct mv_ep) *2;
2305 udc->eps = kzalloc(size, GFP_KERNEL); 2265 udc->eps = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
2306 if (udc->eps == NULL) { 2266 if (udc->eps == NULL) {
2307 dev_err(&dev->dev, "allocate ep memory failed\n"); 2267 dev_err(&pdev->dev, "allocate ep memory failed\n");
2308 retval = -ENOMEM; 2268 retval = -ENOMEM;
2309 goto err_destroy_dma; 2269 goto err_destroy_dma;
2310 } 2270 }
2311 2271
2312 /* initialize ep0 status request structure */ 2272 /* initialize ep0 status request structure */
2313 udc->status_req = kzalloc(sizeof(struct mv_req), GFP_KERNEL); 2273 udc->status_req = devm_kzalloc(&pdev->dev, sizeof(struct mv_req),
2274 GFP_KERNEL);
2314 if (!udc->status_req) { 2275 if (!udc->status_req) {
2315 dev_err(&dev->dev, "allocate status_req memory failed\n"); 2276 dev_err(&pdev->dev, "allocate status_req memory failed\n");
2316 retval = -ENOMEM; 2277 retval = -ENOMEM;
2317 goto err_free_eps; 2278 goto err_destroy_dma;
2318 } 2279 }
2319 INIT_LIST_HEAD(&udc->status_req->queue); 2280 INIT_LIST_HEAD(&udc->status_req->queue);
2320 2281
@@ -2329,17 +2290,17 @@ static int mv_udc_probe(struct platform_device *dev)
2329 2290
2330 r = platform_get_resource(udc->dev, IORESOURCE_IRQ, 0); 2291 r = platform_get_resource(udc->dev, IORESOURCE_IRQ, 0);
2331 if (r == NULL) { 2292 if (r == NULL) {
2332 dev_err(&dev->dev, "no IRQ resource defined\n"); 2293 dev_err(&pdev->dev, "no IRQ resource defined\n");
2333 retval = -ENODEV; 2294 retval = -ENODEV;
2334 goto err_free_status_req; 2295 goto err_destroy_dma;
2335 } 2296 }
2336 udc->irq = r->start; 2297 udc->irq = r->start;
2337 if (request_irq(udc->irq, mv_udc_irq, 2298 if (devm_request_irq(&pdev->dev, udc->irq, mv_udc_irq,
2338 IRQF_SHARED, driver_name, udc)) { 2299 IRQF_SHARED, driver_name, udc)) {
2339 dev_err(&dev->dev, "Request irq %d for UDC failed\n", 2300 dev_err(&pdev->dev, "Request irq %d for UDC failed\n",
2340 udc->irq); 2301 udc->irq);
2341 retval = -ENODEV; 2302 retval = -ENODEV;
2342 goto err_free_status_req; 2303 goto err_destroy_dma;
2343 } 2304 }
2344 2305
2345 /* initialize gadget structure */ 2306 /* initialize gadget structure */
@@ -2351,26 +2312,27 @@ static int mv_udc_probe(struct platform_device *dev)
2351 2312
2352 /* the "gadget" abstracts/virtualizes the controller */ 2313 /* the "gadget" abstracts/virtualizes the controller */
2353 dev_set_name(&udc->gadget.dev, "gadget"); 2314 dev_set_name(&udc->gadget.dev, "gadget");
2354 udc->gadget.dev.parent = &dev->dev; 2315 udc->gadget.dev.parent = &pdev->dev;
2355 udc->gadget.dev.dma_mask = dev->dev.dma_mask; 2316 udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
2356 udc->gadget.dev.release = gadget_release; 2317 udc->gadget.dev.release = gadget_release;
2357 udc->gadget.name = driver_name; /* gadget name */ 2318 udc->gadget.name = driver_name; /* gadget name */
2358 2319
2359 retval = device_register(&udc->gadget.dev); 2320 retval = device_register(&udc->gadget.dev);
2360 if (retval) 2321 if (retval)
2361 goto err_free_irq; 2322 goto err_destroy_dma;
2362 2323
2363 eps_init(udc); 2324 eps_init(udc);
2364 2325
2365 /* VBUS detect: we can disable/enable clock on demand.*/ 2326 /* VBUS detect: we can disable/enable clock on demand.*/
2366 if (!IS_ERR_OR_NULL(udc->transceiver)) 2327 if (udc->transceiver)
2367 udc->clock_gating = 1; 2328 udc->clock_gating = 1;
2368 else if (pdata->vbus) { 2329 else if (pdata->vbus) {
2369 udc->clock_gating = 1; 2330 udc->clock_gating = 1;
2370 retval = request_threaded_irq(pdata->vbus->irq, NULL, 2331 retval = devm_request_threaded_irq(&pdev->dev,
2332 pdata->vbus->irq, NULL,
2371 mv_udc_vbus_irq, IRQF_ONESHOT, "vbus", udc); 2333 mv_udc_vbus_irq, IRQF_ONESHOT, "vbus", udc);
2372 if (retval) { 2334 if (retval) {
2373 dev_info(&dev->dev, 2335 dev_info(&pdev->dev,
2374 "Can not request irq for VBUS, " 2336 "Can not request irq for VBUS, "
2375 "disable clock gating\n"); 2337 "disable clock gating\n");
2376 udc->clock_gating = 0; 2338 udc->clock_gating = 0;
@@ -2378,7 +2340,7 @@ static int mv_udc_probe(struct platform_device *dev)
2378 2340
2379 udc->qwork = create_singlethread_workqueue("mv_udc_queue"); 2341 udc->qwork = create_singlethread_workqueue("mv_udc_queue");
2380 if (!udc->qwork) { 2342 if (!udc->qwork) {
2381 dev_err(&dev->dev, "cannot create workqueue\n"); 2343 dev_err(&pdev->dev, "cannot create workqueue\n");
2382 retval = -ENOMEM; 2344 retval = -ENOMEM;
2383 goto err_unregister; 2345 goto err_unregister;
2384 } 2346 }
@@ -2396,53 +2358,40 @@ static int mv_udc_probe(struct platform_device *dev)
2396 else 2358 else
2397 udc->vbus_active = 1; 2359 udc->vbus_active = 1;
2398 2360
2399 retval = usb_add_gadget_udc(&dev->dev, &udc->gadget); 2361 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2400 if (retval) 2362 if (retval)
2401 goto err_unregister; 2363 goto err_create_workqueue;
2402 2364
2403 dev_info(&dev->dev, "successful probe UDC device %s clock gating.\n", 2365 platform_set_drvdata(pdev, udc);
2366 dev_info(&pdev->dev, "successful probe UDC device %s clock gating.\n",
2404 udc->clock_gating ? "with" : "without"); 2367 udc->clock_gating ? "with" : "without");
2405 2368
2406 return 0; 2369 return 0;
2407 2370
2371err_create_workqueue:
2372 destroy_workqueue(udc->qwork);
2408err_unregister: 2373err_unregister:
2409 if (udc->pdata && udc->pdata->vbus
2410 && udc->clock_gating && IS_ERR_OR_NULL(udc->transceiver))
2411 free_irq(pdata->vbus->irq, &dev->dev);
2412 device_unregister(&udc->gadget.dev); 2374 device_unregister(&udc->gadget.dev);
2413err_free_irq:
2414 free_irq(udc->irq, &dev->dev);
2415err_free_status_req:
2416 kfree(udc->status_req->req.buf);
2417 kfree(udc->status_req);
2418err_free_eps:
2419 kfree(udc->eps);
2420err_destroy_dma: 2375err_destroy_dma:
2421 dma_pool_destroy(udc->dtd_pool); 2376 dma_pool_destroy(udc->dtd_pool);
2422err_free_dma: 2377err_free_dma:
2423 dma_free_coherent(&dev->dev, udc->ep_dqh_size, 2378 dma_free_coherent(&pdev->dev, udc->ep_dqh_size,
2424 udc->ep_dqh, udc->ep_dqh_dma); 2379 udc->ep_dqh, udc->ep_dqh_dma);
2425err_disable_clock: 2380err_disable_clock:
2426 mv_udc_disable_internal(udc); 2381 mv_udc_disable_internal(udc);
2427err_iounmap_phyreg: 2382
2428 iounmap(udc->phy_regs);
2429err_iounmap_capreg:
2430 iounmap(udc->cap_regs);
2431err_put_clk:
2432 for (clk_i--; clk_i >= 0; clk_i--)
2433 clk_put(udc->clk[clk_i]);
2434 the_controller = NULL;
2435 kfree(udc);
2436 return retval; 2383 return retval;
2437} 2384}
2438 2385
2439#ifdef CONFIG_PM 2386#ifdef CONFIG_PM
2440static int mv_udc_suspend(struct device *_dev) 2387static int mv_udc_suspend(struct device *dev)
2441{ 2388{
2442 struct mv_udc *udc = the_controller; 2389 struct mv_udc *udc;
2390
2391 udc = dev_get_drvdata(dev);
2443 2392
2444 /* if OTG is enabled, the following will be done in OTG driver*/ 2393 /* if OTG is enabled, the following will be done in OTG driver*/
2445 if (!IS_ERR_OR_NULL(udc->transceiver)) 2394 if (udc->transceiver)
2446 return 0; 2395 return 0;
2447 2396
2448 if (udc->pdata->vbus && udc->pdata->vbus->poll) 2397 if (udc->pdata->vbus && udc->pdata->vbus->poll)
@@ -2469,13 +2418,15 @@ static int mv_udc_suspend(struct device *_dev)
2469 return 0; 2418 return 0;
2470} 2419}
2471 2420
2472static int mv_udc_resume(struct device *_dev) 2421static int mv_udc_resume(struct device *dev)
2473{ 2422{
2474 struct mv_udc *udc = the_controller; 2423 struct mv_udc *udc;
2475 int retval; 2424 int retval;
2476 2425
2426 udc = dev_get_drvdata(dev);
2427
2477 /* if OTG is enabled, the following will be done in OTG driver*/ 2428 /* if OTG is enabled, the following will be done in OTG driver*/
2478 if (!IS_ERR_OR_NULL(udc->transceiver)) 2429 if (udc->transceiver)
2479 return 0; 2430 return 0;
2480 2431
2481 if (!udc->clock_gating) { 2432 if (!udc->clock_gating) {
@@ -2499,11 +2450,12 @@ static const struct dev_pm_ops mv_udc_pm_ops = {
2499}; 2450};
2500#endif 2451#endif
2501 2452
2502static void mv_udc_shutdown(struct platform_device *dev) 2453static void mv_udc_shutdown(struct platform_device *pdev)
2503{ 2454{
2504 struct mv_udc *udc = the_controller; 2455 struct mv_udc *udc;
2505 u32 mode; 2456 u32 mode;
2506 2457
2458 udc = platform_get_drvdata(pdev);
2507 /* reset controller mode to IDLE */ 2459 /* reset controller mode to IDLE */
2508 mv_udc_enable(udc); 2460 mv_udc_enable(udc);
2509 mode = readl(&udc->op_regs->usbmode); 2461 mode = readl(&udc->op_regs->usbmode);
@@ -2514,7 +2466,7 @@ static void mv_udc_shutdown(struct platform_device *dev)
2514 2466
2515static struct platform_driver udc_driver = { 2467static struct platform_driver udc_driver = {
2516 .probe = mv_udc_probe, 2468 .probe = mv_udc_probe,
2517 .remove = __exit_p(mv_udc_remove), 2469 .remove = mv_udc_remove,
2518 .shutdown = mv_udc_shutdown, 2470 .shutdown = mv_udc_shutdown,
2519 .driver = { 2471 .driver = {
2520 .owner = THIS_MODULE, 2472 .owner = THIS_MODULE,
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 661600abace8..def37403989a 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -37,7 +37,7 @@
37 * the runtime footprint, and giving us at least some parts of what 37 * the runtime footprint, and giving us at least some parts of what
38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
39 */ 39 */
40#include "u_serial.c" 40#define USB_FACM_INCLUDED
41#include "f_acm.c" 41#include "f_acm.c"
42#include "f_ecm.c" 42#include "f_ecm.c"
43#include "f_obex.c" 43#include "f_obex.c"
@@ -101,6 +101,15 @@ MODULE_LICENSE("GPL");
101 101
102static u8 hostaddr[ETH_ALEN]; 102static u8 hostaddr[ETH_ALEN];
103 103
104enum {
105 TTY_PORT_OBEX0,
106 TTY_PORT_OBEX1,
107 TTY_PORT_ACM,
108 TTY_PORTS_MAX,
109};
110
111static unsigned char tty_lines[TTY_PORTS_MAX];
112
104static int __init nokia_bind_config(struct usb_configuration *c) 113static int __init nokia_bind_config(struct usb_configuration *c)
105{ 114{
106 int status = 0; 115 int status = 0;
@@ -109,15 +118,15 @@ static int __init nokia_bind_config(struct usb_configuration *c)
109 if (status) 118 if (status)
110 printk(KERN_DEBUG "could not bind phonet config\n"); 119 printk(KERN_DEBUG "could not bind phonet config\n");
111 120
112 status = obex_bind_config(c, 0); 121 status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX0]);
113 if (status) 122 if (status)
114 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 123 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
115 124
116 status = obex_bind_config(c, 1); 125 status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX1]);
117 if (status) 126 if (status)
118 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 127 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
119 128
120 status = acm_bind_config(c, 2); 129 status = acm_bind_config(c, tty_lines[TTY_PORT_ACM]);
121 if (status) 130 if (status)
122 printk(KERN_DEBUG "could not bind acm config\n"); 131 printk(KERN_DEBUG "could not bind acm config\n");
123 132
@@ -133,7 +142,7 @@ static struct usb_configuration nokia_config_500ma_driver = {
133 .bConfigurationValue = 1, 142 .bConfigurationValue = 1,
134 /* .iConfiguration = DYNAMIC */ 143 /* .iConfiguration = DYNAMIC */
135 .bmAttributes = USB_CONFIG_ATT_ONE, 144 .bmAttributes = USB_CONFIG_ATT_ONE,
136 .bMaxPower = 250, /* 500mA */ 145 .MaxPower = 500,
137}; 146};
138 147
139static struct usb_configuration nokia_config_100ma_driver = { 148static struct usb_configuration nokia_config_100ma_driver = {
@@ -141,21 +150,24 @@ static struct usb_configuration nokia_config_100ma_driver = {
141 .bConfigurationValue = 2, 150 .bConfigurationValue = 2,
142 /* .iConfiguration = DYNAMIC */ 151 /* .iConfiguration = DYNAMIC */
143 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, 152 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
144 .bMaxPower = 50, /* 100 mA */ 153 .MaxPower = 100,
145}; 154};
146 155
147static int __init nokia_bind(struct usb_composite_dev *cdev) 156static int __init nokia_bind(struct usb_composite_dev *cdev)
148{ 157{
149 struct usb_gadget *gadget = cdev->gadget; 158 struct usb_gadget *gadget = cdev->gadget;
150 int status; 159 int status;
160 int cur_line;
151 161
152 status = gphonet_setup(cdev->gadget); 162 status = gphonet_setup(cdev->gadget);
153 if (status < 0) 163 if (status < 0)
154 goto err_phonet; 164 goto err_phonet;
155 165
156 status = gserial_setup(cdev->gadget, 3); 166 for (cur_line = 0; cur_line < TTY_PORTS_MAX; cur_line++) {
157 if (status < 0) 167 status = gserial_alloc_line(&tty_lines[cur_line]);
158 goto err_serial; 168 if (status)
169 goto err_ether;
170 }
159 171
160 status = gether_setup(cdev->gadget, hostaddr); 172 status = gether_setup(cdev->gadget, hostaddr);
161 if (status < 0) 173 if (status < 0)
@@ -192,8 +204,10 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
192err_usb: 204err_usb:
193 gether_cleanup(); 205 gether_cleanup();
194err_ether: 206err_ether:
195 gserial_cleanup(); 207 cur_line--;
196err_serial: 208 while (cur_line >= 0)
209 gserial_free_line(tty_lines[cur_line--]);
210
197 gphonet_cleanup(); 211 gphonet_cleanup();
198err_phonet: 212err_phonet:
199 return status; 213 return status;
@@ -201,8 +215,13 @@ err_phonet:
201 215
202static int __exit nokia_unbind(struct usb_composite_dev *cdev) 216static int __exit nokia_unbind(struct usb_composite_dev *cdev)
203{ 217{
218 int i;
219
204 gphonet_cleanup(); 220 gphonet_cleanup();
205 gserial_cleanup(); 221
222 for (i = 0; i < TTY_PORTS_MAX; i++)
223 gserial_free_line(tty_lines[i]);
224
206 gether_cleanup(); 225 gether_cleanup();
207 226
208 return 0; 227 return 0;
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 8bfe990caf1a..06be85c2b233 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -1309,19 +1309,20 @@ static int omap_pullup(struct usb_gadget *gadget, int is_on)
1309 return 0; 1309 return 0;
1310} 1310}
1311 1311
1312static int omap_udc_start(struct usb_gadget_driver *driver, 1312static int omap_udc_start(struct usb_gadget *g,
1313 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1313 struct usb_gadget_driver *driver)
1314static int omap_udc_stop(struct usb_gadget_driver *driver); 1314static int omap_udc_stop(struct usb_gadget *g,
1315 struct usb_gadget_driver *driver);
1315 1316
1316static struct usb_gadget_ops omap_gadget_ops = { 1317static const struct usb_gadget_ops omap_gadget_ops = {
1317 .get_frame = omap_get_frame, 1318 .get_frame = omap_get_frame,
1318 .wakeup = omap_wakeup, 1319 .wakeup = omap_wakeup,
1319 .set_selfpowered = omap_set_selfpowered, 1320 .set_selfpowered = omap_set_selfpowered,
1320 .vbus_session = omap_vbus_session, 1321 .vbus_session = omap_vbus_session,
1321 .vbus_draw = omap_vbus_draw, 1322 .vbus_draw = omap_vbus_draw,
1322 .pullup = omap_pullup, 1323 .pullup = omap_pullup,
1323 .start = omap_udc_start, 1324 .udc_start = omap_udc_start,
1324 .stop = omap_udc_stop, 1325 .udc_stop = omap_udc_stop,
1325}; 1326};
1326 1327
1327/*-------------------------------------------------------------------------*/ 1328/*-------------------------------------------------------------------------*/
@@ -2041,28 +2042,15 @@ static inline int machine_without_vbus_sense(void)
2041 || cpu_is_omap7xx(); 2042 || cpu_is_omap7xx();
2042} 2043}
2043 2044
2044static int omap_udc_start(struct usb_gadget_driver *driver, 2045static int omap_udc_start(struct usb_gadget *g,
2045 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 2046 struct usb_gadget_driver *driver)
2046{ 2047{
2047 int status = -ENODEV; 2048 int status = -ENODEV;
2048 struct omap_ep *ep; 2049 struct omap_ep *ep;
2049 unsigned long flags; 2050 unsigned long flags;
2050 2051
2051 /* basic sanity tests */
2052 if (!udc)
2053 return -ENODEV;
2054 if (!driver
2055 /* FIXME if otg, check: driver->is_otg */
2056 || driver->max_speed < USB_SPEED_FULL
2057 || !bind || !driver->setup)
2058 return -EINVAL;
2059 2052
2060 spin_lock_irqsave(&udc->lock, flags); 2053 spin_lock_irqsave(&udc->lock, flags);
2061 if (udc->driver) {
2062 spin_unlock_irqrestore(&udc->lock, flags);
2063 return -EBUSY;
2064 }
2065
2066 /* reset state */ 2054 /* reset state */
2067 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { 2055 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
2068 ep->irqs = 0; 2056 ep->irqs = 0;
@@ -2084,15 +2072,6 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2084 if (udc->dc_clk != NULL) 2072 if (udc->dc_clk != NULL)
2085 omap_udc_enable_clock(1); 2073 omap_udc_enable_clock(1);
2086 2074
2087 status = bind(&udc->gadget, driver);
2088 if (status) {
2089 DBG("bind to %s --> %d\n", driver->driver.name, status);
2090 udc->gadget.dev.driver = NULL;
2091 udc->driver = NULL;
2092 goto done;
2093 }
2094 DBG("bound to driver %s\n", driver->driver.name);
2095
2096 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); 2075 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
2097 2076
2098 /* connect to bus through transceiver */ 2077 /* connect to bus through transceiver */
@@ -2124,19 +2103,16 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2124done: 2103done:
2125 if (udc->dc_clk != NULL) 2104 if (udc->dc_clk != NULL)
2126 omap_udc_enable_clock(0); 2105 omap_udc_enable_clock(0);
2106
2127 return status; 2107 return status;
2128} 2108}
2129 2109
2130static int omap_udc_stop(struct usb_gadget_driver *driver) 2110static int omap_udc_stop(struct usb_gadget *g,
2111 struct usb_gadget_driver *driver)
2131{ 2112{
2132 unsigned long flags; 2113 unsigned long flags;
2133 int status = -ENODEV; 2114 int status = -ENODEV;
2134 2115
2135 if (!udc)
2136 return -ENODEV;
2137 if (!driver || driver != udc->driver || !driver->unbind)
2138 return -EINVAL;
2139
2140 if (udc->dc_clk != NULL) 2116 if (udc->dc_clk != NULL)
2141 omap_udc_enable_clock(1); 2117 omap_udc_enable_clock(1);
2142 2118
@@ -2152,13 +2128,12 @@ static int omap_udc_stop(struct usb_gadget_driver *driver)
2152 udc_quiesce(udc); 2128 udc_quiesce(udc);
2153 spin_unlock_irqrestore(&udc->lock, flags); 2129 spin_unlock_irqrestore(&udc->lock, flags);
2154 2130
2155 driver->unbind(&udc->gadget);
2156 udc->gadget.dev.driver = NULL; 2131 udc->gadget.dev.driver = NULL;
2157 udc->driver = NULL; 2132 udc->driver = NULL;
2158 2133
2159 if (udc->dc_clk != NULL) 2134 if (udc->dc_clk != NULL)
2160 omap_udc_enable_clock(0); 2135 omap_udc_enable_clock(0);
2161 DBG("unregistered driver '%s'\n", driver->driver.name); 2136
2162 return status; 2137 return status;
2163} 2138}
2164 2139
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index 6490c0040e3a..a787a8ef672b 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -375,6 +375,7 @@ struct pch_udc_dev {
375 struct pch_udc_cfg_data cfg_data; 375 struct pch_udc_cfg_data cfg_data;
376 struct pch_vbus_gpio_data vbus_gpio; 376 struct pch_vbus_gpio_data vbus_gpio;
377}; 377};
378#define to_pch_udc(g) (container_of((g), struct pch_udc_dev, gadget))
378 379
379#define PCH_UDC_PCI_BAR 1 380#define PCH_UDC_PCI_BAR 1
380#define PCI_DEVICE_ID_INTEL_EG20T_UDC 0x8808 381#define PCI_DEVICE_ID_INTEL_EG20T_UDC 0x8808
@@ -384,7 +385,6 @@ struct pch_udc_dev {
384 385
385static const char ep0_string[] = "ep0in"; 386static const char ep0_string[] = "ep0in";
386static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */ 387static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */
387struct pch_udc_dev *pch_udc; /* pointer to device object */
388static bool speed_fs; 388static bool speed_fs;
389module_param_named(speed_fs, speed_fs, bool, S_IRUGO); 389module_param_named(speed_fs, speed_fs, bool, S_IRUGO);
390MODULE_PARM_DESC(speed_fs, "true for Full speed operation"); 390MODULE_PARM_DESC(speed_fs, "true for Full speed operation");
@@ -1235,9 +1235,10 @@ static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
1235 return -EOPNOTSUPP; 1235 return -EOPNOTSUPP;
1236} 1236}
1237 1237
1238static int pch_udc_start(struct usb_gadget_driver *driver, 1238static int pch_udc_start(struct usb_gadget *g,
1239 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1239 struct usb_gadget_driver *driver);
1240static int pch_udc_stop(struct usb_gadget_driver *driver); 1240static int pch_udc_stop(struct usb_gadget *g,
1241 struct usb_gadget_driver *driver);
1241static const struct usb_gadget_ops pch_udc_ops = { 1242static const struct usb_gadget_ops pch_udc_ops = {
1242 .get_frame = pch_udc_pcd_get_frame, 1243 .get_frame = pch_udc_pcd_get_frame,
1243 .wakeup = pch_udc_pcd_wakeup, 1244 .wakeup = pch_udc_pcd_wakeup,
@@ -1245,8 +1246,8 @@ static const struct usb_gadget_ops pch_udc_ops = {
1245 .pullup = pch_udc_pcd_pullup, 1246 .pullup = pch_udc_pcd_pullup,
1246 .vbus_session = pch_udc_pcd_vbus_session, 1247 .vbus_session = pch_udc_pcd_vbus_session,
1247 .vbus_draw = pch_udc_pcd_vbus_draw, 1248 .vbus_draw = pch_udc_pcd_vbus_draw,
1248 .start = pch_udc_start, 1249 .udc_start = pch_udc_start,
1249 .stop = pch_udc_stop, 1250 .udc_stop = pch_udc_stop,
1250}; 1251};
1251 1252
1252/** 1253/**
@@ -2981,40 +2982,15 @@ static int init_dma_pools(struct pch_udc_dev *dev)
2981 return 0; 2982 return 0;
2982} 2983}
2983 2984
2984static int pch_udc_start(struct usb_gadget_driver *driver, 2985static int pch_udc_start(struct usb_gadget *g,
2985 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 2986 struct usb_gadget_driver *driver)
2986{ 2987{
2987 struct pch_udc_dev *dev = pch_udc; 2988 struct pch_udc_dev *dev = to_pch_udc(g);
2988 int retval;
2989
2990 if (!driver || (driver->max_speed == USB_SPEED_UNKNOWN) || !bind ||
2991 !driver->setup || !driver->unbind || !driver->disconnect) {
2992 dev_err(&dev->pdev->dev,
2993 "%s: invalid driver parameter\n", __func__);
2994 return -EINVAL;
2995 }
2996 2989
2997 if (!dev)
2998 return -ENODEV;
2999
3000 if (dev->driver) {
3001 dev_err(&dev->pdev->dev, "%s: already bound\n", __func__);
3002 return -EBUSY;
3003 }
3004 driver->driver.bus = NULL; 2990 driver->driver.bus = NULL;
3005 dev->driver = driver; 2991 dev->driver = driver;
3006 dev->gadget.dev.driver = &driver->driver; 2992 dev->gadget.dev.driver = &driver->driver;
3007 2993
3008 /* Invoke the bind routine of the gadget driver */
3009 retval = bind(&dev->gadget, driver);
3010
3011 if (retval) {
3012 dev_err(&dev->pdev->dev, "%s: binding to %s returning %d\n",
3013 __func__, driver->driver.name, retval);
3014 dev->driver = NULL;
3015 dev->gadget.dev.driver = NULL;
3016 return retval;
3017 }
3018 /* get ready for ep0 traffic */ 2994 /* get ready for ep0 traffic */
3019 pch_udc_setup_ep0(dev); 2995 pch_udc_setup_ep0(dev);
3020 2996
@@ -3026,30 +3002,21 @@ static int pch_udc_start(struct usb_gadget_driver *driver,
3026 return 0; 3002 return 0;
3027} 3003}
3028 3004
3029static int pch_udc_stop(struct usb_gadget_driver *driver) 3005static int pch_udc_stop(struct usb_gadget *g,
3006 struct usb_gadget_driver *driver)
3030{ 3007{
3031 struct pch_udc_dev *dev = pch_udc; 3008 struct pch_udc_dev *dev = to_pch_udc(g);
3032
3033 if (!dev)
3034 return -ENODEV;
3035
3036 if (!driver || (driver != dev->driver)) {
3037 dev_err(&dev->pdev->dev,
3038 "%s: invalid driver parameter\n", __func__);
3039 return -EINVAL;
3040 }
3041 3009
3042 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK); 3010 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK);
3043 3011
3044 /* Assures that there are no pending requests with this driver */ 3012 /* Assures that there are no pending requests with this driver */
3045 driver->disconnect(&dev->gadget);
3046 driver->unbind(&dev->gadget);
3047 dev->gadget.dev.driver = NULL; 3013 dev->gadget.dev.driver = NULL;
3048 dev->driver = NULL; 3014 dev->driver = NULL;
3049 dev->connected = 0; 3015 dev->connected = 0;
3050 3016
3051 /* set SD */ 3017 /* set SD */
3052 pch_udc_set_disconnect(dev); 3018 pch_udc_set_disconnect(dev);
3019
3053 return 0; 3020 return 0;
3054} 3021}
3055 3022
@@ -3164,11 +3131,6 @@ static int pch_udc_probe(struct pci_dev *pdev,
3164 int retval; 3131 int retval;
3165 struct pch_udc_dev *dev; 3132 struct pch_udc_dev *dev;
3166 3133
3167 /* one udc only */
3168 if (pch_udc) {
3169 pr_err("%s: already probed\n", __func__);
3170 return -EBUSY;
3171 }
3172 /* init */ 3134 /* init */
3173 dev = kzalloc(sizeof *dev, GFP_KERNEL); 3135 dev = kzalloc(sizeof *dev, GFP_KERNEL);
3174 if (!dev) { 3136 if (!dev) {
@@ -3207,7 +3169,6 @@ static int pch_udc_probe(struct pci_dev *pdev,
3207 retval = -ENODEV; 3169 retval = -ENODEV;
3208 goto finished; 3170 goto finished;
3209 } 3171 }
3210 pch_udc = dev;
3211 /* initialize the hardware */ 3172 /* initialize the hardware */
3212 if (pch_udc_pcd_init(dev)) { 3173 if (pch_udc_pcd_init(dev)) {
3213 retval = -ENODEV; 3174 retval = -ENODEV;
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index d4ca9f1f7f24..fa9c34469a82 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -996,9 +996,10 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
996 return -EOPNOTSUPP; 996 return -EOPNOTSUPP;
997} 997}
998 998
999static int pxa25x_start(struct usb_gadget_driver *driver, 999static int pxa25x_udc_start(struct usb_gadget *g,
1000 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1000 struct usb_gadget_driver *driver);
1001static int pxa25x_stop(struct usb_gadget_driver *driver); 1001static int pxa25x_udc_stop(struct usb_gadget *g,
1002 struct usb_gadget_driver *driver);
1002 1003
1003static const struct usb_gadget_ops pxa25x_udc_ops = { 1004static const struct usb_gadget_ops pxa25x_udc_ops = {
1004 .get_frame = pxa25x_udc_get_frame, 1005 .get_frame = pxa25x_udc_get_frame,
@@ -1006,8 +1007,8 @@ static const struct usb_gadget_ops pxa25x_udc_ops = {
1006 .vbus_session = pxa25x_udc_vbus_session, 1007 .vbus_session = pxa25x_udc_vbus_session,
1007 .pullup = pxa25x_udc_pullup, 1008 .pullup = pxa25x_udc_pullup,
1008 .vbus_draw = pxa25x_udc_vbus_draw, 1009 .vbus_draw = pxa25x_udc_vbus_draw,
1009 .start = pxa25x_start, 1010 .udc_start = pxa25x_udc_start,
1010 .stop = pxa25x_stop, 1011 .udc_stop = pxa25x_udc_stop,
1011}; 1012};
1012 1013
1013/*-------------------------------------------------------------------------*/ 1014/*-------------------------------------------------------------------------*/
@@ -1254,23 +1255,12 @@ static void udc_enable (struct pxa25x_udc *dev)
1254 * disconnect is reported. then a host may connect again, or 1255 * disconnect is reported. then a host may connect again, or
1255 * the driver might get unbound. 1256 * the driver might get unbound.
1256 */ 1257 */
1257static int pxa25x_start(struct usb_gadget_driver *driver, 1258static int pxa25x_udc_start(struct usb_gadget *g,
1258 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1259 struct usb_gadget_driver *driver)
1259{ 1260{
1260 struct pxa25x_udc *dev = the_controller; 1261 struct pxa25x_udc *dev = to_pxa25x(g);
1261 int retval; 1262 int retval;
1262 1263
1263 if (!driver
1264 || driver->max_speed < USB_SPEED_FULL
1265 || !bind
1266 || !driver->disconnect
1267 || !driver->setup)
1268 return -EINVAL;
1269 if (!dev)
1270 return -ENODEV;
1271 if (dev->driver)
1272 return -EBUSY;
1273
1274 /* first hook up the driver ... */ 1264 /* first hook up the driver ... */
1275 dev->driver = driver; 1265 dev->driver = driver;
1276 dev->gadget.dev.driver = &driver->driver; 1266 dev->gadget.dev.driver = &driver->driver;
@@ -1278,34 +1268,20 @@ static int pxa25x_start(struct usb_gadget_driver *driver,
1278 1268
1279 retval = device_add (&dev->gadget.dev); 1269 retval = device_add (&dev->gadget.dev);
1280 if (retval) { 1270 if (retval) {
1281fail:
1282 dev->driver = NULL; 1271 dev->driver = NULL;
1283 dev->gadget.dev.driver = NULL; 1272 dev->gadget.dev.driver = NULL;
1284 return retval; 1273 return retval;
1285 } 1274 }
1286 retval = bind(&dev->gadget, driver);
1287 if (retval) {
1288 DMSG("bind to driver %s --> error %d\n",
1289 driver->driver.name, retval);
1290 device_del (&dev->gadget.dev);
1291 goto fail;
1292 }
1293 1275
1294 /* ... then enable host detection and ep0; and we're ready 1276 /* ... then enable host detection and ep0; and we're ready
1295 * for set_configuration as well as eventual disconnect. 1277 * for set_configuration as well as eventual disconnect.
1296 */ 1278 */
1297 DMSG("registered gadget driver '%s'\n", driver->driver.name);
1298
1299 /* connect to bus through transceiver */ 1279 /* connect to bus through transceiver */
1300 if (!IS_ERR_OR_NULL(dev->transceiver)) { 1280 if (!IS_ERR_OR_NULL(dev->transceiver)) {
1301 retval = otg_set_peripheral(dev->transceiver->otg, 1281 retval = otg_set_peripheral(dev->transceiver->otg,
1302 &dev->gadget); 1282 &dev->gadget);
1303 if (retval) { 1283 if (retval)
1304 DMSG("can't bind to transceiver\n");
1305 if (driver->unbind)
1306 driver->unbind(&dev->gadget);
1307 goto bind_fail; 1284 goto bind_fail;
1308 }
1309 } 1285 }
1310 1286
1311 pullup(dev); 1287 pullup(dev);
@@ -1334,22 +1310,14 @@ stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
1334 } 1310 }
1335 del_timer_sync(&dev->timer); 1311 del_timer_sync(&dev->timer);
1336 1312
1337 /* report disconnect; the driver is already quiesced */
1338 if (driver)
1339 driver->disconnect(&dev->gadget);
1340
1341 /* re-init driver-visible data structures */ 1313 /* re-init driver-visible data structures */
1342 udc_reinit(dev); 1314 udc_reinit(dev);
1343} 1315}
1344 1316
1345static int pxa25x_stop(struct usb_gadget_driver *driver) 1317static int pxa25x_udc_stop(struct usb_gadget*g,
1318 struct usb_gadget_driver *driver)
1346{ 1319{
1347 struct pxa25x_udc *dev = the_controller; 1320 struct pxa25x_udc *dev = to_pxa25x(g);
1348
1349 if (!dev)
1350 return -ENODEV;
1351 if (!driver || driver != dev->driver || !driver->unbind)
1352 return -EINVAL;
1353 1321
1354 local_irq_disable(); 1322 local_irq_disable();
1355 dev->pullup = 0; 1323 dev->pullup = 0;
@@ -1360,14 +1328,12 @@ static int pxa25x_stop(struct usb_gadget_driver *driver)
1360 if (!IS_ERR_OR_NULL(dev->transceiver)) 1328 if (!IS_ERR_OR_NULL(dev->transceiver))
1361 (void) otg_set_peripheral(dev->transceiver->otg, NULL); 1329 (void) otg_set_peripheral(dev->transceiver->otg, NULL);
1362 1330
1363 driver->unbind(&dev->gadget);
1364 dev->gadget.dev.driver = NULL; 1331 dev->gadget.dev.driver = NULL;
1365 dev->driver = NULL; 1332 dev->driver = NULL;
1366 1333
1367 device_del (&dev->gadget.dev); 1334 device_del (&dev->gadget.dev);
1368
1369 DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
1370 dump_state(dev); 1335 dump_state(dev);
1336
1371 return 0; 1337 return 0;
1372} 1338}
1373 1339
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h
index 2eca1e71fecd..3fe5931dc21a 100644
--- a/drivers/usb/gadget/pxa25x_udc.h
+++ b/drivers/usb/gadget/pxa25x_udc.h
@@ -126,6 +126,7 @@ struct pxa25x_udc {
126 struct dentry *debugfs_udc; 126 struct dentry *debugfs_udc;
127#endif 127#endif
128}; 128};
129#define to_pxa25x(g) (container_of((g), struct pxa25x_udc, gadget))
129 130
130/*-------------------------------------------------------------------------*/ 131/*-------------------------------------------------------------------------*/
131 132
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 2b3b01d5f403..f7d25795821a 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -1671,9 +1671,10 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1671 return -EOPNOTSUPP; 1671 return -EOPNOTSUPP;
1672} 1672}
1673 1673
1674static int pxa27x_udc_start(struct usb_gadget_driver *driver, 1674static int pxa27x_udc_start(struct usb_gadget *g,
1675 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1675 struct usb_gadget_driver *driver);
1676static int pxa27x_udc_stop(struct usb_gadget_driver *driver); 1676static int pxa27x_udc_stop(struct usb_gadget *g,
1677 struct usb_gadget_driver *driver);
1677 1678
1678static const struct usb_gadget_ops pxa_udc_ops = { 1679static const struct usb_gadget_ops pxa_udc_ops = {
1679 .get_frame = pxa_udc_get_frame, 1680 .get_frame = pxa_udc_get_frame,
@@ -1681,8 +1682,8 @@ static const struct usb_gadget_ops pxa_udc_ops = {
1681 .pullup = pxa_udc_pullup, 1682 .pullup = pxa_udc_pullup,
1682 .vbus_session = pxa_udc_vbus_session, 1683 .vbus_session = pxa_udc_vbus_session,
1683 .vbus_draw = pxa_udc_vbus_draw, 1684 .vbus_draw = pxa_udc_vbus_draw,
1684 .start = pxa27x_udc_start, 1685 .udc_start = pxa27x_udc_start,
1685 .stop = pxa27x_udc_stop, 1686 .udc_stop = pxa27x_udc_stop,
1686}; 1687};
1687 1688
1688/** 1689/**
@@ -1802,20 +1803,12 @@ static void udc_enable(struct pxa_udc *udc)
1802 * 1803 *
1803 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1804 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1804 */ 1805 */
1805static int pxa27x_udc_start(struct usb_gadget_driver *driver, 1806static int pxa27x_udc_start(struct usb_gadget *g,
1806 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1807 struct usb_gadget_driver *driver)
1807{ 1808{
1808 struct pxa_udc *udc = the_controller; 1809 struct pxa_udc *udc = to_pxa(g);
1809 int retval; 1810 int retval;
1810 1811
1811 if (!driver || driver->max_speed < USB_SPEED_FULL || !bind
1812 || !driver->disconnect || !driver->setup)
1813 return -EINVAL;
1814 if (!udc)
1815 return -ENODEV;
1816 if (udc->driver)
1817 return -EBUSY;
1818
1819 /* first hook up the driver ... */ 1812 /* first hook up the driver ... */
1820 udc->driver = driver; 1813 udc->driver = driver;
1821 udc->gadget.dev.driver = &driver->driver; 1814 udc->gadget.dev.driver = &driver->driver;
@@ -1824,23 +1817,14 @@ static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1824 retval = device_add(&udc->gadget.dev); 1817 retval = device_add(&udc->gadget.dev);
1825 if (retval) { 1818 if (retval) {
1826 dev_err(udc->dev, "device_add error %d\n", retval); 1819 dev_err(udc->dev, "device_add error %d\n", retval);
1827 goto add_fail; 1820 goto fail;
1828 } 1821 }
1829 retval = bind(&udc->gadget, driver);
1830 if (retval) {
1831 dev_err(udc->dev, "bind to driver %s --> error %d\n",
1832 driver->driver.name, retval);
1833 goto bind_fail;
1834 }
1835 dev_dbg(udc->dev, "registered gadget driver '%s'\n",
1836 driver->driver.name);
1837
1838 if (!IS_ERR_OR_NULL(udc->transceiver)) { 1822 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1839 retval = otg_set_peripheral(udc->transceiver->otg, 1823 retval = otg_set_peripheral(udc->transceiver->otg,
1840 &udc->gadget); 1824 &udc->gadget);
1841 if (retval) { 1825 if (retval) {
1842 dev_err(udc->dev, "can't bind to transceiver\n"); 1826 dev_err(udc->dev, "can't bind to transceiver\n");
1843 goto transceiver_fail; 1827 goto fail;
1844 } 1828 }
1845 } 1829 }
1846 1830
@@ -1848,12 +1832,7 @@ static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1848 udc_enable(udc); 1832 udc_enable(udc);
1849 return 0; 1833 return 0;
1850 1834
1851transceiver_fail: 1835fail:
1852 if (driver->unbind)
1853 driver->unbind(&udc->gadget);
1854bind_fail:
1855 device_del(&udc->gadget.dev);
1856add_fail:
1857 udc->driver = NULL; 1836 udc->driver = NULL;
1858 udc->gadget.dev.driver = NULL; 1837 udc->gadget.dev.driver = NULL;
1859 return retval; 1838 return retval;
@@ -1878,9 +1857,6 @@ static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver)
1878 1857
1879 for (i = 0; i < NR_USB_ENDPOINTS; i++) 1858 for (i = 0; i < NR_USB_ENDPOINTS; i++)
1880 pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep); 1859 pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep);
1881
1882 if (driver)
1883 driver->disconnect(&udc->gadget);
1884} 1860}
1885 1861
1886/** 1862/**
@@ -1889,25 +1865,18 @@ static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver)
1889 * 1865 *
1890 * Returns 0 if no error, -ENODEV, -EINVAL otherwise 1866 * Returns 0 if no error, -ENODEV, -EINVAL otherwise
1891 */ 1867 */
1892static int pxa27x_udc_stop(struct usb_gadget_driver *driver) 1868static int pxa27x_udc_stop(struct usb_gadget *g,
1869 struct usb_gadget_driver *driver)
1893{ 1870{
1894 struct pxa_udc *udc = the_controller; 1871 struct pxa_udc *udc = to_pxa(g);
1895
1896 if (!udc)
1897 return -ENODEV;
1898 if (!driver || driver != udc->driver || !driver->unbind)
1899 return -EINVAL;
1900 1872
1901 stop_activity(udc, driver); 1873 stop_activity(udc, driver);
1902 udc_disable(udc); 1874 udc_disable(udc);
1903 dplus_pullup(udc, 0); 1875 dplus_pullup(udc, 0);
1904 1876
1905 driver->unbind(&udc->gadget);
1906 udc->driver = NULL; 1877 udc->driver = NULL;
1907 1878
1908 device_del(&udc->gadget.dev); 1879 device_del(&udc->gadget.dev);
1909 dev_info(udc->dev, "unregistered gadget driver '%s'\n",
1910 driver->driver.name);
1911 1880
1912 if (!IS_ERR_OR_NULL(udc->transceiver)) 1881 if (!IS_ERR_OR_NULL(udc->transceiver))
1913 return otg_set_peripheral(udc->transceiver->otg, NULL); 1882 return otg_set_peripheral(udc->transceiver->otg, NULL);
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
index 79d81a4b2344..28f2b53530f5 100644
--- a/drivers/usb/gadget/pxa27x_udc.h
+++ b/drivers/usb/gadget/pxa27x_udc.h
@@ -473,6 +473,7 @@ struct pxa_udc {
473 struct dentry *debugfs_eps; 473 struct dentry *debugfs_eps;
474#endif 474#endif
475}; 475};
476#define to_pxa(g) (container_of((g), struct pxa_udc, gadget))
476 477
477static inline struct pxa_udc *to_gadget_udc(struct usb_gadget *gadget) 478static inline struct pxa_udc *to_gadget_udc(struct usb_gadget *gadget)
478{ 479{
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index 5a80751accb7..234838da6d51 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -1812,7 +1812,7 @@ static int r8a66597_set_selfpowered(struct usb_gadget *gadget, int is_self)
1812 return 0; 1812 return 0;
1813} 1813}
1814 1814
1815static struct usb_gadget_ops r8a66597_gadget_ops = { 1815static const struct usb_gadget_ops r8a66597_gadget_ops = {
1816 .get_frame = r8a66597_get_frame, 1816 .get_frame = r8a66597_get_frame,
1817 .udc_start = r8a66597_start, 1817 .udc_start = r8a66597_start,
1818 .udc_stop = r8a66597_stop, 1818 .udc_stop = r8a66597_stop,
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 439c3f972f8c..e1cd0f1adfb9 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -3055,7 +3055,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)
3055 return 0; 3055 return 0;
3056} 3056}
3057 3057
3058static struct usb_gadget_ops s3c_hsotg_gadget_ops = { 3058static const struct usb_gadget_ops s3c_hsotg_gadget_ops = {
3059 .get_frame = s3c_hsotg_gadget_getframe, 3059 .get_frame = s3c_hsotg_gadget_getframe,
3060 .udc_start = s3c_hsotg_udc_start, 3060 .udc_start = s3c_hsotg_udc_start,
3061 .udc_stop = s3c_hsotg_udc_stop, 3061 .udc_stop = s3c_hsotg_udc_stop,
@@ -3572,7 +3572,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
3572 for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) 3572 for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++)
3573 hsotg->supplies[i].supply = s3c_hsotg_supply_names[i]; 3573 hsotg->supplies[i].supply = s3c_hsotg_supply_names[i];
3574 3574
3575 ret = regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies), 3575 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies),
3576 hsotg->supplies); 3576 hsotg->supplies);
3577 if (ret) { 3577 if (ret) {
3578 dev_err(dev, "failed to request supplies: %d\n", ret); 3578 dev_err(dev, "failed to request supplies: %d\n", ret);
@@ -3662,8 +3662,6 @@ err_ep_mem:
3662 kfree(eps); 3662 kfree(eps);
3663err_supplies: 3663err_supplies:
3664 s3c_hsotg_phy_disable(hsotg); 3664 s3c_hsotg_phy_disable(hsotg);
3665 regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
3666
3667err_clk: 3665err_clk:
3668 clk_disable_unprepare(hsotg->clk); 3666 clk_disable_unprepare(hsotg->clk);
3669 3667
@@ -3688,7 +3686,6 @@ static int s3c_hsotg_remove(struct platform_device *pdev)
3688 } 3686 }
3689 3687
3690 s3c_hsotg_phy_disable(hsotg); 3688 s3c_hsotg_phy_disable(hsotg);
3691 regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies);
3692 3689
3693 clk_disable_unprepare(hsotg->clk); 3690 clk_disable_unprepare(hsotg->clk);
3694 3691
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index 52379b11f080..3ed5a397296f 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -435,7 +435,7 @@ static void s3c_hsudc_epin_intr(struct s3c_hsudc *hsudc, u32 ep_idx)
435 struct s3c_hsudc_req *hsreq; 435 struct s3c_hsudc_req *hsreq;
436 u32 csr; 436 u32 csr;
437 437
438 csr = readl((u32)hsudc->regs + S3C_ESR); 438 csr = readl(hsudc->regs + S3C_ESR);
439 if (csr & S3C_ESR_STALL) { 439 if (csr & S3C_ESR_STALL) {
440 writel(S3C_ESR_STALL, hsudc->regs + S3C_ESR); 440 writel(S3C_ESR_STALL, hsudc->regs + S3C_ESR);
441 return; 441 return;
@@ -468,7 +468,7 @@ static void s3c_hsudc_epout_intr(struct s3c_hsudc *hsudc, u32 ep_idx)
468 struct s3c_hsudc_req *hsreq; 468 struct s3c_hsudc_req *hsreq;
469 u32 csr; 469 u32 csr;
470 470
471 csr = readl((u32)hsudc->regs + S3C_ESR); 471 csr = readl(hsudc->regs + S3C_ESR);
472 if (csr & S3C_ESR_STALL) { 472 if (csr & S3C_ESR_STALL) {
473 writel(S3C_ESR_STALL, hsudc->regs + S3C_ESR); 473 writel(S3C_ESR_STALL, hsudc->regs + S3C_ESR);
474 return; 474 return;
@@ -901,12 +901,12 @@ static int s3c_hsudc_queue(struct usb_ep *_ep, struct usb_request *_req,
901 if (list_empty(&hsep->queue) && !hsep->stopped) { 901 if (list_empty(&hsep->queue) && !hsep->stopped) {
902 offset = (ep_index(hsep)) ? S3C_ESR : S3C_EP0SR; 902 offset = (ep_index(hsep)) ? S3C_ESR : S3C_EP0SR;
903 if (ep_is_in(hsep)) { 903 if (ep_is_in(hsep)) {
904 csr = readl((u32)hsudc->regs + offset); 904 csr = readl(hsudc->regs + offset);
905 if (!(csr & S3C_ESR_TX_SUCCESS) && 905 if (!(csr & S3C_ESR_TX_SUCCESS) &&
906 (s3c_hsudc_write_fifo(hsep, hsreq) == 1)) 906 (s3c_hsudc_write_fifo(hsep, hsreq) == 1))
907 hsreq = NULL; 907 hsreq = NULL;
908 } else { 908 } else {
909 csr = readl((u32)hsudc->regs + offset); 909 csr = readl(hsudc->regs + offset);
910 if ((csr & S3C_ESR_RX_SUCCESS) 910 if ((csr & S3C_ESR_RX_SUCCESS)
911 && (s3c_hsudc_read_fifo(hsep, hsreq) == 1)) 911 && (s3c_hsudc_read_fifo(hsep, hsreq) == 1))
912 hsreq = NULL; 912 hsreq = NULL;
@@ -1254,7 +1254,7 @@ static int s3c_hsudc_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1254 return -EOPNOTSUPP; 1254 return -EOPNOTSUPP;
1255} 1255}
1256 1256
1257static struct usb_gadget_ops s3c_hsudc_gadget_ops = { 1257static const struct usb_gadget_ops s3c_hsudc_gadget_ops = {
1258 .get_frame = s3c_hsudc_gadget_getframe, 1258 .get_frame = s3c_hsudc_gadget_getframe,
1259 .udc_start = s3c_hsudc_start, 1259 .udc_start = s3c_hsudc_start,
1260 .udc_stop = s3c_hsudc_stop, 1260 .udc_stop = s3c_hsudc_stop,
@@ -1286,7 +1286,7 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1286 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++) 1286 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++)
1287 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i]; 1287 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i];
1288 1288
1289 ret = regulator_bulk_get(dev, ARRAY_SIZE(hsudc->supplies), 1289 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsudc->supplies),
1290 hsudc->supplies); 1290 hsudc->supplies);
1291 if (ret != 0) { 1291 if (ret != 0) {
1292 dev_err(dev, "failed to request supplies: %d\n", ret); 1292 dev_err(dev, "failed to request supplies: %d\n", ret);
@@ -1367,7 +1367,6 @@ err_res:
1367 if (!IS_ERR_OR_NULL(hsudc->transceiver)) 1367 if (!IS_ERR_OR_NULL(hsudc->transceiver))
1368 usb_put_phy(hsudc->transceiver); 1368 usb_put_phy(hsudc->transceiver);
1369 1369
1370 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies);
1371err_supplies: 1370err_supplies:
1372 return ret; 1371 return ret;
1373} 1372}
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index a2fa6e16d019..fc07b4381286 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1538,9 +1538,10 @@ static int s3c2410_vbus_draw(struct usb_gadget *_gadget, unsigned ma)
1538 return -ENOTSUPP; 1538 return -ENOTSUPP;
1539} 1539}
1540 1540
1541static int s3c2410_udc_start(struct usb_gadget_driver *driver, 1541static int s3c2410_udc_start(struct usb_gadget *g,
1542 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)); 1542 struct usb_gadget_driver *driver);
1543static int s3c2410_udc_stop(struct usb_gadget_driver *driver); 1543static int s3c2410_udc_stop(struct usb_gadget *g,
1544 struct usb_gadget_driver *driver);
1544 1545
1545static const struct usb_gadget_ops s3c2410_ops = { 1546static const struct usb_gadget_ops s3c2410_ops = {
1546 .get_frame = s3c2410_udc_get_frame, 1547 .get_frame = s3c2410_udc_get_frame,
@@ -1549,8 +1550,8 @@ static const struct usb_gadget_ops s3c2410_ops = {
1549 .pullup = s3c2410_udc_pullup, 1550 .pullup = s3c2410_udc_pullup,
1550 .vbus_session = s3c2410_udc_vbus_session, 1551 .vbus_session = s3c2410_udc_vbus_session,
1551 .vbus_draw = s3c2410_vbus_draw, 1552 .vbus_draw = s3c2410_vbus_draw,
1552 .start = s3c2410_udc_start, 1553 .udc_start = s3c2410_udc_start,
1553 .stop = s3c2410_udc_stop, 1554 .udc_stop = s3c2410_udc_stop,
1554}; 1555};
1555 1556
1556static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) 1557static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd)
@@ -1664,33 +1665,14 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev)
1664 s3c2410_udc_command(S3C2410_UDC_P_ENABLE); 1665 s3c2410_udc_command(S3C2410_UDC_P_ENABLE);
1665} 1666}
1666 1667
1667static int s3c2410_udc_start(struct usb_gadget_driver *driver, 1668static int s3c2410_udc_start(struct usb_gadget *g,
1668 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *)) 1669 struct usb_gadget_driver *driver)
1669{ 1670{
1670 struct s3c2410_udc *udc = the_controller; 1671 struct s3c2410_udc *udc = to_s3c2410(g)
1671 int retval; 1672 int retval;
1672 1673
1673 dprintk(DEBUG_NORMAL, "%s() '%s'\n", __func__, driver->driver.name); 1674 dprintk(DEBUG_NORMAL, "%s() '%s'\n", __func__, driver->driver.name);
1674 1675
1675 /* Sanity checks */
1676 if (!udc)
1677 return -ENODEV;
1678
1679 if (udc->driver)
1680 return -EBUSY;
1681
1682 if (!bind || !driver->setup || driver->max_speed < USB_SPEED_FULL) {
1683 dev_err(&udc->gadget.dev, "Invalid driver: bind %p setup %p speed %d\n",
1684 bind, driver->setup, driver->max_speed);
1685 return -EINVAL;
1686 }
1687#if defined(MODULE)
1688 if (!driver->unbind) {
1689 dev_err(&udc->gadget.dev, "Invalid driver: no unbind method\n");
1690 return -EINVAL;
1691 }
1692#endif
1693
1694 /* Hook the driver */ 1676 /* Hook the driver */
1695 udc->driver = driver; 1677 udc->driver = driver;
1696 udc->gadget.dev.driver = &driver->driver; 1678 udc->gadget.dev.driver = &driver->driver;
@@ -1702,15 +1684,6 @@ static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1702 goto register_error; 1684 goto register_error;
1703 } 1685 }
1704 1686
1705 dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n",
1706 driver->driver.name);
1707
1708 retval = bind(&udc->gadget, driver);
1709 if (retval) {
1710 device_del(&udc->gadget.dev);
1711 goto register_error;
1712 }
1713
1714 /* Enable udc */ 1687 /* Enable udc */
1715 s3c2410_udc_enable(udc); 1688 s3c2410_udc_enable(udc);
1716 1689
@@ -1722,24 +1695,10 @@ register_error:
1722 return retval; 1695 return retval;
1723} 1696}
1724 1697
1725static int s3c2410_udc_stop(struct usb_gadget_driver *driver) 1698static int s3c2410_udc_stop(struct usb_gadget *g,
1699 struct usb_gadget_driver *driver)
1726{ 1700{
1727 struct s3c2410_udc *udc = the_controller; 1701 struct s3c2410_udc *udc = to_s3c2410(g);
1728
1729 if (!udc)
1730 return -ENODEV;
1731
1732 if (!driver || driver != udc->driver || !driver->unbind)
1733 return -EINVAL;
1734
1735 dprintk(DEBUG_NORMAL, "usb_gadget_unregister_driver() '%s'\n",
1736 driver->driver.name);
1737
1738 /* report disconnect */
1739 if (driver->disconnect)
1740 driver->disconnect(&udc->gadget);
1741
1742 driver->unbind(&udc->gadget);
1743 1702
1744 device_del(&udc->gadget.dev); 1703 device_del(&udc->gadget.dev);
1745 udc->driver = NULL; 1704 udc->driver = NULL;
diff --git a/drivers/usb/gadget/s3c2410_udc.h b/drivers/usb/gadget/s3c2410_udc.h
index 3e80fd5c820f..93bf225f1969 100644
--- a/drivers/usb/gadget/s3c2410_udc.h
+++ b/drivers/usb/gadget/s3c2410_udc.h
@@ -95,5 +95,6 @@ struct s3c2410_udc {
95 u8 vbus; 95 u8 vbus;
96 struct dentry *regs_info; 96 struct dentry *regs_info;
97}; 97};
98#define to_s3c2410(g) (container_of((g), struct s3c2410_udc, gadget))
98 99
99#endif 100#endif
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 44752f531e85..68d7bb06ebcb 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -36,10 +36,8 @@
36 * the runtime footprint, and giving us at least some parts of what 36 * the runtime footprint, and giving us at least some parts of what
37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
38 */ 38 */
39#include "f_acm.c"
40#include "f_obex.c" 39#include "f_obex.c"
41#include "f_serial.c" 40#include "f_serial.c"
42#include "u_serial.c"
43 41
44/*-------------------------------------------------------------------------*/ 42/*-------------------------------------------------------------------------*/
45USB_GADGET_COMPOSITE_OPTIONS(); 43USB_GADGET_COMPOSITE_OPTIONS();
@@ -128,20 +126,25 @@ module_param(n_ports, uint, 0);
128MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); 126MODULE_PARM_DESC(n_ports, "number of ports to create, default=1");
129 127
130/*-------------------------------------------------------------------------*/ 128/*-------------------------------------------------------------------------*/
129static unsigned char tty_lines[MAX_U_SERIAL_PORTS];
131 130
132static int __init serial_bind_config(struct usb_configuration *c) 131static int __init serial_bind_obex_config(struct usb_configuration *c)
133{ 132{
134 unsigned i; 133 unsigned i;
135 int status = 0; 134 int status = 0;
136 135
137 for (i = 0; i < n_ports && status == 0; i++) { 136 for (i = 0; i < n_ports && status == 0; i++)
138 if (use_acm) 137 status = obex_bind_config(c, tty_lines[i]);
139 status = acm_bind_config(c, i); 138 return status;
140 else if (use_obex) 139}
141 status = obex_bind_config(c, i); 140
142 else 141static int __init serial_bind_gser_config(struct usb_configuration *c)
143 status = gser_bind_config(c, i); 142{
144 } 143 unsigned i;
144 int status = 0;
145
146 for (i = 0; i < n_ports && status == 0; i++)
147 status = gser_bind_config(c, tty_lines[i]);
145 return status; 148 return status;
146} 149}
147 150
@@ -152,13 +155,70 @@ static struct usb_configuration serial_config_driver = {
152 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 155 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
153}; 156};
154 157
158static struct usb_function_instance *fi_serial[MAX_U_SERIAL_PORTS];
159static struct usb_function *f_serial[MAX_U_SERIAL_PORTS];
160
161static int serial_register_ports(struct usb_composite_dev *cdev,
162 struct usb_configuration *c, const char *f_name)
163{
164 int i;
165 int ret;
166
167 ret = usb_add_config_only(cdev, c);
168 if (ret)
169 goto out;
170
171 for (i = 0; i < n_ports; i++) {
172 struct f_serial_opts *opts;
173
174 fi_serial[i] = usb_get_function_instance(f_name);
175 if (IS_ERR(fi_serial[i])) {
176 ret = PTR_ERR(fi_serial[i]);
177 goto fail;
178 }
179 opts = container_of(fi_serial[i], struct f_serial_opts, func_inst);
180 opts->port_num = tty_lines[i];
181
182 f_serial[i] = usb_get_function(fi_serial[i]);
183 if (IS_ERR(f_serial[i])) {
184 ret = PTR_ERR(f_serial[i]);
185 goto err_get_func;
186 }
187
188 ret = usb_add_function(c, f_serial[i]);
189 if (ret)
190 goto err_add_func;
191 }
192
193 return 0;
194
195err_add_func:
196 usb_put_function(f_serial[i]);
197err_get_func:
198 usb_put_function_instance(fi_serial[i]);
199
200fail:
201 i--;
202 while (i >= 0) {
203 usb_remove_function(c, f_serial[i]);
204 usb_put_function(f_serial[i]);
205 usb_put_function_instance(fi_serial[i]);
206 i--;
207 }
208out:
209 return ret;
210}
211
155static int __init gs_bind(struct usb_composite_dev *cdev) 212static int __init gs_bind(struct usb_composite_dev *cdev)
156{ 213{
157 int status; 214 int status;
215 int cur_line;
158 216
159 status = gserial_setup(cdev->gadget, n_ports); 217 for (cur_line = 0; cur_line < n_ports; cur_line++) {
160 if (status < 0) 218 status = gserial_alloc_line(&tty_lines[cur_line]);
161 return status; 219 if (status)
220 goto fail;
221 }
162 222
163 /* Allocate string descriptor numbers ... note that string 223 /* Allocate string descriptor numbers ... note that string
164 * contents can be overridden by the composite_dev glue. 224 * contents can be overridden by the composite_dev glue.
@@ -178,8 +238,16 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
178 } 238 }
179 239
180 /* register our configuration */ 240 /* register our configuration */
181 status = usb_add_config(cdev, &serial_config_driver, 241 if (use_acm) {
182 serial_bind_config); 242 status = serial_register_ports(cdev, &serial_config_driver,
243 "acm");
244 usb_ep_autoconfig_reset(cdev->gadget);
245 } else if (use_obex)
246 status = usb_add_config(cdev, &serial_config_driver,
247 serial_bind_obex_config);
248 else
249 status = usb_add_config(cdev, &serial_config_driver,
250 serial_bind_gser_config);
183 if (status < 0) 251 if (status < 0)
184 goto fail; 252 goto fail;
185 253
@@ -189,16 +257,31 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
189 return 0; 257 return 0;
190 258
191fail: 259fail:
192 gserial_cleanup(); 260 cur_line--;
261 while (cur_line >= 0)
262 gserial_free_line(tty_lines[cur_line--]);
193 return status; 263 return status;
194} 264}
195 265
266static int gs_unbind(struct usb_composite_dev *cdev)
267{
268 int i;
269
270 for (i = 0; i < n_ports; i++) {
271 usb_put_function(f_serial[i]);
272 usb_put_function_instance(fi_serial[i]);
273 gserial_free_line(tty_lines[i]);
274 }
275 return 0;
276}
277
196static __refdata struct usb_composite_driver gserial_driver = { 278static __refdata struct usb_composite_driver gserial_driver = {
197 .name = "g_serial", 279 .name = "g_serial",
198 .dev = &device_desc, 280 .dev = &device_desc,
199 .strings = dev_strings, 281 .strings = dev_strings,
200 .max_speed = USB_SPEED_SUPER, 282 .max_speed = USB_SPEED_SUPER,
201 .bind = gs_bind, 283 .bind = gs_bind,
284 .unbind = gs_unbind,
202}; 285};
203 286
204static int __init init(void) 287static int __init init(void)
@@ -234,6 +317,5 @@ module_init(init);
234static void __exit cleanup(void) 317static void __exit cleanup(void)
235{ 318{
236 usb_composite_unregister(&gserial_driver); 319 usb_composite_unregister(&gserial_driver);
237 gserial_cleanup();
238} 320}
239module_exit(cleanup); 321module_exit(cleanup);
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 0e3ae43454a2..4ecbf8496f48 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -93,18 +93,6 @@
93 93
94/*-------------------------------------------------------------------------*/ 94/*-------------------------------------------------------------------------*/
95 95
96/* CBI Interrupt data structure */
97struct interrupt_data {
98 u8 bType;
99 u8 bValue;
100};
101
102#define CBI_INTERRUPT_DATA_LEN 2
103
104/* CBI Accept Device-Specific Command request */
105#define USB_CBI_ADSC_REQUEST 0x00
106
107
108/* Length of a SCSI Command Data Block */ 96/* Length of a SCSI Command Data Block */
109#define MAX_COMMAND_SIZE 16 97#define MAX_COMMAND_SIZE 16
110 98
@@ -385,41 +373,6 @@ static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = {
385 /*.bMaxBurst = DYNAMIC, */ 373 /*.bMaxBurst = DYNAMIC, */
386}; 374};
387 375
388static __maybe_unused struct usb_ext_cap_descriptor fsg_ext_cap_desc = {
389 .bLength = USB_DT_USB_EXT_CAP_SIZE,
390 .bDescriptorType = USB_DT_DEVICE_CAPABILITY,
391 .bDevCapabilityType = USB_CAP_TYPE_EXT,
392
393 .bmAttributes = cpu_to_le32(USB_LPM_SUPPORT),
394};
395
396static __maybe_unused struct usb_ss_cap_descriptor fsg_ss_cap_desc = {
397 .bLength = USB_DT_USB_SS_CAP_SIZE,
398 .bDescriptorType = USB_DT_DEVICE_CAPABILITY,
399 .bDevCapabilityType = USB_SS_CAP_TYPE,
400
401 /* .bmAttributes = LTM is not supported yet */
402
403 .wSpeedSupported = cpu_to_le16(USB_LOW_SPEED_OPERATION
404 | USB_FULL_SPEED_OPERATION
405 | USB_HIGH_SPEED_OPERATION
406 | USB_5GBPS_OPERATION),
407 .bFunctionalitySupport = USB_LOW_SPEED_OPERATION,
408 .bU1devExitLat = USB_DEFAULT_U1_DEV_EXIT_LAT,
409 .bU2DevExitLat = cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT),
410};
411
412static __maybe_unused struct usb_bos_descriptor fsg_bos_desc = {
413 .bLength = USB_DT_BOS_SIZE,
414 .bDescriptorType = USB_DT_BOS,
415
416 .wTotalLength = cpu_to_le16(USB_DT_BOS_SIZE
417 + USB_DT_USB_EXT_CAP_SIZE
418 + USB_DT_USB_SS_CAP_SIZE),
419
420 .bNumDeviceCaps = 2,
421};
422
423static struct usb_descriptor_header *fsg_ss_function[] = { 376static struct usb_descriptor_header *fsg_ss_function[] = {
424 (struct usb_descriptor_header *) &fsg_intf_desc, 377 (struct usb_descriptor_header *) &fsg_intf_desc,
425 (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, 378 (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc,
@@ -429,20 +382,6 @@ static struct usb_descriptor_header *fsg_ss_function[] = {
429 NULL, 382 NULL,
430}; 383};
431 384
432/* Maxpacket and other transfer characteristics vary by speed. */
433static __maybe_unused struct usb_endpoint_descriptor *
434fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
435 struct usb_endpoint_descriptor *hs,
436 struct usb_endpoint_descriptor *ss)
437{
438 if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
439 return ss;
440 else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
441 return hs;
442 return fs;
443}
444
445
446/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ 385/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
447static struct usb_string fsg_strings[] = { 386static struct usb_string fsg_strings[] = {
448 {FSG_STRING_INTERFACE, fsg_string_interface}, 387 {FSG_STRING_INTERFACE, fsg_string_interface},
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 598dcc1212f0..588a9be18ef8 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -26,6 +26,7 @@
26#include <linux/tty_flip.h> 26#include <linux/tty_flip.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/export.h> 28#include <linux/export.h>
29#include <linux/module.h>
29 30
30#include "u_serial.h" 31#include "u_serial.h"
31 32
@@ -35,11 +36,12 @@
35 * "serial port" functionality through the USB gadget stack. Each such 36 * "serial port" functionality through the USB gadget stack. Each such
36 * port is exposed through a /dev/ttyGS* node. 37 * port is exposed through a /dev/ttyGS* node.
37 * 38 *
38 * After initialization (gserial_setup), these TTY port devices stay 39 * After this module has been loaded, the individual TTY port can be requested
39 * available until they are removed (gserial_cleanup). Each one may be 40 * (gserial_alloc_line()) and it will stay available until they are removed
40 * connected to a USB function (gserial_connect), or disconnected (with 41 * (gserial_free_line()). Each one may be connected to a USB function
41 * gserial_disconnect) when the USB host issues a config change event. 42 * (gserial_connect), or disconnected (with gserial_disconnect) when the USB
42 * Data can only flow when the port is connected to the host. 43 * host issues a config change event. Data can only flow when the port is
44 * connected to the host.
43 * 45 *
44 * A given TTY port can be made available in multiple configurations. 46 * A given TTY port can be made available in multiple configurations.
45 * For example, each one might expose a ttyGS0 node which provides a 47 * For example, each one might expose a ttyGS0 node which provides a
@@ -119,13 +121,10 @@ struct gs_port {
119 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ 121 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
120}; 122};
121 123
122/* increase N_PORTS if you need more */
123#define N_PORTS 4
124static struct portmaster { 124static struct portmaster {
125 struct mutex lock; /* protect open/close */ 125 struct mutex lock; /* protect open/close */
126 struct gs_port *port; 126 struct gs_port *port;
127} ports[N_PORTS]; 127} ports[MAX_U_SERIAL_PORTS];
128static unsigned n_ports;
129 128
130#define GS_CLOSE_TIMEOUT 15 /* seconds */ 129#define GS_CLOSE_TIMEOUT 15 /* seconds */
131 130
@@ -309,6 +308,7 @@ gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)
309 308
310 return req; 309 return req;
311} 310}
311EXPORT_SYMBOL_GPL(gs_alloc_req);
312 312
313/* 313/*
314 * gs_free_req 314 * gs_free_req
@@ -320,6 +320,7 @@ void gs_free_req(struct usb_ep *ep, struct usb_request *req)
320 kfree(req->buf); 320 kfree(req->buf);
321 usb_ep_free_request(ep, req); 321 usb_ep_free_request(ep, req);
322} 322}
323EXPORT_SYMBOL_GPL(gs_free_req);
323 324
324/* 325/*
325 * gs_send_packet 326 * gs_send_packet
@@ -1030,10 +1031,19 @@ static int
1030gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) 1031gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
1031{ 1032{
1032 struct gs_port *port; 1033 struct gs_port *port;
1034 int ret = 0;
1035
1036 mutex_lock(&ports[port_num].lock);
1037 if (ports[port_num].port) {
1038 ret = -EBUSY;
1039 goto out;
1040 }
1033 1041
1034 port = kzalloc(sizeof(struct gs_port), GFP_KERNEL); 1042 port = kzalloc(sizeof(struct gs_port), GFP_KERNEL);
1035 if (port == NULL) 1043 if (port == NULL) {
1036 return -ENOMEM; 1044 ret = -ENOMEM;
1045 goto out;
1046 }
1037 1047
1038 tty_port_init(&port->port); 1048 tty_port_init(&port->port);
1039 spin_lock_init(&port->port_lock); 1049 spin_lock_init(&port->port_lock);
@@ -1049,109 +1059,9 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
1049 port->port_line_coding = *coding; 1059 port->port_line_coding = *coding;
1050 1060
1051 ports[port_num].port = port; 1061 ports[port_num].port = port;
1052 1062out:
1053 return 0; 1063 mutex_unlock(&ports[port_num].lock);
1054} 1064 return ret;
1055
1056/**
1057 * gserial_setup - initialize TTY driver for one or more ports
1058 * @g: gadget to associate with these ports
1059 * @count: how many ports to support
1060 * Context: may sleep
1061 *
1062 * The TTY stack needs to know in advance how many devices it should
1063 * plan to manage. Use this call to set up the ports you will be
1064 * exporting through USB. Later, connect them to functions based
1065 * on what configuration is activated by the USB host; and disconnect
1066 * them as appropriate.
1067 *
1068 * An example would be a two-configuration device in which both
1069 * configurations expose port 0, but through different functions.
1070 * One configuration could even expose port 1 while the other
1071 * one doesn't.
1072 *
1073 * Returns negative errno or zero.
1074 */
1075int gserial_setup(struct usb_gadget *g, unsigned count)
1076{
1077 unsigned i;
1078 struct usb_cdc_line_coding coding;
1079 int status;
1080
1081 if (count == 0 || count > N_PORTS)
1082 return -EINVAL;
1083
1084 gs_tty_driver = alloc_tty_driver(count);
1085 if (!gs_tty_driver)
1086 return -ENOMEM;
1087
1088 gs_tty_driver->driver_name = "g_serial";
1089 gs_tty_driver->name = PREFIX;
1090 /* uses dynamically assigned dev_t values */
1091
1092 gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1093 gs_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1094 gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1095 gs_tty_driver->init_termios = tty_std_termios;
1096
1097 /* 9600-8-N-1 ... matches defaults expected by "usbser.sys" on
1098 * MS-Windows. Otherwise, most of these flags shouldn't affect
1099 * anything unless we were to actually hook up to a serial line.
1100 */
1101 gs_tty_driver->init_termios.c_cflag =
1102 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1103 gs_tty_driver->init_termios.c_ispeed = 9600;
1104 gs_tty_driver->init_termios.c_ospeed = 9600;
1105
1106 coding.dwDTERate = cpu_to_le32(9600);
1107 coding.bCharFormat = 8;
1108 coding.bParityType = USB_CDC_NO_PARITY;
1109 coding.bDataBits = USB_CDC_1_STOP_BITS;
1110
1111 tty_set_operations(gs_tty_driver, &gs_tty_ops);
1112
1113 /* make devices be openable */
1114 for (i = 0; i < count; i++) {
1115 mutex_init(&ports[i].lock);
1116 status = gs_port_alloc(i, &coding);
1117 if (status) {
1118 count = i;
1119 goto fail;
1120 }
1121 }
1122 n_ports = count;
1123
1124 /* export the driver ... */
1125 status = tty_register_driver(gs_tty_driver);
1126 if (status) {
1127 pr_err("%s: cannot register, err %d\n",
1128 __func__, status);
1129 goto fail;
1130 }
1131
1132 /* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */
1133 for (i = 0; i < count; i++) {
1134 struct device *tty_dev;
1135
1136 tty_dev = tty_port_register_device(&ports[i].port->port,
1137 gs_tty_driver, i, &g->dev);
1138 if (IS_ERR(tty_dev))
1139 pr_warning("%s: no classdev for port %d, err %ld\n",
1140 __func__, i, PTR_ERR(tty_dev));
1141 }
1142
1143 pr_debug("%s: registered %d ttyGS* device%s\n", __func__,
1144 count, (count == 1) ? "" : "s");
1145
1146 return status;
1147fail:
1148 while (count--) {
1149 tty_port_destroy(&ports[count].port->port);
1150 kfree(ports[count].port);
1151 }
1152 put_tty_driver(gs_tty_driver);
1153 gs_tty_driver = NULL;
1154 return status;
1155} 1065}
1156 1066
1157static int gs_closed(struct gs_port *port) 1067static int gs_closed(struct gs_port *port)
@@ -1164,55 +1074,77 @@ static int gs_closed(struct gs_port *port)
1164 return cond; 1074 return cond;
1165} 1075}
1166 1076
1167/** 1077static void gserial_free_port(struct gs_port *port)
1168 * gserial_cleanup - remove TTY-over-USB driver and devices 1078{
1169 * Context: may sleep 1079 tasklet_kill(&port->push);
1170 * 1080 /* wait for old opens to finish */
1171 * This is called to free all resources allocated by @gserial_setup(). 1081 wait_event(port->port.close_wait, gs_closed(port));
1172 * Accordingly, it may need to wait until some open /dev/ files have 1082 WARN_ON(port->port_usb != NULL);
1173 * closed. 1083 tty_port_destroy(&port->port);
1174 * 1084 kfree(port);
1175 * The caller must have issued @gserial_disconnect() for any ports 1085}
1176 * that had previously been connected, so that there is never any 1086
1177 * I/O pending when it's called. 1087void gserial_free_line(unsigned char port_num)
1178 */
1179void gserial_cleanup(void)
1180{ 1088{
1181 unsigned i;
1182 struct gs_port *port; 1089 struct gs_port *port;
1183 1090
1184 if (!gs_tty_driver) 1091 mutex_lock(&ports[port_num].lock);
1092 if (WARN_ON(!ports[port_num].port)) {
1093 mutex_unlock(&ports[port_num].lock);
1185 return; 1094 return;
1095 }
1096 port = ports[port_num].port;
1097 ports[port_num].port = NULL;
1098 mutex_unlock(&ports[port_num].lock);
1186 1099
1187 /* start sysfs and /dev/ttyGS* node removal */ 1100 gserial_free_port(port);
1188 for (i = 0; i < n_ports; i++) 1101 tty_unregister_device(gs_tty_driver, port_num);
1189 tty_unregister_device(gs_tty_driver, i); 1102}
1190 1103EXPORT_SYMBOL_GPL(gserial_free_line);
1191 for (i = 0; i < n_ports; i++) {
1192 /* prevent new opens */
1193 mutex_lock(&ports[i].lock);
1194 port = ports[i].port;
1195 ports[i].port = NULL;
1196 mutex_unlock(&ports[i].lock);
1197
1198 tasklet_kill(&port->push);
1199 1104
1200 /* wait for old opens to finish */ 1105int gserial_alloc_line(unsigned char *line_num)
1201 wait_event(port->port.close_wait, gs_closed(port)); 1106{
1107 struct usb_cdc_line_coding coding;
1108 struct device *tty_dev;
1109 int ret;
1110 int port_num;
1202 1111
1203 WARN_ON(port->port_usb != NULL); 1112 coding.dwDTERate = cpu_to_le32(9600);
1113 coding.bCharFormat = 8;
1114 coding.bParityType = USB_CDC_NO_PARITY;
1115 coding.bDataBits = USB_CDC_1_STOP_BITS;
1204 1116
1205 tty_port_destroy(&port->port); 1117 for (port_num = 0; port_num < MAX_U_SERIAL_PORTS; port_num++) {
1206 kfree(port); 1118 ret = gs_port_alloc(port_num, &coding);
1119 if (ret == -EBUSY)
1120 continue;
1121 if (ret)
1122 return ret;
1123 break;
1207 } 1124 }
1208 n_ports = 0; 1125 if (ret)
1126 return ret;
1209 1127
1210 tty_unregister_driver(gs_tty_driver); 1128 /* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */
1211 put_tty_driver(gs_tty_driver); 1129
1212 gs_tty_driver = NULL; 1130 tty_dev = tty_port_register_device(&ports[port_num].port->port,
1131 gs_tty_driver, port_num, NULL);
1132 if (IS_ERR(tty_dev)) {
1133 struct gs_port *port;
1134 pr_err("%s: failed to register tty for port %d, err %ld\n",
1135 __func__, port_num, PTR_ERR(tty_dev));
1213 1136
1214 pr_debug("%s: cleaned up ttyGS* support\n", __func__); 1137 ret = PTR_ERR(tty_dev);
1138 port = ports[port_num].port;
1139 ports[port_num].port = NULL;
1140 gserial_free_port(port);
1141 goto err;
1142 }
1143 *line_num = port_num;
1144err:
1145 return ret;
1215} 1146}
1147EXPORT_SYMBOL_GPL(gserial_alloc_line);
1216 1148
1217/** 1149/**
1218 * gserial_connect - notify TTY I/O glue that USB link is active 1150 * gserial_connect - notify TTY I/O glue that USB link is active
@@ -1229,8 +1161,8 @@ void gserial_cleanup(void)
1229 * 1161 *
1230 * Caller needs to have set up the endpoints and USB function in @dev 1162 * Caller needs to have set up the endpoints and USB function in @dev
1231 * before calling this, as well as the appropriate (speed-specific) 1163 * before calling this, as well as the appropriate (speed-specific)
1232 * endpoint descriptors, and also have set up the TTY driver by calling 1164 * endpoint descriptors, and also have allocate @port_num by calling
1233 * @gserial_setup(). 1165 * @gserial_alloc_line().
1234 * 1166 *
1235 * Returns negative errno or zero. 1167 * Returns negative errno or zero.
1236 * On success, ep->driver_data will be overwritten. 1168 * On success, ep->driver_data will be overwritten.
@@ -1241,11 +1173,18 @@ int gserial_connect(struct gserial *gser, u8 port_num)
1241 unsigned long flags; 1173 unsigned long flags;
1242 int status; 1174 int status;
1243 1175
1244 if (!gs_tty_driver || port_num >= n_ports) 1176 if (port_num >= MAX_U_SERIAL_PORTS)
1245 return -ENXIO; 1177 return -ENXIO;
1246 1178
1247 /* we "know" gserial_cleanup() hasn't been called */
1248 port = ports[port_num].port; 1179 port = ports[port_num].port;
1180 if (!port) {
1181 pr_err("serial line %d not allocated.\n", port_num);
1182 return -EINVAL;
1183 }
1184 if (port->port_usb) {
1185 pr_err("serial line %d is in use.\n", port_num);
1186 return -EBUSY;
1187 }
1249 1188
1250 /* activate the endpoints */ 1189 /* activate the endpoints */
1251 status = usb_ep_enable(gser->in); 1190 status = usb_ep_enable(gser->in);
@@ -1292,7 +1231,7 @@ fail_out:
1292 gser->in->driver_data = NULL; 1231 gser->in->driver_data = NULL;
1293 return status; 1232 return status;
1294} 1233}
1295 1234EXPORT_SYMBOL_GPL(gserial_connect);
1296/** 1235/**
1297 * gserial_disconnect - notify TTY I/O glue that USB link is inactive 1236 * gserial_disconnect - notify TTY I/O glue that USB link is inactive
1298 * @gser: the function, on which gserial_connect() was called 1237 * @gser: the function, on which gserial_connect() was called
@@ -1347,3 +1286,65 @@ void gserial_disconnect(struct gserial *gser)
1347 1286
1348 spin_unlock_irqrestore(&port->port_lock, flags); 1287 spin_unlock_irqrestore(&port->port_lock, flags);
1349} 1288}
1289EXPORT_SYMBOL_GPL(gserial_disconnect);
1290
1291static int userial_init(void)
1292{
1293 unsigned i;
1294 int status;
1295
1296 gs_tty_driver = alloc_tty_driver(MAX_U_SERIAL_PORTS);
1297 if (!gs_tty_driver)
1298 return -ENOMEM;
1299
1300 gs_tty_driver->driver_name = "g_serial";
1301 gs_tty_driver->name = PREFIX;
1302 /* uses dynamically assigned dev_t values */
1303
1304 gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1305 gs_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1306 gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1307 gs_tty_driver->init_termios = tty_std_termios;
1308
1309 /* 9600-8-N-1 ... matches defaults expected by "usbser.sys" on
1310 * MS-Windows. Otherwise, most of these flags shouldn't affect
1311 * anything unless we were to actually hook up to a serial line.
1312 */
1313 gs_tty_driver->init_termios.c_cflag =
1314 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1315 gs_tty_driver->init_termios.c_ispeed = 9600;
1316 gs_tty_driver->init_termios.c_ospeed = 9600;
1317
1318 tty_set_operations(gs_tty_driver, &gs_tty_ops);
1319 for (i = 0; i < MAX_U_SERIAL_PORTS; i++)
1320 mutex_init(&ports[i].lock);
1321
1322 /* export the driver ... */
1323 status = tty_register_driver(gs_tty_driver);
1324 if (status) {
1325 pr_err("%s: cannot register, err %d\n",
1326 __func__, status);
1327 goto fail;
1328 }
1329
1330 pr_debug("%s: registered %d ttyGS* device%s\n", __func__,
1331 MAX_U_SERIAL_PORTS,
1332 (MAX_U_SERIAL_PORTS == 1) ? "" : "s");
1333
1334 return status;
1335fail:
1336 put_tty_driver(gs_tty_driver);
1337 gs_tty_driver = NULL;
1338 return status;
1339}
1340module_init(userial_init);
1341
1342static void userial_cleanup(void)
1343{
1344 tty_unregister_driver(gs_tty_driver);
1345 put_tty_driver(gs_tty_driver);
1346 gs_tty_driver = NULL;
1347}
1348module_exit(userial_cleanup);
1349
1350MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h
index 9b0fe6450fbf..66ce73a00509 100644
--- a/drivers/usb/gadget/u_serial.h
+++ b/drivers/usb/gadget/u_serial.h
@@ -15,6 +15,13 @@
15#include <linux/usb/composite.h> 15#include <linux/usb/composite.h>
16#include <linux/usb/cdc.h> 16#include <linux/usb/cdc.h>
17 17
18#define MAX_U_SERIAL_PORTS 4
19
20struct f_serial_opts {
21 struct usb_function_instance func_inst;
22 u8 port_num;
23};
24
18/* 25/*
19 * One non-multiplexed "serial" I/O port ... there can be several of these 26 * One non-multiplexed "serial" I/O port ... there can be several of these
20 * on any given USB peripheral device, if it provides enough endpoints. 27 * on any given USB peripheral device, if it provides enough endpoints.
@@ -49,9 +56,9 @@ struct gserial {
49struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags); 56struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags);
50void gs_free_req(struct usb_ep *, struct usb_request *req); 57void gs_free_req(struct usb_ep *, struct usb_request *req);
51 58
52/* port setup/teardown is handled by gadget driver */ 59/* management of individual TTY ports */
53int gserial_setup(struct usb_gadget *g, unsigned n_ports); 60int gserial_alloc_line(unsigned char *port_line);
54void gserial_cleanup(void); 61void gserial_free_line(unsigned char port_line);
55 62
56/* connect/disconnect is handled by individual functions */ 63/* connect/disconnect is handled by individual functions */
57int gserial_connect(struct gserial *, u8 port_num); 64int gserial_connect(struct gserial *, u8 port_num);
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 4d90a800063c..2a9cd369f71c 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -102,28 +102,6 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
102/* ------------------------------------------------------------------------- */ 102/* ------------------------------------------------------------------------- */
103 103
104/** 104/**
105 * usb_gadget_start - tells usb device controller to start up
106 * @gadget: The gadget we want to get started
107 * @driver: The driver we want to bind to @gadget
108 * @bind: The bind function for @driver
109 *
110 * This call is issued by the UDC Class driver when it's about
111 * to register a gadget driver to the device controller, before
112 * calling gadget driver's bind() method.
113 *
114 * It allows the controller to be powered off until strictly
115 * necessary to have it powered on.
116 *
117 * Returns zero on success, else negative errno.
118 */
119static inline int usb_gadget_start(struct usb_gadget *gadget,
120 struct usb_gadget_driver *driver,
121 int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
122{
123 return gadget->ops->start(driver, bind);
124}
125
126/**
127 * usb_gadget_udc_start - tells usb device controller to start up 105 * usb_gadget_udc_start - tells usb device controller to start up
128 * @gadget: The gadget we want to get started 106 * @gadget: The gadget we want to get started
129 * @driver: The driver we want to bind to @gadget 107 * @driver: The driver we want to bind to @gadget
@@ -144,24 +122,6 @@ static inline int usb_gadget_udc_start(struct usb_gadget *gadget,
144} 122}
145 123
146/** 124/**
147 * usb_gadget_stop - tells usb device controller we don't need it anymore
148 * @gadget: The device we want to stop activity
149 * @driver: The driver to unbind from @gadget
150 *
151 * This call is issued by the UDC Class driver after calling
152 * gadget driver's unbind() method.
153 *
154 * The details are implementation specific, but it can go as
155 * far as powering off UDC completely and disable its data
156 * line pullups.
157 */
158static inline void usb_gadget_stop(struct usb_gadget *gadget,
159 struct usb_gadget_driver *driver)
160{
161 gadget->ops->stop(driver);
162}
163
164/**
165 * usb_gadget_udc_stop - tells usb device controller we don't need it anymore 125 * usb_gadget_udc_stop - tells usb device controller we don't need it anymore
166 * @gadget: The device we want to stop activity 126 * @gadget: The device we want to stop activity
167 * @driver: The driver to unbind from @gadget 127 * @driver: The driver to unbind from @gadget
@@ -246,14 +206,6 @@ err1:
246} 206}
247EXPORT_SYMBOL_GPL(usb_add_gadget_udc); 207EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
248 208
249static int udc_is_newstyle(struct usb_udc *udc)
250{
251 if (udc->gadget->ops->udc_start && udc->gadget->ops->udc_stop)
252 return 1;
253 return 0;
254}
255
256
257static void usb_gadget_remove_driver(struct usb_udc *udc) 209static void usb_gadget_remove_driver(struct usb_udc *udc)
258{ 210{
259 dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", 211 dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
@@ -261,14 +213,10 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
261 213
262 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 214 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
263 215
264 if (udc_is_newstyle(udc)) { 216 usb_gadget_disconnect(udc->gadget);
265 usb_gadget_disconnect(udc->gadget); 217 udc->driver->disconnect(udc->gadget);
266 udc->driver->disconnect(udc->gadget); 218 udc->driver->unbind(udc->gadget);
267 udc->driver->unbind(udc->gadget); 219 usb_gadget_udc_stop(udc->gadget, udc->driver);
268 usb_gadget_udc_stop(udc->gadget, udc->driver);
269 } else {
270 usb_gadget_stop(udc->gadget, udc->driver);
271 }
272 220
273 udc->driver = NULL; 221 udc->driver = NULL;
274 udc->dev.driver = NULL; 222 udc->dev.driver = NULL;
@@ -311,6 +259,62 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
311 259
312/* ------------------------------------------------------------------------- */ 260/* ------------------------------------------------------------------------- */
313 261
262static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
263{
264 int ret;
265
266 dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
267 driver->function);
268
269 udc->driver = driver;
270 udc->dev.driver = &driver->driver;
271
272 ret = driver->bind(udc->gadget, driver);
273 if (ret)
274 goto err1;
275 ret = usb_gadget_udc_start(udc->gadget, driver);
276 if (ret) {
277 driver->unbind(udc->gadget);
278 goto err1;
279 }
280 usb_gadget_connect(udc->gadget);
281
282 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
283 return 0;
284err1:
285 dev_err(&udc->dev, "failed to start %s: %d\n",
286 udc->driver->function, ret);
287 udc->driver = NULL;
288 udc->dev.driver = NULL;
289 return ret;
290}
291
292int udc_attach_driver(const char *name, struct usb_gadget_driver *driver)
293{
294 struct usb_udc *udc = NULL;
295 int ret = -ENODEV;
296
297 mutex_lock(&udc_lock);
298 list_for_each_entry(udc, &udc_list, list) {
299 ret = strcmp(name, dev_name(&udc->dev));
300 if (!ret)
301 break;
302 }
303 if (ret) {
304 ret = -ENODEV;
305 goto out;
306 }
307 if (udc->driver) {
308 ret = -EBUSY;
309 goto out;
310 }
311 ret = udc_bind_to_driver(udc, driver);
312out:
313 mutex_unlock(&udc_lock);
314 return ret;
315}
316EXPORT_SYMBOL_GPL(udc_attach_driver);
317
314int usb_gadget_probe_driver(struct usb_gadget_driver *driver) 318int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
315{ 319{
316 struct usb_udc *udc = NULL; 320 struct usb_udc *udc = NULL;
@@ -329,41 +333,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
329 pr_debug("couldn't find an available UDC\n"); 333 pr_debug("couldn't find an available UDC\n");
330 mutex_unlock(&udc_lock); 334 mutex_unlock(&udc_lock);
331 return -ENODEV; 335 return -ENODEV;
332
333found: 336found:
334 dev_dbg(&udc->dev, "registering UDC driver [%s]\n", 337 ret = udc_bind_to_driver(udc, driver);
335 driver->function);
336
337 udc->driver = driver;
338 udc->dev.driver = &driver->driver;
339
340 if (udc_is_newstyle(udc)) {
341 ret = driver->bind(udc->gadget, driver);
342 if (ret)
343 goto err1;
344 ret = usb_gadget_udc_start(udc->gadget, driver);
345 if (ret) {
346 driver->unbind(udc->gadget);
347 goto err1;
348 }
349 usb_gadget_connect(udc->gadget);
350 } else {
351
352 ret = usb_gadget_start(udc->gadget, driver, driver->bind);
353 if (ret)
354 goto err1;
355
356 }
357
358 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
359 mutex_unlock(&udc_lock);
360 return 0;
361
362err1:
363 dev_err(&udc->dev, "failed to start %s: %d\n",
364 udc->driver->function, ret);
365 udc->driver = NULL;
366 udc->dev.driver = NULL;
367 mutex_unlock(&udc_lock); 338 mutex_unlock(&udc_lock);
368 return ret; 339 return ret;
369} 340}
@@ -410,13 +381,11 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
410 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 381 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
411 382
412 if (sysfs_streq(buf, "connect")) { 383 if (sysfs_streq(buf, "connect")) {
413 if (udc_is_newstyle(udc)) 384 usb_gadget_udc_start(udc->gadget, udc->driver);
414 usb_gadget_udc_start(udc->gadget, udc->driver);
415 usb_gadget_connect(udc->gadget); 385 usb_gadget_connect(udc->gadget);
416 } else if (sysfs_streq(buf, "disconnect")) { 386 } else if (sysfs_streq(buf, "disconnect")) {
417 usb_gadget_disconnect(udc->gadget); 387 usb_gadget_disconnect(udc->gadget);
418 if (udc_is_newstyle(udc)) 388 usb_gadget_udc_stop(udc->gadget, udc->driver);
419 usb_gadget_udc_stop(udc->gadget, udc->driver);
420 } else { 389 } else {
421 dev_err(dev, "unsupported command '%s'\n", buf); 390 dev_err(dev, "unsupported command '%s'\n", buf);
422 return -EINVAL; 391 return -EINVAL;
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index 69cf5c2cd335..8cef1e658c29 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -336,7 +336,7 @@ static struct usb_configuration webcam_config_driver = {
336 .bConfigurationValue = 1, 336 .bConfigurationValue = 1,
337 .iConfiguration = 0, /* dynamic */ 337 .iConfiguration = 0, /* dynamic */
338 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 338 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
339 .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, 339 .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW,
340}; 340};
341 341
342static int /* __init_or_exit */ 342static int /* __init_or_exit */
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 6bf4c0611365..685fa681cb65 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -10,7 +10,6 @@
10 * (at your option) any later version. 10 * (at your option) any later version.
11 */ 11 */
12 12
13
14/* 13/*
15 * Gadget Zero only needs two bulk endpoints, and is an example of how you 14 * Gadget Zero only needs two bulk endpoints, and is an example of how you
16 * can write a hardware-agnostic gadget driver running inside a USB device. 15 * can write a hardware-agnostic gadget driver running inside a USB device.
@@ -43,23 +42,11 @@
43#include <linux/kernel.h> 42#include <linux/kernel.h>
44#include <linux/slab.h> 43#include <linux/slab.h>
45#include <linux/device.h> 44#include <linux/device.h>
45#include <linux/module.h>
46#include <linux/err.h>
47#include <linux/usb/composite.h>
46 48
47#include "g_zero.h" 49#include "g_zero.h"
48#include "gadget_chips.h"
49
50
51/*-------------------------------------------------------------------------*/
52
53/*
54 * Kbuild is not very cooperative with respect to linking separately
55 * compiled library objects into one module. So for now we won't use
56 * separate compilation ... ensuring init/exit sections work to shrink
57 * the runtime footprint, and giving us at least some parts of what
58 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
59 */
60#include "f_sourcesink.c"
61#include "f_loopback.c"
62
63/*-------------------------------------------------------------------------*/ 50/*-------------------------------------------------------------------------*/
64USB_GADGET_COMPOSITE_OPTIONS(); 51USB_GADGET_COMPOSITE_OPTIONS();
65 52
@@ -67,9 +54,6 @@ USB_GADGET_COMPOSITE_OPTIONS();
67 54
68static const char longname[] = "Gadget Zero"; 55static const char longname[] = "Gadget Zero";
69 56
70unsigned buflen = 4096; /* only used for bulk endpoints */
71module_param(buflen, uint, 0);
72
73/* 57/*
74 * Normally the "loopback" configuration is second (index 1) so 58 * Normally the "loopback" configuration is second (index 1) so
75 * it's not the default. Here's where to change that order, to 59 * it's not the default. Here's where to change that order, to
@@ -79,6 +63,13 @@ module_param(buflen, uint, 0);
79static bool loopdefault = 0; 63static bool loopdefault = 0;
80module_param(loopdefault, bool, S_IRUGO|S_IWUSR); 64module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
81 65
66static struct usb_zero_options gzero_options = {
67 .isoc_interval = 4,
68 .isoc_maxpacket = 1024,
69 .bulk_buflen = 4096,
70 .qlen = 32,
71};
72
82/*-------------------------------------------------------------------------*/ 73/*-------------------------------------------------------------------------*/
83 74
84/* Thanks to NetChip Technologies for donating this product ID. 75/* Thanks to NetChip Technologies for donating this product ID.
@@ -129,20 +120,27 @@ static struct usb_otg_descriptor otg_descriptor = {
129 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 120 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
130}; 121};
131 122
132const struct usb_descriptor_header *otg_desc[] = { 123static const struct usb_descriptor_header *otg_desc[] = {
133 (struct usb_descriptor_header *) &otg_descriptor, 124 (struct usb_descriptor_header *) &otg_descriptor,
134 NULL, 125 NULL,
135}; 126};
127#else
128#define otg_desc NULL
136#endif 129#endif
137 130
138/* string IDs are assigned dynamically */ 131/* string IDs are assigned dynamically */
139/* default serial number takes at least two packets */ 132/* default serial number takes at least two packets */
140static char serial[] = "0123456789.0123456789.0123456789"; 133static char serial[] = "0123456789.0123456789.0123456789";
141 134
135#define USB_GZERO_SS_DESC (USB_GADGET_FIRST_AVAIL_IDX + 0)
136#define USB_GZERO_LB_DESC (USB_GADGET_FIRST_AVAIL_IDX + 1)
137
142static struct usb_string strings_dev[] = { 138static struct usb_string strings_dev[] = {
143 [USB_GADGET_MANUFACTURER_IDX].s = "", 139 [USB_GADGET_MANUFACTURER_IDX].s = "",
144 [USB_GADGET_PRODUCT_IDX].s = longname, 140 [USB_GADGET_PRODUCT_IDX].s = longname,
145 [USB_GADGET_SERIAL_IDX].s = serial, 141 [USB_GADGET_SERIAL_IDX].s = serial,
142 [USB_GZERO_SS_DESC].s = "source and sink data",
143 [USB_GZERO_LB_DESC].s = "loop input to output",
146 { } /* end of list */ 144 { } /* end of list */
147}; 145};
148 146
@@ -158,58 +156,6 @@ static struct usb_gadget_strings *dev_strings[] = {
158 156
159/*-------------------------------------------------------------------------*/ 157/*-------------------------------------------------------------------------*/
160 158
161struct usb_request *alloc_ep_req(struct usb_ep *ep, int len)
162{
163 struct usb_request *req;
164
165 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
166 if (req) {
167 if (len)
168 req->length = len;
169 else
170 req->length = buflen;
171 req->buf = kmalloc(req->length, GFP_ATOMIC);
172 if (!req->buf) {
173 usb_ep_free_request(ep, req);
174 req = NULL;
175 }
176 }
177 return req;
178}
179
180void free_ep_req(struct usb_ep *ep, struct usb_request *req)
181{
182 kfree(req->buf);
183 usb_ep_free_request(ep, req);
184}
185
186static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
187{
188 int value;
189
190 if (ep->driver_data) {
191 value = usb_ep_disable(ep);
192 if (value < 0)
193 DBG(cdev, "disable %s --> %d\n",
194 ep->name, value);
195 ep->driver_data = NULL;
196 }
197}
198
199void disable_endpoints(struct usb_composite_dev *cdev,
200 struct usb_ep *in, struct usb_ep *out,
201 struct usb_ep *iso_in, struct usb_ep *iso_out)
202{
203 disable_ep(cdev, in);
204 disable_ep(cdev, out);
205 if (iso_in)
206 disable_ep(cdev, iso_in);
207 if (iso_out)
208 disable_ep(cdev, iso_out);
209}
210
211/*-------------------------------------------------------------------------*/
212
213static struct timer_list autoresume_timer; 159static struct timer_list autoresume_timer;
214 160
215static void zero_autoresume(unsigned long _c) 161static void zero_autoresume(unsigned long _c)
@@ -251,8 +197,65 @@ static void zero_resume(struct usb_composite_dev *cdev)
251 197
252/*-------------------------------------------------------------------------*/ 198/*-------------------------------------------------------------------------*/
253 199
200static struct usb_configuration loopback_driver = {
201 .label = "loopback",
202 .bConfigurationValue = 2,
203 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
204 /* .iConfiguration = DYNAMIC */
205};
206
207static struct usb_function *func_ss;
208static struct usb_function_instance *func_inst_ss;
209
210static int ss_config_setup(struct usb_configuration *c,
211 const struct usb_ctrlrequest *ctrl)
212{
213 switch (ctrl->bRequest) {
214 case 0x5b:
215 case 0x5c:
216 return func_ss->setup(func_ss, ctrl);
217 default:
218 return -EOPNOTSUPP;
219 }
220}
221
222static struct usb_configuration sourcesink_driver = {
223 .label = "source/sink",
224 .setup = ss_config_setup,
225 .bConfigurationValue = 3,
226 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
227 /* .iConfiguration = DYNAMIC */
228};
229
230module_param_named(buflen, gzero_options.bulk_buflen, uint, 0);
231module_param_named(pattern, gzero_options.pattern, uint, S_IRUGO|S_IWUSR);
232MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63, 2 = none");
233
234module_param_named(isoc_interval, gzero_options.isoc_interval, uint,
235 S_IRUGO|S_IWUSR);
236MODULE_PARM_DESC(isoc_interval, "1 - 16");
237
238module_param_named(isoc_maxpacket, gzero_options.isoc_maxpacket, uint,
239 S_IRUGO|S_IWUSR);
240MODULE_PARM_DESC(isoc_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)");
241
242module_param_named(isoc_mult, gzero_options.isoc_mult, uint, S_IRUGO|S_IWUSR);
243MODULE_PARM_DESC(isoc_mult, "0 - 2 (hs/ss only)");
244
245module_param_named(isoc_maxburst, gzero_options.isoc_maxburst, uint,
246 S_IRUGO|S_IWUSR);
247MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)");
248
249static struct usb_function *func_lb;
250static struct usb_function_instance *func_inst_lb;
251
252module_param_named(qlen, gzero_options.qlen, uint, S_IRUGO|S_IWUSR);
253MODULE_PARM_DESC(qlen, "depth of loopback queue");
254
254static int __init zero_bind(struct usb_composite_dev *cdev) 255static int __init zero_bind(struct usb_composite_dev *cdev)
255{ 256{
257 struct f_ss_opts *ss_opts;
258 struct f_lb_opts *lb_opts;
256 int status; 259 int status;
257 260
258 /* Allocate string descriptor numbers ... note that string 261 /* Allocate string descriptor numbers ... note that string
@@ -268,27 +271,105 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
268 271
269 setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev); 272 setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
270 273
274 func_inst_ss = usb_get_function_instance("SourceSink");
275 if (IS_ERR(func_inst_ss))
276 return PTR_ERR(func_inst_ss);
277
278 ss_opts = container_of(func_inst_ss, struct f_ss_opts, func_inst);
279 ss_opts->pattern = gzero_options.pattern;
280 ss_opts->isoc_interval = gzero_options.isoc_interval;
281 ss_opts->isoc_maxpacket = gzero_options.isoc_maxpacket;
282 ss_opts->isoc_mult = gzero_options.isoc_mult;
283 ss_opts->isoc_maxburst = gzero_options.isoc_maxpacket;
284 ss_opts->bulk_buflen = gzero_options.bulk_buflen;
285
286 func_ss = usb_get_function(func_inst_ss);
287 if (IS_ERR(func_ss))
288 goto err_put_func_inst_ss;
289
290 func_inst_lb = usb_get_function_instance("Loopback");
291 if (IS_ERR(func_inst_lb))
292 goto err_put_func_ss;
293
294 lb_opts = container_of(func_inst_lb, struct f_lb_opts, func_inst);
295 lb_opts->bulk_buflen = gzero_options.bulk_buflen;
296 lb_opts->qlen = gzero_options.qlen;
297
298 func_lb = usb_get_function(func_inst_lb);
299 if (IS_ERR(func_lb)) {
300 status = PTR_ERR(func_lb);
301 goto err_put_func_inst_lb;
302 }
303
304 sourcesink_driver.iConfiguration = strings_dev[USB_GZERO_SS_DESC].id;
305 loopback_driver.iConfiguration = strings_dev[USB_GZERO_LB_DESC].id;
306
307 /* support autoresume for remote wakeup testing */
308 sourcesink_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP;
309 loopback_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP;
310 sourcesink_driver.descriptors = NULL;
311 loopback_driver.descriptors = NULL;
312 if (autoresume) {
313 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
314 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
315 }
316
317 /* support OTG systems */
318 if (gadget_is_otg(cdev->gadget)) {
319 sourcesink_driver.descriptors = otg_desc;
320 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
321 loopback_driver.descriptors = otg_desc;
322 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
323 }
324
271 /* Register primary, then secondary configuration. Note that 325 /* Register primary, then secondary configuration. Note that
272 * SH3 only allows one config... 326 * SH3 only allows one config...
273 */ 327 */
274 if (loopdefault) { 328 if (loopdefault) {
275 loopback_add(cdev, autoresume != 0); 329 usb_add_config_only(cdev, &loopback_driver);
276 sourcesink_add(cdev, autoresume != 0); 330 usb_add_config_only(cdev, &sourcesink_driver);
277 } else { 331 } else {
278 sourcesink_add(cdev, autoresume != 0); 332 usb_add_config_only(cdev, &sourcesink_driver);
279 loopback_add(cdev, autoresume != 0); 333 usb_add_config_only(cdev, &loopback_driver);
280 } 334 }
335 status = usb_add_function(&sourcesink_driver, func_ss);
336 if (status)
337 goto err_conf_flb;
338
339 usb_ep_autoconfig_reset(cdev->gadget);
340 status = usb_add_function(&loopback_driver, func_lb);
341 if (status)
342 goto err_conf_flb;
281 343
344 usb_ep_autoconfig_reset(cdev->gadget);
282 usb_composite_overwrite_options(cdev, &coverwrite); 345 usb_composite_overwrite_options(cdev, &coverwrite);
283 346
284 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); 347 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
285 348
286 return 0; 349 return 0;
350
351err_conf_flb:
352 usb_put_function(func_lb);
353 func_lb = NULL;
354err_put_func_inst_lb:
355 usb_put_function_instance(func_inst_lb);
356 func_inst_lb = NULL;
357err_put_func_ss:
358 usb_put_function(func_ss);
359 func_ss = NULL;
360err_put_func_inst_ss:
361 usb_put_function_instance(func_inst_ss);
362 func_inst_ss = NULL;
363 return status;
287} 364}
288 365
289static int zero_unbind(struct usb_composite_dev *cdev) 366static int zero_unbind(struct usb_composite_dev *cdev)
290{ 367{
291 del_timer_sync(&autoresume_timer); 368 del_timer_sync(&autoresume_timer);
369 if (!IS_ERR_OR_NULL(func_ss))
370 usb_put_function(func_ss);
371 if (!IS_ERR_OR_NULL(func_lb))
372 usb_put_function(func_lb);
292 return 0; 373 return 0;
293} 374}
294 375
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index 6c56297ea16b..3065809546b1 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -302,7 +302,6 @@ static int mv_ehci_remove(struct platform_device *pdev)
302{ 302{
303 struct ehci_hcd_mv *ehci_mv = platform_get_drvdata(pdev); 303 struct ehci_hcd_mv *ehci_mv = platform_get_drvdata(pdev);
304 struct usb_hcd *hcd = ehci_mv->hcd; 304 struct usb_hcd *hcd = ehci_mv->hcd;
305 int clk_i;
306 305
307 if (hcd->rh_registered) 306 if (hcd->rh_registered)
308 usb_remove_hcd(hcd); 307 usb_remove_hcd(hcd);
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c
index eace975991a8..da2d60c06f15 100644
--- a/drivers/usb/otg/mv_otg.c
+++ b/drivers/usb/otg/mv_otg.c
@@ -662,18 +662,9 @@ static struct attribute_group inputs_attr_group = {
662int mv_otg_remove(struct platform_device *pdev) 662int mv_otg_remove(struct platform_device *pdev)
663{ 663{
664 struct mv_otg *mvotg = platform_get_drvdata(pdev); 664 struct mv_otg *mvotg = platform_get_drvdata(pdev);
665 int clk_i;
666 665
667 sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group); 666 sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group);
668 667
669 if (mvotg->irq)
670 free_irq(mvotg->irq, mvotg);
671
672 if (mvotg->pdata->vbus)
673 free_irq(mvotg->pdata->vbus->irq, mvotg);
674 if (mvotg->pdata->id)
675 free_irq(mvotg->pdata->id->irq, mvotg);
676
677 if (mvotg->qwork) { 668 if (mvotg->qwork) {
678 flush_workqueue(mvotg->qwork); 669 flush_workqueue(mvotg->qwork);
679 destroy_workqueue(mvotg->qwork); 670 destroy_workqueue(mvotg->qwork);
@@ -681,21 +672,9 @@ int mv_otg_remove(struct platform_device *pdev)
681 672
682 mv_otg_disable(mvotg); 673 mv_otg_disable(mvotg);
683 674
684 if (mvotg->cap_regs)
685 iounmap(mvotg->cap_regs);
686
687 if (mvotg->phy_regs)
688 iounmap(mvotg->phy_regs);
689
690 for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++)
691 clk_put(mvotg->clk[clk_i]);
692
693 usb_remove_phy(&mvotg->phy); 675 usb_remove_phy(&mvotg->phy);
694 platform_set_drvdata(pdev, NULL); 676 platform_set_drvdata(pdev, NULL);
695 677
696 kfree(mvotg->phy.otg);
697 kfree(mvotg);
698
699 return 0; 678 return 0;
700} 679}
701 680
@@ -714,17 +693,15 @@ static int mv_otg_probe(struct platform_device *pdev)
714 } 693 }
715 694
716 size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum; 695 size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum;
717 mvotg = kzalloc(size, GFP_KERNEL); 696 mvotg = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
718 if (!mvotg) { 697 if (!mvotg) {
719 dev_err(&pdev->dev, "failed to allocate memory!\n"); 698 dev_err(&pdev->dev, "failed to allocate memory!\n");
720 return -ENOMEM; 699 return -ENOMEM;
721 } 700 }
722 701
723 otg = kzalloc(sizeof *otg, GFP_KERNEL); 702 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
724 if (!otg) { 703 if (!otg)
725 kfree(mvotg);
726 return -ENOMEM; 704 return -ENOMEM;
727 }
728 705
729 platform_set_drvdata(pdev, mvotg); 706 platform_set_drvdata(pdev, mvotg);
730 707
@@ -733,18 +710,18 @@ static int mv_otg_probe(struct platform_device *pdev)
733 710
734 mvotg->clknum = pdata->clknum; 711 mvotg->clknum = pdata->clknum;
735 for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { 712 for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) {
736 mvotg->clk[clk_i] = clk_get(&pdev->dev, pdata->clkname[clk_i]); 713 mvotg->clk[clk_i] = devm_clk_get(&pdev->dev,
714 pdata->clkname[clk_i]);
737 if (IS_ERR(mvotg->clk[clk_i])) { 715 if (IS_ERR(mvotg->clk[clk_i])) {
738 retval = PTR_ERR(mvotg->clk[clk_i]); 716 retval = PTR_ERR(mvotg->clk[clk_i]);
739 goto err_put_clk; 717 return retval;
740 } 718 }
741 } 719 }
742 720
743 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); 721 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue");
744 if (!mvotg->qwork) { 722 if (!mvotg->qwork) {
745 dev_dbg(&pdev->dev, "cannot create workqueue for OTG\n"); 723 dev_dbg(&pdev->dev, "cannot create workqueue for OTG\n");
746 retval = -ENOMEM; 724 return -ENOMEM;
747 goto err_put_clk;
748 } 725 }
749 726
750 INIT_DELAYED_WORK(&mvotg->work, mv_otg_work); 727 INIT_DELAYED_WORK(&mvotg->work, mv_otg_work);
@@ -772,7 +749,7 @@ static int mv_otg_probe(struct platform_device *pdev)
772 goto err_destroy_workqueue; 749 goto err_destroy_workqueue;
773 } 750 }
774 751
775 mvotg->phy_regs = ioremap(r->start, resource_size(r)); 752 mvotg->phy_regs = devm_ioremap(&pdev->dev, r->start, resource_size(r));
776 if (mvotg->phy_regs == NULL) { 753 if (mvotg->phy_regs == NULL) {
777 dev_err(&pdev->dev, "failed to map phy I/O memory\n"); 754 dev_err(&pdev->dev, "failed to map phy I/O memory\n");
778 retval = -EFAULT; 755 retval = -EFAULT;
@@ -784,21 +761,21 @@ static int mv_otg_probe(struct platform_device *pdev)
784 if (r == NULL) { 761 if (r == NULL) {
785 dev_err(&pdev->dev, "no I/O memory resource defined\n"); 762 dev_err(&pdev->dev, "no I/O memory resource defined\n");
786 retval = -ENODEV; 763 retval = -ENODEV;
787 goto err_unmap_phyreg; 764 goto err_destroy_workqueue;
788 } 765 }
789 766
790 mvotg->cap_regs = ioremap(r->start, resource_size(r)); 767 mvotg->cap_regs = devm_ioremap(&pdev->dev, r->start, resource_size(r));
791 if (mvotg->cap_regs == NULL) { 768 if (mvotg->cap_regs == NULL) {
792 dev_err(&pdev->dev, "failed to map I/O memory\n"); 769 dev_err(&pdev->dev, "failed to map I/O memory\n");
793 retval = -EFAULT; 770 retval = -EFAULT;
794 goto err_unmap_phyreg; 771 goto err_destroy_workqueue;
795 } 772 }
796 773
797 /* we will acces controller register, so enable the udc controller */ 774 /* we will acces controller register, so enable the udc controller */
798 retval = mv_otg_enable_internal(mvotg); 775 retval = mv_otg_enable_internal(mvotg);
799 if (retval) { 776 if (retval) {
800 dev_err(&pdev->dev, "mv otg enable error %d\n", retval); 777 dev_err(&pdev->dev, "mv otg enable error %d\n", retval);
801 goto err_unmap_capreg; 778 goto err_destroy_workqueue;
802 } 779 }
803 780
804 mvotg->op_regs = 781 mvotg->op_regs =
@@ -806,9 +783,9 @@ static int mv_otg_probe(struct platform_device *pdev)
806 + (readl(mvotg->cap_regs) & CAPLENGTH_MASK)); 783 + (readl(mvotg->cap_regs) & CAPLENGTH_MASK));
807 784
808 if (pdata->id) { 785 if (pdata->id) {
809 retval = request_threaded_irq(pdata->id->irq, NULL, 786 retval = devm_request_threaded_irq(&pdev->dev, pdata->id->irq,
810 mv_otg_inputs_irq, 787 NULL, mv_otg_inputs_irq,
811 IRQF_ONESHOT, "id", mvotg); 788 IRQF_ONESHOT, "id", mvotg);
812 if (retval) { 789 if (retval) {
813 dev_info(&pdev->dev, 790 dev_info(&pdev->dev,
814 "Failed to request irq for ID\n"); 791 "Failed to request irq for ID\n");
@@ -818,9 +795,9 @@ static int mv_otg_probe(struct platform_device *pdev)
818 795
819 if (pdata->vbus) { 796 if (pdata->vbus) {
820 mvotg->clock_gating = 1; 797 mvotg->clock_gating = 1;
821 retval = request_threaded_irq(pdata->vbus->irq, NULL, 798 retval = devm_request_threaded_irq(&pdev->dev, pdata->vbus->irq,
822 mv_otg_inputs_irq, 799 NULL, mv_otg_inputs_irq,
823 IRQF_ONESHOT, "vbus", mvotg); 800 IRQF_ONESHOT, "vbus", mvotg);
824 if (retval) { 801 if (retval) {
825 dev_info(&pdev->dev, 802 dev_info(&pdev->dev,
826 "Failed to request irq for VBUS, " 803 "Failed to request irq for VBUS, "
@@ -844,7 +821,7 @@ static int mv_otg_probe(struct platform_device *pdev)
844 } 821 }
845 822
846 mvotg->irq = r->start; 823 mvotg->irq = r->start;
847 if (request_irq(mvotg->irq, mv_otg_irq, IRQF_SHARED, 824 if (devm_request_irq(&pdev->dev, mvotg->irq, mv_otg_irq, IRQF_SHARED,
848 driver_name, mvotg)) { 825 driver_name, mvotg)) {
849 dev_err(&pdev->dev, "Request irq %d for OTG failed\n", 826 dev_err(&pdev->dev, "Request irq %d for OTG failed\n",
850 mvotg->irq); 827 mvotg->irq);
@@ -857,14 +834,14 @@ static int mv_otg_probe(struct platform_device *pdev)
857 if (retval < 0) { 834 if (retval < 0) {
858 dev_err(&pdev->dev, "can't register transceiver, %d\n", 835 dev_err(&pdev->dev, "can't register transceiver, %d\n",
859 retval); 836 retval);
860 goto err_free_irq; 837 goto err_disable_clk;
861 } 838 }
862 839
863 retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group); 840 retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group);
864 if (retval < 0) { 841 if (retval < 0) {
865 dev_dbg(&pdev->dev, 842 dev_dbg(&pdev->dev,
866 "Can't register sysfs attr group: %d\n", retval); 843 "Can't register sysfs attr group: %d\n", retval);
867 goto err_set_transceiver; 844 goto err_remove_phy;
868 } 845 }
869 846
870 spin_lock_init(&mvotg->wq_lock); 847 spin_lock_init(&mvotg->wq_lock);
@@ -879,30 +856,15 @@ static int mv_otg_probe(struct platform_device *pdev)
879 856
880 return 0; 857 return 0;
881 858
882err_set_transceiver: 859err_remove_phy:
883 usb_remove_phy(&mvotg->phy); 860 usb_remove_phy(&mvotg->phy);
884err_free_irq:
885 free_irq(mvotg->irq, mvotg);
886err_disable_clk: 861err_disable_clk:
887 if (pdata->vbus)
888 free_irq(pdata->vbus->irq, mvotg);
889 if (pdata->id)
890 free_irq(pdata->id->irq, mvotg);
891 mv_otg_disable_internal(mvotg); 862 mv_otg_disable_internal(mvotg);
892err_unmap_capreg:
893 iounmap(mvotg->cap_regs);
894err_unmap_phyreg:
895 iounmap(mvotg->phy_regs);
896err_destroy_workqueue: 863err_destroy_workqueue:
897 flush_workqueue(mvotg->qwork); 864 flush_workqueue(mvotg->qwork);
898 destroy_workqueue(mvotg->qwork); 865 destroy_workqueue(mvotg->qwork);
899err_put_clk:
900 for (clk_i--; clk_i >= 0; clk_i--)
901 clk_put(mvotg->clk[clk_i]);
902 866
903 platform_set_drvdata(pdev, NULL); 867 platform_set_drvdata(pdev, NULL);
904 kfree(otg);
905 kfree(mvotg);
906 868
907 return retval; 869 return retval;
908} 870}
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index f2985cd88021..78fca978b2d0 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -900,7 +900,7 @@ static int usbhsg_set_selfpowered(struct usb_gadget *gadget, int is_self)
900 return 0; 900 return 0;
901} 901}
902 902
903static struct usb_gadget_ops usbhsg_gadget_ops = { 903static const struct usb_gadget_ops usbhsg_gadget_ops = {
904 .get_frame = usbhsg_get_frame, 904 .get_frame = usbhsg_get_frame,
905 .set_selfpowered = usbhsg_set_selfpowered, 905 .set_selfpowered = usbhsg_set_selfpowered,
906 .udc_start = usbhsg_gadget_start, 906 .udc_start = usbhsg_gadget_start,