usb: gadget: epautoconf: add endpoint capabilities flags verification
authorRobert Baldyga <r.baldyga@samsung.com>
Fri, 31 Jul 2015 14:00:49 +0000 (16:00 +0200)
committerFelipe Balbi <balbi@ti.com>
Tue, 4 Aug 2015 17:27:11 +0000 (12:27 -0500)
Introduce endpoint matching mechanism basing on endpoint capabilities
flags. We check if endpoint supports transfer type and direction requested
in ep descriptor. Since we have this new endpoint matching mechanism
there is no need to have old code guessing endpoint capabilities basing
on its name, so we are getting rid of it. Remove also the obsolete comment.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/epautoconf.c

index 8e00ca7655496933972725001ab8aa43aa96b91d..af4b10a9068e7289c0f5df7873c6acd531e4ad4c 100644 (file)
 
 #include "gadget_chips.h"
 
-/*
- * This should work with endpoints from controller drivers sharing the
- * same endpoint naming convention.  By example:
- *
- *     - ep1, ep2, ... address is fixed, not direction or type
- *     - ep1in, ep2out, ... address and direction are fixed, not type
- *     - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction
- *     - ep1in-bulk, ep2out-iso, ... all three are fixed
- *     - ep-* ... no functionality restrictions
- *
- * Type suffixes are "-bulk", "-iso", or "-int".  Numbers are decimal.
- * Less common restrictions are implied by gadget_is_*().
- *
- * NOTE:  each endpoint is unidirectional, as specified by its USB
- * descriptor; and isn't specific to a configuration or altsetting.
- */
 static int
 ep_matches (
        struct usb_gadget               *gadget,
@@ -47,7 +31,6 @@ ep_matches (
 )
 {
        u8              type;
-       const char      *tmp;
        u16             max;
 
        int             num_req_streams = 0;
@@ -56,58 +39,39 @@ ep_matches (
        if (ep->claimed)
                return 0;
 
-       /* only support ep0 for portable CONTROL traffic */
        type = usb_endpoint_type(desc);
-       if (USB_ENDPOINT_XFER_CONTROL == type)
-               return 0;
-
-       /* some other naming convention */
-       if ('e' != ep->name[0])
+       switch (type) {
+       case USB_ENDPOINT_XFER_CONTROL:
+               /* only support ep0 for portable CONTROL traffic */
                return 0;
+       case USB_ENDPOINT_XFER_ISOC:
+               if (!ep->caps.type_iso)
+                       return 0;
+               break;
+       case USB_ENDPOINT_XFER_BULK:
+               if (!ep->caps.type_bulk)
+                       return 0;
+               break;
+       case USB_ENDPOINT_XFER_INT:
+               /* bulk endpoints handle interrupt transfers,
+                * except the toggle-quirky iso-synch kind
+                */
+               if (!ep->caps.type_int && !ep->caps.type_bulk)
+                       return 0;
+               /* for now, avoid PXA "interrupt-in";
+                * it's documented as never using DATA1.
+                */
+               if (gadget_is_pxa(gadget) && ep->caps.type_int)
+                       return 0;
+               break;
+       }
 
-       /* type-restriction:  "-iso", "-bulk", or "-int".
-        * direction-restriction:  "in", "out".
-        */
-       if ('-' != ep->name[2]) {
-               tmp = strrchr (ep->name, '-');
-               if (tmp) {
-                       switch (type) {
-                       case USB_ENDPOINT_XFER_INT:
-                               /* bulk endpoints handle interrupt transfers,
-                                * except the toggle-quirky iso-synch kind
-                                */
-                               if ('s' == tmp[2])      // == "-iso"
-                                       return 0;
-                               /* for now, avoid PXA "interrupt-in";
-                                * it's documented as never using DATA1.
-                                */
-                               if (gadget_is_pxa (gadget)
-                                               && 'i' == tmp [1])
-                                       return 0;
-                               break;
-                       case USB_ENDPOINT_XFER_BULK:
-                               if ('b' != tmp[1])      // != "-bulk"
-                                       return 0;
-                               break;
-                       case USB_ENDPOINT_XFER_ISOC:
-                               if ('s' != tmp[2])      // != "-iso"
-                                       return 0;
-                       }
-               } else {
-                       tmp = ep->name + strlen (ep->name);
-               }
-
-               /* direction-restriction:  "..in-..", "out-.." */
-               tmp--;
-               if (!isdigit (*tmp)) {
-                       if (desc->bEndpointAddress & USB_DIR_IN) {
-                               if ('n' != *tmp)
-                                       return 0;
-                       } else {
-                               if ('t' != *tmp)
-                                       return 0;
-                       }
-               }
+       if (usb_endpoint_dir_in(desc)) {
+               if (!ep->caps.dir_in)
+                       return 0;
+       } else {
+               if (!ep->caps.dir_out)
+                       return 0;
        }
 
        /*