]> git.sur5r.net Git - u-boot/blobdiff - drivers/usb/gadget/epautoconf.c
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot] / drivers / usb / gadget / epautoconf.c
index 0df4b2a103e845953a883f42faac86fe846ee6f4..179b94cdd0ae75759605a2617da9e6a5830de580 100644 (file)
@@ -1,19 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * epautoconf.c -- endpoint autoconfiguration for usb gadget drivers
  *
  * Copyright (C) 2004 David Brownell
  *
- * SPDX-License-Identifier:    GPL-2.0+
- *
- * SPDX-License-Identifier:    GPL-2.0+
- *
- * Ported to U-boot by: Thomas Smits <ts.smits@gmail.com> and
+ * Ported to U-Boot by: Thomas Smits <ts.smits@gmail.com> and
  *                      Remy Bohmer <linux@bohmer.net>
  */
 
 #include <common.h>
 #include <linux/usb/ch9.h>
-#include <asm/errno.h>
+#include <linux/errno.h>
 #include <linux/usb/gadget.h>
 #include <asm/unaligned.h>
 #include "gadget_chips.h"
@@ -220,7 +217,7 @@ struct usb_ep *usb_ep_autoconfig(
        struct usb_endpoint_descriptor  *desc
 )
 {
-       struct usb_ep   *ep;
+       struct usb_ep   *ep = NULL;
        u8              type;
 
        type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
@@ -261,6 +258,28 @@ struct usb_ep *usb_ep_autoconfig(
                ep = find_ep(gadget, "ep1-bulk");
                if (ep && ep_matches(gadget, ep, desc))
                        return ep;
+       } else if (gadget_is_dwc3(gadget)) {
+               const char *name = NULL;
+               /*
+                * First try standard, common configuration: ep1in-bulk,
+                * ep2out-bulk, ep3in-int to match other udc drivers to avoid
+                * confusion in already deployed software (endpoint numbers
+                * hardcoded in userspace software/drivers)
+                */
+               if ((desc->bEndpointAddress & USB_DIR_IN) &&
+                   type == USB_ENDPOINT_XFER_BULK)
+                       name = "ep1in";
+               else if ((desc->bEndpointAddress & USB_DIR_IN) == 0 &&
+                        type == USB_ENDPOINT_XFER_BULK)
+                       name = "ep2out";
+               else if ((desc->bEndpointAddress & USB_DIR_IN) &&
+                        type == USB_ENDPOINT_XFER_INT)
+                       name = "ep3in";
+
+               if (name)
+                       ep = find_ep(gadget, name);
+               if (ep && ep_matches(gadget, ep, desc))
+                       return ep;
        }
 
        /* Second, look at endpoints until an unclaimed one looks usable */