usb: gadget: defer setting maxpacket till ->setup()
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 23 Jun 2011 12:26:11 +0000 (14:26 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 1 Jul 2011 21:31:12 +0000 (14:31 -0700)
maxpacket is set by the udc driver for ep0 very early. This value is
copied by the function gadget used later for the USB_DT_DEVICE and
USB_DT_DEVICE_QUALIFIER query. This seems to work fine so far. For USB3
we need set a different value here. In SS speed it is 2^x with x=9 and
in HS we set something <= 64. If the UDC starts in SS and continues in
HS after the cable has been plugged it will report a too small value.
There setting of this value is defered and taken automaticly from the
ep0 pointer where the UDC driver can update it according to the speed it
detected _after_ a cable has been plugged.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/gadget/composite.c
drivers/usb/gadget/dbgp.c
drivers/usb/gadget/file_storage.c
drivers/usb/gadget/gmidi.c
drivers/usb/gadget/inode.c
drivers/usb/gadget/printer.c

index c5abe270970ac6158d176668af091df2c300423f..5ef87794fd328743f635d07fd9b56d3429451d7c 100644 (file)
@@ -573,7 +573,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;
 }
@@ -1450,7 +1450,6 @@ static int composite_bind(struct usb_gadget *gadget)
                goto fail;
 
        cdev->desc = *composite->dev;
-       cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 
        /* standardized runtime overrides for device ID data */
        if (idVendor)
index 052209e89271da9692aa0f63464073f8274e385a..8beefdd367875542e0d3e02c20041ff59a2ffe53 100644 (file)
@@ -314,7 +314,6 @@ static int __init dbgp_bind(struct usb_gadget *gadget)
 
        dbgp.req->length = DBGP_REQ_EP0_LEN;
        gadget->ep0->driver_data = gadget;
-       device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 
 #ifdef CONFIG_USB_G_DBGP_SERIAL
        dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL);
@@ -365,6 +364,7 @@ static int dbgp_setup(struct usb_gadget *gadget,
                        dev_dbg(&dbgp.gadget->dev, "setup: desc device\n");
                        len = sizeof device_desc;
                        data = &device_desc;
+                       device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
                        break;
                case USB_DT_DEBUG:
                        dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n");
index 738591a64bb4525bf45f1f7848dffa5dcb905913..639e14a2fd15e4c5f6fd899f19631ff9beec3212 100644 (file)
@@ -929,6 +929,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
 
                case USB_DT_DEVICE:
                        VDBG(fsg, "get device descriptor\n");
+                       device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
                        value = sizeof device_desc;
                        memcpy(req->buf, &device_desc, value);
                        break;
@@ -936,6 +937,11 @@ static int standard_setup_req(struct fsg_dev *fsg,
                        VDBG(fsg, "get device qualifier\n");
                        if (!gadget_is_dualspeed(fsg->gadget))
                                break;
+                       /*
+                        * Assume ep0 uses the same maxpacket value for both
+                        * speeds
+                        */
+                       dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
                        value = sizeof dev_qualifier;
                        memcpy(req->buf, &dev_qualifier, value);
                        break;
@@ -3417,7 +3423,6 @@ static int __init fsg_bind(struct usb_gadget *gadget)
        }
 
        /* Fix up the descriptors */
-       device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
        device_desc.idVendor = cpu_to_le16(mod_data.vendor);
        device_desc.idProduct = cpu_to_le16(mod_data.product);
        device_desc.bcdDevice = cpu_to_le16(mod_data.release);
@@ -3431,9 +3436,6 @@ static int __init fsg_bind(struct usb_gadget *gadget)
        if (gadget_is_dualspeed(gadget)) {
                fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
 
-               /* Assume ep0 uses the same maxpacket value for both speeds */
-               dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
-
                /* Assume endpoint addresses are the same for both speeds */
                fsg_hs_bulk_in_desc.bEndpointAddress =
                        fsg_fs_bulk_in_desc.bEndpointAddress;
index 4f40f1467438ba7b1022bdbc5bf625711aef0809..8b9220e128a7f8023bea11acb07aa2d67592db0e 100644 (file)
@@ -695,6 +695,7 @@ static int gmidi_setup(struct usb_gadget *gadget,
                switch (w_value >> 8) {
 
                case USB_DT_DEVICE:
+                       device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
                        value = min(w_length, (u16) sizeof(device_desc));
                        memcpy(req->buf, &device_desc, value);
                        break;
@@ -1249,8 +1250,6 @@ autoconf_fail:
 
        dev->req->complete = gmidi_setup_complete;
 
-       device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
-
        gadget->ep0->driver_data = dev;
 
        INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
index a9a455692397e9ed3db8892195efcce925ba626c..1b240990448f05fe25149d9fd21c211499961d4f 100644 (file)
@@ -1347,7 +1347,7 @@ static void make_qualifier (struct dev_data *dev)
        qual.bDeviceProtocol = desc->bDeviceProtocol;
 
        /* assumes ep0 uses the same value for both speeds ... */
-       qual.bMaxPacketSize0 = desc->bMaxPacketSize0;
+       qual.bMaxPacketSize0 = dev->gadget->ep0->maxpacket;
 
        qual.bNumConfigurations = 1;
        qual.bRESERVED = 0;
@@ -1404,7 +1404,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                }
 
                dev->state = STATE_DEV_CONNECTED;
-               dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
 
                INFO (dev, "connected\n");
                event = next_event (dev, GADGETFS_CONNECT);
@@ -1432,6 +1431,7 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 
                case USB_DT_DEVICE:
                        value = min (w_length, (u16) sizeof *dev->dev);
+                       dev->dev->bMaxPacketSize0 = dev->gadget->ep0->maxpacket;
                        req->buf = dev->dev;
                        break;
 #ifdef CONFIG_USB_GADGET_DUALSPEED
@@ -1712,7 +1712,6 @@ gadgetfs_bind (struct usb_gadget *gadget)
        set_gadget_data (gadget, dev);
        dev->gadget = gadget;
        gadget->ep0->driver_data = dev;
-       dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
 
        /* preallocate control response and buffer */
        dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
index 00e5f19c75bac72fda8a1a624ef914f793b916a7..d5df8dd9d58e67ed74c071ecd508ab6580d28d07 100644 (file)
@@ -1148,6 +1148,8 @@ printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                        switch (wValue >> 8) {
 
                        case USB_DT_DEVICE:
+                               device_desc.bMaxPacketSize0 =
+                                       gadget->ep0->maxpacket;
                                value = min(wLength, (u16) sizeof device_desc);
                                memcpy(req->buf, &device_desc, value);
                                break;
@@ -1155,6 +1157,12 @@ printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                        case USB_DT_DEVICE_QUALIFIER:
                                if (!gadget->is_dualspeed)
                                        break;
+                               /*
+                                * assumes ep0 uses the same value for both
+                                * speeds
+                                */
+                               dev_qualifier.bMaxPacketSize0 =
+                                       gadget->ep0->maxpacket;
                                value = min(wLength,
                                                (u16) sizeof dev_qualifier);
                                memcpy(req->buf, &dev_qualifier, value);
@@ -1450,15 +1458,11 @@ autoconf_fail:
        out_ep->driver_data = out_ep;   /* claim */
 
 #ifdef CONFIG_USB_GADGET_DUALSPEED
-       /* assumes ep0 uses the same value for both speeds ... */
-       dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
-
-       /* and that all endpoints are dual-speed */
+       /* assumes that all endpoints are dual-speed */
        hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
        hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
 #endif /* DUALSPEED */
 
-       device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
        usb_gadget_set_selfpowered(gadget);
 
        if (gadget->is_otg) {