2 * linux/drivers/usb/gadget/pxa2xx_udc.c
3 * Intel PXA2xx and IXP4xx on-chip full speed USB device controllers
5 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
6 * Copyright (C) 2003 Robert Schwebel, Pengutronix
7 * Copyright (C) 2003 Benedikt Spranger, Pengutronix
8 * Copyright (C) 2003 David Brownell
9 * Copyright (C) 2003 Joshua Wise
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 // #define VERBOSE DBG_VERBOSE
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/ioport.h>
34 #include <linux/types.h>
35 #include <linux/version.h>
36 #include <linux/errno.h>
37 #include <linux/delay.h>
38 #include <linux/sched.h>
39 #include <linux/slab.h>
40 #include <linux/init.h>
41 #include <linux/timer.h>
42 #include <linux/list.h>
43 #include <linux/interrupt.h>
44 #include <linux/proc_fs.h>
46 #include <linux/device.h>
47 #include <linux/dma-mapping.h>
49 #include <asm/byteorder.h>
53 #include <asm/system.h>
54 #include <asm/mach-types.h>
55 #include <asm/unaligned.h>
56 #include <asm/hardware.h>
58 #include <linux/usb_ch9.h>
59 #include <linux/usb_gadget.h>
61 #include <asm/arch/udc.h>
65 * This driver handles the USB Device Controller (UDC) in Intel's PXA 2xx
66 * series processors. The UDC for the IXP 4xx series is very similar.
67 * There are fifteen endpoints, in addition to ep0.
69 * Such controller drivers work with a gadget driver. The gadget driver
70 * returns descriptors, implements configuration and data protocols used
71 * by the host to interact with this device, and allocates endpoints to
72 * the different protocol interfaces. The controller driver virtualizes
73 * usb hardware so that the gadget drivers will be more portable.
75 * This UDC hardware wants to implement a bit too much USB protocol, so
76 * it constrains the sorts of USB configuration change events that work.
77 * The errata for these chips are misleading; some "fixed" bugs from
78 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
81 #define DRIVER_VERSION "14-Dec-2003"
82 #define DRIVER_DESC "PXA 2xx USB Device Controller driver"
85 static const char driver_name [] = "pxa2xx_udc";
87 static const char ep0name [] = "ep0";
91 // #define USE_OUT_DMA
92 // #define DISABLE_TEST_MODE
98 #ifdef CONFIG_ARCH_IXP4XX
101 /* cpu-specific register addresses are compiled in to this code */
102 #ifdef CONFIG_ARCH_PXA
103 #error "Can't configure both IXP and PXA"
108 #include "pxa2xx_udc.h"
111 #ifdef CONFIG_EMBEDDED
112 /* few strings, and little code to use them */
118 static int use_dma = 1;
119 MODULE_PARM (use_dma, "i");
120 MODULE_PARM_DESC (use_dma, "true to use dma");
122 static void dma_nodesc_handler (int dmach, void *_ep, struct pt_regs *r);
123 static void kick_dma(struct pxa2xx_ep *ep, struct pxa2xx_request *req);
126 #define DMASTR " (dma support)"
128 #define DMASTR " (dma in)"
132 #define DMASTR " (pio only)"
136 #ifdef CONFIG_USB_PXA2XX_SMALL
137 #define SIZE_STR " (small)"
142 #ifdef DISABLE_TEST_MODE
143 /* (mode == 0) == no undocumented chip tweaks
144 * (mode & 1) == double buffer bulk IN
145 * (mode & 2) == double buffer bulk OUT
146 * ... so mode = 3 (or 7, 15, etc) does it for both
148 static ushort fifo_mode = 0;
149 MODULE_PARM (fifo_mode, "h");
150 MODULE_PARM_DESC (fifo_mode, "pxa2xx udc fifo mode");
153 /* ---------------------------------------------------------------------------
154 * endpoint related parts of the api to the usb controller hardware,
155 * used by gadget driver; and the inner talker-to-hardware core.
156 * ---------------------------------------------------------------------------
159 static void pxa2xx_ep_fifo_flush (struct usb_ep *ep);
160 static void nuke (struct pxa2xx_ep *, int status);
162 static void pio_irq_enable(int bEndpointAddress)
164 bEndpointAddress &= 0xf;
165 if (bEndpointAddress < 8)
166 UICR0 &= ~(1 << bEndpointAddress);
168 bEndpointAddress -= 8;
169 UICR1 &= ~(1 << bEndpointAddress);
173 static void pio_irq_disable(int bEndpointAddress)
175 bEndpointAddress &= 0xf;
176 if (bEndpointAddress < 8)
177 UICR0 |= 1 << bEndpointAddress;
179 bEndpointAddress -= 8;
180 UICR1 |= 1 << bEndpointAddress;
184 /* The UDCCR reg contains mask and interrupt status bits,
185 * so using '|=' isn't safe as it may ack an interrupt.
187 #define UDCCR_MASK_BITS (UDCCR_REM | UDCCR_SRM | UDCCR_UDE)
189 static inline void udc_set_mask_UDCCR(int mask)
191 UDCCR = (UDCCR & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS);
194 static inline void udc_clear_mask_UDCCR(int mask)
196 UDCCR = (UDCCR & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS);
199 static inline void udc_ack_int_UDCCR(int mask)
201 /* udccr contains the bits we dont want to change */
202 __u32 udccr = UDCCR & UDCCR_MASK_BITS;
204 UDCCR = udccr | (mask & ~UDCCR_MASK_BITS);
208 * endpoint enable/disable
210 * we need to verify the descriptors used to enable endpoints. since pxa2xx
211 * endpoint configurations are fixed, and are pretty much always enabled,
212 * there's not a lot to manage here.
214 * because pxa2xx can't selectively initialize bulk (or interrupt) endpoints,
215 * (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
216 * for a single interface (with only the default altsetting) and for gadget
217 * drivers that don't halt endpoints (not reset by set_interface). that also
218 * means that if you use ISO, you must violate the USB spec rule that all
219 * iso endpoints must be in non-default altsettings.
221 static int pxa2xx_ep_enable (struct usb_ep *_ep,
222 const struct usb_endpoint_descriptor *desc)
224 struct pxa2xx_ep *ep;
225 struct pxa2xx_udc *dev;
227 ep = container_of (_ep, struct pxa2xx_ep, ep);
228 if (!_ep || !desc || ep->desc || _ep->name == ep0name
229 || desc->bDescriptorType != USB_DT_ENDPOINT
230 || ep->bEndpointAddress != desc->bEndpointAddress
231 || ep->fifo_size < le16_to_cpu
232 (desc->wMaxPacketSize)) {
233 DMSG("%s, bad ep or descriptor\n", __FUNCTION__);
237 /* xfer types must match, except that interrupt ~= bulk */
238 if (ep->bmAttributes != desc->bmAttributes
239 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
240 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
241 DMSG("%s, %s type mismatch\n", __FUNCTION__, _ep->name);
245 /* hardware _could_ do smaller, but driver doesn't */
246 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
247 && le16_to_cpu (desc->wMaxPacketSize)
249 || !desc->wMaxPacketSize) {
250 DMSG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name);
255 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
256 DMSG("%s, bogus device state\n", __FUNCTION__);
263 ep->pio_irqs = ep->dma_irqs = 0;
264 ep->ep.maxpacket = le16_to_cpu (desc->wMaxPacketSize);
266 /* flush fifo (mostly for OUT buffers) */
267 pxa2xx_ep_fifo_flush (_ep);
269 /* ... reset halt state too, if we could ... */
272 /* for (some) bulk and ISO endpoints, try to get a DMA channel and
273 * bind it to the endpoint. otherwise use PIO.
275 switch (ep->bmAttributes) {
276 case USB_ENDPOINT_XFER_ISOC:
277 if (le16_to_cpu(desc->wMaxPacketSize) % 32)
280 case USB_ENDPOINT_XFER_BULK:
281 if (!use_dma || !ep->reg_drcmr)
283 ep->dma = pxa_request_dma ((char *)_ep->name,
284 (le16_to_cpu (desc->wMaxPacketSize) > 64)
285 ? DMA_PRIO_MEDIUM /* some iso */
287 dma_nodesc_handler, ep);
289 *ep->reg_drcmr = DRCMR_MAPVLD | ep->dma;
290 DMSG("%s using dma%d\n", _ep->name, ep->dma);
295 DBG(DBG_VERBOSE, "enabled %s\n", _ep->name);
299 static int pxa2xx_ep_disable (struct usb_ep *_ep)
301 struct pxa2xx_ep *ep;
303 ep = container_of (_ep, struct pxa2xx_ep, ep);
304 if (!_ep || !ep->desc) {
305 DMSG("%s, %s not enabled\n", __FUNCTION__,
306 _ep ? ep->ep.name : NULL);
309 nuke (ep, -ESHUTDOWN);
314 pxa_free_dma (ep->dma);
319 /* flush fifo (mostly for IN buffers) */
320 pxa2xx_ep_fifo_flush (_ep);
325 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
329 /*-------------------------------------------------------------------------*/
331 /* for the pxa2xx, these can just wrap kmalloc/kfree. gadget drivers
332 * must still pass correctly initialized endpoints, since other controller
333 * drivers may care about how it's currently set up (dma issues etc).
337 * pxa2xx_ep_alloc_request - allocate a request data structure
339 static struct usb_request *
340 pxa2xx_ep_alloc_request (struct usb_ep *_ep, int gfp_flags)
342 struct pxa2xx_request *req;
344 req = kmalloc (sizeof *req, gfp_flags);
348 memset (req, 0, sizeof *req);
349 INIT_LIST_HEAD (&req->queue);
355 * pxa2xx_ep_free_request - deallocate a request data structure
358 pxa2xx_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
360 struct pxa2xx_request *req;
362 req = container_of (_req, struct pxa2xx_request, req);
363 WARN_ON (!list_empty (&req->queue));
368 /* PXA cache needs flushing with DMA I/O (it's dma-incoherent), but there's
369 * no device-affinity and the heap works perfectly well for i/o buffers.
370 * It wastes much less memory than dma_alloc_coherent() would, and even
371 * prevents cacheline (32 bytes wide) sharing problems.
374 pxa2xx_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
375 dma_addr_t *dma, int gfp_flags)
379 retval = kmalloc (bytes, gfp_flags & ~(__GFP_DMA|__GFP_HIGHMEM));
381 *dma = virt_to_bus (retval);
386 pxa2xx_ep_free_buffer(struct usb_ep *_ep, void *buf, dma_addr_t dma,
392 /*-------------------------------------------------------------------------*/
395 * done - retire a request; caller blocked irqs
397 static void done(struct pxa2xx_ep *ep, struct pxa2xx_request *req, int status)
399 unsigned stopped = ep->stopped;
401 list_del_init(&req->queue);
403 if (likely (req->req.status == -EINPROGRESS))
404 req->req.status = status;
406 status = req->req.status;
408 if (status && status != -ESHUTDOWN)
409 DBG(DBG_VERBOSE, "complete %s req %p stat %d len %u/%u\n",
410 ep->ep.name, &req->req, status,
411 req->req.actual, req->req.length);
413 /* don't modify queue heads during completion callback */
415 req->req.complete(&ep->ep, &req->req);
416 ep->stopped = stopped;
420 static inline void ep0_idle (struct pxa2xx_udc *dev)
422 dev->ep0state = EP0_IDLE;
427 write_packet(volatile u32 *uddr, struct pxa2xx_request *req, unsigned max)
430 unsigned length, count;
432 buf = req->req.buf + req->req.actual;
435 /* how big will this packet be? */
436 length = min(req->req.length - req->req.actual, max);
437 req->req.actual += length;
440 while (likely(count--))
447 * write to an IN endpoint fifo, as many packets as possible.
448 * irqs will use this to write the rest later.
449 * caller guarantees at least one packet buffer is ready (or a zlp).
452 write_fifo (struct pxa2xx_ep *ep, struct pxa2xx_request *req)
456 max = le16_to_cpu(ep->desc->wMaxPacketSize);
459 int is_last, is_short;
461 count = write_packet(ep->reg_uddr, req, max);
463 /* last packet is usually short (or a zlp) */
464 if (unlikely (count != max))
465 is_last = is_short = 1;
467 if (likely(req->req.length != req->req.actual)
472 /* interrupt/iso maxpacket may not fill the fifo */
473 is_short = unlikely (max < ep->fifo_size);
476 DBG(DBG_VERY_NOISY, "wrote %s %d bytes%s%s %d left %p\n",
478 is_last ? "/L" : "", is_short ? "/S" : "",
479 req->req.length - req->req.actual, req);
481 /* let loose that packet. maybe try writing another one,
482 * double buffering might work. TSP, TPC, and TFS
483 * bit values are the same for all normal IN endpoints.
485 *ep->reg_udccs = UDCCS_BI_TPC;
487 *ep->reg_udccs = UDCCS_BI_TSP;
489 /* requests complete when all IN data is in the FIFO */
492 if (list_empty(&ep->queue) || unlikely(ep->dma >= 0)) {
493 pio_irq_disable (ep->bEndpointAddress);
495 /* unaligned data and zlps couldn't use dma */
496 if (unlikely(!list_empty(&ep->queue))) {
497 req = list_entry(ep->queue.next,
498 struct pxa2xx_request, queue);
507 // TODO experiment: how robust can fifo mode tweaking be?
508 // double buffering is off in the default fifo mode, which
509 // prevents TFS from being set here.
511 } while (*ep->reg_udccs & UDCCS_BI_TFS);
515 /* caller asserts req->pending (ep0 irq status nyet cleared); starts
516 * ep0 data stage. these chips want very simple state transitions.
519 void ep0start(struct pxa2xx_udc *dev, u32 flags, const char *tag)
521 UDCCS0 = flags|UDCCS0_SA|UDCCS0_OPR;
523 dev->req_pending = 0;
524 DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n",
525 __FUNCTION__, tag, UDCCS0, flags);
529 write_ep0_fifo (struct pxa2xx_ep *ep, struct pxa2xx_request *req)
534 count = write_packet(&UDDR0, req, EP0_FIFO_SIZE);
535 ep->dev->stats.write.bytes += count;
537 /* last packet "must be" short (or a zlp) */
538 is_short = (count != EP0_FIFO_SIZE);
540 DBG(DBG_VERY_NOISY, "ep0in %d bytes %d left %p\n", count,
541 req->req.length - req->req.actual, req);
543 if (unlikely (is_short)) {
544 if (ep->dev->req_pending)
545 ep0start(ep->dev, UDCCS0_IPR, "short IN");
549 count = req->req.length;
553 /* This seems to get rid of lost status irqs in some cases:
554 * host responds quickly, or next request involves config
555 * change automagic, or should have been hidden, or ...
557 * FIXME get rid of all udelays possible...
559 if (count >= EP0_FIFO_SIZE) {
562 if ((UDCCS0 & UDCCS0_OPR) != 0) {
563 /* clear OPR, generate ack */
572 } else if (ep->dev->req_pending)
573 ep0start(ep->dev, 0, "IN");
579 * read_fifo - unload packet(s) from the fifo we use for usb OUT
580 * transfers and put them into the request. caller should have made
581 * sure there's at least one packet ready.
583 * returns true if the request completed because of short packet or the
584 * request buffer having filled (and maybe overran till end-of-packet).
587 read_fifo (struct pxa2xx_ep *ep, struct pxa2xx_request *req)
592 unsigned bufferspace, count, is_short;
594 /* make sure there's a packet in the FIFO.
595 * UDCCS_{BO,IO}_RPC are all the same bit value.
596 * UDCCS_{BO,IO}_RNE are all the same bit value.
598 udccs = *ep->reg_udccs;
599 if (unlikely ((udccs & UDCCS_BO_RPC) == 0))
601 buf = req->req.buf + req->req.actual;
603 bufferspace = req->req.length - req->req.actual;
605 /* read all bytes from this packet */
606 if (likely (udccs & UDCCS_BO_RNE)) {
607 count = 1 + (0x0ff & *ep->reg_ubcr);
608 req->req.actual += min (count, bufferspace);
611 is_short = (count < ep->ep.maxpacket);
612 DBG(DBG_VERY_NOISY, "read %s %02x, %d bytes%s req %p %d/%d\n",
613 ep->ep.name, udccs, count,
614 is_short ? "/S" : "",
615 req, req->req.actual, req->req.length);
616 while (likely (count-- != 0)) {
617 u8 byte = (u8) *ep->reg_uddr;
619 if (unlikely (bufferspace == 0)) {
620 /* this happens when the driver's buffer
621 * is smaller than what the host sent.
622 * discard the extra data.
624 if (req->req.status != -EOVERFLOW)
625 DMSG("%s overflow %d\n",
627 req->req.status = -EOVERFLOW;
633 *ep->reg_udccs = UDCCS_BO_RPC;
634 /* RPC/RSP/RNE could now reflect the other packet buffer */
636 /* iso is one request per packet */
637 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
638 if (udccs & UDCCS_IO_ROF)
639 req->req.status = -EHOSTUNREACH;
640 /* more like "is_done" */
645 if (is_short || req->req.actual == req->req.length) {
647 if (list_empty(&ep->queue))
648 pio_irq_disable (ep->bEndpointAddress);
652 /* finished that packet. the next one may be waiting... */
658 * special ep0 version of the above. no UBCR0 or double buffering; status
659 * handshaking is magic. most device protocols don't need control-OUT.
660 * CDC vendor commands (and RNDIS), mass storage CB/CBI, and some other
661 * protocols do use them.
664 read_ep0_fifo (struct pxa2xx_ep *ep, struct pxa2xx_request *req)
667 unsigned bufferspace;
669 buf = req->req.buf + req->req.actual;
670 bufferspace = req->req.length - req->req.actual;
672 while (UDCCS0 & UDCCS0_RNE) {
675 if (unlikely (bufferspace == 0)) {
676 /* this happens when the driver's buffer
677 * is smaller than what the host sent.
678 * discard the extra data.
680 if (req->req.status != -EOVERFLOW)
681 DMSG("%s overflow\n", ep->ep.name);
682 req->req.status = -EOVERFLOW;
690 UDCCS0 = UDCCS0_OPR | UDCCS0_IPR;
693 if (req->req.actual >= req->req.length)
696 /* finished that packet. the next one may be waiting... */
702 #define MAX_IN_DMA ((DCMD_LENGTH + 1) - BULK_FIFO_SIZE)
705 start_dma_nodesc(struct pxa2xx_ep *ep, struct pxa2xx_request *req, int is_in)
707 u32 dcmd = req->req.length;
708 u32 buf = req->req.dma;
709 u32 fifo = io_v2p ((u32)ep->reg_uddr);
711 /* caller guarantees there's a packet or more remaining
712 * - IN may end with a short packet (TSP set separately),
713 * - OUT is always full length
715 buf += req->req.actual;
716 dcmd -= req->req.actual;
719 /* no-descriptor mode can be simple for bulk-in, iso-in, iso-out */
720 DCSR(ep->dma) = DCSR_NODESC;
722 DSADR(ep->dma) = buf;
723 DTADR(ep->dma) = fifo;
724 if (dcmd > MAX_IN_DMA)
727 ep->dma_fixup = (dcmd % ep->ep.maxpacket) != 0;
728 dcmd |= DCMD_BURST32 | DCMD_WIDTH1
729 | DCMD_FLOWTRG | DCMD_INCSRCADDR;
732 DSADR(ep->dma) = fifo;
733 DTADR(ep->dma) = buf;
734 if (ep->bmAttributes != USB_ENDPOINT_XFER_ISOC)
735 dcmd = ep->ep.maxpacket;
736 dcmd |= DCMD_BURST32 | DCMD_WIDTH1
737 | DCMD_FLOWSRC | DCMD_INCTRGADDR;
740 DCMD(ep->dma) = dcmd;
741 DCSR(ep->dma) = DCSR_RUN | DCSR_NODESC
743 ? DCSR_STOPIRQEN /* use dma_nodesc_handler() */
744 : 0); /* use handle_ep() */
747 static void kick_dma(struct pxa2xx_ep *ep, struct pxa2xx_request *req)
749 int is_in = ep->bEndpointAddress & USB_DIR_IN;
752 /* unaligned tx buffers and zlps only work with PIO */
753 if ((req->req.dma & 0x0f) != 0
754 || unlikely((req->req.length - req->req.actual)
756 pio_irq_enable(ep->bEndpointAddress);
757 if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0)
758 (void) write_fifo(ep, req);
760 start_dma_nodesc(ep, req, USB_DIR_IN);
763 if ((req->req.length - req->req.actual) < ep->ep.maxpacket) {
764 DMSG("%s short dma read...\n", ep->ep.name);
765 /* we're always set up for pio out */
768 *ep->reg_udccs = UDCCS_BO_DME
769 | (*ep->reg_udccs & UDCCS_BO_FST);
770 start_dma_nodesc(ep, req, USB_DIR_OUT);
775 static void cancel_dma(struct pxa2xx_ep *ep)
777 struct pxa2xx_request *req;
780 if (DCSR(ep->dma) == 0 || list_empty(&ep->queue))
784 while ((DCSR(ep->dma) & DCSR_STOPSTATE) == 0)
787 req = list_entry(ep->queue.next, struct pxa2xx_request, queue);
788 tmp = DCMD(ep->dma) & DCMD_LENGTH;
789 req->req.actual = req->req.length - (tmp & DCMD_LENGTH);
791 /* the last tx packet may be incomplete, so flush the fifo.
792 * FIXME correct req.actual if we can
794 if (ep->bEndpointAddress & USB_DIR_IN)
795 *ep->reg_udccs = UDCCS_BI_FTF;
798 /* dma channel stopped ... normal tx end (IN), or on error (IN/OUT) */
799 static void dma_nodesc_handler(int dmach, void *_ep, struct pt_regs *r)
801 struct pxa2xx_ep *ep = _ep;
802 struct pxa2xx_request *req;
807 req = list_entry(ep->queue.next, struct pxa2xx_request, queue);
810 ep->dev->stats.irqs++;
811 HEX_DISPLAY(ep->dev->stats.irqs);
816 if ((tmp & DCSR_STOPSTATE) == 0
817 || (DDADR(ep->dma) & DDADR_STOP) != 0) {
818 DBG(DBG_VERBOSE, "%s, dcsr %08x ddadr %08x\n",
819 ep->ep.name, DCSR(ep->dma), DDADR(ep->dma));
822 DCSR(ep->dma) = 0; /* clear DCSR_STOPSTATE */
824 /* update transfer status */
825 completed = tmp & DCSR_BUSERR;
826 if (ep->bEndpointAddress & USB_DIR_IN)
827 tmp = DSADR(ep->dma);
829 tmp = DTADR(ep->dma);
830 req->req.actual = tmp - req->req.dma;
832 /* FIXME seems we sometimes see partial transfers... */
834 if (unlikely(completed != 0))
835 req->req.status = -EIO;
836 else if (req->req.actual) {
837 /* these registers have zeroes in low bits; they miscount
838 * some (end-of-transfer) short packets: tx 14 as tx 12
841 req->req.actual = min(req->req.actual + 3,
844 tmp = (req->req.length - req->req.actual);
845 completed = (tmp == 0);
846 if (completed && (ep->bEndpointAddress & USB_DIR_IN)) {
848 /* maybe validate final short packet ... */
849 if ((req->req.actual % ep->ep.maxpacket) != 0)
850 *ep->reg_udccs = UDCCS_BI_TSP/*|UDCCS_BI_TPC*/;
852 /* ... or zlp, using pio fallback */
853 else if (ep->bmAttributes == USB_ENDPOINT_XFER_BULK
855 DMSG("%s zlp terminate ...\n", ep->ep.name);
861 if (likely(completed)) {
864 /* maybe re-activate after completion */
865 if (ep->stopped || list_empty(&ep->queue))
867 req = list_entry(ep->queue.next, struct pxa2xx_request, queue);
876 /*-------------------------------------------------------------------------*/
879 pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, int gfp_flags)
881 struct pxa2xx_request *req;
882 struct pxa2xx_ep *ep;
883 struct pxa2xx_udc *dev;
886 req = container_of(_req, struct pxa2xx_request, req);
887 if (unlikely (!_req || !_req->complete || !_req->buf
888 || !list_empty(&req->queue))) {
889 DMSG("%s, bad params\n", __FUNCTION__);
893 ep = container_of(_ep, struct pxa2xx_ep, ep);
894 if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) {
895 DMSG("%s, bad ep\n", __FUNCTION__);
900 if (unlikely (!dev->driver
901 || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
902 DMSG("%s, bogus device state\n", __FUNCTION__);
906 /* iso is always one packet per request, that's the only way
907 * we can report per-packet status. that also helps with dma.
909 if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
910 && req->req.length > le16_to_cpu
911 (ep->desc->wMaxPacketSize)))
915 // FIXME caller may already have done the dma mapping
917 _req->dma = dma_map_single(dev->dev,
918 _req->buf, _req->length,
919 ((ep->bEndpointAddress & USB_DIR_IN) != 0)
925 DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n",
926 _ep->name, _req, _req->length, _req->buf);
928 local_irq_save(flags);
930 _req->status = -EINPROGRESS;
933 /* kickstart this i/o queue? */
934 if (list_empty(&ep->queue) && !ep->stopped) {
935 if (ep->desc == 0 /* ep0 */) {
936 unsigned length = _req->length;
938 switch (dev->ep0state) {
939 case EP0_IN_DATA_PHASE:
940 dev->stats.write.ops++;
941 if (write_ep0_fifo(ep, req))
945 case EP0_OUT_DATA_PHASE:
946 dev->stats.read.ops++;
948 if (dev->req_config) {
949 DBG(DBG_VERBOSE, "ep0 config ack%s\n",
950 dev->has_cfr ? "" : " raced");
952 UDCCFR = UDCCFR_AREN|UDCCFR_ACM;
954 dev->ep0state = EP0_END_XFER;
957 if (dev->req_pending)
958 ep0start(dev, UDCCS0_IPR, "OUT");
959 if (length == 0 || ((UDCCS0 & UDCCS0_RNE) != 0
960 && read_ep0_fifo(ep, req))) {
968 DMSG("ep0 i/o, odd state %d\n", dev->ep0state);
969 local_irq_restore (flags);
973 /* either start dma or prime pio pump */
974 } else if (ep->dma >= 0) {
977 /* can the FIFO can satisfy the request immediately? */
978 } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0
979 && (*ep->reg_udccs & UDCCS_BI_TFS) != 0
980 && write_fifo(ep, req)) {
982 } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0
983 && read_fifo(ep, req)) {
987 if (likely (req && ep->desc) && ep->dma < 0)
988 pio_irq_enable(ep->bEndpointAddress);
991 /* pio or dma irq handler advances the queue. */
992 if (likely (req != 0))
993 list_add_tail(&req->queue, &ep->queue);
994 local_irq_restore(flags);
1001 * nuke - dequeue ALL requests
1003 static void nuke(struct pxa2xx_ep *ep, int status)
1005 struct pxa2xx_request *req;
1007 /* called with irqs blocked */
1009 if (ep->dma >= 0 && !ep->stopped)
1012 while (!list_empty(&ep->queue)) {
1013 req = list_entry(ep->queue.next,
1014 struct pxa2xx_request,
1016 done(ep, req, status);
1019 pio_irq_disable (ep->bEndpointAddress);
1023 /* dequeue JUST ONE request */
1024 static int pxa2xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1026 struct pxa2xx_ep *ep;
1027 struct pxa2xx_request *req;
1028 unsigned long flags;
1030 ep = container_of(_ep, struct pxa2xx_ep, ep);
1031 if (!_ep || ep->ep.name == ep0name)
1034 local_irq_save(flags);
1036 /* make sure it's actually queued on this endpoint */
1037 list_for_each_entry (req, &ep->queue, queue) {
1038 if (&req->req == _req)
1041 if (&req->req != _req) {
1042 local_irq_restore(flags);
1047 if (ep->dma >= 0 && ep->queue.next == &req->queue && !ep->stopped) {
1049 done(ep, req, -ECONNRESET);
1051 if (!list_empty(&ep->queue)) {
1052 req = list_entry(ep->queue.next,
1053 struct pxa2xx_request, queue);
1058 done(ep, req, -ECONNRESET);
1060 local_irq_restore(flags);
1064 /*-------------------------------------------------------------------------*/
1066 static int pxa2xx_ep_set_halt(struct usb_ep *_ep, int value)
1068 struct pxa2xx_ep *ep;
1069 unsigned long flags;
1071 ep = container_of(_ep, struct pxa2xx_ep, ep);
1073 || (!ep->desc && ep->ep.name != ep0name))
1074 || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
1075 DMSG("%s, bad ep\n", __FUNCTION__);
1079 /* this path (reset toggle+halt) is needed to implement
1080 * SET_INTERFACE on normal hardware. but it can't be
1081 * done from software on the PXA UDC, and the hardware
1082 * forgets to do it as part of SET_INTERFACE automagic.
1084 DMSG("only host can clear %s halt\n", _ep->name);
1088 local_irq_save(flags);
1090 if ((ep->bEndpointAddress & USB_DIR_IN) != 0
1091 && ((*ep->reg_udccs & UDCCS_BI_TFS) == 0
1092 || !list_empty(&ep->queue))) {
1093 local_irq_restore(flags);
1097 /* FST bit is the same for control, bulk in, bulk out, interrupt in */
1098 *ep->reg_udccs = UDCCS_BI_FST|UDCCS_BI_FTF;
1100 /* ep0 needs special care */
1102 start_watchdog(ep->dev);
1103 ep->dev->req_pending = 0;
1104 ep->dev->ep0state = EP0_STALL;
1107 /* and bulk/intr endpoints like dropping stalls too */
1110 for (i = 0; i < 1000; i += 20) {
1111 if (*ep->reg_udccs & UDCCS_BI_SST)
1116 local_irq_restore(flags);
1118 DBG(DBG_VERBOSE, "%s halt\n", _ep->name);
1122 static int pxa2xx_ep_fifo_status(struct usb_ep *_ep)
1124 struct pxa2xx_ep *ep;
1126 ep = container_of(_ep, struct pxa2xx_ep, ep);
1128 DMSG("%s, bad ep\n", __FUNCTION__);
1131 /* pxa can't report unclaimed bytes from IN fifos */
1132 if ((ep->bEndpointAddress & USB_DIR_IN) != 0)
1134 if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN
1135 || (*ep->reg_udccs & UDCCS_BO_RFS) == 0)
1138 return (*ep->reg_ubcr & 0xfff) + 1;
1141 static void pxa2xx_ep_fifo_flush(struct usb_ep *_ep)
1143 struct pxa2xx_ep *ep;
1145 ep = container_of(_ep, struct pxa2xx_ep, ep);
1146 if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) {
1147 DMSG("%s, bad ep\n", __FUNCTION__);
1151 /* toggle and halt bits stay unchanged */
1153 /* for OUT, just read and discard the FIFO contents. */
1154 if ((ep->bEndpointAddress & USB_DIR_IN) == 0) {
1155 while (((*ep->reg_udccs) & UDCCS_BO_RNE) != 0)
1156 (void) *ep->reg_uddr;
1160 /* most IN status is the same, but ISO can't stall */
1161 *ep->reg_udccs = UDCCS_BI_TPC|UDCCS_BI_FTF|UDCCS_BI_TUR
1162 | (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
1167 static struct usb_ep_ops pxa2xx_ep_ops = {
1168 .enable = pxa2xx_ep_enable,
1169 .disable = pxa2xx_ep_disable,
1171 .alloc_request = pxa2xx_ep_alloc_request,
1172 .free_request = pxa2xx_ep_free_request,
1174 .alloc_buffer = pxa2xx_ep_alloc_buffer,
1175 .free_buffer = pxa2xx_ep_free_buffer,
1177 .queue = pxa2xx_ep_queue,
1178 .dequeue = pxa2xx_ep_dequeue,
1180 .set_halt = pxa2xx_ep_set_halt,
1181 .fifo_status = pxa2xx_ep_fifo_status,
1182 .fifo_flush = pxa2xx_ep_fifo_flush,
1186 /* ---------------------------------------------------------------------------
1187 * device-scoped parts of the api to the usb controller hardware
1188 * ---------------------------------------------------------------------------
1191 static int pxa2xx_udc_get_frame(struct usb_gadget *_gadget)
1193 return ((UFNRH & 0x07) << 8) | (UFNRL & 0xff);
1196 static int pxa2xx_udc_wakeup(struct usb_gadget *_gadget)
1198 /* host may not have enabled remote wakeup */
1199 if ((UDCCS0 & UDCCS0_DRWF) == 0)
1200 return -EHOSTUNREACH;
1201 udc_set_mask_UDCCR(UDCCR_RSM);
1205 static const struct usb_gadget_ops pxa2xx_udc_ops = {
1206 .get_frame = pxa2xx_udc_get_frame,
1207 .wakeup = pxa2xx_udc_wakeup,
1208 // current versions must always be self-powered
1212 /*-------------------------------------------------------------------------*/
1214 #ifdef UDC_PROC_FILE
1216 static const char proc_node_name [] = "driver/udc";
1219 udc_proc_read(char *page, char **start, off_t off, int count,
1220 int *eof, void *_dev)
1223 struct pxa2xx_udc *dev = _dev;
1225 unsigned size = count;
1226 unsigned long flags;
1233 local_irq_save(flags);
1235 /* basic device status */
1236 t = scnprintf(next, size, DRIVER_DESC "\n"
1237 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1238 driver_name, DRIVER_VERSION SIZE_STR DMASTR,
1239 dev->driver ? dev->driver->driver.name : "(none)",
1240 is_usb_connected() ? "full speed" : "disconnected");
1244 /* registers for device and ep0 */
1245 t = scnprintf(next, size,
1246 "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
1247 UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
1252 t = scnprintf(next, size,
1253 "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp,
1254 (tmp & UDCCR_REM) ? " rem" : "",
1255 (tmp & UDCCR_RSTIR) ? " rstir" : "",
1256 (tmp & UDCCR_SRM) ? " srm" : "",
1257 (tmp & UDCCR_SUSIR) ? " susir" : "",
1258 (tmp & UDCCR_RESIR) ? " resir" : "",
1259 (tmp & UDCCR_RSM) ? " rsm" : "",
1260 (tmp & UDCCR_UDA) ? " uda" : "",
1261 (tmp & UDCCR_UDE) ? " ude" : "");
1266 t = scnprintf(next, size,
1267 "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp,
1268 (tmp & UDCCS0_SA) ? " sa" : "",
1269 (tmp & UDCCS0_RNE) ? " rne" : "",
1270 (tmp & UDCCS0_FST) ? " fst" : "",
1271 (tmp & UDCCS0_SST) ? " sst" : "",
1272 (tmp & UDCCS0_DRWF) ? " dwrf" : "",
1273 (tmp & UDCCS0_FTF) ? " ftf" : "",
1274 (tmp & UDCCS0_IPR) ? " ipr" : "",
1275 (tmp & UDCCS0_OPR) ? " opr" : "");
1281 t = scnprintf(next, size,
1282 "udccfr %02X =%s%s\n", tmp,
1283 (tmp & UDCCFR_AREN) ? " aren" : "",
1284 (tmp & UDCCFR_ACM) ? " acm" : "");
1289 if (!is_usb_connected() || !dev->driver)
1292 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
1293 dev->stats.write.bytes, dev->stats.write.ops,
1294 dev->stats.read.bytes, dev->stats.read.ops,
1299 /* dump endpoint queues */
1300 for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
1301 struct pxa2xx_ep *ep = &dev->ep [i];
1302 struct pxa2xx_request *req;
1306 const struct usb_endpoint_descriptor *d;
1311 tmp = *dev->ep [i].reg_udccs;
1312 t = scnprintf(next, size,
1313 "%s max %d %s udccs %02x irqs %lu/%lu\n",
1314 ep->ep.name, le16_to_cpu (d->wMaxPacketSize),
1315 (ep->dma >= 0) ? "dma" : "pio", tmp,
1316 ep->pio_irqs, ep->dma_irqs);
1317 /* TODO translate all five groups of udccs bits! */
1319 } else /* ep0 should only have one transfer queued */
1320 t = scnprintf(next, size, "ep0 max 16 pio irqs %lu\n",
1322 if (t <= 0 || t > size)
1327 if (list_empty(&ep->queue)) {
1328 t = scnprintf(next, size, "\t(nothing queued)\n");
1329 if (t <= 0 || t > size)
1335 list_for_each_entry(req, &ep->queue, queue) {
1337 if (ep->dma >= 0 && req->queue.prev == &ep->queue)
1338 t = scnprintf(next, size,
1339 "\treq %p len %d/%d "
1340 "buf %p (dma%d dcmd %08x)\n",
1341 &req->req, req->req.actual,
1342 req->req.length, req->req.buf,
1343 ep->dma, DCMD(ep->dma)
1344 // low 13 bits == bytes-to-go
1348 t = scnprintf(next, size,
1349 "\treq %p len %d/%d buf %p\n",
1350 &req->req, req->req.actual,
1351 req->req.length, req->req.buf);
1352 if (t <= 0 || t > size)
1360 local_irq_restore(flags);
1362 return count - size;
1365 #define create_proc_files() \
1366 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev)
1367 #define remove_proc_files() \
1368 remove_proc_entry(proc_node_name, NULL)
1370 #else /* !UDC_PROC_FILE */
1371 #define create_proc_files() do {} while (0)
1372 #define remove_proc_files() do {} while (0)
1374 #endif /* UDC_PROC_FILE */
1376 /* "function" sysfs attribute */
1378 show_function (struct device *_dev, char *buf)
1380 struct pxa2xx_udc *dev = dev_get_drvdata (_dev);
1383 || !dev->driver->function
1384 || strlen (dev->driver->function) > PAGE_SIZE)
1386 return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function);
1388 static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
1390 /*-------------------------------------------------------------------------*/
1393 * udc_disable - disable USB device controller
1395 static void udc_disable(struct pxa2xx_udc *dev)
1397 /* block all irqs */
1398 udc_set_mask_UDCCR(UDCCR_SRM|UDCCR_REM);
1399 UICR0 = UICR1 = 0xff;
1402 /* if hardware supports it, disconnect from usb */
1403 make_usb_disappear();
1405 udc_clear_mask_UDCCR(UDCCR_UDE);
1407 #ifdef CONFIG_ARCH_PXA
1408 /* Disable clock for USB device */
1409 CKEN &= ~CKEN11_USB;
1413 dev->gadget.speed = USB_SPEED_UNKNOWN;
1419 * udc_reinit - initialize software state
1421 static void udc_reinit(struct pxa2xx_udc *dev)
1425 /* device/ep0 records init */
1426 INIT_LIST_HEAD (&dev->gadget.ep_list);
1427 INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
1428 dev->ep0state = EP0_IDLE;
1430 /* basic endpoint records init */
1431 for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
1432 struct pxa2xx_ep *ep = &dev->ep[i];
1435 list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list);
1439 INIT_LIST_HEAD (&ep->queue);
1440 ep->pio_irqs = ep->dma_irqs = 0;
1443 /* the rest was statically initialized, and is read-only */
1446 /* until it's enabled, this UDC should be completely invisible
1449 static void udc_enable (struct pxa2xx_udc *dev)
1451 udc_clear_mask_UDCCR(UDCCR_UDE);
1453 #ifdef CONFIG_ARCH_PXA
1454 /* Enable clock for USB device */
1458 /* try to clear these bits before we enable the udc */
1459 udc_ack_int_UDCCR(UDCCR_SUSIR|/*UDCCR_RSTIR|*/UDCCR_RESIR);
1462 dev->gadget.speed = USB_SPEED_UNKNOWN;
1463 dev->stats.irqs = 0;
1466 * sequence taken from chapter 12.5.10, PXA250 AppProcDevManual:
1468 * - if RESET is already in progress, ack interrupt
1469 * - unmask reset interrupt
1471 udc_set_mask_UDCCR(UDCCR_UDE);
1472 if (!(UDCCR & UDCCR_UDA))
1473 udc_ack_int_UDCCR(UDCCR_RSTIR);
1475 if (dev->has_cfr /* UDC_RES2 is defined */) {
1476 /* pxa255 (a0+) can avoid a set_config race that could
1477 * prevent gadget drivers from configuring correctly
1479 UDCCFR = UDCCFR_ACM;
1481 /* "USB test mode" for pxa250 errata 40-42 (stepping a0, a1)
1482 * which could result in missing packets and interrupts.
1483 * supposedly one bit per endpoint, controlling whether it
1484 * double buffers or not; ACM/AREN bits fit into the holes.
1485 * zero bits (like USIR0_IRx) disable double buffering.
1491 #ifdef DISABLE_TEST_MODE
1492 /* "test mode" seems to have become the default in later chip
1493 * revs, preventing double buffering (and invalidating docs).
1494 * this EXPERIMENT enables it for bulk endpoints by tweaking
1495 * undefined/reserved register bits (that other drivers clear).
1496 * Belcarra code comments noted this usage.
1498 if (fifo_mode & 1) { /* IN endpoints */
1499 UDC_RES1 |= USIR0_IR1|USIR0_IR6;
1500 UDC_RES2 |= USIR1_IR11;
1502 if (fifo_mode & 2) { /* OUT endpoints */
1503 UDC_RES1 |= USIR0_IR2|USIR0_IR7;
1504 UDC_RES2 |= USIR1_IR12;
1508 /* caller must be able to sleep in order to cope
1509 * with startup transients.
1511 schedule_timeout(HZ/10);
1513 /* enable suspend/resume and reset irqs */
1514 udc_clear_mask_UDCCR(UDCCR_SRM | UDCCR_REM);
1516 /* enable ep0 irqs */
1517 UICR0 &= ~UICR0_IM0;
1519 /* if hardware supports it, connect to usb and wait for host */
1524 /* when a driver is successfully registered, it will receive
1525 * control requests including set_configuration(), which enables
1526 * non-control requests. then usb traffic follows until a
1527 * disconnect is reported. then a host may connect again, or
1528 * the driver might get unbound.
1530 int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1532 struct pxa2xx_udc *dev = the_controller;
1536 || driver->speed != USB_SPEED_FULL
1539 || !driver->disconnect
1547 /* first hook up the driver ... */
1548 dev->driver = driver;
1549 dev->gadget.dev.driver = &driver->driver;
1551 device_add (&dev->gadget.dev);
1552 retval = driver->bind(&dev->gadget);
1554 DMSG("bind to driver %s --> error %d\n",
1555 driver->driver.name, retval);
1556 device_del (&dev->gadget.dev);
1559 dev->gadget.dev.driver = 0;
1562 device_create_file(dev->dev, &dev_attr_function);
1564 /* ... then enable host detection and ep0; and we're ready
1565 * for set_configuration as well as eventual disconnect.
1566 * NOTE: this shouldn't power up until later.
1568 DMSG("registered gadget driver '%s'\n", driver->driver.name);
1573 EXPORT_SYMBOL(usb_gadget_register_driver);
1576 stop_activity(struct pxa2xx_udc *dev, struct usb_gadget_driver *driver)
1580 /* don't disconnect drivers more than once */
1581 if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1583 dev->gadget.speed = USB_SPEED_UNKNOWN;
1585 /* prevent new request submissions, kill any outstanding requests */
1586 for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
1587 struct pxa2xx_ep *ep = &dev->ep[i];
1590 nuke(ep, -ESHUTDOWN);
1592 del_timer_sync(&dev->timer);
1594 /* report disconnect; the driver is already quiesced */
1597 driver->disconnect(&dev->gadget);
1599 /* re-init driver-visible data structures */
1603 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1605 struct pxa2xx_udc *dev = the_controller;
1609 if (!driver || driver != dev->driver)
1612 local_irq_disable();
1614 stop_activity(dev, driver);
1617 driver->unbind(&dev->gadget);
1620 device_del (&dev->gadget.dev);
1621 device_remove_file(dev->dev, &dev_attr_function);
1623 DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
1627 EXPORT_SYMBOL(usb_gadget_unregister_driver);
1630 /*-------------------------------------------------------------------------*/
1632 #ifdef CONFIG_ARCH_LUBBOCK
1634 /* Lubbock can report connect or disconnect irqs. Likely more hardware
1635 * could support it as a timer callback.
1637 * FIXME for better power management, keep the hardware powered down
1638 * until a host is powering the link. means scheduling work later
1639 * in some task that can udc_enable().
1642 #define enable_disconnect_irq() \
1643 if (machine_is_lubbock()) { enable_irq(LUBBOCK_USB_DISC_IRQ); }
1644 #define disable_disconnect_irq() \
1645 if (machine_is_lubbock()) { disable_irq(LUBBOCK_USB_DISC_IRQ); }
1648 usb_connection_irq(int irq, void *_dev, struct pt_regs *r)
1650 struct pxa2xx_udc *dev = _dev;
1653 HEX_DISPLAY(dev->stats.irqs);
1655 if (!is_usb_connected()) {
1657 disable_disconnect_irq();
1658 /* report disconnect just once */
1659 if (dev->gadget.speed != USB_SPEED_UNKNOWN) {
1660 DMSG("disconnect %s\n",
1661 dev->driver ? dev->driver->driver.name : 0);
1662 stop_activity(dev, dev->driver);
1664 // udc_disable (dev);
1666 // maybe "ACTION=disconnect /sbin/hotplug gadget".
1668 } else if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
1671 DMSG("?? connect irq ??\n");
1673 // if there's no driver bound, ignore; else
1674 // udc_enable (dev);
1675 // UDC irqs drive the rest.
1676 // maybe "ACTION=connect /sbin/hotplug gadget".
1683 #ifndef enable_disconnect_irq
1684 #warning USB disconnect() is not yet reported.
1685 #define enable_disconnect_irq() do {} while (0)
1686 #define disable_disconnect_irq() do {} while (0)
1690 /*-------------------------------------------------------------------------*/
1692 static inline void clear_ep_state (struct pxa2xx_udc *dev)
1696 /* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
1697 * fifos, and pending transactions mustn't be continued in any case.
1699 for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++)
1700 nuke(&dev->ep[i], -ECONNABORTED);
1703 static void udc_watchdog(unsigned long _dev)
1705 struct pxa2xx_udc *dev = (void *)_dev;
1707 local_irq_disable();
1708 if (dev->ep0state == EP0_STALL
1709 && (UDCCS0 & UDCCS0_FST) == 0
1710 && (UDCCS0 & UDCCS0_SST) == 0) {
1711 UDCCS0 = UDCCS0_FST|UDCCS0_FTF;
1712 DBG(DBG_VERBOSE, "ep0 re-stall\n");
1713 start_watchdog(dev);
1718 static void handle_ep0 (struct pxa2xx_udc *dev)
1720 u32 udccs0 = UDCCS0;
1721 struct pxa2xx_ep *ep = &dev->ep [0];
1722 struct pxa2xx_request *req;
1724 struct usb_ctrlrequest r;
1729 if (list_empty(&ep->queue))
1732 req = list_entry(ep->queue.next, struct pxa2xx_request, queue);
1734 /* clear stall status */
1735 if (udccs0 & UDCCS0_SST) {
1737 UDCCS0 = UDCCS0_SST;
1738 del_timer(&dev->timer);
1742 /* previous request unfinished? non-error iff back-to-back ... */
1743 if ((udccs0 & UDCCS0_SA) != 0 && dev->ep0state != EP0_IDLE) {
1745 del_timer(&dev->timer);
1749 switch (dev->ep0state) {
1751 /* late-breaking status? */
1754 /* start control request? */
1755 if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))
1756 == (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))) {
1761 /* read SETUP packet */
1762 for (i = 0; i < 8; i++) {
1763 if (unlikely(!(UDCCS0 & UDCCS0_RNE))) {
1765 DMSG("SETUP %d!\n", i);
1768 u.raw [i] = (u8) UDDR0;
1770 if (unlikely((UDCCS0 & UDCCS0_RNE) != 0))
1774 le16_to_cpus (&u.r.wValue);
1775 le16_to_cpus (&u.r.wIndex);
1776 le16_to_cpus (&u.r.wLength);
1779 DBG(DBG_VERBOSE, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1780 u.r.bRequestType, u.r.bRequest,
1781 u.r.wValue, u.r.wIndex, u.r.wLength);
1783 /* cope with automagic for some standard requests. */
1784 dev->req_std = (u.r.bRequestType & USB_TYPE_MASK)
1785 == USB_TYPE_STANDARD;
1786 dev->req_config = 0;
1787 dev->req_pending = 1;
1788 switch (u.r.bRequest) {
1789 /* hardware restricts gadget drivers here! */
1790 case USB_REQ_SET_CONFIGURATION:
1791 if (u.r.bRequestType == USB_RECIP_DEVICE) {
1792 /* reflect hardware's automagic
1793 * up to the gadget driver.
1796 dev->req_config = 1;
1797 clear_ep_state(dev);
1798 /* if !has_cfr, there's no synch
1799 * else use AREN (later) not SA|OPR
1800 * USIR0_IR0 acts edge sensitive
1804 /* ... and here, even more ... */
1805 case USB_REQ_SET_INTERFACE:
1806 if (u.r.bRequestType == USB_RECIP_INTERFACE) {
1807 /* udc hardware is broken by design:
1808 * - altsetting may only be zero;
1809 * - hw resets all interfaces' eps;
1810 * - ep reset doesn't include halt(?).
1812 DMSG("broken set_interface (%d/%d)\n",
1813 u.r.wIndex, u.r.wValue);
1817 /* hardware was supposed to hide this */
1818 case USB_REQ_SET_ADDRESS:
1819 if (u.r.bRequestType == USB_RECIP_DEVICE) {
1820 ep0start(dev, 0, "address");
1826 if (u.r.bRequestType & USB_DIR_IN)
1827 dev->ep0state = EP0_IN_DATA_PHASE;
1829 dev->ep0state = EP0_OUT_DATA_PHASE;
1831 i = dev->driver->setup(&dev->gadget, &u.r);
1833 /* hardware automagic preventing STALL... */
1834 if (dev->req_config) {
1835 /* hardware sometimes neglects to tell
1836 * tell us about config change events,
1837 * so later ones may fail...
1839 WARN("config change %02x fail %d?\n",
1842 /* TODO experiment: if has_cfr,
1843 * hardware didn't ACK; maybe we
1844 * could actually STALL!
1847 DBG(DBG_VERBOSE, "protocol STALL, "
1848 "%02x err %d\n", UDCCS0, i);
1850 /* the watchdog timer helps deal with cases
1851 * where udc seems to clear FST wrongly, and
1852 * then NAKs instead of STALLing.
1854 ep0start(dev, UDCCS0_FST|UDCCS0_FTF, "stall");
1855 start_watchdog(dev);
1856 dev->ep0state = EP0_STALL;
1859 /* deferred i/o == no response yet */
1860 } else if (dev->req_pending) {
1861 if (likely(dev->ep0state == EP0_IN_DATA_PHASE
1862 || dev->req_std || u.r.wLength))
1863 ep0start(dev, 0, "defer");
1865 ep0start(dev, UDCCS0_IPR, "defer/IPR");
1868 /* expect at least one data or status stage irq */
1871 } else if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA))
1872 == (UDCCS0_OPR|UDCCS0_SA))) {
1875 /* pxa210/250 erratum 131 for B0/B1 says RNE lies.
1876 * still observed on a pxa255 a0.
1878 DBG(DBG_VERBOSE, "e131\n");
1881 /* read SETUP data, but don't trust it too much */
1882 for (i = 0; i < 8; i++)
1883 u.raw [i] = (u8) UDDR0;
1884 if ((u.r.bRequestType & USB_RECIP_MASK)
1887 if (u.word [0] == 0 && u.word [1] == 0)
1891 /* some random early IRQ:
1894 * - OPR got set, without SA (likely status stage)
1896 UDCCS0 = udccs0 & (UDCCS0_SA|UDCCS0_OPR);
1899 case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR etc */
1900 if (udccs0 & UDCCS0_OPR) {
1901 UDCCS0 = UDCCS0_OPR|UDCCS0_FTF;
1902 DBG(DBG_VERBOSE, "ep0in premature status\n");
1906 } else /* irq was IPR clearing */ {
1908 /* this IN packet might finish the request */
1909 (void) write_ep0_fifo(ep, req);
1910 } /* else IN token before response was written */
1913 case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR etc */
1914 if (udccs0 & UDCCS0_OPR) {
1916 /* this OUT packet might finish the request */
1917 if (read_ep0_fifo(ep, req))
1919 /* else more OUT packets expected */
1920 } /* else OUT token before read was issued */
1921 } else /* irq was IPR clearing */ {
1922 DBG(DBG_VERBOSE, "ep0out premature status\n");
1931 /* ack control-IN status (maybe in-zlp was skipped)
1932 * also appears after some config change events.
1934 if (udccs0 & UDCCS0_OPR)
1935 UDCCS0 = UDCCS0_OPR;
1939 UDCCS0 = UDCCS0_FST;
1945 static void handle_ep(struct pxa2xx_ep *ep)
1947 struct pxa2xx_request *req;
1948 int is_in = ep->bEndpointAddress & USB_DIR_IN;
1954 if (likely (!list_empty(&ep->queue)))
1955 req = list_entry(ep->queue.next,
1956 struct pxa2xx_request, queue);
1960 // TODO check FST handling
1962 udccs = *ep->reg_udccs;
1963 if (unlikely(is_in)) { /* irq from TPC, SST, or (ISO) TUR */
1965 if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
1966 tmp |= UDCCS_BI_SST;
1969 *ep->reg_udccs = tmp;
1970 if (req && likely ((udccs & UDCCS_BI_TFS) != 0))
1971 completed = write_fifo(ep, req);
1973 } else { /* irq from RPC (or for ISO, ROF) */
1974 if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
1975 tmp = UDCCS_BO_SST | UDCCS_BO_DME;
1977 tmp = UDCCS_IO_ROF | UDCCS_IO_DME;
1980 *ep->reg_udccs = tmp;
1982 /* fifos can hold packets, ready for reading... */
1985 // TODO didn't yet debug out-dma. this approach assumes
1986 // the worst about short packets and RPC; it might be better.
1988 if (likely(ep->dma >= 0)) {
1989 if (!(udccs & UDCCS_BO_RSP)) {
1990 *ep->reg_udccs = UDCCS_BO_RPC;
1996 completed = read_fifo(ep, req);
1998 pio_irq_disable (ep->bEndpointAddress);
2001 } while (completed);
2005 * pxa2xx_udc_irq - interrupt handler
2007 * avoid delays in ep0 processing. the control handshaking isn't always
2008 * under software control (pxa250c0 and the pxa255 are better), and delays
2009 * could cause usb protocol errors.
2012 pxa2xx_udc_irq(int irq, void *_dev, struct pt_regs *r)
2014 struct pxa2xx_udc *dev = _dev;
2018 HEX_DISPLAY(dev->stats.irqs);
2024 /* SUSpend Interrupt Request */
2025 if (unlikely(udccr & UDCCR_SUSIR)) {
2026 udc_ack_int_UDCCR(UDCCR_SUSIR);
2028 DBG(DBG_VERBOSE, "USB suspend%s\n", is_usb_connected()
2029 ? "" : "+disconnect");
2031 if (!is_usb_connected())
2032 stop_activity(dev, dev->driver);
2033 else if (dev->gadget.speed != USB_SPEED_UNKNOWN
2035 && dev->driver->suspend)
2036 dev->driver->suspend(&dev->gadget);
2040 /* RESume Interrupt Request */
2041 if (unlikely(udccr & UDCCR_RESIR)) {
2042 udc_ack_int_UDCCR(UDCCR_RESIR);
2044 DBG(DBG_VERBOSE, "USB resume\n");
2046 if (dev->gadget.speed != USB_SPEED_UNKNOWN
2048 && dev->driver->resume
2049 && is_usb_connected())
2050 dev->driver->resume(&dev->gadget);
2053 /* ReSeT Interrupt Request - USB reset */
2054 if (unlikely(udccr & UDCCR_RSTIR)) {
2055 udc_ack_int_UDCCR(UDCCR_RSTIR);
2058 if ((UDCCR & UDCCR_UDA) == 0) {
2059 DBG(DBG_VERBOSE, "USB reset start\n");
2060 if (dev->gadget.speed != USB_SPEED_UNKNOWN)
2061 disable_disconnect_irq();
2063 /* reset driver and endpoints,
2064 * in case that's not yet done
2066 stop_activity (dev, dev->driver);
2069 INFO("USB reset\n");
2070 dev->gadget.speed = USB_SPEED_FULL;
2072 memset(&dev->stats, 0, sizeof dev->stats);
2073 /* driver and endpoints are still reset */
2074 enable_disconnect_irq();
2078 u32 usir0 = USIR0 & ~UICR0;
2079 u32 usir1 = USIR1 & ~UICR1;
2082 if (unlikely (!usir0 && !usir1))
2085 DBG(DBG_VERY_NOISY, "irq %02x.%02x\n", usir1, usir0);
2087 /* control traffic */
2088 if (usir0 & USIR0_IR0) {
2089 dev->ep[0].pio_irqs++;
2094 /* endpoint data transfers */
2095 for (i = 0; i < 8; i++) {
2098 if (i && (usir0 & tmp)) {
2099 handle_ep(&dev->ep[i]);
2104 handle_ep(&dev->ep[i+8]);
2111 /* we could also ask for 1 msec SOF (SIR) interrupts */
2117 /*-------------------------------------------------------------------------*/
2119 static void nop_release (struct device *dev)
2121 DMSG("%s %s\n", __FUNCTION__, dev->bus_id);
2124 /* this uses load-time allocation and initialization (instead of
2125 * doing it at run-time) to save code, eliminate fault paths, and
2126 * be more obviously correct.
2128 static struct pxa2xx_udc memory = {
2130 .ops = &pxa2xx_udc_ops,
2131 .ep0 = &memory.ep[0].ep,
2132 .name = driver_name,
2135 .release = nop_release,
2139 /* control endpoint */
2143 .ops = &pxa2xx_ep_ops,
2144 .maxpacket = EP0_FIFO_SIZE,
2147 .reg_udccs = &UDCCS0,
2151 /* first group of endpoints */
2154 .name = "ep1in-bulk",
2155 .ops = &pxa2xx_ep_ops,
2156 .maxpacket = BULK_FIFO_SIZE,
2159 .fifo_size = BULK_FIFO_SIZE,
2160 .bEndpointAddress = USB_DIR_IN | 1,
2161 .bmAttributes = USB_ENDPOINT_XFER_BULK,
2162 .reg_udccs = &UDCCS1,
2168 .name = "ep2out-bulk",
2169 .ops = &pxa2xx_ep_ops,
2170 .maxpacket = BULK_FIFO_SIZE,
2173 .fifo_size = BULK_FIFO_SIZE,
2174 .bEndpointAddress = 2,
2175 .bmAttributes = USB_ENDPOINT_XFER_BULK,
2176 .reg_udccs = &UDCCS2,
2181 #ifndef CONFIG_USB_PXA2XX_SMALL
2184 .name = "ep3in-iso",
2185 .ops = &pxa2xx_ep_ops,
2186 .maxpacket = ISO_FIFO_SIZE,
2189 .fifo_size = ISO_FIFO_SIZE,
2190 .bEndpointAddress = USB_DIR_IN | 3,
2191 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
2192 .reg_udccs = &UDCCS3,
2198 .name = "ep4out-iso",
2199 .ops = &pxa2xx_ep_ops,
2200 .maxpacket = ISO_FIFO_SIZE,
2203 .fifo_size = ISO_FIFO_SIZE,
2204 .bEndpointAddress = 4,
2205 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
2206 .reg_udccs = &UDCCS4,
2213 .name = "ep5in-int",
2214 .ops = &pxa2xx_ep_ops,
2215 .maxpacket = INT_FIFO_SIZE,
2218 .fifo_size = INT_FIFO_SIZE,
2219 .bEndpointAddress = USB_DIR_IN | 5,
2220 .bmAttributes = USB_ENDPOINT_XFER_INT,
2221 .reg_udccs = &UDCCS5,
2225 /* second group of endpoints */
2228 .name = "ep6in-bulk",
2229 .ops = &pxa2xx_ep_ops,
2230 .maxpacket = BULK_FIFO_SIZE,
2233 .fifo_size = BULK_FIFO_SIZE,
2234 .bEndpointAddress = USB_DIR_IN | 6,
2235 .bmAttributes = USB_ENDPOINT_XFER_BULK,
2236 .reg_udccs = &UDCCS6,
2242 .name = "ep7out-bulk",
2243 .ops = &pxa2xx_ep_ops,
2244 .maxpacket = BULK_FIFO_SIZE,
2247 .fifo_size = BULK_FIFO_SIZE,
2248 .bEndpointAddress = 7,
2249 .bmAttributes = USB_ENDPOINT_XFER_BULK,
2250 .reg_udccs = &UDCCS7,
2257 .name = "ep8in-iso",
2258 .ops = &pxa2xx_ep_ops,
2259 .maxpacket = ISO_FIFO_SIZE,
2262 .fifo_size = ISO_FIFO_SIZE,
2263 .bEndpointAddress = USB_DIR_IN | 8,
2264 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
2265 .reg_udccs = &UDCCS8,
2271 .name = "ep9out-iso",
2272 .ops = &pxa2xx_ep_ops,
2273 .maxpacket = ISO_FIFO_SIZE,
2276 .fifo_size = ISO_FIFO_SIZE,
2277 .bEndpointAddress = 9,
2278 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
2279 .reg_udccs = &UDCCS9,
2286 .name = "ep10in-int",
2287 .ops = &pxa2xx_ep_ops,
2288 .maxpacket = INT_FIFO_SIZE,
2291 .fifo_size = INT_FIFO_SIZE,
2292 .bEndpointAddress = USB_DIR_IN | 10,
2293 .bmAttributes = USB_ENDPOINT_XFER_INT,
2294 .reg_udccs = &UDCCS10,
2295 .reg_uddr = &UDDR10,
2298 /* third group of endpoints */
2301 .name = "ep11in-bulk",
2302 .ops = &pxa2xx_ep_ops,
2303 .maxpacket = BULK_FIFO_SIZE,
2306 .fifo_size = BULK_FIFO_SIZE,
2307 .bEndpointAddress = USB_DIR_IN | 11,
2308 .bmAttributes = USB_ENDPOINT_XFER_BULK,
2309 .reg_udccs = &UDCCS11,
2310 .reg_uddr = &UDDR11,
2315 .name = "ep12out-bulk",
2316 .ops = &pxa2xx_ep_ops,
2317 .maxpacket = BULK_FIFO_SIZE,
2320 .fifo_size = BULK_FIFO_SIZE,
2321 .bEndpointAddress = 12,
2322 .bmAttributes = USB_ENDPOINT_XFER_BULK,
2323 .reg_udccs = &UDCCS12,
2324 .reg_ubcr = &UBCR12,
2325 .reg_uddr = &UDDR12,
2330 .name = "ep13in-iso",
2331 .ops = &pxa2xx_ep_ops,
2332 .maxpacket = ISO_FIFO_SIZE,
2335 .fifo_size = ISO_FIFO_SIZE,
2336 .bEndpointAddress = USB_DIR_IN | 13,
2337 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
2338 .reg_udccs = &UDCCS13,
2339 .reg_uddr = &UDDR13,
2344 .name = "ep14out-iso",
2345 .ops = &pxa2xx_ep_ops,
2346 .maxpacket = ISO_FIFO_SIZE,
2349 .fifo_size = ISO_FIFO_SIZE,
2350 .bEndpointAddress = 14,
2351 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
2352 .reg_udccs = &UDCCS14,
2353 .reg_ubcr = &UBCR14,
2354 .reg_uddr = &UDDR14,
2359 .name = "ep15in-int",
2360 .ops = &pxa2xx_ep_ops,
2361 .maxpacket = INT_FIFO_SIZE,
2364 .fifo_size = INT_FIFO_SIZE,
2365 .bEndpointAddress = USB_DIR_IN | 15,
2366 .bmAttributes = USB_ENDPOINT_XFER_INT,
2367 .reg_udccs = &UDCCS15,
2368 .reg_uddr = &UDDR15,
2370 #endif /* !CONFIG_USB_PXA2XX_SMALL */
2373 #define CP15R0_VENDOR_MASK 0xffffe000
2375 #if defined(CONFIG_ARCH_PXA)
2376 #define CP15R0_XSCALE_VALUE 0x69052000 /* intel/arm/xscale */
2378 #elif defined(CONFIG_ARCH_IXP4XX)
2379 #define CP15R0_XSCALE_VALUE 0x69054000 /* intel/arm/ixp4xx */
2383 #define CP15R0_PROD_MASK 0x000003f0
2384 #define PXA25x 0x00000100 /* and PXA26x */
2385 #define PXA210 0x00000120
2387 #define CP15R0_REV_MASK 0x0000000f
2389 #define CP15R0_PRODREV_MASK (CP15R0_PROD_MASK | CP15R0_REV_MASK)
2391 #define PXA255_A0 0x00000106 /* or PXA260_B1 */
2392 #define PXA250_C0 0x00000105 /* or PXA26x_B0 */
2393 #define PXA250_B2 0x00000104
2394 #define PXA250_B1 0x00000103 /* or PXA260_A0 */
2395 #define PXA250_B0 0x00000102
2396 #define PXA250_A1 0x00000101
2397 #define PXA250_A0 0x00000100
2399 #define PXA210_C0 0x00000125
2400 #define PXA210_B2 0x00000124
2401 #define PXA210_B1 0x00000123
2402 #define PXA210_B0 0x00000122
2403 #define IXP425_A0 0x000001c1
2406 * probe - binds to the platform device
2408 static int __init pxa2xx_udc_probe(struct device *_dev)
2410 struct pxa2xx_udc *dev = &memory;
2411 int retval, out_dma = 1;
2414 /* insist on Intel/ARM/XScale */
2415 asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
2416 if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
2417 printk(KERN_ERR "%s: not XScale!\n", driver_name);
2421 /* trigger chiprev-specific logic */
2422 switch (chiprev & CP15R0_PRODREV_MASK) {
2423 #if defined(CONFIG_ARCH_PXA)
2429 /* A0/A1 "not released"; ep 13, 15 unusable */
2431 case PXA250_B2: case PXA210_B2:
2432 case PXA250_B1: case PXA210_B1:
2433 case PXA250_B0: case PXA210_B0:
2436 case PXA250_C0: case PXA210_C0:
2438 #elif defined(CONFIG_ARCH_IXP4XX)
2445 printk(KERN_ERR "%s: unrecognized processor: %08x\n",
2446 driver_name, chiprev);
2447 /* iop3xx, ixp4xx, ... */
2451 pr_debug("%s: IRQ %d%s%s%s\n", driver_name, IRQ_USB,
2452 dev->has_cfr ? "" : " (!cfr)",
2453 out_dma ? "" : " (broken dma-out)",
2461 /* pxa 250 erratum 130 prevents using OUT dma (fixed C0) */
2463 DMSG("disabled OUT dma\n");
2464 dev->ep[ 2].reg_drcmr = dev->ep[ 4].reg_drcmr = 0;
2465 dev->ep[ 7].reg_drcmr = dev->ep[ 9].reg_drcmr = 0;
2466 dev->ep[12].reg_drcmr = dev->ep[14].reg_drcmr = 0;
2470 /* other non-static parts of init */
2472 dev->mach = _dev->platform_data;
2474 init_timer(&dev->timer);
2475 dev->timer.function = udc_watchdog;
2476 dev->timer.data = (unsigned long) dev;
2478 device_initialize(&dev->gadget.dev);
2479 dev->gadget.dev.parent = _dev;
2480 dev->gadget.dev.dma_mask = _dev->dma_mask;
2482 the_controller = dev;
2483 dev_set_drvdata(_dev, dev);
2488 /* irq setup after old hardware state is cleaned up */
2489 retval = request_irq(IRQ_USB, pxa2xx_udc_irq,
2490 SA_INTERRUPT, driver_name, dev);
2492 printk(KERN_ERR "%s: can't get irq %i, err %d\n",
2493 driver_name, IRQ_USB, retval);
2498 #ifdef CONFIG_ARCH_LUBBOCK
2499 if (machine_is_lubbock()) {
2500 disable_irq(LUBBOCK_USB_DISC_IRQ);
2501 retval = request_irq(LUBBOCK_USB_DISC_IRQ,
2503 SA_INTERRUPT /* OOPSING | SA_SAMPLE_RANDOM */,
2506 enable_irq(LUBBOCK_USB_DISC_IRQ);
2507 printk(KERN_ERR "%s: can't get irq %i, err %d\n",
2508 driver_name, LUBBOCK_USB_DISC_IRQ, retval);
2514 create_proc_files();
2518 static int __exit pxa2xx_udc_remove(struct device *_dev)
2520 struct pxa2xx_udc *dev = _dev->driver_data;
2523 remove_proc_files();
2524 usb_gadget_unregister_driver(dev->driver);
2527 free_irq(IRQ_USB, dev);
2530 if (machine_is_lubbock() && dev->got_disc) {
2531 free_irq(LUBBOCK_USB_DISC_IRQ, dev);
2534 dev_set_drvdata(_dev, 0);
2539 /*-------------------------------------------------------------------------*/
2541 static struct device_driver udc_driver = {
2542 .name = (char *) driver_name,
2543 .bus = &platform_bus_type,
2544 .probe = pxa2xx_udc_probe,
2545 .remove = __exit_p(pxa2xx_udc_remove),
2547 // FIXME power management support
2548 // .suspend = ... disable UDC
2549 // .resume = ... re-enable UDC
2552 static int __init udc_init(void)
2554 printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION);
2555 return driver_register(&udc_driver);
2557 module_init(udc_init);
2559 static void __exit udc_exit(void)
2561 driver_unregister(&udc_driver);
2563 module_exit(udc_exit);
2565 MODULE_DESCRIPTION(DRIVER_DESC);
2566 MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
2567 MODULE_LICENSE("GPL");