]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/usb/gadget/composite.c
Use correct spelling of "U-Boot"
[people/ms/u-boot.git] / drivers / usb / gadget / composite.c
index 2c5600ed5210c9da2e2450132d11d1c65a41578e..60f9272ae6d29a356f4e49a031f5631905734038 100644 (file)
@@ -2,21 +2,9 @@
  * composite.c - infrastructure for Composite USB Gadgets
  *
  * Copyright (C) 2006-2008 David Brownell
- * U-boot porting: Lukasz Majewski <l.majewski@samsung.com>
+ * U-Boot porting: Lukasz Majewski <l.majewski@samsung.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 #undef DEBUG
 
@@ -295,7 +283,7 @@ static void device_qual(struct usb_composite_dev *cdev)
        qual->bDeviceSubClass = cdev->desc.bDeviceSubClass;
        qual->bDeviceProtocol = cdev->desc.bDeviceProtocol;
        /* ASSUME same EP0 fifo size at both speeds */
-       qual->bMaxPacketSize0 = cdev->desc.bMaxPacketSize0;
+       qual->bMaxPacketSize0 = cdev->gadget->ep0->maxpacket;
        qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER);
        qual->bRESERVED = 0;
 }
@@ -748,6 +736,8 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                case USB_DT_DEVICE:
                        cdev->desc.bNumConfigurations =
                                count_configs(cdev, USB_DT_DEVICE);
+                       cdev->desc.bMaxPacketSize0 =
+                               cdev->gadget->ep0->maxpacket;
                        value = min(w_length, (u16) sizeof cdev->desc);
                        memcpy(req->buf, &cdev->desc, value);
                        break;
@@ -755,8 +745,8 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                        if (!gadget_is_dualspeed(gadget))
                                break;
                        device_qual(cdev);
-                       value = min(w_length,
-                               sizeof(struct usb_qualifier_descriptor));
+                       value = min_t(int, w_length,
+                                     sizeof(struct usb_qualifier_descriptor));
                        break;
                case USB_DT_OTHER_SPEED_CONFIG:
                        if (!gadget_is_dualspeed(gadget))
@@ -773,6 +763,14 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                        if (value >= 0)
                                value = min(w_length, (u16) value);
                        break;
+               case USB_DT_BOS:
+                       /*
+                        * The USB compliance test (USB 2.0 Command Verifier)
+                        * issues this request. We should not run into the
+                        * default path here. But return for now until
+                        * the superspeed support is added.
+                        */
+                       break;
                default:
                        goto unknown;
                }
@@ -950,6 +948,7 @@ static void composite_unbind(struct usb_gadget *gadget)
                        debug("unbind config '%s'/%p\n", c->label, c);
                        c->unbind(c);
                }
+               free(c);
        }
        if (composite->unbind)
                composite->unbind(cdev);
@@ -997,7 +996,8 @@ static int composite_bind(struct usb_gadget *gadget)
        if (status < 0)
                goto fail;
 
-       cdev->desc = *composite->dev;
+       memcpy(&cdev->desc, composite->dev,
+              sizeof(struct usb_device_descriptor));
        cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 
        debug("%s: ready\n", composite->name);
@@ -1053,6 +1053,7 @@ static struct usb_gadget_driver composite_driver = {
        .unbind         = composite_unbind,
 
        .setup          = composite_setup,
+       .reset          = composite_disconnect,
        .disconnect     = composite_disconnect,
 
        .suspend        = composite_suspend,
@@ -1098,4 +1099,5 @@ void usb_composite_unregister(struct usb_composite_driver *driver)
        if (composite != driver)
                return;
        usb_gadget_unregister_driver(&composite_driver);
+       composite = NULL;
 }