aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/Kconfig2
-rw-r--r--drivers/usb/gadget/amd5536udc.c2
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c20
-rw-r--r--drivers/usb/gadget/cdc2.c8
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c3
-rw-r--r--drivers/usb/gadget/composite.c22
-rw-r--r--drivers/usb/gadget/dummy_hcd.c4
-rw-r--r--drivers/usb/gadget/epautoconf.c2
-rw-r--r--drivers/usb/gadget/ether.c8
-rw-r--r--drivers/usb/gadget/f_acm.c10
-rw-r--r--drivers/usb/gadget/f_ecm.c16
-rw-r--r--drivers/usb/gadget/f_loopback.c10
-rw-r--r--drivers/usb/gadget/f_obex.c12
-rw-r--r--drivers/usb/gadget/f_phonet.c8
-rw-r--r--drivers/usb/gadget/f_rndis.c12
-rw-r--r--drivers/usb/gadget/f_serial.c4
-rw-r--r--drivers/usb/gadget/f_sourcesink.c56
-rw-r--r--drivers/usb/gadget/f_subset.c14
-rw-r--r--drivers/usb/gadget/file_storage.c35
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c46
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c11
-rw-r--r--drivers/usb/gadget/g_zero.h4
-rw-r--r--drivers/usb/gadget/gmidi.c23
-rw-r--r--drivers/usb/gadget/goku_udc.c8
-rw-r--r--drivers/usb/gadget/imx_udc.c250
-rw-r--r--drivers/usb/gadget/imx_udc.h49
-rw-r--r--drivers/usb/gadget/inode.c4
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c16
-rw-r--r--drivers/usb/gadget/net2280.c16
-rw-r--r--drivers/usb/gadget/printer.c18
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c4
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c272
-rw-r--r--drivers/usb/gadget/pxa27x_udc.h10
-rw-r--r--drivers/usb/gadget/rndis.c99
-rw-r--r--drivers/usb/gadget/serial.c12
-rw-r--r--drivers/usb/gadget/u_serial.c2
-rw-r--r--drivers/usb/gadget/zero.c78
37 files changed, 749 insertions, 421 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 3219d137340a..770b3eaa9184 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -191,6 +191,7 @@ config USB_GADGET_OMAP
191 boolean "OMAP USB Device Controller" 191 boolean "OMAP USB Device Controller"
192 depends on ARCH_OMAP 192 depends on ARCH_OMAP
193 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG 193 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG
194 select USB_OTG_UTILS if ARCH_OMAP
194 help 195 help
195 Many Texas Instruments OMAP processors have flexible full 196 Many Texas Instruments OMAP processors have flexible full
196 speed USB device controllers, with support for up to 30 197 speed USB device controllers, with support for up to 30
@@ -253,6 +254,7 @@ config USB_PXA25X_SMALL
253config USB_GADGET_PXA27X 254config USB_GADGET_PXA27X
254 boolean "PXA 27x" 255 boolean "PXA 27x"
255 depends on ARCH_PXA && PXA27x 256 depends on ARCH_PXA && PXA27x
257 select USB_OTG_UTILS
256 help 258 help
257 Intel's PXA 27x series XScale ARM v5TE processors include 259 Intel's PXA 27x series XScale ARM v5TE processors include
258 an integrated full speed USB 1.1 device controller. 260 an integrated full speed USB 1.1 device controller.
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index abf8192f89e8..826f3adde5d8 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -551,7 +551,7 @@ udc_alloc_request(struct usb_ep *usbep, gfp_t gfp)
551 dma_desc->status = AMD_ADDBITS(dma_desc->status, 551 dma_desc->status = AMD_ADDBITS(dma_desc->status,
552 UDC_DMA_STP_STS_BS_HOST_BUSY, 552 UDC_DMA_STP_STS_BS_HOST_BUSY,
553 UDC_DMA_STP_STS_BS); 553 UDC_DMA_STP_STS_BS);
554 dma_desc->bufptr = __constant_cpu_to_le32(DMA_DONT_USE); 554 dma_desc->bufptr = cpu_to_le32(DMA_DONT_USE);
555 req->td_data = dma_desc; 555 req->td_data = dma_desc;
556 req->td_data_last = NULL; 556 req->td_data_last = NULL;
557 req->chain_len = 1; 557 req->chain_len = 1;
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index ee7ebb674416..563d57275448 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1017,7 +1017,7 @@ static struct usb_endpoint_descriptor usba_ep0_desc = {
1017 .bDescriptorType = USB_DT_ENDPOINT, 1017 .bDescriptorType = USB_DT_ENDPOINT,
1018 .bEndpointAddress = 0, 1018 .bEndpointAddress = 0,
1019 .bmAttributes = USB_ENDPOINT_XFER_CONTROL, 1019 .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
1020 .wMaxPacketSize = __constant_cpu_to_le16(64), 1020 .wMaxPacketSize = cpu_to_le16(64),
1021 /* FIXME: I have no idea what to put here */ 1021 /* FIXME: I have no idea what to put here */
1022 .bInterval = 1, 1022 .bInterval = 1,
1023}; 1023};
@@ -1207,21 +1207,21 @@ static int do_test_mode(struct usba_udc *udc)
1207/* Avoid overly long expressions */ 1207/* Avoid overly long expressions */
1208static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq) 1208static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq)
1209{ 1209{
1210 if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP)) 1210 if (crq->wValue == cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP))
1211 return true; 1211 return true;
1212 return false; 1212 return false;
1213} 1213}
1214 1214
1215static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq) 1215static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq)
1216{ 1216{
1217 if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_TEST_MODE)) 1217 if (crq->wValue == cpu_to_le16(USB_DEVICE_TEST_MODE))
1218 return true; 1218 return true;
1219 return false; 1219 return false;
1220} 1220}
1221 1221
1222static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq) 1222static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
1223{ 1223{
1224 if (crq->wValue == __constant_cpu_to_le16(USB_ENDPOINT_HALT)) 1224 if (crq->wValue == cpu_to_le16(USB_ENDPOINT_HALT))
1225 return true; 1225 return true;
1226 return false; 1226 return false;
1227} 1227}
@@ -1239,7 +1239,7 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1239 status = cpu_to_le16(udc->devstatus); 1239 status = cpu_to_le16(udc->devstatus);
1240 } else if (crq->bRequestType 1240 } else if (crq->bRequestType
1241 == (USB_DIR_IN | USB_RECIP_INTERFACE)) { 1241 == (USB_DIR_IN | USB_RECIP_INTERFACE)) {
1242 status = __constant_cpu_to_le16(0); 1242 status = cpu_to_le16(0);
1243 } else if (crq->bRequestType 1243 } else if (crq->bRequestType
1244 == (USB_DIR_IN | USB_RECIP_ENDPOINT)) { 1244 == (USB_DIR_IN | USB_RECIP_ENDPOINT)) {
1245 struct usba_ep *target; 1245 struct usba_ep *target;
@@ -1250,12 +1250,12 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1250 1250
1251 status = 0; 1251 status = 0;
1252 if (is_stalled(udc, target)) 1252 if (is_stalled(udc, target))
1253 status |= __constant_cpu_to_le16(1); 1253 status |= cpu_to_le16(1);
1254 } else 1254 } else
1255 goto delegate; 1255 goto delegate;
1256 1256
1257 /* Write directly to the FIFO. No queueing is done. */ 1257 /* Write directly to the FIFO. No queueing is done. */
1258 if (crq->wLength != __constant_cpu_to_le16(sizeof(status))) 1258 if (crq->wLength != cpu_to_le16(sizeof(status)))
1259 goto stall; 1259 goto stall;
1260 ep->state = DATA_STAGE_IN; 1260 ep->state = DATA_STAGE_IN;
1261 __raw_writew(status, ep->fifo); 1261 __raw_writew(status, ep->fifo);
@@ -1274,7 +1274,7 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1274 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) { 1274 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
1275 struct usba_ep *target; 1275 struct usba_ep *target;
1276 1276
1277 if (crq->wLength != __constant_cpu_to_le16(0) 1277 if (crq->wLength != cpu_to_le16(0)
1278 || !feature_is_ep_halt(crq)) 1278 || !feature_is_ep_halt(crq))
1279 goto stall; 1279 goto stall;
1280 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); 1280 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
@@ -1308,7 +1308,7 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1308 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) { 1308 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
1309 struct usba_ep *target; 1309 struct usba_ep *target;
1310 1310
1311 if (crq->wLength != __constant_cpu_to_le16(0) 1311 if (crq->wLength != cpu_to_le16(0)
1312 || !feature_is_ep_halt(crq)) 1312 || !feature_is_ep_halt(crq))
1313 goto stall; 1313 goto stall;
1314 1314
@@ -1514,7 +1514,7 @@ restart:
1514 */ 1514 */
1515 ep->state = DATA_STAGE_IN; 1515 ep->state = DATA_STAGE_IN;
1516 } else { 1516 } else {
1517 if (crq.crq.wLength != __constant_cpu_to_le16(0)) 1517 if (crq.crq.wLength != cpu_to_le16(0))
1518 ep->state = DATA_STAGE_OUT; 1518 ep->state = DATA_STAGE_OUT;
1519 else 1519 else
1520 ep->state = STATUS_STAGE_IN; 1520 ep->state = STATUS_STAGE_IN;
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 5495b171cf29..928137d3dbdc 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -66,7 +66,7 @@ static struct usb_device_descriptor device_desc = {
66 .bLength = sizeof device_desc, 66 .bLength = sizeof device_desc,
67 .bDescriptorType = USB_DT_DEVICE, 67 .bDescriptorType = USB_DT_DEVICE,
68 68
69 .bcdUSB = __constant_cpu_to_le16(0x0200), 69 .bcdUSB = cpu_to_le16(0x0200),
70 70
71 .bDeviceClass = USB_CLASS_COMM, 71 .bDeviceClass = USB_CLASS_COMM,
72 .bDeviceSubClass = 0, 72 .bDeviceSubClass = 0,
@@ -74,8 +74,8 @@ static struct usb_device_descriptor device_desc = {
74 /* .bMaxPacketSize0 = f(hardware) */ 74 /* .bMaxPacketSize0 = f(hardware) */
75 75
76 /* Vendor and product id can be overridden by module parameters. */ 76 /* Vendor and product id can be overridden by module parameters. */
77 .idVendor = __constant_cpu_to_le16(CDC_VENDOR_NUM), 77 .idVendor = cpu_to_le16(CDC_VENDOR_NUM),
78 .idProduct = __constant_cpu_to_le16(CDC_PRODUCT_NUM), 78 .idProduct = cpu_to_le16(CDC_PRODUCT_NUM),
79 /* .bcdDevice = f(hardware) */ 79 /* .bcdDevice = f(hardware) */
80 /* .iManufacturer = DYNAMIC */ 80 /* .iManufacturer = DYNAMIC */
81 /* .iProduct = DYNAMIC */ 81 /* .iProduct = DYNAMIC */
@@ -193,7 +193,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
193 gadget->name, 193 gadget->name,
194 cdc_config_driver.label); 194 cdc_config_driver.label);
195 device_desc.bcdDevice = 195 device_desc.bcdDevice =
196 __constant_cpu_to_le16(0x0300 | 0x0099); 196 cpu_to_le16(0x0300 | 0x0099);
197 } 197 }
198 198
199 199
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index bebf911c7e5f..22c65960c429 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -56,7 +56,6 @@
56#include <linux/dma-mapping.h> 56#include <linux/dma-mapping.h>
57#include <linux/init.h> 57#include <linux/init.h>
58#include <linux/interrupt.h> 58#include <linux/interrupt.h>
59#include <linux/interrupt.h>
60#include <linux/io.h> 59#include <linux/io.h>
61#include <linux/irq.h> 60#include <linux/irq.h>
62#include <linux/kernel.h> 61#include <linux/kernel.h>
@@ -2626,7 +2625,7 @@ static int udc_probe(struct device *dev, void __iomem *regs, const char *name)
2626 INIT_LIST_HEAD(&udc->gadget.ep_list); 2625 INIT_LIST_HEAD(&udc->gadget.ep_list);
2627 udc->gadget.ep0 = NULL; 2626 udc->gadget.ep0 = NULL;
2628 2627
2629 strcpy(udc->gadget.dev.bus_id, "gadget"); 2628 dev_set_name(&udc->gadget.dev, "gadget");
2630 udc->gadget.dev.dma_mask = dev->dma_mask; 2629 udc->gadget.dev.dma_mask = dev->dma_mask;
2631 udc->gadget.dev.parent = dev; 2630 udc->gadget.dev.parent = dev;
2632 udc->gadget.dev.release = udc_release; 2631 udc->gadget.dev.release = udc_release;
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index f2da0269e1b1..59e85234fa0a 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -149,16 +149,17 @@ done:
149int usb_function_deactivate(struct usb_function *function) 149int usb_function_deactivate(struct usb_function *function)
150{ 150{
151 struct usb_composite_dev *cdev = function->config->cdev; 151 struct usb_composite_dev *cdev = function->config->cdev;
152 unsigned long flags;
152 int status = 0; 153 int status = 0;
153 154
154 spin_lock(&cdev->lock); 155 spin_lock_irqsave(&cdev->lock, flags);
155 156
156 if (cdev->deactivations == 0) 157 if (cdev->deactivations == 0)
157 status = usb_gadget_disconnect(cdev->gadget); 158 status = usb_gadget_disconnect(cdev->gadget);
158 if (status == 0) 159 if (status == 0)
159 cdev->deactivations++; 160 cdev->deactivations++;
160 161
161 spin_unlock(&cdev->lock); 162 spin_unlock_irqrestore(&cdev->lock, flags);
162 return status; 163 return status;
163} 164}
164 165
@@ -683,6 +684,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
683 struct usb_request *req = cdev->req; 684 struct usb_request *req = cdev->req;
684 int value = -EOPNOTSUPP; 685 int value = -EOPNOTSUPP;
685 u16 w_index = le16_to_cpu(ctrl->wIndex); 686 u16 w_index = le16_to_cpu(ctrl->wIndex);
687 u8 intf = w_index & 0xFF;
686 u16 w_value = le16_to_cpu(ctrl->wValue); 688 u16 w_value = le16_to_cpu(ctrl->wValue);
687 u16 w_length = le16_to_cpu(ctrl->wLength); 689 u16 w_length = le16_to_cpu(ctrl->wLength);
688 struct usb_function *f = NULL; 690 struct usb_function *f = NULL;
@@ -769,10 +771,10 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
769 goto unknown; 771 goto unknown;
770 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 772 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
771 break; 773 break;
772 f = cdev->config->interface[w_index]; 774 f = cdev->config->interface[intf];
773 if (!f) 775 if (!f)
774 break; 776 break;
775 if (w_value && !f->get_alt) 777 if (w_value && !f->set_alt)
776 break; 778 break;
777 value = f->set_alt(f, w_index, w_value); 779 value = f->set_alt(f, w_index, w_value);
778 break; 780 break;
@@ -781,7 +783,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
781 goto unknown; 783 goto unknown;
782 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 784 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
783 break; 785 break;
784 f = cdev->config->interface[w_index]; 786 f = cdev->config->interface[intf];
785 if (!f) 787 if (!f)
786 break; 788 break;
787 /* lots of interfaces only need altsetting zero... */ 789 /* lots of interfaces only need altsetting zero... */
@@ -808,7 +810,7 @@ unknown:
808 */ 810 */
809 if ((ctrl->bRequestType & USB_RECIP_MASK) 811 if ((ctrl->bRequestType & USB_RECIP_MASK)
810 == USB_RECIP_INTERFACE) { 812 == USB_RECIP_INTERFACE) {
811 f = cdev->config->interface[w_index]; 813 f = cdev->config->interface[intf];
812 if (f && f->setup) 814 if (f && f->setup)
813 value = f->setup(f, ctrl); 815 value = f->setup(f, ctrl);
814 else 816 else
@@ -1012,7 +1014,7 @@ composite_suspend(struct usb_gadget *gadget)
1012 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1014 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1013 struct usb_function *f; 1015 struct usb_function *f;
1014 1016
1015 /* REVISIT: should we have config and device level 1017 /* REVISIT: should we have config level
1016 * suspend/resume callbacks? 1018 * suspend/resume callbacks?
1017 */ 1019 */
1018 DBG(cdev, "suspend\n"); 1020 DBG(cdev, "suspend\n");
@@ -1022,6 +1024,8 @@ composite_suspend(struct usb_gadget *gadget)
1022 f->suspend(f); 1024 f->suspend(f);
1023 } 1025 }
1024 } 1026 }
1027 if (composite->suspend)
1028 composite->suspend(cdev);
1025} 1029}
1026 1030
1027static void 1031static void
@@ -1030,10 +1034,12 @@ composite_resume(struct usb_gadget *gadget)
1030 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1034 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1031 struct usb_function *f; 1035 struct usb_function *f;
1032 1036
1033 /* REVISIT: should we have config and device level 1037 /* REVISIT: should we have config level
1034 * suspend/resume callbacks? 1038 * suspend/resume callbacks?
1035 */ 1039 */
1036 DBG(cdev, "resume\n"); 1040 DBG(cdev, "resume\n");
1041 if (composite->resume)
1042 composite->resume(cdev);
1037 if (cdev->config) { 1043 if (cdev->config) {
1038 list_for_each_entry(f, &cdev->config->functions, list) { 1044 list_for_each_entry(f, &cdev->config->functions, list) {
1039 if (f->resume) 1045 if (f->resume)
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 9064696636ac..a56b24d305f8 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -1437,7 +1437,7 @@ restart:
1437 } 1437 }
1438 if (urb->transfer_buffer_length > 1) 1438 if (urb->transfer_buffer_length > 1)
1439 buf [1] = 0; 1439 buf [1] = 0;
1440 urb->actual_length = min (2, 1440 urb->actual_length = min_t(u32, 2,
1441 urb->transfer_buffer_length); 1441 urb->transfer_buffer_length);
1442 value = 0; 1442 value = 0;
1443 status = 0; 1443 status = 0;
@@ -1626,7 +1626,7 @@ static int dummy_hub_control (
1626 hub_descriptor ((struct usb_hub_descriptor *) buf); 1626 hub_descriptor ((struct usb_hub_descriptor *) buf);
1627 break; 1627 break;
1628 case GetHubStatus: 1628 case GetHubStatus:
1629 *(__le32 *) buf = __constant_cpu_to_le32 (0); 1629 *(__le32 *) buf = cpu_to_le32 (0);
1630 break; 1630 break;
1631 case GetPortStatus: 1631 case GetPortStatus:
1632 if (wIndex != 1) 1632 if (wIndex != 1)
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index a36b1175b18d..cd0914ec898e 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -148,7 +148,7 @@ ep_matches (
148 return 0; 148 return 0;
149 149
150 /* BOTH: "high bandwidth" works only at high speed */ 150 /* BOTH: "high bandwidth" works only at high speed */
151 if ((desc->wMaxPacketSize & __constant_cpu_to_le16(3<<11))) { 151 if ((desc->wMaxPacketSize & cpu_to_le16(3<<11))) {
152 if (!gadget->is_dualspeed) 152 if (!gadget->is_dualspeed)
153 return 0; 153 return 0;
154 /* configure your hardware with enough buffering!! */ 154 /* configure your hardware with enough buffering!! */
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 37252d0012a7..d006dc652e02 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -156,7 +156,7 @@ static struct usb_device_descriptor device_desc = {
156 .bLength = sizeof device_desc, 156 .bLength = sizeof device_desc,
157 .bDescriptorType = USB_DT_DEVICE, 157 .bDescriptorType = USB_DT_DEVICE,
158 158
159 .bcdUSB = __constant_cpu_to_le16 (0x0200), 159 .bcdUSB = cpu_to_le16 (0x0200),
160 160
161 .bDeviceClass = USB_CLASS_COMM, 161 .bDeviceClass = USB_CLASS_COMM,
162 .bDeviceSubClass = 0, 162 .bDeviceSubClass = 0,
@@ -167,8 +167,8 @@ static struct usb_device_descriptor device_desc = {
167 * we support. (As does bNumConfigurations.) These values can 167 * we support. (As does bNumConfigurations.) These values can
168 * also be overridden by module parameters. 168 * also be overridden by module parameters.
169 */ 169 */
170 .idVendor = __constant_cpu_to_le16 (CDC_VENDOR_NUM), 170 .idVendor = cpu_to_le16 (CDC_VENDOR_NUM),
171 .idProduct = __constant_cpu_to_le16 (CDC_PRODUCT_NUM), 171 .idProduct = cpu_to_le16 (CDC_PRODUCT_NUM),
172 /* .bcdDevice = f(hardware) */ 172 /* .bcdDevice = f(hardware) */
173 /* .iManufacturer = DYNAMIC */ 173 /* .iManufacturer = DYNAMIC */
174 /* .iProduct = DYNAMIC */ 174 /* .iProduct = DYNAMIC */
@@ -318,7 +318,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
318 gadget->name, 318 gadget->name,
319 eth_config_driver.label); 319 eth_config_driver.label);
320 device_desc.bcdDevice = 320 device_desc.bcdDevice =
321 __constant_cpu_to_le16(0x0300 | 0x0099); 321 cpu_to_le16(0x0300 | 0x0099);
322 } 322 }
323 323
324 324
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index c1d34df0b157..7953948bfe4a 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -125,7 +125,7 @@ static struct usb_cdc_header_desc acm_header_desc __initdata = {
125 .bLength = sizeof(acm_header_desc), 125 .bLength = sizeof(acm_header_desc),
126 .bDescriptorType = USB_DT_CS_INTERFACE, 126 .bDescriptorType = USB_DT_CS_INTERFACE,
127 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 127 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
128 .bcdCDC = __constant_cpu_to_le16(0x0110), 128 .bcdCDC = cpu_to_le16(0x0110),
129}; 129};
130 130
131static struct usb_cdc_call_mgmt_descriptor 131static struct usb_cdc_call_mgmt_descriptor
@@ -159,7 +159,7 @@ static struct usb_endpoint_descriptor acm_fs_notify_desc __initdata = {
159 .bDescriptorType = USB_DT_ENDPOINT, 159 .bDescriptorType = USB_DT_ENDPOINT,
160 .bEndpointAddress = USB_DIR_IN, 160 .bEndpointAddress = USB_DIR_IN,
161 .bmAttributes = USB_ENDPOINT_XFER_INT, 161 .bmAttributes = USB_ENDPOINT_XFER_INT,
162 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET), 162 .wMaxPacketSize = cpu_to_le16(GS_NOTIFY_MAXPACKET),
163 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL, 163 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL,
164}; 164};
165 165
@@ -197,7 +197,7 @@ static struct usb_endpoint_descriptor acm_hs_notify_desc __initdata = {
197 .bDescriptorType = USB_DT_ENDPOINT, 197 .bDescriptorType = USB_DT_ENDPOINT,
198 .bEndpointAddress = USB_DIR_IN, 198 .bEndpointAddress = USB_DIR_IN,
199 .bmAttributes = USB_ENDPOINT_XFER_INT, 199 .bmAttributes = USB_ENDPOINT_XFER_INT,
200 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET), 200 .wMaxPacketSize = cpu_to_le16(GS_NOTIFY_MAXPACKET),
201 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4, 201 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4,
202}; 202};
203 203
@@ -205,14 +205,14 @@ static struct usb_endpoint_descriptor acm_hs_in_desc __initdata = {
205 .bLength = USB_DT_ENDPOINT_SIZE, 205 .bLength = USB_DT_ENDPOINT_SIZE,
206 .bDescriptorType = USB_DT_ENDPOINT, 206 .bDescriptorType = USB_DT_ENDPOINT,
207 .bmAttributes = USB_ENDPOINT_XFER_BULK, 207 .bmAttributes = USB_ENDPOINT_XFER_BULK,
208 .wMaxPacketSize = __constant_cpu_to_le16(512), 208 .wMaxPacketSize = cpu_to_le16(512),
209}; 209};
210 210
211static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = { 211static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = {
212 .bLength = USB_DT_ENDPOINT_SIZE, 212 .bLength = USB_DT_ENDPOINT_SIZE,
213 .bDescriptorType = USB_DT_ENDPOINT, 213 .bDescriptorType = USB_DT_ENDPOINT,
214 .bmAttributes = USB_ENDPOINT_XFER_BULK, 214 .bmAttributes = USB_ENDPOINT_XFER_BULK,
215 .wMaxPacketSize = __constant_cpu_to_le16(512), 215 .wMaxPacketSize = cpu_to_le16(512),
216}; 216};
217 217
218static struct usb_descriptor_header *acm_hs_function[] __initdata = { 218static struct usb_descriptor_header *acm_hs_function[] __initdata = {
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index 4ae579948e54..ecf5bdd0ae06 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -130,7 +130,7 @@ static struct usb_cdc_header_desc ecm_header_desc __initdata = {
130 .bDescriptorType = USB_DT_CS_INTERFACE, 130 .bDescriptorType = USB_DT_CS_INTERFACE,
131 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 131 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
132 132
133 .bcdCDC = __constant_cpu_to_le16(0x0110), 133 .bcdCDC = cpu_to_le16(0x0110),
134}; 134};
135 135
136static struct usb_cdc_union_desc ecm_union_desc __initdata = { 136static struct usb_cdc_union_desc ecm_union_desc __initdata = {
@@ -148,9 +148,9 @@ static struct usb_cdc_ether_desc ecm_desc __initdata = {
148 148
149 /* this descriptor actually adds value, surprise! */ 149 /* this descriptor actually adds value, surprise! */
150 /* .iMACAddress = DYNAMIC */ 150 /* .iMACAddress = DYNAMIC */
151 .bmEthernetStatistics = __constant_cpu_to_le32(0), /* no statistics */ 151 .bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
152 .wMaxSegmentSize = __constant_cpu_to_le16(ETH_FRAME_LEN), 152 .wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
153 .wNumberMCFilters = __constant_cpu_to_le16(0), 153 .wNumberMCFilters = cpu_to_le16(0),
154 .bNumberPowerFilters = 0, 154 .bNumberPowerFilters = 0,
155}; 155};
156 156
@@ -192,7 +192,7 @@ static struct usb_endpoint_descriptor fs_ecm_notify_desc __initdata = {
192 192
193 .bEndpointAddress = USB_DIR_IN, 193 .bEndpointAddress = USB_DIR_IN,
194 .bmAttributes = USB_ENDPOINT_XFER_INT, 194 .bmAttributes = USB_ENDPOINT_XFER_INT,
195 .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT), 195 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
196 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, 196 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
197}; 197};
198 198
@@ -236,7 +236,7 @@ static struct usb_endpoint_descriptor hs_ecm_notify_desc __initdata = {
236 236
237 .bEndpointAddress = USB_DIR_IN, 237 .bEndpointAddress = USB_DIR_IN,
238 .bmAttributes = USB_ENDPOINT_XFER_INT, 238 .bmAttributes = USB_ENDPOINT_XFER_INT,
239 .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT), 239 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
240 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 240 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
241}; 241};
242static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = { 242static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = {
@@ -245,7 +245,7 @@ static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = {
245 245
246 .bEndpointAddress = USB_DIR_IN, 246 .bEndpointAddress = USB_DIR_IN,
247 .bmAttributes = USB_ENDPOINT_XFER_BULK, 247 .bmAttributes = USB_ENDPOINT_XFER_BULK,
248 .wMaxPacketSize = __constant_cpu_to_le16(512), 248 .wMaxPacketSize = cpu_to_le16(512),
249}; 249};
250 250
251static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = { 251static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = {
@@ -254,7 +254,7 @@ static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = {
254 254
255 .bEndpointAddress = USB_DIR_OUT, 255 .bEndpointAddress = USB_DIR_OUT,
256 .bmAttributes = USB_ENDPOINT_XFER_BULK, 256 .bmAttributes = USB_ENDPOINT_XFER_BULK,
257 .wMaxPacketSize = __constant_cpu_to_le16(512), 257 .wMaxPacketSize = cpu_to_le16(512),
258}; 258};
259 259
260static struct usb_descriptor_header *ecm_hs_function[] __initdata = { 260static struct usb_descriptor_header *ecm_hs_function[] __initdata = {
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index 8affe1dfc2c1..eb6ddfc20857 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -100,7 +100,7 @@ static struct usb_endpoint_descriptor hs_loop_source_desc = {
100 .bDescriptorType = USB_DT_ENDPOINT, 100 .bDescriptorType = USB_DT_ENDPOINT,
101 101
102 .bmAttributes = USB_ENDPOINT_XFER_BULK, 102 .bmAttributes = USB_ENDPOINT_XFER_BULK,
103 .wMaxPacketSize = __constant_cpu_to_le16(512), 103 .wMaxPacketSize = cpu_to_le16(512),
104}; 104};
105 105
106static struct usb_endpoint_descriptor hs_loop_sink_desc = { 106static struct usb_endpoint_descriptor hs_loop_sink_desc = {
@@ -108,7 +108,7 @@ static struct usb_endpoint_descriptor hs_loop_sink_desc = {
108 .bDescriptorType = USB_DT_ENDPOINT, 108 .bDescriptorType = USB_DT_ENDPOINT,
109 109
110 .bmAttributes = USB_ENDPOINT_XFER_BULK, 110 .bmAttributes = USB_ENDPOINT_XFER_BULK,
111 .wMaxPacketSize = __constant_cpu_to_le16(512), 111 .wMaxPacketSize = cpu_to_le16(512),
112}; 112};
113 113
114static struct usb_descriptor_header *hs_loopback_descs[] = { 114static struct usb_descriptor_header *hs_loopback_descs[] = {
@@ -359,7 +359,7 @@ static struct usb_configuration loopback_driver = {
359 * loopback_add - add a loopback testing configuration to a device 359 * loopback_add - add a loopback testing configuration to a device
360 * @cdev: the device to support the loopback configuration 360 * @cdev: the device to support the loopback configuration
361 */ 361 */
362int __init loopback_add(struct usb_composite_dev *cdev) 362int __init loopback_add(struct usb_composite_dev *cdev, bool autoresume)
363{ 363{
364 int id; 364 int id;
365 365
@@ -372,6 +372,10 @@ int __init loopback_add(struct usb_composite_dev *cdev)
372 loopback_intf.iInterface = id; 372 loopback_intf.iInterface = id;
373 loopback_driver.iConfiguration = id; 373 loopback_driver.iConfiguration = id;
374 374
375 /* support autoresume for remote wakeup testing */
376 if (autoresume)
377 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
378
375 /* support OTG systems */ 379 /* support OTG systems */
376 if (gadget_is_otg(cdev->gadget)) { 380 if (gadget_is_otg(cdev->gadget)) {
377 loopback_driver.descriptors = otg_desc; 381 loopback_driver.descriptors = otg_desc;
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index 80c2e7e9622f..46d6266f30ec 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -123,7 +123,7 @@ static struct usb_cdc_header_desc obex_cdc_header_desc __initdata = {
123 .bLength = sizeof(obex_cdc_header_desc), 123 .bLength = sizeof(obex_cdc_header_desc),
124 .bDescriptorType = USB_DT_CS_INTERFACE, 124 .bDescriptorType = USB_DT_CS_INTERFACE,
125 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 125 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
126 .bcdCDC = __constant_cpu_to_le16(0x0120), 126 .bcdCDC = cpu_to_le16(0x0120),
127}; 127};
128 128
129static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = { 129static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = {
@@ -138,7 +138,7 @@ static struct usb_cdc_obex_desc obex_desc __initdata = {
138 .bLength = sizeof(obex_desc), 138 .bLength = sizeof(obex_desc),
139 .bDescriptorType = USB_DT_CS_INTERFACE, 139 .bDescriptorType = USB_DT_CS_INTERFACE,
140 .bDescriptorSubType = USB_CDC_OBEX_TYPE, 140 .bDescriptorSubType = USB_CDC_OBEX_TYPE,
141 .bcdVersion = __constant_cpu_to_le16(0x0100), 141 .bcdVersion = cpu_to_le16(0x0100),
142}; 142};
143 143
144/* High-Speed Support */ 144/* High-Speed Support */
@@ -149,7 +149,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = {
149 149
150 .bEndpointAddress = USB_DIR_OUT, 150 .bEndpointAddress = USB_DIR_OUT,
151 .bmAttributes = USB_ENDPOINT_XFER_BULK, 151 .bmAttributes = USB_ENDPOINT_XFER_BULK,
152 .wMaxPacketSize = __constant_cpu_to_le16(512), 152 .wMaxPacketSize = cpu_to_le16(512),
153}; 153};
154 154
155static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = { 155static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = {
@@ -158,7 +158,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = {
158 158
159 .bEndpointAddress = USB_DIR_IN, 159 .bEndpointAddress = USB_DIR_IN,
160 .bmAttributes = USB_ENDPOINT_XFER_BULK, 160 .bmAttributes = USB_ENDPOINT_XFER_BULK,
161 .wMaxPacketSize = __constant_cpu_to_le16(512), 161 .wMaxPacketSize = cpu_to_le16(512),
162}; 162};
163 163
164static struct usb_descriptor_header *hs_function[] __initdata = { 164static struct usb_descriptor_header *hs_function[] __initdata = {
@@ -366,9 +366,9 @@ obex_bind(struct usb_configuration *c, struct usb_function *f)
366 f->hs_descriptors = usb_copy_descriptors(hs_function); 366 f->hs_descriptors = usb_copy_descriptors(hs_function);
367 367
368 obex->hs.obex_in = usb_find_endpoint(hs_function, 368 obex->hs.obex_in = usb_find_endpoint(hs_function,
369 f->descriptors, &obex_hs_ep_in_desc); 369 f->hs_descriptors, &obex_hs_ep_in_desc);
370 obex->hs.obex_out = usb_find_endpoint(hs_function, 370 obex->hs.obex_out = usb_find_endpoint(hs_function,
371 f->descriptors, &obex_hs_ep_out_desc); 371 f->hs_descriptors, &obex_hs_ep_out_desc);
372 } 372 }
373 373
374 /* Avoid letting this gadget enumerate until the userspace 374 /* Avoid letting this gadget enumerate until the userspace
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index c0916c7b217e..c1abeb89b413 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -79,7 +79,7 @@ pn_header_desc = {
79 .bLength = sizeof pn_header_desc, 79 .bLength = sizeof pn_header_desc,
80 .bDescriptorType = USB_DT_CS_INTERFACE, 80 .bDescriptorType = USB_DT_CS_INTERFACE,
81 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 81 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
82 .bcdCDC = __constant_cpu_to_le16(0x0110), 82 .bcdCDC = cpu_to_le16(0x0110),
83}; 83};
84 84
85static const struct usb_cdc_header_desc 85static const struct usb_cdc_header_desc
@@ -87,7 +87,7 @@ pn_phonet_desc = {
87 .bLength = sizeof pn_phonet_desc, 87 .bLength = sizeof pn_phonet_desc,
88 .bDescriptorType = USB_DT_CS_INTERFACE, 88 .bDescriptorType = USB_DT_CS_INTERFACE,
89 .bDescriptorSubType = USB_CDC_PHONET_TYPE, 89 .bDescriptorSubType = USB_CDC_PHONET_TYPE,
90 .bcdCDC = __constant_cpu_to_le16(0x1505), /* ??? */ 90 .bcdCDC = cpu_to_le16(0x1505), /* ??? */
91}; 91};
92 92
93static struct usb_cdc_union_desc 93static struct usb_cdc_union_desc
@@ -138,7 +138,7 @@ pn_hs_sink_desc = {
138 138
139 .bEndpointAddress = USB_DIR_OUT, 139 .bEndpointAddress = USB_DIR_OUT,
140 .bmAttributes = USB_ENDPOINT_XFER_BULK, 140 .bmAttributes = USB_ENDPOINT_XFER_BULK,
141 .wMaxPacketSize = __constant_cpu_to_le16(512), 141 .wMaxPacketSize = cpu_to_le16(512),
142}; 142};
143 143
144static struct usb_endpoint_descriptor 144static struct usb_endpoint_descriptor
@@ -157,7 +157,7 @@ pn_hs_source_desc = {
157 157
158 .bEndpointAddress = USB_DIR_IN, 158 .bEndpointAddress = USB_DIR_IN,
159 .bmAttributes = USB_ENDPOINT_XFER_BULK, 159 .bmAttributes = USB_ENDPOINT_XFER_BULK,
160 .wMaxPacketSize = __constant_cpu_to_le16(512), 160 .wMaxPacketSize = cpu_to_le16(512),
161}; 161};
162 162
163static struct usb_descriptor_header *fs_pn_function[] = { 163static struct usb_descriptor_header *fs_pn_function[] = {
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 3a8bb53fc473..3279a4726042 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -137,7 +137,7 @@ static struct usb_cdc_header_desc header_desc __initdata = {
137 .bDescriptorType = USB_DT_CS_INTERFACE, 137 .bDescriptorType = USB_DT_CS_INTERFACE,
138 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 138 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
139 139
140 .bcdCDC = __constant_cpu_to_le16(0x0110), 140 .bcdCDC = cpu_to_le16(0x0110),
141}; 141};
142 142
143static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor __initdata = { 143static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor __initdata = {
@@ -187,7 +187,7 @@ static struct usb_endpoint_descriptor fs_notify_desc __initdata = {
187 187
188 .bEndpointAddress = USB_DIR_IN, 188 .bEndpointAddress = USB_DIR_IN,
189 .bmAttributes = USB_ENDPOINT_XFER_INT, 189 .bmAttributes = USB_ENDPOINT_XFER_INT,
190 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), 190 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
191 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, 191 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
192}; 192};
193 193
@@ -230,7 +230,7 @@ static struct usb_endpoint_descriptor hs_notify_desc __initdata = {
230 230
231 .bEndpointAddress = USB_DIR_IN, 231 .bEndpointAddress = USB_DIR_IN,
232 .bmAttributes = USB_ENDPOINT_XFER_INT, 232 .bmAttributes = USB_ENDPOINT_XFER_INT,
233 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), 233 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
234 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 234 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
235}; 235};
236static struct usb_endpoint_descriptor hs_in_desc __initdata = { 236static struct usb_endpoint_descriptor hs_in_desc __initdata = {
@@ -239,7 +239,7 @@ static struct usb_endpoint_descriptor hs_in_desc __initdata = {
239 239
240 .bEndpointAddress = USB_DIR_IN, 240 .bEndpointAddress = USB_DIR_IN,
241 .bmAttributes = USB_ENDPOINT_XFER_BULK, 241 .bmAttributes = USB_ENDPOINT_XFER_BULK,
242 .wMaxPacketSize = __constant_cpu_to_le16(512), 242 .wMaxPacketSize = cpu_to_le16(512),
243}; 243};
244 244
245static struct usb_endpoint_descriptor hs_out_desc __initdata = { 245static struct usb_endpoint_descriptor hs_out_desc __initdata = {
@@ -248,7 +248,7 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = {
248 248
249 .bEndpointAddress = USB_DIR_OUT, 249 .bEndpointAddress = USB_DIR_OUT,
250 .bmAttributes = USB_ENDPOINT_XFER_BULK, 250 .bmAttributes = USB_ENDPOINT_XFER_BULK,
251 .wMaxPacketSize = __constant_cpu_to_le16(512), 251 .wMaxPacketSize = cpu_to_le16(512),
252}; 252};
253 253
254static struct usb_descriptor_header *eth_hs_function[] __initdata = { 254static struct usb_descriptor_header *eth_hs_function[] __initdata = {
@@ -437,7 +437,7 @@ invalid:
437 DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n", 437 DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n",
438 ctrl->bRequestType, ctrl->bRequest, 438 ctrl->bRequestType, ctrl->bRequest,
439 w_value, w_index, w_length); 439 w_value, w_index, w_length);
440 req->zero = 0; 440 req->zero = (value < w_length);
441 req->length = value; 441 req->length = value;
442 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); 442 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
443 if (value < 0) 443 if (value < 0)
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index fe5674db344b..db0aa93606ef 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -89,14 +89,14 @@ static struct usb_endpoint_descriptor gser_hs_in_desc __initdata = {
89 .bLength = USB_DT_ENDPOINT_SIZE, 89 .bLength = USB_DT_ENDPOINT_SIZE,
90 .bDescriptorType = USB_DT_ENDPOINT, 90 .bDescriptorType = USB_DT_ENDPOINT,
91 .bmAttributes = USB_ENDPOINT_XFER_BULK, 91 .bmAttributes = USB_ENDPOINT_XFER_BULK,
92 .wMaxPacketSize = __constant_cpu_to_le16(512), 92 .wMaxPacketSize = cpu_to_le16(512),
93}; 93};
94 94
95static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = { 95static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = {
96 .bLength = USB_DT_ENDPOINT_SIZE, 96 .bLength = USB_DT_ENDPOINT_SIZE,
97 .bDescriptorType = USB_DT_ENDPOINT, 97 .bDescriptorType = USB_DT_ENDPOINT,
98 .bmAttributes = USB_ENDPOINT_XFER_BULK, 98 .bmAttributes = USB_ENDPOINT_XFER_BULK,
99 .wMaxPacketSize = __constant_cpu_to_le16(512), 99 .wMaxPacketSize = cpu_to_le16(512),
100}; 100};
101 101
102static struct usb_descriptor_header *gser_hs_function[] __initdata = { 102static struct usb_descriptor_header *gser_hs_function[] __initdata = {
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index dc84d26d2835..bffe91d525f9 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -59,7 +59,6 @@ struct f_sourcesink {
59 59
60 struct usb_ep *in_ep; 60 struct usb_ep *in_ep;
61 struct usb_ep *out_ep; 61 struct usb_ep *out_ep;
62 struct timer_list resume;
63}; 62};
64 63
65static inline struct f_sourcesink *func_to_ss(struct usb_function *f) 64static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
@@ -67,10 +66,6 @@ static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
67 return container_of(f, struct f_sourcesink, function); 66 return container_of(f, struct f_sourcesink, function);
68} 67}
69 68
70static unsigned autoresume;
71module_param(autoresume, uint, 0);
72MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup");
73
74static unsigned pattern; 69static unsigned pattern;
75module_param(pattern, uint, 0); 70module_param(pattern, uint, 0);
76MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63 "); 71MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63 ");
@@ -118,7 +113,7 @@ static struct usb_endpoint_descriptor hs_source_desc = {
118 .bDescriptorType = USB_DT_ENDPOINT, 113 .bDescriptorType = USB_DT_ENDPOINT,
119 114
120 .bmAttributes = USB_ENDPOINT_XFER_BULK, 115 .bmAttributes = USB_ENDPOINT_XFER_BULK,
121 .wMaxPacketSize = __constant_cpu_to_le16(512), 116 .wMaxPacketSize = cpu_to_le16(512),
122}; 117};
123 118
124static struct usb_endpoint_descriptor hs_sink_desc = { 119static struct usb_endpoint_descriptor hs_sink_desc = {
@@ -126,7 +121,7 @@ static struct usb_endpoint_descriptor hs_sink_desc = {
126 .bDescriptorType = USB_DT_ENDPOINT, 121 .bDescriptorType = USB_DT_ENDPOINT,
127 122
128 .bmAttributes = USB_ENDPOINT_XFER_BULK, 123 .bmAttributes = USB_ENDPOINT_XFER_BULK,
129 .wMaxPacketSize = __constant_cpu_to_le16(512), 124 .wMaxPacketSize = cpu_to_le16(512),
130}; 125};
131 126
132static struct usb_descriptor_header *hs_source_sink_descs[] = { 127static struct usb_descriptor_header *hs_source_sink_descs[] = {
@@ -155,21 +150,6 @@ static struct usb_gadget_strings *sourcesink_strings[] = {
155 150
156/*-------------------------------------------------------------------------*/ 151/*-------------------------------------------------------------------------*/
157 152
158static void sourcesink_autoresume(unsigned long _c)
159{
160 struct usb_composite_dev *cdev = (void *)_c;
161 struct usb_gadget *g = cdev->gadget;
162
163 /* Normally the host would be woken up for something
164 * more significant than just a timer firing; likely
165 * because of some direct user request.
166 */
167 if (g->speed != USB_SPEED_UNKNOWN) {
168 int status = usb_gadget_wakeup(g);
169 DBG(cdev, "%s --> %d\n", __func__, status);
170 }
171}
172
173static int __init 153static int __init
174sourcesink_bind(struct usb_configuration *c, struct usb_function *f) 154sourcesink_bind(struct usb_configuration *c, struct usb_function *f)
175{ 155{
@@ -198,9 +178,6 @@ autoconf_fail:
198 goto autoconf_fail; 178 goto autoconf_fail;
199 ss->out_ep->driver_data = cdev; /* claim */ 179 ss->out_ep->driver_data = cdev; /* claim */
200 180
201 setup_timer(&ss->resume, sourcesink_autoresume,
202 (unsigned long) c->cdev);
203
204 /* support high speed hardware */ 181 /* support high speed hardware */
205 if (gadget_is_dualspeed(c->cdev->gadget)) { 182 if (gadget_is_dualspeed(c->cdev->gadget)) {
206 hs_source_desc.bEndpointAddress = 183 hs_source_desc.bEndpointAddress =
@@ -359,7 +336,6 @@ static void disable_source_sink(struct f_sourcesink *ss)
359 336
360 cdev = ss->function.config->cdev; 337 cdev = ss->function.config->cdev;
361 disable_endpoints(cdev, ss->in_ep, ss->out_ep); 338 disable_endpoints(cdev, ss->in_ep, ss->out_ep);
362 del_timer(&ss->resume);
363 VDBG(cdev, "%s disabled\n", ss->function.name); 339 VDBG(cdev, "%s disabled\n", ss->function.name);
364} 340}
365 341
@@ -426,30 +402,6 @@ static void sourcesink_disable(struct usb_function *f)
426 disable_source_sink(ss); 402 disable_source_sink(ss);
427} 403}
428 404
429static void sourcesink_suspend(struct usb_function *f)
430{
431 struct f_sourcesink *ss = func_to_ss(f);
432 struct usb_composite_dev *cdev = f->config->cdev;
433
434 if (cdev->gadget->speed == USB_SPEED_UNKNOWN)
435 return;
436
437 if (autoresume) {
438 mod_timer(&ss->resume, jiffies + (HZ * autoresume));
439 DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume);
440 } else
441 DBG(cdev, "%s\n", __func__);
442}
443
444static void sourcesink_resume(struct usb_function *f)
445{
446 struct f_sourcesink *ss = func_to_ss(f);
447 struct usb_composite_dev *cdev = f->config->cdev;
448
449 DBG(cdev, "%s\n", __func__);
450 del_timer(&ss->resume);
451}
452
453/*-------------------------------------------------------------------------*/ 405/*-------------------------------------------------------------------------*/
454 406
455static int __init sourcesink_bind_config(struct usb_configuration *c) 407static int __init sourcesink_bind_config(struct usb_configuration *c)
@@ -467,8 +419,6 @@ static int __init sourcesink_bind_config(struct usb_configuration *c)
467 ss->function.unbind = sourcesink_unbind; 419 ss->function.unbind = sourcesink_unbind;
468 ss->function.set_alt = sourcesink_set_alt; 420 ss->function.set_alt = sourcesink_set_alt;
469 ss->function.disable = sourcesink_disable; 421 ss->function.disable = sourcesink_disable;
470 ss->function.suspend = sourcesink_suspend;
471 ss->function.resume = sourcesink_resume;
472 422
473 status = usb_add_function(c, &ss->function); 423 status = usb_add_function(c, &ss->function);
474 if (status) 424 if (status)
@@ -559,7 +509,7 @@ static struct usb_configuration sourcesink_driver = {
559 * sourcesink_add - add a source/sink testing configuration to a device 509 * sourcesink_add - add a source/sink testing configuration to a device
560 * @cdev: the device to support the configuration 510 * @cdev: the device to support the configuration
561 */ 511 */
562int __init sourcesink_add(struct usb_composite_dev *cdev) 512int __init sourcesink_add(struct usb_composite_dev *cdev, bool autoresume)
563{ 513{
564 int id; 514 int id;
565 515
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index fe1832875771..a9c98fdb626d 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -108,7 +108,7 @@ static struct usb_cdc_header_desc mdlm_header_desc __initdata = {
108 .bDescriptorType = USB_DT_CS_INTERFACE, 108 .bDescriptorType = USB_DT_CS_INTERFACE,
109 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 109 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
110 110
111 .bcdCDC = __constant_cpu_to_le16(0x0110), 111 .bcdCDC = cpu_to_le16(0x0110),
112}; 112};
113 113
114static struct usb_cdc_mdlm_desc mdlm_desc __initdata = { 114static struct usb_cdc_mdlm_desc mdlm_desc __initdata = {
@@ -116,7 +116,7 @@ static struct usb_cdc_mdlm_desc mdlm_desc __initdata = {
116 .bDescriptorType = USB_DT_CS_INTERFACE, 116 .bDescriptorType = USB_DT_CS_INTERFACE,
117 .bDescriptorSubType = USB_CDC_MDLM_TYPE, 117 .bDescriptorSubType = USB_CDC_MDLM_TYPE,
118 118
119 .bcdVersion = __constant_cpu_to_le16(0x0100), 119 .bcdVersion = cpu_to_le16(0x0100),
120 .bGUID = { 120 .bGUID = {
121 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6, 121 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
122 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f, 122 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
@@ -144,9 +144,9 @@ static struct usb_cdc_ether_desc ether_desc __initdata = {
144 144
145 /* this descriptor actually adds value, surprise! */ 145 /* this descriptor actually adds value, surprise! */
146 /* .iMACAddress = DYNAMIC */ 146 /* .iMACAddress = DYNAMIC */
147 .bmEthernetStatistics = __constant_cpu_to_le32(0), /* no statistics */ 147 .bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
148 .wMaxSegmentSize = __constant_cpu_to_le16(ETH_FRAME_LEN), 148 .wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
149 .wNumberMCFilters = __constant_cpu_to_le16(0), 149 .wNumberMCFilters = cpu_to_le16(0),
150 .bNumberPowerFilters = 0, 150 .bNumberPowerFilters = 0,
151}; 151};
152 152
@@ -186,7 +186,7 @@ static struct usb_endpoint_descriptor hs_subset_in_desc __initdata = {
186 .bDescriptorType = USB_DT_ENDPOINT, 186 .bDescriptorType = USB_DT_ENDPOINT,
187 187
188 .bmAttributes = USB_ENDPOINT_XFER_BULK, 188 .bmAttributes = USB_ENDPOINT_XFER_BULK,
189 .wMaxPacketSize = __constant_cpu_to_le16(512), 189 .wMaxPacketSize = cpu_to_le16(512),
190}; 190};
191 191
192static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = { 192static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = {
@@ -194,7 +194,7 @@ static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = {
194 .bDescriptorType = USB_DT_ENDPOINT, 194 .bDescriptorType = USB_DT_ENDPOINT,
195 195
196 .bmAttributes = USB_ENDPOINT_XFER_BULK, 196 .bmAttributes = USB_ENDPOINT_XFER_BULK,
197 .wMaxPacketSize = __constant_cpu_to_le16(512), 197 .wMaxPacketSize = cpu_to_le16(512),
198}; 198};
199 199
200static struct usb_descriptor_header *hs_eth_function[] __initdata = { 200static struct usb_descriptor_header *hs_eth_function[] __initdata = {
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index b10fa31cc915..5c030b080d4c 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -847,13 +847,13 @@ device_desc = {
847 .bLength = sizeof device_desc, 847 .bLength = sizeof device_desc,
848 .bDescriptorType = USB_DT_DEVICE, 848 .bDescriptorType = USB_DT_DEVICE,
849 849
850 .bcdUSB = __constant_cpu_to_le16(0x0200), 850 .bcdUSB = cpu_to_le16(0x0200),
851 .bDeviceClass = USB_CLASS_PER_INTERFACE, 851 .bDeviceClass = USB_CLASS_PER_INTERFACE,
852 852
853 /* The next three values can be overridden by module parameters */ 853 /* The next three values can be overridden by module parameters */
854 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_ID), 854 .idVendor = cpu_to_le16(DRIVER_VENDOR_ID),
855 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_ID), 855 .idProduct = cpu_to_le16(DRIVER_PRODUCT_ID),
856 .bcdDevice = __constant_cpu_to_le16(0xffff), 856 .bcdDevice = cpu_to_le16(0xffff),
857 857
858 .iManufacturer = STRING_MANUFACTURER, 858 .iManufacturer = STRING_MANUFACTURER,
859 .iProduct = STRING_PRODUCT, 859 .iProduct = STRING_PRODUCT,
@@ -926,7 +926,7 @@ fs_intr_in_desc = {
926 926
927 .bEndpointAddress = USB_DIR_IN, 927 .bEndpointAddress = USB_DIR_IN,
928 .bmAttributes = USB_ENDPOINT_XFER_INT, 928 .bmAttributes = USB_ENDPOINT_XFER_INT,
929 .wMaxPacketSize = __constant_cpu_to_le16(2), 929 .wMaxPacketSize = cpu_to_le16(2),
930 .bInterval = 32, // frames -> 32 ms 930 .bInterval = 32, // frames -> 32 ms
931}; 931};
932 932
@@ -954,7 +954,7 @@ dev_qualifier = {
954 .bLength = sizeof dev_qualifier, 954 .bLength = sizeof dev_qualifier,
955 .bDescriptorType = USB_DT_DEVICE_QUALIFIER, 955 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
956 956
957 .bcdUSB = __constant_cpu_to_le16(0x0200), 957 .bcdUSB = cpu_to_le16(0x0200),
958 .bDeviceClass = USB_CLASS_PER_INTERFACE, 958 .bDeviceClass = USB_CLASS_PER_INTERFACE,
959 959
960 .bNumConfigurations = 1, 960 .bNumConfigurations = 1,
@@ -967,7 +967,7 @@ hs_bulk_in_desc = {
967 967
968 /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */ 968 /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
969 .bmAttributes = USB_ENDPOINT_XFER_BULK, 969 .bmAttributes = USB_ENDPOINT_XFER_BULK,
970 .wMaxPacketSize = __constant_cpu_to_le16(512), 970 .wMaxPacketSize = cpu_to_le16(512),
971}; 971};
972 972
973static struct usb_endpoint_descriptor 973static struct usb_endpoint_descriptor
@@ -977,7 +977,7 @@ hs_bulk_out_desc = {
977 977
978 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */ 978 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
979 .bmAttributes = USB_ENDPOINT_XFER_BULK, 979 .bmAttributes = USB_ENDPOINT_XFER_BULK,
980 .wMaxPacketSize = __constant_cpu_to_le16(512), 980 .wMaxPacketSize = cpu_to_le16(512),
981 .bInterval = 1, // NAK every 1 uframe 981 .bInterval = 1, // NAK every 1 uframe
982}; 982};
983 983
@@ -988,7 +988,7 @@ hs_intr_in_desc = {
988 988
989 /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */ 989 /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
990 .bmAttributes = USB_ENDPOINT_XFER_INT, 990 .bmAttributes = USB_ENDPOINT_XFER_INT,
991 .wMaxPacketSize = __constant_cpu_to_le16(2), 991 .wMaxPacketSize = cpu_to_le16(2),
992 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms 992 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms
993}; 993};
994 994
@@ -1711,7 +1711,9 @@ static int do_write(struct fsg_dev *fsg)
1711 curlun->sense_data = SS_WRITE_PROTECTED; 1711 curlun->sense_data = SS_WRITE_PROTECTED;
1712 return -EINVAL; 1712 return -EINVAL;
1713 } 1713 }
1714 spin_lock(&curlun->filp->f_lock);
1714 curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait 1715 curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
1716 spin_unlock(&curlun->filp->f_lock);
1715 1717
1716 /* Get the starting Logical Block Address and check that it's 1718 /* Get the starting Logical Block Address and check that it's
1717 * not too big */ 1719 * not too big */
@@ -1728,8 +1730,11 @@ static int do_write(struct fsg_dev *fsg)
1728 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1730 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1729 return -EINVAL; 1731 return -EINVAL;
1730 } 1732 }
1731 if (fsg->cmnd[1] & 0x08) // FUA 1733 if (fsg->cmnd[1] & 0x08) { // FUA
1734 spin_lock(&curlun->filp->f_lock);
1732 curlun->filp->f_flags |= O_SYNC; 1735 curlun->filp->f_flags |= O_SYNC;
1736 spin_unlock(&curlun->filp->f_lock);
1737 }
1733 } 1738 }
1734 if (lba >= curlun->num_sectors) { 1739 if (lba >= curlun->num_sectors) {
1735 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 1740 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
@@ -2646,7 +2651,7 @@ static int send_status(struct fsg_dev *fsg)
2646 struct bulk_cs_wrap *csw = bh->buf; 2651 struct bulk_cs_wrap *csw = bh->buf;
2647 2652
2648 /* Store and send the Bulk-only CSW */ 2653 /* Store and send the Bulk-only CSW */
2649 csw->Signature = __constant_cpu_to_le32(USB_BULK_CS_SIG); 2654 csw->Signature = cpu_to_le32(USB_BULK_CS_SIG);
2650 csw->Tag = fsg->tag; 2655 csw->Tag = fsg->tag;
2651 csw->Residue = cpu_to_le32(fsg->residue); 2656 csw->Residue = cpu_to_le32(fsg->residue);
2652 csw->Status = status; 2657 csw->Status = status;
@@ -3089,7 +3094,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
3089 3094
3090 /* Is the CBW valid? */ 3095 /* Is the CBW valid? */
3091 if (req->actual != USB_BULK_CB_WRAP_LEN || 3096 if (req->actual != USB_BULK_CB_WRAP_LEN ||
3092 cbw->Signature != __constant_cpu_to_le32( 3097 cbw->Signature != cpu_to_le32(
3093 USB_BULK_CB_SIG)) { 3098 USB_BULK_CB_SIG)) {
3094 DBG(fsg, "invalid CBW: len %u sig 0x%x\n", 3099 DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
3095 req->actual, 3100 req->actual,
@@ -3879,7 +3884,11 @@ static int __init check_parameters(struct fsg_dev *fsg)
3879 mod_data.protocol_type = USB_SC_SCSI; 3884 mod_data.protocol_type = USB_SC_SCSI;
3880 mod_data.protocol_name = "Transparent SCSI"; 3885 mod_data.protocol_name = "Transparent SCSI";
3881 3886
3882 if (gadget_is_sh(fsg->gadget)) 3887 /* Some peripheral controllers are known not to be able to
3888 * halt bulk endpoints correctly. If one of them is present,
3889 * disable stalls.
3890 */
3891 if (gadget_is_sh(fsg->gadget) || gadget_is_at91(fsg->gadget))
3883 mod_data.can_stall = 0; 3892 mod_data.can_stall = 0;
3884 3893
3885 if (mod_data.release == 0xffff) { // Parameter wasn't set 3894 if (mod_data.release == 0xffff) { // Parameter wasn't set
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index d6c5bcd40064..d701bf4698d2 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -1622,6 +1622,8 @@ static int qe_ep_disable(struct usb_ep *_ep)
1622 nuke(ep, -ESHUTDOWN); 1622 nuke(ep, -ESHUTDOWN);
1623 ep->desc = NULL; 1623 ep->desc = NULL;
1624 ep->stopped = 1; 1624 ep->stopped = 1;
1625 ep->tx_req = NULL;
1626 qe_ep_reset(udc, ep->epnum);
1625 spin_unlock_irqrestore(&udc->lock, flags); 1627 spin_unlock_irqrestore(&udc->lock, flags);
1626 1628
1627 cpm_muram_free(cpm_muram_offset(ep->rxbase)); 1629 cpm_muram_free(cpm_muram_offset(ep->rxbase));
@@ -1681,14 +1683,11 @@ static void qe_free_request(struct usb_ep *_ep, struct usb_request *_req)
1681 kfree(req); 1683 kfree(req);
1682} 1684}
1683 1685
1684/* queues (submits) an I/O request to an endpoint */ 1686static int __qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req)
1685static int qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1686 gfp_t gfp_flags)
1687{ 1687{
1688 struct qe_ep *ep = container_of(_ep, struct qe_ep, ep); 1688 struct qe_ep *ep = container_of(_ep, struct qe_ep, ep);
1689 struct qe_req *req = container_of(_req, struct qe_req, req); 1689 struct qe_req *req = container_of(_req, struct qe_req, req);
1690 struct qe_udc *udc; 1690 struct qe_udc *udc;
1691 unsigned long flags;
1692 int reval; 1691 int reval;
1693 1692
1694 udc = ep->udc; 1693 udc = ep->udc;
@@ -1732,7 +1731,7 @@ static int qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1732 list_add_tail(&req->queue, &ep->queue); 1731 list_add_tail(&req->queue, &ep->queue);
1733 dev_vdbg(udc->dev, "gadget have request in %s! %d\n", 1732 dev_vdbg(udc->dev, "gadget have request in %s! %d\n",
1734 ep->name, req->req.length); 1733 ep->name, req->req.length);
1735 spin_lock_irqsave(&udc->lock, flags); 1734
1736 /* push the request to device */ 1735 /* push the request to device */
1737 if (ep_is_in(ep)) 1736 if (ep_is_in(ep))
1738 reval = ep_req_send(ep, req); 1737 reval = ep_req_send(ep, req);
@@ -1748,11 +1747,24 @@ static int qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1748 if (ep->dir == USB_DIR_OUT) 1747 if (ep->dir == USB_DIR_OUT)
1749 reval = ep_req_receive(ep, req); 1748 reval = ep_req_receive(ep, req);
1750 1749
1751 spin_unlock_irqrestore(&udc->lock, flags);
1752
1753 return 0; 1750 return 0;
1754} 1751}
1755 1752
1753/* queues (submits) an I/O request to an endpoint */
1754static int qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1755 gfp_t gfp_flags)
1756{
1757 struct qe_ep *ep = container_of(_ep, struct qe_ep, ep);
1758 struct qe_udc *udc = ep->udc;
1759 unsigned long flags;
1760 int ret;
1761
1762 spin_lock_irqsave(&udc->lock, flags);
1763 ret = __qe_ep_queue(_ep, _req);
1764 spin_unlock_irqrestore(&udc->lock, flags);
1765 return ret;
1766}
1767
1756/* dequeues (cancels, unlinks) an I/O request from an endpoint */ 1768/* dequeues (cancels, unlinks) an I/O request from an endpoint */
1757static int qe_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1769static int qe_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1758{ 1770{
@@ -2008,7 +2020,7 @@ static void ch9getstatus(struct qe_udc *udc, u8 request_type, u16 value,
2008 udc->ep0_dir = USB_DIR_IN; 2020 udc->ep0_dir = USB_DIR_IN;
2009 2021
2010 /* data phase */ 2022 /* data phase */
2011 status = qe_ep_queue(&ep->ep, &req->req, GFP_ATOMIC); 2023 status = __qe_ep_queue(&ep->ep, &req->req);
2012 2024
2013 if (status == 0) 2025 if (status == 0)
2014 return; 2026 return;
@@ -2151,6 +2163,9 @@ static int reset_irq(struct qe_udc *udc)
2151{ 2163{
2152 unsigned char i; 2164 unsigned char i;
2153 2165
2166 if (udc->usb_state == USB_STATE_DEFAULT)
2167 return 0;
2168
2154 qe_usb_disable(); 2169 qe_usb_disable();
2155 out_8(&udc->usb_regs->usb_usadr, 0); 2170 out_8(&udc->usb_regs->usb_usadr, 0);
2156 2171
@@ -2442,8 +2457,12 @@ static int __devinit qe_udc_reg_init(struct qe_udc *udc)
2442 struct usb_ctlr __iomem *qe_usbregs; 2457 struct usb_ctlr __iomem *qe_usbregs;
2443 qe_usbregs = udc->usb_regs; 2458 qe_usbregs = udc->usb_regs;
2444 2459
2445 /* Init the usb register */ 2460 /* Spec says that we must enable the USB controller to change mode. */
2446 out_8(&qe_usbregs->usb_usmod, 0x01); 2461 out_8(&qe_usbregs->usb_usmod, 0x01);
2462 /* Mode changed, now disable it, since muram isn't initialized yet. */
2463 out_8(&qe_usbregs->usb_usmod, 0x00);
2464
2465 /* Initialize the rest. */
2447 out_be16(&qe_usbregs->usb_usbmr, 0); 2466 out_be16(&qe_usbregs->usb_usbmr, 0);
2448 out_8(&qe_usbregs->usb_uscom, 0); 2467 out_8(&qe_usbregs->usb_uscom, 0);
2449 out_be16(&qe_usbregs->usb_usber, USBER_ALL_CLEAR); 2468 out_be16(&qe_usbregs->usb_usber, USBER_ALL_CLEAR);
@@ -2604,6 +2623,10 @@ static int __devinit qe_udc_probe(struct of_device *ofdev,
2604 (unsigned long)udc_controller); 2623 (unsigned long)udc_controller);
2605 /* request irq and disable DR */ 2624 /* request irq and disable DR */
2606 udc_controller->usb_irq = irq_of_parse_and_map(np, 0); 2625 udc_controller->usb_irq = irq_of_parse_and_map(np, 0);
2626 if (!udc_controller->usb_irq) {
2627 ret = -EINVAL;
2628 goto err_noirq;
2629 }
2607 2630
2608 ret = request_irq(udc_controller->usb_irq, qe_udc_irq, 0, 2631 ret = request_irq(udc_controller->usb_irq, qe_udc_irq, 0,
2609 driver_name, udc_controller); 2632 driver_name, udc_controller);
@@ -2625,6 +2648,8 @@ static int __devinit qe_udc_probe(struct of_device *ofdev,
2625err6: 2648err6:
2626 free_irq(udc_controller->usb_irq, udc_controller); 2649 free_irq(udc_controller->usb_irq, udc_controller);
2627err5: 2650err5:
2651 irq_dispose_mapping(udc_controller->usb_irq);
2652err_noirq:
2628 if (udc_controller->nullmap) { 2653 if (udc_controller->nullmap) {
2629 dma_unmap_single(udc_controller->gadget.dev.parent, 2654 dma_unmap_single(udc_controller->gadget.dev.parent,
2630 udc_controller->nullp, 256, 2655 udc_controller->nullp, 256,
@@ -2648,7 +2673,7 @@ err2:
2648 iounmap(udc_controller->usb_regs); 2673 iounmap(udc_controller->usb_regs);
2649err1: 2674err1:
2650 kfree(udc_controller); 2675 kfree(udc_controller);
2651 2676 udc_controller = NULL;
2652 return ret; 2677 return ret;
2653} 2678}
2654 2679
@@ -2710,6 +2735,7 @@ static int __devexit qe_udc_remove(struct of_device *ofdev)
2710 kfree(ep->txframe); 2735 kfree(ep->txframe);
2711 2736
2712 free_irq(udc_controller->usb_irq, udc_controller); 2737 free_irq(udc_controller->usb_irq, udc_controller);
2738 irq_dispose_mapping(udc_controller->usb_irq);
2713 2739
2714 tasklet_kill(&udc_controller->rx_tasklet); 2740 tasklet_kill(&udc_controller->rx_tasklet);
2715 2741
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index f3c6703cffda..9d7b95d4e3d2 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -404,7 +404,10 @@ static void struct_ep_qh_setup(struct fsl_udc *udc, unsigned char ep_num,
404 } 404 }
405 if (zlt) 405 if (zlt)
406 tmp |= EP_QUEUE_HEAD_ZLT_SEL; 406 tmp |= EP_QUEUE_HEAD_ZLT_SEL;
407
407 p_QH->max_pkt_length = cpu_to_le32(tmp); 408 p_QH->max_pkt_length = cpu_to_le32(tmp);
409 p_QH->next_dtd_ptr = 1;
410 p_QH->size_ioc_int_sts = 0;
408 411
409 return; 412 return;
410} 413}
@@ -1799,7 +1802,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1799 1802
1800out: 1803out:
1801 if (retval) 1804 if (retval)
1802 printk("gadget driver register failed %d\n", retval); 1805 printk(KERN_WARNING "gadget driver register failed %d\n",
1806 retval);
1803 return retval; 1807 return retval;
1804} 1808}
1805EXPORT_SYMBOL(usb_gadget_register_driver); 1809EXPORT_SYMBOL(usb_gadget_register_driver);
@@ -1844,7 +1848,8 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1844 udc_controller->gadget.dev.driver = NULL; 1848 udc_controller->gadget.dev.driver = NULL;
1845 udc_controller->driver = NULL; 1849 udc_controller->driver = NULL;
1846 1850
1847 printk("unregistered gadget driver '%s'\n", driver->driver.name); 1851 printk(KERN_WARNING "unregistered gadget driver '%s'\n",
1852 driver->driver.name);
1848 return 0; 1853 return 0;
1849} 1854}
1850EXPORT_SYMBOL(usb_gadget_unregister_driver); 1855EXPORT_SYMBOL(usb_gadget_unregister_driver);
@@ -2452,7 +2457,7 @@ module_init(udc_init);
2452static void __exit udc_exit(void) 2457static void __exit udc_exit(void)
2453{ 2458{
2454 platform_driver_unregister(&udc_driver); 2459 platform_driver_unregister(&udc_driver);
2455 printk("%s unregistered\n", driver_desc); 2460 printk(KERN_WARNING "%s unregistered\n", driver_desc);
2456} 2461}
2457 2462
2458module_exit(udc_exit); 2463module_exit(udc_exit);
diff --git a/drivers/usb/gadget/g_zero.h b/drivers/usb/gadget/g_zero.h
index dd2f16ad5a88..e84b3c47ed3c 100644
--- a/drivers/usb/gadget/g_zero.h
+++ b/drivers/usb/gadget/g_zero.h
@@ -19,7 +19,7 @@ void disable_endpoints(struct usb_composite_dev *cdev,
19 struct usb_ep *in, struct usb_ep *out); 19 struct usb_ep *in, struct usb_ep *out);
20 20
21/* configuration-specific linkup */ 21/* configuration-specific linkup */
22int sourcesink_add(struct usb_composite_dev *cdev); 22int sourcesink_add(struct usb_composite_dev *cdev, bool autoresume);
23int loopback_add(struct usb_composite_dev *cdev); 23int loopback_add(struct usb_composite_dev *cdev, bool autoresume);
24 24
25#endif /* __G_ZERO_H */ 25#endif /* __G_ZERO_H */
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 60d3f9e9b51f..b9312dc6e041 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -199,10 +199,10 @@ DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1);
199static struct usb_device_descriptor device_desc = { 199static struct usb_device_descriptor device_desc = {
200 .bLength = USB_DT_DEVICE_SIZE, 200 .bLength = USB_DT_DEVICE_SIZE,
201 .bDescriptorType = USB_DT_DEVICE, 201 .bDescriptorType = USB_DT_DEVICE,
202 .bcdUSB = __constant_cpu_to_le16(0x0200), 202 .bcdUSB = cpu_to_le16(0x0200),
203 .bDeviceClass = USB_CLASS_PER_INTERFACE, 203 .bDeviceClass = USB_CLASS_PER_INTERFACE,
204 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM), 204 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
205 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM), 205 .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
206 .iManufacturer = STRING_MANUFACTURER, 206 .iManufacturer = STRING_MANUFACTURER,
207 .iProduct = STRING_PRODUCT, 207 .iProduct = STRING_PRODUCT,
208 .bNumConfigurations = 1, 208 .bNumConfigurations = 1,
@@ -241,8 +241,8 @@ static const struct usb_ac_header_descriptor_1 ac_header_desc = {
241 .bLength = USB_DT_AC_HEADER_SIZE(1), 241 .bLength = USB_DT_AC_HEADER_SIZE(1),
242 .bDescriptorType = USB_DT_CS_INTERFACE, 242 .bDescriptorType = USB_DT_CS_INTERFACE,
243 .bDescriptorSubtype = USB_MS_HEADER, 243 .bDescriptorSubtype = USB_MS_HEADER,
244 .bcdADC = __constant_cpu_to_le16(0x0100), 244 .bcdADC = cpu_to_le16(0x0100),
245 .wTotalLength = __constant_cpu_to_le16(USB_DT_AC_HEADER_SIZE(1)), 245 .wTotalLength = cpu_to_le16(USB_DT_AC_HEADER_SIZE(1)),
246 .bInCollection = 1, 246 .bInCollection = 1,
247 .baInterfaceNr = { 247 .baInterfaceNr = {
248 [0] = GMIDI_MS_INTERFACE, 248 [0] = GMIDI_MS_INTERFACE,
@@ -265,8 +265,8 @@ static const struct usb_ms_header_descriptor ms_header_desc = {
265 .bLength = USB_DT_MS_HEADER_SIZE, 265 .bLength = USB_DT_MS_HEADER_SIZE,
266 .bDescriptorType = USB_DT_CS_INTERFACE, 266 .bDescriptorType = USB_DT_CS_INTERFACE,
267 .bDescriptorSubtype = USB_MS_HEADER, 267 .bDescriptorSubtype = USB_MS_HEADER,
268 .bcdMSC = __constant_cpu_to_le16(0x0100), 268 .bcdMSC = cpu_to_le16(0x0100),
269 .wTotalLength = __constant_cpu_to_le16(USB_DT_MS_HEADER_SIZE 269 .wTotalLength = cpu_to_le16(USB_DT_MS_HEADER_SIZE
270 + 2*USB_DT_MIDI_IN_SIZE 270 + 2*USB_DT_MIDI_IN_SIZE
271 + 2*USB_DT_MIDI_OUT_SIZE(1)), 271 + 2*USB_DT_MIDI_OUT_SIZE(1)),
272}; 272};
@@ -1099,10 +1099,9 @@ static int gmidi_register_card(struct gmidi_device *dev)
1099 .dev_free = gmidi_snd_free, 1099 .dev_free = gmidi_snd_free,
1100 }; 1100 };
1101 1101
1102 card = snd_card_new(index, id, THIS_MODULE, 0); 1102 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
1103 if (!card) { 1103 if (err < 0) {
1104 ERROR(dev, "snd_card_new failed\n"); 1104 ERROR(dev, "snd_card_create failed\n");
1105 err = -ENOMEM;
1106 goto fail; 1105 goto fail;
1107 } 1106 }
1108 dev->card = card; 1107 dev->card = card;
@@ -1227,7 +1226,7 @@ autoconf_fail:
1227 */ 1226 */
1228 pr_warning("%s: controller '%s' not recognized\n", 1227 pr_warning("%s: controller '%s' not recognized\n",
1229 shortname, gadget->name); 1228 shortname, gadget->name);
1230 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); 1229 device_desc.bcdDevice = cpu_to_le16(0x9999);
1231 } 1230 }
1232 1231
1233 1232
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 63419c4d503c..de010c939dbb 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1472,7 +1472,7 @@ static void ep0_setup(struct goku_udc *dev)
1472 /* active endpoint */ 1472 /* active endpoint */
1473 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0)) 1473 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0))
1474 goto stall; 1474 goto stall;
1475 if (ctrl.wIndex & __constant_cpu_to_le16( 1475 if (ctrl.wIndex & cpu_to_le16(
1476 USB_DIR_IN)) { 1476 USB_DIR_IN)) {
1477 if (!dev->ep[tmp].is_in) 1477 if (!dev->ep[tmp].is_in)
1478 goto stall; 1478 goto stall;
@@ -1480,7 +1480,7 @@ static void ep0_setup(struct goku_udc *dev)
1480 if (dev->ep[tmp].is_in) 1480 if (dev->ep[tmp].is_in)
1481 goto stall; 1481 goto stall;
1482 } 1482 }
1483 if (ctrl.wValue != __constant_cpu_to_le16( 1483 if (ctrl.wValue != cpu_to_le16(
1484 USB_ENDPOINT_HALT)) 1484 USB_ENDPOINT_HALT))
1485 goto stall; 1485 goto stall;
1486 if (tmp) 1486 if (tmp)
@@ -1493,7 +1493,7 @@ succeed:
1493 return; 1493 return;
1494 case USB_RECIP_DEVICE: 1494 case USB_RECIP_DEVICE:
1495 /* device remote wakeup: always clear */ 1495 /* device remote wakeup: always clear */
1496 if (ctrl.wValue != __constant_cpu_to_le16(1)) 1496 if (ctrl.wValue != cpu_to_le16(1))
1497 goto stall; 1497 goto stall;
1498 VDBG(dev, "clear dev remote wakeup\n"); 1498 VDBG(dev, "clear dev remote wakeup\n");
1499 goto succeed; 1499 goto succeed;
@@ -1519,7 +1519,7 @@ succeed:
1519 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION 1519 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION
1520 && ctrl.bRequestType == USB_RECIP_DEVICE); 1520 && ctrl.bRequestType == USB_RECIP_DEVICE);
1521 if (unlikely(dev->req_config)) 1521 if (unlikely(dev->req_config))
1522 dev->configured = (ctrl.wValue != __constant_cpu_to_le16(0)); 1522 dev->configured = (ctrl.wValue != cpu_to_le16(0));
1523 1523
1524 /* delegate everything to the gadget driver. 1524 /* delegate everything to the gadget driver.
1525 * it may respond after this irq handler returns. 1525 * it may respond after this irq handler returns.
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index cde8fdf15d5b..168658b4b4e2 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * driver/usb/gadget/imx_udc.c 2 * driver/usb/gadget/imx_udc.c
3 * 3 *
4 * Copyright (C) 2005 Mike Lee(eemike@gmail.com) 4 * Copyright (C) 2005 Mike Lee <eemike@gmail.com>
5 * Copyright (C) 2008 Darius Augulis <augulis.darius@gmail.com> 5 * Copyright (C) 2008 Darius Augulis <augulis.darius@gmail.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -28,6 +28,7 @@
28#include <linux/dma-mapping.h> 28#include <linux/dma-mapping.h>
29#include <linux/clk.h> 29#include <linux/clk.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/timer.h>
31 32
32#include <linux/usb/ch9.h> 33#include <linux/usb/ch9.h>
33#include <linux/usb/gadget.h> 34#include <linux/usb/gadget.h>
@@ -51,7 +52,8 @@ void ep0_chg_stat(const char *label, struct imx_udc_struct *imx_usb,
51void imx_udc_enable(struct imx_udc_struct *imx_usb) 52void imx_udc_enable(struct imx_udc_struct *imx_usb)
52{ 53{
53 int temp = __raw_readl(imx_usb->base + USB_CTRL); 54 int temp = __raw_readl(imx_usb->base + USB_CTRL);
54 __raw_writel(temp | CTRL_FE_ENA | CTRL_AFE_ENA, imx_usb->base + USB_CTRL); 55 __raw_writel(temp | CTRL_FE_ENA | CTRL_AFE_ENA,
56 imx_usb->base + USB_CTRL);
55 imx_usb->gadget.speed = USB_SPEED_FULL; 57 imx_usb->gadget.speed = USB_SPEED_FULL;
56} 58}
57 59
@@ -126,7 +128,8 @@ void imx_udc_config(struct imx_udc_struct *imx_usb)
126 for (j = 0; j < 5; j++) { 128 for (j = 0; j < 5; j++) {
127 __raw_writeb(ep_conf[j], 129 __raw_writeb(ep_conf[j],
128 imx_usb->base + USB_DDAT); 130 imx_usb->base + USB_DDAT);
129 do {} while (__raw_readl(imx_usb->base + USB_DADR) 131 do {} while (__raw_readl(imx_usb->base
132 + USB_DADR)
130 & DADR_BSY); 133 & DADR_BSY);
131 } 134 }
132 } 135 }
@@ -183,7 +186,8 @@ void imx_udc_init_ep(struct imx_udc_struct *imx_usb)
183 temp = (EP_DIR(imx_ep) << 7) | (max << 5) 186 temp = (EP_DIR(imx_ep) << 7) | (max << 5)
184 | (imx_ep->bmAttributes << 3); 187 | (imx_ep->bmAttributes << 3);
185 __raw_writel(temp, imx_usb->base + USB_EP_STAT(i)); 188 __raw_writel(temp, imx_usb->base + USB_EP_STAT(i));
186 __raw_writel(temp | EPSTAT_FLUSH, imx_usb->base + USB_EP_STAT(i)); 189 __raw_writel(temp | EPSTAT_FLUSH,
190 imx_usb->base + USB_EP_STAT(i));
187 D_INI(imx_usb->dev, "<%s> ep%d_stat %08x\n", __func__, i, 191 D_INI(imx_usb->dev, "<%s> ep%d_stat %08x\n", __func__, i,
188 __raw_readl(imx_usb->base + USB_EP_STAT(i))); 192 __raw_readl(imx_usb->base + USB_EP_STAT(i)));
189 } 193 }
@@ -278,15 +282,18 @@ void imx_ep_stall(struct imx_ep_struct *imx_ep)
278 struct imx_udc_struct *imx_usb = imx_ep->imx_usb; 282 struct imx_udc_struct *imx_usb = imx_ep->imx_usb;
279 int temp, i; 283 int temp, i;
280 284
281 D_ERR(imx_usb->dev, "<%s> Forced stall on %s\n", __func__, imx_ep->ep.name); 285 D_ERR(imx_usb->dev,
286 "<%s> Forced stall on %s\n", __func__, imx_ep->ep.name);
282 287
283 imx_flush(imx_ep); 288 imx_flush(imx_ep);
284 289
285 /* Special care for ep0 */ 290 /* Special care for ep0 */
286 if (EP_NO(imx_ep)) { 291 if (!EP_NO(imx_ep)) {
287 temp = __raw_readl(imx_usb->base + USB_CTRL); 292 temp = __raw_readl(imx_usb->base + USB_CTRL);
288 __raw_writel(temp | CTRL_CMDOVER | CTRL_CMDERROR, imx_usb->base + USB_CTRL); 293 __raw_writel(temp | CTRL_CMDOVER | CTRL_CMDERROR,
289 do { } while (__raw_readl(imx_usb->base + USB_CTRL) & CTRL_CMDOVER); 294 imx_usb->base + USB_CTRL);
295 do { } while (__raw_readl(imx_usb->base + USB_CTRL)
296 & CTRL_CMDOVER);
290 temp = __raw_readl(imx_usb->base + USB_CTRL); 297 temp = __raw_readl(imx_usb->base + USB_CTRL);
291 __raw_writel(temp & ~CTRL_CMDERROR, imx_usb->base + USB_CTRL); 298 __raw_writel(temp & ~CTRL_CMDERROR, imx_usb->base + USB_CTRL);
292 } 299 }
@@ -296,12 +303,13 @@ void imx_ep_stall(struct imx_ep_struct *imx_ep)
296 imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); 303 imx_usb->base + USB_EP_STAT(EP_NO(imx_ep)));
297 304
298 for (i = 0; i < 100; i ++) { 305 for (i = 0; i < 100; i ++) {
299 temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); 306 temp = __raw_readl(imx_usb->base
300 if (!temp & EPSTAT_STALL) 307 + USB_EP_STAT(EP_NO(imx_ep)));
308 if (!(temp & EPSTAT_STALL))
301 break; 309 break;
302 udelay(20); 310 udelay(20);
303 } 311 }
304 if (i == 50) 312 if (i == 100)
305 D_ERR(imx_usb->dev, "<%s> Non finished stall on %s\n", 313 D_ERR(imx_usb->dev, "<%s> Non finished stall on %s\n",
306 __func__, imx_ep->ep.name); 314 __func__, imx_ep->ep.name);
307 } 315 }
@@ -325,7 +333,8 @@ static int imx_udc_wakeup(struct usb_gadget *_gadget)
325 ******************************************************************************* 333 *******************************************************************************
326 */ 334 */
327 335
328static void ep_add_request(struct imx_ep_struct *imx_ep, struct imx_request *req) 336static void ep_add_request(struct imx_ep_struct *imx_ep,
337 struct imx_request *req)
329{ 338{
330 if (unlikely(!req)) 339 if (unlikely(!req))
331 return; 340 return;
@@ -334,7 +343,8 @@ static void ep_add_request(struct imx_ep_struct *imx_ep, struct imx_request *req
334 list_add_tail(&req->queue, &imx_ep->queue); 343 list_add_tail(&req->queue, &imx_ep->queue);
335} 344}
336 345
337static void ep_del_request(struct imx_ep_struct *imx_ep, struct imx_request *req) 346static void ep_del_request(struct imx_ep_struct *imx_ep,
347 struct imx_request *req)
338{ 348{
339 if (unlikely(!req)) 349 if (unlikely(!req))
340 return; 350 return;
@@ -343,7 +353,8 @@ static void ep_del_request(struct imx_ep_struct *imx_ep, struct imx_request *req
343 req->in_use = 0; 353 req->in_use = 0;
344} 354}
345 355
346static void done(struct imx_ep_struct *imx_ep, struct imx_request *req, int status) 356static void done(struct imx_ep_struct *imx_ep,
357 struct imx_request *req, int status)
347{ 358{
348 ep_del_request(imx_ep, req); 359 ep_del_request(imx_ep, req);
349 360
@@ -494,7 +505,8 @@ static int write_fifo(struct imx_ep_struct *imx_ep, struct imx_request *req)
494 __func__, imx_ep->ep.name, req, 505 __func__, imx_ep->ep.name, req,
495 completed ? "completed" : "not completed"); 506 completed ? "completed" : "not completed");
496 if (!EP_NO(imx_ep)) 507 if (!EP_NO(imx_ep))
497 ep0_chg_stat(__func__, imx_ep->imx_usb, EP0_IDLE); 508 ep0_chg_stat(__func__,
509 imx_ep->imx_usb, EP0_IDLE);
498 } 510 }
499 } 511 }
500 512
@@ -539,10 +551,9 @@ static int handle_ep0(struct imx_ep_struct *imx_ep)
539 struct imx_request *req = NULL; 551 struct imx_request *req = NULL;
540 int ret = 0; 552 int ret = 0;
541 553
542 if (!list_empty(&imx_ep->queue)) 554 if (!list_empty(&imx_ep->queue)) {
543 req = list_entry(imx_ep->queue.next, struct imx_request, queue); 555 req = list_entry(imx_ep->queue.next, struct imx_request, queue);
544 556
545 if (req) {
546 switch (imx_ep->imx_usb->ep0state) { 557 switch (imx_ep->imx_usb->ep0state) {
547 558
548 case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR */ 559 case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR */
@@ -561,6 +572,10 @@ static int handle_ep0(struct imx_ep_struct *imx_ep)
561 } 572 }
562 } 573 }
563 574
575 else
576 D_ERR(imx_ep->imx_usb->dev, "<%s> no request on %s\n",
577 __func__, imx_ep->ep.name);
578
564 return ret; 579 return ret;
565} 580}
566 581
@@ -583,7 +598,8 @@ static void handle_ep0_devreq(struct imx_udc_struct *imx_usb)
583 "<%s> no setup packet received\n", __func__); 598 "<%s> no setup packet received\n", __func__);
584 goto stall; 599 goto stall;
585 } 600 }
586 u.word[i] = __raw_readl(imx_usb->base + USB_EP_FDAT(EP_NO(imx_ep))); 601 u.word[i] = __raw_readl(imx_usb->base
602 + USB_EP_FDAT(EP_NO(imx_ep)));
587 } 603 }
588 604
589 temp = imx_ep_empty(imx_ep); 605 temp = imx_ep_empty(imx_ep);
@@ -759,7 +775,7 @@ static int imx_ep_queue
759 */ 775 */
760 if (imx_usb->set_config && !EP_NO(imx_ep)) { 776 if (imx_usb->set_config && !EP_NO(imx_ep)) {
761 imx_usb->set_config = 0; 777 imx_usb->set_config = 0;
762 D_EPX(imx_usb->dev, 778 D_ERR(imx_usb->dev,
763 "<%s> gadget reply set config\n", __func__); 779 "<%s> gadget reply set config\n", __func__);
764 return 0; 780 return 0;
765 } 781 }
@@ -779,28 +795,29 @@ static int imx_ep_queue
779 return -ESHUTDOWN; 795 return -ESHUTDOWN;
780 } 796 }
781 797
782 local_irq_save(flags);
783
784 /* Debug */ 798 /* Debug */
785 D_REQ(imx_usb->dev, "<%s> ep%d %s request for [%d] bytes\n", 799 D_REQ(imx_usb->dev, "<%s> ep%d %s request for [%d] bytes\n",
786 __func__, EP_NO(imx_ep), 800 __func__, EP_NO(imx_ep),
787 ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state == EP0_IN_DATA_PHASE) 801 ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state
788 || (EP_NO(imx_ep) && EP_DIR(imx_ep))) ? "IN" : "OUT", usb_req->length); 802 == EP0_IN_DATA_PHASE)
803 || (EP_NO(imx_ep) && EP_DIR(imx_ep)))
804 ? "IN" : "OUT", usb_req->length);
789 dump_req(__func__, imx_ep, usb_req); 805 dump_req(__func__, imx_ep, usb_req);
790 806
791 if (imx_ep->stopped) { 807 if (imx_ep->stopped) {
792 usb_req->status = -ESHUTDOWN; 808 usb_req->status = -ESHUTDOWN;
793 ret = -ESHUTDOWN; 809 return -ESHUTDOWN;
794 goto out;
795 } 810 }
796 811
797 if (req->in_use) { 812 if (req->in_use) {
798 D_ERR(imx_usb->dev, 813 D_ERR(imx_usb->dev,
799 "<%s> refusing to queue req %p (already queued)\n", 814 "<%s> refusing to queue req %p (already queued)\n",
800 __func__, req); 815 __func__, req);
801 goto out; 816 return 0;
802 } 817 }
803 818
819 local_irq_save(flags);
820
804 usb_req->status = -EINPROGRESS; 821 usb_req->status = -EINPROGRESS;
805 usb_req->actual = 0; 822 usb_req->actual = 0;
806 823
@@ -810,7 +827,7 @@ static int imx_ep_queue
810 ret = handle_ep0(imx_ep); 827 ret = handle_ep0(imx_ep);
811 else 828 else
812 ret = handle_ep(imx_ep); 829 ret = handle_ep(imx_ep);
813out: 830
814 local_irq_restore(flags); 831 local_irq_restore(flags);
815 return ret; 832 return ret;
816} 833}
@@ -997,71 +1014,32 @@ static void udc_stop_activity(struct imx_udc_struct *imx_usb,
997 ******************************************************************************* 1014 *******************************************************************************
998 */ 1015 */
999 1016
1000static irqreturn_t imx_udc_irq(int irq, void *dev) 1017/*
1018 * Called when timer expires.
1019 * Timer is started when CFG_CHG is received.
1020 */
1021static void handle_config(unsigned long data)
1001{ 1022{
1002 struct imx_udc_struct *imx_usb = dev; 1023 struct imx_udc_struct *imx_usb = (void *)data;
1003 struct usb_ctrlrequest u; 1024 struct usb_ctrlrequest u;
1004 int temp, cfg, intf, alt; 1025 int temp, cfg, intf, alt;
1005 int intr = __raw_readl(imx_usb->base + USB_INTR);
1006 1026
1007 if (intr & (INTR_WAKEUP | INTR_SUSPEND | INTR_RESUME | INTR_RESET_START 1027 local_irq_disable();
1008 | INTR_RESET_STOP | INTR_CFG_CHG)) {
1009 dump_intr(__func__, intr, imx_usb->dev);
1010 dump_usb_stat(__func__, imx_usb);
1011 }
1012 1028
1013 if (!imx_usb->driver) { 1029 temp = __raw_readl(imx_usb->base + USB_STAT);
1014 /*imx_udc_disable(imx_usb);*/ 1030 cfg = (temp & STAT_CFG) >> 5;
1015 goto end_irq; 1031 intf = (temp & STAT_INTF) >> 3;
1016 } 1032 alt = temp & STAT_ALTSET;
1017 1033
1018 if (intr & INTR_WAKEUP) { 1034 D_REQ(imx_usb->dev,
1019 if (imx_usb->gadget.speed == USB_SPEED_UNKNOWN 1035 "<%s> orig config C=%d, I=%d, A=%d / "
1020 && imx_usb->driver && imx_usb->driver->resume) 1036 "req config C=%d, I=%d, A=%d\n",
1021 imx_usb->driver->resume(&imx_usb->gadget); 1037 __func__, imx_usb->cfg, imx_usb->intf, imx_usb->alt,
1022 imx_usb->set_config = 0; 1038 cfg, intf, alt);
1023 imx_usb->gadget.speed = USB_SPEED_FULL;
1024 }
1025
1026 if (intr & INTR_SUSPEND) {
1027 if (imx_usb->gadget.speed != USB_SPEED_UNKNOWN
1028 && imx_usb->driver && imx_usb->driver->suspend)
1029 imx_usb->driver->suspend(&imx_usb->gadget);
1030 imx_usb->set_config = 0;
1031 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1032 }
1033
1034 if (intr & INTR_RESET_START) {
1035 __raw_writel(intr, imx_usb->base + USB_INTR);
1036 udc_stop_activity(imx_usb, imx_usb->driver);
1037 imx_usb->set_config = 0;
1038 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1039 }
1040 1039
1041 if (intr & INTR_RESET_STOP) 1040 if (cfg == 1 || cfg == 2) {
1042 imx_usb->gadget.speed = USB_SPEED_FULL;
1043 1041
1044 if (intr & INTR_CFG_CHG) {
1045 __raw_writel(INTR_CFG_CHG, imx_usb->base + USB_INTR);
1046 temp = __raw_readl(imx_usb->base + USB_STAT);
1047 cfg = (temp & STAT_CFG) >> 5;
1048 intf = (temp & STAT_INTF) >> 3;
1049 alt = temp & STAT_ALTSET;
1050
1051 D_REQ(imx_usb->dev,
1052 "<%s> orig config C=%d, I=%d, A=%d / "
1053 "req config C=%d, I=%d, A=%d\n",
1054 __func__, imx_usb->cfg, imx_usb->intf, imx_usb->alt,
1055 cfg, intf, alt);
1056
1057 if (cfg != 1 && cfg != 2)
1058 goto end_irq;
1059
1060 imx_usb->set_config = 0;
1061
1062 /* Config setup */
1063 if (imx_usb->cfg != cfg) { 1042 if (imx_usb->cfg != cfg) {
1064 D_REQ(imx_usb->dev, "<%s> Change config start\n",__func__);
1065 u.bRequest = USB_REQ_SET_CONFIGURATION; 1043 u.bRequest = USB_REQ_SET_CONFIGURATION;
1066 u.bRequestType = USB_DIR_OUT | 1044 u.bRequestType = USB_DIR_OUT |
1067 USB_TYPE_STANDARD | 1045 USB_TYPE_STANDARD |
@@ -1070,14 +1048,10 @@ static irqreturn_t imx_udc_irq(int irq, void *dev)
1070 u.wIndex = 0; 1048 u.wIndex = 0;
1071 u.wLength = 0; 1049 u.wLength = 0;
1072 imx_usb->cfg = cfg; 1050 imx_usb->cfg = cfg;
1073 imx_usb->set_config = 1;
1074 imx_usb->driver->setup(&imx_usb->gadget, &u); 1051 imx_usb->driver->setup(&imx_usb->gadget, &u);
1075 imx_usb->set_config = 0;
1076 D_REQ(imx_usb->dev, "<%s> Change config done\n",__func__);
1077 1052
1078 } 1053 }
1079 if (imx_usb->intf != intf || imx_usb->alt != alt) { 1054 if (imx_usb->intf != intf || imx_usb->alt != alt) {
1080 D_REQ(imx_usb->dev, "<%s> Change interface start\n",__func__);
1081 u.bRequest = USB_REQ_SET_INTERFACE; 1055 u.bRequest = USB_REQ_SET_INTERFACE;
1082 u.bRequestType = USB_DIR_OUT | 1056 u.bRequestType = USB_DIR_OUT |
1083 USB_TYPE_STANDARD | 1057 USB_TYPE_STANDARD |
@@ -1087,20 +1061,92 @@ static irqreturn_t imx_udc_irq(int irq, void *dev)
1087 u.wLength = 0; 1061 u.wLength = 0;
1088 imx_usb->intf = intf; 1062 imx_usb->intf = intf;
1089 imx_usb->alt = alt; 1063 imx_usb->alt = alt;
1090 imx_usb->set_config = 1;
1091 imx_usb->driver->setup(&imx_usb->gadget, &u); 1064 imx_usb->driver->setup(&imx_usb->gadget, &u);
1092 imx_usb->set_config = 0;
1093 D_REQ(imx_usb->dev, "<%s> Change interface done\n",__func__);
1094 } 1065 }
1095 } 1066 }
1096 1067
1068 imx_usb->set_config = 0;
1069
1070 local_irq_enable();
1071}
1072
1073static irqreturn_t imx_udc_irq(int irq, void *dev)
1074{
1075 struct imx_udc_struct *imx_usb = dev;
1076 int intr = __raw_readl(imx_usb->base + USB_INTR);
1077 int temp;
1078
1079 if (intr & (INTR_WAKEUP | INTR_SUSPEND | INTR_RESUME | INTR_RESET_START
1080 | INTR_RESET_STOP | INTR_CFG_CHG)) {
1081 dump_intr(__func__, intr, imx_usb->dev);
1082 dump_usb_stat(__func__, imx_usb);
1083 }
1084
1085 if (!imx_usb->driver)
1086 goto end_irq;
1087
1097 if (intr & INTR_SOF) { 1088 if (intr & INTR_SOF) {
1089 /* Copy from Freescale BSP.
1090 We must enable SOF intr and set CMDOVER.
1091 Datasheet don't specifiy this action, but it
1092 is done in Freescale BSP, so just copy it.
1093 */
1098 if (imx_usb->ep0state == EP0_IDLE) { 1094 if (imx_usb->ep0state == EP0_IDLE) {
1099 temp = __raw_readl(imx_usb->base + USB_CTRL); 1095 temp = __raw_readl(imx_usb->base + USB_CTRL);
1100 __raw_writel(temp | CTRL_CMDOVER, imx_usb->base + USB_CTRL); 1096 __raw_writel(temp | CTRL_CMDOVER,
1097 imx_usb->base + USB_CTRL);
1101 } 1098 }
1102 } 1099 }
1103 1100
1101 if (intr & INTR_CFG_CHG) {
1102 /* A workaround of serious IMX UDC bug.
1103 Handling of CFG_CHG should be delayed for some time, because
1104 IMX does not NACK the host when CFG_CHG interrupt is pending.
1105 There is no time to handle current CFG_CHG
1106 if next CFG_CHG or SETUP packed is send immediately.
1107 We have to clear CFG_CHG, start the timer and
1108 NACK the host by setting CTRL_CMDOVER
1109 if it sends any SETUP packet.
1110 When timer expires, handler is called to handle configuration
1111 changes. While CFG_CHG is not handled (set_config=1),
1112 we must NACK the host to every SETUP packed.
1113 This delay prevents from going out of sync with host.
1114 */
1115 __raw_writel(INTR_CFG_CHG, imx_usb->base + USB_INTR);
1116 imx_usb->set_config = 1;
1117 mod_timer(&imx_usb->timer, jiffies + 5);
1118 goto end_irq;
1119 }
1120
1121 if (intr & INTR_WAKEUP) {
1122 if (imx_usb->gadget.speed == USB_SPEED_UNKNOWN
1123 && imx_usb->driver && imx_usb->driver->resume)
1124 imx_usb->driver->resume(&imx_usb->gadget);
1125 imx_usb->set_config = 0;
1126 del_timer(&imx_usb->timer);
1127 imx_usb->gadget.speed = USB_SPEED_FULL;
1128 }
1129
1130 if (intr & INTR_SUSPEND) {
1131 if (imx_usb->gadget.speed != USB_SPEED_UNKNOWN
1132 && imx_usb->driver && imx_usb->driver->suspend)
1133 imx_usb->driver->suspend(&imx_usb->gadget);
1134 imx_usb->set_config = 0;
1135 del_timer(&imx_usb->timer);
1136 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1137 }
1138
1139 if (intr & INTR_RESET_START) {
1140 __raw_writel(intr, imx_usb->base + USB_INTR);
1141 udc_stop_activity(imx_usb, imx_usb->driver);
1142 imx_usb->set_config = 0;
1143 del_timer(&imx_usb->timer);
1144 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1145 }
1146
1147 if (intr & INTR_RESET_STOP)
1148 imx_usb->gadget.speed = USB_SPEED_FULL;
1149
1104end_irq: 1150end_irq:
1105 __raw_writel(intr, imx_usb->base + USB_INTR); 1151 __raw_writel(intr, imx_usb->base + USB_INTR);
1106 return IRQ_HANDLED; 1152 return IRQ_HANDLED;
@@ -1109,6 +1155,7 @@ end_irq:
1109static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev) 1155static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev)
1110{ 1156{
1111 struct imx_udc_struct *imx_usb = dev; 1157 struct imx_udc_struct *imx_usb = dev;
1158 struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[0];
1112 int intr = __raw_readl(imx_usb->base + USB_EP_INTR(0)); 1159 int intr = __raw_readl(imx_usb->base + USB_EP_INTR(0));
1113 1160
1114 dump_ep_intr(__func__, 0, intr, imx_usb->dev); 1161 dump_ep_intr(__func__, 0, intr, imx_usb->dev);
@@ -1118,16 +1165,15 @@ static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev)
1118 return IRQ_HANDLED; 1165 return IRQ_HANDLED;
1119 } 1166 }
1120 1167
1121 /* DEVREQ IRQ has highest priority */ 1168 /* DEVREQ has highest priority */
1122 if (intr & (EPINTR_DEVREQ | EPINTR_MDEVREQ)) 1169 if (intr & (EPINTR_DEVREQ | EPINTR_MDEVREQ))
1123 handle_ep0_devreq(imx_usb); 1170 handle_ep0_devreq(imx_usb);
1124 /* Seem i.MX is missing EOF interrupt sometimes. 1171 /* Seem i.MX is missing EOF interrupt sometimes.
1125 * Therefore we monitor both EOF and FIFO_EMPTY interrups 1172 * Therefore we don't monitor EOF.
1126 * when transmiting, and both EOF and FIFO_FULL when 1173 * We call handle_ep0() only if a request is queued for ep0.
1127 * receiving data.
1128 */ 1174 */
1129 else if (intr & (EPINTR_EOF | EPINTR_FIFO_EMPTY | EPINTR_FIFO_FULL)) 1175 else if (!list_empty(&imx_ep->queue))
1130 handle_ep0(&imx_usb->imx_ep[0]); 1176 handle_ep0(imx_ep);
1131 1177
1132 __raw_writel(intr, imx_usb->base + USB_EP_INTR(0)); 1178 __raw_writel(intr, imx_usb->base + USB_EP_INTR(0));
1133 1179
@@ -1186,8 +1232,8 @@ static struct imx_udc_struct controller = {
1186 .ep0 = &controller.imx_ep[0].ep, 1232 .ep0 = &controller.imx_ep[0].ep,
1187 .name = driver_name, 1233 .name = driver_name,
1188 .dev = { 1234 .dev = {
1189 .bus_id = "gadget", 1235 .init_name = "gadget",
1190 }, 1236 },
1191 }, 1237 },
1192 1238
1193 .imx_ep[0] = { 1239 .imx_ep[0] = {
@@ -1318,6 +1364,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1318 1364
1319 udc_stop_activity(imx_usb, driver); 1365 udc_stop_activity(imx_usb, driver);
1320 imx_udc_disable(imx_usb); 1366 imx_udc_disable(imx_usb);
1367 del_timer(&imx_usb->timer);
1321 1368
1322 driver->unbind(&imx_usb->gadget); 1369 driver->unbind(&imx_usb->gadget);
1323 imx_usb->gadget.dev.driver = NULL; 1370 imx_usb->gadget.dev.driver = NULL;
@@ -1435,6 +1482,10 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1435 usb_init_data(imx_usb); 1482 usb_init_data(imx_usb);
1436 imx_udc_init(imx_usb); 1483 imx_udc_init(imx_usb);
1437 1484
1485 init_timer(&imx_usb->timer);
1486 imx_usb->timer.function = handle_config;
1487 imx_usb->timer.data = (unsigned long)imx_usb;
1488
1438 return 0; 1489 return 0;
1439 1490
1440fail3: 1491fail3:
@@ -1457,6 +1508,7 @@ static int __exit imx_udc_remove(struct platform_device *pdev)
1457 int i; 1508 int i;
1458 1509
1459 imx_udc_disable(imx_usb); 1510 imx_udc_disable(imx_usb);
1511 del_timer(&imx_usb->timer);
1460 1512
1461 for (i = 0; i < IMX_USB_NB_EP + 1; i++) 1513 for (i = 0; i < IMX_USB_NB_EP + 1; i++)
1462 free_irq(imx_usb->usbd_int[i], imx_usb); 1514 free_irq(imx_usb->usbd_int[i], imx_usb);
diff --git a/drivers/usb/gadget/imx_udc.h b/drivers/usb/gadget/imx_udc.h
index 850076937d8d..b48ad59603d1 100644
--- a/drivers/usb/gadget/imx_udc.h
+++ b/drivers/usb/gadget/imx_udc.h
@@ -23,7 +23,8 @@
23/* Helper macros */ 23/* Helper macros */
24#define EP_NO(ep) ((ep->bEndpointAddress) & ~USB_DIR_IN) /* IN:1, OUT:0 */ 24#define EP_NO(ep) ((ep->bEndpointAddress) & ~USB_DIR_IN) /* IN:1, OUT:0 */
25#define EP_DIR(ep) ((ep->bEndpointAddress) & USB_DIR_IN ? 1 : 0) 25#define EP_DIR(ep) ((ep->bEndpointAddress) & USB_DIR_IN ? 1 : 0)
26#define irq_to_ep(irq) (((irq) >= USBD_INT0) || ((irq) <= USBD_INT6) ? ((irq) - USBD_INT0) : (USBD_INT6)) /*should not happen*/ 26#define irq_to_ep(irq) (((irq) >= USBD_INT0) || ((irq) <= USBD_INT6) \
27 ? ((irq) - USBD_INT0) : (USBD_INT6)) /*should not happen*/
27#define ep_to_irq(ep) (EP_NO((ep)) + USBD_INT0) 28#define ep_to_irq(ep) (EP_NO((ep)) + USBD_INT0)
28#define IMX_USB_NB_EP 6 29#define IMX_USB_NB_EP 6
29 30
@@ -58,6 +59,7 @@ struct imx_udc_struct {
58 struct device *dev; 59 struct device *dev;
59 struct imx_ep_struct imx_ep[IMX_USB_NB_EP]; 60 struct imx_ep_struct imx_ep[IMX_USB_NB_EP];
60 struct clk *clk; 61 struct clk *clk;
62 struct timer_list timer;
61 enum ep0_state ep0state; 63 enum ep0_state ep0state;
62 struct resource *res; 64 struct resource *res;
63 void __iomem *base; 65 void __iomem *base;
@@ -88,8 +90,8 @@ struct imx_udc_struct {
88#define USB_EP_FDAT3(x) (0x3F + (x*0x30)) /* USB FIFO data */ 90#define USB_EP_FDAT3(x) (0x3F + (x*0x30)) /* USB FIFO data */
89#define USB_EP_FSTAT(x) (0x40 + (x*0x30)) /* USB FIFO status */ 91#define USB_EP_FSTAT(x) (0x40 + (x*0x30)) /* USB FIFO status */
90#define USB_EP_FCTRL(x) (0x44 + (x*0x30)) /* USB FIFO control */ 92#define USB_EP_FCTRL(x) (0x44 + (x*0x30)) /* USB FIFO control */
91#define USB_EP_LRFP(x) (0x48 + (x*0x30)) /* USB last read frame pointer */ 93#define USB_EP_LRFP(x) (0x48 + (x*0x30)) /* USB last rd f. pointer */
92#define USB_EP_LWFP(x) (0x4C + (x*0x30)) /* USB last write frame pointer */ 94#define USB_EP_LWFP(x) (0x4C + (x*0x30)) /* USB last wr f. pointer */
93#define USB_EP_FALRM(x) (0x50 + (x*0x30)) /* USB FIFO alarm */ 95#define USB_EP_FALRM(x) (0x50 + (x*0x30)) /* USB FIFO alarm */
94#define USB_EP_FRDP(x) (0x54 + (x*0x30)) /* USB FIFO read pointer */ 96#define USB_EP_FRDP(x) (0x54 + (x*0x30)) /* USB FIFO read pointer */
95#define USB_EP_FWRP(x) (0x58 + (x*0x30)) /* USB FIFO write pointer */ 97#define USB_EP_FWRP(x) (0x58 + (x*0x30)) /* USB FIFO write pointer */
@@ -170,7 +172,7 @@ struct imx_udc_struct {
170/* #define DEBUG_IRQ */ 172/* #define DEBUG_IRQ */
171/* #define DEBUG_EPIRQ */ 173/* #define DEBUG_EPIRQ */
172/* #define DEBUG_DUMP */ 174/* #define DEBUG_DUMP */
173#define DEBUG_ERR 175/* #define DEBUG_ERR */
174 176
175#ifdef DEBUG_REQ 177#ifdef DEBUG_REQ
176 #define D_REQ(dev, args...) dev_dbg(dev, ## args) 178 #define D_REQ(dev, args...) dev_dbg(dev, ## args)
@@ -228,7 +230,8 @@ struct imx_udc_struct {
228#endif /* DEBUG_IRQ */ 230#endif /* DEBUG_IRQ */
229 231
230#ifdef DEBUG_EPIRQ 232#ifdef DEBUG_EPIRQ
231 static void dump_ep_intr(const char *label, int nr, int irqreg, struct device *dev) 233 static void dump_ep_intr(const char *label, int nr, int irqreg,
234 struct device *dev)
232 { 235 {
233 dev_dbg(dev, "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, nr, 236 dev_dbg(dev, "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, nr,
234 (irqreg & EPINTR_FIFO_FULL) ? " full" : "", 237 (irqreg & EPINTR_FIFO_FULL) ? " full" : "",
@@ -246,7 +249,8 @@ struct imx_udc_struct {
246#endif /* DEBUG_IRQ */ 249#endif /* DEBUG_IRQ */
247 250
248#ifdef DEBUG_DUMP 251#ifdef DEBUG_DUMP
249 static void dump_usb_stat(const char *label, struct imx_udc_struct *imx_usb) 252 static void dump_usb_stat(const char *label,
253 struct imx_udc_struct *imx_usb)
250 { 254 {
251 int temp = __raw_readl(imx_usb->base + USB_STAT); 255 int temp = __raw_readl(imx_usb->base + USB_STAT);
252 256
@@ -259,12 +263,15 @@ struct imx_udc_struct {
259 (temp & STAT_ALTSET)); 263 (temp & STAT_ALTSET));
260 } 264 }
261 265
262 static void dump_ep_stat(const char *label, struct imx_ep_struct *imx_ep) 266 static void dump_ep_stat(const char *label,
267 struct imx_ep_struct *imx_ep)
263 { 268 {
264 int temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); 269 int temp = __raw_readl(imx_ep->imx_usb->base
270 + USB_EP_INTR(EP_NO(imx_ep)));
265 271
266 dev_dbg(imx_ep->imx_usb->dev, 272 dev_dbg(imx_ep->imx_usb->dev,
267 "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, EP_NO(imx_ep), 273 "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n",
274 label, EP_NO(imx_ep),
268 (temp & EPINTR_FIFO_FULL) ? " full" : "", 275 (temp & EPINTR_FIFO_FULL) ? " full" : "",
269 (temp & EPINTR_FIFO_EMPTY) ? " fempty" : "", 276 (temp & EPINTR_FIFO_EMPTY) ? " fempty" : "",
270 (temp & EPINTR_FIFO_ERROR) ? " ferr" : "", 277 (temp & EPINTR_FIFO_ERROR) ? " ferr" : "",
@@ -275,18 +282,22 @@ struct imx_udc_struct {
275 (temp & EPINTR_DEVREQ) ? " devreq" : "", 282 (temp & EPINTR_DEVREQ) ? " devreq" : "",
276 (temp & EPINTR_EOT) ? " eot" : ""); 283 (temp & EPINTR_EOT) ? " eot" : "");
277 284
278 temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); 285 temp = __raw_readl(imx_ep->imx_usb->base
286 + USB_EP_STAT(EP_NO(imx_ep)));
279 287
280 dev_dbg(imx_ep->imx_usb->dev, 288 dev_dbg(imx_ep->imx_usb->dev,
281 "<%s> EP%d_STAT=[%s%s bcount=%d]\n", label, EP_NO(imx_ep), 289 "<%s> EP%d_STAT=[%s%s bcount=%d]\n",
290 label, EP_NO(imx_ep),
282 (temp & EPSTAT_SIP) ? " sip" : "", 291 (temp & EPSTAT_SIP) ? " sip" : "",
283 (temp & EPSTAT_STALL) ? " stall" : "", 292 (temp & EPSTAT_STALL) ? " stall" : "",
284 (temp & EPSTAT_BCOUNT) >> 16); 293 (temp & EPSTAT_BCOUNT) >> 16);
285 294
286 temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_FSTAT(EP_NO(imx_ep))); 295 temp = __raw_readl(imx_ep->imx_usb->base
296 + USB_EP_FSTAT(EP_NO(imx_ep)));
287 297
288 dev_dbg(imx_ep->imx_usb->dev, 298 dev_dbg(imx_ep->imx_usb->dev,
289 "<%s> EP%d_FSTAT=[%s%s%s%s%s%s%s]\n", label, EP_NO(imx_ep), 299 "<%s> EP%d_FSTAT=[%s%s%s%s%s%s%s]\n",
300 label, EP_NO(imx_ep),
290 (temp & FSTAT_ERR) ? " ferr" : "", 301 (temp & FSTAT_ERR) ? " ferr" : "",
291 (temp & FSTAT_UF) ? " funder" : "", 302 (temp & FSTAT_UF) ? " funder" : "",
292 (temp & FSTAT_OF) ? " fover" : "", 303 (temp & FSTAT_OF) ? " fover" : "",
@@ -296,19 +307,23 @@ struct imx_udc_struct {
296 (temp & FSTAT_EMPTY) ? " fempty" : ""); 307 (temp & FSTAT_EMPTY) ? " fempty" : "");
297 } 308 }
298 309
299 static void dump_req(const char *label, struct imx_ep_struct *imx_ep, struct usb_request *req) 310 static void dump_req(const char *label, struct imx_ep_struct *imx_ep,
311 struct usb_request *req)
300 { 312 {
301 int i; 313 int i;
302 314
303 if (!req || !req->buf) { 315 if (!req || !req->buf) {
304 dev_dbg(imx_ep->imx_usb->dev, "<%s> req or req buf is free\n", label); 316 dev_dbg(imx_ep->imx_usb->dev,
317 "<%s> req or req buf is free\n", label);
305 return; 318 return;
306 } 319 }
307 320
308 if ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state == EP0_IN_DATA_PHASE) 321 if ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state
322 == EP0_IN_DATA_PHASE)
309 || (EP_NO(imx_ep) && EP_DIR(imx_ep))) { 323 || (EP_NO(imx_ep) && EP_DIR(imx_ep))) {
310 324
311 dev_dbg(imx_ep->imx_usb->dev, "<%s> request dump <", label); 325 dev_dbg(imx_ep->imx_usb->dev,
326 "<%s> request dump <", label);
312 for (i = 0; i < req->length; i++) 327 for (i = 0; i < req->length; i++)
313 printk("%02x-", *((u8 *)req->buf + i)); 328 printk("%02x-", *((u8 *)req->buf + i));
314 printk(">\n"); 329 printk(">\n");
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 317b48fdbf01..d20937f28a19 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1334,7 +1334,7 @@ static void make_qualifier (struct dev_data *dev)
1334 1334
1335 qual.bLength = sizeof qual; 1335 qual.bLength = sizeof qual;
1336 qual.bDescriptorType = USB_DT_DEVICE_QUALIFIER; 1336 qual.bDescriptorType = USB_DT_DEVICE_QUALIFIER;
1337 qual.bcdUSB = __constant_cpu_to_le16 (0x0200); 1337 qual.bcdUSB = cpu_to_le16 (0x0200);
1338 1338
1339 desc = dev->dev; 1339 desc = dev->dev;
1340 qual.bDeviceClass = desc->bDeviceClass; 1340 qual.bDeviceClass = desc->bDeviceClass;
@@ -1908,7 +1908,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1908 || dev->dev->bNumConfigurations != 1) 1908 || dev->dev->bNumConfigurations != 1)
1909 goto fail; 1909 goto fail;
1910 dev->dev->bNumConfigurations = 1; 1910 dev->dev->bNumConfigurations = 1;
1911 dev->dev->bcdUSB = __constant_cpu_to_le16 (0x0200); 1911 dev->dev->bcdUSB = cpu_to_le16 (0x0200);
1912 1912
1913 /* triggers gadgetfs_bind(); then we can enumerate. */ 1913 /* triggers gadgetfs_bind(); then we can enumerate. */
1914 spin_unlock_irq (&dev->lock); 1914 spin_unlock_irq (&dev->lock);
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index d554b0895603..6cd3d54f5640 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -432,8 +432,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
432 device_add(&dev->gadget.dev); 432 device_add(&dev->gadget.dev);
433 retval = driver->bind(&dev->gadget); 433 retval = driver->bind(&dev->gadget);
434 if (retval) { 434 if (retval) {
435 printk("%s: bind to driver %s --> error %d\n", dev->gadget.name, 435 printk(KERN_WARNING "%s: bind to driver %s --> error %d\n",
436 driver->driver.name, retval); 436 dev->gadget.name, driver->driver.name, retval);
437 device_del(&dev->gadget.dev); 437 device_del(&dev->gadget.dev);
438 438
439 dev->driver = 0; 439 dev->driver = 0;
@@ -445,8 +445,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
445 * for set_configuration as well as eventual disconnect. 445 * for set_configuration as well as eventual disconnect.
446 * NOTE: this shouldn't power up until later. 446 * NOTE: this shouldn't power up until later.
447 */ 447 */
448 printk("%s: registered gadget driver '%s'\n", dev->gadget.name, 448 printk(KERN_WARNING "%s: registered gadget driver '%s'\n",
449 driver->driver.name); 449 dev->gadget.name, driver->driver.name);
450 450
451 udc_enable(dev); 451 udc_enable(dev);
452 452
@@ -581,7 +581,8 @@ static int read_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
581 * discard the extra data. 581 * discard the extra data.
582 */ 582 */
583 if (req->req.status != -EOVERFLOW) 583 if (req->req.status != -EOVERFLOW)
584 printk("%s overflow %d\n", ep->ep.name, count); 584 printk(KERN_WARNING "%s overflow %d\n",
585 ep->ep.name, count);
585 req->req.status = -EOVERFLOW; 586 req->req.status = -EOVERFLOW;
586 } else { 587 } else {
587 *buf++ = byte; 588 *buf++ = byte;
@@ -831,7 +832,8 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
831 queue); 832 queue);
832 833
833 if (!req) { 834 if (!req) {
834 printk("%s: NULL REQ %d\n", 835 printk(KERN_WARNING
836 "%s: NULL REQ %d\n",
835 __func__, ep_idx); 837 __func__, ep_idx);
836 flush(ep); 838 flush(ep);
837 break; 839 break;
@@ -844,7 +846,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
844 846
845 } else { 847 } else {
846 /* Throw packet away.. */ 848 /* Throw packet away.. */
847 printk("%s: No descriptor?!?\n", __func__); 849 printk(KERN_WARNING "%s: No descriptor?!?\n", __func__);
848 flush(ep); 850 flush(ep);
849 } 851 }
850} 852}
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 12c6d83b218c..9498be87a724 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -142,8 +142,8 @@ static char *type_string (u8 bmAttributes)
142 142
143#include "net2280.h" 143#include "net2280.h"
144 144
145#define valid_bit __constant_cpu_to_le32 (1 << VALID_BIT) 145#define valid_bit cpu_to_le32 (1 << VALID_BIT)
146#define dma_done_ie __constant_cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE) 146#define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
147 147
148/*-------------------------------------------------------------------------*/ 148/*-------------------------------------------------------------------------*/
149 149
@@ -425,7 +425,7 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
425 return NULL; 425 return NULL;
426 } 426 }
427 td->dmacount = 0; /* not VALID */ 427 td->dmacount = 0; /* not VALID */
428 td->dmaaddr = __constant_cpu_to_le32 (DMA_ADDR_INVALID); 428 td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
429 td->dmadesc = td->dmaaddr; 429 td->dmadesc = td->dmaaddr;
430 req->td = td; 430 req->td = td;
431 } 431 }
@@ -775,7 +775,7 @@ static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
775 fill_dma_desc (ep, req, 1); 775 fill_dma_desc (ep, req, 1);
776 776
777 if (!use_dma_chaining) 777 if (!use_dma_chaining)
778 req->td->dmacount |= __constant_cpu_to_le32 (1 << END_OF_CHAIN); 778 req->td->dmacount |= cpu_to_le32 (1 << END_OF_CHAIN);
779 779
780 start_queue (ep, tmp, req->td_dma); 780 start_queue (ep, tmp, req->td_dma);
781} 781}
@@ -2407,9 +2407,9 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2407 2407
2408 if (readl (&e->regs->ep_rsp) 2408 if (readl (&e->regs->ep_rsp)
2409 & (1 << SET_ENDPOINT_HALT)) 2409 & (1 << SET_ENDPOINT_HALT))
2410 status = __constant_cpu_to_le32 (1); 2410 status = cpu_to_le32 (1);
2411 else 2411 else
2412 status = __constant_cpu_to_le32 (0); 2412 status = cpu_to_le32 (0);
2413 2413
2414 /* don't bother with a request object! */ 2414 /* don't bother with a request object! */
2415 writel (0, &dev->epregs [0].ep_irqenb); 2415 writel (0, &dev->epregs [0].ep_irqenb);
@@ -2667,7 +2667,7 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2667 req = list_entry (ep->queue.next, 2667 req = list_entry (ep->queue.next,
2668 struct net2280_request, queue); 2668 struct net2280_request, queue);
2669 dmacount = req->td->dmacount; 2669 dmacount = req->td->dmacount;
2670 dmacount &= __constant_cpu_to_le32 ( 2670 dmacount &= cpu_to_le32 (
2671 (1 << VALID_BIT) 2671 (1 << VALID_BIT)
2672 | DMA_BYTE_COUNT_MASK); 2672 | DMA_BYTE_COUNT_MASK);
2673 if (dmacount && (dmacount & valid_bit) == 0) 2673 if (dmacount && (dmacount & valid_bit) == 0)
@@ -2881,7 +2881,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2881 goto done; 2881 goto done;
2882 } 2882 }
2883 td->dmacount = 0; /* not VALID */ 2883 td->dmacount = 0; /* not VALID */
2884 td->dmaaddr = __constant_cpu_to_le32 (DMA_ADDR_INVALID); 2884 td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
2885 td->dmadesc = td->dmaaddr; 2885 td->dmadesc = td->dmaaddr;
2886 dev->ep [i].dummy = td; 2886 dev->ep [i].dummy = td;
2887 } 2887 }
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 5a3034fdfe47..29500154d00c 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -225,12 +225,12 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR);
225static struct usb_device_descriptor device_desc = { 225static struct usb_device_descriptor device_desc = {
226 .bLength = sizeof device_desc, 226 .bLength = sizeof device_desc,
227 .bDescriptorType = USB_DT_DEVICE, 227 .bDescriptorType = USB_DT_DEVICE,
228 .bcdUSB = __constant_cpu_to_le16(0x0200), 228 .bcdUSB = cpu_to_le16(0x0200),
229 .bDeviceClass = USB_CLASS_PER_INTERFACE, 229 .bDeviceClass = USB_CLASS_PER_INTERFACE,
230 .bDeviceSubClass = 0, 230 .bDeviceSubClass = 0,
231 .bDeviceProtocol = 0, 231 .bDeviceProtocol = 0,
232 .idVendor = __constant_cpu_to_le16(PRINTER_VENDOR_NUM), 232 .idVendor = cpu_to_le16(PRINTER_VENDOR_NUM),
233 .idProduct = __constant_cpu_to_le16(PRINTER_PRODUCT_NUM), 233 .idProduct = cpu_to_le16(PRINTER_PRODUCT_NUM),
234 .iManufacturer = STRING_MANUFACTURER, 234 .iManufacturer = STRING_MANUFACTURER,
235 .iProduct = STRING_PRODUCT, 235 .iProduct = STRING_PRODUCT,
236 .iSerialNumber = STRING_SERIALNUM, 236 .iSerialNumber = STRING_SERIALNUM,
@@ -299,20 +299,20 @@ static struct usb_endpoint_descriptor hs_ep_in_desc = {
299 .bLength = USB_DT_ENDPOINT_SIZE, 299 .bLength = USB_DT_ENDPOINT_SIZE,
300 .bDescriptorType = USB_DT_ENDPOINT, 300 .bDescriptorType = USB_DT_ENDPOINT,
301 .bmAttributes = USB_ENDPOINT_XFER_BULK, 301 .bmAttributes = USB_ENDPOINT_XFER_BULK,
302 .wMaxPacketSize = __constant_cpu_to_le16(512) 302 .wMaxPacketSize = cpu_to_le16(512)
303}; 303};
304 304
305static struct usb_endpoint_descriptor hs_ep_out_desc = { 305static struct usb_endpoint_descriptor hs_ep_out_desc = {
306 .bLength = USB_DT_ENDPOINT_SIZE, 306 .bLength = USB_DT_ENDPOINT_SIZE,
307 .bDescriptorType = USB_DT_ENDPOINT, 307 .bDescriptorType = USB_DT_ENDPOINT,
308 .bmAttributes = USB_ENDPOINT_XFER_BULK, 308 .bmAttributes = USB_ENDPOINT_XFER_BULK,
309 .wMaxPacketSize = __constant_cpu_to_le16(512) 309 .wMaxPacketSize = cpu_to_le16(512)
310}; 310};
311 311
312static struct usb_qualifier_descriptor dev_qualifier = { 312static struct usb_qualifier_descriptor dev_qualifier = {
313 .bLength = sizeof dev_qualifier, 313 .bLength = sizeof dev_qualifier,
314 .bDescriptorType = USB_DT_DEVICE_QUALIFIER, 314 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
315 .bcdUSB = __constant_cpu_to_le16(0x0200), 315 .bcdUSB = cpu_to_le16(0x0200),
316 .bDeviceClass = USB_CLASS_PRINTER, 316 .bDeviceClass = USB_CLASS_PRINTER,
317 .bNumConfigurations = 1 317 .bNumConfigurations = 1
318}; 318};
@@ -1406,16 +1406,16 @@ printer_bind(struct usb_gadget *gadget)
1406 gadget->name); 1406 gadget->name);
1407 /* unrecognized, but safe unless bulk is REALLY quirky */ 1407 /* unrecognized, but safe unless bulk is REALLY quirky */
1408 device_desc.bcdDevice = 1408 device_desc.bcdDevice =
1409 __constant_cpu_to_le16(0xFFFF); 1409 cpu_to_le16(0xFFFF);
1410 } 1410 }
1411 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s", 1411 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
1412 init_utsname()->sysname, init_utsname()->release, 1412 init_utsname()->sysname, init_utsname()->release,
1413 gadget->name); 1413 gadget->name);
1414 1414
1415 device_desc.idVendor = 1415 device_desc.idVendor =
1416 __constant_cpu_to_le16(PRINTER_VENDOR_NUM); 1416 cpu_to_le16(PRINTER_VENDOR_NUM);
1417 device_desc.idProduct = 1417 device_desc.idProduct =
1418 __constant_cpu_to_le16(PRINTER_PRODUCT_NUM); 1418 cpu_to_le16(PRINTER_PRODUCT_NUM);
1419 1419
1420 /* support optional vendor/distro customization */ 1420 /* support optional vendor/distro customization */
1421 if (idVendor) { 1421 if (idVendor) {
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index 9b36205c5759..0ce4e2819847 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -904,8 +904,8 @@ static void pxa25x_ep_fifo_flush(struct usb_ep *_ep)
904 904
905 /* most IN status is the same, but ISO can't stall */ 905 /* most IN status is the same, but ISO can't stall */
906 *ep->reg_udccs = UDCCS_BI_TPC|UDCCS_BI_FTF|UDCCS_BI_TUR 906 *ep->reg_udccs = UDCCS_BI_TPC|UDCCS_BI_FTF|UDCCS_BI_TUR
907 | (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) 907 | (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
908 ? 0 : UDCCS_BI_SST; 908 ? 0 : UDCCS_BI_SST);
909} 909}
910 910
911 911
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 990f40f988d4..8cc676ecbb23 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -30,6 +30,7 @@
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/clk.h> 31#include <linux/clk.h>
32#include <linux/irq.h> 32#include <linux/irq.h>
33#include <linux/gpio.h>
33 34
34#include <asm/byteorder.h> 35#include <asm/byteorder.h>
35#include <mach/hardware.h> 36#include <mach/hardware.h>
@@ -278,7 +279,7 @@ static void pxa_init_debugfs(struct pxa_udc *udc)
278 goto err_queues; 279 goto err_queues;
279 eps = debugfs_create_file("epstate", 0400, root, udc, 280 eps = debugfs_create_file("epstate", 0400, root, udc,
280 &eps_dbg_fops); 281 &eps_dbg_fops);
281 if (!queues) 282 if (!eps)
282 goto err_eps; 283 goto err_eps;
283 284
284 udc->debugfs_root = root; 285 udc->debugfs_root = root;
@@ -747,13 +748,13 @@ static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status)
747} 748}
748 749
749/** 750/**
750 * ep_end_out_req - Ends control endpoint in request 751 * ep_end_out_req - Ends endpoint OUT request
751 * @ep: physical endpoint 752 * @ep: physical endpoint
752 * @req: pxa request 753 * @req: pxa request
753 * 754 *
754 * Context: ep->lock held 755 * Context: ep->lock held
755 * 756 *
756 * Ends endpoint in request (completes usb request). 757 * Ends endpoint OUT request (completes usb request).
757 */ 758 */
758static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) 759static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
759{ 760{
@@ -762,13 +763,13 @@ static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
762} 763}
763 764
764/** 765/**
765 * ep0_end_out_req - Ends control endpoint in request (ends data stage) 766 * ep0_end_out_req - Ends control endpoint OUT request (ends data stage)
766 * @ep: physical endpoint 767 * @ep: physical endpoint
767 * @req: pxa request 768 * @req: pxa request
768 * 769 *
769 * Context: ep->lock held 770 * Context: ep->lock held
770 * 771 *
771 * Ends control endpoint in request (completes usb request), and puts 772 * Ends control endpoint OUT request (completes usb request), and puts
772 * control endpoint into idle state 773 * control endpoint into idle state
773 */ 774 */
774static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) 775static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
@@ -779,13 +780,13 @@ static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
779} 780}
780 781
781/** 782/**
782 * ep_end_in_req - Ends endpoint out request 783 * ep_end_in_req - Ends endpoint IN request
783 * @ep: physical endpoint 784 * @ep: physical endpoint
784 * @req: pxa request 785 * @req: pxa request
785 * 786 *
786 * Context: ep->lock held 787 * Context: ep->lock held
787 * 788 *
788 * Ends endpoint out request (completes usb request). 789 * Ends endpoint IN request (completes usb request).
789 */ 790 */
790static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) 791static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
791{ 792{
@@ -794,20 +795,18 @@ static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
794} 795}
795 796
796/** 797/**
797 * ep0_end_in_req - Ends control endpoint out request (ends data stage) 798 * ep0_end_in_req - Ends control endpoint IN request (ends data stage)
798 * @ep: physical endpoint 799 * @ep: physical endpoint
799 * @req: pxa request 800 * @req: pxa request
800 * 801 *
801 * Context: ep->lock held 802 * Context: ep->lock held
802 * 803 *
803 * Ends control endpoint out request (completes usb request), and puts 804 * Ends control endpoint IN request (completes usb request), and puts
804 * control endpoint into status state 805 * control endpoint into status state
805 */ 806 */
806static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) 807static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
807{ 808{
808 struct pxa_udc *udc = ep->dev; 809 set_ep0state(ep->dev, IN_STATUS_STAGE);
809
810 set_ep0state(udc, IN_STATUS_STAGE);
811 ep_end_in_req(ep, req); 810 ep_end_in_req(ep, req);
812} 811}
813 812
@@ -1167,7 +1166,7 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1167 ep_end_in_req(ep, req); 1166 ep_end_in_req(ep, req);
1168 } else { 1167 } else {
1169 ep_err(ep, "got a request of %d bytes while" 1168 ep_err(ep, "got a request of %d bytes while"
1170 "in state WATI_ACK_SET_CONF_INTERF\n", 1169 "in state WAIT_ACK_SET_CONF_INTERF\n",
1171 length); 1170 length);
1172 ep_del_request(ep, req); 1171 ep_del_request(ep, req);
1173 rc = -EL2HLT; 1172 rc = -EL2HLT;
@@ -1213,30 +1212,26 @@ static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1213 struct udc_usb_ep *udc_usb_ep; 1212 struct udc_usb_ep *udc_usb_ep;
1214 struct pxa27x_request *req; 1213 struct pxa27x_request *req;
1215 unsigned long flags; 1214 unsigned long flags;
1216 int rc; 1215 int rc = -EINVAL;
1217 1216
1218 if (!_ep) 1217 if (!_ep)
1219 return -EINVAL; 1218 return rc;
1220 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep); 1219 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1221 ep = udc_usb_ep->pxa_ep; 1220 ep = udc_usb_ep->pxa_ep;
1222 if (!ep || is_ep0(ep)) 1221 if (!ep || is_ep0(ep))
1223 return -EINVAL; 1222 return rc;
1224 1223
1225 spin_lock_irqsave(&ep->lock, flags); 1224 spin_lock_irqsave(&ep->lock, flags);
1226 1225
1227 /* make sure it's actually queued on this endpoint */ 1226 /* make sure it's actually queued on this endpoint */
1228 list_for_each_entry(req, &ep->queue, queue) { 1227 list_for_each_entry(req, &ep->queue, queue) {
1229 if (&req->req == _req) 1228 if (&req->req == _req) {
1229 req_done(ep, req, -ECONNRESET);
1230 rc = 0;
1230 break; 1231 break;
1232 }
1231 } 1233 }
1232 1234
1233 rc = -EINVAL;
1234 if (&req->req != _req)
1235 goto out;
1236
1237 rc = 0;
1238 req_done(ep, req, -ECONNRESET);
1239out:
1240 spin_unlock_irqrestore(&ep->lock, flags); 1235 spin_unlock_irqrestore(&ep->lock, flags);
1241 return rc; 1236 return rc;
1242} 1237}
@@ -1471,6 +1466,32 @@ static struct usb_ep_ops pxa_ep_ops = {
1471 .fifo_flush = pxa_ep_fifo_flush, 1466 .fifo_flush = pxa_ep_fifo_flush,
1472}; 1467};
1473 1468
1469/**
1470 * dplus_pullup - Connect or disconnect pullup resistor to D+ pin
1471 * @udc: udc device
1472 * @on: 0 if disconnect pullup resistor, 1 otherwise
1473 * Context: any
1474 *
1475 * Handle D+ pullup resistor, make the device visible to the usb bus, and
1476 * declare it as a full speed usb device
1477 */
1478static void dplus_pullup(struct pxa_udc *udc, int on)
1479{
1480 if (on) {
1481 if (gpio_is_valid(udc->mach->gpio_pullup))
1482 gpio_set_value(udc->mach->gpio_pullup,
1483 !udc->mach->gpio_pullup_inverted);
1484 if (udc->mach->udc_command)
1485 udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
1486 } else {
1487 if (gpio_is_valid(udc->mach->gpio_pullup))
1488 gpio_set_value(udc->mach->gpio_pullup,
1489 udc->mach->gpio_pullup_inverted);
1490 if (udc->mach->udc_command)
1491 udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
1492 }
1493 udc->pullup_on = on;
1494}
1474 1495
1475/** 1496/**
1476 * pxa_udc_get_frame - Returns usb frame number 1497 * pxa_udc_get_frame - Returns usb frame number
@@ -1500,21 +1521,145 @@ static int pxa_udc_wakeup(struct usb_gadget *_gadget)
1500 return 0; 1521 return 0;
1501} 1522}
1502 1523
1524static void udc_enable(struct pxa_udc *udc);
1525static void udc_disable(struct pxa_udc *udc);
1526
1527/**
1528 * should_enable_udc - Tells if UDC should be enabled
1529 * @udc: udc device
1530 * Context: any
1531 *
1532 * The UDC should be enabled if :
1533
1534 * - the pullup resistor is connected
1535 * - and a gadget driver is bound
1536 * - and vbus is sensed (or no vbus sense is available)
1537 *
1538 * Returns 1 if UDC should be enabled, 0 otherwise
1539 */
1540static int should_enable_udc(struct pxa_udc *udc)
1541{
1542 int put_on;
1543
1544 put_on = ((udc->pullup_on) && (udc->driver));
1545 put_on &= ((udc->vbus_sensed) || (!udc->transceiver));
1546 return put_on;
1547}
1548
1549/**
1550 * should_disable_udc - Tells if UDC should be disabled
1551 * @udc: udc device
1552 * Context: any
1553 *
1554 * The UDC should be disabled if :
1555 * - the pullup resistor is not connected
1556 * - or no gadget driver is bound
1557 * - or no vbus is sensed (when vbus sesing is available)
1558 *
1559 * Returns 1 if UDC should be disabled
1560 */
1561static int should_disable_udc(struct pxa_udc *udc)
1562{
1563 int put_off;
1564
1565 put_off = ((!udc->pullup_on) || (!udc->driver));
1566 put_off |= ((!udc->vbus_sensed) && (udc->transceiver));
1567 return put_off;
1568}
1569
1570/**
1571 * pxa_udc_pullup - Offer manual D+ pullup control
1572 * @_gadget: usb gadget using the control
1573 * @is_active: 0 if disconnect, else connect D+ pullup resistor
1574 * Context: !in_interrupt()
1575 *
1576 * Returns 0 if OK, -EOPNOTSUPP if udc driver doesn't handle D+ pullup
1577 */
1578static int pxa_udc_pullup(struct usb_gadget *_gadget, int is_active)
1579{
1580 struct pxa_udc *udc = to_gadget_udc(_gadget);
1581
1582 if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command)
1583 return -EOPNOTSUPP;
1584
1585 dplus_pullup(udc, is_active);
1586
1587 if (should_enable_udc(udc))
1588 udc_enable(udc);
1589 if (should_disable_udc(udc))
1590 udc_disable(udc);
1591 return 0;
1592}
1593
1594static void udc_enable(struct pxa_udc *udc);
1595static void udc_disable(struct pxa_udc *udc);
1596
1597/**
1598 * pxa_udc_vbus_session - Called by external transceiver to enable/disable udc
1599 * @_gadget: usb gadget
1600 * @is_active: 0 if should disable the udc, 1 if should enable
1601 *
1602 * Enables the udc, and optionnaly activates D+ pullup resistor. Or disables the
1603 * udc, and deactivates D+ pullup resistor.
1604 *
1605 * Returns 0
1606 */
1607static int pxa_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
1608{
1609 struct pxa_udc *udc = to_gadget_udc(_gadget);
1610
1611 udc->vbus_sensed = is_active;
1612 if (should_enable_udc(udc))
1613 udc_enable(udc);
1614 if (should_disable_udc(udc))
1615 udc_disable(udc);
1616
1617 return 0;
1618}
1619
1620/**
1621 * pxa_udc_vbus_draw - Called by gadget driver after SET_CONFIGURATION completed
1622 * @_gadget: usb gadget
1623 * @mA: current drawn
1624 *
1625 * Context: !in_interrupt()
1626 *
1627 * Called after a configuration was chosen by a USB host, to inform how much
1628 * current can be drawn by the device from VBus line.
1629 *
1630 * Returns 0 or -EOPNOTSUPP if no transceiver is handling the udc
1631 */
1632static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1633{
1634 struct pxa_udc *udc;
1635
1636 udc = to_gadget_udc(_gadget);
1637 if (udc->transceiver)
1638 return otg_set_power(udc->transceiver, mA);
1639 return -EOPNOTSUPP;
1640}
1641
1503static const struct usb_gadget_ops pxa_udc_ops = { 1642static const struct usb_gadget_ops pxa_udc_ops = {
1504 .get_frame = pxa_udc_get_frame, 1643 .get_frame = pxa_udc_get_frame,
1505 .wakeup = pxa_udc_wakeup, 1644 .wakeup = pxa_udc_wakeup,
1506 /* current versions must always be self-powered */ 1645 .pullup = pxa_udc_pullup,
1646 .vbus_session = pxa_udc_vbus_session,
1647 .vbus_draw = pxa_udc_vbus_draw,
1507}; 1648};
1508 1649
1509/** 1650/**
1510 * udc_disable - disable udc device controller 1651 * udc_disable - disable udc device controller
1511 * @udc: udc device 1652 * @udc: udc device
1653 * Context: any
1512 * 1654 *
1513 * Disables the udc device : disables clocks, udc interrupts, control endpoint 1655 * Disables the udc device : disables clocks, udc interrupts, control endpoint
1514 * interrupts. 1656 * interrupts.
1515 */ 1657 */
1516static void udc_disable(struct pxa_udc *udc) 1658static void udc_disable(struct pxa_udc *udc)
1517{ 1659{
1660 if (!udc->enabled)
1661 return;
1662
1518 udc_writel(udc, UDCICR0, 0); 1663 udc_writel(udc, UDCICR0, 0);
1519 udc_writel(udc, UDCICR1, 0); 1664 udc_writel(udc, UDCICR1, 0);
1520 1665
@@ -1523,8 +1668,8 @@ static void udc_disable(struct pxa_udc *udc)
1523 1668
1524 ep0_idle(udc); 1669 ep0_idle(udc);
1525 udc->gadget.speed = USB_SPEED_UNKNOWN; 1670 udc->gadget.speed = USB_SPEED_UNKNOWN;
1526 if (udc->mach->udc_command) 1671
1527 udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 1672 udc->enabled = 0;
1528} 1673}
1529 1674
1530/** 1675/**
@@ -1555,10 +1700,9 @@ static __init void udc_init_data(struct pxa_udc *dev)
1555 } 1700 }
1556 1701
1557 /* USB endpoints init */ 1702 /* USB endpoints init */
1558 for (i = 0; i < NR_USB_ENDPOINTS; i++) 1703 for (i = 1; i < NR_USB_ENDPOINTS; i++)
1559 if (i != 0) 1704 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list,
1560 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, 1705 &dev->gadget.ep_list);
1561 &dev->gadget.ep_list);
1562} 1706}
1563 1707
1564/** 1708/**
@@ -1570,6 +1714,9 @@ static __init void udc_init_data(struct pxa_udc *dev)
1570 */ 1714 */
1571static void udc_enable(struct pxa_udc *udc) 1715static void udc_enable(struct pxa_udc *udc)
1572{ 1716{
1717 if (udc->enabled)
1718 return;
1719
1573 udc_writel(udc, UDCICR0, 0); 1720 udc_writel(udc, UDCICR0, 0);
1574 udc_writel(udc, UDCICR1, 0); 1721 udc_writel(udc, UDCICR1, 0);
1575 udc_clear_mask_UDCCR(udc, UDCCR_UDE); 1722 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
@@ -1598,9 +1745,7 @@ static void udc_enable(struct pxa_udc *udc)
1598 /* enable ep0 irqs */ 1745 /* enable ep0 irqs */
1599 pio_irq_enable(&udc->pxa_ep[0]); 1746 pio_irq_enable(&udc->pxa_ep[0]);
1600 1747
1601 dev_info(udc->dev, "UDC connecting\n"); 1748 udc->enabled = 1;
1602 if (udc->mach->udc_command)
1603 udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
1604} 1749}
1605 1750
1606/** 1751/**
@@ -1612,6 +1757,9 @@ static void udc_enable(struct pxa_udc *udc)
1612 * usb traffic follows until a disconnect is reported. Then a host may connect 1757 * usb traffic follows until a disconnect is reported. Then a host may connect
1613 * again, or the driver might get unbound. 1758 * again, or the driver might get unbound.
1614 * 1759 *
1760 * Note that the udc is not automatically enabled. Check function
1761 * should_enable_udc().
1762 *
1615 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1763 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1616 */ 1764 */
1617int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1765int usb_gadget_register_driver(struct usb_gadget_driver *driver)
@@ -1630,6 +1778,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1630 /* first hook up the driver ... */ 1778 /* first hook up the driver ... */
1631 udc->driver = driver; 1779 udc->driver = driver;
1632 udc->gadget.dev.driver = &driver->driver; 1780 udc->gadget.dev.driver = &driver->driver;
1781 dplus_pullup(udc, 1);
1633 1782
1634 retval = device_add(&udc->gadget.dev); 1783 retval = device_add(&udc->gadget.dev);
1635 if (retval) { 1784 if (retval) {
@@ -1645,9 +1794,21 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1645 dev_dbg(udc->dev, "registered gadget driver '%s'\n", 1794 dev_dbg(udc->dev, "registered gadget driver '%s'\n",
1646 driver->driver.name); 1795 driver->driver.name);
1647 1796
1648 udc_enable(udc); 1797 if (udc->transceiver) {
1798 retval = otg_set_peripheral(udc->transceiver, &udc->gadget);
1799 if (retval) {
1800 dev_err(udc->dev, "can't bind to transceiver\n");
1801 goto transceiver_fail;
1802 }
1803 }
1804
1805 if (should_enable_udc(udc))
1806 udc_enable(udc);
1649 return 0; 1807 return 0;
1650 1808
1809transceiver_fail:
1810 if (driver->unbind)
1811 driver->unbind(&udc->gadget);
1651bind_fail: 1812bind_fail:
1652 device_del(&udc->gadget.dev); 1813 device_del(&udc->gadget.dev);
1653add_fail: 1814add_fail:
@@ -1699,14 +1860,17 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1699 1860
1700 stop_activity(udc, driver); 1861 stop_activity(udc, driver);
1701 udc_disable(udc); 1862 udc_disable(udc);
1863 dplus_pullup(udc, 0);
1702 1864
1703 driver->unbind(&udc->gadget); 1865 driver->unbind(&udc->gadget);
1704 udc->driver = NULL; 1866 udc->driver = NULL;
1705 1867
1706 device_del(&udc->gadget.dev); 1868 device_del(&udc->gadget.dev);
1707
1708 dev_info(udc->dev, "unregistered gadget driver '%s'\n", 1869 dev_info(udc->dev, "unregistered gadget driver '%s'\n",
1709 driver->driver.name); 1870 driver->driver.name);
1871
1872 if (udc->transceiver)
1873 return otg_set_peripheral(udc->transceiver, NULL);
1710 return 0; 1874 return 0;
1711} 1875}
1712EXPORT_SYMBOL(usb_gadget_unregister_driver); 1876EXPORT_SYMBOL(usb_gadget_unregister_driver);
@@ -1823,14 +1987,14 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
1823 struct pxa27x_request *req = NULL; 1987 struct pxa27x_request *req = NULL;
1824 int completed = 0; 1988 int completed = 0;
1825 1989
1990 if (!list_empty(&ep->queue))
1991 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
1992
1826 udccsr0 = udc_ep_readl(ep, UDCCSR); 1993 udccsr0 = udc_ep_readl(ep, UDCCSR);
1827 ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n", 1994 ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n",
1828 EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR), 1995 EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR),
1829 (fifo_irq << 1 | opc_irq)); 1996 (fifo_irq << 1 | opc_irq));
1830 1997
1831 if (!list_empty(&ep->queue))
1832 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
1833
1834 if (udccsr0 & UDCCSR0_SST) { 1998 if (udccsr0 & UDCCSR0_SST) {
1835 ep_dbg(ep, "clearing stall status\n"); 1999 ep_dbg(ep, "clearing stall status\n");
1836 nuke(ep, -EPIPE); 2000 nuke(ep, -EPIPE);
@@ -2212,7 +2376,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2212{ 2376{
2213 struct resource *regs; 2377 struct resource *regs;
2214 struct pxa_udc *udc = &memory; 2378 struct pxa_udc *udc = &memory;
2215 int retval; 2379 int retval = 0, gpio;
2216 2380
2217 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2381 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2218 if (!regs) 2382 if (!regs)
@@ -2223,6 +2387,20 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2223 2387
2224 udc->dev = &pdev->dev; 2388 udc->dev = &pdev->dev;
2225 udc->mach = pdev->dev.platform_data; 2389 udc->mach = pdev->dev.platform_data;
2390 udc->transceiver = otg_get_transceiver();
2391
2392 gpio = udc->mach->gpio_pullup;
2393 if (gpio_is_valid(gpio)) {
2394 retval = gpio_request(gpio, "USB D+ pullup");
2395 if (retval == 0)
2396 gpio_direction_output(gpio,
2397 udc->mach->gpio_pullup_inverted);
2398 }
2399 if (retval) {
2400 dev_err(&pdev->dev, "Couldn't request gpio %d : %d\n",
2401 gpio, retval);
2402 return retval;
2403 }
2226 2404
2227 udc->clk = clk_get(&pdev->dev, NULL); 2405 udc->clk = clk_get(&pdev->dev, NULL);
2228 if (IS_ERR(udc->clk)) { 2406 if (IS_ERR(udc->clk)) {
@@ -2240,6 +2418,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2240 device_initialize(&udc->gadget.dev); 2418 device_initialize(&udc->gadget.dev);
2241 udc->gadget.dev.parent = &pdev->dev; 2419 udc->gadget.dev.parent = &pdev->dev;
2242 udc->gadget.dev.dma_mask = NULL; 2420 udc->gadget.dev.dma_mask = NULL;
2421 udc->vbus_sensed = 0;
2243 2422
2244 the_controller = udc; 2423 the_controller = udc;
2245 platform_set_drvdata(pdev, udc); 2424 platform_set_drvdata(pdev, udc);
@@ -2273,14 +2452,21 @@ err_clk:
2273static int __exit pxa_udc_remove(struct platform_device *_dev) 2452static int __exit pxa_udc_remove(struct platform_device *_dev)
2274{ 2453{
2275 struct pxa_udc *udc = platform_get_drvdata(_dev); 2454 struct pxa_udc *udc = platform_get_drvdata(_dev);
2455 int gpio = udc->mach->gpio_pullup;
2276 2456
2277 usb_gadget_unregister_driver(udc->driver); 2457 usb_gadget_unregister_driver(udc->driver);
2278 free_irq(udc->irq, udc); 2458 free_irq(udc->irq, udc);
2279 pxa_cleanup_debugfs(udc); 2459 pxa_cleanup_debugfs(udc);
2460 if (gpio_is_valid(gpio))
2461 gpio_free(gpio);
2462
2463 otg_put_transceiver(udc->transceiver);
2280 2464
2465 udc->transceiver = NULL;
2281 platform_set_drvdata(_dev, NULL); 2466 platform_set_drvdata(_dev, NULL);
2282 the_controller = NULL; 2467 the_controller = NULL;
2283 clk_put(udc->clk); 2468 clk_put(udc->clk);
2469 iounmap(udc->regs);
2284 2470
2285 return 0; 2471 return 0;
2286} 2472}
@@ -2319,6 +2505,8 @@ static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state)
2319 } 2505 }
2320 2506
2321 udc_disable(udc); 2507 udc_disable(udc);
2508 udc->pullup_resume = udc->pullup_on;
2509 dplus_pullup(udc, 0);
2322 2510
2323 return 0; 2511 return 0;
2324} 2512}
@@ -2346,7 +2534,9 @@ static int pxa_udc_resume(struct platform_device *_dev)
2346 ep->udccsr_value, ep->udccr_value); 2534 ep->udccsr_value, ep->udccr_value);
2347 } 2535 }
2348 2536
2349 udc_enable(udc); 2537 dplus_pullup(udc, udc->pullup_resume);
2538 if (should_enable_udc(udc))
2539 udc_enable(udc);
2350 /* 2540 /*
2351 * We do not handle OTG yet. 2541 * We do not handle OTG yet.
2352 * 2542 *
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
index 1d1b7936ee11..db58125331da 100644
--- a/drivers/usb/gadget/pxa27x_udc.h
+++ b/drivers/usb/gadget/pxa27x_udc.h
@@ -26,6 +26,7 @@
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/usb/otg.h>
29 30
30/* 31/*
31 * Register definitions 32 * Register definitions
@@ -421,10 +422,14 @@ struct udc_stats {
421 * @driver: bound gadget (zero, g_ether, g_file_storage, ...) 422 * @driver: bound gadget (zero, g_ether, g_file_storage, ...)
422 * @dev: device 423 * @dev: device
423 * @mach: machine info, used to activate specific GPIO 424 * @mach: machine info, used to activate specific GPIO
425 * @transceiver: external transceiver to handle vbus sense and D+ pullup
424 * @ep0state: control endpoint state machine state 426 * @ep0state: control endpoint state machine state
425 * @stats: statistics on udc usage 427 * @stats: statistics on udc usage
426 * @udc_usb_ep: array of usb endpoints offered by the gadget 428 * @udc_usb_ep: array of usb endpoints offered by the gadget
427 * @pxa_ep: array of pxa available endpoints 429 * @pxa_ep: array of pxa available endpoints
430 * @enabled: UDC was enabled by a previous udc_enable()
431 * @pullup_on: if pullup resistor connected to D+ pin
432 * @pullup_resume: if pullup resistor should be connected to D+ pin on resume
428 * @config: UDC active configuration 433 * @config: UDC active configuration
429 * @last_interface: UDC interface of the last SET_INTERFACE host request 434 * @last_interface: UDC interface of the last SET_INTERFACE host request
430 * @last_alternate: UDC altsetting of the last SET_INTERFACE host request 435 * @last_alternate: UDC altsetting of the last SET_INTERFACE host request
@@ -443,6 +448,7 @@ struct pxa_udc {
443 struct usb_gadget_driver *driver; 448 struct usb_gadget_driver *driver;
444 struct device *dev; 449 struct device *dev;
445 struct pxa2xx_udc_mach_info *mach; 450 struct pxa2xx_udc_mach_info *mach;
451 struct otg_transceiver *transceiver;
446 452
447 enum ep0_state ep0state; 453 enum ep0_state ep0state;
448 struct udc_stats stats; 454 struct udc_stats stats;
@@ -450,6 +456,10 @@ struct pxa_udc {
450 struct udc_usb_ep udc_usb_ep[NR_USB_ENDPOINTS]; 456 struct udc_usb_ep udc_usb_ep[NR_USB_ENDPOINTS];
451 struct pxa_ep pxa_ep[NR_PXA_ENDPOINTS]; 457 struct pxa_ep pxa_ep[NR_PXA_ENDPOINTS];
452 458
459 unsigned enabled:1;
460 unsigned pullup_on:1;
461 unsigned pullup_resume:1;
462 unsigned vbus_sensed:1;
453 unsigned config:2; 463 unsigned config:2;
454 unsigned last_interface:3; 464 unsigned last_interface:3;
455 unsigned last_alternate:3; 465 unsigned last_alternate:3;
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 8c26f5ea2b83..2b4660e08c4d 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -63,7 +63,7 @@ MODULE_PARM_DESC (rndis_debug, "enable debugging");
63static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS]; 63static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS];
64 64
65/* Driver Version */ 65/* Driver Version */
66static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1); 66static const __le32 rndis_driver_version = cpu_to_le32 (1);
67 67
68/* Function Prototypes */ 68/* Function Prototypes */
69static rndis_resp_t *rndis_add_response (int configNr, u32 length); 69static rndis_resp_t *rndis_add_response (int configNr, u32 length);
@@ -170,7 +170,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
170 int i, count; 170 int i, count;
171 rndis_query_cmplt_type *resp; 171 rndis_query_cmplt_type *resp;
172 struct net_device *net; 172 struct net_device *net;
173 struct net_device_stats *stats; 173 const struct net_device_stats *stats;
174 174
175 if (!r) return -ENOMEM; 175 if (!r) return -ENOMEM;
176 resp = (rndis_query_cmplt_type *) r->buf; 176 resp = (rndis_query_cmplt_type *) r->buf;
@@ -190,13 +190,10 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
190 190
191 /* response goes here, right after the header */ 191 /* response goes here, right after the header */
192 outbuf = (__le32 *) &resp[1]; 192 outbuf = (__le32 *) &resp[1];
193 resp->InformationBufferOffset = __constant_cpu_to_le32 (16); 193 resp->InformationBufferOffset = cpu_to_le32 (16);
194 194
195 net = rndis_per_dev_params[configNr].dev; 195 net = rndis_per_dev_params[configNr].dev;
196 if (net->get_stats) 196 stats = dev_get_stats(net);
197 stats = net->get_stats(net);
198 else
199 stats = NULL;
200 197
201 switch (OID) { 198 switch (OID) {
202 199
@@ -221,7 +218,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
221 * reddite ergo quae sunt Caesaris Caesari 218 * reddite ergo quae sunt Caesaris Caesari
222 * et quae sunt Dei Deo! 219 * et quae sunt Dei Deo!
223 */ 220 */
224 *outbuf = __constant_cpu_to_le32 (0); 221 *outbuf = cpu_to_le32 (0);
225 retval = 0; 222 retval = 0;
226 break; 223 break;
227 224
@@ -256,7 +253,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
256 pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__); 253 pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__);
257 if (rndis_per_dev_params [configNr].media_state 254 if (rndis_per_dev_params [configNr].media_state
258 == NDIS_MEDIA_STATE_DISCONNECTED) 255 == NDIS_MEDIA_STATE_DISCONNECTED)
259 *outbuf = __constant_cpu_to_le32 (0); 256 *outbuf = cpu_to_le32 (0);
260 else 257 else
261 *outbuf = cpu_to_le32 ( 258 *outbuf = cpu_to_le32 (
262 rndis_per_dev_params [configNr].speed); 259 rndis_per_dev_params [configNr].speed);
@@ -317,7 +314,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
317 /* mandatory */ 314 /* mandatory */
318 case OID_GEN_MAXIMUM_TOTAL_SIZE: 315 case OID_GEN_MAXIMUM_TOTAL_SIZE:
319 pr_debug("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__); 316 pr_debug("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
320 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); 317 *outbuf = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
321 retval = 0; 318 retval = 0;
322 break; 319 break;
323 320
@@ -332,7 +329,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
332 329
333 case OID_GEN_PHYSICAL_MEDIUM: 330 case OID_GEN_PHYSICAL_MEDIUM:
334 pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__); 331 pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__);
335 *outbuf = __constant_cpu_to_le32 (0); 332 *outbuf = cpu_to_le32 (0);
336 retval = 0; 333 retval = 0;
337 break; 334 break;
338 335
@@ -342,7 +339,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
342 */ 339 */
343 case OID_GEN_MAC_OPTIONS: /* from WinME */ 340 case OID_GEN_MAC_OPTIONS: /* from WinME */
344 pr_debug("%s: OID_GEN_MAC_OPTIONS\n", __func__); 341 pr_debug("%s: OID_GEN_MAC_OPTIONS\n", __func__);
345 *outbuf = __constant_cpu_to_le32( 342 *outbuf = cpu_to_le32(
346 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 343 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
347 | NDIS_MAC_OPTION_FULL_DUPLEX); 344 | NDIS_MAC_OPTION_FULL_DUPLEX);
348 retval = 0; 345 retval = 0;
@@ -431,7 +428,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
431 case OID_802_3_MULTICAST_LIST: 428 case OID_802_3_MULTICAST_LIST:
432 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); 429 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__);
433 /* Multicast base address only */ 430 /* Multicast base address only */
434 *outbuf = __constant_cpu_to_le32 (0xE0000000); 431 *outbuf = cpu_to_le32 (0xE0000000);
435 retval = 0; 432 retval = 0;
436 break; 433 break;
437 434
@@ -439,7 +436,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
439 case OID_802_3_MAXIMUM_LIST_SIZE: 436 case OID_802_3_MAXIMUM_LIST_SIZE:
440 pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); 437 pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
441 /* Multicast base address only */ 438 /* Multicast base address only */
442 *outbuf = __constant_cpu_to_le32 (1); 439 *outbuf = cpu_to_le32 (1);
443 retval = 0; 440 retval = 0;
444 break; 441 break;
445 442
@@ -461,14 +458,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
461 /* mandatory */ 458 /* mandatory */
462 case OID_802_3_XMIT_ONE_COLLISION: 459 case OID_802_3_XMIT_ONE_COLLISION:
463 pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__); 460 pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__);
464 *outbuf = __constant_cpu_to_le32 (0); 461 *outbuf = cpu_to_le32 (0);
465 retval = 0; 462 retval = 0;
466 break; 463 break;
467 464
468 /* mandatory */ 465 /* mandatory */
469 case OID_802_3_XMIT_MORE_COLLISIONS: 466 case OID_802_3_XMIT_MORE_COLLISIONS:
470 pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); 467 pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
471 *outbuf = __constant_cpu_to_le32 (0); 468 *outbuf = cpu_to_le32 (0);
472 retval = 0; 469 retval = 0;
473 break; 470 break;
474 471
@@ -572,24 +569,24 @@ static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
572 return -ENOMEM; 569 return -ENOMEM;
573 resp = (rndis_init_cmplt_type *) r->buf; 570 resp = (rndis_init_cmplt_type *) r->buf;
574 571
575 resp->MessageType = __constant_cpu_to_le32 ( 572 resp->MessageType = cpu_to_le32 (
576 REMOTE_NDIS_INITIALIZE_CMPLT); 573 REMOTE_NDIS_INITIALIZE_CMPLT);
577 resp->MessageLength = __constant_cpu_to_le32 (52); 574 resp->MessageLength = cpu_to_le32 (52);
578 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 575 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
579 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); 576 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS);
580 resp->MajorVersion = __constant_cpu_to_le32 (RNDIS_MAJOR_VERSION); 577 resp->MajorVersion = cpu_to_le32 (RNDIS_MAJOR_VERSION);
581 resp->MinorVersion = __constant_cpu_to_le32 (RNDIS_MINOR_VERSION); 578 resp->MinorVersion = cpu_to_le32 (RNDIS_MINOR_VERSION);
582 resp->DeviceFlags = __constant_cpu_to_le32 (RNDIS_DF_CONNECTIONLESS); 579 resp->DeviceFlags = cpu_to_le32 (RNDIS_DF_CONNECTIONLESS);
583 resp->Medium = __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3); 580 resp->Medium = cpu_to_le32 (RNDIS_MEDIUM_802_3);
584 resp->MaxPacketsPerTransfer = __constant_cpu_to_le32 (1); 581 resp->MaxPacketsPerTransfer = cpu_to_le32 (1);
585 resp->MaxTransferSize = cpu_to_le32 ( 582 resp->MaxTransferSize = cpu_to_le32 (
586 params->dev->mtu 583 params->dev->mtu
587 + sizeof (struct ethhdr) 584 + sizeof (struct ethhdr)
588 + sizeof (struct rndis_packet_msg_type) 585 + sizeof (struct rndis_packet_msg_type)
589 + 22); 586 + 22);
590 resp->PacketAlignmentFactor = __constant_cpu_to_le32 (0); 587 resp->PacketAlignmentFactor = cpu_to_le32 (0);
591 resp->AFListOffset = __constant_cpu_to_le32 (0); 588 resp->AFListOffset = cpu_to_le32 (0);
592 resp->AFListSize = __constant_cpu_to_le32 (0); 589 resp->AFListSize = cpu_to_le32 (0);
593 590
594 params->resp_avail(params->v); 591 params->resp_avail(params->v);
595 return 0; 592 return 0;
@@ -617,7 +614,7 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
617 return -ENOMEM; 614 return -ENOMEM;
618 resp = (rndis_query_cmplt_type *) r->buf; 615 resp = (rndis_query_cmplt_type *) r->buf;
619 616
620 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); 617 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT);
621 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 618 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
622 619
623 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), 620 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID),
@@ -626,13 +623,13 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
626 le32_to_cpu(buf->InformationBufferLength), 623 le32_to_cpu(buf->InformationBufferLength),
627 r)) { 624 r)) {
628 /* OID not supported */ 625 /* OID not supported */
629 resp->Status = __constant_cpu_to_le32 ( 626 resp->Status = cpu_to_le32 (
630 RNDIS_STATUS_NOT_SUPPORTED); 627 RNDIS_STATUS_NOT_SUPPORTED);
631 resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp); 628 resp->MessageLength = cpu_to_le32 (sizeof *resp);
632 resp->InformationBufferLength = __constant_cpu_to_le32 (0); 629 resp->InformationBufferLength = cpu_to_le32 (0);
633 resp->InformationBufferOffset = __constant_cpu_to_le32 (0); 630 resp->InformationBufferOffset = cpu_to_le32 (0);
634 } else 631 } else
635 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); 632 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS);
636 633
637 params->resp_avail(params->v); 634 params->resp_avail(params->v);
638 return 0; 635 return 0;
@@ -665,14 +662,14 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
665 pr_debug("\n"); 662 pr_debug("\n");
666#endif 663#endif
667 664
668 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT); 665 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_SET_CMPLT);
669 resp->MessageLength = __constant_cpu_to_le32 (16); 666 resp->MessageLength = cpu_to_le32 (16);
670 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 667 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
671 if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID), 668 if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID),
672 ((u8 *) buf) + 8 + BufOffset, BufLength, r)) 669 ((u8 *) buf) + 8 + BufOffset, BufLength, r))
673 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED); 670 resp->Status = cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED);
674 else 671 else
675 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); 672 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS);
676 673
677 params->resp_avail(params->v); 674 params->resp_avail(params->v);
678 return 0; 675 return 0;
@@ -689,11 +686,11 @@ static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
689 return -ENOMEM; 686 return -ENOMEM;
690 resp = (rndis_reset_cmplt_type *) r->buf; 687 resp = (rndis_reset_cmplt_type *) r->buf;
691 688
692 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); 689 resp->MessageType = cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT);
693 resp->MessageLength = __constant_cpu_to_le32 (16); 690 resp->MessageLength = cpu_to_le32 (16);
694 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); 691 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS);
695 /* resent information */ 692 /* resent information */
696 resp->AddressingReset = __constant_cpu_to_le32 (1); 693 resp->AddressingReset = cpu_to_le32 (1);
697 694
698 params->resp_avail(params->v); 695 params->resp_avail(params->v);
699 return 0; 696 return 0;
@@ -713,11 +710,11 @@ static int rndis_keepalive_response (int configNr,
713 return -ENOMEM; 710 return -ENOMEM;
714 resp = (rndis_keepalive_cmplt_type *) r->buf; 711 resp = (rndis_keepalive_cmplt_type *) r->buf;
715 712
716 resp->MessageType = __constant_cpu_to_le32 ( 713 resp->MessageType = cpu_to_le32 (
717 REMOTE_NDIS_KEEPALIVE_CMPLT); 714 REMOTE_NDIS_KEEPALIVE_CMPLT);
718 resp->MessageLength = __constant_cpu_to_le32 (16); 715 resp->MessageLength = cpu_to_le32 (16);
719 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 716 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
720 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); 717 resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS);
721 718
722 params->resp_avail(params->v); 719 params->resp_avail(params->v);
723 return 0; 720 return 0;
@@ -742,12 +739,12 @@ static int rndis_indicate_status_msg (int configNr, u32 status)
742 return -ENOMEM; 739 return -ENOMEM;
743 resp = (rndis_indicate_status_msg_type *) r->buf; 740 resp = (rndis_indicate_status_msg_type *) r->buf;
744 741
745 resp->MessageType = __constant_cpu_to_le32 ( 742 resp->MessageType = cpu_to_le32 (
746 REMOTE_NDIS_INDICATE_STATUS_MSG); 743 REMOTE_NDIS_INDICATE_STATUS_MSG);
747 resp->MessageLength = __constant_cpu_to_le32 (20); 744 resp->MessageLength = cpu_to_le32 (20);
748 resp->Status = cpu_to_le32 (status); 745 resp->Status = cpu_to_le32 (status);
749 resp->StatusBufferLength = __constant_cpu_to_le32 (0); 746 resp->StatusBufferLength = cpu_to_le32 (0);
750 resp->StatusBufferOffset = __constant_cpu_to_le32 (0); 747 resp->StatusBufferOffset = cpu_to_le32 (0);
751 748
752 params->resp_avail(params->v); 749 params->resp_avail(params->v);
753 return 0; 750 return 0;
@@ -963,9 +960,9 @@ void rndis_add_hdr (struct sk_buff *skb)
963 return; 960 return;
964 header = (void *) skb_push (skb, sizeof *header); 961 header = (void *) skb_push (skb, sizeof *header);
965 memset (header, 0, sizeof *header); 962 memset (header, 0, sizeof *header);
966 header->MessageType = __constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG); 963 header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG);
967 header->MessageLength = cpu_to_le32(skb->len); 964 header->MessageLength = cpu_to_le32(skb->len);
968 header->DataOffset = __constant_cpu_to_le32 (36); 965 header->DataOffset = cpu_to_le32 (36);
969 header->DataLength = cpu_to_le32(skb->len - sizeof *header); 966 header->DataLength = cpu_to_le32(skb->len - sizeof *header);
970} 967}
971 968
@@ -1029,7 +1026,7 @@ int rndis_rm_hdr(struct sk_buff *skb)
1029 __le32 *tmp = (void *) skb->data; 1026 __le32 *tmp = (void *) skb->data;
1030 1027
1031 /* MessageType, MessageLength */ 1028 /* MessageType, MessageLength */
1032 if (__constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG) 1029 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
1033 != get_unaligned(tmp++)) 1030 != get_unaligned(tmp++))
1034 return -EINVAL; 1031 return -EINVAL;
1035 tmp++; 1032 tmp++;
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 37879af1c433..f46a60962dab 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -87,12 +87,12 @@ static struct usb_gadget_strings *dev_strings[] = {
87static struct usb_device_descriptor device_desc = { 87static struct usb_device_descriptor device_desc = {
88 .bLength = USB_DT_DEVICE_SIZE, 88 .bLength = USB_DT_DEVICE_SIZE,
89 .bDescriptorType = USB_DT_DEVICE, 89 .bDescriptorType = USB_DT_DEVICE,
90 .bcdUSB = __constant_cpu_to_le16(0x0200), 90 .bcdUSB = cpu_to_le16(0x0200),
91 /* .bDeviceClass = f(use_acm) */ 91 /* .bDeviceClass = f(use_acm) */
92 .bDeviceSubClass = 0, 92 .bDeviceSubClass = 0,
93 .bDeviceProtocol = 0, 93 .bDeviceProtocol = 0,
94 /* .bMaxPacketSize0 = f(hardware) */ 94 /* .bMaxPacketSize0 = f(hardware) */
95 .idVendor = __constant_cpu_to_le16(GS_VENDOR_ID), 95 .idVendor = cpu_to_le16(GS_VENDOR_ID),
96 /* .idProduct = f(use_acm) */ 96 /* .idProduct = f(use_acm) */
97 /* .bcdDevice = f(hardware) */ 97 /* .bcdDevice = f(hardware) */
98 /* .iManufacturer = DYNAMIC */ 98 /* .iManufacturer = DYNAMIC */
@@ -216,7 +216,7 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
216 pr_warning("gs_bind: controller '%s' not recognized\n", 216 pr_warning("gs_bind: controller '%s' not recognized\n",
217 gadget->name); 217 gadget->name);
218 device_desc.bcdDevice = 218 device_desc.bcdDevice =
219 __constant_cpu_to_le16(GS_VERSION_NUM | 0x0099); 219 cpu_to_le16(GS_VERSION_NUM | 0x0099);
220 } 220 }
221 221
222 if (gadget_is_otg(cdev->gadget)) { 222 if (gadget_is_otg(cdev->gadget)) {
@@ -255,19 +255,19 @@ static int __init init(void)
255 serial_config_driver.bConfigurationValue = 2; 255 serial_config_driver.bConfigurationValue = 2;
256 device_desc.bDeviceClass = USB_CLASS_COMM; 256 device_desc.bDeviceClass = USB_CLASS_COMM;
257 device_desc.idProduct = 257 device_desc.idProduct =
258 __constant_cpu_to_le16(GS_CDC_PRODUCT_ID); 258 cpu_to_le16(GS_CDC_PRODUCT_ID);
259 } else if (use_obex) { 259 } else if (use_obex) {
260 serial_config_driver.label = "CDC OBEX config"; 260 serial_config_driver.label = "CDC OBEX config";
261 serial_config_driver.bConfigurationValue = 3; 261 serial_config_driver.bConfigurationValue = 3;
262 device_desc.bDeviceClass = USB_CLASS_COMM; 262 device_desc.bDeviceClass = USB_CLASS_COMM;
263 device_desc.idProduct = 263 device_desc.idProduct =
264 __constant_cpu_to_le16(GS_CDC_OBEX_PRODUCT_ID); 264 cpu_to_le16(GS_CDC_OBEX_PRODUCT_ID);
265 } else { 265 } else {
266 serial_config_driver.label = "Generic Serial config"; 266 serial_config_driver.label = "Generic Serial config";
267 serial_config_driver.bConfigurationValue = 1; 267 serial_config_driver.bConfigurationValue = 1;
268 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC; 268 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
269 device_desc.idProduct = 269 device_desc.idProduct =
270 __constant_cpu_to_le16(GS_PRODUCT_ID); 270 cpu_to_le16(GS_PRODUCT_ID);
271 } 271 }
272 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label; 272 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label;
273 273
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 53d59287f2bc..0a4d99ab40d8 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -1092,7 +1092,7 @@ int __init gserial_setup(struct usb_gadget *g, unsigned count)
1092 gs_tty_driver->init_termios.c_ispeed = 9600; 1092 gs_tty_driver->init_termios.c_ispeed = 9600;
1093 gs_tty_driver->init_termios.c_ospeed = 9600; 1093 gs_tty_driver->init_termios.c_ospeed = 9600;
1094 1094
1095 coding.dwDTERate = __constant_cpu_to_le32(9600); 1095 coding.dwDTERate = cpu_to_le32(9600);
1096 coding.bCharFormat = 8; 1096 coding.bCharFormat = 8;
1097 coding.bParityType = USB_CDC_NO_PARITY; 1097 coding.bParityType = USB_CDC_NO_PARITY;
1098 coding.bDataBits = USB_CDC_1_STOP_BITS; 1098 coding.bDataBits = USB_CDC_1_STOP_BITS;
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 361d9659ac48..2d772401b7ad 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -102,22 +102,32 @@ module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
102#ifndef CONFIG_USB_ZERO_HNPTEST 102#ifndef CONFIG_USB_ZERO_HNPTEST
103#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */ 103#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
104#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */ 104#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
105#define DEFAULT_AUTORESUME 0
105#else 106#else
106#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */ 107#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
107#define DRIVER_PRODUCT_NUM 0xbadd 108#define DRIVER_PRODUCT_NUM 0xbadd
109#define DEFAULT_AUTORESUME 5
108#endif 110#endif
109 111
112/* If the optional "autoresume" mode is enabled, it provides good
113 * functional coverage for the "USBCV" test harness from USB-IF.
114 * It's always set if OTG mode is enabled.
115 */
116unsigned autoresume = DEFAULT_AUTORESUME;
117module_param(autoresume, uint, S_IRUGO);
118MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup");
119
110/*-------------------------------------------------------------------------*/ 120/*-------------------------------------------------------------------------*/
111 121
112static struct usb_device_descriptor device_desc = { 122static struct usb_device_descriptor device_desc = {
113 .bLength = sizeof device_desc, 123 .bLength = sizeof device_desc,
114 .bDescriptorType = USB_DT_DEVICE, 124 .bDescriptorType = USB_DT_DEVICE,
115 125
116 .bcdUSB = __constant_cpu_to_le16(0x0200), 126 .bcdUSB = cpu_to_le16(0x0200),
117 .bDeviceClass = USB_CLASS_VENDOR_SPEC, 127 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
118 128
119 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM), 129 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
120 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM), 130 .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
121 .bNumConfigurations = 2, 131 .bNumConfigurations = 2,
122}; 132};
123 133
@@ -212,6 +222,47 @@ void disable_endpoints(struct usb_composite_dev *cdev,
212 222
213/*-------------------------------------------------------------------------*/ 223/*-------------------------------------------------------------------------*/
214 224
225static struct timer_list autoresume_timer;
226
227static void zero_autoresume(unsigned long _c)
228{
229 struct usb_composite_dev *cdev = (void *)_c;
230 struct usb_gadget *g = cdev->gadget;
231
232 /* unconfigured devices can't issue wakeups */
233 if (!cdev->config)
234 return;
235
236 /* Normally the host would be woken up for something
237 * more significant than just a timer firing; likely
238 * because of some direct user request.
239 */
240 if (g->speed != USB_SPEED_UNKNOWN) {
241 int status = usb_gadget_wakeup(g);
242 INFO(cdev, "%s --> %d\n", __func__, status);
243 }
244}
245
246static void zero_suspend(struct usb_composite_dev *cdev)
247{
248 if (cdev->gadget->speed == USB_SPEED_UNKNOWN)
249 return;
250
251 if (autoresume) {
252 mod_timer(&autoresume_timer, jiffies + (HZ * autoresume));
253 DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume);
254 } else
255 DBG(cdev, "%s\n", __func__);
256}
257
258static void zero_resume(struct usb_composite_dev *cdev)
259{
260 DBG(cdev, "%s\n", __func__);
261 del_timer(&autoresume_timer);
262}
263
264/*-------------------------------------------------------------------------*/
265
215static int __init zero_bind(struct usb_composite_dev *cdev) 266static int __init zero_bind(struct usb_composite_dev *cdev)
216{ 267{
217 int gcnum; 268 int gcnum;
@@ -239,17 +290,19 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
239 strings_dev[STRING_SERIAL_IDX].id = id; 290 strings_dev[STRING_SERIAL_IDX].id = id;
240 device_desc.iSerialNumber = id; 291 device_desc.iSerialNumber = id;
241 292
293 setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
294
242 /* Register primary, then secondary configuration. Note that 295 /* Register primary, then secondary configuration. Note that
243 * SH3 only allows one config... 296 * SH3 only allows one config...
244 */ 297 */
245 if (loopdefault) { 298 if (loopdefault) {
246 loopback_add(cdev); 299 loopback_add(cdev, autoresume != 0);
247 if (!gadget_is_sh(gadget)) 300 if (!gadget_is_sh(gadget))
248 sourcesink_add(cdev); 301 sourcesink_add(cdev, autoresume != 0);
249 } else { 302 } else {
250 sourcesink_add(cdev); 303 sourcesink_add(cdev, autoresume != 0);
251 if (!gadget_is_sh(gadget)) 304 if (!gadget_is_sh(gadget))
252 loopback_add(cdev); 305 loopback_add(cdev, autoresume != 0);
253 } 306 }
254 307
255 gcnum = usb_gadget_controller_number(gadget); 308 gcnum = usb_gadget_controller_number(gadget);
@@ -265,7 +318,7 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
265 */ 318 */
266 pr_warning("%s: controller '%s' not recognized\n", 319 pr_warning("%s: controller '%s' not recognized\n",
267 longname, gadget->name); 320 longname, gadget->name);
268 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); 321 device_desc.bcdDevice = cpu_to_le16(0x9999);
269 } 322 }
270 323
271 324
@@ -278,11 +331,20 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
278 return 0; 331 return 0;
279} 332}
280 333
334static int zero_unbind(struct usb_composite_dev *cdev)
335{
336 del_timer_sync(&autoresume_timer);
337 return 0;
338}
339
281static struct usb_composite_driver zero_driver = { 340static struct usb_composite_driver zero_driver = {
282 .name = "zero", 341 .name = "zero",
283 .dev = &device_desc, 342 .dev = &device_desc,
284 .strings = dev_strings, 343 .strings = dev_strings,
285 .bind = zero_bind, 344 .bind = zero_bind,
345 .unbind = zero_unbind,
346 .suspend = zero_suspend,
347 .resume = zero_resume,
286}; 348};
287 349
288MODULE_AUTHOR("David Brownell"); 350MODULE_AUTHOR("David Brownell");