static const char driver_desc[] = DRIVER_DESC;
-/* controller device global variable */
-static struct langwell_udc *the_controller;
-
/* for endpoint 0 operations */
static const struct usb_endpoint_descriptor
langwell_ep0_desc = {
return 0;
}
-static int langwell_start(struct usb_gadget_driver *driver,
- int (*bind)(struct usb_gadget *));
-static int langwell_stop(struct usb_gadget_driver *driver);
+static int langwell_start(struct usb_gadget *g,
+ struct usb_gadget_driver *driver);
+
+static int langwell_stop(struct usb_gadget *g,
+ struct usb_gadget_driver *driver);
+
/* device controller usb_gadget_ops structure */
static const struct usb_gadget_ops langwell_ops = {
/* D+ pullup, software-controlled connect/disconnect to USB host */
.pullup = langwell_pullup,
- .start = langwell_start,
- .stop = langwell_stop,
+ .udc_start = langwell_start,
+ .udc_stop = langwell_stop,
};
* the driver might get unbound.
*/
-static int langwell_start(struct usb_gadget_driver *driver,
- int (*bind)(struct usb_gadget *))
+static int langwell_start(struct usb_gadget *g,
+ struct usb_gadget_driver *driver)
{
- struct langwell_udc *dev = the_controller;
+ struct langwell_udc *dev = gadget_to_langwell(g);
unsigned long flags;
int retval;
- if (!dev)
- return -ENODEV;
-
dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
- if (dev->driver)
- return -EBUSY;
-
spin_lock_irqsave(&dev->lock, flags);
/* hook up the driver ... */
spin_unlock_irqrestore(&dev->lock, flags);
- retval = bind(&dev->gadget);
- if (retval) {
- dev_dbg(&dev->pdev->dev, "bind to driver %s --> %d\n",
- driver->driver.name, retval);
- dev->driver = NULL;
- dev->gadget.dev.driver = NULL;
- return retval;
- }
-
retval = device_create_file(&dev->pdev->dev, &dev_attr_function);
if (retval)
- goto err_unbind;
+ goto err;
dev->usb_state = USB_STATE_ATTACHED;
dev->ep0_state = WAIT_FOR_SETUP;
dev_info(&dev->pdev->dev, "register driver: %s\n",
driver->driver.name);
dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
+
return 0;
-err_unbind:
- driver->unbind(&dev->gadget);
+err:
dev->gadget.dev.driver = NULL;
dev->driver = NULL;
dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
+
return retval;
}
/* unregister gadget driver */
-static int langwell_stop(struct usb_gadget_driver *driver)
+static int langwell_stop(struct usb_gadget *g,
+ struct usb_gadget_driver *driver)
{
- struct langwell_udc *dev = the_controller;
+ struct langwell_udc *dev = gadget_to_langwell(g);
unsigned long flags;
- if (!dev)
- return -ENODEV;
-
dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
- if (unlikely(!driver || !driver->unbind))
- return -EINVAL;
-
/* exit PHY low power suspend */
if (dev->pdev->device != 0x0829)
langwell_phy_low_power(dev, 0);
stop_activity(dev, driver);
spin_unlock_irqrestore(&dev->lock, flags);
- /* unbind gadget driver */
- driver->unbind(&dev->gadget);
dev->gadget.dev.driver = NULL;
dev->driver = NULL;
dev_info(&dev->pdev->dev, "unregistered driver '%s'\n",
driver->driver.name);
dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
+
return 0;
}
/* free dev, wait for the release() finished */
wait_for_completion(&done);
-
- the_controller = NULL;
}
size_t size;
int retval;
- if (the_controller) {
- dev_warn(&pdev->dev, "ignoring\n");
- return -EBUSY;
- }
-
/* alloc, and start init */
dev = kzalloc(sizeof *dev, GFP_KERNEL);
if (dev == NULL) {
"After langwell_udc_probe(), print all registers:\n");
print_all_registers(dev);
- the_controller = dev;
-
retval = device_register(&dev->gadget.dev);
if (retval)
goto error;