From: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> 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, only the dummy_hcd is converted, other will follow in this patch. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> Signed-off-by: Felipe Balbi <balbi@xxxxxx> --- drivers/usb/gadget/composite.c | 3 ++- drivers/usb/gadget/dbgp.c | 3 ++- drivers/usb/gadget/dummy_hcd.c | 31 ++++++++++++++++++++++--------- 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 -- 8 files changed, 37 insertions(+), 19 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 82314ed..688046e 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1226,6 +1226,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, @@ -1273,7 +1274,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 e5ac8a3..abe4a2e 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 3214ca3..0b3cb47 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; @@ -845,7 +852,6 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) usb_hcd_poll_rh_status (dummy_to_hcd (dum)); return 0; } -EXPORT_SYMBOL (usb_gadget_unregister_driver); #undef is_enabled @@ -892,6 +898,12 @@ static int dummy_udc_probe (struct platform_device *pdev) return rc; } + rc = usb_add_gadget(&pdev->dev, &dum->gadget); + if (rc < 0) { + put_device(&dum->gadget.dev); + return rc; + } + platform_set_drvdata (pdev, dum); rc = device_create_file (&dum->gadget.dev, &dev_attr_function); if (rc < 0) @@ -903,6 +915,7 @@ static int dummy_udc_remove (struct platform_device *pdev) { struct dummy *dum = platform_get_drvdata (pdev); + usb_del_gadget(&dum->gadget); platform_set_drvdata (pdev, NULL); device_remove_file (&dum->gadget.dev, &dev_attr_function); device_unregister (&dum->gadget.dev); diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index a6eacb5..603fbe6 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c @@ -3591,6 +3591,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, @@ -3632,7 +3633,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 c3f2bd4..4a05e0f 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c @@ -1544,6 +1544,7 @@ static struct usb_gadget_driver printer_driver = { .speed = DEVSPEED, .function = (char *) driver_desc, + .bind = printer_bind, .unbind = printer_unbind, .setup = printer_setup, @@ -1579,11 +1580,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 c408752..4bcabe8 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -807,8 +807,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.1.343.ga91df -- 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