usb: gadget: atmel_usba_udc: convert to newstyle start/stop interface
authorSebastian Andrzej Siewior <sebastian@breakpoint.cc>
Sat, 4 Feb 2012 17:55:24 +0000 (18:55 +0100)
committerFelipe Balbi <balbi@ti.com>
Fri, 4 May 2012 12:53:01 +0000 (15:53 +0300)
This patches converts the driver into the new style start/stop interface.
As a result the driver no longer uses the static global the_udc
variable in start/stop functions. I kept the the_udc variable since it
makes the init code a little simpler.
Someone with hardware might want to look if it possible to move the vbus
irq/toggle_bias code into ->pullup().

Compile tested only.

Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/atmel_usba_udc.c

index f545e933758f12eb25dd422bb74dc66f1f354655..e23bf7984aaf673e966ca358ea85c047f58481a4 100644 (file)
@@ -1008,16 +1008,16 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
        return 0;
 }
 
-static int atmel_usba_start(struct usb_gadget_driver *driver,
-               int (*bind)(struct usb_gadget *));
-static int atmel_usba_stop(struct usb_gadget_driver *driver);
-
+static int atmel_usba_start(struct usb_gadget *gadget,
+               struct usb_gadget_driver *driver);
+static int atmel_usba_stop(struct usb_gadget *gadget,
+               struct usb_gadget_driver *driver);
 static const struct usb_gadget_ops usba_udc_ops = {
        .get_frame              = usba_udc_get_frame,
        .wakeup                 = usba_udc_wakeup,
        .set_selfpowered        = usba_udc_set_selfpowered,
-       .start                  = atmel_usba_start,
-       .stop                   = atmel_usba_stop,
+       .udc_start              = atmel_usba_start,
+       .udc_stop               = atmel_usba_stop,
 };
 
 static struct usb_endpoint_descriptor usba_ep0_desc = {
@@ -1795,21 +1795,13 @@ out:
        return IRQ_HANDLED;
 }
 
-static int atmel_usba_start(struct usb_gadget_driver *driver,
-               int (*bind)(struct usb_gadget *))
+static int atmel_usba_start(struct usb_gadget *gadget,
+               struct usb_gadget_driver *driver)
 {
-       struct usba_udc *udc = &the_udc;
+       struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget);
        unsigned long flags;
-       int ret;
-
-       if (!udc->pdev)
-               return -ENODEV;
 
        spin_lock_irqsave(&udc->lock, flags);
-       if (udc->driver) {
-               spin_unlock_irqrestore(&udc->lock, flags);
-               return -EBUSY;
-       }
 
        udc->devstatus = 1 << USB_DEVICE_SELF_POWERED;
        udc->driver = driver;
@@ -1819,13 +1811,6 @@ static int atmel_usba_start(struct usb_gadget_driver *driver,
        clk_enable(udc->pclk);
        clk_enable(udc->hclk);
 
-       ret = bind(&udc->gadget);
-       if (ret) {
-               DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
-                       driver->driver.name, ret);
-               goto err_driver_bind;
-       }
-
        DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name);
 
        udc->vbus_prev = 0;
@@ -1842,23 +1827,14 @@ static int atmel_usba_start(struct usb_gadget_driver *driver,
        spin_unlock_irqrestore(&udc->lock, flags);
 
        return 0;
-
-err_driver_bind:
-       udc->driver = NULL;
-       udc->gadget.dev.driver = NULL;
-       return ret;
 }
 
-static int atmel_usba_stop(struct usb_gadget_driver *driver)
+static int atmel_usba_stop(struct usb_gadget *gadget,
+               struct usb_gadget_driver *driver)
 {
-       struct usba_udc *udc = &the_udc;
+       struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget);
        unsigned long flags;
 
-       if (!udc->pdev)
-               return -ENODEV;
-       if (driver != udc->driver || !driver->unbind)
-               return -EINVAL;
-
        if (gpio_is_valid(udc->vbus_pin))
                disable_irq(gpio_to_irq(udc->vbus_pin));
 
@@ -1871,10 +1847,6 @@ static int atmel_usba_stop(struct usb_gadget_driver *driver)
        toggle_bias(0);
        usba_writel(udc, CTRL, USBA_DISABLE_MASK);
 
-       if (udc->driver->disconnect)
-               udc->driver->disconnect(&udc->gadget);
-
-       driver->unbind(&udc->gadget);
        udc->gadget.dev.driver = NULL;
        udc->driver = NULL;