]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/gadget/composite.c
USB: composite: Fix bug: low byte of w_index is the usb interface number not the...
[linux-2.6-omap-h63xx.git] / drivers / usb / gadget / composite.c
index 85c876c1f150b734eb2193e62760bb9f6b972785..5d11c291f1ad113da485076efb4ec9724f253178 100644 (file)
@@ -127,6 +127,70 @@ done:
        return value;
 }
 
+/**
+ * usb_function_deactivate - prevent function and gadget enumeration
+ * @function: the function that isn't yet ready to respond
+ *
+ * Blocks response of the gadget driver to host enumeration by
+ * preventing the data line pullup from being activated.  This is
+ * normally called during @bind() processing to change from the
+ * initial "ready to respond" state, or when a required resource
+ * becomes available.
+ *
+ * For example, drivers that serve as a passthrough to a userspace
+ * daemon can block enumeration unless that daemon (such as an OBEX,
+ * MTP, or print server) is ready to handle host requests.
+ *
+ * Not all systems support software control of their USB peripheral
+ * data pullups.
+ *
+ * Returns zero on success, else negative errno.
+ */
+int usb_function_deactivate(struct usb_function *function)
+{
+       struct usb_composite_dev        *cdev = function->config->cdev;
+       int                             status = 0;
+
+       spin_lock(&cdev->lock);
+
+       if (cdev->deactivations == 0)
+               status = usb_gadget_disconnect(cdev->gadget);
+       if (status == 0)
+               cdev->deactivations++;
+
+       spin_unlock(&cdev->lock);
+       return status;
+}
+
+/**
+ * usb_function_activate - allow function and gadget enumeration
+ * @function: function on which usb_function_activate() was called
+ *
+ * Reverses effect of usb_function_deactivate().  If no more functions
+ * are delaying their activation, the gadget driver will respond to
+ * host enumeration procedures.
+ *
+ * Returns zero on success, else negative errno.
+ */
+int usb_function_activate(struct usb_function *function)
+{
+       struct usb_composite_dev        *cdev = function->config->cdev;
+       int                             status = 0;
+
+       spin_lock(&cdev->lock);
+
+       if (WARN_ON(cdev->deactivations == 0))
+               status = -EINVAL;
+       else {
+               cdev->deactivations--;
+               if (cdev->deactivations == 0)
+                       status = usb_gadget_connect(cdev->gadget);
+       }
+
+       spin_unlock(&cdev->lock);
+       return status;
+}
+
 /**
  * usb_interface_id() - allocate an unused interface ID
  * @config: configuration associated with the interface
@@ -181,7 +245,7 @@ static int config_buf(struct usb_configuration *config,
        c->bConfigurationValue = config->bConfigurationValue;
        c->iConfiguration = config->iConfiguration;
        c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes;
-       c->bMaxPower = config->bMaxPower;
+       c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2);
 
        /* There may be e.g. OTG descriptors */
        if (config->descriptors) {
@@ -368,7 +432,7 @@ static int set_config(struct usb_composite_dev *cdev,
        }
 
        /* when we return, be sure our power usage is valid */
-       power = 2 * c->bMaxPower;
+       power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW;
 done:
        usb_gadget_vbus_draw(gadget, power);
        return result;
@@ -619,6 +683,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
        struct usb_request              *req = cdev->req;
        int                             value = -EOPNOTSUPP;
        u16                             w_index = le16_to_cpu(ctrl->wIndex);
+       u8                              intf = w_index & 0xFF;
        u16                             w_value = le16_to_cpu(ctrl->wValue);
        u16                             w_length = le16_to_cpu(ctrl->wLength);
        struct usb_function             *f = NULL;
@@ -705,10 +770,10 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                        goto unknown;
                if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
                        break;
-               f = cdev->config->interface[w_index];
+               f = cdev->config->interface[intf];
                if (!f)
                        break;
-               if (w_value && !f->get_alt)
+               if (w_value && !f->set_alt)
                        break;
                value = f->set_alt(f, w_index, w_value);
                break;
@@ -717,7 +782,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                        goto unknown;
                if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
                        break;
-               f = cdev->config->interface[w_index];
+               f = cdev->config->interface[intf];
                if (!f)
                        break;
                /* lots of interfaces only need altsetting zero... */
@@ -744,7 +809,7 @@ unknown:
                 */
                if ((ctrl->bRequestType & USB_RECIP_MASK)
                                == USB_RECIP_INTERFACE) {
-                       f = cdev->config->interface[w_index];
+                       f = cdev->config->interface[intf];
                        if (f && f->setup)
                                value = f->setup(f, ctrl);
                        else