aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/Kconfig42
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/amd5536udc.c30
-rw-r--r--drivers/usb/gadget/at91_udc.c25
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c206
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.h9
-rw-r--r--drivers/usb/gadget/dummy_hcd.c101
-rw-r--r--drivers/usb/gadget/epautoconf.c12
-rw-r--r--drivers/usb/gadget/ether.c26
-rw-r--r--drivers/usb/gadget/file_storage.c61
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c7
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.h2
-rw-r--r--drivers/usb/gadget/gmidi.c8
-rw-r--r--drivers/usb/gadget/goku_udc.c22
-rw-r--r--drivers/usb/gadget/inode.c18
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c133
-rw-r--r--drivers/usb/gadget/m66592-udc.c2
-rw-r--r--drivers/usb/gadget/m66592-udc.h4
-rw-r--r--drivers/usb/gadget/net2280.h2
-rw-r--r--drivers/usb/gadget/omap_udc.c539
-rw-r--r--drivers/usb/gadget/omap_udc.h61
-rw-r--r--drivers/usb/gadget/printer.c92
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c2404
-rw-r--r--drivers/usb/gadget/pxa27x_udc.h495
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c28
-rw-r--r--drivers/usb/gadget/rndis.c188
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c2
-rw-r--r--drivers/usb/gadget/serial.c803
-rw-r--r--drivers/usb/gadget/usbstring.c2
-rw-r--r--drivers/usb/gadget/zero.c370
30 files changed, 4307 insertions, 1388 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 6f45dd669b33..3565d4352826 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -44,8 +44,8 @@ menuconfig USB_GADGET
44if USB_GADGET 44if USB_GADGET
45 45
46config USB_GADGET_DEBUG 46config USB_GADGET_DEBUG
47 boolean "Debugging messages" 47 boolean "Debugging messages (DEVELOPMENT)"
48 depends on USB_GADGET && DEBUG_KERNEL && EXPERIMENTAL 48 depends on USB_GADGET && DEBUG_KERNEL
49 help 49 help
50 Many controller and gadget drivers will print some debugging 50 Many controller and gadget drivers will print some debugging
51 messages if you use this option to ask for those messages. 51 messages if you use this option to ask for those messages.
@@ -58,7 +58,7 @@ config USB_GADGET_DEBUG
58 production build. 58 production build.
59 59
60config USB_GADGET_DEBUG_FILES 60config USB_GADGET_DEBUG_FILES
61 boolean "Debugging information files" 61 boolean "Debugging information files (DEVELOPMENT)"
62 depends on USB_GADGET && PROC_FS 62 depends on USB_GADGET && PROC_FS
63 help 63 help
64 Some of the drivers in the "gadget" framework can expose 64 Some of the drivers in the "gadget" framework can expose
@@ -69,7 +69,7 @@ config USB_GADGET_DEBUG_FILES
69 here. If in doubt, or to conserve kernel memory, say "N". 69 here. If in doubt, or to conserve kernel memory, say "N".
70 70
71config USB_GADGET_DEBUG_FS 71config USB_GADGET_DEBUG_FS
72 boolean "Debugging information files in debugfs" 72 boolean "Debugging information files in debugfs (DEVELOPMENT)"
73 depends on USB_GADGET && DEBUG_FS 73 depends on USB_GADGET && DEBUG_FS
74 help 74 help
75 Some of the drivers in the "gadget" framework can expose 75 Some of the drivers in the "gadget" framework can expose
@@ -118,10 +118,10 @@ config USB_AMD5536UDC
118config USB_GADGET_ATMEL_USBA 118config USB_GADGET_ATMEL_USBA
119 boolean "Atmel USBA" 119 boolean "Atmel USBA"
120 select USB_GADGET_DUALSPEED 120 select USB_GADGET_DUALSPEED
121 depends on AVR32 121 depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL
122 help 122 help
123 USBA is the integrated high-speed USB Device controller on 123 USBA is the integrated high-speed USB Device controller on
124 the AT32AP700x processors from Atmel. 124 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
125 125
126config USB_ATMEL_USBA 126config USB_ATMEL_USBA
127 tristate 127 tristate
@@ -231,6 +231,26 @@ config SUPERH_BUILT_IN_M66592
231 However, this problem is improved if change a value of 231 However, this problem is improved if change a value of
232 NET_IP_ALIGN to 4. 232 NET_IP_ALIGN to 4.
233 233
234config USB_GADGET_PXA27X
235 boolean "PXA 27x"
236 depends on ARCH_PXA && PXA27x
237 help
238 Intel's PXA 27x series XScale ARM v5TE processors include
239 an integrated full speed USB 1.1 device controller.
240
241 It has up to 23 endpoints, as well as endpoint zero (for
242 control transfers).
243
244 Say "y" to link the driver statically, or "m" to build a
245 dynamically linked module called "pxa27x_udc" and force all
246 gadget drivers to also be dynamically linked.
247
248config USB_PXA27X
249 tristate
250 depends on USB_GADGET_PXA27X
251 default USB_GADGET
252 select USB_GADGET_SELECTED
253
234config USB_GADGET_GOKU 254config USB_GADGET_GOKU
235 boolean "Toshiba TC86C001 'Goku-S'" 255 boolean "Toshiba TC86C001 'Goku-S'"
236 depends on PCI 256 depends on PCI
@@ -337,7 +357,7 @@ config USB_AT91
337 357
338config USB_GADGET_DUMMY_HCD 358config USB_GADGET_DUMMY_HCD
339 boolean "Dummy HCD (DEVELOPMENT)" 359 boolean "Dummy HCD (DEVELOPMENT)"
340 depends on (USB=y || (USB=m && USB_GADGET=m)) && EXPERIMENTAL 360 depends on USB=y || (USB=m && USB_GADGET=m)
341 select USB_GADGET_DUALSPEED 361 select USB_GADGET_DUALSPEED
342 help 362 help
343 This host controller driver emulates USB, looping all data transfer 363 This host controller driver emulates USB, looping all data transfer
@@ -404,7 +424,6 @@ choice
404 424
405config USB_ZERO 425config USB_ZERO
406 tristate "Gadget Zero (DEVELOPMENT)" 426 tristate "Gadget Zero (DEVELOPMENT)"
407 depends on EXPERIMENTAL
408 help 427 help
409 Gadget Zero is a two-configuration device. It either sinks and 428 Gadget Zero is a two-configuration device. It either sinks and
410 sources bulk data; or it loops back a configurable number of 429 sources bulk data; or it loops back a configurable number of
@@ -468,8 +487,8 @@ config USB_ETH
468 dynamically linked module called "g_ether". 487 dynamically linked module called "g_ether".
469 488
470config USB_ETH_RNDIS 489config USB_ETH_RNDIS
471 bool "RNDIS support (EXPERIMENTAL)" 490 bool "RNDIS support"
472 depends on USB_ETH && EXPERIMENTAL 491 depends on USB_ETH
473 default y 492 default y
474 help 493 help
475 Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, 494 Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
@@ -495,6 +514,9 @@ config USB_GADGETFS
495 All endpoints, transfer speeds, and transfer types supported by 514 All endpoints, transfer speeds, and transfer types supported by
496 the hardware are available, through read() and write() calls. 515 the hardware are available, through read() and write() calls.
497 516
517 Currently, this option is still labelled as EXPERIMENTAL because
518 of existing race conditions in the underlying in-kernel AIO core.
519
498 Say "y" to link the driver statically, or "m" to build a 520 Say "y" to link the driver statically, or "m" to build a
499 dynamically linked module called "gadgetfs". 521 dynamically linked module called "gadgetfs".
500 522
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index c3aab80b6c76..12357255d740 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
9obj-$(CONFIG_USB_NET2280) += net2280.o 9obj-$(CONFIG_USB_NET2280) += net2280.o
10obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o 10obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o
11obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o 11obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o
12obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o
12obj-$(CONFIG_USB_GOKU) += goku_udc.o 13obj-$(CONFIG_USB_GOKU) += goku_udc.o
13obj-$(CONFIG_USB_OMAP) += omap_udc.o 14obj-$(CONFIG_USB_OMAP) += omap_udc.o
14obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o 15obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index b663f23f2642..f261d2a9a5f0 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -328,6 +328,7 @@ udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc)
328 u32 tmp; 328 u32 tmp;
329 unsigned long iflags; 329 unsigned long iflags;
330 u8 udc_csr_epix; 330 u8 udc_csr_epix;
331 unsigned maxpacket;
331 332
332 if (!usbep 333 if (!usbep
333 || usbep->name == ep0_string 334 || usbep->name == ep0_string
@@ -354,9 +355,10 @@ udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc)
354 writel(tmp, &dev->ep[ep->num].regs->ctl); 355 writel(tmp, &dev->ep[ep->num].regs->ctl);
355 356
356 /* set max packet size */ 357 /* set max packet size */
358 maxpacket = le16_to_cpu(desc->wMaxPacketSize);
357 tmp = readl(&dev->ep[ep->num].regs->bufout_maxpkt); 359 tmp = readl(&dev->ep[ep->num].regs->bufout_maxpkt);
358 tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize, UDC_EP_MAX_PKT_SIZE); 360 tmp = AMD_ADDBITS(tmp, maxpacket, UDC_EP_MAX_PKT_SIZE);
359 ep->ep.maxpacket = desc->wMaxPacketSize; 361 ep->ep.maxpacket = maxpacket;
360 writel(tmp, &dev->ep[ep->num].regs->bufout_maxpkt); 362 writel(tmp, &dev->ep[ep->num].regs->bufout_maxpkt);
361 363
362 /* IN ep */ 364 /* IN ep */
@@ -370,8 +372,8 @@ udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc)
370 /* double buffering: fifo size = 2 x max packet size */ 372 /* double buffering: fifo size = 2 x max packet size */
371 tmp = AMD_ADDBITS( 373 tmp = AMD_ADDBITS(
372 tmp, 374 tmp,
373 desc->wMaxPacketSize * UDC_EPIN_BUFF_SIZE_MULT 375 maxpacket * UDC_EPIN_BUFF_SIZE_MULT
374 / UDC_DWORD_BYTES, 376 / UDC_DWORD_BYTES,
375 UDC_EPIN_BUFF_SIZE); 377 UDC_EPIN_BUFF_SIZE);
376 writel(tmp, &dev->ep[ep->num].regs->bufin_framenum); 378 writel(tmp, &dev->ep[ep->num].regs->bufin_framenum);
377 379
@@ -390,7 +392,7 @@ udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc)
390 392
391 /* set max packet size UDC CSR */ 393 /* set max packet size UDC CSR */
392 tmp = readl(&dev->csr->ne[ep->num - UDC_CSR_EP_OUT_IX_OFS]); 394 tmp = readl(&dev->csr->ne[ep->num - UDC_CSR_EP_OUT_IX_OFS]);
393 tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize, 395 tmp = AMD_ADDBITS(tmp, maxpacket,
394 UDC_CSR_NE_MAX_PKT); 396 UDC_CSR_NE_MAX_PKT);
395 writel(tmp, &dev->csr->ne[ep->num - UDC_CSR_EP_OUT_IX_OFS]); 397 writel(tmp, &dev->csr->ne[ep->num - UDC_CSR_EP_OUT_IX_OFS]);
396 398
@@ -407,7 +409,7 @@ udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc)
407 /* set ep values */ 409 /* set ep values */
408 tmp = readl(&dev->csr->ne[udc_csr_epix]); 410 tmp = readl(&dev->csr->ne[udc_csr_epix]);
409 /* max packet */ 411 /* max packet */
410 tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize, UDC_CSR_NE_MAX_PKT); 412 tmp = AMD_ADDBITS(tmp, maxpacket, UDC_CSR_NE_MAX_PKT);
411 /* ep number */ 413 /* ep number */
412 tmp = AMD_ADDBITS(tmp, desc->bEndpointAddress, UDC_CSR_NE_NUM); 414 tmp = AMD_ADDBITS(tmp, desc->bEndpointAddress, UDC_CSR_NE_NUM);
413 /* ep direction */ 415 /* ep direction */
@@ -2832,7 +2834,7 @@ __acquires(dev->lock)
2832 /* make usb request for gadget driver */ 2834 /* make usb request for gadget driver */
2833 memset(&setup_data, 0 , sizeof(union udc_setup_data)); 2835 memset(&setup_data, 0 , sizeof(union udc_setup_data));
2834 setup_data.request.bRequest = USB_REQ_SET_CONFIGURATION; 2836 setup_data.request.bRequest = USB_REQ_SET_CONFIGURATION;
2835 setup_data.request.wValue = dev->cur_config; 2837 setup_data.request.wValue = cpu_to_le16(dev->cur_config);
2836 2838
2837 /* programm the NE registers */ 2839 /* programm the NE registers */
2838 for (i = 0; i < UDC_EP_NUM; i++) { 2840 for (i = 0; i < UDC_EP_NUM; i++) {
@@ -2881,8 +2883,8 @@ __acquires(dev->lock)
2881 memset(&setup_data, 0 , sizeof(union udc_setup_data)); 2883 memset(&setup_data, 0 , sizeof(union udc_setup_data));
2882 setup_data.request.bRequest = USB_REQ_SET_INTERFACE; 2884 setup_data.request.bRequest = USB_REQ_SET_INTERFACE;
2883 setup_data.request.bRequestType = USB_RECIP_INTERFACE; 2885 setup_data.request.bRequestType = USB_RECIP_INTERFACE;
2884 setup_data.request.wValue = dev->cur_alt; 2886 setup_data.request.wValue = cpu_to_le16(dev->cur_alt);
2885 setup_data.request.wIndex = dev->cur_intf; 2887 setup_data.request.wIndex = cpu_to_le16(dev->cur_intf);
2886 2888
2887 DBG(dev, "SET_INTERFACE interrupt: alt=%d intf=%d\n", 2889 DBG(dev, "SET_INTERFACE interrupt: alt=%d intf=%d\n",
2888 dev->cur_alt, dev->cur_intf); 2890 dev->cur_alt, dev->cur_intf);
@@ -3248,6 +3250,8 @@ static int udc_pci_probe(
3248 3250
3249 /* pci setup */ 3251 /* pci setup */
3250 if (pci_enable_device(pdev) < 0) { 3252 if (pci_enable_device(pdev) < 0) {
3253 kfree(dev);
3254 dev = NULL;
3251 retval = -ENODEV; 3255 retval = -ENODEV;
3252 goto finished; 3256 goto finished;
3253 } 3257 }
@@ -3259,6 +3263,8 @@ static int udc_pci_probe(
3259 3263
3260 if (!request_mem_region(resource, len, name)) { 3264 if (!request_mem_region(resource, len, name)) {
3261 dev_dbg(&pdev->dev, "pci device used already\n"); 3265 dev_dbg(&pdev->dev, "pci device used already\n");
3266 kfree(dev);
3267 dev = NULL;
3262 retval = -EBUSY; 3268 retval = -EBUSY;
3263 goto finished; 3269 goto finished;
3264 } 3270 }
@@ -3267,18 +3273,24 @@ static int udc_pci_probe(
3267 dev->virt_addr = ioremap_nocache(resource, len); 3273 dev->virt_addr = ioremap_nocache(resource, len);
3268 if (dev->virt_addr == NULL) { 3274 if (dev->virt_addr == NULL) {
3269 dev_dbg(&pdev->dev, "start address cannot be mapped\n"); 3275 dev_dbg(&pdev->dev, "start address cannot be mapped\n");
3276 kfree(dev);
3277 dev = NULL;
3270 retval = -EFAULT; 3278 retval = -EFAULT;
3271 goto finished; 3279 goto finished;
3272 } 3280 }
3273 3281
3274 if (!pdev->irq) { 3282 if (!pdev->irq) {
3275 dev_err(&dev->pdev->dev, "irq not set\n"); 3283 dev_err(&dev->pdev->dev, "irq not set\n");
3284 kfree(dev);
3285 dev = NULL;
3276 retval = -ENODEV; 3286 retval = -ENODEV;
3277 goto finished; 3287 goto finished;
3278 } 3288 }
3279 3289
3280 if (request_irq(pdev->irq, udc_irq, IRQF_SHARED, name, dev) != 0) { 3290 if (request_irq(pdev->irq, udc_irq, IRQF_SHARED, name, dev) != 0) {
3281 dev_dbg(&dev->pdev->dev, "request_irq(%d) fail\n", pdev->irq); 3291 dev_dbg(&dev->pdev->dev, "request_irq(%d) fail\n", pdev->irq);
3292 kfree(dev);
3293 dev = NULL;
3282 retval = -EBUSY; 3294 retval = -EBUSY;
3283 goto finished; 3295 goto finished;
3284 } 3296 }
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index a83e8b798ec9..b6b2a0a5ba37 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -231,6 +231,7 @@ static int proc_udc_open(struct inode *inode, struct file *file)
231} 231}
232 232
233static const struct file_operations proc_ops = { 233static const struct file_operations proc_ops = {
234 .owner = THIS_MODULE,
234 .open = proc_udc_open, 235 .open = proc_udc_open,
235 .read = seq_read, 236 .read = seq_read,
236 .llseek = seq_lseek, 237 .llseek = seq_lseek,
@@ -239,15 +240,7 @@ static const struct file_operations proc_ops = {
239 240
240static void create_debug_file(struct at91_udc *udc) 241static void create_debug_file(struct at91_udc *udc)
241{ 242{
242 struct proc_dir_entry *pde; 243 udc->pde = proc_create_data(debug_filename, 0, NULL, &proc_ops, udc);
243
244 pde = create_proc_entry (debug_filename, 0, NULL);
245 udc->pde = pde;
246 if (pde == NULL)
247 return;
248
249 pde->proc_fops = &proc_ops;
250 pde->data = udc;
251} 244}
252 245
253static void remove_debug_file(struct at91_udc *udc) 246static void remove_debug_file(struct at91_udc *udc)
@@ -389,6 +382,7 @@ static int write_fifo(struct at91_ep *ep, struct at91_request *req)
389 u32 csr = __raw_readl(creg); 382 u32 csr = __raw_readl(creg);
390 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0)); 383 u8 __iomem *dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0));
391 unsigned total, count, is_last; 384 unsigned total, count, is_last;
385 u8 *buf;
392 386
393 /* 387 /*
394 * TODO: allow for writing two packets to the fifo ... that'll 388 * TODO: allow for writing two packets to the fifo ... that'll
@@ -413,6 +407,8 @@ static int write_fifo(struct at91_ep *ep, struct at91_request *req)
413 return 0; 407 return 0;
414 } 408 }
415 409
410 buf = req->req.buf + req->req.actual;
411 prefetch(buf);
416 total = req->req.length - req->req.actual; 412 total = req->req.length - req->req.actual;
417 if (ep->ep.maxpacket < total) { 413 if (ep->ep.maxpacket < total) {
418 count = ep->ep.maxpacket; 414 count = ep->ep.maxpacket;
@@ -435,7 +431,7 @@ static int write_fifo(struct at91_ep *ep, struct at91_request *req)
435 * recover when the actual bytecount matters (e.g. for USB Test 431 * recover when the actual bytecount matters (e.g. for USB Test
436 * and Measurement Class devices). 432 * and Measurement Class devices).
437 */ 433 */
438 __raw_writesb(dreg, req->req.buf + req->req.actual, count); 434 __raw_writesb(dreg, buf, count);
439 csr &= ~SET_FX; 435 csr &= ~SET_FX;
440 csr |= CLR_FX | AT91_UDP_TXPKTRDY; 436 csr |= CLR_FX | AT91_UDP_TXPKTRDY;
441 __raw_writel(csr, creg); 437 __raw_writel(csr, creg);
@@ -457,7 +453,7 @@ static void nuke(struct at91_ep *ep, int status)
457 if (list_empty(&ep->queue)) 453 if (list_empty(&ep->queue))
458 return; 454 return;
459 455
460 VDBG("%s %s\n", __FUNCTION__, ep->ep.name); 456 VDBG("%s %s\n", __func__, ep->ep.name);
461 while (!list_empty(&ep->queue)) { 457 while (!list_empty(&ep->queue)) {
462 req = list_entry(ep->queue.next, struct at91_request, queue); 458 req = list_entry(ep->queue.next, struct at91_request, queue);
463 done(ep, req, status); 459 done(ep, req, status);
@@ -792,7 +788,7 @@ static int at91_wakeup(struct usb_gadget *gadget)
792 int status = -EINVAL; 788 int status = -EINVAL;
793 unsigned long flags; 789 unsigned long flags;
794 790
795 DBG("%s\n", __FUNCTION__ ); 791 DBG("%s\n", __func__ );
796 local_irq_save(flags); 792 local_irq_save(flags);
797 793
798 if (!udc->clocked || !udc->suspended) 794 if (!udc->clocked || !udc->suspended)
@@ -892,7 +888,7 @@ static void pullup(struct at91_udc *udc, int is_on)
892 at91_udp_write(udc, AT91_UDP_TXVC, 0); 888 at91_udp_write(udc, AT91_UDP_TXVC, 0);
893 if (cpu_is_at91rm9200()) 889 if (cpu_is_at91rm9200())
894 gpio_set_value(udc->board.pullup_pin, active); 890 gpio_set_value(udc->board.pullup_pin, active);
895 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) { 891 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) {
896 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); 892 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
897 893
898 txvc |= AT91_UDP_TXVC_PUON; 894 txvc |= AT91_UDP_TXVC_PUON;
@@ -910,7 +906,7 @@ static void pullup(struct at91_udc *udc, int is_on)
910 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 906 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
911 if (cpu_is_at91rm9200()) 907 if (cpu_is_at91rm9200())
912 gpio_set_value(udc->board.pullup_pin, !active); 908 gpio_set_value(udc->board.pullup_pin, !active);
913 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) { 909 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) {
914 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); 910 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
915 911
916 txvc &= ~AT91_UDP_TXVC_PUON; 912 txvc &= ~AT91_UDP_TXVC_PUON;
@@ -1884,3 +1880,4 @@ module_exit(udc_exit_module);
1884MODULE_DESCRIPTION("AT91 udc driver"); 1880MODULE_DESCRIPTION("AT91 udc driver");
1885MODULE_AUTHOR("Thomas Rathbone, David Brownell"); 1881MODULE_AUTHOR("Thomas Rathbone, David Brownell");
1886MODULE_LICENSE("GPL"); 1882MODULE_LICENSE("GPL");
1883MODULE_ALIAS("platform:at91_udc");
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index af8b2a3a2d4a..07e5a0b5dcda 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -18,6 +18,7 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/usb/ch9.h> 19#include <linux/usb/ch9.h>
20#include <linux/usb/gadget.h> 20#include <linux/usb/gadget.h>
21#include <linux/usb/atmel_usba_udc.h>
21#include <linux/delay.h> 22#include <linux/delay.h>
22 23
23#include <asm/gpio.h> 24#include <asm/gpio.h>
@@ -27,6 +28,7 @@
27 28
28 29
29static struct usba_udc the_udc; 30static struct usba_udc the_udc;
31static struct usba_ep *usba_ep;
30 32
31#ifdef CONFIG_USB_GADGET_DEBUG_FS 33#ifdef CONFIG_USB_GADGET_DEBUG_FS
32#include <linux/debugfs.h> 34#include <linux/debugfs.h>
@@ -324,53 +326,28 @@ static int vbus_is_present(struct usba_udc *udc)
324 return 1; 326 return 1;
325} 327}
326 328
327static void copy_to_fifo(void __iomem *fifo, const void *buf, int len) 329#if defined(CONFIG_AVR32)
330
331static void toggle_bias(int is_on)
328{ 332{
329 unsigned long tmp;
330
331 DBG(DBG_FIFO, "copy to FIFO (len %d):\n", len);
332 for (; len > 0; len -= 4, buf += 4, fifo += 4) {
333 tmp = *(unsigned long *)buf;
334 if (len >= 4) {
335 DBG(DBG_FIFO, " -> %08lx\n", tmp);
336 __raw_writel(tmp, fifo);
337 } else {
338 do {
339 DBG(DBG_FIFO, " -> %02lx\n", tmp >> 24);
340 __raw_writeb(tmp >> 24, fifo);
341 fifo++;
342 tmp <<= 8;
343 } while (--len);
344 break;
345 }
346 }
347} 333}
348 334
349static void copy_from_fifo(void *buf, void __iomem *fifo, int len) 335#elif defined(CONFIG_ARCH_AT91)
336
337#include <asm/arch/at91_pmc.h>
338
339static void toggle_bias(int is_on)
350{ 340{
351 union { 341 unsigned int uckr = at91_sys_read(AT91_CKGR_UCKR);
352 unsigned long *w; 342
353 unsigned char *b; 343 if (is_on)
354 } p; 344 at91_sys_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
355 unsigned long tmp; 345 else
356 346 at91_sys_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
357 DBG(DBG_FIFO, "copy from FIFO (len %d):\n", len);
358 for (p.w = buf; len > 0; len -= 4, p.w++, fifo += 4) {
359 if (len >= 4) {
360 tmp = __raw_readl(fifo);
361 *p.w = tmp;
362 DBG(DBG_FIFO, " -> %08lx\n", tmp);
363 } else {
364 do {
365 tmp = __raw_readb(fifo);
366 *p.b = tmp;
367 DBG(DBG_FIFO, " -> %02lx\n", tmp);
368 fifo++, p.b++;
369 } while (--len);
370 }
371 }
372} 347}
373 348
349#endif /* CONFIG_ARCH_AT91 */
350
374static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req) 351static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
375{ 352{
376 unsigned int transaction_len; 353 unsigned int transaction_len;
@@ -387,7 +364,7 @@ static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
387 ep->ep.name, req, transaction_len, 364 ep->ep.name, req, transaction_len,
388 req->last_transaction ? ", done" : ""); 365 req->last_transaction ? ", done" : "");
389 366
390 copy_to_fifo(ep->fifo, req->req.buf + req->req.actual, transaction_len); 367 memcpy_toio(ep->fifo, req->req.buf + req->req.actual, transaction_len);
391 usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY); 368 usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
392 req->req.actual += transaction_len; 369 req->req.actual += transaction_len;
393} 370}
@@ -476,7 +453,7 @@ static void receive_data(struct usba_ep *ep)
476 bytecount = req->req.length - req->req.actual; 453 bytecount = req->req.length - req->req.actual;
477 } 454 }
478 455
479 copy_from_fifo(req->req.buf + req->req.actual, 456 memcpy_fromio(req->req.buf + req->req.actual,
480 ep->fifo, bytecount); 457 ep->fifo, bytecount);
481 req->req.actual += bytecount; 458 req->req.actual += bytecount;
482 459
@@ -672,7 +649,13 @@ static int usba_ep_disable(struct usb_ep *_ep)
672 649
673 if (!ep->desc) { 650 if (!ep->desc) {
674 spin_unlock_irqrestore(&udc->lock, flags); 651 spin_unlock_irqrestore(&udc->lock, flags);
675 DBG(DBG_ERR, "ep_disable: %s not enabled\n", ep->ep.name); 652 /* REVISIT because this driver disables endpoints in
653 * reset_all_endpoints() before calling disconnect(),
654 * most gadget drivers would trigger this non-error ...
655 */
656 if (udc->gadget.speed != USB_SPEED_UNKNOWN)
657 DBG(DBG_ERR, "ep_disable: %s not enabled\n",
658 ep->ep.name);
676 return -EINVAL; 659 return -EINVAL;
677 } 660 }
678 ep->desc = NULL; 661 ep->desc = NULL;
@@ -1029,33 +1012,6 @@ static const struct usb_gadget_ops usba_udc_ops = {
1029 .set_selfpowered = usba_udc_set_selfpowered, 1012 .set_selfpowered = usba_udc_set_selfpowered,
1030}; 1013};
1031 1014
1032#define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
1033{ \
1034 .ep = { \
1035 .ops = &usba_ep_ops, \
1036 .name = nam, \
1037 .maxpacket = maxpkt, \
1038 }, \
1039 .udc = &the_udc, \
1040 .queue = LIST_HEAD_INIT(usba_ep[idx].queue), \
1041 .fifo_size = maxpkt, \
1042 .nr_banks = maxbk, \
1043 .index = idx, \
1044 .can_dma = dma, \
1045 .can_isoc = isoc, \
1046}
1047
1048static struct usba_ep usba_ep[] = {
1049 EP("ep0", 0, 64, 1, 0, 0),
1050 EP("ep1in-bulk", 1, 512, 2, 1, 1),
1051 EP("ep2out-bulk", 2, 512, 2, 1, 1),
1052 EP("ep3in-int", 3, 64, 3, 1, 0),
1053 EP("ep4out-int", 4, 64, 3, 1, 0),
1054 EP("ep5in-iso", 5, 1024, 3, 1, 1),
1055 EP("ep6out-iso", 6, 1024, 3, 1, 1),
1056};
1057#undef EP
1058
1059static struct usb_endpoint_descriptor usba_ep0_desc = { 1015static struct usb_endpoint_descriptor usba_ep0_desc = {
1060 .bLength = USB_DT_ENDPOINT_SIZE, 1016 .bLength = USB_DT_ENDPOINT_SIZE,
1061 .bDescriptorType = USB_DT_ENDPOINT, 1017 .bDescriptorType = USB_DT_ENDPOINT,
@@ -1074,7 +1030,6 @@ static void nop_release(struct device *dev)
1074static struct usba_udc the_udc = { 1030static struct usba_udc the_udc = {
1075 .gadget = { 1031 .gadget = {
1076 .ops = &usba_udc_ops, 1032 .ops = &usba_udc_ops,
1077 .ep0 = &usba_ep[0].ep,
1078 .ep_list = LIST_HEAD_INIT(the_udc.gadget.ep_list), 1033 .ep_list = LIST_HEAD_INIT(the_udc.gadget.ep_list),
1079 .is_dualspeed = 1, 1034 .is_dualspeed = 1,
1080 .name = "atmel_usba_udc", 1035 .name = "atmel_usba_udc",
@@ -1083,8 +1038,6 @@ static struct usba_udc the_udc = {
1083 .release = nop_release, 1038 .release = nop_release,
1084 }, 1039 },
1085 }, 1040 },
1086
1087 .lock = SPIN_LOCK_UNLOCKED,
1088}; 1041};
1089 1042
1090/* 1043/*
@@ -1103,6 +1056,12 @@ static void reset_all_endpoints(struct usba_udc *udc)
1103 request_complete(ep, req, -ECONNRESET); 1056 request_complete(ep, req, -ECONNRESET);
1104 } 1057 }
1105 1058
1059 /* NOTE: normally, the next call to the gadget driver is in
1060 * charge of disabling endpoints... usually disconnect().
1061 * The exception would be entering a high speed test mode.
1062 *
1063 * FIXME remove this code ... and retest thoroughly.
1064 */
1106 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { 1065 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
1107 if (ep->desc) { 1066 if (ep->desc) {
1108 spin_unlock(&udc->lock); 1067 spin_unlock(&udc->lock);
@@ -1231,7 +1190,7 @@ static int do_test_mode(struct usba_udc *udc)
1231 } else { 1190 } else {
1232 usba_ep_writel(ep, CTL_ENB, USBA_EPT_ENABLE); 1191 usba_ep_writel(ep, CTL_ENB, USBA_EPT_ENABLE);
1233 usba_writel(udc, TST, USBA_TST_PKT_MODE); 1192 usba_writel(udc, TST, USBA_TST_PKT_MODE);
1234 copy_to_fifo(ep->fifo, test_packet_buffer, 1193 memcpy_toio(ep->fifo, test_packet_buffer,
1235 sizeof(test_packet_buffer)); 1194 sizeof(test_packet_buffer));
1236 usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY); 1195 usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
1237 dev_info(dev, "Entering Test_Packet mode...\n"); 1196 dev_info(dev, "Entering Test_Packet mode...\n");
@@ -1270,7 +1229,7 @@ static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
1270static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep, 1229static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1271 struct usb_ctrlrequest *crq) 1230 struct usb_ctrlrequest *crq)
1272{ 1231{
1273 int retval = 0;; 1232 int retval = 0;
1274 1233
1275 switch (crq->bRequest) { 1234 switch (crq->bRequest) {
1276 case USB_REQ_GET_STATUS: { 1235 case USB_REQ_GET_STATUS: {
@@ -1530,13 +1489,13 @@ restart:
1530 DBG(DBG_HW, "Packet length: %u\n", pkt_len); 1489 DBG(DBG_HW, "Packet length: %u\n", pkt_len);
1531 if (pkt_len != sizeof(crq)) { 1490 if (pkt_len != sizeof(crq)) {
1532 pr_warning("udc: Invalid packet length %u " 1491 pr_warning("udc: Invalid packet length %u "
1533 "(expected %lu)\n", pkt_len, sizeof(crq)); 1492 "(expected %zu)\n", pkt_len, sizeof(crq));
1534 set_protocol_stall(udc, ep); 1493 set_protocol_stall(udc, ep);
1535 return; 1494 return;
1536 } 1495 }
1537 1496
1538 DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo); 1497 DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo);
1539 copy_from_fifo(crq.data, ep->fifo, sizeof(crq)); 1498 memcpy_fromio(crq.data, ep->fifo, sizeof(crq));
1540 1499
1541 /* Free up one bank in the FIFO so that we can 1500 /* Free up one bank in the FIFO so that we can
1542 * generate or receive a reply right away. */ 1501 * generate or receive a reply right away. */
@@ -1688,6 +1647,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
1688 DBG(DBG_INT, "irq, status=%#08x\n", status); 1647 DBG(DBG_INT, "irq, status=%#08x\n", status);
1689 1648
1690 if (status & USBA_DET_SUSPEND) { 1649 if (status & USBA_DET_SUSPEND) {
1650 toggle_bias(0);
1691 usba_writel(udc, INT_CLR, USBA_DET_SUSPEND); 1651 usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
1692 DBG(DBG_BUS, "Suspend detected\n"); 1652 DBG(DBG_BUS, "Suspend detected\n");
1693 if (udc->gadget.speed != USB_SPEED_UNKNOWN 1653 if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1699,6 +1659,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
1699 } 1659 }
1700 1660
1701 if (status & USBA_WAKE_UP) { 1661 if (status & USBA_WAKE_UP) {
1662 toggle_bias(1);
1702 usba_writel(udc, INT_CLR, USBA_WAKE_UP); 1663 usba_writel(udc, INT_CLR, USBA_WAKE_UP);
1703 DBG(DBG_BUS, "Wake Up CPU detected\n"); 1664 DBG(DBG_BUS, "Wake Up CPU detected\n");
1704 } 1665 }
@@ -1742,6 +1703,14 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
1742 usba_writel(udc, INT_CLR, USBA_END_OF_RESET); 1703 usba_writel(udc, INT_CLR, USBA_END_OF_RESET);
1743 reset_all_endpoints(udc); 1704 reset_all_endpoints(udc);
1744 1705
1706 if (udc->gadget.speed != USB_SPEED_UNKNOWN
1707 && udc->driver->disconnect) {
1708 udc->gadget.speed = USB_SPEED_UNKNOWN;
1709 spin_unlock(&udc->lock);
1710 udc->driver->disconnect(&udc->gadget);
1711 spin_lock(&udc->lock);
1712 }
1713
1745 if (status & USBA_HIGH_SPEED) { 1714 if (status & USBA_HIGH_SPEED) {
1746 DBG(DBG_BUS, "High-speed bus reset detected\n"); 1715 DBG(DBG_BUS, "High-speed bus reset detected\n");
1747 udc->gadget.speed = USB_SPEED_HIGH; 1716 udc->gadget.speed = USB_SPEED_HIGH;
@@ -1765,9 +1734,13 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
1765 | USBA_DET_SUSPEND 1734 | USBA_DET_SUSPEND
1766 | USBA_END_OF_RESUME)); 1735 | USBA_END_OF_RESUME));
1767 1736
1737 /*
1738 * Unclear why we hit this irregularly, e.g. in usbtest,
1739 * but it's clearly harmless...
1740 */
1768 if (!(usba_ep_readl(ep0, CFG) & USBA_EPT_MAPPED)) 1741 if (!(usba_ep_readl(ep0, CFG) & USBA_EPT_MAPPED))
1769 dev_warn(&udc->pdev->dev, 1742 dev_dbg(&udc->pdev->dev,
1770 "WARNING: EP0 configuration is invalid!\n"); 1743 "ODD: EP0 configuration is invalid!\n");
1771 } 1744 }
1772 1745
1773 spin_unlock(&udc->lock); 1746 spin_unlock(&udc->lock);
@@ -1792,15 +1765,19 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
1792 vbus = gpio_get_value(udc->vbus_pin); 1765 vbus = gpio_get_value(udc->vbus_pin);
1793 if (vbus != udc->vbus_prev) { 1766 if (vbus != udc->vbus_prev) {
1794 if (vbus) { 1767 if (vbus) {
1795 usba_writel(udc, CTRL, USBA_EN_USBA); 1768 toggle_bias(1);
1769 usba_writel(udc, CTRL, USBA_ENABLE_MASK);
1796 usba_writel(udc, INT_ENB, USBA_END_OF_RESET); 1770 usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
1797 } else { 1771 } else {
1798 udc->gadget.speed = USB_SPEED_UNKNOWN; 1772 udc->gadget.speed = USB_SPEED_UNKNOWN;
1799 reset_all_endpoints(udc); 1773 reset_all_endpoints(udc);
1800 usba_writel(udc, CTRL, 0); 1774 toggle_bias(0);
1801 spin_unlock(&udc->lock); 1775 usba_writel(udc, CTRL, USBA_DISABLE_MASK);
1802 udc->driver->disconnect(&udc->gadget); 1776 if (udc->driver->disconnect) {
1803 spin_lock(&udc->lock); 1777 spin_unlock(&udc->lock);
1778 udc->driver->disconnect(&udc->gadget);
1779 spin_lock(&udc->lock);
1780 }
1804 } 1781 }
1805 udc->vbus_prev = vbus; 1782 udc->vbus_prev = vbus;
1806 } 1783 }
@@ -1850,7 +1827,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1850 /* If Vbus is present, enable the controller and wait for reset */ 1827 /* If Vbus is present, enable the controller and wait for reset */
1851 spin_lock_irqsave(&udc->lock, flags); 1828 spin_lock_irqsave(&udc->lock, flags);
1852 if (vbus_is_present(udc) && udc->vbus_prev == 0) { 1829 if (vbus_is_present(udc) && udc->vbus_prev == 0) {
1853 usba_writel(udc, CTRL, USBA_EN_USBA); 1830 toggle_bias(1);
1831 usba_writel(udc, CTRL, USBA_ENABLE_MASK);
1854 usba_writel(udc, INT_ENB, USBA_END_OF_RESET); 1832 usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
1855 } 1833 }
1856 spin_unlock_irqrestore(&udc->lock, flags); 1834 spin_unlock_irqrestore(&udc->lock, flags);
@@ -1871,7 +1849,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1871 1849
1872 if (!udc->pdev) 1850 if (!udc->pdev)
1873 return -ENODEV; 1851 return -ENODEV;
1874 if (driver != udc->driver) 1852 if (driver != udc->driver || !driver->unbind)
1875 return -EINVAL; 1853 return -EINVAL;
1876 1854
1877 if (udc->vbus_pin != -1) 1855 if (udc->vbus_pin != -1)
@@ -1883,7 +1861,11 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1883 spin_unlock_irqrestore(&udc->lock, flags); 1861 spin_unlock_irqrestore(&udc->lock, flags);
1884 1862
1885 /* This will also disable the DP pullup */ 1863 /* This will also disable the DP pullup */
1886 usba_writel(udc, CTRL, 0); 1864 toggle_bias(0);
1865 usba_writel(udc, CTRL, USBA_DISABLE_MASK);
1866
1867 if (udc->driver->disconnect)
1868 udc->driver->disconnect(&udc->gadget);
1887 1869
1888 driver->unbind(&udc->gadget); 1870 driver->unbind(&udc->gadget);
1889 udc->gadget.dev.driver = NULL; 1871 udc->gadget.dev.driver = NULL;
@@ -1908,7 +1890,7 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1908 1890
1909 regs = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID); 1891 regs = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID);
1910 fifo = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID); 1892 fifo = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID);
1911 if (!regs || !fifo) 1893 if (!regs || !fifo || !pdata)
1912 return -ENXIO; 1894 return -ENXIO;
1913 1895
1914 irq = platform_get_irq(pdev, 0); 1896 irq = platform_get_irq(pdev, 0);
@@ -1924,6 +1906,7 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1924 goto err_get_hclk; 1906 goto err_get_hclk;
1925 } 1907 }
1926 1908
1909 spin_lock_init(&udc->lock);
1927 udc->pdev = pdev; 1910 udc->pdev = pdev;
1928 udc->pclk = pclk; 1911 udc->pclk = pclk;
1929 udc->hclk = hclk; 1912 udc->hclk = hclk;
@@ -1953,19 +1936,48 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1953 1936
1954 /* Make sure we start from a clean slate */ 1937 /* Make sure we start from a clean slate */
1955 clk_enable(pclk); 1938 clk_enable(pclk);
1956 usba_writel(udc, CTRL, 0); 1939 toggle_bias(0);
1940 usba_writel(udc, CTRL, USBA_DISABLE_MASK);
1957 clk_disable(pclk); 1941 clk_disable(pclk);
1958 1942
1943 usba_ep = kmalloc(sizeof(struct usba_ep) * pdata->num_ep,
1944 GFP_KERNEL);
1945 if (!usba_ep)
1946 goto err_alloc_ep;
1947
1948 the_udc.gadget.ep0 = &usba_ep[0].ep;
1949
1959 INIT_LIST_HEAD(&usba_ep[0].ep.ep_list); 1950 INIT_LIST_HEAD(&usba_ep[0].ep.ep_list);
1960 usba_ep[0].ep_regs = udc->regs + USBA_EPT_BASE(0); 1951 usba_ep[0].ep_regs = udc->regs + USBA_EPT_BASE(0);
1961 usba_ep[0].dma_regs = udc->regs + USBA_DMA_BASE(0); 1952 usba_ep[0].dma_regs = udc->regs + USBA_DMA_BASE(0);
1962 usba_ep[0].fifo = udc->fifo + USBA_FIFO_BASE(0); 1953 usba_ep[0].fifo = udc->fifo + USBA_FIFO_BASE(0);
1963 for (i = 1; i < ARRAY_SIZE(usba_ep); i++) { 1954 usba_ep[0].ep.ops = &usba_ep_ops;
1955 usba_ep[0].ep.name = pdata->ep[0].name;
1956 usba_ep[0].ep.maxpacket = pdata->ep[0].fifo_size;
1957 usba_ep[0].udc = &the_udc;
1958 INIT_LIST_HEAD(&usba_ep[0].queue);
1959 usba_ep[0].fifo_size = pdata->ep[0].fifo_size;
1960 usba_ep[0].nr_banks = pdata->ep[0].nr_banks;
1961 usba_ep[0].index = pdata->ep[0].index;
1962 usba_ep[0].can_dma = pdata->ep[0].can_dma;
1963 usba_ep[0].can_isoc = pdata->ep[0].can_isoc;
1964
1965 for (i = 1; i < pdata->num_ep; i++) {
1964 struct usba_ep *ep = &usba_ep[i]; 1966 struct usba_ep *ep = &usba_ep[i];
1965 1967
1966 ep->ep_regs = udc->regs + USBA_EPT_BASE(i); 1968 ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
1967 ep->dma_regs = udc->regs + USBA_DMA_BASE(i); 1969 ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
1968 ep->fifo = udc->fifo + USBA_FIFO_BASE(i); 1970 ep->fifo = udc->fifo + USBA_FIFO_BASE(i);
1971 ep->ep.ops = &usba_ep_ops;
1972 ep->ep.name = pdata->ep[i].name;
1973 ep->ep.maxpacket = pdata->ep[i].fifo_size;
1974 ep->udc = &the_udc;
1975 INIT_LIST_HEAD(&ep->queue);
1976 ep->fifo_size = pdata->ep[i].fifo_size;
1977 ep->nr_banks = pdata->ep[i].nr_banks;
1978 ep->index = pdata->ep[i].index;
1979 ep->can_dma = pdata->ep[i].can_dma;
1980 ep->can_isoc = pdata->ep[i].can_isoc;
1969 1981
1970 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); 1982 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
1971 } 1983 }
@@ -1984,7 +1996,7 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1984 goto err_device_add; 1996 goto err_device_add;
1985 } 1997 }
1986 1998
1987 if (pdata && pdata->vbus_pin != GPIO_PIN_NONE) { 1999 if (pdata->vbus_pin >= 0) {
1988 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) { 2000 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) {
1989 udc->vbus_pin = pdata->vbus_pin; 2001 udc->vbus_pin = pdata->vbus_pin;
1990 2002
@@ -2004,7 +2016,7 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2004 } 2016 }
2005 2017
2006 usba_init_debugfs(udc); 2018 usba_init_debugfs(udc);
2007 for (i = 1; i < ARRAY_SIZE(usba_ep); i++) 2019 for (i = 1; i < pdata->num_ep; i++)
2008 usba_ep_init_debugfs(udc, &usba_ep[i]); 2020 usba_ep_init_debugfs(udc, &usba_ep[i]);
2009 2021
2010 return 0; 2022 return 0;
@@ -2012,6 +2024,8 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2012err_device_add: 2024err_device_add:
2013 free_irq(irq, udc); 2025 free_irq(irq, udc);
2014err_request_irq: 2026err_request_irq:
2027 kfree(usba_ep);
2028err_alloc_ep:
2015 iounmap(udc->fifo); 2029 iounmap(udc->fifo);
2016err_map_fifo: 2030err_map_fifo:
2017 iounmap(udc->regs); 2031 iounmap(udc->regs);
@@ -2029,10 +2043,11 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
2029{ 2043{
2030 struct usba_udc *udc; 2044 struct usba_udc *udc;
2031 int i; 2045 int i;
2046 struct usba_platform_data *pdata = pdev->dev.platform_data;
2032 2047
2033 udc = platform_get_drvdata(pdev); 2048 udc = platform_get_drvdata(pdev);
2034 2049
2035 for (i = 1; i < ARRAY_SIZE(usba_ep); i++) 2050 for (i = 1; i < pdata->num_ep; i++)
2036 usba_ep_cleanup_debugfs(&usba_ep[i]); 2051 usba_ep_cleanup_debugfs(&usba_ep[i]);
2037 usba_cleanup_debugfs(udc); 2052 usba_cleanup_debugfs(udc);
2038 2053
@@ -2040,6 +2055,7 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
2040 gpio_free(udc->vbus_pin); 2055 gpio_free(udc->vbus_pin);
2041 2056
2042 free_irq(udc->irq, udc); 2057 free_irq(udc->irq, udc);
2058 kfree(usba_ep);
2043 iounmap(udc->fifo); 2059 iounmap(udc->fifo);
2044 iounmap(udc->regs); 2060 iounmap(udc->regs);
2045 clk_put(udc->hclk); 2061 clk_put(udc->hclk);
@@ -2054,6 +2070,7 @@ static struct platform_driver udc_driver = {
2054 .remove = __exit_p(usba_udc_remove), 2070 .remove = __exit_p(usba_udc_remove),
2055 .driver = { 2071 .driver = {
2056 .name = "atmel_usba_udc", 2072 .name = "atmel_usba_udc",
2073 .owner = THIS_MODULE,
2057 }, 2074 },
2058}; 2075};
2059 2076
@@ -2072,3 +2089,4 @@ module_exit(udc_exit);
2072MODULE_DESCRIPTION("Atmel USBA UDC driver"); 2089MODULE_DESCRIPTION("Atmel USBA UDC driver");
2073MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>"); 2090MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
2074MODULE_LICENSE("GPL"); 2091MODULE_LICENSE("GPL");
2092MODULE_ALIAS("platform:atmel_usba_udc");
diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h
index 08bf6f9aaf7e..f7baea307f0d 100644
--- a/drivers/usb/gadget/atmel_usba_udc.h
+++ b/drivers/usb/gadget/atmel_usba_udc.h
@@ -41,6 +41,15 @@
41#define USBA_EN_USBA (1 << 8) 41#define USBA_EN_USBA (1 << 8)
42#define USBA_DETACH (1 << 9) 42#define USBA_DETACH (1 << 9)
43#define USBA_REMOTE_WAKE_UP (1 << 10) 43#define USBA_REMOTE_WAKE_UP (1 << 10)
44#define USBA_PULLD_DIS (1 << 11)
45
46#if defined(CONFIG_AVR32)
47#define USBA_ENABLE_MASK USBA_EN_USBA
48#define USBA_DISABLE_MASK 0
49#elif defined(CONFIG_ARCH_AT91)
50#define USBA_ENABLE_MASK (USBA_EN_USBA | USBA_PULLD_DIS)
51#define USBA_DISABLE_MASK USBA_DETACH
52#endif /* CONFIG_ARCH_AT91 */
44 53
45/* Bitfields in FNUM */ 54/* Bitfields in FNUM */
46#define USBA_MICRO_FRAME_NUM_OFFSET 0 55#define USBA_MICRO_FRAME_NUM_OFFSET 0
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index cbe44535c0f0..42036192a03c 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -365,16 +365,14 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
365 case USB_SPEED_HIGH: 365 case USB_SPEED_HIGH:
366 if (max == 512) 366 if (max == 512)
367 break; 367 break;
368 /* conserve return statements */ 368 goto done;
369 default: 369 case USB_SPEED_FULL:
370 switch (max) { 370 if (max == 8 || max == 16 || max == 32 || max == 64)
371 case 8: case 16: case 32: case 64:
372 /* we'll fake any legal size */ 371 /* we'll fake any legal size */
373 break; 372 break;
374 default: 373 /* save a return statement */
375 case USB_SPEED_LOW: 374 default:
376 goto done; 375 goto done;
377 }
378 } 376 }
379 break; 377 break;
380 case USB_ENDPOINT_XFER_INT: 378 case USB_ENDPOINT_XFER_INT:
@@ -894,13 +892,12 @@ static int dummy_udc_suspend (struct platform_device *pdev, pm_message_t state)
894{ 892{
895 struct dummy *dum = platform_get_drvdata(pdev); 893 struct dummy *dum = platform_get_drvdata(pdev);
896 894
897 dev_dbg (&pdev->dev, "%s\n", __FUNCTION__); 895 dev_dbg (&pdev->dev, "%s\n", __func__);
898 spin_lock_irq (&dum->lock); 896 spin_lock_irq (&dum->lock);
899 dum->udc_suspended = 1; 897 dum->udc_suspended = 1;
900 set_link_state (dum); 898 set_link_state (dum);
901 spin_unlock_irq (&dum->lock); 899 spin_unlock_irq (&dum->lock);
902 900
903 pdev->dev.power.power_state = state;
904 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 901 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
905 return 0; 902 return 0;
906} 903}
@@ -909,13 +906,12 @@ static int dummy_udc_resume (struct platform_device *pdev)
909{ 906{
910 struct dummy *dum = platform_get_drvdata(pdev); 907 struct dummy *dum = platform_get_drvdata(pdev);
911 908
912 dev_dbg (&pdev->dev, "%s\n", __FUNCTION__); 909 dev_dbg (&pdev->dev, "%s\n", __func__);
913 spin_lock_irq (&dum->lock); 910 spin_lock_irq (&dum->lock);
914 dum->udc_suspended = 0; 911 dum->udc_suspended = 0;
915 set_link_state (dum); 912 set_link_state (dum);
916 spin_unlock_irq (&dum->lock); 913 spin_unlock_irq (&dum->lock);
917 914
918 pdev->dev.power.power_state = PMSG_ON;
919 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 915 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
920 return 0; 916 return 0;
921} 917}
@@ -1559,8 +1555,7 @@ hub_descriptor (struct usb_hub_descriptor *desc)
1559 memset (desc, 0, sizeof *desc); 1555 memset (desc, 0, sizeof *desc);
1560 desc->bDescriptorType = 0x29; 1556 desc->bDescriptorType = 0x29;
1561 desc->bDescLength = 9; 1557 desc->bDescLength = 9;
1562 desc->wHubCharacteristics = (__force __u16) 1558 desc->wHubCharacteristics = cpu_to_le16(0x0001);
1563 (__constant_cpu_to_le16 (0x0001));
1564 desc->bNbrPorts = 1; 1559 desc->bNbrPorts = 1;
1565 desc->bitmap [0] = 0xff; 1560 desc->bitmap [0] = 0xff;
1566 desc->bitmap [1] = 0xff; 1561 desc->bitmap [1] = 0xff;
@@ -1711,7 +1706,7 @@ static int dummy_bus_suspend (struct usb_hcd *hcd)
1711{ 1706{
1712 struct dummy *dum = hcd_to_dummy (hcd); 1707 struct dummy *dum = hcd_to_dummy (hcd);
1713 1708
1714 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __FUNCTION__); 1709 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
1715 1710
1716 spin_lock_irq (&dum->lock); 1711 spin_lock_irq (&dum->lock);
1717 dum->rh_state = DUMMY_RH_SUSPENDED; 1712 dum->rh_state = DUMMY_RH_SUSPENDED;
@@ -1726,7 +1721,7 @@ static int dummy_bus_resume (struct usb_hcd *hcd)
1726 struct dummy *dum = hcd_to_dummy (hcd); 1721 struct dummy *dum = hcd_to_dummy (hcd);
1727 int rc = 0; 1722 int rc = 0;
1728 1723
1729 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __FUNCTION__); 1724 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
1730 1725
1731 spin_lock_irq (&dum->lock); 1726 spin_lock_irq (&dum->lock);
1732 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 1727 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
@@ -1900,7 +1895,7 @@ static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state)
1900 struct dummy *dum; 1895 struct dummy *dum;
1901 int rc = 0; 1896 int rc = 0;
1902 1897
1903 dev_dbg (&pdev->dev, "%s\n", __FUNCTION__); 1898 dev_dbg (&pdev->dev, "%s\n", __func__);
1904 1899
1905 hcd = platform_get_drvdata (pdev); 1900 hcd = platform_get_drvdata (pdev);
1906 dum = hcd_to_dummy (hcd); 1901 dum = hcd_to_dummy (hcd);
@@ -1916,7 +1911,7 @@ static int dummy_hcd_resume (struct platform_device *pdev)
1916{ 1911{
1917 struct usb_hcd *hcd; 1912 struct usb_hcd *hcd;
1918 1913
1919 dev_dbg (&pdev->dev, "%s\n", __FUNCTION__); 1914 dev_dbg (&pdev->dev, "%s\n", __func__);
1920 1915
1921 hcd = platform_get_drvdata (pdev); 1916 hcd = platform_get_drvdata (pdev);
1922 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 1917 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
@@ -1937,69 +1932,57 @@ static struct platform_driver dummy_hcd_driver = {
1937 1932
1938/*-------------------------------------------------------------------------*/ 1933/*-------------------------------------------------------------------------*/
1939 1934
1940/* These don't need to do anything because the pdev structures are 1935static struct platform_device *the_udc_pdev;
1941 * statically allocated. */ 1936static struct platform_device *the_hcd_pdev;
1942static void
1943dummy_udc_release (struct device *dev) {}
1944
1945static void
1946dummy_hcd_release (struct device *dev) {}
1947
1948static struct platform_device the_udc_pdev = {
1949 .name = (char *) gadget_name,
1950 .id = -1,
1951 .dev = {
1952 .release = dummy_udc_release,
1953 },
1954};
1955
1956static struct platform_device the_hcd_pdev = {
1957 .name = (char *) driver_name,
1958 .id = -1,
1959 .dev = {
1960 .release = dummy_hcd_release,
1961 },
1962};
1963 1937
1964static int __init init (void) 1938static int __init init (void)
1965{ 1939{
1966 int retval; 1940 int retval = -ENOMEM;
1967 1941
1968 if (usb_disabled ()) 1942 if (usb_disabled ())
1969 return -ENODEV; 1943 return -ENODEV;
1970 1944
1971 retval = platform_driver_register (&dummy_hcd_driver); 1945 the_hcd_pdev = platform_device_alloc(driver_name, -1);
1972 if (retval < 0) 1946 if (!the_hcd_pdev)
1973 return retval; 1947 return retval;
1948 the_udc_pdev = platform_device_alloc(gadget_name, -1);
1949 if (!the_udc_pdev)
1950 goto err_alloc_udc;
1974 1951
1975 retval = platform_driver_register (&dummy_udc_driver); 1952 retval = platform_driver_register(&dummy_hcd_driver);
1953 if (retval < 0)
1954 goto err_register_hcd_driver;
1955 retval = platform_driver_register(&dummy_udc_driver);
1976 if (retval < 0) 1956 if (retval < 0)
1977 goto err_register_udc_driver; 1957 goto err_register_udc_driver;
1978 1958
1979 retval = platform_device_register (&the_hcd_pdev); 1959 retval = platform_device_add(the_hcd_pdev);
1980 if (retval < 0) 1960 if (retval < 0)
1981 goto err_register_hcd; 1961 goto err_add_hcd;
1982 1962 retval = platform_device_add(the_udc_pdev);
1983 retval = platform_device_register (&the_udc_pdev);
1984 if (retval < 0) 1963 if (retval < 0)
1985 goto err_register_udc; 1964 goto err_add_udc;
1986 return retval; 1965 return retval;
1987 1966
1988err_register_udc: 1967err_add_udc:
1989 platform_device_unregister (&the_hcd_pdev); 1968 platform_device_del(the_hcd_pdev);
1990err_register_hcd: 1969err_add_hcd:
1991 platform_driver_unregister (&dummy_udc_driver); 1970 platform_driver_unregister(&dummy_udc_driver);
1992err_register_udc_driver: 1971err_register_udc_driver:
1993 platform_driver_unregister (&dummy_hcd_driver); 1972 platform_driver_unregister(&dummy_hcd_driver);
1973err_register_hcd_driver:
1974 platform_device_put(the_udc_pdev);
1975err_alloc_udc:
1976 platform_device_put(the_hcd_pdev);
1994 return retval; 1977 return retval;
1995} 1978}
1996module_init (init); 1979module_init (init);
1997 1980
1998static void __exit cleanup (void) 1981static void __exit cleanup (void)
1999{ 1982{
2000 platform_device_unregister (&the_udc_pdev); 1983 platform_device_unregister(the_udc_pdev);
2001 platform_device_unregister (&the_hcd_pdev); 1984 platform_device_unregister(the_hcd_pdev);
2002 platform_driver_unregister (&dummy_udc_driver); 1985 platform_driver_unregister(&dummy_udc_driver);
2003 platform_driver_unregister (&dummy_hcd_driver); 1986 platform_driver_unregister(&dummy_hcd_driver);
2004} 1987}
2005module_exit (cleanup); 1988module_exit (cleanup);
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index f9d07108bc30..8bdad221fa91 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -34,12 +34,12 @@
34 34
35 35
36/* we must assign addresses for configurable endpoints (like net2280) */ 36/* we must assign addresses for configurable endpoints (like net2280) */
37static __devinitdata unsigned epnum; 37static __initdata unsigned epnum;
38 38
39// #define MANY_ENDPOINTS 39// #define MANY_ENDPOINTS
40#ifdef MANY_ENDPOINTS 40#ifdef MANY_ENDPOINTS
41/* more than 15 configurable endpoints */ 41/* more than 15 configurable endpoints */
42static __devinitdata unsigned in_epnum; 42static __initdata unsigned in_epnum;
43#endif 43#endif
44 44
45 45
@@ -59,7 +59,7 @@ static __devinitdata unsigned in_epnum;
59 * NOTE: each endpoint is unidirectional, as specified by its USB 59 * NOTE: each endpoint is unidirectional, as specified by its USB
60 * descriptor; and isn't specific to a configuration or altsetting. 60 * descriptor; and isn't specific to a configuration or altsetting.
61 */ 61 */
62static int __devinit 62static int __init
63ep_matches ( 63ep_matches (
64 struct usb_gadget *gadget, 64 struct usb_gadget *gadget,
65 struct usb_ep *ep, 65 struct usb_ep *ep,
@@ -186,7 +186,7 @@ ep_matches (
186 return 1; 186 return 1;
187} 187}
188 188
189static struct usb_ep * __devinit 189static struct usb_ep * __init
190find_ep (struct usb_gadget *gadget, const char *name) 190find_ep (struct usb_gadget *gadget, const char *name)
191{ 191{
192 struct usb_ep *ep; 192 struct usb_ep *ep;
@@ -228,7 +228,7 @@ find_ep (struct usb_gadget *gadget, const char *name)
228 * 228 *
229 * On failure, this returns a null endpoint descriptor. 229 * On failure, this returns a null endpoint descriptor.
230 */ 230 */
231struct usb_ep * __devinit usb_ep_autoconfig ( 231struct usb_ep * __init usb_ep_autoconfig (
232 struct usb_gadget *gadget, 232 struct usb_gadget *gadget,
233 struct usb_endpoint_descriptor *desc 233 struct usb_endpoint_descriptor *desc
234) 234)
@@ -295,7 +295,7 @@ struct usb_ep * __devinit usb_ep_autoconfig (
295 * state such as ep->driver_data and the record of assigned endpoints 295 * state such as ep->driver_data and the record of assigned endpoints
296 * used by usb_ep_autoconfig(). 296 * used by usb_ep_autoconfig().
297 */ 297 */
298void __devinit usb_ep_autoconfig_reset (struct usb_gadget *gadget) 298void __init usb_ep_autoconfig_reset (struct usb_gadget *gadget)
299{ 299{
300 struct usb_ep *ep; 300 struct usb_ep *ep;
301 301
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index e99872308144..8d61ea67a817 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -235,10 +235,6 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
235#define DEV_CONFIG_CDC 235#define DEV_CONFIG_CDC
236#endif 236#endif
237 237
238#ifdef CONFIG_USB_GADGET_PXA27X
239#define DEV_CONFIG_CDC
240#endif
241
242#ifdef CONFIG_USB_GADGET_S3C2410 238#ifdef CONFIG_USB_GADGET_S3C2410
243#define DEV_CONFIG_CDC 239#define DEV_CONFIG_CDC
244#endif 240#endif
@@ -270,6 +266,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
270#define DEV_CONFIG_SUBSET 266#define DEV_CONFIG_SUBSET
271#endif 267#endif
272 268
269#ifdef CONFIG_USB_GADGET_PXA27X
270#define DEV_CONFIG_SUBSET
271#endif
272
273#ifdef CONFIG_USB_GADGET_SUPERH 273#ifdef CONFIG_USB_GADGET_SUPERH
274#define DEV_CONFIG_SUBSET 274#define DEV_CONFIG_SUBSET
275#endif 275#endif
@@ -1102,7 +1102,7 @@ static void eth_reset_config (struct eth_dev *dev)
1102 if (dev->config == 0) 1102 if (dev->config == 0)
1103 return; 1103 return;
1104 1104
1105 DEBUG (dev, "%s\n", __FUNCTION__); 1105 DEBUG (dev, "%s\n", __func__);
1106 1106
1107 netif_stop_queue (dev->net); 1107 netif_stop_queue (dev->net);
1108 netif_carrier_off (dev->net); 1108 netif_carrier_off (dev->net);
@@ -1263,7 +1263,7 @@ static void issue_start_status (struct eth_dev *dev)
1263 struct usb_cdc_notification *event; 1263 struct usb_cdc_notification *event;
1264 int value; 1264 int value;
1265 1265
1266 DEBUG (dev, "%s, flush old status first\n", __FUNCTION__); 1266 DEBUG (dev, "%s, flush old status first\n", __func__);
1267 1267
1268 /* flush old status 1268 /* flush old status
1269 * 1269 *
@@ -1329,7 +1329,7 @@ static void rndis_command_complete (struct usb_ep *ep, struct usb_request *req)
1329 spin_lock(&dev->lock); 1329 spin_lock(&dev->lock);
1330 status = rndis_msg_parser (dev->rndis_config, (u8 *) req->buf); 1330 status = rndis_msg_parser (dev->rndis_config, (u8 *) req->buf);
1331 if (status < 0) 1331 if (status < 0)
1332 ERROR(dev, "%s: rndis parse error %d\n", __FUNCTION__, status); 1332 ERROR(dev, "%s: rndis parse error %d\n", __func__, status);
1333 spin_unlock(&dev->lock); 1333 spin_unlock(&dev->lock);
1334} 1334}
1335 1335
@@ -2113,7 +2113,7 @@ static int rndis_control_ack (struct net_device *net)
2113 2113
2114static void eth_start (struct eth_dev *dev, gfp_t gfp_flags) 2114static void eth_start (struct eth_dev *dev, gfp_t gfp_flags)
2115{ 2115{
2116 DEBUG (dev, "%s\n", __FUNCTION__); 2116 DEBUG (dev, "%s\n", __func__);
2117 2117
2118 /* fill the rx queue */ 2118 /* fill the rx queue */
2119 rx_fill (dev, gfp_flags); 2119 rx_fill (dev, gfp_flags);
@@ -2133,7 +2133,7 @@ static int eth_open (struct net_device *net)
2133{ 2133{
2134 struct eth_dev *dev = netdev_priv(net); 2134 struct eth_dev *dev = netdev_priv(net);
2135 2135
2136 DEBUG (dev, "%s\n", __FUNCTION__); 2136 DEBUG (dev, "%s\n", __func__);
2137 if (netif_carrier_ok (dev->net)) 2137 if (netif_carrier_ok (dev->net))
2138 eth_start (dev, GFP_KERNEL); 2138 eth_start (dev, GFP_KERNEL);
2139 return 0; 2139 return 0;
@@ -2143,7 +2143,7 @@ static int eth_stop (struct net_device *net)
2143{ 2143{
2144 struct eth_dev *dev = netdev_priv(net); 2144 struct eth_dev *dev = netdev_priv(net);
2145 2145
2146 VDEBUG (dev, "%s\n", __FUNCTION__); 2146 VDEBUG (dev, "%s\n", __func__);
2147 netif_stop_queue (net); 2147 netif_stop_queue (net);
2148 2148
2149 DEBUG (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n", 2149 DEBUG (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n",
@@ -2229,7 +2229,7 @@ eth_unbind (struct usb_gadget *gadget)
2229 set_gadget_data (gadget, NULL); 2229 set_gadget_data (gadget, NULL);
2230} 2230}
2231 2231
2232static u8 __devinit nibble (unsigned char c) 2232static u8 __init nibble (unsigned char c)
2233{ 2233{
2234 if (likely (isdigit (c))) 2234 if (likely (isdigit (c)))
2235 return c - '0'; 2235 return c - '0';
@@ -2239,7 +2239,7 @@ static u8 __devinit nibble (unsigned char c)
2239 return 0; 2239 return 0;
2240} 2240}
2241 2241
2242static int __devinit get_ether_addr(const char *str, u8 *dev_addr) 2242static int __init get_ether_addr(const char *str, u8 *dev_addr)
2243{ 2243{
2244 if (str) { 2244 if (str) {
2245 unsigned i; 2245 unsigned i;
@@ -2260,7 +2260,7 @@ static int __devinit get_ether_addr(const char *str, u8 *dev_addr)
2260 return 1; 2260 return 1;
2261} 2261}
2262 2262
2263static int __devinit 2263static int __init
2264eth_bind (struct usb_gadget *gadget) 2264eth_bind (struct usb_gadget *gadget)
2265{ 2265{
2266 struct eth_dev *dev; 2266 struct eth_dev *dev;
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 017a196d041f..47bb9f09a1aa 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -644,7 +644,7 @@ struct fsg_dev {
644 644
645 unsigned long atomic_bitflags; 645 unsigned long atomic_bitflags;
646#define REGISTERED 0 646#define REGISTERED 0
647#define CLEAR_BULK_HALTS 1 647#define IGNORE_BULK_OUT 1
648#define SUSPENDED 2 648#define SUSPENDED 2
649 649
650 struct usb_ep *bulk_in; 650 struct usb_ep *bulk_in;
@@ -1104,7 +1104,7 @@ static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
1104 if (req->actual > 0) 1104 if (req->actual > 0)
1105 dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual); 1105 dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
1106 if (req->status || req->actual != req->length) 1106 if (req->status || req->actual != req->length)
1107 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1107 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
1108 req->status, req->actual, req->length); 1108 req->status, req->actual, req->length);
1109 if (req->status == -ECONNRESET) // Request was cancelled 1109 if (req->status == -ECONNRESET) // Request was cancelled
1110 usb_ep_fifo_flush(ep); 1110 usb_ep_fifo_flush(ep);
@@ -1125,7 +1125,7 @@ static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
1125 struct fsg_buffhd *bh = req->context; 1125 struct fsg_buffhd *bh = req->context;
1126 1126
1127 if (req->status || req->actual != req->length) 1127 if (req->status || req->actual != req->length)
1128 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1128 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
1129 req->status, req->actual, req->length); 1129 req->status, req->actual, req->length);
1130 if (req->status == -ECONNRESET) // Request was cancelled 1130 if (req->status == -ECONNRESET) // Request was cancelled
1131 usb_ep_fifo_flush(ep); 1131 usb_ep_fifo_flush(ep);
@@ -1146,7 +1146,7 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
1146 1146
1147 dump_msg(fsg, "bulk-out", req->buf, req->actual); 1147 dump_msg(fsg, "bulk-out", req->buf, req->actual);
1148 if (req->status || req->actual != bh->bulk_out_intended_length) 1148 if (req->status || req->actual != bh->bulk_out_intended_length)
1149 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1149 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
1150 req->status, req->actual, 1150 req->status, req->actual,
1151 bh->bulk_out_intended_length); 1151 bh->bulk_out_intended_length);
1152 if (req->status == -ECONNRESET) // Request was cancelled 1152 if (req->status == -ECONNRESET) // Request was cancelled
@@ -1169,7 +1169,7 @@ static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
1169 struct fsg_buffhd *bh = req->context; 1169 struct fsg_buffhd *bh = req->context;
1170 1170
1171 if (req->status || req->actual != req->length) 1171 if (req->status || req->actual != req->length)
1172 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1172 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
1173 req->status, req->actual, req->length); 1173 req->status, req->actual, req->length);
1174 if (req->status == -ECONNRESET) // Request was cancelled 1174 if (req->status == -ECONNRESET) // Request was cancelled
1175 usb_ep_fifo_flush(ep); 1175 usb_ep_fifo_flush(ep);
@@ -2307,6 +2307,29 @@ static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
2307 return rc; 2307 return rc;
2308} 2308}
2309 2309
2310static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
2311{
2312 int rc;
2313
2314 DBG(fsg, "bulk-in set wedge\n");
2315 rc = usb_ep_set_wedge(fsg->bulk_in);
2316 if (rc == -EAGAIN)
2317 VDBG(fsg, "delayed bulk-in endpoint wedge\n");
2318 while (rc != 0) {
2319 if (rc != -EAGAIN) {
2320 WARN(fsg, "usb_ep_set_wedge -> %d\n", rc);
2321 rc = 0;
2322 break;
2323 }
2324
2325 /* Wait for a short time and then try again */
2326 if (msleep_interruptible(100) != 0)
2327 return -EINTR;
2328 rc = usb_ep_set_wedge(fsg->bulk_in);
2329 }
2330 return rc;
2331}
2332
2310static int pad_with_zeros(struct fsg_dev *fsg) 2333static int pad_with_zeros(struct fsg_dev *fsg)
2311{ 2334{
2312 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill; 2335 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
@@ -2936,8 +2959,8 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2936 struct usb_request *req = bh->outreq; 2959 struct usb_request *req = bh->outreq;
2937 struct bulk_cb_wrap *cbw = req->buf; 2960 struct bulk_cb_wrap *cbw = req->buf;
2938 2961
2939 /* Was this a real packet? */ 2962 /* Was this a real packet? Should it be ignored? */
2940 if (req->status) 2963 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
2941 return -EINVAL; 2964 return -EINVAL;
2942 2965
2943 /* Is the CBW valid? */ 2966 /* Is the CBW valid? */
@@ -2948,13 +2971,17 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2948 req->actual, 2971 req->actual,
2949 le32_to_cpu(cbw->Signature)); 2972 le32_to_cpu(cbw->Signature));
2950 2973
2951 /* The Bulk-only spec says we MUST stall the bulk pipes! 2974 /* The Bulk-only spec says we MUST stall the IN endpoint
2952 * If we want to avoid stalls, set a flag so that we will 2975 * (6.6.1), so it's unavoidable. It also says we must
2953 * clear the endpoint halts at the next reset. */ 2976 * retain this state until the next reset, but there's
2954 if (!mod_data.can_stall) 2977 * no way to tell the controller driver it should ignore
2955 set_bit(CLEAR_BULK_HALTS, &fsg->atomic_bitflags); 2978 * Clear-Feature(HALT) requests.
2956 fsg_set_halt(fsg, fsg->bulk_out); 2979 *
2957 halt_bulk_in_endpoint(fsg); 2980 * We aren't required to halt the OUT endpoint; instead
2981 * we can simply accept and discard any data received
2982 * until the next reset. */
2983 wedge_bulk_in_endpoint(fsg);
2984 set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2958 return -EINVAL; 2985 return -EINVAL;
2959 } 2986 }
2960 2987
@@ -3140,6 +3167,7 @@ reset:
3140 goto reset; 3167 goto reset;
3141 fsg->bulk_out_enabled = 1; 3168 fsg->bulk_out_enabled = 1;
3142 fsg->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); 3169 fsg->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize);
3170 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
3143 3171
3144 if (transport_is_cbi()) { 3172 if (transport_is_cbi()) {
3145 d = ep_desc(fsg->gadget, &fs_intr_in_desc, &hs_intr_in_desc); 3173 d = ep_desc(fsg->gadget, &fs_intr_in_desc, &hs_intr_in_desc);
@@ -3321,11 +3349,8 @@ static void handle_exception(struct fsg_dev *fsg)
3321 /* In case we were forced against our will to halt a 3349 /* In case we were forced against our will to halt a
3322 * bulk endpoint, clear the halt now. (The SuperH UDC 3350 * bulk endpoint, clear the halt now. (The SuperH UDC
3323 * requires this.) */ 3351 * requires this.) */
3324 if (test_and_clear_bit(CLEAR_BULK_HALTS, 3352 if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
3325 &fsg->atomic_bitflags)) {
3326 usb_ep_clear_halt(fsg->bulk_in); 3353 usb_ep_clear_halt(fsg->bulk_in);
3327 usb_ep_clear_halt(fsg->bulk_out);
3328 }
3329 3354
3330 if (transport_is_bbb()) { 3355 if (transport_is_bbb()) {
3331 if (fsg->ep0_req_tag == exception_req_tag) 3356 if (fsg->ep0_req_tag == exception_req_tag)
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index 63e8fa3a69e1..18687543d7fa 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -773,11 +773,11 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
773 /* catch various bogus parameters */ 773 /* catch various bogus parameters */
774 if (!_req || !req->req.complete || !req->req.buf 774 if (!_req || !req->req.complete || !req->req.buf
775 || !list_empty(&req->queue)) { 775 || !list_empty(&req->queue)) {
776 VDBG("%s, bad params\n", __FUNCTION__); 776 VDBG("%s, bad params\n", __func__);
777 return -EINVAL; 777 return -EINVAL;
778 } 778 }
779 if (unlikely(!_ep || !ep->desc)) { 779 if (unlikely(!_ep || !ep->desc)) {
780 VDBG("%s, bad ep\n", __FUNCTION__); 780 VDBG("%s, bad ep\n", __func__);
781 return -EINVAL; 781 return -EINVAL;
782 } 782 }
783 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 783 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
@@ -1627,7 +1627,9 @@ static int reset_queues(struct fsl_udc *udc)
1627 udc_reset_ep_queue(udc, pipe); 1627 udc_reset_ep_queue(udc, pipe);
1628 1628
1629 /* report disconnect; the driver is already quiesced */ 1629 /* report disconnect; the driver is already quiesced */
1630 spin_unlock(&udc->lock);
1630 udc->driver->disconnect(&udc->gadget); 1631 udc->driver->disconnect(&udc->gadget);
1632 spin_lock(&udc->lock);
1631 1633
1632 return 0; 1634 return 0;
1633} 1635}
@@ -2475,3 +2477,4 @@ module_exit(udc_exit);
2475MODULE_DESCRIPTION(DRIVER_DESC); 2477MODULE_DESCRIPTION(DRIVER_DESC);
2476MODULE_AUTHOR(DRIVER_AUTHOR); 2478MODULE_AUTHOR(DRIVER_AUTHOR);
2477MODULE_LICENSE("GPL"); 2479MODULE_LICENSE("GPL");
2480MODULE_ALIAS("platform:fsl-usb2-udc");
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 9fb0b1ec8526..98b1483ef6a5 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -512,7 +512,7 @@ struct fsl_udc {
512 512
513#ifdef DEBUG 513#ifdef DEBUG
514#define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt "\n", \ 514#define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt "\n", \
515 __FUNCTION__, ## args) 515 __func__, ## args)
516#else 516#else
517#define DBG(fmt, args...) do{}while(0) 517#define DBG(fmt, args...) do{}while(0)
518#endif 518#endif
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 5b42ccd0035f..7f4d4828e3aa 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -229,7 +229,7 @@ static const struct usb_ac_header_descriptor_1 ac_header_desc = {
229 .bDescriptorType = USB_DT_CS_INTERFACE, 229 .bDescriptorType = USB_DT_CS_INTERFACE,
230 .bDescriptorSubtype = USB_MS_HEADER, 230 .bDescriptorSubtype = USB_MS_HEADER,
231 .bcdADC = __constant_cpu_to_le16(0x0100), 231 .bcdADC = __constant_cpu_to_le16(0x0100),
232 .wTotalLength = USB_DT_AC_HEADER_SIZE(1), 232 .wTotalLength = __constant_cpu_to_le16(USB_DT_AC_HEADER_SIZE(1)),
233 .bInCollection = 1, 233 .bInCollection = 1,
234 .baInterfaceNr = { 234 .baInterfaceNr = {
235 [0] = GMIDI_MS_INTERFACE, 235 [0] = GMIDI_MS_INTERFACE,
@@ -253,9 +253,9 @@ static const struct usb_ms_header_descriptor ms_header_desc = {
253 .bDescriptorType = USB_DT_CS_INTERFACE, 253 .bDescriptorType = USB_DT_CS_INTERFACE,
254 .bDescriptorSubtype = USB_MS_HEADER, 254 .bDescriptorSubtype = USB_MS_HEADER,
255 .bcdMSC = __constant_cpu_to_le16(0x0100), 255 .bcdMSC = __constant_cpu_to_le16(0x0100),
256 .wTotalLength = USB_DT_MS_HEADER_SIZE 256 .wTotalLength = __constant_cpu_to_le16(USB_DT_MS_HEADER_SIZE
257 + 2*USB_DT_MIDI_IN_SIZE 257 + 2*USB_DT_MIDI_IN_SIZE
258 + 2*USB_DT_MIDI_OUT_SIZE(1), 258 + 2*USB_DT_MIDI_OUT_SIZE(1)),
259}; 259};
260 260
261#define JACK_IN_EMB 1 261#define JACK_IN_EMB 1
@@ -1149,7 +1149,7 @@ fail:
1149/* 1149/*
1150 * Creates an output endpoint, and initializes output ports. 1150 * Creates an output endpoint, and initializes output ports.
1151 */ 1151 */
1152static int __devinit gmidi_bind(struct usb_gadget *gadget) 1152static int __init gmidi_bind(struct usb_gadget *gadget)
1153{ 1153{
1154 struct gmidi_device *dev; 1154 struct gmidi_device *dev;
1155 struct usb_ep *in_ep, *out_ep; 1155 struct usb_ep *in_ep, *out_ep;
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index d3e702576de6..be6613afedbf 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -127,7 +127,7 @@ goku_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
127 127
128 /* enabling the no-toggle interrupt mode would need an api hook */ 128 /* enabling the no-toggle interrupt mode would need an api hook */
129 mode = 0; 129 mode = 0;
130 max = le16_to_cpu(get_unaligned(&desc->wMaxPacketSize)); 130 max = get_unaligned_le16(&desc->wMaxPacketSize);
131 switch (max) { 131 switch (max) {
132 case 64: mode++; 132 case 64: mode++;
133 case 32: mode++; 133 case 32: mode++;
@@ -692,7 +692,7 @@ static void abort_dma(struct goku_ep *ep, int status)
692 req->req.actual = (curr - req->req.dma) + 1; 692 req->req.actual = (curr - req->req.dma) + 1;
693 req->req.status = status; 693 req->req.status = status;
694 694
695 VDBG(ep->dev, "%s %s %s %d/%d\n", __FUNCTION__, ep->ep.name, 695 VDBG(ep->dev, "%s %s %s %d/%d\n", __func__, ep->ep.name,
696 ep->is_in ? "IN" : "OUT", 696 ep->is_in ? "IN" : "OUT",
697 req->req.actual, req->req.length); 697 req->req.actual, req->req.length);
698 698
@@ -826,7 +826,7 @@ static int goku_dequeue(struct usb_ep *_ep, struct usb_request *_req)
826 if (dev->ep0state == EP0_SUSPEND) 826 if (dev->ep0state == EP0_SUSPEND)
827 return -EBUSY; 827 return -EBUSY;
828 828
829 VDBG(dev, "%s %s %s %s %p\n", __FUNCTION__, _ep->name, 829 VDBG(dev, "%s %s %s %s %p\n", __func__, _ep->name,
830 ep->is_in ? "IN" : "OUT", 830 ep->is_in ? "IN" : "OUT",
831 ep->dma ? "dma" : "pio", 831 ep->dma ? "dma" : "pio",
832 _req); 832 _req);
@@ -898,7 +898,7 @@ static int goku_set_halt(struct usb_ep *_ep, int value)
898 898
899 /* don't change EPxSTATUS_EP_INVALID to READY */ 899 /* don't change EPxSTATUS_EP_INVALID to READY */
900 } else if (!ep->desc) { 900 } else if (!ep->desc) {
901 DBG(ep->dev, "%s %s inactive?\n", __FUNCTION__, ep->ep.name); 901 DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name);
902 return -EINVAL; 902 return -EINVAL;
903 } 903 }
904 904
@@ -940,7 +940,7 @@ static int goku_fifo_status(struct usb_ep *_ep)
940 regs = ep->dev->regs; 940 regs = ep->dev->regs;
941 size = readl(&regs->EPxSizeLA[ep->num]) & DATASIZE; 941 size = readl(&regs->EPxSizeLA[ep->num]) & DATASIZE;
942 size += readl(&regs->EPxSizeLB[ep->num]) & DATASIZE; 942 size += readl(&regs->EPxSizeLB[ep->num]) & DATASIZE;
943 VDBG(ep->dev, "%s %s %u\n", __FUNCTION__, ep->ep.name, size); 943 VDBG(ep->dev, "%s %s %u\n", __func__, ep->ep.name, size);
944 return size; 944 return size;
945} 945}
946 946
@@ -953,11 +953,11 @@ static void goku_fifo_flush(struct usb_ep *_ep)
953 if (!_ep) 953 if (!_ep)
954 return; 954 return;
955 ep = container_of(_ep, struct goku_ep, ep); 955 ep = container_of(_ep, struct goku_ep, ep);
956 VDBG(ep->dev, "%s %s\n", __FUNCTION__, ep->ep.name); 956 VDBG(ep->dev, "%s %s\n", __func__, ep->ep.name);
957 957
958 /* don't change EPxSTATUS_EP_INVALID to READY */ 958 /* don't change EPxSTATUS_EP_INVALID to READY */
959 if (!ep->desc && ep->num != 0) { 959 if (!ep->desc && ep->num != 0) {
960 DBG(ep->dev, "%s %s inactive?\n", __FUNCTION__, ep->ep.name); 960 DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name);
961 return; 961 return;
962 } 962 }
963 963
@@ -1286,7 +1286,7 @@ static void ep0_start(struct goku_udc *dev)
1286 struct goku_udc_regs __iomem *regs = dev->regs; 1286 struct goku_udc_regs __iomem *regs = dev->regs;
1287 unsigned i; 1287 unsigned i;
1288 1288
1289 VDBG(dev, "%s\n", __FUNCTION__); 1289 VDBG(dev, "%s\n", __func__);
1290 1290
1291 udc_reset(dev); 1291 udc_reset(dev);
1292 udc_reinit (dev); 1292 udc_reinit (dev);
@@ -1322,7 +1322,7 @@ static void udc_enable(struct goku_udc *dev)
1322 if (readl(&dev->regs->power_detect) & PW_DETECT) 1322 if (readl(&dev->regs->power_detect) & PW_DETECT)
1323 ep0_start(dev); 1323 ep0_start(dev);
1324 else { 1324 else {
1325 DBG(dev, "%s\n", __FUNCTION__); 1325 DBG(dev, "%s\n", __func__);
1326 dev->int_enable = INT_PWRDETECT; 1326 dev->int_enable = INT_PWRDETECT;
1327 writel(dev->int_enable, &dev->regs->int_enable); 1327 writel(dev->int_enable, &dev->regs->int_enable);
1328 } 1328 }
@@ -1387,7 +1387,7 @@ stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver)
1387{ 1387{
1388 unsigned i; 1388 unsigned i;
1389 1389
1390 DBG (dev, "%s\n", __FUNCTION__); 1390 DBG (dev, "%s\n", __func__);
1391 1391
1392 if (dev->gadget.speed == USB_SPEED_UNKNOWN) 1392 if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1393 driver = NULL; 1393 driver = NULL;
@@ -1726,7 +1726,7 @@ static void goku_remove(struct pci_dev *pdev)
1726{ 1726{
1727 struct goku_udc *dev = pci_get_drvdata(pdev); 1727 struct goku_udc *dev = pci_get_drvdata(pdev);
1728 1728
1729 DBG(dev, "%s\n", __FUNCTION__); 1729 DBG(dev, "%s\n", __func__);
1730 1730
1731 BUG_ON(dev->driver); 1731 BUG_ON(dev->driver);
1732 1732
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 0a6feafc8d28..69b0a2754f2a 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1107,13 +1107,13 @@ scan:
1107 1107
1108 switch (state) { 1108 switch (state) {
1109 default: 1109 default:
1110 DBG (dev, "fail %s, state %d\n", __FUNCTION__, state); 1110 DBG (dev, "fail %s, state %d\n", __func__, state);
1111 retval = -ESRCH; 1111 retval = -ESRCH;
1112 break; 1112 break;
1113 case STATE_DEV_UNCONNECTED: 1113 case STATE_DEV_UNCONNECTED:
1114 case STATE_DEV_CONNECTED: 1114 case STATE_DEV_CONNECTED:
1115 spin_unlock_irq (&dev->lock); 1115 spin_unlock_irq (&dev->lock);
1116 DBG (dev, "%s wait\n", __FUNCTION__); 1116 DBG (dev, "%s wait\n", __func__);
1117 1117
1118 /* wait for events */ 1118 /* wait for events */
1119 retval = wait_event_interruptible (dev->wait, 1119 retval = wait_event_interruptible (dev->wait,
@@ -1222,7 +1222,7 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1222 DBG(dev, "bogus ep0out stall!\n"); 1222 DBG(dev, "bogus ep0out stall!\n");
1223 } 1223 }
1224 } else 1224 } else
1225 DBG (dev, "fail %s, state %d\n", __FUNCTION__, dev->state); 1225 DBG (dev, "fail %s, state %d\n", __func__, dev->state);
1226 1226
1227 spin_unlock_irq (&dev->lock); 1227 spin_unlock_irq (&dev->lock);
1228 return retval; 1228 return retval;
@@ -1233,7 +1233,7 @@ ep0_fasync (int f, struct file *fd, int on)
1233{ 1233{
1234 struct dev_data *dev = fd->private_data; 1234 struct dev_data *dev = fd->private_data;
1235 // caller must F_SETOWN before signal delivery happens 1235 // caller must F_SETOWN before signal delivery happens
1236 VDEBUG (dev, "%s %s\n", __FUNCTION__, on ? "on" : "off"); 1236 VDEBUG (dev, "%s %s\n", __func__, on ? "on" : "off");
1237 return fasync_helper (f, fd, on, &dev->fasync); 1237 return fasync_helper (f, fd, on, &dev->fasync);
1238} 1238}
1239 1239
@@ -1575,7 +1575,7 @@ static void destroy_ep_files (struct dev_data *dev)
1575{ 1575{
1576 struct list_head *entry, *tmp; 1576 struct list_head *entry, *tmp;
1577 1577
1578 DBG (dev, "%s %d\n", __FUNCTION__, dev->state); 1578 DBG (dev, "%s %d\n", __func__, dev->state);
1579 1579
1580 /* dev->state must prevent interference */ 1580 /* dev->state must prevent interference */
1581restart: 1581restart:
@@ -1662,7 +1662,7 @@ enomem1:
1662 put_dev (dev); 1662 put_dev (dev);
1663 kfree (data); 1663 kfree (data);
1664enomem0: 1664enomem0:
1665 DBG (dev, "%s enomem\n", __FUNCTION__); 1665 DBG (dev, "%s enomem\n", __func__);
1666 destroy_ep_files (dev); 1666 destroy_ep_files (dev);
1667 return -ENOMEM; 1667 return -ENOMEM;
1668} 1668}
@@ -1672,7 +1672,7 @@ gadgetfs_unbind (struct usb_gadget *gadget)
1672{ 1672{
1673 struct dev_data *dev = get_gadget_data (gadget); 1673 struct dev_data *dev = get_gadget_data (gadget);
1674 1674
1675 DBG (dev, "%s\n", __FUNCTION__); 1675 DBG (dev, "%s\n", __func__);
1676 1676
1677 spin_lock_irq (&dev->lock); 1677 spin_lock_irq (&dev->lock);
1678 dev->state = STATE_DEV_UNBOUND; 1678 dev->state = STATE_DEV_UNBOUND;
@@ -1685,7 +1685,7 @@ gadgetfs_unbind (struct usb_gadget *gadget)
1685 /* we've already been disconnected ... no i/o is active */ 1685 /* we've already been disconnected ... no i/o is active */
1686 if (dev->req) 1686 if (dev->req)
1687 usb_ep_free_request (gadget->ep0, dev->req); 1687 usb_ep_free_request (gadget->ep0, dev->req);
1688 DBG (dev, "%s done\n", __FUNCTION__); 1688 DBG (dev, "%s done\n", __func__);
1689 put_dev (dev); 1689 put_dev (dev);
1690} 1690}
1691 1691
@@ -1933,7 +1933,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1933 1933
1934fail: 1934fail:
1935 spin_unlock_irq (&dev->lock); 1935 spin_unlock_irq (&dev->lock);
1936 pr_debug ("%s: %s fail %Zd, %p\n", shortname, __FUNCTION__, value, dev); 1936 pr_debug ("%s: %s fail %Zd, %p\n", shortname, __func__, value, dev);
1937 kfree (dev->buf); 1937 kfree (dev->buf);
1938 dev->buf = NULL; 1938 dev->buf = NULL;
1939 return value; 1939 return value;
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 37243ef7104e..825abd2621b3 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -253,7 +253,7 @@ udc_proc_read(char *page, char **start, off_t off, int count,
253 */ 253 */
254static void udc_disable(struct lh7a40x_udc *dev) 254static void udc_disable(struct lh7a40x_udc *dev)
255{ 255{
256 DEBUG("%s, %p\n", __FUNCTION__, dev); 256 DEBUG("%s, %p\n", __func__, dev);
257 257
258 udc_set_address(dev, 0); 258 udc_set_address(dev, 0);
259 259
@@ -285,7 +285,7 @@ static void udc_reinit(struct lh7a40x_udc *dev)
285{ 285{
286 u32 i; 286 u32 i;
287 287
288 DEBUG("%s, %p\n", __FUNCTION__, dev); 288 DEBUG("%s, %p\n", __func__, dev);
289 289
290 /* device/ep0 records init */ 290 /* device/ep0 records init */
291 INIT_LIST_HEAD(&dev->gadget.ep_list); 291 INIT_LIST_HEAD(&dev->gadget.ep_list);
@@ -318,7 +318,7 @@ static void udc_enable(struct lh7a40x_udc *dev)
318{ 318{
319 int ep; 319 int ep;
320 320
321 DEBUG("%s, %p\n", __FUNCTION__, dev); 321 DEBUG("%s, %p\n", __func__, dev);
322 322
323 dev->gadget.speed = USB_SPEED_UNKNOWN; 323 dev->gadget.speed = USB_SPEED_UNKNOWN;
324 324
@@ -412,7 +412,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
412 struct lh7a40x_udc *dev = the_controller; 412 struct lh7a40x_udc *dev = the_controller;
413 int retval; 413 int retval;
414 414
415 DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name); 415 DEBUG("%s: %s\n", __func__, driver->driver.name);
416 416
417 if (!driver 417 if (!driver
418 || driver->speed != USB_SPEED_FULL 418 || driver->speed != USB_SPEED_FULL
@@ -521,7 +521,7 @@ static int write_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
521 is_short = unlikely(max < ep_maxpacket(ep)); 521 is_short = unlikely(max < ep_maxpacket(ep));
522 } 522 }
523 523
524 DEBUG("%s: wrote %s %d bytes%s%s %d left %p\n", __FUNCTION__, 524 DEBUG("%s: wrote %s %d bytes%s%s %d left %p\n", __func__,
525 ep->ep.name, count, 525 ep->ep.name, count,
526 is_last ? "/L" : "", is_short ? "/S" : "", 526 is_last ? "/L" : "", is_short ? "/S" : "",
527 req->req.length - req->req.actual, req); 527 req->req.length - req->req.actual, req);
@@ -555,7 +555,7 @@ static int read_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
555 /* make sure there's a packet in the FIFO. */ 555 /* make sure there's a packet in the FIFO. */
556 csr = usb_read(ep->csr1); 556 csr = usb_read(ep->csr1);
557 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY)) { 557 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY)) {
558 DEBUG("%s: Packet NOT ready!\n", __FUNCTION__); 558 DEBUG("%s: Packet NOT ready!\n", __func__);
559 return -EINVAL; 559 return -EINVAL;
560 } 560 }
561 561
@@ -614,7 +614,7 @@ static void done(struct lh7a40x_ep *ep, struct lh7a40x_request *req, int status)
614 unsigned int stopped = ep->stopped; 614 unsigned int stopped = ep->stopped;
615 u32 index; 615 u32 index;
616 616
617 DEBUG("%s, %p\n", __FUNCTION__, ep); 617 DEBUG("%s, %p\n", __func__, ep);
618 list_del_init(&req->queue); 618 list_del_init(&req->queue);
619 619
620 if (likely(req->req.status == -EINPROGRESS)) 620 if (likely(req->req.status == -EINPROGRESS))
@@ -644,7 +644,7 @@ static void done(struct lh7a40x_ep *ep, struct lh7a40x_request *req, int status)
644/** Enable EP interrupt */ 644/** Enable EP interrupt */
645static void pio_irq_enable(int ep) 645static void pio_irq_enable(int ep)
646{ 646{
647 DEBUG("%s: %d\n", __FUNCTION__, ep); 647 DEBUG("%s: %d\n", __func__, ep);
648 648
649 switch (ep) { 649 switch (ep) {
650 case 1: 650 case 1:
@@ -665,7 +665,7 @@ static void pio_irq_enable(int ep)
665/** Disable EP interrupt */ 665/** Disable EP interrupt */
666static void pio_irq_disable(int ep) 666static void pio_irq_disable(int ep)
667{ 667{
668 DEBUG("%s: %d\n", __FUNCTION__, ep); 668 DEBUG("%s: %d\n", __func__, ep);
669 669
670 switch (ep) { 670 switch (ep) {
671 case 1: 671 case 1:
@@ -690,7 +690,7 @@ void nuke(struct lh7a40x_ep *ep, int status)
690{ 690{
691 struct lh7a40x_request *req; 691 struct lh7a40x_request *req;
692 692
693 DEBUG("%s, %p\n", __FUNCTION__, ep); 693 DEBUG("%s, %p\n", __func__, ep);
694 694
695 /* Flush FIFO */ 695 /* Flush FIFO */
696 flush(ep); 696 flush(ep);
@@ -734,7 +734,7 @@ static void flush_all(struct lh7a40x_udc *dev)
734 */ 734 */
735static void flush(struct lh7a40x_ep *ep) 735static void flush(struct lh7a40x_ep *ep)
736{ 736{
737 DEBUG("%s, %p\n", __FUNCTION__, ep); 737 DEBUG("%s, %p\n", __func__, ep);
738 738
739 switch (ep->ep_type) { 739 switch (ep->ep_type) {
740 case ep_control: 740 case ep_control:
@@ -766,7 +766,7 @@ static void lh7a40x_in_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
766 usb_set_index(ep_idx); 766 usb_set_index(ep_idx);
767 767
768 csr = usb_read(ep->csr1); 768 csr = usb_read(ep->csr1);
769 DEBUG("%s: %d, csr %x\n", __FUNCTION__, ep_idx, csr); 769 DEBUG("%s: %d, csr %x\n", __func__, ep_idx, csr);
770 770
771 if (csr & USB_IN_CSR1_SENT_STALL) { 771 if (csr & USB_IN_CSR1_SENT_STALL) {
772 DEBUG("USB_IN_CSR1_SENT_STALL\n"); 772 DEBUG("USB_IN_CSR1_SENT_STALL\n");
@@ -776,7 +776,7 @@ static void lh7a40x_in_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
776 } 776 }
777 777
778 if (!ep->desc) { 778 if (!ep->desc) {
779 DEBUG("%s: NO EP DESC\n", __FUNCTION__); 779 DEBUG("%s: NO EP DESC\n", __func__);
780 return; 780 return;
781 } 781 }
782 782
@@ -802,7 +802,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
802 struct lh7a40x_ep *ep = &dev->ep[ep_idx]; 802 struct lh7a40x_ep *ep = &dev->ep[ep_idx];
803 struct lh7a40x_request *req; 803 struct lh7a40x_request *req;
804 804
805 DEBUG("%s: %d\n", __FUNCTION__, ep_idx); 805 DEBUG("%s: %d\n", __func__, ep_idx);
806 806
807 usb_set_index(ep_idx); 807 usb_set_index(ep_idx);
808 808
@@ -814,11 +814,11 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
814 usb_read(ep-> 814 usb_read(ep->
815 csr1)) & (USB_OUT_CSR1_OUT_PKT_RDY | 815 csr1)) & (USB_OUT_CSR1_OUT_PKT_RDY |
816 USB_OUT_CSR1_SENT_STALL)) { 816 USB_OUT_CSR1_SENT_STALL)) {
817 DEBUG("%s: %x\n", __FUNCTION__, csr); 817 DEBUG("%s: %x\n", __func__, csr);
818 818
819 if (csr & USB_OUT_CSR1_SENT_STALL) { 819 if (csr & USB_OUT_CSR1_SENT_STALL) {
820 DEBUG("%s: stall sent, flush fifo\n", 820 DEBUG("%s: stall sent, flush fifo\n",
821 __FUNCTION__); 821 __func__);
822 /* usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1); */ 822 /* usb_set(USB_OUT_CSR1_FIFO_FLUSH, ep->csr1); */
823 flush(ep); 823 flush(ep);
824 } else if (csr & USB_OUT_CSR1_OUT_PKT_RDY) { 824 } else if (csr & USB_OUT_CSR1_OUT_PKT_RDY) {
@@ -832,7 +832,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
832 832
833 if (!req) { 833 if (!req) {
834 printk("%s: NULL REQ %d\n", 834 printk("%s: NULL REQ %d\n",
835 __FUNCTION__, ep_idx); 835 __func__, ep_idx);
836 flush(ep); 836 flush(ep);
837 break; 837 break;
838 } else { 838 } else {
@@ -844,7 +844,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
844 844
845 } else { 845 } else {
846 /* Throw packet away.. */ 846 /* Throw packet away.. */
847 printk("%s: No descriptor?!?\n", __FUNCTION__); 847 printk("%s: No descriptor?!?\n", __func__);
848 flush(ep); 848 flush(ep);
849 } 849 }
850} 850}
@@ -886,7 +886,7 @@ static void lh7a40x_reset_intr(struct lh7a40x_udc *dev)
886#if 0 /* def CONFIG_ARCH_LH7A404 */ 886#if 0 /* def CONFIG_ARCH_LH7A404 */
887 /* Does not work always... */ 887 /* Does not work always... */
888 888
889 DEBUG("%s: %d\n", __FUNCTION__, dev->usb_address); 889 DEBUG("%s: %d\n", __func__, dev->usb_address);
890 890
891 if (!dev->usb_address) { 891 if (!dev->usb_address) {
892 /*usb_set(USB_RESET_IO, USB_RESET); 892 /*usb_set(USB_RESET_IO, USB_RESET);
@@ -936,7 +936,7 @@ static irqreturn_t lh7a40x_udc_irq(int irq, void *_dev)
936 if (!intr_out && !intr_in && !intr_int) 936 if (!intr_out && !intr_in && !intr_int)
937 break; 937 break;
938 938
939 DEBUG("%s (on state %s)\n", __FUNCTION__, 939 DEBUG("%s (on state %s)\n", __func__,
940 state_names[dev->ep0state]); 940 state_names[dev->ep0state]);
941 DEBUG("intr_out = %x\n", intr_out); 941 DEBUG("intr_out = %x\n", intr_out);
942 DEBUG("intr_in = %x\n", intr_in); 942 DEBUG("intr_in = %x\n", intr_in);
@@ -1016,14 +1016,14 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
1016 struct lh7a40x_udc *dev; 1016 struct lh7a40x_udc *dev;
1017 unsigned long flags; 1017 unsigned long flags;
1018 1018
1019 DEBUG("%s, %p\n", __FUNCTION__, _ep); 1019 DEBUG("%s, %p\n", __func__, _ep);
1020 1020
1021 ep = container_of(_ep, struct lh7a40x_ep, ep); 1021 ep = container_of(_ep, struct lh7a40x_ep, ep);
1022 if (!_ep || !desc || ep->desc || _ep->name == ep0name 1022 if (!_ep || !desc || ep->desc || _ep->name == ep0name
1023 || desc->bDescriptorType != USB_DT_ENDPOINT 1023 || desc->bDescriptorType != USB_DT_ENDPOINT
1024 || ep->bEndpointAddress != desc->bEndpointAddress 1024 || ep->bEndpointAddress != desc->bEndpointAddress
1025 || ep_maxpacket(ep) < le16_to_cpu(desc->wMaxPacketSize)) { 1025 || ep_maxpacket(ep) < le16_to_cpu(desc->wMaxPacketSize)) {
1026 DEBUG("%s, bad ep or descriptor\n", __FUNCTION__); 1026 DEBUG("%s, bad ep or descriptor\n", __func__);
1027 return -EINVAL; 1027 return -EINVAL;
1028 } 1028 }
1029 1029
@@ -1031,7 +1031,7 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
1031 if (ep->bmAttributes != desc->bmAttributes 1031 if (ep->bmAttributes != desc->bmAttributes
1032 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK 1032 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
1033 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { 1033 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
1034 DEBUG("%s, %s type mismatch\n", __FUNCTION__, _ep->name); 1034 DEBUG("%s, %s type mismatch\n", __func__, _ep->name);
1035 return -EINVAL; 1035 return -EINVAL;
1036 } 1036 }
1037 1037
@@ -1039,13 +1039,13 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
1039 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 1039 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
1040 && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(ep)) 1040 && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(ep))
1041 || !desc->wMaxPacketSize) { 1041 || !desc->wMaxPacketSize) {
1042 DEBUG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 1042 DEBUG("%s, bad %s maxpacket\n", __func__, _ep->name);
1043 return -ERANGE; 1043 return -ERANGE;
1044 } 1044 }
1045 1045
1046 dev = ep->dev; 1046 dev = ep->dev;
1047 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { 1047 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
1048 DEBUG("%s, bogus device state\n", __FUNCTION__); 1048 DEBUG("%s, bogus device state\n", __func__);
1049 return -ESHUTDOWN; 1049 return -ESHUTDOWN;
1050 } 1050 }
1051 1051
@@ -1061,7 +1061,7 @@ static int lh7a40x_ep_enable(struct usb_ep *_ep,
1061 /* Reset halt state (does flush) */ 1061 /* Reset halt state (does flush) */
1062 lh7a40x_set_halt(_ep, 0); 1062 lh7a40x_set_halt(_ep, 0);
1063 1063
1064 DEBUG("%s: enabled %s\n", __FUNCTION__, _ep->name); 1064 DEBUG("%s: enabled %s\n", __func__, _ep->name);
1065 return 0; 1065 return 0;
1066} 1066}
1067 1067
@@ -1073,11 +1073,11 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
1073 struct lh7a40x_ep *ep; 1073 struct lh7a40x_ep *ep;
1074 unsigned long flags; 1074 unsigned long flags;
1075 1075
1076 DEBUG("%s, %p\n", __FUNCTION__, _ep); 1076 DEBUG("%s, %p\n", __func__, _ep);
1077 1077
1078 ep = container_of(_ep, struct lh7a40x_ep, ep); 1078 ep = container_of(_ep, struct lh7a40x_ep, ep);
1079 if (!_ep || !ep->desc) { 1079 if (!_ep || !ep->desc) {
1080 DEBUG("%s, %s not enabled\n", __FUNCTION__, 1080 DEBUG("%s, %s not enabled\n", __func__,
1081 _ep ? ep->ep.name : NULL); 1081 _ep ? ep->ep.name : NULL);
1082 return -EINVAL; 1082 return -EINVAL;
1083 } 1083 }
@@ -1097,7 +1097,7 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
1097 1097
1098 spin_unlock_irqrestore(&ep->dev->lock, flags); 1098 spin_unlock_irqrestore(&ep->dev->lock, flags);
1099 1099
1100 DEBUG("%s: disabled %s\n", __FUNCTION__, _ep->name); 1100 DEBUG("%s: disabled %s\n", __func__, _ep->name);
1101 return 0; 1101 return 0;
1102} 1102}
1103 1103
@@ -1106,7 +1106,7 @@ static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep,
1106{ 1106{
1107 struct lh7a40x_request *req; 1107 struct lh7a40x_request *req;
1108 1108
1109 DEBUG("%s, %p\n", __FUNCTION__, ep); 1109 DEBUG("%s, %p\n", __func__, ep);
1110 1110
1111 req = kzalloc(sizeof(*req), gfp_flags); 1111 req = kzalloc(sizeof(*req), gfp_flags);
1112 if (!req) 1112 if (!req)
@@ -1121,7 +1121,7 @@ static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *_req)
1121{ 1121{
1122 struct lh7a40x_request *req; 1122 struct lh7a40x_request *req;
1123 1123
1124 DEBUG("%s, %p\n", __FUNCTION__, ep); 1124 DEBUG("%s, %p\n", __func__, ep);
1125 1125
1126 req = container_of(_req, struct lh7a40x_request, req); 1126 req = container_of(_req, struct lh7a40x_request, req);
1127 WARN_ON(!list_empty(&req->queue)); 1127 WARN_ON(!list_empty(&req->queue));
@@ -1140,25 +1140,25 @@ static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req,
1140 struct lh7a40x_udc *dev; 1140 struct lh7a40x_udc *dev;
1141 unsigned long flags; 1141 unsigned long flags;
1142 1142
1143 DEBUG("\n\n\n%s, %p\n", __FUNCTION__, _ep); 1143 DEBUG("\n\n\n%s, %p\n", __func__, _ep);
1144 1144
1145 req = container_of(_req, struct lh7a40x_request, req); 1145 req = container_of(_req, struct lh7a40x_request, req);
1146 if (unlikely 1146 if (unlikely
1147 (!_req || !_req->complete || !_req->buf 1147 (!_req || !_req->complete || !_req->buf
1148 || !list_empty(&req->queue))) { 1148 || !list_empty(&req->queue))) {
1149 DEBUG("%s, bad params\n", __FUNCTION__); 1149 DEBUG("%s, bad params\n", __func__);
1150 return -EINVAL; 1150 return -EINVAL;
1151 } 1151 }
1152 1152
1153 ep = container_of(_ep, struct lh7a40x_ep, ep); 1153 ep = container_of(_ep, struct lh7a40x_ep, ep);
1154 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) { 1154 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1155 DEBUG("%s, bad ep\n", __FUNCTION__); 1155 DEBUG("%s, bad ep\n", __func__);
1156 return -EINVAL; 1156 return -EINVAL;
1157 } 1157 }
1158 1158
1159 dev = ep->dev; 1159 dev = ep->dev;
1160 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { 1160 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
1161 DEBUG("%s, bogus device state %p\n", __FUNCTION__, dev->driver); 1161 DEBUG("%s, bogus device state %p\n", __func__, dev->driver);
1162 return -ESHUTDOWN; 1162 return -ESHUTDOWN;
1163 } 1163 }
1164 1164
@@ -1218,7 +1218,7 @@ static int lh7a40x_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1218 struct lh7a40x_request *req; 1218 struct lh7a40x_request *req;
1219 unsigned long flags; 1219 unsigned long flags;
1220 1220
1221 DEBUG("%s, %p\n", __FUNCTION__, _ep); 1221 DEBUG("%s, %p\n", __func__, _ep);
1222 1222
1223 ep = container_of(_ep, struct lh7a40x_ep, ep); 1223 ep = container_of(_ep, struct lh7a40x_ep, ep);
1224 if (!_ep || ep->ep.name == ep0name) 1224 if (!_ep || ep->ep.name == ep0name)
@@ -1253,13 +1253,13 @@ static int lh7a40x_set_halt(struct usb_ep *_ep, int value)
1253 1253
1254 ep = container_of(_ep, struct lh7a40x_ep, ep); 1254 ep = container_of(_ep, struct lh7a40x_ep, ep);
1255 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) { 1255 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1256 DEBUG("%s, bad ep\n", __FUNCTION__); 1256 DEBUG("%s, bad ep\n", __func__);
1257 return -EINVAL; 1257 return -EINVAL;
1258 } 1258 }
1259 1259
1260 usb_set_index(ep_index(ep)); 1260 usb_set_index(ep_index(ep));
1261 1261
1262 DEBUG("%s, ep %d, val %d\n", __FUNCTION__, ep_index(ep), value); 1262 DEBUG("%s, ep %d, val %d\n", __func__, ep_index(ep), value);
1263 1263
1264 spin_lock_irqsave(&ep->dev->lock, flags); 1264 spin_lock_irqsave(&ep->dev->lock, flags);
1265 1265
@@ -1325,11 +1325,11 @@ static int lh7a40x_fifo_status(struct usb_ep *_ep)
1325 1325
1326 ep = container_of(_ep, struct lh7a40x_ep, ep); 1326 ep = container_of(_ep, struct lh7a40x_ep, ep);
1327 if (!_ep) { 1327 if (!_ep) {
1328 DEBUG("%s, bad ep\n", __FUNCTION__); 1328 DEBUG("%s, bad ep\n", __func__);
1329 return -ENODEV; 1329 return -ENODEV;
1330 } 1330 }
1331 1331
1332 DEBUG("%s, %d\n", __FUNCTION__, ep_index(ep)); 1332 DEBUG("%s, %d\n", __func__, ep_index(ep));
1333 1333
1334 /* LPD can't report unclaimed bytes from IN fifos */ 1334 /* LPD can't report unclaimed bytes from IN fifos */
1335 if (ep_is_in(ep)) 1335 if (ep_is_in(ep))
@@ -1355,7 +1355,7 @@ static void lh7a40x_fifo_flush(struct usb_ep *_ep)
1355 1355
1356 ep = container_of(_ep, struct lh7a40x_ep, ep); 1356 ep = container_of(_ep, struct lh7a40x_ep, ep);
1357 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) { 1357 if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1358 DEBUG("%s, bad ep\n", __FUNCTION__); 1358 DEBUG("%s, bad ep\n", __func__);
1359 return; 1359 return;
1360 } 1360 }
1361 1361
@@ -1376,7 +1376,7 @@ static int write_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1376 1376
1377 max = ep_maxpacket(ep); 1377 max = ep_maxpacket(ep);
1378 1378
1379 DEBUG_EP0("%s\n", __FUNCTION__); 1379 DEBUG_EP0("%s\n", __func__);
1380 1380
1381 count = write_packet(ep, req, max); 1381 count = write_packet(ep, req, max);
1382 1382
@@ -1390,7 +1390,7 @@ static int write_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1390 is_last = 1; 1390 is_last = 1;
1391 } 1391 }
1392 1392
1393 DEBUG_EP0("%s: wrote %s %d bytes%s %d left %p\n", __FUNCTION__, 1393 DEBUG_EP0("%s: wrote %s %d bytes%s %d left %p\n", __func__,
1394 ep->ep.name, count, 1394 ep->ep.name, count,
1395 is_last ? "/L" : "", req->req.length - req->req.actual, req); 1395 is_last ? "/L" : "", req->req.length - req->req.actual, req);
1396 1396
@@ -1434,7 +1434,7 @@ static int read_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1434 unsigned bufferspace, count, is_short; 1434 unsigned bufferspace, count, is_short;
1435 volatile u32 *fifo = (volatile u32 *)ep->fifo; 1435 volatile u32 *fifo = (volatile u32 *)ep->fifo;
1436 1436
1437 DEBUG_EP0("%s\n", __FUNCTION__); 1437 DEBUG_EP0("%s\n", __func__);
1438 1438
1439 csr = usb_read(USB_EP0_CSR); 1439 csr = usb_read(USB_EP0_CSR);
1440 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY)) 1440 if (!(csr & USB_OUT_CSR1_OUT_PKT_RDY))
@@ -1492,7 +1492,7 @@ static int read_fifo_ep0(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
1492 */ 1492 */
1493static void udc_set_address(struct lh7a40x_udc *dev, unsigned char address) 1493static void udc_set_address(struct lh7a40x_udc *dev, unsigned char address)
1494{ 1494{
1495 DEBUG_EP0("%s: %d\n", __FUNCTION__, address); 1495 DEBUG_EP0("%s: %d\n", __func__, address);
1496 /* c.f. 15.1.2.2 Table 15-4 address will be used after DATA_END is set */ 1496 /* c.f. 15.1.2.2 Table 15-4 address will be used after DATA_END is set */
1497 dev->usb_address = address; 1497 dev->usb_address = address;
1498 usb_set((address & USB_FA_FUNCTION_ADDR), USB_FA); 1498 usb_set((address & USB_FA_FUNCTION_ADDR), USB_FA);
@@ -1514,7 +1514,7 @@ static void lh7a40x_ep0_out(struct lh7a40x_udc *dev, u32 csr)
1514 struct lh7a40x_ep *ep = &dev->ep[0]; 1514 struct lh7a40x_ep *ep = &dev->ep[0];
1515 int ret; 1515 int ret;
1516 1516
1517 DEBUG_EP0("%s: %x\n", __FUNCTION__, csr); 1517 DEBUG_EP0("%s: %x\n", __func__, csr);
1518 1518
1519 if (list_empty(&ep->queue)) 1519 if (list_empty(&ep->queue))
1520 req = 0; 1520 req = 0;
@@ -1533,13 +1533,13 @@ static void lh7a40x_ep0_out(struct lh7a40x_udc *dev, u32 csr)
1533 if (ret) { 1533 if (ret) {
1534 /* Done! */ 1534 /* Done! */
1535 DEBUG_EP0("%s: finished, waiting for status\n", 1535 DEBUG_EP0("%s: finished, waiting for status\n",
1536 __FUNCTION__); 1536 __func__);
1537 1537
1538 usb_set((EP0_CLR_OUT | EP0_DATA_END), USB_EP0_CSR); 1538 usb_set((EP0_CLR_OUT | EP0_DATA_END), USB_EP0_CSR);
1539 dev->ep0state = WAIT_FOR_SETUP; 1539 dev->ep0state = WAIT_FOR_SETUP;
1540 } else { 1540 } else {
1541 /* Not done yet.. */ 1541 /* Not done yet.. */
1542 DEBUG_EP0("%s: not finished\n", __FUNCTION__); 1542 DEBUG_EP0("%s: not finished\n", __func__);
1543 usb_set(EP0_CLR_OUT, USB_EP0_CSR); 1543 usb_set(EP0_CLR_OUT, USB_EP0_CSR);
1544 } 1544 }
1545 } else { 1545 } else {
@@ -1556,7 +1556,7 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
1556 struct lh7a40x_ep *ep = &dev->ep[0]; 1556 struct lh7a40x_ep *ep = &dev->ep[0];
1557 int ret, need_zlp = 0; 1557 int ret, need_zlp = 0;
1558 1558
1559 DEBUG_EP0("%s: %x\n", __FUNCTION__, csr); 1559 DEBUG_EP0("%s: %x\n", __func__, csr);
1560 1560
1561 if (list_empty(&ep->queue)) 1561 if (list_empty(&ep->queue))
1562 req = 0; 1562 req = 0;
@@ -1564,7 +1564,7 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
1564 req = list_entry(ep->queue.next, struct lh7a40x_request, queue); 1564 req = list_entry(ep->queue.next, struct lh7a40x_request, queue);
1565 1565
1566 if (!req) { 1566 if (!req) {
1567 DEBUG_EP0("%s: NULL REQ\n", __FUNCTION__); 1567 DEBUG_EP0("%s: NULL REQ\n", __func__);
1568 return 0; 1568 return 0;
1569 } 1569 }
1570 1570
@@ -1585,17 +1585,17 @@ static int lh7a40x_ep0_in(struct lh7a40x_udc *dev, u32 csr)
1585 1585
1586 if (ret == 1 && !need_zlp) { 1586 if (ret == 1 && !need_zlp) {
1587 /* Last packet */ 1587 /* Last packet */
1588 DEBUG_EP0("%s: finished, waiting for status\n", __FUNCTION__); 1588 DEBUG_EP0("%s: finished, waiting for status\n", __func__);
1589 1589
1590 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR); 1590 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
1591 dev->ep0state = WAIT_FOR_SETUP; 1591 dev->ep0state = WAIT_FOR_SETUP;
1592 } else { 1592 } else {
1593 DEBUG_EP0("%s: not finished\n", __FUNCTION__); 1593 DEBUG_EP0("%s: not finished\n", __func__);
1594 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR); 1594 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR);
1595 } 1595 }
1596 1596
1597 if (need_zlp) { 1597 if (need_zlp) {
1598 DEBUG_EP0("%s: Need ZLP!\n", __FUNCTION__); 1598 DEBUG_EP0("%s: Need ZLP!\n", __func__);
1599 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR); 1599 usb_set(EP0_IN_PKT_RDY, USB_EP0_CSR);
1600 dev->ep0state = DATA_STATE_NEED_ZLP; 1600 dev->ep0state = DATA_STATE_NEED_ZLP;
1601 } 1601 }
@@ -1694,7 +1694,7 @@ static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
1694 struct usb_ctrlrequest ctrl; 1694 struct usb_ctrlrequest ctrl;
1695 int i, bytes, is_in; 1695 int i, bytes, is_in;
1696 1696
1697 DEBUG_SETUP("%s: %x\n", __FUNCTION__, csr); 1697 DEBUG_SETUP("%s: %x\n", __func__, csr);
1698 1698
1699 /* Nuke all previous transfers */ 1699 /* Nuke all previous transfers */
1700 nuke(ep, -EPROTO); 1700 nuke(ep, -EPROTO);
@@ -1799,7 +1799,7 @@ static void lh7a40x_ep0_setup(struct lh7a40x_udc *dev, u32 csr)
1799 */ 1799 */
1800static void lh7a40x_ep0_in_zlp(struct lh7a40x_udc *dev, u32 csr) 1800static void lh7a40x_ep0_in_zlp(struct lh7a40x_udc *dev, u32 csr)
1801{ 1801{
1802 DEBUG_EP0("%s: %x\n", __FUNCTION__, csr); 1802 DEBUG_EP0("%s: %x\n", __func__, csr);
1803 1803
1804 /* c.f. Table 15-14 */ 1804 /* c.f. Table 15-14 */
1805 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR); 1805 usb_set((EP0_IN_PKT_RDY | EP0_DATA_END), USB_EP0_CSR);
@@ -1818,7 +1818,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1818 usb_set_index(0); 1818 usb_set_index(0);
1819 csr = usb_read(USB_EP0_CSR); 1819 csr = usb_read(USB_EP0_CSR);
1820 1820
1821 DEBUG_EP0("%s: csr = %x\n", __FUNCTION__, csr); 1821 DEBUG_EP0("%s: csr = %x\n", __func__, csr);
1822 1822
1823 /* 1823 /*
1824 * For overview of what we should be doing see c.f. Chapter 18.1.2.4 1824 * For overview of what we should be doing see c.f. Chapter 18.1.2.4
@@ -1832,7 +1832,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1832 * - clear the SENT_STALL bit 1832 * - clear the SENT_STALL bit
1833 */ 1833 */
1834 if (csr & EP0_SENT_STALL) { 1834 if (csr & EP0_SENT_STALL) {
1835 DEBUG_EP0("%s: EP0_SENT_STALL is set: %x\n", __FUNCTION__, csr); 1835 DEBUG_EP0("%s: EP0_SENT_STALL is set: %x\n", __func__, csr);
1836 usb_clear((EP0_SENT_STALL | EP0_SEND_STALL), USB_EP0_CSR); 1836 usb_clear((EP0_SENT_STALL | EP0_SEND_STALL), USB_EP0_CSR);
1837 nuke(ep, -ECONNABORTED); 1837 nuke(ep, -ECONNABORTED);
1838 dev->ep0state = WAIT_FOR_SETUP; 1838 dev->ep0state = WAIT_FOR_SETUP;
@@ -1849,7 +1849,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1849 */ 1849 */
1850 if (!(csr & (EP0_IN_PKT_RDY | EP0_OUT_PKT_RDY))) { 1850 if (!(csr & (EP0_IN_PKT_RDY | EP0_OUT_PKT_RDY))) {
1851 DEBUG_EP0("%s: IN_PKT_RDY and OUT_PKT_RDY are clear\n", 1851 DEBUG_EP0("%s: IN_PKT_RDY and OUT_PKT_RDY are clear\n",
1852 __FUNCTION__); 1852 __func__);
1853 1853
1854 switch (dev->ep0state) { 1854 switch (dev->ep0state) {
1855 case DATA_STATE_XMIT: 1855 case DATA_STATE_XMIT:
@@ -1877,7 +1877,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1877 * - set SERVICED_SETUP_END_BIT 1877 * - set SERVICED_SETUP_END_BIT
1878 */ 1878 */
1879 if (csr & EP0_SETUP_END) { 1879 if (csr & EP0_SETUP_END) {
1880 DEBUG_EP0("%s: EP0_SETUP_END is set: %x\n", __FUNCTION__, csr); 1880 DEBUG_EP0("%s: EP0_SETUP_END is set: %x\n", __func__, csr);
1881 1881
1882 usb_set(EP0_CLR_SETUP_END, USB_EP0_CSR); 1882 usb_set(EP0_CLR_SETUP_END, USB_EP0_CSR);
1883 1883
@@ -1896,7 +1896,7 @@ static void lh7a40x_handle_ep0(struct lh7a40x_udc *dev, u32 intr)
1896 */ 1896 */
1897 if (csr & EP0_OUT_PKT_RDY) { 1897 if (csr & EP0_OUT_PKT_RDY) {
1898 1898
1899 DEBUG_EP0("%s: EP0_OUT_PKT_RDY is set: %x\n", __FUNCTION__, 1899 DEBUG_EP0("%s: EP0_OUT_PKT_RDY is set: %x\n", __func__,
1900 csr); 1900 csr);
1901 1901
1902 switch (dev->ep0state) { 1902 switch (dev->ep0state) {
@@ -1926,7 +1926,7 @@ static void lh7a40x_ep0_kick(struct lh7a40x_udc *dev, struct lh7a40x_ep *ep)
1926 usb_set_index(0); 1926 usb_set_index(0);
1927 csr = usb_read(USB_EP0_CSR); 1927 csr = usb_read(USB_EP0_CSR);
1928 1928
1929 DEBUG_EP0("%s: %x\n", __FUNCTION__, csr); 1929 DEBUG_EP0("%s: %x\n", __func__, csr);
1930 1930
1931 /* Clear "out packet ready" */ 1931 /* Clear "out packet ready" */
1932 usb_set(EP0_CLR_OUT, USB_EP0_CSR); 1932 usb_set(EP0_CLR_OUT, USB_EP0_CSR);
@@ -1949,7 +1949,7 @@ static int lh7a40x_udc_get_frame(struct usb_gadget *_gadget)
1949{ 1949{
1950 u32 frame1 = usb_read(USB_FRM_NUM1); /* Least significant 8 bits */ 1950 u32 frame1 = usb_read(USB_FRM_NUM1); /* Least significant 8 bits */
1951 u32 frame2 = usb_read(USB_FRM_NUM2); /* Most significant 3 bits */ 1951 u32 frame2 = usb_read(USB_FRM_NUM2); /* Most significant 3 bits */
1952 DEBUG("%s, %p\n", __FUNCTION__, _gadget); 1952 DEBUG("%s, %p\n", __func__, _gadget);
1953 return ((frame2 & 0x07) << 8) | (frame1 & 0xff); 1953 return ((frame2 & 0x07) << 8) | (frame1 & 0xff);
1954} 1954}
1955 1955
@@ -1970,7 +1970,7 @@ static const struct usb_gadget_ops lh7a40x_udc_ops = {
1970 1970
1971static void nop_release(struct device *dev) 1971static void nop_release(struct device *dev)
1972{ 1972{
1973 DEBUG("%s %s\n", __FUNCTION__, dev->bus_id); 1973 DEBUG("%s %s\n", __func__, dev->bus_id);
1974} 1974}
1975 1975
1976static struct lh7a40x_udc memory = { 1976static struct lh7a40x_udc memory = {
@@ -2065,7 +2065,7 @@ static int lh7a40x_udc_probe(struct platform_device *pdev)
2065 struct lh7a40x_udc *dev = &memory; 2065 struct lh7a40x_udc *dev = &memory;
2066 int retval; 2066 int retval;
2067 2067
2068 DEBUG("%s: %p\n", __FUNCTION__, pdev); 2068 DEBUG("%s: %p\n", __func__, pdev);
2069 2069
2070 spin_lock_init(&dev->lock); 2070 spin_lock_init(&dev->lock);
2071 dev->dev = &pdev->dev; 2071 dev->dev = &pdev->dev;
@@ -2098,7 +2098,7 @@ static int lh7a40x_udc_remove(struct platform_device *pdev)
2098{ 2098{
2099 struct lh7a40x_udc *dev = platform_get_drvdata(pdev); 2099 struct lh7a40x_udc *dev = platform_get_drvdata(pdev);
2100 2100
2101 DEBUG("%s: %p\n", __FUNCTION__, pdev); 2101 DEBUG("%s: %p\n", __func__, pdev);
2102 2102
2103 if (dev->driver) 2103 if (dev->driver)
2104 return -EBUSY; 2104 return -EBUSY;
@@ -2131,7 +2131,7 @@ static struct platform_driver udc_driver = {
2131 2131
2132static int __init udc_init(void) 2132static int __init udc_init(void)
2133{ 2133{
2134 DEBUG("%s: %s version %s\n", __FUNCTION__, driver_name, DRIVER_VERSION); 2134 DEBUG("%s: %s version %s\n", __func__, driver_name, DRIVER_VERSION);
2135 return platform_driver_register(&udc_driver); 2135 return platform_driver_register(&udc_driver);
2136} 2136}
2137 2137
@@ -2146,3 +2146,4 @@ module_exit(udc_exit);
2146MODULE_DESCRIPTION(DRIVER_DESC); 2146MODULE_DESCRIPTION(DRIVER_DESC);
2147MODULE_AUTHOR("Mikko Lahteenmaki, Bo Henriksen"); 2147MODULE_AUTHOR("Mikko Lahteenmaki, Bo Henriksen");
2148MODULE_LICENSE("GPL"); 2148MODULE_LICENSE("GPL");
2149MODULE_ALIAS("platform:lh7a40x_udc");
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 835948f0715a..ee6b35fa870f 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -35,6 +35,7 @@
35MODULE_DESCRIPTION("M66592 USB gadget driver"); 35MODULE_DESCRIPTION("M66592 USB gadget driver");
36MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
37MODULE_AUTHOR("Yoshihiro Shimoda"); 37MODULE_AUTHOR("Yoshihiro Shimoda");
38MODULE_ALIAS("platform:m66592_udc");
38 39
39#define DRIVER_VERSION "18 Oct 2007" 40#define DRIVER_VERSION "18 Oct 2007"
40 41
@@ -1671,6 +1672,7 @@ static struct platform_driver m66592_driver = {
1671 .remove = __exit_p(m66592_remove), 1672 .remove = __exit_p(m66592_remove),
1672 .driver = { 1673 .driver = {
1673 .name = (char *) udc_name, 1674 .name = (char *) udc_name,
1675 .owner = THIS_MODULE,
1674 }, 1676 },
1675}; 1677};
1676 1678
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h
index 17b792b7f6bf..f118f00f1466 100644
--- a/drivers/usb/gadget/m66592-udc.h
+++ b/drivers/usb/gadget/m66592-udc.h
@@ -485,11 +485,11 @@ struct m66592 {
485 struct m66592_ep *epaddr2ep[16]; 485 struct m66592_ep *epaddr2ep[16];
486 486
487 struct usb_request *ep0_req; /* for internal request */ 487 struct usb_request *ep0_req; /* for internal request */
488 u16 ep0_data; /* for internal request */ 488 __le16 ep0_data; /* for internal request */
489 u16 old_vbus;
489 490
490 struct timer_list timer; 491 struct timer_list timer;
491 492
492 u16 old_vbus;
493 int scount; 493 int scount;
494 494
495 int old_dvsq; 495 int old_dvsq;
diff --git a/drivers/usb/gadget/net2280.h b/drivers/usb/gadget/net2280.h
index 44ca139983d8..1f2af398a9a4 100644
--- a/drivers/usb/gadget/net2280.h
+++ b/drivers/usb/gadget/net2280.h
@@ -299,7 +299,7 @@ static inline void assert_out_naking (struct net2280_ep *ep, const char *where)
299 &ep->regs->ep_rsp); 299 &ep->regs->ep_rsp);
300 } 300 }
301} 301}
302#define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__FUNCTION__) 302#define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__func__)
303#else 303#else
304#define ASSERT_OUT_NAKING(ep) do {} while (0) 304#define ASSERT_OUT_NAKING(ep) do {} while (0)
305#endif 305#endif
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index e6d68bda428a..03a7f49d207d 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -135,13 +135,17 @@ static void use_ep(struct omap_ep *ep, u16 select)
135 135
136 if (ep->bEndpointAddress & USB_DIR_IN) 136 if (ep->bEndpointAddress & USB_DIR_IN)
137 num |= UDC_EP_DIR; 137 num |= UDC_EP_DIR;
138 UDC_EP_NUM_REG = num | select; 138 omap_writew(num | select, UDC_EP_NUM);
139 /* when select, MUST deselect later !! */ 139 /* when select, MUST deselect later !! */
140} 140}
141 141
142static inline void deselect_ep(void) 142static inline void deselect_ep(void)
143{ 143{
144 UDC_EP_NUM_REG &= ~UDC_EP_SEL; 144 u16 w;
145
146 w = omap_readw(UDC_EP_NUM);
147 w &= ~UDC_EP_SEL;
148 omap_writew(w, UDC_EP_NUM);
145 /* 6 wait states before TX will happen */ 149 /* 6 wait states before TX will happen */
146} 150}
147 151
@@ -163,7 +167,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
163 || ep->bEndpointAddress != desc->bEndpointAddress 167 || ep->bEndpointAddress != desc->bEndpointAddress
164 || ep->maxpacket < le16_to_cpu 168 || ep->maxpacket < le16_to_cpu
165 (desc->wMaxPacketSize)) { 169 (desc->wMaxPacketSize)) {
166 DBG("%s, bad ep or descriptor\n", __FUNCTION__); 170 DBG("%s, bad ep or descriptor\n", __func__);
167 return -EINVAL; 171 return -EINVAL;
168 } 172 }
169 maxp = le16_to_cpu (desc->wMaxPacketSize); 173 maxp = le16_to_cpu (desc->wMaxPacketSize);
@@ -171,7 +175,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
171 && maxp != ep->maxpacket) 175 && maxp != ep->maxpacket)
172 || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket 176 || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket
173 || !desc->wMaxPacketSize) { 177 || !desc->wMaxPacketSize) {
174 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 178 DBG("%s, bad %s maxpacket\n", __func__, _ep->name);
175 return -ERANGE; 179 return -ERANGE;
176 } 180 }
177 181
@@ -194,13 +198,13 @@ static int omap_ep_enable(struct usb_ep *_ep,
194 if (ep->bmAttributes != desc->bmAttributes 198 if (ep->bmAttributes != desc->bmAttributes
195 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK 199 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
196 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { 200 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
197 DBG("%s, %s type mismatch\n", __FUNCTION__, _ep->name); 201 DBG("%s, %s type mismatch\n", __func__, _ep->name);
198 return -EINVAL; 202 return -EINVAL;
199 } 203 }
200 204
201 udc = ep->udc; 205 udc = ep->udc;
202 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { 206 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
203 DBG("%s, bogus device state\n", __FUNCTION__); 207 DBG("%s, bogus device state\n", __func__);
204 return -ESHUTDOWN; 208 return -ESHUTDOWN;
205 } 209 }
206 210
@@ -216,7 +220,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
216 ep->has_dma = 0; 220 ep->has_dma = 0;
217 ep->lch = -1; 221 ep->lch = -1;
218 use_ep(ep, UDC_EP_SEL); 222 use_ep(ep, UDC_EP_SEL);
219 UDC_CTRL_REG = udc->clr_halt; 223 omap_writew(udc->clr_halt, UDC_CTRL);
220 ep->ackwait = 0; 224 ep->ackwait = 0;
221 deselect_ep(); 225 deselect_ep();
222 226
@@ -232,7 +236,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
232 if (desc->bmAttributes != USB_ENDPOINT_XFER_ISOC 236 if (desc->bmAttributes != USB_ENDPOINT_XFER_ISOC
233 && !ep->has_dma 237 && !ep->has_dma
234 && !(ep->bEndpointAddress & USB_DIR_IN)) { 238 && !(ep->bEndpointAddress & USB_DIR_IN)) {
235 UDC_CTRL_REG = UDC_SET_FIFO_EN; 239 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
236 ep->ackwait = 1 + ep->double_buf; 240 ep->ackwait = 1 + ep->double_buf;
237 } 241 }
238 242
@@ -249,7 +253,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
249 unsigned long flags; 253 unsigned long flags;
250 254
251 if (!_ep || !ep->desc) { 255 if (!_ep || !ep->desc) {
252 DBG("%s, %s not enabled\n", __FUNCTION__, 256 DBG("%s, %s not enabled\n", __func__,
253 _ep ? ep->ep.name : NULL); 257 _ep ? ep->ep.name : NULL);
254 return -EINVAL; 258 return -EINVAL;
255 } 259 }
@@ -259,7 +263,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
259 nuke (ep, -ESHUTDOWN); 263 nuke (ep, -ESHUTDOWN);
260 ep->ep.maxpacket = ep->maxpacket; 264 ep->ep.maxpacket = ep->maxpacket;
261 ep->has_dma = 0; 265 ep->has_dma = 0;
262 UDC_CTRL_REG = UDC_SET_HALT; 266 omap_writew(UDC_SET_HALT, UDC_CTRL);
263 list_del_init(&ep->iso); 267 list_del_init(&ep->iso);
264 del_timer(&ep->timer); 268 del_timer(&ep->timer);
265 269
@@ -360,13 +364,13 @@ write_packet(u8 *buf, struct omap_req *req, unsigned max)
360 if (likely((((int)buf) & 1) == 0)) { 364 if (likely((((int)buf) & 1) == 0)) {
361 wp = (u16 *)buf; 365 wp = (u16 *)buf;
362 while (max >= 2) { 366 while (max >= 2) {
363 UDC_DATA_REG = *wp++; 367 omap_writew(*wp++, UDC_DATA);
364 max -= 2; 368 max -= 2;
365 } 369 }
366 buf = (u8 *)wp; 370 buf = (u8 *)wp;
367 } 371 }
368 while (max--) 372 while (max--)
369 *(volatile u8 *)&UDC_DATA_REG = *buf++; 373 omap_writeb(*buf++, UDC_DATA);
370 return len; 374 return len;
371} 375}
372 376
@@ -385,13 +389,13 @@ static int write_fifo(struct omap_ep *ep, struct omap_req *req)
385 prefetch(buf); 389 prefetch(buf);
386 390
387 /* PIO-IN isn't double buffered except for iso */ 391 /* PIO-IN isn't double buffered except for iso */
388 ep_stat = UDC_STAT_FLG_REG; 392 ep_stat = omap_readw(UDC_STAT_FLG);
389 if (ep_stat & UDC_FIFO_UNWRITABLE) 393 if (ep_stat & UDC_FIFO_UNWRITABLE)
390 return 0; 394 return 0;
391 395
392 count = ep->ep.maxpacket; 396 count = ep->ep.maxpacket;
393 count = write_packet(buf, req, count); 397 count = write_packet(buf, req, count);
394 UDC_CTRL_REG = UDC_SET_FIFO_EN; 398 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
395 ep->ackwait = 1; 399 ep->ackwait = 1;
396 400
397 /* last packet is often short (sometimes a zlp) */ 401 /* last packet is often short (sometimes a zlp) */
@@ -425,13 +429,13 @@ read_packet(u8 *buf, struct omap_req *req, unsigned avail)
425 if (likely((((int)buf) & 1) == 0)) { 429 if (likely((((int)buf) & 1) == 0)) {
426 wp = (u16 *)buf; 430 wp = (u16 *)buf;
427 while (avail >= 2) { 431 while (avail >= 2) {
428 *wp++ = UDC_DATA_REG; 432 *wp++ = omap_readw(UDC_DATA);
429 avail -= 2; 433 avail -= 2;
430 } 434 }
431 buf = (u8 *)wp; 435 buf = (u8 *)wp;
432 } 436 }
433 while (avail--) 437 while (avail--)
434 *buf++ = *(volatile u8 *)&UDC_DATA_REG; 438 *buf++ = omap_readb(UDC_DATA);
435 return len; 439 return len;
436} 440}
437 441
@@ -446,7 +450,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
446 prefetchw(buf); 450 prefetchw(buf);
447 451
448 for (;;) { 452 for (;;) {
449 u16 ep_stat = UDC_STAT_FLG_REG; 453 u16 ep_stat = omap_readw(UDC_STAT_FLG);
450 454
451 is_last = 0; 455 is_last = 0;
452 if (ep_stat & FIFO_EMPTY) { 456 if (ep_stat & FIFO_EMPTY) {
@@ -460,7 +464,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
460 if (ep_stat & UDC_FIFO_FULL) 464 if (ep_stat & UDC_FIFO_FULL)
461 avail = ep->ep.maxpacket; 465 avail = ep->ep.maxpacket;
462 else { 466 else {
463 avail = UDC_RXFSTAT_REG; 467 avail = omap_readw(UDC_RXFSTAT);
464 ep->fnf = ep->double_buf; 468 ep->fnf = ep->double_buf;
465 } 469 }
466 count = read_packet(buf, req, avail); 470 count = read_packet(buf, req, avail);
@@ -473,7 +477,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
473 req->req.status = -EOVERFLOW; 477 req->req.status = -EOVERFLOW;
474 avail -= count; 478 avail -= count;
475 while (avail--) 479 while (avail--)
476 (void) *(volatile u8 *)&UDC_DATA_REG; 480 omap_readw(UDC_DATA);
477 } 481 }
478 } else if (req->req.length == req->req.actual) 482 } else if (req->req.length == req->req.actual)
479 is_last = 1; 483 is_last = 1;
@@ -491,32 +495,6 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
491 495
492/*-------------------------------------------------------------------------*/ 496/*-------------------------------------------------------------------------*/
493 497
494static inline dma_addr_t dma_csac(unsigned lch)
495{
496 dma_addr_t csac;
497
498 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
499 * read before the DMA controller finished disabling the channel.
500 */
501 csac = OMAP_DMA_CSAC_REG(lch);
502 if (csac == 0)
503 csac = OMAP_DMA_CSAC_REG(lch);
504 return csac;
505}
506
507static inline dma_addr_t dma_cdac(unsigned lch)
508{
509 dma_addr_t cdac;
510
511 /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
512 * read before the DMA controller finished disabling the channel.
513 */
514 cdac = OMAP_DMA_CDAC_REG(lch);
515 if (cdac == 0)
516 cdac = OMAP_DMA_CDAC_REG(lch);
517 return cdac;
518}
519
520static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) 498static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
521{ 499{
522 dma_addr_t end; 500 dma_addr_t end;
@@ -527,7 +505,7 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
527 if (cpu_is_omap15xx()) 505 if (cpu_is_omap15xx())
528 return 0; 506 return 0;
529 507
530 end = dma_csac(ep->lch); 508 end = omap_get_dma_src_pos(ep->lch);
531 if (end == ep->dma_counter) 509 if (end == ep->dma_counter)
532 return 0; 510 return 0;
533 511
@@ -537,15 +515,11 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
537 return end - start; 515 return end - start;
538} 516}
539 517
540#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \
541 ? OMAP_DMA_CSAC_REG(x) /* really: CPC */ \
542 : dma_cdac(x))
543
544static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) 518static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
545{ 519{
546 dma_addr_t end; 520 dma_addr_t end;
547 521
548 end = DMA_DEST_LAST(ep->lch); 522 end = omap_get_dma_dst_pos(ep->lch);
549 if (end == ep->dma_counter) 523 if (end == ep->dma_counter)
550 return 0; 524 return 0;
551 525
@@ -565,7 +539,7 @@ static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
565 539
566static void next_in_dma(struct omap_ep *ep, struct omap_req *req) 540static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
567{ 541{
568 u16 txdma_ctrl; 542 u16 txdma_ctrl, w;
569 unsigned length = req->req.length - req->req.actual; 543 unsigned length = req->req.length - req->req.actual;
570 const int sync_mode = cpu_is_omap15xx() 544 const int sync_mode = cpu_is_omap15xx()
571 ? OMAP_DMA_SYNC_FRAME 545 ? OMAP_DMA_SYNC_FRAME
@@ -596,14 +570,18 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
596 0, 0); 570 0, 0);
597 571
598 omap_start_dma(ep->lch); 572 omap_start_dma(ep->lch);
599 ep->dma_counter = dma_csac(ep->lch); 573 ep->dma_counter = omap_get_dma_src_pos(ep->lch);
600 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel); 574 w = omap_readw(UDC_DMA_IRQ_EN);
601 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl; 575 w |= UDC_TX_DONE_IE(ep->dma_channel);
576 omap_writew(w, UDC_DMA_IRQ_EN);
577 omap_writew(UDC_TXN_START | txdma_ctrl, UDC_TXDMA(ep->dma_channel));
602 req->dma_bytes = length; 578 req->dma_bytes = length;
603} 579}
604 580
605static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status) 581static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
606{ 582{
583 u16 w;
584
607 if (status == 0) { 585 if (status == 0) {
608 req->req.actual += req->dma_bytes; 586 req->req.actual += req->dma_bytes;
609 587
@@ -620,7 +598,9 @@ static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
620 598
621 /* tx completion */ 599 /* tx completion */
622 omap_stop_dma(ep->lch); 600 omap_stop_dma(ep->lch);
623 UDC_DMA_IRQ_EN_REG &= ~UDC_TX_DONE_IE(ep->dma_channel); 601 w = omap_readw(UDC_DMA_IRQ_EN);
602 w &= ~UDC_TX_DONE_IE(ep->dma_channel);
603 omap_writew(w, UDC_DMA_IRQ_EN);
624 done(ep, req, status); 604 done(ep, req, status);
625} 605}
626 606
@@ -628,6 +608,7 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
628{ 608{
629 unsigned packets = req->req.length - req->req.actual; 609 unsigned packets = req->req.length - req->req.actual;
630 int dma_trigger = 0; 610 int dma_trigger = 0;
611 u16 w;
631 612
632 if (cpu_is_omap24xx()) 613 if (cpu_is_omap24xx())
633 dma_trigger = OMAP24XX_DMA(USB_W2FC_RX0, ep->dma_channel); 614 dma_trigger = OMAP24XX_DMA(USB_W2FC_RX0, ep->dma_channel);
@@ -654,12 +635,14 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
654 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 635 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
655 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, 636 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual,
656 0, 0); 637 0, 0);
657 ep->dma_counter = DMA_DEST_LAST(ep->lch); 638 ep->dma_counter = omap_get_dma_dst_pos(ep->lch);
658 639
659 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); 640 omap_writew(UDC_RXN_STOP | (packets - 1), UDC_RXDMA(ep->dma_channel));
660 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel); 641 w = omap_readw(UDC_DMA_IRQ_EN);
661 UDC_EP_NUM_REG = (ep->bEndpointAddress & 0xf); 642 w |= UDC_RX_EOT_IE(ep->dma_channel);
662 UDC_CTRL_REG = UDC_SET_FIFO_EN; 643 omap_writew(w, UDC_DMA_IRQ_EN);
644 omap_writew(ep->bEndpointAddress & 0xf, UDC_EP_NUM);
645 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
663 646
664 omap_start_dma(ep->lch); 647 omap_start_dma(ep->lch);
665} 648}
@@ -667,7 +650,7 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
667static void 650static void
668finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one) 651finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one)
669{ 652{
670 u16 count; 653 u16 count, w;
671 654
672 if (status == 0) 655 if (status == 0)
673 ep->dma_counter = (u16) (req->req.dma + req->req.actual); 656 ep->dma_counter = (u16) (req->req.dma + req->req.actual);
@@ -686,13 +669,15 @@ finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one)
686 return; 669 return;
687 670
688 /* rx completion */ 671 /* rx completion */
689 UDC_DMA_IRQ_EN_REG &= ~UDC_RX_EOT_IE(ep->dma_channel); 672 w = omap_readw(UDC_DMA_IRQ_EN);
673 w &= ~UDC_RX_EOT_IE(ep->dma_channel);
674 omap_writew(w, UDC_DMA_IRQ_EN);
690 done(ep, req, status); 675 done(ep, req, status);
691} 676}
692 677
693static void dma_irq(struct omap_udc *udc, u16 irq_src) 678static void dma_irq(struct omap_udc *udc, u16 irq_src)
694{ 679{
695 u16 dman_stat = UDC_DMAN_STAT_REG; 680 u16 dman_stat = omap_readw(UDC_DMAN_STAT);
696 struct omap_ep *ep; 681 struct omap_ep *ep;
697 struct omap_req *req; 682 struct omap_req *req;
698 683
@@ -706,7 +691,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
706 struct omap_req, queue); 691 struct omap_req, queue);
707 finish_in_dma(ep, req, 0); 692 finish_in_dma(ep, req, 0);
708 } 693 }
709 UDC_IRQ_SRC_REG = UDC_TXN_DONE; 694 omap_writew(UDC_TXN_DONE, UDC_IRQ_SRC);
710 695
711 if (!list_empty (&ep->queue)) { 696 if (!list_empty (&ep->queue)) {
712 req = container_of(ep->queue.next, 697 req = container_of(ep->queue.next,
@@ -725,7 +710,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
725 struct omap_req, queue); 710 struct omap_req, queue);
726 finish_out_dma(ep, req, 0, dman_stat & UDC_DMA_RX_SB); 711 finish_out_dma(ep, req, 0, dman_stat & UDC_DMA_RX_SB);
727 } 712 }
728 UDC_IRQ_SRC_REG = UDC_RXN_EOT; 713 omap_writew(UDC_RXN_EOT, UDC_IRQ_SRC);
729 714
730 if (!list_empty (&ep->queue)) { 715 if (!list_empty (&ep->queue)) {
731 req = container_of(ep->queue.next, 716 req = container_of(ep->queue.next,
@@ -739,7 +724,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
739 ep->irqs++; 724 ep->irqs++;
740 /* omap15xx does this unasked... */ 725 /* omap15xx does this unasked... */
741 VDBG("%s, RX_CNT irq?\n", ep->ep.name); 726 VDBG("%s, RX_CNT irq?\n", ep->ep.name);
742 UDC_IRQ_SRC_REG = UDC_RXN_CNT; 727 omap_writew(UDC_RXN_CNT, UDC_IRQ_SRC);
743 } 728 }
744} 729}
745 730
@@ -762,9 +747,9 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
762 747
763 is_in = ep->bEndpointAddress & USB_DIR_IN; 748 is_in = ep->bEndpointAddress & USB_DIR_IN;
764 if (is_in) 749 if (is_in)
765 reg = UDC_TXDMA_CFG_REG; 750 reg = omap_readw(UDC_TXDMA_CFG);
766 else 751 else
767 reg = UDC_RXDMA_CFG_REG; 752 reg = omap_readw(UDC_RXDMA_CFG);
768 reg |= UDC_DMA_REQ; /* "pulse" activated */ 753 reg |= UDC_DMA_REQ; /* "pulse" activated */
769 754
770 ep->dma_channel = 0; 755 ep->dma_channel = 0;
@@ -792,7 +777,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
792 status = omap_request_dma(dma_channel, 777 status = omap_request_dma(dma_channel,
793 ep->ep.name, dma_error, ep, &ep->lch); 778 ep->ep.name, dma_error, ep, &ep->lch);
794 if (status == 0) { 779 if (status == 0) {
795 UDC_TXDMA_CFG_REG = reg; 780 omap_writew(reg, UDC_TXDMA_CFG);
796 /* EMIFF or SDRC */ 781 /* EMIFF or SDRC */
797 omap_set_dma_src_burst_mode(ep->lch, 782 omap_set_dma_src_burst_mode(ep->lch,
798 OMAP_DMA_DATA_BURST_4); 783 OMAP_DMA_DATA_BURST_4);
@@ -801,7 +786,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
801 omap_set_dma_dest_params(ep->lch, 786 omap_set_dma_dest_params(ep->lch,
802 OMAP_DMA_PORT_TIPB, 787 OMAP_DMA_PORT_TIPB,
803 OMAP_DMA_AMODE_CONSTANT, 788 OMAP_DMA_AMODE_CONSTANT,
804 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG), 789 (unsigned long) io_v2p(UDC_DATA_DMA),
805 0, 0); 790 0, 0);
806 } 791 }
807 } else { 792 } else {
@@ -813,12 +798,12 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
813 status = omap_request_dma(dma_channel, 798 status = omap_request_dma(dma_channel,
814 ep->ep.name, dma_error, ep, &ep->lch); 799 ep->ep.name, dma_error, ep, &ep->lch);
815 if (status == 0) { 800 if (status == 0) {
816 UDC_RXDMA_CFG_REG = reg; 801 omap_writew(reg, UDC_RXDMA_CFG);
817 /* TIPB */ 802 /* TIPB */
818 omap_set_dma_src_params(ep->lch, 803 omap_set_dma_src_params(ep->lch,
819 OMAP_DMA_PORT_TIPB, 804 OMAP_DMA_PORT_TIPB,
820 OMAP_DMA_AMODE_CONSTANT, 805 OMAP_DMA_AMODE_CONSTANT,
821 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG), 806 (unsigned long) io_v2p(UDC_DATA_DMA),
822 0, 0); 807 0, 0);
823 /* EMIFF or SDRC */ 808 /* EMIFF or SDRC */
824 omap_set_dma_dest_burst_mode(ep->lch, 809 omap_set_dma_dest_burst_mode(ep->lch,
@@ -834,7 +819,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
834 819
835 /* channel type P: hw synch (fifo) */ 820 /* channel type P: hw synch (fifo) */
836 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) 821 if (cpu_class_is_omap1() && !cpu_is_omap15xx())
837 OMAP1_DMA_LCH_CTRL_REG(ep->lch) = 2; 822 omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P);
838 } 823 }
839 824
840just_restart: 825just_restart:
@@ -860,7 +845,7 @@ just_restart:
860 (is_in ? write_fifo : read_fifo)(ep, req); 845 (is_in ? write_fifo : read_fifo)(ep, req);
861 deselect_ep(); 846 deselect_ep();
862 if (!is_in) { 847 if (!is_in) {
863 UDC_CTRL_REG = UDC_SET_FIFO_EN; 848 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
864 ep->ackwait = 1 + ep->double_buf; 849 ep->ackwait = 1 + ep->double_buf;
865 } 850 }
866 /* IN: 6 wait states before it'll tx */ 851 /* IN: 6 wait states before it'll tx */
@@ -881,7 +866,7 @@ static void dma_channel_release(struct omap_ep *ep)
881 else 866 else
882 req = NULL; 867 req = NULL;
883 868
884 active = ((1 << 7) & OMAP_DMA_CCR_REG(ep->lch)) != 0; 869 active = omap_get_dma_active_status(ep->lch);
885 870
886 DBG("%s release %s %cxdma%d %p\n", ep->ep.name, 871 DBG("%s release %s %cxdma%d %p\n", ep->ep.name,
887 active ? "active" : "idle", 872 active ? "active" : "idle",
@@ -894,23 +879,25 @@ static void dma_channel_release(struct omap_ep *ep)
894 879
895 /* wait till current packet DMA finishes, and fifo empties */ 880 /* wait till current packet DMA finishes, and fifo empties */
896 if (ep->bEndpointAddress & USB_DIR_IN) { 881 if (ep->bEndpointAddress & USB_DIR_IN) {
897 UDC_TXDMA_CFG_REG = (UDC_TXDMA_CFG_REG & ~mask) | UDC_DMA_REQ; 882 omap_writew((omap_readw(UDC_TXDMA_CFG) & ~mask) | UDC_DMA_REQ,
883 UDC_TXDMA_CFG);
898 884
899 if (req) { 885 if (req) {
900 finish_in_dma(ep, req, -ECONNRESET); 886 finish_in_dma(ep, req, -ECONNRESET);
901 887
902 /* clear FIFO; hosts probably won't empty it */ 888 /* clear FIFO; hosts probably won't empty it */
903 use_ep(ep, UDC_EP_SEL); 889 use_ep(ep, UDC_EP_SEL);
904 UDC_CTRL_REG = UDC_CLR_EP; 890 omap_writew(UDC_CLR_EP, UDC_CTRL);
905 deselect_ep(); 891 deselect_ep();
906 } 892 }
907 while (UDC_TXDMA_CFG_REG & mask) 893 while (omap_readw(UDC_TXDMA_CFG) & mask)
908 udelay(10); 894 udelay(10);
909 } else { 895 } else {
910 UDC_RXDMA_CFG_REG = (UDC_RXDMA_CFG_REG & ~mask) | UDC_DMA_REQ; 896 omap_writew((omap_readw(UDC_RXDMA_CFG) & ~mask) | UDC_DMA_REQ,
897 UDC_RXDMA_CFG);
911 898
912 /* dma empties the fifo */ 899 /* dma empties the fifo */
913 while (UDC_RXDMA_CFG_REG & mask) 900 while (omap_readw(UDC_RXDMA_CFG) & mask)
914 udelay(10); 901 udelay(10);
915 if (req) 902 if (req)
916 finish_out_dma(ep, req, -ECONNRESET, 0); 903 finish_out_dma(ep, req, -ECONNRESET, 0);
@@ -936,11 +923,11 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
936 /* catch various bogus parameters */ 923 /* catch various bogus parameters */
937 if (!_req || !req->req.complete || !req->req.buf 924 if (!_req || !req->req.complete || !req->req.buf
938 || !list_empty(&req->queue)) { 925 || !list_empty(&req->queue)) {
939 DBG("%s, bad params\n", __FUNCTION__); 926 DBG("%s, bad params\n", __func__);
940 return -EINVAL; 927 return -EINVAL;
941 } 928 }
942 if (!_ep || (!ep->desc && ep->bEndpointAddress)) { 929 if (!_ep || (!ep->desc && ep->bEndpointAddress)) {
943 DBG("%s, bad ep\n", __FUNCTION__); 930 DBG("%s, bad ep\n", __func__);
944 return -EINVAL; 931 return -EINVAL;
945 } 932 }
946 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 933 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
@@ -959,7 +946,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
959 && (ep->bEndpointAddress & USB_DIR_IN) == 0 946 && (ep->bEndpointAddress & USB_DIR_IN) == 0
960 && !cpu_class_is_omap2() 947 && !cpu_class_is_omap2()
961 && (req->req.length % ep->ep.maxpacket) != 0) { 948 && (req->req.length % ep->ep.maxpacket) != 0) {
962 DBG("%s, no partial packet OUT reads\n", __FUNCTION__); 949 DBG("%s, no partial packet OUT reads\n", __func__);
963 return -EMSGSIZE; 950 return -EMSGSIZE;
964 } 951 }
965 952
@@ -997,9 +984,13 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
997 req->req.actual = 0; 984 req->req.actual = 0;
998 985
999 /* maybe kickstart non-iso i/o queues */ 986 /* maybe kickstart non-iso i/o queues */
1000 if (is_iso) 987 if (is_iso) {
1001 UDC_IRQ_EN_REG |= UDC_SOF_IE; 988 u16 w;
1002 else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) { 989
990 w = omap_readw(UDC_IRQ_EN);
991 w |= UDC_SOF_IE;
992 omap_writew(w, UDC_IRQ_EN);
993 } else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) {
1003 int is_in; 994 int is_in;
1004 995
1005 if (ep->bEndpointAddress == 0) { 996 if (ep->bEndpointAddress == 0) {
@@ -1017,23 +1008,23 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
1017 * requests to non-control endpoints 1008 * requests to non-control endpoints
1018 */ 1009 */
1019 if (udc->ep0_set_config) { 1010 if (udc->ep0_set_config) {
1020 u16 irq_en = UDC_IRQ_EN_REG; 1011 u16 irq_en = omap_readw(UDC_IRQ_EN);
1021 1012
1022 irq_en |= UDC_DS_CHG_IE | UDC_EP0_IE; 1013 irq_en |= UDC_DS_CHG_IE | UDC_EP0_IE;
1023 if (!udc->ep0_reset_config) 1014 if (!udc->ep0_reset_config)
1024 irq_en |= UDC_EPN_RX_IE 1015 irq_en |= UDC_EPN_RX_IE
1025 | UDC_EPN_TX_IE; 1016 | UDC_EPN_TX_IE;
1026 UDC_IRQ_EN_REG = irq_en; 1017 omap_writew(irq_en, UDC_IRQ_EN);
1027 } 1018 }
1028 1019
1029 /* STATUS for zero length DATA stages is 1020 /* STATUS for zero length DATA stages is
1030 * always an IN ... even for IN transfers, 1021 * always an IN ... even for IN transfers,
1031 * a weird case which seem to stall OMAP. 1022 * a weird case which seem to stall OMAP.
1032 */ 1023 */
1033 UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR); 1024 omap_writew(UDC_EP_SEL | UDC_EP_DIR, UDC_EP_NUM);
1034 UDC_CTRL_REG = UDC_CLR_EP; 1025 omap_writew(UDC_CLR_EP, UDC_CTRL);
1035 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1026 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1036 UDC_EP_NUM_REG = UDC_EP_DIR; 1027 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
1037 1028
1038 /* cleanup */ 1029 /* cleanup */
1039 udc->ep0_pending = 0; 1030 udc->ep0_pending = 0;
@@ -1042,11 +1033,11 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
1042 1033
1043 /* non-empty DATA stage */ 1034 /* non-empty DATA stage */
1044 } else if (is_in) { 1035 } else if (is_in) {
1045 UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR; 1036 omap_writew(UDC_EP_SEL | UDC_EP_DIR, UDC_EP_NUM);
1046 } else { 1037 } else {
1047 if (udc->ep0_setup) 1038 if (udc->ep0_setup)
1048 goto irq_wait; 1039 goto irq_wait;
1049 UDC_EP_NUM_REG = UDC_EP_SEL; 1040 omap_writew(UDC_EP_SEL, UDC_EP_NUM);
1050 } 1041 }
1051 } else { 1042 } else {
1052 is_in = ep->bEndpointAddress & USB_DIR_IN; 1043 is_in = ep->bEndpointAddress & USB_DIR_IN;
@@ -1062,7 +1053,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
1062 req = NULL; 1053 req = NULL;
1063 deselect_ep(); 1054 deselect_ep();
1064 if (!is_in) { 1055 if (!is_in) {
1065 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1056 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1066 ep->ackwait = 1 + ep->double_buf; 1057 ep->ackwait = 1 + ep->double_buf;
1067 } 1058 }
1068 /* IN: 6 wait states before it'll tx */ 1059 /* IN: 6 wait states before it'll tx */
@@ -1130,9 +1121,9 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
1130 else if (value) { 1121 else if (value) {
1131 if (ep->udc->ep0_set_config) { 1122 if (ep->udc->ep0_set_config) {
1132 WARN("error changing config?\n"); 1123 WARN("error changing config?\n");
1133 UDC_SYSCON2_REG = UDC_CLR_CFG; 1124 omap_writew(UDC_CLR_CFG, UDC_SYSCON2);
1134 } 1125 }
1135 UDC_SYSCON2_REG = UDC_STALL_CMD; 1126 omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
1136 ep->udc->ep0_pending = 0; 1127 ep->udc->ep0_pending = 0;
1137 status = 0; 1128 status = 0;
1138 } else /* NOP */ 1129 } else /* NOP */
@@ -1159,8 +1150,8 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
1159 channel = 0; 1150 channel = 0;
1160 1151
1161 use_ep(ep, UDC_EP_SEL); 1152 use_ep(ep, UDC_EP_SEL);
1162 if (UDC_STAT_FLG_REG & UDC_NON_ISO_FIFO_EMPTY) { 1153 if (omap_readw(UDC_STAT_FLG) & UDC_NON_ISO_FIFO_EMPTY) {
1163 UDC_CTRL_REG = UDC_SET_HALT; 1154 omap_writew(UDC_SET_HALT, UDC_CTRL);
1164 status = 0; 1155 status = 0;
1165 } else 1156 } else
1166 status = -EAGAIN; 1157 status = -EAGAIN;
@@ -1170,10 +1161,10 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
1170 dma_channel_claim(ep, channel); 1161 dma_channel_claim(ep, channel);
1171 } else { 1162 } else {
1172 use_ep(ep, 0); 1163 use_ep(ep, 0);
1173 UDC_CTRL_REG = ep->udc->clr_halt; 1164 omap_writew(ep->udc->clr_halt, UDC_CTRL);
1174 ep->ackwait = 0; 1165 ep->ackwait = 0;
1175 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1166 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1176 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1167 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1177 ep->ackwait = 1 + ep->double_buf; 1168 ep->ackwait = 1 + ep->double_buf;
1178 } 1169 }
1179 } 1170 }
@@ -1205,7 +1196,7 @@ static struct usb_ep_ops omap_ep_ops = {
1205 1196
1206static int omap_get_frame(struct usb_gadget *gadget) 1197static int omap_get_frame(struct usb_gadget *gadget)
1207{ 1198{
1208 u16 sof = UDC_SOF_REG; 1199 u16 sof = omap_readw(UDC_SOF);
1209 return (sof & UDC_TS_OK) ? (sof & UDC_TS) : -EL2NSYNC; 1200 return (sof & UDC_TS_OK) ? (sof & UDC_TS) : -EL2NSYNC;
1210} 1201}
1211 1202
@@ -1224,7 +1215,7 @@ static int omap_wakeup(struct usb_gadget *gadget)
1224 */ 1215 */
1225 if (udc->devstat & (UDC_B_HNP_ENABLE|UDC_R_WK_OK)) { 1216 if (udc->devstat & (UDC_B_HNP_ENABLE|UDC_R_WK_OK)) {
1226 DBG("remote wakeup...\n"); 1217 DBG("remote wakeup...\n");
1227 UDC_SYSCON2_REG = UDC_RMT_WKP; 1218 omap_writew(UDC_RMT_WKP, UDC_SYSCON2);
1228 retval = 0; 1219 retval = 0;
1229 } 1220 }
1230 1221
@@ -1247,12 +1238,12 @@ omap_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
1247 1238
1248 udc = container_of(gadget, struct omap_udc, gadget); 1239 udc = container_of(gadget, struct omap_udc, gadget);
1249 spin_lock_irqsave(&udc->lock, flags); 1240 spin_lock_irqsave(&udc->lock, flags);
1250 syscon1 = UDC_SYSCON1_REG; 1241 syscon1 = omap_readw(UDC_SYSCON1);
1251 if (is_selfpowered) 1242 if (is_selfpowered)
1252 syscon1 |= UDC_SELF_PWR; 1243 syscon1 |= UDC_SELF_PWR;
1253 else 1244 else
1254 syscon1 &= ~UDC_SELF_PWR; 1245 syscon1 &= ~UDC_SELF_PWR;
1255 UDC_SYSCON1_REG = syscon1; 1246 omap_writew(syscon1, UDC_SYSCON1);
1256 spin_unlock_irqrestore(&udc->lock, flags); 1247 spin_unlock_irqrestore(&udc->lock, flags);
1257 1248
1258 return 0; 1249 return 0;
@@ -1265,20 +1256,36 @@ static int can_pullup(struct omap_udc *udc)
1265 1256
1266static void pullup_enable(struct omap_udc *udc) 1257static void pullup_enable(struct omap_udc *udc)
1267{ 1258{
1268 udc->gadget.dev.parent->power.power_state = PMSG_ON; 1259 u16 w;
1269 udc->gadget.dev.power.power_state = PMSG_ON; 1260
1270 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1261 w = omap_readw(UDC_SYSCON1);
1271 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) 1262 w |= UDC_PULLUP_EN;
1272 OTG_CTRL_REG |= OTG_BSESSVLD; 1263 omap_writew(w, UDC_SYSCON1);
1273 UDC_IRQ_EN_REG = UDC_DS_CHG_IE; 1264 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) {
1265 u32 l;
1266
1267 l = omap_readl(OTG_CTRL);
1268 l |= OTG_BSESSVLD;
1269 omap_writel(l, OTG_CTRL);
1270 }
1271 omap_writew(UDC_DS_CHG_IE, UDC_IRQ_EN);
1274} 1272}
1275 1273
1276static void pullup_disable(struct omap_udc *udc) 1274static void pullup_disable(struct omap_udc *udc)
1277{ 1275{
1278 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) 1276 u16 w;
1279 OTG_CTRL_REG &= ~OTG_BSESSVLD; 1277
1280 UDC_IRQ_EN_REG = UDC_DS_CHG_IE; 1278 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) {
1281 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN; 1279 u32 l;
1280
1281 l = omap_readl(OTG_CTRL);
1282 l &= ~OTG_BSESSVLD;
1283 omap_writel(l, OTG_CTRL);
1284 }
1285 omap_writew(UDC_DS_CHG_IE, UDC_IRQ_EN);
1286 w = omap_readw(UDC_SYSCON1);
1287 w &= ~UDC_PULLUP_EN;
1288 omap_writew(w, UDC_SYSCON1);
1282} 1289}
1283 1290
1284static struct omap_udc *udc; 1291static struct omap_udc *udc;
@@ -1306,6 +1313,7 @@ static int omap_vbus_session(struct usb_gadget *gadget, int is_active)
1306{ 1313{
1307 struct omap_udc *udc; 1314 struct omap_udc *udc;
1308 unsigned long flags; 1315 unsigned long flags;
1316 u32 l;
1309 1317
1310 udc = container_of(gadget, struct omap_udc, gadget); 1318 udc = container_of(gadget, struct omap_udc, gadget);
1311 spin_lock_irqsave(&udc->lock, flags); 1319 spin_lock_irqsave(&udc->lock, flags);
@@ -1313,10 +1321,12 @@ static int omap_vbus_session(struct usb_gadget *gadget, int is_active)
1313 udc->vbus_active = (is_active != 0); 1321 udc->vbus_active = (is_active != 0);
1314 if (cpu_is_omap15xx()) { 1322 if (cpu_is_omap15xx()) {
1315 /* "software" detect, ignored if !VBUS_MODE_1510 */ 1323 /* "software" detect, ignored if !VBUS_MODE_1510 */
1324 l = omap_readl(FUNC_MUX_CTRL_0);
1316 if (is_active) 1325 if (is_active)
1317 FUNC_MUX_CTRL_0_REG |= VBUS_CTRL_1510; 1326 l |= VBUS_CTRL_1510;
1318 else 1327 else
1319 FUNC_MUX_CTRL_0_REG &= ~VBUS_CTRL_1510; 1328 l &= ~VBUS_CTRL_1510;
1329 omap_writel(l, FUNC_MUX_CTRL_0);
1320 } 1330 }
1321 if (udc->dc_clk != NULL && is_active) { 1331 if (udc->dc_clk != NULL && is_active) {
1322 if (!udc->clk_requested) { 1332 if (!udc->clk_requested) {
@@ -1386,9 +1396,9 @@ static void nuke(struct omap_ep *ep, int status)
1386 dma_channel_release(ep); 1396 dma_channel_release(ep);
1387 1397
1388 use_ep(ep, 0); 1398 use_ep(ep, 0);
1389 UDC_CTRL_REG = UDC_CLR_EP; 1399 omap_writew(UDC_CLR_EP, UDC_CTRL);
1390 if (ep->bEndpointAddress && ep->bmAttributes != USB_ENDPOINT_XFER_ISOC) 1400 if (ep->bEndpointAddress && ep->bmAttributes != USB_ENDPOINT_XFER_ISOC)
1391 UDC_CTRL_REG = UDC_SET_HALT; 1401 omap_writew(UDC_SET_HALT, UDC_CTRL);
1392 1402
1393 while (!list_empty(&ep->queue)) { 1403 while (!list_empty(&ep->queue)) {
1394 req = list_entry(ep->queue.next, struct omap_req, queue); 1404 req = list_entry(ep->queue.next, struct omap_req, queue);
@@ -1416,8 +1426,8 @@ static void update_otg(struct omap_udc *udc)
1416 if (!gadget_is_otg(&udc->gadget)) 1426 if (!gadget_is_otg(&udc->gadget))
1417 return; 1427 return;
1418 1428
1419 if (OTG_CTRL_REG & OTG_ID) 1429 if (omap_readl(OTG_CTRL) & OTG_ID)
1420 devstat = UDC_DEVSTAT_REG; 1430 devstat = omap_readw(UDC_DEVSTAT);
1421 else 1431 else
1422 devstat = 0; 1432 devstat = 0;
1423 1433
@@ -1428,9 +1438,14 @@ static void update_otg(struct omap_udc *udc)
1428 /* Enable HNP early, avoiding races on suspend irq path. 1438 /* Enable HNP early, avoiding races on suspend irq path.
1429 * ASSUMES OTG state machine B_BUS_REQ input is true. 1439 * ASSUMES OTG state machine B_BUS_REQ input is true.
1430 */ 1440 */
1431 if (udc->gadget.b_hnp_enable) 1441 if (udc->gadget.b_hnp_enable) {
1432 OTG_CTRL_REG = (OTG_CTRL_REG | OTG_B_HNPEN | OTG_B_BUSREQ) 1442 u32 l;
1433 & ~OTG_PULLUP; 1443
1444 l = omap_readl(OTG_CTRL);
1445 l |= OTG_B_HNPEN | OTG_B_BUSREQ;
1446 l &= ~OTG_PULLUP;
1447 omap_writel(l, OTG_CTRL);
1448 }
1434} 1449}
1435 1450
1436static void ep0_irq(struct omap_udc *udc, u16 irq_src) 1451static void ep0_irq(struct omap_udc *udc, u16 irq_src)
@@ -1448,7 +1463,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1448 1463
1449 nuke(ep0, 0); 1464 nuke(ep0, 0);
1450 if (ack) { 1465 if (ack) {
1451 UDC_IRQ_SRC_REG = ack; 1466 omap_writew(ack, UDC_IRQ_SRC);
1452 irq_src = UDC_SETUP; 1467 irq_src = UDC_SETUP;
1453 } 1468 }
1454 } 1469 }
@@ -1468,9 +1483,9 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1468 if (irq_src & UDC_EP0_TX) { 1483 if (irq_src & UDC_EP0_TX) {
1469 int stat; 1484 int stat;
1470 1485
1471 UDC_IRQ_SRC_REG = UDC_EP0_TX; 1486 omap_writew(UDC_EP0_TX, UDC_IRQ_SRC);
1472 UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR; 1487 omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM);
1473 stat = UDC_STAT_FLG_REG; 1488 stat = omap_readw(UDC_STAT_FLG);
1474 if (stat & UDC_ACK) { 1489 if (stat & UDC_ACK) {
1475 if (udc->ep0_in) { 1490 if (udc->ep0_in) {
1476 /* write next IN packet from response, 1491 /* write next IN packet from response,
@@ -1478,26 +1493,26 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1478 */ 1493 */
1479 if (req) 1494 if (req)
1480 stat = write_fifo(ep0, req); 1495 stat = write_fifo(ep0, req);
1481 UDC_EP_NUM_REG = UDC_EP_DIR; 1496 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
1482 if (!req && udc->ep0_pending) { 1497 if (!req && udc->ep0_pending) {
1483 UDC_EP_NUM_REG = UDC_EP_SEL; 1498 omap_writew(UDC_EP_SEL, UDC_EP_NUM);
1484 UDC_CTRL_REG = UDC_CLR_EP; 1499 omap_writew(UDC_CLR_EP, UDC_CTRL);
1485 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1500 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1486 UDC_EP_NUM_REG = 0; 1501 omap_writew(0, UDC_EP_NUM);
1487 udc->ep0_pending = 0; 1502 udc->ep0_pending = 0;
1488 } /* else: 6 wait states before it'll tx */ 1503 } /* else: 6 wait states before it'll tx */
1489 } else { 1504 } else {
1490 /* ack status stage of OUT transfer */ 1505 /* ack status stage of OUT transfer */
1491 UDC_EP_NUM_REG = UDC_EP_DIR; 1506 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
1492 if (req) 1507 if (req)
1493 done(ep0, req, 0); 1508 done(ep0, req, 0);
1494 } 1509 }
1495 req = NULL; 1510 req = NULL;
1496 } else if (stat & UDC_STALL) { 1511 } else if (stat & UDC_STALL) {
1497 UDC_CTRL_REG = UDC_CLR_HALT; 1512 omap_writew(UDC_CLR_HALT, UDC_CTRL);
1498 UDC_EP_NUM_REG = UDC_EP_DIR; 1513 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
1499 } else { 1514 } else {
1500 UDC_EP_NUM_REG = UDC_EP_DIR; 1515 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
1501 } 1516 }
1502 } 1517 }
1503 1518
@@ -1505,9 +1520,9 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1505 if (irq_src & UDC_EP0_RX) { 1520 if (irq_src & UDC_EP0_RX) {
1506 int stat; 1521 int stat;
1507 1522
1508 UDC_IRQ_SRC_REG = UDC_EP0_RX; 1523 omap_writew(UDC_EP0_RX, UDC_IRQ_SRC);
1509 UDC_EP_NUM_REG = UDC_EP_SEL; 1524 omap_writew(UDC_EP_SEL, UDC_EP_NUM);
1510 stat = UDC_STAT_FLG_REG; 1525 stat = omap_readw(UDC_STAT_FLG);
1511 if (stat & UDC_ACK) { 1526 if (stat & UDC_ACK) {
1512 if (!udc->ep0_in) { 1527 if (!udc->ep0_in) {
1513 stat = 0; 1528 stat = 0;
@@ -1515,34 +1530,35 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1515 * reactiviting the fifo; stall on errors. 1530 * reactiviting the fifo; stall on errors.
1516 */ 1531 */
1517 if (!req || (stat = read_fifo(ep0, req)) < 0) { 1532 if (!req || (stat = read_fifo(ep0, req)) < 0) {
1518 UDC_SYSCON2_REG = UDC_STALL_CMD; 1533 omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
1519 udc->ep0_pending = 0; 1534 udc->ep0_pending = 0;
1520 stat = 0; 1535 stat = 0;
1521 } else if (stat == 0) 1536 } else if (stat == 0)
1522 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1537 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1523 UDC_EP_NUM_REG = 0; 1538 omap_writew(0, UDC_EP_NUM);
1524 1539
1525 /* activate status stage */ 1540 /* activate status stage */
1526 if (stat == 1) { 1541 if (stat == 1) {
1527 done(ep0, req, 0); 1542 done(ep0, req, 0);
1528 /* that may have STALLed ep0... */ 1543 /* that may have STALLed ep0... */
1529 UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR; 1544 omap_writew(UDC_EP_SEL | UDC_EP_DIR,
1530 UDC_CTRL_REG = UDC_CLR_EP; 1545 UDC_EP_NUM);
1531 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1546 omap_writew(UDC_CLR_EP, UDC_CTRL);
1532 UDC_EP_NUM_REG = UDC_EP_DIR; 1547 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1548 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
1533 udc->ep0_pending = 0; 1549 udc->ep0_pending = 0;
1534 } 1550 }
1535 } else { 1551 } else {
1536 /* ack status stage of IN transfer */ 1552 /* ack status stage of IN transfer */
1537 UDC_EP_NUM_REG = 0; 1553 omap_writew(0, UDC_EP_NUM);
1538 if (req) 1554 if (req)
1539 done(ep0, req, 0); 1555 done(ep0, req, 0);
1540 } 1556 }
1541 } else if (stat & UDC_STALL) { 1557 } else if (stat & UDC_STALL) {
1542 UDC_CTRL_REG = UDC_CLR_HALT; 1558 omap_writew(UDC_CLR_HALT, UDC_CTRL);
1543 UDC_EP_NUM_REG = 0; 1559 omap_writew(0, UDC_EP_NUM);
1544 } else { 1560 } else {
1545 UDC_EP_NUM_REG = 0; 1561 omap_writew(0, UDC_EP_NUM);
1546 } 1562 }
1547 } 1563 }
1548 1564
@@ -1557,14 +1573,14 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1557 1573
1558 /* read the (latest) SETUP message */ 1574 /* read the (latest) SETUP message */
1559 do { 1575 do {
1560 UDC_EP_NUM_REG = UDC_SETUP_SEL; 1576 omap_writew(UDC_SETUP_SEL, UDC_EP_NUM);
1561 /* two bytes at a time */ 1577 /* two bytes at a time */
1562 u.word[0] = UDC_DATA_REG; 1578 u.word[0] = omap_readw(UDC_DATA);
1563 u.word[1] = UDC_DATA_REG; 1579 u.word[1] = omap_readw(UDC_DATA);
1564 u.word[2] = UDC_DATA_REG; 1580 u.word[2] = omap_readw(UDC_DATA);
1565 u.word[3] = UDC_DATA_REG; 1581 u.word[3] = omap_readw(UDC_DATA);
1566 UDC_EP_NUM_REG = 0; 1582 omap_writew(0, UDC_EP_NUM);
1567 } while (UDC_IRQ_SRC_REG & UDC_SETUP); 1583 } while (omap_readw(UDC_IRQ_SRC) & UDC_SETUP);
1568 1584
1569#define w_value le16_to_cpu(u.r.wValue) 1585#define w_value le16_to_cpu(u.r.wValue)
1570#define w_index le16_to_cpu(u.r.wIndex) 1586#define w_index le16_to_cpu(u.r.wIndex)
@@ -1595,9 +1611,9 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1595 * later if it fails the request. 1611 * later if it fails the request.
1596 */ 1612 */
1597 if (udc->ep0_reset_config) 1613 if (udc->ep0_reset_config)
1598 UDC_SYSCON2_REG = UDC_CLR_CFG; 1614 omap_writew(UDC_CLR_CFG, UDC_SYSCON2);
1599 else 1615 else
1600 UDC_SYSCON2_REG = UDC_DEV_CFG; 1616 omap_writew(UDC_DEV_CFG, UDC_SYSCON2);
1601 update_otg(udc); 1617 update_otg(udc);
1602 goto delegate; 1618 goto delegate;
1603 case USB_REQ_CLEAR_FEATURE: 1619 case USB_REQ_CLEAR_FEATURE:
@@ -1615,10 +1631,10 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1615 || !ep->desc) 1631 || !ep->desc)
1616 goto do_stall; 1632 goto do_stall;
1617 use_ep(ep, 0); 1633 use_ep(ep, 0);
1618 UDC_CTRL_REG = udc->clr_halt; 1634 omap_writew(udc->clr_halt, UDC_CTRL);
1619 ep->ackwait = 0; 1635 ep->ackwait = 0;
1620 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1636 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1621 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1637 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1622 ep->ackwait = 1 + ep->double_buf; 1638 ep->ackwait = 1 + ep->double_buf;
1623 } 1639 }
1624 /* NOTE: assumes the host behaves sanely, 1640 /* NOTE: assumes the host behaves sanely,
@@ -1651,15 +1667,15 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1651 } 1667 }
1652 use_ep(ep, 0); 1668 use_ep(ep, 0);
1653 /* can't halt if fifo isn't empty... */ 1669 /* can't halt if fifo isn't empty... */
1654 UDC_CTRL_REG = UDC_CLR_EP; 1670 omap_writew(UDC_CLR_EP, UDC_CTRL);
1655 UDC_CTRL_REG = UDC_SET_HALT; 1671 omap_writew(UDC_SET_HALT, UDC_CTRL);
1656 VDBG("%s halted by host\n", ep->name); 1672 VDBG("%s halted by host\n", ep->name);
1657ep0out_status_stage: 1673ep0out_status_stage:
1658 status = 0; 1674 status = 0;
1659 UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR; 1675 omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM);
1660 UDC_CTRL_REG = UDC_CLR_EP; 1676 omap_writew(UDC_CLR_EP, UDC_CTRL);
1661 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1677 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1662 UDC_EP_NUM_REG = UDC_EP_DIR; 1678 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
1663 udc->ep0_pending = 0; 1679 udc->ep0_pending = 0;
1664 break; 1680 break;
1665 case USB_REQ_GET_STATUS: 1681 case USB_REQ_GET_STATUS:
@@ -1696,10 +1712,10 @@ intf_status:
1696 1712
1697zero_status: 1713zero_status:
1698 /* return two zero bytes */ 1714 /* return two zero bytes */
1699 UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR; 1715 omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM);
1700 UDC_DATA_REG = 0; 1716 omap_writew(0, UDC_DATA);
1701 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1717 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1702 UDC_EP_NUM_REG = UDC_EP_DIR; 1718 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
1703 status = 0; 1719 status = 0;
1704 VDBG("GET_STATUS, interface %d\n", w_index); 1720 VDBG("GET_STATUS, interface %d\n", w_index);
1705 /* next, status stage */ 1721 /* next, status stage */
@@ -1708,8 +1724,8 @@ zero_status:
1708delegate: 1724delegate:
1709 /* activate the ep0out fifo right away */ 1725 /* activate the ep0out fifo right away */
1710 if (!udc->ep0_in && w_length) { 1726 if (!udc->ep0_in && w_length) {
1711 UDC_EP_NUM_REG = 0; 1727 omap_writew(0, UDC_EP_NUM);
1712 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1728 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1713 } 1729 }
1714 1730
1715 /* gadget drivers see class/vendor specific requests, 1731 /* gadget drivers see class/vendor specific requests,
@@ -1750,9 +1766,9 @@ do_stall:
1750 if (udc->ep0_reset_config) 1766 if (udc->ep0_reset_config)
1751 WARN("error resetting config?\n"); 1767 WARN("error resetting config?\n");
1752 else 1768 else
1753 UDC_SYSCON2_REG = UDC_CLR_CFG; 1769 omap_writew(UDC_CLR_CFG, UDC_SYSCON2);
1754 } 1770 }
1755 UDC_SYSCON2_REG = UDC_STALL_CMD; 1771 omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
1756 udc->ep0_pending = 0; 1772 udc->ep0_pending = 0;
1757 } 1773 }
1758 } 1774 }
@@ -1766,7 +1782,7 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1766{ 1782{
1767 u16 devstat, change; 1783 u16 devstat, change;
1768 1784
1769 devstat = UDC_DEVSTAT_REG; 1785 devstat = omap_readw(UDC_DEVSTAT);
1770 change = devstat ^ udc->devstat; 1786 change = devstat ^ udc->devstat;
1771 udc->devstat = devstat; 1787 udc->devstat = devstat;
1772 1788
@@ -1806,7 +1822,8 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1806 INFO("USB reset done, gadget %s\n", 1822 INFO("USB reset done, gadget %s\n",
1807 udc->driver->driver.name); 1823 udc->driver->driver.name);
1808 /* ep0 traffic is legal from now on */ 1824 /* ep0 traffic is legal from now on */
1809 UDC_IRQ_EN_REG = UDC_DS_CHG_IE | UDC_EP0_IE; 1825 omap_writew(UDC_DS_CHG_IE | UDC_EP0_IE,
1826 UDC_IRQ_EN);
1810 } 1827 }
1811 change &= ~UDC_USB_RESET; 1828 change &= ~UDC_USB_RESET;
1812 } 1829 }
@@ -1850,7 +1867,7 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1850 VDBG("devstat %03x, ignore change %03x\n", 1867 VDBG("devstat %03x, ignore change %03x\n",
1851 devstat, change); 1868 devstat, change);
1852 1869
1853 UDC_IRQ_SRC_REG = UDC_DS_CHG; 1870 omap_writew(UDC_DS_CHG, UDC_IRQ_SRC);
1854} 1871}
1855 1872
1856static irqreturn_t omap_udc_irq(int irq, void *_udc) 1873static irqreturn_t omap_udc_irq(int irq, void *_udc)
@@ -1861,7 +1878,7 @@ static irqreturn_t omap_udc_irq(int irq, void *_udc)
1861 unsigned long flags; 1878 unsigned long flags;
1862 1879
1863 spin_lock_irqsave(&udc->lock, flags); 1880 spin_lock_irqsave(&udc->lock, flags);
1864 irq_src = UDC_IRQ_SRC_REG; 1881 irq_src = omap_readw(UDC_IRQ_SRC);
1865 1882
1866 /* Device state change (usb ch9 stuff) */ 1883 /* Device state change (usb ch9 stuff) */
1867 if (irq_src & UDC_DS_CHG) { 1884 if (irq_src & UDC_DS_CHG) {
@@ -1884,7 +1901,7 @@ static irqreturn_t omap_udc_irq(int irq, void *_udc)
1884 irq_src &= ~(UDC_TXN_DONE|UDC_RXN_CNT|UDC_RXN_EOT); 1901 irq_src &= ~(UDC_TXN_DONE|UDC_RXN_CNT|UDC_RXN_EOT);
1885 } 1902 }
1886 1903
1887 irq_src &= ~(UDC_SOF|UDC_EPN_TX|UDC_EPN_RX); 1904 irq_src &= ~(UDC_IRQ_SOF | UDC_EPN_TX|UDC_EPN_RX);
1888 if (irq_src) 1905 if (irq_src)
1889 DBG("udc_irq, unhandled %03x\n", irq_src); 1906 DBG("udc_irq, unhandled %03x\n", irq_src);
1890 spin_unlock_irqrestore(&udc->lock, flags); 1907 spin_unlock_irqrestore(&udc->lock, flags);
@@ -1905,7 +1922,7 @@ static void pio_out_timer(unsigned long _ep)
1905 spin_lock_irqsave(&ep->udc->lock, flags); 1922 spin_lock_irqsave(&ep->udc->lock, flags);
1906 if (!list_empty(&ep->queue) && ep->ackwait) { 1923 if (!list_empty(&ep->queue) && ep->ackwait) {
1907 use_ep(ep, UDC_EP_SEL); 1924 use_ep(ep, UDC_EP_SEL);
1908 stat_flg = UDC_STAT_FLG_REG; 1925 stat_flg = omap_readw(UDC_STAT_FLG);
1909 1926
1910 if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN) 1927 if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN)
1911 || (ep->double_buf && HALF_FULL(stat_flg)))) { 1928 || (ep->double_buf && HALF_FULL(stat_flg)))) {
@@ -1915,8 +1932,8 @@ static void pio_out_timer(unsigned long _ep)
1915 req = container_of(ep->queue.next, 1932 req = container_of(ep->queue.next,
1916 struct omap_req, queue); 1933 struct omap_req, queue);
1917 (void) read_fifo(ep, req); 1934 (void) read_fifo(ep, req);
1918 UDC_EP_NUM_REG = ep->bEndpointAddress; 1935 omap_writew(ep->bEndpointAddress, UDC_EP_NUM);
1919 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1936 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1920 ep->ackwait = 1 + ep->double_buf; 1937 ep->ackwait = 1 + ep->double_buf;
1921 } else 1938 } else
1922 deselect_ep(); 1939 deselect_ep();
@@ -1936,20 +1953,20 @@ static irqreturn_t omap_udc_pio_irq(int irq, void *_dev)
1936 unsigned long flags; 1953 unsigned long flags;
1937 1954
1938 spin_lock_irqsave(&udc->lock, flags); 1955 spin_lock_irqsave(&udc->lock, flags);
1939 epn_stat = UDC_EPN_STAT_REG; 1956 epn_stat = omap_readw(UDC_EPN_STAT);
1940 irq_src = UDC_IRQ_SRC_REG; 1957 irq_src = omap_readw(UDC_IRQ_SRC);
1941 1958
1942 /* handle OUT first, to avoid some wasteful NAKs */ 1959 /* handle OUT first, to avoid some wasteful NAKs */
1943 if (irq_src & UDC_EPN_RX) { 1960 if (irq_src & UDC_EPN_RX) {
1944 epnum = (epn_stat >> 8) & 0x0f; 1961 epnum = (epn_stat >> 8) & 0x0f;
1945 UDC_IRQ_SRC_REG = UDC_EPN_RX; 1962 omap_writew(UDC_EPN_RX, UDC_IRQ_SRC);
1946 status = IRQ_HANDLED; 1963 status = IRQ_HANDLED;
1947 ep = &udc->ep[epnum]; 1964 ep = &udc->ep[epnum];
1948 ep->irqs++; 1965 ep->irqs++;
1949 1966
1950 UDC_EP_NUM_REG = epnum | UDC_EP_SEL; 1967 omap_writew(epnum | UDC_EP_SEL, UDC_EP_NUM);
1951 ep->fnf = 0; 1968 ep->fnf = 0;
1952 if ((UDC_STAT_FLG_REG & UDC_ACK)) { 1969 if (omap_readw(UDC_STAT_FLG) & UDC_ACK) {
1953 ep->ackwait--; 1970 ep->ackwait--;
1954 if (!list_empty(&ep->queue)) { 1971 if (!list_empty(&ep->queue)) {
1955 int stat; 1972 int stat;
@@ -1961,15 +1978,15 @@ static irqreturn_t omap_udc_pio_irq(int irq, void *_dev)
1961 } 1978 }
1962 } 1979 }
1963 /* min 6 clock delay before clearing EP_SEL ... */ 1980 /* min 6 clock delay before clearing EP_SEL ... */
1964 epn_stat = UDC_EPN_STAT_REG; 1981 epn_stat = omap_readw(UDC_EPN_STAT);
1965 epn_stat = UDC_EPN_STAT_REG; 1982 epn_stat = omap_readw(UDC_EPN_STAT);
1966 UDC_EP_NUM_REG = epnum; 1983 omap_writew(epnum, UDC_EP_NUM);
1967 1984
1968 /* enabling fifo _after_ clearing ACK, contrary to docs, 1985 /* enabling fifo _after_ clearing ACK, contrary to docs,
1969 * reduces lossage; timer still needed though (sigh). 1986 * reduces lossage; timer still needed though (sigh).
1970 */ 1987 */
1971 if (ep->fnf) { 1988 if (ep->fnf) {
1972 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1989 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1973 ep->ackwait = 1 + ep->double_buf; 1990 ep->ackwait = 1 + ep->double_buf;
1974 } 1991 }
1975 mod_timer(&ep->timer, PIO_OUT_TIMEOUT); 1992 mod_timer(&ep->timer, PIO_OUT_TIMEOUT);
@@ -1978,13 +1995,13 @@ static irqreturn_t omap_udc_pio_irq(int irq, void *_dev)
1978 /* then IN transfers */ 1995 /* then IN transfers */
1979 else if (irq_src & UDC_EPN_TX) { 1996 else if (irq_src & UDC_EPN_TX) {
1980 epnum = epn_stat & 0x0f; 1997 epnum = epn_stat & 0x0f;
1981 UDC_IRQ_SRC_REG = UDC_EPN_TX; 1998 omap_writew(UDC_EPN_TX, UDC_IRQ_SRC);
1982 status = IRQ_HANDLED; 1999 status = IRQ_HANDLED;
1983 ep = &udc->ep[16 + epnum]; 2000 ep = &udc->ep[16 + epnum];
1984 ep->irqs++; 2001 ep->irqs++;
1985 2002
1986 UDC_EP_NUM_REG = epnum | UDC_EP_DIR | UDC_EP_SEL; 2003 omap_writew(epnum | UDC_EP_DIR | UDC_EP_SEL, UDC_EP_NUM);
1987 if ((UDC_STAT_FLG_REG & UDC_ACK)) { 2004 if (omap_readw(UDC_STAT_FLG) & UDC_ACK) {
1988 ep->ackwait = 0; 2005 ep->ackwait = 0;
1989 if (!list_empty(&ep->queue)) { 2006 if (!list_empty(&ep->queue)) {
1990 req = container_of(ep->queue.next, 2007 req = container_of(ep->queue.next,
@@ -1993,9 +2010,9 @@ static irqreturn_t omap_udc_pio_irq(int irq, void *_dev)
1993 } 2010 }
1994 } 2011 }
1995 /* min 6 clock delay before clearing EP_SEL ... */ 2012 /* min 6 clock delay before clearing EP_SEL ... */
1996 epn_stat = UDC_EPN_STAT_REG; 2013 epn_stat = omap_readw(UDC_EPN_STAT);
1997 epn_stat = UDC_EPN_STAT_REG; 2014 epn_stat = omap_readw(UDC_EPN_STAT);
1998 UDC_EP_NUM_REG = epnum | UDC_EP_DIR; 2015 omap_writew(epnum | UDC_EP_DIR, UDC_EP_NUM);
1999 /* then 6 clocks before it'd tx */ 2016 /* then 6 clocks before it'd tx */
2000 } 2017 }
2001 2018
@@ -2023,7 +2040,7 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
2023 req = list_entry(ep->queue.next, struct omap_req, queue); 2040 req = list_entry(ep->queue.next, struct omap_req, queue);
2024 2041
2025 use_ep(ep, UDC_EP_SEL); 2042 use_ep(ep, UDC_EP_SEL);
2026 stat = UDC_STAT_FLG_REG; 2043 stat = omap_readw(UDC_STAT_FLG);
2027 2044
2028 /* NOTE: like the other controller drivers, this isn't 2045 /* NOTE: like the other controller drivers, this isn't
2029 * currently reporting lost or damaged frames. 2046 * currently reporting lost or damaged frames.
@@ -2055,9 +2072,14 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
2055 if (!list_empty(&ep->queue)) 2072 if (!list_empty(&ep->queue))
2056 pending = 1; 2073 pending = 1;
2057 } 2074 }
2058 if (!pending) 2075 if (!pending) {
2059 UDC_IRQ_EN_REG &= ~UDC_SOF_IE; 2076 u16 w;
2060 UDC_IRQ_SRC_REG = UDC_SOF; 2077
2078 w = omap_readw(UDC_IRQ_EN);
2079 w &= ~UDC_SOF_IE;
2080 omap_writew(w, UDC_IRQ_EN);
2081 }
2082 omap_writew(UDC_IRQ_SOF, UDC_IRQ_SRC);
2061 2083
2062 spin_unlock_irqrestore(&udc->lock, flags); 2084 spin_unlock_irqrestore(&udc->lock, flags);
2063 return IRQ_HANDLED; 2085 return IRQ_HANDLED;
@@ -2106,7 +2128,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2106 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) 2128 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
2107 continue; 2129 continue;
2108 use_ep(ep, 0); 2130 use_ep(ep, 0);
2109 UDC_CTRL_REG = UDC_SET_HALT; 2131 omap_writew(UDC_SET_HALT, UDC_CTRL);
2110 } 2132 }
2111 udc->ep0_pending = 0; 2133 udc->ep0_pending = 0;
2112 udc->ep[0].irqs = 0; 2134 udc->ep[0].irqs = 0;
@@ -2130,7 +2152,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2130 } 2152 }
2131 DBG("bound to driver %s\n", driver->driver.name); 2153 DBG("bound to driver %s\n", driver->driver.name);
2132 2154
2133 UDC_IRQ_SRC_REG = UDC_IRQ_SRC_MASK; 2155 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
2134 2156
2135 /* connect to bus through transceiver */ 2157 /* connect to bus through transceiver */
2136 if (udc->transceiver) { 2158 if (udc->transceiver) {
@@ -2227,7 +2249,7 @@ static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2227 else 2249 else
2228 buf[0] = 0; 2250 buf[0] = 0;
2229 2251
2230 stat_flg = UDC_STAT_FLG_REG; 2252 stat_flg = omap_readw(UDC_STAT_FLG);
2231 seq_printf(s, 2253 seq_printf(s,
2232 "\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n", 2254 "\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n",
2233 ep->name, buf, 2255 ep->name, buf,
@@ -2294,11 +2316,11 @@ static int proc_otg_show(struct seq_file *s)
2294 trans = CONTROL_DEVCONF_REG; 2316 trans = CONTROL_DEVCONF_REG;
2295 } else { 2317 } else {
2296 ctrl_name = "tranceiver_ctrl"; 2318 ctrl_name = "tranceiver_ctrl";
2297 trans = USB_TRANSCEIVER_CTRL_REG; 2319 trans = omap_readw(USB_TRANSCEIVER_CTRL);
2298 } 2320 }
2299 seq_printf(s, "\nOTG rev %d.%d, %s %05x\n", 2321 seq_printf(s, "\nOTG rev %d.%d, %s %05x\n",
2300 tmp >> 4, tmp & 0xf, ctrl_name, trans); 2322 tmp >> 4, tmp & 0xf, ctrl_name, trans);
2301 tmp = OTG_SYSCON_1_REG; 2323 tmp = omap_readw(OTG_SYSCON_1);
2302 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," 2324 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s,"
2303 FOURBITS "\n", tmp, 2325 FOURBITS "\n", tmp,
2304 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R), 2326 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R),
@@ -2310,7 +2332,7 @@ static int proc_otg_show(struct seq_file *s)
2310 (tmp & HST_IDLE_EN) ? " !host" : "", 2332 (tmp & HST_IDLE_EN) ? " !host" : "",
2311 (tmp & DEV_IDLE_EN) ? " !dev" : "", 2333 (tmp & DEV_IDLE_EN) ? " !dev" : "",
2312 (tmp & OTG_RESET_DONE) ? " reset_done" : " reset_active"); 2334 (tmp & OTG_RESET_DONE) ? " reset_done" : " reset_active");
2313 tmp = OTG_SYSCON_2_REG; 2335 tmp = omap_readl(OTG_SYSCON_2);
2314 seq_printf(s, "otg_syscon2 %08x%s" EIGHTBITS 2336 seq_printf(s, "otg_syscon2 %08x%s" EIGHTBITS
2315 " b_ase_brst=%d hmc=%d\n", tmp, 2337 " b_ase_brst=%d hmc=%d\n", tmp,
2316 (tmp & OTG_EN) ? " otg_en" : "", 2338 (tmp & OTG_EN) ? " otg_en" : "",
@@ -2325,7 +2347,7 @@ static int proc_otg_show(struct seq_file *s)
2325 (tmp & HMC_TLLATTACH) ? " tllattach" : "", 2347 (tmp & HMC_TLLATTACH) ? " tllattach" : "",
2326 B_ASE_BRST(tmp), 2348 B_ASE_BRST(tmp),
2327 OTG_HMC(tmp)); 2349 OTG_HMC(tmp));
2328 tmp = OTG_CTRL_REG; 2350 tmp = omap_readl(OTG_CTRL);
2329 seq_printf(s, "otg_ctrl %06x" EIGHTBITS EIGHTBITS "%s\n", tmp, 2351 seq_printf(s, "otg_ctrl %06x" EIGHTBITS EIGHTBITS "%s\n", tmp,
2330 (tmp & OTG_ASESSVLD) ? " asess" : "", 2352 (tmp & OTG_ASESSVLD) ? " asess" : "",
2331 (tmp & OTG_BSESSEND) ? " bsess_end" : "", 2353 (tmp & OTG_BSESSEND) ? " bsess_end" : "",
@@ -2345,13 +2367,13 @@ static int proc_otg_show(struct seq_file *s)
2345 (tmp & OTG_PU_VBUS) ? " pu_vb" : "", 2367 (tmp & OTG_PU_VBUS) ? " pu_vb" : "",
2346 (tmp & OTG_PU_ID) ? " pu_id" : "" 2368 (tmp & OTG_PU_ID) ? " pu_id" : ""
2347 ); 2369 );
2348 tmp = OTG_IRQ_EN_REG; 2370 tmp = omap_readw(OTG_IRQ_EN);
2349 seq_printf(s, "otg_irq_en %04x" "\n", tmp); 2371 seq_printf(s, "otg_irq_en %04x" "\n", tmp);
2350 tmp = OTG_IRQ_SRC_REG; 2372 tmp = omap_readw(OTG_IRQ_SRC);
2351 seq_printf(s, "otg_irq_src %04x" "\n", tmp); 2373 seq_printf(s, "otg_irq_src %04x" "\n", tmp);
2352 tmp = OTG_OUTCTRL_REG; 2374 tmp = omap_readw(OTG_OUTCTRL);
2353 seq_printf(s, "otg_outctrl %04x" "\n", tmp); 2375 seq_printf(s, "otg_outctrl %04x" "\n", tmp);
2354 tmp = OTG_TEST_REG; 2376 tmp = omap_readw(OTG_TEST);
2355 seq_printf(s, "otg_test %04x" "\n", tmp); 2377 seq_printf(s, "otg_test %04x" "\n", tmp);
2356 return 0; 2378 return 0;
2357} 2379}
@@ -2372,7 +2394,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2372 driver_desc, 2394 driver_desc,
2373 use_dma ? " (dma)" : ""); 2395 use_dma ? " (dma)" : "");
2374 2396
2375 tmp = UDC_REV_REG & 0xff; 2397 tmp = omap_readw(UDC_REV) & 0xff;
2376 seq_printf(s, 2398 seq_printf(s,
2377 "UDC rev %d.%d, fifo mode %d, gadget %s\n" 2399 "UDC rev %d.%d, fifo mode %d, gadget %s\n"
2378 "hmc %d, transceiver %s\n", 2400 "hmc %d, transceiver %s\n",
@@ -2386,16 +2408,16 @@ static int proc_udc_show(struct seq_file *s, void *_)
2386 ? "external" : "(none)")); 2408 ? "external" : "(none)"));
2387 if (cpu_class_is_omap1()) { 2409 if (cpu_class_is_omap1()) {
2388 seq_printf(s, "ULPD control %04x req %04x status %04x\n", 2410 seq_printf(s, "ULPD control %04x req %04x status %04x\n",
2389 __REG16(ULPD_CLOCK_CTRL), 2411 omap_readw(ULPD_CLOCK_CTRL),
2390 __REG16(ULPD_SOFT_REQ), 2412 omap_readw(ULPD_SOFT_REQ),
2391 __REG16(ULPD_STATUS_REQ)); 2413 omap_readw(ULPD_STATUS_REQ));
2392 } 2414 }
2393 2415
2394 /* OTG controller registers */ 2416 /* OTG controller registers */
2395 if (!cpu_is_omap15xx()) 2417 if (!cpu_is_omap15xx())
2396 proc_otg_show(s); 2418 proc_otg_show(s);
2397 2419
2398 tmp = UDC_SYSCON1_REG; 2420 tmp = omap_readw(UDC_SYSCON1);
2399 seq_printf(s, "\nsyscon1 %04x" EIGHTBITS "\n", tmp, 2421 seq_printf(s, "\nsyscon1 %04x" EIGHTBITS "\n", tmp,
2400 (tmp & UDC_CFG_LOCK) ? " cfg_lock" : "", 2422 (tmp & UDC_CFG_LOCK) ? " cfg_lock" : "",
2401 (tmp & UDC_DATA_ENDIAN) ? " data_endian" : "", 2423 (tmp & UDC_DATA_ENDIAN) ? " data_endian" : "",
@@ -2414,7 +2436,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2414 return 0; 2436 return 0;
2415 } 2437 }
2416 2438
2417 tmp = UDC_DEVSTAT_REG; 2439 tmp = omap_readw(UDC_DEVSTAT);
2418 seq_printf(s, "devstat %04x" EIGHTBITS "%s%s\n", tmp, 2440 seq_printf(s, "devstat %04x" EIGHTBITS "%s%s\n", tmp,
2419 (tmp & UDC_B_HNP_ENABLE) ? " b_hnp" : "", 2441 (tmp & UDC_B_HNP_ENABLE) ? " b_hnp" : "",
2420 (tmp & UDC_A_HNP_SUPPORT) ? " a_hnp" : "", 2442 (tmp & UDC_A_HNP_SUPPORT) ? " a_hnp" : "",
@@ -2426,20 +2448,20 @@ static int proc_udc_show(struct seq_file *s, void *_)
2426 (tmp & UDC_ADD) ? " ADD" : "", 2448 (tmp & UDC_ADD) ? " ADD" : "",
2427 (tmp & UDC_DEF) ? " DEF" : "", 2449 (tmp & UDC_DEF) ? " DEF" : "",
2428 (tmp & UDC_ATT) ? " ATT" : ""); 2450 (tmp & UDC_ATT) ? " ATT" : "");
2429 seq_printf(s, "sof %04x\n", UDC_SOF_REG); 2451 seq_printf(s, "sof %04x\n", omap_readw(UDC_SOF));
2430 tmp = UDC_IRQ_EN_REG; 2452 tmp = omap_readw(UDC_IRQ_EN);
2431 seq_printf(s, "irq_en %04x" FOURBITS "%s\n", tmp, 2453 seq_printf(s, "irq_en %04x" FOURBITS "%s\n", tmp,
2432 (tmp & UDC_SOF_IE) ? " sof" : "", 2454 (tmp & UDC_SOF_IE) ? " sof" : "",
2433 (tmp & UDC_EPN_RX_IE) ? " epn_rx" : "", 2455 (tmp & UDC_EPN_RX_IE) ? " epn_rx" : "",
2434 (tmp & UDC_EPN_TX_IE) ? " epn_tx" : "", 2456 (tmp & UDC_EPN_TX_IE) ? " epn_tx" : "",
2435 (tmp & UDC_DS_CHG_IE) ? " ds_chg" : "", 2457 (tmp & UDC_DS_CHG_IE) ? " ds_chg" : "",
2436 (tmp & UDC_EP0_IE) ? " ep0" : ""); 2458 (tmp & UDC_EP0_IE) ? " ep0" : "");
2437 tmp = UDC_IRQ_SRC_REG; 2459 tmp = omap_readw(UDC_IRQ_SRC);
2438 seq_printf(s, "irq_src %04x" EIGHTBITS "%s%s\n", tmp, 2460 seq_printf(s, "irq_src %04x" EIGHTBITS "%s%s\n", tmp,
2439 (tmp & UDC_TXN_DONE) ? " txn_done" : "", 2461 (tmp & UDC_TXN_DONE) ? " txn_done" : "",
2440 (tmp & UDC_RXN_CNT) ? " rxn_cnt" : "", 2462 (tmp & UDC_RXN_CNT) ? " rxn_cnt" : "",
2441 (tmp & UDC_RXN_EOT) ? " rxn_eot" : "", 2463 (tmp & UDC_RXN_EOT) ? " rxn_eot" : "",
2442 (tmp & UDC_SOF) ? " sof" : "", 2464 (tmp & UDC_IRQ_SOF) ? " sof" : "",
2443 (tmp & UDC_EPN_RX) ? " epn_rx" : "", 2465 (tmp & UDC_EPN_RX) ? " epn_rx" : "",
2444 (tmp & UDC_EPN_TX) ? " epn_tx" : "", 2466 (tmp & UDC_EPN_TX) ? " epn_tx" : "",
2445 (tmp & UDC_DS_CHG) ? " ds_chg" : "", 2467 (tmp & UDC_DS_CHG) ? " ds_chg" : "",
@@ -2449,7 +2471,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2449 if (use_dma) { 2471 if (use_dma) {
2450 unsigned i; 2472 unsigned i;
2451 2473
2452 tmp = UDC_DMA_IRQ_EN_REG; 2474 tmp = omap_readw(UDC_DMA_IRQ_EN);
2453 seq_printf(s, "dma_irq_en %04x%s" EIGHTBITS "\n", tmp, 2475 seq_printf(s, "dma_irq_en %04x%s" EIGHTBITS "\n", tmp,
2454 (tmp & UDC_TX_DONE_IE(3)) ? " tx2_done" : "", 2476 (tmp & UDC_TX_DONE_IE(3)) ? " tx2_done" : "",
2455 (tmp & UDC_RX_CNT_IE(3)) ? " rx2_cnt" : "", 2477 (tmp & UDC_RX_CNT_IE(3)) ? " rx2_cnt" : "",
@@ -2463,29 +2485,29 @@ static int proc_udc_show(struct seq_file *s, void *_)
2463 (tmp & UDC_RX_CNT_IE(1)) ? " rx0_cnt" : "", 2485 (tmp & UDC_RX_CNT_IE(1)) ? " rx0_cnt" : "",
2464 (tmp & UDC_RX_EOT_IE(1)) ? " rx0_eot" : ""); 2486 (tmp & UDC_RX_EOT_IE(1)) ? " rx0_eot" : "");
2465 2487
2466 tmp = UDC_RXDMA_CFG_REG; 2488 tmp = omap_readw(UDC_RXDMA_CFG);
2467 seq_printf(s, "rxdma_cfg %04x\n", tmp); 2489 seq_printf(s, "rxdma_cfg %04x\n", tmp);
2468 if (tmp) { 2490 if (tmp) {
2469 for (i = 0; i < 3; i++) { 2491 for (i = 0; i < 3; i++) {
2470 if ((tmp & (0x0f << (i * 4))) == 0) 2492 if ((tmp & (0x0f << (i * 4))) == 0)
2471 continue; 2493 continue;
2472 seq_printf(s, "rxdma[%d] %04x\n", i, 2494 seq_printf(s, "rxdma[%d] %04x\n", i,
2473 UDC_RXDMA_REG(i + 1)); 2495 omap_readw(UDC_RXDMA(i + 1)));
2474 } 2496 }
2475 } 2497 }
2476 tmp = UDC_TXDMA_CFG_REG; 2498 tmp = omap_readw(UDC_TXDMA_CFG);
2477 seq_printf(s, "txdma_cfg %04x\n", tmp); 2499 seq_printf(s, "txdma_cfg %04x\n", tmp);
2478 if (tmp) { 2500 if (tmp) {
2479 for (i = 0; i < 3; i++) { 2501 for (i = 0; i < 3; i++) {
2480 if (!(tmp & (0x0f << (i * 4)))) 2502 if (!(tmp & (0x0f << (i * 4))))
2481 continue; 2503 continue;
2482 seq_printf(s, "txdma[%d] %04x\n", i, 2504 seq_printf(s, "txdma[%d] %04x\n", i,
2483 UDC_TXDMA_REG(i + 1)); 2505 omap_readw(UDC_TXDMA(i + 1)));
2484 } 2506 }
2485 } 2507 }
2486 } 2508 }
2487 2509
2488 tmp = UDC_DEVSTAT_REG; 2510 tmp = omap_readw(UDC_DEVSTAT);
2489 if (tmp & UDC_ATT) { 2511 if (tmp & UDC_ATT) {
2490 proc_ep_show(s, &udc->ep[0]); 2512 proc_ep_show(s, &udc->ep[0]);
2491 if (tmp & UDC_ADD) { 2513 if (tmp & UDC_ADD) {
@@ -2506,6 +2528,7 @@ static int proc_udc_open(struct inode *inode, struct file *file)
2506} 2528}
2507 2529
2508static const struct file_operations proc_ops = { 2530static const struct file_operations proc_ops = {
2531 .owner = THIS_MODULE,
2509 .open = proc_udc_open, 2532 .open = proc_udc_open,
2510 .read = seq_read, 2533 .read = seq_read,
2511 .llseek = seq_lseek, 2534 .llseek = seq_lseek,
@@ -2514,11 +2537,7 @@ static const struct file_operations proc_ops = {
2514 2537
2515static void create_proc_file(void) 2538static void create_proc_file(void)
2516{ 2539{
2517 struct proc_dir_entry *pde; 2540 proc_create(proc_filename, 0, NULL, &proc_ops);
2518
2519 pde = create_proc_entry (proc_filename, 0, NULL);
2520 if (pde)
2521 pde->proc_fops = &proc_ops;
2522} 2541}
2523 2542
2524static void remove_proc_file(void) 2543static void remove_proc_file(void)
@@ -2540,7 +2559,7 @@ static inline void remove_proc_file(void) {}
2540 * buffer space among the endpoints we'll be operating. 2559 * buffer space among the endpoints we'll be operating.
2541 * 2560 *
2542 * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when 2561 * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when
2543 * UDC_SYSCON_1_REG.CFG_LOCK is set can now work. We won't use that 2562 * UDC_SYSCON_1.CFG_LOCK is set can now work. We won't use that
2544 * capability yet though. 2563 * capability yet though.
2545 */ 2564 */
2546static unsigned __init 2565static unsigned __init
@@ -2602,9 +2621,9 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2602 name, addr, epn_rxtx, maxp, dbuf ? "x2" : "", buf); 2621 name, addr, epn_rxtx, maxp, dbuf ? "x2" : "", buf);
2603 2622
2604 if (addr & USB_DIR_IN) 2623 if (addr & USB_DIR_IN)
2605 UDC_EP_TX_REG(addr & 0xf) = epn_rxtx; 2624 omap_writew(epn_rxtx, UDC_EP_TX(addr & 0xf));
2606 else 2625 else
2607 UDC_EP_RX_REG(addr) = epn_rxtx; 2626 omap_writew(epn_rxtx, UDC_EP_RX(addr));
2608 2627
2609 /* next endpoint's buffer starts after this one's */ 2628 /* next endpoint's buffer starts after this one's */
2610 buf += maxp; 2629 buf += maxp;
@@ -2643,15 +2662,15 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
2643 unsigned tmp, buf; 2662 unsigned tmp, buf;
2644 2663
2645 /* abolish any previous hardware state */ 2664 /* abolish any previous hardware state */
2646 UDC_SYSCON1_REG = 0; 2665 omap_writew(0, UDC_SYSCON1);
2647 UDC_IRQ_EN_REG = 0; 2666 omap_writew(0, UDC_IRQ_EN);
2648 UDC_IRQ_SRC_REG = UDC_IRQ_SRC_MASK; 2667 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
2649 UDC_DMA_IRQ_EN_REG = 0; 2668 omap_writew(0, UDC_DMA_IRQ_EN);
2650 UDC_RXDMA_CFG_REG = 0; 2669 omap_writew(0, UDC_RXDMA_CFG);
2651 UDC_TXDMA_CFG_REG = 0; 2670 omap_writew(0, UDC_TXDMA_CFG);
2652 2671
2653 /* UDC_PULLUP_EN gates the chip clock */ 2672 /* UDC_PULLUP_EN gates the chip clock */
2654 // OTG_SYSCON_1_REG |= DEV_IDLE_EN; 2673 // OTG_SYSCON_1 |= DEV_IDLE_EN;
2655 2674
2656 udc = kzalloc(sizeof(*udc), GFP_KERNEL); 2675 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
2657 if (!udc) 2676 if (!udc)
@@ -2682,8 +2701,8 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
2682 2701
2683 /* initially disable all non-ep0 endpoints */ 2702 /* initially disable all non-ep0 endpoints */
2684 for (tmp = 1; tmp < 15; tmp++) { 2703 for (tmp = 1; tmp < 15; tmp++) {
2685 UDC_EP_RX_REG(tmp) = 0; 2704 omap_writew(0, UDC_EP_RX(tmp));
2686 UDC_EP_TX_REG(tmp) = 0; 2705 omap_writew(0, UDC_EP_TX(tmp));
2687 } 2706 }
2688 2707
2689#define OMAP_BULK_EP(name,addr) \ 2708#define OMAP_BULK_EP(name,addr) \
@@ -2768,7 +2787,7 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
2768 ERR("unsupported fifo_mode #%d\n", fifo_mode); 2787 ERR("unsupported fifo_mode #%d\n", fifo_mode);
2769 return -ENODEV; 2788 return -ENODEV;
2770 } 2789 }
2771 UDC_SYSCON1_REG = UDC_CFG_LOCK|UDC_SELF_PWR; 2790 omap_writew(UDC_CFG_LOCK|UDC_SELF_PWR, UDC_SYSCON1);
2772 INFO("fifo mode %d, %d bytes not used\n", fifo_mode, 2048 - buf); 2791 INFO("fifo mode %d, %d bytes not used\n", fifo_mode, 2048 - buf);
2773 return 0; 2792 return 0;
2774} 2793}
@@ -2812,7 +2831,7 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2812 } 2831 }
2813 2832
2814 INFO("OMAP UDC rev %d.%d%s\n", 2833 INFO("OMAP UDC rev %d.%d%s\n",
2815 UDC_REV_REG >> 4, UDC_REV_REG & 0xf, 2834 omap_readw(UDC_REV) >> 4, omap_readw(UDC_REV) & 0xf,
2816 config->otg ? ", Mini-AB" : ""); 2835 config->otg ? ", Mini-AB" : "");
2817 2836
2818 /* use the mode given to us by board init code */ 2837 /* use the mode given to us by board init code */
@@ -2827,12 +2846,12 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2827 * know when to turn PULLUP_EN on/off; and that 2846 * know when to turn PULLUP_EN on/off; and that
2828 * means we always "need" the 48MHz clock. 2847 * means we always "need" the 48MHz clock.
2829 */ 2848 */
2830 u32 tmp = FUNC_MUX_CTRL_0_REG; 2849 u32 tmp = omap_readl(FUNC_MUX_CTRL_0);
2831 2850 tmp &= ~VBUS_CTRL_1510;
2832 FUNC_MUX_CTRL_0_REG &= ~VBUS_CTRL_1510; 2851 omap_writel(tmp, FUNC_MUX_CTRL_0);
2833 tmp |= VBUS_MODE_1510; 2852 tmp |= VBUS_MODE_1510;
2834 tmp &= ~VBUS_CTRL_1510; 2853 tmp &= ~VBUS_CTRL_1510;
2835 FUNC_MUX_CTRL_0_REG = tmp; 2854 omap_writel(tmp, FUNC_MUX_CTRL_0);
2836 } 2855 }
2837 } else { 2856 } else {
2838 /* The transceiver may package some GPIO logic or handle 2857 /* The transceiver may package some GPIO logic or handle
@@ -2912,7 +2931,7 @@ known:
2912#endif 2931#endif
2913 2932
2914 /* starting with omap1710 es2.0, clear toggle is a separate bit */ 2933 /* starting with omap1710 es2.0, clear toggle is a separate bit */
2915 if (UDC_REV_REG >= 0x61) 2934 if (omap_readw(UDC_REV) >= 0x61)
2916 udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE; 2935 udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE;
2917 else 2936 else
2918 udc->clr_halt = UDC_RESET_EP; 2937 udc->clr_halt = UDC_RESET_EP;
@@ -3010,7 +3029,7 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
3010 put_device(udc->transceiver->dev); 3029 put_device(udc->transceiver->dev);
3011 udc->transceiver = NULL; 3030 udc->transceiver = NULL;
3012 } 3031 }
3013 UDC_SYSCON1_REG = 0; 3032 omap_writew(0, UDC_SYSCON1);
3014 3033
3015 remove_proc_file(); 3034 remove_proc_file();
3016 3035
@@ -3041,7 +3060,7 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
3041 * 3060 *
3042 * REVISIT we should probably reject suspend requests when there's a host 3061 * REVISIT we should probably reject suspend requests when there's a host
3043 * session active, rather than disconnecting, at least on boards that can 3062 * session active, rather than disconnecting, at least on boards that can
3044 * report VBUS irqs (UDC_DEVSTAT_REG.UDC_ATT). And in any case, we need to 3063 * report VBUS irqs (UDC_DEVSTAT.UDC_ATT). And in any case, we need to
3045 * make host resumes and VBUS detection trigger OMAP wakeup events; that 3064 * make host resumes and VBUS detection trigger OMAP wakeup events; that
3046 * may involve talking to an external transceiver (e.g. isp1301). 3065 * may involve talking to an external transceiver (e.g. isp1301).
3047 */ 3066 */
@@ -3050,7 +3069,7 @@ static int omap_udc_suspend(struct platform_device *dev, pm_message_t message)
3050{ 3069{
3051 u32 devstat; 3070 u32 devstat;
3052 3071
3053 devstat = UDC_DEVSTAT_REG; 3072 devstat = omap_readw(UDC_DEVSTAT);
3054 3073
3055 /* we're requesting 48 MHz clock if the pullup is enabled 3074 /* we're requesting 48 MHz clock if the pullup is enabled
3056 * (== we're attached to the host) and we're not suspended, 3075 * (== we're attached to the host) and we're not suspended,
@@ -3061,8 +3080,6 @@ static int omap_udc_suspend(struct platform_device *dev, pm_message_t message)
3061 omap_pullup(&udc->gadget, 0); 3080 omap_pullup(&udc->gadget, 0);
3062 } 3081 }
3063 3082
3064 udc->gadget.dev.power.power_state = PMSG_SUSPEND;
3065 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND;
3066 return 0; 3083 return 0;
3067} 3084}
3068 3085
@@ -3109,4 +3126,4 @@ module_exit(udc_exit);
3109 3126
3110MODULE_DESCRIPTION(DRIVER_DESC); 3127MODULE_DESCRIPTION(DRIVER_DESC);
3111MODULE_LICENSE("GPL"); 3128MODULE_LICENSE("GPL");
3112 3129MODULE_ALIAS("platform:omap_udc");
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h
index c6b9cbc7230a..8522bbb12278 100644
--- a/drivers/usb/gadget/omap_udc.h
+++ b/drivers/usb/gadget/omap_udc.h
@@ -8,23 +8,22 @@
8/* 8/*
9 * USB device/endpoint management registers 9 * USB device/endpoint management registers
10 */ 10 */
11#define UDC_REG(offset) __REG16(UDC_BASE + (offset))
12 11
13#define UDC_REV_REG UDC_REG(0x0) /* Revision */ 12#define UDC_REV (UDC_BASE + 0x0) /* Revision */
14#define UDC_EP_NUM_REG UDC_REG(0x4) /* Which endpoint */ 13#define UDC_EP_NUM (UDC_BASE + 0x4) /* Which endpoint */
15# define UDC_SETUP_SEL (1 << 6) 14# define UDC_SETUP_SEL (1 << 6)
16# define UDC_EP_SEL (1 << 5) 15# define UDC_EP_SEL (1 << 5)
17# define UDC_EP_DIR (1 << 4) 16# define UDC_EP_DIR (1 << 4)
18 /* low 4 bits for endpoint number */ 17 /* low 4 bits for endpoint number */
19#define UDC_DATA_REG UDC_REG(0x08) /* Endpoint FIFO */ 18#define UDC_DATA (UDC_BASE + 0x08) /* Endpoint FIFO */
20#define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */ 19#define UDC_CTRL (UDC_BASE + 0x0C) /* Endpoint control */
21# define UDC_CLR_HALT (1 << 7) 20# define UDC_CLR_HALT (1 << 7)
22# define UDC_SET_HALT (1 << 6) 21# define UDC_SET_HALT (1 << 6)
23# define UDC_CLRDATA_TOGGLE (1 << 3) 22# define UDC_CLRDATA_TOGGLE (1 << 3)
24# define UDC_SET_FIFO_EN (1 << 2) 23# define UDC_SET_FIFO_EN (1 << 2)
25# define UDC_CLR_EP (1 << 1) 24# define UDC_CLR_EP (1 << 1)
26# define UDC_RESET_EP (1 << 0) 25# define UDC_RESET_EP (1 << 0)
27#define UDC_STAT_FLG_REG UDC_REG(0x10) /* Endpoint status */ 26#define UDC_STAT_FLG (UDC_BASE + 0x10) /* Endpoint status */
28# define UDC_NO_RXPACKET (1 << 15) 27# define UDC_NO_RXPACKET (1 << 15)
29# define UDC_MISS_IN (1 << 14) 28# define UDC_MISS_IN (1 << 14)
30# define UDC_DATA_FLUSH (1 << 13) 29# define UDC_DATA_FLUSH (1 << 13)
@@ -38,8 +37,8 @@
38# define UDC_FIFO_EN (1 << 2) 37# define UDC_FIFO_EN (1 << 2)
39# define UDC_NON_ISO_FIFO_EMPTY (1 << 1) 38# define UDC_NON_ISO_FIFO_EMPTY (1 << 1)
40# define UDC_NON_ISO_FIFO_FULL (1 << 0) 39# define UDC_NON_ISO_FIFO_FULL (1 << 0)
41#define UDC_RXFSTAT_REG UDC_REG(0x14) /* OUT bytecount */ 40#define UDC_RXFSTAT (UDC_BASE + 0x14) /* OUT bytecount */
42#define UDC_SYSCON1_REG UDC_REG(0x18) /* System config 1 */ 41#define UDC_SYSCON1 (UDC_BASE + 0x18) /* System config 1 */
43# define UDC_CFG_LOCK (1 << 8) 42# define UDC_CFG_LOCK (1 << 8)
44# define UDC_DATA_ENDIAN (1 << 7) 43# define UDC_DATA_ENDIAN (1 << 7)
45# define UDC_DMA_ENDIAN (1 << 6) 44# define UDC_DMA_ENDIAN (1 << 6)
@@ -48,12 +47,12 @@
48# define UDC_SELF_PWR (1 << 2) 47# define UDC_SELF_PWR (1 << 2)
49# define UDC_SOFF_DIS (1 << 1) 48# define UDC_SOFF_DIS (1 << 1)
50# define UDC_PULLUP_EN (1 << 0) 49# define UDC_PULLUP_EN (1 << 0)
51#define UDC_SYSCON2_REG UDC_REG(0x1C) /* System config 2 */ 50#define UDC_SYSCON2 (UDC_BASE + 0x1C) /* System config 2 */
52# define UDC_RMT_WKP (1 << 6) 51# define UDC_RMT_WKP (1 << 6)
53# define UDC_STALL_CMD (1 << 5) 52# define UDC_STALL_CMD (1 << 5)
54# define UDC_DEV_CFG (1 << 3) 53# define UDC_DEV_CFG (1 << 3)
55# define UDC_CLR_CFG (1 << 2) 54# define UDC_CLR_CFG (1 << 2)
56#define UDC_DEVSTAT_REG UDC_REG(0x20) /* Device status */ 55#define UDC_DEVSTAT (UDC_BASE + 0x20) /* Device status */
57# define UDC_B_HNP_ENABLE (1 << 9) 56# define UDC_B_HNP_ENABLE (1 << 9)
58# define UDC_A_HNP_SUPPORT (1 << 8) 57# define UDC_A_HNP_SUPPORT (1 << 8)
59# define UDC_A_ALT_HNP_SUPPORT (1 << 7) 58# define UDC_A_ALT_HNP_SUPPORT (1 << 7)
@@ -64,26 +63,26 @@
64# define UDC_ADD (1 << 2) 63# define UDC_ADD (1 << 2)
65# define UDC_DEF (1 << 1) 64# define UDC_DEF (1 << 1)
66# define UDC_ATT (1 << 0) 65# define UDC_ATT (1 << 0)
67#define UDC_SOF_REG UDC_REG(0x24) /* Start of frame */ 66#define UDC_SOF (UDC_BASE + 0x24) /* Start of frame */
68# define UDC_FT_LOCK (1 << 12) 67# define UDC_FT_LOCK (1 << 12)
69# define UDC_TS_OK (1 << 11) 68# define UDC_TS_OK (1 << 11)
70# define UDC_TS 0x03ff 69# define UDC_TS 0x03ff
71#define UDC_IRQ_EN_REG UDC_REG(0x28) /* Interrupt enable */ 70#define UDC_IRQ_EN (UDC_BASE + 0x28) /* Interrupt enable */
72# define UDC_SOF_IE (1 << 7) 71# define UDC_SOF_IE (1 << 7)
73# define UDC_EPN_RX_IE (1 << 5) 72# define UDC_EPN_RX_IE (1 << 5)
74# define UDC_EPN_TX_IE (1 << 4) 73# define UDC_EPN_TX_IE (1 << 4)
75# define UDC_DS_CHG_IE (1 << 3) 74# define UDC_DS_CHG_IE (1 << 3)
76# define UDC_EP0_IE (1 << 0) 75# define UDC_EP0_IE (1 << 0)
77#define UDC_DMA_IRQ_EN_REG UDC_REG(0x2C) /* DMA irq enable */ 76#define UDC_DMA_IRQ_EN (UDC_BASE + 0x2C) /* DMA irq enable */
78 /* rx/tx dma channels numbered 1-3 not 0-2 */ 77 /* rx/tx dma channels numbered 1-3 not 0-2 */
79# define UDC_TX_DONE_IE(n) (1 << (4 * (n) - 2)) 78# define UDC_TX_DONE_IE(n) (1 << (4 * (n) - 2))
80# define UDC_RX_CNT_IE(n) (1 << (4 * (n) - 3)) 79# define UDC_RX_CNT_IE(n) (1 << (4 * (n) - 3))
81# define UDC_RX_EOT_IE(n) (1 << (4 * (n) - 4)) 80# define UDC_RX_EOT_IE(n) (1 << (4 * (n) - 4))
82#define UDC_IRQ_SRC_REG UDC_REG(0x30) /* Interrupt source */ 81#define UDC_IRQ_SRC (UDC_BASE + 0x30) /* Interrupt source */
83# define UDC_TXN_DONE (1 << 10) 82# define UDC_TXN_DONE (1 << 10)
84# define UDC_RXN_CNT (1 << 9) 83# define UDC_RXN_CNT (1 << 9)
85# define UDC_RXN_EOT (1 << 8) 84# define UDC_RXN_EOT (1 << 8)
86# define UDC_SOF (1 << 7) 85# define UDC_IRQ_SOF (1 << 7)
87# define UDC_EPN_RX (1 << 5) 86# define UDC_EPN_RX (1 << 5)
88# define UDC_EPN_TX (1 << 4) 87# define UDC_EPN_TX (1 << 4)
89# define UDC_DS_CHG (1 << 3) 88# define UDC_DS_CHG (1 << 3)
@@ -91,41 +90,41 @@
91# define UDC_EP0_RX (1 << 1) 90# define UDC_EP0_RX (1 << 1)
92# define UDC_EP0_TX (1 << 0) 91# define UDC_EP0_TX (1 << 0)
93# define UDC_IRQ_SRC_MASK 0x7bf 92# define UDC_IRQ_SRC_MASK 0x7bf
94#define UDC_EPN_STAT_REG UDC_REG(0x34) /* EP irq status */ 93#define UDC_EPN_STAT (UDC_BASE + 0x34) /* EP irq status */
95#define UDC_DMAN_STAT_REG UDC_REG(0x38) /* DMA irq status */ 94#define UDC_DMAN_STAT (UDC_BASE + 0x38) /* DMA irq status */
96# define UDC_DMA_RX_SB (1 << 12) 95# define UDC_DMA_RX_SB (1 << 12)
97# define UDC_DMA_RX_SRC(x) (((x)>>8) & 0xf) 96# define UDC_DMA_RX_SRC(x) (((x)>>8) & 0xf)
98# define UDC_DMA_TX_SRC(x) (((x)>>0) & 0xf) 97# define UDC_DMA_TX_SRC(x) (((x)>>0) & 0xf)
99 98
100 99
101/* DMA configuration registers: up to three channels in each direction. */ 100/* DMA configuration registers: up to three channels in each direction. */
102#define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */ 101#define UDC_RXDMA_CFG (UDC_BASE + 0x40) /* 3 eps for RX DMA */
103# define UDC_DMA_REQ (1 << 12) 102# define UDC_DMA_REQ (1 << 12)
104#define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */ 103#define UDC_TXDMA_CFG (UDC_BASE + 0x44) /* 3 eps for TX DMA */
105#define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */ 104#define UDC_DATA_DMA (UDC_BASE + 0x48) /* rx/tx fifo addr */
106 105
107/* rx/tx dma control, numbering channels 1-3 not 0-2 */ 106/* rx/tx dma control, numbering channels 1-3 not 0-2 */
108#define UDC_TXDMA_REG(chan) UDC_REG(0x50 - 4 + 4 * (chan)) 107#define UDC_TXDMA(chan) (UDC_BASE + 0x50 - 4 + 4 * (chan))
109# define UDC_TXN_EOT (1 << 15) /* bytes vs packets */ 108# define UDC_TXN_EOT (1 << 15) /* bytes vs packets */
110# define UDC_TXN_START (1 << 14) /* start transfer */ 109# define UDC_TXN_START (1 << 14) /* start transfer */
111# define UDC_TXN_TSC 0x03ff /* units in xfer */ 110# define UDC_TXN_TSC 0x03ff /* units in xfer */
112#define UDC_RXDMA_REG(chan) UDC_REG(0x60 - 4 + 4 * (chan)) 111#define UDC_RXDMA(chan) (UDC_BASE + 0x60 - 4 + 4 * (chan))
113# define UDC_RXN_STOP (1 << 15) /* enable EOT irq */ 112# define UDC_RXN_STOP (1 << 15) /* enable EOT irq */
114# define UDC_RXN_TC 0x00ff /* packets in xfer */ 113# define UDC_RXN_TC 0x00ff /* packets in xfer */
115 114
116 115
117/* 116/*
118 * Endpoint configuration registers (used before CFG_LOCK is set) 117 * Endpoint configuration registers (used before CFG_LOCK is set)
119 * UDC_EP_TX_REG(0) is unused 118 * UDC_EP_TX(0) is unused
120 */ 119 */
121#define UDC_EP_RX_REG(endpoint) UDC_REG(0x80 + (endpoint)*4) 120#define UDC_EP_RX(endpoint) (UDC_BASE + 0x80 + (endpoint)*4)
122# define UDC_EPN_RX_VALID (1 << 15) 121# define UDC_EPN_RX_VALID (1 << 15)
123# define UDC_EPN_RX_DB (1 << 14) 122# define UDC_EPN_RX_DB (1 << 14)
124 /* buffer size in bits 13, 12 */ 123 /* buffer size in bits 13, 12 */
125# define UDC_EPN_RX_ISO (1 << 11) 124# define UDC_EPN_RX_ISO (1 << 11)
126 /* buffer pointer in low 11 bits */ 125 /* buffer pointer in low 11 bits */
127#define UDC_EP_TX_REG(endpoint) UDC_REG(0xc0 + (endpoint)*4) 126#define UDC_EP_TX(endpoint) (UDC_BASE + 0xc0 + (endpoint)*4)
128 /* same bitfields as in RX_REG */ 127 /* same bitfields as in RX */
129 128
130/*-------------------------------------------------------------------------*/ 129/*-------------------------------------------------------------------------*/
131 130
@@ -195,14 +194,14 @@ struct omap_udc {
195 194
196/*-------------------------------------------------------------------------*/ 195/*-------------------------------------------------------------------------*/
197 196
198#define MOD_CONF_CTRL_0_REG __REG32(MOD_CONF_CTRL_0) 197/* MOD_CONF_CTRL_0 */
199#define VBUS_W2FC_1510 (1 << 17) /* 0 gpio0, 1 dvdd2 pin */ 198#define VBUS_W2FC_1510 (1 << 17) /* 0 gpio0, 1 dvdd2 pin */
200 199
201#define FUNC_MUX_CTRL_0_REG __REG32(FUNC_MUX_CTRL_0) 200/* FUNC_MUX_CTRL_0 */
202#define VBUS_CTRL_1510 (1 << 19) /* 1 connected (software) */ 201#define VBUS_CTRL_1510 (1 << 19) /* 1 connected (software) */
203#define VBUS_MODE_1510 (1 << 18) /* 0 hardware, 1 software */ 202#define VBUS_MODE_1510 (1 << 18) /* 0 hardware, 1 software */
204 203
205#define HMC_1510 ((MOD_CONF_CTRL_0_REG >> 1) & 0x3f) 204#define HMC_1510 ((omap_readl(MOD_CONF_CTRL_0) >> 1) & 0x3f)
206#define HMC_1610 (OTG_SYSCON_2_REG & 0x3f) 205#define HMC_1610 (omap_readl(OTG_SYSCON_2) & 0x3f)
207#define HMC (cpu_is_omap15xx() ? HMC_1510 : HMC_1610) 206#define HMC (cpu_is_omap15xx() ? HMC_1510 : HMC_1610)
208 207
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 2c32bd08ee7d..76be75e3ab8f 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -390,9 +390,12 @@ static void rx_complete(struct usb_ep *ep, struct usb_request *req)
390 390
391 /* normal completion */ 391 /* normal completion */
392 case 0: 392 case 0:
393 list_add_tail(&req->list, &dev->rx_buffers); 393 if (req->actual > 0) {
394 wake_up_interruptible(&dev->rx_wait); 394 list_add_tail(&req->list, &dev->rx_buffers);
395 DBG(dev, "G_Printer : rx length %d\n", req->actual); 395 DBG(dev, "G_Printer : rx length %d\n", req->actual);
396 } else {
397 list_add(&req->list, &dev->rx_reqs);
398 }
396 break; 399 break;
397 400
398 /* software-driven interface shutdown */ 401 /* software-driven interface shutdown */
@@ -417,6 +420,8 @@ static void rx_complete(struct usb_ep *ep, struct usb_request *req)
417 list_add(&req->list, &dev->rx_reqs); 420 list_add(&req->list, &dev->rx_reqs);
418 break; 421 break;
419 } 422 }
423
424 wake_up_interruptible(&dev->rx_wait);
420 spin_unlock_irqrestore(&dev->lock, flags); 425 spin_unlock_irqrestore(&dev->lock, flags);
421} 426}
422 427
@@ -494,6 +499,39 @@ printer_close(struct inode *inode, struct file *fd)
494 return 0; 499 return 0;
495} 500}
496 501
502/* This function must be called with interrupts turned off. */
503static void
504setup_rx_reqs(struct printer_dev *dev)
505{
506 struct usb_request *req;
507
508 while (likely(!list_empty(&dev->rx_reqs))) {
509 int error;
510
511 req = container_of(dev->rx_reqs.next,
512 struct usb_request, list);
513 list_del_init(&req->list);
514
515 /* The USB Host sends us whatever amount of data it wants to
516 * so we always set the length field to the full USB_BUFSIZE.
517 * If the amount of data is more than the read() caller asked
518 * for it will be stored in the request buffer until it is
519 * asked for by read().
520 */
521 req->length = USB_BUFSIZE;
522 req->complete = rx_complete;
523
524 error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
525 if (error) {
526 DBG(dev, "rx submit --> %d\n", error);
527 list_add(&req->list, &dev->rx_reqs);
528 break;
529 } else {
530 list_add(&req->list, &dev->rx_reqs_active);
531 }
532 }
533}
534
497static ssize_t 535static ssize_t
498printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) 536printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
499{ 537{
@@ -522,31 +560,7 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
522 */ 560 */
523 dev->reset_printer = 0; 561 dev->reset_printer = 0;
524 562
525 while (likely(!list_empty(&dev->rx_reqs))) { 563 setup_rx_reqs(dev);
526 int error;
527
528 req = container_of(dev->rx_reqs.next,
529 struct usb_request, list);
530 list_del_init(&req->list);
531
532 /* The USB Host sends us whatever amount of data it wants to
533 * so we always set the length field to the full USB_BUFSIZE.
534 * If the amount of data is more than the read() caller asked
535 * for it will be stored in the request buffer until it is
536 * asked for by read().
537 */
538 req->length = USB_BUFSIZE;
539 req->complete = rx_complete;
540
541 error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
542 if (error) {
543 DBG(dev, "rx submit --> %d\n", error);
544 list_add(&req->list, &dev->rx_reqs);
545 break;
546 } else {
547 list_add(&req->list, &dev->rx_reqs_active);
548 }
549 }
550 564
551 bytes_copied = 0; 565 bytes_copied = 0;
552 current_rx_req = dev->current_rx_req; 566 current_rx_req = dev->current_rx_req;
@@ -615,9 +629,9 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
615 629
616 spin_lock_irqsave(&dev->lock, flags); 630 spin_lock_irqsave(&dev->lock, flags);
617 631
618 /* We've disconnected or reset free the req and buffer */ 632 /* We've disconnected or reset so return. */
619 if (dev->reset_printer) { 633 if (dev->reset_printer) {
620 printer_req_free(dev->out_ep, current_rx_req); 634 list_add(&current_rx_req->list, &dev->rx_reqs);
621 spin_unlock_irqrestore(&dev->lock, flags); 635 spin_unlock_irqrestore(&dev->lock, flags);
622 spin_unlock(&dev->lock_printer_io); 636 spin_unlock(&dev->lock_printer_io);
623 return -EAGAIN; 637 return -EAGAIN;
@@ -735,7 +749,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
735 749
736 /* We've disconnected or reset so free the req and buffer */ 750 /* We've disconnected or reset so free the req and buffer */
737 if (dev->reset_printer) { 751 if (dev->reset_printer) {
738 printer_req_free(dev->in_ep, req); 752 list_add(&req->list, &dev->tx_reqs);
739 spin_unlock_irqrestore(&dev->lock, flags); 753 spin_unlock_irqrestore(&dev->lock, flags);
740 spin_unlock(&dev->lock_printer_io); 754 spin_unlock(&dev->lock_printer_io);
741 return -EAGAIN; 755 return -EAGAIN;
@@ -791,6 +805,12 @@ printer_poll(struct file *fd, poll_table *wait)
791 unsigned long flags; 805 unsigned long flags;
792 int status = 0; 806 int status = 0;
793 807
808 spin_lock(&dev->lock_printer_io);
809 spin_lock_irqsave(&dev->lock, flags);
810 setup_rx_reqs(dev);
811 spin_unlock_irqrestore(&dev->lock, flags);
812 spin_unlock(&dev->lock_printer_io);
813
794 poll_wait(fd, &dev->rx_wait, wait); 814 poll_wait(fd, &dev->rx_wait, wait);
795 poll_wait(fd, &dev->tx_wait, wait); 815 poll_wait(fd, &dev->tx_wait, wait);
796 816
@@ -798,7 +818,8 @@ printer_poll(struct file *fd, poll_table *wait)
798 if (likely(!list_empty(&dev->tx_reqs))) 818 if (likely(!list_empty(&dev->tx_reqs)))
799 status |= POLLOUT | POLLWRNORM; 819 status |= POLLOUT | POLLWRNORM;
800 820
801 if (likely(!list_empty(&dev->rx_buffers))) 821 if (likely(dev->current_rx_bytes) ||
822 likely(!list_empty(&dev->rx_buffers)))
802 status |= POLLIN | POLLRDNORM; 823 status |= POLLIN | POLLRDNORM;
803 824
804 spin_unlock_irqrestore(&dev->lock, flags); 825 spin_unlock_irqrestore(&dev->lock, flags);
@@ -894,7 +915,7 @@ static void printer_reset_interface(struct printer_dev *dev)
894 if (dev->interface < 0) 915 if (dev->interface < 0)
895 return; 916 return;
896 917
897 DBG(dev, "%s\n", __FUNCTION__); 918 DBG(dev, "%s\n", __func__);
898 919
899 if (dev->in) 920 if (dev->in)
900 usb_ep_disable(dev->in_ep); 921 usb_ep_disable(dev->in_ep);
@@ -1084,6 +1105,7 @@ static void printer_soft_reset(struct printer_dev *dev)
1084 if (usb_ep_enable(dev->out_ep, dev->out)) 1105 if (usb_ep_enable(dev->out_ep, dev->out))
1085 DBG(dev, "Failed to enable USB out_ep\n"); 1106 DBG(dev, "Failed to enable USB out_ep\n");
1086 1107
1108 wake_up_interruptible(&dev->rx_wait);
1087 wake_up_interruptible(&dev->tx_wait); 1109 wake_up_interruptible(&dev->tx_wait);
1088 wake_up_interruptible(&dev->tx_flush_wait); 1110 wake_up_interruptible(&dev->tx_flush_wait);
1089} 1111}
@@ -1262,7 +1284,7 @@ printer_disconnect(struct usb_gadget *gadget)
1262 struct printer_dev *dev = get_gadget_data(gadget); 1284 struct printer_dev *dev = get_gadget_data(gadget);
1263 unsigned long flags; 1285 unsigned long flags;
1264 1286
1265 DBG(dev, "%s\n", __FUNCTION__); 1287 DBG(dev, "%s\n", __func__);
1266 1288
1267 spin_lock_irqsave(&dev->lock, flags); 1289 spin_lock_irqsave(&dev->lock, flags);
1268 1290
@@ -1278,7 +1300,7 @@ printer_unbind(struct usb_gadget *gadget)
1278 struct usb_request *req; 1300 struct usb_request *req;
1279 1301
1280 1302
1281 DBG(dev, "%s\n", __FUNCTION__); 1303 DBG(dev, "%s\n", __func__);
1282 1304
1283 /* Remove sysfs files */ 1305 /* Remove sysfs files */
1284 device_destroy(usb_gadget_class, g_printer_devno); 1306 device_destroy(usb_gadget_class, g_printer_devno);
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
new file mode 100644
index 000000000000..e02bfd4df3a6
--- /dev/null
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -0,0 +1,2404 @@
1/*
2 * Handles the Intel 27x USB Device Controller (UDC)
3 *
4 * Inspired by original driver by Frank Becker, David Brownell, and others.
5 * Copyright (C) 2008 Robert Jarzmik
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/types.h>
25#include <linux/version.h>
26#include <linux/errno.h>
27#include <linux/platform_device.h>
28#include <linux/delay.h>
29#include <linux/list.h>
30#include <linux/interrupt.h>
31#include <linux/proc_fs.h>
32#include <linux/clk.h>
33#include <linux/irq.h>
34
35#include <asm/byteorder.h>
36#include <asm/hardware.h>
37
38#include <linux/usb.h>
39#include <linux/usb/ch9.h>
40#include <linux/usb/gadget.h>
41
42#include <asm/arch/udc.h>
43
44#include "pxa27x_udc.h"
45
46/*
47 * This driver handles the USB Device Controller (UDC) in Intel's PXA 27x
48 * series processors.
49 *
50 * Such controller drivers work with a gadget driver. The gadget driver
51 * returns descriptors, implements configuration and data protocols used
52 * by the host to interact with this device, and allocates endpoints to
53 * the different protocol interfaces. The controller driver virtualizes
54 * usb hardware so that the gadget drivers will be more portable.
55 *
56 * This UDC hardware wants to implement a bit too much USB protocol. The
57 * biggest issues are: that the endpoints have to be set up before the
58 * controller can be enabled (minor, and not uncommon); and each endpoint
59 * can only have one configuration, interface and alternative interface
60 * number (major, and very unusual). Once set up, these cannot be changed
61 * without a controller reset.
62 *
63 * The workaround is to setup all combinations necessary for the gadgets which
64 * will work with this driver. This is done in pxa_udc structure, statically.
65 * See pxa_udc, udc_usb_ep versus pxa_ep, and matching function find_pxa_ep.
66 * (You could modify this if needed. Some drivers have a "fifo_mode" module
67 * parameter to facilitate such changes.)
68 *
69 * The combinations have been tested with these gadgets :
70 * - zero gadget
71 * - file storage gadget
72 * - ether gadget
73 *
74 * The driver doesn't use DMA, only IO access and IRQ callbacks. No use is
75 * made of UDC's double buffering either. USB "On-The-Go" is not implemented.
76 *
77 * All the requests are handled the same way :
78 * - the drivers tries to handle the request directly to the IO
79 * - if the IO fifo is not big enough, the remaining is send/received in
80 * interrupt handling.
81 */
82
83#define DRIVER_VERSION "2008-04-18"
84#define DRIVER_DESC "PXA 27x USB Device Controller driver"
85
86static const char driver_name[] = "pxa27x_udc";
87static struct pxa_udc *the_controller;
88
89static void handle_ep(struct pxa_ep *ep);
90
91/*
92 * Debug filesystem
93 */
94#ifdef CONFIG_USB_GADGET_DEBUG_FS
95
96#include <linux/debugfs.h>
97#include <linux/uaccess.h>
98#include <linux/seq_file.h>
99
100static int state_dbg_show(struct seq_file *s, void *p)
101{
102 struct pxa_udc *udc = s->private;
103 int pos = 0, ret;
104 u32 tmp;
105
106 ret = -ENODEV;
107 if (!udc->driver)
108 goto out;
109
110 /* basic device status */
111 pos += seq_printf(s, DRIVER_DESC "\n"
112 "%s version: %s\nGadget driver: %s\n",
113 driver_name, DRIVER_VERSION,
114 udc->driver ? udc->driver->driver.name : "(none)");
115
116 tmp = udc_readl(udc, UDCCR);
117 pos += seq_printf(s,
118 "udccr=0x%0x(%s%s%s%s%s%s%s%s%s%s), "
119 "con=%d,inter=%d,altinter=%d\n", tmp,
120 (tmp & UDCCR_OEN) ? " oen":"",
121 (tmp & UDCCR_AALTHNP) ? " aalthnp":"",
122 (tmp & UDCCR_AHNP) ? " rem" : "",
123 (tmp & UDCCR_BHNP) ? " rstir" : "",
124 (tmp & UDCCR_DWRE) ? " dwre" : "",
125 (tmp & UDCCR_SMAC) ? " smac" : "",
126 (tmp & UDCCR_EMCE) ? " emce" : "",
127 (tmp & UDCCR_UDR) ? " udr" : "",
128 (tmp & UDCCR_UDA) ? " uda" : "",
129 (tmp & UDCCR_UDE) ? " ude" : "",
130 (tmp & UDCCR_ACN) >> UDCCR_ACN_S,
131 (tmp & UDCCR_AIN) >> UDCCR_AIN_S,
132 (tmp & UDCCR_AAISN) >> UDCCR_AAISN_S);
133 /* registers for device and ep0 */
134 pos += seq_printf(s, "udcicr0=0x%08x udcicr1=0x%08x\n",
135 udc_readl(udc, UDCICR0), udc_readl(udc, UDCICR1));
136 pos += seq_printf(s, "udcisr0=0x%08x udcisr1=0x%08x\n",
137 udc_readl(udc, UDCISR0), udc_readl(udc, UDCISR1));
138 pos += seq_printf(s, "udcfnr=%d\n", udc_readl(udc, UDCFNR));
139 pos += seq_printf(s, "irqs: reset=%lu, suspend=%lu, resume=%lu, "
140 "reconfig=%lu\n",
141 udc->stats.irqs_reset, udc->stats.irqs_suspend,
142 udc->stats.irqs_resume, udc->stats.irqs_reconfig);
143
144 ret = 0;
145out:
146 return ret;
147}
148
149static int queues_dbg_show(struct seq_file *s, void *p)
150{
151 struct pxa_udc *udc = s->private;
152 struct pxa_ep *ep;
153 struct pxa27x_request *req;
154 int pos = 0, i, maxpkt, ret;
155
156 ret = -ENODEV;
157 if (!udc->driver)
158 goto out;
159
160 /* dump endpoint queues */
161 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
162 ep = &udc->pxa_ep[i];
163 maxpkt = ep->fifo_size;
164 pos += seq_printf(s, "%-12s max_pkt=%d %s\n",
165 EPNAME(ep), maxpkt, "pio");
166
167 if (list_empty(&ep->queue)) {
168 pos += seq_printf(s, "\t(nothing queued)\n");
169 continue;
170 }
171
172 list_for_each_entry(req, &ep->queue, queue) {
173 pos += seq_printf(s, "\treq %p len %d/%d buf %p\n",
174 &req->req, req->req.actual,
175 req->req.length, req->req.buf);
176 }
177 }
178
179 ret = 0;
180out:
181 return ret;
182}
183
184static int eps_dbg_show(struct seq_file *s, void *p)
185{
186 struct pxa_udc *udc = s->private;
187 struct pxa_ep *ep;
188 int pos = 0, i, ret;
189 u32 tmp;
190
191 ret = -ENODEV;
192 if (!udc->driver)
193 goto out;
194
195 ep = &udc->pxa_ep[0];
196 tmp = udc_ep_readl(ep, UDCCSR);
197 pos += seq_printf(s, "udccsr0=0x%03x(%s%s%s%s%s%s%s)\n", tmp,
198 (tmp & UDCCSR0_SA) ? " sa" : "",
199 (tmp & UDCCSR0_RNE) ? " rne" : "",
200 (tmp & UDCCSR0_FST) ? " fst" : "",
201 (tmp & UDCCSR0_SST) ? " sst" : "",
202 (tmp & UDCCSR0_DME) ? " dme" : "",
203 (tmp & UDCCSR0_IPR) ? " ipr" : "",
204 (tmp & UDCCSR0_OPC) ? " opc" : "");
205 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
206 ep = &udc->pxa_ep[i];
207 tmp = i? udc_ep_readl(ep, UDCCR) : udc_readl(udc, UDCCR);
208 pos += seq_printf(s, "%-12s: "
209 "IN %lu(%lu reqs), OUT %lu(%lu reqs), "
210 "irqs=%lu, udccr=0x%08x, udccsr=0x%03x, "
211 "udcbcr=%d\n",
212 EPNAME(ep),
213 ep->stats.in_bytes, ep->stats.in_ops,
214 ep->stats.out_bytes, ep->stats.out_ops,
215 ep->stats.irqs,
216 tmp, udc_ep_readl(ep, UDCCSR),
217 udc_ep_readl(ep, UDCBCR));
218 }
219
220 ret = 0;
221out:
222 return ret;
223}
224
225static int eps_dbg_open(struct inode *inode, struct file *file)
226{
227 return single_open(file, eps_dbg_show, inode->i_private);
228}
229
230static int queues_dbg_open(struct inode *inode, struct file *file)
231{
232 return single_open(file, queues_dbg_show, inode->i_private);
233}
234
235static int state_dbg_open(struct inode *inode, struct file *file)
236{
237 return single_open(file, state_dbg_show, inode->i_private);
238}
239
240static const struct file_operations state_dbg_fops = {
241 .owner = THIS_MODULE,
242 .open = state_dbg_open,
243 .llseek = seq_lseek,
244 .read = seq_read,
245 .release = single_release,
246};
247
248static const struct file_operations queues_dbg_fops = {
249 .owner = THIS_MODULE,
250 .open = queues_dbg_open,
251 .llseek = seq_lseek,
252 .read = seq_read,
253 .release = single_release,
254};
255
256static const struct file_operations eps_dbg_fops = {
257 .owner = THIS_MODULE,
258 .open = eps_dbg_open,
259 .llseek = seq_lseek,
260 .read = seq_read,
261 .release = single_release,
262};
263
264static void pxa_init_debugfs(struct pxa_udc *udc)
265{
266 struct dentry *root, *state, *queues, *eps;
267
268 root = debugfs_create_dir(udc->gadget.name, NULL);
269 if (IS_ERR(root) || !root)
270 goto err_root;
271
272 state = debugfs_create_file("udcstate", 0400, root, udc,
273 &state_dbg_fops);
274 if (!state)
275 goto err_state;
276 queues = debugfs_create_file("queues", 0400, root, udc,
277 &queues_dbg_fops);
278 if (!queues)
279 goto err_queues;
280 eps = debugfs_create_file("epstate", 0400, root, udc,
281 &eps_dbg_fops);
282 if (!queues)
283 goto err_eps;
284
285 udc->debugfs_root = root;
286 udc->debugfs_state = state;
287 udc->debugfs_queues = queues;
288 udc->debugfs_eps = eps;
289 return;
290err_eps:
291 debugfs_remove(eps);
292err_queues:
293 debugfs_remove(queues);
294err_state:
295 debugfs_remove(root);
296err_root:
297 dev_err(udc->dev, "debugfs is not available\n");
298}
299
300static void pxa_cleanup_debugfs(struct pxa_udc *udc)
301{
302 debugfs_remove(udc->debugfs_eps);
303 debugfs_remove(udc->debugfs_queues);
304 debugfs_remove(udc->debugfs_state);
305 debugfs_remove(udc->debugfs_root);
306 udc->debugfs_eps = NULL;
307 udc->debugfs_queues = NULL;
308 udc->debugfs_state = NULL;
309 udc->debugfs_root = NULL;
310}
311
312#else
313static inline void pxa_init_debugfs(struct pxa_udc *udc)
314{
315}
316
317static inline void pxa_cleanup_debugfs(struct pxa_udc *udc)
318{
319}
320#endif
321
322/**
323 * is_match_usb_pxa - check if usb_ep and pxa_ep match
324 * @udc_usb_ep: usb endpoint
325 * @ep: pxa endpoint
326 * @config: configuration required in pxa_ep
327 * @interface: interface required in pxa_ep
328 * @altsetting: altsetting required in pxa_ep
329 *
330 * Returns 1 if all criteria match between pxa and usb endpoint, 0 otherwise
331 */
332static int is_match_usb_pxa(struct udc_usb_ep *udc_usb_ep, struct pxa_ep *ep,
333 int config, int interface, int altsetting)
334{
335 if (usb_endpoint_num(&udc_usb_ep->desc) != ep->addr)
336 return 0;
337 if (usb_endpoint_dir_in(&udc_usb_ep->desc) != ep->dir_in)
338 return 0;
339 if (usb_endpoint_type(&udc_usb_ep->desc) != ep->type)
340 return 0;
341 if ((ep->config != config) || (ep->interface != interface)
342 || (ep->alternate != altsetting))
343 return 0;
344 return 1;
345}
346
347/**
348 * find_pxa_ep - find pxa_ep structure matching udc_usb_ep
349 * @udc: pxa udc
350 * @udc_usb_ep: udc_usb_ep structure
351 *
352 * Match udc_usb_ep and all pxa_ep available, to see if one matches.
353 * This is necessary because of the strong pxa hardware restriction requiring
354 * that once pxa endpoints are initialized, their configuration is freezed, and
355 * no change can be made to their address, direction, or in which configuration,
356 * interface or altsetting they are active ... which differs from more usual
357 * models which have endpoints be roughly just addressable fifos, and leave
358 * configuration events up to gadget drivers (like all control messages).
359 *
360 * Note that there is still a blurred point here :
361 * - we rely on UDCCR register "active interface" and "active altsetting".
362 * This is a nonsense in regard of USB spec, where multiple interfaces are
363 * active at the same time.
364 * - if we knew for sure that the pxa can handle multiple interface at the
365 * same time, assuming Intel's Developer Guide is wrong, this function
366 * should be reviewed, and a cache of couples (iface, altsetting) should
367 * be kept in the pxa_udc structure. In this case this function would match
368 * against the cache of couples instead of the "last altsetting" set up.
369 *
370 * Returns the matched pxa_ep structure or NULL if none found
371 */
372static struct pxa_ep *find_pxa_ep(struct pxa_udc *udc,
373 struct udc_usb_ep *udc_usb_ep)
374{
375 int i;
376 struct pxa_ep *ep;
377 int cfg = udc->config;
378 int iface = udc->last_interface;
379 int alt = udc->last_alternate;
380
381 if (udc_usb_ep == &udc->udc_usb_ep[0])
382 return &udc->pxa_ep[0];
383
384 for (i = 1; i < NR_PXA_ENDPOINTS; i++) {
385 ep = &udc->pxa_ep[i];
386 if (is_match_usb_pxa(udc_usb_ep, ep, cfg, iface, alt))
387 return ep;
388 }
389 return NULL;
390}
391
392/**
393 * update_pxa_ep_matches - update pxa_ep cached values in all udc_usb_ep
394 * @udc: pxa udc
395 *
396 * Context: in_interrupt()
397 *
398 * Updates all pxa_ep fields in udc_usb_ep structures, if this field was
399 * previously set up (and is not NULL). The update is necessary is a
400 * configuration change or altsetting change was issued by the USB host.
401 */
402static void update_pxa_ep_matches(struct pxa_udc *udc)
403{
404 int i;
405 struct udc_usb_ep *udc_usb_ep;
406
407 for (i = 1; i < NR_USB_ENDPOINTS; i++) {
408 udc_usb_ep = &udc->udc_usb_ep[i];
409 if (udc_usb_ep->pxa_ep)
410 udc_usb_ep->pxa_ep = find_pxa_ep(udc, udc_usb_ep);
411 }
412}
413
414/**
415 * pio_irq_enable - Enables irq generation for one endpoint
416 * @ep: udc endpoint
417 */
418static void pio_irq_enable(struct pxa_ep *ep)
419{
420 struct pxa_udc *udc = ep->dev;
421 int index = EPIDX(ep);
422 u32 udcicr0 = udc_readl(udc, UDCICR0);
423 u32 udcicr1 = udc_readl(udc, UDCICR1);
424
425 if (index < 16)
426 udc_writel(udc, UDCICR0, udcicr0 | (3 << (index * 2)));
427 else
428 udc_writel(udc, UDCICR1, udcicr1 | (3 << ((index - 16) * 2)));
429}
430
431/**
432 * pio_irq_disable - Disables irq generation for one endpoint
433 * @ep: udc endpoint
434 * @index: endpoint number
435 */
436static void pio_irq_disable(struct pxa_ep *ep)
437{
438 struct pxa_udc *udc = ep->dev;
439 int index = EPIDX(ep);
440 u32 udcicr0 = udc_readl(udc, UDCICR0);
441 u32 udcicr1 = udc_readl(udc, UDCICR1);
442
443 if (index < 16)
444 udc_writel(udc, UDCICR0, udcicr0 & ~(3 << (index * 2)));
445 else
446 udc_writel(udc, UDCICR1, udcicr1 & ~(3 << ((index - 16) * 2)));
447}
448
449/**
450 * udc_set_mask_UDCCR - set bits in UDCCR
451 * @udc: udc device
452 * @mask: bits to set in UDCCR
453 *
454 * Sets bits in UDCCR, leaving DME and FST bits as they were.
455 */
456static inline void udc_set_mask_UDCCR(struct pxa_udc *udc, int mask)
457{
458 u32 udccr = udc_readl(udc, UDCCR);
459 udc_writel(udc, UDCCR,
460 (udccr & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS));
461}
462
463/**
464 * udc_clear_mask_UDCCR - clears bits in UDCCR
465 * @udc: udc device
466 * @mask: bit to clear in UDCCR
467 *
468 * Clears bits in UDCCR, leaving DME and FST bits as they were.
469 */
470static inline void udc_clear_mask_UDCCR(struct pxa_udc *udc, int mask)
471{
472 u32 udccr = udc_readl(udc, UDCCR);
473 udc_writel(udc, UDCCR,
474 (udccr & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS));
475}
476
477/**
478 * ep_count_bytes_remain - get how many bytes in udc endpoint
479 * @ep: udc endpoint
480 *
481 * Returns number of bytes in OUT fifos. Broken for IN fifos (-EOPNOTSUPP)
482 */
483static int ep_count_bytes_remain(struct pxa_ep *ep)
484{
485 if (ep->dir_in)
486 return -EOPNOTSUPP;
487 return udc_ep_readl(ep, UDCBCR) & 0x3ff;
488}
489
490/**
491 * ep_is_empty - checks if ep has byte ready for reading
492 * @ep: udc endpoint
493 *
494 * If endpoint is the control endpoint, checks if there are bytes in the
495 * control endpoint fifo. If endpoint is a data endpoint, checks if bytes
496 * are ready for reading on OUT endpoint.
497 *
498 * Returns 0 if ep not empty, 1 if ep empty, -EOPNOTSUPP if IN endpoint
499 */
500static int ep_is_empty(struct pxa_ep *ep)
501{
502 int ret;
503
504 if (!is_ep0(ep) && ep->dir_in)
505 return -EOPNOTSUPP;
506 if (is_ep0(ep))
507 ret = !(udc_ep_readl(ep, UDCCSR) & UDCCSR0_RNE);
508 else
509 ret = !(udc_ep_readl(ep, UDCCSR) & UDCCSR_BNE);
510 return ret;
511}
512
513/**
514 * ep_is_full - checks if ep has place to write bytes
515 * @ep: udc endpoint
516 *
517 * If endpoint is not the control endpoint and is an IN endpoint, checks if
518 * there is place to write bytes into the endpoint.
519 *
520 * Returns 0 if ep not full, 1 if ep full, -EOPNOTSUPP if OUT endpoint
521 */
522static int ep_is_full(struct pxa_ep *ep)
523{
524 if (is_ep0(ep))
525 return (udc_ep_readl(ep, UDCCSR) & UDCCSR0_IPR);
526 if (!ep->dir_in)
527 return -EOPNOTSUPP;
528 return (!(udc_ep_readl(ep, UDCCSR) & UDCCSR_BNF));
529}
530
531/**
532 * epout_has_pkt - checks if OUT endpoint fifo has a packet available
533 * @ep: pxa endpoint
534 *
535 * Returns 1 if a complete packet is available, 0 if not, -EOPNOTSUPP for IN ep.
536 */
537static int epout_has_pkt(struct pxa_ep *ep)
538{
539 if (!is_ep0(ep) && ep->dir_in)
540 return -EOPNOTSUPP;
541 if (is_ep0(ep))
542 return (udc_ep_readl(ep, UDCCSR) & UDCCSR0_OPC);
543 return (udc_ep_readl(ep, UDCCSR) & UDCCSR_PC);
544}
545
546/**
547 * set_ep0state - Set ep0 automata state
548 * @dev: udc device
549 * @state: state
550 */
551static void set_ep0state(struct pxa_udc *udc, int state)
552{
553 struct pxa_ep *ep = &udc->pxa_ep[0];
554 char *old_stname = EP0_STNAME(udc);
555
556 udc->ep0state = state;
557 ep_dbg(ep, "state=%s->%s, udccsr0=0x%03x, udcbcr=%d\n", old_stname,
558 EP0_STNAME(udc), udc_ep_readl(ep, UDCCSR),
559 udc_ep_readl(ep, UDCBCR));
560}
561
562/**
563 * ep0_idle - Put control endpoint into idle state
564 * @dev: udc device
565 */
566static void ep0_idle(struct pxa_udc *dev)
567{
568 set_ep0state(dev, WAIT_FOR_SETUP);
569}
570
571/**
572 * inc_ep_stats_reqs - Update ep stats counts
573 * @ep: physical endpoint
574 * @req: usb request
575 * @is_in: ep direction (USB_DIR_IN or 0)
576 *
577 */
578static void inc_ep_stats_reqs(struct pxa_ep *ep, int is_in)
579{
580 if (is_in)
581 ep->stats.in_ops++;
582 else
583 ep->stats.out_ops++;
584}
585
586/**
587 * inc_ep_stats_bytes - Update ep stats counts
588 * @ep: physical endpoint
589 * @count: bytes transfered on endpoint
590 * @req: usb request
591 * @is_in: ep direction (USB_DIR_IN or 0)
592 */
593static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in)
594{
595 if (is_in)
596 ep->stats.in_bytes += count;
597 else
598 ep->stats.out_bytes += count;
599}
600
601/**
602 * pxa_ep_setup - Sets up an usb physical endpoint
603 * @ep: pxa27x physical endpoint
604 *
605 * Find the physical pxa27x ep, and setup its UDCCR
606 */
607static __init void pxa_ep_setup(struct pxa_ep *ep)
608{
609 u32 new_udccr;
610
611 new_udccr = ((ep->config << UDCCONR_CN_S) & UDCCONR_CN)
612 | ((ep->interface << UDCCONR_IN_S) & UDCCONR_IN)
613 | ((ep->alternate << UDCCONR_AISN_S) & UDCCONR_AISN)
614 | ((EPADDR(ep) << UDCCONR_EN_S) & UDCCONR_EN)
615 | ((EPXFERTYPE(ep) << UDCCONR_ET_S) & UDCCONR_ET)
616 | ((ep->dir_in) ? UDCCONR_ED : 0)
617 | ((ep->fifo_size << UDCCONR_MPS_S) & UDCCONR_MPS)
618 | UDCCONR_EE;
619
620 udc_ep_writel(ep, UDCCR, new_udccr);
621}
622
623/**
624 * pxa_eps_setup - Sets up all usb physical endpoints
625 * @dev: udc device
626 *
627 * Setup all pxa physical endpoints, except ep0
628 */
629static __init void pxa_eps_setup(struct pxa_udc *dev)
630{
631 unsigned int i;
632
633 dev_dbg(dev->dev, "%s: dev=%p\n", __func__, dev);
634
635 for (i = 1; i < NR_PXA_ENDPOINTS; i++)
636 pxa_ep_setup(&dev->pxa_ep[i]);
637}
638
639/**
640 * pxa_ep_alloc_request - Allocate usb request
641 * @_ep: usb endpoint
642 * @gfp_flags:
643 *
644 * For the pxa27x, these can just wrap kmalloc/kfree. gadget drivers
645 * must still pass correctly initialized endpoints, since other controller
646 * drivers may care about how it's currently set up (dma issues etc).
647 */
648static struct usb_request *
649pxa_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
650{
651 struct pxa27x_request *req;
652
653 req = kzalloc(sizeof *req, gfp_flags);
654 if (!req || !_ep)
655 return NULL;
656
657 INIT_LIST_HEAD(&req->queue);
658 req->in_use = 0;
659 req->udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
660
661 return &req->req;
662}
663
664/**
665 * pxa_ep_free_request - Free usb request
666 * @_ep: usb endpoint
667 * @_req: usb request
668 *
669 * Wrapper around kfree to free _req
670 */
671static void pxa_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
672{
673 struct pxa27x_request *req;
674
675 req = container_of(_req, struct pxa27x_request, req);
676 WARN_ON(!list_empty(&req->queue));
677 kfree(req);
678}
679
680/**
681 * ep_add_request - add a request to the endpoint's queue
682 * @ep: usb endpoint
683 * @req: usb request
684 *
685 * Context: ep->lock held
686 *
687 * Queues the request in the endpoint's queue, and enables the interrupts
688 * on the endpoint.
689 */
690static void ep_add_request(struct pxa_ep *ep, struct pxa27x_request *req)
691{
692 if (unlikely(!req))
693 return;
694 ep_vdbg(ep, "req:%p, lg=%d, udccsr=0x%03x\n", req,
695 req->req.length, udc_ep_readl(ep, UDCCSR));
696
697 req->in_use = 1;
698 list_add_tail(&req->queue, &ep->queue);
699 pio_irq_enable(ep);
700}
701
702/**
703 * ep_del_request - removes a request from the endpoint's queue
704 * @ep: usb endpoint
705 * @req: usb request
706 *
707 * Context: ep->lock held
708 *
709 * Unqueue the request from the endpoint's queue. If there are no more requests
710 * on the endpoint, and if it's not the control endpoint, interrupts are
711 * disabled on the endpoint.
712 */
713static void ep_del_request(struct pxa_ep *ep, struct pxa27x_request *req)
714{
715 if (unlikely(!req))
716 return;
717 ep_vdbg(ep, "req:%p, lg=%d, udccsr=0x%03x\n", req,
718 req->req.length, udc_ep_readl(ep, UDCCSR));
719
720 list_del_init(&req->queue);
721 req->in_use = 0;
722 if (!is_ep0(ep) && list_empty(&ep->queue))
723 pio_irq_disable(ep);
724}
725
726/**
727 * req_done - Complete an usb request
728 * @ep: pxa physical endpoint
729 * @req: pxa request
730 * @status: usb request status sent to gadget API
731 *
732 * Context: ep->lock held
733 *
734 * Retire a pxa27x usb request. Endpoint must be locked.
735 */
736static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status)
737{
738 ep_del_request(ep, req);
739 if (likely(req->req.status == -EINPROGRESS))
740 req->req.status = status;
741 else
742 status = req->req.status;
743
744 if (status && status != -ESHUTDOWN)
745 ep_dbg(ep, "complete req %p stat %d len %u/%u\n",
746 &req->req, status,
747 req->req.actual, req->req.length);
748
749 req->req.complete(&req->udc_usb_ep->usb_ep, &req->req);
750}
751
752/**
753 * ep_end_out_req - Ends control endpoint in request
754 * @ep: physical endpoint
755 * @req: pxa request
756 *
757 * Context: ep->lock held
758 *
759 * Ends endpoint in request (completes usb request).
760 */
761static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
762{
763 inc_ep_stats_reqs(ep, !USB_DIR_IN);
764 req_done(ep, req, 0);
765}
766
767/**
768 * ep0_end_out_req - Ends control endpoint in request (ends data stage)
769 * @ep: physical endpoint
770 * @req: pxa request
771 *
772 * Context: ep->lock held
773 *
774 * Ends control endpoint in request (completes usb request), and puts
775 * control endpoint into idle state
776 */
777static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
778{
779 set_ep0state(ep->dev, OUT_STATUS_STAGE);
780 ep_end_out_req(ep, req);
781 ep0_idle(ep->dev);
782}
783
784/**
785 * ep_end_in_req - Ends endpoint out request
786 * @ep: physical endpoint
787 * @req: pxa request
788 *
789 * Context: ep->lock held
790 *
791 * Ends endpoint out request (completes usb request).
792 */
793static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
794{
795 inc_ep_stats_reqs(ep, USB_DIR_IN);
796 req_done(ep, req, 0);
797}
798
799/**
800 * ep0_end_in_req - Ends control endpoint out request (ends data stage)
801 * @ep: physical endpoint
802 * @req: pxa request
803 *
804 * Context: ep->lock held
805 *
806 * Ends control endpoint out request (completes usb request), and puts
807 * control endpoint into status state
808 */
809static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
810{
811 struct pxa_udc *udc = ep->dev;
812
813 set_ep0state(udc, IN_STATUS_STAGE);
814 ep_end_in_req(ep, req);
815}
816
817/**
818 * nuke - Dequeue all requests
819 * @ep: pxa endpoint
820 * @status: usb request status
821 *
822 * Context: ep->lock held
823 *
824 * Dequeues all requests on an endpoint. As a side effect, interrupts will be
825 * disabled on that endpoint (because no more requests).
826 */
827static void nuke(struct pxa_ep *ep, int status)
828{
829 struct pxa27x_request *req;
830
831 while (!list_empty(&ep->queue)) {
832 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
833 req_done(ep, req, status);
834 }
835}
836
837/**
838 * read_packet - transfer 1 packet from an OUT endpoint into request
839 * @ep: pxa physical endpoint
840 * @req: usb request
841 *
842 * Takes bytes from OUT endpoint and transfers them info the usb request.
843 * If there is less space in request than bytes received in OUT endpoint,
844 * bytes are left in the OUT endpoint.
845 *
846 * Returns how many bytes were actually transfered
847 */
848static int read_packet(struct pxa_ep *ep, struct pxa27x_request *req)
849{
850 u32 *buf;
851 int bytes_ep, bufferspace, count, i;
852
853 bytes_ep = ep_count_bytes_remain(ep);
854 bufferspace = req->req.length - req->req.actual;
855
856 buf = (u32 *)(req->req.buf + req->req.actual);
857 prefetchw(buf);
858
859 if (likely(!ep_is_empty(ep)))
860 count = min(bytes_ep, bufferspace);
861 else /* zlp */
862 count = 0;
863
864 for (i = count; i > 0; i -= 4)
865 *buf++ = udc_ep_readl(ep, UDCDR);
866 req->req.actual += count;
867
868 udc_ep_writel(ep, UDCCSR, UDCCSR_PC);
869
870 return count;
871}
872
873/**
874 * write_packet - transfer 1 packet from request into an IN endpoint
875 * @ep: pxa physical endpoint
876 * @req: usb request
877 * @max: max bytes that fit into endpoint
878 *
879 * Takes bytes from usb request, and transfers them into the physical
880 * endpoint. If there are no bytes to transfer, doesn't write anything
881 * to physical endpoint.
882 *
883 * Returns how many bytes were actually transfered.
884 */
885static int write_packet(struct pxa_ep *ep, struct pxa27x_request *req,
886 unsigned int max)
887{
888 int length, count, remain, i;
889 u32 *buf;
890 u8 *buf_8;
891
892 buf = (u32 *)(req->req.buf + req->req.actual);
893 prefetch(buf);
894
895 length = min(req->req.length - req->req.actual, max);
896 req->req.actual += length;
897
898 remain = length & 0x3;
899 count = length & ~(0x3);
900 for (i = count; i > 0 ; i -= 4)
901 udc_ep_writel(ep, UDCDR, *buf++);
902
903 buf_8 = (u8 *)buf;
904 for (i = remain; i > 0; i--)
905 udc_ep_writeb(ep, UDCDR, *buf_8++);
906
907 ep_vdbg(ep, "length=%d+%d, udccsr=0x%03x\n", count, remain,
908 udc_ep_readl(ep, UDCCSR));
909
910 return length;
911}
912
913/**
914 * read_fifo - Transfer packets from OUT endpoint into usb request
915 * @ep: pxa physical endpoint
916 * @req: usb request
917 *
918 * Context: callable when in_interrupt()
919 *
920 * Unload as many packets as possible from the fifo we use for usb OUT
921 * transfers and put them into the request. Caller should have made sure
922 * there's at least one packet ready.
923 * Doesn't complete the request, that's the caller's job
924 *
925 * Returns 1 if the request completed, 0 otherwise
926 */
927static int read_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
928{
929 int count, is_short, completed = 0;
930
931 while (epout_has_pkt(ep)) {
932 count = read_packet(ep, req);
933 inc_ep_stats_bytes(ep, count, !USB_DIR_IN);
934
935 is_short = (count < ep->fifo_size);
936 ep_dbg(ep, "read udccsr:%03x, count:%d bytes%s req %p %d/%d\n",
937 udc_ep_readl(ep, UDCCSR), count, is_short ? "/S" : "",
938 &req->req, req->req.actual, req->req.length);
939
940 /* completion */
941 if (is_short || req->req.actual == req->req.length) {
942 completed = 1;
943 break;
944 }
945 /* finished that packet. the next one may be waiting... */
946 }
947 return completed;
948}
949
950/**
951 * write_fifo - transfer packets from usb request into an IN endpoint
952 * @ep: pxa physical endpoint
953 * @req: pxa usb request
954 *
955 * Write to an IN endpoint fifo, as many packets as possible.
956 * irqs will use this to write the rest later.
957 * caller guarantees at least one packet buffer is ready (or a zlp).
958 * Doesn't complete the request, that's the caller's job
959 *
960 * Returns 1 if request fully transfered, 0 if partial transfer
961 */
962static int write_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
963{
964 unsigned max;
965 int count, is_short, is_last = 0, completed = 0, totcount = 0;
966 u32 udccsr;
967
968 max = ep->fifo_size;
969 do {
970 is_short = 0;
971
972 udccsr = udc_ep_readl(ep, UDCCSR);
973 if (udccsr & UDCCSR_PC) {
974 ep_vdbg(ep, "Clearing Transmit Complete, udccsr=%x\n",
975 udccsr);
976 udc_ep_writel(ep, UDCCSR, UDCCSR_PC);
977 }
978 if (udccsr & UDCCSR_TRN) {
979 ep_vdbg(ep, "Clearing Underrun on, udccsr=%x\n",
980 udccsr);
981 udc_ep_writel(ep, UDCCSR, UDCCSR_TRN);
982 }
983
984 count = write_packet(ep, req, max);
985 inc_ep_stats_bytes(ep, count, USB_DIR_IN);
986 totcount += count;
987
988 /* last packet is usually short (or a zlp) */
989 if (unlikely(count < max)) {
990 is_last = 1;
991 is_short = 1;
992 } else {
993 if (likely(req->req.length > req->req.actual)
994 || req->req.zero)
995 is_last = 0;
996 else
997 is_last = 1;
998 /* interrupt/iso maxpacket may not fill the fifo */
999 is_short = unlikely(max < ep->fifo_size);
1000 }
1001
1002 if (is_short)
1003 udc_ep_writel(ep, UDCCSR, UDCCSR_SP);
1004
1005 /* requests complete when all IN data is in the FIFO */
1006 if (is_last) {
1007 completed = 1;
1008 break;
1009 }
1010 } while (!ep_is_full(ep));
1011
1012 ep_dbg(ep, "wrote count:%d bytes%s%s, left:%d req=%p\n",
1013 totcount, is_last ? "/L" : "", is_short ? "/S" : "",
1014 req->req.length - req->req.actual, &req->req);
1015
1016 return completed;
1017}
1018
1019/**
1020 * read_ep0_fifo - Transfer packets from control endpoint into usb request
1021 * @ep: control endpoint
1022 * @req: pxa usb request
1023 *
1024 * Special ep0 version of the above read_fifo. Reads as many bytes from control
1025 * endpoint as can be read, and stores them into usb request (limited by request
1026 * maximum length).
1027 *
1028 * Returns 0 if usb request only partially filled, 1 if fully filled
1029 */
1030static int read_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1031{
1032 int count, is_short, completed = 0;
1033
1034 while (epout_has_pkt(ep)) {
1035 count = read_packet(ep, req);
1036 udc_ep_writel(ep, UDCCSR, UDCCSR0_OPC);
1037 inc_ep_stats_bytes(ep, count, !USB_DIR_IN);
1038
1039 is_short = (count < ep->fifo_size);
1040 ep_dbg(ep, "read udccsr:%03x, count:%d bytes%s req %p %d/%d\n",
1041 udc_ep_readl(ep, UDCCSR), count, is_short ? "/S" : "",
1042 &req->req, req->req.actual, req->req.length);
1043
1044 if (is_short || req->req.actual >= req->req.length) {
1045 completed = 1;
1046 break;
1047 }
1048 }
1049
1050 return completed;
1051}
1052
1053/**
1054 * write_ep0_fifo - Send a request to control endpoint (ep0 in)
1055 * @ep: control endpoint
1056 * @req: request
1057 *
1058 * Context: callable when in_interrupt()
1059 *
1060 * Sends a request (or a part of the request) to the control endpoint (ep0 in).
1061 * If the request doesn't fit, the remaining part will be sent from irq.
1062 * The request is considered fully written only if either :
1063 * - last write transfered all remaining bytes, but fifo was not fully filled
1064 * - last write was a 0 length write
1065 *
1066 * Returns 1 if request fully written, 0 if request only partially sent
1067 */
1068static int write_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1069{
1070 unsigned count;
1071 int is_last, is_short;
1072
1073 count = write_packet(ep, req, EP0_FIFO_SIZE);
1074 inc_ep_stats_bytes(ep, count, USB_DIR_IN);
1075
1076 is_short = (count < EP0_FIFO_SIZE);
1077 is_last = ((count == 0) || (count < EP0_FIFO_SIZE));
1078
1079 /* Sends either a short packet or a 0 length packet */
1080 if (unlikely(is_short))
1081 udc_ep_writel(ep, UDCCSR, UDCCSR0_IPR);
1082
1083 ep_dbg(ep, "in %d bytes%s%s, %d left, req=%p, udccsr0=0x%03x\n",
1084 count, is_short ? "/S" : "", is_last ? "/L" : "",
1085 req->req.length - req->req.actual,
1086 &req->req, udc_ep_readl(ep, UDCCSR));
1087
1088 return is_last;
1089}
1090
1091/**
1092 * pxa_ep_queue - Queue a request into an IN endpoint
1093 * @_ep: usb endpoint
1094 * @_req: usb request
1095 * @gfp_flags: flags
1096 *
1097 * Context: normally called when !in_interrupt, but callable when in_interrupt()
1098 * in the special case of ep0 setup :
1099 * (irq->handle_ep0_ctrl_req->gadget_setup->pxa_ep_queue)
1100 *
1101 * Returns 0 if succedeed, error otherwise
1102 */
1103static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1104 gfp_t gfp_flags)
1105{
1106 struct udc_usb_ep *udc_usb_ep;
1107 struct pxa_ep *ep;
1108 struct pxa27x_request *req;
1109 struct pxa_udc *dev;
1110 unsigned long flags;
1111 int rc = 0;
1112 int is_first_req;
1113 unsigned length;
1114
1115 req = container_of(_req, struct pxa27x_request, req);
1116 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1117
1118 if (unlikely(!_req || !_req->complete || !_req->buf))
1119 return -EINVAL;
1120
1121 if (unlikely(!_ep))
1122 return -EINVAL;
1123
1124 dev = udc_usb_ep->dev;
1125 ep = udc_usb_ep->pxa_ep;
1126 if (unlikely(!ep))
1127 return -EINVAL;
1128
1129 dev = ep->dev;
1130 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
1131 ep_dbg(ep, "bogus device state\n");
1132 return -ESHUTDOWN;
1133 }
1134
1135 /* iso is always one packet per request, that's the only way
1136 * we can report per-packet status. that also helps with dma.
1137 */
1138 if (unlikely(EPXFERTYPE_is_ISO(ep)
1139 && req->req.length > ep->fifo_size))
1140 return -EMSGSIZE;
1141
1142 spin_lock_irqsave(&ep->lock, flags);
1143
1144 is_first_req = list_empty(&ep->queue);
1145 ep_dbg(ep, "queue req %p(first=%s), len %d buf %p\n",
1146 _req, is_first_req ? "yes" : "no",
1147 _req->length, _req->buf);
1148
1149 if (!ep->enabled) {
1150 _req->status = -ESHUTDOWN;
1151 rc = -ESHUTDOWN;
1152 goto out;
1153 }
1154
1155 if (req->in_use) {
1156 ep_err(ep, "refusing to queue req %p (already queued)\n", req);
1157 goto out;
1158 }
1159
1160 length = _req->length;
1161 _req->status = -EINPROGRESS;
1162 _req->actual = 0;
1163
1164 ep_add_request(ep, req);
1165
1166 if (is_ep0(ep)) {
1167 switch (dev->ep0state) {
1168 case WAIT_ACK_SET_CONF_INTERF:
1169 if (length == 0) {
1170 ep_end_in_req(ep, req);
1171 } else {
1172 ep_err(ep, "got a request of %d bytes while"
1173 "in state WATI_ACK_SET_CONF_INTERF\n",
1174 length);
1175 ep_del_request(ep, req);
1176 rc = -EL2HLT;
1177 }
1178 ep0_idle(ep->dev);
1179 break;
1180 case IN_DATA_STAGE:
1181 if (!ep_is_full(ep))
1182 if (write_ep0_fifo(ep, req))
1183 ep0_end_in_req(ep, req);
1184 break;
1185 case OUT_DATA_STAGE:
1186 if ((length == 0) || !epout_has_pkt(ep))
1187 if (read_ep0_fifo(ep, req))
1188 ep0_end_out_req(ep, req);
1189 break;
1190 default:
1191 ep_err(ep, "odd state %s to send me a request\n",
1192 EP0_STNAME(ep->dev));
1193 ep_del_request(ep, req);
1194 rc = -EL2HLT;
1195 break;
1196 }
1197 } else {
1198 handle_ep(ep);
1199 }
1200
1201out:
1202 spin_unlock_irqrestore(&ep->lock, flags);
1203 return rc;
1204}
1205
1206/**
1207 * pxa_ep_dequeue - Dequeue one request
1208 * @_ep: usb endpoint
1209 * @_req: usb request
1210 *
1211 * Return 0 if no error, -EINVAL or -ECONNRESET otherwise
1212 */
1213static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1214{
1215 struct pxa_ep *ep;
1216 struct udc_usb_ep *udc_usb_ep;
1217 struct pxa27x_request *req;
1218 unsigned long flags;
1219 int rc;
1220
1221 if (!_ep)
1222 return -EINVAL;
1223 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1224 ep = udc_usb_ep->pxa_ep;
1225 if (!ep || is_ep0(ep))
1226 return -EINVAL;
1227
1228 spin_lock_irqsave(&ep->lock, flags);
1229
1230 /* make sure it's actually queued on this endpoint */
1231 list_for_each_entry(req, &ep->queue, queue) {
1232 if (&req->req == _req)
1233 break;
1234 }
1235
1236 rc = -EINVAL;
1237 if (&req->req != _req)
1238 goto out;
1239
1240 rc = 0;
1241 req_done(ep, req, -ECONNRESET);
1242out:
1243 spin_unlock_irqrestore(&ep->lock, flags);
1244 return rc;
1245}
1246
1247/**
1248 * pxa_ep_set_halt - Halts operations on one endpoint
1249 * @_ep: usb endpoint
1250 * @value:
1251 *
1252 * Returns 0 if no error, -EINVAL, -EROFS, -EAGAIN otherwise
1253 */
1254static int pxa_ep_set_halt(struct usb_ep *_ep, int value)
1255{
1256 struct pxa_ep *ep;
1257 struct udc_usb_ep *udc_usb_ep;
1258 unsigned long flags;
1259 int rc;
1260
1261
1262 if (!_ep)
1263 return -EINVAL;
1264 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1265 ep = udc_usb_ep->pxa_ep;
1266 if (!ep || is_ep0(ep))
1267 return -EINVAL;
1268
1269 if (value == 0) {
1270 /*
1271 * This path (reset toggle+halt) is needed to implement
1272 * SET_INTERFACE on normal hardware. but it can't be
1273 * done from software on the PXA UDC, and the hardware
1274 * forgets to do it as part of SET_INTERFACE automagic.
1275 */
1276 ep_dbg(ep, "only host can clear halt\n");
1277 return -EROFS;
1278 }
1279
1280 spin_lock_irqsave(&ep->lock, flags);
1281
1282 rc = -EAGAIN;
1283 if (ep->dir_in && (ep_is_full(ep) || !list_empty(&ep->queue)))
1284 goto out;
1285
1286 /* FST, FEF bits are the same for control and non control endpoints */
1287 rc = 0;
1288 udc_ep_writel(ep, UDCCSR, UDCCSR_FST | UDCCSR_FEF);
1289 if (is_ep0(ep))
1290 set_ep0state(ep->dev, STALL);
1291
1292out:
1293 spin_unlock_irqrestore(&ep->lock, flags);
1294 return rc;
1295}
1296
1297/**
1298 * pxa_ep_fifo_status - Get how many bytes in physical endpoint
1299 * @_ep: usb endpoint
1300 *
1301 * Returns number of bytes in OUT fifos. Broken for IN fifos.
1302 */
1303static int pxa_ep_fifo_status(struct usb_ep *_ep)
1304{
1305 struct pxa_ep *ep;
1306 struct udc_usb_ep *udc_usb_ep;
1307
1308 if (!_ep)
1309 return -ENODEV;
1310 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1311 ep = udc_usb_ep->pxa_ep;
1312 if (!ep || is_ep0(ep))
1313 return -ENODEV;
1314
1315 if (ep->dir_in)
1316 return -EOPNOTSUPP;
1317 if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN || ep_is_empty(ep))
1318 return 0;
1319 else
1320 return ep_count_bytes_remain(ep) + 1;
1321}
1322
1323/**
1324 * pxa_ep_fifo_flush - Flushes one endpoint
1325 * @_ep: usb endpoint
1326 *
1327 * Discards all data in one endpoint(IN or OUT), except control endpoint.
1328 */
1329static void pxa_ep_fifo_flush(struct usb_ep *_ep)
1330{
1331 struct pxa_ep *ep;
1332 struct udc_usb_ep *udc_usb_ep;
1333 unsigned long flags;
1334
1335 if (!_ep)
1336 return;
1337 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1338 ep = udc_usb_ep->pxa_ep;
1339 if (!ep || is_ep0(ep))
1340 return;
1341
1342 spin_lock_irqsave(&ep->lock, flags);
1343
1344 if (unlikely(!list_empty(&ep->queue)))
1345 ep_dbg(ep, "called while queue list not empty\n");
1346 ep_dbg(ep, "called\n");
1347
1348 /* for OUT, just read and discard the FIFO contents. */
1349 if (!ep->dir_in) {
1350 while (!ep_is_empty(ep))
1351 udc_ep_readl(ep, UDCDR);
1352 } else {
1353 /* most IN status is the same, but ISO can't stall */
1354 udc_ep_writel(ep, UDCCSR,
1355 UDCCSR_PC | UDCCSR_FEF | UDCCSR_TRN
1356 | (EPXFERTYPE_is_ISO(ep) ? 0 : UDCCSR_SST));
1357 }
1358
1359 spin_unlock_irqrestore(&ep->lock, flags);
1360
1361 return;
1362}
1363
1364/**
1365 * pxa_ep_enable - Enables usb endpoint
1366 * @_ep: usb endpoint
1367 * @desc: usb endpoint descriptor
1368 *
1369 * Nothing much to do here, as ep configuration is done once and for all
1370 * before udc is enabled. After udc enable, no physical endpoint configuration
1371 * can be changed.
1372 * Function makes sanity checks and flushes the endpoint.
1373 */
1374static int pxa_ep_enable(struct usb_ep *_ep,
1375 const struct usb_endpoint_descriptor *desc)
1376{
1377 struct pxa_ep *ep;
1378 struct udc_usb_ep *udc_usb_ep;
1379 struct pxa_udc *udc;
1380
1381 if (!_ep || !desc)
1382 return -EINVAL;
1383
1384 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1385 if (udc_usb_ep->pxa_ep) {
1386 ep = udc_usb_ep->pxa_ep;
1387 ep_warn(ep, "usb_ep %s already enabled, doing nothing\n",
1388 _ep->name);
1389 } else {
1390 ep = find_pxa_ep(udc_usb_ep->dev, udc_usb_ep);
1391 }
1392
1393 if (!ep || is_ep0(ep)) {
1394 dev_err(udc_usb_ep->dev->dev,
1395 "unable to match pxa_ep for ep %s\n",
1396 _ep->name);
1397 return -EINVAL;
1398 }
1399
1400 if ((desc->bDescriptorType != USB_DT_ENDPOINT)
1401 || (ep->type != usb_endpoint_type(desc))) {
1402 ep_err(ep, "type mismatch\n");
1403 return -EINVAL;
1404 }
1405
1406 if (ep->fifo_size < le16_to_cpu(desc->wMaxPacketSize)) {
1407 ep_err(ep, "bad maxpacket\n");
1408 return -ERANGE;
1409 }
1410
1411 udc_usb_ep->pxa_ep = ep;
1412 udc = ep->dev;
1413
1414 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
1415 ep_err(ep, "bogus device state\n");
1416 return -ESHUTDOWN;
1417 }
1418
1419 ep->enabled = 1;
1420
1421 /* flush fifo (mostly for OUT buffers) */
1422 pxa_ep_fifo_flush(_ep);
1423
1424 ep_dbg(ep, "enabled\n");
1425 return 0;
1426}
1427
1428/**
1429 * pxa_ep_disable - Disable usb endpoint
1430 * @_ep: usb endpoint
1431 *
1432 * Same as for pxa_ep_enable, no physical endpoint configuration can be
1433 * changed.
1434 * Function flushes the endpoint and related requests.
1435 */
1436static int pxa_ep_disable(struct usb_ep *_ep)
1437{
1438 struct pxa_ep *ep;
1439 struct udc_usb_ep *udc_usb_ep;
1440 unsigned long flags;
1441
1442 if (!_ep)
1443 return -EINVAL;
1444
1445 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1446 ep = udc_usb_ep->pxa_ep;
1447 if (!ep || is_ep0(ep) || !list_empty(&ep->queue))
1448 return -EINVAL;
1449
1450 spin_lock_irqsave(&ep->lock, flags);
1451 ep->enabled = 0;
1452 nuke(ep, -ESHUTDOWN);
1453 spin_unlock_irqrestore(&ep->lock, flags);
1454
1455 pxa_ep_fifo_flush(_ep);
1456 udc_usb_ep->pxa_ep = NULL;
1457
1458 ep_dbg(ep, "disabled\n");
1459 return 0;
1460}
1461
1462static struct usb_ep_ops pxa_ep_ops = {
1463 .enable = pxa_ep_enable,
1464 .disable = pxa_ep_disable,
1465
1466 .alloc_request = pxa_ep_alloc_request,
1467 .free_request = pxa_ep_free_request,
1468
1469 .queue = pxa_ep_queue,
1470 .dequeue = pxa_ep_dequeue,
1471
1472 .set_halt = pxa_ep_set_halt,
1473 .fifo_status = pxa_ep_fifo_status,
1474 .fifo_flush = pxa_ep_fifo_flush,
1475};
1476
1477
1478/**
1479 * pxa_udc_get_frame - Returns usb frame number
1480 * @_gadget: usb gadget
1481 */
1482static int pxa_udc_get_frame(struct usb_gadget *_gadget)
1483{
1484 struct pxa_udc *udc = to_gadget_udc(_gadget);
1485
1486 return (udc_readl(udc, UDCFNR) & 0x7ff);
1487}
1488
1489/**
1490 * pxa_udc_wakeup - Force udc device out of suspend
1491 * @_gadget: usb gadget
1492 *
1493 * Returns 0 if succesfull, error code otherwise
1494 */
1495static int pxa_udc_wakeup(struct usb_gadget *_gadget)
1496{
1497 struct pxa_udc *udc = to_gadget_udc(_gadget);
1498
1499 /* host may not have enabled remote wakeup */
1500 if ((udc_readl(udc, UDCCR) & UDCCR_DWRE) == 0)
1501 return -EHOSTUNREACH;
1502 udc_set_mask_UDCCR(udc, UDCCR_UDR);
1503 return 0;
1504}
1505
1506static const struct usb_gadget_ops pxa_udc_ops = {
1507 .get_frame = pxa_udc_get_frame,
1508 .wakeup = pxa_udc_wakeup,
1509 /* current versions must always be self-powered */
1510};
1511
1512/**
1513 * udc_disable - disable udc device controller
1514 * @udc: udc device
1515 *
1516 * Disables the udc device : disables clocks, udc interrupts, control endpoint
1517 * interrupts.
1518 */
1519static void udc_disable(struct pxa_udc *udc)
1520{
1521 udc_writel(udc, UDCICR0, 0);
1522 udc_writel(udc, UDCICR1, 0);
1523
1524 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
1525 clk_disable(udc->clk);
1526
1527 ep0_idle(udc);
1528 udc->gadget.speed = USB_SPEED_UNKNOWN;
1529 if (udc->mach->udc_command)
1530 udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
1531}
1532
1533/**
1534 * udc_init_data - Initialize udc device data structures
1535 * @dev: udc device
1536 *
1537 * Initializes gadget endpoint list, endpoints locks. No action is taken
1538 * on the hardware.
1539 */
1540static __init void udc_init_data(struct pxa_udc *dev)
1541{
1542 int i;
1543 struct pxa_ep *ep;
1544
1545 /* device/ep0 records init */
1546 INIT_LIST_HEAD(&dev->gadget.ep_list);
1547 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
1548 dev->udc_usb_ep[0].pxa_ep = &dev->pxa_ep[0];
1549 ep0_idle(dev);
1550
1551 /* PXA endpoints init */
1552 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
1553 ep = &dev->pxa_ep[i];
1554
1555 ep->enabled = is_ep0(ep);
1556 INIT_LIST_HEAD(&ep->queue);
1557 spin_lock_init(&ep->lock);
1558 }
1559
1560 /* USB endpoints init */
1561 for (i = 0; i < NR_USB_ENDPOINTS; i++)
1562 if (i != 0)
1563 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list,
1564 &dev->gadget.ep_list);
1565}
1566
1567/**
1568 * udc_enable - Enables the udc device
1569 * @dev: udc device
1570 *
1571 * Enables the udc device : enables clocks, udc interrupts, control endpoint
1572 * interrupts, sets usb as UDC client and setups endpoints.
1573 */
1574static void udc_enable(struct pxa_udc *udc)
1575{
1576 udc_writel(udc, UDCICR0, 0);
1577 udc_writel(udc, UDCICR1, 0);
1578 udc_writel(udc, UP2OCR, UP2OCR_HXOE);
1579 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
1580
1581 clk_enable(udc->clk);
1582
1583 ep0_idle(udc);
1584 udc->gadget.speed = USB_SPEED_FULL;
1585 memset(&udc->stats, 0, sizeof(udc->stats));
1586
1587 udc_set_mask_UDCCR(udc, UDCCR_UDE);
1588 udelay(2);
1589 if (udc_readl(udc, UDCCR) & UDCCR_EMCE)
1590 dev_err(udc->dev, "Configuration errors, udc disabled\n");
1591
1592 /*
1593 * Caller must be able to sleep in order to cope with startup transients
1594 */
1595 msleep(100);
1596
1597 /* enable suspend/resume and reset irqs */
1598 udc_writel(udc, UDCICR1,
1599 UDCICR1_IECC | UDCICR1_IERU
1600 | UDCICR1_IESU | UDCICR1_IERS);
1601
1602 /* enable ep0 irqs */
1603 pio_irq_enable(&udc->pxa_ep[0]);
1604
1605 dev_info(udc->dev, "UDC connecting\n");
1606 if (udc->mach->udc_command)
1607 udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
1608}
1609
1610/**
1611 * usb_gadget_register_driver - Register gadget driver
1612 * @driver: gadget driver
1613 *
1614 * When a driver is successfully registered, it will receive control requests
1615 * including set_configuration(), which enables non-control requests. Then
1616 * usb traffic follows until a disconnect is reported. Then a host may connect
1617 * again, or the driver might get unbound.
1618 *
1619 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1620 */
1621int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1622{
1623 struct pxa_udc *udc = the_controller;
1624 int retval;
1625
1626 if (!driver || driver->speed != USB_SPEED_FULL || !driver->bind
1627 || !driver->disconnect || !driver->setup)
1628 return -EINVAL;
1629 if (!udc)
1630 return -ENODEV;
1631 if (udc->driver)
1632 return -EBUSY;
1633
1634 /* first hook up the driver ... */
1635 udc->driver = driver;
1636 udc->gadget.dev.driver = &driver->driver;
1637
1638 retval = device_add(&udc->gadget.dev);
1639 if (retval) {
1640 dev_err(udc->dev, "device_add error %d\n", retval);
1641 goto add_fail;
1642 }
1643 retval = driver->bind(&udc->gadget);
1644 if (retval) {
1645 dev_err(udc->dev, "bind to driver %s --> error %d\n",
1646 driver->driver.name, retval);
1647 goto bind_fail;
1648 }
1649 dev_dbg(udc->dev, "registered gadget driver '%s'\n",
1650 driver->driver.name);
1651
1652 udc_enable(udc);
1653 return 0;
1654
1655bind_fail:
1656 device_del(&udc->gadget.dev);
1657add_fail:
1658 udc->driver = NULL;
1659 udc->gadget.dev.driver = NULL;
1660 return retval;
1661}
1662EXPORT_SYMBOL(usb_gadget_register_driver);
1663
1664
1665/**
1666 * stop_activity - Stops udc endpoints
1667 * @udc: udc device
1668 * @driver: gadget driver
1669 *
1670 * Disables all udc endpoints (even control endpoint), report disconnect to
1671 * the gadget user.
1672 */
1673static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver)
1674{
1675 int i;
1676
1677 /* don't disconnect drivers more than once */
1678 if (udc->gadget.speed == USB_SPEED_UNKNOWN)
1679 driver = NULL;
1680 udc->gadget.speed = USB_SPEED_UNKNOWN;
1681
1682 for (i = 0; i < NR_USB_ENDPOINTS; i++)
1683 pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep);
1684
1685 if (driver)
1686 driver->disconnect(&udc->gadget);
1687}
1688
1689/**
1690 * usb_gadget_unregister_driver - Unregister the gadget driver
1691 * @driver: gadget driver
1692 *
1693 * Returns 0 if no error, -ENODEV, -EINVAL otherwise
1694 */
1695int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1696{
1697 struct pxa_udc *udc = the_controller;
1698
1699 if (!udc)
1700 return -ENODEV;
1701 if (!driver || driver != udc->driver || !driver->unbind)
1702 return -EINVAL;
1703
1704 stop_activity(udc, driver);
1705 udc_disable(udc);
1706
1707 driver->unbind(&udc->gadget);
1708 udc->driver = NULL;
1709
1710 device_del(&udc->gadget.dev);
1711
1712 dev_info(udc->dev, "unregistered gadget driver '%s'\n",
1713 driver->driver.name);
1714 return 0;
1715}
1716EXPORT_SYMBOL(usb_gadget_unregister_driver);
1717
1718/**
1719 * handle_ep0_ctrl_req - handle control endpoint control request
1720 * @udc: udc device
1721 * @req: control request
1722 */
1723static void handle_ep0_ctrl_req(struct pxa_udc *udc,
1724 struct pxa27x_request *req)
1725{
1726 struct pxa_ep *ep = &udc->pxa_ep[0];
1727 union {
1728 struct usb_ctrlrequest r;
1729 u32 word[2];
1730 } u;
1731 int i;
1732 int have_extrabytes = 0;
1733
1734 nuke(ep, -EPROTO);
1735
1736 /* read SETUP packet */
1737 for (i = 0; i < 2; i++) {
1738 if (unlikely(ep_is_empty(ep)))
1739 goto stall;
1740 u.word[i] = udc_ep_readl(ep, UDCDR);
1741 }
1742
1743 have_extrabytes = !ep_is_empty(ep);
1744 while (!ep_is_empty(ep)) {
1745 i = udc_ep_readl(ep, UDCDR);
1746 ep_err(ep, "wrong to have extra bytes for setup : 0x%08x\n", i);
1747 }
1748
1749 ep_dbg(ep, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1750 u.r.bRequestType, u.r.bRequest,
1751 le16_to_cpu(u.r.wValue), le16_to_cpu(u.r.wIndex),
1752 le16_to_cpu(u.r.wLength));
1753 if (unlikely(have_extrabytes))
1754 goto stall;
1755
1756 if (u.r.bRequestType & USB_DIR_IN)
1757 set_ep0state(udc, IN_DATA_STAGE);
1758 else
1759 set_ep0state(udc, OUT_DATA_STAGE);
1760
1761 /* Tell UDC to enter Data Stage */
1762 udc_ep_writel(ep, UDCCSR, UDCCSR0_SA | UDCCSR0_OPC);
1763
1764 i = udc->driver->setup(&udc->gadget, &u.r);
1765 if (i < 0)
1766 goto stall;
1767out:
1768 return;
1769stall:
1770 ep_dbg(ep, "protocol STALL, udccsr0=%03x err %d\n",
1771 udc_ep_readl(ep, UDCCSR), i);
1772 udc_ep_writel(ep, UDCCSR, UDCCSR0_FST | UDCCSR0_FTF);
1773 set_ep0state(udc, STALL);
1774 goto out;
1775}
1776
1777/**
1778 * handle_ep0 - Handle control endpoint data transfers
1779 * @udc: udc device
1780 * @fifo_irq: 1 if triggered by fifo service type irq
1781 * @opc_irq: 1 if triggered by output packet complete type irq
1782 *
1783 * Context : when in_interrupt() or with ep->lock held
1784 *
1785 * Tries to transfer all pending request data into the endpoint and/or
1786 * transfer all pending data in the endpoint into usb requests.
1787 * Handles states of ep0 automata.
1788 *
1789 * PXA27x hardware handles several standard usb control requests without
1790 * driver notification. The requests fully handled by hardware are :
1791 * SET_ADDRESS, SET_FEATURE, CLEAR_FEATURE, GET_CONFIGURATION, GET_INTERFACE,
1792 * GET_STATUS
1793 * The requests handled by hardware, but with irq notification are :
1794 * SYNCH_FRAME, SET_CONFIGURATION, SET_INTERFACE
1795 * The remaining standard requests really handled by handle_ep0 are :
1796 * GET_DESCRIPTOR, SET_DESCRIPTOR, specific requests.
1797 * Requests standardized outside of USB 2.0 chapter 9 are handled more
1798 * uniformly, by gadget drivers.
1799 *
1800 * The control endpoint state machine is _not_ USB spec compliant, it's even
1801 * hardly compliant with Intel PXA270 developers guide.
1802 * The key points which inferred this state machine are :
1803 * - on every setup token, bit UDCCSR0_SA is raised and held until cleared by
1804 * software.
1805 * - on every OUT packet received, UDCCSR0_OPC is raised and held until
1806 * cleared by software.
1807 * - clearing UDCCSR0_OPC always flushes ep0. If in setup stage, never do it
1808 * before reading ep0.
1809 * - irq can be called on a "packet complete" event (opc_irq=1), while
1810 * UDCCSR0_OPC is not yet raised (delta can be as big as 100ms
1811 * from experimentation).
1812 * - as UDCCSR0_SA can be activated while in irq handling, and clearing
1813 * UDCCSR0_OPC would flush the setup data, we almost never clear UDCCSR0_OPC
1814 * => we never actually read the "status stage" packet of an IN data stage
1815 * => this is not documented in Intel documentation
1816 * - hardware as no idea of STATUS STAGE, it only handle SETUP STAGE and DATA
1817 * STAGE. The driver add STATUS STAGE to send last zero length packet in
1818 * OUT_STATUS_STAGE.
1819 * - special attention was needed for IN_STATUS_STAGE. If a packet complete
1820 * event is detected, we terminate the status stage without ackowledging the
1821 * packet (not to risk to loose a potential SETUP packet)
1822 */
1823static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
1824{
1825 u32 udccsr0;
1826 struct pxa_ep *ep = &udc->pxa_ep[0];
1827 struct pxa27x_request *req = NULL;
1828 int completed = 0;
1829
1830 udccsr0 = udc_ep_readl(ep, UDCCSR);
1831 ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n",
1832 EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR),
1833 (fifo_irq << 1 | opc_irq));
1834
1835 if (!list_empty(&ep->queue))
1836 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
1837
1838 if (udccsr0 & UDCCSR0_SST) {
1839 ep_dbg(ep, "clearing stall status\n");
1840 nuke(ep, -EPIPE);
1841 udc_ep_writel(ep, UDCCSR, UDCCSR0_SST);
1842 ep0_idle(udc);
1843 }
1844
1845 if (udccsr0 & UDCCSR0_SA) {
1846 nuke(ep, 0);
1847 set_ep0state(udc, SETUP_STAGE);
1848 }
1849
1850 switch (udc->ep0state) {
1851 case WAIT_FOR_SETUP:
1852 /*
1853 * Hardware bug : beware, we cannot clear OPC, since we would
1854 * miss a potential OPC irq for a setup packet.
1855 * So, we only do ... nothing, and hope for a next irq with
1856 * UDCCSR0_SA set.
1857 */
1858 break;
1859 case SETUP_STAGE:
1860 udccsr0 &= UDCCSR0_CTRL_REQ_MASK;
1861 if (likely(udccsr0 == UDCCSR0_CTRL_REQ_MASK))
1862 handle_ep0_ctrl_req(udc, req);
1863 break;
1864 case IN_DATA_STAGE: /* GET_DESCRIPTOR */
1865 if (epout_has_pkt(ep))
1866 udc_ep_writel(ep, UDCCSR, UDCCSR0_OPC);
1867 if (req && !ep_is_full(ep))
1868 completed = write_ep0_fifo(ep, req);
1869 if (completed)
1870 ep0_end_in_req(ep, req);
1871 break;
1872 case OUT_DATA_STAGE: /* SET_DESCRIPTOR */
1873 if (epout_has_pkt(ep) && req)
1874 completed = read_ep0_fifo(ep, req);
1875 if (completed)
1876 ep0_end_out_req(ep, req);
1877 break;
1878 case STALL:
1879 udc_ep_writel(ep, UDCCSR, UDCCSR0_FST);
1880 break;
1881 case IN_STATUS_STAGE:
1882 /*
1883 * Hardware bug : beware, we cannot clear OPC, since we would
1884 * miss a potential PC irq for a setup packet.
1885 * So, we only put the ep0 into WAIT_FOR_SETUP state.
1886 */
1887 if (opc_irq)
1888 ep0_idle(udc);
1889 break;
1890 case OUT_STATUS_STAGE:
1891 case WAIT_ACK_SET_CONF_INTERF:
1892 ep_warn(ep, "should never get in %s state here!!!\n",
1893 EP0_STNAME(ep->dev));
1894 ep0_idle(udc);
1895 break;
1896 }
1897}
1898
1899/**
1900 * handle_ep - Handle endpoint data tranfers
1901 * @ep: pxa physical endpoint
1902 *
1903 * Tries to transfer all pending request data into the endpoint and/or
1904 * transfer all pending data in the endpoint into usb requests.
1905 *
1906 * Is always called when in_interrupt() or with ep->lock held.
1907 */
1908static void handle_ep(struct pxa_ep *ep)
1909{
1910 struct pxa27x_request *req;
1911 int completed;
1912 u32 udccsr;
1913 int is_in = ep->dir_in;
1914 int loop = 0;
1915
1916 do {
1917 completed = 0;
1918 udccsr = udc_ep_readl(ep, UDCCSR);
1919 if (likely(!list_empty(&ep->queue)))
1920 req = list_entry(ep->queue.next,
1921 struct pxa27x_request, queue);
1922 else
1923 req = NULL;
1924
1925 ep_dbg(ep, "req:%p, udccsr 0x%03x loop=%d\n",
1926 req, udccsr, loop++);
1927
1928 if (unlikely(udccsr & (UDCCSR_SST | UDCCSR_TRN)))
1929 udc_ep_writel(ep, UDCCSR,
1930 udccsr & (UDCCSR_SST | UDCCSR_TRN));
1931 if (!req)
1932 break;
1933
1934 if (unlikely(is_in)) {
1935 if (likely(!ep_is_full(ep)))
1936 completed = write_fifo(ep, req);
1937 if (completed)
1938 ep_end_in_req(ep, req);
1939 } else {
1940 if (likely(epout_has_pkt(ep)))
1941 completed = read_fifo(ep, req);
1942 if (completed)
1943 ep_end_out_req(ep, req);
1944 }
1945 } while (completed);
1946}
1947
1948/**
1949 * pxa27x_change_configuration - Handle SET_CONF usb request notification
1950 * @udc: udc device
1951 * @config: usb configuration
1952 *
1953 * Post the request to upper level.
1954 * Don't use any pxa specific harware configuration capabilities
1955 */
1956static void pxa27x_change_configuration(struct pxa_udc *udc, int config)
1957{
1958 struct usb_ctrlrequest req ;
1959
1960 dev_dbg(udc->dev, "config=%d\n", config);
1961
1962 udc->config = config;
1963 udc->last_interface = 0;
1964 udc->last_alternate = 0;
1965
1966 req.bRequestType = 0;
1967 req.bRequest = USB_REQ_SET_CONFIGURATION;
1968 req.wValue = config;
1969 req.wIndex = 0;
1970 req.wLength = 0;
1971
1972 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF);
1973 udc->driver->setup(&udc->gadget, &req);
1974}
1975
1976/**
1977 * pxa27x_change_interface - Handle SET_INTERF usb request notification
1978 * @udc: udc device
1979 * @iface: interface number
1980 * @alt: alternate setting number
1981 *
1982 * Post the request to upper level.
1983 * Don't use any pxa specific harware configuration capabilities
1984 */
1985static void pxa27x_change_interface(struct pxa_udc *udc, int iface, int alt)
1986{
1987 struct usb_ctrlrequest req;
1988
1989 dev_dbg(udc->dev, "interface=%d, alternate setting=%d\n", iface, alt);
1990
1991 udc->last_interface = iface;
1992 udc->last_alternate = alt;
1993
1994 req.bRequestType = USB_RECIP_INTERFACE;
1995 req.bRequest = USB_REQ_SET_INTERFACE;
1996 req.wValue = alt;
1997 req.wIndex = iface;
1998 req.wLength = 0;
1999
2000 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF);
2001 udc->driver->setup(&udc->gadget, &req);
2002}
2003
2004/*
2005 * irq_handle_data - Handle data transfer
2006 * @irq: irq IRQ number
2007 * @udc: dev pxa_udc device structure
2008 *
2009 * Called from irq handler, transferts data to or from endpoint to queue
2010 */
2011static void irq_handle_data(int irq, struct pxa_udc *udc)
2012{
2013 int i;
2014 struct pxa_ep *ep;
2015 u32 udcisr0 = udc_readl(udc, UDCISR0) & UDCCISR0_EP_MASK;
2016 u32 udcisr1 = udc_readl(udc, UDCISR1) & UDCCISR1_EP_MASK;
2017
2018 if (udcisr0 & UDCISR_INT_MASK) {
2019 udc->pxa_ep[0].stats.irqs++;
2020 udc_writel(udc, UDCISR0, UDCISR_INT(0, UDCISR_INT_MASK));
2021 handle_ep0(udc, !!(udcisr0 & UDCICR_FIFOERR),
2022 !!(udcisr0 & UDCICR_PKTCOMPL));
2023 }
2024
2025 udcisr0 >>= 2;
2026 for (i = 1; udcisr0 != 0 && i < 16; udcisr0 >>= 2, i++) {
2027 if (!(udcisr0 & UDCISR_INT_MASK))
2028 continue;
2029
2030 udc_writel(udc, UDCISR0, UDCISR_INT(i, UDCISR_INT_MASK));
2031 ep = &udc->pxa_ep[i];
2032 ep->stats.irqs++;
2033 handle_ep(ep);
2034 }
2035
2036 for (i = 16; udcisr1 != 0 && i < 24; udcisr1 >>= 2, i++) {
2037 udc_writel(udc, UDCISR1, UDCISR_INT(i - 16, UDCISR_INT_MASK));
2038 if (!(udcisr1 & UDCISR_INT_MASK))
2039 continue;
2040
2041 ep = &udc->pxa_ep[i];
2042 ep->stats.irqs++;
2043 handle_ep(ep);
2044 }
2045
2046}
2047
2048/**
2049 * irq_udc_suspend - Handle IRQ "UDC Suspend"
2050 * @udc: udc device
2051 */
2052static void irq_udc_suspend(struct pxa_udc *udc)
2053{
2054 udc_writel(udc, UDCISR1, UDCISR1_IRSU);
2055 udc->stats.irqs_suspend++;
2056
2057 if (udc->gadget.speed != USB_SPEED_UNKNOWN
2058 && udc->driver && udc->driver->suspend)
2059 udc->driver->suspend(&udc->gadget);
2060 ep0_idle(udc);
2061}
2062
2063/**
2064 * irq_udc_resume - Handle IRQ "UDC Resume"
2065 * @udc: udc device
2066 */
2067static void irq_udc_resume(struct pxa_udc *udc)
2068{
2069 udc_writel(udc, UDCISR1, UDCISR1_IRRU);
2070 udc->stats.irqs_resume++;
2071
2072 if (udc->gadget.speed != USB_SPEED_UNKNOWN
2073 && udc->driver && udc->driver->resume)
2074 udc->driver->resume(&udc->gadget);
2075}
2076
2077/**
2078 * irq_udc_reconfig - Handle IRQ "UDC Change Configuration"
2079 * @udc: udc device
2080 */
2081static void irq_udc_reconfig(struct pxa_udc *udc)
2082{
2083 unsigned config, interface, alternate, config_change;
2084 u32 udccr = udc_readl(udc, UDCCR);
2085
2086 udc_writel(udc, UDCISR1, UDCISR1_IRCC);
2087 udc->stats.irqs_reconfig++;
2088
2089 config = (udccr & UDCCR_ACN) >> UDCCR_ACN_S;
2090 config_change = (config != udc->config);
2091 pxa27x_change_configuration(udc, config);
2092
2093 interface = (udccr & UDCCR_AIN) >> UDCCR_AIN_S;
2094 alternate = (udccr & UDCCR_AAISN) >> UDCCR_AAISN_S;
2095 pxa27x_change_interface(udc, interface, alternate);
2096
2097 if (config_change)
2098 update_pxa_ep_matches(udc);
2099 udc_set_mask_UDCCR(udc, UDCCR_SMAC);
2100}
2101
2102/**
2103 * irq_udc_reset - Handle IRQ "UDC Reset"
2104 * @udc: udc device
2105 */
2106static void irq_udc_reset(struct pxa_udc *udc)
2107{
2108 u32 udccr = udc_readl(udc, UDCCR);
2109 struct pxa_ep *ep = &udc->pxa_ep[0];
2110
2111 dev_info(udc->dev, "USB reset\n");
2112 udc_writel(udc, UDCISR1, UDCISR1_IRRS);
2113 udc->stats.irqs_reset++;
2114
2115 if ((udccr & UDCCR_UDA) == 0) {
2116 dev_dbg(udc->dev, "USB reset start\n");
2117 stop_activity(udc, udc->driver);
2118 }
2119 udc->gadget.speed = USB_SPEED_FULL;
2120 memset(&udc->stats, 0, sizeof udc->stats);
2121
2122 nuke(ep, -EPROTO);
2123 udc_ep_writel(ep, UDCCSR, UDCCSR0_FTF | UDCCSR0_OPC);
2124 ep0_idle(udc);
2125}
2126
2127/**
2128 * pxa_udc_irq - Main irq handler
2129 * @irq: irq number
2130 * @_dev: udc device
2131 *
2132 * Handles all udc interrupts
2133 */
2134static irqreturn_t pxa_udc_irq(int irq, void *_dev)
2135{
2136 struct pxa_udc *udc = _dev;
2137 u32 udcisr0 = udc_readl(udc, UDCISR0);
2138 u32 udcisr1 = udc_readl(udc, UDCISR1);
2139 u32 udccr = udc_readl(udc, UDCCR);
2140 u32 udcisr1_spec;
2141
2142 dev_vdbg(udc->dev, "Interrupt, UDCISR0:0x%08x, UDCISR1:0x%08x, "
2143 "UDCCR:0x%08x\n", udcisr0, udcisr1, udccr);
2144
2145 udcisr1_spec = udcisr1 & 0xf8000000;
2146 if (unlikely(udcisr1_spec & UDCISR1_IRSU))
2147 irq_udc_suspend(udc);
2148 if (unlikely(udcisr1_spec & UDCISR1_IRRU))
2149 irq_udc_resume(udc);
2150 if (unlikely(udcisr1_spec & UDCISR1_IRCC))
2151 irq_udc_reconfig(udc);
2152 if (unlikely(udcisr1_spec & UDCISR1_IRRS))
2153 irq_udc_reset(udc);
2154
2155 if ((udcisr0 & UDCCISR0_EP_MASK) | (udcisr1 & UDCCISR1_EP_MASK))
2156 irq_handle_data(irq, udc);
2157
2158 return IRQ_HANDLED;
2159}
2160
2161static struct pxa_udc memory = {
2162 .gadget = {
2163 .ops = &pxa_udc_ops,
2164 .ep0 = &memory.udc_usb_ep[0].usb_ep,
2165 .name = driver_name,
2166 .dev = {
2167 .bus_id = "gadget",
2168 },
2169 },
2170
2171 .udc_usb_ep = {
2172 USB_EP_CTRL,
2173 USB_EP_OUT_BULK(1),
2174 USB_EP_IN_BULK(2),
2175 USB_EP_IN_ISO(3),
2176 USB_EP_OUT_ISO(4),
2177 USB_EP_IN_INT(5),
2178 },
2179
2180 .pxa_ep = {
2181 PXA_EP_CTRL,
2182 /* Endpoints for gadget zero */
2183 PXA_EP_OUT_BULK(1, 1, 3, 0, 0),
2184 PXA_EP_IN_BULK(2, 2, 3, 0, 0),
2185 /* Endpoints for ether gadget, file storage gadget */
2186 PXA_EP_OUT_BULK(3, 1, 1, 0, 0),
2187 PXA_EP_IN_BULK(4, 2, 1, 0, 0),
2188 PXA_EP_IN_ISO(5, 3, 1, 0, 0),
2189 PXA_EP_OUT_ISO(6, 4, 1, 0, 0),
2190 PXA_EP_IN_INT(7, 5, 1, 0, 0),
2191 /* Endpoints for RNDIS, serial */
2192 PXA_EP_OUT_BULK(8, 1, 2, 0, 0),
2193 PXA_EP_IN_BULK(9, 2, 2, 0, 0),
2194 PXA_EP_IN_INT(10, 5, 2, 0, 0),
2195 /*
2196 * All the following endpoints are only for completion. They
2197 * won't never work, as multiple interfaces are really broken on
2198 * the pxa.
2199 */
2200 PXA_EP_OUT_BULK(11, 1, 2, 1, 0),
2201 PXA_EP_IN_BULK(12, 2, 2, 1, 0),
2202 /* Endpoint for CDC Ether */
2203 PXA_EP_OUT_BULK(13, 1, 1, 1, 1),
2204 PXA_EP_IN_BULK(14, 2, 1, 1, 1),
2205 }
2206};
2207
2208/**
2209 * pxa_udc_probe - probes the udc device
2210 * @_dev: platform device
2211 *
2212 * Perform basic init : allocates udc clock, creates sysfs files, requests
2213 * irq.
2214 */
2215static int __init pxa_udc_probe(struct platform_device *pdev)
2216{
2217 struct resource *regs;
2218 struct pxa_udc *udc = &memory;
2219 int retval;
2220
2221 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2222 if (!regs)
2223 return -ENXIO;
2224 udc->irq = platform_get_irq(pdev, 0);
2225 if (udc->irq < 0)
2226 return udc->irq;
2227
2228 udc->dev = &pdev->dev;
2229 udc->mach = pdev->dev.platform_data;
2230
2231 udc->clk = clk_get(&pdev->dev, "UDCCLK");
2232 if (IS_ERR(udc->clk)) {
2233 retval = PTR_ERR(udc->clk);
2234 goto err_clk;
2235 }
2236
2237 retval = -ENOMEM;
2238 udc->regs = ioremap(regs->start, regs->end - regs->start + 1);
2239 if (!udc->regs) {
2240 dev_err(&pdev->dev, "Unable to map UDC I/O memory\n");
2241 goto err_map;
2242 }
2243
2244 device_initialize(&udc->gadget.dev);
2245 udc->gadget.dev.parent = &pdev->dev;
2246 udc->gadget.dev.dma_mask = NULL;
2247
2248 the_controller = udc;
2249 platform_set_drvdata(pdev, udc);
2250 udc_init_data(udc);
2251 pxa_eps_setup(udc);
2252
2253 /* irq setup after old hardware state is cleaned up */
2254 retval = request_irq(udc->irq, pxa_udc_irq,
2255 IRQF_SHARED, driver_name, udc);
2256 if (retval != 0) {
2257 dev_err(udc->dev, "%s: can't get irq %i, err %d\n",
2258 driver_name, IRQ_USB, retval);
2259 goto err_irq;
2260 }
2261
2262 pxa_init_debugfs(udc);
2263 return 0;
2264err_irq:
2265 iounmap(udc->regs);
2266err_map:
2267 clk_put(udc->clk);
2268 udc->clk = NULL;
2269err_clk:
2270 return retval;
2271}
2272
2273/**
2274 * pxa_udc_remove - removes the udc device driver
2275 * @_dev: platform device
2276 */
2277static int __exit pxa_udc_remove(struct platform_device *_dev)
2278{
2279 struct pxa_udc *udc = platform_get_drvdata(_dev);
2280
2281 usb_gadget_unregister_driver(udc->driver);
2282 free_irq(udc->irq, udc);
2283 pxa_cleanup_debugfs(udc);
2284
2285 platform_set_drvdata(_dev, NULL);
2286 the_controller = NULL;
2287 clk_put(udc->clk);
2288
2289 return 0;
2290}
2291
2292static void pxa_udc_shutdown(struct platform_device *_dev)
2293{
2294 struct pxa_udc *udc = platform_get_drvdata(_dev);
2295
2296 if (udc_readl(udc, UDCCR) & UDCCR_UDE)
2297 udc_disable(udc);
2298}
2299
2300#ifdef CONFIG_PM
2301/**
2302 * pxa_udc_suspend - Suspend udc device
2303 * @_dev: platform device
2304 * @state: suspend state
2305 *
2306 * Suspends udc : saves configuration registers (UDCCR*), then disables the udc
2307 * device.
2308 */
2309static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state)
2310{
2311 int i;
2312 struct pxa_udc *udc = platform_get_drvdata(_dev);
2313 struct pxa_ep *ep;
2314
2315 ep = &udc->pxa_ep[0];
2316 udc->udccsr0 = udc_ep_readl(ep, UDCCSR);
2317 for (i = 1; i < NR_PXA_ENDPOINTS; i++) {
2318 ep = &udc->pxa_ep[i];
2319 ep->udccsr_value = udc_ep_readl(ep, UDCCSR);
2320 ep->udccr_value = udc_ep_readl(ep, UDCCR);
2321 ep_dbg(ep, "udccsr:0x%03x, udccr:0x%x\n",
2322 ep->udccsr_value, ep->udccr_value);
2323 }
2324
2325 udc_disable(udc);
2326
2327 return 0;
2328}
2329
2330/**
2331 * pxa_udc_resume - Resume udc device
2332 * @_dev: platform device
2333 *
2334 * Resumes udc : restores configuration registers (UDCCR*), then enables the udc
2335 * device.
2336 */
2337static int pxa_udc_resume(struct platform_device *_dev)
2338{
2339 int i;
2340 struct pxa_udc *udc = platform_get_drvdata(_dev);
2341 struct pxa_ep *ep;
2342
2343 ep = &udc->pxa_ep[0];
2344 udc_ep_writel(ep, UDCCSR, udc->udccsr0 & (UDCCSR0_FST | UDCCSR0_DME));
2345 for (i = 1; i < NR_PXA_ENDPOINTS; i++) {
2346 ep = &udc->pxa_ep[i];
2347 udc_ep_writel(ep, UDCCSR, ep->udccsr_value);
2348 udc_ep_writel(ep, UDCCR, ep->udccr_value);
2349 ep_dbg(ep, "udccsr:0x%03x, udccr:0x%x\n",
2350 ep->udccsr_value, ep->udccr_value);
2351 }
2352
2353 udc_enable(udc);
2354 /*
2355 * We do not handle OTG yet.
2356 *
2357 * OTGPH bit is set when sleep mode is entered.
2358 * it indicates that OTG pad is retaining its state.
2359 * Upon exit from sleep mode and before clearing OTGPH,
2360 * Software must configure the USB OTG pad, UDC, and UHC
2361 * to the state they were in before entering sleep mode.
2362 */
2363 PSSR |= PSSR_OTGPH;
2364
2365 return 0;
2366}
2367#endif
2368
2369/* work with hotplug and coldplug */
2370MODULE_ALIAS("platform:pxa2xx-udc");
2371
2372static struct platform_driver udc_driver = {
2373 .driver = {
2374 .name = "pxa2xx-udc",
2375 .owner = THIS_MODULE,
2376 },
2377 .remove = __exit_p(pxa_udc_remove),
2378 .shutdown = pxa_udc_shutdown,
2379#ifdef CONFIG_PM
2380 .suspend = pxa_udc_suspend,
2381 .resume = pxa_udc_resume
2382#endif
2383};
2384
2385static int __init udc_init(void)
2386{
2387 if (!cpu_is_pxa27x())
2388 return -ENODEV;
2389
2390 printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION);
2391 return platform_driver_probe(&udc_driver, pxa_udc_probe);
2392}
2393module_init(udc_init);
2394
2395
2396static void __exit udc_exit(void)
2397{
2398 platform_driver_unregister(&udc_driver);
2399}
2400module_exit(udc_exit);
2401
2402MODULE_DESCRIPTION(DRIVER_DESC);
2403MODULE_AUTHOR("Robert Jarzmik");
2404MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
new file mode 100644
index 000000000000..97453db924ff
--- /dev/null
+++ b/drivers/usb/gadget/pxa27x_udc.h
@@ -0,0 +1,495 @@
1/*
2 * linux/drivers/usb/gadget/pxa27x_udc.h
3 * Intel PXA27x on-chip full speed USB device controller
4 *
5 * Inspired by original driver by Frank Becker, David Brownell, and others.
6 * Copyright (C) 2008 Robert Jarzmik
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __LINUX_USB_GADGET_PXA27X_H
24#define __LINUX_USB_GADGET_PXA27X_H
25
26#include <linux/types.h>
27#include <linux/spinlock.h>
28#include <linux/io.h>
29
30/*
31 * Register definitions
32 */
33/* Offsets */
34#define UDCCR 0x0000 /* UDC Control Register */
35#define UDCICR0 0x0004 /* UDC Interrupt Control Register0 */
36#define UDCICR1 0x0008 /* UDC Interrupt Control Register1 */
37#define UDCISR0 0x000C /* UDC Interrupt Status Register 0 */
38#define UDCISR1 0x0010 /* UDC Interrupt Status Register 1 */
39#define UDCFNR 0x0014 /* UDC Frame Number Register */
40#define UDCOTGICR 0x0018 /* UDC On-The-Go interrupt control */
41#define UP2OCR 0x0020 /* USB Port 2 Output Control register */
42#define UP3OCR 0x0024 /* USB Port 3 Output Control register */
43#define UDCCSRn(x) (0x0100 + ((x)<<2)) /* UDC Control/Status register */
44#define UDCBCRn(x) (0x0200 + ((x)<<2)) /* UDC Byte Count Register */
45#define UDCDRn(x) (0x0300 + ((x)<<2)) /* UDC Data Register */
46#define UDCCRn(x) (0x0400 + ((x)<<2)) /* UDC Control Register */
47
48#define UDCCR_OEN (1 << 31) /* On-the-Go Enable */
49#define UDCCR_AALTHNP (1 << 30) /* A-device Alternate Host Negotiation
50 Protocol Port Support */
51#define UDCCR_AHNP (1 << 29) /* A-device Host Negotiation Protocol
52 Support */
53#define UDCCR_BHNP (1 << 28) /* B-device Host Negotiation Protocol
54 Enable */
55#define UDCCR_DWRE (1 << 16) /* Device Remote Wake-up Enable */
56#define UDCCR_ACN (0x03 << 11) /* Active UDC configuration Number */
57#define UDCCR_ACN_S 11
58#define UDCCR_AIN (0x07 << 8) /* Active UDC interface Number */
59#define UDCCR_AIN_S 8
60#define UDCCR_AAISN (0x07 << 5) /* Active UDC Alternate Interface
61 Setting Number */
62#define UDCCR_AAISN_S 5
63#define UDCCR_SMAC (1 << 4) /* Switch Endpoint Memory to Active
64 Configuration */
65#define UDCCR_EMCE (1 << 3) /* Endpoint Memory Configuration
66 Error */
67#define UDCCR_UDR (1 << 2) /* UDC Resume */
68#define UDCCR_UDA (1 << 1) /* UDC Active */
69#define UDCCR_UDE (1 << 0) /* UDC Enable */
70
71#define UDCICR_INT(n, intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
72#define UDCICR1_IECC (1 << 31) /* IntEn - Configuration Change */
73#define UDCICR1_IESOF (1 << 30) /* IntEn - Start of Frame */
74#define UDCICR1_IERU (1 << 29) /* IntEn - Resume */
75#define UDCICR1_IESU (1 << 28) /* IntEn - Suspend */
76#define UDCICR1_IERS (1 << 27) /* IntEn - Reset */
77#define UDCICR_FIFOERR (1 << 1) /* FIFO Error interrupt for EP */
78#define UDCICR_PKTCOMPL (1 << 0) /* Packet Complete interrupt for EP */
79#define UDCICR_INT_MASK (UDCICR_FIFOERR | UDCICR_PKTCOMPL)
80
81#define UDCISR_INT(n, intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
82#define UDCISR1_IRCC (1 << 31) /* IntReq - Configuration Change */
83#define UDCISR1_IRSOF (1 << 30) /* IntReq - Start of Frame */
84#define UDCISR1_IRRU (1 << 29) /* IntReq - Resume */
85#define UDCISR1_IRSU (1 << 28) /* IntReq - Suspend */
86#define UDCISR1_IRRS (1 << 27) /* IntReq - Reset */
87#define UDCISR_INT_MASK (UDCICR_FIFOERR | UDCICR_PKTCOMPL)
88
89#define UDCOTGICR_IESF (1 << 24) /* OTG SET_FEATURE command recvd */
90#define UDCOTGICR_IEXR (1 << 17) /* Extra Transciever Interrupt
91 Rising Edge Interrupt Enable */
92#define UDCOTGICR_IEXF (1 << 16) /* Extra Transciever Interrupt
93 Falling Edge Interrupt Enable */
94#define UDCOTGICR_IEVV40R (1 << 9) /* OTG Vbus Valid 4.0V Rising Edge
95 Interrupt Enable */
96#define UDCOTGICR_IEVV40F (1 << 8) /* OTG Vbus Valid 4.0V Falling Edge
97 Interrupt Enable */
98#define UDCOTGICR_IEVV44R (1 << 7) /* OTG Vbus Valid 4.4V Rising Edge
99 Interrupt Enable */
100#define UDCOTGICR_IEVV44F (1 << 6) /* OTG Vbus Valid 4.4V Falling Edge
101 Interrupt Enable */
102#define UDCOTGICR_IESVR (1 << 5) /* OTG Session Valid Rising Edge
103 Interrupt Enable */
104#define UDCOTGICR_IESVF (1 << 4) /* OTG Session Valid Falling Edge
105 Interrupt Enable */
106#define UDCOTGICR_IESDR (1 << 3) /* OTG A-Device SRP Detect Rising
107 Edge Interrupt Enable */
108#define UDCOTGICR_IESDF (1 << 2) /* OTG A-Device SRP Detect Falling
109 Edge Interrupt Enable */
110#define UDCOTGICR_IEIDR (1 << 1) /* OTG ID Change Rising Edge
111 Interrupt Enable */
112#define UDCOTGICR_IEIDF (1 << 0) /* OTG ID Change Falling Edge
113 Interrupt Enable */
114
115/* Host Port 2 field bits */
116#define UP2OCR_CPVEN (1 << 0) /* Charge Pump Vbus Enable */
117#define UP2OCR_CPVPE (1 << 1) /* Charge Pump Vbus Pulse Enable */
118 /* Transceiver enablers */
119#define UP2OCR_DPPDE (1 << 2) /* D+ Pull Down Enable */
120#define UP2OCR_DMPDE (1 << 3) /* D- Pull Down Enable */
121#define UP2OCR_DPPUE (1 << 4) /* D+ Pull Up Enable */
122#define UP2OCR_DMPUE (1 << 5) /* D- Pull Up Enable */
123#define UP2OCR_DPPUBE (1 << 6) /* D+ Pull Up Bypass Enable */
124#define UP2OCR_DMPUBE (1 << 7) /* D- Pull Up Bypass Enable */
125#define UP2OCR_EXSP (1 << 8) /* External Transceiver Speed Control */
126#define UP2OCR_EXSUS (1 << 9) /* External Transceiver Speed Enable */
127#define UP2OCR_IDON (1 << 10) /* OTG ID Read Enable */
128#define UP2OCR_HXS (1 << 16) /* Transceiver Output Select */
129#define UP2OCR_HXOE (1 << 17) /* Transceiver Output Enable */
130#define UP2OCR_SEOS (1 << 24) /* Single-Ended Output Select */
131
132#define UDCCSR0_SA (1 << 7) /* Setup Active */
133#define UDCCSR0_RNE (1 << 6) /* Receive FIFO Not Empty */
134#define UDCCSR0_FST (1 << 5) /* Force Stall */
135#define UDCCSR0_SST (1 << 4) /* Sent Stall */
136#define UDCCSR0_DME (1 << 3) /* DMA Enable */
137#define UDCCSR0_FTF (1 << 2) /* Flush Transmit FIFO */
138#define UDCCSR0_IPR (1 << 1) /* IN Packet Ready */
139#define UDCCSR0_OPC (1 << 0) /* OUT Packet Complete */
140
141#define UDCCSR_DPE (1 << 9) /* Data Packet Error */
142#define UDCCSR_FEF (1 << 8) /* Flush Endpoint FIFO */
143#define UDCCSR_SP (1 << 7) /* Short Packet Control/Status */
144#define UDCCSR_BNE (1 << 6) /* Buffer Not Empty (IN endpoints) */
145#define UDCCSR_BNF (1 << 6) /* Buffer Not Full (OUT endpoints) */
146#define UDCCSR_FST (1 << 5) /* Force STALL */
147#define UDCCSR_SST (1 << 4) /* Sent STALL */
148#define UDCCSR_DME (1 << 3) /* DMA Enable */
149#define UDCCSR_TRN (1 << 2) /* Tx/Rx NAK */
150#define UDCCSR_PC (1 << 1) /* Packet Complete */
151#define UDCCSR_FS (1 << 0) /* FIFO needs service */
152
153#define UDCCONR_CN (0x03 << 25) /* Configuration Number */
154#define UDCCONR_CN_S 25
155#define UDCCONR_IN (0x07 << 22) /* Interface Number */
156#define UDCCONR_IN_S 22
157#define UDCCONR_AISN (0x07 << 19) /* Alternate Interface Number */
158#define UDCCONR_AISN_S 19
159#define UDCCONR_EN (0x0f << 15) /* Endpoint Number */
160#define UDCCONR_EN_S 15
161#define UDCCONR_ET (0x03 << 13) /* Endpoint Type: */
162#define UDCCONR_ET_S 13
163#define UDCCONR_ET_INT (0x03 << 13) /* Interrupt */
164#define UDCCONR_ET_BULK (0x02 << 13) /* Bulk */
165#define UDCCONR_ET_ISO (0x01 << 13) /* Isochronous */
166#define UDCCONR_ET_NU (0x00 << 13) /* Not used */
167#define UDCCONR_ED (1 << 12) /* Endpoint Direction */
168#define UDCCONR_MPS (0x3ff << 2) /* Maximum Packet Size */
169#define UDCCONR_MPS_S 2
170#define UDCCONR_DE (1 << 1) /* Double Buffering Enable */
171#define UDCCONR_EE (1 << 0) /* Endpoint Enable */
172
173#define UDCCR_MASK_BITS (UDCCR_OEN | UDCCR_SMAC | UDCCR_UDR | UDCCR_UDE)
174#define UDCCSR_WR_MASK (UDCCSR_DME | UDCCSR_FST)
175#define UDC_FNR_MASK (0x7ff)
176#define UDC_BCR_MASK (0x3ff)
177
178/*
179 * UDCCR = UDC Endpoint Configuration Registers
180 * UDCCSR = UDC Control/Status Register for this EP
181 * UDCBCR = UDC Byte Count Remaining (contents of OUT fifo)
182 * UDCDR = UDC Endpoint Data Register (the fifo)
183 */
184#define ofs_UDCCR(ep) (UDCCRn(ep->idx))
185#define ofs_UDCCSR(ep) (UDCCSRn(ep->idx))
186#define ofs_UDCBCR(ep) (UDCBCRn(ep->idx))
187#define ofs_UDCDR(ep) (UDCDRn(ep->idx))
188
189/* Register access macros */
190#define udc_ep_readl(ep, reg) \
191 __raw_readl((ep)->dev->regs + ofs_##reg(ep))
192#define udc_ep_writel(ep, reg, value) \
193 __raw_writel((value), ep->dev->regs + ofs_##reg(ep))
194#define udc_ep_readb(ep, reg) \
195 __raw_readb((ep)->dev->regs + ofs_##reg(ep))
196#define udc_ep_writeb(ep, reg, value) \
197 __raw_writeb((value), ep->dev->regs + ofs_##reg(ep))
198#define udc_readl(dev, reg) \
199 __raw_readl((dev)->regs + (reg))
200#define udc_writel(udc, reg, value) \
201 __raw_writel((value), (udc)->regs + (reg))
202
203#define UDCCSR_MASK (UDCCSR_FST | UDCCSR_DME)
204#define UDCCISR0_EP_MASK ~0
205#define UDCCISR1_EP_MASK 0xffff
206#define UDCCSR0_CTRL_REQ_MASK (UDCCSR0_OPC | UDCCSR0_SA | UDCCSR0_RNE)
207
208#define EPIDX(ep) (ep->idx)
209#define EPADDR(ep) (ep->addr)
210#define EPXFERTYPE(ep) (ep->type)
211#define EPNAME(ep) (ep->name)
212#define is_ep0(ep) (!ep->idx)
213#define EPXFERTYPE_is_ISO(ep) (EPXFERTYPE(ep) == USB_ENDPOINT_XFER_ISOC)
214
215/*
216 * Endpoint definitions
217 *
218 * Once enabled, pxa endpoint configuration is freezed, and cannot change
219 * unless a reset happens or the udc is disabled.
220 * Therefore, we must define all pxa potential endpoint definitions needed for
221 * all gadget and set them up before the udc is enabled.
222 *
223 * As the architecture chosen is fully static, meaning the pxa endpoint
224 * configurations are set up once and for all, we must provide a way to match
225 * one usb endpoint (usb_ep) to several pxa endpoints. The reason is that gadget
226 * layer autoconf doesn't choose the usb_ep endpoint on (config, interface, alt)
227 * criteria, while the pxa architecture requires that.
228 *
229 * The solution is to define several pxa endpoints matching one usb_ep. Ex:
230 * - "ep1-in" matches pxa endpoint EPA (which is an IN ep at addr 1, when
231 * the udc talks on (config=3, interface=0, alt=0)
232 * - "ep1-in" matches pxa endpoint EPB (which is an IN ep at addr 1, when
233 * the udc talks on (config=3, interface=0, alt=1)
234 * - "ep1-in" matches pxa endpoint EPC (which is an IN ep at addr 1, when
235 * the udc talks on (config=2, interface=0, alt=0)
236 *
237 * We'll define the pxa endpoint by its index (EPA => idx=1, EPB => idx=2, ...)
238 */
239
240/*
241 * Endpoint definition helpers
242 */
243#define USB_EP_DEF(addr, bname, dir, type, maxpkt) \
244{ .usb_ep = { .name = bname, .ops = &pxa_ep_ops, .maxpacket = maxpkt, }, \
245 .desc = { .bEndpointAddress = addr | (dir ? USB_DIR_IN : 0), \
246 .bmAttributes = type, \
247 .wMaxPacketSize = maxpkt, }, \
248 .dev = &memory \
249}
250#define USB_EP_BULK(addr, bname, dir) \
251 USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_BULK, BULK_FIFO_SIZE)
252#define USB_EP_ISO(addr, bname, dir) \
253 USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_ISOC, ISO_FIFO_SIZE)
254#define USB_EP_INT(addr, bname, dir) \
255 USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_INT, INT_FIFO_SIZE)
256#define USB_EP_IN_BULK(n) USB_EP_BULK(n, "ep" #n "in-bulk", 1)
257#define USB_EP_OUT_BULK(n) USB_EP_BULK(n, "ep" #n "out-bulk", 0)
258#define USB_EP_IN_ISO(n) USB_EP_ISO(n, "ep" #n "in-iso", 1)
259#define USB_EP_OUT_ISO(n) USB_EP_ISO(n, "ep" #n "out-iso", 0)
260#define USB_EP_IN_INT(n) USB_EP_INT(n, "ep" #n "in-int", 1)
261#define USB_EP_CTRL USB_EP_DEF(0, "ep0", 0, 0, EP0_FIFO_SIZE)
262
263#define PXA_EP_DEF(_idx, _addr, dir, _type, maxpkt, _config, iface, altset) \
264{ \
265 .dev = &memory, \
266 .name = "ep" #_idx, \
267 .idx = _idx, .enabled = 0, \
268 .dir_in = dir, .addr = _addr, \
269 .config = _config, .interface = iface, .alternate = altset, \
270 .type = _type, .fifo_size = maxpkt, \
271}
272#define PXA_EP_BULK(_idx, addr, dir, config, iface, alt) \
273 PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_BULK, BULK_FIFO_SIZE, \
274 config, iface, alt)
275#define PXA_EP_ISO(_idx, addr, dir, config, iface, alt) \
276 PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_ISOC, ISO_FIFO_SIZE, \
277 config, iface, alt)
278#define PXA_EP_INT(_idx, addr, dir, config, iface, alt) \
279 PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_INT, INT_FIFO_SIZE, \
280 config, iface, alt)
281#define PXA_EP_IN_BULK(i, adr, c, f, a) PXA_EP_BULK(i, adr, 1, c, f, a)
282#define PXA_EP_OUT_BULK(i, adr, c, f, a) PXA_EP_BULK(i, adr, 0, c, f, a)
283#define PXA_EP_IN_ISO(i, adr, c, f, a) PXA_EP_ISO(i, adr, 1, c, f, a)
284#define PXA_EP_OUT_ISO(i, adr, c, f, a) PXA_EP_ISO(i, adr, 0, c, f, a)
285#define PXA_EP_IN_INT(i, adr, c, f, a) PXA_EP_INT(i, adr, 1, c, f, a)
286#define PXA_EP_CTRL PXA_EP_DEF(0, 0, 0, 0, EP0_FIFO_SIZE, 0, 0, 0)
287
288struct pxa27x_udc;
289
290struct stats {
291 unsigned long in_ops;
292 unsigned long out_ops;
293 unsigned long in_bytes;
294 unsigned long out_bytes;
295 unsigned long irqs;
296};
297
298/**
299 * struct udc_usb_ep - container of each usb_ep structure
300 * @usb_ep: usb endpoint
301 * @desc: usb descriptor, especially type and address
302 * @dev: udc managing this endpoint
303 * @pxa_ep: matching pxa_ep (cache of find_pxa_ep() call)
304 */
305struct udc_usb_ep {
306 struct usb_ep usb_ep;
307 struct usb_endpoint_descriptor desc;
308 struct pxa_udc *dev;
309 struct pxa_ep *pxa_ep;
310};
311
312/**
313 * struct pxa_ep - pxa endpoint
314 * @dev: udc device
315 * @queue: requests queue
316 * @lock: lock to pxa_ep data (queues and stats)
317 * @enabled: true when endpoint enabled (not stopped by gadget layer)
318 * @idx: endpoint index (1 => epA, 2 => epB, ..., 24 => epX)
319 * @name: endpoint name (for trace/debug purpose)
320 * @dir_in: 1 if IN endpoint, 0 if OUT endpoint
321 * @addr: usb endpoint number
322 * @config: configuration in which this endpoint is active
323 * @interface: interface in which this endpoint is active
324 * @alternate: altsetting in which this endpoitn is active
325 * @fifo_size: max packet size in the endpoint fifo
326 * @type: endpoint type (bulk, iso, int, ...)
327 * @udccsr_value: save register of UDCCSR0 for suspend/resume
328 * @udccr_value: save register of UDCCR for suspend/resume
329 * @stats: endpoint statistics
330 *
331 * The *PROBLEM* is that pxa's endpoint configuration scheme is both misdesigned
332 * (cares about config/interface/altsetting, thus placing needless limits on
333 * device capability) and full of implementation bugs forcing it to be set up
334 * for use more or less like a pxa255.
335 *
336 * As we define the pxa_ep statically, we must guess all needed pxa_ep for all
337 * gadget which may work with this udc driver.
338 */
339struct pxa_ep {
340 struct pxa_udc *dev;
341
342 struct list_head queue;
343 spinlock_t lock; /* Protects this structure */
344 /* (queues, stats) */
345 unsigned enabled:1;
346
347 unsigned idx:5;
348 char *name;
349
350 /*
351 * Specific pxa endpoint data, needed for hardware initialization
352 */
353 unsigned dir_in:1;
354 unsigned addr:3;
355 unsigned config:2;
356 unsigned interface:3;
357 unsigned alternate:3;
358 unsigned fifo_size;
359 unsigned type;
360
361#ifdef CONFIG_PM
362 u32 udccsr_value;
363 u32 udccr_value;
364#endif
365 struct stats stats;
366};
367
368/**
369 * struct pxa27x_request - container of each usb_request structure
370 * @req: usb request
371 * @udc_usb_ep: usb endpoint the request was submitted on
372 * @in_use: sanity check if request already queued on an pxa_ep
373 * @queue: linked list of requests, linked on pxa_ep->queue
374 */
375struct pxa27x_request {
376 struct usb_request req;
377 struct udc_usb_ep *udc_usb_ep;
378 unsigned in_use:1;
379 struct list_head queue;
380};
381
382enum ep0_state {
383 WAIT_FOR_SETUP,
384 SETUP_STAGE,
385 IN_DATA_STAGE,
386 OUT_DATA_STAGE,
387 IN_STATUS_STAGE,
388 OUT_STATUS_STAGE,
389 STALL,
390 WAIT_ACK_SET_CONF_INTERF
391};
392
393static char *ep0_state_name[] = {
394 "WAIT_FOR_SETUP", "SETUP_STAGE", "IN_DATA_STAGE", "OUT_DATA_STAGE",
395 "IN_STATUS_STAGE", "OUT_STATUS_STAGE", "STALL",
396 "WAIT_ACK_SET_CONF_INTERF"
397};
398#define EP0_STNAME(udc) ep0_state_name[(udc)->ep0state]
399
400#define EP0_FIFO_SIZE 16U
401#define BULK_FIFO_SIZE 64U
402#define ISO_FIFO_SIZE 256U
403#define INT_FIFO_SIZE 16U
404
405struct udc_stats {
406 unsigned long irqs_reset;
407 unsigned long irqs_suspend;
408 unsigned long irqs_resume;
409 unsigned long irqs_reconfig;
410};
411
412#define NR_USB_ENDPOINTS (1 + 5) /* ep0 + ep1in-bulk + .. + ep3in-iso */
413#define NR_PXA_ENDPOINTS (1 + 14) /* ep0 + epA + epB + .. + epX */
414
415/**
416 * struct pxa_udc - udc structure
417 * @regs: mapped IO space
418 * @irq: udc irq
419 * @clk: udc clock
420 * @usb_gadget: udc gadget structure
421 * @driver: bound gadget (zero, g_ether, g_file_storage, ...)
422 * @dev: device
423 * @mach: machine info, used to activate specific GPIO
424 * @ep0state: control endpoint state machine state
425 * @stats: statistics on udc usage
426 * @udc_usb_ep: array of usb endpoints offered by the gadget
427 * @pxa_ep: array of pxa available endpoints
428 * @config: UDC active configuration
429 * @last_interface: UDC interface of the last SET_INTERFACE host request
430 * @last_alternate: UDC altsetting of the last SET_INTERFACE host request
431 * @udccsr0: save of udccsr0 in case of suspend
432 * @debugfs_root: root entry of debug filesystem
433 * @debugfs_state: debugfs entry for "udcstate"
434 * @debugfs_queues: debugfs entry for "queues"
435 * @debugfs_eps: debugfs entry for "epstate"
436 */
437struct pxa_udc {
438 void __iomem *regs;
439 int irq;
440 struct clk *clk;
441
442 struct usb_gadget gadget;
443 struct usb_gadget_driver *driver;
444 struct device *dev;
445 struct pxa2xx_udc_mach_info *mach;
446
447 enum ep0_state ep0state;
448 struct udc_stats stats;
449
450 struct udc_usb_ep udc_usb_ep[NR_USB_ENDPOINTS];
451 struct pxa_ep pxa_ep[NR_PXA_ENDPOINTS];
452
453 unsigned config:2;
454 unsigned last_interface:3;
455 unsigned last_alternate:3;
456
457#ifdef CONFIG_PM
458 unsigned udccsr0;
459#endif
460#ifdef CONFIG_USB_GADGET_DEBUG_FS
461 struct dentry *debugfs_root;
462 struct dentry *debugfs_state;
463 struct dentry *debugfs_queues;
464 struct dentry *debugfs_eps;
465#endif
466};
467
468static inline struct pxa_udc *to_gadget_udc(struct usb_gadget *gadget)
469{
470 return container_of(gadget, struct pxa_udc, gadget);
471}
472
473/*
474 * Debugging/message support
475 */
476#define ep_dbg(ep, fmt, arg...) \
477 dev_dbg(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
478#define ep_vdbg(ep, fmt, arg...) \
479 dev_vdbg(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
480#define ep_err(ep, fmt, arg...) \
481 dev_err(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
482#define ep_info(ep, fmt, arg...) \
483 dev_info(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
484#define ep_warn(ep, fmt, arg...) \
485 dev_warn(ep->dev->dev, "%s:%s:" fmt, EPNAME(ep), __func__, ## arg)
486
487/*
488 * Cannot include pxa-regs.h, as register names are similar.
489 * So PSSR is redefined here. This should be removed once UDC registers will
490 * be gone from pxa-regs.h.
491 */
492#define PSSR __REG(0x40F00004) /* Power Manager Sleep Status */
493#define PSSR_OTGPH (1 << 6) /* OTG Peripheral Hold */
494
495#endif /* __LINUX_USB_GADGET_PXA27X_H */
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 096c41cc40d1..08f699b1fc57 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -235,7 +235,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
235 || ep->bEndpointAddress != desc->bEndpointAddress 235 || ep->bEndpointAddress != desc->bEndpointAddress
236 || ep->fifo_size < le16_to_cpu 236 || ep->fifo_size < le16_to_cpu
237 (desc->wMaxPacketSize)) { 237 (desc->wMaxPacketSize)) {
238 DMSG("%s, bad ep or descriptor\n", __FUNCTION__); 238 DMSG("%s, bad ep or descriptor\n", __func__);
239 return -EINVAL; 239 return -EINVAL;
240 } 240 }
241 241
@@ -243,7 +243,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
243 if (ep->bmAttributes != desc->bmAttributes 243 if (ep->bmAttributes != desc->bmAttributes
244 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK 244 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
245 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { 245 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
246 DMSG("%s, %s type mismatch\n", __FUNCTION__, _ep->name); 246 DMSG("%s, %s type mismatch\n", __func__, _ep->name);
247 return -EINVAL; 247 return -EINVAL;
248 } 248 }
249 249
@@ -252,13 +252,13 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep,
252 && le16_to_cpu (desc->wMaxPacketSize) 252 && le16_to_cpu (desc->wMaxPacketSize)
253 != BULK_FIFO_SIZE) 253 != BULK_FIFO_SIZE)
254 || !desc->wMaxPacketSize) { 254 || !desc->wMaxPacketSize) {
255 DMSG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 255 DMSG("%s, bad %s maxpacket\n", __func__, _ep->name);
256 return -ERANGE; 256 return -ERANGE;
257 } 257 }
258 258
259 dev = ep->dev; 259 dev = ep->dev;
260 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { 260 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
261 DMSG("%s, bogus device state\n", __FUNCTION__); 261 DMSG("%s, bogus device state\n", __func__);
262 return -ESHUTDOWN; 262 return -ESHUTDOWN;
263 } 263 }
264 264
@@ -283,7 +283,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
283 283
284 ep = container_of (_ep, struct pxa2xx_ep, ep); 284 ep = container_of (_ep, struct pxa2xx_ep, ep);
285 if (!_ep || !ep->desc) { 285 if (!_ep || !ep->desc) {
286 DMSG("%s, %s not enabled\n", __FUNCTION__, 286 DMSG("%s, %s not enabled\n", __func__,
287 _ep ? ep->ep.name : NULL); 287 _ep ? ep->ep.name : NULL);
288 return -EINVAL; 288 return -EINVAL;
289 } 289 }
@@ -461,7 +461,7 @@ void ep0start(struct pxa2xx_udc *dev, u32 flags, const char *tag)
461 USIR0 = USIR0_IR0; 461 USIR0 = USIR0_IR0;
462 dev->req_pending = 0; 462 dev->req_pending = 0;
463 DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n", 463 DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n",
464 __FUNCTION__, tag, UDCCS0, flags); 464 __func__, tag, UDCCS0, flags);
465} 465}
466 466
467static int 467static int
@@ -651,20 +651,20 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
651 req = container_of(_req, struct pxa2xx_request, req); 651 req = container_of(_req, struct pxa2xx_request, req);
652 if (unlikely (!_req || !_req->complete || !_req->buf 652 if (unlikely (!_req || !_req->complete || !_req->buf
653 || !list_empty(&req->queue))) { 653 || !list_empty(&req->queue))) {
654 DMSG("%s, bad params\n", __FUNCTION__); 654 DMSG("%s, bad params\n", __func__);
655 return -EINVAL; 655 return -EINVAL;
656 } 656 }
657 657
658 ep = container_of(_ep, struct pxa2xx_ep, ep); 658 ep = container_of(_ep, struct pxa2xx_ep, ep);
659 if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) { 659 if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) {
660 DMSG("%s, bad ep\n", __FUNCTION__); 660 DMSG("%s, bad ep\n", __func__);
661 return -EINVAL; 661 return -EINVAL;
662 } 662 }
663 663
664 dev = ep->dev; 664 dev = ep->dev;
665 if (unlikely (!dev->driver 665 if (unlikely (!dev->driver
666 || dev->gadget.speed == USB_SPEED_UNKNOWN)) { 666 || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
667 DMSG("%s, bogus device state\n", __FUNCTION__); 667 DMSG("%s, bogus device state\n", __func__);
668 return -ESHUTDOWN; 668 return -ESHUTDOWN;
669 } 669 }
670 670
@@ -807,7 +807,7 @@ static int pxa2xx_ep_set_halt(struct usb_ep *_ep, int value)
807 if (unlikely (!_ep 807 if (unlikely (!_ep
808 || (!ep->desc && ep->ep.name != ep0name)) 808 || (!ep->desc && ep->ep.name != ep0name))
809 || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 809 || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
810 DMSG("%s, bad ep\n", __FUNCTION__); 810 DMSG("%s, bad ep\n", __func__);
811 return -EINVAL; 811 return -EINVAL;
812 } 812 }
813 if (value == 0) { 813 if (value == 0) {
@@ -859,7 +859,7 @@ static int pxa2xx_ep_fifo_status(struct usb_ep *_ep)
859 859
860 ep = container_of(_ep, struct pxa2xx_ep, ep); 860 ep = container_of(_ep, struct pxa2xx_ep, ep);
861 if (!_ep) { 861 if (!_ep) {
862 DMSG("%s, bad ep\n", __FUNCTION__); 862 DMSG("%s, bad ep\n", __func__);
863 return -ENODEV; 863 return -ENODEV;
864 } 864 }
865 /* pxa can't report unclaimed bytes from IN fifos */ 865 /* pxa can't report unclaimed bytes from IN fifos */
@@ -878,7 +878,7 @@ static void pxa2xx_ep_fifo_flush(struct usb_ep *_ep)
878 878
879 ep = container_of(_ep, struct pxa2xx_ep, ep); 879 ep = container_of(_ep, struct pxa2xx_ep, ep);
880 if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) { 880 if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) {
881 DMSG("%s, bad ep\n", __FUNCTION__); 881 DMSG("%s, bad ep\n", __func__);
882 return; 882 return;
883 } 883 }
884 884
@@ -1813,7 +1813,7 @@ pxa2xx_udc_irq(int irq, void *_dev)
1813 1813
1814static void nop_release (struct device *dev) 1814static void nop_release (struct device *dev)
1815{ 1815{
1816 DMSG("%s %s\n", __FUNCTION__, dev->bus_id); 1816 DMSG("%s %s\n", __func__, dev->bus_id);
1817} 1817}
1818 1818
1819/* this uses load-time allocation and initialization (instead of 1819/* this uses load-time allocation and initialization (instead of
@@ -2380,4 +2380,4 @@ module_exit(udc_exit);
2380MODULE_DESCRIPTION(DRIVER_DESC); 2380MODULE_DESCRIPTION(DRIVER_DESC);
2381MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell"); 2381MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
2382MODULE_LICENSE("GPL"); 2382MODULE_LICENSE("GPL");
2383 2383MODULE_ALIAS("platform:pxa2xx-udc");
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 3d036647431f..d0677f5d3cd5 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -183,14 +183,10 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
183 DBG("query OID %08x value, len %d:\n", OID, buf_len); 183 DBG("query OID %08x value, len %d:\n", OID, buf_len);
184 for (i = 0; i < buf_len; i += 16) { 184 for (i = 0; i < buf_len; i += 16) {
185 DBG("%03d: %08x %08x %08x %08x\n", i, 185 DBG("%03d: %08x %08x %08x %08x\n", i,
186 le32_to_cpu(get_unaligned((__le32 *) 186 get_unaligned_le32(&buf[i]),
187 &buf[i])), 187 get_unaligned_le32(&buf[i + 4]),
188 le32_to_cpu(get_unaligned((__le32 *) 188 get_unaligned_le32(&buf[i + 8]),
189 &buf[i + 4])), 189 get_unaligned_le32(&buf[i + 12]));
190 le32_to_cpu(get_unaligned((__le32 *)
191 &buf[i + 8])),
192 le32_to_cpu(get_unaligned((__le32 *)
193 &buf[i + 12])));
194 } 190 }
195 } 191 }
196 192
@@ -204,7 +200,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
204 200
205 /* mandatory */ 201 /* mandatory */
206 case OID_GEN_SUPPORTED_LIST: 202 case OID_GEN_SUPPORTED_LIST:
207 DBG("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__); 203 DBG("%s: OID_GEN_SUPPORTED_LIST\n", __func__);
208 length = sizeof (oid_supported_list); 204 length = sizeof (oid_supported_list);
209 count = length / sizeof (u32); 205 count = length / sizeof (u32);
210 for (i = 0; i < count; i++) 206 for (i = 0; i < count; i++)
@@ -214,7 +210,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
214 210
215 /* mandatory */ 211 /* mandatory */
216 case OID_GEN_HARDWARE_STATUS: 212 case OID_GEN_HARDWARE_STATUS:
217 DBG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__); 213 DBG("%s: OID_GEN_HARDWARE_STATUS\n", __func__);
218 /* Bogus question! 214 /* Bogus question!
219 * Hardware must be ready to receive high level protocols. 215 * Hardware must be ready to receive high level protocols.
220 * BTW: 216 * BTW:
@@ -227,14 +223,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
227 223
228 /* mandatory */ 224 /* mandatory */
229 case OID_GEN_MEDIA_SUPPORTED: 225 case OID_GEN_MEDIA_SUPPORTED:
230 DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__); 226 DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__);
231 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 227 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
232 retval = 0; 228 retval = 0;
233 break; 229 break;
234 230
235 /* mandatory */ 231 /* mandatory */
236 case OID_GEN_MEDIA_IN_USE: 232 case OID_GEN_MEDIA_IN_USE:
237 DBG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__); 233 DBG("%s: OID_GEN_MEDIA_IN_USE\n", __func__);
238 /* one medium, one transport... (maybe you do it better) */ 234 /* one medium, one transport... (maybe you do it better) */
239 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 235 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
240 retval = 0; 236 retval = 0;
@@ -242,7 +238,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
242 238
243 /* mandatory */ 239 /* mandatory */
244 case OID_GEN_MAXIMUM_FRAME_SIZE: 240 case OID_GEN_MAXIMUM_FRAME_SIZE:
245 DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__); 241 DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
246 if (rndis_per_dev_params [configNr].dev) { 242 if (rndis_per_dev_params [configNr].dev) {
247 *outbuf = cpu_to_le32 ( 243 *outbuf = cpu_to_le32 (
248 rndis_per_dev_params [configNr].dev->mtu); 244 rndis_per_dev_params [configNr].dev->mtu);
@@ -253,7 +249,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
253 /* mandatory */ 249 /* mandatory */
254 case OID_GEN_LINK_SPEED: 250 case OID_GEN_LINK_SPEED:
255 if (rndis_debug > 1) 251 if (rndis_debug > 1)
256 DBG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 252 DBG("%s: OID_GEN_LINK_SPEED\n", __func__);
257 if (rndis_per_dev_params [configNr].media_state 253 if (rndis_per_dev_params [configNr].media_state
258 == NDIS_MEDIA_STATE_DISCONNECTED) 254 == NDIS_MEDIA_STATE_DISCONNECTED)
259 *outbuf = __constant_cpu_to_le32 (0); 255 *outbuf = __constant_cpu_to_le32 (0);
@@ -265,7 +261,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
265 261
266 /* mandatory */ 262 /* mandatory */
267 case OID_GEN_TRANSMIT_BLOCK_SIZE: 263 case OID_GEN_TRANSMIT_BLOCK_SIZE:
268 DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__); 264 DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
269 if (rndis_per_dev_params [configNr].dev) { 265 if (rndis_per_dev_params [configNr].dev) {
270 *outbuf = cpu_to_le32 ( 266 *outbuf = cpu_to_le32 (
271 rndis_per_dev_params [configNr].dev->mtu); 267 rndis_per_dev_params [configNr].dev->mtu);
@@ -275,7 +271,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
275 271
276 /* mandatory */ 272 /* mandatory */
277 case OID_GEN_RECEIVE_BLOCK_SIZE: 273 case OID_GEN_RECEIVE_BLOCK_SIZE:
278 DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__); 274 DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
279 if (rndis_per_dev_params [configNr].dev) { 275 if (rndis_per_dev_params [configNr].dev) {
280 *outbuf = cpu_to_le32 ( 276 *outbuf = cpu_to_le32 (
281 rndis_per_dev_params [configNr].dev->mtu); 277 rndis_per_dev_params [configNr].dev->mtu);
@@ -285,7 +281,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
285 281
286 /* mandatory */ 282 /* mandatory */
287 case OID_GEN_VENDOR_ID: 283 case OID_GEN_VENDOR_ID:
288 DBG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__); 284 DBG("%s: OID_GEN_VENDOR_ID\n", __func__);
289 *outbuf = cpu_to_le32 ( 285 *outbuf = cpu_to_le32 (
290 rndis_per_dev_params [configNr].vendorID); 286 rndis_per_dev_params [configNr].vendorID);
291 retval = 0; 287 retval = 0;
@@ -293,7 +289,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
293 289
294 /* mandatory */ 290 /* mandatory */
295 case OID_GEN_VENDOR_DESCRIPTION: 291 case OID_GEN_VENDOR_DESCRIPTION:
296 DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__); 292 DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__);
297 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 293 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
298 memcpy (outbuf, 294 memcpy (outbuf,
299 rndis_per_dev_params [configNr].vendorDescr, length); 295 rndis_per_dev_params [configNr].vendorDescr, length);
@@ -301,7 +297,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
301 break; 297 break;
302 298
303 case OID_GEN_VENDOR_DRIVER_VERSION: 299 case OID_GEN_VENDOR_DRIVER_VERSION:
304 DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__); 300 DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__);
305 /* Created as LE */ 301 /* Created as LE */
306 *outbuf = rndis_driver_version; 302 *outbuf = rndis_driver_version;
307 retval = 0; 303 retval = 0;
@@ -309,14 +305,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
309 305
310 /* mandatory */ 306 /* mandatory */
311 case OID_GEN_CURRENT_PACKET_FILTER: 307 case OID_GEN_CURRENT_PACKET_FILTER:
312 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__); 308 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
313 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); 309 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
314 retval = 0; 310 retval = 0;
315 break; 311 break;
316 312
317 /* mandatory */ 313 /* mandatory */
318 case OID_GEN_MAXIMUM_TOTAL_SIZE: 314 case OID_GEN_MAXIMUM_TOTAL_SIZE:
319 DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__); 315 DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
320 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); 316 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
321 retval = 0; 317 retval = 0;
322 break; 318 break;
@@ -324,14 +320,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
324 /* mandatory */ 320 /* mandatory */
325 case OID_GEN_MEDIA_CONNECT_STATUS: 321 case OID_GEN_MEDIA_CONNECT_STATUS:
326 if (rndis_debug > 1) 322 if (rndis_debug > 1)
327 DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 323 DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
328 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 324 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
329 .media_state); 325 .media_state);
330 retval = 0; 326 retval = 0;
331 break; 327 break;
332 328
333 case OID_GEN_PHYSICAL_MEDIUM: 329 case OID_GEN_PHYSICAL_MEDIUM:
334 DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__); 330 DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__);
335 *outbuf = __constant_cpu_to_le32 (0); 331 *outbuf = __constant_cpu_to_le32 (0);
336 retval = 0; 332 retval = 0;
337 break; 333 break;
@@ -341,7 +337,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
341 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! 337 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
342 */ 338 */
343 case OID_GEN_MAC_OPTIONS: /* from WinME */ 339 case OID_GEN_MAC_OPTIONS: /* from WinME */
344 DBG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__); 340 DBG("%s: OID_GEN_MAC_OPTIONS\n", __func__);
345 *outbuf = __constant_cpu_to_le32( 341 *outbuf = __constant_cpu_to_le32(
346 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 342 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
347 | NDIS_MAC_OPTION_FULL_DUPLEX); 343 | NDIS_MAC_OPTION_FULL_DUPLEX);
@@ -353,7 +349,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
353 /* mandatory */ 349 /* mandatory */
354 case OID_GEN_XMIT_OK: 350 case OID_GEN_XMIT_OK:
355 if (rndis_debug > 1) 351 if (rndis_debug > 1)
356 DBG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 352 DBG("%s: OID_GEN_XMIT_OK\n", __func__);
357 if (rndis_per_dev_params [configNr].stats) { 353 if (rndis_per_dev_params [configNr].stats) {
358 *outbuf = cpu_to_le32 ( 354 *outbuf = cpu_to_le32 (
359 rndis_per_dev_params [configNr].stats->tx_packets - 355 rndis_per_dev_params [configNr].stats->tx_packets -
@@ -366,7 +362,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
366 /* mandatory */ 362 /* mandatory */
367 case OID_GEN_RCV_OK: 363 case OID_GEN_RCV_OK:
368 if (rndis_debug > 1) 364 if (rndis_debug > 1)
369 DBG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 365 DBG("%s: OID_GEN_RCV_OK\n", __func__);
370 if (rndis_per_dev_params [configNr].stats) { 366 if (rndis_per_dev_params [configNr].stats) {
371 *outbuf = cpu_to_le32 ( 367 *outbuf = cpu_to_le32 (
372 rndis_per_dev_params [configNr].stats->rx_packets - 368 rndis_per_dev_params [configNr].stats->rx_packets -
@@ -379,7 +375,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
379 /* mandatory */ 375 /* mandatory */
380 case OID_GEN_XMIT_ERROR: 376 case OID_GEN_XMIT_ERROR:
381 if (rndis_debug > 1) 377 if (rndis_debug > 1)
382 DBG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 378 DBG("%s: OID_GEN_XMIT_ERROR\n", __func__);
383 if (rndis_per_dev_params [configNr].stats) { 379 if (rndis_per_dev_params [configNr].stats) {
384 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 380 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
385 .stats->tx_errors); 381 .stats->tx_errors);
@@ -390,7 +386,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
390 /* mandatory */ 386 /* mandatory */
391 case OID_GEN_RCV_ERROR: 387 case OID_GEN_RCV_ERROR:
392 if (rndis_debug > 1) 388 if (rndis_debug > 1)
393 DBG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 389 DBG("%s: OID_GEN_RCV_ERROR\n", __func__);
394 if (rndis_per_dev_params [configNr].stats) { 390 if (rndis_per_dev_params [configNr].stats) {
395 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 391 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
396 .stats->rx_errors); 392 .stats->rx_errors);
@@ -400,7 +396,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
400 396
401 /* mandatory */ 397 /* mandatory */
402 case OID_GEN_RCV_NO_BUFFER: 398 case OID_GEN_RCV_NO_BUFFER:
403 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__); 399 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__);
404 if (rndis_per_dev_params [configNr].stats) { 400 if (rndis_per_dev_params [configNr].stats) {
405 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 401 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
406 .stats->rx_dropped); 402 .stats->rx_dropped);
@@ -410,7 +406,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
410 406
411#ifdef RNDIS_OPTIONAL_STATS 407#ifdef RNDIS_OPTIONAL_STATS
412 case OID_GEN_DIRECTED_BYTES_XMIT: 408 case OID_GEN_DIRECTED_BYTES_XMIT:
413 DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __FUNCTION__); 409 DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __func__);
414 /* 410 /*
415 * Aunt Tilly's size of shoes 411 * Aunt Tilly's size of shoes
416 * minus antarctica count of penguins 412 * minus antarctica count of penguins
@@ -430,7 +426,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
430 break; 426 break;
431 427
432 case OID_GEN_DIRECTED_FRAMES_XMIT: 428 case OID_GEN_DIRECTED_FRAMES_XMIT:
433 DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__); 429 DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __func__);
434 /* dito */ 430 /* dito */
435 if (rndis_per_dev_params [configNr].stats) { 431 if (rndis_per_dev_params [configNr].stats) {
436 *outbuf = cpu_to_le32 ( 432 *outbuf = cpu_to_le32 (
@@ -446,7 +442,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
446 break; 442 break;
447 443
448 case OID_GEN_MULTICAST_BYTES_XMIT: 444 case OID_GEN_MULTICAST_BYTES_XMIT:
449 DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__); 445 DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __func__);
450 if (rndis_per_dev_params [configNr].stats) { 446 if (rndis_per_dev_params [configNr].stats) {
451 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 447 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
452 .stats->multicast*1234); 448 .stats->multicast*1234);
@@ -455,7 +451,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
455 break; 451 break;
456 452
457 case OID_GEN_MULTICAST_FRAMES_XMIT: 453 case OID_GEN_MULTICAST_FRAMES_XMIT:
458 DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__); 454 DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __func__);
459 if (rndis_per_dev_params [configNr].stats) { 455 if (rndis_per_dev_params [configNr].stats) {
460 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 456 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
461 .stats->multicast); 457 .stats->multicast);
@@ -464,7 +460,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
464 break; 460 break;
465 461
466 case OID_GEN_BROADCAST_BYTES_XMIT: 462 case OID_GEN_BROADCAST_BYTES_XMIT:
467 DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__); 463 DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __func__);
468 if (rndis_per_dev_params [configNr].stats) { 464 if (rndis_per_dev_params [configNr].stats) {
469 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 465 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
470 .stats->tx_packets/42*255); 466 .stats->tx_packets/42*255);
@@ -473,7 +469,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
473 break; 469 break;
474 470
475 case OID_GEN_BROADCAST_FRAMES_XMIT: 471 case OID_GEN_BROADCAST_FRAMES_XMIT:
476 DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__); 472 DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __func__);
477 if (rndis_per_dev_params [configNr].stats) { 473 if (rndis_per_dev_params [configNr].stats) {
478 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 474 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
479 .stats->tx_packets/42); 475 .stats->tx_packets/42);
@@ -482,19 +478,19 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
482 break; 478 break;
483 479
484 case OID_GEN_DIRECTED_BYTES_RCV: 480 case OID_GEN_DIRECTED_BYTES_RCV:
485 DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__); 481 DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __func__);
486 *outbuf = __constant_cpu_to_le32 (0); 482 *outbuf = __constant_cpu_to_le32 (0);
487 retval = 0; 483 retval = 0;
488 break; 484 break;
489 485
490 case OID_GEN_DIRECTED_FRAMES_RCV: 486 case OID_GEN_DIRECTED_FRAMES_RCV:
491 DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__); 487 DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __func__);
492 *outbuf = __constant_cpu_to_le32 (0); 488 *outbuf = __constant_cpu_to_le32 (0);
493 retval = 0; 489 retval = 0;
494 break; 490 break;
495 491
496 case OID_GEN_MULTICAST_BYTES_RCV: 492 case OID_GEN_MULTICAST_BYTES_RCV:
497 DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__); 493 DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __func__);
498 if (rndis_per_dev_params [configNr].stats) { 494 if (rndis_per_dev_params [configNr].stats) {
499 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 495 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
500 .stats->multicast * 1111); 496 .stats->multicast * 1111);
@@ -503,7 +499,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
503 break; 499 break;
504 500
505 case OID_GEN_MULTICAST_FRAMES_RCV: 501 case OID_GEN_MULTICAST_FRAMES_RCV:
506 DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__); 502 DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __func__);
507 if (rndis_per_dev_params [configNr].stats) { 503 if (rndis_per_dev_params [configNr].stats) {
508 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 504 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
509 .stats->multicast); 505 .stats->multicast);
@@ -512,7 +508,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
512 break; 508 break;
513 509
514 case OID_GEN_BROADCAST_BYTES_RCV: 510 case OID_GEN_BROADCAST_BYTES_RCV:
515 DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__); 511 DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __func__);
516 if (rndis_per_dev_params [configNr].stats) { 512 if (rndis_per_dev_params [configNr].stats) {
517 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 513 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
518 .stats->rx_packets/42*255); 514 .stats->rx_packets/42*255);
@@ -521,7 +517,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
521 break; 517 break;
522 518
523 case OID_GEN_BROADCAST_FRAMES_RCV: 519 case OID_GEN_BROADCAST_FRAMES_RCV:
524 DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__); 520 DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __func__);
525 if (rndis_per_dev_params [configNr].stats) { 521 if (rndis_per_dev_params [configNr].stats) {
526 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 522 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
527 .stats->rx_packets/42); 523 .stats->rx_packets/42);
@@ -530,7 +526,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
530 break; 526 break;
531 527
532 case OID_GEN_RCV_CRC_ERROR: 528 case OID_GEN_RCV_CRC_ERROR:
533 DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__); 529 DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __func__);
534 if (rndis_per_dev_params [configNr].stats) { 530 if (rndis_per_dev_params [configNr].stats) {
535 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 531 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
536 .stats->rx_crc_errors); 532 .stats->rx_crc_errors);
@@ -539,7 +535,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
539 break; 535 break;
540 536
541 case OID_GEN_TRANSMIT_QUEUE_LENGTH: 537 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
542 DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__); 538 DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __func__);
543 *outbuf = __constant_cpu_to_le32 (0); 539 *outbuf = __constant_cpu_to_le32 (0);
544 retval = 0; 540 retval = 0;
545 break; 541 break;
@@ -549,7 +545,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
549 545
550 /* mandatory */ 546 /* mandatory */
551 case OID_802_3_PERMANENT_ADDRESS: 547 case OID_802_3_PERMANENT_ADDRESS:
552 DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__); 548 DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__);
553 if (rndis_per_dev_params [configNr].dev) { 549 if (rndis_per_dev_params [configNr].dev) {
554 length = ETH_ALEN; 550 length = ETH_ALEN;
555 memcpy (outbuf, 551 memcpy (outbuf,
@@ -561,7 +557,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
561 557
562 /* mandatory */ 558 /* mandatory */
563 case OID_802_3_CURRENT_ADDRESS: 559 case OID_802_3_CURRENT_ADDRESS:
564 DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__); 560 DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __func__);
565 if (rndis_per_dev_params [configNr].dev) { 561 if (rndis_per_dev_params [configNr].dev) {
566 length = ETH_ALEN; 562 length = ETH_ALEN;
567 memcpy (outbuf, 563 memcpy (outbuf,
@@ -573,7 +569,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
573 569
574 /* mandatory */ 570 /* mandatory */
575 case OID_802_3_MULTICAST_LIST: 571 case OID_802_3_MULTICAST_LIST:
576 DBG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 572 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__);
577 /* Multicast base address only */ 573 /* Multicast base address only */
578 *outbuf = __constant_cpu_to_le32 (0xE0000000); 574 *outbuf = __constant_cpu_to_le32 (0xE0000000);
579 retval = 0; 575 retval = 0;
@@ -581,21 +577,21 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
581 577
582 /* mandatory */ 578 /* mandatory */
583 case OID_802_3_MAXIMUM_LIST_SIZE: 579 case OID_802_3_MAXIMUM_LIST_SIZE:
584 DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__); 580 DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
585 /* Multicast base address only */ 581 /* Multicast base address only */
586 *outbuf = __constant_cpu_to_le32 (1); 582 *outbuf = __constant_cpu_to_le32 (1);
587 retval = 0; 583 retval = 0;
588 break; 584 break;
589 585
590 case OID_802_3_MAC_OPTIONS: 586 case OID_802_3_MAC_OPTIONS:
591 DBG("%s: OID_802_3_MAC_OPTIONS\n", __FUNCTION__); 587 DBG("%s: OID_802_3_MAC_OPTIONS\n", __func__);
592 break; 588 break;
593 589
594 /* ieee802.3 statistics OIDs (table 4-4) */ 590 /* ieee802.3 statistics OIDs (table 4-4) */
595 591
596 /* mandatory */ 592 /* mandatory */
597 case OID_802_3_RCV_ERROR_ALIGNMENT: 593 case OID_802_3_RCV_ERROR_ALIGNMENT:
598 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__); 594 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
599 if (rndis_per_dev_params [configNr].stats) { 595 if (rndis_per_dev_params [configNr].stats) {
600 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 596 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
601 .stats->rx_frame_errors); 597 .stats->rx_frame_errors);
@@ -605,51 +601,51 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
605 601
606 /* mandatory */ 602 /* mandatory */
607 case OID_802_3_XMIT_ONE_COLLISION: 603 case OID_802_3_XMIT_ONE_COLLISION:
608 DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__); 604 DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__);
609 *outbuf = __constant_cpu_to_le32 (0); 605 *outbuf = __constant_cpu_to_le32 (0);
610 retval = 0; 606 retval = 0;
611 break; 607 break;
612 608
613 /* mandatory */ 609 /* mandatory */
614 case OID_802_3_XMIT_MORE_COLLISIONS: 610 case OID_802_3_XMIT_MORE_COLLISIONS:
615 DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__); 611 DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
616 *outbuf = __constant_cpu_to_le32 (0); 612 *outbuf = __constant_cpu_to_le32 (0);
617 retval = 0; 613 retval = 0;
618 break; 614 break;
619 615
620#ifdef RNDIS_OPTIONAL_STATS 616#ifdef RNDIS_OPTIONAL_STATS
621 case OID_802_3_XMIT_DEFERRED: 617 case OID_802_3_XMIT_DEFERRED:
622 DBG("%s: OID_802_3_XMIT_DEFERRED\n", __FUNCTION__); 618 DBG("%s: OID_802_3_XMIT_DEFERRED\n", __func__);
623 /* TODO */ 619 /* TODO */
624 break; 620 break;
625 621
626 case OID_802_3_XMIT_MAX_COLLISIONS: 622 case OID_802_3_XMIT_MAX_COLLISIONS:
627 DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __FUNCTION__); 623 DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __func__);
628 /* TODO */ 624 /* TODO */
629 break; 625 break;
630 626
631 case OID_802_3_RCV_OVERRUN: 627 case OID_802_3_RCV_OVERRUN:
632 DBG("%s: OID_802_3_RCV_OVERRUN\n", __FUNCTION__); 628 DBG("%s: OID_802_3_RCV_OVERRUN\n", __func__);
633 /* TODO */ 629 /* TODO */
634 break; 630 break;
635 631
636 case OID_802_3_XMIT_UNDERRUN: 632 case OID_802_3_XMIT_UNDERRUN:
637 DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __FUNCTION__); 633 DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __func__);
638 /* TODO */ 634 /* TODO */
639 break; 635 break;
640 636
641 case OID_802_3_XMIT_HEARTBEAT_FAILURE: 637 case OID_802_3_XMIT_HEARTBEAT_FAILURE:
642 DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __FUNCTION__); 638 DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __func__);
643 /* TODO */ 639 /* TODO */
644 break; 640 break;
645 641
646 case OID_802_3_XMIT_TIMES_CRS_LOST: 642 case OID_802_3_XMIT_TIMES_CRS_LOST:
647 DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __FUNCTION__); 643 DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __func__);
648 /* TODO */ 644 /* TODO */
649 break; 645 break;
650 646
651 case OID_802_3_XMIT_LATE_COLLISIONS: 647 case OID_802_3_XMIT_LATE_COLLISIONS:
652 DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __FUNCTION__); 648 DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __func__);
653 /* TODO */ 649 /* TODO */
654 break; 650 break;
655#endif /* RNDIS_OPTIONAL_STATS */ 651#endif /* RNDIS_OPTIONAL_STATS */
@@ -657,7 +653,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
657#ifdef RNDIS_PM 653#ifdef RNDIS_PM
658 /* power management OIDs (table 4-5) */ 654 /* power management OIDs (table 4-5) */
659 case OID_PNP_CAPABILITIES: 655 case OID_PNP_CAPABILITIES:
660 DBG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__); 656 DBG("%s: OID_PNP_CAPABILITIES\n", __func__);
661 657
662 /* for now, no wakeup capabilities */ 658 /* for now, no wakeup capabilities */
663 length = sizeof (struct NDIS_PNP_CAPABILITIES); 659 length = sizeof (struct NDIS_PNP_CAPABILITIES);
@@ -665,8 +661,8 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
665 retval = 0; 661 retval = 0;
666 break; 662 break;
667 case OID_PNP_QUERY_POWER: 663 case OID_PNP_QUERY_POWER:
668 DBG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__, 664 DBG("%s: OID_PNP_QUERY_POWER D%d\n", __func__,
669 le32_to_cpu(get_unaligned((__le32 *)buf)) - 1); 665 get_unaligned_le32(buf) - 1);
670 /* only suspend is a real power state, and 666 /* only suspend is a real power state, and
671 * it can't be entered by OID_PNP_SET_POWER... 667 * it can't be entered by OID_PNP_SET_POWER...
672 */ 668 */
@@ -677,7 +673,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
677 673
678 default: 674 default:
679 pr_warning("%s: query unknown OID 0x%08X\n", 675 pr_warning("%s: query unknown OID 0x%08X\n",
680 __FUNCTION__, OID); 676 __func__, OID);
681 } 677 }
682 if (retval < 0) 678 if (retval < 0)
683 length = 0; 679 length = 0;
@@ -705,14 +701,10 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
705 DBG("set OID %08x value, len %d:\n", OID, buf_len); 701 DBG("set OID %08x value, len %d:\n", OID, buf_len);
706 for (i = 0; i < buf_len; i += 16) { 702 for (i = 0; i < buf_len; i += 16) {
707 DBG("%03d: %08x %08x %08x %08x\n", i, 703 DBG("%03d: %08x %08x %08x %08x\n", i,
708 le32_to_cpu(get_unaligned((__le32 *) 704 get_unaligned_le32(&buf[i]),
709 &buf[i])), 705 get_unaligned_le32(&buf[i + 4]),
710 le32_to_cpu(get_unaligned((__le32 *) 706 get_unaligned_le32(&buf[i + 8]),
711 &buf[i + 4])), 707 get_unaligned_le32(&buf[i + 12]));
712 le32_to_cpu(get_unaligned((__le32 *)
713 &buf[i + 8])),
714 le32_to_cpu(get_unaligned((__le32 *)
715 &buf[i + 12])));
716 } 708 }
717 } 709 }
718 710
@@ -726,10 +718,9 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
726 * PROMISCUOUS, DIRECTED, 718 * PROMISCUOUS, DIRECTED,
727 * MULTICAST, ALL_MULTICAST, BROADCAST 719 * MULTICAST, ALL_MULTICAST, BROADCAST
728 */ 720 */
729 *params->filter = (u16) le32_to_cpu(get_unaligned( 721 *params->filter = (u16)get_unaligned_le32(buf);
730 (__le32 *)buf));
731 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", 722 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
732 __FUNCTION__, *params->filter); 723 __func__, *params->filter);
733 724
734 /* this call has a significant side effect: it's 725 /* this call has a significant side effect: it's
735 * what makes the packet flow start and stop, like 726 * what makes the packet flow start and stop, like
@@ -753,7 +744,7 @@ update_linkstate:
753 744
754 case OID_802_3_MULTICAST_LIST: 745 case OID_802_3_MULTICAST_LIST:
755 /* I think we can ignore this */ 746 /* I think we can ignore this */
756 DBG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 747 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__);
757 retval = 0; 748 retval = 0;
758 break; 749 break;
759#if 0 750#if 0
@@ -762,7 +753,7 @@ update_linkstate:
762 struct rndis_config_parameter *param; 753 struct rndis_config_parameter *param;
763 param = (struct rndis_config_parameter *) buf; 754 param = (struct rndis_config_parameter *) buf;
764 DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n", 755 DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n",
765 __FUNCTION__, 756 __func__,
766 min(cpu_to_le32(param->ParameterNameLength),80), 757 min(cpu_to_le32(param->ParameterNameLength),80),
767 buf + param->ParameterNameOffset); 758 buf + param->ParameterNameOffset);
768 retval = 0; 759 retval = 0;
@@ -777,8 +768,8 @@ update_linkstate:
777 * resuming, Windows forces a reset, and then SET_POWER D0. 768 * resuming, Windows forces a reset, and then SET_POWER D0.
778 * FIXME ... then things go batty; Windows wedges itself. 769 * FIXME ... then things go batty; Windows wedges itself.
779 */ 770 */
780 i = le32_to_cpu(get_unaligned((__le32 *)buf)); 771 i = get_unaligned_le32(buf);
781 DBG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1); 772 DBG("%s: OID_PNP_SET_POWER D%d\n", __func__, i - 1);
782 switch (i) { 773 switch (i) {
783 case NdisDeviceStateD0: 774 case NdisDeviceStateD0:
784 *params->filter = params->saved_filter; 775 *params->filter = params->saved_filter;
@@ -802,7 +793,7 @@ update_linkstate:
802 793
803 default: 794 default:
804 pr_warning("%s: set unknown OID 0x%08X, size %d\n", 795 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
805 __FUNCTION__, OID, buf_len); 796 __func__, OID, buf_len);
806 } 797 }
807 798
808 return retval; 799 return retval;
@@ -855,7 +846,7 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
855 rndis_query_cmplt_type *resp; 846 rndis_query_cmplt_type *resp;
856 rndis_resp_t *r; 847 rndis_resp_t *r;
857 848
858 // DBG("%s: OID = %08X\n", __FUNCTION__, cpu_to_le32(buf->OID)); 849 // DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID));
859 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 850 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
860 851
861 /* 852 /*
@@ -908,9 +899,9 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
908 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 899 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
909 900
910#ifdef VERBOSE 901#ifdef VERBOSE
911 DBG("%s: Length: %d\n", __FUNCTION__, BufLength); 902 DBG("%s: Length: %d\n", __func__, BufLength);
912 DBG("%s: Offset: %d\n", __FUNCTION__, BufOffset); 903 DBG("%s: Offset: %d\n", __func__, BufOffset);
913 DBG("%s: InfoBuffer: ", __FUNCTION__); 904 DBG("%s: InfoBuffer: ", __func__);
914 905
915 for (i = 0; i < BufLength; i++) { 906 for (i = 0; i < BufLength; i++) {
916 DBG("%02x ", *(((u8 *) buf) + i + 8 + BufOffset)); 907 DBG("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
@@ -1064,8 +1055,8 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1064 return -ENOMEM; 1055 return -ENOMEM;
1065 1056
1066 tmp = (__le32 *) buf; 1057 tmp = (__le32 *) buf;
1067 MsgType = le32_to_cpu(get_unaligned(tmp++)); 1058 MsgType = get_unaligned_le32(tmp++);
1068 MsgLength = le32_to_cpu(get_unaligned(tmp++)); 1059 MsgLength = get_unaligned_le32(tmp++);
1069 1060
1070 if (configNr >= RNDIS_MAX_CONFIGS) 1061 if (configNr >= RNDIS_MAX_CONFIGS)
1071 return -ENOTSUPP; 1062 return -ENOTSUPP;
@@ -1080,14 +1071,14 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1080 switch (MsgType) { 1071 switch (MsgType) {
1081 case REMOTE_NDIS_INITIALIZE_MSG: 1072 case REMOTE_NDIS_INITIALIZE_MSG:
1082 DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 1073 DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
1083 __FUNCTION__ ); 1074 __func__ );
1084 params->state = RNDIS_INITIALIZED; 1075 params->state = RNDIS_INITIALIZED;
1085 return rndis_init_response (configNr, 1076 return rndis_init_response (configNr,
1086 (rndis_init_msg_type *) buf); 1077 (rndis_init_msg_type *) buf);
1087 1078
1088 case REMOTE_NDIS_HALT_MSG: 1079 case REMOTE_NDIS_HALT_MSG:
1089 DBG("%s: REMOTE_NDIS_HALT_MSG\n", 1080 DBG("%s: REMOTE_NDIS_HALT_MSG\n",
1090 __FUNCTION__ ); 1081 __func__ );
1091 params->state = RNDIS_UNINITIALIZED; 1082 params->state = RNDIS_UNINITIALIZED;
1092 if (params->dev) { 1083 if (params->dev) {
1093 netif_carrier_off (params->dev); 1084 netif_carrier_off (params->dev);
@@ -1105,7 +1096,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1105 1096
1106 case REMOTE_NDIS_RESET_MSG: 1097 case REMOTE_NDIS_RESET_MSG:
1107 DBG("%s: REMOTE_NDIS_RESET_MSG\n", 1098 DBG("%s: REMOTE_NDIS_RESET_MSG\n",
1108 __FUNCTION__ ); 1099 __func__ );
1109 return rndis_reset_response (configNr, 1100 return rndis_reset_response (configNr,
1110 (rndis_reset_msg_type *) buf); 1101 (rndis_reset_msg_type *) buf);
1111 1102
@@ -1113,7 +1104,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1113 /* For USB: host does this every 5 seconds */ 1104 /* For USB: host does this every 5 seconds */
1114 if (rndis_debug > 1) 1105 if (rndis_debug > 1)
1115 DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1106 DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
1116 __FUNCTION__ ); 1107 __func__ );
1117 return rndis_keepalive_response (configNr, 1108 return rndis_keepalive_response (configNr,
1118 (rndis_keepalive_msg_type *) 1109 (rndis_keepalive_msg_type *)
1119 buf); 1110 buf);
@@ -1124,7 +1115,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1124 * suspending itself. 1115 * suspending itself.
1125 */ 1116 */
1126 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n", 1117 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
1127 __FUNCTION__ , MsgType, MsgLength); 1118 __func__ , MsgType, MsgLength);
1128 { 1119 {
1129 unsigned i; 1120 unsigned i;
1130 for (i = 0; i < MsgLength; i += 16) { 1121 for (i = 0; i < MsgLength; i += 16) {
@@ -1159,7 +1150,7 @@ int rndis_register (int (* rndis_control_ack) (struct net_device *))
1159 if (!rndis_per_dev_params [i].used) { 1150 if (!rndis_per_dev_params [i].used) {
1160 rndis_per_dev_params [i].used = 1; 1151 rndis_per_dev_params [i].used = 1;
1161 rndis_per_dev_params [i].ack = rndis_control_ack; 1152 rndis_per_dev_params [i].ack = rndis_control_ack;
1162 DBG("%s: configNr = %d\n", __FUNCTION__, i); 1153 DBG("%s: configNr = %d\n", __func__, i);
1163 return i; 1154 return i;
1164 } 1155 }
1165 } 1156 }
@@ -1170,7 +1161,7 @@ int rndis_register (int (* rndis_control_ack) (struct net_device *))
1170 1161
1171void rndis_deregister (int configNr) 1162void rndis_deregister (int configNr)
1172{ 1163{
1173 DBG("%s: \n", __FUNCTION__ ); 1164 DBG("%s: \n", __func__ );
1174 1165
1175 if (configNr >= RNDIS_MAX_CONFIGS) return; 1166 if (configNr >= RNDIS_MAX_CONFIGS) return;
1176 rndis_per_dev_params [configNr].used = 0; 1167 rndis_per_dev_params [configNr].used = 0;
@@ -1182,7 +1173,7 @@ int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1182 struct net_device_stats *stats, 1173 struct net_device_stats *stats,
1183 u16 *cdc_filter) 1174 u16 *cdc_filter)
1184{ 1175{
1185 DBG("%s:\n", __FUNCTION__ ); 1176 DBG("%s:\n", __func__ );
1186 if (!dev || !stats) return -1; 1177 if (!dev || !stats) return -1;
1187 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1178 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1188 1179
@@ -1195,7 +1186,7 @@ int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1195 1186
1196int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) 1187int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1197{ 1188{
1198 DBG("%s:\n", __FUNCTION__ ); 1189 DBG("%s:\n", __func__ );
1199 if (!vendorDescr) return -1; 1190 if (!vendorDescr) return -1;
1200 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1191 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1201 1192
@@ -1207,7 +1198,7 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1207 1198
1208int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 1199int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
1209{ 1200{
1210 DBG("%s: %u %u\n", __FUNCTION__, medium, speed); 1201 DBG("%s: %u %u\n", __func__, medium, speed);
1211 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1202 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1212 1203
1213 rndis_per_dev_params [configNr].medium = medium; 1204 rndis_per_dev_params [configNr].medium = medium;
@@ -1296,10 +1287,9 @@ int rndis_rm_hdr(struct sk_buff *skb)
1296 tmp++; 1287 tmp++;
1297 1288
1298 /* DataOffset, DataLength */ 1289 /* DataOffset, DataLength */
1299 if (!skb_pull(skb, le32_to_cpu(get_unaligned(tmp++)) 1290 if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8))
1300 + 8 /* offset of DataOffset */))
1301 return -EOVERFLOW; 1291 return -EOVERFLOW;
1302 skb_trim(skb, le32_to_cpu(get_unaligned(tmp++))); 1292 skb_trim(skb, get_unaligned_le32(tmp++));
1303 1293
1304 return 0; 1294 return 0;
1305} 1295}
@@ -1403,7 +1393,7 @@ static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1403#endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1393#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1404 1394
1405 1395
1406int __devinit rndis_init (void) 1396int __init rndis_init (void)
1407{ 1397{
1408 u8 i; 1398 u8 i;
1409 1399
@@ -1415,7 +1405,7 @@ int __devinit rndis_init (void)
1415 if (!(rndis_connect_state [i] 1405 if (!(rndis_connect_state [i]
1416 = create_proc_entry (name, 0660, NULL))) 1406 = create_proc_entry (name, 0660, NULL)))
1417 { 1407 {
1418 DBG("%s :remove entries", __FUNCTION__); 1408 DBG("%s :remove entries", __func__);
1419 while (i) { 1409 while (i) {
1420 sprintf (name, NAME_TEMPLATE, --i); 1410 sprintf (name, NAME_TEMPLATE, --i);
1421 remove_proc_entry (name, NULL); 1411 remove_proc_entry (name, NULL);
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index aadc4204d6f9..6b1ef488043b 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -2047,3 +2047,5 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
2047MODULE_DESCRIPTION(DRIVER_DESC); 2047MODULE_DESCRIPTION(DRIVER_DESC);
2048MODULE_VERSION(DRIVER_VERSION); 2048MODULE_VERSION(DRIVER_VERSION);
2049MODULE_LICENSE("GPL"); 2049MODULE_LICENSE("GPL");
2050MODULE_ALIAS("platform:s3c2410-usbgadget");
2051MODULE_ALIAS("platform:s3c2440-usbgadget");
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index f5c3896b1d95..fa019fa73334 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -14,7 +14,6 @@
14 * This software is distributed under the terms of the GNU General 14 * This software is distributed under the terms of the GNU General
15 * Public License ("GPL") as published by the Free Software Foundation, 15 * Public License ("GPL") as published by the Free Software Foundation,
16 * either version 2 of that License or (at your option) any later version. 16 * either version 2 of that License or (at your option) any later version.
17 *
18 */ 17 */
19 18
20#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -33,7 +32,7 @@
33/* Defines */ 32/* Defines */
34 33
35#define GS_VERSION_STR "v2.2" 34#define GS_VERSION_STR "v2.2"
36#define GS_VERSION_NUM 0x0202 35#define GS_VERSION_NUM 0x2200
37 36
38#define GS_LONG_NAME "Gadget Serial" 37#define GS_LONG_NAME "Gadget Serial"
39#define GS_SHORT_NAME "g_serial" 38#define GS_SHORT_NAME "g_serial"
@@ -41,7 +40,11 @@
41#define GS_MAJOR 127 40#define GS_MAJOR 127
42#define GS_MINOR_START 0 41#define GS_MINOR_START 0
43 42
44#define GS_NUM_PORTS 16 43/* REVISIT only one port is supported for now;
44 * see gs_{send,recv}_packet() ... no multiplexing,
45 * and no support for multiple ACM devices.
46 */
47#define GS_NUM_PORTS 1
45 48
46#define GS_NUM_CONFIGS 1 49#define GS_NUM_CONFIGS 1
47#define GS_NO_CONFIG_ID 0 50#define GS_NO_CONFIG_ID 0
@@ -65,6 +68,9 @@
65 68
66#define GS_DEFAULT_USE_ACM 0 69#define GS_DEFAULT_USE_ACM 0
67 70
71/* 9600-8-N-1 ... matches init_termios.c_cflag and defaults
72 * expected by "usbser.sys" on MS-Windows.
73 */
68#define GS_DEFAULT_DTE_RATE 9600 74#define GS_DEFAULT_DTE_RATE 9600
69#define GS_DEFAULT_DATA_BITS 8 75#define GS_DEFAULT_DATA_BITS 8
70#define GS_DEFAULT_PARITY USB_CDC_NO_PARITY 76#define GS_DEFAULT_PARITY USB_CDC_NO_PARITY
@@ -107,10 +113,6 @@ static int debug = 1;
107#define GS_NOTIFY_MAXPACKET 8 113#define GS_NOTIFY_MAXPACKET 8
108 114
109 115
110/* Structures */
111
112struct gs_dev;
113
114/* circular buffer */ 116/* circular buffer */
115struct gs_buf { 117struct gs_buf {
116 unsigned int buf_size; 118 unsigned int buf_size;
@@ -119,12 +121,6 @@ struct gs_buf {
119 char *buf_put; 121 char *buf_put;
120}; 122};
121 123
122/* list of requests */
123struct gs_req_entry {
124 struct list_head re_entry;
125 struct usb_request *re_req;
126};
127
128/* the port structure holds info for each port, one for each minor number */ 124/* the port structure holds info for each port, one for each minor number */
129struct gs_port { 125struct gs_port {
130 struct gs_dev *port_dev; /* pointer to device struct */ 126 struct gs_dev *port_dev; /* pointer to device struct */
@@ -135,7 +131,10 @@ struct gs_port {
135 int port_in_use; /* open/close in progress */ 131 int port_in_use; /* open/close in progress */
136 wait_queue_head_t port_write_wait;/* waiting to write */ 132 wait_queue_head_t port_write_wait;/* waiting to write */
137 struct gs_buf *port_write_buf; 133 struct gs_buf *port_write_buf;
138 struct usb_cdc_line_coding port_line_coding; 134 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
135 u16 port_handshake_bits;
136#define RS232_RTS (1 << 1)
137#define RS232_DTE (1 << 0)
139}; 138};
140 139
141/* the device structure holds info for the USB device */ 140/* the device structure holds info for the USB device */
@@ -161,26 +160,7 @@ struct gs_dev {
161 160
162/* Functions */ 161/* Functions */
163 162
164/* module */ 163/* tty driver internals */
165static int __init gs_module_init(void);
166static void __exit gs_module_exit(void);
167
168/* tty driver */
169static int gs_open(struct tty_struct *tty, struct file *file);
170static void gs_close(struct tty_struct *tty, struct file *file);
171static int gs_write(struct tty_struct *tty,
172 const unsigned char *buf, int count);
173static void gs_put_char(struct tty_struct *tty, unsigned char ch);
174static void gs_flush_chars(struct tty_struct *tty);
175static int gs_write_room(struct tty_struct *tty);
176static int gs_chars_in_buffer(struct tty_struct *tty);
177static void gs_throttle(struct tty_struct * tty);
178static void gs_unthrottle(struct tty_struct * tty);
179static void gs_break(struct tty_struct *tty, int break_state);
180static int gs_ioctl(struct tty_struct *tty, struct file *file,
181 unsigned int cmd, unsigned long arg);
182static void gs_set_termios(struct tty_struct *tty, struct ktermios *old);
183
184static int gs_send(struct gs_dev *dev); 164static int gs_send(struct gs_dev *dev);
185static int gs_send_packet(struct gs_dev *dev, char *packet, 165static int gs_send_packet(struct gs_dev *dev, char *packet,
186 unsigned int size); 166 unsigned int size);
@@ -189,17 +169,7 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet,
189static void gs_read_complete(struct usb_ep *ep, struct usb_request *req); 169static void gs_read_complete(struct usb_ep *ep, struct usb_request *req);
190static void gs_write_complete(struct usb_ep *ep, struct usb_request *req); 170static void gs_write_complete(struct usb_ep *ep, struct usb_request *req);
191 171
192/* gadget driver */ 172/* gadget driver internals */
193static int gs_bind(struct usb_gadget *gadget);
194static void gs_unbind(struct usb_gadget *gadget);
195static int gs_setup(struct usb_gadget *gadget,
196 const struct usb_ctrlrequest *ctrl);
197static int gs_setup_standard(struct usb_gadget *gadget,
198 const struct usb_ctrlrequest *ctrl);
199static int gs_setup_class(struct usb_gadget *gadget,
200 const struct usb_ctrlrequest *ctrl);
201static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req);
202static void gs_disconnect(struct usb_gadget *gadget);
203static int gs_set_config(struct gs_dev *dev, unsigned config); 173static int gs_set_config(struct gs_dev *dev, unsigned config);
204static void gs_reset_config(struct gs_dev *dev); 174static void gs_reset_config(struct gs_dev *dev);
205static int gs_build_config_buf(u8 *buf, struct usb_gadget *g, 175static int gs_build_config_buf(u8 *buf, struct usb_gadget *g,
@@ -209,10 +179,6 @@ static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
209 gfp_t kmalloc_flags); 179 gfp_t kmalloc_flags);
210static void gs_free_req(struct usb_ep *ep, struct usb_request *req); 180static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
211 181
212static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len,
213 gfp_t kmalloc_flags);
214static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);
215
216static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags); 182static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags);
217static void gs_free_ports(struct gs_dev *dev); 183static void gs_free_ports(struct gs_dev *dev);
218 184
@@ -227,62 +193,15 @@ static unsigned int gs_buf_put(struct gs_buf *gb, const char *buf,
227static unsigned int gs_buf_get(struct gs_buf *gb, char *buf, 193static unsigned int gs_buf_get(struct gs_buf *gb, char *buf,
228 unsigned int count); 194 unsigned int count);
229 195
230/* external functions */
231extern int net2280_set_fifo_mode(struct usb_gadget *gadget, int mode);
232
233 196
234/* Globals */ 197/* Globals */
235 198
236static struct gs_dev *gs_device; 199static struct gs_dev *gs_device;
237 200
238static const char *EP_IN_NAME;
239static const char *EP_OUT_NAME;
240static const char *EP_NOTIFY_NAME;
241
242static struct mutex gs_open_close_lock[GS_NUM_PORTS]; 201static struct mutex gs_open_close_lock[GS_NUM_PORTS];
243 202
244static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE;
245static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE;
246
247static unsigned int write_buf_size = GS_DEFAULT_WRITE_BUF_SIZE;
248
249static unsigned int use_acm = GS_DEFAULT_USE_ACM;
250
251
252/* tty driver struct */
253static const struct tty_operations gs_tty_ops = {
254 .open = gs_open,
255 .close = gs_close,
256 .write = gs_write,
257 .put_char = gs_put_char,
258 .flush_chars = gs_flush_chars,
259 .write_room = gs_write_room,
260 .ioctl = gs_ioctl,
261 .set_termios = gs_set_termios,
262 .throttle = gs_throttle,
263 .unthrottle = gs_unthrottle,
264 .break_ctl = gs_break,
265 .chars_in_buffer = gs_chars_in_buffer,
266};
267static struct tty_driver *gs_tty_driver;
268
269/* gadget driver struct */
270static struct usb_gadget_driver gs_gadget_driver = {
271#ifdef CONFIG_USB_GADGET_DUALSPEED
272 .speed = USB_SPEED_HIGH,
273#else
274 .speed = USB_SPEED_FULL,
275#endif /* CONFIG_USB_GADGET_DUALSPEED */
276 .function = GS_LONG_NAME,
277 .bind = gs_bind,
278 .unbind = gs_unbind,
279 .setup = gs_setup,
280 .disconnect = gs_disconnect,
281 .driver = {
282 .name = GS_SHORT_NAME,
283 },
284};
285 203
204/*-------------------------------------------------------------------------*/
286 205
287/* USB descriptors */ 206/* USB descriptors */
288 207
@@ -299,7 +218,6 @@ static char manufacturer[50];
299static struct usb_string gs_strings[] = { 218static struct usb_string gs_strings[] = {
300 { GS_MANUFACTURER_STR_ID, manufacturer }, 219 { GS_MANUFACTURER_STR_ID, manufacturer },
301 { GS_PRODUCT_STR_ID, GS_LONG_NAME }, 220 { GS_PRODUCT_STR_ID, GS_LONG_NAME },
302 { GS_SERIAL_STR_ID, "0" },
303 { GS_BULK_CONFIG_STR_ID, "Gadget Serial Bulk" }, 221 { GS_BULK_CONFIG_STR_ID, "Gadget Serial Bulk" },
304 { GS_ACM_CONFIG_STR_ID, "Gadget Serial CDC ACM" }, 222 { GS_ACM_CONFIG_STR_ID, "Gadget Serial CDC ACM" },
305 { GS_CONTROL_STR_ID, "Gadget Serial Control" }, 223 { GS_CONTROL_STR_ID, "Gadget Serial Control" },
@@ -322,7 +240,6 @@ static struct usb_device_descriptor gs_device_desc = {
322 .idProduct = __constant_cpu_to_le16(GS_PRODUCT_ID), 240 .idProduct = __constant_cpu_to_le16(GS_PRODUCT_ID),
323 .iManufacturer = GS_MANUFACTURER_STR_ID, 241 .iManufacturer = GS_MANUFACTURER_STR_ID,
324 .iProduct = GS_PRODUCT_STR_ID, 242 .iProduct = GS_PRODUCT_STR_ID,
325 .iSerialNumber = GS_SERIAL_STR_ID,
326 .bNumConfigurations = GS_NUM_CONFIGS, 243 .bNumConfigurations = GS_NUM_CONFIGS,
327}; 244};
328 245
@@ -359,7 +276,7 @@ static const struct usb_interface_descriptor gs_bulk_interface_desc = {
359 .bDescriptorType = USB_DT_INTERFACE, 276 .bDescriptorType = USB_DT_INTERFACE,
360 .bInterfaceNumber = GS_BULK_INTERFACE_ID, 277 .bInterfaceNumber = GS_BULK_INTERFACE_ID,
361 .bNumEndpoints = 2, 278 .bNumEndpoints = 2,
362 .bInterfaceClass = USB_CLASS_CDC_DATA, 279 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
363 .bInterfaceSubClass = 0, 280 .bInterfaceSubClass = 0,
364 .bInterfaceProtocol = 0, 281 .bInterfaceProtocol = 0,
365 .iInterface = GS_DATA_STR_ID, 282 .iInterface = GS_DATA_STR_ID,
@@ -406,7 +323,7 @@ static struct usb_cdc_acm_descriptor gs_acm_descriptor = {
406 .bLength = sizeof(gs_acm_descriptor), 323 .bLength = sizeof(gs_acm_descriptor),
407 .bDescriptorType = USB_DT_CS_INTERFACE, 324 .bDescriptorType = USB_DT_CS_INTERFACE,
408 .bDescriptorSubType = USB_CDC_ACM_TYPE, 325 .bDescriptorSubType = USB_CDC_ACM_TYPE,
409 .bmCapabilities = 0, 326 .bmCapabilities = (1 << 1),
410}; 327};
411 328
412static const struct usb_cdc_union_desc gs_union_desc = { 329static const struct usb_cdc_union_desc gs_union_desc = {
@@ -516,6 +433,8 @@ static const struct usb_descriptor_header *gs_acm_highspeed_function[] = {
516}; 433};
517 434
518 435
436/*-------------------------------------------------------------------------*/
437
519/* Module */ 438/* Module */
520MODULE_DESCRIPTION(GS_LONG_NAME); 439MODULE_DESCRIPTION(GS_LONG_NAME);
521MODULE_AUTHOR("Al Borchers"); 440MODULE_AUTHOR("Al Borchers");
@@ -526,84 +445,23 @@ module_param(debug, int, S_IRUGO|S_IWUSR);
526MODULE_PARM_DESC(debug, "Enable debugging, 0=off, 1=on"); 445MODULE_PARM_DESC(debug, "Enable debugging, 0=off, 1=on");
527#endif 446#endif
528 447
448static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE;
529module_param(read_q_size, uint, S_IRUGO); 449module_param(read_q_size, uint, S_IRUGO);
530MODULE_PARM_DESC(read_q_size, "Read request queue size, default=32"); 450MODULE_PARM_DESC(read_q_size, "Read request queue size, default=32");
531 451
452static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE;
532module_param(write_q_size, uint, S_IRUGO); 453module_param(write_q_size, uint, S_IRUGO);
533MODULE_PARM_DESC(write_q_size, "Write request queue size, default=32"); 454MODULE_PARM_DESC(write_q_size, "Write request queue size, default=32");
534 455
456static unsigned int write_buf_size = GS_DEFAULT_WRITE_BUF_SIZE;
535module_param(write_buf_size, uint, S_IRUGO); 457module_param(write_buf_size, uint, S_IRUGO);
536MODULE_PARM_DESC(write_buf_size, "Write buffer size, default=8192"); 458MODULE_PARM_DESC(write_buf_size, "Write buffer size, default=8192");
537 459
460static unsigned int use_acm = GS_DEFAULT_USE_ACM;
538module_param(use_acm, uint, S_IRUGO); 461module_param(use_acm, uint, S_IRUGO);
539MODULE_PARM_DESC(use_acm, "Use CDC ACM, 0=no, 1=yes, default=no"); 462MODULE_PARM_DESC(use_acm, "Use CDC ACM, 0=no, 1=yes, default=no");
540 463
541module_init(gs_module_init); 464/*-------------------------------------------------------------------------*/
542module_exit(gs_module_exit);
543
544/*
545* gs_module_init
546*
547* Register as a USB gadget driver and a tty driver.
548*/
549static int __init gs_module_init(void)
550{
551 int i;
552 int retval;
553
554 retval = usb_gadget_register_driver(&gs_gadget_driver);
555 if (retval) {
556 pr_err("gs_module_init: cannot register gadget driver, "
557 "ret=%d\n", retval);
558 return retval;
559 }
560
561 gs_tty_driver = alloc_tty_driver(GS_NUM_PORTS);
562 if (!gs_tty_driver)
563 return -ENOMEM;
564 gs_tty_driver->owner = THIS_MODULE;
565 gs_tty_driver->driver_name = GS_SHORT_NAME;
566 gs_tty_driver->name = "ttygs";
567 gs_tty_driver->major = GS_MAJOR;
568 gs_tty_driver->minor_start = GS_MINOR_START;
569 gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
570 gs_tty_driver->subtype = SERIAL_TYPE_NORMAL;
571 gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
572 gs_tty_driver->init_termios = tty_std_termios;
573 gs_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
574 tty_set_operations(gs_tty_driver, &gs_tty_ops);
575
576 for (i=0; i < GS_NUM_PORTS; i++)
577 mutex_init(&gs_open_close_lock[i]);
578
579 retval = tty_register_driver(gs_tty_driver);
580 if (retval) {
581 usb_gadget_unregister_driver(&gs_gadget_driver);
582 put_tty_driver(gs_tty_driver);
583 pr_err("gs_module_init: cannot register tty driver, "
584 "ret=%d\n", retval);
585 return retval;
586 }
587
588 pr_info("gs_module_init: %s %s loaded\n",
589 GS_LONG_NAME, GS_VERSION_STR);
590 return 0;
591}
592
593/*
594* gs_module_exit
595*
596* Unregister as a tty driver and a USB gadget driver.
597*/
598static void __exit gs_module_exit(void)
599{
600 tty_unregister_driver(gs_tty_driver);
601 put_tty_driver(gs_tty_driver);
602 usb_gadget_unregister_driver(&gs_gadget_driver);
603
604 pr_info("gs_module_exit: %s %s unloaded\n",
605 GS_LONG_NAME, GS_VERSION_STR);
606}
607 465
608/* TTY Driver */ 466/* TTY Driver */
609 467
@@ -748,15 +606,15 @@ exit_unlock_dev:
748 * gs_close 606 * gs_close
749 */ 607 */
750 608
751#define GS_WRITE_FINISHED_EVENT_SAFELY(p) \ 609static int gs_write_finished_event_safely(struct gs_port *p)
752({ \ 610{
753 int cond; \ 611 int cond;
754 \ 612
755 spin_lock_irq(&(p)->port_lock); \ 613 spin_lock_irq(&(p)->port_lock);
756 cond = !(p)->port_dev || !gs_buf_data_avail((p)->port_write_buf); \ 614 cond = !(p)->port_dev || !gs_buf_data_avail((p)->port_write_buf);
757 spin_unlock_irq(&(p)->port_lock); \ 615 spin_unlock_irq(&(p)->port_lock);
758 cond; \ 616 return cond;
759}) 617}
760 618
761static void gs_close(struct tty_struct *tty, struct file *file) 619static void gs_close(struct tty_struct *tty, struct file *file)
762{ 620{
@@ -802,7 +660,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
802 if (gs_buf_data_avail(port->port_write_buf) > 0) { 660 if (gs_buf_data_avail(port->port_write_buf) > 0) {
803 spin_unlock_irq(&port->port_lock); 661 spin_unlock_irq(&port->port_lock);
804 wait_event_interruptible_timeout(port->port_write_wait, 662 wait_event_interruptible_timeout(port->port_write_wait,
805 GS_WRITE_FINISHED_EVENT_SAFELY(port), 663 gs_write_finished_event_safely(port),
806 GS_CLOSE_TIMEOUT * HZ); 664 GS_CLOSE_TIMEOUT * HZ);
807 spin_lock_irq(&port->port_lock); 665 spin_lock_irq(&port->port_lock);
808 } 666 }
@@ -883,14 +741,15 @@ exit:
883/* 741/*
884 * gs_put_char 742 * gs_put_char
885 */ 743 */
886static void gs_put_char(struct tty_struct *tty, unsigned char ch) 744static int gs_put_char(struct tty_struct *tty, unsigned char ch)
887{ 745{
888 unsigned long flags; 746 unsigned long flags;
889 struct gs_port *port = tty->driver_data; 747 struct gs_port *port = tty->driver_data;
748 int ret = 0;
890 749
891 if (port == NULL) { 750 if (port == NULL) {
892 pr_err("gs_put_char: NULL port pointer\n"); 751 pr_err("gs_put_char: NULL port pointer\n");
893 return; 752 return 0;
894 } 753 }
895 754
896 gs_debug("gs_put_char: (%d,%p) char=0x%x, called from %p\n", 755 gs_debug("gs_put_char: (%d,%p) char=0x%x, called from %p\n",
@@ -910,10 +769,11 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch)
910 goto exit; 769 goto exit;
911 } 770 }
912 771
913 gs_buf_put(port->port_write_buf, &ch, 1); 772 ret = gs_buf_put(port->port_write_buf, &ch, 1);
914 773
915exit: 774exit:
916 spin_unlock_irqrestore(&port->port_lock, flags); 775 spin_unlock_irqrestore(&port->port_lock, flags);
776 return ret;
917} 777}
918 778
919/* 779/*
@@ -1058,6 +918,23 @@ static void gs_set_termios(struct tty_struct *tty, struct ktermios *old)
1058{ 918{
1059} 919}
1060 920
921static const struct tty_operations gs_tty_ops = {
922 .open = gs_open,
923 .close = gs_close,
924 .write = gs_write,
925 .put_char = gs_put_char,
926 .flush_chars = gs_flush_chars,
927 .write_room = gs_write_room,
928 .ioctl = gs_ioctl,
929 .set_termios = gs_set_termios,
930 .throttle = gs_throttle,
931 .unthrottle = gs_unthrottle,
932 .break_ctl = gs_break,
933 .chars_in_buffer = gs_chars_in_buffer,
934};
935
936/*-------------------------------------------------------------------------*/
937
1061/* 938/*
1062* gs_send 939* gs_send
1063* 940*
@@ -1073,7 +950,6 @@ static int gs_send(struct gs_dev *dev)
1073 unsigned long flags; 950 unsigned long flags;
1074 struct usb_ep *ep; 951 struct usb_ep *ep;
1075 struct usb_request *req; 952 struct usb_request *req;
1076 struct gs_req_entry *req_entry;
1077 953
1078 if (dev == NULL) { 954 if (dev == NULL) {
1079 pr_err("gs_send: NULL device pointer\n"); 955 pr_err("gs_send: NULL device pointer\n");
@@ -1086,10 +962,8 @@ static int gs_send(struct gs_dev *dev)
1086 962
1087 while(!list_empty(&dev->dev_req_list)) { 963 while(!list_empty(&dev->dev_req_list)) {
1088 964
1089 req_entry = list_entry(dev->dev_req_list.next, 965 req = list_entry(dev->dev_req_list.next,
1090 struct gs_req_entry, re_entry); 966 struct usb_request, list);
1091
1092 req = req_entry->re_req;
1093 967
1094 len = gs_send_packet(dev, req->buf, ep->maxpacket); 968 len = gs_send_packet(dev, req->buf, ep->maxpacket);
1095 969
@@ -1099,7 +973,7 @@ static int gs_send(struct gs_dev *dev)
1099 *((unsigned char *)req->buf), 973 *((unsigned char *)req->buf),
1100 *((unsigned char *)req->buf+1), 974 *((unsigned char *)req->buf+1),
1101 *((unsigned char *)req->buf+2)); 975 *((unsigned char *)req->buf+2));
1102 list_del(&req_entry->re_entry); 976 list_del(&req->list);
1103 req->length = len; 977 req->length = len;
1104 spin_unlock_irqrestore(&dev->dev_lock, flags); 978 spin_unlock_irqrestore(&dev->dev_lock, flags);
1105 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { 979 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
@@ -1282,7 +1156,6 @@ requeue:
1282static void gs_write_complete(struct usb_ep *ep, struct usb_request *req) 1156static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
1283{ 1157{
1284 struct gs_dev *dev = ep->driver_data; 1158 struct gs_dev *dev = ep->driver_data;
1285 struct gs_req_entry *gs_req = req->context;
1286 1159
1287 if (dev == NULL) { 1160 if (dev == NULL) {
1288 pr_err("gs_write_complete: NULL device pointer\n"); 1161 pr_err("gs_write_complete: NULL device pointer\n");
@@ -1293,13 +1166,8 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
1293 case 0: 1166 case 0:
1294 /* normal completion */ 1167 /* normal completion */
1295requeue: 1168requeue:
1296 if (gs_req == NULL) {
1297 pr_err("gs_write_complete: NULL request pointer\n");
1298 return;
1299 }
1300
1301 spin_lock(&dev->dev_lock); 1169 spin_lock(&dev->dev_lock);
1302 list_add(&gs_req->re_entry, &dev->dev_req_list); 1170 list_add(&req->list, &dev->dev_req_list);
1303 spin_unlock(&dev->dev_lock); 1171 spin_unlock(&dev->dev_lock);
1304 1172
1305 gs_send(dev); 1173 gs_send(dev);
@@ -1321,9 +1189,39 @@ requeue:
1321 } 1189 }
1322} 1190}
1323 1191
1192/*-------------------------------------------------------------------------*/
1193
1324/* Gadget Driver */ 1194/* Gadget Driver */
1325 1195
1326/* 1196/*
1197 * gs_unbind
1198 *
1199 * Called on module unload. Frees the control request and device
1200 * structure.
1201 */
1202static void /* __init_or_exit */ gs_unbind(struct usb_gadget *gadget)
1203{
1204 struct gs_dev *dev = get_gadget_data(gadget);
1205
1206 gs_device = NULL;
1207
1208 /* read/write requests already freed, only control request remains */
1209 if (dev != NULL) {
1210 if (dev->dev_ctrl_req != NULL) {
1211 gs_free_req(gadget->ep0, dev->dev_ctrl_req);
1212 dev->dev_ctrl_req = NULL;
1213 }
1214 gs_reset_config(dev);
1215 gs_free_ports(dev);
1216 kfree(dev);
1217 set_gadget_data(gadget, NULL);
1218 }
1219
1220 pr_info("gs_unbind: %s %s unbound\n", GS_LONG_NAME,
1221 GS_VERSION_STR);
1222}
1223
1224/*
1327 * gs_bind 1225 * gs_bind
1328 * 1226 *
1329 * Called on module load. Allocates and initializes the device 1227 * Called on module load. Allocates and initializes the device
@@ -1355,19 +1253,23 @@ static int __init gs_bind(struct usb_gadget *gadget)
1355 __constant_cpu_to_le16(GS_VERSION_NUM|0x0099); 1253 __constant_cpu_to_le16(GS_VERSION_NUM|0x0099);
1356 } 1254 }
1357 1255
1256 dev = kzalloc(sizeof(struct gs_dev), GFP_KERNEL);
1257 if (dev == NULL)
1258 return -ENOMEM;
1259
1358 usb_ep_autoconfig_reset(gadget); 1260 usb_ep_autoconfig_reset(gadget);
1359 1261
1360 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_in_desc); 1262 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_in_desc);
1361 if (!ep) 1263 if (!ep)
1362 goto autoconf_fail; 1264 goto autoconf_fail;
1363 EP_IN_NAME = ep->name; 1265 dev->dev_in_ep = ep;
1364 ep->driver_data = ep; /* claim the endpoint */ 1266 ep->driver_data = dev; /* claim the endpoint */
1365 1267
1366 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_out_desc); 1268 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_out_desc);
1367 if (!ep) 1269 if (!ep)
1368 goto autoconf_fail; 1270 goto autoconf_fail;
1369 EP_OUT_NAME = ep->name; 1271 dev->dev_out_ep = ep;
1370 ep->driver_data = ep; /* claim the endpoint */ 1272 ep->driver_data = dev; /* claim the endpoint */
1371 1273
1372 if (use_acm) { 1274 if (use_acm) {
1373 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc); 1275 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc);
@@ -1377,8 +1279,8 @@ static int __init gs_bind(struct usb_gadget *gadget)
1377 } 1279 }
1378 gs_device_desc.idProduct = __constant_cpu_to_le16( 1280 gs_device_desc.idProduct = __constant_cpu_to_le16(
1379 GS_CDC_PRODUCT_ID), 1281 GS_CDC_PRODUCT_ID),
1380 EP_NOTIFY_NAME = ep->name; 1282 dev->dev_notify_ep = ep;
1381 ep->driver_data = ep; /* claim the endpoint */ 1283 ep->driver_data = dev; /* claim the endpoint */
1382 } 1284 }
1383 1285
1384 gs_device_desc.bDeviceClass = use_acm 1286 gs_device_desc.bDeviceClass = use_acm
@@ -1408,9 +1310,7 @@ static int __init gs_bind(struct usb_gadget *gadget)
1408 gs_acm_config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1310 gs_acm_config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1409 } 1311 }
1410 1312
1411 gs_device = dev = kzalloc(sizeof(struct gs_dev), GFP_KERNEL); 1313 gs_device = dev;
1412 if (dev == NULL)
1413 return -ENOMEM;
1414 1314
1415 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s", 1315 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
1416 init_utsname()->sysname, init_utsname()->release, 1316 init_utsname()->sysname, init_utsname()->release,
@@ -1434,8 +1334,6 @@ static int __init gs_bind(struct usb_gadget *gadget)
1434 gs_unbind(gadget); 1334 gs_unbind(gadget);
1435 return -ENOMEM; 1335 return -ENOMEM;
1436 } 1336 }
1437 dev->dev_ctrl_req->complete = gs_setup_complete;
1438
1439 gadget->ep0->driver_data = dev; 1337 gadget->ep0->driver_data = dev;
1440 1338
1441 pr_info("gs_bind: %s %s bound\n", 1339 pr_info("gs_bind: %s %s bound\n",
@@ -1444,97 +1342,11 @@ static int __init gs_bind(struct usb_gadget *gadget)
1444 return 0; 1342 return 0;
1445 1343
1446autoconf_fail: 1344autoconf_fail:
1345 kfree(dev);
1447 pr_err("gs_bind: cannot autoconfigure on %s\n", gadget->name); 1346 pr_err("gs_bind: cannot autoconfigure on %s\n", gadget->name);
1448 return -ENODEV; 1347 return -ENODEV;
1449} 1348}
1450 1349
1451/*
1452 * gs_unbind
1453 *
1454 * Called on module unload. Frees the control request and device
1455 * structure.
1456 */
1457static void /* __init_or_exit */ gs_unbind(struct usb_gadget *gadget)
1458{
1459 struct gs_dev *dev = get_gadget_data(gadget);
1460
1461 gs_device = NULL;
1462
1463 /* read/write requests already freed, only control request remains */
1464 if (dev != NULL) {
1465 if (dev->dev_ctrl_req != NULL) {
1466 gs_free_req(gadget->ep0, dev->dev_ctrl_req);
1467 dev->dev_ctrl_req = NULL;
1468 }
1469 gs_free_ports(dev);
1470 if (dev->dev_notify_ep)
1471 usb_ep_disable(dev->dev_notify_ep);
1472 if (dev->dev_in_ep)
1473 usb_ep_disable(dev->dev_in_ep);
1474 if (dev->dev_out_ep)
1475 usb_ep_disable(dev->dev_out_ep);
1476 kfree(dev);
1477 set_gadget_data(gadget, NULL);
1478 }
1479
1480 pr_info("gs_unbind: %s %s unbound\n", GS_LONG_NAME,
1481 GS_VERSION_STR);
1482}
1483
1484/*
1485 * gs_setup
1486 *
1487 * Implements all the control endpoint functionality that's not
1488 * handled in hardware or the hardware driver.
1489 *
1490 * Returns the size of the data sent to the host, or a negative
1491 * error number.
1492 */
1493static int gs_setup(struct usb_gadget *gadget,
1494 const struct usb_ctrlrequest *ctrl)
1495{
1496 int ret = -EOPNOTSUPP;
1497 struct gs_dev *dev = get_gadget_data(gadget);
1498 struct usb_request *req = dev->dev_ctrl_req;
1499 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1500 u16 wValue = le16_to_cpu(ctrl->wValue);
1501 u16 wLength = le16_to_cpu(ctrl->wLength);
1502
1503 switch (ctrl->bRequestType & USB_TYPE_MASK) {
1504 case USB_TYPE_STANDARD:
1505 ret = gs_setup_standard(gadget,ctrl);
1506 break;
1507
1508 case USB_TYPE_CLASS:
1509 ret = gs_setup_class(gadget,ctrl);
1510 break;
1511
1512 default:
1513 pr_err("gs_setup: unknown request, type=%02x, request=%02x, "
1514 "value=%04x, index=%04x, length=%d\n",
1515 ctrl->bRequestType, ctrl->bRequest,
1516 wValue, wIndex, wLength);
1517 break;
1518 }
1519
1520 /* respond with data transfer before status phase? */
1521 if (ret >= 0) {
1522 req->length = ret;
1523 req->zero = ret < wLength
1524 && (ret % gadget->ep0->maxpacket) == 0;
1525 ret = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1526 if (ret < 0) {
1527 pr_err("gs_setup: cannot queue response, ret=%d\n",
1528 ret);
1529 req->status = 0;
1530 gs_setup_complete(gadget->ep0, req);
1531 }
1532 }
1533
1534 /* device either stalls (ret < 0) or reports success */
1535 return ret;
1536}
1537
1538static int gs_setup_standard(struct usb_gadget *gadget, 1350static int gs_setup_standard(struct usb_gadget *gadget,
1539 const struct usb_ctrlrequest *ctrl) 1351 const struct usb_ctrlrequest *ctrl)
1540{ 1352{
@@ -1664,6 +1476,42 @@ set_interface_done:
1664 return ret; 1476 return ret;
1665} 1477}
1666 1478
1479static void gs_setup_complete_set_line_coding(struct usb_ep *ep,
1480 struct usb_request *req)
1481{
1482 struct gs_dev *dev = ep->driver_data;
1483 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */
1484
1485 switch (req->status) {
1486 case 0:
1487 /* normal completion */
1488 if (req->actual != sizeof(port->port_line_coding))
1489 usb_ep_set_halt(ep);
1490 else if (port) {
1491 struct usb_cdc_line_coding *value = req->buf;
1492
1493 /* REVISIT: we currently just remember this data.
1494 * If we change that, (a) validate it first, then
1495 * (b) update whatever hardware needs updating.
1496 */
1497 spin_lock(&port->port_lock);
1498 port->port_line_coding = *value;
1499 spin_unlock(&port->port_lock);
1500 }
1501 break;
1502
1503 case -ESHUTDOWN:
1504 /* disconnect */
1505 gs_free_req(ep, req);
1506 break;
1507
1508 default:
1509 /* unexpected */
1510 break;
1511 }
1512 return;
1513}
1514
1667static int gs_setup_class(struct usb_gadget *gadget, 1515static int gs_setup_class(struct usb_gadget *gadget,
1668 const struct usb_ctrlrequest *ctrl) 1516 const struct usb_ctrlrequest *ctrl)
1669{ 1517{
@@ -1677,18 +1525,14 @@ static int gs_setup_class(struct usb_gadget *gadget,
1677 1525
1678 switch (ctrl->bRequest) { 1526 switch (ctrl->bRequest) {
1679 case USB_CDC_REQ_SET_LINE_CODING: 1527 case USB_CDC_REQ_SET_LINE_CODING:
1680 /* FIXME Submit req to read the data; have its completion 1528 if (wLength != sizeof(struct usb_cdc_line_coding))
1681 * handler copy that data to port->port_line_coding (iff 1529 break;
1682 * it's valid) and maybe pass it on. Until then, fail. 1530 ret = wLength;
1683 */ 1531 req->complete = gs_setup_complete_set_line_coding;
1684 pr_warning("gs_setup: set_line_coding "
1685 "unuspported\n");
1686 break; 1532 break;
1687 1533
1688 case USB_CDC_REQ_GET_LINE_CODING: 1534 case USB_CDC_REQ_GET_LINE_CODING:
1689 port = dev->dev_port[0]; /* ACM only has one port */ 1535 ret = min_t(int, wLength, sizeof(struct usb_cdc_line_coding));
1690 ret = min(wLength,
1691 (u16)sizeof(struct usb_cdc_line_coding));
1692 if (port) { 1536 if (port) {
1693 spin_lock(&port->port_lock); 1537 spin_lock(&port->port_lock);
1694 memcpy(req->buf, &port->port_line_coding, ret); 1538 memcpy(req->buf, &port->port_line_coding, ret);
@@ -1697,15 +1541,27 @@ static int gs_setup_class(struct usb_gadget *gadget,
1697 break; 1541 break;
1698 1542
1699 case USB_CDC_REQ_SET_CONTROL_LINE_STATE: 1543 case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
1700 /* FIXME Submit req to read the data; have its completion 1544 if (wLength != 0)
1701 * handler use that to set the state (iff it's valid) and 1545 break;
1702 * maybe pass it on. Until then, fail. 1546 ret = 0;
1703 */ 1547 if (port) {
1704 pr_warning("gs_setup: set_control_line_state " 1548 /* REVISIT: we currently just remember this data.
1705 "unuspported\n"); 1549 * If we change that, update whatever hardware needs
1550 * updating.
1551 */
1552 spin_lock(&port->port_lock);
1553 port->port_handshake_bits = wValue;
1554 spin_unlock(&port->port_lock);
1555 }
1706 break; 1556 break;
1707 1557
1708 default: 1558 default:
1559 /* NOTE: strictly speaking, we should accept AT-commands
1560 * using SEND_ENCPSULATED_COMMAND/GET_ENCAPSULATED_RESPONSE.
1561 * But our call management descriptor says we don't handle
1562 * call management, so we should be able to get by without
1563 * handling those "required" commands (except by stalling).
1564 */
1709 pr_err("gs_setup: unknown class request, " 1565 pr_err("gs_setup: unknown class request, "
1710 "type=%02x, request=%02x, value=%04x, " 1566 "type=%02x, request=%02x, value=%04x, "
1711 "index=%04x, length=%d\n", 1567 "index=%04x, length=%d\n",
@@ -1730,6 +1586,62 @@ static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req)
1730} 1586}
1731 1587
1732/* 1588/*
1589 * gs_setup
1590 *
1591 * Implements all the control endpoint functionality that's not
1592 * handled in hardware or the hardware driver.
1593 *
1594 * Returns the size of the data sent to the host, or a negative
1595 * error number.
1596 */
1597static int gs_setup(struct usb_gadget *gadget,
1598 const struct usb_ctrlrequest *ctrl)
1599{
1600 int ret = -EOPNOTSUPP;
1601 struct gs_dev *dev = get_gadget_data(gadget);
1602 struct usb_request *req = dev->dev_ctrl_req;
1603 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1604 u16 wValue = le16_to_cpu(ctrl->wValue);
1605 u16 wLength = le16_to_cpu(ctrl->wLength);
1606
1607 req->complete = gs_setup_complete;
1608
1609 switch (ctrl->bRequestType & USB_TYPE_MASK) {
1610 case USB_TYPE_STANDARD:
1611 ret = gs_setup_standard(gadget, ctrl);
1612 break;
1613
1614 case USB_TYPE_CLASS:
1615 ret = gs_setup_class(gadget, ctrl);
1616 break;
1617
1618 default:
1619 pr_err("gs_setup: unknown request, type=%02x, request=%02x, "
1620 "value=%04x, index=%04x, length=%d\n",
1621 ctrl->bRequestType, ctrl->bRequest,
1622 wValue, wIndex, wLength);
1623 break;
1624 }
1625
1626 /* respond with data transfer before status phase? */
1627 if (ret >= 0) {
1628 req->length = ret;
1629 req->zero = ret < wLength
1630 && (ret % gadget->ep0->maxpacket) == 0;
1631 ret = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1632 if (ret < 0) {
1633 pr_err("gs_setup: cannot queue response, ret=%d\n",
1634 ret);
1635 req->status = 0;
1636 gs_setup_complete(gadget->ep0, req);
1637 }
1638 }
1639
1640 /* device either stalls (ret < 0) or reports success */
1641 return ret;
1642}
1643
1644/*
1733 * gs_disconnect 1645 * gs_disconnect
1734 * 1646 *
1735 * Called when the device is disconnected. Frees the closed 1647 * Called when the device is disconnected. Frees the closed
@@ -1758,6 +1670,23 @@ static void gs_disconnect(struct usb_gadget *gadget)
1758 pr_info("gs_disconnect: %s disconnected\n", GS_LONG_NAME); 1670 pr_info("gs_disconnect: %s disconnected\n", GS_LONG_NAME);
1759} 1671}
1760 1672
1673static struct usb_gadget_driver gs_gadget_driver = {
1674#ifdef CONFIG_USB_GADGET_DUALSPEED
1675 .speed = USB_SPEED_HIGH,
1676#else
1677 .speed = USB_SPEED_FULL,
1678#endif /* CONFIG_USB_GADGET_DUALSPEED */
1679 .function = GS_LONG_NAME,
1680 .bind = gs_bind,
1681 .unbind = gs_unbind,
1682 .setup = gs_setup,
1683 .disconnect = gs_disconnect,
1684 .driver = {
1685 .name = GS_SHORT_NAME,
1686 .owner = THIS_MODULE,
1687 },
1688};
1689
1761/* 1690/*
1762 * gs_set_config 1691 * gs_set_config
1763 * 1692 *
@@ -1773,9 +1702,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1773 int ret = 0; 1702 int ret = 0;
1774 struct usb_gadget *gadget = dev->dev_gadget; 1703 struct usb_gadget *gadget = dev->dev_gadget;
1775 struct usb_ep *ep; 1704 struct usb_ep *ep;
1776 struct usb_endpoint_descriptor *ep_desc; 1705 struct usb_endpoint_descriptor *out, *in, *notify;
1777 struct usb_request *req; 1706 struct usb_request *req;
1778 struct gs_req_entry *req_entry;
1779 1707
1780 if (dev == NULL) { 1708 if (dev == NULL) {
1781 pr_err("gs_set_config: NULL device pointer\n"); 1709 pr_err("gs_set_config: NULL device pointer\n");
@@ -1793,86 +1721,62 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1793 case GS_BULK_CONFIG_ID: 1721 case GS_BULK_CONFIG_ID:
1794 if (use_acm) 1722 if (use_acm)
1795 return -EINVAL; 1723 return -EINVAL;
1796 /* device specific optimizations */
1797 if (gadget_is_net2280(gadget))
1798 net2280_set_fifo_mode(gadget, 1);
1799 break; 1724 break;
1800 case GS_ACM_CONFIG_ID: 1725 case GS_ACM_CONFIG_ID:
1801 if (!use_acm) 1726 if (!use_acm)
1802 return -EINVAL; 1727 return -EINVAL;
1803 /* device specific optimizations */
1804 if (gadget_is_net2280(gadget))
1805 net2280_set_fifo_mode(gadget, 1);
1806 break; 1728 break;
1807 default: 1729 default:
1808 return -EINVAL; 1730 return -EINVAL;
1809 } 1731 }
1810 1732
1811 dev->dev_config = config; 1733 in = choose_ep_desc(gadget,
1812 1734 &gs_highspeed_in_desc,
1813 gadget_for_each_ep(ep, gadget) { 1735 &gs_fullspeed_in_desc);
1814 1736 out = choose_ep_desc(gadget,
1815 if (EP_NOTIFY_NAME 1737 &gs_highspeed_out_desc,
1816 && strcmp(ep->name, EP_NOTIFY_NAME) == 0) { 1738 &gs_fullspeed_out_desc);
1817 ep_desc = choose_ep_desc(gadget, 1739 notify = dev->dev_notify_ep
1740 ? choose_ep_desc(gadget,
1818 &gs_highspeed_notify_desc, 1741 &gs_highspeed_notify_desc,
1819 &gs_fullspeed_notify_desc); 1742 &gs_fullspeed_notify_desc)
1820 ret = usb_ep_enable(ep,ep_desc); 1743 : NULL;
1821 if (ret == 0) {
1822 ep->driver_data = dev;
1823 dev->dev_notify_ep = ep;
1824 dev->dev_notify_ep_desc = ep_desc;
1825 } else {
1826 pr_err("gs_set_config: cannot enable NOTIFY "
1827 "endpoint %s, ret=%d\n",
1828 ep->name, ret);
1829 goto exit_reset_config;
1830 }
1831 }
1832 1744
1833 else if (strcmp(ep->name, EP_IN_NAME) == 0) { 1745 ret = usb_ep_enable(dev->dev_in_ep, in);
1834 ep_desc = choose_ep_desc(gadget, 1746 if (ret == 0) {
1835 &gs_highspeed_in_desc, 1747 dev->dev_in_ep_desc = in;
1836 &gs_fullspeed_in_desc); 1748 } else {
1837 ret = usb_ep_enable(ep,ep_desc); 1749 pr_debug("%s: cannot enable %s %s, ret=%d\n",
1838 if (ret == 0) { 1750 __func__, "IN", dev->dev_in_ep->name, ret);
1839 ep->driver_data = dev; 1751 return ret;
1840 dev->dev_in_ep = ep; 1752 }
1841 dev->dev_in_ep_desc = ep_desc;
1842 } else {
1843 pr_err("gs_set_config: cannot enable IN "
1844 "endpoint %s, ret=%d\n",
1845 ep->name, ret);
1846 goto exit_reset_config;
1847 }
1848 }
1849
1850 else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
1851 ep_desc = choose_ep_desc(gadget,
1852 &gs_highspeed_out_desc,
1853 &gs_fullspeed_out_desc);
1854 ret = usb_ep_enable(ep,ep_desc);
1855 if (ret == 0) {
1856 ep->driver_data = dev;
1857 dev->dev_out_ep = ep;
1858 dev->dev_out_ep_desc = ep_desc;
1859 } else {
1860 pr_err("gs_set_config: cannot enable OUT "
1861 "endpoint %s, ret=%d\n",
1862 ep->name, ret);
1863 goto exit_reset_config;
1864 }
1865 }
1866 1753
1754 ret = usb_ep_enable(dev->dev_out_ep, out);
1755 if (ret == 0) {
1756 dev->dev_out_ep_desc = out;
1757 } else {
1758 pr_debug("%s: cannot enable %s %s, ret=%d\n",
1759 __func__, "OUT", dev->dev_out_ep->name, ret);
1760fail0:
1761 usb_ep_disable(dev->dev_in_ep);
1762 return ret;
1867 } 1763 }
1868 1764
1869 if (dev->dev_in_ep == NULL || dev->dev_out_ep == NULL 1765 if (notify) {
1870 || (config != GS_BULK_CONFIG_ID && dev->dev_notify_ep == NULL)) { 1766 ret = usb_ep_enable(dev->dev_notify_ep, notify);
1871 pr_err("gs_set_config: cannot find endpoints\n"); 1767 if (ret == 0) {
1872 ret = -ENODEV; 1768 dev->dev_notify_ep_desc = notify;
1873 goto exit_reset_config; 1769 } else {
1770 pr_debug("%s: cannot enable %s %s, ret=%d\n",
1771 __func__, "NOTIFY",
1772 dev->dev_notify_ep->name, ret);
1773 usb_ep_disable(dev->dev_out_ep);
1774 goto fail0;
1775 }
1874 } 1776 }
1875 1777
1778 dev->dev_config = config;
1779
1876 /* allocate and queue read requests */ 1780 /* allocate and queue read requests */
1877 ep = dev->dev_out_ep; 1781 ep = dev->dev_out_ep;
1878 for (i=0; i<read_q_size && ret == 0; i++) { 1782 for (i=0; i<read_q_size && ret == 0; i++) {
@@ -1893,9 +1797,10 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1893 /* allocate write requests, and put on free list */ 1797 /* allocate write requests, and put on free list */
1894 ep = dev->dev_in_ep; 1798 ep = dev->dev_in_ep;
1895 for (i=0; i<write_q_size; i++) { 1799 for (i=0; i<write_q_size; i++) {
1896 if ((req_entry=gs_alloc_req_entry(ep, ep->maxpacket, GFP_ATOMIC))) { 1800 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
1897 req_entry->re_req->complete = gs_write_complete; 1801 if (req) {
1898 list_add(&req_entry->re_entry, &dev->dev_req_list); 1802 req->complete = gs_write_complete;
1803 list_add(&req->list, &dev->dev_req_list);
1899 } else { 1804 } else {
1900 pr_err("gs_set_config: cannot allocate " 1805 pr_err("gs_set_config: cannot allocate "
1901 "write requests\n"); 1806 "write requests\n");
@@ -1904,6 +1809,11 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1904 } 1809 }
1905 } 1810 }
1906 1811
1812 /* REVISIT the ACM mode should be able to actually *issue* some
1813 * notifications, for at least serial state change events if
1814 * not also for network connection; say so in bmCapabilities.
1815 */
1816
1907 pr_info("gs_set_config: %s configured, %s speed %s config\n", 1817 pr_info("gs_set_config: %s configured, %s speed %s config\n",
1908 GS_LONG_NAME, 1818 GS_LONG_NAME,
1909 gadget->speed == USB_SPEED_HIGH ? "high" : "full", 1819 gadget->speed == USB_SPEED_HIGH ? "high" : "full",
@@ -1928,7 +1838,7 @@ exit_reset_config:
1928 */ 1838 */
1929static void gs_reset_config(struct gs_dev *dev) 1839static void gs_reset_config(struct gs_dev *dev)
1930{ 1840{
1931 struct gs_req_entry *req_entry; 1841 struct usb_request *req;
1932 1842
1933 if (dev == NULL) { 1843 if (dev == NULL) {
1934 pr_err("gs_reset_config: NULL device pointer\n"); 1844 pr_err("gs_reset_config: NULL device pointer\n");
@@ -1942,26 +1852,18 @@ static void gs_reset_config(struct gs_dev *dev)
1942 1852
1943 /* free write requests on the free list */ 1853 /* free write requests on the free list */
1944 while(!list_empty(&dev->dev_req_list)) { 1854 while(!list_empty(&dev->dev_req_list)) {
1945 req_entry = list_entry(dev->dev_req_list.next, 1855 req = list_entry(dev->dev_req_list.next,
1946 struct gs_req_entry, re_entry); 1856 struct usb_request, list);
1947 list_del(&req_entry->re_entry); 1857 list_del(&req->list);
1948 gs_free_req_entry(dev->dev_in_ep, req_entry); 1858 gs_free_req(dev->dev_in_ep, req);
1949 } 1859 }
1950 1860
1951 /* disable endpoints, forcing completion of pending i/o; */ 1861 /* disable endpoints, forcing completion of pending i/o; */
1952 /* completion handlers free their requests in this case */ 1862 /* completion handlers free their requests in this case */
1953 if (dev->dev_notify_ep) { 1863 if (dev->dev_notify_ep)
1954 usb_ep_disable(dev->dev_notify_ep); 1864 usb_ep_disable(dev->dev_notify_ep);
1955 dev->dev_notify_ep = NULL; 1865 usb_ep_disable(dev->dev_in_ep);
1956 } 1866 usb_ep_disable(dev->dev_out_ep);
1957 if (dev->dev_in_ep) {
1958 usb_ep_disable(dev->dev_in_ep);
1959 dev->dev_in_ep = NULL;
1960 }
1961 if (dev->dev_out_ep) {
1962 usb_ep_disable(dev->dev_out_ep);
1963 dev->dev_out_ep = NULL;
1964 }
1965} 1867}
1966 1868
1967/* 1869/*
@@ -2055,46 +1957,6 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
2055} 1957}
2056 1958
2057/* 1959/*
2058 * gs_alloc_req_entry
2059 *
2060 * Allocates a request and its buffer, using the given
2061 * endpoint, buffer len, and kmalloc flags.
2062 */
2063static struct gs_req_entry *
2064gs_alloc_req_entry(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)
2065{
2066 struct gs_req_entry *req;
2067
2068 req = kmalloc(sizeof(struct gs_req_entry), kmalloc_flags);
2069 if (req == NULL)
2070 return NULL;
2071
2072 req->re_req = gs_alloc_req(ep, len, kmalloc_flags);
2073 if (req->re_req == NULL) {
2074 kfree(req);
2075 return NULL;
2076 }
2077
2078 req->re_req->context = req;
2079
2080 return req;
2081}
2082
2083/*
2084 * gs_free_req_entry
2085 *
2086 * Frees a request and its buffer.
2087 */
2088static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
2089{
2090 if (ep != NULL && req != NULL) {
2091 if (req->re_req != NULL)
2092 gs_free_req(ep, req->re_req);
2093 kfree(req);
2094 }
2095}
2096
2097/*
2098 * gs_alloc_ports 1960 * gs_alloc_ports
2099 * 1961 *
2100 * Allocate all ports and set the gs_dev struct to point to them. 1962 * Allocate all ports and set the gs_dev struct to point to them.
@@ -2163,8 +2025,7 @@ static void gs_free_ports(struct gs_dev *dev)
2163 port->port_dev = NULL; 2025 port->port_dev = NULL;
2164 wake_up_interruptible(&port->port_write_wait); 2026 wake_up_interruptible(&port->port_write_wait);
2165 if (port->port_tty) { 2027 if (port->port_tty) {
2166 wake_up_interruptible(&port->port_tty->read_wait); 2028 tty_hangup(port->port_tty);
2167 wake_up_interruptible(&port->port_tty->write_wait);
2168 } 2029 }
2169 spin_unlock_irqrestore(&port->port_lock, flags); 2030 spin_unlock_irqrestore(&port->port_lock, flags);
2170 } else { 2031 } else {
@@ -2176,6 +2037,8 @@ static void gs_free_ports(struct gs_dev *dev)
2176 } 2037 }
2177} 2038}
2178 2039
2040/*-------------------------------------------------------------------------*/
2041
2179/* Circular Buffer */ 2042/* Circular Buffer */
2180 2043
2181/* 2044/*
@@ -2336,3 +2199,77 @@ gs_buf_get(struct gs_buf *gb, char *buf, unsigned int count)
2336 2199
2337 return count; 2200 return count;
2338} 2201}
2202
2203/*-------------------------------------------------------------------------*/
2204
2205static struct tty_driver *gs_tty_driver;
2206
2207/*
2208 * gs_module_init
2209 *
2210 * Register as a USB gadget driver and a tty driver.
2211 */
2212static int __init gs_module_init(void)
2213{
2214 int i;
2215 int retval;
2216
2217 retval = usb_gadget_register_driver(&gs_gadget_driver);
2218 if (retval) {
2219 pr_err("gs_module_init: cannot register gadget driver, "
2220 "ret=%d\n", retval);
2221 return retval;
2222 }
2223
2224 gs_tty_driver = alloc_tty_driver(GS_NUM_PORTS);
2225 if (!gs_tty_driver)
2226 return -ENOMEM;
2227 gs_tty_driver->owner = THIS_MODULE;
2228 gs_tty_driver->driver_name = GS_SHORT_NAME;
2229 gs_tty_driver->name = "ttygs";
2230 gs_tty_driver->major = GS_MAJOR;
2231 gs_tty_driver->minor_start = GS_MINOR_START;
2232 gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
2233 gs_tty_driver->subtype = SERIAL_TYPE_NORMAL;
2234 gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
2235 gs_tty_driver->init_termios = tty_std_termios;
2236 /* must match GS_DEFAULT_DTE_RATE and friends */
2237 gs_tty_driver->init_termios.c_cflag =
2238 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2239 gs_tty_driver->init_termios.c_ispeed = GS_DEFAULT_DTE_RATE;
2240 gs_tty_driver->init_termios.c_ospeed = GS_DEFAULT_DTE_RATE;
2241 tty_set_operations(gs_tty_driver, &gs_tty_ops);
2242
2243 for (i = 0; i < GS_NUM_PORTS; i++)
2244 mutex_init(&gs_open_close_lock[i]);
2245
2246 retval = tty_register_driver(gs_tty_driver);
2247 if (retval) {
2248 usb_gadget_unregister_driver(&gs_gadget_driver);
2249 put_tty_driver(gs_tty_driver);
2250 pr_err("gs_module_init: cannot register tty driver, "
2251 "ret=%d\n", retval);
2252 return retval;
2253 }
2254
2255 pr_info("gs_module_init: %s %s loaded\n",
2256 GS_LONG_NAME, GS_VERSION_STR);
2257 return 0;
2258}
2259module_init(gs_module_init);
2260
2261/*
2262 * gs_module_exit
2263 *
2264 * Unregister as a tty driver and a USB gadget driver.
2265 */
2266static void __exit gs_module_exit(void)
2267{
2268 tty_unregister_driver(gs_tty_driver);
2269 put_tty_driver(gs_tty_driver);
2270 usb_gadget_unregister_driver(&gs_gadget_driver);
2271
2272 pr_info("gs_module_exit: %s %s unloaded\n",
2273 GS_LONG_NAME, GS_VERSION_STR);
2274}
2275module_exit(gs_module_exit);
diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c
index 878e428a0ec1..4154be375c7a 100644
--- a/drivers/usb/gadget/usbstring.c
+++ b/drivers/usb/gadget/usbstring.c
@@ -74,7 +74,7 @@ static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len)
74 goto fail; 74 goto fail;
75 } else 75 } else
76 uchar = c; 76 uchar = c;
77 put_unaligned (cpu_to_le16 (uchar), cp++); 77 put_unaligned_le16(uchar, cp++);
78 count++; 78 count++;
79 len--; 79 len--;
80 } 80 }
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index d3d4f4048e6c..fce4924dbbe8 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -23,9 +23,7 @@
23/* 23/*
24 * Gadget Zero only needs two bulk endpoints, and is an example of how you 24 * Gadget Zero only needs two bulk endpoints, and is an example of how you
25 * can write a hardware-agnostic gadget driver running inside a USB device. 25 * can write a hardware-agnostic gadget driver running inside a USB device.
26 * 26 * Some hardware details are visible, but don't affect most of the driver.
27 * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
28 * affect most of the driver.
29 * 27 *
30 * Use it with the Linux host/master side "usbtest" driver to get a basic 28 * Use it with the Linux host/master side "usbtest" driver to get a basic
31 * functional test of your device-side usb stack, or with "usb-skeleton". 29 * functional test of your device-side usb stack, or with "usb-skeleton".
@@ -37,6 +35,7 @@
37 * buflen=N default N=4096, buffer size used 35 * buflen=N default N=4096, buffer size used
38 * qlen=N default N=32, how many buffers in the loopback queue 36 * qlen=N default N=32, how many buffers in the loopback queue
39 * loopdefault default false, list loopback config first 37 * loopdefault default false, list loopback config first
38 * autoresume=N default N=0, seconds before triggering remote wakeup
40 * 39 *
41 * Many drivers will only have one configuration, letting them be much 40 * Many drivers will only have one configuration, letting them be much
42 * simpler if they also don't support high speed operation (like this 41 * simpler if they also don't support high speed operation (like this
@@ -62,13 +61,13 @@
62 61
63/*-------------------------------------------------------------------------*/ 62/*-------------------------------------------------------------------------*/
64 63
65#define DRIVER_VERSION "Lughnasadh, 2007" 64#define DRIVER_VERSION "Earth Day 2008"
66 65
67static const char shortname [] = "zero"; 66static const char shortname[] = "zero";
68static const char longname [] = "Gadget Zero"; 67static const char longname[] = "Gadget Zero";
69 68
70static const char source_sink [] = "source and sink data"; 69static const char source_sink[] = "source and sink data";
71static const char loopback [] = "loop input to output"; 70static const char loopback[] = "loop input to output";
72 71
73/*-------------------------------------------------------------------------*/ 72/*-------------------------------------------------------------------------*/
74 73
@@ -120,16 +119,16 @@ static unsigned buflen = 4096;
120static unsigned qlen = 32; 119static unsigned qlen = 32;
121static unsigned pattern = 0; 120static unsigned pattern = 0;
122 121
123module_param (buflen, uint, S_IRUGO); 122module_param(buflen, uint, S_IRUGO);
124module_param (qlen, uint, S_IRUGO); 123module_param(qlen, uint, S_IRUGO);
125module_param (pattern, uint, S_IRUGO|S_IWUSR); 124module_param(pattern, uint, S_IRUGO|S_IWUSR);
126 125
127/* 126/*
128 * if it's nonzero, autoresume says how many seconds to wait 127 * if it's nonzero, autoresume says how many seconds to wait
129 * before trying to wake up the host after suspend. 128 * before trying to wake up the host after suspend.
130 */ 129 */
131static unsigned autoresume = 0; 130static unsigned autoresume = 0;
132module_param (autoresume, uint, 0); 131module_param(autoresume, uint, 0);
133 132
134/* 133/*
135 * Normally the "loopback" configuration is second (index 1) so 134 * Normally the "loopback" configuration is second (index 1) so
@@ -138,8 +137,7 @@ module_param (autoresume, uint, 0);
138 * Or controllers (like superh) that only support one config. 137 * Or controllers (like superh) that only support one config.
139 */ 138 */
140static int loopdefault = 0; 139static int loopdefault = 0;
141 140module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
142module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
143 141
144/*-------------------------------------------------------------------------*/ 142/*-------------------------------------------------------------------------*/
145 143
@@ -176,24 +174,22 @@ module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
176#define CONFIG_SOURCE_SINK 3 174#define CONFIG_SOURCE_SINK 3
177#define CONFIG_LOOPBACK 2 175#define CONFIG_LOOPBACK 2
178 176
179static struct usb_device_descriptor 177static struct usb_device_descriptor device_desc = {
180device_desc = {
181 .bLength = sizeof device_desc, 178 .bLength = sizeof device_desc,
182 .bDescriptorType = USB_DT_DEVICE, 179 .bDescriptorType = USB_DT_DEVICE,
183 180
184 .bcdUSB = __constant_cpu_to_le16 (0x0200), 181 .bcdUSB = __constant_cpu_to_le16(0x0200),
185 .bDeviceClass = USB_CLASS_VENDOR_SPEC, 182 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
186 183
187 .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM), 184 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
188 .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM), 185 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
189 .iManufacturer = STRING_MANUFACTURER, 186 .iManufacturer = STRING_MANUFACTURER,
190 .iProduct = STRING_PRODUCT, 187 .iProduct = STRING_PRODUCT,
191 .iSerialNumber = STRING_SERIAL, 188 .iSerialNumber = STRING_SERIAL,
192 .bNumConfigurations = 2, 189 .bNumConfigurations = 2,
193}; 190};
194 191
195static struct usb_config_descriptor 192static struct usb_config_descriptor source_sink_config = {
196source_sink_config = {
197 .bLength = sizeof source_sink_config, 193 .bLength = sizeof source_sink_config,
198 .bDescriptorType = USB_DT_CONFIG, 194 .bDescriptorType = USB_DT_CONFIG,
199 195
@@ -205,8 +201,7 @@ source_sink_config = {
205 .bMaxPower = 1, /* self-powered */ 201 .bMaxPower = 1, /* self-powered */
206}; 202};
207 203
208static struct usb_config_descriptor 204static struct usb_config_descriptor loopback_config = {
209loopback_config = {
210 .bLength = sizeof loopback_config, 205 .bLength = sizeof loopback_config,
211 .bDescriptorType = USB_DT_CONFIG, 206 .bDescriptorType = USB_DT_CONFIG,
212 207
@@ -218,8 +213,7 @@ loopback_config = {
218 .bMaxPower = 1, /* self-powered */ 213 .bMaxPower = 1, /* self-powered */
219}; 214};
220 215
221static struct usb_otg_descriptor 216static struct usb_otg_descriptor otg_descriptor = {
222otg_descriptor = {
223 .bLength = sizeof otg_descriptor, 217 .bLength = sizeof otg_descriptor,
224 .bDescriptorType = USB_DT_OTG, 218 .bDescriptorType = USB_DT_OTG,
225 219
@@ -228,8 +222,7 @@ otg_descriptor = {
228 222
229/* one interface in each configuration */ 223/* one interface in each configuration */
230 224
231static const struct usb_interface_descriptor 225static const struct usb_interface_descriptor source_sink_intf = {
232source_sink_intf = {
233 .bLength = sizeof source_sink_intf, 226 .bLength = sizeof source_sink_intf,
234 .bDescriptorType = USB_DT_INTERFACE, 227 .bDescriptorType = USB_DT_INTERFACE,
235 228
@@ -238,8 +231,7 @@ source_sink_intf = {
238 .iInterface = STRING_SOURCE_SINK, 231 .iInterface = STRING_SOURCE_SINK,
239}; 232};
240 233
241static const struct usb_interface_descriptor 234static const struct usb_interface_descriptor loopback_intf = {
242loopback_intf = {
243 .bLength = sizeof loopback_intf, 235 .bLength = sizeof loopback_intf,
244 .bDescriptorType = USB_DT_INTERFACE, 236 .bDescriptorType = USB_DT_INTERFACE,
245 237
@@ -250,8 +242,7 @@ loopback_intf = {
250 242
251/* two full speed bulk endpoints; their use is config-dependent */ 243/* two full speed bulk endpoints; their use is config-dependent */
252 244
253static struct usb_endpoint_descriptor 245static struct usb_endpoint_descriptor fs_source_desc = {
254fs_source_desc = {
255 .bLength = USB_DT_ENDPOINT_SIZE, 246 .bLength = USB_DT_ENDPOINT_SIZE,
256 .bDescriptorType = USB_DT_ENDPOINT, 247 .bDescriptorType = USB_DT_ENDPOINT,
257 248
@@ -259,8 +250,7 @@ fs_source_desc = {
259 .bmAttributes = USB_ENDPOINT_XFER_BULK, 250 .bmAttributes = USB_ENDPOINT_XFER_BULK,
260}; 251};
261 252
262static struct usb_endpoint_descriptor 253static struct usb_endpoint_descriptor fs_sink_desc = {
263fs_sink_desc = {
264 .bLength = USB_DT_ENDPOINT_SIZE, 254 .bLength = USB_DT_ENDPOINT_SIZE,
265 .bDescriptorType = USB_DT_ENDPOINT, 255 .bDescriptorType = USB_DT_ENDPOINT,
266 256
@@ -268,7 +258,7 @@ fs_sink_desc = {
268 .bmAttributes = USB_ENDPOINT_XFER_BULK, 258 .bmAttributes = USB_ENDPOINT_XFER_BULK,
269}; 259};
270 260
271static const struct usb_descriptor_header *fs_source_sink_function [] = { 261static const struct usb_descriptor_header *fs_source_sink_function[] = {
272 (struct usb_descriptor_header *) &otg_descriptor, 262 (struct usb_descriptor_header *) &otg_descriptor,
273 (struct usb_descriptor_header *) &source_sink_intf, 263 (struct usb_descriptor_header *) &source_sink_intf,
274 (struct usb_descriptor_header *) &fs_sink_desc, 264 (struct usb_descriptor_header *) &fs_sink_desc,
@@ -276,7 +266,7 @@ static const struct usb_descriptor_header *fs_source_sink_function [] = {
276 NULL, 266 NULL,
277}; 267};
278 268
279static const struct usb_descriptor_header *fs_loopback_function [] = { 269static const struct usb_descriptor_header *fs_loopback_function[] = {
280 (struct usb_descriptor_header *) &otg_descriptor, 270 (struct usb_descriptor_header *) &otg_descriptor,
281 (struct usb_descriptor_header *) &loopback_intf, 271 (struct usb_descriptor_header *) &loopback_intf,
282 (struct usb_descriptor_header *) &fs_sink_desc, 272 (struct usb_descriptor_header *) &fs_sink_desc,
@@ -293,36 +283,33 @@ static const struct usb_descriptor_header *fs_loopback_function [] = {
293 * for the config descriptor. 283 * for the config descriptor.
294 */ 284 */
295 285
296static struct usb_endpoint_descriptor 286static struct usb_endpoint_descriptor hs_source_desc = {
297hs_source_desc = {
298 .bLength = USB_DT_ENDPOINT_SIZE, 287 .bLength = USB_DT_ENDPOINT_SIZE,
299 .bDescriptorType = USB_DT_ENDPOINT, 288 .bDescriptorType = USB_DT_ENDPOINT,
300 289
301 .bmAttributes = USB_ENDPOINT_XFER_BULK, 290 .bmAttributes = USB_ENDPOINT_XFER_BULK,
302 .wMaxPacketSize = __constant_cpu_to_le16 (512), 291 .wMaxPacketSize = __constant_cpu_to_le16(512),
303}; 292};
304 293
305static struct usb_endpoint_descriptor 294static struct usb_endpoint_descriptor hs_sink_desc = {
306hs_sink_desc = {
307 .bLength = USB_DT_ENDPOINT_SIZE, 295 .bLength = USB_DT_ENDPOINT_SIZE,
308 .bDescriptorType = USB_DT_ENDPOINT, 296 .bDescriptorType = USB_DT_ENDPOINT,
309 297
310 .bmAttributes = USB_ENDPOINT_XFER_BULK, 298 .bmAttributes = USB_ENDPOINT_XFER_BULK,
311 .wMaxPacketSize = __constant_cpu_to_le16 (512), 299 .wMaxPacketSize = __constant_cpu_to_le16(512),
312}; 300};
313 301
314static struct usb_qualifier_descriptor 302static struct usb_qualifier_descriptor dev_qualifier = {
315dev_qualifier = {
316 .bLength = sizeof dev_qualifier, 303 .bLength = sizeof dev_qualifier,
317 .bDescriptorType = USB_DT_DEVICE_QUALIFIER, 304 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
318 305
319 .bcdUSB = __constant_cpu_to_le16 (0x0200), 306 .bcdUSB = __constant_cpu_to_le16(0x0200),
320 .bDeviceClass = USB_CLASS_VENDOR_SPEC, 307 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
321 308
322 .bNumConfigurations = 2, 309 .bNumConfigurations = 2,
323}; 310};
324 311
325static const struct usb_descriptor_header *hs_source_sink_function [] = { 312static const struct usb_descriptor_header *hs_source_sink_function[] = {
326 (struct usb_descriptor_header *) &otg_descriptor, 313 (struct usb_descriptor_header *) &otg_descriptor,
327 (struct usb_descriptor_header *) &source_sink_intf, 314 (struct usb_descriptor_header *) &source_sink_intf,
328 (struct usb_descriptor_header *) &hs_source_desc, 315 (struct usb_descriptor_header *) &hs_source_desc,
@@ -330,7 +317,7 @@ static const struct usb_descriptor_header *hs_source_sink_function [] = {
330 NULL, 317 NULL,
331}; 318};
332 319
333static const struct usb_descriptor_header *hs_loopback_function [] = { 320static const struct usb_descriptor_header *hs_loopback_function[] = {
334 (struct usb_descriptor_header *) &otg_descriptor, 321 (struct usb_descriptor_header *) &otg_descriptor,
335 (struct usb_descriptor_header *) &loopback_intf, 322 (struct usb_descriptor_header *) &loopback_intf,
336 (struct usb_descriptor_header *) &hs_source_desc, 323 (struct usb_descriptor_header *) &hs_source_desc,
@@ -355,7 +342,7 @@ static char serial[] = "0123456789.0123456789.0123456789";
355 342
356 343
357/* static strings, in UTF-8 */ 344/* static strings, in UTF-8 */
358static struct usb_string strings [] = { 345static struct usb_string strings[] = {
359 { STRING_MANUFACTURER, manufacturer, }, 346 { STRING_MANUFACTURER, manufacturer, },
360 { STRING_PRODUCT, longname, }, 347 { STRING_PRODUCT, longname, },
361 { STRING_SERIAL, serial, }, 348 { STRING_SERIAL, serial, },
@@ -364,7 +351,7 @@ static struct usb_string strings [] = {
364 { } /* end of list */ 351 { } /* end of list */
365}; 352};
366 353
367static struct usb_gadget_strings stringtab = { 354static struct usb_gadget_strings stringtab = {
368 .language = 0x0409, /* en-us */ 355 .language = 0x0409, /* en-us */
369 .strings = strings, 356 .strings = strings,
370}; 357};
@@ -387,8 +374,7 @@ static struct usb_gadget_strings stringtab = {
387 * high bandwidth modes at high speed. (Maybe work like Intel's test 374 * high bandwidth modes at high speed. (Maybe work like Intel's test
388 * device?) 375 * device?)
389 */ 376 */
390static int 377static int config_buf(struct usb_gadget *gadget,
391config_buf (struct usb_gadget *gadget,
392 u8 *buf, u8 type, unsigned index) 378 u8 *buf, u8 type, unsigned index)
393{ 379{
394 int is_source_sink; 380 int is_source_sink;
@@ -419,7 +405,7 @@ config_buf (struct usb_gadget *gadget,
419 if (!gadget_is_otg(gadget)) 405 if (!gadget_is_otg(gadget))
420 function++; 406 function++;
421 407
422 len = usb_gadget_config_buf (is_source_sink 408 len = usb_gadget_config_buf(is_source_sink
423 ? &source_sink_config 409 ? &source_sink_config
424 : &loopback_config, 410 : &loopback_config,
425 buf, USB_BUFSIZ, function); 411 buf, USB_BUFSIZ, function);
@@ -431,27 +417,26 @@ config_buf (struct usb_gadget *gadget,
431 417
432/*-------------------------------------------------------------------------*/ 418/*-------------------------------------------------------------------------*/
433 419
434static struct usb_request * 420static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
435alloc_ep_req (struct usb_ep *ep, unsigned length)
436{ 421{
437 struct usb_request *req; 422 struct usb_request *req;
438 423
439 req = usb_ep_alloc_request (ep, GFP_ATOMIC); 424 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
440 if (req) { 425 if (req) {
441 req->length = length; 426 req->length = length;
442 req->buf = kmalloc(length, GFP_ATOMIC); 427 req->buf = kmalloc(length, GFP_ATOMIC);
443 if (!req->buf) { 428 if (!req->buf) {
444 usb_ep_free_request (ep, req); 429 usb_ep_free_request(ep, req);
445 req = NULL; 430 req = NULL;
446 } 431 }
447 } 432 }
448 return req; 433 return req;
449} 434}
450 435
451static void free_ep_req (struct usb_ep *ep, struct usb_request *req) 436static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
452{ 437{
453 kfree(req->buf); 438 kfree(req->buf);
454 usb_ep_free_request (ep, req); 439 usb_ep_free_request(ep, req);
455} 440}
456 441
457/*-------------------------------------------------------------------------*/ 442/*-------------------------------------------------------------------------*/
@@ -472,7 +457,7 @@ static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
472/* optionally require specific source/sink data patterns */ 457/* optionally require specific source/sink data patterns */
473 458
474static int 459static int
475check_read_data ( 460check_read_data(
476 struct zero_dev *dev, 461 struct zero_dev *dev,
477 struct usb_ep *ep, 462 struct usb_ep *ep,
478 struct usb_request *req 463 struct usb_request *req
@@ -498,8 +483,8 @@ check_read_data (
498 continue; 483 continue;
499 break; 484 break;
500 } 485 }
501 ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf); 486 ERROR(dev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
502 usb_ep_set_halt (ep); 487 usb_ep_set_halt(ep);
503 return -EINVAL; 488 return -EINVAL;
504 } 489 }
505 return 0; 490 return 0;
@@ -512,7 +497,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
512 497
513 switch (pattern) { 498 switch (pattern) {
514 case 0: 499 case 0:
515 memset (req->buf, 0, req->length); 500 memset(req->buf, 0, req->length);
516 break; 501 break;
517 case 1: 502 case 1:
518 for (i = 0; i < req->length; i++) 503 for (i = 0; i < req->length; i++)
@@ -525,7 +510,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
525 * irq delay between end of one request and start of the next. 510 * irq delay between end of one request and start of the next.
526 * that prevents using hardware dma queues. 511 * that prevents using hardware dma queues.
527 */ 512 */
528static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) 513static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
529{ 514{
530 struct zero_dev *dev = ep->driver_data; 515 struct zero_dev *dev = ep->driver_data;
531 int status = req->status; 516 int status = req->status;
@@ -534,8 +519,8 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
534 519
535 case 0: /* normal completion? */ 520 case 0: /* normal completion? */
536 if (ep == dev->out_ep) { 521 if (ep == dev->out_ep) {
537 check_read_data (dev, ep, req); 522 check_read_data(dev, ep, req);
538 memset (req->buf, 0x55, req->length); 523 memset(req->buf, 0x55, req->length);
539 } else 524 } else
540 reinit_write_data(ep, req); 525 reinit_write_data(ep, req);
541 break; 526 break;
@@ -544,11 +529,11 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
544 case -ECONNABORTED: /* hardware forced ep reset */ 529 case -ECONNABORTED: /* hardware forced ep reset */
545 case -ECONNRESET: /* request dequeued */ 530 case -ECONNRESET: /* request dequeued */
546 case -ESHUTDOWN: /* disconnect from host */ 531 case -ESHUTDOWN: /* disconnect from host */
547 VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status, 532 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
548 req->actual, req->length); 533 req->actual, req->length);
549 if (ep == dev->out_ep) 534 if (ep == dev->out_ep)
550 check_read_data (dev, ep, req); 535 check_read_data(dev, ep, req);
551 free_ep_req (ep, req); 536 free_ep_req(ep, req);
552 return; 537 return;
553 538
554 case -EOVERFLOW: /* buffer overrun on read means that 539 case -EOVERFLOW: /* buffer overrun on read means that
@@ -557,18 +542,18 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
557 */ 542 */
558 default: 543 default:
559#if 1 544#if 1
560 DBG (dev, "%s complete --> %d, %d/%d\n", ep->name, 545 DBG(dev, "%s complete --> %d, %d/%d\n", ep->name,
561 status, req->actual, req->length); 546 status, req->actual, req->length);
562#endif 547#endif
563 case -EREMOTEIO: /* short read */ 548 case -EREMOTEIO: /* short read */
564 break; 549 break;
565 } 550 }
566 551
567 status = usb_ep_queue (ep, req, GFP_ATOMIC); 552 status = usb_ep_queue(ep, req, GFP_ATOMIC);
568 if (status) { 553 if (status) {
569 ERROR (dev, "kill %s: resubmit %d bytes --> %d\n", 554 ERROR(dev, "kill %s: resubmit %d bytes --> %d\n",
570 ep->name, req->length, status); 555 ep->name, req->length, status);
571 usb_ep_set_halt (ep); 556 usb_ep_set_halt(ep);
572 /* FIXME recover later ... somehow */ 557 /* FIXME recover later ... somehow */
573 } 558 }
574} 559}
@@ -578,24 +563,24 @@ static struct usb_request *source_sink_start_ep(struct usb_ep *ep)
578 struct usb_request *req; 563 struct usb_request *req;
579 int status; 564 int status;
580 565
581 req = alloc_ep_req (ep, buflen); 566 req = alloc_ep_req(ep, buflen);
582 if (!req) 567 if (!req)
583 return NULL; 568 return NULL;
584 569
585 memset (req->buf, 0, req->length); 570 memset(req->buf, 0, req->length);
586 req->complete = source_sink_complete; 571 req->complete = source_sink_complete;
587 572
588 if (strcmp (ep->name, EP_IN_NAME) == 0) 573 if (strcmp(ep->name, EP_IN_NAME) == 0)
589 reinit_write_data(ep, req); 574 reinit_write_data(ep, req);
590 else 575 else
591 memset (req->buf, 0x55, req->length); 576 memset(req->buf, 0x55, req->length);
592 577
593 status = usb_ep_queue(ep, req, GFP_ATOMIC); 578 status = usb_ep_queue(ep, req, GFP_ATOMIC);
594 if (status) { 579 if (status) {
595 struct zero_dev *dev = ep->driver_data; 580 struct zero_dev *dev = ep->driver_data;
596 581
597 ERROR (dev, "start %s --> %d\n", ep->name, status); 582 ERROR(dev, "start %s --> %d\n", ep->name, status);
598 free_ep_req (ep, req); 583 free_ep_req(ep, req);
599 req = NULL; 584 req = NULL;
600 } 585 }
601 586
@@ -608,34 +593,34 @@ static int set_source_sink_config(struct zero_dev *dev)
608 struct usb_ep *ep; 593 struct usb_ep *ep;
609 struct usb_gadget *gadget = dev->gadget; 594 struct usb_gadget *gadget = dev->gadget;
610 595
611 gadget_for_each_ep (ep, gadget) { 596 gadget_for_each_ep(ep, gadget) {
612 const struct usb_endpoint_descriptor *d; 597 const struct usb_endpoint_descriptor *d;
613 598
614 /* one endpoint writes (sources) zeroes in (to the host) */ 599 /* one endpoint writes (sources) zeroes in (to the host) */
615 if (strcmp (ep->name, EP_IN_NAME) == 0) { 600 if (strcmp(ep->name, EP_IN_NAME) == 0) {
616 d = ep_desc (gadget, &hs_source_desc, &fs_source_desc); 601 d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
617 result = usb_ep_enable (ep, d); 602 result = usb_ep_enable(ep, d);
618 if (result == 0) { 603 if (result == 0) {
619 ep->driver_data = dev; 604 ep->driver_data = dev;
620 if (source_sink_start_ep(ep) != NULL) { 605 if (source_sink_start_ep(ep) != NULL) {
621 dev->in_ep = ep; 606 dev->in_ep = ep;
622 continue; 607 continue;
623 } 608 }
624 usb_ep_disable (ep); 609 usb_ep_disable(ep);
625 result = -EIO; 610 result = -EIO;
626 } 611 }
627 612
628 /* one endpoint reads (sinks) anything out (from the host) */ 613 /* one endpoint reads (sinks) anything out (from the host) */
629 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { 614 } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
630 d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc); 615 d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
631 result = usb_ep_enable (ep, d); 616 result = usb_ep_enable(ep, d);
632 if (result == 0) { 617 if (result == 0) {
633 ep->driver_data = dev; 618 ep->driver_data = dev;
634 if (source_sink_start_ep(ep) != NULL) { 619 if (source_sink_start_ep(ep) != NULL) {
635 dev->out_ep = ep; 620 dev->out_ep = ep;
636 continue; 621 continue;
637 } 622 }
638 usb_ep_disable (ep); 623 usb_ep_disable(ep);
639 result = -EIO; 624 result = -EIO;
640 } 625 }
641 626
@@ -644,11 +629,11 @@ static int set_source_sink_config(struct zero_dev *dev)
644 continue; 629 continue;
645 630
646 /* stop on error */ 631 /* stop on error */
647 ERROR (dev, "can't start %s, result %d\n", ep->name, result); 632 ERROR(dev, "can't start %s, result %d\n", ep->name, result);
648 break; 633 break;
649 } 634 }
650 if (result == 0) 635 if (result == 0)
651 DBG (dev, "buflen %d\n", buflen); 636 DBG(dev, "buflen %d\n", buflen);
652 637
653 /* caller is responsible for cleanup on error */ 638 /* caller is responsible for cleanup on error */
654 return result; 639 return result;
@@ -656,7 +641,7 @@ static int set_source_sink_config(struct zero_dev *dev)
656 641
657/*-------------------------------------------------------------------------*/ 642/*-------------------------------------------------------------------------*/
658 643
659static void loopback_complete (struct usb_ep *ep, struct usb_request *req) 644static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
660{ 645{
661 struct zero_dev *dev = ep->driver_data; 646 struct zero_dev *dev = ep->driver_data;
662 int status = req->status; 647 int status = req->status;
@@ -668,19 +653,19 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
668 /* loop this OUT packet back IN to the host */ 653 /* loop this OUT packet back IN to the host */
669 req->zero = (req->actual < req->length); 654 req->zero = (req->actual < req->length);
670 req->length = req->actual; 655 req->length = req->actual;
671 status = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC); 656 status = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC);
672 if (status == 0) 657 if (status == 0)
673 return; 658 return;
674 659
675 /* "should never get here" */ 660 /* "should never get here" */
676 ERROR (dev, "can't loop %s to %s: %d\n", 661 ERROR(dev, "can't loop %s to %s: %d\n",
677 ep->name, dev->in_ep->name, 662 ep->name, dev->in_ep->name,
678 status); 663 status);
679 } 664 }
680 665
681 /* queue the buffer for some later OUT packet */ 666 /* queue the buffer for some later OUT packet */
682 req->length = buflen; 667 req->length = buflen;
683 status = usb_ep_queue (dev->out_ep, req, GFP_ATOMIC); 668 status = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
684 if (status == 0) 669 if (status == 0)
685 return; 670 return;
686 671
@@ -688,7 +673,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
688 /* FALLTHROUGH */ 673 /* FALLTHROUGH */
689 674
690 default: 675 default:
691 ERROR (dev, "%s loop complete --> %d, %d/%d\n", ep->name, 676 ERROR(dev, "%s loop complete --> %d, %d/%d\n", ep->name,
692 status, req->actual, req->length); 677 status, req->actual, req->length);
693 /* FALLTHROUGH */ 678 /* FALLTHROUGH */
694 679
@@ -700,7 +685,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
700 case -ECONNABORTED: /* hardware forced ep reset */ 685 case -ECONNABORTED: /* hardware forced ep reset */
701 case -ECONNRESET: /* request dequeued */ 686 case -ECONNRESET: /* request dequeued */
702 case -ESHUTDOWN: /* disconnect from host */ 687 case -ESHUTDOWN: /* disconnect from host */
703 free_ep_req (ep, req); 688 free_ep_req(ep, req);
704 return; 689 return;
705 } 690 }
706} 691}
@@ -711,13 +696,13 @@ static int set_loopback_config(struct zero_dev *dev)
711 struct usb_ep *ep; 696 struct usb_ep *ep;
712 struct usb_gadget *gadget = dev->gadget; 697 struct usb_gadget *gadget = dev->gadget;
713 698
714 gadget_for_each_ep (ep, gadget) { 699 gadget_for_each_ep(ep, gadget) {
715 const struct usb_endpoint_descriptor *d; 700 const struct usb_endpoint_descriptor *d;
716 701
717 /* one endpoint writes data back IN to the host */ 702 /* one endpoint writes data back IN to the host */
718 if (strcmp (ep->name, EP_IN_NAME) == 0) { 703 if (strcmp(ep->name, EP_IN_NAME) == 0) {
719 d = ep_desc (gadget, &hs_source_desc, &fs_source_desc); 704 d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
720 result = usb_ep_enable (ep, d); 705 result = usb_ep_enable(ep, d);
721 if (result == 0) { 706 if (result == 0) {
722 ep->driver_data = dev; 707 ep->driver_data = dev;
723 dev->in_ep = ep; 708 dev->in_ep = ep;
@@ -725,9 +710,9 @@ static int set_loopback_config(struct zero_dev *dev)
725 } 710 }
726 711
727 /* one endpoint just reads OUT packets */ 712 /* one endpoint just reads OUT packets */
728 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { 713 } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
729 d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc); 714 d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
730 result = usb_ep_enable (ep, d); 715 result = usb_ep_enable(ep, d);
731 if (result == 0) { 716 if (result == 0) {
732 ep->driver_data = dev; 717 ep->driver_data = dev;
733 dev->out_ep = ep; 718 dev->out_ep = ep;
@@ -739,7 +724,7 @@ static int set_loopback_config(struct zero_dev *dev)
739 continue; 724 continue;
740 725
741 /* stop on error */ 726 /* stop on error */
742 ERROR (dev, "can't enable %s, result %d\n", ep->name, result); 727 ERROR(dev, "can't enable %s, result %d\n", ep->name, result);
743 break; 728 break;
744 } 729 }
745 730
@@ -753,19 +738,19 @@ static int set_loopback_config(struct zero_dev *dev)
753 738
754 ep = dev->out_ep; 739 ep = dev->out_ep;
755 for (i = 0; i < qlen && result == 0; i++) { 740 for (i = 0; i < qlen && result == 0; i++) {
756 req = alloc_ep_req (ep, buflen); 741 req = alloc_ep_req(ep, buflen);
757 if (req) { 742 if (req) {
758 req->complete = loopback_complete; 743 req->complete = loopback_complete;
759 result = usb_ep_queue (ep, req, GFP_ATOMIC); 744 result = usb_ep_queue(ep, req, GFP_ATOMIC);
760 if (result) 745 if (result)
761 DBG (dev, "%s queue req --> %d\n", 746 DBG(dev, "%s queue req --> %d\n",
762 ep->name, result); 747 ep->name, result);
763 } else 748 } else
764 result = -ENOMEM; 749 result = -ENOMEM;
765 } 750 }
766 } 751 }
767 if (result == 0) 752 if (result == 0)
768 DBG (dev, "qlen %d, buflen %d\n", qlen, buflen); 753 DBG(dev, "qlen %d, buflen %d\n", qlen, buflen);
769 754
770 /* caller is responsible for cleanup on error */ 755 /* caller is responsible for cleanup on error */
771 return result; 756 return result;
@@ -773,26 +758,26 @@ static int set_loopback_config(struct zero_dev *dev)
773 758
774/*-------------------------------------------------------------------------*/ 759/*-------------------------------------------------------------------------*/
775 760
776static void zero_reset_config (struct zero_dev *dev) 761static void zero_reset_config(struct zero_dev *dev)
777{ 762{
778 if (dev->config == 0) 763 if (dev->config == 0)
779 return; 764 return;
780 765
781 DBG (dev, "reset config\n"); 766 DBG(dev, "reset config\n");
782 767
783 /* just disable endpoints, forcing completion of pending i/o. 768 /* just disable endpoints, forcing completion of pending i/o.
784 * all our completion handlers free their requests in this case. 769 * all our completion handlers free their requests in this case.
785 */ 770 */
786 if (dev->in_ep) { 771 if (dev->in_ep) {
787 usb_ep_disable (dev->in_ep); 772 usb_ep_disable(dev->in_ep);
788 dev->in_ep = NULL; 773 dev->in_ep = NULL;
789 } 774 }
790 if (dev->out_ep) { 775 if (dev->out_ep) {
791 usb_ep_disable (dev->out_ep); 776 usb_ep_disable(dev->out_ep);
792 dev->out_ep = NULL; 777 dev->out_ep = NULL;
793 } 778 }
794 dev->config = 0; 779 dev->config = 0;
795 del_timer (&dev->resume); 780 del_timer(&dev->resume);
796} 781}
797 782
798/* change our operational config. this code must agree with the code 783/* change our operational config. this code must agree with the code
@@ -813,12 +798,12 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
813 if (number == dev->config) 798 if (number == dev->config)
814 return 0; 799 return 0;
815 800
816 if (gadget_is_sa1100 (gadget) && dev->config) { 801 if (gadget_is_sa1100(gadget) && dev->config) {
817 /* tx fifo is full, but we can't clear it...*/ 802 /* tx fifo is full, but we can't clear it...*/
818 ERROR(dev, "can't change configurations\n"); 803 ERROR(dev, "can't change configurations\n");
819 return -ESPIPE; 804 return -ESPIPE;
820 } 805 }
821 zero_reset_config (dev); 806 zero_reset_config(dev);
822 807
823 switch (number) { 808 switch (number) {
824 case CONFIG_SOURCE_SINK: 809 case CONFIG_SOURCE_SINK:
@@ -837,7 +822,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
837 if (!result && (!dev->in_ep || !dev->out_ep)) 822 if (!result && (!dev->in_ep || !dev->out_ep))
838 result = -ENODEV; 823 result = -ENODEV;
839 if (result) 824 if (result)
840 zero_reset_config (dev); 825 zero_reset_config(dev);
841 else { 826 else {
842 char *speed; 827 char *speed;
843 828
@@ -849,7 +834,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
849 } 834 }
850 835
851 dev->config = number; 836 dev->config = number;
852 INFO (dev, "%s speed config #%d: %s\n", speed, number, 837 INFO(dev, "%s speed config #%d: %s\n", speed, number,
853 (number == CONFIG_SOURCE_SINK) 838 (number == CONFIG_SOURCE_SINK)
854 ? source_sink : loopback); 839 ? source_sink : loopback);
855 } 840 }
@@ -858,10 +843,10 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
858 843
859/*-------------------------------------------------------------------------*/ 844/*-------------------------------------------------------------------------*/
860 845
861static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req) 846static void zero_setup_complete(struct usb_ep *ep, struct usb_request *req)
862{ 847{
863 if (req->status || req->actual != req->length) 848 if (req->status || req->actual != req->length)
864 DBG ((struct zero_dev *) ep->driver_data, 849 DBG((struct zero_dev *) ep->driver_data,
865 "setup complete --> %d, %d/%d\n", 850 "setup complete --> %d, %d/%d\n",
866 req->status, req->actual, req->length); 851 req->status, req->actual, req->length);
867} 852}
@@ -874,9 +859,9 @@ static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
874 * the work is in config-specific setup. 859 * the work is in config-specific setup.
875 */ 860 */
876static int 861static int
877zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) 862zero_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
878{ 863{
879 struct zero_dev *dev = get_gadget_data (gadget); 864 struct zero_dev *dev = get_gadget_data(gadget);
880 struct usb_request *req = dev->req; 865 struct usb_request *req = dev->req;
881 int value = -EOPNOTSUPP; 866 int value = -EOPNOTSUPP;
882 u16 w_index = le16_to_cpu(ctrl->wIndex); 867 u16 w_index = le16_to_cpu(ctrl->wIndex);
@@ -895,14 +880,14 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
895 switch (w_value >> 8) { 880 switch (w_value >> 8) {
896 881
897 case USB_DT_DEVICE: 882 case USB_DT_DEVICE:
898 value = min (w_length, (u16) sizeof device_desc); 883 value = min(w_length, (u16) sizeof device_desc);
899 memcpy (req->buf, &device_desc, value); 884 memcpy(req->buf, &device_desc, value);
900 break; 885 break;
901 case USB_DT_DEVICE_QUALIFIER: 886 case USB_DT_DEVICE_QUALIFIER:
902 if (!gadget_is_dualspeed(gadget)) 887 if (!gadget_is_dualspeed(gadget))
903 break; 888 break;
904 value = min (w_length, (u16) sizeof dev_qualifier); 889 value = min(w_length, (u16) sizeof dev_qualifier);
905 memcpy (req->buf, &dev_qualifier, value); 890 memcpy(req->buf, &dev_qualifier, value);
906 break; 891 break;
907 892
908 case USB_DT_OTHER_SPEED_CONFIG: 893 case USB_DT_OTHER_SPEED_CONFIG:
@@ -910,11 +895,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
910 break; 895 break;
911 // FALLTHROUGH 896 // FALLTHROUGH
912 case USB_DT_CONFIG: 897 case USB_DT_CONFIG:
913 value = config_buf (gadget, req->buf, 898 value = config_buf(gadget, req->buf,
914 w_value >> 8, 899 w_value >> 8,
915 w_value & 0xff); 900 w_value & 0xff);
916 if (value >= 0) 901 if (value >= 0)
917 value = min (w_length, (u16) value); 902 value = min(w_length, (u16) value);
918 break; 903 break;
919 904
920 case USB_DT_STRING: 905 case USB_DT_STRING:
@@ -923,10 +908,10 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
923 * add string tables for other languages, using 908 * add string tables for other languages, using
924 * any UTF-8 characters 909 * any UTF-8 characters
925 */ 910 */
926 value = usb_gadget_get_string (&stringtab, 911 value = usb_gadget_get_string(&stringtab,
927 w_value & 0xff, req->buf); 912 w_value & 0xff, req->buf);
928 if (value >= 0) 913 if (value >= 0)
929 value = min (w_length, (u16) value); 914 value = min(w_length, (u16) value);
930 break; 915 break;
931 } 916 }
932 break; 917 break;
@@ -936,20 +921,20 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
936 if (ctrl->bRequestType != 0) 921 if (ctrl->bRequestType != 0)
937 goto unknown; 922 goto unknown;
938 if (gadget->a_hnp_support) 923 if (gadget->a_hnp_support)
939 DBG (dev, "HNP available\n"); 924 DBG(dev, "HNP available\n");
940 else if (gadget->a_alt_hnp_support) 925 else if (gadget->a_alt_hnp_support)
941 DBG (dev, "HNP needs a different root port\n"); 926 DBG(dev, "HNP needs a different root port\n");
942 else 927 else
943 VDBG (dev, "HNP inactive\n"); 928 VDBG(dev, "HNP inactive\n");
944 spin_lock (&dev->lock); 929 spin_lock(&dev->lock);
945 value = zero_set_config(dev, w_value); 930 value = zero_set_config(dev, w_value);
946 spin_unlock (&dev->lock); 931 spin_unlock(&dev->lock);
947 break; 932 break;
948 case USB_REQ_GET_CONFIGURATION: 933 case USB_REQ_GET_CONFIGURATION:
949 if (ctrl->bRequestType != USB_DIR_IN) 934 if (ctrl->bRequestType != USB_DIR_IN)
950 goto unknown; 935 goto unknown;
951 *(u8 *)req->buf = dev->config; 936 *(u8 *)req->buf = dev->config;
952 value = min (w_length, (u16) 1); 937 value = min(w_length, (u16) 1);
953 break; 938 break;
954 939
955 /* until we add altsetting support, or other interfaces, 940 /* until we add altsetting support, or other interfaces,
@@ -959,7 +944,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
959 case USB_REQ_SET_INTERFACE: 944 case USB_REQ_SET_INTERFACE:
960 if (ctrl->bRequestType != USB_RECIP_INTERFACE) 945 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
961 goto unknown; 946 goto unknown;
962 spin_lock (&dev->lock); 947 spin_lock(&dev->lock);
963 if (dev->config && w_index == 0 && w_value == 0) { 948 if (dev->config && w_index == 0 && w_value == 0) {
964 u8 config = dev->config; 949 u8 config = dev->config;
965 950
@@ -970,11 +955,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
970 * if we had more than one interface we couldn't 955 * if we had more than one interface we couldn't
971 * use this "reset the config" shortcut. 956 * use this "reset the config" shortcut.
972 */ 957 */
973 zero_reset_config (dev); 958 zero_reset_config(dev);
974 zero_set_config(dev, config); 959 zero_set_config(dev, config);
975 value = 0; 960 value = 0;
976 } 961 }
977 spin_unlock (&dev->lock); 962 spin_unlock(&dev->lock);
978 break; 963 break;
979 case USB_REQ_GET_INTERFACE: 964 case USB_REQ_GET_INTERFACE:
980 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) 965 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
@@ -986,7 +971,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
986 break; 971 break;
987 } 972 }
988 *(u8 *)req->buf = 0; 973 *(u8 *)req->buf = 0;
989 value = min (w_length, (u16) 1); 974 value = min(w_length, (u16) 1);
990 break; 975 break;
991 976
992 /* 977 /*
@@ -1018,7 +1003,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1018 1003
1019 default: 1004 default:
1020unknown: 1005unknown:
1021 VDBG (dev, 1006 VDBG(dev,
1022 "unknown control req%02x.%02x v%04x i%04x l%d\n", 1007 "unknown control req%02x.%02x v%04x i%04x l%d\n",
1023 ctrl->bRequestType, ctrl->bRequest, 1008 ctrl->bRequestType, ctrl->bRequest,
1024 w_value, w_index, w_length); 1009 w_value, w_index, w_length);
@@ -1028,11 +1013,11 @@ unknown:
1028 if (value >= 0) { 1013 if (value >= 0) {
1029 req->length = value; 1014 req->length = value;
1030 req->zero = value < w_length; 1015 req->zero = value < w_length;
1031 value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC); 1016 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1032 if (value < 0) { 1017 if (value < 0) {
1033 DBG (dev, "ep_queue --> %d\n", value); 1018 DBG(dev, "ep_queue --> %d\n", value);
1034 req->status = 0; 1019 req->status = 0;
1035 zero_setup_complete (gadget->ep0, req); 1020 zero_setup_complete(gadget->ep0, req);
1036 } 1021 }
1037 } 1022 }
1038 1023
@@ -1040,28 +1025,26 @@ unknown:
1040 return value; 1025 return value;
1041} 1026}
1042 1027
1043static void 1028static void zero_disconnect(struct usb_gadget *gadget)
1044zero_disconnect (struct usb_gadget *gadget)
1045{ 1029{
1046 struct zero_dev *dev = get_gadget_data (gadget); 1030 struct zero_dev *dev = get_gadget_data(gadget);
1047 unsigned long flags; 1031 unsigned long flags;
1048 1032
1049 spin_lock_irqsave (&dev->lock, flags); 1033 spin_lock_irqsave(&dev->lock, flags);
1050 zero_reset_config (dev); 1034 zero_reset_config(dev);
1051 1035
1052 /* a more significant application might have some non-usb 1036 /* a more significant application might have some non-usb
1053 * activities to quiesce here, saving resources like power 1037 * activities to quiesce here, saving resources like power
1054 * or pushing the notification up a network stack. 1038 * or pushing the notification up a network stack.
1055 */ 1039 */
1056 spin_unlock_irqrestore (&dev->lock, flags); 1040 spin_unlock_irqrestore(&dev->lock, flags);
1057 1041
1058 /* next we may get setup() calls to enumerate new connections; 1042 /* next we may get setup() calls to enumerate new connections;
1059 * or an unbind() during shutdown (including removing module). 1043 * or an unbind() during shutdown (including removing module).
1060 */ 1044 */
1061} 1045}
1062 1046
1063static void 1047static void zero_autoresume(unsigned long _dev)
1064zero_autoresume (unsigned long _dev)
1065{ 1048{
1066 struct zero_dev *dev = (struct zero_dev *) _dev; 1049 struct zero_dev *dev = (struct zero_dev *) _dev;
1067 int status; 1050 int status;
@@ -1070,32 +1053,30 @@ zero_autoresume (unsigned long _dev)
1070 * more significant than just a timer firing... 1053 * more significant than just a timer firing...
1071 */ 1054 */
1072 if (dev->gadget->speed != USB_SPEED_UNKNOWN) { 1055 if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
1073 status = usb_gadget_wakeup (dev->gadget); 1056 status = usb_gadget_wakeup(dev->gadget);
1074 DBG (dev, "wakeup --> %d\n", status); 1057 DBG(dev, "wakeup --> %d\n", status);
1075 } 1058 }
1076} 1059}
1077 1060
1078/*-------------------------------------------------------------------------*/ 1061/*-------------------------------------------------------------------------*/
1079 1062
1080static void /* __init_or_exit */ 1063static void zero_unbind(struct usb_gadget *gadget)
1081zero_unbind (struct usb_gadget *gadget)
1082{ 1064{
1083 struct zero_dev *dev = get_gadget_data (gadget); 1065 struct zero_dev *dev = get_gadget_data(gadget);
1084 1066
1085 DBG (dev, "unbind\n"); 1067 DBG(dev, "unbind\n");
1086 1068
1087 /* we've already been disconnected ... no i/o is active */ 1069 /* we've already been disconnected ... no i/o is active */
1088 if (dev->req) { 1070 if (dev->req) {
1089 dev->req->length = USB_BUFSIZ; 1071 dev->req->length = USB_BUFSIZ;
1090 free_ep_req (gadget->ep0, dev->req); 1072 free_ep_req(gadget->ep0, dev->req);
1091 } 1073 }
1092 del_timer_sync (&dev->resume); 1074 del_timer_sync(&dev->resume);
1093 kfree (dev); 1075 kfree(dev);
1094 set_gadget_data (gadget, NULL); 1076 set_gadget_data(gadget, NULL);
1095} 1077}
1096 1078
1097static int __init 1079static int __init zero_bind(struct usb_gadget *gadget)
1098zero_bind (struct usb_gadget *gadget)
1099{ 1080{
1100 struct zero_dev *dev; 1081 struct zero_dev *dev;
1101 struct usb_ep *ep; 1082 struct usb_ep *ep;
@@ -1111,8 +1092,8 @@ zero_bind (struct usb_gadget *gadget)
1111 * autoconfigure on any sane usb controller driver, 1092 * autoconfigure on any sane usb controller driver,
1112 * but there may also be important quirks to address. 1093 * but there may also be important quirks to address.
1113 */ 1094 */
1114 usb_ep_autoconfig_reset (gadget); 1095 usb_ep_autoconfig_reset(gadget);
1115 ep = usb_ep_autoconfig (gadget, &fs_source_desc); 1096 ep = usb_ep_autoconfig(gadget, &fs_source_desc);
1116 if (!ep) { 1097 if (!ep) {
1117autoconf_fail: 1098autoconf_fail:
1118 pr_err("%s: can't autoconfigure on %s\n", 1099 pr_err("%s: can't autoconfigure on %s\n",
@@ -1122,15 +1103,15 @@ autoconf_fail:
1122 EP_IN_NAME = ep->name; 1103 EP_IN_NAME = ep->name;
1123 ep->driver_data = ep; /* claim */ 1104 ep->driver_data = ep; /* claim */
1124 1105
1125 ep = usb_ep_autoconfig (gadget, &fs_sink_desc); 1106 ep = usb_ep_autoconfig(gadget, &fs_sink_desc);
1126 if (!ep) 1107 if (!ep)
1127 goto autoconf_fail; 1108 goto autoconf_fail;
1128 EP_OUT_NAME = ep->name; 1109 EP_OUT_NAME = ep->name;
1129 ep->driver_data = ep; /* claim */ 1110 ep->driver_data = ep; /* claim */
1130 1111
1131 gcnum = usb_gadget_controller_number (gadget); 1112 gcnum = usb_gadget_controller_number(gadget);
1132 if (gcnum >= 0) 1113 if (gcnum >= 0)
1133 device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum); 1114 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1134 else { 1115 else {
1135 /* gadget zero is so simple (for now, no altsettings) that 1116 /* gadget zero is so simple (for now, no altsettings) that
1136 * it SHOULD NOT have problems with bulk-capable hardware. 1117 * it SHOULD NOT have problems with bulk-capable hardware.
@@ -1141,7 +1122,7 @@ autoconf_fail:
1141 */ 1122 */
1142 pr_warning("%s: controller '%s' not recognized\n", 1123 pr_warning("%s: controller '%s' not recognized\n",
1143 shortname, gadget->name); 1124 shortname, gadget->name);
1144 device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999); 1125 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1145 } 1126 }
1146 1127
1147 1128
@@ -1149,12 +1130,16 @@ autoconf_fail:
1149 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1130 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1150 if (!dev) 1131 if (!dev)
1151 return -ENOMEM; 1132 return -ENOMEM;
1152 spin_lock_init (&dev->lock); 1133 spin_lock_init(&dev->lock);
1153 dev->gadget = gadget; 1134 dev->gadget = gadget;
1154 set_gadget_data (gadget, dev); 1135 set_gadget_data(gadget, dev);
1136
1137 init_timer(&dev->resume);
1138 dev->resume.function = zero_autoresume;
1139 dev->resume.data = (unsigned long) dev;
1155 1140
1156 /* preallocate control response and buffer */ 1141 /* preallocate control response and buffer */
1157 dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); 1142 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
1158 if (!dev->req) 1143 if (!dev->req)
1159 goto enomem; 1144 goto enomem;
1160 dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL); 1145 dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
@@ -1182,11 +1167,8 @@ autoconf_fail:
1182 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1167 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1183 } 1168 }
1184 1169
1185 usb_gadget_set_selfpowered (gadget); 1170 usb_gadget_set_selfpowered(gadget);
1186 1171
1187 init_timer (&dev->resume);
1188 dev->resume.function = zero_autoresume;
1189 dev->resume.data = (unsigned long) dev;
1190 if (autoresume) { 1172 if (autoresume) {
1191 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1173 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1192 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1174 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
@@ -1194,45 +1176,43 @@ autoconf_fail:
1194 1176
1195 gadget->ep0->driver_data = dev; 1177 gadget->ep0->driver_data = dev;
1196 1178
1197 INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname); 1179 INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
1198 INFO (dev, "using %s, OUT %s IN %s\n", gadget->name, 1180 INFO(dev, "using %s, OUT %s IN %s\n", gadget->name,
1199 EP_OUT_NAME, EP_IN_NAME); 1181 EP_OUT_NAME, EP_IN_NAME);
1200 1182
1201 snprintf (manufacturer, sizeof manufacturer, "%s %s with %s", 1183 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
1202 init_utsname()->sysname, init_utsname()->release, 1184 init_utsname()->sysname, init_utsname()->release,
1203 gadget->name); 1185 gadget->name);
1204 1186
1205 return 0; 1187 return 0;
1206 1188
1207enomem: 1189enomem:
1208 zero_unbind (gadget); 1190 zero_unbind(gadget);
1209 return -ENOMEM; 1191 return -ENOMEM;
1210} 1192}
1211 1193
1212/*-------------------------------------------------------------------------*/ 1194/*-------------------------------------------------------------------------*/
1213 1195
1214static void 1196static void zero_suspend(struct usb_gadget *gadget)
1215zero_suspend (struct usb_gadget *gadget)
1216{ 1197{
1217 struct zero_dev *dev = get_gadget_data (gadget); 1198 struct zero_dev *dev = get_gadget_data(gadget);
1218 1199
1219 if (gadget->speed == USB_SPEED_UNKNOWN) 1200 if (gadget->speed == USB_SPEED_UNKNOWN)
1220 return; 1201 return;
1221 1202
1222 if (autoresume) { 1203 if (autoresume) {
1223 mod_timer (&dev->resume, jiffies + (HZ * autoresume)); 1204 mod_timer(&dev->resume, jiffies + (HZ * autoresume));
1224 DBG (dev, "suspend, wakeup in %d seconds\n", autoresume); 1205 DBG(dev, "suspend, wakeup in %d seconds\n", autoresume);
1225 } else 1206 } else
1226 DBG (dev, "suspend\n"); 1207 DBG(dev, "suspend\n");
1227} 1208}
1228 1209
1229static void 1210static void zero_resume(struct usb_gadget *gadget)
1230zero_resume (struct usb_gadget *gadget)
1231{ 1211{
1232 struct zero_dev *dev = get_gadget_data (gadget); 1212 struct zero_dev *dev = get_gadget_data(gadget);
1233 1213
1234 DBG (dev, "resume\n"); 1214 DBG(dev, "resume\n");
1235 del_timer (&dev->resume); 1215 del_timer(&dev->resume);
1236} 1216}
1237 1217
1238 1218
@@ -1264,15 +1244,15 @@ MODULE_AUTHOR("David Brownell");
1264MODULE_LICENSE("GPL"); 1244MODULE_LICENSE("GPL");
1265 1245
1266 1246
1267static int __init init (void) 1247static int __init init(void)
1268{ 1248{
1269 return usb_gadget_register_driver (&zero_driver); 1249 return usb_gadget_register_driver(&zero_driver);
1270} 1250}
1271module_init (init); 1251module_init(init);
1272 1252
1273static void __exit cleanup (void) 1253static void __exit cleanup(void)
1274{ 1254{
1275 usb_gadget_unregister_driver (&zero_driver); 1255 usb_gadget_unregister_driver(&zero_driver);
1276} 1256}
1277module_exit (cleanup); 1257module_exit(cleanup);
1278 1258