usb: gadget: configfs: pass UDC name via usb_gadget_driver struct
authorRuslan Bilovol <ruslan.bilovol@gmail.com>
Mon, 23 Nov 2015 08:56:36 +0000 (09:56 +0100)
committerFelipe Balbi <balbi@ti.com>
Wed, 16 Dec 2015 16:07:26 +0000 (10:07 -0600)
Now when udc-core supports binding to specific UDC by passing
its name via 'udc_name' member of usb_gadget_driver struct,
switch to this generic approach.

Tested-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
[rebased and fixed checkpatch issues]
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/configfs.c

index 163d305e1200bb07a73357d7b5824d97b362b924..590c44989e5eb3dee6f751dc6ce109357eed19f6 100644 (file)
@@ -56,7 +56,6 @@ struct gadget_info {
        struct list_head string_list;
        struct list_head available_func;
 
-       const char *udc_name;
        struct usb_composite_driver composite;
        struct usb_composite_dev cdev;
        bool use_os_desc;
@@ -233,21 +232,23 @@ static ssize_t gadget_dev_desc_bcdUSB_store(struct config_item *item,
 
 static ssize_t gadget_dev_desc_UDC_show(struct config_item *item, char *page)
 {
-       return sprintf(page, "%s\n", to_gadget_info(item)->udc_name ?: "");
+       char *udc_name = to_gadget_info(item)->composite.gadget_driver.udc_name;
+
+       return sprintf(page, "%s\n", udc_name ?: "");
 }
 
 static int unregister_gadget(struct gadget_info *gi)
 {
        int ret;
 
-       if (!gi->udc_name)
+       if (!gi->composite.gadget_driver.udc_name)
                return -ENODEV;
 
        ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver);
        if (ret)
                return ret;
-       kfree(gi->udc_name);
-       gi->udc_name = NULL;
+       kfree(gi->composite.gadget_driver.udc_name);
+       gi->composite.gadget_driver.udc_name = NULL;
        return 0;
 }
 
@@ -271,14 +272,16 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
                if (ret)
                        goto err;
        } else {
-               if (gi->udc_name) {
+               if (gi->composite.gadget_driver.udc_name) {
                        ret = -EBUSY;
                        goto err;
                }
-               ret = usb_udc_attach_driver(name, &gi->composite.gadget_driver);
-               if (ret)
+               gi->composite.gadget_driver.udc_name = name;
+               ret = usb_gadget_probe_driver(&gi->composite.gadget_driver);
+               if (ret) {
+                       gi->composite.gadget_driver.udc_name = NULL;
                        goto err;
-               gi->udc_name = name;
+               }
        }
        mutex_unlock(&gi->lock);
        return len;
@@ -427,9 +430,9 @@ static int config_usb_cfg_unlink(
         * remove the function.
         */
        mutex_lock(&gi->lock);
-       if (gi->udc_name)
+       if (gi->composite.gadget_driver.udc_name)
                unregister_gadget(gi);
-       WARN_ON(gi->udc_name);
+       WARN_ON(gi->composite.gadget_driver.udc_name);
 
        list_for_each_entry(f, &cfg->func_list, list) {
                if (f->fi == fi) {
@@ -873,10 +876,10 @@ static int os_desc_unlink(struct config_item *os_desc_ci,
        struct usb_composite_dev *cdev = &gi->cdev;
 
        mutex_lock(&gi->lock);
-       if (gi->udc_name)
+       if (gi->composite.gadget_driver.udc_name)
                unregister_gadget(gi);
        cdev->os_desc_config = NULL;
-       WARN_ON(gi->udc_name);
+       WARN_ON(gi->composite.gadget_driver.udc_name);
        mutex_unlock(&gi->lock);
        return 0;
 }