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
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 #undef DEBUG /* messages on error and most fault paths */
48 #undef VERBOSE /* extra debug messages (success too) */
50 #include <linux/module.h>
51 #include <linux/pci.h>
52 #include <linux/dma-mapping.h>
53 #include <linux/kernel.h>
54 #include <linux/delay.h>
55 #include <linux/ioport.h>
56 #include <linux/sched.h>
57 #include <linux/slab.h>
58 #include <linux/smp_lock.h>
59 #include <linux/errno.h>
60 #include <linux/init.h>
61 #include <linux/timer.h>
62 #include <linux/list.h>
63 #include <linux/interrupt.h>
64 #include <linux/moduleparam.h>
65 #include <linux/device.h>
66 #include <linux/usb_ch9.h>
67 #include <linux/usb_gadget.h>
69 #include <asm/byteorder.h>
72 #include <asm/system.h>
73 #include <asm/unaligned.h>
76 #define DRIVER_DESC "PLX NET228x USB Peripheral Controller"
77 #define DRIVER_VERSION "2005 Sept 27"
79 #define DMA_ADDR_INVALID (~(dma_addr_t)0)
80 #define EP_DONTUSE 13 /* nonzero */
82 #define USE_RDK_LEDS /* GPIO pins control three LEDs */
85 static const char driver_name
[] = "net2280";
86 static const char driver_desc
[] = DRIVER_DESC
;
88 static const char ep0name
[] = "ep0";
89 static const char *const ep_name
[] = {
91 "ep-a", "ep-b", "ep-c", "ep-d",
95 /* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO)
96 * use_dma_chaining -- dma descriptor queueing gives even more irq reduction
98 * The net2280 DMA engines are not tightly integrated with their FIFOs;
99 * not all cases are (yet) handled well in this driver or the silicon.
100 * Some gadget drivers work better with the dma support here than others.
101 * These two parameters let you use PIO or more aggressive DMA.
103 static int use_dma
= 1;
104 static int use_dma_chaining
= 0;
106 /* "modprobe net2280 use_dma=n" etc */
107 module_param (use_dma
, bool, S_IRUGO
);
108 module_param (use_dma_chaining
, bool, S_IRUGO
);
111 /* mode 0 == ep-{a,b,c,d} 1K fifo each
112 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
113 * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
115 static ushort fifo_mode
= 0;
117 /* "modprobe net2280 fifo_mode=1" etc */
118 module_param (fifo_mode
, ushort
, 0644);
120 /* enable_suspend -- When enabled, the driver will respond to
121 * USB suspend requests by powering down the NET2280. Otherwise,
122 * USB suspend requests will be ignored. This is acceptible for
123 * self-powered devices
125 static int enable_suspend
= 0;
127 /* "modprobe net2280 enable_suspend=1" etc */
128 module_param (enable_suspend
, bool, S_IRUGO
);
131 #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
133 #if defined(CONFIG_USB_GADGET_DEBUG_FILES) || defined (DEBUG)
134 static char *type_string (u8 bmAttributes
)
136 switch ((bmAttributes
) & USB_ENDPOINT_XFERTYPE_MASK
) {
137 case USB_ENDPOINT_XFER_BULK
: return "bulk";
138 case USB_ENDPOINT_XFER_ISOC
: return "iso";
139 case USB_ENDPOINT_XFER_INT
: return "intr";
147 #define valid_bit __constant_cpu_to_le32 (1 << VALID_BIT)
148 #define dma_done_ie __constant_cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
150 /*-------------------------------------------------------------------------*/
153 net2280_enable (struct usb_ep
*_ep
, const struct usb_endpoint_descriptor
*desc
)
156 struct net2280_ep
*ep
;
160 ep
= container_of (_ep
, struct net2280_ep
, ep
);
161 if (!_ep
|| !desc
|| ep
->desc
|| _ep
->name
== ep0name
162 || desc
->bDescriptorType
!= USB_DT_ENDPOINT
)
165 if (!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
168 /* erratum 0119 workaround ties up an endpoint number */
169 if ((desc
->bEndpointAddress
& 0x0f) == EP_DONTUSE
)
172 /* sanity check ep-e/ep-f since their fifos are small */
173 max
= le16_to_cpu (desc
->wMaxPacketSize
) & 0x1fff;
174 if (ep
->num
> 4 && max
> 64)
177 spin_lock_irqsave (&dev
->lock
, flags
);
178 _ep
->maxpacket
= max
& 0x7ff;
181 /* ep_reset() has already been called */
183 ep
->out_overflow
= 0;
185 /* set speed-dependent max packet; may kick in high bandwidth */
186 set_idx_reg (dev
->regs
, REG_EP_MAXPKT (dev
, ep
->num
), max
);
188 /* FIFO lines can't go to different packets. PIO is ok, so
189 * use it instead of troublesome (non-bulk) multi-packet DMA.
191 if (ep
->dma
&& (max
% 4) != 0 && use_dma_chaining
) {
192 DEBUG (ep
->dev
, "%s, no dma for maxpacket %d\n",
193 ep
->ep
.name
, ep
->ep
.maxpacket
);
197 /* set type, direction, address; reset fifo counters */
198 writel ((1 << FIFO_FLUSH
), &ep
->regs
->ep_stat
);
199 tmp
= (desc
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
);
200 if (tmp
== USB_ENDPOINT_XFER_INT
) {
201 /* erratum 0105 workaround prevents hs NYET */
202 if (dev
->chiprev
== 0100
203 && dev
->gadget
.speed
== USB_SPEED_HIGH
204 && !(desc
->bEndpointAddress
& USB_DIR_IN
))
205 writel ((1 << CLEAR_NAK_OUT_PACKETS_MODE
),
207 } else if (tmp
== USB_ENDPOINT_XFER_BULK
) {
208 /* catch some particularly blatant driver bugs */
209 if ((dev
->gadget
.speed
== USB_SPEED_HIGH
211 || (dev
->gadget
.speed
== USB_SPEED_FULL
213 spin_unlock_irqrestore (&dev
->lock
, flags
);
217 ep
->is_iso
= (tmp
== USB_ENDPOINT_XFER_ISOC
) ? 1 : 0;
218 tmp
<<= ENDPOINT_TYPE
;
219 tmp
|= desc
->bEndpointAddress
;
220 tmp
|= (4 << ENDPOINT_BYTE_COUNT
); /* default full fifo lines */
221 tmp
|= 1 << ENDPOINT_ENABLE
;
224 /* for OUT transfers, block the rx fifo until a read is posted */
225 ep
->is_in
= (tmp
& USB_DIR_IN
) != 0;
227 writel ((1 << SET_NAK_OUT_PACKETS
), &ep
->regs
->ep_rsp
);
228 else if (dev
->pdev
->device
!= 0x2280) {
229 /* Added for 2282, Don't use nak packets on an in endpoint,
230 * this was ignored on 2280
232 writel ((1 << CLEAR_NAK_OUT_PACKETS
)
233 | (1 << CLEAR_NAK_OUT_PACKETS_MODE
), &ep
->regs
->ep_rsp
);
236 writel (tmp
, &ep
->regs
->ep_cfg
);
239 if (!ep
->dma
) { /* pio, per-packet */
240 tmp
= (1 << ep
->num
) | readl (&dev
->regs
->pciirqenb0
);
241 writel (tmp
, &dev
->regs
->pciirqenb0
);
243 tmp
= (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE
)
244 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE
);
245 if (dev
->pdev
->device
== 0x2280)
246 tmp
|= readl (&ep
->regs
->ep_irqenb
);
247 writel (tmp
, &ep
->regs
->ep_irqenb
);
248 } else { /* dma, per-request */
249 tmp
= (1 << (8 + ep
->num
)); /* completion */
250 tmp
|= readl (&dev
->regs
->pciirqenb1
);
251 writel (tmp
, &dev
->regs
->pciirqenb1
);
253 /* for short OUT transfers, dma completions can't
254 * advance the queue; do it pio-style, by hand.
255 * NOTE erratum 0112 workaround #2
257 if ((desc
->bEndpointAddress
& USB_DIR_IN
) == 0) {
258 tmp
= (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE
);
259 writel (tmp
, &ep
->regs
->ep_irqenb
);
261 tmp
= (1 << ep
->num
) | readl (&dev
->regs
->pciirqenb0
);
262 writel (tmp
, &dev
->regs
->pciirqenb0
);
266 tmp
= desc
->bEndpointAddress
;
267 DEBUG (dev
, "enabled %s (ep%d%s-%s) %s max %04x\n",
268 _ep
->name
, tmp
& 0x0f, DIR_STRING (tmp
),
269 type_string (desc
->bmAttributes
),
270 ep
->dma
? "dma" : "pio", max
);
272 /* pci writes may still be posted */
273 spin_unlock_irqrestore (&dev
->lock
, flags
);
277 static int handshake (u32 __iomem
*ptr
, u32 mask
, u32 done
, int usec
)
282 result
= readl (ptr
);
283 if (result
== ~(u32
)0) /* "device unplugged" */
294 static const struct usb_ep_ops net2280_ep_ops
;
296 static void ep_reset (struct net2280_regs __iomem
*regs
, struct net2280_ep
*ep
)
301 INIT_LIST_HEAD (&ep
->queue
);
303 ep
->ep
.maxpacket
= ~0;
304 ep
->ep
.ops
= &net2280_ep_ops
;
306 /* disable the dma, irqs, endpoint... */
308 writel (0, &ep
->dma
->dmactl
);
309 writel ( (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT
)
310 | (1 << DMA_TRANSACTION_DONE_INTERRUPT
)
312 , &ep
->dma
->dmastat
);
314 tmp
= readl (®s
->pciirqenb0
);
315 tmp
&= ~(1 << ep
->num
);
316 writel (tmp
, ®s
->pciirqenb0
);
318 tmp
= readl (®s
->pciirqenb1
);
319 tmp
&= ~(1 << (8 + ep
->num
)); /* completion */
320 writel (tmp
, ®s
->pciirqenb1
);
322 writel (0, &ep
->regs
->ep_irqenb
);
324 /* init to our chosen defaults, notably so that we NAK OUT
325 * packets until the driver queues a read (+note erratum 0112)
327 if (!ep
->is_in
|| ep
->dev
->pdev
->device
== 0x2280) {
328 tmp
= (1 << SET_NAK_OUT_PACKETS_MODE
)
329 | (1 << SET_NAK_OUT_PACKETS
)
330 | (1 << CLEAR_EP_HIDE_STATUS_PHASE
)
331 | (1 << CLEAR_INTERRUPT_MODE
);
334 tmp
= (1 << CLEAR_NAK_OUT_PACKETS_MODE
)
335 | (1 << CLEAR_NAK_OUT_PACKETS
)
336 | (1 << CLEAR_EP_HIDE_STATUS_PHASE
)
337 | (1 << CLEAR_INTERRUPT_MODE
);
341 tmp
|= (1 << CLEAR_ENDPOINT_TOGGLE
)
342 | (1 << CLEAR_ENDPOINT_HALT
);
344 writel (tmp
, &ep
->regs
->ep_rsp
);
346 /* scrub most status bits, and flush any fifo state */
347 if (ep
->dev
->pdev
->device
== 0x2280)
348 tmp
= (1 << FIFO_OVERFLOW
)
349 | (1 << FIFO_UNDERFLOW
);
353 writel (tmp
| (1 << TIMEOUT
)
354 | (1 << USB_STALL_SENT
)
355 | (1 << USB_IN_NAK_SENT
)
356 | (1 << USB_IN_ACK_RCVD
)
357 | (1 << USB_OUT_PING_NAK_SENT
)
358 | (1 << USB_OUT_ACK_SENT
)
360 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT
)
361 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT
)
362 | (1 << DATA_PACKET_RECEIVED_INTERRUPT
)
363 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
)
364 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
365 | (1 << DATA_IN_TOKEN_INTERRUPT
)
366 , &ep
->regs
->ep_stat
);
368 /* fifo size is handled separately */
371 static void nuke (struct net2280_ep
*);
373 static int net2280_disable (struct usb_ep
*_ep
)
375 struct net2280_ep
*ep
;
378 ep
= container_of (_ep
, struct net2280_ep
, ep
);
379 if (!_ep
|| !ep
->desc
|| _ep
->name
== ep0name
)
382 spin_lock_irqsave (&ep
->dev
->lock
, flags
);
384 ep_reset (ep
->dev
->regs
, ep
);
386 VDEBUG (ep
->dev
, "disabled %s %s\n",
387 ep
->dma
? "dma" : "pio", _ep
->name
);
389 /* synch memory views with the device */
390 (void) readl (&ep
->regs
->ep_cfg
);
392 if (use_dma
&& !ep
->dma
&& ep
->num
>= 1 && ep
->num
<= 4)
393 ep
->dma
= &ep
->dev
->dma
[ep
->num
- 1];
395 spin_unlock_irqrestore (&ep
->dev
->lock
, flags
);
399 /*-------------------------------------------------------------------------*/
401 static struct usb_request
*
402 net2280_alloc_request (struct usb_ep
*_ep
, gfp_t gfp_flags
)
404 struct net2280_ep
*ep
;
405 struct net2280_request
*req
;
409 ep
= container_of (_ep
, struct net2280_ep
, ep
);
411 req
= kzalloc(sizeof(*req
), gfp_flags
);
415 req
->req
.dma
= DMA_ADDR_INVALID
;
416 INIT_LIST_HEAD (&req
->queue
);
418 /* this dma descriptor may be swapped with the previous dummy */
420 struct net2280_dma
*td
;
422 td
= pci_pool_alloc (ep
->dev
->requests
, gfp_flags
,
428 td
->dmacount
= 0; /* not VALID */
429 td
->dmaaddr
= __constant_cpu_to_le32 (DMA_ADDR_INVALID
);
430 td
->dmadesc
= td
->dmaaddr
;
437 net2280_free_request (struct usb_ep
*_ep
, struct usb_request
*_req
)
439 struct net2280_ep
*ep
;
440 struct net2280_request
*req
;
442 ep
= container_of (_ep
, struct net2280_ep
, ep
);
446 req
= container_of (_req
, struct net2280_request
, req
);
447 WARN_ON (!list_empty (&req
->queue
));
449 pci_pool_free (ep
->dev
->requests
, req
->td
, req
->td_dma
);
453 /*-------------------------------------------------------------------------*/
456 * dma-coherent memory allocation (for dma-capable endpoints)
458 * NOTE: the dma_*_coherent() API calls suck. Most implementations are
459 * (a) page-oriented, so small buffers lose big; and (b) asymmetric with
460 * respect to calls with irqs disabled: alloc is safe, free is not.
461 * We currently work around (b), but not (a).
465 net2280_alloc_buffer (
473 struct net2280_ep
*ep
;
475 ep
= container_of (_ep
, struct net2280_ep
, ep
);
478 *dma
= DMA_ADDR_INVALID
;
481 retval
= dma_alloc_coherent(&ep
->dev
->pdev
->dev
,
482 bytes
, dma
, gfp_flags
);
484 retval
= kmalloc(bytes
, gfp_flags
);
488 static DEFINE_SPINLOCK(buflock
);
489 static LIST_HEAD(buffers
);
492 struct list_head list
;
498 static void do_free(unsigned long ignored
)
500 spin_lock_irq(&buflock
);
501 while (!list_empty(&buffers
)) {
502 struct free_record
*buf
;
504 buf
= list_entry(buffers
.next
, struct free_record
, list
);
505 list_del(&buf
->list
);
506 spin_unlock_irq(&buflock
);
508 dma_free_coherent(buf
->dev
, buf
->bytes
, buf
, buf
->dma
);
510 spin_lock_irq(&buflock
);
512 spin_unlock_irq(&buflock
);
515 static DECLARE_TASKLET(deferred_free
, do_free
, 0);
518 net2280_free_buffer (
524 /* free memory into the right allocator */
525 if (dma
!= DMA_ADDR_INVALID
) {
526 struct net2280_ep
*ep
;
527 struct free_record
*buf
= address
;
530 ep
= container_of(_ep
, struct net2280_ep
, ep
);
534 ep
= container_of (_ep
, struct net2280_ep
, ep
);
535 buf
->dev
= &ep
->dev
->pdev
->dev
;
539 spin_lock_irqsave(&buflock
, flags
);
540 list_add_tail(&buf
->list
, &buffers
);
541 tasklet_schedule(&deferred_free
);
542 spin_unlock_irqrestore(&buflock
, flags
);
547 /*-------------------------------------------------------------------------*/
549 /* load a packet into the fifo we use for usb IN transfers.
550 * works for all endpoints.
552 * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo
553 * at a time, but this code is simpler because it knows it only writes
554 * one packet. ep-a..ep-d should use dma instead.
557 write_fifo (struct net2280_ep
*ep
, struct usb_request
*req
)
559 struct net2280_ep_regs __iomem
*regs
= ep
->regs
;
562 unsigned count
, total
;
564 /* INVARIANT: fifo is currently empty. (testable) */
567 buf
= req
->buf
+ req
->actual
;
569 total
= req
->length
- req
->actual
;
575 /* write just one packet at a time */
576 count
= ep
->ep
.maxpacket
;
577 if (count
> total
) /* min() cannot be used on a bitfield */
580 VDEBUG (ep
->dev
, "write %s fifo (IN) %d bytes%s req %p\n",
582 (count
!= ep
->ep
.maxpacket
) ? " (short)" : "",
585 /* NOTE be careful if you try to align these. fifo lines
586 * should normally be full (4 bytes) and successive partial
587 * lines are ok only in certain cases.
589 tmp
= get_unaligned ((u32
*)buf
);
591 writel (tmp
, ®s
->ep_data
);
596 /* last fifo entry is "short" unless we wrote a full packet.
597 * also explicitly validate last word in (periodic) transfers
598 * when maxpacket is not a multiple of 4 bytes.
600 if (count
|| total
< ep
->ep
.maxpacket
) {
601 tmp
= count
? get_unaligned ((u32
*)buf
) : count
;
603 set_fifo_bytecount (ep
, count
& 0x03);
604 writel (tmp
, ®s
->ep_data
);
607 /* pci writes may still be posted */
610 /* work around erratum 0106: PCI and USB race over the OUT fifo.
611 * caller guarantees chiprev 0100, out endpoint is NAKing, and
612 * there's no real data in the fifo.
614 * NOTE: also used in cases where that erratum doesn't apply:
615 * where the host wrote "too much" data to us.
617 static void out_flush (struct net2280_ep
*ep
)
622 ASSERT_OUT_NAKING (ep
);
624 statp
= &ep
->regs
->ep_stat
;
625 writel ( (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
626 | (1 << DATA_PACKET_RECEIVED_INTERRUPT
)
628 writel ((1 << FIFO_FLUSH
), statp
);
631 if (tmp
& (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
632 /* high speed did bulk NYET; fifo isn't filling */
633 && ep
->dev
->gadget
.speed
== USB_SPEED_FULL
) {
636 usec
= 50; /* 64 byte bulk/interrupt */
637 handshake (statp
, (1 << USB_OUT_PING_NAK_SENT
),
638 (1 << USB_OUT_PING_NAK_SENT
), usec
);
639 /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
643 /* unload packet(s) from the fifo we use for usb OUT transfers.
644 * returns true iff the request completed, because of short packet
645 * or the request buffer having filled with full packets.
647 * for ep-a..ep-d this will read multiple packets out when they
648 * have been accepted.
651 read_fifo (struct net2280_ep
*ep
, struct net2280_request
*req
)
653 struct net2280_ep_regs __iomem
*regs
= ep
->regs
;
654 u8
*buf
= req
->req
.buf
+ req
->req
.actual
;
655 unsigned count
, tmp
, is_short
;
656 unsigned cleanup
= 0, prevent
= 0;
658 /* erratum 0106 ... packets coming in during fifo reads might
659 * be incompletely rejected. not all cases have workarounds.
661 if (ep
->dev
->chiprev
== 0x0100
662 && ep
->dev
->gadget
.speed
== USB_SPEED_FULL
) {
664 tmp
= readl (&ep
->regs
->ep_stat
);
665 if ((tmp
& (1 << NAK_OUT_PACKETS
)))
667 else if ((tmp
& (1 << FIFO_FULL
))) {
668 start_out_naking (ep
);
671 /* else: hope we don't see the problem */
674 /* never overflow the rx buffer. the fifo reads packets until
675 * it sees a short one; we might not be ready for them all.
678 count
= readl (®s
->ep_avail
);
679 if (unlikely (count
== 0)) {
681 tmp
= readl (&ep
->regs
->ep_stat
);
682 count
= readl (®s
->ep_avail
);
683 /* handled that data already? */
684 if (count
== 0 && (tmp
& (1 << NAK_OUT_PACKETS
)) == 0)
688 tmp
= req
->req
.length
- req
->req
.actual
;
690 /* as with DMA, data overflow gets flushed */
691 if ((tmp
% ep
->ep
.maxpacket
) != 0) {
693 "%s out fifo %d bytes, expected %d\n",
694 ep
->ep
.name
, count
, tmp
);
695 req
->req
.status
= -EOVERFLOW
;
697 /* NAK_OUT_PACKETS will be set, so flushing is safe;
698 * the next read will start with the next packet
700 } /* else it's a ZLP, no worries */
703 req
->req
.actual
+= count
;
705 is_short
= (count
== 0) || ((count
% ep
->ep
.maxpacket
) != 0);
707 VDEBUG (ep
->dev
, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
708 ep
->ep
.name
, count
, is_short
? " (short)" : "",
709 cleanup
? " flush" : "", prevent
? " nak" : "",
710 req
, req
->req
.actual
, req
->req
.length
);
713 tmp
= readl (®s
->ep_data
);
715 put_unaligned (tmp
, (u32
*)buf
);
720 tmp
= readl (®s
->ep_data
);
721 /* LE conversion is implicit here: */
730 writel ((1 << CLEAR_NAK_OUT_PACKETS
), &ep
->regs
->ep_rsp
);
731 (void) readl (&ep
->regs
->ep_rsp
);
734 return is_short
|| ((req
->req
.actual
== req
->req
.length
)
738 /* fill out dma descriptor to match a given request */
740 fill_dma_desc (struct net2280_ep
*ep
, struct net2280_request
*req
, int valid
)
742 struct net2280_dma
*td
= req
->td
;
743 u32 dmacount
= req
->req
.length
;
745 /* don't let DMA continue after a short OUT packet,
746 * so overruns can't affect the next transfer.
747 * in case of overruns on max-size packets, we can't
748 * stop the fifo from filling but we can flush it.
751 dmacount
|= (1 << DMA_DIRECTION
);
752 if ((!ep
->is_in
&& (dmacount
% ep
->ep
.maxpacket
) != 0)
753 || ep
->dev
->pdev
->device
!= 0x2280)
754 dmacount
|= (1 << END_OF_CHAIN
);
758 dmacount
|= (1 << VALID_BIT
);
759 if (likely(!req
->req
.no_interrupt
|| !use_dma_chaining
))
760 dmacount
|= (1 << DMA_DONE_INTERRUPT_ENABLE
);
762 /* td->dmadesc = previously set by caller */
763 td
->dmaaddr
= cpu_to_le32 (req
->req
.dma
);
765 /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */
767 td
->dmacount
= cpu_to_le32p (&dmacount
);
770 static const u32 dmactl_default
=
771 (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT
)
772 | (1 << DMA_CLEAR_COUNT_ENABLE
)
773 /* erratum 0116 workaround part 1 (use POLLING) */
774 | (POLL_100_USEC
<< DESCRIPTOR_POLLING_RATE
)
775 | (1 << DMA_VALID_BIT_POLLING_ENABLE
)
776 | (1 << DMA_VALID_BIT_ENABLE
)
777 | (1 << DMA_SCATTER_GATHER_ENABLE
)
778 /* erratum 0116 workaround part 2 (no AUTOSTART) */
781 static inline void spin_stop_dma (struct net2280_dma_regs __iomem
*dma
)
783 handshake (&dma
->dmactl
, (1 << DMA_ENABLE
), 0, 50);
786 static inline void stop_dma (struct net2280_dma_regs __iomem
*dma
)
788 writel (readl (&dma
->dmactl
) & ~(1 << DMA_ENABLE
), &dma
->dmactl
);
792 static void start_queue (struct net2280_ep
*ep
, u32 dmactl
, u32 td_dma
)
794 struct net2280_dma_regs __iomem
*dma
= ep
->dma
;
795 unsigned int tmp
= (1 << VALID_BIT
) | (ep
->is_in
<< DMA_DIRECTION
);
797 if (ep
->dev
->pdev
->device
!= 0x2280)
798 tmp
|= (1 << END_OF_CHAIN
);
800 writel (tmp
, &dma
->dmacount
);
801 writel (readl (&dma
->dmastat
), &dma
->dmastat
);
803 writel (td_dma
, &dma
->dmadesc
);
804 writel (dmactl
, &dma
->dmactl
);
806 /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
807 (void) readl (&ep
->dev
->pci
->pcimstctl
);
809 writel ((1 << DMA_START
), &dma
->dmastat
);
812 stop_out_naking (ep
);
815 static void start_dma (struct net2280_ep
*ep
, struct net2280_request
*req
)
818 struct net2280_dma_regs __iomem
*dma
= ep
->dma
;
820 /* FIXME can't use DMA for ZLPs */
822 /* on this path we "know" there's no dma active (yet) */
823 WARN_ON (readl (&dma
->dmactl
) & (1 << DMA_ENABLE
));
824 writel (0, &ep
->dma
->dmactl
);
826 /* previous OUT packet might have been short */
827 if (!ep
->is_in
&& ((tmp
= readl (&ep
->regs
->ep_stat
))
828 & (1 << NAK_OUT_PACKETS
)) != 0) {
829 writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT
),
832 tmp
= readl (&ep
->regs
->ep_avail
);
834 writel (readl (&dma
->dmastat
), &dma
->dmastat
);
836 /* transfer all/some fifo data */
837 writel (req
->req
.dma
, &dma
->dmaaddr
);
838 tmp
= min (tmp
, req
->req
.length
);
840 /* dma irq, faking scatterlist status */
841 req
->td
->dmacount
= cpu_to_le32 (req
->req
.length
- tmp
);
842 writel ((1 << DMA_DONE_INTERRUPT_ENABLE
)
843 | tmp
, &dma
->dmacount
);
844 req
->td
->dmadesc
= 0;
847 writel ((1 << DMA_ENABLE
), &dma
->dmactl
);
848 writel ((1 << DMA_START
), &dma
->dmastat
);
853 tmp
= dmactl_default
;
855 /* force packet boundaries between dma requests, but prevent the
856 * controller from automagically writing a last "short" packet
857 * (zero length) unless the driver explicitly said to do that.
860 if (likely ((req
->req
.length
% ep
->ep
.maxpacket
) != 0
862 tmp
|= (1 << DMA_FIFO_VALIDATE
);
863 ep
->in_fifo_validate
= 1;
865 ep
->in_fifo_validate
= 0;
868 /* init req->td, pointing to the current dummy */
869 req
->td
->dmadesc
= cpu_to_le32 (ep
->td_dma
);
870 fill_dma_desc (ep
, req
, 1);
872 if (!use_dma_chaining
)
873 req
->td
->dmacount
|= __constant_cpu_to_le32 (1 << END_OF_CHAIN
);
875 start_queue (ep
, tmp
, req
->td_dma
);
879 queue_dma (struct net2280_ep
*ep
, struct net2280_request
*req
, int valid
)
881 struct net2280_dma
*end
;
884 /* swap new dummy for old, link; fill and maybe activate */
890 ep
->td_dma
= req
->td_dma
;
893 end
->dmadesc
= cpu_to_le32 (ep
->td_dma
);
895 fill_dma_desc (ep
, req
, valid
);
899 done (struct net2280_ep
*ep
, struct net2280_request
*req
, int status
)
902 unsigned stopped
= ep
->stopped
;
904 list_del_init (&req
->queue
);
906 if (req
->req
.status
== -EINPROGRESS
)
907 req
->req
.status
= status
;
909 status
= req
->req
.status
;
913 pci_unmap_single (dev
->pdev
, req
->req
.dma
, req
->req
.length
,
914 ep
->is_in
? PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
);
915 req
->req
.dma
= DMA_ADDR_INVALID
;
919 if (status
&& status
!= -ESHUTDOWN
)
920 VDEBUG (dev
, "complete %s req %p stat %d len %u/%u\n",
921 ep
->ep
.name
, &req
->req
, status
,
922 req
->req
.actual
, req
->req
.length
);
924 /* don't modify queue heads during completion callback */
926 spin_unlock (&dev
->lock
);
927 req
->req
.complete (&ep
->ep
, &req
->req
);
928 spin_lock (&dev
->lock
);
929 ep
->stopped
= stopped
;
932 /*-------------------------------------------------------------------------*/
935 net2280_queue (struct usb_ep
*_ep
, struct usb_request
*_req
, gfp_t gfp_flags
)
937 struct net2280_request
*req
;
938 struct net2280_ep
*ep
;
942 /* we always require a cpu-view buffer, so that we can
943 * always use pio (as fallback or whatever).
945 req
= container_of (_req
, struct net2280_request
, req
);
946 if (!_req
|| !_req
->complete
|| !_req
->buf
947 || !list_empty (&req
->queue
))
949 if (_req
->length
> (~0 & DMA_BYTE_COUNT_MASK
))
951 ep
= container_of (_ep
, struct net2280_ep
, ep
);
952 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0))
955 if (!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
958 /* FIXME implement PIO fallback for ZLPs with DMA */
959 if (ep
->dma
&& _req
->length
== 0)
962 /* set up dma mapping in case the caller didn't */
963 if (ep
->dma
&& _req
->dma
== DMA_ADDR_INVALID
) {
964 _req
->dma
= pci_map_single (dev
->pdev
, _req
->buf
, _req
->length
,
965 ep
->is_in
? PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
);
970 VDEBUG (dev
, "%s queue req %p, len %d buf %p\n",
971 _ep
->name
, _req
, _req
->length
, _req
->buf
);
974 spin_lock_irqsave (&dev
->lock
, flags
);
976 _req
->status
= -EINPROGRESS
;
979 /* kickstart this i/o queue? */
980 if (list_empty (&ep
->queue
) && !ep
->stopped
) {
981 /* use DMA if the endpoint supports it, else pio */
985 /* maybe there's no control data, just status ack */
986 if (ep
->num
== 0 && _req
->length
== 0) {
989 VDEBUG (dev
, "%s status ack\n", ep
->ep
.name
);
993 /* PIO ... stuff the fifo, or unblock it. */
995 write_fifo (ep
, _req
);
996 else if (list_empty (&ep
->queue
)) {
999 /* OUT FIFO might have packet(s) buffered */
1000 s
= readl (&ep
->regs
->ep_stat
);
1001 if ((s
& (1 << FIFO_EMPTY
)) == 0) {
1002 /* note: _req->short_not_ok is
1003 * ignored here since PIO _always_
1004 * stops queue advance here, and
1005 * _req->status doesn't change for
1006 * short reads (only _req->actual)
1008 if (read_fifo (ep
, req
)) {
1012 /* don't queue it */
1015 s
= readl (&ep
->regs
->ep_stat
);
1018 /* don't NAK, let the fifo fill */
1019 if (req
&& (s
& (1 << NAK_OUT_PACKETS
)))
1020 writel ((1 << CLEAR_NAK_OUT_PACKETS
),
1025 } else if (ep
->dma
) {
1031 /* preventing magic zlps is per-engine state, not
1032 * per-transfer; irq logic must recover hiccups.
1034 expect
= likely (req
->req
.zero
1035 || (req
->req
.length
% ep
->ep
.maxpacket
) != 0);
1036 if (expect
!= ep
->in_fifo_validate
)
1039 queue_dma (ep
, req
, valid
);
1041 } /* else the irq handler advances the queue. */
1044 list_add_tail (&req
->queue
, &ep
->queue
);
1046 spin_unlock_irqrestore (&dev
->lock
, flags
);
1048 /* pci writes may still be posted */
1054 struct net2280_ep
*ep
,
1055 struct net2280_request
*req
,
1060 req
->req
.actual
= req
->req
.length
- (DMA_BYTE_COUNT_MASK
& dmacount
);
1061 done (ep
, req
, status
);
1064 static void restart_dma (struct net2280_ep
*ep
);
1066 static void scan_dma_completions (struct net2280_ep
*ep
)
1068 /* only look at descriptors that were "naturally" retired,
1069 * so fifo and list head state won't matter
1071 while (!list_empty (&ep
->queue
)) {
1072 struct net2280_request
*req
;
1075 req
= list_entry (ep
->queue
.next
,
1076 struct net2280_request
, queue
);
1080 tmp
= le32_to_cpup (&req
->td
->dmacount
);
1081 if ((tmp
& (1 << VALID_BIT
)) != 0)
1084 /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
1085 * cases where DMA must be aborted; this code handles
1086 * all non-abort DMA completions.
1088 if (unlikely (req
->td
->dmadesc
== 0)) {
1090 tmp
= readl (&ep
->dma
->dmacount
);
1091 if (tmp
& DMA_BYTE_COUNT_MASK
)
1093 /* single transfer mode */
1094 dma_done (ep
, req
, tmp
, 0);
1096 } else if (!ep
->is_in
1097 && (req
->req
.length
% ep
->ep
.maxpacket
) != 0) {
1098 tmp
= readl (&ep
->regs
->ep_stat
);
1100 /* AVOID TROUBLE HERE by not issuing short reads from
1101 * your gadget driver. That helps avoids errata 0121,
1102 * 0122, and 0124; not all cases trigger the warning.
1104 if ((tmp
& (1 << NAK_OUT_PACKETS
)) == 0) {
1105 WARN (ep
->dev
, "%s lost packet sync!\n",
1107 req
->req
.status
= -EOVERFLOW
;
1108 } else if ((tmp
= readl (&ep
->regs
->ep_avail
)) != 0) {
1109 /* fifo gets flushed later */
1110 ep
->out_overflow
= 1;
1111 DEBUG (ep
->dev
, "%s dma, discard %d len %d\n",
1114 req
->req
.status
= -EOVERFLOW
;
1117 dma_done (ep
, req
, tmp
, 0);
1121 static void restart_dma (struct net2280_ep
*ep
)
1123 struct net2280_request
*req
;
1124 u32 dmactl
= dmactl_default
;
1128 req
= list_entry (ep
->queue
.next
, struct net2280_request
, queue
);
1130 if (!use_dma_chaining
) {
1131 start_dma (ep
, req
);
1135 /* the 2280 will be processing the queue unless queue hiccups after
1136 * the previous transfer:
1137 * IN: wanted automagic zlp, head doesn't (or vice versa)
1138 * DMA_FIFO_VALIDATE doesn't init from dma descriptors.
1139 * OUT: was "usb-short", we must restart.
1141 if (ep
->is_in
&& !req
->valid
) {
1142 struct net2280_request
*entry
, *prev
= NULL
;
1143 int reqmode
, done
= 0;
1145 DEBUG (ep
->dev
, "%s dma hiccup td %p\n", ep
->ep
.name
, req
->td
);
1146 ep
->in_fifo_validate
= likely (req
->req
.zero
1147 || (req
->req
.length
% ep
->ep
.maxpacket
) != 0);
1148 if (ep
->in_fifo_validate
)
1149 dmactl
|= (1 << DMA_FIFO_VALIDATE
);
1150 list_for_each_entry (entry
, &ep
->queue
, queue
) {
1155 dmacount
= entry
->td
->dmacount
;
1157 reqmode
= likely (entry
->req
.zero
1158 || (entry
->req
.length
1159 % ep
->ep
.maxpacket
) != 0);
1160 if (reqmode
== ep
->in_fifo_validate
) {
1162 dmacount
|= valid_bit
;
1163 entry
->td
->dmacount
= dmacount
;
1167 /* force a hiccup */
1168 prev
->td
->dmacount
|= dma_done_ie
;
1173 /* walk the rest of the queue so unlinks behave */
1175 dmacount
&= ~valid_bit
;
1176 entry
->td
->dmacount
= dmacount
;
1181 writel (0, &ep
->dma
->dmactl
);
1182 start_queue (ep
, dmactl
, req
->td_dma
);
1185 static void abort_dma (struct net2280_ep
*ep
)
1187 /* abort the current transfer */
1188 if (likely (!list_empty (&ep
->queue
))) {
1189 /* FIXME work around errata 0121, 0122, 0124 */
1190 writel ((1 << DMA_ABORT
), &ep
->dma
->dmastat
);
1191 spin_stop_dma (ep
->dma
);
1194 scan_dma_completions (ep
);
1197 /* dequeue ALL requests */
1198 static void nuke (struct net2280_ep
*ep
)
1200 struct net2280_request
*req
;
1202 /* called with spinlock held */
1206 while (!list_empty (&ep
->queue
)) {
1207 req
= list_entry (ep
->queue
.next
,
1208 struct net2280_request
,
1210 done (ep
, req
, -ESHUTDOWN
);
1214 /* dequeue JUST ONE request */
1215 static int net2280_dequeue (struct usb_ep
*_ep
, struct usb_request
*_req
)
1217 struct net2280_ep
*ep
;
1218 struct net2280_request
*req
;
1219 unsigned long flags
;
1223 ep
= container_of (_ep
, struct net2280_ep
, ep
);
1224 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0) || !_req
)
1227 spin_lock_irqsave (&ep
->dev
->lock
, flags
);
1228 stopped
= ep
->stopped
;
1230 /* quiesce dma while we patch the queue */
1234 dmactl
= readl (&ep
->dma
->dmactl
);
1235 /* WARNING erratum 0127 may kick in ... */
1237 scan_dma_completions (ep
);
1240 /* make sure it's still queued on this endpoint */
1241 list_for_each_entry (req
, &ep
->queue
, queue
) {
1242 if (&req
->req
== _req
)
1245 if (&req
->req
!= _req
) {
1246 spin_unlock_irqrestore (&ep
->dev
->lock
, flags
);
1250 /* queue head may be partially complete. */
1251 if (ep
->queue
.next
== &req
->queue
) {
1253 DEBUG (ep
->dev
, "unlink (%s) dma\n", _ep
->name
);
1254 _req
->status
= -ECONNRESET
;
1256 if (likely (ep
->queue
.next
== &req
->queue
)) {
1257 // NOTE: misreports single-transfer mode
1258 req
->td
->dmacount
= 0; /* invalidate */
1260 readl (&ep
->dma
->dmacount
),
1264 DEBUG (ep
->dev
, "unlink (%s) pio\n", _ep
->name
);
1265 done (ep
, req
, -ECONNRESET
);
1269 /* patch up hardware chaining data */
1270 } else if (ep
->dma
&& use_dma_chaining
) {
1271 if (req
->queue
.prev
== ep
->queue
.next
) {
1272 writel (le32_to_cpu (req
->td
->dmadesc
),
1274 if (req
->td
->dmacount
& dma_done_ie
)
1275 writel (readl (&ep
->dma
->dmacount
)
1276 | le32_to_cpu(dma_done_ie
),
1277 &ep
->dma
->dmacount
);
1279 struct net2280_request
*prev
;
1281 prev
= list_entry (req
->queue
.prev
,
1282 struct net2280_request
, queue
);
1283 prev
->td
->dmadesc
= req
->td
->dmadesc
;
1284 if (req
->td
->dmacount
& dma_done_ie
)
1285 prev
->td
->dmacount
|= dma_done_ie
;
1290 done (ep
, req
, -ECONNRESET
);
1291 ep
->stopped
= stopped
;
1294 /* turn off dma on inactive queues */
1295 if (list_empty (&ep
->queue
))
1297 else if (!ep
->stopped
) {
1298 /* resume current request, or start new one */
1300 writel (dmactl
, &ep
->dma
->dmactl
);
1302 start_dma (ep
, list_entry (ep
->queue
.next
,
1303 struct net2280_request
, queue
));
1307 spin_unlock_irqrestore (&ep
->dev
->lock
, flags
);
1311 /*-------------------------------------------------------------------------*/
1313 static int net2280_fifo_status (struct usb_ep
*_ep
);
1316 net2280_set_halt (struct usb_ep
*_ep
, int value
)
1318 struct net2280_ep
*ep
;
1319 unsigned long flags
;
1322 ep
= container_of (_ep
, struct net2280_ep
, ep
);
1323 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0))
1325 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1327 if (ep
->desc
/* not ep0 */ && (ep
->desc
->bmAttributes
& 0x03)
1328 == USB_ENDPOINT_XFER_ISOC
)
1331 spin_lock_irqsave (&ep
->dev
->lock
, flags
);
1332 if (!list_empty (&ep
->queue
))
1334 else if (ep
->is_in
&& value
&& net2280_fifo_status (_ep
) != 0)
1337 VDEBUG (ep
->dev
, "%s %s halt\n", _ep
->name
,
1338 value
? "set" : "clear");
1339 /* set/clear, then synch memory views with the device */
1342 ep
->dev
->protocol_stall
= 1;
1347 (void) readl (&ep
->regs
->ep_rsp
);
1349 spin_unlock_irqrestore (&ep
->dev
->lock
, flags
);
1355 net2280_fifo_status (struct usb_ep
*_ep
)
1357 struct net2280_ep
*ep
;
1360 ep
= container_of (_ep
, struct net2280_ep
, ep
);
1361 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0))
1363 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1366 avail
= readl (&ep
->regs
->ep_avail
) & ((1 << 12) - 1);
1367 if (avail
> ep
->fifo_size
)
1370 avail
= ep
->fifo_size
- avail
;
1375 net2280_fifo_flush (struct usb_ep
*_ep
)
1377 struct net2280_ep
*ep
;
1379 ep
= container_of (_ep
, struct net2280_ep
, ep
);
1380 if (!_ep
|| (!ep
->desc
&& ep
->num
!= 0))
1382 if (!ep
->dev
->driver
|| ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1385 writel ((1 << FIFO_FLUSH
), &ep
->regs
->ep_stat
);
1386 (void) readl (&ep
->regs
->ep_rsp
);
1389 static const struct usb_ep_ops net2280_ep_ops
= {
1390 .enable
= net2280_enable
,
1391 .disable
= net2280_disable
,
1393 .alloc_request
= net2280_alloc_request
,
1394 .free_request
= net2280_free_request
,
1396 .alloc_buffer
= net2280_alloc_buffer
,
1397 .free_buffer
= net2280_free_buffer
,
1399 .queue
= net2280_queue
,
1400 .dequeue
= net2280_dequeue
,
1402 .set_halt
= net2280_set_halt
,
1403 .fifo_status
= net2280_fifo_status
,
1404 .fifo_flush
= net2280_fifo_flush
,
1407 /*-------------------------------------------------------------------------*/
1409 static int net2280_get_frame (struct usb_gadget
*_gadget
)
1411 struct net2280
*dev
;
1412 unsigned long flags
;
1417 dev
= container_of (_gadget
, struct net2280
, gadget
);
1418 spin_lock_irqsave (&dev
->lock
, flags
);
1419 retval
= get_idx_reg (dev
->regs
, REG_FRAME
) & 0x03ff;
1420 spin_unlock_irqrestore (&dev
->lock
, flags
);
1424 static int net2280_wakeup (struct usb_gadget
*_gadget
)
1426 struct net2280
*dev
;
1428 unsigned long flags
;
1432 dev
= container_of (_gadget
, struct net2280
, gadget
);
1434 spin_lock_irqsave (&dev
->lock
, flags
);
1435 tmp
= readl (&dev
->usb
->usbctl
);
1436 if (tmp
& (1 << DEVICE_REMOTE_WAKEUP_ENABLE
))
1437 writel (1 << GENERATE_RESUME
, &dev
->usb
->usbstat
);
1438 spin_unlock_irqrestore (&dev
->lock
, flags
);
1440 /* pci writes may still be posted */
1444 static int net2280_set_selfpowered (struct usb_gadget
*_gadget
, int value
)
1446 struct net2280
*dev
;
1448 unsigned long flags
;
1452 dev
= container_of (_gadget
, struct net2280
, gadget
);
1454 spin_lock_irqsave (&dev
->lock
, flags
);
1455 tmp
= readl (&dev
->usb
->usbctl
);
1457 tmp
|= (1 << SELF_POWERED_STATUS
);
1459 tmp
&= ~(1 << SELF_POWERED_STATUS
);
1460 writel (tmp
, &dev
->usb
->usbctl
);
1461 spin_unlock_irqrestore (&dev
->lock
, flags
);
1466 static int net2280_pullup(struct usb_gadget
*_gadget
, int is_on
)
1468 struct net2280
*dev
;
1470 unsigned long flags
;
1474 dev
= container_of (_gadget
, struct net2280
, gadget
);
1476 spin_lock_irqsave (&dev
->lock
, flags
);
1477 tmp
= readl (&dev
->usb
->usbctl
);
1478 dev
->softconnect
= (is_on
!= 0);
1480 tmp
|= (1 << USB_DETECT_ENABLE
);
1482 tmp
&= ~(1 << USB_DETECT_ENABLE
);
1483 writel (tmp
, &dev
->usb
->usbctl
);
1484 spin_unlock_irqrestore (&dev
->lock
, flags
);
1489 static const struct usb_gadget_ops net2280_ops
= {
1490 .get_frame
= net2280_get_frame
,
1491 .wakeup
= net2280_wakeup
,
1492 .set_selfpowered
= net2280_set_selfpowered
,
1493 .pullup
= net2280_pullup
,
1496 /*-------------------------------------------------------------------------*/
1498 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1500 /* FIXME move these into procfs, and use seq_file.
1501 * Sysfs _still_ doesn't behave for arbitrarily sized files,
1502 * and also doesn't help products using this with 2.4 kernels.
1505 /* "function" sysfs attribute */
1507 show_function (struct device
*_dev
, struct device_attribute
*attr
, char *buf
)
1509 struct net2280
*dev
= dev_get_drvdata (_dev
);
1512 || !dev
->driver
->function
1513 || strlen (dev
->driver
->function
) > PAGE_SIZE
)
1515 return scnprintf (buf
, PAGE_SIZE
, "%s\n", dev
->driver
->function
);
1517 static DEVICE_ATTR (function
, S_IRUGO
, show_function
, NULL
);
1520 show_registers (struct device
*_dev
, struct device_attribute
*attr
, char *buf
)
1522 struct net2280
*dev
;
1525 unsigned long flags
;
1530 dev
= dev_get_drvdata (_dev
);
1533 spin_lock_irqsave (&dev
->lock
, flags
);
1536 s
= dev
->driver
->driver
.name
;
1540 /* Main Control Registers */
1541 t
= scnprintf (next
, size
, "%s version " DRIVER_VERSION
1542 ", chiprev %04x, dma %s\n\n"
1543 "devinit %03x fifoctl %08x gadget '%s'\n"
1544 "pci irqenb0 %02x irqenb1 %08x "
1545 "irqstat0 %04x irqstat1 %08x\n",
1546 driver_name
, dev
->chiprev
,
1548 ? (use_dma_chaining
? "chaining" : "enabled")
1550 readl (&dev
->regs
->devinit
),
1551 readl (&dev
->regs
->fifoctl
),
1553 readl (&dev
->regs
->pciirqenb0
),
1554 readl (&dev
->regs
->pciirqenb1
),
1555 readl (&dev
->regs
->irqstat0
),
1556 readl (&dev
->regs
->irqstat1
));
1560 /* USB Control Registers */
1561 t1
= readl (&dev
->usb
->usbctl
);
1562 t2
= readl (&dev
->usb
->usbstat
);
1563 if (t1
& (1 << VBUS_PIN
)) {
1564 if (t2
& (1 << HIGH_SPEED
))
1566 else if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1570 /* full speed bit (6) not working?? */
1573 t
= scnprintf (next
, size
,
1574 "stdrsp %08x usbctl %08x usbstat %08x "
1575 "addr 0x%02x (%s)\n",
1576 readl (&dev
->usb
->stdrsp
), t1
, t2
,
1577 readl (&dev
->usb
->ouraddr
), s
);
1581 /* PCI Master Control Registers */
1583 /* DMA Control Registers */
1585 /* Configurable EP Control Registers */
1586 for (i
= 0; i
< 7; i
++) {
1587 struct net2280_ep
*ep
;
1593 t1
= readl (&ep
->regs
->ep_cfg
);
1594 t2
= readl (&ep
->regs
->ep_rsp
) & 0xff;
1595 t
= scnprintf (next
, size
,
1596 "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
1598 ep
->ep
.name
, t1
, t2
,
1599 (t2
& (1 << CLEAR_NAK_OUT_PACKETS
))
1601 (t2
& (1 << CLEAR_EP_HIDE_STATUS_PHASE
))
1603 (t2
& (1 << CLEAR_EP_FORCE_CRC_ERROR
))
1605 (t2
& (1 << CLEAR_INTERRUPT_MODE
))
1606 ? "interrupt " : "",
1607 (t2
& (1<<CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE
))
1609 (t2
& (1 << CLEAR_NAK_OUT_PACKETS_MODE
))
1611 (t2
& (1 << CLEAR_ENDPOINT_TOGGLE
))
1612 ? "DATA1 " : "DATA0 ",
1613 (t2
& (1 << CLEAR_ENDPOINT_HALT
))
1615 readl (&ep
->regs
->ep_irqenb
));
1619 t
= scnprintf (next
, size
,
1620 "\tstat %08x avail %04x "
1622 readl (&ep
->regs
->ep_stat
),
1623 readl (&ep
->regs
->ep_avail
),
1624 t1
& 0x0f, DIR_STRING (t1
),
1625 type_string (t1
>> 8),
1626 ep
->stopped
? "*" : "");
1633 t
= scnprintf (next
, size
,
1634 " dma\tctl %08x stat %08x count %08x\n"
1635 "\taddr %08x desc %08x\n",
1636 readl (&ep
->dma
->dmactl
),
1637 readl (&ep
->dma
->dmastat
),
1638 readl (&ep
->dma
->dmacount
),
1639 readl (&ep
->dma
->dmaaddr
),
1640 readl (&ep
->dma
->dmadesc
));
1646 /* Indexed Registers */
1650 t
= scnprintf (next
, size
, "\nirqs: ");
1653 for (i
= 0; i
< 7; i
++) {
1654 struct net2280_ep
*ep
;
1659 t
= scnprintf (next
, size
, " %s/%lu", ep
->ep
.name
, ep
->irqs
);
1664 t
= scnprintf (next
, size
, "\n");
1668 spin_unlock_irqrestore (&dev
->lock
, flags
);
1670 return PAGE_SIZE
- size
;
1672 static DEVICE_ATTR (registers
, S_IRUGO
, show_registers
, NULL
);
1675 show_queues (struct device
*_dev
, struct device_attribute
*attr
, char *buf
)
1677 struct net2280
*dev
;
1680 unsigned long flags
;
1683 dev
= dev_get_drvdata (_dev
);
1686 spin_lock_irqsave (&dev
->lock
, flags
);
1688 for (i
= 0; i
< 7; i
++) {
1689 struct net2280_ep
*ep
= &dev
->ep
[i
];
1690 struct net2280_request
*req
;
1694 const struct usb_endpoint_descriptor
*d
;
1699 t
= d
->bEndpointAddress
;
1700 t
= scnprintf (next
, size
,
1701 "\n%s (ep%d%s-%s) max %04x %s fifo %d\n",
1702 ep
->ep
.name
, t
& USB_ENDPOINT_NUMBER_MASK
,
1703 (t
& USB_DIR_IN
) ? "in" : "out",
1705 switch (d
->bmAttributes
& 0x03) {
1706 case USB_ENDPOINT_XFER_BULK
:
1707 val
= "bulk"; break;
1708 case USB_ENDPOINT_XFER_INT
:
1709 val
= "intr"; break;
1713 le16_to_cpu (d
->wMaxPacketSize
) & 0x1fff,
1714 ep
->dma
? "dma" : "pio", ep
->fifo_size
1716 } else /* ep0 should only have one transfer queued */
1717 t
= scnprintf (next
, size
, "ep0 max 64 pio %s\n",
1718 ep
->is_in
? "in" : "out");
1719 if (t
<= 0 || t
> size
)
1724 if (list_empty (&ep
->queue
)) {
1725 t
= scnprintf (next
, size
, "\t(nothing queued)\n");
1726 if (t
<= 0 || t
> size
)
1732 list_for_each_entry (req
, &ep
->queue
, queue
) {
1733 if (ep
->dma
&& req
->td_dma
== readl (&ep
->dma
->dmadesc
))
1734 t
= scnprintf (next
, size
,
1735 "\treq %p len %d/%d "
1736 "buf %p (dmacount %08x)\n",
1737 &req
->req
, req
->req
.actual
,
1738 req
->req
.length
, req
->req
.buf
,
1739 readl (&ep
->dma
->dmacount
));
1741 t
= scnprintf (next
, size
,
1742 "\treq %p len %d/%d buf %p\n",
1743 &req
->req
, req
->req
.actual
,
1744 req
->req
.length
, req
->req
.buf
);
1745 if (t
<= 0 || t
> size
)
1751 struct net2280_dma
*td
;
1754 t
= scnprintf (next
, size
, "\t td %08x "
1755 " count %08x buf %08x desc %08x\n",
1757 le32_to_cpu (td
->dmacount
),
1758 le32_to_cpu (td
->dmaaddr
),
1759 le32_to_cpu (td
->dmadesc
));
1760 if (t
<= 0 || t
> size
)
1769 spin_unlock_irqrestore (&dev
->lock
, flags
);
1770 return PAGE_SIZE
- size
;
1772 static DEVICE_ATTR (queues
, S_IRUGO
, show_queues
, NULL
);
1777 #define device_create_file(a,b) do {} while (0)
1778 #define device_remove_file device_create_file
1782 /*-------------------------------------------------------------------------*/
1784 /* another driver-specific mode might be a request type doing dma
1785 * to/from another device fifo instead of to/from memory.
1788 static void set_fifo_mode (struct net2280
*dev
, int mode
)
1790 /* keeping high bits preserves BAR2 */
1791 writel ((0xffff << PCI_BASE2_RANGE
) | mode
, &dev
->regs
->fifoctl
);
1793 /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */
1794 INIT_LIST_HEAD (&dev
->gadget
.ep_list
);
1795 list_add_tail (&dev
->ep
[1].ep
.ep_list
, &dev
->gadget
.ep_list
);
1796 list_add_tail (&dev
->ep
[2].ep
.ep_list
, &dev
->gadget
.ep_list
);
1799 list_add_tail (&dev
->ep
[3].ep
.ep_list
, &dev
->gadget
.ep_list
);
1800 list_add_tail (&dev
->ep
[4].ep
.ep_list
, &dev
->gadget
.ep_list
);
1801 dev
->ep
[1].fifo_size
= dev
->ep
[2].fifo_size
= 1024;
1804 dev
->ep
[1].fifo_size
= dev
->ep
[2].fifo_size
= 2048;
1807 list_add_tail (&dev
->ep
[3].ep
.ep_list
, &dev
->gadget
.ep_list
);
1808 dev
->ep
[1].fifo_size
= 2048;
1809 dev
->ep
[2].fifo_size
= 1024;
1812 /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */
1813 list_add_tail (&dev
->ep
[5].ep
.ep_list
, &dev
->gadget
.ep_list
);
1814 list_add_tail (&dev
->ep
[6].ep
.ep_list
, &dev
->gadget
.ep_list
);
1817 /* just declare this in any driver that really need it */
1818 extern int net2280_set_fifo_mode (struct usb_gadget
*gadget
, int mode
);
1821 * net2280_set_fifo_mode - change allocation of fifo buffers
1822 * @gadget: access to the net2280 device that will be updated
1823 * @mode: 0 for default, four 1kB buffers (ep-a through ep-d);
1824 * 1 for two 2kB buffers (ep-a and ep-b only);
1825 * 2 for one 2kB buffer (ep-a) and two 1kB ones (ep-b, ep-c).
1827 * returns zero on success, else negative errno. when this succeeds,
1828 * the contents of gadget->ep_list may have changed.
1830 * you may only call this function when endpoints a-d are all disabled.
1831 * use it whenever extra hardware buffering can help performance, such
1832 * as before enabling "high bandwidth" interrupt endpoints that use
1833 * maxpacket bigger than 512 (when double buffering would otherwise
1836 int net2280_set_fifo_mode (struct usb_gadget
*gadget
, int mode
)
1839 struct net2280
*dev
;
1841 unsigned long flags
;
1845 dev
= container_of (gadget
, struct net2280
, gadget
);
1847 spin_lock_irqsave (&dev
->lock
, flags
);
1849 for (i
= 1; i
<= 4; i
++)
1850 if (dev
->ep
[i
].desc
) {
1854 if (mode
< 0 || mode
> 2)
1857 set_fifo_mode (dev
, mode
);
1858 spin_unlock_irqrestore (&dev
->lock
, flags
);
1862 DEBUG (dev
, "fifo: ep-a 2K, ep-b 2K\n");
1864 DEBUG (dev
, "fifo: ep-a 2K, ep-b 1K, ep-c 1K\n");
1865 /* else all are 1K */
1869 EXPORT_SYMBOL (net2280_set_fifo_mode
);
1871 /*-------------------------------------------------------------------------*/
1873 /* keeping it simple:
1874 * - one bus driver, initted first;
1875 * - one function driver, initted second
1877 * most of the work to support multiple net2280 controllers would
1878 * be to associate this gadget driver (yes?) with all of them, or
1879 * perhaps to bind specific drivers to specific devices.
1882 static struct net2280
*the_controller
;
1884 static void usb_reset (struct net2280
*dev
)
1888 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1889 (void) readl (&dev
->usb
->usbctl
);
1891 net2280_led_init (dev
);
1893 /* disable automatic responses, and irqs */
1894 writel (0, &dev
->usb
->stdrsp
);
1895 writel (0, &dev
->regs
->pciirqenb0
);
1896 writel (0, &dev
->regs
->pciirqenb1
);
1898 /* clear old dma and irq state */
1899 for (tmp
= 0; tmp
< 4; tmp
++) {
1900 struct net2280_ep
*ep
= &dev
->ep
[tmp
+ 1];
1905 writel (~0, &dev
->regs
->irqstat0
),
1906 writel (~(1 << SUSPEND_REQUEST_INTERRUPT
), &dev
->regs
->irqstat1
),
1908 /* reset, and enable pci */
1909 tmp
= readl (&dev
->regs
->devinit
)
1911 | (1 << FIFO_SOFT_RESET
)
1912 | (1 << USB_SOFT_RESET
)
1913 | (1 << M8051_RESET
);
1914 writel (tmp
, &dev
->regs
->devinit
);
1916 /* standard fifo and endpoint allocations */
1917 set_fifo_mode (dev
, (fifo_mode
<= 2) ? fifo_mode
: 0);
1920 static void usb_reinit (struct net2280
*dev
)
1925 /* use_dma changes are ignored till next device re-init */
1928 /* basic endpoint init */
1929 for (tmp
= 0; tmp
< 7; tmp
++) {
1930 struct net2280_ep
*ep
= &dev
->ep
[tmp
];
1932 ep
->ep
.name
= ep_name
[tmp
];
1936 if (tmp
> 0 && tmp
<= 4) {
1937 ep
->fifo_size
= 1024;
1939 ep
->dma
= &dev
->dma
[tmp
- 1];
1942 ep
->regs
= &dev
->epregs
[tmp
];
1943 ep_reset (dev
->regs
, ep
);
1945 dev
->ep
[0].ep
.maxpacket
= 64;
1946 dev
->ep
[5].ep
.maxpacket
= 64;
1947 dev
->ep
[6].ep
.maxpacket
= 64;
1949 dev
->gadget
.ep0
= &dev
->ep
[0].ep
;
1950 dev
->ep
[0].stopped
= 0;
1951 INIT_LIST_HEAD (&dev
->gadget
.ep0
->ep_list
);
1953 /* we want to prevent lowlevel/insecure access from the USB host,
1954 * but erratum 0119 means this enable bit is ignored
1956 for (tmp
= 0; tmp
< 5; tmp
++)
1957 writel (EP_DONTUSE
, &dev
->dep
[tmp
].dep_cfg
);
1960 static void ep0_start (struct net2280
*dev
)
1962 writel ( (1 << CLEAR_EP_HIDE_STATUS_PHASE
)
1963 | (1 << CLEAR_NAK_OUT_PACKETS
)
1964 | (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE
)
1965 , &dev
->epregs
[0].ep_rsp
);
1968 * hardware optionally handles a bunch of standard requests
1969 * that the API hides from drivers anyway. have it do so.
1970 * endpoint status/features are handled in software, to
1971 * help pass tests for some dubious behavior.
1973 writel ( (1 << SET_TEST_MODE
)
1974 | (1 << SET_ADDRESS
)
1975 | (1 << DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP
)
1976 | (1 << GET_DEVICE_STATUS
)
1977 | (1 << GET_INTERFACE_STATUS
)
1978 , &dev
->usb
->stdrsp
);
1979 writel ( (1 << USB_ROOT_PORT_WAKEUP_ENABLE
)
1980 | (1 << SELF_POWERED_USB_DEVICE
)
1981 | (1 << REMOTE_WAKEUP_SUPPORT
)
1982 | (dev
->softconnect
<< USB_DETECT_ENABLE
)
1983 | (1 << SELF_POWERED_STATUS
)
1984 , &dev
->usb
->usbctl
);
1986 /* enable irqs so we can see ep0 and general operation */
1987 writel ( (1 << SETUP_PACKET_INTERRUPT_ENABLE
)
1988 | (1 << ENDPOINT_0_INTERRUPT_ENABLE
)
1989 , &dev
->regs
->pciirqenb0
);
1990 writel ( (1 << PCI_INTERRUPT_ENABLE
)
1991 | (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE
)
1992 | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE
)
1993 | (1 << PCI_RETRY_ABORT_INTERRUPT_ENABLE
)
1994 | (1 << VBUS_INTERRUPT_ENABLE
)
1995 | (1 << ROOT_PORT_RESET_INTERRUPT_ENABLE
)
1996 | (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE
)
1997 , &dev
->regs
->pciirqenb1
);
1999 /* don't leave any writes posted */
2000 (void) readl (&dev
->usb
->usbctl
);
2003 /* when a driver is successfully registered, it will receive
2004 * control requests including set_configuration(), which enables
2005 * non-control requests. then usb traffic follows until a
2006 * disconnect is reported. then a host may connect again, or
2007 * the driver might get unbound.
2009 int usb_gadget_register_driver (struct usb_gadget_driver
*driver
)
2011 struct net2280
*dev
= the_controller
;
2015 /* insist on high speed support from the driver, since
2016 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
2017 * "must not be used in normal operation"
2020 || driver
->speed
!= USB_SPEED_HIGH
2030 for (i
= 0; i
< 7; i
++)
2031 dev
->ep
[i
].irqs
= 0;
2033 /* hook up the driver ... */
2034 dev
->softconnect
= 1;
2035 driver
->driver
.bus
= NULL
;
2036 dev
->driver
= driver
;
2037 dev
->gadget
.dev
.driver
= &driver
->driver
;
2038 retval
= driver
->bind (&dev
->gadget
);
2040 DEBUG (dev
, "bind to driver %s --> %d\n",
2041 driver
->driver
.name
, retval
);
2043 dev
->gadget
.dev
.driver
= NULL
;
2047 retval
= device_create_file (&dev
->pdev
->dev
, &dev_attr_function
);
2048 if (retval
) goto err_unbind
;
2049 retval
= device_create_file (&dev
->pdev
->dev
, &dev_attr_queues
);
2050 if (retval
) goto err_func
;
2052 /* ... then enable host detection and ep0; and we're ready
2053 * for set_configuration as well as eventual disconnect.
2055 net2280_led_active (dev
, 1);
2058 DEBUG (dev
, "%s ready, usbctl %08x stdrsp %08x\n",
2059 driver
->driver
.name
,
2060 readl (&dev
->usb
->usbctl
),
2061 readl (&dev
->usb
->stdrsp
));
2063 /* pci writes may still be posted */
2067 device_remove_file (&dev
->pdev
->dev
, &dev_attr_function
);
2069 driver
->unbind (&dev
->gadget
);
2070 dev
->gadget
.dev
.driver
= NULL
;
2074 EXPORT_SYMBOL (usb_gadget_register_driver
);
2077 stop_activity (struct net2280
*dev
, struct usb_gadget_driver
*driver
)
2081 /* don't disconnect if it's not connected */
2082 if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
2085 /* stop hardware; prevent new request submissions;
2086 * and kill any outstanding requests.
2089 for (i
= 0; i
< 7; i
++)
2090 nuke (&dev
->ep
[i
]);
2092 /* report disconnect; the driver is already quiesced */
2094 spin_unlock (&dev
->lock
);
2095 driver
->disconnect (&dev
->gadget
);
2096 spin_lock (&dev
->lock
);
2102 int usb_gadget_unregister_driver (struct usb_gadget_driver
*driver
)
2104 struct net2280
*dev
= the_controller
;
2105 unsigned long flags
;
2109 if (!driver
|| driver
!= dev
->driver
)
2112 spin_lock_irqsave (&dev
->lock
, flags
);
2113 stop_activity (dev
, driver
);
2114 spin_unlock_irqrestore (&dev
->lock
, flags
);
2116 net2280_pullup (&dev
->gadget
, 0);
2118 driver
->unbind (&dev
->gadget
);
2119 dev
->gadget
.dev
.driver
= NULL
;
2122 net2280_led_active (dev
, 0);
2123 device_remove_file (&dev
->pdev
->dev
, &dev_attr_function
);
2124 device_remove_file (&dev
->pdev
->dev
, &dev_attr_queues
);
2126 DEBUG (dev
, "unregistered driver '%s'\n", driver
->driver
.name
);
2129 EXPORT_SYMBOL (usb_gadget_unregister_driver
);
2132 /*-------------------------------------------------------------------------*/
2134 /* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq.
2135 * also works for dma-capable endpoints, in pio mode or just
2136 * to manually advance the queue after short OUT transfers.
2138 static void handle_ep_small (struct net2280_ep
*ep
)
2140 struct net2280_request
*req
;
2142 /* 0 error, 1 mid-data, 2 done */
2145 if (!list_empty (&ep
->queue
))
2146 req
= list_entry (ep
->queue
.next
,
2147 struct net2280_request
, queue
);
2151 /* ack all, and handle what we care about */
2152 t
= readl (&ep
->regs
->ep_stat
);
2155 VDEBUG (ep
->dev
, "%s ack ep_stat %08x, req %p\n",
2156 ep
->ep
.name
, t
, req
? &req
->req
: 0);
2158 if (!ep
->is_in
|| ep
->dev
->pdev
->device
== 0x2280)
2159 writel (t
& ~(1 << NAK_OUT_PACKETS
), &ep
->regs
->ep_stat
);
2161 /* Added for 2282 */
2162 writel (t
, &ep
->regs
->ep_stat
);
2164 /* for ep0, monitor token irqs to catch data stage length errors
2165 * and to synchronize on status.
2167 * also, to defer reporting of protocol stalls ... here's where
2168 * data or status first appears, handling stalls here should never
2169 * cause trouble on the host side..
2171 * control requests could be slightly faster without token synch for
2172 * status, but status can jam up that way.
2174 if (unlikely (ep
->num
== 0)) {
2176 /* status; stop NAKing */
2177 if (t
& (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)) {
2178 if (ep
->dev
->protocol_stall
) {
2185 /* reply to extra IN data tokens with a zlp */
2186 } else if (t
& (1 << DATA_IN_TOKEN_INTERRUPT
)) {
2187 if (ep
->dev
->protocol_stall
) {
2191 } else if (!req
&& !ep
->stopped
)
2192 write_fifo (ep
, NULL
);
2195 /* status; stop NAKing */
2196 if (t
& (1 << DATA_IN_TOKEN_INTERRUPT
)) {
2197 if (ep
->dev
->protocol_stall
) {
2202 /* an extra OUT token is an error */
2203 } else if (((t
& (1 << DATA_OUT_PING_TOKEN_INTERRUPT
))
2205 && req
->req
.actual
== req
->req
.length
)
2207 ep
->dev
->protocol_stall
= 1;
2211 done (ep
, req
, -EOVERFLOW
);
2217 if (unlikely (!req
))
2220 /* manual DMA queue advance after short OUT */
2221 if (likely (ep
->dma
!= 0)) {
2222 if (t
& (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT
)) {
2224 int stopped
= ep
->stopped
;
2226 /* TRANSFERRED works around OUT_DONE erratum 0112.
2227 * we expect (N <= maxpacket) bytes; host wrote M.
2228 * iff (M < N) we won't ever see a DMA interrupt.
2231 for (count
= 0; ; t
= readl (&ep
->regs
->ep_stat
)) {
2233 /* any preceding dma transfers must finish.
2234 * dma handles (M >= N), may empty the queue
2236 scan_dma_completions (ep
);
2237 if (unlikely (list_empty (&ep
->queue
)
2238 || ep
->out_overflow
)) {
2242 req
= list_entry (ep
->queue
.next
,
2243 struct net2280_request
, queue
);
2245 /* here either (M < N), a "real" short rx;
2246 * or (M == N) and the queue didn't empty
2248 if (likely (t
& (1 << FIFO_EMPTY
))) {
2249 count
= readl (&ep
->dma
->dmacount
);
2250 count
&= DMA_BYTE_COUNT_MASK
;
2251 if (readl (&ep
->dma
->dmadesc
)
2259 /* stop DMA, leave ep NAKing */
2260 writel ((1 << DMA_ABORT
), &ep
->dma
->dmastat
);
2261 spin_stop_dma (ep
->dma
);
2264 req
->td
->dmacount
= 0;
2265 t
= readl (&ep
->regs
->ep_avail
);
2266 dma_done (ep
, req
, count
,
2267 (ep
->out_overflow
|| t
)
2271 /* also flush to prevent erratum 0106 trouble */
2272 if (unlikely (ep
->out_overflow
2273 || (ep
->dev
->chiprev
== 0x0100
2274 && ep
->dev
->gadget
.speed
2275 == USB_SPEED_FULL
))) {
2277 ep
->out_overflow
= 0;
2280 /* (re)start dma if needed, stop NAKing */
2281 ep
->stopped
= stopped
;
2282 if (!list_empty (&ep
->queue
))
2285 DEBUG (ep
->dev
, "%s dma ep_stat %08x ??\n",
2289 /* data packet(s) received (in the fifo, OUT) */
2290 } else if (t
& (1 << DATA_PACKET_RECEIVED_INTERRUPT
)) {
2291 if (read_fifo (ep
, req
) && ep
->num
!= 0)
2294 /* data packet(s) transmitted (IN) */
2295 } else if (t
& (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
)) {
2298 len
= req
->req
.length
- req
->req
.actual
;
2299 if (len
> ep
->ep
.maxpacket
)
2300 len
= ep
->ep
.maxpacket
;
2301 req
->req
.actual
+= len
;
2303 /* if we wrote it all, we're usually done */
2304 if (req
->req
.actual
== req
->req
.length
) {
2306 /* send zlps until the status stage */
2307 } else if (!req
->req
.zero
|| len
!= ep
->ep
.maxpacket
)
2311 /* there was nothing to do ... */
2312 } else if (mode
== 1)
2317 /* stream endpoints often resubmit/unlink in completion */
2320 /* maybe advance queue to next request */
2322 /* NOTE: net2280 could let gadget driver start the
2323 * status stage later. since not all controllers let
2324 * them control that, the api doesn't (yet) allow it.
2330 if (!list_empty (&ep
->queue
) && !ep
->stopped
)
2331 req
= list_entry (ep
->queue
.next
,
2332 struct net2280_request
, queue
);
2335 if (req
&& !ep
->is_in
)
2336 stop_out_naking (ep
);
2340 /* is there a buffer for the next packet?
2341 * for best streaming performance, make sure there is one.
2343 if (req
&& !ep
->stopped
) {
2345 /* load IN fifo with next packet (may be zlp) */
2346 if (t
& (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
))
2347 write_fifo (ep
, &req
->req
);
2351 static struct net2280_ep
*
2352 get_ep_by_addr (struct net2280
*dev
, u16 wIndex
)
2354 struct net2280_ep
*ep
;
2356 if ((wIndex
& USB_ENDPOINT_NUMBER_MASK
) == 0)
2357 return &dev
->ep
[0];
2358 list_for_each_entry (ep
, &dev
->gadget
.ep_list
, ep
.ep_list
) {
2359 u8 bEndpointAddress
;
2363 bEndpointAddress
= ep
->desc
->bEndpointAddress
;
2364 if ((wIndex
^ bEndpointAddress
) & USB_DIR_IN
)
2366 if ((wIndex
& 0x0f) == (bEndpointAddress
& 0x0f))
2372 static void handle_stat0_irqs (struct net2280
*dev
, u32 stat
)
2374 struct net2280_ep
*ep
;
2377 /* most of these don't need individual acks */
2378 stat
&= ~(1 << INTA_ASSERTED
);
2381 // DEBUG (dev, "irqstat0 %04x\n", stat);
2383 /* starting a control request? */
2384 if (unlikely (stat
& (1 << SETUP_PACKET_INTERRUPT
))) {
2387 struct usb_ctrlrequest r
;
2390 struct net2280_request
*req
;
2392 if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
2393 if (readl (&dev
->usb
->usbstat
) & (1 << HIGH_SPEED
))
2394 dev
->gadget
.speed
= USB_SPEED_HIGH
;
2396 dev
->gadget
.speed
= USB_SPEED_FULL
;
2397 net2280_led_speed (dev
, dev
->gadget
.speed
);
2398 DEBUG (dev
, "%s speed\n",
2399 (dev
->gadget
.speed
== USB_SPEED_HIGH
)
2406 /* make sure any leftover request state is cleared */
2407 stat
&= ~(1 << ENDPOINT_0_INTERRUPT
);
2408 while (!list_empty (&ep
->queue
)) {
2409 req
= list_entry (ep
->queue
.next
,
2410 struct net2280_request
, queue
);
2411 done (ep
, req
, (req
->req
.actual
== req
->req
.length
)
2415 dev
->protocol_stall
= 0;
2417 if (ep
->dev
->pdev
->device
== 0x2280)
2418 tmp
= (1 << FIFO_OVERFLOW
)
2419 | (1 << FIFO_UNDERFLOW
);
2423 writel (tmp
| (1 << TIMEOUT
)
2424 | (1 << USB_STALL_SENT
)
2425 | (1 << USB_IN_NAK_SENT
)
2426 | (1 << USB_IN_ACK_RCVD
)
2427 | (1 << USB_OUT_PING_NAK_SENT
)
2428 | (1 << USB_OUT_ACK_SENT
)
2429 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT
)
2430 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT
)
2431 | (1 << DATA_PACKET_RECEIVED_INTERRUPT
)
2432 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
)
2433 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
2434 | (1 << DATA_IN_TOKEN_INTERRUPT
)
2435 , &ep
->regs
->ep_stat
);
2436 u
.raw
[0] = readl (&dev
->usb
->setup0123
);
2437 u
.raw
[1] = readl (&dev
->usb
->setup4567
);
2439 cpu_to_le32s (&u
.raw
[0]);
2440 cpu_to_le32s (&u
.raw
[1]);
2444 #define w_value le16_to_cpup (&u.r.wValue)
2445 #define w_index le16_to_cpup (&u.r.wIndex)
2446 #define w_length le16_to_cpup (&u.r.wLength)
2449 writel (1 << SETUP_PACKET_INTERRUPT
, &dev
->regs
->irqstat0
);
2450 stat
^= (1 << SETUP_PACKET_INTERRUPT
);
2452 /* watch control traffic at the token level, and force
2453 * synchronization before letting the status stage happen.
2454 * FIXME ignore tokens we'll NAK, until driver responds.
2455 * that'll mean a lot less irqs for some drivers.
2457 ep
->is_in
= (u
.r
.bRequestType
& USB_DIR_IN
) != 0;
2459 scratch
= (1 << DATA_PACKET_TRANSMITTED_INTERRUPT
)
2460 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
2461 | (1 << DATA_IN_TOKEN_INTERRUPT
);
2462 stop_out_naking (ep
);
2464 scratch
= (1 << DATA_PACKET_RECEIVED_INTERRUPT
)
2465 | (1 << DATA_OUT_PING_TOKEN_INTERRUPT
)
2466 | (1 << DATA_IN_TOKEN_INTERRUPT
);
2467 writel (scratch
, &dev
->epregs
[0].ep_irqenb
);
2469 /* we made the hardware handle most lowlevel requests;
2470 * everything else goes uplevel to the gadget code.
2472 switch (u
.r
.bRequest
) {
2473 case USB_REQ_GET_STATUS
: {
2474 struct net2280_ep
*e
;
2477 /* hw handles device and interface status */
2478 if (u
.r
.bRequestType
!= (USB_DIR_IN
|USB_RECIP_ENDPOINT
))
2480 if ((e
= get_ep_by_addr (dev
, w_index
)) == 0
2484 if (readl (&e
->regs
->ep_rsp
)
2485 & (1 << SET_ENDPOINT_HALT
))
2486 status
= __constant_cpu_to_le32 (1);
2488 status
= __constant_cpu_to_le32 (0);
2490 /* don't bother with a request object! */
2491 writel (0, &dev
->epregs
[0].ep_irqenb
);
2492 set_fifo_bytecount (ep
, w_length
);
2493 writel ((__force u32
)status
, &dev
->epregs
[0].ep_data
);
2495 VDEBUG (dev
, "%s stat %02x\n", ep
->ep
.name
, status
);
2496 goto next_endpoints
;
2499 case USB_REQ_CLEAR_FEATURE
: {
2500 struct net2280_ep
*e
;
2502 /* hw handles device features */
2503 if (u
.r
.bRequestType
!= USB_RECIP_ENDPOINT
)
2505 if (w_value
!= USB_ENDPOINT_HALT
2508 if ((e
= get_ep_by_addr (dev
, w_index
)) == 0)
2512 VDEBUG (dev
, "%s clear halt\n", ep
->ep
.name
);
2513 goto next_endpoints
;
2516 case USB_REQ_SET_FEATURE
: {
2517 struct net2280_ep
*e
;
2519 /* hw handles device features */
2520 if (u
.r
.bRequestType
!= USB_RECIP_ENDPOINT
)
2522 if (w_value
!= USB_ENDPOINT_HALT
2525 if ((e
= get_ep_by_addr (dev
, w_index
)) == 0)
2529 VDEBUG (dev
, "%s set halt\n", ep
->ep
.name
);
2530 goto next_endpoints
;
2535 VDEBUG (dev
, "setup %02x.%02x v%04x i%04x l%04x"
2537 u
.r
.bRequestType
, u
.r
.bRequest
,
2538 w_value
, w_index
, w_length
,
2539 readl (&ep
->regs
->ep_cfg
));
2540 spin_unlock (&dev
->lock
);
2541 tmp
= dev
->driver
->setup (&dev
->gadget
, &u
.r
);
2542 spin_lock (&dev
->lock
);
2545 /* stall ep0 on error */
2548 VDEBUG (dev
, "req %02x.%02x protocol STALL; stat %d\n",
2549 u
.r
.bRequestType
, u
.r
.bRequest
, tmp
);
2550 dev
->protocol_stall
= 1;
2553 /* some in/out token irq should follow; maybe stall then.
2554 * driver must queue a request (even zlp) or halt ep0
2555 * before the host times out.
2564 /* endpoint data irq ? */
2565 scratch
= stat
& 0x7f;
2567 for (num
= 0; scratch
; num
++) {
2570 /* do this endpoint's FIFO and queue need tending? */
2572 if ((scratch
& t
) == 0)
2576 ep
= &dev
->ep
[num
];
2577 handle_ep_small (ep
);
2581 DEBUG (dev
, "unhandled irqstat0 %08x\n", stat
);
2584 #define DMA_INTERRUPTS ( \
2585 (1 << DMA_D_INTERRUPT) \
2586 | (1 << DMA_C_INTERRUPT) \
2587 | (1 << DMA_B_INTERRUPT) \
2588 | (1 << DMA_A_INTERRUPT))
2589 #define PCI_ERROR_INTERRUPTS ( \
2590 (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT) \
2591 | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT) \
2592 | (1 << PCI_RETRY_ABORT_INTERRUPT))
2594 static void handle_stat1_irqs (struct net2280
*dev
, u32 stat
)
2596 struct net2280_ep
*ep
;
2597 u32 tmp
, num
, mask
, scratch
;
2599 /* after disconnect there's nothing else to do! */
2600 tmp
= (1 << VBUS_INTERRUPT
) | (1 << ROOT_PORT_RESET_INTERRUPT
);
2601 mask
= (1 << HIGH_SPEED
) | (1 << FULL_SPEED
);
2603 /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
2604 * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRRUPT set and
2605 * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
2606 * only indicates a change in the reset state).
2609 writel (tmp
, &dev
->regs
->irqstat1
);
2610 if ((((stat
& (1 << ROOT_PORT_RESET_INTERRUPT
))
2611 && ((readl (&dev
->usb
->usbstat
) & mask
)
2613 || ((readl (&dev
->usb
->usbctl
)
2614 & (1 << VBUS_PIN
)) == 0)
2615 ) && ( dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
)) {
2616 DEBUG (dev
, "disconnect %s\n",
2617 dev
->driver
->driver
.name
);
2618 stop_activity (dev
, dev
->driver
);
2624 /* vBUS can bounce ... one of many reasons to ignore the
2625 * notion of hotplug events on bus connect/disconnect!
2631 /* NOTE: chip stays in PCI D0 state for now, but it could
2632 * enter D1 to save more power
2634 tmp
= (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT
);
2636 writel (tmp
, &dev
->regs
->irqstat1
);
2637 if (stat
& (1 << SUSPEND_REQUEST_INTERRUPT
)) {
2638 if (dev
->driver
->suspend
)
2639 dev
->driver
->suspend (&dev
->gadget
);
2640 if (!enable_suspend
)
2641 stat
&= ~(1 << SUSPEND_REQUEST_INTERRUPT
);
2643 if (dev
->driver
->resume
)
2644 dev
->driver
->resume (&dev
->gadget
);
2645 /* at high speed, note erratum 0133 */
2650 /* clear any other status/irqs */
2652 writel (stat
, &dev
->regs
->irqstat1
);
2654 /* some status we can just ignore */
2655 if (dev
->pdev
->device
== 0x2280)
2656 stat
&= ~((1 << CONTROL_STATUS_INTERRUPT
)
2657 | (1 << SUSPEND_REQUEST_INTERRUPT
)
2658 | (1 << RESUME_INTERRUPT
)
2659 | (1 << SOF_INTERRUPT
));
2661 stat
&= ~((1 << CONTROL_STATUS_INTERRUPT
)
2662 | (1 << RESUME_INTERRUPT
)
2663 | (1 << SOF_DOWN_INTERRUPT
)
2664 | (1 << SOF_INTERRUPT
));
2668 // DEBUG (dev, "irqstat1 %08x\n", stat);
2670 /* DMA status, for ep-{a,b,c,d} */
2671 scratch
= stat
& DMA_INTERRUPTS
;
2672 stat
&= ~DMA_INTERRUPTS
;
2674 for (num
= 0; scratch
; num
++) {
2675 struct net2280_dma_regs __iomem
*dma
;
2678 if ((tmp
& scratch
) == 0)
2682 ep
= &dev
->ep
[num
+ 1];
2688 /* clear ep's dma status */
2689 tmp
= readl (&dma
->dmastat
);
2690 writel (tmp
, &dma
->dmastat
);
2692 /* chaining should stop on abort, short OUT from fifo,
2693 * or (stat0 codepath) short OUT transfer.
2695 if (!use_dma_chaining
) {
2696 if ((tmp
& (1 << DMA_TRANSACTION_DONE_INTERRUPT
))
2698 DEBUG (ep
->dev
, "%s no xact done? %08x\n",
2705 /* OUT transfers terminate when the data from the
2706 * host is in our memory. Process whatever's done.
2707 * On this path, we know transfer's last packet wasn't
2708 * less than req->length. NAK_OUT_PACKETS may be set,
2709 * or the FIFO may already be holding new packets.
2711 * IN transfers can linger in the FIFO for a very
2712 * long time ... we ignore that for now, accounting
2713 * precisely (like PIO does) needs per-packet irqs
2715 scan_dma_completions (ep
);
2717 /* disable dma on inactive queues; else maybe restart */
2718 if (list_empty (&ep
->queue
)) {
2719 if (use_dma_chaining
)
2722 tmp
= readl (&dma
->dmactl
);
2723 if (!use_dma_chaining
2724 || (tmp
& (1 << DMA_ENABLE
)) == 0)
2726 else if (ep
->is_in
&& use_dma_chaining
) {
2727 struct net2280_request
*req
;
2730 /* the descriptor at the head of the chain
2731 * may still have VALID_BIT clear; that's
2732 * used to trigger changing DMA_FIFO_VALIDATE
2733 * (affects automagic zlp writes).
2735 req
= list_entry (ep
->queue
.next
,
2736 struct net2280_request
, queue
);
2737 dmacount
= req
->td
->dmacount
;
2738 dmacount
&= __constant_cpu_to_le32 (
2740 | DMA_BYTE_COUNT_MASK
);
2741 if (dmacount
&& (dmacount
& valid_bit
) == 0)
2748 /* NOTE: there are other PCI errors we might usefully notice.
2749 * if they appear very often, here's where to try recovering.
2751 if (stat
& PCI_ERROR_INTERRUPTS
) {
2752 ERROR (dev
, "pci dma error; stat %08x\n", stat
);
2753 stat
&= ~PCI_ERROR_INTERRUPTS
;
2754 /* these are fatal errors, but "maybe" they won't
2757 stop_activity (dev
, dev
->driver
);
2763 DEBUG (dev
, "unhandled irqstat1 %08x\n", stat
);
2766 static irqreturn_t
net2280_irq (int irq
, void *_dev
)
2768 struct net2280
*dev
= _dev
;
2770 /* shared interrupt, not ours */
2771 if (!(readl(&dev
->regs
->irqstat0
) & (1 << INTA_ASSERTED
)))
2774 spin_lock (&dev
->lock
);
2776 /* handle disconnect, dma, and more */
2777 handle_stat1_irqs (dev
, readl (&dev
->regs
->irqstat1
));
2779 /* control requests and PIO */
2780 handle_stat0_irqs (dev
, readl (&dev
->regs
->irqstat0
));
2782 spin_unlock (&dev
->lock
);
2787 /*-------------------------------------------------------------------------*/
2789 static void gadget_release (struct device
*_dev
)
2791 struct net2280
*dev
= dev_get_drvdata (_dev
);
2796 /* tear down the binding between this driver and the pci device */
2798 static void net2280_remove (struct pci_dev
*pdev
)
2800 struct net2280
*dev
= pci_get_drvdata (pdev
);
2802 /* start with the driver above us */
2804 /* should have been done already by driver model core */
2805 WARN (dev
, "pci remove, driver '%s' is still registered\n",
2806 dev
->driver
->driver
.name
);
2807 usb_gadget_unregister_driver (dev
->driver
);
2810 /* then clean up the resources we allocated during probe() */
2811 net2280_led_shutdown (dev
);
2812 if (dev
->requests
) {
2814 for (i
= 1; i
< 5; i
++) {
2815 if (!dev
->ep
[i
].dummy
)
2817 pci_pool_free (dev
->requests
, dev
->ep
[i
].dummy
,
2818 dev
->ep
[i
].td_dma
);
2820 pci_pool_destroy (dev
->requests
);
2823 free_irq (pdev
->irq
, dev
);
2825 iounmap (dev
->regs
);
2827 release_mem_region (pci_resource_start (pdev
, 0),
2828 pci_resource_len (pdev
, 0));
2830 pci_disable_device (pdev
);
2831 device_unregister (&dev
->gadget
.dev
);
2832 device_remove_file (&pdev
->dev
, &dev_attr_registers
);
2833 pci_set_drvdata (pdev
, NULL
);
2835 INFO (dev
, "unbind\n");
2837 the_controller
= NULL
;
2840 /* wrap this driver around the specified device, but
2841 * don't respond over USB until a gadget driver binds to us.
2844 static int net2280_probe (struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2846 struct net2280
*dev
;
2847 unsigned long resource
, len
;
2848 void __iomem
*base
= NULL
;
2851 /* if you want to support more than one controller in a system,
2852 * usb_gadget_driver_{register,unregister}() must change.
2854 if (the_controller
) {
2855 dev_warn (&pdev
->dev
, "ignoring\n");
2859 /* alloc, and start init */
2860 dev
= kzalloc (sizeof *dev
, SLAB_KERNEL
);
2866 pci_set_drvdata (pdev
, dev
);
2867 spin_lock_init (&dev
->lock
);
2869 dev
->gadget
.ops
= &net2280_ops
;
2870 dev
->gadget
.is_dualspeed
= 1;
2872 /* the "gadget" abstracts/virtualizes the controller */
2873 strcpy (dev
->gadget
.dev
.bus_id
, "gadget");
2874 dev
->gadget
.dev
.parent
= &pdev
->dev
;
2875 dev
->gadget
.dev
.dma_mask
= pdev
->dev
.dma_mask
;
2876 dev
->gadget
.dev
.release
= gadget_release
;
2877 dev
->gadget
.name
= driver_name
;
2879 /* now all the pci goodies ... */
2880 if (pci_enable_device (pdev
) < 0) {
2886 /* BAR 0 holds all the registers
2887 * BAR 1 is 8051 memory; unused here (note erratum 0103)
2888 * BAR 2 is fifo memory; unused here
2890 resource
= pci_resource_start (pdev
, 0);
2891 len
= pci_resource_len (pdev
, 0);
2892 if (!request_mem_region (resource
, len
, driver_name
)) {
2893 DEBUG (dev
, "controller already in use\n");
2899 /* FIXME provide firmware download interface to put
2900 * 8051 code into the chip, e.g. to turn on PCI PM.
2903 base
= ioremap_nocache (resource
, len
);
2905 DEBUG (dev
, "can't map memory\n");
2909 dev
->regs
= (struct net2280_regs __iomem
*) base
;
2910 dev
->usb
= (struct net2280_usb_regs __iomem
*) (base
+ 0x0080);
2911 dev
->pci
= (struct net2280_pci_regs __iomem
*) (base
+ 0x0100);
2912 dev
->dma
= (struct net2280_dma_regs __iomem
*) (base
+ 0x0180);
2913 dev
->dep
= (struct net2280_dep_regs __iomem
*) (base
+ 0x0200);
2914 dev
->epregs
= (struct net2280_ep_regs __iomem
*) (base
+ 0x0300);
2916 /* put into initial config, link up all endpoints */
2917 writel (0, &dev
->usb
->usbctl
);
2921 /* irq setup after old hardware is cleaned up */
2923 ERROR (dev
, "No IRQ. Check PCI setup!\n");
2928 if (request_irq (pdev
->irq
, net2280_irq
, IRQF_SHARED
, driver_name
, dev
)
2930 ERROR (dev
, "request interrupt %d failed\n", pdev
->irq
);
2937 /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */
2938 dev
->requests
= pci_pool_create ("requests", pdev
,
2939 sizeof (struct net2280_dma
),
2940 0 /* no alignment requirements */,
2941 0 /* or page-crossing issues */);
2942 if (!dev
->requests
) {
2943 DEBUG (dev
, "can't get request pool\n");
2947 for (i
= 1; i
< 5; i
++) {
2948 struct net2280_dma
*td
;
2950 td
= pci_pool_alloc (dev
->requests
, GFP_KERNEL
,
2951 &dev
->ep
[i
].td_dma
);
2953 DEBUG (dev
, "can't get dummy %d\n", i
);
2957 td
->dmacount
= 0; /* not VALID */
2958 td
->dmaaddr
= __constant_cpu_to_le32 (DMA_ADDR_INVALID
);
2959 td
->dmadesc
= td
->dmaaddr
;
2960 dev
->ep
[i
].dummy
= td
;
2963 /* enable lower-overhead pci memory bursts during DMA */
2964 writel ( (1 << DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE
)
2965 // 256 write retries may not be enough...
2966 // | (1 << PCI_RETRY_ABORT_ENABLE)
2967 | (1 << DMA_READ_MULTIPLE_ENABLE
)
2968 | (1 << DMA_READ_LINE_ENABLE
)
2969 , &dev
->pci
->pcimstctl
);
2970 /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
2971 pci_set_master (pdev
);
2974 /* ... also flushes any posted pci writes */
2975 dev
->chiprev
= get_idx_reg (dev
->regs
, REG_CHIPREV
) & 0xffff;
2978 INFO (dev
, "%s\n", driver_desc
);
2979 INFO (dev
, "irq %d, pci mem %p, chip rev %04x\n",
2980 pdev
->irq
, base
, dev
->chiprev
);
2981 INFO (dev
, "version: " DRIVER_VERSION
"; dma %s\n",
2983 ? (use_dma_chaining
? "chaining" : "enabled")
2985 the_controller
= dev
;
2987 retval
= device_register (&dev
->gadget
.dev
);
2988 if (retval
) goto done
;
2989 retval
= device_create_file (&pdev
->dev
, &dev_attr_registers
);
2990 if (retval
) goto done
;
2996 net2280_remove (pdev
);
3000 /* make sure the board is quiescent; otherwise it will continue
3001 * generating IRQs across the upcoming reboot.
3004 static void net2280_shutdown (struct pci_dev
*pdev
)
3006 struct net2280
*dev
= pci_get_drvdata (pdev
);
3009 writel (0, &dev
->regs
->pciirqenb0
);
3010 writel (0, &dev
->regs
->pciirqenb1
);
3012 /* disable the pullup so the host will think we're gone */
3013 writel (0, &dev
->usb
->usbctl
);
3017 /*-------------------------------------------------------------------------*/
3019 static const struct pci_device_id pci_ids
[] = { {
3020 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
3024 .subvendor
= PCI_ANY_ID
,
3025 .subdevice
= PCI_ANY_ID
,
3027 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
3031 .subvendor
= PCI_ANY_ID
,
3032 .subdevice
= PCI_ANY_ID
,
3034 }, { /* end: all zeroes */ }
3036 MODULE_DEVICE_TABLE (pci
, pci_ids
);
3038 /* pci driver glue; this is a "new style" PCI driver module */
3039 static struct pci_driver net2280_pci_driver
= {
3040 .name
= (char *) driver_name
,
3041 .id_table
= pci_ids
,
3043 .probe
= net2280_probe
,
3044 .remove
= net2280_remove
,
3045 .shutdown
= net2280_shutdown
,
3047 /* FIXME add power management support */
3050 MODULE_DESCRIPTION (DRIVER_DESC
);
3051 MODULE_AUTHOR ("David Brownell");
3052 MODULE_LICENSE ("GPL");
3054 static int __init
init (void)
3057 use_dma_chaining
= 0;
3058 return pci_register_driver (&net2280_pci_driver
);
3062 static void __exit
cleanup (void)
3064 pci_unregister_driver (&net2280_pci_driver
);
3066 module_exit (cleanup
);