aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2011-06-28 09:33:47 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-06-28 14:13:35 -0400
commit0f91349b89f37dfad7b77f7829a105b6a0f526ec (patch)
tree4a2b109d3d736318913d0209a5f4ce89aaad1d24
parent2ccea03a8f7ec93641791f2760d7cdc6cab6205f (diff)
usb: gadget: convert all users to the new udc infrastructure
peripheral drivers are using usb_add_gadget()/usb_del_gadget() to register/unregister to the udc-core. The udc-core will take the first available gadget driver and attach function driver which is calling usb_gadget_register_driver(). This is the same behaviour we have right now. Only dummy_hcd was tested, the others were compiled tested. Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Anton Tikhomirov <av.tikhomirov@samsung.com> Cc: Ben Dooks <ben-linux@fluff.org> Cc: Dan Carpenter <error27@gmail.com> Cc: Darius Augulis <augulis.darius@gmail.com> Cc: Eric Miao <eric.y.miao@gmail.com> Cc: Jingoo Han <jg1.han@samsung.com> Cc: Kukjin Kim <kgene.kim@samsung.com> Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Cc: Li Yang <leoli@freescale.com> Cc: Michael Hennerich <michael.hennerich@analog.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Cc: Nicolas Ferre <nicolas.ferre@atmel.com> Cc: Pavankumar Kondeti <pkondeti@codeaurora.org> Cc: Roy Huang <roy.huang@analog.com> Cc: Russell King <linux@arm.linux.org.uk> Cc: Toshiharu Okada <toshiharu-linux@dsn.okisemi.com> Cc: Xiaochen Shen <xiaochen.shen@intel.com> Cc: Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> Cc: Yuan-Hsin Chen <yhchen@faraday-tech.com> Cc: cxie4 <cxie4@marvell.com> Cc: linux-geode@lists.infradead.org Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/amd5536udc.c18
-rw-r--r--drivers/usb/gadget/at91_udc.c20
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c26
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c43
-rw-r--r--drivers/usb/gadget/dummy_hcd.c31
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c20
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c20
-rw-r--r--drivers/usb/gadget/fusb300_udc.c15
-rw-r--r--drivers/usb/gadget/goku_udc.c19
-rw-r--r--drivers/usb/gadget/imx_udc.c20
-rw-r--r--drivers/usb/gadget/langwell_udc.c20
-rw-r--r--drivers/usb/gadget/m66592-udc.c17
-rw-r--r--drivers/usb/gadget/mv_udc_core.c19
-rw-r--r--drivers/usb/gadget/net2272.c22
-rw-r--r--drivers/usb/gadget/net2280.c18
-rw-r--r--drivers/usb/gadget/omap_udc.c22
-rw-r--r--drivers/usb/gadget/pch_udc.c16
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c19
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c23
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c15
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c19
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c16
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c29
-rw-r--r--drivers/usb/musb/musb_gadget.c23
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c20
26 files changed, 388 insertions, 143 deletions
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 345261738b13..9ba725af4a08 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -3,6 +3,7 @@
3# 3#
4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5 5
6obj-$(CONFIG_USB_GADGET) += udc-core.o
6obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 7obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
7obj-$(CONFIG_USB_NET2272) += net2272.o 8obj-$(CONFIG_USB_NET2272) += net2272.o
8obj-$(CONFIG_USB_NET2280) += net2280.o 9obj-$(CONFIG_USB_NET2280) += net2280.o
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 95e8138cd48f..70f2b376c86d 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1438,10 +1438,15 @@ static int udc_wakeup(struct usb_gadget *gadget)
1438 return 0; 1438 return 0;
1439} 1439}
1440 1440
1441static int amd5536_start(struct usb_gadget_driver *driver,
1442 int (*bind)(struct usb_gadget *));
1443static int amd5536_stop(struct usb_gadget_driver *driver);
1441/* gadget operations */ 1444/* gadget operations */
1442static const struct usb_gadget_ops udc_ops = { 1445static const struct usb_gadget_ops udc_ops = {
1443 .wakeup = udc_wakeup, 1446 .wakeup = udc_wakeup,
1444 .get_frame = udc_get_frame, 1447 .get_frame = udc_get_frame,
1448 .start = amd5536_start,
1449 .stop = amd5536_stop,
1445}; 1450};
1446 1451
1447/* Setups endpoint parameters, adds endpoints to linked list */ 1452/* Setups endpoint parameters, adds endpoints to linked list */
@@ -1955,7 +1960,7 @@ static int setup_ep0(struct udc *dev)
1955} 1960}
1956 1961
1957/* Called by gadget driver to register itself */ 1962/* Called by gadget driver to register itself */
1958int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1963static int amd5536_start(struct usb_gadget_driver *driver,
1959 int (*bind)(struct usb_gadget *)) 1964 int (*bind)(struct usb_gadget *))
1960{ 1965{
1961 struct udc *dev = udc; 1966 struct udc *dev = udc;
@@ -2002,7 +2007,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2002 2007
2003 return 0; 2008 return 0;
2004} 2009}
2005EXPORT_SYMBOL(usb_gadget_probe_driver);
2006 2010
2007/* shutdown requests and disconnect from gadget */ 2011/* shutdown requests and disconnect from gadget */
2008static void 2012static void
@@ -2027,7 +2031,7 @@ __acquires(dev->lock)
2027} 2031}
2028 2032
2029/* Called by gadget driver to unregister itself */ 2033/* Called by gadget driver to unregister itself */
2030int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2034static int amd5536_stop(struct usb_gadget_driver *driver)
2031{ 2035{
2032 struct udc *dev = udc; 2036 struct udc *dev = udc;
2033 unsigned long flags; 2037 unsigned long flags;
@@ -2057,8 +2061,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2057 2061
2058 return 0; 2062 return 0;
2059} 2063}
2060EXPORT_SYMBOL(usb_gadget_unregister_driver);
2061
2062 2064
2063/* Clear pending NAK bits */ 2065/* Clear pending NAK bits */
2064static void udc_process_cnak_queue(struct udc *dev) 2066static void udc_process_cnak_queue(struct udc *dev)
@@ -3134,6 +3136,7 @@ static void udc_pci_remove(struct pci_dev *pdev)
3134 3136
3135 dev = pci_get_drvdata(pdev); 3137 dev = pci_get_drvdata(pdev);
3136 3138
3139 usb_del_gadget_udc(&udc->gadget);
3137 /* gadget driver must not be registered */ 3140 /* gadget driver must not be registered */
3138 BUG_ON(dev->driver != NULL); 3141 BUG_ON(dev->driver != NULL);
3139 3142
@@ -3382,8 +3385,13 @@ static int udc_probe(struct udc *dev)
3382 "driver version: %s(for Geode5536 B1)\n", tmp); 3385 "driver version: %s(for Geode5536 B1)\n", tmp);
3383 udc = dev; 3386 udc = dev;
3384 3387
3388 retval = usb_add_gadget_udc(&udc->pdev->dev, &dev->gadget);
3389 if (retval)
3390 goto finished;
3391
3385 retval = device_register(&dev->gadget.dev); 3392 retval = device_register(&dev->gadget.dev);
3386 if (retval) { 3393 if (retval) {
3394 usb_del_gadget_udc(&dev->gadget);
3387 put_device(&dev->gadget.dev); 3395 put_device(&dev->gadget.dev);
3388 goto finished; 3396 goto finished;
3389 } 3397 }
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index f4690ffcb489..98cbc06c30fd 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -985,12 +985,18 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on)
985 return 0; 985 return 0;
986} 986}
987 987
988static int at91_start(struct usb_gadget_driver *driver,
989 int (*bind)(struct usb_gadget *));
990static int at91_stop(struct usb_gadget_driver *driver);
991
988static const struct usb_gadget_ops at91_udc_ops = { 992static const struct usb_gadget_ops at91_udc_ops = {
989 .get_frame = at91_get_frame, 993 .get_frame = at91_get_frame,
990 .wakeup = at91_wakeup, 994 .wakeup = at91_wakeup,
991 .set_selfpowered = at91_set_selfpowered, 995 .set_selfpowered = at91_set_selfpowered,
992 .vbus_session = at91_vbus_session, 996 .vbus_session = at91_vbus_session,
993 .pullup = at91_pullup, 997 .pullup = at91_pullup,
998 .start = at91_start,
999 .stop = at91_stop,
994 1000
995 /* 1001 /*
996 * VBUS-powered devices may also also want to support bigger 1002 * VBUS-powered devices may also also want to support bigger
@@ -1628,7 +1634,7 @@ static void at91_vbus_timer(unsigned long data)
1628 schedule_work(&udc->vbus_timer_work); 1634 schedule_work(&udc->vbus_timer_work);
1629} 1635}
1630 1636
1631int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1637static int at91_start(struct usb_gadget_driver *driver,
1632 int (*bind)(struct usb_gadget *)) 1638 int (*bind)(struct usb_gadget *))
1633{ 1639{
1634 struct at91_udc *udc = &controller; 1640 struct at91_udc *udc = &controller;
@@ -1672,9 +1678,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1672 DBG("bound to %s\n", driver->driver.name); 1678 DBG("bound to %s\n", driver->driver.name);
1673 return 0; 1679 return 0;
1674} 1680}
1675EXPORT_SYMBOL(usb_gadget_probe_driver);
1676 1681
1677int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 1682static int at91_stop(struct usb_gadget_driver *driver)
1678{ 1683{
1679 struct at91_udc *udc = &controller; 1684 struct at91_udc *udc = &controller;
1680 unsigned long flags; 1685 unsigned long flags;
@@ -1696,7 +1701,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1696 DBG("unbound from %s\n", driver->driver.name); 1701 DBG("unbound from %s\n", driver->driver.name);
1697 return 0; 1702 return 0;
1698} 1703}
1699EXPORT_SYMBOL (usb_gadget_unregister_driver);
1700 1704
1701/*-------------------------------------------------------------------------*/ 1705/*-------------------------------------------------------------------------*/
1702 1706
@@ -1854,13 +1858,18 @@ static int __init at91udc_probe(struct platform_device *pdev)
1854 DBG("no VBUS detection, assuming always-on\n"); 1858 DBG("no VBUS detection, assuming always-on\n");
1855 udc->vbus = 1; 1859 udc->vbus = 1;
1856 } 1860 }
1861 retval = usb_add_gadget_udc(dev, &udc->gadget);
1862 if (retval)
1863 goto fail4;
1857 dev_set_drvdata(dev, udc); 1864 dev_set_drvdata(dev, udc);
1858 device_init_wakeup(dev, 1); 1865 device_init_wakeup(dev, 1);
1859 create_debug_file(udc); 1866 create_debug_file(udc);
1860 1867
1861 INFO("%s version %s\n", driver_name, DRIVER_VERSION); 1868 INFO("%s version %s\n", driver_name, DRIVER_VERSION);
1862 return 0; 1869 return 0;
1863 1870fail4:
1871 if (udc->board.vbus_pin > 0 && !udc->board.vbus_polled)
1872 free_irq(udc->board.vbus_pin, udc);
1864fail3: 1873fail3:
1865 if (udc->board.vbus_pin > 0) 1874 if (udc->board.vbus_pin > 0)
1866 gpio_free(udc->board.vbus_pin); 1875 gpio_free(udc->board.vbus_pin);
@@ -1887,6 +1896,7 @@ static int __exit at91udc_remove(struct platform_device *pdev)
1887 1896
1888 DBG("remove\n"); 1897 DBG("remove\n");
1889 1898
1899 usb_del_gadget_udc(&udc->gadget);
1890 if (udc->driver) 1900 if (udc->driver)
1891 return -EBUSY; 1901 return -EBUSY;
1892 1902
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index db1a659702ba..e6b970a2a29c 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1007,10 +1007,16 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
1007 return 0; 1007 return 0;
1008} 1008}
1009 1009
1010static int atmel_usba_start(struct usb_gadget_driver *driver,
1011 int (*bind)(struct usb_gadget *));
1012static int atmel_usba_stop(struct usb_gadget_driver *driver);
1013
1010static const struct usb_gadget_ops usba_udc_ops = { 1014static const struct usb_gadget_ops usba_udc_ops = {
1011 .get_frame = usba_udc_get_frame, 1015 .get_frame = usba_udc_get_frame,
1012 .wakeup = usba_udc_wakeup, 1016 .wakeup = usba_udc_wakeup,
1013 .set_selfpowered = usba_udc_set_selfpowered, 1017 .set_selfpowered = usba_udc_set_selfpowered,
1018 .start = atmel_usba_start,
1019 .stop = atmel_usba_stop,
1014}; 1020};
1015 1021
1016static struct usb_endpoint_descriptor usba_ep0_desc = { 1022static struct usb_endpoint_descriptor usba_ep0_desc = {
@@ -1789,7 +1795,7 @@ out:
1789 return IRQ_HANDLED; 1795 return IRQ_HANDLED;
1790} 1796}
1791 1797
1792int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1798static int atmel_usba_start(struct usb_gadget_driver *driver,
1793 int (*bind)(struct usb_gadget *)) 1799 int (*bind)(struct usb_gadget *))
1794{ 1800{
1795 struct usba_udc *udc = &the_udc; 1801 struct usba_udc *udc = &the_udc;
@@ -1842,9 +1848,8 @@ err_driver_bind:
1842 udc->gadget.dev.driver = NULL; 1848 udc->gadget.dev.driver = NULL;
1843 return ret; 1849 return ret;
1844} 1850}
1845EXPORT_SYMBOL(usb_gadget_probe_driver);
1846 1851
1847int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1852static int atmel_usba_stop(struct usb_gadget_driver *driver)
1848{ 1853{
1849 struct usba_udc *udc = &the_udc; 1854 struct usba_udc *udc = &the_udc;
1850 unsigned long flags; 1855 unsigned long flags;
@@ -1880,7 +1885,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1880 1885
1881 return 0; 1886 return 0;
1882} 1887}
1883EXPORT_SYMBOL(usb_gadget_unregister_driver);
1884 1888
1885static int __init usba_udc_probe(struct platform_device *pdev) 1889static int __init usba_udc_probe(struct platform_device *pdev)
1886{ 1890{
@@ -2021,12 +2025,24 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2021 } 2025 }
2022 } 2026 }
2023 2027
2028 ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2029 if (ret)
2030 goto err_add_udc;
2031
2024 usba_init_debugfs(udc); 2032 usba_init_debugfs(udc);
2025 for (i = 1; i < pdata->num_ep; i++) 2033 for (i = 1; i < pdata->num_ep; i++)
2026 usba_ep_init_debugfs(udc, &usba_ep[i]); 2034 usba_ep_init_debugfs(udc, &usba_ep[i]);
2027 2035
2028 return 0; 2036 return 0;
2029 2037
2038err_add_udc:
2039 if (gpio_is_valid(pdata->vbus_pin)) {
2040 free_irq(gpio_to_irq(udc->vbus_pin), udc);
2041 gpio_free(udc->vbus_pin);
2042 }
2043
2044 device_unregister(&udc->gadget.dev);
2045
2030err_device_add: 2046err_device_add:
2031 free_irq(irq, udc); 2047 free_irq(irq, udc);
2032err_request_irq: 2048err_request_irq:
@@ -2053,6 +2069,8 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
2053 2069
2054 udc = platform_get_drvdata(pdev); 2070 udc = platform_get_drvdata(pdev);
2055 2071
2072 usb_del_gadget_udc(&udc->gadget);
2073
2056 for (i = 1; i < pdata->num_ep; i++) 2074 for (i = 1; i < pdata->num_ep; i++)
2057 usba_ep_cleanup_debugfs(&usba_ep[i]); 2075 usba_ep_cleanup_debugfs(&usba_ep[i]);
2058 usba_cleanup_debugfs(udc); 2076 usba_cleanup_debugfs(udc);
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index baaf87ed7685..909bc45c0be0 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -857,7 +857,7 @@ static void dbg_print(u8 addr, const char *name, int status, const char *extra)
857 stamp = stamp * 1000000 + tval.tv_usec; 857 stamp = stamp * 1000000 + tval.tv_usec;
858 858
859 scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG, 859 scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG,
860 "%04X\t» %02X %-7.7s %4i «\t%s\n", 860 "%04X\t? %02X %-7.7s %4i ?\t%s\n",
861 stamp, addr, name, status, extra); 861 stamp, addr, name, status, extra);
862 862
863 dbg_inc(&dbg_data.idx); 863 dbg_inc(&dbg_data.idx);
@@ -865,7 +865,7 @@ static void dbg_print(u8 addr, const char *name, int status, const char *extra)
865 write_unlock_irqrestore(&dbg_data.lck, flags); 865 write_unlock_irqrestore(&dbg_data.lck, flags);
866 866
867 if (dbg_data.tty != 0) 867 if (dbg_data.tty != 0)
868 pr_notice("%04X\t» %02X %-7.7s %4i «\t%s\n", 868 pr_notice("%04X\t? %02X %-7.7s %4i ?\t%s\n",
869 stamp, addr, name, status, extra); 869 stamp, addr, name, status, extra);
870} 870}
871 871
@@ -1025,15 +1025,15 @@ static ssize_t show_inters(struct device *dev, struct device_attribute *attr,
1025 1025
1026 n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n", 1026 n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n",
1027 isr_statistics.test); 1027 isr_statistics.test);
1028 n += scnprintf(buf + n, PAGE_SIZE - n, "» ui = %d\n", 1028 n += scnprintf(buf + n, PAGE_SIZE - n, "? ui = %d\n",
1029 isr_statistics.ui); 1029 isr_statistics.ui);
1030 n += scnprintf(buf + n, PAGE_SIZE - n, "» uei = %d\n", 1030 n += scnprintf(buf + n, PAGE_SIZE - n, "? uei = %d\n",
1031 isr_statistics.uei); 1031 isr_statistics.uei);
1032 n += scnprintf(buf + n, PAGE_SIZE - n, "» pci = %d\n", 1032 n += scnprintf(buf + n, PAGE_SIZE - n, "? pci = %d\n",
1033 isr_statistics.pci); 1033 isr_statistics.pci);
1034 n += scnprintf(buf + n, PAGE_SIZE - n, "» uri = %d\n", 1034 n += scnprintf(buf + n, PAGE_SIZE - n, "? uri = %d\n",
1035 isr_statistics.uri); 1035 isr_statistics.uri);
1036 n += scnprintf(buf + n, PAGE_SIZE - n, "» sli = %d\n", 1036 n += scnprintf(buf + n, PAGE_SIZE - n, "? sli = %d\n",
1037 isr_statistics.sli); 1037 isr_statistics.sli);
1038 n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n", 1038 n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n",
1039 isr_statistics.none); 1039 isr_statistics.none);
@@ -2515,6 +2515,9 @@ static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
2515 return -ENOTSUPP; 2515 return -ENOTSUPP;
2516} 2516}
2517 2517
2518static int ci13xxx_start(struct usb_gadget_driver *driver,
2519 int (*bind)(struct usb_gadget *));
2520static int ci13xxx_stop(struct usb_gadget_driver *driver);
2518/** 2521/**
2519 * Device operations part of the API to the USB controller hardware, 2522 * Device operations part of the API to the USB controller hardware,
2520 * which don't involve endpoints (or i/o) 2523 * which don't involve endpoints (or i/o)
@@ -2524,17 +2527,19 @@ static const struct usb_gadget_ops usb_gadget_ops = {
2524 .vbus_session = ci13xxx_vbus_session, 2527 .vbus_session = ci13xxx_vbus_session,
2525 .wakeup = ci13xxx_wakeup, 2528 .wakeup = ci13xxx_wakeup,
2526 .vbus_draw = ci13xxx_vbus_draw, 2529 .vbus_draw = ci13xxx_vbus_draw,
2530 .start = ci13xxx_start,
2531 .stop = ci13xxx_stop,
2527}; 2532};
2528 2533
2529/** 2534/**
2530 * usb_gadget_probe_driver: register a gadget driver 2535 * ci13xxx_start: register a gadget driver
2531 * @driver: the driver being registered 2536 * @driver: the driver being registered
2532 * @bind: the driver's bind callback 2537 * @bind: the driver's bind callback
2533 * 2538 *
2534 * Check usb_gadget_probe_driver() at <linux/usb/gadget.h> for details. 2539 * Check ci13xxx_start() at <linux/usb/gadget.h> for details.
2535 * Interrupts are enabled here. 2540 * Interrupts are enabled here.
2536 */ 2541 */
2537int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2542static int ci13xxx_start(struct usb_gadget_driver *driver,
2538 int (*bind)(struct usb_gadget *)) 2543 int (*bind)(struct usb_gadget *))
2539{ 2544{
2540 struct ci13xxx *udc = _udc; 2545 struct ci13xxx *udc = _udc;
@@ -2657,14 +2662,13 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2657 spin_unlock_irqrestore(udc->lock, flags); 2662 spin_unlock_irqrestore(udc->lock, flags);
2658 return retval; 2663 return retval;
2659} 2664}
2660EXPORT_SYMBOL(usb_gadget_probe_driver);
2661 2665
2662/** 2666/**
2663 * usb_gadget_unregister_driver: unregister a gadget driver 2667 * ci13xxx_stop: unregister a gadget driver
2664 * 2668 *
2665 * Check usb_gadget_unregister_driver() at "usb_gadget.h" for details 2669 * Check usb_gadget_unregister_driver() at "usb_gadget.h" for details
2666 */ 2670 */
2667int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2671static int ci13xxx_stop(struct usb_gadget_driver *driver)
2668{ 2672{
2669 struct ci13xxx *udc = _udc; 2673 struct ci13xxx *udc = _udc;
2670 unsigned long i, flags; 2674 unsigned long i, flags;
@@ -2726,7 +2730,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2726 2730
2727 return 0; 2731 return 0;
2728} 2732}
2729EXPORT_SYMBOL(usb_gadget_unregister_driver);
2730 2733
2731/****************************************************************************** 2734/******************************************************************************
2732 * BUS block 2735 * BUS block
@@ -2901,12 +2904,23 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
2901 if (retval) 2904 if (retval)
2902 goto remove_dbg; 2905 goto remove_dbg;
2903 } 2906 }
2907
2908 retval = usb_add_gadget_udc(dev, &udc->gadget);
2909 if (retval)
2910 goto remove_trans;
2911
2904 pm_runtime_no_callbacks(&udc->gadget.dev); 2912 pm_runtime_no_callbacks(&udc->gadget.dev);
2905 pm_runtime_enable(&udc->gadget.dev); 2913 pm_runtime_enable(&udc->gadget.dev);
2906 2914
2907 _udc = udc; 2915 _udc = udc;
2908 return retval; 2916 return retval;
2909 2917
2918remove_trans:
2919 if (udc->transceiver) {
2920 otg_set_peripheral(udc->transceiver, &udc->gadget);
2921 otg_put_transceiver(udc->transceiver);
2922 }
2923
2910 err("error = %i", retval); 2924 err("error = %i", retval);
2911remove_dbg: 2925remove_dbg:
2912#ifdef CONFIG_USB_GADGET_DEBUG_FILES 2926#ifdef CONFIG_USB_GADGET_DEBUG_FILES
@@ -2936,6 +2950,7 @@ static void udc_remove(void)
2936 err("EINVAL"); 2950 err("EINVAL");
2937 return; 2951 return;
2938 } 2952 }
2953 usb_del_gadget_udc(&udc->gadget);
2939 2954
2940 if (udc->transceiver) { 2955 if (udc->transceiver) {
2941 otg_set_peripheral(udc->transceiver, &udc->gadget); 2956 otg_set_peripheral(udc->transceiver, &udc->gadget);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index d3dcabc1a5fc..d47a565d085c 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -710,11 +710,17 @@ static int dummy_pullup (struct usb_gadget *_gadget, int value)
710 return 0; 710 return 0;
711} 711}
712 712
713static int dummy_udc_start(struct usb_gadget_driver *driver,
714 int (*bind)(struct usb_gadget *));
715static int dummy_udc_stop(struct usb_gadget_driver *driver);
716
713static const struct usb_gadget_ops dummy_ops = { 717static const struct usb_gadget_ops dummy_ops = {
714 .get_frame = dummy_g_get_frame, 718 .get_frame = dummy_g_get_frame,
715 .wakeup = dummy_wakeup, 719 .wakeup = dummy_wakeup,
716 .set_selfpowered = dummy_set_selfpowered, 720 .set_selfpowered = dummy_set_selfpowered,
717 .pullup = dummy_pullup, 721 .pullup = dummy_pullup,
722 .start = dummy_udc_start,
723 .stop = dummy_udc_stop,
718}; 724};
719 725
720/*-------------------------------------------------------------------------*/ 726/*-------------------------------------------------------------------------*/
@@ -747,8 +753,7 @@ static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
747 * for each driver that registers: just add to a big root hub. 753 * for each driver that registers: just add to a big root hub.
748 */ 754 */
749 755
750int 756static int dummy_udc_start(struct usb_gadget_driver *driver,
751usb_gadget_probe_driver(struct usb_gadget_driver *driver,
752 int (*bind)(struct usb_gadget *)) 757 int (*bind)(struct usb_gadget *))
753{ 758{
754 struct dummy *dum = the_controller; 759 struct dummy *dum = the_controller;
@@ -812,10 +817,8 @@ usb_gadget_probe_driver(struct usb_gadget_driver *driver,
812 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 817 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
813 return 0; 818 return 0;
814} 819}
815EXPORT_SYMBOL(usb_gadget_probe_driver);
816 820
817int 821static int dummy_udc_stop(struct usb_gadget_driver *driver)
818usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
819{ 822{
820 struct dummy *dum = the_controller; 823 struct dummy *dum = the_controller;
821 unsigned long flags; 824 unsigned long flags;
@@ -845,7 +848,6 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
845 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 848 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
846 return 0; 849 return 0;
847} 850}
848EXPORT_SYMBOL (usb_gadget_unregister_driver);
849 851
850#undef is_enabled 852#undef is_enabled
851 853
@@ -892,11 +894,20 @@ static int dummy_udc_probe (struct platform_device *pdev)
892 return rc; 894 return rc;
893 } 895 }
894 896
897 rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget);
898 if (rc < 0)
899 goto err_udc;
900
895 rc = device_create_file (&dum->gadget.dev, &dev_attr_function); 901 rc = device_create_file (&dum->gadget.dev, &dev_attr_function);
896 if (rc < 0) 902 if (rc < 0)
897 device_unregister (&dum->gadget.dev); 903 goto err_dev;
898 else 904 platform_set_drvdata(pdev, dum);
899 platform_set_drvdata(pdev, dum); 905 return rc;
906
907err_dev:
908 usb_del_gadget_udc(&dum->gadget);
909err_udc:
910 device_unregister(&dum->gadget.dev);
900 return rc; 911 return rc;
901} 912}
902 913
@@ -904,6 +915,7 @@ static int dummy_udc_remove (struct platform_device *pdev)
904{ 915{
905 struct dummy *dum = platform_get_drvdata (pdev); 916 struct dummy *dum = platform_get_drvdata (pdev);
906 917
918 usb_del_gadget_udc(&dum->gadget);
907 platform_set_drvdata (pdev, NULL); 919 platform_set_drvdata (pdev, NULL);
908 device_remove_file (&dum->gadget.dev, &dev_attr_function); 920 device_remove_file (&dum->gadget.dev, &dev_attr_function);
909 device_unregister (&dum->gadget.dev); 921 device_unregister (&dum->gadget.dev);
@@ -1863,7 +1875,6 @@ static void dummy_stop (struct usb_hcd *hcd)
1863 dum = hcd_to_dummy (hcd); 1875 dum = hcd_to_dummy (hcd);
1864 1876
1865 device_remove_file (dummy_dev(dum), &dev_attr_urbs); 1877 device_remove_file (dummy_dev(dum), &dev_attr_urbs);
1866 usb_gadget_unregister_driver (dum->driver);
1867 dev_info (dummy_dev(dum), "stopped\n"); 1878 dev_info (dummy_dev(dum), "stopped\n");
1868} 1879}
1869 1880
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 3a68e09309f7..3bf872e1ad39 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -1927,6 +1927,10 @@ static int qe_pullup(struct usb_gadget *gadget, int is_on)
1927 return -ENOTSUPP; 1927 return -ENOTSUPP;
1928} 1928}
1929 1929
1930static int fsl_qe_start(struct usb_gadget_driver *driver,
1931 int (*bind)(struct usb_gadget *));
1932static int fsl_qe_stop(struct usb_gadget_driver *driver);
1933
1930/* defined in usb_gadget.h */ 1934/* defined in usb_gadget.h */
1931static struct usb_gadget_ops qe_gadget_ops = { 1935static struct usb_gadget_ops qe_gadget_ops = {
1932 .get_frame = qe_get_frame, 1936 .get_frame = qe_get_frame,
@@ -1935,6 +1939,8 @@ static struct usb_gadget_ops qe_gadget_ops = {
1935 .vbus_session = qe_vbus_session, 1939 .vbus_session = qe_vbus_session,
1936 .vbus_draw = qe_vbus_draw, 1940 .vbus_draw = qe_vbus_draw,
1937 .pullup = qe_pullup, 1941 .pullup = qe_pullup,
1942 .start = fsl_qe_start,
1943 .stop = fsl_qe_stop,
1938}; 1944};
1939 1945
1940/*------------------------------------------------------------------------- 1946/*-------------------------------------------------------------------------
@@ -2320,7 +2326,7 @@ static irqreturn_t qe_udc_irq(int irq, void *_udc)
2320/*------------------------------------------------------------------------- 2326/*-------------------------------------------------------------------------
2321 Gadget driver probe and unregister. 2327 Gadget driver probe and unregister.
2322 --------------------------------------------------------------------------*/ 2328 --------------------------------------------------------------------------*/
2323int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2329static int fsl_qe_start(struct usb_gadget_driver *driver,
2324 int (*bind)(struct usb_gadget *)) 2330 int (*bind)(struct usb_gadget *))
2325{ 2331{
2326 int retval; 2332 int retval;
@@ -2369,9 +2375,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2369 udc_controller->gadget.name, driver->driver.name); 2375 udc_controller->gadget.name, driver->driver.name);
2370 return 0; 2376 return 0;
2371} 2377}
2372EXPORT_SYMBOL(usb_gadget_probe_driver);
2373 2378
2374int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2379static int fsl_qe_stop(struct usb_gadget_driver *driver)
2375{ 2380{
2376 struct qe_ep *loop_ep; 2381 struct qe_ep *loop_ep;
2377 unsigned long flags; 2382 unsigned long flags;
@@ -2411,7 +2416,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2411 driver->driver.name); 2416 driver->driver.name);
2412 return 0; 2417 return 0;
2413} 2418}
2414EXPORT_SYMBOL(usb_gadget_unregister_driver);
2415 2419
2416/* udc structure's alloc and setup, include ep-param alloc */ 2420/* udc structure's alloc and setup, include ep-param alloc */
2417static struct qe_udc __devinit *qe_udc_config(struct platform_device *ofdev) 2421static struct qe_udc __devinit *qe_udc_config(struct platform_device *ofdev)
@@ -2662,11 +2666,17 @@ static int __devinit qe_udc_probe(struct platform_device *ofdev)
2662 if (ret) 2666 if (ret)
2663 goto err6; 2667 goto err6;
2664 2668
2669 ret = usb_add_gadget_udc(&ofdev->dev, &udc_controller->gadget);
2670 if (ret)
2671 goto err7;
2672
2665 dev_info(udc_controller->dev, 2673 dev_info(udc_controller->dev,
2666 "%s USB controller initialized as device\n", 2674 "%s USB controller initialized as device\n",
2667 (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM"); 2675 (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM");
2668 return 0; 2676 return 0;
2669 2677
2678err7:
2679 device_unregister(&udc_controller->gadget.dev);
2670err6: 2680err6:
2671 free_irq(udc_controller->usb_irq, udc_controller); 2681 free_irq(udc_controller->usb_irq, udc_controller);
2672err5: 2682err5:
@@ -2721,6 +2731,8 @@ static int __devexit qe_udc_remove(struct platform_device *ofdev)
2721 if (!udc_controller) 2731 if (!udc_controller)
2722 return -ENODEV; 2732 return -ENODEV;
2723 2733
2734 usb_del_gadget_udc(&udc_controller->gadget);
2735
2724 udc_controller->done = &done; 2736 udc_controller->done = &done;
2725 tasklet_disable(&udc_controller->rx_tasklet); 2737 tasklet_disable(&udc_controller->rx_tasklet);
2726 2738
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 2cd9a60c7f3a..5e3dbed7d003 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1232,6 +1232,9 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
1232 return 0; 1232 return 0;
1233} 1233}
1234 1234
1235static int fsl_start(struct usb_gadget_driver *driver,
1236 int (*bind)(struct usb_gadget *));
1237static int fsl_stop(struct usb_gadget_driver *driver);
1235/* defined in gadget.h */ 1238/* defined in gadget.h */
1236static struct usb_gadget_ops fsl_gadget_ops = { 1239static struct usb_gadget_ops fsl_gadget_ops = {
1237 .get_frame = fsl_get_frame, 1240 .get_frame = fsl_get_frame,
@@ -1240,6 +1243,8 @@ static struct usb_gadget_ops fsl_gadget_ops = {
1240 .vbus_session = fsl_vbus_session, 1243 .vbus_session = fsl_vbus_session,
1241 .vbus_draw = fsl_vbus_draw, 1244 .vbus_draw = fsl_vbus_draw,
1242 .pullup = fsl_pullup, 1245 .pullup = fsl_pullup,
1246 .start = fsl_start,
1247 .stop = fsl_stop,
1243}; 1248};
1244 1249
1245/* Set protocol stall on ep0, protocol stall will automatically be cleared 1250/* Set protocol stall on ep0, protocol stall will automatically be cleared
@@ -1908,7 +1913,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
1908 * Hook to gadget drivers 1913 * Hook to gadget drivers
1909 * Called by initialization code of gadget drivers 1914 * Called by initialization code of gadget drivers
1910*----------------------------------------------------------------*/ 1915*----------------------------------------------------------------*/
1911int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1916static int fsl_start(struct usb_gadget_driver *driver,
1912 int (*bind)(struct usb_gadget *)) 1917 int (*bind)(struct usb_gadget *))
1913{ 1918{
1914 int retval = -ENODEV; 1919 int retval = -ENODEV;
@@ -1976,10 +1981,9 @@ out:
1976 retval); 1981 retval);
1977 return retval; 1982 return retval;
1978} 1983}
1979EXPORT_SYMBOL(usb_gadget_probe_driver);
1980 1984
1981/* Disconnect from gadget driver */ 1985/* Disconnect from gadget driver */
1982int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1986static int fsl_stop(struct usb_gadget_driver *driver)
1983{ 1987{
1984 struct fsl_ep *loop_ep; 1988 struct fsl_ep *loop_ep;
1985 unsigned long flags; 1989 unsigned long flags;
@@ -2022,7 +2026,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2022 driver->driver.name); 2026 driver->driver.name);
2023 return 0; 2027 return 0;
2024} 2028}
2025EXPORT_SYMBOL(usb_gadget_unregister_driver);
2026 2029
2027/*------------------------------------------------------------------------- 2030/*-------------------------------------------------------------------------
2028 PROC File System Support 2031 PROC File System Support
@@ -2578,9 +2581,16 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2578 ret = -ENOMEM; 2581 ret = -ENOMEM;
2579 goto err_unregister; 2582 goto err_unregister;
2580 } 2583 }
2584
2585 ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget);
2586 if (ret)
2587 goto err_del_udc;
2588
2581 create_proc_file(); 2589 create_proc_file();
2582 return 0; 2590 return 0;
2583 2591
2592err_del_udc:
2593 dma_pool_destroy(udc_controller->td_pool);
2584err_unregister: 2594err_unregister:
2585 device_unregister(&udc_controller->gadget.dev); 2595 device_unregister(&udc_controller->gadget.dev);
2586err_free_irq: 2596err_free_irq:
@@ -2612,6 +2622,8 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
2612 2622
2613 if (!udc_controller) 2623 if (!udc_controller)
2614 return -ENODEV; 2624 return -ENODEV;
2625
2626 usb_del_gadget_udc(&udc_controller->gadget);
2615 udc_controller->done = &done; 2627 udc_controller->done = &done;
2616 2628
2617 fsl_udc_clk_release(); 2629 fsl_udc_clk_release();
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index b82a1149145a..06353e7ba1fb 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -1495,7 +1495,7 @@ static void init_controller(struct fusb300 *fusb300)
1495/*------------------------------------------------------------------------*/ 1495/*------------------------------------------------------------------------*/
1496static struct fusb300 *the_controller; 1496static struct fusb300 *the_controller;
1497 1497
1498int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1498static int fusb300_udc_start(struct usb_gadget_driver *driver,
1499 int (*bind)(struct usb_gadget *)) 1499 int (*bind)(struct usb_gadget *))
1500{ 1500{
1501 struct fusb300 *fusb300 = the_controller; 1501 struct fusb300 *fusb300 = the_controller;
@@ -1539,9 +1539,8 @@ error:
1539 1539
1540 return retval; 1540 return retval;
1541} 1541}
1542EXPORT_SYMBOL(usb_gadget_probe_driver);
1543 1542
1544int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1543static int fusb300_udc_stop(struct usb_gadget_driver *driver)
1545{ 1544{
1546 struct fusb300 *fusb300 = the_controller; 1545 struct fusb300 *fusb300 = the_controller;
1547 1546
@@ -1557,7 +1556,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1557 1556
1558 return 0; 1557 return 0;
1559} 1558}
1560EXPORT_SYMBOL(usb_gadget_unregister_driver);
1561/*--------------------------------------------------------------------------*/ 1559/*--------------------------------------------------------------------------*/
1562 1560
1563static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active) 1561static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
@@ -1567,12 +1565,15 @@ static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active)
1567 1565
1568static struct usb_gadget_ops fusb300_gadget_ops = { 1566static struct usb_gadget_ops fusb300_gadget_ops = {
1569 .pullup = fusb300_udc_pullup, 1567 .pullup = fusb300_udc_pullup,
1568 .start = fusb300_udc_start,
1569 .stop = fusb300_udc_stop,
1570}; 1570};
1571 1571
1572static int __exit fusb300_remove(struct platform_device *pdev) 1572static int __exit fusb300_remove(struct platform_device *pdev)
1573{ 1573{
1574 struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev); 1574 struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev);
1575 1575
1576 usb_del_gadget_udc(&fusb300->gadget);
1576 iounmap(fusb300->reg); 1577 iounmap(fusb300->reg);
1577 free_irq(platform_get_irq(pdev, 0), fusb300); 1578 free_irq(platform_get_irq(pdev, 0), fusb300);
1578 1579
@@ -1697,9 +1698,15 @@ static int __init fusb300_probe(struct platform_device *pdev)
1697 goto clean_up3; 1698 goto clean_up3;
1698 1699
1699 init_controller(fusb300); 1700 init_controller(fusb300);
1701 ret = usb_add_gadget_udc(&pdev->dev, &fusb300->gadget);
1702 if (ret)
1703 goto err_add_udc;
1704
1700 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1705 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1701 1706
1702 return 0; 1707 return 0;
1708err_add_udc:
1709 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
1703 1710
1704clean_up3: 1711clean_up3:
1705 free_irq(ires->start, fusb300); 1712 free_irq(ires->start, fusb300);
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index bf6e11c758d5..7f87805cddc4 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -996,8 +996,14 @@ static int goku_get_frame(struct usb_gadget *_gadget)
996 return -EOPNOTSUPP; 996 return -EOPNOTSUPP;
997} 997}
998 998
999static int goku_start(struct usb_gadget_driver *driver,
1000 int (*bind)(struct usb_gadget *));
1001static int goku_stop(struct usb_gadget_driver *driver);
1002
999static const struct usb_gadget_ops goku_ops = { 1003static const struct usb_gadget_ops goku_ops = {
1000 .get_frame = goku_get_frame, 1004 .get_frame = goku_get_frame,
1005 .start = goku_start,
1006 .stop = goku_stop,
1001 // no remote wakeup 1007 // no remote wakeup
1002 // not selfpowered 1008 // not selfpowered
1003}; 1009};
@@ -1344,7 +1350,7 @@ static struct goku_udc *the_controller;
1344 * disconnect is reported. then a host may connect again, or 1350 * disconnect is reported. then a host may connect again, or
1345 * the driver might get unbound. 1351 * the driver might get unbound.
1346 */ 1352 */
1347int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1353static int goku_start(struct usb_gadget_driver *driver,
1348 int (*bind)(struct usb_gadget *)) 1354 int (*bind)(struct usb_gadget *))
1349{ 1355{
1350 struct goku_udc *dev = the_controller; 1356 struct goku_udc *dev = the_controller;
@@ -1382,7 +1388,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1382 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name); 1388 DBG(dev, "registered gadget driver '%s'\n", driver->driver.name);
1383 return 0; 1389 return 0;
1384} 1390}
1385EXPORT_SYMBOL(usb_gadget_probe_driver);
1386 1391
1387static void 1392static void
1388stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) 1393stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
@@ -1408,7 +1413,7 @@ stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
1408 udc_enable(dev); 1413 udc_enable(dev);
1409} 1414}
1410 1415
1411int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1416static int goku_stop(struct usb_gadget_driver *driver)
1412{ 1417{
1413 struct goku_udc *dev = the_controller; 1418 struct goku_udc *dev = the_controller;
1414 unsigned long flags; 1419 unsigned long flags;
@@ -1429,8 +1434,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1429 DBG(dev, "unregistered driver '%s'\n", driver->driver.name); 1434 DBG(dev, "unregistered driver '%s'\n", driver->driver.name);
1430 return 0; 1435 return 0;
1431} 1436}
1432EXPORT_SYMBOL(usb_gadget_unregister_driver);
1433
1434 1437
1435/*-------------------------------------------------------------------------*/ 1438/*-------------------------------------------------------------------------*/
1436 1439
@@ -1730,6 +1733,8 @@ static void goku_remove(struct pci_dev *pdev)
1730 1733
1731 DBG(dev, "%s\n", __func__); 1734 DBG(dev, "%s\n", __func__);
1732 1735
1736 usb_del_gadget_udc(&dev->gadget);
1737
1733 BUG_ON(dev->driver); 1738 BUG_ON(dev->driver);
1734 1739
1735#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1740#ifdef CONFIG_USB_GADGET_DEBUG_FILES
@@ -1854,6 +1859,10 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1854 goto err; 1859 goto err;
1855 } 1860 }
1856 dev->registered = 1; 1861 dev->registered = 1;
1862 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
1863 if (retval)
1864 goto err;
1865
1857 return 0; 1866 return 0;
1858 1867
1859err: 1868err:
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index ade40066decf..692fd9b2248b 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1237,9 +1237,14 @@ irq_handler_t intr_handler(int i)
1237 ******************************************************************************* 1237 *******************************************************************************
1238 */ 1238 */
1239 1239
1240static int imx_udc_start(struct usb_gadget_driver *driver,
1241 int (*bind)(struct usb_gadget *));
1242static int imx_udc_stop(struct usb_gadget_driver *driver);
1240static const struct usb_gadget_ops imx_udc_ops = { 1243static const struct usb_gadget_ops imx_udc_ops = {
1241 .get_frame = imx_udc_get_frame, 1244 .get_frame = imx_udc_get_frame,
1242 .wakeup = imx_udc_wakeup, 1245 .wakeup = imx_udc_wakeup,
1246 .start = imx_udc_start,
1247 .stop = imx_udc_stop,
1243}; 1248};
1244 1249
1245static struct imx_udc_struct controller = { 1250static struct imx_udc_struct controller = {
@@ -1324,7 +1329,7 @@ static struct imx_udc_struct controller = {
1324 * USB gadget driver functions 1329 * USB gadget driver functions
1325 ******************************************************************************* 1330 *******************************************************************************
1326 */ 1331 */
1327int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1332static int imx_udc_start(struct usb_gadget_driver *driver,
1328 int (*bind)(struct usb_gadget *)) 1333 int (*bind)(struct usb_gadget *))
1329{ 1334{
1330 struct imx_udc_struct *imx_usb = &controller; 1335 struct imx_udc_struct *imx_usb = &controller;
@@ -1368,9 +1373,8 @@ fail:
1368 imx_usb->gadget.dev.driver = NULL; 1373 imx_usb->gadget.dev.driver = NULL;
1369 return retval; 1374 return retval;
1370} 1375}
1371EXPORT_SYMBOL(usb_gadget_probe_driver);
1372 1376
1373int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1377static int imx_udc_stop(struct usb_gadget_driver *driver)
1374{ 1378{
1375 struct imx_udc_struct *imx_usb = &controller; 1379 struct imx_udc_struct *imx_usb = &controller;
1376 1380
@@ -1394,7 +1398,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1394 1398
1395 return 0; 1399 return 0;
1396} 1400}
1397EXPORT_SYMBOL(usb_gadget_unregister_driver);
1398 1401
1399/******************************************************************************* 1402/*******************************************************************************
1400 * Module functions 1403 * Module functions
@@ -1504,8 +1507,14 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1504 imx_usb->timer.function = handle_config; 1507 imx_usb->timer.function = handle_config;
1505 imx_usb->timer.data = (unsigned long)imx_usb; 1508 imx_usb->timer.data = (unsigned long)imx_usb;
1506 1509
1507 return 0; 1510 ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget);
1511 if (ret)
1512 goto fail4;
1508 1513
1514 return 0;
1515fail4:
1516 for (i = 0; i < IMX_USB_NB_EP + 1; i++)
1517 free_irq(imx_usb->usbd_int[i], imx_usb);
1509fail3: 1518fail3:
1510 clk_put(clk); 1519 clk_put(clk);
1511 clk_disable(clk); 1520 clk_disable(clk);
@@ -1525,6 +1534,7 @@ static int __exit imx_udc_remove(struct platform_device *pdev)
1525 struct imxusb_platform_data *pdata = pdev->dev.platform_data; 1534 struct imxusb_platform_data *pdata = pdev->dev.platform_data;
1526 int i; 1535 int i;
1527 1536
1537 usb_del_gadget_udc(&imx_usb->gadget);
1528 imx_udc_disable(imx_usb); 1538 imx_udc_disable(imx_usb);
1529 del_timer(&imx_usb->timer); 1539 del_timer(&imx_usb->timer);
1530 1540
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index 9cee88a43a73..d8403ae3c2b3 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -1321,7 +1321,9 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on)
1321 return 0; 1321 return 0;
1322} 1322}
1323 1323
1324 1324static int langwell_start(struct usb_gadget_driver *driver,
1325 int (*bind)(struct usb_gadget *));
1326static int langwell_stop(struct usb_gadget_driver *driver);
1325/* device controller usb_gadget_ops structure */ 1327/* device controller usb_gadget_ops structure */
1326static const struct usb_gadget_ops langwell_ops = { 1328static const struct usb_gadget_ops langwell_ops = {
1327 1329
@@ -1342,6 +1344,9 @@ static const struct usb_gadget_ops langwell_ops = {
1342 1344
1343 /* D+ pullup, software-controlled connect/disconnect to USB host */ 1345 /* D+ pullup, software-controlled connect/disconnect to USB host */
1344 .pullup = langwell_pullup, 1346 .pullup = langwell_pullup,
1347
1348 .start = langwell_start,
1349 .stop = langwell_stop,
1345}; 1350};
1346 1351
1347 1352
@@ -1852,7 +1857,7 @@ static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup);
1852 * the driver might get unbound. 1857 * the driver might get unbound.
1853 */ 1858 */
1854 1859
1855int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1860static int langwell_start(struct usb_gadget_driver *driver,
1856 int (*bind)(struct usb_gadget *)) 1861 int (*bind)(struct usb_gadget *))
1857{ 1862{
1858 struct langwell_udc *dev = the_controller; 1863 struct langwell_udc *dev = the_controller;
@@ -1914,11 +1919,9 @@ err_unbind:
1914 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); 1919 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1915 return retval; 1920 return retval;
1916} 1921}
1917EXPORT_SYMBOL(usb_gadget_probe_driver);
1918
1919 1922
1920/* unregister gadget driver */ 1923/* unregister gadget driver */
1921int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1924static int langwell_stop(struct usb_gadget_driver *driver)
1922{ 1925{
1923 struct langwell_udc *dev = the_controller; 1926 struct langwell_udc *dev = the_controller;
1924 unsigned long flags; 1927 unsigned long flags;
@@ -1965,8 +1968,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1965 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); 1968 dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
1966 return 0; 1969 return 0;
1967} 1970}
1968EXPORT_SYMBOL(usb_gadget_unregister_driver);
1969
1970 1971
1971/*-------------------------------------------------------------------------*/ 1972/*-------------------------------------------------------------------------*/
1972 1973
@@ -3373,6 +3374,10 @@ static int langwell_udc_probe(struct pci_dev *pdev,
3373 if (retval) 3374 if (retval)
3374 goto error; 3375 goto error;
3375 3376
3377 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
3378 if (retval)
3379 goto error;
3380
3376 retval = device_create_file(&pdev->dev, &dev_attr_langwell_udc); 3381 retval = device_create_file(&pdev->dev, &dev_attr_langwell_udc);
3377 if (retval) 3382 if (retval)
3378 goto error; 3383 goto error;
@@ -3403,6 +3408,7 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state)
3403 3408
3404 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); 3409 dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
3405 3410
3411 usb_del_gadget_udc(&dev->gadget);
3406 /* disable interrupt and set controller to stop state */ 3412 /* disable interrupt and set controller to stop state */
3407 langwell_udc_stop(dev); 3413 langwell_udc_stop(dev);
3408 3414
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 084aa080a2d5..11d37821ce7a 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1454,7 +1454,7 @@ static struct usb_ep_ops m66592_ep_ops = {
1454/*-------------------------------------------------------------------------*/ 1454/*-------------------------------------------------------------------------*/
1455static struct m66592 *the_controller; 1455static struct m66592 *the_controller;
1456 1456
1457int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1457static int m66592_start(struct usb_gadget_driver *driver,
1458 int (*bind)(struct usb_gadget *)) 1458 int (*bind)(struct usb_gadget *))
1459{ 1459{
1460 struct m66592 *m66592 = the_controller; 1460 struct m66592 *m66592 = the_controller;
@@ -1506,9 +1506,8 @@ error:
1506 1506
1507 return retval; 1507 return retval;
1508} 1508}
1509EXPORT_SYMBOL(usb_gadget_probe_driver);
1510 1509
1511int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1510static int m66592_stop(struct usb_gadget_driver *driver)
1512{ 1511{
1513 struct m66592 *m66592 = the_controller; 1512 struct m66592 *m66592 = the_controller;
1514 unsigned long flags; 1513 unsigned long flags;
@@ -1533,7 +1532,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1533 m66592->driver = NULL; 1532 m66592->driver = NULL;
1534 return 0; 1533 return 0;
1535} 1534}
1536EXPORT_SYMBOL(usb_gadget_unregister_driver);
1537 1535
1538/*-------------------------------------------------------------------------*/ 1536/*-------------------------------------------------------------------------*/
1539static int m66592_get_frame(struct usb_gadget *_gadget) 1537static int m66592_get_frame(struct usb_gadget *_gadget)
@@ -1544,12 +1542,16 @@ static int m66592_get_frame(struct usb_gadget *_gadget)
1544 1542
1545static struct usb_gadget_ops m66592_gadget_ops = { 1543static struct usb_gadget_ops m66592_gadget_ops = {
1546 .get_frame = m66592_get_frame, 1544 .get_frame = m66592_get_frame,
1545 .start = m66592_start,
1546 .stop = m66592_stop,
1547}; 1547};
1548 1548
1549static int __exit m66592_remove(struct platform_device *pdev) 1549static int __exit m66592_remove(struct platform_device *pdev)
1550{ 1550{
1551 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); 1551 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev);
1552 1552
1553 usb_del_gadget_udc(&m66592->gadget);
1554
1553 del_timer_sync(&m66592->timer); 1555 del_timer_sync(&m66592->timer);
1554 iounmap(m66592->reg); 1556 iounmap(m66592->reg);
1555 free_irq(platform_get_irq(pdev, 0), m66592); 1557 free_irq(platform_get_irq(pdev, 0), m66592);
@@ -1691,9 +1693,16 @@ static int __init m66592_probe(struct platform_device *pdev)
1691 1693
1692 init_controller(m66592); 1694 init_controller(m66592);
1693 1695
1696 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget);
1697 if (ret)
1698 goto err_add_udc;
1699
1694 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1700 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1695 return 0; 1701 return 0;
1696 1702
1703err_add_udc:
1704 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1705
1697clean_up3: 1706clean_up3:
1698#ifdef CONFIG_HAVE_CLK 1707#ifdef CONFIG_HAVE_CLK
1699 if (m66592->pdata->on_chip) { 1708 if (m66592->pdata->on_chip) {
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index b1a8146b9d50..6adf38c5353f 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -1128,6 +1128,9 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on)
1128 return 0; 1128 return 0;
1129} 1129}
1130 1130
1131static int mv_udc_start(struct usb_gadget_driver *driver,
1132 int (*bind)(struct usb_gadget *));
1133static int mv_udc_stop(struct usb_gadget_driver *driver);
1131/* device controller usb_gadget_ops structure */ 1134/* device controller usb_gadget_ops structure */
1132static const struct usb_gadget_ops mv_ops = { 1135static const struct usb_gadget_ops mv_ops = {
1133 1136
@@ -1139,6 +1142,8 @@ static const struct usb_gadget_ops mv_ops = {
1139 1142
1140 /* D+ pullup, software-controlled connect/disconnect to USB host */ 1143 /* D+ pullup, software-controlled connect/disconnect to USB host */
1141 .pullup = mv_udc_pullup, 1144 .pullup = mv_udc_pullup,
1145 .start = mv_udc_start,
1146 .stop = mv_udc_stop,
1142}; 1147};
1143 1148
1144static void mv_udc_testmode(struct mv_udc *udc, u16 index, bool enter) 1149static void mv_udc_testmode(struct mv_udc *udc, u16 index, bool enter)
@@ -1230,7 +1235,7 @@ static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver)
1230 } 1235 }
1231} 1236}
1232 1237
1233int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1238static int mv_udc_start(struct usb_gadget_driver *driver,
1234 int (*bind)(struct usb_gadget *)) 1239 int (*bind)(struct usb_gadget *))
1235{ 1240{
1236 struct mv_udc *udc = the_controller; 1241 struct mv_udc *udc = the_controller;
@@ -1270,9 +1275,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1270 1275
1271 return 0; 1276 return 0;
1272} 1277}
1273EXPORT_SYMBOL(usb_gadget_probe_driver);
1274 1278
1275int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1279static int mv_udc_stop(struct usb_gadget_driver *driver)
1276{ 1280{
1277 struct mv_udc *udc = the_controller; 1281 struct mv_udc *udc = the_controller;
1278 unsigned long flags; 1282 unsigned long flags;
@@ -1296,7 +1300,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1296 1300
1297 return 0; 1301 return 0;
1298} 1302}
1299EXPORT_SYMBOL(usb_gadget_unregister_driver);
1300 1303
1301static int 1304static int
1302udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) 1305udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty)
@@ -1880,9 +1883,10 @@ static void gadget_release(struct device *_dev)
1880static int mv_udc_remove(struct platform_device *dev) 1883static int mv_udc_remove(struct platform_device *dev)
1881{ 1884{
1882 struct mv_udc *udc = the_controller; 1885 struct mv_udc *udc = the_controller;
1883
1884 DECLARE_COMPLETION(done); 1886 DECLARE_COMPLETION(done);
1885 1887
1888 usb_del_gadget_udc(&udc->gadget);
1889
1886 udc->done = &done; 1890 udc->done = &done;
1887 1891
1888 /* free memory allocated in probe */ 1892 /* free memory allocated in probe */
@@ -2074,11 +2078,12 @@ int mv_udc_probe(struct platform_device *dev)
2074 2078
2075 the_controller = udc; 2079 the_controller = udc;
2076 2080
2077 goto out; 2081 retval = usb_add_gadget_udc(&dev->dev, &udc->gadget);
2082 if (!retval)
2083 return retval;
2078error: 2084error:
2079 if (udc) 2085 if (udc)
2080 mv_udc_remove(udc->dev); 2086 mv_udc_remove(udc->dev);
2081out:
2082 return retval; 2087 return retval;
2083} 2088}
2084 2089
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c
index 29151c44f476..7f1219e239a3 100644
--- a/drivers/usb/gadget/net2272.c
+++ b/drivers/usb/gadget/net2272.c
@@ -1172,11 +1172,17 @@ net2272_pullup(struct usb_gadget *_gadget, int is_on)
1172 return 0; 1172 return 0;
1173} 1173}
1174 1174
1175static int net2272_start(struct usb_gadget_driver *driver,
1176 int (*bind)(struct usb_gadget *));
1177static int net2272_stop(struct usb_gadget_driver *driver);
1178
1175static const struct usb_gadget_ops net2272_ops = { 1179static const struct usb_gadget_ops net2272_ops = {
1176 .get_frame = net2272_get_frame, 1180 .get_frame = net2272_get_frame,
1177 .wakeup = net2272_wakeup, 1181 .wakeup = net2272_wakeup,
1178 .set_selfpowered = net2272_set_selfpowered, 1182 .set_selfpowered = net2272_set_selfpowered,
1179 .pullup = net2272_pullup 1183 .pullup = net2272_pullup,
1184 .start = net2272_start,
1185 .stop = net2272_stop,
1180}; 1186};
1181 1187
1182/*---------------------------------------------------------------------------*/ 1188/*---------------------------------------------------------------------------*/
@@ -1447,7 +1453,7 @@ net2272_ep0_start(struct net2272 *dev)
1447 * disconnect is reported. then a host may connect again, or 1453 * disconnect is reported. then a host may connect again, or
1448 * the driver might get unbound. 1454 * the driver might get unbound.
1449 */ 1455 */
1450int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1456static int net2272_start(struct usb_gadget_driver *driver,
1451 int (*bind)(struct usb_gadget *)) 1457 int (*bind)(struct usb_gadget *))
1452{ 1458{
1453 struct net2272 *dev = the_controller; 1459 struct net2272 *dev = the_controller;
@@ -1487,7 +1493,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1487 1493
1488 return 0; 1494 return 0;
1489} 1495}
1490EXPORT_SYMBOL(usb_gadget_probe_driver);
1491 1496
1492static void 1497static void
1493stop_activity(struct net2272 *dev, struct usb_gadget_driver *driver) 1498stop_activity(struct net2272 *dev, struct usb_gadget_driver *driver)
@@ -1515,7 +1520,7 @@ stop_activity(struct net2272 *dev, struct usb_gadget_driver *driver)
1515 net2272_usb_reinit(dev); 1520 net2272_usb_reinit(dev);
1516} 1521}
1517 1522
1518int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1523static int net2272_stop(struct usb_gadget_driver *driver)
1519{ 1524{
1520 struct net2272 *dev = the_controller; 1525 struct net2272 *dev = the_controller;
1521 unsigned long flags; 1526 unsigned long flags;
@@ -1538,7 +1543,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1538 dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name); 1543 dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name);
1539 return 0; 1544 return 0;
1540} 1545}
1541EXPORT_SYMBOL(usb_gadget_unregister_driver);
1542 1546
1543/*---------------------------------------------------------------------------*/ 1547/*---------------------------------------------------------------------------*/
1544/* handle ep-a/ep-b dma completions */ 1548/* handle ep-a/ep-b dma completions */
@@ -2217,6 +2221,8 @@ net2272_gadget_release(struct device *_dev)
2217static void __devexit 2221static void __devexit
2218net2272_remove(struct net2272 *dev) 2222net2272_remove(struct net2272 *dev)
2219{ 2223{
2224 usb_del_gadget_udc(&dev->gadget);
2225
2220 /* start with the driver above us */ 2226 /* start with the driver above us */
2221 if (dev->driver) { 2227 if (dev->driver) {
2222 /* should have been done already by driver model core */ 2228 /* should have been done already by driver model core */
@@ -2310,8 +2316,14 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags)
2310 if (ret) 2316 if (ret)
2311 goto err_dev_reg; 2317 goto err_dev_reg;
2312 2318
2319 ret = usb_add_gadget_udc(dev->dev, &dev->gadget);
2320 if (ret)
2321 goto err_add_udc;
2322
2313 return 0; 2323 return 0;
2314 2324
2325err_add_udc:
2326 device_remove_file(dev->dev, &dev_attr_registers);
2315 err_dev_reg: 2327 err_dev_reg:
2316 device_unregister(&dev->gadget.dev); 2328 device_unregister(&dev->gadget.dev);
2317 err_irq: 2329 err_irq:
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 476d88e1ae97..1e6ea6f26507 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -1410,11 +1410,17 @@ static int net2280_pullup(struct usb_gadget *_gadget, int is_on)
1410 return 0; 1410 return 0;
1411} 1411}
1412 1412
1413static int net2280_start(struct usb_gadget_driver *driver,
1414 int (*bind)(struct usb_gadget *));
1415static int net2280_stop(struct usb_gadget_driver *driver);
1416
1413static const struct usb_gadget_ops net2280_ops = { 1417static const struct usb_gadget_ops net2280_ops = {
1414 .get_frame = net2280_get_frame, 1418 .get_frame = net2280_get_frame,
1415 .wakeup = net2280_wakeup, 1419 .wakeup = net2280_wakeup,
1416 .set_selfpowered = net2280_set_selfpowered, 1420 .set_selfpowered = net2280_set_selfpowered,
1417 .pullup = net2280_pullup, 1421 .pullup = net2280_pullup,
1422 .start = net2280_start,
1423 .stop = net2280_stop,
1418}; 1424};
1419 1425
1420/*-------------------------------------------------------------------------*/ 1426/*-------------------------------------------------------------------------*/
@@ -1930,7 +1936,7 @@ static void ep0_start (struct net2280 *dev)
1930 * disconnect is reported. then a host may connect again, or 1936 * disconnect is reported. then a host may connect again, or
1931 * the driver might get unbound. 1937 * the driver might get unbound.
1932 */ 1938 */
1933int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1939static int net2280_start(struct usb_gadget_driver *driver,
1934 int (*bind)(struct usb_gadget *)) 1940 int (*bind)(struct usb_gadget *))
1935{ 1941{
1936 struct net2280 *dev = the_controller; 1942 struct net2280 *dev = the_controller;
@@ -1994,7 +2000,6 @@ err_unbind:
1994 dev->driver = NULL; 2000 dev->driver = NULL;
1995 return retval; 2001 return retval;
1996} 2002}
1997EXPORT_SYMBOL(usb_gadget_probe_driver);
1998 2003
1999static void 2004static void
2000stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) 2005stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
@@ -2022,7 +2027,7 @@ stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
2022 usb_reinit (dev); 2027 usb_reinit (dev);
2023} 2028}
2024 2029
2025int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 2030static int net2280_stop(struct usb_gadget_driver *driver)
2026{ 2031{
2027 struct net2280 *dev = the_controller; 2032 struct net2280 *dev = the_controller;
2028 unsigned long flags; 2033 unsigned long flags;
@@ -2049,8 +2054,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2049 DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name); 2054 DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name);
2050 return 0; 2055 return 0;
2051} 2056}
2052EXPORT_SYMBOL (usb_gadget_unregister_driver);
2053
2054 2057
2055/*-------------------------------------------------------------------------*/ 2058/*-------------------------------------------------------------------------*/
2056 2059
@@ -2732,6 +2735,8 @@ static void net2280_remove (struct pci_dev *pdev)
2732{ 2735{
2733 struct net2280 *dev = pci_get_drvdata (pdev); 2736 struct net2280 *dev = pci_get_drvdata (pdev);
2734 2737
2738 usb_del_gadget_udc(&dev->gadget);
2739
2735 BUG_ON(dev->driver); 2740 BUG_ON(dev->driver);
2736 2741
2737 /* then clean up the resources we allocated during probe() */ 2742 /* then clean up the resources we allocated during probe() */
@@ -2916,6 +2921,9 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2916 retval = device_create_file (&pdev->dev, &dev_attr_registers); 2921 retval = device_create_file (&pdev->dev, &dev_attr_registers);
2917 if (retval) goto done; 2922 if (retval) goto done;
2918 2923
2924 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
2925 if (retval)
2926 goto done;
2919 return 0; 2927 return 0;
2920 2928
2921done: 2929done:
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 82fd24935332..740c7daed279 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -1375,6 +1375,10 @@ static int omap_pullup(struct usb_gadget *gadget, int is_on)
1375 return 0; 1375 return 0;
1376} 1376}
1377 1377
1378static int omap_udc_start(struct usb_gadget_driver *driver,
1379 int (*bind)(struct usb_gadget *));
1380static int omap_udc_stop(struct usb_gadget_driver *driver);
1381
1378static struct usb_gadget_ops omap_gadget_ops = { 1382static struct usb_gadget_ops omap_gadget_ops = {
1379 .get_frame = omap_get_frame, 1383 .get_frame = omap_get_frame,
1380 .wakeup = omap_wakeup, 1384 .wakeup = omap_wakeup,
@@ -1382,6 +1386,8 @@ static struct usb_gadget_ops omap_gadget_ops = {
1382 .vbus_session = omap_vbus_session, 1386 .vbus_session = omap_vbus_session,
1383 .vbus_draw = omap_vbus_draw, 1387 .vbus_draw = omap_vbus_draw,
1384 .pullup = omap_pullup, 1388 .pullup = omap_pullup,
1389 .start = omap_udc_start,
1390 .stop = omap_udc_stop,
1385}; 1391};
1386 1392
1387/*-------------------------------------------------------------------------*/ 1393/*-------------------------------------------------------------------------*/
@@ -2102,7 +2108,7 @@ static inline int machine_without_vbus_sense(void)
2102 ); 2108 );
2103} 2109}
2104 2110
2105int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2111static int omap_udc_start(struct usb_gadget_driver *driver,
2106 int (*bind)(struct usb_gadget *)) 2112 int (*bind)(struct usb_gadget *))
2107{ 2113{
2108 int status = -ENODEV; 2114 int status = -ENODEV;
@@ -2186,9 +2192,8 @@ done:
2186 omap_udc_enable_clock(0); 2192 omap_udc_enable_clock(0);
2187 return status; 2193 return status;
2188} 2194}
2189EXPORT_SYMBOL(usb_gadget_probe_driver);
2190 2195
2191int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) 2196static int omap_udc_stop(struct usb_gadget_driver *driver)
2192{ 2197{
2193 unsigned long flags; 2198 unsigned long flags;
2194 int status = -ENODEV; 2199 int status = -ENODEV;
@@ -2222,8 +2227,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2222 DBG("unregistered driver '%s'\n", driver->driver.name); 2227 DBG("unregistered driver '%s'\n", driver->driver.name);
2223 return status; 2228 return status;
2224} 2229}
2225EXPORT_SYMBOL(usb_gadget_unregister_driver);
2226
2227 2230
2228/*-------------------------------------------------------------------------*/ 2231/*-------------------------------------------------------------------------*/
2229 2232
@@ -2991,9 +2994,16 @@ known:
2991 2994
2992 create_proc_file(); 2995 create_proc_file();
2993 status = device_add(&udc->gadget.dev); 2996 status = device_add(&udc->gadget.dev);
2997 if (status)
2998 goto cleanup4;
2999
3000 status = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2994 if (!status) 3001 if (!status)
2995 return status; 3002 return status;
2996 /* If fail, fall through */ 3003 /* If fail, fall through */
3004cleanup4:
3005 remove_proc_file();
3006
2997#ifdef USE_ISO 3007#ifdef USE_ISO
2998cleanup3: 3008cleanup3:
2999 free_irq(pdev->resource[2].start, udc); 3009 free_irq(pdev->resource[2].start, udc);
@@ -3029,6 +3039,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
3029 3039
3030 if (!udc) 3040 if (!udc)
3031 return -ENODEV; 3041 return -ENODEV;
3042
3043 usb_del_gadget_udc(&udc->gadget);
3032 if (udc->driver) 3044 if (udc->driver)
3033 return -EBUSY; 3045 return -EBUSY;
3034 3046
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index 68dbcc3e4cc2..f96615ab6b77 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -1176,6 +1176,9 @@ static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
1176 return -EOPNOTSUPP; 1176 return -EOPNOTSUPP;
1177} 1177}
1178 1178
1179static int pch_udc_start(struct usb_gadget_driver *driver,
1180 int (*bind)(struct usb_gadget *));
1181static int pch_udc_stop(struct usb_gadget_driver *driver);
1179static const struct usb_gadget_ops pch_udc_ops = { 1182static const struct usb_gadget_ops pch_udc_ops = {
1180 .get_frame = pch_udc_pcd_get_frame, 1183 .get_frame = pch_udc_pcd_get_frame,
1181 .wakeup = pch_udc_pcd_wakeup, 1184 .wakeup = pch_udc_pcd_wakeup,
@@ -1183,6 +1186,8 @@ static const struct usb_gadget_ops pch_udc_ops = {
1183 .pullup = pch_udc_pcd_pullup, 1186 .pullup = pch_udc_pcd_pullup,
1184 .vbus_session = pch_udc_pcd_vbus_session, 1187 .vbus_session = pch_udc_pcd_vbus_session,
1185 .vbus_draw = pch_udc_pcd_vbus_draw, 1188 .vbus_draw = pch_udc_pcd_vbus_draw,
1189 .start = pch_udc_start,
1190 .stop = pch_udc_stop,
1186}; 1191};
1187 1192
1188/** 1193/**
@@ -2690,7 +2695,7 @@ static int init_dma_pools(struct pch_udc_dev *dev)
2690 return 0; 2695 return 0;
2691} 2696}
2692 2697
2693int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2698static int pch_udc_start(struct usb_gadget_driver *driver,
2694 int (*bind)(struct usb_gadget *)) 2699 int (*bind)(struct usb_gadget *))
2695{ 2700{
2696 struct pch_udc_dev *dev = pch_udc; 2701 struct pch_udc_dev *dev = pch_udc;
@@ -2733,9 +2738,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
2733 dev->connected = 1; 2738 dev->connected = 1;
2734 return 0; 2739 return 0;
2735} 2740}
2736EXPORT_SYMBOL(usb_gadget_probe_driver);
2737 2741
2738int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2742static int pch_udc_stop(struct usb_gadget_driver *driver)
2739{ 2743{
2740 struct pch_udc_dev *dev = pch_udc; 2744 struct pch_udc_dev *dev = pch_udc;
2741 2745
@@ -2761,7 +2765,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2761 pch_udc_set_disconnect(dev); 2765 pch_udc_set_disconnect(dev);
2762 return 0; 2766 return 0;
2763} 2767}
2764EXPORT_SYMBOL(usb_gadget_unregister_driver);
2765 2768
2766static void pch_udc_shutdown(struct pci_dev *pdev) 2769static void pch_udc_shutdown(struct pci_dev *pdev)
2767{ 2770{
@@ -2778,6 +2781,8 @@ static void pch_udc_remove(struct pci_dev *pdev)
2778{ 2781{
2779 struct pch_udc_dev *dev = pci_get_drvdata(pdev); 2782 struct pch_udc_dev *dev = pci_get_drvdata(pdev);
2780 2783
2784 usb_del_gadget_udc(&dev->gadget);
2785
2781 /* gadget driver must not be registered */ 2786 /* gadget driver must not be registered */
2782 if (dev->driver) 2787 if (dev->driver)
2783 dev_err(&pdev->dev, 2788 dev_err(&pdev->dev,
@@ -2953,6 +2958,9 @@ static int pch_udc_probe(struct pci_dev *pdev,
2953 2958
2954 /* Put the device in disconnected state till a driver is bound */ 2959 /* Put the device in disconnected state till a driver is bound */
2955 pch_udc_set_disconnect(dev); 2960 pch_udc_set_disconnect(dev);
2961 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
2962 if (retval)
2963 goto finished;
2956 return 0; 2964 return 0;
2957 2965
2958finished: 2966finished:
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index 774545494cf2..e4e59b4de25d 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -1011,12 +1011,18 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1011 return -EOPNOTSUPP; 1011 return -EOPNOTSUPP;
1012} 1012}
1013 1013
1014static int pxa25x_start(struct usb_gadget_driver *driver,
1015 int (*bind)(struct usb_gadget *));
1016static int pxa25x_stop(struct usb_gadget_driver *driver);
1017
1014static const struct usb_gadget_ops pxa25x_udc_ops = { 1018static const struct usb_gadget_ops pxa25x_udc_ops = {
1015 .get_frame = pxa25x_udc_get_frame, 1019 .get_frame = pxa25x_udc_get_frame,
1016 .wakeup = pxa25x_udc_wakeup, 1020 .wakeup = pxa25x_udc_wakeup,
1017 .vbus_session = pxa25x_udc_vbus_session, 1021 .vbus_session = pxa25x_udc_vbus_session,
1018 .pullup = pxa25x_udc_pullup, 1022 .pullup = pxa25x_udc_pullup,
1019 .vbus_draw = pxa25x_udc_vbus_draw, 1023 .vbus_draw = pxa25x_udc_vbus_draw,
1024 .start = pxa25x_start,
1025 .stop = pxa25x_stop,
1020}; 1026};
1021 1027
1022/*-------------------------------------------------------------------------*/ 1028/*-------------------------------------------------------------------------*/
@@ -1263,7 +1269,7 @@ static void udc_enable (struct pxa25x_udc *dev)
1263 * disconnect is reported. then a host may connect again, or 1269 * disconnect is reported. then a host may connect again, or
1264 * the driver might get unbound. 1270 * the driver might get unbound.
1265 */ 1271 */
1266int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1272static int pxa25x_start(struct usb_gadget_driver *driver,
1267 int (*bind)(struct usb_gadget *)) 1273 int (*bind)(struct usb_gadget *))
1268{ 1274{
1269 struct pxa25x_udc *dev = the_controller; 1275 struct pxa25x_udc *dev = the_controller;
@@ -1322,7 +1328,6 @@ fail:
1322bind_fail: 1328bind_fail:
1323 return retval; 1329 return retval;
1324} 1330}
1325EXPORT_SYMBOL(usb_gadget_probe_driver);
1326 1331
1327static void 1332static void
1328stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) 1333stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
@@ -1351,7 +1356,7 @@ stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
1351 udc_reinit(dev); 1356 udc_reinit(dev);
1352} 1357}
1353 1358
1354int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1359static int pxa25x_stop(struct usb_gadget_driver *driver)
1355{ 1360{
1356 struct pxa25x_udc *dev = the_controller; 1361 struct pxa25x_udc *dev = the_controller;
1357 1362
@@ -1379,8 +1384,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1379 dump_state(dev); 1384 dump_state(dev);
1380 return 0; 1385 return 0;
1381} 1386}
1382EXPORT_SYMBOL(usb_gadget_unregister_driver);
1383
1384 1387
1385/*-------------------------------------------------------------------------*/ 1388/*-------------------------------------------------------------------------*/
1386 1389
@@ -2231,8 +2234,11 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2231#endif 2234#endif
2232 create_debug_files(dev); 2235 create_debug_files(dev);
2233 2236
2234 return 0; 2237 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
2238 if (!retval)
2239 return retval;
2235 2240
2241 remove_debug_files(dev);
2236#ifdef CONFIG_ARCH_LUBBOCK 2242#ifdef CONFIG_ARCH_LUBBOCK
2237lubbock_fail0: 2243lubbock_fail0:
2238 free_irq(LUBBOCK_USB_DISC_IRQ, dev); 2244 free_irq(LUBBOCK_USB_DISC_IRQ, dev);
@@ -2261,6 +2267,7 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2261{ 2267{
2262 struct pxa25x_udc *dev = platform_get_drvdata(pdev); 2268 struct pxa25x_udc *dev = platform_get_drvdata(pdev);
2263 2269
2270 usb_del_gadget_udc(&dev->gadget);
2264 if (dev->driver) 2271 if (dev->driver)
2265 return -EBUSY; 2272 return -EBUSY;
2266 2273
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 57607696735c..85b68c75dc9d 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -1680,12 +1680,18 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1680 return -EOPNOTSUPP; 1680 return -EOPNOTSUPP;
1681} 1681}
1682 1682
1683static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1684 int (*bind)(struct usb_gadget *));
1685static int pxa27x_udc_stop(struct usb_gadget_driver *driver);
1686
1683static const struct usb_gadget_ops pxa_udc_ops = { 1687static const struct usb_gadget_ops pxa_udc_ops = {
1684 .get_frame = pxa_udc_get_frame, 1688 .get_frame = pxa_udc_get_frame,
1685 .wakeup = pxa_udc_wakeup, 1689 .wakeup = pxa_udc_wakeup,
1686 .pullup = pxa_udc_pullup, 1690 .pullup = pxa_udc_pullup,
1687 .vbus_session = pxa_udc_vbus_session, 1691 .vbus_session = pxa_udc_vbus_session,
1688 .vbus_draw = pxa_udc_vbus_draw, 1692 .vbus_draw = pxa_udc_vbus_draw,
1693 .start = pxa27x_udc_start,
1694 .stop = pxa27x_udc_stop,
1689}; 1695};
1690 1696
1691/** 1697/**
@@ -1791,7 +1797,7 @@ static void udc_enable(struct pxa_udc *udc)
1791} 1797}
1792 1798
1793/** 1799/**
1794 * usb_gadget_probe_driver - Register gadget driver 1800 * pxa27x_start - Register gadget driver
1795 * @driver: gadget driver 1801 * @driver: gadget driver
1796 * @bind: bind function 1802 * @bind: bind function
1797 * 1803 *
@@ -1805,7 +1811,7 @@ static void udc_enable(struct pxa_udc *udc)
1805 * 1811 *
1806 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1812 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1807 */ 1813 */
1808int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1814static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1809 int (*bind)(struct usb_gadget *)) 1815 int (*bind)(struct usb_gadget *))
1810{ 1816{
1811 struct pxa_udc *udc = the_controller; 1817 struct pxa_udc *udc = the_controller;
@@ -1860,8 +1866,6 @@ add_fail:
1860 udc->gadget.dev.driver = NULL; 1866 udc->gadget.dev.driver = NULL;
1861 return retval; 1867 return retval;
1862} 1868}
1863EXPORT_SYMBOL(usb_gadget_probe_driver);
1864
1865 1869
1866/** 1870/**
1867 * stop_activity - Stops udc endpoints 1871 * stop_activity - Stops udc endpoints
@@ -1888,12 +1892,12 @@ static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver)
1888} 1892}
1889 1893
1890/** 1894/**
1891 * usb_gadget_unregister_driver - Unregister the gadget driver 1895 * pxa27x_udc_stop - Unregister the gadget driver
1892 * @driver: gadget driver 1896 * @driver: gadget driver
1893 * 1897 *
1894 * Returns 0 if no error, -ENODEV, -EINVAL otherwise 1898 * Returns 0 if no error, -ENODEV, -EINVAL otherwise
1895 */ 1899 */
1896int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1900static int pxa27x_udc_stop(struct usb_gadget_driver *driver)
1897{ 1901{
1898 struct pxa_udc *udc = the_controller; 1902 struct pxa_udc *udc = the_controller;
1899 1903
@@ -1917,7 +1921,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1917 return otg_set_peripheral(udc->transceiver, NULL); 1921 return otg_set_peripheral(udc->transceiver, NULL);
1918 return 0; 1922 return 0;
1919} 1923}
1920EXPORT_SYMBOL(usb_gadget_unregister_driver);
1921 1924
1922/** 1925/**
1923 * handle_ep0_ctrl_req - handle control endpoint control request 1926 * handle_ep0_ctrl_req - handle control endpoint control request
@@ -2516,9 +2519,14 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2516 driver_name, IRQ_USB, retval); 2519 driver_name, IRQ_USB, retval);
2517 goto err_irq; 2520 goto err_irq;
2518 } 2521 }
2522 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2523 if (retval)
2524 goto err_add_udc;
2519 2525
2520 pxa_init_debugfs(udc); 2526 pxa_init_debugfs(udc);
2521 return 0; 2527 return 0;
2528err_add_udc:
2529 free_irq(udc->irq, udc);
2522err_irq: 2530err_irq:
2523 iounmap(udc->regs); 2531 iounmap(udc->regs);
2524err_map: 2532err_map:
@@ -2537,6 +2545,7 @@ static int __exit pxa_udc_remove(struct platform_device *_dev)
2537 struct pxa_udc *udc = platform_get_drvdata(_dev); 2545 struct pxa_udc *udc = platform_get_drvdata(_dev);
2538 int gpio = udc->mach->gpio_pullup; 2546 int gpio = udc->mach->gpio_pullup;
2539 2547
2548 usb_del_gadget_udc(&udc->gadget);
2540 usb_gadget_unregister_driver(udc->driver); 2549 usb_gadget_unregister_driver(udc->driver);
2541 free_irq(udc->irq, udc); 2550 free_irq(udc->irq, udc);
2542 pxa_cleanup_debugfs(udc); 2551 pxa_cleanup_debugfs(udc);
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index 6dcc1f68fa60..51b655f3b477 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -1410,7 +1410,7 @@ static struct usb_ep_ops r8a66597_ep_ops = {
1410/*-------------------------------------------------------------------------*/ 1410/*-------------------------------------------------------------------------*/
1411static struct r8a66597 *the_controller; 1411static struct r8a66597 *the_controller;
1412 1412
1413int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1413static int r8a66597_start(struct usb_gadget_driver *driver,
1414 int (*bind)(struct usb_gadget *)) 1414 int (*bind)(struct usb_gadget *))
1415{ 1415{
1416 struct r8a66597 *r8a66597 = the_controller; 1416 struct r8a66597 *r8a66597 = the_controller;
@@ -1462,9 +1462,8 @@ error:
1462 1462
1463 return retval; 1463 return retval;
1464} 1464}
1465EXPORT_SYMBOL(usb_gadget_probe_driver);
1466 1465
1467int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1466static int r8a66597_stop(struct usb_gadget_driver *driver)
1468{ 1467{
1469 struct r8a66597 *r8a66597 = the_controller; 1468 struct r8a66597 *r8a66597 = the_controller;
1470 unsigned long flags; 1469 unsigned long flags;
@@ -1488,7 +1487,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1488 r8a66597->driver = NULL; 1487 r8a66597->driver = NULL;
1489 return 0; 1488 return 0;
1490} 1489}
1491EXPORT_SYMBOL(usb_gadget_unregister_driver);
1492 1490
1493/*-------------------------------------------------------------------------*/ 1491/*-------------------------------------------------------------------------*/
1494static int r8a66597_get_frame(struct usb_gadget *_gadget) 1492static int r8a66597_get_frame(struct usb_gadget *_gadget)
@@ -1499,12 +1497,15 @@ static int r8a66597_get_frame(struct usb_gadget *_gadget)
1499 1497
1500static struct usb_gadget_ops r8a66597_gadget_ops = { 1498static struct usb_gadget_ops r8a66597_gadget_ops = {
1501 .get_frame = r8a66597_get_frame, 1499 .get_frame = r8a66597_get_frame,
1500 .start = r8a66597_start,
1501 .stop = r8a66597_stop,
1502}; 1502};
1503 1503
1504static int __exit r8a66597_remove(struct platform_device *pdev) 1504static int __exit r8a66597_remove(struct platform_device *pdev)
1505{ 1505{
1506 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); 1506 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
1507 1507
1508 usb_del_gadget_udc(&r8a66597->gadget);
1508 del_timer_sync(&r8a66597->timer); 1509 del_timer_sync(&r8a66597->timer);
1509 iounmap(r8a66597->reg); 1510 iounmap(r8a66597->reg);
1510 free_irq(platform_get_irq(pdev, 0), r8a66597); 1511 free_irq(platform_get_irq(pdev, 0), r8a66597);
@@ -1647,9 +1648,15 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1647 1648
1648 init_controller(r8a66597); 1649 init_controller(r8a66597);
1649 1650
1651 ret = usb_add_gadget_udc(&pdev->dev, &r8a66597->gadget);
1652 if (ret)
1653 goto err_add_udc;
1654
1650 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1655 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1651 return 0; 1656 return 0;
1652 1657
1658err_add_udc:
1659 r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
1653clean_up3: 1660clean_up3:
1654 free_irq(irq, r8a66597); 1661 free_irq(irq, r8a66597);
1655clean_up2: 1662clean_up2:
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 0dfee282878a..8bdee67ce09a 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -2574,7 +2574,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2574 return 0; 2574 return 0;
2575} 2575}
2576 2576
2577int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 2577static int s3c_hsotg_start(struct usb_gadget_driver *driver,
2578 int (*bind)(struct usb_gadget *)) 2578 int (*bind)(struct usb_gadget *))
2579{ 2579{
2580 struct s3c_hsotg *hsotg = our_hsotg; 2580 struct s3c_hsotg *hsotg = our_hsotg;
@@ -2745,9 +2745,8 @@ err:
2745 hsotg->gadget.dev.driver = NULL; 2745 hsotg->gadget.dev.driver = NULL;
2746 return ret; 2746 return ret;
2747} 2747}
2748EXPORT_SYMBOL(usb_gadget_probe_driver);
2749 2748
2750int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2749static int s3c_hsotg_stop(struct usb_gadget_driver *driver)
2751{ 2750{
2752 struct s3c_hsotg *hsotg = our_hsotg; 2751 struct s3c_hsotg *hsotg = our_hsotg;
2753 int ep; 2752 int ep;
@@ -2775,7 +2774,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2775 2774
2776 return 0; 2775 return 0;
2777} 2776}
2778EXPORT_SYMBOL(usb_gadget_unregister_driver);
2779 2777
2780static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) 2778static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget)
2781{ 2779{
@@ -2784,6 +2782,8 @@ static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget)
2784 2782
2785static struct usb_gadget_ops s3c_hsotg_gadget_ops = { 2783static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
2786 .get_frame = s3c_hsotg_gadget_getframe, 2784 .get_frame = s3c_hsotg_gadget_getframe,
2785 .start = s3c_hsotg_start,
2786 .stop = s3c_hsotg_stop,
2787}; 2787};
2788 2788
2789/** 2789/**
@@ -3403,6 +3403,10 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3403 for (epnum = 0; epnum < S3C_HSOTG_EPS; epnum++) 3403 for (epnum = 0; epnum < S3C_HSOTG_EPS; epnum++)
3404 s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); 3404 s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum);
3405 3405
3406 ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget);
3407 if (ret)
3408 goto err_add_udc;
3409
3406 s3c_hsotg_create_debug(hsotg); 3410 s3c_hsotg_create_debug(hsotg);
3407 3411
3408 s3c_hsotg_dump(hsotg); 3412 s3c_hsotg_dump(hsotg);
@@ -3410,6 +3414,11 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3410 our_hsotg = hsotg; 3414 our_hsotg = hsotg;
3411 return 0; 3415 return 0;
3412 3416
3417err_add_udc:
3418 s3c_hsotg_gate(pdev, false);
3419 clk_disable(hsotg->clk);
3420 clk_put(hsotg->clk);
3421
3413err_regs: 3422err_regs:
3414 iounmap(hsotg->regs); 3423 iounmap(hsotg->regs);
3415 3424
@@ -3427,6 +3436,8 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev)
3427{ 3436{
3428 struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); 3437 struct s3c_hsotg *hsotg = platform_get_drvdata(pdev);
3429 3438
3439 usb_del_gadget_udc(&hsotg->gadget);
3440
3430 s3c_hsotg_delete_debug(hsotg); 3441 s3c_hsotg_delete_debug(hsotg);
3431 3442
3432 usb_gadget_unregister_driver(hsotg->driver); 3443 usb_gadget_unregister_driver(hsotg->driver);
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index d5e3e1e58626..dc9f42823a45 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -1133,7 +1133,7 @@ static irqreturn_t s3c_hsudc_irq(int irq, void *_dev)
1133 return IRQ_HANDLED; 1133 return IRQ_HANDLED;
1134} 1134}
1135 1135
1136int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1136static int s3c_hsudc_start(struct usb_gadget_driver *driver,
1137 int (*bind)(struct usb_gadget *)) 1137 int (*bind)(struct usb_gadget *))
1138{ 1138{
1139 struct s3c_hsudc *hsudc = the_controller; 1139 struct s3c_hsudc *hsudc = the_controller;
@@ -1181,9 +1181,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1181 1181
1182 return 0; 1182 return 0;
1183} 1183}
1184EXPORT_SYMBOL(usb_gadget_probe_driver);
1185 1184
1186int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1185static int s3c_hsudc_stop(struct usb_gadget_driver *driver)
1187{ 1186{
1188 struct s3c_hsudc *hsudc = the_controller; 1187 struct s3c_hsudc *hsudc = the_controller;
1189 unsigned long flags; 1188 unsigned long flags;
@@ -1210,7 +1209,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1210 driver->driver.name); 1209 driver->driver.name);
1211 return 0; 1210 return 0;
1212} 1211}
1213EXPORT_SYMBOL(usb_gadget_unregister_driver);
1214 1212
1215static inline u32 s3c_hsudc_read_frameno(struct s3c_hsudc *hsudc) 1213static inline u32 s3c_hsudc_read_frameno(struct s3c_hsudc *hsudc)
1216{ 1214{
@@ -1224,6 +1222,8 @@ static int s3c_hsudc_gadget_getframe(struct usb_gadget *gadget)
1224 1222
1225static struct usb_gadget_ops s3c_hsudc_gadget_ops = { 1223static struct usb_gadget_ops s3c_hsudc_gadget_ops = {
1226 .get_frame = s3c_hsudc_gadget_getframe, 1224 .get_frame = s3c_hsudc_gadget_getframe,
1225 .start = s3c_hsudc_start,
1226 .stop = s3c_hsudc_stop,
1227}; 1227};
1228 1228
1229static int s3c_hsudc_probe(struct platform_device *pdev) 1229static int s3c_hsudc_probe(struct platform_device *pdev)
@@ -1311,7 +1311,15 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1311 1311
1312 disable_irq(hsudc->irq); 1312 disable_irq(hsudc->irq);
1313 local_irq_enable(); 1313 local_irq_enable();
1314
1315 ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget);
1316 if (ret)
1317 goto err_add_udc;
1318
1314 return 0; 1319 return 0;
1320err_add_udc:
1321 clk_disable(hsudc->uclk);
1322 clk_put(hsudc->uclk);
1315err_clk: 1323err_clk:
1316 free_irq(hsudc->irq, hsudc); 1324 free_irq(hsudc->irq, hsudc);
1317err_irq: 1325err_irq:
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index 100f2635cf0a..1c19cd3f6a57 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1552,6 +1552,10 @@ static int s3c2410_vbus_draw(struct usb_gadget *_gadget, unsigned ma)
1552 return -ENOTSUPP; 1552 return -ENOTSUPP;
1553} 1553}
1554 1554
1555static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1556 int (*bind)(struct usb_gadget *));
1557static int s3c2410_udc_stop(struct usb_gadget_driver *driver);
1558
1555static const struct usb_gadget_ops s3c2410_ops = { 1559static const struct usb_gadget_ops s3c2410_ops = {
1556 .get_frame = s3c2410_udc_get_frame, 1560 .get_frame = s3c2410_udc_get_frame,
1557 .wakeup = s3c2410_udc_wakeup, 1561 .wakeup = s3c2410_udc_wakeup,
@@ -1559,6 +1563,8 @@ static const struct usb_gadget_ops s3c2410_ops = {
1559 .pullup = s3c2410_udc_pullup, 1563 .pullup = s3c2410_udc_pullup,
1560 .vbus_session = s3c2410_udc_vbus_session, 1564 .vbus_session = s3c2410_udc_vbus_session,
1561 .vbus_draw = s3c2410_vbus_draw, 1565 .vbus_draw = s3c2410_vbus_draw,
1566 .start = s3c2410_udc_start,
1567 .stop = s3c2410_udc_stop,
1562}; 1568};
1563 1569
1564static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) 1570static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd)
@@ -1672,10 +1678,7 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev)
1672 s3c2410_udc_command(S3C2410_UDC_P_ENABLE); 1678 s3c2410_udc_command(S3C2410_UDC_P_ENABLE);
1673} 1679}
1674 1680
1675/* 1681static int s3c2410_udc_start(struct usb_gadget_driver *driver,
1676 * usb_gadget_probe_driver
1677 */
1678int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
1679 int (*bind)(struct usb_gadget *)) 1682 int (*bind)(struct usb_gadget *))
1680{ 1683{
1681 struct s3c2410_udc *udc = the_controller; 1684 struct s3c2410_udc *udc = the_controller;
@@ -1730,12 +1733,8 @@ register_error:
1730 udc->gadget.dev.driver = NULL; 1733 udc->gadget.dev.driver = NULL;
1731 return retval; 1734 return retval;
1732} 1735}
1733EXPORT_SYMBOL(usb_gadget_probe_driver);
1734 1736
1735/* 1737static int s3c2410_udc_stop(struct usb_gadget_driver *driver)
1736 * usb_gadget_unregister_driver
1737 */
1738int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1739{ 1738{
1740 struct s3c2410_udc *udc = the_controller; 1739 struct s3c2410_udc *udc = the_controller;
1741 1740
@@ -1955,6 +1954,10 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1955 goto err_vbus_irq; 1954 goto err_vbus_irq;
1956 } 1955 }
1957 1956
1957 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
1958 if (retval)
1959 goto err_add_udc;
1960
1958 if (s3c2410_udc_debugfs_root) { 1961 if (s3c2410_udc_debugfs_root) {
1959 udc->regs_info = debugfs_create_file("registers", S_IRUGO, 1962 udc->regs_info = debugfs_create_file("registers", S_IRUGO,
1960 s3c2410_udc_debugfs_root, 1963 s3c2410_udc_debugfs_root,
@@ -1967,6 +1970,10 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1967 1970
1968 return 0; 1971 return 0;
1969 1972
1973err_add_udc:
1974 if (udc_info && !udc_info->udc_command &&
1975 gpio_is_valid(udc_info->pullup_pin))
1976 gpio_free(udc_info->pullup_pin);
1970err_vbus_irq: 1977err_vbus_irq:
1971 if (udc_info && udc_info->vbus_pin > 0) 1978 if (udc_info && udc_info->vbus_pin > 0)
1972 free_irq(gpio_to_irq(udc_info->vbus_pin), udc); 1979 free_irq(gpio_to_irq(udc_info->vbus_pin), udc);
@@ -1992,6 +1999,8 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
1992 unsigned int irq; 1999 unsigned int irq;
1993 2000
1994 dev_dbg(&pdev->dev, "%s()\n", __func__); 2001 dev_dbg(&pdev->dev, "%s()\n", __func__);
2002
2003 usb_del_gadget_udc(&udc->gadget);
1995 if (udc->driver) 2004 if (udc->driver)
1996 return -EBUSY; 2005 return -EBUSY;
1997 2006
@@ -2105,8 +2114,6 @@ static void __exit udc_exit(void)
2105 debugfs_remove(s3c2410_udc_debugfs_root); 2114 debugfs_remove(s3c2410_udc_debugfs_root);
2106} 2115}
2107 2116
2108EXPORT_SYMBOL(usb_gadget_unregister_driver);
2109
2110module_init(udc_init); 2117module_init(udc_init);
2111module_exit(udc_exit); 2118module_exit(udc_exit);
2112 2119
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 0a50a35e1853..728572cf709c 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1704,6 +1704,10 @@ static int musb_gadget_pullup(struct usb_gadget *gadget, int is_on)
1704 return 0; 1704 return 0;
1705} 1705}
1706 1706
1707static int musb_gadget_start(struct usb_gadget_driver *driver,
1708 int (*bind)(struct usb_gadget *));
1709static int musb_gadget_stop(struct usb_gadget_driver *driver);
1710
1707static const struct usb_gadget_ops musb_gadget_operations = { 1711static const struct usb_gadget_ops musb_gadget_operations = {
1708 .get_frame = musb_gadget_get_frame, 1712 .get_frame = musb_gadget_get_frame,
1709 .wakeup = musb_gadget_wakeup, 1713 .wakeup = musb_gadget_wakeup,
@@ -1711,6 +1715,8 @@ static const struct usb_gadget_ops musb_gadget_operations = {
1711 /* .vbus_session = musb_gadget_vbus_session, */ 1715 /* .vbus_session = musb_gadget_vbus_session, */
1712 .vbus_draw = musb_gadget_vbus_draw, 1716 .vbus_draw = musb_gadget_vbus_draw,
1713 .pullup = musb_gadget_pullup, 1717 .pullup = musb_gadget_pullup,
1718 .start = musb_gadget_start,
1719 .stop = musb_gadget_stop,
1714}; 1720};
1715 1721
1716/* ----------------------------------------------------------------------- */ 1722/* ----------------------------------------------------------------------- */
@@ -1835,7 +1841,16 @@ int __init musb_gadget_setup(struct musb *musb)
1835 if (status != 0) { 1841 if (status != 0) {
1836 put_device(&musb->g.dev); 1842 put_device(&musb->g.dev);
1837 the_gadget = NULL; 1843 the_gadget = NULL;
1844 return status;
1838 } 1845 }
1846 status = usb_add_gadget_udc(musb->controller, &musb->g);
1847 if (status)
1848 goto err;
1849
1850 return 0;
1851err:
1852 device_unregister(&musb->g.dev);
1853 the_gadget = NULL;
1839 return status; 1854 return status;
1840} 1855}
1841 1856
@@ -1844,6 +1859,7 @@ void musb_gadget_cleanup(struct musb *musb)
1844 if (musb != the_gadget) 1859 if (musb != the_gadget)
1845 return; 1860 return;
1846 1861
1862 usb_del_gadget_udc(&musb->g);
1847 device_unregister(&musb->g.dev); 1863 device_unregister(&musb->g.dev);
1848 the_gadget = NULL; 1864 the_gadget = NULL;
1849} 1865}
@@ -1860,7 +1876,7 @@ void musb_gadget_cleanup(struct musb *musb)
1860 * @param bind the driver's bind function 1876 * @param bind the driver's bind function
1861 * @return <0 if error, 0 if everything is fine 1877 * @return <0 if error, 0 if everything is fine
1862 */ 1878 */
1863int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 1879static int musb_gadget_start(struct usb_gadget_driver *driver,
1864 int (*bind)(struct usb_gadget *)) 1880 int (*bind)(struct usb_gadget *))
1865{ 1881{
1866 struct musb *musb = the_gadget; 1882 struct musb *musb = the_gadget;
@@ -1962,7 +1978,6 @@ err1:
1962err0: 1978err0:
1963 return retval; 1979 return retval;
1964} 1980}
1965EXPORT_SYMBOL(usb_gadget_probe_driver);
1966 1981
1967static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver) 1982static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
1968{ 1983{
@@ -2012,7 +2027,7 @@ static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
2012 * 2027 *
2013 * @param driver the gadget driver to unregister 2028 * @param driver the gadget driver to unregister
2014 */ 2029 */
2015int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2030static int musb_gadget_stop(struct usb_gadget_driver *driver)
2016{ 2031{
2017 struct musb *musb = the_gadget; 2032 struct musb *musb = the_gadget;
2018 unsigned long flags; 2033 unsigned long flags;
@@ -2071,8 +2086,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2071 2086
2072 return 0; 2087 return 0;
2073} 2088}
2074EXPORT_SYMBOL(usb_gadget_unregister_driver);
2075
2076 2089
2077/* ----------------------------------------------------------------------- */ 2090/* ----------------------------------------------------------------------- */
2078 2091
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index aa591b663835..c9c56e7a1b18 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -725,7 +725,7 @@ static int usbhsg_try_stop(struct usbhs_priv *priv, u32 status)
725 * 725 *
726 */ 726 */
727struct usbhsg_gpriv *the_controller; 727struct usbhsg_gpriv *the_controller;
728int usb_gadget_probe_driver(struct usb_gadget_driver *driver, 728static int usbhsg_gadget_start(struct usb_gadget_driver *driver,
729 int (*bind)(struct usb_gadget *)) 729 int (*bind)(struct usb_gadget *))
730{ 730{
731 struct usbhsg_gpriv *gpriv = the_controller; 731 struct usbhsg_gpriv *gpriv = the_controller;
@@ -775,9 +775,8 @@ add_fail:
775 775
776 return ret; 776 return ret;
777} 777}
778EXPORT_SYMBOL(usb_gadget_probe_driver);
779 778
780int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 779static int usbhsg_gadget_stop(struct usb_gadget_driver *driver)
781{ 780{
782 struct usbhsg_gpriv *gpriv = the_controller; 781 struct usbhsg_gpriv *gpriv = the_controller;
783 struct usbhs_priv *priv; 782 struct usbhs_priv *priv;
@@ -806,7 +805,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
806 805
807 return 0; 806 return 0;
808} 807}
809EXPORT_SYMBOL(usb_gadget_unregister_driver);
810 808
811/* 809/*
812 * usb gadget ops 810 * usb gadget ops
@@ -821,6 +819,8 @@ static int usbhsg_get_frame(struct usb_gadget *gadget)
821 819
822static struct usb_gadget_ops usbhsg_gadget_ops = { 820static struct usb_gadget_ops usbhsg_gadget_ops = {
823 .get_frame = usbhsg_get_frame, 821 .get_frame = usbhsg_get_frame,
822 .start = usbhsg_gadget_start,
823 .stop = usbhsg_gadget_stop,
824}; 824};
825 825
826static int usbhsg_start(struct usbhs_priv *priv) 826static int usbhsg_start(struct usbhs_priv *priv)
@@ -840,6 +840,7 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
840 struct device *dev = usbhs_priv_to_dev(priv); 840 struct device *dev = usbhs_priv_to_dev(priv);
841 int pipe_size = usbhs_get_dparam(priv, pipe_size); 841 int pipe_size = usbhs_get_dparam(priv, pipe_size);
842 int i; 842 int i;
843 int ret;
843 844
844 gpriv = kzalloc(sizeof(struct usbhsg_gpriv), GFP_KERNEL); 845 gpriv = kzalloc(sizeof(struct usbhsg_gpriv), GFP_KERNEL);
845 if (!gpriv) { 846 if (!gpriv) {
@@ -850,6 +851,7 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
850 uep = kzalloc(sizeof(struct usbhsg_uep) * pipe_size, GFP_KERNEL); 851 uep = kzalloc(sizeof(struct usbhsg_uep) * pipe_size, GFP_KERNEL);
851 if (!uep) { 852 if (!uep) {
852 dev_err(dev, "Could not allocate ep\n"); 853 dev_err(dev, "Could not allocate ep\n");
854 ret = -ENOMEM;
853 goto usbhs_mod_gadget_probe_err_gpriv; 855 goto usbhs_mod_gadget_probe_err_gpriv;
854 } 856 }
855 857
@@ -911,20 +913,28 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
911 913
912 the_controller = gpriv; 914 the_controller = gpriv;
913 915
916 ret = usb_add_gadget_udc(dev, &gpriv->gadget);
917 if (ret)
918 goto err_add_udc;
919
920
914 dev_info(dev, "gadget probed\n"); 921 dev_info(dev, "gadget probed\n");
915 922
916 return 0; 923 return 0;
924err_add_udc:
925 kfree(gpriv->uep);
917 926
918usbhs_mod_gadget_probe_err_gpriv: 927usbhs_mod_gadget_probe_err_gpriv:
919 kfree(gpriv); 928 kfree(gpriv);
920 929
921 return -ENOMEM; 930 return ret;
922} 931}
923 932
924void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv) 933void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv)
925{ 934{
926 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); 935 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
927 936
937 usb_del_gadget_udc(&gpriv->gadget);
928 kfree(gpriv->uep); 938 kfree(gpriv->uep);
929 kfree(gpriv); 939 kfree(gpriv);
930} 940}