mbox series

[RFC,0/4] USB: gadget: Create a bus for gadgets

Message ID YjeEbHL8ITkW692W@rowland.harvard.edu
Headers show
Series USB: gadget: Create a bus for gadgets | expand

Message

Alan Stern March 20, 2022, 7:45 p.m. UTC
Everyone:

The following series of patches implements Greg's suggestion that 
gadgets should be registered on some sort of bus.  It turns out that the 
best way to do this is to create a new "gadget" bus, with specialized 
matching and probing routines, rather than using an existing bus.

Patches 1-3 are simple preparations for the big change.  They stand on 
their own, make useful little changes, and could be merged by themselves
without committing to adding the "gadget" bus.  Patch 4 is main one.

I'm posting this series for feedback from the Gadget/UDC maintainer and 
others.  If everything works out okay, the patches can be submitted for 
real once the upcoming merge window closes.

Alan Stern

Comments

Jun Li March 22, 2022, 12:57 p.m. UTC | #1
Alan Stern <stern@rowland.harvard.edu> 于2022年3月22日周二 06:57写道:
>
> In preparation for adding a "gadget" bus, this patch renames
> usb_gadget_probe_driver() to usb_gadget_register_driver().  The new
> name will be more accurate, since gadget drivers will be registered on
> the gadget bus and the probing will be done by the driver core, not
> the UDC core.
>
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

Missed one rename change:
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 1fb837d9271e..4141206bb0ed 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -284,7 +284,7 @@ static ssize_t gadget_dev_desc_UDC_store(struct
config_item *item,
                        goto err;
                }
                gi->composite.gadget_driver.udc_name = name;
-               ret = usb_gadget_probe_driver(&gi->composite.gadget_driver);
+               ret = usb_gadget_register_driver(&gi->composite.gadget_driver);
                if (ret) {
                        gi->composite.gadget_driver.udc_name = NULL;
                        goto err;
Li Jun
>
>
>  drivers/usb/gadget/composite.c         |    2 +-
>  drivers/usb/gadget/legacy/dbgp.c       |    2 +-
>  drivers/usb/gadget/legacy/inode.c      |    2 +-
>  drivers/usb/gadget/legacy/raw_gadget.c |    4 ++--
>  drivers/usb/gadget/udc/core.c          |    4 ++--
>  include/linux/usb/gadget.h             |    4 ++--
>  6 files changed, 9 insertions(+), 9 deletions(-)
>
> Index: usb-devel/drivers/usb/gadget/composite.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/gadget/composite.c
> +++ usb-devel/drivers/usb/gadget/composite.c
> @@ -2500,7 +2500,7 @@ int usb_composite_probe(struct usb_compo
>         gadget_driver->driver.name = driver->name;
>         gadget_driver->max_speed = driver->max_speed;
>
> -       return usb_gadget_probe_driver(gadget_driver);
> +       return usb_gadget_register_driver(gadget_driver);
>  }
>  EXPORT_SYMBOL_GPL(usb_composite_probe);
>
> Index: usb-devel/drivers/usb/gadget/legacy/dbgp.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/gadget/legacy/dbgp.c
> +++ usb-devel/drivers/usb/gadget/legacy/dbgp.c
> @@ -422,7 +422,7 @@ static struct usb_gadget_driver dbgp_dri
>
>  static int __init dbgp_init(void)
>  {
> -       return usb_gadget_probe_driver(&dbgp_driver);
> +       return usb_gadget_register_driver(&dbgp_driver);
>  }
>
>  static void __exit dbgp_exit(void)
> Index: usb-devel/drivers/usb/gadget/legacy/inode.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/gadget/legacy/inode.c
> +++ usb-devel/drivers/usb/gadget/legacy/inode.c
> @@ -1873,7 +1873,7 @@ dev_config (struct file *fd, const char
>         else
>                 gadgetfs_driver.max_speed = USB_SPEED_FULL;
>
> -       value = usb_gadget_probe_driver(&gadgetfs_driver);
> +       value = usb_gadget_register_driver(&gadgetfs_driver);
>         if (value != 0) {
>                 spin_lock_irq(&dev->lock);
>                 goto fail;
> Index: usb-devel/drivers/usb/gadget/legacy/raw_gadget.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/gadget/legacy/raw_gadget.c
> +++ usb-devel/drivers/usb/gadget/legacy/raw_gadget.c
> @@ -510,12 +510,12 @@ static int raw_ioctl_run(struct raw_dev
>         }
>         spin_unlock_irqrestore(&dev->lock, flags);
>
> -       ret = usb_gadget_probe_driver(&dev->driver);
> +       ret = usb_gadget_register_driver(&dev->driver);
>
>         spin_lock_irqsave(&dev->lock, flags);
>         if (ret) {
>                 dev_err(dev->dev,
> -                       "fail, usb_gadget_probe_driver returned %d\n", ret);
> +                       "fail, usb_gadget_register_driver returned %d\n", ret);
>                 dev->state = STATE_DEV_FAILED;
>                 goto out_unlock;
>         }
> Index: usb-devel/drivers/usb/gadget/udc/core.c
> ===================================================================
> --- usb-devel.orig/drivers/usb/gadget/udc/core.c
> +++ usb-devel/drivers/usb/gadget/udc/core.c
> @@ -1523,7 +1523,7 @@ err1:
>         return ret;
>  }
>
> -int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
> +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
>  {
>         struct usb_udc          *udc = NULL;
>         int                     ret = -ENODEV;
> @@ -1568,7 +1568,7 @@ found:
>         mutex_unlock(&udc_lock);
>         return ret;
>  }
> -EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
> +EXPORT_SYMBOL_GPL(usb_gadget_register_driver);
>
>  int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
>  {
> Index: usb-devel/include/linux/usb/gadget.h
> ===================================================================
> --- usb-devel.orig/include/linux/usb/gadget.h
> +++ usb-devel/include/linux/usb/gadget.h
> @@ -745,7 +745,7 @@ struct usb_gadget_driver {
>   */
>
>  /**
> - * usb_gadget_probe_driver - probe a gadget driver
> + * usb_gadget_register_driver - register a gadget driver
>   * @driver: the driver being registered
>   * Context: can sleep
>   *
> @@ -755,7 +755,7 @@ struct usb_gadget_driver {
>   * registration call returns.  It's expected that the @bind() function will
>   * be in init sections.
>   */
> -int usb_gadget_probe_driver(struct usb_gadget_driver *driver);
> +int usb_gadget_register_driver(struct usb_gadget_driver *driver);
>
>  /**
>   * usb_gadget_unregister_driver - unregister a gadget driver