peripheral drivers are using usb_add_gadget()/usb_del_gadget() to register/unregister to the udc-core. gadget (function) drivers will use usb_gadget_register_driver() / usb_gadget_unregister_driver() to register themself. The probe function is moved to the struct. 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. Rigth now, the only converted peripheral driver is the dummy_hcd. Other will follow in this patch. Converting peripheral drivers und gadgets in two separate patches would break bisecting. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> --- drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/composite.c | 3 +- drivers/usb/gadget/dbgp.c | 3 +- drivers/usb/gadget/dummy_hcd.c | 50 ++++++++++++++++++++---------------- drivers/usb/gadget/file_storage.c | 3 +- drivers/usb/gadget/gmidi.c | 3 +- drivers/usb/gadget/inode.c | 6 +++- drivers/usb/gadget/printer.c | 5 ++- include/linux/usb/gadget.h | 2 - 9 files changed, 44 insertions(+), 32 deletions(-) diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 4fe92b1..9969709 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -3,6 +3,7 @@ # ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG +obj-$(CONFIG_USB_GADGET) += udc-core.o obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o obj-$(CONFIG_USB_NET2280) += net2280.o obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 5cbb1a4..fea629c 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1249,6 +1249,7 @@ composite_resume(struct usb_gadget *gadget) static struct usb_gadget_driver composite_driver = { .speed = USB_SPEED_HIGH, + .bind = composite_bind, .unbind = composite_unbind, .setup = composite_setup, @@ -1296,7 +1297,7 @@ int usb_composite_probe(struct usb_composite_driver *driver, composite = driver; composite_gadget_bind = bind; - return usb_gadget_probe_driver(&composite_driver, composite_bind); + return usb_gadget_register_driver(&composite_driver); } /** diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c index dbe92ee..1cc968b 100644 --- a/drivers/usb/gadget/dbgp.c +++ b/drivers/usb/gadget/dbgp.c @@ -403,6 +403,7 @@ fail: static struct usb_gadget_driver dbgp_driver = { .function = "dbgp", .speed = USB_SPEED_HIGH, + .bind = dbgp_bind, .unbind = dbgp_unbind, .setup = dbgp_setup, .disconnect = dbgp_disconnect, @@ -414,7 +415,7 @@ static struct usb_gadget_driver dbgp_driver = { static int __init dbgp_init(void) { - return usb_gadget_probe_driver(&dbgp_driver, dbgp_bind); + return usb_gadget_register_driver(&dbgp_driver); } static void __exit dbgp_exit(void) diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 61ff927..5d6fad5 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -710,11 +710,18 @@ static int dummy_pullup (struct usb_gadget *_gadget, int value) return 0; } +static int dummy_udc_start(struct usb_gadget *gadget, + struct usb_gadget_driver *driver); +static int dummy_udc_stop(struct usb_gadget *gadget, + struct usb_gadget_driver *driver); + static const struct usb_gadget_ops dummy_ops = { .get_frame = dummy_g_get_frame, .wakeup = dummy_wakeup, .set_selfpowered = dummy_set_selfpowered, .pullup = dummy_pullup, + .start = dummy_udc_start, + .stop = dummy_udc_stop, }; /*-------------------------------------------------------------------------*/ @@ -747,9 +754,8 @@ static DEVICE_ATTR (function, S_IRUGO, show_function, NULL); * for each driver that registers: just add to a big root hub. */ -int -usb_gadget_probe_driver(struct usb_gadget_driver *driver, - int (*bind)(struct usb_gadget *)) +static int dummy_udc_start(struct usb_gadget *gadget, + struct usb_gadget_driver *driver) { struct dummy *dum = the_controller; int retval, i; @@ -758,7 +764,9 @@ usb_gadget_probe_driver(struct usb_gadget_driver *driver, return -EINVAL; if (dum->driver) return -EBUSY; - if (!bind || !driver->setup || driver->speed == USB_SPEED_UNKNOWN) + if (!driver->bind) + return -EINVAL; + if (!driver->setup || driver->speed == USB_SPEED_UNKNOWN) return -EINVAL; /* @@ -796,7 +804,7 @@ usb_gadget_probe_driver(struct usb_gadget_driver *driver, dum->gadget.dev.driver = &driver->driver; dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", driver->driver.name); - retval = bind(&dum->gadget); + retval = driver->bind(&dum->gadget); if (retval) { dum->driver = NULL; dum->gadget.dev.driver = NULL; @@ -812,10 +820,9 @@ usb_gadget_probe_driver(struct usb_gadget_driver *driver, usb_hcd_poll_rh_status (dummy_to_hcd (dum)); return 0; } -EXPORT_SYMBOL(usb_gadget_probe_driver); -int -usb_gadget_unregister_driver (struct usb_gadget_driver *driver) +static int dummy_udc_stop(struct usb_gadget *gadget, + struct usb_gadget_driver *driver) { struct dummy *dum = the_controller; unsigned long flags; @@ -833,19 +840,9 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) set_link_state (dum); spin_unlock_irqrestore (&dum->lock, flags); - driver->unbind (&dum->gadget); - dum->gadget.dev.driver = NULL; - dum->driver = NULL; - - spin_lock_irqsave (&dum->lock, flags); - dum->pullup = 0; - set_link_state (dum); - spin_unlock_irqrestore (&dum->lock, flags); - usb_hcd_poll_rh_status (dummy_to_hcd (dum)); return 0; } -EXPORT_SYMBOL (usb_gadget_unregister_driver); #undef is_enabled @@ -892,11 +889,20 @@ static int dummy_udc_probe (struct platform_device *pdev) return rc; } + rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget); + if (rc < 0) + goto err_udc; + rc = device_create_file (&dum->gadget.dev, &dev_attr_function); if (rc < 0) - device_unregister (&dum->gadget.dev); - else - platform_set_drvdata(pdev, dum); + goto err_dev; + platform_set_drvdata(pdev, dum); + return rc; + +err_dev: + usb_del_gadget_udc(&dum->gadget); +err_udc: + device_unregister(&dum->gadget.dev); return rc; } @@ -904,6 +910,7 @@ static int dummy_udc_remove (struct platform_device *pdev) { struct dummy *dum = platform_get_drvdata (pdev); + usb_del_gadget_udc(&dum->gadget); platform_set_drvdata (pdev, NULL); device_remove_file (&dum->gadget.dev, &dev_attr_function); device_unregister (&dum->gadget.dev); @@ -1863,7 +1870,6 @@ static void dummy_stop (struct usb_hcd *hcd) dum = hcd_to_dummy (hcd); device_remove_file (dummy_dev(dum), &dev_attr_urbs); - usb_gadget_unregister_driver (dum->driver); dev_info (dummy_dev(dum), "stopped\n"); } diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 0360f56..5d76bcb 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c @@ -3562,6 +3562,7 @@ static struct usb_gadget_driver fsg_driver = { .speed = USB_SPEED_FULL, #endif .function = (char *) fsg_string_product, + .bind = fsg_bind, .unbind = fsg_unbind, .disconnect = fsg_disconnect, .setup = fsg_setup, @@ -3603,7 +3604,7 @@ static int __init fsg_init(void) if ((rc = fsg_alloc()) != 0) return rc; fsg = the_fsg; - if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0) + if ((rc = usb_gadget_register_driver(&fsg_driver)) != 0) kref_put(&fsg->ref, fsg_release); return rc; } diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index 47b86b9..dcc4da2 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c @@ -1292,6 +1292,7 @@ static void gmidi_resume(struct usb_gadget *gadget) static struct usb_gadget_driver gmidi_driver = { .speed = USB_SPEED_FULL, .function = (char *)longname, + .bind = gmidi_bind, .unbind = gmidi_unbind, .setup = gmidi_setup, @@ -1308,7 +1309,7 @@ static struct usb_gadget_driver gmidi_driver = { static int __init gmidi_init(void) { - return usb_gadget_probe_driver(&gmidi_driver, gmidi_bind); + return usb_gadget_register_driver(&gmidi_driver); } module_init(gmidi_init); diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index a01383f..1379122 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c @@ -1776,6 +1776,7 @@ static struct usb_gadget_driver gadgetfs_driver = { .speed = USB_SPEED_FULL, #endif .function = (char *) driver_desc, + .bind = gadgetfs_bind, .unbind = gadgetfs_unbind, .setup = gadgetfs_setup, .disconnect = gadgetfs_disconnect, @@ -1798,6 +1799,7 @@ static int gadgetfs_probe (struct usb_gadget *gadget) static struct usb_gadget_driver probe_driver = { .speed = USB_SPEED_HIGH, + .bind = gadgetfs_probe, .unbind = gadgetfs_nop, .setup = (void *)gadgetfs_nop, .disconnect = gadgetfs_nop, @@ -1907,7 +1909,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) /* triggers gadgetfs_bind(); then we can enumerate. */ spin_unlock_irq (&dev->lock); - value = usb_gadget_probe_driver(&gadgetfs_driver, gadgetfs_bind); + value = usb_gadget_register_driver(&gadgetfs_driver); if (value != 0) { kfree (dev->buf); dev->buf = NULL; @@ -2047,7 +2049,7 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent) return -ESRCH; /* fake probe to determine $CHIP */ - (void) usb_gadget_probe_driver(&probe_driver, gadgetfs_probe); + (void) usb_gadget_register_driver(&probe_driver); if (!CHIP) return -ENODEV; diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 271ef94..1bc22c2 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c @@ -1546,6 +1546,7 @@ static struct usb_gadget_driver printer_driver = { .speed = DEVSPEED, .function = (char *) driver_desc, + .bind = printer_bind, .unbind = printer_unbind, .setup = printer_setup, @@ -1581,11 +1582,11 @@ init(void) return status; } - status = usb_gadget_probe_driver(&printer_driver, printer_bind); + status = usb_gadget_register_driver(&printer_driver); if (status) { class_destroy(usb_gadget_class); unregister_chrdev_region(g_printer_devno, 1); - DBG(dev, "usb_gadget_probe_driver %x\n", status); + DBG(dev, "usb_gadget_register_driver %x\n", status); } return status; diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 3d2d46f..fc783df 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -808,8 +808,6 @@ struct usb_gadget_driver { * this registration call returns. It's expected that the @driver->bind() * function will be in init sections. */ -int usb_gadget_probe_driver(struct usb_gadget_driver *driver, - int (*bind)(struct usb_gadget *)); int usb_gadget_register_driver(struct usb_gadget_driver *driver); /** -- 1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html