lkml.org 
[lkml]   [2015]   [Feb]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 1/2] usb: gadget: udc-core: independent registration of gadgets and gadget drivers
Date
Change behavior during registration of gadgets and
gadget drivers in udc-core. Instead of previous
approach when for successful probe of usb gadget driver
at least one usb gadget should be already registered
use another one where gadget drivers and gadgets
can be registered in udc-core independently.

Independent registration of gadgets and gadget drivers
is useful for built-in into kernel gadget and gadget
driver case - because it's possible that gadget is
really probed only on late_init stage (due to deferred
probe) whereas gadget driver's probe is silently failed
on module_init stage due to no any UDC added.

Also it is useful for modules case - now there is no
difference what module to insert first: gadget module
or gadget driver one.

Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
---
drivers/usb/gadget/udc/udc-core.c | 77 +++++++++++++++++++++++++++++++++++++--
1 file changed, 74 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
index 5a81cb0..71b6942 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -46,10 +46,18 @@ struct usb_udc {
struct list_head list;
};

+struct pending_gadget_driver {
+ struct usb_gadget_driver *driver;
+ char *udc_name;
+ struct list_head list;
+};
+
static struct class *udc_class;
static LIST_HEAD(udc_list);
+static LIST_HEAD(gadget_driver_pending_list);
static DEFINE_MUTEX(udc_lock);

+static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver);
/* ------------------------------------------------------------------------- */

#ifdef CONFIG_HAS_DMA
@@ -244,6 +252,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
{
struct usb_udc *udc;
int ret = -ENOMEM;
+ struct pending_gadget_driver *pending;

udc = kzalloc(sizeof(*udc), GFP_KERNEL);
if (!udc)
@@ -288,6 +297,24 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,

usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);

+ if (!list_empty(&gadget_driver_pending_list)) {
+ pending = list_first_entry(&gadget_driver_pending_list,
+ struct pending_gadget_driver, list);
+
+ if (pending->udc_name) {
+ if (!strcmp(pending->udc_name, dev_name(&udc->dev))) {
+ udc_bind_to_driver(udc, pending->driver);
+ list_del(&pending->list);
+ kfree(pending->udc_name);
+ kfree(pending);
+ }
+ } else {
+ udc_bind_to_driver(udc, pending->driver);
+ list_del(&pending->list);
+ kfree(pending);
+ }
+ }
+
mutex_unlock(&udc_lock);

return 0;
@@ -423,7 +450,27 @@ int usb_udc_attach_driver(const char *name, struct usb_gadget_driver *driver)
break;
}
if (ret) {
- ret = -ENODEV;
+ struct pending_gadget_driver *pending;
+
+ pending = kzalloc(sizeof(*pending), GFP_KERNEL);
+ if (!pending) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ pending->driver = driver;
+ pending->udc_name = kstrdup(name, GFP_KERNEL);
+ if (!pending->udc_name) {
+ kfree(pending);
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ list_add_tail(&pending->list, &gadget_driver_pending_list);
+
+ pr_info("udc-core: couldn't find the [%s] UDC "
+ "- added [%s] to list of pending drivers\n",
+ name, driver->function);
+ ret = 0;
goto out;
}
if (udc->driver) {
@@ -440,6 +487,7 @@ EXPORT_SYMBOL_GPL(usb_udc_attach_driver);
int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
{
struct usb_udc *udc = NULL;
+ struct pending_gadget_driver *pending;
int ret;

if (!driver || !driver->bind || !driver->setup)
@@ -452,9 +500,20 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
goto found;
}

- pr_debug("couldn't find an available UDC\n");
+ pending = kzalloc(sizeof(*pending), GFP_KERNEL);
+ if (!pending) {
+ mutex_unlock(&udc_lock);
+ return -ENOMEM;
+ }
+ pending->driver = driver;
+ list_add_tail(&pending->list, &gadget_driver_pending_list);
+
+ pr_info("udc-core: couldn't find an available UDC "
+ "- add [%s] to list of pending drivers\n",
+ driver->function);
+
mutex_unlock(&udc_lock);
- return -ENODEV;
+ return 0;
found:
ret = udc_bind_to_driver(udc, driver);
mutex_unlock(&udc_lock);
@@ -465,6 +524,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
{
struct usb_udc *udc = NULL;
+ struct pending_gadget_driver *pending = NULL;
int ret = -ENODEV;

if (!driver || !driver->unbind)
@@ -480,6 +540,17 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
break;
}

+ if (ret) {
+ list_for_each_entry(pending, &gadget_driver_pending_list, list)
+ if (pending->driver == driver) {
+ list_del(&pending->list);
+ kfree(pending->udc_name);
+ kfree(pending);
+ ret = 0;
+ break;
+ }
+ }
+
mutex_unlock(&udc_lock);
return ret;
}
--
1.9.1


\
 
 \ /
  Last update: 2015-02-16 00:21    [W:0.034 / U:8.476 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site