2 * Driver for the PLX NET2280 USB device controller.
3 * Specs and errata are available from <http://www.plxtech.com>.
5 * PLX Technology Inc. (formerly NetChip Technology) supported the
6 * development of this driver.
9 * CODE STATUS HIGHLIGHTS
11 * This driver should work well with most "gadget" drivers, including
12 * the File Storage, Serial, and Ethernet/RNDIS gadget drivers
13 * as well as Gadget Zero and Gadgetfs.
15 * DMA is enabled by default. Drivers using transfer queues might use
16 * DMA chaining to remove IRQ latencies between transfers. (Except when
17 * short OUT transfers happen.) Drivers can use the req->no_interrupt
18 * hint to completely eliminate some IRQs, if a later IRQ is guaranteed
19 * and DMA chaining is enabled.
21 * Note that almost all the errata workarounds here are only needed for
22 * rev1 chips. Rev1a silicon (0110) fixes almost all of them.
26 * Copyright (C) 2003 David Brownell
27 * Copyright (C) 2003-2005 PLX Technology, Inc.
29 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility with 2282 chip
31 * 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 * the Free Software Foundation; either version 2 of the License, or
34 * (at your option) any later version.
36 * This program is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with this program; if not, write to the Free Software
43 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 #undef DEBUG /* messages on error and most fault paths */
47 #undef VERBOSE /* extra debug messages (success too) */
49 #include <linux/module.h>
50 #include <linux/pci.h>
51 #include <linux/dma-mapping.h>
52 #include <linux/kernel.h>
53 #include <linux/delay.h>
54 #include <linux/ioport.h>
55 #include <linux/sched.h>
56 #include <linux/slab.h>
57 #include <linux/smp_lock.h>
58 #include <linux/errno.h>
59 #include <linux/init.h>
60 #include <linux/timer.h>
61 #include <linux/list.h>
62 #include <linux/interrupt.h>
63 #include <linux/moduleparam.h>
64 #include <linux/device.h>
65 #include <linux/usb_ch9.h>
66 #include <linux/usb_gadget.h>
68 #include <asm/byteorder.h>
71 #include <asm/system.h>
72 #include <asm/unaligned.h>
75 #define DRIVER_DESC "PLX NET228x USB Peripheral Controller"
76 #define DRIVER_VERSION "2005 Sept 27"
78 #define DMA_ADDR_INVALID (~(dma_addr_t)0)
79 #define EP_DONTUSE 13 /* nonzero */
81 #define USE_RDK_LEDS /* GPIO pins control three LEDs */
84 static const char driver_name
[] = "net2280";
85 static const char driver_desc
[] = DRIVER_DESC
;
87 static const char ep0name
[] = "ep0";
88 static const char *ep_name
[] = {
90 "ep-a", "ep-b", "ep-c", "ep-d",
94 /* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO)
95 * use_dma_chaining -- dma descriptor queueing gives even more irq reduction
97 * The net2280 DMA engines are not tightly integrated with their FIFOs;
98 * not all cases are (yet) handled well in this driver or the silicon.
99 * Some gadget drivers work better with the dma support here than others.
100 * These two parameters let you use PIO or more aggressive DMA.
102 static int use_dma
= 1;
103 static int use_dma_chaining
= 0;
105 /* "modprobe net2280 use_dma=n" etc */
106 module_param (use_dma
, bool, S_IRUGO
);
107 module_param (use_dma_chaining
, bool, S_IRUGO
);
110 /* mode 0 == ep-{a,b,c,d} 1K fifo each
111 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
112 * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
114 static ushort fifo_mode
= 0;
116 /* "modprobe net2280 fifo_mode=1" etc */
117 module_param (fifo_mode
, ushort
, 0644);
119 /* enable_suspend -- When enabled, the driver will respond to
120 * USB suspend requests by powering down the NET2280. Otherwise,
121 * USB suspend requests will be ignored. This is acceptible for
122 * self-powered devices
124 static int enable_suspend
= 0;
126 /* "modprobe net2280 enable_suspend=1" etc */
127 module_param (enable_suspend
, bool, S_IRUGO
);
130 #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
132 #if defined(CONFIG_USB_GADGET_DEBUG_FILES) || defined (DEBUG)
133 static char *type_string (u8 bmAttributes
)
135 switch ((bmAttributes
) & USB_ENDPOINT_XFERTYPE_MASK
) {
136 case USB_ENDPOINT_XFER_BULK
: return "bulk";
137 case USB_ENDPOINT_XFER_ISOC
: return "iso";
138 case USB_ENDPOINT_XFER_INT
: return "intr";
146 #define valid_bit __constant_cpu_to_le32 (1 << VALID_BIT)
147 #define dma_done_ie __constant_cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
149 /*-------------------------------------------------------------------------*/
152 net2280_enable (struct usb_ep
*_ep
, const struct usb_endpoint_descriptor
*desc
)
155 struct net2280_ep
*ep
;
159 ep
= container_of (_ep
, struct net2280_ep
, ep
);
160 if (!_ep
|| !desc
|| ep
->desc
|| _ep
->name
== ep0name
161 || desc
->bDescriptorType
!= USB_DT_ENDPOINT
)
164 if (!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
167 /* erratum 0119 workaround ties up an endpoint number */
168 if ((desc
->bEndpointAddress
& 0x0f) == EP_DONTUSE
)
171 /* sanity check ep-e/ep-f since their fifos are small */
172 max
= le16_to_cpu (desc
->wMaxPacketSize
) & 0x1fff;
173 if (ep
->num
> 4 && max
> 64)
176 spin_lock_irqsave (&dev
->lock
, flags
);
177 _ep
->maxpacket
= max
& 0x7ff;
180 /* ep_reset() has already been called */
182 ep
->out_overflow
= 0;
184 /* set speed-dependent max packet; may kick in high bandwidth */
185 set_idx_reg (dev
->regs
, REG_EP_MAXPKT (dev
, ep
->num
), max
);
187 /* FIFO lines can't go to different packets. PIO is ok, so
188 * use it instead of troublesome (non-bulk) multi-packet DMA.
190 if (ep
->dma
&& (max
% 4) != 0 && use_dma_chaining
) {
191 DEBUG (ep
->dev
, "%s, no dma for maxpacket %d\n",
192 ep
->ep
.name
, ep
->ep
.maxpacket
);
196 /* set type, direction, address; reset fifo counters */
197 writel ((1 << FIFO_FLUSH
), &ep
->regs
->ep_stat
);
198 tmp
= (desc
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
);
199 if (tmp
== USB_ENDPOINT_XFER_INT
) {
200 /* erratum 0105 workaround prevents hs NYET */
201 if (dev
->chiprev
== 0100
202 && dev
->gadget
.speed
== USB_SPEED_HIGH
203 && !(desc
->bEndpointAddress
& USB_DIR_IN
))
204 writel ((1 << CLEAR_NAK_OUT_PACKETS_MODE
),
206 } else if (tmp
== USB_ENDPOINT_XFER_BULK
) {
207 /* catch some particularly blatant driver bugs */
208 if ((dev
->gadget
.speed
== USB_SPEED_HIGH
210 || (dev
->gadget
.speed
== USB_SPEED_FULL
212 spin_unlock_irqrestore (&dev
->lock
, flags
);
216 ep
->is_iso
= (tmp
== USB_ENDPOINT_XFER_ISOC
) ? 1 : 0;
217 tmp
<<= ENDPOINT_TYPE
;
218 tmp
|= desc
->bEndpointAddress
;
219 tmp
|= (4 << ENDPOINT_BYTE_COUNT
); /* default full fifo lines */
220 tmp
|= 1 << ENDPOINT_ENABLE
;
223 /* for OUT transfers, block the rx fifo until a read is posted */
224 ep
->is_in
= (tmp
& USB_DIR_IN
) != 0;
226 writel ((1 << SET_NAK_OUT_PACKETS
), &ep
->regs
->ep_rsp
);
227 else if (dev
->pdev
->device
!= 0x2280) {
228 /* Added for 2282, Don't use nak packets on an in endpoint, this was ignored on 2280 */
229 writel ((1 << CLEAR_NAK_OUT_PACKETS
)
230 | (1 << CLEAR_NAK_OUT_PACKETS_MODE
), &ep
->regs
->ep_rsp
);
233 writel (tmp
, &ep
->regs
->ep_cfg
);
236 if (!ep
->dma
) { /* pio, per-packet */
237 tmp
= (1 << ep
->num
) | readl (&dev
->regs
->pciirqenb0
);
238 writel (tmp
, &dev
->regs
->pciirqenb0
);
240 tmp
= (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE
)
241 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE
);
242 if (dev
->pdev
->device
== 0x2280)
243 tmp
|= readl (&ep
->regs
->ep_irqenb
);
244 writel (tmp
, &ep
->regs
->ep_irqenb
);
245 } else { /* dma, per-request */
246 tmp
= (1 << (8 + ep
->num
)); /* completion */
247 tmp
|= readl (&dev
->regs
->pciirqenb1
);
248 writel (tmp
, &dev
->regs
->pciirqenb1
);
250 /* for short OUT transfers, dma completions can't
251 * advance the queue; do it pio-style, by hand.
252 * NOTE erratum 0112 workaround #2
254 if ((desc
->bEndpointAddress
& USB_DIR_IN
) == 0) {
255 tmp
= (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE
);
256 writel (tmp
, &ep
->regs
->ep_irqenb
);
258 tmp
= (1 << ep
->num
) | readl (&dev
->regs
->pciirqenb0
);
259 writel (tmp
, &dev
->regs
->pciirqenb0
);
263 tmp
= desc
->bEndpointAddress
;
264 DEBUG (dev
, "enabled %s (ep%d%s-%s) %s max %04x\n",
265 _ep
->name
, tmp
& 0x0f, DIR_STRING (tmp
),
266 type_string (desc
->bmAttributes
),
267 ep
->dma
? "dma" : "pio", max
);
269 /* pci writes may still be posted */
270 spin_unlock_irqrestore (&dev
->lock
, flags
);
274 static int handshake (u32 __iomem
*ptr
, u32 mask
, u32 done
, int usec
)
279 result
= readl (ptr
);
280 if (result
== ~(u32
)0) /* "device unplugged" */
291 static struct usb_ep_ops net2280_ep_ops
;
293 static void ep_reset (struct net2280_regs __iomem
*regs
, struct net2280_ep
*ep
)
298 INIT_LIST_HEAD (&ep
->queue
);
300 ep
->ep
.maxpacket
= ~0;
301 ep
->ep
.ops
= &net2280_ep_ops
;
303 /* disable the dma, irqs, endpoint... */
305 writel (0, &ep
->dma
->dmactl
);
306 writel ( (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT
)
307 | (1 << DMA_TRANSACTION_DONE_INTERRUPT
)
309 , &ep
->dma
->dmastat
);
311 tmp
= readl (®s
->pciirqenb0
);
312 tmp
&= ~(1 << ep
->num
);
313 writel (tmp
, ®s
->pciirqenb0
);
315 tmp
= readl (®s
->pciirqenb1
);
316 tmp
&= ~(1 << (8 + ep
->num
)); /* completion */
317 writel (tmp
, ®s
->pciirqenb1
);
319 writel (0, &ep
->regs
->ep_irqenb
);
321 /* init to our chosen defaults, notably so that we NAK OUT
322 * packets until the driver queues a read (+note erratum 0112)
324 if (!ep
->is_in
|| ep
->dev
->pdev
->device
== 0x2280) {
325 tmp
= (1 << SET_NAK_OUT_PACKETS_MODE
)
326 | (1 << SET_NAK_OUT_PACKETS
)
327 | (1 << CLEAR_EP_HIDE_STATUS_PHASE
)
328 | (1 << CLEAR_INTERRUPT_MODE
);
331 tmp
= (1 << CLEAR_NAK_OUT_PACKETS_MODE
)
332 | (1 << CLEAR_NAK_OUT_PACKETS
)
333 | (1 << CLEAR_EP_HIDE_STATUS_PHASE
)
334 | (1 << CLEAR_INTERRUPT_MODE
);
338 tmp
|= (1 << CLEAR_ENDPOINT_TOGGLE
)
339 | (1 << CLEAR_ENDPOINT_HALT
);
341 writel (tmp
, &ep
->regs
->ep_rsp
);
343 /* scrub most status bits, and flush any fifo state */
344 if (ep
->dev
->pdev
->device
== 0x2280)
345 tmp
= (1 << FIFO_OVERFLOW
)
346 | (1 << FIFO_UNDERFLOW
);
350 writel (tmp
| (1 << TIMEOUT
)
351 | (1 << USB_STALL_SENT
)
352 | (1 << USB_IN_NAK_SENT
)
353 | (1 << USB_IN_ACK_RCVD
)
354 | (1 << USB_OUT_PING_NAK_SENT
)
355 | (1 << USB_OUT_ACK_SENT
)
357 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT
)
358 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT
)
359 | (1 << DATA_PACKET_RECEIVED_INTERRUPT
)
360 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
)
361 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
362 | (1 << DATA_IN_TOKEN_INTERRUPT
)
363 , &ep
->regs
->ep_stat
);
365 /* fifo size is handled separately */
368 static void nuke (struct net2280_ep
*);
370 static int net2280_disable (struct usb_ep
*_ep
)
372 struct net2280_ep
*ep
;
375 ep
= container_of (_ep
, struct net2280_ep
, ep
);
376 if (!_ep
|| !ep
->desc
|| _ep
->name
== ep0name
)
379 spin_lock_irqsave (&ep
->dev
->lock
, flags
);
381 ep_reset (ep
->dev
->regs
, ep
);
383 VDEBUG (ep
->dev
, "disabled %s %s\n",
384 ep
->dma
? "dma" : "pio", _ep
->name
);
386 /* synch memory views with the device */
387 (void) readl (&ep
->regs
->ep_cfg
);
389 if (use_dma
&& !ep
->dma
&& ep
->num
>= 1 && ep
->num
<= 4)
390 ep
->dma
= &ep
->dev
->dma
[ep
->num
- 1];
392 spin_unlock_irqrestore (&ep
->dev
->lock
, flags
);
396 /*-------------------------------------------------------------------------*/
398 static struct usb_request
*
399 net2280_alloc_request (struct usb_ep
*_ep
, gfp_t gfp_flags
)
401 struct net2280_ep
*ep
;
402 struct net2280_request
*req
;
406 ep
= container_of (_ep
, struct net2280_ep
, ep
);
408 req
= kzalloc(sizeof(*req
), gfp_flags
);
412 req
->req
.dma
= DMA_ADDR_INVALID
;
413 INIT_LIST_HEAD (&req
->queue
);
415 /* this dma descriptor may be swapped with the previous dummy */
417 struct net2280_dma
*td
;
419 td
= pci_pool_alloc (ep
->dev
->requests
, gfp_flags
,
425 td
->dmacount
= 0; /* not VALID */
426 td
->dmaaddr
= __constant_cpu_to_le32 (DMA_ADDR_INVALID
);
427 td
->dmadesc
= td
->dmaaddr
;
434 net2280_free_request (struct usb_ep
*_ep
, struct usb_request
*_req
)
436 struct net2280_ep
*ep
;
437 struct net2280_request
*req
;
439 ep
= container_of (_ep
, struct net2280_ep
, ep
);
443 req
= container_of (_req
, struct net2280_request
, req
);
444 WARN_ON (!list_empty (&req
->queue
));
446 pci_pool_free (ep
->dev
->requests
, req
->td
, req
->td_dma
);
450 /*-------------------------------------------------------------------------*/
454 /* many common platforms have dma-coherent caches, which means that it's
455 * safe to use kmalloc() memory for all i/o buffers without using any
456 * cache flushing calls. (unless you're trying to share cache lines
457 * between dma and non-dma activities, which is a slow idea in any case.)
459 * other platforms need more care, with 2.5 having a moderately general
460 * solution (which falls down for allocations smaller than one page)
461 * that improves significantly on the 2.4 PCI allocators by removing
462 * the restriction that memory never be freed in_interrupt().
464 #if defined(CONFIG_X86)
467 #elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
470 #elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT)
473 /* FIXME there are other cases, including an x86-64 one ... */
476 /* allocating buffers this way eliminates dma mapping overhead, which
477 * on some platforms will mean eliminating a per-io buffer copy. with
478 * some kinds of system caches, further tweaks may still be needed.
481 net2280_alloc_buffer (
489 struct net2280_ep
*ep
;
491 ep
= container_of (_ep
, struct net2280_ep
, ep
);
494 *dma
= DMA_ADDR_INVALID
;
496 #if defined(USE_KMALLOC)
497 retval
= kmalloc(bytes
, gfp_flags
);
499 *dma
= virt_to_phys(retval
);
502 /* the main problem with this call is that it wastes memory
503 * on typical 1/N page allocations: it allocates 1-N pages.
505 #warning Using dma_alloc_coherent even with buffers smaller than a page.
506 retval
= dma_alloc_coherent(&ep
->dev
->pdev
->dev
,
507 bytes
, dma
, gfp_flags
);
509 retval
= kmalloc(bytes
, gfp_flags
);
515 net2280_free_buffer (
521 /* free memory into the right allocator */
523 if (dma
!= DMA_ADDR_INVALID
) {
524 struct net2280_ep
*ep
;
526 ep
= container_of(_ep
, struct net2280_ep
, ep
);
529 dma_free_coherent(&ep
->dev
->pdev
->dev
, bytes
, buf
, dma
);
535 /*-------------------------------------------------------------------------*/
537 /* load a packet into the fifo we use for usb IN transfers.
538 * works for all endpoints.
540 * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo
541 * at a time, but this code is simpler because it knows it only writes
542 * one packet. ep-a..ep-d should use dma instead.
545 write_fifo (struct net2280_ep
*ep
, struct usb_request
*req
)
547 struct net2280_ep_regs __iomem
*regs
= ep
->regs
;
550 unsigned count
, total
;
552 /* INVARIANT: fifo is currently empty. (testable) */
555 buf
= req
->buf
+ req
->actual
;
557 total
= req
->length
- req
->actual
;
563 /* write just one packet at a time */
564 count
= ep
->ep
.maxpacket
;
565 if (count
> total
) /* min() cannot be used on a bitfield */
568 VDEBUG (ep
->dev
, "write %s fifo (IN) %d bytes%s req %p\n",
570 (count
!= ep
->ep
.maxpacket
) ? " (short)" : "",
573 /* NOTE be careful if you try to align these. fifo lines
574 * should normally be full (4 bytes) and successive partial
575 * lines are ok only in certain cases.
577 tmp
= get_unaligned ((u32
*)buf
);
579 writel (tmp
, ®s
->ep_data
);
584 /* last fifo entry is "short" unless we wrote a full packet.
585 * also explicitly validate last word in (periodic) transfers
586 * when maxpacket is not a multiple of 4 bytes.
588 if (count
|| total
< ep
->ep
.maxpacket
) {
589 tmp
= count
? get_unaligned ((u32
*)buf
) : count
;
591 set_fifo_bytecount (ep
, count
& 0x03);
592 writel (tmp
, ®s
->ep_data
);
595 /* pci writes may still be posted */
598 /* work around erratum 0106: PCI and USB race over the OUT fifo.
599 * caller guarantees chiprev 0100, out endpoint is NAKing, and
600 * there's no real data in the fifo.
602 * NOTE: also used in cases where that erratum doesn't apply:
603 * where the host wrote "too much" data to us.
605 static void out_flush (struct net2280_ep
*ep
)
610 ASSERT_OUT_NAKING (ep
);
612 statp
= &ep
->regs
->ep_stat
;
613 writel ( (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
614 | (1 << DATA_PACKET_RECEIVED_INTERRUPT
)
616 writel ((1 << FIFO_FLUSH
), statp
);
619 if (tmp
& (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
620 /* high speed did bulk NYET; fifo isn't filling */
621 && ep
->dev
->gadget
.speed
== USB_SPEED_FULL
) {
624 usec
= 50; /* 64 byte bulk/interrupt */
625 handshake (statp
, (1 << USB_OUT_PING_NAK_SENT
),
626 (1 << USB_OUT_PING_NAK_SENT
), usec
);
627 /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
631 /* unload packet(s) from the fifo we use for usb OUT transfers.
632 * returns true iff the request completed, because of short packet
633 * or the request buffer having filled with full packets.
635 * for ep-a..ep-d this will read multiple packets out when they
636 * have been accepted.
639 read_fifo (struct net2280_ep
*ep
, struct net2280_request
*req
)
641 struct net2280_ep_regs __iomem
*regs
= ep
->regs
;
642 u8
*buf
= req
->req
.buf
+ req
->req
.actual
;
643 unsigned count
, tmp
, is_short
;
644 unsigned cleanup
= 0, prevent
= 0;
646 /* erratum 0106 ... packets coming in during fifo reads might
647 * be incompletely rejected. not all cases have workarounds.
649 if (ep
->dev
->chiprev
== 0x0100
650 && ep
->dev
->gadget
.speed
== USB_SPEED_FULL
) {
652 tmp
= readl (&ep
->regs
->ep_stat
);
653 if ((tmp
& (1 << NAK_OUT_PACKETS
)))
655 else if ((tmp
& (1 << FIFO_FULL
))) {
656 start_out_naking (ep
);
659 /* else: hope we don't see the problem */
662 /* never overflow the rx buffer. the fifo reads packets until
663 * it sees a short one; we might not be ready for them all.
666 count
= readl (®s
->ep_avail
);
667 if (unlikely (count
== 0)) {
669 tmp
= readl (&ep
->regs
->ep_stat
);
670 count
= readl (®s
->ep_avail
);
671 /* handled that data already? */
672 if (count
== 0 && (tmp
& (1 << NAK_OUT_PACKETS
)) == 0)
676 tmp
= req
->req
.length
- req
->req
.actual
;
678 /* as with DMA, data overflow gets flushed */
679 if ((tmp
% ep
->ep
.maxpacket
) != 0) {
681 "%s out fifo %d bytes, expected %d\n",
682 ep
->ep
.name
, count
, tmp
);
683 req
->req
.status
= -EOVERFLOW
;
685 /* NAK_OUT_PACKETS will be set, so flushing is safe;
686 * the next read will start with the next packet
688 } /* else it's a ZLP, no worries */
691 req
->req
.actual
+= count
;
693 is_short
= (count
== 0) || ((count
% ep
->ep
.maxpacket
) != 0);
695 VDEBUG (ep
->dev
, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
696 ep
->ep
.name
, count
, is_short
? " (short)" : "",
697 cleanup
? " flush" : "", prevent
? " nak" : "",
698 req
, req
->req
.actual
, req
->req
.length
);
701 tmp
= readl (®s
->ep_data
);
703 put_unaligned (tmp
, (u32
*)buf
);
708 tmp
= readl (®s
->ep_data
);
709 /* LE conversion is implicit here: */
718 writel ((1 << CLEAR_NAK_OUT_PACKETS
), &ep
->regs
->ep_rsp
);
719 (void) readl (&ep
->regs
->ep_rsp
);
722 return is_short
|| ((req
->req
.actual
== req
->req
.length
)
726 /* fill out dma descriptor to match a given request */
728 fill_dma_desc (struct net2280_ep
*ep
, struct net2280_request
*req
, int valid
)
730 struct net2280_dma
*td
= req
->td
;
731 u32 dmacount
= req
->req
.length
;
733 /* don't let DMA continue after a short OUT packet,
734 * so overruns can't affect the next transfer.
735 * in case of overruns on max-size packets, we can't
736 * stop the fifo from filling but we can flush it.
739 dmacount
|= (1 << DMA_DIRECTION
);
740 if ((!ep
->is_in
&& (dmacount
% ep
->ep
.maxpacket
) != 0) || ep
->dev
->pdev
->device
!= 0x2280)
741 dmacount
|= (1 << END_OF_CHAIN
);
745 dmacount
|= (1 << VALID_BIT
);
746 if (likely(!req
->req
.no_interrupt
|| !use_dma_chaining
))
747 dmacount
|= (1 << DMA_DONE_INTERRUPT_ENABLE
);
749 /* td->dmadesc = previously set by caller */
750 td
->dmaaddr
= cpu_to_le32 (req
->req
.dma
);
752 /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */
754 td
->dmacount
= cpu_to_le32p (&dmacount
);
757 static const u32 dmactl_default
=
758 (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT
)
759 | (1 << DMA_CLEAR_COUNT_ENABLE
)
760 /* erratum 0116 workaround part 1 (use POLLING) */
761 | (POLL_100_USEC
<< DESCRIPTOR_POLLING_RATE
)
762 | (1 << DMA_VALID_BIT_POLLING_ENABLE
)
763 | (1 << DMA_VALID_BIT_ENABLE
)
764 | (1 << DMA_SCATTER_GATHER_ENABLE
)
765 /* erratum 0116 workaround part 2 (no AUTOSTART) */
768 static inline void spin_stop_dma (struct net2280_dma_regs __iomem
*dma
)
770 handshake (&dma
->dmactl
, (1 << DMA_ENABLE
), 0, 50);
773 static inline void stop_dma (struct net2280_dma_regs __iomem
*dma
)
775 writel (readl (&dma
->dmactl
) & ~(1 << DMA_ENABLE
), &dma
->dmactl
);
779 static void start_queue (struct net2280_ep
*ep
, u32 dmactl
, u32 td_dma
)
781 struct net2280_dma_regs __iomem
*dma
= ep
->dma
;
782 unsigned int tmp
= (1 << VALID_BIT
) | (ep
->is_in
<< DMA_DIRECTION
);
784 if (ep
->dev
->pdev
->device
!= 0x2280)
785 tmp
|= (1 << END_OF_CHAIN
);
787 writel (tmp
, &dma
->dmacount
);
788 writel (readl (&dma
->dmastat
), &dma
->dmastat
);
790 writel (td_dma
, &dma
->dmadesc
);
791 writel (dmactl
, &dma
->dmactl
);
793 /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
794 (void) readl (&ep
->dev
->pci
->pcimstctl
);
796 writel ((1 << DMA_START
), &dma
->dmastat
);
799 stop_out_naking (ep
);
802 static void start_dma (struct net2280_ep
*ep
, struct net2280_request
*req
)
805 struct net2280_dma_regs __iomem
*dma
= ep
->dma
;
807 /* FIXME can't use DMA for ZLPs */
809 /* on this path we "know" there's no dma active (yet) */
810 WARN_ON (readl (&dma
->dmactl
) & (1 << DMA_ENABLE
));
811 writel (0, &ep
->dma
->dmactl
);
813 /* previous OUT packet might have been short */
814 if (!ep
->is_in
&& ((tmp
= readl (&ep
->regs
->ep_stat
))
815 & (1 << NAK_OUT_PACKETS
)) != 0) {
816 writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT
),
819 tmp
= readl (&ep
->regs
->ep_avail
);
821 writel (readl (&dma
->dmastat
), &dma
->dmastat
);
823 /* transfer all/some fifo data */
824 writel (req
->req
.dma
, &dma
->dmaaddr
);
825 tmp
= min (tmp
, req
->req
.length
);
827 /* dma irq, faking scatterlist status */
828 req
->td
->dmacount
= cpu_to_le32 (req
->req
.length
- tmp
);
829 writel ((1 << DMA_DONE_INTERRUPT_ENABLE
)
830 | tmp
, &dma
->dmacount
);
831 req
->td
->dmadesc
= 0;
834 writel ((1 << DMA_ENABLE
), &dma
->dmactl
);
835 writel ((1 << DMA_START
), &dma
->dmastat
);
840 tmp
= dmactl_default
;
842 /* force packet boundaries between dma requests, but prevent the
843 * controller from automagically writing a last "short" packet
844 * (zero length) unless the driver explicitly said to do that.
847 if (likely ((req
->req
.length
% ep
->ep
.maxpacket
) != 0
849 tmp
|= (1 << DMA_FIFO_VALIDATE
);
850 ep
->in_fifo_validate
= 1;
852 ep
->in_fifo_validate
= 0;
855 /* init req->td, pointing to the current dummy */
856 req
->td
->dmadesc
= cpu_to_le32 (ep
->td_dma
);
857 fill_dma_desc (ep
, req
, 1);
859 if (!use_dma_chaining
)
860 req
->td
->dmacount
|= __constant_cpu_to_le32 (1 << END_OF_CHAIN
);
862 start_queue (ep
, tmp
, req
->td_dma
);
866 queue_dma (struct net2280_ep
*ep
, struct net2280_request
*req
, int valid
)
868 struct net2280_dma
*end
;
871 /* swap new dummy for old, link; fill and maybe activate */
877 ep
->td_dma
= req
->td_dma
;
880 end
->dmadesc
= cpu_to_le32 (ep
->td_dma
);
882 fill_dma_desc (ep
, req
, valid
);
886 done (struct net2280_ep
*ep
, struct net2280_request
*req
, int status
)
889 unsigned stopped
= ep
->stopped
;
891 list_del_init (&req
->queue
);
893 if (req
->req
.status
== -EINPROGRESS
)
894 req
->req
.status
= status
;
896 status
= req
->req
.status
;
900 pci_unmap_single (dev
->pdev
, req
->req
.dma
, req
->req
.length
,
901 ep
->is_in
? PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
);
902 req
->req
.dma
= DMA_ADDR_INVALID
;
906 if (status
&& status
!= -ESHUTDOWN
)
907 VDEBUG (dev
, "complete %s req %p stat %d len %u/%u\n",
908 ep
->ep
.name
, &req
->req
, status
,
909 req
->req
.actual
, req
->req
.length
);
911 /* don't modify queue heads during completion callback */
913 spin_unlock (&dev
->lock
);
914 req
->req
.complete (&ep
->ep
, &req
->req
);
915 spin_lock (&dev
->lock
);
916 ep
->stopped
= stopped
;
919 /*-------------------------------------------------------------------------*/
922 net2280_queue (struct usb_ep
*_ep
, struct usb_request
*_req
, gfp_t gfp_flags
)
924 struct net2280_request
*req
;
925 struct net2280_ep
*ep
;
929 /* we always require a cpu-view buffer, so that we can
930 * always use pio (as fallback or whatever).
932 req
= container_of (_req
, struct net2280_request
, req
);
933 if (!_req
|| !_req
->complete
|| !_req
->buf
934 || !list_empty (&req
->queue
))
936 if (_req
->length
> (~0 & DMA_BYTE_COUNT_MASK
))
938 ep
= container_of (_ep
, struct net2280_ep
, ep
);
939 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0))
942 if (!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
945 /* FIXME implement PIO fallback for ZLPs with DMA */
946 if (ep
->dma
&& _req
->length
== 0)
949 /* set up dma mapping in case the caller didn't */
950 if (ep
->dma
&& _req
->dma
== DMA_ADDR_INVALID
) {
951 _req
->dma
= pci_map_single (dev
->pdev
, _req
->buf
, _req
->length
,
952 ep
->is_in
? PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
);
957 VDEBUG (dev
, "%s queue req %p, len %d buf %p\n",
958 _ep
->name
, _req
, _req
->length
, _req
->buf
);
961 spin_lock_irqsave (&dev
->lock
, flags
);
963 _req
->status
= -EINPROGRESS
;
966 /* kickstart this i/o queue? */
967 if (list_empty (&ep
->queue
) && !ep
->stopped
) {
968 /* use DMA if the endpoint supports it, else pio */
972 /* maybe there's no control data, just status ack */
973 if (ep
->num
== 0 && _req
->length
== 0) {
976 VDEBUG (dev
, "%s status ack\n", ep
->ep
.name
);
980 /* PIO ... stuff the fifo, or unblock it. */
982 write_fifo (ep
, _req
);
983 else if (list_empty (&ep
->queue
)) {
986 /* OUT FIFO might have packet(s) buffered */
987 s
= readl (&ep
->regs
->ep_stat
);
988 if ((s
& (1 << FIFO_EMPTY
)) == 0) {
989 /* note: _req->short_not_ok is
990 * ignored here since PIO _always_
991 * stops queue advance here, and
992 * _req->status doesn't change for
993 * short reads (only _req->actual)
995 if (read_fifo (ep
, req
)) {
1002 s
= readl (&ep
->regs
->ep_stat
);
1005 /* don't NAK, let the fifo fill */
1006 if (req
&& (s
& (1 << NAK_OUT_PACKETS
)))
1007 writel ((1 << CLEAR_NAK_OUT_PACKETS
),
1012 } else if (ep
->dma
) {
1018 /* preventing magic zlps is per-engine state, not
1019 * per-transfer; irq logic must recover hiccups.
1021 expect
= likely (req
->req
.zero
1022 || (req
->req
.length
% ep
->ep
.maxpacket
) != 0);
1023 if (expect
!= ep
->in_fifo_validate
)
1026 queue_dma (ep
, req
, valid
);
1028 } /* else the irq handler advances the queue. */
1031 list_add_tail (&req
->queue
, &ep
->queue
);
1033 spin_unlock_irqrestore (&dev
->lock
, flags
);
1035 /* pci writes may still be posted */
1041 struct net2280_ep
*ep
,
1042 struct net2280_request
*req
,
1047 req
->req
.actual
= req
->req
.length
- (DMA_BYTE_COUNT_MASK
& dmacount
);
1048 done (ep
, req
, status
);
1051 static void restart_dma (struct net2280_ep
*ep
);
1053 static void scan_dma_completions (struct net2280_ep
*ep
)
1055 /* only look at descriptors that were "naturally" retired,
1056 * so fifo and list head state won't matter
1058 while (!list_empty (&ep
->queue
)) {
1059 struct net2280_request
*req
;
1062 req
= list_entry (ep
->queue
.next
,
1063 struct net2280_request
, queue
);
1067 tmp
= le32_to_cpup (&req
->td
->dmacount
);
1068 if ((tmp
& (1 << VALID_BIT
)) != 0)
1071 /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
1072 * cases where DMA must be aborted; this code handles
1073 * all non-abort DMA completions.
1075 if (unlikely (req
->td
->dmadesc
== 0)) {
1077 tmp
= readl (&ep
->dma
->dmacount
);
1078 if (tmp
& DMA_BYTE_COUNT_MASK
)
1080 /* single transfer mode */
1081 dma_done (ep
, req
, tmp
, 0);
1083 } else if (!ep
->is_in
1084 && (req
->req
.length
% ep
->ep
.maxpacket
) != 0) {
1085 tmp
= readl (&ep
->regs
->ep_stat
);
1087 /* AVOID TROUBLE HERE by not issuing short reads from
1088 * your gadget driver. That helps avoids errata 0121,
1089 * 0122, and 0124; not all cases trigger the warning.
1091 if ((tmp
& (1 << NAK_OUT_PACKETS
)) == 0) {
1092 WARN (ep
->dev
, "%s lost packet sync!\n",
1094 req
->req
.status
= -EOVERFLOW
;
1095 } else if ((tmp
= readl (&ep
->regs
->ep_avail
)) != 0) {
1096 /* fifo gets flushed later */
1097 ep
->out_overflow
= 1;
1098 DEBUG (ep
->dev
, "%s dma, discard %d len %d\n",
1101 req
->req
.status
= -EOVERFLOW
;
1104 dma_done (ep
, req
, tmp
, 0);
1108 static void restart_dma (struct net2280_ep
*ep
)
1110 struct net2280_request
*req
;
1111 u32 dmactl
= dmactl_default
;
1115 req
= list_entry (ep
->queue
.next
, struct net2280_request
, queue
);
1117 if (!use_dma_chaining
) {
1118 start_dma (ep
, req
);
1122 /* the 2280 will be processing the queue unless queue hiccups after
1123 * the previous transfer:
1124 * IN: wanted automagic zlp, head doesn't (or vice versa)
1125 * DMA_FIFO_VALIDATE doesn't init from dma descriptors.
1126 * OUT: was "usb-short", we must restart.
1128 if (ep
->is_in
&& !req
->valid
) {
1129 struct net2280_request
*entry
, *prev
= NULL
;
1130 int reqmode
, done
= 0;
1132 DEBUG (ep
->dev
, "%s dma hiccup td %p\n", ep
->ep
.name
, req
->td
);
1133 ep
->in_fifo_validate
= likely (req
->req
.zero
1134 || (req
->req
.length
% ep
->ep
.maxpacket
) != 0);
1135 if (ep
->in_fifo_validate
)
1136 dmactl
|= (1 << DMA_FIFO_VALIDATE
);
1137 list_for_each_entry (entry
, &ep
->queue
, queue
) {
1142 dmacount
= entry
->td
->dmacount
;
1144 reqmode
= likely (entry
->req
.zero
1145 || (entry
->req
.length
1146 % ep
->ep
.maxpacket
) != 0);
1147 if (reqmode
== ep
->in_fifo_validate
) {
1149 dmacount
|= valid_bit
;
1150 entry
->td
->dmacount
= dmacount
;
1154 /* force a hiccup */
1155 prev
->td
->dmacount
|= dma_done_ie
;
1160 /* walk the rest of the queue so unlinks behave */
1162 dmacount
&= ~valid_bit
;
1163 entry
->td
->dmacount
= dmacount
;
1168 writel (0, &ep
->dma
->dmactl
);
1169 start_queue (ep
, dmactl
, req
->td_dma
);
1172 static void abort_dma (struct net2280_ep
*ep
)
1174 /* abort the current transfer */
1175 if (likely (!list_empty (&ep
->queue
))) {
1176 /* FIXME work around errata 0121, 0122, 0124 */
1177 writel ((1 << DMA_ABORT
), &ep
->dma
->dmastat
);
1178 spin_stop_dma (ep
->dma
);
1181 scan_dma_completions (ep
);
1184 /* dequeue ALL requests */
1185 static void nuke (struct net2280_ep
*ep
)
1187 struct net2280_request
*req
;
1189 /* called with spinlock held */
1193 while (!list_empty (&ep
->queue
)) {
1194 req
= list_entry (ep
->queue
.next
,
1195 struct net2280_request
,
1197 done (ep
, req
, -ESHUTDOWN
);
1201 /* dequeue JUST ONE request */
1202 static int net2280_dequeue (struct usb_ep
*_ep
, struct usb_request
*_req
)
1204 struct net2280_ep
*ep
;
1205 struct net2280_request
*req
;
1206 unsigned long flags
;
1210 ep
= container_of (_ep
, struct net2280_ep
, ep
);
1211 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0) || !_req
)
1214 spin_lock_irqsave (&ep
->dev
->lock
, flags
);
1215 stopped
= ep
->stopped
;
1217 /* quiesce dma while we patch the queue */
1221 dmactl
= readl (&ep
->dma
->dmactl
);
1222 /* WARNING erratum 0127 may kick in ... */
1224 scan_dma_completions (ep
);
1227 /* make sure it's still queued on this endpoint */
1228 list_for_each_entry (req
, &ep
->queue
, queue
) {
1229 if (&req
->req
== _req
)
1232 if (&req
->req
!= _req
) {
1233 spin_unlock_irqrestore (&ep
->dev
->lock
, flags
);
1237 /* queue head may be partially complete. */
1238 if (ep
->queue
.next
== &req
->queue
) {
1240 DEBUG (ep
->dev
, "unlink (%s) dma\n", _ep
->name
);
1241 _req
->status
= -ECONNRESET
;
1243 if (likely (ep
->queue
.next
== &req
->queue
)) {
1244 // NOTE: misreports single-transfer mode
1245 req
->td
->dmacount
= 0; /* invalidate */
1247 readl (&ep
->dma
->dmacount
),
1251 DEBUG (ep
->dev
, "unlink (%s) pio\n", _ep
->name
);
1252 done (ep
, req
, -ECONNRESET
);
1256 /* patch up hardware chaining data */
1257 } else if (ep
->dma
&& use_dma_chaining
) {
1258 if (req
->queue
.prev
== ep
->queue
.next
) {
1259 writel (le32_to_cpu (req
->td
->dmadesc
),
1261 if (req
->td
->dmacount
& dma_done_ie
)
1262 writel (readl (&ep
->dma
->dmacount
)
1263 | le32_to_cpu(dma_done_ie
),
1264 &ep
->dma
->dmacount
);
1266 struct net2280_request
*prev
;
1268 prev
= list_entry (req
->queue
.prev
,
1269 struct net2280_request
, queue
);
1270 prev
->td
->dmadesc
= req
->td
->dmadesc
;
1271 if (req
->td
->dmacount
& dma_done_ie
)
1272 prev
->td
->dmacount
|= dma_done_ie
;
1277 done (ep
, req
, -ECONNRESET
);
1278 ep
->stopped
= stopped
;
1281 /* turn off dma on inactive queues */
1282 if (list_empty (&ep
->queue
))
1284 else if (!ep
->stopped
) {
1285 /* resume current request, or start new one */
1287 writel (dmactl
, &ep
->dma
->dmactl
);
1289 start_dma (ep
, list_entry (ep
->queue
.next
,
1290 struct net2280_request
, queue
));
1294 spin_unlock_irqrestore (&ep
->dev
->lock
, flags
);
1298 /*-------------------------------------------------------------------------*/
1300 static int net2280_fifo_status (struct usb_ep
*_ep
);
1303 net2280_set_halt (struct usb_ep
*_ep
, int value
)
1305 struct net2280_ep
*ep
;
1306 unsigned long flags
;
1309 ep
= container_of (_ep
, struct net2280_ep
, ep
);
1310 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0))
1312 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1314 if (ep
->desc
/* not ep0 */ && (ep
->desc
->bmAttributes
& 0x03)
1315 == USB_ENDPOINT_XFER_ISOC
)
1318 spin_lock_irqsave (&ep
->dev
->lock
, flags
);
1319 if (!list_empty (&ep
->queue
))
1321 else if (ep
->is_in
&& value
&& net2280_fifo_status (_ep
) != 0)
1324 VDEBUG (ep
->dev
, "%s %s halt\n", _ep
->name
,
1325 value
? "set" : "clear");
1326 /* set/clear, then synch memory views with the device */
1329 ep
->dev
->protocol_stall
= 1;
1334 (void) readl (&ep
->regs
->ep_rsp
);
1336 spin_unlock_irqrestore (&ep
->dev
->lock
, flags
);
1342 net2280_fifo_status (struct usb_ep
*_ep
)
1344 struct net2280_ep
*ep
;
1347 ep
= container_of (_ep
, struct net2280_ep
, ep
);
1348 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0))
1350 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1353 avail
= readl (&ep
->regs
->ep_avail
) & ((1 << 12) - 1);
1354 if (avail
> ep
->fifo_size
)
1357 avail
= ep
->fifo_size
- avail
;
1362 net2280_fifo_flush (struct usb_ep
*_ep
)
1364 struct net2280_ep
*ep
;
1366 ep
= container_of (_ep
, struct net2280_ep
, ep
);
1367 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0))
1369 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1372 writel ((1 << FIFO_FLUSH
), &ep
->regs
->ep_stat
);
1373 (void) readl (&ep
->regs
->ep_rsp
);
1376 static struct usb_ep_ops net2280_ep_ops
= {
1377 .enable
= net2280_enable
,
1378 .disable
= net2280_disable
,
1380 .alloc_request
= net2280_alloc_request
,
1381 .free_request
= net2280_free_request
,
1383 .alloc_buffer
= net2280_alloc_buffer
,
1384 .free_buffer
= net2280_free_buffer
,
1386 .queue
= net2280_queue
,
1387 .dequeue
= net2280_dequeue
,
1389 .set_halt
= net2280_set_halt
,
1390 .fifo_status
= net2280_fifo_status
,
1391 .fifo_flush
= net2280_fifo_flush
,
1394 /*-------------------------------------------------------------------------*/
1396 static int net2280_get_frame (struct usb_gadget
*_gadget
)
1398 struct net2280
*dev
;
1399 unsigned long flags
;
1404 dev
= container_of (_gadget
, struct net2280
, gadget
);
1405 spin_lock_irqsave (&dev
->lock
, flags
);
1406 retval
= get_idx_reg (dev
->regs
, REG_FRAME
) & 0x03ff;
1407 spin_unlock_irqrestore (&dev
->lock
, flags
);
1411 static int net2280_wakeup (struct usb_gadget
*_gadget
)
1413 struct net2280
*dev
;
1415 unsigned long flags
;
1419 dev
= container_of (_gadget
, struct net2280
, gadget
);
1421 spin_lock_irqsave (&dev
->lock
, flags
);
1422 tmp
= readl (&dev
->usb
->usbctl
);
1423 if (tmp
& (1 << DEVICE_REMOTE_WAKEUP_ENABLE
))
1424 writel (1 << GENERATE_RESUME
, &dev
->usb
->usbstat
);
1425 spin_unlock_irqrestore (&dev
->lock
, flags
);
1427 /* pci writes may still be posted */
1431 static int net2280_set_selfpowered (struct usb_gadget
*_gadget
, int value
)
1433 struct net2280
*dev
;
1435 unsigned long flags
;
1439 dev
= container_of (_gadget
, struct net2280
, gadget
);
1441 spin_lock_irqsave (&dev
->lock
, flags
);
1442 tmp
= readl (&dev
->usb
->usbctl
);
1444 tmp
|= (1 << SELF_POWERED_STATUS
);
1446 tmp
&= ~(1 << SELF_POWERED_STATUS
);
1447 writel (tmp
, &dev
->usb
->usbctl
);
1448 spin_unlock_irqrestore (&dev
->lock
, flags
);
1453 static int net2280_pullup(struct usb_gadget
*_gadget
, int is_on
)
1455 struct net2280
*dev
;
1457 unsigned long flags
;
1461 dev
= container_of (_gadget
, struct net2280
, gadget
);
1463 spin_lock_irqsave (&dev
->lock
, flags
);
1464 tmp
= readl (&dev
->usb
->usbctl
);
1465 dev
->softconnect
= (is_on
!= 0);
1467 tmp
|= (1 << USB_DETECT_ENABLE
);
1469 tmp
&= ~(1 << USB_DETECT_ENABLE
);
1470 writel (tmp
, &dev
->usb
->usbctl
);
1471 spin_unlock_irqrestore (&dev
->lock
, flags
);
1476 static const struct usb_gadget_ops net2280_ops
= {
1477 .get_frame
= net2280_get_frame
,
1478 .wakeup
= net2280_wakeup
,
1479 .set_selfpowered
= net2280_set_selfpowered
,
1480 .pullup
= net2280_pullup
,
1483 /*-------------------------------------------------------------------------*/
1485 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1487 /* FIXME move these into procfs, and use seq_file.
1488 * Sysfs _still_ doesn't behave for arbitrarily sized files,
1489 * and also doesn't help products using this with 2.4 kernels.
1492 /* "function" sysfs attribute */
1494 show_function (struct device
*_dev
, struct device_attribute
*attr
, char *buf
)
1496 struct net2280
*dev
= dev_get_drvdata (_dev
);
1499 || !dev
->driver
->function
1500 || strlen (dev
->driver
->function
) > PAGE_SIZE
)
1502 return scnprintf (buf
, PAGE_SIZE
, "%s\n", dev
->driver
->function
);
1504 static DEVICE_ATTR (function
, S_IRUGO
, show_function
, NULL
);
1507 show_registers (struct device
*_dev
, struct device_attribute
*attr
, char *buf
)
1509 struct net2280
*dev
;
1512 unsigned long flags
;
1517 dev
= dev_get_drvdata (_dev
);
1520 spin_lock_irqsave (&dev
->lock
, flags
);
1523 s
= dev
->driver
->driver
.name
;
1527 /* Main Control Registers */
1528 t
= scnprintf (next
, size
, "%s version " DRIVER_VERSION
1529 ", chiprev %04x, dma %s\n\n"
1530 "devinit %03x fifoctl %08x gadget '%s'\n"
1531 "pci irqenb0 %02x irqenb1 %08x "
1532 "irqstat0 %04x irqstat1 %08x\n",
1533 driver_name
, dev
->chiprev
,
1535 ? (use_dma_chaining
? "chaining" : "enabled")
1537 readl (&dev
->regs
->devinit
),
1538 readl (&dev
->regs
->fifoctl
),
1540 readl (&dev
->regs
->pciirqenb0
),
1541 readl (&dev
->regs
->pciirqenb1
),
1542 readl (&dev
->regs
->irqstat0
),
1543 readl (&dev
->regs
->irqstat1
));
1547 /* USB Control Registers */
1548 t1
= readl (&dev
->usb
->usbctl
);
1549 t2
= readl (&dev
->usb
->usbstat
);
1550 if (t1
& (1 << VBUS_PIN
)) {
1551 if (t2
& (1 << HIGH_SPEED
))
1553 else if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1557 /* full speed bit (6) not working?? */
1560 t
= scnprintf (next
, size
,
1561 "stdrsp %08x usbctl %08x usbstat %08x "
1562 "addr 0x%02x (%s)\n",
1563 readl (&dev
->usb
->stdrsp
), t1
, t2
,
1564 readl (&dev
->usb
->ouraddr
), s
);
1568 /* PCI Master Control Registers */
1570 /* DMA Control Registers */
1572 /* Configurable EP Control Registers */
1573 for (i
= 0; i
< 7; i
++) {
1574 struct net2280_ep
*ep
;
1580 t1
= readl (&ep
->regs
->ep_cfg
);
1581 t2
= readl (&ep
->regs
->ep_rsp
) & 0xff;
1582 t
= scnprintf (next
, size
,
1583 "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
1585 ep
->ep
.name
, t1
, t2
,
1586 (t2
& (1 << CLEAR_NAK_OUT_PACKETS
))
1588 (t2
& (1 << CLEAR_EP_HIDE_STATUS_PHASE
))
1590 (t2
& (1 << CLEAR_EP_FORCE_CRC_ERROR
))
1592 (t2
& (1 << CLEAR_INTERRUPT_MODE
))
1593 ? "interrupt " : "",
1594 (t2
& (1<<CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE
))
1596 (t2
& (1 << CLEAR_NAK_OUT_PACKETS_MODE
))
1598 (t2
& (1 << CLEAR_ENDPOINT_TOGGLE
))
1599 ? "DATA1 " : "DATA0 ",
1600 (t2
& (1 << CLEAR_ENDPOINT_HALT
))
1602 readl (&ep
->regs
->ep_irqenb
));
1606 t
= scnprintf (next
, size
,
1607 "\tstat %08x avail %04x "
1609 readl (&ep
->regs
->ep_stat
),
1610 readl (&ep
->regs
->ep_avail
),
1611 t1
& 0x0f, DIR_STRING (t1
),
1612 type_string (t1
>> 8),
1613 ep
->stopped
? "*" : "");
1620 t
= scnprintf (next
, size
,
1621 " dma\tctl %08x stat %08x count %08x\n"
1622 "\taddr %08x desc %08x\n",
1623 readl (&ep
->dma
->dmactl
),
1624 readl (&ep
->dma
->dmastat
),
1625 readl (&ep
->dma
->dmacount
),
1626 readl (&ep
->dma
->dmaaddr
),
1627 readl (&ep
->dma
->dmadesc
));
1633 /* Indexed Registers */
1637 t
= scnprintf (next
, size
, "\nirqs: ");
1640 for (i
= 0; i
< 7; i
++) {
1641 struct net2280_ep
*ep
;
1646 t
= scnprintf (next
, size
, " %s/%lu", ep
->ep
.name
, ep
->irqs
);
1651 t
= scnprintf (next
, size
, "\n");
1655 spin_unlock_irqrestore (&dev
->lock
, flags
);
1657 return PAGE_SIZE
- size
;
1659 static DEVICE_ATTR (registers
, S_IRUGO
, show_registers
, NULL
);
1662 show_queues (struct device
*_dev
, struct device_attribute
*attr
, char *buf
)
1664 struct net2280
*dev
;
1667 unsigned long flags
;
1670 dev
= dev_get_drvdata (_dev
);
1673 spin_lock_irqsave (&dev
->lock
, flags
);
1675 for (i
= 0; i
< 7; i
++) {
1676 struct net2280_ep
*ep
= &dev
->ep
[i
];
1677 struct net2280_request
*req
;
1681 const struct usb_endpoint_descriptor
*d
;
1686 t
= d
->bEndpointAddress
;
1687 t
= scnprintf (next
, size
,
1688 "\n%s (ep%d%s-%s) max %04x %s fifo %d\n",
1689 ep
->ep
.name
, t
& USB_ENDPOINT_NUMBER_MASK
,
1690 (t
& USB_DIR_IN
) ? "in" : "out",
1692 switch (d
->bmAttributes
& 0x03) {
1693 case USB_ENDPOINT_XFER_BULK
:
1694 val
= "bulk"; break;
1695 case USB_ENDPOINT_XFER_INT
:
1696 val
= "intr"; break;
1700 le16_to_cpu (d
->wMaxPacketSize
) & 0x1fff,
1701 ep
->dma
? "dma" : "pio", ep
->fifo_size
1703 } else /* ep0 should only have one transfer queued */
1704 t
= scnprintf (next
, size
, "ep0 max 64 pio %s\n",
1705 ep
->is_in
? "in" : "out");
1706 if (t
<= 0 || t
> size
)
1711 if (list_empty (&ep
->queue
)) {
1712 t
= scnprintf (next
, size
, "\t(nothing queued)\n");
1713 if (t
<= 0 || t
> size
)
1719 list_for_each_entry (req
, &ep
->queue
, queue
) {
1720 if (ep
->dma
&& req
->td_dma
== readl (&ep
->dma
->dmadesc
))
1721 t
= scnprintf (next
, size
,
1722 "\treq %p len %d/%d "
1723 "buf %p (dmacount %08x)\n",
1724 &req
->req
, req
->req
.actual
,
1725 req
->req
.length
, req
->req
.buf
,
1726 readl (&ep
->dma
->dmacount
));
1728 t
= scnprintf (next
, size
,
1729 "\treq %p len %d/%d buf %p\n",
1730 &req
->req
, req
->req
.actual
,
1731 req
->req
.length
, req
->req
.buf
);
1732 if (t
<= 0 || t
> size
)
1738 struct net2280_dma
*td
;
1741 t
= scnprintf (next
, size
, "\t td %08x "
1742 " count %08x buf %08x desc %08x\n",
1744 le32_to_cpu (td
->dmacount
),
1745 le32_to_cpu (td
->dmaaddr
),
1746 le32_to_cpu (td
->dmadesc
));
1747 if (t
<= 0 || t
> size
)
1756 spin_unlock_irqrestore (&dev
->lock
, flags
);
1757 return PAGE_SIZE
- size
;
1759 static DEVICE_ATTR (queues
, S_IRUGO
, show_queues
, NULL
);
1764 #define device_create_file(a,b) do {} while (0)
1765 #define device_remove_file device_create_file
1769 /*-------------------------------------------------------------------------*/
1771 /* another driver-specific mode might be a request type doing dma
1772 * to/from another device fifo instead of to/from memory.
1775 static void set_fifo_mode (struct net2280
*dev
, int mode
)
1777 /* keeping high bits preserves BAR2 */
1778 writel ((0xffff << PCI_BASE2_RANGE
) | mode
, &dev
->regs
->fifoctl
);
1780 /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */
1781 INIT_LIST_HEAD (&dev
->gadget
.ep_list
);
1782 list_add_tail (&dev
->ep
[1].ep
.ep_list
, &dev
->gadget
.ep_list
);
1783 list_add_tail (&dev
->ep
[2].ep
.ep_list
, &dev
->gadget
.ep_list
);
1786 list_add_tail (&dev
->ep
[3].ep
.ep_list
, &dev
->gadget
.ep_list
);
1787 list_add_tail (&dev
->ep
[4].ep
.ep_list
, &dev
->gadget
.ep_list
);
1788 dev
->ep
[1].fifo_size
= dev
->ep
[2].fifo_size
= 1024;
1791 dev
->ep
[1].fifo_size
= dev
->ep
[2].fifo_size
= 2048;
1794 list_add_tail (&dev
->ep
[3].ep
.ep_list
, &dev
->gadget
.ep_list
);
1795 dev
->ep
[1].fifo_size
= 2048;
1796 dev
->ep
[2].fifo_size
= 1024;
1799 /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */
1800 list_add_tail (&dev
->ep
[5].ep
.ep_list
, &dev
->gadget
.ep_list
);
1801 list_add_tail (&dev
->ep
[6].ep
.ep_list
, &dev
->gadget
.ep_list
);
1804 /* just declare this in any driver that really need it */
1805 extern int net2280_set_fifo_mode (struct usb_gadget
*gadget
, int mode
);
1808 * net2280_set_fifo_mode - change allocation of fifo buffers
1809 * @gadget: access to the net2280 device that will be updated
1810 * @mode: 0 for default, four 1kB buffers (ep-a through ep-d);
1811 * 1 for two 2kB buffers (ep-a and ep-b only);
1812 * 2 for one 2kB buffer (ep-a) and two 1kB ones (ep-b, ep-c).
1814 * returns zero on success, else negative errno. when this succeeds,
1815 * the contents of gadget->ep_list may have changed.
1817 * you may only call this function when endpoints a-d are all disabled.
1818 * use it whenever extra hardware buffering can help performance, such
1819 * as before enabling "high bandwidth" interrupt endpoints that use
1820 * maxpacket bigger than 512 (when double buffering would otherwise
1823 int net2280_set_fifo_mode (struct usb_gadget
*gadget
, int mode
)
1826 struct net2280
*dev
;
1828 unsigned long flags
;
1832 dev
= container_of (gadget
, struct net2280
, gadget
);
1834 spin_lock_irqsave (&dev
->lock
, flags
);
1836 for (i
= 1; i
<= 4; i
++)
1837 if (dev
->ep
[i
].desc
) {
1841 if (mode
< 0 || mode
> 2)
1844 set_fifo_mode (dev
, mode
);
1845 spin_unlock_irqrestore (&dev
->lock
, flags
);
1849 DEBUG (dev
, "fifo: ep-a 2K, ep-b 2K\n");
1851 DEBUG (dev
, "fifo: ep-a 2K, ep-b 1K, ep-c 1K\n");
1852 /* else all are 1K */
1856 EXPORT_SYMBOL (net2280_set_fifo_mode
);
1858 /*-------------------------------------------------------------------------*/
1860 /* keeping it simple:
1861 * - one bus driver, initted first;
1862 * - one function driver, initted second
1864 * most of the work to support multiple net2280 controllers would
1865 * be to associate this gadget driver (yes?) with all of them, or
1866 * perhaps to bind specific drivers to specific devices.
1869 static struct net2280
*the_controller
;
1871 static void usb_reset (struct net2280
*dev
)
1875 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1876 (void) readl (&dev
->usb
->usbctl
);
1878 net2280_led_init (dev
);
1880 /* disable automatic responses, and irqs */
1881 writel (0, &dev
->usb
->stdrsp
);
1882 writel (0, &dev
->regs
->pciirqenb0
);
1883 writel (0, &dev
->regs
->pciirqenb1
);
1885 /* clear old dma and irq state */
1886 for (tmp
= 0; tmp
< 4; tmp
++) {
1887 struct net2280_ep
*ep
= &dev
->ep
[tmp
+ 1];
1892 writel (~0, &dev
->regs
->irqstat0
),
1893 writel (~(1 << SUSPEND_REQUEST_INTERRUPT
), &dev
->regs
->irqstat1
),
1895 /* reset, and enable pci */
1896 tmp
= readl (&dev
->regs
->devinit
)
1898 | (1 << FIFO_SOFT_RESET
)
1899 | (1 << USB_SOFT_RESET
)
1900 | (1 << M8051_RESET
);
1901 writel (tmp
, &dev
->regs
->devinit
);
1903 /* standard fifo and endpoint allocations */
1904 set_fifo_mode (dev
, (fifo_mode
<= 2) ? fifo_mode
: 0);
1907 static void usb_reinit (struct net2280
*dev
)
1912 /* use_dma changes are ignored till next device re-init */
1915 /* basic endpoint init */
1916 for (tmp
= 0; tmp
< 7; tmp
++) {
1917 struct net2280_ep
*ep
= &dev
->ep
[tmp
];
1919 ep
->ep
.name
= ep_name
[tmp
];
1923 if (tmp
> 0 && tmp
<= 4) {
1924 ep
->fifo_size
= 1024;
1926 ep
->dma
= &dev
->dma
[tmp
- 1];
1929 ep
->regs
= &dev
->epregs
[tmp
];
1930 ep_reset (dev
->regs
, ep
);
1932 dev
->ep
[0].ep
.maxpacket
= 64;
1933 dev
->ep
[5].ep
.maxpacket
= 64;
1934 dev
->ep
[6].ep
.maxpacket
= 64;
1936 dev
->gadget
.ep0
= &dev
->ep
[0].ep
;
1937 dev
->ep
[0].stopped
= 0;
1938 INIT_LIST_HEAD (&dev
->gadget
.ep0
->ep_list
);
1940 /* we want to prevent lowlevel/insecure access from the USB host,
1941 * but erratum 0119 means this enable bit is ignored
1943 for (tmp
= 0; tmp
< 5; tmp
++)
1944 writel (EP_DONTUSE
, &dev
->dep
[tmp
].dep_cfg
);
1947 static void ep0_start (struct net2280
*dev
)
1949 writel ( (1 << CLEAR_EP_HIDE_STATUS_PHASE
)
1950 | (1 << CLEAR_NAK_OUT_PACKETS
)
1951 | (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE
)
1952 , &dev
->epregs
[0].ep_rsp
);
1955 * hardware optionally handles a bunch of standard requests
1956 * that the API hides from drivers anyway. have it do so.
1957 * endpoint status/features are handled in software, to
1958 * help pass tests for some dubious behavior.
1960 writel ( (1 << SET_TEST_MODE
)
1961 | (1 << SET_ADDRESS
)
1962 | (1 << DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP
)
1963 | (1 << GET_DEVICE_STATUS
)
1964 | (1 << GET_INTERFACE_STATUS
)
1965 , &dev
->usb
->stdrsp
);
1966 writel ( (1 << USB_ROOT_PORT_WAKEUP_ENABLE
)
1967 | (1 << SELF_POWERED_USB_DEVICE
)
1968 | (1 << REMOTE_WAKEUP_SUPPORT
)
1969 | (dev
->softconnect
<< USB_DETECT_ENABLE
)
1970 | (1 << SELF_POWERED_STATUS
)
1971 , &dev
->usb
->usbctl
);
1973 /* enable irqs so we can see ep0 and general operation */
1974 writel ( (1 << SETUP_PACKET_INTERRUPT_ENABLE
)
1975 | (1 << ENDPOINT_0_INTERRUPT_ENABLE
)
1976 , &dev
->regs
->pciirqenb0
);
1977 writel ( (1 << PCI_INTERRUPT_ENABLE
)
1978 | (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE
)
1979 | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE
)
1980 | (1 << PCI_RETRY_ABORT_INTERRUPT_ENABLE
)
1981 | (1 << VBUS_INTERRUPT_ENABLE
)
1982 | (1 << ROOT_PORT_RESET_INTERRUPT_ENABLE
)
1983 | (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE
)
1984 , &dev
->regs
->pciirqenb1
);
1986 /* don't leave any writes posted */
1987 (void) readl (&dev
->usb
->usbctl
);
1990 /* when a driver is successfully registered, it will receive
1991 * control requests including set_configuration(), which enables
1992 * non-control requests. then usb traffic follows until a
1993 * disconnect is reported. then a host may connect again, or
1994 * the driver might get unbound.
1996 int usb_gadget_register_driver (struct usb_gadget_driver
*driver
)
1998 struct net2280
*dev
= the_controller
;
2002 /* insist on high speed support from the driver, since
2003 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
2004 * "must not be used in normal operation"
2007 || driver
->speed
!= USB_SPEED_HIGH
2017 for (i
= 0; i
< 7; i
++)
2018 dev
->ep
[i
].irqs
= 0;
2020 /* hook up the driver ... */
2021 dev
->softconnect
= 1;
2022 driver
->driver
.bus
= NULL
;
2023 dev
->driver
= driver
;
2024 dev
->gadget
.dev
.driver
= &driver
->driver
;
2025 retval
= driver
->bind (&dev
->gadget
);
2027 DEBUG (dev
, "bind to driver %s --> %d\n",
2028 driver
->driver
.name
, retval
);
2030 dev
->gadget
.dev
.driver
= NULL
;
2034 device_create_file (&dev
->pdev
->dev
, &dev_attr_function
);
2035 device_create_file (&dev
->pdev
->dev
, &dev_attr_queues
);
2037 /* ... then enable host detection and ep0; and we're ready
2038 * for set_configuration as well as eventual disconnect.
2040 net2280_led_active (dev
, 1);
2043 DEBUG (dev
, "%s ready, usbctl %08x stdrsp %08x\n",
2044 driver
->driver
.name
,
2045 readl (&dev
->usb
->usbctl
),
2046 readl (&dev
->usb
->stdrsp
));
2048 /* pci writes may still be posted */
2051 EXPORT_SYMBOL (usb_gadget_register_driver
);
2054 stop_activity (struct net2280
*dev
, struct usb_gadget_driver
*driver
)
2058 /* don't disconnect if it's not connected */
2059 if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
2062 /* stop hardware; prevent new request submissions;
2063 * and kill any outstanding requests.
2066 for (i
= 0; i
< 7; i
++)
2067 nuke (&dev
->ep
[i
]);
2069 /* report disconnect; the driver is already quiesced */
2071 spin_unlock (&dev
->lock
);
2072 driver
->disconnect (&dev
->gadget
);
2073 spin_lock (&dev
->lock
);
2079 int usb_gadget_unregister_driver (struct usb_gadget_driver
*driver
)
2081 struct net2280
*dev
= the_controller
;
2082 unsigned long flags
;
2086 if (!driver
|| driver
!= dev
->driver
)
2089 spin_lock_irqsave (&dev
->lock
, flags
);
2090 stop_activity (dev
, driver
);
2091 spin_unlock_irqrestore (&dev
->lock
, flags
);
2093 net2280_pullup (&dev
->gadget
, 0);
2095 driver
->unbind (&dev
->gadget
);
2096 dev
->gadget
.dev
.driver
= NULL
;
2099 net2280_led_active (dev
, 0);
2100 device_remove_file (&dev
->pdev
->dev
, &dev_attr_function
);
2101 device_remove_file (&dev
->pdev
->dev
, &dev_attr_queues
);
2103 DEBUG (dev
, "unregistered driver '%s'\n", driver
->driver
.name
);
2106 EXPORT_SYMBOL (usb_gadget_unregister_driver
);
2109 /*-------------------------------------------------------------------------*/
2111 /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq.
2112 * also works for dma-capable endpoints, in pio mode or just
2113 * to manually advance the queue after short OUT transfers.
2115 static void handle_ep_small (struct net2280_ep
*ep
)
2117 struct net2280_request
*req
;
2119 /* 0 error, 1 mid-data, 2 done */
2122 if (!list_empty (&ep
->queue
))
2123 req
= list_entry (ep
->queue
.next
,
2124 struct net2280_request
, queue
);
2128 /* ack all, and handle what we care about */
2129 t
= readl (&ep
->regs
->ep_stat
);
2132 VDEBUG (ep
->dev
, "%s ack ep_stat %08x, req %p\n",
2133 ep
->ep
.name
, t
, req
? &req
->req
: 0);
2135 if (!ep
->is_in
|| ep
->dev
->pdev
->device
== 0x2280)
2136 writel (t
& ~(1 << NAK_OUT_PACKETS
), &ep
->regs
->ep_stat
);
2138 /* Added for 2282 */
2139 writel (t
, &ep
->regs
->ep_stat
);
2141 /* for ep0, monitor token irqs to catch data stage length errors
2142 * and to synchronize on status.
2144 * also, to defer reporting of protocol stalls ... here's where
2145 * data or status first appears, handling stalls here should never
2146 * cause trouble on the host side..
2148 * control requests could be slightly faster without token synch for
2149 * status, but status can jam up that way.
2151 if (unlikely (ep
->num
== 0)) {
2153 /* status; stop NAKing */
2154 if (t
& (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)) {
2155 if (ep
->dev
->protocol_stall
) {
2162 /* reply to extra IN data tokens with a zlp */
2163 } else if (t
& (1 << DATA_IN_TOKEN_INTERRUPT
)) {
2164 if (ep
->dev
->protocol_stall
) {
2168 } else if (!req
&& !ep
->stopped
)
2169 write_fifo (ep
, NULL
);
2172 /* status; stop NAKing */
2173 if (t
& (1 << DATA_IN_TOKEN_INTERRUPT
)) {
2174 if (ep
->dev
->protocol_stall
) {
2179 /* an extra OUT token is an error */
2180 } else if (((t
& (1 << DATA_OUT_PING_TOKEN_INTERRUPT
))
2182 && req
->req
.actual
== req
->req
.length
)
2184 ep
->dev
->protocol_stall
= 1;
2188 done (ep
, req
, -EOVERFLOW
);
2194 if (unlikely (!req
))
2197 /* manual DMA queue advance after short OUT */
2198 if (likely (ep
->dma
!= 0)) {
2199 if (t
& (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT
)) {
2201 int stopped
= ep
->stopped
;
2203 /* TRANSFERRED works around OUT_DONE erratum 0112.
2204 * we expect (N <= maxpacket) bytes; host wrote M.
2205 * iff (M < N) we won't ever see a DMA interrupt.
2208 for (count
= 0; ; t
= readl (&ep
->regs
->ep_stat
)) {
2210 /* any preceding dma transfers must finish.
2211 * dma handles (M >= N), may empty the queue
2213 scan_dma_completions (ep
);
2214 if (unlikely (list_empty (&ep
->queue
)
2215 || ep
->out_overflow
)) {
2219 req
= list_entry (ep
->queue
.next
,
2220 struct net2280_request
, queue
);
2222 /* here either (M < N), a "real" short rx;
2223 * or (M == N) and the queue didn't empty
2225 if (likely (t
& (1 << FIFO_EMPTY
))) {
2226 count
= readl (&ep
->dma
->dmacount
);
2227 count
&= DMA_BYTE_COUNT_MASK
;
2228 if (readl (&ep
->dma
->dmadesc
)
2236 /* stop DMA, leave ep NAKing */
2237 writel ((1 << DMA_ABORT
), &ep
->dma
->dmastat
);
2238 spin_stop_dma (ep
->dma
);
2241 req
->td
->dmacount
= 0;
2242 t
= readl (&ep
->regs
->ep_avail
);
2243 dma_done (ep
, req
, count
,
2244 (ep
->out_overflow
|| t
) ? -EOVERFLOW
: 0);
2247 /* also flush to prevent erratum 0106 trouble */
2248 if (unlikely (ep
->out_overflow
2249 || (ep
->dev
->chiprev
== 0x0100
2250 && ep
->dev
->gadget
.speed
2251 == USB_SPEED_FULL
))) {
2253 ep
->out_overflow
= 0;
2256 /* (re)start dma if needed, stop NAKing */
2257 ep
->stopped
= stopped
;
2258 if (!list_empty (&ep
->queue
))
2261 DEBUG (ep
->dev
, "%s dma ep_stat %08x ??\n",
2265 /* data packet(s) received (in the fifo, OUT) */
2266 } else if (t
& (1 << DATA_PACKET_RECEIVED_INTERRUPT
)) {
2267 if (read_fifo (ep
, req
) && ep
->num
!= 0)
2270 /* data packet(s) transmitted (IN) */
2271 } else if (t
& (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
)) {
2274 len
= req
->req
.length
- req
->req
.actual
;
2275 if (len
> ep
->ep
.maxpacket
)
2276 len
= ep
->ep
.maxpacket
;
2277 req
->req
.actual
+= len
;
2279 /* if we wrote it all, we're usually done */
2280 if (req
->req
.actual
== req
->req
.length
) {
2282 /* send zlps until the status stage */
2283 } else if (!req
->req
.zero
|| len
!= ep
->ep
.maxpacket
)
2287 /* there was nothing to do ... */
2288 } else if (mode
== 1)
2293 /* stream endpoints often resubmit/unlink in completion */
2296 /* maybe advance queue to next request */
2298 /* NOTE: net2280 could let gadget driver start the
2299 * status stage later. since not all controllers let
2300 * them control that, the api doesn't (yet) allow it.
2306 if (!list_empty (&ep
->queue
) && !ep
->stopped
)
2307 req
= list_entry (ep
->queue
.next
,
2308 struct net2280_request
, queue
);
2311 if (req
&& !ep
->is_in
)
2312 stop_out_naking (ep
);
2316 /* is there a buffer for the next packet?
2317 * for best streaming performance, make sure there is one.
2319 if (req
&& !ep
->stopped
) {
2321 /* load IN fifo with next packet (may be zlp) */
2322 if (t
& (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
))
2323 write_fifo (ep
, &req
->req
);
2327 static struct net2280_ep
*
2328 get_ep_by_addr (struct net2280
*dev
, u16 wIndex
)
2330 struct net2280_ep
*ep
;
2332 if ((wIndex
& USB_ENDPOINT_NUMBER_MASK
) == 0)
2333 return &dev
->ep
[0];
2334 list_for_each_entry (ep
, &dev
->gadget
.ep_list
, ep
.ep_list
) {
2335 u8 bEndpointAddress
;
2339 bEndpointAddress
= ep
->desc
->bEndpointAddress
;
2340 if ((wIndex
^ bEndpointAddress
) & USB_DIR_IN
)
2342 if ((wIndex
& 0x0f) == (bEndpointAddress
& 0x0f))
2348 static void handle_stat0_irqs (struct net2280
*dev
, u32 stat
)
2350 struct net2280_ep
*ep
;
2353 /* most of these don't need individual acks */
2354 stat
&= ~(1 << INTA_ASSERTED
);
2357 // DEBUG (dev, "irqstat0 %04x\n", stat);
2359 /* starting a control request? */
2360 if (unlikely (stat
& (1 << SETUP_PACKET_INTERRUPT
))) {
2363 struct usb_ctrlrequest r
;
2366 struct net2280_request
*req
;
2368 if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
2369 if (readl (&dev
->usb
->usbstat
) & (1 << HIGH_SPEED
))
2370 dev
->gadget
.speed
= USB_SPEED_HIGH
;
2372 dev
->gadget
.speed
= USB_SPEED_FULL
;
2373 net2280_led_speed (dev
, dev
->gadget
.speed
);
2374 DEBUG (dev
, "%s speed\n",
2375 (dev
->gadget
.speed
== USB_SPEED_HIGH
)
2382 /* make sure any leftover request state is cleared */
2383 stat
&= ~(1 << ENDPOINT_0_INTERRUPT
);
2384 while (!list_empty (&ep
->queue
)) {
2385 req
= list_entry (ep
->queue
.next
,
2386 struct net2280_request
, queue
);
2387 done (ep
, req
, (req
->req
.actual
== req
->req
.length
)
2391 dev
->protocol_stall
= 0;
2393 if (ep
->dev
->pdev
->device
== 0x2280)
2394 tmp
= (1 << FIFO_OVERFLOW
)
2395 | (1 << FIFO_UNDERFLOW
);
2399 writel (tmp
| (1 << TIMEOUT
)
2400 | (1 << USB_STALL_SENT
)
2401 | (1 << USB_IN_NAK_SENT
)
2402 | (1 << USB_IN_ACK_RCVD
)
2403 | (1 << USB_OUT_PING_NAK_SENT
)
2404 | (1 << USB_OUT_ACK_SENT
)
2405 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT
)
2406 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT
)
2407 | (1 << DATA_PACKET_RECEIVED_INTERRUPT
)
2408 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
)
2409 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
2410 | (1 << DATA_IN_TOKEN_INTERRUPT
)
2411 , &ep
->regs
->ep_stat
);
2412 u
.raw
[0] = readl (&dev
->usb
->setup0123
);
2413 u
.raw
[1] = readl (&dev
->usb
->setup4567
);
2415 cpu_to_le32s (&u
.raw
[0]);
2416 cpu_to_le32s (&u
.raw
[1]);
2420 #define w_value le16_to_cpup (&u.r.wValue)
2421 #define w_index le16_to_cpup (&u.r.wIndex)
2422 #define w_length le16_to_cpup (&u.r.wLength)
2425 writel (1 << SETUP_PACKET_INTERRUPT
, &dev
->regs
->irqstat0
);
2426 stat
^= (1 << SETUP_PACKET_INTERRUPT
);
2428 /* watch control traffic at the token level, and force
2429 * synchronization before letting the status stage happen.
2430 * FIXME ignore tokens we'll NAK, until driver responds.
2431 * that'll mean a lot less irqs for some drivers.
2433 ep
->is_in
= (u
.r
.bRequestType
& USB_DIR_IN
) != 0;
2435 scratch
= (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
)
2436 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
2437 | (1 << DATA_IN_TOKEN_INTERRUPT
);
2438 stop_out_naking (ep
);
2440 scratch
= (1 << DATA_PACKET_RECEIVED_INTERRUPT
)
2441 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
2442 | (1 << DATA_IN_TOKEN_INTERRUPT
);
2443 writel (scratch
, &dev
->epregs
[0].ep_irqenb
);
2445 /* we made the hardware handle most lowlevel requests;
2446 * everything else goes uplevel to the gadget code.
2448 switch (u
.r
.bRequest
) {
2449 case USB_REQ_GET_STATUS
: {
2450 struct net2280_ep
*e
;
2453 /* hw handles device and interface status */
2454 if (u
.r
.bRequestType
!= (USB_DIR_IN
|USB_RECIP_ENDPOINT
))
2456 if ((e
= get_ep_by_addr (dev
, w_index
)) == 0
2460 if (readl (&e
->regs
->ep_rsp
)
2461 & (1 << SET_ENDPOINT_HALT
))
2462 status
= __constant_cpu_to_le32 (1);
2464 status
= __constant_cpu_to_le32 (0);
2466 /* don't bother with a request object! */
2467 writel (0, &dev
->epregs
[0].ep_irqenb
);
2468 set_fifo_bytecount (ep
, w_length
);
2469 writel ((__force u32
)status
, &dev
->epregs
[0].ep_data
);
2471 VDEBUG (dev
, "%s stat %02x\n", ep
->ep
.name
, status
);
2472 goto next_endpoints
;
2475 case USB_REQ_CLEAR_FEATURE
: {
2476 struct net2280_ep
*e
;
2478 /* hw handles device features */
2479 if (u
.r
.bRequestType
!= USB_RECIP_ENDPOINT
)
2481 if (w_value
!= USB_ENDPOINT_HALT
2484 if ((e
= get_ep_by_addr (dev
, w_index
)) == 0)
2488 VDEBUG (dev
, "%s clear halt\n", ep
->ep
.name
);
2489 goto next_endpoints
;
2492 case USB_REQ_SET_FEATURE
: {
2493 struct net2280_ep
*e
;
2495 /* hw handles device features */
2496 if (u
.r
.bRequestType
!= USB_RECIP_ENDPOINT
)
2498 if (w_value
!= USB_ENDPOINT_HALT
2501 if ((e
= get_ep_by_addr (dev
, w_index
)) == 0)
2505 VDEBUG (dev
, "%s set halt\n", ep
->ep
.name
);
2506 goto next_endpoints
;
2511 VDEBUG (dev
, "setup %02x.%02x v%04x i%04x l%04x"
2513 u
.r
.bRequestType
, u
.r
.bRequest
,
2514 w_value
, w_index
, w_length
,
2515 readl (&ep
->regs
->ep_cfg
));
2516 spin_unlock (&dev
->lock
);
2517 tmp
= dev
->driver
->setup (&dev
->gadget
, &u
.r
);
2518 spin_lock (&dev
->lock
);
2521 /* stall ep0 on error */
2524 VDEBUG (dev
, "req %02x.%02x protocol STALL; stat %d\n",
2525 u
.r
.bRequestType
, u
.r
.bRequest
, tmp
);
2526 dev
->protocol_stall
= 1;
2529 /* some in/out token irq should follow; maybe stall then.
2530 * driver must queue a request (even zlp) or halt ep0
2531 * before the host times out.
2540 /* endpoint data irq ? */
2541 scratch
= stat
& 0x7f;
2543 for (num
= 0; scratch
; num
++) {
2546 /* do this endpoint's FIFO and queue need tending? */
2548 if ((scratch
& t
) == 0)
2552 ep
= &dev
->ep
[num
];
2553 handle_ep_small (ep
);
2557 DEBUG (dev
, "unhandled irqstat0 %08x\n", stat
);
2560 #define DMA_INTERRUPTS ( \
2561 (1 << DMA_D_INTERRUPT) \
2562 | (1 << DMA_C_INTERRUPT) \
2563 | (1 << DMA_B_INTERRUPT) \
2564 | (1 << DMA_A_INTERRUPT))
2565 #define PCI_ERROR_INTERRUPTS ( \
2566 (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT) \
2567 | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT) \
2568 | (1 << PCI_RETRY_ABORT_INTERRUPT))
2570 static void handle_stat1_irqs (struct net2280
*dev
, u32 stat
)
2572 struct net2280_ep
*ep
;
2573 u32 tmp
, num
, mask
, scratch
;
2575 /* after disconnect there's nothing else to do! */
2576 tmp
= (1 << VBUS_INTERRUPT
) | (1 << ROOT_PORT_RESET_INTERRUPT
);
2577 mask
= (1 << HIGH_SPEED
) | (1 << FULL_SPEED
);
2579 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
2580 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRRUPT set and
2581 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
2582 * only indicates a change in the reset state).
2585 writel (tmp
, &dev
->regs
->irqstat1
);
2586 if ((((stat
& (1 << ROOT_PORT_RESET_INTERRUPT
)) &&
2587 ((readl (&dev
->usb
->usbstat
) & mask
) == 0))
2588 || ((readl (&dev
->usb
->usbctl
) & (1 << VBUS_PIN
)) == 0)
2589 ) && ( dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
)) {
2590 DEBUG (dev
, "disconnect %s\n",
2591 dev
->driver
->driver
.name
);
2592 stop_activity (dev
, dev
->driver
);
2598 /* vBUS can bounce ... one of many reasons to ignore the
2599 * notion of hotplug events on bus connect/disconnect!
2605 /* NOTE: chip stays in PCI D0 state for now, but it could
2606 * enter D1 to save more power
2608 tmp
= (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT
);
2610 writel (tmp
, &dev
->regs
->irqstat1
);
2611 if (stat
& (1 << SUSPEND_REQUEST_INTERRUPT
)) {
2612 if (dev
->driver
->suspend
)
2613 dev
->driver
->suspend (&dev
->gadget
);
2614 if (!enable_suspend
)
2615 stat
&= ~(1 << SUSPEND_REQUEST_INTERRUPT
);
2617 if (dev
->driver
->resume
)
2618 dev
->driver
->resume (&dev
->gadget
);
2619 /* at high speed, note erratum 0133 */
2624 /* clear any other status/irqs */
2626 writel (stat
, &dev
->regs
->irqstat1
);
2628 /* some status we can just ignore */
2629 if (dev
->pdev
->device
== 0x2280)
2630 stat
&= ~((1 << CONTROL_STATUS_INTERRUPT
)
2631 | (1 << SUSPEND_REQUEST_INTERRUPT
)
2632 | (1 << RESUME_INTERRUPT
)
2633 | (1 << SOF_INTERRUPT
));
2635 stat
&= ~((1 << CONTROL_STATUS_INTERRUPT
)
2636 | (1 << RESUME_INTERRUPT
)
2637 | (1 << SOF_DOWN_INTERRUPT
)
2638 | (1 << SOF_INTERRUPT
));
2642 // DEBUG (dev, "irqstat1 %08x\n", stat);
2644 /* DMA status, for ep-{a,b,c,d} */
2645 scratch
= stat
& DMA_INTERRUPTS
;
2646 stat
&= ~DMA_INTERRUPTS
;
2648 for (num
= 0; scratch
; num
++) {
2649 struct net2280_dma_regs __iomem
*dma
;
2652 if ((tmp
& scratch
) == 0)
2656 ep
= &dev
->ep
[num
+ 1];
2662 /* clear ep's dma status */
2663 tmp
= readl (&dma
->dmastat
);
2664 writel (tmp
, &dma
->dmastat
);
2666 /* chaining should stop on abort, short OUT from fifo,
2667 * or (stat0 codepath) short OUT transfer.
2669 if (!use_dma_chaining
) {
2670 if ((tmp
& (1 << DMA_TRANSACTION_DONE_INTERRUPT
))
2672 DEBUG (ep
->dev
, "%s no xact done? %08x\n",
2679 /* OUT transfers terminate when the data from the
2680 * host is in our memory. Process whatever's done.
2681 * On this path, we know transfer's last packet wasn't
2682 * less than req->length. NAK_OUT_PACKETS may be set,
2683 * or the FIFO may already be holding new packets.
2685 * IN transfers can linger in the FIFO for a very
2686 * long time ... we ignore that for now, accounting
2687 * precisely (like PIO does) needs per-packet irqs
2689 scan_dma_completions (ep
);
2691 /* disable dma on inactive queues; else maybe restart */
2692 if (list_empty (&ep
->queue
)) {
2693 if (use_dma_chaining
)
2696 tmp
= readl (&dma
->dmactl
);
2697 if (!use_dma_chaining
2698 || (tmp
& (1 << DMA_ENABLE
)) == 0)
2700 else if (ep
->is_in
&& use_dma_chaining
) {
2701 struct net2280_request
*req
;
2704 /* the descriptor at the head of the chain
2705 * may still have VALID_BIT clear; that's
2706 * used to trigger changing DMA_FIFO_VALIDATE
2707 * (affects automagic zlp writes).
2709 req
= list_entry (ep
->queue
.next
,
2710 struct net2280_request
, queue
);
2711 dmacount
= req
->td
->dmacount
;
2712 dmacount
&= __constant_cpu_to_le32 (
2714 | DMA_BYTE_COUNT_MASK
);
2715 if (dmacount
&& (dmacount
& valid_bit
) == 0)
2722 /* NOTE: there are other PCI errors we might usefully notice.
2723 * if they appear very often, here's where to try recovering.
2725 if (stat
& PCI_ERROR_INTERRUPTS
) {
2726 ERROR (dev
, "pci dma error; stat %08x\n", stat
);
2727 stat
&= ~PCI_ERROR_INTERRUPTS
;
2728 /* these are fatal errors, but "maybe" they won't
2731 stop_activity (dev
, dev
->driver
);
2737 DEBUG (dev
, "unhandled irqstat1 %08x\n", stat
);
2740 static irqreturn_t
net2280_irq (int irq
, void *_dev
, struct pt_regs
* r
)
2742 struct net2280
*dev
= _dev
;
2744 /* shared interrupt, not ours */
2745 if (!(readl(&dev
->regs
->irqstat0
) & (1 << INTA_ASSERTED
)))
2748 spin_lock (&dev
->lock
);
2750 /* handle disconnect, dma, and more */
2751 handle_stat1_irqs (dev
, readl (&dev
->regs
->irqstat1
));
2753 /* control requests and PIO */
2754 handle_stat0_irqs (dev
, readl (&dev
->regs
->irqstat0
));
2756 spin_unlock (&dev
->lock
);
2761 /*-------------------------------------------------------------------------*/
2763 static void gadget_release (struct device
*_dev
)
2765 struct net2280
*dev
= dev_get_drvdata (_dev
);
2770 /* tear down the binding between this driver and the pci device */
2772 static void net2280_remove (struct pci_dev
*pdev
)
2774 struct net2280
*dev
= pci_get_drvdata (pdev
);
2776 /* start with the driver above us */
2778 /* should have been done already by driver model core */
2779 WARN (dev
, "pci remove, driver '%s' is still registered\n",
2780 dev
->driver
->driver
.name
);
2781 usb_gadget_unregister_driver (dev
->driver
);
2784 /* then clean up the resources we allocated during probe() */
2785 net2280_led_shutdown (dev
);
2786 if (dev
->requests
) {
2788 for (i
= 1; i
< 5; i
++) {
2789 if (!dev
->ep
[i
].dummy
)
2791 pci_pool_free (dev
->requests
, dev
->ep
[i
].dummy
,
2792 dev
->ep
[i
].td_dma
);
2794 pci_pool_destroy (dev
->requests
);
2797 free_irq (pdev
->irq
, dev
);
2799 iounmap (dev
->regs
);
2801 release_mem_region (pci_resource_start (pdev
, 0),
2802 pci_resource_len (pdev
, 0));
2804 pci_disable_device (pdev
);
2805 device_unregister (&dev
->gadget
.dev
);
2806 device_remove_file (&pdev
->dev
, &dev_attr_registers
);
2807 pci_set_drvdata (pdev
, NULL
);
2809 INFO (dev
, "unbind\n");
2811 the_controller
= NULL
;
2814 /* wrap this driver around the specified device, but
2815 * don't respond over USB until a gadget driver binds to us.
2818 static int net2280_probe (struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2820 struct net2280
*dev
;
2821 unsigned long resource
, len
;
2822 void __iomem
*base
= NULL
;
2825 /* if you want to support more than one controller in a system,
2826 * usb_gadget_driver_{register,unregister}() must change.
2828 if (the_controller
) {
2829 dev_warn (&pdev
->dev
, "ignoring\n");
2833 /* alloc, and start init */
2834 dev
= kzalloc (sizeof *dev
, SLAB_KERNEL
);
2840 pci_set_drvdata (pdev
, dev
);
2841 spin_lock_init (&dev
->lock
);
2843 dev
->gadget
.ops
= &net2280_ops
;
2844 dev
->gadget
.is_dualspeed
= 1;
2846 /* the "gadget" abstracts/virtualizes the controller */
2847 strcpy (dev
->gadget
.dev
.bus_id
, "gadget");
2848 dev
->gadget
.dev
.parent
= &pdev
->dev
;
2849 dev
->gadget
.dev
.dma_mask
= pdev
->dev
.dma_mask
;
2850 dev
->gadget
.dev
.release
= gadget_release
;
2851 dev
->gadget
.name
= driver_name
;
2853 /* now all the pci goodies ... */
2854 if (pci_enable_device (pdev
) < 0) {
2860 /* BAR 0 holds all the registers
2861 * BAR 1 is 8051 memory; unused here (note erratum 0103)
2862 * BAR 2 is fifo memory; unused here
2864 resource
= pci_resource_start (pdev
, 0);
2865 len
= pci_resource_len (pdev
, 0);
2866 if (!request_mem_region (resource
, len
, driver_name
)) {
2867 DEBUG (dev
, "controller already in use\n");
2873 base
= ioremap_nocache (resource
, len
);
2875 DEBUG (dev
, "can't map memory\n");
2879 dev
->regs
= (struct net2280_regs __iomem
*) base
;
2880 dev
->usb
= (struct net2280_usb_regs __iomem
*) (base
+ 0x0080);
2881 dev
->pci
= (struct net2280_pci_regs __iomem
*) (base
+ 0x0100);
2882 dev
->dma
= (struct net2280_dma_regs __iomem
*) (base
+ 0x0180);
2883 dev
->dep
= (struct net2280_dep_regs __iomem
*) (base
+ 0x0200);
2884 dev
->epregs
= (struct net2280_ep_regs __iomem
*) (base
+ 0x0300);
2886 /* put into initial config, link up all endpoints */
2887 writel (0, &dev
->usb
->usbctl
);
2891 /* irq setup after old hardware is cleaned up */
2893 ERROR (dev
, "No IRQ. Check PCI setup!\n");
2898 if (request_irq (pdev
->irq
, net2280_irq
, IRQF_SHARED
, driver_name
, dev
)
2900 ERROR (dev
, "request interrupt %d failed\n", pdev
->irq
);
2907 /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */
2908 dev
->requests
= pci_pool_create ("requests", pdev
,
2909 sizeof (struct net2280_dma
),
2910 0 /* no alignment requirements */,
2911 0 /* or page-crossing issues */);
2912 if (!dev
->requests
) {
2913 DEBUG (dev
, "can't get request pool\n");
2917 for (i
= 1; i
< 5; i
++) {
2918 struct net2280_dma
*td
;
2920 td
= pci_pool_alloc (dev
->requests
, GFP_KERNEL
,
2921 &dev
->ep
[i
].td_dma
);
2923 DEBUG (dev
, "can't get dummy %d\n", i
);
2927 td
->dmacount
= 0; /* not VALID */
2928 td
->dmaaddr
= __constant_cpu_to_le32 (DMA_ADDR_INVALID
);
2929 td
->dmadesc
= td
->dmaaddr
;
2930 dev
->ep
[i
].dummy
= td
;
2933 /* enable lower-overhead pci memory bursts during DMA */
2934 writel ( (1 << DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE
)
2935 // 256 write retries may not be enough...
2936 // | (1 << PCI_RETRY_ABORT_ENABLE)
2937 | (1 << DMA_READ_MULTIPLE_ENABLE
)
2938 | (1 << DMA_READ_LINE_ENABLE
)
2939 , &dev
->pci
->pcimstctl
);
2940 /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
2941 pci_set_master (pdev
);
2944 /* ... also flushes any posted pci writes */
2945 dev
->chiprev
= get_idx_reg (dev
->regs
, REG_CHIPREV
) & 0xffff;
2948 INFO (dev
, "%s\n", driver_desc
);
2949 INFO (dev
, "irq %d, pci mem %p, chip rev %04x\n",
2950 pdev
->irq
, base
, dev
->chiprev
);
2951 INFO (dev
, "version: " DRIVER_VERSION
"; dma %s\n",
2953 ? (use_dma_chaining
? "chaining" : "enabled")
2955 the_controller
= dev
;
2957 device_register (&dev
->gadget
.dev
);
2958 device_create_file (&pdev
->dev
, &dev_attr_registers
);
2964 net2280_remove (pdev
);
2968 /* make sure the board is quiescent; otherwise it will continue
2969 * generating IRQs across the upcoming reboot.
2972 static void net2280_shutdown (struct pci_dev
*pdev
)
2974 struct net2280
*dev
= pci_get_drvdata (pdev
);
2977 writel (0, &dev
->regs
->pciirqenb0
);
2978 writel (0, &dev
->regs
->pciirqenb1
);
2980 /* disable the pullup so the host will think we're gone */
2981 writel (0, &dev
->usb
->usbctl
);
2985 /*-------------------------------------------------------------------------*/
2987 static struct pci_device_id pci_ids
[] = { {
2988 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
2992 .subvendor
= PCI_ANY_ID
,
2993 .subdevice
= PCI_ANY_ID
,
2995 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
2999 .subvendor
= PCI_ANY_ID
,
3000 .subdevice
= PCI_ANY_ID
,
3002 }, { /* end: all zeroes */ }
3004 MODULE_DEVICE_TABLE (pci
, pci_ids
);
3006 /* pci driver glue; this is a "new style" PCI driver module */
3007 static struct pci_driver net2280_pci_driver
= {
3008 .name
= (char *) driver_name
,
3009 .id_table
= pci_ids
,
3011 .probe
= net2280_probe
,
3012 .remove
= net2280_remove
,
3013 .shutdown
= net2280_shutdown
,
3015 /* FIXME add power management support */
3018 MODULE_DESCRIPTION (DRIVER_DESC
);
3019 MODULE_AUTHOR ("David Brownell");
3020 MODULE_LICENSE ("GPL");
3022 static int __init
init (void)
3025 use_dma_chaining
= 0;
3026 return pci_register_driver (&net2280_pci_driver
);
3030 static void __exit
cleanup (void)
3032 pci_unregister_driver (&net2280_pci_driver
);
3034 module_exit (cleanup
);