usb: gadget: composite: redirect setup requests
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Thu, 7 Nov 2013 07:41:25 +0000 (08:41 +0100)
committerFelipe Balbi <balbi@ti.com>
Tue, 26 Nov 2013 19:40:44 +0000 (13:40 -0600)
If there are setup requests not directed to an endpont or an interface,
current config's setup() has been attempted so far.
This patch, in case the above fails, adds code which tries the setup() of
configuration's function if there is only one function in the configuration.

This behavior is required to provide equivalent of gadget zero with configfs.

The gadget zero has a "config driver" for sourcesink, but all it does is
delegating the request to the function proper. So when the equivalent gadget
is set up with configfs it needs to handle requests directed to
"config driver", but with configfs it is not possible to specify
"config drivers".

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/composite.c

index 3e7ae707f691c4b0cf4b701024d8df0af4a5bb69..611fe89c3a8b24ec3afd3a8d89136a553c1a7313 100644 (file)
@@ -1451,8 +1451,22 @@ unknown:
                        struct usb_configuration        *c;
 
                        c = cdev->config;
-                       if (c && c->setup)
+                       if (!c)
+                               goto done;
+
+                       /* try current config's setup */
+                       if (c->setup) {
                                value = c->setup(c, ctrl);
+                               goto done;
+                       }
+
+                       /* try the only function in the current config */
+                       if (!list_is_singular(&c->functions))
+                               goto done;
+                       f = list_first_entry(&c->functions, struct usb_function,
+                                            list);
+                       if (f->setup)
+                               value = f->setup(f, ctrl);
                }
 
                goto done;