usb: gadget: r8a66597-udc: fix cannot connect after rmmod gadget driver
[deliverable/linux.git] / drivers / usb / gadget / r8a66597-udc.c
index 6dcc1f68fa6041531e73eed8104d5c1acff1338b..4f3f1ce0424bf0cccc4945a5e81f027c0a78ec90 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2006-2009 Renesas Solutions Corp.
  *
- * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
+ * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1410,7 +1410,7 @@ static struct usb_ep_ops r8a66597_ep_ops = {
 /*-------------------------------------------------------------------------*/
 static struct r8a66597 *the_controller;
 
-int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
+static int r8a66597_start(struct usb_gadget_driver *driver,
                int (*bind)(struct usb_gadget *))
 {
        struct r8a66597 *r8a66597 = the_controller;
@@ -1444,6 +1444,7 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
                goto error;
        }
 
+       init_controller(r8a66597);
        r8a66597_bset(r8a66597, VBSE, INTENB0);
        if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) {
                r8a66597_start_xclock(r8a66597);
@@ -1462,9 +1463,8 @@ error:
 
        return retval;
 }
-EXPORT_SYMBOL(usb_gadget_probe_driver);
 
-int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
+static int r8a66597_stop(struct usb_gadget_driver *driver)
 {
        struct r8a66597 *r8a66597 = the_controller;
        unsigned long flags;
@@ -1475,20 +1475,16 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
        spin_lock_irqsave(&r8a66597->lock, flags);
        if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN)
                r8a66597_usb_disconnect(r8a66597);
-       spin_unlock_irqrestore(&r8a66597->lock, flags);
-
        r8a66597_bclr(r8a66597, VBSE, INTENB0);
+       disable_controller(r8a66597);
+       spin_unlock_irqrestore(&r8a66597->lock, flags);
 
        driver->unbind(&r8a66597->gadget);
 
-       init_controller(r8a66597);
-       disable_controller(r8a66597);
-
        device_del(&r8a66597->gadget.dev);
        r8a66597->driver = NULL;
        return 0;
 }
-EXPORT_SYMBOL(usb_gadget_unregister_driver);
 
 /*-------------------------------------------------------------------------*/
 static int r8a66597_get_frame(struct usb_gadget *_gadget)
@@ -1499,12 +1495,15 @@ static int r8a66597_get_frame(struct usb_gadget *_gadget)
 
 static struct usb_gadget_ops r8a66597_gadget_ops = {
        .get_frame              = r8a66597_get_frame,
+       .start                  = r8a66597_start,
+       .stop                   = r8a66597_stop,
 };
 
 static int __exit r8a66597_remove(struct platform_device *pdev)
 {
        struct r8a66597         *r8a66597 = dev_get_drvdata(&pdev->dev);
 
+       usb_del_gadget_udc(&r8a66597->gadget);
        del_timer_sync(&r8a66597->timer);
        iounmap(r8a66597->reg);
        free_irq(platform_get_irq(pdev, 0), r8a66597);
@@ -1645,11 +1644,15 @@ static int __init r8a66597_probe(struct platform_device *pdev)
                goto clean_up3;
        r8a66597->ep0_req->complete = nop_completion;
 
-       init_controller(r8a66597);
+       ret = usb_add_gadget_udc(&pdev->dev, &r8a66597->gadget);
+       if (ret)
+               goto err_add_udc;
 
        dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
        return 0;
 
+err_add_udc:
+       r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
 clean_up3:
        free_irq(irq, r8a66597);
 clean_up2:
@@ -1679,6 +1682,7 @@ static struct platform_driver r8a66597_driver = {
                .name = (char *) udc_name,
        },
 };
+MODULE_ALIAS("platform:r8a66597_udc");
 
 static int __init r8a66597_udc_init(void)
 {
This page took 0.027718 seconds and 5 git commands to generate.