Commit afdaadc3 authored by Ruslan Bilovol's avatar Ruslan Bilovol Committed by Felipe Balbi

usb: gadget: configfs: pass UDC name via usb_gadget_driver struct

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: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: default avatarRuslan Bilovol <ruslan.bilovol@gmail.com>
[rebased and fixed checkpatch issues]
Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Tested-by: default avatarPeter Chen <peter.chen@freescale.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 2284b29d
...@@ -56,7 +56,6 @@ struct gadget_info { ...@@ -56,7 +56,6 @@ struct gadget_info {
struct list_head string_list; struct list_head string_list;
struct list_head available_func; struct list_head available_func;
const char *udc_name;
struct usb_composite_driver composite; struct usb_composite_driver composite;
struct usb_composite_dev cdev; struct usb_composite_dev cdev;
bool use_os_desc; bool use_os_desc;
...@@ -233,21 +232,23 @@ static ssize_t gadget_dev_desc_bcdUSB_store(struct config_item *item, ...@@ -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) 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) static int unregister_gadget(struct gadget_info *gi)
{ {
int ret; int ret;
if (!gi->udc_name) if (!gi->composite.gadget_driver.udc_name)
return -ENODEV; return -ENODEV;
ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver); ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver);
if (ret) if (ret)
return ret; return ret;
kfree(gi->udc_name); kfree(gi->composite.gadget_driver.udc_name);
gi->udc_name = NULL; gi->composite.gadget_driver.udc_name = NULL;
return 0; return 0;
} }
...@@ -271,14 +272,16 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item, ...@@ -271,14 +272,16 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
if (ret) if (ret)
goto err; goto err;
} else { } else {
if (gi->udc_name) { if (gi->composite.gadget_driver.udc_name) {
ret = -EBUSY; ret = -EBUSY;
goto err; goto err;
} }
ret = usb_udc_attach_driver(name, &gi->composite.gadget_driver); gi->composite.gadget_driver.udc_name = name;
if (ret) ret = usb_gadget_probe_driver(&gi->composite.gadget_driver);
if (ret) {
gi->composite.gadget_driver.udc_name = NULL;
goto err; goto err;
gi->udc_name = name; }
} }
mutex_unlock(&gi->lock); mutex_unlock(&gi->lock);
return len; return len;
...@@ -427,9 +430,9 @@ static int config_usb_cfg_unlink( ...@@ -427,9 +430,9 @@ static int config_usb_cfg_unlink(
* remove the function. * remove the function.
*/ */
mutex_lock(&gi->lock); mutex_lock(&gi->lock);
if (gi->udc_name) if (gi->composite.gadget_driver.udc_name)
unregister_gadget(gi); 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) { list_for_each_entry(f, &cfg->func_list, list) {
if (f->fi == fi) { if (f->fi == fi) {
...@@ -873,10 +876,10 @@ static int os_desc_unlink(struct config_item *os_desc_ci, ...@@ -873,10 +876,10 @@ static int os_desc_unlink(struct config_item *os_desc_ci,
struct usb_composite_dev *cdev = &gi->cdev; struct usb_composite_dev *cdev = &gi->cdev;
mutex_lock(&gi->lock); mutex_lock(&gi->lock);
if (gi->udc_name) if (gi->composite.gadget_driver.udc_name)
unregister_gadget(gi); unregister_gadget(gi);
cdev->os_desc_config = NULL; cdev->os_desc_config = NULL;
WARN_ON(gi->udc_name); WARN_ON(gi->composite.gadget_driver.udc_name);
mutex_unlock(&gi->lock); mutex_unlock(&gi->lock);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment