提交 2c7f0989 编写于 作者: F Felipe Balbi

usb: gadget: langwell: convert to new style

with this patch we can finally remove the global
"the_controller" pointer.
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 5bc639fc
...@@ -50,9 +50,6 @@ static const char driver_name[] = "langwell_udc"; ...@@ -50,9 +50,6 @@ static const char driver_name[] = "langwell_udc";
static const char driver_desc[] = DRIVER_DESC; static const char driver_desc[] = DRIVER_DESC;
/* controller device global variable */
static struct langwell_udc *the_controller;
/* for endpoint 0 operations */ /* for endpoint 0 operations */
static const struct usb_endpoint_descriptor static const struct usb_endpoint_descriptor
langwell_ep0_desc = { langwell_ep0_desc = {
...@@ -1311,9 +1308,12 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on) ...@@ -1311,9 +1308,12 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on)
return 0; return 0;
} }
static int langwell_start(struct usb_gadget_driver *driver, static int langwell_start(struct usb_gadget *g,
int (*bind)(struct usb_gadget *)); struct usb_gadget_driver *driver);
static int langwell_stop(struct usb_gadget_driver *driver);
static int langwell_stop(struct usb_gadget *g,
struct usb_gadget_driver *driver);
/* device controller usb_gadget_ops structure */ /* device controller usb_gadget_ops structure */
static const struct usb_gadget_ops langwell_ops = { static const struct usb_gadget_ops langwell_ops = {
...@@ -1335,8 +1335,8 @@ static const struct usb_gadget_ops langwell_ops = { ...@@ -1335,8 +1335,8 @@ static const struct usb_gadget_ops langwell_ops = {
/* D+ pullup, software-controlled connect/disconnect to USB host */ /* D+ pullup, software-controlled connect/disconnect to USB host */
.pullup = langwell_pullup, .pullup = langwell_pullup,
.start = langwell_start, .udc_start = langwell_start,
.stop = langwell_stop, .udc_stop = langwell_stop,
}; };
...@@ -1848,21 +1848,15 @@ static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup); ...@@ -1848,21 +1848,15 @@ static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup);
* the driver might get unbound. * the driver might get unbound.
*/ */
static int langwell_start(struct usb_gadget_driver *driver, static int langwell_start(struct usb_gadget *g,
int (*bind)(struct usb_gadget *)) struct usb_gadget_driver *driver)
{ {
struct langwell_udc *dev = the_controller; struct langwell_udc *dev = gadget_to_langwell(g);
unsigned long flags; unsigned long flags;
int retval; int retval;
if (!dev)
return -ENODEV;
dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
if (dev->driver)
return -EBUSY;
spin_lock_irqsave(&dev->lock, flags); spin_lock_irqsave(&dev->lock, flags);
/* hook up the driver ... */ /* hook up the driver ... */
...@@ -1872,18 +1866,9 @@ static int langwell_start(struct usb_gadget_driver *driver, ...@@ -1872,18 +1866,9 @@ static int langwell_start(struct usb_gadget_driver *driver,
spin_unlock_irqrestore(&dev->lock, flags); 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); retval = device_create_file(&dev->pdev->dev, &dev_attr_function);
if (retval) if (retval)
goto err_unbind; goto err;
dev->usb_state = USB_STATE_ATTACHED; dev->usb_state = USB_STATE_ATTACHED;
dev->ep0_state = WAIT_FOR_SETUP; dev->ep0_state = WAIT_FOR_SETUP;
...@@ -1900,31 +1885,27 @@ static int langwell_start(struct usb_gadget_driver *driver, ...@@ -1900,31 +1885,27 @@ static int langwell_start(struct usb_gadget_driver *driver,
dev_info(&dev->pdev->dev, "register driver: %s\n", dev_info(&dev->pdev->dev, "register driver: %s\n",
driver->driver.name); driver->driver.name);
dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return 0; return 0;
err_unbind: err:
driver->unbind(&dev->gadget);
dev->gadget.dev.driver = NULL; dev->gadget.dev.driver = NULL;
dev->driver = NULL; dev->driver = NULL;
dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return retval; return retval;
} }
/* unregister gadget driver */ /* 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; unsigned long flags;
if (!dev)
return -ENODEV;
dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__);
if (unlikely(!driver || !driver->unbind))
return -EINVAL;
/* exit PHY low power suspend */ /* exit PHY low power suspend */
if (dev->pdev->device != 0x0829) if (dev->pdev->device != 0x0829)
langwell_phy_low_power(dev, 0); langwell_phy_low_power(dev, 0);
...@@ -1947,8 +1928,6 @@ static int langwell_stop(struct usb_gadget_driver *driver) ...@@ -1947,8 +1928,6 @@ static int langwell_stop(struct usb_gadget_driver *driver)
stop_activity(dev, driver); stop_activity(dev, driver);
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
/* unbind gadget driver */
driver->unbind(&dev->gadget);
dev->gadget.dev.driver = NULL; dev->gadget.dev.driver = NULL;
dev->driver = NULL; dev->driver = NULL;
...@@ -1957,6 +1936,7 @@ static int langwell_stop(struct usb_gadget_driver *driver) ...@@ -1957,6 +1936,7 @@ static int langwell_stop(struct usb_gadget_driver *driver)
dev_info(&dev->pdev->dev, "unregistered driver '%s'\n", dev_info(&dev->pdev->dev, "unregistered driver '%s'\n",
driver->driver.name); driver->driver.name);
dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__);
return 0; return 0;
} }
...@@ -3098,8 +3078,6 @@ static void langwell_udc_remove(struct pci_dev *pdev) ...@@ -3098,8 +3078,6 @@ static void langwell_udc_remove(struct pci_dev *pdev)
/* free dev, wait for the release() finished */ /* free dev, wait for the release() finished */
wait_for_completion(&done); wait_for_completion(&done);
the_controller = NULL;
} }
...@@ -3118,11 +3096,6 @@ static int langwell_udc_probe(struct pci_dev *pdev, ...@@ -3118,11 +3096,6 @@ static int langwell_udc_probe(struct pci_dev *pdev,
size_t size; size_t size;
int retval; int retval;
if (the_controller) {
dev_warn(&pdev->dev, "ignoring\n");
return -EBUSY;
}
/* alloc, and start init */ /* alloc, and start init */
dev = kzalloc(sizeof *dev, GFP_KERNEL); dev = kzalloc(sizeof *dev, GFP_KERNEL);
if (dev == NULL) { if (dev == NULL) {
...@@ -3342,8 +3315,6 @@ static int langwell_udc_probe(struct pci_dev *pdev, ...@@ -3342,8 +3315,6 @@ static int langwell_udc_probe(struct pci_dev *pdev,
"After langwell_udc_probe(), print all registers:\n"); "After langwell_udc_probe(), print all registers:\n");
print_all_registers(dev); print_all_registers(dev);
the_controller = dev;
retval = device_register(&dev->gadget.dev); retval = device_register(&dev->gadget.dev);
if (retval) if (retval)
goto error; goto error;
......
...@@ -221,3 +221,5 @@ struct langwell_udc { ...@@ -221,3 +221,5 @@ struct langwell_udc {
u16 dev_status; u16 dev_status;
}; };
#define gadget_to_langwell(g) container_of((g), struct langwell_udc, gadget)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册