usb: gadget: composite: Fix USB CV compliance testing
Petlozu Pravareshwar [Fri, 8 Feb 2013 11:10:04 +0000 (16:10 +0530)]
Enable USB_CONFIG_ATT_SELFPOWER in bmAttributes when the
device is self-powered. Also fixing the GET_CONFIGURATION
when the config field is set to NULL.

Bug 965634

Change-Id: I069da940b1473d5c0b49b2ce2abc7f8862956534
Signed-off-by: Petlozu Pravareshwar <petlozup@nvidia.com>
Reviewed-on: http://git-master/r/197438
Reviewed-by: Venu Byravarasu <vbyravarasu@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Venkat Moganty <vmoganty@nvidia.com>

drivers/usb/gadget/composite.c

index f571572..02bfc64 100644 (file)
@@ -2,6 +2,7 @@
  * composite.c - infrastructure for Composite USB Gadgets
  *
  * Copyright (C) 2006-2008 David Brownell
+ * Copyright (c) 2013 NVIDIA CORPORATION. All rights reserved.
  *
  * 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
@@ -368,6 +369,8 @@ static int config_buf(struct usb_configuration *config,
        c->bConfigurationValue = config->bConfigurationValue;
        c->iConfiguration = config->iConfiguration;
        c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes;
+       if (CONFIG_USB_GADGET_VBUS_DRAW <= USB_SELF_POWER_VBUS_MAX_DRAW)
+               c->bmAttributes |= USB_CONFIG_ATT_SELFPOWER;
        c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2);
 
        /* There may be e.g. OTG descriptors */
@@ -1176,12 +1179,11 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
        case USB_REQ_GET_CONFIGURATION:
                if (ctrl->bRequestType != USB_DIR_IN)
                        goto unknown;
-               if (cdev->config) {
+               if (cdev->config)
                        *(u8 *)req->buf = cdev->config->bConfigurationValue;
-                       value = min(w_length, (u16) 1);
-               } else {
+               else
                        *(u8 *)req->buf = 0;
-               }
+               value = min(w_length, (u16) 1);
                break;
 
        /* function drivers must handle get/set altsetting; if there's