aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/net2280.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/net2280.c')
-rw-r--r--drivers/usb/gadget/net2280.c159
1 files changed, 89 insertions, 70 deletions
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 1facdea56a8a..3bda37f9a35f 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -2,7 +2,7 @@
2 * Driver for the PLX NET2280 USB device controller. 2 * Driver for the PLX NET2280 USB device controller.
3 * Specs and errata are available from <http://www.plxtech.com>. 3 * Specs and errata are available from <http://www.plxtech.com>.
4 * 4 *
5 * PLX Technology Inc. (formerly NetChip Technology) supported the 5 * PLX Technology Inc. (formerly NetChip Technology) supported the
6 * development of this driver. 6 * development of this driver.
7 * 7 *
8 * 8 *
@@ -26,7 +26,8 @@
26 * Copyright (C) 2003 David Brownell 26 * Copyright (C) 2003 David Brownell
27 * Copyright (C) 2003-2005 PLX Technology, Inc. 27 * Copyright (C) 2003-2005 PLX Technology, Inc.
28 * 28 *
29 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility with 2282 chip 29 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility
30 * with 2282 chip
30 * 31 *
31 * This program is free software; you can redistribute it and/or modify 32 * This program is free software; you can redistribute it and/or modify
32 * it under the terms of the GNU General Public License as published by 33 * it under the terms of the GNU General Public License as published by
@@ -46,7 +47,6 @@
46#undef DEBUG /* messages on error and most fault paths */ 47#undef DEBUG /* messages on error and most fault paths */
47#undef VERBOSE /* extra debug messages (success too) */ 48#undef VERBOSE /* extra debug messages (success too) */
48 49
49#include <linux/config.h>
50#include <linux/module.h> 50#include <linux/module.h>
51#include <linux/pci.h> 51#include <linux/pci.h>
52#include <linux/dma-mapping.h> 52#include <linux/dma-mapping.h>
@@ -86,7 +86,7 @@ static const char driver_name [] = "net2280";
86static const char driver_desc [] = DRIVER_DESC; 86static const char driver_desc [] = DRIVER_DESC;
87 87
88static const char ep0name [] = "ep0"; 88static const char ep0name [] = "ep0";
89static const char *ep_name [] = { 89static const char *const ep_name [] = {
90 ep0name, 90 ep0name,
91 "ep-a", "ep-b", "ep-c", "ep-d", 91 "ep-a", "ep-b", "ep-c", "ep-d",
92 "ep-e", "ep-f", 92 "ep-e", "ep-f",
@@ -226,7 +226,9 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
226 if (!ep->is_in) 226 if (!ep->is_in)
227 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); 227 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
228 else if (dev->pdev->device != 0x2280) { 228 else if (dev->pdev->device != 0x2280) {
229 /* Added for 2282, Don't use nak packets on an in endpoint, this was ignored on 2280 */ 229 /* Added for 2282, Don't use nak packets on an in endpoint,
230 * this was ignored on 2280
231 */
230 writel ((1 << CLEAR_NAK_OUT_PACKETS) 232 writel ((1 << CLEAR_NAK_OUT_PACKETS)
231 | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp); 233 | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
232 } 234 }
@@ -289,7 +291,7 @@ static int handshake (u32 __iomem *ptr, u32 mask, u32 done, int usec)
289 return -ETIMEDOUT; 291 return -ETIMEDOUT;
290} 292}
291 293
292static struct usb_ep_ops net2280_ep_ops; 294static const struct usb_ep_ops net2280_ep_ops;
293 295
294static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep) 296static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)
295{ 297{
@@ -450,34 +452,15 @@ net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
450 452
451/*-------------------------------------------------------------------------*/ 453/*-------------------------------------------------------------------------*/
452 454
453#undef USE_KMALLOC 455/*
454 456 * dma-coherent memory allocation (for dma-capable endpoints)
455/* many common platforms have dma-coherent caches, which means that it's
456 * safe to use kmalloc() memory for all i/o buffers without using any
457 * cache flushing calls. (unless you're trying to share cache lines
458 * between dma and non-dma activities, which is a slow idea in any case.)
459 * 457 *
460 * other platforms need more care, with 2.5 having a moderately general 458 * NOTE: the dma_*_coherent() API calls suck. Most implementations are
461 * solution (which falls down for allocations smaller than one page) 459 * (a) page-oriented, so small buffers lose big; and (b) asymmetric with
462 * that improves significantly on the 2.4 PCI allocators by removing 460 * respect to calls with irqs disabled: alloc is safe, free is not.
463 * the restriction that memory never be freed in_interrupt(). 461 * We currently work around (b), but not (a).
464 */ 462 */
465#if defined(CONFIG_X86)
466#define USE_KMALLOC
467
468#elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
469#define USE_KMALLOC
470 463
471#elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
472#define USE_KMALLOC
473
474/* FIXME there are other cases, including an x86-64 one ... */
475#endif
476
477/* allocating buffers this way eliminates dma mapping overhead, which
478 * on some platforms will mean eliminating a per-io buffer copy. with
479 * some kinds of system caches, further tweaks may still be needed.
480 */
481static void * 464static void *
482net2280_alloc_buffer ( 465net2280_alloc_buffer (
483 struct usb_ep *_ep, 466 struct usb_ep *_ep,
@@ -494,43 +477,71 @@ net2280_alloc_buffer (
494 return NULL; 477 return NULL;
495 *dma = DMA_ADDR_INVALID; 478 *dma = DMA_ADDR_INVALID;
496 479
497#if defined(USE_KMALLOC) 480 if (ep->dma)
498 retval = kmalloc(bytes, gfp_flags);
499 if (retval)
500 *dma = virt_to_phys(retval);
501#else
502 if (ep->dma) {
503 /* the main problem with this call is that it wastes memory
504 * on typical 1/N page allocations: it allocates 1-N pages.
505 */
506#warning Using dma_alloc_coherent even with buffers smaller than a page.
507 retval = dma_alloc_coherent(&ep->dev->pdev->dev, 481 retval = dma_alloc_coherent(&ep->dev->pdev->dev,
508 bytes, dma, gfp_flags); 482 bytes, dma, gfp_flags);
509 } else 483 else
510 retval = kmalloc(bytes, gfp_flags); 484 retval = kmalloc(bytes, gfp_flags);
511#endif
512 return retval; 485 return retval;
513} 486}
514 487
488static DEFINE_SPINLOCK(buflock);
489static LIST_HEAD(buffers);
490
491struct free_record {
492 struct list_head list;
493 struct device *dev;
494 unsigned bytes;
495 dma_addr_t dma;
496};
497
498static void do_free(unsigned long ignored)
499{
500 spin_lock_irq(&buflock);
501 while (!list_empty(&buffers)) {
502 struct free_record *buf;
503
504 buf = list_entry(buffers.next, struct free_record, list);
505 list_del(&buf->list);
506 spin_unlock_irq(&buflock);
507
508 dma_free_coherent(buf->dev, buf->bytes, buf, buf->dma);
509
510 spin_lock_irq(&buflock);
511 }
512 spin_unlock_irq(&buflock);
513}
514
515static DECLARE_TASKLET(deferred_free, do_free, 0);
516
515static void 517static void
516net2280_free_buffer ( 518net2280_free_buffer (
517 struct usb_ep *_ep, 519 struct usb_ep *_ep,
518 void *buf, 520 void *address,
519 dma_addr_t dma, 521 dma_addr_t dma,
520 unsigned bytes 522 unsigned bytes
521) { 523) {
522 /* free memory into the right allocator */ 524 /* free memory into the right allocator */
523#ifndef USE_KMALLOC
524 if (dma != DMA_ADDR_INVALID) { 525 if (dma != DMA_ADDR_INVALID) {
525 struct net2280_ep *ep; 526 struct net2280_ep *ep;
527 struct free_record *buf = address;
528 unsigned long flags;
526 529
527 ep = container_of(_ep, struct net2280_ep, ep); 530 ep = container_of(_ep, struct net2280_ep, ep);
528 if (!_ep) 531 if (!_ep)
529 return; 532 return;
530 dma_free_coherent(&ep->dev->pdev->dev, bytes, buf, dma); 533
534 ep = container_of (_ep, struct net2280_ep, ep);
535 buf->dev = &ep->dev->pdev->dev;
536 buf->bytes = bytes;
537 buf->dma = dma;
538
539 spin_lock_irqsave(&buflock, flags);
540 list_add_tail(&buf->list, &buffers);
541 tasklet_schedule(&deferred_free);
542 spin_unlock_irqrestore(&buflock, flags);
531 } else 543 } else
532#endif 544 kfree (address);
533 kfree (buf);
534} 545}
535 546
536/*-------------------------------------------------------------------------*/ 547/*-------------------------------------------------------------------------*/
@@ -738,7 +749,8 @@ fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid)
738 */ 749 */
739 if (ep->is_in) 750 if (ep->is_in)
740 dmacount |= (1 << DMA_DIRECTION); 751 dmacount |= (1 << DMA_DIRECTION);
741 if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) || ep->dev->pdev->device != 0x2280) 752 if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0)
753 || ep->dev->pdev->device != 0x2280)
742 dmacount |= (1 << END_OF_CHAIN); 754 dmacount |= (1 << END_OF_CHAIN);
743 755
744 req->valid = valid; 756 req->valid = valid;
@@ -813,7 +825,7 @@ static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
813 825
814 /* previous OUT packet might have been short */ 826 /* previous OUT packet might have been short */
815 if (!ep->is_in && ((tmp = readl (&ep->regs->ep_stat)) 827 if (!ep->is_in && ((tmp = readl (&ep->regs->ep_stat))
816 & (1 << NAK_OUT_PACKETS)) != 0) { 828 & (1 << NAK_OUT_PACKETS)) != 0) {
817 writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT), 829 writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT),
818 &ep->regs->ep_stat); 830 &ep->regs->ep_stat);
819 831
@@ -1374,7 +1386,7 @@ net2280_fifo_flush (struct usb_ep *_ep)
1374 (void) readl (&ep->regs->ep_rsp); 1386 (void) readl (&ep->regs->ep_rsp);
1375} 1387}
1376 1388
1377static struct usb_ep_ops net2280_ep_ops = { 1389static const struct usb_ep_ops net2280_ep_ops = {
1378 .enable = net2280_enable, 1390 .enable = net2280_enable,
1379 .disable = net2280_disable, 1391 .disable = net2280_disable,
1380 1392
@@ -1632,7 +1644,7 @@ show_registers (struct device *_dev, struct device_attribute *attr, char *buf)
1632 } 1644 }
1633 1645
1634 /* Indexed Registers */ 1646 /* Indexed Registers */
1635 // none yet 1647 // none yet
1636 1648
1637 /* Statistics */ 1649 /* Statistics */
1638 t = scnprintf (next, size, "\nirqs: "); 1650 t = scnprintf (next, size, "\nirqs: ");
@@ -1692,11 +1704,11 @@ show_queues (struct device *_dev, struct device_attribute *attr, char *buf)
1692 ({ char *val; 1704 ({ char *val;
1693 switch (d->bmAttributes & 0x03) { 1705 switch (d->bmAttributes & 0x03) {
1694 case USB_ENDPOINT_XFER_BULK: 1706 case USB_ENDPOINT_XFER_BULK:
1695 val = "bulk"; break; 1707 val = "bulk"; break;
1696 case USB_ENDPOINT_XFER_INT: 1708 case USB_ENDPOINT_XFER_INT:
1697 val = "intr"; break; 1709 val = "intr"; break;
1698 default: 1710 default:
1699 val = "iso"; break; 1711 val = "iso"; break;
1700 }; val; }), 1712 }; val; }),
1701 le16_to_cpu (d->wMaxPacketSize) & 0x1fff, 1713 le16_to_cpu (d->wMaxPacketSize) & 0x1fff,
1702 ep->dma ? "dma" : "pio", ep->fifo_size 1714 ep->dma ? "dma" : "pio", ep->fifo_size
@@ -1809,8 +1821,8 @@ extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
1809 * net2280_set_fifo_mode - change allocation of fifo buffers 1821 * net2280_set_fifo_mode - change allocation of fifo buffers
1810 * @gadget: access to the net2280 device that will be updated 1822 * @gadget: access to the net2280 device that will be updated
1811 * @mode: 0 for default, four 1kB buffers (ep-a through ep-d); 1823 * @mode: 0 for default, four 1kB buffers (ep-a through ep-d);
1812 * 1 for two 2kB buffers (ep-a and ep-b only); 1824 * 1 for two 2kB buffers (ep-a and ep-b only);
1813 * 2 for one 2kB buffer (ep-a) and two 1kB ones (ep-b, ep-c). 1825 * 2 for one 2kB buffer (ep-a) and two 1kB ones (ep-b, ep-c).
1814 * 1826 *
1815 * returns zero on success, else negative errno. when this succeeds, 1827 * returns zero on success, else negative errno. when this succeeds,
1816 * the contents of gadget->ep_list may have changed. 1828 * the contents of gadget->ep_list may have changed.
@@ -2242,7 +2254,8 @@ static void handle_ep_small (struct net2280_ep *ep)
2242 req->td->dmacount = 0; 2254 req->td->dmacount = 0;
2243 t = readl (&ep->regs->ep_avail); 2255 t = readl (&ep->regs->ep_avail);
2244 dma_done (ep, req, count, 2256 dma_done (ep, req, count,
2245 (ep->out_overflow || t) ? -EOVERFLOW : 0); 2257 (ep->out_overflow || t)
2258 ? -EOVERFLOW : 0);
2246 } 2259 }
2247 2260
2248 /* also flush to prevent erratum 0106 trouble */ 2261 /* also flush to prevent erratum 0106 trouble */
@@ -2412,7 +2425,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2412 , &ep->regs->ep_stat); 2425 , &ep->regs->ep_stat);
2413 u.raw [0] = readl (&dev->usb->setup0123); 2426 u.raw [0] = readl (&dev->usb->setup0123);
2414 u.raw [1] = readl (&dev->usb->setup4567); 2427 u.raw [1] = readl (&dev->usb->setup4567);
2415 2428
2416 cpu_to_le32s (&u.raw [0]); 2429 cpu_to_le32s (&u.raw [0]);
2417 cpu_to_le32s (&u.raw [1]); 2430 cpu_to_le32s (&u.raw [1]);
2418 2431
@@ -2579,14 +2592,16 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2579 2592
2580 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set. 2593 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
2581 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRRUPT set and 2594 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRRUPT set and
2582 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT 2595 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
2583 * only indicates a change in the reset state). 2596 * only indicates a change in the reset state).
2584 */ 2597 */
2585 if (stat & tmp) { 2598 if (stat & tmp) {
2586 writel (tmp, &dev->regs->irqstat1); 2599 writel (tmp, &dev->regs->irqstat1);
2587 if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT)) && 2600 if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT))
2588 ((readl (&dev->usb->usbstat) & mask) == 0)) 2601 && ((readl (&dev->usb->usbstat) & mask)
2589 || ((readl (&dev->usb->usbctl) & (1 << VBUS_PIN)) == 0) 2602 == 0))
2603 || ((readl (&dev->usb->usbctl)
2604 & (1 << VBUS_PIN)) == 0)
2590 ) && ( dev->gadget.speed != USB_SPEED_UNKNOWN)) { 2605 ) && ( dev->gadget.speed != USB_SPEED_UNKNOWN)) {
2591 DEBUG (dev, "disconnect %s\n", 2606 DEBUG (dev, "disconnect %s\n",
2592 dev->driver->driver.name); 2607 dev->driver->driver.name);
@@ -2853,7 +2868,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2853 2868
2854 /* now all the pci goodies ... */ 2869 /* now all the pci goodies ... */
2855 if (pci_enable_device (pdev) < 0) { 2870 if (pci_enable_device (pdev) < 0) {
2856 retval = -ENODEV; 2871 retval = -ENODEV;
2857 goto done; 2872 goto done;
2858 } 2873 }
2859 dev->enabled = 1; 2874 dev->enabled = 1;
@@ -2871,6 +2886,10 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2871 } 2886 }
2872 dev->region = 1; 2887 dev->region = 1;
2873 2888
2889 /* FIXME provide firmware download interface to put
2890 * 8051 code into the chip, e.g. to turn on PCI PM.
2891 */
2892
2874 base = ioremap_nocache (resource, len); 2893 base = ioremap_nocache (resource, len);
2875 if (base == NULL) { 2894 if (base == NULL) {
2876 DEBUG (dev, "can't map memory\n"); 2895 DEBUG (dev, "can't map memory\n");
@@ -2896,7 +2915,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2896 goto done; 2915 goto done;
2897 } 2916 }
2898 2917
2899 if (request_irq (pdev->irq, net2280_irq, SA_SHIRQ, driver_name, dev) 2918 if (request_irq (pdev->irq, net2280_irq, IRQF_SHARED, driver_name, dev)
2900 != 0) { 2919 != 0) {
2901 ERROR (dev, "request interrupt %d failed\n", pdev->irq); 2920 ERROR (dev, "request interrupt %d failed\n", pdev->irq);
2902 retval = -EBUSY; 2921 retval = -EBUSY;
@@ -2985,16 +3004,16 @@ static void net2280_shutdown (struct pci_dev *pdev)
2985 3004
2986/*-------------------------------------------------------------------------*/ 3005/*-------------------------------------------------------------------------*/
2987 3006
2988static struct pci_device_id pci_ids [] = { { 3007static const struct pci_device_id pci_ids [] = { {
2989 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), 3008 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
2990 .class_mask = ~0, 3009 .class_mask = ~0,
2991 .vendor = 0x17cc, 3010 .vendor = 0x17cc,
2992 .device = 0x2280, 3011 .device = 0x2280,
2993 .subvendor = PCI_ANY_ID, 3012 .subvendor = PCI_ANY_ID,
2994 .subdevice = PCI_ANY_ID, 3013 .subdevice = PCI_ANY_ID,
2995}, { 3014}, {
2996 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), 3015 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
2997 .class_mask = ~0, 3016 .class_mask = ~0,
2998 .vendor = 0x17cc, 3017 .vendor = 0x17cc,
2999 .device = 0x2282, 3018 .device = 0x2282,
3000 .subvendor = PCI_ANY_ID, 3019 .subvendor = PCI_ANY_ID,